@economic/taco 2.64.1-test-1.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.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);
@@ -37818,15 +37830,6 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
37818
37830
  virtualiser.measure();
37819
37831
  }
37820
37832
  }, [expandedState]);
37821
- React__default.useEffect(() => {
37822
- const totalSize2 = virtualiser.getTotalSize();
37823
- console.log("before measuring totalSize", totalSize2);
37824
- virtualiser.measure();
37825
- setTimeout(() => {
37826
- const totalSize3 = virtualiser.getTotalSize();
37827
- console.log("after measuring totalSize", totalSize3);
37828
- }, 1e3);
37829
- }, [tableMeta.fontSize.size, tableMeta.rowHeight.height, JSON.stringify(table.getState().sorting), rows.length]);
37830
37833
  const totalSize = virtualiser.getTotalSize();
37831
37834
  const virtualItems = virtualiser.getVirtualItems();
37832
37835
  const scrollToIndex = React__default.useCallback(
@@ -38546,14 +38549,13 @@ const DisplayRow = React__default.memo(function DisplayRow2(props) {
38546
38549
  }
38547
38550
  const ref = React__default.useRef(null);
38548
38551
  const expansionRef = React__default.useRef(null);
38549
- const rowSize = useResizeObserver$1(ref, true);
38550
38552
  const expandedRowSize = useResizeObserver$1(expansionRef, !!expandedRow);
38551
38553
  React__default.useEffect(() => {
38552
38554
  var _a2, _b2;
38553
38555
  const rowHeight = ((_a2 = ref.current) == null ? void 0 : _a2.getBoundingClientRect().height) ?? 0;
38554
38556
  const expansionHeight = ((_b2 = expansionRef.current) == null ? void 0 : _b2.getBoundingClientRect().height) ?? 0;
38555
38557
  measureRow(rowHeight + expansionHeight);
38556
- }, [rowSize, expandedRowSize, measureRow]);
38558
+ }, [expansionRef.current, expandedRowSize == null ? void 0 : expandedRowSize.height]);
38557
38559
  const className = clsx("group/row", otherAttributes.className, {
38558
38560
  "hover:cursor-grab": tableMeta.rowDrag.isEnabled && typeof attributes.onClick !== "function",
38559
38561
  "hover:cursor-pointer": typeof attributes.onClick === "function"
@@ -45169,11 +45171,11 @@ function guessComparatorsBasedOnControl(column) {
45169
45171
  }
45170
45172
  const FilterContext = React__default.createContext([]);
45171
45173
  const FilterColumn = React__default.forwardRef((props, ref) => {
45172
- const { allColumns, onChange: handleChange, value = null, ...attributes } = props;
45174
+ const { allHeaders, onChange: handleChange, value = null, ...attributes } = props;
45173
45175
  const { texts } = useLocalization();
45174
45176
  const filters = React__default.useContext(FilterContext);
45175
- const selectedColumn = allColumns.find((column) => column.id === value);
45176
- const warning2 = selectedColumn && !selectedColumn.getIsVisible();
45177
+ const selectedColumn = allHeaders.find((header) => header.id === value);
45178
+ const warning2 = selectedColumn && !selectedColumn.column.getIsVisible();
45177
45179
  return /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-col" }, /* @__PURE__ */ React__default.createElement(
45178
45180
  Field,
45179
45181
  {
@@ -45191,23 +45193,23 @@ const FilterColumn = React__default.forwardRef((props, ref) => {
45191
45193
  onChange: handleChange,
45192
45194
  value
45193
45195
  },
45194
- allColumns.map((column) => {
45195
- var _a, _b, _c;
45196
+ allHeaders.map((header) => {
45197
+ var _a, _b;
45196
45198
  return /* @__PURE__ */ React__default.createElement(
45197
45199
  Select22.Option,
45198
45200
  {
45199
- key: column.id,
45200
- value: column.id,
45201
- 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(
45202
45204
  Tooltip$3,
45203
45205
  {
45204
- title: column.getIsGrouped() ? texts.table.filters.hiddenGroupedColumn : texts.table.filters.hiddenColumn
45206
+ title: header.column.getIsGrouped() ? texts.table.filters.hiddenGroupedColumn : texts.table.filters.hiddenColumn
45205
45207
  },
45206
45208
  /* @__PURE__ */ React__default.createElement(Icon$1, { name: "eye-off", className: "text-grey-500 !h-5 !w-5" })
45207
45209
  ) : void 0,
45208
- 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))
45209
45211
  },
45210
- ((_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())})` : "")
45211
45213
  );
45212
45214
  })
45213
45215
  )
@@ -45376,9 +45378,9 @@ function Control(props) {
45376
45378
  );
45377
45379
  }
45378
45380
  function Filter(props) {
45379
- const { allColumns, filter: filter2, onChange: handleChange, onRemove, position } = props;
45381
+ const { allHeaders, filter: filter2, onChange: handleChange, onRemove, position } = props;
45380
45382
  const { texts } = useLocalization();
45381
- const column = allColumns.find((c2) => c2.id === filter2.id);
45383
+ const column = allHeaders.find((header) => header.column.id === filter2.id);
45382
45384
  const ref = React__default.useRef(null);
45383
45385
  const {
45384
45386
  id: id2,
@@ -45386,13 +45388,13 @@ function Filter(props) {
45386
45388
  } = filter2;
45387
45389
  const handleChangeColumn = (columnId) => {
45388
45390
  var _a, _b, _c;
45389
- const previousColumn = allColumns.find((column2) => column2.id === id2);
45390
- const nextColumn = allColumns.find((column2) => column2.id === columnId);
45391
- 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)) {
45392
45394
  handleChange(position, { id: columnId, value: filter2.value });
45393
45395
  return;
45394
45396
  }
45395
- const validComparators = guessComparatorsBasedOnControl(nextColumn);
45397
+ const validComparators = guessComparatorsBasedOnControl(nextColumn == null ? void 0 : nextColumn.column);
45396
45398
  const value2 = {
45397
45399
  comparator: validComparators[0],
45398
45400
  value: void 0
@@ -45415,13 +45417,13 @@ function Filter(props) {
45415
45417
  ref.current.focus();
45416
45418
  }
45417
45419
  }, [id2]);
45418
- 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);
45419
45421
  }
45420
45422
  const placeholderFilter = { id: "", value: { comparator: TableFilterComparator.Contains, value: void 0 } };
45421
45423
  function ManageFiltersPopover(props) {
45422
45424
  const { length, table, ...popoverProps } = props;
45423
45425
  const { locale: locale2, texts } = useLocalization();
45424
- 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));
45425
45427
  const columnFilters = table.getState().columnFilters;
45426
45428
  const tableMeta = table.options.meta;
45427
45429
  const [filters, setFilters] = React__default.useState(columnFilters.length ? columnFilters : [placeholderFilter]);
@@ -45460,7 +45462,7 @@ function ManageFiltersPopover(props) {
45460
45462
  if (f2.id === null || f2.id === "") {
45461
45463
  return false;
45462
45464
  }
45463
- 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;
45464
45466
  if (f2.value.comparator === TableFilterComparator.IsEmpty || f2.value.comparator === TableFilterComparator.IsNotEmpty || controlRenderer === "switch") {
45465
45467
  return true;
45466
45468
  }
@@ -45490,7 +45492,7 @@ function ManageFiltersPopover(props) {
45490
45492
  Filter,
45491
45493
  {
45492
45494
  key: `filter_${index2}`,
45493
- allColumns,
45495
+ allHeaders,
45494
45496
  filter: filter2,
45495
45497
  position: index2,
45496
45498
  onChange: handleChangeFilter,
@@ -53930,14 +53932,6 @@ function isTableScrolled(ref) {
53930
53932
  function useTableEditingListener(table, tableRef, scrollToIndex) {
53931
53933
  const tableMeta = table.options.meta;
53932
53934
  const localization = useLocalization();
53933
- useLazyEffect(() => {
53934
- return () => {
53935
- var _a;
53936
- if (tableMeta.editing.isEditing && tableMeta.rowActive.rowActiveIndex !== void 0) {
53937
- tableMeta.editing.saveChanges(table, (_a = table.getRowModel().rows[tableMeta.rowActive.rowActiveIndex]) == null ? void 0 : _a.id);
53938
- }
53939
- };
53940
- }, [tableMeta.rowActive.rowActiveIndex, tableMeta.editing.isEditing]);
53941
53935
  const hasChanges = tableMeta.editing.hasChanges();
53942
53936
  React__default.useEffect(() => {
53943
53937
  function showUnsavedChangesWarning(event) {
@@ -55282,7 +55276,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55282
55276
  var _a, _b, _c;
55283
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];
55284
55278
  }
55285
- async function onCellChanged(cell, rowIndex, nextValue, shouldRunUpdaters = true) {
55279
+ async function onCellChanged(cell, rowIndex, nextValue, shouldRunUpdaters = true, shouldRunValidation = true) {
55286
55280
  var _a;
55287
55281
  const tableMeta = cell.getContext().table.options.meta;
55288
55282
  const state2 = tableMeta.editing.getState();
@@ -55312,7 +55306,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55312
55306
  const nextMoveReasons = { ...state2.changes.moveReasons[cell.row.id] };
55313
55307
  const nextCellErrors = { ...(_a = state2.changes.errors[cell.row.id]) == null ? void 0 : _a.cells };
55314
55308
  let validationErrors = {};
55315
- if (validator && Object.keys(nextChanges).length && original) {
55309
+ if (validator && Object.keys(nextChanges).length && original && shouldRunValidation) {
55316
55310
  const nextRowValue = { ...original, ...changes, ...updatesForOtherCells };
55317
55311
  validationErrors = await validator(nextRowValue) ?? {};
55318
55312
  }
@@ -55794,7 +55788,7 @@ function EditingControlCell(props) {
55794
55788
  if (hasChanged) {
55795
55789
  tableMeta.editing.setCellValue(cell, rowIndex, nextValue);
55796
55790
  if (hasNonTextControl) {
55797
- requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue));
55791
+ requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue, true, false));
55798
55792
  }
55799
55793
  }
55800
55794
  },
@@ -55807,7 +55801,7 @@ function EditingControlCell(props) {
55807
55801
  }
55808
55802
  requestAnimationFrame(() => {
55809
55803
  tableMeta.editing.toggleDetailedMode(false);
55810
- tableMeta.editing.onCellChanged(cell, rowIndex, void 0, !hasNonTextControl);
55804
+ tableMeta.editing.onCellChanged(cell, rowIndex, void 0, !hasNonTextControl, true);
55811
55805
  });
55812
55806
  },
55813
55807
  [hasNonTextControl, cell.row.id, JSON.stringify(rowChanges), rowIndex, cell.column.id, cell.row.original]
@@ -56103,6 +56097,11 @@ function Row(props) {
56103
56097
  }
56104
56098
  }
56105
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]);
56106
56105
  const handleFocus = React__default.useCallback(
56107
56106
  (event) => {
56108
56107
  var _a;