@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.
- package/dist/gem.es.js +54 -44
- package/dist/gem.umd.js +22 -22
- package/elements/base/modal-factory.d.ts +18 -15
- package/elements/base/modal-factory.d.ts.map +1 -1
- package/elements/base/reflect.d.ts.map +1 -1
- package/elements/base/reflect.js +1 -3
- package/elements/base/reflect.js.map +1 -1
- package/elements/base/route.d.ts +1 -0
- package/elements/base/route.d.ts.map +1 -1
- package/elements/base/route.js +16 -4
- package/elements/base/route.js.map +1 -1
- package/elements/base/title.d.ts +1 -1
- package/elements/base/title.js +1 -1
- package/helper/i18n.js.map +1 -1
- package/lib/decorators.d.ts +1 -1
- package/lib/decorators.js +3 -3
- package/lib/decorators.js.map +1 -1
- package/lib/element.d.ts +4 -5
- package/lib/element.d.ts.map +1 -1
- package/lib/element.js +31 -33
- package/lib/element.js.map +1 -1
- package/lib/history.js +8 -7
- package/lib/history.js.map +1 -1
- package/lib/utils.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.d.ts.map +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -2
- package/src/elements/base/reflect.ts +1 -4
- package/src/elements/base/route.ts +16 -7
- package/src/elements/base/title.ts +1 -1
- package/src/helper/i18n.ts +1 -1
- package/src/lib/decorators.ts +3 -3
- package/src/lib/element.ts +35 -41
- package/src/lib/history.ts +10 -10
- package/src/lib/utils.ts +1 -1
- package/src/lib/version.ts +1 -1
- package/src/test/gem-element/advance.test.ts +8 -8
- package/src/test/gem-element/basic.test.ts +1 -1
- package/src/test/gem-element/decorators.test.ts +1 -1
- 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:
|
|
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
|
-
|
|
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
|
-
|
|
1754
|
-
__privateGet$1(this, _internals).states
|
|
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,
|
|
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-
|
|
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
|
|
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,
|
|
1946
|
+
const { observedAttributes, observedProperties, defineEvents, defineCSSStates, defineRefs } = cls;
|
|
1948
1947
|
observedAttributes == null ? void 0 : observedAttributes.forEach((attr) => defineAttribute(cls.prototype, kebabToCamelCase(attr), attr));
|
|
1949
|
-
|
|
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),
|
|
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, "
|
|
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,
|
|
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
|
|
2065
|
+
function getUrlBarPath(internalPath) {
|
|
2067
2066
|
return gemHistory.basePath ? gemHistory.basePath + internalPath : internalPath;
|
|
2068
2067
|
}
|
|
2069
|
-
function getInternalPath(
|
|
2070
|
-
if (
|
|
2068
|
+
function getInternalPath(urlBarPath) {
|
|
2069
|
+
if (urlBarPath === gemHistory.basePath)
|
|
2071
2070
|
return "/";
|
|
2072
|
-
return
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
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.
|
|
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.
|
|
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
|
}
|