bobe 0.0.54 → 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 +142 -32
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +142 -32
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +144 -35
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +144 -35
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +35 -25
- package/dist/index.umd.js +142 -32
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/bobe.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Queue, isNum, matchIdStart2, matchId, escapeMap, jsVarRegexp, date32 } from 'bobe-shared';
|
|
2
|
-
import { Signal, Computed, Keys, getPulling, setPulling, deepSignal, toRaw, ScheduleType, runWithPulling, Scope, Store, noopEffect, NoopEffect, Effect, effect as effect$1, shareSignal } from 'aoye';
|
|
1
|
+
import { Queue, isNum, matchIdStart2, matchId, escapeMap, pickInPlace, jsVarRegexp, date32 } from 'bobe-shared';
|
|
2
|
+
import { Signal, Computed, Keys, isStore, getPulling, setPulling, deepSignal, toRaw, ScheduleType, runWithPulling, Scope, Store, noopEffect, NoopEffect, Effect, effect as effect$1, shareSignal, flushMicroEffectManual } from 'aoye';
|
|
3
3
|
export { Store } from 'aoye';
|
|
4
4
|
|
|
5
5
|
let TokenType = function (TokenType) {
|
|
@@ -32,11 +32,12 @@ let FakeType = function (FakeType) {
|
|
|
32
32
|
FakeType[FakeType["Fragment"] = 32] = "Fragment";
|
|
33
33
|
FakeType[FakeType["ForItem"] = 64] = "ForItem";
|
|
34
34
|
FakeType[FakeType["Context"] = 128] = "Context";
|
|
35
|
+
FakeType[FakeType["DynamicText"] = 256] = "DynamicText";
|
|
35
36
|
return FakeType;
|
|
36
37
|
}({});
|
|
37
38
|
const CondBit = FakeType.If | FakeType.Fail | FakeType.Else;
|
|
38
39
|
const LogicalBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem;
|
|
39
|
-
FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment;
|
|
40
|
+
const CtxProviderBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment | FakeType.DynamicText;
|
|
40
41
|
const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context;
|
|
41
42
|
const TokenizerSwitcherBit = FakeType.Component | FakeType.Fragment;
|
|
42
43
|
let NodeSort = function (NodeSort) {
|
|
@@ -242,6 +243,7 @@ class Tokenizer {
|
|
|
242
243
|
}
|
|
243
244
|
isEof() {
|
|
244
245
|
if (!this.token) return false;
|
|
246
|
+
if (this.i >= this.code.length && !this.waitingTokens.len) return true;
|
|
245
247
|
return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
|
|
246
248
|
}
|
|
247
249
|
setToken(type, value, dt = 1) {
|
|
@@ -1416,6 +1418,17 @@ function macInc(arr) {
|
|
|
1416
1418
|
}
|
|
1417
1419
|
return candyLast;
|
|
1418
1420
|
}
|
|
1421
|
+
class InlineFragment {
|
|
1422
|
+
[Keys.ProxyFreeObject] = true;
|
|
1423
|
+
constructor(snapshot, data, key, tokenizer) {
|
|
1424
|
+
this.snapshot = snapshot;
|
|
1425
|
+
this.data = data;
|
|
1426
|
+
this.key = key;
|
|
1427
|
+
this.tokenizer = tokenizer;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
const isUI = fn => typeof fn === 'function' && fn.__BOBE_IS_UI;
|
|
1431
|
+
const isRenderAble = val => isStore(val) || isUI(val) || val instanceof InlineFragment;
|
|
1419
1432
|
|
|
1420
1433
|
const KEY_INDEX = '__BOBE_KEY_INDEX';
|
|
1421
1434
|
let _ctxStack;
|
|
@@ -1472,7 +1485,7 @@ class Interpreter {
|
|
|
1472
1485
|
stack.push({
|
|
1473
1486
|
node: ctx.current,
|
|
1474
1487
|
prev: ctx.prevSibling
|
|
1475
|
-
}, !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
|
|
1488
|
+
}, !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));
|
|
1476
1489
|
if (ctx.current.__logicType) {
|
|
1477
1490
|
if (isLogicNode) {
|
|
1478
1491
|
setPulling(ctx.current.effect);
|
|
@@ -1606,21 +1619,14 @@ class Interpreter {
|
|
|
1606
1619
|
} else if (hookType) {
|
|
1607
1620
|
const data = this.getData();
|
|
1608
1621
|
if (hookType === 'static') {
|
|
1609
|
-
if (
|
|
1622
|
+
if (isRenderAble(value)) {
|
|
1610
1623
|
_node = this.componentOrFragmentDeclaration(value, ctx);
|
|
1611
1624
|
} else {
|
|
1612
|
-
throw new SyntaxError(`declaration 不支持 ${value} 类型的静态插值`);
|
|
1613
|
-
}
|
|
1614
|
-
} else {
|
|
1615
|
-
const valueIsMapKey = Reflect.has(data[Keys.Raw], value);
|
|
1616
|
-
const val = data[Keys.Raw][value];
|
|
1617
|
-
if (typeof val === 'function' || val instanceof InlineFragment) {
|
|
1618
|
-
_node = this.componentOrFragmentDeclaration(val, ctx);
|
|
1619
|
-
} else {
|
|
1620
|
-
const str = valueIsMapKey ? value : this.getFn(data, value);
|
|
1621
1625
|
_node = this.createNode('text');
|
|
1622
|
-
|
|
1626
|
+
_node.text = String(value);
|
|
1623
1627
|
}
|
|
1628
|
+
} else {
|
|
1629
|
+
return this.dynamicDeclaration(data, value, ctx);
|
|
1624
1630
|
}
|
|
1625
1631
|
} else {
|
|
1626
1632
|
_node = this.createNode(value);
|
|
@@ -1638,6 +1644,96 @@ class Interpreter {
|
|
|
1638
1644
|
}
|
|
1639
1645
|
return _node;
|
|
1640
1646
|
}
|
|
1647
|
+
dynamicDeclaration(pData, value, ctx) {
|
|
1648
|
+
const valueIsMapKey = Reflect.has(pData[Keys.Raw], value);
|
|
1649
|
+
let node = {
|
|
1650
|
+
__logicType: null,
|
|
1651
|
+
realParent: null,
|
|
1652
|
+
tokenizer: null,
|
|
1653
|
+
effect: null,
|
|
1654
|
+
textNode: null,
|
|
1655
|
+
owner: ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node,
|
|
1656
|
+
snapshot: this.tokenizer.snapshot(['dentStack']),
|
|
1657
|
+
parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
|
|
1658
|
+
};
|
|
1659
|
+
let isUpdate = false;
|
|
1660
|
+
node.realAfter = this.insertAfterAnchor(`dynamic-after`);
|
|
1661
|
+
node.effect = this.effect(({
|
|
1662
|
+
old,
|
|
1663
|
+
val
|
|
1664
|
+
}) => {
|
|
1665
|
+
let oldLogicType = node.__logicType,
|
|
1666
|
+
oldTextNode = node.textNode;
|
|
1667
|
+
if (oldLogicType) {
|
|
1668
|
+
this.removeLogicNode(node);
|
|
1669
|
+
pickInPlace(node, ['realParent', 'realBefore', 'realAfter',, 'owner', 'snapshot', 'parentDataProvider']);
|
|
1670
|
+
}
|
|
1671
|
+
if (isRenderAble(val)) {
|
|
1672
|
+
if (oldTextNode) {
|
|
1673
|
+
this.remove(oldTextNode);
|
|
1674
|
+
}
|
|
1675
|
+
const info = this.createComponentData(val);
|
|
1676
|
+
info.__logicType;
|
|
1677
|
+
Object.assign(node, info);
|
|
1678
|
+
this.onePropParsed = info.onePropParsed;
|
|
1679
|
+
if (isUpdate) {
|
|
1680
|
+
this.tokenizer = node.owner.tokenizer;
|
|
1681
|
+
this.tokenizer.resume(node.snapshot);
|
|
1682
|
+
this.ctx.stack.push({
|
|
1683
|
+
node: node.parentDataProvider,
|
|
1684
|
+
prev: null
|
|
1685
|
+
}, NodeSort.CtxProvider);
|
|
1686
|
+
}
|
|
1687
|
+
this.tokenizer.nextToken();
|
|
1688
|
+
this.headerLineAndExtensions(node);
|
|
1689
|
+
if (isUpdate) {
|
|
1690
|
+
this.ctx.stack.pop();
|
|
1691
|
+
}
|
|
1692
|
+
this.onePropParsed = this.oneRealPropParsed;
|
|
1693
|
+
this.tokenizer = node.tokenizer;
|
|
1694
|
+
if (node.fragmentSnapshot) {
|
|
1695
|
+
this.tokenizer.resume(node.fragmentSnapshot);
|
|
1696
|
+
this.tokenizer.useDedentAsEof = true;
|
|
1697
|
+
this.tokenizer.initIndentWhenUseDedentAsEof();
|
|
1698
|
+
}
|
|
1699
|
+
if (isUpdate) {
|
|
1700
|
+
this.program(node.realParent, node.owner, node.realBefore, node);
|
|
1701
|
+
}
|
|
1702
|
+
} else {
|
|
1703
|
+
node.__logicType = FakeType.DynamicText;
|
|
1704
|
+
let textNode = oldTextNode;
|
|
1705
|
+
const isNewTextNode = !textNode;
|
|
1706
|
+
if (isNewTextNode) {
|
|
1707
|
+
textNode = node.textNode = this.createNode('text');
|
|
1708
|
+
}
|
|
1709
|
+
textNode.text = String(val);
|
|
1710
|
+
if (isNewTextNode) {
|
|
1711
|
+
if (isUpdate) {
|
|
1712
|
+
this.handleInsert(node.realParent, textNode, node.realBefore);
|
|
1713
|
+
} else {
|
|
1714
|
+
this.tokenizer.nextToken();
|
|
1715
|
+
this.headerLineAndExtensions(node);
|
|
1716
|
+
const _this$ctx2 = this.ctx,
|
|
1717
|
+
realParent = _this$ctx2.realParent,
|
|
1718
|
+
prevSibling = _this$ctx2.prevSibling;
|
|
1719
|
+
this.handleInsert(realParent, textNode, prevSibling);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
isUpdate = true;
|
|
1724
|
+
return isDestroy => {
|
|
1725
|
+
if (isDestroy) {
|
|
1726
|
+
this.removeLogicNode(node);
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
}, [() => {
|
|
1730
|
+
const val = valueIsMapKey ? pData[value] : this.getFn(pData, value)();
|
|
1731
|
+
return val;
|
|
1732
|
+
}], {
|
|
1733
|
+
type: 'render'
|
|
1734
|
+
});
|
|
1735
|
+
return node;
|
|
1736
|
+
}
|
|
1641
1737
|
createContextNode() {
|
|
1642
1738
|
const child = deepSignal({}, getPulling());
|
|
1643
1739
|
const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
|
|
@@ -2056,20 +2152,22 @@ class Interpreter {
|
|
|
2056
2152
|
}
|
|
2057
2153
|
}
|
|
2058
2154
|
oneRealPropParsed = this.onePropParsed.bind(this);
|
|
2059
|
-
|
|
2060
|
-
let
|
|
2155
|
+
createComponentData(ComponentOrRender) {
|
|
2156
|
+
let tokenizer, child, fragmentSnapshot, resumeSnapshot, __logicType;
|
|
2061
2157
|
const isCC = ComponentOrRender.prototype instanceof Store;
|
|
2062
2158
|
if (isCC) {
|
|
2063
|
-
Component = ComponentOrRender;
|
|
2159
|
+
const Component = ComponentOrRender;
|
|
2064
2160
|
child = Component.new();
|
|
2065
2161
|
tokenizer = child.ui(true);
|
|
2162
|
+
__logicType = FakeType.Component;
|
|
2066
2163
|
} else if (ComponentOrRender instanceof InlineFragment) {
|
|
2067
2164
|
const conf = ComponentOrRender;
|
|
2068
2165
|
child = deepSignal({}, getPulling(), true);
|
|
2069
2166
|
Object.setPrototypeOf(child, conf.data);
|
|
2070
2167
|
tokenizer = conf.tokenizer;
|
|
2071
2168
|
fragmentSnapshot = conf.snapshot;
|
|
2072
|
-
|
|
2169
|
+
__logicType = FakeType.Fragment;
|
|
2170
|
+
resumeSnapshot = tokenizer.snapshot(['dentStack', 'token', 'needIndent', 'isFirstToken', 'isFirstToken', 'useDedentAsEof']);
|
|
2073
2171
|
} else {
|
|
2074
2172
|
const render = ComponentOrRender;
|
|
2075
2173
|
const boundStore = render.boundStore;
|
|
@@ -2078,18 +2176,36 @@ class Interpreter {
|
|
|
2078
2176
|
Object.setPrototypeOf(child, boundStore);
|
|
2079
2177
|
}
|
|
2080
2178
|
tokenizer = render(true);
|
|
2179
|
+
__logicType = FakeType.Fragment;
|
|
2081
2180
|
}
|
|
2181
|
+
return {
|
|
2182
|
+
data: child,
|
|
2183
|
+
tokenizer,
|
|
2184
|
+
onePropParsed: createStoreOnePropParsed(child),
|
|
2185
|
+
fragmentSnapshot,
|
|
2186
|
+
resumeSnapshot,
|
|
2187
|
+
__logicType
|
|
2188
|
+
};
|
|
2189
|
+
}
|
|
2190
|
+
componentOrFragmentDeclaration(ComponentOrRender, ctx) {
|
|
2191
|
+
const _this$createComponent = this.createComponentData(ComponentOrRender),
|
|
2192
|
+
data = _this$createComponent.data,
|
|
2193
|
+
tokenizer = _this$createComponent.tokenizer,
|
|
2194
|
+
onePropParsed = _this$createComponent.onePropParsed,
|
|
2195
|
+
fragmentSnapshot = _this$createComponent.fragmentSnapshot,
|
|
2196
|
+
resumeSnapshot = _this$createComponent.resumeSnapshot,
|
|
2197
|
+
__logicType = _this$createComponent.__logicType;
|
|
2082
2198
|
const node = {
|
|
2083
|
-
__logicType
|
|
2199
|
+
__logicType,
|
|
2084
2200
|
realParent: ctx.realParent,
|
|
2085
2201
|
realBefore: null,
|
|
2086
2202
|
realAfter: null,
|
|
2087
|
-
data
|
|
2203
|
+
data,
|
|
2088
2204
|
tokenizer,
|
|
2089
2205
|
fragmentSnapshot,
|
|
2090
2206
|
resumeSnapshot
|
|
2091
2207
|
};
|
|
2092
|
-
this.onePropParsed =
|
|
2208
|
+
this.onePropParsed = onePropParsed;
|
|
2093
2209
|
node.realAfter = this.insertAfterAnchor('component-after');
|
|
2094
2210
|
return node;
|
|
2095
2211
|
}
|
|
@@ -2272,7 +2388,7 @@ class Interpreter {
|
|
|
2272
2388
|
if (key === 'ref') {
|
|
2273
2389
|
const valueIsMapKey = Reflect.has(data[Keys.Raw], value);
|
|
2274
2390
|
let refValue = _node;
|
|
2275
|
-
if (_node.__logicType
|
|
2391
|
+
if (_node.__logicType & TokenizerSwitcherBit) {
|
|
2276
2392
|
refValue = _node.data;
|
|
2277
2393
|
} else {
|
|
2278
2394
|
refValue[Keys.ProxyFreeObject] = true;
|
|
@@ -2298,8 +2414,8 @@ class Interpreter {
|
|
|
2298
2414
|
} else {
|
|
2299
2415
|
this.onePropParsed(data, _node, key, value, false, isFn, hookI);
|
|
2300
2416
|
}
|
|
2301
|
-
key =
|
|
2302
|
-
eq =
|
|
2417
|
+
key = undefined;
|
|
2418
|
+
eq = undefined;
|
|
2303
2419
|
}
|
|
2304
2420
|
this.tokenizer.nextToken();
|
|
2305
2421
|
}
|
|
@@ -2387,15 +2503,6 @@ function createStoreOnePropParsed(child) {
|
|
|
2387
2503
|
};
|
|
2388
2504
|
return onePropParsed;
|
|
2389
2505
|
}
|
|
2390
|
-
class InlineFragment {
|
|
2391
|
-
[Keys.ProxyFreeObject] = true;
|
|
2392
|
-
constructor(snapshot, data, key, tokenizer) {
|
|
2393
|
-
this.snapshot = snapshot;
|
|
2394
|
-
this.data = data;
|
|
2395
|
-
this.key = key;
|
|
2396
|
-
this.tokenizer = tokenizer;
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
2506
|
|
|
2400
2507
|
function bobe(fragments, ...values) {
|
|
2401
2508
|
const ui = function ui(isSub) {
|
|
@@ -2408,6 +2515,7 @@ function bobe(fragments, ...values) {
|
|
|
2408
2515
|
return tokenizer;
|
|
2409
2516
|
};
|
|
2410
2517
|
ui.boundStore = Store.Current;
|
|
2518
|
+
ui.__BOBE_IS_UI = true;
|
|
2411
2519
|
return ui;
|
|
2412
2520
|
}
|
|
2413
2521
|
function customRender(option) {
|
|
@@ -2423,6 +2531,7 @@ function customRender(option) {
|
|
|
2423
2531
|
tokenizer
|
|
2424
2532
|
};
|
|
2425
2533
|
terp.program(root, componentNode);
|
|
2534
|
+
flushMicroEffectManual();
|
|
2426
2535
|
return [componentNode, store];
|
|
2427
2536
|
};
|
|
2428
2537
|
}
|
|
@@ -2466,5 +2575,5 @@ const effect = (callback, depOrOpt, opt) => {
|
|
|
2466
2575
|
return effect$1(callback, newDeps, option);
|
|
2467
2576
|
};
|
|
2468
2577
|
|
|
2469
|
-
export { Compiler, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
|
|
2578
|
+
export { Compiler, FakeType, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
|
|
2470
2579
|
//# sourceMappingURL=bobe.esm.js.map
|