@wordrhyme/auto-crud 1.0.6 → 1.0.8

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 CHANGED
@@ -265,10 +265,12 @@ interface AutoCrudTableProps<TSchema> {
265
265
  overrides?: Record<string, any>; // 表单覆盖配置
266
266
  columns?: number; // 表单列数
267
267
  };
268
- slots?: {
269
- toolbarStart?: React.ReactNode; // 工具栏左侧插槽
270
- toolbarEnd?: React.ReactNode; // 工具栏右侧插槽
271
- };
268
+ /**
269
+ * 工具栏右侧操作配置
270
+ * - 只传 custom 项:内置保持默认,custom 追加到首/尾
271
+ * - 包含任意内置 type:数组完全接管,未列出的内置项自动隐藏
272
+ */
273
+ toolbarActions?: ToolbarActionItem[];
272
274
  /**
273
275
  * 行操作配置
274
276
  * - 只传 custom 项:内置保持默认,custom 追加到首/尾
@@ -518,6 +520,156 @@ table={{
518
520
 
519
521
  ---
520
522
 
523
+ ## 🔧 工具栏操作配置
524
+
525
+ `toolbarActions` 数组控制页面顶部右侧工具栏的按钮,设计思路完全对齐行操作 `actions`。
526
+
527
+ 内置操作类型:`create`(新建)、`import`(导入)、`export`(导出)。
528
+
529
+ ### 只添加自定义按钮(内置保持默认)
530
+
531
+ 只传 `type: "custom"` 项时,所有内置按钮(导入、导出、新建)保持原样,custom 项按 `position` 插入首部或尾部。
532
+
533
+ ```tsx
534
+ <AutoCrudTable
535
+ toolbarActions={[
536
+ { type: "custom", component: <Button variant="outline">分类管理</Button>, position: "start" },
537
+ { type: "custom", component: <Button variant="outline">批量标签</Button> }, // 默认 position: "end"
538
+ ]}
539
+ />
540
+ // 渲染顺序: 分类管理 · [导入] · [导出] · [新建] · 批量标签
541
+ ```
542
+
543
+ ### 调整内置按钮顺序
544
+
545
+ 数组中只要包含任意内置 `type`,就会**完全接管工具栏** —— 未列出的内置按钮**直接隐藏**,渲染顺序**严格按数组**。
546
+
547
+ ```tsx
548
+ <AutoCrudTable
549
+ toolbarActions={[
550
+ { type: "create" }, // 新建移到最前
551
+ { type: "export", label: "导出 CSV" }, // 覆盖文案
552
+ // import 未列出 → 隐藏
553
+ ]}
554
+ />
555
+ // 渲染顺序: 新建 · 导出 CSV(导入按钮消失)
556
+ ```
557
+
558
+ ### 覆盖内置按钮行为
559
+
560
+ ```tsx
561
+ <AutoCrudTable
562
+ toolbarActions={[
563
+ { type: "import" },
564
+ { type: "export" },
565
+ {
566
+ type: "create",
567
+ label: "发布商品",
568
+ onClick: () => router.push('/products/new'), // 跳转详情页而非弹窗
569
+ },
570
+ ]}
571
+ />
572
+ ```
573
+
574
+ ### 完全替换内置按钮组件
575
+
576
+ ```tsx
577
+ <AutoCrudTable
578
+ toolbarActions={[
579
+ { type: "export" },
580
+ {
581
+ type: "create",
582
+ component: ( // 整个按钮替换
583
+ <DropdownMenu>
584
+ <DropdownMenuTrigger asChild>
585
+ <Button><Plus className="mr-2 h-4 w-4" />新建</Button>
586
+ </DropdownMenuTrigger>
587
+ <DropdownMenuContent>
588
+ <DropdownMenuItem onClick={() => create('simple')}>简易商品</DropdownMenuItem>
589
+ <DropdownMenuItem onClick={() => create('sku')}>多规格商品</DropdownMenuItem>
590
+ </DropdownMenuContent>
591
+ </DropdownMenu>
592
+ ),
593
+ },
594
+ ]}
595
+ />
596
+ ```
597
+
598
+ ### 混合 custom 和内置
599
+
600
+ ```tsx
601
+ <AutoCrudTable
602
+ toolbarActions={[
603
+ { type: "custom", component: <CategoryFilter onChange={setCategory} /> },
604
+ { type: "export" },
605
+ { type: "create", label: "发布", onClick: () => router.push('/products/new') },
606
+ ]}
607
+ />
608
+ // 渲染顺序: 分类筛选 · 导出 · 发布(导入隐藏)
609
+ ```
610
+
611
+ ### 与 `permissions` 的交互
612
+
613
+ `toolbarActions` 与 `permissions` 的交互规则如下:
614
+
615
+ - `permissions.can.create = false` → 即使配置了 `{ type: "create" }`,新建按钮仍不渲染
616
+ - `permissions.can.export = false` → 即使配置了 `{ type: "export" }`,导出按钮仍不渲染
617
+ - 内置项即使使用 `component` 完全替换渲染,也仍然受对应权限控制
618
+ - `type: "custom"` 不受 permissions 影响,由业务方自行控制
619
+
620
+ ```tsx
621
+ <AutoCrudTable
622
+ permissions={{
623
+ can: { create: isAdmin, export: true, delete: isAdmin },
624
+ }}
625
+ toolbarActions={[
626
+ { type: "export" }, // ✅ 始终渲染
627
+ { type: "create", label: "发布商品" }, // 🔒 仅 isAdmin 时渲染
628
+ {
629
+ type: "custom", // ✅ 不受 permissions 影响
630
+ component: isEditor ? <Button>审核</Button> : null, // 业务方自行守卫
631
+ },
632
+ ]}
633
+ />
634
+ ```
635
+
636
+ ### `toolbarActions` 传参高级语法(函数式)
637
+
638
+ 如果你的目标是拦截并修改基于原顺序的所有内容,你还可以传递一个函数:
639
+
640
+ ```tsx
641
+ <AutoCrudTable
642
+ // defaults 即内置三个按钮的信息,在此数组里你可以随意 map、过滤或插值
643
+ toolbarActions={(defaults) => defaults.map(btn =>
644
+ btn.type === 'create'
645
+ ? { ...btn, label: '发布商品', onClick: () => router.push('/products/new') }
646
+ : btn
647
+ )}
648
+ />
649
+ // 非常适合“只盖头不换面”的场景,不会导致内置按钮丢失或顺序打乱
650
+ ```
651
+
652
+ ### `ToolbarActionItem` 类型
653
+
654
+ ```typescript
655
+ type ToolbarActionItem = ToolbarBuiltinActionItem | ToolbarCustomActionItem;
656
+
657
+ type ToolbarBuiltinActionItem = {
658
+ type: "create" | "import" | "export";
659
+ onClick?: () => void; // 覆盖默认行为
660
+ label?: string; // 覆盖默认文案
661
+ component?: React.ReactNode; // 完全替换按钮渲染
662
+ };
663
+
664
+ type ToolbarCustomActionItem = {
665
+ type: "custom";
666
+ component: React.ReactNode; // 自定义渲染内容
667
+ position?: "start" | "end"; // 仅在无内置项时生效,默认 "end"
668
+ };
669
+ ```
670
+
671
+ ---
672
+
521
673
  ## 🎬 行操作配置
522
674
 
523
675
  `actions` 数组控制每行下拉菜单的操作项,支持覆盖内置操作、添加自定义操作、完全自定义顺序。
@@ -562,6 +714,20 @@ table={{
562
714
  />
563
715
  ```
564
716
 
717
+ ### 支持函数配置模式
718
+
719
+ 如果只需要在原来的基础上做细微拦截处理,传入一个函数更省事:
720
+
721
+ ```tsx
722
+ <AutoCrudTable
723
+ actions={(defaults) => defaults.map(action =>
724
+ action.type === 'delete'
725
+ ? { ...action, label: "下架", variant: "default" }
726
+ : action
727
+ )}
728
+ />
729
+ ```
730
+
565
731
  ### `ActionItem` 类型
566
732
 
567
733
  ```typescript
package/dist/index.cjs CHANGED
@@ -5910,7 +5910,16 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
5910
5910
  })
5911
5911
  });
5912
5912
  }
5913
- function resolveActions(items, defaults, rowActionsLocale) {
5913
+ /**
5914
+ * 解析列表行操作
5915
+ */
5916
+ function resolveActions(actionsOrFn, defaults, rowActionsLocale) {
5917
+ const items = typeof actionsOrFn === "function" ? actionsOrFn([
5918
+ { type: "view" },
5919
+ { type: "edit" },
5920
+ { type: "copy" },
5921
+ { type: "delete" }
5922
+ ]) : actionsOrFn;
5914
5923
  const defaultItems = [
5915
5924
  {
5916
5925
  label: rowActionsLocale.view,
@@ -5980,7 +5989,7 @@ function resolveActions(items, defaults, rowActionsLocale) {
5980
5989
  *
5981
5990
  * 高级 CRUD 表格组件,封装了完整的增删改查流程
5982
5991
  */
5983
- function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, slots, permissions, actions: actionItems, locale: localeProp, onCreate }) {
5992
+ function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, permissions, actions: actionItems, toolbarActions, locale: localeProp, onCreate }) {
5984
5993
  const locale = resolveLocale(localeProp);
5985
5994
  const can = {
5986
5995
  create: permissions?.can?.create ?? true,
@@ -6061,34 +6070,69 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
6061
6070
  children: description
6062
6071
  })]
6063
6072
  }),
6064
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6065
- className: "flex items-center justify-between gap-4",
6066
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6067
- className: "flex items-center gap-2",
6068
- children: slots?.toolbarStart
6069
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6070
- className: "flex items-center gap-2",
6071
- children: [
6072
- slots?.toolbarEnd,
6073
- canImport && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
6073
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6074
+ className: "flex items-center justify-end gap-4",
6075
+ children: (() => {
6076
+ const renderBuiltinButton = (type, overrides) => {
6077
+ if (type === "import" && canImport) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
6074
6078
  variant: "outline",
6075
6079
  size: "sm",
6076
- onClick: () => setImportOpen(true),
6077
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Download, { className: "mr-2 h-4 w-4" }), locale.toolbar.import]
6078
- }),
6079
- canExport && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
6080
+ onClick: overrides?.onClick ?? (() => setImportOpen(true)),
6081
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Download, { className: "mr-2 h-4 w-4" }), overrides?.label ?? locale.toolbar.import]
6082
+ }, "import");
6083
+ if (type === "export" && canExport) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__pixpilot_shadcn.Button, {
6080
6084
  variant: "outline",
6081
6085
  size: "sm",
6082
- onClick: handleExportClick,
6086
+ onClick: overrides?.onClick ?? handleExportClick,
6083
6087
  disabled: exporting || selectedCount === 0 && !resource.handlers.export,
6084
- children: [exporting ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Upload, { className: "mr-2 h-4 w-4" }), selectedCount > 0 ? locale.toolbar.exportSelected(selectedCount) : locale.toolbar.export]
6085
- }),
6086
- can.create && (slots?.createButton ? slots.createButton : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.Button, {
6087
- onClick: onCreate ?? resource.handlers.openCreate,
6088
- children: locale.toolbar.create
6089
- }))
6090
- ]
6091
- })]
6088
+ children: [exporting ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Upload, { className: "mr-2 h-4 w-4" }), overrides?.label ?? (selectedCount > 0 ? locale.toolbar.exportSelected(selectedCount) : locale.toolbar.export)]
6089
+ }, "export");
6090
+ if (type === "create" && can.create) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.Button, {
6091
+ onClick: overrides?.onClick ?? onCreate ?? resource.handlers.openCreate,
6092
+ children: overrides?.label ?? locale.toolbar.create
6093
+ }, "create");
6094
+ return null;
6095
+ };
6096
+ const resolvedToolbarActions = typeof toolbarActions === "function" ? toolbarActions([
6097
+ { type: "import" },
6098
+ { type: "export" },
6099
+ { type: "create" }
6100
+ ]) : toolbarActions;
6101
+ if (!resolvedToolbarActions || resolvedToolbarActions.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6102
+ className: "flex items-center gap-2",
6103
+ children: [
6104
+ renderBuiltinButton("import"),
6105
+ renderBuiltinButton("export"),
6106
+ renderBuiltinButton("create")
6107
+ ]
6108
+ });
6109
+ if (!resolvedToolbarActions.some((i) => i.type !== "custom")) {
6110
+ const startNodes = resolvedToolbarActions.filter((i) => i.type === "custom" && i.position === "start").map((a, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: a.component }, `start-${i}`));
6111
+ const endNodes = resolvedToolbarActions.filter((i) => i.type === "custom" && i.position !== "start").map((a, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: a.component }, `end-${i}`));
6112
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6113
+ className: "flex items-center gap-2",
6114
+ children: [
6115
+ startNodes,
6116
+ renderBuiltinButton("import"),
6117
+ renderBuiltinButton("export"),
6118
+ renderBuiltinButton("create"),
6119
+ endNodes
6120
+ ]
6121
+ });
6122
+ }
6123
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6124
+ className: "flex items-center gap-2",
6125
+ children: resolvedToolbarActions.map((action, index) => {
6126
+ if (action.type === "custom") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: action.component }, `custom-${index}`);
6127
+ if (!(action.type === "import" ? canImport : action.type === "export" ? canExport : can.create)) return null;
6128
+ if (action.component) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: action.component }, action.type);
6129
+ return renderBuiltinButton(action.type, {
6130
+ onClick: action.onClick,
6131
+ label: action.label
6132
+ });
6133
+ })
6134
+ });
6135
+ })()
6092
6136
  }),
6093
6137
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoTable, {
6094
6138
  data: resource.tableData.data,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime3 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime2 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";
@@ -314,7 +314,7 @@ declare function AutoTableActionBar<TData>({
314
314
  enableExport,
315
315
  enableDelete,
316
316
  extraActions
317
- }: AutoTableActionBarProps<TData>): react_jsx_runtime3.JSX.Element;
317
+ }: AutoTableActionBarProps<TData>): react_jsx_runtime2.JSX.Element;
318
318
  //#endregion
319
319
  //#region src/lib/schema-bridge/types.d.ts
320
320
  /**
@@ -470,7 +470,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
470
470
  enableExport,
471
471
  onSelectedCountChange,
472
472
  getSelectedRows
473
- }: AutoTableProps<T>): react_jsx_runtime3.JSX.Element;
473
+ }: AutoTableProps<T>): react_jsx_runtime2.JSX.Element;
474
474
  //#endregion
475
475
  //#region src/i18n/locale.d.ts
476
476
  /**
@@ -661,6 +661,31 @@ type CustomActionItem<T> = {
661
661
  * - **包含任意内置 type**:数组完全接管,未列出的隐藏,顺序即渲染顺序
662
662
  */
663
663
  type ActionItem<T> = BuiltinActionItem<T> | CustomActionItem<T>;
664
+ type ActionConfig<T> = ActionItem<T>[] | ((defaults: BuiltinActionItem<T>[]) => ActionItem<T>[]);
665
+ /**
666
+ * 顶部工具栏内置操作项
667
+ */
668
+ type ToolbarBuiltinActionItem = {
669
+ type: "create" | "import" | "export";
670
+ /** 替代默认的行为 */
671
+ onClick?: () => void;
672
+ /** 替代默认的标签文本 */
673
+ label?: string;
674
+ /** 替代整个按钮的渲染 */
675
+ component?: React$1.ReactNode;
676
+ };
677
+ /**
678
+ * 顶部工具栏自定义操作项
679
+ */
680
+ type ToolbarCustomActionItem = {
681
+ type: "custom";
682
+ /** 渲染自定义内容 */
683
+ component: React$1.ReactNode;
684
+ /** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
685
+ position?: "start" | "end";
686
+ };
687
+ type ToolbarActionItem = ToolbarBuiltinActionItem | ToolbarCustomActionItem;
688
+ type ToolbarActionConfig = ToolbarActionItem[] | ((defaults: ToolbarBuiltinActionItem[]) => ToolbarActionItem[]);
664
689
  /**
665
690
  * AutoCrudTable Props 接口
666
691
  */
@@ -708,17 +733,13 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
708
733
  /** 弹窗自定义容器类名(支持控制大小、最大高度等) */
709
734
  className?: string;
710
735
  };
711
- /** 扩展点 */
712
- slots?: {
713
- /** 工具栏左侧插槽 */
714
- toolbarStart?: React$1.ReactNode;
715
- /** 工具栏右侧插槽 */
716
- toolbarEnd?: React$1.ReactNode;
717
- /** 覆盖内置的新建按钮组件 */
718
- createButton?: React$1.ReactNode;
719
- };
720
736
  /** 行操作配置,见 {@link ActionItem} */
721
- actions?: ActionItem<z.output<TSchema>>[];
737
+ actions?: ActionConfig<z.output<TSchema>>;
738
+ /**
739
+ * 顶层工具栏操作配置
740
+ * 用法类同 `actions` 行操作。一旦配置了包含内置 `type` 的数组,它将完全接管右侧工具栏!
741
+ */
742
+ toolbarActions?: ToolbarActionConfig;
722
743
  /**
723
744
  * 权限配置
724
745
  * 控制按钮显示和字段访问
@@ -771,12 +792,12 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
771
792
  fields,
772
793
  table: tableConfig,
773
794
  form: formConfig,
774
- slots,
775
795
  permissions,
776
796
  actions: actionItems,
797
+ toolbarActions,
777
798
  locale: localeProp,
778
799
  onCreate
779
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime3.JSX.Element;
800
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime2.JSX.Element;
780
801
  //#endregion
781
802
  //#region src/components/auto-crud/auto-form.d.ts
782
803
  interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
@@ -808,7 +829,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
808
829
  labelAlign,
809
830
  labelWidth,
810
831
  showSubmitButton
811
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime3.JSX.Element;
832
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime2.JSX.Element;
812
833
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
813
834
  ref?: React.Ref<AutoFormRef>;
814
835
  }) => ReturnType<typeof AutoFormInner>;
@@ -1106,7 +1127,7 @@ declare function AutoTableSimpleFilters<TData>({
1106
1127
  shallow,
1107
1128
  filters: externalFilters,
1108
1129
  onFiltersChange
1109
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime3.JSX.Element | null;
1130
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime2.JSX.Element | null;
1110
1131
  //#endregion
1111
1132
  //#region src/components/auto-crud/form-modal.d.ts
1112
1133
  type ModalVariant = "dialog" | "sheet";
@@ -1148,7 +1169,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
1148
1169
  labelAlign,
1149
1170
  labelWidth,
1150
1171
  className
1151
- }: CrudFormModalProps<T>): react_jsx_runtime3.JSX.Element;
1172
+ }: CrudFormModalProps<T>): react_jsx_runtime2.JSX.Element;
1152
1173
  //#endregion
1153
1174
  //#region src/components/auto-crud/import-dialog.d.ts
1154
1175
  interface ImportDialogProps {
@@ -1170,7 +1191,7 @@ declare function ImportDialog({
1170
1191
  columns,
1171
1192
  title,
1172
1193
  locale
1173
- }: ImportDialogProps): react_jsx_runtime3.JSX.Element;
1194
+ }: ImportDialogProps): react_jsx_runtime2.JSX.Element;
1174
1195
  //#endregion
1175
1196
  //#region src/components/auto-crud/export-dialog.d.ts
1176
1197
  type ExportMode = "selected" | "filtered";
@@ -1190,7 +1211,7 @@ declare function ExportDialog({
1190
1211
  selectedCount,
1191
1212
  onExport,
1192
1213
  canExportFiltered
1193
- }: ExportDialogProps): react_jsx_runtime3.JSX.Element;
1214
+ }: ExportDialogProps): react_jsx_runtime2.JSX.Element;
1194
1215
  //#endregion
1195
1216
  //#region src/components/data-table/data-table.d.ts
1196
1217
  interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1203,7 +1224,7 @@ declare function DataTable<TData>({
1203
1224
  children,
1204
1225
  className,
1205
1226
  ...props
1206
- }: DataTableProps<TData>): react_jsx_runtime3.JSX.Element;
1227
+ }: DataTableProps<TData>): react_jsx_runtime2.JSX.Element;
1207
1228
  //#endregion
1208
1229
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
1209
1230
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1214,7 +1235,7 @@ declare function DataTableAdvancedToolbar<TData>({
1214
1235
  children,
1215
1236
  className,
1216
1237
  ...props
1217
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1238
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
1218
1239
  //#endregion
1219
1240
  //#region src/components/data-table/data-table-column-header.d.ts
1220
1241
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -1226,7 +1247,7 @@ declare function DataTableColumnHeader<TData, TValue>({
1226
1247
  label,
1227
1248
  className,
1228
1249
  ...props
1229
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1250
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
1230
1251
  //#endregion
1231
1252
  //#region src/components/data-table/data-table-faceted-filter.d.ts
1232
1253
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -1240,7 +1261,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
1240
1261
  title,
1241
1262
  options,
1242
1263
  multiple
1243
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1264
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
1244
1265
  //#endregion
1245
1266
  //#region src/components/data-table/data-table-pagination.d.ts
1246
1267
  interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
@@ -1252,7 +1273,7 @@ declare function DataTablePagination<TData>({
1252
1273
  pageSizeOptions,
1253
1274
  className,
1254
1275
  ...props
1255
- }: DataTablePaginationProps<TData>): react_jsx_runtime3.JSX.Element;
1276
+ }: DataTablePaginationProps<TData>): react_jsx_runtime2.JSX.Element;
1256
1277
  //#endregion
1257
1278
  //#region src/components/data-table/data-table-toolbar.d.ts
1258
1279
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1263,7 +1284,7 @@ declare function DataTableToolbar<TData>({
1263
1284
  children,
1264
1285
  className,
1265
1286
  ...props
1266
- }: DataTableToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1287
+ }: DataTableToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
1267
1288
  //#endregion
1268
1289
  //#region src/components/data-table/data-table-view-options.d.ts
1269
1290
  interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
@@ -1274,7 +1295,7 @@ declare function DataTableViewOptions<TData>({
1274
1295
  table,
1275
1296
  disabled,
1276
1297
  ...props
1277
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime3.JSX.Element;
1298
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime2.JSX.Element;
1278
1299
  //#endregion
1279
1300
  //#region src/hooks/use-data-table.d.ts
1280
1301
  interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
@@ -1609,4 +1630,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
1609
1630
  */
1610
1631
  declare function downloadCSVTemplate(headers: string[], filename?: string): void;
1611
1632
  //#endregion
1612
- 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 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 };
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 };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _tanstack_react_table0 from "@tanstack/react-table";
3
3
  import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
4
4
  import { DropdownMenuTrigger, PopoverContent } from "@pixpilot/shadcn";
5
5
  import { ClassValue } from "clsx";
6
- import * as react_jsx_runtime4 from "react/jsx-runtime";
6
+ import * as react_jsx_runtime12 from "react/jsx-runtime";
7
7
  import { z } from "zod";
8
8
  import { ISchema } from "@formily/json-schema";
9
9
 
@@ -314,7 +314,7 @@ declare function AutoTableActionBar<TData>({
314
314
  enableExport,
315
315
  enableDelete,
316
316
  extraActions
317
- }: AutoTableActionBarProps<TData>): react_jsx_runtime4.JSX.Element;
317
+ }: AutoTableActionBarProps<TData>): react_jsx_runtime12.JSX.Element;
318
318
  //#endregion
319
319
  //#region src/lib/schema-bridge/types.d.ts
320
320
  /**
@@ -470,7 +470,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
470
470
  enableExport,
471
471
  onSelectedCountChange,
472
472
  getSelectedRows
473
- }: AutoTableProps<T>): react_jsx_runtime4.JSX.Element;
473
+ }: AutoTableProps<T>): react_jsx_runtime12.JSX.Element;
474
474
  //#endregion
475
475
  //#region src/i18n/locale.d.ts
476
476
  /**
@@ -661,6 +661,31 @@ type CustomActionItem<T> = {
661
661
  * - **包含任意内置 type**:数组完全接管,未列出的隐藏,顺序即渲染顺序
662
662
  */
663
663
  type ActionItem<T> = BuiltinActionItem<T> | CustomActionItem<T>;
664
+ type ActionConfig<T> = ActionItem<T>[] | ((defaults: BuiltinActionItem<T>[]) => ActionItem<T>[]);
665
+ /**
666
+ * 顶部工具栏内置操作项
667
+ */
668
+ type ToolbarBuiltinActionItem = {
669
+ type: "create" | "import" | "export";
670
+ /** 替代默认的行为 */
671
+ onClick?: () => void;
672
+ /** 替代默认的标签文本 */
673
+ label?: string;
674
+ /** 替代整个按钮的渲染 */
675
+ component?: React$1.ReactNode;
676
+ };
677
+ /**
678
+ * 顶部工具栏自定义操作项
679
+ */
680
+ type ToolbarCustomActionItem = {
681
+ type: "custom";
682
+ /** 渲染自定义内容 */
683
+ component: React$1.ReactNode;
684
+ /** 仅在无内置项时生效:插入到首部还是尾部(默认 end) */
685
+ position?: "start" | "end";
686
+ };
687
+ type ToolbarActionItem = ToolbarBuiltinActionItem | ToolbarCustomActionItem;
688
+ type ToolbarActionConfig = ToolbarActionItem[] | ((defaults: ToolbarBuiltinActionItem[]) => ToolbarActionItem[]);
664
689
  /**
665
690
  * AutoCrudTable Props 接口
666
691
  */
@@ -708,17 +733,13 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
708
733
  /** 弹窗自定义容器类名(支持控制大小、最大高度等) */
709
734
  className?: string;
710
735
  };
711
- /** 扩展点 */
712
- slots?: {
713
- /** 工具栏左侧插槽 */
714
- toolbarStart?: React$1.ReactNode;
715
- /** 工具栏右侧插槽 */
716
- toolbarEnd?: React$1.ReactNode;
717
- /** 覆盖内置的新建按钮组件 */
718
- createButton?: React$1.ReactNode;
719
- };
720
736
  /** 行操作配置,见 {@link ActionItem} */
721
- actions?: ActionItem<z.output<TSchema>>[];
737
+ actions?: ActionConfig<z.output<TSchema>>;
738
+ /**
739
+ * 顶层工具栏操作配置
740
+ * 用法类同 `actions` 行操作。一旦配置了包含内置 `type` 的数组,它将完全接管右侧工具栏!
741
+ */
742
+ toolbarActions?: ToolbarActionConfig;
722
743
  /**
723
744
  * 权限配置
724
745
  * 控制按钮显示和字段访问
@@ -771,12 +792,12 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
771
792
  fields,
772
793
  table: tableConfig,
773
794
  form: formConfig,
774
- slots,
775
795
  permissions,
776
796
  actions: actionItems,
797
+ toolbarActions,
777
798
  locale: localeProp,
778
799
  onCreate
779
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime4.JSX.Element;
800
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime12.JSX.Element;
780
801
  //#endregion
781
802
  //#region src/components/auto-crud/auto-form.d.ts
782
803
  interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
@@ -808,7 +829,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
808
829
  labelAlign,
809
830
  labelWidth,
810
831
  showSubmitButton
811
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime4.JSX.Element;
832
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime12.JSX.Element;
812
833
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
813
834
  ref?: React.Ref<AutoFormRef>;
814
835
  }) => ReturnType<typeof AutoFormInner>;
@@ -1106,7 +1127,7 @@ declare function AutoTableSimpleFilters<TData>({
1106
1127
  shallow,
1107
1128
  filters: externalFilters,
1108
1129
  onFiltersChange
1109
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime4.JSX.Element | null;
1130
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime12.JSX.Element | null;
1110
1131
  //#endregion
1111
1132
  //#region src/components/auto-crud/form-modal.d.ts
1112
1133
  type ModalVariant = "dialog" | "sheet";
@@ -1148,7 +1169,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
1148
1169
  labelAlign,
1149
1170
  labelWidth,
1150
1171
  className
1151
- }: CrudFormModalProps<T>): react_jsx_runtime4.JSX.Element;
1172
+ }: CrudFormModalProps<T>): react_jsx_runtime12.JSX.Element;
1152
1173
  //#endregion
1153
1174
  //#region src/components/auto-crud/import-dialog.d.ts
1154
1175
  interface ImportDialogProps {
@@ -1170,7 +1191,7 @@ declare function ImportDialog({
1170
1191
  columns,
1171
1192
  title,
1172
1193
  locale
1173
- }: ImportDialogProps): react_jsx_runtime4.JSX.Element;
1194
+ }: ImportDialogProps): react_jsx_runtime12.JSX.Element;
1174
1195
  //#endregion
1175
1196
  //#region src/components/auto-crud/export-dialog.d.ts
1176
1197
  type ExportMode = "selected" | "filtered";
@@ -1190,7 +1211,7 @@ declare function ExportDialog({
1190
1211
  selectedCount,
1191
1212
  onExport,
1192
1213
  canExportFiltered
1193
- }: ExportDialogProps): react_jsx_runtime4.JSX.Element;
1214
+ }: ExportDialogProps): react_jsx_runtime12.JSX.Element;
1194
1215
  //#endregion
1195
1216
  //#region src/components/data-table/data-table.d.ts
1196
1217
  interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1203,7 +1224,7 @@ declare function DataTable<TData>({
1203
1224
  children,
1204
1225
  className,
1205
1226
  ...props
1206
- }: DataTableProps<TData>): react_jsx_runtime4.JSX.Element;
1227
+ }: DataTableProps<TData>): react_jsx_runtime12.JSX.Element;
1207
1228
  //#endregion
1208
1229
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
1209
1230
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1214,7 +1235,7 @@ declare function DataTableAdvancedToolbar<TData>({
1214
1235
  children,
1215
1236
  className,
1216
1237
  ...props
1217
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime4.JSX.Element;
1238
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime12.JSX.Element;
1218
1239
  //#endregion
1219
1240
  //#region src/components/data-table/data-table-column-header.d.ts
1220
1241
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -1226,7 +1247,7 @@ declare function DataTableColumnHeader<TData, TValue>({
1226
1247
  label,
1227
1248
  className,
1228
1249
  ...props
1229
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime4.JSX.Element;
1250
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime12.JSX.Element;
1230
1251
  //#endregion
1231
1252
  //#region src/components/data-table/data-table-faceted-filter.d.ts
1232
1253
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -1240,7 +1261,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
1240
1261
  title,
1241
1262
  options,
1242
1263
  multiple
1243
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime4.JSX.Element;
1264
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime12.JSX.Element;
1244
1265
  //#endregion
1245
1266
  //#region src/components/data-table/data-table-pagination.d.ts
1246
1267
  interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
@@ -1252,7 +1273,7 @@ declare function DataTablePagination<TData>({
1252
1273
  pageSizeOptions,
1253
1274
  className,
1254
1275
  ...props
1255
- }: DataTablePaginationProps<TData>): react_jsx_runtime4.JSX.Element;
1276
+ }: DataTablePaginationProps<TData>): react_jsx_runtime12.JSX.Element;
1256
1277
  //#endregion
1257
1278
  //#region src/components/data-table/data-table-toolbar.d.ts
1258
1279
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1263,7 +1284,7 @@ declare function DataTableToolbar<TData>({
1263
1284
  children,
1264
1285
  className,
1265
1286
  ...props
1266
- }: DataTableToolbarProps<TData>): react_jsx_runtime4.JSX.Element;
1287
+ }: DataTableToolbarProps<TData>): react_jsx_runtime12.JSX.Element;
1267
1288
  //#endregion
1268
1289
  //#region src/components/data-table/data-table-view-options.d.ts
1269
1290
  interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
@@ -1274,7 +1295,7 @@ declare function DataTableViewOptions<TData>({
1274
1295
  table,
1275
1296
  disabled,
1276
1297
  ...props
1277
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime4.JSX.Element;
1298
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime12.JSX.Element;
1278
1299
  //#endregion
1279
1300
  //#region src/hooks/use-data-table.d.ts
1280
1301
  interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
@@ -1609,4 +1630,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
1609
1630
  */
1610
1631
  declare function downloadCSVTemplate(headers: string[], filename?: string): void;
1611
1632
  //#endregion
1612
- 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 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 };
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 };
package/dist/index.js CHANGED
@@ -5868,7 +5868,16 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
5868
5868
  })
5869
5869
  });
5870
5870
  }
5871
- function resolveActions(items, defaults, rowActionsLocale) {
5871
+ /**
5872
+ * 解析列表行操作
5873
+ */
5874
+ function resolveActions(actionsOrFn, defaults, rowActionsLocale) {
5875
+ const items = typeof actionsOrFn === "function" ? actionsOrFn([
5876
+ { type: "view" },
5877
+ { type: "edit" },
5878
+ { type: "copy" },
5879
+ { type: "delete" }
5880
+ ]) : actionsOrFn;
5872
5881
  const defaultItems = [
5873
5882
  {
5874
5883
  label: rowActionsLocale.view,
@@ -5938,7 +5947,7 @@ function resolveActions(items, defaults, rowActionsLocale) {
5938
5947
  *
5939
5948
  * 高级 CRUD 表格组件,封装了完整的增删改查流程
5940
5949
  */
5941
- function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, slots, permissions, actions: actionItems, locale: localeProp, onCreate }) {
5950
+ function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, permissions, actions: actionItems, toolbarActions, locale: localeProp, onCreate }) {
5942
5951
  const locale = resolveLocale(localeProp);
5943
5952
  const can = {
5944
5953
  create: permissions?.can?.create ?? true,
@@ -6019,34 +6028,69 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
6019
6028
  children: description
6020
6029
  })]
6021
6030
  }),
6022
- /* @__PURE__ */ jsxs("div", {
6023
- className: "flex items-center justify-between gap-4",
6024
- children: [/* @__PURE__ */ jsx("div", {
6025
- className: "flex items-center gap-2",
6026
- children: slots?.toolbarStart
6027
- }), /* @__PURE__ */ jsxs("div", {
6028
- className: "flex items-center gap-2",
6029
- children: [
6030
- slots?.toolbarEnd,
6031
- canImport && /* @__PURE__ */ jsxs(Button, {
6031
+ /* @__PURE__ */ jsx("div", {
6032
+ className: "flex items-center justify-end gap-4",
6033
+ children: (() => {
6034
+ const renderBuiltinButton = (type, overrides) => {
6035
+ if (type === "import" && canImport) return /* @__PURE__ */ jsxs(Button, {
6032
6036
  variant: "outline",
6033
6037
  size: "sm",
6034
- onClick: () => setImportOpen(true),
6035
- children: [/* @__PURE__ */ jsx(Download, { className: "mr-2 h-4 w-4" }), locale.toolbar.import]
6036
- }),
6037
- canExport && /* @__PURE__ */ jsxs(Button, {
6038
+ onClick: overrides?.onClick ?? (() => setImportOpen(true)),
6039
+ children: [/* @__PURE__ */ jsx(Download, { className: "mr-2 h-4 w-4" }), overrides?.label ?? locale.toolbar.import]
6040
+ }, "import");
6041
+ if (type === "export" && canExport) return /* @__PURE__ */ jsxs(Button, {
6038
6042
  variant: "outline",
6039
6043
  size: "sm",
6040
- onClick: handleExportClick,
6044
+ onClick: overrides?.onClick ?? handleExportClick,
6041
6045
  disabled: exporting || selectedCount === 0 && !resource.handlers.export,
6042
- children: [exporting ? /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Upload, { className: "mr-2 h-4 w-4" }), selectedCount > 0 ? locale.toolbar.exportSelected(selectedCount) : locale.toolbar.export]
6043
- }),
6044
- can.create && (slots?.createButton ? slots.createButton : /* @__PURE__ */ jsx(Button, {
6045
- onClick: onCreate ?? resource.handlers.openCreate,
6046
- children: locale.toolbar.create
6047
- }))
6048
- ]
6049
- })]
6046
+ children: [exporting ? /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Upload, { className: "mr-2 h-4 w-4" }), overrides?.label ?? (selectedCount > 0 ? locale.toolbar.exportSelected(selectedCount) : locale.toolbar.export)]
6047
+ }, "export");
6048
+ if (type === "create" && can.create) return /* @__PURE__ */ jsx(Button, {
6049
+ onClick: overrides?.onClick ?? onCreate ?? resource.handlers.openCreate,
6050
+ children: overrides?.label ?? locale.toolbar.create
6051
+ }, "create");
6052
+ return null;
6053
+ };
6054
+ const resolvedToolbarActions = typeof toolbarActions === "function" ? toolbarActions([
6055
+ { type: "import" },
6056
+ { type: "export" },
6057
+ { type: "create" }
6058
+ ]) : toolbarActions;
6059
+ if (!resolvedToolbarActions || resolvedToolbarActions.length === 0) return /* @__PURE__ */ jsxs("div", {
6060
+ className: "flex items-center gap-2",
6061
+ children: [
6062
+ renderBuiltinButton("import"),
6063
+ renderBuiltinButton("export"),
6064
+ renderBuiltinButton("create")
6065
+ ]
6066
+ });
6067
+ if (!resolvedToolbarActions.some((i) => i.type !== "custom")) {
6068
+ const startNodes = resolvedToolbarActions.filter((i) => i.type === "custom" && i.position === "start").map((a, i) => /* @__PURE__ */ jsx(React.Fragment, { children: a.component }, `start-${i}`));
6069
+ const endNodes = resolvedToolbarActions.filter((i) => i.type === "custom" && i.position !== "start").map((a, i) => /* @__PURE__ */ jsx(React.Fragment, { children: a.component }, `end-${i}`));
6070
+ return /* @__PURE__ */ jsxs("div", {
6071
+ className: "flex items-center gap-2",
6072
+ children: [
6073
+ startNodes,
6074
+ renderBuiltinButton("import"),
6075
+ renderBuiltinButton("export"),
6076
+ renderBuiltinButton("create"),
6077
+ endNodes
6078
+ ]
6079
+ });
6080
+ }
6081
+ return /* @__PURE__ */ jsx("div", {
6082
+ className: "flex items-center gap-2",
6083
+ children: resolvedToolbarActions.map((action, index) => {
6084
+ if (action.type === "custom") return /* @__PURE__ */ jsx(React.Fragment, { children: action.component }, `custom-${index}`);
6085
+ if (!(action.type === "import" ? canImport : action.type === "export" ? canExport : can.create)) return null;
6086
+ if (action.component) return /* @__PURE__ */ jsx(React.Fragment, { children: action.component }, action.type);
6087
+ return renderBuiltinButton(action.type, {
6088
+ onClick: action.onClick,
6089
+ label: action.label
6090
+ });
6091
+ })
6092
+ });
6093
+ })()
6050
6094
  }),
6051
6095
  /* @__PURE__ */ jsx(AutoTable, {
6052
6096
  data: resource.tableData.data,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wordrhyme/auto-crud",
3
3
  "type": "module",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "description": "Schema-first CRUD components with auto-generated tables and forms",
6
6
  "author": "wordrhyme",
7
7
  "license": "MIT",
@@ -84,8 +84,8 @@
84
84
  "@internal/eslint-config": "0.3.0",
85
85
  "@internal/prettier-config": "0.0.1",
86
86
  "@internal/tsconfig": "0.1.0",
87
- "@internal/vitest-config": "0.1.0",
88
- "@internal/tsdown-config": "0.1.0"
87
+ "@internal/tsdown-config": "0.1.0",
88
+ "@internal/vitest-config": "0.1.0"
89
89
  },
90
90
  "prettier": "@internal/prettier-config",
91
91
  "scripts": {