@forgeax/app-shell 0.11.1 → 0.13.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
@@ -19,6 +19,64 @@ interface DetachedWindowTarget {
19
19
  interface DetachedWindowCapability<Context = void> {
20
20
  createTarget(context: Context): DetachedWindowTarget;
21
21
  }
22
+ interface DetachWindowOptions {
23
+ readonly title?: string;
24
+ readonly width?: number;
25
+ readonly height?: number;
26
+ readonly x?: number;
27
+ readonly y?: number;
28
+ }
29
+ interface WindowManager {
30
+ canDetach(): boolean;
31
+ openSurfaceWindow(surface: SurfaceDescriptor, options?: DetachWindowOptions): Promise<boolean>;
32
+ closeSurfaceWindow(surface: SurfaceDescriptor): Promise<void>;
33
+ isSurfaceWindowOpen(surface: SurfaceDescriptor): Promise<boolean>;
34
+ onSurfaceWindowClosed(listener: (surface: SurfaceDescriptor) => void): () => void;
35
+ }
36
+ interface BrowserPopupWindow {
37
+ readonly closed: boolean;
38
+ focus(): void;
39
+ close(): void;
40
+ }
41
+ interface BrowserWindowHost {
42
+ readonly screen: {
43
+ readonly width: number;
44
+ readonly height: number;
45
+ };
46
+ open(url: string, target: string, features: string): BrowserPopupWindow | null;
47
+ setInterval(callback: () => void, delayMs: number): unknown;
48
+ clearInterval(handle: unknown): void;
49
+ }
50
+ interface CreateBrowserWindowManagerOptions {
51
+ readonly surfaceUrl: (surface: SurfaceDescriptor) => string;
52
+ readonly host?: BrowserWindowHost;
53
+ readonly closePollIntervalMs?: number;
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
+ /** Product-neutral browser popup carrier with injected surface URL policy. */
77
+ declare function createBrowserWindowManager(options: CreateBrowserWindowManagerOptions): WindowManager;
78
+ /** Event-driven external-window lifecycle with all native policy injected. */
79
+ declare function createExternalWindowManager(options: CreateExternalWindowManagerOptions): WindowManager;
22
80
  /** Stable identity shared by keep-alive registries and physical carriers. */
23
81
  declare function surfaceKey(surface: SurfaceDescriptor): string;
24
82
  /** Deterministic, injective and carrier-safe label for the complete identity. */
@@ -28,4 +86,4 @@ declare function encodeSurfaceQuery(surface: SurfaceDescriptor): string;
28
86
  /** Decode structural identity, or null for a normal shell/invalid entry. */
29
87
  declare function decodeSurfaceFromLocation(search?: string): SurfaceDescriptor | null;
30
88
 
31
- export { type DetachedWindowCapability, type DetachedWindowTarget, type SurfaceDescriptor, type SurfaceKind, type SurfacePane, decodeSurfaceFromLocation, encodeSurfaceQuery, surfaceKey, surfaceWindowLabel };
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 };
package/dist/window.js CHANGED
@@ -1,4 +1,144 @@
1
1
  // src/window.ts
2
+ function currentBrowserHost() {
3
+ if (typeof window === "undefined" || typeof window.open !== "function") return void 0;
4
+ return {
5
+ screen: window.screen,
6
+ open: (url, target, features) => window.open(url, target, features),
7
+ setInterval: (callback, delayMs) => window.setInterval(callback, delayMs),
8
+ clearInterval: (handle) => window.clearInterval(handle)
9
+ };
10
+ }
11
+ function createBrowserWindowManager(options) {
12
+ const host = options.host ?? currentBrowserHost();
13
+ const windows = /* @__PURE__ */ new Map();
14
+ const closePolls = /* @__PURE__ */ new Map();
15
+ const closeListeners = /* @__PURE__ */ new Set();
16
+ const forget = (surface) => {
17
+ const key = surfaceWindowLabel(surface);
18
+ const poll = closePolls.get(key);
19
+ if (poll !== void 0) host?.clearInterval(poll);
20
+ closePolls.delete(key);
21
+ windows.delete(key);
22
+ };
23
+ const notifyClosed = (surface) => {
24
+ for (const listener of closeListeners) {
25
+ try {
26
+ listener(surface);
27
+ } catch {
28
+ }
29
+ }
30
+ };
31
+ return {
32
+ canDetach: () => host !== void 0,
33
+ async openSurfaceWindow(surface, detachOptions) {
34
+ if (!host) return false;
35
+ const label = surfaceWindowLabel(surface);
36
+ const existing = windows.get(label);
37
+ if (existing !== void 0 && !existing.closed) {
38
+ existing.focus();
39
+ return true;
40
+ }
41
+ if (existing !== void 0) forget(surface);
42
+ const width = detachOptions?.width ?? 960;
43
+ const height = detachOptions?.height ?? 720;
44
+ const left = detachOptions?.x ?? Math.max(0, Math.round((host.screen.width - width) / 2));
45
+ const top = detachOptions?.y ?? Math.max(0, Math.round((host.screen.height - height) / 2));
46
+ const popup = host.open(
47
+ options.surfaceUrl(surface),
48
+ label,
49
+ `popup=yes,width=${width},height=${height},left=${left},top=${top},resizable=yes`
50
+ );
51
+ if (popup === null) return false;
52
+ windows.set(label, popup);
53
+ const poll = host.setInterval(() => {
54
+ if (!popup.closed) return;
55
+ forget(surface);
56
+ notifyClosed(surface);
57
+ }, options.closePollIntervalMs ?? 250);
58
+ closePolls.set(label, poll);
59
+ return true;
60
+ },
61
+ async closeSurfaceWindow(surface) {
62
+ const popup = windows.get(surfaceWindowLabel(surface));
63
+ if (popup !== void 0 && !popup.closed) popup.close();
64
+ forget(surface);
65
+ },
66
+ async isSurfaceWindowOpen(surface) {
67
+ const popup = windows.get(surfaceWindowLabel(surface));
68
+ return popup !== void 0 && !popup.closed;
69
+ },
70
+ onSurfaceWindowClosed(listener) {
71
+ closeListeners.add(listener);
72
+ return () => {
73
+ closeListeners.delete(listener);
74
+ };
75
+ }
76
+ };
77
+ }
78
+ function createExternalWindowManager(options) {
79
+ const closeListeners = /* @__PURE__ */ new Set();
80
+ const notifyClosed = (surface) => {
81
+ for (const listener of closeListeners) {
82
+ try {
83
+ listener(surface);
84
+ } catch {
85
+ }
86
+ }
87
+ };
88
+ return {
89
+ canDetach: options.canDetach,
90
+ async openSurfaceWindow(surface, detachOptions) {
91
+ const host = await options.loadHost();
92
+ if (!host) return false;
93
+ const label = surfaceWindowLabel(surface);
94
+ const existing = await host.getByLabel(label);
95
+ if (existing) {
96
+ try {
97
+ await existing.show();
98
+ await existing.focus();
99
+ return true;
100
+ } catch {
101
+ }
102
+ }
103
+ return new Promise((resolve) => {
104
+ let settled = false;
105
+ const finish = (result) => {
106
+ if (settled) return;
107
+ settled = true;
108
+ clearTimeout(timeout);
109
+ resolve(result);
110
+ };
111
+ const timeout = setTimeout(() => finish(true), options.createdTimeoutMs ?? 2e3);
112
+ void host.create(label, surface, detachOptions, {
113
+ created: () => finish(true),
114
+ error: () => finish(false),
115
+ destroyed: () => notifyClosed(surface)
116
+ }).catch(() => finish(false));
117
+ });
118
+ },
119
+ async closeSurfaceWindow(surface) {
120
+ const host = await options.loadHost();
121
+ if (!host) return;
122
+ const existing = await host.getByLabel(surfaceWindowLabel(surface));
123
+ if (!existing) return;
124
+ try {
125
+ await existing.close();
126
+ } catch {
127
+ }
128
+ },
129
+ async isSurfaceWindowOpen(surface) {
130
+ const host = await options.loadHost();
131
+ if (!host) return false;
132
+ return await host.getByLabel(surfaceWindowLabel(surface)) !== null;
133
+ },
134
+ onSurfaceWindowClosed(listener) {
135
+ closeListeners.add(listener);
136
+ return () => {
137
+ closeListeners.delete(listener);
138
+ };
139
+ }
140
+ };
141
+ }
2
142
  function surfaceKey(surface) {
3
143
  const id = surface.id.includes(":") || surface.id.startsWith("~") ? `~${encodeURIComponent(surface.id)}` : surface.id;
4
144
  const pane = surface.pane ? `:${surface.pane}` : "";
@@ -48,6 +188,8 @@ function decodeSurfaceFromLocation(search = typeof window !== "undefined" ? wind
48
188
  };
49
189
  }
50
190
  export {
191
+ createBrowserWindowManager,
192
+ createExternalWindowManager,
51
193
  decodeSurfaceFromLocation,
52
194
  encodeSurfaceQuery,
53
195
  surfaceKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgeax/app-shell",
3
- "version": "0.11.1",
3
+ "version": "0.13.0",
4
4
  "description": "Generic Dock, Panel, Window, and Slot composition primitives",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",