@blastlauncher/runtime 3.0.0-alpha.1 → 3.0.0-alpha.10
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/api/ai-browser.d.ts +24 -4
- package/dist/api/diagnostics.js +14 -4
- package/dist/api/enums.generated.d.ts +12 -2
- package/dist/api/enums.generated.js +12 -2
- package/dist/api/index.d.ts +24 -4
- package/dist/api/navigation.js +1 -1
- package/dist/api/unsupported.generated.d.ts +12 -2
- package/dist/api/window.js +1 -1
- package/dist/browser.d.ts +19 -0
- package/dist/browser.js +32 -0
- package/dist/core.d.ts +18 -0
- package/dist/core.js +261 -0
- package/dist/main.js +51 -287
- package/dist/reconciler/index.d.ts +2 -2
- package/dist/reconciler/index.js +405 -27
- package/dist/reconciler/serialize.js +65 -25
- package/dist/reconciler/types.d.ts +5 -2
- package/package.json +7 -2
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,12 @@ 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 lastPublishedKind = "none";
|
|
231
|
+
let lastPublishedRootId = null;
|
|
232
|
+
let lastTopChildren = [];
|
|
233
|
+
const handlers = new Map();
|
|
106
234
|
const errors = [];
|
|
107
235
|
// Errors raised while serializing or publishing a commit. Throwing inside
|
|
108
236
|
// React's commit phase corrupts the reconciler for every later root in the
|
|
@@ -113,8 +241,11 @@ export function createSceneRoot({ publish, onWarning = noop, onError }) {
|
|
|
113
241
|
reportError(error);
|
|
114
242
|
}
|
|
115
243
|
const container = {
|
|
244
|
+
parent: null,
|
|
116
245
|
children: [],
|
|
117
246
|
nextId: 1,
|
|
247
|
+
childrenDirty: true,
|
|
248
|
+
subtreeDirty: true,
|
|
118
249
|
commit() {
|
|
119
250
|
try {
|
|
120
251
|
commitSnapshot();
|
|
@@ -126,27 +257,274 @@ export function createSceneRoot({ publish, onWarning = noop, onError }) {
|
|
|
126
257
|
}
|
|
127
258
|
},
|
|
128
259
|
};
|
|
129
|
-
function
|
|
130
|
-
|
|
131
|
-
|
|
260
|
+
function isCovered(node) {
|
|
261
|
+
return node.type === "Navigation.Entry" && node.props.active === false;
|
|
262
|
+
}
|
|
263
|
+
function unpublishSubtree(node, activeRev) {
|
|
264
|
+
if (!node.published || node.lastCommitRev === activeRev)
|
|
265
|
+
return;
|
|
266
|
+
node.published = false;
|
|
267
|
+
handlers.delete(node.id);
|
|
268
|
+
const prev = node.publishedChildren;
|
|
269
|
+
node.publishedChildren = [];
|
|
270
|
+
for (let i = 0; i < prev.length; i++)
|
|
271
|
+
unpublishSubtree(prev[i], activeRev);
|
|
272
|
+
}
|
|
273
|
+
/** Serializes a subtree (reusing clean cached subtrees) and registers its handlers. */
|
|
274
|
+
function serializeSubtree(node, activeRev, removed) {
|
|
275
|
+
node.lastCommitRev = activeRev;
|
|
276
|
+
const covered = isCovered(node);
|
|
277
|
+
const needsProps = node.propsDirty || !node.cachedNode;
|
|
278
|
+
const needsChildren = node.childrenDirty ||
|
|
279
|
+
node.subtreeDirty ||
|
|
280
|
+
!node.cachedNode ||
|
|
281
|
+
!node.published ||
|
|
282
|
+
covered !== node.publishedCovered;
|
|
283
|
+
let props;
|
|
284
|
+
if (needsProps) {
|
|
285
|
+
const callbacks = new Map();
|
|
286
|
+
props = serializeProps(node.type, node.props, callbacks, onWarning);
|
|
287
|
+
node.ownHandlers = callbacks;
|
|
288
|
+
handlers.set(node.id, callbacks);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
props = node.cachedNode.props;
|
|
292
|
+
if (!node.published && node.ownHandlers)
|
|
293
|
+
handlers.set(node.id, node.ownHandlers);
|
|
294
|
+
}
|
|
295
|
+
let children;
|
|
296
|
+
if (covered) {
|
|
297
|
+
if (node.publishedChildren.length > 0) {
|
|
298
|
+
for (let i = 0; i < node.publishedChildren.length; i++) {
|
|
299
|
+
removed.push(node.publishedChildren[i]);
|
|
300
|
+
}
|
|
301
|
+
node.publishedChildren = [];
|
|
302
|
+
}
|
|
303
|
+
children = [];
|
|
304
|
+
}
|
|
305
|
+
else if (!needsChildren && node.cachedNode) {
|
|
306
|
+
children = node.cachedNode.children;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
const prevChildren = node.publishedChildren;
|
|
310
|
+
const nextInstances = [];
|
|
311
|
+
children = [];
|
|
312
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
313
|
+
const child = node.children[i];
|
|
314
|
+
if (child.hidden)
|
|
315
|
+
continue;
|
|
316
|
+
nextInstances.push(child);
|
|
317
|
+
children.push(serializeSubtree(child, activeRev, removed));
|
|
318
|
+
}
|
|
319
|
+
for (let i = 0; i < prevChildren.length; i++) {
|
|
320
|
+
const prevChild = prevChildren[i];
|
|
321
|
+
if (prevChild.lastCommitRev !== activeRev)
|
|
322
|
+
removed.push(prevChild);
|
|
323
|
+
}
|
|
324
|
+
node.publishedChildren = nextInstances;
|
|
325
|
+
}
|
|
326
|
+
node.propsDirty = false;
|
|
327
|
+
node.childrenDirty = false;
|
|
328
|
+
node.subtreeDirty = false;
|
|
329
|
+
node.published = true;
|
|
330
|
+
node.publishedCovered = covered;
|
|
331
|
+
const nextNode = !needsProps && !needsChildren && node.cachedNode
|
|
332
|
+
? node.cachedNode
|
|
333
|
+
: { id: node.id, type: node.type, props, children };
|
|
334
|
+
node.cachedNode = nextNode;
|
|
335
|
+
return nextNode;
|
|
336
|
+
}
|
|
337
|
+
/** Collects minimal patch ops against the last published tree in O(dirty nodes). */
|
|
338
|
+
function collectPatch(node, activeRev, ops, removed) {
|
|
339
|
+
node.lastCommitRev = activeRev;
|
|
340
|
+
if (!node.subtreeDirty)
|
|
341
|
+
return;
|
|
342
|
+
const covered = isCovered(node);
|
|
343
|
+
const coveredChanged = covered !== node.publishedCovered;
|
|
344
|
+
let nextProps = node.cachedNode.props;
|
|
345
|
+
let propsChanged = false;
|
|
346
|
+
if (node.propsDirty) {
|
|
132
347
|
const callbacks = new Map();
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
348
|
+
const serialized = serializeProps(node.type, node.props, callbacks, onWarning);
|
|
349
|
+
node.ownHandlers = callbacks;
|
|
350
|
+
handlers.set(node.id, callbacks);
|
|
351
|
+
if (!jsonEqual(nextProps, serialized)) {
|
|
352
|
+
nextProps = serialized;
|
|
353
|
+
propsChanged = true;
|
|
354
|
+
ops.push({ op: "props", id: node.id, props: nextProps });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
let childrenChanged = false;
|
|
358
|
+
let nextChildrenNodes = node.cachedNode.children;
|
|
359
|
+
if (covered) {
|
|
360
|
+
if (node.publishedChildren.length > 0 || coveredChanged) {
|
|
361
|
+
for (let i = 0; i < node.publishedChildren.length; i++) {
|
|
362
|
+
removed.push(node.publishedChildren[i]);
|
|
363
|
+
}
|
|
364
|
+
node.publishedChildren = [];
|
|
365
|
+
nextChildrenNodes = [];
|
|
366
|
+
childrenChanged = true;
|
|
367
|
+
ops.push({ op: "children", id: node.id, children: [] });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
else if (node.childrenDirty || coveredChanged) {
|
|
371
|
+
const prevChildren = node.publishedChildren;
|
|
372
|
+
const nextInstances = [];
|
|
373
|
+
const patchChildren = [];
|
|
374
|
+
nextChildrenNodes = [];
|
|
375
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
376
|
+
const child = node.children[i];
|
|
377
|
+
if (child.hidden)
|
|
378
|
+
continue;
|
|
379
|
+
nextInstances.push(child);
|
|
380
|
+
if (child.published) {
|
|
381
|
+
child.lastCommitRev = activeRev;
|
|
382
|
+
patchChildren.push(child.id);
|
|
383
|
+
if (child.subtreeDirty)
|
|
384
|
+
collectPatch(child, activeRev, ops, removed);
|
|
385
|
+
nextChildrenNodes.push(child.cachedNode);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
const serialized = serializeSubtree(child, activeRev, removed);
|
|
389
|
+
patchChildren.push(serialized);
|
|
390
|
+
nextChildrenNodes.push(serialized);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
for (let i = 0; i < prevChildren.length; i++) {
|
|
394
|
+
const prevChild = prevChildren[i];
|
|
395
|
+
if (prevChild.lastCommitRev !== activeRev)
|
|
396
|
+
removed.push(prevChild);
|
|
397
|
+
}
|
|
398
|
+
node.publishedChildren = nextInstances;
|
|
399
|
+
childrenChanged = true;
|
|
400
|
+
ops.push({ op: "children", id: node.id, children: patchChildren });
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
// Children list unchanged; recurse only into dirty existing children.
|
|
404
|
+
const kids = node.publishedChildren;
|
|
405
|
+
const prevNodes = node.cachedNode.children;
|
|
406
|
+
let anyChildChanged = false;
|
|
407
|
+
for (let i = 0; i < kids.length; i++) {
|
|
408
|
+
const child = kids[i];
|
|
409
|
+
if (child.subtreeDirty) {
|
|
410
|
+
collectPatch(child, activeRev, ops, removed);
|
|
411
|
+
if (child.cachedNode !== prevNodes[i])
|
|
412
|
+
anyChildChanged = true;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (anyChildChanged) {
|
|
416
|
+
childrenChanged = true;
|
|
417
|
+
nextChildrenNodes = [];
|
|
418
|
+
for (let i = 0; i < kids.length; i++) {
|
|
419
|
+
nextChildrenNodes.push(kids[i].cachedNode);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
node.propsDirty = false;
|
|
424
|
+
node.childrenDirty = false;
|
|
425
|
+
node.subtreeDirty = false;
|
|
426
|
+
node.published = true;
|
|
427
|
+
node.publishedCovered = covered;
|
|
428
|
+
if (propsChanged || childrenChanged) {
|
|
429
|
+
node.cachedNode = {
|
|
136
430
|
id: node.id,
|
|
137
431
|
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),
|
|
432
|
+
props: nextProps,
|
|
433
|
+
children: nextChildrenNodes,
|
|
143
434
|
};
|
|
144
435
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
436
|
+
}
|
|
437
|
+
function commitSnapshot() {
|
|
438
|
+
const activeRev = revision + 1;
|
|
439
|
+
const removed = [];
|
|
440
|
+
const visibleTop = [];
|
|
441
|
+
for (let i = 0; i < container.children.length; i++) {
|
|
442
|
+
const child = container.children[i];
|
|
443
|
+
if (!child.hidden)
|
|
444
|
+
visibleTop.push(child);
|
|
445
|
+
}
|
|
446
|
+
const nextKind = visibleTop.length === 0 ? "null" : visibleTop.length === 1 ? "single" : "synthetic";
|
|
447
|
+
const nextRootId = nextKind === "null" ? null : nextKind === "single" ? visibleTop[0].id : "0";
|
|
448
|
+
const canPatch = publishPatch !== undefined &&
|
|
449
|
+
lastPublishedKind !== "none" &&
|
|
450
|
+
nextKind === lastPublishedKind &&
|
|
451
|
+
nextRootId === lastPublishedRootId &&
|
|
452
|
+
nextKind !== "null";
|
|
453
|
+
if (canPatch) {
|
|
454
|
+
const baseRevision = revision;
|
|
455
|
+
const ops = [];
|
|
456
|
+
if (nextKind === "single") {
|
|
457
|
+
collectPatch(visibleTop[0], activeRev, ops, removed);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
// Synthetic `#root` ("0") with multiple top-level children.
|
|
461
|
+
if (container.childrenDirty) {
|
|
462
|
+
const patchChildren = [];
|
|
463
|
+
for (let i = 0; i < visibleTop.length; i++) {
|
|
464
|
+
const child = visibleTop[i];
|
|
465
|
+
if (child.published) {
|
|
466
|
+
child.lastCommitRev = activeRev;
|
|
467
|
+
patchChildren.push(child.id);
|
|
468
|
+
if (child.subtreeDirty)
|
|
469
|
+
collectPatch(child, activeRev, ops, removed);
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
patchChildren.push(serializeSubtree(child, activeRev, removed));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
for (let i = 0; i < lastTopChildren.length; i++) {
|
|
476
|
+
const prevTop = lastTopChildren[i];
|
|
477
|
+
if (prevTop.lastCommitRev !== activeRev)
|
|
478
|
+
removed.push(prevTop);
|
|
479
|
+
}
|
|
480
|
+
lastTopChildren = visibleTop;
|
|
481
|
+
ops.push({ op: "children", id: "0", children: patchChildren });
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
for (let i = 0; i < visibleTop.length; i++) {
|
|
485
|
+
const child = visibleTop[i];
|
|
486
|
+
if (child.subtreeDirty)
|
|
487
|
+
collectPatch(child, activeRev, ops, removed);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
for (let i = 0; i < removed.length; i++)
|
|
492
|
+
unpublishSubtree(removed[i], activeRev);
|
|
493
|
+
container.childrenDirty = false;
|
|
494
|
+
container.subtreeDirty = false;
|
|
495
|
+
revision = activeRev;
|
|
496
|
+
publishPatch({ revision, baseRevision, ops });
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
// Full snapshot path (initial commit, root shape/id change, or unmount to null).
|
|
500
|
+
const serializedTop = [];
|
|
501
|
+
for (let i = 0; i < visibleTop.length; i++) {
|
|
502
|
+
serializedTop.push(serializeSubtree(visibleTop[i], activeRev, removed));
|
|
503
|
+
}
|
|
504
|
+
for (let i = 0; i < lastTopChildren.length; i++) {
|
|
505
|
+
const prevTop = lastTopChildren[i];
|
|
506
|
+
if (prevTop.lastCommitRev !== activeRev)
|
|
507
|
+
removed.push(prevTop);
|
|
508
|
+
}
|
|
509
|
+
for (let i = 0; i < removed.length; i++)
|
|
510
|
+
unpublishSubtree(removed[i], activeRev);
|
|
511
|
+
lastTopChildren = visibleTop;
|
|
512
|
+
container.childrenDirty = false;
|
|
513
|
+
container.subtreeDirty = false;
|
|
514
|
+
const root = serializedTop.length > 1
|
|
515
|
+
? { id: "0", type: "#root", props: {}, children: serializedTop }
|
|
516
|
+
: (serializedTop[0] ?? null);
|
|
517
|
+
const prevKind = lastPublishedKind;
|
|
518
|
+
lastPublishedKind = nextKind;
|
|
519
|
+
lastPublishedRootId = nextRootId;
|
|
520
|
+
if (publishPatch !== undefined && prevKind !== "none" && nextKind === "null") {
|
|
521
|
+
const baseRevision = revision;
|
|
522
|
+
revision = activeRev;
|
|
523
|
+
publishPatch({ revision, baseRevision, ops: [{ op: "root", root: null }] });
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
revision = activeRev;
|
|
527
|
+
publish({ revision, root });
|
|
150
528
|
}
|
|
151
529
|
function reportError(error) {
|
|
152
530
|
if (onError)
|
|
@@ -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
|
@@ -16,14 +16,19 @@
|
|
|
16
16
|
"types": "./dist/main.d.ts",
|
|
17
17
|
"import": "./dist/main.js",
|
|
18
18
|
"default": "./dist/main.js"
|
|
19
|
+
},
|
|
20
|
+
"./browser": {
|
|
21
|
+
"types": "./dist/browser.d.ts",
|
|
22
|
+
"import": "./dist/browser.js",
|
|
23
|
+
"default": "./dist/browser.js"
|
|
19
24
|
}
|
|
20
25
|
},
|
|
21
26
|
"dependencies": {
|
|
22
|
-
"@blastlauncher/protocol": "3.0.0-alpha.
|
|
27
|
+
"@blastlauncher/protocol": "3.0.0-alpha.10",
|
|
23
28
|
"react": "19.3.1",
|
|
24
29
|
"react-reconciler": "0.34.0"
|
|
25
30
|
},
|
|
26
|
-
"version": "3.0.0-alpha.
|
|
31
|
+
"version": "3.0.0-alpha.10",
|
|
27
32
|
"license": "MIT",
|
|
28
33
|
"repository": {
|
|
29
34
|
"type": "git",
|