@wordrhyme/auto-crud 1.21.0 → 1.21.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 +5 -0
- package/dist/index.cjs +27 -8
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1814,6 +1814,11 @@ This provides a real **separate single-row** TanStack context, not the original
|
|
|
1814
1814
|
list's pagination, selection or row index. Reused custom cells retain their own
|
|
1815
1815
|
truncation and interaction behavior.
|
|
1816
1816
|
|
|
1817
|
+
When `fields[field].table.component` declares a component and the caller resolves it
|
|
1818
|
+
into a `table.overrides[field].cell`, that cell is preserved alongside `display`,
|
|
1819
|
+
`options` and `dataSource`. Without a resolved cell, default presentation still
|
|
1820
|
+
applies. Fields without `table.component` keep their existing presentation priority.
|
|
1821
|
+
|
|
1817
1822
|
### 状态徽标颜色
|
|
1818
1823
|
|
|
1819
1824
|
对于 `table.display: "badge"`,标量字段的 `table.options` 可设置 `badgeTone`,支持 `neutral`、`success`、`warning`、`info`。徽标保留文字标签并附带装饰圆点,未配置颜色时沿用原有徽标样式,纯文本展示不受影响。业务状态与颜色的对应关系由调用方配置。
|
package/dist/index.cjs
CHANGED
|
@@ -1794,8 +1794,16 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1794
1794
|
const [orderedViews, setOrderedViews] = (0, react.useState)([]);
|
|
1795
1795
|
const [error, setError] = (0, react.useState)(null);
|
|
1796
1796
|
const [search, setSearch] = (0, react.useState)(() => getUrlParams().toString());
|
|
1797
|
+
const defaultPending = (0, react.useRef)(search === "");
|
|
1798
|
+
const onInteract = () => {
|
|
1799
|
+
defaultPending.current = false;
|
|
1800
|
+
};
|
|
1797
1801
|
(0, react.useEffect)(() => {
|
|
1798
|
-
const update = () =>
|
|
1802
|
+
const update = (event) => {
|
|
1803
|
+
const next = getUrlParams().toString();
|
|
1804
|
+
if (next !== "" || event.type === "popstate") defaultPending.current = false;
|
|
1805
|
+
setSearch(next);
|
|
1806
|
+
};
|
|
1799
1807
|
window.addEventListener("urlchange", update);
|
|
1800
1808
|
window.addEventListener("popstate", update);
|
|
1801
1809
|
return () => {
|
|
@@ -1878,16 +1886,18 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1878
1886
|
if (!ready || !fieldsReady || preferences === void 0) return;
|
|
1879
1887
|
const first = !preferencesRestored.current;
|
|
1880
1888
|
const urlReference = getUrlParams().get(viewKey);
|
|
1881
|
-
|
|
1889
|
+
const lateDefault = !first && defaultPending.current && preferencesRef.current === null && getUrlParams().toString() === "" && !!defaultView && viewItems.some((view) => view.id === defaultView || view.slug === defaultView);
|
|
1890
|
+
if (!first && !lateDefault && urlReference === lastViewParam.current && (selectedId !== null || !viewItems.some((view) => view.id === urlReference || view.slug === urlReference))) return;
|
|
1882
1891
|
const savedViews = viewItems;
|
|
1883
1892
|
let cancelled = false;
|
|
1884
1893
|
queueMicrotask(() => {
|
|
1885
1894
|
if (cancelled) return;
|
|
1895
|
+
if (lateDefault && (!defaultPending.current || preferencesRef.current !== null || getUrlParams().toString() !== "")) return;
|
|
1886
1896
|
preferencesRestored.current = true;
|
|
1887
1897
|
lastViewParam.current = urlReference;
|
|
1888
1898
|
const storedPreferences = preferencesRef.current;
|
|
1889
1899
|
let reference = urlReference;
|
|
1890
|
-
if (first && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1900
|
+
if ((first || lateDefault) && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1891
1901
|
if (reference === null || reference === "") {
|
|
1892
1902
|
setSelected(null);
|
|
1893
1903
|
setError(null);
|
|
@@ -1917,6 +1927,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1917
1927
|
setSearchParams(params, { history: "replace" });
|
|
1918
1928
|
}
|
|
1919
1929
|
setSelected(view);
|
|
1930
|
+
defaultPending.current = false;
|
|
1920
1931
|
savePreferences({
|
|
1921
1932
|
selector: display,
|
|
1922
1933
|
viewId: view.id
|
|
@@ -2281,7 +2292,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
2281
2292
|
})]
|
|
2282
2293
|
})
|
|
2283
2294
|
]
|
|
2284
|
-
}), display), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Dialog, {
|
|
2295
|
+
}), display, onInteract), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Dialog, {
|
|
2285
2296
|
open: dialog !== null,
|
|
2286
2297
|
onOpenChange: (isOpen) => {
|
|
2287
2298
|
if (!isOpen && !mutation.isPending) setDialog(null);
|
|
@@ -7998,8 +8009,12 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
7998
8009
|
filterState,
|
|
7999
8010
|
renderFilterValue
|
|
8000
8011
|
]);
|
|
8001
|
-
const renderToolbar = (viewSelector) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8012
|
+
const renderToolbar = (viewSelector, onInteract) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8002
8013
|
className: "flex w-full items-start justify-between gap-2 p-1",
|
|
8014
|
+
onPointerDownCapture: onInteract,
|
|
8015
|
+
onClickCapture: onInteract,
|
|
8016
|
+
onKeyDownCapture: onInteract,
|
|
8017
|
+
onChangeCapture: onInteract,
|
|
8003
8018
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
8004
8019
|
className: "flex min-h-[40px] min-w-0 flex-1 items-start gap-2",
|
|
8005
8020
|
"data-filter-parent": true,
|
|
@@ -8074,10 +8089,14 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
8074
8089
|
resourceId: activeResourceId,
|
|
8075
8090
|
table,
|
|
8076
8091
|
onApply: clearBatchSearch,
|
|
8077
|
-
children: (controls, display) => display === "tabs" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8092
|
+
children: (controls, display, onInteract) => display === "tabs" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
8078
8093
|
className: "space-y-2",
|
|
8094
|
+
onPointerDownCapture: onInteract,
|
|
8095
|
+
onClickCapture: onInteract,
|
|
8096
|
+
onKeyDownCapture: onInteract,
|
|
8097
|
+
onChangeCapture: onInteract,
|
|
8079
8098
|
children: [controls, renderToolbar()]
|
|
8080
|
-
}) : renderToolbar(controls)
|
|
8099
|
+
}) : renderToolbar(controls, onInteract)
|
|
8081
8100
|
}) : renderToolbar(),
|
|
8082
8101
|
tableContent,
|
|
8083
8102
|
enableRowSelection && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AutoTableActionBar, {
|
|
@@ -10194,7 +10213,7 @@ function buildTableOverrides(fields, legacyOverrides, dynamicFilterState, dynami
|
|
|
10194
10213
|
...tableProps
|
|
10195
10214
|
};
|
|
10196
10215
|
const hasTableLabels = config.table.options !== void 0 || config.table.dataSource !== void 0;
|
|
10197
|
-
if (display && display !== "auto" || hasTableLabels) {
|
|
10216
|
+
if (!(typeof config.table.component === "string" && result[key]?.cell !== void 0) && (display && display !== "auto" || hasTableLabels)) {
|
|
10198
10217
|
const options = tableConfig?.dataSource ? mergeFieldOptions(dynamicResolveOptions, presentationOptions) : presentationOptions ?? mergedSharedDynamicOptions;
|
|
10199
10218
|
result[key] = {
|
|
10200
10219
|
...result[key],
|
package/dist/index.d.cts
CHANGED
|
@@ -1880,7 +1880,7 @@ interface Field {
|
|
|
1880
1880
|
options?: FieldOption[];
|
|
1881
1881
|
/** 仅用于表格展示的动态值标签源 */
|
|
1882
1882
|
dataSource?: AutoCrudDataSourceConfig;
|
|
1883
|
-
/**
|
|
1883
|
+
/** 声明式展示模式;覆盖普通 cell,保留调用方已解析的 table.component 单元格 */
|
|
1884
1884
|
display?: FieldTableDisplay;
|
|
1885
1885
|
/** 该列的类名;th 应用于表头,td 应用于正文单元格 */
|
|
1886
1886
|
classNames?: ColumnMeta<unknown, unknown>['classNames'];
|
package/dist/index.d.ts
CHANGED
|
@@ -1880,7 +1880,7 @@ interface Field {
|
|
|
1880
1880
|
options?: FieldOption[];
|
|
1881
1881
|
/** 仅用于表格展示的动态值标签源 */
|
|
1882
1882
|
dataSource?: AutoCrudDataSourceConfig;
|
|
1883
|
-
/**
|
|
1883
|
+
/** 声明式展示模式;覆盖普通 cell,保留调用方已解析的 table.component 单元格 */
|
|
1884
1884
|
display?: FieldTableDisplay;
|
|
1885
1885
|
/** 该列的类名;th 应用于表头,td 应用于正文单元格 */
|
|
1886
1886
|
classNames?: ColumnMeta<unknown, unknown>['classNames'];
|
package/dist/index.js
CHANGED
|
@@ -1778,8 +1778,16 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1778
1778
|
const [orderedViews, setOrderedViews] = useState([]);
|
|
1779
1779
|
const [error, setError] = useState(null);
|
|
1780
1780
|
const [search, setSearch] = useState(() => getUrlParams().toString());
|
|
1781
|
+
const defaultPending = useRef(search === "");
|
|
1782
|
+
const onInteract = () => {
|
|
1783
|
+
defaultPending.current = false;
|
|
1784
|
+
};
|
|
1781
1785
|
useEffect(() => {
|
|
1782
|
-
const update = () =>
|
|
1786
|
+
const update = (event) => {
|
|
1787
|
+
const next = getUrlParams().toString();
|
|
1788
|
+
if (next !== "" || event.type === "popstate") defaultPending.current = false;
|
|
1789
|
+
setSearch(next);
|
|
1790
|
+
};
|
|
1783
1791
|
window.addEventListener("urlchange", update);
|
|
1784
1792
|
window.addEventListener("popstate", update);
|
|
1785
1793
|
return () => {
|
|
@@ -1862,16 +1870,18 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1862
1870
|
if (!ready || !fieldsReady || preferences === void 0) return;
|
|
1863
1871
|
const first = !preferencesRestored.current;
|
|
1864
1872
|
const urlReference = getUrlParams().get(viewKey);
|
|
1865
|
-
|
|
1873
|
+
const lateDefault = !first && defaultPending.current && preferencesRef.current === null && getUrlParams().toString() === "" && !!defaultView && viewItems.some((view) => view.id === defaultView || view.slug === defaultView);
|
|
1874
|
+
if (!first && !lateDefault && urlReference === lastViewParam.current && (selectedId !== null || !viewItems.some((view) => view.id === urlReference || view.slug === urlReference))) return;
|
|
1866
1875
|
const savedViews = viewItems;
|
|
1867
1876
|
let cancelled = false;
|
|
1868
1877
|
queueMicrotask(() => {
|
|
1869
1878
|
if (cancelled) return;
|
|
1879
|
+
if (lateDefault && (!defaultPending.current || preferencesRef.current !== null || getUrlParams().toString() !== "")) return;
|
|
1870
1880
|
preferencesRestored.current = true;
|
|
1871
1881
|
lastViewParam.current = urlReference;
|
|
1872
1882
|
const storedPreferences = preferencesRef.current;
|
|
1873
1883
|
let reference = urlReference;
|
|
1874
|
-
if (first && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1884
|
+
if ((first || lateDefault) && urlReference === null) reference = storedPreferences ? storedPreferences.viewId : defaultView ?? null;
|
|
1875
1885
|
if (reference === null || reference === "") {
|
|
1876
1886
|
setSelected(null);
|
|
1877
1887
|
setError(null);
|
|
@@ -1901,6 +1911,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
1901
1911
|
setSearchParams(params, { history: "replace" });
|
|
1902
1912
|
}
|
|
1903
1913
|
setSelected(view);
|
|
1914
|
+
defaultPending.current = false;
|
|
1904
1915
|
savePreferences({
|
|
1905
1916
|
selector: display,
|
|
1906
1917
|
viewId: view.id
|
|
@@ -2265,7 +2276,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
|
|
|
2265
2276
|
})]
|
|
2266
2277
|
})
|
|
2267
2278
|
]
|
|
2268
|
-
}), display), /* @__PURE__ */ jsx(Dialog, {
|
|
2279
|
+
}), display, onInteract), /* @__PURE__ */ jsx(Dialog, {
|
|
2269
2280
|
open: dialog !== null,
|
|
2270
2281
|
onOpenChange: (isOpen) => {
|
|
2271
2282
|
if (!isOpen && !mutation.isPending) setDialog(null);
|
|
@@ -7982,8 +7993,12 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
7982
7993
|
filterState,
|
|
7983
7994
|
renderFilterValue
|
|
7984
7995
|
]);
|
|
7985
|
-
const renderToolbar = (viewSelector) => /* @__PURE__ */ jsxs("div", {
|
|
7996
|
+
const renderToolbar = (viewSelector, onInteract) => /* @__PURE__ */ jsxs("div", {
|
|
7986
7997
|
className: "flex w-full items-start justify-between gap-2 p-1",
|
|
7998
|
+
onPointerDownCapture: onInteract,
|
|
7999
|
+
onClickCapture: onInteract,
|
|
8000
|
+
onKeyDownCapture: onInteract,
|
|
8001
|
+
onChangeCapture: onInteract,
|
|
7987
8002
|
children: [/* @__PURE__ */ jsx("div", {
|
|
7988
8003
|
className: "flex min-h-[40px] min-w-0 flex-1 items-start gap-2",
|
|
7989
8004
|
"data-filter-parent": true,
|
|
@@ -8058,10 +8073,14 @@ function AutoTable({ resourceId, views, schema, data, getRowId, expandedRow, def
|
|
|
8058
8073
|
resourceId: activeResourceId,
|
|
8059
8074
|
table,
|
|
8060
8075
|
onApply: clearBatchSearch,
|
|
8061
|
-
children: (controls, display) => display === "tabs" ? /* @__PURE__ */ jsxs("div", {
|
|
8076
|
+
children: (controls, display, onInteract) => display === "tabs" ? /* @__PURE__ */ jsxs("div", {
|
|
8062
8077
|
className: "space-y-2",
|
|
8078
|
+
onPointerDownCapture: onInteract,
|
|
8079
|
+
onClickCapture: onInteract,
|
|
8080
|
+
onKeyDownCapture: onInteract,
|
|
8081
|
+
onChangeCapture: onInteract,
|
|
8063
8082
|
children: [controls, renderToolbar()]
|
|
8064
|
-
}) : renderToolbar(controls)
|
|
8083
|
+
}) : renderToolbar(controls, onInteract)
|
|
8065
8084
|
}) : renderToolbar(),
|
|
8066
8085
|
tableContent,
|
|
8067
8086
|
enableRowSelection && /* @__PURE__ */ jsx(AutoTableActionBar, {
|
|
@@ -10178,7 +10197,7 @@ function buildTableOverrides(fields, legacyOverrides, dynamicFilterState, dynami
|
|
|
10178
10197
|
...tableProps
|
|
10179
10198
|
};
|
|
10180
10199
|
const hasTableLabels = config.table.options !== void 0 || config.table.dataSource !== void 0;
|
|
10181
|
-
if (display && display !== "auto" || hasTableLabels) {
|
|
10200
|
+
if (!(typeof config.table.component === "string" && result[key]?.cell !== void 0) && (display && display !== "auto" || hasTableLabels)) {
|
|
10182
10201
|
const options = tableConfig?.dataSource ? mergeFieldOptions(dynamicResolveOptions, presentationOptions) : presentationOptions ?? mergedSharedDynamicOptions;
|
|
10183
10202
|
result[key] = {
|
|
10184
10203
|
...result[key],
|
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.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/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",
|
|
@@ -95,10 +95,10 @@
|
|
|
95
95
|
"typescript": "^5.9.3",
|
|
96
96
|
"vitest": "^3.2.4",
|
|
97
97
|
"@internal/prettier-config": "0.0.1",
|
|
98
|
-
"@internal/eslint-config": "0.3.0",
|
|
99
98
|
"@internal/tsconfig": "0.1.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/eslint-config": "0.3.0"
|
|
102
102
|
},
|
|
103
103
|
"prettier": "@internal/prettier-config",
|
|
104
104
|
"scripts": {
|