@forgeax/app-shell 0.13.0 → 0.14.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/window.d.ts CHANGED
@@ -73,6 +73,19 @@ interface CreateExternalWindowManagerOptions {
73
73
  readonly loadHost: () => Promise<ExternalWindowHost | undefined>;
74
74
  readonly createdTimeoutMs?: number;
75
75
  }
76
+ interface OpenPanelWindowOptions {
77
+ readonly detachSurface: (surface: SurfaceDescriptor, options: Required<Pick<DetachWindowOptions, 'title' | 'width' | 'height'>> & Pick<DetachWindowOptions, 'x' | 'y'>) => Promise<boolean>;
78
+ readonly position?: Readonly<Pick<DetachWindowOptions, 'x' | 'y'>>;
79
+ readonly closeDockPanel?: () => void;
80
+ }
81
+ interface PanelWindowingController {
82
+ openPanelWindow(panelId: string, capability: DetachedWindowCapability | undefined, options: OpenPanelWindowOptions): Promise<boolean>;
83
+ panelForClosedSurface(surface: SurfaceDescriptor): string | undefined;
84
+ }
85
+ declare function canOpenPanelWindow(capability: DetachedWindowCapability | undefined, carrierAvailable: boolean): capability is DetachedWindowCapability;
86
+ declare function shouldShowDetachedPlaceholder(floatingSurfaces: Readonly<Record<string, true>>, surface: SurfaceDescriptor): boolean;
87
+ /** Product-neutral transaction joining a dock placement to a detached carrier. */
88
+ declare function createPanelWindowingController(): PanelWindowingController;
76
89
  /** Product-neutral browser popup carrier with injected surface URL policy. */
77
90
  declare function createBrowserWindowManager(options: CreateBrowserWindowManagerOptions): WindowManager;
78
91
  /** Event-driven external-window lifecycle with all native policy injected. */
@@ -86,4 +99,4 @@ declare function encodeSurfaceQuery(surface: SurfaceDescriptor): string;
86
99
  /** Decode structural identity, or null for a normal shell/invalid entry. */
87
100
  declare function decodeSurfaceFromLocation(search?: string): SurfaceDescriptor | null;
88
101
 
89
- export { type BrowserPopupWindow, type BrowserWindowHost, type CreateBrowserWindowManagerOptions, type CreateExternalWindowManagerOptions, type DetachWindowOptions, type DetachedWindowCapability, type DetachedWindowTarget, type ExternalWindowHandle, type ExternalWindowHost, type ExternalWindowLifecycle, type SurfaceDescriptor, type SurfaceKind, type SurfacePane, type WindowManager, createBrowserWindowManager, createExternalWindowManager, decodeSurfaceFromLocation, encodeSurfaceQuery, surfaceKey, surfaceWindowLabel };
102
+ export { type BrowserPopupWindow, type BrowserWindowHost, type CreateBrowserWindowManagerOptions, type CreateExternalWindowManagerOptions, type DetachWindowOptions, type DetachedWindowCapability, type DetachedWindowTarget, type ExternalWindowHandle, type ExternalWindowHost, type ExternalWindowLifecycle, type OpenPanelWindowOptions, type PanelWindowingController, type SurfaceDescriptor, type SurfaceKind, type SurfacePane, type WindowManager, canOpenPanelWindow, createBrowserWindowManager, createExternalWindowManager, createPanelWindowingController, decodeSurfaceFromLocation, encodeSurfaceQuery, shouldShowDetachedPlaceholder, surfaceKey, surfaceWindowLabel };
package/dist/window.js CHANGED
@@ -1,4 +1,73 @@
1
1
  // src/window.ts
2
+ function canOpenPanelWindow(capability, carrierAvailable) {
3
+ return capability !== void 0 && carrierAvailable;
4
+ }
5
+ function shouldShowDetachedPlaceholder(floatingSurfaces, surface) {
6
+ return floatingSurfaces[surfaceKey(surface)] === true;
7
+ }
8
+ function createPanelWindowingController() {
9
+ const detachedPanels = /* @__PURE__ */ new Map();
10
+ return {
11
+ async openPanelWindow(panelId, capability, options) {
12
+ if (!capability) return false;
13
+ let target;
14
+ try {
15
+ target = capability.createTarget();
16
+ } catch {
17
+ return false;
18
+ }
19
+ const key = surfaceKey(target.surface);
20
+ const closesPlacement = target.dockBehavior === "close";
21
+ let reservation;
22
+ if (closesPlacement) {
23
+ if (!options.closeDockPanel || detachedPanels.has(key)) return false;
24
+ reservation = { panelId, state: "pending" };
25
+ detachedPanels.set(key, reservation);
26
+ }
27
+ let opened;
28
+ try {
29
+ opened = await options.detachSurface(target.surface, {
30
+ title: target.title,
31
+ width: target.width,
32
+ height: target.height,
33
+ ...options.position
34
+ });
35
+ } catch {
36
+ if (reservation && detachedPanels.get(key) === reservation) detachedPanels.delete(key);
37
+ return false;
38
+ }
39
+ if (!opened) {
40
+ if (reservation && detachedPanels.get(key) === reservation) detachedPanels.delete(key);
41
+ return false;
42
+ }
43
+ if (closesPlacement) {
44
+ if (detachedPanels.get(key) !== reservation) return false;
45
+ try {
46
+ options.closeDockPanel();
47
+ } catch {
48
+ if (detachedPanels.get(key) === reservation) detachedPanels.delete(key);
49
+ return false;
50
+ }
51
+ reservation.state = "leased";
52
+ }
53
+ return true;
54
+ },
55
+ panelForClosedSurface(surface) {
56
+ const key = surfaceKey(surface);
57
+ const lease = detachedPanels.get(key);
58
+ if (lease?.state === "pending") {
59
+ detachedPanels.delete(key);
60
+ return void 0;
61
+ }
62
+ if (lease?.state === "leased") {
63
+ queueMicrotask(() => {
64
+ if (detachedPanels.get(key) === lease) detachedPanels.delete(key);
65
+ });
66
+ }
67
+ return lease?.state === "leased" ? lease.panelId : void 0;
68
+ }
69
+ };
70
+ }
2
71
  function currentBrowserHost() {
3
72
  if (typeof window === "undefined" || typeof window.open !== "function") return void 0;
4
73
  return {
@@ -188,10 +257,13 @@ function decodeSurfaceFromLocation(search = typeof window !== "undefined" ? wind
188
257
  };
189
258
  }
190
259
  export {
260
+ canOpenPanelWindow,
191
261
  createBrowserWindowManager,
192
262
  createExternalWindowManager,
263
+ createPanelWindowingController,
193
264
  decodeSurfaceFromLocation,
194
265
  encodeSurfaceQuery,
266
+ shouldShowDetachedPlaceholder,
195
267
  surfaceKey,
196
268
  surfaceWindowLabel
197
269
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgeax/app-shell",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Generic Dock, Panel, Window, and Slot composition primitives",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",