@economic/taco 2.45.0-alpha.1 → 2.45.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/dist/components/Popover/Popover.d.ts +1 -1
  2. package/dist/components/Provider/Localization.d.ts +2 -0
  3. package/dist/components/Report/Report.d.ts +1 -1
  4. package/dist/components/Select2/components/Search.d.ts +0 -6
  5. package/dist/components/Table3/Table3.d.ts +2 -14
  6. package/dist/components/Table3/components/Columns/Internal/EditingActionsMenu.d.ts +3 -4
  7. package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.d.ts +7 -0
  8. package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +14 -0
  9. package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +11 -0
  10. package/dist/components/Table3/features/useEditingState.d.ts +29 -0
  11. package/dist/components/Table3/features/useTableEditing.d.ts +26 -36
  12. package/dist/components/Table3/listeners/useTableEditingListener.d.ts +1 -1
  13. package/dist/components/Table3/types.d.ts +24 -8
  14. package/dist/components/Table3/useTable3.d.ts +6 -0
  15. package/dist/components/Table3/util/editing.d.ts +7 -1
  16. package/dist/esm/index.css +35 -4
  17. package/dist/esm/packages/taco/src/components/Button/util.js +1 -1
  18. package/dist/esm/packages/taco/src/components/Button/util.js.map +1 -1
  19. package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js +2 -2
  20. package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js.map +1 -1
  21. package/dist/esm/packages/taco/src/components/Popover/Popover.js.map +1 -1
  22. package/dist/esm/packages/taco/src/components/Provider/Localization.js +5 -3
  23. package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
  24. package/dist/esm/packages/taco/src/components/Select2/Select2.js +21 -40
  25. package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
  26. package/dist/esm/packages/taco/src/components/Select2/components/Search.js +2 -12
  27. package/dist/esm/packages/taco/src/components/Select2/components/Search.js.map +1 -1
  28. package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js +19 -1
  29. package/dist/esm/packages/taco/src/components/Select2/components/Trigger.js.map +1 -1
  30. package/dist/esm/packages/taco/src/components/Switch/Switch.js +1 -1
  31. package/dist/esm/packages/taco/src/components/Switch/Switch.js.map +1 -1
  32. package/dist/esm/packages/taco/src/components/Table3/Table3.js +14 -6
  33. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  34. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/Editing/RowMoveIndicator.js +1 -2
  35. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/Editing/RowMoveIndicator.js.map +1 -1
  36. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +33 -11
  37. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  38. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js +7 -39
  39. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js.map +1 -1
  40. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +17 -12
  41. package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
  42. package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js +34 -0
  43. package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js.map +1 -0
  44. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +104 -0
  45. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -0
  46. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js +2 -14
  47. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js.map +1 -1
  48. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +96 -0
  49. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -0
  50. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js +39 -6
  51. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js.map +1 -1
  52. package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js +4 -17
  53. package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js.map +1 -1
  54. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +519 -0
  55. package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -0
  56. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +29 -406
  57. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  58. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +44 -33
  59. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  60. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +44 -14
  61. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  62. package/dist/esm/packages/taco/src/components/Table3/util/editing.js +11 -23
  63. package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
  64. package/dist/esm/packages/taco/src/primitives/Collection/components/Root.js +18 -0
  65. package/dist/esm/packages/taco/src/primitives/Collection/components/Root.js.map +1 -1
  66. package/dist/esm/packages/taco/src/primitives/Listbox2/components/Option.js +0 -5
  67. package/dist/esm/packages/taco/src/primitives/Listbox2/components/Option.js.map +1 -1
  68. package/dist/esm/packages/taco/src/primitives/Listbox2/components/Root.js +1 -0
  69. package/dist/esm/packages/taco/src/primitives/Listbox2/components/Root.js.map +1 -1
  70. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +6 -4
  71. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  72. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js +30 -17
  73. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js.map +1 -1
  74. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js +10 -7
  75. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js.map +1 -1
  76. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
  77. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js +6 -3
  78. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js.map +1 -1
  79. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js +4 -2
  80. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
  81. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/RowContext.js +2 -1
  82. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/RowContext.js.map +1 -1
  83. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js +8 -1
  84. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js.map +1 -1
  85. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +29 -7
  86. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  87. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +2 -2
  88. package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
  89. package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
  90. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowSelection.js +2 -1
  91. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowSelection.js.map +1 -1
  92. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +1 -1
  93. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
  94. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +11 -0
  95. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
  96. package/dist/esm/packages/taco/src/utils/dom.js +20 -10
  97. package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
  98. package/dist/index.css +35 -4
  99. package/dist/primitives/Collection/components/Root.d.ts +2 -0
  100. package/dist/primitives/Table/Core/components/Body/util.d.ts +4 -4
  101. package/dist/primitives/Table/Core/components/Columns/Internal/Actions.d.ts +3 -1
  102. package/dist/primitives/Table/Core/components/Footer/Footer.d.ts +1 -1
  103. package/dist/primitives/Table/Core/components/Row/RowContext.d.ts +1 -0
  104. package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +2 -2
  105. package/dist/primitives/Table/Core/features/useTableStyle.d.ts +3 -3
  106. package/dist/primitives/Table/Core/types.d.ts +4 -0
  107. package/dist/primitives/Table/Core/useTable.d.ts +2 -2
  108. package/dist/primitives/Table/types.d.ts +2 -2
  109. package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
  110. package/dist/taco.cjs.development.js +1119 -743
  111. package/dist/taco.cjs.development.js.map +1 -1
  112. package/dist/taco.cjs.production.min.js +1 -1
  113. package/dist/taco.cjs.production.min.js.map +1 -1
  114. package/dist/utils/dom.d.ts +2 -1
  115. package/package.json +17 -17
  116. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js +0 -90
  117. package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import React__default from 'react';
2
- import { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown.js';
3
2
  import { Tooltip } from '../../../../Tooltip/Tooltip.js';
4
3
  import { useLocalization } from '../../../../Provider/Localization.js';
5
4
  import { Shortcut } from '../../../../Shortcut/Shortcut.js';
6
5
  import { ModeSwitch } from '../../../../ModeSwitch/ModeSwitch.js';
6
+ import { shortcut } from '../../../util/editing.js';
7
7
 
8
8
  function Editing(props) {
9
9
  const {
@@ -15,30 +15,17 @@ function Editing(props) {
15
15
  } = useLocalization();
16
16
  const ref = React__default.useRef(null);
17
17
  const tableMeta = table.options.meta;
18
- const shortcut = {
19
- key: 'e',
20
- meta: true,
21
- shift: false
18
+ const handleChange = enabled => {
19
+ tableMeta.editing.toggleEditing(enabled, table, scrollToIndex);
22
20
  };
23
21
  const tooltip = /*#__PURE__*/React__default.createElement(React__default.Fragment, null, texts.table3.editing.buttons.edit.tooltip, /*#__PURE__*/React__default.createElement(Shortcut, {
24
22
  className: "ml-2",
25
23
  keys: shortcut
26
24
  }));
27
- useGlobalKeyDown(shortcut, event => {
28
- var _ref$current;
29
- event.preventDefault();
30
- (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.click();
31
- });
32
- const handleChange = enabled => {
33
- tableMeta.editing.toggleEditing(enabled);
34
- requestAnimationFrame(() => {
35
- var _tableMeta$rowActive$;
36
- return scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
37
- });
38
- };
39
25
  return /*#__PURE__*/React__default.createElement(Tooltip, {
40
26
  title: tooltip
41
27
  }, /*#__PURE__*/React__default.createElement(ModeSwitch, {
28
+ "data-table": "editing-toggle",
42
29
  checked: tableMeta.editing.isEditing,
43
30
  onChange: handleChange,
44
31
  ref: ref
@@ -1 +1 @@
1
- {"version":3,"file":"Editing.js","sources":["../../../../../../../../../../src/components/Table3/components/Toolbar/Editing/Editing.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { ModeSwitch } from '../../../../ModeSwitch/ModeSwitch';\nimport { useGlobalKeyDown } from '../../../../../hooks/useGlobalKeyDown';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\n\ntype EditingProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n scrollToIndex: any;\n table: ReactTable<TType>;\n};\n\nexport function Editing<TType = unknown>(props: EditingProps<TType>) {\n const { scrollToIndex, table } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n const shortcut = { key: 'e', meta: true, shift: false };\n const tooltip = (\n <>\n {texts.table3.editing.buttons.edit.tooltip}\n <Shortcut className=\"ml-2\" keys={shortcut} />\n </>\n );\n\n useGlobalKeyDown(shortcut, (event: KeyboardEvent) => {\n event.preventDefault();\n ref.current?.click();\n });\n\n const handleChange = (enabled: boolean) => {\n tableMeta.editing.toggleEditing(enabled);\n requestAnimationFrame(() => scrollToIndex(tableMeta.rowActive.rowActiveIndex ?? 0));\n };\n\n return (\n <Tooltip title={tooltip}>\n <ModeSwitch checked={tableMeta.editing.isEditing} onChange={handleChange} ref={ref} />\n </Tooltip>\n );\n}\n"],"names":["Editing","props","scrollToIndex","table","texts","useLocalization","ref","React","useRef","tableMeta","options","meta","shortcut","key","shift","tooltip","table3","editing","buttons","edit","Shortcut","className","keys","useGlobalKeyDown","event","preventDefault","_ref$current","current","click","handleChange","enabled","toggleEditing","requestAnimationFrame","_tableMeta$rowActive$","rowActive","rowActiveIndex","Tooltip","title","ModeSwitch","checked","isEditing","onChange"],"mappings":";;;;;;;SAagBA,OAAOA,CAAkBC,KAA0B;EAC/D,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGF,KAAK;EACtC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAoB,IAAI,CAAC;EACjD,MAAMC,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAA6B;EAE7D,MAAMC,QAAQ,GAAG;IAAEC,GAAG,EAAE,GAAG;IAAEF,IAAI,EAAE,IAAI;IAAEG,KAAK,EAAE;GAAO;EACvD,MAAMC,OAAO,gBACTR,4DACKH,KAAK,CAACY,MAAM,CAACC,OAAO,CAACC,OAAO,CAACC,IAAI,CAACJ,OAAO,eAC1CR,6BAACa,QAAQ;IAACC,SAAS,EAAC,MAAM;IAACC,IAAI,EAAEV;IAAY,CAEpD;EAEDW,gBAAgB,CAACX,QAAQ,EAAGY,KAAoB;;IAC5CA,KAAK,CAACC,cAAc,EAAE;IACtB,CAAAC,YAAA,GAAApB,GAAG,CAACqB,OAAO,cAAAD,YAAA,uBAAXA,YAAA,CAAaE,KAAK,EAAE;GACvB,CAAC;EAEF,MAAMC,YAAY,GAAIC,OAAgB;IAClCrB,SAAS,CAACQ,OAAO,CAACc,aAAa,CAACD,OAAO,CAAC;IACxCE,qBAAqB,CAAC;MAAA,IAAAC,qBAAA;MAAA,OAAM/B,aAAa,EAAA+B,qBAAA,GAACxB,SAAS,CAACyB,SAAS,CAACC,cAAc,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,CAAC,CAAC;MAAC;GACtF;EAED,oBACI1B,6BAAC6B,OAAO;IAACC,KAAK,EAAEtB;kBACZR,6BAAC+B,UAAU;IAACC,OAAO,EAAE9B,SAAS,CAACQ,OAAO,CAACuB,SAAS;IAAEC,QAAQ,EAAEZ,YAAY;IAAEvB,GAAG,EAAEA;IAAO,CAChF;AAElB;;;;"}
1
+ {"version":3,"file":"Editing.js","sources":["../../../../../../../../../../src/components/Table3/components/Toolbar/Editing/Editing.tsx"],"sourcesContent":["import React from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { ModeSwitch } from '../../../../ModeSwitch/ModeSwitch';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\nimport { shortcut } from '../../../util/editing';\n\ntype EditingProps<TType = unknown> = React.HTMLAttributes<HTMLButtonElement> & {\n scrollToIndex: any;\n table: ReactTable<TType>;\n};\n\nexport function Editing<TType = unknown>(props: EditingProps<TType>) {\n const { scrollToIndex, table } = props;\n const { texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n\n const handleChange = (enabled: boolean) => {\n tableMeta.editing.toggleEditing(enabled, table, scrollToIndex);\n };\n\n const tooltip = (\n <>\n {texts.table3.editing.buttons.edit.tooltip}\n <Shortcut className=\"ml-2\" keys={shortcut} />\n </>\n );\n\n return (\n <Tooltip title={tooltip}>\n <ModeSwitch data-table=\"editing-toggle\" checked={tableMeta.editing.isEditing} onChange={handleChange} ref={ref} />\n </Tooltip>\n );\n}\n"],"names":["Editing","props","scrollToIndex","table","texts","useLocalization","ref","React","useRef","tableMeta","options","meta","handleChange","enabled","editing","toggleEditing","tooltip","table3","buttons","edit","Shortcut","className","keys","shortcut","Tooltip","title","ModeSwitch","checked","isEditing","onChange"],"mappings":";;;;;;;SAagBA,OAAOA,CAAkBC,KAA0B;EAC/D,MAAM;IAAEC,aAAa;IAAEC;GAAO,GAAGF,KAAK;EACtC,MAAM;IAAEG;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,GAAG,GAAGC,cAAK,CAACC,MAAM,CAAoB,IAAI,CAAC;EACjD,MAAMC,SAAS,GAAGN,KAAK,CAACO,OAAO,CAACC,IAA6B;EAE7D,MAAMC,YAAY,GAAIC,OAAgB;IAClCJ,SAAS,CAACK,OAAO,CAACC,aAAa,CAACF,OAAO,EAAEV,KAAK,EAAED,aAAa,CAAC;GACjE;EAED,MAAMc,OAAO,gBACTT,4DACKH,KAAK,CAACa,MAAM,CAACH,OAAO,CAACI,OAAO,CAACC,IAAI,CAACH,OAAO,eAC1CT,6BAACa,QAAQ;IAACC,SAAS,EAAC,MAAM;IAACC,IAAI,EAAEC;IAAY,CAEpD;EAED,oBACIhB,6BAACiB,OAAO;IAACC,KAAK,EAAET;kBACZT,6BAACmB,UAAU;kBAAY,gBAAgB;IAACC,OAAO,EAAElB,SAAS,CAACK,OAAO,CAACc,SAAS;IAAEC,QAAQ,EAAEjB,YAAY;IAAEN,GAAG,EAAEA;IAAO,CAC5G;AAElB;;;;"}
@@ -0,0 +1,519 @@
1
+ import React__default from 'react';
2
+ import { useLocalization } from '../../Provider/Localization.js';
3
+ import { v4 } from 'uuid';
4
+ import { _forOf, _catch } from '../../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
5
+ import { isTemporaryRow, willRowMove, TEMPORARY_ROW_ID_PREFIX } from '../util/editing.js';
6
+ import omit from 'lodash-es/omit';
7
+ import setWith from 'lodash-es/setWith';
8
+
9
+ const DELAY_BEFORE_REMOVING_SAVE_STATUS = 3000;
10
+ function reducer(state, action) {
11
+ const {
12
+ type,
13
+ rowId,
14
+ payload
15
+ } = action;
16
+ switch (type) {
17
+ case 'setCellValue':
18
+ {
19
+ const {
20
+ columnId,
21
+ row,
22
+ value
23
+ } = payload;
24
+ return {
25
+ ...state,
26
+ changes: {
27
+ ...state.changes,
28
+ rows: setWith(state.changes.rows, `${rowId}.${columnId}`, value, Object),
29
+ originals: setWith(state.changes.originals, rowId, row, Object)
30
+ }
31
+ };
32
+ }
33
+ case 'removeCellValue':
34
+ {
35
+ const {
36
+ columnId,
37
+ rowIdentityAccessor
38
+ } = payload;
39
+ const changes = omit(state.changes.rows, `${rowId}.${columnId}`);
40
+ // if there are no changes left, remove the row
41
+ if (!Object.keys(changes[rowId]).length) {
42
+ return reducer(state, {
43
+ type: 'removeRow',
44
+ rowId,
45
+ payload: {
46
+ rowIdentityAccessor
47
+ }
48
+ });
49
+ }
50
+ return {
51
+ ...state,
52
+ changes: {
53
+ ...state.changes,
54
+ rows: omit(state.changes.rows, `${rowId}.${columnId}`),
55
+ errors: omit(state.changes.errors, `${rowId}.cells.${columnId}`),
56
+ moveReasons: omit(state.changes.moveReasons, `${rowId}.${columnId}`)
57
+ }
58
+ };
59
+ }
60
+ case 'updateRow':
61
+ {
62
+ const {
63
+ cellErrors,
64
+ moveReasons,
65
+ original,
66
+ value
67
+ } = payload;
68
+ return {
69
+ ...state,
70
+ changes: {
71
+ ...state.changes,
72
+ rows: setWith(state.changes.rows, rowId, value, Object),
73
+ errors: setWith(state.changes.errors, `${rowId}.cells`, cellErrors !== null && cellErrors !== void 0 ? cellErrors : state.changes.errors.cells[rowId], Object),
74
+ originals: setWith(state.changes.originals, rowId, original !== null && original !== void 0 ? original : state.changes.originals[rowId], Object),
75
+ moveReasons: setWith(state.changes.moveReasons, rowId, moveReasons !== null && moveReasons !== void 0 ? moveReasons : state.changes.moveReasons[rowId], Object),
76
+ // status can be undefined, so don't use ??
77
+ status: setWith(state.changes.status, rowId, undefined, Object)
78
+ }
79
+ };
80
+ }
81
+ case 'removeRow':
82
+ {
83
+ const {
84
+ rowIdentityAccessor
85
+ } = payload;
86
+ return {
87
+ ...state,
88
+ changes: {
89
+ ...state.changes,
90
+ rows: omit(state.changes.rows, rowId),
91
+ errors: omit(state.changes.errors, rowId),
92
+ moveReasons: omit(state.changes.moveReasons, rowId),
93
+ originals: omit(state.changes.originals, rowId),
94
+ status: omit(state.changes.status, rowId)
95
+ },
96
+ temporaryRows: state.temporaryRows.filter(row => row[rowIdentityAccessor] !== rowId)
97
+ };
98
+ }
99
+ case 'setRowStatus':
100
+ {
101
+ const {
102
+ status
103
+ } = payload;
104
+ return {
105
+ ...state,
106
+ changes: {
107
+ ...state.changes,
108
+ status: status ? setWith(state.changes.status, rowId, status, Object) : omit(state.changes.status, rowId)
109
+ }
110
+ };
111
+ }
112
+ case 'setRowErrors':
113
+ {
114
+ const {
115
+ ...errors
116
+ } = payload;
117
+ return {
118
+ ...state,
119
+ changes: {
120
+ ...state.changes,
121
+ errors: setWith(state.changes.errors, rowId, errors, Object)
122
+ }
123
+ };
124
+ }
125
+ case 'createRow':
126
+ {
127
+ const {
128
+ value
129
+ } = payload;
130
+ return {
131
+ ...state,
132
+ temporaryRows: state.temporaryRows.concat(value),
133
+ changes: {
134
+ ...state.changes,
135
+ rows: setWith(state.changes.rows, rowId, value, Object),
136
+ originals: setWith(state.changes.originals, rowId, value, Object)
137
+ }
138
+ };
139
+ }
140
+ default:
141
+ return state;
142
+ }
143
+ }
144
+ function usePendingChangesState(handleSave, handleChange, rowIdentityAccessor, validator) {
145
+ const saveChanges = function (table, rowId = undefined) {
146
+ try {
147
+ let _exit = false;
148
+ if (!handleSave) {
149
+ console.warn('Tried to save, but Table has no onEditingSave handler');
150
+ return Promise.resolve(false);
151
+ }
152
+ // sometimes we only want to save one row
153
+ const changes = rowId ? {
154
+ [rowId]: state.changes.rows[rowId]
155
+ } : state.changes.rows;
156
+ let completed = true;
157
+ const _temp9 = _forOf(Object.keys(changes), function (rowId) {
158
+ const status = getRowStatus(rowId);
159
+ return _catch(function () {
160
+ function _temp8(_result) {
161
+ return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
162
+ // cleanup changes, we don't need them after saving
163
+ discardChanges(rowId, table);
164
+ // show the saved status, then remove it after a delay
165
+ setRowStatus(rowId, 'saved');
166
+ setTimeout(() => {
167
+ setRowStatus(rowId, undefined);
168
+ }, DELAY_BEFORE_REMOVING_SAVE_STATUS);
169
+ });
170
+ }
171
+ // don't try to save if - already saving, or there are known errors
172
+ if (status === 'saving' || status === 'errored') {
173
+ return;
174
+ }
175
+ setRowStatus(rowId, 'saving');
176
+ const changeSet = {
177
+ ...state.changes.originals[rowId],
178
+ ...changes[rowId]
179
+ };
180
+ // if we had to create a temporary id, delete it first - it's our data, not theirs
181
+ if (isTemporaryRow(changeSet[rowIdentityAccessor])) {
182
+ delete changeSet[rowIdentityAccessor];
183
+ }
184
+ // re-run validation, maybe a cell is already invalid but has never been blurred
185
+ const _temp7 = function () {
186
+ if (validator) {
187
+ return Promise.resolve(validator(changeSet)).then(function (errors) {
188
+ if (errors && Object.keys(errors).length) {
189
+ throw errors;
190
+ }
191
+ });
192
+ }
193
+ }();
194
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); // send new data to the server
195
+ }, function (error) {
196
+ var _error$response;
197
+ 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) {
198
+ console.error(error);
199
+ }
200
+ // the onEditingSave handler should throw errors when something fails, e.g. validation, network errors etc
201
+ // this code handles those errors and maps them either to row errors or cell specific errors
202
+ let rowError;
203
+ let cellErrors;
204
+ if (typeof error === 'string') {
205
+ rowError = error;
206
+ } else if (error instanceof Error) {
207
+ var _error$response2;
208
+ rowError = error.message;
209
+ // most of our apis return error objects within this shape
210
+ if (typeof ((_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data) === 'object') {
211
+ var _error$response3;
212
+ cellErrors = (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : _error$response3.data;
213
+ }
214
+ } else if (typeof error === 'object') {
215
+ cellErrors = error;
216
+ }
217
+ if (rowError || cellErrors) {
218
+ dispatch({
219
+ type: 'setRowErrors',
220
+ rowId,
221
+ payload: {
222
+ row: rowError,
223
+ cells: cellErrors,
224
+ shouldShowErrorAlert: true
225
+ }
226
+ });
227
+ }
228
+ setRowStatus(rowId, 'errored');
229
+ completed = false;
230
+ });
231
+ }, function () {
232
+ return _exit;
233
+ });
234
+ return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function (_result3) {
235
+ return _exit ? _result3 : completed;
236
+ }) : _exit ? _temp9 : completed);
237
+ } catch (e) {
238
+ return Promise.reject(e);
239
+ }
240
+ };
241
+ const onCellChanged = function (cell, rowIndex, shouldRunUpdaters = true) {
242
+ try {
243
+ function _temp6() {
244
+ var _state$changes$errors11;
245
+ function _temp4() {
246
+ // only set errors and move reasons for the cells we're currently acting on
247
+ // why? because the UX is not good if we set them for cells the user hasn't touched yet
248
+ const cellsToActOn = [cell.column.id, ...Object.keys(updatesForOtherCells)];
249
+ const allCells = cell.row._getAllCellsByColumnId();
250
+ cellsToActOn.forEach(accessor => {
251
+ if (validationErrors[accessor]) {
252
+ nextCellErrors[accessor] = validationErrors[accessor];
253
+ // don't show move indicator for cells with errors, they aren't valid and can't be saved
254
+ delete nextMoveReasons[accessor];
255
+ } else {
256
+ var _allCells$accessor;
257
+ // there isn't any error in this run, remove any error set in state
258
+ delete nextCellErrors[accessor];
259
+ if ((_allCells$accessor = allCells[accessor]) !== null && _allCells$accessor !== void 0 && _allCells$accessor.column.getIsSorted()) {
260
+ // run row move determination
261
+ const reason = willRowMove(cell, nextChanges[accessor], rowIndex, localization);
262
+ // if the row will move based on this change save why, otherwise delete any existing state
263
+ if (reason) {
264
+ nextMoveReasons[accessor] = reason;
265
+ } else {
266
+ delete nextMoveReasons[accessor];
267
+ }
268
+ }
269
+ }
270
+ });
271
+ dispatch({
272
+ type: 'updateRow',
273
+ rowId: cell.row.id,
274
+ payload: {
275
+ cellErrors: nextCellErrors,
276
+ moveReasons: nextMoveReasons,
277
+ value: nextChanges
278
+ }
279
+ });
280
+ }
281
+ // create a projection of the next state, so we can act against it
282
+ const nextChanges = {
283
+ ...state.changes.rows[cell.row.id],
284
+ ...updatesForOtherCells
285
+ };
286
+ const nextMoveReasons = {
287
+ ...state.changes.moveReasons[cell.row.id]
288
+ };
289
+ const nextCellErrors = {
290
+ ...((_state$changes$errors11 = state.changes.errors[cell.row.id]) === null || _state$changes$errors11 === void 0 ? void 0 : _state$changes$errors11.cells)
291
+ };
292
+ // run validation
293
+ let validationErrors = {};
294
+ const _temp3 = function () {
295
+ if (validator) {
296
+ const nextRowValue = {
297
+ ...state.changes.originals[cell.row.id],
298
+ ...changes,
299
+ ...updatesForOtherCells
300
+ };
301
+ return Promise.resolve(validator(nextRowValue)).then(function (_validator2) {
302
+ validationErrors = _validator2 !== null && _validator2 !== void 0 ? _validator2 : {};
303
+ });
304
+ }
305
+ }();
306
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
307
+ }
308
+ const changes = state.changes.rows[cell.row.id];
309
+ if (!changes) {
310
+ return Promise.resolve();
311
+ }
312
+ let updatesForOtherCells = {};
313
+ // run the updater handler if there is one, to see if there are any other cells to update
314
+ const _temp5 = function () {
315
+ if (typeof handleChange === 'function' && shouldRunUpdaters) {
316
+ const previousRowValue = {
317
+ ...state.changes.originals[cell.row.id]
318
+ };
319
+ const nextRowValue = {
320
+ ...state.changes.originals[cell.row.id],
321
+ ...changes
322
+ };
323
+ return Promise.resolve(handleChange(cell.column.id, changes[cell.column.id], nextRowValue, previousRowValue)).then(function (_handleChange) {
324
+ updatesForOtherCells = _handleChange !== null && _handleChange !== void 0 ? _handleChange : {};
325
+ });
326
+ }
327
+ }();
328
+ return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5));
329
+ } catch (e) {
330
+ return Promise.reject(e);
331
+ }
332
+ }; // 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
+ const localization = useLocalization();
365
+ const [state, dispatch] = React__default.useReducer(reducer, {
366
+ changes: {
367
+ rows: {},
368
+ errors: {},
369
+ moveReasons: {},
370
+ originals: {},
371
+ status: {}
372
+ },
373
+ temporaryRows: []
374
+ });
375
+ function getRowValue(rowId) {
376
+ var _state$changes$rows$r, _state$changes$rows;
377
+ 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;
378
+ }
379
+ function getRowMoveReason(rowId) {
380
+ var _Object$values$, _state$changes$moveRe, _state$changes$moveRe2;
381
+ return (_Object$values$ = Object.values((_state$changes$moveRe = (_state$changes$moveRe2 = state.changes.moveReasons) === null || _state$changes$moveRe2 === void 0 ? void 0 : _state$changes$moveRe2[rowId]) !== null && _state$changes$moveRe !== void 0 ? _state$changes$moveRe : {})[0]) !== null && _Object$values$ !== void 0 ? _Object$values$ : undefined;
382
+ }
383
+ function hasRowErrors(rowId) {
384
+ var _state$changes$errors, _state$changes$errors2, _state$changes$errors3;
385
+ return !!((_state$changes$errors = state.changes.errors[rowId]) !== null && _state$changes$errors !== void 0 && _state$changes$errors.row) || !!Object.keys((_state$changes$errors2 = (_state$changes$errors3 = state.changes.errors[rowId]) === null || _state$changes$errors3 === void 0 ? void 0 : _state$changes$errors3.cells) !== null && _state$changes$errors2 !== void 0 ? _state$changes$errors2 : {}).length;
386
+ }
387
+ function hasRowErrorsShownInAlert(rowId) {
388
+ var _state$changes$errors4;
389
+ return hasRowErrors(rowId) && !!((_state$changes$errors4 = state.changes.errors[rowId]) !== null && _state$changes$errors4 !== void 0 && _state$changes$errors4.shouldShowErrorAlert);
390
+ }
391
+ function hasTemporaryRowErrors() {
392
+ var _state$temporaryRows, _state$changes$errors5, _state$changes$errors6, _state$changes$errors7;
393
+ const newRow = (_state$temporaryRows = state.temporaryRows) === null || _state$temporaryRows === void 0 ? void 0 : _state$temporaryRows[0];
394
+ if (!newRow) {
395
+ return false;
396
+ }
397
+ const rowId = newRow[rowIdentityAccessor];
398
+ return !!((_state$changes$errors5 = state.changes.errors[rowId]) !== null && _state$changes$errors5 !== void 0 && _state$changes$errors5.row) || !!Object.keys((_state$changes$errors6 = (_state$changes$errors7 = state.changes.errors[rowId]) === null || _state$changes$errors7 === void 0 ? void 0 : _state$changes$errors7.cells) !== null && _state$changes$errors6 !== void 0 ? _state$changes$errors6 : {}).length;
399
+ }
400
+ function getRowStatus(rowId) {
401
+ return state.changes.status[rowId];
402
+ }
403
+ function setRowStatus(rowId, status) {
404
+ dispatch({
405
+ type: 'setRowStatus',
406
+ rowId,
407
+ payload: {
408
+ status
409
+ }
410
+ });
411
+ }
412
+ function createRow(data) {
413
+ const newRowId = `${TEMPORARY_ROW_ID_PREFIX}${v4()}`;
414
+ const value = {
415
+ ...data,
416
+ [rowIdentityAccessor]: newRowId
417
+ };
418
+ dispatch({
419
+ type: 'createRow',
420
+ rowId: newRowId,
421
+ payload: {
422
+ value
423
+ }
424
+ });
425
+ return newRowId;
426
+ }
427
+ // cells
428
+ function setCellValue(cell, value) {
429
+ const rowId = cell.row.id;
430
+ const columnId = cell.column.id;
431
+ // update if the change is different to the original value
432
+ if (value !== cell.row.original[columnId]) {
433
+ dispatch({
434
+ type: 'setCellValue',
435
+ rowId,
436
+ payload: {
437
+ columnId,
438
+ row: cell.row.original,
439
+ value
440
+ }
441
+ });
442
+ }
443
+ // otherwise remove any previous change - no point saving the same value
444
+ else if (cell.row.id in state.changes.rows) {
445
+ dispatch({
446
+ type: 'removeCellValue',
447
+ rowId,
448
+ payload: {
449
+ columnId,
450
+ rowIdentityAccessor
451
+ }
452
+ });
453
+ }
454
+ }
455
+ function getCellValue(cell) {
456
+ var _state$changes$rows2, _state$changes$rows2$;
457
+ return (_state$changes$rows2 = state.changes.rows) === null || _state$changes$rows2 === void 0 ? void 0 : (_state$changes$rows2$ = _state$changes$rows2[cell.row.id]) === null || _state$changes$rows2$ === void 0 ? void 0 : _state$changes$rows2$[cell.column.id];
458
+ }
459
+ function getCellError(cell) {
460
+ var _state$changes$errors8, _state$changes$errors9, _state$changes$errors10;
461
+ return (_state$changes$errors8 = state.changes.errors) === null || _state$changes$errors8 === void 0 ? void 0 : (_state$changes$errors9 = _state$changes$errors8[cell.row.id]) === null || _state$changes$errors9 === void 0 ? void 0 : (_state$changes$errors10 = _state$changes$errors9.cells) === null || _state$changes$errors10 === void 0 ? void 0 : _state$changes$errors10[cell.column.id];
462
+ }
463
+ function getErrorsShownInAlert() {
464
+ const rowsWithErrors = Object.keys(state.changes.errors);
465
+ if (!rowsWithErrors.length) {
466
+ return [];
467
+ }
468
+ return rowsWithErrors.filter(hasRowErrorsShownInAlert).map(rowId => ({
469
+ rowId,
470
+ changes: state.changes.rows[rowId],
471
+ errors: state.changes.errors[rowId]
472
+ }));
473
+ }
474
+ function hasSaved() {
475
+ return !!Object.values(state.changes.status).filter(value => value === 'saved').length;
476
+ }
477
+ function hasChanges(rowId) {
478
+ return rowId ? !!state.changes.rows[rowId] : !!Object.keys(state.changes.rows).length;
479
+ }
480
+ function discardChanges(rowId, table) {
481
+ // remove any new rows from pinned state before discarding them
482
+ table.resetRowPinning(true);
483
+ dispatch({
484
+ type: 'removeRow',
485
+ rowId,
486
+ payload: {
487
+ rowIdentityAccessor
488
+ }
489
+ });
490
+ }
491
+ return {
492
+ // row
493
+ setRowValue,
494
+ getRowValue,
495
+ getRowMoveReason,
496
+ hasRowErrors,
497
+ hasRowErrorsShownInAlert,
498
+ hasTemporaryRowErrors,
499
+ getRowStatus,
500
+ setRowStatus,
501
+ // cells
502
+ setCellValue,
503
+ getCellValue,
504
+ getCellError,
505
+ onCellChanged,
506
+ // general
507
+ getErrorsShownInAlert,
508
+ hasChanges,
509
+ saveChanges,
510
+ discardChanges,
511
+ hasSaved,
512
+ // new rows
513
+ createRow,
514
+ temporaryRows: state.temporaryRows
515
+ };
516
+ }
517
+
518
+ export { usePendingChangesState };
519
+ //# sourceMappingURL=useEditingState.js.map
@@ -0,0 +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 | 'createRow';\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 'createRow': {\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 createRow<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: 'createRow',\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 createRow,\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","createRow","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,K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