@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,251 @@
|
|
|
1
|
+
/** The key of what stands for a function, a component, a part of Ta or a live object as it crosses. */
|
|
2
|
+
export const MARK = '#ta';
|
|
3
|
+
/** Handles given out together, let go together: the props of a part, the registration of a view. */
|
|
4
|
+
export class CodecScope {
|
|
5
|
+
constructor(codec) {
|
|
6
|
+
this.codec = codec;
|
|
7
|
+
this.ids = new Set();
|
|
8
|
+
this.stops = [];
|
|
9
|
+
}
|
|
10
|
+
release() {
|
|
11
|
+
this.codec.release(this);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const ELEMENT = [Symbol.for('react.element'), Symbol.for('react.transitional.element')];
|
|
15
|
+
/**
|
|
16
|
+
* Turns what crosses into what a structured clone carries, and back (docs/design/ta-extension-access.md 3.2): a
|
|
17
|
+
* function becomes a handle the other side calls through the channel (its result a promise), a component one the
|
|
18
|
+
* other side draws, a part of Ta its path, the live methods of an object a snapshot sent again as it changes. Both
|
|
19
|
+
* ends have one; neither knows what the values mean.
|
|
20
|
+
*/
|
|
21
|
+
export class Codec {
|
|
22
|
+
constructor(channel, side = {}) {
|
|
23
|
+
this.channel = channel;
|
|
24
|
+
this.side = side;
|
|
25
|
+
this.nextId = 1;
|
|
26
|
+
this.own = new Map();
|
|
27
|
+
this.ids = new WeakMap();
|
|
28
|
+
this.proxies = new Map();
|
|
29
|
+
this.lives = new Map();
|
|
30
|
+
this.forever = new CodecScope(this);
|
|
31
|
+
channel.handle('fn', body => {
|
|
32
|
+
const { id, args } = body;
|
|
33
|
+
const found = this.own.get(id);
|
|
34
|
+
if ((found === null || found === void 0 ? void 0 : found.kind) !== 'f') {
|
|
35
|
+
throw new Error('That function is gone.');
|
|
36
|
+
}
|
|
37
|
+
const decoded = (Array.isArray(args) ? args : []).map(arg => this.decode(arg));
|
|
38
|
+
return Promise.resolve(found.value(...decoded)).then(value => this.encode(value));
|
|
39
|
+
});
|
|
40
|
+
channel.on('live', body => {
|
|
41
|
+
const { id, values } = body;
|
|
42
|
+
const live = this.lives.get(id);
|
|
43
|
+
if (live) {
|
|
44
|
+
live.values = this.decode(values);
|
|
45
|
+
for (const listener of live.listeners)
|
|
46
|
+
listener();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
scope() {
|
|
51
|
+
return new CodecScope(this);
|
|
52
|
+
}
|
|
53
|
+
/** A component this side handed out, by its handle. */
|
|
54
|
+
component(id) {
|
|
55
|
+
const found = this.own.get(id);
|
|
56
|
+
return (found === null || found === void 0 ? void 0 : found.kind) === 'c' ? found.value : undefined;
|
|
57
|
+
}
|
|
58
|
+
/** The arguments of a call, each by its shape. */
|
|
59
|
+
encodeArgs(args, shapes, scope = this.forever) {
|
|
60
|
+
return args.map((arg, index) => { var _a; return this.encode(arg, (_a = shapes === null || shapes === void 0 ? void 0 : shapes[index]) !== null && _a !== void 0 ? _a : undefined, scope); });
|
|
61
|
+
}
|
|
62
|
+
encode(value, shape, scope = this.forever, seen = new Set()) {
|
|
63
|
+
var _a, _b, _c, _d, _e;
|
|
64
|
+
if (shape === 'X') {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
if (shape === 'L') {
|
|
68
|
+
return typeof value === 'function' ? String(value()) : value;
|
|
69
|
+
}
|
|
70
|
+
if (shape === 'C') {
|
|
71
|
+
return value === undefined || value === null ? value : this.componentMark(value, scope);
|
|
72
|
+
}
|
|
73
|
+
if (typeof value === 'symbol') {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (typeof value === 'function') {
|
|
77
|
+
const path = (_b = (_a = this.side).partOf) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
78
|
+
return path ? { [MARK]: 'part', path } : { [MARK]: 'f', id: this.hold(value, 'f', scope) };
|
|
79
|
+
}
|
|
80
|
+
if (!value || typeof value !== 'object') {
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
if (seen.has(value)) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const kind = value.$typeof;
|
|
87
|
+
if (ELEMENT.includes(kind)) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (typeof kind === 'symbol') {
|
|
91
|
+
// A component of React's own kinds (memo, forwardRef): drawn where it is, as any component.
|
|
92
|
+
return this.componentMark(value, scope);
|
|
93
|
+
}
|
|
94
|
+
const path = (_d = (_c = this.side).partOf) === null || _d === void 0 ? void 0 : _d.call(_c, value);
|
|
95
|
+
if (path) {
|
|
96
|
+
return { [MARK]: 'part', path };
|
|
97
|
+
}
|
|
98
|
+
if (Codec.cloned(value)) {
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
seen.add(value);
|
|
102
|
+
try {
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
const each = shape && typeof shape === 'object' ? shape.each : undefined;
|
|
105
|
+
return value.map(item => this.encode(item, each, scope, seen));
|
|
106
|
+
}
|
|
107
|
+
if (typeof Node !== 'undefined' && value instanceof Node) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const fields = shape && typeof shape === 'object' ? shape : undefined;
|
|
111
|
+
if ((_e = fields === null || fields === void 0 ? void 0 : fields.live) === null || _e === void 0 ? void 0 : _e.length) {
|
|
112
|
+
return this.liveMark(value, fields, scope, seen);
|
|
113
|
+
}
|
|
114
|
+
return this.fields(value, fields, scope, seen);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
seen.delete(value);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
decode(value) {
|
|
121
|
+
var _a, _b, _c, _d;
|
|
122
|
+
if (!value || typeof value !== 'object' || Codec.cloned(value)) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
if (Array.isArray(value)) {
|
|
126
|
+
return value.map(item => this.decode(item));
|
|
127
|
+
}
|
|
128
|
+
const mark = value;
|
|
129
|
+
switch (mark[MARK]) {
|
|
130
|
+
case 'f':
|
|
131
|
+
return this.proxy(Number(mark.id));
|
|
132
|
+
case 'c':
|
|
133
|
+
return (_b = (_a = this.side).component) === null || _b === void 0 ? void 0 : _b.call(_a, Number(mark.id));
|
|
134
|
+
case 'part':
|
|
135
|
+
return (_d = (_c = this.side).part) === null || _d === void 0 ? void 0 : _d.call(_c, String(mark.path));
|
|
136
|
+
case 'live':
|
|
137
|
+
return this.live(value);
|
|
138
|
+
}
|
|
139
|
+
const decoded = {};
|
|
140
|
+
for (const [key, item] of Object.entries(value)) {
|
|
141
|
+
decoded[key] = this.decode(item);
|
|
142
|
+
}
|
|
143
|
+
return decoded;
|
|
144
|
+
}
|
|
145
|
+
release(scope) {
|
|
146
|
+
for (const stop of scope.stops.splice(0))
|
|
147
|
+
stop();
|
|
148
|
+
for (const id of scope.ids) {
|
|
149
|
+
const found = this.own.get(id);
|
|
150
|
+
if (found && --found.uses <= 0) {
|
|
151
|
+
this.own.delete(id);
|
|
152
|
+
if (found.value && (typeof found.value === 'object' || typeof found.value === 'function')) {
|
|
153
|
+
this.ids.delete(found.value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
scope.ids.clear();
|
|
158
|
+
}
|
|
159
|
+
componentMark(value, scope) {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
const path = (_b = (_a = this.side).partOf) === null || _b === void 0 ? void 0 : _b.call(_a, value);
|
|
162
|
+
return path ? { [MARK]: 'part', path } : { [MARK]: 'c', id: this.hold(value, 'c', scope) };
|
|
163
|
+
}
|
|
164
|
+
fields(value, shape, scope, seen, skip) {
|
|
165
|
+
const fields = shape && typeof shape === 'object' ? shape.fields : undefined;
|
|
166
|
+
const encoded = {};
|
|
167
|
+
for (const key of Object.keys(value)) {
|
|
168
|
+
if (!(skip === null || skip === void 0 ? void 0 : skip.includes(key))) {
|
|
169
|
+
encoded[key] = this.encode(value[key], fields === null || fields === void 0 ? void 0 : fields[key], scope, seen);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return encoded;
|
|
173
|
+
}
|
|
174
|
+
/** Its live methods read now and again whenever its own `subscribe` says, the rest as fields. */
|
|
175
|
+
liveMark(value, shape, scope, seen) {
|
|
176
|
+
var _a;
|
|
177
|
+
const names = (_a = shape.live) !== null && _a !== void 0 ? _a : [];
|
|
178
|
+
const id = this.nextId++;
|
|
179
|
+
// Each read in a scope of its own, the one before let go: what a menu gave out before is gone with it.
|
|
180
|
+
let current = this.scope();
|
|
181
|
+
scope.stops.push(() => current.release());
|
|
182
|
+
const read = () => {
|
|
183
|
+
const next = this.scope();
|
|
184
|
+
const values = {};
|
|
185
|
+
for (const name of names) {
|
|
186
|
+
const method = value[name];
|
|
187
|
+
if (typeof method === 'function') {
|
|
188
|
+
values[name] = this.encode(method.call(value), undefined, next);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
current.release();
|
|
192
|
+
current = next;
|
|
193
|
+
return values;
|
|
194
|
+
};
|
|
195
|
+
const subscribe = value.subscribe;
|
|
196
|
+
if (typeof subscribe === 'function') {
|
|
197
|
+
const stop = subscribe.call(value, () => this.channel.notify('live', { id, values: read() }));
|
|
198
|
+
if (typeof stop === 'function') {
|
|
199
|
+
scope.stops.push(stop);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { [MARK]: 'live', id, values: read(), rest: this.fields(value, shape, scope, seen, [...names, 'subscribe']) };
|
|
203
|
+
}
|
|
204
|
+
live(mark) {
|
|
205
|
+
var _a;
|
|
206
|
+
const id = Number(mark.id);
|
|
207
|
+
const live = { values: this.decode(mark.values), listeners: new Set() };
|
|
208
|
+
this.lives.set(id, live);
|
|
209
|
+
const object = ((_a = this.decode(mark.rest)) !== null && _a !== void 0 ? _a : {});
|
|
210
|
+
for (const name of Object.keys(live.values)) {
|
|
211
|
+
object[name] = () => live.values[name];
|
|
212
|
+
}
|
|
213
|
+
object.subscribe = (listener) => {
|
|
214
|
+
live.listeners.add(listener);
|
|
215
|
+
return () => live.listeners.delete(listener);
|
|
216
|
+
};
|
|
217
|
+
return object;
|
|
218
|
+
}
|
|
219
|
+
hold(value, kind, scope) {
|
|
220
|
+
var _a;
|
|
221
|
+
const key = value;
|
|
222
|
+
let id = this.ids.get(key);
|
|
223
|
+
if (id === undefined || ((_a = this.own.get(id)) === null || _a === void 0 ? void 0 : _a.kind) !== kind) {
|
|
224
|
+
id = this.nextId++;
|
|
225
|
+
this.ids.set(key, id);
|
|
226
|
+
this.own.set(id, { value, uses: 0, kind });
|
|
227
|
+
}
|
|
228
|
+
if (!scope.ids.has(id)) {
|
|
229
|
+
scope.ids.add(id);
|
|
230
|
+
this.own.get(id).uses++;
|
|
231
|
+
}
|
|
232
|
+
return id;
|
|
233
|
+
}
|
|
234
|
+
proxy(id) {
|
|
235
|
+
let proxy = this.proxies.get(id);
|
|
236
|
+
if (!proxy) {
|
|
237
|
+
proxy = (...args) => this.channel.request('fn', { id, args: this.encodeArgs(args, undefined) }).then(value => this.decode(value));
|
|
238
|
+
this.proxies.set(id, proxy);
|
|
239
|
+
}
|
|
240
|
+
return proxy;
|
|
241
|
+
}
|
|
242
|
+
/** What a structured clone carries as it is. */
|
|
243
|
+
static cloned(value) {
|
|
244
|
+
return (value instanceof Date ||
|
|
245
|
+
value instanceof RegExp ||
|
|
246
|
+
value instanceof ArrayBuffer ||
|
|
247
|
+
ArrayBuffer.isView(value) ||
|
|
248
|
+
(typeof Blob !== 'undefined' && value instanceof Blob));
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Root } from 'react-dom/client';
|
|
2
|
+
interface Watched {
|
|
3
|
+
key: string;
|
|
4
|
+
hook: (...args: unknown[]) => unknown;
|
|
5
|
+
args: unknown[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The hooks of the page a sandbox uses (docs/design/ta-extension-access.md 3.2), run in a root of their own, apart from
|
|
9
|
+
* any view: each watched by a key, its value told whenever it renders. Rendered at once (flushSync), so that a value is
|
|
10
|
+
* known as soon as it is watched.
|
|
11
|
+
*/
|
|
12
|
+
export declare class HookHost {
|
|
13
|
+
protected readonly heard: (key: string, value: unknown) => void;
|
|
14
|
+
protected readonly root: Root;
|
|
15
|
+
protected readonly watched: Map<string, Watched>;
|
|
16
|
+
constructor(heard: (key: string, value: unknown) => void);
|
|
17
|
+
watch(key: string, hook: (...args: unknown[]) => unknown, args: unknown[]): void;
|
|
18
|
+
args(key: string, args: unknown[]): void;
|
|
19
|
+
unwatch(key: string): void;
|
|
20
|
+
dispose(): void;
|
|
21
|
+
protected render(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
class Guard extends React.Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.state = { failed: false };
|
|
8
|
+
}
|
|
9
|
+
static getDerivedStateFromError() {
|
|
10
|
+
return { failed: true };
|
|
11
|
+
}
|
|
12
|
+
componentDidCatch(error) {
|
|
13
|
+
console.error(`A hook of a sandbox failed (${this.props.name}):`, error);
|
|
14
|
+
}
|
|
15
|
+
render() {
|
|
16
|
+
return this.state.failed ? null : this.props.children;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function Watch({ watched, heard }) {
|
|
20
|
+
const value = watched.hook(...watched.args);
|
|
21
|
+
React.useLayoutEffect(() => heard(watched.key, value));
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The hooks of the page a sandbox uses (docs/design/ta-extension-access.md 3.2), run in a root of their own, apart from
|
|
26
|
+
* any view: each watched by a key, its value told whenever it renders. Rendered at once (flushSync), so that a value is
|
|
27
|
+
* known as soon as it is watched.
|
|
28
|
+
*/
|
|
29
|
+
export class HookHost {
|
|
30
|
+
constructor(heard) {
|
|
31
|
+
this.heard = heard;
|
|
32
|
+
this.watched = new Map();
|
|
33
|
+
this.root = createRoot(document.createElement('div'));
|
|
34
|
+
}
|
|
35
|
+
watch(key, hook, args) {
|
|
36
|
+
this.watched.set(key, { key, hook, args });
|
|
37
|
+
this.render();
|
|
38
|
+
}
|
|
39
|
+
args(key, args) {
|
|
40
|
+
const found = this.watched.get(key);
|
|
41
|
+
if (found) {
|
|
42
|
+
this.watched.set(key, { ...found, args });
|
|
43
|
+
this.render();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
unwatch(key) {
|
|
47
|
+
if (this.watched.delete(key)) {
|
|
48
|
+
this.render();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
dispose() {
|
|
52
|
+
this.watched.clear();
|
|
53
|
+
this.root.unmount();
|
|
54
|
+
}
|
|
55
|
+
render() {
|
|
56
|
+
const heard = this.heard;
|
|
57
|
+
flushSync(() => this.root.render([...this.watched.values()].map(watched => (React.createElement(Guard, { key: watched.key, name: watched.key },
|
|
58
|
+
React.createElement(Watch, { watched: watched, heard: heard }))))));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=hook-host.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { TaExtensionAccess } from '@celljs/ta-protocol';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import type { WebExtensionAPI } from '../extension/web-extension-api.js';
|
|
4
|
+
import { Channel } from './channel/channel.js';
|
|
5
|
+
import { Codec, type CodecScope } from './channel/codec.js';
|
|
6
|
+
import { HookHost } from './hook-host.js';
|
|
7
|
+
import { RemoteCopy } from './remote/remote-copy.js';
|
|
8
|
+
import type { RemoteEvent } from './remote/remote-protocol.js';
|
|
9
|
+
import { SandboxFrame } from './sandbox-frame.js';
|
|
10
|
+
import { type SandboxOptions } from './sandbox-protocol.js';
|
|
11
|
+
/** What the copy of a root tells the view that draws it. */
|
|
12
|
+
export interface RemoteRootEvents {
|
|
13
|
+
part(element: HTMLElement): void;
|
|
14
|
+
partGone(element: HTMLElement): void;
|
|
15
|
+
failed(message: string): void;
|
|
16
|
+
}
|
|
17
|
+
/** What an isolated host is given besides the API: the code, the options of the device, and how the page changes. */
|
|
18
|
+
export interface IsolatedHostSource {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly access: TaExtensionAccess;
|
|
22
|
+
readonly options: SandboxOptions;
|
|
23
|
+
/** Something the values of the API read may have changed (the settings): they are read again. */
|
|
24
|
+
changes(listener: () => void): () => void;
|
|
25
|
+
}
|
|
26
|
+
/** The parts of Ta in the copies: their props as the sandbox sent them, by the id the sandbox gave each. */
|
|
27
|
+
declare class PartBoard {
|
|
28
|
+
protected readonly kept: Map<string, Record<string, unknown>>;
|
|
29
|
+
protected readonly listeners: Set<() => void>;
|
|
30
|
+
protected readonly keys: WeakMap<HTMLElement, number>;
|
|
31
|
+
protected nextKey: number;
|
|
32
|
+
protected current: number;
|
|
33
|
+
readonly subscribe: (listener: () => void) => () => undefined;
|
|
34
|
+
readonly version: () => number;
|
|
35
|
+
props(id: string): Record<string, unknown> | undefined;
|
|
36
|
+
set(id: string, props: Record<string, unknown> | undefined): void;
|
|
37
|
+
/** The slots of a part (`<ta-slot n>`), by the name of their prop. */
|
|
38
|
+
slots(element: HTMLElement): [string, HTMLElement][];
|
|
39
|
+
keyOf(element: HTMLElement): number;
|
|
40
|
+
changed(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The page's side of an extension in a sandbox (docs/design/ta-extension-access.md 3.3): what it asks answered by the
|
|
44
|
+
* API, cut to its access, by the entries of WEB_API_SPEC and the checks of SANDBOX_GUARDS; the hooks it uses run here
|
|
45
|
+
* (HookHost) and their values sent; what it draws copied into the page (RemoteRoot, RemoteCopy). One for the extension,
|
|
46
|
+
* however many places show it. It knows no member of the API by name.
|
|
47
|
+
*/
|
|
48
|
+
export declare class IsolatedHost {
|
|
49
|
+
protected readonly pi: WebExtensionAPI;
|
|
50
|
+
protected readonly source: IsolatedHostSource;
|
|
51
|
+
readonly className: string;
|
|
52
|
+
readonly parts: PartBoard;
|
|
53
|
+
protected readonly frame: SandboxFrame;
|
|
54
|
+
protected channel?: Channel;
|
|
55
|
+
protected codec?: Codec;
|
|
56
|
+
protected hooks?: HookHost;
|
|
57
|
+
protected readonly hookScopes: Map<string, CodecScope>;
|
|
58
|
+
protected readonly holds: Map<number, () => void>;
|
|
59
|
+
protected nextHold: number;
|
|
60
|
+
protected readonly copies: Map<number, {
|
|
61
|
+
copy: RemoteCopy;
|
|
62
|
+
events: RemoteRootEvents;
|
|
63
|
+
scope: CodecScope;
|
|
64
|
+
}>;
|
|
65
|
+
protected nextRoot: number;
|
|
66
|
+
protected readonly components: Map<number, React.ComponentType<Record<string, unknown>>>;
|
|
67
|
+
protected values: Record<string, unknown>;
|
|
68
|
+
protected readonly style: HTMLStyleElement;
|
|
69
|
+
protected readonly stops: (() => void)[];
|
|
70
|
+
protected absent: Set<string>;
|
|
71
|
+
protected stopped: boolean;
|
|
72
|
+
constructor(pi: WebExtensionAPI, source: IsolatedHostSource);
|
|
73
|
+
/** Starts the sandbox; resolves once the extension ran and registered what it has. */
|
|
74
|
+
start(): Promise<void>;
|
|
75
|
+
stop(): void;
|
|
76
|
+
/** Copies a component of the sandbox into `element`; its root, to unmount it with. */
|
|
77
|
+
mount(element: HTMLElement, component: number, props: Record<string, unknown>, events: RemoteRootEvents): number;
|
|
78
|
+
props(root: number, props: Record<string, unknown>): void;
|
|
79
|
+
unmount(root: number): void;
|
|
80
|
+
/** The component of Ta of a path (`ui.Markdown`, `ui.icons.Star`) as far as the extension's access reaches. */
|
|
81
|
+
partComponent(path: string): unknown;
|
|
82
|
+
protected component(id: number): React.ComponentType<Record<string, unknown>>;
|
|
83
|
+
protected event(event: RemoteEvent): void;
|
|
84
|
+
protected reaches(path: string): boolean;
|
|
85
|
+
/** A member of the API cut to the extension's access, by its path: what reading it throws, it throws. */
|
|
86
|
+
protected member(path: string): {
|
|
87
|
+
value: unknown;
|
|
88
|
+
call: (...args: unknown[]) => unknown;
|
|
89
|
+
};
|
|
90
|
+
protected decodeArgs(args: unknown, _scope?: CodecScope): unknown[];
|
|
91
|
+
protected answer({ path, args }: {
|
|
92
|
+
path: string;
|
|
93
|
+
args: unknown[];
|
|
94
|
+
}, _signal?: AbortSignal): Promise<unknown>;
|
|
95
|
+
/** What an address of the page holds, for a sandbox, which cannot load it. */
|
|
96
|
+
static held(url: string): Promise<Blob>;
|
|
97
|
+
protected release(id: number): void;
|
|
98
|
+
protected watchHook(key: string, path: string, args: unknown): void;
|
|
99
|
+
protected heardHook(key: string, value: unknown): void;
|
|
100
|
+
/** The values and the methods of no arguments, read now (`value`, `read`). */
|
|
101
|
+
protected read(): Record<string, unknown>;
|
|
102
|
+
protected sendValues(reread?: boolean): void;
|
|
103
|
+
protected encoded(values: Record<string, unknown>): Record<string, unknown>;
|
|
104
|
+
}
|
|
105
|
+
export {};
|