@economic/taco 2.45.4 → 2.46.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Provider/Localization.d.ts +2 -0
- package/dist/components/Report/Report.d.ts +1 -1
- package/dist/components/Table3/Table3.d.ts +2 -14
- package/dist/components/Table3/components/Columns/Internal/EditingActionsMenu.d.ts +1 -2
- package/dist/components/Table3/components/Editing/DiscardChangesConfirmationDialog.d.ts +7 -0
- package/dist/components/Table3/components/Row/Editing/CreateNewRow.d.ts +14 -0
- package/dist/components/Table3/components/Row/Editing/TemporaryRow.d.ts +11 -0
- package/dist/components/Table3/features/useEditingState.d.ts +29 -0
- package/dist/components/Table3/features/useTableEditing.d.ts +26 -36
- package/dist/components/Table3/listeners/useTableEditingListener.d.ts +1 -1
- package/dist/components/Table3/types.d.ts +24 -8
- package/dist/components/Table3/useTable3.d.ts +6 -0
- package/dist/components/Table3/util/editing.d.ts +7 -1
- package/dist/esm/index.css +28 -4
- 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 +5 -3
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/Select2.js +1 -1
- package/dist/esm/packages/taco/src/components/Select2/Select2.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 +14 -6
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/Editing/RowMoveIndicator.js +1 -2
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/Editing/RowMoveIndicator.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +25 -11
- 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 +5 -37
- 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 +17 -12
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/Alert.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js +34 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Editing/DiscardChangesConfirmationDialog.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js +103 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateNewRow.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/SaveStatus.js +2 -14
- 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/Editing/TemporaryRow.js +96 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/TemporaryRow.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js +39 -6
- 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 +4 -17
- 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/useEditingState.js +519 -0
- package/dist/esm/packages/taco/src/components/Table3/features/useEditingState.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +29 -406
- 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 +44 -33
- package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/useTable3.js +34 -13
- package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js +11 -23
- 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 +1 -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 +9 -3
- 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 +9 -7
- 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.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/Row/Row.js +4 -2
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/RowContext.js +2 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/RowContext.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +29 -7
- 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 +11 -0
- package/dist/esm/packages/taco/src/primitives/Table/useTableManager/util/setup.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/dom.js +7 -4
- package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
- package/dist/index.css +28 -4
- package/dist/primitives/Table/Core/components/Columns/Internal/Actions.d.ts +3 -1
- package/dist/primitives/Table/Core/components/Footer/Footer.d.ts +2 -2
- package/dist/primitives/Table/Core/components/Row/RowContext.d.ts +1 -0
- package/dist/primitives/Table/Core/features/useTableRenderer.d.ts +2 -2
- package/dist/primitives/Table/Core/types.d.ts +4 -0
- package/dist/primitives/Table/Core/useTable.d.ts +2 -2
- package/dist/primitives/Table/types.d.ts +1 -1
- package/dist/primitives/Table/useTableManager/useTableManager.d.ts +1 -1
- package/dist/taco.cjs.development.js +987 -660
- 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 +1 -0
- package/package.json +2 -2
- package/dist/components/Table3/components/Row/Editing/CreateRowButton.d.ts +0 -11
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js +0 -90
- package/dist/esm/packages/taco/src/components/Table3/components/Row/Editing/CreateRowButton.js.map +0 -1
@@ -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 { 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
|
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 { isElementTriggeredFromContainer, setDataFocusAttribute } from '../../../../utils/dom';\nimport { DiscardChangesConfirmationDialog } from '../Editing/DiscardChangesConfirmationDialog';\nimport { isTemporaryRow } from '../../util/editing';\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 rowStatus = tableMeta.editing.getRowStatus(row.id);\n\n // discard new row\n const [showDiscardDialog, setShowDiscardDialog] = React.useState(false);\n\n function handleDiscard() {\n tableMeta.editing.discardChanges(row.id, table);\n requestAnimationFrame(() => {\n if (isTemporaryRow(row.id)) {\n tableMeta.editing.createRowButtonRef.current?.focus();\n } else {\n focusManager.focusFirst();\n }\n });\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLTableRowElement>) {\n if (props.onKeyDown) {\n props.onKeyDown(event);\n }\n\n if (event.isDefaultPrevented() || event.isPropagationStopped()) {\n return;\n }\n\n if (\n event.key === 'Escape' &&\n tableMeta.editing.hasChanges(row.id) &&\n !isElementTriggeredFromContainer(event.target as HTMLElement, event.currentTarget)\n ) {\n event.preventDefault();\n setShowDiscardDialog(true);\n }\n }\n\n const attributes = {\n 'data-row-editing-invalid': tableMeta.editing.hasRowErrors(row.id)\n ? !tableMeta.editing.hasRowErrorsShownInAlert(row.id)\n ? 'unseen'\n : true\n : undefined,\n 'data-row-editing-status': rowStatus,\n onFocus: handleFocus,\n onKeyDown: handleKeyDown,\n };\n\n return (\n <>\n <DisplayRow<TType> {...props} {...attributes}>\n {rowStatus === 'saving' || rowStatus === 'saved' ? <SaveStatus rowId={row.id} table={table} /> : null}\n </DisplayRow>\n <DiscardChangesConfirmationDialog\n open={showDiscardDialog}\n onChange={setShowDiscardDialog}\n onDiscard={handleDiscard}\n />\n </>\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","rowStatus","getRowStatus","id","showDiscardDialog","setShowDiscardDialog","useState","handleDiscard","discardChanges","requestAnimationFrame","isTemporaryRow","_tableMeta$editing$cr","createRowButtonRef","current","focus","handleKeyDown","onKeyDown","isDefaultPrevented","isPropagationStopped","key","hasChanges","isElementTriggeredFromContainer","currentTarget","preventDefault","attributes","hasRowErrors","hasRowErrorsShownInAlert","onFocus","DisplayRow","SaveStatus","rowId","DiscardChangesConfirmationDialog","open","onChange","onDiscard"],"mappings":"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"}
|
@@ -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
|
19
|
-
|
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
|
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 {
|
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
|