/** * Pure helpers backing the extension dialog API in `./index`. * * The IPC wrappers themselves are hard to test (they depend on Electron), so the logic that decides * what gets sent and how a host reply is interpreted lives here and is unit tested directly. * @internal */ /** * Options controlling how CanKing opens an extension dialog window. */ export interface ExtensionDialogOptions { /** Window title. Defaults to the extension's display name. */ title?: string; /** Initial width. Only applied the first time this dialog is opened; later the user's size wins. */ width?: number; /** Initial height. Only applied the first time this dialog is opened; later the user's size wins. */ height?: number; /** Whether the dialog blocks the main window. Defaults to true. */ modal?: boolean; /** Whether the user may resize the window. Defaults to true. */ resizable?: boolean; } /** * Why an extension dialog did not complete normally. * * - `unsupported-host` — the CanKing version is older than this API, or the call was blocked. * - `unknown-extension` — the host could not resolve the caller to an installed extension. * - `invalid-dialog-id` — the dialog id, view id or arguments were rejected. A dialog id may contain * only letters, digits, `-` and `_`, and arguments must be JSON-serializable. * - `already-open` — this dialog is already open; the existing window was focused instead. * - `too-many-dialogs` — the per-extension dialog limit was reached. */ export type ExtensionDialogFailureReason = 'unsupported-host' | 'unknown-extension' | 'invalid-dialog-id' | 'already-open' | 'too-many-dialogs'; /** * The outcome of opening an extension dialog. * * This is deliberately a wrapper object rather than a bare result value: the host returns * `undefined` both when a dialog is dismissed without a result and when the call is blocked, so * `completed` is the only way to tell those apart. */ export interface ExtensionDialogResult { /** True if the dialog opened and has now closed. */ completed: boolean; /** The value passed to `closeExtensionDialog`, or undefined if the user dismissed the window. */ result?: TResult; /** Set only when `completed` is false. */ reason?: ExtensionDialogFailureReason; } /** * Checks that a dialog id is safe to place in a URL path segment. * * The id becomes part of the route the dialog window loads, so it is restricted to an unreserved * character set. That rules out path traversal, scheme injection and query/fragment splicing * without needing to escape anything. * @param dialogId - The dialog id to check. * @returns True if the id is acceptable. * @internal */ export declare function isValidExtensionDialogId(dialogId: unknown): dialogId is string; /** * Normalizes caller-supplied dialog options into the shape sent over IPC. * * Undefined entries are dropped rather than sent as explicit undefined, so the host applies its own * defaults and a stored window size is not overwritten by a partially filled object. * @param options - The options as supplied by the extension, possibly undefined. * @returns A normalized options object containing only the keys that were actually set. * @internal */ export declare function normalizeExtensionDialogOptions(options?: ExtensionDialogOptions): ExtensionDialogOptions; /** * Interprets whatever the host returned from `main-open-extension-dialog`. * * A host that predates this API has no handler and the invoke rejects; a host that has the handler * but blocked the call resolves with `undefined`. Both collapse to `unsupported-host` so callers * have a single "the dialog never opened" case to fall back on. * @param raw - The raw value resolved by the IPC invoke. * @returns A well-formed result object. * @internal */ export declare function toExtensionDialogResult(raw: unknown): ExtensionDialogResult; /** * Reads the dialog parameters the host puts on the dialog window's URL. * @param search - The query string, typically `window.location.search`. * @returns The workspace view id that opened the dialog, and the dialog id being rendered. * `id` is -1 and `dialogId` undefined when the parameters are absent or unusable. * @internal */ export declare function parseExtensionDialogParams(search: string): { id: number; dialogId?: string; };