import { AddTabOptions } from './LayoutService'; /** * The docking workspace, as an API. * * Everything an application does with tabs — open one or bring it forward, * close it, rename it, point it at something new, ask what is on screen — * without learning FlexLayout's model or its action wire format. Every * FlexLayout call the shell makes on an app's behalf lives in this file, so a * FlexLayout upgrade is absorbed here rather than in every consumer. * * Usable outside React, like the registries. `useLayoutStore().model` stays * exported as an escape hatch, but is not a stable API. */ /** A tab, as the workspace describes it. */ export interface TabRef { /** FlexLayout node id. Stable for the life of the tab. */ id: string; /** Registered component id (aliases resolved). */ component: string; /** Text on the tab. */ title: string; /** The tab's config, without the shell's own bookkeeping keys. */ config: Record; /** The tabset holding it. */ tabsetId: string; /** Selected within its tabset, so currently rendered. */ selected: boolean; /** Selected within the active tabset: the tab the user is working in. */ active: boolean; /** Marked dirty with `setDirty` / `useLayoutStore().setTabDirty`. */ dirty: boolean; } /** What is open, and which tab is active. */ export interface WorkspaceSnapshot { tabs: TabRef[]; /** Id of the active tab, or `null` when nothing is open. */ active: string | null; } /** Options for {@link workspace.open}. */ export interface OpenTabOptions extends AddTabOptions { /** Tab title. Defaults to the component id for a new tab. */ title?: string; /** Config for a new tab, or merged into a reused tab's config. */ config?: Record; } export declare const workspace: { /** * Open a tab, or bring forward the one already open with the same reuse * key (by default, the same component). See {@link AddTabOptions}. * * @returns The tab id, or `null` when the layout has nowhere to put it. */ open(component: string, options?: OpenTabOptions): string | null; /** Select a tab and make its tabset active. `false` if no such tab. */ focus(tabId: string): boolean; /** * Close a tab. A dirty tab asks first, through the shell's modal, unless * `force` is set. * * @returns Whether the tab was closed. */ close(tabId: string, options?: { force?: boolean; }): Promise; /** Change a tab's title. */ rename(tabId: string, title: string): void; /** * Change a tab in place. `config` is merged into the existing config; * `component` swaps what the tab renders. */ update(tabId: string, patch: { title?: string; config?: Record; component?: string; }): void; /** Tabs showing `component` (aliases resolved), or matching a predicate. */ find(match: string | ((tab: TabRef) => boolean)): TabRef[]; /** A tab by id. */ get(tabId: string): TabRef | undefined; /** Whether a tab showing `component` is open. */ isOpen(component: string): boolean; /** The tab the user is working in, or `null`. */ active(): TabRef | null; /** Every open tab and which one is active. Cheap: cached per change. */ snapshot: () => WorkspaceSnapshot; /** * Clear the saved layout and return to the app's initial layout (its * `initialLayoutJson`, or the empty default). For a "Reset Layout" button. */ reset(): void; /** * Rewrite tabs saved under an aliased component id to the id it now names, * retitling them when the alias says to. `ShellLayout` runs this on mount. * * @returns How many tabs were rewritten. */ normalizeAliases(): number; /** * Close every tab whose component is not registered. Used by the `'drop'` * unknown-component policy. * * @returns How many tabs were closed. */ dropUnknown(): number; /** Run `listener` after every layout change. Returns an unsubscribe. */ onDidChange(listener: (snapshot: WorkspaceSnapshot) => void): () => void; /** * Run `listener` whenever a tab becomes the active one, or is explicitly * opened or focused while already active. Returns an unsubscribe. */ onDidActivate(listener: (tab: TabRef) => void): () => void; }; /** The workspace snapshot, re-rendering on every layout change. */ export declare const useWorkspaceSnapshot: () => WorkspaceSnapshot; /** Identifies the tab a component is rendered in. Provided by `ShellLayout`. */ export declare const TabContext: import('react').Context<{ id: string; } | null>; /** Options for {@link useTab}. */ export interface UseTabOptions { /** * Called when this tab becomes the active tab — clicked, opened, or * explicitly brought forward — and once on mount if it mounts active. The * place to focus an input. */ onActivate?: (tab: TabRef) => void; } /** What {@link useTab} returns. Outside a tab, `id` is `null` and setters no-op. */ export interface UseTabResult { id: string | null; title: string; config: C; selected: boolean; active: boolean; dirty: boolean; setTitle: (title: string) => void; /** Merge into this tab's config. Re-renders the tab with the new props. */ setConfig: (patch: Partial) => void; setDirty: (dirty: boolean) => void; close: (options?: { force?: boolean; }) => Promise; } /** * A tab component's view of the tab it is rendered in. * * @example * ```tsx * const Desk = () => { * const input = useRef(null); * const { config } = useTab<{ query?: string }>({ * onActivate: () => input.current?.focus(), * }); * ... * }; * ``` */ export declare const useTab: = Record>(options?: UseTabOptions) => UseTabResult;