regor 1.3.5 → 1.3.7
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/README.md +44 -21
- package/dist/regor.d.ts +42 -24
- package/dist/regor.es2015.cjs.js +741 -390
- package/dist/regor.es2015.cjs.prod.js +3 -3
- package/dist/regor.es2015.esm.js +741 -390
- package/dist/regor.es2015.esm.prod.js +3 -3
- package/dist/regor.es2015.iife.js +741 -390
- package/dist/regor.es2015.iife.prod.js +3 -3
- package/dist/regor.es2019.cjs.js +741 -390
- package/dist/regor.es2019.cjs.prod.js +3 -3
- package/dist/regor.es2019.esm.js +741 -390
- package/dist/regor.es2019.esm.prod.js +3 -3
- package/dist/regor.es2019.iife.js +741 -390
- package/dist/regor.es2019.iife.prod.js +3 -3
- package/dist/regor.es2022.cjs.js +732 -378
- package/dist/regor.es2022.cjs.prod.js +3 -3
- package/dist/regor.es2022.esm.js +732 -378
- package/dist/regor.es2022.esm.prod.js +3 -3
- package/dist/regor.es2022.iife.js +732 -378
- package/dist/regor.es2022.iife.prod.js +3 -3
- package/package.json +1 -1
|
@@ -30,7 +30,7 @@ var Regor = (() => {
|
|
|
30
30
|
computeRef: () => computeRef,
|
|
31
31
|
computed: () => computed,
|
|
32
32
|
createApp: () => createApp,
|
|
33
|
-
|
|
33
|
+
defineComponent: () => defineComponent,
|
|
34
34
|
drainUnbind: () => drainUnbind,
|
|
35
35
|
endBatch: () => endBatch,
|
|
36
36
|
entangle: () => entangle,
|
|
@@ -71,8 +71,8 @@ var Regor = (() => {
|
|
|
71
71
|
// src/cleanup/unbind.ts
|
|
72
72
|
var unbind = (node) => {
|
|
73
73
|
const stack = [node];
|
|
74
|
-
|
|
75
|
-
const currentNode = stack
|
|
74
|
+
for (let i = 0; i < stack.length; ++i) {
|
|
75
|
+
const currentNode = stack[i];
|
|
76
76
|
unbindSingle(currentNode);
|
|
77
77
|
for (let child = currentNode.lastChild; child != null; child = child.previousSibling) {
|
|
78
78
|
stack.push(child);
|
|
@@ -422,6 +422,8 @@ var Regor = (() => {
|
|
|
422
422
|
};
|
|
423
423
|
|
|
424
424
|
// src/bind/IfBinder.ts
|
|
425
|
+
var noopStopObserving = () => {
|
|
426
|
+
};
|
|
425
427
|
var mount = (nodes, binder, parent, end) => {
|
|
426
428
|
const childNodes = [];
|
|
427
429
|
for (const x of nodes) {
|
|
@@ -546,18 +548,14 @@ var Regor = (() => {
|
|
|
546
548
|
const parseResult = this.__binder.__parser.__parse(expression);
|
|
547
549
|
const value = parseResult.value;
|
|
548
550
|
const remainingElses = this.__collectElses(nextElement, refresh);
|
|
549
|
-
|
|
551
|
+
let stopObserver = noopStopObserving;
|
|
550
552
|
const unbinder = () => {
|
|
551
553
|
parseResult.stop();
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
stopObserverList.length = 0;
|
|
554
|
+
stopObserver();
|
|
555
|
+
stopObserver = noopStopObserving;
|
|
556
556
|
};
|
|
557
557
|
addUnbinder(commentBegin, unbinder);
|
|
558
|
-
|
|
559
|
-
};
|
|
560
|
-
stopObserverList.push(stopObserving);
|
|
558
|
+
stopObserver = parseResult.subscribe(refresh);
|
|
561
559
|
return [
|
|
562
560
|
{
|
|
563
561
|
mount: () => {
|
|
@@ -568,8 +566,9 @@ var Regor = (() => {
|
|
|
568
566
|
},
|
|
569
567
|
isTrue: () => !!value()[0],
|
|
570
568
|
isMounted: false
|
|
571
|
-
}
|
|
572
|
-
|
|
569
|
+
},
|
|
570
|
+
...remainingElses
|
|
571
|
+
];
|
|
573
572
|
}
|
|
574
573
|
}
|
|
575
574
|
__bindToExpression(el, expression) {
|
|
@@ -615,29 +614,31 @@ var Regor = (() => {
|
|
|
615
614
|
});
|
|
616
615
|
};
|
|
617
616
|
const collectedElses = this.__collectElses(nextElement, refresh);
|
|
618
|
-
|
|
617
|
+
let stopObserver = noopStopObserving;
|
|
619
618
|
const unbinder = () => {
|
|
620
619
|
parseResult.stop();
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
}
|
|
624
|
-
stopObserverList.length = 0;
|
|
620
|
+
stopObserver();
|
|
621
|
+
stopObserver = noopStopObserving;
|
|
625
622
|
};
|
|
626
623
|
addUnbinder(commentBegin, unbinder);
|
|
627
624
|
refresh();
|
|
628
|
-
|
|
629
|
-
};
|
|
630
|
-
stopObserverList.push(stopObserving);
|
|
625
|
+
stopObserver = parseResult.subscribe(refresh);
|
|
631
626
|
}
|
|
632
627
|
};
|
|
633
628
|
|
|
634
629
|
// src/common/common.ts
|
|
635
630
|
var getNodes = (el) => {
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
631
|
+
const source = isTemplate(el) ? el.content.childNodes : [el];
|
|
632
|
+
const result = [];
|
|
633
|
+
for (let i = 0; i < source.length; ++i) {
|
|
634
|
+
const node = source[i];
|
|
635
|
+
if (node.nodeType === 1) {
|
|
636
|
+
const tagName = node?.tagName;
|
|
637
|
+
if (tagName === "SCRIPT" || tagName === "STYLE") continue;
|
|
638
|
+
}
|
|
639
|
+
result.push(node);
|
|
640
|
+
}
|
|
641
|
+
return result;
|
|
641
642
|
};
|
|
642
643
|
var bindChildNodes = (binder, childNodes) => {
|
|
643
644
|
for (let i = 0; i < childNodes.length; ++i) {
|
|
@@ -734,7 +735,9 @@ var Regor = (() => {
|
|
|
734
735
|
});
|
|
735
736
|
|
|
736
737
|
// src/directives/teleport.ts
|
|
737
|
-
var teleportDirective = {
|
|
738
|
+
var teleportDirective = {
|
|
739
|
+
mount: () => void 0
|
|
740
|
+
};
|
|
738
741
|
|
|
739
742
|
// src/composition/callMounted.ts
|
|
740
743
|
var callMounted = (context) => {
|
|
@@ -768,11 +771,6 @@ var Regor = (() => {
|
|
|
768
771
|
return scopeSymbol2 in value;
|
|
769
772
|
};
|
|
770
773
|
|
|
771
|
-
// src/composition/onUnmounted.ts
|
|
772
|
-
var onUnmounted = (onUnmounted2, noThrow) => {
|
|
773
|
-
peekScope(noThrow)?.onUnmounted.push(onUnmounted2);
|
|
774
|
-
};
|
|
775
|
-
|
|
776
774
|
// src/reactivity/refSymbols.ts
|
|
777
775
|
var refSymbol = Symbol("ref");
|
|
778
776
|
var srefSymbol = Symbol("sref");
|
|
@@ -783,6 +781,34 @@ var Regor = (() => {
|
|
|
783
781
|
return value != null && value[srefSymbol] === 1;
|
|
784
782
|
};
|
|
785
783
|
|
|
784
|
+
// src/directives/context.ts
|
|
785
|
+
var contextDirective = {
|
|
786
|
+
collectRefObj: true,
|
|
787
|
+
mount: ({ parseResult }) => ({
|
|
788
|
+
update: ({ values }) => {
|
|
789
|
+
const ctx = parseResult.context;
|
|
790
|
+
const obj = values[0];
|
|
791
|
+
if (!isObject(obj)) return;
|
|
792
|
+
for (const item of Object.entries(obj)) {
|
|
793
|
+
const key = item[0];
|
|
794
|
+
const nextValue = item[1];
|
|
795
|
+
const ctxKey = ctx[key];
|
|
796
|
+
if (ctxKey === nextValue) continue;
|
|
797
|
+
if (isRef(ctxKey)) {
|
|
798
|
+
ctxKey(nextValue);
|
|
799
|
+
} else {
|
|
800
|
+
ctx[key] = nextValue;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
})
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/composition/onUnmounted.ts
|
|
808
|
+
var onUnmounted = (onUnmounted2, noThrow) => {
|
|
809
|
+
peekScope(noThrow)?.onUnmounted.push(onUnmounted2);
|
|
810
|
+
};
|
|
811
|
+
|
|
786
812
|
// src/observer/observe.ts
|
|
787
813
|
var observe = (source, observer, init, trackUnmount = true) => {
|
|
788
814
|
if (!isRef(source))
|
|
@@ -799,37 +825,6 @@ var Regor = (() => {
|
|
|
799
825
|
return stop;
|
|
800
826
|
};
|
|
801
827
|
|
|
802
|
-
// src/directives/context.ts
|
|
803
|
-
var contextDirective = {
|
|
804
|
-
collectRefObj: true,
|
|
805
|
-
onBind: (_, parseResult) => {
|
|
806
|
-
const stopObserving = observe(
|
|
807
|
-
parseResult.value,
|
|
808
|
-
() => {
|
|
809
|
-
const value = parseResult.value();
|
|
810
|
-
const ctx = parseResult.context;
|
|
811
|
-
const obj = value[0];
|
|
812
|
-
if (!isObject(obj)) {
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
for (const item of Object.entries(obj)) {
|
|
816
|
-
const key = item[0];
|
|
817
|
-
const value2 = item[1];
|
|
818
|
-
const ctxKey = ctx[key];
|
|
819
|
-
if (ctxKey === value2) continue;
|
|
820
|
-
if (isRef(ctxKey)) {
|
|
821
|
-
ctxKey(value2);
|
|
822
|
-
} else {
|
|
823
|
-
ctx[key] = value2;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
},
|
|
827
|
-
true
|
|
828
|
-
);
|
|
829
|
-
return stopObserving;
|
|
830
|
-
}
|
|
831
|
-
};
|
|
832
|
-
|
|
833
828
|
// src/reactivity/entangle.ts
|
|
834
829
|
var entangle = (r1, r2) => {
|
|
835
830
|
if (r1 === r2) return () => {
|
|
@@ -1156,8 +1151,8 @@ var Regor = (() => {
|
|
|
1156
1151
|
};
|
|
1157
1152
|
var singlePropDirective = {
|
|
1158
1153
|
collectRefObj: true,
|
|
1159
|
-
|
|
1160
|
-
if (!option) return noop;
|
|
1154
|
+
mount: ({ parseResult, option }) => {
|
|
1155
|
+
if (typeof option !== "string" || !option) return noop;
|
|
1161
1156
|
const key = camelize(option);
|
|
1162
1157
|
let currentSource;
|
|
1163
1158
|
let bridge;
|
|
@@ -1178,43 +1173,43 @@ var Regor = (() => {
|
|
|
1178
1173
|
stopEntangle = entangle(source, target);
|
|
1179
1174
|
currentSource = source;
|
|
1180
1175
|
};
|
|
1181
|
-
const
|
|
1182
|
-
parseResult.value
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
if (bridge && ctxKey === bridge) {
|
|
1189
|
-
bridge(value);
|
|
1190
|
-
return;
|
|
1191
|
-
}
|
|
1192
|
-
resetSync();
|
|
1193
|
-
if (isRef(ctxKey)) {
|
|
1194
|
-
ctxKey(value);
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
ctx[key] = value;
|
|
1176
|
+
const apply = () => {
|
|
1177
|
+
const value = parseResult.refs[0] ?? parseResult.value()[0];
|
|
1178
|
+
const ctx = parseResult.context;
|
|
1179
|
+
const ctxKey = ctx[key];
|
|
1180
|
+
if (!isRef(value)) {
|
|
1181
|
+
if (bridge && ctxKey === bridge) {
|
|
1182
|
+
bridge(value);
|
|
1198
1183
|
return;
|
|
1199
1184
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
syncRefs(value, ctxKey);
|
|
1204
|
-
} else {
|
|
1205
|
-
ctx[key] = value;
|
|
1206
|
-
}
|
|
1185
|
+
resetSync();
|
|
1186
|
+
if (isRef(ctxKey)) {
|
|
1187
|
+
ctxKey(value);
|
|
1207
1188
|
return;
|
|
1208
1189
|
}
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1190
|
+
ctx[key] = value;
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
if (isModelBridge(value)) {
|
|
1194
|
+
if (ctxKey === value) return;
|
|
1195
|
+
if (isRef(ctxKey)) {
|
|
1196
|
+
syncRefs(value, ctxKey);
|
|
1197
|
+
} else {
|
|
1198
|
+
ctx[key] = value;
|
|
1199
|
+
}
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
if (!bridge) bridge = createModelBridge(value);
|
|
1203
|
+
ctx[key] = bridge;
|
|
1204
|
+
syncRefs(value, bridge);
|
|
1205
|
+
};
|
|
1206
|
+
return {
|
|
1207
|
+
update: () => {
|
|
1208
|
+
apply();
|
|
1212
1209
|
},
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
stopEntangle();
|
|
1217
|
-
stopObserving();
|
|
1210
|
+
unmount: () => {
|
|
1211
|
+
stopEntangle();
|
|
1212
|
+
}
|
|
1218
1213
|
};
|
|
1219
1214
|
}
|
|
1220
1215
|
};
|
|
@@ -1235,7 +1230,10 @@ var Regor = (() => {
|
|
|
1235
1230
|
__getRegisteredComponentSelector(registeredComponents) {
|
|
1236
1231
|
if (this.__registeredComponentSize !== registeredComponents.size) {
|
|
1237
1232
|
const names = [...registeredComponents.keys()];
|
|
1238
|
-
this.__registeredComponentSelector =
|
|
1233
|
+
this.__registeredComponentSelector = [
|
|
1234
|
+
...names,
|
|
1235
|
+
...names.map(hyphenate)
|
|
1236
|
+
].join(",");
|
|
1239
1237
|
this.__registeredComponentSize = registeredComponents.size;
|
|
1240
1238
|
}
|
|
1241
1239
|
return this.__registeredComponentSelector;
|
|
@@ -1310,7 +1308,10 @@ var Regor = (() => {
|
|
|
1310
1308
|
definedProp
|
|
1311
1309
|
])
|
|
1312
1310
|
);
|
|
1313
|
-
for (const name of
|
|
1311
|
+
for (const name of [
|
|
1312
|
+
...definedProps,
|
|
1313
|
+
...definedProps.map(hyphenate)
|
|
1314
|
+
]) {
|
|
1314
1315
|
const value = component2.getAttribute(name);
|
|
1315
1316
|
if (value === null) continue;
|
|
1316
1317
|
props[camelize(name)] = value;
|
|
@@ -1603,15 +1604,14 @@ var Regor = (() => {
|
|
|
1603
1604
|
const processNode = (node) => {
|
|
1604
1605
|
const attrs = node.attributes;
|
|
1605
1606
|
if (!attrs || attrs.length === 0) return;
|
|
1606
|
-
const attrsAny = attrs;
|
|
1607
1607
|
for (let i = 0; i < attrs.length; ++i) {
|
|
1608
|
-
const name =
|
|
1608
|
+
const name = attrs.item(i)?.name;
|
|
1609
1609
|
if (!name) continue;
|
|
1610
1610
|
appendDirective(node, name);
|
|
1611
1611
|
}
|
|
1612
1612
|
};
|
|
1613
1613
|
processNode(element);
|
|
1614
|
-
if (!isRecursive) return map;
|
|
1614
|
+
if (!isRecursive || !element.firstElementChild) return map;
|
|
1615
1615
|
const nodes = element.querySelectorAll("*");
|
|
1616
1616
|
for (const node of nodes) {
|
|
1617
1617
|
processNode(node);
|
|
@@ -1621,6 +1621,8 @@ var Regor = (() => {
|
|
|
1621
1621
|
};
|
|
1622
1622
|
|
|
1623
1623
|
// src/bind/DynamicBinder.ts
|
|
1624
|
+
var noopStopObserving2 = () => {
|
|
1625
|
+
};
|
|
1624
1626
|
var mount2 = (nodes, parent) => {
|
|
1625
1627
|
for (const x of nodes) {
|
|
1626
1628
|
const node = x.cloneNode(true);
|
|
@@ -1735,19 +1737,15 @@ var Regor = (() => {
|
|
|
1735
1737
|
mounted.name = name;
|
|
1736
1738
|
});
|
|
1737
1739
|
};
|
|
1738
|
-
|
|
1740
|
+
let stopObserver = noopStopObserving2;
|
|
1739
1741
|
const unbinder = () => {
|
|
1740
1742
|
parseResult.stop();
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
}
|
|
1744
|
-
stopObserverList.length = 0;
|
|
1743
|
+
stopObserver();
|
|
1744
|
+
stopObserver = noopStopObserving2;
|
|
1745
1745
|
};
|
|
1746
1746
|
addUnbinder(commentBegin, unbinder);
|
|
1747
1747
|
refresh();
|
|
1748
|
-
|
|
1749
|
-
};
|
|
1750
|
-
stopObserverList.push(stopObserving);
|
|
1748
|
+
stopObserver = parseResult.subscribe(refresh);
|
|
1751
1749
|
}
|
|
1752
1750
|
};
|
|
1753
1751
|
|
|
@@ -1757,6 +1755,272 @@ var Regor = (() => {
|
|
|
1757
1755
|
return anyValue != null && anyValue[srefSymbol] === 1 ? anyValue() : anyValue;
|
|
1758
1756
|
};
|
|
1759
1757
|
|
|
1758
|
+
// src/directives/html.ts
|
|
1759
|
+
var updateHtml = (el, values) => {
|
|
1760
|
+
const [value, replacer] = values;
|
|
1761
|
+
if (isFunction(replacer)) replacer(el, value);
|
|
1762
|
+
else el.innerHTML = value?.toString();
|
|
1763
|
+
};
|
|
1764
|
+
var htmlDirective = {
|
|
1765
|
+
mount: () => ({
|
|
1766
|
+
update: ({ el, values }) => {
|
|
1767
|
+
updateHtml(el, values);
|
|
1768
|
+
}
|
|
1769
|
+
})
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
// src/bind/ForBinderFastPath.ts
|
|
1773
|
+
var ForBinderFastPath = class _ForBinderFastPath {
|
|
1774
|
+
__bindings;
|
|
1775
|
+
constructor(bindings) {
|
|
1776
|
+
this.__bindings = bindings;
|
|
1777
|
+
}
|
|
1778
|
+
static __create(binder, nodes) {
|
|
1779
|
+
const parser = binder.__parser;
|
|
1780
|
+
const config = binder.__config;
|
|
1781
|
+
const builtInNames = config.__builtInNames;
|
|
1782
|
+
const blockedBuiltIns = /* @__PURE__ */ new Set([
|
|
1783
|
+
builtInNames.for,
|
|
1784
|
+
builtInNames.if,
|
|
1785
|
+
builtInNames.else,
|
|
1786
|
+
builtInNames.elseif,
|
|
1787
|
+
builtInNames.pre
|
|
1788
|
+
]);
|
|
1789
|
+
const directiveMap = config.__directiveMap;
|
|
1790
|
+
const contextComponents = parser.__getComponents();
|
|
1791
|
+
if (Object.keys(contextComponents).length > 0 || config.__componentsUpperCase.size > 0) {
|
|
1792
|
+
return void 0;
|
|
1793
|
+
}
|
|
1794
|
+
const collector = binder.__directiveCollector;
|
|
1795
|
+
const bindings = [];
|
|
1796
|
+
let nodeIndex = 0;
|
|
1797
|
+
const stack = [];
|
|
1798
|
+
for (let i = nodes.length - 1; i >= 0; --i) {
|
|
1799
|
+
stack.push(nodes[i]);
|
|
1800
|
+
}
|
|
1801
|
+
while (stack.length > 0) {
|
|
1802
|
+
const node = stack.pop();
|
|
1803
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
1804
|
+
const el = node;
|
|
1805
|
+
if (el.tagName === "TEMPLATE") return void 0;
|
|
1806
|
+
if (el.tagName.includes("-")) return void 0;
|
|
1807
|
+
const tagNameUpper = camelize(el.tagName).toUpperCase();
|
|
1808
|
+
if (config.__componentsUpperCase.has(tagNameUpper) || contextComponents[tagNameUpper]) {
|
|
1809
|
+
return void 0;
|
|
1810
|
+
}
|
|
1811
|
+
const attrs = el.attributes;
|
|
1812
|
+
for (let i = 0; i < attrs.length; ++i) {
|
|
1813
|
+
const attrName = attrs.item(i)?.name;
|
|
1814
|
+
if (!attrName) continue;
|
|
1815
|
+
if (blockedBuiltIns.has(attrName)) return void 0;
|
|
1816
|
+
const { terms, flags } = collector.__parseName(attrName);
|
|
1817
|
+
const [name, option] = terms;
|
|
1818
|
+
const directive = directiveMap[attrName] ?? directiveMap[name];
|
|
1819
|
+
if (!directive) continue;
|
|
1820
|
+
if (directive === htmlDirective) return void 0;
|
|
1821
|
+
bindings.push({
|
|
1822
|
+
nodeIndex,
|
|
1823
|
+
attrName,
|
|
1824
|
+
directive,
|
|
1825
|
+
option,
|
|
1826
|
+
flags
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
++nodeIndex;
|
|
1830
|
+
}
|
|
1831
|
+
const children = node.childNodes;
|
|
1832
|
+
for (let i = children.length - 1; i >= 0; --i) {
|
|
1833
|
+
stack.push(children[i]);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
if (bindings.length === 0) return void 0;
|
|
1837
|
+
return new _ForBinderFastPath(bindings);
|
|
1838
|
+
}
|
|
1839
|
+
__bind(binder, nodes) {
|
|
1840
|
+
const elements = [];
|
|
1841
|
+
const stack = [];
|
|
1842
|
+
for (let i = nodes.length - 1; i >= 0; --i) {
|
|
1843
|
+
stack.push(nodes[i]);
|
|
1844
|
+
}
|
|
1845
|
+
while (stack.length > 0) {
|
|
1846
|
+
const node = stack.pop();
|
|
1847
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
1848
|
+
elements.push(node);
|
|
1849
|
+
}
|
|
1850
|
+
const children = node.childNodes;
|
|
1851
|
+
for (let i = children.length - 1; i >= 0; --i) {
|
|
1852
|
+
stack.push(children[i]);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
for (let i = 0; i < this.__bindings.length; ++i) {
|
|
1856
|
+
const binding = this.__bindings[i];
|
|
1857
|
+
const el = elements[binding.nodeIndex];
|
|
1858
|
+
if (!el) continue;
|
|
1859
|
+
binder.__bind(
|
|
1860
|
+
binding.directive,
|
|
1861
|
+
el,
|
|
1862
|
+
binding.attrName,
|
|
1863
|
+
false,
|
|
1864
|
+
binding.option,
|
|
1865
|
+
binding.flags
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
// src/bind/ForBinderKeyedDiff.ts
|
|
1872
|
+
var moveMountItemBefore = (item, anchor) => {
|
|
1873
|
+
const parent = anchor.parentNode;
|
|
1874
|
+
if (!parent) return;
|
|
1875
|
+
for (let i = 0; i < item.items.length; ++i) {
|
|
1876
|
+
parent.insertBefore(item.items[i], anchor);
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
var getSequence = (arr) => {
|
|
1880
|
+
const len = arr.length;
|
|
1881
|
+
const p = arr.slice();
|
|
1882
|
+
const result = [];
|
|
1883
|
+
let u;
|
|
1884
|
+
let v;
|
|
1885
|
+
let c;
|
|
1886
|
+
for (let i = 0; i < len; ++i) {
|
|
1887
|
+
const value = arr[i];
|
|
1888
|
+
if (value === 0) continue;
|
|
1889
|
+
const j = result[result.length - 1];
|
|
1890
|
+
if (j === void 0 || arr[j] < value) {
|
|
1891
|
+
p[i] = j ?? -1;
|
|
1892
|
+
result.push(i);
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
u = 0;
|
|
1896
|
+
v = result.length - 1;
|
|
1897
|
+
while (u < v) {
|
|
1898
|
+
c = u + v >> 1;
|
|
1899
|
+
if (arr[result[c]] < value) u = c + 1;
|
|
1900
|
+
else v = c;
|
|
1901
|
+
}
|
|
1902
|
+
if (value < arr[result[u]]) {
|
|
1903
|
+
if (u > 0) p[i] = result[u - 1];
|
|
1904
|
+
result[u] = i;
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
u = result.length;
|
|
1908
|
+
v = result[u - 1] ?? -1;
|
|
1909
|
+
while (u-- > 0) {
|
|
1910
|
+
result[u] = v;
|
|
1911
|
+
v = p[v];
|
|
1912
|
+
}
|
|
1913
|
+
return result;
|
|
1914
|
+
};
|
|
1915
|
+
var ForBinderKeyedDiff = class {
|
|
1916
|
+
/**
|
|
1917
|
+
* Applies keyed patch and returns the next ordered mount list.
|
|
1918
|
+
* Returns `undefined` when keyed mode is not safe for this update.
|
|
1919
|
+
*/
|
|
1920
|
+
static __patch(options) {
|
|
1921
|
+
const {
|
|
1922
|
+
oldItems,
|
|
1923
|
+
newValues,
|
|
1924
|
+
getKey,
|
|
1925
|
+
isSameValue,
|
|
1926
|
+
mountNewValue,
|
|
1927
|
+
removeMountItem,
|
|
1928
|
+
endAnchor
|
|
1929
|
+
} = options;
|
|
1930
|
+
const oldLen = oldItems.length;
|
|
1931
|
+
const newLen = newValues.length;
|
|
1932
|
+
const newKeys = new Array(newLen);
|
|
1933
|
+
const keySeen = /* @__PURE__ */ new Set();
|
|
1934
|
+
for (let i2 = 0; i2 < newLen; ++i2) {
|
|
1935
|
+
const key = getKey(newValues[i2]);
|
|
1936
|
+
if (key === void 0 || keySeen.has(key)) return void 0;
|
|
1937
|
+
keySeen.add(key);
|
|
1938
|
+
newKeys[i2] = key;
|
|
1939
|
+
}
|
|
1940
|
+
const newMountItems = new Array(newLen);
|
|
1941
|
+
let i = 0;
|
|
1942
|
+
let e1 = oldLen - 1;
|
|
1943
|
+
let e2 = newLen - 1;
|
|
1944
|
+
while (i <= e1 && i <= e2) {
|
|
1945
|
+
const oldItem = oldItems[i];
|
|
1946
|
+
if (getKey(oldItem.value) !== newKeys[i]) break;
|
|
1947
|
+
if (!isSameValue(oldItem.value, newValues[i])) break;
|
|
1948
|
+
oldItem.value = newValues[i];
|
|
1949
|
+
newMountItems[i] = oldItem;
|
|
1950
|
+
++i;
|
|
1951
|
+
}
|
|
1952
|
+
while (i <= e1 && i <= e2) {
|
|
1953
|
+
const oldItem = oldItems[e1];
|
|
1954
|
+
if (getKey(oldItem.value) !== newKeys[e2]) break;
|
|
1955
|
+
if (!isSameValue(oldItem.value, newValues[e2])) break;
|
|
1956
|
+
oldItem.value = newValues[e2];
|
|
1957
|
+
newMountItems[e2] = oldItem;
|
|
1958
|
+
--e1;
|
|
1959
|
+
--e2;
|
|
1960
|
+
}
|
|
1961
|
+
if (i > e1) {
|
|
1962
|
+
for (let k = e2; k >= i; --k) {
|
|
1963
|
+
const anchor = k + 1 < newLen ? newMountItems[k + 1].items[0] : endAnchor;
|
|
1964
|
+
newMountItems[k] = mountNewValue(k, newValues[k], anchor);
|
|
1965
|
+
}
|
|
1966
|
+
return newMountItems;
|
|
1967
|
+
}
|
|
1968
|
+
if (i > e2) {
|
|
1969
|
+
for (let k = i; k <= e1; ++k) removeMountItem(oldItems[k]);
|
|
1970
|
+
return newMountItems;
|
|
1971
|
+
}
|
|
1972
|
+
const s1 = i;
|
|
1973
|
+
const s2 = i;
|
|
1974
|
+
const toBePatched = e2 - s2 + 1;
|
|
1975
|
+
const newIndexToOldIndexMap = new Array(toBePatched).fill(0);
|
|
1976
|
+
const keyToNewIndexMap = /* @__PURE__ */ new Map();
|
|
1977
|
+
for (let k = s2; k <= e2; ++k) {
|
|
1978
|
+
keyToNewIndexMap.set(newKeys[k], k);
|
|
1979
|
+
}
|
|
1980
|
+
let moved = false;
|
|
1981
|
+
let maxNewIndexSoFar = 0;
|
|
1982
|
+
for (let k = s1; k <= e1; ++k) {
|
|
1983
|
+
const oldItem = oldItems[k];
|
|
1984
|
+
const newIndex = keyToNewIndexMap.get(getKey(oldItem.value));
|
|
1985
|
+
if (newIndex === void 0) {
|
|
1986
|
+
removeMountItem(oldItem);
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
if (!isSameValue(oldItem.value, newValues[newIndex])) {
|
|
1990
|
+
removeMountItem(oldItem);
|
|
1991
|
+
continue;
|
|
1992
|
+
}
|
|
1993
|
+
oldItem.value = newValues[newIndex];
|
|
1994
|
+
newMountItems[newIndex] = oldItem;
|
|
1995
|
+
newIndexToOldIndexMap[newIndex - s2] = k + 1;
|
|
1996
|
+
if (newIndex >= maxNewIndexSoFar) maxNewIndexSoFar = newIndex;
|
|
1997
|
+
else moved = true;
|
|
1998
|
+
}
|
|
1999
|
+
const increasingNewIndexSequence = moved ? getSequence(newIndexToOldIndexMap) : [];
|
|
2000
|
+
let seqIdx = increasingNewIndexSequence.length - 1;
|
|
2001
|
+
for (let k = toBePatched - 1; k >= 0; --k) {
|
|
2002
|
+
const newIndex = s2 + k;
|
|
2003
|
+
const anchor = newIndex + 1 < newLen ? newMountItems[newIndex + 1].items[0] : endAnchor;
|
|
2004
|
+
if (newIndexToOldIndexMap[k] === 0) {
|
|
2005
|
+
newMountItems[newIndex] = mountNewValue(
|
|
2006
|
+
newIndex,
|
|
2007
|
+
newValues[newIndex],
|
|
2008
|
+
anchor
|
|
2009
|
+
);
|
|
2010
|
+
continue;
|
|
2011
|
+
}
|
|
2012
|
+
const item = newMountItems[newIndex];
|
|
2013
|
+
if (!moved) continue;
|
|
2014
|
+
if (seqIdx >= 0 && increasingNewIndexSequence[seqIdx] === k) {
|
|
2015
|
+
--seqIdx;
|
|
2016
|
+
} else if (item) {
|
|
2017
|
+
moveMountItemBefore(item, anchor);
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
return newMountItems;
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
2023
|
+
|
|
1760
2024
|
// src/bind/MountList.ts
|
|
1761
2025
|
var MountList = class {
|
|
1762
2026
|
__list = [];
|
|
@@ -1836,6 +2100,8 @@ var Regor = (() => {
|
|
|
1836
2100
|
// src/bind/ForBinder.ts
|
|
1837
2101
|
var forMarker = Symbol("r-for");
|
|
1838
2102
|
var noIndexRef = (_) => -1;
|
|
2103
|
+
var noopStopObserving3 = () => {
|
|
2104
|
+
};
|
|
1839
2105
|
var ForBinder = class _ForBinder {
|
|
1840
2106
|
__binder;
|
|
1841
2107
|
__for;
|
|
@@ -1905,6 +2171,7 @@ var Regor = (() => {
|
|
|
1905
2171
|
el.removeAttribute(nameKey);
|
|
1906
2172
|
el.removeAttribute(nameKeyBind);
|
|
1907
2173
|
const nodes = getNodes(el);
|
|
2174
|
+
const fastPath = ForBinderFastPath.__create(this.__binder, nodes);
|
|
1908
2175
|
const parent = el.parentNode;
|
|
1909
2176
|
if (!parent) return;
|
|
1910
2177
|
const title = `${this.__for} => ${forPath}`;
|
|
@@ -1924,6 +2191,7 @@ var Regor = (() => {
|
|
|
1924
2191
|
const rowContexts = singleCapturedContext ? [void 0, capturedContext[0]] : void 0;
|
|
1925
2192
|
const getKey = this.__createKeyGetter(keyExpression);
|
|
1926
2193
|
const areEqual = (a, b) => getKey(a) === getKey(b);
|
|
2194
|
+
const isSameValue = (a, b) => a === b;
|
|
1927
2195
|
const mountNewValue = (i2, newValue, nextSibling) => {
|
|
1928
2196
|
const result = config.createContext(newValue, i2);
|
|
1929
2197
|
const mountItem = MountList.__createItem(result.index, newValue);
|
|
@@ -1936,7 +2204,8 @@ var Regor = (() => {
|
|
|
1936
2204
|
insertParent.insertBefore(node, nextSibling);
|
|
1937
2205
|
childNodes.push(node);
|
|
1938
2206
|
}
|
|
1939
|
-
|
|
2207
|
+
if (fastPath) fastPath.__bind(binder, childNodes);
|
|
2208
|
+
else bindChildNodes(binder, childNodes);
|
|
1940
2209
|
start = start.nextSibling;
|
|
1941
2210
|
while (start !== nextSibling) {
|
|
1942
2211
|
mountItem.items.push(start);
|
|
@@ -1988,16 +2257,51 @@ var Regor = (() => {
|
|
|
1988
2257
|
mountList.__removeAllAfter(0);
|
|
1989
2258
|
return;
|
|
1990
2259
|
}
|
|
2260
|
+
const iterableValues = [];
|
|
2261
|
+
for (const value2 of this.__getIterable(newValues[0])) {
|
|
2262
|
+
iterableValues.push(value2);
|
|
2263
|
+
}
|
|
2264
|
+
const patched = ForBinderKeyedDiff.__patch({
|
|
2265
|
+
oldItems: mountList.__list,
|
|
2266
|
+
newValues: iterableValues,
|
|
2267
|
+
getKey,
|
|
2268
|
+
isSameValue,
|
|
2269
|
+
mountNewValue: (index, value2, nextSibling) => mountNewValue(index, value2, nextSibling),
|
|
2270
|
+
removeMountItem: (item) => {
|
|
2271
|
+
for (let k = 0; k < item.items.length; ++k) {
|
|
2272
|
+
removeNode(item.items[k]);
|
|
2273
|
+
}
|
|
2274
|
+
},
|
|
2275
|
+
endAnchor: commentEnd
|
|
2276
|
+
});
|
|
2277
|
+
if (patched) {
|
|
2278
|
+
mountList.__list = patched;
|
|
2279
|
+
mountList.__valueMap.clear();
|
|
2280
|
+
for (let k = 0; k < patched.length; ++k) {
|
|
2281
|
+
const item = patched[k];
|
|
2282
|
+
item.order = k;
|
|
2283
|
+
item.index(k);
|
|
2284
|
+
const key = getKey(item.value);
|
|
2285
|
+
if (key !== void 0) {
|
|
2286
|
+
mountList.__valueMap.set(key, item);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
1991
2291
|
let i2 = 0;
|
|
1992
2292
|
let firstRemovalOrInsertionIndex = Number.MAX_SAFE_INTEGER;
|
|
1993
2293
|
const initialLength = len;
|
|
1994
2294
|
const forGrowThreshold = this.__binder.__config.forGrowThreshold;
|
|
1995
2295
|
const shouldGrowList = () => mountList.__length < initialLength + forGrowThreshold;
|
|
1996
|
-
for (const newValue of
|
|
2296
|
+
for (const newValue of iterableValues) {
|
|
1997
2297
|
const modify = () => {
|
|
1998
2298
|
if (i2 < len) {
|
|
1999
2299
|
const mountItem = mountList.__get(i2++);
|
|
2000
|
-
if (areEqual(mountItem.value, newValue))
|
|
2300
|
+
if (areEqual(mountItem.value, newValue)) {
|
|
2301
|
+
if (isSameValue(mountItem.value, newValue)) return;
|
|
2302
|
+
replace(i2 - 1, newValue);
|
|
2303
|
+
return;
|
|
2304
|
+
}
|
|
2001
2305
|
const newValueMountPosition = mountList.__lookupValueOrderIfMounted(
|
|
2002
2306
|
getKey(newValue)
|
|
2003
2307
|
);
|
|
@@ -2047,24 +2351,21 @@ var Regor = (() => {
|
|
|
2047
2351
|
mountList.__removeAllAfter(j);
|
|
2048
2352
|
updateIndexes(firstRemovalOrInsertionIndex);
|
|
2049
2353
|
};
|
|
2050
|
-
const observeTailChanges = () => {
|
|
2051
|
-
stopObserving = parseResult.subscribe ? parseResult.subscribe(updateDom) : () => {
|
|
2052
|
-
};
|
|
2053
|
-
};
|
|
2054
2354
|
const unbinder = () => {
|
|
2055
2355
|
parseResult.stop();
|
|
2056
2356
|
stopObserving();
|
|
2357
|
+
stopObserving = noopStopObserving3;
|
|
2057
2358
|
};
|
|
2058
2359
|
const parseResult = parser.__parse(config.list);
|
|
2059
2360
|
const value = parseResult.value;
|
|
2060
|
-
let stopObserving;
|
|
2361
|
+
let stopObserving = noopStopObserving3;
|
|
2061
2362
|
let i = 0;
|
|
2062
2363
|
const mountList = new MountList(getKey);
|
|
2063
2364
|
for (const item of this.__getIterable(value()[0])) {
|
|
2064
2365
|
mountList.__push(mountNewValue(i++, item, commentEnd));
|
|
2065
2366
|
}
|
|
2066
2367
|
addUnbinder(commentBegin, unbinder);
|
|
2067
|
-
|
|
2368
|
+
stopObserving = parseResult.subscribe(updateDom);
|
|
2068
2369
|
}
|
|
2069
2370
|
static __forPathRegex = /\{?\[?\(?([^)}\]]+)\)?\]?\}?([^)]+)?\s+\b(?:in|of)\b\s+(.*)\s*$/;
|
|
2070
2371
|
__parseForPath(forPath) {
|
|
@@ -2243,97 +2544,108 @@ var Regor = (() => {
|
|
|
2243
2544
|
__bindToExpression(config, el, valueExpression, option, flags) {
|
|
2244
2545
|
if (el.nodeType !== Node.ELEMENT_NODE || valueExpression == null) return;
|
|
2245
2546
|
if (this.__handleTeleport(config, el, valueExpression)) return;
|
|
2246
|
-
const
|
|
2547
|
+
const dynamicOption = this.__parseDynamicOption(option, config.once);
|
|
2548
|
+
const result = this.__parseExpression(config, valueExpression);
|
|
2549
|
+
const stops = this.__createBindStops(result, dynamicOption);
|
|
2550
|
+
addUnbinder(el, stops.stop);
|
|
2551
|
+
const payload = this.__createDirectivePayload(
|
|
2552
|
+
el,
|
|
2553
|
+
valueExpression,
|
|
2554
|
+
result,
|
|
2555
|
+
dynamicOption,
|
|
2556
|
+
option,
|
|
2557
|
+
flags
|
|
2558
|
+
);
|
|
2559
|
+
const mountedUpdate = this.__mountDirective(config, payload, stops);
|
|
2560
|
+
if (!mountedUpdate) return;
|
|
2561
|
+
const emitChange = this.__createEmitter(
|
|
2562
|
+
payload,
|
|
2563
|
+
result,
|
|
2564
|
+
dynamicOption,
|
|
2565
|
+
option,
|
|
2566
|
+
mountedUpdate
|
|
2567
|
+
);
|
|
2568
|
+
emitChange();
|
|
2569
|
+
if (!config.once) {
|
|
2570
|
+
stops.result = result.subscribe(emitChange);
|
|
2571
|
+
if (dynamicOption) {
|
|
2572
|
+
stops.dynamic = dynamicOption.subscribe(emitChange);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
__parseDynamicOption(option, once) {
|
|
2577
|
+
const dynamicOptionExpression = isOptionDynamic(option, this.__dynamic);
|
|
2578
|
+
if (!dynamicOptionExpression) return void 0;
|
|
2579
|
+
return this.__parser.__parse(
|
|
2580
|
+
camelize(dynamicOptionExpression),
|
|
2581
|
+
void 0,
|
|
2582
|
+
void 0,
|
|
2583
|
+
void 0,
|
|
2584
|
+
once
|
|
2585
|
+
);
|
|
2586
|
+
}
|
|
2587
|
+
__parseExpression(config, valueExpression) {
|
|
2588
|
+
return this.__parser.__parse(
|
|
2247
2589
|
valueExpression,
|
|
2248
2590
|
config.isLazy,
|
|
2249
2591
|
config.isLazyKey,
|
|
2250
2592
|
config.collectRefObj,
|
|
2251
2593
|
config.once
|
|
2252
2594
|
);
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
const
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2595
|
+
}
|
|
2596
|
+
__createBindStops(result, dynamicOption) {
|
|
2597
|
+
const stops = {
|
|
2598
|
+
stop: () => {
|
|
2599
|
+
result.stop();
|
|
2600
|
+
dynamicOption?.stop();
|
|
2601
|
+
stops.result?.();
|
|
2602
|
+
stops.dynamic?.();
|
|
2603
|
+
stops.mounted?.();
|
|
2604
|
+
stops.result = void 0;
|
|
2605
|
+
stops.dynamic = void 0;
|
|
2606
|
+
stops.mounted = void 0;
|
|
2260
2607
|
}
|
|
2261
|
-
stopObserverList.length = 0;
|
|
2262
2608
|
};
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2609
|
+
return stops;
|
|
2610
|
+
}
|
|
2611
|
+
__createDirectivePayload(el, expr, result, dynamicOption, option, flags) {
|
|
2612
|
+
return {
|
|
2613
|
+
el,
|
|
2614
|
+
expr,
|
|
2615
|
+
values: result.value(),
|
|
2616
|
+
previousValues: void 0,
|
|
2617
|
+
option: dynamicOption ? dynamicOption.value()[0] : option,
|
|
2618
|
+
previousOption: void 0,
|
|
2619
|
+
flags,
|
|
2620
|
+
parseResult: result,
|
|
2621
|
+
dynamicOption
|
|
2622
|
+
};
|
|
2623
|
+
}
|
|
2624
|
+
__mountDirective(config, payload, stops) {
|
|
2625
|
+
const mounted = config.mount(payload);
|
|
2626
|
+
if (typeof mounted === "function") {
|
|
2627
|
+
stops.mounted = mounted;
|
|
2628
|
+
return void 0;
|
|
2274
2629
|
}
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
let previousValues = result.value();
|
|
2278
|
-
let previousOption = hasDynamicOption ? dynamicOption.value()[0] : option;
|
|
2279
|
-
if (!config.once && hasOnChange) {
|
|
2280
|
-
const stopObserving = result.subscribe ? result.subscribe(() => {
|
|
2281
|
-
const preValues = previousValues;
|
|
2282
|
-
const preOption = previousOption;
|
|
2283
|
-
const nextValues = result.value();
|
|
2284
|
-
const nextOption = hasDynamicOption ? dynamicOpt.value()[0] : option;
|
|
2285
|
-
previousValues = nextValues;
|
|
2286
|
-
previousOption = nextOption;
|
|
2287
|
-
config.onChange?.(
|
|
2288
|
-
el,
|
|
2289
|
-
nextValues,
|
|
2290
|
-
preValues,
|
|
2291
|
-
nextOption,
|
|
2292
|
-
preOption,
|
|
2293
|
-
flags
|
|
2294
|
-
);
|
|
2295
|
-
}) : () => {
|
|
2296
|
-
};
|
|
2297
|
-
stopObserverList.push(stopObserving);
|
|
2298
|
-
if (dynamicOpt) {
|
|
2299
|
-
const stopObserving2 = dynamicOpt.subscribe ? dynamicOpt.subscribe(() => {
|
|
2300
|
-
const preOption = previousOption;
|
|
2301
|
-
const nextValues = result.value();
|
|
2302
|
-
const nextOption = dynamicOpt.value()[0];
|
|
2303
|
-
previousValues = nextValues;
|
|
2304
|
-
previousOption = nextOption;
|
|
2305
|
-
config.onChange?.(
|
|
2306
|
-
el,
|
|
2307
|
-
nextValues,
|
|
2308
|
-
preOption,
|
|
2309
|
-
nextOption,
|
|
2310
|
-
preOption,
|
|
2311
|
-
flags
|
|
2312
|
-
);
|
|
2313
|
-
}) : () => {
|
|
2314
|
-
};
|
|
2315
|
-
stopObserverList.push(stopObserving2);
|
|
2316
|
-
}
|
|
2630
|
+
if (mounted?.unmount) {
|
|
2631
|
+
stops.mounted = mounted.unmount;
|
|
2317
2632
|
}
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
void 0,
|
|
2335
|
-
flags
|
|
2336
|
-
);
|
|
2633
|
+
return mounted?.update;
|
|
2634
|
+
}
|
|
2635
|
+
__createEmitter(payload, result, dynamicOption, option, mountedUpdate) {
|
|
2636
|
+
let previousValues;
|
|
2637
|
+
let previousOption;
|
|
2638
|
+
return () => {
|
|
2639
|
+
const nextValues = result.value();
|
|
2640
|
+
const nextOption = dynamicOption ? dynamicOption.value()[0] : option;
|
|
2641
|
+
payload.values = nextValues;
|
|
2642
|
+
payload.previousValues = previousValues;
|
|
2643
|
+
payload.option = nextOption;
|
|
2644
|
+
payload.previousOption = previousOption;
|
|
2645
|
+
previousValues = nextValues;
|
|
2646
|
+
previousOption = nextOption;
|
|
2647
|
+
mountedUpdate(payload);
|
|
2648
|
+
};
|
|
2337
2649
|
}
|
|
2338
2650
|
};
|
|
2339
2651
|
|
|
@@ -2370,38 +2682,50 @@ var Regor = (() => {
|
|
|
2370
2682
|
function includeBooleanAttr(value) {
|
|
2371
2683
|
return !!value || value === "";
|
|
2372
2684
|
}
|
|
2373
|
-
var
|
|
2374
|
-
|
|
2375
|
-
if (option)
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
const previousKey = p && key in p ? key : void 0;
|
|
2394
|
-
patchAttribute(el, key, value, previousKey);
|
|
2395
|
-
}
|
|
2396
|
-
} else {
|
|
2397
|
-
const previousKey = previousValues?.[i];
|
|
2398
|
-
const key = values[i++];
|
|
2399
|
-
const value = values[i];
|
|
2685
|
+
var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
|
|
2686
|
+
if (option) {
|
|
2687
|
+
if (flags && flags.includes("camel")) option = camelize(option);
|
|
2688
|
+
patchAttribute(el, option, values[0], previousOption);
|
|
2689
|
+
return;
|
|
2690
|
+
}
|
|
2691
|
+
const len = values.length;
|
|
2692
|
+
for (let i = 0; i < len; ++i) {
|
|
2693
|
+
const next = values[i];
|
|
2694
|
+
if (isArray(next)) {
|
|
2695
|
+
const previousKey = previousValues?.[i]?.[0];
|
|
2696
|
+
const key = next[0];
|
|
2697
|
+
const value = next[1];
|
|
2698
|
+
patchAttribute(el, key, value, previousKey);
|
|
2699
|
+
} else if (isObject(next)) {
|
|
2700
|
+
for (const item of Object.entries(next)) {
|
|
2701
|
+
const key = item[0];
|
|
2702
|
+
const value = item[1];
|
|
2703
|
+
const p = previousValues?.[i];
|
|
2704
|
+
const previousKey = p && key in p ? key : void 0;
|
|
2400
2705
|
patchAttribute(el, key, value, previousKey);
|
|
2401
2706
|
}
|
|
2707
|
+
} else {
|
|
2708
|
+
const previousKey = previousValues?.[i];
|
|
2709
|
+
const key = values[i++];
|
|
2710
|
+
const value = values[i];
|
|
2711
|
+
patchAttribute(el, key, value, previousKey);
|
|
2402
2712
|
}
|
|
2403
2713
|
}
|
|
2404
2714
|
};
|
|
2715
|
+
var attrDirective = {
|
|
2716
|
+
mount: () => ({
|
|
2717
|
+
update: ({ el, values, previousValues, option, previousOption, flags }) => {
|
|
2718
|
+
updateAttr(
|
|
2719
|
+
el,
|
|
2720
|
+
values,
|
|
2721
|
+
previousValues,
|
|
2722
|
+
option,
|
|
2723
|
+
previousOption,
|
|
2724
|
+
flags
|
|
2725
|
+
);
|
|
2726
|
+
}
|
|
2727
|
+
})
|
|
2728
|
+
};
|
|
2405
2729
|
var patchAttribute = (el, key, value, previousKey) => {
|
|
2406
2730
|
if (previousKey && previousKey !== key) {
|
|
2407
2731
|
el.removeAttribute(previousKey);
|
|
@@ -2435,23 +2759,28 @@ var Regor = (() => {
|
|
|
2435
2759
|
};
|
|
2436
2760
|
|
|
2437
2761
|
// src/directives/class.ts
|
|
2438
|
-
var
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
patchClass(el, next[j], previous?.[j]);
|
|
2448
|
-
}
|
|
2449
|
-
} else {
|
|
2450
|
-
patchClass(el, next, previous);
|
|
2762
|
+
var updateClass = (el, values, previousValues) => {
|
|
2763
|
+
const len = values.length;
|
|
2764
|
+
for (let i = 0; i < len; ++i) {
|
|
2765
|
+
const next = values[i];
|
|
2766
|
+
const previous = previousValues?.[i];
|
|
2767
|
+
if (isArray(next)) {
|
|
2768
|
+
const len2 = next.length;
|
|
2769
|
+
for (let j = 0; j < len2; ++j) {
|
|
2770
|
+
patchClass(el, next[j], previous?.[j]);
|
|
2451
2771
|
}
|
|
2772
|
+
} else {
|
|
2773
|
+
patchClass(el, next, previous);
|
|
2452
2774
|
}
|
|
2453
2775
|
}
|
|
2454
2776
|
};
|
|
2777
|
+
var classDirective = {
|
|
2778
|
+
mount: () => ({
|
|
2779
|
+
update: ({ el, values, previousValues }) => {
|
|
2780
|
+
updateClass(el, values, previousValues);
|
|
2781
|
+
}
|
|
2782
|
+
})
|
|
2783
|
+
};
|
|
2455
2784
|
var patchClass = (el, next, prev) => {
|
|
2456
2785
|
const classList = el.classList;
|
|
2457
2786
|
const isClassString = isString(next);
|
|
@@ -2479,15 +2808,6 @@ var Regor = (() => {
|
|
|
2479
2808
|
}
|
|
2480
2809
|
};
|
|
2481
2810
|
|
|
2482
|
-
// src/directives/html.ts
|
|
2483
|
-
var htmlDirective = {
|
|
2484
|
-
onChange: (el, values) => {
|
|
2485
|
-
const [value, replacer] = values;
|
|
2486
|
-
if (isFunction(replacer)) replacer(el, value);
|
|
2487
|
-
else el.innerHTML = value?.toString();
|
|
2488
|
-
}
|
|
2489
|
-
};
|
|
2490
|
-
|
|
2491
2811
|
// src/common/looseEqual.ts
|
|
2492
2812
|
function looseCompareArrays(a, b) {
|
|
2493
2813
|
if (a.length !== b.length) return false;
|
|
@@ -2560,12 +2880,12 @@ var Regor = (() => {
|
|
|
2560
2880
|
|
|
2561
2881
|
// src/directives/model.ts
|
|
2562
2882
|
var modelDirective = {
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
}
|
|
2883
|
+
mount: ({ el, parseResult, flags }) => ({
|
|
2884
|
+
update: ({ values }) => {
|
|
2885
|
+
updateDomElementValue(el, values[0]);
|
|
2886
|
+
},
|
|
2887
|
+
unmount: attachDOMChangeListener(el, parseResult, flags)
|
|
2888
|
+
})
|
|
2569
2889
|
};
|
|
2570
2890
|
var updateDomElementValue = (el, value) => {
|
|
2571
2891
|
const isAnInput = isInput(el);
|
|
@@ -2871,65 +3191,74 @@ var Regor = (() => {
|
|
|
2871
3191
|
}
|
|
2872
3192
|
return result;
|
|
2873
3193
|
};
|
|
3194
|
+
var bindOn = (el, parseResult, option, dynamicOption, flags) => {
|
|
3195
|
+
if (dynamicOption) {
|
|
3196
|
+
const values2 = parseResult.value();
|
|
3197
|
+
const option2 = unref(dynamicOption.value()[0]);
|
|
3198
|
+
if (!isString(option2)) return () => {
|
|
3199
|
+
};
|
|
3200
|
+
return attachEventListener(
|
|
3201
|
+
el,
|
|
3202
|
+
camelize(option2),
|
|
3203
|
+
() => parseResult.value()[0],
|
|
3204
|
+
flags?.join(",") ?? values2[1]
|
|
3205
|
+
);
|
|
3206
|
+
} else if (option) {
|
|
3207
|
+
const values2 = parseResult.value();
|
|
3208
|
+
return attachEventListener(
|
|
3209
|
+
el,
|
|
3210
|
+
camelize(option),
|
|
3211
|
+
() => parseResult.value()[0],
|
|
3212
|
+
flags?.join(",") ?? values2[1]
|
|
3213
|
+
);
|
|
3214
|
+
}
|
|
3215
|
+
const unbinders = [];
|
|
3216
|
+
const unbinder = () => {
|
|
3217
|
+
unbinders.forEach((x) => x());
|
|
3218
|
+
};
|
|
3219
|
+
const values = parseResult.value();
|
|
3220
|
+
const len = values.length;
|
|
3221
|
+
for (let i = 0; i < len; ++i) {
|
|
3222
|
+
let next = values[i];
|
|
3223
|
+
if (isFunction(next)) next = next();
|
|
3224
|
+
if (isObject(next)) {
|
|
3225
|
+
for (const item of Object.entries(next)) {
|
|
3226
|
+
const eventType = item[0];
|
|
3227
|
+
const method = () => {
|
|
3228
|
+
let obj = parseResult.value()[i];
|
|
3229
|
+
if (isFunction(obj)) obj = obj();
|
|
3230
|
+
obj = obj[eventType];
|
|
3231
|
+
if (isFunction(obj)) obj = obj();
|
|
3232
|
+
return obj;
|
|
3233
|
+
};
|
|
3234
|
+
const flags2 = next[eventType + "_flags"];
|
|
3235
|
+
unbinders.push(attachEventListener(el, eventType, method, flags2));
|
|
3236
|
+
}
|
|
3237
|
+
} else {
|
|
3238
|
+
warning(2 /* BindingRequiresObjectExpressions */, "r-on", el);
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
return unbinder;
|
|
3242
|
+
};
|
|
2874
3243
|
var onDirective = {
|
|
2875
3244
|
isLazy: (i, d) => d === -1 && i % 2 === 0,
|
|
2876
3245
|
isLazyKey: (key, d) => d === 0 && !key.endsWith("_flags"),
|
|
2877
3246
|
once: false,
|
|
2878
3247
|
collectRefObj: true,
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
camelize(option2),
|
|
2888
|
-
() => parseResult.value()[0],
|
|
2889
|
-
flags?.join(",") ?? values2[1]
|
|
2890
|
-
);
|
|
2891
|
-
} else if (option) {
|
|
2892
|
-
const values2 = parseResult.value();
|
|
2893
|
-
return attachEventListener(
|
|
2894
|
-
el,
|
|
2895
|
-
camelize(option),
|
|
2896
|
-
() => parseResult.value()[0],
|
|
2897
|
-
flags?.join(",") ?? values2[1]
|
|
2898
|
-
);
|
|
2899
|
-
}
|
|
2900
|
-
const unbinders = [];
|
|
2901
|
-
const unbinder = () => {
|
|
2902
|
-
unbinders.forEach((x) => x());
|
|
2903
|
-
};
|
|
2904
|
-
const values = parseResult.value();
|
|
2905
|
-
const len = values.length;
|
|
2906
|
-
for (let i = 0; i < len; ++i) {
|
|
2907
|
-
let next = values[i];
|
|
2908
|
-
if (isFunction(next)) next = next();
|
|
2909
|
-
if (isObject(next)) {
|
|
2910
|
-
for (const item of Object.entries(next)) {
|
|
2911
|
-
const eventType = item[0];
|
|
2912
|
-
const method = () => {
|
|
2913
|
-
let obj = parseResult.value()[i];
|
|
2914
|
-
if (isFunction(obj)) obj = obj();
|
|
2915
|
-
obj = obj[eventType];
|
|
2916
|
-
if (isFunction(obj)) obj = obj();
|
|
2917
|
-
return obj;
|
|
2918
|
-
};
|
|
2919
|
-
const flags2 = next[eventType + "_flags"];
|
|
2920
|
-
unbinders.push(attachEventListener(el, eventType, method, flags2));
|
|
2921
|
-
}
|
|
2922
|
-
} else {
|
|
2923
|
-
warning(2 /* BindingRequiresObjectExpressions */, "r-on", el);
|
|
2924
|
-
}
|
|
2925
|
-
}
|
|
2926
|
-
return unbinder;
|
|
3248
|
+
mount: ({ el, parseResult, option, dynamicOption, flags }) => {
|
|
3249
|
+
return bindOn(
|
|
3250
|
+
el,
|
|
3251
|
+
parseResult,
|
|
3252
|
+
option,
|
|
3253
|
+
dynamicOption,
|
|
3254
|
+
flags
|
|
3255
|
+
);
|
|
2927
3256
|
}
|
|
2928
3257
|
};
|
|
2929
3258
|
var getShouldExecuteEvent = (eventType, flags) => {
|
|
2930
3259
|
if (eventType.startsWith("keydown") || eventType.startsWith("keyup") || eventType.startsWith("keypress")) {
|
|
2931
3260
|
flags ??= "";
|
|
2932
|
-
const parts = eventType.split(".")
|
|
3261
|
+
const parts = [...eventType.split("."), ...flags.split(",")];
|
|
2933
3262
|
eventType = parts[0];
|
|
2934
3263
|
const keyType = parts[1];
|
|
2935
3264
|
const isCtrl = parts.includes("ctrl");
|
|
@@ -3002,34 +3331,39 @@ var Regor = (() => {
|
|
|
3002
3331
|
};
|
|
3003
3332
|
|
|
3004
3333
|
// src/directives/prop.ts
|
|
3005
|
-
var
|
|
3006
|
-
|
|
3007
|
-
if (option)
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
const value = item[1];
|
|
3023
|
-
patchProp(el, key, value);
|
|
3024
|
-
}
|
|
3025
|
-
} else {
|
|
3026
|
-
const key = values[i++];
|
|
3027
|
-
const value = values[i];
|
|
3334
|
+
var updatePropBinding = (el, values, option, flags) => {
|
|
3335
|
+
if (option) {
|
|
3336
|
+
if (flags && flags.includes("camel")) option = camelize(option);
|
|
3337
|
+
patchProp(el, option, values[0]);
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3340
|
+
const len = values.length;
|
|
3341
|
+
for (let i = 0; i < len; ++i) {
|
|
3342
|
+
const next = values[i];
|
|
3343
|
+
if (isArray(next)) {
|
|
3344
|
+
const key = next[0];
|
|
3345
|
+
const value = next[1];
|
|
3346
|
+
patchProp(el, key, value);
|
|
3347
|
+
} else if (isObject(next)) {
|
|
3348
|
+
for (const item of Object.entries(next)) {
|
|
3349
|
+
const key = item[0];
|
|
3350
|
+
const value = item[1];
|
|
3028
3351
|
patchProp(el, key, value);
|
|
3029
3352
|
}
|
|
3353
|
+
} else {
|
|
3354
|
+
const key = values[i++];
|
|
3355
|
+
const value = values[i];
|
|
3356
|
+
patchProp(el, key, value);
|
|
3030
3357
|
}
|
|
3031
3358
|
}
|
|
3032
3359
|
};
|
|
3360
|
+
var propDirective = {
|
|
3361
|
+
mount: () => ({
|
|
3362
|
+
update: ({ el, values, option, flags }) => {
|
|
3363
|
+
updatePropBinding(el, values, option, flags);
|
|
3364
|
+
}
|
|
3365
|
+
})
|
|
3366
|
+
};
|
|
3033
3367
|
function includeBooleanAttr2(value) {
|
|
3034
3368
|
return !!value || value === "";
|
|
3035
3369
|
}
|
|
@@ -3084,7 +3418,8 @@ var Regor = (() => {
|
|
|
3084
3418
|
// src/directives/ref.ts
|
|
3085
3419
|
var refDirective = {
|
|
3086
3420
|
once: true,
|
|
3087
|
-
|
|
3421
|
+
mount: ({ el, parseResult, expr }) => {
|
|
3422
|
+
const result = parseResult;
|
|
3088
3423
|
const value = result.value()[0];
|
|
3089
3424
|
const isAnArray = isArray(value);
|
|
3090
3425
|
const sref2 = result.refs[0];
|
|
@@ -3101,37 +3436,47 @@ var Regor = (() => {
|
|
|
3101
3436
|
};
|
|
3102
3437
|
|
|
3103
3438
|
// src/directives/show.ts
|
|
3439
|
+
var updateShow = (el, values) => {
|
|
3440
|
+
const data = getBindData(el).data;
|
|
3441
|
+
let originalDisplay = data._ord;
|
|
3442
|
+
if (isUndefined(originalDisplay)) {
|
|
3443
|
+
originalDisplay = data._ord = el.style.display;
|
|
3444
|
+
}
|
|
3445
|
+
const isVisible = !!values[0];
|
|
3446
|
+
if (isVisible) el.style.display = originalDisplay;
|
|
3447
|
+
else el.style.display = "none";
|
|
3448
|
+
};
|
|
3104
3449
|
var showDirective = {
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
if (isUndefined(originalDisplay)) {
|
|
3109
|
-
originalDisplay = data._ord = el.style.display;
|
|
3450
|
+
mount: () => ({
|
|
3451
|
+
update: ({ el, values }) => {
|
|
3452
|
+
updateShow(el, values);
|
|
3110
3453
|
}
|
|
3111
|
-
|
|
3112
|
-
if (isVisible) el.style.display = originalDisplay;
|
|
3113
|
-
else el.style.display = "none";
|
|
3114
|
-
}
|
|
3454
|
+
})
|
|
3115
3455
|
};
|
|
3116
3456
|
|
|
3117
3457
|
// src/directives/style.ts
|
|
3118
|
-
var
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
patchStyle(el, next[j], previous?.[j]);
|
|
3128
|
-
}
|
|
3129
|
-
} else {
|
|
3130
|
-
patchStyle(el, next, previous);
|
|
3458
|
+
var updateStyle = (el, values, previousValues) => {
|
|
3459
|
+
const len = values.length;
|
|
3460
|
+
for (let i = 0; i < len; ++i) {
|
|
3461
|
+
const next = values[i];
|
|
3462
|
+
const previous = previousValues?.[i];
|
|
3463
|
+
if (isArray(next)) {
|
|
3464
|
+
const len2 = next.length;
|
|
3465
|
+
for (let j = 0; j < len2; ++j) {
|
|
3466
|
+
patchStyle(el, next[j], previous?.[j]);
|
|
3131
3467
|
}
|
|
3468
|
+
} else {
|
|
3469
|
+
patchStyle(el, next, previous);
|
|
3132
3470
|
}
|
|
3133
3471
|
}
|
|
3134
3472
|
};
|
|
3473
|
+
var styleDirective = {
|
|
3474
|
+
mount: () => ({
|
|
3475
|
+
update: ({ el, values, previousValues }) => {
|
|
3476
|
+
updateStyle(el, values, previousValues);
|
|
3477
|
+
}
|
|
3478
|
+
})
|
|
3479
|
+
};
|
|
3135
3480
|
var patchStyle = (el, next, prev) => {
|
|
3136
3481
|
const style = el.style;
|
|
3137
3482
|
const isCssString = isString(next);
|
|
@@ -3239,18 +3584,25 @@ var Regor = (() => {
|
|
|
3239
3584
|
};
|
|
3240
3585
|
|
|
3241
3586
|
// src/directives/text.ts
|
|
3587
|
+
var updateText = (el, values) => {
|
|
3588
|
+
const value = values[0];
|
|
3589
|
+
el.textContent = isSet(value) ? JSON.stringify(flatten([...value])) : isMap(value) ? JSON.stringify(flatten([...value])) : isObject(value) ? JSON.stringify(flatten(value)) : value?.toString() ?? "";
|
|
3590
|
+
};
|
|
3242
3591
|
var textDirective = {
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3592
|
+
mount: () => ({
|
|
3593
|
+
update: ({ el, values }) => {
|
|
3594
|
+
updateText(el, values);
|
|
3595
|
+
}
|
|
3596
|
+
})
|
|
3247
3597
|
};
|
|
3248
3598
|
|
|
3249
3599
|
// src/directives/value.ts
|
|
3250
3600
|
var valueDirective = {
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3601
|
+
mount: () => ({
|
|
3602
|
+
update: ({ el, values }) => {
|
|
3603
|
+
patchProp(el, "value", values[0]);
|
|
3604
|
+
}
|
|
3605
|
+
})
|
|
3254
3606
|
};
|
|
3255
3607
|
|
|
3256
3608
|
// src/app/RegorConfig.ts
|
|
@@ -5054,6 +5406,7 @@ var Regor = (() => {
|
|
|
5054
5406
|
|
|
5055
5407
|
// src/parser/Parser.ts
|
|
5056
5408
|
var astCache = {};
|
|
5409
|
+
var isComponentMap = (value) => !!value;
|
|
5057
5410
|
var Parser = class {
|
|
5058
5411
|
__contexts;
|
|
5059
5412
|
__config;
|
|
@@ -5065,7 +5418,7 @@ var Regor = (() => {
|
|
|
5065
5418
|
this.__contexts = [context, ...this.__contexts];
|
|
5066
5419
|
}
|
|
5067
5420
|
__getComponents() {
|
|
5068
|
-
const obj = this.__contexts.map((x) => x.components).filter(
|
|
5421
|
+
const obj = this.__contexts.map((x) => x.components).filter(isComponentMap).reverse().reduce((p, c) => {
|
|
5069
5422
|
for (const [key, value] of Object.entries(c)) {
|
|
5070
5423
|
p[key.toUpperCase()] = value;
|
|
5071
5424
|
}
|
|
@@ -5076,7 +5429,7 @@ var Regor = (() => {
|
|
|
5076
5429
|
__getComponentSelectors() {
|
|
5077
5430
|
const selectors = [];
|
|
5078
5431
|
const seen = /* @__PURE__ */ new Set();
|
|
5079
|
-
const componentsList = this.__contexts.map((x) => x.components).filter(
|
|
5432
|
+
const componentsList = this.__contexts.map((x) => x.components).filter(isComponentMap).reverse();
|
|
5080
5433
|
for (const components of componentsList) {
|
|
5081
5434
|
for (const key of Object.keys(components)) {
|
|
5082
5435
|
if (seen.has(key)) continue;
|
|
@@ -5087,12 +5440,12 @@ var Regor = (() => {
|
|
|
5087
5440
|
return selectors;
|
|
5088
5441
|
}
|
|
5089
5442
|
__parse(expression, isLazy, isLazyKey, collectRefObj, once) {
|
|
5090
|
-
|
|
5443
|
+
let currentValues = [];
|
|
5091
5444
|
const stopObserverList = [];
|
|
5092
5445
|
const subscribers = /* @__PURE__ */ new Set();
|
|
5093
5446
|
const clearObservers = () => {
|
|
5094
|
-
for (
|
|
5095
|
-
|
|
5447
|
+
for (let i = 0; i < stopObserverList.length; ++i) {
|
|
5448
|
+
stopObserverList[i]();
|
|
5096
5449
|
}
|
|
5097
5450
|
stopObserverList.length = 0;
|
|
5098
5451
|
};
|
|
@@ -5102,13 +5455,13 @@ var Regor = (() => {
|
|
|
5102
5455
|
};
|
|
5103
5456
|
const subscribe = (observer, init) => {
|
|
5104
5457
|
subscribers.add(observer);
|
|
5105
|
-
if (init) observer(
|
|
5458
|
+
if (init) observer(currentValues);
|
|
5106
5459
|
return () => {
|
|
5107
5460
|
subscribers.delete(observer);
|
|
5108
5461
|
};
|
|
5109
5462
|
};
|
|
5110
5463
|
const result = {
|
|
5111
|
-
value,
|
|
5464
|
+
value: () => currentValues,
|
|
5112
5465
|
stop: unbinder,
|
|
5113
5466
|
subscribe,
|
|
5114
5467
|
refs: [],
|
|
@@ -5129,7 +5482,7 @@ var Regor = (() => {
|
|
|
5129
5482
|
context,
|
|
5130
5483
|
collectRefObj
|
|
5131
5484
|
);
|
|
5132
|
-
if (collectRefs2) refs.push(...r.refs);
|
|
5485
|
+
if (collectRefs2 && r.refs.length > 0) refs.push(...r.refs);
|
|
5133
5486
|
return { value: r.value, refs: r.refs, ref: r.ref };
|
|
5134
5487
|
} catch (e) {
|
|
5135
5488
|
warning(6 /* ErrorLog */, `evaluation error: ${expression}`, e);
|
|
@@ -5142,36 +5495,37 @@ var Regor = (() => {
|
|
|
5142
5495
|
const contexts = this.__contexts.slice();
|
|
5143
5496
|
const elements = ast.elements;
|
|
5144
5497
|
const len = elements.length;
|
|
5498
|
+
const expressionRefs = new Array(len);
|
|
5499
|
+
result.refs = expressionRefs;
|
|
5145
5500
|
const refresh = () => {
|
|
5146
5501
|
refs.length = 0;
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5502
|
+
if (!once) {
|
|
5503
|
+
uniqueRefs.clear();
|
|
5504
|
+
clearObservers();
|
|
5505
|
+
}
|
|
5506
|
+
const nextValues = new Array(len);
|
|
5151
5507
|
for (let i = 0; i < len; ++i) {
|
|
5152
5508
|
const expr = elements[i];
|
|
5153
5509
|
if (isLazy?.(i, -1)) {
|
|
5154
|
-
|
|
5510
|
+
nextValues[i] = (e) => evaluate(expr, contexts, false, { $event: e }).value;
|
|
5155
5511
|
continue;
|
|
5156
5512
|
}
|
|
5157
5513
|
const evaluated = evaluate(expr, contexts, true);
|
|
5158
|
-
|
|
5514
|
+
nextValues[i] = evaluated.value;
|
|
5159
5515
|
expressionRefs[i] = evaluated.ref;
|
|
5160
5516
|
}
|
|
5161
5517
|
if (!once) {
|
|
5162
5518
|
for (const r of refs) {
|
|
5163
5519
|
if (uniqueRefs.has(r)) continue;
|
|
5164
5520
|
uniqueRefs.add(r);
|
|
5165
|
-
|
|
5166
|
-
stopObserverList.push(stopObserving);
|
|
5521
|
+
stopObserverList.push(observe(r, refresh));
|
|
5167
5522
|
}
|
|
5168
5523
|
}
|
|
5169
|
-
|
|
5170
|
-
value(values);
|
|
5524
|
+
currentValues = nextValues;
|
|
5171
5525
|
if (subscribers.size !== 0) {
|
|
5172
5526
|
for (const subscriber of subscribers) {
|
|
5173
5527
|
if (!subscribers.has(subscriber)) continue;
|
|
5174
|
-
subscriber(
|
|
5528
|
+
subscriber(currentValues);
|
|
5175
5529
|
}
|
|
5176
5530
|
}
|
|
5177
5531
|
};
|
|
@@ -5480,8 +5834,8 @@ var Regor = (() => {
|
|
|
5480
5834
|
return json;
|
|
5481
5835
|
};
|
|
5482
5836
|
|
|
5483
|
-
// src/app/
|
|
5484
|
-
var
|
|
5837
|
+
// src/app/defineComponent.ts
|
|
5838
|
+
var defineComponent = (template, options = {}) => {
|
|
5485
5839
|
if (isArray(options)) options = { props: options };
|
|
5486
5840
|
if (isString(template)) template = { template };
|
|
5487
5841
|
const context = options.context ?? (() => ({}));
|