@economic/taco 2.29.3 → 2.30.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/dist/esm/index.css +6 -2
  2. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js +4 -5
  3. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js.map +1 -1
  4. package/dist/esm/packages/taco/src/components/Menu/components/Trigger.js +9 -7
  5. package/dist/esm/packages/taco/src/components/Menu/components/Trigger.js.map +1 -1
  6. package/dist/esm/packages/taco/src/components/Select2/Select2.js +3 -1
  7. package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
  8. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +1 -0
  9. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  10. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Body/Body.js +13 -4
  11. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Body/Body.js.map +1 -1
  12. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +2 -2
  13. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
  14. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js +1 -1
  15. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js.map +1 -1
  16. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js +1 -1
  17. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js.map +1 -1
  18. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js +1 -1
  19. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js.map +1 -1
  20. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +21 -27
  21. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  22. package/dist/esm/packages/taco/src/primitives/Table/Core/util/rows.js +1 -2
  23. package/dist/esm/packages/taco/src/primitives/Table/Core/util/rows.js.map +1 -1
  24. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  25. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +45 -12
  26. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
  27. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +8 -8
  28. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
  29. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js +7 -3
  30. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js.map +1 -1
  31. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js +1 -2
  32. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js.map +1 -1
  33. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +1 -1
  34. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  35. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +2 -4
  36. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  37. package/dist/esm/packages/taco/src/utils/dom.js +4 -1
  38. package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
  39. package/dist/index.css +6 -2
  40. package/dist/primitives/Table/Core/components/Body/Body.d.ts +1 -0
  41. package/dist/primitives/Table/Core/util/rows.d.ts +0 -1
  42. package/dist/primitives/Table/types.d.ts +8 -9
  43. package/dist/primitives/Table/useTableDataLoader.d.ts +5 -4
  44. package/dist/primitives/Table/useTableManager/listeners/useTableSearchListener.d.ts +2 -1
  45. package/dist/taco.cjs.development.js +119 -78
  46. package/dist/taco.cjs.development.js.map +1 -1
  47. package/dist/taco.cjs.production.min.js +1 -1
  48. package/dist/taco.cjs.production.min.js.map +1 -1
  49. package/dist/utils/dom.d.ts +1 -0
  50. package/package.json +2 -2
@@ -4122,6 +4122,9 @@ function isElementInteractive(element) {
4122
4122
  }
4123
4123
  return ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL', 'OPTION'].includes(element.tagName) && !element.hidden && !element.disabled && !element.readOnly;
4124
4124
  }
4125
+ function isElementInsideTable3OrReport(element) {
4126
+ return !!(element !== null && element !== void 0 && element.closest('[data-taco^=table]'));
4127
+ }
4125
4128
 
4126
4129
  function isPressingMetaKey(event) {
4127
4130
  return isMacOs() ? event.metaKey : event.ctrlKey;
@@ -5823,9 +5826,7 @@ const useCombobox = ({
5823
5826
  }
5824
5827
  };
5825
5828
  const handleInputKeyDown = event => {
5826
- var _inputRef$current;
5827
5829
  event.persist();
5828
- const insideTheTable = !!((_inputRef$current = inputRef.current) !== null && _inputRef$current !== void 0 && _inputRef$current.closest('table, [role="rowgroup"]'));
5829
5830
  if (!event.ctrlKey && !event.metaKey) {
5830
5831
  switch (event.key) {
5831
5832
  case 'Backspace':
@@ -5847,7 +5848,7 @@ const useCombobox = ({
5847
5848
  }
5848
5849
  case 'Enter':
5849
5850
  {
5850
- if (insideTheTable) {
5851
+ if (isElementInsideTable3OrReport(event.currentTarget)) {
5851
5852
  event.preventDefault();
5852
5853
  if (inline && !open) {
5853
5854
  setOpen(true);
@@ -5865,7 +5866,7 @@ const useCombobox = ({
5865
5866
  if (open) {
5866
5867
  event.preventDefault();
5867
5868
  } else {
5868
- if (!inline && buttonRef.current && !insideTheTable) {
5869
+ if (!inline && buttonRef.current && !isElementInsideTable3OrReport(event.currentTarget)) {
5869
5870
  buttonRef.current.click();
5870
5871
  }
5871
5872
  }
@@ -5885,7 +5886,7 @@ const useCombobox = ({
5885
5886
  listRef.current.dispatchEvent(createCustomKeyboardEvent(event));
5886
5887
  }
5887
5888
  if (inline && !open) {
5888
- if ((event.key === 'ArrowUp' || event.key === 'ArrowDown') && !insideTheTable) {
5889
+ if ((event.key === 'ArrowUp' || event.key === 'ArrowDown') && !isElementInsideTable3OrReport(event.currentTarget)) {
5889
5890
  event.preventDefault();
5890
5891
  const initialIndex = event.key === 'ArrowUp' ? data.length - 1 : 0;
5891
5892
  setCurrentIndex(currentIndex !== undefined ? currentIndex : initialIndex);
@@ -8194,12 +8195,13 @@ const Link$1 = /*#__PURE__*/React.forwardRef(function MenuLink(props, ref) {
8194
8195
  const Trigger$6 = /*#__PURE__*/React.forwardRef(function MenuTrigger(props, ref) {
8195
8196
  const menu = useCurrentMenu();
8196
8197
  const internalRef = useMergedRef(ref);
8197
- const preventArrowDownShortcut = event => {
8198
- var _internalRef$current;
8199
- const isRenderedInTable = !!((_internalRef$current = internalRef.current) !== null && _internalRef$current !== void 0 && _internalRef$current.closest('tbody'));
8200
- if (isRenderedInTable && event.key === 'ArrowDown') {
8201
- var _internalRef$current2, _internalRef$current3;
8202
- internalRef === null || internalRef === void 0 ? void 0 : (_internalRef$current2 = internalRef.current) === null || _internalRef$current2 === void 0 ? void 0 : (_internalRef$current3 = _internalRef$current2.parentNode) === null || _internalRef$current3 === void 0 ? void 0 : _internalRef$current3.dispatchEvent(createCustomKeyboardEvent(event));
8198
+ const handleKeyDown = event => {
8199
+ if (event.key === 'ArrowDown') {
8200
+ if (isElementInsideTable3OrReport(event.currentTarget)) {
8201
+ var _event$currentTarget$;
8202
+ event.preventDefault();
8203
+ (_event$currentTarget$ = event.currentTarget.parentNode) === null || _event$currentTarget$ === void 0 ? void 0 : _event$currentTarget$.dispatchEvent(createCustomKeyboardEvent(event));
8204
+ }
8203
8205
  }
8204
8206
  };
8205
8207
  React.useEffect(() => {
@@ -8210,7 +8212,7 @@ const Trigger$6 = /*#__PURE__*/React.forwardRef(function MenuTrigger(props, ref)
8210
8212
  return /*#__PURE__*/React.createElement(DropdownMenuPrimitive.Trigger, Object.assign({}, props, {
8211
8213
  asChild: true,
8212
8214
  ref: internalRef,
8213
- onKeyDown: preventArrowDownShortcut
8215
+ onKeyDown: handleKeyDown
8214
8216
  }));
8215
8217
  });
8216
8218
 
@@ -9924,6 +9926,7 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
9924
9926
  id,
9925
9927
  accessorKey,
9926
9928
  // To avoid errors caused by undefined row data values, we pass accessorFn as a preventive measure
9929
+ // accessorKey can be dot notated strings, so we use lodash.get to access deeply nested children
9927
9930
  accessorFn: row => get(row, accessorKey),
9928
9931
  header: header,
9929
9932
  // features
@@ -9951,10 +9954,7 @@ function processChildren(child, columns, defaultSizing, defaultSorting, defaultV
9951
9954
  column.cell = info => renderer(info.getValue(), info.row.original);
9952
9955
  }
9953
9956
  if (typeof footer === 'function') {
9954
- column.footer = info => footer(info.table.getRowModel().rows.flatMap(row => {
9955
- var _row$original;
9956
- return ((_row$original = row.original) === null || _row$original === void 0 ? void 0 : _row$original[id]) !== undefined ? [row.original[id]] : [];
9957
- }));
9957
+ column.footer = info => footer(info.table.getRowModel().rows.flatMap(row => row.original !== undefined ? row.original : []));
9958
9958
  }
9959
9959
  // config - filtering
9960
9960
  if (enableColumnFilter) {
@@ -10420,11 +10420,11 @@ function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
10420
10420
  const [rowActiveIndex, setRowActiveIndex] = React__default.useState(initialRowActiveIndex);
10421
10421
  const [rowHoverIndex, setRowHoverIndex] = React__default.useState(undefined);
10422
10422
  const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();
10423
- const move = (direction, length, scrollToIndex) => setRowActiveIndex(currentIndex => {
10424
- const nextIndex = currentIndex !== undefined ? getNextIndex(direction, currentIndex, length) : 0;
10425
- setTimeout(() => scrollToIndex(nextIndex), 1);
10426
- return nextIndex;
10427
- });
10423
+ const move = (direction, length, scrollToIndex) => {
10424
+ const nextIndex = rowActiveIndex !== undefined ? getNextIndex(direction, rowActiveIndex, length) : 0;
10425
+ scrollToIndex(nextIndex);
10426
+ setTimeout(() => setRowActiveIndex(nextIndex), 50);
10427
+ };
10428
10428
  const onKeyDown = React__default.useCallback((event, length, scrollToIndex) => {
10429
10429
  if (!isEnabled || event.defaultPrevented) {
10430
10430
  return;
@@ -10436,8 +10436,8 @@ function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
10436
10436
  event.preventDefault();
10437
10437
  if (event.ctrlKey || event.metaKey) {
10438
10438
  const newIndex = 0;
10439
- setRowActiveIndex(newIndex);
10440
10439
  scrollToIndex(newIndex);
10440
+ setRowActiveIndex(newIndex);
10441
10441
  } else {
10442
10442
  move(-1, length, scrollToIndex);
10443
10443
  }
@@ -10446,14 +10446,14 @@ function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
10446
10446
  event.preventDefault();
10447
10447
  if (event.ctrlKey || event.metaKey) {
10448
10448
  const newIndex = length - 1;
10449
- setRowActiveIndex(newIndex);
10450
10449
  scrollToIndex(newIndex);
10450
+ setRowActiveIndex(newIndex);
10451
10451
  } else {
10452
10452
  move(+1, length, scrollToIndex);
10453
10453
  }
10454
10454
  return;
10455
10455
  }
10456
- }, [isEnabled]);
10456
+ }, [isEnabled, rowActiveIndex]);
10457
10457
  const onFocus = React__default.useCallback((event, length, scrollToIndex) => {
10458
10458
  if (!isEnabled || event.isDefaultPrevented()) {
10459
10459
  return;
@@ -10640,7 +10640,7 @@ function _finallyRethrows(body, finalizer) {
10640
10640
  }
10641
10641
 
10642
10642
  const DEFAULT_PAGE_SIZE = 100;
10643
- function useTableDataLoader(fetch, fetchAll, options = {
10643
+ function useTableDataLoader(fetchPage, fetchAll, options = {
10644
10644
  pageSize: DEFAULT_PAGE_SIZE
10645
10645
  }) {
10646
10646
  const {
@@ -10656,11 +10656,11 @@ function useTableDataLoader(fetch, fetchAll, options = {
10656
10656
  const _lastUsedFilters = React__default.useRef([]);
10657
10657
  const _lastUsedSearch = React__default.useRef();
10658
10658
  const _forceReset = React__default.useRef(false);
10659
- const loadPage = function (pageIndex, sorting, filters, search) {
10659
+ const loadPage = function (pageIndex, sorting, filters) {
10660
10660
  try {
10661
10661
  let reset = false;
10662
10662
  // sorting or filters changed, reset everything
10663
- if (_forceReset.current || search !== _lastUsedSearch.current || JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current)) {
10663
+ if (_forceReset.current || JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current)) {
10664
10664
  _pendingPageRequests.current = {};
10665
10665
  // nuke the dataset so that we "start again" after sorting
10666
10666
  reset = true;
@@ -10676,11 +10676,9 @@ function useTableDataLoader(fetch, fetchAll, options = {
10676
10676
  _lastUsedSorting.current = sorting;
10677
10677
  // set the filters so we can track if it changed between loads
10678
10678
  _lastUsedFilters.current = filters;
10679
- // set the search so we can track if it changed between loads
10680
- _lastUsedSearch.current = search;
10681
10679
  const _temp = _finallyRethrows(function () {
10682
10680
  return _catch(function () {
10683
- return Promise.resolve(fetch(pageIndex, pageSize, sorting, filters, search)).then(function (response) {
10681
+ return Promise.resolve(fetchPage(pageIndex, pageSize, sorting, filters)).then(function (response) {
10684
10682
  // update state, here we do some "magic" to support "load in place"
10685
10683
  setData(currentData => {
10686
10684
  let nextData;
@@ -10709,10 +10707,14 @@ function useTableDataLoader(fetch, fetchAll, options = {
10709
10707
  return Promise.reject(e);
10710
10708
  }
10711
10709
  };
10712
- const loadAll = function (sorting, filters, search) {
10710
+ const loadAll = function (sorting, filters) {
10713
10711
  try {
10712
+ // set the sorting so we can track if it changed between loads
10713
+ _lastUsedSorting.current = sorting;
10714
+ // set the filters so we can track if it changed between loads
10715
+ _lastUsedFilters.current = filters;
10714
10716
  const _temp2 = _catch(function () {
10715
- return Promise.resolve(fetchAll(sorting, filters, search)).then(function (response) {
10717
+ return Promise.resolve(fetchAll(sorting, filters)).then(function (response) {
10716
10718
  length.current = response.length;
10717
10719
  setData(() => {
10718
10720
  let nextData;
@@ -10734,22 +10736,52 @@ function useTableDataLoader(fetch, fetchAll, options = {
10734
10736
  const invalidate = function () {
10735
10737
  try {
10736
10738
  _forceReset.current = true;
10737
- return loadPage(0, _lastUsedSorting.current, _lastUsedFilters.current, _lastUsedSearch.current);
10739
+ return loadPage(0, _lastUsedSorting.current, _lastUsedFilters.current);
10738
10740
  } catch (e) {
10739
10741
  return Promise.reject(e);
10740
10742
  }
10741
10743
  };
10742
- // we reset the page to 0 whenever sorting, filtering or search changes
10744
+ // search works client side - it fetches all then works client side - so these handlers are a little "weird"
10745
+ // if a search is currently "active", we need to re load all because
10743
10746
  const handleSort = function (sorting) {
10744
10747
  try {
10745
- return loadPage(0, sorting, _lastUsedFilters.current, _lastUsedSearch.current);
10748
+ // set the sorting so we can track if it changed between loads
10749
+ _lastUsedSorting.current = sorting;
10750
+ if (_lastUsedSearch.current) {
10751
+ // we're searching, which means we need to refetch all with the correct sorting applied
10752
+ loadAll(sorting, _lastUsedFilters.current);
10753
+ } else {
10754
+ // reset the page to 0 whenever sorting
10755
+ loadPage(0, sorting, _lastUsedFilters.current);
10756
+ }
10757
+ return Promise.resolve();
10746
10758
  } catch (e) {
10747
10759
  return Promise.reject(e);
10748
10760
  }
10749
10761
  };
10750
10762
  const handleFilter = function (filters) {
10751
10763
  try {
10752
- return loadPage(0, _lastUsedSorting.current, filters, _lastUsedSearch.current);
10764
+ // set the filters so we can track if it changed between loads
10765
+ _lastUsedFilters.current = filters;
10766
+ if (_lastUsedSearch.current) {
10767
+ // we're searching, which means we need to refetch all with the correct sorting applied
10768
+ loadAll(_lastUsedSorting.current, filters);
10769
+ } else {
10770
+ // reset the page to 0 whenever sorting
10771
+ loadPage(0, _lastUsedSorting.current, filters);
10772
+ }
10773
+ return Promise.resolve();
10774
+ } catch (e) {
10775
+ return Promise.reject(e);
10776
+ }
10777
+ };
10778
+ const handleSearch = function (search) {
10779
+ try {
10780
+ // set the search so we can track if it changed between loads
10781
+ _lastUsedSearch.current = search || undefined;
10782
+ // search works client side, and focusing the search field triggers a load of all so we don't actually
10783
+ // want to load anything when search gets changed, we just store the value for other handlers
10784
+ return Promise.resolve();
10753
10785
  } catch (e) {
10754
10786
  return Promise.reject(e);
10755
10787
  }
@@ -10760,6 +10792,7 @@ function useTableDataLoader(fetch, fetchAll, options = {
10760
10792
  loadAll,
10761
10793
  loadPage,
10762
10794
  onChangeFilter: handleFilter,
10795
+ onChangeSearch: handleSearch,
10763
10796
  onChangeSort: handleSort,
10764
10797
  pageSize
10765
10798
  }, invalidate];
@@ -11050,14 +11083,18 @@ function resetHighlightedColumnIndexes(value, table) {
11050
11083
  return firstRowIndex;
11051
11084
  }
11052
11085
 
11053
- function useTableSearchListener(table) {
11086
+ function useTableSearchListener(table, onChangeSearch) {
11054
11087
  const meta = table.options.meta;
11055
11088
  // recalculates highlighted indexes whenever something important changes
11056
11089
  React__default.useEffect(() => {
11057
11090
  if (meta.search.isEnabled) {
11058
- resetHighlightedColumnIndexes(table.getState().globalFilter, table);
11091
+ const query = table.getState().globalFilter;
11092
+ resetHighlightedColumnIndexes(query, table);
11093
+ if (typeof onChangeSearch === 'function') {
11094
+ onChangeSearch(query);
11095
+ }
11059
11096
  }
11060
- }, [meta.server.loadAllStatus, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, table.getState().globalFilter, JSON.stringify(table.getState().sorting), JSON.stringify(table.getState().columnVisibility)]);
11097
+ }, [meta.server.loadAllStatus, meta.search.isEnabled, meta.search.enableGlobalFilter, table.getRowModel().rows.length, table.getState().globalFilter, JSON.stringify(table.getState().sorting), JSON.stringify(table.getState().columnVisibility), onChangeSearch]);
11061
11098
  }
11062
11099
 
11063
11100
  function useTableSettingsListener(table, onChangeSettings) {
@@ -11143,11 +11180,10 @@ function useTableSortingListener(table, onSort) {
11143
11180
  function useTableServerLoadingListener(table, loadPage) {
11144
11181
  const sorting = table.getState().sorting;
11145
11182
  const columnFilters = table.getState().columnFilters;
11146
- const search = table.getState().globalFilter;
11147
11183
  // trigger load of the first page on mount
11148
11184
  React__default.useEffect(() => {
11149
11185
  if (loadPage) {
11150
- loadPage(0, sorting, columnFilters, search);
11186
+ loadPage(0, sorting, columnFilters);
11151
11187
  }
11152
11188
  }, []);
11153
11189
  }
@@ -11248,7 +11284,7 @@ function useTableManager(props, meta, internalColumns) {
11248
11284
  useTableFontSizeListener(instance);
11249
11285
  useTableRowHeightListener(instance);
11250
11286
  useTableRowSelectionListener(instance, props.onRowSelect);
11251
- useTableSearchListener(instance);
11287
+ useTableSearchListener(instance, props.onChangeSearch);
11252
11288
  useTableServerLoadingListener(instance, server.loadPage);
11253
11289
  useTableSettingsListener(instance, setSettings);
11254
11290
  useTableShortcutsListener(instance, props.shortcuts);
@@ -11509,7 +11545,6 @@ const ROW_HEIGHT_ESTIMATES = {
11509
11545
  tall: 49,
11510
11546
  'extra-tall': 57
11511
11547
  };
11512
- const HEADER_FOOTER_ROW_HEIGHT_ESTIMATE = ROW_HEIGHT_ESTIMATES.medium + 2; // header includes 2px border
11513
11548
 
11514
11549
  function SkeletonRow(props) {
11515
11550
  const {
@@ -11547,7 +11582,7 @@ function RowWithServerLoading(props) {
11547
11582
  React__default.useEffect(() => {
11548
11583
  if (inView) {
11549
11584
  var _tableMeta$server$loa, _tableMeta$server;
11550
- (_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, pageIndex, table.getState().sorting, table.getState().columnFilters, table.getState().globalFilter);
11585
+ (_tableMeta$server$loa = (_tableMeta$server = tableMeta.server).loadPage) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, pageIndex, table.getState().sorting, table.getState().columnFilters);
11551
11586
  }
11552
11587
  }, [inView]);
11553
11588
  const groupedCellCount = (_table$getState$group = (_table$getState = table.getState()) === null || _table$getState === void 0 ? void 0 : _table$getState.grouping.length) !== null && _table$getState$group !== void 0 ? _table$getState$group : 0;
@@ -11599,15 +11634,11 @@ function Row(props) {
11599
11634
  })));
11600
11635
  }
11601
11636
 
11602
- const TABLE_SCROLL_PADDING_BOTTOM = 36;
11603
- const TABLE_PADDING_BOTTOM = 0;
11604
11637
  function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
11605
11638
  var _table$getState$group, _ref, _virtualItems$padding, _virtualItems$padding2, _ref2, _virtualItems;
11606
11639
  const tableMeta = table.options.meta;
11607
11640
  const rows = table.getRowModel().rows;
11608
- const HEADER_OFFSET_TOTAL = HEADER_FOOTER_ROW_HEIGHT_ESTIMATE * table.getHeaderGroups().length;
11609
- const isTableGrouped = !!((_table$getState$group = table.getState().grouping) !== null && _table$getState$group !== void 0 && _table$getState$group.length);
11610
- const FOOTER_OFFSET_TOTAL = tableMeta.footer.isEnabled ? HEADER_FOOTER_ROW_HEIGHT_ESTIMATE : 0;
11641
+ const isTableRowGrouped = !!((_table$getState$group = table.getState().grouping) !== null && _table$getState$group !== void 0 && _table$getState$group.length);
11611
11642
  // expanded rows
11612
11643
  const {
11613
11644
  createRowMeasurer,
@@ -11615,16 +11646,25 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
11615
11646
  } = useRowHeightVirtualisation(table);
11616
11647
  // row groups
11617
11648
  const rangeExtractor = useRowGroupVirtualisation(table);
11649
+ // account for thead and tfoot in the scroll area - both are always medium row height
11650
+ const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;
11651
+ // column groups offset the bottom padding :shrug:, multiplying by 1.5 ensures the bottom padding remains
11652
+ // consistent when there are groups and when there aren't. 1.5 is relatively arbitrary, but it gives alignment
11653
+ const scrollPaddingEnd = ROW_HEIGHT_ESTIMATES.medium * (table.getHeaderGroups().length > 1 ? 1.5 : 1);
11654
+ const scrollMargin = isTableRowGrouped ? 0 : scrollPaddingStart;
11618
11655
  const virtualiser = reactVirtual.useVirtualizer({
11619
11656
  count: rows.length,
11620
11657
  estimateSize,
11621
11658
  getScrollElement: () => tableRef.current,
11622
11659
  overscan: tableMeta.printing.isPrinting ? rows.length : undefined,
11623
11660
  rangeExtractor,
11624
- scrollPaddingStart: isTableGrouped ? HEADER_FOOTER_ROW_HEIGHT_ESTIMATE : undefined,
11625
- scrollPaddingEnd: HEADER_OFFSET_TOTAL + TABLE_SCROLL_PADDING_BOTTOM,
11626
- paddingEnd: TABLE_PADDING_BOTTOM
11661
+ // correctly sets top and bottom spacing for the scroll container - very sensitive, don't change
11662
+ scrollMargin,
11663
+ // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list
11664
+ scrollPaddingStart,
11665
+ scrollPaddingEnd: tableMeta.footer.isEnabled ? scrollPaddingEnd * 2 : scrollPaddingEnd
11627
11666
  });
11667
+ const totalSize = virtualiser.getTotalSize();
11628
11668
  const virtualItems = virtualiser.getVirtualItems();
11629
11669
  const scrollToIndex = React__default.useCallback((index, options = {
11630
11670
  align: 'auto',
@@ -11637,29 +11677,18 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
11637
11677
  if (tableRef.current) {
11638
11678
  if (index === 0) {
11639
11679
  virtualiser.scrollToOffset(0, notSmooth);
11640
- } else if (index >= virtualItems.length - 1) {
11641
- // scrolling to the last row isn't easy when rows have dynamic height
11642
- // because you don't know all the heights until they render...
11643
- // so when you skip to the last you don't know if "the end" is actually the end
11644
- virtualiser.scrollToIndex(index, notSmooth);
11645
- // https://github.com/TanStack/virtual/issues/216
11646
- setTimeout(() => {
11647
- virtualiser.scrollToIndex(index, notSmooth);
11648
- setTimeout(() => {
11649
- virtualiser.scrollToIndex(index, notSmooth);
11650
- }, 150);
11651
- }, 150);
11680
+ } else if (index === rows.length - 1) {
11681
+ // sometimes the last row doesn't fully show, so we just force scroll to the bottom
11682
+ tableRef.current.scrollTop = tableRef.current.scrollHeight;
11652
11683
  } else {
11653
11684
  virtualiser.scrollToIndex(index, options);
11654
11685
  }
11655
11686
  }
11656
- }, [virtualItems.length, tableRef.current]);
11687
+ }, [virtualItems.length, tableRef.current, totalSize, rows.length]);
11657
11688
  // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0
11658
- const paddingStartIndex = isTableGrouped && rows.length > 1 ? 1 : 0;
11689
+ const paddingStartIndex = isTableRowGrouped && rows.length > 1 ? 1 : 0;
11659
11690
  // styling for offsetting rows - this "is" the virtualisation
11660
- const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [
11661
- // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0
11662
- Math.max(0, (_ref = ((_virtualItems$padding = virtualItems[paddingStartIndex]) === null || _virtualItems$padding === void 0 ? void 0 : _virtualItems$padding.start) - virtualiser.options.scrollMargin - ((_virtualItems$padding2 = virtualItems[paddingStartIndex]) === null || _virtualItems$padding2 === void 0 ? void 0 : _virtualItems$padding2.size)) !== null && _ref !== void 0 ? _ref : 0), Math.max(0, (_ref2 = virtualiser.getTotalSize() - ((_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end)) !== null && _ref2 !== void 0 ? _ref2 : 0)] : [0, 0];
11691
+ const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, (_ref = ((_virtualItems$padding = virtualItems[paddingStartIndex]) === null || _virtualItems$padding === void 0 ? void 0 : _virtualItems$padding.start) - ((_virtualItems$padding2 = virtualItems[paddingStartIndex]) === null || _virtualItems$padding2 === void 0 ? void 0 : _virtualItems$padding2.size) - scrollMargin) !== null && _ref !== void 0 ? _ref : 0), Math.max(0, (_ref2 = totalSize - ((_virtualItems = virtualItems[virtualItems.length - 1]) === null || _virtualItems === void 0 ? void 0 : _virtualItems.end)) !== null && _ref2 !== void 0 ? _ref2 : 0)] : [0, 0];
11663
11692
  // ensure default active rows are scrolled to
11664
11693
  React__default.useEffect(() => {
11665
11694
  if (defaultRowActiveIndex) {
@@ -11674,7 +11703,7 @@ function useTableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
11674
11703
  let content = null;
11675
11704
  if (rows.length) {
11676
11705
  style = {
11677
- height: `${virtualiser.getTotalSize() - HEADER_OFFSET_TOTAL + FOOTER_OFFSET_TOTAL}px`,
11706
+ height: `${totalSize - scrollMargin}px`,
11678
11707
  paddingBottom,
11679
11708
  paddingTop
11680
11709
  };
@@ -12024,7 +12053,7 @@ function Header$4(context) {
12024
12053
  const _temp = function () {
12025
12054
  if (tableMeta.server.loadAllIfNeeded) {
12026
12055
  // don't pass the search query because we need all data - not filtered data
12027
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, undefined)).then(function () {});
12056
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
12028
12057
  }
12029
12058
  }();
12030
12059
  // load all data if that is possible
@@ -12098,7 +12127,7 @@ function Cell$3(context) {
12098
12127
  const _temp3 = function () {
12099
12128
  if (tableMeta.server.loadAllIfNeeded && selectedRows.some(row => row.original === undefined)) {
12100
12129
  // don't pass the search query because we need all data - not filtered data
12101
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, undefined)).then(function () {});
12130
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
12102
12131
  }
12103
12132
  }();
12104
12133
  return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
@@ -13074,6 +13103,7 @@ function useAugmentedFocusManager() {
13074
13103
  function Body(props) {
13075
13104
  const {
13076
13105
  enableHorizontalArrowKeyNavigation = false,
13106
+ scrollToIndex,
13077
13107
  table,
13078
13108
  ...attributes
13079
13109
  } = props;
@@ -13103,16 +13133,24 @@ function Body(props) {
13103
13133
  // there are no previous elements to focus, go up a row or go outside the table
13104
13134
  // but only if there are actually any focusable elements in the row
13105
13135
  event.preventDefault();
13106
- tableMeta.rowActive.setRowActiveIndex(tableMeta.rowActive.rowActiveIndex - 1);
13107
- requestAnimationFrame(() => focusManager.focusLast());
13136
+ const prevIndex = tableMeta.rowActive.rowActiveIndex - 1;
13137
+ tableMeta.rowActive.setRowActiveIndex(prevIndex);
13138
+ requestAnimationFrame(() => {
13139
+ focusManager.focusLast();
13140
+ scrollToIndex(prevIndex);
13141
+ });
13108
13142
  }
13109
13143
  } else {
13110
13144
  if (!isLastRow) {
13111
13145
  // there are no next elements to focus, go down a row or go outside the table
13112
13146
  // but only if there are actually any focusable elements in the row
13113
13147
  event.preventDefault();
13114
- tableMeta.rowActive.setRowActiveIndex(tableMeta.rowActive.rowActiveIndex + 1);
13115
- requestAnimationFrame(() => focusManager.focusFirst());
13148
+ const nextIndex = tableMeta.rowActive.rowActiveIndex + 1;
13149
+ tableMeta.rowActive.setRowActiveIndex(nextIndex);
13150
+ requestAnimationFrame(() => {
13151
+ focusManager.focusFirst();
13152
+ scrollToIndex(nextIndex);
13153
+ });
13116
13154
  }
13117
13155
  }
13118
13156
  }
@@ -13440,7 +13478,7 @@ function Search$1(props) {
13440
13478
  const _temp = function () {
13441
13479
  if (tableMeta.server.loadAllIfNeeded) {
13442
13480
  // don't pass the search query because we need all data - not filtered data
13443
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, undefined)).then(function () {});
13481
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
13444
13482
  }
13445
13483
  }();
13446
13484
  // load all data if that is possible
@@ -15148,6 +15186,8 @@ const Select2 = /*#__PURE__*/React__default.forwardRef(function Select2(props, r
15148
15186
  var _listboxRef$current;
15149
15187
  if (open) {
15150
15188
  event.preventDefault();
15189
+ } else if (isElementInsideTable3OrReport(event.currentTarget)) {
15190
+ return;
15151
15191
  } else if (!event.ctrlKey && !event.metaKey && (event.key === 'ArrowDown' || /^[a-z0-9]$/i.test(event.key))) {
15152
15192
  setOpen(true);
15153
15193
  }
@@ -15488,7 +15528,7 @@ function Print$1(props) {
15488
15528
  const _temp2 = function () {
15489
15529
  if (tableMeta.server.isEnabled && tableMeta.server.loadAllIfNeeded) {
15490
15530
  const _temp = _catch(function () {
15491
- return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters, undefined)).then(function () {});
15531
+ return Promise.resolve(tableMeta.server.loadAllIfNeeded(table.getState().sorting, table.getState().columnFilters)).then(function () {});
15492
15532
  }, function (error) {
15493
15533
  const errorMessage = `${texts.table.print.error}: ${error}`;
15494
15534
  console.error(errorMessage);
@@ -16170,6 +16210,7 @@ function TableGrid(props) {
16170
16210
  }))))))), table.instance.getRowModel().rows.length ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Body, {
16171
16211
  enableHorizontalArrowKeyNavigation: enableHorizontalArrowKeyNavigation,
16172
16212
  table: table.instance,
16213
+ scrollToIndex: table.renderer.scrollToIndex,
16173
16214
  style: table.renderer.style
16174
16215
  }, table.renderer.rows), table.meta.footer.isEnabled ? /*#__PURE__*/React__default.createElement(Foot, {
16175
16216
  table: table.instance