@wordrhyme/auto-crud 1.12.0 → 1.12.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 +20 -8
- package/dist/index.d.cts +16 -16
- package/dist/index.js +20 -8
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -8990,7 +8990,8 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
8990
8990
|
(0, react.useEffect)(() => {
|
|
8991
8991
|
hooksRef.current = hooks;
|
|
8992
8992
|
}, [hooks]);
|
|
8993
|
-
const
|
|
8993
|
+
const metadataQuery = router.meta?.useQuery(void 0, { staleTime: 3e4 });
|
|
8994
|
+
const metadata = metadataQuery?.data;
|
|
8994
8995
|
const resolvedSchema = (0, react.useMemo)(() => mergeMetadataSchema(schema, metadata?.schema), [schema, metadata?.schema]);
|
|
8995
8996
|
const defaultSorting = (0, react.useMemo)(() => defaultSortOption === false ? [] : defaultSortOption ?? getDefaultSortingForSchema(resolvedSchema), [defaultSortOption, resolvedSchema]);
|
|
8996
8997
|
const metadataFields = (0, react.useMemo)(() => readMetadataFields(metadata?.fields), [metadata?.fields]);
|
|
@@ -9011,6 +9012,10 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
9011
9012
|
search: parseAsString.withDefault("")
|
|
9012
9013
|
}, { shallow: false });
|
|
9013
9014
|
const [filters] = useReadableFilters(columns, { shallow: false });
|
|
9015
|
+
const metadataPending = Boolean(metadataQuery?.isPending);
|
|
9016
|
+
const [filtersReady, setFiltersReady] = (0, react.useState)(!metadataPending);
|
|
9017
|
+
(0, react.useEffect)(() => setFiltersReady(!metadataPending), [metadataPending]);
|
|
9018
|
+
const listReady = !metadataPending && filtersReady;
|
|
9014
9019
|
const queryInput = (0, react.useMemo)(() => {
|
|
9015
9020
|
const autoParams = {
|
|
9016
9021
|
page: urlParams.page,
|
|
@@ -9026,11 +9031,17 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
9026
9031
|
filters,
|
|
9027
9032
|
queryTransform
|
|
9028
9033
|
]);
|
|
9034
|
+
const hasReadyListData = (0, react.useRef)(false);
|
|
9029
9035
|
const listQuery = router.list.useQuery(queryInput, {
|
|
9030
|
-
|
|
9036
|
+
enabled: listReady,
|
|
9037
|
+
placeholderData: hasReadyListData.current ? __tanstack_react_query.keepPreviousData : void 0,
|
|
9031
9038
|
staleTime: 0
|
|
9032
9039
|
});
|
|
9033
|
-
|
|
9040
|
+
(0, react.useEffect)(() => {
|
|
9041
|
+
if (listReady && listQuery.data !== void 0) hasReadyListData.current = true;
|
|
9042
|
+
}, [listReady, listQuery.data]);
|
|
9043
|
+
const listData = listReady ? listQuery.data : void 0;
|
|
9044
|
+
const tableRows = listData?.data ?? [];
|
|
9034
9045
|
const createMutation = router.create.useMutation();
|
|
9035
9046
|
const updateMutation = router.update.useMutation();
|
|
9036
9047
|
const deleteMutation = router.delete.useMutation();
|
|
@@ -9288,16 +9299,17 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
9288
9299
|
]);
|
|
9289
9300
|
const canExport = !!(exportFetcher || exportQuery);
|
|
9290
9301
|
const refresh = (0, react.useCallback)(async () => {
|
|
9302
|
+
if (!listReady) return;
|
|
9291
9303
|
return listQuery.refetch();
|
|
9292
|
-
}, [listQuery]);
|
|
9304
|
+
}, [listQuery, listReady]);
|
|
9293
9305
|
return {
|
|
9294
9306
|
idKey,
|
|
9295
9307
|
tableData: {
|
|
9296
9308
|
data: tableRows,
|
|
9297
|
-
pageCount:
|
|
9298
|
-
...typeof
|
|
9299
|
-
isLoading: listQuery.isLoading,
|
|
9300
|
-
isFetching: listQuery.isFetching
|
|
9309
|
+
pageCount: listData?.pageCount ?? 0,
|
|
9310
|
+
...typeof listData?.total === "number" ? { total: listData.total } : {},
|
|
9311
|
+
isLoading: !listReady || listQuery.isLoading,
|
|
9312
|
+
isFetching: !listReady || listQuery.isFetching
|
|
9301
9313
|
},
|
|
9302
9314
|
schema: resolvedSchema,
|
|
9303
9315
|
fields: metadataFields,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as positionActions, i as matchesPosition, n as actionPositionSchema, r as compareOrder, t as ActionPosition } from "./position-DoBV7yB6.cjs";
|
|
2
|
-
import * as
|
|
2
|
+
import * as react_jsx_runtime9 from "react/jsx-runtime";
|
|
3
3
|
import * as React$1 from "react";
|
|
4
4
|
import { ComponentProps, ReactNode } from "react";
|
|
5
5
|
import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
@@ -672,7 +672,7 @@ declare function DataTable<TData>({
|
|
|
672
672
|
className,
|
|
673
673
|
classNames,
|
|
674
674
|
...props
|
|
675
|
-
}: DataTableProps<TData>):
|
|
675
|
+
}: DataTableProps<TData>): react_jsx_runtime9.JSX.Element;
|
|
676
676
|
//#endregion
|
|
677
677
|
//#region src/components/auto-crud/auto-table-action-bar.d.ts
|
|
678
678
|
/** 批量更新字段配置 */
|
|
@@ -761,7 +761,7 @@ declare function AutoTableActionBar<TData>({
|
|
|
761
761
|
extraActions,
|
|
762
762
|
actions,
|
|
763
763
|
deleteConfirmation
|
|
764
|
-
}: AutoTableActionBarProps<TData>):
|
|
764
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime9.JSX.Element;
|
|
765
765
|
//#endregion
|
|
766
766
|
//#region src/lib/schema-bridge/types.d.ts
|
|
767
767
|
/**
|
|
@@ -1099,7 +1099,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1099
1099
|
onSelectedRowsChange,
|
|
1100
1100
|
getSelectedRows,
|
|
1101
1101
|
exportTableRef
|
|
1102
|
-
}: AutoTableProps<T>):
|
|
1102
|
+
}: AutoTableProps<T>): react_jsx_runtime9.JSX.Element;
|
|
1103
1103
|
//#endregion
|
|
1104
1104
|
//#region src/lib/row-action-dialog.d.ts
|
|
1105
1105
|
interface RowActionDialogProps {
|
|
@@ -1562,7 +1562,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1562
1562
|
locale: localeProp,
|
|
1563
1563
|
onCreate,
|
|
1564
1564
|
onExport
|
|
1565
|
-
}: AutoCrudTableProps<TSchema>):
|
|
1565
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime9.JSX.Element;
|
|
1566
1566
|
//#endregion
|
|
1567
1567
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
1568
1568
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -1601,7 +1601,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1601
1601
|
labelAlign,
|
|
1602
1602
|
labelWidth,
|
|
1603
1603
|
showSubmitButton
|
|
1604
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
1604
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime9.JSX.Element;
|
|
1605
1605
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
1606
1606
|
ref?: React.Ref<AutoFormRef>;
|
|
1607
1607
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -1620,7 +1620,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
1620
1620
|
filters: externalFilters,
|
|
1621
1621
|
onFiltersChange,
|
|
1622
1622
|
leading
|
|
1623
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
1623
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime9.JSX.Element | null;
|
|
1624
1624
|
//#endregion
|
|
1625
1625
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
1626
1626
|
type ModalVariant = 'dialog' | 'sheet';
|
|
@@ -1664,7 +1664,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
1664
1664
|
labelAlign,
|
|
1665
1665
|
labelWidth,
|
|
1666
1666
|
className
|
|
1667
|
-
}: CrudFormModalProps<T>):
|
|
1667
|
+
}: CrudFormModalProps<T>): react_jsx_runtime9.JSX.Element;
|
|
1668
1668
|
//#endregion
|
|
1669
1669
|
//#region src/components/auto-crud/import-dialog.d.ts
|
|
1670
1670
|
interface ImportDialogProps {
|
|
@@ -1686,7 +1686,7 @@ declare function ImportDialog({
|
|
|
1686
1686
|
columns,
|
|
1687
1687
|
title,
|
|
1688
1688
|
locale
|
|
1689
|
-
}: ImportDialogProps):
|
|
1689
|
+
}: ImportDialogProps): react_jsx_runtime9.JSX.Element;
|
|
1690
1690
|
//#endregion
|
|
1691
1691
|
//#region src/components/auto-crud/export-dialog.d.ts
|
|
1692
1692
|
type ExportMode = 'selected' | 'filtered';
|
|
@@ -1706,7 +1706,7 @@ declare function ExportDialog({
|
|
|
1706
1706
|
selectedCount,
|
|
1707
1707
|
onExport,
|
|
1708
1708
|
canExportFiltered
|
|
1709
|
-
}: ExportDialogProps):
|
|
1709
|
+
}: ExportDialogProps): react_jsx_runtime9.JSX.Element;
|
|
1710
1710
|
//#endregion
|
|
1711
1711
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
1712
1712
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<'div'> {
|
|
@@ -1717,7 +1717,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
1717
1717
|
children,
|
|
1718
1718
|
className,
|
|
1719
1719
|
...props
|
|
1720
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
1720
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime9.JSX.Element;
|
|
1721
1721
|
//#endregion
|
|
1722
1722
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
1723
1723
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -1729,7 +1729,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
1729
1729
|
label,
|
|
1730
1730
|
className,
|
|
1731
1731
|
...props
|
|
1732
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
1732
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime9.JSX.Element;
|
|
1733
1733
|
//#endregion
|
|
1734
1734
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
1735
1735
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -1743,7 +1743,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
1743
1743
|
title,
|
|
1744
1744
|
options,
|
|
1745
1745
|
multiple
|
|
1746
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
1746
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime9.JSX.Element;
|
|
1747
1747
|
//#endregion
|
|
1748
1748
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
1749
1749
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<'div'>, TablePaginationOptions {
|
|
@@ -1759,7 +1759,7 @@ declare function DataTablePagination<TData>({
|
|
|
1759
1759
|
pageJumpLabel,
|
|
1760
1760
|
className,
|
|
1761
1761
|
...props
|
|
1762
|
-
}: DataTablePaginationProps<TData>):
|
|
1762
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime9.JSX.Element;
|
|
1763
1763
|
//#endregion
|
|
1764
1764
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
1765
1765
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<'div'> {
|
|
@@ -1770,7 +1770,7 @@ declare function DataTableToolbar<TData>({
|
|
|
1770
1770
|
children,
|
|
1771
1771
|
className,
|
|
1772
1772
|
...props
|
|
1773
|
-
}: DataTableToolbarProps<TData>):
|
|
1773
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime9.JSX.Element;
|
|
1774
1774
|
//#endregion
|
|
1775
1775
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
1776
1776
|
interface DataTableViewOptionsProps<TData> extends PopoverContentProps {
|
|
@@ -1783,7 +1783,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
1783
1783
|
disabled,
|
|
1784
1784
|
locale,
|
|
1785
1785
|
...props
|
|
1786
|
-
}: DataTableViewOptionsProps<TData>):
|
|
1786
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime9.JSX.Element;
|
|
1787
1787
|
//#endregion
|
|
1788
1788
|
//#region src/lib/crud-actions.d.ts
|
|
1789
1789
|
type CrudActionZone = 'toolbar' | 'row' | 'batch';
|
package/dist/index.js
CHANGED
|
@@ -8975,7 +8975,8 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
8975
8975
|
useEffect(() => {
|
|
8976
8976
|
hooksRef.current = hooks;
|
|
8977
8977
|
}, [hooks]);
|
|
8978
|
-
const
|
|
8978
|
+
const metadataQuery = router.meta?.useQuery(void 0, { staleTime: 3e4 });
|
|
8979
|
+
const metadata = metadataQuery?.data;
|
|
8979
8980
|
const resolvedSchema = useMemo(() => mergeMetadataSchema(schema, metadata?.schema), [schema, metadata?.schema]);
|
|
8980
8981
|
const defaultSorting = useMemo(() => defaultSortOption === false ? [] : defaultSortOption ?? getDefaultSortingForSchema(resolvedSchema), [defaultSortOption, resolvedSchema]);
|
|
8981
8982
|
const metadataFields = useMemo(() => readMetadataFields(metadata?.fields), [metadata?.fields]);
|
|
@@ -8996,6 +8997,10 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
8996
8997
|
search: parseAsString.withDefault("")
|
|
8997
8998
|
}, { shallow: false });
|
|
8998
8999
|
const [filters] = useReadableFilters(columns, { shallow: false });
|
|
9000
|
+
const metadataPending = Boolean(metadataQuery?.isPending);
|
|
9001
|
+
const [filtersReady, setFiltersReady] = useState(!metadataPending);
|
|
9002
|
+
useEffect(() => setFiltersReady(!metadataPending), [metadataPending]);
|
|
9003
|
+
const listReady = !metadataPending && filtersReady;
|
|
8999
9004
|
const queryInput = useMemo(() => {
|
|
9000
9005
|
const autoParams = {
|
|
9001
9006
|
page: urlParams.page,
|
|
@@ -9011,11 +9016,17 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
9011
9016
|
filters,
|
|
9012
9017
|
queryTransform
|
|
9013
9018
|
]);
|
|
9019
|
+
const hasReadyListData = useRef(false);
|
|
9014
9020
|
const listQuery = router.list.useQuery(queryInput, {
|
|
9015
|
-
|
|
9021
|
+
enabled: listReady,
|
|
9022
|
+
placeholderData: hasReadyListData.current ? keepPreviousData : void 0,
|
|
9016
9023
|
staleTime: 0
|
|
9017
9024
|
});
|
|
9018
|
-
|
|
9025
|
+
useEffect(() => {
|
|
9026
|
+
if (listReady && listQuery.data !== void 0) hasReadyListData.current = true;
|
|
9027
|
+
}, [listReady, listQuery.data]);
|
|
9028
|
+
const listData = listReady ? listQuery.data : void 0;
|
|
9029
|
+
const tableRows = listData?.data ?? [];
|
|
9019
9030
|
const createMutation = router.create.useMutation();
|
|
9020
9031
|
const updateMutation = router.update.useMutation();
|
|
9021
9032
|
const deleteMutation = router.delete.useMutation();
|
|
@@ -9273,16 +9284,17 @@ function useAutoCrudResource({ router, schema, query: queryTransform, fields, op
|
|
|
9273
9284
|
]);
|
|
9274
9285
|
const canExport = !!(exportFetcher || exportQuery);
|
|
9275
9286
|
const refresh = useCallback(async () => {
|
|
9287
|
+
if (!listReady) return;
|
|
9276
9288
|
return listQuery.refetch();
|
|
9277
|
-
}, [listQuery]);
|
|
9289
|
+
}, [listQuery, listReady]);
|
|
9278
9290
|
return {
|
|
9279
9291
|
idKey,
|
|
9280
9292
|
tableData: {
|
|
9281
9293
|
data: tableRows,
|
|
9282
|
-
pageCount:
|
|
9283
|
-
...typeof
|
|
9284
|
-
isLoading: listQuery.isLoading,
|
|
9285
|
-
isFetching: listQuery.isFetching
|
|
9294
|
+
pageCount: listData?.pageCount ?? 0,
|
|
9295
|
+
...typeof listData?.total === "number" ? { total: listData.total } : {},
|
|
9296
|
+
isLoading: !listReady || listQuery.isLoading,
|
|
9297
|
+
isFetching: !listReady || listQuery.isFetching
|
|
9286
9298
|
},
|
|
9287
9299
|
schema: resolvedSchema,
|
|
9288
9300
|
fields: metadataFields,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.12.
|
|
4
|
+
"version": "1.12.1",
|
|
5
5
|
"description": "Schema-first CRUD components with auto-generated tables and forms",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -95,10 +95,10 @@
|
|
|
95
95
|
"typescript": "^5.9.3",
|
|
96
96
|
"vitest": "^3.2.4",
|
|
97
97
|
"@internal/eslint-config": "0.3.0",
|
|
98
|
-
"@internal/prettier-config": "0.0.1",
|
|
99
|
-
"@internal/tsdown-config": "0.1.0",
|
|
100
98
|
"@internal/tsconfig": "0.1.0",
|
|
101
|
-
"@internal/
|
|
99
|
+
"@internal/tsdown-config": "0.1.0",
|
|
100
|
+
"@internal/vitest-config": "0.1.0",
|
|
101
|
+
"@internal/prettier-config": "0.0.1"
|
|
102
102
|
},
|
|
103
103
|
"prettier": "@internal/prettier-config",
|
|
104
104
|
"scripts": {
|