@economic/taco 2.64.1-table-flickering.0 → 2.65.0-alpha.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/taco.cjs CHANGED
@@ -36623,6 +36623,17 @@ function useTableRowDrop(isEnabled = false, onRowDrop) {
36623
36623
  handleDrop: isEnabled ? onRowDrop : void 0
36624
36624
  };
36625
36625
  }
36626
+ function useTableRowActiveListener$1(table, onRowActive) {
36627
+ var _a;
36628
+ const meta = table.options.meta;
36629
+ const rows = table.getRowModel().flatRows;
36630
+ const currentRow = meta.rowActive.rowActiveIndex !== void 0 ? (_a = rows[meta.rowActive.rowActiveIndex]) == null ? void 0 : _a.original : void 0;
36631
+ React.useEffect(() => {
36632
+ if (meta.rowActive.isEnabled && onRowActive) {
36633
+ onRowActive(currentRow);
36634
+ }
36635
+ }, [meta.rowActive.isEnabled, currentRow, onRowActive]);
36636
+ }
36626
36637
  const DEFAULT_EMPTY_ARRAY = [];
36627
36638
  function useTableManager(props, ref, meta, internalColumns) {
36628
36639
  var _a;
@@ -36723,6 +36734,7 @@ function useTableManager(props, ref, meta, internalColumns) {
36723
36734
  useTableDataListener(instance, length);
36724
36735
  useTableFilterListener(instance, props.onChangeFilter);
36725
36736
  useTableFontSizeListener(instance);
36737
+ useTableRowActiveListener$1(instance, props.onRowActive);
36726
36738
  useTableRowHeightListener(instance);
36727
36739
  useTableRowSelectionListener(instance, props.onRowSelect);
36728
36740
  useTableSearchListener(instance);
@@ -38446,6 +38458,21 @@ function Cell$2(props) {
38446
38458
  }
38447
38459
  return /* @__PURE__ */ React.createElement(CellRenderer, { ...cellProps });
38448
38460
  }
38461
+ const useResizeObserver$1 = (ref, enabled = true) => {
38462
+ const [size2, setSize] = React.useState();
38463
+ React.useEffect(() => {
38464
+ if (!ref.current || !enabled) {
38465
+ return () => void 0;
38466
+ }
38467
+ const observer = new ResizeObserver((entries) => {
38468
+ const entry = entries[0];
38469
+ setSize({ height: entry.contentRect.height, width: entry.contentRect.width });
38470
+ });
38471
+ observer.observe(ref.current);
38472
+ return () => observer.disconnect();
38473
+ }, [enabled]);
38474
+ return size2;
38475
+ };
38449
38476
  const DisplayRow = React.memo(function DisplayRow2(props) {
38450
38477
  var _a, _b, _c;
38451
38478
  const { children, cellRenderer: CellRenderer, index: index2, measureRow, row, table, ...otherAttributes } = props;
@@ -38540,12 +38567,13 @@ const DisplayRow = React.memo(function DisplayRow2(props) {
38540
38567
  }
38541
38568
  const ref = React.useRef(null);
38542
38569
  const expansionRef = React.useRef(null);
38570
+ const expandedRowSize = useResizeObserver$1(expansionRef, !!expandedRow);
38543
38571
  React.useEffect(() => {
38544
38572
  var _a2, _b2;
38545
38573
  const rowHeight = ((_a2 = ref.current) == null ? void 0 : _a2.getBoundingClientRect().height) ?? 0;
38546
38574
  const expansionHeight = ((_b2 = expansionRef.current) == null ? void 0 : _b2.getBoundingClientRect().height) ?? 0;
38547
38575
  measureRow(rowHeight + expansionHeight);
38548
- }, [expansionRef.current]);
38576
+ }, [expansionRef.current, expandedRowSize == null ? void 0 : expandedRowSize.height]);
38549
38577
  const className = clsx("group/row", otherAttributes.className, {
38550
38578
  "hover:cursor-grab": tableMeta.rowDrag.isEnabled && typeof attributes.onClick !== "function",
38551
38579
  "hover:cursor-pointer": typeof attributes.onClick === "function"
@@ -45161,11 +45189,11 @@ function guessComparatorsBasedOnControl(column) {
45161
45189
  }
45162
45190
  const FilterContext = React.createContext([]);
45163
45191
  const FilterColumn = React.forwardRef((props, ref) => {
45164
- const { allColumns, onChange: handleChange, value = null, ...attributes } = props;
45192
+ const { allHeaders, onChange: handleChange, value = null, ...attributes } = props;
45165
45193
  const { texts } = useLocalization();
45166
45194
  const filters = React.useContext(FilterContext);
45167
- const selectedColumn = allColumns.find((column) => column.id === value);
45168
- const warning2 = selectedColumn && !selectedColumn.getIsVisible();
45195
+ const selectedColumn = allHeaders.find((header) => header.id === value);
45196
+ const warning2 = selectedColumn && !selectedColumn.column.getIsVisible();
45169
45197
  return /* @__PURE__ */ React.createElement("div", { className: "flex flex-col" }, /* @__PURE__ */ React.createElement(
45170
45198
  Field,
45171
45199
  {
@@ -45183,23 +45211,23 @@ const FilterColumn = React.forwardRef((props, ref) => {
45183
45211
  onChange: handleChange,
45184
45212
  value
45185
45213
  },
45186
- allColumns.map((column) => {
45187
- var _a, _b, _c;
45214
+ allHeaders.map((header) => {
45215
+ var _a, _b;
45188
45216
  return /* @__PURE__ */ React.createElement(
45189
45217
  Select22.Option,
45190
45218
  {
45191
- key: column.id,
45192
- value: column.id,
45193
- postfix: !column.getIsVisible() || column.getIsGrouped() ? /* @__PURE__ */ React.createElement(
45219
+ key: header.column.id,
45220
+ value: header.column.id,
45221
+ postfix: !header.column.getIsVisible() || header.column.getIsGrouped() ? /* @__PURE__ */ React.createElement(
45194
45222
  Tooltip$3,
45195
45223
  {
45196
- title: column.getIsGrouped() ? texts.table.filters.hiddenGroupedColumn : texts.table.filters.hiddenColumn
45224
+ title: header.column.getIsGrouped() ? texts.table.filters.hiddenGroupedColumn : texts.table.filters.hiddenColumn
45197
45225
  },
45198
45226
  /* @__PURE__ */ React.createElement(Icon$1, { name: "eye-off", className: "text-grey-500 !h-5 !w-5" })
45199
45227
  ) : void 0,
45200
- disabled: column.id !== value && (!column.getCanFilter() || !!filters.find((f2) => f2.id === column.id))
45228
+ disabled: header.column.id !== value && (!header.column.getCanFilter() || !!filters.find((f2) => f2.id === header.column.id))
45201
45229
  },
45202
- ((_a = column.columnDef.meta) == null ? void 0 : _a.header) + (column.parent ? ` (${(_c = (_b = column.parent) == null ? void 0 : _b.columnDef.meta) == null ? void 0 : _c.header})` : "")
45230
+ /* @__PURE__ */ React.createElement(React.Fragment, null, flexRender(header.column.columnDef.header, header.getContext()), header.column.parent ? ` (${flexRender((_b = (_a = header.column.parent) == null ? void 0 : _a.columnDef.meta) == null ? void 0 : _b.header, header.getContext())})` : "")
45203
45231
  );
45204
45232
  })
45205
45233
  )
@@ -45368,9 +45396,9 @@ function Control(props) {
45368
45396
  );
45369
45397
  }
45370
45398
  function Filter(props) {
45371
- const { allColumns, filter: filter2, onChange: handleChange, onRemove, position } = props;
45399
+ const { allHeaders, filter: filter2, onChange: handleChange, onRemove, position } = props;
45372
45400
  const { texts } = useLocalization();
45373
- const column = allColumns.find((c2) => c2.id === filter2.id);
45401
+ const column = allHeaders.find((header) => header.column.id === filter2.id);
45374
45402
  const ref = React.useRef(null);
45375
45403
  const {
45376
45404
  id: id2,
@@ -45378,13 +45406,13 @@ function Filter(props) {
45378
45406
  } = filter2;
45379
45407
  const handleChangeColumn = (columnId) => {
45380
45408
  var _a, _b, _c;
45381
- const previousColumn = allColumns.find((column2) => column2.id === id2);
45382
- const nextColumn = allColumns.find((column2) => column2.id === columnId);
45383
- if (((_a = previousColumn == null ? void 0 : previousColumn.columnDef.meta) == null ? void 0 : _a.dataType) && ((_b = previousColumn == null ? void 0 : previousColumn.columnDef.meta) == null ? void 0 : _b.dataType) === ((_c = nextColumn == null ? void 0 : nextColumn.columnDef.meta) == null ? void 0 : _c.dataType)) {
45409
+ const previousColumn = allHeaders.find((header) => header.column.id === id2);
45410
+ const nextColumn = allHeaders.find((header) => header.column.id === columnId);
45411
+ if (((_a = previousColumn == null ? void 0 : previousColumn.column.columnDef.meta) == null ? void 0 : _a.dataType) && ((_b = previousColumn == null ? void 0 : previousColumn.column.columnDef.meta) == null ? void 0 : _b.dataType) === ((_c = nextColumn == null ? void 0 : nextColumn.column.columnDef.meta) == null ? void 0 : _c.dataType)) {
45384
45412
  handleChange(position, { id: columnId, value: filter2.value });
45385
45413
  return;
45386
45414
  }
45387
- const validComparators = guessComparatorsBasedOnControl(nextColumn);
45415
+ const validComparators = guessComparatorsBasedOnControl(nextColumn == null ? void 0 : nextColumn.column);
45388
45416
  const value2 = {
45389
45417
  comparator: validComparators[0],
45390
45418
  value: void 0
@@ -45407,13 +45435,13 @@ function Filter(props) {
45407
45435
  ref.current.focus();
45408
45436
  }
45409
45437
  }, [id2]);
45410
- return /* @__PURE__ */ React.createElement("div", { className: "flex items-start gap-2" }, /* @__PURE__ */ React.createElement("div", { className: "flex min-h-[theme(spacing.8)] w-14 flex-shrink-0 items-center justify-end pr-2 text-right" }, position > 0 ? texts.table.filters.conditions.and : texts.table.filters.conditions.where), /* @__PURE__ */ React.createElement(FilterColumn, { allColumns, onChange: handleChangeColumn, value: id2, ref }), /* @__PURE__ */ React.createElement(FilterComparator, { column, onChange: handleChangeComparator, value: comparator }), /* @__PURE__ */ React.createElement(FilterValue, { column, comparator, onChange: handleChangeValue, value }), onRemove ? /* @__PURE__ */ React.createElement(IconButton, { appearance: "discrete", className: "ml-auto", icon: "close", onClick: handleRemove }) : null);
45438
+ return /* @__PURE__ */ React.createElement("div", { className: "flex items-start gap-2" }, /* @__PURE__ */ React.createElement("div", { className: "flex min-h-[theme(spacing.8)] w-14 flex-shrink-0 items-center justify-end pr-2 text-right" }, position > 0 ? texts.table.filters.conditions.and : texts.table.filters.conditions.where), /* @__PURE__ */ React.createElement(FilterColumn, { allHeaders, onChange: handleChangeColumn, value: id2, ref }), /* @__PURE__ */ React.createElement(FilterComparator, { column: column == null ? void 0 : column.column, onChange: handleChangeComparator, value: comparator }), /* @__PURE__ */ React.createElement(FilterValue, { column: column == null ? void 0 : column.column, comparator, onChange: handleChangeValue, value }), onRemove ? /* @__PURE__ */ React.createElement(IconButton, { appearance: "discrete", className: "ml-auto", icon: "close", onClick: handleRemove }) : null);
45411
45439
  }
45412
45440
  const placeholderFilter = { id: "", value: { comparator: TableFilterComparator.Contains, value: void 0 } };
45413
45441
  function ManageFiltersPopover(props) {
45414
45442
  const { length, table, ...popoverProps } = props;
45415
45443
  const { locale: locale2, texts } = useLocalization();
45416
- const allColumns = table.getAllLeafColumns().filter((column) => !isInternalColumn(column.id)).sort(sortByHeader);
45444
+ const allHeaders = table.getLeafHeaders().filter((column) => !isInternalColumn(column.id)).sort((headerA, headerB) => sortByHeader(headerA.column, headerB.column));
45417
45445
  const columnFilters = table.getState().columnFilters;
45418
45446
  const tableMeta = table.options.meta;
45419
45447
  const [filters, setFilters] = React.useState(columnFilters.length ? columnFilters : [placeholderFilter]);
@@ -45452,7 +45480,7 @@ function ManageFiltersPopover(props) {
45452
45480
  if (f2.id === null || f2.id === "") {
45453
45481
  return false;
45454
45482
  }
45455
- const controlRenderer = (_b = (_a = allColumns.find((c2) => c2.id === f2.id)) == null ? void 0 : _a.columnDef.meta) == null ? void 0 : _b.control;
45483
+ const controlRenderer = (_b = (_a = allHeaders.find((header) => header.column.id === f2.id)) == null ? void 0 : _a.column.columnDef.meta) == null ? void 0 : _b.control;
45456
45484
  if (f2.value.comparator === TableFilterComparator.IsEmpty || f2.value.comparator === TableFilterComparator.IsNotEmpty || controlRenderer === "switch") {
45457
45485
  return true;
45458
45486
  }
@@ -45482,7 +45510,7 @@ function ManageFiltersPopover(props) {
45482
45510
  Filter,
45483
45511
  {
45484
45512
  key: `filter_${index2}`,
45485
- allColumns,
45513
+ allHeaders,
45486
45514
  filter: filter2,
45487
45515
  position: index2,
45488
45516
  onChange: handleChangeFilter,
@@ -53922,14 +53950,6 @@ function isTableScrolled(ref) {
53922
53950
  function useTableEditingListener(table, tableRef, scrollToIndex) {
53923
53951
  const tableMeta = table.options.meta;
53924
53952
  const localization = useLocalization();
53925
- useLazyEffect(() => {
53926
- return () => {
53927
- var _a;
53928
- if (tableMeta.editing.isEditing && tableMeta.rowActive.rowActiveIndex !== void 0) {
53929
- tableMeta.editing.saveChanges(table, (_a = table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex]) == null ? void 0 : _a.id);
53930
- }
53931
- };
53932
- }, [tableMeta.rowActive.rowActiveIndex, tableMeta.editing.isEditing]);
53933
53953
  const hasChanges = tableMeta.editing.hasChanges();
53934
53954
  React.useEffect(() => {
53935
53955
  function showUnsavedChangesWarning(event) {
@@ -55274,7 +55294,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55274
55294
  var _a, _b, _c;
55275
55295
  return (_c = (_b = (_a = state.changes.errors) == null ? void 0 : _a[cell.row.id]) == null ? void 0 : _b.cells) == null ? void 0 : _c[cell.column.id];
55276
55296
  }
55277
- async function onCellChanged(cell, rowIndex, nextValue, shouldRunUpdaters = true) {
55297
+ async function onCellChanged(cell, rowIndex, nextValue, shouldRunUpdaters = true, shouldRunValidation = true) {
55278
55298
  var _a;
55279
55299
  const tableMeta = cell.getContext().table.options.meta;
55280
55300
  const state2 = tableMeta.editing.getState();
@@ -55304,7 +55324,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55304
55324
  const nextMoveReasons = { ...state2.changes.moveReasons[cell.row.id] };
55305
55325
  const nextCellErrors = { ...(_a = state2.changes.errors[cell.row.id]) == null ? void 0 : _a.cells };
55306
55326
  let validationErrors = {};
55307
- if (validator && Object.keys(nextChanges).length && original) {
55327
+ if (validator && Object.keys(nextChanges).length && original && shouldRunValidation) {
55308
55328
  const nextRowValue = { ...original, ...changes, ...updatesForOtherCells };
55309
55329
  validationErrors = await validator(nextRowValue) ?? {};
55310
55330
  }
@@ -55786,7 +55806,7 @@ function EditingControlCell(props) {
55786
55806
  if (hasChanged) {
55787
55807
  tableMeta.editing.setCellValue(cell, rowIndex, nextValue);
55788
55808
  if (hasNonTextControl) {
55789
- requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue));
55809
+ requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue, true, false));
55790
55810
  }
55791
55811
  }
55792
55812
  },
@@ -55799,7 +55819,7 @@ function EditingControlCell(props) {
55799
55819
  }
55800
55820
  requestAnimationFrame(() => {
55801
55821
  tableMeta.editing.toggleDetailedMode(false);
55802
- tableMeta.editing.onCellChanged(cell, rowIndex, void 0, !hasNonTextControl);
55822
+ tableMeta.editing.onCellChanged(cell, rowIndex, void 0, !hasNonTextControl, true);
55803
55823
  });
55804
55824
  },
55805
55825
  [hasNonTextControl, cell.row.id, JSON.stringify(rowChanges), rowIndex, cell.column.id, cell.row.original]
@@ -56095,6 +56115,11 @@ function Row(props) {
56095
56115
  }
56096
56116
  }
56097
56117
  }, [tableMeta.editing.isEditing, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.lastFocusedCellIndex]);
56118
+ useLazyEffect(() => {
56119
+ if (tableMeta.editing.isEditing && !isActiveRow) {
56120
+ tableMeta.editing.saveChanges(table, row.id);
56121
+ }
56122
+ }, [isActiveRow]);
56098
56123
  const handleFocus = React.useCallback(
56099
56124
  (event) => {
56100
56125
  var _a;
@@ -88413,16 +88438,19 @@ function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_
88413
88438
  const _lastUsedSearch = React.useRef();
88414
88439
  async function loadPage(pageIndex, sorting, filters, hiddenColumns, search) {
88415
88440
  const hasDataChanged = JSON.stringify(sorting) !== JSON.stringify(_lastUsedSorting.current) || JSON.stringify(filters) !== JSON.stringify(_lastUsedFilters.current) || JSON.stringify(hiddenColumns) !== JSON.stringify(_lastUsedHiddenColumns.current) || search !== _lastUsedSearch.current;
88416
- const isAlreadyLoadedOrLoading = _pendingPageRequests.current[pageIndex] || data.cache[pageIndex] && data.cache[pageIndex][0];
88417
- if (!hasDataChanged && isAlreadyLoadedOrLoading) {
88418
- return;
88419
- }
88420
88441
  if (hasDataChanged) {
88421
88442
  _lastUsedSorting.current = sorting;
88422
88443
  _lastUsedFilters.current = filters;
88423
88444
  _lastUsedSearch.current = search;
88424
88445
  _lastUsedHiddenColumns.current = hiddenColumns;
88425
88446
  _pendingPageRequests.current = {};
88447
+ } else {
88448
+ if (_pendingPageRequests.current[pageIndex]) {
88449
+ return;
88450
+ }
88451
+ if (data.cache[pageIndex] && data.cache[pageIndex][0]) {
88452
+ return;
88453
+ }
88426
88454
  }
88427
88455
  const dataKey = getDataKey(sorting, filters, hiddenColumns, search);
88428
88456
  _pendingPageRequests.current[pageIndex] = dataKey;
@@ -88468,7 +88496,6 @@ function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_
88468
88496
  delete _pendingPageRequests.current[pageIndex];
88469
88497
  });
88470
88498
  } catch {
88471
- delete _pendingPageRequests.current[pageIndex];
88472
88499
  }
88473
88500
  }
88474
88501
  const loadAll = async (sorting, filters, hiddenColumns, search) => {
@@ -88578,14 +88605,12 @@ function getCurrentPage(currentPages) {
88578
88605
  return currentPages[middle];
88579
88606
  }
88580
88607
  function getDirection(pageIndex, currentPages) {
88581
- if (!currentPages.length) {
88582
- return void 0;
88583
- }
88584
- if (pageIndex === currentPages[currentPages.length - 1] + 1) {
88585
- return "forward";
88586
- }
88587
- if (pageIndex === currentPages[0] - 1 || currentPages.length === 2 && currentPages[0] !== 0 && pageIndex === currentPages[0]) {
88588
- return "backward";
88608
+ if (currentPages.length) {
88609
+ if (pageIndex === currentPages[currentPages.length - 1] + 1) {
88610
+ return "forward";
88611
+ } else if (pageIndex === currentPages[0] - 1 || currentPages.length === 2 && currentPages[0] !== 0 && pageIndex === currentPages[0]) {
88612
+ return "backward";
88613
+ }
88589
88614
  }
88590
88615
  return void 0;
88591
88616
  }