@economic/taco 2.20.2 → 2.20.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Table3/hooks/features/useEditing.d.ts +2 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useEditing.js +16 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useEditing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/taco.cjs.development.js +16 -2
- 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/package.json +2 -2
- package/types.json +3714 -3668
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { Cell as RTCell } from '@tanstack/react-table';
|
3
|
-
import { Table3SaveHandler } from '../../types';
|
3
|
+
import { Table3Ref, Table3SaveHandler } from '../../types';
|
4
4
|
import { IndicatorReason } from '../../components/columns/cell/Indicator';
|
5
5
|
import { Table3Validation } from './useValidation';
|
6
6
|
export declare enum SavingStatusValue {
|
@@ -8,7 +8,7 @@ export declare enum SavingStatusValue {
|
|
8
8
|
Saved = "saved",
|
9
9
|
Error = "error"
|
10
10
|
}
|
11
|
-
export declare function useEditing<TType = unknown>(isEnabled: boolean, validation: Table3Validation<TType>, onSave?: Table3SaveHandler<TType>): {
|
11
|
+
export declare function useEditing<TType = unknown>(isEnabled: boolean, tableRef: React.RefObject<Table3Ref>, validation: Table3Validation<TType>, onSave?: Table3SaveHandler<TType>): {
|
12
12
|
isEnabled: boolean;
|
13
13
|
isEditing: boolean;
|
14
14
|
toggleEditing: React.Dispatch<React.SetStateAction<boolean>>;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import React__default from 'react';
|
2
2
|
import { shouldTriggerShortcut } from '../../../../utils/keyboard.js';
|
3
|
+
import { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom.js';
|
3
4
|
import _ from 'lodash-es';
|
4
5
|
import { lastCellIndex } from '../../components/rows/Row.js';
|
5
6
|
|
@@ -9,7 +10,7 @@ var SavingStatusValue;
|
|
9
10
|
SavingStatusValue["Saved"] = "saved";
|
10
11
|
SavingStatusValue["Error"] = "error";
|
11
12
|
})(SavingStatusValue || (SavingStatusValue = {}));
|
12
|
-
function useEditing(isEnabled, validation, onSave) {
|
13
|
+
function useEditing(isEnabled, tableRef, validation, onSave) {
|
13
14
|
// used to switch the table into editing mode
|
14
15
|
const [isEditing, setIsEditing] = React__default.useState(false);
|
15
16
|
// Saving indicator need to show saving status per row, saving status can have at least two states 'saving', 'saved',
|
@@ -176,6 +177,20 @@ function useEditing(isEnabled, validation, onSave) {
|
|
176
177
|
}
|
177
178
|
return false;
|
178
179
|
}, [isEditing, editingState]);
|
180
|
+
React__default.useEffect(() => {
|
181
|
+
const handleClickOutside = event => {
|
182
|
+
const target = event.target;
|
183
|
+
const closestPopup = target.closest('[role="dialog"], [role="menu"]');
|
184
|
+
// Need to check that neither target itself nor closest popup is inside or triggetred from the table.
|
185
|
+
if (!isElementInsideOrTriggeredFromContainer(target, tableRef.current) && !isElementInsideOrTriggeredFromContainer(closestPopup, tableRef.current)) {
|
186
|
+
saveChangesIfNeeded();
|
187
|
+
}
|
188
|
+
};
|
189
|
+
document.addEventListener('click', handleClickOutside);
|
190
|
+
return () => {
|
191
|
+
document.removeEventListener('click', handleClickOutside);
|
192
|
+
};
|
193
|
+
}, [saveChangesIfNeeded]);
|
179
194
|
function getSavingStatus(rowId) {
|
180
195
|
return savingStatuses && savingStatuses[rowId];
|
181
196
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useEditing.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useEditing.tsx"],"sourcesContent":["import React from 'react';\nimport _ from 'lodash';\nimport { Cell as RTCell } from '@tanstack/react-table';\n\nimport { Table3SaveHandler } from '../../types';\nimport { IndicatorReason } from '../../components/columns/cell/Indicator';\nimport { shouldTriggerShortcut } from '../../../../utils/keyboard';\nimport { Table3Validation } from './useValidation';\nimport { lastCellIndex } from '../../components/rows/Row';\n\nexport enum SavingStatusValue {\n Saving = 'saving',\n Saved = 'saved',\n Error = 'error',\n}\n\nexport function useEditing<TType = unknown>(\n isEnabled: boolean,\n validation: Table3Validation<TType>,\n onSave?: Table3SaveHandler<TType>\n) {\n // used to switch the table into editing mode\n const [isEditing, setIsEditing] = React.useState(false);\n // Saving indicator need to show saving status per row, saving status can have at least two states 'saving', 'saved',\n // 'saved' should remain for a few seconds to show tick icon after row has been saved.\n const [savingStatuses, dispatchSavingStatusAction] = React.useReducer(savingStatusesReducer, null);\n\n // sets of row changes pending save, either they have not saved yet or they have errors\n const [editingState, dispatchEditingAction] = React.useReducer((state: EditingState<TType>, action) => editingReducer<TType>(state, action), null);\n\n const [detailModeEditing, setDetailModeEditing] = React.useState(false);\n\n function getCellValue<T extends TType>(cell: RTCell<T, unknown>) {\n return editingState ? editingState[cell.row.id]?.[cell.column.id] : undefined;\n }\n\n // Saves editing cell value into editing state.\n function setCellValue<T extends TType>(cell: RTCell<T, unknown>, value: unknown) {\n dispatchEditingAction({\n type: EditingActionType.SET_CELL_VALUE,\n payload: { rowId: cell.row.id, cellId: cell.column.id, value, originalValues: cell.row.original },\n });\n }\n\n // Removes changes from editing state by row id\n function resetChange(rowId: string) {\n dispatchEditingAction({\n type: EditingActionType.RESET_CHANGE,\n payload: { rowId },\n });\n validation.resetErrors(rowId);\n }\n\n const handleKeyDown = React.useCallback(\n (event: KeyboardEvent) => {\n if (event.defaultPrevented) {\n return;\n }\n\n if (shouldTriggerShortcut(event, { key: 'e', meta: true, shift: false })) {\n setIsEditing(editing => !editing);\n } else if (shouldTriggerShortcut(event, { key: 's', meta: true, shift: false })) {\n // Prevent default browser save\n event.preventDefault();\n saveChangesIfNeeded();\n }\n },\n [isEditing]\n );\n\n const handleBlur = React.useCallback((event: React.FocusEvent) => {\n if (event.target === event.currentTarget) {\n saveChangesIfNeeded();\n }\n }, []);\n\n // Creates initial saving statuses from changes object\n const addSavingStatuses = () => {\n const changeset = Object.keys(editingState || {});\n const additionalSavingStatuses = _.reduce(\n changeset,\n (result, rowId) => {\n return { ...result, [rowId]: SavingStatusValue.Saving };\n },\n {}\n );\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUSES,\n payload: { states: additionalSavingStatuses },\n });\n };\n\n // Resets/removes saving status by row id. Used in delayed saving indicator.\n const resetSavingStatus = (rowId: string) => {\n dispatchSavingStatusAction({\n type: SavingStatusActionType.RESET_SAVING_STATUS,\n payload: { rowId },\n });\n };\n\n // Checks if we have changes, then saves them\n const saveChangesIfNeeded = async () => {\n if (!editingState) {\n return;\n }\n\n const changeset = Object.keys(editingState);\n if (onSave && changeset.length) {\n addSavingStatuses();\n\n const responses = await Promise.allSettled(\n changeset.map(rowId => {\n const validationSavePromise = new Promise<void>((resolve, reject) => {\n const changedRow = editingState?.[rowId];\n if (changedRow) {\n validation\n .validate(rowId, changedRow)\n ?.then(() => {\n const savePromise = onSave(changedRow);\n savePromise\n .then(() => {\n resolve();\n })\n .catch(reason => {\n if (reason.errors) {\n validation.setRowErrors(rowId, reason.errors);\n }\n\n reject(reason);\n });\n })\n .catch(() => {\n validation.confirmErrors(rowId);\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUS,\n payload: { rowId, state: SavingStatusValue.Error },\n });\n reject();\n });\n } else {\n reject();\n }\n });\n return validationSavePromise;\n })\n );\n\n responses.forEach((response, index) => {\n const rowId = changeset[index];\n\n if (response.status === 'fulfilled') {\n resetChange(rowId);\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUS,\n payload: { rowId, state: SavingStatusValue.Saved },\n });\n } else {\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUS,\n payload: { rowId, state: SavingStatusValue.Error },\n });\n }\n });\n }\n };\n\n const [rowMoveReason, setRowMoveReason] = React.useState<Record<string, IndicatorReason | null> | null>(null);\n\n const removeRowMoveReason = () => {\n setRowMoveReason(null);\n };\n\n const showWarning = React.useCallback(\n event => {\n if (isEditing && editingState && Object.keys(editingState).length > 0) {\n event.returnValue = true;\n return true;\n }\n\n return false;\n },\n [isEditing, editingState]\n );\n\n function getSavingStatus(rowId: string) {\n return savingStatuses && savingStatuses[rowId];\n }\n\n React.useEffect(() => {\n window.addEventListener('beforeunload', showWarning);\n\n return () => {\n window.removeEventListener('beforeunload', showWarning);\n };\n }, [showWarning]);\n\n React.useEffect(() => {\n if (!isEditing) {\n setDetailModeEditing(false);\n lastCellIndex.value = null;\n }\n }, [isEditing]);\n\n return {\n isEnabled,\n isEditing,\n toggleEditing: setIsEditing,\n changes: editingState,\n getCellValue,\n setCellValue,\n saveChangesIfNeeded,\n detailModeEditing,\n setDetailModeEditing,\n rowMoveReason,\n setRowMoveReason,\n removeRowMoveReason,\n handleKeyDown,\n handleBlur,\n resetChange,\n getSavingStatus,\n resetSavingStatus,\n };\n}\n\nenum EditingActionType {\n SET_CELL_VALUE,\n RESET_CHANGE,\n}\n\ntype EditingState<TType = unknown> = Record<string, TType> | null;\n\ntype EditingAction =\n | { type: EditingActionType.SET_CELL_VALUE; payload: { rowId: string; cellId: string; value: unknown; originalValues } }\n | {\n type: EditingActionType.RESET_CHANGE;\n payload: { rowId: string };\n };\n\nfunction editingReducer<TType = unknown>(state: EditingState<TType>, action: EditingAction): EditingState<TType> {\n switch (action.type) {\n // Set cell value of the row\n case EditingActionType.SET_CELL_VALUE:\n return {\n ...state,\n [action.payload.rowId]: {\n ...(state?.[action.payload.rowId] || action.payload.originalValues),\n [action.payload.cellId]: action.payload.value,\n },\n };\n\n // Reset changes for the row\n case EditingActionType.RESET_CHANGE: {\n let currentChanges: Record<string, TType> | null = { ...state };\n if (currentChanges) {\n delete currentChanges[action.payload.rowId];\n }\n const changeset = Object.keys(currentChanges);\n if (changeset.length === 0) {\n currentChanges = null;\n }\n return currentChanges;\n }\n\n default:\n return state;\n }\n}\n\nenum SavingStatusActionType {\n SET_SAVING_STATUS,\n SET_SAVING_STATUSES,\n RESET_SAVING_STATUS,\n}\n\ntype SavingStatus = Record<string, SavingStatusValue> | null;\n\ntype SavingStatusAction =\n | { type: SavingStatusActionType.SET_SAVING_STATUS; payload: { rowId: string; state: SavingStatusValue } }\n | { type: SavingStatusActionType.SET_SAVING_STATUSES; payload: { states: Record<string, SavingStatusValue> } }\n | { type: SavingStatusActionType.RESET_SAVING_STATUS; payload: { rowId: string } };\n\nfunction savingStatusesReducer(state: SavingStatus, action: SavingStatusAction): SavingStatus {\n switch (action.type) {\n // Set single saving status for the row\n case SavingStatusActionType.SET_SAVING_STATUS:\n return {\n ...state,\n [action.payload.rowId]: action.payload.state,\n };\n // Set multiple saving statuses for multiple rows at the same time\n case SavingStatusActionType.SET_SAVING_STATUSES:\n return {\n ...state,\n ...action.payload.states,\n };\n // Reset/remove saving status for particular row\n case SavingStatusActionType.RESET_SAVING_STATUS: {\n const newSavingStatus = { ...state };\n delete newSavingStatus?.[action.payload.rowId];\n return newSavingStatus;\n }\n\n default:\n return state;\n }\n}\n"],"names":["SavingStatusValue","useEditing","isEnabled","validation","onSave","isEditing","setIsEditing","React","useState","savingStatuses","dispatchSavingStatusAction","useReducer","savingStatusesReducer","editingState","dispatchEditingAction","state","action","editingReducer","detailModeEditing","setDetailModeEditing","getCellValue","cell","_editingState$cell$ro","row","id","column","undefined","setCellValue","value","type","EditingActionType","SET_CELL_VALUE","payload","rowId","cellId","originalValues","original","resetChange","RESET_CHANGE","resetErrors","handleKeyDown","useCallback","event","defaultPrevented","shouldTriggerShortcut","key","meta","shift","editing","preventDefault","saveChangesIfNeeded","handleBlur","target","currentTarget","addSavingStatuses","changeset","Object","keys","additionalSavingStatuses","_","reduce","result","Saving","SavingStatusActionType","SET_SAVING_STATUSES","states","resetSavingStatus","RESET_SAVING_STATUS","Promise","resolve","_temp","length","allSettled","map","validationSavePromise","reject","changedRow","_validation$validate","validate","then","savePromise","catch","reason","errors","setRowErrors","confirmErrors","SET_SAVING_STATUS","Error","responses","forEach","response","index","status","Saved","e","rowMoveReason","setRowMoveReason","removeRowMoveReason","showWarning","returnValue","getSavingStatus","useEffect","window","addEventListener","removeEventListener","lastCellIndex","toggleEditing","changes","currentChanges","newSavingStatus"],"mappings":";;;;;IAUYA;AAAZ,WAAYA,iBAAiB;EACzBA,sCAAiB;EACjBA,oCAAe;EACfA,oCAAe;AACnB,CAAC,EAJWA,iBAAiB,KAAjBA,iBAAiB;SAMbC,UAAUA,CACtBC,SAAkB,EAClBC,UAAmC,EACnCC,MAAiC;;EAGjC,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;;;EAGvD,MAAM,CAACC,cAAc,EAAEC,0BAA0B,CAAC,GAAGH,cAAK,CAACI,UAAU,CAACC,qBAAqB,EAAE,IAAI,CAAC;;EAGlG,MAAM,CAACC,YAAY,EAAEC,qBAAqB,CAAC,GAAGP,cAAK,CAACI,UAAU,CAAC,CAACI,KAA0B,EAAEC,MAAM,KAAKC,cAAc,CAAQF,KAAK,EAAEC,MAAM,CAAC,EAAE,IAAI,CAAC;EAElJ,MAAM,CAACE,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGZ,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EAEvE,SAASY,YAAYA,CAAkBC,IAAwB;;IAC3D,OAAOR,YAAY,IAAAS,qBAAA,GAAGT,YAAY,CAACQ,IAAI,CAACE,GAAG,CAACC,EAAE,CAAC,cAAAF,qBAAA,uBAAzBA,qBAAA,CAA4BD,IAAI,CAACI,MAAM,CAACD,EAAE,CAAC,GAAGE,SAAS;;;EAIjF,SAASC,YAAYA,CAAkBN,IAAwB,EAAEO,KAAc;IAC3Ed,qBAAqB,CAAC;MAClBe,IAAI,EAAEC,iBAAiB,CAACC,cAAc;MACtCC,OAAO,EAAE;QAAEC,KAAK,EAAEZ,IAAI,CAACE,GAAG,CAACC,EAAE;QA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AM,CAACgB,OAAO,CAACjB;OAC1C;;IAEL,KAAKgD,sBAAsB,CAACC,mBAAmB;MAC3C,OAAO;QACH,GAAGjD,KAAK;QACR,GAAGC,MAAM,CAACgB,OAAO,CAACiC;OACrB;;IAEL,KAAKF,sBAAsB,CAACI,mBAAmB;MAAE;QAC7C,MAAM0C,eAAe,GAAG;UAAE,GAAG9F;SAAO;QAC7B8F,eAAe,aAAfA,eAAe,qBAAtB,OAAOA,eAAe,CAAG7F,MAAM,CAACgB,OAAO,CAACC,KAAK,CAAC;QAC9C,OAAO4E,eAAe;;IAG1B;MACI,OAAO9F,KAAK;;AAExB;;;;"}
|
1
|
+
{"version":3,"file":"useEditing.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useEditing.tsx"],"sourcesContent":["import React from 'react';\nimport _ from 'lodash';\nimport { Cell as RTCell } from '@tanstack/react-table';\n\nimport { Table3Ref, Table3SaveHandler } from '../../types';\nimport { IndicatorReason } from '../../components/columns/cell/Indicator';\nimport { shouldTriggerShortcut } from '../../../../utils/keyboard';\nimport { Table3Validation } from './useValidation';\nimport { lastCellIndex } from '../../components/rows/Row';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport enum SavingStatusValue {\n Saving = 'saving',\n Saved = 'saved',\n Error = 'error',\n}\n\nexport function useEditing<TType = unknown>(\n isEnabled: boolean,\n tableRef: React.RefObject<Table3Ref>,\n validation: Table3Validation<TType>,\n onSave?: Table3SaveHandler<TType>\n) {\n // used to switch the table into editing mode\n const [isEditing, setIsEditing] = React.useState(false);\n // Saving indicator need to show saving status per row, saving status can have at least two states 'saving', 'saved',\n // 'saved' should remain for a few seconds to show tick icon after row has been saved.\n const [savingStatuses, dispatchSavingStatusAction] = React.useReducer(savingStatusesReducer, null);\n\n // sets of row changes pending save, either they have not saved yet or they have errors\n const [editingState, dispatchEditingAction] = React.useReducer(\n (state: EditingState<TType>, action) => editingReducer<TType>(state, action),\n null\n );\n\n const [detailModeEditing, setDetailModeEditing] = React.useState(false);\n\n function getCellValue<T extends TType>(cell: RTCell<T, unknown>) {\n return editingState ? editingState[cell.row.id]?.[cell.column.id] : undefined;\n }\n\n // Saves editing cell value into editing state.\n function setCellValue<T extends TType>(cell: RTCell<T, unknown>, value: unknown) {\n dispatchEditingAction({\n type: EditingActionType.SET_CELL_VALUE,\n payload: { rowId: cell.row.id, cellId: cell.column.id, value, originalValues: cell.row.original },\n });\n }\n\n // Removes changes from editing state by row id\n function resetChange(rowId: string) {\n dispatchEditingAction({\n type: EditingActionType.RESET_CHANGE,\n payload: { rowId },\n });\n validation.resetErrors(rowId);\n }\n\n const handleKeyDown = React.useCallback(\n (event: KeyboardEvent) => {\n if (event.defaultPrevented) {\n return;\n }\n\n if (shouldTriggerShortcut(event, { key: 'e', meta: true, shift: false })) {\n setIsEditing(editing => !editing);\n } else if (shouldTriggerShortcut(event, { key: 's', meta: true, shift: false })) {\n // Prevent default browser save\n event.preventDefault();\n saveChangesIfNeeded();\n }\n },\n [isEditing]\n );\n\n const handleBlur = React.useCallback((event: React.FocusEvent) => {\n if (event.target === event.currentTarget) {\n saveChangesIfNeeded();\n }\n }, []);\n\n // Creates initial saving statuses from changes object\n const addSavingStatuses = () => {\n const changeset = Object.keys(editingState || {});\n const additionalSavingStatuses = _.reduce(\n changeset,\n (result, rowId) => {\n return { ...result, [rowId]: SavingStatusValue.Saving };\n },\n {}\n );\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUSES,\n payload: { states: additionalSavingStatuses },\n });\n };\n\n // Resets/removes saving status by row id. Used in delayed saving indicator.\n const resetSavingStatus = (rowId: string) => {\n dispatchSavingStatusAction({\n type: SavingStatusActionType.RESET_SAVING_STATUS,\n payload: { rowId },\n });\n };\n\n // Checks if we have changes, then saves them\n const saveChangesIfNeeded = async () => {\n if (!editingState) {\n return;\n }\n\n const changeset = Object.keys(editingState);\n if (onSave && changeset.length) {\n addSavingStatuses();\n\n const responses = await Promise.allSettled(\n changeset.map(rowId => {\n const validationSavePromise = new Promise<void>((resolve, reject) => {\n const changedRow = editingState?.[rowId];\n if (changedRow) {\n validation\n .validate(rowId, changedRow)\n ?.then(() => {\n const savePromise = onSave(changedRow);\n savePromise\n .then(() => {\n resolve();\n })\n .catch(reason => {\n if (reason.errors) {\n validation.setRowErrors(rowId, reason.errors);\n }\n\n reject(reason);\n });\n })\n .catch(() => {\n validation.confirmErrors(rowId);\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUS,\n payload: { rowId, state: SavingStatusValue.Error },\n });\n reject();\n });\n } else {\n reject();\n }\n });\n return validationSavePromise;\n })\n );\n\n responses.forEach((response, index) => {\n const rowId = changeset[index];\n\n if (response.status === 'fulfilled') {\n resetChange(rowId);\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUS,\n payload: { rowId, state: SavingStatusValue.Saved },\n });\n } else {\n dispatchSavingStatusAction({\n type: SavingStatusActionType.SET_SAVING_STATUS,\n payload: { rowId, state: SavingStatusValue.Error },\n });\n }\n });\n }\n };\n\n const [rowMoveReason, setRowMoveReason] = React.useState<Record<string, IndicatorReason | null> | null>(null);\n\n const removeRowMoveReason = () => {\n setRowMoveReason(null);\n };\n\n const showWarning = React.useCallback(\n event => {\n if (isEditing && editingState && Object.keys(editingState).length > 0) {\n event.returnValue = true;\n return true;\n }\n\n return false;\n },\n [isEditing, editingState]\n );\n\n React.useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n const target = event.target as HTMLElement;\n const closestPopup = target.closest('[role=\"dialog\"], [role=\"menu\"]');\n\n // Need to check that neither target itself nor closest popup is inside or triggetred from the table.\n if (\n !isElementInsideOrTriggeredFromContainer(target, tableRef.current) &&\n !isElementInsideOrTriggeredFromContainer(closestPopup, tableRef.current)\n ) {\n saveChangesIfNeeded();\n }\n };\n\n document.addEventListener('click', handleClickOutside);\n\n return () => {\n document.removeEventListener('click', handleClickOutside);\n };\n }, [saveChangesIfNeeded]);\n\n function getSavingStatus(rowId: string) {\n return savingStatuses && savingStatuses[rowId];\n }\n\n React.useEffect(() => {\n window.addEventListener('beforeunload', showWarning);\n\n return () => {\n window.removeEventListener('beforeunload', showWarning);\n };\n }, [showWarning]);\n\n React.useEffect(() => {\n if (!isEditing) {\n setDetailModeEditing(false);\n lastCellIndex.value = null;\n }\n }, [isEditing]);\n\n return {\n isEnabled,\n isEditing,\n toggleEditing: setIsEditing,\n changes: editingState,\n getCellValue,\n setCellValue,\n saveChangesIfNeeded,\n detailModeEditing,\n setDetailModeEditing,\n rowMoveReason,\n setRowMoveReason,\n removeRowMoveReason,\n handleKeyDown,\n handleBlur,\n resetChange,\n getSavingStatus,\n resetSavingStatus,\n };\n}\n\nenum EditingActionType {\n SET_CELL_VALUE,\n RESET_CHANGE,\n}\n\ntype EditingState<TType = unknown> = Record<string, TType> | null;\n\ntype EditingAction =\n | { type: EditingActionType.SET_CELL_VALUE; payload: { rowId: string; cellId: string; value: unknown; originalValues } }\n | {\n type: EditingActionType.RESET_CHANGE;\n payload: { rowId: string };\n };\n\nfunction editingReducer<TType = unknown>(state: EditingState<TType>, action: EditingAction): EditingState<TType> {\n switch (action.type) {\n // Set cell value of the row\n case EditingActionType.SET_CELL_VALUE:\n return {\n ...state,\n [action.payload.rowId]: {\n ...(state?.[action.payload.rowId] || action.payload.originalValues),\n [action.payload.cellId]: action.payload.value,\n },\n };\n\n // Reset changes for the row\n case EditingActionType.RESET_CHANGE: {\n let currentChanges: Record<string, TType> | null = { ...state };\n if (currentChanges) {\n delete currentChanges[action.payload.rowId];\n }\n const changeset = Object.keys(currentChanges);\n if (changeset.length === 0) {\n currentChanges = null;\n }\n return currentChanges;\n }\n\n default:\n return state;\n }\n}\n\nenum SavingStatusActionType {\n SET_SAVING_STATUS,\n SET_SAVING_STATUSES,\n RESET_SAVING_STATUS,\n}\n\ntype SavingStatus = Record<string, SavingStatusValue> | null;\n\ntype SavingStatusAction =\n | { type: SavingStatusActionType.SET_SAVING_STATUS; payload: { rowId: string; state: SavingStatusValue } }\n | { type: SavingStatusActionType.SET_SAVING_STATUSES; payload: { states: Record<string, SavingStatusValue> } }\n | { type: SavingStatusActionType.RESET_SAVING_STATUS; payload: { rowId: string } };\n\nfunction savingStatusesReducer(state: SavingStatus, action: SavingStatusAction): SavingStatus {\n switch (action.type) {\n // Set single saving status for the row\n case SavingStatusActionType.SET_SAVING_STATUS:\n return {\n ...state,\n [action.payload.rowId]: action.payload.state,\n };\n // Set multiple saving statuses for multiple rows at the same time\n case SavingStatusActionType.SET_SAVING_STATUSES:\n return {\n ...state,\n ...action.payload.states,\n };\n // Reset/remove saving status for particular row\n case SavingStatusActionType.RESET_SAVING_STATUS: {\n const newSavingStatus = { ...state };\n delete newSavingStatus?.[action.payload.rowId];\n return newSavingStatus;\n }\n\n default:\n return state;\n }\n}\n"],"names":["SavingStatusValue","useEditing","isEnabled","tableRef","validation","onSave","isEditing","setIsEditing","React","useState","savingStatuses","dispatchSavingStatusAction","useReducer","savingStatusesReducer","editingState","dispatchEditingAction","state","action","editingReducer","detailModeEditing","setDetailModeEditing","getCellValue","cell","_editingState$cell$ro","row","id","column","undefined","setCellValue","value","type","EditingActionType","SET_CELL_VALUE","payload","rowId","cellId","originalValues","original","resetChange","RESET_CHANGE","resetErrors","handleKeyDown","useCallback","event","defaultPrevented","shouldTriggerShortcut","key","meta","shift","editing","preventDefault","saveChangesIfNeeded","handleBlur","target","currentTarget","addSavingStatuses","changeset","Object","keys","additionalSavingStatuses","_","reduce","result","Saving","SavingStatusActionType","SET_SAVING_STATUSES","states","resetSavingStatus","RESET_SAVING_STATUS","Promise","resolve","_temp","length","allSettled","map","validationSavePromise","reject","changedRow","_validation$validate","validate","then","savePromise","catch","reason","errors","setRowErrors","confirmErrors","SET_SAVING_STATUS","Error","responses","forEach","response","index","status","Saved","e","rowMoveReason","setRowMoveReason","removeRowMoveReason","showWarning","returnValue","useEffect","handleClickOutside","closestPopup","closest","isElementInsideOrTriggeredFromContainer","current","document","addEventListener","removeEventListener","getSavingStatus","window","lastCellIndex","toggleEditing","changes","currentChanges","newSavingStatus"],"mappings":";;;;;;IAWYA;AAAZ,WAAYA,iBAAiB;EACzBA,sCAAiB;EACjBA,oCAAe;EACfA,oCAAe;AACnB,CAAC,EAJWA,iBAAiB,KAAjBA,iBAAiB;SAMbC,UAAUA,CACtBC,SAAkB,EAClBC,QAAoC,EACpCC,UAAmC,EACnCC,MAAiC;;EAGjC,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;;;EAGvD,MAAM,CAACC,cAAc,EAAEC,0BAA0B,CAAC,GAAGH,cAAK,CAACI,UAAU,CAACC,qBAAqB,EAAE,IAAI,CAAC;;EAGlG,MAAM,CAACC,YAAY,EAAEC,qBAAqB,CAAC,GAAGP,cAAK,CAACI,UAAU,CAC1D,CAACI,KAA0B,EAAEC,MAAM,KAAKC,cAAc,CAAQF,KAAK,EAAEC,MAAM,CAAC,EAC5E,IAAI,CACP;EAED,MAAM,CAACE,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGZ,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EAEvE,SAASY,YAAYA,CAAkBC,IAAwB;;IAC3D,OAAOR,YAAY,IAAAS,qBAAA,GAAGT,YAAY,CAACQ,IAAI,CAACE,GAAG,CAACC,EAAE,CAAC,cAAAF,qBAAA,uBAAzBA,qBAAA,CAA4BD,IAAI,CAACI,MAAM,CAACD,EAAE,CAAC,GAAGE,SAAS;;;EAIjF,SAASC,YAAYA,CAAkBN,IAAwB,EAAEO,KAAc;IAC3Ed,qBAAqB,CAAC;MAClBe,IAAI,EAAEC,iBAAiB,CAACC,cAAc;MACtCC,OAAO,EAAE;QAAEC,KAAK,EAAEZ,IAAI,CAACE,GAAG,CAACC,EAAE;QAAEU,MAAM,EAAEb,IAAI,CAACI,MAAM,CAACD,EAAE;QAAEI,KAAK;QAAEO,cAAc,EAAEd,IAAI,CAACE,GAAG,CAACa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B,MAAM,KAAK,CAAC,EAAE;UACxB2C,cAAc,GAAG,IAAI;;QAEzB,OAAOA,cAAc;;IAGzB;MACI,OAAOnG,KAAK;;AAExB;AAEA,IAAKgD,sBAIJ;AAJD,WAAKA,sBAAsB;EACvBA,6FAAiB;EACjBA,iGAAmB;EACnBA,iGAAmB;AACvB,CAAC,EAJIA,sBAAsB,KAAtBA,sBAAsB;AAa3B,SAASnD,qBAAqBA,CAACG,KAAmB,EAAEC,MAA0B;EAC1E,QAAQA,MAAM,CAACa,IAAI;;IAEf,KAAKkC,sBAAsB,CAACuB,iBAAiB;MACzC,OAAO;QACH,GAAGvE,KAAK;QACR,CAACC,MAAM,CAACgB,OAAO,CAACC,KAAK,GAAGjB,MAAM,CAACgB,OAAO,CAACjB;OAC1C;;IAEL,KAAKgD,sBAAsB,CAACC,mBAAmB;MAC3C,OAAO;QACH,GAAGjD,KAAK;QACR,GAAGC,MAAM,CAACgB,OAAO,CAACiC;OACrB;;IAEL,KAAKF,sBAAsB,CAACI,mBAAmB;MAAE;QAC7C,MAAMgD,eAAe,GAAG;UAAE,GAAGpG;SAAO;QAC7BoG,eAAe,aAAfA,eAAe,qBAAtB,OAAOA,eAAe,CAAGnG,MAAM,CAACgB,OAAO,CAACC,KAAK,CAAC;QAC9C,OAAOkF,eAAe;;IAG1B;MACI,OAAOpG,KAAK;;AAExB;;;;"}
|
@@ -48,7 +48,7 @@ function useTable(props, ref) {
|
|
48
48
|
// can't change due to rename to "active row"
|
49
49
|
const validation = useValidation(props.onCellValidate, props.onRowValidate);
|
50
50
|
// not relevant to common table
|
51
|
-
const editing = useEditing(options.enableEditing, validation, props.onSave);
|
51
|
+
const editing = useEditing(options.enableEditing, ref, validation, props.onSave);
|
52
52
|
// we changed how printing works, so this shouldn't be migrated
|
53
53
|
const printing = usePrinting(options.enablePrinting, settings.showWarningWhenPrintingLargeDataset, props.id);
|
54
54
|
// needs to be moved
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useTable.js","sources":["../../../../../../../../src/components/Table3/hooks/useTable.tsx"],"sourcesContent":["import React from 'react';\nimport {\n getCoreRowModel,\n useReactTable,\n Row as RTRow,\n RowData,\n Column as RTColumn,\n TableOptions as RTableOptions,\n TableState,\n getSortedRowModel,\n getFilteredRowModel,\n ColumnMeta,\n} from '@tanstack/react-table';\nimport {\n Table3ColumnAlignment,\n Table3ColumnRenderer,\n Table3Props,\n Table3ColumnHeaderMenu,\n Table3ColumnControlRenderer,\n Table3ColumnDataType,\n Table3ColumnClassNameHandler,\n Table3ColumnFooterRenderer,\n TableStrategy,\n Table3FilterComparator,\n Table3Settings,\n Table3Options,\n Table3Ref,\n} from '../types';\nimport { useTableRowActive } from '../../../primitives/Table/useTable/features/useTableRowActive';\nimport { useTablePreset } from './useTablePreset';\nimport { useTableRowHeight } from '../../../primitives/Table/useTable/features/useTableRowHeight';\nimport { useTableFontSize } from '../../../primitives/Table/useTable/features/useTableFontSize';\nimport { useTableRowSelectionListener } from '../../../primitives/Table/useTable/listeners/useTableRowSelectionListener';\nimport { useRowDrag } from './features/useRowDrag';\nimport { useSettingsStateListener } from './listeners/useSettingsStateListener';\nimport { columnFilterFn, globalFilterFn } from '../util/filtering';\nimport { useTableSortingListener } from '../../../primitives/Table/useTable/listeners/useTableSortingListener';\nimport { useTableFilterListener } from '../../../primitives/Table/useTable/listeners/useTableFilterListener';\nimport { useTableDataListener } from '../../../primitives/Table/useTable/listeners/useTableDataListener';\nimport { useColumnFreezing } from './features/useColumnFreezing';\nimport { useTableRowSelection } from '../../../primitives/Table/useTable/features/useTableRowSelection';\nimport { useTableServerLoading } from '../../../primitives/Table/useTable/features/useTableServerLoading';\nimport { useTableRowClick } from '../../../primitives/Table/useTable/features/useTableRowClick';\nimport { useTableColumnOrdering } from '../../../primitives/Table/useTable/features/useTableColumnOrdering';\nimport { useRowDrop } from './features/useRowDrop';\nimport { useConvertChildrenToColumns } from './useConvertChildrenToColumns';\nimport { useEditing } from './features/useEditing';\nimport { usePrinting } from './features/usePrinting';\nimport { useTableShortcutsListener } from '../../../primitives/Table/useTable/listeners/useTableShortcutsListener';\nimport { useTableRowGoto } from '../../../primitives/Table/useTable/features/useTableRowGoto';\nimport { useTableServerLoadingListener } from '../../../primitives/Table/useTable/listeners/useTableServerLoadingListener';\nimport { useEditingStateListener } from './listeners/useEditingStateListener';\nimport { useSearch } from './features/useSearch';\nimport { useRowActions } from './features/useRowActions';\nimport { useSettings } from './features/useSettings';\nimport { getCellValueAsString } from '../util/columns';\nimport { Table3Validation, useValidation } from './features/useValidation';\nimport { usePauseShortcuts } from './features/usePauseShortcuts';\nimport { useTableFontSizeListener } from '../../../primitives/Table/useTable/listeners/useTableFontSizeListener';\nimport { ensureOrdering } from '../../../primitives/Table/useTable/util/columns';\nimport { COLUMN_ID as ACTIONS_COLUMN_ID } from '../components/columns/internal/Actions';\nimport { COLUMN_ID as EDITING_ACTIONS_COLUMN_ID } from '../components/columns/internal/EditingActions';\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n columnFreezing: ReturnType<typeof useColumnFreezing>;\n columnOrdering: ReturnType<typeof useTableColumnOrdering>;\n editing: ReturnType<typeof useEditing>;\n enableFooter: boolean;\n fontSize: ReturnType<typeof useTableFontSize>;\n getSettings: () => Table3Settings;\n isPrinting: boolean;\n isUsingServer: boolean;\n printing: ReturnType<typeof usePrinting>;\n rowActions: ReturnType<typeof useRowActions>;\n rowActive: ReturnType<typeof useTableRowActive>;\n rowClick: ReturnType<typeof useTableRowClick>;\n rowDrag: ReturnType<typeof useRowDrag>;\n rowDrop: ReturnType<typeof useRowDrop>;\n rowGoto: ReturnType<typeof useTableRowGoto>;\n rowHeight: ReturnType<typeof useTableRowHeight>;\n rowSelection: ReturnType<typeof useTableRowSelection>;\n search: ReturnType<typeof useSearch>;\n server: ReturnType<typeof useTableServerLoading>;\n shortcutsState: ReturnType<typeof usePauseShortcuts>;\n tableRef: React.RefObject<Table3Ref>;\n validation: Table3Validation<TData>;\n }\n\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: Table3ColumnAlignment;\n className?: Table3ColumnClassNameHandler<TData>;\n control?: Table3ColumnControlRenderer<TData>;\n dataType?: Table3ColumnDataType;\n defaultWidth?: number;\n enableOrdering?: boolean;\n enableSearch: boolean;\n enableTruncate?: boolean;\n filters?: Table3FilterComparator[];\n footer?: Table3ColumnFooterRenderer;\n header: string;\n headerClassName?: string;\n menu?: Table3ColumnHeaderMenu;\n renderer?: Table3ColumnRenderer<TValue, TData>;\n tooltip?: string;\n }\n\n interface CellContext<TData extends RowData, TValue> {\n index: number;\n tableRef: React.RefObject<HTMLDivElement>;\n }\n\n interface HeaderContext<TData extends RowData, TValue> {\n scrollToIndex: TableStrategy['scrollToIndex'];\n }\n}\n\nexport function useTable<TType = unknown>(props: Table3Props<TType>, ref: React.RefObject<Table3Ref>) {\n // load any persisted table settings and merge them with any defaults\n const [settings, setSettings] = useSettings(props.id, props.defaultSettings, props.onChangeSettings);\n\n // configure table3 options\n const options = useTablePreset(props);\n\n // configure react-table built-in features\n const tableOptions = configureReactTableOptions(props, options);\n\n // configure custom features\n const columnFreezing = useColumnFreezing(settings.columnFreezingIndex ?? props.defaultColumnFreezingIndex, options);\n // can't change due to rename to \"active row\"\n const validation = useValidation<TType>(props.onCellValidate, props.onRowValidate);\n // not relevant to common table\n const editing = useEditing<TType>(options.enableEditing, validation, props.onSave);\n // we changed how printing works, so this shouldn't be migrated\n const printing = usePrinting(options.enablePrinting, settings.showWarningWhenPrintingLargeDataset, props.id);\n // needs to be moved\n const rowActions = useRowActions<TType>(props.actionsForRow, props.actionsForRowLength);\n // not relevant to common table\n const rowDrag = useRowDrag(options.enableRowDrag);\n // not relevant to common table\n const rowDrop = useRowDrop(options.enableRowDrop, props.onRowDrop);\n // haven't migrated load all/server loading yet\n const search = useSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);\n const shortcutsState = usePauseShortcuts();\n\n // custom features - shared/migrated\n const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);\n const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);\n const rowActive = useTableRowActive(true, props.defaultCurrentRowIndex);\n const rowClick = useTableRowClick<TType>(true, props.onRowClick);\n const rowGoto = useTableRowGoto(options.enableRowGoto, props.onRowGoto);\n const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);\n const rowSelection = useTableRowSelection(options.enableRowSelection);\n const server = useTableServerLoading(props.loadPage, props.loadAll);\n\n // columns\n const { columns, defaultColumnSizing, defaultColumnVisibility, defaultSorting } = useConvertChildrenToColumns<TType>(\n props,\n options,\n editing\n );\n\n // built-in features\n const initialState: Partial<TableState> = React.useMemo(() => {\n const sanitizeSortedColumns = column => columns.find(definedColumn => definedColumn.id === column.id);\n\n const state: Partial<TableState> = {\n columnOrder: ensureOrdering<TType>(columns, settings.columnOrder, [ACTIONS_COLUMN_ID, EDITING_ACTIONS_COLUMN_ID]),\n columnSizing: settings.columnSizing ?? defaultColumnSizing,\n columnVisibility: settings.columnVisibility ?? defaultColumnVisibility,\n sorting: settings.sorting ? settings.sorting.filter(sanitizeSortedColumns) : defaultSorting,\n };\n\n // we don't save these outside the table, but they need to be here for print to inherit them - see PrintButton.tsx\n if ((props.defaultSettings as any)?.columnFilters) {\n state.columnFilters = (props.defaultSettings as any)?.columnFilters;\n }\n\n if ((props.defaultSettings as any)?.globalFilter) {\n state.globalFilter = (props.defaultSettings as any)?.globalFilter;\n }\n\n return state;\n }, []);\n\n const getSettings = () => {\n const state = table.getState();\n return {\n columnFreezingIndex: columnFreezing.frozenColumnIndex,\n columnOrder: columnOrdering.isEnabled ? state.columnOrder : undefined,\n columnSizing: table.options.enableColumnResizing ? state.columnSizing : undefined,\n columnVisibility: table.options.enableHiding ? state.columnVisibility : undefined,\n excludeUnmatchedRecordsInSearch: search.excludeUnmatchedResults,\n fontSize: fontSize.isEnabled ? fontSize.size : undefined,\n rowHeight: rowHeight.isEnabled ? rowHeight.height : undefined,\n showWarningWhenPrintingLargeDataset: printing.isWarningVisibleForLargeDatasets,\n sorting: state.sorting,\n };\n };\n\n const table = useReactTable<TType>({\n data: props.data,\n columns,\n getCoreRowModel: getCoreRowModel(),\n initialState,\n ...tableOptions,\n //debugAll: true,\n meta: {\n columnFreezing,\n columnOrdering,\n editing,\n enableFooter: options.enableFooter,\n fontSize,\n getSettings,\n isPrinting: props.id.endsWith('_print'),\n isUsingServer: !!props.loadPage,\n printing,\n rowActions: rowActions as any,\n rowActive,\n rowClick: rowClick as any,\n rowDrag,\n rowDrop,\n rowGoto,\n rowHeight,\n rowSelection,\n search,\n server,\n shortcutsState,\n tableRef: ref,\n validation,\n },\n });\n\n // listeners\n useEditingStateListener(table);\n useSettingsStateListener(table, setSettings);\n // listeners - shared/migrated\n useTableDataListener(table);\n useTableFilterListener(table, props.onFilter);\n useTableFontSizeListener(table);\n useTableRowSelectionListener(table, props.onRowSelect);\n useTableServerLoadingListener(table, props.loadPage);\n useTableShortcutsListener(table, props.shortcuts);\n useTableSortingListener(table, props.onSort);\n\n return { table, length: props.length ?? props.data.length };\n}\n\nfunction configureReactTableOptions<TType = unknown>(props: Table3Props<TType>, options: Table3Options) {\n const tableOptions: Partial<RTableOptions<TType>> = {\n enableColumnFilters: options.enableFiltering,\n enableColumnResizing: options.enableColumnResizing,\n enableExpanding: options.enableRowExpansion,\n enableGlobalFilter: options.enableSearch,\n enableHiding: options.enableColumnHiding,\n enableRowSelection: options.enableRowSelection,\n enableMultiRowSelection: !options.enableRowSelectionSingle,\n enableSorting: options.enableSorting,\n };\n\n // resizing\n if (tableOptions.enableColumnResizing) {\n tableOptions.columnResizeMode = 'onChange';\n }\n\n // filtering\n if (tableOptions.enableColumnFilters) {\n if (!props.onFilter) {\n tableOptions.filterFns = {\n tacoFilter: (row: RTRow<TType>, columnId: string, filter: any) => columnFilterFn(row.getValue(columnId), filter),\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n }\n\n // we don't tableOptions.manualFiltering = true; because it breaks global filtering, server filtering still works :shrug:\n }\n\n // search\n if (tableOptions.enableGlobalFilter) {\n // search is always client side, since we call loadAll when searching\n tableOptions.globalFilterFn = (row: RTRow<TType>, columnId: string, searchQuery: string) => {\n try {\n if (row.original) {\n const cell = row.getAllCells().find(cell => cell.column.id === columnId);\n const columnMeta = cell?.column.columnDef.meta;\n\n if (cell && cell.column.getIsVisible() && columnMeta?.enableSearch) {\n const cellValue = getCellValueAsString(row.original[columnId], columnMeta?.dataType);\n\n if (cellValue !== undefined) {\n return globalFilterFn(cellValue, searchQuery);\n }\n }\n return false;\n }\n } catch {\n //\n }\n\n return false;\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n tableOptions.getColumnCanGlobalFilter = (column: RTColumn<TType>) =>\n (column.columnDef.meta as ColumnMeta<TType, unknown>).enableSearch ?? true;\n }\n\n // sorting\n if (options.enableSorting) {\n if (props.onSort) {\n tableOptions.manualSorting = true;\n // onSort is called as a listener to let the consumer update their data, so we don't use onSortingChange\n } else {\n tableOptions.getSortedRowModel = getSortedRowModel();\n }\n }\n\n return tableOptions;\n}\n"],"names":["useTable","props","ref","settings","setSettings","useSettings","id","defaultSettings","onChangeSettings","options","useTablePreset","tableOptions","configureReactTableOptions","columnFreezing","useColumnFreezing","_settings$columnFreez","columnFreezingIndex","defaultColumnFreezingIndex","validation","useValidation","onCellValidate","onRowValidate","editing","useEditing","enableEditing","onSave","printing","usePrinting","enablePrinting","showWarningWhenPrintingLargeDataset","rowActions","useRowActions","actionsForRow","actionsForRowLength","rowDrag","useRowDrag","enableRowDrag","rowDrop","useRowDrop","enableRowDrop","onRowDrop","search","useSearch","enableSearch","excludeUnmatchedRecordsInSearch","shortcutsState","usePauseShortcuts","columnOrdering","useTableColumnOrdering","enableColumnOrdering","fontSize","useTableFontSize","enableFontSize","rowActive","useTableRowActive","defaultCurrentRowIndex","rowClick","useTableRowClick","onRowClick","rowGoto","useTableRowGoto","enableRowGoto","onRowGoto","rowHeight","useTableRowHeight","enableRowHeight","rowSelection","useTableRowSelection","enableRowSelection","server","useTableServerLoading","loadPage","loadAll","columns","defaultColumnSizing","defaultColumnVisibility","defaultSorting","useConvertChildrenToColumns","initialState","React","useMemo","sanitizeSortedColumns","column","find","definedColumn","state","columnOrder","ensureOrdering","ACTIONS_COLUMN_ID","EDITING_ACTIONS_COLUMN_ID","columnSizing","_settings$columnSizin","columnVisibility","_settings$columnVisib","sorting","filter","_props$defaultSetting","columnFilters","_props$defaultSetting2","_props$defaultSetting3","globalFilter","_props$defaultSetting4","getSettings","table","getState","frozenColumnIndex","isEnabled","undefined","enableColumnResizing","enableHiding","excludeUnmatchedResults","size","height","isWarningVisibleForLargeDatasets","useReactTable","data","getCoreRowModel","meta","enableFooter","isPrinting","endsWith","isUsingServer","tableRef","useEditingStateListener","useSettingsStateListener","useTableDataListener","useTableFilterListener","onFilter","useTableFontSizeListener","useTableRowSelectionListener","onRowSelect","useTableServerLoadingListener","useTableShortcutsListener","shortcuts","useTableSortingListener","onSort","length","_props$length","enableColumnFilters","enableFiltering","enableExpanding","enableRowExpansion","enableGlobalFilter","enableColumnHiding","enableMultiRowSelection","enableRowSelectionSingle","enableSorting","columnResizeMode","filterFns","tacoFilter","row","columnId","columnFilterFn","getValue","getFilteredRowModel","globalFilterFn","searchQuery","original","cell","getAllCells","columnMeta","columnDef","getIsVisible","cellValue","getCellValueAsString","dataType","getColumnCanGlobalFilter","_column$columnDef$met","manualSorting","getSortedRowModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAqHgBA,QAAQA,CAAkBC,KAAyB,EAAEC,GAA+B;;;EAEhG,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGC,WAAW,CAACJ,KAAK,CAACK,EAAE,EAAEL,KAAK,CAACM,eAAe,EAAEN,KAAK,CAACO,gBAAgB,CAAC;;EAGpG,MAAMC,OAAO,GAAGC,cAAc,CAACT,KAAK,CAAC;;EAGrC,MAAMU,YAAY,GAAGC,0BAA0B,CAACX,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AMS,UAAU,GAAGF,IAAI,aAAJA,IAAI,uBAAJA,IAAI,CAAE5E,MAAM,CAAC+E,SAAS,CAAC5C,IAAI;UAE9C,IAAIyC,IAAI,IAAIA,IAAI,CAAC5E,MAAM,CAACgF,YAAY,EAAE,IAAIF,UAAU,aAAVA,UAAU,eAAVA,UAAU,CAAErH,YAAY,EAAE;YAChE,MAAMwH,SAAS,GAAGC,oBAAoB,CAACd,GAAG,CAACO,QAAQ,CAACN,QAAQ,CAAC,EAAES,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,QAAQ,CAAC;YAEpF,IAAIF,SAAS,KAAKxD,SAAS,EAAE;cACzB,OAAOgD,cAAc,CAACQ,SAAS,EAAEP,WAAW,CAAC;;;UAGrD,OAAO,KAAK;;OAEnB,CAAC,MAAM;;;MAIR,OAAO,KAAK;KACf;IACDjJ,YAAY,CAAC+I,mBAAmB,GAAGA,mBAAmB,EAAE;IACxD/I,YAAY,CAAC2J,wBAAwB,GAAIpF,MAAuB;MAAA,IAAAqF,qBAAA;MAAA,QAAAA,qBAAA,GAC3DrF,MAAM,CAAC+E,SAAS,CAAC5C,IAAmC,CAAC1E,YAAY,cAAA4H,qBAAA,cAAAA,qBAAA,GAAI,IAAI;;;;EAIlF,IAAI9J,OAAO,CAACyI,aAAa,EAAE;IACvB,IAAIjJ,KAAK,CAACsI,MAAM,EAAE;MACd5H,YAAY,CAAC6J,aAAa,GAAG,IAAI;;KAEpC,MAAM;MACH7J,YAAY,CAAC8J,iBAAiB,GAAGA,iBAAiB,EAAE;;;EAI5D,OAAO9J,YAAY;AACvB;;;;"}
|
1
|
+
{"version":3,"file":"useTable.js","sources":["../../../../../../../../src/components/Table3/hooks/useTable.tsx"],"sourcesContent":["import React from 'react';\nimport {\n getCoreRowModel,\n useReactTable,\n Row as RTRow,\n RowData,\n Column as RTColumn,\n TableOptions as RTableOptions,\n TableState,\n getSortedRowModel,\n getFilteredRowModel,\n ColumnMeta,\n} from '@tanstack/react-table';\nimport {\n Table3ColumnAlignment,\n Table3ColumnRenderer,\n Table3Props,\n Table3ColumnHeaderMenu,\n Table3ColumnControlRenderer,\n Table3ColumnDataType,\n Table3ColumnClassNameHandler,\n Table3ColumnFooterRenderer,\n TableStrategy,\n Table3FilterComparator,\n Table3Settings,\n Table3Options,\n Table3Ref,\n} from '../types';\nimport { useTableRowActive } from '../../../primitives/Table/useTable/features/useTableRowActive';\nimport { useTablePreset } from './useTablePreset';\nimport { useTableRowHeight } from '../../../primitives/Table/useTable/features/useTableRowHeight';\nimport { useTableFontSize } from '../../../primitives/Table/useTable/features/useTableFontSize';\nimport { useTableRowSelectionListener } from '../../../primitives/Table/useTable/listeners/useTableRowSelectionListener';\nimport { useRowDrag } from './features/useRowDrag';\nimport { useSettingsStateListener } from './listeners/useSettingsStateListener';\nimport { columnFilterFn, globalFilterFn } from '../util/filtering';\nimport { useTableSortingListener } from '../../../primitives/Table/useTable/listeners/useTableSortingListener';\nimport { useTableFilterListener } from '../../../primitives/Table/useTable/listeners/useTableFilterListener';\nimport { useTableDataListener } from '../../../primitives/Table/useTable/listeners/useTableDataListener';\nimport { useColumnFreezing } from './features/useColumnFreezing';\nimport { useTableRowSelection } from '../../../primitives/Table/useTable/features/useTableRowSelection';\nimport { useTableServerLoading } from '../../../primitives/Table/useTable/features/useTableServerLoading';\nimport { useTableRowClick } from '../../../primitives/Table/useTable/features/useTableRowClick';\nimport { useTableColumnOrdering } from '../../../primitives/Table/useTable/features/useTableColumnOrdering';\nimport { useRowDrop } from './features/useRowDrop';\nimport { useConvertChildrenToColumns } from './useConvertChildrenToColumns';\nimport { useEditing } from './features/useEditing';\nimport { usePrinting } from './features/usePrinting';\nimport { useTableShortcutsListener } from '../../../primitives/Table/useTable/listeners/useTableShortcutsListener';\nimport { useTableRowGoto } from '../../../primitives/Table/useTable/features/useTableRowGoto';\nimport { useTableServerLoadingListener } from '../../../primitives/Table/useTable/listeners/useTableServerLoadingListener';\nimport { useEditingStateListener } from './listeners/useEditingStateListener';\nimport { useSearch } from './features/useSearch';\nimport { useRowActions } from './features/useRowActions';\nimport { useSettings } from './features/useSettings';\nimport { getCellValueAsString } from '../util/columns';\nimport { Table3Validation, useValidation } from './features/useValidation';\nimport { usePauseShortcuts } from './features/usePauseShortcuts';\nimport { useTableFontSizeListener } from '../../../primitives/Table/useTable/listeners/useTableFontSizeListener';\nimport { ensureOrdering } from '../../../primitives/Table/useTable/util/columns';\nimport { COLUMN_ID as ACTIONS_COLUMN_ID } from '../components/columns/internal/Actions';\nimport { COLUMN_ID as EDITING_ACTIONS_COLUMN_ID } from '../components/columns/internal/EditingActions';\n\ndeclare module '@tanstack/table-core' {\n interface TableMeta<TData extends RowData> {\n columnFreezing: ReturnType<typeof useColumnFreezing>;\n columnOrdering: ReturnType<typeof useTableColumnOrdering>;\n editing: ReturnType<typeof useEditing>;\n enableFooter: boolean;\n fontSize: ReturnType<typeof useTableFontSize>;\n getSettings: () => Table3Settings;\n isPrinting: boolean;\n isUsingServer: boolean;\n printing: ReturnType<typeof usePrinting>;\n rowActions: ReturnType<typeof useRowActions>;\n rowActive: ReturnType<typeof useTableRowActive>;\n rowClick: ReturnType<typeof useTableRowClick>;\n rowDrag: ReturnType<typeof useRowDrag>;\n rowDrop: ReturnType<typeof useRowDrop>;\n rowGoto: ReturnType<typeof useTableRowGoto>;\n rowHeight: ReturnType<typeof useTableRowHeight>;\n rowSelection: ReturnType<typeof useTableRowSelection>;\n search: ReturnType<typeof useSearch>;\n server: ReturnType<typeof useTableServerLoading>;\n shortcutsState: ReturnType<typeof usePauseShortcuts>;\n tableRef: React.RefObject<Table3Ref>;\n validation: Table3Validation<TData>;\n }\n\n interface ColumnMeta<TData extends RowData, TValue> {\n align?: Table3ColumnAlignment;\n className?: Table3ColumnClassNameHandler<TData>;\n control?: Table3ColumnControlRenderer<TData>;\n dataType?: Table3ColumnDataType;\n defaultWidth?: number;\n enableOrdering?: boolean;\n enableSearch: boolean;\n enableTruncate?: boolean;\n filters?: Table3FilterComparator[];\n footer?: Table3ColumnFooterRenderer;\n header: string;\n headerClassName?: string;\n menu?: Table3ColumnHeaderMenu;\n renderer?: Table3ColumnRenderer<TValue, TData>;\n tooltip?: string;\n }\n\n interface CellContext<TData extends RowData, TValue> {\n index: number;\n tableRef: React.RefObject<HTMLDivElement>;\n }\n\n interface HeaderContext<TData extends RowData, TValue> {\n scrollToIndex: TableStrategy['scrollToIndex'];\n }\n}\n\nexport function useTable<TType = unknown>(props: Table3Props<TType>, ref: React.RefObject<Table3Ref>) {\n // load any persisted table settings and merge them with any defaults\n const [settings, setSettings] = useSettings(props.id, props.defaultSettings, props.onChangeSettings);\n\n // configure table3 options\n const options = useTablePreset(props);\n\n // configure react-table built-in features\n const tableOptions = configureReactTableOptions(props, options);\n\n // configure custom features\n const columnFreezing = useColumnFreezing(settings.columnFreezingIndex ?? props.defaultColumnFreezingIndex, options);\n // can't change due to rename to \"active row\"\n const validation = useValidation<TType>(props.onCellValidate, props.onRowValidate);\n // not relevant to common table\n const editing = useEditing<TType>(options.enableEditing, ref, validation, props.onSave);\n // we changed how printing works, so this shouldn't be migrated\n const printing = usePrinting(options.enablePrinting, settings.showWarningWhenPrintingLargeDataset, props.id);\n // needs to be moved\n const rowActions = useRowActions<TType>(props.actionsForRow, props.actionsForRowLength);\n // not relevant to common table\n const rowDrag = useRowDrag(options.enableRowDrag);\n // not relevant to common table\n const rowDrop = useRowDrop(options.enableRowDrop, props.onRowDrop);\n // haven't migrated load all/server loading yet\n const search = useSearch(options.enableSearch, settings.excludeUnmatchedRecordsInSearch);\n const shortcutsState = usePauseShortcuts();\n\n // custom features - shared/migrated\n const columnOrdering = useTableColumnOrdering(options.enableColumnOrdering);\n const fontSize = useTableFontSize(options.enableFontSize, settings.fontSize);\n const rowActive = useTableRowActive(true, props.defaultCurrentRowIndex);\n const rowClick = useTableRowClick<TType>(true, props.onRowClick);\n const rowGoto = useTableRowGoto(options.enableRowGoto, props.onRowGoto);\n const rowHeight = useTableRowHeight(options.enableRowHeight, settings.rowHeight);\n const rowSelection = useTableRowSelection(options.enableRowSelection);\n const server = useTableServerLoading(props.loadPage, props.loadAll);\n\n // columns\n const { columns, defaultColumnSizing, defaultColumnVisibility, defaultSorting } = useConvertChildrenToColumns<TType>(\n props,\n options,\n editing\n );\n\n // built-in features\n const initialState: Partial<TableState> = React.useMemo(() => {\n const sanitizeSortedColumns = column => columns.find(definedColumn => definedColumn.id === column.id);\n\n const state: Partial<TableState> = {\n columnOrder: ensureOrdering<TType>(columns, settings.columnOrder, [ACTIONS_COLUMN_ID, EDITING_ACTIONS_COLUMN_ID]),\n columnSizing: settings.columnSizing ?? defaultColumnSizing,\n columnVisibility: settings.columnVisibility ?? defaultColumnVisibility,\n sorting: settings.sorting ? settings.sorting.filter(sanitizeSortedColumns) : defaultSorting,\n };\n\n // we don't save these outside the table, but they need to be here for print to inherit them - see PrintButton.tsx\n if ((props.defaultSettings as any)?.columnFilters) {\n state.columnFilters = (props.defaultSettings as any)?.columnFilters;\n }\n\n if ((props.defaultSettings as any)?.globalFilter) {\n state.globalFilter = (props.defaultSettings as any)?.globalFilter;\n }\n\n return state;\n }, []);\n\n const getSettings = () => {\n const state = table.getState();\n return {\n columnFreezingIndex: columnFreezing.frozenColumnIndex,\n columnOrder: columnOrdering.isEnabled ? state.columnOrder : undefined,\n columnSizing: table.options.enableColumnResizing ? state.columnSizing : undefined,\n columnVisibility: table.options.enableHiding ? state.columnVisibility : undefined,\n excludeUnmatchedRecordsInSearch: search.excludeUnmatchedResults,\n fontSize: fontSize.isEnabled ? fontSize.size : undefined,\n rowHeight: rowHeight.isEnabled ? rowHeight.height : undefined,\n showWarningWhenPrintingLargeDataset: printing.isWarningVisibleForLargeDatasets,\n sorting: state.sorting,\n };\n };\n\n const table = useReactTable<TType>({\n data: props.data,\n columns,\n getCoreRowModel: getCoreRowModel(),\n initialState,\n ...tableOptions,\n //debugAll: true,\n meta: {\n columnFreezing,\n columnOrdering,\n editing,\n enableFooter: options.enableFooter,\n fontSize,\n getSettings,\n isPrinting: props.id.endsWith('_print'),\n isUsingServer: !!props.loadPage,\n printing,\n rowActions: rowActions as any,\n rowActive,\n rowClick: rowClick as any,\n rowDrag,\n rowDrop,\n rowGoto,\n rowHeight,\n rowSelection,\n search,\n server,\n shortcutsState,\n tableRef: ref,\n validation,\n },\n });\n\n // listeners\n useEditingStateListener(table);\n useSettingsStateListener(table, setSettings);\n // listeners - shared/migrated\n useTableDataListener(table);\n useTableFilterListener(table, props.onFilter);\n useTableFontSizeListener(table);\n useTableRowSelectionListener(table, props.onRowSelect);\n useTableServerLoadingListener(table, props.loadPage);\n useTableShortcutsListener(table, props.shortcuts);\n useTableSortingListener(table, props.onSort);\n\n return { table, length: props.length ?? props.data.length };\n}\n\nfunction configureReactTableOptions<TType = unknown>(props: Table3Props<TType>, options: Table3Options) {\n const tableOptions: Partial<RTableOptions<TType>> = {\n enableColumnFilters: options.enableFiltering,\n enableColumnResizing: options.enableColumnResizing,\n enableExpanding: options.enableRowExpansion,\n enableGlobalFilter: options.enableSearch,\n enableHiding: options.enableColumnHiding,\n enableRowSelection: options.enableRowSelection,\n enableMultiRowSelection: !options.enableRowSelectionSingle,\n enableSorting: options.enableSorting,\n };\n\n // resizing\n if (tableOptions.enableColumnResizing) {\n tableOptions.columnResizeMode = 'onChange';\n }\n\n // filtering\n if (tableOptions.enableColumnFilters) {\n if (!props.onFilter) {\n tableOptions.filterFns = {\n tacoFilter: (row: RTRow<TType>, columnId: string, filter: any) => columnFilterFn(row.getValue(columnId), filter),\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n }\n\n // we don't tableOptions.manualFiltering = true; because it breaks global filtering, server filtering still works :shrug:\n }\n\n // search\n if (tableOptions.enableGlobalFilter) {\n // search is always client side, since we call loadAll when searching\n tableOptions.globalFilterFn = (row: RTRow<TType>, columnId: string, searchQuery: string) => {\n try {\n if (row.original) {\n const cell = row.getAllCells().find(cell => cell.column.id === columnId);\n const columnMeta = cell?.column.columnDef.meta;\n\n if (cell && cell.column.getIsVisible() && columnMeta?.enableSearch) {\n const cellValue = getCellValueAsString(row.original[columnId], columnMeta?.dataType);\n\n if (cellValue !== undefined) {\n return globalFilterFn(cellValue, searchQuery);\n }\n }\n return false;\n }\n } catch {\n //\n }\n\n return false;\n };\n tableOptions.getFilteredRowModel = getFilteredRowModel();\n tableOptions.getColumnCanGlobalFilter = (column: RTColumn<TType>) =>\n (column.columnDef.meta as ColumnMeta<TType, unknown>).enableSearch ?? true;\n }\n\n // sorting\n if (options.enableSorting) {\n if (props.onSort) {\n tableOptions.manualSorting = true;\n // onSort is called as a listener to let the consumer update their data, so we don't use onSortingChange\n } else {\n tableOptions.getSortedRowModel = getSortedRowModel();\n }\n }\n\n return tableOptions;\n}\n"],"names":["useTable","props","ref","settings","setSettings","useSettings","id","defaultSettings","onChangeSettings","options","useTablePreset","tableOptions","configureReactTableOptions","columnFreezing","useColumnFreezing","_settings$columnFreez","columnFreezingIndex","defaultColumnFreezingIndex","validation","useValidation","onCellValidate","onRowValidate","editing","useEditing","enableEditing","onSave","printing","usePrinting","enablePrinting","showWarningWhenPrintingLargeDataset","rowActions","useRowActions","actionsForRow","actionsForRowLength","rowDrag","useRowDrag","enableRowDrag","rowDrop","useRowDrop","enableRowDrop","onRowDrop","search","useSearch","enableSearch","excludeUnmatchedRecordsInSearch","shortcutsState","usePauseShortcuts","columnOrdering","useTableColumnOrdering","enableColumnOrdering","fontSize","useTableFontSize","enableFontSize","rowActive","useTableRowActive","defaultCurrentRowIndex","rowClick","useTableRowClick","onRowClick","rowGoto","useTableRowGoto","enableRowGoto","onRowGoto","rowHeight","useTableRowHeight","enableRowHeight","rowSelection","useTableRowSelection","enableRowSelection","server","useTableServerLoading","loadPage","loadAll","columns","defaultColumnSizing","defaultColumnVisibility","defaultSorting","useConvertChildrenToColumns","initialState","React","useMemo","sanitizeSortedColumns","column","find","definedColumn","state","columnOrder","ensureOrdering","ACTIONS_COLUMN_ID","EDITING_ACTIONS_COLUMN_ID","columnSizing","_settings$columnSizin","columnVisibility","_settings$columnVisib","sorting","filter","_props$defaultSetting","columnFilters","_props$defaultSetting2","_props$defaultSetting3","globalFilter","_props$defaultSetting4","getSettings","table","getState","frozenColumnIndex","isEnabled","undefined","enableColumnResizing","enableHiding","excludeUnmatchedResults","size","height","isWarningVisibleForLargeDatasets","useReactTable","data","getCoreRowModel","meta","enableFooter","isPrinting","endsWith","isUsingServer","tableRef","useEditingStateListener","useSettingsStateListener","useTableDataListener","useTableFilterListener","onFilter","useTableFontSizeListener","useTableRowSelectionListener","onRowSelect","useTableServerLoadingListener","useTableShortcutsListener","shortcuts","useTableSortingListener","onSort","length","_props$length","enableColumnFilters","enableFiltering","enableExpanding","enableRowExpansion","enableGlobalFilter","enableColumnHiding","enableMultiRowSelection","enableRowSelectionSingle","enableSorting","columnResizeMode","filterFns","tacoFilter","row","columnId","columnFilterFn","getValue","getFilteredRowModel","globalFilterFn","searchQuery","original","cell","getAllCells","columnMeta","columnDef","getIsVisible","cellValue","getCellValueAsString","dataType","getColumnCanGlobalFilter","_column$columnDef$met","manualSorting","getSortedRowModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAqHgBA,QAAQA,CAAkBC,KAAyB,EAAEC,GAA+B;;;EAEhG,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGC,WAAW,CAACJ,KAAK,CAACK,EAAE,EAAEL,KAAK,CAACM,eAAe,EAAEN,KAAK,CAACO,gBAAgB,CAAC;;EAGpG,MAAMC,OAAO,GAAGC,cAAc,CAACT,KAAK,CAAC;;EAGrC,MAAMU,YAAY,GAAGC,0BAA0B,CAACX,KAAK,EAAEQ,OAAO,CAAC;;EAG/D,MAAMI,cAAc,GAAGC,iBAAiB,EAAAC,qBAAA,GAACZ,QAAQ,CAACa,mBAAmB,cAAAD,qBAAA,cAAAA,qBAAA,GAAId,KAAK,CAACgB,0BAA0B,EAAER,OAAO,CAAC;;EAEnH,MAAMS,UAAU,G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U,eAAVA,UAAU,CAAErH,YAAY,EAAE;YAChE,MAAMwH,SAAS,GAAGC,oBAAoB,CAACd,GAAG,CAACO,QAAQ,CAACN,QAAQ,CAAC,EAAES,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEK,QAAQ,CAAC;YAEpF,IAAIF,SAAS,KAAKxD,SAAS,EAAE;cACzB,OAAOgD,cAAc,CAACQ,SAAS,EAAEP,WAAW,CAAC;;;UAGrD,OAAO,KAAK;;OAEnB,CAAC,MAAM;;;MAIR,OAAO,KAAK;KACf;IACDjJ,YAAY,CAAC+I,mBAAmB,GAAGA,mBAAmB,EAAE;IACxD/I,YAAY,CAAC2J,wBAAwB,GAAIpF,MAAuB;MAAA,IAAAqF,qBAAA;MAAA,QAAAA,qBAAA,GAC3DrF,MAAM,CAAC+E,SAAS,CAAC5C,IAAmC,CAAC1E,YAAY,cAAA4H,qBAAA,cAAAA,qBAAA,GAAI,IAAI;;;;EAIlF,IAAI9J,OAAO,CAACyI,aAAa,EAAE;IACvB,IAAIjJ,KAAK,CAACsI,MAAM,EAAE;MACd5H,YAAY,CAAC6J,aAAa,GAAG,IAAI;;KAEpC,MAAM;MACH7J,YAAY,CAAC8J,iBAAiB,GAAGA,iBAAiB,EAAE;;;EAI5D,OAAO9J,YAAY;AACvB;;;;"}
|
@@ -14471,7 +14471,7 @@ var SavingStatusValue;
|
|
14471
14471
|
SavingStatusValue["Saved"] = "saved";
|
14472
14472
|
SavingStatusValue["Error"] = "error";
|
14473
14473
|
})(SavingStatusValue || (SavingStatusValue = {}));
|
14474
|
-
function useEditing(isEnabled, validation, onSave) {
|
14474
|
+
function useEditing(isEnabled, tableRef, validation, onSave) {
|
14475
14475
|
// used to switch the table into editing mode
|
14476
14476
|
const [isEditing, setIsEditing] = React__default.useState(false);
|
14477
14477
|
// Saving indicator need to show saving status per row, saving status can have at least two states 'saving', 'saved',
|
@@ -14638,6 +14638,20 @@ function useEditing(isEnabled, validation, onSave) {
|
|
14638
14638
|
}
|
14639
14639
|
return false;
|
14640
14640
|
}, [isEditing, editingState]);
|
14641
|
+
React__default.useEffect(() => {
|
14642
|
+
const handleClickOutside = event => {
|
14643
|
+
const target = event.target;
|
14644
|
+
const closestPopup = target.closest('[role="dialog"], [role="menu"]');
|
14645
|
+
// Need to check that neither target itself nor closest popup is inside or triggetred from the table.
|
14646
|
+
if (!isElementInsideOrTriggeredFromContainer(target, tableRef.current) && !isElementInsideOrTriggeredFromContainer(closestPopup, tableRef.current)) {
|
14647
|
+
saveChangesIfNeeded();
|
14648
|
+
}
|
14649
|
+
};
|
14650
|
+
document.addEventListener('click', handleClickOutside);
|
14651
|
+
return () => {
|
14652
|
+
document.removeEventListener('click', handleClickOutside);
|
14653
|
+
};
|
14654
|
+
}, [saveChangesIfNeeded]);
|
14641
14655
|
function getSavingStatus(rowId) {
|
14642
14656
|
return savingStatuses && savingStatuses[rowId];
|
14643
14657
|
}
|
@@ -16394,7 +16408,7 @@ function useTable$1(props, ref) {
|
|
16394
16408
|
// can't change due to rename to "active row"
|
16395
16409
|
const validation = useValidation(props.onCellValidate, props.onRowValidate);
|
16396
16410
|
// not relevant to common table
|
16397
|
-
const editing = useEditing(options.enableEditing, validation, props.onSave);
|
16411
|
+
const editing = useEditing(options.enableEditing, ref, validation, props.onSave);
|
16398
16412
|
// we changed how printing works, so this shouldn't be migrated
|
16399
16413
|
const printing = usePrinting(options.enablePrinting, settings.showWarningWhenPrintingLargeDataset, props.id);
|
16400
16414
|
// needs to be moved
|