@wordrhyme/auto-crud 1.0.7 → 1.0.9
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 +30 -0
- package/dist/index.cjs +24 -7
- package/dist/index.d.cts +20 -18
- package/dist/index.d.ts +20 -18
- package/dist/index.js +24 -7
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -633,6 +633,22 @@ table={{
|
|
|
633
633
|
/>
|
|
634
634
|
```
|
|
635
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
|
+
|
|
636
652
|
### `ToolbarActionItem` 类型
|
|
637
653
|
|
|
638
654
|
```typescript
|
|
@@ -698,6 +714,20 @@ type ToolbarCustomActionItem = {
|
|
|
698
714
|
/>
|
|
699
715
|
```
|
|
700
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
|
+
|
|
701
731
|
### `ActionItem` 类型
|
|
702
732
|
|
|
703
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
|
-
|
|
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,
|
|
@@ -6084,7 +6093,12 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6084
6093
|
}, "create");
|
|
6085
6094
|
return null;
|
|
6086
6095
|
};
|
|
6087
|
-
|
|
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", {
|
|
6088
6102
|
className: "flex items-center gap-2",
|
|
6089
6103
|
children: [
|
|
6090
6104
|
renderBuiltinButton("import"),
|
|
@@ -6092,9 +6106,9 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6092
6106
|
renderBuiltinButton("create")
|
|
6093
6107
|
]
|
|
6094
6108
|
});
|
|
6095
|
-
if (!
|
|
6096
|
-
const startNodes =
|
|
6097
|
-
const endNodes =
|
|
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}`));
|
|
6098
6112
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
6099
6113
|
className: "flex items-center gap-2",
|
|
6100
6114
|
children: [
|
|
@@ -6108,7 +6122,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6108
6122
|
}
|
|
6109
6123
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6110
6124
|
className: "flex items-center gap-2",
|
|
6111
|
-
children:
|
|
6125
|
+
children: resolvedToolbarActions.map((action, index) => {
|
|
6112
6126
|
if (action.type === "custom") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: action.component }, `custom-${index}`);
|
|
6113
6127
|
if (!(action.type === "import" ? canImport : action.type === "export" ? canExport : can.create)) return null;
|
|
6114
6128
|
if (action.component) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: action.component }, action.type);
|
|
@@ -6963,7 +6977,10 @@ function useAutoCrudResource({ router, schema, query: queryTransform, options =
|
|
|
6963
6977
|
filters,
|
|
6964
6978
|
queryTransform
|
|
6965
6979
|
]);
|
|
6966
|
-
const listQuery = router.list.useQuery(queryInput, {
|
|
6980
|
+
const listQuery = router.list.useQuery(queryInput, {
|
|
6981
|
+
placeholderData: keepPreviousData,
|
|
6982
|
+
staleTime: 0
|
|
6983
|
+
});
|
|
6967
6984
|
const createMutation = router.create.useMutation();
|
|
6968
6985
|
const updateMutation = router.update.useMutation();
|
|
6969
6986
|
const deleteMutation = router.delete.useMutation();
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react_jsx_runtime1 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>):
|
|
317
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime1.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>):
|
|
473
|
+
}: AutoTableProps<T>): react_jsx_runtime1.JSX.Element;
|
|
474
474
|
//#endregion
|
|
475
475
|
//#region src/i18n/locale.d.ts
|
|
476
476
|
/**
|
|
@@ -661,6 +661,7 @@ 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>[]);
|
|
664
665
|
/**
|
|
665
666
|
* 顶部工具栏内置操作项
|
|
666
667
|
*/
|
|
@@ -684,6 +685,7 @@ type ToolbarCustomActionItem = {
|
|
|
684
685
|
position?: "start" | "end";
|
|
685
686
|
};
|
|
686
687
|
type ToolbarActionItem = ToolbarBuiltinActionItem | ToolbarCustomActionItem;
|
|
688
|
+
type ToolbarActionConfig = ToolbarActionItem[] | ((defaults: ToolbarBuiltinActionItem[]) => ToolbarActionItem[]);
|
|
687
689
|
/**
|
|
688
690
|
* AutoCrudTable Props 接口
|
|
689
691
|
*/
|
|
@@ -732,12 +734,12 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
732
734
|
className?: string;
|
|
733
735
|
};
|
|
734
736
|
/** 行操作配置,见 {@link ActionItem} */
|
|
735
|
-
actions?:
|
|
737
|
+
actions?: ActionConfig<z.output<TSchema>>;
|
|
736
738
|
/**
|
|
737
739
|
* 顶层工具栏操作配置
|
|
738
740
|
* 用法类同 `actions` 行操作。一旦配置了包含内置 `type` 的数组,它将完全接管右侧工具栏!
|
|
739
741
|
*/
|
|
740
|
-
toolbarActions?:
|
|
742
|
+
toolbarActions?: ToolbarActionConfig;
|
|
741
743
|
/**
|
|
742
744
|
* 权限配置
|
|
743
745
|
* 控制按钮显示和字段访问
|
|
@@ -795,7 +797,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
795
797
|
toolbarActions,
|
|
796
798
|
locale: localeProp,
|
|
797
799
|
onCreate
|
|
798
|
-
}: AutoCrudTableProps<TSchema>):
|
|
800
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime1.JSX.Element;
|
|
799
801
|
//#endregion
|
|
800
802
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
801
803
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -827,7 +829,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
827
829
|
labelAlign,
|
|
828
830
|
labelWidth,
|
|
829
831
|
showSubmitButton
|
|
830
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
832
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime1.JSX.Element;
|
|
831
833
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
832
834
|
ref?: React.Ref<AutoFormRef>;
|
|
833
835
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -1125,7 +1127,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
1125
1127
|
shallow,
|
|
1126
1128
|
filters: externalFilters,
|
|
1127
1129
|
onFiltersChange
|
|
1128
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
1130
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime1.JSX.Element | null;
|
|
1129
1131
|
//#endregion
|
|
1130
1132
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
1131
1133
|
type ModalVariant = "dialog" | "sheet";
|
|
@@ -1167,7 +1169,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1167
1169
|
labelAlign,
|
|
1168
1170
|
labelWidth,
|
|
1169
1171
|
className
|
|
1170
|
-
}: CrudFormModalProps<T>):
|
|
1172
|
+
}: CrudFormModalProps<T>): react_jsx_runtime1.JSX.Element;
|
|
1171
1173
|
//#endregion
|
|
1172
1174
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
1173
1175
|
interface ImportDialogProps {
|
|
@@ -1189,7 +1191,7 @@ declare function ImportDialog({
|
|
|
1189
1191
|
columns,
|
|
1190
1192
|
title,
|
|
1191
1193
|
locale
|
|
1192
|
-
}: ImportDialogProps):
|
|
1194
|
+
}: ImportDialogProps): react_jsx_runtime1.JSX.Element;
|
|
1193
1195
|
//#endregion
|
|
1194
1196
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
1195
1197
|
type ExportMode = "selected" | "filtered";
|
|
@@ -1209,7 +1211,7 @@ declare function ExportDialog({
|
|
|
1209
1211
|
selectedCount,
|
|
1210
1212
|
onExport,
|
|
1211
1213
|
canExportFiltered
|
|
1212
|
-
}: ExportDialogProps):
|
|
1214
|
+
}: ExportDialogProps): react_jsx_runtime1.JSX.Element;
|
|
1213
1215
|
//#endregion
|
|
1214
1216
|
//#region src/components/data-table/data-table.d.ts
|
|
1215
1217
|
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1222,7 +1224,7 @@ declare function DataTable<TData>({
|
|
|
1222
1224
|
children,
|
|
1223
1225
|
className,
|
|
1224
1226
|
...props
|
|
1225
|
-
}: DataTableProps<TData>):
|
|
1227
|
+
}: DataTableProps<TData>): react_jsx_runtime1.JSX.Element;
|
|
1226
1228
|
//#endregion
|
|
1227
1229
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
1228
1230
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1233,7 +1235,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
1233
1235
|
children,
|
|
1234
1236
|
className,
|
|
1235
1237
|
...props
|
|
1236
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
1238
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime1.JSX.Element;
|
|
1237
1239
|
//#endregion
|
|
1238
1240
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
1239
1241
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -1245,7 +1247,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
1245
1247
|
label,
|
|
1246
1248
|
className,
|
|
1247
1249
|
...props
|
|
1248
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
1250
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime1.JSX.Element;
|
|
1249
1251
|
//#endregion
|
|
1250
1252
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
1251
1253
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -1259,7 +1261,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
1259
1261
|
title,
|
|
1260
1262
|
options,
|
|
1261
1263
|
multiple
|
|
1262
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
1264
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime1.JSX.Element;
|
|
1263
1265
|
//#endregion
|
|
1264
1266
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
1265
1267
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
@@ -1271,7 +1273,7 @@ declare function DataTablePagination<TData>({
|
|
|
1271
1273
|
pageSizeOptions,
|
|
1272
1274
|
className,
|
|
1273
1275
|
...props
|
|
1274
|
-
}: DataTablePaginationProps<TData>):
|
|
1276
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime1.JSX.Element;
|
|
1275
1277
|
//#endregion
|
|
1276
1278
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
1277
1279
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1282,7 +1284,7 @@ declare function DataTableToolbar<TData>({
|
|
|
1282
1284
|
children,
|
|
1283
1285
|
className,
|
|
1284
1286
|
...props
|
|
1285
|
-
}: DataTableToolbarProps<TData>):
|
|
1287
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime1.JSX.Element;
|
|
1286
1288
|
//#endregion
|
|
1287
1289
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
1288
1290
|
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
@@ -1293,7 +1295,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
1293
1295
|
table,
|
|
1294
1296
|
disabled,
|
|
1295
1297
|
...props
|
|
1296
|
-
}: DataTableViewOptionsProps<TData>):
|
|
1298
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime1.JSX.Element;
|
|
1297
1299
|
//#endregion
|
|
1298
1300
|
//#region src/hooks/use-data-table.d.ts
|
|
1299
1301
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
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
|
|
6
|
+
import * as react_jsx_runtime2 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>):
|
|
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>):
|
|
473
|
+
}: AutoTableProps<T>): react_jsx_runtime2.JSX.Element;
|
|
474
474
|
//#endregion
|
|
475
475
|
//#region src/i18n/locale.d.ts
|
|
476
476
|
/**
|
|
@@ -661,6 +661,7 @@ 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>[]);
|
|
664
665
|
/**
|
|
665
666
|
* 顶部工具栏内置操作项
|
|
666
667
|
*/
|
|
@@ -684,6 +685,7 @@ type ToolbarCustomActionItem = {
|
|
|
684
685
|
position?: "start" | "end";
|
|
685
686
|
};
|
|
686
687
|
type ToolbarActionItem = ToolbarBuiltinActionItem | ToolbarCustomActionItem;
|
|
688
|
+
type ToolbarActionConfig = ToolbarActionItem[] | ((defaults: ToolbarBuiltinActionItem[]) => ToolbarActionItem[]);
|
|
687
689
|
/**
|
|
688
690
|
* AutoCrudTable Props 接口
|
|
689
691
|
*/
|
|
@@ -732,12 +734,12 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
732
734
|
className?: string;
|
|
733
735
|
};
|
|
734
736
|
/** 行操作配置,见 {@link ActionItem} */
|
|
735
|
-
actions?:
|
|
737
|
+
actions?: ActionConfig<z.output<TSchema>>;
|
|
736
738
|
/**
|
|
737
739
|
* 顶层工具栏操作配置
|
|
738
740
|
* 用法类同 `actions` 行操作。一旦配置了包含内置 `type` 的数组,它将完全接管右侧工具栏!
|
|
739
741
|
*/
|
|
740
|
-
toolbarActions?:
|
|
742
|
+
toolbarActions?: ToolbarActionConfig;
|
|
741
743
|
/**
|
|
742
744
|
* 权限配置
|
|
743
745
|
* 控制按钮显示和字段访问
|
|
@@ -795,7 +797,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
795
797
|
toolbarActions,
|
|
796
798
|
locale: localeProp,
|
|
797
799
|
onCreate
|
|
798
|
-
}: AutoCrudTableProps<TSchema>):
|
|
800
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime2.JSX.Element;
|
|
799
801
|
//#endregion
|
|
800
802
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
801
803
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -827,7 +829,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
827
829
|
labelAlign,
|
|
828
830
|
labelWidth,
|
|
829
831
|
showSubmitButton
|
|
830
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
832
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime2.JSX.Element;
|
|
831
833
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
832
834
|
ref?: React.Ref<AutoFormRef>;
|
|
833
835
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -1125,7 +1127,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
1125
1127
|
shallow,
|
|
1126
1128
|
filters: externalFilters,
|
|
1127
1129
|
onFiltersChange
|
|
1128
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
1130
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime2.JSX.Element | null;
|
|
1129
1131
|
//#endregion
|
|
1130
1132
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
1131
1133
|
type ModalVariant = "dialog" | "sheet";
|
|
@@ -1167,7 +1169,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1167
1169
|
labelAlign,
|
|
1168
1170
|
labelWidth,
|
|
1169
1171
|
className
|
|
1170
|
-
}: CrudFormModalProps<T>):
|
|
1172
|
+
}: CrudFormModalProps<T>): react_jsx_runtime2.JSX.Element;
|
|
1171
1173
|
//#endregion
|
|
1172
1174
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
1173
1175
|
interface ImportDialogProps {
|
|
@@ -1189,7 +1191,7 @@ declare function ImportDialog({
|
|
|
1189
1191
|
columns,
|
|
1190
1192
|
title,
|
|
1191
1193
|
locale
|
|
1192
|
-
}: ImportDialogProps):
|
|
1194
|
+
}: ImportDialogProps): react_jsx_runtime2.JSX.Element;
|
|
1193
1195
|
//#endregion
|
|
1194
1196
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
1195
1197
|
type ExportMode = "selected" | "filtered";
|
|
@@ -1209,7 +1211,7 @@ declare function ExportDialog({
|
|
|
1209
1211
|
selectedCount,
|
|
1210
1212
|
onExport,
|
|
1211
1213
|
canExportFiltered
|
|
1212
|
-
}: ExportDialogProps):
|
|
1214
|
+
}: ExportDialogProps): react_jsx_runtime2.JSX.Element;
|
|
1213
1215
|
//#endregion
|
|
1214
1216
|
//#region src/components/data-table/data-table.d.ts
|
|
1215
1217
|
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1222,7 +1224,7 @@ declare function DataTable<TData>({
|
|
|
1222
1224
|
children,
|
|
1223
1225
|
className,
|
|
1224
1226
|
...props
|
|
1225
|
-
}: DataTableProps<TData>):
|
|
1227
|
+
}: DataTableProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1226
1228
|
//#endregion
|
|
1227
1229
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
1228
1230
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1233,7 +1235,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
1233
1235
|
children,
|
|
1234
1236
|
className,
|
|
1235
1237
|
...props
|
|
1236
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
1238
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1237
1239
|
//#endregion
|
|
1238
1240
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
1239
1241
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -1245,7 +1247,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
1245
1247
|
label,
|
|
1246
1248
|
className,
|
|
1247
1249
|
...props
|
|
1248
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
1250
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
|
|
1249
1251
|
//#endregion
|
|
1250
1252
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
1251
1253
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -1259,7 +1261,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
1259
1261
|
title,
|
|
1260
1262
|
options,
|
|
1261
1263
|
multiple
|
|
1262
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
1264
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
|
|
1263
1265
|
//#endregion
|
|
1264
1266
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
1265
1267
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
@@ -1271,7 +1273,7 @@ declare function DataTablePagination<TData>({
|
|
|
1271
1273
|
pageSizeOptions,
|
|
1272
1274
|
className,
|
|
1273
1275
|
...props
|
|
1274
|
-
}: DataTablePaginationProps<TData>):
|
|
1276
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1275
1277
|
//#endregion
|
|
1276
1278
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
1277
1279
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -1282,7 +1284,7 @@ declare function DataTableToolbar<TData>({
|
|
|
1282
1284
|
children,
|
|
1283
1285
|
className,
|
|
1284
1286
|
...props
|
|
1285
|
-
}: DataTableToolbarProps<TData>):
|
|
1287
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1286
1288
|
//#endregion
|
|
1287
1289
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
1288
1290
|
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
@@ -1293,7 +1295,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
1293
1295
|
table,
|
|
1294
1296
|
disabled,
|
|
1295
1297
|
...props
|
|
1296
|
-
}: DataTableViewOptionsProps<TData>):
|
|
1298
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime2.JSX.Element;
|
|
1297
1299
|
//#endregion
|
|
1298
1300
|
//#region src/hooks/use-data-table.d.ts
|
|
1299
1301
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
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
|
-
|
|
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,
|
|
@@ -6042,7 +6051,12 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6042
6051
|
}, "create");
|
|
6043
6052
|
return null;
|
|
6044
6053
|
};
|
|
6045
|
-
|
|
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", {
|
|
6046
6060
|
className: "flex items-center gap-2",
|
|
6047
6061
|
children: [
|
|
6048
6062
|
renderBuiltinButton("import"),
|
|
@@ -6050,9 +6064,9 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6050
6064
|
renderBuiltinButton("create")
|
|
6051
6065
|
]
|
|
6052
6066
|
});
|
|
6053
|
-
if (!
|
|
6054
|
-
const startNodes =
|
|
6055
|
-
const endNodes =
|
|
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}`));
|
|
6056
6070
|
return /* @__PURE__ */ jsxs("div", {
|
|
6057
6071
|
className: "flex items-center gap-2",
|
|
6058
6072
|
children: [
|
|
@@ -6066,7 +6080,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
6066
6080
|
}
|
|
6067
6081
|
return /* @__PURE__ */ jsx("div", {
|
|
6068
6082
|
className: "flex items-center gap-2",
|
|
6069
|
-
children:
|
|
6083
|
+
children: resolvedToolbarActions.map((action, index) => {
|
|
6070
6084
|
if (action.type === "custom") return /* @__PURE__ */ jsx(React.Fragment, { children: action.component }, `custom-${index}`);
|
|
6071
6085
|
if (!(action.type === "import" ? canImport : action.type === "export" ? canExport : can.create)) return null;
|
|
6072
6086
|
if (action.component) return /* @__PURE__ */ jsx(React.Fragment, { children: action.component }, action.type);
|
|
@@ -6921,7 +6935,10 @@ function useAutoCrudResource({ router, schema, query: queryTransform, options =
|
|
|
6921
6935
|
filters,
|
|
6922
6936
|
queryTransform
|
|
6923
6937
|
]);
|
|
6924
|
-
const listQuery = router.list.useQuery(queryInput, {
|
|
6938
|
+
const listQuery = router.list.useQuery(queryInput, {
|
|
6939
|
+
placeholderData: keepPreviousData,
|
|
6940
|
+
staleTime: 0
|
|
6941
|
+
});
|
|
6925
6942
|
const createMutation = router.create.useMutation();
|
|
6926
6943
|
const updateMutation = router.update.useMutation();
|
|
6927
6944
|
const deleteMutation = router.delete.useMutation();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.9",
|
|
5
5
|
"description": "Schema-first CRUD components with auto-generated tables and forms",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@tanstack/react-query": "^5.90.15",
|
|
74
|
+
"@testing-library/react": "^16.3.0",
|
|
74
75
|
"@trpc/server": "^11.0.0",
|
|
75
76
|
"@types/node": "^22.19.3",
|
|
76
77
|
"@types/react": "^19.2.7",
|
|
@@ -81,8 +82,8 @@
|
|
|
81
82
|
"react-dom": "19.2.4",
|
|
82
83
|
"tsdown": "^0.15.12",
|
|
83
84
|
"typescript": "^5.9.3",
|
|
84
|
-
"@internal/prettier-config": "0.0.1",
|
|
85
85
|
"@internal/eslint-config": "0.3.0",
|
|
86
|
+
"@internal/prettier-config": "0.0.1",
|
|
86
87
|
"@internal/tsconfig": "0.1.0",
|
|
87
88
|
"@internal/vitest-config": "0.1.0",
|
|
88
89
|
"@internal/tsdown-config": "0.1.0"
|