bobe 0.0.52 → 0.0.54
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/bobe.cjs.js +60 -13
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +60 -13
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +60 -13
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +60 -13
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.umd.js +60 -13
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/bobe.esm.js
CHANGED
|
@@ -1655,6 +1655,44 @@ class Interpreter {
|
|
|
1655
1655
|
node.realAfter = this.insertAfterAnchor('context-after');
|
|
1656
1656
|
return node;
|
|
1657
1657
|
}
|
|
1658
|
+
formatForCollection(collection) {
|
|
1659
|
+
const res = {
|
|
1660
|
+
arr: [],
|
|
1661
|
+
keys: null
|
|
1662
|
+
};
|
|
1663
|
+
if (Array.isArray(collection)) {
|
|
1664
|
+
res.arr = collection;
|
|
1665
|
+
return res;
|
|
1666
|
+
}
|
|
1667
|
+
if (collection instanceof Map) {
|
|
1668
|
+
res.keys = [];
|
|
1669
|
+
collection.forEach((v, k) => {
|
|
1670
|
+
res.arr.push(v);
|
|
1671
|
+
res.keys.push(k);
|
|
1672
|
+
});
|
|
1673
|
+
return res;
|
|
1674
|
+
}
|
|
1675
|
+
if (typeof collection === 'object' && collection !== null) {
|
|
1676
|
+
if (collection[Symbol.iterator]) {
|
|
1677
|
+
res.arr = Array.from(collection);
|
|
1678
|
+
return res;
|
|
1679
|
+
}
|
|
1680
|
+
res.arr = Object.values(collection);
|
|
1681
|
+
res.keys = Object.keys(collection);
|
|
1682
|
+
return res;
|
|
1683
|
+
}
|
|
1684
|
+
if (typeof collection === 'number') {
|
|
1685
|
+
res.arr = Array.from({
|
|
1686
|
+
length: collection
|
|
1687
|
+
});
|
|
1688
|
+
return res;
|
|
1689
|
+
}
|
|
1690
|
+
if (typeof collection === 'string') {
|
|
1691
|
+
res.arr = collection.split('');
|
|
1692
|
+
return res;
|
|
1693
|
+
}
|
|
1694
|
+
return res;
|
|
1695
|
+
}
|
|
1658
1696
|
forDeclaration() {
|
|
1659
1697
|
const arrExp = this.tokenizer.jsExp().value;
|
|
1660
1698
|
this.tokenizer.nextToken();
|
|
@@ -1691,6 +1729,8 @@ class Interpreter {
|
|
|
1691
1729
|
realBefore: prevSibling?.realAfter || prevSibling,
|
|
1692
1730
|
realAfter: null,
|
|
1693
1731
|
arr: null,
|
|
1732
|
+
reactiveArr: null,
|
|
1733
|
+
keys: null,
|
|
1694
1734
|
arrSignal: null,
|
|
1695
1735
|
itemExp,
|
|
1696
1736
|
indexName,
|
|
@@ -1717,11 +1757,17 @@ class Interpreter {
|
|
|
1717
1757
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1718
1758
|
let isFirstRender = true;
|
|
1719
1759
|
forNode.effect = new this.Effect(() => {
|
|
1720
|
-
|
|
1760
|
+
const collection = arrSignal.get();
|
|
1761
|
+
const _this$formatForCollec = this.formatForCollection(collection),
|
|
1762
|
+
formattedArr = _this$formatForCollec.arr,
|
|
1763
|
+
keys = _this$formatForCollec.keys;
|
|
1764
|
+
let arr = formattedArr;
|
|
1721
1765
|
arr[Keys.Iterator];
|
|
1722
1766
|
const prevCtx = getPulling();
|
|
1723
1767
|
setPulling(null);
|
|
1724
|
-
forNode.
|
|
1768
|
+
forNode.reactiveArr = formattedArr;
|
|
1769
|
+
forNode.arr = Array.isArray(collection) ? toRaw(arr) : arr;
|
|
1770
|
+
forNode.keys = keys;
|
|
1725
1771
|
const children = forNode.children;
|
|
1726
1772
|
if (isFirstRender) {
|
|
1727
1773
|
const len = arr.length;
|
|
@@ -1759,7 +1805,7 @@ class Interpreter {
|
|
|
1759
1805
|
for (let i = minLen; i--;) {
|
|
1760
1806
|
const child = children[i];
|
|
1761
1807
|
newChildren[i] = child;
|
|
1762
|
-
this.reuseForItem(child, arr[i], itemExp, i, indexName);
|
|
1808
|
+
this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
|
|
1763
1809
|
}
|
|
1764
1810
|
} else {
|
|
1765
1811
|
let s = 0,
|
|
@@ -1772,7 +1818,7 @@ class Interpreter {
|
|
|
1772
1818
|
const key = forNode.getKey(itemData);
|
|
1773
1819
|
if (old === key) {
|
|
1774
1820
|
newChildren[s] = child;
|
|
1775
|
-
this.reuseForItem(child, arr[s], itemExp, s, indexName);
|
|
1821
|
+
this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
|
|
1776
1822
|
s++;
|
|
1777
1823
|
} else {
|
|
1778
1824
|
break;
|
|
@@ -1785,7 +1831,7 @@ class Interpreter {
|
|
|
1785
1831
|
const key = forNode.getKey(itemData);
|
|
1786
1832
|
if (old === key) {
|
|
1787
1833
|
newChildren[e2] = child;
|
|
1788
|
-
this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
|
|
1834
|
+
this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
|
|
1789
1835
|
e1--;
|
|
1790
1836
|
e2--;
|
|
1791
1837
|
} else {
|
|
@@ -1827,7 +1873,7 @@ class Interpreter {
|
|
|
1827
1873
|
}
|
|
1828
1874
|
const child = children[i];
|
|
1829
1875
|
newChildren[newI] = child;
|
|
1830
|
-
this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
|
|
1876
|
+
this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
|
|
1831
1877
|
new2oldI[newI - s2] = i;
|
|
1832
1878
|
key2new.delete(key);
|
|
1833
1879
|
if (newI < maxIncNewI) {
|
|
@@ -1913,15 +1959,15 @@ class Interpreter {
|
|
|
1913
1959
|
this.remove(child.realAfter);
|
|
1914
1960
|
child.effect.dispose();
|
|
1915
1961
|
}
|
|
1916
|
-
reuseForItem(child, data, itemExp, i, indexName) {
|
|
1962
|
+
reuseForItem(child, data, itemExp, i, indexName, indexValue) {
|
|
1917
1963
|
if (typeof itemExp === 'string') {
|
|
1918
1964
|
child.data[itemExp] = data;
|
|
1919
1965
|
if (indexName) {
|
|
1920
|
-
child.data[indexName] = i;
|
|
1966
|
+
child.data[indexName] = indexValue ?? i;
|
|
1921
1967
|
}
|
|
1922
1968
|
} else {
|
|
1923
1969
|
indexName = indexName || KEY_INDEX;
|
|
1924
|
-
child.data[indexName] = i;
|
|
1970
|
+
child.data[indexName] = indexValue ?? i;
|
|
1925
1971
|
}
|
|
1926
1972
|
}
|
|
1927
1973
|
forItemId = 0;
|
|
@@ -1955,23 +2001,24 @@ class Interpreter {
|
|
|
1955
2001
|
itemExp = forNode.itemExp,
|
|
1956
2002
|
vars = forNode.vars,
|
|
1957
2003
|
arrSignal = forNode.arrSignal,
|
|
1958
|
-
getKey = forNode.getKey
|
|
2004
|
+
getKey = forNode.getKey,
|
|
2005
|
+
keys = forNode.keys;
|
|
1959
2006
|
let indexName = forNode.indexName;
|
|
1960
2007
|
let data;
|
|
1961
2008
|
if (typeof itemExp === 'string') {
|
|
1962
2009
|
data = deepSignal(indexName ? {
|
|
1963
2010
|
[itemExp]: arr[i],
|
|
1964
|
-
[indexName]: i
|
|
2011
|
+
[indexName]: keys?.[i] ?? i
|
|
1965
2012
|
} : {
|
|
1966
2013
|
[itemExp]: arr[i]
|
|
1967
2014
|
}, getPulling());
|
|
1968
2015
|
} else {
|
|
1969
2016
|
indexName = indexName ?? KEY_INDEX;
|
|
1970
2017
|
const rawData = {
|
|
1971
|
-
[indexName]: i
|
|
2018
|
+
[indexName]: keys?.[i] ?? i
|
|
1972
2019
|
};
|
|
1973
2020
|
data = deepSignal(rawData, getPulling());
|
|
1974
|
-
const computedData = new Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
|
|
2021
|
+
const computedData = new Computed(() => itemExp((arrSignal.get(), forNode.reactiveArr)[getKey ? data[indexName] : keys ? (data[indexName], i) : i]));
|
|
1975
2022
|
const cells = data[Keys.Meta].cells;
|
|
1976
2023
|
for (let i = 0; i < vars.length; i++) {
|
|
1977
2024
|
const name = vars[i];
|