@carbon/ibm-products 1.6.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/css/index-full-carbon.css +224 -143
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +1 -2
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +178 -142
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +178 -142
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/APIKeyModal/APIKeyModal.js +10 -13
  18. package/es/components/ActionBar/ActionBar.js +0 -3
  19. package/es/components/ActionBar/ActionBarItem.js +2 -6
  20. package/es/components/ActionSet/ActionSet.js +11 -13
  21. package/es/components/AddSelect/AddSelect.js +121 -25
  22. package/es/components/AddSelect/AddSelectBreadcrumbs.js +5 -5
  23. package/es/components/AddSelect/AddSelectColumn.js +21 -0
  24. package/es/components/AddSelect/AddSelectList.js +68 -9
  25. package/es/components/AddSelect/AddSelectSidebar.js +43 -5
  26. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
  27. package/es/components/ButtonMenu/ButtonMenu.js +6 -4
  28. package/es/components/ButtonMenu/ButtonMenuItem.js +1 -2
  29. package/es/components/Card/Card.js +31 -21
  30. package/es/components/Card/CardFooter.js +14 -10
  31. package/es/components/Card/CardHeader.js +8 -6
  32. package/es/components/Cascade/Cascade.js +5 -4
  33. package/es/components/ComboButton/ComboButton.js +0 -4
  34. package/es/components/ComboButton/ComboButtonItem/index.js +0 -5
  35. package/es/components/CreateFullPage/CreateFullPageStep.js +15 -8
  36. package/es/components/CreateModal/CreateModal.js +1 -4
  37. package/es/components/CreateTearsheet/CreateTearsheet.js +10 -11
  38. package/es/components/CreateTearsheet/CreateTearsheetStep.js +18 -14
  39. package/es/components/DataSpreadsheet/DataSpreadsheet.js +454 -0
  40. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +322 -0
  41. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +64 -0
  42. package/es/components/DataSpreadsheet/createActiveCellFn.js +45 -0
  43. package/es/components/DataSpreadsheet/createCellSelectionArea.js +45 -0
  44. package/es/components/DataSpreadsheet/generateData.js +47 -0
  45. package/es/components/DataSpreadsheet/getCellSize.js +30 -0
  46. package/es/components/{CancelableTextEdit → DataSpreadsheet}/index.js +2 -2
  47. package/es/components/EditSidePanel/EditSidePanel.js +9 -10
  48. package/es/components/EmptyStates/EmptyState.js +7 -6
  49. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +4 -8
  50. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +4 -8
  51. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +4 -8
  52. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +4 -8
  53. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +4 -8
  54. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +4 -8
  55. package/es/components/ExampleComponent/ExampleComponent.js +12 -13
  56. package/es/components/ExportModal/ExportModal.js +13 -9
  57. package/es/components/ExpressiveCard/ExpressiveCard.js +0 -8
  58. package/es/components/ImportModal/ImportModal.js +7 -5
  59. package/es/components/InlineEdit/InlineEdit.js +51 -46
  60. package/es/components/LoadingBar/LoadingBar.js +13 -17
  61. package/es/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
  62. package/es/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
  63. package/es/components/ModifiedTabs/ModifiedTabs.js +24 -18
  64. package/es/components/NotificationsPanel/NotificationsPanel.js +109 -86
  65. package/es/components/OptionsTile/OptionsTile.js +6 -9
  66. package/es/components/PageHeader/PageHeader.js +10 -7
  67. package/es/components/ProductiveCard/ProductiveCard.js +23 -12
  68. package/es/components/RemoveModal/RemoveModal.js +0 -3
  69. package/es/components/SidePanel/SidePanel.js +22 -17
  70. package/es/components/TagSet/TagSet.js +13 -9
  71. package/es/components/TagSet/TagSetModal.js +16 -12
  72. package/es/components/TagSet/TagSetOverflow.js +21 -13
  73. package/es/components/Tearsheet/Tearsheet.js +27 -18
  74. package/es/components/Tearsheet/TearsheetNarrow.js +18 -15
  75. package/es/components/Tearsheet/TearsheetShell.js +3 -4
  76. package/es/components/Toolbar/ToolbarButton.js +0 -3
  77. package/es/components/WebTerminal/WebTerminal.js +17 -18
  78. package/es/components/index.js +2 -2
  79. package/es/global/js/hooks/index.js +1 -0
  80. package/es/global/js/hooks/useActiveElement.js +27 -0
  81. package/es/global/js/package-settings.js +2 -1
  82. package/es/global/js/utils/DisplayBox.js +31 -0
  83. package/es/global/js/utils/Wrap.js +7 -5
  84. package/es/global/js/utils/deepCloneObject.js +26 -0
  85. package/es/global/js/utils/getScrollbarWidth.js +14 -0
  86. package/lib/components/APIKeyModal/APIKeyModal.js +10 -13
  87. package/lib/components/ActionBar/ActionBar.js +0 -3
  88. package/lib/components/ActionBar/ActionBarItem.js +2 -6
  89. package/lib/components/ActionSet/ActionSet.js +11 -13
  90. package/lib/components/AddSelect/AddSelect.js +119 -24
  91. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +3 -4
  92. package/lib/components/AddSelect/AddSelectColumn.js +37 -0
  93. package/lib/components/AddSelect/AddSelectList.js +66 -9
  94. package/lib/components/AddSelect/AddSelectSidebar.js +43 -4
  95. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
  96. package/lib/components/ButtonMenu/ButtonMenu.js +6 -4
  97. package/lib/components/ButtonMenu/ButtonMenuItem.js +1 -2
  98. package/lib/components/Card/Card.js +31 -21
  99. package/lib/components/Card/CardFooter.js +14 -10
  100. package/lib/components/Card/CardHeader.js +8 -6
  101. package/lib/components/Cascade/Cascade.js +5 -4
  102. package/lib/components/ComboButton/ComboButton.js +0 -4
  103. package/lib/components/ComboButton/ComboButtonItem/index.js +0 -5
  104. package/lib/components/CreateFullPage/CreateFullPageStep.js +17 -14
  105. package/lib/components/CreateModal/CreateModal.js +1 -4
  106. package/lib/components/CreateTearsheet/CreateTearsheet.js +10 -11
  107. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +20 -20
  108. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +478 -0
  109. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +349 -0
  110. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +80 -0
  111. package/lib/components/DataSpreadsheet/createActiveCellFn.js +56 -0
  112. package/lib/components/DataSpreadsheet/createCellSelectionArea.js +56 -0
  113. package/lib/components/DataSpreadsheet/generateData.js +58 -0
  114. package/lib/components/DataSpreadsheet/getCellSize.js +39 -0
  115. package/lib/components/DataSpreadsheet/index.js +13 -0
  116. package/lib/components/EditSidePanel/EditSidePanel.js +9 -10
  117. package/lib/components/EmptyStates/EmptyState.js +9 -8
  118. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +3 -7
  119. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +3 -7
  120. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +3 -7
  121. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +3 -7
  122. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +3 -7
  123. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +3 -7
  124. package/lib/components/ExampleComponent/ExampleComponent.js +12 -13
  125. package/lib/components/ExportModal/ExportModal.js +13 -9
  126. package/lib/components/ExpressiveCard/ExpressiveCard.js +0 -8
  127. package/lib/components/ImportModal/ImportModal.js +7 -5
  128. package/lib/components/InlineEdit/InlineEdit.js +51 -46
  129. package/lib/components/LoadingBar/LoadingBar.js +13 -17
  130. package/lib/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
  131. package/lib/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
  132. package/lib/components/ModifiedTabs/ModifiedTabs.js +24 -18
  133. package/lib/components/NotificationsPanel/NotificationsPanel.js +109 -86
  134. package/lib/components/OptionsTile/OptionsTile.js +6 -9
  135. package/lib/components/PageHeader/PageHeader.js +9 -6
  136. package/lib/components/ProductiveCard/ProductiveCard.js +24 -18
  137. package/lib/components/RemoveModal/RemoveModal.js +0 -3
  138. package/lib/components/SidePanel/SidePanel.js +22 -17
  139. package/lib/components/TagSet/TagSet.js +13 -9
  140. package/lib/components/TagSet/TagSetModal.js +17 -13
  141. package/lib/components/TagSet/TagSetOverflow.js +24 -19
  142. package/lib/components/Tearsheet/Tearsheet.js +26 -17
  143. package/lib/components/Tearsheet/TearsheetNarrow.js +18 -15
  144. package/lib/components/Tearsheet/TearsheetShell.js +2 -3
  145. package/lib/components/Toolbar/ToolbarButton.js +0 -3
  146. package/lib/components/WebTerminal/WebTerminal.js +17 -18
  147. package/lib/components/index.js +8 -8
  148. package/lib/global/js/hooks/index.js +8 -0
  149. package/lib/global/js/hooks/useActiveElement.js +39 -0
  150. package/lib/global/js/package-settings.js +2 -1
  151. package/lib/global/js/utils/DisplayBox.js +46 -0
  152. package/lib/global/js/utils/Wrap.js +7 -5
  153. package/lib/global/js/utils/deepCloneObject.js +37 -0
  154. package/lib/global/js/utils/getScrollbarWidth.js +23 -0
  155. package/package.json +18 -16
  156. package/scss/components/{CancelableTextEdit → ActionBar}/_storybook-styles.scss +2 -2
  157. package/scss/components/ActionSet/_storybook-styles.scss +1 -3
  158. package/scss/components/AddSelect/_add-select.scss +77 -1
  159. package/scss/components/BreadcrumbWithOverflow/_storybook-styles.scss +8 -0
  160. package/scss/components/ButtonSetWithOverflow/_storybook-styles.scss +8 -0
  161. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +120 -0
  162. package/scss/components/{CancelableTextEdit → DataSpreadsheet}/_index.scss +2 -2
  163. package/scss/components/DataSpreadsheet/_storybook-styles.scss +6 -0
  164. package/scss/components/InlineEdit/_inline-edit.scss +22 -8
  165. package/scss/components/InlineEdit/_storybook-styles.scss +1 -0
  166. package/scss/components/TagSet/_storybook-styles.scss +8 -0
  167. package/scss/components/Tearsheet/_tearsheet.scss +1 -2
  168. package/scss/components/_index.scss +1 -1
  169. package/scss/global/styles/_display-box.scss +62 -0
  170. package/es/components/CancelableTextEdit/CancelableTextEdit.js +0 -245
  171. package/lib/components/CancelableTextEdit/CancelableTextEdit.js +0 -265
  172. package/lib/components/CancelableTextEdit/index.js +0 -13
  173. package/scss/components/CancelableTextEdit/_cancelable-text-edit.scss +0 -212
@@ -0,0 +1,454 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["cellSize", "className", "columns", "data", "id", "onActiveCellChange"];
6
+
7
+ 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; }
8
+
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+
11
+ /**
12
+ * Copyright IBM Corp. 2022, 2022
13
+ *
14
+ * This source code is licensed under the Apache-2.0 license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ */
17
+ // Import portions of React that are needed.
18
+ import React, { useMemo, useRef, useEffect, useState, useCallback } from 'react';
19
+ import { useBlockLayout, useTable } from 'react-table'; // Other standard imports.
20
+
21
+ import PropTypes from 'prop-types';
22
+ import cx from 'classnames';
23
+ import { getDevtoolsProps } from '../../global/js/utils/devtools';
24
+ import { pkg } from '../../settings';
25
+ import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
26
+ import { DataSpreadsheetBody } from './DataSpreadsheetBody';
27
+ import { getCellSize } from './getCellSize';
28
+ import { DataSpreadsheetHeader } from './DataSpreadsheetHeader';
29
+ import { useActiveElement } from '../../global/js/hooks';
30
+ import { createActiveCellFn } from './createActiveCellFn'; // cspell:words rowcount colcount
31
+ // The block part of our conventional BEM class names (blockClass__E--M).
32
+
33
+ var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
34
+ var componentName = 'DataSpreadsheet'; // Default values for props
35
+
36
+ var defaults = {
37
+ cellSize: 'standard',
38
+ columns: Object.freeze([]),
39
+ data: Object.freeze([])
40
+ };
41
+ /**
42
+ * DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
43
+ */
44
+
45
+ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
46
+ var _ref$cellSize = _ref.cellSize,
47
+ cellSize = _ref$cellSize === void 0 ? defaults.cellSize : _ref$cellSize,
48
+ className = _ref.className,
49
+ _ref$columns = _ref.columns,
50
+ columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
51
+ _ref$data = _ref.data,
52
+ data = _ref$data === void 0 ? defaults.data : _ref$data,
53
+ id = _ref.id,
54
+ onActiveCellChange = _ref.onActiveCellChange,
55
+ rest = _objectWithoutProperties(_ref, _excluded);
56
+
57
+ var focusedElement = useActiveElement();
58
+
59
+ var _useState = useState(false),
60
+ _useState2 = _slicedToArray(_useState, 2),
61
+ containerHasFocus = _useState2[0],
62
+ setContainerHasFocus = _useState2[1];
63
+
64
+ var _useState3 = useState(null),
65
+ _useState4 = _slicedToArray(_useState3, 2),
66
+ activeCellCoordinates = _useState4[0],
67
+ setActiveCellCoordinates = _useState4[1];
68
+
69
+ var _useState5 = useState([]),
70
+ _useState6 = _slicedToArray(_useState5, 2),
71
+ selectionAreas = _useState6[0],
72
+ setSelectionAreas = _useState6[1];
73
+
74
+ var _useState7 = useState(false),
75
+ _useState8 = _slicedToArray(_useState7, 2),
76
+ clickAndHoldActive = _useState8[0],
77
+ setClickAndHoldActive = _useState8[1];
78
+
79
+ var _useState9 = useState(null),
80
+ _useState10 = _slicedToArray(_useState9, 2),
81
+ currentMatcher = _useState10[0],
82
+ setCurrentMatcher = _useState10[1];
83
+
84
+ var cellSizeValue = getCellSize(cellSize);
85
+ var defaultColumn = useMemo(function () {
86
+ return {
87
+ width: 150,
88
+ rowHeaderWidth: 64,
89
+ rowHeight: cellSizeValue
90
+ };
91
+ }, [cellSizeValue]);
92
+ var scrollBarSize = useMemo(function () {
93
+ return getScrollbarWidth();
94
+ }, []);
95
+
96
+ var _useTable = useTable({
97
+ columns: columns,
98
+ data: data,
99
+ defaultColumn: defaultColumn
100
+ }, useBlockLayout),
101
+ getTableProps = _useTable.getTableProps,
102
+ getTableBodyProps = _useTable.getTableBodyProps,
103
+ headerGroups = _useTable.headerGroups,
104
+ rows = _useTable.rows,
105
+ totalColumnsWidth = _useTable.totalColumnsWidth,
106
+ prepareRow = _useTable.prepareRow; // Reset everything when spreadsheet loses focus
107
+
108
+
109
+ useEffect(function () {
110
+ if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
111
+ setContainerHasFocus(false);
112
+ removeActiveCell();
113
+ }
114
+
115
+ if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
116
+ setContainerHasFocus(true);
117
+ }
118
+ }, [focusedElement, removeActiveCell]); // Removes the active cell element
119
+
120
+ var removeActiveCell = useCallback(function () {
121
+ var activeCellHighlight = spreadsheetRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
122
+
123
+ if (activeCellHighlight) {
124
+ activeCellHighlight.remove();
125
+ }
126
+ }, [spreadsheetRef]); // Removes the cell selection elements
127
+
128
+ var removeCellSelections = useCallback(function () {
129
+ var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
130
+ Array.from(cellSelections).forEach(function (element) {
131
+ return element.remove();
132
+ });
133
+ }, [spreadsheetRef]); // Click outside useEffect
134
+
135
+ useEffect(function () {
136
+ var handleOutsideClick = function handleOutsideClick(event) {
137
+ if (!spreadsheetRef.current || spreadsheetRef.current.contains(event.target) || event.target.classList.contains("".concat(blockClass, "__active-cell--highlight"))) {
138
+ return;
139
+ }
140
+
141
+ setSelectionAreas([]);
142
+ removeActiveCell();
143
+ removeCellSelections();
144
+ setContainerHasFocus(false);
145
+ setActiveCellCoordinates(null);
146
+ };
147
+
148
+ document.addEventListener('click', handleOutsideClick);
149
+ return function () {
150
+ document.removeEventListener('click', handleOutsideClick);
151
+ };
152
+ }, [spreadsheetRef, removeActiveCell, removeCellSelections]);
153
+ var createActiveCell = useCallback(function (_ref2) {
154
+ var placementElement = _ref2.placementElement,
155
+ coords = _ref2.coords,
156
+ _ref2$addToHeader = _ref2.addToHeader,
157
+ addToHeader = _ref2$addToHeader === void 0 ? false : _ref2$addToHeader;
158
+ 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;
159
+ var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[coords === null || coords === void 0 ? void 0 : coords.column] : null;
160
+ createActiveCellFn({
161
+ placementElement: placementElement,
162
+ coords: coords,
163
+ addToHeader: addToHeader,
164
+ contextRef: spreadsheetRef,
165
+ blockClass: blockClass,
166
+ onActiveCellChange: onActiveCellChange,
167
+ activeCellValue: activeCellValue
168
+ });
169
+ }, [spreadsheetRef, rows, onActiveCellChange]);
170
+ var handleInitialArrowPress = useCallback(function () {
171
+ // If activeCellCoordinates is null then we need to set an initial value
172
+ // which will place the activeCell on the select all cell/button
173
+ if (!activeCellCoordinates) {
174
+ setActiveCellCoordinates({
175
+ column: 'header',
176
+ row: 'header'
177
+ });
178
+ }
179
+
180
+ return;
181
+ }, [activeCellCoordinates]);
182
+
183
+ var updateActiveCellCoordinates = function updateActiveCellCoordinates(_ref3) {
184
+ var coords = _ref3.coords,
185
+ updatedValue = _ref3.updatedValue;
186
+ setActiveCellCoordinates(_objectSpread(_objectSpread({}, coords), updatedValue));
187
+ };
188
+
189
+ var handleKeyPress = useCallback(function (event) {
190
+ var keyCode = event.keyCode; // Command keys need to be returned as there is default browser behavior with these keys
191
+
192
+ if (keyCode === 91 || keyCode === 93) {
193
+ return;
194
+ } // Prevent arrow keys, home key, and end key from scrolling the page when the data spreadsheet container has focus
195
+
196
+
197
+ if ([35, 36, 37, 38, 39, 40].indexOf(keyCode) > -1) {
198
+ event.preventDefault();
199
+ } // Clear out all cell selection areas if user uses any arrow key
200
+
201
+
202
+ if ([37, 38, 39, 40].indexOf(keyCode) > -1) {
203
+ if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length) {
204
+ setSelectionAreas([]);
205
+ removeCellSelections();
206
+ }
207
+ }
208
+
209
+ switch (keyCode) {
210
+ // Tab
211
+ case 9:
212
+ {
213
+ setSelectionAreas([]);
214
+ removeActiveCell();
215
+ setContainerHasFocus(false);
216
+ setActiveCellCoordinates(null);
217
+ break;
218
+ }
219
+ // Left
220
+
221
+ case 37:
222
+ {
223
+ handleInitialArrowPress();
224
+
225
+ var coordinatesClone = _objectSpread({}, activeCellCoordinates);
226
+
227
+ if (coordinatesClone.column === 'header') {
228
+ return;
229
+ }
230
+
231
+ if (typeof coordinatesClone.column === 'number') {
232
+ if (coordinatesClone.column === 0) {
233
+ updateActiveCellCoordinates({
234
+ coords: coordinatesClone,
235
+ updatedValue: {
236
+ column: 'header'
237
+ }
238
+ });
239
+ return;
240
+ }
241
+
242
+ updateActiveCellCoordinates({
243
+ coords: coordinatesClone,
244
+ updatedValue: {
245
+ column: coordinatesClone.column - 1
246
+ }
247
+ });
248
+ }
249
+
250
+ break;
251
+ }
252
+ // Up
253
+
254
+ case 38:
255
+ {
256
+ handleInitialArrowPress();
257
+
258
+ var _coordinatesClone = _objectSpread({}, activeCellCoordinates);
259
+
260
+ if (_coordinatesClone.row === 'header') {
261
+ return;
262
+ }
263
+
264
+ if (typeof _coordinatesClone.row === 'number') {
265
+ // set row back to header if we are at index 0
266
+ if (_coordinatesClone.row === 0) {
267
+ updateActiveCellCoordinates({
268
+ coords: _coordinatesClone,
269
+ updatedValue: {
270
+ row: 'header'
271
+ }
272
+ });
273
+ return;
274
+ } // if we are at any other index than 0, subtract 1 from current row index
275
+
276
+
277
+ updateActiveCellCoordinates({
278
+ coords: _coordinatesClone,
279
+ updatedValue: {
280
+ row: _coordinatesClone.row - 1
281
+ }
282
+ });
283
+ }
284
+
285
+ break;
286
+ }
287
+ // Right
288
+
289
+ case 39:
290
+ {
291
+ handleInitialArrowPress();
292
+
293
+ var _coordinatesClone2 = _objectSpread({}, activeCellCoordinates);
294
+
295
+ if (_coordinatesClone2.column === 'header') {
296
+ updateActiveCellCoordinates({
297
+ coords: _coordinatesClone2,
298
+ updatedValue: {
299
+ column: 0
300
+ }
301
+ });
302
+ }
303
+
304
+ if (typeof _coordinatesClone2.column === 'number') {
305
+ // Prevent active cell coordinates from updating if the active
306
+ // cell is in the last column, ie we can't go any further to the right
307
+ if (columns.length - 1 === _coordinatesClone2.column) {
308
+ return;
309
+ }
310
+
311
+ updateActiveCellCoordinates({
312
+ coords: _coordinatesClone2,
313
+ updatedValue: {
314
+ column: _coordinatesClone2.column + 1
315
+ }
316
+ });
317
+ }
318
+
319
+ break;
320
+ }
321
+ // Down
322
+
323
+ case 40:
324
+ {
325
+ handleInitialArrowPress();
326
+
327
+ var _coordinatesClone3 = _objectSpread({}, activeCellCoordinates);
328
+
329
+ if (_coordinatesClone3.row === 'header') {
330
+ updateActiveCellCoordinates({
331
+ coords: _coordinatesClone3,
332
+ updatedValue: {
333
+ row: 0
334
+ }
335
+ });
336
+ }
337
+
338
+ if (typeof _coordinatesClone3.row === 'number') {
339
+ // Prevent active cell coordinates from updating if the active
340
+ // cell is in the last row, ie we can't go any further down since
341
+ // we are in the last row
342
+ if (rows.length - 1 === _coordinatesClone3.row) {
343
+ return;
344
+ }
345
+
346
+ updateActiveCellCoordinates({
347
+ coords: _coordinatesClone3,
348
+ updatedValue: {
349
+ row: _coordinatesClone3.row + 1
350
+ }
351
+ });
352
+ }
353
+
354
+ break;
355
+ }
356
+ }
357
+ }, [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
358
+
359
+ useEffect(function () {
360
+ 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, "\"]"));
361
+ var shouldPlaceActiveCellInHeader = (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && true;
362
+ var selectAllElement = spreadsheetRef === null || spreadsheetRef === void 0 ? void 0 : spreadsheetRef.current.querySelector("[data-row-index=\"header\"][data-column-index=\"header\"]");
363
+
364
+ if (containerHasFocus) {
365
+ createActiveCell({
366
+ placementElement: activeCellCoordinates ? activeCellPlacementElement : selectAllElement,
367
+ coords: activeCellCoordinates,
368
+ addToHeader: shouldPlaceActiveCellInHeader
369
+ });
370
+ }
371
+ }, [activeCellCoordinates, spreadsheetRef, createActiveCell, containerHasFocus]);
372
+ var localRef = useRef();
373
+ var spreadsheetRef = ref || localRef;
374
+ return /*#__PURE__*/React.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
375
+ className: cx(blockClass, className, _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
376
+ ref: spreadsheetRef,
377
+ role: "grid",
378
+ tabIndex: 0,
379
+ "aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
380
+ "aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
381
+ onKeyDown: handleKeyPress,
382
+ onFocus: function onFocus() {
383
+ return setContainerHasFocus(true);
384
+ }
385
+ }), /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
386
+ cellSizeValue: cellSizeValue,
387
+ defaultColumn: defaultColumn,
388
+ headerGroups: headerGroups
389
+ }), /*#__PURE__*/React.createElement(DataSpreadsheetBody, {
390
+ clickAndHoldActive: clickAndHoldActive,
391
+ setClickAndHoldActive: setClickAndHoldActive,
392
+ currentMatcher: currentMatcher,
393
+ setCurrentMatcher: setCurrentMatcher,
394
+ setContainerHasFocus: setContainerHasFocus,
395
+ selectionAreas: selectionAreas,
396
+ setSelectionAreas: setSelectionAreas,
397
+ cellSize: cellSize,
398
+ defaultColumn: defaultColumn,
399
+ getTableBodyProps: getTableBodyProps,
400
+ onActiveCellChange: onActiveCellChange,
401
+ prepareRow: prepareRow,
402
+ rows: rows,
403
+ setActiveCellCoordinates: setActiveCellCoordinates,
404
+ scrollBarSize: scrollBarSize,
405
+ totalColumnsWidth: totalColumnsWidth,
406
+ id: id
407
+ }));
408
+ }); // Return a placeholder if not released and not enabled by feature flag
409
+
410
+ DataSpreadsheet = pkg.checkComponentEnabled(DataSpreadsheet, componentName); // The display name of the component, used by React. Note that displayName
411
+ // is used in preference to relying on function.name.
412
+
413
+ DataSpreadsheet.displayName = componentName; // The types and DocGen commentary for the component props,
414
+ // in alphabetical order (for consistency).
415
+ // See https://www.npmjs.com/package/prop-types#usage.
416
+
417
+ DataSpreadsheet.propTypes = {
418
+ /**
419
+ * Specifies the cell height
420
+ */
421
+ cellSize: PropTypes.oneOf(['compact', 'standard', 'medium', 'large']),
422
+
423
+ /**
424
+ * Provide an optional class to be applied to the containing node.
425
+ */
426
+ className: PropTypes.string,
427
+
428
+ /**
429
+ * The data that will build the column headers
430
+ */
431
+ columns: PropTypes.arrayOf(PropTypes.shape({
432
+ Header: PropTypes.string,
433
+ accessor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
434
+ Cell: PropTypes.func // optional cell formatter
435
+
436
+ })),
437
+
438
+ /**
439
+ * The spreadsheet data that will be rendered in the body of the spreadsheet component
440
+ */
441
+ data: PropTypes.arrayOf(PropTypes.shape),
442
+
443
+ /**
444
+ * The spreadsheet id
445
+ */
446
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
447
+
448
+ /**
449
+ * The event handler that is called when the active cell changes
450
+ */
451
+ onActiveCellChange: PropTypes.func
452
+ /* TODO: add types and DocGen for all props. */
453
+
454
+ };