@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.css CHANGED
@@ -1623,6 +1623,10 @@ table[data-taco^='table'] tbody tr[data-row-create] td {
1623
1623
  table[data-taco^='table'] tbody tr[data-row-create] td button {
1624
1624
  @apply -mt-[3px];
1625
1625
  }
1626
+
1627
+ table[data-taco='table3'] td [data-taco='combobox'] {
1628
+ display: inline;
1629
+ }
1626
1630
  [data-taco='card-content'] > [data-taco='chart-wrapper']:not(:has([data-taco='chart-donut'], [data-taco='chart-pie'])) {
1627
1631
  @apply w-full;
1628
1632
  }
package/dist/taco.d.ts CHANGED
@@ -3064,7 +3064,7 @@ export declare type Table3Ref = TableRef & {
3064
3064
  editing?: {
3065
3065
  toggleEditing: (enabled: boolean | undefined) => void;
3066
3066
  createRow?: (row: unknown) => Promise<void>;
3067
- save: (rowId: string) => Promise<boolean>;
3067
+ save: (rowId?: string) => Promise<boolean>;
3068
3068
  removeRowChanges: (rowId: string) => Promise<void>;
3069
3069
  };
3070
3070
  };
@@ -3295,6 +3295,7 @@ export declare type TableCommonProps<TType = unknown> = TableFeatureProps<TType>
3295
3295
  toolbarRight?: JSX.Element;
3296
3296
  toolbarPanel?: JSX.Element;
3297
3297
  onEvent?: TableEventHandler;
3298
+ onRowActive?: TableRowActiveHandler<TType>;
3298
3299
  onRowClick?: TableRowClickHandler<TType>;
3299
3300
  onRowDrag?: TableRowDragHandler<TType>;
3300
3301
  onRowDrop?: TableRowDropHandler<TType>;
@@ -3418,6 +3419,8 @@ export declare type TableRowActionRenderer<TType = unknown> = (row: TType, helpe
3418
3419
  };
3419
3420
  }) => JSX.Element | null;
3420
3421
 
3422
+ export declare type TableRowActiveHandler<TType = unknown> = (row: TType | undefined) => void;
3423
+
3421
3424
  export declare type TableRowClickHandler<TType = unknown> = (row: TType) => void;
3422
3425
 
3423
3426
  export declare type TableRowDragHandler<TType = unknown> = (rows: TType[], showPlaceholder: (text: string) => void, setDataTransfer: (data: string) => void) => void;
package/dist/taco.js CHANGED
@@ -36605,6 +36605,17 @@ function useTableRowDrop(isEnabled = false, onRowDrop) {
36605
36605
  handleDrop: isEnabled ? onRowDrop : void 0
36606
36606
  };
36607
36607
  }
36608
+ function useTableRowActiveListener$1(table, onRowActive) {
36609
+ var _a;
36610
+ const meta = table.options.meta;
36611
+ const rows = table.getRowModel().flatRows;
36612
+ const currentRow = meta.rowActive.rowActiveIndex !== void 0 ? (_a = rows[meta.rowActive.rowActiveIndex]) == null ? void 0 : _a.original : void 0;
36613
+ React__default.useEffect(() => {
36614
+ if (meta.rowActive.isEnabled && onRowActive) {
36615
+ onRowActive(currentRow);
36616
+ }
36617
+ }, [meta.rowActive.isEnabled, currentRow, onRowActive]);
36618
+ }
36608
36619
  const DEFAULT_EMPTY_ARRAY = [];
36609
36620
  function useTableManager(props, ref, meta, internalColumns) {
36610
36621
  var _a;
@@ -36705,6 +36716,7 @@ function useTableManager(props, ref, meta, internalColumns) {
36705
36716
  useTableDataListener(instance, length);
36706
36717
  useTableFilterListener(instance, props.onChangeFilter);
36707
36718
  useTableFontSizeListener(instance);
36719
+ useTableRowActiveListener$1(instance, props.onRowActive);
36708
36720
  useTableRowHeightListener(instance);
36709
36721
  useTableRowSelectionListener(instance, props.onRowSelect);
36710
36722
  useTableSearchListener(instance);
@@ -38428,6 +38440,21 @@ function Cell$2(props) {
38428
38440
  }
38429
38441
  return /* @__PURE__ */ React__default.createElement(CellRenderer, { ...cellProps });
38430
38442
  }
38443
+ const useResizeObserver$1 = (ref, enabled = true) => {
38444
+ const [size2, setSize] = React__default.useState();
38445
+ React__default.useEffect(() => {
38446
+ if (!ref.current || !enabled) {
38447
+ return () => void 0;
38448
+ }
38449
+ const observer = new ResizeObserver((entries) => {
38450
+ const entry = entries[0];
38451
+ setSize({ height: entry.contentRect.height, width: entry.contentRect.width });
38452
+ });
38453
+ observer.observe(ref.current);
38454
+ return () => observer.disconnect();
38455
+ }, [enabled]);
38456
+ return size2;
38457
+ };
38431
38458
  const DisplayRow = React__default.memo(function DisplayRow2(props) {
38432
38459
  var _a, _b, _c;
38433
38460
  const { children, cellRenderer: CellRenderer, index: index2, measureRow, row, table, ...otherAttributes } = props;
@@ -38522,12 +38549,13 @@ const DisplayRow = React__default.memo(function DisplayRow2(props) {
38522
38549
  }
38523
38550
  const ref = React__default.useRef(null);
38524
38551
  const expansionRef = React__default.useRef(null);
38552
+ const expandedRowSize = useResizeObserver$1(expansionRef, !!expandedRow);
38525
38553
  React__default.useEffect(() => {
38526
38554
  var _a2, _b2;
38527
38555
  const rowHeight = ((_a2 = ref.current) == null ? void 0 : _a2.getBoundingClientRect().height) ?? 0;
38528
38556
  const expansionHeight = ((_b2 = expansionRef.current) == null ? void 0 : _b2.getBoundingClientRect().height) ?? 0;
38529
38557
  measureRow(rowHeight + expansionHeight);
38530
- }, [expansionRef.current]);
38558
+ }, [expansionRef.current, expandedRowSize == null ? void 0 : expandedRowSize.height]);
38531
38559
  const className = clsx("group/row", otherAttributes.className, {
38532
38560
  "hover:cursor-grab": tableMeta.rowDrag.isEnabled && typeof attributes.onClick !== "function",
38533
38561
  "hover:cursor-pointer": typeof attributes.onClick === "function"
@@ -45143,11 +45171,11 @@ function guessComparatorsBasedOnControl(column) {
45143
45171
  }
45144
45172
  const FilterContext = React__default.createContext([]);
45145
45173
  const FilterColumn = React__default.forwardRef((props, ref) => {
45146
- const { allColumns, onChange: handleChange, value = null, ...attributes } = props;
45174
+ const { allHeaders, onChange: handleChange, value = null, ...attributes } = props;
45147
45175
  const { texts } = useLocalization();
45148
45176
  const filters = React__default.useContext(FilterContext);
45149
- const selectedColumn = allColumns.find((column) => column.id === value);
45150
- const warning2 = selectedColumn && !selectedColumn.getIsVisible();
45177
+ const selectedColumn = allHeaders.find((header) => header.id === value);
45178
+ const warning2 = selectedColumn && !selectedColumn.column.getIsVisible();
45151
45179
  return /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-col" }, /* @__PURE__ */ React__default.createElement(
45152
45180
  Field,
45153
45181
  {
@@ -45165,23 +45193,23 @@ const FilterColumn = React__default.forwardRef((props, ref) => {
45165
45193
  onChange: handleChange,
45166
45194
  value
45167
45195
  },
45168
- allColumns.map((column) => {
45169
- var _a, _b, _c;
45196
+ allHeaders.map((header) => {
45197
+ var _a, _b;
45170
45198
  return /* @__PURE__ */ React__default.createElement(
45171
45199
  Select22.Option,
45172
45200
  {
45173
- key: column.id,
45174
- value: column.id,
45175
- postfix: !column.getIsVisible() || column.getIsGrouped() ? /* @__PURE__ */ React__default.createElement(
45201
+ key: header.column.id,
45202
+ value: header.column.id,
45203
+ postfix: !header.column.getIsVisible() || header.column.getIsGrouped() ? /* @__PURE__ */ React__default.createElement(
45176
45204
  Tooltip$3,
45177
45205
  {
45178
- title: column.getIsGrouped() ? texts.table.filters.hiddenGroupedColumn : texts.table.filters.hiddenColumn
45206
+ title: header.column.getIsGrouped() ? texts.table.filters.hiddenGroupedColumn : texts.table.filters.hiddenColumn
45179
45207
  },
45180
45208
  /* @__PURE__ */ React__default.createElement(Icon$1, { name: "eye-off", className: "text-grey-500 !h-5 !w-5" })
45181
45209
  ) : void 0,
45182
- disabled: column.id !== value && (!column.getCanFilter() || !!filters.find((f2) => f2.id === column.id))
45210
+ disabled: header.column.id !== value && (!header.column.getCanFilter() || !!filters.find((f2) => f2.id === header.column.id))
45183
45211
  },
45184
- ((_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})` : "")
45212
+ /* @__PURE__ */ React__default.createElement(React__default.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())})` : "")
45185
45213
  );
45186
45214
  })
45187
45215
  )
@@ -45350,9 +45378,9 @@ function Control(props) {
45350
45378
  );
45351
45379
  }
45352
45380
  function Filter(props) {
45353
- const { allColumns, filter: filter2, onChange: handleChange, onRemove, position } = props;
45381
+ const { allHeaders, filter: filter2, onChange: handleChange, onRemove, position } = props;
45354
45382
  const { texts } = useLocalization();
45355
- const column = allColumns.find((c2) => c2.id === filter2.id);
45383
+ const column = allHeaders.find((header) => header.column.id === filter2.id);
45356
45384
  const ref = React__default.useRef(null);
45357
45385
  const {
45358
45386
  id: id2,
@@ -45360,13 +45388,13 @@ function Filter(props) {
45360
45388
  } = filter2;
45361
45389
  const handleChangeColumn = (columnId) => {
45362
45390
  var _a, _b, _c;
45363
- const previousColumn = allColumns.find((column2) => column2.id === id2);
45364
- const nextColumn = allColumns.find((column2) => column2.id === columnId);
45365
- 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)) {
45391
+ const previousColumn = allHeaders.find((header) => header.column.id === id2);
45392
+ const nextColumn = allHeaders.find((header) => header.column.id === columnId);
45393
+ 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)) {
45366
45394
  handleChange(position, { id: columnId, value: filter2.value });
45367
45395
  return;
45368
45396
  }
45369
- const validComparators = guessComparatorsBasedOnControl(nextColumn);
45397
+ const validComparators = guessComparatorsBasedOnControl(nextColumn == null ? void 0 : nextColumn.column);
45370
45398
  const value2 = {
45371
45399
  comparator: validComparators[0],
45372
45400
  value: void 0
@@ -45389,13 +45417,13 @@ function Filter(props) {
45389
45417
  ref.current.focus();
45390
45418
  }
45391
45419
  }, [id2]);
45392
- return /* @__PURE__ */ React__default.createElement("div", { className: "flex items-start gap-2" }, /* @__PURE__ */ React__default.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__default.createElement(FilterColumn, { allColumns, onChange: handleChangeColumn, value: id2, ref }), /* @__PURE__ */ React__default.createElement(FilterComparator, { column, onChange: handleChangeComparator, value: comparator }), /* @__PURE__ */ React__default.createElement(FilterValue, { column, comparator, onChange: handleChangeValue, value }), onRemove ? /* @__PURE__ */ React__default.createElement(IconButton, { appearance: "discrete", className: "ml-auto", icon: "close", onClick: handleRemove }) : null);
45420
+ return /* @__PURE__ */ React__default.createElement("div", { className: "flex items-start gap-2" }, /* @__PURE__ */ React__default.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__default.createElement(FilterColumn, { allHeaders, onChange: handleChangeColumn, value: id2, ref }), /* @__PURE__ */ React__default.createElement(FilterComparator, { column: column == null ? void 0 : column.column, onChange: handleChangeComparator, value: comparator }), /* @__PURE__ */ React__default.createElement(FilterValue, { column: column == null ? void 0 : column.column, comparator, onChange: handleChangeValue, value }), onRemove ? /* @__PURE__ */ React__default.createElement(IconButton, { appearance: "discrete", className: "ml-auto", icon: "close", onClick: handleRemove }) : null);
45393
45421
  }
45394
45422
  const placeholderFilter = { id: "", value: { comparator: TableFilterComparator.Contains, value: void 0 } };
45395
45423
  function ManageFiltersPopover(props) {
45396
45424
  const { length, table, ...popoverProps } = props;
45397
45425
  const { locale: locale2, texts } = useLocalization();
45398
- const allColumns = table.getAllLeafColumns().filter((column) => !isInternalColumn(column.id)).sort(sortByHeader);
45426
+ const allHeaders = table.getLeafHeaders().filter((column) => !isInternalColumn(column.id)).sort((headerA, headerB) => sortByHeader(headerA.column, headerB.column));
45399
45427
  const columnFilters = table.getState().columnFilters;
45400
45428
  const tableMeta = table.options.meta;
45401
45429
  const [filters, setFilters] = React__default.useState(columnFilters.length ? columnFilters : [placeholderFilter]);
@@ -45434,7 +45462,7 @@ function ManageFiltersPopover(props) {
45434
45462
  if (f2.id === null || f2.id === "") {
45435
45463
  return false;
45436
45464
  }
45437
- const controlRenderer = (_b = (_a = allColumns.find((c2) => c2.id === f2.id)) == null ? void 0 : _a.columnDef.meta) == null ? void 0 : _b.control;
45465
+ const controlRenderer = (_b = (_a = allHeaders.find((header) => header.column.id === f2.id)) == null ? void 0 : _a.column.columnDef.meta) == null ? void 0 : _b.control;
45438
45466
  if (f2.value.comparator === TableFilterComparator.IsEmpty || f2.value.comparator === TableFilterComparator.IsNotEmpty || controlRenderer === "switch") {
45439
45467
  return true;
45440
45468
  }
@@ -45464,7 +45492,7 @@ function ManageFiltersPopover(props) {
45464
45492
  Filter,
45465
45493
  {
45466
45494
  key: `filter_${index2}`,
45467
- allColumns,
45495
+ allHeaders,
45468
45496
  filter: filter2,
45469
45497
  position: index2,
45470
45498
  onChange: handleChangeFilter,
@@ -53904,14 +53932,6 @@ function isTableScrolled(ref) {
53904
53932
  function useTableEditingListener(table, tableRef, scrollToIndex) {
53905
53933
  const tableMeta = table.options.meta;
53906
53934
  const localization = useLocalization();
53907
- useLazyEffect(() => {
53908
- return () => {
53909
- var _a;
53910
- if (tableMeta.editing.isEditing && tableMeta.rowActive.rowActiveIndex !== void 0) {
53911
- tableMeta.editing.saveChanges(table, (_a = table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex]) == null ? void 0 : _a.id);
53912
- }
53913
- };
53914
- }, [tableMeta.rowActive.rowActiveIndex, tableMeta.editing.isEditing]);
53915
53935
  const hasChanges = tableMeta.editing.hasChanges();
53916
53936
  React__default.useEffect(() => {
53917
53937
  function showUnsavedChangesWarning(event) {
@@ -55256,7 +55276,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55256
55276
  var _a, _b, _c;
55257
55277
  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];
55258
55278
  }
55259
- async function onCellChanged(cell, rowIndex, nextValue, shouldRunUpdaters = true) {
55279
+ async function onCellChanged(cell, rowIndex, nextValue, shouldRunUpdaters = true, shouldRunValidation = true) {
55260
55280
  var _a;
55261
55281
  const tableMeta = cell.getContext().table.options.meta;
55262
55282
  const state2 = tableMeta.editing.getState();
@@ -55286,7 +55306,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55286
55306
  const nextMoveReasons = { ...state2.changes.moveReasons[cell.row.id] };
55287
55307
  const nextCellErrors = { ...(_a = state2.changes.errors[cell.row.id]) == null ? void 0 : _a.cells };
55288
55308
  let validationErrors = {};
55289
- if (validator && Object.keys(nextChanges).length && original) {
55309
+ if (validator && Object.keys(nextChanges).length && original && shouldRunValidation) {
55290
55310
  const nextRowValue = { ...original, ...changes, ...updatesForOtherCells };
55291
55311
  validationErrors = await validator(nextRowValue) ?? {};
55292
55312
  }
@@ -55768,7 +55788,7 @@ function EditingControlCell(props) {
55768
55788
  if (hasChanged) {
55769
55789
  tableMeta.editing.setCellValue(cell, rowIndex, nextValue);
55770
55790
  if (hasNonTextControl) {
55771
- requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue));
55791
+ requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue, true, false));
55772
55792
  }
55773
55793
  }
55774
55794
  },
@@ -55781,7 +55801,7 @@ function EditingControlCell(props) {
55781
55801
  }
55782
55802
  requestAnimationFrame(() => {
55783
55803
  tableMeta.editing.toggleDetailedMode(false);
55784
- tableMeta.editing.onCellChanged(cell, rowIndex, void 0, !hasNonTextControl);
55804
+ tableMeta.editing.onCellChanged(cell, rowIndex, void 0, !hasNonTextControl, true);
55785
55805
  });
55786
55806
  },
55787
55807
  [hasNonTextControl, cell.row.id, JSON.stringify(rowChanges), rowIndex, cell.column.id, cell.row.original]
@@ -56077,6 +56097,11 @@ function Row(props) {
56077
56097
  }
56078
56098
  }
56079
56099
  }, [tableMeta.editing.isEditing, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.lastFocusedCellIndex]);
56100
+ useLazyEffect(() => {
56101
+ if (tableMeta.editing.isEditing && !isActiveRow) {
56102
+ tableMeta.editing.saveChanges(table, row.id);
56103
+ }
56104
+ }, [isActiveRow]);
56080
56105
  const handleFocus = React__default.useCallback(
56081
56106
  (event) => {
56082
56107
  var _a;
@@ -88395,16 +88420,19 @@ function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_
88395
88420
  const _lastUsedSearch = React__default.useRef();
88396
88421
  async function loadPage(pageIndex, sorting, filters, hiddenColumns, search) {
88397
88422
  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;
88398
- const isAlreadyLoadedOrLoading = _pendingPageRequests.current[pageIndex] || data.cache[pageIndex] && data.cache[pageIndex][0];
88399
- if (!hasDataChanged && isAlreadyLoadedOrLoading) {
88400
- return;
88401
- }
88402
88423
  if (hasDataChanged) {
88403
88424
  _lastUsedSorting.current = sorting;
88404
88425
  _lastUsedFilters.current = filters;
88405
88426
  _lastUsedSearch.current = search;
88406
88427
  _lastUsedHiddenColumns.current = hiddenColumns;
88407
88428
  _pendingPageRequests.current = {};
88429
+ } else {
88430
+ if (_pendingPageRequests.current[pageIndex]) {
88431
+ return;
88432
+ }
88433
+ if (data.cache[pageIndex] && data.cache[pageIndex][0]) {
88434
+ return;
88435
+ }
88408
88436
  }
88409
88437
  const dataKey = getDataKey(sorting, filters, hiddenColumns, search);
88410
88438
  _pendingPageRequests.current[pageIndex] = dataKey;
@@ -88450,7 +88478,6 @@ function useTableDataLoader2(fetchPage, fetchAll, options = { pageSize: DEFAULT_
88450
88478
  delete _pendingPageRequests.current[pageIndex];
88451
88479
  });
88452
88480
  } catch {
88453
- delete _pendingPageRequests.current[pageIndex];
88454
88481
  }
88455
88482
  }
88456
88483
  const loadAll = async (sorting, filters, hiddenColumns, search) => {
@@ -88560,14 +88587,12 @@ function getCurrentPage(currentPages) {
88560
88587
  return currentPages[middle];
88561
88588
  }
88562
88589
  function getDirection(pageIndex, currentPages) {
88563
- if (!currentPages.length) {
88564
- return void 0;
88565
- }
88566
- if (pageIndex === currentPages[currentPages.length - 1] + 1) {
88567
- return "forward";
88568
- }
88569
- if (pageIndex === currentPages[0] - 1 || currentPages.length === 2 && currentPages[0] !== 0 && pageIndex === currentPages[0]) {
88570
- return "backward";
88590
+ if (currentPages.length) {
88591
+ if (pageIndex === currentPages[currentPages.length - 1] + 1) {
88592
+ return "forward";
88593
+ } else if (pageIndex === currentPages[0] - 1 || currentPages.length === 2 && currentPages[0] !== 0 && pageIndex === currentPages[0]) {
88594
+ return "backward";
88595
+ }
88571
88596
  }
88572
88597
  return void 0;
88573
88598
  }