tutuca 0.9.113 → 0.9.114
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/chai.js +1180 -359
- package/dist/tutuca-cli.js +14827 -13802
- package/dist/tutuca-components.js +323 -354
- package/dist/tutuca-dev.ext.js +1955 -2033
- package/dist/tutuca-dev.js +3254 -2627
- package/dist/tutuca-dev.min.js +5 -5
- package/dist/tutuca-extra.ext.js +1044 -1222
- package/dist/tutuca-extra.js +1261 -1480
- package/dist/tutuca-extra.min.js +3 -3
- package/dist/tutuca-storybook.js +174 -123
- package/dist/tutuca.ext.js +1026 -1213
- package/dist/tutuca.js +1243 -1471
- package/dist/tutuca.min.js +3 -3
- package/package.json +24 -21
- package/skill/tutuca/cli.md +1 -1
- package/skill/tutuca/testing.md +5 -4
- package/skill/tutuca-source/tutuca.ext.js +1026 -1213
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
import { is } from "immutable";
|
|
3
3
|
|
|
4
4
|
// src/path.js
|
|
5
|
-
var NONE = Symbol("NONE");
|
|
6
|
-
|
|
7
|
-
class Step {
|
|
5
|
+
var NONE = /* @__PURE__ */ Symbol("NONE");
|
|
6
|
+
var Step = class {
|
|
8
7
|
lookup(_v, dval = null) {
|
|
9
8
|
return dval;
|
|
10
9
|
}
|
|
@@ -17,15 +16,19 @@ class Step {
|
|
|
17
16
|
toAbstractPathStep() {
|
|
18
17
|
return this;
|
|
19
18
|
}
|
|
19
|
+
// Freeze any field-resolved key against the value `v` entering this step (see
|
|
20
|
+
// `Path.pinKeys`). Most steps carry no live key and pin to themselves.
|
|
20
21
|
pinKey(_v) {
|
|
21
22
|
return this;
|
|
22
23
|
}
|
|
24
|
+
// A generic `{ field, key? }` descriptor for this step, or null for frame-only
|
|
25
|
+
// steps (binds) that address no field. Used by `Path.toKeys()` so tooling can
|
|
26
|
+
// introspect a path without reaching into Step subclasses.
|
|
23
27
|
toKey() {
|
|
24
28
|
return null;
|
|
25
29
|
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
class BindStep extends Step {
|
|
30
|
+
};
|
|
31
|
+
var BindStep = class _BindStep extends Step {
|
|
29
32
|
constructor(binds) {
|
|
30
33
|
super();
|
|
31
34
|
this.binds = binds;
|
|
@@ -40,17 +43,16 @@ class BindStep extends Step {
|
|
|
40
43
|
return stack.enter(next, { ...this.binds }, false);
|
|
41
44
|
}
|
|
42
45
|
withIndex(i) {
|
|
43
|
-
return new
|
|
46
|
+
return new _BindStep({ ...this.binds, key: i });
|
|
44
47
|
}
|
|
45
48
|
withKey(key) {
|
|
46
|
-
return new
|
|
49
|
+
return new _BindStep({ ...this.binds, key });
|
|
47
50
|
}
|
|
48
51
|
toAbstractPathStep() {
|
|
49
52
|
return null;
|
|
50
53
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class ScopeBindStep extends BindStep {
|
|
54
|
+
};
|
|
55
|
+
var ScopeBindStep = class _ScopeBindStep extends BindStep {
|
|
54
56
|
constructor(val, binds = {}) {
|
|
55
57
|
super(binds);
|
|
56
58
|
this.val = val;
|
|
@@ -60,14 +62,13 @@ class ScopeBindStep extends BindStep {
|
|
|
60
62
|
return stack.enter(next, { ...this.binds, ...dyn }, false);
|
|
61
63
|
}
|
|
62
64
|
withIndex(i) {
|
|
63
|
-
return new
|
|
65
|
+
return new _ScopeBindStep(this.val, { ...this.binds, key: i });
|
|
64
66
|
}
|
|
65
67
|
withKey(key) {
|
|
66
|
-
return new
|
|
68
|
+
return new _ScopeBindStep(this.val, { ...this.binds, key });
|
|
67
69
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
class FieldStep extends Step {
|
|
70
|
+
};
|
|
71
|
+
var FieldStep = class extends Step {
|
|
71
72
|
constructor(field) {
|
|
72
73
|
super();
|
|
73
74
|
this.field = field;
|
|
@@ -87,9 +88,8 @@ class FieldStep extends Step {
|
|
|
87
88
|
toKey() {
|
|
88
89
|
return { field: this.field };
|
|
89
90
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
class SeqStep extends Step {
|
|
91
|
+
};
|
|
92
|
+
var SeqStep = class extends Step {
|
|
93
93
|
constructor(field, key) {
|
|
94
94
|
super();
|
|
95
95
|
this.field = field;
|
|
@@ -109,9 +109,8 @@ class SeqStep extends Step {
|
|
|
109
109
|
toKey() {
|
|
110
110
|
return { field: this.field, key: this.key };
|
|
111
111
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
class SeqAccessStep extends Step {
|
|
112
|
+
};
|
|
113
|
+
var SeqAccessStep = class extends Step {
|
|
115
114
|
constructor(seqField, keyField) {
|
|
116
115
|
super();
|
|
117
116
|
this.seqField = seqField;
|
|
@@ -127,16 +126,20 @@ class SeqAccessStep extends Step {
|
|
|
127
126
|
const key = root?.get(this.keyField, NONE);
|
|
128
127
|
return seq === NONE || key === NONE ? root : root.set(this.seqField, seq.set(key, v));
|
|
129
128
|
}
|
|
129
|
+
// Resolve `keyField` against `v` now and freeze it as a literal-key `SeqStep`, so a
|
|
130
|
+
// later lookup/setValue lands on this same item even if `keyField` changes meanwhile.
|
|
130
131
|
pinKey(v) {
|
|
131
132
|
const key = v?.get(this.keyField, NONE);
|
|
132
133
|
return key === NONE ? this : new SeqStep(this.seqField, key);
|
|
133
134
|
}
|
|
135
|
+
// The key is a *field reference* resolved live, so it is unknown without a value;
|
|
136
|
+
// report the seq field (no key) rather than dropping the step, which would shift
|
|
137
|
+
// the indices of later keys. Call `Path.pinKeys(root)` first to get a concrete key.
|
|
134
138
|
toKey() {
|
|
135
139
|
return { field: this.seqField };
|
|
136
140
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
class EachBindStep extends Step {
|
|
141
|
+
};
|
|
142
|
+
var EachBindStep = class extends Step {
|
|
140
143
|
constructor(iterInfo, key) {
|
|
141
144
|
super();
|
|
142
145
|
this.iterInfo = iterInfo;
|
|
@@ -148,33 +151,34 @@ class EachBindStep extends Step {
|
|
|
148
151
|
setValue(_root, v) {
|
|
149
152
|
return v;
|
|
150
153
|
}
|
|
154
|
+
// Replay the renderer's per-item binds (key, value + any @enrich-with binds)
|
|
155
|
+
// so a rebuilt stack matches the one @each rendered with.
|
|
151
156
|
enterFrame(stack, _prev, next) {
|
|
152
157
|
return stack.enter(next, this.iterInfo.enrichBinds(stack, this.key), false);
|
|
153
158
|
}
|
|
154
159
|
toAbstractPathStep() {
|
|
155
160
|
return null;
|
|
156
161
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
class EachRenderItStep extends SeqStep {
|
|
162
|
+
};
|
|
163
|
+
var EachRenderItStep = class extends SeqStep {
|
|
160
164
|
enterFrame(stack, _prev, next) {
|
|
161
165
|
return stack.enter(next, { key: this.key, value: next }, false).enter(next, {}, true);
|
|
162
166
|
}
|
|
163
167
|
toAbstractPathStep() {
|
|
164
168
|
return new SeqStep(this.field, this.key);
|
|
165
169
|
}
|
|
166
|
-
}
|
|
170
|
+
};
|
|
167
171
|
function warnRawDynStep(op, step) {
|
|
168
172
|
console.warn(`Path.${op} reached a DynStep: call toTransactionPath() first`, step);
|
|
169
173
|
}
|
|
170
|
-
|
|
171
|
-
class DynStep extends Step {
|
|
174
|
+
var DynStep = class extends Step {
|
|
172
175
|
constructor(producerCompId, producerSteps) {
|
|
173
176
|
super();
|
|
174
177
|
this.producerCompId = producerCompId;
|
|
175
178
|
this.producerSteps = producerSteps;
|
|
176
|
-
this.interiorCids = new Set;
|
|
179
|
+
this.interiorCids = /* @__PURE__ */ new Set();
|
|
177
180
|
}
|
|
181
|
+
// Steps spliced into the transaction path in place of this marker.
|
|
178
182
|
teleportSteps() {
|
|
179
183
|
return this.producerSteps;
|
|
180
184
|
}
|
|
@@ -190,17 +194,15 @@ class DynStep extends Step {
|
|
|
190
194
|
warnRawDynStep("enterFrame", this);
|
|
191
195
|
return stack;
|
|
192
196
|
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
class DynEachStep extends DynStep {
|
|
197
|
+
};
|
|
198
|
+
var DynEachStep = class extends DynStep {
|
|
196
199
|
constructor(producerCompId, producerSteps, key) {
|
|
197
200
|
super(producerCompId, producerSteps);
|
|
198
201
|
this.key = key;
|
|
199
202
|
}
|
|
200
203
|
teleportSteps() {
|
|
201
204
|
const { producerSteps, key } = this;
|
|
202
|
-
if (producerSteps.length === 0)
|
|
203
|
-
return producerSteps;
|
|
205
|
+
if (producerSteps.length === 0) return producerSteps;
|
|
204
206
|
const last = producerSteps[producerSteps.length - 1];
|
|
205
207
|
if (!(last instanceof FieldStep)) {
|
|
206
208
|
console.warn("DynEachStep: seq-access dynamic cannot be iterated", this);
|
|
@@ -208,30 +210,34 @@ class DynEachStep extends DynStep {
|
|
|
208
210
|
}
|
|
209
211
|
return producerSteps.slice(0, -1).concat(new SeqStep(last.field, key));
|
|
210
212
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
class Path {
|
|
213
|
+
};
|
|
214
|
+
var Path = class _Path {
|
|
214
215
|
constructor(steps = []) {
|
|
215
216
|
this.steps = steps;
|
|
216
217
|
}
|
|
217
218
|
concat(steps) {
|
|
218
|
-
return new
|
|
219
|
+
return new _Path(this.steps.concat(steps));
|
|
219
220
|
}
|
|
220
221
|
popStep() {
|
|
221
|
-
return new
|
|
222
|
+
return new _Path(this.steps.slice(0, -1));
|
|
222
223
|
}
|
|
224
|
+
// The dispatch path: frame-only steps removed, one step per crossed component
|
|
225
|
+
// (DynStep included). `popStep` over it bubbles through every component.
|
|
223
226
|
compact() {
|
|
224
227
|
const out = [];
|
|
225
228
|
for (const step of this.steps) {
|
|
226
229
|
const s = step.toAbstractPathStep();
|
|
227
230
|
if (s !== null) {
|
|
228
|
-
if (s !== step)
|
|
229
|
-
s._originCid = step._originCid;
|
|
231
|
+
if (s !== step) s._originCid = step._originCid;
|
|
230
232
|
out.push(s);
|
|
231
233
|
}
|
|
232
234
|
}
|
|
233
|
-
return new
|
|
235
|
+
return new _Path(out);
|
|
234
236
|
}
|
|
237
|
+
// The abstract path used to apply a transaction: every DynStep is teleported —
|
|
238
|
+
// the steps interior to its producer..consumer span are dropped and the
|
|
239
|
+
// producer's own path spliced in — so a mutation lands on the data's real
|
|
240
|
+
// location. A path with no DynStep is returned unchanged.
|
|
235
241
|
toTransactionPath() {
|
|
236
242
|
let hasDyn = false;
|
|
237
243
|
for (const step of this.steps)
|
|
@@ -239,76 +245,80 @@ class Path {
|
|
|
239
245
|
hasDyn = true;
|
|
240
246
|
break;
|
|
241
247
|
}
|
|
242
|
-
if (!hasDyn)
|
|
243
|
-
return this;
|
|
248
|
+
if (!hasDyn) return this;
|
|
244
249
|
const out = [];
|
|
245
250
|
for (const step of this.steps) {
|
|
246
251
|
if (step instanceof DynStep) {
|
|
247
|
-
while (out.length > 0 && step.interiorCids.has(out[out.length - 1]._originCid))
|
|
248
|
-
out.pop();
|
|
252
|
+
while (out.length > 0 && step.interiorCids.has(out[out.length - 1]._originCid)) out.pop();
|
|
249
253
|
for (const ts of step.teleportSteps()) {
|
|
250
254
|
ts._originCid = step.producerCompId;
|
|
251
255
|
out.push(ts);
|
|
252
256
|
}
|
|
253
|
-
} else
|
|
254
|
-
out.push(step);
|
|
257
|
+
} else out.push(step);
|
|
255
258
|
}
|
|
256
|
-
return new
|
|
259
|
+
return new _Path(out);
|
|
257
260
|
}
|
|
261
|
+
// Resolve every field-keyed step (e.g. `SeqAccessStep`) against `root`, freezing the
|
|
262
|
+
// key as it is *now* so a later lookup/setValue lands on the same item even if the
|
|
263
|
+
// keyField changed meanwhile (e.g. the selected tab moved while a request was in
|
|
264
|
+
// flight). Returns a new Path with those steps replaced; `this` if nothing pinned.
|
|
265
|
+
// Must be called on a transaction path (no DynSteps — call toTransactionPath first).
|
|
258
266
|
pinKeys(root) {
|
|
259
267
|
let curVal = root;
|
|
260
268
|
let out = null;
|
|
261
|
-
for (let i = 0;i < this.steps.length; i++) {
|
|
269
|
+
for (let i = 0; i < this.steps.length; i++) {
|
|
262
270
|
const step = this.steps[i];
|
|
263
271
|
const pinned = step.pinKey(curVal);
|
|
264
|
-
if (pinned !== step)
|
|
265
|
-
(out ??= this.steps.slice())[i] = pinned;
|
|
272
|
+
if (pinned !== step) (out ??= this.steps.slice())[i] = pinned;
|
|
266
273
|
curVal = step.lookup(curVal, NONE);
|
|
267
|
-
if (curVal === NONE)
|
|
268
|
-
break;
|
|
274
|
+
if (curVal === NONE) break;
|
|
269
275
|
}
|
|
270
|
-
return out ? new
|
|
276
|
+
return out ? new _Path(out) : this;
|
|
271
277
|
}
|
|
272
278
|
lookup(v, dval = null) {
|
|
273
279
|
let curVal = v;
|
|
274
280
|
for (const step of this.steps) {
|
|
275
281
|
curVal = step.lookup(curVal, NONE);
|
|
276
|
-
if (curVal === NONE)
|
|
277
|
-
return dval;
|
|
282
|
+
if (curVal === NONE) return dval;
|
|
278
283
|
}
|
|
279
284
|
return curVal;
|
|
280
285
|
}
|
|
286
|
+
// The values entered along the path, root→leaf (root included): index 0 is `root`,
|
|
287
|
+
// the last entry is the leaf this path resolves to. Stops early at the first
|
|
288
|
+
// unresolvable step. Call on a transaction path (no DynSteps). Used to walk the
|
|
289
|
+
// component instances on a dispatch path (filter via Components.getCompFor).
|
|
281
290
|
resolveChain(root) {
|
|
282
291
|
const out = [root];
|
|
283
292
|
let curVal = root;
|
|
284
293
|
for (const step of this.steps) {
|
|
285
294
|
curVal = step.lookup(curVal, NONE);
|
|
286
|
-
if (curVal === NONE)
|
|
287
|
-
break;
|
|
295
|
+
if (curVal === NONE) break;
|
|
288
296
|
out.push(curVal);
|
|
289
297
|
}
|
|
290
298
|
return out;
|
|
291
299
|
}
|
|
300
|
+
// A flat `[{ field, key? }]` list of the addressing steps, skipping frame-only
|
|
301
|
+
// steps (binds). Generic path introspection so tooling (e.g. the storybook
|
|
302
|
+
// activity log) can identify which subtree a transaction touched without
|
|
303
|
+
// depending on Step internals. Call on a transaction path (no DynSteps).
|
|
292
304
|
toKeys() {
|
|
293
305
|
const out = [];
|
|
294
306
|
for (const step of this.steps) {
|
|
295
307
|
const k = step.toKey();
|
|
296
|
-
if (k !== null)
|
|
297
|
-
out.push(k);
|
|
308
|
+
if (k !== null) out.push(k);
|
|
298
309
|
}
|
|
299
310
|
return out;
|
|
300
311
|
}
|
|
301
312
|
setValue(root, v) {
|
|
302
313
|
const intermediates = new Array(this.steps.length);
|
|
303
314
|
let curVal = root;
|
|
304
|
-
for (let i = 0;i < this.steps.length; i++) {
|
|
315
|
+
for (let i = 0; i < this.steps.length; i++) {
|
|
305
316
|
intermediates[i] = curVal;
|
|
306
317
|
curVal = this.steps[i].lookup(curVal, NONE);
|
|
307
|
-
if (curVal === NONE)
|
|
308
|
-
return root;
|
|
318
|
+
if (curVal === NONE) return root;
|
|
309
319
|
}
|
|
310
320
|
let newVal = v;
|
|
311
|
-
for (let i = this.steps.length - 1;i >= 0; i--) {
|
|
321
|
+
for (let i = this.steps.length - 1; i >= 0; i--) {
|
|
312
322
|
newVal = this.steps[i].setValue(intermediates[i], newVal);
|
|
313
323
|
intermediates[i] = newVal;
|
|
314
324
|
}
|
|
@@ -342,8 +352,7 @@ class Path {
|
|
|
342
352
|
if (handlers === null && (isLeafComponent || bubbles)) {
|
|
343
353
|
handlers = findHandlers(comp, eventIds, vid, eventName);
|
|
344
354
|
if (handlers === null) {
|
|
345
|
-
if (isLeafComponent && stopOnNoEvent && !bubbles)
|
|
346
|
-
return false;
|
|
355
|
+
if (isLeafComponent && stopOnNoEvent && !bubbles) return false;
|
|
347
356
|
} else if (!isLeafComponent) {
|
|
348
357
|
pathSteps.length = 0;
|
|
349
358
|
pendingDyns.length = 0;
|
|
@@ -351,8 +360,7 @@ class Path {
|
|
|
351
360
|
}
|
|
352
361
|
}
|
|
353
362
|
isLeafComponent = false;
|
|
354
|
-
for (const dyn of pendingDyns)
|
|
355
|
-
dyn.interiorCids.add(cidNum);
|
|
363
|
+
for (const dyn of pendingDyns) dyn.interiorCids.add(cidNum);
|
|
356
364
|
if (pushStep) {
|
|
357
365
|
const step = resolvePathStep(comp, nodeIds, vid);
|
|
358
366
|
if (step) {
|
|
@@ -364,9 +372,8 @@ class Path {
|
|
|
364
372
|
}
|
|
365
373
|
}
|
|
366
374
|
}
|
|
367
|
-
for (let i = pendingDyns.length - 1;i >= 0; i--)
|
|
368
|
-
if (pendingDyns[i].producerCompId === cidNum)
|
|
369
|
-
pendingDyns.splice(i, 1);
|
|
375
|
+
for (let i = pendingDyns.length - 1; i >= 0; i--)
|
|
376
|
+
if (pendingDyns[i].producerCompId === cidNum) pendingDyns.splice(i, 1);
|
|
370
377
|
eventIds = [];
|
|
371
378
|
nodeIds = [];
|
|
372
379
|
return true;
|
|
@@ -374,35 +381,32 @@ class Path {
|
|
|
374
381
|
while (node && node !== rootNode && depth < maxDepth) {
|
|
375
382
|
if (node?.dataset) {
|
|
376
383
|
const { eid, cid, vid } = node.dataset;
|
|
377
|
-
if (eid !==
|
|
378
|
-
eventIds.push(eid);
|
|
384
|
+
if (eid !== void 0) eventIds.push(eid);
|
|
379
385
|
const metas = metaChain(node.previousSibling);
|
|
380
386
|
let sawComp = false;
|
|
381
387
|
for (const m of metas) {
|
|
382
388
|
if (m.$ === "Comp") {
|
|
383
389
|
sawComp = true;
|
|
384
|
-
if (!crossComponent(m.cid, m.vid))
|
|
385
|
-
return NO_EVENT_INFO;
|
|
390
|
+
if (!crossComponent(m.cid, m.vid)) return NO_EVENT_INFO;
|
|
386
391
|
nodeIds.push({ nid: m.nid });
|
|
387
392
|
} else {
|
|
388
393
|
nodeIds.push({ nid: m.nid, si: m.si, sk: m.sk });
|
|
389
394
|
}
|
|
390
395
|
}
|
|
391
|
-
if (!sawComp && cid !==
|
|
392
|
-
return NO_EVENT_INFO;
|
|
396
|
+
if (!sawComp && cid !== void 0 && !crossComponent(+cid, vid)) return NO_EVENT_INFO;
|
|
393
397
|
}
|
|
394
398
|
depth += 1;
|
|
395
399
|
node = node.parentNode;
|
|
396
400
|
}
|
|
397
401
|
if (pendingDyns.length > 0)
|
|
398
402
|
console.warn("event reconstruction: dynamic-var producer not found", pendingDyns);
|
|
399
|
-
return [new
|
|
403
|
+
return [new _Path(pathSteps.reverse()), handlers];
|
|
400
404
|
}
|
|
401
405
|
static fromEvent(e, rNode, maxDepth, comps, stopOnNoEvent = true) {
|
|
402
406
|
const { type, target } = e;
|
|
403
|
-
return
|
|
407
|
+
return _Path.fromNodeAndEventName(target, type, rNode, maxDepth, comps, stopOnNoEvent);
|
|
404
408
|
}
|
|
405
|
-
}
|
|
409
|
+
};
|
|
406
410
|
function metaChain(n) {
|
|
407
411
|
const out = [];
|
|
408
412
|
while (n?.nodeType === 8 && n.textContent[0] === "§") {
|
|
@@ -418,13 +422,11 @@ function metaChain(n) {
|
|
|
418
422
|
function findHandlers(comp, eventIds, vid, eventName) {
|
|
419
423
|
for (const eid of eventIds) {
|
|
420
424
|
const handlers = comp.getEventForId(+eid, vid).getHandlersFor(eventName);
|
|
421
|
-
if (handlers !== null)
|
|
422
|
-
return handlers;
|
|
425
|
+
if (handlers !== null) return handlers;
|
|
423
426
|
}
|
|
424
427
|
return null;
|
|
425
428
|
}
|
|
426
|
-
|
|
427
|
-
class StepCtx {
|
|
429
|
+
var StepCtx = class _StepCtx {
|
|
428
430
|
constructor(comp, nodeIds, idx, vid) {
|
|
429
431
|
this.comp = comp;
|
|
430
432
|
this.nodeIds = nodeIds;
|
|
@@ -436,43 +438,38 @@ class StepCtx {
|
|
|
436
438
|
}
|
|
437
439
|
get key() {
|
|
438
440
|
const m = this.meta;
|
|
439
|
-
return m.si !==
|
|
441
|
+
return m.si !== void 0 ? +m.si : m.sk;
|
|
440
442
|
}
|
|
441
443
|
get hasKey() {
|
|
442
444
|
const m = this.meta;
|
|
443
|
-
return m.si !==
|
|
445
|
+
return m.si !== void 0 || m.sk !== void 0;
|
|
444
446
|
}
|
|
445
447
|
next() {
|
|
446
448
|
const { idx, nodeIds } = this;
|
|
447
|
-
return idx + 1 < nodeIds.length ? new
|
|
449
|
+
return idx + 1 < nodeIds.length ? new _StepCtx(this.comp, nodeIds, idx + 1, this.vid) : null;
|
|
448
450
|
}
|
|
449
451
|
resolveNode() {
|
|
450
452
|
return this.comp.getNodeForId(+this.meta.nid, this.vid);
|
|
451
453
|
}
|
|
452
454
|
applyKey(pi) {
|
|
453
|
-
if (pi === null)
|
|
454
|
-
return null;
|
|
455
|
+
if (pi === null) return null;
|
|
455
456
|
const m = this.meta;
|
|
456
|
-
if (m.si !==
|
|
457
|
-
|
|
458
|
-
if (m.sk !== undefined)
|
|
459
|
-
return pi.withKey(m.sk);
|
|
457
|
+
if (m.si !== void 0) return pi.withIndex(+m.si);
|
|
458
|
+
if (m.sk !== void 0) return pi.withKey(m.sk);
|
|
460
459
|
return pi;
|
|
461
460
|
}
|
|
462
|
-
}
|
|
461
|
+
};
|
|
463
462
|
function resolvePathStep(comp, nodeIds, vid) {
|
|
464
|
-
for (let i = 0;i < nodeIds.length; i++) {
|
|
463
|
+
for (let i = 0; i < nodeIds.length; i++) {
|
|
465
464
|
const ctx = new StepCtx(comp, nodeIds, i, vid);
|
|
466
465
|
const step = ctx.resolveNode().toPathStep(ctx);
|
|
467
|
-
if (step !== null)
|
|
468
|
-
return step;
|
|
466
|
+
if (step !== null) return step;
|
|
469
467
|
}
|
|
470
468
|
return null;
|
|
471
469
|
}
|
|
472
470
|
var NO_EVENT_INFO = [null, null];
|
|
473
|
-
var BUBBLING_EVENTS = new Set(["drop"]);
|
|
474
|
-
|
|
475
|
-
class PathBuilder {
|
|
471
|
+
var BUBBLING_EVENTS = /* @__PURE__ */ new Set(["drop"]);
|
|
472
|
+
var PathBuilder = class {
|
|
476
473
|
constructor() {
|
|
477
474
|
this.pathChanges = [];
|
|
478
475
|
}
|
|
@@ -489,7 +486,7 @@ class PathBuilder {
|
|
|
489
486
|
key(name, key) {
|
|
490
487
|
return this.add(new SeqStep(name, key));
|
|
491
488
|
}
|
|
492
|
-
}
|
|
489
|
+
};
|
|
493
490
|
|
|
494
491
|
// src/value.js
|
|
495
492
|
var VALID_VAL_ID_RE = /^[a-zA-Z][a-zA-Z0-9_]*\??$/;
|
|
@@ -518,11 +515,9 @@ var G_FIELD = K_FIELD | K_METHOD | K_CONST | K_SEQ;
|
|
|
518
515
|
var G_VALUE = K_FIELD | K_METHOD | K_BIND | K_DYN | K_NAME | K_TYPE | K_CONST;
|
|
519
516
|
var G_ALL = G_VALUE | K_STRTPL | K_SEQ;
|
|
520
517
|
function sizeOf(v) {
|
|
521
|
-
if (v == null)
|
|
522
|
-
return null;
|
|
518
|
+
if (v == null) return null;
|
|
523
519
|
const s = v.size;
|
|
524
|
-
if (typeof s === "number")
|
|
525
|
-
return s;
|
|
520
|
+
if (typeof s === "number") return s;
|
|
526
521
|
const l = v.length;
|
|
527
522
|
return typeof l === "number" ? l : null;
|
|
528
523
|
}
|
|
@@ -537,209 +532,174 @@ var PREDICATES = {
|
|
|
537
532
|
"null?": { name: "null?", arity: 1, fn: (v) => v == null },
|
|
538
533
|
"equals?": { name: "equals?", arity: 2, fn: (a, b) => is(a, b) }
|
|
539
534
|
};
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
switch (c0) {
|
|
559
|
-
case 94: {
|
|
560
|
-
const name = s.slice(1);
|
|
561
|
-
const newS = px.frame.macroVars?.[name];
|
|
562
|
-
if (newS !== undefined) {
|
|
563
|
-
const tokens = tokenizeValue(newS.trim());
|
|
564
|
-
if (tokens.length !== 1)
|
|
565
|
-
return null;
|
|
566
|
-
const val = this.parseToken(tokens[0], px);
|
|
567
|
-
if (val instanceof ConstVal)
|
|
568
|
-
val.fromMacroVar = true;
|
|
569
|
-
return val;
|
|
570
|
-
}
|
|
571
|
-
px.onParseIssue("bad-value", { role: "macro-var", name, value: s });
|
|
572
|
-
return null;
|
|
573
|
-
}
|
|
574
|
-
case 36:
|
|
575
|
-
return mkVal(s.slice(1), MethodVal);
|
|
576
|
-
case 64: {
|
|
577
|
-
const dot = s.indexOf(".", 1);
|
|
578
|
-
if (dot === -1)
|
|
579
|
-
return mkVal(s.slice(1), BindVal);
|
|
580
|
-
const name = s.slice(1, dot);
|
|
581
|
-
const member = s.slice(dot + 1);
|
|
582
|
-
return isValidValId(name) && isValidValId(member) ? new BindMemberVal(name, member) : null;
|
|
535
|
+
function parseToken(s, px) {
|
|
536
|
+
const c0 = s.charCodeAt(0);
|
|
537
|
+
if (c0 === 39)
|
|
538
|
+
return s.length >= 2 && s.charCodeAt(s.length - 1) === 39 ? new ConstVal(unescapeStr(s.slice(1, -1))) : null;
|
|
539
|
+
if (c0 === 36 && s.charCodeAt(1) === 39)
|
|
540
|
+
return s.length >= 3 && s.charCodeAt(s.length - 1) === 39 ? StrTplVal.parse(s.slice(2, -1), px) : null;
|
|
541
|
+
if (s.indexOf("[") !== -1 || s.indexOf("]") !== -1) return _parseSeqAccess(s, px);
|
|
542
|
+
if (s.indexOf("{") !== -1 || s.indexOf("}") !== -1) return null;
|
|
543
|
+
switch (c0) {
|
|
544
|
+
case 94: {
|
|
545
|
+
const name = s.slice(1);
|
|
546
|
+
const newS = px.frame.macroVars?.[name];
|
|
547
|
+
if (newS !== void 0) {
|
|
548
|
+
const tokens = tokenizeValue(newS.trim());
|
|
549
|
+
if (tokens.length !== 1) return null;
|
|
550
|
+
const val = parseToken(tokens[0], px);
|
|
551
|
+
if (val instanceof ConstVal) val.fromMacroVar = true;
|
|
552
|
+
return val;
|
|
583
553
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
554
|
+
px.onParseIssue("bad-value", { role: "macro-var", name, value: s });
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
case 36:
|
|
558
|
+
return mkVal(s.slice(1), MethodVal);
|
|
559
|
+
case 64: {
|
|
560
|
+
const dot = s.indexOf(".", 1);
|
|
561
|
+
if (dot === -1) return mkVal(s.slice(1), BindVal);
|
|
562
|
+
const name = s.slice(1, dot);
|
|
563
|
+
const member = s.slice(dot + 1);
|
|
564
|
+
return isValidValId(name) && isValidValId(member) ? new BindMemberVal(name, member) : null;
|
|
588
565
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
566
|
+
case 42:
|
|
567
|
+
return mkVal(s.slice(1), DynVal);
|
|
568
|
+
case 46:
|
|
569
|
+
return mkVal(s.slice(1), FieldVal);
|
|
570
|
+
}
|
|
571
|
+
const num = VALID_FLOAT_RE.test(s) ? parseFloat(s) : null;
|
|
572
|
+
if (Number.isFinite(num)) return new ConstVal(num);
|
|
573
|
+
if (s === "true" || s === "false") return new ConstVal(s === "true");
|
|
574
|
+
if (c0 >= 97 && c0 <= 122) return mkVal(s, NameVal);
|
|
575
|
+
if (c0 >= 65 && c0 <= 90) return mkVal(s, TypeVal);
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
function _parseSeqAccess(s, px) {
|
|
579
|
+
const open = s.indexOf("[");
|
|
580
|
+
const close = s.indexOf("]");
|
|
581
|
+
if (open < 1 || close !== s.length - 1 || close < open || s.indexOf("[", open + 1) !== -1)
|
|
582
|
+
return null;
|
|
583
|
+
const left = parseToken(s.slice(0, open), px);
|
|
584
|
+
const right = parseToken(s.slice(open + 1, close), px);
|
|
585
|
+
return left instanceof FieldVal && right instanceof FieldVal ? new SeqAccessVal(left, right) : null;
|
|
586
|
+
}
|
|
587
|
+
function _parseSingle(s, px, group) {
|
|
588
|
+
const tokens = tokenizeValue(s.trim());
|
|
589
|
+
if (tokens.length !== 1) return null;
|
|
590
|
+
const val = parseToken(tokens[0], px);
|
|
591
|
+
return val !== null && kindOf(val) & group ? val : null;
|
|
592
|
+
}
|
|
593
|
+
function parseBool(s, px) {
|
|
594
|
+
const t = s.trim();
|
|
595
|
+
const tokens = tokenizeValue(t);
|
|
596
|
+
if (tokens.length !== 1) return tokens.length === 0 ? null : _parsePredicate(t, tokens, px);
|
|
597
|
+
const val = parseToken(tokens[0], px);
|
|
598
|
+
return val !== null && kindOf(val) & G_BOOL ? val : null;
|
|
599
|
+
}
|
|
600
|
+
function parseText(s, px) {
|
|
601
|
+
return _parseSingle(s, px, G_TEXT);
|
|
602
|
+
}
|
|
603
|
+
function parseComponent(s, px) {
|
|
604
|
+
return _parseSingle(s, px, G_COMPONENT);
|
|
605
|
+
}
|
|
606
|
+
function parseSequence(s, px) {
|
|
607
|
+
return _parseSingle(s, px, G_SEQUENCE);
|
|
608
|
+
}
|
|
609
|
+
function parseField(s, px) {
|
|
610
|
+
return _parseSingle(s, px, G_FIELD);
|
|
611
|
+
}
|
|
612
|
+
function parseProvide(s, px) {
|
|
613
|
+
return _parseSingle(s, px, G_PROVIDE);
|
|
614
|
+
}
|
|
615
|
+
function parseMacroAttr(s, px) {
|
|
616
|
+
return _parseSingle(s, px, G_ALL);
|
|
617
|
+
}
|
|
618
|
+
function parseInputHandler(s, px) {
|
|
619
|
+
return _parseHandler(s, px, "input", true, true);
|
|
620
|
+
}
|
|
621
|
+
function parseAlterHandler(s, px) {
|
|
622
|
+
const r = _parseHandler(s, px, "alter", false, false);
|
|
623
|
+
return r === null ? null : r.handlerVal;
|
|
624
|
+
}
|
|
625
|
+
function _parseHandler(s, px, namespace, allowArgs, report) {
|
|
626
|
+
const tokens = tokenizeValue(s.trim());
|
|
627
|
+
const headTok = tokens[0] ?? "";
|
|
628
|
+
const head = headTok === "" ? null : parseToken(headTok, px);
|
|
629
|
+
const hk = kindOf(head);
|
|
630
|
+
let handlerVal;
|
|
631
|
+
if (hk & K_METHOD) handlerVal = head;
|
|
632
|
+
else if (hk & K_NAME) handlerVal = new HandlerNameVal(head.name, namespace);
|
|
633
|
+
else {
|
|
634
|
+
if (report) px.onParseIssue("bad-value", { role: "handler-name", value: headTok });
|
|
598
635
|
return null;
|
|
599
636
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const left = this.parseToken(s.slice(0, open), px);
|
|
606
|
-
const right = this.parseToken(s.slice(open + 1, close), px);
|
|
607
|
-
return left instanceof FieldVal && right instanceof FieldVal ? new SeqAccessVal(left, right) : null;
|
|
608
|
-
}
|
|
609
|
-
_parseSingle(s, px, group) {
|
|
610
|
-
const tokens = tokenizeValue(s.trim());
|
|
611
|
-
if (tokens.length !== 1)
|
|
612
|
-
return null;
|
|
613
|
-
const val = this.parseToken(tokens[0], px);
|
|
614
|
-
return val !== null && kindOf(val) & group ? val : null;
|
|
615
|
-
}
|
|
616
|
-
parseBool(s, px) {
|
|
617
|
-
const t = s.trim();
|
|
618
|
-
const tokens = tokenizeValue(t);
|
|
619
|
-
if (tokens.length !== 1)
|
|
620
|
-
return tokens.length === 0 ? null : this._parsePredicate(t, tokens, px);
|
|
621
|
-
const val = this.parseToken(tokens[0], px);
|
|
622
|
-
return val !== null && kindOf(val) & G_BOOL ? val : null;
|
|
623
|
-
}
|
|
624
|
-
parseText(s, px) {
|
|
625
|
-
return this._parseSingle(s, px, G_TEXT);
|
|
626
|
-
}
|
|
627
|
-
parseComponent(s, px) {
|
|
628
|
-
return this._parseSingle(s, px, G_COMPONENT);
|
|
629
|
-
}
|
|
630
|
-
parseSequence(s, px) {
|
|
631
|
-
return this._parseSingle(s, px, G_SEQUENCE);
|
|
632
|
-
}
|
|
633
|
-
parseField(s, px) {
|
|
634
|
-
return this._parseSingle(s, px, G_FIELD);
|
|
635
|
-
}
|
|
636
|
-
parseProvide(s, px) {
|
|
637
|
-
return this._parseSingle(s, px, G_PROVIDE);
|
|
638
|
-
}
|
|
639
|
-
parseHandlerArg(s, px) {
|
|
640
|
-
return this._parseSingle(s, px, G_VALUE);
|
|
641
|
-
}
|
|
642
|
-
parseMacroAttr(s, px) {
|
|
643
|
-
return this._parseSingle(s, px, G_ALL);
|
|
644
|
-
}
|
|
645
|
-
parseInputHandler(s, px) {
|
|
646
|
-
return this._parseHandler(s, px, "input", true, true);
|
|
647
|
-
}
|
|
648
|
-
parseAlterHandler(s, px) {
|
|
649
|
-
const r = this._parseHandler(s, px, "alter", false, false);
|
|
650
|
-
return r === null ? null : r.handlerVal;
|
|
651
|
-
}
|
|
652
|
-
_parseHandler(s, px, namespace, allowArgs, report) {
|
|
653
|
-
const tokens = tokenizeValue(s.trim());
|
|
654
|
-
const headTok = tokens[0] ?? "";
|
|
655
|
-
const head = headTok === "" ? null : this.parseToken(headTok, px);
|
|
656
|
-
const hk = kindOf(head);
|
|
657
|
-
let handlerVal;
|
|
658
|
-
if (hk & K_METHOD)
|
|
659
|
-
handlerVal = head;
|
|
660
|
-
else if (hk & K_NAME)
|
|
661
|
-
handlerVal = new HandlerNameVal(head.name, namespace);
|
|
637
|
+
if (!allowArgs) return tokens.length === 1 ? { handlerVal, args: [] } : null;
|
|
638
|
+
const args = new Array(tokens.length - 1);
|
|
639
|
+
for (let i = 1; i < tokens.length; i++) {
|
|
640
|
+
const val = parseToken(tokens[i], px);
|
|
641
|
+
if (val !== null && kindOf(val) & G_VALUE) args[i - 1] = val;
|
|
662
642
|
else {
|
|
663
|
-
if (report)
|
|
664
|
-
|
|
665
|
-
return null;
|
|
666
|
-
}
|
|
667
|
-
if (!allowArgs)
|
|
668
|
-
return tokens.length === 1 ? { handlerVal, args: [] } : null;
|
|
669
|
-
const args = new Array(tokens.length - 1);
|
|
670
|
-
for (let i = 1;i < tokens.length; i++) {
|
|
671
|
-
const val = this.parseToken(tokens[i], px);
|
|
672
|
-
if (val !== null && kindOf(val) & G_VALUE)
|
|
673
|
-
args[i - 1] = val;
|
|
674
|
-
else {
|
|
675
|
-
if (report)
|
|
676
|
-
px.onParseIssue("bad-value", { role: "handler-arg", value: tokens[i] });
|
|
677
|
-
args[i - 1] = this.nullConstVal;
|
|
678
|
-
}
|
|
643
|
+
if (report) px.onParseIssue("bad-value", { role: "handler-arg", value: tokens[i] });
|
|
644
|
+
args[i - 1] = NULL_CONST_VAL;
|
|
679
645
|
}
|
|
680
|
-
return { handlerVal, args };
|
|
681
646
|
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
647
|
+
return { handlerVal, args };
|
|
648
|
+
}
|
|
649
|
+
function _parsePredicate(s, tokens, px) {
|
|
650
|
+
const predName = tokens[0];
|
|
651
|
+
const pred = PREDICATES[predName];
|
|
652
|
+
if (pred === void 0) {
|
|
653
|
+
px.onParseIssue("bad-value", { role: "predicate", value: predName });
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
const arity = tokens.length - 1;
|
|
657
|
+
if (arity !== pred.arity) {
|
|
658
|
+
px.onParseIssue("bad-value", { role: "predicate-arity", value: s, predicate: predName });
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
const args = new Array(arity);
|
|
662
|
+
for (let i = 0; i < arity; i++) {
|
|
663
|
+
const tok = tokens[i + 1];
|
|
664
|
+
const val = parseToken(tok, px);
|
|
665
|
+
if (val === null || !(kindOf(val) & G_BOOL)) {
|
|
666
|
+
px.onParseIssue("bad-value", { role: "predicate-arg", value: tok });
|
|
692
667
|
return null;
|
|
693
668
|
}
|
|
694
|
-
|
|
695
|
-
for (let i = 0;i < arity; i++) {
|
|
696
|
-
const tok = tokens[i + 1];
|
|
697
|
-
const val = this.parseToken(tok, px);
|
|
698
|
-
if (val === null || !(kindOf(val) & G_BOOL)) {
|
|
699
|
-
px.onParseIssue("bad-value", { role: "predicate-arg", value: tok });
|
|
700
|
-
return null;
|
|
701
|
-
}
|
|
702
|
-
args[i] = val;
|
|
703
|
-
}
|
|
704
|
-
return new PredicateVal(pred, args);
|
|
669
|
+
args[i] = val;
|
|
705
670
|
}
|
|
671
|
+
return new PredicateVal(pred, args);
|
|
706
672
|
}
|
|
707
673
|
function kindOf(val) {
|
|
708
|
-
if (val === null)
|
|
709
|
-
|
|
710
|
-
if (val instanceof
|
|
711
|
-
|
|
712
|
-
if (val instanceof
|
|
713
|
-
|
|
714
|
-
if (val instanceof
|
|
715
|
-
|
|
716
|
-
if (val instanceof
|
|
717
|
-
|
|
718
|
-
if (val instanceof MethodVal)
|
|
719
|
-
return K_METHOD;
|
|
720
|
-
if (val instanceof BindVal)
|
|
721
|
-
return K_BIND;
|
|
722
|
-
if (val instanceof DynVal)
|
|
723
|
-
return K_DYN;
|
|
724
|
-
if (val instanceof TypeVal)
|
|
725
|
-
return K_TYPE;
|
|
726
|
-
if (val instanceof NameVal)
|
|
727
|
-
return K_NAME;
|
|
674
|
+
if (val === null) return 0;
|
|
675
|
+
if (val instanceof ConstVal) return val.kind;
|
|
676
|
+
if (val instanceof StrTplVal) return val.kind;
|
|
677
|
+
if (val instanceof SeqAccessVal) return K_SEQ;
|
|
678
|
+
if (val instanceof FieldVal) return K_FIELD;
|
|
679
|
+
if (val instanceof MethodVal) return K_METHOD;
|
|
680
|
+
if (val instanceof BindVal) return K_BIND;
|
|
681
|
+
if (val instanceof DynVal) return K_DYN;
|
|
682
|
+
if (val instanceof TypeVal) return K_TYPE;
|
|
683
|
+
if (val instanceof NameVal) return K_NAME;
|
|
728
684
|
return 0;
|
|
729
685
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
eval(_stack) {
|
|
686
|
+
var BaseVal = class {
|
|
687
|
+
render(_stack, _rx) {
|
|
688
|
+
}
|
|
689
|
+
eval(_stack) {
|
|
690
|
+
}
|
|
734
691
|
toPathItem() {
|
|
735
692
|
return null;
|
|
736
693
|
}
|
|
694
|
+
// Value of this expression when it sits in handler position (`@on.<event>`,
|
|
695
|
+
// `@when`, `@enrich-with`, `@loop-with`): the dispatch machinery calls the
|
|
696
|
+
// result with the event args. Defaults to `eval`; `MethodVal` overrides it
|
|
697
|
+
// to hand back the raw function instead of invoking it.
|
|
737
698
|
evalAsHandler(stack) {
|
|
738
699
|
return this.eval(stack);
|
|
739
700
|
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
class ConstVal extends BaseVal {
|
|
701
|
+
};
|
|
702
|
+
var ConstVal = class extends BaseVal {
|
|
743
703
|
constructor(val, kind = K_CONST) {
|
|
744
704
|
super();
|
|
745
705
|
this.val = val;
|
|
@@ -755,9 +715,9 @@ class ConstVal extends BaseVal {
|
|
|
755
715
|
const v = this.val;
|
|
756
716
|
return typeof v === "string" ? `'${v.replace(/(['\\])/g, "\\$1")}'` : `${v}`;
|
|
757
717
|
}
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
|
|
718
|
+
};
|
|
719
|
+
var NULL_CONST_VAL = new ConstVal(null);
|
|
720
|
+
var PredicateVal = class extends BaseVal {
|
|
761
721
|
constructor(pred, args) {
|
|
762
722
|
super();
|
|
763
723
|
this.pred = pred;
|
|
@@ -766,28 +726,26 @@ class PredicateVal extends BaseVal {
|
|
|
766
726
|
eval(stack) {
|
|
767
727
|
const n = this.args.length;
|
|
768
728
|
const vals = new Array(n);
|
|
769
|
-
for (let i = 0;i < n; i++)
|
|
770
|
-
vals[i] = this.args[i].eval(stack);
|
|
729
|
+
for (let i = 0; i < n; i++) vals[i] = this.args[i].eval(stack);
|
|
771
730
|
return this.pred.fn(...vals);
|
|
772
731
|
}
|
|
773
732
|
toString() {
|
|
774
733
|
return `${this.pred.name} ${this.args.map(String).join(" ")}`;
|
|
775
734
|
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
class StrTplVal extends VarVal {
|
|
735
|
+
};
|
|
736
|
+
var VarVal = class extends BaseVal {
|
|
737
|
+
};
|
|
738
|
+
var StrTplVal = class _StrTplVal extends VarVal {
|
|
782
739
|
constructor(vals) {
|
|
783
740
|
super();
|
|
784
741
|
this.vals = vals;
|
|
785
742
|
this.kind = this.isLiteral() ? K_CONST : K_STRTPL;
|
|
786
743
|
}
|
|
744
|
+
// True when this template carries no dynamic placeholder: every part is a
|
|
745
|
+
// plain `ConstVal` and none was bound from a macro variable (the macro
|
|
746
|
+
// placeholder is real in the body even when it resolved to a constant).
|
|
787
747
|
isLiteral() {
|
|
788
|
-
for (const v of this.vals)
|
|
789
|
-
if (!(v instanceof ConstVal) || v.fromMacroVar)
|
|
790
|
-
return false;
|
|
748
|
+
for (const v of this.vals) if (!(v instanceof ConstVal) || v.fromMacroVar) return false;
|
|
791
749
|
return true;
|
|
792
750
|
}
|
|
793
751
|
render(stack, _rx) {
|
|
@@ -795,38 +753,41 @@ class StrTplVal extends VarVal {
|
|
|
795
753
|
}
|
|
796
754
|
eval(stack) {
|
|
797
755
|
const strs = new Array(this.vals.length);
|
|
798
|
-
for (let i = 0;i < this.vals.length; i++)
|
|
799
|
-
strs[i] = this.vals[i]?.eval(stack, "");
|
|
756
|
+
for (let i = 0; i < this.vals.length; i++) strs[i] = this.vals[i]?.eval(stack, "");
|
|
800
757
|
return strs.join("");
|
|
801
758
|
}
|
|
759
|
+
// When this is a placeholderless literal (see `isLiteral`), returns the
|
|
760
|
+
// string it spells out, in `'…'` source form; otherwise null. The linter
|
|
761
|
+
// uses this to nudge `$'foo'` → `'foo'` (PLACEHOLDERLESS_TEMPLATE_STRING).
|
|
802
762
|
toLiteralSource() {
|
|
803
|
-
if (!this.isLiteral())
|
|
804
|
-
return null;
|
|
763
|
+
if (!this.isLiteral()) return null;
|
|
805
764
|
let out = "";
|
|
806
|
-
for (const v of this.vals)
|
|
807
|
-
out += v.val;
|
|
765
|
+
for (const v of this.vals) out += v.val;
|
|
808
766
|
return new ConstVal(out).toString();
|
|
809
767
|
}
|
|
768
|
+
// `s` is the interior of a `$'…'` template (the text between `$'` and `'`).
|
|
769
|
+
// The interior is unescaped once (`\'`, `\\`) then split on `{…}` groups:
|
|
770
|
+
// text between them becomes a `ConstVal`, expressions inside braces are
|
|
771
|
+
// parsed via `parseText`. A constant-only template is left as a `StrTplVal`
|
|
772
|
+
// (not folded to a `ConstVal`) so the linter can flag it — see
|
|
773
|
+
// `toLiteralSource` and the PLACEHOLDERLESS_TEMPLATE_STRING lint rule.
|
|
810
774
|
static parse(s, px) {
|
|
811
775
|
const parts = unescapeStr(s).split(STR_TPL_SPLIT_RE);
|
|
812
776
|
const vals = new Array(parts.length);
|
|
813
|
-
for (let i = 0;i < parts.length; i++) {
|
|
777
|
+
for (let i = 0; i < parts.length; i++) {
|
|
814
778
|
const part = parts[i];
|
|
815
779
|
const isExpr = part[0] === "{" && part.at(-1) === "}";
|
|
816
|
-
vals[i] = isExpr ?
|
|
780
|
+
vals[i] = isExpr ? parseText(part.slice(1, -1), px) : new ConstVal(part);
|
|
817
781
|
}
|
|
818
782
|
let lo = 0;
|
|
819
783
|
let hi = vals.length;
|
|
820
784
|
const isTrimmable = (v) => v instanceof ConstVal && v.val === "" && !v.fromMacroVar;
|
|
821
|
-
while (lo < hi && isTrimmable(vals[lo]))
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
hi--;
|
|
825
|
-
return new StrTplVal(lo === 0 && hi === vals.length ? vals : vals.slice(lo, hi));
|
|
785
|
+
while (lo < hi && isTrimmable(vals[lo])) lo++;
|
|
786
|
+
while (hi > lo && isTrimmable(vals[hi - 1])) hi--;
|
|
787
|
+
return new _StrTplVal(lo === 0 && hi === vals.length ? vals : vals.slice(lo, hi));
|
|
826
788
|
}
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
class NameVal extends VarVal {
|
|
789
|
+
};
|
|
790
|
+
var NameVal = class extends VarVal {
|
|
830
791
|
constructor(name) {
|
|
831
792
|
super();
|
|
832
793
|
this.name = name;
|
|
@@ -837,9 +798,8 @@ class NameVal extends VarVal {
|
|
|
837
798
|
toString() {
|
|
838
799
|
return this.name;
|
|
839
800
|
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
class HandlerNameVal extends NameVal {
|
|
801
|
+
};
|
|
802
|
+
var HandlerNameVal = class extends NameVal {
|
|
843
803
|
constructor(name, namespace) {
|
|
844
804
|
super(name);
|
|
845
805
|
this.namespace = namespace;
|
|
@@ -847,41 +807,36 @@ class HandlerNameVal extends NameVal {
|
|
|
847
807
|
eval(stack) {
|
|
848
808
|
return stack.getHandlerFor(this.name, this.namespace) ?? mk404Handler(this.namespace, this.name);
|
|
849
809
|
}
|
|
850
|
-
}
|
|
810
|
+
};
|
|
851
811
|
var mk404Handler = (type, name) => function(...args) {
|
|
852
812
|
console.warn("handler not found", { type, name, args }, this);
|
|
853
813
|
return this;
|
|
854
814
|
};
|
|
855
|
-
|
|
856
|
-
class TypeVal extends NameVal {
|
|
815
|
+
var TypeVal = class extends NameVal {
|
|
857
816
|
eval(stack) {
|
|
858
817
|
return stack.lookupType(this.name);
|
|
859
818
|
}
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
class RenderVal extends BaseVal {
|
|
819
|
+
};
|
|
820
|
+
var RenderVal = class extends BaseVal {
|
|
863
821
|
render(stack, _rx) {
|
|
864
822
|
return this.eval(stack);
|
|
865
823
|
}
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
class RenderNameVal extends RenderVal {
|
|
824
|
+
};
|
|
825
|
+
var RenderNameVal = class extends RenderVal {
|
|
869
826
|
constructor(name) {
|
|
870
827
|
super();
|
|
871
828
|
this.name = name;
|
|
872
829
|
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
class BindVal extends RenderNameVal {
|
|
830
|
+
};
|
|
831
|
+
var BindVal = class extends RenderNameVal {
|
|
876
832
|
eval(stack) {
|
|
877
833
|
return stack.lookupBind(this.name);
|
|
878
834
|
}
|
|
879
835
|
toString() {
|
|
880
836
|
return `@${this.name}`;
|
|
881
837
|
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
class BindMemberVal extends BindVal {
|
|
838
|
+
};
|
|
839
|
+
var BindMemberVal = class extends BindVal {
|
|
885
840
|
constructor(name, member) {
|
|
886
841
|
super(name);
|
|
887
842
|
this.member = member;
|
|
@@ -893,18 +848,16 @@ class BindMemberVal extends BindVal {
|
|
|
893
848
|
toString() {
|
|
894
849
|
return `@${this.name}.${this.member}`;
|
|
895
850
|
}
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
class DynVal extends RenderNameVal {
|
|
851
|
+
};
|
|
852
|
+
var DynVal = class extends RenderNameVal {
|
|
899
853
|
eval(stack) {
|
|
900
854
|
return stack.lookupDynamic(this.name);
|
|
901
855
|
}
|
|
902
856
|
toString() {
|
|
903
857
|
return `*${this.name}`;
|
|
904
858
|
}
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
class FieldVal extends RenderNameVal {
|
|
859
|
+
};
|
|
860
|
+
var FieldVal = class extends RenderNameVal {
|
|
908
861
|
eval(stack) {
|
|
909
862
|
return stack.lookupFieldRaw(this.name);
|
|
910
863
|
}
|
|
@@ -914,9 +867,8 @@ class FieldVal extends RenderNameVal {
|
|
|
914
867
|
toString() {
|
|
915
868
|
return `.${this.name}`;
|
|
916
869
|
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
class MethodVal extends RenderNameVal {
|
|
870
|
+
};
|
|
871
|
+
var MethodVal = class extends RenderNameVal {
|
|
920
872
|
eval(stack) {
|
|
921
873
|
return stack.lookupMethod(this.name);
|
|
922
874
|
}
|
|
@@ -926,9 +878,8 @@ class MethodVal extends RenderNameVal {
|
|
|
926
878
|
toString() {
|
|
927
879
|
return `$${this.name}`;
|
|
928
880
|
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
class SeqAccessVal extends RenderVal {
|
|
881
|
+
};
|
|
882
|
+
var SeqAccessVal = class extends RenderVal {
|
|
932
883
|
constructor(seqVal, keyVal) {
|
|
933
884
|
super();
|
|
934
885
|
this.seqVal = seqVal;
|
|
@@ -944,11 +895,10 @@ class SeqAccessVal extends RenderVal {
|
|
|
944
895
|
toString() {
|
|
945
896
|
return `${this.seqVal}[${this.keyVal}]`;
|
|
946
897
|
}
|
|
947
|
-
}
|
|
948
|
-
var vp = new ValParser;
|
|
898
|
+
};
|
|
949
899
|
|
|
950
900
|
// src/attribute.js
|
|
951
|
-
|
|
901
|
+
var Attributes = class {
|
|
952
902
|
constructor(items) {
|
|
953
903
|
this.items = items;
|
|
954
904
|
}
|
|
@@ -961,11 +911,10 @@ class Attributes {
|
|
|
961
911
|
isConstant() {
|
|
962
912
|
return false;
|
|
963
913
|
}
|
|
964
|
-
}
|
|
914
|
+
};
|
|
965
915
|
var booleanAttrsRaw = "itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected";
|
|
966
916
|
var booleanAttrs = new Set(booleanAttrsRaw.split(","));
|
|
967
|
-
|
|
968
|
-
class AttrParser {
|
|
917
|
+
var AttrParser = class {
|
|
969
918
|
constructor(px) {
|
|
970
919
|
this.clear(px);
|
|
971
920
|
}
|
|
@@ -980,13 +929,12 @@ class AttrParser {
|
|
|
980
929
|
this.events = null;
|
|
981
930
|
}
|
|
982
931
|
parseAttr(name, value, parseAll = false) {
|
|
983
|
-
const val = parseAll ?
|
|
932
|
+
const val = parseAll ? parseMacroAttr(value, this.px) : parseText(value, this.px);
|
|
984
933
|
if (val !== null) {
|
|
985
934
|
this.attrs ??= [];
|
|
986
935
|
this.attrs.push(new Attr(name, val));
|
|
987
936
|
this.hasDynamic ||= !(val instanceof ConstVal);
|
|
988
|
-
} else
|
|
989
|
-
this.px.onParseIssue("bad-value", { role: "attr", attr: name, value });
|
|
937
|
+
} else this.px.onParseIssue("bad-value", { role: "attr", attr: name, value });
|
|
990
938
|
}
|
|
991
939
|
pushWrapper(name, raw, val) {
|
|
992
940
|
const node = { name, val, raw };
|
|
@@ -995,7 +943,7 @@ class AttrParser {
|
|
|
995
943
|
return node;
|
|
996
944
|
}
|
|
997
945
|
parseIf(directiveName, value) {
|
|
998
|
-
const dynVal =
|
|
946
|
+
const dynVal = parseBool(value, this.px);
|
|
999
947
|
if (dynVal) {
|
|
1000
948
|
this.ifAttr = new IfAttr(directiveName.slice(3), dynVal);
|
|
1001
949
|
this.attrs ??= [];
|
|
@@ -1007,12 +955,10 @@ class AttrParser {
|
|
|
1007
955
|
}
|
|
1008
956
|
}
|
|
1009
957
|
parseThen(s) {
|
|
1010
|
-
if (this.ifAttr)
|
|
1011
|
-
this.ifAttr.thenVal = vp.parseText(s, this.px) ?? NOT_SET_VAL;
|
|
958
|
+
if (this.ifAttr) this.ifAttr.thenVal = parseText(s, this.px) ?? NOT_SET_VAL;
|
|
1012
959
|
}
|
|
1013
960
|
parseElse(value) {
|
|
1014
|
-
if (this.ifAttr)
|
|
1015
|
-
this.ifAttr.elseVal = vp.parseText(value, this.px) ?? NOT_SET_VAL;
|
|
961
|
+
if (this.ifAttr) this.ifAttr.elseVal = parseText(value, this.px) ?? NOT_SET_VAL;
|
|
1016
962
|
}
|
|
1017
963
|
parseEvent(directiveName, value) {
|
|
1018
964
|
const [eventName, ...modifiers] = directiveName.slice(3).split("+");
|
|
@@ -1021,13 +967,13 @@ class AttrParser {
|
|
|
1021
967
|
if (this.events === null) {
|
|
1022
968
|
this.events = this.px.registerEvents();
|
|
1023
969
|
this.attrs ??= [];
|
|
1024
|
-
this.attrs.push(new ConstAttr("data-eid",
|
|
970
|
+
this.attrs.push(new ConstAttr("data-eid", new ConstVal(this.events.id)));
|
|
1025
971
|
}
|
|
1026
972
|
this.events.add(eventName, handler, modifiers);
|
|
1027
973
|
}
|
|
1028
974
|
}
|
|
1029
975
|
_parseDirectiveValue(directiveName, s, parserFn) {
|
|
1030
|
-
const val = parserFn
|
|
976
|
+
const val = parserFn(s, this.px);
|
|
1031
977
|
if (val === null) {
|
|
1032
978
|
const info = { role: "directive", directive: directiveName, value: s };
|
|
1033
979
|
this.px.onParseIssue("bad-value", info);
|
|
@@ -1038,31 +984,39 @@ class AttrParser {
|
|
|
1038
984
|
switch (directiveName) {
|
|
1039
985
|
case "dangerouslysetinnerhtml":
|
|
1040
986
|
this.attrs ??= [];
|
|
1041
|
-
this.attrs.push(new RawHtmlAttr(this._parseDirectiveValue(directiveName, s,
|
|
987
|
+
this.attrs.push(new RawHtmlAttr(this._parseDirectiveValue(directiveName, s, parseText)));
|
|
1042
988
|
this.hasDynamic = true;
|
|
1043
989
|
return;
|
|
1044
990
|
case "push-view":
|
|
1045
|
-
this.pushWrapper("push-view", s, this._parseDirectiveValue(directiveName, s,
|
|
991
|
+
this.pushWrapper("push-view", s, this._parseDirectiveValue(directiveName, s, parseText));
|
|
1046
992
|
return;
|
|
1047
993
|
case "text":
|
|
1048
|
-
this.textChild = this._parseDirectiveValue(directiveName, s,
|
|
994
|
+
this.textChild = this._parseDirectiveValue(directiveName, s, parseText);
|
|
1049
995
|
return;
|
|
1050
996
|
case "show":
|
|
1051
|
-
this.pushWrapper("show", s, this._parseDirectiveValue(directiveName, s,
|
|
997
|
+
this.pushWrapper("show", s, this._parseDirectiveValue(directiveName, s, parseBool));
|
|
1052
998
|
return;
|
|
1053
999
|
case "hide":
|
|
1054
|
-
this.pushWrapper("hide", s, this._parseDirectiveValue(directiveName, s,
|
|
1000
|
+
this.pushWrapper("hide", s, this._parseDirectiveValue(directiveName, s, parseBool));
|
|
1055
1001
|
return;
|
|
1056
1002
|
case "each": {
|
|
1057
|
-
const val = this._parseDirectiveValue(directiveName, s,
|
|
1003
|
+
const val = this._parseDirectiveValue(directiveName, s, parseSequence);
|
|
1058
1004
|
this.eachAttr = this.pushWrapper("each", s, val);
|
|
1059
1005
|
return;
|
|
1060
1006
|
}
|
|
1061
1007
|
case "enrich-with":
|
|
1062
1008
|
if (this.eachAttr !== null)
|
|
1063
|
-
this.eachAttr.enrichWithVal = this._parseDirectiveValue(
|
|
1009
|
+
this.eachAttr.enrichWithVal = this._parseDirectiveValue(
|
|
1010
|
+
directiveName,
|
|
1011
|
+
s,
|
|
1012
|
+
parseAlterHandler
|
|
1013
|
+
);
|
|
1064
1014
|
else
|
|
1065
|
-
this.pushWrapper(
|
|
1015
|
+
this.pushWrapper(
|
|
1016
|
+
"scope",
|
|
1017
|
+
s,
|
|
1018
|
+
this._parseDirectiveValue(directiveName, s, parseAlterHandler)
|
|
1019
|
+
);
|
|
1066
1020
|
return;
|
|
1067
1021
|
case "when":
|
|
1068
1022
|
this._parseWhen(s);
|
|
@@ -1077,14 +1031,10 @@ class AttrParser {
|
|
|
1077
1031
|
this.parseElse(s);
|
|
1078
1032
|
return;
|
|
1079
1033
|
}
|
|
1080
|
-
if (directiveName.startsWith("on."))
|
|
1081
|
-
|
|
1082
|
-
else if (directiveName.startsWith("
|
|
1083
|
-
|
|
1084
|
-
else if (directiveName.startsWith("then."))
|
|
1085
|
-
this.parseThen(s);
|
|
1086
|
-
else if (directiveName.startsWith("else."))
|
|
1087
|
-
this.parseElse(s);
|
|
1034
|
+
if (directiveName.startsWith("on.")) this.parseEvent(directiveName, s);
|
|
1035
|
+
else if (directiveName.startsWith("if.")) this.parseIf(directiveName, s);
|
|
1036
|
+
else if (directiveName.startsWith("then.")) this.parseThen(s);
|
|
1037
|
+
else if (directiveName.startsWith("else.")) this.parseElse(s);
|
|
1088
1038
|
else {
|
|
1089
1039
|
const info = { name: directiveName, value: s };
|
|
1090
1040
|
this.px.onParseIssue("unknown-directive", info);
|
|
@@ -1092,59 +1042,54 @@ class AttrParser {
|
|
|
1092
1042
|
}
|
|
1093
1043
|
_parseWhen(s) {
|
|
1094
1044
|
if (this.eachAttr !== null)
|
|
1095
|
-
this.eachAttr.whenVal = this._parseDirectiveValue("when", s,
|
|
1045
|
+
this.eachAttr.whenVal = this._parseDirectiveValue("when", s, parseAlterHandler);
|
|
1096
1046
|
}
|
|
1097
1047
|
_parseLoopWith(s) {
|
|
1098
1048
|
if (this.eachAttr !== null)
|
|
1099
|
-
this.eachAttr.loopWithVal = this._parseDirectiveValue("loop-with", s,
|
|
1049
|
+
this.eachAttr.loopWithVal = this._parseDirectiveValue("loop-with", s, parseAlterHandler);
|
|
1100
1050
|
}
|
|
1101
1051
|
parse(attributes, parseAll = false) {
|
|
1102
1052
|
for (const { name, value } of attributes) {
|
|
1103
1053
|
const charCode = name.charCodeAt(0);
|
|
1104
1054
|
if (charCode === 58)
|
|
1105
1055
|
this.parseAttr(name === ":viewbox" ? "viewBox" : name.slice(1), value, parseAll);
|
|
1106
|
-
else if (charCode === 64)
|
|
1107
|
-
this.parseDirective(value, name.slice(1));
|
|
1056
|
+
else if (charCode === 64) this.parseDirective(value, name.slice(1));
|
|
1108
1057
|
else {
|
|
1109
1058
|
this.attrs ??= [];
|
|
1110
1059
|
const constVal = value === "" && booleanAttrs.has(name) ? true : value;
|
|
1111
|
-
this.attrs.push(new ConstAttr(name,
|
|
1060
|
+
this.attrs.push(new ConstAttr(name, new ConstVal(constVal)));
|
|
1112
1061
|
}
|
|
1113
1062
|
}
|
|
1114
1063
|
const { attrs, hasDynamic } = this;
|
|
1115
1064
|
const pAttrs = hasDynamic ? new DynAttrs(attrs) : ConstAttrs.fromAttrs(attrs ?? []);
|
|
1116
1065
|
return [pAttrs, this.wrapperAttrs, this.textChild];
|
|
1117
1066
|
}
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
class ConstAttrs extends Attributes {
|
|
1067
|
+
};
|
|
1068
|
+
var ConstAttrs = class _ConstAttrs extends Attributes {
|
|
1121
1069
|
eval(_stack) {
|
|
1122
1070
|
return this.items;
|
|
1123
1071
|
}
|
|
1124
1072
|
static fromAttrs(attrs) {
|
|
1125
1073
|
const attrsObj = {};
|
|
1126
|
-
for (const attr of attrs)
|
|
1127
|
-
|
|
1128
|
-
return new ConstAttrs(attrsObj);
|
|
1074
|
+
for (const attr of attrs) attrsObj[attr.name] = attr.val.eval(null);
|
|
1075
|
+
return new _ConstAttrs(attrsObj);
|
|
1129
1076
|
}
|
|
1130
1077
|
setDataAttr(key, val) {
|
|
1131
1078
|
this.items[key] = val;
|
|
1132
1079
|
}
|
|
1133
1080
|
toMacroVars() {
|
|
1134
1081
|
const r = {};
|
|
1135
|
-
for (const name in this.items)
|
|
1136
|
-
r[name] = new ConstVal(`${this.items[name]}`).toString();
|
|
1082
|
+
for (const name in this.items) r[name] = new ConstVal(`${this.items[name]}`).toString();
|
|
1137
1083
|
return r;
|
|
1138
1084
|
}
|
|
1139
1085
|
isConstant() {
|
|
1140
1086
|
return true;
|
|
1141
1087
|
}
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
class DynAttrs extends Attributes {
|
|
1088
|
+
};
|
|
1089
|
+
var DynAttrs = class extends Attributes {
|
|
1145
1090
|
eval(stack) {
|
|
1146
1091
|
const attrs = {};
|
|
1147
|
-
for (let i = 0;i < this.items.length; i++) {
|
|
1092
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1148
1093
|
const attr = this.items[i];
|
|
1149
1094
|
attrs[attr.name] = attr.eval(stack);
|
|
1150
1095
|
}
|
|
@@ -1155,19 +1100,16 @@ class DynAttrs extends Attributes {
|
|
|
1155
1100
|
}
|
|
1156
1101
|
toMacroVars() {
|
|
1157
1102
|
const r = {};
|
|
1158
|
-
for (const attr of this.items)
|
|
1159
|
-
r[attr.name] = attr.val.toString();
|
|
1103
|
+
for (const attr of this.items) r[attr.name] = attr.val.toString();
|
|
1160
1104
|
return r;
|
|
1161
1105
|
}
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
class BaseAttr {
|
|
1106
|
+
};
|
|
1107
|
+
var BaseAttr = class {
|
|
1165
1108
|
constructor(name) {
|
|
1166
1109
|
this.name = name;
|
|
1167
1110
|
}
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
class Attr extends BaseAttr {
|
|
1111
|
+
};
|
|
1112
|
+
var Attr = class extends BaseAttr {
|
|
1171
1113
|
constructor(name, val) {
|
|
1172
1114
|
super(name);
|
|
1173
1115
|
this.val = val;
|
|
@@ -1175,22 +1117,19 @@ class Attr extends BaseAttr {
|
|
|
1175
1117
|
eval(stack) {
|
|
1176
1118
|
return this.val.eval(stack);
|
|
1177
1119
|
}
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
class RawHtmlAttr extends Attr {
|
|
1120
|
+
};
|
|
1121
|
+
var ConstAttr = class extends Attr {
|
|
1122
|
+
};
|
|
1123
|
+
var RawHtmlAttr = class extends Attr {
|
|
1184
1124
|
constructor(val) {
|
|
1185
|
-
super("dangerouslySetInnerHTML", val ??
|
|
1125
|
+
super("dangerouslySetInnerHTML", val ?? NULL_CONST_VAL);
|
|
1186
1126
|
}
|
|
1187
1127
|
eval(stack) {
|
|
1188
1128
|
return { __html: `${this.val.eval(stack)}` };
|
|
1189
1129
|
}
|
|
1190
|
-
}
|
|
1191
|
-
var NOT_SET_VAL =
|
|
1192
|
-
|
|
1193
|
-
class IfAttr extends BaseAttr {
|
|
1130
|
+
};
|
|
1131
|
+
var NOT_SET_VAL = NULL_CONST_VAL;
|
|
1132
|
+
var IfAttr = class extends BaseAttr {
|
|
1194
1133
|
constructor(name, condVal) {
|
|
1195
1134
|
super(name);
|
|
1196
1135
|
this.condVal = condVal;
|
|
@@ -1202,73 +1141,66 @@ class IfAttr extends BaseAttr {
|
|
|
1202
1141
|
eval(stack) {
|
|
1203
1142
|
return this.condVal.eval(stack) ? this.thenVal.eval(stack) : this.elseVal.eval(stack);
|
|
1204
1143
|
}
|
|
1205
|
-
}
|
|
1144
|
+
};
|
|
1206
1145
|
var _attrParser = null;
|
|
1207
1146
|
function getAttrParser(px) {
|
|
1208
1147
|
_attrParser ??= new AttrParser(px);
|
|
1209
1148
|
_attrParser.clear(px);
|
|
1210
1149
|
return _attrParser;
|
|
1211
1150
|
}
|
|
1212
|
-
|
|
1213
|
-
class EventHandler {
|
|
1151
|
+
var EventHandler = class _EventHandler {
|
|
1214
1152
|
constructor(handlerVal, args = []) {
|
|
1215
1153
|
this.handlerVal = handlerVal;
|
|
1216
1154
|
this.args = args;
|
|
1217
1155
|
}
|
|
1218
1156
|
getHandlerAndArgs(stack, _event) {
|
|
1219
1157
|
const argValues = new Array(this.args.length);
|
|
1220
|
-
for (let i = 0;i < argValues.length; i++)
|
|
1221
|
-
argValues[i] = this.args[i].eval(stack);
|
|
1158
|
+
for (let i = 0; i < argValues.length; i++) argValues[i] = this.args[i].eval(stack);
|
|
1222
1159
|
return [this.handlerVal.evalAsHandler(stack), argValues];
|
|
1223
1160
|
}
|
|
1224
1161
|
static parse(s, px) {
|
|
1225
|
-
const r =
|
|
1226
|
-
return r === null ? null : new
|
|
1162
|
+
const r = parseInputHandler(s, px);
|
|
1163
|
+
return r === null ? null : new _EventHandler(r.handlerVal, r.args);
|
|
1227
1164
|
}
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
class RequestHandler {
|
|
1165
|
+
};
|
|
1166
|
+
var RequestHandler = class {
|
|
1231
1167
|
constructor(name, fn) {
|
|
1232
1168
|
this.name = name;
|
|
1233
1169
|
this.fn = fn;
|
|
1234
1170
|
}
|
|
1235
|
-
}
|
|
1171
|
+
};
|
|
1236
1172
|
|
|
1237
1173
|
// src/renderer.js
|
|
1238
1174
|
import { isIndexed, isKeyed } from "immutable";
|
|
1239
1175
|
|
|
1240
1176
|
// src/cache.js
|
|
1241
1177
|
var isWeakKey = (k) => k !== null && (typeof k === "object" || typeof k === "function");
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
set(_keys, _cacheKey, _v) {
|
|
1178
|
+
var NullDomCache = class {
|
|
1179
|
+
get(_keys, _cacheKey) {
|
|
1180
|
+
}
|
|
1181
|
+
set(_keys, _cacheKey, _v) {
|
|
1182
|
+
}
|
|
1246
1183
|
evict() {
|
|
1247
1184
|
return { hit: 0, miss: 0, badKey: 0 };
|
|
1248
1185
|
}
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
class WeakMapDomCache {
|
|
1186
|
+
};
|
|
1187
|
+
var WeakMapDomCache = class {
|
|
1252
1188
|
constructor() {
|
|
1253
1189
|
this.hit = this.miss = this.badKey = 0;
|
|
1254
|
-
this.keysByLen = new Map;
|
|
1190
|
+
this.keysByLen = /* @__PURE__ */ new Map();
|
|
1255
1191
|
}
|
|
1256
1192
|
_returnValue(r) {
|
|
1257
|
-
if (r ===
|
|
1258
|
-
|
|
1259
|
-
else
|
|
1260
|
-
this.hit += 1;
|
|
1193
|
+
if (r === void 0) this.miss += 1;
|
|
1194
|
+
else this.hit += 1;
|
|
1261
1195
|
return r;
|
|
1262
1196
|
}
|
|
1263
1197
|
get(keys, cacheKey) {
|
|
1264
1198
|
const len = keys.length;
|
|
1265
1199
|
let cur = this.keysByLen.get(len);
|
|
1266
|
-
if (!cur)
|
|
1267
|
-
|
|
1268
|
-
for (let i = 0;i < len - 1; i++) {
|
|
1200
|
+
if (!cur) return this._returnValue(void 0);
|
|
1201
|
+
for (let i = 0; i < len - 1; i++) {
|
|
1269
1202
|
cur = cur.get(keys[i]);
|
|
1270
|
-
if (!cur)
|
|
1271
|
-
return this._returnValue(undefined);
|
|
1203
|
+
if (!cur) return this._returnValue(void 0);
|
|
1272
1204
|
}
|
|
1273
1205
|
return this._returnValue(cur.get(keys[len - 1])?.[cacheKey]);
|
|
1274
1206
|
}
|
|
@@ -1276,10 +1208,10 @@ class WeakMapDomCache {
|
|
|
1276
1208
|
const len = keys.length;
|
|
1277
1209
|
let cur = this.keysByLen.get(len);
|
|
1278
1210
|
if (!cur) {
|
|
1279
|
-
cur = new WeakMap;
|
|
1211
|
+
cur = /* @__PURE__ */ new WeakMap();
|
|
1280
1212
|
this.keysByLen.set(len, cur);
|
|
1281
1213
|
}
|
|
1282
|
-
for (let i = 0;i < len - 1; i++) {
|
|
1214
|
+
for (let i = 0; i < len - 1; i++) {
|
|
1283
1215
|
const key = keys[i];
|
|
1284
1216
|
let next = cur.get(key);
|
|
1285
1217
|
if (!next) {
|
|
@@ -1287,27 +1219,24 @@ class WeakMapDomCache {
|
|
|
1287
1219
|
this.badKey += 1;
|
|
1288
1220
|
return;
|
|
1289
1221
|
}
|
|
1290
|
-
next = new WeakMap;
|
|
1222
|
+
next = /* @__PURE__ */ new WeakMap();
|
|
1291
1223
|
cur.set(key, next);
|
|
1292
1224
|
}
|
|
1293
1225
|
cur = next;
|
|
1294
1226
|
}
|
|
1295
1227
|
const lastKey = keys[len - 1];
|
|
1296
1228
|
const leaf = cur.get(lastKey);
|
|
1297
|
-
if (leaf)
|
|
1298
|
-
|
|
1299
|
-
else
|
|
1300
|
-
cur.set(lastKey, { [cacheKey]: v });
|
|
1301
|
-
else
|
|
1302
|
-
this.badKey += 1;
|
|
1229
|
+
if (leaf) leaf[cacheKey] = v;
|
|
1230
|
+
else if (isWeakKey(lastKey)) cur.set(lastKey, { [cacheKey]: v });
|
|
1231
|
+
else this.badKey += 1;
|
|
1303
1232
|
}
|
|
1304
1233
|
evict() {
|
|
1305
1234
|
const { hit, miss, badKey } = this;
|
|
1306
1235
|
this.hit = this.miss = this.badKey = 0;
|
|
1307
|
-
this.keysByLen = new Map;
|
|
1236
|
+
this.keysByLen = /* @__PURE__ */ new Map();
|
|
1308
1237
|
return { hit, miss, badKey };
|
|
1309
1238
|
}
|
|
1310
|
-
}
|
|
1239
|
+
};
|
|
1311
1240
|
|
|
1312
1241
|
// src/vdom.js
|
|
1313
1242
|
var HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
@@ -1323,7 +1252,7 @@ function childOpts(vnode, ns, opts) {
|
|
|
1323
1252
|
const target = ns === SVG_NS && isForeignObject(vnode.tag) ? null : ns;
|
|
1324
1253
|
return target === (opts.namespace ?? null) ? opts : { ...opts, namespace: target };
|
|
1325
1254
|
}
|
|
1326
|
-
var NEVER_ASSIGN = new Set([
|
|
1255
|
+
var NEVER_ASSIGN = /* @__PURE__ */ new Set([
|
|
1327
1256
|
"width",
|
|
1328
1257
|
"height",
|
|
1329
1258
|
"href",
|
|
@@ -1339,39 +1268,35 @@ var NEVER_ASSIGN = new Set([
|
|
|
1339
1268
|
var PROP_ATTR_NAME = { className: "class", htmlFor: "for" };
|
|
1340
1269
|
function applyProperties(node, props) {
|
|
1341
1270
|
const namespaced = isNamespaced(node);
|
|
1342
|
-
for (const name in props)
|
|
1343
|
-
setProp(node, name, props[name], namespaced);
|
|
1271
|
+
for (const name in props) setProp(node, name, props[name], namespaced);
|
|
1344
1272
|
}
|
|
1345
1273
|
function setProp(node, name, value, namespaced) {
|
|
1346
1274
|
if (name === "dangerouslySetInnerHTML") {
|
|
1347
|
-
if (value ===
|
|
1348
|
-
node.replaceChildren();
|
|
1275
|
+
if (value === void 0) node.replaceChildren();
|
|
1349
1276
|
else {
|
|
1350
|
-
const
|
|
1351
|
-
if (
|
|
1352
|
-
node.innerHTML = html;
|
|
1277
|
+
const html2 = value.__html ?? "";
|
|
1278
|
+
if (html2 !== node.innerHTML) node.innerHTML = html2;
|
|
1353
1279
|
}
|
|
1354
1280
|
return;
|
|
1355
1281
|
}
|
|
1356
|
-
if (typeof value === "function")
|
|
1357
|
-
return;
|
|
1282
|
+
if (typeof value === "function") return;
|
|
1358
1283
|
const usesProp = !namespaced && !NEVER_ASSIGN.has(name) && name in node;
|
|
1359
1284
|
if (usesProp && value != null) {
|
|
1360
1285
|
try {
|
|
1361
1286
|
node[name] = value;
|
|
1362
1287
|
return;
|
|
1363
|
-
} catch {
|
|
1288
|
+
} catch {
|
|
1289
|
+
}
|
|
1364
1290
|
}
|
|
1365
1291
|
if (value == null || value === false && name[4] !== "-") {
|
|
1366
1292
|
if (usesProp) {
|
|
1367
1293
|
try {
|
|
1368
1294
|
node[name] = "";
|
|
1369
|
-
} catch {
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1370
1297
|
node.removeAttribute(PROP_ATTR_NAME[name] ?? name);
|
|
1371
|
-
} else
|
|
1372
|
-
|
|
1373
|
-
} else
|
|
1374
|
-
node.setAttribute(name, value);
|
|
1298
|
+
} else node.removeAttribute(name);
|
|
1299
|
+
} else node.setAttribute(name, value);
|
|
1375
1300
|
}
|
|
1376
1301
|
function applyValueLast(node, value) {
|
|
1377
1302
|
if (node.tagName === "PROGRESS" && (value == null || value === 0)) {
|
|
@@ -1380,39 +1305,28 @@ function applyValueLast(node, value) {
|
|
|
1380
1305
|
setProp(node, "value", value, isNamespaced(node));
|
|
1381
1306
|
}
|
|
1382
1307
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
var getKey = (child) => child instanceof VNode ? child.key : undefined;
|
|
1308
|
+
var VBase = class {
|
|
1309
|
+
};
|
|
1310
|
+
var getKey = (child) => child instanceof VNode ? child.key : void 0;
|
|
1387
1311
|
var isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function";
|
|
1388
1312
|
function childsEqual(a, b) {
|
|
1389
|
-
if (a === b)
|
|
1390
|
-
|
|
1391
|
-
for (let i = 0;i < a.length; i++)
|
|
1392
|
-
if (!a[i].isEqualTo(b[i]))
|
|
1393
|
-
return false;
|
|
1313
|
+
if (a === b) return true;
|
|
1314
|
+
for (let i = 0; i < a.length; i++) if (!a[i].isEqualTo(b[i])) return false;
|
|
1394
1315
|
return true;
|
|
1395
1316
|
}
|
|
1396
1317
|
function appendChildNodes(parent, childs, opts) {
|
|
1397
|
-
for (const child of childs)
|
|
1398
|
-
parent.appendChild(child.toDom(opts));
|
|
1318
|
+
for (const child of childs) parent.appendChild(child.toDom(opts));
|
|
1399
1319
|
}
|
|
1400
1320
|
function addChild(normalizedChildren, child) {
|
|
1401
|
-
if (child == null)
|
|
1402
|
-
return;
|
|
1321
|
+
if (child == null) return;
|
|
1403
1322
|
if (isIterable(child)) {
|
|
1404
|
-
for (const c of child)
|
|
1405
|
-
addChild(normalizedChildren, c);
|
|
1323
|
+
for (const c of child) addChild(normalizedChildren, c);
|
|
1406
1324
|
} else if (child instanceof VBase) {
|
|
1407
|
-
if (child instanceof VFragment)
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
normalizedChildren.push(child);
|
|
1411
|
-
} else
|
|
1412
|
-
normalizedChildren.push(new VText(child));
|
|
1325
|
+
if (child instanceof VFragment) normalizedChildren.push(...child.childs);
|
|
1326
|
+
else normalizedChildren.push(child);
|
|
1327
|
+
} else normalizedChildren.push(new VText(child));
|
|
1413
1328
|
}
|
|
1414
|
-
|
|
1415
|
-
class VText extends VBase {
|
|
1329
|
+
var VText = class _VText extends VBase {
|
|
1416
1330
|
constructor(text) {
|
|
1417
1331
|
super();
|
|
1418
1332
|
this.text = String(text);
|
|
@@ -1421,14 +1335,13 @@ class VText extends VBase {
|
|
|
1421
1335
|
return 3;
|
|
1422
1336
|
}
|
|
1423
1337
|
isEqualTo(other) {
|
|
1424
|
-
return other instanceof
|
|
1338
|
+
return other instanceof _VText && this.text === other.text;
|
|
1425
1339
|
}
|
|
1426
1340
|
toDom(opts) {
|
|
1427
1341
|
return opts.document.createTextNode(this.text);
|
|
1428
1342
|
}
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
class VComment extends VBase {
|
|
1343
|
+
};
|
|
1344
|
+
var VComment = class _VComment extends VBase {
|
|
1432
1345
|
constructor(text) {
|
|
1433
1346
|
super();
|
|
1434
1347
|
this.text = text;
|
|
@@ -1437,14 +1350,13 @@ class VComment extends VBase {
|
|
|
1437
1350
|
return 8;
|
|
1438
1351
|
}
|
|
1439
1352
|
isEqualTo(other) {
|
|
1440
|
-
return other instanceof
|
|
1353
|
+
return other instanceof _VComment && this.text === other.text;
|
|
1441
1354
|
}
|
|
1442
1355
|
toDom(opts) {
|
|
1443
1356
|
return opts.document.createComment(this.text);
|
|
1444
1357
|
}
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
class VFragment extends VBase {
|
|
1358
|
+
};
|
|
1359
|
+
var VFragment = class _VFragment extends VBase {
|
|
1448
1360
|
constructor(childs) {
|
|
1449
1361
|
super();
|
|
1450
1362
|
this.childs = [];
|
|
@@ -1454,8 +1366,7 @@ class VFragment extends VBase {
|
|
|
1454
1366
|
return 11;
|
|
1455
1367
|
}
|
|
1456
1368
|
isEqualTo(other) {
|
|
1457
|
-
if (!(other instanceof
|
|
1458
|
-
return false;
|
|
1369
|
+
if (!(other instanceof _VFragment) || this.childs.length !== other.childs.length) return false;
|
|
1459
1370
|
return childsEqual(this.childs, other.childs);
|
|
1460
1371
|
}
|
|
1461
1372
|
toDom(opts) {
|
|
@@ -1463,15 +1374,14 @@ class VFragment extends VBase {
|
|
|
1463
1374
|
appendChildNodes(fragment, this.childs, opts);
|
|
1464
1375
|
return fragment;
|
|
1465
1376
|
}
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
class VNode extends VBase {
|
|
1377
|
+
};
|
|
1378
|
+
var VNode = class _VNode extends VBase {
|
|
1469
1379
|
constructor(tag, attrs, childs, key, namespace) {
|
|
1470
1380
|
super();
|
|
1471
1381
|
this.tag = tag;
|
|
1472
1382
|
this.attrs = attrs ?? {};
|
|
1473
1383
|
this.childs = childs ?? [];
|
|
1474
|
-
this.key = key != null ? String(key) :
|
|
1384
|
+
this.key = key != null ? String(key) : void 0;
|
|
1475
1385
|
this.namespace = typeof namespace === "string" ? namespace : null;
|
|
1476
1386
|
}
|
|
1477
1387
|
get nodeType() {
|
|
@@ -1481,18 +1391,13 @@ class VNode extends VBase {
|
|
|
1481
1391
|
return this.tag === other.tag && this.namespace === other.namespace && this.key === other.key;
|
|
1482
1392
|
}
|
|
1483
1393
|
isEqualTo(other) {
|
|
1484
|
-
if (this === other)
|
|
1485
|
-
|
|
1486
|
-
if (!(other instanceof VNode) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
|
|
1394
|
+
if (this === other) return true;
|
|
1395
|
+
if (!(other instanceof _VNode) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
|
|
1487
1396
|
return false;
|
|
1488
1397
|
}
|
|
1489
1398
|
if (this.attrs !== other.attrs) {
|
|
1490
|
-
for (const key in this.attrs)
|
|
1491
|
-
|
|
1492
|
-
return false;
|
|
1493
|
-
for (const key in other.attrs)
|
|
1494
|
-
if (!Object.hasOwn(this.attrs, key))
|
|
1495
|
-
return false;
|
|
1399
|
+
for (const key in this.attrs) if (this.attrs[key] !== other.attrs[key]) return false;
|
|
1400
|
+
for (const key in other.attrs) if (!Object.hasOwn(this.attrs, key)) return false;
|
|
1496
1401
|
}
|
|
1497
1402
|
return childsEqual(this.childs, other.childs);
|
|
1498
1403
|
}
|
|
@@ -1501,32 +1406,29 @@ class VNode extends VBase {
|
|
|
1501
1406
|
const ns = effectiveNs(this, opts);
|
|
1502
1407
|
const tag = ns !== null && this.tag === this.tag.toUpperCase() ? this.tag.toLowerCase() : this.tag;
|
|
1503
1408
|
const attrs = this.attrs;
|
|
1504
|
-
const createOpts = attrs.is != null ? { is: attrs.is } :
|
|
1409
|
+
const createOpts = attrs.is != null ? { is: attrs.is } : void 0;
|
|
1505
1410
|
const node = ns === null ? doc.createElement(tag, createOpts) : doc.createElementNS(ns, tag, createOpts);
|
|
1506
1411
|
const cOpts = childOpts(this, ns, opts);
|
|
1507
1412
|
if ("value" in attrs || "checked" in attrs) {
|
|
1508
1413
|
const { value, checked, ...rest } = attrs;
|
|
1509
1414
|
applyProperties(node, rest);
|
|
1510
1415
|
appendChildNodes(node, this.childs, cOpts);
|
|
1511
|
-
if (value !==
|
|
1512
|
-
|
|
1513
|
-
if (checked !== undefined)
|
|
1514
|
-
setProp(node, "checked", checked, false);
|
|
1416
|
+
if (value !== void 0) applyValueLast(node, value);
|
|
1417
|
+
if (checked !== void 0) setProp(node, "checked", checked, false);
|
|
1515
1418
|
} else {
|
|
1516
1419
|
applyProperties(node, attrs);
|
|
1517
1420
|
appendChildNodes(node, this.childs, cOpts);
|
|
1518
1421
|
}
|
|
1519
1422
|
return node;
|
|
1520
1423
|
}
|
|
1521
|
-
}
|
|
1424
|
+
};
|
|
1522
1425
|
function diffProps(a, b) {
|
|
1523
|
-
if (a === b)
|
|
1524
|
-
return null;
|
|
1426
|
+
if (a === b) return null;
|
|
1525
1427
|
let diff = null;
|
|
1526
1428
|
for (const aKey in a) {
|
|
1527
1429
|
if (!Object.hasOwn(b, aKey)) {
|
|
1528
1430
|
diff ??= {};
|
|
1529
|
-
diff[aKey] =
|
|
1431
|
+
diff[aKey] = void 0;
|
|
1530
1432
|
} else if (a[aKey] !== b[aKey]) {
|
|
1531
1433
|
diff ??= {};
|
|
1532
1434
|
diff[aKey] = b[aKey];
|
|
@@ -1541,8 +1443,7 @@ function diffProps(a, b) {
|
|
|
1541
1443
|
return diff;
|
|
1542
1444
|
}
|
|
1543
1445
|
function morphNode(domNode, source, target, opts) {
|
|
1544
|
-
if (source === target || source.isEqualTo(target))
|
|
1545
|
-
return domNode;
|
|
1446
|
+
if (source === target || source.isEqualTo(target)) return domNode;
|
|
1546
1447
|
const type = source.nodeType;
|
|
1547
1448
|
if (type === target.nodeType) {
|
|
1548
1449
|
if (type === 3 || type === 8) {
|
|
@@ -1557,19 +1458,16 @@ function morphNode(domNode, source, target, opts) {
|
|
|
1557
1458
|
if (hasValue || hasChecked) {
|
|
1558
1459
|
const { value: _v, checked: _c, ...rest } = propsDiff;
|
|
1559
1460
|
applyProperties(domNode, rest);
|
|
1560
|
-
} else
|
|
1561
|
-
applyProperties(domNode, propsDiff);
|
|
1461
|
+
} else applyProperties(domNode, propsDiff);
|
|
1562
1462
|
}
|
|
1563
1463
|
if (!target.attrs.dangerouslySetInnerHTML) {
|
|
1564
1464
|
const ns = effectiveNs(target, opts);
|
|
1565
1465
|
morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
|
|
1566
1466
|
}
|
|
1567
|
-
if (hasValue)
|
|
1568
|
-
|
|
1569
|
-
else if (source.tag === "SELECT" && target.attrs.value !== undefined)
|
|
1467
|
+
if (hasValue) applyValueLast(domNode, propsDiff.value);
|
|
1468
|
+
else if (source.tag === "SELECT" && target.attrs.value !== void 0)
|
|
1570
1469
|
applyValueLast(domNode, target.attrs.value);
|
|
1571
|
-
if (hasChecked)
|
|
1572
|
-
setProp(domNode, "checked", propsDiff.checked, false);
|
|
1470
|
+
if (hasChecked) setProp(domNode, "checked", propsDiff.checked, false);
|
|
1573
1471
|
return domNode;
|
|
1574
1472
|
}
|
|
1575
1473
|
if (type === 11) {
|
|
@@ -1592,7 +1490,7 @@ function morphChildren(parentDom, oldChilds, newChilds, opts) {
|
|
|
1592
1490
|
}
|
|
1593
1491
|
if (oldChilds.length === newChilds.length) {
|
|
1594
1492
|
let hasKey = false;
|
|
1595
|
-
for (let i = 0;i < oldChilds.length; i++) {
|
|
1493
|
+
for (let i = 0; i < oldChilds.length; i++) {
|
|
1596
1494
|
if (getKey(oldChilds[i]) != null || getKey(newChilds[i]) != null) {
|
|
1597
1495
|
hasKey = true;
|
|
1598
1496
|
break;
|
|
@@ -1600,7 +1498,7 @@ function morphChildren(parentDom, oldChilds, newChilds, opts) {
|
|
|
1600
1498
|
}
|
|
1601
1499
|
if (!hasKey) {
|
|
1602
1500
|
let dom = parentDom.firstChild;
|
|
1603
|
-
for (let i = 0;i < oldChilds.length; i++) {
|
|
1501
|
+
for (let i = 0; i < oldChilds.length; i++) {
|
|
1604
1502
|
const next = dom.nextSibling;
|
|
1605
1503
|
morphNode(dom, oldChilds[i], newChilds[i], opts);
|
|
1606
1504
|
dom = next;
|
|
@@ -1609,21 +1507,19 @@ function morphChildren(parentDom, oldChilds, newChilds, opts) {
|
|
|
1609
1507
|
}
|
|
1610
1508
|
}
|
|
1611
1509
|
const domNodes = Array.from(parentDom.childNodes);
|
|
1612
|
-
const oldKeyMap = Object.create(null);
|
|
1613
|
-
for (let i = 0;i < oldChilds.length; i++) {
|
|
1510
|
+
const oldKeyMap = /* @__PURE__ */ Object.create(null);
|
|
1511
|
+
for (let i = 0; i < oldChilds.length; i++) {
|
|
1614
1512
|
const key = getKey(oldChilds[i]);
|
|
1615
|
-
if (key != null)
|
|
1616
|
-
oldKeyMap[key] = i;
|
|
1513
|
+
if (key != null) oldKeyMap[key] = i;
|
|
1617
1514
|
}
|
|
1618
1515
|
const used = new Uint8Array(oldChilds.length);
|
|
1619
1516
|
let unkeyedCursor = 0;
|
|
1620
|
-
for (let j = 0;j < newChilds.length; j++) {
|
|
1517
|
+
for (let j = 0; j < newChilds.length; j++) {
|
|
1621
1518
|
const newChild = newChilds[j];
|
|
1622
1519
|
const newKey = getKey(newChild);
|
|
1623
1520
|
let oldIdx = -1;
|
|
1624
1521
|
if (newKey != null) {
|
|
1625
|
-
if (newKey in oldKeyMap && !used[oldKeyMap[newKey]])
|
|
1626
|
-
oldIdx = oldKeyMap[newKey];
|
|
1522
|
+
if (newKey in oldKeyMap && !used[oldKeyMap[newKey]]) oldIdx = oldKeyMap[newKey];
|
|
1627
1523
|
} else {
|
|
1628
1524
|
while (unkeyedCursor < oldChilds.length) {
|
|
1629
1525
|
if (!used[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
|
|
@@ -1637,16 +1533,14 @@ function morphChildren(parentDom, oldChilds, newChilds, opts) {
|
|
|
1637
1533
|
used[oldIdx] = 1;
|
|
1638
1534
|
const newDom = morphNode(domNodes[oldIdx], oldChilds[oldIdx], newChild, opts);
|
|
1639
1535
|
const ref = parentDom.childNodes[j] ?? null;
|
|
1640
|
-
if (newDom !== ref)
|
|
1641
|
-
parentDom.insertBefore(newDom, ref);
|
|
1536
|
+
if (newDom !== ref) parentDom.insertBefore(newDom, ref);
|
|
1642
1537
|
} else {
|
|
1643
1538
|
const ref = parentDom.childNodes[j] ?? null;
|
|
1644
1539
|
parentDom.insertBefore(newChild.toDom(opts), ref);
|
|
1645
1540
|
}
|
|
1646
1541
|
}
|
|
1647
|
-
for (let i = oldChilds.length - 1;i >= 0; i--)
|
|
1648
|
-
if (!used[i] && domNodes[i].parentNode === parentDom)
|
|
1649
|
-
parentDom.removeChild(domNodes[i]);
|
|
1542
|
+
for (let i = oldChilds.length - 1; i >= 0; i--)
|
|
1543
|
+
if (!used[i] && domNodes[i].parentNode === parentDom) parentDom.removeChild(domNodes[i]);
|
|
1650
1544
|
}
|
|
1651
1545
|
function render(vnode, container, options, prev) {
|
|
1652
1546
|
const isFragment = vnode instanceof VFragment;
|
|
@@ -1665,12 +1559,9 @@ function h(tagName, properties, children, namespace) {
|
|
|
1665
1559
|
if (properties) {
|
|
1666
1560
|
for (const propName in properties) {
|
|
1667
1561
|
const propVal = properties[propName];
|
|
1668
|
-
if (propName === "key")
|
|
1669
|
-
|
|
1670
|
-
else
|
|
1671
|
-
namespace = namespace ?? propVal;
|
|
1672
|
-
else
|
|
1673
|
-
props[propName] = propVal;
|
|
1562
|
+
if (propName === "key") key = propVal;
|
|
1563
|
+
else if (propName === "namespace") namespace = namespace ?? propVal;
|
|
1564
|
+
else props[propName] = propVal;
|
|
1674
1565
|
}
|
|
1675
1566
|
}
|
|
1676
1567
|
if (namespace == null) {
|
|
@@ -1692,11 +1583,10 @@ function h(tagName, properties, children, namespace) {
|
|
|
1692
1583
|
|
|
1693
1584
|
// src/renderer.js
|
|
1694
1585
|
var DATASET_ATTRS = ["nid", "cid", "eid", "vid", "si", "sk"];
|
|
1695
|
-
|
|
1696
|
-
class Renderer {
|
|
1586
|
+
var Renderer = class {
|
|
1697
1587
|
constructor(comps) {
|
|
1698
1588
|
this.comps = comps;
|
|
1699
|
-
this.cache = new WeakMapDomCache;
|
|
1589
|
+
this.cache = new WeakMapDomCache();
|
|
1700
1590
|
this.renderTag = h;
|
|
1701
1591
|
}
|
|
1702
1592
|
renderFragment(childs) {
|
|
@@ -1706,7 +1596,7 @@ class Renderer {
|
|
|
1706
1596
|
return new VComment(text);
|
|
1707
1597
|
}
|
|
1708
1598
|
setNullCache() {
|
|
1709
|
-
this.cache = new NullDomCache;
|
|
1599
|
+
this.cache = new NullDomCache();
|
|
1710
1600
|
}
|
|
1711
1601
|
renderToDOM(stack, val) {
|
|
1712
1602
|
const rootNode = document.createElement("div");
|
|
@@ -1718,33 +1608,33 @@ class Renderer {
|
|
|
1718
1608
|
const dom = this.renderToDOM(stack, val);
|
|
1719
1609
|
if (cleanAttrs) {
|
|
1720
1610
|
const nodes = dom.querySelectorAll("[data-nid],[data-cid],[data-eid]");
|
|
1721
|
-
for (const { dataset } of nodes)
|
|
1722
|
-
for (const name of DATASET_ATTRS)
|
|
1723
|
-
delete dataset[name];
|
|
1611
|
+
for (const { dataset } of nodes) for (const name of DATASET_ATTRS) delete dataset[name];
|
|
1724
1612
|
}
|
|
1725
1613
|
return dom.innerHTML;
|
|
1726
1614
|
}
|
|
1727
1615
|
renderRoot(stack, val, viewName = null) {
|
|
1728
1616
|
const comp = this.comps.getCompFor(val);
|
|
1729
|
-
if (comp === null)
|
|
1730
|
-
return null;
|
|
1617
|
+
if (comp === null) return null;
|
|
1731
1618
|
return this._rValComp(stack, val, comp, comp.getView(viewName).anode, "ROOT", viewName);
|
|
1732
1619
|
}
|
|
1733
1620
|
renderIt(stack, node, key, viewName) {
|
|
1734
1621
|
const comp = this.comps.getCompFor(stack.it);
|
|
1735
1622
|
return comp ? this._rValComp(stack, stack.it, comp, node, key, viewName) : null;
|
|
1736
1623
|
}
|
|
1624
|
+
// `node` is the parse node of the render site (`<x render>` / `render-it` /
|
|
1625
|
+
// `render-each`, or the view's root anode for the app root). It keys the
|
|
1626
|
+
// cache as a globally-unique object: node ids alone are unique only within a
|
|
1627
|
+
// single view, so the same value rendered by two components (e.g. through a
|
|
1628
|
+
// shared dynamic-var sequence) would otherwise collide in the cache.
|
|
1737
1629
|
_rValComp(stack, val, comp, node, key, viewName) {
|
|
1738
|
-
const cacheKey = `${viewName ?? ""}
|
|
1630
|
+
const cacheKey = `${viewName ?? ""}${stack.viewsId ?? ""}${key}`;
|
|
1739
1631
|
const cachePath = [node, val];
|
|
1740
1632
|
stack._pushDynBindValuesToArray(cachePath, comp);
|
|
1741
1633
|
const cachedNode = this.cache.get(cachePath, cacheKey);
|
|
1742
|
-
if (cachedNode)
|
|
1743
|
-
return cachedNode;
|
|
1634
|
+
if (cachedNode) return cachedNode;
|
|
1744
1635
|
const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
|
|
1745
1636
|
const body = this.renderView(view, stack);
|
|
1746
|
-
if (body == null)
|
|
1747
|
-
return null;
|
|
1637
|
+
if (body == null) return null;
|
|
1748
1638
|
const meta = this._renderMetadata({
|
|
1749
1639
|
$: "Comp",
|
|
1750
1640
|
nid: node?.nodeId ?? null,
|
|
@@ -1762,30 +1652,33 @@ class Renderer {
|
|
|
1762
1652
|
const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
|
|
1763
1653
|
const r = [];
|
|
1764
1654
|
const it = stack.it;
|
|
1765
|
-
const { iterData, start, end, keys } = unpackLoopResult(
|
|
1655
|
+
const { iterData, start, end, keys } = unpackLoopResult(
|
|
1656
|
+
loopWith.call(it, seq, makeLoopCtx(stack, filter)),
|
|
1657
|
+
seq
|
|
1658
|
+
);
|
|
1766
1659
|
const renderOne = (key, value, attrName) => {
|
|
1767
1660
|
const cachePath = enricher ? [view, it, value] : [view, value];
|
|
1768
1661
|
const binds = { key, value };
|
|
1769
|
-
const cacheKey = `${stack.viewsId ?? ""}
|
|
1770
|
-
if (enricher)
|
|
1771
|
-
callEnricher(enricher, it, binds, key, value, iterData);
|
|
1662
|
+
const cacheKey = `${stack.viewsId ?? ""}${nid}${key}`;
|
|
1663
|
+
if (enricher) callEnricher(enricher, it, binds, key, value, iterData);
|
|
1772
1664
|
const cachedNode = this.cache.get(cachePath, cacheKey);
|
|
1773
|
-
if (cachedNode)
|
|
1774
|
-
this.pushEachEntry(r, nid, attrName, key, cachedNode);
|
|
1665
|
+
if (cachedNode) this.pushEachEntry(r, nid, attrName, key, cachedNode);
|
|
1775
1666
|
else {
|
|
1776
1667
|
const dom = this.renderView(view, stack.enter(value, binds, false));
|
|
1777
|
-
if (dom != null)
|
|
1778
|
-
this.pushEachEntry(r, nid, attrName, key, dom);
|
|
1668
|
+
if (dom != null) this.pushEachEntry(r, nid, attrName, key, dom);
|
|
1779
1669
|
this.cache.set(cachePath, cacheKey, dom);
|
|
1780
1670
|
}
|
|
1781
1671
|
};
|
|
1782
|
-
if (keys)
|
|
1783
|
-
imKeysIter(seq, renderOne, keys);
|
|
1672
|
+
if (keys) imKeysIter(seq, renderOne, keys);
|
|
1784
1673
|
else
|
|
1785
|
-
getSeqInfo(seq)(
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1674
|
+
getSeqInfo(seq)(
|
|
1675
|
+
seq,
|
|
1676
|
+
(key, value, attrName) => {
|
|
1677
|
+
if (filter.call(it, key, value, iterData)) renderOne(key, value, attrName);
|
|
1678
|
+
},
|
|
1679
|
+
start,
|
|
1680
|
+
end
|
|
1681
|
+
);
|
|
1789
1682
|
return r;
|
|
1790
1683
|
}
|
|
1791
1684
|
renderView(view, stack) {
|
|
@@ -1793,8 +1686,7 @@ class Renderer {
|
|
|
1793
1686
|
while (n !== null) {
|
|
1794
1687
|
const b = n[0];
|
|
1795
1688
|
if (b.isFrame) {
|
|
1796
|
-
if (stack.it !== b.it)
|
|
1797
|
-
break;
|
|
1689
|
+
if (stack.it !== b.it) break;
|
|
1798
1690
|
console.error("recursion detected", stack.it, b.it);
|
|
1799
1691
|
return new VComment("RECURSION AVOIDED");
|
|
1800
1692
|
}
|
|
@@ -1805,10 +1697,12 @@ class Renderer {
|
|
|
1805
1697
|
_renderMetadata(info) {
|
|
1806
1698
|
return new VComment(`§${JSON.stringify(info)}§`);
|
|
1807
1699
|
}
|
|
1700
|
+
// Prefix a loop-less @enrich-with subtree with a boundary meta so event-path
|
|
1701
|
+
// reconstruction replays its binds (mirrors the §Each§ / §Comp§ metas).
|
|
1808
1702
|
renderScopeMeta(nid, dom) {
|
|
1809
1703
|
return new VFragment([this._renderMetadata({ $: "Scope", nid }), dom]);
|
|
1810
1704
|
}
|
|
1811
|
-
}
|
|
1705
|
+
};
|
|
1812
1706
|
var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
|
|
1813
1707
|
var normalizeRange = (start, end, size) => {
|
|
1814
1708
|
let s = start == null ? 0 : start < 0 ? size + start : start;
|
|
@@ -1819,7 +1713,10 @@ var normalizeRange = (start, end, size) => {
|
|
|
1819
1713
|
};
|
|
1820
1714
|
var callEnricher = (enricher, it, binds, key, value, iterData) => {
|
|
1821
1715
|
enricher.call(it, binds, key, value, iterData);
|
|
1822
|
-
console.assert(
|
|
1716
|
+
console.assert(
|
|
1717
|
+
binds.key === key && binds.value === value,
|
|
1718
|
+
"@enrich-with handlers must not overwrite binds.key or binds.value"
|
|
1719
|
+
);
|
|
1823
1720
|
binds.key = key;
|
|
1824
1721
|
binds.value = value;
|
|
1825
1722
|
};
|
|
@@ -1831,8 +1728,7 @@ var unpackLoopResult = (result, seq) => {
|
|
|
1831
1728
|
};
|
|
1832
1729
|
var imKeysIter = (seq, visit, keys) => {
|
|
1833
1730
|
const attrName = isIndexed(seq) ? "si" : "sk";
|
|
1834
|
-
for (const key of keys)
|
|
1835
|
-
visit(key, seq.get(key), attrName);
|
|
1731
|
+
for (const key of keys) visit(key, seq.get(key), attrName);
|
|
1836
1732
|
};
|
|
1837
1733
|
var makeLoopCtx = (stack, filter) => ({
|
|
1838
1734
|
lookup: (name) => stack.lookupBind(name),
|
|
@@ -1840,22 +1736,20 @@ var makeLoopCtx = (stack, filter) => ({
|
|
|
1840
1736
|
});
|
|
1841
1737
|
var imIndexedIter = (seq, visit, start, end) => {
|
|
1842
1738
|
const [s, e] = normalizeRange(start, end, seq.size);
|
|
1843
|
-
for (let i = s;i < e; i++)
|
|
1844
|
-
visit(i, seq.get(i), "si");
|
|
1739
|
+
for (let i = s; i < e; i++) visit(i, seq.get(i), "si");
|
|
1845
1740
|
};
|
|
1846
1741
|
var imKeyedIter = (seq, visit, start, end) => {
|
|
1847
1742
|
const [s, e] = normalizeRange(start, end, seq.size);
|
|
1848
1743
|
let i = 0;
|
|
1849
1744
|
for (const [k, v] of seq.toSeq().entries()) {
|
|
1850
|
-
if (i >= e)
|
|
1851
|
-
|
|
1852
|
-
if (i >= s)
|
|
1853
|
-
visit(k, v, "sk");
|
|
1745
|
+
if (i >= e) break;
|
|
1746
|
+
if (i >= s) visit(k, v, "sk");
|
|
1854
1747
|
i++;
|
|
1855
1748
|
}
|
|
1856
1749
|
};
|
|
1857
|
-
var unkIter = () => {
|
|
1858
|
-
|
|
1750
|
+
var unkIter = () => {
|
|
1751
|
+
};
|
|
1752
|
+
var SEQ_INFO = /* @__PURE__ */ Symbol.for("tutuca.seqInfo");
|
|
1859
1753
|
|
|
1860
1754
|
// src/util/env.js
|
|
1861
1755
|
var isMac = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
|
|
@@ -1869,18 +1763,15 @@ function resolveDynProducer(comp, name) {
|
|
|
1869
1763
|
producerProvide = producerComp?.provide?.[lk.provideName];
|
|
1870
1764
|
} else {
|
|
1871
1765
|
const p = comp?.provide?.[name];
|
|
1872
|
-
if (p == null)
|
|
1873
|
-
return null;
|
|
1766
|
+
if (p == null) return null;
|
|
1874
1767
|
producerComp = comp;
|
|
1875
1768
|
producerProvide = p;
|
|
1876
1769
|
}
|
|
1877
|
-
if (producerComp == null || producerProvide == null)
|
|
1878
|
-
return null;
|
|
1770
|
+
if (producerComp == null || producerProvide == null) return null;
|
|
1879
1771
|
const pi = producerProvide.val?.toPathItem?.() ?? null;
|
|
1880
1772
|
return { producerCompId: producerComp.id, producerSteps: pi ? [pi] : [] };
|
|
1881
1773
|
}
|
|
1882
|
-
|
|
1883
|
-
class BaseNode {
|
|
1774
|
+
var BaseNode = class {
|
|
1884
1775
|
render(_stack, _rx) {
|
|
1885
1776
|
return null;
|
|
1886
1777
|
}
|
|
@@ -1893,10 +1784,10 @@ class BaseNode {
|
|
|
1893
1784
|
isWhiteSpace() {
|
|
1894
1785
|
return false;
|
|
1895
1786
|
}
|
|
1896
|
-
optimize() {
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1787
|
+
optimize() {
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
var TextNode = class extends BaseNode {
|
|
1900
1791
|
constructor(val) {
|
|
1901
1792
|
super();
|
|
1902
1793
|
this.val = val;
|
|
@@ -1905,18 +1796,16 @@ class TextNode extends BaseNode {
|
|
|
1905
1796
|
return this.val;
|
|
1906
1797
|
}
|
|
1907
1798
|
isWhiteSpace() {
|
|
1908
|
-
for (let i = 0;i < this.val.length; i++) {
|
|
1799
|
+
for (let i = 0; i < this.val.length; i++) {
|
|
1909
1800
|
const c = this.val.charCodeAt(i);
|
|
1910
|
-
if (!(c === 32 || c === 10 || c === 9 || c === 13))
|
|
1911
|
-
return false;
|
|
1801
|
+
if (!(c === 32 || c === 10 || c === 9 || c === 13)) return false;
|
|
1912
1802
|
}
|
|
1913
1803
|
return true;
|
|
1914
1804
|
}
|
|
1915
1805
|
hasNewLine() {
|
|
1916
|
-
for (let i = 0;i < this.val.length; i++) {
|
|
1806
|
+
for (let i = 0; i < this.val.length; i++) {
|
|
1917
1807
|
const c = this.val.charCodeAt(i);
|
|
1918
|
-
if (c === 10 || c === 13)
|
|
1919
|
-
return true;
|
|
1808
|
+
if (c === 10 || c === 13) return true;
|
|
1920
1809
|
}
|
|
1921
1810
|
return false;
|
|
1922
1811
|
}
|
|
@@ -1926,31 +1815,27 @@ class TextNode extends BaseNode {
|
|
|
1926
1815
|
isConstant() {
|
|
1927
1816
|
return true;
|
|
1928
1817
|
}
|
|
1929
|
-
setDataAttr(_key, _val) {
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1818
|
+
setDataAttr(_key, _val) {
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1821
|
+
var CommentNode = class extends TextNode {
|
|
1933
1822
|
render(_stack, rx) {
|
|
1934
1823
|
return rx.renderComment(this.val);
|
|
1935
1824
|
}
|
|
1936
|
-
}
|
|
1825
|
+
};
|
|
1937
1826
|
function optimizeChilds(childs) {
|
|
1938
|
-
for (let i = 0;i < childs.length; i++) {
|
|
1827
|
+
for (let i = 0; i < childs.length; i++) {
|
|
1939
1828
|
const child = childs[i];
|
|
1940
|
-
if (child.isConstant())
|
|
1941
|
-
|
|
1942
|
-
else
|
|
1943
|
-
child.optimize();
|
|
1829
|
+
if (child.isConstant()) childs[i] = new RenderOnceNode(child);
|
|
1830
|
+
else child.optimize();
|
|
1944
1831
|
}
|
|
1945
1832
|
}
|
|
1946
1833
|
function optimizeNode(node) {
|
|
1947
|
-
if (node.isConstant())
|
|
1948
|
-
return new RenderOnceNode(node);
|
|
1834
|
+
if (node.isConstant()) return new RenderOnceNode(node);
|
|
1949
1835
|
node.optimize();
|
|
1950
1836
|
return node;
|
|
1951
1837
|
}
|
|
1952
|
-
|
|
1953
|
-
class ChildsNode extends BaseNode {
|
|
1838
|
+
var ChildsNode = class extends BaseNode {
|
|
1954
1839
|
constructor(childs) {
|
|
1955
1840
|
super();
|
|
1956
1841
|
this.childs = childs;
|
|
@@ -1961,9 +1846,8 @@ class ChildsNode extends BaseNode {
|
|
|
1961
1846
|
optimize() {
|
|
1962
1847
|
optimizeChilds(this.childs);
|
|
1963
1848
|
}
|
|
1964
|
-
}
|
|
1965
|
-
|
|
1966
|
-
class DomNode extends ChildsNode {
|
|
1849
|
+
};
|
|
1850
|
+
var DomNode = class extends ChildsNode {
|
|
1967
1851
|
constructor(tagName, attrs, childs, namespace = null) {
|
|
1968
1852
|
super(childs);
|
|
1969
1853
|
this.tagName = tagName;
|
|
@@ -1972,7 +1856,7 @@ class DomNode extends ChildsNode {
|
|
|
1972
1856
|
}
|
|
1973
1857
|
render(stack, rx) {
|
|
1974
1858
|
const childNodes = new Array(this.childs.length);
|
|
1975
|
-
for (let i = 0;i < childNodes.length; i++)
|
|
1859
|
+
for (let i = 0; i < childNodes.length; i++)
|
|
1976
1860
|
childNodes[i] = this.childs[i]?.render?.(stack, rx) ?? null;
|
|
1977
1861
|
return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes, this.namespace);
|
|
1978
1862
|
}
|
|
@@ -1982,21 +1866,18 @@ class DomNode extends ChildsNode {
|
|
|
1982
1866
|
isConstant() {
|
|
1983
1867
|
return this.attrs.isConstant() && super.isConstant();
|
|
1984
1868
|
}
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
|
-
class FragmentNode extends ChildsNode {
|
|
1869
|
+
};
|
|
1870
|
+
var FragmentNode = class extends ChildsNode {
|
|
1988
1871
|
render(stack, rx) {
|
|
1989
1872
|
return rx.renderFragment(this.childs.map((c) => c?.render(stack, rx)));
|
|
1990
1873
|
}
|
|
1991
1874
|
setDataAttr(key, val) {
|
|
1992
|
-
for (const child of this.childs)
|
|
1993
|
-
child.setDataAttr(key, val);
|
|
1875
|
+
for (const child of this.childs) child.setDataAttr(key, val);
|
|
1994
1876
|
}
|
|
1995
|
-
}
|
|
1877
|
+
};
|
|
1996
1878
|
var maybeFragment = (xs) => xs.length === 1 ? xs[0] : new FragmentNode(xs);
|
|
1997
1879
|
var VALID_NODE_RE = /^[a-zA-Z][a-zA-Z0-9-]*$/;
|
|
1998
|
-
|
|
1999
|
-
class ANode extends BaseNode {
|
|
1880
|
+
var ANode = class _ANode extends BaseNode {
|
|
2000
1881
|
constructor(nodeId, val) {
|
|
2001
1882
|
super();
|
|
2002
1883
|
this.nodeId = nodeId;
|
|
@@ -2005,41 +1886,33 @@ class ANode extends BaseNode {
|
|
|
2005
1886
|
toPathStep(ctx) {
|
|
2006
1887
|
return ctx.applyKey(this.val?.toPathItem?.() ?? null);
|
|
2007
1888
|
}
|
|
2008
|
-
static parse(
|
|
2009
|
-
const nodes = px.parseHTML(
|
|
2010
|
-
if (nodes.length === 0)
|
|
2011
|
-
|
|
2012
|
-
if (nodes.length === 1)
|
|
2013
|
-
return ANode.fromDOM(nodes[0], px);
|
|
1889
|
+
static parse(html2, px) {
|
|
1890
|
+
const nodes = px.parseHTML(html2);
|
|
1891
|
+
if (nodes.length === 0) return new CommentNode("Empty View in ANode.parse");
|
|
1892
|
+
if (nodes.length === 1) return _ANode.fromDOM(nodes[0], px);
|
|
2014
1893
|
const childs = [];
|
|
2015
|
-
for (let i = 0;i < nodes.length; i++) {
|
|
2016
|
-
const child =
|
|
2017
|
-
if (child !== null)
|
|
2018
|
-
childs.push(child);
|
|
1894
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1895
|
+
const child = _ANode.fromDOM(nodes[i], px);
|
|
1896
|
+
if (child !== null) childs.push(child);
|
|
2019
1897
|
}
|
|
2020
1898
|
const trimmed = condenseChildsWhites(childs);
|
|
2021
|
-
if (trimmed.length === 0)
|
|
2022
|
-
return new CommentNode("Empty View in ANode.parse");
|
|
1899
|
+
if (trimmed.length === 0) return new CommentNode("Empty View in ANode.parse");
|
|
2023
1900
|
return maybeFragment(trimmed);
|
|
2024
1901
|
}
|
|
2025
1902
|
static fromDOM(node, px) {
|
|
2026
|
-
if (node instanceof px.Text)
|
|
2027
|
-
|
|
2028
|
-
else if (node instanceof px.Comment)
|
|
2029
|
-
return new CommentNode(node.textContent);
|
|
1903
|
+
if (node instanceof px.Text) return new TextNode(node.textContent);
|
|
1904
|
+
else if (node instanceof px.Comment) return new CommentNode(node.textContent);
|
|
2030
1905
|
const { childNodes, attributes: attrs, tagName: tag } = node;
|
|
2031
1906
|
const childs = [];
|
|
2032
|
-
for (let i = 0;i < childNodes.length; i++) {
|
|
2033
|
-
const child =
|
|
2034
|
-
if (child !== null)
|
|
2035
|
-
childs.push(child);
|
|
1907
|
+
for (let i = 0; i < childNodes.length; i++) {
|
|
1908
|
+
const child = _ANode.fromDOM(childNodes[i], px);
|
|
1909
|
+
if (child !== null) childs.push(child);
|
|
2036
1910
|
}
|
|
2037
1911
|
const prevTag = px.currentTag;
|
|
2038
1912
|
px.currentTag = tag;
|
|
2039
1913
|
try {
|
|
2040
1914
|
const isPseudoX = attrs[0]?.name === "@x";
|
|
2041
|
-
if (tag === "X" || isPseudoX)
|
|
2042
|
-
return parseXOp(attrs, childs, isPseudoX ? 1 : 0, px);
|
|
1915
|
+
if (tag === "X" || isPseudoX) return parseXOp(attrs, childs, isPseudoX ? 1 : 0, px);
|
|
2043
1916
|
else if (tag.charCodeAt(1) === 58 && (tag.charCodeAt(0) === 88 || tag.charCodeAt(0) === 120)) {
|
|
2044
1917
|
const macroName = tag.slice(2).toLowerCase();
|
|
2045
1918
|
if (macroName === "slot") {
|
|
@@ -2052,8 +1925,7 @@ class ANode extends BaseNode {
|
|
|
2052
1925
|
} else if (VALID_NODE_RE.test(tag)) {
|
|
2053
1926
|
const [nAttrs, wrappers, textChild] = Attributes.parse(attrs, px);
|
|
2054
1927
|
px.onAttributes(nAttrs, wrappers, textChild, false, tag);
|
|
2055
|
-
if (textChild)
|
|
2056
|
-
childs.unshift(new RenderTextNode(null, textChild));
|
|
1928
|
+
if (textChild) childs.unshift(new RenderTextNode(null, textChild));
|
|
2057
1929
|
const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
|
|
2058
1930
|
const ns = node.namespaceURI;
|
|
2059
1931
|
const namespace = ns && ns !== HTML_NS ? ns : null;
|
|
@@ -2064,10 +1936,9 @@ class ANode extends BaseNode {
|
|
|
2064
1936
|
px.currentTag = prevTag;
|
|
2065
1937
|
}
|
|
2066
1938
|
}
|
|
2067
|
-
}
|
|
1939
|
+
};
|
|
2068
1940
|
function parseXOp(attrs, childs, opIdx, px) {
|
|
2069
|
-
if (attrs.length <= opIdx)
|
|
2070
|
-
return maybeFragment(childs);
|
|
1941
|
+
if (attrs.length <= opIdx) return maybeFragment(childs);
|
|
2071
1942
|
const { name, value } = attrs[opIdx];
|
|
2072
1943
|
if (X_OPS[name]?.ignoresChildren && hasMeaningfulChilds(childs))
|
|
2073
1944
|
px.onParseIssue("x-op-ignores-children", { op: name });
|
|
@@ -2076,13 +1947,13 @@ function parseXOp(attrs, childs, opIdx, px) {
|
|
|
2076
1947
|
let node;
|
|
2077
1948
|
switch (name) {
|
|
2078
1949
|
case "slot":
|
|
2079
|
-
node = new SlotNode(null,
|
|
1950
|
+
node = new SlotNode(null, new ConstVal(value), maybeFragment(childs));
|
|
2080
1951
|
break;
|
|
2081
1952
|
case "text":
|
|
2082
|
-
node = px.addNodeIf(RenderTextNode, parseXOpVal(name, value, px,
|
|
1953
|
+
node = px.addNodeIf(RenderTextNode, parseXOpVal(name, value, px, parseText));
|
|
2083
1954
|
break;
|
|
2084
1955
|
case "render":
|
|
2085
|
-
node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px,
|
|
1956
|
+
node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px, parseComponent), as);
|
|
2086
1957
|
break;
|
|
2087
1958
|
case "render-it":
|
|
2088
1959
|
node = px.addNode(RenderItNode, as);
|
|
@@ -2091,12 +1962,12 @@ function parseXOp(attrs, childs, opIdx, px) {
|
|
|
2091
1962
|
node = parseRenderEach(px, value, as, attrs);
|
|
2092
1963
|
break;
|
|
2093
1964
|
case "show": {
|
|
2094
|
-
const val = parseXOpVal(name, value, px,
|
|
1965
|
+
const val = parseXOpVal(name, value, px, parseBool);
|
|
2095
1966
|
node = px.addNodeIf(ShowNode, val, maybeFragment(childs));
|
|
2096
1967
|
break;
|
|
2097
1968
|
}
|
|
2098
1969
|
case "hide": {
|
|
2099
|
-
const val = parseXOpVal(name, value, px,
|
|
1970
|
+
const val = parseXOpVal(name, value, px, parseBool);
|
|
2100
1971
|
node = px.addNodeIf(HideNode, val, maybeFragment(childs));
|
|
2101
1972
|
break;
|
|
2102
1973
|
}
|
|
@@ -2107,39 +1978,35 @@ function parseXOp(attrs, childs, opIdx, px) {
|
|
|
2107
1978
|
return processXExtras(node, attrs, name, opIdx + 1, px);
|
|
2108
1979
|
}
|
|
2109
1980
|
function parseXOpVal(opName, value, px, parserFn) {
|
|
2110
|
-
const val = parserFn
|
|
2111
|
-
if (val === null)
|
|
2112
|
-
px.onParseIssue("bad-value", { role: "x-op", op: opName, value });
|
|
1981
|
+
const val = parserFn(value, px);
|
|
1982
|
+
if (val === null) px.onParseIssue("bad-value", { role: "x-op", op: opName, value });
|
|
2113
1983
|
return val;
|
|
2114
1984
|
}
|
|
2115
1985
|
function parseViewName(s, px) {
|
|
2116
|
-
return
|
|
1986
|
+
return parseText(s, px) ?? new ConstVal(s);
|
|
2117
1987
|
}
|
|
2118
1988
|
function processXExtras(node, attrs, opName, startIdx, px) {
|
|
2119
1989
|
const { consumed, wrappable } = X_OPS[opName];
|
|
2120
1990
|
const wrappers = [];
|
|
2121
|
-
for (let i = startIdx;i < attrs.length; i++) {
|
|
1991
|
+
for (let i = startIdx; i < attrs.length; i++) {
|
|
2122
1992
|
const a = attrs[i];
|
|
2123
1993
|
const aName = a.name;
|
|
2124
|
-
if (consumed.has(aName))
|
|
2125
|
-
continue;
|
|
1994
|
+
if (consumed.has(aName)) continue;
|
|
2126
1995
|
const atPrefixed = aName.charCodeAt(0) === 64;
|
|
2127
1996
|
const baseName = atPrefixed ? aName.slice(1) : aName;
|
|
2128
1997
|
const wrapper = wrappable ? X_OPS[baseName]?.wrapper : null;
|
|
2129
1998
|
if (wrapper) {
|
|
2130
|
-
if (!atPrefixed)
|
|
2131
|
-
|
|
2132
|
-
wrappers.push([wrapper, vp.parseBool(a.value, px)]);
|
|
1999
|
+
if (!atPrefixed) maybeDeprecateBareXDirective(px, opName, baseName);
|
|
2000
|
+
wrappers.push([wrapper, parseBool(a.value, px)]);
|
|
2133
2001
|
continue;
|
|
2134
2002
|
}
|
|
2135
2003
|
const issueInfo = { op: opName, name: aName, value: a.value };
|
|
2136
2004
|
px.onParseIssue("unknown-x-attr", issueInfo);
|
|
2137
2005
|
}
|
|
2138
|
-
for (let i = wrappers.length - 1;i >= 0; i--) {
|
|
2006
|
+
for (let i = wrappers.length - 1; i >= 0; i--) {
|
|
2139
2007
|
const [Cls, val] = wrappers[i];
|
|
2140
2008
|
const wrapper = px.addNodeIf(Cls, val, node);
|
|
2141
|
-
if (wrapper !== null)
|
|
2142
|
-
node = wrapper;
|
|
2009
|
+
if (wrapper !== null) node = wrapper;
|
|
2143
2010
|
}
|
|
2144
2011
|
return node;
|
|
2145
2012
|
}
|
|
@@ -2148,7 +2015,7 @@ function maybeDeprecateBareXDirective(px, opName, name) {
|
|
|
2148
2015
|
}
|
|
2149
2016
|
function wrap(node, px, wrappers) {
|
|
2150
2017
|
if (wrappers) {
|
|
2151
|
-
for (let i = wrappers.length - 1;i >= 0; i--) {
|
|
2018
|
+
for (let i = wrappers.length - 1; i >= 0; i--) {
|
|
2152
2019
|
const wrapperNode = makeWrapperNode(wrappers[i], px);
|
|
2153
2020
|
if (wrapperNode) {
|
|
2154
2021
|
wrapperNode.wrapNode(node);
|
|
@@ -2168,8 +2035,7 @@ function makeWrapperNode(data, px) {
|
|
|
2168
2035
|
}
|
|
2169
2036
|
return node;
|
|
2170
2037
|
}
|
|
2171
|
-
|
|
2172
|
-
class MacroNode extends BaseNode {
|
|
2038
|
+
var MacroNode = class extends BaseNode {
|
|
2173
2039
|
constructor(name, attrs, slots, px) {
|
|
2174
2040
|
super();
|
|
2175
2041
|
this.name = name;
|
|
@@ -2181,16 +2047,13 @@ class MacroNode extends BaseNode {
|
|
|
2181
2047
|
}
|
|
2182
2048
|
compile(scope) {
|
|
2183
2049
|
const { name, attrs, slots } = this;
|
|
2184
|
-
if (this.px.isInsideMacro(name))
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
if (macro === null)
|
|
2188
|
-
this.node = new CommentNode(`bad macro: ${name}`);
|
|
2050
|
+
if (this.px.isInsideMacro(name)) throw new Error(`Recursive macro expansion: ${name}`);
|
|
2051
|
+
const macro2 = scope.lookupMacro(name);
|
|
2052
|
+
if (macro2 === null) this.node = new CommentNode(`bad macro: ${name}`);
|
|
2189
2053
|
else {
|
|
2190
|
-
const vars = { ...
|
|
2191
|
-
this.node =
|
|
2192
|
-
for (const key in this.dataAttrs)
|
|
2193
|
-
this.node.setDataAttr(key, this.dataAttrs[key]);
|
|
2054
|
+
const vars = { ...macro2.defaults, ...attrs };
|
|
2055
|
+
this.node = macro2.expand(this.px.enterMacro(name, vars, slots));
|
|
2056
|
+
for (const key in this.dataAttrs) this.node.setDataAttr(key, this.dataAttrs[key]);
|
|
2194
2057
|
}
|
|
2195
2058
|
}
|
|
2196
2059
|
render(stack, rx) {
|
|
@@ -2205,9 +2068,8 @@ class MacroNode extends BaseNode {
|
|
|
2205
2068
|
optimize() {
|
|
2206
2069
|
this.node = optimizeNode(this.node);
|
|
2207
2070
|
}
|
|
2208
|
-
}
|
|
2209
|
-
|
|
2210
|
-
class Macro {
|
|
2071
|
+
};
|
|
2072
|
+
var Macro = class {
|
|
2211
2073
|
constructor(defaults, rawView) {
|
|
2212
2074
|
this.defaults = defaults;
|
|
2213
2075
|
this.rawView = rawView;
|
|
@@ -2215,46 +2077,47 @@ class Macro {
|
|
|
2215
2077
|
expand(px) {
|
|
2216
2078
|
return ANode.parse(this.rawView, px);
|
|
2217
2079
|
}
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
class RenderViewId extends ANode {
|
|
2080
|
+
};
|
|
2081
|
+
var RenderViewId = class extends ANode {
|
|
2221
2082
|
constructor(nodeId, val, viewVal) {
|
|
2222
2083
|
super(nodeId, val);
|
|
2223
2084
|
this.viewVal = viewVal;
|
|
2224
2085
|
}
|
|
2086
|
+
// The `as=` view selector, evaluated against the host (enclosing) stack like
|
|
2087
|
+
// `@push-view`. Null when `as=` is absent, so the renderer falls through to
|
|
2088
|
+
// `stack.lookupBestView`.
|
|
2225
2089
|
evalViewName(stack) {
|
|
2226
2090
|
return this.viewVal ? this.viewVal.eval(stack) : null;
|
|
2227
2091
|
}
|
|
2228
|
-
|
|
2229
|
-
|
|
2092
|
+
// A `<x render*>` produces no DOM element of its own to carry `data-cid`;
|
|
2093
|
+
// when it is a view's root the component boundary is recorded in the `Comp`
|
|
2094
|
+
// meta comment instead (see Renderer._rValComp), so this is a no-op.
|
|
2095
|
+
setDataAttr(_key, _val) {
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2230
2098
|
function dynRenderStep(comp, name, key) {
|
|
2231
2099
|
const p = resolveDynProducer(comp, name);
|
|
2232
|
-
if (!p)
|
|
2233
|
-
|
|
2234
|
-
return key === undefined ? new DynStep(p.producerCompId, p.producerSteps) : new DynEachStep(p.producerCompId, p.producerSteps, key);
|
|
2100
|
+
if (!p) return null;
|
|
2101
|
+
return key === void 0 ? new DynStep(p.producerCompId, p.producerSteps) : new DynEachStep(p.producerCompId, p.producerSteps, key);
|
|
2235
2102
|
}
|
|
2236
|
-
|
|
2237
|
-
class RenderNode extends RenderViewId {
|
|
2103
|
+
var RenderNode = class extends RenderViewId {
|
|
2238
2104
|
render(stack, rx) {
|
|
2239
2105
|
const newStack = stack.enter(this.val.eval(stack), {}, true);
|
|
2240
2106
|
return rx.renderIt(newStack, this, "", this.evalViewName(stack));
|
|
2241
2107
|
}
|
|
2242
2108
|
toPathStep(ctx) {
|
|
2243
|
-
if (this.val instanceof DynVal)
|
|
2244
|
-
return dynRenderStep(ctx.comp, this.val.name);
|
|
2109
|
+
if (this.val instanceof DynVal) return dynRenderStep(ctx.comp, this.val.name);
|
|
2245
2110
|
return super.toPathStep(ctx);
|
|
2246
2111
|
}
|
|
2247
|
-
}
|
|
2248
|
-
|
|
2249
|
-
class RenderItNode extends RenderViewId {
|
|
2112
|
+
};
|
|
2113
|
+
var RenderItNode = class extends RenderViewId {
|
|
2250
2114
|
render(stack, rx) {
|
|
2251
2115
|
const newStack = stack.enter(stack.it, {}, true);
|
|
2252
2116
|
return rx.renderIt(newStack, this, "", this.evalViewName(stack));
|
|
2253
2117
|
}
|
|
2254
2118
|
toPathStep(ctx) {
|
|
2255
2119
|
const next = ctx.next();
|
|
2256
|
-
if (next === null)
|
|
2257
|
-
return null;
|
|
2120
|
+
if (next === null) return null;
|
|
2258
2121
|
const nextNode = next.resolveNode();
|
|
2259
2122
|
if (nextNode instanceof EachNode && next.hasKey) {
|
|
2260
2123
|
if (nextNode.val instanceof DynVal)
|
|
@@ -2263,18 +2126,16 @@ class RenderItNode extends RenderViewId {
|
|
|
2263
2126
|
}
|
|
2264
2127
|
return null;
|
|
2265
2128
|
}
|
|
2266
|
-
}
|
|
2129
|
+
};
|
|
2267
2130
|
function parseRenderEach(px, value, as, attrs) {
|
|
2268
|
-
const seqVal = parseXOpVal("render-each", value, px,
|
|
2269
|
-
if (seqVal === null)
|
|
2270
|
-
return null;
|
|
2131
|
+
const seqVal = parseXOpVal("render-each", value, px, parseSequence);
|
|
2132
|
+
if (seqVal === null) return null;
|
|
2271
2133
|
const renderIt = px.addNode(RenderItNode, as);
|
|
2272
2134
|
const attrParser = getAttrParser(px);
|
|
2273
2135
|
const eachAttr = attrParser.eachAttr = attrParser.pushWrapper("each", value, seqVal);
|
|
2274
2136
|
const when = attrs.getNamedItem("@when") ?? attrs.getNamedItem("when");
|
|
2275
2137
|
if (when) {
|
|
2276
|
-
if (when.name.charCodeAt(0) !== 64)
|
|
2277
|
-
maybeDeprecateBareXDirective(px, "render-each", "when");
|
|
2138
|
+
if (when.name.charCodeAt(0) !== 64) maybeDeprecateBareXDirective(px, "render-each", "when");
|
|
2278
2139
|
attrParser._parseWhen(when.value);
|
|
2279
2140
|
}
|
|
2280
2141
|
const lWith = attrs.getNamedItem("@loop-with") ?? attrs.getNamedItem("loop-with");
|
|
@@ -2290,15 +2151,15 @@ function parseRenderEach(px, value, as, attrs) {
|
|
|
2290
2151
|
each.wrapNode(renderIt);
|
|
2291
2152
|
return each;
|
|
2292
2153
|
}
|
|
2293
|
-
|
|
2294
|
-
class RenderTextNode extends ANode {
|
|
2154
|
+
var RenderTextNode = class extends ANode {
|
|
2295
2155
|
render(stack, _rx) {
|
|
2296
2156
|
return this.val.eval(stack);
|
|
2297
2157
|
}
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2158
|
+
// Renders to a text node, which can't carry `data-cid`.
|
|
2159
|
+
setDataAttr(_key, _val) {
|
|
2160
|
+
}
|
|
2161
|
+
};
|
|
2162
|
+
var RenderOnceNode = class extends BaseNode {
|
|
2302
2163
|
constructor(node) {
|
|
2303
2164
|
super();
|
|
2304
2165
|
this.node = node;
|
|
@@ -2311,9 +2172,8 @@ class RenderOnceNode extends BaseNode {
|
|
|
2311
2172
|
render(stack, rx) {
|
|
2312
2173
|
return this._render(stack, rx);
|
|
2313
2174
|
}
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
class WrapperNode extends ANode {
|
|
2175
|
+
};
|
|
2176
|
+
var WrapperNode = class extends ANode {
|
|
2317
2177
|
constructor(nodeId, val, node = null) {
|
|
2318
2178
|
super(nodeId, val);
|
|
2319
2179
|
this.node = node;
|
|
@@ -2328,34 +2188,33 @@ class WrapperNode extends ANode {
|
|
|
2328
2188
|
this.node = optimizeNode(this.node);
|
|
2329
2189
|
}
|
|
2330
2190
|
static register = false;
|
|
2331
|
-
}
|
|
2332
|
-
|
|
2333
|
-
class ShowNode extends WrapperNode {
|
|
2191
|
+
};
|
|
2192
|
+
var ShowNode = class extends WrapperNode {
|
|
2334
2193
|
render(stack, rx) {
|
|
2335
2194
|
return this.val.eval(stack) ? this.node.render(stack, rx) : null;
|
|
2336
2195
|
}
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
|
-
class HideNode extends WrapperNode {
|
|
2196
|
+
};
|
|
2197
|
+
var HideNode = class extends WrapperNode {
|
|
2340
2198
|
render(stack, rx) {
|
|
2341
2199
|
return this.val.eval(stack) ? null : this.node.render(stack, rx);
|
|
2342
2200
|
}
|
|
2343
|
-
}
|
|
2344
|
-
|
|
2345
|
-
class PushViewNameNode extends WrapperNode {
|
|
2201
|
+
};
|
|
2202
|
+
var PushViewNameNode = class extends WrapperNode {
|
|
2346
2203
|
render(stack, rx) {
|
|
2347
2204
|
return this.node.render(stack.pushViewName(this.val.eval(stack)), rx);
|
|
2348
2205
|
}
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
|
|
2206
|
+
};
|
|
2207
|
+
var SlotNode = class extends WrapperNode {
|
|
2208
|
+
// Marker instead of `instanceof`: newMacroNode receives nodes that may come
|
|
2209
|
+
// from a different copy of this module (CLI tools import src/ while the
|
|
2210
|
+
// module under render imports the dist bundle), and cross-copy instanceof
|
|
2211
|
+
// is always false.
|
|
2352
2212
|
isSlotNode = true;
|
|
2353
2213
|
optimize() {
|
|
2354
2214
|
this.node.optimize();
|
|
2355
2215
|
}
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
class ScopeNode extends WrapperNode {
|
|
2216
|
+
};
|
|
2217
|
+
var ScopeNode = class extends WrapperNode {
|
|
2359
2218
|
render(stack, rx) {
|
|
2360
2219
|
const binds = this.val.evalAsHandler(stack)?.call(stack.it) ?? {};
|
|
2361
2220
|
const dom = this.node.render(stack.enter(stack.it, binds, false), rx);
|
|
@@ -2369,9 +2228,8 @@ class ScopeNode extends WrapperNode {
|
|
|
2369
2228
|
this.node.setDataAttr("data-nid", this.nodeId);
|
|
2370
2229
|
}
|
|
2371
2230
|
static register = true;
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
class EachNode extends WrapperNode {
|
|
2231
|
+
};
|
|
2232
|
+
var EachNode = class extends WrapperNode {
|
|
2375
2233
|
constructor(nodeId, val) {
|
|
2376
2234
|
super(nodeId, val);
|
|
2377
2235
|
this.iterInfo = new IterInfo(val, null, null, null);
|
|
@@ -2383,9 +2241,8 @@ class EachNode extends WrapperNode {
|
|
|
2383
2241
|
return ctx.hasKey ? new EachBindStep(this.iterInfo, ctx.key) : null;
|
|
2384
2242
|
}
|
|
2385
2243
|
static register = true;
|
|
2386
|
-
}
|
|
2387
|
-
|
|
2388
|
-
class IterInfo {
|
|
2244
|
+
};
|
|
2245
|
+
var IterInfo = class {
|
|
2389
2246
|
constructor(val, whenVal, loopWithVal, enrichWithVal) {
|
|
2390
2247
|
this.val = val;
|
|
2391
2248
|
this.whenVal = whenVal;
|
|
@@ -2399,17 +2256,22 @@ class IterInfo {
|
|
|
2399
2256
|
const enricher = this.enrichWithVal?.evalAsHandler(stack) ?? null;
|
|
2400
2257
|
return { seq, filter, loopWith, enricher };
|
|
2401
2258
|
}
|
|
2259
|
+
// Rebuild the per-item binds for `key`, mirroring renderEachWhen: seed
|
|
2260
|
+
// { key, value }, then run @enrich-with (with @loop-with's iterData) if any.
|
|
2402
2261
|
enrichBinds(stack, key) {
|
|
2403
2262
|
const { seq, filter, loopWith, enricher } = this.eval(stack);
|
|
2404
2263
|
const value = seq?.get ? seq.get(key, null) : null;
|
|
2405
2264
|
const binds = { key, value };
|
|
2406
2265
|
if (enricher) {
|
|
2407
|
-
const { iterData } = unpackLoopResult(
|
|
2266
|
+
const { iterData } = unpackLoopResult(
|
|
2267
|
+
loopWith.call(stack.it, seq, makeLoopCtx(stack, filter)),
|
|
2268
|
+
seq
|
|
2269
|
+
);
|
|
2408
2270
|
callEnricher(enricher, stack.it, binds, key, value, iterData);
|
|
2409
2271
|
}
|
|
2410
2272
|
return binds;
|
|
2411
2273
|
}
|
|
2412
|
-
}
|
|
2274
|
+
};
|
|
2413
2275
|
function xOp(consumed = [], { wrappable = false, wrapper = null, ignoresChildren = false } = {}) {
|
|
2414
2276
|
return { consumed: new Set(consumed), wrappable, wrapper, ignoresChildren };
|
|
2415
2277
|
}
|
|
@@ -2418,6 +2280,10 @@ var X_OPS = {
|
|
|
2418
2280
|
text: xOp([], { wrappable: true, ignoresChildren: true }),
|
|
2419
2281
|
render: xOp(["as"], { wrappable: true, ignoresChildren: true }),
|
|
2420
2282
|
"render-it": xOp(["as"], { wrappable: true, ignoresChildren: true }),
|
|
2283
|
+
// `@when`/`@loop-with` are consumed here (handled in parseRenderEach) so
|
|
2284
|
+
// `processXExtras` does not flag them as unknown attrs. TEMPORARY: the bare
|
|
2285
|
+
// `when`/`loop-with` spellings are deprecated in favor of the `@` form — see
|
|
2286
|
+
// maybeDeprecateBareXDirective (added 2026-07-08).
|
|
2421
2287
|
"render-each": xOp(["as", "when", "loop-with", "@when", "@loop-with"], {
|
|
2422
2288
|
wrappable: true,
|
|
2423
2289
|
ignoresChildren: true
|
|
@@ -2429,11 +2295,11 @@ var WRAPPER_NODES = {
|
|
|
2429
2295
|
show: ShowNode,
|
|
2430
2296
|
hide: HideNode,
|
|
2431
2297
|
each: EachNode,
|
|
2298
|
+
// internal wrapper produced by a loop-less @enrich-with (no surface @scope directive)
|
|
2432
2299
|
scope: ScopeNode,
|
|
2433
2300
|
"push-view": PushViewNameNode
|
|
2434
2301
|
};
|
|
2435
|
-
|
|
2436
|
-
class ParseContext {
|
|
2302
|
+
var ParseContext = class _ParseContext {
|
|
2437
2303
|
constructor(document2, Text, Comment, nodes, events, macroNodes, frame, parent) {
|
|
2438
2304
|
this.nodes = nodes ?? [];
|
|
2439
2305
|
this.events = events ?? [];
|
|
@@ -2452,11 +2318,11 @@ class ParseContext {
|
|
|
2452
2318
|
enterMacro(macroName, macroVars, macroSlots) {
|
|
2453
2319
|
const { document: document2, Text, Comment, nodes, events, macroNodes } = this;
|
|
2454
2320
|
const frame = { macroName, macroVars, macroSlots };
|
|
2455
|
-
return new
|
|
2321
|
+
return new _ParseContext(document2, Text, Comment, nodes, events, macroNodes, frame, this);
|
|
2456
2322
|
}
|
|
2457
|
-
parseHTML(
|
|
2323
|
+
parseHTML(html2) {
|
|
2458
2324
|
const t = this.document.createElement("template");
|
|
2459
|
-
t.innerHTML =
|
|
2325
|
+
t.innerHTML = html2;
|
|
2460
2326
|
return t.content.childNodes;
|
|
2461
2327
|
}
|
|
2462
2328
|
addNodeIf(Class, val, extra) {
|
|
@@ -2468,6 +2334,8 @@ class ParseContext {
|
|
|
2468
2334
|
}
|
|
2469
2335
|
return null;
|
|
2470
2336
|
}
|
|
2337
|
+
// For nodes that carry no value (e.g. RenderItNode, which reads stack.it at
|
|
2338
|
+
// render time); addNodeIf treats a null val as a failed parse.
|
|
2471
2339
|
addNode(Class, extra) {
|
|
2472
2340
|
const nodeId = this.nodes.length;
|
|
2473
2341
|
const node = new Class(nodeId, null, extra);
|
|
@@ -2484,21 +2352,17 @@ class ParseContext {
|
|
|
2484
2352
|
const anySlot = [];
|
|
2485
2353
|
const slots = { _: new FragmentNode(anySlot) };
|
|
2486
2354
|
for (const child of childs)
|
|
2487
|
-
if (child.isSlotNode)
|
|
2488
|
-
|
|
2489
|
-
else if (!child.isWhiteSpace())
|
|
2490
|
-
anySlot.push(child);
|
|
2355
|
+
if (child.isSlotNode) slots[child.val.val] = child.node;
|
|
2356
|
+
else if (!child.isWhiteSpace()) anySlot.push(child);
|
|
2491
2357
|
const node = new MacroNode(macroName, mAttrs, slots, this);
|
|
2492
2358
|
this.macroNodes.push(node);
|
|
2493
2359
|
return node;
|
|
2494
2360
|
}
|
|
2495
2361
|
compile(scope) {
|
|
2496
|
-
for (let i = 0;i < this.macroNodes.length; i++)
|
|
2497
|
-
this.macroNodes[i].compile(scope);
|
|
2362
|
+
for (let i = 0; i < this.macroNodes.length; i++) this.macroNodes[i].compile(scope);
|
|
2498
2363
|
}
|
|
2499
2364
|
*genEventNames() {
|
|
2500
|
-
for (const event of this.events)
|
|
2501
|
-
yield* event.genEventNames();
|
|
2365
|
+
for (const event of this.events) yield* event.genEventNames();
|
|
2502
2366
|
}
|
|
2503
2367
|
getEventForId(id) {
|
|
2504
2368
|
return this.events[id] ?? null;
|
|
@@ -2506,12 +2370,16 @@ class ParseContext {
|
|
|
2506
2370
|
getNodeForId(id) {
|
|
2507
2371
|
return this.nodes[id] ?? null;
|
|
2508
2372
|
}
|
|
2509
|
-
onAttributes(_attrs, _wrapperAttrs, _textChild, _isMacroCall, _tag) {
|
|
2373
|
+
onAttributes(_attrs, _wrapperAttrs, _textChild, _isMacroCall, _tag) {
|
|
2374
|
+
}
|
|
2510
2375
|
onParseIssue(kind, info) {
|
|
2511
2376
|
console.warn(`tutuca parse issue [${kind}]`, info);
|
|
2512
2377
|
}
|
|
2513
|
-
|
|
2514
|
-
|
|
2378
|
+
// Lint-only channel for deprecation nudges on still-valid syntax; the base
|
|
2379
|
+
// (runtime) context ignores them so live apps stay quiet. See LintParseContext.
|
|
2380
|
+
onDeprecatedSyntax(_kind, _info) {
|
|
2381
|
+
}
|
|
2382
|
+
};
|
|
2515
2383
|
var _htmlBlockTags = "ADDRESS,ARTICLE,ASIDE,BLOCKQUOTE,CAPTION,COL,COLGROUP,DETAILS,DIALOG,DIV,DD,DL,DT,FIELDSET,FIGCAPTION,FIGURE,FOOTER,FORM,H1,H2,H3,H4,H5,H6,HEADER,HGROUP,HR,LEGEND,LI,MAIN,MENU,NAV,OL,P,PRE,SECTION,SUMMARY,TABLE,TBODY,TD,TFOOT,TH,THEAD,TR,UL";
|
|
2516
2384
|
var HTML_BLOCK_TAGS = new Set(_htmlBlockTags.split(","));
|
|
2517
2385
|
var isBlockDomNode = (n) => {
|
|
@@ -2522,31 +2390,25 @@ var isEmptyText = (c) => c instanceof TextNode && c.val === "";
|
|
|
2522
2390
|
var isIgnorableXChild = (c) => c instanceof CommentNode || (c.isWhiteSpace?.() ?? false);
|
|
2523
2391
|
var hasMeaningfulChilds = (childs) => childs.some((c) => !isIgnorableXChild(c));
|
|
2524
2392
|
function trimEdgeWhite(node) {
|
|
2525
|
-
if (!node.isWhiteSpace?.())
|
|
2526
|
-
return false;
|
|
2393
|
+
if (!node.isWhiteSpace?.()) return false;
|
|
2527
2394
|
node.condenseWhiteSpace();
|
|
2528
2395
|
return true;
|
|
2529
2396
|
}
|
|
2530
2397
|
function condenseChildsWhites(childs) {
|
|
2531
|
-
if (childs.length === 0)
|
|
2532
|
-
return childs;
|
|
2398
|
+
if (childs.length === 0) return childs;
|
|
2533
2399
|
const last = childs.length - 1;
|
|
2534
2400
|
let emptied = trimEdgeWhite(childs[0]);
|
|
2535
|
-
if (last > 0 && trimEdgeWhite(childs[last]))
|
|
2536
|
-
|
|
2537
|
-
for (let i = 1;i < last; i++) {
|
|
2401
|
+
if (last > 0 && trimEdgeWhite(childs[last])) emptied = true;
|
|
2402
|
+
for (let i = 1; i < last; i++) {
|
|
2538
2403
|
const cur = childs[i];
|
|
2539
|
-
if (!(cur.isWhiteSpace?.() && cur.hasNewLine()))
|
|
2540
|
-
continue;
|
|
2404
|
+
if (!(cur.isWhiteSpace?.() && cur.hasNewLine())) continue;
|
|
2541
2405
|
const bothBlock = isBlockDomNode(childs[i - 1]) && isBlockDomNode(childs[i + 1]);
|
|
2542
2406
|
cur.condenseWhiteSpace(bothBlock ? "" : " ");
|
|
2543
|
-
if (bothBlock)
|
|
2544
|
-
emptied = true;
|
|
2407
|
+
if (bothBlock) emptied = true;
|
|
2545
2408
|
}
|
|
2546
2409
|
return emptied ? childs.filter((c) => !isEmptyText(c)) : childs;
|
|
2547
2410
|
}
|
|
2548
|
-
|
|
2549
|
-
class View {
|
|
2411
|
+
var View = class {
|
|
2550
2412
|
constructor(name, rawView = "No View Defined", style = "", anode = null, ctx = null) {
|
|
2551
2413
|
this.name = name;
|
|
2552
2414
|
this.anode = anode;
|
|
@@ -2560,18 +2422,18 @@ class View {
|
|
|
2560
2422
|
this.anode.setDataAttr("data-cid", cid);
|
|
2561
2423
|
this.anode.setDataAttr("data-vid", this.name);
|
|
2562
2424
|
this.ctx.compile(scope);
|
|
2563
|
-
if (ctx.cacheConstNodes)
|
|
2564
|
-
this.anode = optimizeNode(this.anode);
|
|
2425
|
+
if (ctx.cacheConstNodes) this.anode = optimizeNode(this.anode);
|
|
2565
2426
|
}
|
|
2566
2427
|
render(stack, rx) {
|
|
2567
2428
|
if (this.anode === null) {
|
|
2568
|
-
throw new Error(
|
|
2429
|
+
throw new Error(
|
|
2430
|
+
`tutuca: view "${this.name}" was rendered before it was compiled — its component is not registered in this app/scope. Source: ${String(this.rawView).slice(0, 80).replace(/\s+/g, " ")}…`
|
|
2431
|
+
);
|
|
2569
2432
|
}
|
|
2570
2433
|
return this.anode.render(stack, rx);
|
|
2571
2434
|
}
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
|
-
class NodeEvents {
|
|
2435
|
+
};
|
|
2436
|
+
var NodeEvents = class {
|
|
2575
2437
|
constructor(id) {
|
|
2576
2438
|
this.id = id;
|
|
2577
2439
|
this.handlers = [];
|
|
@@ -2580,8 +2442,7 @@ class NodeEvents {
|
|
|
2580
2442
|
this.handlers.push(new NodeEvent(name, handlerCall, modifiers));
|
|
2581
2443
|
}
|
|
2582
2444
|
*genEventNames() {
|
|
2583
|
-
for (const handler of this.handlers)
|
|
2584
|
-
yield handler.name;
|
|
2445
|
+
for (const handler of this.handlers) yield handler.name;
|
|
2585
2446
|
}
|
|
2586
2447
|
getHandlersFor(eventName) {
|
|
2587
2448
|
let r = null;
|
|
@@ -2592,9 +2453,8 @@ class NodeEvents {
|
|
|
2592
2453
|
}
|
|
2593
2454
|
return r;
|
|
2594
2455
|
}
|
|
2595
|
-
}
|
|
2596
|
-
|
|
2597
|
-
class NodeEvent {
|
|
2456
|
+
};
|
|
2457
|
+
var NodeEvent = class {
|
|
2598
2458
|
constructor(name, handlerCall, modifiers) {
|
|
2599
2459
|
this.name = name;
|
|
2600
2460
|
this.handlerCall = handlerCall;
|
|
@@ -2609,7 +2469,7 @@ class NodeEvent {
|
|
|
2609
2469
|
r[0] = this.modifierWrapper(r[0], event);
|
|
2610
2470
|
return r;
|
|
2611
2471
|
}
|
|
2612
|
-
}
|
|
2472
|
+
};
|
|
2613
2473
|
var fwdIfCtxPred = (pred) => (w) => (that, f, args, ctx) => pred(ctx) ? w(that, f, args, ctx) : that;
|
|
2614
2474
|
var fwdIfKey = (keyName) => fwdIfCtxPred((ctx) => ctx.e.key === keyName);
|
|
2615
2475
|
var fwdCtrl = fwdIfCtxPred(({ e }) => isMac && e.metaKey || e.ctrlKey);
|
|
@@ -2626,14 +2486,12 @@ var MOD_WRAPPERS_BY_EVENT = {
|
|
|
2626
2486
|
};
|
|
2627
2487
|
var identityModifierWrapper = (f, _ctx) => f;
|
|
2628
2488
|
function compileModifiers(eventName, names) {
|
|
2629
|
-
if (names.length === 0)
|
|
2630
|
-
return identityModifierWrapper;
|
|
2489
|
+
if (names.length === 0) return identityModifierWrapper;
|
|
2631
2490
|
const wrappers = MOD_WRAPPERS_BY_EVENT[eventName] ?? {};
|
|
2632
2491
|
let w = (that, f, args, _ctx) => f.apply(that, args);
|
|
2633
2492
|
for (const name of names) {
|
|
2634
2493
|
const wrapper = wrappers[name];
|
|
2635
|
-
if (wrapper !==
|
|
2636
|
-
w = wrapper(w);
|
|
2494
|
+
if (wrapper !== void 0) w = wrapper(w);
|
|
2637
2495
|
}
|
|
2638
2496
|
return (f, ctx) => function(...args) {
|
|
2639
2497
|
return w(this, f, args, ctx);
|
|
@@ -2641,10 +2499,10 @@ function compileModifiers(eventName, names) {
|
|
|
2641
2499
|
}
|
|
2642
2500
|
|
|
2643
2501
|
// src/components.js
|
|
2644
|
-
|
|
2502
|
+
var Components = class {
|
|
2645
2503
|
constructor() {
|
|
2646
|
-
this.getComponentSymbol = Symbol("getComponent");
|
|
2647
|
-
this.byId = new Map;
|
|
2504
|
+
this.getComponentSymbol = /* @__PURE__ */ Symbol("getComponent");
|
|
2505
|
+
this.byId = /* @__PURE__ */ new Map();
|
|
2648
2506
|
}
|
|
2649
2507
|
registerComponent(comp) {
|
|
2650
2508
|
comp.Class.prototype[this.getComponentSymbol] = () => comp;
|
|
@@ -2664,15 +2522,12 @@ class Components {
|
|
|
2664
2522
|
}
|
|
2665
2523
|
compileStyles() {
|
|
2666
2524
|
const styles = [];
|
|
2667
|
-
for (const comp of this.byId.values())
|
|
2668
|
-
|
|
2669
|
-
return styles.join(`
|
|
2670
|
-
`);
|
|
2525
|
+
for (const comp of this.byId.values()) styles.push(comp.compileStyle());
|
|
2526
|
+
return styles.join("\n");
|
|
2671
2527
|
}
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
constructor(comps = new Components, parent = null) {
|
|
2528
|
+
};
|
|
2529
|
+
var ComponentStack = class _ComponentStack {
|
|
2530
|
+
constructor(comps = new Components(), parent = null) {
|
|
2676
2531
|
this.comps = comps;
|
|
2677
2532
|
this.parent = parent;
|
|
2678
2533
|
this.byName = {};
|
|
@@ -2680,11 +2535,11 @@ class ComponentStack {
|
|
|
2680
2535
|
this.macros = {};
|
|
2681
2536
|
}
|
|
2682
2537
|
enter() {
|
|
2683
|
-
return new
|
|
2538
|
+
return new _ComponentStack(this.comps, this);
|
|
2684
2539
|
}
|
|
2685
2540
|
registerComponents(comps, opts) {
|
|
2686
2541
|
const { aliases = {} } = opts ?? {};
|
|
2687
|
-
for (let i = 0;i < comps.length; i++) {
|
|
2542
|
+
for (let i = 0; i < comps.length; i++) {
|
|
2688
2543
|
const comp = comps[i];
|
|
2689
2544
|
comp.scope = this.enter();
|
|
2690
2545
|
comp.Class.scope = comp.scope;
|
|
@@ -2693,17 +2548,15 @@ class ComponentStack {
|
|
|
2693
2548
|
}
|
|
2694
2549
|
for (const alias in aliases) {
|
|
2695
2550
|
const comp = this.byName[aliases[alias]];
|
|
2696
|
-
console.assert(this.byName[alias] ===
|
|
2697
|
-
if (comp !==
|
|
2698
|
-
|
|
2699
|
-
else
|
|
2700
|
-
console.warn("alias", alias, "to inexistent component", aliases[alias]);
|
|
2551
|
+
console.assert(this.byName[alias] === void 0, "alias overrides component", alias);
|
|
2552
|
+
if (comp !== void 0) this.byName[alias] = comp;
|
|
2553
|
+
else console.warn("alias", alias, "to inexistent component", aliases[alias]);
|
|
2701
2554
|
}
|
|
2702
2555
|
}
|
|
2703
2556
|
registerMacros(macros) {
|
|
2704
2557
|
for (const key in macros) {
|
|
2705
2558
|
const lower = key.toLowerCase();
|
|
2706
|
-
console.assert(this.macros[lower] ===
|
|
2559
|
+
console.assert(this.macros[lower] === void 0, "macro key collision", lower);
|
|
2707
2560
|
this.macros[lower] = macros[key];
|
|
2708
2561
|
}
|
|
2709
2562
|
}
|
|
@@ -2711,8 +2564,7 @@ class ComponentStack {
|
|
|
2711
2564
|
return this.comps.getCompFor(v);
|
|
2712
2565
|
}
|
|
2713
2566
|
registerRequestHandlers(handlers) {
|
|
2714
|
-
for (const name in handlers)
|
|
2715
|
-
this.reqsByName[name] = new RequestHandler(name, handlers[name]);
|
|
2567
|
+
for (const name in handlers) this.reqsByName[name] = new RequestHandler(name, handlers[name]);
|
|
2716
2568
|
}
|
|
2717
2569
|
lookupRequest(name) {
|
|
2718
2570
|
return this.reqsByName[name] ?? this.parent?.lookupRequest(name) ?? null;
|
|
@@ -2723,36 +2575,33 @@ class ComponentStack {
|
|
|
2723
2575
|
lookupMacro(name) {
|
|
2724
2576
|
return this.macros[name] ?? this.parent?.lookupMacro(name) ?? null;
|
|
2725
2577
|
}
|
|
2726
|
-
}
|
|
2727
|
-
|
|
2728
|
-
class ProvideInfo {
|
|
2578
|
+
};
|
|
2579
|
+
var ProvideInfo = class {
|
|
2729
2580
|
constructor(name, val, symbol) {
|
|
2730
2581
|
this.name = name;
|
|
2731
2582
|
this.val = val;
|
|
2732
2583
|
this.symbol = symbol;
|
|
2733
2584
|
}
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
class LookupInfo {
|
|
2585
|
+
};
|
|
2586
|
+
var LookupInfo = class {
|
|
2737
2587
|
constructor(name, compName, provideName, val) {
|
|
2738
2588
|
this.name = name;
|
|
2739
2589
|
this.compName = compName;
|
|
2740
2590
|
this.provideName = provideName;
|
|
2741
2591
|
this.val = val;
|
|
2742
|
-
this._sym =
|
|
2592
|
+
this._sym = void 0;
|
|
2743
2593
|
}
|
|
2744
2594
|
getProducerSymbol(stack) {
|
|
2745
|
-
if (this._sym ===
|
|
2595
|
+
if (this._sym === void 0)
|
|
2746
2596
|
this._sym = stack.lookupType(this.compName)?.provide?.[this.provideName]?.symbol ?? null;
|
|
2747
2597
|
return this._sym;
|
|
2748
2598
|
}
|
|
2749
|
-
}
|
|
2599
|
+
};
|
|
2750
2600
|
var isString = (v) => typeof v === "string";
|
|
2751
2601
|
var _rawSpecKeys = "name view style commonStyle globalStyle input receive bubble response alter views provide lookup fields methods statics";
|
|
2752
2602
|
var KNOWN_SPEC_KEYS = new Set(_rawSpecKeys.split(" "));
|
|
2753
2603
|
var _compId = 0;
|
|
2754
|
-
|
|
2755
|
-
class Component {
|
|
2604
|
+
var Component = class {
|
|
2756
2605
|
constructor(Class, o) {
|
|
2757
2606
|
this.id = _compId++;
|
|
2758
2607
|
this.name = o.name ?? "UnkComp";
|
|
@@ -2777,31 +2626,27 @@ class Component {
|
|
|
2777
2626
|
this.scope = null;
|
|
2778
2627
|
this.spec = o;
|
|
2779
2628
|
this.extra = {};
|
|
2780
|
-
for (const key of Object.keys(o))
|
|
2781
|
-
if (!KNOWN_SPEC_KEYS.has(key))
|
|
2782
|
-
this.extra[key] = o[key];
|
|
2629
|
+
for (const key of Object.keys(o)) if (!KNOWN_SPEC_KEYS.has(key)) this.extra[key] = o[key];
|
|
2783
2630
|
}
|
|
2784
2631
|
compile(ParseContext2) {
|
|
2785
2632
|
for (const name in this.views)
|
|
2786
|
-
this.views[name].compile(new ParseContext2, this.scope, this.id);
|
|
2633
|
+
this.views[name].compile(new ParseContext2(), this.scope, this.id);
|
|
2787
2634
|
const ctx = this.views.main.ctx;
|
|
2788
2635
|
for (const key in this._rawProvide) {
|
|
2789
|
-
const val =
|
|
2790
|
-
if (val)
|
|
2791
|
-
this.provide[key] = new ProvideInfo(key, val, Symbol(key));
|
|
2636
|
+
const val = parseProvide(this._rawProvide[key], ctx);
|
|
2637
|
+
if (val) this.provide[key] = new ProvideInfo(key, val, Symbol(key));
|
|
2792
2638
|
}
|
|
2793
2639
|
for (const key in this._rawLookup) {
|
|
2794
2640
|
const linfo = this._rawLookup[key];
|
|
2795
2641
|
const forStr = isString(linfo) ? linfo : isString(linfo?.for) ? linfo.for : null;
|
|
2796
2642
|
const [compName, provideName] = forStr === null ? [] : forStr.split(".");
|
|
2797
|
-
if (!isString(compName) || !isString(provideName))
|
|
2798
|
-
continue;
|
|
2643
|
+
if (!isString(compName) || !isString(provideName)) continue;
|
|
2799
2644
|
const defStr = isString(linfo?.default) ? linfo.default : null;
|
|
2800
|
-
const val = defStr === null ? null :
|
|
2645
|
+
const val = defStr === null ? null : parseField(defStr, ctx);
|
|
2801
2646
|
this.lookup[key] = new LookupInfo(key, compName, provideName, val);
|
|
2802
2647
|
}
|
|
2803
2648
|
for (const key in this.lookup)
|
|
2804
|
-
if (this.provide[key] !==
|
|
2649
|
+
if (this.provide[key] !== void 0)
|
|
2805
2650
|
console.warn("name declared in both provide and lookup", this.name, key);
|
|
2806
2651
|
}
|
|
2807
2652
|
make(args, opts) {
|
|
@@ -2819,35 +2664,29 @@ class Component {
|
|
|
2819
2664
|
compileStyle() {
|
|
2820
2665
|
const { id, commonStyle, globalStyle, views } = this;
|
|
2821
2666
|
const styles = commonStyle ? [`[data-cid="${id}"]{${commonStyle}}`] : [];
|
|
2822
|
-
if (globalStyle !== "")
|
|
2823
|
-
styles.push(globalStyle);
|
|
2667
|
+
if (globalStyle !== "") styles.push(globalStyle);
|
|
2824
2668
|
for (const name in views) {
|
|
2825
2669
|
const { style } = views[name];
|
|
2826
|
-
if (style !== "")
|
|
2827
|
-
styles.push(`[data-cid="${id}"][data-vid="${name}"]{${style}}`);
|
|
2670
|
+
if (style !== "") styles.push(`[data-cid="${id}"][data-vid="${name}"]{${style}}`);
|
|
2828
2671
|
}
|
|
2829
|
-
return styles.join(
|
|
2830
|
-
`);
|
|
2672
|
+
return styles.join("\n");
|
|
2831
2673
|
}
|
|
2832
|
-
}
|
|
2674
|
+
};
|
|
2833
2675
|
|
|
2834
2676
|
// src/stack.js
|
|
2835
|
-
var STOP = Symbol("STOP");
|
|
2836
|
-
var NEXT = Symbol("NEXT");
|
|
2677
|
+
var STOP = /* @__PURE__ */ Symbol("STOP");
|
|
2678
|
+
var NEXT = /* @__PURE__ */ Symbol("NEXT");
|
|
2837
2679
|
function lookup(chain, name, dv = null) {
|
|
2838
2680
|
let n = chain;
|
|
2839
2681
|
while (n !== null) {
|
|
2840
2682
|
const r = n[0].lookup(name);
|
|
2841
|
-
if (r === STOP)
|
|
2842
|
-
|
|
2843
|
-
if (r !== NEXT)
|
|
2844
|
-
return r;
|
|
2683
|
+
if (r === STOP) return dv;
|
|
2684
|
+
if (r !== NEXT) return r;
|
|
2845
2685
|
n = n[1];
|
|
2846
2686
|
}
|
|
2847
2687
|
return dv;
|
|
2848
2688
|
}
|
|
2849
|
-
|
|
2850
|
-
class BindFrame {
|
|
2689
|
+
var BindFrame = class {
|
|
2851
2690
|
constructor(it, binds, isFrame) {
|
|
2852
2691
|
this.it = it;
|
|
2853
2692
|
this.binds = binds;
|
|
@@ -2855,19 +2694,18 @@ class BindFrame {
|
|
|
2855
2694
|
}
|
|
2856
2695
|
lookup(name) {
|
|
2857
2696
|
const v = this.binds[name];
|
|
2858
|
-
return v ===
|
|
2697
|
+
return v === void 0 ? this.isFrame ? STOP : NEXT : v;
|
|
2859
2698
|
}
|
|
2860
|
-
}
|
|
2861
|
-
|
|
2862
|
-
class ObjectFrame {
|
|
2699
|
+
};
|
|
2700
|
+
var ObjectFrame = class {
|
|
2863
2701
|
constructor(binds) {
|
|
2864
2702
|
this.binds = binds;
|
|
2865
2703
|
}
|
|
2866
2704
|
lookup(key) {
|
|
2867
2705
|
const v = this.binds[key];
|
|
2868
|
-
return v ===
|
|
2706
|
+
return v === void 0 ? NEXT : v;
|
|
2869
2707
|
}
|
|
2870
|
-
}
|
|
2708
|
+
};
|
|
2871
2709
|
function computeViewsId(views) {
|
|
2872
2710
|
let s = "";
|
|
2873
2711
|
let n = views;
|
|
@@ -2877,8 +2715,7 @@ function computeViewsId(views) {
|
|
|
2877
2715
|
}
|
|
2878
2716
|
return s === "main" ? "" : s;
|
|
2879
2717
|
}
|
|
2880
|
-
|
|
2881
|
-
class Stack {
|
|
2718
|
+
var Stack = class _Stack {
|
|
2882
2719
|
constructor(comps, it, binds, dynBinds, views, viewsId, ctx = null) {
|
|
2883
2720
|
this.comps = comps;
|
|
2884
2721
|
this.it = it;
|
|
@@ -2888,44 +2725,42 @@ class Stack {
|
|
|
2888
2725
|
this.viewsId = viewsId;
|
|
2889
2726
|
this.ctx = ctx;
|
|
2890
2727
|
}
|
|
2728
|
+
// Evaluate every provide the entered component publishes and push them as one
|
|
2729
|
+
// dynBinds frame (keyed by each provide's symbol). No-op when there are no provides.
|
|
2891
2730
|
_pushProvides() {
|
|
2892
2731
|
const provide = this.comps.getCompFor(this.it)?.provide;
|
|
2893
|
-
if (provide == null)
|
|
2894
|
-
return this;
|
|
2732
|
+
if (provide == null) return this;
|
|
2895
2733
|
const dynObj = {};
|
|
2896
|
-
let
|
|
2734
|
+
let has2 = false;
|
|
2897
2735
|
for (const k in provide) {
|
|
2898
2736
|
dynObj[provide[k].symbol] = provide[k].val.eval(this);
|
|
2899
|
-
|
|
2737
|
+
has2 = true;
|
|
2900
2738
|
}
|
|
2901
|
-
if (!
|
|
2902
|
-
return this;
|
|
2739
|
+
if (!has2) return this;
|
|
2903
2740
|
const newDynBinds = [new ObjectFrame(dynObj), this.dynBinds];
|
|
2904
2741
|
const { comps, it, binds, views, viewsId, ctx } = this;
|
|
2905
|
-
return new
|
|
2742
|
+
return new _Stack(comps, it, binds, newDynBinds, views, viewsId, ctx);
|
|
2906
2743
|
}
|
|
2907
2744
|
static root(comps, it, ctx) {
|
|
2908
2745
|
const binds = [new BindFrame(it, {}, true), null];
|
|
2909
2746
|
const dynBinds = [new ObjectFrame({}), null];
|
|
2910
2747
|
const views = ["main", null];
|
|
2911
|
-
return new
|
|
2748
|
+
return new _Stack(comps, it, binds, dynBinds, views, "", ctx)._pushProvides();
|
|
2912
2749
|
}
|
|
2913
2750
|
enter(it, bindings = {}, isFrame = true) {
|
|
2914
2751
|
const { comps, binds, dynBinds, views, viewsId, ctx } = this;
|
|
2915
2752
|
const newBinds = [new BindFrame(it, bindings, isFrame), binds];
|
|
2916
|
-
const stack = new
|
|
2753
|
+
const stack = new _Stack(comps, it, newBinds, dynBinds, views, viewsId, ctx);
|
|
2917
2754
|
return isFrame ? stack._pushProvides() : stack;
|
|
2918
2755
|
}
|
|
2919
2756
|
pushViewName(name) {
|
|
2920
2757
|
const { comps, it, binds, dynBinds, views, ctx } = this;
|
|
2921
2758
|
const newViews = [name, views];
|
|
2922
|
-
return new
|
|
2759
|
+
return new _Stack(comps, it, binds, dynBinds, newViews, computeViewsId(newViews), ctx);
|
|
2923
2760
|
}
|
|
2924
2761
|
_pushDynBindValuesToArray(arr, comp) {
|
|
2925
|
-
for (const k in comp.provide)
|
|
2926
|
-
|
|
2927
|
-
for (const k in comp.lookup)
|
|
2928
|
-
arr.push(this._lookupAlias(comp.lookup[k]));
|
|
2762
|
+
for (const k in comp.provide) arr.push(this._lookupProvide(comp.provide[k]));
|
|
2763
|
+
for (const k in comp.lookup) arr.push(this._lookupAlias(comp.lookup[k]));
|
|
2929
2764
|
}
|
|
2930
2765
|
_lookupProvide(p) {
|
|
2931
2766
|
return lookup(this.dynBinds, p.symbol) ?? p.val.eval(this) ?? null;
|
|
@@ -2936,13 +2771,11 @@ class Stack {
|
|
|
2936
2771
|
}
|
|
2937
2772
|
lookupDynamic(name) {
|
|
2938
2773
|
const comp = this.comps.getCompFor(this.it);
|
|
2939
|
-
if (comp == null)
|
|
2940
|
-
return null;
|
|
2774
|
+
if (comp == null) return null;
|
|
2941
2775
|
const lk = comp.lookup[name];
|
|
2942
|
-
if (lk !==
|
|
2943
|
-
return this._lookupAlias(lk);
|
|
2776
|
+
if (lk !== void 0) return this._lookupAlias(lk);
|
|
2944
2777
|
const p = comp.provide[name];
|
|
2945
|
-
return p !==
|
|
2778
|
+
return p !== void 0 ? this._lookupProvide(p) : null;
|
|
2946
2779
|
}
|
|
2947
2780
|
lookupBind(name) {
|
|
2948
2781
|
return lookup(this.binds, name);
|
|
@@ -2967,16 +2800,15 @@ class Stack {
|
|
|
2967
2800
|
let n = this.views;
|
|
2968
2801
|
while (n !== null) {
|
|
2969
2802
|
const view = views[n[0]];
|
|
2970
|
-
if (view !==
|
|
2971
|
-
return view;
|
|
2803
|
+
if (view !== void 0) return view;
|
|
2972
2804
|
n = n[1];
|
|
2973
2805
|
}
|
|
2974
2806
|
return views[defaultViewName];
|
|
2975
2807
|
}
|
|
2976
|
-
}
|
|
2808
|
+
};
|
|
2977
2809
|
|
|
2978
2810
|
// src/transactor.js
|
|
2979
|
-
|
|
2811
|
+
var State = class {
|
|
2980
2812
|
constructor(val) {
|
|
2981
2813
|
this.val = val;
|
|
2982
2814
|
this.changeSubs = [];
|
|
@@ -2987,44 +2819,47 @@ class State {
|
|
|
2987
2819
|
set(val, info) {
|
|
2988
2820
|
const old = this.val;
|
|
2989
2821
|
this.val = val;
|
|
2990
|
-
for (const sub of this.changeSubs)
|
|
2991
|
-
sub({ val, old, info, timestamp: Date.now() });
|
|
2822
|
+
for (const sub of this.changeSubs) sub({ val, old, info, timestamp: Date.now() });
|
|
2992
2823
|
}
|
|
2993
2824
|
update(fn, info) {
|
|
2994
2825
|
return this.set(fn(this.val), info);
|
|
2995
2826
|
}
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
|
-
class Transactor {
|
|
2827
|
+
};
|
|
2828
|
+
var Transactor = class {
|
|
2999
2829
|
constructor(comps, rootValue) {
|
|
3000
2830
|
this.comps = comps;
|
|
3001
2831
|
this.transactions = [];
|
|
3002
2832
|
this.state = new State(rootValue);
|
|
3003
|
-
this.onTransactionPushed = () => {
|
|
2833
|
+
this.onTransactionPushed = () => {
|
|
2834
|
+
};
|
|
3004
2835
|
this._observers = [];
|
|
3005
|
-
this._inflight = new Set;
|
|
2836
|
+
this._inflight = /* @__PURE__ */ new Set();
|
|
3006
2837
|
}
|
|
3007
2838
|
pushTransaction(t) {
|
|
3008
2839
|
this.transactions.push(t);
|
|
3009
2840
|
this.onTransactionPushed(t);
|
|
3010
2841
|
}
|
|
2842
|
+
// Subscribe to a normalized record for every handler invocation (send/receive,
|
|
2843
|
+
// bubble, request/response, input). Returns an unsubscribe function. Records
|
|
2844
|
+
// carry: kind, name, args, path, pathKeys, targetPath, handler, handlerName,
|
|
2845
|
+
// matched, before, after, parent, timestamp. Purely observational.
|
|
3011
2846
|
observe(cb) {
|
|
3012
2847
|
this._observers.push(cb);
|
|
3013
2848
|
return () => {
|
|
3014
2849
|
const i = this._observers.indexOf(cb);
|
|
3015
|
-
if (i !== -1)
|
|
3016
|
-
this._observers.splice(i, 1);
|
|
2850
|
+
if (i !== -1) this._observers.splice(i, 1);
|
|
3017
2851
|
};
|
|
3018
2852
|
}
|
|
3019
2853
|
_emit(record) {
|
|
3020
|
-
for (const cb of this._observers)
|
|
3021
|
-
cb(record);
|
|
2854
|
+
for (const cb of this._observers) cb(record);
|
|
3022
2855
|
}
|
|
2856
|
+
// Build and dispatch the observer record for a settled transaction. The
|
|
2857
|
+
// resolved handler (`_resolvedHandler`/`_matched`) and per-leaf before/after
|
|
2858
|
+
// (`_before`/`_after`) were captured while the handler ran (see callHandler /
|
|
2859
|
+
// updateRootValue). No-op when nobody is observing.
|
|
3023
2860
|
_emitTransaction(transaction, root) {
|
|
3024
|
-
if (this._observers.length === 0)
|
|
3025
|
-
|
|
3026
|
-
if (transaction._resolvedHandler === undefined)
|
|
3027
|
-
return;
|
|
2861
|
+
if (this._observers.length === 0) return;
|
|
2862
|
+
if (transaction._resolvedHandler === void 0) return;
|
|
3028
2863
|
const path = transaction.getTransactionPath().pinKeys(root);
|
|
3029
2864
|
this._emit({
|
|
3030
2865
|
kind: transaction.observeKind,
|
|
@@ -3042,6 +2877,10 @@ class Transactor {
|
|
|
3042
2877
|
timestamp: Date.now()
|
|
3043
2878
|
});
|
|
3044
2879
|
}
|
|
2880
|
+
// Make `child` a tracked unit of `parent`'s subtree: the parent's completion stays open
|
|
2881
|
+
// until the child's *whole* subtree settles. Tracking happens at dispatch time — during
|
|
2882
|
+
// the parent's handler or afterTransaction — while the parent's self-unit is still held,
|
|
2883
|
+
// so the parent counter can't reach zero before the child is registered. Returns `child`.
|
|
3045
2884
|
_link(child, parent) {
|
|
3046
2885
|
if (parent) {
|
|
3047
2886
|
const release = parent.completion.track();
|
|
@@ -3072,12 +2911,13 @@ class Transactor {
|
|
|
3072
2911
|
p.finally(() => this._inflight.delete(p));
|
|
3073
2912
|
return p;
|
|
3074
2913
|
}
|
|
2914
|
+
// Drain queued transactions and await in-flight requests until quiescent. Each
|
|
2915
|
+
// awaited request enqueues a ResponseEvent, which may dispatch more work, so we
|
|
2916
|
+
// loop. `maxTurns` backstops a pathological non-terminating cascade.
|
|
3075
2917
|
async settle(maxTurns = 1e4) {
|
|
3076
2918
|
while ((this.hasPendingTransactions || this._inflight.size) && maxTurns-- > 0) {
|
|
3077
|
-
while (this.hasPendingTransactions)
|
|
3078
|
-
|
|
3079
|
-
if (this._inflight.size)
|
|
3080
|
-
await Promise.allSettled([...this._inflight]);
|
|
2919
|
+
while (this.hasPendingTransactions) this.transactNext();
|
|
2920
|
+
if (this._inflight.size) await Promise.allSettled([...this._inflight]);
|
|
3081
2921
|
}
|
|
3082
2922
|
}
|
|
3083
2923
|
async _runRequest(path, name, args = [], opts = {}, parent = null, release = null) {
|
|
@@ -3107,7 +2947,7 @@ class Transactor {
|
|
|
3107
2947
|
handlerName: found?.fn?.name || name,
|
|
3108
2948
|
matched: found ? "exact" : "none",
|
|
3109
2949
|
before: curLeaf,
|
|
3110
|
-
after:
|
|
2950
|
+
after: void 0,
|
|
3111
2951
|
parent,
|
|
3112
2952
|
timestamp: Date.now()
|
|
3113
2953
|
});
|
|
@@ -3128,27 +2968,24 @@ class Transactor {
|
|
|
3128
2968
|
push(opts?.onErrorName, resHandlerName, error, null, error);
|
|
3129
2969
|
}
|
|
3130
2970
|
} finally {
|
|
3131
|
-
if (release && !released)
|
|
3132
|
-
release();
|
|
2971
|
+
if (release && !released) release();
|
|
3133
2972
|
}
|
|
3134
2973
|
}
|
|
3135
2974
|
get hasPendingTransactions() {
|
|
3136
2975
|
return this.transactions.length > 0;
|
|
3137
2976
|
}
|
|
3138
2977
|
transactNext() {
|
|
3139
|
-
if (this.hasPendingTransactions)
|
|
3140
|
-
this.transact(this.transactions.shift());
|
|
2978
|
+
if (this.hasPendingTransactions) this.transact(this.transactions.shift());
|
|
3141
2979
|
}
|
|
3142
2980
|
transact(transaction) {
|
|
3143
2981
|
try {
|
|
3144
2982
|
const curState = this.state.val;
|
|
3145
2983
|
const newState = transaction.run(curState, this.comps);
|
|
3146
|
-
if (newState !==
|
|
2984
|
+
if (newState !== void 0) {
|
|
3147
2985
|
this.state.set(newState, { transaction });
|
|
3148
2986
|
transaction.afterTransaction();
|
|
3149
2987
|
this._emitTransaction(transaction, curState);
|
|
3150
|
-
} else
|
|
3151
|
-
console.warn("undefined new state", { curState, transaction });
|
|
2988
|
+
} else console.warn("undefined new state", { curState, transaction });
|
|
3152
2989
|
} finally {
|
|
3153
2990
|
transaction._completion?.ensureSelfSettled();
|
|
3154
2991
|
transaction._completion?.releaseSelf();
|
|
@@ -3157,7 +2994,7 @@ class Transactor {
|
|
|
3157
2994
|
transactInputNow(path, event, eventHandler, dragInfo) {
|
|
3158
2995
|
this.transact(new InputEvent(path, event, eventHandler, this, dragInfo));
|
|
3159
2996
|
}
|
|
3160
|
-
}
|
|
2997
|
+
};
|
|
3161
2998
|
function mkReq404(name) {
|
|
3162
2999
|
const fn = () => {
|
|
3163
3000
|
throw new Error(`Request not found: ${name}`);
|
|
@@ -3167,37 +3004,46 @@ function mkReq404(name) {
|
|
|
3167
3004
|
function nullHandler() {
|
|
3168
3005
|
return this;
|
|
3169
3006
|
}
|
|
3170
|
-
|
|
3171
|
-
class Transaction {
|
|
3007
|
+
var Transaction = class {
|
|
3172
3008
|
constructor(path, transactor, parentTransaction = null) {
|
|
3173
3009
|
this.path = path;
|
|
3174
3010
|
this.transactor = transactor;
|
|
3175
3011
|
this.parentTransaction = parentTransaction;
|
|
3176
3012
|
this._completion = null;
|
|
3177
3013
|
}
|
|
3014
|
+
// Lazily created (like the rest of the per-transaction state): a leaf event that
|
|
3015
|
+
// nobody tracks or awaits never allocates one. See `class Completion`.
|
|
3178
3016
|
get completion() {
|
|
3179
|
-
this._completion ??= new Completion;
|
|
3017
|
+
this._completion ??= new Completion();
|
|
3180
3018
|
return this._completion;
|
|
3181
3019
|
}
|
|
3020
|
+
// Resolves once this transaction's own handler has run.
|
|
3182
3021
|
whenSettled() {
|
|
3183
3022
|
return this.completion.whenSettled();
|
|
3184
3023
|
}
|
|
3024
|
+
// Resolves once this transaction AND all transitively-derived work (sends, bubbles,
|
|
3025
|
+
// requests and the responses they produce, recursively) have settled.
|
|
3185
3026
|
whenSubtreeSettled() {
|
|
3186
3027
|
return this.completion.whenSubtreeSettled();
|
|
3187
3028
|
}
|
|
3188
3029
|
run(rootValue, comps) {
|
|
3189
3030
|
return this.updateRootValue(rootValue, comps);
|
|
3190
3031
|
}
|
|
3191
|
-
afterTransaction() {
|
|
3032
|
+
afterTransaction() {
|
|
3033
|
+
}
|
|
3192
3034
|
buildRootStack(root, comps) {
|
|
3193
3035
|
return Stack.root(comps, root);
|
|
3194
3036
|
}
|
|
3195
3037
|
buildStack(root, comps) {
|
|
3196
3038
|
return this.path.toTransactionPath().buildStack(this.buildRootStack(root, comps));
|
|
3197
3039
|
}
|
|
3040
|
+
// The kind reported to observers (see Transactor.observe); null on the base.
|
|
3198
3041
|
get observeKind() {
|
|
3199
3042
|
return null;
|
|
3200
3043
|
}
|
|
3044
|
+
// The name reported to observers; null on the base. Overridden by NameArgs (the
|
|
3045
|
+
// dispatched message name) and InputEvent (the DOM event type). Kept separate from
|
|
3046
|
+
// `name`/`ctx.name` so it can't change handler-visible behavior.
|
|
3201
3047
|
get observeName() {
|
|
3202
3048
|
return null;
|
|
3203
3049
|
}
|
|
@@ -3209,6 +3055,9 @@ class Transaction {
|
|
|
3209
3055
|
getHandlerAndArgs(_root, _instance, _comps) {
|
|
3210
3056
|
return null;
|
|
3211
3057
|
}
|
|
3058
|
+
// The path used to apply the mutation. Teleports dynamic-var renders so it lands on
|
|
3059
|
+
// the data's real location (the dispatch `this.path` keeps intermediates). A subclass
|
|
3060
|
+
// may override to supply a pre-resolved path (see ResponseEvent's pinned keys).
|
|
3212
3061
|
getTransactionPath() {
|
|
3213
3062
|
return this.path.toTransactionPath();
|
|
3214
3063
|
}
|
|
@@ -3224,13 +3073,12 @@ class Transaction {
|
|
|
3224
3073
|
lookupName(_name) {
|
|
3225
3074
|
return null;
|
|
3226
3075
|
}
|
|
3227
|
-
}
|
|
3076
|
+
};
|
|
3228
3077
|
var toNullIfNaN = (v) => Number.isNaN(v) ? null : v;
|
|
3229
3078
|
function getValue(e) {
|
|
3230
3079
|
return e.target.type === "checkbox" ? e.target.checked : (e instanceof CustomEvent ? e.detail : e.target.value) ?? null;
|
|
3231
3080
|
}
|
|
3232
|
-
|
|
3233
|
-
class InputEvent extends Transaction {
|
|
3081
|
+
var InputEvent = class extends Transaction {
|
|
3234
3082
|
constructor(path, e, handler, transactor, dragInfo) {
|
|
3235
3083
|
super(path, transactor);
|
|
3236
3084
|
this.e = e;
|
|
@@ -3238,6 +3086,8 @@ class InputEvent extends Transaction {
|
|
|
3238
3086
|
this.dragInfo = dragInfo;
|
|
3239
3087
|
this._dispatchPath = null;
|
|
3240
3088
|
}
|
|
3089
|
+
// Frame steps removed, DynStep + one step per crossed component kept: bubbling
|
|
3090
|
+
// it visits every component (including intermediates of a dynamic-var render).
|
|
3241
3091
|
get dispatchPath() {
|
|
3242
3092
|
this._dispatchPath ??= this.path.compact();
|
|
3243
3093
|
return this._dispatchPath;
|
|
@@ -3276,6 +3126,7 @@ class InputEvent extends Transaction {
|
|
|
3276
3126
|
case "isShift":
|
|
3277
3127
|
return e.shiftKey;
|
|
3278
3128
|
case "isCtrl":
|
|
3129
|
+
/* falls through */
|
|
3279
3130
|
case "isCmd":
|
|
3280
3131
|
return isMac && e.metaKey || e.ctrlKey;
|
|
3281
3132
|
case "key":
|
|
@@ -3299,9 +3150,8 @@ class InputEvent extends Transaction {
|
|
|
3299
3150
|
}
|
|
3300
3151
|
return null;
|
|
3301
3152
|
}
|
|
3302
|
-
}
|
|
3303
|
-
|
|
3304
|
-
class NameArgsTransaction extends Transaction {
|
|
3153
|
+
};
|
|
3154
|
+
var NameArgsTransaction = class extends Transaction {
|
|
3305
3155
|
constructor(path, transactor, name, args, parentTransaction, opts = {}) {
|
|
3306
3156
|
super(path, transactor, parentTransaction);
|
|
3307
3157
|
this.name = name;
|
|
@@ -3310,6 +3160,8 @@ class NameArgsTransaction extends Transaction {
|
|
|
3310
3160
|
this.targetPath = path;
|
|
3311
3161
|
}
|
|
3312
3162
|
handlerProp = null;
|
|
3163
|
+
// NameArgs verbs map their handler bucket straight to the observed kind:
|
|
3164
|
+
// receive / bubble / response / input.
|
|
3313
3165
|
get observeKind() {
|
|
3314
3166
|
return this.handlerProp;
|
|
3315
3167
|
}
|
|
@@ -3335,9 +3187,8 @@ class NameArgsTransaction extends Transaction {
|
|
|
3335
3187
|
const handler = this.getHandlerForName(comps.getCompFor(instance));
|
|
3336
3188
|
return [handler, [...this.args, new EventContext(this.path, this.transactor, this)]];
|
|
3337
3189
|
}
|
|
3338
|
-
}
|
|
3339
|
-
|
|
3340
|
-
class ResponseEvent extends NameArgsTransaction {
|
|
3190
|
+
};
|
|
3191
|
+
var ResponseEvent = class extends NameArgsTransaction {
|
|
3341
3192
|
handlerProp = "response";
|
|
3342
3193
|
constructor(path, transactor, name, args, parent, txnPath = null) {
|
|
3343
3194
|
super(path, transactor, name, args, parent);
|
|
@@ -3346,9 +3197,8 @@ class ResponseEvent extends NameArgsTransaction {
|
|
|
3346
3197
|
getTransactionPath() {
|
|
3347
3198
|
return this._txnPath ?? super.getTransactionPath();
|
|
3348
3199
|
}
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
class SendEvent extends NameArgsTransaction {
|
|
3200
|
+
};
|
|
3201
|
+
var SendEvent = class extends NameArgsTransaction {
|
|
3352
3202
|
handlerProp = "receive";
|
|
3353
3203
|
run(rootVal, comps) {
|
|
3354
3204
|
return this.opts.skipSelf ? rootVal : this.updateRootValue(rootVal, comps);
|
|
@@ -3358,9 +3208,8 @@ class SendEvent extends NameArgsTransaction {
|
|
|
3358
3208
|
if (opts.bubbles && path.steps.length > 0)
|
|
3359
3209
|
this.transactor.pushBubble(path.popStep(), name, args, opts, this, targetPath);
|
|
3360
3210
|
}
|
|
3361
|
-
}
|
|
3362
|
-
|
|
3363
|
-
class BubbleEvent extends SendEvent {
|
|
3211
|
+
};
|
|
3212
|
+
var BubbleEvent = class extends SendEvent {
|
|
3364
3213
|
handlerProp = "bubble";
|
|
3365
3214
|
constructor(path, transactor, name, args, parent, opts, targetPath) {
|
|
3366
3215
|
super(path, transactor, name, args, parent, opts);
|
|
@@ -3369,15 +3218,13 @@ class BubbleEvent extends SendEvent {
|
|
|
3369
3218
|
stopPropagation() {
|
|
3370
3219
|
this.opts.bubbles = false;
|
|
3371
3220
|
}
|
|
3372
|
-
}
|
|
3373
|
-
|
|
3374
|
-
class InputDispatchEvent extends NameArgsTransaction {
|
|
3221
|
+
};
|
|
3222
|
+
var InputDispatchEvent = class extends NameArgsTransaction {
|
|
3375
3223
|
handlerProp = "input";
|
|
3376
|
-
}
|
|
3377
|
-
|
|
3378
|
-
class Completion {
|
|
3224
|
+
};
|
|
3225
|
+
var Completion = class {
|
|
3379
3226
|
constructor() {
|
|
3380
|
-
this.val =
|
|
3227
|
+
this.val = void 0;
|
|
3381
3228
|
this.selfSettled = false;
|
|
3382
3229
|
this.subtreeSettled = false;
|
|
3383
3230
|
this.pending = 1;
|
|
@@ -3388,45 +3235,42 @@ class Completion {
|
|
|
3388
3235
|
this._selfReleased = false;
|
|
3389
3236
|
}
|
|
3390
3237
|
whenSettled() {
|
|
3391
|
-
if (this.selfSettled)
|
|
3392
|
-
return Promise.resolve(this.val);
|
|
3238
|
+
if (this.selfSettled) return Promise.resolve(this.val);
|
|
3393
3239
|
this._selfPromise ??= new Promise((res) => {
|
|
3394
3240
|
this._selfResolve = res;
|
|
3395
3241
|
});
|
|
3396
3242
|
return this._selfPromise;
|
|
3397
3243
|
}
|
|
3398
3244
|
whenSubtreeSettled() {
|
|
3399
|
-
if (this.subtreeSettled)
|
|
3400
|
-
return Promise.resolve(this.val);
|
|
3245
|
+
if (this.subtreeSettled) return Promise.resolve(this.val);
|
|
3401
3246
|
this._subtreePromise ??= new Promise((res) => {
|
|
3402
3247
|
this._subtreeResolve = res;
|
|
3403
3248
|
});
|
|
3404
3249
|
return this._subtreePromise;
|
|
3405
3250
|
}
|
|
3251
|
+
// The transaction's own handler ran (records its {value, old}). Does not touch the counter.
|
|
3406
3252
|
markSelfSettled(val) {
|
|
3407
|
-
if (this.selfSettled)
|
|
3408
|
-
return;
|
|
3253
|
+
if (this.selfSettled) return;
|
|
3409
3254
|
this.selfSettled = true;
|
|
3410
3255
|
this.val = val;
|
|
3411
3256
|
this._selfResolve?.(val);
|
|
3412
3257
|
}
|
|
3258
|
+
// Settle self even when no handler produced a value (skipSelf / undefined / throw paths).
|
|
3413
3259
|
ensureSelfSettled() {
|
|
3414
|
-
if (!this.selfSettled)
|
|
3415
|
-
this.markSelfSettled(this.val);
|
|
3260
|
+
if (!this.selfSettled) this.markSelfSettled(this.val);
|
|
3416
3261
|
}
|
|
3262
|
+
// Register an outstanding unit; returns a one-shot release.
|
|
3417
3263
|
track() {
|
|
3418
3264
|
this.pending++;
|
|
3419
3265
|
let done = false;
|
|
3420
3266
|
return () => {
|
|
3421
|
-
if (done)
|
|
3422
|
-
return;
|
|
3267
|
+
if (done) return;
|
|
3423
3268
|
done = true;
|
|
3424
3269
|
this._release();
|
|
3425
3270
|
};
|
|
3426
3271
|
}
|
|
3427
3272
|
releaseSelf() {
|
|
3428
|
-
if (this._selfReleased)
|
|
3429
|
-
return;
|
|
3273
|
+
if (this._selfReleased) return;
|
|
3430
3274
|
this._selfReleased = true;
|
|
3431
3275
|
this._release();
|
|
3432
3276
|
}
|
|
@@ -3436,22 +3280,22 @@ class Completion {
|
|
|
3436
3280
|
this._subtreeResolve?.(this.val);
|
|
3437
3281
|
}
|
|
3438
3282
|
}
|
|
3439
|
-
}
|
|
3440
|
-
|
|
3441
|
-
class Dispatcher {
|
|
3283
|
+
};
|
|
3284
|
+
var Dispatcher = class {
|
|
3442
3285
|
constructor(path, transactor, parentTransaction, root = transactor.state.val) {
|
|
3443
3286
|
this.path = path;
|
|
3444
3287
|
this.transactor = transactor;
|
|
3445
3288
|
this.parent = parentTransaction;
|
|
3446
3289
|
this.root = root;
|
|
3447
3290
|
}
|
|
3291
|
+
// Walk the component instances on this ctx's path, leaf→root, calling
|
|
3292
|
+
// callback(Component, instance). Return false from the callback to stop early.
|
|
3448
3293
|
walkPath(callback) {
|
|
3449
3294
|
const comps = this.transactor.comps;
|
|
3450
3295
|
const chain = this.path.toTransactionPath().resolveChain(this.root);
|
|
3451
|
-
for (let i = chain.length - 1;i >= 0; i--) {
|
|
3296
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
3452
3297
|
const comp = comps.getCompFor(chain[i]);
|
|
3453
|
-
if (comp && callback(comp, chain[i]) === false)
|
|
3454
|
-
return;
|
|
3298
|
+
if (comp && callback(comp, chain[i]) === false) return;
|
|
3455
3299
|
}
|
|
3456
3300
|
}
|
|
3457
3301
|
get at() {
|
|
@@ -3478,9 +3322,8 @@ class Dispatcher {
|
|
|
3478
3322
|
lookupTypeFor(name, inst) {
|
|
3479
3323
|
return this.transactor.comps.getCompFor(inst).scope.lookupComponent(name);
|
|
3480
3324
|
}
|
|
3481
|
-
}
|
|
3482
|
-
|
|
3483
|
-
class EventContext extends Dispatcher {
|
|
3325
|
+
};
|
|
3326
|
+
var EventContext = class extends Dispatcher {
|
|
3484
3327
|
get name() {
|
|
3485
3328
|
return this.parent?.name ?? null;
|
|
3486
3329
|
}
|
|
@@ -3490,12 +3333,10 @@ class EventContext extends Dispatcher {
|
|
|
3490
3333
|
stopPropagation() {
|
|
3491
3334
|
return this.parent.stopPropagation();
|
|
3492
3335
|
}
|
|
3493
|
-
}
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
class PathChanges extends PathBuilder {
|
|
3336
|
+
};
|
|
3337
|
+
var RequestContext = class extends Dispatcher {
|
|
3338
|
+
};
|
|
3339
|
+
var PathChanges = class extends PathBuilder {
|
|
3499
3340
|
constructor(dispatcher) {
|
|
3500
3341
|
super();
|
|
3501
3342
|
this.dispatcher = dispatcher;
|
|
@@ -3509,15 +3350,14 @@ class PathChanges extends PathBuilder {
|
|
|
3509
3350
|
buildPath() {
|
|
3510
3351
|
return this.dispatcher.path.concat(this.pathChanges);
|
|
3511
3352
|
}
|
|
3512
|
-
}
|
|
3353
|
+
};
|
|
3513
3354
|
function rootDispatcher(transactor) {
|
|
3514
3355
|
return new Dispatcher(new Path([]), transactor, null);
|
|
3515
3356
|
}
|
|
3516
3357
|
|
|
3517
3358
|
// src/app.js
|
|
3518
3359
|
var _evs = "dragstart dragover dragend touchstart touchmove touchend touchcancel".split(" ");
|
|
3519
|
-
|
|
3520
|
-
class App {
|
|
3360
|
+
var App = class {
|
|
3521
3361
|
constructor(rootNode, comps, renderer, ParseContext2) {
|
|
3522
3362
|
this.rootNode = rootNode;
|
|
3523
3363
|
this.comps = comps;
|
|
@@ -3531,8 +3371,7 @@ class App {
|
|
|
3531
3371
|
this.dragInfo = this.curDragOver = null;
|
|
3532
3372
|
this._touch = null;
|
|
3533
3373
|
this.transactor.onTransactionPushed = (_transaction) => {
|
|
3534
|
-
if (this._transactNextBatchId === null)
|
|
3535
|
-
this._scheduleNextTransactionBatchExecution();
|
|
3374
|
+
if (this._transactNextBatchId === null) this._scheduleNextTransactionBatchExecution();
|
|
3536
3375
|
};
|
|
3537
3376
|
this._compiled = false;
|
|
3538
3377
|
this._renderOpts = { document: rootNode.ownerDocument };
|
|
@@ -3555,29 +3394,23 @@ class App {
|
|
|
3555
3394
|
const isDrag = type === "dragover" || type === "dragstart" || type === "dragend" || type === "drop";
|
|
3556
3395
|
const { rootNode: root, maxEventNodeDepth: maxDepth, comps, transactor } = this;
|
|
3557
3396
|
const [path, handlers] = Path.fromEvent(e, root, maxDepth, comps, !isDrag);
|
|
3558
|
-
if (isDrag)
|
|
3559
|
-
this._handleDragEvent(e, type, path);
|
|
3397
|
+
if (isDrag) this._handleDragEvent(e, type, path);
|
|
3560
3398
|
if (path !== null && handlers !== null)
|
|
3561
|
-
for (const handler of handlers)
|
|
3562
|
-
transactor.transactInputNow(path, e, handler, this.dragInfo);
|
|
3399
|
+
for (const handler of handlers) transactor.transactInputNow(path, e, handler, this.dragInfo);
|
|
3563
3400
|
}
|
|
3564
3401
|
_handleTouchEvent(e) {
|
|
3565
3402
|
const { type } = e;
|
|
3566
3403
|
if (type === "touchstart") {
|
|
3567
|
-
if (this._touch !== null || e.touches.length !== 1)
|
|
3568
|
-
return;
|
|
3404
|
+
if (this._touch !== null || e.touches.length !== 1) return;
|
|
3569
3405
|
const t = e.touches[0];
|
|
3570
3406
|
const draggable = t.target?.closest?.('[draggable="true"]');
|
|
3571
|
-
if (!draggable)
|
|
3572
|
-
return;
|
|
3407
|
+
if (!draggable) return;
|
|
3573
3408
|
this._touch = makeTouchInfo(t.identifier, t.clientX, t.clientY, draggable, false);
|
|
3574
3409
|
return;
|
|
3575
3410
|
}
|
|
3576
|
-
if (this._touch === null)
|
|
3577
|
-
return;
|
|
3411
|
+
if (this._touch === null) return;
|
|
3578
3412
|
const touch = findTouch(e, this._touch.id);
|
|
3579
|
-
if (touch === null)
|
|
3580
|
-
return;
|
|
3413
|
+
if (touch === null) return;
|
|
3581
3414
|
const { rootNode, _touch } = this;
|
|
3582
3415
|
const { clientX, clientY } = touch;
|
|
3583
3416
|
const fire = (type2, target) => {
|
|
@@ -3588,8 +3421,7 @@ class App {
|
|
|
3588
3421
|
if (!_touch.active) {
|
|
3589
3422
|
const dx = clientX - _touch.startX;
|
|
3590
3423
|
const dy = clientY - _touch.startY;
|
|
3591
|
-
if (dx * dx + dy * dy < 100)
|
|
3592
|
-
return;
|
|
3424
|
+
if (dx * dx + dy * dy < 100) return;
|
|
3593
3425
|
_touch.active = true;
|
|
3594
3426
|
e.preventDefault();
|
|
3595
3427
|
fire("dragstart", _touch.target);
|
|
@@ -3601,8 +3433,7 @@ class App {
|
|
|
3601
3433
|
}
|
|
3602
3434
|
if (type === "touchend" || type === "touchcancel") {
|
|
3603
3435
|
if (_touch.active) {
|
|
3604
|
-
if (type === "touchend")
|
|
3605
|
-
fire("drop", hitTest(rootNode, clientX, clientY));
|
|
3436
|
+
if (type === "touchend") fire("drop", hitTest(rootNode, clientX, clientY));
|
|
3606
3437
|
fire("dragend", _touch.target);
|
|
3607
3438
|
}
|
|
3608
3439
|
this._touch = null;
|
|
@@ -3649,13 +3480,20 @@ class App {
|
|
|
3649
3480
|
const root = this.state.val;
|
|
3650
3481
|
const stack = this.makeStack(root);
|
|
3651
3482
|
const { renderer, rootNode, _renderOpts, _renderState } = this;
|
|
3652
|
-
const newState = render(
|
|
3483
|
+
const newState = render(
|
|
3484
|
+
renderer.renderRoot(stack, root, this.rootViewName),
|
|
3485
|
+
rootNode,
|
|
3486
|
+
_renderOpts,
|
|
3487
|
+
_renderState
|
|
3488
|
+
);
|
|
3653
3489
|
this._renderState = newState;
|
|
3654
3490
|
return newState.dom;
|
|
3655
3491
|
}
|
|
3656
3492
|
onChange(callback) {
|
|
3657
3493
|
this.transactor.state.onChange(callback);
|
|
3658
3494
|
}
|
|
3495
|
+
// Subscribe to a normalized record for every handler invocation. Returns an
|
|
3496
|
+
// unsubscribe function. See Transactor.observe.
|
|
3659
3497
|
observe(callback) {
|
|
3660
3498
|
return this.transactor.observe(callback);
|
|
3661
3499
|
}
|
|
@@ -3663,31 +3501,25 @@ class App {
|
|
|
3663
3501
|
for (const Comp of this.comps.byId.values()) {
|
|
3664
3502
|
Comp.compile(this.ParseContext);
|
|
3665
3503
|
for (const key in Comp.views)
|
|
3666
|
-
for (const name of Comp.views[key].ctx.genEventNames())
|
|
3667
|
-
this._eventNames.add(name);
|
|
3504
|
+
for (const name of Comp.views[key].ctx.genEventNames()) this._eventNames.add(name);
|
|
3668
3505
|
}
|
|
3669
3506
|
this._compiled = true;
|
|
3670
3507
|
}
|
|
3671
3508
|
subscribeToEvents(eventNames) {
|
|
3672
|
-
for (const name of eventNames)
|
|
3673
|
-
this.rootNode.addEventListener(name, this, listenerOpts(name));
|
|
3509
|
+
for (const name of eventNames) this.rootNode.addEventListener(name, this, listenerOpts(name));
|
|
3674
3510
|
}
|
|
3675
3511
|
recompileStyles(opts) {
|
|
3676
3512
|
injectCss("tutuca-app", this.comps.compileStyles(), opts?.head ?? document.head);
|
|
3677
3513
|
}
|
|
3678
3514
|
start(opts) {
|
|
3679
|
-
if (!this._compiled)
|
|
3680
|
-
this.compile();
|
|
3515
|
+
if (!this._compiled) this.compile();
|
|
3681
3516
|
this.subscribeToEvents(this._eventNames);
|
|
3682
3517
|
this.onChange((info) => {
|
|
3683
|
-
if (info.val !== info.old)
|
|
3684
|
-
this.render();
|
|
3518
|
+
if (info.val !== info.old) this.render();
|
|
3685
3519
|
});
|
|
3686
3520
|
this.recompileStyles(opts);
|
|
3687
|
-
if (opts?.noCache)
|
|
3688
|
-
|
|
3689
|
-
else
|
|
3690
|
-
this.startCacheEvictionInterval();
|
|
3521
|
+
if (opts?.noCache) this.renderer.setNullCache();
|
|
3522
|
+
else this.startCacheEvictionInterval();
|
|
3691
3523
|
this.render();
|
|
3692
3524
|
}
|
|
3693
3525
|
stop() {
|
|
@@ -3707,42 +3539,36 @@ class App {
|
|
|
3707
3539
|
this._transactNextBatchId = null;
|
|
3708
3540
|
const startTs = Date.now();
|
|
3709
3541
|
const t = this.transactor;
|
|
3710
|
-
while (t.hasPendingTransactions && Date.now() - startTs < maxRunTimeMs)
|
|
3711
|
-
|
|
3712
|
-
if (t.hasPendingTransactions)
|
|
3713
|
-
this._scheduleNextTransactionBatchExecution();
|
|
3542
|
+
while (t.hasPendingTransactions && Date.now() - startTs < maxRunTimeMs) t.transactNext();
|
|
3543
|
+
if (t.hasPendingTransactions) this._scheduleNextTransactionBatchExecution();
|
|
3714
3544
|
}
|
|
3715
3545
|
_scheduleNextTransactionBatchExecution() {
|
|
3716
3546
|
this._transactNextBatchId = setTimeout(() => this._transactNextBatch(), 0);
|
|
3717
3547
|
}
|
|
3718
|
-
startCacheEvictionInterval(intervalMs =
|
|
3548
|
+
startCacheEvictionInterval(intervalMs = 3e4) {
|
|
3719
3549
|
this._evictCacheId = setInterval(() => this.renderer.cache.evict(), intervalMs);
|
|
3720
3550
|
}
|
|
3721
3551
|
stopCacheEvictionInterval() {
|
|
3722
3552
|
clearInterval(this._evictCacheId);
|
|
3723
3553
|
this._evictCacheId = null;
|
|
3724
3554
|
}
|
|
3725
|
-
}
|
|
3555
|
+
};
|
|
3726
3556
|
function injectCss(nodeId, style, styleTarget = document.head) {
|
|
3727
3557
|
const styleNode = document.createElement("style");
|
|
3728
3558
|
const currentNodeWithId = styleTarget.querySelector(`#${nodeId}`);
|
|
3729
|
-
if (currentNodeWithId)
|
|
3730
|
-
styleTarget.removeChild(currentNodeWithId);
|
|
3559
|
+
if (currentNodeWithId) styleTarget.removeChild(currentNodeWithId);
|
|
3731
3560
|
styleNode.id = nodeId;
|
|
3732
3561
|
styleNode.innerHTML = style;
|
|
3733
3562
|
styleTarget.appendChild(styleNode);
|
|
3734
3563
|
}
|
|
3735
|
-
var NOOP = () => {
|
|
3564
|
+
var NOOP = () => {
|
|
3565
|
+
};
|
|
3736
3566
|
function findTouch(e, id) {
|
|
3737
|
-
for (const t of e.changedTouches)
|
|
3738
|
-
|
|
3739
|
-
return t;
|
|
3740
|
-
for (const t of e.touches)
|
|
3741
|
-
if (t.identifier === id)
|
|
3742
|
-
return t;
|
|
3567
|
+
for (const t of e.changedTouches) if (t.identifier === id) return t;
|
|
3568
|
+
for (const t of e.touches) if (t.identifier === id) return t;
|
|
3743
3569
|
return null;
|
|
3744
3570
|
}
|
|
3745
|
-
var listenerOpts = (name) => name === "touchmove" ? { passive: false } :
|
|
3571
|
+
var listenerOpts = (name) => name === "touchmove" ? { passive: false } : void 0;
|
|
3746
3572
|
function makeTouchInfo(id, startX, startY, target, active) {
|
|
3747
3573
|
return { id, startX, startY, target, active };
|
|
3748
3574
|
}
|
|
@@ -3751,8 +3577,7 @@ function hitTest(rootNode, x, y) {
|
|
|
3751
3577
|
let el = root.elementFromPoint?.(x, y) ?? null;
|
|
3752
3578
|
while (el?.shadowRoot) {
|
|
3753
3579
|
const next = el.shadowRoot.elementFromPoint(x, y);
|
|
3754
|
-
if (next === null || next === el)
|
|
3755
|
-
break;
|
|
3580
|
+
if (next === null || next === el) break;
|
|
3756
3581
|
el = next;
|
|
3757
3582
|
}
|
|
3758
3583
|
return el ?? rootNode;
|
|
@@ -3760,14 +3585,12 @@ function hitTest(rootNode, x, y) {
|
|
|
3760
3585
|
function getClosestDropTarget(target, rootNode, count) {
|
|
3761
3586
|
let node = target;
|
|
3762
3587
|
while (count-- > 0 && node !== rootNode) {
|
|
3763
|
-
if (node.dataset?.droptarget !==
|
|
3764
|
-
return node;
|
|
3588
|
+
if (node.dataset?.droptarget !== void 0) return node;
|
|
3765
3589
|
node = node.parentNode;
|
|
3766
3590
|
}
|
|
3767
3591
|
return null;
|
|
3768
3592
|
}
|
|
3769
|
-
|
|
3770
|
-
class DragInfo {
|
|
3593
|
+
var DragInfo = class {
|
|
3771
3594
|
constructor(path, stack, e, val, type, node) {
|
|
3772
3595
|
this.path = path;
|
|
3773
3596
|
this.stack = stack;
|
|
@@ -3779,7 +3602,7 @@ class DragInfo {
|
|
|
3779
3602
|
lookupBind(name) {
|
|
3780
3603
|
return this.stack.lookupBind(name);
|
|
3781
3604
|
}
|
|
3782
|
-
}
|
|
3605
|
+
};
|
|
3783
3606
|
|
|
3784
3607
|
// index.js
|
|
3785
3608
|
import {
|
|
@@ -3840,26 +3663,20 @@ import {
|
|
|
3840
3663
|
var OP_KINDS = ["send", "bubble", "request", "input"];
|
|
3841
3664
|
function phaseOps(phase) {
|
|
3842
3665
|
const ops = [];
|
|
3843
|
-
for (const type of OP_KINDS)
|
|
3844
|
-
|
|
3845
|
-
ops.push({ type, ...a });
|
|
3846
|
-
for (const a of phase.do ?? [])
|
|
3847
|
-
ops.push(a);
|
|
3666
|
+
for (const type of OP_KINDS) for (const a of phase[type] ?? []) ops.push({ type, ...a });
|
|
3667
|
+
for (const a of phase.do ?? []) ops.push(a);
|
|
3848
3668
|
return ops;
|
|
3849
3669
|
}
|
|
3850
3670
|
function resolveArgs(args, self) {
|
|
3851
3671
|
return typeof args === "function" ? args(self) ?? [] : args ?? [];
|
|
3852
3672
|
}
|
|
3853
3673
|
function phaseHasBubble(phase) {
|
|
3854
|
-
if (!phase)
|
|
3855
|
-
|
|
3856
|
-
if (phase.bubble?.length)
|
|
3857
|
-
return true;
|
|
3674
|
+
if (!phase) return false;
|
|
3675
|
+
if (phase.bubble?.length) return true;
|
|
3858
3676
|
return (phase.do ?? []).some((op) => op.type === "bubble");
|
|
3859
3677
|
}
|
|
3860
3678
|
function dispatchPhase(dispatcher, targetPath, phase, self) {
|
|
3861
|
-
if (!phase)
|
|
3862
|
-
return;
|
|
3679
|
+
if (!phase) return;
|
|
3863
3680
|
for (const op of phaseOps(phase)) {
|
|
3864
3681
|
const args = resolveArgs(op.args, self);
|
|
3865
3682
|
switch (op.type) {
|
|
@@ -3882,12 +3699,12 @@ function dispatchPhase(dispatcher, targetPath, phase, self) {
|
|
|
3882
3699
|
}
|
|
3883
3700
|
}
|
|
3884
3701
|
}
|
|
3702
|
+
|
|
3885
3703
|
// src/oo.js
|
|
3886
3704
|
import { Map as IMap, Set as ISet, List, OrderedMap, Record } from "immutable";
|
|
3887
|
-
var BAD_VALUE = Symbol("BadValue");
|
|
3705
|
+
var BAD_VALUE = /* @__PURE__ */ Symbol("BadValue");
|
|
3888
3706
|
var nullCoercer = (v) => v;
|
|
3889
|
-
|
|
3890
|
-
class Field {
|
|
3707
|
+
var Field = class {
|
|
3891
3708
|
constructor(type, name, typeCheck, coercer, defaultValue = null) {
|
|
3892
3709
|
this.type = type;
|
|
3893
3710
|
this.name = name;
|
|
@@ -3901,30 +3718,27 @@ class Field {
|
|
|
3901
3718
|
return { type, defaultValue: dv?.toJS ? dv.toJS() : dv };
|
|
3902
3719
|
}
|
|
3903
3720
|
getFirstFailingCheck(v) {
|
|
3904
|
-
if (!this.typeCheck.isValid(v))
|
|
3905
|
-
|
|
3906
|
-
for (const check of this.checks)
|
|
3907
|
-
if (!check.isValid(v))
|
|
3908
|
-
return check;
|
|
3721
|
+
if (!this.typeCheck.isValid(v)) return this.typeCheck;
|
|
3722
|
+
for (const check2 of this.checks) if (!check2.isValid(v)) return check2;
|
|
3909
3723
|
return null;
|
|
3910
3724
|
}
|
|
3911
3725
|
isValid(v) {
|
|
3912
3726
|
return this.getFirstFailingCheck(v) === null;
|
|
3913
3727
|
}
|
|
3914
|
-
addCheck(
|
|
3915
|
-
this.checks.push(
|
|
3728
|
+
addCheck(check2) {
|
|
3729
|
+
this.checks.push(check2);
|
|
3916
3730
|
return this;
|
|
3917
3731
|
}
|
|
3918
3732
|
coerceOr(v, defaultValue = null) {
|
|
3919
|
-
if (this.isValid(v))
|
|
3920
|
-
return v;
|
|
3733
|
+
if (this.isValid(v)) return v;
|
|
3921
3734
|
const v1 = this.coercer(v);
|
|
3922
3735
|
return this.isValid(v1) ? v1 : defaultValue;
|
|
3923
3736
|
}
|
|
3924
3737
|
coerceOrDefault(v) {
|
|
3925
3738
|
return this.coerceOr(v, this.defaultValue);
|
|
3926
3739
|
}
|
|
3927
|
-
extendProtoForType(_proto, _uname) {
|
|
3740
|
+
extendProtoForType(_proto, _uname) {
|
|
3741
|
+
}
|
|
3928
3742
|
extendProto(proto) {
|
|
3929
3743
|
const { name } = this;
|
|
3930
3744
|
const uname = name[0].toUpperCase() + name.slice(1);
|
|
@@ -3946,22 +3760,19 @@ class Field {
|
|
|
3946
3760
|
};
|
|
3947
3761
|
this.extendProtoForType(proto, uname);
|
|
3948
3762
|
}
|
|
3949
|
-
}
|
|
3950
|
-
|
|
3951
|
-
class Check {
|
|
3763
|
+
};
|
|
3764
|
+
var Check = class {
|
|
3952
3765
|
isValid(_v) {
|
|
3953
3766
|
return true;
|
|
3954
3767
|
}
|
|
3955
3768
|
getMessage(_v) {
|
|
3956
3769
|
return "Invalid";
|
|
3957
3770
|
}
|
|
3958
|
-
}
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
var
|
|
3963
|
-
|
|
3964
|
-
class FnCheck extends Check {
|
|
3771
|
+
};
|
|
3772
|
+
var CheckTypeAny = class extends Check {
|
|
3773
|
+
};
|
|
3774
|
+
var CHECK_TYPE_ANY = new CheckTypeAny();
|
|
3775
|
+
var FnCheck = class extends Check {
|
|
3965
3776
|
constructor(isValidFn, getMessageFn) {
|
|
3966
3777
|
super();
|
|
3967
3778
|
this._isValid = isValidFn;
|
|
@@ -3973,18 +3784,41 @@ class FnCheck extends Check {
|
|
|
3973
3784
|
getMessage(v) {
|
|
3974
3785
|
return this._getMessage(v);
|
|
3975
3786
|
}
|
|
3976
|
-
}
|
|
3977
|
-
var CHECK_TYPE_INT = new FnCheck(
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
var
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3787
|
+
};
|
|
3788
|
+
var CHECK_TYPE_INT = new FnCheck(
|
|
3789
|
+
(v) => Number.isInteger(v),
|
|
3790
|
+
() => "Integer expected"
|
|
3791
|
+
);
|
|
3792
|
+
var CHECK_TYPE_FLOAT = new FnCheck(
|
|
3793
|
+
(v) => Number.isFinite(v),
|
|
3794
|
+
() => "Float expected"
|
|
3795
|
+
);
|
|
3796
|
+
var CHECK_TYPE_BOOL = new FnCheck(
|
|
3797
|
+
(v) => typeof v === "boolean",
|
|
3798
|
+
() => "Boolean expected"
|
|
3799
|
+
);
|
|
3800
|
+
var CHECK_TYPE_STRING = new FnCheck(
|
|
3801
|
+
(v) => typeof v === "string",
|
|
3802
|
+
() => "String expected"
|
|
3803
|
+
);
|
|
3804
|
+
var CHECK_TYPE_LIST = new FnCheck(
|
|
3805
|
+
(v) => List.isList(v),
|
|
3806
|
+
() => "List expected"
|
|
3807
|
+
);
|
|
3808
|
+
var CHECK_TYPE_MAP = new FnCheck(
|
|
3809
|
+
(v) => IMap.isMap(v),
|
|
3810
|
+
() => "Map expected"
|
|
3811
|
+
);
|
|
3812
|
+
var CHECK_TYPE_OMAP = new FnCheck(
|
|
3813
|
+
(v) => OrderedMap.isOrderedMap(v),
|
|
3814
|
+
() => "OrderedMap expected"
|
|
3815
|
+
);
|
|
3816
|
+
var CHECK_TYPE_SET = new FnCheck(
|
|
3817
|
+
(v) => ISet.isSet(v),
|
|
3818
|
+
() => "Set expected"
|
|
3819
|
+
);
|
|
3985
3820
|
var boolCoercer = (v) => !!v;
|
|
3986
|
-
|
|
3987
|
-
class FieldBool extends Field {
|
|
3821
|
+
var FieldBool = class extends Field {
|
|
3988
3822
|
constructor(name, defaultValue = false) {
|
|
3989
3823
|
super("bool", name, CHECK_TYPE_BOOL, boolCoercer, defaultValue);
|
|
3990
3824
|
}
|
|
@@ -3997,9 +3831,8 @@ class FieldBool extends Field {
|
|
|
3997
3831
|
return this.set(name, !!v);
|
|
3998
3832
|
};
|
|
3999
3833
|
}
|
|
4000
|
-
}
|
|
4001
|
-
|
|
4002
|
-
class FieldAny extends Field {
|
|
3834
|
+
};
|
|
3835
|
+
var FieldAny = class extends Field {
|
|
4003
3836
|
constructor(name, defaultValue = null) {
|
|
4004
3837
|
super("any", name, CHECK_TYPE_ANY, nullCoercer, defaultValue);
|
|
4005
3838
|
}
|
|
@@ -4008,34 +3841,30 @@ class FieldAny extends Field {
|
|
|
4008
3841
|
const type = getTypeName(dv) ?? "any";
|
|
4009
3842
|
return { type, defaultValue: dv?.toJS ? dv.toJS() : dv };
|
|
4010
3843
|
}
|
|
4011
|
-
}
|
|
3844
|
+
};
|
|
4012
3845
|
var stringCoercer = (v) => v?.toString?.() ?? "";
|
|
4013
|
-
|
|
4014
|
-
class FieldString extends Field {
|
|
3846
|
+
var FieldString = class extends Field {
|
|
4015
3847
|
constructor(name, defaultValue = "") {
|
|
4016
3848
|
super("text", name, CHECK_TYPE_STRING, stringCoercer, defaultValue);
|
|
4017
3849
|
}
|
|
4018
3850
|
extendProtoForType(proto, _uname) {
|
|
4019
3851
|
extendProtoSized(proto, this.name, "", "length");
|
|
4020
3852
|
}
|
|
4021
|
-
}
|
|
3853
|
+
};
|
|
4022
3854
|
var intCoercer = (v) => Number.isFinite(v) ? Math.trunc(v) : null;
|
|
4023
|
-
|
|
4024
|
-
class FieldInt extends Field {
|
|
3855
|
+
var FieldInt = class extends Field {
|
|
4025
3856
|
constructor(name, defaultValue = 0) {
|
|
4026
3857
|
super("int", name, CHECK_TYPE_INT, intCoercer, defaultValue);
|
|
4027
3858
|
}
|
|
4028
|
-
}
|
|
3859
|
+
};
|
|
4029
3860
|
var floatCoercer = (_) => null;
|
|
4030
|
-
|
|
4031
|
-
class FieldFloat extends Field {
|
|
3861
|
+
var FieldFloat = class extends Field {
|
|
4032
3862
|
constructor(name, defaultValue = 0) {
|
|
4033
3863
|
super("float", name, CHECK_TYPE_FLOAT, floatCoercer, defaultValue);
|
|
4034
3864
|
}
|
|
4035
|
-
}
|
|
3865
|
+
};
|
|
4036
3866
|
var getTypeName = (v) => v?.constructor?.getMetaClass?.()?.name;
|
|
4037
|
-
|
|
4038
|
-
class CheckTypeName {
|
|
3867
|
+
var CheckTypeName = class {
|
|
4039
3868
|
constructor(typeName) {
|
|
4040
3869
|
this.typeName = typeName;
|
|
4041
3870
|
}
|
|
@@ -4046,9 +3875,8 @@ class CheckTypeName {
|
|
|
4046
3875
|
const got = getTypeName(v);
|
|
4047
3876
|
return `Expected "${this.typeName}", got "${got}"`;
|
|
4048
3877
|
}
|
|
4049
|
-
}
|
|
4050
|
-
|
|
4051
|
-
class FieldComp extends Field {
|
|
3878
|
+
};
|
|
3879
|
+
var FieldComp = class extends Field {
|
|
4052
3880
|
constructor(type, name, args) {
|
|
4053
3881
|
super(type, name, new CheckTypeName(type), nullCoercer, null);
|
|
4054
3882
|
this.args = args;
|
|
@@ -4056,8 +3884,8 @@ class FieldComp extends Field {
|
|
|
4056
3884
|
toDataDef() {
|
|
4057
3885
|
return { component: this.typeName, args: this.args };
|
|
4058
3886
|
}
|
|
4059
|
-
}
|
|
4060
|
-
var NONE2 = Symbol("NONE");
|
|
3887
|
+
};
|
|
3888
|
+
var NONE2 = /* @__PURE__ */ Symbol("NONE");
|
|
4061
3889
|
function extendProtoForKeyed(proto, name, uname) {
|
|
4062
3890
|
extendProtoSized(proto, name, EMPTY_LIST);
|
|
4063
3891
|
proto[`setIn${uname}At`] = function(i, v) {
|
|
@@ -4069,8 +3897,7 @@ function extendProtoForKeyed(proto, name, uname) {
|
|
|
4069
3897
|
proto[`updateIn${uname}At`] = function(i, fn) {
|
|
4070
3898
|
const col = this.get(name);
|
|
4071
3899
|
const v = col.get(i, NONE2);
|
|
4072
|
-
if (v !== NONE2)
|
|
4073
|
-
return this.set(name, col.set(i, fn(v)));
|
|
3900
|
+
if (v !== NONE2) return this.set(name, col.set(i, fn(v)));
|
|
4074
3901
|
console.warn("key", i, "not found in", name, col);
|
|
4075
3902
|
return this;
|
|
4076
3903
|
};
|
|
@@ -4084,8 +3911,7 @@ function extendDeleteInAt(proto, name, uname) {
|
|
|
4084
3911
|
}
|
|
4085
3912
|
var EMPTY_LIST = List();
|
|
4086
3913
|
var listCoercer = (v) => Array.isArray(v) ? List(v) : null;
|
|
4087
|
-
|
|
4088
|
-
class FieldList extends Field {
|
|
3914
|
+
var FieldList = class extends Field {
|
|
4089
3915
|
constructor(name, defaultValue = EMPTY_LIST) {
|
|
4090
3916
|
super("list", name, CHECK_TYPE_LIST, listCoercer, defaultValue);
|
|
4091
3917
|
}
|
|
@@ -4099,27 +3925,25 @@ class FieldList extends Field {
|
|
|
4099
3925
|
return this.set(name, this.get(name).insert(i, v));
|
|
4100
3926
|
};
|
|
4101
3927
|
}
|
|
4102
|
-
}
|
|
3928
|
+
};
|
|
4103
3929
|
var imapCoercer = (v) => IMap(v);
|
|
4104
|
-
|
|
4105
|
-
class FieldMap extends Field {
|
|
3930
|
+
var FieldMap = class extends Field {
|
|
4106
3931
|
constructor(name, defaultValue = IMap()) {
|
|
4107
3932
|
super("map", name, CHECK_TYPE_MAP, imapCoercer, defaultValue);
|
|
4108
3933
|
}
|
|
4109
3934
|
extendProtoForType(proto, uname) {
|
|
4110
3935
|
extendProtoForKeyed(proto, this.name, uname);
|
|
4111
3936
|
}
|
|
4112
|
-
}
|
|
3937
|
+
};
|
|
4113
3938
|
var omapCoercer = (v) => OrderedMap(v);
|
|
4114
|
-
|
|
4115
|
-
class FieldOMap extends Field {
|
|
3939
|
+
var FieldOMap = class extends Field {
|
|
4116
3940
|
constructor(name, defaultValue = OrderedMap()) {
|
|
4117
3941
|
super("omap", name, CHECK_TYPE_OMAP, omapCoercer, defaultValue);
|
|
4118
3942
|
}
|
|
4119
3943
|
extendProtoForType(proto, uname) {
|
|
4120
3944
|
extendProtoForKeyed(proto, this.name, uname);
|
|
4121
3945
|
}
|
|
4122
|
-
}
|
|
3946
|
+
};
|
|
4123
3947
|
function extendProtoSized(proto, name, defaultEmpty, propName = "size") {
|
|
4124
3948
|
proto[`${name}Len`] = function() {
|
|
4125
3949
|
return this.get(name, defaultEmpty)[propName];
|
|
@@ -4127,8 +3951,7 @@ function extendProtoSized(proto, name, defaultEmpty, propName = "size") {
|
|
|
4127
3951
|
}
|
|
4128
3952
|
var EMPTY_SET = ISet();
|
|
4129
3953
|
var isetCoercer = (v) => Array.isArray(v) ? ISet(v) : v instanceof Set ? ISet(v) : null;
|
|
4130
|
-
|
|
4131
|
-
class FieldSet extends Field {
|
|
3954
|
+
var FieldSet = class extends Field {
|
|
4132
3955
|
constructor(name, defaultValue = EMPTY_SET) {
|
|
4133
3956
|
super("set", name, CHECK_TYPE_SET, isetCoercer, defaultValue);
|
|
4134
3957
|
}
|
|
@@ -4147,18 +3970,19 @@ class FieldSet extends Field {
|
|
|
4147
3970
|
return this.set(name, current.has(v) ? current.delete(v) : current.add(v));
|
|
4148
3971
|
};
|
|
4149
3972
|
}
|
|
4150
|
-
}
|
|
3973
|
+
};
|
|
4151
3974
|
function mkCompField(field, scope, args) {
|
|
4152
3975
|
const Comp = scope?.lookupComponent(field.type) ?? null;
|
|
4153
3976
|
if (Comp === null)
|
|
4154
|
-
console.warn(
|
|
3977
|
+
console.warn(
|
|
3978
|
+
scope ? `component field "${field.name}": component "${field.type}" not found in scope` : `component field "${field.name}": cannot resolve component "${field.type}" — built without a registered scope (use ${field.type}.make({}) as the default, or build via a registered component)`
|
|
3979
|
+
);
|
|
4155
3980
|
return Comp?.make({ ...field.args, ...args }, { scope }) ?? null;
|
|
4156
3981
|
}
|
|
4157
|
-
|
|
4158
|
-
class ClassBuilder {
|
|
3982
|
+
var ClassBuilder = class {
|
|
4159
3983
|
constructor(name) {
|
|
4160
3984
|
const fields = {};
|
|
4161
|
-
const compFields = new Set;
|
|
3985
|
+
const compFields = /* @__PURE__ */ new Set();
|
|
4162
3986
|
this.name = name;
|
|
4163
3987
|
this.fields = fields;
|
|
4164
3988
|
this.compFields = compFields;
|
|
@@ -4169,16 +3993,13 @@ class ClassBuilder {
|
|
|
4169
3993
|
const scope = opts.scope ?? this.scope;
|
|
4170
3994
|
for (const key in inArgs) {
|
|
4171
3995
|
const field = fields[key];
|
|
4172
|
-
if (compFields.has(key))
|
|
4173
|
-
|
|
4174
|
-
else if (field === undefined)
|
|
3996
|
+
if (compFields.has(key)) args[key] = mkCompField(field, scope, inArgs[key]);
|
|
3997
|
+
else if (field === void 0)
|
|
4175
3998
|
console.warn("extra argument to constructor:", name, key, inArgs);
|
|
4176
|
-
else
|
|
4177
|
-
args[key] = field.coerceOrDefault(inArgs[key]);
|
|
3999
|
+
else args[key] = field.coerceOrDefault(inArgs[key]);
|
|
4178
4000
|
}
|
|
4179
4001
|
for (const key of compFields)
|
|
4180
|
-
if (args[key] ===
|
|
4181
|
-
args[key] = mkCompField(fields[key], scope, inArgs[key]);
|
|
4002
|
+
if (args[key] === void 0) args[key] = mkCompField(fields[key], scope, inArgs[key]);
|
|
4182
4003
|
return this(args);
|
|
4183
4004
|
}
|
|
4184
4005
|
};
|
|
@@ -4199,12 +4020,10 @@ class ClassBuilder {
|
|
|
4199
4020
|
return Class;
|
|
4200
4021
|
}
|
|
4201
4022
|
methods(proto) {
|
|
4202
|
-
for (const k in proto)
|
|
4203
|
-
this._methods[k] = proto[k];
|
|
4023
|
+
for (const k in proto) this._methods[k] = proto[k];
|
|
4204
4024
|
}
|
|
4205
4025
|
statics(proto) {
|
|
4206
|
-
for (const k in proto)
|
|
4207
|
-
this._statics[k] = proto[k];
|
|
4026
|
+
for (const k in proto) this._statics[k] = proto[k];
|
|
4208
4027
|
}
|
|
4209
4028
|
addField(name, dval, FieldCls) {
|
|
4210
4029
|
const field = new FieldCls(name, dval);
|
|
@@ -4217,8 +4036,8 @@ class ClassBuilder {
|
|
|
4217
4036
|
this.fields[name] = field;
|
|
4218
4037
|
return field;
|
|
4219
4038
|
}
|
|
4220
|
-
}
|
|
4221
|
-
var FIELD_CLASS = Symbol.for("tutuca.fieldClass");
|
|
4039
|
+
};
|
|
4040
|
+
var FIELD_CLASS = /* @__PURE__ */ Symbol.for("tutuca.fieldClass");
|
|
4222
4041
|
var fieldsByTypeName = {
|
|
4223
4042
|
text: FieldString,
|
|
4224
4043
|
int: FieldInt,
|
|
@@ -4235,22 +4054,16 @@ function classFromData(name, { fields = {}, methods, statics }) {
|
|
|
4235
4054
|
for (const field in fields) {
|
|
4236
4055
|
const value = fields[field];
|
|
4237
4056
|
const type = typeof value;
|
|
4238
|
-
if (type === "string")
|
|
4239
|
-
|
|
4240
|
-
else if (type === "
|
|
4241
|
-
|
|
4242
|
-
else if (
|
|
4243
|
-
|
|
4244
|
-
else if (
|
|
4245
|
-
b.addField(field, List(value), FieldList);
|
|
4246
|
-
else if (ISet.isSet(value) || value instanceof Set)
|
|
4247
|
-
b.addField(field, ISet(value), FieldSet);
|
|
4248
|
-
else if (OrderedMap.isOrderedMap(value))
|
|
4249
|
-
b.addField(field, value, FieldOMap);
|
|
4250
|
-
else if (value?.type && value?.defaultValue !== undefined) {
|
|
4057
|
+
if (type === "string") b.addField(field, value, FieldString);
|
|
4058
|
+
else if (type === "number") b.addField(field, value, FieldFloat);
|
|
4059
|
+
else if (type === "boolean") b.addField(field, value, FieldBool);
|
|
4060
|
+
else if (List.isList(value) || Array.isArray(value)) b.addField(field, List(value), FieldList);
|
|
4061
|
+
else if (ISet.isSet(value) || value instanceof Set) b.addField(field, ISet(value), FieldSet);
|
|
4062
|
+
else if (OrderedMap.isOrderedMap(value)) b.addField(field, value, FieldOMap);
|
|
4063
|
+
else if (value?.type && value?.defaultValue !== void 0) {
|
|
4251
4064
|
const Field2 = fieldsByTypeName[value.type] ?? FieldAny;
|
|
4252
4065
|
b.addField(field, new Field2().coerceOr(value.defaultValue), Field2);
|
|
4253
|
-
} else if (value?.component && value?.args !==
|
|
4066
|
+
} else if (value?.component && value?.args !== void 0)
|
|
4254
4067
|
b.addCompField(field, value.component, value.args);
|
|
4255
4068
|
else if (IMap.isMap(value) || value?.constructor === Object)
|
|
4256
4069
|
b.addField(field, IMap(value), FieldMap);
|
|
@@ -4259,10 +4072,8 @@ function classFromData(name, { fields = {}, methods, statics }) {
|
|
|
4259
4072
|
b.addField(field, value, Field2);
|
|
4260
4073
|
}
|
|
4261
4074
|
}
|
|
4262
|
-
if (methods)
|
|
4263
|
-
|
|
4264
|
-
if (statics)
|
|
4265
|
-
b.statics(statics);
|
|
4075
|
+
if (methods) b.methods(methods);
|
|
4076
|
+
if (statics) b.statics(statics);
|
|
4266
4077
|
return b.build();
|
|
4267
4078
|
}
|
|
4268
4079
|
Component.fromSpec = (opts) => new Component(classFromData(opts.name, opts), opts);
|
|
@@ -4279,82 +4090,84 @@ async function test(_opts) {
|
|
|
4279
4090
|
return null;
|
|
4280
4091
|
}
|
|
4281
4092
|
function collectIterBindings() {
|
|
4282
|
-
console.warn(
|
|
4093
|
+
console.warn(
|
|
4094
|
+
"collectIterBindings is a no-op in the core tutuca build; use the tutuca-dev build for a functional implementation"
|
|
4095
|
+
);
|
|
4283
4096
|
return [];
|
|
4284
4097
|
}
|
|
4285
4098
|
function tutuca(nodeOrSelector) {
|
|
4286
4099
|
const rootNode = typeof nodeOrSelector === "string" ? document.querySelector(nodeOrSelector) : nodeOrSelector;
|
|
4287
|
-
const comps = new Components;
|
|
4100
|
+
const comps = new Components();
|
|
4288
4101
|
const renderer = new Renderer(comps);
|
|
4289
4102
|
return new App(rootNode, comps, renderer, ParseContext);
|
|
4290
4103
|
}
|
|
4291
4104
|
export {
|
|
4292
|
-
|
|
4293
|
-
updateIn,
|
|
4294
|
-
update,
|
|
4295
|
-
tutuca,
|
|
4296
|
-
test,
|
|
4297
|
-
setIn,
|
|
4298
|
-
set,
|
|
4299
|
-
rootDispatcher,
|
|
4300
|
-
resolveArgs,
|
|
4301
|
-
removeIn,
|
|
4302
|
-
remove,
|
|
4303
|
-
phaseOps,
|
|
4304
|
-
phaseHasBubble,
|
|
4305
|
-
mergeWith,
|
|
4306
|
-
mergeDeepWith,
|
|
4307
|
-
mergeDeep,
|
|
4308
|
-
merge,
|
|
4309
|
-
macro,
|
|
4310
|
-
isValueObject,
|
|
4311
|
-
isStack,
|
|
4312
|
-
isSet,
|
|
4313
|
-
isSeq,
|
|
4314
|
-
isRecord,
|
|
4315
|
-
isPlainObject,
|
|
4316
|
-
isOrderedSet,
|
|
4317
|
-
isOrderedMap,
|
|
4318
|
-
isOrdered,
|
|
4319
|
-
isOrderedMap2 as isOMap,
|
|
4320
|
-
isMap,
|
|
4321
|
-
isList,
|
|
4322
|
-
isKeyed2 as isKeyed,
|
|
4323
|
-
isIndexed2 as isIndexed,
|
|
4324
|
-
isImmutable,
|
|
4325
|
-
isMap2 as isIMap,
|
|
4326
|
-
isCollection,
|
|
4327
|
-
isAssociative,
|
|
4328
|
-
is2 as is,
|
|
4329
|
-
injectCss,
|
|
4330
|
-
html,
|
|
4331
|
-
hash,
|
|
4332
|
-
hasIn,
|
|
4333
|
-
has,
|
|
4334
|
-
getIn,
|
|
4335
|
-
get,
|
|
4336
|
-
fromJS,
|
|
4337
|
-
dispatchPhase,
|
|
4338
|
-
css,
|
|
4339
|
-
component,
|
|
4340
|
-
collectIterBindings,
|
|
4341
|
-
check,
|
|
4342
|
-
Stack2 as Stack,
|
|
4343
|
-
Set2 as Set,
|
|
4344
|
-
Seq,
|
|
4345
|
-
SEQ_INFO,
|
|
4346
|
-
Repeat,
|
|
4347
|
-
Record2 as Record,
|
|
4348
|
-
Range,
|
|
4349
|
-
ParseContext,
|
|
4350
|
-
PairSorting,
|
|
4351
|
-
OrderedSet,
|
|
4352
|
-
OrderedMap2 as OrderedMap,
|
|
4353
|
-
OrderedMap3 as OMap,
|
|
4354
|
-
Map2 as Map,
|
|
4355
|
-
List2 as List,
|
|
4356
|
-
Set3 as ISet,
|
|
4357
|
-
Map3 as IMap,
|
|
4105
|
+
Collection,
|
|
4358
4106
|
FIELD_CLASS,
|
|
4359
|
-
|
|
4107
|
+
Map3 as IMap,
|
|
4108
|
+
Set3 as ISet,
|
|
4109
|
+
List2 as List,
|
|
4110
|
+
Map2 as Map,
|
|
4111
|
+
OrderedMap3 as OMap,
|
|
4112
|
+
OrderedMap2 as OrderedMap,
|
|
4113
|
+
OrderedSet,
|
|
4114
|
+
PairSorting,
|
|
4115
|
+
ParseContext,
|
|
4116
|
+
Range,
|
|
4117
|
+
Record2 as Record,
|
|
4118
|
+
Repeat,
|
|
4119
|
+
SEQ_INFO,
|
|
4120
|
+
Seq,
|
|
4121
|
+
Set2 as Set,
|
|
4122
|
+
Stack2 as Stack,
|
|
4123
|
+
check,
|
|
4124
|
+
collectIterBindings,
|
|
4125
|
+
component,
|
|
4126
|
+
css,
|
|
4127
|
+
dispatchPhase,
|
|
4128
|
+
fromJS,
|
|
4129
|
+
get,
|
|
4130
|
+
getIn,
|
|
4131
|
+
has,
|
|
4132
|
+
hasIn,
|
|
4133
|
+
hash,
|
|
4134
|
+
html,
|
|
4135
|
+
injectCss,
|
|
4136
|
+
is2 as is,
|
|
4137
|
+
isAssociative,
|
|
4138
|
+
isCollection,
|
|
4139
|
+
isMap2 as isIMap,
|
|
4140
|
+
isImmutable,
|
|
4141
|
+
isIndexed2 as isIndexed,
|
|
4142
|
+
isKeyed2 as isKeyed,
|
|
4143
|
+
isList,
|
|
4144
|
+
isMap,
|
|
4145
|
+
isOrderedMap2 as isOMap,
|
|
4146
|
+
isOrdered,
|
|
4147
|
+
isOrderedMap,
|
|
4148
|
+
isOrderedSet,
|
|
4149
|
+
isPlainObject,
|
|
4150
|
+
isRecord,
|
|
4151
|
+
isSeq,
|
|
4152
|
+
isSet,
|
|
4153
|
+
isStack,
|
|
4154
|
+
isValueObject,
|
|
4155
|
+
macro,
|
|
4156
|
+
merge,
|
|
4157
|
+
mergeDeep,
|
|
4158
|
+
mergeDeepWith,
|
|
4159
|
+
mergeWith,
|
|
4160
|
+
phaseHasBubble,
|
|
4161
|
+
phaseOps,
|
|
4162
|
+
remove,
|
|
4163
|
+
removeIn,
|
|
4164
|
+
resolveArgs,
|
|
4165
|
+
rootDispatcher,
|
|
4166
|
+
set,
|
|
4167
|
+
setIn,
|
|
4168
|
+
test,
|
|
4169
|
+
tutuca,
|
|
4170
|
+
update,
|
|
4171
|
+
updateIn,
|
|
4172
|
+
version
|
|
4360
4173
|
};
|