annil 1.1.1 → 1.2.0-beta.0

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 (164) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/api/DefineComponent/collectOptionsForComponent.d.ts +2 -2
  3. package/dist/api/DefineComponent/collectOptionsForComponent.js +24 -28
  4. package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
  5. package/dist/api/DefineComponent/index.d.ts +12 -12
  6. package/dist/api/DefineComponent/index.js.map +1 -1
  7. package/dist/api/RootComponent/Computed/ComputedOption.d.ts +2 -2
  8. package/dist/api/RootComponent/Computed/GetComputedDoc.d.ts +2 -2
  9. package/dist/api/RootComponent/Computed/test/normal.test.js +5 -12
  10. package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
  11. package/dist/api/RootComponent/CustomEvents/CustomEventsOption.d.ts +2 -2
  12. package/dist/api/RootComponent/Data/DataConstraint.d.ts +1 -1
  13. package/dist/api/RootComponent/Data/DataOption.d.ts +2 -2
  14. package/dist/api/RootComponent/Data/GetDataDoc.d.ts +1 -4
  15. package/dist/api/RootComponent/Data/test/GetDataDoc.test.d.ts +3 -2
  16. package/dist/api/RootComponent/Data/test/GetDataDoc.test.js +5 -5
  17. package/dist/api/RootComponent/Data/test/GetDataDoc.test.js.map +1 -1
  18. package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
  19. package/dist/api/RootComponent/Events/EventsConstraint.d.ts +6 -5
  20. package/dist/api/RootComponent/Events/EventsOption.d.ts +2 -3
  21. package/dist/api/RootComponent/Events/test/normal.test.js +1 -1
  22. package/dist/api/RootComponent/Events/test/normal.test.js.map +1 -1
  23. package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +5 -4
  24. package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
  25. package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +6 -7
  26. package/dist/api/RootComponent/PageLifetimes/test/error.test.js +3 -1
  27. package/dist/api/RootComponent/PageLifetimes/test/error.test.js.map +1 -1
  28. package/dist/api/RootComponent/PageLifetimes/test/normal.test.js +3 -1
  29. package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
  30. package/dist/api/RootComponent/RootComponentDoc.d.ts +17 -3
  31. package/dist/api/RootComponent/Store/GeTStoreDoc.d.ts +1 -1
  32. package/dist/api/RootComponent/Store/StoreOption.d.ts +2 -2
  33. package/dist/api/RootComponent/Store/test/normal.test.js.map +1 -1
  34. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +0 -2
  35. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
  36. package/dist/api/RootComponent/index.d.ts +9 -10
  37. package/dist/api/RootComponent/index.js.map +1 -1
  38. package/dist/api/SubComponent/SubData/SubDataConstraint.d.ts +2 -2
  39. package/dist/api/SubComponent/SubData/test/normal.test.js +0 -15
  40. package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
  41. package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
  42. package/dist/api/SubComponent/SubEvents/SubEventsOptions.d.ts +2 -2
  43. package/dist/api/SubComponent/SubEvents/test/error.test.js.map +1 -1
  44. package/dist/api/SubComponent/SubEvents/test/normal.test.js +20 -0
  45. package/dist/api/SubComponent/SubEvents/test/normal.test.js.map +1 -1
  46. package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +3 -2
  47. package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +3 -0
  48. package/dist/api/SubComponent/SubInherit/SubInheritOption.js +2 -0
  49. package/dist/api/SubComponent/SubInherit/SubInheritOption.js.map +1 -0
  50. package/dist/api/SubComponent/SubInherit/test/error.test.js +1 -1
  51. package/dist/api/SubComponent/SubInherit/test/error.test.js.map +1 -1
  52. package/dist/api/SubComponent/SubInherit/test/normal.test.js.map +1 -1
  53. package/dist/api/SubComponent/SubMethods/SubMethodsOption.d.ts +3 -2
  54. package/dist/api/SubComponent/SubMethods/test/error.test.js +6 -0
  55. package/dist/api/SubComponent/SubMethods/test/error.test.js.map +1 -1
  56. package/dist/api/SubComponent/SubMethods/test/normarl.test.js +3 -3
  57. package/dist/api/SubComponent/SubMethods/test/normarl.test.js.map +1 -1
  58. package/dist/api/SubComponent/SubPageLifetimes/SubPageLifetimesOption.d.ts +1 -1
  59. package/dist/api/SubComponent/SubPageLifetimes/test/error.test.d.ts +0 -1
  60. package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js +1 -11
  61. package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js.map +1 -1
  62. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.d.ts +0 -1
  63. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js +1 -25
  64. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
  65. package/dist/api/SubComponent/SubStore/SubDataConstraint.d.ts +2 -2
  66. package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +1 -1
  67. package/dist/api/SubComponent/SubStore/test/error.test.js +2 -0
  68. package/dist/api/SubComponent/SubStore/test/error.test.js.map +1 -1
  69. package/dist/api/SubComponent/SubStore/test/normal.test.js +1 -0
  70. package/dist/api/SubComponent/SubStore/test/normal.test.js.map +1 -1
  71. package/dist/api/SubComponent/SubWatch/SubWatchOption.d.ts +2 -1
  72. package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.d.ts +1 -0
  73. package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js +44 -1
  74. package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js.map +1 -1
  75. package/dist/api/SubComponent/SubWatch/test/error.test.js +10 -2
  76. package/dist/api/SubComponent/SubWatch/test/error.test.js.map +1 -1
  77. package/dist/api/SubComponent/index.d.ts +19 -13
  78. package/dist/api/SubComponent/index.js.map +1 -1
  79. package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
  80. package/dist/behaviors/BComputedAndWatch/types.d.ts +1 -0
  81. package/dist/behaviors/BStore.js.map +1 -1
  82. package/dist/behaviors/BbeforeCreated.js.map +1 -1
  83. package/dist/index.d.ts +3 -3
  84. package/dist/index.js +1 -1
  85. package/dist/index.js.map +1 -1
  86. package/dist/types/OfficialTypeAlias.d.ts +1 -1
  87. package/dist/types/RemoveInnerData.d.ts +1 -0
  88. package/dist/types/RemoveInnerData.js +2 -0
  89. package/dist/types/RemoveInnerData.js.map +1 -0
  90. package/dist/utils/InnerMarker.js +1 -1
  91. package/dist/utils/InnerMarker.js.map +1 -1
  92. package/dist/utils/deepClone.js.map +1 -1
  93. package/package.json +4 -2
  94. package/src/api/DefineComponent/collectOptionsForComponent.ts +176 -66
  95. package/src/api/DefineComponent/index.ts +13 -9
  96. package/src/api/RootComponent/Computed/ComputedOption.ts +23 -3
  97. package/src/api/RootComponent/Computed/GetComputedDoc.ts +1 -3
  98. package/src/api/RootComponent/Computed/test/normal.test.ts +9 -19
  99. package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +26 -22
  100. package/src/api/RootComponent/CustomEvents/test/error.test.ts +5 -5
  101. package/src/api/RootComponent/CustomEvents/test/normal.test.ts +1 -1
  102. package/src/api/RootComponent/Data/DataConstraint.ts +1 -1
  103. package/src/api/RootComponent/Data/DataOption.ts +6 -4
  104. package/src/api/RootComponent/Data/GetDataDoc.ts +1 -18
  105. package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +14 -25
  106. package/src/api/RootComponent/Data/test/error.test.ts +2 -2
  107. package/src/api/RootComponent/Data/test/normal.test.ts +5 -8
  108. package/src/api/RootComponent/Events/EventsConstraint.ts +24 -19
  109. package/src/api/RootComponent/Events/EventsOption.ts +54 -6
  110. package/src/api/RootComponent/Events/test/normal.test.ts +16 -16
  111. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +1 -1
  112. package/src/api/RootComponent/IsPage/IsPageOption.ts +1 -1
  113. package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +11 -8
  114. package/src/api/RootComponent/Lifetimes/LifetimesOption.ts +26 -0
  115. package/src/api/RootComponent/Lifetimes/test/error.test.ts +3 -13
  116. package/src/api/RootComponent/Lifetimes/test/normal.test.ts +1 -1
  117. package/src/api/RootComponent/Methods/MethodsOption.ts +3 -0
  118. package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +21 -10
  119. package/src/api/RootComponent/PageLifetimes/test/error.test.ts +7 -5
  120. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +9 -10
  121. package/src/api/RootComponent/Properties/PropertiesOption.ts +19 -32
  122. package/src/api/RootComponent/RootComponentDoc.ts +19 -3
  123. package/src/api/RootComponent/Store/GeTStoreDoc.ts +1 -1
  124. package/src/api/RootComponent/Store/StoreOption.ts +14 -2
  125. package/src/api/RootComponent/Store/test/error.test.ts +5 -5
  126. package/src/api/RootComponent/Store/test/normal.test.ts +1 -0
  127. package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +1 -12
  128. package/src/api/RootComponent/index.ts +20 -19
  129. package/src/api/SubComponent/SubComputed/SubComputedOption.ts +0 -1
  130. package/src/api/SubComponent/SubData/SubDataConstraint.ts +2 -3
  131. package/src/api/SubComponent/SubData/SubDataOption.ts +4 -0
  132. package/src/api/SubComponent/SubData/test/error.test.ts +1 -1
  133. package/src/api/SubComponent/SubData/test/normal.test.ts +6 -37
  134. package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +7 -2
  135. package/src/api/SubComponent/SubEvents/SubEventsOptions.ts +7 -2
  136. package/src/api/SubComponent/SubEvents/test/error.test.ts +5 -4
  137. package/src/api/SubComponent/SubEvents/test/normal.test.ts +31 -4
  138. package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +6 -3
  139. package/src/api/SubComponent/SubInherit/SubInheritOption.ts +8 -0
  140. package/src/api/SubComponent/SubInherit/test/error.test.ts +9 -7
  141. package/src/api/SubComponent/SubInherit/test/normal.test.ts +5 -4
  142. package/src/api/SubComponent/SubMethods/SubMethodsOption.ts +7 -3
  143. package/src/api/SubComponent/SubMethods/test/error.test.ts +13 -5
  144. package/src/api/SubComponent/SubMethods/test/normarl.test.ts +6 -12
  145. package/src/api/SubComponent/SubPageLifetimes/SubPageLifetimesOption.ts +2 -2
  146. package/src/api/SubComponent/SubPageLifetimes/test/error.test.ts +1 -32
  147. package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +1 -74
  148. package/src/api/SubComponent/SubStore/SubDataConstraint.ts +2 -2
  149. package/src/api/SubComponent/SubStore/SubStoreOption.ts +15 -1
  150. package/src/api/SubComponent/SubStore/test/error.test.ts +4 -0
  151. package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -0
  152. package/src/api/SubComponent/SubWatch/SubWatchOption.ts +2 -1
  153. package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +75 -43
  154. package/src/api/SubComponent/SubWatch/test/error.test.ts +12 -3
  155. package/src/api/SubComponent/index.ts +28 -17
  156. package/src/behaviors/BComputedAndWatch/index.ts +2 -2
  157. package/src/behaviors/BComputedAndWatch/types.ts +1 -0
  158. package/src/behaviors/BStore.ts +4 -6
  159. package/src/behaviors/BbeforeCreated.ts +2 -2
  160. package/src/index.ts +12 -8
  161. package/src/types/OfficialTypeAlias.ts +7 -11
  162. package/src/types/RemoveInnerData.ts +5 -0
  163. package/src/utils/InnerMarker.ts +1 -1
  164. package/src/utils/deepClone.ts +1 -0
@@ -1,37 +1,41 @@
1
1
  import type { V } from "hry-types";
2
2
  import type { CustomEventConstraint } from "./CustomEventConstraint";
3
3
 
4
- /**
5
- * customEvents字段泛型输入
6
- */
7
4
  export type CustomEventsOption<
8
5
  TCustomEvents extends CustomEventConstraint,
9
- DuplicateFieldCheck,
6
+ EventsKeys extends PropertyKey,
10
7
  > = {
11
8
  /**
12
- * 自定义事件
13
- * @remarks 使用this.customEventsA 调用
9
+ * customEvents 定义组件的自定义事件 [类型约束](CustomEventConstraint.ts)
10
+ * @remarks 通过this.A(123)调用。与events字段重复检测
14
11
  * @example
15
12
  * ```ts
16
- * {
17
- * // ...
18
- * customEvents: {
19
- * A: Number, // number
20
- * B: [String as DetailedType<"male" | "femal">, Number], // "male" | "femal" | number
21
- * C: {
22
- * detail: String,
23
- * options: {
24
- * bubbles: true,
25
- * composed: true,
26
- * capturePhase: true,
27
- * },
28
- * },
29
- * },
30
- * };
13
+ * {
14
+ * customEvents: {
15
+ * A: Number, // number
16
+ * B: [String as DetailedType<"male" | "femal">, Number], // "male" | "femal" | number
17
+ * C: {
18
+ * detail: String,
19
+ * options: {
20
+ * bubbles: true,
21
+ * composed: true,
22
+ * capturePhase: true,
23
+ * },
24
+ * },
25
+ * },
26
+ * methods: {
27
+ * M1() {
28
+ * // 调用自定义事件
29
+ * this.A(123);
30
+ * this.B("femal");
31
+ * this.C("string");
32
+ * },
33
+ * },
34
+ * },
31
35
  * ```
32
36
  */
33
37
  customEvents?:
34
38
  & TCustomEvents
35
39
  & V.IllegalFieldValidator<TCustomEvents, "bubbles" | "composed" | "capturePhase", 1, "options">
36
- & V.DuplicateFieldValidator<TCustomEvents, keyof DuplicateFieldCheck, "与events字段重复">;
40
+ & V.DuplicateFieldValidator<TCustomEvents, EventsKeys, "与events字段重复">;
37
41
  };
@@ -5,26 +5,26 @@ import { RootComponent } from "../..";
5
5
  */
6
6
  RootComponent()({
7
7
  customEvents: {
8
- // @ts-expect-error options 没有options字段时无需写对象形式,应简写`error1:Boolean`。
8
+ // @ts-expect-error options 1.1 没有options字段时无需写对象形式,应简写`error1:Boolean`。
9
9
  error1: {
10
10
  detail: Boolean,
11
11
  },
12
- // @ts-expect-error options 不可以为空对象 无意义
12
+ // @ts-expect-error options 1.2 不可以为空对象 无意义
13
13
  error2: {
14
14
  detail: Boolean,
15
15
  options: {},
16
16
  },
17
- // @ts-expect-error false字段不要写 默认就为false
17
+ // @ts-expect-error 1.3 false字段不要写 默认就为false
18
18
  error3: {
19
19
  detail: Boolean,
20
20
  options: { bubbles: false },
21
21
  },
22
- // @ts-expect-error false 字段不要写 默认false
22
+ // @ts-expect-error 1.4 false 字段不要写 默认false
23
23
  error4: {
24
24
  detail: Boolean,
25
25
  options: { capturePhase: false },
26
26
  },
27
- // @ts-expect-error composed字段不可以单独开启,必须存在 bubbles或capturePhase字段为true时
27
+ // @ts-expect-error 1.5 composed字段不可以单独开启,必须存在 bubbles或capturePhase字段为true时
28
28
  error5: {
29
29
  detail: Boolean,
30
30
  options: { composed: true },
@@ -61,7 +61,7 @@ const rootDoc = RootComponent()({
61
61
 
62
62
  type RootDoc = {
63
63
  customEvents: {
64
- // 简写字段 即类型为事件参数e对象的detail字段类型
64
+ // 简写字段 值类型为事件参数edetail类型
65
65
  str: string;
66
66
  null: null;
67
67
  unionStr: "male" | "female";
@@ -1 +1 @@
1
- export type DataConstraint = Record<string, any>;
1
+ export type DataConstraint = Record<string, unknown>;
@@ -1,19 +1,21 @@
1
1
  import type { V } from "hry-types";
2
2
 
3
- export type DataOption<TData extends object, TProperties> = {
3
+ export type DataOption<TData extends object, PropertiesKeys extends PropertyKey> = {
4
4
  /**
5
- * 可通过函数返回形式引入基于Mobx的响应式数据
5
+ * 定义实例基本数据,默认下划线(`_`)开头的为内部数据,不会被渲染
6
+ * @remarks 与properties字段重复校验
6
7
  * @example
7
8
  * ```ts
8
9
  * {
9
10
  * //...
10
11
  * data:{
11
- * reactive_user:() => UserStore.user
12
+ * num:123,
13
+ * _str:'string' //不会被渲染的内部数据
12
14
  * }
13
15
  * }
14
16
  * ```
15
17
  */
16
18
  data?:
17
19
  & TData
18
- & V.DuplicateFieldValidator<TData, keyof TProperties, "与properties字段重复">;
20
+ & V.DuplicateFieldValidator<TData, PropertiesKeys, "与properties字段重复">;
19
21
  };
@@ -1,25 +1,8 @@
1
- import type { O } from "hry-types";
2
- import type { IfExtends } from "hry-types/src/Any/IfExtends";
3
- import type { Func } from "hry-types/src/Misc/Func";
4
-
5
1
  /**
6
2
  * 获取data字段文档类型
7
3
  * @param TData - `DataConstraint`
8
- * @param Type - "去掉函数字段" | "返回函数字段" | "函数值类型变为函数返回类型"
9
4
  * @returns object
10
5
  */
11
6
  export type GetDataDoc<
12
7
  TData extends object,
13
- Type extends "去掉函数字段" | "返回函数字段" | "函数值类型变为函数返回类型" = "函数值类型变为函数返回类型",
14
- > = IfExtends<
15
- Type,
16
- "函数值类型变为函数返回类型",
17
- O.ReturnTypeInObject<TData>,
18
- IfExtends<
19
- Type,
20
- "去掉函数字段",
21
- O.Filter<TData, Func>,
22
- // "返回函数字段"
23
- O.Select<TData, Func>
24
- >
25
- >;
8
+ > = TData;
@@ -1,43 +1,32 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
 
3
- import type { Mock_User } from "../../Properties/test/normalRequired.test";
4
3
  import type { GetDataDoc } from "../GetDataDoc";
5
4
 
6
5
  export const mock_data = {
7
- reactiveUser: () => ({} as Mock_User),
6
+ func: {
7
+ foo(num: number) {
8
+ return num + 1;
9
+ },
10
+ },
8
11
  num: 2,
9
12
  str: "str",
10
13
  };
11
14
 
12
- type Test1 = GetDataDoc<typeof mock_data, "函数值类型变为函数返回类型">;
15
+ type Test1 = GetDataDoc<typeof mock_data>;
13
16
 
14
- type Test1Expected = { reactiveUser: Mock_User; num: number; str: string };
17
+ type Test1Expected = {
18
+ func: {
19
+ foo(num: number): number;
20
+ };
21
+ num: number;
22
+ str: string;
23
+ };
15
24
 
16
25
  Checking<Test1, Test1Expected, Test.Pass>;
17
26
 
18
- type Test2 = GetDataDoc<typeof mock_data, "去掉函数字段">;
19
-
20
- type Test2Expected = { num: number; str: string };
21
-
22
- Checking<Test2, Test2Expected, Test.Pass>;
23
-
24
- type Test3 = GetDataDoc<typeof mock_data, "返回函数字段">;
25
-
26
- type Test3Expected = { reactiveUser: () => Mock_User };
27
-
28
- Checking<Test3, Test3Expected, Test.Pass>;
29
-
30
27
  // 测试空对象
31
- type Test4 = GetDataDoc<{}, "返回函数字段">;
28
+ type Test4 = GetDataDoc<{}>;
32
29
 
33
30
  type Test4Expected = {};
34
31
 
35
32
  Checking<Test4, Test4Expected, Test.Pass>;
36
-
37
- type Test5 = GetDataDoc<{}, "去掉函数字段">;
38
-
39
- Checking<Test5, Test4Expected, Test.Pass>;
40
-
41
- type Test6 = GetDataDoc<{}, "返回函数字段">;
42
-
43
- Checking<Test6, Test4Expected, Test.Pass>;
@@ -1,14 +1,14 @@
1
1
  import { RootComponent } from "../..";
2
2
 
3
3
  /**
4
- * 1 与properties字段重复
4
+ * 字段重复
5
5
  */
6
6
  RootComponent()({
7
7
  properties: {
8
8
  aaa: String,
9
9
  },
10
10
  data: {
11
- // @ts-expect-error ⚠️与properties字段重复⚠️
11
+ // @ts-expect-error 1 ⚠️与properties字段重复⚠️
12
12
  aaa: 123,
13
13
  },
14
14
  });
@@ -3,21 +3,19 @@ import { Checking, type Test } from "hry-types";
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import { RootComponent } from "../..";
5
5
 
6
- /**
7
- * data字段约束为object,函数类型表示引入的响应式字段(mobx)
8
- */
6
+ type Gender = "male" | "female";
7
+
9
8
  const RootDoc = RootComponent()({
10
9
  data: {
11
- gender: <"male" | "female"> "male", // 联合字面量
10
+ gender: <Gender> "male", // 联合字面量
12
11
  num: 123,
13
12
  _innernalFields: 123, // 内部字段无法在wxml中使用
14
13
  },
15
14
  methods: {
16
15
  foo() {
17
- // 1. data配置类型为函数时,this.data中变为函数返回类型
18
16
  Checking<
19
17
  typeof this.data,
20
- ReadonlyDeep<{ gender: "male" | "female"; num: number; _innernalFields: number }>,
18
+ ReadonlyDeep<{ gender: Gender; num: number; _innernalFields: number }>,
21
19
  Test.Pass
22
20
  >;
23
21
  },
@@ -25,12 +23,11 @@ const RootDoc = RootComponent()({
25
23
  });
26
24
 
27
25
  type RootDocExpected = {
28
- gender: "male" | "female";
26
+ gender: Gender;
29
27
  num: number;
30
28
  _innernalFields: number;
31
29
  };
32
30
 
33
- // 2. data配置类型为函数时,dataDoc中变为函数返回类型
34
31
  Checking<typeof RootDoc["data"], RootDocExpected, Test.Pass>;
35
32
 
36
33
  // data为空对象时
@@ -1,3 +1,5 @@
1
+ // import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
+ import type { IfExtends } from "hry-types/src/Any/_api";
1
3
  import type { Select } from "hry-types/src/Object/_api";
2
4
  import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
3
5
  import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
@@ -16,9 +18,9 @@ type FilterNormalFields<O extends object> = Select<O, Bubbles | Capture, "contai
16
18
 
17
19
  // 获取冒泡或捕获的事件
18
20
  type GetBubblesOrCaptureEventsFromCompDoc<
19
- TComponentDocTuple extends ComponentDoc[],
21
+ ComponentDocList extends ComponentDoc[],
20
22
  Result extends CustomEventsDoc = {},
21
- > = TComponentDocTuple extends [infer Head extends ComponentDoc, ...infer Rest extends ComponentDoc[]]
23
+ > = ComponentDocList extends [infer Head extends ComponentDoc, ...infer Rest extends ComponentDoc[]]
22
24
  ? GetBubblesOrCaptureEventsFromCompDoc<
23
25
  Rest,
24
26
  Result & (FilterNormalFields<Head["customEvents"] & {}>)
@@ -47,23 +49,26 @@ type TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<T extends CustomEven
47
49
  };
48
50
 
49
51
  // 所有子组件自定义事件(过滤掉非冒泡或捕获)的key加入后缀并把值(detail)转换为函数类型
50
- type GetAllSubCustomEventsConstraint<TReceivedComponentDoc extends ComponentDoc[] | ComponentDoc> = {} extends
51
- TReceivedComponentDoc ? {}
52
- : TReceivedComponentDoc extends ComponentDoc[] ? TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<
53
- GetBubblesOrCaptureEventsFromCompDoc<TReceivedComponentDoc>
54
- >
55
- : ComponentDoc["customEvents"] & {};
52
+ type GetAllSubCustomEventsConstraint<
53
+ ComponentDocList extends ComponentDoc[],
54
+ AllCustomEvents extends CustomEventsDoc = GetBubblesOrCaptureEventsFromCompDoc<ComponentDocList>,
55
+ > = IfExtends<
56
+ {},
57
+ AllCustomEvents,
58
+ BaseEvent,
59
+ TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<
60
+ AllCustomEvents
61
+ >
62
+ >;
63
+
64
+ type BaseEvent = Record<string, (e: WMBaseEvent) => any>;
56
65
 
57
66
  /**
58
- * events字段约束
67
+ * events字段约束 由自身事件和冒泡的子组件事件组成。带前缀是子组件事件,带后缀(_catch)表示阻止冒泡
59
68
  */
60
- export type EventsConstraint<TReceivedComponentDoc extends ComponentDoc[] | ComponentDoc = {}> = {} extends
61
- TReceivedComponentDoc ? Record<string, (e: WMBaseEvent) => any>
62
- : TReceivedComponentDoc extends ComponentDoc ? {
63
- [k in keyof TReceivedComponentDoc["customEvents"]]?: (
64
- e: Exclude<TReceivedComponentDoc["customEvents"][k], CustomEventsTags>,
65
- ) => void;
66
- }
67
- : GetAllSubCustomEventsConstraint<TReceivedComponentDoc>;
68
- // // 一般事件字段约束
69
- // & Record<string, (e: WMBaseEvent) => any>;
69
+ export type EventsConstraint<ComponentDocList extends ComponentDoc[] = []> = IfExtends<
70
+ [],
71
+ ComponentDocList,
72
+ BaseEvent,
73
+ GetAllSubCustomEventsConstraint<ComponentDocList>
74
+ >;
@@ -1,7 +1,55 @@
1
- import type { V } from "hry-types";
2
-
3
- export type EventsOption<TEvents extends object, EventsDoc> = {
4
- events?:
5
- & TEvents
6
- & V.IllegalFieldValidator<TEvents, keyof EventsDoc>;
1
+ export type EventsOption<TEvents extends object> = {
2
+ /**
3
+ * 根组件事件字段,当RootComopnent传入组件泛型时,有子组件事件提示
4
+ *
5
+ * @example A 无子组件时
6
+ * ```ts
7
+ * RootComponent()({
8
+ * events: {
9
+ * onTap(e) {
10
+ * Checking<typeof e, WMBaseEvent, Test.Pass>;
11
+ * },
12
+ * },
13
+ * });
14
+ * ```
15
+ * @example B
16
+ * ```ts
17
+ * type ComponentDocA = {
18
+ * customEvents: {
19
+ * aaa_str: string;
20
+ * aaa_num: number | Bubbles;
21
+ * };
22
+ * };
23
+ *
24
+ * type ComponentDocB = {
25
+ * customEvents: {
26
+ * bbb_str: string;
27
+ * bbb_num: number | Capture;
28
+ * };
29
+ * };
30
+ * RootComponent<[ComponentDocA, ComponentDocB]>()({
31
+ * events: {
32
+ * // 后缀bubbles表示为子组件的冒泡事件
33
+ * aaa_num_bubbles(e) {
34
+ * Checking<typeof e.detail, number, Test.Pass>;
35
+ * },
36
+ * // 后缀加catch表示阻止事件传递,当前组件类型将不会向上传递此事件类型。
37
+ * aaa_num_bubbles_catch(e) {
38
+ * Checking<typeof e.detail, number, Test.Pass>;
39
+ * },
40
+ * // 后缀capture表示是捕获事件
41
+ * bbb_num_capture(e: Dataset<{ currentTargetDataset: number }, { targetDataset: string }, number>) {
42
+ * Checking<typeof e.detail, number, Test.Pass>;
43
+ * Checking<typeof e.currentTarget.dataset.currentTargetDataset, number, Test.Pass>;
44
+ * Checking<typeof e.target.dataset.targetDataset, string, Test.Pass>;
45
+ * },
46
+ * // 后缀加catch表示阻止事件传递,由于捕获事件向下阻止,所以当发现捕获事件不触发时应查看上级组件是否有阻止事件。
47
+ * bbb_num_capture_catch(e) {
48
+ * Checking<typeof e.detail, number, Test.Pass>;
49
+ * },
50
+ * },
51
+ * });
52
+ * ```
53
+ */
54
+ events?: TEvents;
7
55
  };
@@ -13,22 +13,22 @@ import { RootComponent } from "../..";
13
13
  import type { Bubbles, Capture } from "../../CustomEvents/CustomEventsTag";
14
14
 
15
15
  /**
16
- * 1. 事件参数e的类型默认为官方基础类型
16
+ * 1. 没有子组件时,事件参数e的类型默认为官方基础类型
17
17
  */
18
18
  RootComponent()({
19
19
  events: {
20
- aaa(e) {
20
+ onTap(e) {
21
21
  Checking<typeof e, WMBaseEvent, Test.Pass>;
22
22
  },
23
23
  },
24
24
  });
25
25
 
26
26
  /**
27
- * 2. 事件参数e可通过WMBaseEvent和WMCustomEvent(多一个detail类型)定义内部类型。
27
+ * 2. 没有子组件时,事件参数e可通过WMBaseEvent和WMCustomEvent(多一个detail类型)定义内部类型。
28
28
  */
29
29
  RootComponent()({
30
30
  events: {
31
- // 通过WMCustomEvent定义detai,mark,CurrentTargetDataset,targetDataset数据类型
31
+ // 2.1 通过WMCustomEvent定义detai,mark,CurrentTargetDataset,targetDataset数据类型
32
32
  customA(
33
33
  e: WMCustomEvent<
34
34
  { detailData: string },
@@ -47,21 +47,21 @@ RootComponent()({
47
47
 
48
48
  Checking<typeof e.target.dataset.targetDatasetData, number, Test.Pass>;
49
49
  },
50
- // 通过Detail定义detai类型
50
+ // 2.2 通过Detail定义detai类型
51
51
  bbb(e: Detail<{ str: string }>) {
52
52
  Checking<typeof e.detail.str, string, Test.Pass>;
53
53
  },
54
- // 通过Mark定义mark类型
54
+ // 2.3 通过Mark定义mark类型
55
55
  ccc(e: Mark<{ id: string }>) {
56
56
  const markId = e.mark!.id;
57
57
 
58
58
  Checking<typeof markId, string, Test.Pass>;
59
59
  },
60
- // 通过CurrentTargetDataset定义currentTarget.dataset类型
60
+ // 2.4 通过CurrentTargetDataset定义currentTarget.dataset类型
61
61
  ddd(e: CurrentTargetDataset<{ str: string }>) {
62
62
  Checking<typeof e.currentTarget.dataset.str, string, Test.Pass>;
63
63
  },
64
- // 通过TargetDataset定义target.dateset类型
64
+ // 2.5 通过TargetDataset定义target.dateset类型
65
65
  eee(e: TargetDataset<{ str: string }>) {
66
66
  Checking<typeof e.target.dataset.str, string, Test.Pass>;
67
67
  },
@@ -86,19 +86,19 @@ type ComponentDocB = ComponentDoc<{
86
86
  }>;
87
87
 
88
88
  /**
89
- * 6. 当传入子组件文档列表时,提供子组件的冒泡和捕获事件的字段提示
89
+ * 3. 当传入子组件文档列表时,提供子组件的冒泡和捕获事件的字段提示
90
90
  */
91
91
  const RootDoc = RootComponent<[ComponentDocA, ComponentDocB]>()({
92
92
  events: {
93
- // 后缀bubbles表示为子组件的冒泡事件
93
+ // 3.1 后缀bubbles表示为子组件的冒泡事件
94
94
  aaa_num_bubbles(e) {
95
95
  Checking<typeof e.detail, number, Test.Pass>;
96
96
  },
97
- // 后缀加catch表示阻止事件传递,当前组件类型将不会向上传递此事件类型。
97
+ // 3.2 后缀加catch表示阻止事件传递,当前组件类型将不会向上传递此事件类型。
98
98
  aaa_num_bubbles_catch(e) {
99
99
  Checking<typeof e.detail, number, Test.Pass>;
100
100
  },
101
- // 后缀capture表示是捕获事件
101
+ // 3.3 后缀capture表示是捕获事件
102
102
  bbb_num_capture(e: Dataset<{ currentTargetDataset: number }, { targetDataset: string }, number>) {
103
103
  Checking<typeof e.detail, number, Test.Pass>;
104
104
 
@@ -106,7 +106,7 @@ const RootDoc = RootComponent<[ComponentDocA, ComponentDocB]>()({
106
106
 
107
107
  Checking<typeof e.target.dataset.targetDataset, string, Test.Pass>;
108
108
  },
109
- // 后缀加catch表示阻止事件传递,由于捕获事件向下阻止,所以当发现捕获事件不触发时应查看上级组件是否有阻止事件。
109
+ // 3.4 后缀加catch表示阻止事件传递,由于捕获事件向下阻止,所以当发现捕获事件不触发时应查看上级组件是否有阻止事件。
110
110
  bbb_num_capture_catch(e) {
111
111
  Checking<typeof e.detail, number, Test.Pass>;
112
112
  },
@@ -122,11 +122,11 @@ type RootDocExpect = {
122
122
  };
123
123
  };
124
124
 
125
- // 7 返回EventsDoc正常
125
+ // 4 返回EventsDoc正常
126
126
  Checking<typeof RootDoc, RootDocExpect, Test.Pass>;
127
127
 
128
128
  /**
129
- * 8 events字段为`{}`时,返回类型中无events字段。
129
+ * 5 events字段为`{}`时,返回类型中无events字段。
130
130
  */
131
131
  const EmptyEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({
132
132
  events: {},
@@ -135,7 +135,7 @@ const EmptyEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({
135
135
  Checking<typeof EmptyEventsFields, {}, Test.Pass>;
136
136
 
137
137
  /**
138
- * 9 没有events字段时,返回类型中无events字段。
138
+ * 6 没有events字段时,返回类型中无events字段。
139
139
  */
140
140
  const NoEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({});
141
141
 
@@ -32,7 +32,7 @@ RootComponent()({
32
32
  pageLifetimes: {
33
33
  onLoad(data) {
34
34
  Checking<typeof data, {
35
- optionalObj: {
35
+ optionalObj?: {
36
36
  name: string;
37
37
  };
38
38
  obj: object;
@@ -1,6 +1,6 @@
1
1
  export type IsPageOption<TIsPage extends boolean> = {
2
2
  /**
3
- * 表示组件是否为页面,可选,默认false
3
+ * 表示组件是否为页面,默认false,会引起pageLifetimes类型变化
4
4
  */
5
5
  isPage?: TIsPage;
6
6
  };
@@ -1,11 +1,14 @@
1
+ import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
1
2
  import type { WMCompLifetimes } from "../../../types/OfficialTypeAlias";
2
- import type { FinalOptionsForComponent } from "../../DefineComponent";
3
+ import type { FinalOptionsOfComponent } from "../../DefineComponent";
3
4
 
4
5
  export type LifetimesConstraint = // 官方组件生命周期
5
- & WMCompLifetimes["lifetimes"]
6
- & {
7
- /**
8
- * 建立组件时的真正配置对象
9
- */
10
- beforeCreate?: (options: FinalOptionsForComponent) => void;
11
- };
6
+ ComputeIntersection<
7
+ & WMCompLifetimes["lifetimes"]
8
+ & {
9
+ /**
10
+ * 建立组件时的真正配置对象
11
+ */
12
+ beforeCreate?: (options: FinalOptionsOfComponent) => void;
13
+ }
14
+ >;
@@ -2,6 +2,32 @@ import type { LifetimesConstraint } from "./LifetimesConstraint";
2
2
 
3
3
  export type LifetimesOption<TIsPage extends boolean> = TIsPage extends false // 组件开通lifetimes字段
4
4
  ? {
5
+ /**
6
+ * 在原生类型上增加了beforeCreate周期
7
+ * @example
8
+ * ```ts
9
+ * RootComponent()({
10
+ * lifetimes: {
11
+ * beforeCreate(opitons) {
12
+ * opitons;//为最终进入Component的配置对象
13
+ * },
14
+ * created() {
15
+ * },
16
+ * attached() {
17
+ * },
18
+ * ready() {
19
+ * },
20
+ * detached() {
21
+ * },
22
+ * error(err) {
23
+ * err.cause;
24
+ * },
25
+ * moved() {
26
+ * },
27
+ * },
28
+ * });
29
+ * ```
30
+ */
5
31
  lifetimes?: LifetimesConstraint;
6
32
  }
7
33
  // 页面关闭lifetimes字段(其实也可以开启)
@@ -1,33 +1,23 @@
1
1
  import { RootComponent } from "../..";
2
- /**
3
- * 1 组件时(无ispage字段或为false),
4
- */
2
+
5
3
  RootComponent()({
6
4
  lifetimes: {
7
5
  beforeCreate() {},
8
-
9
6
  created() {},
10
-
11
7
  attached() {},
12
-
13
8
  ready() {},
14
-
15
9
  detached() {},
16
-
17
10
  error(err) {
18
11
  err.cause;
19
12
  },
20
13
  moved() {},
21
- // @ts-expect-error 错误的声明周期字段报错
14
+ // @ts-expect-error 1 错误的声明周期字段报错
22
15
  xxx() {},
23
16
  },
24
17
  });
25
18
 
26
- /**
27
- * 2. 页面时 不开启lifetimes字段
28
- */
29
19
  RootComponent()({
30
20
  isPage: true,
31
- // @ts-expect-error 页面时未开启此字段
21
+ // @ts-expect-error 2 页面时未开启此字段
32
22
  lifetimes: {},
33
23
  });
@@ -5,7 +5,7 @@ import { RootComponent } from "../../../..";
5
5
  */
6
6
  RootComponent()({
7
7
  lifetimes: {
8
- // 新增声明周期用于查看实例初始化之前的配置文件
8
+ // 新增声明周期可用于查看或拓展配置文件
9
9
  beforeCreate(opitons) {
10
10
  opitons;
11
11
  },
@@ -6,6 +6,9 @@ export type MethodsOption<
6
6
  TMethods extends MethodsConstraint,
7
7
  DuplicateField extends PropertyKey,
8
8
  > = {
9
+ /**
10
+ * 与customEvents和events字段重复检测
11
+ */
9
12
  methods?:
10
13
  & TMethods
11
14
  & V.DuplicateFieldValidator<TMethods, DuplicateField>;