@isoloop/dom 0.0.0-next.5bbb503 → 0.0.0-next.62ef495
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/{applier-BSeEH9MP.js → applier-D5wb4gz9.js} +7 -1
- package/dist/{dom-ANUAQHqi.d.ts → dom-Bctskbvg.d.ts} +49 -5
- package/dist/{dom-7EzPoV0N.js → dom-yLsf0Z4e.js} +134 -64
- package/dist/host.js +1 -1
- package/dist/{install-DE1VIvyG.js → install-D7m7By8i.js} +1 -1
- package/dist/testing-worker.d.ts +9 -1
- package/dist/testing-worker.js +37 -3
- package/dist/testing.d.ts +7 -1
- package/dist/testing.js +31 -3
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +2 -2
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ function createApplier(container, policy) {
|
|
|
17
17
|
const nodes = /* @__PURE__ */ new Map([[0, container]]);
|
|
18
18
|
const ids = new WeakMap([[container, 0]]);
|
|
19
19
|
const listens = /* @__PURE__ */ new Map();
|
|
20
|
+
const known = /* @__PURE__ */ new WeakMap();
|
|
20
21
|
const setAttr = (el, name, value) => {
|
|
21
22
|
const safe = value === null ? null : policy.attribute(el.localName, nsOf(el), name, value);
|
|
22
23
|
try {
|
|
@@ -25,6 +26,7 @@ function createApplier(container, policy) {
|
|
|
25
26
|
} catch {}
|
|
26
27
|
};
|
|
27
28
|
const setProp = (el, name, value, force = false) => {
|
|
29
|
+
if (name === "checked") known.set(el, Boolean(value));
|
|
28
30
|
if (!policy.property(el, name, value, force)) return;
|
|
29
31
|
if (name === "checked" && el instanceof HTMLInputElement) el.checked = Boolean(value);
|
|
30
32
|
else if (name === "selected" && el instanceof HTMLOptionElement) el.selected = Boolean(value);
|
|
@@ -160,7 +162,11 @@ function createApplier(container, policy) {
|
|
|
160
162
|
};
|
|
161
163
|
const el = nodes.get(target);
|
|
162
164
|
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement) out.value = el.value;
|
|
163
|
-
if (el instanceof HTMLInputElement &&
|
|
165
|
+
if (el instanceof HTMLInputElement && el.type === "radio") out.checked = el.checked;
|
|
166
|
+
else if (el instanceof HTMLInputElement && el.type === "checkbox" && known.get(el) !== el.checked) {
|
|
167
|
+
out.checked = el.checked;
|
|
168
|
+
known.set(el, el.checked);
|
|
169
|
+
}
|
|
164
170
|
if (e instanceof MouseEvent || e instanceof KeyboardEvent) out.mods = {
|
|
165
171
|
alt: e.altKey,
|
|
166
172
|
ctrl: e.ctrlKey,
|
|
@@ -7,13 +7,20 @@ type Listener = {
|
|
|
7
7
|
capture: boolean;
|
|
8
8
|
once: boolean;
|
|
9
9
|
};
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* One render root and where its records go. A worker has one; a pool has one
|
|
12
|
+
* per visual member, all in the same document (ADR 0015).
|
|
13
|
+
*/
|
|
14
|
+
type Owner = {
|
|
15
|
+
readonly root: WElement;
|
|
16
|
+
push(r: DomRecord): void;
|
|
17
|
+
};
|
|
18
|
+
/** Shared state of one document: ids, the render roots, known nodes. */
|
|
11
19
|
type Core = {
|
|
12
|
-
/** The render
|
|
13
|
-
|
|
20
|
+
/** The render roots, in the order they were made. */
|
|
21
|
+
roots: Set<WElement>;
|
|
14
22
|
nextId: number;
|
|
15
23
|
known: Map<NodeId, WNode>;
|
|
16
|
-
record(r: DomRecord): void;
|
|
17
24
|
/** An element was inserted into `document.head`, which the bridge doesn't render. */
|
|
18
25
|
onHead(tag: string): void;
|
|
19
26
|
};
|
|
@@ -51,8 +58,19 @@ declare abstract class WNode extends WEventTarget {
|
|
|
51
58
|
/** @internal */ isoNext: WNode | null;
|
|
52
59
|
/** @internal Whether the host knows this node (it's in the tree under the root). */
|
|
53
60
|
isoKnown: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* @internal The root this node was rendered under, once it has been. Kept
|
|
63
|
+
* after the node leaves the tree, so it can't move to another member's root
|
|
64
|
+
* in a pool (ADR 0015, decision 3).
|
|
65
|
+
*/
|
|
66
|
+
isoOwner: Owner | null;
|
|
54
67
|
constructor(doc: WDocument, id: NodeId);
|
|
55
68
|
/** @internal */ override isoParentTarget(): WEventTarget | null;
|
|
69
|
+
/**
|
|
70
|
+
* @internal The id the host knows this node by: a render root is always
|
|
71
|
+
* `ROOT_ID` to its own surface, whatever its id in the document.
|
|
72
|
+
*/
|
|
73
|
+
get isoWire(): NodeId;
|
|
56
74
|
/** @internal */ override isoListenChanged(type: string, on: boolean): void;
|
|
57
75
|
get parentNode(): WParentNode | null;
|
|
58
76
|
get parentElement(): WElement | null;
|
|
@@ -267,6 +285,32 @@ interface WorkerDom {
|
|
|
267
285
|
setValue(node: WNode, value: string, opts?: {
|
|
268
286
|
force?: boolean;
|
|
269
287
|
}): void;
|
|
288
|
+
/**
|
|
289
|
+
* Adds another render root to this document, with its own batches: one per
|
|
290
|
+
* visual member of a pool (ADR 0015). Its surface knows it as `ROOT_ID`.
|
|
291
|
+
*/
|
|
292
|
+
addRoot(opts: RootOptions): RenderRoot;
|
|
293
|
+
}
|
|
294
|
+
type RootOptions = {
|
|
295
|
+
/** Receives this root's batches, in order. */
|
|
296
|
+
onBatch(batch: DomBatch): void;
|
|
297
|
+
/** Called once per batch with the flush to run; default `queueMicrotask`. */
|
|
298
|
+
schedule?: (flush: () => void) => void;
|
|
299
|
+
};
|
|
300
|
+
/** One member's render root in a shared document (ADR 0015). */
|
|
301
|
+
interface RenderRoot {
|
|
302
|
+
readonly root: WElement;
|
|
303
|
+
/** Sends this root's pending records now, if any. */
|
|
304
|
+
flush(): void;
|
|
305
|
+
/** Dispatches an event from this root's surface; `ROOT_ID` names the root. */
|
|
306
|
+
deliver(event: DomEvent): void;
|
|
307
|
+
/** The id this root's surface knows `node` by, or `undefined` if it isn't rendered under this root. */
|
|
308
|
+
idOf(node: WNode): NodeId | undefined;
|
|
309
|
+
setValue(node: WNode, value: string, opts?: {
|
|
310
|
+
force?: boolean;
|
|
311
|
+
}): void;
|
|
312
|
+
/** Stops sending this root's records and forgets its nodes: the member stopped. */
|
|
313
|
+
dispose(): void;
|
|
270
314
|
}
|
|
271
315
|
declare function createDom(opts: WorkerDomOptions): WorkerDom;
|
|
272
|
-
export {
|
|
316
|
+
export { WDocumentFragment as a, WText as c, createDom as d, WDocument as i, WorkerDom as l, RootOptions as n, WElement as o, WComment as r, WNode as s, RenderRoot as t, WorkerDomOptions as u };
|
|
@@ -9,6 +9,10 @@ const domError = (name, message) => {
|
|
|
9
9
|
e.name = name;
|
|
10
10
|
return e;
|
|
11
11
|
};
|
|
12
|
+
/** Records a change to a known node, to the root that holds it. */
|
|
13
|
+
const emit = (n, r) => {
|
|
14
|
+
n.isoOwner?.push(r);
|
|
15
|
+
};
|
|
12
16
|
/** Listener storage and capture/bubble dispatch through `isoParentTarget()`. */
|
|
13
17
|
var WEventTarget = class {
|
|
14
18
|
/** @internal */ isoListeners = /* @__PURE__ */ new Map();
|
|
@@ -152,6 +156,12 @@ var WNode = class extends WEventTarget {
|
|
|
152
156
|
/** @internal */ isoNext = null;
|
|
153
157
|
/** @internal Whether the host knows this node (it's in the tree under the root). */
|
|
154
158
|
isoKnown = false;
|
|
159
|
+
/**
|
|
160
|
+
* @internal The root this node was rendered under, once it has been. Kept
|
|
161
|
+
* after the node leaves the tree, so it can't move to another member's root
|
|
162
|
+
* in a pool (ADR 0015, decision 3).
|
|
163
|
+
*/
|
|
164
|
+
isoOwner = null;
|
|
155
165
|
constructor(doc, id) {
|
|
156
166
|
super();
|
|
157
167
|
this.ownerDocument = doc;
|
|
@@ -160,10 +170,17 @@ var WNode = class extends WEventTarget {
|
|
|
160
170
|
/** @internal */ isoParentTarget() {
|
|
161
171
|
return this.isoParent;
|
|
162
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* @internal The id the host knows this node by: a render root is always
|
|
175
|
+
* `ROOT_ID` to its own surface, whatever its id in the document.
|
|
176
|
+
*/
|
|
177
|
+
get isoWire() {
|
|
178
|
+
return this.isoOwner?.root === this ? 0 : this.isoId;
|
|
179
|
+
}
|
|
163
180
|
/** @internal */ isoListenChanged(type, on) {
|
|
164
|
-
if (this.isoKnown) this
|
|
181
|
+
if (this.isoKnown) emit(this, [
|
|
165
182
|
"listen",
|
|
166
|
-
this.
|
|
183
|
+
this.isoWire,
|
|
167
184
|
type,
|
|
168
185
|
on
|
|
169
186
|
]);
|
|
@@ -217,9 +234,9 @@ var WCharacterData = class extends WNode {
|
|
|
217
234
|
const data = str(v);
|
|
218
235
|
if (data === this.isoData) return;
|
|
219
236
|
this.isoData = data;
|
|
220
|
-
if (this.isoKnown) this
|
|
237
|
+
if (this.isoKnown) emit(this, [
|
|
221
238
|
"text",
|
|
222
|
-
this.
|
|
239
|
+
this.isoWire,
|
|
223
240
|
data
|
|
224
241
|
]);
|
|
225
242
|
}
|
|
@@ -443,27 +460,28 @@ var WParentNode = class extends WNode {
|
|
|
443
460
|
return child;
|
|
444
461
|
}
|
|
445
462
|
if (this.ownerDocument.head === this && child instanceof WElement) this.ownerDocument.isoCore.onHead(child.localName);
|
|
463
|
+
if (this.isoKnown && ownedElsewhere(child, this.isoOwner)) throw domError("HierarchyRequestError", "insertBefore: a node can't move to another member's root in a pool");
|
|
446
464
|
const wasKnown = child.isoKnown;
|
|
447
465
|
child.isoParent?.isoUnlink(child);
|
|
448
466
|
this.isoLink(child, ref);
|
|
449
467
|
const core = this.ownerDocument.isoCore;
|
|
450
|
-
if (wasKnown && this.isoKnown)
|
|
468
|
+
if (wasKnown && this.isoKnown) emit(this, [
|
|
451
469
|
"move",
|
|
452
|
-
this.
|
|
470
|
+
this.isoWire,
|
|
453
471
|
child.isoId,
|
|
454
472
|
ref?.isoId ?? null
|
|
455
473
|
]);
|
|
456
474
|
else if (wasKnown) {
|
|
457
|
-
|
|
475
|
+
emit(child, ["remove", child.isoId]);
|
|
458
476
|
forget(child, core);
|
|
459
477
|
} else if (this.isoKnown) {
|
|
460
|
-
|
|
478
|
+
emit(this, [
|
|
461
479
|
"insert",
|
|
462
|
-
this.
|
|
480
|
+
this.isoWire,
|
|
463
481
|
serialize(child),
|
|
464
482
|
ref?.isoId ?? null
|
|
465
483
|
]);
|
|
466
|
-
learn(child, core);
|
|
484
|
+
learn(child, core, this.isoOwner);
|
|
467
485
|
}
|
|
468
486
|
return child;
|
|
469
487
|
}
|
|
@@ -471,9 +489,8 @@ var WParentNode = class extends WNode {
|
|
|
471
489
|
if (child.isoParent !== this) throw domError("NotFoundError", "removeChild: not a child");
|
|
472
490
|
this.isoUnlink(child);
|
|
473
491
|
if (child.isoKnown) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
forget(child, core);
|
|
492
|
+
emit(child, ["remove", child.isoId]);
|
|
493
|
+
forget(child, this.ownerDocument.isoCore);
|
|
477
494
|
}
|
|
478
495
|
return child;
|
|
479
496
|
}
|
|
@@ -566,9 +583,9 @@ var WElement = class extends WParentNode {
|
|
|
566
583
|
const v = str(value);
|
|
567
584
|
if (this.isoAttrs.get(n) === v) return;
|
|
568
585
|
this.isoAttrs.set(n, v);
|
|
569
|
-
if (this.isoKnown) this
|
|
586
|
+
if (this.isoKnown) emit(this, [
|
|
570
587
|
"attr",
|
|
571
|
-
this.
|
|
588
|
+
this.isoWire,
|
|
572
589
|
n,
|
|
573
590
|
v
|
|
574
591
|
]);
|
|
@@ -576,9 +593,9 @@ var WElement = class extends WParentNode {
|
|
|
576
593
|
removeAttribute(name) {
|
|
577
594
|
const n = this.isoAttrName(name);
|
|
578
595
|
if (!this.isoAttrs.delete(n)) return;
|
|
579
|
-
if (this.isoKnown) this
|
|
596
|
+
if (this.isoKnown) emit(this, [
|
|
580
597
|
"attr",
|
|
581
|
-
this.
|
|
598
|
+
this.isoWire,
|
|
582
599
|
n,
|
|
583
600
|
null
|
|
584
601
|
]);
|
|
@@ -618,9 +635,9 @@ var WElement = class extends WParentNode {
|
|
|
618
635
|
/** @internal */ isoSetProp(name, value, record) {
|
|
619
636
|
if (this.isoProps.get(name) === value) return;
|
|
620
637
|
this.isoProps.set(name, value);
|
|
621
|
-
if (record && this.isoKnown) this
|
|
638
|
+
if (record && this.isoKnown) emit(this, [
|
|
622
639
|
"prop",
|
|
623
|
-
this.
|
|
640
|
+
this.isoWire,
|
|
624
641
|
name,
|
|
625
642
|
value
|
|
626
643
|
]);
|
|
@@ -907,8 +924,11 @@ var WDocument = class extends WEventTarget {
|
|
|
907
924
|
}
|
|
908
925
|
return null;
|
|
909
926
|
};
|
|
910
|
-
const root
|
|
911
|
-
|
|
927
|
+
for (const root of this.isoCore.roots) {
|
|
928
|
+
const hit = walk(root);
|
|
929
|
+
if (hit) return hit;
|
|
930
|
+
}
|
|
931
|
+
return walk(this.head);
|
|
912
932
|
}
|
|
913
933
|
/**
|
|
914
934
|
* Type selectors only, alone or as a `head > title` child chain: what React
|
|
@@ -967,75 +987,125 @@ function serialize(n) {
|
|
|
967
987
|
children: n.childNodes.map(serialize)
|
|
968
988
|
};
|
|
969
989
|
}
|
|
970
|
-
|
|
990
|
+
/** Whether `n` or anything under it was rendered under a root other than `owner`. */
|
|
991
|
+
function ownedElsewhere(n, owner) {
|
|
992
|
+
if (n.isoOwner && n.isoOwner !== owner) return true;
|
|
993
|
+
return !n.isoKnown && n.childNodes.some((c) => ownedElsewhere(c, owner));
|
|
994
|
+
}
|
|
995
|
+
function learn(n, core, owner) {
|
|
971
996
|
n.isoKnown = true;
|
|
997
|
+
n.isoOwner = owner;
|
|
972
998
|
core.known.set(n.isoId, n);
|
|
973
|
-
for (const c of n.childNodes) learn(c, core);
|
|
999
|
+
for (const c of n.childNodes) learn(c, core, owner);
|
|
974
1000
|
}
|
|
975
1001
|
function forget(n, core) {
|
|
976
1002
|
n.isoKnown = false;
|
|
977
1003
|
core.known.delete(n.isoId);
|
|
978
1004
|
for (const c of n.childNodes) forget(c, core);
|
|
979
1005
|
}
|
|
980
|
-
|
|
981
|
-
|
|
1006
|
+
const isControl = (node) => node instanceof WHTMLInputElement || node instanceof WHTMLTextAreaElement || node instanceof WHTMLSelectElement;
|
|
1007
|
+
function setValueOf(node, value, o) {
|
|
1008
|
+
if (!isControl(node)) throw new TypeError("setValue: not an input, textarea or select");
|
|
1009
|
+
if (!o.force) {
|
|
1010
|
+
node.value = value;
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
1013
|
+
node.isoSetProp("value", value, false);
|
|
1014
|
+
if (node.isoKnown) emit(node, [
|
|
1015
|
+
"prop",
|
|
1016
|
+
node.isoWire,
|
|
1017
|
+
"value",
|
|
1018
|
+
value,
|
|
1019
|
+
true
|
|
1020
|
+
]);
|
|
1021
|
+
}
|
|
1022
|
+
function deliverTo(node, event) {
|
|
1023
|
+
if (!node) return;
|
|
1024
|
+
if (isControl(node) && event.value !== void 0) node.isoSetProp("value", event.value, false);
|
|
1025
|
+
if (node instanceof WHTMLInputElement && event.checked !== void 0) node.isoSetProp("checked", event.checked, false);
|
|
1026
|
+
if (event.type === "scroll" && node instanceof WElement) node.isoScroll = {
|
|
1027
|
+
top: event.scrollTop ?? 0,
|
|
1028
|
+
left: event.scrollLeft ?? 0
|
|
1029
|
+
};
|
|
1030
|
+
node.dispatchEvent(toEvent(event));
|
|
1031
|
+
}
|
|
1032
|
+
/** A root's recorder: records batched per microtask (or `schedule`) into `onBatch`. */
|
|
1033
|
+
function recorder(root, onBatch, schedule) {
|
|
982
1034
|
let pending = [];
|
|
983
1035
|
let scheduled = false;
|
|
1036
|
+
let live = true;
|
|
984
1037
|
const flush = () => {
|
|
985
1038
|
scheduled = false;
|
|
986
1039
|
if (pending.length === 0) return;
|
|
987
1040
|
const batch = pending;
|
|
988
1041
|
pending = [];
|
|
989
|
-
|
|
1042
|
+
if (live) onBatch(batch);
|
|
1043
|
+
};
|
|
1044
|
+
return {
|
|
1045
|
+
owner: {
|
|
1046
|
+
root,
|
|
1047
|
+
push(r) {
|
|
1048
|
+
if (!live) return;
|
|
1049
|
+
pending.push(r);
|
|
1050
|
+
if (!scheduled) {
|
|
1051
|
+
scheduled = true;
|
|
1052
|
+
schedule(flush);
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
},
|
|
1056
|
+
flush,
|
|
1057
|
+
stop: () => {
|
|
1058
|
+
live = false;
|
|
1059
|
+
pending = [];
|
|
1060
|
+
}
|
|
990
1061
|
};
|
|
1062
|
+
}
|
|
1063
|
+
function createDom(opts) {
|
|
1064
|
+
const schedule = opts.schedule ?? ((fn) => queueMicrotask(fn));
|
|
991
1065
|
const core = {
|
|
992
|
-
|
|
1066
|
+
roots: /* @__PURE__ */ new Set(),
|
|
993
1067
|
nextId: 1,
|
|
994
1068
|
known: /* @__PURE__ */ new Map(),
|
|
995
|
-
onHead: opts.onHead ?? (() => {})
|
|
996
|
-
record(r) {
|
|
997
|
-
pending.push(r);
|
|
998
|
-
if (!scheduled) {
|
|
999
|
-
scheduled = true;
|
|
1000
|
-
schedule(flush);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1069
|
+
onHead: opts.onHead ?? (() => {})
|
|
1003
1070
|
};
|
|
1004
1071
|
const document = new WDocument(core);
|
|
1005
|
-
const
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1072
|
+
const makeRoot = (id) => {
|
|
1073
|
+
const root = new WHTMLElement(document, id, "iso-root", "html");
|
|
1074
|
+
root.isoKnown = true;
|
|
1075
|
+
core.known.set(id, root);
|
|
1076
|
+
core.roots.add(root);
|
|
1077
|
+
return root;
|
|
1078
|
+
};
|
|
1079
|
+
const root = makeRoot(0);
|
|
1080
|
+
const main = recorder(root, (b) => opts.onBatch(b), schedule);
|
|
1081
|
+
root.isoOwner = main.owner;
|
|
1009
1082
|
return {
|
|
1010
1083
|
document,
|
|
1011
1084
|
root,
|
|
1012
|
-
flush,
|
|
1085
|
+
flush: main.flush,
|
|
1013
1086
|
idOf: (node) => node.isoId,
|
|
1014
|
-
setValue(node, value, o = {})
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
node.
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
value,
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
top: event.scrollTop ?? 0,
|
|
1036
|
-
left: event.scrollLeft ?? 0
|
|
1087
|
+
setValue: (node, value, o = {}) => setValueOf(node, value, o),
|
|
1088
|
+
deliver: (event) => deliverTo(core.known.get(event.target), event),
|
|
1089
|
+
addRoot(o) {
|
|
1090
|
+
const member = makeRoot(core.nextId++);
|
|
1091
|
+
const rec = recorder(member, (b) => o.onBatch(b), o.schedule ?? schedule);
|
|
1092
|
+
member.isoOwner = rec.owner;
|
|
1093
|
+
const mine = (node) => node?.isoKnown && node.isoOwner === rec.owner ? node : void 0;
|
|
1094
|
+
return {
|
|
1095
|
+
root: member,
|
|
1096
|
+
flush: rec.flush,
|
|
1097
|
+
idOf: (node) => mine(node) ? node.isoWire : void 0,
|
|
1098
|
+
setValue(node, value, so = {}) {
|
|
1099
|
+
if (node.isoOwner && node.isoOwner !== rec.owner) throw new TypeError("setValue: not a node of this member's root");
|
|
1100
|
+
setValueOf(node, value, so);
|
|
1101
|
+
},
|
|
1102
|
+
deliver: (event) => deliverTo(mine(event.target === 0 ? member : core.known.get(event.target)), event),
|
|
1103
|
+
dispose() {
|
|
1104
|
+
rec.stop();
|
|
1105
|
+
core.roots.delete(member);
|
|
1106
|
+
forget(member, core);
|
|
1107
|
+
}
|
|
1037
1108
|
};
|
|
1038
|
-
node.dispatchEvent(toEvent(event));
|
|
1039
1109
|
}
|
|
1040
1110
|
};
|
|
1041
1111
|
}
|
package/dist/host.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { n as ROOT_ID, r as isDomBatch, t as ISOLOOP_DOM_FMT } from "./records-wVZrPpqr.js";
|
|
2
|
-
import { t as createApplier } from "./applier-
|
|
2
|
+
import { t as createApplier } from "./applier-D5wb4gz9.js";
|
|
3
3
|
export { ISOLOOP_DOM_FMT, ROOT_ID, createApplier, isDomBatch };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as WText, a as WDocumentFragment, c as WHTMLElement, d as WHTMLOptionElement, f as WHTMLSelectElement, g as WSVGElement, l as WHTMLIFrameElement, m as WNode, n as WComment, o as WElement, p as WHTMLTextAreaElement, r as WDOMTokenList, u as WHTMLInputElement } from "./dom-
|
|
1
|
+
import { _ as WText, a as WDocumentFragment, c as WHTMLElement, d as WHTMLOptionElement, f as WHTMLSelectElement, g as WSVGElement, l as WHTMLIFrameElement, m as WNode, n as WComment, o as WElement, p as WHTMLTextAreaElement, r as WDOMTokenList, u as WHTMLInputElement } from "./dom-yLsf0Z4e.js";
|
|
2
2
|
// src/worker/install.ts
|
|
3
3
|
/** The DOM globals the subset provides (ADR 0010 point 2), by their DOM names. */
|
|
4
4
|
const DOM_GLOBALS = {
|
package/dist/testing-worker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as DomBatch } from "./records-OXGckMg9.js";
|
|
2
|
-
import {
|
|
2
|
+
import { l as WorkerDom } from "./dom-Bctskbvg.js";
|
|
3
3
|
/** One framework major's log, as `packages/dom/usage/<project>.json` stores it. */
|
|
4
4
|
export type UsageLog = {
|
|
5
5
|
/** E.g. `preact@10.29.8`. */
|
|
@@ -19,6 +19,7 @@ export type UsageTracker = {
|
|
|
19
19
|
export type FixtureMessage = {
|
|
20
20
|
t: "batch";
|
|
21
21
|
batch: DomBatch;
|
|
22
|
+
member?: number;
|
|
22
23
|
} | {
|
|
23
24
|
t: "usage";
|
|
24
25
|
log: UsageLog;
|
|
@@ -26,6 +27,13 @@ export type FixtureMessage = {
|
|
|
26
27
|
t: "error";
|
|
27
28
|
error: string;
|
|
28
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* A pooled fixture (ADR 0015, M2d): one subset document installed as this
|
|
32
|
+
* worker's `document`, with `n` render roots, one per member. Each root's
|
|
33
|
+
* batches are posted with its `member` index, and the page's events for a
|
|
34
|
+
* member go to its root. Pair with `mountMembers()` on the page.
|
|
35
|
+
*/
|
|
36
|
+
export declare function servePoolFixture(n: number): Element[];
|
|
29
37
|
/**
|
|
30
38
|
* Installs the subset as this worker's `document`, posts every batch, and
|
|
31
39
|
* delivers the page's events. Import it before the framework: React decides
|
package/dist/testing-worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as install, t as DOM_GLOBALS } from "./install-
|
|
2
|
-
import { h as WParentNode, i as WDocument, o as WElement, s as WEventTarget, t as WCharacterData, v as createDom } from "./dom-
|
|
1
|
+
import { n as install, t as DOM_GLOBALS } from "./install-D7m7By8i.js";
|
|
2
|
+
import { h as WParentNode, i as WDocument, o as WElement, s as WEventTarget, t as WCharacterData, v as createDom } from "./dom-yLsf0Z4e.js";
|
|
3
3
|
// src/testing/worker.ts
|
|
4
4
|
/** Everything a framework sees: the classes `install()` exposes, and `document`. */
|
|
5
5
|
const CLASSES = [
|
|
@@ -26,6 +26,40 @@ const fail = (err) => {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
const isEventMessage = (x) => typeof x === "object" && x !== null && Reflect.get(x, "t") === "event";
|
|
29
|
+
const catchErrors = () => {
|
|
30
|
+
addEventListener("error", (e) => {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
fail(e.error);
|
|
33
|
+
});
|
|
34
|
+
addEventListener("unhandledrejection", (e) => {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
fail(e.reason);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* A pooled fixture (ADR 0015, M2d): one subset document installed as this
|
|
41
|
+
* worker's `document`, with `n` render roots, one per member. Each root's
|
|
42
|
+
* batches are posted with its `member` index, and the page's events for a
|
|
43
|
+
* member go to its root. Pair with `mountMembers()` on the page.
|
|
44
|
+
*/
|
|
45
|
+
function servePoolFixture(n) {
|
|
46
|
+
const dom = createDom({ onBatch: () => {} });
|
|
47
|
+
install(dom, self);
|
|
48
|
+
const roots = Array.from({ length: n }, (_, member) => dom.addRoot({ onBatch: (batch) => post({
|
|
49
|
+
t: "batch",
|
|
50
|
+
batch,
|
|
51
|
+
member
|
|
52
|
+
}) }));
|
|
53
|
+
addEventListener("message", (e) => {
|
|
54
|
+
if (isEventMessage(e.data)) roots[e.data.member ?? 0]?.deliver(e.data.event);
|
|
55
|
+
});
|
|
56
|
+
catchErrors();
|
|
57
|
+
return roots.map((r) => {
|
|
58
|
+
const container = r.root;
|
|
59
|
+
if (!(container instanceof Element)) throw new Error("the subset is not installed");
|
|
60
|
+
return container;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
29
63
|
/**
|
|
30
64
|
* Installs the subset as this worker's `document`, posts every batch, and
|
|
31
65
|
* delivers the page's events. Import it before the framework: React decides
|
|
@@ -180,4 +214,4 @@ async function reportUsage(tracker, framework, run) {
|
|
|
180
214
|
fail(err);
|
|
181
215
|
}
|
|
182
216
|
}
|
|
183
|
-
export { driveUsageFixture, reportUsage, serveFixture, trackUsage };
|
|
217
|
+
export { driveUsageFixture, reportUsage, serveFixture, servePoolFixture, trackUsage };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as WorkerDom } from "./dom-Bctskbvg.js";
|
|
2
2
|
import { FixtureMessage, UsageLog } from "./testing-worker.js";
|
|
3
3
|
/** An event as a host bridge sends it to the isolate, reduced to what the suite reads. */
|
|
4
4
|
type ConformanceEvent = {
|
|
@@ -134,6 +134,12 @@ type FixtureHost = {
|
|
|
134
134
|
dispose(): void;
|
|
135
135
|
};
|
|
136
136
|
export declare function mountFixture(worker: Worker): FixtureHost;
|
|
137
|
+
/**
|
|
138
|
+
* The page side of `servePoolFixture(n)`: one container per member, each
|
|
139
|
+
* with its own applier, getting only that member's batches and sending its
|
|
140
|
+
* events back for that member (ADR 0015, M2d task 2).
|
|
141
|
+
*/
|
|
142
|
+
export declare function mountMembers(worker: Worker, n: number): HTMLElement[];
|
|
137
143
|
/**
|
|
138
144
|
* The user actions the smoke tests take on the fixture app (the same ones
|
|
139
145
|
* `driveUsageFixture` sends as events), for a container either way: the
|
package/dist/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as WParentNode, o as WElement, t as WCharacterData, v as createDom } from "./dom-
|
|
2
|
-
import { t as createApplier } from "./applier-
|
|
1
|
+
import { h as WParentNode, o as WElement, t as WCharacterData, v as createDom } from "./dom-yLsf0Z4e.js";
|
|
2
|
+
import { t as createApplier } from "./applier-D5wb4gz9.js";
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
import { commands } from "vitest/browser";
|
|
5
5
|
// src/testing/conformance.ts
|
|
@@ -615,6 +615,34 @@ function mountFixture(worker) {
|
|
|
615
615
|
}
|
|
616
616
|
};
|
|
617
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* The page side of `servePoolFixture(n)`: one container per member, each
|
|
620
|
+
* with its own applier, getting only that member's batches and sending its
|
|
621
|
+
* events back for that member (ADR 0015, M2d task 2).
|
|
622
|
+
*/
|
|
623
|
+
function mountMembers(worker, n) {
|
|
624
|
+
const surfaces = Array.from({ length: n }, (_, member) => {
|
|
625
|
+
const container = document.createElement("div");
|
|
626
|
+
document.body.append(container);
|
|
627
|
+
const applier = createApplier(container, OPEN);
|
|
628
|
+
for (const type of EVENTS) container.addEventListener(type, (e) => {
|
|
629
|
+
const event = applier.eventFor(e);
|
|
630
|
+
if (event) worker.postMessage({
|
|
631
|
+
t: "event",
|
|
632
|
+
event,
|
|
633
|
+
member
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
return {
|
|
637
|
+
container,
|
|
638
|
+
applier
|
|
639
|
+
};
|
|
640
|
+
});
|
|
641
|
+
worker.addEventListener("message", (e) => {
|
|
642
|
+
if (isMessage(e.data) && e.data.t === "batch") surfaces[e.data.member ?? 0]?.applier.apply(e.data.batch);
|
|
643
|
+
});
|
|
644
|
+
return surfaces.map((s) => s.container);
|
|
645
|
+
}
|
|
618
646
|
/** Sets a control's value the way typing does: through the prototype's setter, past React's value tracker. */
|
|
619
647
|
function setNative(el, value) {
|
|
620
648
|
const proto = el instanceof HTMLInputElement ? HTMLInputElement.prototype : HTMLSelectElement.prototype;
|
|
@@ -668,4 +696,4 @@ function snapshot(root) {
|
|
|
668
696
|
select: one(root, "select", HTMLSelectElement).value
|
|
669
697
|
};
|
|
670
698
|
}
|
|
671
|
-
export { CASES, SMOKE_STEPS, TOLERATED_MISSING, checkDomUsage, createIsoloopDomDriver, mountFixture, runBridgeConformance, snapshot };
|
|
699
|
+
export { CASES, SMOKE_STEPS, TOLERATED_MISSING, checkDomUsage, createIsoloopDomDriver, mountFixture, mountMembers, runBridgeConformance, snapshot };
|
package/dist/worker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as ISOLOOP_DOM_FMT, c as ROOT_ID, i as DomRecord, l as SerializedNode, n as DomEvent, o as Namespace, r as DomMods, s as NodeId, t as DomBatch, u as SyncedProp } from "./records-OXGckMg9.js";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as WDocumentFragment, c as WText, d as createDom, i as WDocument, l as WorkerDom, n as RootOptions, o as WElement, r as WComment, s as WNode, t as RenderRoot, u as WorkerDomOptions } from "./dom-Bctskbvg.js";
|
|
3
3
|
/** The DOM globals the subset provides (ADR 0010 point 2), by their DOM names. */
|
|
4
4
|
export declare const DOM_GLOBALS: Readonly<Record<string, unknown>>;
|
|
5
5
|
/**
|
|
@@ -8,4 +8,4 @@ export declare const DOM_GLOBALS: Readonly<Record<string, unknown>>;
|
|
|
8
8
|
* headless isolate never calls this.
|
|
9
9
|
*/
|
|
10
10
|
export declare function install(dom: WorkerDom, scope: object): void;
|
|
11
|
-
export { type DomBatch, type DomEvent, type DomMods, type DomRecord, ISOLOOP_DOM_FMT, type Namespace, type NodeId, ROOT_ID, type SerializedNode, type SyncedProp, WComment, WDocument, WDocumentFragment, WElement, WNode, WText, type WorkerDom, type WorkerDomOptions, createDom };
|
|
11
|
+
export { type DomBatch, type DomEvent, type DomMods, type DomRecord, ISOLOOP_DOM_FMT, type Namespace, type NodeId, ROOT_ID, type RenderRoot, type RootOptions, type SerializedNode, type SyncedProp, WComment, WDocument, WDocumentFragment, WElement, WNode, WText, type WorkerDom, type WorkerDomOptions, createDom };
|
package/dist/worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { n as ROOT_ID, t as ISOLOOP_DOM_FMT } from "./records-wVZrPpqr.js";
|
|
2
|
-
import { _ as WText, a as WDocumentFragment, i as WDocument, m as WNode, n as WComment, o as WElement, v as createDom } from "./dom-
|
|
3
|
-
import { n as install, t as DOM_GLOBALS } from "./install-
|
|
2
|
+
import { _ as WText, a as WDocumentFragment, i as WDocument, m as WNode, n as WComment, o as WElement, v as createDom } from "./dom-yLsf0Z4e.js";
|
|
3
|
+
import { n as install, t as DOM_GLOBALS } from "./install-D7m7By8i.js";
|
|
4
4
|
export { DOM_GLOBALS, ISOLOOP_DOM_FMT, ROOT_ID, WComment, WDocument, WDocumentFragment, WElement, WNode, WText, createDom, install };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@isoloop/dom",
|
|
3
|
-
"version": "0.0.0-next.
|
|
3
|
+
"version": "0.0.0-next.62ef495",
|
|
4
4
|
"description": "Internal: Isoloop's render bridge (isoloop-dom@1). Used by @isoloop/runtime and @isoloop/host; not for app code.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|