@wordrhyme/auto-crud 1.24.0 → 1.24.1

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 CHANGED
@@ -1950,10 +1950,14 @@ tablePagination.register('example.stores', {
1950
1950
  ```
1951
1951
 
1952
1952
  Registrations notify mounted tables. Explicit `table.pagination` takes precedence
1953
- over registration. Page jumps accept only integer pages in the known page range;
1954
- the control is disabled when the page count is unavailable.
1955
-
1956
- In `AutoCrudTable`, the jump label follows the existing `locale` unless explicitly overridden.
1953
+ over registration. With `showPageJump`, focus the current page number to select it
1954
+ and type a destination. Enter or leaving the field commits a valid page; Escape
1955
+ or an invalid entry restores the current page. Clicking a navigation or page-size
1956
+ button uses that control directly. The input is disabled when the page count is unavailable.
1957
+
1958
+ The input's accessible name follows `locale.pagination.pageJump` unless
1959
+ `pageJumpLabel` overrides it. A custom `pagination.page` formatter can place
1960
+ the input within its text by using its optional third argument in place of the page number.
1957
1961
 
1958
1962
  Set `responsive: true` alongside these options to hide the extra controls when
1959
1963
  their measured content does not fit the pagination container. This responds to
package/dist/index.cjs CHANGED
@@ -2615,7 +2615,7 @@ const enUSPagination = {
2615
2615
  selected: (count, total) => `${count} of ${total} row(s) selected.`,
2616
2616
  total: (count) => `Total: ${count}`,
2617
2617
  rowsPerPage: "Rows per page",
2618
- page: (page, total) => `Page ${page} of ${total}`,
2618
+ page: (page, total, pageText) => `Page ${pageText ?? page} of ${total}`,
2619
2619
  pageJump: "Go to page",
2620
2620
  firstPage: "Go to first page",
2621
2621
  previousPage: "Go to previous page",
@@ -2693,7 +2693,7 @@ const zhCN = {
2693
2693
  selected: (count, total) => `已选择 ${total} 条中的 ${count} 条`,
2694
2694
  total: (count) => `共 ${count} 条`,
2695
2695
  rowsPerPage: "每页条数",
2696
- page: (page, total) => `第 ${page} / ${total} 页`,
2696
+ page: (page, total, pageText) => `第 ${pageText ?? page} / ${total} 页`,
2697
2697
  pageJump: "跳转到页",
2698
2698
  firstPage: "首页",
2699
2699
  previousPage: "上一页",
@@ -2880,7 +2880,7 @@ const jaJP = {
2880
2880
  selected: (count, total) => `${total} 件中 ${count} 件を選択`,
2881
2881
  total: (count) => `合計: ${count}`,
2882
2882
  rowsPerPage: "ページあたりの行数",
2883
- page: (page, total) => `${page} / ${total} ページ`,
2883
+ page: (page, total, pageText) => `${pageText ?? page} / ${total} ページ`,
2884
2884
  pageJump: "ページへ移動",
2885
2885
  firstPage: "最初のページ",
2886
2886
  previousPage: "前のページ",
@@ -2994,7 +2994,7 @@ const koKR = {
2994
2994
  selected: (count, total) => `${total}개 중 ${count}개 선택됨`,
2995
2995
  total: (count) => `전체: ${count}`,
2996
2996
  rowsPerPage: "페이지당 행 수",
2997
- page: (page, total) => `${page} / ${total} 페이지`,
2997
+ page: (page, total, pageText) => `${pageText ?? page} / ${total} 페이지`,
2998
2998
  pageJump: "페이지로 이동",
2999
2999
  firstPage: "첫 페이지",
3000
3000
  previousPage: "이전 페이지",
@@ -3108,7 +3108,7 @@ const frFR = {
3108
3108
  selected: (count, total) => `${count} ligne(s) sélectionnée(s) sur ${total}.`,
3109
3109
  total: (count) => `Total : ${count}`,
3110
3110
  rowsPerPage: "Lignes par page",
3111
- page: (page, total) => `Page ${page} sur ${total}`,
3111
+ page: (page, total, pageText) => `Page ${pageText ?? page} sur ${total}`,
3112
3112
  pageJump: "Aller à la page",
3113
3113
  firstPage: "Première page",
3114
3114
  previousPage: "Page précédente",
@@ -3222,7 +3222,7 @@ const deDE = {
3222
3222
  selected: (count, total) => `${count} von ${total} Zeile(n) ausgewählt.`,
3223
3223
  total: (count) => `Gesamt: ${count}`,
3224
3224
  rowsPerPage: "Zeilen pro Seite",
3225
- page: (page, total) => `Seite ${page} von ${total}`,
3225
+ page: (page, total, pageText) => `Seite ${pageText ?? page} von ${total}`,
3226
3226
  pageJump: "Zur Seite springen",
3227
3227
  firstPage: "Erste Seite",
3228
3228
  previousPage: "Vorherige Seite",
@@ -3336,7 +3336,7 @@ const esES = {
3336
3336
  selected: (count, total) => `${count} de ${total} fila(s) seleccionada(s).`,
3337
3337
  total: (count) => `Total: ${count}`,
3338
3338
  rowsPerPage: "Filas por página",
3339
- page: (page, total) => `Página ${page} de ${total}`,
3339
+ page: (page, total, pageText) => `Página ${pageText ?? page} de ${total}`,
3340
3340
  pageJump: "Ir a la página",
3341
3341
  firstPage: "Primera página",
3342
3342
  previousPage: "Página anterior",
@@ -3469,8 +3469,11 @@ function DataTablePagination({ table, pageSizeOptions = [
3469
3469
  const hideExtras = responsive && !hasSpace;
3470
3470
  const hiddenClass = hideExtras ? "absolute invisible pointer-events-none left-0 top-0" : void 0;
3471
3471
  const { pageIndex, pageSize } = table.getState().pagination;
3472
+ const currentPage = pageIndex + 1;
3472
3473
  const pageCount = table.getPageCount();
3473
3474
  const knownPageCount = pageCount >= 0;
3475
+ const pageSlot = "{currentPage}";
3476
+ const [beforeInput, afterInput] = showPageJump && knownPageCount ? locale.page(currentPage, pageCount, pageSlot).split(pageSlot) : [];
3474
3477
  const canJump = Number.isFinite(pageCount) && pageCount > 0;
3475
3478
  const canGoNext = table.getCanNextPage() && (knownPageCount || table.options.data.length >= pageSize);
3476
3479
  const total = table.options.rowCount ?? (table.options.manualPagination ? void 0 : table.getRowCount());
@@ -3489,7 +3492,8 @@ function DataTablePagination({ table, pageSizeOptions = [
3489
3492
  const children = Array.from(node.children);
3490
3493
  return children.reduce((sum, child) => {
3491
3494
  const style = getComputedStyle(child);
3492
- return sum + (child === nav || child === jump ? width(child) : child.getBoundingClientRect().width) + (parseFloat(style.marginLeft) || 0) + (parseFloat(style.marginRight) || 0);
3495
+ const measured = jump?.parentElement === child ? jump : child;
3496
+ return sum + (child === nav ? width(nav) : measured.getBoundingClientRect().width) + (parseFloat(style.marginLeft) || 0) + (parseFloat(style.marginRight) || 0);
3493
3497
  }, 0) + Math.max(0, children.length - 1) * gap(node);
3494
3498
  };
3495
3499
  const measure = () => {
@@ -3507,7 +3511,7 @@ function DataTablePagination({ table, pageSizeOptions = [
3507
3511
  ...info.children,
3508
3512
  ...group.children,
3509
3513
  ...nav.children,
3510
- ...jump?.children ?? []
3514
+ ...jump ? [jump] : []
3511
3515
  ]) observer.observe(node);
3512
3516
  measure();
3513
3517
  return () => observer.disconnect();
@@ -3527,6 +3531,10 @@ function DataTablePagination({ table, pageSizeOptions = [
3527
3531
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: selectionTotal === void 0 || selectedCount > selectionTotal ? (locale.selectedCount ?? enUSActionBar.selected)(selectedCount) : locale.selected(selectedCount, selectionTotal) }), total !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: locale.total(total) })]
3528
3532
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3529
3533
  ref: controls,
3534
+ onPointerDownCapture: (event) => {
3535
+ const input = event.currentTarget.ownerDocument.activeElement;
3536
+ if (input instanceof HTMLInputElement && pageJump.current?.contains(input) && event.target instanceof Element && event.target.closest("button")) input.value = String(currentPage);
3537
+ },
3530
3538
  className: cn("flex items-center gap-4 sm:gap-6 lg:gap-8", responsive ? "flex-row flex-wrap justify-center whitespace-nowrap [&>*]:shrink-0" : "flex-col-reverse sm:flex-row"),
3531
3539
  children: [
3532
3540
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -3551,44 +3559,41 @@ function DataTablePagination({ table, pageSizeOptions = [
3551
3559
  })]
3552
3560
  })]
3553
3561
  }),
3554
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3562
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3555
3563
  className: "flex items-center justify-center font-medium text-sm",
3556
- children: knownPageCount ? locale.page(pageIndex + 1, pageCount) : pageIndex + 1
3557
- }),
3558
- showPageJump && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3559
- ref: pageJump,
3560
- className: hideExtras ? "pointer-events-none absolute inset-x-0 top-0 invisible overflow-hidden" : void 0,
3561
- "aria-hidden": hideExtras || void 0,
3562
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
3563
- className: "flex w-max items-center gap-2",
3564
- onSubmit: (event) => {
3565
- event.preventDefault();
3566
- const page = Number(new FormData(event.currentTarget).get("page"));
3567
- if (canJump && Number.isInteger(page) && page >= 1 && page <= pageCount) table.setPageIndex(page - 1);
3568
- },
3569
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
3570
- className: "flex items-center gap-2 whitespace-nowrap text-sm",
3571
- children: [jumpLabel, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
3572
- name: "page",
3573
- type: "number",
3574
- min: 1,
3575
- max: canJump ? pageCount : void 0,
3576
- step: 1,
3577
- required: true,
3578
- defaultValue: pageIndex + 1,
3579
- disabled: !canJump,
3580
- className: "h-8 w-20"
3581
- }, `${pageIndex}-${pageCount}`)]
3582
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
3583
- type: "submit",
3584
- variant: "outline",
3585
- size: "icon",
3586
- className: "size-8",
3587
- disabled: !canJump,
3588
- "aria-label": jumpLabel,
3589
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, {})
3590
- })]
3591
- })
3564
+ children: [(!showPageJump || hideExtras) && (knownPageCount ? locale.page(currentPage, pageCount) : currentPage), showPageJump && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3565
+ ref: pageJump,
3566
+ className: cn("flex w-max items-center gap-1 whitespace-nowrap", hiddenClass),
3567
+ "aria-hidden": hideExtras || void 0,
3568
+ children: [
3569
+ beforeInput,
3570
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
3571
+ "aria-label": jumpLabel,
3572
+ type: "text",
3573
+ inputMode: "numeric",
3574
+ enterKeyHint: "go",
3575
+ defaultValue: currentPage,
3576
+ disabled: !canJump || hideExtras,
3577
+ className: "h-8 min-w-10 px-1 text-center tabular-nums",
3578
+ style: { width: `calc(${String(pageCount).length}ch + 1rem)` },
3579
+ onFocus: (event) => event.currentTarget.select(),
3580
+ onKeyDown: (event) => {
3581
+ if (event.key !== "Enter" && event.key !== "Escape") return;
3582
+ event.preventDefault();
3583
+ if (event.key === "Escape") event.currentTarget.value = String(currentPage);
3584
+ event.currentTarget.blur();
3585
+ },
3586
+ onBlur: (event) => {
3587
+ const input = event.currentTarget;
3588
+ const value = input.value;
3589
+ const page = Number(value);
3590
+ input.value = String(currentPage);
3591
+ if (/^\d+$/.test(value) && page >= 1 && page <= pageCount && page !== currentPage) table.setPageIndex(page - 1);
3592
+ }
3593
+ }, `${pageIndex}-${pageCount}`),
3594
+ afterInput
3595
+ ]
3596
+ })]
3592
3597
  }),
3593
3598
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3594
3599
  ref: navigation,
@@ -7610,20 +7615,27 @@ function AutoTableActionBar({ table, locale: localeProp, onDeleteSelected, onUpd
7610
7615
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn_ui.ActionBar, {
7611
7616
  open: rows.length > 0,
7612
7617
  onOpenChange,
7618
+ className: "w-max max-w-[calc(100%-2rem)]",
7613
7619
  children: [
7614
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn_ui.ActionBarSelection, { children: [
7615
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7616
- className: "font-medium",
7617
- children: locale.selected(rows.length)
7618
- }),
7619
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarSeparator, {}),
7620
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarClose, {
7621
- "aria-label": locale.clearSelection,
7622
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {})
7623
- })
7624
- ] }),
7625
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarSeparator, {}),
7626
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarGroup, { children: renderedActions })
7620
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn_ui.ActionBarSelection, {
7621
+ className: "shrink-0 whitespace-nowrap",
7622
+ children: [
7623
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7624
+ className: "font-medium",
7625
+ children: locale.selected(rows.length)
7626
+ }),
7627
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarSeparator, {}),
7628
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarClose, {
7629
+ "aria-label": locale.clearSelection,
7630
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {})
7631
+ })
7632
+ ]
7633
+ }),
7634
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarSeparator, { className: "shrink-0" }),
7635
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn_ui.ActionBarGroup, {
7636
+ className: "-m-1 min-w-0 overflow-x-auto p-1 [&>*]:shrink-0",
7637
+ children: renderedActions
7638
+ })
7627
7639
  ]
7628
7640
  });
7629
7641
  }
@@ -9952,6 +9964,7 @@ function useDynamicFilterOptions(fields) {
9952
9964
  const searchValuesRef = react.useRef({});
9953
9965
  const sourceEntriesByFieldRef = react.useRef({});
9954
9966
  const timersRef = react.useRef({});
9967
+ const loadedSourcesRef = react.useRef(/* @__PURE__ */ new Map());
9955
9968
  const sourceEntries = react.useMemo(() => {
9956
9969
  if (!fields) return [];
9957
9970
  return Object.entries(fields).flatMap(([field, config]) => {
@@ -10073,9 +10086,10 @@ function useDynamicFilterOptions(fields) {
10073
10086
  setFieldHasMore(field, hasMore);
10074
10087
  setFieldLoading(field, false);
10075
10088
  }, (error) => {
10076
- if (controller?.signal.aborted) return;
10089
+ if (requestVersionsRef.current[field] !== requestVersion || controller?.signal.aborted) return;
10077
10090
  console.warn(`[AutoCrud] Failed to load filter data source "${source.key}".`, error);
10078
10091
  if (!append) {
10092
+ loadedSourcesRef.current.delete(field);
10079
10093
  setFieldOptions(field, []);
10080
10094
  setFieldHasMore(field, false);
10081
10095
  pageByFieldRef.current = {
@@ -10106,6 +10120,7 @@ function useDynamicFilterOptions(fields) {
10106
10120
  }, []);
10107
10121
  react.useEffect(() => {
10108
10122
  if (sourceEntries.length === 0) {
10123
+ loadedSourcesRef.current.clear();
10109
10124
  hasMoreByFieldRef.current = {};
10110
10125
  loadingByFieldRef.current = {};
10111
10126
  optionsByFieldRef.current = {};
@@ -10121,7 +10136,19 @@ function useDynamicFilterOptions(fields) {
10121
10136
  removeInactiveFieldState(setLoadingByField, loadingByFieldRef, activeFields);
10122
10137
  removeInactiveFieldState(setOptionsByField, optionsByFieldRef, activeFields);
10123
10138
  for (const field of Object.keys(controllersRef.current)) if (!activeFields.has(field)) clearFieldRequest(field);
10124
- for (const { field } of sourceEntries) loadFieldOptions(field);
10139
+ for (const field of loadedSourcesRef.current.keys()) if (!activeFields.has(field)) loadedSourcesRef.current.delete(field);
10140
+ for (const { field, source } of sourceEntries) {
10141
+ const entry = dataSources.get(source.key);
10142
+ const search = entry?.search ? searchValues[field] ?? "" : void 0;
10143
+ const previous = loadedSourcesRef.current.get(field);
10144
+ if (previous?.key === source.key && previous.entry === entry && previous.search === search) continue;
10145
+ loadedSourcesRef.current.set(field, {
10146
+ key: source.key,
10147
+ entry,
10148
+ search
10149
+ });
10150
+ loadFieldOptions(field);
10151
+ }
10125
10152
  }, [
10126
10153
  clearFieldRequest,
10127
10154
  loadFieldOptions,
@@ -10132,6 +10159,7 @@ function useDynamicFilterOptions(fields) {
10132
10159
  ]);
10133
10160
  react.useEffect(() => () => {
10134
10161
  for (const field of Object.keys(controllersRef.current)) clearFieldRequest(field);
10162
+ loadedSourcesRef.current.clear();
10135
10163
  }, [clearFieldRequest]);
10136
10164
  return react.useMemo(() => ({
10137
10165
  hasMoreByField,
@@ -10198,7 +10226,7 @@ function useDynamicResolveOptions(fields, rows, hiddenColumns) {
10198
10226
  const requestVersion = requestVersionRef.current + 1;
10199
10227
  requestVersionRef.current = requestVersion;
10200
10228
  if (sourceEntries.length === 0) {
10201
- setOptionsByField({});
10229
+ setOptionsByField((current) => Object.keys(current).length === 0 ? current : {});
10202
10230
  return;
10203
10231
  }
10204
10232
  let cancelled = false;
@@ -10227,7 +10255,7 @@ function useDynamicResolveOptions(fields, rows, hiddenColumns) {
10227
10255
  if (cached.length > 0) next[entry.field] = cached;
10228
10256
  }
10229
10257
  for (const [field, options] of Object.entries(current)) if (activeFields.has(field) && !next[field]) next[field] = options;
10230
- return next;
10258
+ return Object.keys(next).length === 0 && Object.keys(current).length === 0 ? current : next;
10231
10259
  });
10232
10260
  for (const sourceEntry of sourceEntries) {
10233
10261
  const entry = dataSources.get(sourceEntry.source.key);
package/dist/index.d.cts CHANGED
@@ -943,7 +943,8 @@ interface TablePaginationLocale {
943
943
  selectedCount?: (count: number) => string;
944
944
  total: (count: number) => string;
945
945
  rowsPerPage: string;
946
- page: (page: number, total: number) => string;
946
+ /** Use pageText in place of the current number when rendering an inline jump field. */
947
+ page: (page: number, total: number, pageText?: string) => string;
947
948
  pageJump: string;
948
949
  firstPage: string;
949
950
  previousPage: string;
@@ -1194,8 +1195,9 @@ interface TablePaginationOptions {
1194
1195
  alwaysShowFirstLast?: boolean;
1195
1196
  /** Hide optional controls when their measured content does not fit the container. */
1196
1197
  responsive?: boolean;
1197
- /** Show an input to jump to a known page; defaults to false. */
1198
+ /** Make the current page number editable; defaults to false. */
1198
1199
  showPageJump?: boolean;
1200
+ /** Accessible name of the page number input. */
1199
1201
  pageJumpLabel?: string;
1200
1202
  }
1201
1203
  declare module '@tanstack/react-table' {
package/dist/index.d.ts CHANGED
@@ -943,7 +943,8 @@ interface TablePaginationLocale {
943
943
  selectedCount?: (count: number) => string;
944
944
  total: (count: number) => string;
945
945
  rowsPerPage: string;
946
- page: (page: number, total: number) => string;
946
+ /** Use pageText in place of the current number when rendering an inline jump field. */
947
+ page: (page: number, total: number, pageText?: string) => string;
947
948
  pageJump: string;
948
949
  firstPage: string;
949
950
  previousPage: string;
@@ -1194,8 +1195,9 @@ interface TablePaginationOptions {
1194
1195
  alwaysShowFirstLast?: boolean;
1195
1196
  /** Hide optional controls when their measured content does not fit the container. */
1196
1197
  responsive?: boolean;
1197
- /** Show an input to jump to a known page; defaults to false. */
1198
+ /** Make the current page number editable; defaults to false. */
1198
1199
  showPageJump?: boolean;
1200
+ /** Accessible name of the page number input. */
1199
1201
  pageJumpLabel?: string;
1200
1202
  }
1201
1203
  declare module '@tanstack/react-table' {