@mantou/gem 1.6.17 → 1.6.19

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/gem.es.js CHANGED
@@ -1535,7 +1535,7 @@ var __privateSet$1 = (obj, member, value, setter) => {
1535
1535
  setter ? setter.call(obj, value) : member.set(obj, value);
1536
1536
  return value;
1537
1537
  };
1538
- var _renderRoot, _internals, _isAppendReason, _isAsync, _effectList, _momeList, _unmountCallback, _exec, _execEffect, _execMemo, _initEffect, _render, _shouldUpdate, _updateCallback, _update, _updated, _connectedCallback;
1538
+ var _renderRoot, _internals, _isAppendReason, _isMounted, _isAsync, _effectList, _memoList, _unmountCallback, _exec, _execEffect, _execMemo, _initEffect, _render, _shouldUpdate, _updateCallback, _update, _updated, _connectedCallback;
1539
1539
  function emptyFunction() {
1540
1540
  }
1541
1541
  function execCallback(fun) {
@@ -1552,6 +1552,7 @@ const tick = (timeStamp = performance.now()) => {
1552
1552
  }
1553
1553
  };
1554
1554
  asyncRenderTaskList.addEventListener("start", () => addMicrotask(tick));
1555
+ const constructorSymbol = Symbol("constructor");
1555
1556
  const initSymbol = Symbol("init");
1556
1557
  const updateSymbol = Symbol("update");
1557
1558
  class GemElement extends HTMLElement {
@@ -1560,9 +1561,10 @@ class GemElement extends HTMLElement {
1560
1561
  __privateAdd$1(this, _renderRoot, void 0);
1561
1562
  __privateAdd$1(this, _internals, void 0);
1562
1563
  __privateAdd$1(this, _isAppendReason, void 0);
1564
+ __privateAdd$1(this, _isMounted, void 0);
1563
1565
  __privateAdd$1(this, _isAsync, void 0);
1564
1566
  __privateAdd$1(this, _effectList, void 0);
1565
- __privateAdd$1(this, _momeList, void 0);
1567
+ __privateAdd$1(this, _memoList, void 0);
1566
1568
  __privateAdd$1(this, _unmountCallback, void 0);
1567
1569
  this.setState = (payload) => {
1568
1570
  if (!this.state)
@@ -1585,7 +1587,7 @@ class GemElement extends HTMLElement {
1585
1587
  __privateGet$1(this, _exec).call(this, __privateGet$1(this, _effectList));
1586
1588
  });
1587
1589
  __privateAdd$1(this, _execMemo, () => {
1588
- __privateGet$1(this, _exec).call(this, __privateGet$1(this, _momeList));
1590
+ __privateGet$1(this, _exec).call(this, __privateGet$1(this, _memoList));
1589
1591
  });
1590
1592
  this.effect = (callback, getDep) => {
1591
1593
  if (!__privateGet$1(this, _effectList))
@@ -1594,22 +1596,23 @@ class GemElement extends HTMLElement {
1594
1596
  callback,
1595
1597
  getDep,
1596
1598
  values: void 0,
1597
- initialized: !!this.isConnected
1599
+ initialized: __privateGet$1(this, _isMounted),
1600
+ inConstructor: this[constructorSymbol]
1598
1601
  };
1599
- if (this.isConnected) {
1602
+ if (__privateGet$1(this, _isMounted)) {
1600
1603
  effectItem.values = getDep == null ? void 0 : getDep();
1601
1604
  effectItem.preCallback = callback(effectItem.values);
1602
1605
  }
1603
1606
  __privateGet$1(this, _effectList).push(effectItem);
1604
1607
  };
1605
1608
  this.memo = (callback, getDep) => {
1606
- if (!__privateGet$1(this, _momeList))
1607
- __privateSet$1(this, _momeList, []);
1608
- __privateGet$1(this, _momeList).push({
1609
+ if (!__privateGet$1(this, _memoList))
1610
+ __privateSet$1(this, _memoList, []);
1611
+ __privateGet$1(this, _memoList).push({
1609
1612
  callback,
1610
1613
  getDep,
1611
1614
  values: [Symbol()],
1612
- initialized: this.isConnected
1615
+ inConstructor: this[constructorSymbol]
1613
1616
  });
1614
1617
  };
1615
1618
  __privateAdd$1(this, _initEffect, () => {
@@ -1641,7 +1644,7 @@ class GemElement extends HTMLElement {
1641
1644
  return this.shouldUpdate ? this.shouldUpdate() : true;
1642
1645
  });
1643
1646
  __privateAdd$1(this, _updateCallback, () => {
1644
- if (this.isConnected && __privateGet$1(this, _shouldUpdate).call(this)) {
1647
+ if (__privateGet$1(this, _isMounted) && __privateGet$1(this, _shouldUpdate).call(this)) {
1645
1648
  const temp = __privateGet$1(this, _render).call(this);
1646
1649
  temp !== void 0 && render(temp, __privateGet$1(this, _renderRoot));
1647
1650
  addMicrotask(__privateGet$1(this, _updated));
@@ -1664,6 +1667,7 @@ class GemElement extends HTMLElement {
1664
1667
  });
1665
1668
  __privateAdd$1(this, _connectedCallback, () => {
1666
1669
  var _a2, _b, _c;
1670
+ this[constructorSymbol] = false;
1667
1671
  if (__privateGet$1(this, _isAppendReason)) {
1668
1672
  __privateSet$1(this, _isAppendReason, false);
1669
1673
  return;
@@ -1675,16 +1679,18 @@ class GemElement extends HTMLElement {
1675
1679
  });
1676
1680
  const temp = __privateGet$1(this, _render).call(this);
1677
1681
  temp !== void 0 && render(temp, __privateGet$1(this, _renderRoot));
1682
+ __privateSet$1(this, _isMounted, true);
1678
1683
  __privateSet$1(this, _unmountCallback, (_b = this.mounted) == null ? void 0 : _b.call(this));
1679
1684
  __privateGet$1(this, _initEffect).call(this);
1680
1685
  if (rootElement2 && ((_c = this.getRootNode().host) == null ? void 0 : _c.tagName) !== rootElement2.toUpperCase()) {
1681
1686
  throw new GemError(`not allow current root type`);
1682
1687
  }
1683
1688
  });
1689
+ this[constructorSymbol] = true;
1684
1690
  addMicrotask(() => this[initSymbol] = false);
1685
1691
  this[initSymbol] = true;
1686
1692
  this[updateSymbol] = () => {
1687
- if (this.isConnected) {
1693
+ if (__privateGet$1(this, _isMounted)) {
1688
1694
  addMicrotask(__privateGet$1(this, _update));
1689
1695
  }
1690
1696
  };
@@ -1755,7 +1761,7 @@ class GemElement extends HTMLElement {
1755
1761
  return __privateGet$1(this, _internals);
1756
1762
  }
1757
1763
  attributeChangedCallback() {
1758
- if (this.isConnected) {
1764
+ if (__privateGet$1(this, _isMounted)) {
1759
1765
  addMicrotask(__privateGet$1(this, _update));
1760
1766
  }
1761
1767
  }
@@ -1785,11 +1791,12 @@ class GemElement extends HTMLElement {
1785
1791
  }
1786
1792
  }
1787
1793
  disconnectedCallback() {
1788
- var _a2, _b, _c;
1794
+ var _a2, _b, _c, _d;
1789
1795
  if (this.isConnected) {
1790
1796
  __privateSet$1(this, _isAppendReason, true);
1791
1797
  return;
1792
1798
  }
1799
+ __privateSet$1(this, _isMounted, false);
1793
1800
  const { observedStores } = this.constructor;
1794
1801
  observedStores == null ? void 0 : observedStores.forEach((store2) => {
1795
1802
  disconnect(store2, __privateGet$1(this, _update));
@@ -1799,15 +1806,17 @@ class GemElement extends HTMLElement {
1799
1806
  (_b = __privateGet$1(this, _effectList)) == null ? void 0 : _b.forEach((effectItem) => {
1800
1807
  execCallback(effectItem.preCallback);
1801
1808
  });
1802
- __privateSet$1(this, _momeList, (_c = __privateGet$1(this, _momeList)) == null ? void 0 : _c.filter(({ initialized }) => !initialized));
1809
+ __privateSet$1(this, _effectList, (_c = __privateGet$1(this, _effectList)) == null ? void 0 : _c.filter(({ inConstructor }) => inConstructor));
1810
+ __privateSet$1(this, _memoList, (_d = __privateGet$1(this, _memoList)) == null ? void 0 : _d.filter(({ inConstructor }) => inConstructor));
1803
1811
  }
1804
1812
  }
1805
1813
  _renderRoot = new WeakMap();
1806
1814
  _internals = new WeakMap();
1807
1815
  _isAppendReason = new WeakMap();
1816
+ _isMounted = new WeakMap();
1808
1817
  _isAsync = new WeakMap();
1809
1818
  _effectList = new WeakMap();
1810
- _momeList = new WeakMap();
1819
+ _memoList = new WeakMap();
1811
1820
  _unmountCallback = new WeakMap();
1812
1821
  _exec = new WeakMap();
1813
1822
  _execEffect = new WeakMap();
@@ -2059,13 +2068,13 @@ function validData(data) {
2059
2068
  if ($hasShouldCloseHandle)
2060
2069
  throw new GemError("`$hasShouldCloseHandle` is not allowed");
2061
2070
  }
2062
- function getUrlbarPath(internalPath) {
2071
+ function getUrlBarPath(internalPath) {
2063
2072
  return gemHistory.basePath ? gemHistory.basePath + internalPath : internalPath;
2064
2073
  }
2065
- function getInternalPath(urlbarPath) {
2066
- if (urlbarPath === gemHistory.basePath)
2074
+ function getInternalPath(urlBarPath) {
2075
+ if (urlBarPath === gemHistory.basePath)
2067
2076
  return "/";
2068
- return urlbarPath.replace(new RegExp(`^${gemHistory.basePath}/`), "/");
2077
+ return urlBarPath.replace(new RegExp(`^${gemHistory.basePath}/`), "/");
2069
2078
  }
2070
2079
  function normalizeParams(params) {
2071
2080
  const current = paramsMap.get(store.$key) || {};
@@ -2089,7 +2098,7 @@ function updateHistory(p, native) {
2089
2098
  }, data);
2090
2099
  paramsMap.set(state2.$key, params);
2091
2100
  updateStore(cleanObject(store), state2);
2092
- const url = getUrlbarPath(path) + new QueryString(query) + hash;
2101
+ const url = getUrlBarPath(path) + new QueryString(query) + hash;
2093
2102
  const prevHash = decodeURIComponent(location.hash);
2094
2103
  native(state2, title, url);
2095
2104
  if (prevHash !== hash)
@@ -2104,7 +2113,7 @@ function updateHistoryByNative(data, title, originUrl, native) {
2104
2113
  const params = normalizeParams({ path: pathname, query: new QueryString(search), hash, title, data });
2105
2114
  paramsMap.set(state2.$key, params);
2106
2115
  updateStore(cleanObject(store), state2);
2107
- const url = getUrlbarPath(pathname) + params.query + hash;
2116
+ const url = getUrlBarPath(pathname) + params.query + hash;
2108
2117
  const prevHash = location.hash;
2109
2118
  native(state2, title, url);
2110
2119
  if (prevHash !== hash)
@@ -2218,7 +2227,8 @@ if (!window._GEMHISTORY) {
2218
2227
  });
2219
2228
  }
2220
2229
  const prevState = store;
2221
- if (parseFloat(newState.$key) > parseFloat(prevState.$key) && newState.$hasOpenHandle) {
2230
+ const isForward = parseFloat(newState.$key) > parseFloat(prevState.$key);
2231
+ if (isForward && newState.$hasOpenHandle) {
2222
2232
  (_b = (_a2 = paramsMap.get(newState.$key)) == null ? void 0 : _a2.open) == null ? void 0 : _b.call(_a2);
2223
2233
  } else if (prevState.$hasCloseHandle) {
2224
2234
  const prevParams = paramsMap.get(prevState.$key);
@@ -2335,9 +2345,17 @@ let GemRouteElement = class extends GemElement {
2335
2345
  __privateSet2(this, _lastLoader, void 0);
2336
2346
  this.currentRoute = route;
2337
2347
  this.currentParams = params;
2338
- this.setState({ content });
2339
- this.routechange(this.currentRoute);
2340
- __privateGet2(this, _updateLocationStore).call(this);
2348
+ const changeContent = () => {
2349
+ this.setState({ content });
2350
+ this.routechange(this.currentRoute);
2351
+ __privateGet2(this, _updateLocationStore).call(this);
2352
+ return Promise.resolve();
2353
+ };
2354
+ if (this.transition && "startViewTransition" in document) {
2355
+ document.startViewTransition(changeContent);
2356
+ } else {
2357
+ changeContent();
2358
+ }
2341
2359
  });
2342
2360
  this.routes = routes;
2343
2361
  }
@@ -2423,6 +2441,9 @@ GemRouteElement.findRoute = (target = [], path) => {
2423
2441
  }
2424
2442
  return { route: defaultRoute };
2425
2443
  };
2444
+ __decorateClass$6([
2445
+ boolattribute
2446
+ ], GemRouteElement.prototype, "transition", 2);
2426
2447
  __decorateClass$6([
2427
2448
  property
2428
2449
  ], GemRouteElement.prototype, "routes", 2);
@@ -2949,7 +2970,7 @@ function replaceStyle(style, theme) {
2949
2970
  const themeStore = themeStoreMap.get(theme);
2950
2971
  const themeProp = themePropMap.get(theme);
2951
2972
  const rules = Object.keys(themeStore).reduce((prev, key2) => {
2952
- if (!themeStore[key2])
2973
+ if (!themeStore[key2] || !themeProp[key2])
2953
2974
  return prev;
2954
2975
  return prev + `${themeProp[key2]}:${themeStore[key2]};`;
2955
2976
  }, "");
@@ -3269,7 +3290,7 @@ const mediaQuery = {
3269
3290
  return matche(this.DATA_REDUCE);
3270
3291
  }
3271
3292
  };
3272
- const version = "1.6.17";
3293
+ const version = "1.6.19";
3273
3294
  if (window.__GEM_DEVTOOLS__HOOK__) {
3274
3295
  Object.assign(window.__GEM_DEVTOOLS__HOOK__, __spreadValues({}, Gem));
3275
3296
  }