@blastlauncher/runtime 3.0.0-alpha.9 → 3.0.0-canary.20261126024732.gb7befd6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +3 -0
- package/dist/main.js +5 -0
- package/dist/reconciler/index.d.ts +3 -2
- package/dist/reconciler/index.js +410 -27
- package/dist/reconciler/serialize.js +65 -25
- package/dist/reconciler/types.d.ts +5 -2
- package/package.json +2 -2
package/dist/core.js
CHANGED
|
@@ -51,9 +51,11 @@ export function startRuntime(options) {
|
|
|
51
51
|
};
|
|
52
52
|
const root = createSceneRoot({
|
|
53
53
|
publish: (scene) => send({ type: "scene", ...scene }),
|
|
54
|
+
publishPatch: (patch) => send({ type: "scene.patch", ...patch }),
|
|
54
55
|
onWarning: (message) => log("warn", [message]),
|
|
55
56
|
onError: fatal,
|
|
56
57
|
});
|
|
58
|
+
root.setPatchMode(false);
|
|
57
59
|
setCapabilityRequester((name, params, requestOptions = {}) => {
|
|
58
60
|
if (requestOptions.signal?.aborted)
|
|
59
61
|
return Promise.reject(new DOMException("The operation was aborted", "AbortError"));
|
|
@@ -181,6 +183,7 @@ export function startRuntime(options) {
|
|
|
181
183
|
if (message.type !== "init" || message.protocol !== PROTOCOL_VERSION)
|
|
182
184
|
return fatal(`Expected init with protocol ${PROTOCOL_VERSION}`, "PROTOCOL_ERROR");
|
|
183
185
|
initialized = true;
|
|
186
|
+
root.setPatchMode(message.scenePatches === true);
|
|
184
187
|
send({ type: "ready", protocol: PROTOCOL_VERSION });
|
|
185
188
|
providerLoad = load(message);
|
|
186
189
|
void providerLoad.catch(fatal);
|
package/dist/main.js
CHANGED
|
@@ -87,6 +87,11 @@ const runtime = startRuntime({
|
|
|
87
87
|
log,
|
|
88
88
|
loadCommand: (command) => import(__rewriteRelativeImportExtension(pathToFileURL(command.entry).href)),
|
|
89
89
|
});
|
|
90
|
+
// Standby workers spawned by the host pass `--prewarm` so the `@raycast/api`
|
|
91
|
+
// shim finishes loading while idle before `init` arrives.
|
|
92
|
+
if (process.argv.includes("--prewarm")) {
|
|
93
|
+
void import("@blastlauncher/runtime/api").catch((error) => runtime.fatal(error));
|
|
94
|
+
}
|
|
90
95
|
process.on("uncaughtException", (error) => runtime.fatal(error));
|
|
91
96
|
process.on("unhandledRejection", (error) => runtime.fatal(error));
|
|
92
97
|
process.stdin.on("error", (error) => runtime.fatal(error));
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { SceneRootOptions } from "./types.js";
|
|
3
|
-
export type { JsonValue, SceneNode, SceneRootOptions, SceneSnapshot } from "./types.js";
|
|
4
|
-
export declare function createSceneRoot({ publish, onWarning, onError }: SceneRootOptions): {
|
|
3
|
+
export type { JsonValue, SceneNode, ScenePatch, ScenePatchOp, SceneRootOptions, SceneSnapshot, } from "./types.js";
|
|
4
|
+
export declare function createSceneRoot({ publish, publishPatch, onWarning, onError, }: SceneRootOptions): {
|
|
5
5
|
render: (element: ReactNode) => void;
|
|
6
6
|
unmount(): void;
|
|
7
7
|
dispatch(nodeId: string, handler: string, args: unknown[]): unknown;
|
|
8
|
+
setPatchMode(enabled: boolean): void;
|
|
8
9
|
flush: () => void;
|
|
9
10
|
};
|
package/dist/reconciler/index.js
CHANGED
|
@@ -2,18 +2,107 @@ import { createContext } from "react";
|
|
|
2
2
|
import Reconciler from "react-reconciler";
|
|
3
3
|
import { ConcurrentRoot, DiscreteEventPriority, NoEventPriority, } from "react-reconciler/constants.js";
|
|
4
4
|
import { serializeProps } from "./serialize.js";
|
|
5
|
+
function shallowRawPropsEqual(a, b) {
|
|
6
|
+
if (a === b)
|
|
7
|
+
return true;
|
|
8
|
+
let countA = 0;
|
|
9
|
+
for (const key in a) {
|
|
10
|
+
if (!Object.hasOwn(a, key) || key === "children" || key === "key")
|
|
11
|
+
continue;
|
|
12
|
+
countA++;
|
|
13
|
+
if (!Object.hasOwn(b, key) || !Object.is(a[key], b[key]))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
let countB = 0;
|
|
17
|
+
for (const key in b) {
|
|
18
|
+
if (!Object.hasOwn(b, key) || key === "children" || key === "key")
|
|
19
|
+
continue;
|
|
20
|
+
countB++;
|
|
21
|
+
}
|
|
22
|
+
return countA === countB;
|
|
23
|
+
}
|
|
24
|
+
function jsonEqual(a, b) {
|
|
25
|
+
if (Object.is(a, b))
|
|
26
|
+
return true;
|
|
27
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object")
|
|
28
|
+
return false;
|
|
29
|
+
if (Array.isArray(a)) {
|
|
30
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
31
|
+
return false;
|
|
32
|
+
for (let i = 0; i < a.length; i++)
|
|
33
|
+
if (!jsonEqual(a[i], b[i]))
|
|
34
|
+
return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(b))
|
|
38
|
+
return false;
|
|
39
|
+
const ao = a;
|
|
40
|
+
const bo = b;
|
|
41
|
+
let countA = 0;
|
|
42
|
+
for (const key in ao) {
|
|
43
|
+
if (!Object.hasOwn(ao, key))
|
|
44
|
+
continue;
|
|
45
|
+
countA++;
|
|
46
|
+
if (!Object.hasOwn(bo, key) || !jsonEqual(ao[key], bo[key]))
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
let countB = 0;
|
|
50
|
+
for (const key in bo) {
|
|
51
|
+
if (!Object.hasOwn(bo, key))
|
|
52
|
+
continue;
|
|
53
|
+
countB++;
|
|
54
|
+
}
|
|
55
|
+
return countA === countB;
|
|
56
|
+
}
|
|
57
|
+
function markUp(node) {
|
|
58
|
+
let current = node;
|
|
59
|
+
while (current !== null && !current.subtreeDirty) {
|
|
60
|
+
current.subtreeDirty = true;
|
|
61
|
+
current = current.parent;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
5
64
|
function remove(parent, child) {
|
|
6
65
|
const index = parent.children.indexOf(child);
|
|
7
|
-
if (index !== -1)
|
|
66
|
+
if (index !== -1) {
|
|
8
67
|
parent.children.splice(index, 1);
|
|
68
|
+
if (child.parent === parent)
|
|
69
|
+
child.parent = null;
|
|
70
|
+
parent.childrenDirty = true;
|
|
71
|
+
markUp(parent);
|
|
72
|
+
}
|
|
9
73
|
}
|
|
10
74
|
function insert(parent, child, before) {
|
|
11
|
-
|
|
75
|
+
if (child.parent && child.parent !== parent)
|
|
76
|
+
remove(child.parent, child);
|
|
77
|
+
else {
|
|
78
|
+
const existing = parent.children.indexOf(child);
|
|
79
|
+
if (existing !== -1)
|
|
80
|
+
parent.children.splice(existing, 1);
|
|
81
|
+
}
|
|
12
82
|
const index = before ? parent.children.indexOf(before) : -1;
|
|
13
83
|
parent.children.splice(index === -1 ? parent.children.length : index, 0, child);
|
|
84
|
+
child.parent = parent;
|
|
85
|
+
parent.childrenDirty = true;
|
|
86
|
+
markUp(parent);
|
|
14
87
|
}
|
|
15
88
|
function instance(container, type, props) {
|
|
16
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
id: String(container.nextId++),
|
|
91
|
+
type,
|
|
92
|
+
props,
|
|
93
|
+
children: [],
|
|
94
|
+
hidden: false,
|
|
95
|
+
parent: null,
|
|
96
|
+
propsDirty: true,
|
|
97
|
+
childrenDirty: true,
|
|
98
|
+
subtreeDirty: true,
|
|
99
|
+
published: false,
|
|
100
|
+
publishedCovered: false,
|
|
101
|
+
publishedChildren: [],
|
|
102
|
+
lastCommitRev: 0,
|
|
103
|
+
cachedNode: undefined,
|
|
104
|
+
ownHandlers: undefined,
|
|
105
|
+
};
|
|
17
106
|
}
|
|
18
107
|
const noop = () => { };
|
|
19
108
|
let priority = NoEventPriority;
|
|
@@ -42,26 +131,62 @@ const config = {
|
|
|
42
131
|
shouldSetTextContent: () => false,
|
|
43
132
|
prepareForCommit: () => null,
|
|
44
133
|
resetAfterCommit: (container) => container.commit(),
|
|
45
|
-
commitUpdate: (node, _type,
|
|
134
|
+
commitUpdate: (node, _type, oldProps, props) => {
|
|
46
135
|
node.props = props;
|
|
136
|
+
if (!shallowRawPropsEqual(oldProps, props)) {
|
|
137
|
+
node.propsDirty = true;
|
|
138
|
+
markUp(node);
|
|
139
|
+
}
|
|
47
140
|
},
|
|
48
|
-
commitTextUpdate: (node,
|
|
141
|
+
commitTextUpdate: (node, oldText, text) => {
|
|
49
142
|
node.props = { text };
|
|
143
|
+
if (oldText !== text) {
|
|
144
|
+
node.propsDirty = true;
|
|
145
|
+
markUp(node);
|
|
146
|
+
}
|
|
50
147
|
},
|
|
51
148
|
clearContainer: (container) => {
|
|
149
|
+
for (const child of container.children)
|
|
150
|
+
child.parent = null;
|
|
52
151
|
container.children = [];
|
|
152
|
+
container.childrenDirty = true;
|
|
153
|
+
container.subtreeDirty = true;
|
|
53
154
|
},
|
|
54
155
|
hideInstance: (node) => {
|
|
55
|
-
node.hidden
|
|
156
|
+
if (!node.hidden) {
|
|
157
|
+
node.hidden = true;
|
|
158
|
+
if (node.parent) {
|
|
159
|
+
node.parent.childrenDirty = true;
|
|
160
|
+
markUp(node.parent);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
56
163
|
},
|
|
57
164
|
hideTextInstance: (node) => {
|
|
58
|
-
node.hidden
|
|
165
|
+
if (!node.hidden) {
|
|
166
|
+
node.hidden = true;
|
|
167
|
+
if (node.parent) {
|
|
168
|
+
node.parent.childrenDirty = true;
|
|
169
|
+
markUp(node.parent);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
59
172
|
},
|
|
60
173
|
unhideInstance: (node) => {
|
|
61
|
-
node.hidden
|
|
174
|
+
if (node.hidden) {
|
|
175
|
+
node.hidden = false;
|
|
176
|
+
if (node.parent) {
|
|
177
|
+
node.parent.childrenDirty = true;
|
|
178
|
+
markUp(node.parent);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
62
181
|
},
|
|
63
182
|
unhideTextInstance: (node) => {
|
|
64
|
-
node.hidden
|
|
183
|
+
if (node.hidden) {
|
|
184
|
+
node.hidden = false;
|
|
185
|
+
if (node.parent) {
|
|
186
|
+
node.parent.childrenDirty = true;
|
|
187
|
+
markUp(node.parent);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
65
190
|
},
|
|
66
191
|
scheduleTimeout: setTimeout,
|
|
67
192
|
cancelTimeout: clearTimeout,
|
|
@@ -100,9 +225,13 @@ const config = {
|
|
|
100
225
|
getSuspendedCommitReason: () => null,
|
|
101
226
|
};
|
|
102
227
|
const renderer = Reconciler(config);
|
|
103
|
-
export function createSceneRoot({ publish, onWarning = noop, onError }) {
|
|
228
|
+
export function createSceneRoot({ publish, publishPatch, onWarning = noop, onError, }) {
|
|
104
229
|
let revision = 0;
|
|
105
|
-
let
|
|
230
|
+
let patchMode = publishPatch !== undefined;
|
|
231
|
+
let lastPublishedKind = "none";
|
|
232
|
+
let lastPublishedRootId = null;
|
|
233
|
+
let lastTopChildren = [];
|
|
234
|
+
const handlers = new Map();
|
|
106
235
|
const errors = [];
|
|
107
236
|
// Errors raised while serializing or publishing a commit. Throwing inside
|
|
108
237
|
// React's commit phase corrupts the reconciler for every later root in the
|
|
@@ -113,8 +242,11 @@ export function createSceneRoot({ publish, onWarning = noop, onError }) {
|
|
|
113
242
|
reportError(error);
|
|
114
243
|
}
|
|
115
244
|
const container = {
|
|
245
|
+
parent: null,
|
|
116
246
|
children: [],
|
|
117
247
|
nextId: 1,
|
|
248
|
+
childrenDirty: true,
|
|
249
|
+
subtreeDirty: true,
|
|
118
250
|
commit() {
|
|
119
251
|
try {
|
|
120
252
|
commitSnapshot();
|
|
@@ -126,27 +258,275 @@ export function createSceneRoot({ publish, onWarning = noop, onError }) {
|
|
|
126
258
|
}
|
|
127
259
|
},
|
|
128
260
|
};
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
261
|
+
function isCovered(node) {
|
|
262
|
+
return node.type === "Navigation.Entry" && node.props.active === false;
|
|
263
|
+
}
|
|
264
|
+
function unpublishSubtree(node, activeRev) {
|
|
265
|
+
if (!node.published || node.lastCommitRev === activeRev)
|
|
266
|
+
return;
|
|
267
|
+
node.published = false;
|
|
268
|
+
handlers.delete(node.id);
|
|
269
|
+
const prev = node.publishedChildren;
|
|
270
|
+
node.publishedChildren = [];
|
|
271
|
+
for (let i = 0; i < prev.length; i++)
|
|
272
|
+
unpublishSubtree(prev[i], activeRev);
|
|
273
|
+
}
|
|
274
|
+
/** Serializes a subtree (reusing clean cached subtrees) and registers its handlers. */
|
|
275
|
+
function serializeSubtree(node, activeRev, removed) {
|
|
276
|
+
node.lastCommitRev = activeRev;
|
|
277
|
+
const covered = isCovered(node);
|
|
278
|
+
const needsProps = node.propsDirty || !node.cachedNode;
|
|
279
|
+
const needsChildren = node.childrenDirty ||
|
|
280
|
+
node.subtreeDirty ||
|
|
281
|
+
!node.cachedNode ||
|
|
282
|
+
!node.published ||
|
|
283
|
+
covered !== node.publishedCovered;
|
|
284
|
+
let props;
|
|
285
|
+
if (needsProps) {
|
|
132
286
|
const callbacks = new Map();
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
287
|
+
props = serializeProps(node.type, node.props, callbacks, onWarning);
|
|
288
|
+
node.ownHandlers = callbacks;
|
|
289
|
+
handlers.set(node.id, callbacks);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
props = node.cachedNode.props;
|
|
293
|
+
if (!node.published && node.ownHandlers)
|
|
294
|
+
handlers.set(node.id, node.ownHandlers);
|
|
295
|
+
}
|
|
296
|
+
let children;
|
|
297
|
+
if (covered) {
|
|
298
|
+
if (node.publishedChildren.length > 0) {
|
|
299
|
+
for (let i = 0; i < node.publishedChildren.length; i++) {
|
|
300
|
+
removed.push(node.publishedChildren[i]);
|
|
301
|
+
}
|
|
302
|
+
node.publishedChildren = [];
|
|
303
|
+
}
|
|
304
|
+
children = [];
|
|
305
|
+
}
|
|
306
|
+
else if (!needsChildren && node.cachedNode) {
|
|
307
|
+
children = node.cachedNode.children;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
const prevChildren = node.publishedChildren;
|
|
311
|
+
const nextInstances = [];
|
|
312
|
+
children = [];
|
|
313
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
314
|
+
const child = node.children[i];
|
|
315
|
+
if (child.hidden)
|
|
316
|
+
continue;
|
|
317
|
+
nextInstances.push(child);
|
|
318
|
+
children.push(serializeSubtree(child, activeRev, removed));
|
|
319
|
+
}
|
|
320
|
+
for (let i = 0; i < prevChildren.length; i++) {
|
|
321
|
+
const prevChild = prevChildren[i];
|
|
322
|
+
if (prevChild.lastCommitRev !== activeRev)
|
|
323
|
+
removed.push(prevChild);
|
|
324
|
+
}
|
|
325
|
+
node.publishedChildren = nextInstances;
|
|
326
|
+
}
|
|
327
|
+
node.propsDirty = false;
|
|
328
|
+
node.childrenDirty = false;
|
|
329
|
+
node.subtreeDirty = false;
|
|
330
|
+
node.published = true;
|
|
331
|
+
node.publishedCovered = covered;
|
|
332
|
+
const nextNode = !needsProps && !needsChildren && node.cachedNode
|
|
333
|
+
? node.cachedNode
|
|
334
|
+
: { id: node.id, type: node.type, props, children };
|
|
335
|
+
node.cachedNode = nextNode;
|
|
336
|
+
return nextNode;
|
|
337
|
+
}
|
|
338
|
+
/** Collects minimal patch ops against the last published tree in O(dirty nodes). */
|
|
339
|
+
function collectPatch(node, activeRev, ops, removed) {
|
|
340
|
+
node.lastCommitRev = activeRev;
|
|
341
|
+
if (!node.subtreeDirty)
|
|
342
|
+
return;
|
|
343
|
+
const covered = isCovered(node);
|
|
344
|
+
const coveredChanged = covered !== node.publishedCovered;
|
|
345
|
+
let nextProps = node.cachedNode.props;
|
|
346
|
+
let propsChanged = false;
|
|
347
|
+
if (node.propsDirty) {
|
|
348
|
+
const callbacks = new Map();
|
|
349
|
+
const serialized = serializeProps(node.type, node.props, callbacks, onWarning);
|
|
350
|
+
node.ownHandlers = callbacks;
|
|
351
|
+
handlers.set(node.id, callbacks);
|
|
352
|
+
if (!jsonEqual(nextProps, serialized)) {
|
|
353
|
+
nextProps = serialized;
|
|
354
|
+
propsChanged = true;
|
|
355
|
+
ops.push({ op: "props", id: node.id, props: nextProps });
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
let childrenChanged = false;
|
|
359
|
+
let nextChildrenNodes = node.cachedNode.children;
|
|
360
|
+
if (covered) {
|
|
361
|
+
if (node.publishedChildren.length > 0 || coveredChanged) {
|
|
362
|
+
for (let i = 0; i < node.publishedChildren.length; i++) {
|
|
363
|
+
removed.push(node.publishedChildren[i]);
|
|
364
|
+
}
|
|
365
|
+
node.publishedChildren = [];
|
|
366
|
+
nextChildrenNodes = [];
|
|
367
|
+
childrenChanged = true;
|
|
368
|
+
ops.push({ op: "children", id: node.id, children: [] });
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else if (node.childrenDirty || coveredChanged) {
|
|
372
|
+
const prevChildren = node.publishedChildren;
|
|
373
|
+
const nextInstances = [];
|
|
374
|
+
const patchChildren = [];
|
|
375
|
+
nextChildrenNodes = [];
|
|
376
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
377
|
+
const child = node.children[i];
|
|
378
|
+
if (child.hidden)
|
|
379
|
+
continue;
|
|
380
|
+
nextInstances.push(child);
|
|
381
|
+
if (child.published) {
|
|
382
|
+
child.lastCommitRev = activeRev;
|
|
383
|
+
patchChildren.push(child.id);
|
|
384
|
+
if (child.subtreeDirty)
|
|
385
|
+
collectPatch(child, activeRev, ops, removed);
|
|
386
|
+
nextChildrenNodes.push(child.cachedNode);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
const serialized = serializeSubtree(child, activeRev, removed);
|
|
390
|
+
patchChildren.push(serialized);
|
|
391
|
+
nextChildrenNodes.push(serialized);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
for (let i = 0; i < prevChildren.length; i++) {
|
|
395
|
+
const prevChild = prevChildren[i];
|
|
396
|
+
if (prevChild.lastCommitRev !== activeRev)
|
|
397
|
+
removed.push(prevChild);
|
|
398
|
+
}
|
|
399
|
+
node.publishedChildren = nextInstances;
|
|
400
|
+
childrenChanged = true;
|
|
401
|
+
ops.push({ op: "children", id: node.id, children: patchChildren });
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
// Children list unchanged; recurse only into dirty existing children.
|
|
405
|
+
const kids = node.publishedChildren;
|
|
406
|
+
const prevNodes = node.cachedNode.children;
|
|
407
|
+
let anyChildChanged = false;
|
|
408
|
+
for (let i = 0; i < kids.length; i++) {
|
|
409
|
+
const child = kids[i];
|
|
410
|
+
if (child.subtreeDirty) {
|
|
411
|
+
collectPatch(child, activeRev, ops, removed);
|
|
412
|
+
if (child.cachedNode !== prevNodes[i])
|
|
413
|
+
anyChildChanged = true;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (anyChildChanged) {
|
|
417
|
+
childrenChanged = true;
|
|
418
|
+
nextChildrenNodes = [];
|
|
419
|
+
for (let i = 0; i < kids.length; i++) {
|
|
420
|
+
nextChildrenNodes.push(kids[i].cachedNode);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
node.propsDirty = false;
|
|
425
|
+
node.childrenDirty = false;
|
|
426
|
+
node.subtreeDirty = false;
|
|
427
|
+
node.published = true;
|
|
428
|
+
node.publishedCovered = covered;
|
|
429
|
+
if (propsChanged || childrenChanged) {
|
|
430
|
+
node.cachedNode = {
|
|
136
431
|
id: node.id,
|
|
137
432
|
type: node.type,
|
|
138
|
-
props,
|
|
139
|
-
|
|
140
|
-
children: node.type === "Navigation.Entry" && node.props.active === false
|
|
141
|
-
? []
|
|
142
|
-
: node.children.filter((child) => !child.hidden).map(snapshot),
|
|
433
|
+
props: nextProps,
|
|
434
|
+
children: nextChildrenNodes,
|
|
143
435
|
};
|
|
144
436
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
437
|
+
}
|
|
438
|
+
function commitSnapshot() {
|
|
439
|
+
const activeRev = revision + 1;
|
|
440
|
+
const removed = [];
|
|
441
|
+
const visibleTop = [];
|
|
442
|
+
for (let i = 0; i < container.children.length; i++) {
|
|
443
|
+
const child = container.children[i];
|
|
444
|
+
if (!child.hidden)
|
|
445
|
+
visibleTop.push(child);
|
|
446
|
+
}
|
|
447
|
+
const nextKind = visibleTop.length === 0 ? "null" : visibleTop.length === 1 ? "single" : "synthetic";
|
|
448
|
+
const nextRootId = nextKind === "null" ? null : nextKind === "single" ? visibleTop[0].id : "0";
|
|
449
|
+
const canPatch = patchMode &&
|
|
450
|
+
publishPatch !== undefined &&
|
|
451
|
+
lastPublishedKind !== "none" &&
|
|
452
|
+
nextKind === lastPublishedKind &&
|
|
453
|
+
nextRootId === lastPublishedRootId &&
|
|
454
|
+
nextKind !== "null";
|
|
455
|
+
if (canPatch) {
|
|
456
|
+
const baseRevision = revision;
|
|
457
|
+
const ops = [];
|
|
458
|
+
if (nextKind === "single") {
|
|
459
|
+
collectPatch(visibleTop[0], activeRev, ops, removed);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
// Synthetic `#root` ("0") with multiple top-level children.
|
|
463
|
+
if (container.childrenDirty) {
|
|
464
|
+
const patchChildren = [];
|
|
465
|
+
for (let i = 0; i < visibleTop.length; i++) {
|
|
466
|
+
const child = visibleTop[i];
|
|
467
|
+
if (child.published) {
|
|
468
|
+
child.lastCommitRev = activeRev;
|
|
469
|
+
patchChildren.push(child.id);
|
|
470
|
+
if (child.subtreeDirty)
|
|
471
|
+
collectPatch(child, activeRev, ops, removed);
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
patchChildren.push(serializeSubtree(child, activeRev, removed));
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
for (let i = 0; i < lastTopChildren.length; i++) {
|
|
478
|
+
const prevTop = lastTopChildren[i];
|
|
479
|
+
if (prevTop.lastCommitRev !== activeRev)
|
|
480
|
+
removed.push(prevTop);
|
|
481
|
+
}
|
|
482
|
+
lastTopChildren = visibleTop;
|
|
483
|
+
ops.push({ op: "children", id: "0", children: patchChildren });
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
for (let i = 0; i < visibleTop.length; i++) {
|
|
487
|
+
const child = visibleTop[i];
|
|
488
|
+
if (child.subtreeDirty)
|
|
489
|
+
collectPatch(child, activeRev, ops, removed);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
for (let i = 0; i < removed.length; i++)
|
|
494
|
+
unpublishSubtree(removed[i], activeRev);
|
|
495
|
+
container.childrenDirty = false;
|
|
496
|
+
container.subtreeDirty = false;
|
|
497
|
+
revision = activeRev;
|
|
498
|
+
publishPatch({ revision, baseRevision, ops });
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
// Full snapshot path (initial commit, root shape/id change, or unmount to null).
|
|
502
|
+
const serializedTop = [];
|
|
503
|
+
for (let i = 0; i < visibleTop.length; i++) {
|
|
504
|
+
serializedTop.push(serializeSubtree(visibleTop[i], activeRev, removed));
|
|
505
|
+
}
|
|
506
|
+
for (let i = 0; i < lastTopChildren.length; i++) {
|
|
507
|
+
const prevTop = lastTopChildren[i];
|
|
508
|
+
if (prevTop.lastCommitRev !== activeRev)
|
|
509
|
+
removed.push(prevTop);
|
|
510
|
+
}
|
|
511
|
+
for (let i = 0; i < removed.length; i++)
|
|
512
|
+
unpublishSubtree(removed[i], activeRev);
|
|
513
|
+
lastTopChildren = visibleTop;
|
|
514
|
+
container.childrenDirty = false;
|
|
515
|
+
container.subtreeDirty = false;
|
|
516
|
+
const root = serializedTop.length > 1
|
|
517
|
+
? { id: "0", type: "#root", props: {}, children: serializedTop }
|
|
518
|
+
: (serializedTop[0] ?? null);
|
|
519
|
+
const prevKind = lastPublishedKind;
|
|
520
|
+
lastPublishedKind = nextKind;
|
|
521
|
+
lastPublishedRootId = nextRootId;
|
|
522
|
+
if (patchMode && publishPatch !== undefined && prevKind !== "none" && nextKind === "null") {
|
|
523
|
+
const baseRevision = revision;
|
|
524
|
+
revision = activeRev;
|
|
525
|
+
publishPatch({ revision, baseRevision, ops: [{ op: "root", root: null }] });
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
revision = activeRev;
|
|
529
|
+
publish({ revision, root });
|
|
150
530
|
}
|
|
151
531
|
function reportError(error) {
|
|
152
532
|
if (onError)
|
|
@@ -181,6 +561,9 @@ export function createSceneRoot({ publish, onWarning = noop, onError }) {
|
|
|
181
561
|
throw new Error(`Unknown handler ${handler} on scene node ${nodeId}`);
|
|
182
562
|
return callback(...args);
|
|
183
563
|
},
|
|
564
|
+
setPatchMode(enabled) {
|
|
565
|
+
patchMode = enabled && publishPatch !== undefined;
|
|
566
|
+
},
|
|
184
567
|
flush,
|
|
185
568
|
};
|
|
186
569
|
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { isValidElement } from "react";
|
|
2
2
|
import { UnsupportedApiError, unsupportedPath } from "../api/unsupported.js";
|
|
3
3
|
export function serializeProps(type, props, handlers, warn) {
|
|
4
|
-
|
|
4
|
+
let ancestors;
|
|
5
5
|
function visit(value, path) {
|
|
6
6
|
if (value === undefined)
|
|
7
7
|
return undefined;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (typeof value === "number" && Number.isFinite(value))
|
|
8
|
+
const kind = typeof value;
|
|
9
|
+
if (value === null || kind === "string" || kind === "boolean")
|
|
11
10
|
return value;
|
|
11
|
+
if (kind === "number") {
|
|
12
|
+
if (Number.isFinite(value))
|
|
13
|
+
return value;
|
|
14
|
+
warn(`Dropped non-serializable prop ${type}.${path}`);
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
12
17
|
// `List.Item.Accessory` carries `Date` labels (also nested in
|
|
13
18
|
// `{ value, color }` forms); clients get the ISO string instead.
|
|
14
19
|
if (value instanceof Date)
|
|
@@ -18,36 +23,71 @@ export function serializeProps(type, props, handlers, warn) {
|
|
|
18
23
|
const stubPath = unsupportedPath(value);
|
|
19
24
|
if (stubPath)
|
|
20
25
|
throw new UnsupportedApiError(stubPath);
|
|
21
|
-
if (
|
|
26
|
+
if (kind === "function") {
|
|
22
27
|
let name = path;
|
|
23
28
|
while (handlers.has(name))
|
|
24
29
|
name += ":handler";
|
|
25
30
|
handlers.set(name, value);
|
|
26
31
|
return { $handler: name };
|
|
27
32
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
if (kind === "object" && !isValidElement(value)) {
|
|
34
|
+
const obj = value;
|
|
35
|
+
const isArr = Array.isArray(obj);
|
|
36
|
+
const proto = isArr ? null : Object.getPrototypeOf(obj);
|
|
37
|
+
if (isArr || proto === Object.prototype || proto === null) {
|
|
38
|
+
if (ancestors?.has(obj)) {
|
|
39
|
+
warn(`Dropped non-serializable prop ${type}.${path}`);
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
ancestors ??= new Set();
|
|
43
|
+
ancestors.add(obj);
|
|
44
|
+
let result;
|
|
45
|
+
if (isArr) {
|
|
46
|
+
const arr = obj;
|
|
47
|
+
const out = [];
|
|
48
|
+
for (let index = 0; index < arr.length; index++) {
|
|
49
|
+
out.push(visit(arr[index], `${path}[${index}]`) ?? null);
|
|
50
|
+
}
|
|
51
|
+
result = out;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const record = obj;
|
|
55
|
+
const out = {};
|
|
56
|
+
for (const key in record) {
|
|
57
|
+
if (!Object.hasOwn(record, key))
|
|
58
|
+
continue;
|
|
59
|
+
const next = visit(record[key], `${path}.${key}`);
|
|
60
|
+
if (next !== undefined)
|
|
61
|
+
out[key] = next;
|
|
62
|
+
}
|
|
63
|
+
result = out;
|
|
64
|
+
}
|
|
65
|
+
ancestors.delete(obj);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
43
68
|
}
|
|
44
69
|
warn(`Dropped non-serializable prop ${type}.${path}`);
|
|
45
70
|
return undefined;
|
|
46
71
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const key in props) {
|
|
74
|
+
if (!Object.hasOwn(props, key) || key === "children" || key === "key")
|
|
75
|
+
continue;
|
|
76
|
+
const value = props[key];
|
|
77
|
+
if (value === undefined)
|
|
78
|
+
continue;
|
|
79
|
+
const kind = typeof value;
|
|
80
|
+
if (value === null || kind === "string" || kind === "boolean") {
|
|
81
|
+
out[key] = value;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (kind === "number" && Number.isFinite(value)) {
|
|
85
|
+
out[key] = value;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
50
88
|
const next = visit(value, key);
|
|
51
|
-
|
|
52
|
-
|
|
89
|
+
if (next !== undefined)
|
|
90
|
+
out[key] = next;
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
53
93
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { SceneMessage } from "@blastlauncher/protocol";
|
|
2
|
-
export type { JsonValue, SceneNode } from "@blastlauncher/protocol";
|
|
1
|
+
import type { SceneMessage, ScenePatchMessage } from "@blastlauncher/protocol";
|
|
2
|
+
export type { JsonValue, SceneNode, ScenePatchOp } from "@blastlauncher/protocol";
|
|
3
3
|
export type SceneSnapshot = Omit<SceneMessage, "type">;
|
|
4
|
+
export type ScenePatch = Omit<ScenePatchMessage, "type">;
|
|
4
5
|
export interface SceneRootOptions {
|
|
5
6
|
publish(snapshot: SceneSnapshot): void;
|
|
7
|
+
/** Optional incremental patch sink; called instead of `publish` when a patch is possible. */
|
|
8
|
+
publishPatch?(patch: ScenePatch): void;
|
|
6
9
|
onWarning?(message: string): void;
|
|
7
10
|
onError?(error: unknown): void;
|
|
8
11
|
}
|
package/package.json
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@blastlauncher/protocol": "3.0.0-
|
|
27
|
+
"@blastlauncher/protocol": "3.0.0-canary.20261126024732.gb7befd6",
|
|
28
28
|
"react": "19.3.1",
|
|
29
29
|
"react-reconciler": "0.34.0"
|
|
30
30
|
},
|
|
31
|
-
"version": "3.0.0-
|
|
31
|
+
"version": "3.0.0-canary.20261126024732.gb7befd6",
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|