@peers-app/peers-ui 0.33.23 → 0.34.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/command-palette/command-palette.js +4 -2
- package/dist/components/router.d.ts +1 -0
- package/dist/components/router.js +4 -1
- package/dist/host-shell/host-shell-consumer.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -1
- package/dist/isolated-screens/config.d.ts +51 -0
- package/dist/isolated-screens/config.js +73 -0
- package/dist/isolated-screens/frame-autostart.d.ts +1 -0
- package/dist/isolated-screens/frame-autostart.js +18 -0
- package/dist/isolated-screens/frame-bridge.d.ts +30 -0
- package/dist/isolated-screens/frame-bridge.js +113 -0
- package/dist/isolated-screens/frame-component.d.ts +6 -0
- package/dist/isolated-screens/frame-component.js +20 -0
- package/dist/isolated-screens/frame-document.d.ts +26 -0
- package/dist/isolated-screens/frame-document.js +69 -0
- package/dist/isolated-screens/frame-policy.d.ts +17 -0
- package/dist/isolated-screens/frame-policy.js +230 -0
- package/dist/isolated-screens/frame-protocol.d.ts +185 -0
- package/dist/isolated-screens/frame-protocol.js +139 -0
- package/dist/isolated-screens/frame-pvars.d.ts +33 -0
- package/dist/isolated-screens/frame-pvars.js +152 -0
- package/dist/isolated-screens/frame-realm.d.ts +12 -0
- package/dist/isolated-screens/frame-realm.js +31 -0
- package/dist/isolated-screens/frame-runtime.d.ts +5 -0
- package/dist/isolated-screens/frame-runtime.js +416 -0
- package/dist/isolated-screens/frame-storage.d.ts +43 -0
- package/dist/isolated-screens/frame-storage.js +85 -0
- package/dist/isolated-screens/index.d.ts +3 -0
- package/dist/isolated-screens/index.js +13 -0
- package/dist/isolated-screens/isolated-screen.d.ts +191 -0
- package/dist/isolated-screens/isolated-screen.js +684 -0
- package/dist/isolated-screens/piece-frames.d.ts +27 -0
- package/dist/isolated-screens/piece-frames.js +311 -0
- package/dist/isolated-screens/piece-reach.d.ts +11 -0
- package/dist/isolated-screens/piece-reach.js +56 -0
- package/dist/isolated-screens/port-channel.d.ts +47 -0
- package/dist/isolated-screens/port-channel.js +153 -0
- package/dist/isolated-screens/routes-sandbox.d.ts +8 -0
- package/dist/isolated-screens/routes-sandbox.js +130 -0
- package/dist/isolated-screens/screen-tab-context.d.ts +4 -0
- package/dist/isolated-screens/screen-tab-context.js +6 -0
- package/dist/isolated-screens/test-ports.d.ts +3 -0
- package/dist/isolated-screens/test-ports.js +21 -0
- package/dist/mentions/mentions-client.js +9 -0
- package/dist/notifications/index.js +9 -5
- package/dist/operator-console/console-copy.d.ts +15 -0
- package/dist/operator-console/console-copy.js +97 -0
- package/dist/operator-console/console-header.d.ts +33 -0
- package/dist/operator-console/console-header.js +67 -0
- package/dist/operator-console/console-input.d.ts +20 -0
- package/dist/operator-console/console-input.js +313 -0
- package/dist/operator-console/console-repl.d.ts +7 -0
- package/dist/operator-console/console-repl.js +108 -0
- package/dist/operator-console/console-scope.d.ts +45 -0
- package/dist/operator-console/console-scope.js +174 -0
- package/dist/operator-console/console-screen.d.ts +8 -0
- package/dist/operator-console/console-screen.js +32 -0
- package/dist/operator-console/console-session.d.ts +106 -0
- package/dist/operator-console/console-session.js +567 -0
- package/dist/operator-console/console-test-host.d.ts +21 -0
- package/dist/operator-console/console-test-host.js +114 -0
- package/dist/operator-console/console-theme.d.ts +41 -0
- package/dist/operator-console/console-theme.js +55 -0
- package/dist/operator-console/console-value.d.ts +27 -0
- package/dist/operator-console/console-value.js +291 -0
- package/dist/operator-console/operator-console-state.js +3 -1
- package/dist/operator-console/operator-console.d.ts +8 -21
- package/dist/operator-console/operator-console.js +8 -61
- package/dist/root-layout/app-shell-height.d.ts +24 -3
- package/dist/root-layout/app-shell-height.js +25 -4
- package/dist/root-layout/host-app-menu.d.ts +17 -0
- package/dist/root-layout/host-app-menu.js +22 -0
- package/dist/root-layout/layouts/full-screen-layout.js +7 -1
- package/dist/root-layout/layouts/tabs-with-console-layout.js +1 -1
- package/dist/system-apps/console.app.d.ts +15 -0
- package/dist/system-apps/console.app.js +25 -0
- package/dist/system-apps/index.d.ts +1 -0
- package/dist/system-apps/index.js +6 -1
- package/dist/tabs-layout/tabs-layout.js +13 -20
- package/dist/tabs-layout/tabs-state.js +39 -16
- package/dist/theme.css +66 -0
- package/dist/ui-contracts/piece-height.d.ts +18 -0
- package/dist/ui-contracts/piece-height.js +15 -0
- package/dist/ui-contracts/piece-host.d.ts +24 -1
- package/dist/ui-contracts/piece-host.js +53 -2
- package/dist/ui-contracts/piece-props.d.ts +16 -0
- package/dist/ui-contracts/piece-props.js +39 -0
- package/dist/ui-contracts/piece-resolution.d.ts +5 -0
- package/dist/ui-contracts/piece-resolution.js +38 -2
- package/dist/ui-contracts/piece.d.ts +2 -7
- package/dist/ui-contracts/piece.js +22 -37
- package/dist/ui-contracts/popover-surface.d.ts +14 -0
- package/dist/ui-contracts/popover-surface.js +32 -3
- package/dist/ui-inspection/dom-actions.d.ts +23 -0
- package/dist/ui-inspection/dom-actions.js +169 -0
- package/dist/ui-inspection/dom-inspector.d.ts +20 -0
- package/dist/ui-inspection/dom-inspector.js +184 -0
- package/dist/ui-inspection/index.d.ts +73 -0
- package/dist/ui-inspection/index.js +147 -0
- package/dist/ui-router/find-route.d.ts +6 -0
- package/dist/ui-router/find-route.js +22 -0
- package/dist/ui-router/routes-loader.js +23 -4
- package/dist/ui-router/runnable-version.js +3 -0
- package/dist/ui-router/ui-loader.d.ts +6 -1
- package/dist/ui-router/ui-loader.js +102 -26
- package/package.json +3 -3
|
@@ -13,6 +13,7 @@ exports.executeCommand = executeCommand;
|
|
|
13
13
|
exports.initializeCommandPalette = initializeCommandPalette;
|
|
14
14
|
exports.destroyCommandPalette = destroyCommandPalette;
|
|
15
15
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
16
|
+
const frame_realm_1 = require("../isolated-screens/frame-realm");
|
|
16
17
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
17
18
|
/** Whether the command palette is open. In memory only. */
|
|
18
19
|
exports.isCommandPaletteOpen = (0, peers_sdk_1.observable)(false);
|
|
@@ -234,7 +235,8 @@ function destroyCommandPalette() {
|
|
|
234
235
|
document.removeEventListener("keydown", handleKeyDown);
|
|
235
236
|
shortcutToCommandMap.clear();
|
|
236
237
|
}
|
|
237
|
-
// Auto-initialize when this module loads
|
|
238
|
-
|
|
238
|
+
// Auto-initialize when this module loads. Not in an isolated screen's frame: there the host's
|
|
239
|
+
// palette answers, since the frame forwards ⌘ and Ctrl keys to it.
|
|
240
|
+
if (typeof window !== "undefined" && !(0, frame_realm_1.isInFrame)()) {
|
|
239
241
|
initializeCommandPalette();
|
|
240
242
|
}
|
|
@@ -52,6 +52,7 @@ const tool_list_1 = require("../screens/tools/tool-list");
|
|
|
52
52
|
const variable_details_1 = require("../screens/variables/variable-details");
|
|
53
53
|
const variable_list_1 = require("../screens/variables/variable-list");
|
|
54
54
|
const ui_loader_1 = require("../ui-router/ui-loader");
|
|
55
|
+
require("../operator-console/console-screen");
|
|
55
56
|
require("../screens/console-logs/console-logs-list");
|
|
56
57
|
require("../screens/identity");
|
|
57
58
|
require("../screens/network-viewer");
|
|
@@ -83,7 +84,9 @@ function Router({ path: providedPath } = {}) {
|
|
|
83
84
|
if (path === "settings" || path === "profile") {
|
|
84
85
|
return (0, jsx_runtime_1.jsx)(settings_page_1.SettingsPage, {});
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
+
// Matching uses the normalized path; an isolated screen gets the tab's path as it is, with
|
|
88
|
+
// its query and case.
|
|
89
|
+
const ui = (0, ui_loader_1.UIRouter)({ path, props: {}, uiCategory: "screen", tabPath: originalPath });
|
|
87
90
|
if (ui) {
|
|
88
91
|
return ui;
|
|
89
92
|
}
|
|
@@ -6,6 +6,8 @@ exports.openOnHost = openOnHost;
|
|
|
6
6
|
exports.openLink = openLink;
|
|
7
7
|
exports.openInEditorOnHost = openInEditorOnHost;
|
|
8
8
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
9
|
+
const frame_protocol_1 = require("../isolated-screens/frame-protocol");
|
|
10
|
+
const frame_realm_1 = require("../isolated-screens/frame-realm");
|
|
9
11
|
/**
|
|
10
12
|
* Shared handle for System Host Shell on the local host. Calls name no data context, so the
|
|
11
13
|
* host runs them in the personal context, where the signed-in user has Self access.
|
|
@@ -38,6 +40,12 @@ const LINK_SCHEMES = new Set(["http:", "https:", "mailto:"]);
|
|
|
38
40
|
* @param url - An `http:`, `https:`, or `mailto:` URL.
|
|
39
41
|
*/
|
|
40
42
|
async function openLink(url) {
|
|
43
|
+
// An isolated screen asks its host, which opens it the same way.
|
|
44
|
+
const host = (0, frame_realm_1.frameHost)();
|
|
45
|
+
if (host) {
|
|
46
|
+
await host.request(frame_protocol_1.FrameRequest.openLink, { url });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
41
49
|
let scheme;
|
|
42
50
|
try {
|
|
43
51
|
scheme = new URL(url).protocol;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from "./graph/ring-layout";
|
|
|
17
17
|
export * from "./groups";
|
|
18
18
|
export * from "./hooks";
|
|
19
19
|
export { openLink } from "./host-shell/host-shell-consumer";
|
|
20
|
+
export * from "./isolated-screens";
|
|
20
21
|
export * from "./local-network/local-network-access";
|
|
21
22
|
export * from "./local-network/local-network-offer";
|
|
22
23
|
export { MentionChip, MentionGroupContext, type MentionState, useMentionPlace, } from "./mentions/mention-chip";
|
|
@@ -33,3 +34,4 @@ export { selectedRootLayoutId, setRootLayout } from "./root-layout/root-layout-s
|
|
|
33
34
|
export * from "./tabs-layout/tabs-layout";
|
|
34
35
|
export { activeTabId, activeTabs, closeCurrentTab, goToTabPath, TabState, updateActiveTabTitle, } from "./tabs-layout/tabs-state";
|
|
35
36
|
export * from "./ui-contracts";
|
|
37
|
+
export { actOnUI, FRAME_SELECTOR_PREFIX, type IUIActionInput, inspectUI, type UIActionOperation, } from "./ui-inspection";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = exports.configureIconSearchIndexes = void 0;
|
|
17
|
+
exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = exports.configureIconSearchIndexes = void 0;
|
|
18
18
|
__exportStar(require("./components/color-picker"), exports);
|
|
19
19
|
__exportStar(require("./components/data-grid"), exports);
|
|
20
20
|
__exportStar(require("./components/icon"), exports);
|
|
@@ -40,6 +40,7 @@ __exportStar(require("./groups"), exports);
|
|
|
40
40
|
__exportStar(require("./hooks"), exports);
|
|
41
41
|
var host_shell_consumer_1 = require("./host-shell/host-shell-consumer");
|
|
42
42
|
Object.defineProperty(exports, "openLink", { enumerable: true, get: function () { return host_shell_consumer_1.openLink; } });
|
|
43
|
+
__exportStar(require("./isolated-screens"), exports);
|
|
43
44
|
__exportStar(require("./local-network/local-network-access"), exports);
|
|
44
45
|
__exportStar(require("./local-network/local-network-offer"), exports);
|
|
45
46
|
// Mentions for package screens: chips, and opening a mentioned record. Search stays inside the
|
|
@@ -81,3 +82,8 @@ Object.defineProperty(exports, "goToTabPath", { enumerable: true, get: function
|
|
|
81
82
|
Object.defineProperty(exports, "updateActiveTabTitle", { enumerable: true, get: function () { return tabs_state_1.updateActiveTabTitle; } });
|
|
82
83
|
// UI contracts: embed another package's UI pieces by contract (docs/Packages/ui-contracts.md).
|
|
83
84
|
__exportStar(require("./ui-contracts"), exports);
|
|
85
|
+
// `peers ui inspect`, `click`, `set` and `scroll`, across the window and its isolated screens.
|
|
86
|
+
var ui_inspection_1 = require("./ui-inspection");
|
|
87
|
+
Object.defineProperty(exports, "actOnUI", { enumerable: true, get: function () { return ui_inspection_1.actOnUI; } });
|
|
88
|
+
Object.defineProperty(exports, "FRAME_SELECTOR_PREFIX", { enumerable: true, get: function () { return ui_inspection_1.FRAME_SELECTOR_PREFIX; } });
|
|
89
|
+
Object.defineProperty(exports, "inspectUI", { enumerable: true, get: function () { return ui_inspection_1.inspectUI; } });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IContractTransport, IUIPackageSession } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Which package screens run isolated, and what the host app gives peers-ui to run them.
|
|
4
|
+
*
|
|
5
|
+
* A host app (Electron's renderer, the PWA) turns isolation on by calling
|
|
6
|
+
* {@link configureIsolatedScreens} with two things only it can provide: the frame runtime's
|
|
7
|
+
* source (its own frame entry, built for a frame), and a way to open a contract session that acts
|
|
8
|
+
* as one package. Without it, as in tests, every screen runs in the shared window as before.
|
|
9
|
+
*/
|
|
10
|
+
/** What the host app provides to run screens in frames. */
|
|
11
|
+
export interface IIsolatedScreensHost {
|
|
12
|
+
/**
|
|
13
|
+
* The frame runtime's source: the host's frame entry, built to run as one script in a frame.
|
|
14
|
+
* Read once, the first time a screen opens.
|
|
15
|
+
*/
|
|
16
|
+
loadRuntimeSource(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Open a contract session for one screen. Its calls act as the user, reaching only what the
|
|
19
|
+
* package declares (`createLocalUserContextContractProviderRouter`'s `uiPackage`).
|
|
20
|
+
*
|
|
21
|
+
* @param session - The screen's package and version.
|
|
22
|
+
* @returns The session's transport, how to close it, and, for a transport that can reconnect
|
|
23
|
+
* without its subscriptions, how to hear that it did.
|
|
24
|
+
*/
|
|
25
|
+
openSession(session: IUIPackageSession): {
|
|
26
|
+
transport: IContractTransport;
|
|
27
|
+
dispose(): void;
|
|
28
|
+
onReset?(listener: () => void): () => void;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Packages whose screens still run in the shared window, each for something isolated screens
|
|
33
|
+
* can't do for it yet. The list only shrinks: each entry goes when its reason does.
|
|
34
|
+
*/
|
|
35
|
+
export declare const SHARED_WINDOW_PACKAGES: ReadonlyMap<string, string>;
|
|
36
|
+
/**
|
|
37
|
+
* Turn isolated screens on. The host app calls it once at startup, before the first screen.
|
|
38
|
+
*
|
|
39
|
+
* @param host - The runtime source and the session opener, or `undefined` to turn it off (tests).
|
|
40
|
+
*/
|
|
41
|
+
export declare function configureIsolatedScreens(host: IIsolatedScreensHost | undefined): void;
|
|
42
|
+
/** The host's isolation hooks, when isolation is on. */
|
|
43
|
+
export declare function isolatedScreensHost(): IIsolatedScreensHost | undefined;
|
|
44
|
+
/** The frame runtime's source, read once. A failed read is tried again next time. */
|
|
45
|
+
export declare function frameRuntimeSource(): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a package's screens run in frames here.
|
|
48
|
+
*
|
|
49
|
+
* @param packageId - The package.
|
|
50
|
+
*/
|
|
51
|
+
export declare function runsIsolated(packageId: string | undefined): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHARED_WINDOW_PACKAGES = void 0;
|
|
4
|
+
exports.configureIsolatedScreens = configureIsolatedScreens;
|
|
5
|
+
exports.isolatedScreensHost = isolatedScreensHost;
|
|
6
|
+
exports.frameRuntimeSource = frameRuntimeSource;
|
|
7
|
+
exports.runsIsolated = runsIsolated;
|
|
8
|
+
let isolatedHost;
|
|
9
|
+
let runtimeSource;
|
|
10
|
+
/**
|
|
11
|
+
* Packages whose screens still run in the shared window, each for something isolated screens
|
|
12
|
+
* can't do for it yet. The list only shrinks: each entry goes when its reason does.
|
|
13
|
+
*/
|
|
14
|
+
exports.SHARED_WINDOW_PACKAGES = new Map([
|
|
15
|
+
[
|
|
16
|
+
"00mh0wlipjixk2gqmurbwee0o",
|
|
17
|
+
"Tasks: its timer overlay shows over every app (global widgets, task 00mwiaq9279nj7u3a8cchwjin)",
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"00mwi9ux5ate4rpcr26wdedph",
|
|
21
|
+
"Operator: its overlay shows over every app and listens to keys in any app (global widgets), and it uses the microphone",
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"00mp0gayf4f9hotacqsobyv6w",
|
|
25
|
+
"Voice Hub: it uses the microphone and wake word models, and reads its skills' widgets' DOM (Voice Skill widgets as a UI contract, embedded-ui.md slice 5)",
|
|
26
|
+
],
|
|
27
|
+
[
|
|
28
|
+
"00mkhtkl95byv5o2xsw12mi2x",
|
|
29
|
+
"Family Hub: it embeds other packages' widgets by UI id and uses Electron's <webview> (embedded-ui.md slices 4 and 5)",
|
|
30
|
+
],
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* Turn isolated screens on. The host app calls it once at startup, before the first screen.
|
|
34
|
+
*
|
|
35
|
+
* @param host - The runtime source and the session opener, or `undefined` to turn it off (tests).
|
|
36
|
+
*/
|
|
37
|
+
function configureIsolatedScreens(host) {
|
|
38
|
+
isolatedHost = host;
|
|
39
|
+
runtimeSource = undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The host's isolation hooks, when isolation is on. */
|
|
42
|
+
function isolatedScreensHost() {
|
|
43
|
+
return isolatedHost;
|
|
44
|
+
}
|
|
45
|
+
/** The frame runtime's source, read once. A failed read is tried again next time. */
|
|
46
|
+
function frameRuntimeSource() {
|
|
47
|
+
if (!isolatedHost)
|
|
48
|
+
return Promise.reject(new Error("Isolated screens aren't configured"));
|
|
49
|
+
runtimeSource ??= isolatedHost.loadRuntimeSource().catch((error) => {
|
|
50
|
+
runtimeSource = undefined;
|
|
51
|
+
throw error;
|
|
52
|
+
});
|
|
53
|
+
return runtimeSource;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Whether a package's screens run in frames here.
|
|
57
|
+
*
|
|
58
|
+
* @param packageId - The package.
|
|
59
|
+
*/
|
|
60
|
+
function runsIsolated(packageId) {
|
|
61
|
+
if (!isolatedHost || !packageId)
|
|
62
|
+
return false;
|
|
63
|
+
return !exports.SHARED_WINDOW_PACKAGES.has(packageId) || isolatesSharedWindowPackagesForTests();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A test seam: the PWA's browser tests set `globalThis.__PEERS_ISOLATE_ALL_SCREENS__` before the
|
|
67
|
+
* page loads, so Tasks, the one package a fresh account has, runs isolated too. Nothing in Peers
|
|
68
|
+
* sets it.
|
|
69
|
+
*/
|
|
70
|
+
function isolatesSharedWindowPackagesForTests() {
|
|
71
|
+
return (globalThis.__PEERS_ISOLATE_ALL_SCREENS__ ===
|
|
72
|
+
true);
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const frame_bridge_1 = require("./frame-bridge");
|
|
4
|
+
const frame_document_1 = require("./frame-document");
|
|
5
|
+
/**
|
|
6
|
+
* The first module an isolated screen's frame runtime runs: it takes the port the frame's
|
|
7
|
+
* document left for it and installs the bridge, before peers-ui or any package code loads. A host
|
|
8
|
+
* app's frame entry imports it first (`@peers-app/peers-ui/dist/isolated-screens/frame-autostart`),
|
|
9
|
+
* then sets the window's `React`, `PeersSDK`, `PeersUI` and `zod` globals and calls
|
|
10
|
+
* `startFrameRuntime`.
|
|
11
|
+
*/
|
|
12
|
+
const frameWindow = window;
|
|
13
|
+
const port = frameWindow[frame_document_1.FRAME_PORT_GLOBAL];
|
|
14
|
+
if (!port) {
|
|
15
|
+
throw new Error("The frame runtime runs only in an isolated screen's frame, which hands it a port");
|
|
16
|
+
}
|
|
17
|
+
delete frameWindow[frame_document_1.FRAME_PORT_GLOBAL];
|
|
18
|
+
(0, frame_bridge_1.installFrameBridge)(port);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type IFrameStorage } from "./frame-storage";
|
|
2
|
+
import { type IPortChannel, type IPortLike } from "./port-channel";
|
|
3
|
+
/**
|
|
4
|
+
* The frame side of an isolated package screen's bridge to its host: everything the SDK reaches
|
|
5
|
+
* the host through, pointed at the frame's port instead. It's installed before peers-ui or any
|
|
6
|
+
* package code loads, so their module-level variables and calls go through it from the start.
|
|
7
|
+
*
|
|
8
|
+
* - Legacy RPC (`rpcServerCalls`) is asked of the host, whose policy answers a few reads and
|
|
9
|
+
* refuses the rest.
|
|
10
|
+
* - Contract calls go over the frame's own session, which the host opened for its package.
|
|
11
|
+
* - Persistent variables are the host's: a package's are stored under its id.
|
|
12
|
+
* - `localStorage` is the package's own, kept by the host.
|
|
13
|
+
*/
|
|
14
|
+
/** What {@link installFrameBridge} sets up, for the frame runtime. */
|
|
15
|
+
export interface IFrameBridge {
|
|
16
|
+
/** The channel to the host. */
|
|
17
|
+
host: IPortChannel;
|
|
18
|
+
/** The frame's `localStorage`. */
|
|
19
|
+
storage: IFrameStorage;
|
|
20
|
+
}
|
|
21
|
+
/** The bridge, once {@link installFrameBridge} ran. */
|
|
22
|
+
export declare function frameBridge(): IFrameBridge | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Point this realm's SDK at the host through `port`. Runs once, first thing in the frame.
|
|
25
|
+
*
|
|
26
|
+
* @param port - The port the host handed the frame with the runtime.
|
|
27
|
+
* @param win - The frame's window (tests pass a stand-in).
|
|
28
|
+
* @returns The bridge.
|
|
29
|
+
*/
|
|
30
|
+
export declare function installFrameBridge(port: IPortLike, win?: Window & typeof globalThis): IFrameBridge;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.frameBridge = frameBridge;
|
|
4
|
+
exports.installFrameBridge = installFrameBridge;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const frame_protocol_1 = require("./frame-protocol");
|
|
7
|
+
const frame_realm_1 = require("./frame-realm");
|
|
8
|
+
const frame_storage_1 = require("./frame-storage");
|
|
9
|
+
const port_channel_1 = require("./port-channel");
|
|
10
|
+
let installed;
|
|
11
|
+
/** The bridge, once {@link installFrameBridge} ran. */
|
|
12
|
+
function frameBridge() {
|
|
13
|
+
return installed;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The frame's contract transport: calls go to the host, and the host's notifications for the
|
|
17
|
+
* frame's session come back to whichever transport is current. A reset makes a new one, so the
|
|
18
|
+
* old one's handlers hear nothing more.
|
|
19
|
+
*/
|
|
20
|
+
function portContractTransports(host) {
|
|
21
|
+
let current = new Map();
|
|
22
|
+
host.onNotify(frame_protocol_1.HostNotice.contract, ({ channel, args }) => {
|
|
23
|
+
for (const handler of current.get(channel) ?? []) {
|
|
24
|
+
try {
|
|
25
|
+
void Promise.resolve(handler(...(Array.isArray(args) ? args : []))).catch((error) => console.error(`[frame] contract notification on ${channel} failed`, error));
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error(`[frame] contract notification on ${channel} failed`, error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return () => {
|
|
33
|
+
const handlers = new Map();
|
|
34
|
+
current = handlers;
|
|
35
|
+
return {
|
|
36
|
+
emit: (channel, ...args) => host.request(frame_protocol_1.FrameRequest.contractEmit, { channel, args }),
|
|
37
|
+
on: (channel, handler) => {
|
|
38
|
+
let set = handlers.get(channel);
|
|
39
|
+
if (!set) {
|
|
40
|
+
set = new Set();
|
|
41
|
+
handlers.set(channel, set);
|
|
42
|
+
}
|
|
43
|
+
set.add(handler);
|
|
44
|
+
return () => {
|
|
45
|
+
set?.delete(handler);
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function framePersistentVarBackend(host) {
|
|
52
|
+
const listeners = new Map();
|
|
53
|
+
host.onNotify(frame_protocol_1.HostNotice.pvarChanged, ({ bindingId, value }) => {
|
|
54
|
+
listeners.get(bindingId)?.(value);
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
bind(request, onChange) {
|
|
58
|
+
const bindingId = (0, peers_sdk_1.newid)();
|
|
59
|
+
listeners.set(bindingId, onChange);
|
|
60
|
+
return {
|
|
61
|
+
loaded: host.request(frame_protocol_1.FrameRequest.pvarBind, { bindingId, request }),
|
|
62
|
+
write: async (value) => {
|
|
63
|
+
await host.request(frame_protocol_1.FrameRequest.pvarWrite, { bindingId, value });
|
|
64
|
+
},
|
|
65
|
+
delete: async () => {
|
|
66
|
+
await host.request(frame_protocol_1.FrameRequest.pvarDelete, { bindingId });
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Point this realm's SDK at the host through `port`. Runs once, first thing in the frame.
|
|
74
|
+
*
|
|
75
|
+
* @param port - The port the host handed the frame with the runtime.
|
|
76
|
+
* @param win - The frame's window (tests pass a stand-in).
|
|
77
|
+
* @returns The bridge.
|
|
78
|
+
*/
|
|
79
|
+
function installFrameBridge(port, win = window) {
|
|
80
|
+
if (installed)
|
|
81
|
+
return installed;
|
|
82
|
+
const host = (0, port_channel_1.openPortChannel)(port);
|
|
83
|
+
(0, frame_realm_1.setFrameHost)(host);
|
|
84
|
+
for (const name of Object.keys(peers_sdk_1.rpcServerCalls)) {
|
|
85
|
+
peers_sdk_1.rpcServerCalls[name] = (...args) => host.request(frame_protocol_1.FrameRequest.rpc, { name, args });
|
|
86
|
+
}
|
|
87
|
+
// Nothing to flush in a frame: the host owns the databases.
|
|
88
|
+
peers_sdk_1.rpcServerCalls.flushDatabases = async () => { };
|
|
89
|
+
host.onNotify(frame_protocol_1.HostNotice.event, (event) => {
|
|
90
|
+
void peers_sdk_1.rpcClientCalls.emitEvent(event);
|
|
91
|
+
});
|
|
92
|
+
// A new registration is how the SDK's clients learn to subscribe again after a reconnect.
|
|
93
|
+
const nextTransport = portContractTransports(host);
|
|
94
|
+
let unregister = (0, peers_sdk_1.registerHostContractTransport)(nextTransport());
|
|
95
|
+
host.onNotify(frame_protocol_1.HostNotice.contractReset, () => {
|
|
96
|
+
unregister();
|
|
97
|
+
unregister = (0, peers_sdk_1.registerHostContractTransport)(nextTransport());
|
|
98
|
+
});
|
|
99
|
+
(0, peers_sdk_1.setPersistentVarBackend)(framePersistentVarBackend(host));
|
|
100
|
+
const storage = (0, frame_storage_1.createFrameStorage)((change) => host.notify(frame_protocol_1.FrameNotice.storage, change));
|
|
101
|
+
for (const name of ["localStorage", "sessionStorage"]) {
|
|
102
|
+
const value = name === "localStorage" ? storage.local : storage.session;
|
|
103
|
+
try {
|
|
104
|
+
Object.defineProperty(win, name, { value, configurable: true, enumerable: true });
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.warn(`[frame] couldn't replace ${name}`, error);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
(0, peers_sdk_1.notifyClientConnected)();
|
|
111
|
+
installed = { host, storage };
|
|
112
|
+
return installed;
|
|
113
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { IPackageFrameProps } from "./isolated-screen";
|
|
3
|
+
/** Register the package frame component. */
|
|
4
|
+
export declare function registerPackageFrame(component: React.ComponentType<IPackageFrameProps>): void;
|
|
5
|
+
/** The package frame component; throws when the frame host hasn't loaded. */
|
|
6
|
+
export declare function packageFrameComponent(): React.ComponentType<IPackageFrameProps>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerPackageFrame = registerPackageFrame;
|
|
4
|
+
exports.packageFrameComponent = packageFrameComponent;
|
|
5
|
+
/**
|
|
6
|
+
* The host's package frame component, registered by `isolated-screen.tsx` when it loads, so the
|
|
7
|
+
* piece components can draw it without importing the frame host (and everything it imports) into
|
|
8
|
+
* modules that only resolve pieces.
|
|
9
|
+
*/
|
|
10
|
+
let registered;
|
|
11
|
+
/** Register the package frame component. */
|
|
12
|
+
function registerPackageFrame(component) {
|
|
13
|
+
registered = component;
|
|
14
|
+
}
|
|
15
|
+
/** The package frame component; throws when the frame host hasn't loaded. */
|
|
16
|
+
function packageFrameComponent() {
|
|
17
|
+
if (!registered)
|
|
18
|
+
throw new Error("The isolated screens host isn't loaded");
|
|
19
|
+
return registered;
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The document every isolated screen's frame starts with, as its `srcdoc`.
|
|
3
|
+
*
|
|
4
|
+
* The frame is sandboxed without `allow-same-origin`, so it has an opaque origin of its own: it
|
|
5
|
+
* can't reach the host's DOM, storage, cookies or globals, and the host can't be reached from it
|
|
6
|
+
* except by messages. Its policy lets it run the code the host hands it and load images and media
|
|
7
|
+
* from anywhere, and nothing else: no requests (`connect-src`), no frames, no forms sent anywhere.
|
|
8
|
+
*
|
|
9
|
+
* The script says hello to the parent once. The host, which made the frame and knows its window,
|
|
10
|
+
* answers with the frame runtime's source and a `MessagePort`; the script keeps the port where the
|
|
11
|
+
* runtime's first module finds it and runs the source. A second boot is ignored.
|
|
12
|
+
*/
|
|
13
|
+
/** The message a frame's document sends its parent when it's ready to boot. */
|
|
14
|
+
export declare const FRAME_HELLO = "peers-frame-hello";
|
|
15
|
+
/** The message the host answers with: `{ type, runtime }`, with the port transferred. */
|
|
16
|
+
export declare const FRAME_BOOT = "peers-frame-boot";
|
|
17
|
+
/** Where the boot script leaves the port for the runtime. */
|
|
18
|
+
export declare const FRAME_PORT_GLOBAL = "__peersFramePort";
|
|
19
|
+
/** The frame's content security policy. */
|
|
20
|
+
export declare const FRAME_CSP: string;
|
|
21
|
+
/**
|
|
22
|
+
* The frame's starting document.
|
|
23
|
+
*
|
|
24
|
+
* @param colorMode - The theme to start in, so the frame doesn't flash the other one.
|
|
25
|
+
*/
|
|
26
|
+
export declare function frameDocument(colorMode: "light" | "dark"): string;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The document every isolated screen's frame starts with, as its `srcdoc`.
|
|
4
|
+
*
|
|
5
|
+
* The frame is sandboxed without `allow-same-origin`, so it has an opaque origin of its own: it
|
|
6
|
+
* can't reach the host's DOM, storage, cookies or globals, and the host can't be reached from it
|
|
7
|
+
* except by messages. Its policy lets it run the code the host hands it and load images and media
|
|
8
|
+
* from anywhere, and nothing else: no requests (`connect-src`), no frames, no forms sent anywhere.
|
|
9
|
+
*
|
|
10
|
+
* The script says hello to the parent once. The host, which made the frame and knows its window,
|
|
11
|
+
* answers with the frame runtime's source and a `MessagePort`; the script keeps the port where the
|
|
12
|
+
* runtime's first module finds it and runs the source. A second boot is ignored.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.FRAME_CSP = exports.FRAME_PORT_GLOBAL = exports.FRAME_BOOT = exports.FRAME_HELLO = void 0;
|
|
16
|
+
exports.frameDocument = frameDocument;
|
|
17
|
+
/** The message a frame's document sends its parent when it's ready to boot. */
|
|
18
|
+
exports.FRAME_HELLO = "peers-frame-hello";
|
|
19
|
+
/** The message the host answers with: `{ type, runtime }`, with the port transferred. */
|
|
20
|
+
exports.FRAME_BOOT = "peers-frame-boot";
|
|
21
|
+
/** Where the boot script leaves the port for the runtime. */
|
|
22
|
+
exports.FRAME_PORT_GLOBAL = "__peersFramePort";
|
|
23
|
+
/** The frame's content security policy. */
|
|
24
|
+
exports.FRAME_CSP = [
|
|
25
|
+
"default-src 'none'",
|
|
26
|
+
"script-src 'unsafe-inline' 'unsafe-eval' blob:",
|
|
27
|
+
"style-src 'unsafe-inline'",
|
|
28
|
+
"img-src data: blob: https: http:",
|
|
29
|
+
"media-src data: blob: https: http:",
|
|
30
|
+
"font-src data:",
|
|
31
|
+
"connect-src data: blob:",
|
|
32
|
+
"worker-src blob:",
|
|
33
|
+
"frame-src 'none'",
|
|
34
|
+
"form-action 'none'",
|
|
35
|
+
"base-uri 'none'",
|
|
36
|
+
].join("; ");
|
|
37
|
+
/**
|
|
38
|
+
* The frame's starting document.
|
|
39
|
+
*
|
|
40
|
+
* @param colorMode - The theme to start in, so the frame doesn't flash the other one.
|
|
41
|
+
*/
|
|
42
|
+
function frameDocument(colorMode) {
|
|
43
|
+
const background = colorMode === "dark" ? "#212529" : "#fff";
|
|
44
|
+
return `<!doctype html>
|
|
45
|
+
<html data-bs-theme="${colorMode}" style="height:100%;background:${background}">
|
|
46
|
+
<head>
|
|
47
|
+
<meta charset="utf-8">
|
|
48
|
+
<meta http-equiv="Content-Security-Policy" content="${exports.FRAME_CSP}">
|
|
49
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
50
|
+
<style>html,body,#peers-frame-root{height:100%;margin:0}</style>
|
|
51
|
+
</head>
|
|
52
|
+
<body style="background:${background}">
|
|
53
|
+
<div id="peers-frame-root"></div>
|
|
54
|
+
<script>
|
|
55
|
+
(function () {
|
|
56
|
+
var booted = false;
|
|
57
|
+
addEventListener("message", function (event) {
|
|
58
|
+
var data = event.data;
|
|
59
|
+
if (booted || event.source !== parent || !data || data.type !== "${exports.FRAME_BOOT}") return;
|
|
60
|
+
booted = true;
|
|
61
|
+
window.${exports.FRAME_PORT_GLOBAL} = event.ports[0];
|
|
62
|
+
(0, eval)(data.runtime);
|
|
63
|
+
});
|
|
64
|
+
parent.postMessage({ type: "${exports.FRAME_HELLO}" }, "*");
|
|
65
|
+
})();
|
|
66
|
+
</script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>`;
|
|
69
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type IEventData } from "@peers-app/peers-sdk";
|
|
2
|
+
/** Persistent variables every screen may read through the table. */
|
|
3
|
+
export declare const SCREEN_READABLE_PVARS: ReadonlySet<string>;
|
|
4
|
+
/** One screen's legacy RPC: answers its calls, and forwards it the events it subscribed to. */
|
|
5
|
+
export interface IFrameRpc {
|
|
6
|
+
/** Answer one call. */
|
|
7
|
+
call(name: string, args: unknown[]): Promise<unknown>;
|
|
8
|
+
/** End every event subscription. */
|
|
9
|
+
dispose(): void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Serve one isolated screen's legacy RPC calls.
|
|
13
|
+
*
|
|
14
|
+
* @param packageId - The screen's package.
|
|
15
|
+
* @param sendEvent - Hands the screen a data event it subscribed to.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createFrameRpc(packageId: string, sendEvent: (event: IEventData) => void): IFrameRpc;
|