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.esm.js CHANGED
@@ -1,5 +1,5 @@
1
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';
2
+ import { Signal, Computed, Keys, 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) {
@@ -242,6 +242,7 @@ class Tokenizer {
242
242
  }
243
243
  isEof() {
244
244
  if (!this.token) return false;
245
+ if (this.i >= this.code.length && !this.waitingTokens.len) return true;
245
246
  return this.token.type & TokenType.Identifier && this.token.value === Tokenizer.EofId;
246
247
  }
247
248
  setToken(type, value, dt = 1) {
@@ -1655,6 +1656,44 @@ class Interpreter {
1655
1656
  node.realAfter = this.insertAfterAnchor('context-after');
1656
1657
  return node;
1657
1658
  }
1659
+ formatForCollection(collection) {
1660
+ const res = {
1661
+ arr: [],
1662
+ keys: null
1663
+ };
1664
+ if (Array.isArray(collection)) {
1665
+ res.arr = collection;
1666
+ return res;
1667
+ }
1668
+ if (collection instanceof Map) {
1669
+ res.keys = [];
1670
+ collection.forEach((v, k) => {
1671
+ res.arr.push(v);
1672
+ res.keys.push(k);
1673
+ });
1674
+ return res;
1675
+ }
1676
+ if (typeof collection === 'object' && collection !== null) {
1677
+ if (collection[Symbol.iterator]) {
1678
+ res.arr = Array.from(collection);
1679
+ return res;
1680
+ }
1681
+ res.arr = Object.values(collection);
1682
+ res.keys = Object.keys(collection);
1683
+ return res;
1684
+ }
1685
+ if (typeof collection === 'number') {
1686
+ res.arr = Array.from({
1687
+ length: collection
1688
+ });
1689
+ return res;
1690
+ }
1691
+ if (typeof collection === 'string') {
1692
+ res.arr = collection.split('');
1693
+ return res;
1694
+ }
1695
+ return res;
1696
+ }
1658
1697
  forDeclaration() {
1659
1698
  const arrExp = this.tokenizer.jsExp().value;
1660
1699
  this.tokenizer.nextToken();
@@ -1691,6 +1730,8 @@ class Interpreter {
1691
1730
  realBefore: prevSibling?.realAfter || prevSibling,
1692
1731
  realAfter: null,
1693
1732
  arr: null,
1733
+ reactiveArr: null,
1734
+ keys: null,
1694
1735
  arrSignal: null,
1695
1736
  itemExp,
1696
1737
  indexName,
@@ -1717,11 +1758,17 @@ class Interpreter {
1717
1758
  const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
1718
1759
  let isFirstRender = true;
1719
1760
  forNode.effect = new this.Effect(() => {
1720
- let arr = arrSignal.get();
1761
+ const collection = arrSignal.get();
1762
+ const _this$formatForCollec = this.formatForCollection(collection),
1763
+ formattedArr = _this$formatForCollec.arr,
1764
+ keys = _this$formatForCollec.keys;
1765
+ let arr = formattedArr;
1721
1766
  arr[Keys.Iterator];
1722
1767
  const prevCtx = getPulling();
1723
1768
  setPulling(null);
1724
- forNode.arr = arr = toRaw(arr);
1769
+ forNode.reactiveArr = formattedArr;
1770
+ forNode.arr = Array.isArray(collection) ? toRaw(arr) : arr;
1771
+ forNode.keys = keys;
1725
1772
  const children = forNode.children;
1726
1773
  if (isFirstRender) {
1727
1774
  const len = arr.length;
@@ -1759,7 +1806,7 @@ class Interpreter {
1759
1806
  for (let i = minLen; i--;) {
1760
1807
  const child = children[i];
1761
1808
  newChildren[i] = child;
1762
- this.reuseForItem(child, arr[i], itemExp, i, indexName);
1809
+ this.reuseForItem(child, arr[i], itemExp, i, indexName, keys?.[i]);
1763
1810
  }
1764
1811
  } else {
1765
1812
  let s = 0,
@@ -1772,7 +1819,7 @@ class Interpreter {
1772
1819
  const key = forNode.getKey(itemData);
1773
1820
  if (old === key) {
1774
1821
  newChildren[s] = child;
1775
- this.reuseForItem(child, arr[s], itemExp, s, indexName);
1822
+ this.reuseForItem(child, arr[s], itemExp, s, indexName, keys?.[s]);
1776
1823
  s++;
1777
1824
  } else {
1778
1825
  break;
@@ -1785,7 +1832,7 @@ class Interpreter {
1785
1832
  const key = forNode.getKey(itemData);
1786
1833
  if (old === key) {
1787
1834
  newChildren[e2] = child;
1788
- this.reuseForItem(child, arr[e2], itemExp, e2, indexName);
1835
+ this.reuseForItem(child, arr[e2], itemExp, e2, indexName, keys?.[e2]);
1789
1836
  e1--;
1790
1837
  e2--;
1791
1838
  } else {
@@ -1827,7 +1874,7 @@ class Interpreter {
1827
1874
  }
1828
1875
  const child = children[i];
1829
1876
  newChildren[newI] = child;
1830
- this.reuseForItem(child, arr[newI], itemExp, newI, indexName);
1877
+ this.reuseForItem(child, arr[newI], itemExp, newI, indexName, keys?.[newI]);
1831
1878
  new2oldI[newI - s2] = i;
1832
1879
  key2new.delete(key);
1833
1880
  if (newI < maxIncNewI) {
@@ -1913,15 +1960,15 @@ class Interpreter {
1913
1960
  this.remove(child.realAfter);
1914
1961
  child.effect.dispose();
1915
1962
  }
1916
- reuseForItem(child, data, itemExp, i, indexName) {
1963
+ reuseForItem(child, data, itemExp, i, indexName, indexValue) {
1917
1964
  if (typeof itemExp === 'string') {
1918
1965
  child.data[itemExp] = data;
1919
1966
  if (indexName) {
1920
- child.data[indexName] = i;
1967
+ child.data[indexName] = indexValue ?? i;
1921
1968
  }
1922
1969
  } else {
1923
1970
  indexName = indexName || KEY_INDEX;
1924
- child.data[indexName] = i;
1971
+ child.data[indexName] = indexValue ?? i;
1925
1972
  }
1926
1973
  }
1927
1974
  forItemId = 0;
@@ -1955,23 +2002,24 @@ class Interpreter {
1955
2002
  itemExp = forNode.itemExp,
1956
2003
  vars = forNode.vars,
1957
2004
  arrSignal = forNode.arrSignal,
1958
- getKey = forNode.getKey;
2005
+ getKey = forNode.getKey,
2006
+ keys = forNode.keys;
1959
2007
  let indexName = forNode.indexName;
1960
2008
  let data;
1961
2009
  if (typeof itemExp === 'string') {
1962
2010
  data = deepSignal(indexName ? {
1963
2011
  [itemExp]: arr[i],
1964
- [indexName]: i
2012
+ [indexName]: keys?.[i] ?? i
1965
2013
  } : {
1966
2014
  [itemExp]: arr[i]
1967
2015
  }, getPulling());
1968
2016
  } else {
1969
2017
  indexName = indexName ?? KEY_INDEX;
1970
2018
  const rawData = {
1971
- [indexName]: i
2019
+ [indexName]: keys?.[i] ?? i
1972
2020
  };
1973
2021
  data = deepSignal(rawData, getPulling());
1974
- const computedData = new Computed(() => itemExp(arrSignal.get()[getKey ? data[indexName] : i]));
2022
+ const computedData = new Computed(() => itemExp((arrSignal.get(), forNode.reactiveArr)[getKey ? data[indexName] : keys ? (data[indexName], i) : i]));
1975
2023
  const cells = data[Keys.Meta].cells;
1976
2024
  for (let i = 0; i < vars.length; i++) {
1977
2025
  const name = vars[i];
@@ -2376,6 +2424,7 @@ function customRender(option) {
2376
2424
  tokenizer
2377
2425
  };
2378
2426
  terp.program(root, componentNode);
2427
+ flushMicroEffectManual();
2379
2428
  return [componentNode, store];
2380
2429
  };
2381
2430
  }
@@ -2419,5 +2468,5 @@ const effect = (callback, depOrOpt, opt) => {
2419
2468
  return effect$1(callback, newDeps, option);
2420
2469
  };
2421
2470
 
2422
- export { Compiler, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
2471
+ export { Compiler, FakeType, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
2423
2472
  //# sourceMappingURL=bobe.esm.js.map