@economic/taco 17.1.0 → 17.2.0-EC-005678-test-tanstack-virtual.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.
@@ -32,7 +32,12 @@ const BaseTable3 = types.fixedForwardRef(function BaseTable32(props, ref) {
32
32
  return table3.meta.editing.hasChanges(row.rowId);
33
33
  });
34
34
  const hasCreateWorkflow = table3.meta.editing.isEnabled && props.onEditingCreate;
35
- const [hasScrollbar, isScrolled] = editing.isTableScrolled(table3.ref);
35
+ const [hasScrollbar, isScrolledToBottom] = editing.isTableScrolled(table3.ref);
36
+ const isScrolled = isScrolledToBottom && table3.meta.footer.isEnabled;
37
+ const restoreCreateRowFocus = React.useRef(false);
38
+ React.useEffect(() => {
39
+ restoreCreateRowFocus.current = false;
40
+ });
36
41
  let createWorkflow;
37
42
  if (hasCreateWorkflow) {
38
43
  createWorkflow = /* @__PURE__ */ React.createElement(
@@ -40,6 +45,7 @@ const BaseTable3 = types.fixedForwardRef(function BaseTable32(props, ref) {
40
45
  {
41
46
  buttonRef: table3.meta.editing.createRowButtonRef,
42
47
  hasScrollbar,
48
+ restoreFocusRef: restoreCreateRowFocus,
43
49
  table: table3.instance,
44
50
  tableMeta: table3.meta,
45
51
  tableRef: table3.ref
@@ -30,7 +30,12 @@ const BaseTable3 = fixedForwardRef(function BaseTable32(props, ref) {
30
30
  return table3.meta.editing.hasChanges(row.rowId);
31
31
  });
32
32
  const hasCreateWorkflow = table3.meta.editing.isEnabled && props.onEditingCreate;
33
- const [hasScrollbar, isScrolled] = isTableScrolled(table3.ref);
33
+ const [hasScrollbar, isScrolledToBottom] = isTableScrolled(table3.ref);
34
+ const isScrolled = isScrolledToBottom && table3.meta.footer.isEnabled;
35
+ const restoreCreateRowFocus = React__default.useRef(false);
36
+ React__default.useEffect(() => {
37
+ restoreCreateRowFocus.current = false;
38
+ });
34
39
  let createWorkflow;
35
40
  if (hasCreateWorkflow) {
36
41
  createWorkflow = /* @__PURE__ */ React__default.createElement(
@@ -38,6 +43,7 @@ const BaseTable3 = fixedForwardRef(function BaseTable32(props, ref) {
38
43
  {
39
44
  buttonRef: table3.meta.editing.createRowButtonRef,
40
45
  hasScrollbar,
46
+ restoreFocusRef: restoreCreateRowFocus,
41
47
  table: table3.instance,
42
48
  tableMeta: table3.meta,
43
49
  tableRef: table3.ref
@@ -9,8 +9,34 @@ const Shortcut = require("../../../../Shortcut/Shortcut.cjs");
9
9
  const SCROLL_NEAR_BOTTOM_THRESHOLD_PX = 80;
10
10
  const SCROLL_DELAY_MS = 150;
11
11
  function CreateNewRow(props) {
12
- const { buttonRef, hasScrollbar, table, tableMeta, tableRef } = props;
12
+ const { buttonRef, hasScrollbar, restoreFocusRef, table, tableMeta, tableRef } = props;
13
13
  const { texts } = Localization.useLocalization();
14
+ const rowRef = React.useRef(null);
15
+ React.useLayoutEffect(() => {
16
+ const row = rowRef.current;
17
+ let frame;
18
+ let isPending = false;
19
+ const getButton = () => row?.querySelector("button") ?? null;
20
+ if (restoreFocusRef.current) {
21
+ restoreFocusRef.current = false;
22
+ isPending = true;
23
+ frame = requestAnimationFrame(() => {
24
+ isPending = false;
25
+ if (!document.activeElement || document.activeElement === document.body) {
26
+ getButton()?.focus();
27
+ }
28
+ });
29
+ }
30
+ return () => {
31
+ if (frame !== void 0) {
32
+ cancelAnimationFrame(frame);
33
+ }
34
+ const button = getButton();
35
+ if (isPending || button && document.activeElement === button) {
36
+ restoreFocusRef.current = true;
37
+ }
38
+ };
39
+ }, [restoreFocusRef]);
14
40
  const temporaryRows = tableMeta.editing.temporaryRows;
15
41
  const temporaryRowId = temporaryRows[0]?.[tableMeta.rowIdentityAccessor] ?? "";
16
42
  const isDisabled = !!table.getState().globalFilter || !!table.getState().columnFilters?.length || !!temporaryRowId && !!tableMeta.editing.hasRowErrors(temporaryRowId);
@@ -42,7 +68,7 @@ function CreateNewRow(props) {
42
68
  "bottom-0": !tableMeta.footer.isEnabled,
43
69
  "!border-t-[0] border-b": !hasScrollbar
44
70
  });
45
- return /* @__PURE__ */ React.createElement("tr", { "data-row-create": true, className, tabIndex: -1 }, /* @__PURE__ */ React.createElement("td", { className: "col-span-full !bg-gray-50/50 !px-1" }, /* @__PURE__ */ React.createElement(
71
+ return /* @__PURE__ */ React.createElement("tr", { "data-row-create": true, className, ref: rowRef, tabIndex: -1 }, /* @__PURE__ */ React.createElement("td", { className: "col-span-full !bg-gray-50/50 !px-1" }, /* @__PURE__ */ React.createElement(
46
72
  Button.LegacyButton,
47
73
  {
48
74
  appearance: "transparent",
@@ -1,12 +1,17 @@
1
1
  import { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';
2
2
  import { default as React } from 'react';
3
3
  import { TableRef } from '../../../../../primitives/Table/types';
4
+ type CreateNewRowMeta<TType> = Pick<ReactTableMeta<TType>, 'rowIdentityAccessor'> & {
5
+ editing: Pick<ReactTableMeta<TType>['editing'], 'createRow' | 'getRowStatus' | 'hasRowErrors' | 'temporaryRows'>;
6
+ footer: Pick<ReactTableMeta<TType>['footer'], 'isEnabled'>;
7
+ };
4
8
  type CreateNewRowProps<TType = unknown> = {
5
9
  buttonRef: React.Ref<HTMLButtonElement>;
6
10
  hasScrollbar: boolean;
11
+ restoreFocusRef: React.RefObject<boolean>;
7
12
  table: ReactTable<TType>;
8
- tableMeta: ReactTableMeta<TType>;
9
- tableRef: React.RefObject<TableRef>;
13
+ tableMeta: CreateNewRowMeta<TType>;
14
+ tableRef: React.RefObject<TableRef | null>;
10
15
  };
11
16
  export declare function CreateNewRow<TType = unknown>(props: CreateNewRowProps<TType>): React.JSX.Element;
12
17
  export {};
@@ -7,8 +7,34 @@ import { Shortcut } from "../../../../Shortcut/Shortcut.js";
7
7
  const SCROLL_NEAR_BOTTOM_THRESHOLD_PX = 80;
8
8
  const SCROLL_DELAY_MS = 150;
9
9
  function CreateNewRow(props) {
10
- const { buttonRef, hasScrollbar, table, tableMeta, tableRef } = props;
10
+ const { buttonRef, hasScrollbar, restoreFocusRef, table, tableMeta, tableRef } = props;
11
11
  const { texts } = useLocalization();
12
+ const rowRef = React__default.useRef(null);
13
+ React__default.useLayoutEffect(() => {
14
+ const row = rowRef.current;
15
+ let frame;
16
+ let isPending = false;
17
+ const getButton = () => row?.querySelector("button") ?? null;
18
+ if (restoreFocusRef.current) {
19
+ restoreFocusRef.current = false;
20
+ isPending = true;
21
+ frame = requestAnimationFrame(() => {
22
+ isPending = false;
23
+ if (!document.activeElement || document.activeElement === document.body) {
24
+ getButton()?.focus();
25
+ }
26
+ });
27
+ }
28
+ return () => {
29
+ if (frame !== void 0) {
30
+ cancelAnimationFrame(frame);
31
+ }
32
+ const button = getButton();
33
+ if (isPending || button && document.activeElement === button) {
34
+ restoreFocusRef.current = true;
35
+ }
36
+ };
37
+ }, [restoreFocusRef]);
12
38
  const temporaryRows = tableMeta.editing.temporaryRows;
13
39
  const temporaryRowId = temporaryRows[0]?.[tableMeta.rowIdentityAccessor] ?? "";
14
40
  const isDisabled = !!table.getState().globalFilter || !!table.getState().columnFilters?.length || !!temporaryRowId && !!tableMeta.editing.hasRowErrors(temporaryRowId);
@@ -40,7 +66,7 @@ function CreateNewRow(props) {
40
66
  "bottom-0": !tableMeta.footer.isEnabled,
41
67
  "!border-t-[0] border-b": !hasScrollbar
42
68
  });
43
- return /* @__PURE__ */ React__default.createElement("tr", { "data-row-create": true, className, tabIndex: -1 }, /* @__PURE__ */ React__default.createElement("td", { className: "col-span-full !bg-gray-50/50 !px-1" }, /* @__PURE__ */ React__default.createElement(
69
+ return /* @__PURE__ */ React__default.createElement("tr", { "data-row-create": true, className, ref: rowRef, tabIndex: -1 }, /* @__PURE__ */ React__default.createElement("td", { className: "col-span-full !bg-gray-50/50 !px-1" }, /* @__PURE__ */ React__default.createElement(
44
70
  LegacyButton,
45
71
  {
46
72
  appearance: "transparent",
@@ -24,7 +24,8 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
24
24
  }, [isEditing]);
25
25
  function toggleEditing(enabled, table, scrollToIndex) {
26
26
  const tableMeta = rows.getTableMeta(table);
27
- if (enabled) {
27
+ const isEnabled2 = typeof enabled === "function" ? enabled(tableMeta.editing.isEditing) : enabled;
28
+ if (isEnabled2) {
28
29
  const index = tableMeta.rowActive.rowActiveIndex ?? 0;
29
30
  if (tableMeta.rowActive.rowActiveIndex === void 0) {
30
31
  tableMeta.rowActive.setRowActiveIndex(index);
@@ -32,11 +33,11 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
32
33
  if (!editing.isTemporaryRow(table.getRowModel().rows[index]?.id)) {
33
34
  scrollToIndex(index);
34
35
  }
35
- } else if (!enabled) {
36
+ } else if (!isEnabled2) {
36
37
  toggleDetailedMode(false);
37
38
  setLastFocusedCellIndex(void 0);
38
39
  }
39
- setEditing(enabled);
40
+ setEditing(isEnabled2);
40
41
  pendingChangesFns.saveChanges(table);
41
42
  }
42
43
  async function createRow(table, row) {
@@ -22,7 +22,8 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
22
22
  }, [isEditing]);
23
23
  function toggleEditing(enabled, table, scrollToIndex) {
24
24
  const tableMeta = getTableMeta(table);
25
- if (enabled) {
25
+ const isEnabled2 = typeof enabled === "function" ? enabled(tableMeta.editing.isEditing) : enabled;
26
+ if (isEnabled2) {
26
27
  const index = tableMeta.rowActive.rowActiveIndex ?? 0;
27
28
  if (tableMeta.rowActive.rowActiveIndex === void 0) {
28
29
  tableMeta.rowActive.setRowActiveIndex(index);
@@ -30,11 +31,11 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
30
31
  if (!isTemporaryRow(table.getRowModel().rows[index]?.id)) {
31
32
  scrollToIndex(index);
32
33
  }
33
- } else if (!enabled) {
34
+ } else if (!isEnabled2) {
34
35
  toggleDetailedMode(false);
35
36
  setLastFocusedCellIndex(void 0);
36
37
  }
37
- setEditing(enabled);
38
+ setEditing(isEnabled2);
38
39
  pendingChangesFns.saveChanges(table);
39
40
  }
40
41
  async function createRow(table, row) {
@@ -3,22 +3,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const useGlobalKeyDown = require("../../../hooks/useGlobalKeyDown.cjs");
5
5
  const useLazyEffect = require("../../../hooks/useLazyEffect.cjs");
6
- const rows = require("../../../primitives/Table/useTableManager/util/rows.cjs");
7
6
  const search = require("../../../primitives/Table/useTableManager/util/search.cjs");
8
7
  const dom = require("../../../utils/dom.cjs");
9
8
  const editing = require("../util/editing.cjs");
10
9
  const Localization = require("../../Provider/Localization.cjs");
11
- function useTableEditingListener(table, tableRef, scrollToIndex) {
12
- const tableMeta = rows.getTableMeta(table);
10
+ function useTableEditingListener(table, tableMeta, tableRef, scrollToIndex) {
13
11
  const localization = Localization.useLocalization();
14
12
  const hasChanges = tableMeta.editing.hasChanges();
15
13
  React.useEffect(() => {
16
14
  function showUnsavedChangesWarning(event) {
17
15
  if (tableMeta.editing.isEditing && hasChanges) {
16
+ event.preventDefault();
18
17
  event.returnValue = true;
19
- return true;
20
18
  }
21
- return false;
22
19
  }
23
20
  window.addEventListener("beforeunload", showUnsavedChangesWarning);
24
21
  return () => {
@@ -1,4 +1,7 @@
1
- import { Table as ReactTable } from '@tanstack/react-table';
1
+ import { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';
2
2
  import { default as React } from 'react';
3
- import { TableRef } from '../../../primitives/Table/types';
4
- export declare function useTableEditingListener<TType = unknown>(table: ReactTable<TType>, tableRef: React.RefObject<TableRef>, scrollToIndex: (index: number) => void): void;
3
+ type TableEditingListenerMeta<TType> = {
4
+ editing: Pick<ReactTableMeta<TType>['editing'], 'hasChanges' | 'hasSaved' | 'isEditing' | 'isEnabled' | 'saveChanges' | 'toggleEditing'>;
5
+ };
6
+ export declare function useTableEditingListener<TType = unknown>(table: ReactTable<TType>, tableMeta: TableEditingListenerMeta<TType>, tableRef: React.RefObject<HTMLElement | null>, scrollToIndex: (index: number) => void): void;
7
+ export {};
@@ -1,22 +1,19 @@
1
1
  import React__default from "react";
2
2
  import { useGlobalKeyDown } from "../../../hooks/useGlobalKeyDown.js";
3
3
  import { useLazyEffect } from "../../../hooks/useLazyEffect.js";
4
- import { getTableMeta } from "../../../primitives/Table/useTableManager/util/rows.js";
5
4
  import { resetHighlightedColumnIndexes } from "../../../primitives/Table/useTableManager/util/search.js";
6
5
  import { isElementInsideOrTriggeredFromContainer } from "../../../utils/dom.js";
7
6
  import { shortcut } from "../util/editing.js";
8
7
  import { useLocalization } from "../../Provider/Localization.js";
9
- function useTableEditingListener(table, tableRef, scrollToIndex) {
10
- const tableMeta = getTableMeta(table);
8
+ function useTableEditingListener(table, tableMeta, tableRef, scrollToIndex) {
11
9
  const localization = useLocalization();
12
10
  const hasChanges = tableMeta.editing.hasChanges();
13
11
  React__default.useEffect(() => {
14
12
  function showUnsavedChangesWarning(event) {
15
13
  if (tableMeta.editing.isEditing && hasChanges) {
14
+ event.preventDefault();
16
15
  event.returnValue = true;
17
- return true;
18
16
  }
19
- return false;
20
17
  }
21
18
  window.addEventListener("beforeunload", showUnsavedChangesWarning);
22
19
  return () => {
@@ -91,7 +91,7 @@ function useTable3(props, ref) {
91
91
  toggleEditing(true);
92
92
  }
93
93
  }, []);
94
- useTableEditingListener.useTableEditingListener(table.instance, table.ref, table.renderer.scrollToIndex);
94
+ useTableEditingListener.useTableEditingListener(table.instance, table.meta, table.ref, table.renderer.scrollToIndex);
95
95
  React.useEffect(() => {
96
96
  const tableRef = table.ref.current;
97
97
  if (tableRef) {
@@ -89,7 +89,7 @@ function useTable3(props, ref) {
89
89
  toggleEditing(true);
90
90
  }
91
91
  }, []);
92
- useTableEditingListener(table.instance, table.ref, table.renderer.scrollToIndex);
92
+ useTableEditingListener(table.instance, table.meta, table.ref, table.renderer.scrollToIndex);
93
93
  React__default.useEffect(() => {
94
94
  const tableRef = table.ref.current;
95
95
  if (tableRef) {
@@ -20,8 +20,26 @@ function willRowMoveAfterSearch(cell, change, table, localization) {
20
20
  if (!table.options.enableGlobalFilter || !searchQuery) {
21
21
  return false;
22
22
  }
23
- const rowWithChange = { ...cell.row, original: { ...cell.row.original, [cell.column.id]: change } };
24
- return !search.globalFilterFn(rowWithChange, cell.column.id, searchQuery, localization);
23
+ const originalWithChange = { ...cell.row.original, [cell.column.id]: change };
24
+ const getValueWithChange = (columnId) => columnId === cell.column.id ? change : cell.row.getValue(columnId);
25
+ return !table.getAllLeafColumns().some((column) => {
26
+ if (!column.getCanGlobalFilter()) {
27
+ return false;
28
+ }
29
+ const { dataType, dataTypeOptions } = column.columnDef.meta ?? {};
30
+ try {
31
+ return !!search.isMatched(
32
+ searchQuery,
33
+ getValueWithChange(column.id),
34
+ originalWithChange,
35
+ dataType,
36
+ dataTypeOptions,
37
+ localization
38
+ );
39
+ } catch {
40
+ return false;
41
+ }
42
+ });
25
43
  }
26
44
  function willRowMoveAfterFilter(cell, change, localization) {
27
45
  if (!cell.column.getIsFiltered()) {
@@ -94,9 +112,11 @@ function isTemporaryRow(rowId) {
94
112
  return String(rowId).startsWith(TEMPORARY_ROW_ID_PREFIX);
95
113
  }
96
114
  const shortcut = { key: "e", meta: true, shift: false };
115
+ const parsePixels = (value) => Number.parseFloat(value || "0");
97
116
  function isTableScrolled(ref) {
98
117
  if (ref.current) {
99
- const height = Number(ref.current?.querySelector("tbody")?.style.height || "0") + Number(ref.current?.querySelector("tbody")?.style.paddingBottom || "0");
118
+ const tbody = ref.current.querySelector("tbody");
119
+ const height = parsePixels(tbody?.style.height) + parsePixels(tbody?.style.paddingBottom);
100
120
  const hasVerticalScrollbar = ref.current.scrollHeight > ref.current.clientHeight;
101
121
  return [hasVerticalScrollbar, height > ref.current.scrollHeight];
102
122
  }
@@ -1,5 +1,5 @@
1
1
  import { columnFilterFn } from "../../../primitives/Table/useTableManager/util/filtering.js";
2
- import { globalFilterFn } from "../../../primitives/Table/useTableManager/util/search.js";
2
+ import { isMatched } from "../../../primitives/Table/useTableManager/util/search.js";
3
3
  function willRowMove(cell, change, rowIndex, localization) {
4
4
  const { table } = cell.getContext();
5
5
  if (willRowMoveAfterSearch(cell, change, table, localization)) {
@@ -18,8 +18,26 @@ function willRowMoveAfterSearch(cell, change, table, localization) {
18
18
  if (!table.options.enableGlobalFilter || !searchQuery) {
19
19
  return false;
20
20
  }
21
- const rowWithChange = { ...cell.row, original: { ...cell.row.original, [cell.column.id]: change } };
22
- return !globalFilterFn(rowWithChange, cell.column.id, searchQuery, localization);
21
+ const originalWithChange = { ...cell.row.original, [cell.column.id]: change };
22
+ const getValueWithChange = (columnId) => columnId === cell.column.id ? change : cell.row.getValue(columnId);
23
+ return !table.getAllLeafColumns().some((column) => {
24
+ if (!column.getCanGlobalFilter()) {
25
+ return false;
26
+ }
27
+ const { dataType, dataTypeOptions } = column.columnDef.meta ?? {};
28
+ try {
29
+ return !!isMatched(
30
+ searchQuery,
31
+ getValueWithChange(column.id),
32
+ originalWithChange,
33
+ dataType,
34
+ dataTypeOptions,
35
+ localization
36
+ );
37
+ } catch {
38
+ return false;
39
+ }
40
+ });
23
41
  }
24
42
  function willRowMoveAfterFilter(cell, change, localization) {
25
43
  if (!cell.column.getIsFiltered()) {
@@ -92,9 +110,11 @@ function isTemporaryRow(rowId) {
92
110
  return String(rowId).startsWith(TEMPORARY_ROW_ID_PREFIX);
93
111
  }
94
112
  const shortcut = { key: "e", meta: true, shift: false };
113
+ const parsePixels = (value) => Number.parseFloat(value || "0");
95
114
  function isTableScrolled(ref) {
96
115
  if (ref.current) {
97
- const height = Number(ref.current?.querySelector("tbody")?.style.height || "0") + Number(ref.current?.querySelector("tbody")?.style.paddingBottom || "0");
116
+ const tbody = ref.current.querySelector("tbody");
117
+ const height = parsePixels(tbody?.style.height) + parsePixels(tbody?.style.paddingBottom);
98
118
  const hasVerticalScrollbar = ref.current.scrollHeight > ref.current.clientHeight;
99
119
  return [hasVerticalScrollbar, height > ref.current.scrollHeight];
100
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/taco",
3
- "version": "17.1.0",
3
+ "version": "17.2.0-EC-005678-test-tanstack-virtual.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -51,7 +51,7 @@
51
51
  "@react-aria/focus": "^3.19.0",
52
52
  "@react-aria/interactions": "^3.12.0",
53
53
  "@tanstack/react-table": "^8.21.3",
54
- "@tanstack/react-virtual": "3.14.25",
54
+ "@tanstack/react-virtual": "3.14.28",
55
55
  "date-fns": "^4.4.0",
56
56
  "lodash": "^4.18.1",
57
57
  "motion": "12.42.2",
@@ -70,7 +70,7 @@
70
70
  "@svgr/cli": "^8.1.0",
71
71
  "@testing-library/jest-dom": "^7.0.1",
72
72
  "@testing-library/react": "^16.3.3",
73
- "@testing-library/user-event": "^14.6.12",
73
+ "@testing-library/user-event": "^14.6.13",
74
74
  "@types/lodash": "^4.17.27",
75
75
  "@types/node": "^22.20.5",
76
76
  "@types/react": "19.2.18",
@@ -90,5 +90,5 @@
90
90
  "vitest": "^4.1.12",
91
91
  "vitest-fail-on-console": "^0.10.1"
92
92
  },
93
- "gitHead": "7f70a4854f477b84a05f453c838e94433b8c7f6a"
93
+ "gitHead": "9f6a5293c40c6b57e94cd562c28bb00a29def006"
94
94
  }