@wordrhyme/auto-crud 0.10.0 → 1.0.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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime1 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
2
2
  import { z } from "zod";
3
3
  import * as _tanstack_react_table0 from "@tanstack/react-table";
4
4
  import { Column, ColumnDef, ColumnSort, Row, RowData, Table, TableOptions, TableState } from "@tanstack/react-table";
@@ -314,7 +314,7 @@ declare function AutoTableActionBar<TData>({
314
314
  enableExport,
315
315
  enableDelete,
316
316
  extraActions
317
- }: AutoTableActionBarProps<TData>): react_jsx_runtime1.JSX.Element;
317
+ }: AutoTableActionBarProps<TData>): react_jsx_runtime3.JSX.Element;
318
318
  //#endregion
319
319
  //#region src/lib/schema-bridge/types.d.ts
320
320
  /**
@@ -463,9 +463,34 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
463
463
  enableExport,
464
464
  onSelectedCountChange,
465
465
  getSelectedRows
466
- }: AutoTableProps<T>): react_jsx_runtime1.JSX.Element;
466
+ }: AutoTableProps<T>): react_jsx_runtime3.JSX.Element;
467
467
  //#endregion
468
468
  //#region src/components/auto-crud/auto-crud-table.d.ts
469
+ /**
470
+ * 筛选器独立配置
471
+ * 可独立于 table.meta 配置筛选器行为
472
+ */
473
+ interface FilterConfig {
474
+ /** 是否启用筛选(默认跟随 table.meta.variant 推断) */
475
+ enabled?: boolean;
476
+ /** 筛选器类型 */
477
+ variant?: "text" | "number" | "range" | "date" | "dateRange" | "boolean" | "select" | "multiSelect";
478
+ /** select/multiSelect 的选项列表 */
479
+ options?: Array<{
480
+ label: string;
481
+ value: string;
482
+ count?: number;
483
+ icon?: React$1.FC<React$1.SVGProps<SVGSVGElement>>;
484
+ }>;
485
+ /** range 的最小/最大值 */
486
+ range?: [number, number];
487
+ /** number 的单位 */
488
+ unit?: string;
489
+ /** 过滤器占位符 */
490
+ placeholder?: string;
491
+ /** 是否在筛选栏中隐藏(隐藏筛选但不影响表格列显示) */
492
+ hidden?: boolean;
493
+ }
469
494
  /**
470
495
  * 统一字段配置
471
496
  * 支持共用配置 + 表格/表单特定配置
@@ -475,6 +500,11 @@ interface Field {
475
500
  label?: string;
476
501
  /** 是否隐藏(表格和表单都隐藏) */
477
502
  hidden?: boolean;
503
+ /**
504
+ * 筛选器独立配置
505
+ * 独立于 table.meta 控制筛选器行为,不影响表格列显示/隐藏
506
+ */
507
+ filter?: FilterConfig;
478
508
  /** 表格特定配置 */
479
509
  table?: {
480
510
  /** 是否在表格中隐藏 */
@@ -591,7 +621,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
591
621
  form: formConfig,
592
622
  slots,
593
623
  permissions
594
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime1.JSX.Element;
624
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime3.JSX.Element;
595
625
  //#endregion
596
626
  //#region src/components/auto-crud/auto-form.d.ts
597
627
  interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
@@ -623,11 +653,87 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
623
653
  labelAlign,
624
654
  labelWidth,
625
655
  showSubmitButton
626
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime1.JSX.Element;
656
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime3.JSX.Element;
627
657
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
628
658
  ref?: React.Ref<AutoFormRef>;
629
659
  }) => ReturnType<typeof AutoFormInner>;
630
660
  //#endregion
661
+ //#region src/hooks/use-url-state.d.ts
662
+ /**
663
+ * URL 状态管理 Hook - 替代 nuqs
664
+ * 将 React 状态同步到 URL query string
665
+ *
666
+ * 架构说明:
667
+ * - 使用 queueMicrotask 延迟 URL 更新,确保在渲染完成后执行
668
+ * - 符合 React 渲染规则,不会触发 "Cannot update a component while rendering" 错误
669
+ */
670
+ interface UrlStateOptions {
671
+ /** 历史记录模式: push 添加新记录, replace 替换当前记录 */
672
+ history?: "push" | "replace";
673
+ /** 是否浅层更新(不触发页面刷新) */
674
+ shallow?: boolean;
675
+ /** 节流时间(毫秒) */
676
+ throttleMs?: number;
677
+ /** 防抖时间(毫秒) */
678
+ debounceMs?: number;
679
+ /** 当值等于默认值时是否清除 URL 参数 */
680
+ clearOnDefault?: boolean;
681
+ /** 滚动到顶部 */
682
+ scroll?: boolean;
683
+ /** React transition */
684
+ startTransition?: React$1.TransitionStartFunction;
685
+ }
686
+ interface Parser<T> {
687
+ parse: (value: string) => T;
688
+ serialize: (value: T) => string;
689
+ }
690
+ declare const parseAsInteger: Parser<number> & {
691
+ withDefault: (defaultValue: number) => Parser<number> & {
692
+ defaultValue: number;
693
+ };
694
+ };
695
+ declare const parseAsString: Parser<string> & {
696
+ withDefault: (defaultValue: string) => Parser<string> & {
697
+ defaultValue: string;
698
+ };
699
+ };
700
+ declare function parseAsStringEnum<T extends string>(validValues: readonly T[]): Parser<T | null> & {
701
+ withDefault: (defaultValue: T) => Parser<T> & {
702
+ defaultValue: T;
703
+ };
704
+ };
705
+ declare function parseAsArrayOf<T>(itemParser: Parser<T>, separator?: string): Parser<T[]> & {
706
+ withDefault: (defaultValue: T[]) => Parser<T[]> & {
707
+ defaultValue: T[];
708
+ };
709
+ };
710
+ declare function getUrlParams(): URLSearchParams;
711
+ declare function setSearchParams(params: URLSearchParams, options?: Pick<UrlStateOptions, "history" | "scroll">): void;
712
+ /**
713
+ * 单个 URL 状态参数
714
+ */
715
+ declare function useUrlState<T>(key: string, parser: Parser<T> & {
716
+ defaultValue?: T;
717
+ }, options?: UrlStateOptions): [T, (value: T | ((prev: T) => T)) => void];
718
+ /**
719
+ * 多个 URL 状态参数
720
+ */
721
+ declare function useUrlStates<T extends Record<string, unknown>>(parsers: { [K in keyof T]: Parser<T[K]> & {
722
+ defaultValue?: T[K];
723
+ } }, options?: UrlStateOptions): [T, (values: Partial<T>) => void];
724
+ /**
725
+ * nuqs 兼容层 - useQueryState
726
+ */
727
+ declare function useQueryState<T>(key: string, parser: Parser<T> & {
728
+ defaultValue?: T;
729
+ }, options?: UrlStateOptions): [T, (value: T | ((prev: T) => T)) => Promise<URLSearchParams>];
730
+ /**
731
+ * nuqs 兼容层 - useQueryStates
732
+ */
733
+ declare function useQueryStates<T extends Record<string, unknown>>(parsers: { [K in keyof T]: Parser<T[K]> & {
734
+ defaultValue?: T[K];
735
+ } }, options?: UrlStateOptions): [T, (values: Partial<T>) => Promise<URLSearchParams>];
736
+ //#endregion
631
737
  //#region src/config/data-table.d.ts
632
738
  type DataTableConfig = typeof dataTableConfig;
633
739
  declare const dataTableConfig: {
@@ -754,82 +860,6 @@ declare const dataTableConfig: {
754
860
  joinOperators: readonly ["and", "or"];
755
861
  };
756
862
  //#endregion
757
- //#region src/hooks/use-url-state.d.ts
758
- /**
759
- * URL 状态管理 Hook - 替代 nuqs
760
- * 将 React 状态同步到 URL query string
761
- *
762
- * 架构说明:
763
- * - 使用 queueMicrotask 延迟 URL 更新,确保在渲染完成后执行
764
- * - 符合 React 渲染规则,不会触发 "Cannot update a component while rendering" 错误
765
- */
766
- interface UrlStateOptions {
767
- /** 历史记录模式: push 添加新记录, replace 替换当前记录 */
768
- history?: "push" | "replace";
769
- /** 是否浅层更新(不触发页面刷新) */
770
- shallow?: boolean;
771
- /** 节流时间(毫秒) */
772
- throttleMs?: number;
773
- /** 防抖时间(毫秒) */
774
- debounceMs?: number;
775
- /** 当值等于默认值时是否清除 URL 参数 */
776
- clearOnDefault?: boolean;
777
- /** 滚动到顶部 */
778
- scroll?: boolean;
779
- /** React transition */
780
- startTransition?: React$1.TransitionStartFunction;
781
- }
782
- interface Parser<T> {
783
- parse: (value: string) => T;
784
- serialize: (value: T) => string;
785
- }
786
- declare const parseAsInteger: Parser<number> & {
787
- withDefault: (defaultValue: number) => Parser<number> & {
788
- defaultValue: number;
789
- };
790
- };
791
- declare const parseAsString: Parser<string> & {
792
- withDefault: (defaultValue: string) => Parser<string> & {
793
- defaultValue: string;
794
- };
795
- };
796
- declare function parseAsStringEnum<T extends string>(validValues: readonly T[]): Parser<T | null> & {
797
- withDefault: (defaultValue: T) => Parser<T> & {
798
- defaultValue: T;
799
- };
800
- };
801
- declare function parseAsArrayOf<T>(itemParser: Parser<T>, separator?: string): Parser<T[]> & {
802
- withDefault: (defaultValue: T[]) => Parser<T[]> & {
803
- defaultValue: T[];
804
- };
805
- };
806
- declare function getUrlParams(): URLSearchParams;
807
- declare function setSearchParams(params: URLSearchParams, options?: Pick<UrlStateOptions, "history" | "scroll">): void;
808
- /**
809
- * 单个 URL 状态参数
810
- */
811
- declare function useUrlState<T>(key: string, parser: Parser<T> & {
812
- defaultValue?: T;
813
- }, options?: UrlStateOptions): [T, (value: T | ((prev: T) => T)) => void];
814
- /**
815
- * 多个 URL 状态参数
816
- */
817
- declare function useUrlStates<T extends Record<string, unknown>>(parsers: { [K in keyof T]: Parser<T[K]> & {
818
- defaultValue?: T[K];
819
- } }, options?: UrlStateOptions): [T, (values: Partial<T>) => void];
820
- /**
821
- * nuqs 兼容层 - useQueryState
822
- */
823
- declare function useQueryState<T>(key: string, parser: Parser<T> & {
824
- defaultValue?: T;
825
- }, options?: UrlStateOptions): [T, (value: T | ((prev: T) => T)) => Promise<URLSearchParams>];
826
- /**
827
- * nuqs 兼容层 - useQueryStates
828
- */
829
- declare function useQueryStates<T extends Record<string, unknown>>(parsers: { [K in keyof T]: Parser<T[K]> & {
830
- defaultValue?: T[K];
831
- } }, options?: UrlStateOptions): [T, (values: Partial<T>) => Promise<URLSearchParams>];
832
- //#endregion
833
863
  //#region src/lib/parsers.d.ts
834
864
  declare const filterItemSchema: z.ZodObject<{
835
865
  id: z.ZodString;
@@ -868,6 +898,7 @@ type FilterItemSchema = z.infer<typeof filterItemSchema>;
868
898
  declare module "@tanstack/react-table" {
869
899
  interface TableMeta<TData extends RowData> {
870
900
  queryKeys?: QueryKeys;
901
+ queryStateOptions?: UrlStateOptions;
871
902
  }
872
903
  interface ColumnMeta<TData extends RowData, TValue> {
873
904
  label?: string;
@@ -918,7 +949,7 @@ declare function AutoTableSimpleFilters<TData>({
918
949
  shallow,
919
950
  filters: externalFilters,
920
951
  onFiltersChange
921
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime1.JSX.Element | null;
952
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime3.JSX.Element | null;
922
953
  //#endregion
923
954
  //#region src/components/auto-crud/form-modal.d.ts
924
955
  type ModalVariant = "dialog" | "sheet";
@@ -953,7 +984,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
953
984
  title,
954
985
  labelAlign,
955
986
  labelWidth
956
- }: CrudFormModalProps<T>): react_jsx_runtime1.JSX.Element;
987
+ }: CrudFormModalProps<T>): react_jsx_runtime3.JSX.Element;
957
988
  //#endregion
958
989
  //#region src/components/auto-crud/import-dialog.d.ts
959
990
  interface ImportDialogProps {
@@ -972,7 +1003,7 @@ declare function ImportDialog({
972
1003
  onImport,
973
1004
  columns,
974
1005
  title
975
- }: ImportDialogProps): react_jsx_runtime1.JSX.Element;
1006
+ }: ImportDialogProps): react_jsx_runtime3.JSX.Element;
976
1007
  //#endregion
977
1008
  //#region src/components/auto-crud/export-dialog.d.ts
978
1009
  type ExportMode = "selected" | "filtered";
@@ -992,7 +1023,7 @@ declare function ExportDialog({
992
1023
  selectedCount,
993
1024
  onExport,
994
1025
  canExportFiltered
995
- }: ExportDialogProps): react_jsx_runtime1.JSX.Element;
1026
+ }: ExportDialogProps): react_jsx_runtime3.JSX.Element;
996
1027
  //#endregion
997
1028
  //#region src/components/data-table/data-table.d.ts
998
1029
  interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1005,7 +1036,7 @@ declare function DataTable<TData>({
1005
1036
  children,
1006
1037
  className,
1007
1038
  ...props
1008
- }: DataTableProps<TData>): react_jsx_runtime1.JSX.Element;
1039
+ }: DataTableProps<TData>): react_jsx_runtime3.JSX.Element;
1009
1040
  //#endregion
1010
1041
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
1011
1042
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1016,7 +1047,7 @@ declare function DataTableAdvancedToolbar<TData>({
1016
1047
  children,
1017
1048
  className,
1018
1049
  ...props
1019
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime1.JSX.Element;
1050
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1020
1051
  //#endregion
1021
1052
  //#region src/components/data-table/data-table-column-header.d.ts
1022
1053
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -1028,7 +1059,7 @@ declare function DataTableColumnHeader<TData, TValue>({
1028
1059
  label,
1029
1060
  className,
1030
1061
  ...props
1031
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime1.JSX.Element;
1062
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1032
1063
  //#endregion
1033
1064
  //#region src/components/data-table/data-table-faceted-filter.d.ts
1034
1065
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -1042,7 +1073,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
1042
1073
  title,
1043
1074
  options,
1044
1075
  multiple
1045
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime1.JSX.Element;
1076
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1046
1077
  //#endregion
1047
1078
  //#region src/components/data-table/data-table-pagination.d.ts
1048
1079
  interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
@@ -1054,7 +1085,7 @@ declare function DataTablePagination<TData>({
1054
1085
  pageSizeOptions,
1055
1086
  className,
1056
1087
  ...props
1057
- }: DataTablePaginationProps<TData>): react_jsx_runtime1.JSX.Element;
1088
+ }: DataTablePaginationProps<TData>): react_jsx_runtime3.JSX.Element;
1058
1089
  //#endregion
1059
1090
  //#region src/components/data-table/data-table-toolbar.d.ts
1060
1091
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1065,7 +1096,7 @@ declare function DataTableToolbar<TData>({
1065
1096
  children,
1066
1097
  className,
1067
1098
  ...props
1068
- }: DataTableToolbarProps<TData>): react_jsx_runtime1.JSX.Element;
1099
+ }: DataTableToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1069
1100
  //#endregion
1070
1101
  //#region src/components/data-table/data-table-view-options.d.ts
1071
1102
  interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
@@ -1076,7 +1107,7 @@ declare function DataTableViewOptions<TData>({
1076
1107
  table,
1077
1108
  disabled,
1078
1109
  ...props
1079
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime1.JSX.Element;
1110
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime3.JSX.Element;
1080
1111
  //#endregion
1081
1112
  //#region src/hooks/use-data-table.d.ts
1082
1113
  interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
@@ -1411,4 +1442,4 @@ declare function exportAllToCSV<T extends Record<string, unknown>>(data: T[], op
1411
1442
  */
1412
1443
  declare function downloadCSVTemplate(headers: string[], filename?: string): void;
1413
1444
  //#endregion
1414
- export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, 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, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataToCSV, downloadCSVTemplate, exportAllToCSV, exportTableToCSV, formatDate, generateCSVTemplate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };
1445
+ export { type ActionsColumnConfig, AutoCrudTable, type AutoCrudTableProps, AutoForm, type AutoQueryParams, 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, ExportDialog, type ExportDialogProps, type ExportMode, ExtendedColumnFilter, ExtendedColumnSort, type Field, type FieldType, type Fields, type FilterConfig, FilterOperator, type FilterVariant, type FormSchemaOverrides, ImportDialog, type ImportDialogProps, type ImportResult, type JSONSchema, type JSONSchemaProperty, JoinOperator, type ListParams, type ListResult, Option, type ParsedImportData, type ParsedZodField, type Parser, QueryKeys, SchemaAdapter, type SimpleFieldConfig, type SimpleFieldsConfig, type ToastAdapter, type UnifiedField, type UnifiedSchema, type UrlStateOptions, type UseAutoCrudResourceOptions, type UseAutoCrudResourceParams, type UseAutoCrudResourceReturn, cn, coerceRowValues, createActionsColumn, createEditFormSchema, createFormSchema, createMemoryDataSource, createSelectColumn, createTRPCDataSource, createTableSchema, dataToCSV, downloadCSVTemplate, exportAllToCSV, exportTableToCSV, formatDate, generateCSVTemplate, getUrlParams, humanize, noopToastAdapter, parseAsArrayOf, parseAsInteger, parseAsString, parseAsStringEnum, parseCSV, parseImportFile, parseJSON, parseZodField, setSearchParams, useAutoCrudResource, useDataTable, useQueryState, useQueryStates, useReadableFilters, useUrlState, useUrlStates };