@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,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RemoteRoot = RemoteRoot;
|
|
37
|
+
const React = __importStar(require("react"));
|
|
38
|
+
const react_dom_1 = require("react-dom");
|
|
39
|
+
const empty_state_1 = require("../components/empty-state");
|
|
40
|
+
/** What the extension gave a part of Ta to draw (its children, a title of nodes), moved under where the part draws it. */
|
|
41
|
+
function Slot({ node, className }) {
|
|
42
|
+
const ref = React.useRef(null);
|
|
43
|
+
React.useLayoutEffect(() => {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.appendChild(node);
|
|
46
|
+
}, [node]);
|
|
47
|
+
return React.createElement("span", { ref: ref, className: className });
|
|
48
|
+
}
|
|
49
|
+
class Boundary extends React.Component {
|
|
50
|
+
constructor() {
|
|
51
|
+
super(...arguments);
|
|
52
|
+
this.state = { failed: false };
|
|
53
|
+
}
|
|
54
|
+
static getDerivedStateFromError() {
|
|
55
|
+
return { failed: true };
|
|
56
|
+
}
|
|
57
|
+
componentDidCatch(error) {
|
|
58
|
+
console.error('A part of Ta in a sandbox failed:', error);
|
|
59
|
+
}
|
|
60
|
+
render() {
|
|
61
|
+
return this.state.failed ? null : this.props.children;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** A part of Ta in a copy: its component, its props from the sandbox, and its slots. */
|
|
65
|
+
function Part({ host, element }) {
|
|
66
|
+
const version = React.useSyncExternalStore(host.parts.subscribe, host.parts.version);
|
|
67
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: version says the props or the slots changed
|
|
68
|
+
const shown = React.useMemo(() => {
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
const Component = host.partComponent((_a = element.getAttribute('k')) !== null && _a !== void 0 ? _a : '');
|
|
71
|
+
if (!Component) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const props = { ...((_c = host.parts.props((_b = element.getAttribute('d')) !== null && _b !== void 0 ? _b : '')) !== null && _c !== void 0 ? _c : {}) };
|
|
75
|
+
for (const [name, node] of host.parts.slots(element)) {
|
|
76
|
+
props[name] = React.createElement(Slot, { node: node, className: host.className });
|
|
77
|
+
}
|
|
78
|
+
return React.createElement(Component, { ...props });
|
|
79
|
+
}, [host, element, version]);
|
|
80
|
+
return (0, react_dom_1.createPortal)(React.createElement(Boundary, null, shown), element);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A component of an extension in a sandbox, where the page shows it (docs/design/ta-extension-access.md 3.4): a root
|
|
84
|
+
* of its own in the sandbox, copied here into real DOM, with Ta's components drawn in it by the page itself.
|
|
85
|
+
*/
|
|
86
|
+
function RemoteRoot({ host, component, props }) {
|
|
87
|
+
const ref = React.useRef(null);
|
|
88
|
+
const [root, setRoot] = React.useState();
|
|
89
|
+
const [failed, setFailed] = React.useState();
|
|
90
|
+
const [parts, setParts] = React.useState([]);
|
|
91
|
+
const latest = React.useRef(props);
|
|
92
|
+
latest.current = props;
|
|
93
|
+
React.useLayoutEffect(() => {
|
|
94
|
+
const element = ref.current;
|
|
95
|
+
if (!element) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const mounted = host.mount(element, component, latest.current, {
|
|
99
|
+
part: part => setParts(list => (list.includes(part) ? list : [...list, part])),
|
|
100
|
+
partGone: part => setParts(list => list.filter(one => one !== part)),
|
|
101
|
+
failed: setFailed,
|
|
102
|
+
});
|
|
103
|
+
setRoot(mounted);
|
|
104
|
+
return () => host.unmount(mounted);
|
|
105
|
+
}, [host, component]);
|
|
106
|
+
React.useEffect(() => {
|
|
107
|
+
if (root !== undefined) {
|
|
108
|
+
host.props(root, props);
|
|
109
|
+
}
|
|
110
|
+
}, [host, root, props]);
|
|
111
|
+
// The copy in a box of its own, whose children React never touches; the parts of Ta drawn into it by portals.
|
|
112
|
+
return (React.createElement(React.Fragment, null,
|
|
113
|
+
failed ? React.createElement(empty_state_1.EmptyState, { compact: true, tone: "error", title: failed }) : null,
|
|
114
|
+
React.createElement("div", { ref: ref, className: `ta-remote ${host.className}` }),
|
|
115
|
+
parts.map(part => (React.createElement(Part, { key: host.parts.keyOf(part), host: host, element: part })))));
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=remote-root.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TaExtensionAccess } from '@celljs/ta-protocol';
|
|
2
|
+
import type { WebExtensionAPI } from '../../extension/web-extension-api';
|
|
3
|
+
import type { Channel } from '../channel/channel';
|
|
4
|
+
import type { Codec } from '../channel/codec';
|
|
5
|
+
import type { FrameParts } from './frame-parts';
|
|
6
|
+
import { FrameStore } from './frame-store';
|
|
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
|
+
}
|
|
29
|
+
//# sourceMappingURL=frame-api.d.ts.map
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FrameApi = void 0;
|
|
37
|
+
const React = __importStar(require("react"));
|
|
38
|
+
const busy_1 = require("../../components/busy");
|
|
39
|
+
const web_access_1 = require("../../extension/web-access");
|
|
40
|
+
const web_api_spec_1 = require("../../extension/web-api-spec");
|
|
41
|
+
const frame_store_1 = require("./frame-store");
|
|
42
|
+
/** What the sandbox gives itself (`local` of WEB_API_SPEC), by path. */
|
|
43
|
+
const LOCAL = { React, 'ui.useBusy': busy_1.useBusy };
|
|
44
|
+
let nextHook = 1;
|
|
45
|
+
/**
|
|
46
|
+
* The extension's `pi` in a sandbox, made from WEB_API_SPEC alone (docs/design/ta-extension-access.md 3.2): each
|
|
47
|
+
* member as its form says, crossing to the page by its path; then cut by the same WebAccessUtil.limit as in the page.
|
|
48
|
+
* No member is written here by hand.
|
|
49
|
+
*/
|
|
50
|
+
var FrameApi;
|
|
51
|
+
(function (FrameApi) {
|
|
52
|
+
function create(source) {
|
|
53
|
+
const hooks = new Map();
|
|
54
|
+
source.channel.on('hook', body => {
|
|
55
|
+
var _a;
|
|
56
|
+
const { key, value, error } = body;
|
|
57
|
+
if (error) {
|
|
58
|
+
console.error(error);
|
|
59
|
+
}
|
|
60
|
+
(_a = hooks.get(String(key))) === null || _a === void 0 ? void 0 : _a.set(error ? undefined : source.codec().decode(value));
|
|
61
|
+
});
|
|
62
|
+
const whole = group(source, hooks, web_api_spec_1.WEB_API_SPEC, '');
|
|
63
|
+
return web_access_1.WebAccessUtil.limit(whole, source.access, source.name);
|
|
64
|
+
}
|
|
65
|
+
FrameApi.create = create;
|
|
66
|
+
function group(source, hooks, members, prefix) {
|
|
67
|
+
const made = {};
|
|
68
|
+
for (const [key, entry] of Object.entries(members)) {
|
|
69
|
+
const path = prefix + key;
|
|
70
|
+
if (source.absent.has(path) || entry.form === 'page') {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const descriptor = member(source, hooks, path, entry);
|
|
74
|
+
if (descriptor) {
|
|
75
|
+
Object.defineProperty(made, key, { enumerable: true, ...descriptor });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return made;
|
|
79
|
+
}
|
|
80
|
+
function member(source, hooks, path, entry) {
|
|
81
|
+
const { channel, codec, values } = source;
|
|
82
|
+
const ask = (args, shapes) => channel.request('api', { path, args: codec().encodeArgs(args, shapes) }).then(value => codec().decode(value));
|
|
83
|
+
switch (entry.form) {
|
|
84
|
+
case 'local':
|
|
85
|
+
return Object.keys(LOCAL).includes(path) ? { value: LOCAL[path] } : undefined;
|
|
86
|
+
case 'group':
|
|
87
|
+
return { value: group(source, hooks, entry.members, `${path}.`) };
|
|
88
|
+
case 'value':
|
|
89
|
+
return { get: () => values.get()[path] };
|
|
90
|
+
case 'read':
|
|
91
|
+
return { value: () => values.get()[path] };
|
|
92
|
+
case 'component':
|
|
93
|
+
return source.parts_on ? { value: source.parts.part(path) } : undefined;
|
|
94
|
+
case 'components':
|
|
95
|
+
return source.parts_on ? { value: source.parts.icons(source.icons) } : undefined;
|
|
96
|
+
case 'call':
|
|
97
|
+
if (entry.returns === 'url') {
|
|
98
|
+
// The same address for the same arguments, as in the page.
|
|
99
|
+
const urls = new Map();
|
|
100
|
+
return {
|
|
101
|
+
value: (...args) => {
|
|
102
|
+
const key = JSON.stringify(args);
|
|
103
|
+
let url = urls.get(key);
|
|
104
|
+
if (!url) {
|
|
105
|
+
url = ask(args, entry.args).then(blob => URL.createObjectURL(blob));
|
|
106
|
+
urls.set(key, url);
|
|
107
|
+
url.catch(() => urls.delete(key));
|
|
108
|
+
}
|
|
109
|
+
return url;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return { value: (...args) => ask(args, entry.args) };
|
|
114
|
+
case 'fire':
|
|
115
|
+
return {
|
|
116
|
+
value: (...args) => {
|
|
117
|
+
ask(args, entry.args).catch(error => console.error(`pi.${path}:`, error));
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
case 'hold':
|
|
121
|
+
return {
|
|
122
|
+
value: (...args) => {
|
|
123
|
+
const held = ask(args, entry.args);
|
|
124
|
+
held.catch(error => console.error(`pi.${path}:`, error));
|
|
125
|
+
let released = false;
|
|
126
|
+
return () => {
|
|
127
|
+
if (!released) {
|
|
128
|
+
released = true;
|
|
129
|
+
void held.then(id => channel.request('release', id)).catch(() => undefined);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
case 'hook':
|
|
135
|
+
return { value: entry.peek ? peek(values, path) : hook(source, hooks, path, entry.args) };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** A hook the page reads before the extension starts and sends again as it changes. */
|
|
139
|
+
function peek(values, path) {
|
|
140
|
+
// biome-ignore lint/correctness/noComponentHookFactories: a member of pi made from the spec, the same function for every render
|
|
141
|
+
return function usePeek() {
|
|
142
|
+
return React.useSyncExternalStore(values.subscribe, () => values.get()[path]);
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* A hook the page runs for it while it is mounted (HookHost): its value comes as the page renders it, undefined at
|
|
147
|
+
* first. Functions among its arguments cross once, each calling the latest of them, so that a new closure each
|
|
148
|
+
* render is not a new watch.
|
|
149
|
+
*/
|
|
150
|
+
function hook(source, hooks, path, shapes) {
|
|
151
|
+
const { channel, codec } = source;
|
|
152
|
+
// biome-ignore lint/correctness/noComponentHookFactories: a member of pi made from the spec, the same function for every render
|
|
153
|
+
return function useRemote(...args) {
|
|
154
|
+
var _a;
|
|
155
|
+
const [key] = React.useState(() => `h${nextHook++}`);
|
|
156
|
+
const [store] = React.useState(() => new frame_store_1.FrameStore(undefined));
|
|
157
|
+
const latest = React.useRef(args);
|
|
158
|
+
latest.current = args;
|
|
159
|
+
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));
|
|
160
|
+
const encoded = args.map((arg, index) => (typeof arg === 'function' ? stable[index] : arg));
|
|
161
|
+
const data = JSON.stringify((_a = args.map(arg => (typeof arg === 'function' ? null : arg))) !== null && _a !== void 0 ? _a : null);
|
|
162
|
+
const sent = React.useRef(undefined);
|
|
163
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: watched once; its arguments are sent again below as they change
|
|
164
|
+
React.useLayoutEffect(() => {
|
|
165
|
+
hooks.set(key, store);
|
|
166
|
+
channel.notify('hook.watch', { key, path, args: codec().encodeArgs(encoded, shapes) });
|
|
167
|
+
sent.current = data;
|
|
168
|
+
return () => {
|
|
169
|
+
hooks.delete(key);
|
|
170
|
+
channel.notify('hook.unwatch', { key });
|
|
171
|
+
};
|
|
172
|
+
}, [key]);
|
|
173
|
+
React.useLayoutEffect(() => {
|
|
174
|
+
if (sent.current !== undefined && sent.current !== data) {
|
|
175
|
+
sent.current = data;
|
|
176
|
+
channel.notify('hook.args', { key, args: codec().encodeArgs(encoded, shapes) });
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return React.useSyncExternalStore(store.subscribe, store.get);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
})(FrameApi || (exports.FrameApi = FrameApi = {}));
|
|
183
|
+
//# sourceMappingURL=frame-api.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { WebExtensionAPI } from '../../extension/web-extension-api';
|
|
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>>;
|
|
7
|
+
//# sourceMappingURL=frame-features.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FRAME_FEATURES = void 0;
|
|
4
|
+
const sandbox_features_1 = require("../sandbox-features");
|
|
5
|
+
const sandbox_protocol_1 = require("../sandbox-protocol");
|
|
6
|
+
/**
|
|
7
|
+
* The sandbox's half of each feature (SANDBOX_FEATURES, by the same name), given what the page's half gave it. One
|
|
8
|
+
* the user turned off is never started.
|
|
9
|
+
*/
|
|
10
|
+
exports.FRAME_FEATURES = {
|
|
11
|
+
/** A `localStorage` as in the page, kept with the extension's storage: a document of no origin has none (3.5). */
|
|
12
|
+
local: (given, pi) => {
|
|
13
|
+
const items = new Map(Object.entries(given && typeof given === 'object' ? given : {}).map(([key, value]) => [key, String(value)]));
|
|
14
|
+
let timer;
|
|
15
|
+
const save = () => {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = setTimeout(() => void pi.storage.set(sandbox_features_1.LOCAL_KEY, Object.fromEntries(items)).catch(error => console.error(error)), 300);
|
|
18
|
+
};
|
|
19
|
+
const size = () => [...items].reduce((sum, [key, value]) => sum + key.length + value.length, 0);
|
|
20
|
+
const storage = {
|
|
21
|
+
get length() {
|
|
22
|
+
return items.size;
|
|
23
|
+
},
|
|
24
|
+
key: index => { var _a; return (_a = [...items.keys()][index]) !== null && _a !== void 0 ? _a : null; },
|
|
25
|
+
getItem: key => { var _a; return (_a = items.get(String(key))) !== null && _a !== void 0 ? _a : null; },
|
|
26
|
+
setItem: (key, value) => {
|
|
27
|
+
const before = items.get(String(key));
|
|
28
|
+
items.set(String(key), String(value));
|
|
29
|
+
if (size() > sandbox_protocol_1.SandboxLimits.LOCAL_CHARS) {
|
|
30
|
+
if (before === undefined) {
|
|
31
|
+
items.delete(String(key));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
items.set(String(key), before);
|
|
35
|
+
}
|
|
36
|
+
throw new DOMException('The storage of this extension is full.', 'QuotaExceededError');
|
|
37
|
+
}
|
|
38
|
+
save();
|
|
39
|
+
},
|
|
40
|
+
removeItem: key => {
|
|
41
|
+
if (items.delete(String(key))) {
|
|
42
|
+
save();
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
clear: () => {
|
|
46
|
+
items.clear();
|
|
47
|
+
save();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(window, 'localStorage', { configurable: true, get: () => storage });
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=frame-features.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { Channel } from '../channel/channel';
|
|
3
|
+
import type { Codec } from '../channel/codec';
|
|
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
|
+
}
|
|
37
|
+
//# sourceMappingURL=frame-parts.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FrameParts = void 0;
|
|
37
|
+
const React = __importStar(require("react"));
|
|
38
|
+
const remote_protocol_1 = require("../remote/remote-protocol");
|
|
39
|
+
let nextPart = 1;
|
|
40
|
+
/** Whether a prop is something to draw (an element, elements), which goes in a slot rather than across as data. */
|
|
41
|
+
function drawn(value) {
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
return value.some(drawn);
|
|
44
|
+
}
|
|
45
|
+
return React.isValidElement(value);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The stand-ins of Ta's components in a sandbox (docs/design/ta-extension-access.md 3.4): each draws a `<ta-part>`,
|
|
49
|
+
* copied to the page, where the page draws the component itself; what is given it to draw goes in `<ta-slot>`s, its
|
|
50
|
+
* other props across the channel. Known by their paths, so that what crosses names them, not handles.
|
|
51
|
+
*/
|
|
52
|
+
class FrameParts {
|
|
53
|
+
constructor(channel, codec) {
|
|
54
|
+
this.channel = channel;
|
|
55
|
+
this.codec = codec;
|
|
56
|
+
this.paths = new Map();
|
|
57
|
+
}
|
|
58
|
+
pathOf(value) {
|
|
59
|
+
return this.paths.get(value);
|
|
60
|
+
}
|
|
61
|
+
/** The stand-in of the component of `path`. */
|
|
62
|
+
part(path) {
|
|
63
|
+
const parts = this;
|
|
64
|
+
function Part(props) {
|
|
65
|
+
const [id] = React.useState(() => String(nextPart++));
|
|
66
|
+
const slots = [];
|
|
67
|
+
const data = {};
|
|
68
|
+
for (const [name, value] of Object.entries(props)) {
|
|
69
|
+
if (name === 'children' || drawn(value)) {
|
|
70
|
+
slots.push([name, value]);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
data[name] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
parts.useSend(id, data);
|
|
77
|
+
return React.createElement(remote_protocol_1.PART_TAG, { k: path, d: id }, slots.map(([name, value]) => React.createElement(remote_protocol_1.SLOT_TAG, { key: name, n: name }, value)));
|
|
78
|
+
}
|
|
79
|
+
Part.displayName = path;
|
|
80
|
+
this.paths.set(Part, path);
|
|
81
|
+
return Part;
|
|
82
|
+
}
|
|
83
|
+
/** The icons, each a stand-in. */
|
|
84
|
+
icons(names) {
|
|
85
|
+
return Object.fromEntries(names.map(name => [name, this.part(`ui.icons.${name}`)]));
|
|
86
|
+
}
|
|
87
|
+
/** Sends its data props as they change, what they gave out before let go; none once it is gone. */
|
|
88
|
+
useSend(id, data) {
|
|
89
|
+
const scope = React.useRef(undefined);
|
|
90
|
+
React.useLayoutEffect(() => {
|
|
91
|
+
var _a;
|
|
92
|
+
const codec = this.codec();
|
|
93
|
+
const next = codec.scope();
|
|
94
|
+
this.channel.notify('part', { id, props: codec.encode(data, undefined, next) });
|
|
95
|
+
(_a = scope.current) === null || _a === void 0 ? void 0 : _a.release();
|
|
96
|
+
scope.current = next;
|
|
97
|
+
});
|
|
98
|
+
React.useLayoutEffect(() => () => {
|
|
99
|
+
var _a;
|
|
100
|
+
this.channel.notify('part', { id });
|
|
101
|
+
(_a = scope.current) === null || _a === void 0 ? void 0 : _a.release();
|
|
102
|
+
}, [id]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.FrameParts = FrameParts;
|
|
106
|
+
//# sourceMappingURL=frame-parts.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Root } from 'react-dom/client';
|
|
2
|
+
import type { Channel } from '../channel/channel';
|
|
3
|
+
import type { Codec } from '../channel/codec';
|
|
4
|
+
import { RemoteMirror } from '../remote/remote-mirror';
|
|
5
|
+
import { FrameStore } from './frame-store';
|
|
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
|
+
}
|
|
27
|
+
//# sourceMappingURL=frame-roots.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FrameRoots = void 0;
|
|
37
|
+
const React = __importStar(require("react"));
|
|
38
|
+
const client_1 = require("react-dom/client");
|
|
39
|
+
const remote_mirror_1 = require("../remote/remote-mirror");
|
|
40
|
+
const frame_store_1 = require("./frame-store");
|
|
41
|
+
class Boundary extends React.Component {
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.state = { failed: false };
|
|
45
|
+
}
|
|
46
|
+
static getDerivedStateFromError() {
|
|
47
|
+
return { failed: true };
|
|
48
|
+
}
|
|
49
|
+
componentDidCatch(error) {
|
|
50
|
+
this.props.report(error instanceof Error ? error.message : String(error));
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
return this.state.failed ? null : this.props.children;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function Live({ component: Shown, props }) {
|
|
57
|
+
const current = React.useSyncExternalStore(props.subscribe, props.get);
|
|
58
|
+
return React.createElement(Shown, { ...current });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The roots of a sandbox (docs/design/ta-extension-access.md 3.4): a component the page shows, rendered here by the
|
|
62
|
+
* extension's own React into a container of the sandbox's document, which RemoteMirror copies to the page.
|
|
63
|
+
*/
|
|
64
|
+
class FrameRoots {
|
|
65
|
+
constructor(channel, codec) {
|
|
66
|
+
this.channel = channel;
|
|
67
|
+
this.codec = codec;
|
|
68
|
+
this.roots = new Map();
|
|
69
|
+
this.mirror = new remote_mirror_1.RemoteMirror({
|
|
70
|
+
ops: (root, ops) => channel.notify('ops', { root, ops }),
|
|
71
|
+
link: href => channel.notify('link', href),
|
|
72
|
+
styles: css => channel.notify('styles', css),
|
|
73
|
+
});
|
|
74
|
+
channel.handle('mount', body => this.mount(body));
|
|
75
|
+
channel.on('props', body => {
|
|
76
|
+
var _a;
|
|
77
|
+
var _b;
|
|
78
|
+
const { root, props } = body;
|
|
79
|
+
(_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 : {}));
|
|
80
|
+
});
|
|
81
|
+
channel.on('unmount', body => this.unmount(Number(body.root)));
|
|
82
|
+
channel.on('event', body => this.mirror.dispatch(body));
|
|
83
|
+
this.mirror.observeHead();
|
|
84
|
+
}
|
|
85
|
+
mount({ root, component, props }) {
|
|
86
|
+
var _a;
|
|
87
|
+
const Shown = this.codec().component(Number(component));
|
|
88
|
+
if (typeof Shown !== 'function' && typeof Shown !== 'object') {
|
|
89
|
+
throw new Error('What the page shows is not one of the extension.');
|
|
90
|
+
}
|
|
91
|
+
const container = document.createElement('div');
|
|
92
|
+
document.body.appendChild(container);
|
|
93
|
+
const store = new frame_store_1.FrameStore(((_a = this.codec().decode(props)) !== null && _a !== void 0 ? _a : {}));
|
|
94
|
+
const report = (message) => this.channel.notify('failed', { root, message });
|
|
95
|
+
const reactRoot = (0, client_1.createRoot)(container);
|
|
96
|
+
this.roots.set(root, { root: reactRoot, container, props: store });
|
|
97
|
+
this.mirror.observe(root, container);
|
|
98
|
+
reactRoot.render(React.createElement(Boundary, { report: report },
|
|
99
|
+
React.createElement(Live, { component: Shown, props: store })));
|
|
100
|
+
}
|
|
101
|
+
unmount(root) {
|
|
102
|
+
const found = this.roots.get(root);
|
|
103
|
+
if (!found) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.roots.delete(root);
|
|
107
|
+
this.mirror.stop(root);
|
|
108
|
+
found.root.unmount();
|
|
109
|
+
found.container.remove();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.FrameRoots = FrameRoots;
|
|
113
|
+
//# sourceMappingURL=frame-roots.js.map
|