@forgeax/app-shell 0.12.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
@@ -52,8 +52,44 @@ interface CreateBrowserWindowManagerOptions {
52
52
  readonly host?: BrowserWindowHost;
53
53
  readonly closePollIntervalMs?: number;
54
54
  }
55
+ /** Product-neutral handle implemented by event-driven native window adapters. */
56
+ interface ExternalWindowHandle {
57
+ show(): void | Promise<void>;
58
+ focus(): void | Promise<void>;
59
+ close(): void | Promise<void>;
60
+ }
61
+ interface ExternalWindowLifecycle {
62
+ created(): void;
63
+ error(): void;
64
+ destroyed(): void;
65
+ }
66
+ /** Adapter seam: products retain native API loading and concrete create policy. */
67
+ interface ExternalWindowHost {
68
+ getByLabel(label: string): Promise<ExternalWindowHandle | null>;
69
+ create(label: string, surface: SurfaceDescriptor, options: DetachWindowOptions | undefined, lifecycle: ExternalWindowLifecycle): Promise<ExternalWindowHandle>;
70
+ }
71
+ interface CreateExternalWindowManagerOptions {
72
+ readonly canDetach: () => boolean;
73
+ readonly loadHost: () => Promise<ExternalWindowHost | undefined>;
74
+ readonly createdTimeoutMs?: number;
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;
55
89
  /** Product-neutral browser popup carrier with injected surface URL policy. */
56
90
  declare function createBrowserWindowManager(options: CreateBrowserWindowManagerOptions): WindowManager;
91
+ /** Event-driven external-window lifecycle with all native policy injected. */
92
+ declare function createExternalWindowManager(options: CreateExternalWindowManagerOptions): WindowManager;
57
93
  /** Stable identity shared by keep-alive registries and physical carriers. */
58
94
  declare function surfaceKey(surface: SurfaceDescriptor): string;
59
95
  /** Deterministic, injective and carrier-safe label for the complete identity. */
@@ -63,4 +99,4 @@ declare function encodeSurfaceQuery(surface: SurfaceDescriptor): string;
63
99
  /** Decode structural identity, or null for a normal shell/invalid entry. */
64
100
  declare function decodeSurfaceFromLocation(search?: string): SurfaceDescriptor | null;
65
101
 
66
- export { type BrowserPopupWindow, type BrowserWindowHost, type CreateBrowserWindowManagerOptions, type DetachWindowOptions, type DetachedWindowCapability, type DetachedWindowTarget, type SurfaceDescriptor, type SurfaceKind, type SurfacePane, type WindowManager, createBrowserWindowManager, 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 {
@@ -75,6 +144,70 @@ function createBrowserWindowManager(options) {
75
144
  }
76
145
  };
77
146
  }
147
+ function createExternalWindowManager(options) {
148
+ const closeListeners = /* @__PURE__ */ new Set();
149
+ const notifyClosed = (surface) => {
150
+ for (const listener of closeListeners) {
151
+ try {
152
+ listener(surface);
153
+ } catch {
154
+ }
155
+ }
156
+ };
157
+ return {
158
+ canDetach: options.canDetach,
159
+ async openSurfaceWindow(surface, detachOptions) {
160
+ const host = await options.loadHost();
161
+ if (!host) return false;
162
+ const label = surfaceWindowLabel(surface);
163
+ const existing = await host.getByLabel(label);
164
+ if (existing) {
165
+ try {
166
+ await existing.show();
167
+ await existing.focus();
168
+ return true;
169
+ } catch {
170
+ }
171
+ }
172
+ return new Promise((resolve) => {
173
+ let settled = false;
174
+ const finish = (result) => {
175
+ if (settled) return;
176
+ settled = true;
177
+ clearTimeout(timeout);
178
+ resolve(result);
179
+ };
180
+ const timeout = setTimeout(() => finish(true), options.createdTimeoutMs ?? 2e3);
181
+ void host.create(label, surface, detachOptions, {
182
+ created: () => finish(true),
183
+ error: () => finish(false),
184
+ destroyed: () => notifyClosed(surface)
185
+ }).catch(() => finish(false));
186
+ });
187
+ },
188
+ async closeSurfaceWindow(surface) {
189
+ const host = await options.loadHost();
190
+ if (!host) return;
191
+ const existing = await host.getByLabel(surfaceWindowLabel(surface));
192
+ if (!existing) return;
193
+ try {
194
+ await existing.close();
195
+ } catch {
196
+ }
197
+ },
198
+ async isSurfaceWindowOpen(surface) {
199
+ const host = await options.loadHost();
200
+ if (!host) return false;
201
+ return await host.getByLabel(surfaceWindowLabel(surface)) !== null;
202
+ },
203
+ onSurfaceWindowClosed(listener) {
204
+ closeListeners.add(listener);
205
+ return () => {
206
+ closeListeners.delete(listener);
207
+ };
208
+ }
209
+ };
210
+ }
78
211
  function surfaceKey(surface) {
79
212
  const id = surface.id.includes(":") || surface.id.startsWith("~") ? `~${encodeURIComponent(surface.id)}` : surface.id;
80
213
  const pane = surface.pane ? `:${surface.pane}` : "";
@@ -124,9 +257,13 @@ function decodeSurfaceFromLocation(search = typeof window !== "undefined" ? wind
124
257
  };
125
258
  }
126
259
  export {
260
+ canOpenPanelWindow,
127
261
  createBrowserWindowManager,
262
+ createExternalWindowManager,
263
+ createPanelWindowingController,
128
264
  decodeSurfaceFromLocation,
129
265
  encodeSurfaceQuery,
266
+ shouldShowDetachedPlaceholder,
130
267
  surfaceKey,
131
268
  surfaceWindowLabel
132
269
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgeax/app-shell",
3
- "version": "0.12.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",