@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,478 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.DataSpreadsheet = void 0;
11
+
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
+
14
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
+
16
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
+
18
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
19
+
20
+ var _react = _interopRequireWildcard(require("react"));
21
+
22
+ var _reactTable = require("react-table");
23
+
24
+ var _propTypes = _interopRequireDefault(require("prop-types"));
25
+
26
+ var _classnames = _interopRequireDefault(require("classnames"));
27
+
28
+ var _devtools = require("../../global/js/utils/devtools");
29
+
30
+ var _settings = require("../../settings");
31
+
32
+ var _getScrollbarWidth = require("../../global/js/utils/getScrollbarWidth");
33
+
34
+ var _DataSpreadsheetBody = require("./DataSpreadsheetBody");
35
+
36
+ var _getCellSize = require("./getCellSize");
37
+
38
+ var _DataSpreadsheetHeader = require("./DataSpreadsheetHeader");
39
+
40
+ var _hooks = require("../../global/js/hooks");
41
+
42
+ var _createActiveCellFn = require("./createActiveCellFn");
43
+
44
+ var _excluded = ["cellSize", "className", "columns", "data", "id", "onActiveCellChange"];
45
+
46
+ 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
+
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; }
49
+
50
+ 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
+
52
+ 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) { (0, _defineProperty2.default)(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; }
53
+
54
+ // cspell:words rowcount colcount
55
+ // The block part of our conventional BEM class names (blockClass__E--M).
56
+ var blockClass = "".concat(_settings.pkg.prefix, "--data-spreadsheet");
57
+ var componentName = 'DataSpreadsheet'; // Default values for props
58
+
59
+ var defaults = {
60
+ cellSize: 'standard',
61
+ columns: Object.freeze([]),
62
+ data: Object.freeze([])
63
+ };
64
+ /**
65
+ * DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
66
+ */
67
+
68
+ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
69
+ var _ref$cellSize = _ref.cellSize,
70
+ cellSize = _ref$cellSize === void 0 ? defaults.cellSize : _ref$cellSize,
71
+ className = _ref.className,
72
+ _ref$columns = _ref.columns,
73
+ columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
74
+ _ref$data = _ref.data,
75
+ data = _ref$data === void 0 ? defaults.data : _ref$data,
76
+ id = _ref.id,
77
+ onActiveCellChange = _ref.onActiveCellChange,
78
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
79
+ var focusedElement = (0, _hooks.useActiveElement)();
80
+
81
+ var _useState = (0, _react.useState)(false),
82
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
83
+ containerHasFocus = _useState2[0],
84
+ setContainerHasFocus = _useState2[1];
85
+
86
+ var _useState3 = (0, _react.useState)(null),
87
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
88
+ activeCellCoordinates = _useState4[0],
89
+ setActiveCellCoordinates = _useState4[1];
90
+
91
+ var _useState5 = (0, _react.useState)([]),
92
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
93
+ selectionAreas = _useState6[0],
94
+ setSelectionAreas = _useState6[1];
95
+
96
+ var _useState7 = (0, _react.useState)(false),
97
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
98
+ clickAndHoldActive = _useState8[0],
99
+ setClickAndHoldActive = _useState8[1];
100
+
101
+ var _useState9 = (0, _react.useState)(null),
102
+ _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
103
+ currentMatcher = _useState10[0],
104
+ setCurrentMatcher = _useState10[1];
105
+
106
+ var cellSizeValue = (0, _getCellSize.getCellSize)(cellSize);
107
+ var defaultColumn = (0, _react.useMemo)(function () {
108
+ return {
109
+ width: 150,
110
+ rowHeaderWidth: 64,
111
+ rowHeight: cellSizeValue
112
+ };
113
+ }, [cellSizeValue]);
114
+ var scrollBarSize = (0, _react.useMemo)(function () {
115
+ return (0, _getScrollbarWidth.getScrollbarWidth)();
116
+ }, []);
117
+
118
+ var _useTable = (0, _reactTable.useTable)({
119
+ columns: columns,
120
+ data: data,
121
+ defaultColumn: defaultColumn
122
+ }, _reactTable.useBlockLayout),
123
+ getTableProps = _useTable.getTableProps,
124
+ getTableBodyProps = _useTable.getTableBodyProps,
125
+ headerGroups = _useTable.headerGroups,
126
+ rows = _useTable.rows,
127
+ totalColumnsWidth = _useTable.totalColumnsWidth,
128
+ prepareRow = _useTable.prepareRow; // Reset everything when spreadsheet loses focus
129
+
130
+
131
+ (0, _react.useEffect)(function () {
132
+ if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
133
+ setContainerHasFocus(false);
134
+ removeActiveCell();
135
+ }
136
+
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
141
+
142
+ var removeActiveCell = (0, _react.useCallback)(function () {
143
+ var activeCellHighlight = spreadsheetRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
144
+
145
+ if (activeCellHighlight) {
146
+ activeCellHighlight.remove();
147
+ }
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;
161
+ }
162
+
163
+ setSelectionAreas([]);
164
+ removeActiveCell();
165
+ removeCellSelections();
166
+ setContainerHasFocus(false);
167
+ setActiveCellCoordinates(null);
168
+ };
169
+
170
+ document.addEventListener('click', handleOutsideClick);
171
+ return function () {
172
+ document.removeEventListener('click', handleOutsideClick);
173
+ };
174
+ }, [spreadsheetRef, removeActiveCell, removeCellSelections]);
175
+ var createActiveCell = (0, _react.useCallback)(function (_ref2) {
176
+ var placementElement = _ref2.placementElement,
177
+ coords = _ref2.coords,
178
+ _ref2$addToHeader = _ref2.addToHeader,
179
+ addToHeader = _ref2$addToHeader === void 0 ? false : _ref2$addToHeader;
180
+ 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
+ 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]);
192
+ var handleInitialArrowPress = (0, _react.useCallback)(function () {
193
+ // If activeCellCoordinates is null then we need to set an initial value
194
+ // which will place the activeCell on the select all cell/button
195
+ if (!activeCellCoordinates) {
196
+ setActiveCellCoordinates({
197
+ column: 'header',
198
+ row: 'header'
199
+ });
200
+ }
201
+
202
+ return;
203
+ }, [activeCellCoordinates]);
204
+
205
+ var updateActiveCellCoordinates = function updateActiveCellCoordinates(_ref3) {
206
+ var coords = _ref3.coords,
207
+ updatedValue = _ref3.updatedValue;
208
+ setActiveCellCoordinates(_objectSpread(_objectSpread({}, coords), updatedValue));
209
+ };
210
+
211
+ 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
213
+
214
+ if (keyCode === 91 || keyCode === 93) {
215
+ return;
216
+ } // Prevent arrow keys, home key, and end key from scrolling the page when the data spreadsheet container has focus
217
+
218
+
219
+ if ([35, 36, 37, 38, 39, 40].indexOf(keyCode) > -1) {
220
+ event.preventDefault();
221
+ } // Clear out all cell selection areas if user uses any arrow key
222
+
223
+
224
+ if ([37, 38, 39, 40].indexOf(keyCode) > -1) {
225
+ if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length) {
226
+ setSelectionAreas([]);
227
+ removeCellSelections();
228
+ }
229
+ }
230
+
231
+ switch (keyCode) {
232
+ // Tab
233
+ case 9:
234
+ {
235
+ setSelectionAreas([]);
236
+ removeActiveCell();
237
+ setContainerHasFocus(false);
238
+ setActiveCellCoordinates(null);
239
+ break;
240
+ }
241
+ // Left
242
+
243
+ case 37:
244
+ {
245
+ handleInitialArrowPress();
246
+
247
+ var coordinatesClone = _objectSpread({}, activeCellCoordinates);
248
+
249
+ if (coordinatesClone.column === 'header') {
250
+ return;
251
+ }
252
+
253
+ if (typeof coordinatesClone.column === 'number') {
254
+ if (coordinatesClone.column === 0) {
255
+ updateActiveCellCoordinates({
256
+ coords: coordinatesClone,
257
+ updatedValue: {
258
+ column: 'header'
259
+ }
260
+ });
261
+ return;
262
+ }
263
+
264
+ updateActiveCellCoordinates({
265
+ coords: coordinatesClone,
266
+ updatedValue: {
267
+ column: coordinatesClone.column - 1
268
+ }
269
+ });
270
+ }
271
+
272
+ break;
273
+ }
274
+ // Up
275
+
276
+ case 38:
277
+ {
278
+ handleInitialArrowPress();
279
+
280
+ var _coordinatesClone = _objectSpread({}, activeCellCoordinates);
281
+
282
+ if (_coordinatesClone.row === 'header') {
283
+ return;
284
+ }
285
+
286
+ if (typeof _coordinatesClone.row === 'number') {
287
+ // set row back to header if we are at index 0
288
+ if (_coordinatesClone.row === 0) {
289
+ updateActiveCellCoordinates({
290
+ coords: _coordinatesClone,
291
+ updatedValue: {
292
+ row: 'header'
293
+ }
294
+ });
295
+ return;
296
+ } // if we are at any other index than 0, subtract 1 from current row index
297
+
298
+
299
+ updateActiveCellCoordinates({
300
+ coords: _coordinatesClone,
301
+ updatedValue: {
302
+ row: _coordinatesClone.row - 1
303
+ }
304
+ });
305
+ }
306
+
307
+ break;
308
+ }
309
+ // Right
310
+
311
+ case 39:
312
+ {
313
+ handleInitialArrowPress();
314
+
315
+ var _coordinatesClone2 = _objectSpread({}, activeCellCoordinates);
316
+
317
+ if (_coordinatesClone2.column === 'header') {
318
+ updateActiveCellCoordinates({
319
+ coords: _coordinatesClone2,
320
+ updatedValue: {
321
+ column: 0
322
+ }
323
+ });
324
+ }
325
+
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;
331
+ }
332
+
333
+ updateActiveCellCoordinates({
334
+ coords: _coordinatesClone2,
335
+ updatedValue: {
336
+ column: _coordinatesClone2.column + 1
337
+ }
338
+ });
339
+ }
340
+
341
+ break;
342
+ }
343
+ // Down
344
+
345
+ case 40:
346
+ {
347
+ handleInitialArrowPress();
348
+
349
+ var _coordinatesClone3 = _objectSpread({}, activeCellCoordinates);
350
+
351
+ if (_coordinatesClone3.row === 'header') {
352
+ updateActiveCellCoordinates({
353
+ coords: _coordinatesClone3,
354
+ updatedValue: {
355
+ row: 0
356
+ }
357
+ });
358
+ }
359
+
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;
366
+ }
367
+
368
+ updateActiveCellCoordinates({
369
+ coords: _coordinatesClone3,
370
+ updatedValue: {
371
+ row: _coordinatesClone3.row + 1
372
+ }
373
+ });
374
+ }
375
+
376
+ break;
377
+ }
378
+ }
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
380
+
381
+ (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
391
+ });
392
+ }
393
+ }, [activeCellCoordinates, spreadsheetRef, createActiveCell, containerHasFocus]);
394
+ var localRef = (0, _react.useRef)();
395
+ var spreadsheetRef = ref || localRef;
396
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, getTableProps(), (0, _devtools.getDevtoolsProps)(componentName), {
397
+ className: (0, _classnames.default)(blockClass, className, (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
398
+ ref: spreadsheetRef,
399
+ role: "grid",
400
+ tabIndex: 0,
401
+ "aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
402
+ "aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
403
+ onKeyDown: handleKeyPress,
404
+ onFocus: function onFocus() {
405
+ return setContainerHasFocus(true);
406
+ }
407
+ }), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetHeader.DataSpreadsheetHeader, {
408
+ cellSizeValue: cellSizeValue,
409
+ defaultColumn: defaultColumn,
410
+ headerGroups: headerGroups
411
+ }), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetBody.DataSpreadsheetBody, {
412
+ clickAndHoldActive: clickAndHoldActive,
413
+ setClickAndHoldActive: setClickAndHoldActive,
414
+ currentMatcher: currentMatcher,
415
+ setCurrentMatcher: setCurrentMatcher,
416
+ setContainerHasFocus: setContainerHasFocus,
417
+ selectionAreas: selectionAreas,
418
+ setSelectionAreas: setSelectionAreas,
419
+ cellSize: cellSize,
420
+ defaultColumn: defaultColumn,
421
+ getTableBodyProps: getTableBodyProps,
422
+ onActiveCellChange: onActiveCellChange,
423
+ prepareRow: prepareRow,
424
+ rows: rows,
425
+ setActiveCellCoordinates: setActiveCellCoordinates,
426
+ scrollBarSize: scrollBarSize,
427
+ totalColumnsWidth: totalColumnsWidth,
428
+ id: id
429
+ }));
430
+ }); // Return a placeholder if not released and not enabled by feature flag
431
+
432
+
433
+ exports.DataSpreadsheet = DataSpreadsheet;
434
+ exports.DataSpreadsheet = DataSpreadsheet = _settings.pkg.checkComponentEnabled(DataSpreadsheet, componentName); // The display name of the component, used by React. Note that displayName
435
+ // is used in preference to relying on function.name.
436
+
437
+ DataSpreadsheet.displayName = componentName; // The types and DocGen commentary for the component props,
438
+ // in alphabetical order (for consistency).
439
+ // See https://www.npmjs.com/package/prop-types#usage.
440
+
441
+ DataSpreadsheet.propTypes = {
442
+ /**
443
+ * Specifies the cell height
444
+ */
445
+ cellSize: _propTypes.default.oneOf(['compact', 'standard', 'medium', 'large']),
446
+
447
+ /**
448
+ * Provide an optional class to be applied to the containing node.
449
+ */
450
+ className: _propTypes.default.string,
451
+
452
+ /**
453
+ * The data that will build the column headers
454
+ */
455
+ columns: _propTypes.default.arrayOf(_propTypes.default.shape({
456
+ Header: _propTypes.default.string,
457
+ accessor: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
458
+ Cell: _propTypes.default.func // optional cell formatter
459
+
460
+ })),
461
+
462
+ /**
463
+ * The spreadsheet data that will be rendered in the body of the spreadsheet component
464
+ */
465
+ data: _propTypes.default.arrayOf(_propTypes.default.shape),
466
+
467
+ /**
468
+ * The spreadsheet id
469
+ */
470
+ id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
471
+
472
+ /**
473
+ * The event handler that is called when the active cell changes
474
+ */
475
+ onActiveCellChange: _propTypes.default.func
476
+ /* TODO: add types and DocGen for all props. */
477
+
478
+ };