@economic/taco 2.66.1-test.0 → 2.67.1-create-handler-active-row.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
@@ -26978,7 +26978,7 @@ const Content$4 = React__namespace.forwardRef(function HangerContent(props, ref)
26978
26978
  const context = React__namespace.useContext(HangerContext);
26979
26979
  const { texts } = useLocalization();
26980
26980
  const className = clsx(
26981
- "wcag-blue-500 border border-transparent rounded p-3 pr-12 yt-shadow focus:border-transparent max-w-sm",
26981
+ "wcag-blue-500 border border-transparent rounded p-3 pr-12 yt-shadow focus:border-transparent max-w-sm print:hidden",
26982
26982
  props.className
26983
26983
  );
26984
26984
  const handleInteractOutside = (event) => {
@@ -35651,7 +35651,7 @@ function useReactTableInitialState(props, columns, persistedSettings, defaults2)
35651
35651
  columnOrder
35652
35652
  );
35653
35653
  } else {
35654
- if (props.defaultColumnFreezingIndex) {
35654
+ if (props.defaultColumnFreezingIndex !== void 0) {
35655
35655
  columnPinning.left = freezeUptoExternalColumn(props.defaultColumnFreezingIndex, columnOrder);
35656
35656
  } else {
35657
35657
  columnPinning.left = unfreezeAllExternalColumns(columnOrder);
@@ -37852,12 +37852,12 @@ function getScrollPaddingEndOffset(table) {
37852
37852
  }
37853
37853
  return height;
37854
37854
  }
37855
- function getPaddingEndOffset(table, options) {
37855
+ function getPaddingEndOffset(table) {
37856
37856
  const bottomRows = table.getBottomRows() ?? [];
37857
- return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length + ((options == null ? void 0 : options.virtualiserPaddingEndOffset) ?? 0);
37857
+ return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length;
37858
37858
  }
37859
37859
  const OVERSCAN_ROW_COUNT = 8;
37860
- function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIndex, options) {
37860
+ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIndex) {
37861
37861
  var _a, _b, _c, _d, _e;
37862
37862
  const tableMeta = table.options.meta;
37863
37863
  const isTableRowGrouped = !!((_a = table.getState().grouping) == null ? void 0 : _a.length);
@@ -37876,7 +37876,7 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
37876
37876
  // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list
37877
37877
  scrollPaddingStart,
37878
37878
  scrollPaddingEnd: getScrollPaddingEndOffset(table),
37879
- paddingEnd: getPaddingEndOffset(table, options)
37879
+ paddingEnd: getPaddingEndOffset(table)
37880
37880
  });
37881
37881
  const expandedState = table.getState().expanded;
37882
37882
  const previousExpandedStateRef = React.useRef(false);
@@ -37890,15 +37890,15 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
37890
37890
  const totalSize = virtualiser.getTotalSize();
37891
37891
  const virtualItems = virtualiser.getVirtualItems();
37892
37892
  const scrollToIndex = React.useCallback(
37893
- (index2, options2 = { align: "auto", behavior: "smooth" }) => {
37894
- const notSmooth = { ...options2, behavior: "auto" };
37893
+ (index2, options = { align: "auto", behavior: "smooth" }) => {
37894
+ const notSmooth = { ...options, behavior: "auto" };
37895
37895
  if (tableRef.current) {
37896
37896
  if (index2 === 0) {
37897
37897
  virtualiser.scrollToOffset(0, notSmooth);
37898
37898
  } else if (index2 === count2 - 1) {
37899
37899
  tableRef.current.scrollTop = tableRef.current.scrollHeight;
37900
37900
  } else {
37901
- virtualiser.scrollToIndex(index2, options2);
37901
+ virtualiser.scrollToIndex(index2, options);
37902
37902
  }
37903
37903
  }
37904
37904
  },
@@ -38336,17 +38336,10 @@ const INTERNAL_RENDERERS = {
38336
38336
  rowExpansion: renderer$1,
38337
38337
  rowSelection: renderer
38338
38338
  };
38339
- function useTable$1(props, externalRef, renderers, meta, options) {
38339
+ function useTable$1(props, externalRef, renderers, meta) {
38340
38340
  const ref = useMergedRef(externalRef);
38341
38341
  const manager = useTableManager(props, ref, meta, INTERNAL_RENDERERS);
38342
- const renderer2 = useTableRenderer(
38343
- renderers,
38344
- manager.instance,
38345
- ref,
38346
- manager.meta.length,
38347
- props.defaultRowActiveIndex,
38348
- options
38349
- );
38342
+ const renderer2 = useTableRenderer(renderers, manager.instance, ref, manager.meta.length, props.defaultRowActiveIndex);
38350
38343
  const { style, stylesheet } = useTableStyle(manager.id, manager.instance);
38351
38344
  useTableGlobalShortcuts(manager.instance, ref, renderer2.scrollToIndex, props.enableLocalKeyboardShortcuts);
38352
38345
  useTableRef(manager.instance, ref);
@@ -39037,6 +39030,9 @@ function Header$1(props) {
39037
39030
  if (canHide) {
39038
39031
  memoedProps.onHide = header.column.getToggleVisibilityHandler();
39039
39032
  }
39033
+ if (header.id === "__expansion") {
39034
+ memoedProps.isExpanded = table.getIsSomeRowsExpanded();
39035
+ }
39040
39036
  if (canPin) {
39041
39037
  memoedProps.onPin = (index2) => {
39042
39038
  table.setColumnPinning((pinningState) => {
@@ -39087,6 +39083,7 @@ const MemoedHeader = React.memo(function MemoedHeader2(props) {
39087
39083
  hasMenu,
39088
39084
  id: id2,
39089
39085
  index: index2,
39086
+ isExpanded,
39090
39087
  isFiltered,
39091
39088
  isGroup: isGroup2,
39092
39089
  isPinned,
@@ -39126,6 +39123,7 @@ const MemoedHeader = React.memo(function MemoedHeader2(props) {
39126
39123
  "data-cell-id": id2,
39127
39124
  "data-cell-pinned": isPinned ? isPinned : void 0,
39128
39125
  "data-taco": isGroup2 ? "grouped-column-header" : "column-header",
39126
+ "data-rows-expanded": isExpanded ? isExpanded : void 0,
39129
39127
  style,
39130
39128
  ref: setRef
39131
39129
  },
@@ -39320,10 +39318,10 @@ function Summary(props) {
39320
39318
  } else if (!tableMeta.server.isEnabled && (((_a = table.getState().columnFilters) == null ? void 0 : _a.length) || // filtered data
39321
39319
  !!table.getState().globalFilter && table.options.enableGlobalFilter)) {
39322
39320
  label = texts.table.footer.summary.records;
39323
- count2 = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("strong", null, new Intl.NumberFormat(locale2).format(currentLength)), " ", texts.table.footer.summary.count, " ", /* @__PURE__ */ React.createElement("strong", null, new Intl.NumberFormat(locale2).format(length)));
39321
+ count2 = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("strong", { "data-taco": "table-footer-current-count" }, new Intl.NumberFormat(locale2).format(currentLength)), " ", texts.table.footer.summary.count, " ", /* @__PURE__ */ React.createElement("strong", { "data-taco": "table-footer-total-count" }, new Intl.NumberFormat(locale2).format(length)));
39324
39322
  } else {
39325
39323
  label = texts.table.footer.summary.records;
39326
- count2 = /* @__PURE__ */ React.createElement("strong", null, new Intl.NumberFormat(locale2).format(length));
39324
+ count2 = /* @__PURE__ */ React.createElement("strong", { "data-taco": "table-footer-total-count" }, new Intl.NumberFormat(locale2).format(length));
39327
39325
  }
39328
39326
  return /* @__PURE__ */ React.createElement(
39329
39327
  "div",
@@ -39482,7 +39480,7 @@ const SearchInput22 = React.forwardRef(function SearchInput222(props, ref) {
39482
39480
  );
39483
39481
  }
39484
39482
  if (hasFind && isActive) {
39485
- postfix = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", { className: "text-grey-700 flex h-4 items-center" }, loading ? /* @__PURE__ */ React.createElement(Spinner, { className: "h-4 w-4" }) : showTotal ? /* @__PURE__ */ React.createElement("span", { className: "border-r border-black/[0.25] pr-2" }, `${findCurrent ?? 0}/${findTotal ?? 0}`) : null), findCurrent ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
39483
+ postfix = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", { className: "text-grey-700 flex h-4 items-center" }, loading ? /* @__PURE__ */ React.createElement(Spinner, { className: "h-4 w-4" }) : showTotal ? /* @__PURE__ */ React.createElement("span", { className: "border-r border-black/[0.25] pr-2", "data-taco": "search-matches-counter" }, `${findCurrent ?? 0}/${findTotal ?? 0}`) : null), findCurrent ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
39486
39484
  IconButton,
39487
39485
  {
39488
39486
  "aria-label": texts.searchInput.findPrevious,
@@ -45174,6 +45172,7 @@ function Print(props) {
45174
45172
  {
45175
45173
  icon: "print",
45176
45174
  "aria-label": texts.table.print.tooltip,
45175
+ id: `${tableId}-toolbar-print`,
45177
45176
  dialog: (dialogProps) => /* @__PURE__ */ React.createElement(
45178
45177
  PrintDialog,
45179
45178
  {
@@ -45510,7 +45509,7 @@ function Filter(props) {
45510
45509
  ref.current.focus();
45511
45510
  }
45512
45511
  }, [id2]);
45513
- 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);
45512
+ return /* @__PURE__ */ React.createElement("div", { className: "flex items-start gap-2", "data-taco": "filter-row" }, /* @__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);
45514
45513
  }
45515
45514
  const placeholderFilter = { id: "", value: { comparator: TableFilterComparator.Contains, value: void 0 } };
45516
45515
  function ManageFiltersPopover(props) {
@@ -45591,10 +45590,10 @@ function ManageFiltersPopover(props) {
45591
45590
  onChange: handleChangeFilter,
45592
45591
  onRemove: filters.length > 0 && filters.some((f2) => f2.id) || filters.length > 1 ? handleRemoveFilter : void 0
45593
45592
  }
45594
- )), /* @__PURE__ */ React.createElement("div", { className: "justify-start" }, /* @__PURE__ */ React.createElement(Button$4, { appearance: "discrete", onClick: handleCreate }, "+ ", texts.table.filters.buttons.addFilter))), /* @__PURE__ */ React.createElement(Group$6, { className: "ml-auto" }, /* @__PURE__ */ React.createElement(Popover.Close, null, /* @__PURE__ */ React.createElement(Button$4, null, texts.table.filters.buttons.cancel)), /* @__PURE__ */ React.createElement(Button$4, { onClick: handleClear }, texts.table.filters.buttons.clear), /* @__PURE__ */ React.createElement(Button$4, { appearance: "primary", onClick: handleApply }, texts.table.filters.buttons.apply))))));
45593
+ )), /* @__PURE__ */ React.createElement("div", { className: "justify-start" }, /* @__PURE__ */ React.createElement(Button$4, { appearance: "discrete", onClick: handleCreate, name: "add-filter" }, "+ ", texts.table.filters.buttons.addFilter))), /* @__PURE__ */ React.createElement(Group$6, { className: "ml-auto" }, /* @__PURE__ */ React.createElement(Popover.Close, null, /* @__PURE__ */ React.createElement(Button$4, { name: "close-filters" }, texts.table.filters.buttons.cancel)), /* @__PURE__ */ React.createElement(Button$4, { name: "clear-filters", onClick: handleClear }, texts.table.filters.buttons.clear), /* @__PURE__ */ React.createElement(Button$4, { appearance: "primary", name: "apply-filters", onClick: handleApply }, texts.table.filters.buttons.apply))))));
45595
45594
  }
45596
45595
  function Filters(props) {
45597
- const { length, table } = props;
45596
+ const { length, tableId, table } = props;
45598
45597
  const { texts } = useLocalization();
45599
45598
  const isLargeScreen = useIsLargeScreen();
45600
45599
  const columnFilters = table.getState().columnFilters;
@@ -45607,7 +45606,8 @@ function Filters(props) {
45607
45606
  popover: (popoverProps) => /* @__PURE__ */ React.createElement(ManageFiltersPopover, { ...popoverProps, length, table }),
45608
45607
  shortcut: shortcut2,
45609
45608
  ref,
45610
- tooltip: /* @__PURE__ */ React.createElement(React.Fragment, null, texts.table.filters.tooltip, /* @__PURE__ */ React.createElement(Shortcut, { className: "ml-2", keys: shortcut2 }))
45609
+ tooltip: /* @__PURE__ */ React.createElement(React.Fragment, null, texts.table.filters.tooltip, /* @__PURE__ */ React.createElement(Shortcut, { className: "ml-2", keys: shortcut2 })),
45610
+ id: `${tableId}-toolbar-filters`
45611
45611
  };
45612
45612
  React.useEffect(() => {
45613
45613
  var _a;
@@ -45640,7 +45640,7 @@ function TableToolbar(props) {
45640
45640
  "data-taco": "table-toolbar"
45641
45641
  },
45642
45642
  table.props.toolbarLeft,
45643
- /* @__PURE__ */ React.createElement(Group$6, { className: "ml-auto flex-shrink-0 items-center print:hidden" }, customTools, canFilter ? /* @__PURE__ */ React.createElement(Filters, { length: table.meta.length, table: table.instance }) : null, table.props.toolbarRight, canPrint ? /* @__PURE__ */ React.createElement(Print, { table: table.instance, tableId: table.id, tableRef: table.ref }) : null, canSettings ? /* @__PURE__ */ React.createElement(Settings, { customSettings: table.props.customSettings, id: `${id2}-settings`, table: table.instance }) : null, canSearch ? /* @__PURE__ */ React.createElement(Search$1, { scrollToIndex: table.renderer.scrollToIndex, table: table.instance, tableRef: table.ref }) : null)
45643
+ /* @__PURE__ */ React.createElement(Group$6, { className: "ml-auto flex-shrink-0 items-center print:hidden" }, customTools, canFilter ? /* @__PURE__ */ React.createElement(Filters, { length: table.meta.length, tableId: table.id, table: table.instance }) : null, table.props.toolbarRight, canPrint ? /* @__PURE__ */ React.createElement(Print, { table: table.instance, tableId: table.id, tableRef: table.ref }) : null, canSettings ? /* @__PURE__ */ React.createElement(Settings, { customSettings: table.props.customSettings, id: `${id2}-settings`, table: table.instance }) : null, canSearch ? /* @__PURE__ */ React.createElement(Search$1, { scrollToIndex: table.renderer.scrollToIndex, table: table.instance, tableRef: table.ref }) : null)
45644
45644
  ), table.props.toolbarPanel ? /* @__PURE__ */ React.createElement("div", { className: "mb-4" }, table.props.toolbarPanel) : void 0);
45645
45645
  }
45646
45646
  function canChangeSettings(table, customSettings) {
@@ -55285,6 +55285,13 @@ function reducer(state, action) {
55285
55285
  indexes: setWith(state.indexes, rowId, index2, Object)
55286
55286
  };
55287
55287
  }
55288
+ case "forceValidate": {
55289
+ const { newState } = payload;
55290
+ return {
55291
+ ...state,
55292
+ ...newState
55293
+ };
55294
+ }
55288
55295
  default:
55289
55296
  return state;
55290
55297
  }
@@ -55444,6 +55451,46 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55444
55451
  }
55445
55452
  });
55446
55453
  }
55454
+ async function forceValidate(table) {
55455
+ if (validator && table.getRowModel().rows.length) {
55456
+ const newState = { ...state };
55457
+ const returnIds = [];
55458
+ await Promise.all(
55459
+ table.getRowModel().rows.map(async (row, index2) => {
55460
+ var _a, _b;
55461
+ const rowWithChanges = { ...row.original, ...state.changes.rows[row.id] };
55462
+ if (rowWithChanges) {
55463
+ const cellErrors = await validator(rowWithChanges);
55464
+ if (cellErrors) {
55465
+ newState.changes.dirty[row.id] = true;
55466
+ newState.changes.originals[row.id] = row.original;
55467
+ newState.changes.moveReasons[row.id] = { ...newState.changes.moveReasons[row.id] };
55468
+ newState.changes.rows[row.id] = { ...newState.changes.rows[row.id] };
55469
+ newState.changes.status[row.id] = "errored";
55470
+ newState.indexes[row.id] = index2;
55471
+ newState.changes.errors[row.id] = {
55472
+ cells: cellErrors,
55473
+ row: ((_a = newState.changes.errors[row.id]) == null ? void 0 : _a.row) ?? void 0,
55474
+ shouldShowErrorAlert: ((_b = newState.changes.errors[row.id]) == null ? void 0 : _b.shouldShowErrorAlert) ?? false
55475
+ };
55476
+ Object.keys(cellErrors).forEach((columnId) => {
55477
+ newState.changes.rows[row.id][columnId] = rowWithChanges[columnId];
55478
+ });
55479
+ returnIds.push(row.id);
55480
+ }
55481
+ }
55482
+ })
55483
+ );
55484
+ dispatch({
55485
+ type: "forceValidate",
55486
+ payload: {
55487
+ newState
55488
+ }
55489
+ });
55490
+ return returnIds;
55491
+ }
55492
+ return [];
55493
+ }
55447
55494
  function getErrors() {
55448
55495
  return Object.keys(state.changes.errors);
55449
55496
  }
@@ -55572,6 +55619,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
55572
55619
  hasTemporaryRowErrors,
55573
55620
  getRowStatus,
55574
55621
  setRowStatus,
55622
+ forceValidate,
55575
55623
  // cells
55576
55624
  setCellValue,
55577
55625
  getCellValue,
@@ -55625,6 +55673,7 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
55625
55673
  pendingChangesFns.saveChanges(table);
55626
55674
  }
55627
55675
  async function createRow2(table, row) {
55676
+ var _a, _b;
55628
55677
  if (!handleCreate) {
55629
55678
  return;
55630
55679
  }
@@ -55635,7 +55684,10 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
55635
55684
  return;
55636
55685
  }
55637
55686
  }
55638
- const changeset = row ?? await handleCreate();
55687
+ const currentRow = ((_a = table.options.meta) == null ? void 0 : _a.rowActive.rowActiveIndex) !== void 0 ? table.getRowModel().flatRows[(_b = table.options.meta) == null ? void 0 : _b.rowActive.rowActiveIndex] : void 0;
55688
+ const changeset = row ?? await handleCreate({
55689
+ activeRow: currentRow ? { ...currentRow.original, ...tableMeta.editing.getRowValue(currentRow.id) } : void 0
55690
+ });
55639
55691
  try {
55640
55692
  if (changeset) {
55641
55693
  const temporaryRows = tableMeta.editing.temporaryRows;
@@ -55644,10 +55696,10 @@ function useTableEditing(isEnabled = false, defaultToggleEditing = false, handle
55644
55696
  requestAnimationFrame(() => {
55645
55697
  const newRowId = pendingChangesFns.insertTemporaryRow(changeset, nextRowIndex);
55646
55698
  table.setRowPinning((currentState) => {
55647
- var _a;
55699
+ var _a2;
55648
55700
  return {
55649
55701
  ...currentState,
55650
- bottom: (_a = currentState.bottom ?? []) == null ? void 0 : _a.concat(newRowId)
55702
+ bottom: (_a2 = currentState.bottom ?? []) == null ? void 0 : _a2.concat(newRowId)
55651
55703
  };
55652
55704
  });
55653
55705
  toggleDetailedMode(false);
@@ -56325,14 +56377,7 @@ function useTable3(props, ref) {
56325
56377
  ]) : props.rowActions
56326
56378
  };
56327
56379
  const meta = { editing };
56328
- const options = {
56329
- virtualiserPaddingEndOffset: 0
56330
- };
56331
- if (props.enableEditing) {
56332
- const validationErrorLabelHeight = 17;
56333
- options.virtualiserPaddingEndOffset = editing.getErrors().length * validationErrorLabelHeight;
56334
- }
56335
- const table = useTable$1(extendedProps, ref, RENDERERS, meta, options);
56380
+ const table = useTable$1(extendedProps, ref, RENDERERS, meta);
56336
56381
  const toggleEditing = (enabled) => table.meta.editing.toggleEditing(enabled ?? ((editing2) => !editing2), table.instance, table.renderer.scrollToIndex);
56337
56382
  React.useEffect(() => {
56338
56383
  if (props.defaultToggleEditing) {
@@ -56355,6 +56400,14 @@ function useTable3(props, ref) {
56355
56400
  }
56356
56401
  }
56357
56402
  }, [table.ref.current, table.meta.editing.isEnabled]);
56403
+ React.useEffect(() => {
56404
+ if (table.ref.current) {
56405
+ const instance = table.ref.current.instance;
56406
+ if (table.meta.editing.isEnabled) {
56407
+ instance.editing.forceValidate = async () => table.meta.editing.forceValidate(table.instance);
56408
+ }
56409
+ }
56410
+ }, [table.meta.editing.forceValidate]);
56358
56411
  return table;
56359
56412
  }
56360
56413
  function Alert(props) {