@mantou/gem 2.0.0 → 2.1.1

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 (87) hide show
  1. package/dist/gem.es.js +1172 -1188
  2. package/dist/gem.umd.js +25 -25
  3. package/elements/base/gesture.d.ts +1 -2
  4. package/elements/base/gesture.d.ts.map +1 -1
  5. package/elements/base/gesture.js +21 -28
  6. package/elements/base/gesture.js.map +1 -1
  7. package/elements/base/link.d.ts +1 -2
  8. package/elements/base/link.d.ts.map +1 -1
  9. package/elements/base/link.js +17 -10
  10. package/elements/base/link.js.map +1 -1
  11. package/elements/base/modal-factory.d.ts +6 -4
  12. package/elements/base/modal-factory.d.ts.map +1 -1
  13. package/elements/base/modal-factory.js +3 -3
  14. package/elements/base/modal-factory.js.map +1 -1
  15. package/elements/base/route.d.ts +8 -2
  16. package/elements/base/route.d.ts.map +1 -1
  17. package/elements/base/route.js +4 -4
  18. package/elements/base/route.js.map +1 -1
  19. package/elements/base/title.d.ts +0 -1
  20. package/elements/base/title.d.ts.map +1 -1
  21. package/elements/base/title.js +15 -5
  22. package/elements/base/title.js.map +1 -1
  23. package/elements/base/unsafe.d.ts +1 -1
  24. package/elements/base/unsafe.d.ts.map +1 -1
  25. package/elements/base/unsafe.js +10 -4
  26. package/elements/base/unsafe.js.map +1 -1
  27. package/elements/base/use.d.ts +0 -1
  28. package/elements/base/use.d.ts.map +1 -1
  29. package/elements/base/use.js +11 -2
  30. package/elements/base/use.js.map +1 -1
  31. package/helper/i18n.d.ts.map +1 -1
  32. package/helper/i18n.js +11 -11
  33. package/helper/i18n.js.map +1 -1
  34. package/helper/theme.d.ts +8 -7
  35. package/helper/theme.d.ts.map +1 -1
  36. package/helper/theme.js +21 -21
  37. package/helper/theme.js.map +1 -1
  38. package/lib/decorators.d.ts +1 -1
  39. package/lib/decorators.d.ts.map +1 -1
  40. package/lib/decorators.js +3 -3
  41. package/lib/decorators.js.map +1 -1
  42. package/lib/element.d.ts +5 -4
  43. package/lib/element.d.ts.map +1 -1
  44. package/lib/element.js +14 -16
  45. package/lib/element.js.map +1 -1
  46. package/lib/history.d.ts +20 -8
  47. package/lib/history.d.ts.map +1 -1
  48. package/lib/history.js +12 -12
  49. package/lib/history.js.map +1 -1
  50. package/lib/store.d.ts +5 -10
  51. package/lib/store.d.ts.map +1 -1
  52. package/lib/store.js +7 -22
  53. package/lib/store.js.map +1 -1
  54. package/lib/utils.d.ts +1 -0
  55. package/lib/utils.d.ts.map +1 -1
  56. package/lib/utils.js +20 -14
  57. package/lib/utils.js.map +1 -1
  58. package/lib/version.d.ts +1 -1
  59. package/lib/version.d.ts.map +1 -1
  60. package/lib/version.js +1 -2
  61. package/lib/version.js.map +1 -1
  62. package/package.json +3 -4
  63. package/src/elements/base/gesture.ts +23 -25
  64. package/src/elements/base/link.ts +9 -9
  65. package/src/elements/base/modal-factory.ts +3 -3
  66. package/src/elements/base/route.ts +4 -4
  67. package/src/elements/base/title.ts +5 -4
  68. package/src/elements/base/unsafe.ts +6 -3
  69. package/src/elements/base/use.ts +4 -3
  70. package/src/helper/i18n.ts +11 -8
  71. package/src/helper/theme.ts +27 -26
  72. package/src/lib/decorators.ts +4 -4
  73. package/src/lib/element.ts +17 -19
  74. package/src/lib/history.ts +12 -12
  75. package/src/lib/store.ts +11 -31
  76. package/src/lib/utils.ts +22 -14
  77. package/src/lib/version.ts +1 -2
  78. package/src/test/gem-element/advance.test.ts +2 -2
  79. package/src/test/gem-element/basic.test.ts +3 -3
  80. package/src/test/gem-element/decorators.test.ts +4 -4
  81. package/src/test/store.test.ts +7 -7
  82. package/src/test/utils.test.ts +1 -1
  83. package/LICENSE +0 -21
  84. package/helper/react-shim.d.ts +0 -15
  85. package/helper/react-shim.d.ts.map +0 -1
  86. package/helper/react-shim.js +0 -56
  87. package/helper/react-shim.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  // https://github.com/WICG/navigation-api#stakeholder-feedback
2
2
 
3
- import { connect, useStore } from './store';
3
+ import { connect, createStore } from './store';
4
4
  import { QueryString, cleanObject, GemError, absoluteLocation } from './utils';
5
5
 
6
6
  const nativeHistory = window.history;
@@ -18,7 +18,7 @@ export interface HistoryState {
18
18
  [index: string]: any;
19
19
  }
20
20
 
21
- const [store, updateHistoryStore] = useStore<HistoryState>({
21
+ const store = createStore<HistoryState>({
22
22
  $hasCloseHandle: false,
23
23
  $hasOpenHandle: false,
24
24
  $hasShouldCloseHandle: false,
@@ -103,7 +103,7 @@ function updateHistory(p: UpdateHistoryParams, native: typeof nativeHistory.push
103
103
  paramsMap.set(state.$key, params);
104
104
  dispatchBeforeChangeEvent();
105
105
  cleanObject(store);
106
- updateHistoryStore(state);
106
+ store(state);
107
107
  const url = getUrlBarPath(path) + new QueryString(query) + hash;
108
108
  const prevHash = decodeURIComponent(location.hash);
109
109
  native(state, title, url);
@@ -123,7 +123,7 @@ function updateHistoryByNative(data: any, title: string, originUrl: string, nati
123
123
  paramsMap.set(state.$key, params);
124
124
  dispatchBeforeChangeEvent();
125
125
  cleanObject(store);
126
- updateHistoryStore(state);
126
+ store(state);
127
127
  const url = getUrlBarPath(pathname) + params.query + hash;
128
128
  const prevHash = location.hash;
129
129
  native(state, title, url);
@@ -131,7 +131,7 @@ function updateHistoryByNative(data: any, title: string, originUrl: string, nati
131
131
  if (prevHash !== hash) window.dispatchEvent(new CustomEvent('hashchange'));
132
132
  }
133
133
 
134
- const [gemBasePathStore, updateBasePathStore] = useStore({
134
+ const gemBasePathStore = createStore({
135
135
  basePath: '',
136
136
  });
137
137
 
@@ -147,7 +147,7 @@ class GemHistory extends EventTarget {
147
147
  }
148
148
  set basePath(basePath: string) {
149
149
  // 应用初始化的时候设置
150
- updateBasePathStore({ basePath });
150
+ gemBasePathStore({ basePath });
151
151
  // paramsMap 更新后 ui 才会更新
152
152
  Object.assign(paramsMap.get(store.$key)!, { path: getInternalPath(location.pathname) });
153
153
  }
@@ -156,7 +156,7 @@ class GemHistory extends EventTarget {
156
156
  }
157
157
  updateParams(params: UpdateHistoryParams) {
158
158
  Object.assign(paramsMap.get(store.$key)!, params);
159
- updateHistoryStore();
159
+ store();
160
160
  }
161
161
  push(params: UpdateHistoryParams) {
162
162
  updateHistory(params, nativePushState);
@@ -183,7 +183,7 @@ class GemHistory extends EventTarget {
183
183
  // `<gem-**>` 只读写父应用 `basePath`
184
184
  const gemHistory = new GemHistory();
185
185
 
186
- const [gemTitleStore, updateTitleStore] = useStore({ defaultTitle: document.title, url: '', title: '' });
186
+ const gemTitleStore = createStore({ defaultTitle: document.title, url: '', title: '' });
187
187
 
188
188
  const _GEMHISTORY = { history: gemHistory, titleStore: gemTitleStore, basePathStore: gemBasePathStore };
189
189
 
@@ -217,7 +217,7 @@ if (!window._GEMHISTORY) {
217
217
  // 支持在 `data:` `blob:` 中 `import`
218
218
  if (protocol.startsWith('http')) gemHistory.replace({ path: pathname, query: search, hash });
219
219
  } else if (nativeHistory.state.$hasCloseHandle) {
220
- updateHistoryStore(nativeHistory.state);
220
+ store(nativeHistory.state);
221
221
  const params = normalizeParams({ title: document.title });
222
222
  paramsMap.set(store.$key, params);
223
223
  // 有 handle 返回键的页面刷新需要清除返回 handler
@@ -225,7 +225,7 @@ if (!window._GEMHISTORY) {
225
225
  } else {
226
226
  // 有 gem 历史的正常普通刷新, 储存 params
227
227
  const params = normalizeParams({ title: document.title, hash: location.hash });
228
- updateHistoryStore({
228
+ store({
229
229
  $key: getKey(),
230
230
  ...(nativeHistory.state || {}),
231
231
  });
@@ -242,7 +242,7 @@ if (!window._GEMHISTORY) {
242
242
  connect(store, () => {
243
243
  const { title } = gemHistory.getParams();
244
244
  if (title !== gemTitleStore.title) {
245
- updateTitleStore({ title });
245
+ gemTitleStore({ title });
246
246
  }
247
247
  });
248
248
 
@@ -312,7 +312,7 @@ if (!window._GEMHISTORY) {
312
312
 
313
313
  dispatchBeforeChangeEvent();
314
314
  cleanObject(store);
315
- updateHistoryStore(newState);
315
+ store(newState);
316
316
  });
317
317
  }
318
318
 
package/src/lib/store.ts CHANGED
@@ -1,40 +1,20 @@
1
- import type { NonPrimitive } from './utils';
2
- import { addMicrotask, GemError } from './utils';
1
+ import { addMicrotask, createUpdater } from './utils';
3
2
 
4
- export const StoreListenerMap = new WeakMap<NonPrimitive, Set<() => void>>();
3
+ export type Store<T = any> = ReturnType<typeof createUpdater<T>>;
5
4
 
6
- // 限制 `updateStore` 的参数类型
7
- export type Store<T> = T & { '': string };
5
+ export const StoreListenerMap = new WeakMap<Store<any>, Set<() => void>>();
8
6
 
9
- export function createStore<T extends NonPrimitive>(originStore: T) {
10
- if (StoreListenerMap.has(originStore)) {
11
- throw new GemError('argument error');
12
- }
13
- StoreListenerMap.set(originStore, new Set<() => void>());
14
- return originStore as Store<T>;
15
- }
16
-
17
- export function updateStore<T extends NonPrimitive>(store: Store<T>, value?: Partial<T>) {
18
- Object.assign(store, value);
19
- StoreListenerMap.get(store)?.forEach((func) => {
20
- addMicrotask(func);
7
+ export function createStore<T = any>(originStore: T) {
8
+ const store = createUpdater(originStore, (value?: Partial<T>) => {
9
+ Object.assign(store, value);
10
+ StoreListenerMap.get(store)?.forEach((func) => addMicrotask(func));
21
11
  });
12
+ StoreListenerMap.set(store, new Set<() => void>());
13
+ return store;
22
14
  }
23
15
 
24
- export function useStore<T extends NonPrimitive>(originStore: T) {
25
- const store = createStore(originStore);
26
- return [store, (value?: Partial<T>) => updateStore(store, value)] as const;
27
- }
28
-
29
- export function connect<T extends NonPrimitive>(store: Store<T>, func: () => void) {
16
+ export function connect(store: Store<any>, func: () => void) {
30
17
  const listeners = StoreListenerMap.get(store);
31
18
  listeners?.add(func);
32
- return () => {
33
- listeners?.delete(func);
34
- };
35
- }
36
-
37
- export function disconnect<T extends NonPrimitive>(store: Store<T>, func: () => void) {
38
- const listeners = StoreListenerMap.get(store);
39
- listeners?.delete(func);
19
+ return () => listeners?.delete(func);
40
20
  }
package/src/lib/utils.ts CHANGED
@@ -1,18 +1,26 @@
1
- let microtaskSet = new Set<() => void>();
1
+ const { assign, setPrototypeOf, fromEntries, entries, keys } = Object;
2
+
3
+ const microtaskSet = new Set<() => void>();
2
4
  export function addMicrotask(func: () => void) {
3
- if (typeof func !== 'function') return;
4
- if (!microtaskSet.size) {
5
- // delayed execution callback after updating store
6
- globalThis.queueMicrotask(() => {
7
- const set = microtaskSet;
8
- microtaskSet = new Set();
9
- set.forEach((f) => f());
10
- });
11
- }
12
- microtaskSet.delete(func);
5
+ if (microtaskSet.has(func)) return;
6
+ queueMicrotask(() => {
7
+ microtaskSet.delete(func);
8
+ func();
9
+ });
13
10
  microtaskSet.add(func);
14
11
  }
15
12
 
13
+ // 注意 typeof state === 'function' 但是没有 Function 的方法和属性
14
+ export function createUpdater<T, Fn = (payload?: Partial<T>) => any>(initState: T, fn: Fn) {
15
+ const state: any = fn;
16
+ setPrototypeOf(state, null);
17
+ delete state.name;
18
+ delete state.length;
19
+ assign(state, initState);
20
+ // TODO: type
21
+ return state as Fn & T;
22
+ }
23
+
16
24
  // 不编码 hash 用于比较
17
25
  export function absoluteLocation(currentPath = '', relativePath = '') {
18
26
  const { pathname, search, hash } = new URL(relativePath, location.origin + currentPath);
@@ -156,11 +164,11 @@ export class QueryString extends URLSearchParams {
156
164
  concat(param: any) {
157
165
  let query: any;
158
166
  if (typeof param === 'string') {
159
- query = Object.fromEntries(new URLSearchParams(param).entries());
167
+ query = fromEntries(new URLSearchParams(param).entries());
160
168
  } else {
161
169
  query = param;
162
170
  }
163
- Object.entries(query).forEach(([key, value]) => {
171
+ entries(query).forEach(([key, value]) => {
164
172
  this.append(key, this.#stringify(value));
165
173
  });
166
174
  }
@@ -247,7 +255,7 @@ export function kebabToCamelCase(str: string) {
247
255
  }
248
256
 
249
257
  export function cleanObject<T extends Record<string, unknown>>(o: T) {
250
- Object.keys(o).forEach((key: keyof T) => {
258
+ keys(o).forEach((key: keyof T) => {
251
259
  delete o[key];
252
260
  });
253
261
  return o;
@@ -1,2 +1 @@
1
- // Do not modify manually
2
- export const version = '0.0.0';
1
+ export const version = '2.1.1';
@@ -10,7 +10,7 @@ import { fixture, expect, nextFrame } from '@open-wc/testing';
10
10
 
11
11
  import type { Metadata } from '../../lib/element';
12
12
  import { createCSSSheet, createState, GemElement, html, createRef } from '../../lib/element';
13
- import { createStore, updateStore } from '../../lib/store';
13
+ import { createStore } from '../../lib/store';
14
14
  import {
15
15
  attribute,
16
16
  property,
@@ -45,7 +45,7 @@ describe('异步 gem element 测试', () => {
45
45
  it('异步 gem element 更新', async () => {
46
46
  const el: AsyncGemDemo = await fixture(html`<async-gem-demo></async-gem-demo>`);
47
47
  expect(el.renderCount).to.equal(1);
48
- updateStore(store, { a: ++store.a });
48
+ store({ a: ++store.a });
49
49
  el.internals.stateList[0]({ a: ++(el.internals.stateList[0] as any).a });
50
50
  await nextFrame();
51
51
  expect(el.renderCount).to.equal(2);
@@ -1,7 +1,7 @@
1
1
  import { fixture, expect, nextFrame } from '@open-wc/testing';
2
2
 
3
3
  import { createCSSSheet, createState, GemElement, html } from '../../lib/element';
4
- import { createStore, updateStore } from '../../lib/store';
4
+ import { createStore } from '../../lib/store';
5
5
  import { css } from '../../lib/utils';
6
6
  import {
7
7
  adoptedStyle,
@@ -142,8 +142,8 @@ describe('基本 gem element 测试', () => {
142
142
  it('更新 store', async () => {
143
143
  const a = store.a;
144
144
  const el: GemDemo = await fixture(html`<gem-demo></gem-demo>`);
145
- updateStore(store, { a: ++store.a });
146
- updateStore(store, { a: ++store.a });
145
+ store({ a: ++store.a });
146
+ store({ a: ++store.a });
147
147
  expect(store.a).to.equal(a + 2);
148
148
  expect(el.renderCount).to.equal(1);
149
149
  await Promise.resolve();
@@ -2,7 +2,7 @@ import { fixture, expect } from '@open-wc/testing';
2
2
 
3
3
  import type { Metadata } from '../../lib/element';
4
4
  import { createCSSSheet, GemElement, html, createRef } from '../../lib/element';
5
- import { createStore, updateStore } from '../../lib/store';
5
+ import { createStore } from '../../lib/store';
6
6
  import { css } from '../../lib/utils';
7
7
  import type { Emitter } from '../../lib/decorators';
8
8
  import {
@@ -81,10 +81,10 @@ describe('装饰器', () => {
81
81
  rank-count="2"
82
82
  ></decorator-gem-demo>
83
83
  `);
84
- updateStore(store, { a: 1 });
84
+ store({ a: 1 });
85
85
  await Promise.resolve();
86
86
  const metadata: Metadata = Reflect.get(DecoratorGemElement, Symbol.metadata);
87
- expect(metadata.observedStores).to.eql([{ a: 1 }]);
87
+ expect({ ...metadata.observedStores.at(0) }).to.eql({ a: 1 });
88
88
  expect(metadata.observedAttributes).to.eql(['rank-attr', 'rank-disabled', 'rank-count']);
89
89
  expect(metadata.definedEvents).to.eql(['say-hi']);
90
90
  expect(metadata.definedCSSStates).to.eql(['open-state']);
@@ -102,7 +102,7 @@ describe('装饰器', () => {
102
102
  expect(el.inputRef.ref.startsWith('ref-')).to.equal(true);
103
103
  expect(el.bodySlot).to.equal('body-slot');
104
104
  expect(el).shadowDom.to.equal('attr: attr, disabled: true, count: 2, prop: prop');
105
- updateStore(store, { a: 3 });
105
+ store({ a: 3 });
106
106
  await Promise.resolve();
107
107
  expect(el.renderCount).to.equal(3);
108
108
  el.sayHi(2);
@@ -1,27 +1,27 @@
1
1
  import { expect, aTimeout } from '@open-wc/testing';
2
2
 
3
- import { StoreListenerMap, createStore, updateStore, connect, disconnect } from '../lib/store';
3
+ import { StoreListenerMap, createStore, connect } from '../lib/store';
4
4
 
5
5
  describe('store 测试', () => {
6
6
  it('create store', () => {
7
7
  const origin = { a: 1 };
8
8
  const store = createStore(origin);
9
- expect(store).to.equal(origin);
9
+ expect({ ...store }).to.deep.equal(origin);
10
10
  expect(!!StoreListenerMap.get(store)).to.equal(true);
11
11
  });
12
12
  it('update store', async () => {
13
13
  const store = createStore({ a: 1 });
14
14
  let flag = true;
15
15
  const update = () => (flag = !flag);
16
- connect(store, update);
17
- updateStore(store, { a: 1 });
16
+ const disconnect = connect(store, update);
17
+ store({ a: 1 });
18
18
  await aTimeout(0);
19
19
  expect(flag).to.equal(false);
20
- updateStore(store);
20
+ store();
21
21
  await aTimeout(0);
22
22
  expect(flag).to.equal(true);
23
- disconnect(store, update);
24
- updateStore(store, { a: 1 });
23
+ disconnect();
24
+ store({ a: 1 });
25
25
  await aTimeout(0);
26
26
  expect(flag).to.equal(true);
27
27
  });
@@ -112,7 +112,7 @@ describe('utils 测试', () => {
112
112
  });
113
113
  expect(cssSheet.scroll.startsWith('scroll')).to.true;
114
114
  const rules = cssSheet[SheetToken].getStyle().cssRules;
115
- expect(rules.item(0).selectorText).to.equal(':scope, :host');
115
+ expect(rules.item(0).selectorText).to.equal(':where(:scope:not([hidden])), :host(:where(:not([hidden])))');
116
116
  expect(rules.item(1).selectorText.startsWith('.scroll')).to.true;
117
117
  expect(rules.item(1).style.background).to.equal('red');
118
118
  expect(rules.item(1).cssRules.item(0).selectorText).to.equal('&:hover *');
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021-present
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,15 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import { Store } from '../lib/store';
3
- /**
4
- * `<gem-route>.routes.getContent`
5
- */
6
- export declare function renderReactNode(ele: any, node: ReactNode): void;
7
- /**
8
- * Same as `@connectStore`
9
- */
10
- export declare function connectStore<T extends object>(store: Store<T>): void;
11
- /**
12
- * Warning: https://github.com/facebook/react/issues/25675
13
- */
14
- export declare function useReactNode(node: ReactNode): any;
15
- //# sourceMappingURL=react-shim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-shim.d.ts","sourceRoot":"","sources":["../src/helper/react-shim.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAA+B,MAAM,OAAO,CAAC;AAM/D,OAAO,EAAE,KAAK,EAAW,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,QAgBxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,QAG7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,OAe3C"}
@@ -1,56 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
- // @ts-ignore
3
- // eslint-disable-next-line import/no-unresolved
4
- import { useEffect, useRef, useState } from 'react';
5
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
- // @ts-ignore
7
- // eslint-disable-next-line import/no-unresolved
8
- import { createRoot } from 'react-dom/client';
9
- import { connect } from '../lib/store';
10
- /**
11
- * `<gem-route>.routes.getContent`
12
- */
13
- export function renderReactNode(ele, node) {
14
- var _a;
15
- (_a = ele.react) === null || _a === void 0 ? void 0 : _a.unmount();
16
- ele.react = createRoot(ele);
17
- // async
18
- ele.react.render(node);
19
- // override
20
- const routeEle = ele instanceof HTMLElement ? ele : ele.host;
21
- const originUnmounted = routeEle.unmounted;
22
- if (!(originUnmounted === null || originUnmounted === void 0 ? void 0 : originUnmounted.react)) {
23
- routeEle.unmounted = () => {
24
- originUnmounted === null || originUnmounted === void 0 ? void 0 : originUnmounted.apply(routeEle);
25
- ele.react.unmount();
26
- };
27
- routeEle.unmounted.react = true;
28
- }
29
- }
30
- /**
31
- * Same as `@connectStore`
32
- */
33
- export function connectStore(store) {
34
- const [_, update] = useState({});
35
- useEffect(() => connect(store, () => update({})), []);
36
- }
37
- /**
38
- * Warning: https://github.com/facebook/react/issues/25675
39
- */
40
- export function useReactNode(node) {
41
- const ref = useRef();
42
- // Warning: Attempted to synchronously unmount a root while React was already rendering. React cannot finish unmounting the root until the current render has completed, which may lead to a race condition.
43
- useEffect(() => () => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.root.unmount(); }, []);
44
- if (ref.current) {
45
- ref.current.root.render(node);
46
- return ref.current.container;
47
- }
48
- const container = document.createElement('div');
49
- container.style.display = 'contents';
50
- const root = createRoot(container);
51
- ref.current = { root, container };
52
- // Warning: Render methods should be a pure function of props and state; triggering nested component updates from render is not allowed. If necessary, trigger nested updates in componentDidUpdate.
53
- root.render(node);
54
- return container;
55
- }
56
- //# sourceMappingURL=react-shim.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-shim.js","sourceRoot":"","sources":["../src/helper/react-shim.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,aAAa;AACb,gDAAgD;AAChD,OAAO,EAAa,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/D,6DAA6D;AAC7D,aAAa;AACb,gDAAgD;AAChD,OAAO,EAAQ,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAS,OAAO,EAAE,MAAM,cAAc,CAAC;AAE9C;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,IAAe;;IACvD,MAAA,GAAG,CAAC,KAAK,0CAAE,OAAO,EAAE,CA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