react-dockable-desktop 5.0.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -110,6 +110,30 @@ interface BuiltInPanelEvents {
110
110
  'panel:restored': {
111
111
  id: string;
112
112
  };
113
+ /**
114
+ * Fires whenever something `saveLayout()` would capture changes — open/close/minimize/restore,
115
+ * and an `openPanel` `dedupeKey` redirect. Coalesces those into one signal for autosave-style
116
+ * consumers, so they don't need to subscribe to four separate events. Does **not** cover a
117
+ * `registerStateProvider` callback's return value changing on its own — that's a pull, there's
118
+ * no way to observe it changing without the panel separately notifying — nor resize/split-ratio
119
+ * drag/dock-rearrange, which have no hooks yet.
120
+ */
121
+ 'layout:changed': Record<string, never>;
122
+ /**
123
+ * Fires from inside `saveLayout()` itself, only when that specific call excluded at least one
124
+ * panel (a panel whose current `props` — static or from a `registerStateProvider` — failed
125
+ * {@link isSerializable}). A passive `PanelInfo.serializable` flag alone isn't enough for this:
126
+ * nobody may be polling it at the exact moment a save happens and something silently drops out
127
+ * (e.g. a floating window rendering data from a live class instance). This is deliberately just
128
+ * a signal, not a UI opinion — decide for yourself whether that becomes a toast, a console
129
+ * warning, or nothing.
130
+ */
131
+ 'layout:panels-excluded': {
132
+ panels: {
133
+ id: string;
134
+ component: string;
135
+ }[];
136
+ };
113
137
  }
114
138
  /** Per-panel definition supplied to WorkspaceClient constructor. */
115
139
  interface PanelDefinition {
@@ -228,6 +252,9 @@ declare class WorkspaceClient<TUserEvents extends Record<string, unknown> = Reco
228
252
  isOpen(id: string): boolean;
229
253
  /** Returns the IDs of all currently open panels. */
230
254
  getOpenPanelIds(): string[];
255
+ /** Finds an already-open panel of the given component with a matching `dedupeKey` (set via
256
+ * `openPanel`'s `dedupeKey` option). Returns `null` if none is open. */
257
+ findPanelId(component: string, dedupeKey: string): string | null;
231
258
  saveLayout(): string;
232
259
  loadLayout(json: string): boolean;
233
260
  setDirection(dir: 'ltr' | 'rtl'): void;
@@ -247,6 +274,12 @@ declare class WorkspaceClient<TUserEvents extends Record<string, unknown> = Reco
247
274
  registerCloseGuard(id: string, guard: () => boolean | Promise<boolean>): void;
248
275
  /** Removes a previously registered close guard. */
249
276
  unregisterCloseGuard(id: string): void;
277
+ /** Registers a callback reporting a panel's current restorable state, pulled fresh on every
278
+ * `saveLayout()` call — see {@link BuiltInPanelEvents}'s `'layout:panels-excluded'` doc and
279
+ * `FormContainerContract.registerStateProvider`. */
280
+ registerStateProvider(id: string, provider: () => unknown): void;
281
+ /** Removes a previously registered state provider. */
282
+ unregisterStateProvider(id: string): void;
250
283
  /** Sets/clears a panel's dirty (unsaved changes) flag. */
251
284
  setPanelDirty(id: string, dirty: boolean, options?: DirtyStateOptions): void;
252
285
  /** Updates a panel's displayed title. */
@@ -277,6 +310,16 @@ declare class WorkspaceClient<TUserEvents extends Record<string, unknown> = Reco
277
310
  onPanelMinimize(callback: (id: string) => void): () => void;
278
311
  /** Subscribe to panel restore events. */
279
312
  onPanelRestore(callback: (id: string) => void): () => void;
313
+ /** Subscribe to the coalesced layout-change signal — see {@link BuiltInPanelEvents}'s
314
+ * `'layout:changed'` doc for exactly what it covers (and doesn't). */
315
+ onLayoutChanged(callback: () => void): () => void;
316
+ /** Subscribe to notification that a `saveLayout()` call excluded one or more panels because
317
+ * their current props weren't serializable — see {@link BuiltInPanelEvents}'s
318
+ * `'layout:panels-excluded'` doc. */
319
+ onPanelsExcluded(callback: (panels: {
320
+ id: string;
321
+ component: string;
322
+ }[]) => void): () => void;
280
323
  }
281
324
 
282
325
  /**
@@ -534,6 +577,51 @@ interface PanelInfo {
534
577
  dirty?: boolean;
535
578
  /** Custom options applied to the automatic unsaved changes modal. */
536
579
  dirtyOptions?: DirtyStateOptions;
580
+ /** Custom per-instance data passed via `openPanel(id, component, { props })`. Unconstrained —
581
+ * any value is accepted, but only a value that passes {@link isSerializable} is actually
582
+ * included in {@link WindowActions.saveLayout}'s output. See {@link PanelInfo.serializable}. */
583
+ props?: Record<string, unknown>;
584
+ /** Whether this panel's current `props` can round-trip through `saveLayout()`/`loadLayout()`.
585
+ * Computed automatically — `true` when no `props` were passed, or when they were and passed
586
+ * {@link isSerializable}. A panel with `serializable: false` still renders and works normally;
587
+ * it's simply excluded from the next `saveLayout()` call (and pruned from `gridRoot`/
588
+ * `floating`/`minimized` in that saved snapshot) rather than corrupting or throwing. */
589
+ serializable: boolean;
590
+ /** Optional dedup key. If another open panel of the same `component` already has this exact
591
+ * key, `openPanel` focuses that existing panel instead of creating a new one — see
592
+ * {@link WindowActions.openPanel}'s `dedupeKey` option and {@link WindowActions.findPanelId}. */
593
+ dedupeKey?: string;
594
+ }
595
+ /**
596
+ * Options accepted by {@link WindowActions.openPanel}.
597
+ */
598
+ interface OpenPanelOptions<P extends object = Record<string, unknown>> {
599
+ /** Override the panel tab/window title. Accepts a plain string or an i18n message descriptor. */
600
+ title?: string | ContextMenuPredefinedMessage;
601
+ /** Initial placement: `'floating'`, `'docked'` (default when a grid exists), or `'tabbed'`. */
602
+ initialTarget?: 'floating' | 'docked' | 'tabbed';
603
+ /** Pin the new floating window to a workspace corner on creation. Has no effect when
604
+ * `initialTarget` is `'docked'` or `'tabbed'`. */
605
+ anchor?: FloatAnchor | null;
606
+ /** Set `state.activePanelId` to this panel. @default true */
607
+ focus?: boolean;
608
+ /**
609
+ * Custom per-instance data spread onto the panel component alongside `panelId`, matching
610
+ * `openModal`/`openLeftPanel`/`openRightPanel`'s already-unconstrained `props` argument — no
611
+ * type restriction here either. Whether a specific value round-trips through `saveLayout()` is
612
+ * a runtime fact, not a type-level guarantee: see {@link PanelInfo.serializable} and the
613
+ * `'layout:panels-excluded'` event.
614
+ */
615
+ props?: P;
616
+ /**
617
+ * If set, and another currently-open panel of the same `component` already has this exact
618
+ * `dedupeKey`, that existing panel is focused instead of opening a new one — the `id`/`props`
619
+ * passed to *this* call are ignored in that case, the same way re-opening an already-open exact
620
+ * `id` already focuses it instead of duplicating it. Use this when multiple call sites might
621
+ * not agree on the same literal `id` for what is semantically the same entity (e.g. "the panel
622
+ * for the document at this path"). See also {@link WindowActions.findPanelId}.
623
+ */
624
+ dedupeKey?: string;
537
625
  }
538
626
  /**
539
627
  * Global window manager state tree representing grid nodes, windows, and panels.
@@ -592,6 +680,8 @@ interface WindowActions {
592
680
  * @param options.initialTarget - Initial placement: `'floating'`, `'docked'` (default when a grid exists), or `'tabbed'`.
593
681
  * @param options.anchor - Pin the new floating window to a workspace corner on creation. Has no effect when `initialTarget` is `'docked'` or `'tabbed'`.
594
682
  * @param options.focus - Set `state.activePanelId` to this panel. @default true
683
+ * @param options.props - Custom per-instance data spread onto the component alongside `panelId`. Unconstrained, like `openModal`/`openLeftPanel`/`openRightPanel`'s `props` — see {@link PanelInfo.serializable} for what determines whether it survives `saveLayout()`.
684
+ * @param options.dedupeKey - If another open panel of the same `component` already has this key, that panel is focused instead of opening a new one.
595
685
  * @example
596
686
  * ```ts
597
687
  * // Open floating and pin to the top-right corner:
@@ -599,14 +689,15 @@ interface WindowActions {
599
689
  *
600
690
  * // Open in the background without stealing focus:
601
691
  * actions.openPanel('prefetch', 'report', { focus: false });
692
+ *
693
+ * // Open with per-instance data, deduped by document path:
694
+ * actions.openPanel(crypto.randomUUID(), 'document', {
695
+ * props: { path: '/notes/todo.md' },
696
+ * dedupeKey: '/notes/todo.md',
697
+ * });
602
698
  * ```
603
699
  */
604
- openPanel: (id: string, component: string, options?: {
605
- title?: string | ContextMenuPredefinedMessage;
606
- initialTarget?: 'floating' | 'docked' | 'tabbed';
607
- anchor?: FloatAnchor | null;
608
- focus?: boolean;
609
- }) => void;
700
+ openPanel: <P extends object = Record<string, unknown>>(id: string, component: string, options?: OpenPanelOptions<P>) => void;
610
701
  /**
611
702
  * Closes a panel immediately, bypassing dirty-state close guards.
612
703
  * For guarded close, use {@link requestClosePanel}.
@@ -691,6 +782,15 @@ interface WindowActions {
691
782
  * @returns Array of panel instance IDs.
692
783
  */
693
784
  getOpenPanelIds: () => string[];
785
+ /**
786
+ * Finds the ID of an already-open panel of the given `component` with a matching `dedupeKey`
787
+ * (set via `openPanel`'s `dedupeKey` option). Uses a synchronous `stateRef` read — safe to
788
+ * call outside of render.
789
+ * @param component - Component key registered in the panel catalog.
790
+ * @param dedupeKey - The dedup key to search for.
791
+ * @returns The matching panel's ID, or `null` if none is open.
792
+ */
793
+ findPanelId: (component: string, dedupeKey: string) => string | null;
694
794
  /**
695
795
  * Serializes the entire workspace state to a JSON string.
696
796
  * Includes grid layout, floating window positions, minimized panels, and panel metadata.
@@ -757,6 +857,23 @@ interface WindowActions {
757
857
  * @param id - Panel instance ID.
758
858
  */
759
859
  unregisterCloseGuard: (id: string) => void;
860
+ /**
861
+ * Registers a callback reporting a docked/floating panel's *current* restorable state, pulled
862
+ * fresh every `saveLayout()` call — for panels whose props alone can't capture state they
863
+ * accumulate after opening (scroll position, an in-progress edit, a view-mode toggle). A panel
864
+ * that registers nothing keeps its static open-time `props` (or none). The returned value goes
865
+ * through the same {@link isSerializable} check as static props, re-evaluated on every save —
866
+ * a provider-backed panel's serializability can flip over its lifetime.
867
+ * @param id - Panel instance ID.
868
+ * @param provider - Called synchronously at each `saveLayout()`; return the current state (or
869
+ * `undefined` to fall back to the static `props` this panel was opened with).
870
+ */
871
+ registerStateProvider: (id: string, provider: () => unknown) => void;
872
+ /**
873
+ * Removes a previously registered state provider.
874
+ * @param id - Panel instance ID.
875
+ */
876
+ unregisterStateProvider: (id: string) => void;
760
877
  /**
761
878
  * Marks a panel as dirty (has unsaved changes). Dirty panels show a visual indicator
762
879
  * and the built-in close guard prompts the user before closing.
@@ -1059,6 +1176,26 @@ interface DockableDesktopProviderProps extends WindowManagerProviderProps {
1059
1176
  */
1060
1177
  declare const DockableDesktopProvider: React$1.FC<DockableDesktopProviderProps>;
1061
1178
 
1179
+ /**
1180
+ * Recursively checks whether a value can round-trip through `JSON.stringify`/`JSON.parse`
1181
+ * without silently losing information.
1182
+ *
1183
+ * Deliberately **not** a `JSON.stringify` try/catch — that call doesn't throw for the actual
1184
+ * failure case this guards against: a function-valued property is simply dropped by
1185
+ * `JSON.stringify`, not rejected. This walks the value tree instead, returning `false` as soon as
1186
+ * it finds a function, symbol, `undefined`, React element, or any non-plain object (a class
1187
+ * instance, `Map`, `Set`, `RegExp`, etc.).
1188
+ *
1189
+ * `Date` is treated as an explicit exception — serializable-enough, matching `JSON.stringify`'s
1190
+ * own behavior — even though it doesn't round-trip back to a `Date` instance on parse. That's a
1191
+ * smaller, more tolerable gotcha than a silently-vanishing function, so it's documented rather
1192
+ * than treated as a disqualifying case.
1193
+ *
1194
+ * Used to decide whether a docked/floating panel's `props` can be included in
1195
+ * `WorkspaceClient.saveLayout()`'s output — see {@link PanelInfo.serializable}.
1196
+ */
1197
+ declare function isSerializable(value: unknown): boolean;
1198
+
1062
1199
  /**
1063
1200
  * Options used when requesting to close a container.
1064
1201
  */
@@ -1079,6 +1216,17 @@ interface FormContainerContract {
1079
1216
  setDirty: (dirty: boolean, options?: DirtyStateOptions) => void;
1080
1217
  /** Register a custom close guard handler. Returning false or a promise resolving to false blocks closing. */
1081
1218
  onCloseRequested: (handler: () => boolean | Promise<boolean>) => (() => void);
1219
+ /**
1220
+ * Registers a callback reporting this panel's *current* restorable state, pulled fresh by
1221
+ * `WorkspaceClient.saveLayout()` every time it's called — for panels whose static open-time
1222
+ * props can't capture state accumulated after opening (scroll position, an in-progress edit, a
1223
+ * view-mode toggle). Only meaningful for docked/floating panels — left/right side panels and
1224
+ * modals already have a complete answer to this via `openLeftPanel`/`openRightPanel`/
1225
+ * `openModal`'s own `props` argument plus `updateInstance`, so this is `undefined` there.
1226
+ * The returned value must be synchronous — `saveLayout()` itself never returns a `Promise`.
1227
+ * Return `undefined` to fall back to the static `props` this panel was opened with.
1228
+ */
1229
+ registerStateProvider?: (getState: () => unknown) => (() => void);
1082
1230
  /** Change the display title of the containing tab or window dynamically. */
1083
1231
  setTitle: (title: string | {
1084
1232
  id: string;
@@ -2131,4 +2279,4 @@ declare function computeResizedRect(dir: ResizeDir, dx: number, dy: number, star
2131
2279
  */
2132
2280
  declare function useColorScheme(): 'dark' | 'light';
2133
2281
 
2134
- export { type BuiltInPanelEvents, type ButtonVariant, type CloseOptions, ConfirmationForm, type ConfirmationFormProps, ContextMenu, type ContextMenuAdapter, type ContextMenuCheckbox, type ContextMenuHandle, type ContextMenuItem, type ContextMenuLabel, type ContextMenuPredefinedMessage, type ContextMenuProps, ContextMenuProvider, type ContextMenuSeparator, type ContextMenuSimpleItem, type ContextMenuSubMenu, DefaultContextMenuAdapter, DockableDesktopProvider, type DockableDesktopProviderProps, type DropPosition, type DropTarget, type FloatAnchor, type FloatingWindow, FormContainerContext, type FormContainerContract, FormContainerProvider, type LayoutGridNode, type LayoutLeafNode, type LayoutNode, LeftPanelRenderer, type ManagedWindowConfig, type MenuItemAction, type MessageFormatter, type ModalOptions, ModalStackRenderer, type PanelActions, type PanelContribution, PanelContributionProvider, type PanelDefinition, PanelFloatingWindow, type PanelFloatingWindowManagerHandle, type PanelFloatingWindowProps, type PanelInfo, type PanelInstance, type PanelInstanceId, PanelOverlayRoot, type PanelOverlayRootProps, PanelProvider, PanelRegistry, PanelRegistryClass, type PanelRegistryEntry, type PanelSidebarSection, type PanelState, type PanelTitle, PanelToolbar, ToolbarItem as PanelToolbarItem, type PanelToolbarProps, ToolbarSeparator as PanelToolbarSeparator, type PointerDragConfig, type PredefinedMessageKey, type ResizeConstraints, type ResizeDir, type ResizeRect, type ResolvedToastOptions, RightPanelRenderer, type SearchResult, type SerializedLayout, type ShowContextMenuOptions, type SidePanelOptions, SidePanelRenderer, type SidePanelRendererProps, Sidebar, type SidebarContextValue, type SidebarHandle, type SidebarProps, type SidebarTab, type SidebarTabContextValue, type SplitDirection, type SplitOrientation, type StyleClasses, type TaskbarVisibility, type ToastAdapter, ToastContainer, type ToastContainerProps, type ToastFunction, type ToastOptions, type ToastPosition, type ToastPromiseMessages, type ToastType, Toolbar, type ToolbarActionItem, ToolbarButton, type ToolbarButtonProps, ToolbarCenter, type ToolbarContextValue, type ToolbarGroupEntry, type ToolbarGroupItem, type ToolbarGroupSubItem, type ToolbarHandle, type ToolbarItem$1 as ToolbarItem, type ToolbarPosition, type ToolbarProps, ToolbarProvider, type ToolbarRadioItem, ToolbarSearchInput, type ToolbarSearchInputProps, type ToolbarSeparator$1 as ToolbarSeparator, ToolbarSpacer, ToolbarToggle, type ToolbarToggleItem, type ToolbarToggleProps, type ToolbarVariant, type UsePanelFloatingWindowReturn, type WindowActions, WindowManager, type WindowManagerProps, WindowManagerProvider, type WindowManagerProviderProps, type WindowState, WorkspaceClient, type WorkspaceClientConfig, computeResizedRect, defaultPredefinedMessages, formatLabel, sidebarSectionToTab, startPointerDrag, toast, useActivePanelContribution, useColorScheme, useFormContainer, useFormatMessage, useMergedSidebarTabs, useMergedToolbarItems, usePanelActions, usePanelContext, usePanelContextMenu, usePanelContribution, usePanelFloatingWindow, usePanelFloatingWindowManager, usePanelId, usePanelSize, usePanelState, usePredefinedMessages, useRegistry, useShowContextMenu, useSidebar, useSidebarTab, useStyleClasses, useToolbar, useWindowManagerActions, useWindowManagerState };
2282
+ export { type BuiltInPanelEvents, type ButtonVariant, type CloseOptions, ConfirmationForm, type ConfirmationFormProps, ContextMenu, type ContextMenuAdapter, type ContextMenuCheckbox, type ContextMenuHandle, type ContextMenuItem, type ContextMenuLabel, type ContextMenuPredefinedMessage, type ContextMenuProps, ContextMenuProvider, type ContextMenuSeparator, type ContextMenuSimpleItem, type ContextMenuSubMenu, DefaultContextMenuAdapter, DockableDesktopProvider, type DockableDesktopProviderProps, type DropPosition, type DropTarget, type FloatAnchor, type FloatingWindow, FormContainerContext, type FormContainerContract, FormContainerProvider, type LayoutGridNode, type LayoutLeafNode, type LayoutNode, LeftPanelRenderer, type ManagedWindowConfig, type MenuItemAction, type MessageFormatter, type ModalOptions, ModalStackRenderer, type OpenPanelOptions, type PanelActions, type PanelContribution, PanelContributionProvider, type PanelDefinition, PanelFloatingWindow, type PanelFloatingWindowManagerHandle, type PanelFloatingWindowProps, type PanelInfo, type PanelInstance, type PanelInstanceId, PanelOverlayRoot, type PanelOverlayRootProps, PanelProvider, PanelRegistry, PanelRegistryClass, type PanelRegistryEntry, type PanelSidebarSection, type PanelState, type PanelTitle, PanelToolbar, ToolbarItem as PanelToolbarItem, type PanelToolbarProps, ToolbarSeparator as PanelToolbarSeparator, type PointerDragConfig, type PredefinedMessageKey, type ResizeConstraints, type ResizeDir, type ResizeRect, type ResolvedToastOptions, RightPanelRenderer, type SearchResult, type SerializedLayout, type ShowContextMenuOptions, type SidePanelOptions, SidePanelRenderer, type SidePanelRendererProps, Sidebar, type SidebarContextValue, type SidebarHandle, type SidebarProps, type SidebarTab, type SidebarTabContextValue, type SplitDirection, type SplitOrientation, type StyleClasses, type TaskbarVisibility, type ToastAdapter, ToastContainer, type ToastContainerProps, type ToastFunction, type ToastOptions, type ToastPosition, type ToastPromiseMessages, type ToastType, Toolbar, type ToolbarActionItem, ToolbarButton, type ToolbarButtonProps, ToolbarCenter, type ToolbarContextValue, type ToolbarGroupEntry, type ToolbarGroupItem, type ToolbarGroupSubItem, type ToolbarHandle, type ToolbarItem$1 as ToolbarItem, type ToolbarPosition, type ToolbarProps, ToolbarProvider, type ToolbarRadioItem, ToolbarSearchInput, type ToolbarSearchInputProps, type ToolbarSeparator$1 as ToolbarSeparator, ToolbarSpacer, ToolbarToggle, type ToolbarToggleItem, type ToolbarToggleProps, type ToolbarVariant, type UsePanelFloatingWindowReturn, type WindowActions, WindowManager, type WindowManagerProps, WindowManagerProvider, type WindowManagerProviderProps, type WindowState, WorkspaceClient, type WorkspaceClientConfig, computeResizedRect, defaultPredefinedMessages, formatLabel, isSerializable, sidebarSectionToTab, startPointerDrag, toast, useActivePanelContribution, useColorScheme, useFormContainer, useFormatMessage, useMergedSidebarTabs, useMergedToolbarItems, usePanelActions, usePanelContext, usePanelContextMenu, usePanelContribution, usePanelFloatingWindow, usePanelFloatingWindowManager, usePanelId, usePanelSize, usePanelState, usePredefinedMessages, useRegistry, useShowContextMenu, useSidebar, useSidebarTab, useStyleClasses, useToolbar, useWindowManagerActions, useWindowManagerState };
package/dist/index.d.ts CHANGED
@@ -110,6 +110,30 @@ interface BuiltInPanelEvents {
110
110
  'panel:restored': {
111
111
  id: string;
112
112
  };
113
+ /**
114
+ * Fires whenever something `saveLayout()` would capture changes — open/close/minimize/restore,
115
+ * and an `openPanel` `dedupeKey` redirect. Coalesces those into one signal for autosave-style
116
+ * consumers, so they don't need to subscribe to four separate events. Does **not** cover a
117
+ * `registerStateProvider` callback's return value changing on its own — that's a pull, there's
118
+ * no way to observe it changing without the panel separately notifying — nor resize/split-ratio
119
+ * drag/dock-rearrange, which have no hooks yet.
120
+ */
121
+ 'layout:changed': Record<string, never>;
122
+ /**
123
+ * Fires from inside `saveLayout()` itself, only when that specific call excluded at least one
124
+ * panel (a panel whose current `props` — static or from a `registerStateProvider` — failed
125
+ * {@link isSerializable}). A passive `PanelInfo.serializable` flag alone isn't enough for this:
126
+ * nobody may be polling it at the exact moment a save happens and something silently drops out
127
+ * (e.g. a floating window rendering data from a live class instance). This is deliberately just
128
+ * a signal, not a UI opinion — decide for yourself whether that becomes a toast, a console
129
+ * warning, or nothing.
130
+ */
131
+ 'layout:panels-excluded': {
132
+ panels: {
133
+ id: string;
134
+ component: string;
135
+ }[];
136
+ };
113
137
  }
114
138
  /** Per-panel definition supplied to WorkspaceClient constructor. */
115
139
  interface PanelDefinition {
@@ -228,6 +252,9 @@ declare class WorkspaceClient<TUserEvents extends Record<string, unknown> = Reco
228
252
  isOpen(id: string): boolean;
229
253
  /** Returns the IDs of all currently open panels. */
230
254
  getOpenPanelIds(): string[];
255
+ /** Finds an already-open panel of the given component with a matching `dedupeKey` (set via
256
+ * `openPanel`'s `dedupeKey` option). Returns `null` if none is open. */
257
+ findPanelId(component: string, dedupeKey: string): string | null;
231
258
  saveLayout(): string;
232
259
  loadLayout(json: string): boolean;
233
260
  setDirection(dir: 'ltr' | 'rtl'): void;
@@ -247,6 +274,12 @@ declare class WorkspaceClient<TUserEvents extends Record<string, unknown> = Reco
247
274
  registerCloseGuard(id: string, guard: () => boolean | Promise<boolean>): void;
248
275
  /** Removes a previously registered close guard. */
249
276
  unregisterCloseGuard(id: string): void;
277
+ /** Registers a callback reporting a panel's current restorable state, pulled fresh on every
278
+ * `saveLayout()` call — see {@link BuiltInPanelEvents}'s `'layout:panels-excluded'` doc and
279
+ * `FormContainerContract.registerStateProvider`. */
280
+ registerStateProvider(id: string, provider: () => unknown): void;
281
+ /** Removes a previously registered state provider. */
282
+ unregisterStateProvider(id: string): void;
250
283
  /** Sets/clears a panel's dirty (unsaved changes) flag. */
251
284
  setPanelDirty(id: string, dirty: boolean, options?: DirtyStateOptions): void;
252
285
  /** Updates a panel's displayed title. */
@@ -277,6 +310,16 @@ declare class WorkspaceClient<TUserEvents extends Record<string, unknown> = Reco
277
310
  onPanelMinimize(callback: (id: string) => void): () => void;
278
311
  /** Subscribe to panel restore events. */
279
312
  onPanelRestore(callback: (id: string) => void): () => void;
313
+ /** Subscribe to the coalesced layout-change signal — see {@link BuiltInPanelEvents}'s
314
+ * `'layout:changed'` doc for exactly what it covers (and doesn't). */
315
+ onLayoutChanged(callback: () => void): () => void;
316
+ /** Subscribe to notification that a `saveLayout()` call excluded one or more panels because
317
+ * their current props weren't serializable — see {@link BuiltInPanelEvents}'s
318
+ * `'layout:panels-excluded'` doc. */
319
+ onPanelsExcluded(callback: (panels: {
320
+ id: string;
321
+ component: string;
322
+ }[]) => void): () => void;
280
323
  }
281
324
 
282
325
  /**
@@ -534,6 +577,51 @@ interface PanelInfo {
534
577
  dirty?: boolean;
535
578
  /** Custom options applied to the automatic unsaved changes modal. */
536
579
  dirtyOptions?: DirtyStateOptions;
580
+ /** Custom per-instance data passed via `openPanel(id, component, { props })`. Unconstrained —
581
+ * any value is accepted, but only a value that passes {@link isSerializable} is actually
582
+ * included in {@link WindowActions.saveLayout}'s output. See {@link PanelInfo.serializable}. */
583
+ props?: Record<string, unknown>;
584
+ /** Whether this panel's current `props` can round-trip through `saveLayout()`/`loadLayout()`.
585
+ * Computed automatically — `true` when no `props` were passed, or when they were and passed
586
+ * {@link isSerializable}. A panel with `serializable: false` still renders and works normally;
587
+ * it's simply excluded from the next `saveLayout()` call (and pruned from `gridRoot`/
588
+ * `floating`/`minimized` in that saved snapshot) rather than corrupting or throwing. */
589
+ serializable: boolean;
590
+ /** Optional dedup key. If another open panel of the same `component` already has this exact
591
+ * key, `openPanel` focuses that existing panel instead of creating a new one — see
592
+ * {@link WindowActions.openPanel}'s `dedupeKey` option and {@link WindowActions.findPanelId}. */
593
+ dedupeKey?: string;
594
+ }
595
+ /**
596
+ * Options accepted by {@link WindowActions.openPanel}.
597
+ */
598
+ interface OpenPanelOptions<P extends object = Record<string, unknown>> {
599
+ /** Override the panel tab/window title. Accepts a plain string or an i18n message descriptor. */
600
+ title?: string | ContextMenuPredefinedMessage;
601
+ /** Initial placement: `'floating'`, `'docked'` (default when a grid exists), or `'tabbed'`. */
602
+ initialTarget?: 'floating' | 'docked' | 'tabbed';
603
+ /** Pin the new floating window to a workspace corner on creation. Has no effect when
604
+ * `initialTarget` is `'docked'` or `'tabbed'`. */
605
+ anchor?: FloatAnchor | null;
606
+ /** Set `state.activePanelId` to this panel. @default true */
607
+ focus?: boolean;
608
+ /**
609
+ * Custom per-instance data spread onto the panel component alongside `panelId`, matching
610
+ * `openModal`/`openLeftPanel`/`openRightPanel`'s already-unconstrained `props` argument — no
611
+ * type restriction here either. Whether a specific value round-trips through `saveLayout()` is
612
+ * a runtime fact, not a type-level guarantee: see {@link PanelInfo.serializable} and the
613
+ * `'layout:panels-excluded'` event.
614
+ */
615
+ props?: P;
616
+ /**
617
+ * If set, and another currently-open panel of the same `component` already has this exact
618
+ * `dedupeKey`, that existing panel is focused instead of opening a new one — the `id`/`props`
619
+ * passed to *this* call are ignored in that case, the same way re-opening an already-open exact
620
+ * `id` already focuses it instead of duplicating it. Use this when multiple call sites might
621
+ * not agree on the same literal `id` for what is semantically the same entity (e.g. "the panel
622
+ * for the document at this path"). See also {@link WindowActions.findPanelId}.
623
+ */
624
+ dedupeKey?: string;
537
625
  }
538
626
  /**
539
627
  * Global window manager state tree representing grid nodes, windows, and panels.
@@ -592,6 +680,8 @@ interface WindowActions {
592
680
  * @param options.initialTarget - Initial placement: `'floating'`, `'docked'` (default when a grid exists), or `'tabbed'`.
593
681
  * @param options.anchor - Pin the new floating window to a workspace corner on creation. Has no effect when `initialTarget` is `'docked'` or `'tabbed'`.
594
682
  * @param options.focus - Set `state.activePanelId` to this panel. @default true
683
+ * @param options.props - Custom per-instance data spread onto the component alongside `panelId`. Unconstrained, like `openModal`/`openLeftPanel`/`openRightPanel`'s `props` — see {@link PanelInfo.serializable} for what determines whether it survives `saveLayout()`.
684
+ * @param options.dedupeKey - If another open panel of the same `component` already has this key, that panel is focused instead of opening a new one.
595
685
  * @example
596
686
  * ```ts
597
687
  * // Open floating and pin to the top-right corner:
@@ -599,14 +689,15 @@ interface WindowActions {
599
689
  *
600
690
  * // Open in the background without stealing focus:
601
691
  * actions.openPanel('prefetch', 'report', { focus: false });
692
+ *
693
+ * // Open with per-instance data, deduped by document path:
694
+ * actions.openPanel(crypto.randomUUID(), 'document', {
695
+ * props: { path: '/notes/todo.md' },
696
+ * dedupeKey: '/notes/todo.md',
697
+ * });
602
698
  * ```
603
699
  */
604
- openPanel: (id: string, component: string, options?: {
605
- title?: string | ContextMenuPredefinedMessage;
606
- initialTarget?: 'floating' | 'docked' | 'tabbed';
607
- anchor?: FloatAnchor | null;
608
- focus?: boolean;
609
- }) => void;
700
+ openPanel: <P extends object = Record<string, unknown>>(id: string, component: string, options?: OpenPanelOptions<P>) => void;
610
701
  /**
611
702
  * Closes a panel immediately, bypassing dirty-state close guards.
612
703
  * For guarded close, use {@link requestClosePanel}.
@@ -691,6 +782,15 @@ interface WindowActions {
691
782
  * @returns Array of panel instance IDs.
692
783
  */
693
784
  getOpenPanelIds: () => string[];
785
+ /**
786
+ * Finds the ID of an already-open panel of the given `component` with a matching `dedupeKey`
787
+ * (set via `openPanel`'s `dedupeKey` option). Uses a synchronous `stateRef` read — safe to
788
+ * call outside of render.
789
+ * @param component - Component key registered in the panel catalog.
790
+ * @param dedupeKey - The dedup key to search for.
791
+ * @returns The matching panel's ID, or `null` if none is open.
792
+ */
793
+ findPanelId: (component: string, dedupeKey: string) => string | null;
694
794
  /**
695
795
  * Serializes the entire workspace state to a JSON string.
696
796
  * Includes grid layout, floating window positions, minimized panels, and panel metadata.
@@ -757,6 +857,23 @@ interface WindowActions {
757
857
  * @param id - Panel instance ID.
758
858
  */
759
859
  unregisterCloseGuard: (id: string) => void;
860
+ /**
861
+ * Registers a callback reporting a docked/floating panel's *current* restorable state, pulled
862
+ * fresh every `saveLayout()` call — for panels whose props alone can't capture state they
863
+ * accumulate after opening (scroll position, an in-progress edit, a view-mode toggle). A panel
864
+ * that registers nothing keeps its static open-time `props` (or none). The returned value goes
865
+ * through the same {@link isSerializable} check as static props, re-evaluated on every save —
866
+ * a provider-backed panel's serializability can flip over its lifetime.
867
+ * @param id - Panel instance ID.
868
+ * @param provider - Called synchronously at each `saveLayout()`; return the current state (or
869
+ * `undefined` to fall back to the static `props` this panel was opened with).
870
+ */
871
+ registerStateProvider: (id: string, provider: () => unknown) => void;
872
+ /**
873
+ * Removes a previously registered state provider.
874
+ * @param id - Panel instance ID.
875
+ */
876
+ unregisterStateProvider: (id: string) => void;
760
877
  /**
761
878
  * Marks a panel as dirty (has unsaved changes). Dirty panels show a visual indicator
762
879
  * and the built-in close guard prompts the user before closing.
@@ -1059,6 +1176,26 @@ interface DockableDesktopProviderProps extends WindowManagerProviderProps {
1059
1176
  */
1060
1177
  declare const DockableDesktopProvider: React$1.FC<DockableDesktopProviderProps>;
1061
1178
 
1179
+ /**
1180
+ * Recursively checks whether a value can round-trip through `JSON.stringify`/`JSON.parse`
1181
+ * without silently losing information.
1182
+ *
1183
+ * Deliberately **not** a `JSON.stringify` try/catch — that call doesn't throw for the actual
1184
+ * failure case this guards against: a function-valued property is simply dropped by
1185
+ * `JSON.stringify`, not rejected. This walks the value tree instead, returning `false` as soon as
1186
+ * it finds a function, symbol, `undefined`, React element, or any non-plain object (a class
1187
+ * instance, `Map`, `Set`, `RegExp`, etc.).
1188
+ *
1189
+ * `Date` is treated as an explicit exception — serializable-enough, matching `JSON.stringify`'s
1190
+ * own behavior — even though it doesn't round-trip back to a `Date` instance on parse. That's a
1191
+ * smaller, more tolerable gotcha than a silently-vanishing function, so it's documented rather
1192
+ * than treated as a disqualifying case.
1193
+ *
1194
+ * Used to decide whether a docked/floating panel's `props` can be included in
1195
+ * `WorkspaceClient.saveLayout()`'s output — see {@link PanelInfo.serializable}.
1196
+ */
1197
+ declare function isSerializable(value: unknown): boolean;
1198
+
1062
1199
  /**
1063
1200
  * Options used when requesting to close a container.
1064
1201
  */
@@ -1079,6 +1216,17 @@ interface FormContainerContract {
1079
1216
  setDirty: (dirty: boolean, options?: DirtyStateOptions) => void;
1080
1217
  /** Register a custom close guard handler. Returning false or a promise resolving to false blocks closing. */
1081
1218
  onCloseRequested: (handler: () => boolean | Promise<boolean>) => (() => void);
1219
+ /**
1220
+ * Registers a callback reporting this panel's *current* restorable state, pulled fresh by
1221
+ * `WorkspaceClient.saveLayout()` every time it's called — for panels whose static open-time
1222
+ * props can't capture state accumulated after opening (scroll position, an in-progress edit, a
1223
+ * view-mode toggle). Only meaningful for docked/floating panels — left/right side panels and
1224
+ * modals already have a complete answer to this via `openLeftPanel`/`openRightPanel`/
1225
+ * `openModal`'s own `props` argument plus `updateInstance`, so this is `undefined` there.
1226
+ * The returned value must be synchronous — `saveLayout()` itself never returns a `Promise`.
1227
+ * Return `undefined` to fall back to the static `props` this panel was opened with.
1228
+ */
1229
+ registerStateProvider?: (getState: () => unknown) => (() => void);
1082
1230
  /** Change the display title of the containing tab or window dynamically. */
1083
1231
  setTitle: (title: string | {
1084
1232
  id: string;
@@ -2131,4 +2279,4 @@ declare function computeResizedRect(dir: ResizeDir, dx: number, dy: number, star
2131
2279
  */
2132
2280
  declare function useColorScheme(): 'dark' | 'light';
2133
2281
 
2134
- export { type BuiltInPanelEvents, type ButtonVariant, type CloseOptions, ConfirmationForm, type ConfirmationFormProps, ContextMenu, type ContextMenuAdapter, type ContextMenuCheckbox, type ContextMenuHandle, type ContextMenuItem, type ContextMenuLabel, type ContextMenuPredefinedMessage, type ContextMenuProps, ContextMenuProvider, type ContextMenuSeparator, type ContextMenuSimpleItem, type ContextMenuSubMenu, DefaultContextMenuAdapter, DockableDesktopProvider, type DockableDesktopProviderProps, type DropPosition, type DropTarget, type FloatAnchor, type FloatingWindow, FormContainerContext, type FormContainerContract, FormContainerProvider, type LayoutGridNode, type LayoutLeafNode, type LayoutNode, LeftPanelRenderer, type ManagedWindowConfig, type MenuItemAction, type MessageFormatter, type ModalOptions, ModalStackRenderer, type PanelActions, type PanelContribution, PanelContributionProvider, type PanelDefinition, PanelFloatingWindow, type PanelFloatingWindowManagerHandle, type PanelFloatingWindowProps, type PanelInfo, type PanelInstance, type PanelInstanceId, PanelOverlayRoot, type PanelOverlayRootProps, PanelProvider, PanelRegistry, PanelRegistryClass, type PanelRegistryEntry, type PanelSidebarSection, type PanelState, type PanelTitle, PanelToolbar, ToolbarItem as PanelToolbarItem, type PanelToolbarProps, ToolbarSeparator as PanelToolbarSeparator, type PointerDragConfig, type PredefinedMessageKey, type ResizeConstraints, type ResizeDir, type ResizeRect, type ResolvedToastOptions, RightPanelRenderer, type SearchResult, type SerializedLayout, type ShowContextMenuOptions, type SidePanelOptions, SidePanelRenderer, type SidePanelRendererProps, Sidebar, type SidebarContextValue, type SidebarHandle, type SidebarProps, type SidebarTab, type SidebarTabContextValue, type SplitDirection, type SplitOrientation, type StyleClasses, type TaskbarVisibility, type ToastAdapter, ToastContainer, type ToastContainerProps, type ToastFunction, type ToastOptions, type ToastPosition, type ToastPromiseMessages, type ToastType, Toolbar, type ToolbarActionItem, ToolbarButton, type ToolbarButtonProps, ToolbarCenter, type ToolbarContextValue, type ToolbarGroupEntry, type ToolbarGroupItem, type ToolbarGroupSubItem, type ToolbarHandle, type ToolbarItem$1 as ToolbarItem, type ToolbarPosition, type ToolbarProps, ToolbarProvider, type ToolbarRadioItem, ToolbarSearchInput, type ToolbarSearchInputProps, type ToolbarSeparator$1 as ToolbarSeparator, ToolbarSpacer, ToolbarToggle, type ToolbarToggleItem, type ToolbarToggleProps, type ToolbarVariant, type UsePanelFloatingWindowReturn, type WindowActions, WindowManager, type WindowManagerProps, WindowManagerProvider, type WindowManagerProviderProps, type WindowState, WorkspaceClient, type WorkspaceClientConfig, computeResizedRect, defaultPredefinedMessages, formatLabel, sidebarSectionToTab, startPointerDrag, toast, useActivePanelContribution, useColorScheme, useFormContainer, useFormatMessage, useMergedSidebarTabs, useMergedToolbarItems, usePanelActions, usePanelContext, usePanelContextMenu, usePanelContribution, usePanelFloatingWindow, usePanelFloatingWindowManager, usePanelId, usePanelSize, usePanelState, usePredefinedMessages, useRegistry, useShowContextMenu, useSidebar, useSidebarTab, useStyleClasses, useToolbar, useWindowManagerActions, useWindowManagerState };
2282
+ export { type BuiltInPanelEvents, type ButtonVariant, type CloseOptions, ConfirmationForm, type ConfirmationFormProps, ContextMenu, type ContextMenuAdapter, type ContextMenuCheckbox, type ContextMenuHandle, type ContextMenuItem, type ContextMenuLabel, type ContextMenuPredefinedMessage, type ContextMenuProps, ContextMenuProvider, type ContextMenuSeparator, type ContextMenuSimpleItem, type ContextMenuSubMenu, DefaultContextMenuAdapter, DockableDesktopProvider, type DockableDesktopProviderProps, type DropPosition, type DropTarget, type FloatAnchor, type FloatingWindow, FormContainerContext, type FormContainerContract, FormContainerProvider, type LayoutGridNode, type LayoutLeafNode, type LayoutNode, LeftPanelRenderer, type ManagedWindowConfig, type MenuItemAction, type MessageFormatter, type ModalOptions, ModalStackRenderer, type OpenPanelOptions, type PanelActions, type PanelContribution, PanelContributionProvider, type PanelDefinition, PanelFloatingWindow, type PanelFloatingWindowManagerHandle, type PanelFloatingWindowProps, type PanelInfo, type PanelInstance, type PanelInstanceId, PanelOverlayRoot, type PanelOverlayRootProps, PanelProvider, PanelRegistry, PanelRegistryClass, type PanelRegistryEntry, type PanelSidebarSection, type PanelState, type PanelTitle, PanelToolbar, ToolbarItem as PanelToolbarItem, type PanelToolbarProps, ToolbarSeparator as PanelToolbarSeparator, type PointerDragConfig, type PredefinedMessageKey, type ResizeConstraints, type ResizeDir, type ResizeRect, type ResolvedToastOptions, RightPanelRenderer, type SearchResult, type SerializedLayout, type ShowContextMenuOptions, type SidePanelOptions, SidePanelRenderer, type SidePanelRendererProps, Sidebar, type SidebarContextValue, type SidebarHandle, type SidebarProps, type SidebarTab, type SidebarTabContextValue, type SplitDirection, type SplitOrientation, type StyleClasses, type TaskbarVisibility, type ToastAdapter, ToastContainer, type ToastContainerProps, type ToastFunction, type ToastOptions, type ToastPosition, type ToastPromiseMessages, type ToastType, Toolbar, type ToolbarActionItem, ToolbarButton, type ToolbarButtonProps, ToolbarCenter, type ToolbarContextValue, type ToolbarGroupEntry, type ToolbarGroupItem, type ToolbarGroupSubItem, type ToolbarHandle, type ToolbarItem$1 as ToolbarItem, type ToolbarPosition, type ToolbarProps, ToolbarProvider, type ToolbarRadioItem, ToolbarSearchInput, type ToolbarSearchInputProps, type ToolbarSeparator$1 as ToolbarSeparator, ToolbarSpacer, ToolbarToggle, type ToolbarToggleItem, type ToolbarToggleProps, type ToolbarVariant, type UsePanelFloatingWindowReturn, type WindowActions, WindowManager, type WindowManagerProps, WindowManagerProvider, type WindowManagerProviderProps, type WindowState, WorkspaceClient, type WorkspaceClientConfig, computeResizedRect, defaultPredefinedMessages, formatLabel, isSerializable, sidebarSectionToTab, startPointerDrag, toast, useActivePanelContribution, useColorScheme, useFormContainer, useFormatMessage, useMergedSidebarTabs, useMergedToolbarItems, usePanelActions, usePanelContext, usePanelContextMenu, usePanelContribution, usePanelFloatingWindow, usePanelFloatingWindowManager, usePanelId, usePanelSize, usePanelState, usePredefinedMessages, useRegistry, useShowContextMenu, useSidebar, useSidebarTab, useStyleClasses, useToolbar, useWindowManagerActions, useWindowManagerState };