@economic/taco 2.69.2-search-race-condition.0 → 2.69.2-search-race-condition.1

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
@@ -45098,10 +45098,10 @@ function Search$1(props) {
45098
45098
  };
45099
45099
  const [loading, setLoading] = React.useState(false);
45100
45100
  const handleSearch = React.useCallback(
45101
- _.debounce((query2) => {
45101
+ _.debounce((query2, hiddenColumns2) => {
45102
45102
  var _a2, _b, _c;
45103
45103
  setLoading(true);
45104
- (_c = (_b = (_a2 = tableMeta.search).handleSearch) == null ? void 0 : _b.call(_a2, query2, hiddenColumns)) == null ? void 0 : _c.then(() => {
45104
+ (_c = (_b = (_a2 = tableMeta.search).handleSearch) == null ? void 0 : _b.call(_a2, query2, hiddenColumns2)) == null ? void 0 : _c.then(() => {
45105
45105
  setLoading(false);
45106
45106
  });
45107
45107
  }, 400),
@@ -45110,7 +45110,7 @@ function Search$1(props) {
45110
45110
  const handleChange = (query2) => {
45111
45111
  table.setGlobalFilter(String(query2 ?? ""));
45112
45112
  if (tableMeta.search.enableGlobalFilter && tableMeta.search.handleSearch) {
45113
- handleSearch(query2);
45113
+ handleSearch(query2, hiddenColumns);
45114
45114
  }
45115
45115
  };
45116
45116
  const handleToggleExcludeUnmatchedResults = async (enabled) => {
@@ -49651,7 +49651,14 @@ const EditPopover = (props) => {
49651
49651
  onChangeColor: setColor,
49652
49652
  onKeyDown: preventKeyDownPropagation
49653
49653
  }
49654
- )) : null, /* @__PURE__ */ React.createElement(Group$6, null, /* @__PURE__ */ React.createElement(Button$4, { onClick: close }, texts.select2.cancel), /* @__PURE__ */ React.createElement(Button$4, { appearance: "primary", onClick: handleSave(close) }, texts.select2.save))) : null, onEdit && onDelete ? /* @__PURE__ */ React.createElement("hr", null) : null, onDelete ? /* @__PURE__ */ React.createElement(
49654
+ )) : null, /* @__PURE__ */ React.createElement(Group$6, null, /* @__PURE__ */ React.createElement(Button$4, { onClick: close }, texts.select2.cancel), /* @__PURE__ */ React.createElement(
49655
+ Button$4,
49656
+ {
49657
+ appearance: "primary",
49658
+ onClick: handleSave(close)
49659
+ },
49660
+ texts.select2.save
49661
+ ))) : null, onEdit && onDelete ? /* @__PURE__ */ React.createElement("hr", null) : null, onDelete ? /* @__PURE__ */ React.createElement(
49655
49662
  "button",
49656
49663
  {
49657
49664
  className: "hover:text-grey-700 flex items-center justify-start gap-1",
@@ -50917,6 +50924,7 @@ function Control(props) {
50917
50924
  const controlRenderer = (_a = column == null ? void 0 : column.columnDef.meta) == null ? void 0 : _a.control;
50918
50925
  const dataType = (_b = column == null ? void 0 : column.columnDef.meta) == null ? void 0 : _b.dataType;
50919
50926
  const filters = React.useContext(FilterContext);
50927
+ const ref = React.useRef(null);
50920
50928
  React.useEffect(() => {
50921
50929
  if ((controlRenderer === "switch" || controlRenderer === "checkbox") && value === void 0) {
50922
50930
  onChange(false);
@@ -50926,8 +50934,9 @@ function Control(props) {
50926
50934
  const control = controlRenderer(
50927
50935
  {
50928
50936
  ...attributes,
50929
- setValue: (value2) => onChange(value2),
50930
- value
50937
+ setValue: onChange,
50938
+ value,
50939
+ ref
50931
50940
  },
50932
50941
  void 0,
50933
50942
  filters
@@ -57189,7 +57198,9 @@ const useRowSelect = (onSelectedRows) => {
57189
57198
  const { onChange: _2, ...props } = getToggleAllRowsSelectedProps();
57190
57199
  const onChange = (checked) => {
57191
57200
  if (checked) {
57192
- onSelectedRows(Object.assign({}, Array.from({ length: rows.length }).fill(true)));
57201
+ onSelectedRows(
57202
+ Object.assign({}, Array.from({ length: rows.length }).fill(true))
57203
+ );
57193
57204
  } else {
57194
57205
  onSelectedRows({});
57195
57206
  }
@@ -60636,7 +60647,8 @@ var setWithExports = requireSetWith();
60636
60647
  const setWith = /* @__PURE__ */ getDefaultExportFromCjs(setWithExports);
60637
60648
  const DELAY_BEFORE_REMOVING_SAVE_STATUS = 3e3;
60638
60649
  function reducer(state, action) {
60639
- const { type, rowId, payload } = action;
60650
+ var _a;
60651
+ const { type, payload } = action;
60640
60652
  switch (type) {
60641
60653
  case "setCellValue": {
60642
60654
  const { columnId, index: index2, row, value } = payload;
@@ -60644,26 +60656,26 @@ function reducer(state, action) {
60644
60656
  ...state,
60645
60657
  changes: {
60646
60658
  ...state.changes,
60647
- rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),
60648
- originals: setWith(state.changes.originals, rowId, row, Object),
60649
- dirty: setWith(state.changes.dirty, rowId, true, Object)
60659
+ rows: setWith(state.changes.rows, `${action.rowId}.${columnId}`, value, Object),
60660
+ originals: setWith(state.changes.originals, action.rowId, row, Object),
60661
+ dirty: setWith(state.changes.dirty, action.rowId, true, Object)
60650
60662
  },
60651
- indexes: setWith(state.indexes, rowId, index2, Object)
60663
+ indexes: setWith(state.indexes, action.rowId, index2, Object)
60652
60664
  };
60653
60665
  }
60654
60666
  case "removeCellValue": {
60655
60667
  const { columnId, rowIdentityAccessor } = payload;
60656
- const changes = omit$1(state.changes.rows, `${rowId}.${columnId}`);
60657
- if (!Object.keys(changes[rowId]).length) {
60658
- return reducer(state, { type: "removeRow", rowId, payload: { rowIdentityAccessor } });
60668
+ const changes = omit$1(state.changes.rows, `${action.rowId}.${columnId}`);
60669
+ if (!Object.keys(changes[action.rowId]).length) {
60670
+ return reducer(state, { type: "removeRow", rowId: action.rowId, payload: { rowIdentityAccessor } });
60659
60671
  }
60660
60672
  return {
60661
60673
  ...state,
60662
60674
  changes: {
60663
60675
  ...state.changes,
60664
- rows: omit$1(state.changes.rows, `${rowId}.${columnId}`),
60665
- errors: omit$1(state.changes.errors, `${rowId}.cells.${columnId}`),
60666
- moveReasons: omit$1(state.changes.moveReasons, `${rowId}.${columnId}`)
60676
+ rows: omit$1(state.changes.rows, `${action.rowId}.${columnId}`),
60677
+ errors: omit$1(state.changes.errors, `${action.rowId}.cells.${columnId}`),
60678
+ moveReasons: omit$1(state.changes.moveReasons, `${action.rowId}.${columnId}`)
60667
60679
  }
60668
60680
  };
60669
60681
  }
@@ -60673,24 +60685,28 @@ function reducer(state, action) {
60673
60685
  ...state,
60674
60686
  changes: {
60675
60687
  ...state.changes,
60676
- rows: setWith(state.changes.rows, rowId, value, Object),
60688
+ rows: setWith(state.changes.rows, action.rowId, value, Object),
60677
60689
  errors: setWith(
60678
60690
  state.changes.errors,
60679
- `${rowId}.cells`,
60680
- cellErrors ?? state.changes.errors.cells[rowId],
60691
+ `${action.rowId}.cells`,
60692
+ cellErrors ?? ((_a = state.changes.errors[action.rowId]) == null ? void 0 : _a.cells),
60693
+ Object
60694
+ ),
60695
+ originals: setWith(
60696
+ state.changes.originals,
60697
+ action.rowId,
60698
+ original ?? state.changes.originals[action.rowId],
60681
60699
  Object
60682
60700
  ),
60683
- originals: setWith(state.changes.originals, rowId, original ?? state.changes.originals[rowId], Object),
60684
60701
  moveReasons: setWith(
60685
60702
  state.changes.moveReasons,
60686
- rowId,
60687
- moveReasons ?? state.changes.moveReasons[rowId],
60703
+ action.rowId,
60704
+ moveReasons ?? state.changes.moveReasons[action.rowId],
60688
60705
  Object
60689
- ),
60690
- // status can be undefined, so don't use ??
60691
- status: setWith(state.changes.status, rowId, void 0, Object)
60706
+ )
60692
60707
  },
60693
- indexes: setWith(state.indexes, rowId, index2, Object)
60708
+ indexes: setWith(state.indexes, action.rowId, index2, Object),
60709
+ statuses: omit$1(state.statuses, action.rowId)
60694
60710
  };
60695
60711
  }
60696
60712
  case "removeRow": {
@@ -60699,28 +60715,27 @@ function reducer(state, action) {
60699
60715
  ...state,
60700
60716
  changes: {
60701
60717
  ...state.changes,
60702
- rows: omit$1(state.changes.rows, rowId),
60703
- errors: omit$1(state.changes.errors, rowId),
60704
- moveReasons: omit$1(state.changes.moveReasons, rowId),
60705
- originals: omit$1(state.changes.originals, rowId),
60706
- status: omit$1(state.changes.status, rowId),
60707
- dirty: omit$1(state.changes.dirty, rowId)
60718
+ rows: omit$1(state.changes.rows, action.rowId),
60719
+ errors: omit$1(state.changes.errors, action.rowId),
60720
+ moveReasons: omit$1(state.changes.moveReasons, action.rowId),
60721
+ originals: omit$1(state.changes.originals, action.rowId),
60722
+ dirty: omit$1(state.changes.dirty, action.rowId)
60708
60723
  },
60709
- indexes: omit$1(state.indexes, rowId),
60710
- temporaryRows: state.temporaryRows.filter((row) => row[rowIdentityAccessor] !== rowId)
60724
+ indexes: omit$1(state.indexes, action.rowId),
60725
+ temporaryRows: state.temporaryRows.filter((row) => row[rowIdentityAccessor] !== action.rowId)
60711
60726
  };
60712
60727
  }
60713
60728
  case "complete": {
60714
60729
  const { changes, handleDiscard } = payload;
60715
- if (JSON.stringify(changes) !== JSON.stringify(state.changes.rows[rowId])) {
60730
+ if (JSON.stringify(changes) !== JSON.stringify(state.changes.rows[action.rowId])) {
60716
60731
  return {
60717
60732
  ...state,
60718
60733
  changes: {
60719
60734
  ...state.changes,
60720
60735
  originals: setWith(
60721
60736
  state.changes.originals,
60722
- rowId,
60723
- { ...state.changes.originals[rowId], ...changes },
60737
+ action.rowId,
60738
+ { ...state.changes.originals[action.rowId], ...changes },
60724
60739
  Object
60725
60740
  )
60726
60741
  }
@@ -60733,12 +60748,15 @@ function reducer(state, action) {
60733
60748
  }
60734
60749
  case "setRowStatus": {
60735
60750
  const { status } = payload;
60751
+ if (status) {
60752
+ return {
60753
+ ...state,
60754
+ statuses: setWith(state.statuses, action.rowId, status, Object)
60755
+ };
60756
+ }
60736
60757
  return {
60737
60758
  ...state,
60738
- changes: {
60739
- ...state.changes,
60740
- status: status ? setWith(state.changes.status, rowId, status, Object) : omit$1(state.changes.status, rowId)
60741
- }
60759
+ statuses: omit$1(state.statuses, action.rowId)
60742
60760
  };
60743
60761
  }
60744
60762
  case "setRowErrors": {
@@ -60747,7 +60765,7 @@ function reducer(state, action) {
60747
60765
  ...state,
60748
60766
  changes: {
60749
60767
  ...state.changes,
60750
- errors: setWith(state.changes.errors, rowId, errors, Object)
60768
+ errors: setWith(state.changes.errors, action.rowId, errors, Object)
60751
60769
  }
60752
60770
  };
60753
60771
  }
@@ -60758,10 +60776,10 @@ function reducer(state, action) {
60758
60776
  temporaryRows: state.temporaryRows.concat(value),
60759
60777
  changes: {
60760
60778
  ...state.changes,
60761
- rows: setWith(state.changes.rows, rowId, value, Object),
60762
- originals: setWith(state.changes.originals, rowId, value, Object)
60779
+ rows: setWith(state.changes.rows, action.rowId, value, Object),
60780
+ originals: setWith(state.changes.originals, action.rowId, value, Object)
60763
60781
  },
60764
- indexes: setWith(state.indexes, rowId, index2, Object)
60782
+ indexes: setWith(state.indexes, action.rowId, index2, Object)
60765
60783
  };
60766
60784
  }
60767
60785
  case "forceValidate": {
@@ -60778,9 +60796,10 @@ function reducer(state, action) {
60778
60796
  function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIdentityAccessor, validator) {
60779
60797
  const localization = useLocalization();
60780
60798
  const [state, dispatch] = React.useReducer(reducer, {
60781
- changes: { rows: {}, errors: {}, moveReasons: {}, originals: {}, status: {}, dirty: {} },
60799
+ changes: { rows: {}, errors: {}, moveReasons: {}, originals: {}, dirty: {} },
60782
60800
  indexes: {},
60783
- temporaryRows: []
60801
+ temporaryRows: [],
60802
+ statuses: {}
60784
60803
  });
60785
60804
  function getRowValue(rowId) {
60786
60805
  var _a;
@@ -60808,7 +60827,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
60808
60827
  return !!((_b = state.changes.errors[rowId]) == null ? void 0 : _b.row) || !!Object.keys(((_c = state.changes.errors[rowId]) == null ? void 0 : _c.cells) ?? {}).length;
60809
60828
  }
60810
60829
  function getRowStatus(rowId) {
60811
- return state.changes.status[rowId];
60830
+ return state.statuses[rowId];
60812
60831
  }
60813
60832
  function setRowStatus(rowId, status) {
60814
60833
  dispatch({
@@ -60819,6 +60838,12 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
60819
60838
  }
60820
60839
  });
60821
60840
  }
60841
+ function showSavedStatus(rowId) {
60842
+ setRowStatus(rowId, "saved");
60843
+ setTimeout(() => {
60844
+ setRowStatus(rowId, void 0);
60845
+ }, DELAY_BEFORE_REMOVING_SAVE_STATUS);
60846
+ }
60822
60847
  function insertTemporaryRow(data, rowIndex) {
60823
60848
  const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${nanoid()}`;
60824
60849
  const value = {
@@ -60945,7 +60970,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
60945
60970
  newState.changes.originals[row.id] = row.original;
60946
60971
  newState.changes.moveReasons[row.id] = { ...newState.changes.moveReasons[row.id] };
60947
60972
  newState.changes.rows[row.id] = { ...newState.changes.rows[row.id] };
60948
- newState.changes.status[row.id] = "errored";
60973
+ newState.statuses[row.id] = "errored";
60949
60974
  newState.indexes[row.id] = index2;
60950
60975
  newState.changes.errors[row.id] = {
60951
60976
  cells: cellErrors,
@@ -60986,7 +61011,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
60986
61011
  }));
60987
61012
  }
60988
61013
  function hasSaved() {
60989
- return !!Object.values(state.changes.status).filter((value) => value === "saved").length;
61014
+ return !!Object.values(state.statuses).filter((status) => status === "saved").length;
60990
61015
  }
60991
61016
  function hasChanges(rowId) {
60992
61017
  return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;
@@ -61025,10 +61050,7 @@ function usePendingChangesState(handleSave, handleChange, handleDiscard, rowIden
61025
61050
  }
61026
61051
  await handleSave(changeSet);
61027
61052
  complete(rowId2, table, rowChanges);
61028
- setRowStatus(rowId2, "saved");
61029
- setTimeout(() => {
61030
- setRowStatus(rowId2, void 0);
61031
- }, DELAY_BEFORE_REMOVING_SAVE_STATUS);
61053
+ showSavedStatus(rowId2);
61032
61054
  } catch (error) {
61033
61055
  if (error instanceof ReferenceError || error instanceof TypeError || ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) >= 500) {
61034
61056
  console.error(error);
@@ -61211,7 +61233,8 @@ function RowMoveIndicator(props) {
61211
61233
  const { cell, cellRef, isActiveRow } = props;
61212
61234
  const { texts } = useLocalization();
61213
61235
  const [show, setShow] = React.useState(false);
61214
- const tableMeta = cell.getContext().table.options.meta;
61236
+ const table = cell.getContext().table;
61237
+ const tableMeta = table.options.meta;
61215
61238
  const columnMeta = cell.column.columnDef.meta ?? {};
61216
61239
  const moveReason = tableMeta.editing.getRowMoveReason(cell.row.id);
61217
61240
  React.useEffect(() => {
@@ -61239,7 +61262,15 @@ function RowMoveIndicator(props) {
61239
61262
  return null;
61240
61263
  }
61241
61264
  const { title, description } = getMessageFromReason(texts, moveReason);
61242
- return /* @__PURE__ */ React.createElement(Tooltip$3, { placement: "bottom", title: description.replace("[COLUMN]", columnMeta.header) }, /* @__PURE__ */ React.createElement("span", { "data-row-move-indicator": true }, /* @__PURE__ */ React.createElement(Icon$1, { name: "info", className: "-mt-0.5 mr-1 !h-4 !w-4 rounded-full bg-white !p-0 text-blue-500" }), title));
61265
+ let columnHeader = columnMeta.header;
61266
+ if (moveReason === "sorting") {
61267
+ const sortedColumns = table.getState().sorting;
61268
+ const sortedColumn = table.getColumn(sortedColumns[0].id);
61269
+ if (sortedColumn) {
61270
+ columnHeader = sortedColumn.columnDef.meta.header;
61271
+ }
61272
+ }
61273
+ return /* @__PURE__ */ React.createElement(Tooltip$3, { placement: "bottom", title: description.replace("[COLUMN]", columnHeader) }, /* @__PURE__ */ React.createElement("span", { "data-row-move-indicator": true }, /* @__PURE__ */ React.createElement(Icon$1, { name: "info", className: "-mt-0.5 mr-1 !h-4 !w-4 rounded-full bg-white !p-0 text-blue-500" }), title));
61243
61274
  }
61244
61275
  function getMessageFromReason(texts, reason) {
61245
61276
  let title;
@@ -61408,10 +61439,17 @@ function EditingControlCell(props) {
61408
61439
  const handleFocus = useEditingCellAutofocus(props);
61409
61440
  const value = cell.getValue();
61410
61441
  const rowChanges = tableMeta.editing.getRowValue(cell.row.id);
61442
+ const shouldRunUpdate = React.useRef(false);
61411
61443
  const hasNonTextControl = React.useMemo(() => {
61412
61444
  var _a;
61413
61445
  return typeof type === "function" && !!((_a = cellRef.current) == null ? void 0 : _a.querySelector('[data-taco="Select2"],[data-taco="switch"],[data-taco="checkbox"]'));
61414
61446
  }, [cellRef.current]);
61447
+ useLazyEffect(() => {
61448
+ if (hasNonTextControl && shouldRunUpdate.current) {
61449
+ tableMeta.editing.onCellChanged(cell, rowIndex, value, true, false);
61450
+ shouldRunUpdate.current = false;
61451
+ }
61452
+ }, [value]);
61415
61453
  const handleChange = React.useCallback(
61416
61454
  (nextValue) => {
61417
61455
  let hasChanged = false;
@@ -61428,9 +61466,7 @@ function EditingControlCell(props) {
61428
61466
  }
61429
61467
  if (hasChanged) {
61430
61468
  tableMeta.editing.setCellValue(cell, rowIndex, nextValue);
61431
- if (hasNonTextControl) {
61432
- requestAnimationFrame(() => tableMeta.editing.onCellChanged(cell, rowIndex, nextValue, true, false));
61433
- }
61469
+ shouldRunUpdate.current = hasNonTextControl;
61434
61470
  }
61435
61471
  },
61436
61472
  [hasNonTextControl, cell.row.id, cell.column.id, cell.row.original, rowIndex, value, columnMeta.dataType]
@@ -61885,7 +61921,7 @@ function useTable3(props, ref) {
61885
61921
  removeRowChanges: (rowId) => table.meta.editing.discardChanges(rowId, table.instance),
61886
61922
  save: (rowId) => table.meta.editing.saveChanges(table.instance, rowId)
61887
61923
  };
61888
- if (props.onEditingCreate) {
61924
+ if (props.onEditingCreate && instance.editing) {
61889
61925
  instance.editing.createRow = (row) => table.meta.editing.createRow(table.instance, row);
61890
61926
  }
61891
61927
  }
@@ -61894,7 +61930,7 @@ function useTable3(props, ref) {
61894
61930
  React.useEffect(() => {
61895
61931
  if (table.ref.current) {
61896
61932
  const instance = table.ref.current.instance;
61897
- if (table.meta.editing.isEnabled) {
61933
+ if (table.meta.editing.isEnabled && instance.editing) {
61898
61934
  instance.editing.forceValidate = async () => await table.meta.editing.forceValidate(table.instance);
61899
61935
  }
61900
61936
  }