@mantou/gem 2.1.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 (52) hide show
  1. package/dist/gem.es.js +1018 -1019
  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 +2 -2
  12. package/elements/base/title.d.ts +0 -1
  13. package/elements/base/title.d.ts.map +1 -1
  14. package/elements/base/title.js +13 -3
  15. package/elements/base/title.js.map +1 -1
  16. package/elements/base/unsafe.d.ts +1 -1
  17. package/elements/base/unsafe.d.ts.map +1 -1
  18. package/elements/base/unsafe.js +10 -4
  19. package/elements/base/unsafe.js.map +1 -1
  20. package/elements/base/use.d.ts +0 -1
  21. package/elements/base/use.d.ts.map +1 -1
  22. package/elements/base/use.js +11 -2
  23. package/elements/base/use.js.map +1 -1
  24. package/lib/decorators.d.ts.map +1 -1
  25. package/lib/decorators.js +3 -3
  26. package/lib/decorators.js.map +1 -1
  27. package/lib/element.d.ts +2 -2
  28. package/lib/element.d.ts.map +1 -1
  29. package/lib/element.js +8 -7
  30. package/lib/element.js.map +1 -1
  31. package/lib/utils.d.ts.map +1 -1
  32. package/lib/utils.js +1 -0
  33. package/lib/utils.js.map +1 -1
  34. package/lib/version.d.ts +1 -1
  35. package/lib/version.d.ts.map +1 -1
  36. package/lib/version.js +1 -2
  37. package/lib/version.js.map +1 -1
  38. package/package.json +2 -3
  39. package/src/elements/base/gesture.ts +23 -25
  40. package/src/elements/base/link.ts +9 -9
  41. package/src/elements/base/title.ts +3 -2
  42. package/src/elements/base/unsafe.ts +6 -3
  43. package/src/elements/base/use.ts +4 -3
  44. package/src/lib/decorators.ts +3 -3
  45. package/src/lib/element.ts +8 -7
  46. package/src/lib/utils.ts +1 -0
  47. package/src/lib/version.ts +1 -2
  48. package/LICENSE +0 -21
  49. package/helper/react-shim.d.ts +0 -15
  50. package/helper/react-shim.d.ts.map +0 -1
  51. package/helper/react-shim.js +0 -56
  52. package/helper/react-shim.js.map +0 -1
@@ -35,13 +35,13 @@ defineProperty(Symbol, 'metadata', { value: Symbol.for('Symbol.metadata') });
35
35
 
36
36
  const execCallback = (fun: any) => typeof fun === 'function' && fun();
37
37
 
38
- // 跨多个 gem 工作
38
+ // 读取构造样式表,跨多个 gem 工作
39
39
  export const SheetToken = Symbol.for('gem@sheetToken');
40
- // proto prop
40
+ // 更新元素,跨多个 gem 工作
41
41
  export const UpdateToken = Symbol.for('gem@update');
42
42
 
43
43
  const BoundaryCSSState = 'gem-style-boundary';
44
- export const RenderErrorEvent = 'gem@render-error';
44
+ export const _RenderErrorEvent = 'gem@render-error';
45
45
 
46
46
  // fix modal-factory type error
47
47
  const updateTokenAlias = UpdateToken;
@@ -261,7 +261,7 @@ function clearEffect(list: EffectItem<any>[]) {
261
261
  type Render = () => TemplateResult | null | undefined;
262
262
  type RenderItem = { render: Render; condition?: () => boolean };
263
263
 
264
- export let createTemplate: (ele: GemElement, item: RenderItem) => void;
264
+ export let _createTemplate: (ele: GemElement, item: RenderItem) => void;
265
265
 
266
266
  export type Metadata = Partial<ShadowRootInit> & {
267
267
  /** 内容可被外部样式化 */
@@ -341,7 +341,7 @@ export abstract class GemElement extends HTMLElement {
341
341
  return state;
342
342
  };
343
343
  createRef = () => new RefObject(currentConstructGemElement);
344
- createTemplate = (ele, item) => ele.#renderList.push(item);
344
+ _createTemplate = (ele, item) => ele.#renderList.push(item);
345
345
  }
346
346
 
347
347
  constructor() {
@@ -385,7 +385,8 @@ export abstract class GemElement extends HTMLElement {
385
385
  }
386
386
 
387
387
  get #renderItem() {
388
- return this.#renderList.find((e) => !e.condition || e.condition());
388
+ // 从末尾开始寻找,允许被覆盖
389
+ return this.#renderList.findLast((e) => !e.condition || e.condition());
389
390
  }
390
391
 
391
392
  get internals() {
@@ -419,7 +420,7 @@ export abstract class GemElement extends HTMLElement {
419
420
  if (temp === undefined) return;
420
421
  render(temp, this.#renderRoot);
421
422
  } catch (err) {
422
- this.dispatchEvent(new CustomEvent(RenderErrorEvent, { bubbles: true, composed: true, detail: err }));
423
+ this.dispatchEvent(new CustomEvent(_RenderErrorEvent, { bubbles: true, composed: true, detail: err }));
423
424
  }
424
425
  };
425
426
 
package/src/lib/utils.ts CHANGED
@@ -10,6 +10,7 @@ export function addMicrotask(func: () => void) {
10
10
  microtaskSet.add(func);
11
11
  }
12
12
 
13
+ // 注意 typeof state === 'function' 但是没有 Function 的方法和属性
13
14
  export function createUpdater<T, Fn = (payload?: Partial<T>) => any>(initState: T, fn: Fn) {
14
15
  const state: any = fn;
15
16
  setPrototypeOf(state, null);
@@ -1,2 +1 @@
1
- // Do not modify manually
2
- export const version = '0.0.0';
1
+ export const version = '2.1.1';
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,EAA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