marko 6.0.0-next.3.35 → 6.0.0-next.3.37
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/common/types.d.ts +1 -0
- package/dist/debug/dom.js +41 -35
- package/dist/debug/dom.mjs +41 -35
- package/dist/debug/html.js +8 -8
- package/dist/debug/html.mjs +8 -8
- package/dist/dom/compat.d.ts +1 -1
- package/dist/dom/renderer.d.ts +3 -4
- package/dist/dom/template.d.ts +1 -1
- package/dist/dom.d.ts +0 -2
- package/dist/dom.js +28 -24
- package/dist/dom.mjs +28 -24
- package/dist/html/writer.d.ts +4 -4
- package/dist/html.js +8 -8
- package/dist/html.mjs +8 -8
- package/dist/translator/index.js +122 -56
- package/dist/translator/util/signals.d.ts +1 -0
- package/package.json +1 -1
package/dist/common/types.d.ts
CHANGED
package/dist/debug/dom.js
CHANGED
@@ -44,7 +44,6 @@ __export(dom_exports, {
|
|
44
44
|
controllable_textarea_value_effect: () => controllable_input_value_effect,
|
45
45
|
createRenderer: () => createRenderer,
|
46
46
|
createRendererWithOwner: () => createRendererWithOwner,
|
47
|
-
createScope: () => createScope,
|
48
47
|
createTemplate: () => createTemplate,
|
49
48
|
data: () => data,
|
50
49
|
dynamicClosure: () => dynamicClosure,
|
@@ -240,20 +239,13 @@ function on(element, type, handler) {
|
|
240
239
|
if (!handlersByElement.has(element)) {
|
241
240
|
defaultDelegator(element, type, handleDelegated);
|
242
241
|
}
|
243
|
-
handlersByElement.set(element, handler ||
|
242
|
+
handlersByElement.set(element, handler || null);
|
244
243
|
}
|
245
244
|
function createDelegator() {
|
246
|
-
const
|
245
|
+
const kEvents = Symbol();
|
247
246
|
return function ensureDelegated(node, type, handler) {
|
248
247
|
const root = node.getRootNode();
|
249
|
-
|
250
|
-
if (!delegatedEvents) {
|
251
|
-
delegatedEventsByRoot.set(root, delegatedEvents = /* @__PURE__ */ new Set());
|
252
|
-
}
|
253
|
-
if (!delegatedEvents.has(type)) {
|
254
|
-
delegatedEvents.add(type);
|
255
|
-
root.addEventListener(type, handler, true);
|
256
|
-
}
|
248
|
+
(root[kEvents] ||= {})[type] ||= (root.addEventListener(type, handler, true), 1);
|
257
249
|
};
|
258
250
|
}
|
259
251
|
function handleDelegated(ev) {
|
@@ -387,9 +379,10 @@ var Render = class {
|
|
387
379
|
curParent.prepend(startNode);
|
388
380
|
}
|
389
381
|
this.___currentScopeId = this.___scopeStack.pop();
|
390
|
-
} else if (token === "|" /* BranchSingleNode */) {
|
382
|
+
} else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
|
391
383
|
let next = data3.indexOf(" ");
|
392
|
-
let curNode =
|
384
|
+
let curNode = visit;
|
385
|
+
scope[~next ? data3.slice(0, next) : data3] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit;
|
393
386
|
while (~next) {
|
394
387
|
const start = next + 1;
|
395
388
|
next = data3.indexOf(" ", start);
|
@@ -628,7 +621,7 @@ function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
|
|
628
621
|
}
|
629
622
|
function controllable_select_value_effect(scope, nodeAccessor) {
|
630
623
|
const el = scope[nodeAccessor];
|
631
|
-
|
624
|
+
const onChange = () => {
|
632
625
|
const valueChange = scope[nodeAccessor + ";" /* ControlledHandler */];
|
633
626
|
if (valueChange) {
|
634
627
|
scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
|
@@ -644,7 +637,19 @@ function controllable_select_value_effect(scope, nodeAccessor) {
|
|
644
637
|
);
|
645
638
|
}
|
646
639
|
}
|
647
|
-
}
|
640
|
+
};
|
641
|
+
if (!controllableHandlers.has(el)) {
|
642
|
+
new MutationObserver(() => {
|
643
|
+
const value2 = scope[nodeAccessor + ":" /* ControlledValue */];
|
644
|
+
if (Array.isArray(value2) ? value2.length !== el.selectedOptions.length || value2.some((value3, i) => value3 != el.selectedOptions[i].value) : el.value != value2) {
|
645
|
+
onChange();
|
646
|
+
}
|
647
|
+
}).observe(el, {
|
648
|
+
childList: true,
|
649
|
+
subtree: true
|
650
|
+
});
|
651
|
+
}
|
652
|
+
syncControllable(el, "input", hasSelectChanged, onChange);
|
648
653
|
}
|
649
654
|
function setSelectOptions(el, value2, valueChange) {
|
650
655
|
if (Array.isArray(value2)) {
|
@@ -727,25 +732,27 @@ function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
|
|
727
732
|
scope[nodeAccessor].defaultChecked = checked;
|
728
733
|
}
|
729
734
|
}
|
730
|
-
var
|
731
|
-
var
|
735
|
+
var controllableDelegate = createDelegator();
|
736
|
+
var controllableHandlers = /* @__PURE__ */ new WeakMap();
|
732
737
|
function syncControllable(el, event, hasChanged, onChange) {
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
738
|
+
if (!controllableHandlers.has(el)) {
|
739
|
+
controllableDelegate(el, event, handleChange);
|
740
|
+
if (el.form) {
|
741
|
+
controllableDelegate(el.form, "reset", handleFormReset);
|
742
|
+
}
|
743
|
+
if (isResuming && hasChanged(el)) {
|
744
|
+
queueMicrotask(onChange);
|
745
|
+
}
|
740
746
|
}
|
747
|
+
controllableHandlers.set(el, onChange);
|
741
748
|
}
|
742
|
-
function
|
743
|
-
|
749
|
+
function handleChange(ev) {
|
750
|
+
controllableHandlers.get(ev.target)?.(ev);
|
744
751
|
}
|
745
|
-
function
|
752
|
+
function handleFormReset(ev) {
|
746
753
|
const handlers = [];
|
747
754
|
for (const el of ev.target.elements) {
|
748
|
-
const handler =
|
755
|
+
const handler = controllableHandlers.get(el);
|
749
756
|
if (handler && hasFormElementChanged(el)) {
|
750
757
|
handlers.push(handler);
|
751
758
|
}
|
@@ -1436,7 +1443,6 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
|
|
1436
1443
|
___setup: setup,
|
1437
1444
|
___clone: _clone,
|
1438
1445
|
___owner: owner,
|
1439
|
-
___sourceNode: void 0,
|
1440
1446
|
get ___args() {
|
1441
1447
|
return args ||= getArgs?.();
|
1442
1448
|
}
|
@@ -1530,12 +1536,12 @@ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersecti
|
|
1530
1536
|
function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
1531
1537
|
const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */];
|
1532
1538
|
const referenceNode = scope[nodeAccessor];
|
1533
|
-
const newBranch = newRenderer
|
1539
|
+
const newBranch = newRenderer && createBranchScopeWithTagNameOrRenderer(
|
1534
1540
|
newRenderer,
|
1535
1541
|
scope.$global,
|
1536
1542
|
scope,
|
1537
1543
|
referenceNode
|
1538
|
-
)
|
1544
|
+
);
|
1539
1545
|
referenceNode.textContent = "";
|
1540
1546
|
if (newBranch) {
|
1541
1547
|
insertBranchBefore(newBranch, referenceNode, null);
|
@@ -1544,10 +1550,10 @@ function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
|
1544
1550
|
scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
|
1545
1551
|
}
|
1546
1552
|
var emptyMarkerMap = /* @__PURE__ */ new Map([
|
1547
|
-
[Symbol(), getEmptyBranch(
|
1553
|
+
[Symbol(), /* @__PURE__ */ getEmptyBranch(0)]
|
1548
1554
|
]);
|
1549
1555
|
var emptyMarkerArray = [
|
1550
|
-
/* @__PURE__ */ getEmptyBranch(
|
1556
|
+
/* @__PURE__ */ getEmptyBranch(0)
|
1551
1557
|
];
|
1552
1558
|
var emptyMap = /* @__PURE__ */ new Map();
|
1553
1559
|
var emptyArray = [];
|
@@ -1989,7 +1995,7 @@ var compat = {
|
|
1989
1995
|
return value2 === MARK || value2 === CLEAN || value2 === DIRTY;
|
1990
1996
|
},
|
1991
1997
|
isRenderer(renderer) {
|
1992
|
-
return renderer.___clone
|
1998
|
+
return renderer.___clone;
|
1993
1999
|
},
|
1994
2000
|
getStartNode(branch) {
|
1995
2001
|
return branch.___startNode;
|
@@ -2019,7 +2025,7 @@ var compat = {
|
|
2019
2025
|
return value2;
|
2020
2026
|
},
|
2021
2027
|
createRenderer(setup, clone, args) {
|
2022
|
-
const renderer = createRenderer("",
|
2028
|
+
const renderer = createRenderer("", 0, setup, args && (() => args));
|
2023
2029
|
renderer.___clone = clone;
|
2024
2030
|
return renderer;
|
2025
2031
|
},
|
package/dist/debug/dom.mjs
CHANGED
@@ -153,20 +153,13 @@ function on(element, type, handler) {
|
|
153
153
|
if (!handlersByElement.has(element)) {
|
154
154
|
defaultDelegator(element, type, handleDelegated);
|
155
155
|
}
|
156
|
-
handlersByElement.set(element, handler ||
|
156
|
+
handlersByElement.set(element, handler || null);
|
157
157
|
}
|
158
158
|
function createDelegator() {
|
159
|
-
const
|
159
|
+
const kEvents = Symbol();
|
160
160
|
return function ensureDelegated(node, type, handler) {
|
161
161
|
const root = node.getRootNode();
|
162
|
-
|
163
|
-
if (!delegatedEvents) {
|
164
|
-
delegatedEventsByRoot.set(root, delegatedEvents = /* @__PURE__ */ new Set());
|
165
|
-
}
|
166
|
-
if (!delegatedEvents.has(type)) {
|
167
|
-
delegatedEvents.add(type);
|
168
|
-
root.addEventListener(type, handler, true);
|
169
|
-
}
|
162
|
+
(root[kEvents] ||= {})[type] ||= (root.addEventListener(type, handler, true), 1);
|
170
163
|
};
|
171
164
|
}
|
172
165
|
function handleDelegated(ev) {
|
@@ -300,9 +293,10 @@ var Render = class {
|
|
300
293
|
curParent.prepend(startNode);
|
301
294
|
}
|
302
295
|
this.___currentScopeId = this.___scopeStack.pop();
|
303
|
-
} else if (token === "|" /* BranchSingleNode */) {
|
296
|
+
} else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
|
304
297
|
let next = data3.indexOf(" ");
|
305
|
-
let curNode =
|
298
|
+
let curNode = visit;
|
299
|
+
scope[~next ? data3.slice(0, next) : data3] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit;
|
306
300
|
while (~next) {
|
307
301
|
const start = next + 1;
|
308
302
|
next = data3.indexOf(" ", start);
|
@@ -541,7 +535,7 @@ function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
|
|
541
535
|
}
|
542
536
|
function controllable_select_value_effect(scope, nodeAccessor) {
|
543
537
|
const el = scope[nodeAccessor];
|
544
|
-
|
538
|
+
const onChange = () => {
|
545
539
|
const valueChange = scope[nodeAccessor + ";" /* ControlledHandler */];
|
546
540
|
if (valueChange) {
|
547
541
|
scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
|
@@ -557,7 +551,19 @@ function controllable_select_value_effect(scope, nodeAccessor) {
|
|
557
551
|
);
|
558
552
|
}
|
559
553
|
}
|
560
|
-
}
|
554
|
+
};
|
555
|
+
if (!controllableHandlers.has(el)) {
|
556
|
+
new MutationObserver(() => {
|
557
|
+
const value2 = scope[nodeAccessor + ":" /* ControlledValue */];
|
558
|
+
if (Array.isArray(value2) ? value2.length !== el.selectedOptions.length || value2.some((value3, i) => value3 != el.selectedOptions[i].value) : el.value != value2) {
|
559
|
+
onChange();
|
560
|
+
}
|
561
|
+
}).observe(el, {
|
562
|
+
childList: true,
|
563
|
+
subtree: true
|
564
|
+
});
|
565
|
+
}
|
566
|
+
syncControllable(el, "input", hasSelectChanged, onChange);
|
561
567
|
}
|
562
568
|
function setSelectOptions(el, value2, valueChange) {
|
563
569
|
if (Array.isArray(value2)) {
|
@@ -640,25 +646,27 @@ function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
|
|
640
646
|
scope[nodeAccessor].defaultChecked = checked;
|
641
647
|
}
|
642
648
|
}
|
643
|
-
var
|
644
|
-
var
|
649
|
+
var controllableDelegate = createDelegator();
|
650
|
+
var controllableHandlers = /* @__PURE__ */ new WeakMap();
|
645
651
|
function syncControllable(el, event, hasChanged, onChange) {
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
652
|
+
if (!controllableHandlers.has(el)) {
|
653
|
+
controllableDelegate(el, event, handleChange);
|
654
|
+
if (el.form) {
|
655
|
+
controllableDelegate(el.form, "reset", handleFormReset);
|
656
|
+
}
|
657
|
+
if (isResuming && hasChanged(el)) {
|
658
|
+
queueMicrotask(onChange);
|
659
|
+
}
|
653
660
|
}
|
661
|
+
controllableHandlers.set(el, onChange);
|
654
662
|
}
|
655
|
-
function
|
656
|
-
|
663
|
+
function handleChange(ev) {
|
664
|
+
controllableHandlers.get(ev.target)?.(ev);
|
657
665
|
}
|
658
|
-
function
|
666
|
+
function handleFormReset(ev) {
|
659
667
|
const handlers = [];
|
660
668
|
for (const el of ev.target.elements) {
|
661
|
-
const handler =
|
669
|
+
const handler = controllableHandlers.get(el);
|
662
670
|
if (handler && hasFormElementChanged(el)) {
|
663
671
|
handlers.push(handler);
|
664
672
|
}
|
@@ -1349,7 +1357,6 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
|
|
1349
1357
|
___setup: setup,
|
1350
1358
|
___clone: _clone,
|
1351
1359
|
___owner: owner,
|
1352
|
-
___sourceNode: void 0,
|
1353
1360
|
get ___args() {
|
1354
1361
|
return args ||= getArgs?.();
|
1355
1362
|
}
|
@@ -1443,12 +1450,12 @@ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersecti
|
|
1443
1450
|
function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
1444
1451
|
const prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */];
|
1445
1452
|
const referenceNode = scope[nodeAccessor];
|
1446
|
-
const newBranch = newRenderer
|
1453
|
+
const newBranch = newRenderer && createBranchScopeWithTagNameOrRenderer(
|
1447
1454
|
newRenderer,
|
1448
1455
|
scope.$global,
|
1449
1456
|
scope,
|
1450
1457
|
referenceNode
|
1451
|
-
)
|
1458
|
+
);
|
1452
1459
|
referenceNode.textContent = "";
|
1453
1460
|
if (newBranch) {
|
1454
1461
|
insertBranchBefore(newBranch, referenceNode, null);
|
@@ -1457,10 +1464,10 @@ function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
|
1457
1464
|
scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
|
1458
1465
|
}
|
1459
1466
|
var emptyMarkerMap = /* @__PURE__ */ new Map([
|
1460
|
-
[Symbol(), getEmptyBranch(
|
1467
|
+
[Symbol(), /* @__PURE__ */ getEmptyBranch(0)]
|
1461
1468
|
]);
|
1462
1469
|
var emptyMarkerArray = [
|
1463
|
-
/* @__PURE__ */ getEmptyBranch(
|
1470
|
+
/* @__PURE__ */ getEmptyBranch(0)
|
1464
1471
|
];
|
1465
1472
|
var emptyMap = /* @__PURE__ */ new Map();
|
1466
1473
|
var emptyArray = [];
|
@@ -1902,7 +1909,7 @@ var compat = {
|
|
1902
1909
|
return value2 === MARK || value2 === CLEAN || value2 === DIRTY;
|
1903
1910
|
},
|
1904
1911
|
isRenderer(renderer) {
|
1905
|
-
return renderer.___clone
|
1912
|
+
return renderer.___clone;
|
1906
1913
|
},
|
1907
1914
|
getStartNode(branch) {
|
1908
1915
|
return branch.___startNode;
|
@@ -1932,7 +1939,7 @@ var compat = {
|
|
1932
1939
|
return value2;
|
1933
1940
|
},
|
1934
1941
|
createRenderer(setup, clone, args) {
|
1935
|
-
const renderer = createRenderer("",
|
1942
|
+
const renderer = createRenderer("", 0, setup, args && (() => args));
|
1936
1943
|
renderer.___clone = clone;
|
1937
1944
|
return renderer;
|
1938
1945
|
},
|
@@ -2072,7 +2079,6 @@ export {
|
|
2072
2079
|
controllable_input_value_effect as controllable_textarea_value_effect,
|
2073
2080
|
createRenderer,
|
2074
2081
|
createRendererWithOwner,
|
2075
|
-
createScope,
|
2076
2082
|
createTemplate,
|
2077
2083
|
data,
|
2078
2084
|
dynamicClosure,
|
package/dist/debug/html.js
CHANGED
@@ -1614,7 +1614,7 @@ function resumeForOf(list, cb, scopeId, accessor) {
|
|
1614
1614
|
)
|
1615
1615
|
);
|
1616
1616
|
}
|
1617
|
-
function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
|
1617
|
+
function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
|
1618
1618
|
let branchIds = "";
|
1619
1619
|
forOf(list, (item, index) => {
|
1620
1620
|
const branchId = peekNextScopeId();
|
@@ -1623,7 +1623,7 @@ function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
|
|
1623
1623
|
});
|
1624
1624
|
$chunk.writeHTML(
|
1625
1625
|
$chunk.boundary.state.mark(
|
1626
|
-
"|" /* BranchSingleNode */,
|
1626
|
+
onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1627
1627
|
scopeId + " " + accessor + branchIds
|
1628
1628
|
)
|
1629
1629
|
);
|
@@ -1645,7 +1645,7 @@ function resumeForIn(obj, cb, scopeId, accessor) {
|
|
1645
1645
|
)
|
1646
1646
|
);
|
1647
1647
|
}
|
1648
|
-
function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
|
1648
|
+
function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
|
1649
1649
|
let branchIds = "";
|
1650
1650
|
forIn(obj, (key, value) => {
|
1651
1651
|
const branchId = peekNextScopeId();
|
@@ -1654,7 +1654,7 @@ function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
|
|
1654
1654
|
});
|
1655
1655
|
$chunk.writeHTML(
|
1656
1656
|
$chunk.boundary.state.mark(
|
1657
|
-
"|" /* BranchSingleNode */,
|
1657
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1658
1658
|
scopeId + " " + accessor + branchIds
|
1659
1659
|
)
|
1660
1660
|
);
|
@@ -1676,7 +1676,7 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
|
|
1676
1676
|
)
|
1677
1677
|
);
|
1678
1678
|
}
|
1679
|
-
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
|
1679
|
+
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
|
1680
1680
|
let branchIds = "";
|
1681
1681
|
forTo(to, from, step, (index) => {
|
1682
1682
|
const branchId = peekNextScopeId();
|
@@ -1685,7 +1685,7 @@ function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
|
|
1685
1685
|
});
|
1686
1686
|
$chunk.writeHTML(
|
1687
1687
|
$chunk.boundary.state.mark(
|
1688
|
-
"|" /* BranchSingleNode */,
|
1688
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1689
1689
|
scopeId + " " + accessor + branchIds
|
1690
1690
|
)
|
1691
1691
|
);
|
@@ -1709,7 +1709,7 @@ function resumeConditional(cb, scopeId, accessor) {
|
|
1709
1709
|
)
|
1710
1710
|
);
|
1711
1711
|
}
|
1712
|
-
function resumeSingleNodeConditional(cb, scopeId, accessor) {
|
1712
|
+
function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
|
1713
1713
|
const branchId = peekNextScopeId();
|
1714
1714
|
withContext(branchIdKey, branchId, cb);
|
1715
1715
|
const rendered = peekNextScopeId() !== branchId;
|
@@ -1720,7 +1720,7 @@ function resumeSingleNodeConditional(cb, scopeId, accessor) {
|
|
1720
1720
|
}
|
1721
1721
|
$chunk.writeHTML(
|
1722
1722
|
$chunk.boundary.state.mark(
|
1723
|
-
"|" /* BranchSingleNode */,
|
1723
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1724
1724
|
scopeId + " " + accessor + (rendered ? " " + branchId : "")
|
1725
1725
|
)
|
1726
1726
|
);
|
package/dist/debug/html.mjs
CHANGED
@@ -1532,7 +1532,7 @@ function resumeForOf(list, cb, scopeId, accessor) {
|
|
1532
1532
|
)
|
1533
1533
|
);
|
1534
1534
|
}
|
1535
|
-
function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
|
1535
|
+
function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
|
1536
1536
|
let branchIds = "";
|
1537
1537
|
forOf(list, (item, index) => {
|
1538
1538
|
const branchId = peekNextScopeId();
|
@@ -1541,7 +1541,7 @@ function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
|
|
1541
1541
|
});
|
1542
1542
|
$chunk.writeHTML(
|
1543
1543
|
$chunk.boundary.state.mark(
|
1544
|
-
"|" /* BranchSingleNode */,
|
1544
|
+
onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1545
1545
|
scopeId + " " + accessor + branchIds
|
1546
1546
|
)
|
1547
1547
|
);
|
@@ -1563,7 +1563,7 @@ function resumeForIn(obj, cb, scopeId, accessor) {
|
|
1563
1563
|
)
|
1564
1564
|
);
|
1565
1565
|
}
|
1566
|
-
function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
|
1566
|
+
function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
|
1567
1567
|
let branchIds = "";
|
1568
1568
|
forIn(obj, (key, value) => {
|
1569
1569
|
const branchId = peekNextScopeId();
|
@@ -1572,7 +1572,7 @@ function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
|
|
1572
1572
|
});
|
1573
1573
|
$chunk.writeHTML(
|
1574
1574
|
$chunk.boundary.state.mark(
|
1575
|
-
"|" /* BranchSingleNode */,
|
1575
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1576
1576
|
scopeId + " " + accessor + branchIds
|
1577
1577
|
)
|
1578
1578
|
);
|
@@ -1594,7 +1594,7 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
|
|
1594
1594
|
)
|
1595
1595
|
);
|
1596
1596
|
}
|
1597
|
-
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
|
1597
|
+
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
|
1598
1598
|
let branchIds = "";
|
1599
1599
|
forTo(to, from, step, (index) => {
|
1600
1600
|
const branchId = peekNextScopeId();
|
@@ -1603,7 +1603,7 @@ function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
|
|
1603
1603
|
});
|
1604
1604
|
$chunk.writeHTML(
|
1605
1605
|
$chunk.boundary.state.mark(
|
1606
|
-
"|" /* BranchSingleNode */,
|
1606
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1607
1607
|
scopeId + " " + accessor + branchIds
|
1608
1608
|
)
|
1609
1609
|
);
|
@@ -1627,7 +1627,7 @@ function resumeConditional(cb, scopeId, accessor) {
|
|
1627
1627
|
)
|
1628
1628
|
);
|
1629
1629
|
}
|
1630
|
-
function resumeSingleNodeConditional(cb, scopeId, accessor) {
|
1630
|
+
function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
|
1631
1631
|
const branchId = peekNextScopeId();
|
1632
1632
|
withContext(branchIdKey, branchId, cb);
|
1633
1633
|
const rendered = peekNextScopeId() !== branchId;
|
@@ -1638,7 +1638,7 @@ function resumeSingleNodeConditional(cb, scopeId, accessor) {
|
|
1638
1638
|
}
|
1639
1639
|
$chunk.writeHTML(
|
1640
1640
|
$chunk.boundary.state.mark(
|
1641
|
-
"|" /* BranchSingleNode */,
|
1641
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1642
1642
|
scopeId + " " + accessor + (rendered ? " " + branchId : "")
|
1643
1643
|
)
|
1644
1644
|
);
|
package/dist/dom/compat.d.ts
CHANGED
@@ -7,7 +7,7 @@ export declare const compat: {
|
|
7
7
|
init(warp10Noop: any): void;
|
8
8
|
registerRenderer(fn: any): void;
|
9
9
|
isOp(value: any): boolean;
|
10
|
-
isRenderer(renderer: any):
|
10
|
+
isRenderer(renderer: any): any;
|
11
11
|
getStartNode(branch: any): any;
|
12
12
|
setScopeNodes(branch: any, startNode: Node, endNode: Node): void;
|
13
13
|
runComponentEffects(this: any): void;
|
package/dist/dom/renderer.d.ts
CHANGED
@@ -4,9 +4,8 @@ export type Renderer = {
|
|
4
4
|
___id: symbol;
|
5
5
|
___template: string;
|
6
6
|
___walks: string;
|
7
|
-
___setup: SetupFn | undefined;
|
7
|
+
___setup: SetupFn | undefined | 0;
|
8
8
|
___clone: (ns: string) => ChildNode;
|
9
|
-
___sourceNode: Node | undefined;
|
10
9
|
___args: Signal<unknown> | undefined;
|
11
10
|
___owner: Scope | undefined;
|
12
11
|
};
|
@@ -15,6 +14,6 @@ export declare function createBranchScopeWithRenderer(renderer: Renderer, $globa
|
|
15
14
|
export declare function createBranchScopeWithTagNameOrRenderer(tagNameOrRenderer: Renderer | string, $global: Scope["$global"], parentScope: Scope, parentNode: ParentNode): BranchScope;
|
16
15
|
export declare function initBranch(renderer: Renderer, branch: BranchScope, parentNode: ParentNode): void;
|
17
16
|
export declare function dynamicTagAttrs(nodeAccessor: Accessor, getContent?: (scope: Scope) => Renderer, inputIsArgs?: boolean): (scope: Scope, attrsOrOp: (() => Record<string, unknown>) | SignalOp) => void;
|
18
|
-
export declare function createRendererWithOwner(template: string, rawWalks?: string, setup?: SetupFn, getArgs?: () => Signal<unknown>): (owner?: Scope) => Renderer;
|
19
|
-
export declare function createRenderer(template: string, walks?: string, setup?: SetupFn, getArgs?: () => Signal<unknown>): Renderer;
|
17
|
+
export declare function createRendererWithOwner(template: string, rawWalks?: string | 0, setup?: SetupFn | 0, getArgs?: () => Signal<unknown>): (owner?: Scope) => Renderer;
|
18
|
+
export declare function createRenderer(template: string, walks?: string | 0, setup?: SetupFn | 0, getArgs?: () => Signal<unknown>): Renderer;
|
20
19
|
export {};
|
package/dist/dom/template.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
import type { Template } from "../common/types";
|
2
2
|
import { createRenderer } from "./renderer";
|
3
|
-
export declare const createTemplate: (templateId: string, template: string, walks?: string | undefined, setup?: ((scope: import("../
|
3
|
+
export declare const createTemplate: (templateId: string, template: string, walks?: string | 0 | undefined, setup?: 0 | ((scope: import("../common/types").Scope) => void) | undefined, getArgs?: (() => import("./signals").Signal<unknown>) | undefined) => Template;
|
package/dist/dom.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
export { attrTag, attrTags } from "./common/attr-tag";
|
2
2
|
export { forIn, forOf, forTo } from "./common/for";
|
3
|
-
export type { Scope } from "./common/types";
|
4
3
|
export { getAbortSignal, resetAbortSignal } from "./dom/abort-signal";
|
5
4
|
export { compat } from "./dom/compat";
|
6
5
|
export { conditional, conditionalOnlyChild, loopIn, loopOf, loopTo, } from "./dom/control-flow";
|
@@ -10,6 +9,5 @@ export { on } from "./dom/event";
|
|
10
9
|
export { run } from "./dom/queue";
|
11
10
|
export { createRenderer, createRendererWithOwner, dynamicTagAttrs, } from "./dom/renderer";
|
12
11
|
export { init, nodeRef, register, registerBoundSignal, registerSubscriber, } from "./dom/resume";
|
13
|
-
export { createScope } from "./dom/scope";
|
14
12
|
export { conditionalClosure, dynamicClosure, effect, inChild, intersection, intersections, loopClosure, nextTagId, setTagVar, setTagVarChange, state, tagVarSignal, tagVarSignalChange, value, } from "./dom/signals";
|
15
13
|
export { createTemplate } from "./dom/template";
|
package/dist/dom.js
CHANGED
@@ -41,7 +41,6 @@ __export(dom_exports, {
|
|
41
41
|
controllable_textarea_value_effect: () => controllable_input_value_effect,
|
42
42
|
createRenderer: () => createRenderer,
|
43
43
|
createRendererWithOwner: () => createRendererWithOwner,
|
44
|
-
createScope: () => createScope,
|
45
44
|
createTemplate: () => createTemplate,
|
46
45
|
data: () => data,
|
47
46
|
dynamicClosure: () => dynamicClosure,
|
@@ -179,13 +178,13 @@ function normalizeDynamicRenderer(value2) {
|
|
179
178
|
var elementHandlersByEvent = /* @__PURE__ */ new Map(), defaultDelegator = createDelegator();
|
180
179
|
function on(element, type, handler) {
|
181
180
|
let handlersByElement = elementHandlersByEvent.get(type);
|
182
|
-
handlersByElement || elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap()), handlersByElement.has(element) || defaultDelegator(element, type, handleDelegated), handlersByElement.set(element, handler ||
|
181
|
+
handlersByElement || elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap()), handlersByElement.has(element) || defaultDelegator(element, type, handleDelegated), handlersByElement.set(element, handler || null);
|
183
182
|
}
|
184
183
|
function createDelegator() {
|
185
|
-
let
|
184
|
+
let kEvents = Symbol();
|
186
185
|
return function(node, type, handler) {
|
187
|
-
let root = node.getRootNode()
|
188
|
-
|
186
|
+
let root = node.getRootNode();
|
187
|
+
(root[kEvents] ||= {})[type] ||= (root.addEventListener(type, handler, !0), 1);
|
189
188
|
};
|
190
189
|
}
|
191
190
|
function handleDelegated(ev) {
|
@@ -268,9 +267,9 @@ var registeredValues = {}, Render = class {
|
|
268
267
|
visit
|
269
268
|
).a;
|
270
269
|
curParent !== startNode.parentNode && curParent.prepend(startNode), this.e = this.n.pop();
|
271
|
-
} else if (token === "|" /* BranchSingleNode */) {
|
272
|
-
let next = data3.indexOf(" "), curNode =
|
273
|
-
for (; ~next; ) {
|
270
|
+
} else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
|
271
|
+
let next = data3.indexOf(" "), curNode = visit;
|
272
|
+
for (scope[~next ? data3.slice(0, next) : data3] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit; ~next; ) {
|
274
273
|
let start = next + 1;
|
275
274
|
next = data3.indexOf(" ", start);
|
276
275
|
let childScopeId = data3.slice(start, ~next ? next : data3.length);
|
@@ -409,8 +408,7 @@ function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
|
|
409
408
|
);
|
410
409
|
}
|
411
410
|
function controllable_select_value_effect(scope, nodeAccessor) {
|
412
|
-
let el = scope[nodeAccessor]
|
413
|
-
syncControllable(el, "input", hasSelectChanged, () => {
|
411
|
+
let el = scope[nodeAccessor], onChange = () => {
|
414
412
|
let valueChange = scope[nodeAccessor + ";" /* ControlledHandler */];
|
415
413
|
valueChange && (scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */, valueChange(
|
416
414
|
Array.isArray(scope[nodeAccessor + ":" /* ControlledValue */]) ? Array.from(el.selectedOptions, toValueProp) : el.value
|
@@ -419,7 +417,14 @@ function controllable_select_value_effect(scope, nodeAccessor) {
|
|
419
417
|
scope[nodeAccessor + ":" /* ControlledValue */],
|
420
418
|
valueChange
|
421
419
|
));
|
422
|
-
}
|
420
|
+
};
|
421
|
+
controllableHandlers.has(el) || new MutationObserver(() => {
|
422
|
+
let value2 = scope[nodeAccessor + ":" /* ControlledValue */];
|
423
|
+
(Array.isArray(value2) ? value2.length !== el.selectedOptions.length || value2.some((value3, i) => value3 != el.selectedOptions[i].value) : el.value != value2) && onChange();
|
424
|
+
}).observe(el, {
|
425
|
+
childList: !0,
|
426
|
+
subtree: !0
|
427
|
+
}), syncControllable(el, "input", hasSelectChanged, onChange);
|
423
428
|
}
|
424
429
|
function setSelectOptions(el, value2, valueChange) {
|
425
430
|
if (Array.isArray(value2))
|
@@ -471,17 +476,17 @@ function setValueAndUpdateSelection(el, value2) {
|
|
471
476
|
function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
|
472
477
|
scope[nodeAccessor + ";" /* ControlledHandler */] = checkedChange, checkedChange ? (scope[nodeAccessor + "=" /* ControlledType */] = type, scope[nodeAccessor].checked = checked) : (scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, scope[nodeAccessor].defaultChecked = checked);
|
473
478
|
}
|
474
|
-
var
|
479
|
+
var controllableDelegate = createDelegator(), controllableHandlers = /* @__PURE__ */ new WeakMap();
|
475
480
|
function syncControllable(el, event, hasChanged, onChange) {
|
476
|
-
|
481
|
+
controllableHandlers.has(el) || (controllableDelegate(el, event, handleChange), el.form && controllableDelegate(el.form, "reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange)), controllableHandlers.set(el, onChange);
|
477
482
|
}
|
478
|
-
function
|
479
|
-
|
483
|
+
function handleChange(ev) {
|
484
|
+
controllableHandlers.get(ev.target)?.(ev);
|
480
485
|
}
|
481
|
-
function
|
486
|
+
function handleFormReset(ev) {
|
482
487
|
let handlers = [];
|
483
488
|
for (let el of ev.target.elements) {
|
484
|
-
let handler =
|
489
|
+
let handler = controllableHandlers.get(el);
|
485
490
|
handler && hasFormElementChanged(el) && handlers.push(handler);
|
486
491
|
}
|
487
492
|
requestAnimationFrame(() => {
|
@@ -938,7 +943,6 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
|
|
938
943
|
x: setup,
|
939
944
|
l: _clone,
|
940
945
|
u: owner,
|
941
|
-
J: void 0,
|
942
946
|
get d() {
|
943
947
|
return args ||= getArgs?.();
|
944
948
|
}
|
@@ -1005,18 +1009,18 @@ var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
|
|
1005
1009
|
};
|
1006
1010
|
};
|
1007
1011
|
function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
1008
|
-
let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer
|
1012
|
+
let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer && createBranchScopeWithTagNameOrRenderer(
|
1009
1013
|
newRenderer,
|
1010
1014
|
scope.$global,
|
1011
1015
|
scope,
|
1012
1016
|
referenceNode
|
1013
|
-
)
|
1017
|
+
);
|
1014
1018
|
referenceNode.textContent = "", newBranch && insertBranchBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
|
1015
1019
|
}
|
1016
1020
|
var emptyMarkerMap = /* @__PURE__ */ new Map([
|
1017
|
-
[Symbol(), getEmptyBranch(
|
1021
|
+
[Symbol(), /* @__PURE__ */ getEmptyBranch(0)]
|
1018
1022
|
]), emptyMarkerArray = [
|
1019
|
-
/* @__PURE__ */ getEmptyBranch(
|
1023
|
+
/* @__PURE__ */ getEmptyBranch(0)
|
1020
1024
|
], emptyMap = /* @__PURE__ */ new Map(), emptyArray = [];
|
1021
1025
|
function loopOf(nodeAccessor, renderer) {
|
1022
1026
|
return loop(
|
@@ -1279,7 +1283,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
|
|
1279
1283
|
return value2 === MARK || value2 === CLEAN || value2 === DIRTY;
|
1280
1284
|
},
|
1281
1285
|
isRenderer(renderer) {
|
1282
|
-
return renderer.l
|
1286
|
+
return renderer.l;
|
1283
1287
|
},
|
1284
1288
|
getStartNode(branch) {
|
1285
1289
|
return branch.a;
|
@@ -1303,7 +1307,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
|
|
1303
1307
|
) : value2;
|
1304
1308
|
},
|
1305
1309
|
createRenderer(setup, clone, args) {
|
1306
|
-
let renderer = createRenderer("",
|
1310
|
+
let renderer = createRenderer("", 0, setup, args && (() => args));
|
1307
1311
|
return renderer.l = clone, renderer;
|
1308
1312
|
},
|
1309
1313
|
render(out, component, renderer, args) {
|
package/dist/dom.mjs
CHANGED
@@ -95,13 +95,13 @@ function normalizeDynamicRenderer(value2) {
|
|
95
95
|
var elementHandlersByEvent = /* @__PURE__ */ new Map(), defaultDelegator = createDelegator();
|
96
96
|
function on(element, type, handler) {
|
97
97
|
let handlersByElement = elementHandlersByEvent.get(type);
|
98
|
-
handlersByElement || elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap()), handlersByElement.has(element) || defaultDelegator(element, type, handleDelegated), handlersByElement.set(element, handler ||
|
98
|
+
handlersByElement || elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap()), handlersByElement.has(element) || defaultDelegator(element, type, handleDelegated), handlersByElement.set(element, handler || null);
|
99
99
|
}
|
100
100
|
function createDelegator() {
|
101
|
-
let
|
101
|
+
let kEvents = Symbol();
|
102
102
|
return function(node, type, handler) {
|
103
|
-
let root = node.getRootNode()
|
104
|
-
|
103
|
+
let root = node.getRootNode();
|
104
|
+
(root[kEvents] ||= {})[type] ||= (root.addEventListener(type, handler, !0), 1);
|
105
105
|
};
|
106
106
|
}
|
107
107
|
function handleDelegated(ev) {
|
@@ -184,9 +184,9 @@ var registeredValues = {}, Render = class {
|
|
184
184
|
visit
|
185
185
|
).a;
|
186
186
|
curParent !== startNode.parentNode && curParent.prepend(startNode), this.e = this.n.pop();
|
187
|
-
} else if (token === "|" /* BranchSingleNode */) {
|
188
|
-
let next = data3.indexOf(" "), curNode =
|
189
|
-
for (; ~next; ) {
|
187
|
+
} else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
|
188
|
+
let next = data3.indexOf(" "), curNode = visit;
|
189
|
+
for (scope[~next ? data3.slice(0, next) : data3] = token === "=" /* BranchSingleNodeOnlyChildInParent */ ? visit.parentNode : visit; ~next; ) {
|
190
190
|
let start = next + 1;
|
191
191
|
next = data3.indexOf(" ", start);
|
192
192
|
let childScopeId = data3.slice(start, ~next ? next : data3.length);
|
@@ -325,8 +325,7 @@ function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
|
|
325
325
|
);
|
326
326
|
}
|
327
327
|
function controllable_select_value_effect(scope, nodeAccessor) {
|
328
|
-
let el = scope[nodeAccessor]
|
329
|
-
syncControllable(el, "input", hasSelectChanged, () => {
|
328
|
+
let el = scope[nodeAccessor], onChange = () => {
|
330
329
|
let valueChange = scope[nodeAccessor + ";" /* ControlledHandler */];
|
331
330
|
valueChange && (scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */, valueChange(
|
332
331
|
Array.isArray(scope[nodeAccessor + ":" /* ControlledValue */]) ? Array.from(el.selectedOptions, toValueProp) : el.value
|
@@ -335,7 +334,14 @@ function controllable_select_value_effect(scope, nodeAccessor) {
|
|
335
334
|
scope[nodeAccessor + ":" /* ControlledValue */],
|
336
335
|
valueChange
|
337
336
|
));
|
338
|
-
}
|
337
|
+
};
|
338
|
+
controllableHandlers.has(el) || new MutationObserver(() => {
|
339
|
+
let value2 = scope[nodeAccessor + ":" /* ControlledValue */];
|
340
|
+
(Array.isArray(value2) ? value2.length !== el.selectedOptions.length || value2.some((value3, i) => value3 != el.selectedOptions[i].value) : el.value != value2) && onChange();
|
341
|
+
}).observe(el, {
|
342
|
+
childList: !0,
|
343
|
+
subtree: !0
|
344
|
+
}), syncControllable(el, "input", hasSelectChanged, onChange);
|
339
345
|
}
|
340
346
|
function setSelectOptions(el, value2, valueChange) {
|
341
347
|
if (Array.isArray(value2))
|
@@ -387,17 +393,17 @@ function setValueAndUpdateSelection(el, value2) {
|
|
387
393
|
function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
|
388
394
|
scope[nodeAccessor + ";" /* ControlledHandler */] = checkedChange, checkedChange ? (scope[nodeAccessor + "=" /* ControlledType */] = type, scope[nodeAccessor].checked = checked) : (scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, scope[nodeAccessor].defaultChecked = checked);
|
389
395
|
}
|
390
|
-
var
|
396
|
+
var controllableDelegate = createDelegator(), controllableHandlers = /* @__PURE__ */ new WeakMap();
|
391
397
|
function syncControllable(el, event, hasChanged, onChange) {
|
392
|
-
|
398
|
+
controllableHandlers.has(el) || (controllableDelegate(el, event, handleChange), el.form && controllableDelegate(el.form, "reset", handleFormReset), isResuming && hasChanged(el) && queueMicrotask(onChange)), controllableHandlers.set(el, onChange);
|
393
399
|
}
|
394
|
-
function
|
395
|
-
|
400
|
+
function handleChange(ev) {
|
401
|
+
controllableHandlers.get(ev.target)?.(ev);
|
396
402
|
}
|
397
|
-
function
|
403
|
+
function handleFormReset(ev) {
|
398
404
|
let handlers = [];
|
399
405
|
for (let el of ev.target.elements) {
|
400
|
-
let handler =
|
406
|
+
let handler = controllableHandlers.get(el);
|
401
407
|
handler && hasFormElementChanged(el) && handlers.push(handler);
|
402
408
|
}
|
403
409
|
requestAnimationFrame(() => {
|
@@ -854,7 +860,6 @@ function createRendererWithOwner(template, rawWalks, setup, getArgs) {
|
|
854
860
|
x: setup,
|
855
861
|
l: _clone,
|
856
862
|
u: owner,
|
857
|
-
J: void 0,
|
858
863
|
get d() {
|
859
864
|
return args ||= getArgs?.();
|
860
865
|
}
|
@@ -921,18 +926,18 @@ var conditionalOnlyChild = function(nodeAccessor, fn, getIntersection) {
|
|
921
926
|
};
|
922
927
|
};
|
923
928
|
function setConditionalRendererOnlyChild(scope, nodeAccessor, newRenderer) {
|
924
|
-
let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer
|
929
|
+
let prevBranch = scope[nodeAccessor + "!" /* ConditionalScope */], referenceNode = scope[nodeAccessor], newBranch = newRenderer && createBranchScopeWithTagNameOrRenderer(
|
925
930
|
newRenderer,
|
926
931
|
scope.$global,
|
927
932
|
scope,
|
928
933
|
referenceNode
|
929
|
-
)
|
934
|
+
);
|
930
935
|
referenceNode.textContent = "", newBranch && insertBranchBefore(newBranch, referenceNode, null), prevBranch && destroyBranch(prevBranch), scope[nodeAccessor + "!" /* ConditionalScope */] = newBranch;
|
931
936
|
}
|
932
937
|
var emptyMarkerMap = /* @__PURE__ */ new Map([
|
933
|
-
[Symbol(), getEmptyBranch(
|
938
|
+
[Symbol(), /* @__PURE__ */ getEmptyBranch(0)]
|
934
939
|
]), emptyMarkerArray = [
|
935
|
-
/* @__PURE__ */ getEmptyBranch(
|
940
|
+
/* @__PURE__ */ getEmptyBranch(0)
|
936
941
|
], emptyMap = /* @__PURE__ */ new Map(), emptyArray = [];
|
937
942
|
function loopOf(nodeAccessor, renderer) {
|
938
943
|
return loop(
|
@@ -1195,7 +1200,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
|
|
1195
1200
|
return value2 === MARK || value2 === CLEAN || value2 === DIRTY;
|
1196
1201
|
},
|
1197
1202
|
isRenderer(renderer) {
|
1198
|
-
return renderer.l
|
1203
|
+
return renderer.l;
|
1199
1204
|
},
|
1200
1205
|
getStartNode(branch) {
|
1201
1206
|
return branch.a;
|
@@ -1219,7 +1224,7 @@ var classIdToBranch = /* @__PURE__ */ new Map(), compat = {
|
|
1219
1224
|
) : value2;
|
1220
1225
|
},
|
1221
1226
|
createRenderer(setup, clone, args) {
|
1222
|
-
let renderer = createRenderer("",
|
1227
|
+
let renderer = createRenderer("", 0, setup, args && (() => args));
|
1223
1228
|
return renderer.l = clone, renderer;
|
1224
1229
|
},
|
1225
1230
|
render(out, component, renderer, args) {
|
@@ -1311,7 +1316,6 @@ export {
|
|
1311
1316
|
controllable_input_value_effect as controllable_textarea_value_effect,
|
1312
1317
|
createRenderer,
|
1313
1318
|
createRendererWithOwner,
|
1314
|
-
createScope,
|
1315
1319
|
createTemplate,
|
1316
1320
|
data,
|
1317
1321
|
dynamicClosure,
|
package/dist/html/writer.d.ts
CHANGED
@@ -27,13 +27,13 @@ export declare function markResumeNode(scopeId: number, accessor: Accessor): str
|
|
27
27
|
export declare function nodeRef(scopeId: number, id?: string): () => void;
|
28
28
|
export declare function resumeClosestBranch(scopeId: number): void;
|
29
29
|
export declare function resumeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, scopeId: number, accessor: Accessor): void;
|
30
|
-
export declare function resumeSingleNodeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, scopeId: number, accessor: Accessor): void;
|
30
|
+
export declare function resumeSingleNodeForOf(list: Falsy | Iterable<unknown>, cb: (item: unknown, index: number) => void, scopeId: number, accessor: Accessor, onlyChildInParent?: 1): void;
|
31
31
|
export declare function resumeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, scopeId: number, accessor: Accessor): void;
|
32
|
-
export declare function resumeSingleNodeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, scopeId: number, accessor: Accessor): void;
|
32
|
+
export declare function resumeSingleNodeForIn(obj: Falsy | {}, cb: (key: string, value: unknown) => void, scopeId: number, accessor: Accessor, onlyChild?: 1): void;
|
33
33
|
export declare function resumeForTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, scopeId: number, accessor: Accessor): void;
|
34
|
-
export declare function resumeSingleNodeForTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, scopeId: number, accessor: Accessor): void;
|
34
|
+
export declare function resumeSingleNodeForTo(to: number, from: number | Falsy, step: number | Falsy, cb: (index: number) => void, scopeId: number, accessor: Accessor, onlyChild?: 1): void;
|
35
35
|
export declare function resumeConditional(cb: () => void | number, scopeId: number, accessor: Accessor): void;
|
36
|
-
export declare function resumeSingleNodeConditional(cb: () => void | number, scopeId: number, accessor: Accessor): void;
|
36
|
+
export declare function resumeSingleNodeConditional(cb: () => void | number, scopeId: number, accessor: Accessor, onlyChild?: 1): void;
|
37
37
|
export declare function writeScope(scopeId: number, partialScope: PartialScope): ScopeInternals;
|
38
38
|
export declare function writeExistingScope(scope: ScopeInternals): ScopeInternals;
|
39
39
|
export declare function ensureScopeWithId(scopeId: number): PartialScope;
|
package/dist/html.js
CHANGED
@@ -1066,14 +1066,14 @@ function resumeForOf(list, cb, scopeId, accessor) {
|
|
1066
1066
|
)
|
1067
1067
|
);
|
1068
1068
|
}
|
1069
|
-
function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
|
1069
|
+
function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
|
1070
1070
|
let branchIds = "";
|
1071
1071
|
forOf(list, (item, index) => {
|
1072
1072
|
let branchId = peekNextScopeId();
|
1073
1073
|
branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(item, index));
|
1074
1074
|
}), $chunk.writeHTML(
|
1075
1075
|
$chunk.boundary.state.mark(
|
1076
|
-
"|" /* BranchSingleNode */,
|
1076
|
+
onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1077
1077
|
scopeId + " " + accessor + branchIds
|
1078
1078
|
)
|
1079
1079
|
);
|
@@ -1092,14 +1092,14 @@ function resumeForIn(obj, cb, scopeId, accessor) {
|
|
1092
1092
|
)
|
1093
1093
|
);
|
1094
1094
|
}
|
1095
|
-
function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
|
1095
|
+
function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
|
1096
1096
|
let branchIds = "";
|
1097
1097
|
forIn(obj, (key, value) => {
|
1098
1098
|
let branchId = peekNextScopeId();
|
1099
1099
|
branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(key, value));
|
1100
1100
|
}), $chunk.writeHTML(
|
1101
1101
|
$chunk.boundary.state.mark(
|
1102
|
-
"|" /* BranchSingleNode */,
|
1102
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1103
1103
|
scopeId + " " + accessor + branchIds
|
1104
1104
|
)
|
1105
1105
|
);
|
@@ -1118,14 +1118,14 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
|
|
1118
1118
|
)
|
1119
1119
|
);
|
1120
1120
|
}
|
1121
|
-
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
|
1121
|
+
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
|
1122
1122
|
let branchIds = "";
|
1123
1123
|
forTo(to, from, step, (index) => {
|
1124
1124
|
let branchId = peekNextScopeId();
|
1125
1125
|
branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(index));
|
1126
1126
|
}), $chunk.writeHTML(
|
1127
1127
|
$chunk.boundary.state.mark(
|
1128
|
-
"|" /* BranchSingleNode */,
|
1128
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1129
1129
|
scopeId + " " + accessor + branchIds
|
1130
1130
|
)
|
1131
1131
|
);
|
@@ -1141,13 +1141,13 @@ function resumeConditional(cb, scopeId, accessor) {
|
|
1141
1141
|
)
|
1142
1142
|
);
|
1143
1143
|
}
|
1144
|
-
function resumeSingleNodeConditional(cb, scopeId, accessor) {
|
1144
|
+
function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
|
1145
1145
|
let branchId = peekNextScopeId();
|
1146
1146
|
withContext(branchIdKey, branchId, cb);
|
1147
1147
|
let rendered = peekNextScopeId() !== branchId;
|
1148
1148
|
rendered ? writeScope(branchId, {}) : nextScopeId(), $chunk.writeHTML(
|
1149
1149
|
$chunk.boundary.state.mark(
|
1150
|
-
"|" /* BranchSingleNode */,
|
1150
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1151
1151
|
scopeId + " " + accessor + (rendered ? " " + branchId : "")
|
1152
1152
|
)
|
1153
1153
|
);
|
package/dist/html.mjs
CHANGED
@@ -987,14 +987,14 @@ function resumeForOf(list, cb, scopeId, accessor) {
|
|
987
987
|
)
|
988
988
|
);
|
989
989
|
}
|
990
|
-
function resumeSingleNodeForOf(list, cb, scopeId, accessor) {
|
990
|
+
function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
|
991
991
|
let branchIds = "";
|
992
992
|
forOf(list, (item, index) => {
|
993
993
|
let branchId = peekNextScopeId();
|
994
994
|
branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(item, index));
|
995
995
|
}), $chunk.writeHTML(
|
996
996
|
$chunk.boundary.state.mark(
|
997
|
-
"|" /* BranchSingleNode */,
|
997
|
+
onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
998
998
|
scopeId + " " + accessor + branchIds
|
999
999
|
)
|
1000
1000
|
);
|
@@ -1013,14 +1013,14 @@ function resumeForIn(obj, cb, scopeId, accessor) {
|
|
1013
1013
|
)
|
1014
1014
|
);
|
1015
1015
|
}
|
1016
|
-
function resumeSingleNodeForIn(obj, cb, scopeId, accessor) {
|
1016
|
+
function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
|
1017
1017
|
let branchIds = "";
|
1018
1018
|
forIn(obj, (key, value) => {
|
1019
1019
|
let branchId = peekNextScopeId();
|
1020
1020
|
branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(key, value));
|
1021
1021
|
}), $chunk.writeHTML(
|
1022
1022
|
$chunk.boundary.state.mark(
|
1023
|
-
"|" /* BranchSingleNode */,
|
1023
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1024
1024
|
scopeId + " " + accessor + branchIds
|
1025
1025
|
)
|
1026
1026
|
);
|
@@ -1039,14 +1039,14 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
|
|
1039
1039
|
)
|
1040
1040
|
);
|
1041
1041
|
}
|
1042
|
-
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor) {
|
1042
|
+
function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
|
1043
1043
|
let branchIds = "";
|
1044
1044
|
forTo(to, from, step, (index) => {
|
1045
1045
|
let branchId = peekNextScopeId();
|
1046
1046
|
branchIds = " " + branchId + branchIds, withContext(branchIdKey, branchId, () => cb(index));
|
1047
1047
|
}), $chunk.writeHTML(
|
1048
1048
|
$chunk.boundary.state.mark(
|
1049
|
-
"|" /* BranchSingleNode */,
|
1049
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1050
1050
|
scopeId + " " + accessor + branchIds
|
1051
1051
|
)
|
1052
1052
|
);
|
@@ -1062,13 +1062,13 @@ function resumeConditional(cb, scopeId, accessor) {
|
|
1062
1062
|
)
|
1063
1063
|
);
|
1064
1064
|
}
|
1065
|
-
function resumeSingleNodeConditional(cb, scopeId, accessor) {
|
1065
|
+
function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
|
1066
1066
|
let branchId = peekNextScopeId();
|
1067
1067
|
withContext(branchIdKey, branchId, cb);
|
1068
1068
|
let rendered = peekNextScopeId() !== branchId;
|
1069
1069
|
rendered ? writeScope(branchId, {}) : nextScopeId(), $chunk.writeHTML(
|
1070
1070
|
$chunk.boundary.state.mark(
|
1071
|
-
"|" /* BranchSingleNode */,
|
1071
|
+
onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
|
1072
1072
|
scopeId + " " + accessor + (rendered ? " " + branchId : "")
|
1073
1073
|
)
|
1074
1074
|
);
|
package/dist/translator/index.js
CHANGED
@@ -626,19 +626,22 @@ function toMemberExpression(object, key, optional) {
|
|
626
626
|
|
627
627
|
// src/translator/util/runtime.ts
|
628
628
|
var pureFunctions = [
|
629
|
-
"
|
629
|
+
"conditional",
|
630
|
+
"conditionalClosure",
|
631
|
+
"conditionalOnlyChild",
|
630
632
|
"createRenderer",
|
631
633
|
"createRendererWithOwner",
|
632
|
-
"
|
633
|
-
"
|
634
|
+
"createTemplate",
|
635
|
+
"dynamicClosure",
|
636
|
+
"dynamicTagAttrs",
|
637
|
+
"inChild",
|
634
638
|
"intersection",
|
635
639
|
"loopClosure",
|
636
|
-
"conditionalClosure",
|
637
|
-
"dynamicClosure",
|
638
|
-
"loopOf",
|
639
640
|
"loopIn",
|
641
|
+
"loopOf",
|
640
642
|
"loopTo",
|
641
|
-
"
|
643
|
+
"state",
|
644
|
+
"value"
|
642
645
|
];
|
643
646
|
function importRuntime(name2) {
|
644
647
|
const { output } = getMarkoOpts();
|
@@ -1987,6 +1990,10 @@ function setForceResumeScope(section) {
|
|
1987
1990
|
_setForceResumeScope(section, true);
|
1988
1991
|
}
|
1989
1992
|
var [getSerializedScopeProperties] = createSectionState("serializedScopeProperties", () => /* @__PURE__ */ new Map());
|
1993
|
+
var [getHTMLSectionStatements] = createSectionState(
|
1994
|
+
"htmlScopeStatements",
|
1995
|
+
() => []
|
1996
|
+
);
|
1990
1997
|
var unimplementedBuild = () => {
|
1991
1998
|
return import_compiler17.types.stringLiteral("SIGNAL NOT INITIALIZED");
|
1992
1999
|
};
|
@@ -2677,13 +2684,14 @@ function writeHTMLResumeStatements(path5) {
|
|
2677
2684
|
)
|
2678
2685
|
);
|
2679
2686
|
}
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2687
|
+
const additionalStatements = getHTMLSectionStatements(section);
|
2688
|
+
if (path5.get("body").length || additionalStatements.length) {
|
2689
|
+
path5.unshiftContainer("body", [
|
2683
2690
|
import_compiler17.types.variableDeclaration("const", [
|
2684
2691
|
import_compiler17.types.variableDeclarator(scopeIdIdentifier, callRuntime("nextScopeId"))
|
2685
|
-
])
|
2686
|
-
|
2692
|
+
]),
|
2693
|
+
...additionalStatements
|
2694
|
+
]);
|
2687
2695
|
}
|
2688
2696
|
const returnIdentifier = getSectionReturnValueIdentifier(section);
|
2689
2697
|
if (returnIdentifier !== void 0) {
|
@@ -4521,7 +4529,9 @@ var native_tag_default = {
|
|
4521
4529
|
const tagName2 = node.name.type === "StringLiteral" ? node.name.value : import_compiler28.types.toIdentifier(tag.get("name"));
|
4522
4530
|
const tagExtra = node.extra ??= {};
|
4523
4531
|
const bindingName = "#" + tagName2;
|
4524
|
-
|
4532
|
+
if (hasEventHandlers || node.var) {
|
4533
|
+
tagExtra[kSerializeMarker] = true;
|
4534
|
+
}
|
4525
4535
|
tagExtra[kNativeTagBinding] = createBinding(
|
4526
4536
|
bindingName,
|
4527
4537
|
0 /* dom */,
|
@@ -4902,9 +4912,9 @@ var native_tag_default = {
|
|
4902
4912
|
import_compiler28.types.ifStatement(tag.node.name, consumeHTML(tag))
|
4903
4913
|
)[0].skip();
|
4904
4914
|
}
|
4905
|
-
if (nodeRef2 && (extra[kSerializeMarker] || isStatefulReferences(extra.referencedBindings) || tag.node.attributes.some(
|
4915
|
+
if (nodeRef2 && (extra[kSerializeMarker] || extra[kSerializeMarker] === void 0 && (isStatefulReferences(extra.referencedBindings) || tag.node.attributes.some(
|
4906
4916
|
(attr2) => isStatefulReferences(attr2.value.extra?.referencedBindings)
|
4907
|
-
))) {
|
4917
|
+
)))) {
|
4908
4918
|
markNode(tag, nodeRef2);
|
4909
4919
|
}
|
4910
4920
|
exit2(tag);
|
@@ -5083,17 +5093,18 @@ var for_default = {
|
|
5083
5093
|
const tagExtra = node.extra;
|
5084
5094
|
const isStateful = isStatefulReferences(tagExtra.referencedBindings);
|
5085
5095
|
const parentTag = getParentTag(tag);
|
5086
|
-
const
|
5096
|
+
const onlyChildInParentOptimization = isOnlyChildInParent(tag);
|
5097
|
+
const nodeRef2 = onlyChildInParentOptimization ? parentTag.node.extra[kNativeTagBinding] : tag.node.extra[kForMarkerBinding];
|
5087
5098
|
const forAttrs = getKnownAttrValues(node);
|
5088
5099
|
const forType = getForType(node);
|
5089
5100
|
const params = node.body.params;
|
5090
5101
|
const statements = [];
|
5091
5102
|
const bodyStatements = node.body.body;
|
5092
5103
|
const hasStatefulClosures = checkStatefulClosures(bodySection, true);
|
5093
|
-
const singleNodeOptimization = bodySection.content === null || bodySection.content.singleChild
|
5104
|
+
const singleNodeOptimization = bodySection.content === null || bodySection.content.singleChild && bodySection.content.startType !== 4 /* Text */;
|
5094
5105
|
let keyExpression;
|
5095
|
-
if (
|
5096
|
-
parentTag.node.extra[kSerializeMarker] =
|
5106
|
+
if (singleNodeOptimization && onlyChildInParentOptimization) {
|
5107
|
+
parentTag.node.extra[kSerializeMarker] = false;
|
5097
5108
|
}
|
5098
5109
|
if (isStateful || hasStatefulClosures) {
|
5099
5110
|
const defaultParamNames = {
|
@@ -5147,7 +5158,7 @@ var for_default = {
|
|
5147
5158
|
keyExpression = params[defaultByParamIndex];
|
5148
5159
|
}
|
5149
5160
|
const forScopesIdentifier = getScopeIdentifier(bodySection);
|
5150
|
-
|
5161
|
+
getHTMLSectionStatements(tagSection).push(
|
5151
5162
|
import_compiler29.types.variableDeclaration("const", [
|
5152
5163
|
import_compiler29.types.variableDeclarator(
|
5153
5164
|
forScopesIdentifier,
|
@@ -5200,6 +5211,9 @@ var for_default = {
|
|
5200
5211
|
getScopeAccessorLiteral(nodeRef2)
|
5201
5212
|
);
|
5202
5213
|
}
|
5214
|
+
if (singleNodeOptimization && onlyChildInParentOptimization) {
|
5215
|
+
forTagArgs.push(import_compiler29.types.numericLiteral(1));
|
5216
|
+
}
|
5203
5217
|
statements.push(
|
5204
5218
|
import_compiler29.types.expressionStatement(callRuntime(forTagHTMLRuntime, ...forTagArgs))
|
5205
5219
|
);
|
@@ -6943,7 +6957,7 @@ var IfTag = {
|
|
6943
6957
|
if (branchBodySection) {
|
6944
6958
|
branchBodySection.isBranch = true;
|
6945
6959
|
branchBodySection.upstreamExpression = rootExtra;
|
6946
|
-
if (!(branchBodySection.content === null || branchBodySection.content?.singleChild)) {
|
6960
|
+
if (!(branchBodySection.content === null || branchBodySection.content?.singleChild && branchBodySection.content.startType !== 4 /* Text */)) {
|
6947
6961
|
singleNodeOptimization = false;
|
6948
6962
|
}
|
6949
6963
|
}
|
@@ -7084,16 +7098,16 @@ var IfTag = {
|
|
7084
7098
|
)
|
7085
7099
|
);
|
7086
7100
|
}
|
7087
|
-
nextTag.insertBefore(
|
7101
|
+
nextTag.insertBefore(statement);
|
7102
|
+
getHTMLSectionStatements(section).push(
|
7088
7103
|
import_compiler38.types.variableDeclaration(
|
7089
7104
|
"let",
|
7090
7105
|
[
|
7091
7106
|
import_compiler38.types.variableDeclarator(ifScopeIdIdentifier),
|
7092
7107
|
isStateful && import_compiler38.types.variableDeclarator(ifRendererIdentifier)
|
7093
7108
|
].filter(Boolean)
|
7094
|
-
)
|
7095
|
-
|
7096
|
-
]);
|
7109
|
+
)
|
7110
|
+
);
|
7097
7111
|
getSerializedScopeProperties(section).set(
|
7098
7112
|
import_compiler38.types.stringLiteral(
|
7099
7113
|
getScopeAccessorLiteral(nodeRef2).value + "!" /* ConditionalScope */
|
@@ -8034,6 +8048,7 @@ var function_default = {
|
|
8034
8048
|
if (index === void 0) {
|
8035
8049
|
functionNameCounts.set(name2, 0);
|
8036
8050
|
} else {
|
8051
|
+
functionNameCounts.set(name2, index + 1);
|
8037
8052
|
id = `_${index}`;
|
8038
8053
|
}
|
8039
8054
|
extra.section = section;
|
@@ -9315,6 +9330,7 @@ var dynamic_tag_default = {
|
|
9315
9330
|
|
9316
9331
|
// src/translator/visitors/tag/index.ts
|
9317
9332
|
var TAG_NAME_IDENTIFIER_REG = /^[A-Z][a-zA-Z0-9_$]*$/;
|
9333
|
+
var BINDING_CHANGE_HANDLER = /* @__PURE__ */ new WeakMap();
|
9318
9334
|
var tag_default = {
|
9319
9335
|
transform: {
|
9320
9336
|
enter(tag) {
|
@@ -9332,18 +9348,7 @@ var tag_default = {
|
|
9332
9348
|
const attr2 = attributes[i];
|
9333
9349
|
if (import_compiler53.types.isMarkoAttribute(attr2) && attr2.bound) {
|
9334
9350
|
attr2.bound = false;
|
9335
|
-
|
9336
|
-
if (changeValue === null) {
|
9337
|
-
throw tag.hub.buildError(
|
9338
|
-
attr2,
|
9339
|
-
"Attributes may only be bound to identifiers or member expressions"
|
9340
|
-
);
|
9341
|
-
}
|
9342
|
-
attributes.splice(
|
9343
|
-
++i,
|
9344
|
-
0,
|
9345
|
-
import_compiler53.types.markoAttribute(attr2.name + "Change", changeValue)
|
9346
|
-
);
|
9351
|
+
attributes.splice(++i, 0, getChangeHandler(tag, attr2));
|
9347
9352
|
crawl = true;
|
9348
9353
|
}
|
9349
9354
|
}
|
@@ -9463,33 +9468,94 @@ var tag_default = {
|
|
9463
9468
|
}
|
9464
9469
|
};
|
9465
9470
|
function getChangeHandler(tag, attr2) {
|
9471
|
+
const attrName = attr2.name;
|
9472
|
+
const changeAttrName = attrName + "Change";
|
9466
9473
|
if (import_compiler53.types.isIdentifier(attr2.value)) {
|
9467
|
-
const
|
9468
|
-
|
9469
|
-
|
9470
|
-
|
9471
|
-
|
9472
|
-
|
9474
|
+
const binding = tag.scope.getBinding(attr2.value.name);
|
9475
|
+
if (!binding)
|
9476
|
+
return import_compiler53.types.markoAttribute(
|
9477
|
+
changeAttrName,
|
9478
|
+
buildChangeHandlerFunction(attr2.value)
|
9479
|
+
);
|
9480
|
+
const existingChangedAttr = BINDING_CHANGE_HANDLER.get(binding.identifier);
|
9481
|
+
if (!existingChangedAttr) {
|
9482
|
+
const changeHandlerAttr = import_compiler53.types.markoAttribute(
|
9483
|
+
changeAttrName,
|
9484
|
+
buildChangeHandlerFunction(attr2.value)
|
9485
|
+
);
|
9486
|
+
BINDING_CHANGE_HANDLER.set(binding.identifier, changeHandlerAttr);
|
9487
|
+
return changeHandlerAttr;
|
9488
|
+
}
|
9489
|
+
if (existingChangedAttr.type === "Identifier") {
|
9490
|
+
return import_compiler53.types.markoAttribute(
|
9491
|
+
changeAttrName,
|
9492
|
+
withPreviousLocation(
|
9493
|
+
import_compiler53.types.identifier(existingChangedAttr.name),
|
9494
|
+
attr2.value
|
9473
9495
|
)
|
9474
|
-
|
9496
|
+
);
|
9497
|
+
}
|
9498
|
+
const markoRoot = isMarko(binding.path) ? binding.path : getMarkoRoot(binding.path);
|
9499
|
+
if (!(markoRoot?.isMarkoTag() || markoRoot?.isMarkoTagBody())) {
|
9500
|
+
throw tag.hub.buildError(attr2.value, "Unable to bind to value.");
|
9501
|
+
}
|
9502
|
+
const changeHandlerId = markoRoot.scope.generateUid(changeAttrName);
|
9503
|
+
const changeHandlerConst = import_compiler53.types.markoTag(
|
9504
|
+
import_compiler53.types.stringLiteral("const"),
|
9505
|
+
[import_compiler53.types.markoAttribute("value", existingChangedAttr.value, null, null, true)],
|
9506
|
+
import_compiler53.types.markoTagBody([]),
|
9507
|
+
null,
|
9508
|
+
import_compiler53.types.identifier(changeHandlerId)
|
9509
|
+
);
|
9510
|
+
BINDING_CHANGE_HANDLER.set(
|
9511
|
+
binding.identifier,
|
9512
|
+
existingChangedAttr.value = import_compiler53.types.identifier(changeHandlerId)
|
9513
|
+
);
|
9514
|
+
if (markoRoot.isMarkoTag()) {
|
9515
|
+
markoRoot.insertAfter(changeHandlerConst);
|
9516
|
+
} else {
|
9517
|
+
markoRoot.unshiftContainer("body", changeHandlerConst);
|
9518
|
+
}
|
9519
|
+
return import_compiler53.types.markoAttribute(
|
9520
|
+
changeAttrName,
|
9521
|
+
withPreviousLocation(import_compiler53.types.identifier(changeHandlerId), attr2.value)
|
9475
9522
|
);
|
9476
9523
|
} else if (import_compiler53.types.isMemberExpression(attr2.value)) {
|
9477
9524
|
const prop = attr2.value.property;
|
9478
|
-
if (import_compiler53.types.isPrivateName(
|
9479
|
-
|
9480
|
-
|
9481
|
-
import_compiler53.types.
|
9482
|
-
|
9483
|
-
|
9484
|
-
|
9485
|
-
|
9486
|
-
|
9487
|
-
|
9488
|
-
|
9525
|
+
if (!import_compiler53.types.isPrivateName(attr2.value.property)) {
|
9526
|
+
return import_compiler53.types.markoAttribute(
|
9527
|
+
changeAttrName,
|
9528
|
+
import_compiler53.types.memberExpression(
|
9529
|
+
import_compiler53.types.cloneNode(attr2.value.object),
|
9530
|
+
prop.type === "Identifier" ? withPreviousLocation(import_compiler53.types.identifier(prop.name + "Change"), prop) : import_compiler53.types.binaryExpression(
|
9531
|
+
"+",
|
9532
|
+
import_compiler53.types.cloneNode(prop),
|
9533
|
+
import_compiler53.types.stringLiteral("Change")
|
9534
|
+
),
|
9535
|
+
prop.type !== "Identifier"
|
9536
|
+
)
|
9489
9537
|
);
|
9490
9538
|
}
|
9491
9539
|
}
|
9492
|
-
|
9540
|
+
throw tag.hub.buildError(
|
9541
|
+
attr2.value,
|
9542
|
+
"Attributes may only be bound to identifiers or member expressions"
|
9543
|
+
);
|
9544
|
+
}
|
9545
|
+
function buildChangeHandlerFunction(id) {
|
9546
|
+
const newId = "_new_" + id.name;
|
9547
|
+
return import_compiler53.types.arrowFunctionExpression(
|
9548
|
+
[withPreviousLocation(import_compiler53.types.identifier(newId), id)],
|
9549
|
+
import_compiler53.types.blockStatement([
|
9550
|
+
import_compiler53.types.expressionStatement(
|
9551
|
+
import_compiler53.types.assignmentExpression(
|
9552
|
+
"=",
|
9553
|
+
withPreviousLocation(import_compiler53.types.identifier(id.name), id),
|
9554
|
+
withPreviousLocation(import_compiler53.types.identifier(newId), id)
|
9555
|
+
)
|
9556
|
+
)
|
9557
|
+
])
|
9558
|
+
);
|
9493
9559
|
}
|
9494
9560
|
|
9495
9561
|
// src/translator/visitors/text.ts
|
@@ -38,6 +38,7 @@ export type Signal = {
|
|
38
38
|
export declare function setClosureSignalBuilder(tag: t.NodePath<t.MarkoTag>, builder: closureSignalBuilder): void;
|
39
39
|
export declare function setForceResumeScope(section: Section): void;
|
40
40
|
export declare const getSerializedScopeProperties: (section: Section) => Map<t.StringLiteral | t.NumericLiteral, t.Expression>;
|
41
|
+
export declare const getHTMLSectionStatements: (section: Section) => t.Statement[];
|
41
42
|
export declare function getSignal(section: Section, referencedBindings: ReferencedBindings, name?: string): Signal;
|
42
43
|
export declare function initValue(binding: Binding, runtimeHelper?: "value" | "state"): Signal;
|
43
44
|
export declare function getSignalFn(signal: Signal, params: Array<t.Identifier | t.Pattern>, referencedBindings?: ReferencedBindings): t.ArrowFunctionExpression;
|