bobe 0.0.53 → 0.0.56
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 +63 -13
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +63 -13
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +64 -15
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +64 -15
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +15 -16
- package/dist/index.umd.js +63 -13
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -11,10 +11,7 @@ declare class Interpreter {
|
|
|
11
11
|
ctx: ProgramCtx;
|
|
12
12
|
rootComponent: ComponentNode$1 | null;
|
|
13
13
|
program(root: any, componentNode?: ComponentNode$1, before?: any, ctxProvider?: any): ComponentNode$1;
|
|
14
|
-
insertAfterAnchor(name?: string):
|
|
15
|
-
name: string;
|
|
16
|
-
nextSibling: any;
|
|
17
|
-
};
|
|
14
|
+
insertAfterAnchor(name?: string): any;
|
|
18
15
|
/** 处理
|
|
19
16
|
* 是逻辑 是普通
|
|
20
17
|
* 父节点 将子节点加入 directList 调用 insert 方法挨个插入子节点
|
|
@@ -31,10 +28,16 @@ declare class Interpreter {
|
|
|
31
28
|
* */
|
|
32
29
|
declaration(ctx: ProgramCtx): any;
|
|
33
30
|
createContextNode(): ContextNode;
|
|
31
|
+
formatForCollection(collection: any): {
|
|
32
|
+
arr: any[];
|
|
33
|
+
keys: string[] | null;
|
|
34
|
+
};
|
|
34
35
|
forDeclaration(): ForNode | ForItemNode;
|
|
35
36
|
insertForItem(forNode: ForNode, i: number, parentData: any, newChildren: ForItemNode[], before: any, snapshotForUpdate: any): void;
|
|
36
37
|
removeForItem(children: ForItemNode[], i: number): void;
|
|
37
|
-
reuseForItem(child: ForItemNode, data: any, itemExp: string | ((value: any) => any), i: number, indexName?: string
|
|
38
|
+
reuseForItem(child: ForItemNode, data: any, itemExp: string | ((value: any) => any), i: number, indexName?: string,
|
|
39
|
+
/** Map/Set 等有 key 时,index 值为 key */
|
|
40
|
+
indexValue?: any): void;
|
|
38
41
|
forItemId: number;
|
|
39
42
|
createForItem(forNode: ForNode, i: number, parentData: any): ForItemNode;
|
|
40
43
|
getItemData(forNode: ForNode, i: number, parentData: any): Record<any, any>;
|
|
@@ -80,22 +83,15 @@ declare class Interpreter {
|
|
|
80
83
|
*/
|
|
81
84
|
attributeList(_node: any, data: any): string;
|
|
82
85
|
config(opt: TerpConf): void;
|
|
83
|
-
createNode(name: string):
|
|
84
|
-
name: string;
|
|
85
|
-
props: {};
|
|
86
|
-
nextSibling: any;
|
|
87
|
-
};
|
|
86
|
+
createNode(name: string): any;
|
|
88
87
|
nextSib(node: any): any;
|
|
89
88
|
firstChild(node: any): any;
|
|
90
|
-
createAnchor(name: string):
|
|
91
|
-
name: string;
|
|
92
|
-
nextSibling: any;
|
|
93
|
-
};
|
|
89
|
+
createAnchor(name: string): any;
|
|
94
90
|
insertAfter(parent: any, node: any, prev: any): void;
|
|
95
91
|
defaultInsert(parent: any, node: any, prev: any): void;
|
|
96
92
|
remove(node: any, parent?: any, prev?: any): void;
|
|
97
93
|
defaultRemove(node: any, parent: any, prevSibling: any): void;
|
|
98
|
-
setProp(node: any, key: string, value: any, hookI?: number):
|
|
94
|
+
setProp(node: any, key: string, value: any, hookI?: number): any | (() => void);
|
|
99
95
|
Effect: typeof Effect;
|
|
100
96
|
effect: typeof effect$1;
|
|
101
97
|
}
|
|
@@ -258,6 +254,9 @@ type ForNode = Omit<LogicNode, 'data'> & {
|
|
|
258
254
|
indexName?: string;
|
|
259
255
|
getKey?: (data: any) => any;
|
|
260
256
|
arr: any[];
|
|
257
|
+
/** 响应式版本:数组为 proxy、Map/Set 的 item 已被 deepSignal 包装 */
|
|
258
|
+
reactiveArr: any[];
|
|
259
|
+
keys: string[] | null;
|
|
261
260
|
arrSignal: Signal<any[]> | Computed<any[]>;
|
|
262
261
|
effect: Effect;
|
|
263
262
|
i: number;
|
|
@@ -568,5 +567,5 @@ declare const context: IContext;
|
|
|
568
567
|
|
|
569
568
|
declare const effect: (callback: (...args: ValueDiff[]) => void, depOrOpt?: Dep[] | Dep | CustomEffectOpt, opt?: CustomEffectOpt) => aoye.Effect;
|
|
570
569
|
|
|
571
|
-
export { Compiler, NodeType, ParseErrorCode, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
|
|
570
|
+
export { Compiler, FakeType, NodeType, ParseErrorCode, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
|
|
572
571
|
export type { ASTNodeType, BaseNode, CommentNode, ComponentNode, ConditionalNode, DynamicValue, ElementNode, FragmentNode, IContext, InterpolationNode, LoopNode, ParseError, Program, Property, PropertyKeyNode, PropertyValue, SourceLocation, StaticValue, TemplateNode, TextNode };
|
package/dist/index.umd.js
CHANGED
|
@@ -244,6 +244,7 @@
|
|
|
244
244
|
}
|
|
245
245
|
isEof() {
|
|
246
246
|
if (!this.token) return false;
|
|
247
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
247
248
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
248
249
|
}
|
|
249
250
|
setToken(type, value, dt = 1) {
|
|
@@ -1657,6 +1658,44 @@
|
|
|
1657
1658
|
node.realAfter = this.insertAfterAnchor('context-after');
|
|
1658
1659
|
return node;
|
|
1659
1660
|
}
|
|
1661
|
+
formatForCollection(collection) {
|
|
1662
|
+
const res = {
|
|
1663
|
+
arr: [],
|
|
1664
|
+
keys: null
|
|
1665
|
+
};
|
|
1666
|
+
if (Array.isArray(collection)) {
|
|
1667
|
+
res.arr = collection;
|
|
1668
|
+
return res;
|
|
1669
|
+
}
|
|
1670
|
+
if (collection instanceof Map) {
|
|
1671
|
+
res.keys = [];
|
|
1672
|
+
collection.forEach((v, k) => {
|
|
1673
|
+
res.arr.push(v);
|
|
1674
|
+
res.keys.push(k);
|
|
1675
|
+
});
|
|
1676
|
+
return res;
|
|
1677
|
+
}
|
|
1678
|
+
if (typeof collection === 'object' && collection !== null) {
|
|
1679
|
+
if (collection[Symbol.iterator]) {
|
|
1680
|
+
res.arr = Array.from(collection);
|
|
1681
|
+
return res;
|
|
1682
|
+
}
|
|
1683
|
+
res.arr = Object.values(collection);
|
|
1684
|
+
res.keys = Object.keys(collection);
|
|
1685
|
+
return res;
|
|
1686
|
+
}
|
|
1687
|
+
if (typeof collection === 'number') {
|
|
1688
|
+
res.arr = Array.from({
|
|
1689
|
+
length: collection
|
|
1690
|
+
});
|
|
1691
|
+
return res;
|
|
1692
|
+
}
|
|
1693
|
+
if (typeof collection === 'string') {
|
|
1694
|
+
res.arr = collection.split('');
|
|
1695
|
+
return res;
|
|
1696
|
+
}
|
|
1697
|
+
return res;
|
|
1698
|
+
}
|
|
1660
1699
|
forDeclaration() {
|
|
1661
1700
|
const arrExp = this.tokenizer.jsExp().value;
|
|
1662
1701
|
this.tokenizer.nextToken();
|
|
@@ -1693,6 +1732,8 @@
|
|
|
1693
1732
|
realBefore: prevSibling?.realAfter || prevSibling,
|
|
1694
1733
|
realAfter: null,
|
|
1695
1734
|
arr: null,
|
|
1735
|
+
reactiveArr: null,
|
|
1736
|
+
keys: null,
|
|
1696
1737
|
arrSignal: null,
|
|
1697
1738
|
itemExp,
|
|
1698
1739
|
indexName,
|
|
@@ -1719,11 +1760,17 @@
|
|
|
1719
1760
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1720
1761
|
let isFirstRender = true;
|
|
1721
1762
|
forNode.effect = new this.Effect(() => {
|
|
1722
|
-
|
|
1763
|
+
const collection = arrSignal.get();
|
|
1764
|
+
const _this$formatForCollec = this.formatForCollection(collection),
|
|
1765
|
+
formattedArr = _this$formatForCollec.arr,
|
|
1766
|
+
keys = _this$formatForCollec.keys;
|
|
1767
|
+
let arr = formattedArr;
|
|
1723
1768
|
arr[aoye.Keys.Iterator];
|
|
1724
1769
|
const prevCtx = aoye.getPulling();
|
|
1725
1770
|
aoye.setPulling(null);
|
|
1726
|
-
forNode.
|
|
1771
|
+
forNode.reactiveArr = formattedArr;
|
|
1772
|
+
forNode.arr = Array.isArray(collection) ? aoye.toRaw(arr) : arr;
|
|
1773
|
+
forNode.keys = keys;
|
|
1727
1774
|
const children = forNode.children;
|
|
1728
1775
|
if (isFirstRender) {
|
|
1729
1776
|
const len = arr.length;
|
|
@@ -1761,7 +1808,7 @@
|
|
|
1761
1808
|
for (let i = minLen; i--;) {
|
|
1762
1809
|
const child = children[i];
|
|
1763
1810
|
newChildren[i] = child;
|
|
1764
|
-
this.reuseForItem(child, arr[i], itemExp, i, indexName);
|
|
1811
|
+
this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
|
|
1765
1812
|
}
|
|
1766
1813
|
} else {
|
|
1767
1814
|
let s = 0,
|
|
@@ -1774,7 +1821,7 @@
|
|
|
1774
1821
|
const key = forNode.getKey(itemData);
|
|
1775
1822
|
if (old === key) {
|
|
1776
1823
|
newChildren[s] = child;
|
|
1777
|
-
this.reuseForItem(child, arr[s], itemExp, s, indexName);
|
|
1824
|
+
this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
|
|
1778
1825
|
s++;
|
|
1779
1826
|
} else {
|
|
1780
1827
|
break;
|
|
@@ -1787,7 +1834,7 @@
|
|
|
1787
1834
|
const key = forNode.getKey(itemData);
|
|
1788
1835
|
if (old === key) {
|
|
1789
1836
|
newChildren[e2] = child;
|
|
1790
|
-
this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
|
|
1837
|
+
this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
|
|
1791
1838
|
e1--;
|
|
1792
1839
|
e2--;
|
|
1793
1840
|
} else {
|
|
@@ -1829,7 +1876,7 @@
|
|
|
1829
1876
|
}
|
|
1830
1877
|
const child = children[i];
|
|
1831
1878
|
newChildren[newI] = child;
|
|
1832
|
-
this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
|
|
1879
|
+
this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
|
|
1833
1880
|
new2oldI[newI - s2] = i;
|
|
1834
1881
|
key2new.delete(key);
|
|
1835
1882
|
if (newI < maxIncNewI) {
|
|
@@ -1915,15 +1962,15 @@
|
|
|
1915
1962
|
this.remove(child.realAfter);
|
|
1916
1963
|
child.effect.dispose();
|
|
1917
1964
|
}
|
|
1918
|
-
reuseForItem(child, data, itemExp, i, indexName) {
|
|
1965
|
+
reuseForItem(child, data, itemExp, i, indexName, indexValue) {
|
|
1919
1966
|
if (typeof itemExp === 'string') {
|
|
1920
1967
|
child.data[itemExp] = data;
|
|
1921
1968
|
if (indexName) {
|
|
1922
|
-
child.data[indexName] = i;
|
|
1969
|
+
child.data[indexName] = indexValue ?? i;
|
|
1923
1970
|
}
|
|
1924
1971
|
} else {
|
|
1925
1972
|
indexName = indexName || KEY_INDEX;
|
|
1926
|
-
child.data[indexName] = i;
|
|
1973
|
+
child.data[indexName] = indexValue ?? i;
|
|
1927
1974
|
}
|
|
1928
1975
|
}
|
|
1929
1976
|
forItemId = 0;
|
|
@@ -1957,23 +2004,24 @@
|
|
|
1957
2004
|
itemExp = forNode.itemExp,
|
|
1958
2005
|
vars = forNode.vars,
|
|
1959
2006
|
arrSignal = forNode.arrSignal,
|
|
1960
|
-
getKey = forNode.getKey
|
|
2007
|
+
getKey = forNode.getKey,
|
|
2008
|
+
keys = forNode.keys;
|
|
1961
2009
|
let indexName = forNode.indexName;
|
|
1962
2010
|
let data;
|
|
1963
2011
|
if (typeof itemExp === 'string') {
|
|
1964
2012
|
data = aoye.deepSignal(indexName ? {
|
|
1965
2013
|
[itemExp]: arr[i],
|
|
1966
|
-
[indexName]: i
|
|
2014
|
+
[indexName]: keys?.[i] ?? i
|
|
1967
2015
|
} : {
|
|
1968
2016
|
[itemExp]: arr[i]
|
|
1969
2017
|
}, aoye.getPulling());
|
|
1970
2018
|
} else {
|
|
1971
2019
|
indexName = indexName ?? KEY_INDEX;
|
|
1972
2020
|
const rawData = {
|
|
1973
|
-
[indexName]: i
|
|
2021
|
+
[indexName]: keys?.[i] ?? i
|
|
1974
2022
|
};
|
|
1975
2023
|
data = aoye.deepSignal(rawData, aoye.getPulling());
|
|
1976
|
-
const computedData = new aoye.Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
|
|
2024
|
+
const computedData = new aoye.Computed(() => itemExp((arrSignal.get(), forNode.reactiveArr)[getKey ? data[indexName] : keys ? (data[indexName], i) : i]));
|
|
1977
2025
|
const cells = data[aoye.Keys.Meta].cells;
|
|
1978
2026
|
for (let i = 0; i < vars.length; i++) {
|
|
1979
2027
|
const name = vars[i];
|
|
@@ -2378,6 +2426,7 @@
|
|
|
2378
2426
|
tokenizer
|
|
2379
2427
|
};
|
|
2380
2428
|
terp.program(root, componentNode);
|
|
2429
|
+
aoye.flushMicroEffectManual();
|
|
2381
2430
|
return [componentNode, store];
|
|
2382
2431
|
};
|
|
2383
2432
|
}
|
|
@@ -2426,6 +2475,7 @@
|
|
|
2426
2475
|
get: function () { return aoye.Store; }
|
|
2427
2476
|
});
|
|
2428
2477
|
exports.Compiler = Compiler;
|
|
2478
|
+
exports.FakeType = FakeType;
|
|
2429
2479
|
exports.NodeType = NodeType;
|
|
2430
2480
|
exports.ParseSyntaxError = ParseSyntaxError;
|
|
2431
2481
|
exports.Tokenizer = Tokenizer;
|