@wordrhyme/auto-crud 1.15.0 → 1.16.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 +44 -0
- package/dist/index.cjs +36 -15
- package/dist/index.d.cts +19 -6
- package/dist/index.d.ts +19 -6
- package/dist/index.js +36 -15
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2124,3 +2124,47 @@ function EditTags({
|
|
|
2124
2124
|
独立使用 `TagFilter` 时,在 `AutoCrudProvider` 内传入 `resourceId="crm.customers"` 和 `field="tags"`,默认显示工具栏按钮;表格内部可省略 `resourceId`,自动继承表格的 CRUD id。嵌入自有条件行可传 `variant="input"`;`id` 和 `className` 对应输入样式的触发按钮,`open/onOpenChange` 可控制其展开状态。值仍通过 `value/onChange` 控制,不需要转换成普通多选数组。
|
|
2125
2125
|
|
|
2126
2126
|
`useAutoCrudResource` 返回 `metadataPending`,`AutoCrudTable` 据此等待字段元数据就绪,再恢复上次视图,避免把尚未加载的扩展字段当成已删除字段。自定义资源应在异步字段加载期间提供 `metadataPending: true`;独立 `AutoTable` 使用 `views={{ fieldsReady: false }}` 暂停恢复和视图切换,字段加载完成后改为 `true`。未提供这些状态时沿用同步字段行为。
|
|
2127
|
+
|
|
2128
|
+
## 自定义全局搜索
|
|
2129
|
+
|
|
2130
|
+
`table.search.render` 可替换搜索输入框。回调的 `value` / `onValueChange` 沿用表格文字搜索和分页状态;额外条件变化时调用 `resetPage()`。未提供 `render` 时保留默认输入框。
|
|
2131
|
+
|
|
2132
|
+
自定义输入框应转发 `onCompositionStart` / `onCompositionEnd`,以沿用中文等输入法的组合输入保护,避免选词完成前发起搜索:
|
|
2133
|
+
|
|
2134
|
+
```tsx
|
|
2135
|
+
render: ({ value, onValueChange, onCompositionStart, onCompositionEnd, placeholder }) => (
|
|
2136
|
+
<Input
|
|
2137
|
+
value={value}
|
|
2138
|
+
onChange={(event) => onValueChange(event.target.value)}
|
|
2139
|
+
onCompositionStart={onCompositionStart}
|
|
2140
|
+
onCompositionEnd={onCompositionEnd}
|
|
2141
|
+
placeholder={placeholder}
|
|
2142
|
+
/>
|
|
2143
|
+
);
|
|
2144
|
+
```
|
|
2145
|
+
|
|
2146
|
+
同一次操作可以先调用 `onValueChange(next)` 再调用 `resetPage()`;分页重置会提交最新文字,不会恢复旧关键词。
|
|
2147
|
+
|
|
2148
|
+
```tsx
|
|
2149
|
+
const resource = useAutoCrudResource({
|
|
2150
|
+
router: api.products,
|
|
2151
|
+
schema: productSchema,
|
|
2152
|
+
query: (params) => ({ ...params, image }),
|
|
2153
|
+
queryContext: { methodOverride: 'POST' },
|
|
2154
|
+
});
|
|
2155
|
+
|
|
2156
|
+
<AutoCrudTable
|
|
2157
|
+
resource={resource}
|
|
2158
|
+
schema={productSchema}
|
|
2159
|
+
table={{
|
|
2160
|
+
search: {
|
|
2161
|
+
placeholder: '搜索商品',
|
|
2162
|
+
render: (props) => (
|
|
2163
|
+
<ProductSearch {...props} image={image} onImageChange={setImage} />
|
|
2164
|
+
),
|
|
2165
|
+
},
|
|
2166
|
+
}}
|
|
2167
|
+
/>;
|
|
2168
|
+
```
|
|
2169
|
+
|
|
2170
|
+
`TableSearchProps` / `TableSearchConfig` 可从包入口导入。`queryContext` 透传给 tRPC 列表与自动导出;自定义 `exportFetcher` 需自行传递请求上下文。服务端须支持所选传输方式。`resource.tableData.error` 暴露查询失败,调用方可展示具体错误;它不把失败当成无匹配结果。
|
package/dist/index.cjs
CHANGED
|
@@ -5667,12 +5667,13 @@ function SimpleDateFilter({ title, maxDate, multiple, value, onChange }) {
|
|
|
5667
5667
|
|
|
5668
5668
|
//#endregion
|
|
5669
5669
|
//#region src/components/auto-crud/auto-table-search.tsx
|
|
5670
|
-
function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "page" }) {
|
|
5670
|
+
function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "page", render }) {
|
|
5671
5671
|
const [value, setValue] = (0, react.useState)(() => getUrlParams().get("search") ?? "");
|
|
5672
|
+
const valueRef = (0, react.useRef)(value);
|
|
5672
5673
|
const composing = (0, react.useRef)(false);
|
|
5673
|
-
const commit = (0, react.useCallback)((next) => {
|
|
5674
|
+
const commit = (0, react.useCallback)((next, resetPage = false) => {
|
|
5674
5675
|
const params = getUrlParams();
|
|
5675
|
-
if ((params.get("search") ?? "") === next) return;
|
|
5676
|
+
if ((params.get("search") ?? "") === next && !resetPage) return;
|
|
5676
5677
|
if (next) params.set("search", next);
|
|
5677
5678
|
else params.delete("search");
|
|
5678
5679
|
params.delete(pageKey);
|
|
@@ -5683,7 +5684,8 @@ function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "
|
|
|
5683
5684
|
(0, react.useEffect)(() => {
|
|
5684
5685
|
const sync = () => {
|
|
5685
5686
|
cancel();
|
|
5686
|
-
|
|
5687
|
+
valueRef.current = getUrlParams().get("search") ?? "";
|
|
5688
|
+
setValue(valueRef.current);
|
|
5687
5689
|
};
|
|
5688
5690
|
window.addEventListener("popstate", sync);
|
|
5689
5691
|
window.addEventListener("urlchange", sync);
|
|
@@ -5694,23 +5696,37 @@ function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "
|
|
|
5694
5696
|
};
|
|
5695
5697
|
}, [cancel, pageKey]);
|
|
5696
5698
|
const change = (next) => {
|
|
5699
|
+
valueRef.current = next;
|
|
5697
5700
|
setValue(next);
|
|
5698
5701
|
cancel();
|
|
5699
5702
|
if (composing.current) return;
|
|
5700
5703
|
if (!next || debounceMs <= 0) commit(next);
|
|
5701
5704
|
else debouncedCommit(next);
|
|
5702
5705
|
};
|
|
5706
|
+
const onCompositionStart = () => {
|
|
5707
|
+
composing.current = true;
|
|
5708
|
+
cancel();
|
|
5709
|
+
};
|
|
5710
|
+
const onCompositionEnd = (event) => {
|
|
5711
|
+
composing.current = false;
|
|
5712
|
+
change(event.currentTarget.value);
|
|
5713
|
+
};
|
|
5714
|
+
if (render) return render({
|
|
5715
|
+
value,
|
|
5716
|
+
onValueChange: change,
|
|
5717
|
+
onCompositionStart,
|
|
5718
|
+
onCompositionEnd,
|
|
5719
|
+
placeholder,
|
|
5720
|
+
resetPage: () => {
|
|
5721
|
+
cancel();
|
|
5722
|
+
commit(valueRef.current, true);
|
|
5723
|
+
}
|
|
5724
|
+
});
|
|
5703
5725
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
|
|
5704
5726
|
value,
|
|
5705
5727
|
onChange: (event) => change(event.target.value),
|
|
5706
|
-
onCompositionStart
|
|
5707
|
-
|
|
5708
|
-
cancel();
|
|
5709
|
-
},
|
|
5710
|
-
onCompositionEnd: (event) => {
|
|
5711
|
-
composing.current = false;
|
|
5712
|
-
change(event.currentTarget.value);
|
|
5713
|
-
},
|
|
5728
|
+
onCompositionStart,
|
|
5729
|
+
onCompositionEnd,
|
|
5714
5730
|
placeholder,
|
|
5715
5731
|
className: "h-8 w-48 shrink-0"
|
|
5716
5732
|
});
|
|
@@ -10875,7 +10891,7 @@ function modalReducer(state, action$1) {
|
|
|
10875
10891
|
/**
|
|
10876
10892
|
* Hook 主函数
|
|
10877
10893
|
*/
|
|
10878
|
-
function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform, fields, options = {} }) {
|
|
10894
|
+
function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform, queryContext, fields, options = {} }) {
|
|
10879
10895
|
const { idKey = "id", defaultVariant = "dialog", hooks, toast: toastAdapter, exportFetcher, defaultSort: defaultSortOption } = options;
|
|
10880
10896
|
const toast$1 = (0, react.useMemo)(() => toastAdapter === false ? noopToastAdapter : toastAdapter ?? defaultToastAdapter, [toastAdapter]);
|
|
10881
10897
|
const hooksRef = (0, react.useRef)(hooks);
|
|
@@ -10930,6 +10946,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
10930
10946
|
]);
|
|
10931
10947
|
const hasReadyListData = (0, react.useRef)(false);
|
|
10932
10948
|
const listQuery = router.list.useQuery(queryInput, {
|
|
10949
|
+
...queryContext !== void 0 ? { trpc: { context: queryContext } } : {},
|
|
10933
10950
|
enabled: listReady,
|
|
10934
10951
|
placeholderData: hasReadyListData.current ? __tanstack_react_query.keepPreviousData : void 0,
|
|
10935
10952
|
staleTime: 0
|
|
@@ -10950,7 +10967,10 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
10950
10967
|
const { page: _p, perPage: _pp,...rest } = queryInput;
|
|
10951
10968
|
return rest;
|
|
10952
10969
|
}, [queryInput]);
|
|
10953
|
-
const exportQuery = router.export?.useQuery(exportInput, {
|
|
10970
|
+
const exportQuery = router.export?.useQuery(exportInput, {
|
|
10971
|
+
enabled: false,
|
|
10972
|
+
...queryContext !== void 0 ? { trpc: { context: queryContext } } : {}
|
|
10973
|
+
});
|
|
10954
10974
|
const [modal, dispatch] = (0, react.useReducer)(modalReducer, {
|
|
10955
10975
|
createOpen: false,
|
|
10956
10976
|
editOpen: false,
|
|
@@ -11207,7 +11227,8 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
11207
11227
|
pageCount: listData?.pageCount ?? 0,
|
|
11208
11228
|
...typeof listData?.total === "number" ? { total: listData.total } : {},
|
|
11209
11229
|
isLoading: !listReady || listQuery.isLoading,
|
|
11210
|
-
isFetching: !listReady || listQuery.isFetching
|
|
11230
|
+
isFetching: !listReady || listQuery.isFetching,
|
|
11231
|
+
error: listQuery.error
|
|
11211
11232
|
},
|
|
11212
11233
|
schema: resolvedSchema,
|
|
11213
11234
|
metadataPending,
|
package/dist/index.d.cts
CHANGED
|
@@ -244,6 +244,7 @@ interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
244
244
|
isLoading: boolean;
|
|
245
245
|
/** 是否正在获取数据(用于显示微妙的加载指示器) */
|
|
246
246
|
isFetching: boolean;
|
|
247
|
+
error?: Error | null;
|
|
247
248
|
};
|
|
248
249
|
/** Optional schema override from host metadata. */
|
|
249
250
|
schema?: z.ZodObject<z.ZodRawShape>;
|
|
@@ -361,6 +362,8 @@ interface UseAutoCrudResourceParams<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
361
362
|
* ```
|
|
362
363
|
*/
|
|
363
364
|
query?: (params: AutoQueryParams) => Record<string, unknown>;
|
|
365
|
+
/** tRPC operation context shared by list and automatic export requests. */
|
|
366
|
+
queryContext?: Record<string, unknown>;
|
|
364
367
|
/** 其他配置选项 */
|
|
365
368
|
options?: UseAutoCrudResourceOptions<TSchema, TListItem>;
|
|
366
369
|
}
|
|
@@ -372,6 +375,7 @@ declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
372
375
|
queryKeys,
|
|
373
376
|
schema,
|
|
374
377
|
query: queryTransform,
|
|
378
|
+
queryContext,
|
|
375
379
|
fields,
|
|
376
380
|
options
|
|
377
381
|
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
@@ -1408,6 +1412,19 @@ declare function createActionsColumn<T>(items: ActionsColumnConfig<T>): ColumnDe
|
|
|
1408
1412
|
//#region src/components/auto-crud/auto-table.d.ts
|
|
1409
1413
|
/** 过滤模式类型 */
|
|
1410
1414
|
type FilterMode = 'simple' | 'advanced' | 'command';
|
|
1415
|
+
interface TableSearchProps extends Pick<React.ComponentPropsWithoutRef<'input'>, 'onCompositionStart' | 'onCompositionEnd'> {
|
|
1416
|
+
value: string;
|
|
1417
|
+
onValueChange: (value: string) => void;
|
|
1418
|
+
placeholder: string;
|
|
1419
|
+
/** Reset pagination when an additional search criterion changes. */
|
|
1420
|
+
resetPage: () => void;
|
|
1421
|
+
}
|
|
1422
|
+
interface TableSearchConfig {
|
|
1423
|
+
placeholder?: string;
|
|
1424
|
+
/** Search delay in milliseconds. Defaults to 200; use 0 for immediate queries. */
|
|
1425
|
+
debounceMs?: number;
|
|
1426
|
+
render?: (props: TableSearchProps) => React.ReactNode;
|
|
1427
|
+
}
|
|
1411
1428
|
interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> extends Pick<DataTableProps<z.infer<T>>, 'expandedRow'> {
|
|
1412
1429
|
/** Stable CRUD identity for saved views and tag services. */
|
|
1413
1430
|
resourceId?: string;
|
|
@@ -1447,11 +1464,7 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> extends Pick<Data
|
|
|
1447
1464
|
*/
|
|
1448
1465
|
filterMode?: FilterMode | FilterMode[];
|
|
1449
1466
|
/** 全局搜索框 */
|
|
1450
|
-
search?: boolean |
|
|
1451
|
-
placeholder?: string;
|
|
1452
|
-
/** Search delay in milliseconds. Defaults to 200; use 0 for immediate queries. */
|
|
1453
|
-
debounceMs?: number;
|
|
1454
|
-
};
|
|
1467
|
+
search?: boolean | TableSearchConfig;
|
|
1455
1468
|
/** Extra table controls rendered between sorting and column visibility. */
|
|
1456
1469
|
toolbarExtra?: React.ReactNode;
|
|
1457
1470
|
/** Sorting and column visibility strings. Defaults to English for standalone use. */
|
|
@@ -2586,4 +2599,4 @@ interface TagAssignmentProps extends TagScope, Pick<RowActionDialogProps, 'open'
|
|
|
2586
2599
|
/** Controlled dialog. Callers own the trigger, its appearance and its placement. */
|
|
2587
2600
|
declare function TagAssignment(props: TagAssignmentProps): react_jsx_runtime17.JSX.Element | null;
|
|
2588
2601
|
//#endregion
|
|
2589
|
-
export { type ActionConfig, type ActionItem, type ActionPosition, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudExportContext, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudProvider, type AutoCrudProviderProps, type AutoCrudQueryCapabilities, type AutoCrudRowActionContext, type AutoCrudRowOpenOptions, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoFormProps, type AutoQueryParams, AutoTable, AutoTableActionBar, type AutoTableProps, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableClassNames, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, type DataTableProps, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type DataTableViewOptionsProps, type DateFormatPreset, type DateFormatter, type DateLocaleOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldTableDisplay, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportIssue, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, type RowActionConfig, type RowActionDialogProps, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, type SavedView, type SavedViewsConfig, SchemaAdapter, Select, type SelectMode, type SelectOption, type SelectProps, type SelectSearchableDynamicProps, type SelectSearchableMultipleProps, type SelectSearchableProps, type SelectSearchableSingleProps, type SelectSimpleProps, type SelectTriggerRenderProps, type SimpleFieldConfig, type SimpleFieldsConfig, type TableActionBarLocale, type TableControlsLocale, type TablePaginationLocale, type TablePaginationOptions, TagAssignment, type TagAssignmentProps, TagFilter, type TagFilterProps, type TagFilterValue, type TagInput, type TagOption, type TagScope, type TagService, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarBuiltinActionType, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, type ViewInput, type ViewQuery, type ViewStorage, type WorkbookSheet, actionPositionSchema, cn, coerceRowValues, compareOrder, components, createActionsColumn, createEditFormSchema, createFormSchema, createLocalViewStorage, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, exportWorkbook, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, matchesPosition, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, positionActions, resolveLocale, setDateFormatter, setSearchParams, setToolbarResolver, tablePagination, tagFilterValueSchema, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
|
2602
|
+
export { type ActionConfig, type ActionItem, type ActionPosition, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudExportContext, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudProvider, type AutoCrudProviderProps, type AutoCrudQueryCapabilities, type AutoCrudRowActionContext, type AutoCrudRowOpenOptions, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoFormProps, type AutoQueryParams, AutoTable, AutoTableActionBar, type AutoTableProps, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableClassNames, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, type DataTableProps, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type DataTableViewOptionsProps, type DateFormatPreset, type DateFormatter, type DateLocaleOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldTableDisplay, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportIssue, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, type RowActionConfig, type RowActionDialogProps, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, type SavedView, type SavedViewsConfig, SchemaAdapter, Select, type SelectMode, type SelectOption, type SelectProps, type SelectSearchableDynamicProps, type SelectSearchableMultipleProps, type SelectSearchableProps, type SelectSearchableSingleProps, type SelectSimpleProps, type SelectTriggerRenderProps, type SimpleFieldConfig, type SimpleFieldsConfig, type TableActionBarLocale, type TableControlsLocale, type TablePaginationLocale, type TablePaginationOptions, type TableSearchConfig, type TableSearchProps, TagAssignment, type TagAssignmentProps, TagFilter, type TagFilterProps, type TagFilterValue, type TagInput, type TagOption, type TagScope, type TagService, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarBuiltinActionType, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, type ViewInput, type ViewQuery, type ViewStorage, type WorkbookSheet, actionPositionSchema, cn, coerceRowValues, compareOrder, components, createActionsColumn, createEditFormSchema, createFormSchema, createLocalViewStorage, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, exportWorkbook, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, matchesPosition, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, positionActions, resolveLocale, setDateFormatter, setSearchParams, setToolbarResolver, tablePagination, tagFilterValueSchema, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,7 @@ interface UseAutoCrudResourceReturn<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
244
244
|
isLoading: boolean;
|
|
245
245
|
/** 是否正在获取数据(用于显示微妙的加载指示器) */
|
|
246
246
|
isFetching: boolean;
|
|
247
|
+
error?: Error | null;
|
|
247
248
|
};
|
|
248
249
|
/** Optional schema override from host metadata. */
|
|
249
250
|
schema?: z.ZodObject<z.ZodRawShape>;
|
|
@@ -361,6 +362,8 @@ interface UseAutoCrudResourceParams<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
361
362
|
* ```
|
|
362
363
|
*/
|
|
363
364
|
query?: (params: AutoQueryParams) => Record<string, unknown>;
|
|
365
|
+
/** tRPC operation context shared by list and automatic export requests. */
|
|
366
|
+
queryContext?: Record<string, unknown>;
|
|
364
367
|
/** 其他配置选项 */
|
|
365
368
|
options?: UseAutoCrudResourceOptions<TSchema, TListItem>;
|
|
366
369
|
}
|
|
@@ -372,6 +375,7 @@ declare function useAutoCrudResource<TSchema extends z.ZodObject<z.ZodRawShape>,
|
|
|
372
375
|
queryKeys,
|
|
373
376
|
schema,
|
|
374
377
|
query: queryTransform,
|
|
378
|
+
queryContext,
|
|
375
379
|
fields,
|
|
376
380
|
options
|
|
377
381
|
}: UseAutoCrudResourceParams<TSchema, TListItem>): UseAutoCrudResourceReturn<TSchema, TListItem>;
|
|
@@ -1408,6 +1412,19 @@ declare function createActionsColumn<T>(items: ActionsColumnConfig<T>): ColumnDe
|
|
|
1408
1412
|
//#region src/components/auto-crud/auto-table.d.ts
|
|
1409
1413
|
/** 过滤模式类型 */
|
|
1410
1414
|
type FilterMode = 'simple' | 'advanced' | 'command';
|
|
1415
|
+
interface TableSearchProps extends Pick<React.ComponentPropsWithoutRef<'input'>, 'onCompositionStart' | 'onCompositionEnd'> {
|
|
1416
|
+
value: string;
|
|
1417
|
+
onValueChange: (value: string) => void;
|
|
1418
|
+
placeholder: string;
|
|
1419
|
+
/** Reset pagination when an additional search criterion changes. */
|
|
1420
|
+
resetPage: () => void;
|
|
1421
|
+
}
|
|
1422
|
+
interface TableSearchConfig {
|
|
1423
|
+
placeholder?: string;
|
|
1424
|
+
/** Search delay in milliseconds. Defaults to 200; use 0 for immediate queries. */
|
|
1425
|
+
debounceMs?: number;
|
|
1426
|
+
render?: (props: TableSearchProps) => React.ReactNode;
|
|
1427
|
+
}
|
|
1411
1428
|
interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> extends Pick<DataTableProps<z.infer<T>>, 'expandedRow'> {
|
|
1412
1429
|
/** Stable CRUD identity for saved views and tag services. */
|
|
1413
1430
|
resourceId?: string;
|
|
@@ -1447,11 +1464,7 @@ interface AutoTableProps<T extends z.ZodObject<z.ZodRawShape>> extends Pick<Data
|
|
|
1447
1464
|
*/
|
|
1448
1465
|
filterMode?: FilterMode | FilterMode[];
|
|
1449
1466
|
/** 全局搜索框 */
|
|
1450
|
-
search?: boolean |
|
|
1451
|
-
placeholder?: string;
|
|
1452
|
-
/** Search delay in milliseconds. Defaults to 200; use 0 for immediate queries. */
|
|
1453
|
-
debounceMs?: number;
|
|
1454
|
-
};
|
|
1467
|
+
search?: boolean | TableSearchConfig;
|
|
1455
1468
|
/** Extra table controls rendered between sorting and column visibility. */
|
|
1456
1469
|
toolbarExtra?: React.ReactNode;
|
|
1457
1470
|
/** Sorting and column visibility strings. Defaults to English for standalone use. */
|
|
@@ -2586,4 +2599,4 @@ interface TagAssignmentProps extends TagScope, Pick<RowActionDialogProps, 'open'
|
|
|
2586
2599
|
/** Controlled dialog. Callers own the trigger, its appearance and its placement. */
|
|
2587
2600
|
declare function TagAssignment(props: TagAssignmentProps): react_jsx_runtime17.JSX.Element | null;
|
|
2588
2601
|
//#endregion
|
|
2589
|
-
export { type ActionConfig, type ActionItem, type ActionPosition, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudExportContext, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudProvider, type AutoCrudProviderProps, type AutoCrudQueryCapabilities, type AutoCrudRowActionContext, type AutoCrudRowOpenOptions, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoFormProps, type AutoQueryParams, AutoTable, AutoTableActionBar, type AutoTableProps, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableClassNames, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, type DataTableProps, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type DataTableViewOptionsProps, type DateFormatPreset, type DateFormatter, type DateLocaleOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldTableDisplay, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportIssue, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, type RowActionConfig, type RowActionDialogProps, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, type SavedView, type SavedViewsConfig, SchemaAdapter, Select, type SelectMode, type SelectOption, type SelectProps, type SelectSearchableDynamicProps, type SelectSearchableMultipleProps, type SelectSearchableProps, type SelectSearchableSingleProps, type SelectSimpleProps, type SelectTriggerRenderProps, type SimpleFieldConfig, type SimpleFieldsConfig, type TableActionBarLocale, type TableControlsLocale, type TablePaginationLocale, type TablePaginationOptions, TagAssignment, type TagAssignmentProps, TagFilter, type TagFilterProps, type TagFilterValue, type TagInput, type TagOption, type TagScope, type TagService, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarBuiltinActionType, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, type ViewInput, type ViewQuery, type ViewStorage, type WorkbookSheet, actionPositionSchema, cn, coerceRowValues, compareOrder, components, createActionsColumn, createEditFormSchema, createFormSchema, createLocalViewStorage, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, exportWorkbook, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, matchesPosition, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, positionActions, resolveLocale, setDateFormatter, setSearchParams, setToolbarResolver, tablePagination, tagFilterValueSchema, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
|
2602
|
+
export { type ActionConfig, type ActionItem, type ActionPosition, type ActionsColumnConfig, type AutoCrudActionConfig, type AutoCrudActionsConfig, type AutoCrudDataSourceConfig, type AutoCrudDataSourceContext, type AutoCrudDataSourceEntry, type AutoCrudDataSourceLoader, type AutoCrudDataSourceRegistration, type AutoCrudExportContext, type AutoCrudFormComponentConfig, type AutoCrudLocale, type AutoCrudOption, AutoCrudProvider, type AutoCrudProviderProps, type AutoCrudQueryCapabilities, type AutoCrudRowActionContext, type AutoCrudRowOpenOptions, AutoCrudTable, type AutoCrudTableProps, type AutoCrudToolbarContext, type AutoCrudToolbarResolver, AutoForm, type AutoFormProps, type AutoQueryParams, AutoTable, AutoTableActionBar, type AutoTableProps, AutoTableSimpleFilters, type BatchActionConfig, type BatchActionContext, type BatchActionItem, type BatchBuiltinActionItem, type BatchBuiltinActionType, type BatchCustomActionItem, type BatchUpdateField, type ColumnOverrides, type CreateFormSchemaOptions, type CreateTableSchemaOptions, type CrudActionBase, type CrudActionEntry, type CrudActionRegistration, type CrudActionZone, CrudFormModal, type CrudHooks, type CrudOperationPermissions, type CrudPermissions, type DataSource, DataTable, DataTableAdvancedToolbar, DataTableClassNames, DataTableColumnHeader, DataTableFacetedFilter, DataTablePagination, type DataTableProps, DataTableRowAction, DataTableToolbar, DataTableViewOptions, type DataTableViewOptionsProps, type DateFormatPreset, type DateFormatter, type DateLocaleOptions, type EnumOption, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldOption, type FieldTableDisplay, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportIssue, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, type LocaleProp, MultiCombobox, type MultiComboboxOption, type MultiComboboxProps, type MultiComboboxTriggerRenderProps, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, type RowActionConfig, type RowActionDialogProps, type RowActionItem, type RowBuiltinActionItem, type RowBuiltinActionType, type RowCustomActionItem, type SavedView, type SavedViewsConfig, SchemaAdapter, Select, type SelectMode, type SelectOption, type SelectProps, type SelectSearchableDynamicProps, type SelectSearchableMultipleProps, type SelectSearchableProps, type SelectSearchableSingleProps, type SelectSimpleProps, type SelectTriggerRenderProps, type SimpleFieldConfig, type SimpleFieldsConfig, type TableActionBarLocale, type TableControlsLocale, type TablePaginationLocale, type TablePaginationOptions, type TableSearchConfig, type TableSearchProps, TagAssignment, type TagAssignmentProps, TagFilter, type TagFilterProps, type TagFilterValue, type TagInput, type TagOption, type TagScope, type TagService, type ToastAdapter, type ToolbarActionConfig, type ToolbarActionItem, type ToolbarBuiltinActionItem, type ToolbarBuiltinActionType, type ToolbarCustomActionItem, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, type ViewInput, type ViewQuery, type ViewStorage, type WorkbookSheet, actionPositionSchema, cn, coerceRowValues, compareOrder, components, createActionsColumn, createEditFormSchema, createFormSchema, createLocalViewStorage, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, crudActions, dataSources, dataToCSV, deDE, downloadCSVTemplate, enUS, esES, exportAllToCSV, exportTableToCSV, exportWorkbook, formComponents, formatDate, frFR, generateCSVTemplate, getUrlParams, humanize, jaJP, koKR, matchesPosition, noopToastAdapter, normalizeDataSourceConfig, normalizeOptions, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, positionActions, resolveLocale, setDateFormatter, setSearchParams, setToolbarResolver, tablePagination, tagFilterValueSchema, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates, zhCN };
|
package/dist/index.js
CHANGED
|
@@ -5651,12 +5651,13 @@ function SimpleDateFilter({ title, maxDate, multiple, value, onChange }) {
|
|
|
5651
5651
|
|
|
5652
5652
|
//#endregion
|
|
5653
5653
|
//#region src/components/auto-crud/auto-table-search.tsx
|
|
5654
|
-
function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "page" }) {
|
|
5654
|
+
function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "page", render }) {
|
|
5655
5655
|
const [value, setValue] = useState(() => getUrlParams().get("search") ?? "");
|
|
5656
|
+
const valueRef = useRef(value);
|
|
5656
5657
|
const composing = useRef(false);
|
|
5657
|
-
const commit = useCallback((next) => {
|
|
5658
|
+
const commit = useCallback((next, resetPage = false) => {
|
|
5658
5659
|
const params = getUrlParams();
|
|
5659
|
-
if ((params.get("search") ?? "") === next) return;
|
|
5660
|
+
if ((params.get("search") ?? "") === next && !resetPage) return;
|
|
5660
5661
|
if (next) params.set("search", next);
|
|
5661
5662
|
else params.delete("search");
|
|
5662
5663
|
params.delete(pageKey);
|
|
@@ -5667,7 +5668,8 @@ function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "
|
|
|
5667
5668
|
useEffect(() => {
|
|
5668
5669
|
const sync = () => {
|
|
5669
5670
|
cancel();
|
|
5670
|
-
|
|
5671
|
+
valueRef.current = getUrlParams().get("search") ?? "";
|
|
5672
|
+
setValue(valueRef.current);
|
|
5671
5673
|
};
|
|
5672
5674
|
window.addEventListener("popstate", sync);
|
|
5673
5675
|
window.addEventListener("urlchange", sync);
|
|
@@ -5678,23 +5680,37 @@ function AutoTableSearch({ placeholder = "搜索", debounceMs = 200, pageKey = "
|
|
|
5678
5680
|
};
|
|
5679
5681
|
}, [cancel, pageKey]);
|
|
5680
5682
|
const change = (next) => {
|
|
5683
|
+
valueRef.current = next;
|
|
5681
5684
|
setValue(next);
|
|
5682
5685
|
cancel();
|
|
5683
5686
|
if (composing.current) return;
|
|
5684
5687
|
if (!next || debounceMs <= 0) commit(next);
|
|
5685
5688
|
else debouncedCommit(next);
|
|
5686
5689
|
};
|
|
5690
|
+
const onCompositionStart = () => {
|
|
5691
|
+
composing.current = true;
|
|
5692
|
+
cancel();
|
|
5693
|
+
};
|
|
5694
|
+
const onCompositionEnd = (event) => {
|
|
5695
|
+
composing.current = false;
|
|
5696
|
+
change(event.currentTarget.value);
|
|
5697
|
+
};
|
|
5698
|
+
if (render) return render({
|
|
5699
|
+
value,
|
|
5700
|
+
onValueChange: change,
|
|
5701
|
+
onCompositionStart,
|
|
5702
|
+
onCompositionEnd,
|
|
5703
|
+
placeholder,
|
|
5704
|
+
resetPage: () => {
|
|
5705
|
+
cancel();
|
|
5706
|
+
commit(valueRef.current, true);
|
|
5707
|
+
}
|
|
5708
|
+
});
|
|
5687
5709
|
return /* @__PURE__ */ jsx(Input, {
|
|
5688
5710
|
value,
|
|
5689
5711
|
onChange: (event) => change(event.target.value),
|
|
5690
|
-
onCompositionStart
|
|
5691
|
-
|
|
5692
|
-
cancel();
|
|
5693
|
-
},
|
|
5694
|
-
onCompositionEnd: (event) => {
|
|
5695
|
-
composing.current = false;
|
|
5696
|
-
change(event.currentTarget.value);
|
|
5697
|
-
},
|
|
5712
|
+
onCompositionStart,
|
|
5713
|
+
onCompositionEnd,
|
|
5698
5714
|
placeholder,
|
|
5699
5715
|
className: "h-8 w-48 shrink-0"
|
|
5700
5716
|
});
|
|
@@ -10859,7 +10875,7 @@ function modalReducer(state, action$1) {
|
|
|
10859
10875
|
/**
|
|
10860
10876
|
* Hook 主函数
|
|
10861
10877
|
*/
|
|
10862
|
-
function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform, fields, options = {} }) {
|
|
10878
|
+
function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform, queryContext, fields, options = {} }) {
|
|
10863
10879
|
const { idKey = "id", defaultVariant = "dialog", hooks, toast: toastAdapter, exportFetcher, defaultSort: defaultSortOption } = options;
|
|
10864
10880
|
const toast$1 = useMemo(() => toastAdapter === false ? noopToastAdapter : toastAdapter ?? defaultToastAdapter, [toastAdapter]);
|
|
10865
10881
|
const hooksRef = useRef(hooks);
|
|
@@ -10914,6 +10930,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
10914
10930
|
]);
|
|
10915
10931
|
const hasReadyListData = useRef(false);
|
|
10916
10932
|
const listQuery = router.list.useQuery(queryInput, {
|
|
10933
|
+
...queryContext !== void 0 ? { trpc: { context: queryContext } } : {},
|
|
10917
10934
|
enabled: listReady,
|
|
10918
10935
|
placeholderData: hasReadyListData.current ? keepPreviousData : void 0,
|
|
10919
10936
|
staleTime: 0
|
|
@@ -10934,7 +10951,10 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
10934
10951
|
const { page: _p, perPage: _pp,...rest } = queryInput;
|
|
10935
10952
|
return rest;
|
|
10936
10953
|
}, [queryInput]);
|
|
10937
|
-
const exportQuery = router.export?.useQuery(exportInput, {
|
|
10954
|
+
const exportQuery = router.export?.useQuery(exportInput, {
|
|
10955
|
+
enabled: false,
|
|
10956
|
+
...queryContext !== void 0 ? { trpc: { context: queryContext } } : {}
|
|
10957
|
+
});
|
|
10938
10958
|
const [modal, dispatch] = useReducer(modalReducer, {
|
|
10939
10959
|
createOpen: false,
|
|
10940
10960
|
editOpen: false,
|
|
@@ -11191,7 +11211,8 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
|
|
|
11191
11211
|
pageCount: listData?.pageCount ?? 0,
|
|
11192
11212
|
...typeof listData?.total === "number" ? { total: listData.total } : {},
|
|
11193
11213
|
isLoading: !listReady || listQuery.isLoading,
|
|
11194
|
-
isFetching: !listReady || listQuery.isFetching
|
|
11214
|
+
isFetching: !listReady || listQuery.isFetching,
|
|
11215
|
+
error: listQuery.error
|
|
11195
11216
|
},
|
|
11196
11217
|
schema: resolvedSchema,
|
|
11197
11218
|
metadataPending,
|
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.16.0",
|
|
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.
|
|
74
|
+
"@wordrhyme/formily-shadcn": "2.1.3",
|
|
75
75
|
"@wordrhyme/shadcn": "2.0.2",
|
|
76
|
-
"@wordrhyme/shadcn-ui": "2.1.
|
|
76
|
+
"@wordrhyme/shadcn-ui": "2.1.3"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@storybook/react": "^8.6.18",
|