@forgeax/app-shell 0.13.0 → 0.15.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/chunk-ZYCR2LSP.js +270 -0
- package/dist/react.d.ts +11 -1
- package/dist/react.js +23 -0
- package/dist/window.d.ts +14 -1
- package/dist/window.js +14 -189
- package/package.json +1 -1
|
@@ -0,0 +1,270 @@
|
|
|
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
|
+
}
|
|
71
|
+
function currentBrowserHost() {
|
|
72
|
+
if (typeof window === "undefined" || typeof window.open !== "function") return void 0;
|
|
73
|
+
return {
|
|
74
|
+
screen: window.screen,
|
|
75
|
+
open: (url, target, features) => window.open(url, target, features),
|
|
76
|
+
setInterval: (callback, delayMs) => window.setInterval(callback, delayMs),
|
|
77
|
+
clearInterval: (handle) => window.clearInterval(handle)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function createBrowserWindowManager(options) {
|
|
81
|
+
const host = options.host ?? currentBrowserHost();
|
|
82
|
+
const windows = /* @__PURE__ */ new Map();
|
|
83
|
+
const closePolls = /* @__PURE__ */ new Map();
|
|
84
|
+
const closeListeners = /* @__PURE__ */ new Set();
|
|
85
|
+
const forget = (surface) => {
|
|
86
|
+
const key = surfaceWindowLabel(surface);
|
|
87
|
+
const poll = closePolls.get(key);
|
|
88
|
+
if (poll !== void 0) host?.clearInterval(poll);
|
|
89
|
+
closePolls.delete(key);
|
|
90
|
+
windows.delete(key);
|
|
91
|
+
};
|
|
92
|
+
const notifyClosed = (surface) => {
|
|
93
|
+
for (const listener of closeListeners) {
|
|
94
|
+
try {
|
|
95
|
+
listener(surface);
|
|
96
|
+
} catch {
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
canDetach: () => host !== void 0,
|
|
102
|
+
async openSurfaceWindow(surface, detachOptions) {
|
|
103
|
+
if (!host) return false;
|
|
104
|
+
const label = surfaceWindowLabel(surface);
|
|
105
|
+
const existing = windows.get(label);
|
|
106
|
+
if (existing !== void 0 && !existing.closed) {
|
|
107
|
+
existing.focus();
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (existing !== void 0) forget(surface);
|
|
111
|
+
const width = detachOptions?.width ?? 960;
|
|
112
|
+
const height = detachOptions?.height ?? 720;
|
|
113
|
+
const left = detachOptions?.x ?? Math.max(0, Math.round((host.screen.width - width) / 2));
|
|
114
|
+
const top = detachOptions?.y ?? Math.max(0, Math.round((host.screen.height - height) / 2));
|
|
115
|
+
const popup = host.open(
|
|
116
|
+
options.surfaceUrl(surface),
|
|
117
|
+
label,
|
|
118
|
+
`popup=yes,width=${width},height=${height},left=${left},top=${top},resizable=yes`
|
|
119
|
+
);
|
|
120
|
+
if (popup === null) return false;
|
|
121
|
+
windows.set(label, popup);
|
|
122
|
+
const poll = host.setInterval(() => {
|
|
123
|
+
if (!popup.closed) return;
|
|
124
|
+
forget(surface);
|
|
125
|
+
notifyClosed(surface);
|
|
126
|
+
}, options.closePollIntervalMs ?? 250);
|
|
127
|
+
closePolls.set(label, poll);
|
|
128
|
+
return true;
|
|
129
|
+
},
|
|
130
|
+
async closeSurfaceWindow(surface) {
|
|
131
|
+
const popup = windows.get(surfaceWindowLabel(surface));
|
|
132
|
+
if (popup !== void 0 && !popup.closed) popup.close();
|
|
133
|
+
forget(surface);
|
|
134
|
+
},
|
|
135
|
+
async isSurfaceWindowOpen(surface) {
|
|
136
|
+
const popup = windows.get(surfaceWindowLabel(surface));
|
|
137
|
+
return popup !== void 0 && !popup.closed;
|
|
138
|
+
},
|
|
139
|
+
onSurfaceWindowClosed(listener) {
|
|
140
|
+
closeListeners.add(listener);
|
|
141
|
+
return () => {
|
|
142
|
+
closeListeners.delete(listener);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
};
|
|
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
|
+
}
|
|
211
|
+
function surfaceKey(surface) {
|
|
212
|
+
const id = surface.id.includes(":") || surface.id.startsWith("~") ? `~${encodeURIComponent(surface.id)}` : surface.id;
|
|
213
|
+
const pane = surface.pane ? `:${surface.pane}` : "";
|
|
214
|
+
const instance = surface.instance ? `:instance=${encodeURIComponent(surface.instance)}` : "";
|
|
215
|
+
return `${surface.kind}:${id}${pane}${instance}`;
|
|
216
|
+
}
|
|
217
|
+
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
218
|
+
function utf8ToBase64Url(value) {
|
|
219
|
+
const bytes = new TextEncoder().encode(value);
|
|
220
|
+
let encoded = "";
|
|
221
|
+
for (let index = 0; index < bytes.length; index += 3) {
|
|
222
|
+
const first = bytes[index];
|
|
223
|
+
const second = bytes[index + 1];
|
|
224
|
+
const third = bytes[index + 2];
|
|
225
|
+
encoded += BASE64URL_ALPHABET[first >> 2];
|
|
226
|
+
encoded += BASE64URL_ALPHABET[(first & 3) << 4 | (second ?? 0) >> 4];
|
|
227
|
+
if (second !== void 0) {
|
|
228
|
+
encoded += BASE64URL_ALPHABET[(second & 15) << 2 | (third ?? 0) >> 6];
|
|
229
|
+
}
|
|
230
|
+
if (third !== void 0) encoded += BASE64URL_ALPHABET[third & 63];
|
|
231
|
+
}
|
|
232
|
+
return encoded;
|
|
233
|
+
}
|
|
234
|
+
function surfaceWindowLabel(surface) {
|
|
235
|
+
return `fx-surface-${utf8ToBase64Url(surfaceKey(surface))}`;
|
|
236
|
+
}
|
|
237
|
+
function encodeSurfaceQuery(surface) {
|
|
238
|
+
const params = new URLSearchParams();
|
|
239
|
+
params.set("surface", surface.kind);
|
|
240
|
+
params.set("id", surface.id);
|
|
241
|
+
if (surface.pane) params.set("pane", surface.pane);
|
|
242
|
+
if (surface.instance) params.set("instance", surface.instance);
|
|
243
|
+
return params.toString();
|
|
244
|
+
}
|
|
245
|
+
function decodeSurfaceFromLocation(search = typeof window !== "undefined" ? window.location.search : "") {
|
|
246
|
+
const params = new URLSearchParams(search);
|
|
247
|
+
const kind = params.get("surface");
|
|
248
|
+
const id = params.get("id");
|
|
249
|
+
if (!id || kind !== "plugin" && kind !== "panel") return null;
|
|
250
|
+
const pane = params.get("pane");
|
|
251
|
+
const instance = params.get("instance");
|
|
252
|
+
return {
|
|
253
|
+
kind,
|
|
254
|
+
id,
|
|
255
|
+
pane: pane === "left" || pane === "center" ? pane : void 0,
|
|
256
|
+
instance: instance || void 0
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export {
|
|
261
|
+
canOpenPanelWindow,
|
|
262
|
+
shouldShowDetachedPlaceholder,
|
|
263
|
+
createPanelWindowingController,
|
|
264
|
+
createBrowserWindowManager,
|
|
265
|
+
createExternalWindowManager,
|
|
266
|
+
surfaceKey,
|
|
267
|
+
surfaceWindowLabel,
|
|
268
|
+
encodeSurfaceQuery,
|
|
269
|
+
decodeSurfaceFromLocation
|
|
270
|
+
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, HTMLAttributes, ReactNode } from 'react';
|
|
3
|
+
import { DetachedWindowCapability } from './window.js';
|
|
3
4
|
|
|
4
5
|
/** Stable FNV-1a color bucket for a shell slot name. */
|
|
5
6
|
declare function hashSlotHue(name: string): number;
|
|
@@ -39,6 +40,15 @@ interface PanelSurfaceProps extends Omit<HTMLAttributes<HTMLElement>, 'children'
|
|
|
39
40
|
/** Product-neutral panel section and content presentation. */
|
|
40
41
|
declare function PanelSurface({ id, registered, singleTab, header, content, children, className, ...props }: PanelSurfaceProps): ReactElement;
|
|
41
42
|
|
|
43
|
+
interface DetachedPanelBoundaryProps {
|
|
44
|
+
readonly capability?: DetachedWindowCapability;
|
|
45
|
+
readonly floatingSurfaces: Readonly<Record<string, true>>;
|
|
46
|
+
readonly placeholder: ReactNode;
|
|
47
|
+
readonly children: ReactNode;
|
|
48
|
+
}
|
|
49
|
+
/** Product-neutral presentation switch for a keep-anchor detached surface. */
|
|
50
|
+
declare function DetachedPanelBoundary({ capability, floatingSurfaces, placeholder, children, }: DetachedPanelBoundaryProps): ReactNode;
|
|
51
|
+
|
|
42
52
|
type ShellSlotElement = 'aside' | 'div' | 'main' | 'section';
|
|
43
53
|
interface ShellSlotProps extends HTMLAttributes<HTMLElement> {
|
|
44
54
|
as?: ShellSlotElement;
|
|
@@ -47,4 +57,4 @@ interface ShellSlotProps extends HTMLAttributes<HTMLElement> {
|
|
|
47
57
|
/** Structural shell marker that preserves the caller's semantic element. */
|
|
48
58
|
declare function ShellSlot({ as, name, ...props }: ShellSlotProps): ReactElement;
|
|
49
59
|
|
|
50
|
-
export { type PanelContentPadding, type PanelContentPolicy, type PanelContentScroll, type PanelContentTone, PanelSurface, type PanelSurfaceProps, ResizeHandle, type ResizeHandleProps, ShellSlot, type ShellSlotElement, type ShellSlotProps, SlotDebugOverlay, hashSlotHue, isSlotDebugEnabled, useLocalSize };
|
|
60
|
+
export { DetachedPanelBoundary, type DetachedPanelBoundaryProps, type PanelContentPadding, type PanelContentPolicy, type PanelContentScroll, type PanelContentTone, PanelSurface, type PanelSurfaceProps, ResizeHandle, type ResizeHandleProps, ShellSlot, type ShellSlotElement, type ShellSlotProps, SlotDebugOverlay, hashSlotHue, isSlotDebugEnabled, useLocalSize };
|
package/dist/react.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
shouldShowDetachedPlaceholder
|
|
3
|
+
} from "./chunk-ZYCR2LSP.js";
|
|
4
|
+
|
|
1
5
|
// src/react.tsx
|
|
2
6
|
import { createElement } from "react";
|
|
3
7
|
|
|
@@ -293,6 +297,24 @@ function PanelSurface({
|
|
|
293
297
|
);
|
|
294
298
|
}
|
|
295
299
|
|
|
300
|
+
// src/detached-panel.tsx
|
|
301
|
+
function DetachedPanelBoundary({
|
|
302
|
+
capability,
|
|
303
|
+
floatingSurfaces,
|
|
304
|
+
placeholder,
|
|
305
|
+
children
|
|
306
|
+
}) {
|
|
307
|
+
if (!capability) return children;
|
|
308
|
+
try {
|
|
309
|
+
const target = capability.createTarget();
|
|
310
|
+
if (target.dockBehavior === "keep-anchor" && shouldShowDetachedPlaceholder(floatingSurfaces, target.surface)) {
|
|
311
|
+
return placeholder;
|
|
312
|
+
}
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
return children;
|
|
316
|
+
}
|
|
317
|
+
|
|
296
318
|
// src/react.tsx
|
|
297
319
|
function ShellSlot({
|
|
298
320
|
as = "div",
|
|
@@ -302,6 +324,7 @@ function ShellSlot({
|
|
|
302
324
|
return createElement(as, { ...props, "data-fx-slot": name });
|
|
303
325
|
}
|
|
304
326
|
export {
|
|
327
|
+
DetachedPanelBoundary,
|
|
305
328
|
PanelSurface,
|
|
306
329
|
ResizeHandle,
|
|
307
330
|
ShellSlot,
|
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,197 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
142
|
-
function surfaceKey(surface) {
|
|
143
|
-
const id = surface.id.includes(":") || surface.id.startsWith("~") ? `~${encodeURIComponent(surface.id)}` : surface.id;
|
|
144
|
-
const pane = surface.pane ? `:${surface.pane}` : "";
|
|
145
|
-
const instance = surface.instance ? `:instance=${encodeURIComponent(surface.instance)}` : "";
|
|
146
|
-
return `${surface.kind}:${id}${pane}${instance}`;
|
|
147
|
-
}
|
|
148
|
-
var BASE64URL_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
149
|
-
function utf8ToBase64Url(value) {
|
|
150
|
-
const bytes = new TextEncoder().encode(value);
|
|
151
|
-
let encoded = "";
|
|
152
|
-
for (let index = 0; index < bytes.length; index += 3) {
|
|
153
|
-
const first = bytes[index];
|
|
154
|
-
const second = bytes[index + 1];
|
|
155
|
-
const third = bytes[index + 2];
|
|
156
|
-
encoded += BASE64URL_ALPHABET[first >> 2];
|
|
157
|
-
encoded += BASE64URL_ALPHABET[(first & 3) << 4 | (second ?? 0) >> 4];
|
|
158
|
-
if (second !== void 0) {
|
|
159
|
-
encoded += BASE64URL_ALPHABET[(second & 15) << 2 | (third ?? 0) >> 6];
|
|
160
|
-
}
|
|
161
|
-
if (third !== void 0) encoded += BASE64URL_ALPHABET[third & 63];
|
|
162
|
-
}
|
|
163
|
-
return encoded;
|
|
164
|
-
}
|
|
165
|
-
function surfaceWindowLabel(surface) {
|
|
166
|
-
return `fx-surface-${utf8ToBase64Url(surfaceKey(surface))}`;
|
|
167
|
-
}
|
|
168
|
-
function encodeSurfaceQuery(surface) {
|
|
169
|
-
const params = new URLSearchParams();
|
|
170
|
-
params.set("surface", surface.kind);
|
|
171
|
-
params.set("id", surface.id);
|
|
172
|
-
if (surface.pane) params.set("pane", surface.pane);
|
|
173
|
-
if (surface.instance) params.set("instance", surface.instance);
|
|
174
|
-
return params.toString();
|
|
175
|
-
}
|
|
176
|
-
function decodeSurfaceFromLocation(search = typeof window !== "undefined" ? window.location.search : "") {
|
|
177
|
-
const params = new URLSearchParams(search);
|
|
178
|
-
const kind = params.get("surface");
|
|
179
|
-
const id = params.get("id");
|
|
180
|
-
if (!id || kind !== "plugin" && kind !== "panel") return null;
|
|
181
|
-
const pane = params.get("pane");
|
|
182
|
-
const instance = params.get("instance");
|
|
183
|
-
return {
|
|
184
|
-
kind,
|
|
185
|
-
id,
|
|
186
|
-
pane: pane === "left" || pane === "center" ? pane : void 0,
|
|
187
|
-
instance: instance || void 0
|
|
188
|
-
};
|
|
189
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
canOpenPanelWindow,
|
|
3
|
+
createBrowserWindowManager,
|
|
4
|
+
createExternalWindowManager,
|
|
5
|
+
createPanelWindowingController,
|
|
6
|
+
decodeSurfaceFromLocation,
|
|
7
|
+
encodeSurfaceQuery,
|
|
8
|
+
shouldShowDetachedPlaceholder,
|
|
9
|
+
surfaceKey,
|
|
10
|
+
surfaceWindowLabel
|
|
11
|
+
} from "./chunk-ZYCR2LSP.js";
|
|
190
12
|
export {
|
|
13
|
+
canOpenPanelWindow,
|
|
191
14
|
createBrowserWindowManager,
|
|
192
15
|
createExternalWindowManager,
|
|
16
|
+
createPanelWindowingController,
|
|
193
17
|
decodeSurfaceFromLocation,
|
|
194
18
|
encodeSurfaceQuery,
|
|
19
|
+
shouldShowDetachedPlaceholder,
|
|
195
20
|
surfaceKey,
|
|
196
21
|
surfaceWindowLabel
|
|
197
22
|
};
|