@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/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAG9B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
package/index.js CHANGED
@@ -1,8 +1,6 @@
1
- export * from './lib/decorators';
2
1
  export * from './lib/element';
2
+ export * from './lib/history';
3
3
  export * from './lib/store';
4
4
  export * from './lib/utils';
5
5
  export * from './lib/version';
6
- // 使用路径时可选模块
7
- export * from './lib/history';
8
6
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAE9B,YAAY;AACZ,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
@@ -1,18 +1,15 @@
1
- import type { css, Metadata, TemplateResult } from './element';
2
- import { GemElement } from './element';
1
+ import type { TemplateResult } from './lit-html';
2
+ import type { Metadata, Sheet } from './reactive';
3
+ import { GemElement } from './reactive';
3
4
  import type { Store } from './store';
4
- import * as elementExports from './element';
5
- import * as decoratorsExports from './decorators';
6
- import * as storeExports from './store';
7
- import * as versionExports from './version';
8
5
  /**
9
6
  * 定义一个响应式的 attribute,驼峰字段名将自动映射到烤串 attribute,默认值为空字符串;不要覆盖定义
10
7
  *
11
- * For example
8
+ * @example
12
9
  * ```ts
13
- * class App extends GemElement {
14
- * @attribute attr: string;
15
- * }
10
+ * class App extends GemElement {
11
+ * @​attribute attr: string;
12
+ * }
16
13
  * ```
17
14
  */
18
15
  export declare function attribute<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T, string>): (this: any, initValue: any) => any;
@@ -21,25 +18,25 @@ export declare function numattribute<T extends GemElement>(_: undefined, context
21
18
  /**
22
19
  * 定义一个响应式的 property,注意值可能为 `undefined`;不要覆盖定义
23
20
  *
24
- * For example
21
+ * @example
25
22
  * ```ts
26
- * class App extends GemElement {
27
- * @property prop: Data | undefined;
28
- * }
23
+ * class App extends GemElement {
24
+ * @​property prop: Data | undefined;
25
+ * }
29
26
  * ```
30
27
  */
31
28
  export declare function property<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T>): (this: any, initValue: any) => any;
32
29
  /**
33
30
  * 依赖 `GemElement.memo`
34
31
  *
35
- * For example
32
+ * @example
36
33
  * ```ts
37
- * class App extends GemElement {
38
- * @memo(() => [])
39
- * get data() {
40
- * return 1;
41
- * }
42
- * }
34
+ * class App extends GemElement {
35
+ * @​memo(() => [])
36
+ * get data() {
37
+ * return 1;
38
+ * }
39
+ * }
43
40
  * ```
44
41
  */
45
42
  export declare function memo<T extends GemElement, V = any, K = any[] | undefined>(getDep?: K extends readonly any[] ? (instance: T) => K : undefined): (_: any, context: ClassGetterDecoratorContext<T, V> | ClassFieldDecoratorContext<T> | ClassMethodDecoratorContext<T>) => void;
@@ -48,14 +45,14 @@ export declare function memo<T extends GemElement, V = any, K = any[] | undefine
48
45
  * - 方法执行在字段前面
49
46
  * - 如果没有 oldValue,在为首次执行
50
47
  *
51
- * For example
48
+ * @example
52
49
  * ```ts
53
- * class App extends GemElement {
54
- * @effect(() => [])
55
- * #fetchData(newValue, oldValue) {
56
- * console.log('fetch')
57
- * }
58
- * }
50
+ * class App extends GemElement {
51
+ * @​effect(() => [])
52
+ * #fetchData(newValue, oldValue) {
53
+ * console.log('fetch')
54
+ * }
55
+ * }
59
56
  * ```
60
57
  */
61
58
  export declare function effect<T extends GemElement, V extends (depValues: K, oldDepValues?: K) => any, K = any[] | undefined>(getDep?: K extends readonly any[] ? (instance: T) => K : undefined): (_: any, { addInitializer, access }: ClassFieldDecoratorContext<T, V> | ClassMethodDecoratorContext<T, V>) => void;
@@ -74,48 +71,48 @@ export declare function fallback<T extends GemElement, V extends (err: any) => T
74
71
  * 重新赋值转换 css 伪类
75
72
  * 将来也可能用于 IDE 识别
76
73
  *
77
- * For example
74
+ * @example
78
75
  * ```ts
79
- * class App extends GemElement {
80
- * @state state: boolean;
81
- * }
76
+ * class App extends GemElement {
77
+ * @​state state: boolean;
78
+ * }
82
79
  * ```
83
80
  */
84
81
  export declare function state<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T, boolean>): void;
85
82
  /**
86
83
  * 定义一个内部 slot,默认值即为字段名,不能使用全局属性 `slot`
87
84
  *
88
- * For example
85
+ * @example
89
86
  * ```ts
90
- * class App extends GemElement {
91
- * @slot slot: string;
92
- * @slot static slot: string;
93
- * }
87
+ * class App extends GemElement {
88
+ * @​slot slot: string;
89
+ * @​slot static slot: string;
90
+ * }
94
91
  * ```
95
92
  */
96
93
  export declare function slot(_: undefined, context: ClassFieldDecoratorContext<any, string>): (this: any, value: string) => string;
97
94
  /**
98
95
  * 定义一个内部 part,默认值即为字段名,不能使用全局属性 `part`
99
96
  *
100
- * For example
97
+ * @example
101
98
  * ```ts
102
- * class App extends GemElement {
103
- * @part part: string;
104
- * @part static part: string;
105
- * }
99
+ * class App extends GemElement {
100
+ * @​part part: string;
101
+ * @​part static part: string;
102
+ * }
106
103
  * ```
107
104
  */
108
105
  export declare function part(_: undefined, context: ClassFieldDecoratorContext<any, string>): (this: any, value: string) => string;
109
- export type Emitter<T = any> = (detail?: T, options?: Omit<CustomEventInit<unknown>, 'detail'>) => Promise<void> | void;
106
+ export type Emitter<T = any> = ((detail?: T, options?: Omit<CustomEventInit<unknown>, 'detail'>) => Promise<void> | void) & {};
110
107
  /**
111
108
  * 定义一个事件发射器,类似 `HTMLElement.click`,
112
109
  * 调用时将同步发送一个和字段名称的烤串式格式的自定义事件
113
110
  *
114
- * For example
111
+ * @example
115
112
  * ```ts
116
- * class App extends GemElement {
117
- * @emitter load: Function;
118
- * }
113
+ * class App extends GemElement {
114
+ * @​emitter load: Function;
115
+ * }
119
116
  * ```
120
117
  */
121
118
  export declare function emitter<T extends GemElement>(_: undefined, context: ClassFieldDecoratorContext<T, Emitter>): void;
@@ -123,20 +120,20 @@ export declare function globalemitter<T extends GemElement>(_: undefined, contex
123
120
  /**
124
121
  * 分配一个构造的样式表,前面的优先级越高(因为装饰器是越近越早执行)
125
122
  *
126
- * For example
123
+ * @example
127
124
  * ```ts
128
- * @adoptedStyle(stylesheet)
129
- * class App extends GemElement {}
125
+ * ​@​adoptedStyle(stylesheet)
126
+ * class App extends GemElement {}
130
127
  * ```
131
128
  */
132
- export declare function adoptedStyle(sheet: ReturnType<typeof css>): (_: unknown, context: ClassDecoratorContext) => void;
129
+ export declare function adoptedStyle(sheet: Sheet<unknown>): (_: unknown, context: ClassDecoratorContext) => void;
133
130
  /**
134
131
  * 链接一个 store,当 store 更新时更新元素
135
132
  *
136
- * For example
133
+ * @example
137
134
  * ```ts
138
- * @connectStore(store)
139
- * class App extends GemElement {}
135
+ * ​@​connectStore(store)
136
+ * class App extends GemElement {}
140
137
  * ```
141
138
  */
142
139
  export declare function connectStore(store: Store<any>): (_: unknown, context: ClassDecoratorContext) => void;
@@ -154,16 +151,11 @@ export declare function aria(info: Metadata['aria']): (_: any, context: ClassDec
154
151
  /**
155
152
  * 定义自定义元素
156
153
  *
157
- * For example
154
+ * @example
158
155
  * ```ts
159
- * @customElement('my-element')
160
- * class App extends GemElement {}
156
+ * ​@​customElement('my-element')
157
+ * class App extends GemElement {}
161
158
  * ```
162
159
  */
163
160
  export declare function customElement(name: string): (cls: new (...args: any) => any, { addInitializer }: ClassDecoratorContext) => void;
164
- declare global {
165
- interface Window {
166
- __GEM_DEVTOOLS__HOOK__?: (typeof elementExports & typeof decoratorsExports & typeof storeExports & typeof versionExports) | Record<string, never>;
167
- }
168
- }
169
161
  //# sourceMappingURL=decorators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/lib/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,UAAU,EAA2D,MAAM,WAAW,CAAC;AAEhG,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,cAAc,MAAM,WAAW,CAAC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AI/C;AAED;;;GAGG;AACH,wBAAgB,KAAK,KACX,GAAG,GAAG,EAAE,SAAS,qBAAqB,UAI/C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,IACjC,GAAG,GAAG,EAAE,SAAS,qBAAqB,UAI/C;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,IAChC,KAAK,KAAK,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,EAAE,oBAAoB,qBAAqB,UAKlF"}
package/lib/decorators.js CHANGED
@@ -1,11 +1,8 @@
1
- import { GemElement, UpdateToken, _createTemplate, _RenderErrorEvent, render } from './element';
2
- import { camelToKebabCase, PropProxyMap, GemError } from './utils';
3
- import * as elementExports from './element';
4
- import * as decoratorsExports from './decorators';
5
- import * as storeExports from './store';
6
- import * as versionExports from './version';
1
+ // biome-ignore-all lint/plugin/no_this_effect: 定义装饰器
2
+ import { _createTemplate, _RenderErrorEvent, GemElement, render, UpdateToken } from './reactive';
3
+ import { camelToKebabCase, GemError, PropProxyMap } from './utils';
7
4
  const { deleteProperty, getOwnPropertyDescriptor, defineProperty } = Reflect;
8
- const { getPrototypeOf, assign } = Object;
5
+ const { getPrototypeOf, assign, hasOwn } = Object;
9
6
  const gemElementProxyMap = new PropProxyMap();
10
7
  function pushStaticField(context, field, member) {
11
8
  const metadata = context.metadata;
@@ -18,7 +15,8 @@ function pushStaticField(context, field, member) {
18
15
  metadata[field].push(member);
19
16
  }
20
17
  function clearField(instance, prop) {
21
- const { value } = getOwnPropertyDescriptor(instance, prop);
18
+ // hmr 支持不存在属性
19
+ const { value } = getOwnPropertyDescriptor(instance, prop) || {};
22
20
  deleteProperty(instance, prop);
23
21
  instance[prop] = value;
24
22
  }
@@ -27,20 +25,21 @@ const observedTargetAttributes = new WeakMap();
27
25
  // 不在 Devtools 中工作 https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#dom_access
28
26
  // 使用 Gem DevTools 注入脚本监听 attribute 变化
29
27
  const { setAttribute, toggleAttribute, removeAttribute } = Element.prototype;
28
+ const getObservedPropName = (i, n) => observedTargetAttributes.get(getPrototypeOf(i))?.get(n);
30
29
  GemElement.prototype.setAttribute = function (n, v) {
31
- const prop = observedTargetAttributes.get(getPrototypeOf(this))?.get(n);
30
+ const prop = getObservedPropName(this, n);
32
31
  if (!prop)
33
32
  return setAttribute.call(this, n, v);
34
33
  this[prop] = v;
35
34
  };
36
35
  GemElement.prototype.removeAttribute = function (n) {
37
- const prop = observedTargetAttributes.get(getPrototypeOf(this))?.get(n);
36
+ const prop = getObservedPropName(this, n);
38
37
  if (!prop)
39
38
  return removeAttribute.call(this, n);
40
39
  this[prop] = null;
41
40
  };
42
41
  GemElement.prototype.toggleAttribute = function (n, force) {
43
- const prop = observedTargetAttributes.get(getPrototypeOf(this))?.get(n);
42
+ const prop = getObservedPropName(this, n);
44
43
  if (!prop)
45
44
  return toggleAttribute.call(this, n, force);
46
45
  return (this[prop] = force ?? !this.hasAttribute(n));
@@ -113,7 +112,7 @@ function decoratorAttr(context, attrType) {
113
112
  const attr = camelToKebabCase(prop);
114
113
  context.addInitializer(function () {
115
114
  const target = getDecoratorTarget(this, context);
116
- if (!target.hasOwnProperty(prop)) {
115
+ if (!hasOwn(target, prop)) {
117
116
  pushStaticField(context, 'observedAttributes', attr); // 没有 observe 的效果
118
117
  defineProp(target, prop, { attr, attrType });
119
118
  }
@@ -132,11 +131,11 @@ function decoratorAttr(context, attrType) {
132
131
  /**
133
132
  * 定义一个响应式的 attribute,驼峰字段名将自动映射到烤串 attribute,默认值为空字符串;不要覆盖定义
134
133
  *
135
- * For example
134
+ * @example
136
135
  * ```ts
137
- * class App extends GemElement {
138
- * @attribute attr: string;
139
- * }
136
+ * class App extends GemElement {
137
+ * @​attribute attr: string;
138
+ * }
140
139
  * ```
141
140
  */
142
141
  export function attribute(_, context) {
@@ -151,18 +150,18 @@ export function numattribute(_, context) {
151
150
  /**
152
151
  * 定义一个响应式的 property,注意值可能为 `undefined`;不要覆盖定义
153
152
  *
154
- * For example
153
+ * @example
155
154
  * ```ts
156
- * class App extends GemElement {
157
- * @property prop: Data | undefined;
158
- * }
155
+ * class App extends GemElement {
156
+ * @​property prop: Data | undefined;
157
+ * }
159
158
  * ```
160
159
  */
161
160
  export function property(_, context) {
162
161
  const prop = context.name;
163
162
  context.addInitializer(function () {
164
163
  const target = getDecoratorTarget(this, context);
165
- if (!target.hasOwnProperty(prop)) {
164
+ if (!hasOwn(target, prop)) {
166
165
  pushStaticField(context, 'observedProperties', prop);
167
166
  defineProp(target, prop);
168
167
  }
@@ -176,18 +175,18 @@ export function property(_, context) {
176
175
  /**
177
176
  * 依赖 `GemElement.memo`
178
177
  *
179
- * For example
178
+ * @example
180
179
  * ```ts
181
- * class App extends GemElement {
182
- * @memo(() => [])
183
- * get data() {
184
- * return 1;
185
- * }
186
- * }
180
+ * class App extends GemElement {
181
+ * @​memo(() => [])
182
+ * get data() {
183
+ * return 1;
184
+ * }
185
+ * }
187
186
  * ```
188
187
  */
189
188
  export function memo(getDep) {
190
- return function (_, context) {
189
+ return (_, context) => {
191
190
  const { addInitializer, name, access, kind } = context;
192
191
  addInitializer(function () {
193
192
  const dep = getDep && (() => getDep(this));
@@ -195,10 +194,18 @@ export function memo(getDep) {
195
194
  // 不能设置私有字段 https://github.com/tc39/proposal-decorators/issues/509
196
195
  if (context.private)
197
196
  throw new GemError('not support');
198
- this.memo(() => defineProperty(this, name, { configurable: true, value: access.get(this) }), dep);
197
+ const target = getDecoratorTarget(this, context);
198
+ // 不能直接用 `access.get.bind(this)` 是现有 builder 工具的 bug?
199
+ const getter = getOwnPropertyDescriptor(target, name).get.bind(this);
200
+ this.memo(() => {
201
+ defineProperty(this, name, {
202
+ configurable: true,
203
+ value: getter(),
204
+ });
205
+ }, dep);
199
206
  }
200
207
  else {
201
- this.memo(access.get(this).bind(this), dep);
208
+ this.memo(access.get.call(this, this).bind(this), dep);
202
209
  }
203
210
  });
204
211
  };
@@ -208,27 +215,27 @@ export function memo(getDep) {
208
215
  * - 方法执行在字段前面
209
216
  * - 如果没有 oldValue,在为首次执行
210
217
  *
211
- * For example
218
+ * @example
212
219
  * ```ts
213
- * class App extends GemElement {
214
- * @effect(() => [])
215
- * #fetchData(newValue, oldValue) {
216
- * console.log('fetch')
217
- * }
218
- * }
220
+ * class App extends GemElement {
221
+ * @​effect(() => [])
222
+ * #fetchData(newValue, oldValue) {
223
+ * console.log('fetch')
224
+ * }
225
+ * }
219
226
  * ```
220
227
  */
221
228
  export function effect(getDep) {
222
- return function (_, { addInitializer, access }) {
229
+ return (_, { addInitializer, access }) => {
223
230
  addInitializer(function () {
224
- this.effect(access.get(this).bind(this), getDep && (() => getDep(this)));
231
+ this.effect(access.get.call(this, this).bind(this), getDep && (() => getDep(this)));
225
232
  });
226
233
  };
227
234
  }
228
235
  export function unmounted() {
229
- return function (_, { addInitializer, access }) {
236
+ return (_, { addInitializer, access }) => {
230
237
  addInitializer(function () {
231
- this.effect(() => access.get(this).bind(this), () => []);
238
+ this.effect(() => access.get.call(this, this).bind(this), () => []);
232
239
  });
233
240
  };
234
241
  }
@@ -243,20 +250,20 @@ export function mounted() {
243
250
  export function template(
244
251
  /** 当所有 `template` 返回 `false` 时不进行更新,包括 `memo` */
245
252
  condition) {
246
- return function (_, { addInitializer, access }) {
253
+ return (_, { addInitializer, access }) => {
247
254
  addInitializer(function () {
248
255
  _createTemplate(this, {
249
- render: access.get(this).bind(this),
256
+ render: access.get.call(this, this).bind(this),
250
257
  condition: condition && (() => condition(this)),
251
258
  });
252
259
  });
253
260
  };
254
261
  }
255
262
  export function fallback() {
256
- return function (_, { addInitializer, access }) {
263
+ return (_, { addInitializer, access }) => {
257
264
  addInitializer(function () {
258
265
  this.addEventListener(_RenderErrorEvent, ({ detail }) => {
259
- render(access.get(this).apply(this, [detail]), this.internals.shadowRoot || this);
266
+ render(access.get.call(this, this).apply(this, [detail]), this.internals.shadowRoot || this);
260
267
  });
261
268
  });
262
269
  };
@@ -287,11 +294,11 @@ function defineCSSState(target, prop, stateStr) {
287
294
  * 重新赋值转换 css 伪类
288
295
  * 将来也可能用于 IDE 识别
289
296
  *
290
- * For example
297
+ * @example
291
298
  * ```ts
292
- * class App extends GemElement {
293
- * @state state: boolean;
294
- * }
299
+ * class App extends GemElement {
300
+ * @​state state: boolean;
301
+ * }
295
302
  * ```
296
303
  */
297
304
  export function state(_, context) {
@@ -299,7 +306,7 @@ export function state(_, context) {
299
306
  const attr = camelToKebabCase(prop);
300
307
  context.addInitializer(function () {
301
308
  const target = getDecoratorTarget(this, context);
302
- if (!target.hasOwnProperty(prop)) {
309
+ if (!hasOwn(target, prop)) {
303
310
  pushStaticField(context, 'definedCSSStates', attr);
304
311
  defineCSSState(target, prop, attr);
305
312
  }
@@ -324,12 +331,12 @@ function defineStaticField(context, target, field, value) {
324
331
  /**
325
332
  * 定义一个内部 slot,默认值即为字段名,不能使用全局属性 `slot`
326
333
  *
327
- * For example
334
+ * @example
328
335
  * ```ts
329
- * class App extends GemElement {
330
- * @slot slot: string;
331
- * @slot static slot: string;
332
- * }
336
+ * class App extends GemElement {
337
+ * @​slot slot: string;
338
+ * @​slot static slot: string;
339
+ * }
333
340
  * ```
334
341
  */
335
342
  export function slot(_, context) {
@@ -340,12 +347,12 @@ export function slot(_, context) {
340
347
  /**
341
348
  * 定义一个内部 part,默认值即为字段名,不能使用全局属性 `part`
342
349
  *
343
- * For example
350
+ * @example
344
351
  * ```ts
345
- * class App extends GemElement {
346
- * @part part: string;
347
- * @part static part: string;
348
- * }
352
+ * class App extends GemElement {
353
+ * @​part part: string;
354
+ * @​part static part: string;
355
+ * }
349
356
  * ```
350
357
  */
351
358
  export function part(_, context) {
@@ -357,11 +364,11 @@ export function part(_, context) {
357
364
  * 定义一个事件发射器,类似 `HTMLElement.click`,
358
365
  * 调用时将同步发送一个和字段名称的烤串式格式的自定义事件
359
366
  *
360
- * For example
367
+ * @example
361
368
  * ```ts
362
- * class App extends GemElement {
363
- * @emitter load: Function;
364
- * }
369
+ * class App extends GemElement {
370
+ * @​emitter load: Function;
371
+ * }
365
372
  * ```
366
373
  */
367
374
  export function emitter(_, context) {
@@ -375,7 +382,7 @@ function defineEmitter(context, eventOptions) {
375
382
  const event = camelToKebabCase(prop);
376
383
  context.addInitializer(function () {
377
384
  const target = getDecoratorTarget(this, context);
378
- if (!target.hasOwnProperty(prop)) {
385
+ if (!hasOwn(target, prop)) {
379
386
  pushStaticField(context, 'definedEvents', event);
380
387
  defineProp(target, prop, { event, eventOptions });
381
388
  }
@@ -385,39 +392,39 @@ function defineEmitter(context, eventOptions) {
385
392
  /**
386
393
  * 分配一个构造的样式表,前面的优先级越高(因为装饰器是越近越早执行)
387
394
  *
388
- * For example
395
+ * @example
389
396
  * ```ts
390
- * @adoptedStyle(stylesheet)
391
- * class App extends GemElement {}
397
+ * ​@​adoptedStyle(stylesheet)
398
+ * class App extends GemElement {}
392
399
  * ```
393
400
  */
394
401
  export function adoptedStyle(sheet) {
395
- return function (_, context) {
402
+ return (_, context) => {
396
403
  pushStaticField(context, 'adoptedStyleSheets', sheet);
397
404
  };
398
405
  }
399
406
  /**
400
407
  * 链接一个 store,当 store 更新时更新元素
401
408
  *
402
- * For example
409
+ * @example
403
410
  * ```ts
404
- * @connectStore(store)
405
- * class App extends GemElement {}
411
+ * ​@​connectStore(store)
412
+ * class App extends GemElement {}
406
413
  * ```
407
414
  */
408
415
  export function connectStore(store) {
409
- return function (_, context) {
416
+ return (_, context) => {
410
417
  pushStaticField(context, 'observedStores', store);
411
418
  };
412
419
  }
413
420
  export function shadow({ mode = 'open', serializable = true, delegatesFocus, slotAssignment, } = {}) {
414
- return function (_, context) {
421
+ return (_, context) => {
415
422
  const metadata = context.metadata;
416
423
  assign(metadata, { mode, serializable, delegatesFocus, slotAssignment });
417
424
  };
418
425
  }
419
426
  export function light({ penetrable }) {
420
- return function (_, context) {
427
+ return (_, context) => {
421
428
  const metadata = context.metadata;
422
429
  metadata.penetrable = penetrable;
423
430
  };
@@ -427,7 +434,7 @@ export function light({ penetrable }) {
427
434
  * 例如:https://examples.gemjs.org/async
428
435
  */
429
436
  export function async() {
430
- return function (_, context) {
437
+ return (_, context) => {
431
438
  const metadata = context.metadata;
432
439
  metadata.noBlocking = true;
433
440
  };
@@ -436,7 +443,7 @@ export function async() {
436
443
  * 定义元素的可访问性属性
437
444
  */
438
445
  export function aria(info) {
439
- return function (_, context) {
446
+ return (_, context) => {
440
447
  const metadata = context.metadata;
441
448
  metadata.aria = { ...metadata.aria, ...info };
442
449
  };
@@ -444,25 +451,17 @@ export function aria(info) {
444
451
  /**
445
452
  * 定义自定义元素
446
453
  *
447
- * For example
454
+ * @example
448
455
  * ```ts
449
- * @customElement('my-element')
450
- * class App extends GemElement {}
456
+ * ​@​customElement('my-element')
457
+ * class App extends GemElement {}
451
458
  * ```
452
459
  */
453
460
  export function customElement(name) {
454
- return function (cls, { addInitializer }) {
455
- addInitializer(function () {
461
+ return (cls, { addInitializer }) => {
462
+ addInitializer(() => {
456
463
  customElements.define(name, cls);
457
464
  });
458
465
  };
459
466
  }
460
- if (window.__GEM_DEVTOOLS__HOOK__ && !window.__GEM_DEVTOOLS__HOOK__.GemElement) {
461
- assign(window.__GEM_DEVTOOLS__HOOK__, {
462
- ...elementExports,
463
- ...decoratorsExports,
464
- ...storeExports,
465
- ...versionExports,
466
- });
467
- }
468
467
  //# sourceMappingURL=decorators.js.map