annil 1.7.5-beta.4 → 1.7.6
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.
- package/CHANGELOG.md +14 -0
- package/README.md +45 -38
- package/dist/api/DefineComponent/ReturnType/ComponentType.d.ts +18 -0
- package/dist/api/DefineComponent/ReturnType/ComponentType.js +2 -0
- package/dist/api/DefineComponent/ReturnType/ComponentType.js.map +1 -0
- package/dist/api/DefineComponent/ReturnType/CreateComponentDoc.d.ts +3 -3
- package/dist/api/DefineComponent/ReturnType/CreatePageDoc.d.ts +2 -2
- package/dist/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.d.ts +3 -3
- package/dist/api/DefineComponent/RootComponent/RootComponentOption.d.ts +2 -2
- package/dist/api/DefineComponent/SubComponents/SubComponentsOption.d.ts +2 -2
- package/dist/api/DefineComponent/index.d.ts +5 -5
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js +2 -2
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js +1 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js +2 -2
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/index.js +1 -1
- package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js +1 -0
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js.map +1 -1
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +4 -4
- package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +3 -1
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +2 -1
- package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +2 -2
- package/dist/api/RootComponent/{RootComponentDoc.d.ts → RootComponentType.d.ts} +16 -15
- package/dist/api/RootComponent/RootComponentType.js +2 -0
- package/dist/api/RootComponent/RootComponentType.js.map +1 -0
- package/dist/api/RootComponent/index.d.ts +5 -4
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/{SubComponentDoc.d.ts → SubComponentType.d.ts} +3 -3
- package/dist/api/SubComponent/SubComponentType.js +2 -0
- package/dist/api/SubComponent/SubComponentType.js.map +1 -0
- package/dist/api/SubComponent/SubComputed/SubComputedOption.d.ts +2 -2
- package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +2 -2
- package/dist/api/SubComponent/index.d.ts +9 -6
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/behaviors/BStore.d.ts +1 -1
- package/dist/behaviors/BStore.js +33 -18
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/types/CreateComponentType.d.ts +23 -2
- package/dist/types/ExtendComponentType.d.ts +34 -0
- package/dist/types/ExtendComponentType.js +6 -0
- package/dist/types/ExtendComponentType.js.map +1 -0
- package/dist/types/GetComponentPrefix.d.ts +2 -2
- package/dist/types/RemoveNullOfRequired.d.ts +7 -0
- package/dist/types/RemoveNullOfRequired.js +2 -0
- package/dist/types/RemoveNullOfRequired.js.map +1 -0
- package/dist/types/ReplacePrefix.d.ts +2 -2
- package/dist/utils/assertNonNullable.js +1 -0
- package/dist/utils/assertNonNullable.js.map +1 -1
- package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.d.ts → utils/deepEqual.d.ts} +1 -1
- package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js → utils/deepEqual.js} +3 -3
- package/dist/utils/deepEqual.js.map +1 -0
- package/package.json +2 -3
- package/src/api/DefineComponent/NameOrPage/test/error.test.ts +6 -6
- package/src/api/DefineComponent/ReturnType/{ComponentDoc.ts → ComponentType.ts} +6 -7
- package/src/api/DefineComponent/ReturnType/CreateComponentDoc.ts +4 -4
- package/src/api/DefineComponent/ReturnType/CreatePageDoc.ts +2 -2
- package/src/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.ts +3 -3
- package/src/api/DefineComponent/ReturnType/GetPropertiesDocOfSubDoc.ts +3 -3
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +5 -5
- package/src/api/DefineComponent/RootComponent/RootComponentOption.ts +2 -2
- package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +2 -2
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +3 -3
- package/src/api/DefineComponent/index.ts +7 -7
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.ts +1 -0
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/index.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/index.ts +1 -1
- package/src/api/DefineComponent/normalizeOptions/internalFieldProtection.ts +1 -0
- package/src/api/RootComponent/Computed/test/normal.test.ts +20 -0
- package/src/api/RootComponent/Events/EventsConstraint.ts +5 -5
- package/src/api/RootComponent/Events/test/normal.test.ts +5 -5
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +2 -4
- package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +4 -1
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +26 -0
- package/src/api/RootComponent/Properties/GetOptionalDoc.ts +4 -4
- package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +2 -1
- package/src/api/RootComponent/Properties/GetRequiredDoc.ts +9 -23
- package/src/api/RootComponent/{RootComponentDoc.ts → RootComponentType.ts} +16 -15
- package/src/api/RootComponent/index.ts +10 -4
- package/src/api/SubComponent/{SubComponentDoc.ts → SubComponentType.ts} +3 -3
- package/src/api/SubComponent/SubComputed/SubComputedOption.ts +2 -0
- package/src/api/SubComponent/SubComputed/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +5 -5
- package/src/api/SubComponent/SubData/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubData/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +2 -2
- package/src/api/SubComponent/SubEvents/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubEvents/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +2 -2
- package/src/api/SubComponent/SubInherit/test/error.test.ts +6 -6
- package/src/api/SubComponent/SubInherit/test/normal.test.ts +18 -4
- package/src/api/SubComponent/SubInstance/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +4 -4
- package/src/api/SubComponent/SubMethods/test/error.test.ts +4 -4
- package/src/api/SubComponent/SubMethods/test/normarl.test.ts +4 -4
- package/src/api/SubComponent/SubReturnType/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubReturnType/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubStore/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +4 -4
- package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchSubData.test.ts +2 -2
- package/src/api/SubComponent/index.ts +17 -11
- package/src/behaviors/BStore.ts +37 -23
- package/src/index.ts +2 -2
- package/src/types/CreateComponentType.ts +23 -2
- package/src/types/ExtendComponentType.ts +60 -0
- package/src/types/GetComponentPrefix.ts +2 -2
- package/src/types/GetPropertiesDuplicatedKeys.ts +3 -3
- package/src/types/ReplacePrefix.ts +2 -2
- package/src/utils/assertNonNullable.ts +1 -0
- package/src/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.ts → utils/deepEqual.ts} +2 -3
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.d.ts +0 -18
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.js +0 -2
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.js.map +0 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js.map +0 -1
- package/dist/api/RootComponent/RootComponentDoc.js +0 -2
- package/dist/api/RootComponent/RootComponentDoc.js.map +0 -1
- package/dist/api/SubComponent/SubComponentDoc.js +0 -2
- package/dist/api/SubComponent/SubComponentDoc.js.map +0 -1
- package/dist/types/DocAssign.d.ts +0 -10
- package/dist/types/DocAssign.js +0 -6
- package/dist/types/DocAssign.js.map +0 -1
- package/src/types/DocAssign.ts +0 -36
- package/tsconfig.json +0 -23
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { SelectKeys } from "hry-types/src/Object/_api";
|
|
2
2
|
import type { Composed, CustomEventsTags } from "../RootComponent/CustomEvents/CustomEventsTag";
|
|
3
|
-
type
|
|
3
|
+
type _SubComponentType = {
|
|
4
4
|
[k in string]: string | number | bigint | boolean | symbol | null | Record<string, unknown> | unknown[] | CustomEventsTags;
|
|
5
5
|
};
|
|
6
|
-
type _Validator<O, ErrKeys = Exclude<keyof O, SelectKeys<O, Composed, "contains->">>> = [ErrKeys] extends [never] ?
|
|
6
|
+
type _Validator<O, ErrKeys = Exclude<keyof O, SelectKeys<O, Composed, "contains->">>> = [ErrKeys] extends [never] ? _SubComponentType : `${ErrKeys & string} 不是穿透事件`;
|
|
7
7
|
/**
|
|
8
8
|
* SubComponent API 返回类型
|
|
9
9
|
* @remarks 穿透的子组件自定义事件
|
|
@@ -13,5 +13,5 @@ type _Validator<O, ErrKeys = Exclude<keyof O, SelectKeys<O, Composed, "contains-
|
|
|
13
13
|
* };
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
export type
|
|
16
|
+
export type SubComponentType<O extends _Validator<O> = _SubComponentType> = O;
|
|
17
17
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubComponentType.js","sourceRoot":"","sources":["../../../src/api/SubComponent/SubComponentType.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { G } from "hry-types";
|
|
2
|
-
export type SubComputedOption<TComputed extends object, legal extends PropertyKey> = {
|
|
3
|
-
computed?: TComputed & G.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
|
|
2
|
+
export type SubComputedOption<TComputed extends object, legal extends PropertyKey, Instance extends object> = {
|
|
3
|
+
computed?: TComputed & ThisType<Instance> & G.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
|
|
4
4
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Contains } from "hry-types/src/Any/Contains";
|
|
2
2
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
3
3
|
import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
|
|
4
|
-
import type {
|
|
4
|
+
import type { ComponentType } from "../../DefineComponent/ReturnType/ComponentType";
|
|
5
5
|
import type { Bubbles, Capture, CustomEventsTags } from "../../RootComponent/CustomEvents/CustomEventsTag";
|
|
6
6
|
/**
|
|
7
7
|
* 把组件事件类型转为函数类型,冒泡事件捕获事件会多一个加后缀(_catch)的key,表示阻止事件冒泡和捕获。
|
|
8
8
|
*/
|
|
9
|
-
export type SubEventsConstraint<CompDoc extends
|
|
9
|
+
export type SubEventsConstraint<CompDoc extends ComponentType> = {
|
|
10
10
|
[k in keyof CompDoc["customEvents"] as Contains<CompDoc["customEvents"][k], Bubbles | Capture> extends true ? (k | `${k & string}_catch`) : k]?: (e: IfExtends<WMBaseEvent, CompDoc["customEvents"][k], WMBaseEvent, Detail<Exclude<CompDoc["customEvents"][k], CustomEventsTags>>>) => void;
|
|
11
11
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { SelectKeys } from "hry-types/src/Object/_api";
|
|
2
2
|
import type { RemoveInnerData } from "../../../types/RemoveInnerData";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentType } from "../../DefineComponent/ReturnType/ComponentType";
|
|
4
4
|
type WXMLSign = "wxml";
|
|
5
5
|
type unionAddList<Keys extends string> = Keys | Keys[];
|
|
6
6
|
/**
|
|
7
7
|
* 子组件inherit字段约束,key为构建组件所需的properties字段,类型为根组件数据的key或key[]或`WXMLSign`。要求根数据类型为子数据类型的子类型。当key的值来自wxml(循环产生的子数据等情况)时用`WXMLSign`表示。
|
|
8
8
|
* @returns object
|
|
9
9
|
*/
|
|
10
|
-
export type InheritConstraint<AllRootData extends object, TComponentDoc extends
|
|
10
|
+
export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentType> = {
|
|
11
11
|
[k in keyof TComponentDoc["properties"]]?: unionAddList<RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>> | WXMLSign;
|
|
12
12
|
};
|
|
13
13
|
export {};
|
|
@@ -2,20 +2,21 @@ import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
|
2
2
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
3
3
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
4
4
|
import type { RequiredKeys } from "hry-types/src/Object/RequiredKeys";
|
|
5
|
+
import type { ComputeObject } from "../../types/ComputeObj";
|
|
5
6
|
import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
|
|
6
7
|
import type { InnerFields } from "../../types/InnerData";
|
|
7
8
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
8
9
|
import type { Replace } from "../../types/Replace";
|
|
9
10
|
import type { ReplacePrefix } from "../../types/ReplacePrefix";
|
|
10
|
-
import type {
|
|
11
|
-
import type { IInjectStore } from "../InstanceInject/instanceConfig";
|
|
11
|
+
import type { ComponentType } from "../DefineComponent/ReturnType/ComponentType";
|
|
12
|
+
import type { IInjectAllData, IInjectStore } from "../InstanceInject/instanceConfig";
|
|
12
13
|
import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
|
|
13
14
|
import type { DataConstraint } from "../RootComponent/Data/DataConstraint";
|
|
14
15
|
import type { EventsConstraint } from "../RootComponent/Events/EventsConstraint";
|
|
15
16
|
import type { LifetimesConstraint } from "../RootComponent/Lifetimes/LifetimesConstraint";
|
|
16
17
|
import type { MethodsConstraint } from "../RootComponent/Methods/MethodsConstraint";
|
|
17
18
|
import type { PageLifetimesOption } from "../RootComponent/PageLifetimes/PageLifetimesOption";
|
|
18
|
-
import type {
|
|
19
|
+
import type { RootComponentType } from "../RootComponent/RootComponentType";
|
|
19
20
|
import type { StoreConstraint } from "../RootComponent/Store/StoreConstraint";
|
|
20
21
|
import type { GetSubComputedDoc } from "./SubComputed/GetSubComputedDoc";
|
|
21
22
|
import type { SubComputedConstraint } from "./SubComputed/SubComputedConstraint";
|
|
@@ -36,15 +37,17 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
|
|
|
36
37
|
import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
|
|
37
38
|
import type { SubStoreOption } from "./SubStore/SubStoreOption";
|
|
38
39
|
import type { SubWatchOption } from "./SubWatch/SubWatchOption";
|
|
39
|
-
type Options<RootDoc extends
|
|
40
|
-
|
|
40
|
+
type Options<RootDoc extends RootComponentType, IsPage extends boolean, CurrentCompDoc extends ComponentType, Prefix extends string, AllRootDataDoc extends object, TInherit extends object, TSubData extends object, TSubStore extends object, TSubComputed extends object, TEvents extends object, TSubMethods extends SubMethodsConstraint, InheritDoc extends object, SubDataDoc extends object, SubStoreDoc extends object, SubComputedDoc extends object, SubEventsDoc extends object, SubMethodsDoc extends object, CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"]> = SubInheritOption<TInherit, CompDocKeys> & SubDataOption<TSubData, Exclude<CompDocKeys, (keyof InheritDoc)> | InnerFields<Prefix>> & SubStoreOption<TSubStore, Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))> | InnerFields<Prefix>> & SubComputedOption<TSubComputed, Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> | InnerFields<Prefix>, {
|
|
41
|
+
data: ComputeObject<AllRootDataDoc & Replace<SubComputedDoc, Required<CurrentCompDoc["properties"]>> & IInjectAllData>;
|
|
42
|
+
}> & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>> & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)> & SubPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>> & SubLifetimesOption & SubWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & SubObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<SubInstance<SubMethodsDoc & RootDoc["methods"], Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, NonNullable<RootDoc["customEvents"]>, SubStoreDoc>>;
|
|
43
|
+
type SubComponentConstructor<TRootDoc extends RootComponentType, TOriginalCompDoc extends ComponentType, TSupplementalPrefix extends string = "", IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false, CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`, CurrentCompDoc extends ComponentType = IfExtends<TSupplementalPrefix, "", TOriginalCompDoc, ReplacePrefix<TOriginalCompDoc, CurrentPrefix>>, AllRootDataDoc extends object = Required<TRootDoc["properties"]> & TRootDoc["data"] & TRootDoc["computed"] & TRootDoc["store"]> = <TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TEvents extends SubEventsConstraint<CurrentCompDoc>, TSubComputed extends SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubMethods extends SubMethodsConstraint = {}, InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>, SubDataDoc extends object = IfExtends<SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore, {}, {
|
|
41
44
|
[k in keyof TSubStore]: ReturnType<NonNullable<TSubStore[k]>>;
|
|
42
45
|
}>, SubComputedDoc extends object = IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>, SubEventsDoc extends object = IfExtends<SubEventsConstraint<CurrentCompDoc>, TEvents, {}, TEvents>, SubMethodsDoc extends object = TSubMethods, MissingRequiredField extends PropertyKey = Exclude<RequiredKeys<NonNullable<CurrentCompDoc["properties"]>>, keyof (InheritDoc & SubDataDoc & SubStoreDoc & IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>)>>(options: Options<TRootDoc, IsPage, CurrentCompDoc, CurrentPrefix, AllRootDataDoc, TInherit, TSubData, TSubStore, TSubComputed, TEvents, TSubMethods, InheritDoc, SubDataDoc, SubStoreDoc, SubComputedDoc, SubEventsDoc, SubMethodsDoc>) => CreateSubComponentDoc<NonNullable<TOriginalCompDoc["customEvents"]>, SubEventsDoc, MissingRequiredField>;
|
|
43
46
|
/**
|
|
44
47
|
* 子组件构建函数
|
|
45
48
|
* @returns `(options:) => SubComponentDoc`
|
|
46
49
|
*/
|
|
47
|
-
export declare function SubComponent<RootDoc extends
|
|
50
|
+
export declare function SubComponent<RootDoc extends RootComponentType, CompDoc extends ComponentType, Prefix extends string = "">(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>>;
|
|
48
51
|
export type SubComponentTrueOptions = {
|
|
49
52
|
inhrit?: string;
|
|
50
53
|
data?: DataConstraint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/SubComponent/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/SubComponent/index.ts"],"names":[],"mappings":"AAuOA;;;GAGG;AACH,MAAM,UAAU,YAAY;IAK1B,8DAA8D;IAC9D,OAAO,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAkC,CAAQ,CAAC;AACvE,CAAC"}
|
package/dist/behaviors/BStore.js
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
|
+
import { deepEqual } from "../utils/deepEqual";
|
|
2
|
+
import { isEmptyObject } from "../utils/isEmptyObject";
|
|
3
|
+
function reactionRegister(storeConfig) {
|
|
4
|
+
const unequalData = {};
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
6
|
+
const { comparer, reaction, toJS } = require("mobx");
|
|
7
|
+
// 存储reaction的disposer 需要保护内部字段验证
|
|
8
|
+
this.disposer = {};
|
|
9
|
+
for (const key in storeConfig) {
|
|
10
|
+
const currentStoreValue = toJS(storeConfig[key]());
|
|
11
|
+
/* istanbul ignore next 没办法测试啊,在打开一个页面后退回,修改store,再打开相同页面是会出现store数据不准确的问题*/
|
|
12
|
+
// @ts-ignore this.data[key]一定存在
|
|
13
|
+
if (!deepEqual(currentStoreValue, this.data[key])) {
|
|
14
|
+
unequalData[key] = currentStoreValue;
|
|
15
|
+
}
|
|
16
|
+
// 添加响应式逻辑
|
|
17
|
+
this.disposer[key] = reaction(storeConfig[key], (value) => {
|
|
18
|
+
this.setData({
|
|
19
|
+
[key]: toJS(value),
|
|
20
|
+
});
|
|
21
|
+
}, {
|
|
22
|
+
equals: comparer.structural,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
delete this.data.__storeConfig__;
|
|
26
|
+
/* istanbul ignore next */
|
|
27
|
+
if (!isEmptyObject(unequalData))
|
|
28
|
+
this.setData(unequalData);
|
|
29
|
+
}
|
|
1
30
|
/**
|
|
2
|
-
* 在created
|
|
31
|
+
* 在attached(1.7.5之前在created中)生命周期中,建立store数据的reaction
|
|
3
32
|
* 在detached生命周期中,清除store数据
|
|
4
33
|
*/
|
|
5
34
|
export const BStore = Behavior({
|
|
6
35
|
lifetimes: {
|
|
7
|
-
|
|
36
|
+
attached() {
|
|
37
|
+
// 此时store数据已初始化到data中(initStore)
|
|
8
38
|
const storeConfig = this.data.__storeConfig__;
|
|
9
39
|
if (!storeConfig)
|
|
10
40
|
return;
|
|
11
|
-
|
|
12
|
-
const { comparer, reaction, toJS } = require("mobx");
|
|
13
|
-
// 存储reaction的disposer 需要冲突字段验证
|
|
14
|
-
this.disposer = {};
|
|
15
|
-
for (const key in storeConfig) {
|
|
16
|
-
// 添加响应式逻辑
|
|
17
|
-
this.disposer[key] = reaction(storeConfig[key], (value) => {
|
|
18
|
-
// 加入到待setData对象中
|
|
19
|
-
this.setData({
|
|
20
|
-
[key]: toJS(value),
|
|
21
|
-
});
|
|
22
|
-
}, {
|
|
23
|
-
equals: comparer.structural,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
delete this.data.__storeConfig__;
|
|
41
|
+
reactionRegister.call(this, storeConfig);
|
|
27
42
|
},
|
|
28
43
|
detached() {
|
|
29
44
|
/* istanbul ignore next 清除store数据 test中模拟了测试,所以忽略 框架(1.6.1)不支持 issue {@link https://github.com/wechat-miniprogram/miniprogram-simulate/issues/110}*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BStore.js","sourceRoot":"","sources":["../../src/behaviors/BStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BStore.js","sourceRoot":"","sources":["../../src/behaviors/BStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,SAAS,gBAAgB,CAAiB,WAA0C;IAClF,MAAM,WAAW,GAA4B,EAAE,CAAC;IAChD,iEAAiE;IACjE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAgB,CAAC;IACpE,iCAAiC;IACjC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnD,4EAA4E;QAC5E,gCAAgC;QAChC,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAClD,WAAW,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC;QACvC,CAAC;QACD,UAAU;QACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAC3B,WAAW,CAAC,GAAG,CAAC,EAChB,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,CAAC,OAAO,CAAC;gBACX,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;aACnB,CAAC,CAAC;QACL,CAAC,EACD;YACE,MAAM,EAAE,QAAQ,CAAC,UAAU;SAC5B,CACF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;IACjC,2BAA2B;IAC3B,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC;QAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAAS,EAAE;QACT,QAAQ;YACN,iCAAiC;YACjC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;YAC9C,IAAI,CAAC,WAAW;gBAAE,OAAO;YAEzB,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC3C,CAAC;QACD,QAAQ;YACN,oJAAoJ;YACpJ,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,CAAC;QACH,CAAC;KACF;CACF,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { RootComponent } from "./api/RootComponent";
|
|
|
5
5
|
import { SubComponent } from "./api/SubComponent";
|
|
6
6
|
import type { CreateComponentType } from "./types/CreateComponentType";
|
|
7
7
|
import type { DetailedType } from "./types/DetailedType";
|
|
8
|
-
import type {
|
|
8
|
+
import type { ExtendComponentType } from "./types/ExtendComponentType";
|
|
9
9
|
import type { ParamsEqual } from "./types/TwoParamsEqual";
|
|
10
10
|
export type { Vant, Wm } from "./thirdLib";
|
|
11
11
|
export type { CurrentTargetDataset, Dataset, Detail, Mark, TargetDataset, WMBaseEvent, WMCustomEvent, } from "./types/OfficialTypeAlias";
|
|
12
|
-
export { type CreateComponentType, DefineComponent, type DetailedType, type
|
|
12
|
+
export { type CreateComponentType, DefineComponent, type DetailedType, type ExtendComponentType, type IInjectInfo, instanceConfig, navigateTo, type ParamsEqual, RootComponent, SubComponent, };
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/_api";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
4
4
|
import type { AddPrefix } from "./AddPrefix";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 建立一个组件类型
|
|
7
|
+
* @param TName 组件名称
|
|
8
|
+
* @param T 类型配置
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* type $CustomA = CreateComponentType<"customA", {
|
|
12
|
+
* properties: { num: string };
|
|
13
|
+
* customEvents: { onTap: string }
|
|
14
|
+
* }>;
|
|
15
|
+
*
|
|
16
|
+
* // 等同下面的类型
|
|
17
|
+
* type $CustomA = {
|
|
18
|
+
* properties: {
|
|
19
|
+
* customA_num: string;
|
|
20
|
+
* };
|
|
21
|
+
* customEvents: {
|
|
22
|
+
* customA_onTap: string;
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type CreateComponentType<TName extends string, T extends ComponentType> = ComputeIntersection<IfExtends<unknown, T["properties"], {}, {
|
|
6
27
|
properties: AddPrefix<T["properties"] & {}, TName>;
|
|
7
28
|
}> & IfExtends<unknown, T["customEvents"], {}, {
|
|
8
29
|
customEvents: AddPrefix<T["customEvents"] & {}, TName>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
+
import type { ComputeIntersectionDeep } from "hry-types/src/Object/ComputeIntersectionDeep";
|
|
3
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
4
|
+
import type { GetComponentPrefix } from "./GetComponentPrefix";
|
|
5
|
+
type Validator<TOriginalComponentType extends ComponentType, TExtensionType extends ComponentType, TOriginalPrefix extends PropertyKey = GetComponentPrefix<TOriginalComponentType>, TExtenstionPrefix extends PropertyKey = GetComponentPrefix<TExtensionType>, DuplicateKeys extends PropertyKey = Extract<keyof TExtensionType["properties"], keyof TOriginalComponentType["properties"]> | Extract<keyof TExtensionType["customEvents"], keyof TOriginalComponentType["customEvents"]>> = IfExtends<TOriginalPrefix, TExtenstionPrefix, IfExtends<DuplicateKeys, never, ComponentType, `${DuplicateKeys & string}字段重复`>, `前缀错误,应为${TOriginalPrefix & string}`>;
|
|
6
|
+
/**
|
|
7
|
+
* 拓展组件类型
|
|
8
|
+
* @param TOriginalComponentType 原始组件类型
|
|
9
|
+
* @param TExtensionType 拓展类型
|
|
10
|
+
* @description 拓展类型必须与原始类型有相同的前缀
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type $CustomA = ExtendComponentType<
|
|
14
|
+
* { properties: { aaa_num: number };
|
|
15
|
+
* customEvents: { aaa_xxx: string }
|
|
16
|
+
* },
|
|
17
|
+
* { properties: { aaa_str: string };
|
|
18
|
+
* customEvents: { aaa_yyy: string }
|
|
19
|
+
* }>;
|
|
20
|
+
*
|
|
21
|
+
* // 等同下面的类型
|
|
22
|
+
* type $CustomA = {
|
|
23
|
+
* properties: {
|
|
24
|
+
* aaa_num: number;
|
|
25
|
+
* aaa_str: string;
|
|
26
|
+
* };
|
|
27
|
+
* customEvents: {
|
|
28
|
+
* aaa_xxx: string;
|
|
29
|
+
* aaa_yyy: string;
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type ExtendComponentType<TOriginalComponentType extends ComponentType, TExtensionType extends Validator<TOriginalComponentType, TExtensionType>> = ComputeIntersectionDeep<TOriginalComponentType & TExtensionType>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
// type test0 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
3
|
+
// type test1 = ExtendComponentType<{ customEvents: { aaa_xxx: string } }, { customEvents: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
4
|
+
// type test2 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
5
|
+
// type test3 = ExtendComponentType<{ customEvents: { aaa_xxx: string } }, { customEvents: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
6
|
+
//# sourceMappingURL=ExtendComponentType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtendComponentType.js","sourceRoot":"","sources":["../../src/types/ExtendComponentType.ts"],"names":[],"mappings":";AAqDA,kIAAkI;AAElI,sIAAsI;AAEtI,iIAAiI;AAEjI,qIAAqI"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
4
4
|
/**
|
|
5
5
|
* 提取文档前缀名
|
|
6
6
|
*/
|
|
7
|
-
export type GetComponentPrefix<TComponentDoc extends
|
|
7
|
+
export type GetComponentPrefix<TComponentDoc extends ComponentType> = EmptyObject extends TComponentDoc ? never : keyof IfExtends<unknown, TComponentDoc["properties"], TComponentDoc["customEvents"], TComponentDoc["properties"]> extends `${infer P}_${string}` ? P : never;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RequiredKeys } from "hry-types/src/Object/RequiredKeys";
|
|
2
|
+
/**
|
|
3
|
+
* 去除对象中非可选字段类型中的null
|
|
4
|
+
*/
|
|
5
|
+
export type RemoveNullOfRequired<T extends object, RequireKeys extends keyof T = RequiredKeys<T>> = {
|
|
6
|
+
[k in keyof T]: k extends RequireKeys ? Exclude<T[k], null> : T[k];
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RemoveNullOfRequired.js","sourceRoot":"","sources":["../../src/types/RemoveNullOfRequired.ts"],"names":[],"mappings":""}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
3
3
|
type _ReplacePrefix<O, TPrefix extends string> = {
|
|
4
4
|
[k in keyof O as k extends `${string}_${infer L}` ? `${TPrefix}_${L}` : k]: O[k];
|
|
5
5
|
};
|
|
@@ -8,7 +8,7 @@ type _ReplacePrefix<O, TPrefix extends string> = {
|
|
|
8
8
|
* @param TComponentDoc - ComponentDoc
|
|
9
9
|
* @returns ComponentDoc
|
|
10
10
|
*/
|
|
11
|
-
export type ReplacePrefix<TComponentDoc extends
|
|
11
|
+
export type ReplacePrefix<TComponentDoc extends ComponentType, TPrefix extends string = ""> = IfExtends<unknown, TComponentDoc["properties"], {}, {
|
|
12
12
|
properties: _ReplacePrefix<TComponentDoc["properties"], TPrefix>;
|
|
13
13
|
}> & IfExtends<unknown, TComponentDoc["customEvents"], {}, {
|
|
14
14
|
customEvents: _ReplacePrefix<TComponentDoc["customEvents"], TPrefix>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertNonNullable.js","sourceRoot":"","sources":["../../src/utils/assertNonNullable.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAC/B,KAAsE;IAEtE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,KAAuB,CAAC;AACjC,CAAC"}
|
|
1
|
+
{"version":3,"file":"assertNonNullable.js","sourceRoot":"","sources":["../../src/utils/assertNonNullable.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,iBAAiB,CAC/B,KAAsE;IAEtE,2BAA2B;IAC3B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,kCAAkC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO,KAAuB,CAAC;AACjC,CAAC"}
|
|
@@ -25,7 +25,7 @@ function isSamePattern(a, b) {
|
|
|
25
25
|
* 两个函数使用toString()比较
|
|
26
26
|
* 支持Date,RegExp
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function deepEqual(a, b) {
|
|
29
29
|
// 如果两个值是原始类型或null,直接用Object.is比较
|
|
30
30
|
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
|
|
31
31
|
if (typeof a !== "function" || typeof b !== "function") {
|
|
@@ -55,7 +55,7 @@ export function isEqual(a, b) {
|
|
|
55
55
|
for (const key of keysA) {
|
|
56
56
|
if (keysB.includes(key)) {
|
|
57
57
|
// @ts-ignore
|
|
58
|
-
if (!
|
|
58
|
+
if (!deepEqual(a[key], b[key])) {
|
|
59
59
|
return false;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -66,4 +66,4 @@ export function isEqual(a, b) {
|
|
|
66
66
|
// 如果以上的条件都满足,说明两个值是深度相等的
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
|
-
//# sourceMappingURL=
|
|
69
|
+
//# sourceMappingURL=deepEqual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepEqual.js","sourceRoot":"","sources":["../../src/utils/deepEqual.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "annil",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"description": "微信小程序(原生开发)插件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
"CHANGELOG.md",
|
|
41
41
|
"README.md",
|
|
42
42
|
"src",
|
|
43
|
-
"dist"
|
|
44
|
-
"tsconfig.json"
|
|
43
|
+
"dist"
|
|
45
44
|
],
|
|
46
45
|
"keywords": [
|
|
47
46
|
"mini",
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RootComponentType } from "../../../RootComponent/RootComponentType";
|
|
2
2
|
import { DefineComponent } from "../..";
|
|
3
3
|
|
|
4
4
|
DefineComponent({
|
|
5
5
|
// @ts-expect-error 1 RootComponentDoc中isPage为true时 应该书写page字段
|
|
6
6
|
name: "test",
|
|
7
|
-
rootComponent: { isPage: true } satisfies
|
|
7
|
+
rootComponent: { isPage: true } satisfies RootComponentType,
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
DefineComponent({
|
|
11
11
|
// @ts-expect-error 2 RootComponentDoc中isPage不为true时 应该书写name字段
|
|
12
12
|
path: "/pages/index/index",
|
|
13
|
-
rootComponent: {} satisfies
|
|
13
|
+
rootComponent: {} satisfies RootComponentType,
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
DefineComponent({
|
|
17
17
|
// @ts-expect-error 3 页面路径已'/'开头
|
|
18
18
|
path: "pages/index/index",
|
|
19
|
-
rootComponent: { isPage: true } satisfies
|
|
19
|
+
rootComponent: { isPage: true } satisfies RootComponentType,
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
DefineComponent({
|
|
23
23
|
// @ts-expect-error 4 组件名不可为空
|
|
24
24
|
name: "",
|
|
25
|
-
rootComponent: {} satisfies
|
|
25
|
+
rootComponent: {} satisfies RootComponentType,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
DefineComponent({
|
|
29
29
|
// @ts-expect-error 5 组件名不可包含下划线 _
|
|
30
30
|
name: "ddd_ddd",
|
|
31
|
-
rootComponent: {} satisfies
|
|
31
|
+
rootComponent: {} satisfies RootComponentType,
|
|
32
32
|
});
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
type PrefixKeys = `${string}_${string}`;
|
|
3
2
|
|
|
4
|
-
type
|
|
5
|
-
properties?: Record<PrefixKeys,
|
|
6
|
-
customEvents?: Record<PrefixKeys,
|
|
3
|
+
type _ComponentType = {
|
|
4
|
+
properties?: Record<PrefixKeys, unknown>;
|
|
5
|
+
customEvents?: Record<PrefixKeys, unknown>;
|
|
7
6
|
};
|
|
8
7
|
|
|
9
8
|
type Error = "{ properties?: Record<PrefixKeys, any>; customEvents?: Record<PrefixKeys, any>;}";
|
|
10
9
|
|
|
11
|
-
type _Validator<O> = keyof O extends keyof
|
|
10
|
+
type _Validator<O> = keyof O extends keyof _ComponentType
|
|
12
11
|
// @ts-ignore 要求ComponentDoc有前缀
|
|
13
|
-
? keyof (O["properties"] & O["customEvents"]) extends PrefixKeys ?
|
|
12
|
+
? keyof (O["properties"] & O["customEvents"]) extends PrefixKeys ? _ComponentType
|
|
14
13
|
: Error
|
|
15
14
|
: Error;
|
|
16
15
|
|
|
@@ -23,4 +22,4 @@ type _Validator<O> = keyof O extends keyof _ComponentDoc
|
|
|
23
22
|
* };
|
|
24
23
|
* ```
|
|
25
24
|
*/
|
|
26
|
-
export type
|
|
25
|
+
export type ComponentType<O extends _Validator<O> = _ComponentType> = O;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
3
|
import type { AddNullForObject } from "../../../types/AddNullForObject";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { RootComponentType } from "../../RootComponent/RootComponentType";
|
|
5
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
6
6
|
import type { GetCustomEventDocOfSubDoc } from "./GetCustomEventDocOfSubDoc";
|
|
7
7
|
|
|
8
8
|
// 获取RootComponetDoc中events字段类型阻止事件(后最为catch)的key `${ 组件前缀 }_${infer Key}_${ bubbles | capture }_catch`
|
|
9
9
|
type GetStopKeys<O> = { [k in keyof O]: k extends `${string}_${infer Key}_${string}_catch` ? Key : never }[keyof O];
|
|
10
10
|
|
|
11
11
|
export type CreateComponentDoc<
|
|
12
|
-
TRootDoc extends
|
|
12
|
+
TRootDoc extends RootComponentType,
|
|
13
13
|
TName extends string,
|
|
14
|
-
TSubComponentTuple extends
|
|
14
|
+
TSubComponentTuple extends SubComponentType[],
|
|
15
15
|
// 获取RootDoc和SubComponent[]中所有的properties字段类型
|
|
16
16
|
AllPropertiesDoc extends unknown | object = TRootDoc["properties"],
|
|
17
17
|
AllCustomEventsDoc extends unknown | object =
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RootComponentType } from "../../RootComponent/RootComponentType";
|
|
4
4
|
|
|
5
5
|
export type CreatePageDoc<
|
|
6
|
-
TRootDoc extends
|
|
6
|
+
TRootDoc extends RootComponentType,
|
|
7
7
|
TPath extends string,
|
|
8
8
|
> = ComputeIntersection<
|
|
9
9
|
& { path: TPath }
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { IsNever, IsUnion } from "hry-types/src/Any/_api";
|
|
2
2
|
import type { UnionTwoObject } from "hry-types/src/Object/UnionTwoObject";
|
|
3
3
|
import type { Last } from "hry-types/src/Union/Last";
|
|
4
|
-
import type {
|
|
4
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 因为子组件文档customEvents字段有可能相同(无前缀),所以使用UnionTwoObject
|
|
8
8
|
* 由于SubComponentDoc为空时返回never而不`{}`,所以`Exclude<U, TLast>`不影响结果。
|
|
9
9
|
*/
|
|
10
|
-
type _GetCustomEventDocOfSubDoc<U extends
|
|
10
|
+
type _GetCustomEventDocOfSubDoc<U extends SubComponentType, Result = {}, TLast = Last<U>> = IsNever<U> extends true
|
|
11
11
|
? Result
|
|
12
12
|
: _GetCustomEventDocOfSubDoc<Exclude<U, TLast>, UnionTwoObject<Result, TLast>>;
|
|
13
13
|
|
|
@@ -15,6 +15,6 @@ type _GetCustomEventDocOfSubDoc<U extends SubComponentDoc, Result = {}, TLast =
|
|
|
15
15
|
* 获取子组件自定义事件文档
|
|
16
16
|
* @remarks U 中 相同字段类型联合,所以使用元组推导不如Last性能好。
|
|
17
17
|
*/
|
|
18
|
-
export type GetCustomEventDocOfSubDoc<UnionSubDoc extends
|
|
18
|
+
export type GetCustomEventDocOfSubDoc<UnionSubDoc extends SubComponentType> = IsUnion<UnionSubDoc> extends true
|
|
19
19
|
? _GetCustomEventDocOfSubDoc<UnionSubDoc>
|
|
20
20
|
: UnionSubDoc;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
2
2
|
|
|
3
3
|
// 获取元组中所有SubComponentDoc的properties字段类型。这里忽略相同key的情况,结果为各个properties对象交叉类型。因为DefinComopnent API 在获取 SubComponentDoc字段类型时做了相同字段类型报错。
|
|
4
|
-
export type GetPropertiesDocOfSubDoc<Tuple extends
|
|
5
|
-
[infer Head extends
|
|
4
|
+
export type GetPropertiesDocOfSubDoc<Tuple extends SubComponentType[], Result = unknown> = Tuple extends
|
|
5
|
+
[infer Head extends SubComponentType, ...infer Rest extends SubComponentType[]]
|
|
6
6
|
? GetPropertiesDocOfSubDoc<Rest, Result & Head["properties"]>
|
|
7
7
|
: Result;
|
|
@@ -16,8 +16,8 @@ import type {
|
|
|
16
16
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
17
17
|
import type { PropertiesConstraint } from "../../../RootComponent/Properties/PropertiesConstraint";
|
|
18
18
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
19
|
+
import type { RootComponentType } from "../../../RootComponent/RootComponentType";
|
|
20
|
+
import type { SubComponentType } from "../../../SubComponent/SubComponentType";
|
|
21
21
|
import { DefineComponent } from "../..";
|
|
22
22
|
|
|
23
23
|
const properties = {
|
|
@@ -123,7 +123,7 @@ const compDoc = DefineComponent({
|
|
|
123
123
|
|
|
124
124
|
Checking<typeof compDoc, ComputeIntersection<CompOnlyCustomEventsExpected & OnlyPropertiesExpected>, Test.Pass>;
|
|
125
125
|
|
|
126
|
-
type SubA =
|
|
126
|
+
type SubA = SubComponentType<{
|
|
127
127
|
str: string | Bubbles | Composed;
|
|
128
128
|
num: number | Capture | Composed;
|
|
129
129
|
null: null | Bubbles | Capture | Composed;
|
|
@@ -145,7 +145,7 @@ type customEventsRootDocExpect = {
|
|
|
145
145
|
|
|
146
146
|
Checking<typeof customEventsRootDoc, customEventsRootDocExpect, Test.Pass>;
|
|
147
147
|
|
|
148
|
-
type SubB =
|
|
148
|
+
type SubB = SubComponentType<{
|
|
149
149
|
str: number | Bubbles | Composed;
|
|
150
150
|
num: string | Capture | Composed;
|
|
151
151
|
null: boolean | Bubbles | Capture | Composed;
|
|
@@ -168,7 +168,7 @@ type WhenSameKeyOfCustomEventsRootDocExpect = {
|
|
|
168
168
|
|
|
169
169
|
Checking<typeof WhenSameKeyOfCustomEventsRootDoc, WhenSameKeyOfCustomEventsRootDocExpect, Test.Pass>;
|
|
170
170
|
|
|
171
|
-
type RootDocCatch =
|
|
171
|
+
type RootDocCatch = RootComponentType<{
|
|
172
172
|
events: {
|
|
173
173
|
aaa_str_bubbles_catch: () => void;
|
|
174
174
|
};
|