@economic/taco 2.14.2 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Drawer/Drawer.d.ts +5 -1
- package/dist/components/Icon/components/AiChatSolid.d.ts +3 -0
- package/dist/components/Icon/components/AiStars.d.ts +3 -0
- package/dist/components/Icon/components/EnvelopeSolid.d.ts +3 -0
- package/dist/components/Icon/components/PhoneSolid.d.ts +3 -0
- package/dist/components/Icon/components/QuestionMarkBold.d.ts +3 -0
- package/dist/components/Icon/components/index.d.ts +1 -1
- package/dist/components/Input/Input.d.ts +1 -1
- package/dist/components/Menu/components/Item.d.ts +1 -1
- package/dist/components/Menu/components/Link.d.ts +1 -1
- package/dist/components/Navigation2/components/Link.d.ts +1 -1
- package/dist/components/Provider/Localization.d.ts +19 -0
- package/dist/components/SearchInput2/SearchInput2.d.ts +1 -0
- package/dist/components/Select2/components/Option.d.ts +2 -2
- package/dist/components/Select2/components/Search.d.ts +1 -1
- package/dist/components/Table3/components/alert/ErrorAlert.d.ts +10 -0
- package/dist/components/Table3/components/columns/cell/DisplayCell.d.ts +5 -2
- package/dist/components/Table3/components/columns/cell/EditingCell.d.ts +3 -0
- package/dist/components/Table3/components/columns/cell/Highlight.d.ts +2 -0
- package/dist/components/Table3/components/columns/internal/EditingActions.d.ts +1 -1
- package/dist/components/Table3/components/rows/Row.d.ts +2 -0
- package/dist/components/Table3/components/rows/RowContext.d.ts +1 -0
- package/dist/components/Table3/hooks/features/useEditing.d.ts +12 -11
- package/dist/components/Table3/hooks/features/usePauseShortcuts.d.ts +5 -0
- package/dist/components/Table3/hooks/features/useSearch.d.ts +2 -0
- package/dist/components/Table3/hooks/features/useValidation.d.ts +13 -0
- package/dist/components/Table3/hooks/useTable.d.ts +4 -0
- package/dist/components/Table3/types.d.ts +26 -1
- package/dist/components/Table3/util/editing.d.ts +6 -0
- package/dist/components/Tag/Tag.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +4 -0
- package/dist/esm/index.css +112 -33
- package/dist/esm/packages/taco/src/components/Drawer/Drawer.js +7 -2
- package/dist/esm/packages/taco/src/components/Drawer/Drawer.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Field/Field.js +19 -3
- package/dist/esm/packages/taco/src/components/Field/Field.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Icon/components/AiChatSolid.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/AiChatSolid.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/AiStars.js +30 -0
- package/dist/esm/packages/taco/src/components/Icon/components/AiStars.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/EnvelopeSolid.js +19 -0
- package/dist/esm/packages/taco/src/components/Icon/components/EnvelopeSolid.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/PhoneSolid.js +17 -0
- package/dist/esm/packages/taco/src/components/Icon/components/PhoneSolid.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/QuestionMarkBold.js +17 -0
- package/dist/esm/packages/taco/src/components/Icon/components/QuestionMarkBold.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Icon/components/index.js +10 -0
- package/dist/esm/packages/taco/src/components/Icon/components/index.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +19 -0
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +4 -0
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +28 -4
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/alert/ErrorAlert.js +154 -0
- package/dist/esm/packages/taco/src/components/Table3/components/alert/ErrorAlert.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js +51 -6
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Cell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js +7 -55
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/DisplayCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js +69 -37
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingCell.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingControl.js +17 -17
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/EditingControl.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Highlight.js +41 -0
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/Highlight.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/controls/TextareaControl.js +21 -12
- package/dist/esm/packages/taco/src/components/Table3/components/columns/cell/controls/TextareaControl.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/footer/Footer.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/footer/Footer.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Group.js +6 -5
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Group.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Header.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/columns/header/Header.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js +57 -17
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/EditingActions.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/rows/Row.js +42 -32
- package/dist/esm/packages/taco/src/components/Table3/components/rows/Row.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/rows/RowContext.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/components/rows/RowContext.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js +8 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/hooks/useParentStylesheets.js +2 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/hooks/useParentStylesheets.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Search.js +48 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Search.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Settings.js +2 -2
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Settings.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Toolbar.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Toolbar.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useEditing.js +185 -101
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useEditing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/usePauseShortcuts.js +12 -0
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/usePauseShortcuts.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useSearch.js +4 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useSearch.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useValidation.js +178 -0
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useValidation.js.map +1 -0
- package/dist/esm/packages/taco/src/components/Table3/hooks/useConvertChildrenToColumns.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useConvertChildrenToColumns.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +8 -2
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/strategies/virtualised.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/types.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js +21 -1
- package/dist/esm/packages/taco/src/components/Table3/util/editing.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Tooltip/Tooltip.js +4 -0
- package/dist/esm/packages/taco/src/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/hooks/useTruncated.js +20 -0
- package/dist/esm/packages/taco/src/utils/hooks/useTruncated.js.map +1 -0
- package/dist/index.css +112 -33
- package/dist/taco.cjs.development.js +1735 -957
- 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 +23852 -10957
@@ -1,57 +1,48 @@
|
|
1
1
|
import React__default from 'react';
|
2
2
|
import { shouldTriggerShortcut } from '../../../../utils/keyboard.js';
|
3
3
|
import _ from 'lodash-es';
|
4
|
+
import { lastCellIndex } from '../../components/rows/Row.js';
|
4
5
|
|
5
|
-
var
|
6
|
-
(function (
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
})(
|
11
|
-
function useEditing(isEnabled, onSave) {
|
6
|
+
var SavingStatusValue;
|
7
|
+
(function (SavingStatusValue) {
|
8
|
+
SavingStatusValue["Saving"] = "saving";
|
9
|
+
SavingStatusValue["Saved"] = "saved";
|
10
|
+
SavingStatusValue["Error"] = "error";
|
11
|
+
})(SavingStatusValue || (SavingStatusValue = {}));
|
12
|
+
function useEditing(isEnabled, validation, onSave) {
|
12
13
|
// used to switch the table into editing mode
|
13
14
|
const [isEditing, setIsEditing] = React__default.useState(false);
|
14
|
-
// Saving indicator need to show saving
|
15
|
+
// Saving indicator need to show saving status per row, saving status can have at least two states 'saving', 'saved',
|
15
16
|
// 'saved' should remain for a few seconds to show tick icon after row has been saved.
|
16
|
-
const [
|
17
|
+
const [savingStatuses, dispatchSavingStatusAction] = React__default.useReducer(savingStatusesReducer, null);
|
17
18
|
// sets of row changes pending save, either they have not saved yet or they have errors
|
18
|
-
const [
|
19
|
+
const [editingState, dispatchEditingAction] = React__default.useReducer((state, action) => editingReducer(state, action), null);
|
19
20
|
const [detailModeEditing, setDetailModeEditing] = React__default.useState(false);
|
20
21
|
function getCellValue(cell) {
|
21
|
-
var
|
22
|
-
return
|
22
|
+
var _editingState$cell$ro;
|
23
|
+
return editingState ? (_editingState$cell$ro = editingState[cell.row.id]) === null || _editingState$cell$ro === void 0 ? void 0 : _editingState$cell$ro[cell.column.id] : undefined;
|
23
24
|
}
|
24
25
|
// Saves editing cell value into editing state.
|
25
26
|
function setCellValue(cell, value) {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
} else {
|
34
|
-
nextChanges[cell.row.id] = {
|
35
|
-
...cell.row.original,
|
36
|
-
[cell.column.id]: value
|
37
|
-
};
|
27
|
+
dispatchEditingAction({
|
28
|
+
type: EditingActionType.SET_CELL_VALUE,
|
29
|
+
payload: {
|
30
|
+
rowId: cell.row.id,
|
31
|
+
cellId: cell.column.id,
|
32
|
+
value,
|
33
|
+
originalValues: cell.row.original
|
38
34
|
}
|
39
|
-
return nextChanges;
|
40
35
|
});
|
41
36
|
}
|
42
37
|
// Removes changes from editing state by row id
|
43
38
|
function resetChange(rowId) {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
|
51
|
-
if (changeset.length === 0) {
|
52
|
-
currentChanges = null;
|
53
|
-
}
|
54
|
-
setChanges(currentChanges);
|
39
|
+
dispatchEditingAction({
|
40
|
+
type: EditingActionType.RESET_CHANGE,
|
41
|
+
payload: {
|
42
|
+
rowId
|
43
|
+
}
|
44
|
+
});
|
45
|
+
validation.resetErrors(rowId);
|
55
46
|
}
|
56
47
|
const handleKeyDown = React__default.useCallback(event => {
|
57
48
|
if (event.defaultPrevented) {
|
@@ -78,71 +69,93 @@ function useEditing(isEnabled, onSave) {
|
|
78
69
|
saveChangesIfNeeded();
|
79
70
|
}
|
80
71
|
}, []);
|
81
|
-
// Creates initial saving
|
82
|
-
const
|
83
|
-
const changeset = Object.keys(
|
84
|
-
const
|
72
|
+
// Creates initial saving statuses from changes object
|
73
|
+
const addSavingStatuses = () => {
|
74
|
+
const changeset = Object.keys(editingState || {});
|
75
|
+
const additionalSavingStatuses = _.reduce(changeset, (result, rowId) => {
|
85
76
|
return {
|
86
77
|
...result,
|
87
|
-
[
|
88
|
-
state: SavingStateValue.Saving
|
89
|
-
}
|
78
|
+
[rowId]: SavingStatusValue.Saving
|
90
79
|
};
|
91
80
|
}, {});
|
92
|
-
|
93
|
-
|
94
|
-
|
81
|
+
dispatchSavingStatusAction({
|
82
|
+
type: SavingStatusActionType.SET_SAVING_STATUSES,
|
83
|
+
payload: {
|
84
|
+
states: additionalSavingStatuses
|
85
|
+
}
|
95
86
|
});
|
96
87
|
};
|
97
|
-
//
|
98
|
-
const
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
88
|
+
// Resets/removes saving status by row id. Used in delayed saving indicator.
|
89
|
+
const resetSavingStatus = rowId => {
|
90
|
+
dispatchSavingStatusAction({
|
91
|
+
type: SavingStatusActionType.RESET_SAVING_STATUS,
|
92
|
+
payload: {
|
93
|
+
rowId
|
94
|
+
}
|
95
|
+
});
|
104
96
|
};
|
105
97
|
// Checks if we have changes, then saves them
|
106
98
|
const saveChangesIfNeeded = function () {
|
107
99
|
try {
|
108
|
-
if (!
|
100
|
+
if (!editingState) {
|
109
101
|
return Promise.resolve();
|
110
102
|
}
|
111
|
-
const changeset = Object.keys(
|
103
|
+
const changeset = Object.keys(editingState);
|
112
104
|
const _temp = function () {
|
113
105
|
if (onSave && changeset.length) {
|
114
|
-
|
115
|
-
return Promise.resolve(Promise.allSettled(changeset.map(rowId =>
|
116
|
-
|
117
|
-
const
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
106
|
+
addSavingStatuses();
|
107
|
+
return Promise.resolve(Promise.allSettled(changeset.map(rowId => {
|
108
|
+
const validationSavePromise = new Promise((resolve, reject) => {
|
109
|
+
const changedRow = editingState === null || editingState === void 0 ? void 0 : editingState[rowId];
|
110
|
+
if (changedRow) {
|
111
|
+
var _validation$validate;
|
112
|
+
(_validation$validate = validation.validate(rowId, changedRow)) === null || _validation$validate === void 0 ? void 0 : _validation$validate.then(() => {
|
113
|
+
const savePromise = onSave(changedRow);
|
114
|
+
savePromise.then(() => {
|
115
|
+
resolve();
|
116
|
+
}).catch(reason => {
|
117
|
+
if (reason.errors) {
|
118
|
+
validation.setRowErrors(rowId, reason.errors);
|
119
|
+
}
|
120
|
+
reject(reason);
|
121
|
+
});
|
122
|
+
}).catch(() => {
|
123
|
+
validation.confirmErrors(rowId);
|
124
|
+
dispatchSavingStatusAction({
|
125
|
+
type: SavingStatusActionType.SET_SAVING_STATUS,
|
126
|
+
payload: {
|
127
|
+
rowId,
|
128
|
+
state: SavingStatusValue.Error
|
129
|
+
}
|
130
|
+
});
|
131
|
+
reject();
|
132
|
+
});
|
133
|
+
} else {
|
134
|
+
reject();
|
135
|
+
}
|
127
136
|
});
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
137
|
+
return validationSavePromise;
|
138
|
+
}))).then(function (responses) {
|
139
|
+
responses.forEach((response, index) => {
|
140
|
+
const rowId = changeset[index];
|
141
|
+
if (response.status === 'fulfilled') {
|
142
|
+
resetChange(rowId);
|
143
|
+
dispatchSavingStatusAction({
|
144
|
+
type: SavingStatusActionType.SET_SAVING_STATUS,
|
145
|
+
payload: {
|
146
|
+
rowId,
|
147
|
+
state: SavingStatusValue.Saved
|
148
|
+
}
|
149
|
+
});
|
150
|
+
} else {
|
151
|
+
dispatchSavingStatusAction({
|
152
|
+
type: SavingStatusActionType.SET_SAVING_STATUS,
|
153
|
+
payload: {
|
154
|
+
rowId,
|
155
|
+
state: SavingStatusValue.Error
|
156
|
+
}
|
157
|
+
});
|
158
|
+
}
|
146
159
|
});
|
147
160
|
});
|
148
161
|
}
|
@@ -152,34 +165,37 @@ function useEditing(isEnabled, onSave) {
|
|
152
165
|
return Promise.reject(e);
|
153
166
|
}
|
154
167
|
};
|
155
|
-
const [rowMoveReason, setRowMoveReason] = React__default.useState(
|
156
|
-
const removeRowMoveReason =
|
157
|
-
setRowMoveReason(
|
158
|
-
const newState = {
|
159
|
-
...prevState
|
160
|
-
};
|
161
|
-
delete newState[columnId];
|
162
|
-
return newState;
|
163
|
-
});
|
168
|
+
const [rowMoveReason, setRowMoveReason] = React__default.useState(null);
|
169
|
+
const removeRowMoveReason = () => {
|
170
|
+
setRowMoveReason(null);
|
164
171
|
};
|
165
172
|
const showWarning = React__default.useCallback(event => {
|
166
|
-
if (isEditing &&
|
173
|
+
if (isEditing && editingState && Object.keys(editingState).length > 0) {
|
167
174
|
event.returnValue = true;
|
168
175
|
return true;
|
169
176
|
}
|
170
177
|
return false;
|
171
|
-
}, [isEditing,
|
178
|
+
}, [isEditing, editingState]);
|
179
|
+
function getSavingStatus(rowId) {
|
180
|
+
return savingStatuses && savingStatuses[rowId];
|
181
|
+
}
|
172
182
|
React__default.useEffect(() => {
|
173
183
|
window.addEventListener('beforeunload', showWarning);
|
174
184
|
return () => {
|
175
185
|
window.removeEventListener('beforeunload', showWarning);
|
176
186
|
};
|
177
187
|
}, [showWarning]);
|
188
|
+
React__default.useEffect(() => {
|
189
|
+
if (!isEditing) {
|
190
|
+
setDetailModeEditing(false);
|
191
|
+
lastCellIndex.value = null;
|
192
|
+
}
|
193
|
+
}, [isEditing]);
|
178
194
|
return {
|
179
195
|
isEnabled,
|
180
196
|
isEditing,
|
181
197
|
toggleEditing: setIsEditing,
|
182
|
-
changes,
|
198
|
+
changes: editingState,
|
183
199
|
getCellValue,
|
184
200
|
setCellValue,
|
185
201
|
saveChangesIfNeeded,
|
@@ -191,10 +207,78 @@ function useEditing(isEnabled, onSave) {
|
|
191
207
|
handleKeyDown,
|
192
208
|
handleBlur,
|
193
209
|
resetChange,
|
194
|
-
|
195
|
-
|
210
|
+
getSavingStatus,
|
211
|
+
resetSavingStatus
|
196
212
|
};
|
197
213
|
}
|
214
|
+
var EditingActionType;
|
215
|
+
(function (EditingActionType) {
|
216
|
+
EditingActionType[EditingActionType["SET_CELL_VALUE"] = 0] = "SET_CELL_VALUE";
|
217
|
+
EditingActionType[EditingActionType["RESET_CHANGE"] = 1] = "RESET_CHANGE";
|
218
|
+
})(EditingActionType || (EditingActionType = {}));
|
219
|
+
function editingReducer(state, action) {
|
220
|
+
switch (action.type) {
|
221
|
+
// Set cell value of the row
|
222
|
+
case EditingActionType.SET_CELL_VALUE:
|
223
|
+
return {
|
224
|
+
...state,
|
225
|
+
[action.payload.rowId]: {
|
226
|
+
...((state === null || state === void 0 ? void 0 : state[action.payload.rowId]) || action.payload.originalValues),
|
227
|
+
[action.payload.cellId]: action.payload.value
|
228
|
+
}
|
229
|
+
};
|
230
|
+
// Reset changes for the row
|
231
|
+
case EditingActionType.RESET_CHANGE:
|
232
|
+
{
|
233
|
+
let currentChanges = {
|
234
|
+
...state
|
235
|
+
};
|
236
|
+
if (currentChanges) {
|
237
|
+
delete currentChanges[action.payload.rowId];
|
238
|
+
}
|
239
|
+
const changeset = Object.keys(currentChanges);
|
240
|
+
if (changeset.length === 0) {
|
241
|
+
currentChanges = null;
|
242
|
+
}
|
243
|
+
return currentChanges;
|
244
|
+
}
|
245
|
+
default:
|
246
|
+
return state;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
var SavingStatusActionType;
|
250
|
+
(function (SavingStatusActionType) {
|
251
|
+
SavingStatusActionType[SavingStatusActionType["SET_SAVING_STATUS"] = 0] = "SET_SAVING_STATUS";
|
252
|
+
SavingStatusActionType[SavingStatusActionType["SET_SAVING_STATUSES"] = 1] = "SET_SAVING_STATUSES";
|
253
|
+
SavingStatusActionType[SavingStatusActionType["RESET_SAVING_STATUS"] = 2] = "RESET_SAVING_STATUS";
|
254
|
+
})(SavingStatusActionType || (SavingStatusActionType = {}));
|
255
|
+
function savingStatusesReducer(state, action) {
|
256
|
+
switch (action.type) {
|
257
|
+
// Set single saving status for the row
|
258
|
+
case SavingStatusActionType.SET_SAVING_STATUS:
|
259
|
+
return {
|
260
|
+
...state,
|
261
|
+
[action.payload.rowId]: action.payload.state
|
262
|
+
};
|
263
|
+
// Set multiple saving statuses for multiple rows at the same time
|
264
|
+
case SavingStatusActionType.SET_SAVING_STATUSES:
|
265
|
+
return {
|
266
|
+
...state,
|
267
|
+
...action.payload.states
|
268
|
+
};
|
269
|
+
// Reset/remove saving status for particular row
|
270
|
+
case SavingStatusActionType.RESET_SAVING_STATUS:
|
271
|
+
{
|
272
|
+
const newSavingStatus = {
|
273
|
+
...state
|
274
|
+
};
|
275
|
+
newSavingStatus === null || newSavingStatus === void 0 ? true : delete newSavingStatus[action.payload.rowId];
|
276
|
+
return newSavingStatus;
|
277
|
+
}
|
278
|
+
default:
|
279
|
+
return state;
|
280
|
+
}
|
281
|
+
}
|
198
282
|
|
199
|
-
export {
|
283
|
+
export { SavingStatusValue, useEditing };
|
200
284
|
//# sourceMappingURL=useEditing.js.map
|
@@ -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 { IndicatorReason } from '../../components/columns/cell/Indicator';\nimport { shouldTriggerShortcut } from '../../../../utils/keyboard';\n\nexport enum SavingStateValue {\n Saving = 'saving',\n Saved = 'saved',\n Error = 'error',\n}\n\nexport type SavingState = {\n state: SavingStateValue;\n};\n\nexport function useEditing<TType = unknown>(isEnabled: boolean, onSave?: (row: TType) => void) {\n // used to switch the table into editing mode\n const [isEditing, setIsEditing] = React.useState(false);\n // Saving indicator need to show saving state per row, saving state can have at lkeast two states 'saving', 'saved',\n // 'saved' should remain for a few seconds to show tick icon after row has been saved.\n const [savingStates, setSavingStates] = React.useState<Record<string, SavingState> | null>(null);\n\n // sets of row changes pending save, either they have not saved yet or they have errors\n const [changes, setChanges] = React.useState<Record<string, TType> | null>(null);\n\n const [detailModeEditing, setDetailModeEditing] = React.useState(false);\n\n function getCellValue<T extends TType>(cell: RTCell<T, unknown>) {\n return changes ? changes[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 setChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n\n if (nextChanges[cell.row.id]) {\n nextChanges[cell.row.id][cell.column.id] = value;\n // we should probably delete the cell if it has just reverted back to its original value\n } else {\n nextChanges[cell.row.id] = { ...cell.row.original, [cell.column.id]: value };\n }\n\n return nextChanges;\n });\n }\n\n // Removes changes from editing state by row id\n function resetChange(rowId: string) {\n let currentChanges: Record<string, TType> | null = changes ? { ...changes } : {};\n if (currentChanges) {\n delete currentChanges[rowId];\n }\n const changeset = Object.keys(currentChanges);\n if (changeset.length === 0) {\n currentChanges = null;\n }\n\n setChanges(currentChanges);\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 states from changes object\n const addSavingStates = () => {\n const changeset = Object.keys(changes || {});\n const additionalSavingStates = _.reduce(\n changeset,\n (result, value) => {\n return { ...result, [value]: { state: SavingStateValue.Saving } };\n },\n {}\n );\n setSavingStates({ ...savingStates, ...additionalSavingStates });\n };\n\n // Repoves edititng state by row is. Used in delayed saving indicator.\n const removeSavingState = (rowId: string) => {\n const newSavingStates = { ...savingStates };\n delete newSavingStates[rowId];\n setSavingStates(newSavingStates);\n };\n\n // Checks if we have changes, then saves them\n const saveChangesIfNeeded = async () => {\n if (!changes) {\n return;\n }\n\n const changeset = Object.keys(changes);\n if (onSave && changeset.length) {\n addSavingStates();\n\n const responses = await Promise.allSettled(changeset.map(rowId => onSave(changes[rowId])));\n\n setChanges(currentChanges => {\n const nextChanges = { ...currentChanges };\n\n responses.forEach((response, index) => {\n const rowId = changeset[index];\n\n if (response.status === 'fulfilled') {\n delete nextChanges[rowId];\n }\n });\n\n return nextChanges;\n });\n\n setSavingStates(savingStates => {\n const nextSavingStates = savingStates ? { ...savingStates } : {};\n responses.forEach((response, index) => {\n const rowId = changeset[index];\n\n if (response.status === 'fulfilled') {\n nextSavingStates[rowId] = { state: SavingStateValue.Saved };\n } else {\n // add the error when validation is added\n nextSavingStates[rowId] = { state: SavingStateValue.Error };\n }\n });\n return nextSavingStates;\n });\n }\n };\n\n const [rowMoveReason, setRowMoveReason] = React.useState<Record<string, IndicatorReason | null>>({});\n\n const removeRowMoveReason = (columnId: string) => {\n setRowMoveReason(prevState => {\n const newState = { ...prevState };\n delete newState[columnId];\n\n return newState;\n });\n };\n\n const showWarning = React.useCallback(\n event => {\n if (isEditing && changes && Object.keys(changes).length > 0) {\n event.returnValue = true;\n return true;\n }\n\n return false;\n },\n [isEditing, changes]\n );\n\n React.useEffect(() => {\n window.addEventListener('beforeunload', showWarning);\n\n return () => {\n window.removeEventListener('beforeunload', showWarning);\n };\n }, [showWarning]);\n\n return {\n isEnabled,\n isEditing,\n toggleEditing: setIsEditing,\n changes,\n getCellValue,\n setCellValue,\n saveChangesIfNeeded,\n detailModeEditing,\n setDetailModeEditing,\n rowMoveReason,\n setRowMoveReason,\n removeRowMoveReason,\n handleKeyDown,\n handleBlur,\n resetChange,\n savingStates,\n removeSavingState,\n };\n}\n"],"names":["SavingStateValue","useEditing","isEnabled","onSave","isEditing","setIsEditing","React","useState","savingStates","setSavingStates","changes","setChanges","detailModeEditing","setDetailModeEditing","getCellValue","cell","_changes$cell$row$id","row","id","column","undefined","setCellValue","value","currentChanges","nextChanges","original","resetChange","rowId","changeset","Object","keys","length","handleKeyDown","useCallback","event","defaultPrevented","shouldTriggerShortcut","key","meta","shift","editing","preventDefault","saveChangesIfNeeded","handleBlur","target","currentTarget","addSavingStates","additionalSavingStates","_","reduce","result","state","Saving","removeSavingState","newSavingStates","Promise","resolve","_temp","allSettled","map","then","responses","forEach","response","index","status","nextSavingStates","Saved","Error","e","reject","rowMoveReason","setRowMoveReason","removeRowMoveReason","columnId","prevState","newState","showWarning","returnValue","useEffect","window","addEventListener","removeEventListener","toggleEditing"],"mappings":";;;;IAOYA;AAAZ,WAAYA,gBAAgB;EACxBA,qCAAiB;EACjBA,mCAAe;EACfA,mCAAe;AACnB,CAAC,EAJWA,gBAAgB,KAAhBA,gBAAgB;SAUZC,UAAUA,CAAkBC,SAAkB,EAAEC,MAA6B;;EAEzF,MAAM,CAACC,SAAS,EAAEC,YAAY,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;;;EAGvD,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqC,IAAI,CAAC;;EAGhG,MAAM,CAACG,OAAO,EAAEC,UAAU,CAAC,GAAGL,cAAK,CAACC,QAAQ,CAA+B,IAAI,CAAC;EAEhF,MAAM,CAACK,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGP,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EAEvE,SAASO,YAAYA,CAAkBC,IAAwB;;IAC3D,OAAOL,OAAO,IAAAM,oBAAA,GAAGN,OAAO,CAACK,IAAI,CAACE,GAAG,CAACC,EAAE,CAAC,cAAAF,oBAAA,uBAApBA,oBAAA,CAAuBD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CAAC;EAEpG,MAAMkE,mBAAmB,GAAIC,QAAgB;IACzCF,gBAAgB,CAACG,SAAS;MACtB,MAAMC,QAAQ,GAAG;QAAE,GAAGD;OAAW;MACjC,OAAOC,QAAQ,CAACF,QAAQ,CAAC;MAEzB,OAAOE,QAAQ;KAClB,CAAC;GACL;EAED,MAAMC,WAAW,GAAGvE,cAAK,CAAC2B,WAAW,CACjCC,KAAK;IACD,IAAI9B,SAAS,IAAIM,OAAO,IAAImB,MAAM,CAACC,IAAI,CAACpB,OAAO,CAAC,CAACqB,MAAM,GAAG,CAAC,EAAE;MACzDG,KAAK,CAAC4C,WAAW,GAAG,IAAI;MACxB,OAAO,IAAI;;IAGf,OAAO,KAAK;GACf,EACD,CAAC1E,SAAS,EAAEM,OAAO,CAAC,CACvB;EAEDJ,cAAK,CAACyE,SAAS,CAAC;IACZC,MAAM,CAACC,gBAAgB,CAAC,cAAc,EAAEJ,WAAW,CAAC;IAEpD,OAAO;MACHG,MAAM,CAACE,mBAAmB,CAAC,cAAc,EAAEL,WAAW,CAAC;KAC1D;GACJ,EAAE,CAACA,WAAW,CAAC,CAAC;EAEjB,OAAO;IACH3E,SAAS;IACTE,SAAS;IACT+E,aAAa,EAAE9E,YAAY;IAC3BK,OAAO;IACPI,YAAY;IACZO,YAAY;IACZqB,mBAAmB;IACnB9B,iBAAiB;IACjBC,oBAAoB;IACpB0D,aAAa;IACbC,gBAAgB;IAChBC,mBAAmB;IACnBzC,aAAa;IACbW,UAAU;IACVjB,WAAW;IACXlB,YAAY;IACZ6C;GACH;AACL;;;;"}
|
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;QAAEU,MAAM,EAAEb,IAAI,CAACI,MAAM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EL,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;;;;"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import React__default from 'react';
|
2
|
+
|
3
|
+
function usePauseShortcuts() {
|
4
|
+
const [isShortcutsPaused, setIsShortcutsPaused] = React__default.useState(false);
|
5
|
+
return {
|
6
|
+
isPaused: isShortcutsPaused,
|
7
|
+
pause: setIsShortcutsPaused
|
8
|
+
};
|
9
|
+
}
|
10
|
+
|
11
|
+
export { usePauseShortcuts };
|
12
|
+
//# sourceMappingURL=usePauseShortcuts.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"usePauseShortcuts.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/usePauseShortcuts.ts"],"sourcesContent":["import React from 'react';\n\nexport function usePauseShortcuts() {\n const [isShortcutsPaused, setIsShortcutsPaused] = React.useState(false);\n\n return {\n isPaused: isShortcutsPaused,\n pause: setIsShortcutsPaused,\n };\n}\n"],"names":["usePauseShortcuts","isShortcutsPaused","setIsShortcutsPaused","React","useState","isPaused","pause"],"mappings":";;SAEgBA,iBAAiBA;EAC7B,MAAM,CAACC,iBAAiB,EAAEC,oBAAoB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EAEvE,OAAO;IACHC,QAAQ,EAAEJ,iBAAiB;IAC3BK,KAAK,EAAEJ;GACV;AACL;;;;"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import React__default from 'react';
|
2
2
|
|
3
3
|
function useSearch(isEnabled, excludeUnmatchedResultsInSearch = false, loadAll) {
|
4
|
+
const [isSearching, setIsSearching] = React__default.useState(false);
|
4
5
|
const [query, setQuery] = React__default.useState();
|
5
6
|
const [enableHighlighting, setEnableHighlighting] = React__default.useState(true);
|
6
7
|
const [excludeUnmatchedResults, setExcludeUnmatchedResults] = React__default.useState(excludeUnmatchedResultsInSearch);
|
@@ -19,7 +20,9 @@ function useSearch(isEnabled, excludeUnmatchedResultsInSearch = false, loadAll)
|
|
19
20
|
setHighlightedColumnIndexes,
|
20
21
|
currentHighlightColumnIndex,
|
21
22
|
setCurrentHighlightColumnIndex,
|
22
|
-
loadAll
|
23
|
+
loadAll,
|
24
|
+
isSearching,
|
25
|
+
setIsSearching
|
23
26
|
};
|
24
27
|
}
|
25
28
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useSearch.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useSearch.ts"],"sourcesContent":["import React from 'react';\nimport { Table3LoadAllHandler } from '../../types';\n\nexport function useSearch(isEnabled: boolean, excludeUnmatchedResultsInSearch = false, loadAll?: Table3LoadAllHandler) {\n const [query, setQuery] = React.useState<string | undefined>();\n const [enableHighlighting, setEnableHighlighting] = React.useState<boolean>(true);\n const [excludeUnmatchedResults, setExcludeUnmatchedResults] = React.useState<boolean>(excludeUnmatchedResultsInSearch);\n\n // highlighting\n const [highlightedColumnIndexes, setHighlightedColumnIndexes] = React.useState<number[][]>([]);\n const [currentHighlightColumnIndex, setCurrentHighlightColumnIndex] = React.useState<number | undefined>(undefined);\n\n return {\n isEnabled,\n isHighlightingEnabled: enableHighlighting,\n toggleHighlighting: setEnableHighlighting,\n excludeUnmatchedResults,\n toggleExcludeUnmatchedResults: setExcludeUnmatchedResults,\n query,\n setQuery: isEnabled ? setQuery : () => undefined,\n highlightedColumnIndexes,\n setHighlightedColumnIndexes,\n currentHighlightColumnIndex,\n setCurrentHighlightColumnIndex,\n loadAll,\n };\n}\n"],"names":["useSearch","isEnabled","excludeUnmatchedResultsInSearch","loadAll","
|
1
|
+
{"version":3,"file":"useSearch.js","sources":["../../../../../../../../../src/components/Table3/hooks/features/useSearch.ts"],"sourcesContent":["import React from 'react';\nimport { Table3LoadAllHandler } from '../../types';\n\nexport function useSearch(isEnabled: boolean, excludeUnmatchedResultsInSearch = false, loadAll?: Table3LoadAllHandler) {\n const [isSearching, setIsSearching] = React.useState(false);\n const [query, setQuery] = React.useState<string | undefined>();\n const [enableHighlighting, setEnableHighlighting] = React.useState<boolean>(true);\n const [excludeUnmatchedResults, setExcludeUnmatchedResults] = React.useState<boolean>(excludeUnmatchedResultsInSearch);\n\n // highlighting\n const [highlightedColumnIndexes, setHighlightedColumnIndexes] = React.useState<number[][]>([]);\n const [currentHighlightColumnIndex, setCurrentHighlightColumnIndex] = React.useState<number | undefined>(undefined);\n\n return {\n isEnabled,\n isHighlightingEnabled: enableHighlighting,\n toggleHighlighting: setEnableHighlighting,\n excludeUnmatchedResults,\n toggleExcludeUnmatchedResults: setExcludeUnmatchedResults,\n query,\n setQuery: isEnabled ? setQuery : () => undefined,\n highlightedColumnIndexes,\n setHighlightedColumnIndexes,\n currentHighlightColumnIndex,\n setCurrentHighlightColumnIndex,\n loadAll,\n isSearching,\n setIsSearching,\n };\n}\n"],"names":["useSearch","isEnabled","excludeUnmatchedResultsInSearch","loadAll","isSearching","setIsSearching","React","useState","query","setQuery","enableHighlighting","setEnableHighlighting","excludeUnmatchedResults","setExcludeUnmatchedResults","highlightedColumnIndexes","setHighlightedColumnIndexes","currentHighlightColumnIndex","setCurrentHighlightColumnIndex","undefined","isHighlightingEnabled","toggleHighlighting","toggleExcludeUnmatchedResults"],"mappings":";;SAGgBA,SAASA,CAACC,SAAkB,EAAEC,+BAA+B,GAAG,KAAK,EAAEC,OAA8B;EACjH,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EAC3D,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGH,cAAK,CAACC,QAAQ,EAAsB;EAC9D,MAAM,CAACG,kBAAkB,EAAEC,qBAAqB,CAAC,GAAGL,cAAK,CAACC,QAAQ,CAAU,IAAI,CAAC;EACjF,MAAM,CAACK,uBAAuB,EAAEC,0BAA0B,CAAC,GAAGP,cAAK,CAACC,QAAQ,CAAUL,+BAA+B,CAAC;;EAGtH,MAAM,CAACY,wBAAwB,EAAEC,2BAA2B,CAAC,GAAGT,cAAK,CAACC,QAAQ,CAAa,EAAE,CAAC;EAC9F,MAAM,CAACS,2BAA2B,EAAEC,8BAA8B,CAAC,GAAGX,cAAK,CAACC,QAAQ,CAAqBW,SAAS,CAAC;EAEnH,OAAO;IACHjB,SAAS;IACTkB,qBAAqB,EAAET,kBAAkB;IACzCU,kBAAkB,EAAET,qBAAqB;IACzCC,uBAAuB;IACvBS,6BAA6B,EAAER,0BAA0B;IACzDL,KAAK;IACLC,QAAQ,EAAER,SAAS,GAAGQ,QAAQ,GAAG,MAAMS,SAAS;IAChDJ,wBAAwB;IACxBC,2BAA2B;IAC3BC,2BAA2B;IAC3BC,8BAA8B;IAC9Bd,OAAO;IACPC,WAAW;IACXC;GACH;AACL;;;;"}
|