bobe 0.0.60 → 0.0.61

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 CHANGED
@@ -34,15 +34,15 @@ let FakeType = function (FakeType) {
34
34
  FakeType[FakeType["ForItem"] = 64] = "ForItem";
35
35
  FakeType[FakeType["Context"] = 128] = "Context";
36
36
  FakeType[FakeType["DynamicText"] = 256] = "DynamicText";
37
+ FakeType[FakeType["Tp"] = 512] = "Tp";
37
38
  return FakeType;
38
39
  }({});
39
40
  const CondBit = FakeType.If | FakeType.Fail | FakeType.Else;
40
- const LogicalBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem;
41
41
  const CtxProviderBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.For | FakeType.ForItem | FakeType.Component | FakeType.Fragment | FakeType.DynamicText;
42
- const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context;
42
+ const ContextBit = FakeType.If | FakeType.Fail | FakeType.Else | FakeType.ForItem | FakeType.Context | FakeType.Tp;
43
43
  const TokenizerSwitcherBit = FakeType.Component | FakeType.Fragment;
44
44
  let NodeSort = function (NodeSort) {
45
- NodeSort[NodeSort["Logic"] = 1] = "Logic";
45
+ NodeSort[NodeSort["EffectNode"] = 1] = "EffectNode";
46
46
  NodeSort[NodeSort["Real"] = 2] = "Real";
47
47
  NodeSort[NodeSort["Component"] = 4] = "Component";
48
48
  NodeSort[NodeSort["CtxProvider"] = 8] = "CtxProvider";
@@ -55,6 +55,7 @@ let NodeSort = function (NodeSort) {
55
55
  TerpEvt["HandledComponentNode"] = "handled-component-node";
56
56
  return TerpEvt;
57
57
  })({});
58
+ const FakeNode = Symbol('fake-node');
58
59
  let ParseErrorCode = function (ParseErrorCode) {
59
60
  ParseErrorCode[ParseErrorCode["UNCLOSED_BRACE"] = 9001] = "UNCLOSED_BRACE";
60
61
  ParseErrorCode[ParseErrorCode["UNCLOSED_STRING"] = 9002] = "UNCLOSED_STRING";
@@ -1449,9 +1450,6 @@ class Interpreter {
1449
1450
  constructor(tokenizer) {
1450
1451
  this.tokenizer = tokenizer;
1451
1452
  }
1452
- isLogicNode(node) {
1453
- return node && node.__logicType & LogicalBit;
1454
- }
1455
1453
  rootComponent = null;
1456
1454
  program(root, componentNode, before, ctxProvider) {
1457
1455
  this.rootComponent = componentNode;
@@ -1470,7 +1468,7 @@ class Interpreter {
1470
1468
  stack.push({
1471
1469
  node: ctxProvider,
1472
1470
  prev: null
1473
- }, (ctxProvider.__logicType & LogicalBit ? NodeSort.Logic : 0) | NodeSort.CtxProvider);
1471
+ }, (ctxProvider.__logicType && ctxProvider.effect ? NodeSort.EffectNode : 0) | NodeSort.CtxProvider);
1474
1472
  }
1475
1473
  const rootLen = stack.length;
1476
1474
  const ctx = this.ctx = {
@@ -1493,18 +1491,22 @@ class Interpreter {
1493
1491
  const token = this.tokenizer.token;
1494
1492
  if (token.type & TokenType.Indent) {
1495
1493
  this.tokenizer.nextToken();
1496
- const isLogicNode = this.isLogicNode(ctx.current);
1494
+ const isEffectNode = ctx.current && ctx.current.__logicType && ctx.current.effect;
1497
1495
  stack.push({
1498
1496
  node: ctx.current,
1499
1497
  prev: ctx.prevSibling
1500
- }, !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));
1498
+ }, !ctx.current.__logicType ? NodeSort.Real : (isEffectNode ? NodeSort.EffectNode : 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));
1501
1499
  if (ctx.current.__logicType) {
1502
1500
  this.beforeLogicIndent?.(ctx.current);
1503
- if (isLogicNode) {
1501
+ if (isEffectNode) {
1504
1502
  aoye.setPulling(ctx.current.effect);
1505
1503
  if (ctx.current.__logicType & FakeType.ForItem) {
1506
1504
  ctx.prevSibling = ctx.current.realBefore;
1507
1505
  }
1506
+ if (ctx.current.__logicType & FakeType.Tp) {
1507
+ ctx.realParent = ctx.current.tpData[aoye.Keys.Raw].node;
1508
+ ctx.prevSibling = ctx.current.contentBefore;
1509
+ }
1508
1510
  }
1509
1511
  } else {
1510
1512
  if (ctx.current) {
@@ -1540,14 +1542,17 @@ class Interpreter {
1540
1542
  const prevSameType = stack.peekByType(NodeSort.Real);
1541
1543
  ctx.realParent = prevSameType?.node || root;
1542
1544
  } else {
1543
- if (sort & NodeSort.Logic) {
1544
- const parentLogic = stack.peekByType(NodeSort.Logic)?.node;
1545
+ if (sort & NodeSort.EffectNode) {
1546
+ const parentLogic = stack.peekByType(NodeSort.EffectNode)?.node;
1545
1547
  if (parentLogic) {
1546
1548
  aoye.setPulling(parentLogic.effect);
1547
1549
  } else {
1548
1550
  aoye.setPulling(rootPulling);
1549
1551
  }
1550
1552
  }
1553
+ if (parent.__logicType === FakeType.Tp) {
1554
+ ctx.realParent = parent.realParent;
1555
+ }
1551
1556
  if (sort & NodeSort.TokenizerSwitcher) {
1552
1557
  const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
1553
1558
  if (parent.resumeSnapshot) {
@@ -1584,13 +1589,17 @@ class Interpreter {
1584
1589
  }
1585
1590
  return componentNode;
1586
1591
  }
1587
- insertAnchor(name = 'anchor', isBefore = false) {
1592
+ insertAnchor(node, name = 'anchor', isBefore = false) {
1588
1593
  const _this$ctx = this.ctx,
1589
1594
  realParent = _this$ctx.realParent,
1590
1595
  prevSibling = _this$ctx.prevSibling,
1591
1596
  stack = _this$ctx.stack,
1592
1597
  before = _this$ctx.before;
1598
+ _this$ctx.current;
1593
1599
  const afterAnchor = this.createAnchor(name, isBefore);
1600
+ if (!isBefore) {
1601
+ this.anchorRefBack(afterAnchor, node);
1602
+ }
1594
1603
  this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
1595
1604
  this.handleInsert(realParent, afterAnchor, prevSibling);
1596
1605
  return afterAnchor;
@@ -1635,6 +1644,8 @@ class Interpreter {
1635
1644
  return this.condDeclaration(ctx);
1636
1645
  } else if (value === 'context') {
1637
1646
  _node = this.createContextNode();
1647
+ } else if (value === 'tp') {
1648
+ return this.createTpNode();
1638
1649
  } else if (value === 'for') {
1639
1650
  return this.forDeclaration();
1640
1651
  } else if (hookType) {
@@ -1678,7 +1689,7 @@ class Interpreter {
1678
1689
  parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
1679
1690
  };
1680
1691
  let isUpdate = false;
1681
- node.realAfter = this.insertAnchor(`dynamic-after`);
1692
+ node.realAfter = this.insertAnchor(node, `dynamic-after`);
1682
1693
  node.effect = this.effect(({
1683
1694
  old,
1684
1695
  val
@@ -1758,6 +1769,93 @@ class Interpreter {
1758
1769
  });
1759
1770
  return node;
1760
1771
  }
1772
+ createTpNode() {
1773
+ const child = aoye.deepSignal({}, aoye.getPulling());
1774
+ const node = {
1775
+ __logicType: FakeType.Tp,
1776
+ data: this.getData(),
1777
+ realParent: null,
1778
+ realBefore: null,
1779
+ realAfter: null,
1780
+ contentBefore: null,
1781
+ contentAfter: null,
1782
+ effect: null,
1783
+ snapshot: null,
1784
+ tpData: child,
1785
+ owner: this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node
1786
+ };
1787
+ this.onePropParsed = createStoreOnePropParsed(child);
1788
+ this.tokenizer.nextToken();
1789
+ this.headerLineAndExtensions(node);
1790
+ this.onePropParsed = this.oneRealPropParsed;
1791
+ node.realAfter = this.insertAnchor(node, 'tp-after');
1792
+ const before = node.contentBefore = this.createAnchor('tp-content-before', true);
1793
+ const after = node.contentAfter = this.createAnchor('tp-content-after', true);
1794
+ let firstRender = true;
1795
+ node.effect = this.effect(({
1796
+ old: oldDom,
1797
+ val: dom
1798
+ }) => {
1799
+ const removeTpChild = () => {
1800
+ if (oldDom) {
1801
+ let point = before;
1802
+ do {
1803
+ const next = this.nextSib(point);
1804
+ this.remove(point, oldDom, null);
1805
+ if (point === after) break;
1806
+ point = next;
1807
+ } while (true);
1808
+ }
1809
+ };
1810
+ if (firstRender) {
1811
+ if (dom) {
1812
+ this.handleInsert(dom, after, null);
1813
+ this.handleInsert(dom, before, null);
1814
+ } else {
1815
+ if (this.tokenizer.token.type === TokenType.Indent) {
1816
+ const dentLen = this.tokenizer.dentStack[this.tokenizer.dentStack.length - 2] ?? 0;
1817
+ this.tokenizer.skip(dentLen);
1818
+ }
1819
+ }
1820
+ } else {
1821
+ if (dom) {
1822
+ if (oldDom) {
1823
+ let point = before,
1824
+ lastInsert = null;
1825
+ do {
1826
+ const next = this.nextSib(point);
1827
+ const fakeNode = point[FakeNode];
1828
+ if (fakeNode) {
1829
+ fakeNode.realParent = dom;
1830
+ }
1831
+ this.handleInsert(dom, point, lastInsert);
1832
+ if (point === after) break;
1833
+ lastInsert = point;
1834
+ point = next;
1835
+ } while (true);
1836
+ } else {
1837
+ this.handleInsert(dom, after, null);
1838
+ this.handleInsert(dom, before, null);
1839
+ this.tokenizer = node.owner.tokenizer;
1840
+ this.tokenizer.resume(node.snapshot);
1841
+ this.tokenizer.useDedentAsEof = false;
1842
+ this.program(dom, node.owner, before, node);
1843
+ }
1844
+ } else {
1845
+ removeTpChild();
1846
+ }
1847
+ }
1848
+ firstRender = false;
1849
+ return isDestroy => {
1850
+ if (isDestroy) {
1851
+ removeTpChild();
1852
+ }
1853
+ };
1854
+ }, [() => child.node], {
1855
+ type: 'render'
1856
+ });
1857
+ return node;
1858
+ }
1761
1859
  createContextNode() {
1762
1860
  const child = aoye.deepSignal({}, aoye.getPulling());
1763
1861
  const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
@@ -1772,7 +1870,7 @@ class Interpreter {
1772
1870
  realBefore: null,
1773
1871
  realAfter: null
1774
1872
  };
1775
- node.realAfter = this.insertAnchor('context-after');
1873
+ node.realAfter = this.insertAnchor(node, 'context-after');
1776
1874
  return node;
1777
1875
  }
1778
1876
  formatForCollection(collection) {
@@ -1865,13 +1963,12 @@ class Interpreter {
1865
1963
  const rawGetKey = new Function('data', `with(data){return (${keyExp})}`);
1866
1964
  forNode.getKey = data => rawGetKey(safe(data));
1867
1965
  }
1868
- window['for1'] = forNode;
1869
1966
  const data = this.getData();
1870
1967
  const cells = data[aoye.Keys.Meta].cells;
1871
1968
  const hasArrExpKey = Reflect.has(data[aoye.Keys.Raw], arrExp);
1872
1969
  const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new aoye.Computed(this.getFn(data, arrExp));
1873
1970
  forNode.arrSignal = arrSignal;
1874
- forNode.realAfter = this.insertAnchor('for-after');
1971
+ forNode.realAfter = this.insertAnchor(forNode, 'for-after');
1875
1972
  const _forNode$snapshot = forNode.snapshot;
1876
1973
  _forNode$snapshot.dentStack;
1877
1974
  _forNode$snapshot.isFirstToken;
@@ -1894,8 +1991,8 @@ class Interpreter {
1894
1991
  const len = arr.length;
1895
1992
  for (let i = len; i--;) {
1896
1993
  const item = this.createForItem(forNode, i, data);
1897
- item.realAfter = this.insertAnchor('for-item-after');
1898
- item.realBefore = this.insertAnchor('for-item-before', true);
1994
+ item.realAfter = this.insertAnchor(item, 'for-item-after');
1995
+ item.realBefore = this.insertAnchor(item, 'for-item-before', true);
1899
1996
  item.realParent = forNode.realParent;
1900
1997
  children[i] = item;
1901
1998
  }
@@ -2057,10 +2154,14 @@ class Interpreter {
2057
2154
  }, aoye.ScheduleType.Render);
2058
2155
  return forNode.children[0] || forNode;
2059
2156
  }
2157
+ anchorRefBack(anchor, node) {
2158
+ anchor[FakeNode] = node;
2159
+ }
2060
2160
  insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
2061
2161
  const item = this.createForItem(forNode, i, parentData);
2062
2162
  newChildren[i] = item;
2063
2163
  let realAfter = this.createAnchor('for-item-after');
2164
+ this.anchorRefBack(realAfter, item);
2064
2165
  this.handleInsert(forNode.realParent, realAfter, before);
2065
2166
  let realBefore = this.createAnchor('for-item-before', true);
2066
2167
  this.handleInsert(forNode.realParent, realBefore, before);
@@ -2231,7 +2332,7 @@ class Interpreter {
2231
2332
  resumeSnapshot
2232
2333
  };
2233
2334
  this.onePropParsed = onePropParsed;
2234
- node.realAfter = this.insertAnchor('component-after');
2335
+ node.realAfter = this.insertAnchor(node, 'component-after');
2235
2336
  return node;
2236
2337
  }
2237
2338
  getFn(data, expression) {
@@ -2326,7 +2427,7 @@ class Interpreter {
2326
2427
  break;
2327
2428
  }
2328
2429
  ifNode.condition = signal;
2329
- ifNode.realAfter = this.insertAnchor(`${keyWord.value}-after`);
2430
+ ifNode.realAfter = this.insertAnchor(ifNode, `${keyWord.value}-after`);
2330
2431
  const ef = this.effect(({
2331
2432
  val
2332
2433
  }) => {
@@ -2369,10 +2470,11 @@ class Interpreter {
2369
2470
  const tokenizer = this.tokenizer;
2370
2471
  do {
2371
2472
  const isComponent = _node.__logicType & TokenizerSwitcherBit;
2473
+ const isTp = _node.__logicType === FakeType.Tp;
2372
2474
  let snapshot, dentLen;
2373
2475
  const data = this.getData();
2374
2476
  const unHandledKey = this.attributeList(_node, data);
2375
- if (isComponent) {
2477
+ if (isComponent || isTp) {
2376
2478
  snapshot = tokenizer.snapshot(undefined, -1);
2377
2479
  dentLen = tokenizer.dentStack[tokenizer.dentStack.length - 1];
2378
2480
  }
@@ -2384,6 +2486,9 @@ class Interpreter {
2384
2486
  if ((tokenizer.token.type & TokenType.Pipe) === 0) {
2385
2487
  break;
2386
2488
  }
2489
+ } else if (isTp) {
2490
+ _node.snapshot = snapshot;
2491
+ break;
2387
2492
  } else {
2388
2493
  break;
2389
2494
  }