@celljs/ta-web 4.34.0 → 4.35.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/README.en.md +1 -1
- package/README.md +1 -1
- package/esm/browser/apps/app-icon.d.ts +23 -0
- package/esm/browser/apps/app-icon.js +98 -0
- package/esm/browser/apps/app-settings.d.ts +6 -0
- package/esm/browser/apps/app-settings.js +67 -0
- package/esm/browser/apps/app-window-util.d.ts +23 -0
- package/esm/browser/apps/app-window-util.js +27 -0
- package/esm/browser/apps/app-window.d.ts +9 -0
- package/esm/browser/apps/app-window.js +90 -0
- package/esm/browser/apps/web-apps.d.ts +29 -0
- package/esm/browser/apps/web-apps.js +57 -0
- package/esm/browser/assistant/call-keeper.d.ts +2 -5
- package/esm/browser/assistant/call-keeper.js +7 -11
- package/esm/browser/components/access-settings.d.ts +6 -0
- package/esm/browser/components/access-settings.js +52 -0
- package/esm/browser/components/app-root.d.ts +6 -0
- package/esm/browser/components/app-root.js +34 -0
- package/esm/browser/components/app-view.d.ts +8 -2
- package/esm/browser/components/app-view.js +1 -25
- package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/settings-more.js +6 -0
- package/esm/browser/device/screen-awake.d.ts +16 -0
- package/esm/browser/device/screen-awake.js +37 -0
- package/esm/browser/device/sheet-swipe.js +4 -0
- package/esm/browser/extension/icons.js +2 -1
- package/esm/browser/extension/web-access.d.ts +16 -0
- package/esm/browser/extension/web-access.js +75 -0
- package/esm/browser/extension/web-api-desktop.d.ts +23 -0
- package/esm/browser/extension/web-api-spec.d.ts +70 -0
- package/esm/browser/extension/web-api-spec.js +223 -0
- package/esm/browser/extension/web-extension-api.d.ts +6 -0
- package/esm/browser/extension/web-extension-context.js +11 -2
- package/esm/browser/extension/web-extension-run.d.ts +6 -1
- package/esm/browser/extension/web-extension-run.js +25 -0
- package/esm/browser/extension/web-extensions-running.d.ts +18 -1
- package/esm/browser/extension/web-extensions-running.js +102 -9
- package/esm/browser/extension/web-pages.d.ts +5 -0
- package/esm/browser/extension/web-pages.js +3 -0
- package/esm/browser/i18n/en/common.d.ts +1 -0
- package/esm/browser/i18n/en/common.js +1 -0
- package/esm/browser/i18n/en/discover.d.ts +11 -0
- package/esm/browser/i18n/en/discover.js +11 -0
- package/esm/browser/i18n/en/settings.d.ts +28 -0
- package/esm/browser/i18n/en/settings.js +28 -0
- package/esm/browser/i18n/ja/common.js +1 -0
- package/esm/browser/i18n/ja/discover.js +11 -0
- package/esm/browser/i18n/ja/settings.js +28 -0
- package/esm/browser/i18n/locales.d.ts +41 -3
- package/esm/browser/i18n/messages.d.ts +40 -2
- package/esm/browser/i18n/zh/common.js +1 -0
- package/esm/browser/i18n/zh/discover.js +11 -0
- package/esm/browser/i18n/zh/settings.js +28 -0
- package/esm/browser/i18n/zh-tw/common.js +1 -0
- package/esm/browser/i18n/zh-tw/discover.js +11 -0
- package/esm/browser/i18n/zh-tw/settings.js +28 -0
- package/esm/browser/index.d.ts +1 -0
- package/esm/browser/index.js +1 -0
- package/esm/browser/notices/notices.js +1 -0
- package/esm/browser/sandbox/channel/channel.d.ts +56 -0
- package/esm/browser/sandbox/channel/channel.js +124 -0
- package/esm/browser/sandbox/channel/codec.d.ts +80 -0
- package/esm/browser/sandbox/channel/codec.js +251 -0
- package/esm/browser/sandbox/hook-host.d.ts +23 -0
- package/esm/browser/sandbox/hook-host.js +61 -0
- package/esm/browser/sandbox/isolated-host.d.ts +105 -0
- package/esm/browser/sandbox/isolated-host.js +395 -0
- package/esm/browser/sandbox/remote/remote-copy.d.ts +56 -0
- package/esm/browser/sandbox/remote/remote-copy.js +302 -0
- package/esm/browser/sandbox/remote/remote-mirror.d.ts +61 -0
- package/esm/browser/sandbox/remote/remote-mirror.js +341 -0
- package/esm/browser/sandbox/remote/remote-protocol.d.ts +79 -0
- package/esm/browser/sandbox/remote/remote-protocol.js +54 -0
- package/esm/browser/sandbox/remote/remote-styles.d.ts +10 -0
- package/esm/browser/sandbox/remote/remote-styles.js +113 -0
- package/esm/browser/sandbox/remote-root.d.ts +11 -0
- package/esm/browser/sandbox/remote-root.js +81 -0
- package/esm/browser/sandbox/runtime/frame-api.d.ts +28 -0
- package/esm/browser/sandbox/runtime/frame-api.js +147 -0
- package/esm/browser/sandbox/runtime/frame-features.d.ts +6 -0
- package/esm/browser/sandbox/runtime/frame-features.js +50 -0
- package/esm/browser/sandbox/runtime/frame-parts.d.ts +36 -0
- package/esm/browser/sandbox/runtime/frame-parts.js +69 -0
- package/esm/browser/sandbox/runtime/frame-roots.d.ts +26 -0
- package/esm/browser/sandbox/runtime/frame-roots.js +76 -0
- package/esm/browser/sandbox/runtime/frame-store.d.ts +9 -0
- package/esm/browser/sandbox/runtime/frame-store.js +18 -0
- package/esm/browser/sandbox/runtime/sandbox-runtime.d.ts +11 -0
- package/esm/browser/sandbox/runtime/sandbox-runtime.js +45 -0
- package/esm/browser/sandbox/sandbox-features.d.ts +25 -0
- package/esm/browser/sandbox/sandbox-features.js +32 -0
- package/esm/browser/sandbox/sandbox-frame.d.ts +21 -0
- package/esm/browser/sandbox/sandbox-frame.js +75 -0
- package/esm/browser/sandbox/sandbox-guards.d.ts +19 -0
- package/esm/browser/sandbox/sandbox-guards.js +74 -0
- package/esm/browser/sandbox/sandbox-protocol.d.ts +57 -0
- package/esm/browser/sandbox/sandbox-protocol.js +49 -0
- package/esm/browser/sandbox/sandbox-runtime-code.d.ts +1 -0
- package/esm/browser/sandbox/sandbox-runtime-code.js +3 -0
- package/esm/browser/sandbox/web-sandbox.d.ts +28 -0
- package/esm/browser/sandbox/web-sandbox.js +44 -0
- package/esm/browser/settings/settings-protocol.d.ts +2 -0
- package/esm/browser/settings/settings-protocol.js +2 -0
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +5 -0
- package/esm/browser/style/tints.d.ts +2 -0
- package/esm/browser/style/tints.js +10 -0
- package/esm/browser/util/desktop.d.ts +31 -1
- package/esm/browser/util/desktop.js +20 -0
- package/esm/browser/view.js +1 -1
- package/lib/browser/apps/app-icon.d.ts +24 -0
- package/lib/browser/apps/app-icon.js +134 -0
- package/lib/browser/apps/app-settings.d.ts +7 -0
- package/lib/browser/apps/app-settings.js +103 -0
- package/lib/browser/apps/app-window-util.d.ts +24 -0
- package/lib/browser/apps/app-window-util.js +30 -0
- package/lib/browser/apps/app-window.d.ts +10 -0
- package/lib/browser/apps/app-window.js +126 -0
- package/lib/browser/apps/web-apps.d.ts +30 -0
- package/lib/browser/apps/web-apps.js +61 -0
- package/lib/browser/assistant/call-keeper.d.ts +2 -5
- package/lib/browser/assistant/call-keeper.js +6 -10
- package/lib/browser/components/access-settings.d.ts +7 -0
- package/lib/browser/components/access-settings.js +88 -0
- package/lib/browser/components/app-root.d.ts +7 -0
- package/lib/browser/components/app-root.js +70 -0
- package/lib/browser/components/app-view.d.ts +8 -2
- package/lib/browser/components/app-view.js +1 -25
- package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/settings-more.js +6 -0
- package/lib/browser/device/screen-awake.d.ts +16 -0
- package/lib/browser/device/screen-awake.js +39 -1
- package/lib/browser/device/sheet-swipe.js +4 -0
- package/lib/browser/extension/icons.js +1 -0
- package/lib/browser/extension/web-access.d.ts +17 -0
- package/lib/browser/extension/web-access.js +78 -0
- package/lib/browser/extension/web-api-desktop.d.ts +23 -0
- package/lib/browser/extension/web-api-spec.d.ts +71 -0
- package/lib/browser/extension/web-api-spec.js +226 -0
- package/lib/browser/extension/web-extension-api.d.ts +6 -0
- package/lib/browser/extension/web-extension-context.js +11 -2
- package/lib/browser/extension/web-extension-run.d.ts +6 -1
- package/lib/browser/extension/web-extension-run.js +25 -0
- package/lib/browser/extension/web-extensions-running.d.ts +18 -1
- package/lib/browser/extension/web-extensions-running.js +102 -9
- package/lib/browser/extension/web-pages.d.ts +5 -0
- package/lib/browser/extension/web-pages.js +3 -0
- package/lib/browser/i18n/en/common.d.ts +1 -0
- package/lib/browser/i18n/en/common.js +1 -0
- package/lib/browser/i18n/en/discover.d.ts +11 -0
- package/lib/browser/i18n/en/discover.js +11 -0
- package/lib/browser/i18n/en/settings.d.ts +28 -0
- package/lib/browser/i18n/en/settings.js +28 -0
- package/lib/browser/i18n/ja/common.js +1 -0
- package/lib/browser/i18n/ja/discover.js +11 -0
- package/lib/browser/i18n/ja/settings.js +28 -0
- package/lib/browser/i18n/locales.d.ts +41 -3
- package/lib/browser/i18n/messages.d.ts +40 -2
- package/lib/browser/i18n/zh/common.js +1 -0
- package/lib/browser/i18n/zh/discover.js +11 -0
- package/lib/browser/i18n/zh/settings.js +28 -0
- package/lib/browser/i18n/zh-tw/common.js +1 -0
- package/lib/browser/i18n/zh-tw/discover.js +11 -0
- package/lib/browser/i18n/zh-tw/settings.js +28 -0
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.js +1 -0
- package/lib/browser/notices/notices.js +1 -0
- package/lib/browser/sandbox/channel/channel.d.ts +57 -0
- package/lib/browser/sandbox/channel/channel.js +128 -0
- package/lib/browser/sandbox/channel/codec.d.ts +81 -0
- package/lib/browser/sandbox/channel/codec.js +256 -0
- package/lib/browser/sandbox/hook-host.d.ts +24 -0
- package/lib/browser/sandbox/hook-host.js +98 -0
- package/lib/browser/sandbox/isolated-host.d.ts +106 -0
- package/lib/browser/sandbox/isolated-host.js +432 -0
- package/lib/browser/sandbox/remote/remote-copy.d.ts +57 -0
- package/lib/browser/sandbox/remote/remote-copy.js +306 -0
- package/lib/browser/sandbox/remote/remote-mirror.d.ts +62 -0
- package/lib/browser/sandbox/remote/remote-mirror.js +345 -0
- package/lib/browser/sandbox/remote/remote-protocol.d.ts +80 -0
- package/lib/browser/sandbox/remote/remote-protocol.js +57 -0
- package/lib/browser/sandbox/remote/remote-styles.d.ts +11 -0
- package/lib/browser/sandbox/remote/remote-styles.js +116 -0
- package/lib/browser/sandbox/remote-root.d.ts +12 -0
- package/lib/browser/sandbox/remote-root.js +117 -0
- package/lib/browser/sandbox/runtime/frame-api.d.ts +29 -0
- package/lib/browser/sandbox/runtime/frame-api.js +183 -0
- package/lib/browser/sandbox/runtime/frame-features.d.ts +7 -0
- package/lib/browser/sandbox/runtime/frame-features.js +53 -0
- package/lib/browser/sandbox/runtime/frame-parts.d.ts +37 -0
- package/lib/browser/sandbox/runtime/frame-parts.js +106 -0
- package/lib/browser/sandbox/runtime/frame-roots.d.ts +27 -0
- package/lib/browser/sandbox/runtime/frame-roots.js +113 -0
- package/lib/browser/sandbox/runtime/frame-store.d.ts +10 -0
- package/lib/browser/sandbox/runtime/frame-store.js +22 -0
- package/lib/browser/sandbox/runtime/sandbox-runtime.d.ts +12 -0
- package/lib/browser/sandbox/runtime/sandbox-runtime.js +47 -0
- package/lib/browser/sandbox/sandbox-features.d.ts +26 -0
- package/lib/browser/sandbox/sandbox-features.js +35 -0
- package/lib/browser/sandbox/sandbox-frame.d.ts +22 -0
- package/lib/browser/sandbox/sandbox-frame.js +79 -0
- package/lib/browser/sandbox/sandbox-guards.d.ts +20 -0
- package/lib/browser/sandbox/sandbox-guards.js +77 -0
- package/lib/browser/sandbox/sandbox-protocol.d.ts +58 -0
- package/lib/browser/sandbox/sandbox-protocol.js +52 -0
- package/lib/browser/sandbox/sandbox-runtime-code.d.ts +2 -0
- package/lib/browser/sandbox/sandbox-runtime-code.js +6 -0
- package/lib/browser/sandbox/web-sandbox.d.ts +29 -0
- package/lib/browser/sandbox/web-sandbox.js +47 -0
- package/lib/browser/settings/settings-protocol.d.ts +2 -0
- package/lib/browser/settings/settings-protocol.js +2 -0
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +5 -0
- package/lib/browser/style/tints.d.ts +2 -0
- package/lib/browser/style/tints.js +10 -0
- package/lib/browser/util/desktop.d.ts +31 -1
- package/lib/browser/util/desktop.js +20 -0
- package/lib/browser/view.js +2 -2
- package/package.json +8 -8
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { EmptyState } from '../components/empty-state.js';
|
|
4
|
+
/** What the extension gave a part of Ta to draw (its children, a title of nodes), moved under where the part draws it. */
|
|
5
|
+
function Slot({ node, className }) {
|
|
6
|
+
const ref = React.useRef(null);
|
|
7
|
+
React.useLayoutEffect(() => {
|
|
8
|
+
var _a;
|
|
9
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.appendChild(node);
|
|
10
|
+
}, [node]);
|
|
11
|
+
return React.createElement("span", { ref: ref, className: className });
|
|
12
|
+
}
|
|
13
|
+
class Boundary extends React.Component {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.state = { failed: false };
|
|
17
|
+
}
|
|
18
|
+
static getDerivedStateFromError() {
|
|
19
|
+
return { failed: true };
|
|
20
|
+
}
|
|
21
|
+
componentDidCatch(error) {
|
|
22
|
+
console.error('A part of Ta in a sandbox failed:', error);
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return this.state.failed ? null : this.props.children;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** A part of Ta in a copy: its component, its props from the sandbox, and its slots. */
|
|
29
|
+
function Part({ host, element }) {
|
|
30
|
+
const version = React.useSyncExternalStore(host.parts.subscribe, host.parts.version);
|
|
31
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: version says the props or the slots changed
|
|
32
|
+
const shown = React.useMemo(() => {
|
|
33
|
+
var _a, _b, _c;
|
|
34
|
+
const Component = host.partComponent((_a = element.getAttribute('k')) !== null && _a !== void 0 ? _a : '');
|
|
35
|
+
if (!Component) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const props = { ...((_c = host.parts.props((_b = element.getAttribute('d')) !== null && _b !== void 0 ? _b : '')) !== null && _c !== void 0 ? _c : {}) };
|
|
39
|
+
for (const [name, node] of host.parts.slots(element)) {
|
|
40
|
+
props[name] = React.createElement(Slot, { node: node, className: host.className });
|
|
41
|
+
}
|
|
42
|
+
return React.createElement(Component, { ...props });
|
|
43
|
+
}, [host, element, version]);
|
|
44
|
+
return createPortal(React.createElement(Boundary, null, shown), element);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A component of an extension in a sandbox, where the page shows it (docs/design/ta-extension-access.md 3.4): a root
|
|
48
|
+
* of its own in the sandbox, copied here into real DOM, with Ta's components drawn in it by the page itself.
|
|
49
|
+
*/
|
|
50
|
+
export function RemoteRoot({ host, component, props }) {
|
|
51
|
+
const ref = React.useRef(null);
|
|
52
|
+
const [root, setRoot] = React.useState();
|
|
53
|
+
const [failed, setFailed] = React.useState();
|
|
54
|
+
const [parts, setParts] = React.useState([]);
|
|
55
|
+
const latest = React.useRef(props);
|
|
56
|
+
latest.current = props;
|
|
57
|
+
React.useLayoutEffect(() => {
|
|
58
|
+
const element = ref.current;
|
|
59
|
+
if (!element) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const mounted = host.mount(element, component, latest.current, {
|
|
63
|
+
part: part => setParts(list => (list.includes(part) ? list : [...list, part])),
|
|
64
|
+
partGone: part => setParts(list => list.filter(one => one !== part)),
|
|
65
|
+
failed: setFailed,
|
|
66
|
+
});
|
|
67
|
+
setRoot(mounted);
|
|
68
|
+
return () => host.unmount(mounted);
|
|
69
|
+
}, [host, component]);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (root !== undefined) {
|
|
72
|
+
host.props(root, props);
|
|
73
|
+
}
|
|
74
|
+
}, [host, root, props]);
|
|
75
|
+
// The copy in a box of its own, whose children React never touches; the parts of Ta drawn into it by portals.
|
|
76
|
+
return (React.createElement(React.Fragment, null,
|
|
77
|
+
failed ? React.createElement(EmptyState, { compact: true, tone: "error", title: failed }) : null,
|
|
78
|
+
React.createElement("div", { ref: ref, className: `ta-remote ${host.className}` }),
|
|
79
|
+
parts.map(part => (React.createElement(Part, { key: host.parts.keyOf(part), host: host, element: part })))));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=remote-root.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { TaExtensionAccess } from '@celljs/ta-protocol';
|
|
2
|
+
import type { WebExtensionAPI } from '../../extension/web-extension-api.js';
|
|
3
|
+
import type { Channel } from '../channel/channel.js';
|
|
4
|
+
import type { Codec } from '../channel/codec.js';
|
|
5
|
+
import type { FrameParts } from './frame-parts.js';
|
|
6
|
+
import { FrameStore } from './frame-store.js';
|
|
7
|
+
/** What a sandbox makes its `pi` of. */
|
|
8
|
+
export interface FrameApiSource {
|
|
9
|
+
readonly channel: Channel;
|
|
10
|
+
readonly codec: () => Codec;
|
|
11
|
+
readonly parts: FrameParts;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly access: TaExtensionAccess;
|
|
14
|
+
readonly absent: ReadonlySet<string>;
|
|
15
|
+
readonly icons: readonly string[];
|
|
16
|
+
/** The values of the page, by path, as it sends them again. */
|
|
17
|
+
readonly values: FrameStore<Record<string, unknown>>;
|
|
18
|
+
/** Ta's components: off, they are not there (SandboxOptions.parts). */
|
|
19
|
+
readonly parts_on: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The extension's `pi` in a sandbox, made from WEB_API_SPEC alone (docs/design/ta-extension-access.md 3.2): each
|
|
23
|
+
* member as its form says, crossing to the page by its path; then cut by the same WebAccessUtil.limit as in the page.
|
|
24
|
+
* No member is written here by hand.
|
|
25
|
+
*/
|
|
26
|
+
export declare namespace FrameApi {
|
|
27
|
+
function create(source: FrameApiSource): WebExtensionAPI;
|
|
28
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useBusy } from '../../components/busy.js';
|
|
3
|
+
import { WebAccessUtil } from '../../extension/web-access.js';
|
|
4
|
+
import { WEB_API_SPEC } from '../../extension/web-api-spec.js';
|
|
5
|
+
import { FrameStore } from './frame-store.js';
|
|
6
|
+
/** What the sandbox gives itself (`local` of WEB_API_SPEC), by path. */
|
|
7
|
+
const LOCAL = { React, 'ui.useBusy': useBusy };
|
|
8
|
+
let nextHook = 1;
|
|
9
|
+
/**
|
|
10
|
+
* The extension's `pi` in a sandbox, made from WEB_API_SPEC alone (docs/design/ta-extension-access.md 3.2): each
|
|
11
|
+
* member as its form says, crossing to the page by its path; then cut by the same WebAccessUtil.limit as in the page.
|
|
12
|
+
* No member is written here by hand.
|
|
13
|
+
*/
|
|
14
|
+
export var FrameApi;
|
|
15
|
+
(function (FrameApi) {
|
|
16
|
+
function create(source) {
|
|
17
|
+
const hooks = new Map();
|
|
18
|
+
source.channel.on('hook', body => {
|
|
19
|
+
var _a;
|
|
20
|
+
const { key, value, error } = body;
|
|
21
|
+
if (error) {
|
|
22
|
+
console.error(error);
|
|
23
|
+
}
|
|
24
|
+
(_a = hooks.get(String(key))) === null || _a === void 0 ? void 0 : _a.set(error ? undefined : source.codec().decode(value));
|
|
25
|
+
});
|
|
26
|
+
const whole = group(source, hooks, WEB_API_SPEC, '');
|
|
27
|
+
return WebAccessUtil.limit(whole, source.access, source.name);
|
|
28
|
+
}
|
|
29
|
+
FrameApi.create = create;
|
|
30
|
+
function group(source, hooks, members, prefix) {
|
|
31
|
+
const made = {};
|
|
32
|
+
for (const [key, entry] of Object.entries(members)) {
|
|
33
|
+
const path = prefix + key;
|
|
34
|
+
if (source.absent.has(path) || entry.form === 'page') {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const descriptor = member(source, hooks, path, entry);
|
|
38
|
+
if (descriptor) {
|
|
39
|
+
Object.defineProperty(made, key, { enumerable: true, ...descriptor });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return made;
|
|
43
|
+
}
|
|
44
|
+
function member(source, hooks, path, entry) {
|
|
45
|
+
const { channel, codec, values } = source;
|
|
46
|
+
const ask = (args, shapes) => channel.request('api', { path, args: codec().encodeArgs(args, shapes) }).then(value => codec().decode(value));
|
|
47
|
+
switch (entry.form) {
|
|
48
|
+
case 'local':
|
|
49
|
+
return Object.keys(LOCAL).includes(path) ? { value: LOCAL[path] } : undefined;
|
|
50
|
+
case 'group':
|
|
51
|
+
return { value: group(source, hooks, entry.members, `${path}.`) };
|
|
52
|
+
case 'value':
|
|
53
|
+
return { get: () => values.get()[path] };
|
|
54
|
+
case 'read':
|
|
55
|
+
return { value: () => values.get()[path] };
|
|
56
|
+
case 'component':
|
|
57
|
+
return source.parts_on ? { value: source.parts.part(path) } : undefined;
|
|
58
|
+
case 'components':
|
|
59
|
+
return source.parts_on ? { value: source.parts.icons(source.icons) } : undefined;
|
|
60
|
+
case 'call':
|
|
61
|
+
if (entry.returns === 'url') {
|
|
62
|
+
// The same address for the same arguments, as in the page.
|
|
63
|
+
const urls = new Map();
|
|
64
|
+
return {
|
|
65
|
+
value: (...args) => {
|
|
66
|
+
const key = JSON.stringify(args);
|
|
67
|
+
let url = urls.get(key);
|
|
68
|
+
if (!url) {
|
|
69
|
+
url = ask(args, entry.args).then(blob => URL.createObjectURL(blob));
|
|
70
|
+
urls.set(key, url);
|
|
71
|
+
url.catch(() => urls.delete(key));
|
|
72
|
+
}
|
|
73
|
+
return url;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return { value: (...args) => ask(args, entry.args) };
|
|
78
|
+
case 'fire':
|
|
79
|
+
return {
|
|
80
|
+
value: (...args) => {
|
|
81
|
+
ask(args, entry.args).catch(error => console.error(`pi.${path}:`, error));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
case 'hold':
|
|
85
|
+
return {
|
|
86
|
+
value: (...args) => {
|
|
87
|
+
const held = ask(args, entry.args);
|
|
88
|
+
held.catch(error => console.error(`pi.${path}:`, error));
|
|
89
|
+
let released = false;
|
|
90
|
+
return () => {
|
|
91
|
+
if (!released) {
|
|
92
|
+
released = true;
|
|
93
|
+
void held.then(id => channel.request('release', id)).catch(() => undefined);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
case 'hook':
|
|
99
|
+
return { value: entry.peek ? peek(values, path) : hook(source, hooks, path, entry.args) };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** A hook the page reads before the extension starts and sends again as it changes. */
|
|
103
|
+
function peek(values, path) {
|
|
104
|
+
// biome-ignore lint/correctness/noComponentHookFactories: a member of pi made from the spec, the same function for every render
|
|
105
|
+
return function usePeek() {
|
|
106
|
+
return React.useSyncExternalStore(values.subscribe, () => values.get()[path]);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A hook the page runs for it while it is mounted (HookHost): its value comes as the page renders it, undefined at
|
|
111
|
+
* first. Functions among its arguments cross once, each calling the latest of them, so that a new closure each
|
|
112
|
+
* render is not a new watch.
|
|
113
|
+
*/
|
|
114
|
+
function hook(source, hooks, path, shapes) {
|
|
115
|
+
const { channel, codec } = source;
|
|
116
|
+
// biome-ignore lint/correctness/noComponentHookFactories: a member of pi made from the spec, the same function for every render
|
|
117
|
+
return function useRemote(...args) {
|
|
118
|
+
var _a;
|
|
119
|
+
const [key] = React.useState(() => `h${nextHook++}`);
|
|
120
|
+
const [store] = React.useState(() => new FrameStore(undefined));
|
|
121
|
+
const latest = React.useRef(args);
|
|
122
|
+
latest.current = args;
|
|
123
|
+
const [stable] = React.useState(() => args.map((arg, index) => typeof arg === 'function' ? (...more) => { var _a, _b; return (_b = (_a = latest.current)[index]) === null || _b === void 0 ? void 0 : _b.call(_a, ...more); } : undefined));
|
|
124
|
+
const encoded = args.map((arg, index) => (typeof arg === 'function' ? stable[index] : arg));
|
|
125
|
+
const data = JSON.stringify((_a = args.map(arg => (typeof arg === 'function' ? null : arg))) !== null && _a !== void 0 ? _a : null);
|
|
126
|
+
const sent = React.useRef(undefined);
|
|
127
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: watched once; its arguments are sent again below as they change
|
|
128
|
+
React.useLayoutEffect(() => {
|
|
129
|
+
hooks.set(key, store);
|
|
130
|
+
channel.notify('hook.watch', { key, path, args: codec().encodeArgs(encoded, shapes) });
|
|
131
|
+
sent.current = data;
|
|
132
|
+
return () => {
|
|
133
|
+
hooks.delete(key);
|
|
134
|
+
channel.notify('hook.unwatch', { key });
|
|
135
|
+
};
|
|
136
|
+
}, [key]);
|
|
137
|
+
React.useLayoutEffect(() => {
|
|
138
|
+
if (sent.current !== undefined && sent.current !== data) {
|
|
139
|
+
sent.current = data;
|
|
140
|
+
channel.notify('hook.args', { key, args: codec().encodeArgs(encoded, shapes) });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return React.useSyncExternalStore(store.subscribe, store.get);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
})(FrameApi || (FrameApi = {}));
|
|
147
|
+
//# sourceMappingURL=frame-api.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WebExtensionAPI } from '../../extension/web-extension-api.js';
|
|
2
|
+
/**
|
|
3
|
+
* The sandbox's half of each feature (SANDBOX_FEATURES, by the same name), given what the page's half gave it. One
|
|
4
|
+
* the user turned off is never started.
|
|
5
|
+
*/
|
|
6
|
+
export declare const FRAME_FEATURES: Readonly<Record<string, (given: unknown, pi: WebExtensionAPI) => void>>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { LOCAL_KEY } from '../sandbox-features.js';
|
|
2
|
+
import { SandboxLimits } from '../sandbox-protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* The sandbox's half of each feature (SANDBOX_FEATURES, by the same name), given what the page's half gave it. One
|
|
5
|
+
* the user turned off is never started.
|
|
6
|
+
*/
|
|
7
|
+
export const FRAME_FEATURES = {
|
|
8
|
+
/** A `localStorage` as in the page, kept with the extension's storage: a document of no origin has none (3.5). */
|
|
9
|
+
local: (given, pi) => {
|
|
10
|
+
const items = new Map(Object.entries(given && typeof given === 'object' ? given : {}).map(([key, value]) => [key, String(value)]));
|
|
11
|
+
let timer;
|
|
12
|
+
const save = () => {
|
|
13
|
+
clearTimeout(timer);
|
|
14
|
+
timer = setTimeout(() => void pi.storage.set(LOCAL_KEY, Object.fromEntries(items)).catch(error => console.error(error)), 300);
|
|
15
|
+
};
|
|
16
|
+
const size = () => [...items].reduce((sum, [key, value]) => sum + key.length + value.length, 0);
|
|
17
|
+
const storage = {
|
|
18
|
+
get length() {
|
|
19
|
+
return items.size;
|
|
20
|
+
},
|
|
21
|
+
key: index => { var _a; return (_a = [...items.keys()][index]) !== null && _a !== void 0 ? _a : null; },
|
|
22
|
+
getItem: key => { var _a; return (_a = items.get(String(key))) !== null && _a !== void 0 ? _a : null; },
|
|
23
|
+
setItem: (key, value) => {
|
|
24
|
+
const before = items.get(String(key));
|
|
25
|
+
items.set(String(key), String(value));
|
|
26
|
+
if (size() > SandboxLimits.LOCAL_CHARS) {
|
|
27
|
+
if (before === undefined) {
|
|
28
|
+
items.delete(String(key));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
items.set(String(key), before);
|
|
32
|
+
}
|
|
33
|
+
throw new DOMException('The storage of this extension is full.', 'QuotaExceededError');
|
|
34
|
+
}
|
|
35
|
+
save();
|
|
36
|
+
},
|
|
37
|
+
removeItem: key => {
|
|
38
|
+
if (items.delete(String(key))) {
|
|
39
|
+
save();
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
clear: () => {
|
|
43
|
+
items.clear();
|
|
44
|
+
save();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(window, 'localStorage', { configurable: true, get: () => storage });
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=frame-features.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Channel } from '../channel/channel.js';
|
|
3
|
+
import type { Codec } from '../channel/codec.js';
|
|
4
|
+
declare module 'react' {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'ta-part': {
|
|
8
|
+
k: string;
|
|
9
|
+
d: string;
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
'ta-slot': {
|
|
13
|
+
n: string;
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The stand-ins of Ta's components in a sandbox (docs/design/ta-extension-access.md 3.4): each draws a `<ta-part>`,
|
|
21
|
+
* copied to the page, where the page draws the component itself; what is given it to draw goes in `<ta-slot>`s, its
|
|
22
|
+
* other props across the channel. Known by their paths, so that what crosses names them, not handles.
|
|
23
|
+
*/
|
|
24
|
+
export declare class FrameParts {
|
|
25
|
+
protected readonly channel: Channel;
|
|
26
|
+
protected readonly codec: () => Codec;
|
|
27
|
+
protected readonly paths: Map<unknown, string>;
|
|
28
|
+
constructor(channel: Channel, codec: () => Codec);
|
|
29
|
+
pathOf(value: unknown): string | undefined;
|
|
30
|
+
/** The stand-in of the component of `path`. */
|
|
31
|
+
part(path: string): React.ComponentType<Record<string, unknown>>;
|
|
32
|
+
/** The icons, each a stand-in. */
|
|
33
|
+
icons(names: readonly string[]): Record<string, React.ComponentType<Record<string, unknown>>>;
|
|
34
|
+
/** Sends its data props as they change, what they gave out before let go; none once it is gone. */
|
|
35
|
+
protected useSend(id: string, data: Record<string, unknown>): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PART_TAG, SLOT_TAG } from '../remote/remote-protocol.js';
|
|
3
|
+
let nextPart = 1;
|
|
4
|
+
/** Whether a prop is something to draw (an element, elements), which goes in a slot rather than across as data. */
|
|
5
|
+
function drawn(value) {
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
return value.some(drawn);
|
|
8
|
+
}
|
|
9
|
+
return React.isValidElement(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The stand-ins of Ta's components in a sandbox (docs/design/ta-extension-access.md 3.4): each draws a `<ta-part>`,
|
|
13
|
+
* copied to the page, where the page draws the component itself; what is given it to draw goes in `<ta-slot>`s, its
|
|
14
|
+
* other props across the channel. Known by their paths, so that what crosses names them, not handles.
|
|
15
|
+
*/
|
|
16
|
+
export class FrameParts {
|
|
17
|
+
constructor(channel, codec) {
|
|
18
|
+
this.channel = channel;
|
|
19
|
+
this.codec = codec;
|
|
20
|
+
this.paths = new Map();
|
|
21
|
+
}
|
|
22
|
+
pathOf(value) {
|
|
23
|
+
return this.paths.get(value);
|
|
24
|
+
}
|
|
25
|
+
/** The stand-in of the component of `path`. */
|
|
26
|
+
part(path) {
|
|
27
|
+
const parts = this;
|
|
28
|
+
function Part(props) {
|
|
29
|
+
const [id] = React.useState(() => String(nextPart++));
|
|
30
|
+
const slots = [];
|
|
31
|
+
const data = {};
|
|
32
|
+
for (const [name, value] of Object.entries(props)) {
|
|
33
|
+
if (name === 'children' || drawn(value)) {
|
|
34
|
+
slots.push([name, value]);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
data[name] = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
parts.useSend(id, data);
|
|
41
|
+
return React.createElement(PART_TAG, { k: path, d: id }, slots.map(([name, value]) => React.createElement(SLOT_TAG, { key: name, n: name }, value)));
|
|
42
|
+
}
|
|
43
|
+
Part.displayName = path;
|
|
44
|
+
this.paths.set(Part, path);
|
|
45
|
+
return Part;
|
|
46
|
+
}
|
|
47
|
+
/** The icons, each a stand-in. */
|
|
48
|
+
icons(names) {
|
|
49
|
+
return Object.fromEntries(names.map(name => [name, this.part(`ui.icons.${name}`)]));
|
|
50
|
+
}
|
|
51
|
+
/** Sends its data props as they change, what they gave out before let go; none once it is gone. */
|
|
52
|
+
useSend(id, data) {
|
|
53
|
+
const scope = React.useRef(undefined);
|
|
54
|
+
React.useLayoutEffect(() => {
|
|
55
|
+
var _a;
|
|
56
|
+
const codec = this.codec();
|
|
57
|
+
const next = codec.scope();
|
|
58
|
+
this.channel.notify('part', { id, props: codec.encode(data, undefined, next) });
|
|
59
|
+
(_a = scope.current) === null || _a === void 0 ? void 0 : _a.release();
|
|
60
|
+
scope.current = next;
|
|
61
|
+
});
|
|
62
|
+
React.useLayoutEffect(() => () => {
|
|
63
|
+
var _a;
|
|
64
|
+
this.channel.notify('part', { id });
|
|
65
|
+
(_a = scope.current) === null || _a === void 0 ? void 0 : _a.release();
|
|
66
|
+
}, [id]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=frame-parts.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Root } from 'react-dom/client';
|
|
2
|
+
import type { Channel } from '../channel/channel.js';
|
|
3
|
+
import type { Codec } from '../channel/codec.js';
|
|
4
|
+
import { RemoteMirror } from '../remote/remote-mirror.js';
|
|
5
|
+
import { FrameStore } from './frame-store.js';
|
|
6
|
+
/**
|
|
7
|
+
* The roots of a sandbox (docs/design/ta-extension-access.md 3.4): a component the page shows, rendered here by the
|
|
8
|
+
* extension's own React into a container of the sandbox's document, which RemoteMirror copies to the page.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FrameRoots {
|
|
11
|
+
protected readonly channel: Channel;
|
|
12
|
+
protected readonly codec: () => Codec;
|
|
13
|
+
protected readonly roots: Map<number, {
|
|
14
|
+
root: Root;
|
|
15
|
+
container: HTMLElement;
|
|
16
|
+
props: FrameStore<Record<string, unknown>>;
|
|
17
|
+
}>;
|
|
18
|
+
protected readonly mirror: RemoteMirror;
|
|
19
|
+
constructor(channel: Channel, codec: () => Codec);
|
|
20
|
+
protected mount({ root, component, props }: {
|
|
21
|
+
root: number;
|
|
22
|
+
component: number;
|
|
23
|
+
props: unknown;
|
|
24
|
+
}): void;
|
|
25
|
+
protected unmount(root: number): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { RemoteMirror } from '../remote/remote-mirror.js';
|
|
4
|
+
import { FrameStore } from './frame-store.js';
|
|
5
|
+
class Boundary extends React.Component {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.state = { failed: false };
|
|
9
|
+
}
|
|
10
|
+
static getDerivedStateFromError() {
|
|
11
|
+
return { failed: true };
|
|
12
|
+
}
|
|
13
|
+
componentDidCatch(error) {
|
|
14
|
+
this.props.report(error instanceof Error ? error.message : String(error));
|
|
15
|
+
}
|
|
16
|
+
render() {
|
|
17
|
+
return this.state.failed ? null : this.props.children;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function Live({ component: Shown, props }) {
|
|
21
|
+
const current = React.useSyncExternalStore(props.subscribe, props.get);
|
|
22
|
+
return React.createElement(Shown, { ...current });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The roots of a sandbox (docs/design/ta-extension-access.md 3.4): a component the page shows, rendered here by the
|
|
26
|
+
* extension's own React into a container of the sandbox's document, which RemoteMirror copies to the page.
|
|
27
|
+
*/
|
|
28
|
+
export class FrameRoots {
|
|
29
|
+
constructor(channel, codec) {
|
|
30
|
+
this.channel = channel;
|
|
31
|
+
this.codec = codec;
|
|
32
|
+
this.roots = new Map();
|
|
33
|
+
this.mirror = new RemoteMirror({
|
|
34
|
+
ops: (root, ops) => channel.notify('ops', { root, ops }),
|
|
35
|
+
link: href => channel.notify('link', href),
|
|
36
|
+
styles: css => channel.notify('styles', css),
|
|
37
|
+
});
|
|
38
|
+
channel.handle('mount', body => this.mount(body));
|
|
39
|
+
channel.on('props', body => {
|
|
40
|
+
var _a;
|
|
41
|
+
var _b;
|
|
42
|
+
const { root, props } = body;
|
|
43
|
+
(_a = this.roots.get(Number(root))) === null || _a === void 0 ? void 0 : _a.props.set(((_b = this.codec().decode(props)) !== null && _b !== void 0 ? _b : {}));
|
|
44
|
+
});
|
|
45
|
+
channel.on('unmount', body => this.unmount(Number(body.root)));
|
|
46
|
+
channel.on('event', body => this.mirror.dispatch(body));
|
|
47
|
+
this.mirror.observeHead();
|
|
48
|
+
}
|
|
49
|
+
mount({ root, component, props }) {
|
|
50
|
+
var _a;
|
|
51
|
+
const Shown = this.codec().component(Number(component));
|
|
52
|
+
if (typeof Shown !== 'function' && typeof Shown !== 'object') {
|
|
53
|
+
throw new Error('What the page shows is not one of the extension.');
|
|
54
|
+
}
|
|
55
|
+
const container = document.createElement('div');
|
|
56
|
+
document.body.appendChild(container);
|
|
57
|
+
const store = new FrameStore(((_a = this.codec().decode(props)) !== null && _a !== void 0 ? _a : {}));
|
|
58
|
+
const report = (message) => this.channel.notify('failed', { root, message });
|
|
59
|
+
const reactRoot = createRoot(container);
|
|
60
|
+
this.roots.set(root, { root: reactRoot, container, props: store });
|
|
61
|
+
this.mirror.observe(root, container);
|
|
62
|
+
reactRoot.render(React.createElement(Boundary, { report: report },
|
|
63
|
+
React.createElement(Live, { component: Shown, props: store })));
|
|
64
|
+
}
|
|
65
|
+
unmount(root) {
|
|
66
|
+
const found = this.roots.get(root);
|
|
67
|
+
if (!found) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.roots.delete(root);
|
|
71
|
+
this.mirror.stop(root);
|
|
72
|
+
found.root.unmount();
|
|
73
|
+
found.container.remove();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=frame-roots.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** A value the sandbox keeps of the page's, which hooks read and which changes as the page says. */
|
|
2
|
+
export declare class FrameStore<T> {
|
|
3
|
+
protected value: T;
|
|
4
|
+
protected readonly listeners: Set<() => void>;
|
|
5
|
+
constructor(value: T);
|
|
6
|
+
readonly subscribe: (listener: () => void) => () => undefined;
|
|
7
|
+
readonly get: () => T;
|
|
8
|
+
set(value: T): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** A value the sandbox keeps of the page's, which hooks read and which changes as the page says. */
|
|
2
|
+
export class FrameStore {
|
|
3
|
+
constructor(value) {
|
|
4
|
+
this.value = value;
|
|
5
|
+
this.listeners = new Set();
|
|
6
|
+
this.subscribe = (listener) => {
|
|
7
|
+
this.listeners.add(listener);
|
|
8
|
+
return () => void this.listeners.delete(listener);
|
|
9
|
+
};
|
|
10
|
+
this.get = () => this.value;
|
|
11
|
+
}
|
|
12
|
+
set(value) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
for (const listener of this.listeners)
|
|
15
|
+
listener();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=frame-store.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SandboxBoot } from '../sandbox-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* A sandbox's runtime (docs/design/ta-extension-access.md 3.3): its own React, the extension's `pi` made from the
|
|
4
|
+
* spec, its features, its module run once, and the roots the page shows copied there. Bundled whole into
|
|
5
|
+
* SANDBOX_RUNTIME (scripts/sandbox-runtime.ts).
|
|
6
|
+
*/
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
__taSandbox?: SandboxBoot;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { Channel } from '../channel/channel.js';
|
|
3
|
+
import { Codec } from '../channel/codec.js';
|
|
4
|
+
import { FrameApi } from './frame-api.js';
|
|
5
|
+
import { FRAME_FEATURES } from './frame-features.js';
|
|
6
|
+
import { FrameParts } from './frame-parts.js';
|
|
7
|
+
import { FrameRoots } from './frame-roots.js';
|
|
8
|
+
import { FrameStore } from './frame-store.js';
|
|
9
|
+
const boot = window.__taSandbox;
|
|
10
|
+
delete window.__taSandbox;
|
|
11
|
+
const channel = new Channel(boot.port);
|
|
12
|
+
let codec;
|
|
13
|
+
const getCodec = () => codec;
|
|
14
|
+
const parts = new FrameParts(channel, getCodec);
|
|
15
|
+
codec = new Codec(channel, { partOf: value => parts.pathOf(value) });
|
|
16
|
+
new FrameRoots(channel, getCodec);
|
|
17
|
+
const values = new FrameStore((_a = boot.values) !== null && _a !== void 0 ? _a : {});
|
|
18
|
+
channel.on('values', body => { var _a; return values.set(((_a = getCodec().decode(body)) !== null && _a !== void 0 ? _a : {})); });
|
|
19
|
+
async function main() {
|
|
20
|
+
var _a;
|
|
21
|
+
const pi = FrameApi.create({
|
|
22
|
+
channel,
|
|
23
|
+
codec: getCodec,
|
|
24
|
+
parts,
|
|
25
|
+
name: boot.name,
|
|
26
|
+
access: boot.access,
|
|
27
|
+
absent: new Set(boot.absent),
|
|
28
|
+
icons: boot.icons,
|
|
29
|
+
values,
|
|
30
|
+
parts_on: 'parts' in boot.features,
|
|
31
|
+
});
|
|
32
|
+
for (const [name, given] of Object.entries(boot.features)) {
|
|
33
|
+
(_a = FRAME_FEATURES[name]) === null || _a === void 0 ? void 0 : _a.call(FRAME_FEATURES, given, pi);
|
|
34
|
+
}
|
|
35
|
+
const url = URL.createObjectURL(new Blob([boot.code], { type: 'text/javascript' }));
|
|
36
|
+
const module = (await import(/* @vite-ignore */ url));
|
|
37
|
+
URL.revokeObjectURL(url);
|
|
38
|
+
if (typeof module.default !== 'function') {
|
|
39
|
+
throw new Error('A web extension exports a function as its default export.');
|
|
40
|
+
}
|
|
41
|
+
module.default(pi);
|
|
42
|
+
await channel.request('ready');
|
|
43
|
+
}
|
|
44
|
+
main().catch(error => void channel.request('failed', error instanceof Error ? error.message : String(error)).catch(() => undefined));
|
|
45
|
+
//# sourceMappingURL=sandbox-runtime.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WebExtensionAPI } from '../extension/web-extension-api.js';
|
|
2
|
+
import type { SandboxOptions } from './sandbox-protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* What a sandbox can do besides the API, each a feature of its own the user turns on or off (docs/design/ta-extension-access.md
|
|
5
|
+
* 3.6): its name, the option that turns it on, what of the API is not there without it. Its half in the sandbox is the
|
|
6
|
+
* entry of the same name in FRAME_FEATURES (runtime/frame-features.ts); one off is not given to the sandbox at all.
|
|
7
|
+
*/
|
|
8
|
+
export interface SandboxFeature {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly option: Exclude<keyof SandboxOptions, 'isolate'>;
|
|
11
|
+
/** The members of the API not there while it is off. */
|
|
12
|
+
absent?(): string[];
|
|
13
|
+
/** What the page gives its half in the sandbox as it starts. */
|
|
14
|
+
boot?(pi: WebExtensionAPI): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
/** The key of the extension's storage that keeps its `localStorage`. */
|
|
17
|
+
export declare const LOCAL_KEY = "local:";
|
|
18
|
+
export declare const SANDBOX_FEATURES: readonly SandboxFeature[];
|
|
19
|
+
export declare namespace SandboxFeatureUtil {
|
|
20
|
+
/** What the features on give the sandbox, by name, and the members of the API those off take away. */
|
|
21
|
+
function of(options: SandboxOptions, pi: WebExtensionAPI): Promise<{
|
|
22
|
+
features: Record<string, unknown>;
|
|
23
|
+
absent: string[];
|
|
24
|
+
}>;
|
|
25
|
+
}
|