@carbon/ibm-products 1.7.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. package/css/index-full-carbon.css +227 -5762
  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 +46 -3426
  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 +195 -4028
  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 +195 -4029
  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/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 +10 -12
  21. package/es/components/AddSelect/AddSelect.js +120 -25
  22. package/es/components/AddSelect/AddSelectBreadcrumbs.js +4 -4
  23. package/es/components/AddSelect/AddSelectColumn.js +58 -0
  24. package/es/components/AddSelect/AddSelectList.js +67 -8
  25. package/es/components/AddSelect/AddSelectSidebar.js +7 -1
  26. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
  27. package/es/components/ButtonMenu/ButtonMenu.js +7 -5
  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 +563 -80
  40. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +366 -0
  41. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +81 -0
  42. package/es/components/DataSpreadsheet/checkActiveHeaderCell.js +34 -0
  43. package/es/components/DataSpreadsheet/createActiveCellFn.js +47 -0
  44. package/es/components/DataSpreadsheet/createCellSelectionArea.js +45 -0
  45. package/es/components/DataSpreadsheet/getCellSize.js +30 -0
  46. package/es/components/EditSidePanel/EditSidePanel.js +9 -10
  47. package/es/components/EmptyStates/EmptyState.js +7 -6
  48. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +4 -8
  49. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +4 -8
  50. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +4 -8
  51. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +4 -8
  52. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +4 -8
  53. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +4 -8
  54. package/es/components/ExampleComponent/ExampleComponent.js +12 -13
  55. package/es/components/ExportModal/ExportModal.js +13 -9
  56. package/es/components/ExpressiveCard/ExpressiveCard.js +0 -8
  57. package/es/components/ImportModal/ImportModal.js +7 -5
  58. package/es/components/InlineEdit/InlineEdit.js +44 -46
  59. package/es/components/LoadingBar/LoadingBar.js +13 -17
  60. package/es/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
  61. package/es/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
  62. package/es/components/ModifiedTabs/ModifiedTabs.js +24 -18
  63. package/es/components/NotificationsPanel/NotificationsPanel.js +109 -86
  64. package/es/components/OptionsTile/OptionsTile.js +17 -10
  65. package/es/components/PageHeader/PageHeader.js +58 -47
  66. package/es/components/PageHeader/PageHeaderUtils.js +3 -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 +25 -12
  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/Toolbar/ToolbarButton.js +0 -3
  76. package/es/components/UserProfileImage/UserProfileImage.js +2 -1
  77. package/es/components/WebTerminal/WebTerminal.js +17 -18
  78. package/es/components/index.js +0 -1
  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/utils/DisplayBox.js +31 -0
  82. package/es/global/js/utils/Wrap.js +7 -5
  83. package/es/global/js/utils/deepCloneObject.js +26 -0
  84. package/lib/components/APIKeyModal/APIKeyModal.js +10 -13
  85. package/lib/components/ActionBar/ActionBar.js +0 -3
  86. package/lib/components/ActionBar/ActionBarItem.js +2 -6
  87. package/lib/components/ActionSet/ActionSet.js +10 -12
  88. package/lib/components/AddSelect/AddSelect.js +118 -24
  89. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +2 -3
  90. package/lib/components/AddSelect/AddSelectColumn.js +79 -0
  91. package/lib/components/AddSelect/AddSelectList.js +65 -8
  92. package/lib/components/AddSelect/AddSelectSidebar.js +7 -1
  93. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
  94. package/lib/components/ButtonMenu/ButtonMenu.js +7 -5
  95. package/lib/components/ButtonMenu/ButtonMenuItem.js +1 -2
  96. package/lib/components/Card/Card.js +31 -21
  97. package/lib/components/Card/CardFooter.js +14 -10
  98. package/lib/components/Card/CardHeader.js +8 -6
  99. package/lib/components/Cascade/Cascade.js +5 -4
  100. package/lib/components/ComboButton/ComboButton.js +0 -4
  101. package/lib/components/ComboButton/ComboButtonItem/index.js +0 -5
  102. package/lib/components/CreateFullPage/CreateFullPageStep.js +17 -14
  103. package/lib/components/CreateModal/CreateModal.js +1 -4
  104. package/lib/components/CreateTearsheet/CreateTearsheet.js +10 -11
  105. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +20 -20
  106. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +567 -77
  107. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +391 -0
  108. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +99 -0
  109. package/lib/components/DataSpreadsheet/checkActiveHeaderCell.js +45 -0
  110. package/lib/components/DataSpreadsheet/createActiveCellFn.js +58 -0
  111. package/lib/components/DataSpreadsheet/createCellSelectionArea.js +56 -0
  112. package/lib/components/DataSpreadsheet/getCellSize.js +39 -0
  113. package/lib/components/EditSidePanel/EditSidePanel.js +9 -10
  114. package/lib/components/EmptyStates/EmptyState.js +9 -8
  115. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +3 -7
  116. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +3 -7
  117. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +3 -7
  118. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +3 -7
  119. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +3 -7
  120. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +3 -7
  121. package/lib/components/ExampleComponent/ExampleComponent.js +12 -13
  122. package/lib/components/ExportModal/ExportModal.js +13 -9
  123. package/lib/components/ExpressiveCard/ExpressiveCard.js +0 -8
  124. package/lib/components/ImportModal/ImportModal.js +7 -5
  125. package/lib/components/InlineEdit/InlineEdit.js +43 -45
  126. package/lib/components/LoadingBar/LoadingBar.js +13 -17
  127. package/lib/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
  128. package/lib/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
  129. package/lib/components/ModifiedTabs/ModifiedTabs.js +24 -18
  130. package/lib/components/NotificationsPanel/NotificationsPanel.js +109 -86
  131. package/lib/components/OptionsTile/OptionsTile.js +17 -10
  132. package/lib/components/PageHeader/PageHeader.js +56 -46
  133. package/lib/components/PageHeader/PageHeaderUtils.js +3 -7
  134. package/lib/components/ProductiveCard/ProductiveCard.js +24 -18
  135. package/lib/components/RemoveModal/RemoveModal.js +0 -3
  136. package/lib/components/SidePanel/SidePanel.js +22 -17
  137. package/lib/components/TagSet/TagSet.js +26 -12
  138. package/lib/components/TagSet/TagSetModal.js +17 -13
  139. package/lib/components/TagSet/TagSetOverflow.js +24 -19
  140. package/lib/components/Tearsheet/Tearsheet.js +26 -17
  141. package/lib/components/Tearsheet/TearsheetNarrow.js +18 -15
  142. package/lib/components/Toolbar/ToolbarButton.js +0 -3
  143. package/lib/components/UserProfileImage/UserProfileImage.js +2 -1
  144. package/lib/components/WebTerminal/WebTerminal.js +17 -18
  145. package/lib/components/index.js +0 -8
  146. package/lib/global/js/hooks/index.js +8 -0
  147. package/lib/global/js/hooks/useActiveElement.js +39 -0
  148. package/lib/global/js/utils/DisplayBox.js +46 -0
  149. package/lib/global/js/utils/Wrap.js +7 -5
  150. package/lib/global/js/utils/deepCloneObject.js +37 -0
  151. package/package.json +18 -18
  152. package/scss/components/{CancelableTextEdit/_index.scss → ActionBar/_storybook-styles.scss} +2 -2
  153. package/scss/components/ActionSet/_storybook-styles.scss +1 -3
  154. package/scss/components/AddSelect/_add-select.scss +83 -14
  155. package/scss/components/{CancelableTextEdit → BreadcrumbWithOverflow}/_storybook-styles.scss +2 -2
  156. package/scss/components/ButtonSetWithOverflow/_storybook-styles.scss +8 -0
  157. package/scss/components/CreateInfluencer/_create-influencer.scss +2 -0
  158. package/scss/components/CreateModal/_create-modal.scss +1 -0
  159. package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
  160. package/scss/components/CreateTearsheetNarrow/_create-tearsheet-narrow.scss +1 -0
  161. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +53 -7
  162. package/scss/components/InlineEdit/_inline-edit.scss +36 -15
  163. package/scss/components/InlineEdit/_storybook-styles.scss +2 -0
  164. package/scss/components/LoadingBar/_loading-bar.scss +13 -0
  165. package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -0
  166. package/scss/components/PageHeader/_page-header.scss +2 -0
  167. package/scss/components/SidePanel/_side-panel.scss +11 -4
  168. package/scss/components/StatusIcon/_status-icon.scss +1 -0
  169. package/scss/components/TagSet/_storybook-styles.scss +8 -0
  170. package/scss/components/Tearsheet/_tearsheet.scss +1 -2
  171. package/scss/components/UserProfileImage/_user-profile-image.scss +9 -0
  172. package/scss/components/WebTerminal/_web-terminal.scss +2 -0
  173. package/scss/components/_index.scss +0 -1
  174. package/scss/global/styles/_display-box.scss +62 -0
  175. package/es/components/CancelableTextEdit/CancelableTextEdit.js +0 -245
  176. package/es/components/CancelableTextEdit/index.js +0 -7
  177. package/lib/components/CancelableTextEdit/CancelableTextEdit.js +0 -265
  178. package/lib/components/CancelableTextEdit/index.js +0 -13
  179. package/scss/components/CancelableTextEdit/_cancelable-text-edit.scss +0 -212
@@ -0,0 +1,366 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+
5
+ /**
6
+ * Copyright IBM Corp. 2022, 2022
7
+ *
8
+ * This source code is licensed under the Apache-2.0 license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */
11
+ import React, { useRef, useCallback, useEffect, forwardRef } from 'react';
12
+ import PropTypes from 'prop-types';
13
+ import { FixedSizeList } from 'react-window';
14
+ import cx from 'classnames';
15
+ import { pkg } from '../../settings';
16
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
17
+ import uuidv4 from '../../global/js/utils/uuidv4';
18
+ import { createCellSelectionArea } from './createCellSelectionArea';
19
+ import { checkActiveHeaderCell } from './checkActiveHeaderCell';
20
+ var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
21
+ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
22
+ var activeCellCoordinates = _ref.activeCellCoordinates,
23
+ defaultColumn = _ref.defaultColumn,
24
+ getTableBodyProps = _ref.getTableBodyProps,
25
+ id = _ref.id,
26
+ prepareRow = _ref.prepareRow,
27
+ rows = _ref.rows,
28
+ setActiveCellCoordinates = _ref.setActiveCellCoordinates,
29
+ selectionAreas = _ref.selectionAreas,
30
+ setContainerHasFocus = _ref.setContainerHasFocus,
31
+ setSelectionAreas = _ref.setSelectionAreas,
32
+ scrollBarSize = _ref.scrollBarSize,
33
+ totalColumnsWidth = _ref.totalColumnsWidth,
34
+ clickAndHoldActive = _ref.clickAndHoldActive,
35
+ setClickAndHoldActive = _ref.setClickAndHoldActive,
36
+ currentMatcher = _ref.currentMatcher,
37
+ setCurrentMatcher = _ref.setCurrentMatcher;
38
+ var currentMatcherRef = ref; // Create cell selection areas based on selectionAreas array
39
+
40
+ useEffect(function () {
41
+ if (selectionAreas && selectionAreas.length) {
42
+ selectionAreas.map(function (area) {
43
+ if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
44
+ // Do not create a cell selection area if point1 and point2 have the same values
45
+ // Cell selections must have two distinctly different points for an area to be created
46
+ if (area.point1.row === area.point2.row && area.point1.column === area.point2.column) {
47
+ var selectionAreasClone = deepCloneObject(selectionAreas);
48
+ var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
49
+ return item.matcher === area.matcher;
50
+ });
51
+ selectionAreasClone[indexOfCurrentArea].areaCreated = false;
52
+ selectionAreasClone[indexOfCurrentArea].point2 = null;
53
+ return setSelectionAreas(selectionAreasClone);
54
+ }
55
+
56
+ createCellSelectionArea({
57
+ area: area,
58
+ blockClass: blockClass,
59
+ selectionAreas: selectionAreas,
60
+ setSelectionAreas: setSelectionAreas
61
+ });
62
+ }
63
+
64
+ return;
65
+ });
66
+ }
67
+ }, [selectionAreas, setSelectionAreas]); // Mouse up
68
+
69
+ useEffect(function () {
70
+ var handleMouseUp = function handleMouseUp(event) {
71
+ setClickAndHoldActive(false);
72
+ var cellButton = event.target.closest(".".concat(blockClass, "__body--td"));
73
+
74
+ if (cellButton) {
75
+ var endCellCoordinates = {
76
+ row: Number(cellButton.getAttribute('data-row-index')),
77
+ column: Number(cellButton.getAttribute('data-column-index'))
78
+ };
79
+ setSelectionAreas(function (prev) {
80
+ var selectionAreaClone = deepCloneObject(prev);
81
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
82
+ return item.matcher === currentMatcher;
83
+ }); // No items in the array have an object that matches the value of currentMatcher
84
+
85
+ if (indexOfItemToUpdate === -1) {
86
+ return prev;
87
+ }
88
+
89
+ selectionAreaClone[indexOfItemToUpdate].point2 = endCellCoordinates;
90
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
91
+ return selectionAreaClone;
92
+ });
93
+ } else {
94
+ var selectionAreaClone = deepCloneObject(selectionAreas);
95
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
96
+ return item.matcher === currentMatcher;
97
+ });
98
+
99
+ if (indexOfItemToUpdate === -1) {
100
+ return;
101
+ }
102
+
103
+ var notYetCreatedSelections = selectionAreaClone.filter(function (item) {
104
+ return !item.areaCreated && item.matcher === currentMatcher;
105
+ });
106
+ var previouslyCreatedSelectionAreas = selectionAreaClone.filter(function (item) {
107
+ return item.point2 && item.areaCreated;
108
+ }); // We want to ensure that there is only ever one item in selectionAreas
109
+ // that has not been created yet. This item's point1 values will always
110
+ // be equal to the activeCellCoordinates
111
+
112
+ setSelectionAreas([].concat(_toConsumableArray(notYetCreatedSelections), _toConsumableArray(previouslyCreatedSelectionAreas)));
113
+ }
114
+ };
115
+
116
+ document.addEventListener('mouseup', handleMouseUp);
117
+ return function () {
118
+ document.removeEventListener('mouseup', handleMouseUp);
119
+ };
120
+ }, [selectionAreas, currentMatcher, setSelectionAreas, setClickAndHoldActive, setCurrentMatcher, ref]); // Make sure that if the cellSize prop changes, the active
121
+ // cell also gets updated with the new size
122
+
123
+ useEffect(function () {
124
+ var listContainer = spreadsheetBodyRef === null || spreadsheetBodyRef === void 0 ? void 0 : spreadsheetBodyRef.current;
125
+ var activeCellButton = listContainer.querySelector(".".concat(blockClass, "__active-cell--highlight"));
126
+
127
+ if (activeCellButton) {
128
+ activeCellButton.style.height = "".concat(defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight, "px");
129
+ }
130
+ }, [defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight]); // onClick fn for each cell in the data spreadsheet body,
131
+ // adds the active cell highlight
132
+
133
+ var handleBodyCellClick = useCallback(function (cell, columnIndex) {
134
+ return function (event) {
135
+ event.preventDefault();
136
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
137
+ var isHoldingShiftKey = event.shiftKey;
138
+ setContainerHasFocus(true);
139
+ var activeCoordinates = {
140
+ row: cell.row.index,
141
+ column: columnIndex
142
+ };
143
+ var tempMatcher = uuidv4(); // prevent multiple selections unless cmd key is held
144
+ // meaning that selectionAreas should only have one item by default
145
+
146
+ if (isHoldingCommandKey) {
147
+ setActiveCellCoordinates(activeCoordinates);
148
+ setCurrentMatcher(tempMatcher);
149
+ setSelectionAreas(function (prev) {
150
+ return [].concat(_toConsumableArray(prev), [{
151
+ point1: activeCoordinates,
152
+ matcher: tempMatcher
153
+ }]);
154
+ });
155
+ } else if (isHoldingShiftKey) {
156
+ setContainerHasFocus(true);
157
+ var selectionAreaClone = deepCloneObject(selectionAreas);
158
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
159
+ return item.matcher === currentMatcher;
160
+ });
161
+
162
+ if (indexOfItemToUpdate === -1) {
163
+ // There is always a selectionArea with a point1 object that updates
164
+ // whenever the activeCellCoordinates update, we should always be able
165
+ // to find an index, but if we do not for some reason we should return
166
+ // at this point.
167
+ return;
168
+ } else {
169
+ // Update the selectionArea that was found, do not update currentMatcher
170
+ selectionAreaClone[indexOfItemToUpdate].point1 = activeCellCoordinates;
171
+ selectionAreaClone[indexOfItemToUpdate].point2 = activeCoordinates;
172
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
173
+ selectionAreaClone[indexOfItemToUpdate].matcher = currentMatcher;
174
+ setSelectionAreas(selectionAreaClone);
175
+ }
176
+ } else {
177
+ setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
178
+
179
+ var cellSelections = spreadsheetBodyRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
180
+
181
+ _toConsumableArray(cellSelections).forEach(function (element) {
182
+ return element.remove();
183
+ });
184
+
185
+ setSelectionAreas([{
186
+ point1: activeCoordinates,
187
+ matcher: tempMatcher
188
+ }]);
189
+ setCurrentMatcher(tempMatcher);
190
+ }
191
+
192
+ currentMatcherRef.current = tempMatcher;
193
+ setClickAndHoldActive(true);
194
+ };
195
+ }, [currentMatcherRef, currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher]);
196
+ var handleBodyCellHover = useCallback(function (cell, columnIndex) {
197
+ return function () {
198
+ if (clickAndHoldActive) {
199
+ var cellCoordinates = {
200
+ row: cell.row.index,
201
+ column: columnIndex
202
+ };
203
+ setSelectionAreas(function (prev) {
204
+ var _selectionAreaClone$i, _selectionAreaClone$i2;
205
+
206
+ var selectionAreaClone = deepCloneObject(prev);
207
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
208
+ return item.matcher === currentMatcher;
209
+ }); // No items in the array match up with the currentMatcher value
210
+
211
+ if (indexOfItemToUpdate === -1) {
212
+ return prev;
213
+ } // Do not update state if you're still hovering on the same cell
214
+
215
+
216
+ if (((_selectionAreaClone$i = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i === void 0 ? void 0 : _selectionAreaClone$i.row) === cellCoordinates.row && ((_selectionAreaClone$i2 = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i2 === void 0 ? void 0 : _selectionAreaClone$i2.column) === cellCoordinates.column) {
217
+ return prev;
218
+ }
219
+
220
+ selectionAreaClone[indexOfItemToUpdate].point2 = cellCoordinates;
221
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
222
+ return selectionAreaClone;
223
+ });
224
+ }
225
+ };
226
+ }, [clickAndHoldActive, currentMatcher, setSelectionAreas]); // Renders each cell in the spreadsheet body
227
+
228
+ var RenderRow = useCallback(function (_ref2) {
229
+ var index = _ref2.index,
230
+ style = _ref2.style;
231
+ var row = rows[index];
232
+ prepareRow(row);
233
+ return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
234
+ style: style
235
+ }), {
236
+ className: cx("".concat(blockClass, "__tr")),
237
+ "data-row-index": index
238
+ }), /*#__PURE__*/React.createElement("button", {
239
+ tabIndex: -1,
240
+ "data-row-index": index,
241
+ "data-column-index": "header",
242
+ type: "button",
243
+ className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || checkActiveHeaderCell(index, selectionAreas, 'row'))),
244
+ style: {
245
+ width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
246
+ }
247
+ }, index + 1), row.cells.map(function (cell, index) {
248
+ return /*#__PURE__*/React.createElement("button", _extends({
249
+ tabIndex: -1,
250
+ "data-row-index": cell.row.index,
251
+ "data-column-index": index
252
+ }, cell.getCellProps(), {
253
+ className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
254
+ key: "cell_".concat(index),
255
+ onMouseDown: handleBodyCellClick(cell, index),
256
+ onMouseOver: handleBodyCellHover(cell, index),
257
+ onFocus: function onFocus() {},
258
+ type: "button"
259
+ }), cell.render('Cell'));
260
+ }));
261
+ }, [prepareRow, rows, defaultColumn.rowHeaderWidth, handleBodyCellClick, handleBodyCellHover, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas]);
262
+ var spreadsheetBodyRef = useRef();
263
+ return /*#__PURE__*/React.createElement("div", _extends({
264
+ ref: spreadsheetBodyRef,
265
+ className: cx("".concat(blockClass, "__body--container"))
266
+ }, getTableBodyProps()), /*#__PURE__*/React.createElement(FixedSizeList, {
267
+ className: cx("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
268
+ height: 400,
269
+ itemCount: rows.length,
270
+ itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
271
+ width: totalColumnsWidth + scrollBarSize
272
+ }, RenderRow));
273
+ });
274
+ DataSpreadsheetBody.propTypes = {
275
+ /**
276
+ * Object containing the active cell coordinates
277
+ */
278
+ activeCellCoordinates: PropTypes.shape({
279
+ row: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
280
+ column: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
281
+ }),
282
+
283
+ /**
284
+ * Is the user clicking and holding in the data spreadsheet body
285
+ */
286
+ clickAndHoldActive: PropTypes.bool,
287
+
288
+ /**
289
+ * This represents the id of the current cell selection area
290
+ */
291
+ currentMatcher: PropTypes.string,
292
+
293
+ /**
294
+ * Default spreadsheet sizing values
295
+ */
296
+ defaultColumn: PropTypes.shape({
297
+ rowHeight: PropTypes.number,
298
+ rowHeaderWidth: PropTypes.number,
299
+ width: PropTypes.number
300
+ }),
301
+
302
+ /**
303
+ * Function to set table body prop values
304
+ */
305
+ getTableBodyProps: PropTypes.func,
306
+
307
+ /**
308
+ * The spreadsheet id
309
+ */
310
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
311
+
312
+ /**
313
+ * The event handler that is called when the active cell changes
314
+ */
315
+ onActiveCellChange: PropTypes.func,
316
+
317
+ /**
318
+ * Prepare row function from react-table
319
+ */
320
+ prepareRow: PropTypes.func,
321
+
322
+ /**
323
+ * All of the spreadsheet row data
324
+ */
325
+ rows: PropTypes.arrayOf(PropTypes.object),
326
+
327
+ /**
328
+ * The scrollbar width
329
+ */
330
+ scrollBarSize: PropTypes.number,
331
+
332
+ /**
333
+ * Array of selection areas
334
+ */
335
+ selectionAreas: PropTypes.array,
336
+
337
+ /**
338
+ * Setter fn for activeCellCoordinates state value
339
+ */
340
+ setActiveCellCoordinates: PropTypes.func,
341
+
342
+ /**
343
+ * Setter fn for clickAndHold state value
344
+ */
345
+ setClickAndHoldActive: PropTypes.func,
346
+
347
+ /**
348
+ * Setter fn for containerHasFocus state value
349
+ */
350
+ setContainerHasFocus: PropTypes.func,
351
+
352
+ /**
353
+ * Setter fn for currentMatcher state value
354
+ */
355
+ setCurrentMatcher: PropTypes.func,
356
+
357
+ /**
358
+ * Setter fn for selectionAreas state value
359
+ */
360
+ setSelectionAreas: PropTypes.func,
361
+
362
+ /**
363
+ * The total columns width
364
+ */
365
+ totalColumnsWidth: PropTypes.number
366
+ };
@@ -0,0 +1,81 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+
4
+ /**
5
+ * Copyright IBM Corp. 2022, 2022
6
+ *
7
+ * This source code is licensed under the Apache-2.0 license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import React from 'react';
11
+ import PropTypes from 'prop-types';
12
+ import cx from 'classnames';
13
+ import { pkg } from '../../settings';
14
+ import { checkActiveHeaderCell } from './checkActiveHeaderCell';
15
+ var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
16
+ export var DataSpreadsheetHeader = function DataSpreadsheetHeader(_ref) {
17
+ var activeCellCoordinates = _ref.activeCellCoordinates,
18
+ defaultColumn = _ref.defaultColumn,
19
+ headerGroups = _ref.headerGroups,
20
+ selectionAreas = _ref.selectionAreas;
21
+ return /*#__PURE__*/React.createElement("div", {
22
+ className: cx("".concat(blockClass, "__header--container"))
23
+ }, headerGroups.map(function (headerGroup, index) {
24
+ return /*#__PURE__*/React.createElement("div", _extends({
25
+ key: "header_".concat(index)
26
+ }, headerGroup.getHeaderGroupProps(), {
27
+ className: "".concat(blockClass, "__tr")
28
+ }), /*#__PURE__*/React.createElement("button", {
29
+ "data-row-index": "header",
30
+ "data-column-index": "header",
31
+ type: "button",
32
+ tabIndex: -1,
33
+ className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header')),
34
+ style: {
35
+ width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
36
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
37
+ }
38
+ }, "\xA0"), headerGroup.headers.map(function (column, index) {
39
+ return /*#__PURE__*/React.createElement("button", _extends({
40
+ key: "column_".concat(index),
41
+ "data-row-index": "header",
42
+ "data-column-index": index,
43
+ tabIndex: -1,
44
+ style: {
45
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
46
+ }
47
+ }, column.getHeaderProps(), {
48
+ className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || checkActiveHeaderCell(index, selectionAreas, 'column'))),
49
+ type: "button"
50
+ }), column.render('Header'));
51
+ }));
52
+ }));
53
+ };
54
+ DataSpreadsheetHeader.propTypes = {
55
+ /**
56
+ * Object containing the active cell coordinates
57
+ */
58
+ activeCellCoordinates: PropTypes.shape({
59
+ row: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
60
+ column: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
61
+ }),
62
+
63
+ /**
64
+ * Default spreadsheet sizing values
65
+ */
66
+ defaultColumn: PropTypes.shape({
67
+ rowHeight: PropTypes.number,
68
+ rowHeaderWidth: PropTypes.number,
69
+ width: PropTypes.number
70
+ }),
71
+
72
+ /**
73
+ * Headers provided from useTable hook
74
+ */
75
+ headerGroups: PropTypes.arrayOf(PropTypes.object),
76
+
77
+ /**
78
+ * All of the cell selection area items
79
+ */
80
+ selectionAreas: PropTypes.arrayOf(PropTypes.object)
81
+ };
@@ -0,0 +1,34 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+
3
+ /**
4
+ * Copyright IBM Corp. 2022, 2022
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject'; // Determines if a row or column header cell should receive a highlight/active background color
10
+ // Check each object in selectionAreas and see if the headerIndex is between
11
+ // point1.row and point2.row, inclusive
12
+
13
+ export var checkActiveHeaderCell = function checkActiveHeaderCell(headerIndex, selectionAreas, headerType) {
14
+ var areasCloned = deepCloneObject(selectionAreas);
15
+ var activeRowIndexes = [];
16
+ areasCloned.forEach(function (area) {
17
+ var _area$point, _area$point2, _area$point3, _area$point4;
18
+
19
+ var greatestRowIndex = Math.max((_area$point = area.point1) === null || _area$point === void 0 ? void 0 : _area$point[headerType], (_area$point2 = area.point2) === null || _area$point2 === void 0 ? void 0 : _area$point2[headerType]);
20
+ var lowestRowIndex = Math.min((_area$point3 = area.point1) === null || _area$point3 === void 0 ? void 0 : _area$point3[headerType], (_area$point4 = area.point2) === null || _area$point4 === void 0 ? void 0 : _area$point4[headerType]);
21
+
22
+ for (var i = lowestRowIndex; i <= greatestRowIndex; i++) {
23
+ activeRowIndexes.push(i);
24
+ }
25
+ });
26
+
27
+ var activeRowIndexesNoDuplicates = _toConsumableArray(new Set(activeRowIndexes));
28
+
29
+ if (areasCloned !== null && areasCloned !== void 0 && areasCloned.length && activeRowIndexesNoDuplicates.includes(headerIndex)) {
30
+ return true;
31
+ }
32
+
33
+ return false;
34
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { px } from '@carbon/layout';
8
+ import { pkg } from '../../settings';
9
+ export var createActiveCellFn = function createActiveCellFn(_ref) {
10
+ var placementElement = _ref.placementElement,
11
+ coords = _ref.coords,
12
+ _ref$addToHeader = _ref.addToHeader,
13
+ addToHeader = _ref$addToHeader === void 0 ? false : _ref$addToHeader,
14
+ contextRef = _ref.contextRef,
15
+ _ref$blockClass = _ref.blockClass,
16
+ blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
17
+ onActiveCellChange = _ref.onActiveCellChange,
18
+ activeCellValue = _ref.activeCellValue,
19
+ handleActiveCellMouseEnter = _ref.handleActiveCellMouseEnter;
20
+
21
+ if (!coords) {
22
+ return;
23
+ } // If the active cell is in the column header row (very first), we need to append this element
24
+ // to `.${blockClass}__header--container`, otherwise it should be appended to `.${blockClass}__listContainer` firstElementChild
25
+
26
+
27
+ var activeElementContainer = addToHeader ? contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__header--container")) : contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
28
+ var relativePosition = {
29
+ top: placementElement.getBoundingClientRect().top - activeElementContainer.getBoundingClientRect().top,
30
+ left: placementElement.getBoundingClientRect().left - activeElementContainer.getBoundingClientRect().left
31
+ };
32
+ var activeCellButton = (contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"))) || document.createElement('button');
33
+ activeCellButton.classList.add("".concat(blockClass, "__active-cell--highlight"), "".concat(blockClass, "--interactive-cell-element"));
34
+ activeCellButton.addEventListener('mouseenter', handleActiveCellMouseEnter);
35
+ activeCellButton.style.width = px(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetWidth);
36
+ activeCellButton.style.height = px(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetHeight);
37
+ activeCellButton.style.left = px(relativePosition.left);
38
+ activeCellButton.style.top = px(relativePosition.top);
39
+ activeCellButton.setAttribute('data-active-row-index', typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number' ? coords.row : 'header');
40
+ activeCellButton.setAttribute('data-active-column-index', typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' ? coords.column : 'header');
41
+ activeElementContainer.appendChild(activeCellButton);
42
+ activeCellButton.focus();
43
+
44
+ if (typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' && typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number') {
45
+ onActiveCellChange === null || onActiveCellChange === void 0 ? void 0 : onActiveCellChange(activeCellValue);
46
+ }
47
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { px } from '@carbon/layout';
8
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
9
+ export var createCellSelectionArea = function createCellSelectionArea(_ref) {
10
+ var area = _ref.area,
11
+ blockClass = _ref.blockClass,
12
+ selectionAreas = _ref.selectionAreas,
13
+ setSelectionAreas = _ref.setSelectionAreas;
14
+ var greatestRow = Math.max(area.point1.row, area.point2.row);
15
+ var greatestColumn = Math.max(area.point1.column, area.point2.column);
16
+ var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
17
+ var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
18
+ var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]"));
19
+ var selectionAreaCellWidth = point1Element.offsetWidth;
20
+ var selectionAreaCellHeight = point1Element.offsetHeight;
21
+ var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumn - lowestColumnIndex + 1);
22
+ var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRow - lowestRowIndex + 1);
23
+ var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
24
+ var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
25
+ var relativePosition = {
26
+ top: placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top,
27
+ left: placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left
28
+ };
29
+ var selectionAreaElement = document.querySelector("[data-matcher-id=\"".concat(area.matcher, "\"]")) || document.createElement('div');
30
+ selectionAreaElement.classList.add("".concat(blockClass, "__selection-area--element"));
31
+ selectionAreaElement.setAttribute('data-matcher-id', area.matcher);
32
+ selectionAreaElement.style.width = px(selectionAreaTotalWidth);
33
+ selectionAreaElement.style.height = px(selectionAreaTotalHeight);
34
+ selectionAreaElement.style.left = px(relativePosition.left);
35
+ selectionAreaElement.style.top = px(relativePosition.top);
36
+ bodyContainer.appendChild(selectionAreaElement);
37
+ var selectionAreasClone = deepCloneObject(selectionAreas);
38
+ var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
39
+ return item.matcher === area.matcher;
40
+ }); // We need to add another property to the selectionAreas object array to
41
+ // let us know if an area has been created for each item already, ie createdArea: true
42
+
43
+ selectionAreasClone[indexOfCurrentArea].areaCreated = true;
44
+ setSelectionAreas(selectionAreasClone);
45
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { baseFontSize, sizeXSmall as compact, sizeSmall as standard, sizeMedium as medium, sizeLarge as large } from '@carbon/layout';
8
+
9
+ var getSizeInPixels = function getSizeInPixels(carbonSize) {
10
+ return Number(carbonSize.replace('rem', '') * baseFontSize);
11
+ };
12
+
13
+ export var getCellSize = function getCellSize(cellSize) {
14
+ switch (cellSize) {
15
+ case 'compact':
16
+ return getSizeInPixels(compact);
17
+
18
+ case 'standard':
19
+ return getSizeInPixels(standard);
20
+
21
+ case 'medium':
22
+ return getSizeInPixels(medium);
23
+
24
+ case 'large':
25
+ return getSizeInPixels(large);
26
+
27
+ default:
28
+ return getSizeInPixels(standard);
29
+ }
30
+ };
@@ -31,7 +31,12 @@ import '../../global/js/utils/props-helper'; // The block part of our convention
31
31
  var blockClass = "".concat(pkg.prefix, "--edit-side-panel");
32
32
  var sidePanelBlockClass = "".concat(pkg.prefix, "--side-panel");
33
33
  var componentName = 'EditSidePanel'; // NOTE: the component SCSS is not imported here: it is rolled up separately.
34
+ // Default values for props
34
35
 
36
+ var defaults = {
37
+ placement: 'right',
38
+ size: 'md'
39
+ };
35
40
  /**
36
41
  * TODO: A description of the component.
37
42
  */
@@ -45,12 +50,14 @@ export var EditSidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
45
50
  onRequestClose = _ref.onRequestClose,
46
51
  onRequestSubmit = _ref.onRequestSubmit,
47
52
  open = _ref.open,
48
- placement = _ref.placement,
53
+ _ref$placement = _ref.placement,
54
+ placement = _ref$placement === void 0 ? defaults.placement : _ref$placement,
49
55
  primaryButtonText = _ref.primaryButtonText,
50
56
  secondaryButtonText = _ref.secondaryButtonText,
51
57
  selectorPrimaryFocus = _ref.selectorPrimaryFocus,
52
58
  selectorPageContent = _ref.selectorPageContent,
53
- size = _ref.size,
59
+ _ref$size = _ref.size,
60
+ size = _ref$size === void 0 ? defaults.size : _ref$size,
54
61
  slideIn = _ref.slideIn,
55
62
  subtitle = _ref.subtitle,
56
63
  title = _ref.title,
@@ -198,12 +205,4 @@ EditSidePanel.propTypes = {
198
205
  * The title of the CreateSidePanel is usually the product or service name.
199
206
  */
200
207
  title: PropTypes.node.isRequired
201
- }; // Default values for component props. Default values are not required for
202
- // props that are required, nor for props where the component can apply
203
- // 'undefined' values reasonably. Default values should be provided when the
204
- // component needs to make a choice or assumption when a prop is not supplied.
205
-
206
- EditSidePanel.defaultProps = {
207
- placement: 'right',
208
- size: 'md'
209
208
  };