@mantou/gem 1.6.18 → 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 +32 -15
- package/dist/gem.umd.js +22 -22
- package/elements/base/modal-factory.d.ts +8 -5
- package/elements/base/modal-factory.d.ts.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/helper/i18n.js.map +1 -1
- package/lib/element.d.ts +2 -2
- package/lib/element.d.ts.map +1 -1
- package/lib/element.js +10 -5
- 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.js +1 -1
- package/package.json +1 -1
- package/src/elements/base/route.ts +16 -7
- package/src/helper/i18n.ts +1 -1
- package/src/lib/element.ts +13 -10
- 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/history.test.ts +1 -1
package/src/lib/history.ts
CHANGED
|
@@ -50,13 +50,13 @@ function validData(data: any) {
|
|
|
50
50
|
if ($hasShouldCloseHandle) throw new GemError('`$hasShouldCloseHandle` is not allowed');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function
|
|
53
|
+
function getUrlBarPath(internalPath: string) {
|
|
54
54
|
return gemHistory.basePath ? gemHistory.basePath + internalPath : internalPath;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function getInternalPath(
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
57
|
+
function getInternalPath(urlBarPath: string) {
|
|
58
|
+
if (urlBarPath === gemHistory.basePath) return '/';
|
|
59
|
+
return urlBarPath.replace(new RegExp(`^${gemHistory.basePath}/`), '/');
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function normalizeParams(params: UpdateHistoryParams): HistoryParams {
|
|
@@ -88,7 +88,7 @@ function updateHistory(p: UpdateHistoryParams, native: typeof nativeHistory.push
|
|
|
88
88
|
};
|
|
89
89
|
paramsMap.set(state.$key, params);
|
|
90
90
|
updateStore(cleanObject(store), state);
|
|
91
|
-
const url =
|
|
91
|
+
const url = getUrlBarPath(path) + new QueryString(query) + hash;
|
|
92
92
|
const prevHash = decodeURIComponent(location.hash);
|
|
93
93
|
native(state, title, url);
|
|
94
94
|
if (prevHash !== hash) window.dispatchEvent(new CustomEvent('hashchange'));
|
|
@@ -105,7 +105,7 @@ function updateHistoryByNative(data: any, title: string, originUrl: string, nati
|
|
|
105
105
|
const params = normalizeParams({ path: pathname, query: new QueryString(search), hash, title, data });
|
|
106
106
|
paramsMap.set(state.$key, params);
|
|
107
107
|
updateStore(cleanObject(store), state);
|
|
108
|
-
const url =
|
|
108
|
+
const url = getUrlBarPath(pathname) + params.query + hash;
|
|
109
109
|
const prevHash = location.hash;
|
|
110
110
|
native(state, title, url);
|
|
111
111
|
// `location.hash` 和 `hash` 都已经进行了 url 编码,可以直接进行相等判断
|
|
@@ -127,13 +127,13 @@ class GemHistory {
|
|
|
127
127
|
// 应用初始化的时候设置
|
|
128
128
|
updateStore(gemBasePathStore, { basePath });
|
|
129
129
|
// paramsMap 更新后 ui 才会更新
|
|
130
|
-
Object.assign(paramsMap.get(store.$key)
|
|
130
|
+
Object.assign(paramsMap.get(store.$key)!, { path: getInternalPath(location.pathname) });
|
|
131
131
|
}
|
|
132
132
|
getParams() {
|
|
133
133
|
return paramsMap.get(store.$key)!;
|
|
134
134
|
}
|
|
135
135
|
updateParams(params: UpdateHistoryParams) {
|
|
136
|
-
Object.assign(paramsMap.get(store.$key)
|
|
136
|
+
Object.assign(paramsMap.get(store.$key)!, params);
|
|
137
137
|
updateStore(store, {});
|
|
138
138
|
}
|
|
139
139
|
push(params: UpdateHistoryParams) {
|
|
@@ -257,8 +257,8 @@ if (!window._GEMHISTORY) {
|
|
|
257
257
|
|
|
258
258
|
// url 变化前 historyItem
|
|
259
259
|
const prevState = store;
|
|
260
|
-
|
|
261
|
-
if (
|
|
260
|
+
const isForward = parseFloat(newState.$key) > parseFloat(prevState.$key);
|
|
261
|
+
if (isForward && newState.$hasOpenHandle) {
|
|
262
262
|
// 返回键关闭的 modal 能前进键重新打开
|
|
263
263
|
// 刷新后不能工作:刷新后 historyItem 中只有 url
|
|
264
264
|
// 能在子 app 中工作
|
package/src/lib/utils.ts
CHANGED
|
@@ -272,7 +272,7 @@ export function createCSSSheet<T extends StyledKeyValuePair>(rules: T | string,
|
|
|
272
272
|
style = rules;
|
|
273
273
|
} else {
|
|
274
274
|
Object.keys(rules).forEach((key: keyof T) => {
|
|
275
|
-
sheet[key] = `${key}-${randomStr()}`;
|
|
275
|
+
sheet[key] = `${key as string}-${randomStr()}`;
|
|
276
276
|
style += rules[key].styledContent.replace(/&/g, sheet[key]);
|
|
277
277
|
});
|
|
278
278
|
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.19';
|
|
@@ -222,19 +222,19 @@ class MemoGemDemo extends GemElement {
|
|
|
222
222
|
constructor() {
|
|
223
223
|
super();
|
|
224
224
|
this.memo(
|
|
225
|
-
() => this.memoCount
|
|
225
|
+
() => (this.memoCount += 1),
|
|
226
226
|
() => [this.attr, this.prop],
|
|
227
227
|
);
|
|
228
228
|
}
|
|
229
229
|
willMount() {
|
|
230
230
|
this.memo(
|
|
231
231
|
(_arr) => {
|
|
232
|
-
this.memoCount
|
|
232
|
+
this.memoCount += 2;
|
|
233
233
|
},
|
|
234
234
|
() => [],
|
|
235
235
|
);
|
|
236
236
|
this.memo(() => {
|
|
237
|
-
this.memoCount
|
|
237
|
+
this.memoCount += 4;
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
}
|
|
@@ -242,23 +242,23 @@ customElements.define('memo-gem-demo', MemoGemDemo);
|
|
|
242
242
|
describe('gem element Memo', () => {
|
|
243
243
|
it('依赖当前值', async () => {
|
|
244
244
|
const el: MemoGemDemo = await fixture(html`<memo-gem-demo></memo-gem-demo>`);
|
|
245
|
-
expect(el.memoCount).to.equal(
|
|
245
|
+
expect(el.memoCount).to.equal(7);
|
|
246
246
|
el.attr = 'b';
|
|
247
247
|
el.prop = {};
|
|
248
248
|
await nextFrame();
|
|
249
|
-
expect(el.memoCount).to.equal(
|
|
249
|
+
expect(el.memoCount).to.equal(12);
|
|
250
250
|
|
|
251
251
|
el.update();
|
|
252
252
|
await Promise.resolve();
|
|
253
|
-
expect(el.memoCount).to.equal(
|
|
253
|
+
expect(el.memoCount).to.equal(16);
|
|
254
254
|
|
|
255
255
|
document.body.append(el);
|
|
256
|
-
expect(el.memoCount).to.equal(
|
|
256
|
+
expect(el.memoCount).to.equal(16);
|
|
257
257
|
|
|
258
258
|
el.remove();
|
|
259
259
|
await Promise.resolve();
|
|
260
260
|
document.body.append(el);
|
|
261
|
-
expect(el.memoCount).to.equal(
|
|
261
|
+
expect(el.memoCount).to.equal(22);
|
|
262
262
|
});
|
|
263
263
|
});
|
|
264
264
|
|
package/src/test/history.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ describe('history 测试', () => {
|
|
|
10
10
|
await aTimeout(10);
|
|
11
11
|
expect(window.location.hash).to.equal('#a');
|
|
12
12
|
history.back();
|
|
13
|
-
await aTimeout(
|
|
13
|
+
await aTimeout(600);
|
|
14
14
|
expect(window.location.hash).to.equal(hash);
|
|
15
15
|
history.push({ path: '/a', hash: '#b' });
|
|
16
16
|
await aTimeout(10);
|