diff --git a/apps/web-antd/src/adapter/form-schema.ts b/apps/web-antd/src/adapter/form-schema.ts index 2eef37e99..a759fe4c0 100644 --- a/apps/web-antd/src/adapter/form-schema.ts +++ b/apps/web-antd/src/adapter/form-schema.ts @@ -32,19 +32,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -79,12 +88,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-antdv-next/src/adapter/form-schema.ts b/apps/web-antdv-next/src/adapter/form-schema.ts index bbae3d18c..c2adcc2dc 100644 --- a/apps/web-antdv-next/src/adapter/form-schema.ts +++ b/apps/web-antdv-next/src/adapter/form-schema.ts @@ -32,19 +32,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -79,12 +88,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-ele/src/adapter/form-schema.ts b/apps/web-ele/src/adapter/form-schema.ts index 740ad34d0..770cc61d0 100644 --- a/apps/web-ele/src/adapter/form-schema.ts +++ b/apps/web-ele/src/adapter/form-schema.ts @@ -27,19 +27,28 @@ import type { ComponentType } from './component'; type ElTreeSelectSchemaProps = InstanceType['$props']; type ElTimePickerSchemaProps = InstanceType['$props']; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiSelect: ApiComponentSharedProps & SelectV2Props; ApiTreeSelect: ApiComponentSharedProps & ElTreeSelectSchemaProps; Checkbox: CheckboxProps; @@ -63,12 +72,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-naive/src/adapter/form-schema.ts b/apps/web-naive/src/adapter/form-schema.ts index 0172358ef..f4f062b4a 100644 --- a/apps/web-naive/src/adapter/form-schema.ts +++ b/apps/web-naive/src/adapter/form-schema.ts @@ -24,19 +24,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; Checkbox: CheckboxProps; @@ -60,12 +69,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/apps/web-tdesign/src/adapter/form-schema.ts b/apps/web-tdesign/src/adapter/form-schema.ts index 1211af135..34d7641d6 100644 --- a/apps/web-tdesign/src/adapter/form-schema.ts +++ b/apps/web-tdesign/src/adapter/form-schema.ts @@ -30,19 +30,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; AutoComplete: AutoCompleteProps; @@ -73,12 +82,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName]; diff --git a/playground/src/adapter/form-schema.ts b/playground/src/adapter/form-schema.ts index 2eef37e99..a759fe4c0 100644 --- a/playground/src/adapter/form-schema.ts +++ b/playground/src/adapter/form-schema.ts @@ -32,19 +32,28 @@ import type { import type { ComponentType } from './component'; +type ComponentPropsFnArgs = Parameters< + Extract< + NonNullable['componentProps']>, + (...args: any) => any + > +>; + /** - * 对象形式:使用适配器里为各 `component` 声明的 Props 类型 `P`; - * 与 `Record` 相交是为了满足核心库 `MaybeComponentProps` 的索引签名。 - * 函数形式:通过联合 `CoreFormSchema['componentProps']`,与表单核心对动态 `componentProps` 的约定保持一致。 + * 使用适配器里为各 `component` 声明的 Props 类型 `P`; + * 与 `Record` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。 */ -type SchemaComponentProps

= - | CoreFormSchema['componentProps'] +type ComponentProps

= + | (( + value: ComponentPropsFnArgs[0], + actions: ComponentPropsFnArgs[1], + ) => P & Record) | (P & Record); /** * 与 {@link ComponentType} 中注册的组件名一一对应,便于 Schema 上 `component` + `componentProps` 联动提示 */ -interface FormSchemaComponentPropsMap { +interface ComponentPropsMap { ApiCascader: ApiComponentSharedProps & CascaderProps; ApiSelect: ApiComponentSharedProps & SelectProps; ApiTreeSelect: ApiComponentSharedProps & TreeSelectProps; @@ -79,12 +88,12 @@ type BaseSchema = Omit< 'component' | 'componentProps' >; -type RegisteredName = keyof FormSchemaComponentPropsMap; +type RegisteredName = keyof ComponentPropsMap; type DiscriminatedFormSchema = { [K in RegisteredName]: BaseSchema & { component: K; - componentProps?: SchemaComponentProps; + componentProps?: ComponentProps; }; }[RegisteredName];