@forgeax/app-shell 0.11.1 → 0.12.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,41 @@ 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 browser popup carrier with injected surface URL policy. */
56
+ declare function createBrowserWindowManager(options: CreateBrowserWindowManagerOptions): WindowManager;
22
57
  /** Stable identity shared by keep-alive registries and physical carriers. */
23
58
  declare function surfaceKey(surface: SurfaceDescriptor): string;
24
59
  /** Deterministic, injective and carrier-safe label for the complete identity. */
@@ -28,4 +63,4 @@ declare function encodeSurfaceQuery(surface: SurfaceDescriptor): string;
28
63
  /** Decode structural identity, or null for a normal shell/invalid entry. */
29
64
  declare function decodeSurfaceFromLocation(search?: string): SurfaceDescriptor | null;
30
65
 
31
- export { type DetachedWindowCapability, type DetachedWindowTarget, type SurfaceDescriptor, type SurfaceKind, type SurfacePane, decodeSurfaceFromLocation, encodeSurfaceQuery, surfaceKey, surfaceWindowLabel };
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 };
package/dist/window.js CHANGED
@@ -1,4 +1,80 @@
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
+ }
2
78
  function surfaceKey(surface) {
3
79
  const id = surface.id.includes(":") || surface.id.startsWith("~") ? `~${encodeURIComponent(surface.id)}` : surface.id;
4
80
  const pane = surface.pane ? `:${surface.pane}` : "";
@@ -48,6 +124,7 @@ function decodeSurfaceFromLocation(search = typeof window !== "undefined" ? wind
48
124
  };
49
125
  }
50
126
  export {
127
+ createBrowserWindowManager,
51
128
  decodeSurfaceFromLocation,
52
129
  encodeSurfaceQuery,
53
130
  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.12.0",
4
4
  "description": "Generic Dock, Panel, Window, and Slot composition primitives",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",