@wordrhyme/auto-crud 1.21.1 → 1.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -18
- package/dist/index.js +35 -18
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1747,6 +1747,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1747
1747
|
data,
|
|
1748
1748
|
counts
|
|
1749
1749
|
});
|
|
1750
|
+
const refreshPending = (0, react.useRef)(false);
|
|
1750
1751
|
const refetchCounts = totals.refetch;
|
|
1751
1752
|
(0, react.useEffect)(() => {
|
|
1752
1753
|
const previous = previousSource.current;
|
|
@@ -1754,21 +1755,17 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1754
1755
|
data,
|
|
1755
1756
|
counts
|
|
1756
1757
|
};
|
|
1757
|
-
if (previous.data
|
|
1758
|
-
if (counts
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
resourceId
|
|
1762
|
-
] }).then(() => refetchCounts());
|
|
1758
|
+
if (previous.data !== data || previous.counts !== counts) refreshPending.current = true;
|
|
1759
|
+
if (!counts || !ready || !fieldsReady || totals.fetchStatus !== "idle" || !refreshPending.current) return;
|
|
1760
|
+
refreshPending.current = false;
|
|
1761
|
+
refetchCounts({ cancelRefetch: false });
|
|
1763
1762
|
}, [
|
|
1764
1763
|
data,
|
|
1765
1764
|
counts,
|
|
1766
1765
|
ready,
|
|
1767
1766
|
fieldsReady,
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
config.cacheKey,
|
|
1771
|
-
resourceId
|
|
1767
|
+
totals.fetchStatus,
|
|
1768
|
+
refetchCounts
|
|
1772
1769
|
]);
|
|
1773
1770
|
const renderCount = (key) => {
|
|
1774
1771
|
if (!counts) return null;
|
|
@@ -1794,8 +1791,16 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1794
1791
|
const [orderedViews, setOrderedViews] = (0, react.useState)([]);
|
|
1795
1792
|
const [error, setError] = (0, react.useState)(null);
|
|
1796
1793
|
const [search, setSearch] = (0, react.useState)(() => getUrlParams().toString());
|
|
1794
|
+
const defaultPending = (0, react.useRef)(search === "");
|
|
1795
|
+
const onInteract = () => {
|
|
1796
|
+
defaultPending.current = false;
|
|
1797
|
+
};
|
|
1797
1798
|
(0, react.useEffect)(() => {
|
|
1798
|
-
const update = () =>
|
|
1799
|
+
const update = (event) => {
|
|
1800
|
+
const next = getUrlParams().toString();
|
|
1801
|
+
if (next !== "" || event.type === "popstate") defaultPending.current = false;
|
|
1802
|
+
setSearch(next);
|
|
1803
|
+
};
|
|
1799
1804
|
window.addEventListener("urlchange", update);
|
|
1800
1805
|
window.addEventListener("popstate", update);
|
|
1801
1806
|
return () => {
|
|
@@ -1878,16 +1883,18 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1878
1883
|
if (!ready || !fieldsReady || preferences === void 0) return;
|
|
1879
1884
|
const first = !preferencesRestored.current;
|
|
1880
1885
|
const urlReference = getUrlParams().get(viewKey);
|
|
1881
|
-
|
|
1886
|
+
const lateDefault = !first && defaultPending.current && preferencesRef.current === null && getUrlParams().toString() === "" && !!defaultView && viewItems.some((view) => view.id === defaultView || view.slug === defaultView);
|
|
1887
|
+
if (!first && !lateDefault && urlReference === lastViewParam.current && (selectedId !== null || !viewItems.some((view) => view.id === urlReference || view.slug === urlReference))) return;
|
|
1882
1888
|
const savedViews = viewItems;
|
|
1883
1889
|
let cancelled = false;
|
|
1884
1890
|
queueMicrotask(() => {
|
|
1885
1891
|
if (cancelled) return;
|
|
1892
|
+
if (lateDefault && (!defaultPending.current || preferencesRef.current !== null || getUrlParams().toString() !== "")) return;
|
|
1886
1893
|
preferencesRestored.current = true;
|
|
1887
1894
|
lastViewParam.current = urlReference;
|
|
1888
1895
|
const storedPreferences = preferencesRef.current;
|
|
1889
1896
|
let reference = urlReference;
|
|
1890
|
-
if (first && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1897
|
+
if ((first || lateDefault) && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1891
1898
|
if (reference === null || reference === "") {
|
|
1892
1899
|
setSelected(null);
|
|
1893
1900
|
setError(null);
|
|
@@ -1917,6 +1924,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1917
1924
|
setSearchParams(params, { history: "replace" });
|
|
1918
1925
|
}
|
|
1919
1926
|
setSelected(view);
|
|
1927
|
+
defaultPending.current = false;
|
|
1920
1928
|
savePreferences({
|
|
1921
1929
|
selector: display,
|
|
1922
1930
|
viewId: view.id
|
|
@@ -2281,7 +2289,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
2281
2289
|
})]
|
|
2282
2290
|
})
|
|
2283
2291
|
]
|
|
2284
|
-
}), display), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Dialog, {
|
|
2292
|
+
}), display, onInteract), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Dialog, {
|
|
2285
2293
|
open: dialog !== null,
|
|
2286
2294
|
onOpenChange: (isOpen) => {
|
|
2287
2295
|
if (!isOpen && !mutation.isPending) setDialog(null);
|
|
@@ -7998,8 +8006,12 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
7998
8006
|
filterState,
|
|
7999
8007
|
renderFilterValue
|
|
8000
8008
|
]);
|
|
8001
|
-
const renderToolbar = (viewSelector) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8009
|
+
const renderToolbar = (viewSelector, onInteract) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8002
8010
|
className: "flex w-full items-start justify-between gap-2 p-1",
|
|
8011
|
+
onPointerDownCapture: onInteract,
|
|
8012
|
+
onClickCapture: onInteract,
|
|
8013
|
+
onKeyDownCapture: onInteract,
|
|
8014
|
+
onChangeCapture: onInteract,
|
|
8003
8015
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
8004
8016
|
className: "flex min-h-[40px] min-w-0 flex-1 items-start gap-2",
|
|
8005
8017
|
"data-filter-parent": true,
|
|
@@ -8074,10 +8086,14 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
8074
8086
|
resourceId: activeResourceId,
|
|
8075
8087
|
table,
|
|
8076
8088
|
onApply: clearBatchSearch,
|
|
8077
|
-
children: (controls, display) => display === "tabs" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8089
|
+
children: (controls, display, onInteract) => display === "tabs" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8078
8090
|
className: "space-y-2",
|
|
8091
|
+
onPointerDownCapture: onInteract,
|
|
8092
|
+
onClickCapture: onInteract,
|
|
8093
|
+
onKeyDownCapture: onInteract,
|
|
8094
|
+
onChangeCapture: onInteract,
|
|
8079
8095
|
children: [controls, renderToolbar()]
|
|
8080
|
-
}) : renderToolbar(controls)
|
|
8096
|
+
}) : renderToolbar(controls, onInteract)
|
|
8081
8097
|
}) : renderToolbar(),
|
|
8082
8098
|
tableContent,
|
|
8083
8099
|
enableRowSelection && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoTableActionBar, {
|
|
@@ -11835,6 +11851,7 @@ const defaultToastAdapter = {
|
|
|
11835
11851
|
info: sonner.toast.info,
|
|
11836
11852
|
warning: sonner.toast.warning
|
|
11837
11853
|
};
|
|
11854
|
+
const EMPTY_ROWS = [];
|
|
11838
11855
|
/** 空 toast 适配器(禁用通知) */
|
|
11839
11856
|
const noopToastAdapter = {
|
|
11840
11857
|
success: () => {},
|
|
@@ -12028,7 +12045,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12028
12045
|
if (listReady && listQuery.data !== void 0) hasReadyListData.current = true;
|
|
12029
12046
|
}, [listReady, listQuery.data]);
|
|
12030
12047
|
const listData = listReady ? listQuery.data : void 0;
|
|
12031
|
-
const tableRows = listData?.data ??
|
|
12048
|
+
const tableRows = listData?.data ?? EMPTY_ROWS;
|
|
12032
12049
|
const createMutation = router.create.useMutation();
|
|
12033
12050
|
const updateMutation = router.update.useMutation();
|
|
12034
12051
|
const deleteMutation = router.delete.useMutation();
|
package/dist/index.js
CHANGED
|
@@ -1731,6 +1731,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1731
1731
|
data,
|
|
1732
1732
|
counts
|
|
1733
1733
|
});
|
|
1734
|
+
const refreshPending = useRef(false);
|
|
1734
1735
|
const refetchCounts = totals.refetch;
|
|
1735
1736
|
useEffect(() => {
|
|
1736
1737
|
const previous = previousSource.current;
|
|
@@ -1738,21 +1739,17 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1738
1739
|
data,
|
|
1739
1740
|
counts
|
|
1740
1741
|
};
|
|
1741
|
-
if (previous.data
|
|
1742
|
-
if (counts
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
resourceId
|
|
1746
|
-
] }).then(() => refetchCounts());
|
|
1742
|
+
if (previous.data !== data || previous.counts !== counts) refreshPending.current = true;
|
|
1743
|
+
if (!counts || !ready || !fieldsReady || totals.fetchStatus !== "idle" || !refreshPending.current) return;
|
|
1744
|
+
refreshPending.current = false;
|
|
1745
|
+
refetchCounts({ cancelRefetch: false });
|
|
1747
1746
|
}, [
|
|
1748
1747
|
data,
|
|
1749
1748
|
counts,
|
|
1750
1749
|
ready,
|
|
1751
1750
|
fieldsReady,
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
config.cacheKey,
|
|
1755
|
-
resourceId
|
|
1751
|
+
totals.fetchStatus,
|
|
1752
|
+
refetchCounts
|
|
1756
1753
|
]);
|
|
1757
1754
|
const renderCount = (key) => {
|
|
1758
1755
|
if (!counts) return null;
|
|
@@ -1778,8 +1775,16 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1778
1775
|
const [orderedViews, setOrderedViews] = useState([]);
|
|
1779
1776
|
const [error, setError] = useState(null);
|
|
1780
1777
|
const [search, setSearch] = useState(() => getUrlParams().toString());
|
|
1778
|
+
const defaultPending = useRef(search === "");
|
|
1779
|
+
const onInteract = () => {
|
|
1780
|
+
defaultPending.current = false;
|
|
1781
|
+
};
|
|
1781
1782
|
useEffect(() => {
|
|
1782
|
-
const update = () =>
|
|
1783
|
+
const update = (event) => {
|
|
1784
|
+
const next = getUrlParams().toString();
|
|
1785
|
+
if (next !== "" || event.type === "popstate") defaultPending.current = false;
|
|
1786
|
+
setSearch(next);
|
|
1787
|
+
};
|
|
1783
1788
|
window.addEventListener("urlchange", update);
|
|
1784
1789
|
window.addEventListener("popstate", update);
|
|
1785
1790
|
return () => {
|
|
@@ -1862,16 +1867,18 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1862
1867
|
if (!ready || !fieldsReady || preferences === void 0) return;
|
|
1863
1868
|
const first = !preferencesRestored.current;
|
|
1864
1869
|
const urlReference = getUrlParams().get(viewKey);
|
|
1865
|
-
|
|
1870
|
+
const lateDefault = !first && defaultPending.current && preferencesRef.current === null && getUrlParams().toString() === "" && !!defaultView && viewItems.some((view) => view.id === defaultView || view.slug === defaultView);
|
|
1871
|
+
if (!first && !lateDefault && urlReference === lastViewParam.current && (selectedId !== null || !viewItems.some((view) => view.id === urlReference || view.slug === urlReference))) return;
|
|
1866
1872
|
const savedViews = viewItems;
|
|
1867
1873
|
let cancelled = false;
|
|
1868
1874
|
queueMicrotask(() => {
|
|
1869
1875
|
if (cancelled) return;
|
|
1876
|
+
if (lateDefault && (!defaultPending.current || preferencesRef.current !== null || getUrlParams().toString() !== "")) return;
|
|
1870
1877
|
preferencesRestored.current = true;
|
|
1871
1878
|
lastViewParam.current = urlReference;
|
|
1872
1879
|
const storedPreferences = preferencesRef.current;
|
|
1873
1880
|
let reference = urlReference;
|
|
1874
|
-
if (first && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1881
|
+
if ((first || lateDefault) && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1875
1882
|
if (reference === null || reference === "") {
|
|
1876
1883
|
setSelected(null);
|
|
1877
1884
|
setError(null);
|
|
@@ -1901,6 +1908,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1901
1908
|
setSearchParams(params, { history: "replace" });
|
|
1902
1909
|
}
|
|
1903
1910
|
setSelected(view);
|
|
1911
|
+
defaultPending.current = false;
|
|
1904
1912
|
savePreferences({
|
|
1905
1913
|
selector: display,
|
|
1906
1914
|
viewId: view.id
|
|
@@ -2265,7 +2273,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
2265
2273
|
})]
|
|
2266
2274
|
})
|
|
2267
2275
|
]
|
|
2268
|
-
}), display), /* @__PURE__ */ jsx(Dialog, {
|
|
2276
|
+
}), display, onInteract), /* @__PURE__ */ jsx(Dialog, {
|
|
2269
2277
|
open: dialog !== null,
|
|
2270
2278
|
onOpenChange: (isOpen) => {
|
|
2271
2279
|
if (!isOpen && !mutation.isPending) setDialog(null);
|
|
@@ -7982,8 +7990,12 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
7982
7990
|
filterState,
|
|
7983
7991
|
renderFilterValue
|
|
7984
7992
|
]);
|
|
7985
|
-
const renderToolbar = (viewSelector) => /* @__PURE__ */ jsxs("div", {
|
|
7993
|
+
const renderToolbar = (viewSelector, onInteract) => /* @__PURE__ */ jsxs("div", {
|
|
7986
7994
|
className: "flex w-full items-start justify-between gap-2 p-1",
|
|
7995
|
+
onPointerDownCapture: onInteract,
|
|
7996
|
+
onClickCapture: onInteract,
|
|
7997
|
+
onKeyDownCapture: onInteract,
|
|
7998
|
+
onChangeCapture: onInteract,
|
|
7987
7999
|
children: [/* @__PURE__ */ jsx("div", {
|
|
7988
8000
|
className: "flex min-h-[40px] min-w-0 flex-1 items-start gap-2",
|
|
7989
8001
|
"data-filter-parent": true,
|
|
@@ -8058,10 +8070,14 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
8058
8070
|
resourceId: activeResourceId,
|
|
8059
8071
|
table,
|
|
8060
8072
|
onApply: clearBatchSearch,
|
|
8061
|
-
children: (controls, display) => display === "tabs" ? /* @__PURE__ */ jsxs("div", {
|
|
8073
|
+
children: (controls, display, onInteract) => display === "tabs" ? /* @__PURE__ */ jsxs("div", {
|
|
8062
8074
|
className: "space-y-2",
|
|
8075
|
+
onPointerDownCapture: onInteract,
|
|
8076
|
+
onClickCapture: onInteract,
|
|
8077
|
+
onKeyDownCapture: onInteract,
|
|
8078
|
+
onChangeCapture: onInteract,
|
|
8063
8079
|
children: [controls, renderToolbar()]
|
|
8064
|
-
}) : renderToolbar(controls)
|
|
8080
|
+
}) : renderToolbar(controls, onInteract)
|
|
8065
8081
|
}) : renderToolbar(),
|
|
8066
8082
|
tableContent,
|
|
8067
8083
|
enableRowSelection && /* @__PURE__ */ jsx(AutoTableActionBar, {
|
|
@@ -11819,6 +11835,7 @@ const defaultToastAdapter = {
|
|
|
11819
11835
|
info: toast.info,
|
|
11820
11836
|
warning: toast.warning
|
|
11821
11837
|
};
|
|
11838
|
+
const EMPTY_ROWS = [];
|
|
11822
11839
|
/** 空 toast 适配器(禁用通知) */
|
|
11823
11840
|
const noopToastAdapter = {
|
|
11824
11841
|
success: () => {},
|
|
@@ -12012,7 +12029,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
12012
12029
|
if (listReady && listQuery.data !== void 0) hasReadyListData.current = true;
|
|
12013
12030
|
}, [listReady, listQuery.data]);
|
|
12014
12031
|
const listData = listReady ? listQuery.data : void 0;
|
|
12015
|
-
const tableRows = listData?.data ??
|
|
12032
|
+
const tableRows = listData?.data ?? EMPTY_ROWS;
|
|
12016
12033
|
const createMutation = router.create.useMutation();
|
|
12017
12034
|
const updateMutation = router.update.useMutation();
|
|
12018
12035
|
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.21.
|
|
4
|
+
"version": "1.21.3",
|
|
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/formily-shadcn": "2.1.3",
|
|
75
74
|
"@wordrhyme/shadcn": "2.0.2",
|
|
76
|
-
"@wordrhyme/shadcn-ui": "2.1.3"
|
|
75
|
+
"@wordrhyme/shadcn-ui": "2.1.3",
|
|
76
|
+
"@wordrhyme/formily-shadcn": "2.1.3"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@storybook/react": "^8.6.18",
|
|
@@ -94,11 +94,11 @@
|
|
|
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/tsdown-config": "0.1.0",
|
|
101
|
-
"@internal/vitest-config": "0.1.0"
|
|
100
|
+
"@internal/vitest-config": "0.1.0",
|
|
101
|
+
"@internal/tsconfig": "0.1.0"
|
|
102
102
|
},
|
|
103
103
|
"prettier": "@internal/prettier-config",
|
|
104
104
|
"scripts": {
|