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.
@@ -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";
@@ -1476,9 +1477,6 @@ class Interpreter {
1476
1477
  constructor(tokenizer) {
1477
1478
  this.tokenizer = tokenizer;
1478
1479
  }
1479
- isLogicNode(node) {
1480
- return node && node.__logicType & LogicalBit;
1481
- }
1482
1480
  rootComponent = null;
1483
1481
  program(root, componentNode, before, ctxProvider) {
1484
1482
  this.rootComponent = componentNode;
@@ -1497,7 +1495,7 @@ class Interpreter {
1497
1495
  stack.push({
1498
1496
  node: ctxProvider,
1499
1497
  prev: null
1500
- }, (ctxProvider.__logicType & LogicalBit ? NodeSort.Logic : 0) | NodeSort.CtxProvider);
1498
+ }, (ctxProvider.__logicType && ctxProvider.effect ? NodeSort.EffectNode : 0) | NodeSort.CtxProvider);
1501
1499
  }
1502
1500
  const rootLen = stack.length;
1503
1501
  const ctx = this.ctx = {
@@ -1520,18 +1518,22 @@ class Interpreter {
1520
1518
  const token = this.tokenizer.token;
1521
1519
  if (token.type & TokenType.Indent) {
1522
1520
  this.tokenizer.nextToken();
1523
- const isLogicNode = this.isLogicNode(ctx.current);
1521
+ const isEffectNode = ctx.current && ctx.current.__logicType && ctx.current.effect;
1524
1522
  stack.push({
1525
1523
  node: ctx.current,
1526
1524
  prev: ctx.prevSibling
1527
- }, !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));
1525
+ }, !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));
1528
1526
  if (ctx.current.__logicType) {
1529
1527
  this.beforeLogicIndent?.(ctx.current);
1530
- if (isLogicNode) {
1528
+ if (isEffectNode) {
1531
1529
  aoye.setPulling(ctx.current.effect);
1532
1530
  if (ctx.current.__logicType & FakeType.ForItem) {
1533
1531
  ctx.prevSibling = ctx.current.realBefore;
1534
1532
  }
1533
+ if (ctx.current.__logicType & FakeType.Tp) {
1534
+ ctx.realParent = ctx.current.tpData[aoye.Keys.Raw].node;
1535
+ ctx.prevSibling = ctx.current.contentBefore;
1536
+ }
1535
1537
  }
1536
1538
  } else {
1537
1539
  if (ctx.current) {
@@ -1567,14 +1569,17 @@ class Interpreter {
1567
1569
  const prevSameType = stack.peekByType(NodeSort.Real);
1568
1570
  ctx.realParent = prevSameType?.node || root;
1569
1571
  } else {
1570
- if (sort & NodeSort.Logic) {
1571
- const parentLogic = stack.peekByType(NodeSort.Logic)?.node;
1572
+ if (sort & NodeSort.EffectNode) {
1573
+ const parentLogic = stack.peekByType(NodeSort.EffectNode)?.node;
1572
1574
  if (parentLogic) {
1573
1575
  aoye.setPulling(parentLogic.effect);
1574
1576
  } else {
1575
1577
  aoye.setPulling(rootPulling);
1576
1578
  }
1577
1579
  }
1580
+ if (parent.__logicType === FakeType.Tp) {
1581
+ ctx.realParent = parent.realParent;
1582
+ }
1578
1583
  if (sort & NodeSort.TokenizerSwitcher) {
1579
1584
  const switcher = stack.peekByType(NodeSort.TokenizerSwitcher)?.node;
1580
1585
  if (parent.resumeSnapshot) {
@@ -1611,13 +1616,17 @@ class Interpreter {
1611
1616
  }
1612
1617
  return componentNode;
1613
1618
  }
1614
- insertAnchor(name = 'anchor', isBefore = false) {
1619
+ insertAnchor(node, name = 'anchor', isBefore = false) {
1615
1620
  const _this$ctx = this.ctx,
1616
1621
  realParent = _this$ctx.realParent,
1617
1622
  prevSibling = _this$ctx.prevSibling,
1618
1623
  stack = _this$ctx.stack,
1619
1624
  before = _this$ctx.before;
1625
+ _this$ctx.current;
1620
1626
  const afterAnchor = this.createAnchor(name, isBefore);
1627
+ if (!isBefore) {
1628
+ this.anchorRefBack(afterAnchor, node);
1629
+ }
1621
1630
  this.ctx.prevSibling = stack.length === 2 && !prevSibling ? before : prevSibling;
1622
1631
  this.handleInsert(realParent, afterAnchor, prevSibling);
1623
1632
  return afterAnchor;
@@ -1662,6 +1671,8 @@ class Interpreter {
1662
1671
  return this.condDeclaration(ctx);
1663
1672
  } else if (value === 'context') {
1664
1673
  _node = this.createContextNode();
1674
+ } else if (value === 'tp') {
1675
+ return this.createTpNode();
1665
1676
  } else if (value === 'for') {
1666
1677
  return this.forDeclaration();
1667
1678
  } else if (hookType) {
@@ -1705,7 +1716,7 @@ class Interpreter {
1705
1716
  parentDataProvider: ctx.stack.peekByType(NodeSort.CtxProvider)?.node
1706
1717
  };
1707
1718
  let isUpdate = false;
1708
- node.realAfter = this.insertAnchor(`dynamic-after`);
1719
+ node.realAfter = this.insertAnchor(node, `dynamic-after`);
1709
1720
  node.effect = this.effect(({
1710
1721
  old,
1711
1722
  val
@@ -1785,6 +1796,93 @@ class Interpreter {
1785
1796
  });
1786
1797
  return node;
1787
1798
  }
1799
+ createTpNode() {
1800
+ const child = aoye.deepSignal({}, aoye.getPulling());
1801
+ const node = {
1802
+ __logicType: FakeType.Tp,
1803
+ data: this.getData(),
1804
+ realParent: null,
1805
+ realBefore: null,
1806
+ realAfter: null,
1807
+ contentBefore: null,
1808
+ contentAfter: null,
1809
+ effect: null,
1810
+ snapshot: null,
1811
+ tpData: child,
1812
+ owner: this.ctx.stack.peekByType(NodeSort.TokenizerSwitcher)?.node
1813
+ };
1814
+ this.onePropParsed = createStoreOnePropParsed(child);
1815
+ this.tokenizer.nextToken();
1816
+ this.headerLineAndExtensions(node);
1817
+ this.onePropParsed = this.oneRealPropParsed;
1818
+ node.realAfter = this.insertAnchor(node, 'tp-after');
1819
+ const before = node.contentBefore = this.createAnchor('tp-content-before', true);
1820
+ const after = node.contentAfter = this.createAnchor('tp-content-after', true);
1821
+ let firstRender = true;
1822
+ node.effect = this.effect(({
1823
+ old: oldDom,
1824
+ val: dom
1825
+ }) => {
1826
+ const removeTpChild = () => {
1827
+ if (oldDom) {
1828
+ let point = before;
1829
+ do {
1830
+ const next = this.nextSib(point);
1831
+ this.remove(point, oldDom, null);
1832
+ if (point === after) break;
1833
+ point = next;
1834
+ } while (true);
1835
+ }
1836
+ };
1837
+ if (firstRender) {
1838
+ if (dom) {
1839
+ this.handleInsert(dom, after, null);
1840
+ this.handleInsert(dom, before, null);
1841
+ } else {
1842
+ if (this.tokenizer.token.type === TokenType.Indent) {
1843
+ const dentLen = this.tokenizer.dentStack[this.tokenizer.dentStack.length - 2] ?? 0;
1844
+ this.tokenizer.skip(dentLen);
1845
+ }
1846
+ }
1847
+ } else {
1848
+ if (dom) {
1849
+ if (oldDom) {
1850
+ let point = before,
1851
+ lastInsert = null;
1852
+ do {
1853
+ const next = this.nextSib(point);
1854
+ const fakeNode = point[FakeNode];
1855
+ if (fakeNode) {
1856
+ fakeNode.realParent = dom;
1857
+ }
1858
+ this.handleInsert(dom, point, lastInsert);
1859
+ if (point === after) break;
1860
+ lastInsert = point;
1861
+ point = next;
1862
+ } while (true);
1863
+ } else {
1864
+ this.handleInsert(dom, after, null);
1865
+ this.handleInsert(dom, before, null);
1866
+ this.tokenizer = node.owner.tokenizer;
1867
+ this.tokenizer.resume(node.snapshot);
1868
+ this.tokenizer.useDedentAsEof = false;
1869
+ this.program(dom, node.owner, before, node);
1870
+ }
1871
+ } else {
1872
+ removeTpChild();
1873
+ }
1874
+ }
1875
+ firstRender = false;
1876
+ return isDestroy => {
1877
+ if (isDestroy) {
1878
+ removeTpChild();
1879
+ }
1880
+ };
1881
+ }, [() => child.node], {
1882
+ type: 'render'
1883
+ });
1884
+ return node;
1885
+ }
1788
1886
  createContextNode() {
1789
1887
  const child = aoye.deepSignal({}, aoye.getPulling());
1790
1888
  const parentContext = this.ctx.stack.peekByType(NodeSort.Context)?.node?.context;
@@ -1799,7 +1897,7 @@ class Interpreter {
1799
1897
  realBefore: null,
1800
1898
  realAfter: null
1801
1899
  };
1802
- node.realAfter = this.insertAnchor('context-after');
1900
+ node.realAfter = this.insertAnchor(node, 'context-after');
1803
1901
  return node;
1804
1902
  }
1805
1903
  formatForCollection(collection) {
@@ -1892,13 +1990,12 @@ class Interpreter {
1892
1990
  const rawGetKey = new Function('data', `with(data){return (${keyExp})}`);
1893
1991
  forNode.getKey = data => rawGetKey(safe(data));
1894
1992
  }
1895
- window['for1'] = forNode;
1896
1993
  const data = this.getData();
1897
1994
  const cells = data[aoye.Keys.Meta].cells;
1898
1995
  const hasArrExpKey = Reflect.has(data[aoye.Keys.Raw], arrExp);
1899
1996
  const arrSignal = hasArrExpKey ? (data[arrExp], cells.get(arrExp)) : new aoye.Computed(this.getFn(data, arrExp));
1900
1997
  forNode.arrSignal = arrSignal;
1901
- forNode.realAfter = this.insertAnchor('for-after');
1998
+ forNode.realAfter = this.insertAnchor(forNode, 'for-after');
1902
1999
  const _forNode$snapshot = forNode.snapshot;
1903
2000
  _forNode$snapshot.dentStack;
1904
2001
  _forNode$snapshot.isFirstToken;
@@ -1921,8 +2018,8 @@ class Interpreter {
1921
2018
  const len = arr.length;
1922
2019
  for (let i = len; i--;) {
1923
2020
  const item = this.createForItem(forNode, i, data);
1924
- item.realAfter = this.insertAnchor('for-item-after');
1925
- item.realBefore = this.insertAnchor('for-item-before', true);
2021
+ item.realAfter = this.insertAnchor(item, 'for-item-after');
2022
+ item.realBefore = this.insertAnchor(item, 'for-item-before', true);
1926
2023
  item.realParent = forNode.realParent;
1927
2024
  children[i] = item;
1928
2025
  }
@@ -2084,10 +2181,14 @@ class Interpreter {
2084
2181
  }, aoye.ScheduleType.Render);
2085
2182
  return forNode.children[0] || forNode;
2086
2183
  }
2184
+ anchorRefBack(anchor, node) {
2185
+ anchor[FakeNode] = node;
2186
+ }
2087
2187
  insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
2088
2188
  const item = this.createForItem(forNode, i, parentData);
2089
2189
  newChildren[i] = item;
2090
2190
  let realAfter = this.createAnchor('for-item-after');
2191
+ this.anchorRefBack(realAfter, item);
2091
2192
  this.handleInsert(forNode.realParent, realAfter, before);
2092
2193
  let realBefore = this.createAnchor('for-item-before', true);
2093
2194
  this.handleInsert(forNode.realParent, realBefore, before);
@@ -2258,7 +2359,7 @@ class Interpreter {
2258
2359
  resumeSnapshot
2259
2360
  };
2260
2361
  this.onePropParsed = onePropParsed;
2261
- node.realAfter = this.insertAnchor('component-after');
2362
+ node.realAfter = this.insertAnchor(node, 'component-after');
2262
2363
  return node;
2263
2364
  }
2264
2365
  getFn(data, expression) {
@@ -2353,7 +2454,7 @@ class Interpreter {
2353
2454
  break;
2354
2455
  }
2355
2456
  ifNode.condition = signal;
2356
- ifNode.realAfter = this.insertAnchor(`${keyWord.value}-after`);
2457
+ ifNode.realAfter = this.insertAnchor(ifNode, `${keyWord.value}-after`);
2357
2458
  const ef = this.effect(({
2358
2459
  val
2359
2460
  }) => {
@@ -2396,10 +2497,11 @@ class Interpreter {
2396
2497
  const tokenizer = this.tokenizer;
2397
2498
  do {
2398
2499
  const isComponent = _node.__logicType & TokenizerSwitcherBit;
2500
+ const isTp = _node.__logicType === FakeType.Tp;
2399
2501
  let snapshot, dentLen;
2400
2502
  const data = this.getData();
2401
2503
  const unHandledKey = this.attributeList(_node, data);
2402
- if (isComponent) {
2504
+ if (isComponent || isTp) {
2403
2505
  snapshot = tokenizer.snapshot(undefined, -1);
2404
2506
  dentLen = tokenizer.dentStack[tokenizer.dentStack.length - 1];
2405
2507
  }
@@ -2411,6 +2513,9 @@ class Interpreter {
2411
2513
  if ((tokenizer.token.type & TokenType.Pipe) === 0) {
2412
2514
  break;
2413
2515
  }
2516
+ } else if (isTp) {
2517
+ _node.snapshot = snapshot;
2518
+ break;
2414
2519
  } else {
2415
2520
  break;
2416
2521
  }