@carbon/ibm-products 1.9.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. package/css/index-full-carbon.css +364 -5838
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +5 -5
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +68 -3430
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +3 -3
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +185 -4098
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +5 -5
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +302 -4099
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +5 -5
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/AddSelect/AddSelect.js +98 -92
  18. package/es/components/AddSelect/AddSelectColumn.js +219 -8
  19. package/es/components/AddSelect/AddSelectList.js +5 -5
  20. package/es/components/AddSelect/AddSelectSidebar.js +3 -15
  21. package/es/components/AddSelect/add-select-utils.js +64 -0
  22. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
  23. package/es/components/ButtonMenu/ButtonMenu.js +12 -4
  24. package/es/components/DataSpreadsheet/DataSpreadsheet.js +480 -182
  25. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +124 -81
  26. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +74 -8
  27. package/es/components/DataSpreadsheet/hooks/useMoveActiveCell.js +27 -0
  28. package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +28 -0
  29. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +41 -0
  30. package/es/components/DataSpreadsheet/utils/checkActiveHeaderCell.js +34 -0
  31. package/es/components/DataSpreadsheet/{createActiveCellFn.js → utils/createActiveCellFn.js} +21 -8
  32. package/es/components/DataSpreadsheet/{createCellSelectionArea.js → utils/createCellSelectionArea.js} +8 -4
  33. package/es/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
  34. package/es/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
  35. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +46 -0
  36. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +82 -0
  37. package/es/components/DataSpreadsheet/utils/removeCellSelections.js +30 -0
  38. package/es/components/InlineEdit/InlineEdit.js +58 -27
  39. package/es/components/OptionsTile/OptionsTile.js +31 -21
  40. package/es/components/OptionsTile/index.js +1 -1
  41. package/es/components/PageHeader/PageHeader.js +26 -15
  42. package/es/components/PageHeader/PageHeaderTitle.js +2 -1
  43. package/es/components/PageHeader/PageHeaderUtils.js +24 -29
  44. package/es/components/TagSet/TagSet.js +12 -3
  45. package/es/components/UserProfileImage/UserProfileImage.js +2 -1
  46. package/es/components/index.js +0 -1
  47. package/es/global/js/package-settings.js +1 -2
  48. package/lib/components/AddSelect/AddSelect.js +101 -92
  49. package/lib/components/AddSelect/AddSelectColumn.js +232 -13
  50. package/lib/components/AddSelect/AddSelectList.js +5 -5
  51. package/lib/components/AddSelect/AddSelectSidebar.js +9 -15
  52. package/lib/components/AddSelect/add-select-utils.js +78 -0
  53. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -1
  54. package/lib/components/ButtonMenu/ButtonMenu.js +12 -4
  55. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +490 -186
  56. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +127 -82
  57. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +82 -9
  58. package/lib/components/DataSpreadsheet/hooks/useMoveActiveCell.js +37 -0
  59. package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +39 -0
  60. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +52 -0
  61. package/lib/components/DataSpreadsheet/utils/checkActiveHeaderCell.js +45 -0
  62. package/lib/components/DataSpreadsheet/{createActiveCellFn.js → utils/createActiveCellFn.js} +21 -8
  63. package/lib/components/DataSpreadsheet/{createCellSelectionArea.js → utils/createCellSelectionArea.js} +8 -4
  64. package/lib/components/DataSpreadsheet/{generateData.js → utils/generateData.js} +6 -0
  65. package/lib/components/DataSpreadsheet/{getCellSize.js → utils/getCellSize.js} +0 -0
  66. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +59 -0
  67. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +92 -0
  68. package/lib/components/DataSpreadsheet/utils/removeCellSelections.js +41 -0
  69. package/lib/components/InlineEdit/InlineEdit.js +60 -28
  70. package/lib/components/OptionsTile/OptionsTile.js +30 -20
  71. package/lib/components/PageHeader/PageHeader.js +25 -15
  72. package/lib/components/PageHeader/PageHeaderTitle.js +2 -1
  73. package/lib/components/PageHeader/PageHeaderUtils.js +24 -29
  74. package/lib/components/TagSet/TagSet.js +13 -3
  75. package/lib/components/UserProfileImage/UserProfileImage.js +2 -1
  76. package/lib/components/index.js +0 -8
  77. package/lib/global/js/package-settings.js +1 -2
  78. package/package.json +17 -17
  79. package/scss/components/AddSelect/_add-select.scss +47 -14
  80. package/scss/components/BreadcrumbWithOverflow/_breadcrumb-with-overflow.scss +7 -3
  81. package/scss/components/CreateInfluencer/_create-influencer.scss +2 -0
  82. package/scss/components/CreateModal/_create-modal.scss +1 -0
  83. package/scss/components/CreateSidePanel/_create-side-panel.scss +1 -1
  84. package/scss/components/CreateSidePanel/_storybook-styles.scss +1 -1
  85. package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
  86. package/scss/components/CreateTearsheetNarrow/_create-tearsheet-narrow.scss +1 -0
  87. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +25 -7
  88. package/scss/components/EditSidePanel/_edit-side-panel.scss +9 -0
  89. package/scss/components/EditSidePanel/_storybook-styles.scss +1 -1
  90. package/scss/components/InlineEdit/_inline-edit.scss +46 -39
  91. package/scss/components/InlineEdit/_storybook-styles.scss +1 -0
  92. package/scss/components/ModifiedTabs/_modified-tabs.scss +5 -0
  93. package/scss/components/NotificationsPanel/_notifications-panel.scss +10 -3
  94. package/scss/components/OptionsTile/_index.scss +1 -1
  95. package/scss/components/OptionsTile/_options-tile.scss +17 -17
  96. package/scss/components/OptionsTile/_storybook-styles.scss +4 -4
  97. package/scss/components/PageHeader/_page-header.scss +5 -2
  98. package/scss/components/SidePanel/_side-panel.scss +19 -12
  99. package/scss/components/StatusIcon/_status-icon.scss +1 -0
  100. package/scss/components/Tearsheet/_tearsheet.scss +4 -0
  101. package/scss/components/UserProfileImage/_user-profile-image.scss +9 -0
  102. package/scss/components/WebTerminal/_web-terminal.scss +2 -0
  103. package/scss/components/_index.scss +0 -1
  104. package/es/components/LoadingBar/LoadingBar.js +0 -156
  105. package/es/components/LoadingBar/index.js +0 -7
  106. package/lib/components/LoadingBar/LoadingBar.js +0 -170
  107. package/lib/components/LoadingBar/index.js +0 -13
  108. package/scss/components/LoadingBar/_index.scss +0 -8
  109. package/scss/components/LoadingBar/_loading-bar.scss +0 -211
  110. package/scss/components/LoadingBar/_storybook-styles.scss +0 -14
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _typeof = require("@babel/runtime/helpers/typeof");
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 _devtools = require("../../global/js/utils/devtools");
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 _createActiveCellFn = require("./createActiveCellFn");
46
+ var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
47
+
48
+ var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
43
49
 
44
- var _excluded = ["cellSize", "className", "columns", "data", "id", "onActiveCellChange"];
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 || _typeof(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; }
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),
@@ -98,12 +123,29 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
98
123
  clickAndHoldActive = _useState8[0],
99
124
  setClickAndHoldActive = _useState8[1];
100
125
 
101
- var _useState9 = (0, _react.useState)(null),
126
+ var _useState9 = (0, _react.useState)(''),
102
127
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
103
128
  currentMatcher = _useState10[0],
104
129
  setCurrentMatcher = _useState10[1];
105
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
+ });
106
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)();
107
149
  var defaultColumn = (0, _react.useMemo)(function () {
108
150
  return {
109
151
  width: 150,
@@ -125,53 +167,62 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
125
167
  headerGroups = _useTable.headerGroups,
126
168
  rows = _useTable.rows,
127
169
  totalColumnsWidth = _useTable.totalColumnsWidth,
128
- prepareRow = _useTable.prepareRow; // Reset everything when spreadsheet loses focus
170
+ prepareRow = _useTable.prepareRow; // Update the spreadsheet data after editing a cell
129
171
 
130
172
 
131
- (0, _react.useEffect)(function () {
132
- if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
133
- setContainerHasFocus(false);
134
- removeActiveCell();
135
- }
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
+ }
136
179
 
137
- if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
138
- setContainerHasFocus(true);
139
- }
140
- }, [focusedElement, removeActiveCell]); // Removes the active cell element
180
+ return row;
181
+ });
182
+ });
183
+ }, [cellEditorValue, onDataUpdate]); // Removes the active cell element
141
184
 
142
185
  var removeActiveCell = (0, _react.useCallback)(function () {
143
186
  var activeCellHighlight = spreadsheetRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
144
187
 
145
188
  if (activeCellHighlight) {
146
- activeCellHighlight.remove();
189
+ activeCellHighlight.style.display = 'none';
147
190
  }
148
- }, [spreadsheetRef]); // Removes the cell selection elements
149
-
150
- var removeCellSelections = (0, _react.useCallback)(function () {
151
- var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
152
- Array.from(cellSelections).forEach(function (element) {
153
- return element.remove();
154
- });
155
- }, [spreadsheetRef]); // Click outside useEffect
156
-
157
- (0, _react.useEffect)(function () {
158
- var handleOutsideClick = function handleOutsideClick(event) {
159
- if (!spreadsheetRef.current || spreadsheetRef.current.contains(event.target) || event.target.classList.contains("".concat(blockClass, "__active-cell--highlight"))) {
160
- return;
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();
161
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
162
213
 
163
- setSelectionAreas([]);
164
- removeActiveCell();
165
- removeCellSelections();
166
- setContainerHasFocus(false);
167
- setActiveCellCoordinates(null);
168
- };
214
+ (0, _react.useEffect)(function () {
215
+ var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
169
216
 
170
- document.addEventListener('click', handleOutsideClick);
171
- return function () {
172
- document.removeEventListener('click', handleOutsideClick);
173
- };
174
- }, [spreadsheetRef, removeActiveCell, removeCellSelections]);
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]);
175
226
  var createActiveCell = (0, _react.useCallback)(function (_ref2) {
176
227
  var placementElement = _ref2.placementElement,
177
228
  coords = _ref2.coords,
@@ -179,16 +230,45 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
179
230
  addToHeader = _ref2$addToHeader === void 0 ? false : _ref2$addToHeader;
180
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;
181
232
  var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[coords === null || coords === void 0 ? void 0 : coords.column] : null;
182
- (0, _createActiveCellFn.createActiveCellFn)({
183
- placementElement: placementElement,
184
- coords: coords,
185
- addToHeader: addToHeader,
186
- contextRef: spreadsheetRef,
187
- blockClass: blockClass,
188
- onActiveCellChange: onActiveCellChange,
189
- activeCellValue: activeCellValue
190
- });
191
- }, [spreadsheetRef, rows, onActiveCellChange]);
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
+ });
192
272
  var handleInitialArrowPress = (0, _react.useCallback)(function () {
193
273
  // If activeCellCoordinates is null then we need to set an initial value
194
274
  // which will place the activeCell on the select all cell/button
@@ -201,198 +281,388 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
201
281
 
202
282
  return;
203
283
  }, [activeCellCoordinates]);
204
-
205
- var updateActiveCellCoordinates = function updateActiveCellCoordinates(_ref3) {
284
+ var updateActiveCellCoordinates = (0, _react.useCallback)(function (_ref3) {
206
285
  var coords = _ref3.coords,
207
286
  updatedValue = _ref3.updatedValue;
208
- setActiveCellCoordinates(_objectSpread(_objectSpread({}, coords), updatedValue));
209
- };
210
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
+ }, []);
211
303
  var handleKeyPress = (0, _react.useCallback)(function (event) {
212
- var keyCode = event.keyCode; // Command keys need to be returned as there is default browser behavior with these keys
304
+ var _activeKeys$current, _activeKeys$current2;
213
305
 
214
- if (keyCode === 91 || keyCode === 93) {
306
+ var key = event.key; // Command keys need to be returned as there is default browser behavior with these keys
307
+
308
+ if (key === 'Meta' || key === 'Control') {
215
309
  return;
216
310
  } // Prevent arrow keys, home key, and end key from scrolling the page when the data spreadsheet container has focus
217
311
 
218
312
 
219
- if ([35, 36, 37, 38, 39, 40].indexOf(keyCode) > -1) {
313
+ if (['End', 'Home', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1 && !isEditing) {
220
314
  event.preventDefault();
221
- } // Clear out all cell selection areas if user uses any arrow key
315
+ }
316
+
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
+
222
321
 
322
+ if (['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1) {
323
+ if (isEditing) {
324
+ return;
325
+ }
223
326
 
224
- if ([37, 38, 39, 40].indexOf(keyCode) > -1) {
225
- if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length) {
327
+ if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
226
328
  setSelectionAreas([]);
227
- removeCellSelections();
329
+ removeCellSelections({
330
+ spreadsheetRef: spreadsheetRef
331
+ });
228
332
  }
333
+ } // Update list of activeKeys
334
+
335
+
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]);
229
339
  }
230
340
 
231
- switch (keyCode) {
232
- // Tab
233
- case 9:
234
- {
235
- setSelectionAreas([]);
236
- removeActiveCell();
237
- setContainerHasFocus(false);
238
- setActiveCellCoordinates(null);
239
- break;
240
- }
241
- // Left
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;
365
+ }
366
+ // Left
242
367
 
243
- case 37:
244
- {
245
- handleInitialArrowPress();
368
+ case 'ArrowLeft':
369
+ {
370
+ handleInitialArrowPress();
246
371
 
247
- var coordinatesClone = _objectSpread({}, activeCellCoordinates);
372
+ var coordinatesClone = _objectSpread({}, activeCellCoordinates);
248
373
 
249
- if (coordinatesClone.column === 'header') {
250
- return;
251
- }
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
+ }
252
388
 
253
- if (typeof coordinatesClone.column === 'number') {
254
- if (coordinatesClone.column === 0) {
255
389
  updateActiveCellCoordinates({
256
390
  coords: coordinatesClone,
257
391
  updatedValue: {
258
- column: 'header'
392
+ column: coordinatesClone.column - 1
259
393
  }
260
394
  });
261
- return;
262
395
  }
263
396
 
264
- updateActiveCellCoordinates({
265
- coords: coordinatesClone,
266
- updatedValue: {
267
- column: coordinatesClone.column - 1
268
- }
269
- });
397
+ break;
270
398
  }
399
+ // Up
271
400
 
272
- break;
273
- }
274
- // Up
401
+ case 'ArrowUp':
402
+ {
403
+ handleInitialArrowPress();
275
404
 
276
- case 38:
277
- {
278
- handleInitialArrowPress();
405
+ var _coordinatesClone = _objectSpread({}, activeCellCoordinates);
279
406
 
280
- var _coordinatesClone = _objectSpread({}, activeCellCoordinates);
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
281
422
 
282
- if (_coordinatesClone.row === 'header') {
283
- return;
284
- }
285
423
 
286
- if (typeof _coordinatesClone.row === 'number') {
287
- // set row back to header if we are at index 0
288
- if (_coordinatesClone.row === 0) {
289
424
  updateActiveCellCoordinates({
290
425
  coords: _coordinatesClone,
291
426
  updatedValue: {
292
- row: 'header'
427
+ row: _coordinatesClone.row - 1
293
428
  }
294
429
  });
295
- return;
296
- } // if we are at any other index than 0, subtract 1 from current row index
297
-
430
+ }
298
431
 
299
- updateActiveCellCoordinates({
300
- coords: _coordinatesClone,
301
- updatedValue: {
302
- row: _coordinatesClone.row - 1
303
- }
304
- });
432
+ break;
305
433
  }
434
+ // Right
306
435
 
307
- break;
308
- }
309
- // Right
436
+ case 'ArrowRight':
437
+ {
438
+ handleInitialArrowPress();
310
439
 
311
- case 39:
312
- {
313
- handleInitialArrowPress();
440
+ var _coordinatesClone2 = _objectSpread({}, activeCellCoordinates);
314
441
 
315
- var _coordinatesClone2 = _objectSpread({}, activeCellCoordinates);
442
+ if (_coordinatesClone2.column === 'header') {
443
+ updateActiveCellCoordinates({
444
+ coords: _coordinatesClone2,
445
+ updatedValue: {
446
+ column: 0
447
+ }
448
+ });
449
+ }
316
450
 
317
- if (_coordinatesClone2.column === 'header') {
318
- updateActiveCellCoordinates({
319
- coords: _coordinatesClone2,
320
- updatedValue: {
321
- column: 0
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;
322
456
  }
323
- });
324
- }
325
457
 
326
- if (typeof _coordinatesClone2.column === 'number') {
327
- // Prevent active cell coordinates from updating if the active
328
- // cell is in the last column, ie we can't go any further to the right
329
- if (columns.length - 1 === _coordinatesClone2.column) {
330
- return;
458
+ updateActiveCellCoordinates({
459
+ coords: _coordinatesClone2,
460
+ updatedValue: {
461
+ column: _coordinatesClone2.column + 1
462
+ }
463
+ });
331
464
  }
332
465
 
333
- updateActiveCellCoordinates({
334
- coords: _coordinatesClone2,
335
- updatedValue: {
336
- column: _coordinatesClone2.column + 1
337
- }
338
- });
466
+ break;
339
467
  }
468
+ // Down
340
469
 
341
- break;
342
- }
343
- // Down
470
+ case 'ArrowDown':
471
+ {
472
+ handleInitialArrowPress();
344
473
 
345
- case 40:
346
- {
347
- handleInitialArrowPress();
474
+ var _coordinatesClone3 = _objectSpread({}, activeCellCoordinates);
348
475
 
349
- var _coordinatesClone3 = _objectSpread({}, activeCellCoordinates);
476
+ if (_coordinatesClone3.row === 'header') {
477
+ updateActiveCellCoordinates({
478
+ coords: _coordinatesClone3,
479
+ updatedValue: {
480
+ row: 0
481
+ }
482
+ });
483
+ }
350
484
 
351
- if (_coordinatesClone3.row === 'header') {
352
- updateActiveCellCoordinates({
353
- coords: _coordinatesClone3,
354
- updatedValue: {
355
- row: 0
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;
356
491
  }
357
- });
358
- }
359
492
 
360
- if (typeof _coordinatesClone3.row === 'number') {
361
- // Prevent active cell coordinates from updating if the active
362
- // cell is in the last row, ie we can't go any further down since
363
- // we are in the last row
364
- if (rows.length - 1 === _coordinatesClone3.row) {
365
- return;
493
+ updateActiveCellCoordinates({
494
+ coords: _coordinatesClone3,
495
+ updatedValue: {
496
+ row: _coordinatesClone3.row + 1
497
+ }
498
+ });
366
499
  }
367
500
 
368
- updateActiveCellCoordinates({
369
- coords: _coordinatesClone3,
370
- updatedValue: {
371
- row: _coordinatesClone3.row + 1
372
- }
373
- });
501
+ break;
374
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
513
+
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
+ }
375
522
 
376
- break;
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));
377
546
  }
547
+ }
378
548
  }
379
- }, [handleInitialArrowPress, activeCellCoordinates, selectionAreas === null || selectionAreas === void 0 ? void 0 : selectionAreas.length, removeCellSelections, removeActiveCell, columns.length, rows.length]); // Adds active cell highlight to correct cell onKeyDown
549
+ }; // Go into edit mode if double click is detected on activeCellRef
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;
380
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]);
381
627
  (0, _react.useEffect)(function () {
382
- var activeCellPlacementElement = spreadsheetRef === null || spreadsheetRef === void 0 ? void 0 : spreadsheetRef.current.querySelector("[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, "\"]"));
383
- var shouldPlaceActiveCellInHeader = (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && true;
384
- var selectAllElement = spreadsheetRef === null || spreadsheetRef === void 0 ? void 0 : spreadsheetRef.current.querySelector("[data-row-index=\"header\"][data-column-index=\"header\"]");
385
-
386
- if (containerHasFocus) {
387
- createActiveCell({
388
- placementElement: activeCellCoordinates ? activeCellPlacementElement : selectAllElement,
389
- coords: activeCellCoordinates,
390
- addToHeader: shouldPlaceActiveCellInHeader
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;
391
661
  });
662
+ activeKeys.current = filteredKeysClone;
392
663
  }
393
- }, [activeCellCoordinates, spreadsheetRef, createActiveCell, containerHasFocus]);
394
- var localRef = (0, _react.useRef)();
395
- var spreadsheetRef = ref || localRef;
664
+ };
665
+
396
666
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, getTableProps(), (0, _devtools.getDevtoolsProps)(componentName), {
397
667
  className: (0, _classnames.default)(blockClass, className, (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
398
668
  ref: spreadsheetRef,
@@ -401,14 +671,25 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
401
671
  "aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
402
672
  "aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
403
673
  onKeyDown: handleKeyPress,
674
+ onKeyUp: handleKeyUp,
404
675
  onFocus: function onFocus() {
405
676
  return setContainerHasFocus(true);
406
677
  }
407
678
  }), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetHeader.DataSpreadsheetHeader, {
679
+ ref: spreadsheetRef,
680
+ activeCellCoordinates: activeCellCoordinates,
408
681
  cellSizeValue: cellSizeValue,
682
+ columns: columns,
409
683
  defaultColumn: defaultColumn,
410
- headerGroups: headerGroups
684
+ headerGroups: headerGroups,
685
+ rows: rows,
686
+ selectionAreas: selectionAreas,
687
+ setActiveCellCoordinates: setActiveCellCoordinates,
688
+ setSelectionAreas: setSelectionAreas,
689
+ setCurrentMatcher: setCurrentMatcher
411
690
  }), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetBody.DataSpreadsheetBody, {
691
+ activeCellCoordinates: activeCellCoordinates,
692
+ ref: spreadsheetRef,
412
693
  clickAndHoldActive: clickAndHoldActive,
413
694
  setClickAndHoldActive: setClickAndHoldActive,
414
695
  currentMatcher: currentMatcher,
@@ -425,7 +706,25 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
425
706
  setActiveCellCoordinates: setActiveCellCoordinates,
426
707
  scrollBarSize: scrollBarSize,
427
708
  totalColumnsWidth: totalColumnsWidth,
428
- 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))
429
728
  }));
430
729
  }); // Return a placeholder if not released and not enabled by feature flag
431
730
 
@@ -472,7 +771,12 @@ DataSpreadsheet.propTypes = {
472
771
  /**
473
772
  * The event handler that is called when the active cell changes
474
773
  */
475
- 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
476
780
  /* TODO: add types and DocGen for all props. */
477
781
 
478
782
  };