@wordrhyme/auto-crud 1.2.5 → 1.3.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.
- package/README.md +116 -46
- package/dist/index.cjs +352 -99
- package/dist/index.d.cts +107 -34
- package/dist/index.d.ts +107 -34
- package/dist/index.js +352 -100
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -313,7 +313,12 @@ interface BatchActionContext<TData> {
|
|
|
313
313
|
clearSelection: () => void;
|
|
314
314
|
}
|
|
315
315
|
type BatchBuiltinActionType = 'batchUpdate' | 'export' | 'delete';
|
|
316
|
-
type
|
|
316
|
+
type BatchActionMeta = {
|
|
317
|
+
id?: string;
|
|
318
|
+
order?: number;
|
|
319
|
+
hidden?: boolean;
|
|
320
|
+
};
|
|
321
|
+
type BatchBuiltinActionItem<TData> = BatchActionMeta & {
|
|
317
322
|
type: BatchBuiltinActionType;
|
|
318
323
|
/** 替代默认行为 */
|
|
319
324
|
onClick?: (rows: TData[], context: BatchActionContext<TData>, event: React$1.MouseEvent<HTMLButtonElement>) => void;
|
|
@@ -322,7 +327,7 @@ type BatchBuiltinActionItem<TData> = {
|
|
|
322
327
|
/** 替代整个内置操作的渲染 */
|
|
323
328
|
component?: React$1.ReactNode | ((context: BatchActionContext<TData>) => React$1.ReactNode);
|
|
324
329
|
};
|
|
325
|
-
type BatchCustomActionItem<TData> = {
|
|
330
|
+
type BatchCustomActionItem<TData> = BatchActionMeta & {
|
|
326
331
|
type: 'custom';
|
|
327
332
|
/** 操作文本。传 component 时可省略 */
|
|
328
333
|
label?: string;
|
|
@@ -448,16 +453,18 @@ declare function createSelectColumn<T>(): ColumnDef<T>;
|
|
|
448
453
|
/**
|
|
449
454
|
* 已解析的操作项(渲染层使用)
|
|
450
455
|
*/
|
|
451
|
-
interface ResolvedActionItem<T> {
|
|
452
|
-
label
|
|
453
|
-
onClick
|
|
456
|
+
interface ResolvedActionItem<T, TContext = any> {
|
|
457
|
+
label?: string;
|
|
458
|
+
onClick?: (row: T) => void;
|
|
459
|
+
component?: React$1.ReactNode | ((context: TContext) => React$1.ReactNode);
|
|
460
|
+
getContext?: (row: T) => TContext;
|
|
454
461
|
separator?: boolean;
|
|
455
462
|
variant?: 'default' | 'destructive';
|
|
456
463
|
}
|
|
457
464
|
/**
|
|
458
465
|
* 操作列配置(ResolvedActionItem 数组)
|
|
459
466
|
*/
|
|
460
|
-
type ActionsColumnConfig<T> = ResolvedActionItem<T>[];
|
|
467
|
+
type ActionsColumnConfig<T> = ResolvedActionItem<T, any>[];
|
|
461
468
|
/**
|
|
462
469
|
* 创建操作列
|
|
463
470
|
*/
|
|
@@ -662,27 +669,27 @@ type AutoCrudDataSourceEntry = {
|
|
|
662
669
|
reset: boolean;
|
|
663
670
|
load: AutoCrudDataSourceLoader;
|
|
664
671
|
};
|
|
665
|
-
type RegistryListener = () => void;
|
|
672
|
+
type RegistryListener$1 = () => void;
|
|
666
673
|
declare const formComponents: {
|
|
667
674
|
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
668
675
|
unregister(name: string): void;
|
|
669
676
|
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
670
677
|
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
671
|
-
subscribe(listener: RegistryListener): () => void;
|
|
678
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
672
679
|
};
|
|
673
680
|
declare const components: {
|
|
674
681
|
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
675
682
|
unregister(name: string): void;
|
|
676
683
|
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
677
684
|
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
678
|
-
subscribe(listener: RegistryListener): () => void;
|
|
685
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
679
686
|
};
|
|
680
687
|
declare const dataSources: {
|
|
681
688
|
register(name: string, registration: AutoCrudDataSourceRegistration): void;
|
|
682
689
|
unregister: (name: string) => void;
|
|
683
690
|
get: (name: string) => AutoCrudDataSourceEntry | undefined;
|
|
684
691
|
all: () => Record<string, AutoCrudDataSourceEntry>;
|
|
685
|
-
subscribe: (listener: RegistryListener) => () => void;
|
|
692
|
+
subscribe: (listener: RegistryListener$1) => () => void;
|
|
686
693
|
};
|
|
687
694
|
declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
|
|
688
695
|
key: string;
|
|
@@ -778,51 +785,76 @@ interface Field {
|
|
|
778
785
|
} | false;
|
|
779
786
|
}
|
|
780
787
|
type Fields = Record<string, Field>;
|
|
781
|
-
type BuiltinType = 'view' | 'edit' | 'copy' | 'delete';
|
|
782
788
|
/** 内置操作项(覆盖默认行为或调整位置) */
|
|
783
|
-
type
|
|
784
|
-
|
|
789
|
+
type ActionMeta = {
|
|
790
|
+
id?: string;
|
|
791
|
+
order?: number;
|
|
792
|
+
hidden?: boolean;
|
|
793
|
+
};
|
|
794
|
+
interface AutoCrudRowActionContext<T> {
|
|
795
|
+
crudId: string;
|
|
796
|
+
idKey: string;
|
|
797
|
+
row: T;
|
|
798
|
+
rowId?: string;
|
|
799
|
+
openView: (row: T) => void;
|
|
800
|
+
openEdit?: (row: T) => void;
|
|
801
|
+
copyRow?: (row: T) => void;
|
|
802
|
+
openDelete?: (row: T) => void;
|
|
803
|
+
}
|
|
804
|
+
type ActionComponent<TContext> = React$1.ReactNode | ((context: TContext) => React$1.ReactNode);
|
|
805
|
+
type RowBuiltinActionType = 'view' | 'edit' | 'copy' | 'delete';
|
|
806
|
+
type RowBuiltinActionItem<T> = ActionMeta & {
|
|
807
|
+
type: RowBuiltinActionType;
|
|
785
808
|
onClick?: (row: T) => void;
|
|
786
809
|
label?: string;
|
|
787
810
|
separator?: boolean;
|
|
788
811
|
};
|
|
789
|
-
|
|
790
|
-
type CustomActionItem<T> = {
|
|
812
|
+
type RowCustomActionItem<T> = ActionMeta & {
|
|
791
813
|
type: 'custom';
|
|
792
|
-
label
|
|
793
|
-
onClick
|
|
794
|
-
|
|
814
|
+
label?: string;
|
|
815
|
+
onClick?: (row: T) => void;
|
|
816
|
+
component?: ActionComponent<AutoCrudRowActionContext<T>>;
|
|
795
817
|
position?: 'start' | 'end';
|
|
796
818
|
separator?: boolean;
|
|
797
819
|
variant?: 'default' | 'destructive';
|
|
798
820
|
};
|
|
799
821
|
/**
|
|
800
|
-
*
|
|
822
|
+
* Row action item.
|
|
801
823
|
*
|
|
802
|
-
* -
|
|
803
|
-
* -
|
|
804
|
-
*/
|
|
805
|
-
type
|
|
806
|
-
type
|
|
824
|
+
* - Custom-only config keeps builtin row actions and appends custom actions.
|
|
825
|
+
* - Including any builtin type takes over builtin ordering.
|
|
826
|
+
*/
|
|
827
|
+
type RowActionItem<T> = RowBuiltinActionItem<T> | RowCustomActionItem<T>;
|
|
828
|
+
type RowActionConfig<T> = RowActionItem<T>[] | ((defaults: RowBuiltinActionItem<T>[]) => RowActionItem<T>[]);
|
|
829
|
+
/** @deprecated Use RowActionItem instead. */
|
|
830
|
+
type ActionItem<T> = RowActionItem<T>;
|
|
831
|
+
/** @deprecated Use RowActionConfig instead. */
|
|
832
|
+
type ActionConfig<T> = RowActionConfig<T>;
|
|
833
|
+
type AutoCrudActionsConfig<T> = {
|
|
834
|
+
toolbar?: ToolbarActionConfig;
|
|
835
|
+
row?: RowActionConfig<T>;
|
|
836
|
+
batch?: BatchActionConfig<T>;
|
|
837
|
+
};
|
|
838
|
+
type AutoCrudActionConfig<T> = RowActionConfig<T> | AutoCrudActionsConfig<T>;
|
|
807
839
|
/**
|
|
808
840
|
* 顶部工具栏内置操作项
|
|
809
841
|
*/
|
|
810
|
-
type ToolbarBuiltinActionItem = {
|
|
842
|
+
type ToolbarBuiltinActionItem = ActionMeta & {
|
|
811
843
|
type: 'create' | 'import' | 'export';
|
|
812
844
|
/** 替代默认的行为 */
|
|
813
845
|
onClick?: () => void;
|
|
814
846
|
/** 替代默认的标签文本 */
|
|
815
847
|
label?: string;
|
|
816
848
|
/** 替代整个按钮的渲染 */
|
|
817
|
-
component?:
|
|
849
|
+
component?: ActionComponent<AutoCrudToolbarContext>;
|
|
818
850
|
};
|
|
819
851
|
/**
|
|
820
852
|
* 顶部工具栏自定义操作项
|
|
821
853
|
*/
|
|
822
|
-
type ToolbarCustomActionItem = {
|
|
854
|
+
type ToolbarCustomActionItem = ActionMeta & {
|
|
823
855
|
type: 'custom';
|
|
824
856
|
/** 渲染自定义内容 */
|
|
825
|
-
component:
|
|
857
|
+
component: ActionComponent<AutoCrudToolbarContext>;
|
|
826
858
|
/** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
|
|
827
859
|
position?: 'start' | 'end';
|
|
828
860
|
};
|
|
@@ -883,6 +915,7 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
883
915
|
* 多选后悬浮批量操作栏配置
|
|
884
916
|
* 用法类同 `actions` 行操作和 `toolbar` 顶部工具栏。
|
|
885
917
|
* 只传 custom 时保留默认批量操作;包含任意内置 type 时完全接管顺序。
|
|
918
|
+
* @deprecated Use actions.batch instead.
|
|
886
919
|
*/
|
|
887
920
|
batchActions?: BatchActionConfig<z.output<TSchema>>;
|
|
888
921
|
/** 默认排序 */
|
|
@@ -897,11 +930,12 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
897
930
|
/** 弹窗自定义容器类名(支持控制大小、最大高度等) */
|
|
898
931
|
className?: string;
|
|
899
932
|
};
|
|
900
|
-
/**
|
|
901
|
-
actions?:
|
|
933
|
+
/** 行操作配置,或统一的 toolbar/row/batch 操作配置。 */
|
|
934
|
+
actions?: AutoCrudActionConfig<z.output<TSchema>>;
|
|
902
935
|
/**
|
|
903
936
|
* 顶层工具栏操作配置
|
|
904
937
|
* 用法类同 `actions` 行操作。一旦配置了包含内置 `type` 的数组,它将完全接管右侧工具栏!
|
|
938
|
+
* @deprecated Use actions.toolbar instead.
|
|
905
939
|
*/
|
|
906
940
|
toolbar?: ToolbarActionConfig;
|
|
907
941
|
/** @deprecated Use toolbar instead. */
|
|
@@ -1211,12 +1245,12 @@ declare const filterItemSchema: z.ZodObject<{
|
|
|
1211
1245
|
variant: z.ZodEnum<{
|
|
1212
1246
|
number: "number";
|
|
1213
1247
|
boolean: "boolean";
|
|
1214
|
-
date: "date";
|
|
1215
1248
|
text: "text";
|
|
1249
|
+
range: "range";
|
|
1250
|
+
date: "date";
|
|
1251
|
+
dateRange: "dateRange";
|
|
1216
1252
|
select: "select";
|
|
1217
1253
|
multiSelect: "multiSelect";
|
|
1218
|
-
dateRange: "dateRange";
|
|
1219
|
-
range: "range";
|
|
1220
1254
|
}>;
|
|
1221
1255
|
operator: z.ZodEnum<{
|
|
1222
1256
|
iLike: "iLike";
|
|
@@ -1510,6 +1544,45 @@ interface MultiComboboxProps extends Omit<ComponentProps<typeof Command>, 'value
|
|
|
1510
1544
|
}
|
|
1511
1545
|
declare const MultiCombobox: React$1.FC<MultiComboboxProps>;
|
|
1512
1546
|
//#endregion
|
|
1547
|
+
//#region src/lib/crud-actions.d.ts
|
|
1548
|
+
type CrudActionZone = 'toolbar' | 'row' | 'batch';
|
|
1549
|
+
type CrudActionBase = {
|
|
1550
|
+
type: string;
|
|
1551
|
+
id?: string;
|
|
1552
|
+
order?: number;
|
|
1553
|
+
hidden?: boolean;
|
|
1554
|
+
position?: 'start' | 'end';
|
|
1555
|
+
};
|
|
1556
|
+
type CrudActionEntry<TAction extends CrudActionBase = CrudActionBase> = {
|
|
1557
|
+
targetId: string;
|
|
1558
|
+
zone: CrudActionZone;
|
|
1559
|
+
ownerId: string;
|
|
1560
|
+
action: TAction;
|
|
1561
|
+
order: number;
|
|
1562
|
+
seq: number;
|
|
1563
|
+
};
|
|
1564
|
+
type CrudActionRegistration<TAction extends CrudActionBase = CrudActionBase> = {
|
|
1565
|
+
targetId: string;
|
|
1566
|
+
zone: CrudActionZone;
|
|
1567
|
+
ownerId: string;
|
|
1568
|
+
actions: readonly TAction[];
|
|
1569
|
+
};
|
|
1570
|
+
type RegistryListener = () => void;
|
|
1571
|
+
declare function unregisterOwnerActions(ownerId: string, options?: {
|
|
1572
|
+
targetId?: string;
|
|
1573
|
+
zone?: CrudActionZone;
|
|
1574
|
+
}, shouldNotify?: boolean): void;
|
|
1575
|
+
declare function resolveActions<TAction extends CrudActionBase>(targetId: string | undefined, zone: CrudActionZone, ownerActions: readonly TAction[]): TAction[];
|
|
1576
|
+
declare const crudActions: {
|
|
1577
|
+
register<TAction extends CrudActionBase>(registration: CrudActionRegistration<TAction>): void;
|
|
1578
|
+
unregister: typeof unregisterOwnerActions;
|
|
1579
|
+
clear(): void;
|
|
1580
|
+
get<TAction extends CrudActionBase>(targetId: string, zone: CrudActionZone): CrudActionEntry<TAction>[];
|
|
1581
|
+
resolve: typeof resolveActions;
|
|
1582
|
+
subscribe(listener: RegistryListener): () => void;
|
|
1583
|
+
getSnapshot(): number;
|
|
1584
|
+
};
|
|
1585
|
+
//#endregion
|
|
1513
1586
|
//#region src/hooks/use-data-table.d.ts
|
|
1514
1587
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
|
1515
1588
|
initialState?: Omit<Partial<TableState>, "sorting"> & {
|
|
@@ -1844,4 +1917,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
|
|
|
1844
1917
|
*/
|
|
1845
1918
|
declare function downloadCSVTemplate(headers: string[], filename?: string): void;
|
|
1846
1919
|
//#endregion
|
|
1847
|
-
export { type ActionItem, type ActionsColumnConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, setToolbarResolver, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
|
1920
|
+
export { type ActionConfig, type ActionItem, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, type AutoCrudRowActionContext, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, type RowActionConfig, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, setToolbarResolver, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
package/dist/index.d.ts
CHANGED
|
@@ -313,7 +313,12 @@ interface BatchActionContext<TData> {
|
|
|
313
313
|
clearSelection: () => void;
|
|
314
314
|
}
|
|
315
315
|
type BatchBuiltinActionType = 'batchUpdate' | 'export' | 'delete';
|
|
316
|
-
type
|
|
316
|
+
type BatchActionMeta = {
|
|
317
|
+
id?: string;
|
|
318
|
+
order?: number;
|
|
319
|
+
hidden?: boolean;
|
|
320
|
+
};
|
|
321
|
+
type BatchBuiltinActionItem<TData> = BatchActionMeta & {
|
|
317
322
|
type: BatchBuiltinActionType;
|
|
318
323
|
/** 替代默认行为 */
|
|
319
324
|
onClick?: (rows: TData[], context: BatchActionContext<TData>, event: React$1.MouseEvent<HTMLButtonElement>) => void;
|
|
@@ -322,7 +327,7 @@ type BatchBuiltinActionItem<TData> = {
|
|
|
322
327
|
/** 替代整个内置操作的渲染 */
|
|
323
328
|
component?: React$1.ReactNode | ((context: BatchActionContext<TData>) => React$1.ReactNode);
|
|
324
329
|
};
|
|
325
|
-
type BatchCustomActionItem<TData> = {
|
|
330
|
+
type BatchCustomActionItem<TData> = BatchActionMeta & {
|
|
326
331
|
type: 'custom';
|
|
327
332
|
/** 操作文本。传 component 时可省略 */
|
|
328
333
|
label?: string;
|
|
@@ -448,16 +453,18 @@ declare function createSelectColumn<T>(): ColumnDef<T>;
|
|
|
448
453
|
/**
|
|
449
454
|
* 已解析的操作项(渲染层使用)
|
|
450
455
|
*/
|
|
451
|
-
interface ResolvedActionItem<T> {
|
|
452
|
-
label
|
|
453
|
-
onClick
|
|
456
|
+
interface ResolvedActionItem<T, TContext = any> {
|
|
457
|
+
label?: string;
|
|
458
|
+
onClick?: (row: T) => void;
|
|
459
|
+
component?: React$1.ReactNode | ((context: TContext) => React$1.ReactNode);
|
|
460
|
+
getContext?: (row: T) => TContext;
|
|
454
461
|
separator?: boolean;
|
|
455
462
|
variant?: 'default' | 'destructive';
|
|
456
463
|
}
|
|
457
464
|
/**
|
|
458
465
|
* 操作列配置(ResolvedActionItem 数组)
|
|
459
466
|
*/
|
|
460
|
-
type ActionsColumnConfig<T> = ResolvedActionItem<T>[];
|
|
467
|
+
type ActionsColumnConfig<T> = ResolvedActionItem<T, any>[];
|
|
461
468
|
/**
|
|
462
469
|
* 创建操作列
|
|
463
470
|
*/
|
|
@@ -662,27 +669,27 @@ type AutoCrudDataSourceEntry = {
|
|
|
662
669
|
reset: boolean;
|
|
663
670
|
load: AutoCrudDataSourceLoader;
|
|
664
671
|
};
|
|
665
|
-
type RegistryListener = () => void;
|
|
672
|
+
type RegistryListener$1 = () => void;
|
|
666
673
|
declare const formComponents: {
|
|
667
674
|
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
668
675
|
unregister(name: string): void;
|
|
669
676
|
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
670
677
|
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
671
|
-
subscribe(listener: RegistryListener): () => void;
|
|
678
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
672
679
|
};
|
|
673
680
|
declare const components: {
|
|
674
681
|
register(name: string, value: AutoCrudFormComponentConfig): void;
|
|
675
682
|
unregister(name: string): void;
|
|
676
683
|
get(name: string): AutoCrudFormComponentConfig | undefined;
|
|
677
684
|
all(): Record<string, AutoCrudFormComponentConfig>;
|
|
678
|
-
subscribe(listener: RegistryListener): () => void;
|
|
685
|
+
subscribe(listener: RegistryListener$1): () => void;
|
|
679
686
|
};
|
|
680
687
|
declare const dataSources: {
|
|
681
688
|
register(name: string, registration: AutoCrudDataSourceRegistration): void;
|
|
682
689
|
unregister: (name: string) => void;
|
|
683
690
|
get: (name: string) => AutoCrudDataSourceEntry | undefined;
|
|
684
691
|
all: () => Record<string, AutoCrudDataSourceEntry>;
|
|
685
|
-
subscribe: (listener: RegistryListener) => () => void;
|
|
692
|
+
subscribe: (listener: RegistryListener$1) => () => void;
|
|
686
693
|
};
|
|
687
694
|
declare function normalizeDataSourceConfig(config: AutoCrudDataSourceConfig | undefined): {
|
|
688
695
|
key: string;
|
|
@@ -778,51 +785,76 @@ interface Field {
|
|
|
778
785
|
} | false;
|
|
779
786
|
}
|
|
780
787
|
type Fields = Record<string, Field>;
|
|
781
|
-
type BuiltinType = 'view' | 'edit' | 'copy' | 'delete';
|
|
782
788
|
/** 内置操作项(覆盖默认行为或调整位置) */
|
|
783
|
-
type
|
|
784
|
-
|
|
789
|
+
type ActionMeta = {
|
|
790
|
+
id?: string;
|
|
791
|
+
order?: number;
|
|
792
|
+
hidden?: boolean;
|
|
793
|
+
};
|
|
794
|
+
interface AutoCrudRowActionContext<T> {
|
|
795
|
+
crudId: string;
|
|
796
|
+
idKey: string;
|
|
797
|
+
row: T;
|
|
798
|
+
rowId?: string;
|
|
799
|
+
openView: (row: T) => void;
|
|
800
|
+
openEdit?: (row: T) => void;
|
|
801
|
+
copyRow?: (row: T) => void;
|
|
802
|
+
openDelete?: (row: T) => void;
|
|
803
|
+
}
|
|
804
|
+
type ActionComponent<TContext> = React$1.ReactNode | ((context: TContext) => React$1.ReactNode);
|
|
805
|
+
type RowBuiltinActionType = 'view' | 'edit' | 'copy' | 'delete';
|
|
806
|
+
type RowBuiltinActionItem<T> = ActionMeta & {
|
|
807
|
+
type: RowBuiltinActionType;
|
|
785
808
|
onClick?: (row: T) => void;
|
|
786
809
|
label?: string;
|
|
787
810
|
separator?: boolean;
|
|
788
811
|
};
|
|
789
|
-
|
|
790
|
-
type CustomActionItem<T> = {
|
|
812
|
+
type RowCustomActionItem<T> = ActionMeta & {
|
|
791
813
|
type: 'custom';
|
|
792
|
-
label
|
|
793
|
-
onClick
|
|
794
|
-
|
|
814
|
+
label?: string;
|
|
815
|
+
onClick?: (row: T) => void;
|
|
816
|
+
component?: ActionComponent<AutoCrudRowActionContext<T>>;
|
|
795
817
|
position?: 'start' | 'end';
|
|
796
818
|
separator?: boolean;
|
|
797
819
|
variant?: 'default' | 'destructive';
|
|
798
820
|
};
|
|
799
821
|
/**
|
|
800
|
-
*
|
|
822
|
+
* Row action item.
|
|
801
823
|
*
|
|
802
|
-
* -
|
|
803
|
-
* -
|
|
804
|
-
*/
|
|
805
|
-
type
|
|
806
|
-
type
|
|
824
|
+
* - Custom-only config keeps builtin row actions and appends custom actions.
|
|
825
|
+
* - Including any builtin type takes over builtin ordering.
|
|
826
|
+
*/
|
|
827
|
+
type RowActionItem<T> = RowBuiltinActionItem<T> | RowCustomActionItem<T>;
|
|
828
|
+
type RowActionConfig<T> = RowActionItem<T>[] | ((defaults: RowBuiltinActionItem<T>[]) => RowActionItem<T>[]);
|
|
829
|
+
/** @deprecated Use RowActionItem instead. */
|
|
830
|
+
type ActionItem<T> = RowActionItem<T>;
|
|
831
|
+
/** @deprecated Use RowActionConfig instead. */
|
|
832
|
+
type ActionConfig<T> = RowActionConfig<T>;
|
|
833
|
+
type AutoCrudActionsConfig<T> = {
|
|
834
|
+
toolbar?: ToolbarActionConfig;
|
|
835
|
+
row?: RowActionConfig<T>;
|
|
836
|
+
batch?: BatchActionConfig<T>;
|
|
837
|
+
};
|
|
838
|
+
type AutoCrudActionConfig<T> = RowActionConfig<T> | AutoCrudActionsConfig<T>;
|
|
807
839
|
/**
|
|
808
840
|
* 顶部工具栏内置操作项
|
|
809
841
|
*/
|
|
810
|
-
type ToolbarBuiltinActionItem = {
|
|
842
|
+
type ToolbarBuiltinActionItem = ActionMeta & {
|
|
811
843
|
type: 'create' | 'import' | 'export';
|
|
812
844
|
/** 替代默认的行为 */
|
|
813
845
|
onClick?: () => void;
|
|
814
846
|
/** 替代默认的标签文本 */
|
|
815
847
|
label?: string;
|
|
816
848
|
/** 替代整个按钮的渲染 */
|
|
817
|
-
component?:
|
|
849
|
+
component?: ActionComponent<AutoCrudToolbarContext>;
|
|
818
850
|
};
|
|
819
851
|
/**
|
|
820
852
|
* 顶部工具栏自定义操作项
|
|
821
853
|
*/
|
|
822
|
-
type ToolbarCustomActionItem = {
|
|
854
|
+
type ToolbarCustomActionItem = ActionMeta & {
|
|
823
855
|
type: 'custom';
|
|
824
856
|
/** 渲染自定义内容 */
|
|
825
|
-
component:
|
|
857
|
+
component: ActionComponent<AutoCrudToolbarContext>;
|
|
826
858
|
/** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
|
|
827
859
|
position?: 'start' | 'end';
|
|
828
860
|
};
|
|
@@ -883,6 +915,7 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
883
915
|
* 多选后悬浮批量操作栏配置
|
|
884
916
|
* 用法类同 `actions` 行操作和 `toolbar` 顶部工具栏。
|
|
885
917
|
* 只传 custom 时保留默认批量操作;包含任意内置 type 时完全接管顺序。
|
|
918
|
+
* @deprecated Use actions.batch instead.
|
|
886
919
|
*/
|
|
887
920
|
batchActions?: BatchActionConfig<z.output<TSchema>>;
|
|
888
921
|
/** 默认排序 */
|
|
@@ -897,11 +930,12 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
897
930
|
/** 弹窗自定义容器类名(支持控制大小、最大高度等) */
|
|
898
931
|
className?: string;
|
|
899
932
|
};
|
|
900
|
-
/**
|
|
901
|
-
actions?:
|
|
933
|
+
/** 行操作配置,或统一的 toolbar/row/batch 操作配置。 */
|
|
934
|
+
actions?: AutoCrudActionConfig<z.output<TSchema>>;
|
|
902
935
|
/**
|
|
903
936
|
* 顶层工具栏操作配置
|
|
904
937
|
* 用法类同 `actions` 行操作。一旦配置了包含内置 `type` 的数组,它将完全接管右侧工具栏!
|
|
938
|
+
* @deprecated Use actions.toolbar instead.
|
|
905
939
|
*/
|
|
906
940
|
toolbar?: ToolbarActionConfig;
|
|
907
941
|
/** @deprecated Use toolbar instead. */
|
|
@@ -1211,12 +1245,12 @@ declare const filterItemSchema: z.ZodObject<{
|
|
|
1211
1245
|
variant: z.ZodEnum<{
|
|
1212
1246
|
number: "number";
|
|
1213
1247
|
boolean: "boolean";
|
|
1214
|
-
date: "date";
|
|
1215
1248
|
text: "text";
|
|
1249
|
+
range: "range";
|
|
1250
|
+
date: "date";
|
|
1251
|
+
dateRange: "dateRange";
|
|
1216
1252
|
select: "select";
|
|
1217
1253
|
multiSelect: "multiSelect";
|
|
1218
|
-
dateRange: "dateRange";
|
|
1219
|
-
range: "range";
|
|
1220
1254
|
}>;
|
|
1221
1255
|
operator: z.ZodEnum<{
|
|
1222
1256
|
iLike: "iLike";
|
|
@@ -1510,6 +1544,45 @@ interface MultiComboboxProps extends Omit<ComponentProps<typeof Command>, 'value
|
|
|
1510
1544
|
}
|
|
1511
1545
|
declare const MultiCombobox: React$1.FC<MultiComboboxProps>;
|
|
1512
1546
|
//#endregion
|
|
1547
|
+
//#region src/lib/crud-actions.d.ts
|
|
1548
|
+
type CrudActionZone = 'toolbar' | 'row' | 'batch';
|
|
1549
|
+
type CrudActionBase = {
|
|
1550
|
+
type: string;
|
|
1551
|
+
id?: string;
|
|
1552
|
+
order?: number;
|
|
1553
|
+
hidden?: boolean;
|
|
1554
|
+
position?: 'start' | 'end';
|
|
1555
|
+
};
|
|
1556
|
+
type CrudActionEntry<TAction extends CrudActionBase = CrudActionBase> = {
|
|
1557
|
+
targetId: string;
|
|
1558
|
+
zone: CrudActionZone;
|
|
1559
|
+
ownerId: string;
|
|
1560
|
+
action: TAction;
|
|
1561
|
+
order: number;
|
|
1562
|
+
seq: number;
|
|
1563
|
+
};
|
|
1564
|
+
type CrudActionRegistration<TAction extends CrudActionBase = CrudActionBase> = {
|
|
1565
|
+
targetId: string;
|
|
1566
|
+
zone: CrudActionZone;
|
|
1567
|
+
ownerId: string;
|
|
1568
|
+
actions: readonly TAction[];
|
|
1569
|
+
};
|
|
1570
|
+
type RegistryListener = () => void;
|
|
1571
|
+
declare function unregisterOwnerActions(ownerId: string, options?: {
|
|
1572
|
+
targetId?: string;
|
|
1573
|
+
zone?: CrudActionZone;
|
|
1574
|
+
}, shouldNotify?: boolean): void;
|
|
1575
|
+
declare function resolveActions<TAction extends CrudActionBase>(targetId: string | undefined, zone: CrudActionZone, ownerActions: readonly TAction[]): TAction[];
|
|
1576
|
+
declare const crudActions: {
|
|
1577
|
+
register<TAction extends CrudActionBase>(registration: CrudActionRegistration<TAction>): void;
|
|
1578
|
+
unregister: typeof unregisterOwnerActions;
|
|
1579
|
+
clear(): void;
|
|
1580
|
+
get<TAction extends CrudActionBase>(targetId: string, zone: CrudActionZone): CrudActionEntry<TAction>[];
|
|
1581
|
+
resolve: typeof resolveActions;
|
|
1582
|
+
subscribe(listener: RegistryListener): () => void;
|
|
1583
|
+
getSnapshot(): number;
|
|
1584
|
+
};
|
|
1585
|
+
//#endregion
|
|
1513
1586
|
//#region src/hooks/use-data-table.d.ts
|
|
1514
1587
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
|
1515
1588
|
initialState?: Omit<Partial<TableState>, "sorting"> & {
|
|
@@ -1844,4 +1917,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
|
|
|
1844
1917
|
*/
|
|
1845
1918
|
declare function downloadCSVTemplate(headers: string[], filename?: string): void;
|
|
1846
1919
|
//#endregion
|
|
1847
|
-
export { type ActionItem, type ActionsColumnConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, setToolbarResolver, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
|
1920
|
+
export { type ActionConfig, type ActionItem, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, type AutoCrudRowActionContext, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, type RowActionConfig, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, components, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, setToolbarResolver, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|