@wordrhyme/auto-crud 1.10.0 → 1.11.0
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 +9 -3
- package/dist/index.cjs +7 -2
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +7 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -265,7 +265,10 @@ interface AutoCrudTableProps<TSchema> {
|
|
|
265
265
|
hidden?: string[]; // 隐藏的列
|
|
266
266
|
overrides?: Record<string, any>; // 列覆盖配置
|
|
267
267
|
getRowId?: (record: z.output<TSchema>) => string; // 稳定行标识;展开时必填
|
|
268
|
-
expandedRow?: (
|
|
268
|
+
expandedRow?: (
|
|
269
|
+
record: z.output<TSchema>,
|
|
270
|
+
row: Row<z.output<TSchema>>,
|
|
271
|
+
) => React.ReactNode; // 展开行内容,row 提供已解析的单元格上下文
|
|
269
272
|
filterModes?: FilterMode | FilterMode[]; // 过滤模式
|
|
270
273
|
batchFields?: (string | BatchUpdateField)[]; // 批量更新字段
|
|
271
274
|
/** @deprecated 新代码请使用 actions.batch */
|
|
@@ -298,8 +301,9 @@ interface AutoCrudTableProps<TSchema> {
|
|
|
298
301
|
|
|
299
302
|
#### 展开行详情
|
|
300
303
|
|
|
301
|
-
配置 `table.expandedRow`
|
|
304
|
+
配置 `table.expandedRow` 后,表格自动添加展开箭头。默认全部收起,允许同时展开多行。设置 `table.defaultExpanded: true` 可在首次展示时展开全部行;刷新保留用户的展开选择。该选项仅用于初始化,不控制当前展开状态。
|
|
302
305
|
必须提供 TanStack Table 的 `getRowId`,使用稳定且唯一的业务主键,避免分页、排序后展开错位。
|
|
306
|
+
展开内容可使用 `cqw` 单位,以表格可视区域的宽度为基准,避免宽表中的详情被横向裁切。
|
|
303
307
|
|
|
304
308
|
```tsx
|
|
305
309
|
<AutoCrudTable
|
|
@@ -317,9 +321,11 @@ interface AutoCrudTableProps<TSchema> {
|
|
|
317
321
|
明细数据及其字段权限由业务组件和现有服务负责。
|
|
318
322
|
|
|
319
323
|
详情区域跨全部可见列,不计入分页条数,也不参与主表选择或导出。
|
|
320
|
-
|
|
324
|
+
未启用 `defaultExpanded` 时,数据更新后的展开状态遵循 TanStack Table 默认重置行为。
|
|
321
325
|
`AutoTable` 同样支持 `getRowId` 和 `expandedRow`;直接使用 `DataTable` 时,需自行配置 TanStack 展开能力及触发按钮。
|
|
322
326
|
|
|
327
|
+
`expandedRow` 的第二个参数是当前 TanStack `Row`,可通过 `row.getAllCells()` 读取已解析的列和单元格上下文,复用字段渲染器及数据源标签。只接收订单数据的单参数回调仍可使用。
|
|
328
|
+
|
|
323
329
|
### `useAutoCrudResource()`
|
|
324
330
|
|
|
325
331
|
连接数据源到组件的 Hook。
|
package/dist/index.cjs
CHANGED
|
@@ -581,6 +581,7 @@ function DataTable({ table, actionBar, pagination, expandedRow, children, classN
|
|
|
581
581
|
children,
|
|
582
582
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
583
583
|
className: "overflow-hidden rounded-md border",
|
|
584
|
+
style: expandedRow ? { containerType: "inline-size" } : void 0,
|
|
584
585
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.Table, {
|
|
585
586
|
className: classNames?.table,
|
|
586
587
|
style: hasWidthCap ? {
|
|
@@ -622,7 +623,7 @@ function DataTable({ table, actionBar, pagination, expandedRow, children, classN
|
|
|
622
623
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.TableCell, {
|
|
623
624
|
colSpan: row.getVisibleCells().length,
|
|
624
625
|
className: classNames?.td,
|
|
625
|
-
children: expandedRow(row.original)
|
|
626
|
+
children: expandedRow(row.original, row)
|
|
626
627
|
})
|
|
627
628
|
})] }, row.id)) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.TableRow, {
|
|
628
629
|
className: classNames?.tr,
|
|
@@ -4429,7 +4430,7 @@ const filterModeConfig = {
|
|
|
4429
4430
|
tooltip: "Linear-style command filters"
|
|
4430
4431
|
}
|
|
4431
4432
|
};
|
|
4432
|
-
function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, pagination, total, overrides, classNames, enableRowSelection = true, exclude, filterOnly, actions, pinnedColumns, filterMode, search = false, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows }) {
|
|
4433
|
+
function AutoTable({ schema, data, getRowId, expandedRow, defaultExpanded = false, pageCount = 1, pagination, total, overrides, classNames, enableRowSelection = true, exclude, filterOnly, actions, pinnedColumns, filterMode, search = false, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows }) {
|
|
4433
4434
|
if (expandedRow && !getRowId) throw new Error("AutoTable requires getRowId when expandedRow is provided.");
|
|
4434
4435
|
const enableExpansion = !!expandedRow;
|
|
4435
4436
|
const modes = filterMode ? Array.isArray(filterMode) ? filterMode : [filterMode] : DEFAULT_MODES;
|
|
@@ -4505,6 +4506,7 @@ function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, paginat
|
|
|
4505
4506
|
]);
|
|
4506
4507
|
const stableInitialState = (0, react.useMemo)(() => ({
|
|
4507
4508
|
sorting: initialSorting,
|
|
4509
|
+
expanded: enableExpansion && defaultExpanded ? true : {},
|
|
4508
4510
|
columnPinning: pinnedColumns ?? {
|
|
4509
4511
|
left: [...enableExpansion ? [expandColumnId] : [], ...enableRowSelection ? ["select"] : []],
|
|
4510
4512
|
right: actions ? ["actions"] : []
|
|
@@ -4514,6 +4516,7 @@ function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, paginat
|
|
|
4514
4516
|
pinnedColumns,
|
|
4515
4517
|
enableRowSelection,
|
|
4516
4518
|
enableExpansion,
|
|
4519
|
+
defaultExpanded,
|
|
4517
4520
|
expandColumnId,
|
|
4518
4521
|
actions
|
|
4519
4522
|
]);
|
|
@@ -4524,6 +4527,7 @@ function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, paginat
|
|
|
4524
4527
|
getRowId,
|
|
4525
4528
|
getRowCanExpand: () => enableExpansion,
|
|
4526
4529
|
getExpandedRowModel: enableExpansion ? expandedRowModel : void 0,
|
|
4530
|
+
autoResetExpanded: defaultExpanded ? false : void 0,
|
|
4527
4531
|
pageCount,
|
|
4528
4532
|
...total !== void 0 ? { rowCount: total } : {},
|
|
4529
4533
|
enableAdvancedFilter,
|
|
@@ -7861,6 +7865,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
7861
7865
|
...resource.tableData.total !== void 0 ? { total: resource.tableData.total } : {},
|
|
7862
7866
|
getRowId: tableConfig?.getRowId,
|
|
7863
7867
|
expandedRow: tableConfig?.expandedRow,
|
|
7868
|
+
defaultExpanded: tableConfig?.defaultExpanded,
|
|
7864
7869
|
overrides: tableOverrides,
|
|
7865
7870
|
classNames: tableConfig?.classNames,
|
|
7866
7871
|
exclude: hiddenColumns.filter((key) => !filterOnly.includes(key)),
|
package/dist/index.d.cts
CHANGED
|
@@ -658,8 +658,8 @@ interface DataTableProps<TData> extends ComponentProps<'div'> {
|
|
|
658
658
|
pagination?: TablePaginationOptions;
|
|
659
659
|
classNames?: DataTableClassNames;
|
|
660
660
|
actionBar?: ReactNode;
|
|
661
|
-
/** Content mounted below an expanded row. */
|
|
662
|
-
expandedRow?: (record: TData) => ReactNode;
|
|
661
|
+
/** Content mounted below an expanded row; row provides resolved cell contexts. */
|
|
662
|
+
expandedRow?: (record: TData, row: Row<TData>) => ReactNode;
|
|
663
663
|
}
|
|
664
664
|
declare function DataTable<TData>({
|
|
665
665
|
table,
|
|
@@ -873,6 +873,8 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> extends Pick<Data
|
|
|
873
873
|
data: z.infer<T>[];
|
|
874
874
|
/** Stable row identity; required when expandedRow is provided. */
|
|
875
875
|
getRowId?: TableOptions<z.infer<T>>['getRowId'];
|
|
876
|
+
/** Initially expand all rows. Defaults to false; only applies with expandedRow. */
|
|
877
|
+
defaultExpanded?: boolean;
|
|
876
878
|
pageCount?: number;
|
|
877
879
|
pagination?: TablePaginationOptions;
|
|
878
880
|
/** Total rows matching the current search and filters. */
|
|
@@ -930,6 +932,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
930
932
|
data,
|
|
931
933
|
getRowId,
|
|
932
934
|
expandedRow,
|
|
935
|
+
defaultExpanded,
|
|
933
936
|
pageCount,
|
|
934
937
|
pagination,
|
|
935
938
|
total,
|
|
@@ -1426,7 +1429,7 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
1426
1429
|
batchActions?: BatchActionConfig<z.output<TSchema>>;
|
|
1427
1430
|
/** 默认排序 */
|
|
1428
1431
|
defaultSort?: any[];
|
|
1429
|
-
} & Pick<AutoTableProps<TSchema>, 'getRowId' | 'expandedRow'>;
|
|
1432
|
+
} & Pick<AutoTableProps<TSchema>, 'getRowId' | 'expandedRow' | 'defaultExpanded'>;
|
|
1430
1433
|
/** 表单配置 */
|
|
1431
1434
|
form?: {
|
|
1432
1435
|
/** 表单覆盖配置(兼容旧 API,优先级低于 fieldOverrides) */
|
package/dist/index.d.ts
CHANGED
|
@@ -658,8 +658,8 @@ interface DataTableProps<TData> extends ComponentProps<'div'> {
|
|
|
658
658
|
pagination?: TablePaginationOptions;
|
|
659
659
|
classNames?: DataTableClassNames;
|
|
660
660
|
actionBar?: ReactNode;
|
|
661
|
-
/** Content mounted below an expanded row. */
|
|
662
|
-
expandedRow?: (record: TData) => ReactNode;
|
|
661
|
+
/** Content mounted below an expanded row; row provides resolved cell contexts. */
|
|
662
|
+
expandedRow?: (record: TData, row: Row<TData>) => ReactNode;
|
|
663
663
|
}
|
|
664
664
|
declare function DataTable<TData>({
|
|
665
665
|
table,
|
|
@@ -873,6 +873,8 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> extends Pick<Data
|
|
|
873
873
|
data: z.infer<T>[];
|
|
874
874
|
/** Stable row identity; required when expandedRow is provided. */
|
|
875
875
|
getRowId?: TableOptions<z.infer<T>>['getRowId'];
|
|
876
|
+
/** Initially expand all rows. Defaults to false; only applies with expandedRow. */
|
|
877
|
+
defaultExpanded?: boolean;
|
|
876
878
|
pageCount?: number;
|
|
877
879
|
pagination?: TablePaginationOptions;
|
|
878
880
|
/** Total rows matching the current search and filters. */
|
|
@@ -930,6 +932,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
930
932
|
data,
|
|
931
933
|
getRowId,
|
|
932
934
|
expandedRow,
|
|
935
|
+
defaultExpanded,
|
|
933
936
|
pageCount,
|
|
934
937
|
pagination,
|
|
935
938
|
total,
|
|
@@ -1426,7 +1429,7 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
1426
1429
|
batchActions?: BatchActionConfig<z.output<TSchema>>;
|
|
1427
1430
|
/** 默认排序 */
|
|
1428
1431
|
defaultSort?: any[];
|
|
1429
|
-
} & Pick<AutoTableProps<TSchema>, 'getRowId' | 'expandedRow'>;
|
|
1432
|
+
} & Pick<AutoTableProps<TSchema>, 'getRowId' | 'expandedRow' | 'defaultExpanded'>;
|
|
1430
1433
|
/** 表单配置 */
|
|
1431
1434
|
form?: {
|
|
1432
1435
|
/** 表单覆盖配置(兼容旧 API,优先级低于 fieldOverrides) */
|
package/dist/index.js
CHANGED
|
@@ -566,6 +566,7 @@ function DataTable({ table, actionBar, pagination, expandedRow, children, classN
|
|
|
566
566
|
children,
|
|
567
567
|
/* @__PURE__ */ jsx("div", {
|
|
568
568
|
className: "overflow-hidden rounded-md border",
|
|
569
|
+
style: expandedRow ? { containerType: "inline-size" } : void 0,
|
|
569
570
|
children: /* @__PURE__ */ jsxs(Table$1, {
|
|
570
571
|
className: classNames?.table,
|
|
571
572
|
style: hasWidthCap ? {
|
|
@@ -607,7 +608,7 @@ function DataTable({ table, actionBar, pagination, expandedRow, children, classN
|
|
|
607
608
|
children: /* @__PURE__ */ jsx(TableCell, {
|
|
608
609
|
colSpan: row.getVisibleCells().length,
|
|
609
610
|
className: classNames?.td,
|
|
610
|
-
children: expandedRow(row.original)
|
|
611
|
+
children: expandedRow(row.original, row)
|
|
611
612
|
})
|
|
612
613
|
})] }, row.id)) : /* @__PURE__ */ jsx(TableRow, {
|
|
613
614
|
className: classNames?.tr,
|
|
@@ -4414,7 +4415,7 @@ const filterModeConfig = {
|
|
|
4414
4415
|
tooltip: "Linear-style command filters"
|
|
4415
4416
|
}
|
|
4416
4417
|
};
|
|
4417
|
-
function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, pagination, total, overrides, classNames, enableRowSelection = true, exclude, filterOnly, actions, pinnedColumns, filterMode, search = false, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows }) {
|
|
4418
|
+
function AutoTable({ schema, data, getRowId, expandedRow, defaultExpanded = false, pageCount = 1, pagination, total, overrides, classNames, enableRowSelection = true, exclude, filterOnly, actions, pinnedColumns, filterMode, search = false, onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, actionBarActions, deleteConfirmation, initialSorting, enableExport = true, showDefaultExport = true, onSelectedCountChange, onSelectedRowsChange, getSelectedRows }) {
|
|
4418
4419
|
if (expandedRow && !getRowId) throw new Error("AutoTable requires getRowId when expandedRow is provided.");
|
|
4419
4420
|
const enableExpansion = !!expandedRow;
|
|
4420
4421
|
const modes = filterMode ? Array.isArray(filterMode) ? filterMode : [filterMode] : DEFAULT_MODES;
|
|
@@ -4490,6 +4491,7 @@ function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, paginat
|
|
|
4490
4491
|
]);
|
|
4491
4492
|
const stableInitialState = useMemo(() => ({
|
|
4492
4493
|
sorting: initialSorting,
|
|
4494
|
+
expanded: enableExpansion && defaultExpanded ? true : {},
|
|
4493
4495
|
columnPinning: pinnedColumns ?? {
|
|
4494
4496
|
left: [...enableExpansion ? [expandColumnId] : [], ...enableRowSelection ? ["select"] : []],
|
|
4495
4497
|
right: actions ? ["actions"] : []
|
|
@@ -4499,6 +4501,7 @@ function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, paginat
|
|
|
4499
4501
|
pinnedColumns,
|
|
4500
4502
|
enableRowSelection,
|
|
4501
4503
|
enableExpansion,
|
|
4504
|
+
defaultExpanded,
|
|
4502
4505
|
expandColumnId,
|
|
4503
4506
|
actions
|
|
4504
4507
|
]);
|
|
@@ -4509,6 +4512,7 @@ function AutoTable({ schema, data, getRowId, expandedRow, pageCount = 1, paginat
|
|
|
4509
4512
|
getRowId,
|
|
4510
4513
|
getRowCanExpand: () => enableExpansion,
|
|
4511
4514
|
getExpandedRowModel: enableExpansion ? expandedRowModel : void 0,
|
|
4515
|
+
autoResetExpanded: defaultExpanded ? false : void 0,
|
|
4512
4516
|
pageCount,
|
|
4513
4517
|
...total !== void 0 ? { rowCount: total } : {},
|
|
4514
4518
|
enableAdvancedFilter,
|
|
@@ -7846,6 +7850,7 @@ function AutoCrudTable({ id, title, description, schema, resource, fields, table
|
|
|
7846
7850
|
...resource.tableData.total !== void 0 ? { total: resource.tableData.total } : {},
|
|
7847
7851
|
getRowId: tableConfig?.getRowId,
|
|
7848
7852
|
expandedRow: tableConfig?.expandedRow,
|
|
7853
|
+
defaultExpanded: tableConfig?.defaultExpanded,
|
|
7849
7854
|
overrides: tableOverrides,
|
|
7850
7855
|
classNames: tableConfig?.classNames,
|
|
7851
7856
|
exclude: hiddenColumns.filter((key) => !filterOnly.includes(key)),
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.11.0",
|
|
5
5
|
"description": "Schema-first CRUD components with auto-generated tables and forms",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
"tailwind-merge": "^3.5.0",
|
|
72
72
|
"vaul": "^1.1.2",
|
|
73
73
|
"@wordrhyme/formily-shadcn": "2.1.1",
|
|
74
|
-
"@wordrhyme/shadcn
|
|
75
|
-
"@wordrhyme/shadcn": "2.
|
|
74
|
+
"@wordrhyme/shadcn": "2.0.1",
|
|
75
|
+
"@wordrhyme/shadcn-ui": "2.1.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@storybook/react": "^8.6.18",
|
|
@@ -94,10 +94,10 @@
|
|
|
94
94
|
"typescript": "^5.9.3",
|
|
95
95
|
"vitest": "^3.2.4",
|
|
96
96
|
"@internal/eslint-config": "0.3.0",
|
|
97
|
-
"@internal/
|
|
97
|
+
"@internal/tsconfig": "0.1.0",
|
|
98
98
|
"@internal/vitest-config": "0.1.0",
|
|
99
99
|
"@internal/tsdown-config": "0.1.0",
|
|
100
|
-
"@internal/
|
|
100
|
+
"@internal/prettier-config": "0.0.1"
|
|
101
101
|
},
|
|
102
102
|
"prettier": "@internal/prettier-config",
|
|
103
103
|
"scripts": {
|