bobe 0.0.56 → 0.0.57
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 +139 -32
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +139 -32
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +141 -34
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +141 -34
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +30 -10
- package/dist/index.umd.js +139 -32
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/bobe.cjs.js
CHANGED
|
@@ -33,11 +33,12 @@ let FakeType = function (FakeType) {
|
|
|
33
33
|
FakeType[FakeType["Fragment"] = 32] = "Fragment";
|
|
34
34
|
FakeType[FakeType["ForItem"] = 64] = "ForItem";
|
|
35
35
|
FakeType[FakeType["Context"] = 128] = "Context";
|
|
36
|
+
FakeType[FakeType["DynamicText"] = 256] = "DynamicText";
|
|
36
37
|
return FakeType;
|
|
37
38
|
}({});
|
|
38
39
|
const CondBit = FakeType.If | FakeType.Fail | FakeType.Else;
|
|
39
40
|
const LogicalBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem;
|
|
40
|
-
FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment;
|
|
41
|
+
const CtxProviderBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment | FakeType.DynamicText;
|
|
41
42
|
const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context;
|
|
42
43
|
const TokenizerSwitcherBit = FakeType.Component | FakeType.Fragment;
|
|
43
44
|
let NodeSort = function (NodeSort) {
|
|
@@ -1418,6 +1419,17 @@ function macInc(arr) {
|
|
|
1418
1419
|
}
|
|
1419
1420
|
return candyLast;
|
|
1420
1421
|
}
|
|
1422
|
+
class InlineFragment {
|
|
1423
|
+
[aoye.Keys.ProxyFreeObject] = true;
|
|
1424
|
+
constructor(snapshot, data, key, tokenizer) {
|
|
1425
|
+
this.snapshot = snapshot;
|
|
1426
|
+
this.data = data;
|
|
1427
|
+
this.key = key;
|
|
1428
|
+
this.tokenizer = tokenizer;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
|
|
1432
|
+
const isRenderAble = val => aoye.isStore(val) || isUI(val) || val instanceof InlineFragment;
|
|
1421
1433
|
|
|
1422
1434
|
const KEY_INDEX = '__BOBE_KEY_INDEX';
|
|
1423
1435
|
let _ctxStack;
|
|
@@ -1474,7 +1486,7 @@ class Interpreter {
|
|
|
1474
1486
|
stack.push({
|
|
1475
1487
|
node: ctx.current,
|
|
1476
1488
|
prev: ctx.prevSibling
|
|
1477
|
-
}, !ctx.current.__logicType ? NodeSort.Real : (ctx.current.__logicType & LogicalBit ? NodeSort.Logic : 0) | (ctx.current.__logicType & TokenizerSwitcherBit ? NodeSort.TokenizerSwitcher : 0) | (ctx.current.__logicType & ContextBit ? NodeSort.Context : 0) | (ctx.current.__logicType === FakeType.Component ? NodeSort.Component : 0) | (ctx.current.__logicType
|
|
1489
|
+
}, !ctx.current.__logicType ? NodeSort.Real : (ctx.current.__logicType & LogicalBit ? NodeSort.Logic : 0) | (ctx.current.__logicType & TokenizerSwitcherBit ? NodeSort.TokenizerSwitcher : 0) | (ctx.current.__logicType & ContextBit ? NodeSort.Context : 0) | (ctx.current.__logicType === FakeType.Component ? NodeSort.Component : 0) | (ctx.current.__logicType & CtxProviderBit ? NodeSort.CtxProvider : 0));
|
|
1478
1490
|
if (ctx.current.__logicType) {
|
|
1479
1491
|
if (isLogicNode) {
|
|
1480
1492
|
aoye.setPulling(ctx.current.effect);
|
|
@@ -1608,21 +1620,14 @@ class Interpreter {
|
|
|
1608
1620
|
} else if (hookType) {
|
|
1609
1621
|
const data = this.getData();
|
|
1610
1622
|
if (hookType === 'static') {
|
|
1611
|
-
if (
|
|
1623
|
+
if (isRenderAble(value)) {
|
|
1612
1624
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1613
1625
|
} else {
|
|
1614
|
-
throw new SyntaxError(`declaration 不支持 ${value} 类型的静态插值`);
|
|
1615
|
-
}
|
|
1616
|
-
} else {
|
|
1617
|
-
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
1618
|
-
const val = data[aoye.Keys.Raw][value];
|
|
1619
|
-
if (typeof val === 'function' || val instanceof InlineFragment) {
|
|
1620
|
-
_node = this.componentOrFragmentDeclaration(val, ctx);
|
|
1621
|
-
} else {
|
|
1622
|
-
const str = valueIsMapKey ? value : this.getFn(data, value);
|
|
1623
1626
|
_node = this.createNode('text');
|
|
1624
|
-
|
|
1627
|
+
_node.text = String(value);
|
|
1625
1628
|
}
|
|
1629
|
+
} else {
|
|
1630
|
+
return this.dynamicDeclaration(data, value, ctx);
|
|
1626
1631
|
}
|
|
1627
1632
|
} else {
|
|
1628
1633
|
_node = this.createNode(value);
|
|
@@ -1640,6 +1645,96 @@ class Interpreter {
|
|
|
1640
1645
|
}
|
|
1641
1646
|
return _node;
|
|
1642
1647
|
}
|
|
1648
|
+
dynamicDeclaration(pData, value, ctx) {
|
|
1649
|
+
const valueIsMapKey = Reflect.has(pData[aoye.Keys.Raw], value);
|
|
1650
|
+
let node = {
|
|
1651
|
+
__logicType: null,
|
|
1652
|
+
realParent: null,
|
|
1653
|
+
tokenizer: null,
|
|
1654
|
+
effect: null,
|
|
1655
|
+
textNode: null,
|
|
1656
|
+
owner: ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node,
|
|
1657
|
+
snapshot: this.tokenizer.snapshot(['dentStack']),
|
|
1658
|
+
parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
|
|
1659
|
+
};
|
|
1660
|
+
let isUpdate = false;
|
|
1661
|
+
node.realAfter = this.insertAfterAnchor(`dynamic-after`);
|
|
1662
|
+
node.effect = this.effect(({
|
|
1663
|
+
old,
|
|
1664
|
+
val
|
|
1665
|
+
}) => {
|
|
1666
|
+
let oldLogicType = node.__logicType,
|
|
1667
|
+
oldTextNode = node.textNode;
|
|
1668
|
+
if (oldLogicType) {
|
|
1669
|
+
this.removeLogicNode(node);
|
|
1670
|
+
bobeShared.pickInPlace(node, ['realParent', 'realBefore', 'realAfter',, 'owner', 'snapshot', 'parentDataProvider']);
|
|
1671
|
+
}
|
|
1672
|
+
if (isRenderAble(val)) {
|
|
1673
|
+
if (oldTextNode) {
|
|
1674
|
+
this.remove(oldTextNode);
|
|
1675
|
+
}
|
|
1676
|
+
const info = this.createComponentData(val);
|
|
1677
|
+
info.__logicType;
|
|
1678
|
+
Object.assign(node, info);
|
|
1679
|
+
this.onePropParsed = info.onePropParsed;
|
|
1680
|
+
if (isUpdate) {
|
|
1681
|
+
this.tokenizer = node.owner.tokenizer;
|
|
1682
|
+
this.tokenizer.resume(node.snapshot);
|
|
1683
|
+
this.ctx.stack.push({
|
|
1684
|
+
node: node.parentDataProvider,
|
|
1685
|
+
prev: null
|
|
1686
|
+
}, NodeSort.CtxProvider);
|
|
1687
|
+
}
|
|
1688
|
+
this.tokenizer.nextToken();
|
|
1689
|
+
this.headerLineAndExtensions(node);
|
|
1690
|
+
if (isUpdate) {
|
|
1691
|
+
this.ctx.stack.pop();
|
|
1692
|
+
}
|
|
1693
|
+
this.onePropParsed = this.oneRealPropParsed;
|
|
1694
|
+
this.tokenizer = node.tokenizer;
|
|
1695
|
+
if (node.fragmentSnapshot) {
|
|
1696
|
+
this.tokenizer.resume(node.fragmentSnapshot);
|
|
1697
|
+
this.tokenizer.useDedentAsEof = true;
|
|
1698
|
+
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1699
|
+
}
|
|
1700
|
+
if (isUpdate) {
|
|
1701
|
+
this.program(node.realParent, node.owner, node.realBefore, node);
|
|
1702
|
+
}
|
|
1703
|
+
} else {
|
|
1704
|
+
node.__logicType = FakeType.DynamicText;
|
|
1705
|
+
let textNode = oldTextNode;
|
|
1706
|
+
const isNewTextNode = !textNode;
|
|
1707
|
+
if (isNewTextNode) {
|
|
1708
|
+
textNode = node.textNode = this.createNode('text');
|
|
1709
|
+
}
|
|
1710
|
+
textNode.text = String(val);
|
|
1711
|
+
if (isNewTextNode) {
|
|
1712
|
+
if (isUpdate) {
|
|
1713
|
+
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
1714
|
+
} else {
|
|
1715
|
+
this.tokenizer.nextToken();
|
|
1716
|
+
this.headerLineAndExtensions(node);
|
|
1717
|
+
const _this$ctx2 = this.ctx,
|
|
1718
|
+
realParent = _this$ctx2.realParent,
|
|
1719
|
+
prevSibling = _this$ctx2.prevSibling;
|
|
1720
|
+
this.handleInsert(realParent, textNode, prevSibling);
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
isUpdate = true;
|
|
1725
|
+
return isDestroy => {
|
|
1726
|
+
if (isDestroy) {
|
|
1727
|
+
this.removeLogicNode(node);
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
}, [() => {
|
|
1731
|
+
const val = valueIsMapKey ? pData[value] : this.getFn(pData, value)();
|
|
1732
|
+
return val;
|
|
1733
|
+
}], {
|
|
1734
|
+
type: 'render'
|
|
1735
|
+
});
|
|
1736
|
+
return node;
|
|
1737
|
+
}
|
|
1643
1738
|
createContextNode() {
|
|
1644
1739
|
const child = aoye.deepSignal({}, aoye.getPulling());
|
|
1645
1740
|
const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
|
|
@@ -2058,20 +2153,22 @@ class Interpreter {
|
|
|
2058
2153
|
}
|
|
2059
2154
|
}
|
|
2060
2155
|
oneRealPropParsed = this.onePropParsed.bind(this);
|
|
2061
|
-
|
|
2062
|
-
let
|
|
2156
|
+
createComponentData(ComponentOrRender) {
|
|
2157
|
+
let tokenizer, child, fragmentSnapshot, resumeSnapshot, __logicType;
|
|
2063
2158
|
const isCC = ComponentOrRender.prototype instanceof aoye.Store;
|
|
2064
2159
|
if (isCC) {
|
|
2065
|
-
Component = ComponentOrRender;
|
|
2160
|
+
const Component = ComponentOrRender;
|
|
2066
2161
|
child = Component.new();
|
|
2067
2162
|
tokenizer = child.ui(true);
|
|
2163
|
+
__logicType = FakeType.Component;
|
|
2068
2164
|
} else if (ComponentOrRender instanceof InlineFragment) {
|
|
2069
2165
|
const conf = ComponentOrRender;
|
|
2070
2166
|
child = aoye.deepSignal({}, aoye.getPulling(), true);
|
|
2071
2167
|
Object.setPrototypeOf(child, conf.data);
|
|
2072
2168
|
tokenizer = conf.tokenizer;
|
|
2073
2169
|
fragmentSnapshot = conf.snapshot;
|
|
2074
|
-
|
|
2170
|
+
__logicType = FakeType.Fragment;
|
|
2171
|
+
resumeSnapshot = tokenizer.snapshot(['dentStack', 'token', 'needIndent', 'isFirstToken', 'isFirstToken', 'useDedentAsEof']);
|
|
2075
2172
|
} else {
|
|
2076
2173
|
const render = ComponentOrRender;
|
|
2077
2174
|
const boundStore = render.boundStore;
|
|
@@ -2080,18 +2177,36 @@ class Interpreter {
|
|
|
2080
2177
|
Object.setPrototypeOf(child, boundStore);
|
|
2081
2178
|
}
|
|
2082
2179
|
tokenizer = render(true);
|
|
2180
|
+
__logicType = FakeType.Fragment;
|
|
2083
2181
|
}
|
|
2182
|
+
return {
|
|
2183
|
+
data: child,
|
|
2184
|
+
tokenizer,
|
|
2185
|
+
onePropParsed: createStoreOnePropParsed(child),
|
|
2186
|
+
fragmentSnapshot,
|
|
2187
|
+
resumeSnapshot,
|
|
2188
|
+
__logicType
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
componentOrFragmentDeclaration(ComponentOrRender, ctx) {
|
|
2192
|
+
const _this$createComponent = this.createComponentData(ComponentOrRender),
|
|
2193
|
+
data = _this$createComponent.data,
|
|
2194
|
+
tokenizer = _this$createComponent.tokenizer,
|
|
2195
|
+
onePropParsed = _this$createComponent.onePropParsed,
|
|
2196
|
+
fragmentSnapshot = _this$createComponent.fragmentSnapshot,
|
|
2197
|
+
resumeSnapshot = _this$createComponent.resumeSnapshot,
|
|
2198
|
+
__logicType = _this$createComponent.__logicType;
|
|
2084
2199
|
const node = {
|
|
2085
|
-
__logicType
|
|
2200
|
+
__logicType,
|
|
2086
2201
|
realParent: ctx.realParent,
|
|
2087
2202
|
realBefore: null,
|
|
2088
2203
|
realAfter: null,
|
|
2089
|
-
data
|
|
2204
|
+
data,
|
|
2090
2205
|
tokenizer,
|
|
2091
2206
|
fragmentSnapshot,
|
|
2092
2207
|
resumeSnapshot
|
|
2093
2208
|
};
|
|
2094
|
-
this.onePropParsed =
|
|
2209
|
+
this.onePropParsed = onePropParsed;
|
|
2095
2210
|
node.realAfter = this.insertAfterAnchor('component-after');
|
|
2096
2211
|
return node;
|
|
2097
2212
|
}
|
|
@@ -2274,7 +2389,7 @@ class Interpreter {
|
|
|
2274
2389
|
if (key === 'ref') {
|
|
2275
2390
|
const valueIsMapKey = Reflect.has(data[aoye.Keys.Raw], value);
|
|
2276
2391
|
let refValue = _node;
|
|
2277
|
-
if (_node.__logicType
|
|
2392
|
+
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
2278
2393
|
refValue = _node.data;
|
|
2279
2394
|
} else {
|
|
2280
2395
|
refValue[aoye.Keys.ProxyFreeObject] = true;
|
|
@@ -2300,8 +2415,8 @@ class Interpreter {
|
|
|
2300
2415
|
} else {
|
|
2301
2416
|
this.onePropParsed(data, _node, key, value, false, isFn, hookI);
|
|
2302
2417
|
}
|
|
2303
|
-
key =
|
|
2304
|
-
eq =
|
|
2418
|
+
key = undefined;
|
|
2419
|
+
eq = undefined;
|
|
2305
2420
|
}
|
|
2306
2421
|
this.tokenizer.nextToken();
|
|
2307
2422
|
}
|
|
@@ -2389,15 +2504,6 @@ function createStoreOnePropParsed(child) {
|
|
|
2389
2504
|
};
|
|
2390
2505
|
return onePropParsed;
|
|
2391
2506
|
}
|
|
2392
|
-
class InlineFragment {
|
|
2393
|
-
[aoye.Keys.ProxyFreeObject] = true;
|
|
2394
|
-
constructor(snapshot, data, key, tokenizer) {
|
|
2395
|
-
this.snapshot = snapshot;
|
|
2396
|
-
this.data = data;
|
|
2397
|
-
this.key = key;
|
|
2398
|
-
this.tokenizer = tokenizer;
|
|
2399
|
-
}
|
|
2400
|
-
}
|
|
2401
2507
|
|
|
2402
2508
|
function bobe(fragments, ...values) {
|
|
2403
2509
|
const ui = function ui(isSub) {
|
|
@@ -2410,6 +2516,7 @@ function bobe(fragments, ...values) {
|
|
|
2410
2516
|
return tokenizer;
|
|
2411
2517
|
};
|
|
2412
2518
|
ui.boundStore = aoye.Store.Current;
|
|
2519
|
+
ui.__BOBE_IS_UI = true;
|
|
2413
2520
|
return ui;
|
|
2414
2521
|
}
|
|
2415
2522
|
function customRender(option) {
|