@economic/taco 2.46.9 → 2.47.0-server-1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/dist/components/Report/Report.d.ts +1 -1
  2. package/dist/components/SearchInput2/SearchInput2.d.ts +2 -0
  3. package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +1 -2
  4. package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +1 -0
  5. package/dist/components/Table3/features/useEditingState.d.ts +11 -11
  6. package/dist/components/Table3/features/useTableEditing.d.ts +13 -13
  7. package/dist/components/Table3/util/editing.d.ts +3 -0
  8. package/dist/esm/index.css +2 -2
  9. package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js +17 -17
  10. package/dist/esm/node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js.map +1 -1
  11. package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +6 -3
  12. package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
  13. package/dist/esm/packages/taco/src/components/Table/hooks/plugins/useRowActions.js +1 -1
  14. package/dist/esm/packages/taco/src/components/Table3/Table3.js +14 -4
  15. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  16. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +1 -1
  17. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  18. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +14 -9
  19. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  20. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +2 -4
  21. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -1
  22. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +5 -4
  23. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -1
  24. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +32 -51
  25. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -1
  26. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +5 -3
  27. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  28. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +15 -12
  29. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  30. package/dist/esm/packages/taco/src/components/Table3/util/editing.js +9 -1
  31. package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
  32. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +2 -1
  33. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  34. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Expansion.js +4 -0
  35. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Expansion.js.map +1 -1
  36. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js +7 -4
  37. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Selection.js.map +1 -1
  38. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +7 -2
  39. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
  40. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js +7 -5
  41. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Summary.js.map +1 -1
  42. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js +24 -22
  43. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.js.map +1 -1
  44. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js +41 -4
  45. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
  46. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js +3 -1
  47. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Print/Print.js.map +1 -1
  48. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js +26 -3
  49. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Search/Search.js.map +1 -1
  50. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js +1 -1
  51. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableGlobalShortcuts.js.map +1 -1
  52. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +36 -9
  53. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  54. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +1 -1
  55. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
  56. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  57. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js +5 -7
  58. package/dist/esm/packages/taco/src/primitives/Table/useTableDataLoader.js.map +1 -1
  59. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +1 -1
  60. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
  61. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowExpansion.js +2 -1
  62. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowExpansion.js.map +1 -1
  63. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js +3 -2
  64. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableSearch.js.map +1 -1
  65. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js +4 -2
  66. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableServerLoading.js.map +1 -1
  67. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js +3 -1
  68. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableFilterListener.js.map +1 -1
  69. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js +4 -4
  70. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableRowSelectionListener.js.map +1 -1
  71. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js +14 -13
  72. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableSearchListener.js.map +1 -1
  73. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js +7 -3
  74. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/listeners/useTableServerLoadingListener.js.map +1 -1
  75. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +4 -4
  76. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  77. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js +4 -1
  78. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/columns.js.map +1 -1
  79. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/presets.js +7 -1
  80. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/presets.js.map +1 -1
  81. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +6 -0
  82. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  83. package/dist/hooks/useLazyDebouncedEffect.d.ts +2 -0
  84. package/dist/index.css +2 -2
  85. package/dist/primitives/Table/Core/Table.d.ts +1 -0
  86. package/dist/primitives/Table/Core/components/Row/BuiltIns/SkeletonRow.d.ts +2 -2
  87. package/dist/primitives/Table/Core/components/Row/Row.d.ts +2 -0
  88. package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +1 -1
  89. package/dist/primitives/Table/types.d.ts +11 -6
  90. package/dist/primitives/Table/useTableDataLoader2.d.ts +24 -0
  91. package/dist/primitives/Table/useTableManager/features/useTableRowExpansion.d.ts +2 -1
  92. package/dist/primitives/Table/useTableManager/features/useTableSearch.d.ts +4 -2
  93. package/dist/primitives/Table/useTableManager/features/useTableServerLoading.d.ts +3 -1
  94. package/dist/primitives/Table/useTableManager/listeners/useTableSearchListener.d.ts +1 -2
  95. package/dist/primitives/Table/useTableManager/util/columns.d.ts +2 -1
  96. package/dist/taco.cjs.development.js +363 -229
  97. package/dist/taco.cjs.development.js.map +1 -1
  98. package/dist/taco.cjs.production.min.js +1 -1
  99. package/dist/taco.cjs.production.min.js.map +1 -1
  100. package/package.json +2 -3
@@ -18,6 +18,7 @@ function reducer(state, action) {
18
18
  {
19
19
  const {
20
20
  columnId,
21
+ index,
21
22
  row,
22
23
  value
23
24
  } = payload;
@@ -27,7 +28,8 @@ function reducer(state, action) {
27
28
  ...state.changes,
28
29
  rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),
29
30
  originals: setWith(state.changes.originals, rowId, row, Object)
30
- }
31
+ },
32
+ indexes: setWith(state.indexes, rowId, index, Object)
31
33
  };
32
34
  }
33
35
  case 'removeCellValue':
@@ -61,6 +63,7 @@ function reducer(state, action) {
61
63
  {
62
64
  const {
63
65
  cellErrors,
66
+ index,
64
67
  moveReasons,
65
68
  original,
66
69
  value
@@ -75,7 +78,8 @@ function reducer(state, action) {
75
78
  moveReasons: setWith(state.changes.moveReasons, rowId, moveReasons !== null && moveReasons !== void 0 ? moveReasons : state.changes.moveReasons[rowId], Object),
76
79
  // status can be undefined, so don't use ??
77
80
  status: setWith(state.changes.status, rowId, undefined, Object)
78
- }
81
+ },
82
+ indexes: setWith(state.indexes, rowId, index, Object)
79
83
  };
80
84
  }
81
85
  case 'removeRow':
@@ -93,6 +97,7 @@ function reducer(state, action) {
93
97
  originals: omit(state.changes.originals, rowId),
94
98
  status: omit(state.changes.status, rowId)
95
99
  },
100
+ indexes: omit(state.indexes, rowId),
96
101
  temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId)
97
102
  };
98
103
  }
@@ -125,6 +130,7 @@ function reducer(state, action) {
125
130
  case 'insertTemporaryRow':
126
131
  {
127
132
  const {
133
+ index,
128
134
  value
129
135
  } = payload;
130
136
  return {
@@ -134,7 +140,8 @@ function reducer(state, action) {
134
140
  ...state.changes,
135
141
  rows: setWith(state.changes.rows, rowId, value, Object),
136
142
  originals: setWith(state.changes.originals, rowId, value, Object)
137
- }
143
+ },
144
+ indexes: setWith(state.indexes, rowId, index, Object)
138
145
  };
139
146
  }
140
147
  default:
@@ -154,10 +161,10 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
154
161
  [rowId]: state.changes.rows[rowId]
155
162
  } : state.changes.rows;
156
163
  let completed = true;
157
- const _temp9 = _forOf(Object.keys(changes), function (rowId) {
164
+ const _temp7 = _forOf(Object.keys(changes), function (rowId) {
158
165
  const status = getRowStatus(rowId);
159
166
  return _catch(function () {
160
- function _temp8(_result) {
167
+ function _temp6(_result) {
161
168
  return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
162
169
  // cleanup changes, we don't need them after saving
163
170
  discardChanges(rowId, table);
@@ -182,7 +189,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
182
189
  delete changeSet[rowIdentityAccessor];
183
190
  }
184
191
  // re-run validation, maybe a cell is already invalid but has never been blurred
185
- const _temp7 = function () {
192
+ const _temp5 = function () {
186
193
  if (validator) {
187
194
  return Promise.resolve(validator(changeSet)).then(function (errors) {
188
195
  if (errors && Object.keys(errors).length) {
@@ -191,7 +198,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
191
198
  });
192
199
  }
193
200
  }();
194
- return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); // send new data to the server
201
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); // send new data to the server
195
202
  }, function (error) {
196
203
  var _error$response;
197
204
  if (error instanceof ReferenceError || error instanceof TypeError || (error === null || error === void 0 ? void 0 : (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) >= 500) {
@@ -231,18 +238,18 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
231
238
  }, function () {
232
239
  return _exit;
233
240
  });
234
- return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function (_result3) {
241
+ return Promise.resolve(_temp7 && _temp7.then ? _temp7.then(function (_result3) {
235
242
  return _exit ? _result3 : completed;
236
- }) : _exit ? _temp9 : completed);
243
+ }) : _exit ? _temp7 : completed);
237
244
  } catch (e) {
238
245
  return Promise.reject(e);
239
246
  }
240
247
  };
241
248
  const onCellChanged = function (cell, rowIndex, shouldRunUpdaters = true) {
242
249
  try {
243
- function _temp6() {
250
+ function _temp4() {
244
251
  var _state$changes$errors11;
245
- function _temp4() {
252
+ function _temp2() {
246
253
  // only set errors and move reasons for the cells we're currently acting on
247
254
  // why? because the UX is not good if we set them for cells the user hasn't touched yet
248
255
  const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];
@@ -273,6 +280,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
273
280
  rowId: cell.row.id,
274
281
  payload: {
275
282
  cellErrors: nextCellErrors,
283
+ index: rowIndex,
276
284
  moveReasons: nextMoveReasons,
277
285
  value: nextChanges
278
286
  }
@@ -291,19 +299,19 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
291
299
  };
292
300
  // run validation
293
301
  let validationErrors = {};
294
- const _temp3 = function () {
302
+ const _temp = function () {
295
303
  if (validator) {
296
304
  const nextRowValue = {
297
305
  ...state.changes.originals[cell.row.id],
298
306
  ...changes,
299
307
  ...updatesForOtherCells
300
308
  };
301
- return Promise.resolve(validator(nextRowValue)).then(function (_validator2) {
302
- validationErrors = _validator2 !== null && _validator2 !== void 0 ? _validator2 : {};
309
+ return Promise.resolve(validator(nextRowValue)).then(function (_validator) {
310
+ validationErrors = _validator !== null && _validator !== void 0 ? _validator : {};
303
311
  });
304
312
  }
305
313
  }();
306
- return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
314
+ return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
307
315
  }
308
316
  const changes = state.changes.rows[cell.row.id];
309
317
  if (!changes) {
@@ -311,7 +319,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
311
319
  }
312
320
  let updatesForOtherCells = {};
313
321
  // run the updater handler if there is one, to see if there are any other cells to update
314
- const _temp5 = function () {
322
+ const _temp3 = function () {
315
323
  if (typeof handleChange === 'function' && shouldRunUpdaters) {
316
324
  const previousRowValue = {
317
325
  ...state.changes.originals[cell.row.id]
@@ -325,42 +333,11 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
325
333
  });
326
334
  }
327
335
  }();
328
- return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
336
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3));
329
337
  } catch (e) {
330
338
  return Promise.reject(e);
331
339
  }
332
340
  }; // general
333
- // rows
334
- const setRowValue = function (rowId, original, value) {
335
- try {
336
- function _temp2() {
337
- dispatch({
338
- type: 'updateRow',
339
- rowId,
340
- payload: {
341
- cellErrors,
342
- original,
343
- value
344
- }
345
- });
346
- }
347
- let cellErrors;
348
- const _temp = function () {
349
- if (validator) {
350
- const row = {
351
- ...original,
352
- ...value
353
- };
354
- return Promise.resolve(validator(row)).then(function (_validator) {
355
- cellErrors = _validator !== null && _validator !== void 0 ? _validator : {};
356
- });
357
- }
358
- }();
359
- return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
360
- } catch (e) {
361
- return Promise.reject(e);
362
- }
363
- };
364
341
  const localization = useLocalization();
365
342
  const [state, dispatch] = React__default.useReducer(reducer, {
366
343
  changes: {
@@ -370,8 +347,10 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
370
347
  originals: {},
371
348
  status: {}
372
349
  },
350
+ indexes: {},
373
351
  temporaryRows: []
374
352
  });
353
+ // rows
375
354
  function getRowValue(rowId) {
376
355
  var _state$changes$rows$r, _state$changes$rows;
377
356
  return (_state$changes$rows$r = (_state$changes$rows = state.changes.rows) === null || _state$changes$rows === void 0 ? void 0 : _state$changes$rows[rowId]) !== null && _state$changes$rows$r !== void 0 ? _state$changes$rows$r : undefined;
@@ -409,7 +388,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
409
388
  }
410
389
  });
411
390
  }
412
- function insertTemporaryRow(data) {
391
+ function insertTemporaryRow(data, rowIndex) {
413
392
  const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${v4()}`;
414
393
  const value = {
415
394
  ...data,
@@ -419,13 +398,14 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
419
398
  type: 'insertTemporaryRow',
420
399
  rowId: newRowId,
421
400
  payload: {
401
+ index: rowIndex,
422
402
  value
423
403
  }
424
404
  });
425
405
  return newRowId;
426
406
  }
427
407
  // cells
428
- function setCellValue(cell, value) {
408
+ function setCellValue(cell, rowIndex, value) {
429
409
  const rowId = cell.row.id;
430
410
  const columnId = cell.column.id;
431
411
  // update if the change is different to the original value
@@ -435,6 +415,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
435
415
  rowId,
436
416
  payload: {
437
417
  columnId,
418
+ index: rowIndex,
438
419
  row: cell.row.original,
439
420
  value
440
421
  }
@@ -467,6 +448,7 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
467
448
  }
468
449
  return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({
469
450
  rowId,
451
+ index: state.indexes[rowId],
470
452
  changes: state.changes.rows[rowId],
471
453
  errors: state.changes.errors[rowId]
472
454
  }));
@@ -490,7 +472,6 @@ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, v
490
472
  }
491
473
  return {
492
474
  // row
493
- setRowValue,
494
475
  getRowValue,
495
476
  getRowMoveReason,
496
477
  hasRowErrors,
@@ -1 +1 @@
1
- {"version":3,"file":"useEditingState.js","sources":["../../../../../../../../src/components/Table3/features/useEditingState.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, Cell as ReactTableCell } from '@tanstack/react-table';\nimport { v4 as uuid } from 'uuid';\nimport omit from 'lodash/omit';\nimport setWith from 'lodash/setWith';\nimport { Table3EditingChangeHandler, Table3EditingSaveHandler, Table3EditingValidatorFn } from '../types';\nimport { isTemporaryRow, TEMPORARY_ROW_ID_PREFIX, willRowMove } from '../util/editing';\nimport { useLocalization } from '../../Provider/Localization';\n\nconst DELAY_BEFORE_REMOVING_SAVE_STATUS = 3000;\n\ntype EditingError = {\n row: string;\n cells: Record<string, string>;\n shouldShowErrorAlert: boolean;\n};\ntype EditingRowMoveReason = Record<string, 'search' | 'sorting' | 'filter'>;\ntype EditingSaveState = 'saving' | 'saved' | 'errored';\ntype EditingChangeset<TType = unknown> = Partial<TType>;\ntype EditingState<TType = unknown> = {\n changes: {\n rows: Record<string, EditingChangeset<TType>>;\n errors: Record<string, EditingError>;\n moveReasons: Record<string, EditingRowMoveReason>;\n originals: Record<string, TType>;\n status: Record<string, EditingSaveState>;\n };\n temporaryRows: TType[];\n};\ntype EditingStateAction = {\n type:\n | 'setCellValue'\n | 'removeCellValue'\n | 'updateRow'\n | 'mergeRowValue'\n | 'removeRow'\n | 'setRowStatus'\n | 'setRowErrors'\n | 'insertTemporaryRow';\n rowId: string;\n payload?: any;\n};\n\nfunction reducer<TType = unknown>(state: EditingState<TType>, action: EditingStateAction) {\n const { type, rowId, payload } = action;\n\n switch (type) {\n case 'setCellValue': {\n const { columnId, row, value } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),\n originals: setWith(state.changes.originals, rowId, row, Object),\n },\n };\n }\n\n case 'removeCellValue': {\n const { columnId, rowIdentityAccessor } = payload;\n const changes = omit(state.changes.rows, `${rowId}.${columnId}`);\n\n // if there are no changes left, remove the row\n if (!Object.keys(changes[rowId]).length) {\n return reducer(state, { type: 'removeRow', rowId, payload: { rowIdentityAccessor } });\n }\n\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: omit(state.changes.rows, `${rowId}.${columnId}`),\n errors: omit(state.changes.errors, `${rowId}.cells.${columnId}`),\n moveReasons: omit(state.changes.moveReasons, `${rowId}.${columnId}`),\n },\n };\n }\n\n case 'updateRow': {\n const { cellErrors, moveReasons, original, value } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: setWith(state.changes.rows, rowId, value, Object),\n errors: setWith(\n state.changes.errors,\n `${rowId}.cells`,\n cellErrors ?? state.changes.errors.cells[rowId],\n Object\n ),\n originals: setWith(state.changes.originals, rowId, original ?? state.changes.originals[rowId], Object),\n moveReasons: setWith(\n state.changes.moveReasons,\n rowId,\n moveReasons ?? state.changes.moveReasons[rowId],\n Object\n ),\n // status can be undefined, so don't use ??\n status: setWith(state.changes.status, rowId, undefined, Object),\n },\n };\n }\n\n case 'removeRow': {\n const { rowIdentityAccessor } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: omit(state.changes.rows, rowId),\n errors: omit(state.changes.errors, rowId),\n moveReasons: omit(state.changes.moveReasons, rowId),\n originals: omit(state.changes.originals, rowId),\n status: omit(state.changes.status, rowId),\n },\n temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId),\n };\n }\n\n case 'setRowStatus': {\n const { status } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n status: status ? setWith(state.changes.status, rowId, status, Object) : omit(state.changes.status, rowId),\n },\n };\n }\n\n case 'setRowErrors': {\n const { ...errors } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n errors: setWith(state.changes.errors, rowId, errors, Object),\n },\n };\n }\n\n case 'insertTemporaryRow': {\n const { value } = payload;\n return {\n ...state,\n temporaryRows: state.temporaryRows.concat(value),\n changes: {\n ...state.changes,\n rows: setWith(state.changes.rows, rowId, value, Object),\n originals: setWith(state.changes.originals, rowId, value, Object),\n },\n };\n }\n\n default:\n return state;\n }\n}\n\nexport function usePendingChangesState<TType = unknown>(\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n handleChange: Table3EditingChangeHandler<TType> | undefined,\n rowIdentityAccessor: keyof TType,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n const localization = useLocalization();\n const [state, dispatch] = React.useReducer(reducer, {\n changes: { rows: {}, errors: {}, moveReasons: {}, originals: {}, status: {} },\n temporaryRows: [],\n });\n\n // rows\n async function setRowValue<T extends TType>(rowId: string, original: T, value: Partial<T>) {\n let cellErrors;\n\n if (validator) {\n const row = { ...original, ...value } as T;\n cellErrors = ((await validator(row)) ?? {}) as Record<string, string>;\n }\n\n dispatch({\n type: 'updateRow',\n rowId,\n payload: { cellErrors, original, value },\n });\n }\n\n function getRowValue(rowId: string) {\n return state.changes.rows?.[rowId] ?? undefined;\n }\n\n function getRowMoveReason(rowId: string) {\n return Object.values(state.changes.moveReasons?.[rowId] ?? {})[0] ?? undefined;\n }\n\n function hasRowErrors(rowId: string) {\n return !!state.changes.errors[rowId]?.row || !!Object.keys(state.changes.errors[rowId]?.cells ?? {}).length;\n }\n\n function hasRowErrorsShownInAlert(rowId: string) {\n return hasRowErrors(rowId) && !!state.changes.errors[rowId]?.shouldShowErrorAlert;\n }\n\n function hasTemporaryRowErrors<T extends TType>() {\n const newRow = state.temporaryRows?.[0] as T | undefined;\n\n if (!newRow) {\n return false;\n }\n\n const rowId = newRow[rowIdentityAccessor as string];\n return !!state.changes.errors[rowId]?.row || !!Object.keys(state.changes.errors[rowId]?.cells ?? {}).length;\n }\n\n function getRowStatus(rowId: string) {\n return state.changes.status[rowId];\n }\n\n function setRowStatus(rowId: string, status: EditingSaveState | undefined) {\n dispatch({\n type: 'setRowStatus',\n rowId,\n payload: {\n status,\n },\n });\n }\n\n function insertTemporaryRow<T extends TType>(data: Partial<T>) {\n const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${uuid()}`;\n const value: Partial<TType> = {\n ...data,\n [rowIdentityAccessor]: newRowId,\n };\n\n dispatch({\n type: 'insertTemporaryRow',\n rowId: newRowId,\n payload: { value },\n });\n\n return newRowId;\n }\n\n // cells\n function setCellValue<T extends TType>(cell: ReactTableCell<T, unknown>, value: unknown) {\n const rowId = cell.row.id;\n const columnId = cell.column.id;\n\n // update if the change is different to the original value\n if (value !== cell.row.original[columnId]) {\n dispatch({\n type: 'setCellValue',\n rowId,\n payload: {\n columnId,\n row: cell.row.original,\n value,\n },\n });\n }\n // otherwise remove any previous change - no point saving the same value\n else if (cell.row.id in state.changes.rows) {\n dispatch({\n type: 'removeCellValue',\n rowId,\n payload: {\n columnId,\n rowIdentityAccessor,\n },\n });\n }\n }\n\n function getCellValue<T extends TType>(cell: ReactTableCell<T, unknown>): unknown | undefined {\n return state.changes.rows?.[cell.row.id]?.[cell.column.id];\n }\n\n function getCellError<T extends TType>(cell: ReactTableCell<T, unknown>): string | undefined {\n return state.changes.errors?.[cell.row.id]?.cells?.[cell.column.id];\n }\n\n async function onCellChanged<T extends TType>(cell: ReactTableCell<T, unknown>, rowIndex: number, shouldRunUpdaters = true) {\n const changes = state.changes.rows[cell.row.id];\n\n if (!changes) {\n return;\n }\n\n let updatesForOtherCells: Partial<T> = {};\n\n // run the updater handler if there is one, to see if there are any other cells to update\n if (typeof handleChange === 'function' && shouldRunUpdaters) {\n const previousRowValue = {\n ...state.changes.originals[cell.row.id],\n //...getRowChangeset(updatersRef.current[cell.row.id], rowIdentityAccessor),\n };\n const nextRowValue = {\n ...state.changes.originals[cell.row.id],\n ...changes,\n };\n updatesForOtherCells = ((await handleChange(\n cell.column.id,\n changes[cell.column.id],\n nextRowValue,\n previousRowValue\n )) ?? {}) as Partial<T>;\n }\n\n // create a projection of the next state, so we can act against it\n const nextChanges = { ...state.changes.rows[cell.row.id], ...updatesForOtherCells };\n const nextMoveReasons: EditingRowMoveReason = { ...state.changes.moveReasons[cell.row.id] };\n const nextCellErrors: Record<string, string> = { ...state.changes.errors[cell.row.id]?.cells };\n\n // run validation\n let validationErrors: Record<string, string> = {};\n\n if (validator) {\n const nextRowValue = { ...state.changes.originals[cell.row.id], ...changes, ...updatesForOtherCells };\n validationErrors = ((await validator(nextRowValue)) ?? {}) as Record<string, string>;\n }\n\n // only set errors and move reasons for the cells we're currently acting on\n // why? because the UX is not good if we set them for cells the user hasn't touched yet\n const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];\n const allCells = cell.row._getAllCellsByColumnId();\n\n cellsToActOn.forEach(accessor => {\n if (validationErrors[accessor]) {\n nextCellErrors[accessor] = validationErrors[accessor];\n // don't show move indicator for cells with errors, they aren't valid and can't be saved\n delete nextMoveReasons[accessor];\n } else {\n // there isn't any error in this run, remove any error set in state\n delete nextCellErrors[accessor];\n\n if (allCells[accessor]?.column.getIsSorted()) {\n // run row move determination\n const reason = willRowMove(cell, nextChanges[accessor], rowIndex, localization);\n\n // if the row will move based on this change save why, otherwise delete any existing state\n if (reason) {\n nextMoveReasons[accessor] = reason;\n } else {\n delete nextMoveReasons[accessor];\n }\n }\n }\n });\n\n dispatch({\n type: 'updateRow',\n rowId: cell.row.id,\n payload: {\n cellErrors: nextCellErrors,\n moveReasons: nextMoveReasons,\n value: nextChanges,\n },\n });\n }\n\n // general\n function getErrorsShownInAlert<T extends TType>() {\n const rowsWithErrors = Object.keys(state.changes.errors);\n\n if (!rowsWithErrors.length) {\n return [];\n }\n\n return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({\n rowId,\n changes: state.changes.rows[rowId] as EditingChangeset<T>,\n errors: state.changes.errors[rowId],\n }));\n }\n\n function hasSaved() {\n return !!Object.values(state.changes.status).filter(value => value === 'saved').length;\n }\n\n function hasChanges(rowId?: string) {\n return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;\n }\n\n async function saveChanges<T extends TType>(table: ReactTable<T>, rowId: string | undefined = undefined): Promise<boolean> {\n if (!handleSave) {\n console.warn('Tried to save, but Table has no onEditingSave handler');\n return false;\n }\n\n // sometimes we only want to save one row\n const changes = rowId ? { [rowId]: state.changes.rows[rowId] } : state.changes.rows;\n\n let completed = true;\n\n for (const rowId of Object.keys(changes)) {\n const status = getRowStatus(rowId);\n\n try {\n // don't try to save if - already saving, or there are known errors\n if (status === 'saving' || status === 'errored') {\n continue;\n }\n\n setRowStatus(rowId, 'saving');\n\n const changeSet = { ...state.changes.originals[rowId], ...changes[rowId] };\n\n // if we had to create a temporary id, delete it first - it's our data, not theirs\n if (isTemporaryRow(changeSet[rowIdentityAccessor as string])) {\n delete changeSet[rowIdentityAccessor];\n }\n\n // re-run validation, maybe a cell is already invalid but has never been blurred\n if (validator) {\n const errors = await validator(changeSet);\n\n if (errors && Object.keys(errors).length) {\n throw errors;\n }\n }\n\n // send new data to the server\n await handleSave(changeSet);\n\n // cleanup changes, we don't need them after saving\n discardChanges(rowId, table);\n\n // show the saved status, then remove it after a delay\n setRowStatus(rowId, 'saved');\n setTimeout(() => {\n setRowStatus(rowId, undefined);\n }, DELAY_BEFORE_REMOVING_SAVE_STATUS);\n } catch (error) {\n if (error instanceof ReferenceError || error instanceof TypeError || (error as any)?.response?.status >= 500) {\n console.error(error);\n }\n\n // the onEditingSave handler should throw errors when something fails, e.g. validation, network errors etc\n // this code handles those errors and maps them either to row errors or cell specific errors\n let rowError: string | undefined;\n let cellErrors;\n\n if (typeof error === 'string') {\n rowError = error;\n } else if (error instanceof Error) {\n rowError = error.message;\n\n // most of our apis return error objects within this shape\n if (typeof (error as any).response?.data === 'object') {\n cellErrors = (error as any).response?.data;\n }\n } else if (typeof error === 'object') {\n cellErrors = error;\n }\n\n if (rowError || cellErrors) {\n dispatch({\n type: 'setRowErrors',\n rowId,\n payload: {\n row: rowError,\n cells: cellErrors,\n shouldShowErrorAlert: true,\n },\n });\n }\n\n setRowStatus(rowId, 'errored');\n completed = false;\n }\n }\n\n return completed;\n }\n\n function discardChanges<T extends TType>(rowId: string, table: ReactTable<T>) {\n // remove any new rows from pinned state before discarding them\n table.resetRowPinning(true);\n\n dispatch({\n type: 'removeRow',\n rowId,\n payload: { rowIdentityAccessor },\n });\n }\n\n return {\n // row\n setRowValue,\n getRowValue,\n getRowMoveReason,\n hasRowErrors,\n hasRowErrorsShownInAlert,\n hasTemporaryRowErrors,\n getRowStatus,\n setRowStatus,\n // cells\n setCellValue,\n getCellValue,\n getCellError,\n onCellChanged,\n // general\n getErrorsShownInAlert,\n hasChanges,\n saveChanges,\n discardChanges,\n hasSaved,\n // new rows\n insertTemporaryRow,\n temporaryRows: state.temporaryRows,\n };\n}\n"],"names":["DELAY_BEFORE_REMOVING_SAVE_STATUS","reducer","state","action","type","rowId","payload","columnId","row","value","changes","rows","setWith","Object","originals","rowIdentityAccessor","omit","keys","length","errors","moveReasons","cellErrors","original","cells","status","undefined","temporaryRows","filter","concat","usePendingChangesState","handleSave","handleChange","validator","saveChanges","table","console","warn","Promise","resolve","completed","_temp9","_forOf","getRowStatus","_catch","_temp8","_result","_exit","changeSet","then","discardChanges","setRowStatus","setTimeout","isTemporaryRow","_temp7","error","_error$response","ReferenceError","TypeError","response","rowError","Error","_error$response2","message","data","_error$response3","dispatch","shouldShowErrorAlert","_result3","e","reject","onCellChanged","cell","rowIndex","shouldRunUpdaters","cellsToActOn","column","id","updatesForOtherCells","allCells","_getAllCellsByColumnId","forEach","accessor","validationErrors","nextCellErrors","nextMoveReasons","_allCells$accessor","getIsSorted","reason","willRowMove","nextChanges","localization","_state$changes$errors11","_temp3","nextRowValue","_validator2","_temp4","_temp5","previousRowValue","_handleChange","_temp6","setRowValue","_temp","_validator","_temp2","useLocalization","React","useReducer","getRowValue","_state$changes$rows$r","_state$changes$rows","getRowMoveReason","_Object$values$","values","_state$changes$moveRe","_state$changes$moveRe2","hasRowErrors","_state$changes$errors","_state$changes$errors2","_state$changes$errors3","hasRowErrorsShownInAlert","_state$changes$errors4","hasTemporaryRowErrors","newRow","_state$temporaryRows","_state$changes$errors5","_state$changes$errors6","_state$changes$errors7","insertTemporaryRow","newRowId","TEMPORARY_ROW_ID_PREFIX","uuid","setCellValue","getCellValue","_state$changes$rows2","_state$changes$rows2$","getCellError","_state$changes$errors8","_state$changes$errors9","_state$changes$errors10","getErrorsShownInAlert","rowsWithErrors","map","hasSaved","hasChanges","resetRowPinning"],"mappings":";;;;;;;;AASA,MAAMA,iCAAiC,GAAG,IAAI;AAkC9C,SAASC,OAAOA,CAAkBC,KAA0B,EAAEC,MAA0B;EACpF,MAAM;IAAEC,IAAI;IAAEC,KAAK;IAAEC;GAAS,GAAGH,MAAM;EAEvC,QAAQC,IAAI;IACR,KAAK,cAAc;MAAE;QACjB,MAAM;UAAEG,QAAQ;UAAEC,GAAG;UAAEC;SAAO,GAAGH,OAAO;QACxC,OAAO;UACH,GAAGJ,KAAK;UACRQ,OAAO,EAAE;YACL,GAAGR,KAAK,CAACQ,OAAO;YAChBC,IAAI,EAAEC,OAAO,CAACV,KAAK,CAACQ,OAAO,CAACC,IAAI,EAAE,GAAGN,KAAK,IAAIE,QAAQ,EAAE,EAAEE,KAAK,EAAEI,MAAM,CAAC;YACxEC,SAAS,EAAEF,OAAO,CAACV,KAAK,CAACQ,OAAO,CAACI,SAAS,EAAET,KAAK,EAAEG,GAAG,EAAEK,MAAM;;SAErE;;IAGL,KAAK,iBAAiB;MAAE;QACpB,MAAM;UAAEN,QAAQ;UAAEQ;SAAqB,GAAGT,OAAO;QACjD,MAAMI,OAAO,GAAGM,IAAI,CAACd,KAAK,CAACQ,OAAO,CAACC,IAAI,EAAE,GAAGN,KAAK,IAAIE,QAAQ,EAAE,CAAC;;QAGhE,IAAI,CAACM,MAAM,CAACI,IAAI,CAACP,OAAO,CAACL,KAAK,CAAC,CAAC,CAACa,MAAM,EAAE;UACrC,OAAOjB,OAAO,CAACC,KAAK,EAAE;YAAEE,IAAI,EAAE,WAAW;YAAEC,KAAK;YAAEC,OAAO,EAAE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G1F,SAAS6H,UAAUA,CAAC1I,KAAc;IAC9B,OAAOA,KAAK,GAAG,CAAC,CAACH,KAAK,CAACQ,OAAO,CAACC,IAAI,CAACN,KAAK,CAAC,GAAG,CAAC,CAACQ,MAAM,CAACI,IAAI,CAACf,KAAK,CAACQ,OAAO,CAACC,IAAI,CAAC,CAACO,MAAM;;EA+FzF,SAAS+B,cAAcA,CAAkB5C,KAAa,EAAE6B,KAAoB;;IAExEA,KAAK,CAAC8G,eAAe,CAAC,IAAI,CAAC;IAE3B/E,QAAQ,CAAC;MACL7D,IAAI,EAAE,WAAW;MACjBC,KAAK;MACLC,OAAO,EAAE;QAAES;;KACd,CAAC;;EAGN,OAAO;;IAEHqF,WAAW;IACXO,WAAW;IACXG,gBAAgB;IAChBK,YAAY;IACZI,wBAAwB;IACxBE,qBAAqB;IACrB/E,YAAY;IACZQ,YAAY;;IAEZiF,YAAY;IACZC,YAAY;IACZG,YAAY;IACZjE,aAAa;;IAEbqE,qBAAqB;IACrBI,UAAU;IACV9G,WAAW;IACXgB,cAAc;IACd6F,QAAQ;;IAERf,kBAAkB;IAClBrG,aAAa,EAAExB,KAAK,CAACwB;GACxB;AACL;;;;"}
1
+ {"version":3,"file":"useEditingState.js","sources":["../../../../../../../../src/components/Table3/features/useEditingState.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, Cell as ReactTableCell } from '@tanstack/react-table';\nimport { v4 as uuid } from 'uuid';\nimport omit from 'lodash/omit';\nimport setWith from 'lodash/setWith';\nimport { Table3EditingChangeHandler, Table3EditingSaveHandler, Table3EditingValidatorFn } from '../types';\nimport { isTemporaryRow, TEMPORARY_ROW_ID_PREFIX, willRowMove } from '../util/editing';\nimport { useLocalization } from '../../Provider/Localization';\n\nconst DELAY_BEFORE_REMOVING_SAVE_STATUS = 3000;\n\ntype EditingError = {\n row: string;\n cells: Record<string, string>;\n shouldShowErrorAlert: boolean;\n};\ntype EditingRowMoveReason = Record<string, 'search' | 'sorting' | 'filter'>;\ntype EditingSaveState = 'saving' | 'saved' | 'errored';\ntype EditingChangeset<TType = unknown> = Partial<TType>;\ntype EditingState<TType = unknown> = {\n changes: {\n rows: Record<string, EditingChangeset<TType>>;\n errors: Record<string, EditingError>;\n moveReasons: Record<string, EditingRowMoveReason>;\n originals: Record<string, TType>;\n status: Record<string, EditingSaveState>;\n };\n indexes: Record<string, number>;\n temporaryRows: TType[];\n};\ntype EditingStateAction = {\n type:\n | 'setCellValue'\n | 'removeCellValue'\n | 'updateRow'\n | 'mergeRowValue'\n | 'removeRow'\n | 'setRowStatus'\n | 'setRowErrors'\n | 'insertTemporaryRow';\n rowId: string;\n payload?: any;\n};\n\nfunction reducer<TType = unknown>(state: EditingState<TType>, action: EditingStateAction) {\n const { type, rowId, payload } = action;\n\n switch (type) {\n case 'setCellValue': {\n const { columnId, index, row, value } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),\n originals: setWith(state.changes.originals, rowId, row, Object),\n },\n indexes: setWith(state.indexes, rowId, index, Object),\n };\n }\n\n case 'removeCellValue': {\n const { columnId, rowIdentityAccessor } = payload;\n const changes = omit(state.changes.rows, `${rowId}.${columnId}`);\n\n // if there are no changes left, remove the row\n if (!Object.keys(changes[rowId]).length) {\n return reducer(state, { type: 'removeRow', rowId, payload: { rowIdentityAccessor } });\n }\n\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: omit(state.changes.rows, `${rowId}.${columnId}`),\n errors: omit(state.changes.errors, `${rowId}.cells.${columnId}`),\n moveReasons: omit(state.changes.moveReasons, `${rowId}.${columnId}`),\n },\n };\n }\n\n case 'updateRow': {\n const { cellErrors, index, moveReasons, original, value } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: setWith(state.changes.rows, rowId, value, Object),\n errors: setWith(\n state.changes.errors,\n `${rowId}.cells`,\n cellErrors ?? state.changes.errors.cells[rowId],\n Object\n ),\n originals: setWith(state.changes.originals, rowId, original ?? state.changes.originals[rowId], Object),\n moveReasons: setWith(\n state.changes.moveReasons,\n rowId,\n moveReasons ?? state.changes.moveReasons[rowId],\n Object\n ),\n // status can be undefined, so don't use ??\n status: setWith(state.changes.status, rowId, undefined, Object),\n },\n indexes: setWith(state.indexes, rowId, index, Object),\n };\n }\n\n case 'removeRow': {\n const { rowIdentityAccessor } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n rows: omit(state.changes.rows, rowId),\n errors: omit(state.changes.errors, rowId),\n moveReasons: omit(state.changes.moveReasons, rowId),\n originals: omit(state.changes.originals, rowId),\n status: omit(state.changes.status, rowId),\n },\n indexes: omit(state.indexes, rowId),\n temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId),\n };\n }\n\n case 'setRowStatus': {\n const { status } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n status: status ? setWith(state.changes.status, rowId, status, Object) : omit(state.changes.status, rowId),\n },\n };\n }\n\n case 'setRowErrors': {\n const { ...errors } = payload;\n return {\n ...state,\n changes: {\n ...state.changes,\n errors: setWith(state.changes.errors, rowId, errors, Object),\n },\n };\n }\n\n case 'insertTemporaryRow': {\n const { index, value } = payload;\n return {\n ...state,\n temporaryRows: state.temporaryRows.concat(value),\n changes: {\n ...state.changes,\n rows: setWith(state.changes.rows, rowId, value, Object),\n originals: setWith(state.changes.originals, rowId, value, Object),\n },\n indexes: setWith(state.indexes, rowId, index, Object),\n };\n }\n\n default:\n return state;\n }\n}\n\nexport function usePendingChangesState<TType = unknown>(\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n handleChange: Table3EditingChangeHandler<TType> | undefined,\n rowIdentityAccessor: keyof TType,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n const localization = useLocalization();\n const [state, dispatch] = React.useReducer(reducer, {\n changes: { rows: {}, errors: {}, moveReasons: {}, originals: {}, status: {} },\n indexes: {},\n temporaryRows: [],\n });\n\n // rows\n function getRowValue(rowId: string) {\n return state.changes.rows?.[rowId] ?? undefined;\n }\n\n function getRowMoveReason(rowId: string) {\n return Object.values(state.changes.moveReasons?.[rowId] ?? {})[0] ?? undefined;\n }\n\n function hasRowErrors(rowId: string) {\n return !!state.changes.errors[rowId]?.row || !!Object.keys(state.changes.errors[rowId]?.cells ?? {}).length;\n }\n\n function hasRowErrorsShownInAlert(rowId: string) {\n return hasRowErrors(rowId) && !!state.changes.errors[rowId]?.shouldShowErrorAlert;\n }\n\n function hasTemporaryRowErrors<T extends TType>() {\n const newRow = state.temporaryRows?.[0] as T | undefined;\n\n if (!newRow) {\n return false;\n }\n\n const rowId = newRow[rowIdentityAccessor as string];\n return !!state.changes.errors[rowId]?.row || !!Object.keys(state.changes.errors[rowId]?.cells ?? {}).length;\n }\n\n function getRowStatus(rowId: string) {\n return state.changes.status[rowId];\n }\n\n function setRowStatus(rowId: string, status: EditingSaveState | undefined) {\n dispatch({\n type: 'setRowStatus',\n rowId,\n payload: {\n status,\n },\n });\n }\n\n function insertTemporaryRow<T extends TType>(data: Partial<T>, rowIndex: number) {\n const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${uuid()}`;\n const value: Partial<TType> = {\n ...data,\n [rowIdentityAccessor]: newRowId,\n };\n\n dispatch({\n type: 'insertTemporaryRow',\n rowId: newRowId,\n payload: { index: rowIndex, value },\n });\n\n return newRowId;\n }\n\n // cells\n function setCellValue<T extends TType>(cell: ReactTableCell<T, unknown>, rowIndex: number, value: unknown) {\n const rowId = cell.row.id;\n const columnId = cell.column.id;\n\n // update if the change is different to the original value\n if (value !== cell.row.original[columnId]) {\n dispatch({\n type: 'setCellValue',\n rowId,\n payload: {\n columnId,\n index: rowIndex,\n row: cell.row.original,\n value,\n },\n });\n }\n // otherwise remove any previous change - no point saving the same value\n else if (cell.row.id in state.changes.rows) {\n dispatch({\n type: 'removeCellValue',\n rowId,\n payload: {\n columnId,\n rowIdentityAccessor,\n },\n });\n }\n }\n\n function getCellValue<T extends TType>(cell: ReactTableCell<T, unknown>): unknown | undefined {\n return state.changes.rows?.[cell.row.id]?.[cell.column.id];\n }\n\n function getCellError<T extends TType>(cell: ReactTableCell<T, unknown>): string | undefined {\n return state.changes.errors?.[cell.row.id]?.cells?.[cell.column.id];\n }\n\n async function onCellChanged<T extends TType>(cell: ReactTableCell<T, unknown>, rowIndex: number, shouldRunUpdaters = true) {\n const changes = state.changes.rows[cell.row.id];\n\n if (!changes) {\n return;\n }\n\n let updatesForOtherCells: Partial<T> = {};\n\n // run the updater handler if there is one, to see if there are any other cells to update\n if (typeof handleChange === 'function' && shouldRunUpdaters) {\n const previousRowValue = {\n ...state.changes.originals[cell.row.id],\n //...getRowChangeset(updatersRef.current[cell.row.id], rowIdentityAccessor),\n };\n const nextRowValue = {\n ...state.changes.originals[cell.row.id],\n ...changes,\n };\n updatesForOtherCells = ((await handleChange(\n cell.column.id,\n changes[cell.column.id],\n nextRowValue,\n previousRowValue\n )) ?? {}) as Partial<T>;\n }\n\n // create a projection of the next state, so we can act against it\n const nextChanges = { ...state.changes.rows[cell.row.id], ...updatesForOtherCells };\n const nextMoveReasons: EditingRowMoveReason = { ...state.changes.moveReasons[cell.row.id] };\n const nextCellErrors: Record<string, string> = { ...state.changes.errors[cell.row.id]?.cells };\n\n // run validation\n let validationErrors: Record<string, string> = {};\n\n if (validator) {\n const nextRowValue = { ...state.changes.originals[cell.row.id], ...changes, ...updatesForOtherCells };\n validationErrors = ((await validator(nextRowValue)) ?? {}) as Record<string, string>;\n }\n\n // only set errors and move reasons for the cells we're currently acting on\n // why? because the UX is not good if we set them for cells the user hasn't touched yet\n const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];\n const allCells = cell.row._getAllCellsByColumnId();\n\n cellsToActOn.forEach(accessor => {\n if (validationErrors[accessor]) {\n nextCellErrors[accessor] = validationErrors[accessor];\n // don't show move indicator for cells with errors, they aren't valid and can't be saved\n delete nextMoveReasons[accessor];\n } else {\n // there isn't any error in this run, remove any error set in state\n delete nextCellErrors[accessor];\n\n if (allCells[accessor]?.column.getIsSorted()) {\n // run row move determination\n const reason = willRowMove(cell, nextChanges[accessor], rowIndex, localization);\n\n // if the row will move based on this change save why, otherwise delete any existing state\n if (reason) {\n nextMoveReasons[accessor] = reason;\n } else {\n delete nextMoveReasons[accessor];\n }\n }\n }\n });\n\n dispatch({\n type: 'updateRow',\n rowId: cell.row.id,\n payload: {\n cellErrors: nextCellErrors,\n index: rowIndex,\n moveReasons: nextMoveReasons,\n value: nextChanges,\n },\n });\n }\n\n // general\n function getErrorsShownInAlert<T extends TType>() {\n const rowsWithErrors = Object.keys(state.changes.errors);\n\n if (!rowsWithErrors.length) {\n return [];\n }\n\n return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({\n rowId,\n index: state.indexes[rowId],\n changes: state.changes.rows[rowId] as EditingChangeset<T>,\n errors: state.changes.errors[rowId],\n }));\n }\n\n function hasSaved() {\n return !!Object.values(state.changes.status).filter(value => value === 'saved').length;\n }\n\n function hasChanges(rowId?: string) {\n return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;\n }\n\n async function saveChanges<T extends TType>(table: ReactTable<T>, rowId: string | undefined = undefined): Promise<boolean> {\n if (!handleSave) {\n console.warn('Tried to save, but Table has no onEditingSave handler');\n return false;\n }\n\n // sometimes we only want to save one row\n const changes = rowId ? { [rowId]: state.changes.rows[rowId] } : state.changes.rows;\n\n let completed = true;\n\n for (const rowId of Object.keys(changes)) {\n const status = getRowStatus(rowId);\n\n try {\n // don't try to save if - already saving, or there are known errors\n if (status === 'saving' || status === 'errored') {\n continue;\n }\n\n setRowStatus(rowId, 'saving');\n\n const changeSet = { ...state.changes.originals[rowId], ...changes[rowId] };\n\n // if we had to create a temporary id, delete it first - it's our data, not theirs\n if (isTemporaryRow(changeSet[rowIdentityAccessor as string])) {\n delete changeSet[rowIdentityAccessor];\n }\n\n // re-run validation, maybe a cell is already invalid but has never been blurred\n if (validator) {\n const errors = await validator(changeSet);\n\n if (errors && Object.keys(errors).length) {\n throw errors;\n }\n }\n\n // send new data to the server\n await handleSave(changeSet);\n\n // cleanup changes, we don't need them after saving\n discardChanges(rowId, table);\n\n // show the saved status, then remove it after a delay\n setRowStatus(rowId, 'saved');\n setTimeout(() => {\n setRowStatus(rowId, undefined);\n }, DELAY_BEFORE_REMOVING_SAVE_STATUS);\n } catch (error) {\n if (error instanceof ReferenceError || error instanceof TypeError || (error as any)?.response?.status >= 500) {\n console.error(error);\n }\n\n // the onEditingSave handler should throw errors when something fails, e.g. validation, network errors etc\n // this code handles those errors and maps them either to row errors or cell specific errors\n let rowError: string | undefined;\n let cellErrors;\n\n if (typeof error === 'string') {\n rowError = error;\n } else if (error instanceof Error) {\n rowError = error.message;\n\n // most of our apis return error objects within this shape\n if (typeof (error as any).response?.data === 'object') {\n cellErrors = (error as any).response?.data;\n }\n } else if (typeof error === 'object') {\n cellErrors = error;\n }\n\n if (rowError || cellErrors) {\n dispatch({\n type: 'setRowErrors',\n rowId,\n payload: {\n row: rowError,\n cells: cellErrors,\n shouldShowErrorAlert: true,\n },\n });\n }\n\n setRowStatus(rowId, 'errored');\n completed = false;\n }\n }\n\n return completed;\n }\n\n function discardChanges<T extends TType>(rowId: string, table: ReactTable<T>) {\n // remove any new rows from pinned state before discarding them\n table.resetRowPinning(true);\n\n dispatch({\n type: 'removeRow',\n rowId,\n payload: { rowIdentityAccessor },\n });\n }\n\n return {\n // row\n getRowValue,\n getRowMoveReason,\n hasRowErrors,\n hasRowErrorsShownInAlert,\n hasTemporaryRowErrors,\n getRowStatus,\n setRowStatus,\n // cells\n setCellValue,\n getCellValue,\n getCellError,\n onCellChanged,\n // general\n getErrorsShownInAlert,\n hasChanges,\n saveChanges,\n discardChanges,\n hasSaved,\n // new rows\n insertTemporaryRow,\n temporaryRows: state.temporaryRows,\n };\n}\n"],"names":["DELAY_BEFORE_REMOVING_SAVE_STATUS","reducer","state","action","type","rowId","payload","columnId","index","row","value","changes","rows","setWith","Object","originals","indexes","rowIdentityAccessor","omit","keys","length","errors","moveReasons","cellErrors","original","cells","status","undefined","temporaryRows","filter","concat","usePendingChangesState","handleSave","handleChange","validator","saveChanges","table","console","warn","Promise","resolve","completed","_temp7","_forOf","getRowStatus","_catch","_temp6","_result","_exit","changeSet","then","discardChanges","setRowStatus","setTimeout","isTemporaryRow","_temp5","error","_error$response","ReferenceError","TypeError","response","rowError","Error","_error$response2","message","data","_error$response3","dispatch","shouldShowErrorAlert","_result3","e","reject","onCellChanged","cell","rowIndex","shouldRunUpdaters","cellsToActOn","column","id","updatesForOtherCells","allCells","_getAllCellsByColumnId","forEach","accessor","validationErrors","nextCellErrors","nextMoveReasons","_allCells$accessor","getIsSorted","reason","willRowMove","nextChanges","localization","_state$changes$errors11","_temp","nextRowValue","_validator","_temp2","_temp3","previousRowValue","_handleChange","_temp4","useLocalization","React","useReducer","getRowValue","_state$changes$rows$r","_state$changes$rows","getRowMoveReason","_Object$values$","values","_state$changes$moveRe","_state$changes$moveRe2","hasRowErrors","_state$changes$errors","_state$changes$errors2","_state$changes$errors3","hasRowErrorsShownInAlert","_state$changes$errors4","hasTemporaryRowErrors","newRow","_state$temporaryRows","_state$changes$errors5","_state$changes$errors6","_state$changes$errors7","insertTemporaryRow","newRowId","TEMPORARY_ROW_ID_PREFIX","uuid","setCellValue","getCellValue","_state$changes$rows2","_state$changes$rows2$","getCellError","_state$changes$errors8","_state$changes$errors9","_state$changes$errors10","getErrorsShownInAlert","rowsWithErrors","map","hasSaved","hasChanges","resetRowPinning"],"mappings":";;;;;;;;AASA,MAAMA,iCAAiC,GAAG,IAAI;AAmC9C,SAASC,OAAOA,CAAkBC,KAA0B,EAAEC,MAA0B;EACpF,MAAM;IAAEC,IAAI;IAAEC,KAAK;IAAEC;GAAS,GAAGH,MAAM;EAEvC,QAAQC,IAAI;IACR,KAAK,cAAc;MAAE;QACjB,MAAM;UAAEG,QAAQ;UAAEC,KAAK;UAAEC,GAAG;UAAEC;SAAO,GAAGJ,OAAO;QAC/C,OAAO;UACH,GAAGJ,KAAK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-16,11 +16,11 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCrea
16
16
  const changeset = row !== null && row !== void 0 ? row : handleCreate();
17
17
  try {
18
18
  if (changeset) {
19
- const rowId = pendingChangesFns.insertTemporaryRow(changeset);
20
- table.getRow(rowId).pin('bottom');
21
19
  // set the active row to the new row before toggling editing on
22
20
  const temporaryRows = tableMeta.editing.temporaryRows;
23
21
  const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;
22
+ const rowId = pendingChangesFns.insertTemporaryRow(changeset, nextRowIndex);
23
+ table.getRow(rowId).pin('bottom');
24
24
  tableMeta.rowActive.setRowActiveIndex(nextRowIndex);
25
25
  toggleEditing(true, table, scrollToIndex);
26
26
  setLastFocusedCellIndex(undefined);
@@ -58,7 +58,9 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, handleCrea
58
58
  tableMeta.rowActive.setRowActiveIndex(index);
59
59
  }
60
60
  setEditing(enabled);
61
- if (!isTemporaryRow((_table$getRowModel$ro = table.getRowModel().rows[index]) === null || _table$getRowModel$ro === void 0 ? void 0 : _table$getRowModel$ro.id)) {
61
+ const row = (_table$getRowModel$ro = table.getRowModel().rows[index]) === null || _table$getRowModel$ro === void 0 ? void 0 : _table$getRowModel$ro.id;
62
+ if (row && !isTemporaryRow(row)) {
63
+ console.log('hmm');
62
64
  scrollToIndex(index);
63
65
  }
64
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useTableEditing.js","sources":["../../../../../../../../src/components/Table3/features/useTableEditing.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {\n Table3EditingChangeHandler,\n Table3EditingCreateHandler,\n Table3EditingSaveHandler,\n Table3EditingValidatorFn,\n} from '../types';\nimport { usePendingChangesState } from './useEditingState';\nimport { isTemporaryRow } from '../util/editing';\n\nexport function useTableEditing<TType = unknown>(\n isEnabled = false,\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n handleChange: Table3EditingChangeHandler<TType> | undefined,\n handleCreate: Table3EditingCreateHandler<TType> | undefined,\n rowIdentityAccessor: keyof TType | undefined,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n // used to switch the table into editing mode\n const [isEditing, setEditing] = React.useState(false);\n\n // used to switch the editing between \"detailed\" mode\n const [isDetailedMode, toggleDetailedMode] = React.useState(false);\n\n // used to contain ref to the create button\n const createRowButtonRef = React.useRef<HTMLButtonElement>(null);\n\n // store the last focused cell, so that up/down arrow key navigation remains in the same column\n const [lastFocusedCellIndex, setLastFocusedCellIndex] = React.useState<number | undefined>(undefined);\n\n const pendingChangesFns = usePendingChangesState<TType>(\n handleSave,\n handleChange,\n rowIdentityAccessor as keyof TType,\n validator\n );\n\n function toggleEditing<T extends TType>(\n enabled: React.SetStateAction<boolean>,\n table: ReactTable<T>,\n scrollToIndex: (index: number) => void\n ) {\n if (!enabled) {\n // save\n pendingChangesFns.saveChanges(table);\n // reset detailed mode\n toggleDetailedMode(false);\n // reset the last index back to the first focusable element, when editing gets turned off\n setLastFocusedCellIndex(undefined);\n }\n\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const index = tableMeta.rowActive.rowActiveIndex ?? 0;\n\n if (tableMeta.rowActive.rowActiveIndex === undefined) {\n tableMeta.rowActive.setRowActiveIndex(index);\n }\n\n setEditing(enabled);\n\n if (!isTemporaryRow(table.getRowModel().rows[index]?.id)) {\n scrollToIndex(index);\n }\n }\n\n async function createRow<T extends TType>(table: ReactTable<T>, scrollToIndex: (index: number) => void, row?: Partial<T>) {\n if (!handleCreate) {\n return;\n }\n\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const saved = await tableMeta.editing.saveChanges(table);\n\n if (!saved) {\n return;\n }\n\n const changeset = row ?? handleCreate();\n\n try {\n if (changeset) {\n const rowId = pendingChangesFns.insertTemporaryRow(changeset);\n table.getRow(rowId).pin('bottom');\n\n // set the active row to the new row before toggling editing on\n const temporaryRows = tableMeta.editing.temporaryRows as TType[];\n const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;\n tableMeta.rowActive.setRowActiveIndex(nextRowIndex);\n\n toggleEditing(true, table, scrollToIndex);\n setLastFocusedCellIndex(undefined);\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n return {\n isEnabled,\n isEditing,\n isDetailedMode,\n toggleDetailedMode: isEnabled ? toggleDetailedMode : () => undefined,\n toggleEditing: isEnabled ? toggleEditing : () => undefined,\n lastFocusedCellIndex,\n setLastFocusedCellIndex,\n createRow,\n createRowButtonRef,\n ...pendingChangesFns,\n };\n}\n"],"names":["useTableEditing","isEnabled","handleSave","handleChange","handleCreate","rowIdentityAccessor","validator","createRow","table","scrollToIndex","row","Promise","resolve","tableMeta","options","meta","editing","saveChanges","then","saved","changeset","rowId","pendingChangesFns","insertTemporaryRow","getRow","pin","temporaryRows","nextRowIndex","length","rowActive","setRowActiveIndex","toggleEditing","setLastFocusedCellIndex","undefined","error","console","e","reject","isEditing","setEditing","React","useState","isDetailedMode","toggleDetailedMode","createRowButtonRef","useRef","lastFocusedCellIndex","usePendingChangesState","enabled","index","_tableMeta$rowActive$","rowActiveIndex","isTemporaryRow","_table$getRowModel$ro","getRowModel","rows","id"],"mappings":";;;;SAWgBA,eAAeA,CAC3BC,SAAS,GAAG,KAAK,EACjBC,UAAuD,EACvDC,YAA2D,EAC3DC,YAA2D,EAC3DC,mBAA4C,EAC5CC,SAAsD;QAiDvCC,SAAS,aAAkBC,KAAoB,EAAEC,aAAsC,EAAEC,GAAgB;IAAA;MACpH,IAAI,CAACN,YAAY,EAAE;QACf,OAAAO,OAAA,CAAAC,OAAA;;MAGJ,MAAMC,SAAS,GAAGL,KAAK,CAACM,OAAO,CAACC,IAA6B;MAAC,OAAAJ,OAAA,CAAAC,OAAA,CAC1CC,SAAS,CAACG,OAAO,CAACC,WAAW,CAACT,KAAK,CAAC,EAAAU,IAAA,WAAlDC,KAAK;QAEX,IAAI,CAACA,KAAK,EAAE;UACR;;QA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EACpBC,aAAsC;;IAEtC,IAAI,CAACuC,OAAO,EAAE;;MAEV1B,iBAAiB,CAACL,WAAW,CAACT,KAAK,CAAC;;MAEpCmC,kBAAkB,CAAC,KAAK,CAAC;;MAEzBX,uBAAuB,CAACC,SAAS,CAAC;;IAGtC,MAAMpB,SAAS,GAAGL,KAAK,CAACM,OAAO,CAACC,IAA6B;IAC7D,MAAMkC,KAAK,IAAAC,qBAAA,GAAGrC,SAAS,CAACgB,SAAS,CAACsB,cAAc,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,CAAC;IAErD,IAAIrC,SAAS,CAACgB,SAAS,CAACsB,cAAc,KAAKlB,SAAS,EAAE;MAClDpB,SAAS,CAACgB,SAAS,CAACC,iBAAiB,CAACmB,KAAK,CAAC;;IAGhDV,UAAU,CAACS,OAAO,CAAC;IAEnB,IAAI,CAACI,cAAc,EAAAC,qBAAA,GAAC7C,KAAK,CAAC8C,WAAW,EAAE,CAACC,IAAI,CAACN,KAAK,CAAC,cAAAI,qBAAA,uBAA/BA,qBAAA,CAAiCG,EAAE,CAAC,EAAE;MACtD/C,aAAa,CAACwC,KAAK,CAAC;;;EAoC5B,OAAO;IACHhD,SAAS;IACTqC,SAAS;IACTI,cAAc;IACdC,kBAAkB,EAAE1C,SAAS,GAAG0C,kBAAkB,GAAG,MAAMV,SAAS;IACpEF,aAAa,EAAE9B,SAAS,GAAG8B,aAAa,GAAG,MAAME,SAAS;IAC1Da,oBAAoB;IACpBd,uBAAuB;IACvBzB,SAAS;IACTqC,kBAAkB;IAClB,GAAGtB;GACN;AACL;;;;"}
1
+ {"version":3,"file":"useTableEditing.js","sources":["../../../../../../../../src/components/Table3/features/useTableEditing.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {\n Table3EditingChangeHandler,\n Table3EditingCreateHandler,\n Table3EditingSaveHandler,\n Table3EditingValidatorFn,\n} from '../types';\nimport { usePendingChangesState } from './useEditingState';\nimport { isTemporaryRow } from '../util/editing';\n\nexport function useTableEditing<TType = unknown>(\n isEnabled = false,\n handleSave: Table3EditingSaveHandler<TType> | undefined,\n handleChange: Table3EditingChangeHandler<TType> | undefined,\n handleCreate: Table3EditingCreateHandler<TType> | undefined,\n rowIdentityAccessor: keyof TType | undefined,\n validator: Table3EditingValidatorFn<TType> | undefined\n) {\n // used to switch the table into editing mode\n const [isEditing, setEditing] = React.useState(false);\n\n // used to switch the editing between \"detailed\" mode\n const [isDetailedMode, toggleDetailedMode] = React.useState(false);\n\n // used to contain ref to the create button\n const createRowButtonRef = React.useRef<HTMLButtonElement>(null);\n\n // store the last focused cell, so that up/down arrow key navigation remains in the same column\n const [lastFocusedCellIndex, setLastFocusedCellIndex] = React.useState<number | undefined>(undefined);\n\n const pendingChangesFns = usePendingChangesState<TType>(\n handleSave,\n handleChange,\n rowIdentityAccessor as keyof TType,\n validator\n );\n\n function toggleEditing<T extends TType>(\n enabled: React.SetStateAction<boolean>,\n table: ReactTable<T>,\n scrollToIndex: (index: number) => void\n ) {\n if (!enabled) {\n // save\n pendingChangesFns.saveChanges(table);\n // reset detailed mode\n toggleDetailedMode(false);\n // reset the last index back to the first focusable element, when editing gets turned off\n setLastFocusedCellIndex(undefined);\n }\n\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const index = tableMeta.rowActive.rowActiveIndex ?? 0;\n\n if (tableMeta.rowActive.rowActiveIndex === undefined) {\n tableMeta.rowActive.setRowActiveIndex(index);\n }\n\n setEditing(enabled);\n\n const row = table.getRowModel().rows[index]?.id;\n\n if (row && !isTemporaryRow(row)) {\n console.log('hmm');\n scrollToIndex(index);\n }\n }\n\n async function createRow<T extends TType>(table: ReactTable<T>, scrollToIndex: (index: number) => void, row?: Partial<T>) {\n if (!handleCreate) {\n return;\n }\n\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const saved = await tableMeta.editing.saveChanges(table);\n\n if (!saved) {\n return;\n }\n\n const changeset = row ?? handleCreate();\n\n try {\n if (changeset) {\n // set the active row to the new row before toggling editing on\n const temporaryRows = tableMeta.editing.temporaryRows as TType[];\n const nextRowIndex = temporaryRows.length ? tableMeta.length + 1 : tableMeta.length;\n const rowId = pendingChangesFns.insertTemporaryRow(changeset, nextRowIndex);\n table.getRow(rowId).pin('bottom');\n\n tableMeta.rowActive.setRowActiveIndex(nextRowIndex);\n\n toggleEditing(true, table, scrollToIndex);\n setLastFocusedCellIndex(undefined);\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n return {\n isEnabled,\n isEditing,\n isDetailedMode,\n toggleDetailedMode: isEnabled ? toggleDetailedMode : () => undefined,\n toggleEditing: isEnabled ? toggleEditing : () => undefined,\n lastFocusedCellIndex,\n setLastFocusedCellIndex,\n createRow,\n createRowButtonRef,\n ...pendingChangesFns,\n };\n}\n"],"names":["useTableEditing","isEnabled","handleSave","handleChange","handleCreate","rowIdentityAccessor","validator","createRow","table","scrollToIndex","row","Promise","resolve","tableMeta","options","meta","editing","saveChanges","then","saved","changeset","temporaryRows","nextRowIndex","length","rowId","pendingChangesFns","insertTemporaryRow","getRow","pin","rowActive","setRowActiveIndex","toggleEditing","setLastFocusedCellIndex","undefined","error","console","e","reject","isEditing","setEditing","React","useState","isDetailedMode","toggleDetailedMode","createRowButtonRef","useRef","lastFocusedCellIndex","usePendingChangesState","enabled","index","_tableMeta$rowActive$","rowActiveIndex","_table$getRowModel$ro","getRowModel","rows","id","isTemporaryRow","log"],"mappings":";;;;SAWgBA,eAAeA,CAC3BC,SAAS,GAAG,KAAK,EACjBC,UAAuD,EACvDC,YAA2D,EAC3DC,YAA2D,EAC3DC,mBAA4C,EAC5CC,SAAsD;QAoDvCC,SAAS,aAAkBC,KAAoB,EAAEC,aAAsC,EAAEC,GAAgB;IAAA;MACpH,IAAI,CAACN,YAAY,EAAE;QACf,OAAAO,OAAA,CAAAC,OAAA;;MAGJ,MAAMC,SAAS,GAAGL,KAAK,CAACM,OAAO,CAACC,IAA6B;MAAC,OAAAJ,O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;;"}
@@ -55,18 +55,21 @@ function useTableEditingListener(table, tableRef, scrollToIndex) {
55
55
  document.addEventListener('click', onClickOutside);
56
56
  return () => document.removeEventListener('click', onClickOutside);
57
57
  }, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);
58
- const rows = table.getRowModel().rows;
59
- // make sure pending changes are removed for rows that no longer exist
60
- useLazyEffect(() => {
61
- const pendingChanges = tableMeta.editing.getErrorsShownInAlert();
62
- pendingChanges.forEach(pendingChange => {
63
- try {
64
- table.getRow(pendingChange.rowId);
65
- } catch {
66
- tableMeta.editing.discardChanges(pendingChange.rowId, table);
67
- }
68
- });
69
- }, [rows.length]);
58
+ /*
59
+ const rows = table.getRowModel().rows;
60
+ // make sure pending changes are removed for rows that no longer exist
61
+ useLazyEffect(() => {
62
+ const pendingChanges = tableMeta.editing.getErrorsShownInAlert();
63
+ pendingChanges.forEach(pendingChange => {
64
+ try {
65
+ table.getRow(pendingChange.rowId);
66
+ } catch {
67
+ // TODO: this has the potential to remove changes for "unloaded" rows in server loading
68
+ //tableMeta.editing.discardChanges(pendingChange.rowId, table);
69
+ }
70
+ });
71
+ }, [rows.length]);
72
+ */
70
73
  // shortcuts
71
74
  useGlobalKeyDown(tableMeta.editing.isEnabled ? shortcut : undefined, event => {
72
75
  event.preventDefault();
@@ -1 +1 @@
1
- {"version":3,"file":"useTableEditingListener.js","sources":["../../../../../../../../src/components/Table3/listeners/useTableEditingListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLazyEffect } from '../../../hooks/useLazyEffect';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../utils/dom';\nimport { TableRef } from '../../../primitives/Table/types';\nimport { resetHighlightedColumnIndexes } from '../../../primitives/Table/useTableManager/util/search';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown';\nimport { shortcut } from '../util/editing';\n\nexport function useTableEditingListener<TType = unknown>(\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n scrollToIndex: (index: number) => void\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const localization = useLocalization();\n\n // save when the row changes\n // store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again\n const lastRowActiveIndexRef = React.useRef<number | undefined>(tableMeta.rowActive.rowActiveIndex);\n\n useLazyEffect(() => {\n if (tableMeta.rowActive.rowActiveIndex !== lastRowActiveIndexRef.current) {\n lastRowActiveIndexRef.current = tableMeta.rowActive.rowActiveIndex;\n\n if (tableMeta.editing.isEditing && lastRowActiveIndexRef.current !== undefined) {\n tableMeta.editing.saveChanges(table);\n }\n }\n }, [tableMeta.rowActive.rowActiveIndex]);\n\n // show a warning if the user navigates away without triggering save, such as using the browser back/forward button\n const hasChanges = tableMeta.editing.hasChanges();\n\n React.useEffect(() => {\n function showUnsavedChangesWarning(event: BeforeUnloadEvent) {\n if (tableMeta.editing.isEditing && hasChanges) {\n event.returnValue = true;\n return true;\n }\n\n return false;\n }\n\n window.addEventListener('beforeunload', showUnsavedChangesWarning);\n\n return () => {\n window.removeEventListener('beforeunload', showUnsavedChangesWarning);\n };\n }, [tableMeta.editing.isEditing, hasChanges]);\n\n const hasSavedChanges = tableMeta.editing.hasSaved();\n\n useLazyEffect(() => {\n if (hasSavedChanges) {\n resetHighlightedColumnIndexes(table.getState().globalFilter, table, localization);\n }\n }, [hasSavedChanges]);\n\n React.useEffect(() => {\n const onClickOutside = (event: MouseEvent) => {\n if (tableMeta.editing.isEditing) {\n const element = event.target as Element;\n const isTableOrIsInsideTable =\n element.tagName === 'TABLE' ||\n element.tagName === 'TBODY' ||\n element.getAttribute('data-taco') === 'backdrop' ||\n element.getAttribute('data-table') === 'editing-toggle' ||\n !document.body.contains(element) ||\n isElementInsideOrTriggeredFromContainer(element, tableRef.current);\n\n // users can click the white space below rows which could be inside the table, but a valid scenario to save\n if (!isTableOrIsInsideTable) {\n tableMeta.editing.saveChanges(table);\n }\n }\n };\n\n document.addEventListener('click', onClickOutside);\n\n return () => document.removeEventListener('click', onClickOutside);\n }, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);\n\n const rows = table.getRowModel().rows;\n\n // make sure pending changes are removed for rows that no longer exist\n useLazyEffect(() => {\n const pendingChanges = tableMeta.editing.getErrorsShownInAlert();\n\n pendingChanges.forEach(pendingChange => {\n try {\n table.getRow(pendingChange.rowId);\n } catch {\n tableMeta.editing.discardChanges(pendingChange.rowId, table);\n }\n });\n }, [rows.length]);\n\n // shortcuts\n useGlobalKeyDown(tableMeta.editing.isEnabled ? shortcut : undefined, (event: KeyboardEvent) => {\n event.preventDefault();\n tableMeta.editing.toggleEditing(!tableMeta.editing.isEditing, table, scrollToIndex);\n });\n\n useGlobalKeyDown(tableMeta.editing.isEditing ? { key: 's', meta: true, shift: false } : undefined, event => {\n event.preventDefault();\n tableMeta.editing.saveChanges(table);\n });\n}\n"],"names":["useTableEditingListener","table","tableRef","scrollToIndex","tableMeta","options","meta","localization","useLocalization","lastRowActiveIndexRef","React","useRef","rowActive","rowActiveIndex","useLazyEffect","current","editing","isEditing","undefined","saveChanges","hasChanges","useEffect","showUnsavedChangesWarning","event","returnValue","window","addEventListener","removeEventListener","hasSavedChanges","hasSaved","resetHighlightedColumnIndexes","getState","globalFilter","onClickOutside","element","target","isTableOrIsInsideTable","tagName","getAttribute","document","body","contains","isElementInsideOrTriggeredFromContainer","rows","getRowModel","pendingChanges","getErrorsShownInAlert","forEach","pendingChange","getRow","rowId","discardChanges","length","useGlobalKeyDown","isEnabled","shortcut","preventDefault","toggleEditing","key","shift"],"mappings":";;;;;;;;SAUgBA,uBAAuBA,CACnCC,KAAwB,EACxBC,QAAmC,EACnCC,aAAsC;EAEtC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,YAAY,GAAGC,eAAe,EAAE;;;EAItC,MAAMC,qBAAqB,GAAGC,cAAK,CAACC,MA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AS,CAACY,OAAO,CAACsC,SAAS,GAAGC,QAAQ,GAAGrC,SAAS,EAAGK,KAAoB;IACtFA,KAAK,CAACiC,cAAc,EAAE;IACtBpD,SAAS,CAACY,OAAO,CAACyC,aAAa,CAAC,CAACrD,SAAS,CAACY,OAAO,CAACC,SAAS,EAAEhB,KAAK,EAAEE,aAAa,CAAC;GACtF,CAAC;EAEFkD,gBAAgB,CAACjD,SAAS,CAACY,OAAO,CAACC,SAAS,GAAG;IAAEyC,GAAG,EAAE,GAAG;IAAEpD,IAAI,EAAE,IAAI;IAAEqD,KAAK,EAAE;GAAO,GAAGzC,SAAS,EAAEK,KAAK;IACpGA,KAAK,CAACiC,cAAc,EAAE;IACtBpD,SAAS,CAACY,OAAO,CAACG,WAAW,CAAClB,KAAK,CAAC;GACvC,CAAC;AACN;;;;"}
1
+ {"version":3,"file":"useTableEditingListener.js","sources":["../../../../../../../../src/components/Table3/listeners/useTableEditingListener.ts"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLazyEffect } from '../../../hooks/useLazyEffect';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../utils/dom';\nimport { TableRef } from '../../../primitives/Table/types';\nimport { resetHighlightedColumnIndexes } from '../../../primitives/Table/useTableManager/util/search';\nimport { useLocalization } from '../../Provider/Localization';\nimport { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown';\nimport { shortcut } from '../util/editing';\n\nexport function useTableEditingListener<TType = unknown>(\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n scrollToIndex: (index: number) => void\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const localization = useLocalization();\n\n // save when the row changes\n // store the last row active index, otherwise everytime tableMeta.editing.saveChanges changes the hook runs again\n const lastRowActiveIndexRef = React.useRef<number | undefined>(tableMeta.rowActive.rowActiveIndex);\n\n useLazyEffect(() => {\n if (tableMeta.rowActive.rowActiveIndex !== lastRowActiveIndexRef.current) {\n lastRowActiveIndexRef.current = tableMeta.rowActive.rowActiveIndex;\n\n if (tableMeta.editing.isEditing && lastRowActiveIndexRef.current !== undefined) {\n tableMeta.editing.saveChanges(table);\n }\n }\n }, [tableMeta.rowActive.rowActiveIndex]);\n\n // show a warning if the user navigates away without triggering save, such as using the browser back/forward button\n const hasChanges = tableMeta.editing.hasChanges();\n\n React.useEffect(() => {\n function showUnsavedChangesWarning(event: BeforeUnloadEvent) {\n if (tableMeta.editing.isEditing && hasChanges) {\n event.returnValue = true;\n return true;\n }\n\n return false;\n }\n\n window.addEventListener('beforeunload', showUnsavedChangesWarning);\n\n return () => {\n window.removeEventListener('beforeunload', showUnsavedChangesWarning);\n };\n }, [tableMeta.editing.isEditing, hasChanges]);\n\n const hasSavedChanges = tableMeta.editing.hasSaved();\n\n useLazyEffect(() => {\n if (hasSavedChanges) {\n resetHighlightedColumnIndexes(table.getState().globalFilter, table, localization);\n }\n }, [hasSavedChanges]);\n\n React.useEffect(() => {\n const onClickOutside = (event: MouseEvent) => {\n if (tableMeta.editing.isEditing) {\n const element = event.target as Element;\n const isTableOrIsInsideTable =\n element.tagName === 'TABLE' ||\n element.tagName === 'TBODY' ||\n element.getAttribute('data-taco') === 'backdrop' ||\n element.getAttribute('data-table') === 'editing-toggle' ||\n !document.body.contains(element) ||\n isElementInsideOrTriggeredFromContainer(element, tableRef.current);\n\n // users can click the white space below rows which could be inside the table, but a valid scenario to save\n if (!isTableOrIsInsideTable) {\n tableMeta.editing.saveChanges(table);\n }\n }\n };\n\n document.addEventListener('click', onClickOutside);\n\n return () => document.removeEventListener('click', onClickOutside);\n }, [tableMeta.editing.isEditing, tableMeta.editing.saveChanges]);\n\n /*\n const rows = table.getRowModel().rows;\n\n // make sure pending changes are removed for rows that no longer exist\n useLazyEffect(() => {\n const pendingChanges = tableMeta.editing.getErrorsShownInAlert();\n\n pendingChanges.forEach(pendingChange => {\n try {\n table.getRow(pendingChange.rowId);\n } catch {\n // TODO: this has the potential to remove changes for \"unloaded\" rows in server loading\n //tableMeta.editing.discardChanges(pendingChange.rowId, table);\n }\n });\n }, [rows.length]);\n */\n\n // shortcuts\n useGlobalKeyDown(tableMeta.editing.isEnabled ? shortcut : undefined, (event: KeyboardEvent) => {\n event.preventDefault();\n tableMeta.editing.toggleEditing(!tableMeta.editing.isEditing, table, scrollToIndex);\n });\n\n useGlobalKeyDown(tableMeta.editing.isEditing ? { key: 's', meta: true, shift: false } : undefined, event => {\n event.preventDefault();\n tableMeta.editing.saveChanges(table);\n });\n}\n"],"names":["useTableEditingListener","table","tableRef","scrollToIndex","tableMeta","options","meta","localization","useLocalization","lastRowActiveIndexRef","React","useRef","rowActive","rowActiveIndex","useLazyEffect","current","editing","isEditing","undefined","saveChanges","hasChanges","useEffect","showUnsavedChangesWarning","event","returnValue","window","addEventListener","removeEventListener","hasSavedChanges","hasSaved","resetHighlightedColumnIndexes","getState","globalFilter","onClickOutside","element","target","isTableOrIsInsideTable","tagName","getAttribute","document","body","contains","isElementInsideOrTriggeredFromContainer","useGlobalKeyDown","isEnabled","shortcut","preventDefault","toggleEditing","key","shift"],"mappings":";;;;;;;;SAUgBA,uBAAuBA,CACnCC,KAAwB,EACxBC,QAAmC,EACnCC,aAAsC;EAEtC,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,YAAY,GAAGC,eAAe,EAAE;;;EAItC,MAAMC,qBAAqB,GAAGC,cAAK,CAACC,MAAM,CAAqBP,SAAS,CAACQ,SAAS,CAACC,cAAc,CAAC;EAElGC,aAAa,CAAC;IACV,IAAIV,SAAS,CAACQ,SAAS,CAACC,cAAc,KAAKJ,qBAAqB,CAACM,OAAO,EAAE;MACtEN,qBAAqB,CAACM,OAAO,GAAGX,SAAS,CAACQ,SAAS,CAACC,cAAc;MAElE,IAAIT,SAAS,CAACY,OAAO,CAACC,SAAS,IAAIR,qBAAqB,CAACM,OAAO,KAAKG,SAAS,EAAE;QAC5Ed,SAAS,C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,QAAQ,CAACC,IAAI,CAACC,QAAQ,CAACP,OAAO,CAAC,IAChCQ,uCAAuC,CAACR,OAAO,EAAEhC,QAAQ,CAACa,OAAO,CAAC;;QAGtE,IAAI,CAACqB,sBAAsB,EAAE;UACzBhC,SAAS,CAACY,OAAO,CAACG,WAAW,CAAClB,KAAK,CAAC;;;KAG/C;IAEDsC,QAAQ,CAACb,gBAAgB,CAAC,OAAO,EAAEO,cAAc,CAAC;IAElD,OAAO,MAAMM,QAAQ,CAACZ,mBAAmB,CAAC,OAAO,EAAEM,cAAc,CAAC;GACrE,EAAE,CAAC7B,SAAS,CAACY,OAAO,CAACC,SAAS,EAAEb,SAAS,CAACY,OAAO,CAACG,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;EAqBhEwB,gBAAgB,CAACvC,SAAS,CAACY,OAAO,CAAC4B,SAAS,GAAGC,QAAQ,GAAG3B,SAAS,EAAGK,KAAoB;IACtFA,KAAK,CAACuB,cAAc,EAAE;IACtB1C,SAAS,CAACY,OAAO,CAAC+B,aAAa,CAAC,CAAC3C,SAAS,CAACY,OAAO,CAACC,SAAS,EAAEhB,KAAK,EAAEE,aAAa,CAAC;GACtF,CAAC;EAEFwC,gBAAgB,CAACvC,SAAS,CAACY,OAAO,CAACC,SAAS,GAAG;IAAE+B,GAAG,EAAE,GAAG;IAAE1C,IAAI,EAAE,IAAI;IAAE2C,KAAK,EAAE;GAAO,GAAG/B,SAAS,EAAEK,KAAK;IACpGA,KAAK,CAACuB,cAAc,EAAE;IACtB1C,SAAS,CAACY,OAAO,CAACG,WAAW,CAAClB,KAAK,CAAC;GACvC,CAAC;AACN;;;;"}
@@ -92,6 +92,14 @@ const shortcut = {
92
92
  meta: true,
93
93
  shift: false
94
94
  };
95
+ function isTableScrolled(ref) {
96
+ if (ref.current) {
97
+ var _ref$current, _ref$current$querySel, _ref$current2, _ref$current2$querySe;
98
+ const height = parseFloat(((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : (_ref$current$querySel = _ref$current.querySelector('tbody')) === null || _ref$current$querySel === void 0 ? void 0 : _ref$current$querySel.style.height) || '0') + parseFloat(((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : (_ref$current2$querySe = _ref$current2.querySelector('tbody')) === null || _ref$current2$querySe === void 0 ? void 0 : _ref$current2$querySe.style.paddingBottom) || '0');
99
+ return height > ref.current.scrollHeight;
100
+ }
101
+ return false;
102
+ }
95
103
 
96
- export { TEMPORARY_ROW_ID_PREFIX, isTemporaryRow, shortcut, willRowMove };
104
+ export { TEMPORARY_ROW_ID_PREFIX, isTableScrolled, isTemporaryRow, shortcut, willRowMove };
97
105
  //# sourceMappingURL=editing.js.map