@mantou/gem 1.6.18 → 1.7.0

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.
Files changed (42) hide show
  1. package/dist/gem.es.js +54 -44
  2. package/dist/gem.umd.js +22 -22
  3. package/elements/base/modal-factory.d.ts +18 -15
  4. package/elements/base/modal-factory.d.ts.map +1 -1
  5. package/elements/base/reflect.d.ts.map +1 -1
  6. package/elements/base/reflect.js +1 -3
  7. package/elements/base/reflect.js.map +1 -1
  8. package/elements/base/route.d.ts +1 -0
  9. package/elements/base/route.d.ts.map +1 -1
  10. package/elements/base/route.js +16 -4
  11. package/elements/base/route.js.map +1 -1
  12. package/elements/base/title.d.ts +1 -1
  13. package/elements/base/title.js +1 -1
  14. package/helper/i18n.js.map +1 -1
  15. package/lib/decorators.d.ts +1 -1
  16. package/lib/decorators.js +3 -3
  17. package/lib/decorators.js.map +1 -1
  18. package/lib/element.d.ts +4 -5
  19. package/lib/element.d.ts.map +1 -1
  20. package/lib/element.js +31 -33
  21. package/lib/element.js.map +1 -1
  22. package/lib/history.js +8 -7
  23. package/lib/history.js.map +1 -1
  24. package/lib/utils.js.map +1 -1
  25. package/lib/version.d.ts +1 -1
  26. package/lib/version.d.ts.map +1 -1
  27. package/lib/version.js +1 -1
  28. package/lib/version.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/elements/base/reflect.ts +1 -4
  31. package/src/elements/base/route.ts +16 -7
  32. package/src/elements/base/title.ts +1 -1
  33. package/src/helper/i18n.ts +1 -1
  34. package/src/lib/decorators.ts +3 -3
  35. package/src/lib/element.ts +35 -41
  36. package/src/lib/history.ts +10 -10
  37. package/src/lib/utils.ts +1 -1
  38. package/src/lib/version.ts +1 -1
  39. package/src/test/gem-element/advance.test.ts +8 -8
  40. package/src/test/gem-element/basic.test.ts +1 -1
  41. package/src/test/gem-element/decorators.test.ts +1 -1
  42. package/src/test/history.test.ts +1 -1
package/dist/gem.es.js CHANGED
@@ -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 {
@@ -1595,7 +1596,8 @@ class GemElement extends HTMLElement {
1595
1596
  callback,
1596
1597
  getDep,
1597
1598
  values: void 0,
1598
- initialized: !!__privateGet$1(this, _isMounted)
1599
+ initialized: __privateGet$1(this, _isMounted),
1600
+ inConstructor: this[constructorSymbol]
1599
1601
  };
1600
1602
  if (__privateGet$1(this, _isMounted)) {
1601
1603
  effectItem.values = getDep == null ? void 0 : getDep();
@@ -1610,7 +1612,7 @@ class GemElement extends HTMLElement {
1610
1612
  callback,
1611
1613
  getDep,
1612
1614
  values: [Symbol()],
1613
- initialized: !!__privateGet$1(this, _isMounted)
1615
+ inConstructor: this[constructorSymbol]
1614
1616
  });
1615
1617
  };
1616
1618
  __privateAdd$1(this, _initEffect, () => {
@@ -1665,6 +1667,7 @@ class GemElement extends HTMLElement {
1665
1667
  });
1666
1668
  __privateAdd$1(this, _connectedCallback, () => {
1667
1669
  var _a2, _b, _c;
1670
+ this[constructorSymbol] = false;
1668
1671
  if (__privateGet$1(this, _isAppendReason)) {
1669
1672
  __privateSet$1(this, _isAppendReason, false);
1670
1673
  return;
@@ -1683,6 +1686,7 @@ class GemElement extends HTMLElement {
1683
1686
  throw new GemError(`not allow current root type`);
1684
1687
  }
1685
1688
  });
1689
+ this[constructorSymbol] = true;
1686
1690
  addMicrotask(() => this[initSymbol] = false);
1687
1691
  this[initSymbol] = true;
1688
1692
  this[updateSymbol] = () => {
@@ -1733,25 +1737,20 @@ class GemElement extends HTMLElement {
1733
1737
  }
1734
1738
  }
1735
1739
  get internals() {
1740
+ var _a2, _b;
1736
1741
  if (!__privateGet$1(this, _internals)) {
1737
- const getCustomStateSet = () => {
1738
- const getV = (v) => v.replace(/-/g, "");
1739
- return {
1740
- has: (v) => getV(v) in this.dataset,
1741
- add: (v) => {
1742
- this.dataset[getV(v)] = "";
1743
- },
1744
- delete: (v) => delete this.dataset[getV(v)]
1745
- };
1746
- };
1747
- if (!this.attachInternals) {
1748
- this.attachInternals = () => {
1749
- return { states: getCustomStateSet() };
1750
- };
1751
- }
1752
1742
  __privateSet$1(this, _internals, this.attachInternals());
1753
- if (!__privateGet$1(this, _internals).states) {
1754
- __privateGet$1(this, _internals).states = getCustomStateSet();
1743
+ try {
1744
+ (_a2 = __privateGet$1(this, _internals).states) == null ? void 0 : _a2.add("foo");
1745
+ (_b = __privateGet$1(this, _internals).states) == null ? void 0 : _b.delete("foo");
1746
+ } catch {
1747
+ Reflect.defineProperty(__privateGet$1(this, _internals), "states", {
1748
+ value: new Proxy(__privateGet$1(this, _internals).states, {
1749
+ get(target, p) {
1750
+ return (str) => target[p](`--${str}`);
1751
+ }
1752
+ })
1753
+ });
1755
1754
  }
1756
1755
  }
1757
1756
  return __privateGet$1(this, _internals);
@@ -1787,7 +1786,7 @@ class GemElement extends HTMLElement {
1787
1786
  }
1788
1787
  }
1789
1788
  disconnectedCallback() {
1790
- var _a2, _b, _c;
1789
+ var _a2, _b, _c, _d;
1791
1790
  if (this.isConnected) {
1792
1791
  __privateSet$1(this, _isAppendReason, true);
1793
1792
  return;
@@ -1802,7 +1801,8 @@ class GemElement extends HTMLElement {
1802
1801
  (_b = __privateGet$1(this, _effectList)) == null ? void 0 : _b.forEach((effectItem) => {
1803
1802
  execCallback(effectItem.preCallback);
1804
1803
  });
1805
- __privateSet$1(this, _memoList, (_c = __privateGet$1(this, _memoList)) == null ? void 0 : _c.filter(({ initialized }) => !initialized));
1804
+ __privateSet$1(this, _effectList, (_c = __privateGet$1(this, _effectList)) == null ? void 0 : _c.filter(({ inConstructor }) => inConstructor));
1805
+ __privateSet$1(this, _memoList, (_d = __privateGet$1(this, _memoList)) == null ? void 0 : _d.filter(({ inConstructor }) => inConstructor));
1806
1806
  }
1807
1807
  }
1808
1808
  _renderRoot = new WeakMap();
@@ -1907,7 +1907,7 @@ function defineRef(target, prop, ref) {
1907
1907
  return ref;
1908
1908
  },
1909
1909
  get element() {
1910
- const gemReflects = [...ele.querySelectorAll("[data-gemreflect]")].map((e) => e.target);
1910
+ const gemReflects = [...ele.querySelectorAll("[data-gem-reflect]")].map((e) => e.target);
1911
1911
  for (const e of [ele, ...gemReflects]) {
1912
1912
  const result = e.querySelector(`[ref=${ref}]`);
1913
1913
  if (result)
@@ -1925,18 +1925,17 @@ function defineCSSState(target, prop, state2) {
1925
1925
  Object.defineProperty(target, prop, {
1926
1926
  configurable: true,
1927
1927
  get() {
1928
- var _a2;
1929
1928
  const that = this;
1930
1929
  const { states } = that.internals;
1931
- return (_a2 = states.has) == null ? void 0 : _a2.call(states, state2);
1930
+ return states == null ? void 0 : states.has(state2);
1932
1931
  },
1933
1932
  set(v) {
1934
1933
  const that = this;
1935
1934
  const { states } = that.internals;
1936
1935
  if (v) {
1937
- states.add(state2);
1936
+ states == null ? void 0 : states.add(state2);
1938
1937
  } else {
1939
- states.delete(state2);
1938
+ states == null ? void 0 : states.delete(state2);
1940
1939
  }
1941
1940
  }
1942
1941
  });
@@ -1944,11 +1943,11 @@ function defineCSSState(target, prop, state2) {
1944
1943
  const nativeDefineElement = customElements.define.bind(customElements);
1945
1944
  customElements.define = (name, cls, options) => {
1946
1945
  if (cls.prototype instanceof GemElement) {
1947
- const { observedAttributes, observedPropertys, defineEvents, defineCSSStates, defineRefs } = cls;
1946
+ const { observedAttributes, observedProperties, defineEvents, defineCSSStates, defineRefs } = cls;
1948
1947
  observedAttributes == null ? void 0 : observedAttributes.forEach((attr) => defineAttribute(cls.prototype, kebabToCamelCase(attr), attr));
1949
- observedPropertys == null ? void 0 : observedPropertys.forEach((prop) => defineProperty(cls.prototype, prop));
1948
+ observedProperties == null ? void 0 : observedProperties.forEach((prop) => defineProperty(cls.prototype, prop));
1950
1949
  defineEvents == null ? void 0 : defineEvents.forEach((event) => defineProperty(cls.prototype, kebabToCamelCase(event), event));
1951
- defineCSSStates == null ? void 0 : defineCSSStates.forEach((state2) => defineCSSState(cls.prototype, kebabToCamelCase(state2), `--${state2}`));
1950
+ defineCSSStates == null ? void 0 : defineCSSStates.forEach((state2) => defineCSSState(cls.prototype, kebabToCamelCase(state2), state2));
1952
1951
  defineRefs == null ? void 0 : defineRefs.forEach((ref) => defineRef(cls.prototype, kebabToCamelCase(ref), ref));
1953
1952
  }
1954
1953
  nativeDefineElement(name, cls, options);
@@ -1986,13 +1985,13 @@ function numattribute(target, prop) {
1986
1985
  defineAttr(target, prop, attr);
1987
1986
  }
1988
1987
  function property(target, prop) {
1989
- pushStaticField(target, "observedPropertys", prop);
1988
+ pushStaticField(target, "observedProperties", prop);
1990
1989
  defineProperty(target, prop);
1991
1990
  }
1992
1991
  function state(target, prop) {
1993
1992
  const attr = camelToKebabCase(prop);
1994
1993
  pushStaticField(target, "defineCSSStates", attr);
1995
- defineCSSState(target, prop, `--${attr}`);
1994
+ defineCSSState(target, prop, attr);
1996
1995
  }
1997
1996
  function slot(target, prop) {
1998
1997
  const attr = camelToKebabCase(target[prop] || prop);
@@ -2063,13 +2062,13 @@ function validData(data) {
2063
2062
  if ($hasShouldCloseHandle)
2064
2063
  throw new GemError("`$hasShouldCloseHandle` is not allowed");
2065
2064
  }
2066
- function getUrlbarPath(internalPath) {
2065
+ function getUrlBarPath(internalPath) {
2067
2066
  return gemHistory.basePath ? gemHistory.basePath + internalPath : internalPath;
2068
2067
  }
2069
- function getInternalPath(urlbarPath) {
2070
- if (urlbarPath === gemHistory.basePath)
2068
+ function getInternalPath(urlBarPath) {
2069
+ if (urlBarPath === gemHistory.basePath)
2071
2070
  return "/";
2072
- return urlbarPath.replace(new RegExp(`^${gemHistory.basePath}/`), "/");
2071
+ return urlBarPath.replace(new RegExp(`^${gemHistory.basePath}/`), "/");
2073
2072
  }
2074
2073
  function normalizeParams(params) {
2075
2074
  const current = paramsMap.get(store.$key) || {};
@@ -2093,7 +2092,7 @@ function updateHistory(p, native) {
2093
2092
  }, data);
2094
2093
  paramsMap.set(state2.$key, params);
2095
2094
  updateStore(cleanObject(store), state2);
2096
- const url = getUrlbarPath(path) + new QueryString(query) + hash;
2095
+ const url = getUrlBarPath(path) + new QueryString(query) + hash;
2097
2096
  const prevHash = decodeURIComponent(location.hash);
2098
2097
  native(state2, title, url);
2099
2098
  if (prevHash !== hash)
@@ -2108,7 +2107,7 @@ function updateHistoryByNative(data, title, originUrl, native) {
2108
2107
  const params = normalizeParams({ path: pathname, query: new QueryString(search), hash, title, data });
2109
2108
  paramsMap.set(state2.$key, params);
2110
2109
  updateStore(cleanObject(store), state2);
2111
- const url = getUrlbarPath(pathname) + params.query + hash;
2110
+ const url = getUrlBarPath(pathname) + params.query + hash;
2112
2111
  const prevHash = location.hash;
2113
2112
  native(state2, title, url);
2114
2113
  if (prevHash !== hash)
@@ -2222,7 +2221,8 @@ if (!window._GEMHISTORY) {
2222
2221
  });
2223
2222
  }
2224
2223
  const prevState = store;
2225
- if (parseFloat(newState.$key) > parseFloat(prevState.$key) && newState.$hasOpenHandle) {
2224
+ const isForward = parseFloat(newState.$key) > parseFloat(prevState.$key);
2225
+ if (isForward && newState.$hasOpenHandle) {
2226
2226
  (_b = (_a2 = paramsMap.get(newState.$key)) == null ? void 0 : _a2.open) == null ? void 0 : _b.call(_a2);
2227
2227
  } else if (prevState.$hasCloseHandle) {
2228
2228
  const prevParams = paramsMap.get(prevState.$key);
@@ -2339,9 +2339,17 @@ let GemRouteElement = class extends GemElement {
2339
2339
  __privateSet2(this, _lastLoader, void 0);
2340
2340
  this.currentRoute = route;
2341
2341
  this.currentParams = params;
2342
- this.setState({ content });
2343
- this.routechange(this.currentRoute);
2344
- __privateGet2(this, _updateLocationStore).call(this);
2342
+ const changeContent = () => {
2343
+ this.setState({ content });
2344
+ this.routechange(this.currentRoute);
2345
+ __privateGet2(this, _updateLocationStore).call(this);
2346
+ return Promise.resolve();
2347
+ };
2348
+ if (this.transition && "startViewTransition" in document) {
2349
+ document.startViewTransition(changeContent);
2350
+ } else {
2351
+ changeContent();
2352
+ }
2345
2353
  });
2346
2354
  this.routes = routes;
2347
2355
  }
@@ -2427,6 +2435,9 @@ GemRouteElement.findRoute = (target = [], path) => {
2427
2435
  }
2428
2436
  return { route: defaultRoute };
2429
2437
  };
2438
+ __decorateClass$6([
2439
+ boolattribute
2440
+ ], GemRouteElement.prototype, "transition", 2);
2430
2441
  __decorateClass$6([
2431
2442
  property
2432
2443
  ], GemRouteElement.prototype, "routes", 2);
@@ -2791,13 +2802,12 @@ var __decorateClass$1 = (decorators, target, key2, kind) => {
2791
2802
  __defProp$1(target, key2, result);
2792
2803
  return result;
2793
2804
  };
2794
- document.querySelectorAll("[data-reflect]").forEach((e) => e.remove());
2795
2805
  class GemReflectElement extends GemElement {
2796
2806
  constructor() {
2797
2807
  super({ isLight: true });
2798
2808
  this.target = document.head;
2799
2809
  this.hidden = true;
2800
- this.dataset.gemreflect = "";
2810
+ this.dataset.gemReflect = "";
2801
2811
  this.effect(() => {
2802
2812
  const childNodes = [...this.childNodes];
2803
2813
  childNodes.forEach((node) => {
@@ -3273,7 +3283,7 @@ const mediaQuery = {
3273
3283
  return matche(this.DATA_REDUCE);
3274
3284
  }
3275
3285
  };
3276
- const version = "1.6.18";
3286
+ const version = "1.7.0";
3277
3287
  if (window.__GEM_DEVTOOLS__HOOK__) {
3278
3288
  Object.assign(window.__GEM_DEVTOOLS__HOOK__, __spreadValues({}, Gem));
3279
3289
  }