@economic/taco 2.66.1-alpha.0 → 2.67.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
@@ -3047,7 +3047,7 @@ export declare type Table3EditingCreateHandler<TType = unknown> = () => Promise<
3047
3047
 
3048
3048
  declare type Table3EditingDiscardHandler = () => void;
3049
3049
 
3050
- export declare type Table3EditingSaveHandler<TType = unknown> = (row: TType) => Promise<void>;
3050
+ export declare type Table3EditingSaveHandler<TType = unknown> = (row: TType) => Promise<void> | void;
3051
3051
 
3052
3052
  export declare type Table3EditingValidatorFn<TType = unknown> = (row: TType) => Promise<Partial<Record<keyof TType, string>> | undefined> | Partial<Record<keyof TType, string>> | undefined;
3053
3053
 
@@ -3066,6 +3066,7 @@ export declare type Table3Ref = TableRef & {
3066
3066
  createRow?: (row: unknown) => Promise<void>;
3067
3067
  save: (rowId?: string) => Promise<boolean>;
3068
3068
  removeRowChanges: (rowId: string) => Promise<void>;
3069
+ forceValidate: () => Promise<string[]>;
3069
3070
  };
3070
3071
  };
3071
3072
  };
@@ -3382,7 +3383,7 @@ export declare enum TableFilterComparator {
3382
3383
  IsNoneOf = 15
3383
3384
  }
3384
3385
 
3385
- export declare type TableFilterHandler = (filters: TableColumnFilter[], hiddenColumns: string[]) => Promise<void>;
3386
+ export declare type TableFilterHandler = (filters: TableColumnFilter[], hiddenColumns: string[]) => Promise<void> | void;
3386
3387
 
3387
3388
  export declare type TableFilterValue = {
3388
3389
  comparator: TableFilterComparator;
@@ -3455,7 +3456,7 @@ export declare type TableScrollToIndexHandler = (index: number, options?: {
3455
3456
  align: 'start' | 'center' | 'end' | 'auto';
3456
3457
  }) => void;
3457
3458
 
3458
- export declare type TableSearchHandler = (search: string | undefined, hiddenColumns: string[]) => Promise<void>;
3459
+ export declare type TableSearchHandler = (search: string | undefined, hiddenColumns: string[]) => Promise<void> | void;
3459
3460
 
3460
3461
  export declare type TableServerLoadAllHandler = (sorting: TableColumnSort[], filters: TableColumnFilter[], hiddenColumns: string[], search: string | undefined) => Promise<void>;
3461
3462
 
@@ -3495,7 +3496,7 @@ export declare type TableShortcutHandlerObject<TType = unknown> = {
3495
3496
 
3496
3497
  export declare type TableShortcuts<TType = unknown> = Record<string, TableShortcutHandlerFn<TType> | TableShortcutHandlerObject<TType>>;
3497
3498
 
3498
- export declare type TableSortHandler = (sorting: TableColumnSort[]) => Promise<void>;
3499
+ export declare type TableSortHandler = (sorting: TableColumnSort[]) => Promise<void> | void;
3499
3500
 
3500
3501
  export declare type TableTexts = {
3501
3502
  columns: {
package/dist/taco.js CHANGED
@@ -35633,7 +35633,7 @@ function useReactTableInitialState(props, columns, persistedSettings, defaults2)
35633
35633
  columnOrder
35634
35634
  );
35635
35635
  } else {
35636
- if (props.defaultColumnFreezingIndex) {
35636
+ if (props.defaultColumnFreezingIndex !== void 0) {
35637
35637
  columnPinning.left = freezeUptoExternalColumn(props.defaultColumnFreezingIndex, columnOrder);
35638
35638
  } else {
35639
35639
  columnPinning.left = unfreezeAllExternalColumns(columnOrder);
@@ -37834,12 +37834,12 @@ function getScrollPaddingEndOffset(table) {
37834
37834
  }
37835
37835
  return height;
37836
37836
  }
37837
- function getPaddingEndOffset(table, options) {
37837
+ function getPaddingEndOffset(table) {
37838
37838
  const bottomRows = table.getBottomRows() ?? [];
37839
- return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length + ((options == null ? void 0 : options.virtualiserPaddingEndOffset) ?? 0);
37839
+ return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length;
37840
37840
  }
37841
37841
  const OVERSCAN_ROW_COUNT = 8;
37842
- function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIndex, options) {
37842
+ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIndex) {
37843
37843
  var _a, _b, _c, _d, _e;
37844
37844
  const tableMeta = table.options.meta;
37845
37845
  const isTableRowGrouped = !!((_a = table.getState().grouping) == null ? void 0 : _a.length);
@@ -37858,7 +37858,7 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
37858
37858
  // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list
37859
37859
  scrollPaddingStart,
37860
37860
  scrollPaddingEnd: getScrollPaddingEndOffset(table),
37861
- paddingEnd: getPaddingEndOffset(table, options)
37861
+ paddingEnd: getPaddingEndOffset(table)
37862
37862
  });
37863
37863
  const expandedState = table.getState().expanded;
37864
37864
  const previousExpandedStateRef = React__default.useRef(false);
@@ -37872,15 +37872,15 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
37872
37872
  const totalSize = virtualiser.getTotalSize();
37873
37873
  const virtualItems = virtualiser.getVirtualItems();
37874
37874
  const scrollToIndex = React__default.useCallback(
37875
- (index2, options2 = { align: "auto", behavior: "smooth" }) => {
37876
- const notSmooth = { ...options2, behavior: "auto" };
37875
+ (index2, options = { align: "auto", behavior: "smooth" }) => {
37876
+ const notSmooth = { ...options, behavior: "auto" };
37877
37877
  if (tableRef.current) {
37878
37878
  if (index2 === 0) {
37879
37879
  virtualiser.scrollToOffset(0, notSmooth);
37880
37880
  } else if (index2 === count2 - 1) {
37881
37881
  tableRef.current.scrollTop = tableRef.current.scrollHeight;
37882
37882
  } else {
37883
- virtualiser.scrollToIndex(index2, options2);
37883
+ virtualiser.scrollToIndex(index2, options);
37884
37884
  }
37885
37885
  }
37886
37886
  },
@@ -38318,17 +38318,10 @@ const INTERNAL_RENDERERS = {
38318
38318
  rowExpansion: renderer$1,
38319
38319
  rowSelection: renderer
38320
38320
  };
38321
- function useTable$1(props, externalRef, renderers, meta, options) {
38321
+ function useTable$1(props, externalRef, renderers, meta) {
38322
38322
  const ref = useMergedRef(externalRef);
38323
38323
  const manager = useTableManager(props, ref, meta, INTERNAL_RENDERERS);
38324
- const renderer2 = useTableRenderer(
38325
- renderers,
38326
- manager.instance,
38327
- ref,
38328
- manager.meta.length,
38329
- props.defaultRowActiveIndex,
38330
- options
38331
- );
38324
+ const renderer2 = useTableRenderer(renderers, manager.instance, ref, manager.meta.length, props.defaultRowActiveIndex);
38332
38325
  const { style, stylesheet } = useTableStyle(manager.id, manager.instance);
38333
38326
  useTableGlobalShortcuts(manager.instance, ref, renderer2.scrollToIndex, props.enableLocalKeyboardShortcuts);
38334
38327
  useTableRef(manager.instance, ref);
@@ -39464,7 +39457,7 @@ const SearchInput22 = React__default.forwardRef(function SearchInput222(props, r
39464
39457
  );
39465
39458
  }
39466
39459
  if (hasFind && isActive) {
39467
- postfix = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("span", { className: "text-grey-700 flex h-4 items-center" }, loading ? /* @__PURE__ */ React__default.createElement(Spinner, { className: "h-4 w-4" }) : showTotal ? /* @__PURE__ */ React__default.createElement("span", { className: "border-r border-black/[0.25] pr-2" }, `${findCurrent ?? 0}/${findTotal ?? 0}`) : null), findCurrent ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
39460
+ postfix = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement("span", { className: "text-grey-700 flex h-4 items-center" }, loading ? /* @__PURE__ */ React__default.createElement(Spinner, { className: "h-4 w-4" }) : showTotal ? /* @__PURE__ */ React__default.createElement("span", { className: "border-r border-black/[0.25] pr-2", "data-taco": "search-matches-counter" }, `${findCurrent ?? 0}/${findTotal ?? 0}`) : null), findCurrent ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
39468
39461
  IconButton,
39469
39462
  {
39470
39463
  "aria-label": texts.searchInput.findPrevious,
@@ -54032,11 +54025,17 @@ function useTableEditingListener(table, tableRef, scrollToIndex) {
54032
54025
  }, [hasSavedChanges]);
54033
54026
  React__default.useEffect(() => {
54034
54027
  const onClickOutside = (event) => {
54028
+ var _a;
54035
54029
  if (tableMeta.editing.isEditing) {
54036
54030
  const element = event.target;
54037
- const isInsideDialog = !!element.closest('[role="dialog"]');
54038
- const isTableOrIsInsideTable = element.tagName === "TABLE" || element.tagName === "TBODY" || element.getAttribute("data-taco") === "backdrop" || element.getAttribute("data-table") === "editing-toggle" || !document.body.contains(element) || isElementInsideOrTriggeredFromContainer(element, tableRef.current);
54039
- if (!isTableOrIsInsideTable && !isInsideDialog) {
54031
+ const isClickOnTableOrInsideTable = element.tagName === "TABLE" || element.tagName === "TBODY" || element.getAttribute("data-taco") === "backdrop" || element.getAttribute("data-table") === "editing-toggle" || !document.body.contains(element) || isElementInsideOrTriggeredFromContainer(element, tableRef.current);
54032
+ if (isClickOnTableOrInsideTable) {
54033
+ return;
54034
+ }
54035
+ const dialog = element.closest('[role="dialog"]');
54036
+ const isClickInsideParentDialog = dialog !== null && ((_a = tableRef.current) == null ? void 0 : _a.closest('[role="dialog"]')) === dialog;
54037
+ const isClickOutside = dialog === null;
54038
+ if (isClickInsideParentDialog || isClickOutside) {
54040
54039
  tableMeta.editing.saveChanges(table);
54041
54040
  }
54042
54041
  }
@@ -55261,6 +55260,13 @@ function reducer(state, action) {
55261
55260
  indexes: setWith(state.indexes, rowId, index2, Object)
55262
55261
  };
55263
55262
  }
55263
+ case "forceValidate": {
55264
+ const { newState } = payload;
55265
+ return {
55266
+ ...state,
55267
+ ...newState
55268
+ };
55269
+ }
55264
55270
  default:
55265
55271
  return state;
55266
55272
  }
@@ -55420,6 +55426,46 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55420
55426
  }
55421
55427
  });
55422
55428
  }
55429
+ async function forceValidate(table) {
55430
+ if (validator && table.getRowModel().rows.length) {
55431
+ const newState = { ...state };
55432
+ const returnIds = [];
55433
+ await Promise.all(
55434
+ table.getRowModel().rows.map(async (row, index2) => {
55435
+ var _a, _b;
55436
+ const rowWithChanges = { ...row.original, ...state.changes.rows[row.id] };
55437
+ if (rowWithChanges) {
55438
+ const cellErrors = await validator(rowWithChanges);
55439
+ if (cellErrors) {
55440
+ newState.changes.dirty[row.id] = true;
55441
+ newState.changes.originals[row.id] = row.original;
55442
+ newState.changes.moveReasons[row.id] = { ...newState.changes.moveReasons[row.id] };
55443
+ newState.changes.rows[row.id] = { ...newState.changes.rows[row.id] };
55444
+ newState.changes.status[row.id] = "errored";
55445
+ newState.indexes[row.id] = index2;
55446
+ newState.changes.errors[row.id] = {
55447
+ cells: cellErrors,
55448
+ row: ((_a = newState.changes.errors[row.id]) == null ? void 0 : _a.row) ?? void 0,
55449
+ shouldShowErrorAlert: ((_b = newState.changes.errors[row.id]) == null ? void 0 : _b.shouldShowErrorAlert) ?? false
55450
+ };
55451
+ Object.keys(cellErrors).forEach((columnId) => {
55452
+ newState.changes.rows[row.id][columnId] = rowWithChanges[columnId];
55453
+ });
55454
+ returnIds.push(row.id);
55455
+ }
55456
+ }
55457
+ })
55458
+ );
55459
+ dispatch({
55460
+ type: "forceValidate",
55461
+ payload: {
55462
+ newState
55463
+ }
55464
+ });
55465
+ return returnIds;
55466
+ }
55467
+ return [];
55468
+ }
55423
55469
  function getErrors() {
55424
55470
  return Object.keys(state.changes.errors);
55425
55471
  }
@@ -55548,6 +55594,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55548
55594
  hasTemporaryRowErrors,
55549
55595
  getRowStatus,
55550
55596
  setRowStatus,
55597
+ forceValidate,
55551
55598
  // cells
55552
55599
  setCellValue,
55553
55600
  getCellValue,
@@ -56301,14 +56348,7 @@ function useTable3(props, ref) {
56301
56348
  ]) : props.rowActions
56302
56349
  };
56303
56350
  const meta = { editing };
56304
- const options = {
56305
- virtualiserPaddingEndOffset: 0
56306
- };
56307
- if (props.enableEditing) {
56308
- const validationErrorLabelHeight = 17;
56309
- options.virtualiserPaddingEndOffset = editing.getErrors().length * validationErrorLabelHeight;
56310
- }
56311
- const table = useTable$1(extendedProps, ref, RENDERERS, meta, options);
56351
+ const table = useTable$1(extendedProps, ref, RENDERERS, meta);
56312
56352
  const toggleEditing = (enabled) => table.meta.editing.toggleEditing(enabled ?? ((editing2) => !editing2), table.instance, table.renderer.scrollToIndex);
56313
56353
  React__default.useEffect(() => {
56314
56354
  if (props.defaultToggleEditing) {
@@ -56331,6 +56371,14 @@ function useTable3(props, ref) {
56331
56371
  }
56332
56372
  }
56333
56373
  }, [table.ref.current, table.meta.editing.isEnabled]);
56374
+ React__default.useEffect(() => {
56375
+ if (table.ref.current) {
56376
+ const instance = table.ref.current.instance;
56377
+ if (table.meta.editing.isEnabled) {
56378
+ instance.editing.forceValidate = async () => table.meta.editing.forceValidate(table.instance);
56379
+ }
56380
+ }
56381
+ }, [table.meta.editing.forceValidate]);
56334
56382
  return table;
56335
56383
  }
56336
56384
  function Alert(props) {