@wordrhyme/auto-crud 0.3.0 → 0.4.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/dist/index.cjs +20 -12
- package/dist/index.d.cts +71 -3
- package/dist/index.d.ts +85 -17
- package/dist/index.js +20 -12
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -4201,7 +4201,7 @@ const filterModeConfig = {
|
|
|
4201
4201
|
tooltip: "Linear-style command filters"
|
|
4202
4202
|
}
|
|
4203
4203
|
};
|
|
4204
|
-
function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode = "simple", onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, initialSorting }) {
|
|
4204
|
+
function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode = "simple", onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, initialSorting, enableExport = true }) {
|
|
4205
4205
|
const modes = filterMode ? Array.isArray(filterMode) ? filterMode : [filterMode] : [
|
|
4206
4206
|
"simple",
|
|
4207
4207
|
"advanced",
|
|
@@ -4318,6 +4318,7 @@ function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection
|
|
|
4318
4318
|
onUpdateSelected,
|
|
4319
4319
|
batchUpdateFields,
|
|
4320
4320
|
enableDelete: !!onDeleteSelected,
|
|
4321
|
+
enableExport,
|
|
4321
4322
|
extraActions: actionBarExtra
|
|
4322
4323
|
})
|
|
4323
4324
|
]
|
|
@@ -4599,8 +4600,8 @@ function buildFormOverrides(fields, legacyOverrides) {
|
|
|
4599
4600
|
/**
|
|
4600
4601
|
* 从统一配置生成隐藏列列表
|
|
4601
4602
|
*/
|
|
4602
|
-
function buildHiddenColumns(fields, legacyHidden) {
|
|
4603
|
-
const hidden = new Set(legacyHidden ?? []);
|
|
4603
|
+
function buildHiddenColumns(fields, legacyHidden, denyFields) {
|
|
4604
|
+
const hidden = new Set([...legacyHidden ?? [], ...denyFields ?? []]);
|
|
4604
4605
|
if (fields) {
|
|
4605
4606
|
for (const [key, config] of Object.entries(fields)) if (config.hidden || config.table?.hidden) hidden.add(key);
|
|
4606
4607
|
}
|
|
@@ -4715,10 +4716,16 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
|
|
|
4715
4716
|
*
|
|
4716
4717
|
* 高级 CRUD 表格组件,封装了完整的增删改查流程
|
|
4717
4718
|
*/
|
|
4718
|
-
function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, slots }) {
|
|
4719
|
+
function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, slots, permissions }) {
|
|
4720
|
+
const can = {
|
|
4721
|
+
create: permissions?.can?.create ?? true,
|
|
4722
|
+
update: permissions?.can?.update ?? true,
|
|
4723
|
+
delete: permissions?.can?.delete ?? true,
|
|
4724
|
+
export: permissions?.can?.export ?? true
|
|
4725
|
+
};
|
|
4719
4726
|
const tableOverrides = buildTableOverrides(fields, tableConfig?.overrides);
|
|
4720
4727
|
const formOverrides = buildFormOverrides(fields, formConfig?.overrides);
|
|
4721
|
-
const hiddenColumns = buildHiddenColumns(fields, tableConfig?.hidden);
|
|
4728
|
+
const hiddenColumns = buildHiddenColumns(fields, tableConfig?.hidden, permissions?.deny);
|
|
4722
4729
|
const batchFields = buildBatchUpdateFields(schema, tableConfig?.batchFields, fields);
|
|
4723
4730
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4724
4731
|
className: "space-y-4",
|
|
@@ -4740,7 +4747,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
4740
4747
|
children: slots?.toolbarStart
|
|
4741
4748
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4742
4749
|
className: "flex items-center gap-2",
|
|
4743
|
-
children: [slots?.toolbarEnd, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.Button, {
|
|
4750
|
+
children: [slots?.toolbarEnd, can.create && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__pixpilot_shadcn.Button, {
|
|
4744
4751
|
onClick: resource.handlers.openCreate,
|
|
4745
4752
|
children: "新建"
|
|
4746
4753
|
})]
|
|
@@ -4755,13 +4762,14 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
4755
4762
|
filterMode: tableConfig?.filterModes,
|
|
4756
4763
|
actions: {
|
|
4757
4764
|
onView: resource.handlers.openView,
|
|
4758
|
-
onEdit: resource.handlers.openEdit,
|
|
4759
|
-
onCopy: resource.handlers.copyRow,
|
|
4760
|
-
onDelete: resource.handlers.openDelete
|
|
4765
|
+
onEdit: can.update ? resource.handlers.openEdit : void 0,
|
|
4766
|
+
onCopy: can.create ? resource.handlers.copyRow : void 0,
|
|
4767
|
+
onDelete: can.delete ? resource.handlers.openDelete : void 0
|
|
4761
4768
|
},
|
|
4762
|
-
onDeleteSelected: resource.handlers.deleteMany,
|
|
4763
|
-
onUpdateSelected: resource.handlers.updateMany,
|
|
4764
|
-
batchUpdateFields: batchFields,
|
|
4769
|
+
onDeleteSelected: can.delete ? resource.handlers.deleteMany : void 0,
|
|
4770
|
+
onUpdateSelected: can.update ? resource.handlers.updateMany : void 0,
|
|
4771
|
+
batchUpdateFields: can.update ? batchFields : void 0,
|
|
4772
|
+
enableExport: can.export,
|
|
4765
4773
|
initialSorting: tableConfig?.defaultSort
|
|
4766
4774
|
}),
|
|
4767
4775
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CrudFormModal, {
|
package/dist/index.d.cts
CHANGED
|
@@ -164,6 +164,50 @@ declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
164
164
|
options
|
|
165
165
|
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
166
166
|
//#endregion
|
|
167
|
+
//#region src/types/permissions.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* CRUD 操作权限
|
|
170
|
+
* 控制工具栏按钮、行操作按钮、批量操作按钮的显示
|
|
171
|
+
*/
|
|
172
|
+
interface CrudOperationPermissions {
|
|
173
|
+
/** 是否允许创建(新建按钮、复制行操作) */
|
|
174
|
+
create?: boolean;
|
|
175
|
+
/** 是否允许更新(编辑按钮、批量更新) */
|
|
176
|
+
update?: boolean;
|
|
177
|
+
/** 是否允许删除(删除按钮、批量删除) */
|
|
178
|
+
delete?: boolean;
|
|
179
|
+
/** 是否允许导出 */
|
|
180
|
+
export?: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* AutoCrudTable 权限配置
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```tsx
|
|
187
|
+
* const permissions = useMemo(() => ({
|
|
188
|
+
* can: {
|
|
189
|
+
* create: user.role === 'admin',
|
|
190
|
+
* update: user.role === 'admin' || user.role === 'editor',
|
|
191
|
+
* delete: user.role === 'admin',
|
|
192
|
+
* export: true,
|
|
193
|
+
* },
|
|
194
|
+
* deny: user.role === 'user' ? ['salary', 'ssn'] : [],
|
|
195
|
+
* }), [user.role]);
|
|
196
|
+
*
|
|
197
|
+
* <AutoCrudTable
|
|
198
|
+
* schema={employeeSchema}
|
|
199
|
+
* resource={resource}
|
|
200
|
+
* permissions={permissions}
|
|
201
|
+
* />
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
interface CrudPermissions {
|
|
205
|
+
/** 操作权限(默认全部为 true) */
|
|
206
|
+
can?: CrudOperationPermissions;
|
|
207
|
+
/** 禁止访问的字段列表(表格列和表单字段都会隐藏) */
|
|
208
|
+
deny?: string[];
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
167
211
|
//#region src/components/auto-crud/auto-table-action-bar.d.ts
|
|
168
212
|
/** 批量更新字段配置 */
|
|
169
213
|
interface BatchUpdateField {
|
|
@@ -323,6 +367,8 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
|
323
367
|
actionBarExtra?: React.ReactNode;
|
|
324
368
|
/** 初始排序 */
|
|
325
369
|
initialSorting?: any[];
|
|
370
|
+
/** 是否启用导出功能 (默认 true) */
|
|
371
|
+
enableExport?: boolean;
|
|
326
372
|
}
|
|
327
373
|
declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
328
374
|
schema,
|
|
@@ -338,7 +384,8 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
338
384
|
onUpdateSelected,
|
|
339
385
|
batchUpdateFields,
|
|
340
386
|
actionBarExtra,
|
|
341
|
-
initialSorting
|
|
387
|
+
initialSorting,
|
|
388
|
+
enableExport
|
|
342
389
|
}: AutoTableProps<T>): react_jsx_runtime2.JSX.Element;
|
|
343
390
|
//#endregion
|
|
344
391
|
//#region src/components/auto-crud/auto-crud-table.d.ts
|
|
@@ -430,6 +477,26 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
430
477
|
onClick: () => void;
|
|
431
478
|
}>;
|
|
432
479
|
};
|
|
480
|
+
/**
|
|
481
|
+
* 权限配置
|
|
482
|
+
* 控制按钮显示和字段访问
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```tsx
|
|
486
|
+
* const permissions = useMemo(() => ({
|
|
487
|
+
* can: {
|
|
488
|
+
* create: user.role === 'admin',
|
|
489
|
+
* update: user.role === 'admin' || user.role === 'editor',
|
|
490
|
+
* delete: user.role === 'admin',
|
|
491
|
+
* export: true,
|
|
492
|
+
* },
|
|
493
|
+
* deny: user.role === 'user' ? ['salary', 'ssn'] : [],
|
|
494
|
+
* }), [user.role]);
|
|
495
|
+
*
|
|
496
|
+
* <AutoCrudTable permissions={permissions} ... />
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
permissions?: CrudPermissions;
|
|
433
500
|
}
|
|
434
501
|
/**
|
|
435
502
|
* AutoCrudTable 组件
|
|
@@ -444,7 +511,8 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
444
511
|
fields,
|
|
445
512
|
table: tableConfig,
|
|
446
513
|
form: formConfig,
|
|
447
|
-
slots
|
|
514
|
+
slots,
|
|
515
|
+
permissions
|
|
448
516
|
}: AutoCrudTableProps<TSchema>): react_jsx_runtime2.JSX.Element;
|
|
449
517
|
//#endregion
|
|
450
518
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
@@ -1162,4 +1230,4 @@ declare function formatDate(date: Date | string | number | undefined, opts?: Int
|
|
|
1162
1230
|
*/
|
|
1163
1231
|
declare function humanize(str: string): string;
|
|
1164
1232
|
//#endregion
|
|
1165
|
-
export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, FilterOperator, type FilterVariant, type FormSchemaOverrides, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, cn, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, formatDate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };
|
|
1233
|
+
export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, FilterOperator, type FilterVariant, type FormSchemaOverrides, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, cn, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, formatDate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _tanstack_react_table0 from "@tanstack/react-table";
|
|
|
3
3
|
import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
|
|
4
4
|
import { DropdownMenuTrigger, PopoverContent } from "@pixpilot/shadcn";
|
|
5
5
|
import { ClassValue } from "clsx";
|
|
6
|
-
import * as
|
|
6
|
+
import * as react_jsx_runtime3 from "react/jsx-runtime";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { ISchema } from "@formily/json-schema";
|
|
9
9
|
|
|
@@ -164,6 +164,50 @@ declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
164
164
|
options
|
|
165
165
|
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
166
166
|
//#endregion
|
|
167
|
+
//#region src/types/permissions.d.ts
|
|
168
|
+
/**
|
|
169
|
+
* CRUD 操作权限
|
|
170
|
+
* 控制工具栏按钮、行操作按钮、批量操作按钮的显示
|
|
171
|
+
*/
|
|
172
|
+
interface CrudOperationPermissions {
|
|
173
|
+
/** 是否允许创建(新建按钮、复制行操作) */
|
|
174
|
+
create?: boolean;
|
|
175
|
+
/** 是否允许更新(编辑按钮、批量更新) */
|
|
176
|
+
update?: boolean;
|
|
177
|
+
/** 是否允许删除(删除按钮、批量删除) */
|
|
178
|
+
delete?: boolean;
|
|
179
|
+
/** 是否允许导出 */
|
|
180
|
+
export?: boolean;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* AutoCrudTable 权限配置
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```tsx
|
|
187
|
+
* const permissions = useMemo(() => ({
|
|
188
|
+
* can: {
|
|
189
|
+
* create: user.role === 'admin',
|
|
190
|
+
* update: user.role === 'admin' || user.role === 'editor',
|
|
191
|
+
* delete: user.role === 'admin',
|
|
192
|
+
* export: true,
|
|
193
|
+
* },
|
|
194
|
+
* deny: user.role === 'user' ? ['salary', 'ssn'] : [],
|
|
195
|
+
* }), [user.role]);
|
|
196
|
+
*
|
|
197
|
+
* <AutoCrudTable
|
|
198
|
+
* schema={employeeSchema}
|
|
199
|
+
* resource={resource}
|
|
200
|
+
* permissions={permissions}
|
|
201
|
+
* />
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
interface CrudPermissions {
|
|
205
|
+
/** 操作权限(默认全部为 true) */
|
|
206
|
+
can?: CrudOperationPermissions;
|
|
207
|
+
/** 禁止访问的字段列表(表格列和表单字段都会隐藏) */
|
|
208
|
+
deny?: string[];
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
167
211
|
//#region src/components/auto-crud/auto-table-action-bar.d.ts
|
|
168
212
|
/** 批量更新字段配置 */
|
|
169
213
|
interface BatchUpdateField {
|
|
@@ -199,7 +243,7 @@ declare function AutoTableActionBar<TData>({
|
|
|
199
243
|
enableExport,
|
|
200
244
|
enableDelete,
|
|
201
245
|
extraActions
|
|
202
|
-
}: AutoTableActionBarProps<TData>):
|
|
246
|
+
}: AutoTableActionBarProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
203
247
|
//#endregion
|
|
204
248
|
//#region src/lib/schema-bridge/types.d.ts
|
|
205
249
|
/**
|
|
@@ -323,6 +367,8 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
|
323
367
|
actionBarExtra?: React.ReactNode;
|
|
324
368
|
/** 初始排序 */
|
|
325
369
|
initialSorting?: any[];
|
|
370
|
+
/** 是否启用导出功能 (默认 true) */
|
|
371
|
+
enableExport?: boolean;
|
|
326
372
|
}
|
|
327
373
|
declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
328
374
|
schema,
|
|
@@ -338,8 +384,9 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
338
384
|
onUpdateSelected,
|
|
339
385
|
batchUpdateFields,
|
|
340
386
|
actionBarExtra,
|
|
341
|
-
initialSorting
|
|
342
|
-
|
|
387
|
+
initialSorting,
|
|
388
|
+
enableExport
|
|
389
|
+
}: AutoTableProps<T>): react_jsx_runtime3.JSX.Element;
|
|
343
390
|
//#endregion
|
|
344
391
|
//#region src/components/auto-crud/auto-crud-table.d.ts
|
|
345
392
|
/**
|
|
@@ -430,6 +477,26 @@ interface AutoCrudTableProps<TSchema extends z.ZodObject<z.ZodRawShape>> {
|
|
|
430
477
|
onClick: () => void;
|
|
431
478
|
}>;
|
|
432
479
|
};
|
|
480
|
+
/**
|
|
481
|
+
* 权限配置
|
|
482
|
+
* 控制按钮显示和字段访问
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```tsx
|
|
486
|
+
* const permissions = useMemo(() => ({
|
|
487
|
+
* can: {
|
|
488
|
+
* create: user.role === 'admin',
|
|
489
|
+
* update: user.role === 'admin' || user.role === 'editor',
|
|
490
|
+
* delete: user.role === 'admin',
|
|
491
|
+
* export: true,
|
|
492
|
+
* },
|
|
493
|
+
* deny: user.role === 'user' ? ['salary', 'ssn'] : [],
|
|
494
|
+
* }), [user.role]);
|
|
495
|
+
*
|
|
496
|
+
* <AutoCrudTable permissions={permissions} ... />
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
permissions?: CrudPermissions;
|
|
433
500
|
}
|
|
434
501
|
/**
|
|
435
502
|
* AutoCrudTable 组件
|
|
@@ -444,8 +511,9 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
|
|
|
444
511
|
fields,
|
|
445
512
|
table: tableConfig,
|
|
446
513
|
form: formConfig,
|
|
447
|
-
slots
|
|
448
|
-
|
|
514
|
+
slots,
|
|
515
|
+
permissions
|
|
516
|
+
}: AutoCrudTableProps<TSchema>): react_jsx_runtime3.JSX.Element;
|
|
449
517
|
//#endregion
|
|
450
518
|
//#region src/components/auto-crud/auto-form.d.ts
|
|
451
519
|
interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
|
|
@@ -477,7 +545,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
477
545
|
labelAlign,
|
|
478
546
|
labelWidth,
|
|
479
547
|
showSubmitButton
|
|
480
|
-
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>):
|
|
548
|
+
}: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime3.JSX.Element;
|
|
481
549
|
declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
|
|
482
550
|
ref?: React.Ref<AutoFormRef>;
|
|
483
551
|
}) => ReturnType<typeof AutoFormInner>;
|
|
@@ -772,7 +840,7 @@ declare function AutoTableSimpleFilters<TData>({
|
|
|
772
840
|
shallow,
|
|
773
841
|
filters: externalFilters,
|
|
774
842
|
onFiltersChange
|
|
775
|
-
}: AutoTableSimpleFiltersProps<TData>):
|
|
843
|
+
}: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime3.JSX.Element | null;
|
|
776
844
|
//#endregion
|
|
777
845
|
//#region src/components/auto-crud/form-modal.d.ts
|
|
778
846
|
type ModalVariant = "dialog" | "sheet";
|
|
@@ -807,7 +875,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
|
|
|
807
875
|
title,
|
|
808
876
|
labelAlign,
|
|
809
877
|
labelWidth
|
|
810
|
-
}: CrudFormModalProps<T>):
|
|
878
|
+
}: CrudFormModalProps<T>): react_jsx_runtime3.JSX.Element;
|
|
811
879
|
//#endregion
|
|
812
880
|
//#region src/components/data-table/data-table.d.ts
|
|
813
881
|
interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -820,7 +888,7 @@ declare function DataTable<TData>({
|
|
|
820
888
|
children,
|
|
821
889
|
className,
|
|
822
890
|
...props
|
|
823
|
-
}: DataTableProps<TData>):
|
|
891
|
+
}: DataTableProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
824
892
|
//#endregion
|
|
825
893
|
//#region src/components/data-table/data-table-advanced-toolbar.d.ts
|
|
826
894
|
interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -831,7 +899,7 @@ declare function DataTableAdvancedToolbar<TData>({
|
|
|
831
899
|
children,
|
|
832
900
|
className,
|
|
833
901
|
...props
|
|
834
|
-
}: DataTableAdvancedToolbarProps<TData>):
|
|
902
|
+
}: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
835
903
|
//#endregion
|
|
836
904
|
//#region src/components/data-table/data-table-column-header.d.ts
|
|
837
905
|
interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
|
|
@@ -843,7 +911,7 @@ declare function DataTableColumnHeader<TData, TValue>({
|
|
|
843
911
|
label,
|
|
844
912
|
className,
|
|
845
913
|
...props
|
|
846
|
-
}: DataTableColumnHeaderProps<TData, TValue>):
|
|
914
|
+
}: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
|
|
847
915
|
//#endregion
|
|
848
916
|
//#region src/components/data-table/data-table-faceted-filter.d.ts
|
|
849
917
|
interface DataTableFacetedFilterProps<TData, TValue> {
|
|
@@ -857,7 +925,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
|
|
|
857
925
|
title,
|
|
858
926
|
options,
|
|
859
927
|
multiple
|
|
860
|
-
}: DataTableFacetedFilterProps<TData, TValue>):
|
|
928
|
+
}: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
|
|
861
929
|
//#endregion
|
|
862
930
|
//#region src/components/data-table/data-table-pagination.d.ts
|
|
863
931
|
interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
|
|
@@ -869,7 +937,7 @@ declare function DataTablePagination<TData>({
|
|
|
869
937
|
pageSizeOptions,
|
|
870
938
|
className,
|
|
871
939
|
...props
|
|
872
|
-
}: DataTablePaginationProps<TData>):
|
|
940
|
+
}: DataTablePaginationProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
873
941
|
//#endregion
|
|
874
942
|
//#region src/components/data-table/data-table-toolbar.d.ts
|
|
875
943
|
interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
|
|
@@ -880,7 +948,7 @@ declare function DataTableToolbar<TData>({
|
|
|
880
948
|
children,
|
|
881
949
|
className,
|
|
882
950
|
...props
|
|
883
|
-
}: DataTableToolbarProps<TData>):
|
|
951
|
+
}: DataTableToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
884
952
|
//#endregion
|
|
885
953
|
//#region src/components/data-table/data-table-view-options.d.ts
|
|
886
954
|
interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
|
|
@@ -891,7 +959,7 @@ declare function DataTableViewOptions<TData>({
|
|
|
891
959
|
table,
|
|
892
960
|
disabled,
|
|
893
961
|
...props
|
|
894
|
-
}: DataTableViewOptionsProps<TData>):
|
|
962
|
+
}: DataTableViewOptionsProps<TData>): react_jsx_runtime3.JSX.Element;
|
|
895
963
|
//#endregion
|
|
896
964
|
//#region src/hooks/use-data-table.d.ts
|
|
897
965
|
interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
|
|
@@ -1162,4 +1230,4 @@ declare function formatDate(date: Date | string | number | undefined, opts?: Int
|
|
|
1162
1230
|
*/
|
|
1163
1231
|
declare function humanize(str: string): string;
|
|
1164
1232
|
//#endregion
|
|
1165
|
-
export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, FilterOperator, type FilterVariant, type FormSchemaOverrides, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, cn, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, formatDate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };
|
|
1233
|
+
export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, AutoTable, AutoTableActionBar, AutoTableSimpleFilters, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type EnumOption, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, FilterOperator, type FilterVariant, type FormSchemaOverrides, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, cn, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, formatDate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };
|
package/dist/index.js
CHANGED
|
@@ -4159,7 +4159,7 @@ const filterModeConfig = {
|
|
|
4159
4159
|
tooltip: "Linear-style command filters"
|
|
4160
4160
|
}
|
|
4161
4161
|
};
|
|
4162
|
-
function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode = "simple", onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, initialSorting }) {
|
|
4162
|
+
function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection = true, exclude, actions, pinnedColumns, filterMode = "simple", onDeleteSelected, onUpdateSelected, batchUpdateFields, actionBarExtra, initialSorting, enableExport = true }) {
|
|
4163
4163
|
const modes = filterMode ? Array.isArray(filterMode) ? filterMode : [filterMode] : [
|
|
4164
4164
|
"simple",
|
|
4165
4165
|
"advanced",
|
|
@@ -4276,6 +4276,7 @@ function AutoTable({ schema, data, pageCount = 1, overrides, enableRowSelection
|
|
|
4276
4276
|
onUpdateSelected,
|
|
4277
4277
|
batchUpdateFields,
|
|
4278
4278
|
enableDelete: !!onDeleteSelected,
|
|
4279
|
+
enableExport,
|
|
4279
4280
|
extraActions: actionBarExtra
|
|
4280
4281
|
})
|
|
4281
4282
|
]
|
|
@@ -4557,8 +4558,8 @@ function buildFormOverrides(fields, legacyOverrides) {
|
|
|
4557
4558
|
/**
|
|
4558
4559
|
* 从统一配置生成隐藏列列表
|
|
4559
4560
|
*/
|
|
4560
|
-
function buildHiddenColumns(fields, legacyHidden) {
|
|
4561
|
-
const hidden = new Set(legacyHidden ?? []);
|
|
4561
|
+
function buildHiddenColumns(fields, legacyHidden, denyFields) {
|
|
4562
|
+
const hidden = new Set([...legacyHidden ?? [], ...denyFields ?? []]);
|
|
4562
4563
|
if (fields) {
|
|
4563
4564
|
for (const [key, config] of Object.entries(fields)) if (config.hidden || config.table?.hidden) hidden.add(key);
|
|
4564
4565
|
}
|
|
@@ -4673,10 +4674,16 @@ function ViewModal({ open, onOpenChange, variant, data, schema, fields: fieldCon
|
|
|
4673
4674
|
*
|
|
4674
4675
|
* 高级 CRUD 表格组件,封装了完整的增删改查流程
|
|
4675
4676
|
*/
|
|
4676
|
-
function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, slots }) {
|
|
4677
|
+
function AutoCrudTable({ title, description, schema, resource, fields, table: tableConfig, form: formConfig, slots, permissions }) {
|
|
4678
|
+
const can = {
|
|
4679
|
+
create: permissions?.can?.create ?? true,
|
|
4680
|
+
update: permissions?.can?.update ?? true,
|
|
4681
|
+
delete: permissions?.can?.delete ?? true,
|
|
4682
|
+
export: permissions?.can?.export ?? true
|
|
4683
|
+
};
|
|
4677
4684
|
const tableOverrides = buildTableOverrides(fields, tableConfig?.overrides);
|
|
4678
4685
|
const formOverrides = buildFormOverrides(fields, formConfig?.overrides);
|
|
4679
|
-
const hiddenColumns = buildHiddenColumns(fields, tableConfig?.hidden);
|
|
4686
|
+
const hiddenColumns = buildHiddenColumns(fields, tableConfig?.hidden, permissions?.deny);
|
|
4680
4687
|
const batchFields = buildBatchUpdateFields(schema, tableConfig?.batchFields, fields);
|
|
4681
4688
|
return /* @__PURE__ */ jsxs("div", {
|
|
4682
4689
|
className: "space-y-4",
|
|
@@ -4698,7 +4705,7 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
4698
4705
|
children: slots?.toolbarStart
|
|
4699
4706
|
}), /* @__PURE__ */ jsxs("div", {
|
|
4700
4707
|
className: "flex items-center gap-2",
|
|
4701
|
-
children: [slots?.toolbarEnd, /* @__PURE__ */ jsx(Button, {
|
|
4708
|
+
children: [slots?.toolbarEnd, can.create && /* @__PURE__ */ jsx(Button, {
|
|
4702
4709
|
onClick: resource.handlers.openCreate,
|
|
4703
4710
|
children: "新建"
|
|
4704
4711
|
})]
|
|
@@ -4713,13 +4720,14 @@ function AutoCrudTable({ title, description, schema, resource, fields, table: ta
|
|
|
4713
4720
|
filterMode: tableConfig?.filterModes,
|
|
4714
4721
|
actions: {
|
|
4715
4722
|
onView: resource.handlers.openView,
|
|
4716
|
-
onEdit: resource.handlers.openEdit,
|
|
4717
|
-
onCopy: resource.handlers.copyRow,
|
|
4718
|
-
onDelete: resource.handlers.openDelete
|
|
4723
|
+
onEdit: can.update ? resource.handlers.openEdit : void 0,
|
|
4724
|
+
onCopy: can.create ? resource.handlers.copyRow : void 0,
|
|
4725
|
+
onDelete: can.delete ? resource.handlers.openDelete : void 0
|
|
4719
4726
|
},
|
|
4720
|
-
onDeleteSelected: resource.handlers.deleteMany,
|
|
4721
|
-
onUpdateSelected: resource.handlers.updateMany,
|
|
4722
|
-
batchUpdateFields: batchFields,
|
|
4727
|
+
onDeleteSelected: can.delete ? resource.handlers.deleteMany : void 0,
|
|
4728
|
+
onUpdateSelected: can.update ? resource.handlers.updateMany : void 0,
|
|
4729
|
+
batchUpdateFields: can.update ? batchFields : void 0,
|
|
4730
|
+
enableExport: can.export,
|
|
4723
4731
|
initialSorting: tableConfig?.defaultSort
|
|
4724
4732
|
}),
|
|
4725
4733
|
/* @__PURE__ */ jsx(CrudFormModal, {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordrhyme/auto-crud",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "Schema-first CRUD components with auto-generated tables and forms",
|
|
6
6
|
"author": "wordrhyme",
|
|
7
7
|
"license": "MIT",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"tailwind-merge": "^3.4.0",
|
|
67
67
|
"vaul": "^1.1.2",
|
|
68
68
|
"@pixpilot/formily-shadcn": "0.44.3",
|
|
69
|
-
"@pixpilot/shadcn": "0.
|
|
70
|
-
"@pixpilot/shadcn
|
|
69
|
+
"@pixpilot/shadcn-ui": "0.47.0",
|
|
70
|
+
"@pixpilot/shadcn": "0.9.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@tanstack/react-query": "^5.90.15",
|
|
@@ -81,11 +81,11 @@
|
|
|
81
81
|
"react-dom": "19.2.4",
|
|
82
82
|
"tsdown": "^0.15.12",
|
|
83
83
|
"typescript": "^5.9.3",
|
|
84
|
-
"@internal/eslint-config": "0.3.0",
|
|
85
84
|
"@internal/tsconfig": "0.1.0",
|
|
85
|
+
"@internal/eslint-config": "0.3.0",
|
|
86
86
|
"@internal/tsdown-config": "0.1.0",
|
|
87
|
-
"@internal/
|
|
88
|
-
"@internal/
|
|
87
|
+
"@internal/prettier-config": "0.0.1",
|
|
88
|
+
"@internal/vitest-config": "0.1.0"
|
|
89
89
|
},
|
|
90
90
|
"prettier": "@internal/prettier-config",
|
|
91
91
|
"scripts": {
|