@wordrhyme/auto-crud 1.23.0 → 1.23.1
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/dist/index.cjs +87 -34
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +20 -19
- package/dist/index.js +87 -34
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -10608,6 +10608,39 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
10608
10608
|
const canImport = can.import && !!resource.handlers.import;
|
|
10609
10609
|
const canExport = can.export;
|
|
10610
10610
|
const [importOpen, setImportOpen] = react.useState(false);
|
|
10611
|
+
const resourceIdKey = resource.idKey ?? "id";
|
|
10612
|
+
const modal = resource.modal;
|
|
10613
|
+
const deleteTarget = modal.selected && (readRowId(modal.selected, resourceIdKey) ?? modal.selected);
|
|
10614
|
+
const deleteRequest = react.useRef(null);
|
|
10615
|
+
const [deletePhase, setDeletePhase] = react.useState("idle");
|
|
10616
|
+
const deleting = deletePhase !== "idle" || resource.mutations.isDeleting;
|
|
10617
|
+
react.useEffect(() => {
|
|
10618
|
+
if (deletePhase !== "settled" || !deleteRequest.current) return;
|
|
10619
|
+
const submitted = deleteRequest.current;
|
|
10620
|
+
deleteRequest.current = null;
|
|
10621
|
+
setDeletePhase("idle");
|
|
10622
|
+
if (modal.deleteOpen && submitted.target === deleteTarget && submitted.modal.viewOpen === modal.viewOpen && submitted.modal.editOpen === modal.editOpen && submitted.modal.createOpen === modal.createOpen) resource.handlers.closeModals();
|
|
10623
|
+
}, [
|
|
10624
|
+
deletePhase,
|
|
10625
|
+
deleteTarget,
|
|
10626
|
+
modal,
|
|
10627
|
+
resource.handlers
|
|
10628
|
+
]);
|
|
10629
|
+
const confirmDelete = async () => {
|
|
10630
|
+
if (deleteRequest.current || deleting) return;
|
|
10631
|
+
deleteRequest.current = {
|
|
10632
|
+
target: deleteTarget,
|
|
10633
|
+
modal
|
|
10634
|
+
};
|
|
10635
|
+
setDeletePhase("pending");
|
|
10636
|
+
try {
|
|
10637
|
+
await resource.handlers.confirmDelete();
|
|
10638
|
+
} catch (error) {
|
|
10639
|
+
sonner.toast.error(error instanceof Error ? error.message : String(error));
|
|
10640
|
+
} finally {
|
|
10641
|
+
setDeletePhase("settled");
|
|
10642
|
+
}
|
|
10643
|
+
};
|
|
10611
10644
|
const [selectedRows, setSelectedRows] = react.useState([]);
|
|
10612
10645
|
const [exporting, setExporting] = react.useState(false);
|
|
10613
10646
|
const exportBusyRef = react.useRef(false);
|
|
@@ -10628,7 +10661,6 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
10628
10661
|
]);
|
|
10629
10662
|
const excludedColumns = react.useMemo(() => hiddenColumns.filter((key) => !filterOnly.includes(key)), [hiddenColumns, filterOnly]);
|
|
10630
10663
|
const dynamicResolveOptions = useDynamicResolveOptions(resolvedFields, resource.tableData.data, hiddenColumns);
|
|
10631
|
-
const resourceIdKey = resource.idKey ?? "id";
|
|
10632
10664
|
const tagFields = react.useMemo(() => Object.entries(resolvedFields).filter(([field, config]) => config.tags && !config.hidden && !denyFields?.includes(field)).map(([field, config]) => {
|
|
10633
10665
|
const label = config.label ?? humanize(field);
|
|
10634
10666
|
return {
|
|
@@ -11189,12 +11221,26 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11189
11221
|
}),
|
|
11190
11222
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_ui.AlertDialog, {
|
|
11191
11223
|
open: resource.modal.deleteOpen,
|
|
11192
|
-
onOpenChange: (open) =>
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
|
|
11224
|
+
onOpenChange: (open) => {
|
|
11225
|
+
if (!open && !deleteRequest.current && !deleting) resource.handlers.closeModals();
|
|
11226
|
+
},
|
|
11227
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_ui.AlertDialogContent, {
|
|
11228
|
+
"aria-busy": deleting,
|
|
11229
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_ui.AlertDialogHeader, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_ui.AlertDialogTitle, { children: locale.deleteModal.title }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_ui.AlertDialogDescription, { children: locale.deleteModal.description })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_ui.AlertDialogFooter, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_ui.AlertDialogCancel, {
|
|
11230
|
+
disabled: deleting,
|
|
11231
|
+
children: locale.deleteModal.cancel
|
|
11232
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_ui.AlertDialogAction, {
|
|
11233
|
+
onClick: (event) => {
|
|
11234
|
+
event.preventDefault();
|
|
11235
|
+
confirmDelete();
|
|
11236
|
+
},
|
|
11237
|
+
disabled: deleting,
|
|
11238
|
+
children: [deleting && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, {
|
|
11239
|
+
"aria-hidden": "true",
|
|
11240
|
+
className: "h-4 w-4 animate-spin"
|
|
11241
|
+
}), deleting ? locale.deleteModal.confirming : locale.deleteModal.confirm]
|
|
11242
|
+
})] })]
|
|
11243
|
+
})
|
|
11198
11244
|
}),
|
|
11199
11245
|
canImport && resource.handlers.import && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImportDialog, {
|
|
11200
11246
|
open: importOpen,
|
|
@@ -11933,18 +11979,21 @@ function modalReducer(state, action$1) {
|
|
|
11933
11979
|
case "OPEN_CREATE": return {
|
|
11934
11980
|
...state,
|
|
11935
11981
|
createOpen: true,
|
|
11982
|
+
deleteOpen: false,
|
|
11936
11983
|
selected: null,
|
|
11937
11984
|
copySource: null
|
|
11938
11985
|
};
|
|
11939
11986
|
case "OPEN_CREATE_WITH_COPY": return {
|
|
11940
11987
|
...state,
|
|
11941
11988
|
createOpen: true,
|
|
11989
|
+
deleteOpen: false,
|
|
11942
11990
|
selected: null,
|
|
11943
11991
|
copySource: action$1.payload
|
|
11944
11992
|
};
|
|
11945
11993
|
case "OPEN_EDIT": return {
|
|
11946
11994
|
...state,
|
|
11947
11995
|
editOpen: true,
|
|
11996
|
+
deleteOpen: false,
|
|
11948
11997
|
selected: action$1.payload
|
|
11949
11998
|
};
|
|
11950
11999
|
case "OPEN_DELETE": return {
|
|
@@ -11952,9 +12001,19 @@ function modalReducer(state, action$1) {
|
|
|
11952
12001
|
deleteOpen: true,
|
|
11953
12002
|
selected: action$1.payload
|
|
11954
12003
|
};
|
|
12004
|
+
case "DELETE_SUCCEEDED": {
|
|
12005
|
+
if (!state.deleteOpen || state.selected !== action$1.payload) return state;
|
|
12006
|
+
const otherModalOpen = state.createOpen || state.editOpen || state.viewOpen;
|
|
12007
|
+
return {
|
|
12008
|
+
...state,
|
|
12009
|
+
deleteOpen: false,
|
|
12010
|
+
selected: otherModalOpen ? state.selected : null
|
|
12011
|
+
};
|
|
12012
|
+
}
|
|
11955
12013
|
case "OPEN_VIEW": return {
|
|
11956
12014
|
...state,
|
|
11957
12015
|
viewOpen: true,
|
|
12016
|
+
deleteOpen: false,
|
|
11958
12017
|
selected: action$1.payload
|
|
11959
12018
|
};
|
|
11960
12019
|
case "CLOSE_ALL": return {
|
|
@@ -12195,44 +12254,38 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12195
12254
|
const confirmDelete = (0, react.useCallback)(async () => {
|
|
12196
12255
|
const currentHooks = hooksRef.current;
|
|
12197
12256
|
if (!modal.selected) return;
|
|
12257
|
+
let data = modal.selected;
|
|
12198
12258
|
try {
|
|
12199
|
-
|
|
12200
|
-
|
|
12201
|
-
|
|
12202
|
-
|
|
12203
|
-
|
|
12204
|
-
|
|
12205
|
-
|
|
12206
|
-
|
|
12207
|
-
}
|
|
12208
|
-
|
|
12209
|
-
}
|
|
12259
|
+
const handled = currentHooks?.beforeDelete ? await currentHooks.beforeDelete(modal.selected) : void 0;
|
|
12260
|
+
if (handled === false) return;
|
|
12261
|
+
if (handled !== true) {
|
|
12262
|
+
const id = modal.selected[idKey];
|
|
12263
|
+
data = typeof deleteMutation.mutateAsync === "function" ? await deleteMutation.mutateAsync(id) : await new Promise((resolve, reject) => {
|
|
12264
|
+
deleteMutation.mutate(id, {
|
|
12265
|
+
onSuccess: resolve,
|
|
12266
|
+
onError: reject
|
|
12267
|
+
});
|
|
12268
|
+
});
|
|
12210
12269
|
}
|
|
12211
|
-
const id = modal.selected[idKey];
|
|
12212
|
-
deleteMutation.mutate(id, {
|
|
12213
|
-
onSuccess: (data) => {
|
|
12214
|
-
toast$1.success("删除成功");
|
|
12215
|
-
closeModals();
|
|
12216
|
-
listQuery.refetch();
|
|
12217
|
-
currentHooks?.onSuccess?.("delete", data);
|
|
12218
|
-
},
|
|
12219
|
-
onError: (error) => {
|
|
12220
|
-
const err = error;
|
|
12221
|
-
toast$1.error(`删除失败: ${err.message}`);
|
|
12222
|
-
currentHooks?.onError?.("delete", err);
|
|
12223
|
-
}
|
|
12224
|
-
});
|
|
12225
12270
|
} catch (error) {
|
|
12226
12271
|
const err = error;
|
|
12227
12272
|
toast$1.error(`删除失败: ${err.message}`);
|
|
12228
12273
|
currentHooks?.onError?.("delete", err);
|
|
12274
|
+
return;
|
|
12229
12275
|
}
|
|
12276
|
+
toast$1.success("删除成功");
|
|
12277
|
+
dispatch({
|
|
12278
|
+
type: "DELETE_SUCCEEDED",
|
|
12279
|
+
payload: modal.selected
|
|
12280
|
+
});
|
|
12281
|
+
listQuery.refetch();
|
|
12282
|
+
currentHooks?.onSuccess?.("delete", data);
|
|
12230
12283
|
}, [
|
|
12231
12284
|
modal.selected,
|
|
12232
12285
|
idKey,
|
|
12233
12286
|
deleteMutation,
|
|
12234
|
-
|
|
12235
|
-
|
|
12287
|
+
listQuery,
|
|
12288
|
+
toast$1
|
|
12236
12289
|
]);
|
|
12237
12290
|
const deleteMany = (0, react.useCallback)((rows) => {
|
|
12238
12291
|
const currentHooks = hooksRef.current;
|
package/dist/index.d.cts
CHANGED
|
@@ -299,6 +299,7 @@ interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
299
299
|
closeModals: () => void;
|
|
300
300
|
submitCreate: (values: z.infer<TSchema>) => void;
|
|
301
301
|
submitUpdate: (values: z.infer<TSchema>) => void;
|
|
302
|
+
/** The table waits for a returned promise and ignores its resolved value. */
|
|
302
303
|
confirmDelete: () => void;
|
|
303
304
|
deleteMany: (rows: TListItem[]) => void;
|
|
304
305
|
updateMany: (rows: TListItem[], data: Record<string, unknown>) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as positionActions, i as matchesPosition, n as actionPositionSchema, r as compareOrder, t as ActionPosition } from "./position-mYekVBBH.js";
|
|
2
2
|
import * as React$1 from "react";
|
|
3
3
|
import { ComponentProps, ReactNode } from "react";
|
|
4
|
-
import * as
|
|
4
|
+
import * as react_jsx_runtime20 from "react/jsx-runtime";
|
|
5
5
|
import { DropdownMenuTrigger, PopoverContentProps } from "@wordrhyme/shadcn";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { ClassValue } from "clsx";
|
|
@@ -299,6 +299,7 @@ interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
299
299
|
closeModals: () => void;
|
|
300
300
|
submitCreate: (values: z.infer<TSchema>) => void;
|
|
301
301
|
submitUpdate: (values: z.infer<TSchema>) => void;
|
|
302
|
+
/** The table waits for a returned promise and ignores its resolved value. */
|
|
302
303
|
confirmDelete: () => void;
|
|
303
304
|
deleteMany: (rows: TListItem[]) => void;
|
|
304
305
|
updateMany: (rows: TListItem[], data: Record<string, unknown>) => void;
|
|
@@ -1052,7 +1053,7 @@ interface AutoCrudProviderProps {
|
|
|
1052
1053
|
declare function AutoCrudProvider({
|
|
1053
1054
|
children,
|
|
1054
1055
|
...config
|
|
1055
|
-
}: AutoCrudProviderProps):
|
|
1056
|
+
}: AutoCrudProviderProps): react_jsx_runtime20.JSX.Element;
|
|
1056
1057
|
//#endregion
|
|
1057
1058
|
//#region src/lib/saved-views.d.ts
|
|
1058
1059
|
declare const viewQuerySchema: z.ZodObject<{
|
|
@@ -1397,7 +1398,7 @@ declare function DataTable<TData>({
|
|
|
1397
1398
|
className,
|
|
1398
1399
|
classNames,
|
|
1399
1400
|
...props
|
|
1400
|
-
}: DataTableProps<TData>):
|
|
1401
|
+
}: DataTableProps<TData>): react_jsx_runtime20.JSX.Element;
|
|
1401
1402
|
//#endregion
|
|
1402
1403
|
//#region src/components/auto-crud/auto-table-action-bar.d.ts
|
|
1403
1404
|
/** 批量更新字段配置 */
|
|
@@ -1488,7 +1489,7 @@ declare function AutoTableActionBar<TData>({
|
|
|
1488
1489
|
extraActions,
|
|
1489
1490
|
actions,
|
|
1490
1491
|
deleteConfirmation
|
|
1491
|
-
}: AutoTableActionBarProps<TData>):
|
|
1492
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime20.JSX.Element;
|
|
1492
1493
|
//#endregion
|
|
1493
1494
|
//#region src/lib/schema-bridge/types.d.ts
|
|
1494
1495
|
/**
|
|
@@ -1742,7 +1743,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1742
1743
|
onSelectedRowsChange,
|
|
1743
1744
|
getSelectedRows,
|
|
1744
1745
|
exportTableRef
|
|
1745
|
-
}: AutoTableProps<T>):
|
|
1746
|
+
}: AutoTableProps<T>): react_jsx_runtime20.JSX.Element;
|
|
1746
1747
|
//#endregion
|
|
1747
1748
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
1748
1749
|
type AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> = {
|
|
@@ -1785,7 +1786,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1785
1786
|
labelAlign,
|
|
1786
1787
|
labelWidth,
|
|
1787
1788
|
showSubmitButton
|
|
1788
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
1789
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime20.JSX.Element;
|
|
1789
1790
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
1790
1791
|
ref?: React.Ref<AutoFormRef>;
|
|
1791
1792
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -2172,7 +2173,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
2172
2173
|
locale: localeProp,
|
|
2173
2174
|
onCreate,
|
|
2174
2175
|
onExport
|
|
2175
|
-
}: AutoCrudTableProps<TSchema>):
|
|
2176
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime20.JSX.Element;
|
|
2176
2177
|
//#endregion
|
|
2177
2178
|
//#region src/components/auto-crud/auto-table-simple-filters.d.ts
|
|
2178
2179
|
interface AutoTableSimpleFiltersProps<TData> {
|
|
@@ -2188,7 +2189,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
2188
2189
|
filters: externalFilters,
|
|
2189
2190
|
onFiltersChange,
|
|
2190
2191
|
leading
|
|
2191
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
2192
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime20.JSX.Element | null;
|
|
2192
2193
|
//#endregion
|
|
2193
2194
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
2194
2195
|
type ModalVariant = 'dialog' | 'sheet';
|
|
@@ -2237,7 +2238,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
2237
2238
|
labelAlign,
|
|
2238
2239
|
labelWidth,
|
|
2239
2240
|
className
|
|
2240
|
-
}: CrudFormModalProps<T> & CrudFormModalMode<T>):
|
|
2241
|
+
}: CrudFormModalProps<T> & CrudFormModalMode<T>): react_jsx_runtime20.JSX.Element;
|
|
2241
2242
|
//#endregion
|
|
2242
2243
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
2243
2244
|
interface ImportDialogProps {
|
|
@@ -2262,7 +2263,7 @@ declare function ImportDialog({
|
|
|
2262
2263
|
fields,
|
|
2263
2264
|
title,
|
|
2264
2265
|
locale
|
|
2265
|
-
}: ImportDialogProps):
|
|
2266
|
+
}: ImportDialogProps): react_jsx_runtime20.JSX.Element;
|
|
2266
2267
|
//#endregion
|
|
2267
2268
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
2268
2269
|
type ExportMode = 'selected' | 'filtered';
|
|
@@ -2282,7 +2283,7 @@ declare function ExportDialog({
|
|
|
2282
2283
|
selectedCount,
|
|
2283
2284
|
onExport,
|
|
2284
2285
|
canExportFiltered
|
|
2285
|
-
}: ExportDialogProps):
|
|
2286
|
+
}: ExportDialogProps): react_jsx_runtime20.JSX.Element;
|
|
2286
2287
|
//#endregion
|
|
2287
2288
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
2288
2289
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<'div'> {
|
|
@@ -2293,7 +2294,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
2293
2294
|
children,
|
|
2294
2295
|
className,
|
|
2295
2296
|
...props
|
|
2296
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
2297
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime20.JSX.Element;
|
|
2297
2298
|
//#endregion
|
|
2298
2299
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
2299
2300
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -2305,7 +2306,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
2305
2306
|
label,
|
|
2306
2307
|
className,
|
|
2307
2308
|
...props
|
|
2308
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
2309
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime20.JSX.Element;
|
|
2309
2310
|
//#endregion
|
|
2310
2311
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
2311
2312
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -2319,7 +2320,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
2319
2320
|
title,
|
|
2320
2321
|
options,
|
|
2321
2322
|
multiple
|
|
2322
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
2323
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime20.JSX.Element;
|
|
2323
2324
|
//#endregion
|
|
2324
2325
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
2325
2326
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<'div'>, TablePaginationOptions {
|
|
@@ -2336,7 +2337,7 @@ declare function DataTablePagination<TData>({
|
|
|
2336
2337
|
pageJumpLabel,
|
|
2337
2338
|
className,
|
|
2338
2339
|
...props
|
|
2339
|
-
}: DataTablePaginationProps<TData>):
|
|
2340
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime20.JSX.Element;
|
|
2340
2341
|
//#endregion
|
|
2341
2342
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
2342
2343
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<'div'> {
|
|
@@ -2347,7 +2348,7 @@ declare function DataTableToolbar<TData>({
|
|
|
2347
2348
|
children,
|
|
2348
2349
|
className,
|
|
2349
2350
|
...props
|
|
2350
|
-
}: DataTableToolbarProps<TData>):
|
|
2351
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime20.JSX.Element;
|
|
2351
2352
|
//#endregion
|
|
2352
2353
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
2353
2354
|
interface DataTableViewOptionsProps<TData> extends PopoverContentProps {
|
|
@@ -2360,7 +2361,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
2360
2361
|
disabled,
|
|
2361
2362
|
locale,
|
|
2362
2363
|
...props
|
|
2363
|
-
}: DataTableViewOptionsProps<TData>):
|
|
2364
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime20.JSX.Element;
|
|
2364
2365
|
//#endregion
|
|
2365
2366
|
//#region src/lib/crud-actions.d.ts
|
|
2366
2367
|
type CrudActionZone = 'toolbar' | 'row' | 'batch';
|
|
@@ -2802,7 +2803,7 @@ declare function TagFilter({
|
|
|
2802
2803
|
resourceId: resourceIdProp,
|
|
2803
2804
|
field,
|
|
2804
2805
|
...props
|
|
2805
|
-
}: TagFilterProps):
|
|
2806
|
+
}: TagFilterProps): react_jsx_runtime20.JSX.Element;
|
|
2806
2807
|
interface TagAssignmentProps extends TagScope, Pick<RowActionDialogProps, 'open' | 'onOpenChange'> {
|
|
2807
2808
|
title: string;
|
|
2808
2809
|
/** Current record tags, snapshotted when the editor opens. */
|
|
@@ -2813,6 +2814,6 @@ interface TagAssignmentProps extends TagScope, Pick<RowActionDialogProps, 'open'
|
|
|
2813
2814
|
onSaved?: () => unknown | Promise<unknown>;
|
|
2814
2815
|
}
|
|
2815
2816
|
/** Controlled dialog. Callers own the trigger, its appearance and its placement. */
|
|
2816
|
-
declare function TagAssignment(props: TagAssignmentProps):
|
|
2817
|
+
declare function TagAssignment(props: TagAssignmentProps): react_jsx_runtime20.JSX.Element | null;
|
|
2817
2818
|
//#endregion
|
|
2818
2819
|
export { type ActionConfig, type ActionItem, type ActionPosition, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudExportContext, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudProvider, type AutoCrudProviderProps, type AutoCrudQueryCapabilities, type AutoCrudRowActionContext, type AutoCrudRowOpenOptions, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoFormProps, type AutoQueryParams, AutoTable, AutoTableActionBar, type AutoTableProps, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchSearchConfig, type BatchSearchField, type BatchSearchFilter, type BatchSearchLocale, type BatchSearchState, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableClassNames, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, type DataTableProps, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type DataTableViewOptionsProps, type DateFormatPreset, type DateFormatter, type DateLocaleOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldTableDisplay, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportIssue, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, type PresetView, QueryKeys, type RowActionConfig, type RowActionDialogProps, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, type SavedView, type SavedViewsConfig, SchemaAdapter, Select, type SelectMode, type SelectOption, type SelectProps, type SelectSearchableDynamicProps, type SelectSearchableMultipleProps, type SelectSearchableProps, type SelectSearchableSingleProps, type SelectSimpleProps, type SelectTriggerRenderProps, type SimpleFieldConfig, type SimpleFieldsConfig, type TableActionBarLocale, type TableBatchSearchConfig, type TableControlsLocale, type TableFilterState, type TablePaginationLocale, type TablePaginationOptions, type TableSearchConfig, type TableSearchProps, TagAssignment, type TagAssignmentProps, TagFilter, type TagFilterProps, type TagFilterValue, type TagInput, type TagOption, type TagScope, type TagService, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarBuiltinActionType, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, type ViewCapabilities, type ViewInput, type ViewQuery, type ViewScope, type ViewStorage, type ViewStorageCapabilities, type WorkbookSheet, actionPositionSchema, cn, coerceRowValues, compareOrder, components, createActionsColumn, createEditFormSchema, createFormSchema, createLocalViewStorage, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, exportWorkbook, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, matchesPosition, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, positionActions, presetViewSchema, resolveLocale, savedViewSchema, setDateFormatter, setSearchParams, setToolbarResolver, tablePagination, tagFilterValueSchema, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, viewCapabilitiesSchema, viewInputSchema, viewQuerySchema, viewScopeSchema, viewStorageCapabilitiesSchema, zhCN };
|
package/dist/index.js
CHANGED
|
@@ -10592,6 +10592,39 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
10592
10592
|
const canImport = can.import && !!resource.handlers.import;
|
|
10593
10593
|
const canExport = can.export;
|
|
10594
10594
|
const [importOpen, setImportOpen] = React.useState(false);
|
|
10595
|
+
const resourceIdKey = resource.idKey ?? "id";
|
|
10596
|
+
const modal = resource.modal;
|
|
10597
|
+
const deleteTarget = modal.selected && (readRowId(modal.selected, resourceIdKey) ?? modal.selected);
|
|
10598
|
+
const deleteRequest = React.useRef(null);
|
|
10599
|
+
const [deletePhase, setDeletePhase] = React.useState("idle");
|
|
10600
|
+
const deleting = deletePhase !== "idle" || resource.mutations.isDeleting;
|
|
10601
|
+
React.useEffect(() => {
|
|
10602
|
+
if (deletePhase !== "settled" || !deleteRequest.current) return;
|
|
10603
|
+
const submitted = deleteRequest.current;
|
|
10604
|
+
deleteRequest.current = null;
|
|
10605
|
+
setDeletePhase("idle");
|
|
10606
|
+
if (modal.deleteOpen && submitted.target === deleteTarget && submitted.modal.viewOpen === modal.viewOpen && submitted.modal.editOpen === modal.editOpen && submitted.modal.createOpen === modal.createOpen) resource.handlers.closeModals();
|
|
10607
|
+
}, [
|
|
10608
|
+
deletePhase,
|
|
10609
|
+
deleteTarget,
|
|
10610
|
+
modal,
|
|
10611
|
+
resource.handlers
|
|
10612
|
+
]);
|
|
10613
|
+
const confirmDelete = async () => {
|
|
10614
|
+
if (deleteRequest.current || deleting) return;
|
|
10615
|
+
deleteRequest.current = {
|
|
10616
|
+
target: deleteTarget,
|
|
10617
|
+
modal
|
|
10618
|
+
};
|
|
10619
|
+
setDeletePhase("pending");
|
|
10620
|
+
try {
|
|
10621
|
+
await resource.handlers.confirmDelete();
|
|
10622
|
+
} catch (error) {
|
|
10623
|
+
toast.error(error instanceof Error ? error.message : String(error));
|
|
10624
|
+
} finally {
|
|
10625
|
+
setDeletePhase("settled");
|
|
10626
|
+
}
|
|
10627
|
+
};
|
|
10595
10628
|
const [selectedRows, setSelectedRows] = React.useState([]);
|
|
10596
10629
|
const [exporting, setExporting] = React.useState(false);
|
|
10597
10630
|
const exportBusyRef = React.useRef(false);
|
|
@@ -10612,7 +10645,6 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
10612
10645
|
]);
|
|
10613
10646
|
const excludedColumns = React.useMemo(() => hiddenColumns.filter((key) => !filterOnly.includes(key)), [hiddenColumns, filterOnly]);
|
|
10614
10647
|
const dynamicResolveOptions = useDynamicResolveOptions(resolvedFields, resource.tableData.data, hiddenColumns);
|
|
10615
|
-
const resourceIdKey = resource.idKey ?? "id";
|
|
10616
10648
|
const tagFields = React.useMemo(() => Object.entries(resolvedFields).filter(([field, config]) => config.tags && !config.hidden && !denyFields?.includes(field)).map(([field, config]) => {
|
|
10617
10649
|
const label = config.label ?? humanize(field);
|
|
10618
10650
|
return {
|
|
@@ -11173,12 +11205,26 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11173
11205
|
}),
|
|
11174
11206
|
/* @__PURE__ */ jsx(AlertDialog$1, {
|
|
11175
11207
|
open: resource.modal.deleteOpen,
|
|
11176
|
-
onOpenChange: (open) =>
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
|
|
11180
|
-
|
|
11181
|
-
|
|
11208
|
+
onOpenChange: (open) => {
|
|
11209
|
+
if (!open && !deleteRequest.current && !deleting) resource.handlers.closeModals();
|
|
11210
|
+
},
|
|
11211
|
+
children: /* @__PURE__ */ jsxs(AlertDialogContent$1, {
|
|
11212
|
+
"aria-busy": deleting,
|
|
11213
|
+
children: [/* @__PURE__ */ jsxs(AlertDialogHeader$1, { children: [/* @__PURE__ */ jsx(AlertDialogTitle$1, { children: locale.deleteModal.title }), /* @__PURE__ */ jsx(AlertDialogDescription$1, { children: locale.deleteModal.description })] }), /* @__PURE__ */ jsxs(AlertDialogFooter$1, { children: [/* @__PURE__ */ jsx(AlertDialogCancel$1, {
|
|
11214
|
+
disabled: deleting,
|
|
11215
|
+
children: locale.deleteModal.cancel
|
|
11216
|
+
}), /* @__PURE__ */ jsxs(AlertDialogAction$1, {
|
|
11217
|
+
onClick: (event) => {
|
|
11218
|
+
event.preventDefault();
|
|
11219
|
+
confirmDelete();
|
|
11220
|
+
},
|
|
11221
|
+
disabled: deleting,
|
|
11222
|
+
children: [deleting && /* @__PURE__ */ jsx(Loader2, {
|
|
11223
|
+
"aria-hidden": "true",
|
|
11224
|
+
className: "h-4 w-4 animate-spin"
|
|
11225
|
+
}), deleting ? locale.deleteModal.confirming : locale.deleteModal.confirm]
|
|
11226
|
+
})] })]
|
|
11227
|
+
})
|
|
11182
11228
|
}),
|
|
11183
11229
|
canImport && resource.handlers.import && /* @__PURE__ */ jsx(ImportDialog, {
|
|
11184
11230
|
open: importOpen,
|
|
@@ -11917,18 +11963,21 @@ function modalReducer(state, action$1) {
|
|
|
11917
11963
|
case "OPEN_CREATE": return {
|
|
11918
11964
|
...state,
|
|
11919
11965
|
createOpen: true,
|
|
11966
|
+
deleteOpen: false,
|
|
11920
11967
|
selected: null,
|
|
11921
11968
|
copySource: null
|
|
11922
11969
|
};
|
|
11923
11970
|
case "OPEN_CREATE_WITH_COPY": return {
|
|
11924
11971
|
...state,
|
|
11925
11972
|
createOpen: true,
|
|
11973
|
+
deleteOpen: false,
|
|
11926
11974
|
selected: null,
|
|
11927
11975
|
copySource: action$1.payload
|
|
11928
11976
|
};
|
|
11929
11977
|
case "OPEN_EDIT": return {
|
|
11930
11978
|
...state,
|
|
11931
11979
|
editOpen: true,
|
|
11980
|
+
deleteOpen: false,
|
|
11932
11981
|
selected: action$1.payload
|
|
11933
11982
|
};
|
|
11934
11983
|
case "OPEN_DELETE": return {
|
|
@@ -11936,9 +11985,19 @@ function modalReducer(state, action$1) {
|
|
|
11936
11985
|
deleteOpen: true,
|
|
11937
11986
|
selected: action$1.payload
|
|
11938
11987
|
};
|
|
11988
|
+
case "DELETE_SUCCEEDED": {
|
|
11989
|
+
if (!state.deleteOpen || state.selected !== action$1.payload) return state;
|
|
11990
|
+
const otherModalOpen = state.createOpen || state.editOpen || state.viewOpen;
|
|
11991
|
+
return {
|
|
11992
|
+
...state,
|
|
11993
|
+
deleteOpen: false,
|
|
11994
|
+
selected: otherModalOpen ? state.selected : null
|
|
11995
|
+
};
|
|
11996
|
+
}
|
|
11939
11997
|
case "OPEN_VIEW": return {
|
|
11940
11998
|
...state,
|
|
11941
11999
|
viewOpen: true,
|
|
12000
|
+
deleteOpen: false,
|
|
11942
12001
|
selected: action$1.payload
|
|
11943
12002
|
};
|
|
11944
12003
|
case "CLOSE_ALL": return {
|
|
@@ -12179,44 +12238,38 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12179
12238
|
const confirmDelete = useCallback(async () => {
|
|
12180
12239
|
const currentHooks = hooksRef.current;
|
|
12181
12240
|
if (!modal.selected) return;
|
|
12241
|
+
let data = modal.selected;
|
|
12182
12242
|
try {
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
}
|
|
12192
|
-
|
|
12193
|
-
}
|
|
12243
|
+
const handled = currentHooks?.beforeDelete ? await currentHooks.beforeDelete(modal.selected) : void 0;
|
|
12244
|
+
if (handled === false) return;
|
|
12245
|
+
if (handled !== true) {
|
|
12246
|
+
const id = modal.selected[idKey];
|
|
12247
|
+
data = typeof deleteMutation.mutateAsync === "function" ? await deleteMutation.mutateAsync(id) : await new Promise((resolve, reject) => {
|
|
12248
|
+
deleteMutation.mutate(id, {
|
|
12249
|
+
onSuccess: resolve,
|
|
12250
|
+
onError: reject
|
|
12251
|
+
});
|
|
12252
|
+
});
|
|
12194
12253
|
}
|
|
12195
|
-
const id = modal.selected[idKey];
|
|
12196
|
-
deleteMutation.mutate(id, {
|
|
12197
|
-
onSuccess: (data) => {
|
|
12198
|
-
toast$1.success("删除成功");
|
|
12199
|
-
closeModals();
|
|
12200
|
-
listQuery.refetch();
|
|
12201
|
-
currentHooks?.onSuccess?.("delete", data);
|
|
12202
|
-
},
|
|
12203
|
-
onError: (error) => {
|
|
12204
|
-
const err = error;
|
|
12205
|
-
toast$1.error(`删除失败: ${err.message}`);
|
|
12206
|
-
currentHooks?.onError?.("delete", err);
|
|
12207
|
-
}
|
|
12208
|
-
});
|
|
12209
12254
|
} catch (error) {
|
|
12210
12255
|
const err = error;
|
|
12211
12256
|
toast$1.error(`删除失败: ${err.message}`);
|
|
12212
12257
|
currentHooks?.onError?.("delete", err);
|
|
12258
|
+
return;
|
|
12213
12259
|
}
|
|
12260
|
+
toast$1.success("删除成功");
|
|
12261
|
+
dispatch({
|
|
12262
|
+
type: "DELETE_SUCCEEDED",
|
|
12263
|
+
payload: modal.selected
|
|
12264
|
+
});
|
|
12265
|
+
listQuery.refetch();
|
|
12266
|
+
currentHooks?.onSuccess?.("delete", data);
|
|
12214
12267
|
}, [
|
|
12215
12268
|
modal.selected,
|
|
12216
12269
|
idKey,
|
|
12217
12270
|
deleteMutation,
|
|
12218
|
-
|
|
12219
|
-
|
|
12271
|
+
listQuery,
|
|
12272
|
+
toast$1
|
|
12220
12273
|
]);
|
|
12221
12274
|
const deleteMany = useCallback((rows) => {
|
|
12222
12275
|
const currentHooks = hooksRef.current;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.23.
|
|
4
|
+
"version": "1.23.1",
|
|
5
5
|
"description": "Schema-first CRUD components with auto-generated tables and forms",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
"nanoid": "^5.1.6",
|
|
72
72
|
"tailwind-merge": "^3.5.0",
|
|
73
73
|
"vaul": "^1.1.2",
|
|
74
|
-
"@wordrhyme/shadcn": "2.
|
|
74
|
+
"@wordrhyme/formily-shadcn": "2.1.4",
|
|
75
75
|
"@wordrhyme/shadcn-ui": "2.1.4",
|
|
76
|
-
"@wordrhyme/
|
|
76
|
+
"@wordrhyme/shadcn": "2.0.3"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@storybook/react": "^8.6.18",
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
"vitest": "^3.2.4",
|
|
97
97
|
"@internal/eslint-config": "0.3.0",
|
|
98
98
|
"@internal/prettier-config": "0.0.1",
|
|
99
|
-
"@internal/tsconfig": "0.1.0",
|
|
100
99
|
"@internal/tsdown-config": "0.1.0",
|
|
100
|
+
"@internal/tsconfig": "0.1.0",
|
|
101
101
|
"@internal/vitest-config": "0.1.0"
|
|
102
102
|
},
|
|
103
103
|
"prettier": "@internal/prettier-config",
|