@wordrhyme/auto-crud 1.0.9 → 1.1.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 CHANGED
@@ -825,10 +825,14 @@ function useQueryStates(parsers, options = {}) {
825
825
  //#endregion
826
826
  //#region src/hooks/use-readable-filters.ts
827
827
  const URL_CHANGE_EVENT = "urlchange";
828
+ function toSearchString(params) {
829
+ const queryString = params.toString().replace(/%2C/g, ",");
830
+ return queryString ? `?${queryString}` : "";
831
+ }
828
832
  function useReadableFilters(columns, options = {}) {
829
833
  const { history = "replace", scroll = false } = options;
830
834
  const columnSnapshot = react.useMemo(() => columns, [columns]);
831
- const lastWrittenUrlRef = react.useRef("");
835
+ const lastWrittenUrlRef = react.useRef(null);
832
836
  const filtersRef = react.useRef(null);
833
837
  const [filters, setFilters] = react.useState(() => {
834
838
  const initial = parseReadableFilters(getUrlParams(), columnSnapshot);
@@ -837,7 +841,10 @@ function useReadableFilters(columns, options = {}) {
837
841
  });
838
842
  react.useEffect(() => {
839
843
  const handleUrlChange = () => {
840
- if (window.location.search === lastWrittenUrlRef.current) return;
844
+ if (lastWrittenUrlRef.current !== null && window.location.search === lastWrittenUrlRef.current) {
845
+ lastWrittenUrlRef.current = null;
846
+ return;
847
+ }
841
848
  const next = parseReadableFilters(getUrlParams(), columnSnapshot);
842
849
  filtersRef.current = next;
843
850
  setFilters(next);
@@ -852,11 +859,11 @@ function useReadableFilters(columns, options = {}) {
852
859
  const writeToUrl = react.useCallback((next) => {
853
860
  const params = getUrlParams();
854
861
  applyReadableFilters(params, columnSnapshot, next);
862
+ lastWrittenUrlRef.current = toSearchString(params);
855
863
  setSearchParams(params, {
856
864
  history,
857
865
  scroll
858
866
  });
859
- lastWrittenUrlRef.current = `?${params.toString()}`;
860
867
  }, [
861
868
  columnSnapshot,
862
869
  history,
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_runtime9 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_runtime9.JSX.Element;
318
318
  //#endregion
319
319
  //#region src/lib/schema-bridge/types.d.ts
320
320
  /**
@@ -470,7 +470,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
470
470
  enableExport,
471
471
  onSelectedCountChange,
472
472
  getSelectedRows
473
- }: AutoTableProps<T>): react_jsx_runtime1.JSX.Element;
473
+ }: AutoTableProps<T>): react_jsx_runtime9.JSX.Element;
474
474
  //#endregion
475
475
  //#region src/i18n/locale.d.ts
476
476
  /**
@@ -797,7 +797,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
797
797
  toolbarActions,
798
798
  locale: localeProp,
799
799
  onCreate
800
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime1.JSX.Element;
800
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime9.JSX.Element;
801
801
  //#endregion
802
802
  //#region src/components/auto-crud/auto-form.d.ts
803
803
  interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
@@ -829,7 +829,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
829
829
  labelAlign,
830
830
  labelWidth,
831
831
  showSubmitButton
832
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime1.JSX.Element;
832
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime9.JSX.Element;
833
833
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
834
834
  ref?: React.Ref<AutoFormRef>;
835
835
  }) => ReturnType<typeof AutoFormInner>;
@@ -1127,7 +1127,7 @@ declare function AutoTableSimpleFilters<TData>({
1127
1127
  shallow,
1128
1128
  filters: externalFilters,
1129
1129
  onFiltersChange
1130
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime1.JSX.Element | null;
1130
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime9.JSX.Element | null;
1131
1131
  //#endregion
1132
1132
  //#region src/components/auto-crud/form-modal.d.ts
1133
1133
  type ModalVariant = "dialog" | "sheet";
@@ -1169,7 +1169,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
1169
1169
  labelAlign,
1170
1170
  labelWidth,
1171
1171
  className
1172
- }: CrudFormModalProps<T>): react_jsx_runtime1.JSX.Element;
1172
+ }: CrudFormModalProps<T>): react_jsx_runtime9.JSX.Element;
1173
1173
  //#endregion
1174
1174
  //#region src/components/auto-crud/import-dialog.d.ts
1175
1175
  interface ImportDialogProps {
@@ -1191,7 +1191,7 @@ declare function ImportDialog({
1191
1191
  columns,
1192
1192
  title,
1193
1193
  locale
1194
- }: ImportDialogProps): react_jsx_runtime1.JSX.Element;
1194
+ }: ImportDialogProps): react_jsx_runtime9.JSX.Element;
1195
1195
  //#endregion
1196
1196
  //#region src/components/auto-crud/export-dialog.d.ts
1197
1197
  type ExportMode = "selected" | "filtered";
@@ -1211,7 +1211,7 @@ declare function ExportDialog({
1211
1211
  selectedCount,
1212
1212
  onExport,
1213
1213
  canExportFiltered
1214
- }: ExportDialogProps): react_jsx_runtime1.JSX.Element;
1214
+ }: ExportDialogProps): react_jsx_runtime9.JSX.Element;
1215
1215
  //#endregion
1216
1216
  //#region src/components/data-table/data-table.d.ts
1217
1217
  interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1224,7 +1224,7 @@ declare function DataTable<TData>({
1224
1224
  children,
1225
1225
  className,
1226
1226
  ...props
1227
- }: DataTableProps<TData>): react_jsx_runtime1.JSX.Element;
1227
+ }: DataTableProps<TData>): react_jsx_runtime9.JSX.Element;
1228
1228
  //#endregion
1229
1229
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
1230
1230
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1235,7 +1235,7 @@ declare function DataTableAdvancedToolbar<TData>({
1235
1235
  children,
1236
1236
  className,
1237
1237
  ...props
1238
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime1.JSX.Element;
1238
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime9.JSX.Element;
1239
1239
  //#endregion
1240
1240
  //#region src/components/data-table/data-table-column-header.d.ts
1241
1241
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -1247,7 +1247,7 @@ declare function DataTableColumnHeader<TData, TValue>({
1247
1247
  label,
1248
1248
  className,
1249
1249
  ...props
1250
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime1.JSX.Element;
1250
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime9.JSX.Element;
1251
1251
  //#endregion
1252
1252
  //#region src/components/data-table/data-table-faceted-filter.d.ts
1253
1253
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -1261,7 +1261,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
1261
1261
  title,
1262
1262
  options,
1263
1263
  multiple
1264
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime1.JSX.Element;
1264
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime9.JSX.Element;
1265
1265
  //#endregion
1266
1266
  //#region src/components/data-table/data-table-pagination.d.ts
1267
1267
  interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
@@ -1273,7 +1273,7 @@ declare function DataTablePagination<TData>({
1273
1273
  pageSizeOptions,
1274
1274
  className,
1275
1275
  ...props
1276
- }: DataTablePaginationProps<TData>): react_jsx_runtime1.JSX.Element;
1276
+ }: DataTablePaginationProps<TData>): react_jsx_runtime9.JSX.Element;
1277
1277
  //#endregion
1278
1278
  //#region src/components/data-table/data-table-toolbar.d.ts
1279
1279
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1284,7 +1284,7 @@ declare function DataTableToolbar<TData>({
1284
1284
  children,
1285
1285
  className,
1286
1286
  ...props
1287
- }: DataTableToolbarProps<TData>): react_jsx_runtime1.JSX.Element;
1287
+ }: DataTableToolbarProps<TData>): react_jsx_runtime9.JSX.Element;
1288
1288
  //#endregion
1289
1289
  //#region src/components/data-table/data-table-view-options.d.ts
1290
1290
  interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
@@ -1295,7 +1295,7 @@ declare function DataTableViewOptions<TData>({
1295
1295
  table,
1296
1296
  disabled,
1297
1297
  ...props
1298
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime1.JSX.Element;
1298
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime9.JSX.Element;
1299
1299
  //#endregion
1300
1300
  //#region src/hooks/use-data-table.d.ts
1301
1301
  interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
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 react_jsx_runtime2 from "react/jsx-runtime";
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
 
@@ -314,7 +314,7 @@ declare function AutoTableActionBar<TData>({
314
314
  enableExport,
315
315
  enableDelete,
316
316
  extraActions
317
- }: AutoTableActionBarProps<TData>): react_jsx_runtime2.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
  /**
@@ -470,7 +470,7 @@ declare function AutoTable<T extends z.ZodObject<z.ZodRawShape>>({
470
470
  enableExport,
471
471
  onSelectedCountChange,
472
472
  getSelectedRows
473
- }: AutoTableProps<T>): react_jsx_runtime2.JSX.Element;
473
+ }: AutoTableProps<T>): react_jsx_runtime3.JSX.Element;
474
474
  //#endregion
475
475
  //#region src/i18n/locale.d.ts
476
476
  /**
@@ -797,7 +797,7 @@ declare function AutoCrudTable<TSchema extends z.ZodObject<z.ZodRawShape>>({
797
797
  toolbarActions,
798
798
  locale: localeProp,
799
799
  onCreate
800
- }: AutoCrudTableProps<TSchema>): react_jsx_runtime2.JSX.Element;
800
+ }: AutoCrudTableProps<TSchema>): react_jsx_runtime3.JSX.Element;
801
801
  //#endregion
802
802
  //#region src/components/auto-crud/auto-form.d.ts
803
803
  interface AutoFormProps<T extends z.ZodObject<z.ZodRawShape>> {
@@ -829,7 +829,7 @@ declare function AutoFormInner<T extends z.ZodObject<z.ZodRawShape>>({
829
829
  labelAlign,
830
830
  labelWidth,
831
831
  showSubmitButton
832
- }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime2.JSX.Element;
832
+ }: AutoFormProps<T>, ref: React.Ref<AutoFormRef>): react_jsx_runtime3.JSX.Element;
833
833
  declare const AutoForm: <T extends z.ZodObject<z.ZodRawShape>>(props: AutoFormProps<T> & {
834
834
  ref?: React.Ref<AutoFormRef>;
835
835
  }) => ReturnType<typeof AutoFormInner>;
@@ -1127,7 +1127,7 @@ declare function AutoTableSimpleFilters<TData>({
1127
1127
  shallow,
1128
1128
  filters: externalFilters,
1129
1129
  onFiltersChange
1130
- }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime2.JSX.Element | null;
1130
+ }: AutoTableSimpleFiltersProps<TData>): react_jsx_runtime3.JSX.Element | null;
1131
1131
  //#endregion
1132
1132
  //#region src/components/auto-crud/form-modal.d.ts
1133
1133
  type ModalVariant = "dialog" | "sheet";
@@ -1169,7 +1169,7 @@ declare function CrudFormModal<T extends z.ZodObject<z.ZodRawShape>>({
1169
1169
  labelAlign,
1170
1170
  labelWidth,
1171
1171
  className
1172
- }: CrudFormModalProps<T>): react_jsx_runtime2.JSX.Element;
1172
+ }: CrudFormModalProps<T>): react_jsx_runtime3.JSX.Element;
1173
1173
  //#endregion
1174
1174
  //#region src/components/auto-crud/import-dialog.d.ts
1175
1175
  interface ImportDialogProps {
@@ -1191,7 +1191,7 @@ declare function ImportDialog({
1191
1191
  columns,
1192
1192
  title,
1193
1193
  locale
1194
- }: ImportDialogProps): react_jsx_runtime2.JSX.Element;
1194
+ }: ImportDialogProps): react_jsx_runtime3.JSX.Element;
1195
1195
  //#endregion
1196
1196
  //#region src/components/auto-crud/export-dialog.d.ts
1197
1197
  type ExportMode = "selected" | "filtered";
@@ -1211,7 +1211,7 @@ declare function ExportDialog({
1211
1211
  selectedCount,
1212
1212
  onExport,
1213
1213
  canExportFiltered
1214
- }: ExportDialogProps): react_jsx_runtime2.JSX.Element;
1214
+ }: ExportDialogProps): react_jsx_runtime3.JSX.Element;
1215
1215
  //#endregion
1216
1216
  //#region src/components/data-table/data-table.d.ts
1217
1217
  interface DataTableProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1224,7 +1224,7 @@ declare function DataTable<TData>({
1224
1224
  children,
1225
1225
  className,
1226
1226
  ...props
1227
- }: DataTableProps<TData>): react_jsx_runtime2.JSX.Element;
1227
+ }: DataTableProps<TData>): react_jsx_runtime3.JSX.Element;
1228
1228
  //#endregion
1229
1229
  //#region src/components/data-table/data-table-advanced-toolbar.d.ts
1230
1230
  interface DataTableAdvancedToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1235,7 +1235,7 @@ declare function DataTableAdvancedToolbar<TData>({
1235
1235
  children,
1236
1236
  className,
1237
1237
  ...props
1238
- }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
1238
+ }: DataTableAdvancedToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1239
1239
  //#endregion
1240
1240
  //#region src/components/data-table/data-table-column-header.d.ts
1241
1241
  interface DataTableColumnHeaderProps<TData, TValue> extends React.ComponentProps<typeof DropdownMenuTrigger> {
@@ -1247,7 +1247,7 @@ declare function DataTableColumnHeader<TData, TValue>({
1247
1247
  label,
1248
1248
  className,
1249
1249
  ...props
1250
- }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
1250
+ }: DataTableColumnHeaderProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1251
1251
  //#endregion
1252
1252
  //#region src/components/data-table/data-table-faceted-filter.d.ts
1253
1253
  interface DataTableFacetedFilterProps<TData, TValue> {
@@ -1261,7 +1261,7 @@ declare function DataTableFacetedFilter<TData, TValue>({
1261
1261
  title,
1262
1262
  options,
1263
1263
  multiple
1264
- }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime2.JSX.Element;
1264
+ }: DataTableFacetedFilterProps<TData, TValue>): react_jsx_runtime3.JSX.Element;
1265
1265
  //#endregion
1266
1266
  //#region src/components/data-table/data-table-pagination.d.ts
1267
1267
  interface DataTablePaginationProps<TData> extends React.ComponentProps<"div"> {
@@ -1273,7 +1273,7 @@ declare function DataTablePagination<TData>({
1273
1273
  pageSizeOptions,
1274
1274
  className,
1275
1275
  ...props
1276
- }: DataTablePaginationProps<TData>): react_jsx_runtime2.JSX.Element;
1276
+ }: DataTablePaginationProps<TData>): react_jsx_runtime3.JSX.Element;
1277
1277
  //#endregion
1278
1278
  //#region src/components/data-table/data-table-toolbar.d.ts
1279
1279
  interface DataTableToolbarProps<TData> extends React$1.ComponentProps<"div"> {
@@ -1284,7 +1284,7 @@ declare function DataTableToolbar<TData>({
1284
1284
  children,
1285
1285
  className,
1286
1286
  ...props
1287
- }: DataTableToolbarProps<TData>): react_jsx_runtime2.JSX.Element;
1287
+ }: DataTableToolbarProps<TData>): react_jsx_runtime3.JSX.Element;
1288
1288
  //#endregion
1289
1289
  //#region src/components/data-table/data-table-view-options.d.ts
1290
1290
  interface DataTableViewOptionsProps<TData> extends React$1.ComponentProps<typeof PopoverContent> {
@@ -1295,7 +1295,7 @@ declare function DataTableViewOptions<TData>({
1295
1295
  table,
1296
1296
  disabled,
1297
1297
  ...props
1298
- }: DataTableViewOptionsProps<TData>): react_jsx_runtime2.JSX.Element;
1298
+ }: DataTableViewOptionsProps<TData>): react_jsx_runtime3.JSX.Element;
1299
1299
  //#endregion
1300
1300
  //#region src/hooks/use-data-table.d.ts
1301
1301
  interface UseDataTableProps<TData> extends Omit<TableOptions<TData>, "state" | "pageCount" | "getCoreRowModel" | "manualFiltering" | "manualPagination" | "manualSorting">, Required<Pick<TableOptions<TData>, "pageCount">> {
package/dist/index.js CHANGED
@@ -783,10 +783,14 @@ function useQueryStates(parsers, options = {}) {
783
783
  //#endregion
784
784
  //#region src/hooks/use-readable-filters.ts
785
785
  const URL_CHANGE_EVENT = "urlchange";
786
+ function toSearchString(params) {
787
+ const queryString = params.toString().replace(/%2C/g, ",");
788
+ return queryString ? `?${queryString}` : "";
789
+ }
786
790
  function useReadableFilters(columns, options = {}) {
787
791
  const { history = "replace", scroll = false } = options;
788
792
  const columnSnapshot = React.useMemo(() => columns, [columns]);
789
- const lastWrittenUrlRef = React.useRef("");
793
+ const lastWrittenUrlRef = React.useRef(null);
790
794
  const filtersRef = React.useRef(null);
791
795
  const [filters, setFilters] = React.useState(() => {
792
796
  const initial = parseReadableFilters(getUrlParams(), columnSnapshot);
@@ -795,7 +799,10 @@ function useReadableFilters(columns, options = {}) {
795
799
  });
796
800
  React.useEffect(() => {
797
801
  const handleUrlChange = () => {
798
- if (window.location.search === lastWrittenUrlRef.current) return;
802
+ if (lastWrittenUrlRef.current !== null && window.location.search === lastWrittenUrlRef.current) {
803
+ lastWrittenUrlRef.current = null;
804
+ return;
805
+ }
799
806
  const next = parseReadableFilters(getUrlParams(), columnSnapshot);
800
807
  filtersRef.current = next;
801
808
  setFilters(next);
@@ -810,11 +817,11 @@ function useReadableFilters(columns, options = {}) {
810
817
  const writeToUrl = React.useCallback((next) => {
811
818
  const params = getUrlParams();
812
819
  applyReadableFilters(params, columnSnapshot, next);
820
+ lastWrittenUrlRef.current = toSearchString(params);
813
821
  setSearchParams(params, {
814
822
  history,
815
823
  scroll
816
824
  });
817
- lastWrittenUrlRef.current = `?${params.toString()}`;
818
825
  }, [
819
826
  columnSnapshot,
820
827
  history,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wordrhyme/auto-crud",
3
3
  "type": "module",
4
- "version": "1.0.9",
4
+ "version": "1.1.0",
5
5
  "description": "Schema-first CRUD components with auto-generated tables and forms",
6
6
  "author": "wordrhyme",
7
7
  "license": "MIT",
@@ -85,8 +85,8 @@
85
85
  "@internal/eslint-config": "0.3.0",
86
86
  "@internal/prettier-config": "0.0.1",
87
87
  "@internal/tsconfig": "0.1.0",
88
- "@internal/vitest-config": "0.1.0",
89
- "@internal/tsdown-config": "0.1.0"
88
+ "@internal/tsdown-config": "0.1.0",
89
+ "@internal/vitest-config": "0.1.0"
90
90
  },
91
91
  "prettier": "@internal/prettier-config",
92
92
  "scripts": {