xph-crud 0.0.1 → 0.0.2

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 (31) hide show
  1. package/dist/types/common/index.d.ts +1 -0
  2. package/dist/types/common/src/componnets/actions/actions.d.ts +2 -1
  3. package/dist/types/common/src/componnets/actions/components/index.d.ts +1 -2
  4. package/dist/types/common/src/componnets/actions/hooks/useActionsProps.d.ts +3 -2
  5. package/dist/types/common/src/componnets/actions/hooks/useExtendActions.d.ts +1 -1
  6. package/dist/types/common/src/componnets/actions/types/actionItem.d.ts +10 -7
  7. package/dist/types/common/src/componnets/actions/types/actions.d.ts +3 -2
  8. package/dist/types/common/src/types/extendComponent.d.ts +2 -0
  9. package/dist/types/common/src/types/index.d.ts +3 -0
  10. package/dist/types/form/src/components/index.d.ts +1 -2
  11. package/dist/types/form/src/form.d.ts +4 -3
  12. package/dist/types/form/src/hooks/useExtendForm.d.ts +1 -1
  13. package/dist/types/form/src/hooks/useFormItem.d.ts +1 -5
  14. package/dist/types/form/src/hooks/useFormProps.d.ts +1 -1
  15. package/dist/types/form/src/types/component.d.ts +3 -2
  16. package/dist/types/form/src/types/form.d.ts +3 -2
  17. package/dist/types/form/src/types/formItem.d.ts +4 -3
  18. package/dist/types/table/src/components/searchForm/index.d.ts +1 -1
  19. package/dist/types/table/src/components/table/components/cellFunc/cellFunc.d.ts +1 -1
  20. package/dist/types/table/src/components/table/components/cellFunc/components/actions.d.ts +1 -1
  21. package/dist/types/table/src/components/table/components/cellFunc/components/index.d.ts +2 -2
  22. package/dist/types/table/src/components/table/components/cellFunc/components/link.d.ts +1 -1
  23. package/dist/types/table/src/components/table/components/cellFunc/types/cellFunc.d.ts +26 -12
  24. package/dist/types/table/src/hooks/useSearchForm.d.ts +1 -1
  25. package/dist/types/table/src/table.d.ts +2 -1
  26. package/dist/types/table/src/types/apiTable.d.ts +8 -8
  27. package/dist/types/table/src/types/column.d.ts +11 -10
  28. package/dist/types/table/src/types/crudForm.d.ts +2 -1
  29. package/dist/types/table/src/types/searchForm.d.ts +2 -1
  30. package/dist/types/table/src/types/table.d.ts +15 -4
  31. package/package.json +4 -4
@@ -1,3 +1,4 @@
1
1
  export * from './src/utils';
2
2
  export * from './src/componnets';
3
3
  export * from './src/hooks';
4
+ export * from './src/types';
@@ -1,4 +1,5 @@
1
1
  import { IActionsProps } from './types';
2
+ import { TXphExtendComponentPropsMap } from '../../types';
2
3
 
3
- declare const Actions: (props: IActionsProps) => import("react/jsx-runtime").JSX.Element;
4
+ declare const Actions: <T extends TXphExtendComponentPropsMap = {}>(props: IActionsProps<T>) => import("react/jsx-runtime").JSX.Element;
4
5
  export default Actions;
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
- import { TComponentType } from '../types';
3
2
 
4
- declare const componentMap: Map<keyof TComponentType, React.FC<any>>;
3
+ declare const componentMap: Map<"Button" | "Dropdown", React.FC<any>>;
5
4
  export { componentMap };
@@ -1,5 +1,6 @@
1
1
  import { IActionsProps } from '../types';
2
+ import { TXphExtendComponentPropsMap } from '../../../types';
2
3
 
3
- export default function useActionsProps(props: IActionsProps): {
4
- actionsProps: IActionsProps;
4
+ export default function useActionsProps<T extends TXphExtendComponentPropsMap>(props: IActionsProps<T>): {
5
+ actionsProps: IActionsProps<{}>;
5
6
  };
@@ -1,5 +1,5 @@
1
1
  declare const useExtendActions: () => {
2
- extendActionsProps: import('../types').IActionsProps | undefined;
2
+ extendActionsProps: import('../types').IActionsProps<{}> | undefined;
3
3
  setExtendActionsComp: (componentMap: Map<any, React.FC<any>>) => void;
4
4
  };
5
5
  export default useExtendActions;
@@ -1,13 +1,14 @@
1
1
  import { ButtonProps, MenuProps } from 'antd';
2
+ import { TXphExtendComponentPropsMap } from '../../../types';
2
3
 
3
4
  export interface IBaseActionProps {
4
5
  /** 唯一标识 */
5
6
  key?: string;
6
7
  }
7
- export type TComponentType = {
8
+ export type TComponentType<T extends TXphExtendComponentPropsMap = {}> = {
8
9
  Button: IButtonProps;
9
10
  Dropdown: IDropdownProps;
10
- };
11
+ } & T;
11
12
  interface IButtonProps extends ButtonProps {
12
13
  }
13
14
  interface IDropdownProps extends Omit<ButtonProps, "onClick"> {
@@ -21,11 +22,11 @@ interface IDropdownProps extends Omit<ButtonProps, "onClick"> {
21
22
  onClick: MenuProps["onClick"];
22
23
  }
23
24
  /** 组件类型 */
24
- export interface IComponentActionProps<T extends keyof TComponentType> extends IBaseActionProps {
25
+ export interface IComponentActionProps<T extends keyof TComponentType<K>, K extends TXphExtendComponentPropsMap = {}> extends IBaseActionProps {
25
26
  /** 组件 */
26
27
  component: T;
27
28
  /** 组件属性 */
28
- componentProps?: TComponentType[T];
29
+ componentProps?: TComponentType<K>[T];
29
30
  }
30
31
  /** 自定义内容 */
31
32
  export interface IRenderActionProps extends IBaseActionProps {
@@ -56,9 +57,11 @@ type Without<T, K> = {
56
57
  综上所述,这个 `XOR` 类型的定义通过条件类型实现了对多个类型的互斥组合,并确保在同一时间只能使用其中一个类型。
57
58
  */
58
59
  type XOR<T extends any[]> = T extends [infer A, infer B, ...infer Rest] ? A | B extends object ? (Without<A, keyof B> & B) | (Without<B, keyof A> & A) | XOR<[A | B, ...Rest]> : A | B : T extends [infer A] ? A : never;
59
- export type TActionItemProps = XOR<[
60
- IComponentActionProps<"Button">,
61
- IComponentActionProps<"Dropdown">,
60
+ type TMapComponentActionProps<T extends TXphExtendComponentPropsMap> = {
61
+ [K in keyof TComponentType<T>]: IComponentActionProps<K, T>;
62
+ }[keyof TComponentType<T>];
63
+ export type TActionItemProps<T extends TXphExtendComponentPropsMap = {}> = XOR<[
64
+ TMapComponentActionProps<T>,
62
65
  IRenderActionProps
63
66
  ]>;
64
67
  /** 判断是哪种类型的action */
@@ -1,11 +1,12 @@
1
1
  import { TActionItemProps } from './actionItem';
2
2
  import { ButtonProps } from 'antd/lib/button';
3
+ import { TXphExtendComponentPropsMap } from '../../../types';
3
4
 
4
- export interface IActionsProps {
5
+ export interface IActionsProps<T extends TXphExtendComponentPropsMap = {}> {
5
6
  /** 类型 */
6
7
  type?: ButtonProps["type"];
7
8
  /** 操作项 */
8
- items?: TActionItemProps[];
9
+ items?: TActionItemProps<T>[];
9
10
  /** 禁用(items中的componentProps的disabled优先级最高) */
10
11
  disabled?: boolean;
11
12
  /** 自定义内容(items的优先级高于render) */
@@ -0,0 +1,2 @@
1
+ /** 扩展组件的props映射(共用) */
2
+ export type TExtendComponentPropsMap = Record<string, any>;
@@ -0,0 +1,3 @@
1
+ import { TExtendComponentPropsMap as TXphExtendComponentPropsMap } from './extendComponent';
2
+
3
+ export { TXphExtendComponentPropsMap };
@@ -1,5 +1,4 @@
1
1
  import { default as React } from 'react';
2
- import { TComponentPropsMap } from '../types';
3
2
 
4
- declare const componentMap: Map<keyof TComponentPropsMap, React.FC<any>>;
3
+ declare const componentMap: Map<"Button" | "Select" | "Input" | "InputNumber" | "TreeSelect" | "Transfer" | "Switch" | "Radio" | "RadioGroup" | "Checkbox" | "CheckboxGroup" | "Cascader" | "TimePicker" | "DatePicker" | "MonthPicker" | "WeekPicker" | "RangePicker" | "InputPassword" | "InputTextArea" | "AutoComplete" | "Upload" | "ApiSelect" | "ApiTreeSelect" | "ApiTransfer" | "ApiAutoComplete" | "AutoUpload", React.FC<any>>;
5
4
  export { componentMap };
@@ -1,8 +1,9 @@
1
1
  import { IFormProps, IFormActionType } from './types';
2
- import { ForwardedRef } from 'react';
2
+ import { default as React, ForwardedRef } from 'react';
3
+ import { TXphExtendComponentPropsMap } from '../../common';
3
4
 
4
5
  declare const XphForm: (props: IFormProps, ref: ForwardedRef<IFormActionType>) => import("react/jsx-runtime").JSX.Element;
5
- declare const ForwardedXphForm: (props: IFormProps & {
6
- ref?: ForwardedRef<IFormActionType>;
6
+ declare const ForwardedXphForm: <T extends TXphExtendComponentPropsMap = {}>(props: IFormProps<T> & {
7
+ ref?: React.ForwardedRef<IFormActionType> | undefined;
7
8
  }) => ReturnType<typeof XphForm>;
8
9
  export default ForwardedXphForm;
@@ -1,5 +1,5 @@
1
1
  declare const useExtendForm: () => {
2
- extendFormProps: import('../types').IFormProps | undefined;
2
+ extendFormProps: import('../types').IFormProps<{}> | undefined;
3
3
  setExtendFormComp: (componentMap: Map<any, React.FC<any>>) => void;
4
4
  };
5
5
  export default useExtendForm;
@@ -31,10 +31,6 @@ export declare const useFormItemColProps: (itemProps: TFormItemProps, formProps:
31
31
  declare const useFormItem: ({ formProps }: {
32
32
  formProps: IFormProps;
33
33
  }) => {
34
- formItems: (({
35
- render?: undefined;
36
- } & import('../types').IComponentFormItemProps) | ({
37
- component?: undefined;
38
- } & import('../types').IRenderFormItemProps))[];
34
+ formItems: TFormItemProps[];
39
35
  };
40
36
  export default useFormItem;
@@ -1,6 +1,6 @@
1
1
  import { IFormProps } from '../types';
2
2
 
3
3
  declare const useFormPorps: (formProps: IFormProps) => {
4
- formProps: IFormProps;
4
+ formProps: IFormProps<{}>;
5
5
  };
6
6
  export default useFormPorps;
@@ -4,8 +4,9 @@ import { IApiTreeSelectProps } from '../components/ApiTreeSelect';
4
4
  import { IApiTransferProps } from '../components/ApiTransfer';
5
5
  import { IApiAutoCompleteProps } from '../components/ApiAutoComplete';
6
6
  import { IAutoUploadProps } from '../components/AutoUpload';
7
+ import { TXphExtendComponentPropsMap } from '../../../common';
7
8
 
8
- export type TComponentPropsMap = {
9
+ export type TComponentPropsMap<T extends TXphExtendComponentPropsMap = {}> = {
9
10
  Select: SelectProps;
10
11
  Input: InputProps;
11
12
  InputNumber: InputNumberProps;
@@ -32,4 +33,4 @@ export type TComponentPropsMap = {
32
33
  ApiTransfer: IApiTransferProps;
33
34
  ApiAutoComplete: IApiAutoCompleteProps;
34
35
  AutoUpload: IAutoUploadProps;
35
- };
36
+ } & T;
@@ -1,12 +1,13 @@
1
1
  import { TFormItemProps, Recordable } from './formItem';
2
2
  import { ColProps } from 'antd';
3
3
  import { NamePath } from 'antd/lib/form/interface';
4
+ import { TXphExtendComponentPropsMap } from '../../../common';
4
5
 
5
6
  export interface IRegister {
6
7
  (methods: IFormActionType): void;
7
8
  }
8
- export interface IFormProps {
9
- items: TFormItemProps[] /** 表单项配置集合 */;
9
+ export interface IFormProps<T extends TXphExtendComponentPropsMap = {}> {
10
+ items: TFormItemProps<T>[] /** 表单项配置集合 */;
10
11
  /**
11
12
  * @description 表单布局方式(默认horizontal)
12
13
  * @description 排除了antd的inline,因为可以使用colProps实现inline布局
@@ -3,6 +3,7 @@ import { Rule } from 'antd/es/form';
3
3
  import { default as React } from 'react';
4
4
  import { ColProps } from 'antd';
5
5
  import { IFormActionType } from './form';
6
+ import { TXphExtendComponentPropsMap } from '../../../common';
6
7
 
7
8
  /**
8
9
  * 字符串类型对象
@@ -41,14 +42,14 @@ export interface IRenderFormItemProps extends IBaseFormItemProps {
41
42
  render: (props: IFRenderProps) => React.ReactNode /** 自定义渲染组件 */;
42
43
  }
43
44
  /** component props */
44
- export interface IComponentFormItemProps extends IBaseFormItemProps {
45
- component: keyof TComponentPropsMap /** 映射组件 */;
45
+ export interface IComponentFormItemProps<T extends TXphExtendComponentPropsMap = {}> extends IBaseFormItemProps {
46
+ component: keyof TComponentPropsMap<T> /** 映射组件 */;
46
47
  }
47
48
  type Without<T, K> = {
48
49
  [P in Exclude<keyof T, K>]?: never;
49
50
  };
50
51
  type XOR<T, U> = T | U extends object ? (Without<T, keyof U> & U) | (Without<U, keyof T> & T) : T | U;
51
- export type TFormItemProps = XOR<IRenderFormItemProps, IComponentFormItemProps>;
52
+ export type TFormItemProps<T extends TXphExtendComponentPropsMap = {}> = XOR<IRenderFormItemProps, IComponentFormItemProps<T>>;
52
53
  export declare function isComponentFormItemProps(item: TFormItemProps): item is IComponentFormItemProps;
53
54
  export declare function isRenderFormItemProps(item: TFormItemProps): item is IRenderFormItemProps;
54
55
  export {};
@@ -1,7 +1,7 @@
1
1
  import { RefObject } from 'react';
2
2
  import { TTableActionType, TSearchFormActionType } from '../../types';
3
3
 
4
- declare const SearchForm: import('react').ForwardRefExoticComponent<import('../../../..').IXphFormProps & {
4
+ declare const SearchForm: import('react').ForwardRefExoticComponent<import('../../../..').IXphFormProps<{}> & {
5
5
  showSearch?: boolean | undefined;
6
6
  } & {
7
7
  tableRef: RefObject<TTableActionType>;
@@ -1,5 +1,5 @@
1
1
  import { ICellFuncProps } from './types';
2
2
 
3
- /** CellFunc需循环处理组件(这个是一个递归组件) */
3
+ /** CellFunc需循环处理组件(这个是一个遍历的组件) */
4
4
  declare const CellFunc: (props: ICellFuncProps) => import("react/jsx-runtime").JSX.Element;
5
5
  export default CellFunc;
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { ICurCellFuncProps, IMainProps } from '../types';
3
3
 
4
- declare const Actions: (Comp: React.ReactElement, curCellFuncProps: ICurCellFuncProps<"actions">, mainProps: IMainProps) => import("react/jsx-runtime").JSX.Element;
4
+ declare const Actions: (Comp: React.ReactElement, curCellFuncProps: ICurCellFuncProps<{}, {}, "actions">, mainProps: IMainProps) => import("react/jsx-runtime").JSX.Element;
5
5
  export default Actions;
@@ -2,11 +2,11 @@
2
2
  declare const cellComponentMap: {
3
3
  /** 超链接 */
4
4
  link: {
5
- Comp: (Comp: import('react').JSXElementConstructor<any>, curCellFuncProps: import('../types').ICurCellFuncProps<"link">, mainProps: import('../types').IMainProps) => import("react/jsx-runtime").JSX.Element;
5
+ Comp: (Comp: import('react').JSXElementConstructor<any>, curCellFuncProps: import('../types').ICurCellFuncProps<{}, {}, "link">, mainProps: import('../types').IMainProps) => import("react/jsx-runtime").JSX.Element;
6
6
  };
7
7
  /** 操作组 */
8
8
  actions: {
9
- Comp: (Comp: import('react').ReactElement<any, string | import('react').JSXElementConstructor<any>>, curCellFuncProps: import('../types').ICurCellFuncProps<"actions">, mainProps: import('../types').IMainProps) => import("react/jsx-runtime").JSX.Element;
9
+ Comp: (Comp: import('react').ReactElement<any, string | import('react').JSXElementConstructor<any>>, curCellFuncProps: import('../types').ICurCellFuncProps<{}, {}, "actions">, mainProps: import('../types').IMainProps) => import("react/jsx-runtime").JSX.Element;
10
10
  };
11
11
  };
12
12
  export { cellComponentMap };
@@ -1,5 +1,5 @@
1
1
  import { default as React } from 'react';
2
2
  import { ICurCellFuncProps, IMainProps } from '../types';
3
3
 
4
- declare const Link: (Comp: React.JSXElementConstructor<any>, curCellFuncProps: ICurCellFuncProps<"link">, mainProps: IMainProps) => import("react/jsx-runtime").JSX.Element;
4
+ declare const Link: (Comp: React.JSXElementConstructor<any>, curCellFuncProps: ICurCellFuncProps<{}, {}, "link">, mainProps: IMainProps) => import("react/jsx-runtime").JSX.Element;
5
5
  export default Link;
@@ -1,24 +1,37 @@
1
- import { IXphActionsProps } from '../../../../../../../common';
1
+ import { IXphActionsProps, TXphExtendComponentPropsMap } from '../../../../../../../common';
2
2
 
3
- export type TCellComponentType = "link" | "actions";
4
3
  /** cellFunc中每一项对应的组件componentProps属性映射 */
5
- export interface ICellComponentPropsMap {
4
+ export type TCellComponentPropsMap<CellFuncExtendPropsMap extends TXphExtendComponentPropsMap = {}, ActionsExtendPropsMap extends TXphExtendComponentPropsMap = {}> = {
6
5
  link: {
7
6
  /** 超链接,点击超链接跳转 */
8
7
  url?: string;
9
8
  /** 点击事件(优先级最高) */
10
9
  onClick?: () => void;
11
10
  };
12
- actions: IXphActionsProps;
13
- }
11
+ actions: IXphActionsProps<ActionsExtendPropsMap>;
12
+ } & CellFuncExtendPropsMap;
13
+ type Without<T, K> = {
14
+ [P in Exclude<keyof T, K>]?: never;
15
+ };
16
+ type XOR<T extends any[]> = T extends [infer A, infer B, ...infer Rest] ? A | B extends object ? (Without<A, keyof B> & B) | (Without<B, keyof A> & A) | XOR<[A | B, ...Rest]> : A | B : T extends [infer A] ? A : never;
14
17
  /** cellFunc中每一项的配置 */
15
- export interface ICellProps<T extends TCellComponentType = TCellComponentType> {
18
+ interface ICellProps<T extends keyof TCellComponentPropsMap<J, K>, J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}> {
16
19
  component: T;
17
- componentProps?: ICellComponentPropsMap[T];
20
+ componentProps?: TCellComponentPropsMap<J, K>[T];
18
21
  }
22
+ type TCellFuncPropsMap<J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}> = {
23
+ [T in keyof TCellComponentPropsMap<J, K>]: ICellProps<T, J, K>;
24
+ }[keyof TCellComponentPropsMap<J, K>];
25
+ export type TCellProps<J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}> = XOR<[TCellFuncPropsMap<J, K>]>;
19
26
  /** CellFunc组件的props */
20
- export interface ICellFuncProps<T = unknown, U extends TCellComponentType = TCellComponentType> {
21
- dslConfig: ICellProps<U>[];
27
+ export interface ICellFuncProps<
28
+ /** 行数据类型 */
29
+ T = unknown,
30
+ /** 单元格的扩展组件props映射 */
31
+ J extends TXphExtendComponentPropsMap = {},
32
+ /** 操作组的扩展组件props映射 */
33
+ K extends TXphExtendComponentPropsMap = {}> {
34
+ dslConfig: TCellProps<J, K>[];
22
35
  renderPrams: {
23
36
  text: any;
24
37
  record: T;
@@ -26,9 +39,9 @@ export interface ICellFuncProps<T = unknown, U extends TCellComponentType = TCel
26
39
  };
27
40
  }
28
41
  /** cellFunc中每一项对应的组件的props */
29
- export interface ICurCellFuncProps<T extends TCellComponentType = TCellComponentType> {
30
- curComponentProps?: ICellComponentPropsMap[T];
31
- cellFuncProps: ICellFuncProps<unknown, T>;
42
+ export interface ICurCellFuncProps<J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}, T extends keyof TCellComponentPropsMap<J, K> = keyof TCellComponentPropsMap<J, K>> {
43
+ curComponentProps?: TCellComponentPropsMap<J, K>[T];
44
+ cellFuncProps: ICellFuncProps<unknown, J, K>;
32
45
  }
33
46
  /**
34
47
  *
@@ -41,3 +54,4 @@ export interface IMainProps {
41
54
  mainClick?: () => void;
42
55
  mainStyle?: React.CSSProperties;
43
56
  }
57
+ export {};
@@ -2,5 +2,5 @@ import { TTableProps, TSearchFormActionType } from '../types';
2
2
 
3
3
  export default function useSearchForm({ searchForm }: TTableProps): {
4
4
  searchFormRef: import('react').RefObject<TSearchFormActionType>;
5
- searchFormProps: import('../types').TSearchFormProps | undefined;
5
+ searchFormProps: import('../types').TSearchFormProps<{}> | undefined;
6
6
  };
@@ -1,8 +1,9 @@
1
1
  import { ForwardedRef } from 'react';
2
2
  import { TTableProps, TTableActionType, TDataSourceItem } from './types';
3
+ import { TXphExtendComponentPropsMap } from '../../common';
3
4
 
4
5
  declare const XphTable: <T extends TDataSourceItem>(props: TTableProps<T>, ref: ForwardedRef<TTableActionType>) => import("react/jsx-runtime").JSX.Element;
5
- declare const ForwardedXphTable: <RecordType extends TDataSourceItem = TDataSourceItem>(props: TTableProps<RecordType> & {
6
+ declare const ForwardedXphTable: <RecordType extends TDataSourceItem = TDataSourceItem, CellFuncExtendPropsMap extends TXphExtendComponentPropsMap = {}, ActionsExtendPropsMap extends TXphExtendComponentPropsMap = {}, ToolbarExtendPropsMap extends TXphExtendComponentPropsMap = {}, FormExtendPropsMap extends TXphExtendComponentPropsMap = {}>(props: TTableProps<RecordType, CellFuncExtendPropsMap, ActionsExtendPropsMap, ToolbarExtendPropsMap, FormExtendPropsMap> & {
6
7
  ref?: ForwardedRef<TTableActionType> | undefined;
7
8
  }) => ReturnType<typeof XphTable>;
8
9
  export default ForwardedXphTable;
@@ -1,17 +1,17 @@
1
1
  import { TableProps, PaginationProps } from 'antd';
2
2
  import { TableRowSelection, RowSelectionType } from 'antd/lib/table/interface';
3
- import { IXphActionsProps } from '../../../common';
3
+ import { IXphActionsProps, TXphExtendComponentPropsMap } from '../../../common';
4
4
  import { TDataSourceItem } from './table';
5
5
  import { TColumnProps } from './column';
6
6
 
7
- export interface IFunctionToolbarParams<RecordType = TDataSourceItem> {
7
+ export interface IFunctionToolbarParams<T = TDataSourceItem> {
8
8
  loading: boolean;
9
- selection: RecordType[];
9
+ selection: T[];
10
10
  }
11
11
  /** 扩展antd table的属性 */
12
- export type TApiTableProps<RecordType = TDataSourceItem> = {
12
+ export type TApiTableProps<T = TDataSourceItem, J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}, L extends TXphExtendComponentPropsMap = {}> = {
13
13
  /** 列配置项 */
14
- columns?: TColumnProps<RecordType>[];
14
+ columns?: TColumnProps<T, J, K>[];
15
15
  /** 首次是否自动请求 */
16
16
  autoRequest?: boolean;
17
17
  /** 获取datasource的api */
@@ -21,15 +21,15 @@ export type TApiTableProps<RecordType = TDataSourceItem> = {
21
21
  /** 是否开启前端自动分页(当api不支持分页时可用) */
22
22
  autoPagination?: boolean;
23
23
  /** 单选 / 多选 */
24
- rowSelection?: RowSelectionType | TableRowSelection<RecordType>;
24
+ rowSelection?: RowSelectionType | TableRowSelection<T>;
25
25
  /** 分页配置(因为分页器是独立出来的,使用table的分页器布局需要修改样式) */
26
26
  pagination?: false | PaginationProps;
27
27
  /** 表格撑满父容器(virtual为true时,默认fullHeight为true) */
28
28
  fullHeight?: boolean;
29
29
  /** 顶部操作栏配置,函数时可以传递参数,参数是什么由调用方决定 */
30
- toolbar?: IXphActionsProps | ((e: IFunctionToolbarParams<RecordType>) => IXphActionsProps);
30
+ toolbar?: IXphActionsProps<L> | ((e: IFunctionToolbarParams<T>) => IXphActionsProps<L>);
31
31
  /** 排序、筛选变化时触发 */
32
32
  onChange?: (filters: any, sorter: any, extra: any) => void;
33
- } & Omit<TableProps<RecordType>,
33
+ } & Omit<TableProps<T>,
34
34
  /** 内部控制的属性/重写的属性 */
35
35
  "rowSelection" | "columns" | "loading" | "dataSource" | "pagination">;
@@ -1,32 +1,33 @@
1
1
  import { ColumnType, ColumnGroupType } from 'antd/es/table';
2
2
  import { TDataSourceItem } from './table';
3
- import { ICellProps, TCellComponentType } from '../components/table/components/cellFunc/types';
3
+ import { TCellProps } from '../components/table/components/cellFunc/types';
4
+ import { TXphExtendComponentPropsMap } from '../../../common';
4
5
 
5
6
  /** 扩展一下antd column的属性,不一定要扩展,只是预留 */
6
7
  type TBaseColumnType<T> = {} & ColumnType<T>;
7
- export interface IComponentColumnProps<T, U extends TCellComponentType> extends Omit<TBaseColumnType<T>, "render"> {
8
+ export interface IComponentColumnProps<T, J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}> extends Omit<TBaseColumnType<T>, "render"> {
8
9
  /** 单元格渲染属性(原理也是使用render渲染不同的内容) */
9
10
  cellFunc: ((props: {
10
11
  text: any;
11
12
  record: T;
12
13
  index: number;
13
- }) => ICellProps<U>[]) | ICellProps<U>[];
14
+ }) => TCellProps<J, K>[]) | TCellProps<J, K>[];
14
15
  }
15
16
  export interface IRenderColumnProps<T> extends Omit<TBaseColumnType<T>, "render"> {
16
17
  render?: ColumnType<T>["render"];
17
18
  }
18
- export interface IGroupColumnProps<T> extends Omit<ColumnGroupType<T>, "children"> {
19
- children: Array<TColumnProps<T>>;
19
+ export interface IGroupColumnProps<T, J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}> extends Omit<ColumnGroupType<T>, "children"> {
20
+ children: Array<TColumnProps<T, J, K>>;
20
21
  }
21
22
  type Without<T, K> = {
22
23
  [P in Exclude<keyof T, K>]?: never;
23
24
  };
24
25
  type XOR<T extends any[]> = T extends [infer A, infer B, ...infer Rest] ? A | B extends object ? (Without<A, keyof B> & B) | (Without<B, keyof A> & A) | XOR<[A | B, ...Rest]> : A | B : T extends [infer A] ? A : never;
25
- export type TColumnProps<RecordType = TDataSourceItem, ComponentType extends TCellComponentType = TCellComponentType> = XOR<[
26
- IComponentColumnProps<RecordType, ComponentType>,
27
- IRenderColumnProps<RecordType>,
28
- IGroupColumnProps<RecordType>
26
+ export type TColumnProps<T = TDataSourceItem, J extends TXphExtendComponentPropsMap = {}, K extends TXphExtendComponentPropsMap = {}> = XOR<[
27
+ IComponentColumnProps<T, J, K>,
28
+ IRenderColumnProps<T>,
29
+ IGroupColumnProps<T, J, K>
29
30
  ]>;
30
- export declare function isComponentColumnProps<T, U extends TCellComponentType>(column: TColumnProps<T, U>): column is IComponentColumnProps<T, U>;
31
+ export declare function isComponentColumnProps<T>(column: TColumnProps<T>): column is IComponentColumnProps<T>;
31
32
  export declare function isChildrenColumnProps<T>(column: TColumnProps<T>): column is IGroupColumnProps<T>;
32
33
  export {};
@@ -1,3 +1,4 @@
1
1
  import { IXphFormProps } from '../../../form';
2
+ import { TXphExtendComponentPropsMap } from '../../../common';
2
3
 
3
- export type TCrudFormProps = IXphFormProps & {};
4
+ export type TCrudFormProps<T extends TXphExtendComponentPropsMap = {}> = IXphFormProps<T> & {};
@@ -1,9 +1,10 @@
1
1
  import { IXphFormProps, IXphFormActionType } from '../../../form';
2
+ import { TXphExtendComponentPropsMap } from '../../../common';
2
3
 
3
4
  export type TSearchFormActionType = IXphFormActionType & {
4
5
  setFormLoading: (loading: boolean) => void;
5
6
  };
6
- export type TSearchFormProps = IXphFormProps & {
7
+ export type TSearchFormProps<T extends TXphExtendComponentPropsMap = {}> = IXphFormProps<T> & {
7
8
  /** 是否显示搜索 & 重置按钮 */
8
9
  showSearch?: boolean;
9
10
  };
@@ -2,17 +2,28 @@ import { TableRef } from 'antd/es/table';
2
2
  import { TSearchFormProps } from './searchForm';
3
3
  import { TCrudFormProps } from './crudForm';
4
4
  import { TApiTableProps } from './apiTable';
5
+ import { TXphExtendComponentPropsMap } from '../../../common';
5
6
 
6
7
  /** 行数据 */
7
8
  export type TDataSourceItem = Record<PropertyKey, any>;
8
9
  /** 整个组件的配置 */
9
- export type TTableProps<RecordType = TDataSourceItem> = {
10
+ export type TTableProps<
11
+ /** 行数据类型 */
12
+ RecordType = TDataSourceItem,
13
+ /** 单元格扩展组件props映射 */
14
+ CellFuncExtendPropsMap extends TXphExtendComponentPropsMap = {},
15
+ /** 操作组扩展组件props映射 */
16
+ ActionsExtendPropsMap extends TXphExtendComponentPropsMap = {},
17
+ /** 顶部操作栏扩展组件props映射 */
18
+ ToolbarExtendPropsMap extends TXphExtendComponentPropsMap = {},
19
+ /** 表单扩展组件props映射(包括:搜素表单 & 新增/修改表单) */
20
+ FormExtendPropsMap extends TXphExtendComponentPropsMap = {}> = {
10
21
  /** 表格配置 */
11
- table?: TApiTableProps<RecordType>;
22
+ table?: TApiTableProps<RecordType, CellFuncExtendPropsMap, ActionsExtendPropsMap, ToolbarExtendPropsMap>;
12
23
  /** 搜索表单配置项 */
13
- searchForm?: TSearchFormProps;
24
+ searchForm?: TSearchFormProps<FormExtendPropsMap>;
14
25
  /** 新增 / 修改表单配置项 */
15
- crudForm?: TCrudFormProps;
26
+ crudForm?: TCrudFormProps<FormExtendPropsMap>;
16
27
  /** 分页改变事件 */
17
28
  onPaginationChange?: (page: number, pageSize: number) => void;
18
29
  /** 列表选中事件 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xph-crud",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -11,10 +11,10 @@
11
11
  "configurable-component"
12
12
  ],
13
13
  "scripts": {
14
- "web": "vite",
14
+ "examples": "vite",
15
15
  "build": "tsc && vite build",
16
- "example": "cd example && npm run start",
17
- "build:example": "cd example && npm run build",
16
+ "docs": "cd docs && npm run start",
17
+ "build:docs": "cd docs && npm run build",
18
18
  "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
19
19
  },
20
20
  "files": [