@wordrhyme/auto-crud 1.1.0 → 1.1.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.
- package/README.md +243 -154
- package/dist/index.cjs +131 -39
- package/dist/index.d.cts +84 -34
- package/dist/index.d.ts +84 -34
- package/dist/index.js +131 -39
- package/package.json +13 -13
package/dist/index.cjs
CHANGED
|
@@ -4257,11 +4257,27 @@ function downloadCSV(csvContent, filename) {
|
|
|
4257
4257
|
|
|
4258
4258
|
//#endregion
|
|
4259
4259
|
//#region src/components/auto-crud/auto-table-action-bar.tsx
|
|
4260
|
-
function
|
|
4260
|
+
function isBatchCustomAction(action) {
|
|
4261
|
+
return action.type === "custom";
|
|
4262
|
+
}
|
|
4263
|
+
function AutoTableActionBar({ table, onDeleteSelected, onUpdateSelected, batchUpdateFields, enableExport = true, showDefaultExport = true, enableDelete = true, extraActions, actions }) {
|
|
4261
4264
|
const rows = table.getFilteredSelectedRowModel().rows;
|
|
4262
|
-
const
|
|
4263
|
-
|
|
4265
|
+
const selectedRows = react.useMemo(() => rows.map((row) => row.original), [rows]);
|
|
4266
|
+
const clearSelection = react.useCallback(() => {
|
|
4267
|
+
table.toggleAllRowsSelected(false);
|
|
4264
4268
|
}, [table]);
|
|
4269
|
+
const actionContext = react.useMemo(() => ({
|
|
4270
|
+
rows: selectedRows,
|
|
4271
|
+
table,
|
|
4272
|
+
clearSelection
|
|
4273
|
+
}), [
|
|
4274
|
+
selectedRows,
|
|
4275
|
+
table,
|
|
4276
|
+
clearSelection
|
|
4277
|
+
]);
|
|
4278
|
+
const onOpenChange = react.useCallback((open) => {
|
|
4279
|
+
if (!open) clearSelection();
|
|
4280
|
+
}, [clearSelection]);
|
|
4265
4281
|
const onExport = react.useCallback(() => {
|
|
4266
4282
|
exportTableToCSV(table, {
|
|
4267
4283
|
excludeColumns: ["select", "actions"],
|
|
@@ -4269,17 +4285,108 @@ function AutoTableActionBar({ table, onDeleteSelected, onUpdateSelected, batchUp
|
|
|
4269
4285
|
});
|
|
4270
4286
|
}, [table]);
|
|
4271
4287
|
const onDelete = react.useCallback(() => {
|
|
4272
|
-
if (onDeleteSelected) onDeleteSelected(
|
|
4273
|
-
}, [
|
|
4288
|
+
if (onDeleteSelected) onDeleteSelected(selectedRows);
|
|
4289
|
+
}, [selectedRows, onDeleteSelected]);
|
|
4274
4290
|
const handleBatchUpdate = react.useCallback((field, value) => {
|
|
4275
4291
|
if (onUpdateSelected) {
|
|
4276
|
-
onUpdateSelected(
|
|
4277
|
-
|
|
4292
|
+
onUpdateSelected(selectedRows, { [field]: value });
|
|
4293
|
+
clearSelection();
|
|
4278
4294
|
}
|
|
4279
4295
|
}, [
|
|
4280
|
-
|
|
4296
|
+
selectedRows,
|
|
4297
|
+
onUpdateSelected,
|
|
4298
|
+
clearSelection
|
|
4299
|
+
]);
|
|
4300
|
+
const renderComponent = react.useCallback((component) => typeof component === "function" ? component(actionContext) : component, [actionContext]);
|
|
4301
|
+
const renderBatchUpdate = react.useCallback((keyPrefix = "batch-update") => batchUpdateFields?.map((fieldConfig) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.DropdownMenu, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DropdownMenuTrigger, {
|
|
4302
|
+
asChild: true,
|
|
4303
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
|
|
4304
|
+
variant: "ghost",
|
|
4305
|
+
size: "sm",
|
|
4306
|
+
className: "h-7 gap-1 px-2",
|
|
4307
|
+
children: [fieldConfig.label, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-3.5" })]
|
|
4308
|
+
})
|
|
4309
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DropdownMenuContent, {
|
|
4310
|
+
align: "start",
|
|
4311
|
+
children: fieldConfig.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DropdownMenuItem, {
|
|
4312
|
+
onClick: () => handleBatchUpdate(fieldConfig.field, option.value),
|
|
4313
|
+
children: option.label
|
|
4314
|
+
}, option.value))
|
|
4315
|
+
})] }, `${keyPrefix}-${fieldConfig.field}`)), [batchUpdateFields, handleBatchUpdate]);
|
|
4316
|
+
const renderBuiltinAction = react.useCallback((action) => {
|
|
4317
|
+
if (!(action.type === "batchUpdate" ? !!onUpdateSelected && !!batchUpdateFields?.length : action.type === "export" ? enableExport : enableDelete && !!onDeleteSelected)) return null;
|
|
4318
|
+
if (action.component) return renderComponent(action.component);
|
|
4319
|
+
if (action.type === "batchUpdate") return renderBatchUpdate(action.type);
|
|
4320
|
+
if (action.type === "export") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ActionBarItem, {
|
|
4321
|
+
onClick: (event) => action.onClick ? action.onClick(selectedRows, actionContext, event) : onExport(),
|
|
4322
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Download, {}), action.label ?? "Export"]
|
|
4323
|
+
}, "export");
|
|
4324
|
+
if (action.type === "delete") return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ActionBarItem, {
|
|
4325
|
+
variant: "destructive",
|
|
4326
|
+
onClick: (event) => action.onClick ? action.onClick(selectedRows, actionContext, event) : onDelete(),
|
|
4327
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, {}), action.label ?? "Delete"]
|
|
4328
|
+
}, "delete");
|
|
4329
|
+
return null;
|
|
4330
|
+
}, [
|
|
4331
|
+
actionContext,
|
|
4332
|
+
batchUpdateFields?.length,
|
|
4333
|
+
enableDelete,
|
|
4334
|
+
enableExport,
|
|
4335
|
+
onDelete,
|
|
4336
|
+
onDeleteSelected,
|
|
4281
4337
|
onUpdateSelected,
|
|
4282
|
-
|
|
4338
|
+
onExport,
|
|
4339
|
+
renderBatchUpdate,
|
|
4340
|
+
renderComponent,
|
|
4341
|
+
selectedRows
|
|
4342
|
+
]);
|
|
4343
|
+
const renderCustomAction = react.useCallback((action, index) => {
|
|
4344
|
+
if (action.component) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderComponent(action.component) }, `custom-${index}`);
|
|
4345
|
+
if (!action.label || !action.onClick) return null;
|
|
4346
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionBarItem, {
|
|
4347
|
+
variant: action.variant === "destructive" ? "destructive" : "secondary",
|
|
4348
|
+
onClick: (event) => action.onClick?.(selectedRows, actionContext, event),
|
|
4349
|
+
children: action.label
|
|
4350
|
+
}, `custom-${index}`);
|
|
4351
|
+
}, [
|
|
4352
|
+
actionContext,
|
|
4353
|
+
renderComponent,
|
|
4354
|
+
selectedRows
|
|
4355
|
+
]);
|
|
4356
|
+
const renderedActions = react.useMemo(() => {
|
|
4357
|
+
const resolvedActions = typeof actions === "function" ? actions([
|
|
4358
|
+
{ type: "batchUpdate" },
|
|
4359
|
+
{ type: "export" },
|
|
4360
|
+
{ type: "delete" }
|
|
4361
|
+
]) : actions;
|
|
4362
|
+
if (!resolvedActions || resolvedActions.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
4363
|
+
renderBuiltinAction({ type: "batchUpdate" }),
|
|
4364
|
+
extraActions,
|
|
4365
|
+
showDefaultExport && renderBuiltinAction({ type: "export" }),
|
|
4366
|
+
renderBuiltinAction({ type: "delete" })
|
|
4367
|
+
] });
|
|
4368
|
+
if (!resolvedActions.some((action) => action.type !== "custom")) {
|
|
4369
|
+
const startNodes = resolvedActions.filter(isBatchCustomAction).filter((action) => action.position === "start").map((action, index) => renderCustomAction(action, index));
|
|
4370
|
+
const endNodes = resolvedActions.filter(isBatchCustomAction).filter((action) => action.position !== "start").map((action, index) => renderCustomAction(action, index));
|
|
4371
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
4372
|
+
startNodes,
|
|
4373
|
+
renderBuiltinAction({ type: "batchUpdate" }),
|
|
4374
|
+
extraActions,
|
|
4375
|
+
showDefaultExport && renderBuiltinAction({ type: "export" }),
|
|
4376
|
+
renderBuiltinAction({ type: "delete" }),
|
|
4377
|
+
endNodes
|
|
4378
|
+
] });
|
|
4379
|
+
}
|
|
4380
|
+
return resolvedActions.map((action, index) => {
|
|
4381
|
+
if (action.type === "custom") return renderCustomAction(action, index);
|
|
4382
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: renderBuiltinAction(action) }, action.type);
|
|
4383
|
+
});
|
|
4384
|
+
}, [
|
|
4385
|
+
actions,
|
|
4386
|
+
extraActions,
|
|
4387
|
+
renderBuiltinAction,
|
|
4388
|
+
renderCustomAction,
|
|
4389
|
+
showDefaultExport
|
|
4283
4390
|
]);
|
|
4284
4391
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ActionBar, {
|
|
4285
4392
|
open: rows.length > 0,
|
|
@@ -4295,33 +4402,7 @@ function AutoTableActionBar({ table, onDeleteSelected, onUpdateSelected, batchUp
|
|
|
4295
4402
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionBarClose, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {}) })
|
|
4296
4403
|
] }),
|
|
4297
4404
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionBarSeparator, {}),
|
|
4298
|
-
/* @__PURE__ */ (0, react_jsx_runtime.
|
|
4299
|
-
batchUpdateFields?.map((fieldConfig) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.DropdownMenu, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DropdownMenuTrigger, {
|
|
4300
|
-
asChild: true,
|
|
4301
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
|
|
4302
|
-
variant: "ghost",
|
|
4303
|
-
size: "sm",
|
|
4304
|
-
className: "h-7 gap-1 px-2",
|
|
4305
|
-
children: [fieldConfig.label, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "size-3.5" })]
|
|
4306
|
-
})
|
|
4307
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DropdownMenuContent, {
|
|
4308
|
-
align: "start",
|
|
4309
|
-
children: fieldConfig.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.DropdownMenuItem, {
|
|
4310
|
-
onClick: () => handleBatchUpdate(fieldConfig.field, option.value),
|
|
4311
|
-
children: option.label
|
|
4312
|
-
}, option.value))
|
|
4313
|
-
})] }, fieldConfig.field)),
|
|
4314
|
-
extraActions,
|
|
4315
|
-
enableExport && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ActionBarItem, {
|
|
4316
|
-
onClick: onExport,
|
|
4317
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Download, {}), "Export"]
|
|
4318
|
-
}),
|
|
4319
|
-
enableDelete && onDeleteSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ActionBarItem, {
|
|
4320
|
-
variant: "destructive",
|
|
4321
|
-
onClick: onDelete,
|
|
4322
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, {}), "Delete"]
|
|
4323
|
-
})
|
|
4324
|
-
] })
|
|
4405
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ActionBarGroup, { children: renderedActions })
|
|
4325
4406
|
]
|
|
4326
4407
|
});
|
|
4327
4408
|
}
|
|
@@ -4582,7 +4663,7 @@ const filterModeConfig = {
|
|
|
4582
4663
|
tooltip: "Linear-style command filters"
|
|
4583
4664
|
}
|
|
4584
4665
|
};
|
|
4585
|
-
function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode = "simple", onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, initialSorting, enableExport = true, onSelectedCountChange, getSelectedRows }) {
|
|
4666
|
+
function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode = "simple", onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, getSelectedRows }) {
|
|
4586
4667
|
const modes = filterMode ? Array.isArray(filterMode) ? filterMode : [filterMode] : DEFAULT_MODES;
|
|
4587
4668
|
const [currentMode, setCurrentMode] = useQueryState("filterMode", parseAsStringEnum(modes).withDefault(modes[0] ?? "simple"));
|
|
4588
4669
|
const showToggle = modes.length > 1;
|
|
@@ -4719,7 +4800,9 @@ function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection
|
|
|
4719
4800
|
batchUpdateFields,
|
|
4720
4801
|
enableDelete: !!onDeleteSelected,
|
|
4721
4802
|
enableExport,
|
|
4722
|
-
|
|
4803
|
+
showDefaultExport,
|
|
4804
|
+
extraActions: actionBarExtra,
|
|
4805
|
+
actions: actionBarActions
|
|
4723
4806
|
})
|
|
4724
4807
|
]
|
|
4725
4808
|
});
|
|
@@ -5973,6 +6056,12 @@ function resolveActions(actionsOrFn, defaults, rowActionsLocale) {
|
|
|
5973
6056
|
copy: defaults.copyRow,
|
|
5974
6057
|
delete: defaults.openDelete
|
|
5975
6058
|
};
|
|
6059
|
+
const visibleMap = {
|
|
6060
|
+
view: true,
|
|
6061
|
+
edit: !!defaults.openEdit,
|
|
6062
|
+
copy: !!defaults.copyRow,
|
|
6063
|
+
delete: !!defaults.openDelete
|
|
6064
|
+
};
|
|
5976
6065
|
const variantMap = { delete: "destructive" };
|
|
5977
6066
|
return items.flatMap((item) => {
|
|
5978
6067
|
if (item.type === "custom") return [{
|
|
@@ -5981,6 +6070,7 @@ function resolveActions(actionsOrFn, defaults, rowActionsLocale) {
|
|
|
5981
6070
|
separator: item.separator,
|
|
5982
6071
|
variant: item.variant
|
|
5983
6072
|
}];
|
|
6073
|
+
if (!visibleMap[item.type]) return [];
|
|
5984
6074
|
const handler = item.onClick ?? handlerMap[item.type];
|
|
5985
6075
|
if (!handler) return [];
|
|
5986
6076
|
return [{
|
|
@@ -6157,7 +6247,9 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6157
6247
|
onDeleteSelected: can.delete ? resource.handlers.deleteMany : void 0,
|
|
6158
6248
|
onUpdateSelected: can.update ? resource.handlers.updateMany : void 0,
|
|
6159
6249
|
batchUpdateFields: can.update ? batchFields : void 0,
|
|
6160
|
-
|
|
6250
|
+
actionBarActions: tableConfig?.batchActions,
|
|
6251
|
+
enableExport: canExport,
|
|
6252
|
+
showDefaultExport: false,
|
|
6161
6253
|
initialSorting: tableConfig?.defaultSort,
|
|
6162
6254
|
onSelectedCountChange: setSelectedCount,
|
|
6163
6255
|
getSelectedRows: getSelectedRowsRef
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime6 from "react/jsx-runtime";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
4
4
|
import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
|
|
@@ -292,6 +292,38 @@ interface BatchUpdateField {
|
|
|
292
292
|
value: string;
|
|
293
293
|
}>;
|
|
294
294
|
}
|
|
295
|
+
interface BatchActionContext<TData> {
|
|
296
|
+
/** 选中的原始行数据 */
|
|
297
|
+
rows: TData[];
|
|
298
|
+
/** TanStack Table 实例 */
|
|
299
|
+
table: Table<TData>;
|
|
300
|
+
/** 清空当前选择 */
|
|
301
|
+
clearSelection: () => void;
|
|
302
|
+
}
|
|
303
|
+
type BatchBuiltinActionType = 'batchUpdate' | 'export' | 'delete';
|
|
304
|
+
type BatchBuiltinActionItem<TData> = {
|
|
305
|
+
type: BatchBuiltinActionType;
|
|
306
|
+
/** 替代默认行为 */
|
|
307
|
+
onClick?: (rows: TData[], context: BatchActionContext<TData>, event: React$1.MouseEvent<HTMLButtonElement>) => void;
|
|
308
|
+
/** 替代默认标签,仅对 export/delete 生效 */
|
|
309
|
+
label?: string;
|
|
310
|
+
/** 替代整个内置操作的渲染 */
|
|
311
|
+
component?: React$1.ReactNode | ((context: BatchActionContext<TData>) => React$1.ReactNode);
|
|
312
|
+
};
|
|
313
|
+
type BatchCustomActionItem<TData> = {
|
|
314
|
+
type: 'custom';
|
|
315
|
+
/** 操作文本。传 component 时可省略 */
|
|
316
|
+
label?: string;
|
|
317
|
+
/** 自定义点击行为。传 component 时可省略 */
|
|
318
|
+
onClick?: (rows: TData[], context: BatchActionContext<TData>, event: React$1.MouseEvent<HTMLButtonElement>) => void;
|
|
319
|
+
/** 渲染自定义内容 */
|
|
320
|
+
component?: React$1.ReactNode | ((context: BatchActionContext<TData>) => React$1.ReactNode);
|
|
321
|
+
/** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
|
|
322
|
+
position?: 'start' | 'end';
|
|
323
|
+
variant?: 'default' | 'destructive';
|
|
324
|
+
};
|
|
325
|
+
type BatchActionItem<TData> = BatchBuiltinActionItem<TData> | BatchCustomActionItem<TData>;
|
|
326
|
+
type BatchActionConfig<TData> = BatchActionItem<TData>[] | ((defaults: BatchBuiltinActionItem<TData>[]) => BatchActionItem<TData>[]);
|
|
295
327
|
interface AutoTableActionBarProps<TData> {
|
|
296
328
|
table: Table<TData>;
|
|
297
329
|
onDeleteSelected?: (rows: TData[]) => void;
|
|
@@ -301,10 +333,14 @@ interface AutoTableActionBarProps<TData> {
|
|
|
301
333
|
batchUpdateFields?: BatchUpdateField[];
|
|
302
334
|
/** 是否启用导出功能 */
|
|
303
335
|
enableExport?: boolean;
|
|
336
|
+
/** 未配置 actions / 只配置 custom actions 时,是否展示默认导出按钮 */
|
|
337
|
+
showDefaultExport?: boolean;
|
|
304
338
|
/** 是否启用删除功能 */
|
|
305
339
|
enableDelete?: boolean;
|
|
306
340
|
/** 额外的操作按钮 */
|
|
307
341
|
extraActions?: React$1.ReactNode;
|
|
342
|
+
/** 批量操作配置,支持和行操作/顶部工具栏一致的顺序接管语义 */
|
|
343
|
+
actions?: BatchActionConfig<TData>;
|
|
308
344
|
}
|
|
309
345
|
declare function AutoTableActionBar<TData>({
|
|
310
346
|
table,
|
|
@@ -312,9 +348,11 @@ declare function AutoTableActionBar<TData>({
|
|
|
312
348
|
onUpdateSelected,
|
|
313
349
|
batchUpdateFields,
|
|
314
350
|
enableExport,
|
|
351
|
+
showDefaultExport,
|
|
315
352
|
enableDelete,
|
|
316
|
-
extraActions
|
|
317
|
-
|
|
353
|
+
extraActions,
|
|
354
|
+
actions
|
|
355
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime6.JSX.Element;
|
|
318
356
|
//#endregion
|
|
319
357
|
//#region src/lib/schema-bridge/types.d.ts
|
|
320
358
|
/**
|
|
@@ -414,7 +452,7 @@ declare function createActionsColumn<T>(items: ActionsColumnConfig<T>): ColumnDe
|
|
|
414
452
|
//#endregion
|
|
415
453
|
//#region src/components/auto-crud/auto-table.d.ts
|
|
416
454
|
/** 过滤模式类型 */
|
|
417
|
-
type FilterMode =
|
|
455
|
+
type FilterMode = 'simple' | 'advanced' | 'command';
|
|
418
456
|
interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
419
457
|
schema: T;
|
|
420
458
|
data: z.infer<T>[];
|
|
@@ -443,10 +481,14 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
|
443
481
|
batchUpdateFields?: BatchUpdateField[];
|
|
444
482
|
/** 批量操作栏额外按钮 */
|
|
445
483
|
actionBarExtra?: React.ReactNode;
|
|
484
|
+
/** 批量悬浮操作配置 */
|
|
485
|
+
actionBarActions?: BatchActionConfig<z.infer<T>>;
|
|
446
486
|
/** 初始排序 */
|
|
447
487
|
initialSorting?: any[];
|
|
448
488
|
/** 是否启用导出功能 (默认 true) */
|
|
449
489
|
enableExport?: boolean;
|
|
490
|
+
/** 未配置批量 actions / 只配置 custom actions 时,是否展示默认导出按钮 */
|
|
491
|
+
showDefaultExport?: boolean;
|
|
450
492
|
/** 选中行数变化回调(用于外层组件获知选中状态) */
|
|
451
493
|
onSelectedCountChange?: (count: number) => void;
|
|
452
494
|
/** 获取选中行数据的回调(由外层组件调用) */
|
|
@@ -466,11 +508,13 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
466
508
|
onUpdateSelected,
|
|
467
509
|
batchUpdateFields,
|
|
468
510
|
actionBarExtra,
|
|
511
|
+
actionBarActions,
|
|
469
512
|
initialSorting,
|
|
470
513
|
enableExport,
|
|
514
|
+
showDefaultExport,
|
|
471
515
|
onSelectedCountChange,
|
|
472
516
|
getSelectedRows
|
|
473
|
-
}: AutoTableProps<T>):
|
|
517
|
+
}: AutoTableProps<T>): react_jsx_runtime6.JSX.Element;
|
|
474
518
|
//#endregion
|
|
475
519
|
//#region src/i18n/locale.d.ts
|
|
476
520
|
/**
|
|
@@ -571,7 +615,7 @@ interface FilterConfig {
|
|
|
571
615
|
/** 是否启用筛选(默认跟随 table.meta.variant 推断) */
|
|
572
616
|
enabled?: boolean;
|
|
573
617
|
/** 筛选器类型 */
|
|
574
|
-
variant?:
|
|
618
|
+
variant?: 'text' | 'number' | 'range' | 'date' | 'dateRange' | 'boolean' | 'select' | 'multiSelect';
|
|
575
619
|
/** select/multiSelect 的选项列表 */
|
|
576
620
|
options?: Array<{
|
|
577
621
|
label: string;
|
|
@@ -588,7 +632,7 @@ interface FilterConfig {
|
|
|
588
632
|
/** 是否在筛选栏中隐藏(隐藏筛选但不影响表格列显示) */
|
|
589
633
|
hidden?: boolean;
|
|
590
634
|
/** 控制在哪些筛选模式下显示(未设置则在所有模式显示) */
|
|
591
|
-
modes?: Array<
|
|
635
|
+
modes?: Array<'simple' | 'advanced' | 'command'>;
|
|
592
636
|
}
|
|
593
637
|
/**
|
|
594
638
|
* 统一字段配置
|
|
@@ -626,17 +670,17 @@ interface Field {
|
|
|
626
670
|
*/
|
|
627
671
|
form?: {
|
|
628
672
|
/** 是否在表单中隐藏 */
|
|
629
|
-
|
|
673
|
+
'x-hidden'?: boolean;
|
|
630
674
|
/** 组件类型 */
|
|
631
|
-
|
|
675
|
+
'x-component'?: string;
|
|
632
676
|
/** 组件属性 */
|
|
633
|
-
|
|
677
|
+
'x-component-props'?: Record<string, unknown>;
|
|
634
678
|
/** 其他表单配置 */
|
|
635
679
|
[key: string]: unknown;
|
|
636
680
|
} | false;
|
|
637
681
|
}
|
|
638
682
|
type Fields = Record<string, Field>;
|
|
639
|
-
type BuiltinType =
|
|
683
|
+
type BuiltinType = 'view' | 'edit' | 'copy' | 'delete';
|
|
640
684
|
/** 内置操作项(覆盖默认行为或调整位置) */
|
|
641
685
|
type BuiltinActionItem<T> = {
|
|
642
686
|
type: BuiltinType;
|
|
@@ -646,13 +690,13 @@ type BuiltinActionItem<T> = {
|
|
|
646
690
|
};
|
|
647
691
|
/** 自定义操作项 */
|
|
648
692
|
type CustomActionItem<T> = {
|
|
649
|
-
type:
|
|
693
|
+
type: 'custom';
|
|
650
694
|
label: string;
|
|
651
695
|
onClick: (row: T) => void;
|
|
652
696
|
/** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
|
|
653
|
-
position?:
|
|
697
|
+
position?: 'start' | 'end';
|
|
654
698
|
separator?: boolean;
|
|
655
|
-
variant?:
|
|
699
|
+
variant?: 'default' | 'destructive';
|
|
656
700
|
};
|
|
657
701
|
/**
|
|
658
702
|
* 行操作项
|
|
@@ -666,7 +710,7 @@ type ActionConfig<T> = ActionItem<T>[] | ((defaults: BuiltinActionItem<T>[]) =>
|
|
|
666
710
|
* 顶部工具栏内置操作项
|
|
667
711
|
*/
|
|
668
712
|
type ToolbarBuiltinActionItem = {
|
|
669
|
-
type:
|
|
713
|
+
type: 'create' | 'import' | 'export';
|
|
670
714
|
/** 替代默认的行为 */
|
|
671
715
|
onClick?: () => void;
|
|
672
716
|
/** 替代默认的标签文本 */
|
|
@@ -678,11 +722,11 @@ type ToolbarBuiltinActionItem = {
|
|
|
678
722
|
* 顶部工具栏自定义操作项
|
|
679
723
|
*/
|
|
680
724
|
type ToolbarCustomActionItem = {
|
|
681
|
-
type:
|
|
725
|
+
type: 'custom';
|
|
682
726
|
/** 渲染自定义内容 */
|
|
683
727
|
component: React$1.ReactNode;
|
|
684
728
|
/** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
|
|
685
|
-
position?:
|
|
729
|
+
position?: 'start' | 'end';
|
|
686
730
|
};
|
|
687
731
|
type ToolbarActionItem = ToolbarBuiltinActionItem | ToolbarCustomActionItem;
|
|
688
732
|
type ToolbarActionConfig = ToolbarActionItem[] | ((defaults: ToolbarBuiltinActionItem[]) => ToolbarActionItem[]);
|
|
@@ -721,6 +765,12 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
721
765
|
* - 也可以传完整配置覆盖 label 或 options
|
|
722
766
|
*/
|
|
723
767
|
batchFields?: (string | BatchUpdateField)[];
|
|
768
|
+
/**
|
|
769
|
+
* 多选后悬浮批量操作栏配置
|
|
770
|
+
* 用法类同 `actions` 行操作和 `toolbarActions` 顶部工具栏。
|
|
771
|
+
* 只传 custom 时保留默认批量操作;包含任意内置 type 时完全接管顺序。
|
|
772
|
+
*/
|
|
773
|
+
batchActions?: BatchActionConfig<z.output<TSchema>>;
|
|
724
774
|
/** 默认排序 */
|
|
725
775
|
defaultSort?: any[];
|
|
726
776
|
};
|
|
@@ -797,7 +847,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
797
847
|
toolbarActions,
|
|
798
848
|
locale: localeProp,
|
|
799
849
|
onCreate
|
|
800
|
-
}: AutoCrudTableProps<TSchema>):
|
|
850
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime6.JSX.Element;
|
|
801
851
|
//#endregion
|
|
802
852
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
803
853
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -829,7 +879,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
829
879
|
labelAlign,
|
|
830
880
|
labelWidth,
|
|
831
881
|
showSubmitButton
|
|
832
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
882
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime6.JSX.Element;
|
|
833
883
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
834
884
|
ref?: React.Ref<AutoFormRef>;
|
|
835
885
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -1043,12 +1093,12 @@ declare const filterItemSchema: z.ZodObject<{
|
|
|
1043
1093
|
variant: z.ZodEnum<{
|
|
1044
1094
|
number: "number";
|
|
1045
1095
|
boolean: "boolean";
|
|
1046
|
-
text: "text";
|
|
1047
|
-
range: "range";
|
|
1048
1096
|
date: "date";
|
|
1049
|
-
|
|
1097
|
+
text: "text";
|
|
1050
1098
|
select: "select";
|
|
1051
1099
|
multiSelect: "multiSelect";
|
|
1100
|
+
dateRange: "dateRange";
|
|
1101
|
+
range: "range";
|
|
1052
1102
|
}>;
|
|
1053
1103
|
operator: z.ZodEnum<{
|
|
1054
1104
|
iLike: "iLike";
|
|
@@ -1127,7 +1177,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
1127
1177
|
shallow,
|
|
1128
1178
|
filters: externalFilters,
|
|
1129
1179
|
onFiltersChange
|
|
1130
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
1180
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime6.JSX.Element | null;
|
|
1131
1181
|
//#endregion
|
|
1132
1182
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
1133
1183
|
type ModalVariant = "dialog" | "sheet";
|
|
@@ -1169,7 +1219,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1169
1219
|
labelAlign,
|
|
1170
1220
|
labelWidth,
|
|
1171
1221
|
className
|
|
1172
|
-
}: CrudFormModalProps<T>):
|
|
1222
|
+
}: CrudFormModalProps<T>): react_jsx_runtime6.JSX.Element;
|
|
1173
1223
|
//#endregion
|
|
1174
1224
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
1175
1225
|
interface ImportDialogProps {
|
|
@@ -1191,7 +1241,7 @@ declare function ImportDialog({
|
|
|
1191
1241
|
columns,
|
|
1192
1242
|
title,
|
|
1193
1243
|
locale
|
|
1194
|
-
}: ImportDialogProps):
|
|
1244
|
+
}: ImportDialogProps): react_jsx_runtime6.JSX.Element;
|
|
1195
1245
|
//#endregion
|
|
1196
1246
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
1197
1247
|
type ExportMode = "selected" | "filtered";
|
|
@@ -1211,7 +1261,7 @@ declare function ExportDialog({
|
|
|
1211
1261
|
selectedCount,
|
|
1212
1262
|
onExport,
|
|
1213
1263
|
canExportFiltered
|
|
1214
|
-
}: ExportDialogProps):
|
|
1264
|
+
}: ExportDialogProps): react_jsx_runtime6.JSX.Element;
|
|
1215
1265
|
//#endregion
|
|
1216
1266
|
//#region src/components/data-table/data-table.d.ts
|
|
1217
1267
|
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1224,7 +1274,7 @@ declare function DataTable<TData>({
|
|
|
1224
1274
|
children,
|
|
1225
1275
|
className,
|
|
1226
1276
|
...props
|
|
1227
|
-
}: DataTableProps<TData>):
|
|
1277
|
+
}: DataTableProps<TData>): react_jsx_runtime6.JSX.Element;
|
|
1228
1278
|
//#endregion
|
|
1229
1279
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
1230
1280
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1235,7 +1285,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
1235
1285
|
children,
|
|
1236
1286
|
className,
|
|
1237
1287
|
...props
|
|
1238
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
1288
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime6.JSX.Element;
|
|
1239
1289
|
//#endregion
|
|
1240
1290
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
1241
1291
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -1247,7 +1297,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
1247
1297
|
label,
|
|
1248
1298
|
className,
|
|
1249
1299
|
...props
|
|
1250
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
1300
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime6.JSX.Element;
|
|
1251
1301
|
//#endregion
|
|
1252
1302
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
1253
1303
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -1261,7 +1311,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
1261
1311
|
title,
|
|
1262
1312
|
options,
|
|
1263
1313
|
multiple
|
|
1264
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
1314
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime6.JSX.Element;
|
|
1265
1315
|
//#endregion
|
|
1266
1316
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
1267
1317
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
@@ -1273,7 +1323,7 @@ declare function DataTablePagination<TData>({
|
|
|
1273
1323
|
pageSizeOptions,
|
|
1274
1324
|
className,
|
|
1275
1325
|
...props
|
|
1276
|
-
}: DataTablePaginationProps<TData>):
|
|
1326
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime6.JSX.Element;
|
|
1277
1327
|
//#endregion
|
|
1278
1328
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
1279
1329
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1284,7 +1334,7 @@ declare function DataTableToolbar<TData>({
|
|
|
1284
1334
|
children,
|
|
1285
1335
|
className,
|
|
1286
1336
|
...props
|
|
1287
|
-
}: DataTableToolbarProps<TData>):
|
|
1337
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime6.JSX.Element;
|
|
1288
1338
|
//#endregion
|
|
1289
1339
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
1290
1340
|
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
@@ -1295,7 +1345,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
1295
1345
|
table,
|
|
1296
1346
|
disabled,
|
|
1297
1347
|
...props
|
|
1298
|
-
}: DataTableViewOptionsProps<TData>):
|
|
1348
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime6.JSX.Element;
|
|
1299
1349
|
//#endregion
|
|
1300
1350
|
//#region src/hooks/use-data-table.d.ts
|
|
1301
1351
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
|
@@ -1630,4 +1680,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
|
|
|
1630
1680
|
*/
|
|
1631
1681
|
declare function downloadCSVTemplate(headers: string[], filename?: string): void;
|
|
1632
1682
|
//#endregion
|
|
1633
|
-
export { type ActionItem, type ActionsColumnConfig, type AutoCrudLocale, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, 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 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, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
|
1683
|
+
export { type ActionItem, type ActionsColumnConfig, type AutoCrudLocale, AutoCrudTable, type AutoCrudTableProps, 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 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, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, resolveLocale, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|