@mantou/gem 2.2.0 → 2.2.2

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 (159) hide show
  1. package/dist/gem.es.js +2039 -2051
  2. package/dist/gem.umd.js +12 -32
  3. package/elements/base/dialog.d.ts +1 -1
  4. package/elements/base/dialog.d.ts.map +1 -1
  5. package/elements/base/dialog.js +2 -2
  6. package/elements/base/dialog.js.map +1 -1
  7. package/elements/base/gesture.d.ts +1 -1
  8. package/elements/base/gesture.d.ts.map +1 -1
  9. package/elements/base/gesture.js +5 -5
  10. package/elements/base/gesture.js.map +1 -1
  11. package/elements/base/link.d.ts +1 -1
  12. package/elements/base/link.d.ts.map +1 -1
  13. package/elements/base/link.js +18 -19
  14. package/elements/base/link.js.map +1 -1
  15. package/elements/base/modal-factory.d.ts +93 -57
  16. package/elements/base/modal-factory.d.ts.map +1 -1
  17. package/elements/base/modal-factory.js +4 -3
  18. package/elements/base/modal-factory.js.map +1 -1
  19. package/elements/base/reflect.d.ts +1 -2
  20. package/elements/base/reflect.d.ts.map +1 -1
  21. package/elements/base/reflect.js +8 -10
  22. package/elements/base/reflect.js.map +1 -1
  23. package/elements/base/route.d.ts +18 -8
  24. package/elements/base/route.d.ts.map +1 -1
  25. package/elements/base/route.js +17 -21
  26. package/elements/base/route.js.map +1 -1
  27. package/elements/base/title.d.ts +1 -1
  28. package/elements/base/title.d.ts.map +1 -1
  29. package/elements/base/title.js +5 -7
  30. package/elements/base/title.js.map +1 -1
  31. package/elements/base/unsafe.d.ts +4 -3
  32. package/elements/base/unsafe.d.ts.map +1 -1
  33. package/elements/base/unsafe.js +45 -24
  34. package/elements/base/unsafe.js.map +1 -1
  35. package/elements/base/use.d.ts +1 -1
  36. package/elements/base/use.d.ts.map +1 -1
  37. package/elements/base/use.js +1 -1
  38. package/elements/base/use.js.map +1 -1
  39. package/elements/link.js +1 -1
  40. package/elements/link.js.map +1 -1
  41. package/elements/route.js +1 -1
  42. package/elements/route.js.map +1 -1
  43. package/helper/hmr.d.ts +11 -0
  44. package/helper/hmr.d.ts.map +1 -0
  45. package/helper/hmr.js +255 -0
  46. package/helper/hmr.js.map +1 -0
  47. package/helper/i18n.d.ts +2 -2
  48. package/helper/i18n.d.ts.map +1 -1
  49. package/helper/i18n.js +5 -4
  50. package/helper/i18n.js.map +1 -1
  51. package/helper/logger.d.ts +1 -1
  52. package/helper/logger.d.ts.map +1 -1
  53. package/helper/logger.js +8 -5
  54. package/helper/logger.js.map +1 -1
  55. package/helper/mediaquery.js +1 -1
  56. package/helper/mediaquery.js.map +1 -1
  57. package/helper/react-utils.d.ts.map +1 -1
  58. package/helper/react-utils.js +2 -6
  59. package/helper/react-utils.js.map +1 -1
  60. package/helper/ssr-shim.d.ts.map +1 -1
  61. package/helper/ssr-shim.js +2 -1
  62. package/helper/ssr-shim.js.map +1 -1
  63. package/helper/theme.d.ts +17 -6
  64. package/helper/theme.d.ts.map +1 -1
  65. package/helper/theme.js +23 -8
  66. package/helper/theme.js.map +1 -1
  67. package/index.d.ts +1 -2
  68. package/index.d.ts.map +1 -1
  69. package/index.js +1 -3
  70. package/index.js.map +1 -1
  71. package/lib/decorators.d.ts +54 -62
  72. package/lib/decorators.d.ts.map +1 -1
  73. package/lib/decorators.js +90 -91
  74. package/lib/decorators.js.map +1 -1
  75. package/lib/directive.d.ts +0 -18
  76. package/lib/directive.d.ts.map +1 -1
  77. package/lib/directive.js +1 -2
  78. package/lib/directive.js.map +1 -1
  79. package/lib/element.d.ts +8 -137
  80. package/lib/element.d.ts.map +1 -1
  81. package/lib/element.js +16 -481
  82. package/lib/element.js.map +1 -1
  83. package/lib/history.d.ts +68 -10
  84. package/lib/history.d.ts.map +1 -1
  85. package/lib/history.js +15 -15
  86. package/lib/history.js.map +1 -1
  87. package/lib/lit-html.d.ts +7 -109
  88. package/lib/lit-html.d.ts.map +1 -1
  89. package/lib/lit-html.js +75 -32
  90. package/lib/lit-html.js.map +1 -1
  91. package/lib/reactive.d.ts +130 -0
  92. package/lib/reactive.d.ts.map +1 -0
  93. package/lib/reactive.js +474 -0
  94. package/lib/reactive.js.map +1 -0
  95. package/lib/repeat.d.ts +3 -3
  96. package/lib/repeat.d.ts.map +1 -1
  97. package/lib/repeat.js +3 -3
  98. package/lib/repeat.js.map +1 -1
  99. package/lib/store.d.ts +15 -4
  100. package/lib/store.d.ts.map +1 -1
  101. package/lib/store.js +2 -0
  102. package/lib/store.js.map +1 -1
  103. package/lib/utils.d.ts +26 -11
  104. package/lib/utils.d.ts.map +1 -1
  105. package/lib/utils.js +21 -14
  106. package/lib/utils.js.map +1 -1
  107. package/package.json +3 -3
  108. package/src/dist.ts +6 -8
  109. package/src/elements/base/dialog.ts +2 -2
  110. package/src/elements/base/gesture.ts +6 -6
  111. package/src/elements/base/link.ts +18 -24
  112. package/src/elements/base/modal-factory.ts +4 -3
  113. package/src/elements/base/reflect.ts +2 -3
  114. package/src/elements/base/route.ts +21 -28
  115. package/src/elements/base/title.ts +6 -8
  116. package/src/elements/base/unsafe.ts +33 -14
  117. package/src/elements/base/use.ts +1 -1
  118. package/src/elements/link.ts +1 -1
  119. package/src/elements/route.ts +1 -1
  120. package/src/helper/hmr.ts +305 -0
  121. package/src/helper/i18n.ts +7 -7
  122. package/src/helper/logger.ts +9 -5
  123. package/src/helper/mediaquery.ts +1 -1
  124. package/src/helper/react-utils.ts +4 -12
  125. package/src/helper/ssr-shim.ts +3 -1
  126. package/src/helper/theme.ts +29 -14
  127. package/src/index.ts +1 -4
  128. package/src/lib/decorators.ts +107 -117
  129. package/src/lib/directive.ts +3 -5
  130. package/src/lib/element.ts +21 -600
  131. package/src/lib/history.ts +16 -18
  132. package/src/lib/lit-html.ts +89 -34
  133. package/src/lib/reactive.ts +620 -0
  134. package/src/lib/repeat.ts +5 -5
  135. package/src/lib/store.ts +4 -2
  136. package/src/lib/utils.ts +41 -29
  137. package/src/test/elements/link.test.ts +2 -2
  138. package/src/test/elements/reflect.test.ts +3 -3
  139. package/src/test/elements/title.test.ts +2 -2
  140. package/src/test/gem-element/advance.test.ts +11 -10
  141. package/src/test/gem-element/basic.test.ts +4 -5
  142. package/src/test/gem-element/decorators.test.ts +10 -10
  143. package/src/test/gem-element/multi.test.ts +2 -2
  144. package/src/test/history.test.ts +1 -2
  145. package/src/test/store.test.ts +2 -3
  146. package/src/test/utils.test.ts +5 -6
  147. package/src/test/utils.ts +2 -2
  148. package/helper/react-shim.d.ts +0 -15
  149. package/helper/react-shim.d.ts.map +0 -1
  150. package/helper/react-shim.js +0 -56
  151. package/helper/react-shim.js.map +0 -1
  152. package/lib/directives.d.ts +0 -4
  153. package/lib/directives.d.ts.map +0 -1
  154. package/lib/directives.js +0 -5
  155. package/lib/directives.js.map +0 -1
  156. package/lib/ref.d.ts +0 -1
  157. package/lib/ref.d.ts.map +0 -1
  158. package/lib/ref.js +0 -2
  159. package/lib/ref.js.map +0 -1
package/src/lib/utils.ts CHANGED
@@ -1,15 +1,34 @@
1
1
  const { assign, fromEntries, entries, keys } = Object;
2
2
 
3
+ // 用原生 Chrome 找不到调用栈
4
+ function queueMicrotask(cb: () => void) {
5
+ Promise.resolve().then(cb);
6
+ }
7
+
3
8
  const microtaskSet = new Set<() => void>();
4
- export function addMicrotask(func: () => void) {
9
+ export function addMicrotask(func: () => void, method = queueMicrotask) {
5
10
  if (microtaskSet.has(func)) return;
6
- queueMicrotask(() => {
11
+ method(() => {
7
12
  microtaskSet.delete(func);
8
13
  func();
9
14
  });
10
15
  microtaskSet.add(func);
11
16
  }
12
17
 
18
+ type OverrideFn = {
19
+ name: never;
20
+ apply: never;
21
+ call: never;
22
+ bind: never;
23
+ toString: never;
24
+ prototype: never;
25
+ length: never;
26
+ arguments: never;
27
+ caller: never;
28
+ [Symbol.hasInstance]: never;
29
+ [Symbol.metadata]: never;
30
+ };
31
+
13
32
  // 注意 typeof state === 'function' 但是没有 Function 的方法和属性
14
33
  export function createUpdater<T, Fn = (payload?: Partial<T>) => any>(initState: T, fn: Fn) {
15
34
  const state: any = fn;
@@ -18,10 +37,13 @@ export function createUpdater<T, Fn = (payload?: Partial<T>) => any>(initState:
18
37
  delete state.name;
19
38
  delete state.length;
20
39
  assign(state, initState);
21
- // TODO: type
22
- return state as Fn & T;
40
+ // ts 不允许直接 Omit 掉 Fn 上的属性
41
+ // 只能利用 ts plugin 移除多余的自动完成项
42
+ return state as Fn & Omit<OverrideFn, keyof T> & T;
23
43
  }
24
44
 
45
+ export type Updater<T, Fn = (payload?: Partial<T>) => any> = ReturnType<typeof createUpdater<T, Fn>>;
46
+
25
47
  // 不编码 hash 用于比较
26
48
  export function absoluteLocation(currentPath = '', relativePath = '') {
27
49
  const { pathname, search, hash } = new URL(relativePath, location.origin + currentPath);
@@ -107,8 +129,10 @@ export class LinkedList<T = any> extends EventTarget {
107
129
  return this.#map.get(value);
108
130
  }
109
131
 
110
- // 添加到尾部,已存在时会删除老的项目
111
- // 如果是添加第一个,start 事件会在添加前触发,避免处理事件重复的逻辑
132
+ /**
133
+ * 添加到尾部,已存在时会删除老的项目
134
+ * 如果是添加第一个,start 事件会在添加前触发,避免处理事件重复的逻辑
135
+ */
112
136
  add(value: T) {
113
137
  if (!this.#lastItem) {
114
138
  this.dispatchEvent(new CustomEvent('start'));
@@ -126,7 +150,7 @@ export class LinkedList<T = any> extends EventTarget {
126
150
  this.#map.set(value, item);
127
151
  }
128
152
 
129
- // 删除这个元素后没有其他元素时立即出发 end 事件
153
+ /** 删除这个元素后没有其他元素时立即出发 end 事件 */
130
154
  delete(value: T) {
131
155
  const deleteItem = this.#delete(value);
132
156
  if (!this.#firstItem) {
@@ -135,8 +159,12 @@ export class LinkedList<T = any> extends EventTarget {
135
159
  return deleteItem;
136
160
  }
137
161
 
138
- // 获取头部元素
139
- // 会从链表删除
162
+ clear() {
163
+ this.#map.clear();
164
+ this.#firstItem = this.#lastItem = undefined;
165
+ }
166
+
167
+ /** 获取头部元素,会从链表删除 */
140
168
  get(): T | undefined {
141
169
  const firstItem = this.#firstItem;
142
170
  if (!firstItem) return;
@@ -157,10 +185,6 @@ export class PropProxyMap<T extends NonPrimitive, V = unknown> extends WeakMap<T
157
185
  }
158
186
 
159
187
  export class QueryString extends URLSearchParams {
160
- constructor(param?: any) {
161
- super(param);
162
- }
163
-
164
188
  // support `{ key: ObjectValue }`
165
189
  concat(param: any) {
166
190
  let query: any;
@@ -236,7 +260,7 @@ export function randomStr(len = 5): string {
236
260
  }
237
261
 
238
262
  export function camelToKebabCase(str: string) {
239
- return str.replace(/[A-Z]/g, ($1: string) => '-' + $1.toLowerCase());
263
+ return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
240
264
  }
241
265
 
242
266
  export function kebabToCamelCase(str: string) {
@@ -269,25 +293,18 @@ export function isArrayChange(newValues: any[], oldValues: any[]) {
269
293
  export function objectMapToString<T = any>(
270
294
  object: Record<string, T>,
271
295
  separate: string,
272
- toString: (key: string, value: T) => string,
296
+ toStr: (key: string, value: T) => string,
273
297
  ) {
274
298
  let result = separate;
275
299
  for (const key in object) {
276
- const s = toString(key, object[key]);
300
+ const s = toStr(key, object[key]);
277
301
  result += s ? s + separate : '';
278
302
  }
279
303
  return result;
280
304
  }
281
305
 
282
306
  // Wait: Typescript lib dom CSSStyleDeclaration anchor position
283
- type StyleProp =
284
- | keyof CSSStyleDeclaration
285
- | `--${string}`
286
- | 'scrollbarWidth'
287
- | 'scrollbarColor'
288
- | 'positionAnchor'
289
- | 'anchorDefault'
290
- | 'anchorName';
307
+ type StyleProp = keyof CSSStyleDeclaration | `--${string}` | 'positionAnchor' | 'anchorDefault' | 'anchorName';
291
308
 
292
309
  export type StyleObject = Partial<Record<StyleProp, string | number | false | undefined | null>>;
293
310
 
@@ -310,8 +327,3 @@ export function exportPartsMap(object: Record<string, string | boolean | undefin
310
327
  value === true || key === value ? key : value ? `${key}:${value}` : '',
311
328
  );
312
329
  }
313
-
314
- declare global {
315
- interface PropertyIndexedKeyframes extends StyleObject {}
316
- interface Keyframe extends StyleObject {}
317
- }
@@ -1,6 +1,6 @@
1
- import { fixture, expect } from '../utils';
2
- import { html } from '../../lib/element';
3
1
  import type { GemActiveLinkElement } from '../../elements/link';
2
+ import { html } from '../../lib/element';
3
+ import { expect, fixture } from '../utils';
4
4
 
5
5
  import '../../elements/link';
6
6
 
@@ -1,7 +1,7 @@
1
- import { fixture, expect, nextFrame } from '../utils';
2
- import { css, GemElement, html } from '../../lib/element';
3
- import { adoptedStyle, customElement } from '../../lib/decorators';
4
1
  import type { GemReflectElement } from '../../elements/reflect';
2
+ import { adoptedStyle, customElement } from '../../lib/decorators';
3
+ import { css, GemElement, html } from '../../lib/element';
4
+ import { expect, fixture, nextFrame } from '../utils';
5
5
 
6
6
  import '../../elements/reflect';
7
7
 
@@ -1,6 +1,6 @@
1
- import { fixture, expect, nextFrame } from '../utils';
2
- import { html } from '../../lib/element';
3
1
  import type { GemTitleElement } from '../../elements/title';
2
+ import { html } from '../../lib/element';
3
+ import { expect, fixture, nextFrame } from '../utils';
4
4
 
5
5
  import '../../elements/title';
6
6
 
@@ -6,21 +6,22 @@
6
6
  * - 派生元素(类扩展)
7
7
  * - 无渲染内容 Gem 元素
8
8
  */
9
- import { fixture, expect, nextFrame } from '../utils';
10
- import type { Metadata } from '../../lib/element';
11
- import { css, createState, GemElement, html, createRef } from '../../lib/element';
12
- import { createStore } from '../../lib/store';
9
+
13
10
  import {
11
+ adoptedStyle,
12
+ async,
14
13
  attribute,
15
- property,
14
+ connectStore,
16
15
  customElement,
17
16
  emitter,
18
- adoptedStyle,
19
- connectStore,
20
- async,
21
- shadow,
22
17
  mounted,
18
+ property,
19
+ shadow,
23
20
  } from '../../lib/decorators';
21
+ import type { Metadata } from '../../lib/element';
22
+ import { createRef, createState, css, GemElement, html } from '../../lib/element';
23
+ import { createStore } from '../../lib/store';
24
+ import { expect, fixture, nextFrame } from '../utils';
24
25
 
25
26
  const store = createStore({
26
27
  a: 1,
@@ -340,7 +341,7 @@ describe('gem element 继承', () => {
340
341
  });
341
342
  el.sayHi();
342
343
  await Promise.resolve();
343
- expect(window.name).to.equal(name + '21');
344
+ expect(window.name).to.equal(`${name}21`);
344
345
  });
345
346
  });
346
347
  @customElement('render-empty')
@@ -1,6 +1,3 @@
1
- import { fixture, expect, nextFrame } from '../utils';
2
- import { css, createState, GemElement, html } from '../../lib/element';
3
- import { createStore } from '../../lib/store';
4
1
  import {
5
2
  adoptedStyle,
6
3
  attribute,
@@ -12,6 +9,9 @@ import {
12
9
  property,
13
10
  shadow,
14
11
  } from '../../lib/decorators';
12
+ import { createState, css, GemElement, html } from '../../lib/element';
13
+ import { createStore } from '../../lib/store';
14
+ import { expect, fixture, nextFrame } from '../utils';
15
15
 
16
16
  const store = createStore({
17
17
  a: 1,
@@ -108,8 +108,7 @@ describe('基本 gem element 测试', () => {
108
108
  expect(el.disabled).to.equal(true);
109
109
  expect(el.count).to.equal(2);
110
110
  expect(el.shadowRoot?.textContent).to.equal('attr: value, disabled: true, count: 2, prop: , state: ');
111
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
112
- // @ts-ignore
111
+ // @ts-expect-error
113
112
  el.attr = null;
114
113
  await Promise.resolve();
115
114
  expect(el.hasAttribute('attr')).to.equal(false);
@@ -1,22 +1,22 @@
1
- import { fixture, expect } from '../utils';
2
- import type { Metadata } from '../../lib/element';
3
- import { css, GemElement, html } from '../../lib/element';
4
- import { createStore } from '../../lib/store';
5
1
  import type { Emitter } from '../../lib/decorators';
6
2
  import {
3
+ adoptedStyle,
7
4
  attribute,
8
- property,
9
- customElement,
5
+ boolattribute,
10
6
  connectStore,
11
- adoptedStyle,
7
+ customElement,
12
8
  emitter,
13
- boolattribute,
14
9
  numattribute,
15
10
  part,
11
+ property,
12
+ shadow,
16
13
  slot,
17
14
  state,
18
- shadow,
19
15
  } from '../../lib/decorators';
16
+ import type { Metadata } from '../../lib/element';
17
+ import { css, GemElement, html } from '../../lib/element';
18
+ import { createStore } from '../../lib/store';
19
+ import { expect, fixture } from '../utils';
20
20
 
21
21
  const store = createStore({
22
22
  a: 1,
@@ -81,7 +81,7 @@ describe('装饰器', () => {
81
81
  store({ a: 1 });
82
82
  await Promise.resolve();
83
83
  const metadata: Metadata = Reflect.get(DecoratorGemElement, Symbol.metadata);
84
- expect({ ...metadata.observedStores.at(0) }).to.eql({ a: 1 });
84
+ expect({ ...metadata.observedStores?.at(0) }).to.eql({ a: 1 });
85
85
  expect(metadata.observedAttributes).to.eql(['rank-attr', 'rank-disabled', 'rank-count']);
86
86
  expect(metadata.definedEvents).to.eql(['say-hi']);
87
87
  expect(metadata.definedCSSStates).to.eql(['open-state']);
@@ -1,6 +1,6 @@
1
+ import { attribute, customElement, type Emitter, emitter, mounted, property } from '../../lib/decorators';
2
+ import { createRef, createState, GemElement, html } from '../../lib/element';
1
3
  import { expect, fixture } from '../utils';
2
- import { attribute, customElement, emitter, mounted, property, type Emitter } from '../../lib/decorators';
3
- import { GemElement, html, createRef, createState } from '../../lib/element';
4
4
 
5
5
  @customElement('app-children')
6
6
  export class Children extends GemElement {
@@ -1,6 +1,5 @@
1
1
  import { history } from '../lib/history';
2
-
3
- import { expect, aTimeout } from './utils';
2
+ import { aTimeout, expect } from './utils';
4
3
 
5
4
  describe('history 测试', () => {
6
5
  it('hash', async () => {
@@ -1,6 +1,5 @@
1
- import { _StoreListenerMap, createStore, connect } from '../lib/store';
2
-
3
- import { expect, aTimeout } from './utils';
1
+ import { _StoreListenerMap, connect, createStore } from '../lib/store';
2
+ import { aTimeout, expect } from './utils';
4
3
 
5
4
  describe('store 测试', () => {
6
5
  it('create store', () => {
@@ -1,15 +1,14 @@
1
1
  import { css, SheetToken } from '../lib/element';
2
2
  import {
3
+ absoluteLocation,
4
+ classMap,
5
+ exportPartsMap,
3
6
  LinkedList,
4
7
  QueryString,
5
8
  raw,
6
9
  styled,
7
10
  styleMap,
8
- classMap,
9
- exportPartsMap,
10
- absoluteLocation,
11
11
  } from '../lib/utils';
12
-
13
12
  import { expect } from './utils';
14
13
 
15
14
  declare global {
@@ -77,7 +76,7 @@ describe('utils 测试', () => {
77
76
  query.setAny('obj', [{ a: 1, b: 2 }]);
78
77
  expect(query.getAny('obj')).to.deep.equal({ a: 1, b: 2 });
79
78
  expect(query.getAnyAll('obj')).to.deep.equal([{ a: 1, b: 2 }]);
80
- expect(new QueryString({ a: 1 }).toString()).to.equal('?a=1');
79
+ expect(new QueryString({ a: '1' }).toString()).to.equal('?a=1');
81
80
  expect(new QueryString(query).toString()).to.equal(query.toString());
82
81
  });
83
82
  it('css', () => {
@@ -111,7 +110,7 @@ describe('utils 测试', () => {
111
110
  });
112
111
  expect(cssSheet.scroll.startsWith('scroll')).to.true;
113
112
  const rules = cssSheet[SheetToken].getStyle().cssRules;
114
- expect(rules.item(0).selectorText).to.equal(':where(:scope:not([hidden])), :host(:where(:not([hidden])))');
113
+ expect(rules.item(0).selectorText).to.equal(':where(&:not([hidden])), :host(:where(:not([hidden])))');
115
114
  expect(rules.item(1).selectorText.startsWith('.scroll')).to.true;
116
115
  expect(rules.item(1).style.background).to.equal('red');
117
116
  expect(rules.item(1).cssRules.item(0).selectorText).to.equal('&:hover *');
package/src/test/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { expect, should, assert } from 'chai';
1
+ import { assert, expect, should } from 'chai';
2
2
 
3
- import { render } from '../lib/element';
4
3
  import type { TemplateResult } from '../lib/element';
4
+ import { render } from '../lib/element';
5
5
 
6
6
  export { expect, should, assert };
7
7
 
@@ -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,CAAC;IACrB,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5B,QAAQ;IACR,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAEvB,WAAW;IACX,MAAM,QAAQ,GAAG,GAAG,YAAY,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;IAC7D,MAAM,eAAe,GAAG,QAAQ,CAAC,SAAS,CAAC;IAC3C,IAAI,CAAC,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,KAAK,CAAA,EAAE,CAAC;QAC5B,QAAQ,CAAC,SAAS,GAAG,GAAG,EAAE;YACxB,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;YACjC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC,CAAC;QACF,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,IAAI,CAAC;IAClC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAmB,KAAe;IAC5D,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjC,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,IAAe;IAC1C,MAAM,GAAG,GAAG,MAAM,EAA0C,CAAC;IAC7D,4MAA4M;IAC5M,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,WAAC,OAAA,MAAA,GAAG,CAAC,OAAO,0CAAE,IAAI,CAAC,OAAO,EAAE,CAAA,EAAA,EAAE,EAAE,CAAC,CAAC;IACvD,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;QAChB,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;IAC/B,CAAC;IACD,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,KAAK,CAAC,OAAO,GAAG,UAAU,CAAC;IACrC,MAAM,IAAI,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACnC,GAAG,CAAC,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IAClC,oMAAoM;IACpM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClB,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -1,4 +0,0 @@
1
- export { repeat } from 'lit-html/directives/repeat';
2
- export { guard } from 'lit-html/directives/guard';
3
- export { ifDefined } from 'lit-html/directives/if-defined';
4
- //# sourceMappingURL=directives.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../src/lib/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC"}
package/lib/directives.js DELETED
@@ -1,5 +0,0 @@
1
- export { repeat } from 'lit-html/directives/repeat';
2
- // https://github.com/Polymer/lit-html/issues/1048
3
- export { guard } from 'lit-html/directives/guard';
4
- export { ifDefined } from 'lit-html/directives/if-defined';
5
- //# sourceMappingURL=directives.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directives.js","sourceRoot":"","sources":["../src/lib/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,kDAAkD;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC"}
package/lib/ref.d.ts DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=ref.d.ts.map
package/lib/ref.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/lib/ref.ts"],"names":[],"mappings":""}
package/lib/ref.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=ref.js.map
package/lib/ref.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ref.js","sourceRoot":"","sources":["../src/lib/ref.ts"],"names":[],"mappings":""}