@wordrhyme/auto-crud 1.23.1 → 1.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +67 -26
- package/dist/index.d.cts +1004 -996
- package/dist/index.d.ts +1021 -1013
- package/dist/index.js +68 -27
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { i as positionActions, n as compareOrder, r as matchesPosition, t as act
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { Fragment, createContext, createElement, forwardRef, useCallback, useContext, useEffect, useId, useImperativeHandle, useMemo, useReducer, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
5
|
+
import { hashKey, keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
6
6
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Badge, Button, Calendar, Checkbox, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, Label, Popover, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupItem, Select as Select$1, SelectContent, SelectItem, SelectTrigger, SelectValue, Separator, Slider, Switch, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Textarea, ToggleGroup, ToggleGroupItem, cn as cn$1 } from "@wordrhyme/shadcn";
|
|
7
7
|
import { AppWindow, ArrowDownUp, BadgeCheck, CalendarIcon, Check, CheckCircle2, ChevronDown, ChevronLeft, ChevronRight, ChevronRightIcon, ChevronUp, ChevronsLeft, ChevronsRight, ChevronsRightIcon, ChevronsUpDown, CommandIcon, Copy, Download, Ellipsis, Eye, EyeOff, FileDown, FileSpreadsheetIcon, GripVertical, Info, Layers, List, ListFilter, ListFilterIcon, Loader2, PanelsTopLeft, Pencil, Plus, PlusCircle, RefreshCw, Search, Settings, Settings2, Text, Trash2, Upload, X, XCircle } from "lucide-react";
|
|
8
8
|
import { z } from "zod";
|
|
@@ -1618,7 +1618,7 @@ function SavedViews(props) {
|
|
|
1618
1618
|
key: `${config.cacheKey}:${props.resourceId}`
|
|
1619
1619
|
});
|
|
1620
1620
|
}
|
|
1621
|
-
function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets, hiddenViews, scopeOptions, selector = "dropdown", tabs, counts, onApply, children }) {
|
|
1621
|
+
function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets, hiddenViews, scopeOptions, selector = "dropdown", tabs, counts, countSource, onApply, children }) {
|
|
1622
1622
|
const config = useAutoCrudConfig();
|
|
1623
1623
|
const storage = config.viewStorage;
|
|
1624
1624
|
const client = useQueryClient();
|
|
@@ -1727,25 +1727,39 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1727
1727
|
enabled: Boolean(counts) && ready && fieldsReady
|
|
1728
1728
|
});
|
|
1729
1729
|
const data = table.options.data;
|
|
1730
|
+
const navigationKey = countSource?.navigationKey;
|
|
1731
|
+
const refreshVersion = countSource?.refreshVersion;
|
|
1732
|
+
const listFetching = countSource?.isFetching;
|
|
1730
1733
|
const previousSource = useRef({
|
|
1731
1734
|
data,
|
|
1732
|
-
counts
|
|
1735
|
+
counts,
|
|
1736
|
+
navigationKey
|
|
1733
1737
|
});
|
|
1738
|
+
const countedVersion = useRef(refreshVersion);
|
|
1734
1739
|
const refreshPending = useRef(false);
|
|
1735
1740
|
const refetchCounts = totals.refetch;
|
|
1736
1741
|
useEffect(() => {
|
|
1737
1742
|
const previous = previousSource.current;
|
|
1738
|
-
previousSource.current = {
|
|
1739
|
-
|
|
1743
|
+
previousSource.current = navigationKey === null ? {
|
|
1744
|
+
...previous,
|
|
1740
1745
|
counts
|
|
1746
|
+
} : {
|
|
1747
|
+
data,
|
|
1748
|
+
counts,
|
|
1749
|
+
navigationKey
|
|
1741
1750
|
};
|
|
1742
|
-
if (previous.data !== data || previous.counts !== counts) refreshPending.current = true;
|
|
1743
|
-
|
|
1751
|
+
if (navigationKey !== null && previous.navigationKey === navigationKey && previous.data !== data || previous.counts !== counts) refreshPending.current = true;
|
|
1752
|
+
const resourceRefresh = countedVersion.current !== refreshVersion;
|
|
1753
|
+
if (!counts || !ready || !fieldsReady || totals.fetchStatus !== "idle" || resourceRefresh && listFetching || !refreshPending.current && !resourceRefresh) return;
|
|
1744
1754
|
refreshPending.current = false;
|
|
1755
|
+
countedVersion.current = refreshVersion;
|
|
1745
1756
|
refetchCounts({ cancelRefetch: false });
|
|
1746
1757
|
}, [
|
|
1747
1758
|
data,
|
|
1748
1759
|
counts,
|
|
1760
|
+
navigationKey,
|
|
1761
|
+
refreshVersion,
|
|
1762
|
+
listFetching,
|
|
1749
1763
|
ready,
|
|
1750
1764
|
fieldsReady,
|
|
1751
1765
|
totals.fetchStatus,
|
|
@@ -11096,6 +11110,11 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11096
11110
|
};
|
|
11097
11111
|
const toolbarNodes = normalizedToolbarActions.filter((action$1) => action$1.type !== "refresh").map(renderToolbarAction).filter((node) => node !== null);
|
|
11098
11112
|
const refreshNodes = normalizedToolbarActions.filter((action$1) => action$1.type === "refresh").map(renderToolbarAction);
|
|
11113
|
+
const views = viewsEnabled ? {
|
|
11114
|
+
...typeof viewsEnabled === "object" ? viewsEnabled : {},
|
|
11115
|
+
countSource: resource.tableData.countSource,
|
|
11116
|
+
fieldsReady: !resource.metadataPending && (typeof viewsEnabled !== "object" || viewsEnabled.fieldsReady !== false)
|
|
11117
|
+
} : false;
|
|
11099
11118
|
return /* @__PURE__ */ jsx(CrudResourceContext.Provider, {
|
|
11100
11119
|
value: id,
|
|
11101
11120
|
children: /* @__PURE__ */ jsxs("div", {
|
|
@@ -11120,10 +11139,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
11120
11139
|
}),
|
|
11121
11140
|
/* @__PURE__ */ jsx(AutoTable, {
|
|
11122
11141
|
resourceId: id,
|
|
11123
|
-
views
|
|
11124
|
-
...typeof viewsEnabled === "object" ? viewsEnabled : {},
|
|
11125
|
-
fieldsReady: !resource.metadataPending && (typeof viewsEnabled !== "object" || viewsEnabled.fieldsReady !== false)
|
|
11126
|
-
} : false,
|
|
11142
|
+
views,
|
|
11127
11143
|
data: resource.tableData.data,
|
|
11128
11144
|
schema: resolvedSchema,
|
|
11129
11145
|
pageCount: resource.tableData.pageCount,
|
|
@@ -12108,6 +12124,26 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12108
12124
|
}, [listReady, listQuery.data]);
|
|
12109
12125
|
const listData = listReady ? listQuery.data : void 0;
|
|
12110
12126
|
const tableRows = listData?.data ?? EMPTY_ROWS;
|
|
12127
|
+
const navigationKey = useMemo(() => hashKey([
|
|
12128
|
+
page,
|
|
12129
|
+
perPage,
|
|
12130
|
+
sort,
|
|
12131
|
+
filters,
|
|
12132
|
+
joinOperator,
|
|
12133
|
+
search.trim()
|
|
12134
|
+
]), [
|
|
12135
|
+
page,
|
|
12136
|
+
perPage,
|
|
12137
|
+
sort,
|
|
12138
|
+
filters,
|
|
12139
|
+
joinOperator,
|
|
12140
|
+
search
|
|
12141
|
+
]);
|
|
12142
|
+
const [refreshVersion, requestCountsRefresh] = useReducer((version$1) => version$1 + 1, 0);
|
|
12143
|
+
const refreshResource = useCallback(() => {
|
|
12144
|
+
requestCountsRefresh();
|
|
12145
|
+
return listQuery.refetch();
|
|
12146
|
+
}, [listQuery]);
|
|
12111
12147
|
const createMutation = router.create.useMutation();
|
|
12112
12148
|
const updateMutation = router.update.useMutation();
|
|
12113
12149
|
const deleteMutation = router.delete.useMutation();
|
|
@@ -12159,7 +12195,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12159
12195
|
if (result) {
|
|
12160
12196
|
toast$1.success("创建成功");
|
|
12161
12197
|
closeModals();
|
|
12162
|
-
|
|
12198
|
+
refreshResource();
|
|
12163
12199
|
currentHooks?.onSuccess?.("create", values);
|
|
12164
12200
|
}
|
|
12165
12201
|
return;
|
|
@@ -12170,7 +12206,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12170
12206
|
onSuccess: (data) => {
|
|
12171
12207
|
toast$1.success("创建成功");
|
|
12172
12208
|
closeModals();
|
|
12173
|
-
|
|
12209
|
+
refreshResource();
|
|
12174
12210
|
currentHooks?.onSuccess?.("create", data);
|
|
12175
12211
|
},
|
|
12176
12212
|
onError: (error) => {
|
|
@@ -12187,7 +12223,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12187
12223
|
}, [
|
|
12188
12224
|
createMutation,
|
|
12189
12225
|
closeModals,
|
|
12190
|
-
|
|
12226
|
+
refreshResource
|
|
12191
12227
|
]);
|
|
12192
12228
|
const submitUpdate = useCallback(async (values) => {
|
|
12193
12229
|
const currentHooks = hooksRef.current;
|
|
@@ -12199,7 +12235,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12199
12235
|
if (result) {
|
|
12200
12236
|
toast$1.success("更新成功");
|
|
12201
12237
|
closeModals();
|
|
12202
|
-
|
|
12238
|
+
refreshResource();
|
|
12203
12239
|
currentHooks?.onSuccess?.("update", values);
|
|
12204
12240
|
}
|
|
12205
12241
|
return;
|
|
@@ -12214,7 +12250,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12214
12250
|
onSuccess: (data) => {
|
|
12215
12251
|
toast$1.success("更新成功");
|
|
12216
12252
|
closeModals();
|
|
12217
|
-
|
|
12253
|
+
refreshResource();
|
|
12218
12254
|
currentHooks?.onSuccess?.("update", data);
|
|
12219
12255
|
},
|
|
12220
12256
|
onError: (error) => {
|
|
@@ -12233,7 +12269,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12233
12269
|
idKey,
|
|
12234
12270
|
updateMutation,
|
|
12235
12271
|
closeModals,
|
|
12236
|
-
|
|
12272
|
+
refreshResource
|
|
12237
12273
|
]);
|
|
12238
12274
|
const confirmDelete = useCallback(async () => {
|
|
12239
12275
|
const currentHooks = hooksRef.current;
|
|
@@ -12262,13 +12298,13 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12262
12298
|
type: "DELETE_SUCCEEDED",
|
|
12263
12299
|
payload: modal.selected
|
|
12264
12300
|
});
|
|
12265
|
-
|
|
12301
|
+
refreshResource();
|
|
12266
12302
|
currentHooks?.onSuccess?.("delete", data);
|
|
12267
12303
|
}, [
|
|
12268
12304
|
modal.selected,
|
|
12269
12305
|
idKey,
|
|
12270
12306
|
deleteMutation,
|
|
12271
|
-
|
|
12307
|
+
refreshResource,
|
|
12272
12308
|
toast$1
|
|
12273
12309
|
]);
|
|
12274
12310
|
const deleteMany = useCallback((rows) => {
|
|
@@ -12281,7 +12317,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12281
12317
|
deleteManyMutation.mutate(ids, {
|
|
12282
12318
|
onSuccess: (data) => {
|
|
12283
12319
|
toast$1.success(`成功删除 ${ids.length} 条记录`);
|
|
12284
|
-
|
|
12320
|
+
refreshResource();
|
|
12285
12321
|
currentHooks?.onSuccess?.("delete", data);
|
|
12286
12322
|
},
|
|
12287
12323
|
onError: (error) => {
|
|
@@ -12293,7 +12329,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12293
12329
|
}, [
|
|
12294
12330
|
deleteManyMutation,
|
|
12295
12331
|
idKey,
|
|
12296
|
-
|
|
12332
|
+
refreshResource
|
|
12297
12333
|
]);
|
|
12298
12334
|
const updateMany = useCallback((rows, data) => {
|
|
12299
12335
|
const currentHooks = hooksRef.current;
|
|
@@ -12308,7 +12344,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12308
12344
|
}, {
|
|
12309
12345
|
onSuccess: (result) => {
|
|
12310
12346
|
toast$1.success(`成功更新 ${ids.length} 条记录`);
|
|
12311
|
-
|
|
12347
|
+
refreshResource();
|
|
12312
12348
|
currentHooks?.onSuccess?.("update", result);
|
|
12313
12349
|
},
|
|
12314
12350
|
onError: (error) => {
|
|
@@ -12320,7 +12356,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12320
12356
|
}, [
|
|
12321
12357
|
updateManyMutation,
|
|
12322
12358
|
idKey,
|
|
12323
|
-
|
|
12359
|
+
refreshResource
|
|
12324
12360
|
]);
|
|
12325
12361
|
const copyRow = useCallback((row) => {
|
|
12326
12362
|
dispatch({
|
|
@@ -12335,11 +12371,11 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12335
12371
|
rows: coercedRows,
|
|
12336
12372
|
onConflict: "upsert"
|
|
12337
12373
|
});
|
|
12338
|
-
|
|
12374
|
+
refreshResource();
|
|
12339
12375
|
return result;
|
|
12340
12376
|
}, [
|
|
12341
12377
|
importMutation,
|
|
12342
|
-
|
|
12378
|
+
refreshResource,
|
|
12343
12379
|
schema
|
|
12344
12380
|
]);
|
|
12345
12381
|
const handleExport = useCallback(async () => {
|
|
@@ -12363,8 +12399,8 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12363
12399
|
const canExport = !!(exportFetcher || exportQuery);
|
|
12364
12400
|
const refresh = useCallback(async () => {
|
|
12365
12401
|
if (!listReady) return;
|
|
12366
|
-
return
|
|
12367
|
-
}, [
|
|
12402
|
+
return refreshResource();
|
|
12403
|
+
}, [refreshResource, listReady]);
|
|
12368
12404
|
return {
|
|
12369
12405
|
idKey,
|
|
12370
12406
|
queryKeys,
|
|
@@ -12372,6 +12408,11 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12372
12408
|
filterState,
|
|
12373
12409
|
tableData: {
|
|
12374
12410
|
data: tableRows,
|
|
12411
|
+
countSource: {
|
|
12412
|
+
navigationKey: listData && !listQuery.isPlaceholderData ? navigationKey : null,
|
|
12413
|
+
refreshVersion,
|
|
12414
|
+
isFetching: listQuery.isFetching
|
|
12415
|
+
},
|
|
12375
12416
|
pageCount: listData?.pageCount ?? 0,
|
|
12376
12417
|
...typeof listData?.total === "number" ? { total: listData.total } : {},
|
|
12377
12418
|
isLoading: !listReady || listQuery.isLoading,
|
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.2",
|
|
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.0.3",
|
|
74
75
|
"@wordrhyme/formily-shadcn": "2.1.4",
|
|
75
|
-
"@wordrhyme/shadcn-ui": "2.1.4"
|
|
76
|
-
"@wordrhyme/shadcn": "2.0.3"
|
|
76
|
+
"@wordrhyme/shadcn-ui": "2.1.4"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@storybook/react": "^8.6.18",
|
|
@@ -94,10 +94,10 @@
|
|
|
94
94
|
"tsdown": "^0.15.12",
|
|
95
95
|
"typescript": "^5.9.3",
|
|
96
96
|
"vitest": "^3.2.4",
|
|
97
|
-
"@internal/eslint-config": "0.3.0",
|
|
98
97
|
"@internal/prettier-config": "0.0.1",
|
|
99
|
-
"@internal/
|
|
98
|
+
"@internal/eslint-config": "0.3.0",
|
|
100
99
|
"@internal/tsconfig": "0.1.0",
|
|
100
|
+
"@internal/tsdown-config": "0.1.0",
|
|
101
101
|
"@internal/vitest-config": "0.1.0"
|
|
102
102
|
},
|
|
103
103
|
"prettier": "@internal/prettier-config",
|