Browse Source

refactor: 简化 componentProps 回调的类型写法

pull/7765/head
dullathanol 6 months ago
parent
commit
96d6f89732
  1. 16
      apps/web-antd/src/adapter/form-schema.ts
  2. 16
      apps/web-antdv-next/src/adapter/form-schema.ts
  3. 16
      apps/web-ele/src/adapter/form-schema.ts
  4. 16
      apps/web-naive/src/adapter/form-schema.ts
  5. 16
      apps/web-tdesign/src/adapter/form-schema.ts
  6. 1
      packages/@core/ui-kit/form-ui/src/index.ts
  7. 16
      playground/src/adapter/form-schema.ts

16
apps/web-antd/src/adapter/form-schema.ts

@ -27,26 +27,16 @@ import type { Component } from 'vue';
import type {
ApiComponentSharedProps,
VbenFormSchema as CoreFormSchema,
FormActions,
IconPickerProps,
} from '@vben/common-ui';
import type { ComponentType } from './component';
type ComponentPropsFnArgs = Parameters<
Extract<
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
(...args: any) => any
>
>;
/**
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
*/
type ComponentProps<P> =
| ((
value: ComponentPropsFnArgs[0],
actions: ComponentPropsFnArgs[1],
value: Partial<Record<string, any>>,
actions: FormActions,
) => P & Record<string, any>)
| (P & Record<string, any>);

16
apps/web-antdv-next/src/adapter/form-schema.ts

@ -27,26 +27,16 @@ import type { Component } from 'vue';
import type {
ApiComponentSharedProps,
VbenFormSchema as CoreFormSchema,
FormActions,
IconPickerProps,
} from '@vben/common-ui';
import type { ComponentType } from './component';
type ComponentPropsFnArgs = Parameters<
Extract<
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
(...args: any) => any
>
>;
/**
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
*/
type ComponentProps<P> =
| ((
value: ComponentPropsFnArgs[0],
actions: ComponentPropsFnArgs[1],
value: Partial<Record<string, any>>,
actions: FormActions,
) => P & Record<string, any>)
| (P & Record<string, any>);

16
apps/web-ele/src/adapter/form-schema.ts

@ -19,6 +19,7 @@ import type { Component } from 'vue';
import type {
ApiComponentSharedProps,
VbenFormSchema as CoreFormSchema,
FormActions,
IconPickerProps,
} from '@vben/common-ui';
@ -27,21 +28,10 @@ import type { ComponentType } from './component';
type ElTreeSelectSchemaProps = InstanceType<typeof ElTreeSelect>['$props'];
type ElTimePickerSchemaProps = InstanceType<typeof ElTimePicker>['$props'];
type ComponentPropsFnArgs = Parameters<
Extract<
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
(...args: any) => any
>
>;
/**
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
*/
type ComponentProps<P> =
| ((
value: ComponentPropsFnArgs[0],
actions: ComponentPropsFnArgs[1],
value: Partial<Record<string, any>>,
actions: FormActions,
) => P & Record<string, any>)
| (P & Record<string, any>);

16
apps/web-naive/src/adapter/form-schema.ts

@ -19,26 +19,16 @@ import type { Component } from 'vue';
import type {
ApiComponentSharedProps,
VbenFormSchema as CoreFormSchema,
FormActions,
IconPickerProps,
} from '@vben/common-ui';
import type { ComponentType } from './component';
type ComponentPropsFnArgs = Parameters<
Extract<
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
(...args: any) => any
>
>;
/**
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
*/
type ComponentProps<P> =
| ((
value: ComponentPropsFnArgs[0],
actions: ComponentPropsFnArgs[1],
value: Partial<Record<string, any>>,
actions: FormActions,
) => P & Record<string, any>)
| (P & Record<string, any>);

16
apps/web-tdesign/src/adapter/form-schema.ts

@ -25,26 +25,16 @@ import type { Component } from 'vue';
import type {
ApiComponentSharedProps,
VbenFormSchema as CoreFormSchema,
FormActions,
IconPickerProps,
} from '@vben/common-ui';
import type { ComponentType } from './component';
type ComponentPropsFnArgs = Parameters<
Extract<
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
(...args: any) => any
>
>;
/**
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
*/
type ComponentProps<P> =
| ((
value: ComponentPropsFnArgs[0],
actions: ComponentPropsFnArgs[1],
value: Partial<Record<string, any>>,
actions: FormActions,
) => P & Record<string, any>)
| (P & Record<string, any>);

1
packages/@core/ui-kit/form-ui/src/index.ts

@ -3,6 +3,7 @@ export { setupVbenForm } from './config';
export type {
BaseFormComponentType,
ExtendedFormApi,
FormActions,
VbenFormProps,
FormSchema as VbenFormSchema,
} from './types';

16
playground/src/adapter/form-schema.ts

@ -27,26 +27,16 @@ import type { Component } from 'vue';
import type {
ApiComponentSharedProps,
VbenFormSchema as CoreFormSchema,
FormActions,
IconPickerProps,
} from '@vben/common-ui';
import type { ComponentType } from './component';
type ComponentPropsFnArgs = Parameters<
Extract<
NonNullable<CoreFormSchema<ComponentType>['componentProps']>,
(...args: any) => any
>
>;
/**
* 使用适配器里为各 `component` 声明的 Props 类型 `P`;
* 与 `Record<string, any>` 相交以兼容核心库 `MaybeComponentProps` 的索引签名。
*/
type ComponentProps<P> =
| ((
value: ComponentPropsFnArgs[0],
actions: ComponentPropsFnArgs[1],
value: Partial<Record<string, any>>,
actions: FormActions,
) => P & Record<string, any>)
| (P & Record<string, any>);

Loading…
Cancel
Save