@wordrhyme/auto-crud 1.0.1 → 1.0.3

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
@@ -268,8 +268,13 @@ interface AutoCrudTableProps<TSchema> {
268
268
  slots?: {
269
269
  toolbarStart?: React.ReactNode; // 工具栏左侧插槽
270
270
  toolbarEnd?: React.ReactNode; // 工具栏右侧插槽
271
- rowActions?: (row) => Array<{ label: string; onClick: () => void }>;
272
271
  };
272
+ /**
273
+ * 行操作配置
274
+ * - 只传 custom 项:内置保持默认,custom 追加到首/尾
275
+ * - 包含任意内置 type:数组完全接管,未列出的隐藏,顺序即渲染顺序
276
+ */
277
+ actions?: ActionItem<z.output<TSchema>>[];
273
278
  }
274
279
  ```
275
280
 
@@ -513,6 +518,70 @@ table={{
513
518
 
514
519
  ---
515
520
 
521
+ ## 🎬 行操作配置
522
+
523
+ `actions` 数组控制每行下拉菜单的操作项,支持覆盖内置操作、添加自定义操作、完全自定义顺序。
524
+
525
+ ### 只添加自定义项(内置不变)
526
+
527
+ ```tsx
528
+ <AutoCrudTable
529
+ actions={[
530
+ { type: "custom", label: "分配", onClick: (row) => assign(row.id) },
531
+ { type: "custom", label: "预览", onClick: (row) => preview(row), position: "start" },
532
+ ]}
533
+ />
534
+ // 渲染顺序: 预览 · 查看 · 编辑 · 复制 · 删除 · 分配
535
+ ```
536
+
537
+ ### 覆盖内置行为或隐藏某项
538
+
539
+ 数组中只要包含任意内置 `type`,数组就会完全接管 —— 未列出的内置项自动隐藏。
540
+
541
+ ```tsx
542
+ <AutoCrudTable
543
+ actions={[
544
+ { type: "view", onClick: (row) => router.push(`/tasks/${row.id}`) }, // 覆盖跳转
545
+ { type: "custom", label: "分配", onClick: (row) => assign(row.id) },
546
+ { type: "edit" }, // 默认行为
547
+ // copy / delete 未列出 → 隐藏
548
+ ]}
549
+ />
550
+ ```
551
+
552
+ ### 完全自定义顺序
553
+
554
+ ```tsx
555
+ <AutoCrudTable
556
+ actions={[
557
+ { type: "edit" },
558
+ { type: "copy" },
559
+ { type: "custom", label: "归档", onClick: archive, separator: true },
560
+ { type: "delete", separator: true },
561
+ ]}
562
+ />
563
+ ```
564
+
565
+ ### `ActionItem` 类型
566
+
567
+ ```typescript
568
+ type ActionItem<T> =
569
+ | {
570
+ type: "view" | "edit" | "copy" | "delete";
571
+ onClick?: (row: T) => void; // 不传则使用默认行为
572
+ label?: string; // 不传则使用默认文案
573
+ separator?: boolean; // 此项前加分隔线
574
+ }
575
+ | {
576
+ type: "custom";
577
+ label: string;
578
+ onClick: (row: T) => void;
579
+ position?: "start" | "end"; // 仅无内置项时生效,默认 end
580
+ separator?: boolean;
581
+ variant?: "default" | "destructive";
582
+ };
583
+ ```
584
+
516
585
  ## 🔄 批量操作
517
586
 
518
587
  ### 批量更新
@@ -758,12 +827,12 @@ function CustomTable({ data }) {
758
827
  const columns = [
759
828
  createSelectColumn(),
760
829
  ...createTableSchema(taskSchema, { exclude: ["id"] }),
761
- createActionsColumn({
762
- onEdit: (row) => console.log("Edit", row),
763
- onDelete: (row) => console.log("Delete", row),
764
- onView: (row) => console.log("View", row),
765
- onCopy: (row) => console.log("Copy", row),
766
- }),
830
+ createActionsColumn([
831
+ { label: "查看", onClick: (row) => console.log("View", row) },
832
+ { label: "编辑", onClick: (row) => console.log("Edit", row) },
833
+ { label: "复制", onClick: (row) => console.log("Copy", row) },
834
+ { label: "删除", onClick: (row) => console.log("Delete", row), separator: true, variant: "destructive" },
835
+ ]),
767
836
  ];
768
837
 
769
838
  return (