@carbon/ibm-products 1.8.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- package/css/index-full-carbon.css +270 -5656
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +6 -6
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +58 -3432
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +3 -3
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +238 -3922
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +6 -6
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +238 -3923
- package/css/index.css.map +1 -1
- package/css/index.min.css +6 -6
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +147 -53
- package/es/components/AddSelect/AddSelectBreadcrumbs.js +4 -4
- package/es/components/AddSelect/AddSelectColumn.js +195 -0
- package/es/components/AddSelect/AddSelectList.js +67 -8
- package/es/components/AddSelect/AddSelectSidebar.js +8 -15
- package/es/components/AddSelect/add-select-utils.js +64 -0
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
- package/es/components/ButtonMenu/ButtonMenu.js +1 -1
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +505 -167
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +244 -17
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +74 -8
- package/es/components/DataSpreadsheet/hooks/useMoveActiveCell.js +27 -0
- package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +28 -0
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +41 -0
- package/es/components/DataSpreadsheet/utils/checkActiveHeaderCell.js +34 -0
- package/es/components/DataSpreadsheet/utils/createActiveCellFn.js +58 -0
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +49 -0
- package/es/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
- package/es/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +46 -0
- package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +82 -0
- package/es/components/DataSpreadsheet/utils/removeCellSelections.js +30 -0
- package/es/components/InlineEdit/InlineEdit.js +80 -39
- package/es/components/OptionsTile/OptionsTile.js +31 -21
- package/es/components/OptionsTile/index.js +1 -1
- package/es/components/PageHeader/PageHeader.js +26 -15
- package/es/components/PageHeader/PageHeaderTitle.js +2 -1
- package/es/components/PageHeader/PageHeaderUtils.js +24 -29
- package/es/components/TagSet/TagSet.js +12 -3
- package/es/components/UserProfileImage/UserProfileImage.js +2 -1
- package/es/global/js/utils/DisplayBox.js +31 -0
- package/es/global/js/utils/deepCloneObject.js +26 -0
- package/lib/components/AddSelect/AddSelect.js +150 -54
- package/lib/components/AddSelect/AddSelectBreadcrumbs.js +2 -3
- package/lib/components/AddSelect/AddSelectColumn.js +219 -0
- package/lib/components/AddSelect/AddSelectList.js +65 -8
- package/lib/components/AddSelect/AddSelectSidebar.js +14 -15
- package/lib/components/AddSelect/add-select-utils.js +78 -0
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
- package/lib/components/ButtonMenu/ButtonMenu.js +1 -1
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +514 -170
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +251 -18
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +82 -9
- package/lib/components/DataSpreadsheet/hooks/useMoveActiveCell.js +37 -0
- package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +39 -0
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +52 -0
- package/lib/components/DataSpreadsheet/utils/checkActiveHeaderCell.js +45 -0
- package/lib/components/DataSpreadsheet/{createActiveCellFn.js → utils/createActiveCellFn.js} +22 -9
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +60 -0
- package/lib/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
- package/lib/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +59 -0
- package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +92 -0
- package/lib/components/DataSpreadsheet/utils/removeCellSelections.js +41 -0
- package/lib/components/InlineEdit/InlineEdit.js +82 -40
- package/lib/components/OptionsTile/OptionsTile.js +30 -20
- package/lib/components/PageHeader/PageHeader.js +25 -15
- package/lib/components/PageHeader/PageHeaderTitle.js +2 -1
- package/lib/components/PageHeader/PageHeaderUtils.js +24 -29
- package/lib/components/TagSet/TagSet.js +13 -3
- package/lib/components/UserProfileImage/UserProfileImage.js +2 -1
- package/lib/global/js/utils/DisplayBox.js +46 -0
- package/lib/global/js/utils/deepCloneObject.js +37 -0
- package/package.json +17 -17
- package/scss/components/ActionBar/_storybook-styles.scss +8 -0
- package/scss/components/ActionSet/_storybook-styles.scss +1 -3
- package/scss/components/AddSelect/_add-select.scss +99 -14
- package/scss/components/BreadcrumbWithOverflow/_breadcrumb-with-overflow.scss +7 -3
- package/scss/components/BreadcrumbWithOverflow/_storybook-styles.scss +8 -0
- package/scss/components/ButtonSetWithOverflow/_storybook-styles.scss +8 -0
- package/scss/components/CreateInfluencer/_create-influencer.scss +2 -0
- package/scss/components/CreateModal/_create-modal.scss +1 -0
- package/scss/components/CreateSidePanel/_create-side-panel.scss +1 -1
- package/scss/components/CreateSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
- package/scss/components/CreateTearsheetNarrow/_create-tearsheet-narrow.scss +1 -0
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +42 -6
- package/scss/components/EditSidePanel/_edit-side-panel.scss +9 -0
- package/scss/components/EditSidePanel/_storybook-styles.scss +1 -1
- package/scss/components/InlineEdit/_inline-edit.scss +53 -43
- package/scss/components/InlineEdit/_storybook-styles.scss +2 -0
- package/scss/components/LoadingBar/_loading-bar.scss +13 -0
- package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -0
- package/scss/components/OptionsTile/_index.scss +1 -1
- package/scss/components/OptionsTile/_options-tile.scss +17 -17
- package/scss/components/OptionsTile/_storybook-styles.scss +4 -4
- package/scss/components/PageHeader/_page-header.scss +5 -2
- package/scss/components/SidePanel/_side-panel.scss +19 -12
- package/scss/components/StatusIcon/_status-icon.scss +1 -0
- package/scss/components/TagSet/_storybook-styles.scss +8 -0
- package/scss/components/Tearsheet/_tearsheet.scss +1 -2
- package/scss/components/UserProfileImage/_user-profile-image.scss +9 -0
- package/scss/components/WebTerminal/_web-terminal.scss +2 -0
- package/scss/global/styles/_display-box.scss +62 -0
- package/es/components/DataSpreadsheet/createActiveCellFn.js +0 -45
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
4
|
|
5
|
-
var
|
5
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
6
6
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
@@ -11,6 +11,10 @@ exports.DataSpreadsheet = void 0;
|
|
11
11
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13
13
|
|
14
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
15
|
+
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
17
|
+
|
14
18
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
15
19
|
|
16
20
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
@@ -25,27 +29,43 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
25
29
|
|
26
30
|
var _classnames = _interopRequireDefault(require("classnames"));
|
27
31
|
|
28
|
-
var
|
32
|
+
var _carbonComponentsReact = require("carbon-components-react");
|
29
33
|
|
30
34
|
var _settings = require("../../settings");
|
31
35
|
|
32
|
-
var _getScrollbarWidth = require("../../global/js/utils/getScrollbarWidth");
|
33
|
-
|
34
36
|
var _DataSpreadsheetBody = require("./DataSpreadsheetBody");
|
35
37
|
|
36
|
-
var _getCellSize = require("./getCellSize");
|
37
|
-
|
38
38
|
var _DataSpreadsheetHeader = require("./DataSpreadsheetHeader");
|
39
39
|
|
40
|
+
var _devtools = require("../../global/js/utils/devtools");
|
41
|
+
|
42
|
+
var _getScrollbarWidth = require("../../global/js/utils/getScrollbarWidth");
|
43
|
+
|
40
44
|
var _hooks = require("../../global/js/hooks");
|
41
45
|
|
42
|
-
var
|
46
|
+
var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
|
43
47
|
|
44
|
-
var
|
48
|
+
var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
|
49
|
+
|
50
|
+
var _useResetSpreadsheetFocus = require("./hooks/useResetSpreadsheetFocus");
|
51
|
+
|
52
|
+
var _useSpreadsheetOutsideClick = require("./hooks/useSpreadsheetOutsideClick");
|
53
|
+
|
54
|
+
var _useMoveActiveCell = require("./hooks/useMoveActiveCell");
|
55
|
+
|
56
|
+
var _createActiveCellFn = require("./utils/createActiveCellFn");
|
57
|
+
|
58
|
+
var _getCellSize = require("./utils/getCellSize");
|
59
|
+
|
60
|
+
var _handleMultipleKeys = require("./utils/handleMultipleKeys");
|
61
|
+
|
62
|
+
var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
|
63
|
+
|
64
|
+
var _excluded = ["cellSize", "className", "columns", "data", "onDataUpdate", "id", "onActiveCellChange"];
|
45
65
|
|
46
66
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
47
67
|
|
48
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
68
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
49
69
|
|
50
70
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
51
71
|
|
@@ -59,7 +79,8 @@ var componentName = 'DataSpreadsheet'; // Default values for props
|
|
59
79
|
var defaults = {
|
60
80
|
cellSize: 'standard',
|
61
81
|
columns: Object.freeze([]),
|
62
|
-
data: Object.freeze([])
|
82
|
+
data: Object.freeze([]),
|
83
|
+
onDataUpdate: Object.freeze(function () {})
|
63
84
|
};
|
64
85
|
/**
|
65
86
|
* DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
|
@@ -73,9 +94,13 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
73
94
|
columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
|
74
95
|
_ref$data = _ref.data,
|
75
96
|
data = _ref$data === void 0 ? defaults.data : _ref$data,
|
97
|
+
_ref$onDataUpdate = _ref.onDataUpdate,
|
98
|
+
onDataUpdate = _ref$onDataUpdate === void 0 ? defaults.onDataUpdate : _ref$onDataUpdate,
|
76
99
|
id = _ref.id,
|
77
100
|
onActiveCellChange = _ref.onActiveCellChange,
|
78
101
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
102
|
+
var localRef = (0, _react.useRef)();
|
103
|
+
var spreadsheetRef = ref || localRef;
|
79
104
|
var focusedElement = (0, _hooks.useActiveElement)();
|
80
105
|
|
81
106
|
var _useState = (0, _react.useState)(false),
|
@@ -88,7 +113,39 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
88
113
|
activeCellCoordinates = _useState4[0],
|
89
114
|
setActiveCellCoordinates = _useState4[1];
|
90
115
|
|
116
|
+
var _useState5 = (0, _react.useState)([]),
|
117
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
118
|
+
selectionAreas = _useState6[0],
|
119
|
+
setSelectionAreas = _useState6[1];
|
120
|
+
|
121
|
+
var _useState7 = (0, _react.useState)(false),
|
122
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
123
|
+
clickAndHoldActive = _useState8[0],
|
124
|
+
setClickAndHoldActive = _useState8[1];
|
125
|
+
|
126
|
+
var _useState9 = (0, _react.useState)(''),
|
127
|
+
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
128
|
+
currentMatcher = _useState10[0],
|
129
|
+
setCurrentMatcher = _useState10[1];
|
130
|
+
|
131
|
+
var _useState11 = (0, _react.useState)(false),
|
132
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
133
|
+
isEditing = _useState12[0],
|
134
|
+
setIsEditing = _useState12[1];
|
135
|
+
|
136
|
+
var _useState13 = (0, _react.useState)(''),
|
137
|
+
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
138
|
+
cellEditorValue = _useState14[0],
|
139
|
+
setCellEditorValue = _useState14[1];
|
140
|
+
|
141
|
+
var previousState = (0, _hooks.usePreviousValue)({
|
142
|
+
activeCellCoordinates: activeCellCoordinates
|
143
|
+
});
|
91
144
|
var cellSizeValue = (0, _getCellSize.getCellSize)(cellSize);
|
145
|
+
var cellEditorRef = (0, _react.useRef)();
|
146
|
+
var currentMatcherRef = (0, _react.useRef)();
|
147
|
+
var activeKeys = (0, _react.useRef)([]);
|
148
|
+
var activeCellRef = (0, _react.useRef)();
|
92
149
|
var defaultColumn = (0, _react.useMemo)(function () {
|
93
150
|
return {
|
94
151
|
width: 150,
|
@@ -110,44 +167,62 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
110
167
|
headerGroups = _useTable.headerGroups,
|
111
168
|
rows = _useTable.rows,
|
112
169
|
totalColumnsWidth = _useTable.totalColumnsWidth,
|
113
|
-
prepareRow = _useTable.prepareRow; //
|
170
|
+
prepareRow = _useTable.prepareRow; // Update the spreadsheet data after editing a cell
|
114
171
|
|
115
172
|
|
116
|
-
(0, _react.
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
173
|
+
var updateData = (0, _react.useCallback)(function (rowIndex, columnId) {
|
174
|
+
onDataUpdate(function (prev) {
|
175
|
+
return prev.map(function (row, index) {
|
176
|
+
if (index === rowIndex) {
|
177
|
+
return _objectSpread(_objectSpread({}, prev[rowIndex]), {}, (0, _defineProperty2.default)({}, columnId, cellEditorValue));
|
178
|
+
}
|
121
179
|
|
122
|
-
|
123
|
-
|
124
|
-
}
|
125
|
-
}, [
|
180
|
+
return row;
|
181
|
+
});
|
182
|
+
});
|
183
|
+
}, [cellEditorValue, onDataUpdate]); // Removes the active cell element
|
126
184
|
|
127
185
|
var removeActiveCell = (0, _react.useCallback)(function () {
|
128
186
|
var activeCellHighlight = spreadsheetRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
|
129
187
|
|
130
188
|
if (activeCellHighlight) {
|
131
|
-
activeCellHighlight.
|
189
|
+
activeCellHighlight.style.display = 'none';
|
132
190
|
}
|
133
|
-
}, [spreadsheetRef]);
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
191
|
+
}, [spreadsheetRef]);
|
192
|
+
var removeCellEditor = (0, _react.useCallback)(function () {
|
193
|
+
setCellEditorValue('');
|
194
|
+
setIsEditing(false);
|
195
|
+
cellEditorRef.current.style.display = 'none';
|
196
|
+
}, []); // Removes the cell selection elements
|
197
|
+
|
198
|
+
var removeCellSelections = (0, _react.useCallback)(function (matcher) {
|
199
|
+
if (matcher && typeof matcher === 'string') {
|
200
|
+
var selectionToRemove = spreadsheetRef.current.querySelector("[data-matcher-id=\"".concat(matcher, "\"]"));
|
201
|
+
|
202
|
+
if (selectionToRemove) {
|
203
|
+
selectionToRemove.remove();
|
139
204
|
}
|
205
|
+
} else {
|
206
|
+
var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
|
207
|
+
(0, _toConsumableArray2.default)(cellSelections).forEach(function (element) {
|
208
|
+
return element.remove();
|
209
|
+
});
|
210
|
+
}
|
211
|
+
}, [spreadsheetRef]); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
|
212
|
+
// happen if you click on another cell while isEditing is true
|
140
213
|
|
141
|
-
|
142
|
-
|
143
|
-
setActiveCellCoordinates(null);
|
144
|
-
};
|
214
|
+
(0, _react.useEffect)(function () {
|
215
|
+
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
|
145
216
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
217
|
+
if (((prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) || (prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column)) && isEditing) {
|
218
|
+
var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
|
219
|
+
removeCellEditor();
|
220
|
+
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
221
|
+
}
|
222
|
+
}, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor]);
|
223
|
+
var handleActiveCellMouseEnter = (0, _react.useCallback)(function () {
|
224
|
+
handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
|
225
|
+
}, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]);
|
151
226
|
var createActiveCell = (0, _react.useCallback)(function (_ref2) {
|
152
227
|
var placementElement = _ref2.placementElement,
|
153
228
|
coords = _ref2.coords,
|
@@ -155,16 +230,45 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
155
230
|
addToHeader = _ref2$addToHeader === void 0 ? false : _ref2$addToHeader;
|
156
231
|
var activeCellFullData = typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' && typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number' ? rows[coords === null || coords === void 0 ? void 0 : coords.row].cells[coords === null || coords === void 0 ? void 0 : coords.column] : null;
|
157
232
|
var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[coords === null || coords === void 0 ? void 0 : coords.column] : null;
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
233
|
+
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates; // Only create an active cell if the activeCellCoordinates have changed
|
234
|
+
|
235
|
+
if ((prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row) !== (coords === null || coords === void 0 ? void 0 : coords.row) || (prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column) !== (coords === null || coords === void 0 ? void 0 : coords.column)) {
|
236
|
+
(0, _createActiveCellFn.createActiveCellFn)({
|
237
|
+
placementElement: placementElement,
|
238
|
+
coords: coords,
|
239
|
+
addToHeader: addToHeader,
|
240
|
+
contextRef: spreadsheetRef,
|
241
|
+
blockClass: blockClass,
|
242
|
+
onActiveCellChange: onActiveCellChange,
|
243
|
+
activeCellValue: activeCellValue,
|
244
|
+
activeCellRef: activeCellRef,
|
245
|
+
cellEditorRef: cellEditorRef,
|
246
|
+
defaultColumn: defaultColumn
|
247
|
+
});
|
248
|
+
}
|
249
|
+
}, [spreadsheetRef, rows, onActiveCellChange, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, defaultColumn]);
|
250
|
+
(0, _useResetSpreadsheetFocus.useResetSpreadsheetFocus)({
|
251
|
+
activeKeys: activeKeys,
|
252
|
+
focusedElement: focusedElement,
|
253
|
+
removeActiveCell: removeActiveCell,
|
254
|
+
setContainerHasFocus: setContainerHasFocus
|
255
|
+
});
|
256
|
+
(0, _useSpreadsheetOutsideClick.useSpreadsheetOutsideClick)({
|
257
|
+
spreadsheetRef: spreadsheetRef,
|
258
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
259
|
+
setSelectionAreas: setSelectionAreas,
|
260
|
+
removeActiveCell: removeActiveCell,
|
261
|
+
removeCellSelections: removeCellSelections,
|
262
|
+
setContainerHasFocus: setContainerHasFocus,
|
263
|
+
activeKeys: activeKeys,
|
264
|
+
removeCellEditor: removeCellEditor
|
265
|
+
});
|
266
|
+
(0, _useMoveActiveCell.useMoveActiveCell)({
|
267
|
+
spreadsheetRef: spreadsheetRef,
|
268
|
+
activeCellCoordinates: activeCellCoordinates,
|
269
|
+
containerHasFocus: containerHasFocus,
|
270
|
+
createActiveCell: createActiveCell
|
271
|
+
});
|
168
272
|
var handleInitialArrowPress = (0, _react.useCallback)(function () {
|
169
273
|
// If activeCellCoordinates is null then we need to set an initial value
|
170
274
|
// which will place the activeCell on the select all cell/button
|
@@ -177,189 +281,388 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
177
281
|
|
178
282
|
return;
|
179
283
|
}, [activeCellCoordinates]);
|
180
|
-
|
181
|
-
var updateActiveCellCoordinates = function updateActiveCellCoordinates(_ref3) {
|
284
|
+
var updateActiveCellCoordinates = (0, _react.useCallback)(function (_ref3) {
|
182
285
|
var coords = _ref3.coords,
|
183
286
|
updatedValue = _ref3.updatedValue;
|
184
|
-
setActiveCellCoordinates(_objectSpread(_objectSpread({}, coords), updatedValue));
|
185
|
-
};
|
186
287
|
|
288
|
+
var newActiveCell = _objectSpread(_objectSpread({}, coords), updatedValue);
|
289
|
+
|
290
|
+
setActiveCellCoordinates(newActiveCell); // Only run if the active cell is _not_ a header cell. This will add a point1 object
|
291
|
+
// to selectionAreas every time the active cell changes, allowing us to create cell
|
292
|
+
// selections using keyboard
|
293
|
+
|
294
|
+
if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header') {
|
295
|
+
var tempMatcher = (0, _uuidv.default)();
|
296
|
+
setSelectionAreas([{
|
297
|
+
point1: newActiveCell,
|
298
|
+
matcher: tempMatcher
|
299
|
+
}]);
|
300
|
+
setCurrentMatcher(tempMatcher);
|
301
|
+
}
|
302
|
+
}, []);
|
187
303
|
var handleKeyPress = (0, _react.useCallback)(function (event) {
|
188
|
-
var
|
304
|
+
var _activeKeys$current, _activeKeys$current2;
|
305
|
+
|
306
|
+
var key = event.key; // Command keys need to be returned as there is default browser behavior with these keys
|
189
307
|
|
190
|
-
if (
|
308
|
+
if (key === 'Meta' || key === 'Control') {
|
191
309
|
return;
|
192
310
|
} // Prevent arrow keys, home key, and end key from scrolling the page when the data spreadsheet container has focus
|
193
311
|
|
194
312
|
|
195
|
-
if ([
|
313
|
+
if (['End', 'Home', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1 && !isEditing) {
|
196
314
|
event.preventDefault();
|
197
315
|
}
|
198
316
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
317
|
+
if (['Tab'].indexOf(key) > -1 && isEditing) {
|
318
|
+
return;
|
319
|
+
} // Clear out all cell selection areas if user uses any arrow key, except if the shift key is being held
|
320
|
+
|
321
|
+
|
322
|
+
if (['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1) {
|
323
|
+
if (isEditing) {
|
324
|
+
return;
|
325
|
+
}
|
326
|
+
|
327
|
+
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
|
328
|
+
setSelectionAreas([]);
|
329
|
+
removeCellSelections({
|
330
|
+
spreadsheetRef: spreadsheetRef
|
331
|
+
});
|
332
|
+
}
|
333
|
+
} // Update list of activeKeys
|
209
334
|
|
210
|
-
case 37:
|
211
|
-
{
|
212
|
-
handleInitialArrowPress();
|
213
335
|
|
214
|
-
|
336
|
+
if (!((_activeKeys$current = activeKeys.current) !== null && _activeKeys$current !== void 0 && _activeKeys$current.includes(key))) {
|
337
|
+
var activeClone = (0, _toConsumableArray2.default)(activeKeys.current);
|
338
|
+
activeKeys.current = [].concat((0, _toConsumableArray2.default)(activeClone), [key]);
|
339
|
+
}
|
215
340
|
|
216
|
-
|
217
|
-
|
341
|
+
if (((_activeKeys$current2 = activeKeys.current) === null || _activeKeys$current2 === void 0 ? void 0 : _activeKeys$current2.length) > 1) {
|
342
|
+
(0, _handleMultipleKeys.handleMultipleKeys)({
|
343
|
+
activeKeys: activeKeys,
|
344
|
+
selectionAreas: selectionAreas,
|
345
|
+
currentMatcher: currentMatcher,
|
346
|
+
rows: rows,
|
347
|
+
setSelectionAreas: setSelectionAreas,
|
348
|
+
columns: columns
|
349
|
+
});
|
350
|
+
} // Allow arrow key navigation if there are less than two activeKeys OR
|
351
|
+
// if one of the activeCellCoordinates is in a header position
|
352
|
+
|
353
|
+
|
354
|
+
if (!activeKeys.current.includes('Shift') || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
|
355
|
+
switch (key) {
|
356
|
+
// Tab
|
357
|
+
case 'Tab':
|
358
|
+
{
|
359
|
+
setSelectionAreas([]);
|
360
|
+
removeActiveCell();
|
361
|
+
removeCellEditor();
|
362
|
+
setContainerHasFocus(false);
|
363
|
+
setActiveCellCoordinates(null);
|
364
|
+
break;
|
218
365
|
}
|
366
|
+
// Left
|
367
|
+
|
368
|
+
case 'ArrowLeft':
|
369
|
+
{
|
370
|
+
handleInitialArrowPress();
|
371
|
+
|
372
|
+
var coordinatesClone = _objectSpread({}, activeCellCoordinates);
|
373
|
+
|
374
|
+
if (coordinatesClone.column === 'header') {
|
375
|
+
return;
|
376
|
+
}
|
377
|
+
|
378
|
+
if (typeof coordinatesClone.column === 'number') {
|
379
|
+
if (coordinatesClone.column === 0) {
|
380
|
+
updateActiveCellCoordinates({
|
381
|
+
coords: coordinatesClone,
|
382
|
+
updatedValue: {
|
383
|
+
column: 'header'
|
384
|
+
}
|
385
|
+
});
|
386
|
+
return;
|
387
|
+
}
|
219
388
|
|
220
|
-
if (typeof coordinatesClone.column === 'number') {
|
221
|
-
if (coordinatesClone.column === 0) {
|
222
389
|
updateActiveCellCoordinates({
|
223
390
|
coords: coordinatesClone,
|
224
391
|
updatedValue: {
|
225
|
-
column:
|
392
|
+
column: coordinatesClone.column - 1
|
226
393
|
}
|
227
394
|
});
|
228
|
-
return;
|
229
395
|
}
|
230
396
|
|
231
|
-
|
232
|
-
coords: coordinatesClone,
|
233
|
-
updatedValue: {
|
234
|
-
column: coordinatesClone.column - 1
|
235
|
-
}
|
236
|
-
});
|
397
|
+
break;
|
237
398
|
}
|
399
|
+
// Up
|
238
400
|
|
239
|
-
|
240
|
-
|
241
|
-
|
401
|
+
case 'ArrowUp':
|
402
|
+
{
|
403
|
+
handleInitialArrowPress();
|
242
404
|
|
243
|
-
|
244
|
-
{
|
245
|
-
handleInitialArrowPress();
|
405
|
+
var _coordinatesClone = _objectSpread({}, activeCellCoordinates);
|
246
406
|
|
247
|
-
|
407
|
+
if (_coordinatesClone.row === 'header') {
|
408
|
+
return;
|
409
|
+
}
|
410
|
+
|
411
|
+
if (typeof _coordinatesClone.row === 'number') {
|
412
|
+
// set row back to header if we are at index 0
|
413
|
+
if (_coordinatesClone.row === 0) {
|
414
|
+
updateActiveCellCoordinates({
|
415
|
+
coords: _coordinatesClone,
|
416
|
+
updatedValue: {
|
417
|
+
row: 'header'
|
418
|
+
}
|
419
|
+
});
|
420
|
+
return;
|
421
|
+
} // if we are at any other index than 0, subtract 1 from current row index
|
248
422
|
|
249
|
-
if (_coordinatesClone.row === 'header') {
|
250
|
-
return;
|
251
|
-
}
|
252
423
|
|
253
|
-
if (typeof _coordinatesClone.row === 'number') {
|
254
|
-
// set row back to header if we are at index 0
|
255
|
-
if (_coordinatesClone.row === 0) {
|
256
424
|
updateActiveCellCoordinates({
|
257
425
|
coords: _coordinatesClone,
|
258
426
|
updatedValue: {
|
259
|
-
row:
|
427
|
+
row: _coordinatesClone.row - 1
|
260
428
|
}
|
261
429
|
});
|
262
|
-
|
263
|
-
} // if we are at any other index than 0, subtract 1 from current row index
|
264
|
-
|
430
|
+
}
|
265
431
|
|
266
|
-
|
267
|
-
coords: _coordinatesClone,
|
268
|
-
updatedValue: {
|
269
|
-
row: _coordinatesClone.row - 1
|
270
|
-
}
|
271
|
-
});
|
432
|
+
break;
|
272
433
|
}
|
434
|
+
// Right
|
273
435
|
|
274
|
-
|
275
|
-
|
276
|
-
|
436
|
+
case 'ArrowRight':
|
437
|
+
{
|
438
|
+
handleInitialArrowPress();
|
277
439
|
|
278
|
-
|
279
|
-
{
|
280
|
-
handleInitialArrowPress();
|
440
|
+
var _coordinatesClone2 = _objectSpread({}, activeCellCoordinates);
|
281
441
|
|
282
|
-
|
442
|
+
if (_coordinatesClone2.column === 'header') {
|
443
|
+
updateActiveCellCoordinates({
|
444
|
+
coords: _coordinatesClone2,
|
445
|
+
updatedValue: {
|
446
|
+
column: 0
|
447
|
+
}
|
448
|
+
});
|
449
|
+
}
|
283
450
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
451
|
+
if (typeof _coordinatesClone2.column === 'number') {
|
452
|
+
// Prevent active cell coordinates from updating if the active
|
453
|
+
// cell is in the last column, ie we can't go any further to the right
|
454
|
+
if (columns.length - 1 === _coordinatesClone2.column) {
|
455
|
+
return;
|
289
456
|
}
|
290
|
-
});
|
291
|
-
}
|
292
457
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
458
|
+
updateActiveCellCoordinates({
|
459
|
+
coords: _coordinatesClone2,
|
460
|
+
updatedValue: {
|
461
|
+
column: _coordinatesClone2.column + 1
|
462
|
+
}
|
463
|
+
});
|
298
464
|
}
|
299
465
|
|
300
|
-
|
301
|
-
coords: _coordinatesClone2,
|
302
|
-
updatedValue: {
|
303
|
-
column: _coordinatesClone2.column + 1
|
304
|
-
}
|
305
|
-
});
|
466
|
+
break;
|
306
467
|
}
|
468
|
+
// Down
|
307
469
|
|
308
|
-
|
309
|
-
|
310
|
-
|
470
|
+
case 'ArrowDown':
|
471
|
+
{
|
472
|
+
handleInitialArrowPress();
|
311
473
|
|
312
|
-
|
313
|
-
{
|
314
|
-
handleInitialArrowPress();
|
474
|
+
var _coordinatesClone3 = _objectSpread({}, activeCellCoordinates);
|
315
475
|
|
316
|
-
|
476
|
+
if (_coordinatesClone3.row === 'header') {
|
477
|
+
updateActiveCellCoordinates({
|
478
|
+
coords: _coordinatesClone3,
|
479
|
+
updatedValue: {
|
480
|
+
row: 0
|
481
|
+
}
|
482
|
+
});
|
483
|
+
}
|
317
484
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
485
|
+
if (typeof _coordinatesClone3.row === 'number') {
|
486
|
+
// Prevent active cell coordinates from updating if the active
|
487
|
+
// cell is in the last row, ie we can't go any further down since
|
488
|
+
// we are in the last row
|
489
|
+
if (rows.length - 1 === _coordinatesClone3.row) {
|
490
|
+
return;
|
323
491
|
}
|
324
|
-
});
|
325
|
-
}
|
326
492
|
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
493
|
+
updateActiveCellCoordinates({
|
494
|
+
coords: _coordinatesClone3,
|
495
|
+
updatedValue: {
|
496
|
+
row: _coordinatesClone3.row + 1
|
497
|
+
}
|
498
|
+
});
|
333
499
|
}
|
334
500
|
|
335
|
-
|
336
|
-
coords: _coordinatesClone3,
|
337
|
-
updatedValue: {
|
338
|
-
row: _coordinatesClone3.row + 1
|
339
|
-
}
|
340
|
-
});
|
501
|
+
break;
|
341
502
|
}
|
503
|
+
}
|
504
|
+
}
|
505
|
+
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, removeCellSelections, selectionAreas]);
|
506
|
+
|
507
|
+
var startEditMode = function startEditMode() {
|
508
|
+
setIsEditing(true);
|
509
|
+
var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
510
|
+
var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
511
|
+
setCellEditorValue(activeCellValue);
|
512
|
+
}; // Go into edit mode if 'Enter' key is pressed on activeCellRef
|
342
513
|
|
343
|
-
|
514
|
+
|
515
|
+
var handleActiveCellKeyDown = function handleActiveCellKeyDown(event) {
|
516
|
+
var key = event.key;
|
517
|
+
|
518
|
+
if (key === 'Enter') {
|
519
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
|
520
|
+
startEditMode();
|
521
|
+
}
|
522
|
+
|
523
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
524
|
+
var handleHeaderCellProps = {
|
525
|
+
activeCellCoordinates: activeCellCoordinates,
|
526
|
+
rows: rows,
|
527
|
+
columns: columns,
|
528
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
529
|
+
setCurrentMatcher: setCurrentMatcher,
|
530
|
+
setSelectionAreas: setSelectionAreas,
|
531
|
+
spreadsheetRef: spreadsheetRef,
|
532
|
+
isKeyboard: true
|
533
|
+
}; // Select an entire column
|
534
|
+
|
535
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
536
|
+
(0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
|
537
|
+
type: 'column'
|
538
|
+
}, handleHeaderCellProps));
|
539
|
+
} // Select an entire row
|
540
|
+
|
541
|
+
|
542
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
543
|
+
(0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
|
544
|
+
type: 'row'
|
545
|
+
}, handleHeaderCellProps));
|
344
546
|
}
|
547
|
+
}
|
345
548
|
}
|
346
|
-
}
|
549
|
+
}; // Go into edit mode if double click is detected on activeCellRef
|
347
550
|
|
551
|
+
|
552
|
+
var handleActiveCellDoubleClick = function handleActiveCellDoubleClick() {
|
553
|
+
startEditMode();
|
554
|
+
}; // Update the data
|
555
|
+
|
556
|
+
|
557
|
+
var handleEditSubmit = function handleEditSubmit(event) {
|
558
|
+
var key = event.key;
|
559
|
+
|
560
|
+
var submitEditChanges = function submitEditChanges() {
|
561
|
+
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
|
562
|
+
var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
|
563
|
+
removeCellEditor();
|
564
|
+
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
565
|
+
};
|
566
|
+
|
567
|
+
if (key === 'Enter') {
|
568
|
+
submitEditChanges();
|
569
|
+
setActiveCellCoordinates(function (prev) {
|
570
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
571
|
+
row: prev.row === rows.length - 1 ? prev.row : prev.row + 1 // do not move to next cell below if we're already in the last row
|
572
|
+
|
573
|
+
});
|
574
|
+
});
|
575
|
+
}
|
576
|
+
|
577
|
+
if (key === 'Tab') {
|
578
|
+
event.preventDefault();
|
579
|
+
submitEditChanges();
|
580
|
+
setActiveCellCoordinates(function (prev) {
|
581
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
582
|
+
column: prev.column === columns.length - 1 ? prev.column : prev.column + 1 // do not move to next cell below if we're already in the last column
|
583
|
+
|
584
|
+
});
|
585
|
+
});
|
586
|
+
}
|
587
|
+
|
588
|
+
return;
|
589
|
+
}; // Only update if there are cell selection areas
|
590
|
+
// Find point object that matches currentMatcher and remove the second point
|
591
|
+
// because hovering over the active cell while clicking and holding should
|
592
|
+
// remove the previously existing selection area
|
593
|
+
|
594
|
+
|
595
|
+
var handleActiveCellMouseEnterCallback = (0, _react.useCallback)(function (areas, clickHold) {
|
596
|
+
var freshMatcherValue = currentMatcherRef.current;
|
597
|
+
|
598
|
+
if (!freshMatcherValue) {
|
599
|
+
return;
|
600
|
+
}
|
601
|
+
|
602
|
+
if (areas && areas.length && clickHold && freshMatcherValue) {
|
603
|
+
setSelectionAreas(function (prev) {
|
604
|
+
var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(prev);
|
605
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
606
|
+
return item.matcher === freshMatcherValue;
|
607
|
+
});
|
608
|
+
|
609
|
+
if (indexOfItemToUpdate === -1) {
|
610
|
+
return prev;
|
611
|
+
}
|
612
|
+
|
613
|
+
if ((0, _typeof2.default)(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
|
614
|
+
selectionAreaClone[indexOfItemToUpdate].point2 = null;
|
615
|
+
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
616
|
+
removeCellSelections({
|
617
|
+
matcher: freshMatcherValue,
|
618
|
+
spreadsheetRef: spreadsheetRef
|
619
|
+
});
|
620
|
+
return selectionAreaClone;
|
621
|
+
}
|
622
|
+
|
623
|
+
return prev;
|
624
|
+
});
|
625
|
+
}
|
626
|
+
}, [spreadsheetRef, removeCellSelections]);
|
348
627
|
(0, _react.useEffect)(function () {
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
628
|
+
if (isEditing) {
|
629
|
+
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
630
|
+
|
631
|
+
var cellProps = (_rows$activeCellCoord = rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row]) === null || _rows$activeCellCoord === void 0 ? void 0 : _rows$activeCellCoord.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column];
|
632
|
+
var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
|
633
|
+
var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
|
634
|
+
cellEditorRef.current.style.left = activeCellLeftPosition;
|
635
|
+
cellEditorRef.current.style.top = activeCellTopPosition;
|
636
|
+
cellEditorRef.current.style.display = 'block';
|
637
|
+
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
638
|
+
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
639
|
+
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
640
|
+
|
641
|
+
cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
|
642
|
+
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
643
|
+
}
|
644
|
+
|
645
|
+
if (!isEditing) {
|
646
|
+
cellEditorRef.current.style.display = 'none';
|
647
|
+
cellEditorRef.current.blur();
|
648
|
+
activeCellRef.current.focus();
|
649
|
+
}
|
650
|
+
}, [isEditing, activeCellCoordinates, rows]);
|
651
|
+
|
652
|
+
var handleKeyUp = function handleKeyUp(event) {
|
653
|
+
var _activeKeys$current3;
|
654
|
+
|
655
|
+
var key = event.key; // Remove key from active keys array on key up
|
656
|
+
|
657
|
+
if ((_activeKeys$current3 = activeKeys.current) !== null && _activeKeys$current3 !== void 0 && _activeKeys$current3.includes(key)) {
|
658
|
+
var activeKeysClone = (0, _toConsumableArray2.default)(activeKeys.current);
|
659
|
+
var filteredKeysClone = activeKeysClone.filter(function (item) {
|
660
|
+
return item !== key;
|
358
661
|
});
|
662
|
+
activeKeys.current = filteredKeysClone;
|
359
663
|
}
|
360
|
-
}
|
361
|
-
|
362
|
-
var spreadsheetRef = ref || localRef;
|
664
|
+
};
|
665
|
+
|
363
666
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, getTableProps(), (0, _devtools.getDevtoolsProps)(componentName), {
|
364
667
|
className: (0, _classnames.default)(blockClass, className, (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
|
365
668
|
ref: spreadsheetRef,
|
@@ -368,14 +671,32 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
368
671
|
"aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
|
369
672
|
"aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
|
370
673
|
onKeyDown: handleKeyPress,
|
674
|
+
onKeyUp: handleKeyUp,
|
371
675
|
onFocus: function onFocus() {
|
372
676
|
return setContainerHasFocus(true);
|
373
677
|
}
|
374
678
|
}), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetHeader.DataSpreadsheetHeader, {
|
679
|
+
ref: spreadsheetRef,
|
680
|
+
activeCellCoordinates: activeCellCoordinates,
|
375
681
|
cellSizeValue: cellSizeValue,
|
682
|
+
columns: columns,
|
376
683
|
defaultColumn: defaultColumn,
|
377
|
-
headerGroups: headerGroups
|
684
|
+
headerGroups: headerGroups,
|
685
|
+
rows: rows,
|
686
|
+
selectionAreas: selectionAreas,
|
687
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
688
|
+
setSelectionAreas: setSelectionAreas,
|
689
|
+
setCurrentMatcher: setCurrentMatcher
|
378
690
|
}), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetBody.DataSpreadsheetBody, {
|
691
|
+
activeCellCoordinates: activeCellCoordinates,
|
692
|
+
ref: spreadsheetRef,
|
693
|
+
clickAndHoldActive: clickAndHoldActive,
|
694
|
+
setClickAndHoldActive: setClickAndHoldActive,
|
695
|
+
currentMatcher: currentMatcher,
|
696
|
+
setCurrentMatcher: setCurrentMatcher,
|
697
|
+
setContainerHasFocus: setContainerHasFocus,
|
698
|
+
selectionAreas: selectionAreas,
|
699
|
+
setSelectionAreas: setSelectionAreas,
|
379
700
|
cellSize: cellSize,
|
380
701
|
defaultColumn: defaultColumn,
|
381
702
|
getTableBodyProps: getTableBodyProps,
|
@@ -385,7 +706,25 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
385
706
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
386
707
|
scrollBarSize: scrollBarSize,
|
387
708
|
totalColumnsWidth: totalColumnsWidth,
|
388
|
-
id: id
|
709
|
+
id: id,
|
710
|
+
columns: columns
|
711
|
+
}), /*#__PURE__*/_react.default.createElement("button", {
|
712
|
+
onKeyDown: handleActiveCellKeyDown,
|
713
|
+
onMouseEnter: handleActiveCellMouseEnter,
|
714
|
+
onDoubleClick: handleActiveCellDoubleClick,
|
715
|
+
ref: activeCellRef,
|
716
|
+
className: (0, _classnames.default)("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
|
717
|
+
type: "button"
|
718
|
+
}), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TextArea, {
|
719
|
+
value: cellEditorValue,
|
720
|
+
onKeyDown: handleEditSubmit,
|
721
|
+
onChange: function onChange(event) {
|
722
|
+
return setCellEditorValue(event.target.value);
|
723
|
+
},
|
724
|
+
ref: cellEditorRef,
|
725
|
+
labelText: "",
|
726
|
+
"aria-labelledby": activeCellCoordinates ? "[data-row-index=\"".concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, "\"][data-column-index=\"").concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column, "\"]") : null,
|
727
|
+
className: (0, _classnames.default)("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), (0, _defineProperty2.default)({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
|
389
728
|
}));
|
390
729
|
}); // Return a placeholder if not released and not enabled by feature flag
|
391
730
|
|
@@ -432,7 +771,12 @@ DataSpreadsheet.propTypes = {
|
|
432
771
|
/**
|
433
772
|
* The event handler that is called when the active cell changes
|
434
773
|
*/
|
435
|
-
onActiveCellChange: _propTypes.default.func
|
774
|
+
onActiveCellChange: _propTypes.default.func,
|
775
|
+
|
776
|
+
/**
|
777
|
+
* The setter fn for the data prop
|
778
|
+
*/
|
779
|
+
onDataUpdate: _propTypes.default.func
|
436
780
|
/* TODO: add types and DocGen for all props. */
|
437
781
|
|
438
782
|
};
|