annil 1.0.1 → 1.0.5

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 (180) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +105 -6
  3. package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js +6 -6
  4. package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
  5. package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
  6. package/dist/api/DefineComponent/collectOptionsForComponent.d.ts +4 -0
  7. package/dist/api/DefineComponent/collectOptionsForComponent.js +152 -0
  8. package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -0
  9. package/dist/api/DefineComponent/index.d.ts +4 -28
  10. package/dist/api/DefineComponent/index.js +2 -37
  11. package/dist/api/DefineComponent/index.js.map +1 -1
  12. package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +5 -4
  13. package/dist/api/RootComponent/CustomEvents/GetCustomEventDoc.d.ts +5 -5
  14. package/dist/api/RootComponent/CustomEvents/test/error.test.js +8 -8
  15. package/dist/api/RootComponent/CustomEvents/test/error.test.js.map +1 -1
  16. package/dist/api/RootComponent/CustomEvents/test/normal.test.d.ts +17 -17
  17. package/dist/api/RootComponent/CustomEvents/test/normal.test.js +6 -6
  18. package/dist/api/RootComponent/CustomEvents/test/normal.test.js.map +1 -1
  19. package/dist/api/RootComponent/Data/DataConstraint.d.ts +1 -0
  20. package/dist/api/RootComponent/Data/DataConstraint.js +2 -0
  21. package/dist/api/RootComponent/Data/DataConstraint.js.map +1 -0
  22. package/dist/api/RootComponent/Instance/test/CustomEventsDoc.test.js +5 -5
  23. package/dist/api/RootComponent/Instance/test/CustomEventsDoc.test.js.map +1 -1
  24. package/dist/api/RootComponent/Instance/test/customEvents/normal.test.js +5 -5
  25. package/dist/api/RootComponent/Instance/test/customEvents/normal.test.js.map +1 -1
  26. package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
  27. package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +2 -2
  28. package/dist/api/RootComponent/Lifetimes/test/error.test.js +1 -0
  29. package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
  30. package/dist/api/RootComponent/Lifetimes/test/normal.test.js +3 -0
  31. package/dist/api/RootComponent/Lifetimes/test/normal.test.js.map +1 -1
  32. package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
  33. package/dist/api/RootComponent/Properties/GetOptionalDoc.d.ts +2 -2
  34. package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +2 -2
  35. package/dist/api/RootComponent/Properties/PropertiesConstraint.d.ts +6 -6
  36. package/dist/api/RootComponent/Properties/PropertiesValueValidator.d.ts +2 -2
  37. package/dist/api/RootComponent/Properties/test/error.test.js.map +1 -1
  38. package/dist/api/RootComponent/Properties/test/normalOptional.test.js +15 -0
  39. package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
  40. package/dist/api/RootComponent/Properties/test/normalRequired.test.d.ts +21 -21
  41. package/dist/api/RootComponent/index.d.ts +19 -2
  42. package/dist/api/RootComponent/index.js +1 -1
  43. package/dist/api/RootComponent/index.js.map +1 -1
  44. package/dist/api/SubComponent/SubComputed/GetSubComputedDoc.d.ts +1 -1
  45. package/dist/api/SubComponent/SubComputed/test/normal.test.js +4 -4
  46. package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
  47. package/dist/api/SubComponent/index.d.ts +2 -2
  48. package/dist/api/SubComponent/index.js.map +1 -1
  49. package/dist/api/navigateTo.d.ts +1 -1
  50. package/dist/{utils → behaviors/BComputedAndWatch}/computedUpdater.d.ts +1 -1
  51. package/dist/{utils → behaviors/BComputedAndWatch}/computedUpdater.js +2 -2
  52. package/dist/behaviors/BComputedAndWatch/computedUpdater.js.map +1 -0
  53. package/dist/{utils → behaviors/BComputedAndWatch}/getPathsValue.d.ts +1 -1
  54. package/dist/behaviors/BComputedAndWatch/getPathsValue.js.map +1 -0
  55. package/dist/behaviors/BComputedAndWatch/index.js +8 -1
  56. package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
  57. package/dist/behaviors/BComputedAndWatch/initComputed.js +1 -1
  58. package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
  59. package/dist/behaviors/BStore.js.map +1 -1
  60. package/dist/behaviors/BbeforeCreated.js +1 -2
  61. package/dist/behaviors/BbeforeCreated.js.map +1 -1
  62. package/dist/index.d.ts +3 -2
  63. package/dist/index.js +1 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/types/{SpecificType.d.ts → DetailedType.d.ts} +1 -1
  66. package/dist/types/DetailedType.js +2 -0
  67. package/dist/types/DetailedType.js.map +1 -0
  68. package/dist/types/GenerateDoc.d.ts +9 -0
  69. package/dist/types/GenerateDoc.js +2 -0
  70. package/dist/types/GenerateDoc.js.map +1 -0
  71. package/dist/types/InferDetailedType.d.ts +2 -0
  72. package/dist/types/InferDetailedType.js +2 -0
  73. package/dist/types/InferDetailedType.js.map +1 -0
  74. package/dist/types/{InferSpecificType.test.js → InferDetailedType.test.js} +1 -1
  75. package/dist/types/InferDetailedType.test.js.map +1 -0
  76. package/dist/types/OfficialTypeAlias.d.ts +6 -6
  77. package/package.json +3 -3
  78. package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +12 -12
  79. package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +4 -4
  80. package/src/api/DefineComponent/collectOptionsForComponent.ts +290 -0
  81. package/src/api/DefineComponent/index.ts +12 -85
  82. package/src/api/RootComponent/Computed/test/normal.test.ts +2 -2
  83. package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +6 -4
  84. package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +2 -2
  85. package/src/api/RootComponent/CustomEvents/GetCustomEventDoc.ts +7 -7
  86. package/src/api/RootComponent/CustomEvents/test/error.test.ts +8 -8
  87. package/src/api/RootComponent/CustomEvents/test/normal.test.ts +9 -9
  88. package/src/api/RootComponent/Data/DataConstraint.ts +1 -0
  89. package/src/api/RootComponent/Events/EventsConstraint.ts +1 -1
  90. package/src/api/RootComponent/Instance/test/CustomEventsDoc.test.ts +8 -8
  91. package/src/api/RootComponent/Instance/test/customEvents/normal.test.ts +8 -8
  92. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +3 -3
  93. package/src/api/RootComponent/IsPage/IsPageOption.ts +6 -1
  94. package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +2 -2
  95. package/src/api/RootComponent/Lifetimes/test/error.test.ts +1 -1
  96. package/src/api/RootComponent/Lifetimes/test/normal.test.ts +3 -3
  97. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +3 -3
  98. package/src/api/RootComponent/Properties/GetOptionalDoc.ts +5 -5
  99. package/src/api/RootComponent/Properties/GetRequiredDoc.ts +5 -5
  100. package/src/api/RootComponent/Properties/PropertiesConstraint.ts +6 -6
  101. package/src/api/RootComponent/Properties/PropertiesOption.ts +1 -1
  102. package/src/api/RootComponent/Properties/PropertiesValueValidator.ts +2 -2
  103. package/src/api/RootComponent/Properties/test/error.test.ts +2 -2
  104. package/src/api/RootComponent/Properties/test/normalOptional.test.ts +25 -5
  105. package/src/api/RootComponent/Properties/test/normalRequired.test.ts +11 -11
  106. package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +2 -2
  107. package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +4 -4
  108. package/src/api/RootComponent/index.ts +19 -3
  109. package/src/api/SubComponent/SubComputed/test/normal.test.ts +15 -9
  110. package/src/api/SubComponent/index.ts +4 -4
  111. package/src/{utils → behaviors/BComputedAndWatch}/computedUpdater.ts +5 -4
  112. package/src/{utils → behaviors/BComputedAndWatch}/getPathsValue.ts +1 -1
  113. package/src/behaviors/BComputedAndWatch/index.ts +13 -4
  114. package/src/behaviors/BComputedAndWatch/initComputed.ts +1 -1
  115. package/src/behaviors/BStore.ts +2 -2
  116. package/src/behaviors/BbeforeCreated.ts +3 -3
  117. package/src/index.ts +11 -2
  118. package/src/types/DetailedType.ts +15 -0
  119. package/src/types/GenerateDoc.ts +19 -0
  120. package/src/types/InferDetailedType.test.ts +18 -0
  121. package/src/types/{InferSpecificType.ts → InferDetailedType.ts} +4 -4
  122. package/src/types/OfficialTypeAlias.ts +2 -2
  123. package/src/types/RestorePropertiesDoc.ts +3 -3
  124. package/tsconfig.json +7 -16
  125. package/dist/types/InferSpecificType.d.ts +0 -2
  126. package/dist/types/InferSpecificType.js +0 -2
  127. package/dist/types/InferSpecificType.js.map +0 -1
  128. package/dist/types/InferSpecificType.test.js.map +0 -1
  129. package/dist/types/SpecificType.js +0 -2
  130. package/dist/types/SpecificType.js.map +0 -1
  131. package/dist/utils/InternalFieldProtection.d.ts +0 -2
  132. package/dist/utils/InternalFieldProtection.js +0 -11
  133. package/dist/utils/InternalFieldProtection.js.map +0 -1
  134. package/dist/utils/collector.d.ts +0 -5
  135. package/dist/utils/collector.js +0 -21
  136. package/dist/utils/collector.js.map +0 -1
  137. package/dist/utils/computedUpdater.js.map +0 -1
  138. package/dist/utils/createdHijack.d.ts +0 -0
  139. package/dist/utils/createdHijack.js +0 -2
  140. package/dist/utils/createdHijack.js.map +0 -1
  141. package/dist/utils/customEventsHandle.d.ts +0 -2
  142. package/dist/utils/customEventsHandle.js +0 -20
  143. package/dist/utils/customEventsHandle.js.map +0 -1
  144. package/dist/utils/eventsHandle.d.ts +0 -2
  145. package/dist/utils/eventsHandle.js +0 -5
  146. package/dist/utils/eventsHandle.js.map +0 -1
  147. package/dist/utils/funcConfigHandle.d.ts +0 -2
  148. package/dist/utils/funcConfigHandle.js +0 -18
  149. package/dist/utils/funcConfigHandle.js.map +0 -1
  150. package/dist/utils/getPathsValue.js.map +0 -1
  151. package/dist/utils/initWatchOldValue.d.ts +0 -2
  152. package/dist/utils/initWatchOldValue.js +0 -10
  153. package/dist/utils/initWatchOldValue.js.map +0 -1
  154. package/dist/utils/onLoadHijack.d.ts +0 -3
  155. package/dist/utils/onLoadHijack.js +0 -16
  156. package/dist/utils/onLoadHijack.js.map +0 -1
  157. package/dist/utils/onLoadReceivedDataHandle.d.ts +0 -3
  158. package/dist/utils/onLoadReceivedDataHandle.js +0 -14
  159. package/dist/utils/onLoadReceivedDataHandle.js.map +0 -1
  160. package/dist/utils/rootComponentFieldHandle.d.ts +0 -3
  161. package/dist/utils/rootComponentFieldHandle.js +0 -13
  162. package/dist/utils/rootComponentFieldHandle.js.map +0 -1
  163. package/dist/utils/subComponentsHandle.d.ts +0 -3
  164. package/dist/utils/subComponentsHandle.js +0 -12
  165. package/dist/utils/subComponentsHandle.js.map +0 -1
  166. package/src/types/InferSpecificType.test.ts +0 -18
  167. package/src/types/SpecificType.ts +0 -19
  168. package/src/utils/InternalFieldProtection.ts +0 -18
  169. package/src/utils/collector.ts +0 -41
  170. package/src/utils/createdHijack.ts +0 -21
  171. package/src/utils/customEventsHandle.ts +0 -31
  172. package/src/utils/eventsHandle.ts +0 -10
  173. package/src/utils/funcConfigHandle.ts +0 -30
  174. package/src/utils/initWatchOldValue.ts +0 -12
  175. package/src/utils/onLoadHijack.ts +0 -30
  176. package/src/utils/onLoadReceivedDataHandle.ts +0 -31
  177. package/src/utils/rootComponentFieldHandle.ts +0 -27
  178. package/src/utils/subComponentsHandle.ts +0 -25
  179. /package/dist/{utils → behaviors/BComputedAndWatch}/getPathsValue.js +0 -0
  180. /package/dist/types/{InferSpecificType.test.d.ts → InferDetailedType.test.d.ts} +0 -0
@@ -0,0 +1,290 @@
1
+ import type { Func } from "hry-types/src/Misc/_api";
2
+ import { BBeforeCreate } from "../../behaviors/BbeforeCreated";
3
+ import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
4
+ import { initComputed } from "../../behaviors/BComputedAndWatch/initComputed";
5
+ import type { Instance } from "../../behaviors/BComputedAndWatch/types";
6
+ import { BStore } from "../../behaviors/BStore";
7
+ import { deepClone } from "../../utils/deepClone";
8
+ import { INNERMARKER } from "../../utils/InnerMarker";
9
+ import { isEmptyObject } from "../../utils/isEmptyObject";
10
+ import type { RootComponentTrueOptions } from "../RootComponent";
11
+ import type {
12
+ CustomEventConstraint,
13
+ CustomEvents,
14
+ FullCustomEvents,
15
+ } from "../RootComponent/CustomEvents/CustomEventConstraint";
16
+ import type { EventsConstraint } from "../RootComponent/Events/EventsConstraint";
17
+ import type { PageInstance } from "../RootComponent/Instance/RootComponentInstance";
18
+ import type { SubComponentTrueOptions } from "../SubComponent";
19
+ import type { FinalOptionsForComponent, FuncOptions } from ".";
20
+ /**
21
+ * 针对通过 navigateTo传过来的数据解析
22
+ * @param option - option中的url是拼接了encodeURIComponent转码的data对象的,key为INNERMARKER.url
23
+ */
24
+ /* istanbul ignore next */
25
+ function onLoadReceivedDataHandle(
26
+ this: PageInstance,
27
+ option: Record<typeof INNERMARKER.url, string>,
28
+ ) {
29
+ const innerData: string | undefined = option[INNERMARKER.url];
30
+ // 未使用自定义的navigateTo
31
+ if (innerData === undefined) return;
32
+ const optionData = JSON.parse(decodeURIComponent(innerData));
33
+
34
+ // 使用navigateTo
35
+ for (const key in optionData) {
36
+ option[key] = optionData[key];
37
+ }
38
+
39
+ // setData会触发计算属性 继承属性等 。
40
+ this.setData(option as any);
41
+
42
+ delete option[INNERMARKER.url];
43
+
44
+ Reflect.deleteProperty(this.data, INNERMARKER.url);
45
+ }
46
+
47
+ /**
48
+ * onLoad生命周期劫持函数
49
+ */
50
+ /* istanbul ignore next */
51
+ function onLoadHijack(
52
+ options: FinalOptionsForComponent,
53
+ before: Func[],
54
+ after: Func[] = [],
55
+ ) {
56
+ options.methods ||= {};
57
+
58
+ const cloneOpt = deepClone(options);
59
+ const originalOnLoad: Func | undefined = options.methods.onLoad;
60
+
61
+ options.methods.onLoad = function(props: unknown) {
62
+ before.forEach((func) => {
63
+ func.call(this, props, cloneOpt);
64
+ });
65
+
66
+ originalOnLoad?.call(this, props);
67
+
68
+ after.forEach((func) => {
69
+ func.call(this, props, cloneOpt);
70
+ });
71
+ };
72
+ }
73
+ /**
74
+ * 内部保护字段 即不允许配置的字段名(所有方法下)
75
+ */
76
+ const INNERFIELDS = ["disposer"];
77
+
78
+ /**
79
+ * 报错的形式避免输入字段和内部字段冲突
80
+ */
81
+ /* istanbul ignore next */
82
+ function InternalFieldProtection(methodsConfig: object) {
83
+ const methodsConfigKeys = Object.keys(methodsConfig);
84
+ for (const key of INNERFIELDS) {
85
+ if (methodsConfigKeys.includes(key)) {
86
+ throw Error(`${key}已被内部字段占用`);
87
+ }
88
+ }
89
+ }
90
+ /**
91
+ * 把函数配置放入一个配置中依次运行
92
+ */
93
+ function _funcConfigHandle(methodsConfig: object, configList: Record<string, Func[]>) {
94
+ for (const key in configList) {
95
+ methodsConfig[key] = function(...args: unknown[]) {
96
+ configList[key].forEach(ele => ele.call(this, ...args));
97
+ };
98
+ }
99
+ }
100
+
101
+ function funcConfigHandle(
102
+ finalOptionsForComponent: FinalOptionsForComponent,
103
+ isPage: boolean | undefined,
104
+ funcOptions: FuncOptions,
105
+ ) {
106
+ // 测试框架无法测试page情形
107
+ /* istanbul ignore next */
108
+ if (isPage) {
109
+ // 页面时 生命周期方法(即 on 开头的方法),(https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/component.html)
110
+ funcOptions.pageLifetimes && _funcConfigHandle(finalOptionsForComponent.methods ||= {}, funcOptions.pageLifetimes);
111
+ } else {
112
+ // 组件时
113
+ funcOptions.pageLifetimes
114
+ && _funcConfigHandle(finalOptionsForComponent.pageLifetimes ||= {}, funcOptions.pageLifetimes);
115
+ }
116
+ funcOptions.lifetimes && _funcConfigHandle(finalOptionsForComponent.lifetimes ||= {}, funcOptions.lifetimes);
117
+
118
+ funcOptions.watch && _funcConfigHandle(finalOptionsForComponent.watch ||= {}, funcOptions.watch);
119
+ }
120
+ /**
121
+ * 把配置为函数的字段方法收集到funcConfig中
122
+ */
123
+ function funcFieldsCollect(
124
+ options: SubComponentTrueOptions | RootComponentTrueOptions,
125
+ funcOptions: FuncOptions,
126
+ ) {
127
+ for (const key in funcOptions) {
128
+ // key = "pageLifetimes" | "lifetimes" | "watch"
129
+ if (options[key]) {
130
+ for (const _key in options[key]) {
131
+ (funcOptions[key][_key] ||= []).push(options[key][_key]);
132
+ }
133
+ }
134
+
135
+ Reflect.deleteProperty(options, key);
136
+ }
137
+ }
138
+
139
+ // 其他字段加入到componentOptions对应字段配置中
140
+ function otherFieldsHandle(
141
+ finalOptions: FinalOptionsForComponent,
142
+ rootComponentOptions: RootComponentTrueOptions,
143
+ ) {
144
+ for (const key in rootComponentOptions) {
145
+ const config = rootComponentOptions[key];
146
+ if (Array.isArray(config)) {
147
+ // 好像只有behaviors是数组吧.
148
+ /* istanbul ignore next */
149
+ (finalOptions[key] ||= []).push(...config);
150
+ } else {
151
+ Object.assign(finalOptions[key] ||= {}, config);
152
+ }
153
+ }
154
+ }
155
+ /**
156
+ * 把events字段配置变成函数放入到componentOptions.methods中
157
+ */
158
+ function eventsHandle(componentOptions: FinalOptionsForComponent, eventsConfig: EventsConstraint) {
159
+ /* istanbul ignore next */
160
+ componentOptions.methods ||= {};
161
+
162
+ Object.assign(componentOptions.methods, eventsConfig);
163
+ }
164
+ function subComponentsHandle(
165
+ componentOptions: FinalOptionsForComponent,
166
+ subComponents: SubComponentTrueOptions[],
167
+ funcOptions: FuncOptions,
168
+ ) {
169
+ subComponents.forEach((subOption) => {
170
+ subOption.events && eventsHandle(componentOptions, subOption.events);
171
+
172
+ funcFieldsCollect(subOption, funcOptions);
173
+
174
+ otherFieldsHandle(componentOptions, subOption);
175
+ });
176
+ }
177
+
178
+ // 类型守卫
179
+ function IsFullCustomEvents(
180
+ customEventOptions: CustomEvents,
181
+ ): customEventOptions is FullCustomEvents {
182
+ return Object.prototype.toString.call(customEventOptions) === "[object Object]";
183
+ }
184
+
185
+ /**
186
+ * 把customEvents字段配置变成函数放入到componentOptions.methods中
187
+ */
188
+ function customEventsHandle(
189
+ componentOptions: FinalOptionsForComponent,
190
+ customEventsConfig: CustomEventConstraint,
191
+ ) {
192
+ /* istanbul ignore next */
193
+ componentOptions.methods ||= {};
194
+
195
+ for (const key in customEventsConfig) {
196
+ const customEventOptions = customEventsConfig[key];
197
+
198
+ if (IsFullCustomEvents(customEventOptions)) {
199
+ componentOptions.methods[key] = function(this: Instance, detail: unknown) {
200
+ this.triggerEvent(key, detail, customEventOptions.options);
201
+ };
202
+ } else {
203
+ componentOptions.methods[key] = function(this: Instance, detail: unknown) {
204
+ this.triggerEvent(key, detail);
205
+ };
206
+ }
207
+ }
208
+ }
209
+
210
+ /**
211
+ * 收集 rootComponentOptions 配置到 finalOptions 和 funcOptions 中
212
+ * @param finalOptions - 收集配置对象
213
+ * @param funcOptions - 收集特殊配置对象字段
214
+ * @param rootComponentOptions - 被收集的源配置对象
215
+ */
216
+ function collectRootComponentOption(
217
+ finalOptions: FinalOptionsForComponent,
218
+ funcOptions: FuncOptions,
219
+ rootComponentOptions: RootComponentTrueOptions,
220
+ ) {
221
+ rootComponentOptions.customEvents && customEventsHandle(finalOptions, rootComponentOptions.customEvents);
222
+
223
+ delete rootComponentOptions.customEvents;
224
+
225
+ rootComponentOptions.events && eventsHandle(finalOptions, rootComponentOptions.events);
226
+
227
+ delete rootComponentOptions.events;
228
+
229
+ funcFieldsCollect(rootComponentOptions, funcOptions);
230
+
231
+ otherFieldsHandle(finalOptions, rootComponentOptions);
232
+ }
233
+ /**
234
+ * 返回一个由rootComponentOption和subComponentsList配置整合的对象
235
+ * @param rootComponentOption -
236
+ * @param subComponentsList -
237
+ * @returns FinalOptionsForComponent
238
+ */
239
+ export function collectOptionsForComponent(
240
+ rootComponentOption: RootComponentTrueOptions | undefined,
241
+ subComponentsList: SubComponentTrueOptions[] | undefined,
242
+ ): FinalOptionsForComponent {
243
+ const finalOptionsForComponent: FinalOptionsForComponent = {
244
+ // default options
245
+ options: {
246
+ // addGlobalClass: true,
247
+ multipleSlots: true,
248
+ pureDataPattern: /^_/,
249
+ virtualHost: true,
250
+ },
251
+ // default behaviors
252
+ behaviors: [BStore, BComputedAndWatch],
253
+ };
254
+ /**
255
+ * 有些字段配置同时存在根组件和子组件当中(如pageLifetimes,lifetimes,watch字段), 且key相同值类型为函数。funcConfig对象用于收集这些配置为数组形式,最终再一起整合进finalOptionsForComponent配置中。即funcConfig是一个临时中介对象。
256
+ */
257
+ const funcOptions: FuncOptions = {
258
+ pageLifetimes: {},
259
+ lifetimes: {},
260
+ watch: {},
261
+ };
262
+
263
+ if (rootComponentOption && !isEmptyObject(rootComponentOption)) {
264
+ collectRootComponentOption(finalOptionsForComponent, funcOptions, rootComponentOption);
265
+ }
266
+
267
+ if (subComponentsList && !isEmptyObject(subComponentsList)) {
268
+ subComponentsHandle(finalOptionsForComponent, subComponentsList, funcOptions);
269
+ }
270
+ // 框架无法测试页面
271
+ /* istanbul ignore next */
272
+ if (!isEmptyObject(funcOptions)) {
273
+ funcConfigHandle(finalOptionsForComponent, rootComponentOption?.isPage, funcOptions);
274
+ }
275
+
276
+ finalOptionsForComponent.methods && InternalFieldProtection(finalOptionsForComponent.methods);
277
+
278
+ // BBeforeCreate在最后面
279
+ finalOptionsForComponent.behaviors!.push(BBeforeCreate);
280
+
281
+ onLoadHijack(finalOptionsForComponent, [onLoadReceivedDataHandle, initComputed], []);
282
+
283
+ // 框架无法测试页面
284
+ /* istanbul ignore next */
285
+ if (finalOptionsForComponent.isPage) {
286
+ Reflect.deleteProperty(finalOptionsForComponent.options!, "virtualHost");
287
+ }
288
+
289
+ return finalOptionsForComponent;
290
+ }
@@ -1,15 +1,7 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
2
  import type { Func } from "hry-types/src/Misc/Func";
3
- import { BBeforeCreate } from "../../behaviors/BbeforeCreated";
4
- import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
5
- import { initComputed } from "../../behaviors/BComputedAndWatch/initComputed";
6
- import { BStore } from "../../behaviors/BStore";
7
3
  import type { WMComponent, WMCompPageLifetimes, WMPageLifetimes } from "../../types/OfficialTypeAlias";
8
- import { funcConfigHandle } from "../../utils/funcConfigHandle";
9
- import { isEmptyObject } from "../../utils/isEmptyObject";
10
- import { onLoadReceivedDataHandle } from "../../utils/onLoadReceivedDataHandle";
11
- import { rootComponentFieldHandle } from "../../utils/rootComponentFieldHandle";
12
- import { subComponentsHandle } from "../../utils/subComponentsHandle";
4
+
13
5
  import type { LifetimesConstraint } from "../RootComponent/Lifetimes/LifetimesConstraint";
14
6
  import type { RootComponentDoc } from "../RootComponent/RootComponentDoc";
15
7
  import type { SubComponentDoc } from "../SubComponent/SubComponentDoc";
@@ -19,8 +11,10 @@ import type { CreatePageDoc } from "./ReturnType/CreatePageDoc";
19
11
  import type { RootComponentOption } from "./RootComponent/RootComponentOption";
20
12
  import type { SubComponentsOption } from "./SubComponents/SubComponentsOption";
21
13
 
22
- import { InternalFieldProtection } from "../../utils/InternalFieldProtection";
23
- import { onLoadHijack } from "../../utils/onLoadHijack";
14
+ import type { RootComponentTrueOptions } from "../RootComponent";
15
+ import { collectOptionsForComponent } from "./collectOptionsForComponent";
16
+
17
+ type Path = `/${string}`;
24
18
 
25
19
  type RootOptions<
26
20
  TRootComponentDoc extends RootComponentDoc,
@@ -55,19 +49,15 @@ interface DefineComponentConstructor {
55
49
  * 临时的函数配置项
56
50
  * 把根组件与子组件中配置类型为函数的相同字段配置收集在一起(数组)
57
51
  */
58
- export type FuncConfig = {
59
- pageLifetimes?: Record<string, Func[]>;
60
- lifetimes?: Record<string, Func[]>;
61
- watch?: Record<string, Func[]>;
62
- };
52
+ export type FuncOptions = Record<"pageLifetimes" | "lifetimes" | "watch", Record<string, Func[]>>;
63
53
 
64
54
  /**
65
- * 传入原生Component的配置项
55
+ * 最终传入原生Component的配置项
66
56
  */
67
- export type ComponentOptions = {
57
+ export type FinalOptionsForComponent = {
68
58
  isPage?: boolean;
69
59
  options?: WMComponent.Options;
70
- properties?: object;
60
+ properties?: Record<string, any>;
71
61
  data?: object;
72
62
  store?: object;
73
63
  computed?: Record<string, Func>;
@@ -79,71 +69,8 @@ export type ComponentOptions = {
79
69
  pageLifetimes?: Partial<WMCompPageLifetimes & { load: Func } & WMPageLifetimes>;
80
70
  };
81
71
 
82
- export type Path = `/${string}`;
83
-
84
- export type DefineComponentOptions = {
85
- path?: Path;
86
- name?: string;
87
- rootComponent?: RootComponentDoc;
88
- subComponents?: SubComponentDoc[];
89
- };
90
-
91
72
  export const DefineComponent: DefineComponentConstructor = function(options): any {
92
- // console.log("------------------------------------------------分割线------------------------------------------------");
93
-
94
- // 最终的配置,默认配置与根组件和子组件列表配置汇集而成。
95
- const finalOptions: ComponentOptions = {
96
- // default options
97
- options: {
98
- // addGlobalClass: true,
99
- multipleSlots: true,
100
- pureDataPattern: /^_/,
101
- virtualHost: true,
102
- },
103
- // default behaviors
104
- behaviors: [BStore, BComputedAndWatch],
105
- };
106
- /**
107
- * 有些选项配置是函数,且可能分布在根组件和子组件中,funcConfig 用于收集这些配置,最终再一起整合进finalOptions配置。rootComponentHandle和subComponentsHandle都会收集函数配置到funcConfig中,再由funcConfigHandle整合配置到finalOptions中。
108
- */
109
- const allFuncConfig: FuncConfig = {};
110
-
111
- if (options.rootComponent && !isEmptyObject(options.rootComponent)) {
112
- rootComponentFieldHandle(options.rootComponent, finalOptions, allFuncConfig);
113
- }
114
-
115
- if (options.subComponents && !isEmptyObject(options.subComponents)) {
116
- subComponentsHandle(finalOptions, options.subComponents, allFuncConfig);
117
- }
118
- // 框架无法测试页面
119
- /* istanbul ignore next */
120
- if (!isEmptyObject(allFuncConfig)) {
121
- funcConfigHandle(finalOptions, options.rootComponent?.isPage, allFuncConfig);
122
- }
123
-
124
- finalOptions.methods && InternalFieldProtection(finalOptions.methods);
125
-
126
- finalOptions.behaviors!.push(BBeforeCreate);
127
-
128
- onLoadHijack(finalOptions, [onLoadReceivedDataHandle, initComputed], []);
129
-
130
- // 框架无法测试页面
131
- /* istanbul ignore next */
132
- if (finalOptions.isPage) {
133
- Reflect.deleteProperty(finalOptions.options!, "virtualHost");
134
- }
135
-
136
- Component(finalOptions as any);
137
- };
138
-
139
- export type PageOptions = {
140
- path: Path;
141
- rootComponent: RootComponentDoc & { isPage: true };
142
- subComponents: SubComponentDoc[];
143
- };
144
-
145
- export type CompOptions = {
146
- name: string;
147
- rootComponent: RootComponentDoc & { isPage: undefined };
148
- subComponents: SubComponentDoc[];
73
+ Component(
74
+ collectOptionsForComponent(options.rootComponent as RootComponentTrueOptions | undefined, options.subComponents),
75
+ );
149
76
  };
@@ -1,6 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
- import type { SpecificType } from "../../../../types/SpecificType";
3
+ import type { DetailedType } from "../../../../types/DetailedType";
4
4
  import { RootComponent } from "../..";
5
5
  import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
@@ -88,7 +88,7 @@ Checking<typeof EmptyComputedFieldDoc, { methods: { M1: () => void } }, Test.Pas
88
88
  RootComponent()({
89
89
  isPage: true,
90
90
  properties: {
91
- obj: Object as SpecificType<{ name: string; age: number }>,
91
+ obj: Object as DetailedType<{ name: string; age: number }>,
92
92
  },
93
93
  computed: {
94
94
  age() {
@@ -1,6 +1,6 @@
1
- import type { SpecificType } from "../../../types/SpecificType";
1
+ import type { DetailedType } from "../../../types/DetailedType";
2
2
 
3
- type SimpleCustomeEvents = SpecificType | null;
3
+ type SimpleCustomeEvents = DetailedType | null;
4
4
 
5
5
  export type SimpleCustomeEventsList = SimpleCustomeEvents[];
6
6
 
@@ -43,8 +43,10 @@ export type OptionsFieldsConfigOfCustomEvents =
43
43
  * 带options的CustomEvents配置
44
44
  */
45
45
  export type FullCustomEvents = {
46
- detailType: ShortCustomeEvents;
46
+ detail: ShortCustomeEvents;
47
47
  options: OptionsFieldsConfigOfCustomEvents;
48
48
  };
49
49
 
50
- export type CustomEventConstraint = Record<string, FullCustomEvents | ShortCustomeEvents>;
50
+ export type CustomEvents = FullCustomEvents | ShortCustomeEvents;
51
+
52
+ export type CustomEventConstraint = Record<string, CustomEvents>;
@@ -17,9 +17,9 @@ export type CustomEventsOption<
17
17
  * // ...
18
18
  * customEvents: {
19
19
  * A: Number, // number
20
- * B: [String as SpecificType<"male" | "femal">, Number], // "male" | "femal" | number
20
+ * B: [String as DetailedType<"male" | "femal">, Number], // "male" | "femal" | number
21
21
  * C: {
22
- * detailType: String,
22
+ * detail: String,
23
23
  * options: {
24
24
  * bubbles: true,
25
25
  * composed: true,
@@ -1,5 +1,5 @@
1
- import type { InferSpecificType } from "../../../types/InferSpecificType";
2
- import type { SpecificType } from "../../../types/SpecificType";
1
+ import type { DetailedType } from "../../../types/DetailedType";
2
+ import type { InferDetailedType } from "../../../types/InferDetailedType";
3
3
  import type {
4
4
  CustomEventConstraint,
5
5
  FullCustomEvents,
@@ -8,13 +8,13 @@ import type {
8
8
  } from "./CustomEventConstraint";
9
9
  import type { AddTagForCustomEventsDoc } from "./CustomEventsTag";
10
10
 
11
- export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends SpecificType ? InferSpecificType<T>
11
+ export type GetShortCustomEventsDoc<T extends ShortCustomeEvents> = T extends DetailedType ? InferDetailedType<T>
12
12
  : T extends null ? null
13
13
  : T extends SimpleCustomeEventsList ? GetShortCustomEventsDoc<T[number]>
14
14
  : never;
15
15
 
16
16
  export type GetFullCustomEventsDoc<T extends FullCustomEvents> =
17
- | GetShortCustomEventsDoc<T["detailType"]>
17
+ | GetShortCustomEventsDoc<T["detail"]>
18
18
  | AddTagForCustomEventsDoc<T["options"]>;
19
19
 
20
20
  /**
@@ -23,8 +23,8 @@ export type GetFullCustomEventsDoc<T extends FullCustomEvents> =
23
23
  * ```ts
24
24
  * customEvents:{
25
25
  * a:Number,
26
- * b:{ detailType: String,options:{ bubbles:true } }
27
- * c:{ detailType: Number,options:{ bubbles:true, composed:true } }
26
+ * b:{ detail: String,options:{ bubbles:true } }
27
+ * c:{ detail: Number,options:{ bubbles:true, composed:true } }
28
28
  * }
29
29
  * //result => {a:number,b:string|()=>'bubbles',c:number | ()=>'composed' }
30
30
  * ```
@@ -36,7 +36,7 @@ export type GetCustomEventDoc<T extends CustomEventConstraint> =
36
36
  [k in keyof T]: T[k] extends ShortCustomeEvents ? GetShortCustomEventsDoc<T[k]>
37
37
  // 应该写GetFullCustomEventsDoc<T[k]>带鼠标悬停时不是计算结果。所以代码重复了。
38
38
  : // @ts-ignore T[k] 一定为 FullCustomEvents 类型
39
- | GetShortCustomEventsDoc<T[k]["detailType"]>
39
+ | GetShortCustomEventsDoc<T[k]["detail"]>
40
40
  // 为自定义事件模型加标记,方便识别
41
41
  // @ts-ignore T[k] 一定为 FullCustomEvents 类型
42
42
  | AddTagForCustomEventsDoc<T[k]["options"]>;
@@ -7,26 +7,26 @@ RootComponent()({
7
7
  customEvents: {
8
8
  // @ts-expect-error options 没有options字段时无需写对象形式,应简写`error1:Boolean`。
9
9
  error1: {
10
- detailType: Boolean,
10
+ detail: Boolean,
11
11
  },
12
12
  // @ts-expect-error options 不可以为空对象 无意义
13
13
  error2: {
14
- detailType: Boolean,
14
+ detail: Boolean,
15
15
  options: {},
16
16
  },
17
17
  // @ts-expect-error false字段不要写 默认就为false
18
18
  error3: {
19
- detailType: Boolean,
19
+ detail: Boolean,
20
20
  options: { bubbles: false },
21
21
  },
22
22
  // @ts-expect-error false 字段不要写 默认false
23
23
  error4: {
24
- detailType: Boolean,
24
+ detail: Boolean,
25
25
  options: { capturePhase: false },
26
26
  },
27
27
  // @ts-expect-error composed字段不可以单独开启,必须存在 bubbles或capturePhase字段为true时
28
28
  error5: {
29
- detailType: Boolean,
29
+ detail: Boolean,
30
30
  options: { composed: true },
31
31
  },
32
32
  },
@@ -53,7 +53,7 @@ RootComponent()({
53
53
  RootComponent()({
54
54
  customEvents: {
55
55
  error1: {
56
- detailType: String,
56
+ detail: String,
57
57
  options: {
58
58
  bubbles: true,
59
59
  // @ts-expect-error 非法字段 composed 少了d
@@ -69,7 +69,7 @@ RootComponent()({
69
69
  RootComponent()({
70
70
  customEvents: {
71
71
  error2: {
72
- detailType: String,
72
+ detail: String,
73
73
  options: {
74
74
  bubbles: true,
75
75
  // @ts-expect-error 非法字段 capturePhases 多了 s
@@ -90,7 +90,7 @@ RootComponent()({
90
90
  },
91
91
  customEvents: {
92
92
  bbb: {
93
- detailType: null,
93
+ detail: null,
94
94
  options: {
95
95
  // @ts-expect-error 非法字段
96
96
  bubbleds: false,
@@ -1,5 +1,5 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import { RootComponent, type SpecificType } from "../../../..";
2
+ import { type DetailedType, RootComponent } from "../../../..";
3
3
  import type { CustomEventConstraint, FullCustomEvents, ShortCustomeEvents } from "../CustomEventConstraint";
4
4
  import type {
5
5
  Bubbles,
@@ -16,8 +16,8 @@ import type {
16
16
  export const mock_shortCustomEvents = {
17
17
  str: String,
18
18
  null: null,
19
- unionStr: String as SpecificType<"male" | "female">,
20
- union: [String, Number as SpecificType<0 | 1 | 2>, null],
19
+ unionStr: String as DetailedType<"male" | "female">,
20
+ union: [String, Number as DetailedType<0 | 1 | 2>, null],
21
21
  } satisfies Record<string, ShortCustomeEvents>;
22
22
 
23
23
  /**
@@ -25,27 +25,27 @@ export const mock_shortCustomEvents = {
25
25
  */
26
26
  export const mock_fullCustomEvents = {
27
27
  bubbles: {
28
- detailType: String,
28
+ detail: String,
29
29
  options: { bubbles: true },
30
30
  },
31
31
  capturePhase: {
32
- detailType: null,
32
+ detail: null,
33
33
  options: { capturePhase: true },
34
34
  },
35
35
  bubbles_capturePhase: {
36
- detailType: [String, Number],
36
+ detail: [String, Number],
37
37
  options: { bubbles: true, capturePhase: true },
38
38
  },
39
39
  bubbles_composed: {
40
- detailType: String as SpecificType<"male" | "female">,
40
+ detail: String as DetailedType<"male" | "female">,
41
41
  options: { bubbles: true, composed: true },
42
42
  },
43
43
  capturePhase_composed: {
44
- detailType: [String, Number as SpecificType<0 | 1 | 2>, null],
44
+ detail: [String, Number as DetailedType<0 | 1 | 2>, null],
45
45
  options: { capturePhase: true, composed: true },
46
46
  },
47
47
  bubbles_capturePhase_composed: {
48
- detailType: Boolean,
48
+ detail: Boolean,
49
49
  options: { bubbles: true, capturePhase: true, composed: true },
50
50
  },
51
51
  } satisfies Record<string, FullCustomEvents>;
@@ -0,0 +1 @@
1
+ export type DataConstraint = Record<string, any>;
@@ -46,7 +46,7 @@ type TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<T extends CustomEven
46
46
  ) => void;
47
47
  };
48
48
 
49
- // 所有子组件自定义事件(过滤掉非冒泡或捕获)的key加入后缀并把值(detailType)转换为函数类型
49
+ // 所有子组件自定义事件(过滤掉非冒泡或捕获)的key加入后缀并把值(detail)转换为函数类型
50
50
  type GetAllSubCustomEventsConstraint<TReceivedComponentDoc extends ComponentDoc[] | ComponentDoc> = {} extends
51
51
  TReceivedComponentDoc ? {}
52
52
  : TReceivedComponentDoc extends ComponentDoc[] ? TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<