@forgeax/app-shell 0.24.1 → 0.26.0

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/dock.d.ts CHANGED
@@ -28,6 +28,24 @@ declare function getDockRegions(): DockRegionEntry[];
28
28
  /** Track one live mount of a dock panel and return an idempotent release. */
29
29
  declare function trackDockPanelVisibility(panelId: string): () => void;
30
30
  declare function isDockPanelVisible(panelId: string): boolean;
31
+ interface DockPanelVisibilityEventSource {
32
+ onDidAddPanel(listener: (panel: {
33
+ readonly id: string;
34
+ }) => void): {
35
+ dispose(): void;
36
+ };
37
+ onDidRemovePanel(listener: (panel: {
38
+ readonly id: string;
39
+ }) => void): {
40
+ dispose(): void;
41
+ };
42
+ }
43
+ interface DockPanelVisibilityHooks {
44
+ readonly onAdded?: (panelId: string) => void;
45
+ readonly onRemoved?: (panelId: string) => void;
46
+ }
47
+ /** Balance one visibility lease per live panel id across an injected event source. */
48
+ declare function installDockPanelVisibilityTracking(source: DockPanelVisibilityEventSource, hooks?: DockPanelVisibilityHooks): () => void;
31
49
  declare function hasMountedPanelPlacement(panelIds: readonly string[], mountedPanelIds: ReadonlySet<string>): boolean;
32
50
  interface DockLayoutPersistenceScope<Identity> {
33
51
  readonly key: string;
@@ -91,6 +109,34 @@ type DesignedDockPanelPosition = {
91
109
  * Returns undefined when the panel is absent or no live sibling can anchor it.
92
110
  */
93
111
  declare function designedDockPanelPosition(layout: AuthoredDockLayoutLike, panelId: string, isOpen: (id: string) => boolean): DesignedDockPanelPosition | undefined;
112
+ interface DockCommandPanel {
113
+ close(): void;
114
+ setActive(): void;
115
+ }
116
+ interface DockPanelCommandAdapter {
117
+ getPanel(id: string): DockCommandPanel | undefined;
118
+ addPanel(options: {
119
+ id: string;
120
+ component: string;
121
+ title: string;
122
+ position?: {
123
+ referencePanel?: string;
124
+ direction: DockReopenDirection;
125
+ };
126
+ }): void;
127
+ canOpen(id: string): boolean;
128
+ titleFor(id: string): string;
129
+ authoredLayout?(): AuthoredDockLayoutLike | undefined;
130
+ fallbackPanelId?(): string | undefined;
131
+ }
132
+ interface DockPanelCommands {
133
+ open(id: string): boolean;
134
+ close(id: string): boolean;
135
+ focus(id: string): boolean;
136
+ reveal(id: string): boolean;
137
+ }
138
+ /** Own idempotent panel commands while callers retain membership and product policy. */
139
+ declare function createDockPanelCommands(adapter: DockPanelCommandAdapter): DockPanelCommands;
94
140
  type SideEdge = 'left' | 'right';
95
141
  interface RectLike {
96
142
  left: number;
@@ -128,4 +174,4 @@ declare function handleCrossInstanceDrop(event: CrossInstanceDropEvent, targetRe
128
174
  titleFor?: (panelId: string) => string | undefined;
129
175
  }): void;
130
176
 
131
- export { type AuthoredDockLayoutLike, type AuthoredDockNodeLike, type CrossInstanceDropEvent, DOCK_REGIONS, type DesignedDockPanelPosition, type DockLayoutOrientation, type DockLayoutPersistence, type DockLayoutPersistenceAdapter, type DockLayoutPersistenceScope, type DockRegion, type DockRegionEntry, type DockReopenDirection, type DockviewApiLike, type PanelDescriptorLite, REGIONS, type RectLike, type Region, type SerializedDockLayoutLike, type SerializedDockPanelLike, type SideEdge, createDockLayoutPersistence, designedDockPanelPosition, getDockRegions, getDockviewApi, handleCrossInstanceDrop, hasMountedPanelPlacement, isDockPanelVisible, isDockRegion, isOnSideEdge, nearerSideEdge, pruneSerializedDockLayout, registerDockRegion, registerDockviewApi, resolveRegion, trackDockPanelVisibility };
177
+ export { type AuthoredDockLayoutLike, type AuthoredDockNodeLike, type CrossInstanceDropEvent, DOCK_REGIONS, type DesignedDockPanelPosition, type DockCommandPanel, type DockLayoutOrientation, type DockLayoutPersistence, type DockLayoutPersistenceAdapter, type DockLayoutPersistenceScope, type DockPanelCommandAdapter, type DockPanelCommands, type DockPanelVisibilityEventSource, type DockPanelVisibilityHooks, type DockRegion, type DockRegionEntry, type DockReopenDirection, type DockviewApiLike, type PanelDescriptorLite, REGIONS, type RectLike, type Region, type SerializedDockLayoutLike, type SerializedDockPanelLike, type SideEdge, createDockLayoutPersistence, createDockPanelCommands, designedDockPanelPosition, getDockRegions, getDockviewApi, handleCrossInstanceDrop, hasMountedPanelPlacement, installDockPanelVisibilityTracking, isDockPanelVisible, isDockRegion, isOnSideEdge, nearerSideEdge, pruneSerializedDockLayout, registerDockRegion, registerDockviewApi, resolveRegion, trackDockPanelVisibility };
package/dist/dock.js CHANGED
@@ -42,6 +42,59 @@ function trackDockPanelVisibility(panelId) {
42
42
  function isDockPanelVisible(panelId) {
43
43
  return visibleDockPanels.has(panelId);
44
44
  }
45
+ function installDockPanelVisibilityTracking(source, hooks = {}) {
46
+ const releases = /* @__PURE__ */ new Map();
47
+ let active = true;
48
+ const added = source.onDidAddPanel(({ id }) => {
49
+ if (!active) return;
50
+ if (!releases.has(id)) releases.set(id, trackDockPanelVisibility(id));
51
+ try {
52
+ hooks.onAdded?.(id);
53
+ } catch {
54
+ }
55
+ });
56
+ let removed;
57
+ try {
58
+ removed = source.onDidRemovePanel(({ id }) => {
59
+ if (!active) return;
60
+ try {
61
+ releases.get(id)?.();
62
+ } catch {
63
+ }
64
+ releases.delete(id);
65
+ try {
66
+ hooks.onRemoved?.(id);
67
+ } catch {
68
+ }
69
+ });
70
+ } catch (error) {
71
+ active = false;
72
+ try {
73
+ added.dispose();
74
+ } catch {
75
+ }
76
+ throw error;
77
+ }
78
+ return () => {
79
+ if (!active) return;
80
+ active = false;
81
+ try {
82
+ added.dispose();
83
+ } catch {
84
+ }
85
+ try {
86
+ removed.dispose();
87
+ } catch {
88
+ }
89
+ releases.forEach((release) => {
90
+ try {
91
+ release();
92
+ } catch {
93
+ }
94
+ });
95
+ releases.clear();
96
+ };
97
+ }
45
98
  function hasMountedPanelPlacement(panelIds, mountedPanelIds) {
46
99
  return panelIds.some((id) => mountedPanelIds.has(id));
47
100
  }
@@ -183,6 +236,61 @@ function designedDockPanelPosition(layout, panelId, isOpen) {
183
236
  }
184
237
  return void 0;
185
238
  }
239
+ function createDockPanelCommands(adapter) {
240
+ const panel = (id) => {
241
+ try {
242
+ return adapter.getPanel(id);
243
+ } catch {
244
+ return void 0;
245
+ }
246
+ };
247
+ const focus = (id) => {
248
+ const target = panel(id);
249
+ if (!target) return false;
250
+ try {
251
+ target.setActive();
252
+ return true;
253
+ } catch {
254
+ return false;
255
+ }
256
+ };
257
+ const open = (id) => {
258
+ if (panel(id)) return false;
259
+ try {
260
+ if (!adapter.canOpen(id)) return false;
261
+ const layout = adapter.authoredLayout?.();
262
+ const designed = layout ? designedDockPanelPosition(layout, id, (candidate) => panel(candidate) !== void 0) : void 0;
263
+ const referencePanel = designed?.kind === "relative" ? designed.referencePanel : designed === void 0 ? adapter.fallbackPanelId?.() : void 0;
264
+ adapter.addPanel({
265
+ id,
266
+ component: id,
267
+ title: adapter.titleFor(id),
268
+ position: designed?.kind === "edge" ? { direction: designed.direction } : referencePanel ? { referencePanel, direction: designed?.direction ?? "right" } : void 0
269
+ });
270
+ return true;
271
+ } catch {
272
+ return false;
273
+ }
274
+ };
275
+ return {
276
+ open,
277
+ close(id) {
278
+ const target = panel(id);
279
+ if (!target) return false;
280
+ try {
281
+ target.close();
282
+ return true;
283
+ } catch {
284
+ return false;
285
+ }
286
+ },
287
+ focus,
288
+ reveal(id) {
289
+ if (!panel(id) && !open(id)) return false;
290
+ return focus(id);
291
+ }
292
+ };
293
+ }
186
294
  function isOnSideEdge(location) {
187
295
  return location.type === "edge" && (location.position === "left" || location.position === "right");
188
296
  }
@@ -238,11 +346,13 @@ export {
238
346
  DOCK_REGIONS,
239
347
  REGIONS,
240
348
  createDockLayoutPersistence,
349
+ createDockPanelCommands,
241
350
  designedDockPanelPosition,
242
351
  getDockRegions,
243
352
  getDockviewApi,
244
353
  handleCrossInstanceDrop,
245
354
  hasMountedPanelPlacement,
355
+ installDockPanelVisibilityTracking,
246
356
  isDockPanelVisible,
247
357
  isDockRegion,
248
358
  isOnSideEdge,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgeax/app-shell",
3
- "version": "0.24.1",
3
+ "version": "0.26.0",
4
4
  "description": "Generic Dock, Panel, Window, and Slot composition primitives",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",