@economic/taco 2.44.5-create.5 → 2.44.5-create.7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Provider/Localization.d.ts +0 -2
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/components/Table3/Table3.d.ts +14 -2
- package/dist/components/Table3/components/Columns/Internal/EditingActionsMenu.d.ts +2 -1
- package/dist/components/Table3/components/Row/Editing/CreateRowButton.d.ts +11 -0
- package/dist/components/Table3/features/useTableEditing.d.ts +36 -25
- package/dist/components/Table3/types.d.ts +8 -23
- package/dist/components/Table3/useTable3.d.ts +0 -6
- package/dist/components/Table3/util/editing.d.ts +1 -2
- package/dist/esm/index.css +2 -6
- package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js +2 -2
- package/dist/esm/packages/taco/src/components/ModeSwitch/ModeSwitch.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +3 -5
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Switch/Switch.js +1 -1
- package/dist/esm/packages/taco/src/components/Switch/Switch.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +7 -19
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +22 -21
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js +37 -5
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js +12 -17
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js +90 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js +14 -2
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js +6 -39
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js +2 -7
- package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +406 -19
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +32 -37
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/useTable3.js +8 -25
- package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js +24 -4
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +4 -3
- package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js +3 -9
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Cell/BuiltIns/GroupedCell.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js +3 -6
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Columns/Internal/Actions.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Footer/Footer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js +8 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterValue.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +6 -23
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js +2 -2
- package/dist/esm/packages/taco/src/primitives/Table/Core/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/useTableManager.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js +0 -11
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/dom.js +4 -7
- package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
- package/dist/index.css +2 -6
- package/dist/primitives/Table/Core/Table.d.ts +0 -1
- package/dist/primitives/Table/Core/components/Columns/Internal/Actions.d.ts +1 -3
- package/dist/primitives/Table/Core/components/Footer/Footer.d.ts +2 -2
- package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +2 -2
- package/dist/primitives/Table/Core/features/useTableStyle.d.ts +1 -1
- package/dist/primitives/Table/Core/types.d.ts +0 -3
- package/dist/primitives/Table/Core/useTable.d.ts +2 -2
- package/dist/primitives/Table/types.d.ts +2 -2
- package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
- package/dist/taco.cjs.development.js +627 -904
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/dist/utils/dom.d.ts +0 -1
- package/package.json +1 -1
- package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.d.ts +0 -7
- package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +0 -13
- package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +0 -11
- package/dist/components/Table3/features/useEditingState.d.ts +0 -28
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js +0 -34
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js.map +0 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +0 -88
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +0 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js +0 -95
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +0 -1
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js +0 -512
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +0 -1
@@ -1,9 +1,7 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import { setDataFocusAttribute
|
2
|
+
import { setDataFocusAttribute } from '../../../../utils/dom.js';
|
3
3
|
import { DisplayRow } from '../../../../primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js';
|
4
4
|
import { useAugmentedFocusManager } from '../../../../primitives/Table/Core/components/Body/util.js';
|
5
|
-
import { isTemporaryRow } from '../../util/editing.js';
|
6
|
-
import { DiscardChangesConfirmationDialog } from '../Editing/DiscardChangesConfirmationDialog.js';
|
7
5
|
import { SaveStatus } from './Editing/SaveStatus.js';
|
8
6
|
|
9
7
|
function Row(props) {
|
@@ -29,46 +27,15 @@ function Row(props) {
|
|
29
27
|
}
|
30
28
|
}
|
31
29
|
}, [tableMeta.editing.isEditing, isActiveRow]);
|
32
|
-
const rowStatus = tableMeta.editing.getRowStatus(row.id);
|
33
|
-
// discard new row
|
34
|
-
const [showDiscardDialog, setShowDiscardDialog] = React__default.useState(false);
|
35
|
-
function handleDiscard() {
|
36
|
-
tableMeta.editing.discardChanges(row.id, table);
|
37
|
-
requestAnimationFrame(() => {
|
38
|
-
if (isTemporaryRow(row.id)) {
|
39
|
-
var _tableMeta$editing$cr;
|
40
|
-
(_tableMeta$editing$cr = tableMeta.editing.createRowButtonRef.current) === null || _tableMeta$editing$cr === void 0 ? void 0 : _tableMeta$editing$cr.focus();
|
41
|
-
} else {
|
42
|
-
focusManager.focusFirst();
|
43
|
-
}
|
44
|
-
});
|
45
|
-
}
|
46
|
-
function handleKeyDown(event) {
|
47
|
-
if (props.onKeyDown) {
|
48
|
-
props.onKeyDown(event);
|
49
|
-
}
|
50
|
-
if (event.isDefaultPrevented() || event.isPropagationStopped()) {
|
51
|
-
return;
|
52
|
-
}
|
53
|
-
if (event.key === 'Escape' && tableMeta.editing.hasChanges(row.id) && !isElementTriggeredFromContainer(event.target, event.currentTarget)) {
|
54
|
-
event.preventDefault();
|
55
|
-
setShowDiscardDialog(true);
|
56
|
-
}
|
57
|
-
}
|
58
30
|
const attributes = {
|
59
|
-
'data-row-editing-invalid': tableMeta.editing.hasRowErrors(row.id) ? !tableMeta.editing.
|
60
|
-
'data-row-editing-status':
|
61
|
-
onFocus: handleFocus
|
62
|
-
onKeyDown: handleKeyDown
|
31
|
+
'data-row-editing-invalid': tableMeta.editing.isEnabled && tableMeta.editing.hasRowErrors(row.id) ? !tableMeta.editing.hasRowErrorsSeen(row.id) ? 'unseen' : true : undefined,
|
32
|
+
'data-row-editing-status': tableMeta.editing.isEnabled && tableMeta.editing.getRowSaveStatus(row.id) ? tableMeta.editing.getRowSaveStatus(row.id) : undefined,
|
33
|
+
onFocus: handleFocus
|
63
34
|
};
|
64
|
-
return /*#__PURE__*/React__default.createElement(
|
35
|
+
return /*#__PURE__*/React__default.createElement(DisplayRow, Object.assign({}, props, attributes), tableMeta.editing.getRowSaveStatus(row.id) ? /*#__PURE__*/React__default.createElement(SaveStatus, {
|
65
36
|
rowId: row.id,
|
66
37
|
table: table
|
67
|
-
}) : null)
|
68
|
-
open: showDiscardDialog,
|
69
|
-
onChange: setShowDiscardDialog,
|
70
|
-
onDiscard: handleDiscard
|
71
|
-
}));
|
38
|
+
}) : null);
|
72
39
|
}
|
73
40
|
|
74
41
|
export { Row };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Row.js","sources":["../../../../../../../../../src/components/Table3/components/Row/Row.tsx"],"sourcesContent":["import React from 'react';\nimport { TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { DisplayRow, DisplayRowProps } from '../../../../primitives/Table/Core/components/Row/BuiltIns/DisplayRow';\nimport { SaveStatus } from './Editing/SaveStatus';\nimport { useAugmentedFocusManager } from '../../../../primitives/Table/Core/components/Body/util';\nimport {
|
1
|
+
{"version":3,"file":"Row.js","sources":["../../../../../../../../../src/components/Table3/components/Row/Row.tsx"],"sourcesContent":["import React from 'react';\nimport { TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport { DisplayRow, DisplayRowProps } from '../../../../primitives/Table/Core/components/Row/BuiltIns/DisplayRow';\nimport { SaveStatus } from './Editing/SaveStatus';\nimport { useAugmentedFocusManager } from '../../../../primitives/Table/Core/components/Body/util';\nimport { setDataFocusAttribute } from '../../../../utils/dom';\n\nexport function Row<TType = unknown>(props: DisplayRowProps<TType>) {\n const { row, index, table } = props;\n const focusManager = useAugmentedFocusManager();\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === index;\n\n React.useEffect(() => {\n if (tableMeta.editing.isEditing && isActiveRow && tableMeta.editing.lastFocusedCellIndex === undefined) {\n setDataFocusAttribute(focusManager.focusFirst());\n }\n }, [tableMeta.editing.isEditing, tableMeta.rowActive.rowActiveIndex, tableMeta.editing.lastFocusedCellIndex]);\n\n const handleFocus = React.useCallback(\n (event: React.FocusEvent<HTMLTableRowElement>) => {\n if (tableMeta.editing.isEditing) {\n const cellIndex = Number(event.target.closest('td')?.getAttribute('data-cell-index') ?? undefined);\n\n if (!isNaN(cellIndex)) {\n tableMeta.editing.setLastFocusedCellIndex(Number(cellIndex));\n }\n }\n },\n [tableMeta.editing.isEditing, isActiveRow]\n );\n\n const attributes = {\n 'data-row-editing-invalid':\n tableMeta.editing.isEnabled && tableMeta.editing.hasRowErrors(row.id)\n ? !tableMeta.editing.hasRowErrorsSeen(row.id)\n ? 'unseen'\n : true\n : undefined,\n 'data-row-editing-status':\n tableMeta.editing.isEnabled && tableMeta.editing.getRowSaveStatus(row.id)\n ? tableMeta.editing.getRowSaveStatus(row.id)\n : undefined,\n onFocus: handleFocus,\n };\n\n return (\n <DisplayRow<TType> {...props} {...attributes}>\n {tableMeta.editing.getRowSaveStatus(row.id) ? <SaveStatus rowId={row.id} table={table} /> : null}\n </DisplayRow>\n );\n}\n"],"names":["Row","props","row","index","table","focusManager","useAugmentedFocusManager","tableMeta","options","meta","isActiveRow","rowActive","rowActiveIndex","React","useEffect","editing","isEditing","lastFocusedCellIndex","undefined","setDataFocusAttribute","focusFirst","handleFocus","useCallback","event","_event$target$closest","_event$target$closest2","cellIndex","Number","target","closest","getAttribute","isNaN","setLastFocusedCellIndex","attributes","isEnabled","hasRowErrors","id","hasRowErrorsSeen","getRowSaveStatus","onFocus","DisplayRow","SaveStatus","rowId"],"mappings":";;;;;;SAOgBA,GAAGA,CAAkBC,KAA6B;EAC9D,MAAM;IAAEC,GAAG;IAAEC,KAAK;IAAEC;GAAO,GAAGH,KAAK;EACnC,MAAMI,YAAY,GAAGC,wBAAwB,EAAE;EAC/C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,WAAW,GAAGH,SAAS,CAACI,SAAS,CAACC,cAAc,KAAKT,KAAK;EAEhEU,cAAK,CAACC,SAAS,CAAC;IACZ,IAAIP,SAAS,CAACQ,OAAO,CAACC,SAAS,IAAIN,WAAW,IAAIH,SAAS,CAACQ,OAAO,CAACE,oBAAoB,KAAKC,SAAS,EAAE;MACpGC,qBAAqB,CAACd,YAAY,CAACe,UAAU,EAAE,CAAC;;GAEvD,EAAE,CAACb,SAAS,CAACQ,OAAO,CAACC,SAAS,EAAET,SAAS,CAACI,SAAS,CAACC,cAAc,EAAEL,SAAS,CAACQ,OAAO,CAACE,oBAAoB,CAAC,CAAC;EAE7G,MAAMI,WAAW,GAAGR,cAAK,CAACS,WAAW,CAChCC,KAA4C;IACzC,IAAIhB,SAAS,CAACQ,OAAO,CAACC,SAAS,EAAE;MAAA,IAAAQ,qBAAA,EAAAC,sBAAA;MAC7B,MAAMC,SAAS,GAAGC,MAAM,EAAAH,qBAAA,IAAAC,sBAAA,GAACF,KAAK,CAACK,MAAM,CAACC,OAAO,CAAC,IAAI,CAAC,cAAAJ,sBAAA,uBAA1BA,sBAAA,CAA4BK,YAAY,CAAC,iBAAiB,CAAC,cAAAN,qBAAA,cAAAA,qBAAA,GAAIN,SAAS,CAAC;MAElG,IAAI,CAACa,KAAK,CAACL,SAAS,CAAC,EAAE;QACnBnB,SAAS,CAACQ,OAAO,CAACiB,uBAAuB,CAACL,MAAM,CAACD,SAAS,CAAC,CAAC;;;GAGvE,EACD,CAACnB,SAAS,CAACQ,OAAO,CAACC,SAAS,EAAEN,WAAW,CAAC,CAC7C;EAED,MAAMuB,UAAU,GAAG;IACf,0BAA0B,EACtB1B,SAAS,CAACQ,OAAO,CAACmB,SAAS,IAAI3B,SAAS,CAACQ,OAAO,CAACoB,YAAY,CAACjC,GAAG,CAACkC,EAAE,CAAC,GAC/D,CAAC7B,SAAS,CAACQ,OAAO,CAACsB,gBAAgB,CAACnC,GAAG,CAACkC,EAAE,CAAC,GACvC,QAAQ,GACR,IAAI,GACRlB,SAAS;IACnB,yBAAyB,EACrBX,SAAS,CAACQ,OAAO,CAACmB,SAAS,IAAI3B,SAAS,CAACQ,OAAO,CAACuB,gBAAgB,CAACpC,GAAG,CAACkC,EAAE,CAAC,GACnE7B,SAAS,CAACQ,OAAO,CAACuB,gBAAgB,CAACpC,GAAG,CAACkC,EAAE,CAAC,GAC1ClB,SAAS;IACnBqB,OAAO,EAAElB;GACZ;EAED,oBACIR,6BAAC2B,UAAU,oBAAYvC,KAAK,EAAMgC,UAAU,GACvC1B,SAAS,CAACQ,OAAO,CAACuB,gBAAgB,CAACpC,GAAG,CAACkC,EAAE,CAAC,gBAAGvB,6BAAC4B,UAAU;IAACC,KAAK,EAAExC,GAAG,CAACkC,EAAE;IAAEhC,KAAK,EAAEA;IAAS,GAAG,IAAI,CACvF;AAErB;;;;"}
|
@@ -30,20 +30,15 @@ function Editing(props) {
|
|
30
30
|
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.click();
|
31
31
|
});
|
32
32
|
const handleChange = enabled => {
|
33
|
-
|
34
|
-
tableMeta.rowActive.setRowActiveIndex(0);
|
35
|
-
}
|
33
|
+
tableMeta.editing.toggleEditing(enabled);
|
36
34
|
requestAnimationFrame(() => {
|
37
35
|
var _tableMeta$rowActive$;
|
38
|
-
|
39
|
-
tableMeta.editing.toggleEditing(enabled, table);
|
40
|
-
scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
|
36
|
+
return scrollToIndex((_tableMeta$rowActive$ = tableMeta.rowActive.rowActiveIndex) !== null && _tableMeta$rowActive$ !== void 0 ? _tableMeta$rowActive$ : 0);
|
41
37
|
});
|
42
38
|
};
|
43
39
|
return /*#__PURE__*/React__default.createElement(Tooltip, {
|
44
40
|
title: tooltip
|
45
41
|
}, /*#__PURE__*/React__default.createElement(ModeSwitch, {
|
46
|
-
"data-table": "editing-toggle",
|
47
42
|
checked: tableMeta.editing.isEditing,
|
48
43
|
onChange: handleChange,
|
49
44
|
ref: ref
|
package/dist/esm/packages/taco/src/components/Table3/components/Toolbar/Editing/Editing.js.map
CHANGED
@@ -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
|
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,27 +1,29 @@
|
|
1
1
|
import React__default from 'react';
|
2
|
-
import {
|
2
|
+
import { useGlobalKeyDown } from '../../../hooks/useGlobalKeyDown.js';
|
3
|
+
import { useLocalization } from '../../Provider/Localization.js';
|
4
|
+
import { _forOf, _catch } from '../../../../../../node_modules/babel-plugin-transform-async-to-promises/helpers.mjs.js';
|
5
|
+
import { willRowMove } from '../util/editing.js';
|
6
|
+
import { debounce } from 'lodash-es';
|
3
7
|
|
4
|
-
function useTableEditing(isEnabled = false, handleSave, handleChange,
|
8
|
+
function useTableEditing(isEnabled = false, handleSave, handleChange, validator) {
|
5
9
|
// used to switch the table into editing mode
|
6
|
-
const [isEditing,
|
10
|
+
const [isEditing, toggleEditing] = React__default.useState(false);
|
7
11
|
// used to switch the editing between "detailed" mode
|
8
12
|
const [isDetailedMode, toggleDetailedMode] = React__default.useState(false);
|
9
|
-
// used to contain ref to the create button
|
10
|
-
const createRowButtonRef = React__default.useRef(null);
|
11
13
|
// store the last focused cell, so that up/down arrow key navigation remains in the same column
|
12
|
-
const [lastFocusedCellIndex, setLastFocusedCellIndex] =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
14
|
+
const [lastFocusedCellIndex, setLastFocusedCellIndex] = useLastFocusedCellIndex();
|
15
|
+
// store pending changes for each row
|
16
|
+
// changes are saved as soon as the active row changes, so in most cases this will only contain the active row's changes
|
17
|
+
// but not always - if validation or server requests fail when saving, those rows remain until the failure is resolved
|
18
|
+
const pendingChangesFns = usePendingChanges(isEnabled, handleSave, handleChange, validator);
|
19
|
+
useGlobalKeyDown(isEnabled && isEditing ? {
|
20
|
+
key: 's',
|
21
|
+
meta: true,
|
22
|
+
shift: false
|
23
|
+
} : undefined, event => {
|
24
|
+
event.preventDefault();
|
25
|
+
pendingChangesFns.saveChanges();
|
26
|
+
});
|
25
27
|
return {
|
26
28
|
isEnabled,
|
27
29
|
isEditing,
|
@@ -30,10 +32,395 @@ function useTableEditing(isEnabled = false, handleSave, handleChange, rowIdentit
|
|
30
32
|
toggleEditing: isEnabled ? toggleEditing : () => undefined,
|
31
33
|
lastFocusedCellIndex,
|
32
34
|
setLastFocusedCellIndex,
|
33
|
-
createRowButtonRef,
|
34
35
|
...pendingChangesFns
|
35
36
|
};
|
36
37
|
}
|
38
|
+
function usePendingChanges(isEnabled, handleSave, handleChange, validator) {
|
39
|
+
const saveChanges = function (rowId = undefined) {
|
40
|
+
try {
|
41
|
+
let _exit = false;
|
42
|
+
if (!handleSave) {
|
43
|
+
console.warn('Tried to save, but Table has no onEditingSave handler');
|
44
|
+
return Promise.resolve();
|
45
|
+
}
|
46
|
+
// we save back to pendingChanges, so make a copy of it's state when save was triggered
|
47
|
+
const changesToSave = rowId ? {
|
48
|
+
[rowId]: pendingChanges[rowId]
|
49
|
+
} : {
|
50
|
+
...pendingChanges
|
51
|
+
};
|
52
|
+
const changes = Object.keys(changesToSave);
|
53
|
+
return Promise.resolve(function () {
|
54
|
+
if (changes.length) {
|
55
|
+
return _forOf(changes, function (rowId) {
|
56
|
+
const pendingChange = changesToSave[rowId];
|
57
|
+
const changeSet = getChangesetFromChanges(pendingChange);
|
58
|
+
return _catch(function () {
|
59
|
+
function _temp3(_result) {
|
60
|
+
return _exit ? _result : Promise.resolve(handleSave(changeSet)).then(function () {
|
61
|
+
// cleanup changes, we don't need them after saving
|
62
|
+
resetChanges(rowId);
|
63
|
+
setRowSaveStatus(rowId, 'complete');
|
64
|
+
});
|
65
|
+
}
|
66
|
+
if (getRowSaveStatus(rowId) === 'pending') {
|
67
|
+
_exit = true;
|
68
|
+
return;
|
69
|
+
}
|
70
|
+
// set saving = true
|
71
|
+
setRowSaveStatus(rowId, 'pending');
|
72
|
+
// re-run validation, maybe a cell is already invalid but has never been blurred
|
73
|
+
const _temp2 = function () {
|
74
|
+
if (validator) {
|
75
|
+
return Promise.resolve(validator(changeSet)).then(function (errors) {
|
76
|
+
if (errors && Object.keys(errors).length) {
|
77
|
+
throw errors;
|
78
|
+
}
|
79
|
+
});
|
80
|
+
}
|
81
|
+
}();
|
82
|
+
return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2); // send new data to the server
|
83
|
+
}, function (error) {
|
84
|
+
// the onEditingSave handler should throw errors when something fails, e.g. validation, network errors etc
|
85
|
+
// this code handles those errors and maps them either to row errors or cell specific errors
|
86
|
+
let rowError;
|
87
|
+
let cellErrors;
|
88
|
+
if (typeof error === 'string') {
|
89
|
+
rowError = error;
|
90
|
+
} else if (error instanceof Error) {
|
91
|
+
var _error$response;
|
92
|
+
rowError = error.message;
|
93
|
+
// most of our apis return error objects within this shape
|
94
|
+
if (typeof ((_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data) === 'object') {
|
95
|
+
var _error$response2;
|
96
|
+
cellErrors = (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.data;
|
97
|
+
}
|
98
|
+
} else if (typeof error === 'object') {
|
99
|
+
cellErrors = error;
|
100
|
+
}
|
101
|
+
if (rowError || cellErrors) {
|
102
|
+
setPendingChanges(currentChanges => {
|
103
|
+
const nextChanges = {
|
104
|
+
...currentChanges
|
105
|
+
};
|
106
|
+
nextChanges[rowId]._meta.errors = {
|
107
|
+
row: rowError,
|
108
|
+
cells: cellErrors,
|
109
|
+
shouldShowErrorAlert: true
|
110
|
+
};
|
111
|
+
return nextChanges;
|
112
|
+
});
|
113
|
+
}
|
114
|
+
setRowSaveStatus(rowId, undefined);
|
115
|
+
});
|
116
|
+
}, function () {
|
117
|
+
return _exit;
|
118
|
+
});
|
119
|
+
}
|
120
|
+
}());
|
121
|
+
} catch (e) {
|
122
|
+
return Promise.reject(e);
|
123
|
+
}
|
124
|
+
};
|
125
|
+
const validateCell = function (cell) {
|
126
|
+
try {
|
127
|
+
if (!validator || !isEnabled) {
|
128
|
+
return Promise.resolve();
|
129
|
+
}
|
130
|
+
const changeSet = getChangesetFromChanges(pendingChanges[cell.row.id]);
|
131
|
+
// only validate if the cell being blurred actually has any changes
|
132
|
+
const _temp = function () {
|
133
|
+
if (cell.column.id in changeSet) {
|
134
|
+
return Promise.resolve(validator(changeSet)).then(function (errors) {
|
135
|
+
setPendingChanges(currentChanges => {
|
136
|
+
const nextChanges = {
|
137
|
+
...currentChanges
|
138
|
+
};
|
139
|
+
nextChanges[cell.row.id]._meta = {
|
140
|
+
...nextChanges[cell.row.id]._meta,
|
141
|
+
errors: {
|
142
|
+
...nextChanges[cell.row.id]._meta.errors,
|
143
|
+
cells: errors,
|
144
|
+
shouldShowErrorAlert: !Object.keys(errors).length ? false : nextChanges[cell.row.id]._meta.errors.shouldShowErrorAlert
|
145
|
+
}
|
146
|
+
};
|
147
|
+
return nextChanges;
|
148
|
+
});
|
149
|
+
});
|
150
|
+
}
|
151
|
+
}();
|
152
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
153
|
+
} catch (e) {
|
154
|
+
return Promise.reject(e);
|
155
|
+
}
|
156
|
+
};
|
157
|
+
const setCellValue = function (cell, change, rowIndex) {
|
158
|
+
try {
|
159
|
+
const changes = {
|
160
|
+
[cell.column.id]: change
|
161
|
+
};
|
162
|
+
setPendingChanges(currentChanges => {
|
163
|
+
const nextChanges = createPendingChangesSetter(currentChanges, cell.row, rowIndex, changes, localization);
|
164
|
+
pendingChangesUpdater.syncCellChanges(nextChanges);
|
165
|
+
return nextChanges;
|
166
|
+
});
|
167
|
+
pendingChangesUpdater.runCellUpdates(changes, cell, rowIndex);
|
168
|
+
return Promise.resolve();
|
169
|
+
} catch (e) {
|
170
|
+
return Promise.reject(e);
|
171
|
+
}
|
172
|
+
};
|
173
|
+
const addCreatedRowChangeset = function (row) {
|
174
|
+
try {
|
175
|
+
const cells = row.getAllCells();
|
176
|
+
setPendingChanges(currentChanges => {
|
177
|
+
return cells.reduce((changes, cell) => {
|
178
|
+
if (cell.getValue()) {
|
179
|
+
var _currentChanges$cell$, _currentChanges$cell$2, _currentChanges$cell$3;
|
180
|
+
return {
|
181
|
+
...changes,
|
182
|
+
[cell.row.id]: {
|
183
|
+
...changes[cell.row.id],
|
184
|
+
[cell.column.id]: cell.getValue(),
|
185
|
+
_meta: {
|
186
|
+
...((_currentChanges$cell$ = currentChanges[cell.row.id]) === null || _currentChanges$cell$ === void 0 ? void 0 : _currentChanges$cell$._meta),
|
187
|
+
original: cell.row.original,
|
188
|
+
moveReason: {
|
189
|
+
...((_currentChanges$cell$2 = currentChanges[cell.row.id]) === null || _currentChanges$cell$2 === void 0 ? void 0 : _currentChanges$cell$2._meta.moveReason)
|
190
|
+
},
|
191
|
+
errors: {
|
192
|
+
...((_currentChanges$cell$3 = currentChanges[cell.row.id]) === null || _currentChanges$cell$3 === void 0 ? void 0 : _currentChanges$cell$3._meta.errors)
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
};
|
197
|
+
} else {
|
198
|
+
return changes;
|
199
|
+
}
|
200
|
+
}, currentChanges);
|
201
|
+
});
|
202
|
+
return Promise.resolve();
|
203
|
+
} catch (e) {
|
204
|
+
return Promise.reject(e);
|
205
|
+
}
|
206
|
+
};
|
207
|
+
const localization = useLocalization();
|
208
|
+
const [pendingChanges, setPendingChanges] = React__default.useState({});
|
209
|
+
// we maintain save status as separate state because 'complete' needs to briefly show after pendingChanges are deleted
|
210
|
+
const [saveStates, setSaveState] = React__default.useState({});
|
211
|
+
function getCellValue(cell) {
|
212
|
+
var _pendingChanges$cell$;
|
213
|
+
return (_pendingChanges$cell$ = pendingChanges[cell.row.id]) === null || _pendingChanges$cell$ === void 0 ? void 0 : _pendingChanges$cell$[cell.column.id];
|
214
|
+
}
|
215
|
+
function getCellError(cell) {
|
216
|
+
var _pendingChanges$cell$2, _pendingChanges$cell$3, _pendingChanges$cell$4;
|
217
|
+
return (_pendingChanges$cell$2 = pendingChanges[cell.row.id]) === null || _pendingChanges$cell$2 === void 0 ? void 0 : (_pendingChanges$cell$3 = _pendingChanges$cell$2._meta.errors) === null || _pendingChanges$cell$3 === void 0 ? void 0 : (_pendingChanges$cell$4 = _pendingChanges$cell$3.cells) === null || _pendingChanges$cell$4 === void 0 ? void 0 : _pendingChanges$cell$4[cell.column.id];
|
218
|
+
}
|
219
|
+
const pendingChangesUpdater = usePendingChangesUpdater(handleChange, setPendingChanges);
|
220
|
+
function hasRowErrors(rowId) {
|
221
|
+
var _pendingChanges$rowId, _pendingChanges$rowId2, _pendingChanges$rowId3, _pendingChanges$rowId4, _pendingChanges$rowId5;
|
222
|
+
if (!isEnabled) {
|
223
|
+
return false;
|
224
|
+
}
|
225
|
+
return !!((_pendingChanges$rowId = pendingChanges[rowId]) !== null && _pendingChanges$rowId !== void 0 && (_pendingChanges$rowId2 = _pendingChanges$rowId._meta.errors) !== null && _pendingChanges$rowId2 !== void 0 && _pendingChanges$rowId2.row) || !!Object.keys((_pendingChanges$rowId3 = (_pendingChanges$rowId4 = pendingChanges[rowId]) === null || _pendingChanges$rowId4 === void 0 ? void 0 : (_pendingChanges$rowId5 = _pendingChanges$rowId4._meta.errors) === null || _pendingChanges$rowId5 === void 0 ? void 0 : _pendingChanges$rowId5.cells) !== null && _pendingChanges$rowId3 !== void 0 ? _pendingChanges$rowId3 : {}).length;
|
226
|
+
}
|
227
|
+
function hasRowErrorsSeen(rowId) {
|
228
|
+
var _pendingChanges$rowId6;
|
229
|
+
if (!isEnabled) {
|
230
|
+
return false;
|
231
|
+
}
|
232
|
+
return hasRowErrors(rowId) && !!((_pendingChanges$rowId6 = pendingChanges[rowId]._meta.errors) !== null && _pendingChanges$rowId6 !== void 0 && _pendingChanges$rowId6.shouldShowErrorAlert);
|
233
|
+
}
|
234
|
+
function getRowPendingChange(rowId) {
|
235
|
+
const rowPendingChanges = pendingChanges[rowId];
|
236
|
+
if (rowPendingChanges) {
|
237
|
+
const {
|
238
|
+
_meta,
|
239
|
+
...pendingChange
|
240
|
+
} = rowPendingChanges;
|
241
|
+
return pendingChange;
|
242
|
+
}
|
243
|
+
return undefined;
|
244
|
+
}
|
245
|
+
function getRowSaveStatus(rowId) {
|
246
|
+
if (!isEnabled) {
|
247
|
+
return false;
|
248
|
+
}
|
249
|
+
return saveStates[rowId];
|
250
|
+
}
|
251
|
+
function setRowSaveStatus(rowId, status) {
|
252
|
+
setSaveState(currentStates => {
|
253
|
+
const nextStates = {
|
254
|
+
...currentStates
|
255
|
+
};
|
256
|
+
if (status) {
|
257
|
+
nextStates[rowId] = status;
|
258
|
+
} else {
|
259
|
+
delete nextStates[rowId];
|
260
|
+
}
|
261
|
+
return nextStates;
|
262
|
+
});
|
263
|
+
}
|
264
|
+
function getRowMoveReason(rowId) {
|
265
|
+
var _pendingChanges$rowId7;
|
266
|
+
return (_pendingChanges$rowId7 = pendingChanges[rowId]) !== null && _pendingChanges$rowId7 !== void 0 && _pendingChanges$rowId7._meta.moveReason ? Object.values(pendingChanges[rowId]._meta.moveReason)[0] : undefined;
|
267
|
+
}
|
268
|
+
function hasChanges(rowId) {
|
269
|
+
if (!isEnabled) {
|
270
|
+
return false;
|
271
|
+
}
|
272
|
+
return rowId ? !!pendingChanges[rowId] : !!Object.keys(pendingChanges).length;
|
273
|
+
}
|
274
|
+
function hasAlertErrors() {
|
275
|
+
if (!isEnabled) {
|
276
|
+
return false;
|
277
|
+
}
|
278
|
+
return !!getAlertErrors().length;
|
279
|
+
}
|
280
|
+
function getAlertErrors() {
|
281
|
+
return Object.keys(pendingChanges).filter(hasRowErrorsSeen).map(rowId => ({
|
282
|
+
rowId,
|
283
|
+
pendingChange: pendingChanges[rowId]
|
284
|
+
}));
|
285
|
+
}
|
286
|
+
function resetChanges(rowId) {
|
287
|
+
setPendingChanges(currentChanges => {
|
288
|
+
const nextChanges = {
|
289
|
+
...currentChanges
|
290
|
+
};
|
291
|
+
delete nextChanges[rowId];
|
292
|
+
return nextChanges;
|
293
|
+
});
|
294
|
+
}
|
295
|
+
function getCompletedRowsCount() {
|
296
|
+
return Object.values(saveStates).filter(value => value === 'complete').length;
|
297
|
+
}
|
298
|
+
return {
|
299
|
+
getCellValue,
|
300
|
+
getCellError,
|
301
|
+
setCellValue,
|
302
|
+
validateCell,
|
303
|
+
addCreatedRowChangeset,
|
304
|
+
hasChanges,
|
305
|
+
hasAlertErrors,
|
306
|
+
getAlertErrors,
|
307
|
+
saveChanges,
|
308
|
+
resetChanges,
|
309
|
+
hasRowErrors,
|
310
|
+
hasRowErrorsSeen,
|
311
|
+
getRowPendingChange,
|
312
|
+
getRowSaveStatus,
|
313
|
+
setRowSaveStatus,
|
314
|
+
getRowMoveReason,
|
315
|
+
getCompletedRowsCount
|
316
|
+
};
|
317
|
+
}
|
318
|
+
function useLastFocusedCellIndex() {
|
319
|
+
// store the last focused cell, so that up/down arrow key navigation remains in the same column
|
320
|
+
const lastFocusedCellIndexRef = React__default.useRef(undefined);
|
321
|
+
const setLastFocusedCellIndex = React__default.useCallback(index => {
|
322
|
+
lastFocusedCellIndexRef.current = index;
|
323
|
+
}, []);
|
324
|
+
return [lastFocusedCellIndexRef.current, setLastFocusedCellIndex];
|
325
|
+
}
|
326
|
+
function usePendingChangesUpdater(handleChange, setPendingChanges) {
|
327
|
+
const localization = useLocalization();
|
328
|
+
const updatersRef = React__default.useRef({});
|
329
|
+
const runCellUpdates = React__default.useCallback(debounce(function (changes, cell, rowIndex) {
|
330
|
+
try {
|
331
|
+
const _temp4 = function () {
|
332
|
+
if (typeof handleChange === 'function') {
|
333
|
+
const previousValues = {
|
334
|
+
...cell.row.original,
|
335
|
+
...getChangesetFromChanges(updatersRef.current[cell.row.id])
|
336
|
+
};
|
337
|
+
const nextValues = {
|
338
|
+
...previousValues,
|
339
|
+
...changes
|
340
|
+
};
|
341
|
+
return Promise.resolve(handleChange(cell.column.id, changes[cell.column.id], nextValues, previousValues)).then(function (updates) {
|
342
|
+
if (updates && Object.keys(updates).length) {
|
343
|
+
setPendingChanges(currentChanges => createPendingChangesSetter(currentChanges, cell.row, rowIndex, updates, localization));
|
344
|
+
}
|
345
|
+
});
|
346
|
+
}
|
347
|
+
}();
|
348
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {}) : void 0);
|
349
|
+
} catch (e) {
|
350
|
+
return Promise.reject(e);
|
351
|
+
}
|
352
|
+
}, 250), []);
|
353
|
+
function syncCellChanges(changes) {
|
354
|
+
updatersRef.current = changes;
|
355
|
+
}
|
356
|
+
return {
|
357
|
+
syncCellChanges,
|
358
|
+
runCellUpdates
|
359
|
+
};
|
360
|
+
}
|
361
|
+
function createPendingChangesSetter(currentChanges, row, rowIndex, changes, localization) {
|
362
|
+
var _currentChanges$row$i, _currentChanges$row$i2, _currentChanges$row$i3;
|
363
|
+
// prepare
|
364
|
+
const nextChanges = {
|
365
|
+
...currentChanges
|
366
|
+
};
|
367
|
+
const rowChanges = {
|
368
|
+
...currentChanges[row.id],
|
369
|
+
_meta: {
|
370
|
+
...((_currentChanges$row$i = currentChanges[row.id]) === null || _currentChanges$row$i === void 0 ? void 0 : _currentChanges$row$i._meta),
|
371
|
+
original: row.original,
|
372
|
+
moveReason: {
|
373
|
+
...((_currentChanges$row$i2 = currentChanges[row.id]) === null || _currentChanges$row$i2 === void 0 ? void 0 : _currentChanges$row$i2._meta.moveReason)
|
374
|
+
},
|
375
|
+
errors: {
|
376
|
+
...((_currentChanges$row$i3 = currentChanges[row.id]) === null || _currentChanges$row$i3 === void 0 ? void 0 : _currentChanges$row$i3._meta.errors)
|
377
|
+
}
|
378
|
+
}
|
379
|
+
};
|
380
|
+
// run changes
|
381
|
+
const cells = row._getAllCellsByColumnId();
|
382
|
+
for (const [accessor, change] of Object.entries(changes)) {
|
383
|
+
// update if the change is different to the original (saved) value,
|
384
|
+
// otherwise remove any change - no point saving the same value
|
385
|
+
if (change !== row.original[accessor]) {
|
386
|
+
rowChanges[accessor] = change;
|
387
|
+
// consumers sometimes include properties in onEditingChange that aren't rendered as columns, we need to guard against that.
|
388
|
+
// eslint-disable-next-line no-prototype-builtins
|
389
|
+
if (cells.hasOwnProperty(accessor)) {
|
390
|
+
// determine if the row will move position based on this change, and save why it will move
|
391
|
+
const reason = willRowMove(cells[accessor], change, rowIndex, localization);
|
392
|
+
if (reason) {
|
393
|
+
rowChanges._meta.moveReason[accessor] = reason;
|
394
|
+
} else {
|
395
|
+
delete rowChanges._meta.moveReason[accessor];
|
396
|
+
}
|
397
|
+
}
|
398
|
+
} else {
|
399
|
+
delete rowChanges[accessor];
|
400
|
+
delete rowChanges._meta.moveReason[accessor];
|
401
|
+
}
|
402
|
+
}
|
403
|
+
// set changes
|
404
|
+
// or delete if there are no changes left, so that we don't store changes with unchanged data
|
405
|
+
if (Object.keys(rowChanges).filter(k => k !== '_meta').length) {
|
406
|
+
nextChanges[row.id] = rowChanges;
|
407
|
+
} else {
|
408
|
+
delete nextChanges[row.id];
|
409
|
+
}
|
410
|
+
return nextChanges;
|
411
|
+
}
|
412
|
+
function getChangesetFromChanges(changes) {
|
413
|
+
// extract the original data from the row changes
|
414
|
+
const {
|
415
|
+
_meta,
|
416
|
+
...changeset
|
417
|
+
} = changes !== null && changes !== void 0 ? changes : {};
|
418
|
+
// and mix them in with the changes, ready to send to the server
|
419
|
+
return {
|
420
|
+
...(_meta === null || _meta === void 0 ? void 0 : _meta.original),
|
421
|
+
...changeset
|
422
|
+
};
|
423
|
+
}
|
37
424
|
|
38
425
|
export { useTableEditing };
|
39
426
|
//# sourceMappingURL=useTableEditing.js.map
|