tutuca 0.9.63 → 0.9.65
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/tutuca-cli.js +1190 -1166
- package/dist/tutuca-dev.js +434 -399
- package/dist/tutuca-dev.min.js +2 -2
- package/dist/tutuca-extra.js +419 -392
- package/dist/tutuca-extra.min.js +2 -2
- package/dist/tutuca.js +419 -392
- package/dist/tutuca.min.js +2 -2
- package/package.json +1 -1
- package/skill/tutuca/core.md +28 -5
- package/skill/tutuca/testing.md +6 -3
package/dist/tutuca-cli.js
CHANGED
|
@@ -5350,588 +5350,917 @@ var init_attribute = __esm(() => {
|
|
|
5350
5350
|
};
|
|
5351
5351
|
});
|
|
5352
5352
|
|
|
5353
|
-
// src/
|
|
5354
|
-
function
|
|
5355
|
-
const
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5353
|
+
// src/vdom.js
|
|
5354
|
+
function applyProperties(node, props, previous) {
|
|
5355
|
+
const namespaced = isNamespaced(node);
|
|
5356
|
+
for (const propName in props) {
|
|
5357
|
+
const propValue = props[propName];
|
|
5358
|
+
if (propValue === undefined)
|
|
5359
|
+
removeProperty(node, propName, previous);
|
|
5360
|
+
else if (propName === "dangerouslySetInnerHTML")
|
|
5361
|
+
node.innerHTML = propValue.__html ?? "";
|
|
5362
|
+
else if (propName === "className")
|
|
5363
|
+
node.setAttribute("class", propValue);
|
|
5364
|
+
else if (namespaced || isHtmlAttribute(propName))
|
|
5365
|
+
node.setAttribute(propName, propValue);
|
|
5366
|
+
else
|
|
5367
|
+
node[propName] = propValue;
|
|
5365
5368
|
}
|
|
5366
|
-
if (producerComp == null || producerDyn == null)
|
|
5367
|
-
return null;
|
|
5368
|
-
const pi = producerDyn.val?.toPathItem?.() ?? null;
|
|
5369
|
-
return { producerCompId: producerComp.id, producerSteps: pi ? [pi] : [] };
|
|
5370
5369
|
}
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5370
|
+
function removeProperty(node, propName, previous) {
|
|
5371
|
+
const previousValue = previous[propName];
|
|
5372
|
+
if (propName === "dangerouslySetInnerHTML")
|
|
5373
|
+
node.replaceChildren();
|
|
5374
|
+
else if (propName === "className")
|
|
5375
|
+
node.removeAttribute("class");
|
|
5376
|
+
else if (propName === "htmlFor")
|
|
5377
|
+
node.removeAttribute("for");
|
|
5378
|
+
else if (isNamespaced(node) || typeof previousValue === "string" || isHtmlAttribute(propName))
|
|
5379
|
+
node.removeAttribute(propName);
|
|
5380
|
+
else
|
|
5381
|
+
node[propName] = null;
|
|
5383
5382
|
}
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
const child = childs[i];
|
|
5387
|
-
if (child.isConstant())
|
|
5388
|
-
childs[i] = new RenderOnceNode(child);
|
|
5389
|
-
else
|
|
5390
|
-
child.optimize();
|
|
5391
|
-
}
|
|
5383
|
+
|
|
5384
|
+
class VBase {
|
|
5392
5385
|
}
|
|
5393
|
-
function
|
|
5394
|
-
if (
|
|
5395
|
-
return
|
|
5396
|
-
|
|
5397
|
-
|
|
5386
|
+
function childsEqual(a, b) {
|
|
5387
|
+
if (a === b)
|
|
5388
|
+
return true;
|
|
5389
|
+
for (let i = 0;i < a.length; i++)
|
|
5390
|
+
if (!a[i].isEqualTo(b[i]))
|
|
5391
|
+
return false;
|
|
5392
|
+
return true;
|
|
5398
5393
|
}
|
|
5399
|
-
function
|
|
5400
|
-
|
|
5401
|
-
|
|
5402
|
-
const { name, value } = attrs[opIdx];
|
|
5403
|
-
const as = attrs.getNamedItem("as")?.value ?? null;
|
|
5404
|
-
let node;
|
|
5405
|
-
switch (name) {
|
|
5406
|
-
case "slot":
|
|
5407
|
-
node = new SlotNode(null, vp.const(value), maybeFragment(childs));
|
|
5408
|
-
break;
|
|
5409
|
-
case "text":
|
|
5410
|
-
node = px.addNodeIf(RenderTextNode, parseXOpVal(name, value, px, vp.parseText));
|
|
5411
|
-
break;
|
|
5412
|
-
case "render":
|
|
5413
|
-
node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px, vp.parseComponent), as);
|
|
5414
|
-
break;
|
|
5415
|
-
case "render-it":
|
|
5416
|
-
node = px.addNodeIf(RenderItNode, vp.bindValIt, as);
|
|
5417
|
-
break;
|
|
5418
|
-
case "render-each":
|
|
5419
|
-
node = RenderEachNode.parse(px, vp, value, as, attrs);
|
|
5420
|
-
break;
|
|
5421
|
-
case "show": {
|
|
5422
|
-
const val = parseXOpVal(name, value, px, vp.parseBool);
|
|
5423
|
-
node = px.addNodeIf(ShowNode, val, maybeFragment(childs));
|
|
5424
|
-
break;
|
|
5425
|
-
}
|
|
5426
|
-
case "hide": {
|
|
5427
|
-
const val = parseXOpVal(name, value, px, vp.parseBool);
|
|
5428
|
-
node = px.addNodeIf(HideNode, val, maybeFragment(childs));
|
|
5429
|
-
break;
|
|
5430
|
-
}
|
|
5431
|
-
default:
|
|
5432
|
-
px.onParseIssue("unknown-x-op", { name, value });
|
|
5433
|
-
return new CommentNode(`Error: InvalidSpecialTagOp ${name}=${value}`);
|
|
5434
|
-
}
|
|
5435
|
-
return processXExtras(node, attrs, name, opIdx + 1, px);
|
|
5394
|
+
function appendChildNodes(parent, childs, opts) {
|
|
5395
|
+
for (const child of childs)
|
|
5396
|
+
parent.appendChild(child.toDom(opts));
|
|
5436
5397
|
}
|
|
5437
|
-
function
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5398
|
+
function addChild(normalizedChildren, child) {
|
|
5399
|
+
if (child == null)
|
|
5400
|
+
return;
|
|
5401
|
+
if (isIterable(child)) {
|
|
5402
|
+
for (const c of child)
|
|
5403
|
+
addChild(normalizedChildren, c);
|
|
5404
|
+
} else if (child instanceof VBase) {
|
|
5405
|
+
if (child instanceof VFragment)
|
|
5406
|
+
normalizedChildren.push(...child.childs);
|
|
5407
|
+
else
|
|
5408
|
+
normalizedChildren.push(child);
|
|
5409
|
+
} else
|
|
5410
|
+
normalizedChildren.push(new VText(child));
|
|
5442
5411
|
}
|
|
5443
|
-
function
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
for (
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
continue;
|
|
5412
|
+
function diffProps(a, b) {
|
|
5413
|
+
if (a === b)
|
|
5414
|
+
return null;
|
|
5415
|
+
let diff = null;
|
|
5416
|
+
for (const aKey in a) {
|
|
5417
|
+
if (!Object.hasOwn(b, aKey)) {
|
|
5418
|
+
diff ??= {};
|
|
5419
|
+
diff[aKey] = undefined;
|
|
5420
|
+
} else if (a[aKey] !== b[aKey]) {
|
|
5421
|
+
diff ??= {};
|
|
5422
|
+
diff[aKey] = b[aKey];
|
|
5455
5423
|
}
|
|
5456
|
-
const issueInfo = { op: opName, name: aName, value: a.value };
|
|
5457
|
-
px.onParseIssue("unknown-x-attr", issueInfo);
|
|
5458
5424
|
}
|
|
5459
|
-
for (
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5425
|
+
for (const bKey in b) {
|
|
5426
|
+
if (!Object.hasOwn(a, bKey)) {
|
|
5427
|
+
diff ??= {};
|
|
5428
|
+
diff[bKey] = b[bKey];
|
|
5429
|
+
}
|
|
5464
5430
|
}
|
|
5465
|
-
return
|
|
5431
|
+
return diff;
|
|
5466
5432
|
}
|
|
5467
|
-
function
|
|
5468
|
-
if (
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5433
|
+
function morphNode(domNode, source, target, opts) {
|
|
5434
|
+
if (source === target || source.isEqualTo(target))
|
|
5435
|
+
return domNode;
|
|
5436
|
+
const type = source.nodeType;
|
|
5437
|
+
if (type === target.nodeType) {
|
|
5438
|
+
if (type === 3 || type === 8) {
|
|
5439
|
+
domNode.data = target.text;
|
|
5440
|
+
return domNode;
|
|
5441
|
+
}
|
|
5442
|
+
if (type === 1 && source.isSameKind(target)) {
|
|
5443
|
+
const propsDiff = diffProps(source.attrs, target.attrs);
|
|
5444
|
+
const isSelect = source.tag === "SELECT";
|
|
5445
|
+
if (propsDiff) {
|
|
5446
|
+
if (isSelect && "value" in propsDiff) {
|
|
5447
|
+
const { value: _v, ...rest } = propsDiff;
|
|
5448
|
+
applyProperties(domNode, rest, source.attrs);
|
|
5449
|
+
} else
|
|
5450
|
+
applyProperties(domNode, propsDiff, source.attrs);
|
|
5474
5451
|
}
|
|
5452
|
+
if (!target.attrs.dangerouslySetInnerHTML)
|
|
5453
|
+
morphChildren(domNode, source.childs, target.childs, opts);
|
|
5454
|
+
if (isSelect && target.attrs.value !== undefined)
|
|
5455
|
+
applyProperties(domNode, { value: target.attrs.value }, source.attrs);
|
|
5456
|
+
return domNode;
|
|
5457
|
+
}
|
|
5458
|
+
if (type === 11) {
|
|
5459
|
+
morphChildren(domNode, source.childs, target.childs, opts);
|
|
5460
|
+
return domNode;
|
|
5475
5461
|
}
|
|
5476
5462
|
}
|
|
5477
|
-
|
|
5463
|
+
const newNode = target.toDom(opts);
|
|
5464
|
+
domNode.parentNode?.replaceChild(newNode, domNode);
|
|
5465
|
+
return newNode;
|
|
5478
5466
|
}
|
|
5479
|
-
function
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
node.iterInfo.enrichWithVal = data.enrichWithVal ?? null;
|
|
5484
|
-
node.iterInfo.whenVal = data.whenVal ?? null;
|
|
5485
|
-
node.iterInfo.loopWithVal = data.loopWithVal ?? null;
|
|
5467
|
+
function morphChildren(parentDom, oldChilds, newChilds, opts) {
|
|
5468
|
+
if (oldChilds.length === 0) {
|
|
5469
|
+
appendChildNodes(parentDom, newChilds, opts);
|
|
5470
|
+
return;
|
|
5486
5471
|
}
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
class IterInfo {
|
|
5491
|
-
constructor(val, whenVal, loopWithVal, enrichWithVal) {
|
|
5492
|
-
this.val = val;
|
|
5493
|
-
this.whenVal = whenVal;
|
|
5494
|
-
this.loopWithVal = loopWithVal;
|
|
5495
|
-
this.enrichWithVal = enrichWithVal;
|
|
5472
|
+
if (newChilds.length === 0) {
|
|
5473
|
+
parentDom.replaceChildren();
|
|
5474
|
+
return;
|
|
5496
5475
|
}
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5476
|
+
if (oldChilds.length === newChilds.length) {
|
|
5477
|
+
let hasKey = false;
|
|
5478
|
+
for (let i = 0;i < oldChilds.length; i++) {
|
|
5479
|
+
if (getKey(oldChilds[i]) != null || getKey(newChilds[i]) != null) {
|
|
5480
|
+
hasKey = true;
|
|
5481
|
+
break;
|
|
5482
|
+
}
|
|
5483
|
+
}
|
|
5484
|
+
if (!hasKey) {
|
|
5485
|
+
let dom = parentDom.firstChild;
|
|
5486
|
+
for (let i = 0;i < oldChilds.length; i++) {
|
|
5487
|
+
const next = dom.nextSibling;
|
|
5488
|
+
morphNode(dom, oldChilds[i], newChilds[i], opts);
|
|
5489
|
+
dom = next;
|
|
5490
|
+
}
|
|
5491
|
+
return;
|
|
5492
|
+
}
|
|
5503
5493
|
}
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
|
|
5510
|
-
this.macroNodes = macroNodes ?? [];
|
|
5511
|
-
this.parent = parent ?? null;
|
|
5512
|
-
this.frame = frame ?? {};
|
|
5513
|
-
this.document = document2 ?? globalThis.document;
|
|
5514
|
-
this.Text = Text ?? globalThis.Text;
|
|
5515
|
-
this.Comment = Comment ?? globalThis.Comment;
|
|
5516
|
-
this.cacheConstNodes = true;
|
|
5517
|
-
this.currentTag = null;
|
|
5518
|
-
}
|
|
5519
|
-
isInsideMacro(name) {
|
|
5520
|
-
return this.frame.macroName === name || this.parent?.isInsideMacro(name);
|
|
5521
|
-
}
|
|
5522
|
-
enterMacro(macroName, macroVars, macroSlots) {
|
|
5523
|
-
const { document: document2, Text, Comment, nodes, events, macroNodes } = this;
|
|
5524
|
-
const frame = { macroName, macroVars, macroSlots };
|
|
5525
|
-
return new ParseContext(document2, Text, Comment, nodes, events, macroNodes, frame, this);
|
|
5526
|
-
}
|
|
5527
|
-
parseHTML(html) {
|
|
5528
|
-
const t = this.document.createElement("template");
|
|
5529
|
-
t.innerHTML = html;
|
|
5530
|
-
return t.content.childNodes;
|
|
5494
|
+
const domNodes = Array.from(parentDom.childNodes);
|
|
5495
|
+
const oldKeyMap = Object.create(null);
|
|
5496
|
+
for (let i = 0;i < oldChilds.length; i++) {
|
|
5497
|
+
const key = getKey(oldChilds[i]);
|
|
5498
|
+
if (key != null)
|
|
5499
|
+
oldKeyMap[key] = i;
|
|
5531
5500
|
}
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5501
|
+
const used = new Uint8Array(oldChilds.length);
|
|
5502
|
+
let unkeyedCursor = 0;
|
|
5503
|
+
for (let j = 0;j < newChilds.length; j++) {
|
|
5504
|
+
const newChild = newChilds[j];
|
|
5505
|
+
const newKey = getKey(newChild);
|
|
5506
|
+
let oldIdx = -1;
|
|
5507
|
+
if (newKey != null) {
|
|
5508
|
+
if (newKey in oldKeyMap && !used[oldKeyMap[newKey]])
|
|
5509
|
+
oldIdx = oldKeyMap[newKey];
|
|
5510
|
+
} else {
|
|
5511
|
+
while (unkeyedCursor < oldChilds.length) {
|
|
5512
|
+
if (!used[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
|
|
5513
|
+
oldIdx = unkeyedCursor++;
|
|
5514
|
+
break;
|
|
5515
|
+
}
|
|
5516
|
+
unkeyedCursor++;
|
|
5517
|
+
}
|
|
5538
5518
|
}
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
|
|
5543
|
-
|
|
5544
|
-
|
|
5545
|
-
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
const anySlot = [];
|
|
5549
|
-
const slots = { _: new FragmentNode(anySlot) };
|
|
5550
|
-
for (const child of childs)
|
|
5551
|
-
if (child instanceof SlotNode)
|
|
5552
|
-
slots[child.val.val] = child.node;
|
|
5553
|
-
else if (!(child instanceof TextNode) || !child.isWhiteSpace())
|
|
5554
|
-
anySlot.push(child);
|
|
5555
|
-
const node = new MacroNode(macroName, mAttrs, slots, this);
|
|
5556
|
-
this.macroNodes.push(node);
|
|
5557
|
-
return node;
|
|
5558
|
-
}
|
|
5559
|
-
compile(scope) {
|
|
5560
|
-
for (let i = 0;i < this.macroNodes.length; i++)
|
|
5561
|
-
this.macroNodes[i].compile(scope);
|
|
5562
|
-
}
|
|
5563
|
-
*genEventNames() {
|
|
5564
|
-
for (const event of this.events)
|
|
5565
|
-
yield* event.genEventNames();
|
|
5566
|
-
}
|
|
5567
|
-
getEventForId(id) {
|
|
5568
|
-
return this.events[id] ?? null;
|
|
5569
|
-
}
|
|
5570
|
-
getNodeForId(id) {
|
|
5571
|
-
return this.nodes[id] ?? null;
|
|
5572
|
-
}
|
|
5573
|
-
onAttributes(_attrs, _wrapperAttrs, _textChild, _isMacroCall, _tag) {}
|
|
5574
|
-
onParseIssue(kind, info) {
|
|
5575
|
-
console.warn(`tutuca parse issue [${kind}]`, info);
|
|
5576
|
-
}
|
|
5577
|
-
}
|
|
5578
|
-
function condenseChildsWhites(childs) {
|
|
5579
|
-
if (childs.length === 0)
|
|
5580
|
-
return childs;
|
|
5581
|
-
let changed = false;
|
|
5582
|
-
if (childs[0].isWhiteSpace?.()) {
|
|
5583
|
-
childs[0].condenseWhiteSpace();
|
|
5584
|
-
changed = true;
|
|
5585
|
-
}
|
|
5586
|
-
const last = childs.length - 1;
|
|
5587
|
-
if (last > 0 && childs[last].isWhiteSpace?.()) {
|
|
5588
|
-
childs[last].condenseWhiteSpace();
|
|
5589
|
-
changed = true;
|
|
5590
|
-
}
|
|
5591
|
-
for (let i = 1;i < last; i++) {
|
|
5592
|
-
const cur = childs[i];
|
|
5593
|
-
if (cur.isWhiteSpace?.() && cur.hasNewLine()) {
|
|
5594
|
-
const bothBlock = isBlockDomNode(childs[i - 1]) && isBlockDomNode(childs[i + 1]);
|
|
5595
|
-
cur.condenseWhiteSpace(bothBlock ? "" : " ");
|
|
5596
|
-
if (bothBlock)
|
|
5597
|
-
changed = true;
|
|
5519
|
+
if (oldIdx >= 0) {
|
|
5520
|
+
used[oldIdx] = 1;
|
|
5521
|
+
const newDom = morphNode(domNodes[oldIdx], oldChilds[oldIdx], newChild, opts);
|
|
5522
|
+
const ref = parentDom.childNodes[j] ?? null;
|
|
5523
|
+
if (newDom !== ref)
|
|
5524
|
+
parentDom.insertBefore(newDom, ref);
|
|
5525
|
+
} else {
|
|
5526
|
+
const ref = parentDom.childNodes[j] ?? null;
|
|
5527
|
+
parentDom.insertBefore(newChild.toDom(opts), ref);
|
|
5598
5528
|
}
|
|
5599
5529
|
}
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
class NodeEvents {
|
|
5604
|
-
constructor(id) {
|
|
5605
|
-
this.id = id;
|
|
5606
|
-
this.handlers = [];
|
|
5607
|
-
}
|
|
5608
|
-
add(name, handlerCall, modifiers) {
|
|
5609
|
-
this.handlers.push(new NodeEvent(name, handlerCall, modifiers));
|
|
5610
|
-
}
|
|
5611
|
-
*genEventNames() {
|
|
5612
|
-
for (const handler of this.handlers)
|
|
5613
|
-
yield handler.name;
|
|
5614
|
-
}
|
|
5615
|
-
getHandlersFor(eventName) {
|
|
5616
|
-
let r = null;
|
|
5617
|
-
for (const handler of this.handlers)
|
|
5618
|
-
if (handler.handlesEventName(eventName)) {
|
|
5619
|
-
r ??= [];
|
|
5620
|
-
r.push(handler);
|
|
5621
|
-
}
|
|
5622
|
-
return r;
|
|
5623
|
-
}
|
|
5530
|
+
for (let i = oldChilds.length - 1;i >= 0; i--)
|
|
5531
|
+
if (!used[i] && domNodes[i].parentNode === parentDom)
|
|
5532
|
+
parentDom.removeChild(domNodes[i]);
|
|
5624
5533
|
}
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
this.modifiers = modifiers;
|
|
5632
|
-
}
|
|
5633
|
-
handlesEventName(name) {
|
|
5634
|
-
return this.name === name;
|
|
5635
|
-
}
|
|
5636
|
-
getHandlerAndArgs(stack, event) {
|
|
5637
|
-
const r = this.handlerCall.getHandlerAndArgs(stack, event);
|
|
5638
|
-
r[0] = this.modifierWrapper(r[0], event);
|
|
5639
|
-
return r;
|
|
5534
|
+
function render(vnode, container, options, prev) {
|
|
5535
|
+
const isFragment = vnode instanceof VFragment;
|
|
5536
|
+
if (prev && prev.vnode instanceof VFragment === isFragment) {
|
|
5537
|
+
const oldDom = isFragment ? container : prev.dom;
|
|
5538
|
+
const newDom = morphNode(oldDom, prev.vnode, vnode, options);
|
|
5539
|
+
return { vnode, dom: isFragment ? container : newDom };
|
|
5640
5540
|
}
|
|
5541
|
+
const domNode = vnode.toDom(options);
|
|
5542
|
+
container.replaceChildren(domNode);
|
|
5543
|
+
return { vnode, dom: isFragment ? container : domNode };
|
|
5641
5544
|
}
|
|
5642
|
-
function
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5650
|
-
|
|
5545
|
+
function h(tagName, properties, children, namespace) {
|
|
5546
|
+
const props = {};
|
|
5547
|
+
let key;
|
|
5548
|
+
if (properties) {
|
|
5549
|
+
for (const propName in properties) {
|
|
5550
|
+
const propVal = properties[propName];
|
|
5551
|
+
switch (propName) {
|
|
5552
|
+
case "key":
|
|
5553
|
+
key = propVal;
|
|
5554
|
+
break;
|
|
5555
|
+
case "namespace":
|
|
5556
|
+
namespace = namespace ?? propVal;
|
|
5557
|
+
break;
|
|
5558
|
+
case "class":
|
|
5559
|
+
props.className = propVal;
|
|
5560
|
+
break;
|
|
5561
|
+
case "for":
|
|
5562
|
+
props.htmlFor = propVal;
|
|
5563
|
+
break;
|
|
5564
|
+
default:
|
|
5565
|
+
props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
|
|
5566
|
+
}
|
|
5567
|
+
}
|
|
5651
5568
|
}
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5569
|
+
const c = tagName.charCodeAt(0);
|
|
5570
|
+
const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
|
|
5571
|
+
const normalizedChildren = [];
|
|
5572
|
+
addChild(normalizedChildren, children);
|
|
5573
|
+
return new VNode2(tag, props, normalizedChildren, key, namespace);
|
|
5655
5574
|
}
|
|
5656
|
-
var
|
|
5657
|
-
const
|
|
5658
|
-
return
|
|
5659
|
-
},
|
|
5660
|
-
var
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
init_value();
|
|
5664
|
-
TextNode = class TextNode extends BaseNode {
|
|
5665
|
-
constructor(val) {
|
|
5575
|
+
var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a"), HTML_NS = "http://www.w3.org/1999/xhtml", isNamespaced = (node) => {
|
|
5576
|
+
const ns = node.namespaceURI;
|
|
5577
|
+
return ns !== null && ns !== HTML_NS;
|
|
5578
|
+
}, getKey = (child) => child instanceof VNode2 ? child.key : undefined, isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function", VText, VComment, VFragment, VNode2;
|
|
5579
|
+
var init_vdom = __esm(() => {
|
|
5580
|
+
VText = class VText extends VBase {
|
|
5581
|
+
constructor(text) {
|
|
5666
5582
|
super();
|
|
5667
|
-
this.
|
|
5668
|
-
}
|
|
5669
|
-
render(_stack, _rx) {
|
|
5670
|
-
return this.val;
|
|
5671
|
-
}
|
|
5672
|
-
isWhiteSpace() {
|
|
5673
|
-
for (let i = 0;i < this.val.length; i++) {
|
|
5674
|
-
const c = this.val.charCodeAt(i);
|
|
5675
|
-
if (!(c === 32 || c === 10 || c === 9 || c === 13))
|
|
5676
|
-
return false;
|
|
5677
|
-
}
|
|
5678
|
-
return true;
|
|
5679
|
-
}
|
|
5680
|
-
hasNewLine() {
|
|
5681
|
-
for (let i = 0;i < this.val.length; i++) {
|
|
5682
|
-
const c = this.val.charCodeAt(i);
|
|
5683
|
-
if (c === 10 || c === 13)
|
|
5684
|
-
return true;
|
|
5685
|
-
}
|
|
5686
|
-
return false;
|
|
5583
|
+
this.text = String(text);
|
|
5687
5584
|
}
|
|
5688
|
-
|
|
5689
|
-
|
|
5585
|
+
get nodeType() {
|
|
5586
|
+
return 3;
|
|
5690
5587
|
}
|
|
5691
|
-
|
|
5692
|
-
return
|
|
5588
|
+
isEqualTo(other) {
|
|
5589
|
+
return other instanceof VText && this.text === other.text;
|
|
5693
5590
|
}
|
|
5694
|
-
|
|
5695
|
-
|
|
5696
|
-
CommentNode = class CommentNode extends TextNode {
|
|
5697
|
-
render(_stack, rx) {
|
|
5698
|
-
return rx.renderComment(this.val);
|
|
5591
|
+
toDom(opts) {
|
|
5592
|
+
return opts.document.createTextNode(this.text);
|
|
5699
5593
|
}
|
|
5700
5594
|
};
|
|
5701
|
-
|
|
5702
|
-
constructor(
|
|
5595
|
+
VComment = class VComment extends VBase {
|
|
5596
|
+
constructor(text) {
|
|
5703
5597
|
super();
|
|
5704
|
-
this.
|
|
5598
|
+
this.text = text;
|
|
5705
5599
|
}
|
|
5706
|
-
|
|
5707
|
-
return
|
|
5600
|
+
get nodeType() {
|
|
5601
|
+
return 8;
|
|
5708
5602
|
}
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
}
|
|
5712
|
-
};
|
|
5713
|
-
DomNode = class DomNode extends ChildsNode {
|
|
5714
|
-
constructor(tagName, attrs, childs) {
|
|
5715
|
-
super(childs);
|
|
5716
|
-
this.tagName = tagName;
|
|
5717
|
-
this.attrs = attrs;
|
|
5718
|
-
}
|
|
5719
|
-
render(stack, rx) {
|
|
5720
|
-
const childNodes = new Array(this.childs.length);
|
|
5721
|
-
for (let i = 0;i < childNodes.length; i++)
|
|
5722
|
-
childNodes[i] = this.childs[i]?.render?.(stack, rx) ?? null;
|
|
5723
|
-
return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes);
|
|
5724
|
-
}
|
|
5725
|
-
setDataAttr(key, val) {
|
|
5726
|
-
this.attrs.setDataAttr(key, val);
|
|
5727
|
-
}
|
|
5728
|
-
isConstant() {
|
|
5729
|
-
return this.attrs.isConstant() && super.isConstant();
|
|
5730
|
-
}
|
|
5731
|
-
};
|
|
5732
|
-
FragmentNode = class FragmentNode extends ChildsNode {
|
|
5733
|
-
render(stack, rx) {
|
|
5734
|
-
return rx.renderFragment(this.childs.map((c) => c?.render(stack, rx)));
|
|
5603
|
+
isEqualTo(other) {
|
|
5604
|
+
return other instanceof VComment && this.text === other.text;
|
|
5735
5605
|
}
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
child.setDataAttr(key, val);
|
|
5606
|
+
toDom(opts) {
|
|
5607
|
+
return opts.document.createComment(this.text);
|
|
5739
5608
|
}
|
|
5740
5609
|
};
|
|
5741
|
-
|
|
5742
|
-
|
|
5743
|
-
constructor(nodeId, val) {
|
|
5610
|
+
VFragment = class VFragment extends VBase {
|
|
5611
|
+
constructor(childs) {
|
|
5744
5612
|
super();
|
|
5745
|
-
this.
|
|
5746
|
-
this.
|
|
5613
|
+
this.childs = [];
|
|
5614
|
+
addChild(this.childs, childs);
|
|
5747
5615
|
}
|
|
5748
|
-
|
|
5749
|
-
return
|
|
5616
|
+
get nodeType() {
|
|
5617
|
+
return 11;
|
|
5750
5618
|
}
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
if (nodes.length === 1)
|
|
5756
|
-
return ANode.fromDOM(nodes[0], px);
|
|
5757
|
-
const childs = [];
|
|
5758
|
-
for (let i = 0;i < nodes.length; i++) {
|
|
5759
|
-
const child = ANode.fromDOM(nodes[i], px);
|
|
5760
|
-
if (child !== null)
|
|
5761
|
-
childs.push(child);
|
|
5762
|
-
}
|
|
5763
|
-
const trimmed = condenseChildsWhites(childs);
|
|
5764
|
-
if (trimmed.length === 0)
|
|
5765
|
-
return new CommentNode("Empty View in ANode.parse");
|
|
5766
|
-
return maybeFragment(trimmed);
|
|
5619
|
+
isEqualTo(other) {
|
|
5620
|
+
if (!(other instanceof VFragment) || this.childs.length !== other.childs.length)
|
|
5621
|
+
return false;
|
|
5622
|
+
return childsEqual(this.childs, other.childs);
|
|
5767
5623
|
}
|
|
5768
|
-
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
return new CommentNode(node.textContent);
|
|
5773
|
-
const { childNodes, attributes: attrs, tagName: tag } = node;
|
|
5774
|
-
const childs = [];
|
|
5775
|
-
for (let i = 0;i < childNodes.length; i++) {
|
|
5776
|
-
const child = ANode.fromDOM(childNodes[i], px);
|
|
5777
|
-
if (child !== null)
|
|
5778
|
-
childs.push(child);
|
|
5779
|
-
}
|
|
5780
|
-
const prevTag = px.currentTag;
|
|
5781
|
-
px.currentTag = tag;
|
|
5782
|
-
try {
|
|
5783
|
-
const isPseudoX = attrs[0]?.name === "@x";
|
|
5784
|
-
if (tag === "X" || isPseudoX)
|
|
5785
|
-
return parseXOp(attrs, childs, isPseudoX ? 1 : 0, px);
|
|
5786
|
-
else if (tag.charCodeAt(1) === 58 && tag.charCodeAt(0) === 88) {
|
|
5787
|
-
const macroName = tag.slice(2).toLowerCase();
|
|
5788
|
-
if (macroName === "slot") {
|
|
5789
|
-
const slotName = attrs.getNamedItem("name")?.value ?? "_";
|
|
5790
|
-
return px.frame.macroSlots[slotName] ?? maybeFragment(childs);
|
|
5791
|
-
}
|
|
5792
|
-
const [nAttrs, wrappers] = Attributes.parse(attrs, px, true);
|
|
5793
|
-
px.onAttributes(nAttrs, wrappers, null, true, tag);
|
|
5794
|
-
return wrap(px.newMacroNode(macroName, nAttrs.toMacroVars(), childs), px, wrappers);
|
|
5795
|
-
} else if (VALID_NODE_RE.test(tag)) {
|
|
5796
|
-
const [nAttrs, wrappers, textChild] = Attributes.parse(attrs, px);
|
|
5797
|
-
px.onAttributes(nAttrs, wrappers, textChild, false, tag);
|
|
5798
|
-
if (textChild)
|
|
5799
|
-
childs.unshift(new RenderTextNode(null, textChild));
|
|
5800
|
-
const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
|
|
5801
|
-
return wrap(new DomNode(tag, nAttrs, domChilds), px, wrappers);
|
|
5802
|
-
}
|
|
5803
|
-
return new CommentNode(`Error: InvalidTagName ${tag}`);
|
|
5804
|
-
} finally {
|
|
5805
|
-
px.currentTag = prevTag;
|
|
5806
|
-
}
|
|
5624
|
+
toDom(opts) {
|
|
5625
|
+
const fragment = opts.document.createDocumentFragment();
|
|
5626
|
+
appendChildNodes(fragment, this.childs, opts);
|
|
5627
|
+
return fragment;
|
|
5807
5628
|
}
|
|
5808
5629
|
};
|
|
5809
|
-
|
|
5810
|
-
constructor(
|
|
5630
|
+
VNode2 = class VNode2 extends VBase {
|
|
5631
|
+
constructor(tag, attrs, childs, key, namespace) {
|
|
5811
5632
|
super();
|
|
5812
|
-
this.
|
|
5813
|
-
this.attrs = attrs;
|
|
5814
|
-
this.
|
|
5815
|
-
this.
|
|
5816
|
-
this.
|
|
5817
|
-
this.dataAttrs = {};
|
|
5818
|
-
}
|
|
5819
|
-
compile(scope) {
|
|
5820
|
-
const { name, attrs, slots } = this;
|
|
5821
|
-
if (this.px.isInsideMacro(name))
|
|
5822
|
-
throw new Error(`Recursive macro expansion: ${name}`);
|
|
5823
|
-
const macro = scope.lookupMacro(name);
|
|
5824
|
-
if (macro === null)
|
|
5825
|
-
this.node = new CommentNode(`bad macro: ${name}`);
|
|
5826
|
-
else {
|
|
5827
|
-
const vars = { ...macro.defaults, ...attrs };
|
|
5828
|
-
this.node = macro.expand(this.px.enterMacro(name, vars, slots));
|
|
5829
|
-
for (const key in this.dataAttrs)
|
|
5830
|
-
this.node.setDataAttr(key, this.dataAttrs[key]);
|
|
5831
|
-
}
|
|
5832
|
-
}
|
|
5833
|
-
render(stack, rx) {
|
|
5834
|
-
return this.node.render(stack, rx);
|
|
5835
|
-
}
|
|
5836
|
-
setDataAttr(key, val) {
|
|
5837
|
-
this.dataAttrs[key] = val;
|
|
5838
|
-
}
|
|
5839
|
-
isConstant() {
|
|
5840
|
-
return this.node.isConstant();
|
|
5841
|
-
}
|
|
5842
|
-
optimize() {
|
|
5843
|
-
this.node = optimizeNode(this.node);
|
|
5844
|
-
}
|
|
5845
|
-
};
|
|
5846
|
-
RenderViewId = class RenderViewId extends ANode {
|
|
5847
|
-
constructor(nodeId, val, viewId) {
|
|
5848
|
-
super(nodeId, val);
|
|
5849
|
-
this.viewId = viewId;
|
|
5850
|
-
}
|
|
5851
|
-
};
|
|
5852
|
-
RenderNode = class RenderNode extends RenderViewId {
|
|
5853
|
-
render(stack, rx) {
|
|
5854
|
-
const newStack = stack.enter(this.val.eval(stack), {}, true);
|
|
5855
|
-
return rx.renderIt(newStack, this, "", this.viewId);
|
|
5633
|
+
this.tag = tag;
|
|
5634
|
+
this.attrs = attrs ?? {};
|
|
5635
|
+
this.childs = childs ?? [];
|
|
5636
|
+
this.key = key != null ? String(key) : undefined;
|
|
5637
|
+
this.namespace = typeof namespace === "string" ? namespace : null;
|
|
5856
5638
|
}
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
const p = resolveDynProducer(ctx.comp, this.val.name);
|
|
5860
|
-
return p ? new DynStep(p.producerCompId, p.producerSteps) : null;
|
|
5861
|
-
}
|
|
5862
|
-
return super.toPathStep(ctx);
|
|
5639
|
+
get nodeType() {
|
|
5640
|
+
return 1;
|
|
5863
5641
|
}
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
render(stack, rx) {
|
|
5867
|
-
const newStack = stack.enter(stack.it, {}, true);
|
|
5868
|
-
return rx.renderIt(newStack, this, "", this.viewId);
|
|
5642
|
+
isSameKind(other) {
|
|
5643
|
+
return this.tag === other.tag && this.namespace === other.namespace && this.key === other.key;
|
|
5869
5644
|
}
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
if (nextNode instanceof EachNode && next.hasKey) {
|
|
5876
|
-
if (nextNode.val instanceof DynVal) {
|
|
5877
|
-
const p = resolveDynProducer(ctx.comp, nextNode.val.name);
|
|
5878
|
-
return p ? new DynEachStep(p.producerCompId, p.producerSteps, next.key) : null;
|
|
5879
|
-
}
|
|
5880
|
-
return new EachRenderItStep(nextNode.val.name, next.key);
|
|
5645
|
+
isEqualTo(other) {
|
|
5646
|
+
if (this === other)
|
|
5647
|
+
return true;
|
|
5648
|
+
if (!(other instanceof VNode2) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
|
|
5649
|
+
return false;
|
|
5881
5650
|
}
|
|
5882
|
-
|
|
5883
|
-
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
}
|
|
5890
|
-
render(stack, rx) {
|
|
5891
|
-
return rx.renderEach(stack, this.iterInfo, this, this.viewId);
|
|
5892
|
-
}
|
|
5893
|
-
toPathStep(ctx) {
|
|
5894
|
-
if (this.val instanceof DynVal) {
|
|
5895
|
-
if (!ctx.hasKey)
|
|
5896
|
-
return null;
|
|
5897
|
-
const p = resolveDynProducer(ctx.comp, this.val.name);
|
|
5898
|
-
return p ? new DynEachStep(p.producerCompId, p.producerSteps, ctx.key) : null;
|
|
5651
|
+
if (this.attrs !== other.attrs) {
|
|
5652
|
+
for (const key in this.attrs)
|
|
5653
|
+
if (this.attrs[key] !== other.attrs[key])
|
|
5654
|
+
return false;
|
|
5655
|
+
for (const key in other.attrs)
|
|
5656
|
+
if (!Object.hasOwn(this.attrs, key))
|
|
5657
|
+
return false;
|
|
5899
5658
|
}
|
|
5900
|
-
return
|
|
5659
|
+
return childsEqual(this.childs, other.childs);
|
|
5901
5660
|
}
|
|
5902
|
-
|
|
5903
|
-
const
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
node.iterInfo.whenVal = attrParser.eachAttr.whenVal ?? null;
|
|
5914
|
-
node.iterInfo.loopWithVal = attrParser.eachAttr.loopWithVal ?? null;
|
|
5661
|
+
toDom(opts) {
|
|
5662
|
+
const doc = opts.document;
|
|
5663
|
+
const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
|
|
5664
|
+
if (this.tag === "SELECT" && "value" in this.attrs) {
|
|
5665
|
+
const { value, ...rest } = this.attrs;
|
|
5666
|
+
applyProperties(node, rest, {});
|
|
5667
|
+
appendChildNodes(node, this.childs, opts);
|
|
5668
|
+
applyProperties(node, { value }, {});
|
|
5669
|
+
} else {
|
|
5670
|
+
applyProperties(node, this.attrs, {});
|
|
5671
|
+
appendChildNodes(node, this.childs, opts);
|
|
5915
5672
|
}
|
|
5916
5673
|
return node;
|
|
5917
5674
|
}
|
|
5918
5675
|
};
|
|
5919
|
-
|
|
5920
|
-
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5676
|
+
});
|
|
5677
|
+
|
|
5678
|
+
// src/anode.js
|
|
5679
|
+
function resolveDynProducer(comp, dynName) {
|
|
5680
|
+
const dyn = comp?.dynamic?.[dynName];
|
|
5681
|
+
if (dyn == null)
|
|
5682
|
+
return null;
|
|
5683
|
+
let producerComp, producerDyn;
|
|
5684
|
+
if (dyn.compName != null) {
|
|
5685
|
+
producerComp = comp.scope?.lookupComponent(dyn.compName);
|
|
5686
|
+
producerDyn = producerComp?.dynamic?.[dyn.dynName];
|
|
5687
|
+
} else {
|
|
5688
|
+
producerComp = comp;
|
|
5689
|
+
producerDyn = dyn;
|
|
5690
|
+
}
|
|
5691
|
+
if (producerComp == null || producerDyn == null)
|
|
5692
|
+
return null;
|
|
5693
|
+
const pi = producerDyn.val?.toPathItem?.() ?? null;
|
|
5694
|
+
return { producerCompId: producerComp.id, producerSteps: pi ? [pi] : [] };
|
|
5695
|
+
}
|
|
5696
|
+
|
|
5697
|
+
class BaseNode {
|
|
5698
|
+
render(_stack, _rx) {
|
|
5699
|
+
return null;
|
|
5700
|
+
}
|
|
5701
|
+
setDataAttr(key, val) {
|
|
5702
|
+
console.warn("setDataAttr not implemented for", this, { key, val });
|
|
5703
|
+
}
|
|
5704
|
+
isConstant() {
|
|
5705
|
+
return false;
|
|
5706
|
+
}
|
|
5707
|
+
optimize() {}
|
|
5708
|
+
}
|
|
5709
|
+
function optimizeChilds(childs) {
|
|
5710
|
+
for (let i = 0;i < childs.length; i++) {
|
|
5711
|
+
const child = childs[i];
|
|
5712
|
+
if (child.isConstant())
|
|
5713
|
+
childs[i] = new RenderOnceNode(child);
|
|
5714
|
+
else
|
|
5715
|
+
child.optimize();
|
|
5716
|
+
}
|
|
5717
|
+
}
|
|
5718
|
+
function optimizeNode(node) {
|
|
5719
|
+
if (node.isConstant())
|
|
5720
|
+
return new RenderOnceNode(node);
|
|
5721
|
+
node.optimize();
|
|
5722
|
+
return node;
|
|
5723
|
+
}
|
|
5724
|
+
function parseXOp(attrs, childs, opIdx, px) {
|
|
5725
|
+
if (attrs.length === 0)
|
|
5726
|
+
return maybeFragment(childs);
|
|
5727
|
+
const { name, value } = attrs[opIdx];
|
|
5728
|
+
const as = attrs.getNamedItem("as")?.value ?? null;
|
|
5729
|
+
let node;
|
|
5730
|
+
switch (name) {
|
|
5731
|
+
case "slot":
|
|
5732
|
+
node = new SlotNode(null, vp.const(value), maybeFragment(childs));
|
|
5733
|
+
break;
|
|
5734
|
+
case "text":
|
|
5735
|
+
node = px.addNodeIf(RenderTextNode, parseXOpVal(name, value, px, vp.parseText));
|
|
5736
|
+
break;
|
|
5737
|
+
case "render":
|
|
5738
|
+
node = px.addNodeIf(RenderNode, parseXOpVal(name, value, px, vp.parseComponent), as);
|
|
5739
|
+
break;
|
|
5740
|
+
case "render-it":
|
|
5741
|
+
node = px.addNodeIf(RenderItNode, vp.bindValIt, as);
|
|
5742
|
+
break;
|
|
5743
|
+
case "render-each":
|
|
5744
|
+
node = RenderEachNode.parse(px, vp, value, as, attrs);
|
|
5745
|
+
break;
|
|
5746
|
+
case "show": {
|
|
5747
|
+
const val = parseXOpVal(name, value, px, vp.parseBool);
|
|
5748
|
+
node = px.addNodeIf(ShowNode, val, maybeFragment(childs));
|
|
5749
|
+
break;
|
|
5750
|
+
}
|
|
5751
|
+
case "hide": {
|
|
5752
|
+
const val = parseXOpVal(name, value, px, vp.parseBool);
|
|
5753
|
+
node = px.addNodeIf(HideNode, val, maybeFragment(childs));
|
|
5754
|
+
break;
|
|
5755
|
+
}
|
|
5756
|
+
default:
|
|
5757
|
+
px.onParseIssue("unknown-x-op", { name, value });
|
|
5758
|
+
return new CommentNode(`Error: InvalidSpecialTagOp ${name}=${value}`);
|
|
5759
|
+
}
|
|
5760
|
+
return processXExtras(node, attrs, name, opIdx + 1, px);
|
|
5761
|
+
}
|
|
5762
|
+
function parseXOpVal(opName, value, px, parserFn) {
|
|
5763
|
+
const val = parserFn.call(vp, value, px);
|
|
5764
|
+
if (val === null)
|
|
5765
|
+
px.onParseIssue("bad-value", { role: "x-op", op: opName, value });
|
|
5766
|
+
return val;
|
|
5767
|
+
}
|
|
5768
|
+
function processXExtras(node, attrs, opName, startIdx, px) {
|
|
5769
|
+
const consumed = X_OP_CONSUMED[opName];
|
|
5770
|
+
const wrappable = X_OP_WRAPPABLE.has(opName);
|
|
5771
|
+
const wrappers = [];
|
|
5772
|
+
for (let i = startIdx;i < attrs.length; i++) {
|
|
5773
|
+
const a = attrs[i];
|
|
5774
|
+
const aName = a.name;
|
|
5775
|
+
if (consumed.has(aName))
|
|
5776
|
+
continue;
|
|
5777
|
+
if (wrappable && X_ATTR_WRAPPERS[aName]) {
|
|
5778
|
+
wrappers.push([X_ATTR_WRAPPERS[aName], vp.parseBool(a.value, px)]);
|
|
5779
|
+
continue;
|
|
5780
|
+
}
|
|
5781
|
+
const issueInfo = { op: opName, name: aName, value: a.value };
|
|
5782
|
+
px.onParseIssue("unknown-x-attr", issueInfo);
|
|
5783
|
+
}
|
|
5784
|
+
for (let i = wrappers.length - 1;i >= 0; i--) {
|
|
5785
|
+
const [Cls, val] = wrappers[i];
|
|
5786
|
+
const wrapper = px.addNodeIf(Cls, val, node);
|
|
5787
|
+
if (wrapper !== null)
|
|
5788
|
+
node = wrapper;
|
|
5789
|
+
}
|
|
5790
|
+
return node;
|
|
5791
|
+
}
|
|
5792
|
+
function wrap(node, px, wrappers) {
|
|
5793
|
+
if (wrappers) {
|
|
5794
|
+
for (let i = wrappers.length - 1;i >= 0; i--) {
|
|
5795
|
+
const wrapperNode = makeWrapperNode(wrappers[i], px);
|
|
5796
|
+
if (wrapperNode) {
|
|
5797
|
+
wrapperNode.wrapNode(node);
|
|
5798
|
+
node = wrapperNode;
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5802
|
+
return node;
|
|
5803
|
+
}
|
|
5804
|
+
function makeWrapperNode(data, px) {
|
|
5805
|
+
const Cls = WRAPPER_NODES[data.name];
|
|
5806
|
+
const node = Cls.register ? px.addNodeIf(Cls, data.val) : data.val && new Cls(null, data.val);
|
|
5807
|
+
if (node !== null && data.name === "each") {
|
|
5808
|
+
node.iterInfo.enrichWithVal = data.enrichWithVal ?? null;
|
|
5809
|
+
node.iterInfo.whenVal = data.whenVal ?? null;
|
|
5810
|
+
node.iterInfo.loopWithVal = data.loopWithVal ?? null;
|
|
5811
|
+
}
|
|
5812
|
+
return node;
|
|
5813
|
+
}
|
|
5814
|
+
|
|
5815
|
+
class IterInfo {
|
|
5816
|
+
constructor(val, whenVal, loopWithVal, enrichWithVal) {
|
|
5817
|
+
this.val = val;
|
|
5818
|
+
this.whenVal = whenVal;
|
|
5819
|
+
this.loopWithVal = loopWithVal;
|
|
5820
|
+
this.enrichWithVal = enrichWithVal;
|
|
5821
|
+
}
|
|
5822
|
+
eval(stack) {
|
|
5823
|
+
const seq = this.val.eval(stack) ?? [];
|
|
5824
|
+
const filter = this.whenVal?.evalAsHandler(stack) ?? filterAlwaysTrue;
|
|
5825
|
+
const loopWith = this.loopWithVal?.evalAsHandler(stack) ?? nullLoopWith;
|
|
5826
|
+
const enricher = this.enrichWithVal?.evalAsHandler(stack) ?? null;
|
|
5827
|
+
return { seq, filter, loopWith, enricher };
|
|
5828
|
+
}
|
|
5829
|
+
}
|
|
5830
|
+
|
|
5831
|
+
class ParseContext {
|
|
5832
|
+
constructor(document2, Text, Comment, nodes, events, macroNodes, frame, parent) {
|
|
5833
|
+
this.nodes = nodes ?? [];
|
|
5834
|
+
this.events = events ?? [];
|
|
5835
|
+
this.macroNodes = macroNodes ?? [];
|
|
5836
|
+
this.parent = parent ?? null;
|
|
5837
|
+
this.frame = frame ?? {};
|
|
5838
|
+
this.document = document2 ?? globalThis.document;
|
|
5839
|
+
this.Text = Text ?? globalThis.Text;
|
|
5840
|
+
this.Comment = Comment ?? globalThis.Comment;
|
|
5841
|
+
this.cacheConstNodes = true;
|
|
5842
|
+
this.currentTag = null;
|
|
5843
|
+
}
|
|
5844
|
+
isInsideMacro(name) {
|
|
5845
|
+
return this.frame.macroName === name || this.parent?.isInsideMacro(name);
|
|
5846
|
+
}
|
|
5847
|
+
enterMacro(macroName, macroVars, macroSlots) {
|
|
5848
|
+
const { document: document2, Text, Comment, nodes, events, macroNodes } = this;
|
|
5849
|
+
const frame = { macroName, macroVars, macroSlots };
|
|
5850
|
+
return new ParseContext(document2, Text, Comment, nodes, events, macroNodes, frame, this);
|
|
5851
|
+
}
|
|
5852
|
+
parseHTML(html) {
|
|
5853
|
+
const t = this.document.createElement("template");
|
|
5854
|
+
t.innerHTML = html;
|
|
5855
|
+
return t.content.childNodes;
|
|
5856
|
+
}
|
|
5857
|
+
addNodeIf(Class, val, extra) {
|
|
5858
|
+
if (val !== null) {
|
|
5859
|
+
const nodeId = this.nodes.length;
|
|
5860
|
+
const node = new Class(nodeId, val, extra);
|
|
5861
|
+
this.nodes.push(node);
|
|
5862
|
+
return node;
|
|
5863
|
+
}
|
|
5864
|
+
return null;
|
|
5865
|
+
}
|
|
5866
|
+
registerEvents() {
|
|
5867
|
+
const id = this.events.length;
|
|
5868
|
+
const events = new NodeEvents(id);
|
|
5869
|
+
this.events.push(events);
|
|
5870
|
+
return events;
|
|
5871
|
+
}
|
|
5872
|
+
newMacroNode(macroName, mAttrs, childs) {
|
|
5873
|
+
const anySlot = [];
|
|
5874
|
+
const slots = { _: new FragmentNode(anySlot) };
|
|
5875
|
+
for (const child of childs)
|
|
5876
|
+
if (child instanceof SlotNode)
|
|
5877
|
+
slots[child.val.val] = child.node;
|
|
5878
|
+
else if (!(child instanceof TextNode) || !child.isWhiteSpace())
|
|
5879
|
+
anySlot.push(child);
|
|
5880
|
+
const node = new MacroNode(macroName, mAttrs, slots, this);
|
|
5881
|
+
this.macroNodes.push(node);
|
|
5882
|
+
return node;
|
|
5883
|
+
}
|
|
5884
|
+
compile(scope) {
|
|
5885
|
+
for (let i = 0;i < this.macroNodes.length; i++)
|
|
5886
|
+
this.macroNodes[i].compile(scope);
|
|
5887
|
+
}
|
|
5888
|
+
*genEventNames() {
|
|
5889
|
+
for (const event of this.events)
|
|
5890
|
+
yield* event.genEventNames();
|
|
5891
|
+
}
|
|
5892
|
+
getEventForId(id) {
|
|
5893
|
+
return this.events[id] ?? null;
|
|
5894
|
+
}
|
|
5895
|
+
getNodeForId(id) {
|
|
5896
|
+
return this.nodes[id] ?? null;
|
|
5897
|
+
}
|
|
5898
|
+
onAttributes(_attrs, _wrapperAttrs, _textChild, _isMacroCall, _tag) {}
|
|
5899
|
+
onParseIssue(kind, info) {
|
|
5900
|
+
console.warn(`tutuca parse issue [${kind}]`, info);
|
|
5901
|
+
}
|
|
5902
|
+
}
|
|
5903
|
+
function condenseChildsWhites(childs) {
|
|
5904
|
+
if (childs.length === 0)
|
|
5905
|
+
return childs;
|
|
5906
|
+
let changed = false;
|
|
5907
|
+
if (childs[0].isWhiteSpace?.()) {
|
|
5908
|
+
childs[0].condenseWhiteSpace();
|
|
5909
|
+
changed = true;
|
|
5910
|
+
}
|
|
5911
|
+
const last = childs.length - 1;
|
|
5912
|
+
if (last > 0 && childs[last].isWhiteSpace?.()) {
|
|
5913
|
+
childs[last].condenseWhiteSpace();
|
|
5914
|
+
changed = true;
|
|
5915
|
+
}
|
|
5916
|
+
for (let i = 1;i < last; i++) {
|
|
5917
|
+
const cur = childs[i];
|
|
5918
|
+
if (cur.isWhiteSpace?.() && cur.hasNewLine()) {
|
|
5919
|
+
const bothBlock = isBlockDomNode(childs[i - 1]) && isBlockDomNode(childs[i + 1]);
|
|
5920
|
+
cur.condenseWhiteSpace(bothBlock ? "" : " ");
|
|
5921
|
+
if (bothBlock)
|
|
5922
|
+
changed = true;
|
|
5923
|
+
}
|
|
5924
|
+
}
|
|
5925
|
+
return changed ? childs.filter((c) => !(c instanceof TextNode && c.val === "")) : childs;
|
|
5926
|
+
}
|
|
5927
|
+
|
|
5928
|
+
class NodeEvents {
|
|
5929
|
+
constructor(id) {
|
|
5930
|
+
this.id = id;
|
|
5931
|
+
this.handlers = [];
|
|
5932
|
+
}
|
|
5933
|
+
add(name, handlerCall, modifiers) {
|
|
5934
|
+
this.handlers.push(new NodeEvent(name, handlerCall, modifiers));
|
|
5935
|
+
}
|
|
5936
|
+
*genEventNames() {
|
|
5937
|
+
for (const handler of this.handlers)
|
|
5938
|
+
yield handler.name;
|
|
5939
|
+
}
|
|
5940
|
+
getHandlersFor(eventName) {
|
|
5941
|
+
let r = null;
|
|
5942
|
+
for (const handler of this.handlers)
|
|
5943
|
+
if (handler.handlesEventName(eventName)) {
|
|
5944
|
+
r ??= [];
|
|
5945
|
+
r.push(handler);
|
|
5946
|
+
}
|
|
5947
|
+
return r;
|
|
5948
|
+
}
|
|
5949
|
+
}
|
|
5950
|
+
|
|
5951
|
+
class NodeEvent {
|
|
5952
|
+
constructor(name, handlerCall, modifiers) {
|
|
5953
|
+
this.name = name;
|
|
5954
|
+
this.handlerCall = handlerCall;
|
|
5955
|
+
this.modifierWrapper = compileModifiers(name, modifiers);
|
|
5956
|
+
this.modifiers = modifiers;
|
|
5957
|
+
}
|
|
5958
|
+
handlesEventName(name) {
|
|
5959
|
+
return this.name === name;
|
|
5960
|
+
}
|
|
5961
|
+
getHandlerAndArgs(stack, event) {
|
|
5962
|
+
const r = this.handlerCall.getHandlerAndArgs(stack, event);
|
|
5963
|
+
r[0] = this.modifierWrapper(r[0], event);
|
|
5964
|
+
return r;
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
function compileModifiers(eventName, names) {
|
|
5968
|
+
if (names.length === 0)
|
|
5969
|
+
return identityModifierWrapper;
|
|
5970
|
+
const wrappers = MOD_WRAPPERS_BY_EVENT[eventName] ?? {};
|
|
5971
|
+
let w = (that, f, args, _ctx) => f.apply(that, args);
|
|
5972
|
+
for (const name of names) {
|
|
5973
|
+
const wrapper = wrappers[name];
|
|
5974
|
+
if (wrapper !== undefined)
|
|
5975
|
+
w = wrapper(w);
|
|
5976
|
+
}
|
|
5977
|
+
return (f, ctx) => function(...args) {
|
|
5978
|
+
return w(this, f, args, ctx);
|
|
5979
|
+
};
|
|
5980
|
+
}
|
|
5981
|
+
var TextNode, CommentNode, ChildsNode, DomNode, FragmentNode, maybeFragment = (xs) => xs.length === 1 ? xs[0] : new FragmentNode(xs), VALID_NODE_RE, ANode, MacroNode, RenderViewId, RenderNode, RenderItNode, RenderEachNode, RenderTextNode, RenderOnceNode, WrapperNode, ShowNode, HideNode, PushViewNameNode, SlotNode, ScopeNode, EachNode, filterAlwaysTrue = (_v, _k, _seq) => true, nullLoopWith = (seq) => ({ iterData: { seq } }), X_OP_CONSUMED, X_OP_WRAPPABLE, X_ATTR_WRAPPERS, WRAPPER_NODES, _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", HTML_BLOCK_TAGS, isBlockDomNode = (n) => {
|
|
5982
|
+
const node = n instanceof FragmentNode ? n.childs[0] : n;
|
|
5983
|
+
return node instanceof DomNode && HTML_BLOCK_TAGS.has(node.tagName);
|
|
5984
|
+
}, isMac, fwdIfCtxPred = (pred) => (w) => (that, f, args, ctx) => pred(ctx) ? w(that, f, args, ctx) : that, fwdIfKey = (keyName) => fwdIfCtxPred((ctx) => ctx.e.key === keyName), fwdCtrl, fwdMeta, fwdAlt, metaWraps, MOD_WRAPPERS_BY_EVENT, identityModifierWrapper = (f, _ctx) => f;
|
|
5985
|
+
var init_anode = __esm(() => {
|
|
5986
|
+
init_attribute();
|
|
5987
|
+
init_path();
|
|
5988
|
+
init_value();
|
|
5989
|
+
init_vdom();
|
|
5990
|
+
TextNode = class TextNode extends BaseNode {
|
|
5991
|
+
constructor(val) {
|
|
5992
|
+
super();
|
|
5993
|
+
this.val = val;
|
|
5994
|
+
}
|
|
5995
|
+
render(_stack, _rx) {
|
|
5996
|
+
return this.val;
|
|
5997
|
+
}
|
|
5998
|
+
isWhiteSpace() {
|
|
5999
|
+
for (let i = 0;i < this.val.length; i++) {
|
|
6000
|
+
const c = this.val.charCodeAt(i);
|
|
6001
|
+
if (!(c === 32 || c === 10 || c === 9 || c === 13))
|
|
6002
|
+
return false;
|
|
6003
|
+
}
|
|
6004
|
+
return true;
|
|
6005
|
+
}
|
|
6006
|
+
hasNewLine() {
|
|
6007
|
+
for (let i = 0;i < this.val.length; i++) {
|
|
6008
|
+
const c = this.val.charCodeAt(i);
|
|
6009
|
+
if (c === 10 || c === 13)
|
|
6010
|
+
return true;
|
|
6011
|
+
}
|
|
6012
|
+
return false;
|
|
6013
|
+
}
|
|
6014
|
+
condenseWhiteSpace(replacement = "") {
|
|
6015
|
+
this.val = replacement;
|
|
6016
|
+
}
|
|
6017
|
+
isConstant() {
|
|
6018
|
+
return true;
|
|
6019
|
+
}
|
|
6020
|
+
setDataAttr(_key, _val) {}
|
|
6021
|
+
};
|
|
6022
|
+
CommentNode = class CommentNode extends TextNode {
|
|
6023
|
+
render(_stack, rx) {
|
|
6024
|
+
return rx.renderComment(this.val);
|
|
6025
|
+
}
|
|
6026
|
+
};
|
|
6027
|
+
ChildsNode = class ChildsNode extends BaseNode {
|
|
6028
|
+
constructor(childs) {
|
|
6029
|
+
super();
|
|
6030
|
+
this.childs = childs;
|
|
6031
|
+
}
|
|
6032
|
+
isConstant() {
|
|
6033
|
+
return this.childs.every((v) => v.isConstant());
|
|
6034
|
+
}
|
|
6035
|
+
optimize() {
|
|
6036
|
+
optimizeChilds(this.childs);
|
|
6037
|
+
}
|
|
6038
|
+
};
|
|
6039
|
+
DomNode = class DomNode extends ChildsNode {
|
|
6040
|
+
constructor(tagName, attrs, childs, namespace = null) {
|
|
6041
|
+
super(childs);
|
|
6042
|
+
this.tagName = tagName;
|
|
6043
|
+
this.attrs = attrs;
|
|
6044
|
+
this.namespace = namespace;
|
|
6045
|
+
}
|
|
6046
|
+
render(stack, rx) {
|
|
6047
|
+
const childNodes = new Array(this.childs.length);
|
|
6048
|
+
for (let i = 0;i < childNodes.length; i++)
|
|
6049
|
+
childNodes[i] = this.childs[i]?.render?.(stack, rx) ?? null;
|
|
6050
|
+
return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes, this.namespace);
|
|
6051
|
+
}
|
|
6052
|
+
setDataAttr(key, val) {
|
|
6053
|
+
this.attrs.setDataAttr(key, val);
|
|
6054
|
+
}
|
|
6055
|
+
isConstant() {
|
|
6056
|
+
return this.attrs.isConstant() && super.isConstant();
|
|
6057
|
+
}
|
|
6058
|
+
};
|
|
6059
|
+
FragmentNode = class FragmentNode extends ChildsNode {
|
|
6060
|
+
render(stack, rx) {
|
|
6061
|
+
return rx.renderFragment(this.childs.map((c) => c?.render(stack, rx)));
|
|
6062
|
+
}
|
|
6063
|
+
setDataAttr(key, val) {
|
|
6064
|
+
for (const child of this.childs)
|
|
6065
|
+
child.setDataAttr(key, val);
|
|
6066
|
+
}
|
|
6067
|
+
};
|
|
6068
|
+
VALID_NODE_RE = /^[a-zA-Z][a-zA-Z0-9-]*$/;
|
|
6069
|
+
ANode = class ANode extends BaseNode {
|
|
6070
|
+
constructor(nodeId, val) {
|
|
6071
|
+
super();
|
|
6072
|
+
this.nodeId = nodeId;
|
|
6073
|
+
this.val = val;
|
|
6074
|
+
}
|
|
6075
|
+
toPathStep(ctx) {
|
|
6076
|
+
return ctx.applyKey(this.val?.toPathItem?.() ?? null);
|
|
6077
|
+
}
|
|
6078
|
+
static parse(html, px) {
|
|
6079
|
+
const nodes = px.parseHTML(html);
|
|
6080
|
+
if (nodes.length === 0)
|
|
6081
|
+
return new CommentNode("Empty View in ANode.parse");
|
|
6082
|
+
if (nodes.length === 1)
|
|
6083
|
+
return ANode.fromDOM(nodes[0], px);
|
|
6084
|
+
const childs = [];
|
|
6085
|
+
for (let i = 0;i < nodes.length; i++) {
|
|
6086
|
+
const child = ANode.fromDOM(nodes[i], px);
|
|
6087
|
+
if (child !== null)
|
|
6088
|
+
childs.push(child);
|
|
6089
|
+
}
|
|
6090
|
+
const trimmed = condenseChildsWhites(childs);
|
|
6091
|
+
if (trimmed.length === 0)
|
|
6092
|
+
return new CommentNode("Empty View in ANode.parse");
|
|
6093
|
+
return maybeFragment(trimmed);
|
|
6094
|
+
}
|
|
6095
|
+
static fromDOM(node, px) {
|
|
6096
|
+
if (node instanceof px.Text)
|
|
6097
|
+
return new TextNode(node.textContent);
|
|
6098
|
+
else if (node instanceof px.Comment)
|
|
6099
|
+
return new CommentNode(node.textContent);
|
|
6100
|
+
const { childNodes, attributes: attrs, tagName: tag } = node;
|
|
6101
|
+
const childs = [];
|
|
6102
|
+
for (let i = 0;i < childNodes.length; i++) {
|
|
6103
|
+
const child = ANode.fromDOM(childNodes[i], px);
|
|
6104
|
+
if (child !== null)
|
|
6105
|
+
childs.push(child);
|
|
6106
|
+
}
|
|
6107
|
+
const prevTag = px.currentTag;
|
|
6108
|
+
px.currentTag = tag;
|
|
6109
|
+
try {
|
|
6110
|
+
const isPseudoX = attrs[0]?.name === "@x";
|
|
6111
|
+
if (tag === "X" || isPseudoX)
|
|
6112
|
+
return parseXOp(attrs, childs, isPseudoX ? 1 : 0, px);
|
|
6113
|
+
else if (tag.charCodeAt(1) === 58 && tag.charCodeAt(0) === 88) {
|
|
6114
|
+
const macroName = tag.slice(2).toLowerCase();
|
|
6115
|
+
if (macroName === "slot") {
|
|
6116
|
+
const slotName = attrs.getNamedItem("name")?.value ?? "_";
|
|
6117
|
+
return px.frame.macroSlots[slotName] ?? maybeFragment(childs);
|
|
6118
|
+
}
|
|
6119
|
+
const [nAttrs, wrappers] = Attributes.parse(attrs, px, true);
|
|
6120
|
+
px.onAttributes(nAttrs, wrappers, null, true, tag);
|
|
6121
|
+
return wrap(px.newMacroNode(macroName, nAttrs.toMacroVars(), childs), px, wrappers);
|
|
6122
|
+
} else if (VALID_NODE_RE.test(tag)) {
|
|
6123
|
+
const [nAttrs, wrappers, textChild] = Attributes.parse(attrs, px);
|
|
6124
|
+
px.onAttributes(nAttrs, wrappers, textChild, false, tag);
|
|
6125
|
+
if (textChild)
|
|
6126
|
+
childs.unshift(new RenderTextNode(null, textChild));
|
|
6127
|
+
const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
|
|
6128
|
+
const ns = node.namespaceURI;
|
|
6129
|
+
const namespace = ns && ns !== HTML_NS ? ns : null;
|
|
6130
|
+
return wrap(new DomNode(tag, nAttrs, domChilds, namespace), px, wrappers);
|
|
6131
|
+
}
|
|
6132
|
+
return new CommentNode(`Error: InvalidTagName ${tag}`);
|
|
6133
|
+
} finally {
|
|
6134
|
+
px.currentTag = prevTag;
|
|
6135
|
+
}
|
|
6136
|
+
}
|
|
6137
|
+
};
|
|
6138
|
+
MacroNode = class MacroNode extends BaseNode {
|
|
6139
|
+
constructor(name, attrs, slots, px) {
|
|
6140
|
+
super();
|
|
6141
|
+
this.name = name;
|
|
6142
|
+
this.attrs = attrs;
|
|
6143
|
+
this.slots = slots;
|
|
6144
|
+
this.px = px;
|
|
6145
|
+
this.node = null;
|
|
6146
|
+
this.dataAttrs = {};
|
|
6147
|
+
}
|
|
6148
|
+
compile(scope) {
|
|
6149
|
+
const { name, attrs, slots } = this;
|
|
6150
|
+
if (this.px.isInsideMacro(name))
|
|
6151
|
+
throw new Error(`Recursive macro expansion: ${name}`);
|
|
6152
|
+
const macro = scope.lookupMacro(name);
|
|
6153
|
+
if (macro === null)
|
|
6154
|
+
this.node = new CommentNode(`bad macro: ${name}`);
|
|
6155
|
+
else {
|
|
6156
|
+
const vars = { ...macro.defaults, ...attrs };
|
|
6157
|
+
this.node = macro.expand(this.px.enterMacro(name, vars, slots));
|
|
6158
|
+
for (const key in this.dataAttrs)
|
|
6159
|
+
this.node.setDataAttr(key, this.dataAttrs[key]);
|
|
6160
|
+
}
|
|
6161
|
+
}
|
|
6162
|
+
render(stack, rx) {
|
|
6163
|
+
return this.node.render(stack, rx);
|
|
6164
|
+
}
|
|
6165
|
+
setDataAttr(key, val) {
|
|
6166
|
+
this.dataAttrs[key] = val;
|
|
6167
|
+
}
|
|
6168
|
+
isConstant() {
|
|
6169
|
+
return this.node.isConstant();
|
|
6170
|
+
}
|
|
6171
|
+
optimize() {
|
|
6172
|
+
this.node = optimizeNode(this.node);
|
|
6173
|
+
}
|
|
6174
|
+
};
|
|
6175
|
+
RenderViewId = class RenderViewId extends ANode {
|
|
6176
|
+
constructor(nodeId, val, viewId) {
|
|
6177
|
+
super(nodeId, val);
|
|
6178
|
+
this.viewId = viewId;
|
|
6179
|
+
}
|
|
6180
|
+
};
|
|
6181
|
+
RenderNode = class RenderNode extends RenderViewId {
|
|
6182
|
+
render(stack, rx) {
|
|
6183
|
+
const newStack = stack.enter(this.val.eval(stack), {}, true);
|
|
6184
|
+
return rx.renderIt(newStack, this, "", this.viewId);
|
|
6185
|
+
}
|
|
6186
|
+
toPathStep(ctx) {
|
|
6187
|
+
if (this.val instanceof DynVal) {
|
|
6188
|
+
const p = resolveDynProducer(ctx.comp, this.val.name);
|
|
6189
|
+
return p ? new DynStep(p.producerCompId, p.producerSteps) : null;
|
|
6190
|
+
}
|
|
6191
|
+
return super.toPathStep(ctx);
|
|
6192
|
+
}
|
|
6193
|
+
};
|
|
6194
|
+
RenderItNode = class RenderItNode extends RenderViewId {
|
|
6195
|
+
render(stack, rx) {
|
|
6196
|
+
const newStack = stack.enter(stack.it, {}, true);
|
|
6197
|
+
return rx.renderIt(newStack, this, "", this.viewId);
|
|
6198
|
+
}
|
|
6199
|
+
toPathStep(ctx) {
|
|
6200
|
+
const next = ctx.next();
|
|
6201
|
+
if (next === null)
|
|
6202
|
+
return null;
|
|
6203
|
+
const nextNode = next.resolveNode();
|
|
6204
|
+
if (nextNode instanceof EachNode && next.hasKey) {
|
|
6205
|
+
if (nextNode.val instanceof DynVal) {
|
|
6206
|
+
const p = resolveDynProducer(ctx.comp, nextNode.val.name);
|
|
6207
|
+
return p ? new DynEachStep(p.producerCompId, p.producerSteps, next.key) : null;
|
|
6208
|
+
}
|
|
6209
|
+
return new EachRenderItStep(nextNode.val.name, next.key);
|
|
6210
|
+
}
|
|
6211
|
+
return null;
|
|
6212
|
+
}
|
|
6213
|
+
};
|
|
6214
|
+
RenderEachNode = class RenderEachNode extends RenderViewId {
|
|
6215
|
+
constructor(nodeId, val, viewId) {
|
|
6216
|
+
super(nodeId, val, viewId);
|
|
6217
|
+
this.iterInfo = new IterInfo(val, null, null, null);
|
|
6218
|
+
}
|
|
6219
|
+
render(stack, rx) {
|
|
6220
|
+
return rx.renderEach(stack, this.iterInfo, this, this.viewId);
|
|
6221
|
+
}
|
|
6222
|
+
toPathStep(ctx) {
|
|
6223
|
+
if (this.val instanceof DynVal) {
|
|
6224
|
+
if (!ctx.hasKey)
|
|
6225
|
+
return null;
|
|
6226
|
+
const p = resolveDynProducer(ctx.comp, this.val.name);
|
|
6227
|
+
return p ? new DynEachStep(p.producerCompId, p.producerSteps, ctx.key) : null;
|
|
6228
|
+
}
|
|
6229
|
+
return super.toPathStep(ctx);
|
|
6230
|
+
}
|
|
6231
|
+
static parse(px, vp2, s, as, attrs) {
|
|
6232
|
+
const node = px.addNodeIf(RenderEachNode, parseXOpVal("render-each", s, px, vp2.parseSequence), as);
|
|
6233
|
+
if (node !== null) {
|
|
6234
|
+
const attrParser = getAttrParser(px);
|
|
6235
|
+
attrParser.eachAttr = attrParser.pushWrapper("each", s, node.val);
|
|
6236
|
+
const when = attrs.getNamedItem("when");
|
|
6237
|
+
if (when)
|
|
6238
|
+
attrParser._parseWhen(when.value);
|
|
6239
|
+
const lWith = attrs.getNamedItem("loop-with");
|
|
6240
|
+
if (lWith)
|
|
6241
|
+
attrParser._parseLoopWith(lWith.value);
|
|
6242
|
+
node.iterInfo.whenVal = attrParser.eachAttr.whenVal ?? null;
|
|
6243
|
+
node.iterInfo.loopWithVal = attrParser.eachAttr.loopWithVal ?? null;
|
|
6244
|
+
}
|
|
6245
|
+
return node;
|
|
6246
|
+
}
|
|
6247
|
+
};
|
|
6248
|
+
RenderTextNode = class RenderTextNode extends ANode {
|
|
6249
|
+
render(stack, _rx) {
|
|
6250
|
+
return this.val.eval(stack);
|
|
6251
|
+
}
|
|
6252
|
+
};
|
|
6253
|
+
RenderOnceNode = class RenderOnceNode extends BaseNode {
|
|
6254
|
+
constructor(node) {
|
|
6255
|
+
super();
|
|
6256
|
+
this.node = node;
|
|
6257
|
+
this._render = (stack, rx) => {
|
|
6258
|
+
const dom = node.render(stack, rx);
|
|
6259
|
+
this._render = (_stack, _rx) => dom;
|
|
6260
|
+
return dom;
|
|
6261
|
+
};
|
|
6262
|
+
}
|
|
6263
|
+
render(stack, rx) {
|
|
5935
6264
|
return this._render(stack, rx);
|
|
5936
6265
|
}
|
|
5937
6266
|
};
|
|
@@ -13107,691 +13436,370 @@ class Stack2 {
|
|
|
13107
13436
|
return this.comps.getCompFor(this.it).scope.lookupComponent(name);
|
|
13108
13437
|
}
|
|
13109
13438
|
lookupFieldRaw(name) {
|
|
13110
|
-
return this.it[name] ?? null;
|
|
13111
|
-
}
|
|
13112
|
-
lookupMethod(name) {
|
|
13113
|
-
const fn = this.it[name];
|
|
13114
|
-
return fn instanceof Function ? fn.call(this.it) : null;
|
|
13115
|
-
}
|
|
13116
|
-
lookupName(name) {
|
|
13117
|
-
return this.ctx.lookupName(name);
|
|
13118
|
-
}
|
|
13119
|
-
getHandlerFor(name, key) {
|
|
13120
|
-
return this.comps.getHandlerFor(this.it, name, key);
|
|
13121
|
-
}
|
|
13122
|
-
lookupRequest(name) {
|
|
13123
|
-
return this.comps.getRequestFor(this.it, name);
|
|
13124
|
-
}
|
|
13125
|
-
lookupBestView(views, defaultViewName) {
|
|
13126
|
-
let n = this.views;
|
|
13127
|
-
while (n !== null) {
|
|
13128
|
-
const view = views[n[0]];
|
|
13129
|
-
if (view !== undefined)
|
|
13130
|
-
return view;
|
|
13131
|
-
n = n[1];
|
|
13132
|
-
}
|
|
13133
|
-
return views[defaultViewName];
|
|
13134
|
-
}
|
|
13135
|
-
}
|
|
13136
|
-
var STOP, NEXT;
|
|
13137
|
-
var init_stack = __esm(() => {
|
|
13138
|
-
STOP = Symbol("STOP");
|
|
13139
|
-
NEXT = Symbol("NEXT");
|
|
13140
|
-
});
|
|
13141
|
-
|
|
13142
|
-
// src/transactor.js
|
|
13143
|
-
class State2 {
|
|
13144
|
-
constructor(val) {
|
|
13145
|
-
this.val = val;
|
|
13146
|
-
this.changeSubs = [];
|
|
13147
|
-
}
|
|
13148
|
-
onChange(cb) {
|
|
13149
|
-
this.changeSubs.push(cb);
|
|
13150
|
-
}
|
|
13151
|
-
set(val, info) {
|
|
13152
|
-
const old = this.val;
|
|
13153
|
-
this.val = val;
|
|
13154
|
-
for (const sub of this.changeSubs)
|
|
13155
|
-
sub({ val, old, info, timestamp: Date.now() });
|
|
13156
|
-
}
|
|
13157
|
-
update(fn, info) {
|
|
13158
|
-
return this.set(fn(this.val), info);
|
|
13159
|
-
}
|
|
13160
|
-
}
|
|
13161
|
-
|
|
13162
|
-
class Transactor {
|
|
13163
|
-
constructor(comps, rootValue) {
|
|
13164
|
-
this.comps = comps;
|
|
13165
|
-
this.transactions = [];
|
|
13166
|
-
this.state = new State2(rootValue);
|
|
13167
|
-
this.onTransactionPushed = () => {};
|
|
13168
|
-
}
|
|
13169
|
-
pushTransaction(t) {
|
|
13170
|
-
this.transactions.push(t);
|
|
13171
|
-
this.onTransactionPushed(t);
|
|
13172
|
-
}
|
|
13173
|
-
pushSend(path, name, args = [], opts = {}, parent = null) {
|
|
13174
|
-
this.pushTransaction(new SendEvent(path, this, name, args, parent, opts));
|
|
13175
|
-
}
|
|
13176
|
-
pushBubble(path, name, args = [], opts = {}, parent = null, targetPath = null) {
|
|
13177
|
-
const newOpts = opts.skipSelf ? { ...opts, skipSelf: false } : opts;
|
|
13178
|
-
this.pushTransaction(new BubbleEvent(path, this, name, args, parent, newOpts, targetPath));
|
|
13179
|
-
}
|
|
13180
|
-
async pushRequest(path, name, args = [], opts = {}, parent = null) {
|
|
13181
|
-
const curRoot = this.state.val;
|
|
13182
|
-
const curLeaf = path.toTransactionPath().lookup(curRoot);
|
|
13183
|
-
const handler = this.comps.getRequestFor(curLeaf, name) ?? mkReq404(name);
|
|
13184
|
-
const resHandlerName = opts?.onResName ?? name;
|
|
13185
|
-
const push = (specificName, baseName, singleArg, result, error) => {
|
|
13186
|
-
const resArgs = specificName ? [singleArg] : [result, error];
|
|
13187
|
-
const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent);
|
|
13188
|
-
this.pushTransaction(t);
|
|
13189
|
-
};
|
|
13190
|
-
try {
|
|
13191
|
-
const result = await handler.fn.apply(null, args);
|
|
13192
|
-
push(opts?.onOkName, resHandlerName, result, result, null);
|
|
13193
|
-
} catch (error) {
|
|
13194
|
-
push(opts?.onErrorName, resHandlerName, error, null, error);
|
|
13195
|
-
}
|
|
13196
|
-
}
|
|
13197
|
-
get hasPendingTransactions() {
|
|
13198
|
-
return this.transactions.length > 0;
|
|
13199
|
-
}
|
|
13200
|
-
transactNext() {
|
|
13201
|
-
if (this.hasPendingTransactions)
|
|
13202
|
-
this.transact(this.transactions.shift());
|
|
13203
|
-
}
|
|
13204
|
-
transact(transaction) {
|
|
13205
|
-
const curState = this.state.val;
|
|
13206
|
-
const newState = transaction.run(curState, this.comps);
|
|
13207
|
-
if (newState !== undefined) {
|
|
13208
|
-
this.state.set(newState, { transaction });
|
|
13209
|
-
transaction.afterTransaction();
|
|
13210
|
-
} else
|
|
13211
|
-
console.warn("undefined new state", { curState, transaction });
|
|
13212
|
-
}
|
|
13213
|
-
transactInputNow(path, event, eventHandler, dragInfo) {
|
|
13214
|
-
this.transact(new InputEvent(path, event, eventHandler, this, dragInfo));
|
|
13215
|
-
}
|
|
13216
|
-
}
|
|
13217
|
-
function mkReq404(name) {
|
|
13218
|
-
const fn = () => {
|
|
13219
|
-
throw new Error(`Request not found: ${name}`);
|
|
13220
|
-
};
|
|
13221
|
-
return { fn };
|
|
13222
|
-
}
|
|
13223
|
-
function nullHandler() {
|
|
13224
|
-
return this;
|
|
13225
|
-
}
|
|
13226
|
-
|
|
13227
|
-
class Transaction {
|
|
13228
|
-
constructor(path, transactor, parentTransaction = null) {
|
|
13229
|
-
this.path = path;
|
|
13230
|
-
this.transactor = transactor;
|
|
13231
|
-
this.parentTransaction = parentTransaction;
|
|
13232
|
-
this._task = null;
|
|
13233
|
-
}
|
|
13234
|
-
get task() {
|
|
13235
|
-
this._task ??= new Task;
|
|
13236
|
-
return this._task;
|
|
13237
|
-
}
|
|
13238
|
-
getCompletionPromise() {
|
|
13239
|
-
return this.task.promise;
|
|
13240
|
-
}
|
|
13241
|
-
setParent(parentTransaction) {
|
|
13242
|
-
this.parentTransaction = parentTransaction;
|
|
13243
|
-
parentTransaction.task.addDep(this.task);
|
|
13244
|
-
}
|
|
13245
|
-
run(rootValue, comps) {
|
|
13246
|
-
return this.updateRootValue(rootValue, comps);
|
|
13247
|
-
}
|
|
13248
|
-
afterTransaction() {}
|
|
13249
|
-
buildRootStack(root, comps) {
|
|
13250
|
-
return Stack2.root(comps, root);
|
|
13251
|
-
}
|
|
13252
|
-
buildStack(root, comps) {
|
|
13253
|
-
return this.path.toTransactionPath().buildStack(this.buildRootStack(root, comps));
|
|
13254
|
-
}
|
|
13255
|
-
callHandler(root, instance, comps) {
|
|
13256
|
-
const [handler, args] = this.getHandlerAndArgs(root, instance, comps);
|
|
13257
|
-
return handler.apply(instance, args);
|
|
13258
|
-
}
|
|
13259
|
-
getHandlerAndArgs(_root, _instance, _comps) {
|
|
13260
|
-
return null;
|
|
13261
|
-
}
|
|
13262
|
-
updateRootValue(curRoot, comps) {
|
|
13263
|
-
const txnPath = this.path.toTransactionPath();
|
|
13264
|
-
const curLeaf = txnPath.lookup(curRoot);
|
|
13265
|
-
const newLeaf = this.callHandler(curRoot, curLeaf, comps);
|
|
13266
|
-
this._task?.complete?.({ value: newLeaf, old: curLeaf });
|
|
13267
|
-
return curLeaf !== newLeaf ? txnPath.setValue(curRoot, newLeaf) : curRoot;
|
|
13439
|
+
return this.it[name] ?? null;
|
|
13268
13440
|
}
|
|
13269
|
-
|
|
13270
|
-
|
|
13441
|
+
lookupMethod(name) {
|
|
13442
|
+
const fn = this.it[name];
|
|
13443
|
+
return fn instanceof Function ? fn.call(this.it) : null;
|
|
13271
13444
|
}
|
|
13272
|
-
|
|
13273
|
-
|
|
13274
|
-
return e.target.type === "checkbox" ? e.target.checked : (e instanceof CustomEvent ? e.detail : e.target.value) ?? null;
|
|
13275
|
-
}
|
|
13276
|
-
|
|
13277
|
-
class Task {
|
|
13278
|
-
constructor() {
|
|
13279
|
-
this.deps = [];
|
|
13280
|
-
this.val = this.resolve = this.reject = null;
|
|
13281
|
-
this.promise = new Promise((res, rej) => {
|
|
13282
|
-
this.resolve = res;
|
|
13283
|
-
this.reject = rej;
|
|
13284
|
-
});
|
|
13285
|
-
this.isCompleted = false;
|
|
13445
|
+
lookupName(name) {
|
|
13446
|
+
return this.ctx.lookupName(name);
|
|
13286
13447
|
}
|
|
13287
|
-
|
|
13288
|
-
|
|
13289
|
-
this.deps.push(task);
|
|
13290
|
-
task.promise.then((_) => this._check());
|
|
13448
|
+
getHandlerFor(name, key) {
|
|
13449
|
+
return this.comps.getHandlerFor(this.it, name, key);
|
|
13291
13450
|
}
|
|
13292
|
-
|
|
13293
|
-
this.
|
|
13294
|
-
this._check();
|
|
13451
|
+
lookupRequest(name) {
|
|
13452
|
+
return this.comps.getRequestFor(this.it, name);
|
|
13295
13453
|
}
|
|
13296
|
-
|
|
13297
|
-
|
|
13298
|
-
|
|
13299
|
-
|
|
13454
|
+
lookupBestView(views, defaultViewName) {
|
|
13455
|
+
let n = this.views;
|
|
13456
|
+
while (n !== null) {
|
|
13457
|
+
const view = views[n[0]];
|
|
13458
|
+
if (view !== undefined)
|
|
13459
|
+
return view;
|
|
13460
|
+
n = n[1];
|
|
13300
13461
|
}
|
|
13462
|
+
return views[defaultViewName];
|
|
13301
13463
|
}
|
|
13302
13464
|
}
|
|
13465
|
+
var STOP, NEXT;
|
|
13466
|
+
var init_stack = __esm(() => {
|
|
13467
|
+
STOP = Symbol("STOP");
|
|
13468
|
+
NEXT = Symbol("NEXT");
|
|
13469
|
+
});
|
|
13303
13470
|
|
|
13304
|
-
|
|
13305
|
-
|
|
13306
|
-
|
|
13307
|
-
this.
|
|
13308
|
-
this.
|
|
13471
|
+
// src/transactor.js
|
|
13472
|
+
class State2 {
|
|
13473
|
+
constructor(val) {
|
|
13474
|
+
this.val = val;
|
|
13475
|
+
this.changeSubs = [];
|
|
13309
13476
|
}
|
|
13310
|
-
|
|
13311
|
-
|
|
13477
|
+
onChange(cb) {
|
|
13478
|
+
this.changeSubs.push(cb);
|
|
13312
13479
|
}
|
|
13313
|
-
|
|
13314
|
-
|
|
13480
|
+
set(val, info) {
|
|
13481
|
+
const old = this.val;
|
|
13482
|
+
this.val = val;
|
|
13483
|
+
for (const sub of this.changeSubs)
|
|
13484
|
+
sub({ val, old, info, timestamp: Date.now() });
|
|
13315
13485
|
}
|
|
13316
|
-
|
|
13317
|
-
return this.
|
|
13486
|
+
update(fn, info) {
|
|
13487
|
+
return this.set(fn(this.val), info);
|
|
13318
13488
|
}
|
|
13319
|
-
|
|
13320
|
-
|
|
13489
|
+
}
|
|
13490
|
+
|
|
13491
|
+
class Transactor {
|
|
13492
|
+
constructor(comps, rootValue) {
|
|
13493
|
+
this.comps = comps;
|
|
13494
|
+
this.transactions = [];
|
|
13495
|
+
this.state = new State2(rootValue);
|
|
13496
|
+
this.onTransactionPushed = () => {};
|
|
13321
13497
|
}
|
|
13322
|
-
|
|
13323
|
-
|
|
13498
|
+
pushTransaction(t) {
|
|
13499
|
+
this.transactions.push(t);
|
|
13500
|
+
this.onTransactionPushed(t);
|
|
13324
13501
|
}
|
|
13325
|
-
|
|
13326
|
-
|
|
13502
|
+
pushSend(path, name, args = [], opts = {}, parent = null) {
|
|
13503
|
+
this.pushTransaction(new SendEvent(path, this, name, args, parent, opts));
|
|
13327
13504
|
}
|
|
13328
|
-
|
|
13329
|
-
|
|
13505
|
+
pushBubble(path, name, args = [], opts = {}, parent = null, targetPath = null) {
|
|
13506
|
+
const newOpts = opts.skipSelf ? { ...opts, skipSelf: false } : opts;
|
|
13507
|
+
this.pushTransaction(new BubbleEvent(path, this, name, args, parent, newOpts, targetPath));
|
|
13330
13508
|
}
|
|
13331
|
-
}
|
|
13332
|
-
|
|
13333
|
-
|
|
13334
|
-
|
|
13335
|
-
|
|
13336
|
-
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
}
|
|
13345
|
-
|
|
13346
|
-
this._dispatchPath ??= this.path.compact();
|
|
13347
|
-
return this._dispatchPath;
|
|
13348
|
-
}
|
|
13349
|
-
buildRootStack(root, comps) {
|
|
13350
|
-
return Stack2.root(comps, root, this);
|
|
13351
|
-
}
|
|
13352
|
-
getHandlerAndArgs(root, _instance, comps) {
|
|
13353
|
-
const stack = this.buildStack(root, comps);
|
|
13354
|
-
const [handler, args] = this.handler.getHandlerAndArgs(stack, this);
|
|
13355
|
-
const path = this.dispatchPath;
|
|
13356
|
-
let dispatcher;
|
|
13357
|
-
for (let i = 0;i < args.length; i++) {
|
|
13358
|
-
if (args[i]?.toHandlerArg) {
|
|
13359
|
-
dispatcher ??= new Dispatcher(path, this.transactor, this);
|
|
13360
|
-
args[i] = args[i].toHandlerArg(dispatcher);
|
|
13361
|
-
}
|
|
13362
|
-
}
|
|
13363
|
-
args.push(new EventContext(path, this.transactor, this));
|
|
13364
|
-
return [handler, args];
|
|
13365
|
-
}
|
|
13366
|
-
lookupName(name) {
|
|
13367
|
-
const { e } = this;
|
|
13368
|
-
switch (name) {
|
|
13369
|
-
case "value":
|
|
13370
|
-
return getValue(e);
|
|
13371
|
-
case "valueAsInt":
|
|
13372
|
-
return toNullIfNaN(parseInt(getValue(e), 10));
|
|
13373
|
-
case "valueAsFloat":
|
|
13374
|
-
return toNullIfNaN(parseFloat(getValue(e)));
|
|
13375
|
-
case "target":
|
|
13376
|
-
return e.target;
|
|
13377
|
-
case "event":
|
|
13378
|
-
return e;
|
|
13379
|
-
case "isAlt":
|
|
13380
|
-
return e.altKey;
|
|
13381
|
-
case "isShift":
|
|
13382
|
-
return e.shiftKey;
|
|
13383
|
-
case "isCtrl":
|
|
13384
|
-
case "isCmd":
|
|
13385
|
-
return isMac2 && e.metaKey || e.ctrlKey;
|
|
13386
|
-
case "key":
|
|
13387
|
-
return e.key;
|
|
13388
|
-
case "keyCode":
|
|
13389
|
-
return e.keyCode;
|
|
13390
|
-
case "isUpKey":
|
|
13391
|
-
return e.key === "ArrowUp";
|
|
13392
|
-
case "isDownKey":
|
|
13393
|
-
return e.key === "ArrowDown";
|
|
13394
|
-
case "isSend":
|
|
13395
|
-
return e.key === "Enter";
|
|
13396
|
-
case "isCancel":
|
|
13397
|
-
return e.key === "Escape";
|
|
13398
|
-
case "isTabKey":
|
|
13399
|
-
return e.key === "Tab";
|
|
13400
|
-
case "ctx":
|
|
13401
|
-
return new EventContext(this.dispatchPath, this.transactor, this);
|
|
13402
|
-
case "dragInfo":
|
|
13403
|
-
return this.dragInfo;
|
|
13404
|
-
}
|
|
13405
|
-
return null;
|
|
13406
|
-
}
|
|
13407
|
-
};
|
|
13408
|
-
NameArgsTransaction = class NameArgsTransaction extends Transaction {
|
|
13409
|
-
constructor(path, transactor, name, args, parentTransaction, opts = {}) {
|
|
13410
|
-
super(path, transactor, parentTransaction);
|
|
13411
|
-
this.name = name;
|
|
13412
|
-
this.args = args;
|
|
13413
|
-
this.opts = opts;
|
|
13414
|
-
this.targetPath = path;
|
|
13415
|
-
}
|
|
13416
|
-
handlerProp = null;
|
|
13417
|
-
getHandlerForName(comp) {
|
|
13418
|
-
const handlers = comp?.[this.handlerProp];
|
|
13419
|
-
return handlers?.[this.name] ?? handlers?.$unknown ?? nullHandler;
|
|
13420
|
-
}
|
|
13421
|
-
getHandlerAndArgs(_root, instance, comps) {
|
|
13422
|
-
const handler = this.getHandlerForName(comps.getCompFor(instance));
|
|
13423
|
-
return [handler, [...this.args, new EventContext(this.path, this.transactor, this)]];
|
|
13424
|
-
}
|
|
13425
|
-
};
|
|
13426
|
-
ResponseEvent = class ResponseEvent extends NameArgsTransaction {
|
|
13427
|
-
handlerProp = "response";
|
|
13428
|
-
};
|
|
13429
|
-
SendEvent = class SendEvent extends NameArgsTransaction {
|
|
13430
|
-
handlerProp = "receive";
|
|
13431
|
-
run(rootVal, comps) {
|
|
13432
|
-
return this.opts.skipSelf ? rootVal : this.updateRootValue(rootVal, comps);
|
|
13433
|
-
}
|
|
13434
|
-
afterTransaction() {
|
|
13435
|
-
const { path, name, args, opts, targetPath } = this;
|
|
13436
|
-
if (opts.bubbles && path.steps.length > 0)
|
|
13437
|
-
this.transactor.pushBubble(path.popStep(), name, args, opts, this, targetPath);
|
|
13438
|
-
}
|
|
13439
|
-
};
|
|
13440
|
-
BubbleEvent = class BubbleEvent extends SendEvent {
|
|
13441
|
-
handlerProp = "bubble";
|
|
13442
|
-
constructor(path, transactor, name, args, parent, opts, targetPath) {
|
|
13443
|
-
super(path, transactor, name, args, parent, opts);
|
|
13444
|
-
this.targetPath = targetPath ?? path;
|
|
13445
|
-
}
|
|
13446
|
-
stopPropagation() {
|
|
13447
|
-
this.opts.bubbles = false;
|
|
13448
|
-
}
|
|
13449
|
-
};
|
|
13450
|
-
EventContext = class EventContext extends Dispatcher {
|
|
13451
|
-
get name() {
|
|
13452
|
-
return this.parent?.name ?? null;
|
|
13453
|
-
}
|
|
13454
|
-
get targetPath() {
|
|
13455
|
-
return this.parent.targetPath;
|
|
13456
|
-
}
|
|
13457
|
-
stopPropagation() {
|
|
13458
|
-
return this.parent.stopPropagation();
|
|
13459
|
-
}
|
|
13460
|
-
};
|
|
13461
|
-
PathChanges = class PathChanges extends PathBuilder {
|
|
13462
|
-
constructor(dispatcher) {
|
|
13463
|
-
super();
|
|
13464
|
-
this.dispatcher = dispatcher;
|
|
13465
|
-
}
|
|
13466
|
-
send(name, args, opts) {
|
|
13467
|
-
return this.dispatcher.sendAtPath(this.buildPath(), name, args, opts);
|
|
13468
|
-
}
|
|
13469
|
-
bubble(name, args, opts) {
|
|
13470
|
-
return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
|
|
13471
|
-
}
|
|
13472
|
-
buildPath() {
|
|
13473
|
-
return this.dispatcher.path.concat(this.pathChanges);
|
|
13509
|
+
async pushRequest(path, name, args = [], opts = {}, parent = null) {
|
|
13510
|
+
const curRoot = this.state.val;
|
|
13511
|
+
const curLeaf = path.toTransactionPath().lookup(curRoot);
|
|
13512
|
+
const handler = this.comps.getRequestFor(curLeaf, name) ?? mkReq404(name);
|
|
13513
|
+
const resHandlerName = opts?.onResName ?? name;
|
|
13514
|
+
const push = (specificName, baseName, singleArg, result, error) => {
|
|
13515
|
+
const resArgs = specificName ? [singleArg] : [result, error];
|
|
13516
|
+
const t = new ResponseEvent(path, this, specificName ?? baseName, resArgs, parent);
|
|
13517
|
+
this.pushTransaction(t);
|
|
13518
|
+
};
|
|
13519
|
+
try {
|
|
13520
|
+
const result = await handler.fn.apply(null, args);
|
|
13521
|
+
push(opts?.onOkName, resHandlerName, result, result, null);
|
|
13522
|
+
} catch (error) {
|
|
13523
|
+
push(opts?.onErrorName, resHandlerName, error, null, error);
|
|
13474
13524
|
}
|
|
13475
|
-
}
|
|
13476
|
-
|
|
13477
|
-
|
|
13478
|
-
|
|
13479
|
-
|
|
13480
|
-
|
|
13481
|
-
|
|
13482
|
-
|
|
13483
|
-
|
|
13484
|
-
|
|
13485
|
-
|
|
13486
|
-
|
|
13487
|
-
|
|
13488
|
-
|
|
13489
|
-
|
|
13490
|
-
|
|
13491
|
-
|
|
13525
|
+
}
|
|
13526
|
+
get hasPendingTransactions() {
|
|
13527
|
+
return this.transactions.length > 0;
|
|
13528
|
+
}
|
|
13529
|
+
transactNext() {
|
|
13530
|
+
if (this.hasPendingTransactions)
|
|
13531
|
+
this.transact(this.transactions.shift());
|
|
13532
|
+
}
|
|
13533
|
+
transact(transaction) {
|
|
13534
|
+
const curState = this.state.val;
|
|
13535
|
+
const newState = transaction.run(curState, this.comps);
|
|
13536
|
+
if (newState !== undefined) {
|
|
13537
|
+
this.state.set(newState, { transaction });
|
|
13538
|
+
transaction.afterTransaction();
|
|
13539
|
+
} else
|
|
13540
|
+
console.warn("undefined new state", { curState, transaction });
|
|
13541
|
+
}
|
|
13542
|
+
transactInputNow(path, event, eventHandler, dragInfo) {
|
|
13543
|
+
this.transact(new InputEvent(path, event, eventHandler, this, dragInfo));
|
|
13492
13544
|
}
|
|
13493
13545
|
}
|
|
13494
|
-
function
|
|
13495
|
-
const
|
|
13496
|
-
|
|
13497
|
-
|
|
13498
|
-
|
|
13499
|
-
node.removeAttribute("class");
|
|
13500
|
-
else if (propName === "htmlFor")
|
|
13501
|
-
node.removeAttribute("for");
|
|
13502
|
-
else if (typeof previousValue === "string" || isHtmlAttribute(propName))
|
|
13503
|
-
node.removeAttribute(propName);
|
|
13504
|
-
else
|
|
13505
|
-
node[propName] = null;
|
|
13506
|
-
}
|
|
13507
|
-
|
|
13508
|
-
class VBase {
|
|
13509
|
-
}
|
|
13510
|
-
function childsEqual(a, b) {
|
|
13511
|
-
if (a === b)
|
|
13512
|
-
return true;
|
|
13513
|
-
for (let i = 0;i < a.length; i++)
|
|
13514
|
-
if (!a[i].isEqualTo(b[i]))
|
|
13515
|
-
return false;
|
|
13516
|
-
return true;
|
|
13517
|
-
}
|
|
13518
|
-
function appendChildNodes(parent, childs, opts) {
|
|
13519
|
-
for (const child of childs)
|
|
13520
|
-
parent.appendChild(child.toDom(opts));
|
|
13546
|
+
function mkReq404(name) {
|
|
13547
|
+
const fn = () => {
|
|
13548
|
+
throw new Error(`Request not found: ${name}`);
|
|
13549
|
+
};
|
|
13550
|
+
return { fn };
|
|
13521
13551
|
}
|
|
13522
|
-
function
|
|
13523
|
-
|
|
13524
|
-
return;
|
|
13525
|
-
if (isIterable(child)) {
|
|
13526
|
-
for (const c of child)
|
|
13527
|
-
addChild(normalizedChildren, c);
|
|
13528
|
-
} else if (child instanceof VBase) {
|
|
13529
|
-
if (child instanceof VFragment)
|
|
13530
|
-
normalizedChildren.push(...child.childs);
|
|
13531
|
-
else
|
|
13532
|
-
normalizedChildren.push(child);
|
|
13533
|
-
} else
|
|
13534
|
-
normalizedChildren.push(new VText(child));
|
|
13552
|
+
function nullHandler() {
|
|
13553
|
+
return this;
|
|
13535
13554
|
}
|
|
13536
|
-
|
|
13537
|
-
|
|
13555
|
+
|
|
13556
|
+
class Transaction {
|
|
13557
|
+
constructor(path, transactor, parentTransaction = null) {
|
|
13558
|
+
this.path = path;
|
|
13559
|
+
this.transactor = transactor;
|
|
13560
|
+
this.parentTransaction = parentTransaction;
|
|
13561
|
+
this._task = null;
|
|
13562
|
+
}
|
|
13563
|
+
get task() {
|
|
13564
|
+
this._task ??= new Task;
|
|
13565
|
+
return this._task;
|
|
13566
|
+
}
|
|
13567
|
+
getCompletionPromise() {
|
|
13568
|
+
return this.task.promise;
|
|
13569
|
+
}
|
|
13570
|
+
setParent(parentTransaction) {
|
|
13571
|
+
this.parentTransaction = parentTransaction;
|
|
13572
|
+
parentTransaction.task.addDep(this.task);
|
|
13573
|
+
}
|
|
13574
|
+
run(rootValue, comps) {
|
|
13575
|
+
return this.updateRootValue(rootValue, comps);
|
|
13576
|
+
}
|
|
13577
|
+
afterTransaction() {}
|
|
13578
|
+
buildRootStack(root, comps) {
|
|
13579
|
+
return Stack2.root(comps, root);
|
|
13580
|
+
}
|
|
13581
|
+
buildStack(root, comps) {
|
|
13582
|
+
return this.path.toTransactionPath().buildStack(this.buildRootStack(root, comps));
|
|
13583
|
+
}
|
|
13584
|
+
callHandler(root, instance, comps) {
|
|
13585
|
+
const [handler, args] = this.getHandlerAndArgs(root, instance, comps);
|
|
13586
|
+
return handler.apply(instance, args);
|
|
13587
|
+
}
|
|
13588
|
+
getHandlerAndArgs(_root, _instance, _comps) {
|
|
13538
13589
|
return null;
|
|
13539
|
-
let diff = null;
|
|
13540
|
-
for (const aKey in a) {
|
|
13541
|
-
if (!Object.hasOwn(b, aKey)) {
|
|
13542
|
-
diff ??= {};
|
|
13543
|
-
diff[aKey] = undefined;
|
|
13544
|
-
} else if (a[aKey] !== b[aKey]) {
|
|
13545
|
-
diff ??= {};
|
|
13546
|
-
diff[aKey] = b[aKey];
|
|
13547
|
-
}
|
|
13548
13590
|
}
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
}
|
|
13591
|
+
updateRootValue(curRoot, comps) {
|
|
13592
|
+
const txnPath = this.path.toTransactionPath();
|
|
13593
|
+
const curLeaf = txnPath.lookup(curRoot);
|
|
13594
|
+
const newLeaf = this.callHandler(curRoot, curLeaf, comps);
|
|
13595
|
+
this._task?.complete?.({ value: newLeaf, old: curLeaf });
|
|
13596
|
+
return curLeaf !== newLeaf ? txnPath.setValue(curRoot, newLeaf) : curRoot;
|
|
13597
|
+
}
|
|
13598
|
+
lookupName(_name) {
|
|
13599
|
+
return null;
|
|
13554
13600
|
}
|
|
13555
|
-
return diff;
|
|
13556
13601
|
}
|
|
13557
|
-
function
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
return domNode;
|
|
13602
|
+
function getValue(e) {
|
|
13603
|
+
return e.target.type === "checkbox" ? e.target.checked : (e instanceof CustomEvent ? e.detail : e.target.value) ?? null;
|
|
13604
|
+
}
|
|
13605
|
+
|
|
13606
|
+
class Task {
|
|
13607
|
+
constructor() {
|
|
13608
|
+
this.deps = [];
|
|
13609
|
+
this.val = this.resolve = this.reject = null;
|
|
13610
|
+
this.promise = new Promise((res, rej) => {
|
|
13611
|
+
this.resolve = res;
|
|
13612
|
+
this.reject = rej;
|
|
13613
|
+
});
|
|
13614
|
+
this.isCompleted = false;
|
|
13615
|
+
}
|
|
13616
|
+
addDep(task) {
|
|
13617
|
+
console.assert(!this.isCompleted, "addDep for completed task", this, task);
|
|
13618
|
+
this.deps.push(task);
|
|
13619
|
+
task.promise.then((_) => this._check());
|
|
13620
|
+
}
|
|
13621
|
+
complete(val) {
|
|
13622
|
+
this.val = val;
|
|
13623
|
+
this._check();
|
|
13624
|
+
}
|
|
13625
|
+
_check() {
|
|
13626
|
+
if (this.deps.every((task) => task.isCompleted)) {
|
|
13627
|
+
this.isCompleted = true;
|
|
13628
|
+
this.resolve(this);
|
|
13585
13629
|
}
|
|
13586
13630
|
}
|
|
13587
|
-
const newNode = target.toDom(opts);
|
|
13588
|
-
domNode.parentNode?.replaceChild(newNode, domNode);
|
|
13589
|
-
return newNode;
|
|
13590
13631
|
}
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13632
|
+
|
|
13633
|
+
class Dispatcher {
|
|
13634
|
+
constructor(path, transactor, parentTransaction) {
|
|
13635
|
+
this.path = path;
|
|
13636
|
+
this.transactor = transactor;
|
|
13637
|
+
this.parent = parentTransaction;
|
|
13595
13638
|
}
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
return;
|
|
13639
|
+
get at() {
|
|
13640
|
+
return new PathChanges(this);
|
|
13599
13641
|
}
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13642
|
+
send(name, args, opts) {
|
|
13643
|
+
return this.sendAtPath(this.path, name, args, opts);
|
|
13644
|
+
}
|
|
13645
|
+
bubble(name, args, opts) {
|
|
13646
|
+
return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
|
|
13647
|
+
}
|
|
13648
|
+
sendAtPath(path, name, args, opts) {
|
|
13649
|
+
return this.transactor.pushSend(path, name, args, opts, this.parent);
|
|
13650
|
+
}
|
|
13651
|
+
request(name, args, opts) {
|
|
13652
|
+
return this.requestAtPath(this.path, name, args, opts);
|
|
13653
|
+
}
|
|
13654
|
+
requestAtPath(path, name, args, opts) {
|
|
13655
|
+
return this.transactor.pushRequest(path, name, args, opts, this.parent);
|
|
13656
|
+
}
|
|
13657
|
+
lookupTypeFor(name, inst) {
|
|
13658
|
+
return this.transactor.comps.getCompFor(inst).scope.lookupComponent(name);
|
|
13659
|
+
}
|
|
13660
|
+
}
|
|
13661
|
+
var isMac2, toNullIfNaN = (v) => Number.isNaN(v) ? null : v, InputEvent, NameArgsTransaction, ResponseEvent, SendEvent, BubbleEvent, EventContext, PathChanges;
|
|
13662
|
+
var init_transactor = __esm(() => {
|
|
13663
|
+
init_path();
|
|
13664
|
+
init_stack();
|
|
13665
|
+
isMac2 = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
|
|
13666
|
+
InputEvent = class InputEvent extends Transaction {
|
|
13667
|
+
constructor(path, e, handler, transactor, dragInfo) {
|
|
13668
|
+
super(path, transactor);
|
|
13669
|
+
this.e = e;
|
|
13670
|
+
this.handler = handler;
|
|
13671
|
+
this.dragInfo = dragInfo;
|
|
13672
|
+
this._dispatchPath = null;
|
|
13616
13673
|
}
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
oldIdx = oldKeyMap[newKey];
|
|
13634
|
-
} else {
|
|
13635
|
-
while (unkeyedCursor < oldChilds.length) {
|
|
13636
|
-
if (!used2[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
|
|
13637
|
-
oldIdx = unkeyedCursor++;
|
|
13638
|
-
break;
|
|
13674
|
+
get dispatchPath() {
|
|
13675
|
+
this._dispatchPath ??= this.path.compact();
|
|
13676
|
+
return this._dispatchPath;
|
|
13677
|
+
}
|
|
13678
|
+
buildRootStack(root, comps) {
|
|
13679
|
+
return Stack2.root(comps, root, this);
|
|
13680
|
+
}
|
|
13681
|
+
getHandlerAndArgs(root, _instance, comps) {
|
|
13682
|
+
const stack = this.buildStack(root, comps);
|
|
13683
|
+
const [handler, args] = this.handler.getHandlerAndArgs(stack, this);
|
|
13684
|
+
const path = this.dispatchPath;
|
|
13685
|
+
let dispatcher;
|
|
13686
|
+
for (let i = 0;i < args.length; i++) {
|
|
13687
|
+
if (args[i]?.toHandlerArg) {
|
|
13688
|
+
dispatcher ??= new Dispatcher(path, this.transactor, this);
|
|
13689
|
+
args[i] = args[i].toHandlerArg(dispatcher);
|
|
13639
13690
|
}
|
|
13640
|
-
unkeyedCursor++;
|
|
13641
13691
|
}
|
|
13692
|
+
args.push(new EventContext(path, this.transactor, this));
|
|
13693
|
+
return [handler, args];
|
|
13642
13694
|
}
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13655
|
-
|
|
13656
|
-
|
|
13657
|
-
|
|
13658
|
-
|
|
13659
|
-
|
|
13660
|
-
|
|
13661
|
-
|
|
13662
|
-
|
|
13663
|
-
return { vnode, dom: isFragment ? container : newDom };
|
|
13664
|
-
}
|
|
13665
|
-
const domNode = vnode.toDom(options);
|
|
13666
|
-
container.replaceChildren(domNode);
|
|
13667
|
-
return { vnode, dom: isFragment ? container : domNode };
|
|
13668
|
-
}
|
|
13669
|
-
function h(tagName, properties, children) {
|
|
13670
|
-
const c = tagName.charCodeAt(0);
|
|
13671
|
-
const tag = c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
|
|
13672
|
-
const props = {};
|
|
13673
|
-
let key, namespace;
|
|
13674
|
-
if (properties) {
|
|
13675
|
-
for (const propName in properties) {
|
|
13676
|
-
const propVal = properties[propName];
|
|
13677
|
-
switch (propName) {
|
|
13695
|
+
lookupName(name) {
|
|
13696
|
+
const { e } = this;
|
|
13697
|
+
switch (name) {
|
|
13698
|
+
case "value":
|
|
13699
|
+
return getValue(e);
|
|
13700
|
+
case "valueAsInt":
|
|
13701
|
+
return toNullIfNaN(parseInt(getValue(e), 10));
|
|
13702
|
+
case "valueAsFloat":
|
|
13703
|
+
return toNullIfNaN(parseFloat(getValue(e)));
|
|
13704
|
+
case "target":
|
|
13705
|
+
return e.target;
|
|
13706
|
+
case "event":
|
|
13707
|
+
return e;
|
|
13708
|
+
case "isAlt":
|
|
13709
|
+
return e.altKey;
|
|
13710
|
+
case "isShift":
|
|
13711
|
+
return e.shiftKey;
|
|
13712
|
+
case "isCtrl":
|
|
13713
|
+
case "isCmd":
|
|
13714
|
+
return isMac2 && e.metaKey || e.ctrlKey;
|
|
13678
13715
|
case "key":
|
|
13679
|
-
key
|
|
13680
|
-
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13684
|
-
case "
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
|
|
13691
|
-
|
|
13716
|
+
return e.key;
|
|
13717
|
+
case "keyCode":
|
|
13718
|
+
return e.keyCode;
|
|
13719
|
+
case "isUpKey":
|
|
13720
|
+
return e.key === "ArrowUp";
|
|
13721
|
+
case "isDownKey":
|
|
13722
|
+
return e.key === "ArrowDown";
|
|
13723
|
+
case "isSend":
|
|
13724
|
+
return e.key === "Enter";
|
|
13725
|
+
case "isCancel":
|
|
13726
|
+
return e.key === "Escape";
|
|
13727
|
+
case "isTabKey":
|
|
13728
|
+
return e.key === "Tab";
|
|
13729
|
+
case "ctx":
|
|
13730
|
+
return new EventContext(this.dispatchPath, this.transactor, this);
|
|
13731
|
+
case "dragInfo":
|
|
13732
|
+
return this.dragInfo;
|
|
13692
13733
|
}
|
|
13734
|
+
return null;
|
|
13693
13735
|
}
|
|
13694
|
-
}
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13698
|
-
|
|
13699
|
-
|
|
13700
|
-
|
|
13701
|
-
|
|
13702
|
-
constructor(text) {
|
|
13703
|
-
super();
|
|
13704
|
-
this.text = String(text);
|
|
13705
|
-
}
|
|
13706
|
-
get nodeType() {
|
|
13707
|
-
return 3;
|
|
13736
|
+
};
|
|
13737
|
+
NameArgsTransaction = class NameArgsTransaction extends Transaction {
|
|
13738
|
+
constructor(path, transactor, name, args, parentTransaction, opts = {}) {
|
|
13739
|
+
super(path, transactor, parentTransaction);
|
|
13740
|
+
this.name = name;
|
|
13741
|
+
this.args = args;
|
|
13742
|
+
this.opts = opts;
|
|
13743
|
+
this.targetPath = path;
|
|
13708
13744
|
}
|
|
13709
|
-
|
|
13710
|
-
|
|
13745
|
+
handlerProp = null;
|
|
13746
|
+
getHandlerForName(comp) {
|
|
13747
|
+
const handlers = comp?.[this.handlerProp];
|
|
13748
|
+
return handlers?.[this.name] ?? handlers?.$unknown ?? nullHandler;
|
|
13711
13749
|
}
|
|
13712
|
-
|
|
13713
|
-
|
|
13750
|
+
getHandlerAndArgs(_root, instance, comps) {
|
|
13751
|
+
const handler = this.getHandlerForName(comps.getCompFor(instance));
|
|
13752
|
+
return [handler, [...this.args, new EventContext(this.path, this.transactor, this)]];
|
|
13714
13753
|
}
|
|
13715
13754
|
};
|
|
13716
|
-
|
|
13717
|
-
|
|
13718
|
-
|
|
13719
|
-
|
|
13755
|
+
ResponseEvent = class ResponseEvent extends NameArgsTransaction {
|
|
13756
|
+
handlerProp = "response";
|
|
13757
|
+
};
|
|
13758
|
+
SendEvent = class SendEvent extends NameArgsTransaction {
|
|
13759
|
+
handlerProp = "receive";
|
|
13760
|
+
run(rootVal, comps) {
|
|
13761
|
+
return this.opts.skipSelf ? rootVal : this.updateRootValue(rootVal, comps);
|
|
13720
13762
|
}
|
|
13721
|
-
|
|
13722
|
-
|
|
13763
|
+
afterTransaction() {
|
|
13764
|
+
const { path, name, args, opts, targetPath } = this;
|
|
13765
|
+
if (opts.bubbles && path.steps.length > 0)
|
|
13766
|
+
this.transactor.pushBubble(path.popStep(), name, args, opts, this, targetPath);
|
|
13723
13767
|
}
|
|
13724
|
-
|
|
13725
|
-
|
|
13768
|
+
};
|
|
13769
|
+
BubbleEvent = class BubbleEvent extends SendEvent {
|
|
13770
|
+
handlerProp = "bubble";
|
|
13771
|
+
constructor(path, transactor, name, args, parent, opts, targetPath) {
|
|
13772
|
+
super(path, transactor, name, args, parent, opts);
|
|
13773
|
+
this.targetPath = targetPath ?? path;
|
|
13726
13774
|
}
|
|
13727
|
-
|
|
13728
|
-
|
|
13775
|
+
stopPropagation() {
|
|
13776
|
+
this.opts.bubbles = false;
|
|
13729
13777
|
}
|
|
13730
13778
|
};
|
|
13731
|
-
|
|
13732
|
-
|
|
13733
|
-
|
|
13734
|
-
this.childs = [];
|
|
13735
|
-
addChild(this.childs, childs);
|
|
13736
|
-
}
|
|
13737
|
-
get nodeType() {
|
|
13738
|
-
return 11;
|
|
13779
|
+
EventContext = class EventContext extends Dispatcher {
|
|
13780
|
+
get name() {
|
|
13781
|
+
return this.parent?.name ?? null;
|
|
13739
13782
|
}
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
return false;
|
|
13743
|
-
return childsEqual(this.childs, other.childs);
|
|
13783
|
+
get targetPath() {
|
|
13784
|
+
return this.parent.targetPath;
|
|
13744
13785
|
}
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
appendChildNodes(fragment, this.childs, opts);
|
|
13748
|
-
return fragment;
|
|
13786
|
+
stopPropagation() {
|
|
13787
|
+
return this.parent.stopPropagation();
|
|
13749
13788
|
}
|
|
13750
13789
|
};
|
|
13751
|
-
|
|
13752
|
-
constructor(
|
|
13790
|
+
PathChanges = class PathChanges extends PathBuilder {
|
|
13791
|
+
constructor(dispatcher) {
|
|
13753
13792
|
super();
|
|
13754
|
-
this.
|
|
13755
|
-
this.attrs = attrs ?? {};
|
|
13756
|
-
this.childs = childs ?? [];
|
|
13757
|
-
this.key = key != null ? String(key) : undefined;
|
|
13758
|
-
this.namespace = typeof namespace === "string" ? namespace : null;
|
|
13759
|
-
}
|
|
13760
|
-
get nodeType() {
|
|
13761
|
-
return 1;
|
|
13793
|
+
this.dispatcher = dispatcher;
|
|
13762
13794
|
}
|
|
13763
|
-
|
|
13764
|
-
return this.
|
|
13795
|
+
send(name, args, opts) {
|
|
13796
|
+
return this.dispatcher.sendAtPath(this.buildPath(), name, args, opts);
|
|
13765
13797
|
}
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
return true;
|
|
13769
|
-
if (!(other instanceof VNode2) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
|
|
13770
|
-
return false;
|
|
13771
|
-
}
|
|
13772
|
-
if (this.attrs !== other.attrs) {
|
|
13773
|
-
for (const key in this.attrs)
|
|
13774
|
-
if (this.attrs[key] !== other.attrs[key])
|
|
13775
|
-
return false;
|
|
13776
|
-
for (const key in other.attrs)
|
|
13777
|
-
if (!Object.hasOwn(this.attrs, key))
|
|
13778
|
-
return false;
|
|
13779
|
-
}
|
|
13780
|
-
return childsEqual(this.childs, other.childs);
|
|
13798
|
+
bubble(name, args, opts) {
|
|
13799
|
+
return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
|
|
13781
13800
|
}
|
|
13782
|
-
|
|
13783
|
-
|
|
13784
|
-
const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
|
|
13785
|
-
if (this.tag === "SELECT" && "value" in this.attrs) {
|
|
13786
|
-
const { value, ...rest } = this.attrs;
|
|
13787
|
-
applyProperties(node, rest, {});
|
|
13788
|
-
appendChildNodes(node, this.childs, opts);
|
|
13789
|
-
applyProperties(node, { value }, {});
|
|
13790
|
-
} else {
|
|
13791
|
-
applyProperties(node, this.attrs, {});
|
|
13792
|
-
appendChildNodes(node, this.childs, opts);
|
|
13793
|
-
}
|
|
13794
|
-
return node;
|
|
13801
|
+
buildPath() {
|
|
13802
|
+
return this.dispatcher.path.concat(this.pathChanges);
|
|
13795
13803
|
}
|
|
13796
13804
|
};
|
|
13797
13805
|
});
|
|
@@ -14195,20 +14203,20 @@ class Renderer {
|
|
|
14195
14203
|
renderEach(stack, iterInfo, node, viewName) {
|
|
14196
14204
|
const { seq, filter, loopWith } = iterInfo.eval(stack);
|
|
14197
14205
|
const r = [];
|
|
14198
|
-
const iterData = loopWith.call(stack.it, seq);
|
|
14206
|
+
const { iterData, start, end } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
|
|
14199
14207
|
getSeqInfo(seq)(seq, (key, value, attrName) => {
|
|
14200
14208
|
if (filter.call(stack.it, key, value, iterData)) {
|
|
14201
14209
|
const dom = this.renderIt(stack.enter(value, { key }, true), node, key, viewName);
|
|
14202
14210
|
this.pushEachEntry(r, node.nodeId, attrName, key, dom);
|
|
14203
14211
|
}
|
|
14204
|
-
});
|
|
14212
|
+
}, start, end);
|
|
14205
14213
|
return r;
|
|
14206
14214
|
}
|
|
14207
14215
|
renderEachWhen(stack, iterInfo, view, nid) {
|
|
14208
14216
|
const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
|
|
14209
14217
|
const r = [];
|
|
14210
14218
|
const it = stack.it;
|
|
14211
|
-
const iterData = loopWith.call(it, seq);
|
|
14219
|
+
const { iterData, start, end } = unpackLoopResult(loopWith.call(it, seq), seq);
|
|
14212
14220
|
getSeqInfo(seq)(seq, (key, value, attrName) => {
|
|
14213
14221
|
if (filter.call(it, key, value, iterData)) {
|
|
14214
14222
|
const cachePath = enricher ? [view, it, value] : [view, value];
|
|
@@ -14225,7 +14233,7 @@ class Renderer {
|
|
|
14225
14233
|
this.cache.set(cachePath, cacheKey, dom);
|
|
14226
14234
|
}
|
|
14227
14235
|
}
|
|
14228
|
-
});
|
|
14236
|
+
}, start, end);
|
|
14229
14237
|
return r;
|
|
14230
14238
|
}
|
|
14231
14239
|
renderView(view, stack) {
|
|
@@ -14246,13 +14254,29 @@ class Renderer {
|
|
|
14246
14254
|
return new VComment(`§${JSON.stringify(info)}§`);
|
|
14247
14255
|
}
|
|
14248
14256
|
}
|
|
14249
|
-
var DATASET_ATTRS, getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter,
|
|
14257
|
+
var DATASET_ATTRS, getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter, normalizeRange = (start, end, size) => {
|
|
14258
|
+
let s = start == null ? 0 : start < 0 ? size + start : start;
|
|
14259
|
+
let e = end == null ? size : end < 0 ? size + end : end;
|
|
14260
|
+
s = s < 0 ? 0 : s > size ? size : s;
|
|
14261
|
+
e = e < 0 ? 0 : e > size ? size : e;
|
|
14262
|
+
return [s, e < s ? s : e];
|
|
14263
|
+
}, unpackLoopResult = (result, seq) => {
|
|
14264
|
+
const r = result ?? {};
|
|
14265
|
+
return { iterData: r.iterData ?? { seq }, start: r.start, end: r.end };
|
|
14266
|
+
}, imIndexedIter = (seq, visit, start, end) => {
|
|
14267
|
+
const [s, e] = normalizeRange(start, end, seq.size);
|
|
14268
|
+
for (let i = s;i < e; i++)
|
|
14269
|
+
visit(i, seq.get(i), "si");
|
|
14270
|
+
}, imKeyedIter = (seq, visit, start, end) => {
|
|
14271
|
+
const [s, e] = normalizeRange(start, end, seq.size);
|
|
14250
14272
|
let i = 0;
|
|
14251
|
-
for (const v of seq)
|
|
14252
|
-
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
-
|
|
14273
|
+
for (const [k, v] of seq.toSeq().entries()) {
|
|
14274
|
+
if (i >= e)
|
|
14275
|
+
break;
|
|
14276
|
+
if (i >= s)
|
|
14277
|
+
visit(k, v, "sk");
|
|
14278
|
+
i++;
|
|
14279
|
+
}
|
|
14256
14280
|
}, unkIter = () => {}, SEQ_INFO;
|
|
14257
14281
|
var init_renderer = __esm(() => {
|
|
14258
14282
|
init_immutable();
|