@carbon/ibm-products 1.12.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +47 -0
  2. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +1 -0
  3. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +20 -0
  4. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +1 -0
  5. package/css/components/Datagrid/styles/datagrid.css +264 -0
  6. package/css/components/Datagrid/styles/datagrid.css.map +1 -0
  7. package/css/components/Datagrid/styles/index.css +509 -0
  8. package/css/components/Datagrid/styles/index.css.map +1 -0
  9. package/css/components/Datagrid/styles/useActionsColumn.css +23 -0
  10. package/css/components/Datagrid/styles/useActionsColumn.css.map +1 -0
  11. package/css/components/Datagrid/styles/useColumnRightAlign.css +28 -0
  12. package/css/components/Datagrid/styles/useColumnRightAlign.css.map +1 -0
  13. package/css/components/Datagrid/styles/useNestedRows.css +15 -0
  14. package/css/components/Datagrid/styles/useNestedRows.css.map +1 -0
  15. package/css/components/Datagrid/styles/useNestedTable.css +25 -0
  16. package/css/components/Datagrid/styles/useNestedTable.css.map +1 -0
  17. package/css/components/Datagrid/styles/useSelectAllToggle.css +28 -0
  18. package/css/components/Datagrid/styles/useSelectAllToggle.css.map +1 -0
  19. package/css/components/Datagrid/styles/useSortableColumns.css +50 -0
  20. package/css/components/Datagrid/styles/useSortableColumns.css.map +1 -0
  21. package/css/components/Datagrid/styles/useStickyColumn.css +35 -0
  22. package/css/components/Datagrid/styles/useStickyColumn.css.map +1 -0
  23. package/css/index-full-carbon.css +653 -21
  24. package/css/index-full-carbon.css.map +1 -1
  25. package/css/index-full-carbon.min.css +6 -6
  26. package/css/index-full-carbon.min.css.map +1 -1
  27. package/css/index-without-carbon-released-only.css +21 -10
  28. package/css/index-without-carbon-released-only.css.map +1 -1
  29. package/css/index-without-carbon-released-only.min.css +2 -2
  30. package/css/index-without-carbon-released-only.min.css.map +1 -1
  31. package/css/index-without-carbon.css +653 -21
  32. package/css/index-without-carbon.css.map +1 -1
  33. package/css/index-without-carbon.min.css +5 -5
  34. package/css/index-without-carbon.min.css.map +1 -1
  35. package/css/index.css +653 -21
  36. package/css/index.css.map +1 -1
  37. package/css/index.min.css +6 -6
  38. package/css/index.min.css.map +1 -1
  39. package/es/components/ActionBar/ActionBar.js +3 -1
  40. package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
  41. package/es/components/AddSelect/AddSelect.js +98 -40
  42. package/es/components/AddSelect/AddSelectFilter.js +129 -0
  43. package/es/components/AddSelect/AddSelectList.js +27 -1
  44. package/es/components/AddSelect/AddSelectSidebar.js +15 -5
  45. package/es/components/AddSelect/add-select-utils.js +30 -0
  46. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  47. package/es/components/DataSpreadsheet/DataSpreadsheet.js +269 -142
  48. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +122 -39
  49. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +46 -17
  50. package/es/components/DataSpreadsheet/hooks/index.js +11 -0
  51. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +139 -0
  52. package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  53. package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -0
  54. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -6
  55. package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
  56. package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
  57. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
  58. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
  59. package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
  60. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +42 -8
  61. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +225 -13
  62. package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
  63. package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
  64. package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
  65. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
  66. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
  67. package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
  68. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
  69. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
  70. package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
  71. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
  72. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
  73. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
  74. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
  75. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
  76. package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
  77. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
  78. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
  79. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
  80. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
  81. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
  82. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
  83. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
  84. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
  85. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
  86. package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
  87. package/es/components/Datagrid/Datagrid/index.js +8 -0
  88. package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
  89. package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
  90. package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
  91. package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
  92. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
  93. package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
  94. package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
  95. package/es/components/Datagrid/common-column-ids.js +8 -0
  96. package/es/components/Datagrid/index.js +22 -0
  97. package/es/components/Datagrid/useActionsColumn.js +86 -0
  98. package/es/components/Datagrid/useColumnRightAlign.js +52 -0
  99. package/es/components/Datagrid/useCustomizeColumns.js +45 -0
  100. package/es/components/Datagrid/useDatagrid.js +44 -0
  101. package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
  102. package/es/components/Datagrid/useDisableSelectRows.js +84 -0
  103. package/es/components/Datagrid/useExpandedRow.js +52 -0
  104. package/es/components/Datagrid/useFlexResize.js +51 -0
  105. package/es/components/Datagrid/useFloatingScroll.js +88 -0
  106. package/es/components/Datagrid/useInfiniteScroll.js +54 -0
  107. package/es/components/Datagrid/useNestedRows.js +53 -0
  108. package/es/components/Datagrid/useOnRowClick.js +37 -0
  109. package/es/components/Datagrid/useParentDimensions.js +65 -0
  110. package/es/components/Datagrid/useResizeTable.js +40 -0
  111. package/es/components/Datagrid/useRowExpander.js +34 -0
  112. package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
  113. package/es/components/Datagrid/useRowRenderer.js +30 -0
  114. package/es/components/Datagrid/useRowSize.js +56 -0
  115. package/es/components/Datagrid/useSelectAllToggle.js +74 -0
  116. package/es/components/Datagrid/useSelectRows.js +107 -0
  117. package/es/components/Datagrid/useSkeletonRows.js +32 -0
  118. package/es/components/Datagrid/useSortableColumns.js +110 -0
  119. package/es/components/Datagrid/useStickyColumn.js +183 -0
  120. package/es/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  121. package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  122. package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  123. package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
  124. package/es/components/PageHeader/PageHeader.js +3 -1
  125. package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
  126. package/es/components/TagSet/TagSet.js +22 -6
  127. package/es/components/Tearsheet/TearsheetShell.js +34 -10
  128. package/es/components/UserProfileImage/UserProfileImage.js +37 -9
  129. package/es/components/index.js +2 -1
  130. package/es/global/js/package-settings.js +4 -2
  131. package/lib/components/ActionBar/ActionBar.js +3 -1
  132. package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
  133. package/lib/components/AddSelect/AddSelect.js +97 -38
  134. package/lib/components/AddSelect/AddSelectFilter.js +147 -0
  135. package/lib/components/AddSelect/AddSelectList.js +28 -1
  136. package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
  137. package/lib/components/AddSelect/add-select-utils.js +35 -2
  138. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  139. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +279 -145
  140. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +121 -45
  141. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +47 -17
  142. package/lib/components/DataSpreadsheet/hooks/index.js +45 -0
  143. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +151 -0
  144. package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  145. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +79 -0
  146. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -5
  147. package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
  148. package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
  149. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
  150. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
  151. package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
  152. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +44 -8
  153. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +235 -20
  154. package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
  155. package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
  156. package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
  157. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
  158. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
  159. package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
  160. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
  161. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
  162. package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
  163. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
  164. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
  165. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
  166. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
  167. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
  168. package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
  169. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
  170. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
  171. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
  172. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
  173. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
  174. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
  175. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
  176. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
  177. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
  178. package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
  179. package/lib/components/Datagrid/Datagrid/index.js +15 -0
  180. package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
  181. package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
  182. package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
  183. package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
  184. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
  185. package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
  186. package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
  187. package/lib/components/Datagrid/common-column-ids.js +16 -0
  188. package/lib/components/Datagrid/index.js +127 -0
  189. package/lib/components/Datagrid/useActionsColumn.js +94 -0
  190. package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
  191. package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
  192. package/lib/components/Datagrid/useDatagrid.js +58 -0
  193. package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
  194. package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
  195. package/lib/components/Datagrid/useExpandedRow.js +58 -0
  196. package/lib/components/Datagrid/useFlexResize.js +61 -0
  197. package/lib/components/Datagrid/useFloatingScroll.js +101 -0
  198. package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
  199. package/lib/components/Datagrid/useNestedRows.js +65 -0
  200. package/lib/components/Datagrid/useOnRowClick.js +45 -0
  201. package/lib/components/Datagrid/useParentDimensions.js +75 -0
  202. package/lib/components/Datagrid/useResizeTable.js +48 -0
  203. package/lib/components/Datagrid/useRowExpander.js +45 -0
  204. package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
  205. package/lib/components/Datagrid/useRowRenderer.js +40 -0
  206. package/lib/components/Datagrid/useRowSize.js +67 -0
  207. package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
  208. package/lib/components/Datagrid/useSelectRows.js +119 -0
  209. package/lib/components/Datagrid/useSkeletonRows.js +42 -0
  210. package/lib/components/Datagrid/useSortableColumns.js +117 -0
  211. package/lib/components/Datagrid/useStickyColumn.js +190 -0
  212. package/lib/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  213. package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  214. package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  215. package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
  216. package/lib/components/PageHeader/PageHeader.js +3 -1
  217. package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
  218. package/lib/components/TagSet/TagSet.js +22 -6
  219. package/lib/components/Tearsheet/TearsheetShell.js +36 -10
  220. package/lib/components/UserProfileImage/UserProfileImage.js +37 -9
  221. package/lib/components/index.js +9 -1
  222. package/lib/global/js/package-settings.js +4 -2
  223. package/package.json +20 -16
  224. package/scss/components/AboutModal/_about-modal.scss +4 -0
  225. package/scss/components/AddSelect/_add-select.scss +51 -2
  226. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +72 -9
  227. package/scss/components/Datagrid/_datagrid.scss +66 -0
  228. package/scss/components/Datagrid/_index.scss +8 -0
  229. package/scss/components/Datagrid/_storybook-styles.scss +26 -0
  230. package/scss/components/Datagrid/styles/_variables.scss +9 -0
  231. package/scss/components/Datagrid/styles/addons/CustomizeColumnsModal.scss +48 -0
  232. package/scss/components/Datagrid/styles/addons/RowSizeDropdown.scss +23 -0
  233. package/scss/components/Datagrid/styles/datagrid.scss +318 -0
  234. package/scss/components/Datagrid/styles/index.scss +17 -0
  235. package/scss/components/Datagrid/styles/useActionsColumn.scss +24 -0
  236. package/scss/components/Datagrid/styles/useColumnRightAlign.scss +29 -0
  237. package/scss/components/Datagrid/styles/useNestedRows.scss +17 -0
  238. package/scss/components/Datagrid/styles/useNestedTable.scss +28 -0
  239. package/scss/components/Datagrid/styles/useSelectAllToggle.scss +28 -0
  240. package/scss/components/Datagrid/styles/useSortableColumns.scss +55 -0
  241. package/scss/components/Datagrid/styles/useStickyColumn.scss +38 -0
  242. package/scss/components/ExportModal/_export-modal.scss +0 -4
  243. package/scss/components/HTTPErrors/_http-errors.scss +16 -16
  244. package/scss/components/PageHeader/_page-header.scss +4 -0
  245. package/scss/components/Tearsheet/_tearsheet.scss +4 -0
  246. package/scss/components/_index.scss +1 -0
@@ -2,6 +2,10 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
4
 
5
+ 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; }
6
+
7
+ 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; }
8
+
5
9
  /**
6
10
  * Copyright IBM Corp. 2022, 2022
7
11
  *
@@ -12,6 +16,7 @@ import React, { useRef, useCallback, useEffect, forwardRef } from 'react';
12
16
  import PropTypes from 'prop-types';
13
17
  import { FixedSizeList } from 'react-window';
14
18
  import cx from 'classnames';
19
+ import { px } from '@carbon/layout';
15
20
  import { pkg } from '../../settings';
16
21
  import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
17
22
  import uuidv4 from '../../global/js/utils/uuidv4';
@@ -25,8 +30,11 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
25
30
  var columns = _ref.columns,
26
31
  activeCellCoordinates = _ref.activeCellCoordinates,
27
32
  defaultColumn = _ref.defaultColumn,
33
+ defaultEmptyRowCount = _ref.defaultEmptyRowCount,
28
34
  getTableBodyProps = _ref.getTableBodyProps,
35
+ headerGroups = _ref.headerGroups,
29
36
  id = _ref.id,
37
+ onDataUpdate = _ref.onDataUpdate,
30
38
  prepareRow = _ref.prepareRow,
31
39
  rows = _ref.rows,
32
40
  selectionAreaData = _ref.selectionAreaData,
@@ -41,11 +49,16 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
41
49
  setClickAndHoldActive = _ref.setClickAndHoldActive,
42
50
  currentMatcher = _ref.currentMatcher,
43
51
  setCurrentMatcher = _ref.setCurrentMatcher,
44
- onSelectionAreaChange = _ref.onSelectionAreaChange;
52
+ onSelectionAreaChange = _ref.onSelectionAreaChange,
53
+ setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
45
54
  var previousState = usePreviousValue({
46
55
  selectionAreaData: selectionAreaData,
47
56
  clickAndHoldActive: clickAndHoldActive
48
- }); // Call the `onSelectionAreaChange` handler to send selection area data
57
+ }); // Set custom css property containing the spreadsheet total width
58
+
59
+ useEffect(function () {
60
+ ref === null || ref === void 0 ? void 0 : ref.current.style.setProperty("--".concat(blockClass, "--total-width"), px(totalColumnsWidth + scrollBarSize));
61
+ }, [ref, scrollBarSize, totalColumnsWidth]); // Call the `onSelectionAreaChange` handler to send selection area data
49
62
  // back to the consumer
50
63
 
51
64
  useEffect(function () {
@@ -95,18 +108,20 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
95
108
 
96
109
  if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
97
110
  createCellSelectionArea({
111
+ ref: ref,
98
112
  area: area,
99
113
  blockClass: blockClass,
100
114
  defaultColumn: defaultColumn,
101
115
  selectionAreas: selectionAreas,
102
- setSelectionAreas: setSelectionAreas
116
+ setSelectionAreas: setSelectionAreas,
117
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
103
118
  });
104
119
  }
105
120
 
106
121
  return;
107
122
  });
108
123
  }
109
- }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
124
+ }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
110
125
 
111
126
  var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
112
127
  var rowStart = _ref2.rowStart,
@@ -184,6 +199,9 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
184
199
  // meaning that selectionAreas should only have one item by default
185
200
 
186
201
  if (isHoldingCommandKey) {
202
+ var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
203
+ activeCellElement.setAttribute('data-selection-id', tempMatcher);
204
+ setActiveCellInsideSelectionArea(true);
187
205
  setActiveCellCoordinates(activeCoordinates);
188
206
  setCurrentMatcher(tempMatcher);
189
207
  setSelectionAreas(function (prev) {
@@ -214,6 +232,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
214
232
  setSelectionAreas(selectionAreaClone);
215
233
  }
216
234
  } else {
235
+ setActiveCellInsideSelectionArea(false);
217
236
  setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
218
237
 
219
238
  removeCellSelections({
@@ -227,7 +246,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
227
246
  setSelectionAreaData([]);
228
247
  }
229
248
  };
230
- }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
249
+ }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
231
250
  var handleBodyCellHover = useCallback(function (cell, columnIndex) {
232
251
  return function () {
233
252
  if (clickAndHoldActive) {
@@ -260,7 +279,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
260
279
  };
261
280
  }, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
262
281
  var handleRowHeaderClick = useCallback(function (index) {
263
- return function () {
282
+ return function (event) {
283
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
264
284
  handleHeaderCellSelection({
265
285
  type: 'row',
266
286
  activeCellCoordinates: activeCellCoordinates,
@@ -271,45 +291,88 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
271
291
  setSelectionAreas: setSelectionAreas,
272
292
  spreadsheetRef: ref,
273
293
  index: index,
274
- setSelectionAreaData: setSelectionAreaData
294
+ setSelectionAreaData: setSelectionAreaData,
295
+ isHoldingCommandKey: isHoldingCommandKey
275
296
  });
276
297
  };
277
- }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Renders each row/cell in the spreadsheet body
298
+ }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
299
+ // using defaultEmptyRowCount to determine how many empty rows are created.
300
+
301
+ useEffect(function () {
302
+ if (!(rows !== null && rows !== void 0 && rows.length)) {
303
+ var buildEmptyRows = function buildEmptyRows() {
304
+ var emptyRowData = [];
305
+
306
+ _toConsumableArray(Array(defaultEmptyRowCount)).map(function () {
307
+ var _headerGroups$;
308
+
309
+ var emptyCell = {};
310
+ (_headerGroups$ = headerGroups[0]) === null || _headerGroups$ === void 0 ? void 0 : _headerGroups$.headers.map(function (header) {
311
+ emptyCell[header.id] = null;
312
+ });
313
+ emptyRowData.push(emptyCell);
314
+ });
315
+
316
+ onDataUpdate(emptyRowData);
317
+ };
318
+
319
+ buildEmptyRows();
320
+ }
321
+ }, [rows, headerGroups, defaultEmptyRowCount, onDataUpdate]);
322
+
323
+ var RenderEmptyRows = function RenderEmptyRows() {
324
+ return /*#__PURE__*/React.createElement("div", null);
325
+ }; // Renders each row/cell in the spreadsheet body
326
+
278
327
 
279
328
  var RenderRow = useCallback(function (_ref3) {
280
329
  var index = _ref3.index,
281
330
  style = _ref3.style;
282
331
  var row = rows[index];
283
- prepareRow(row);
284
- return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
285
- style: style
286
- }), {
287
- className: cx("".concat(blockClass, "__tr")),
288
- "data-row-index": index
289
- }), /*#__PURE__*/React.createElement("button", {
290
- tabIndex: -1,
291
- "data-row-index": index,
292
- "data-column-index": "header",
293
- type: "button",
294
- onClick: handleRowHeaderClick(index),
295
- 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'))),
296
- style: {
297
- width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
298
- }
299
- }, index + 1), row.cells.map(function (cell, index) {
300
- return /*#__PURE__*/React.createElement("button", _extends({
332
+
333
+ if (rows && rows.length) {
334
+ prepareRow(row);
335
+ return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
336
+ style: style
337
+ }), {
338
+ className: cx("".concat(blockClass, "__tr")),
339
+ "data-row-index": index,
340
+ "aria-rowindex": index + 1
341
+ }), /*#__PURE__*/React.createElement("div", {
342
+ role: "rowheader"
343
+ }, /*#__PURE__*/React.createElement("button", {
344
+ id: "".concat(blockClass, "__cell--").concat(index, "--header"),
301
345
  tabIndex: -1,
302
- "data-row-index": cell.row.index,
303
- "data-column-index": index
304
- }, cell.getCellProps(), {
305
- className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
306
- key: "cell_".concat(index),
307
- onMouseDown: handleBodyCellClick(cell, index),
308
- onMouseOver: handleBodyCellHover(cell, index),
309
- onFocus: function onFocus() {},
310
- type: "button"
311
- }), cell.render('Cell'));
312
- }));
346
+ "data-row-index": index,
347
+ "data-column-index": "header",
348
+ type: "button",
349
+ onClick: handleRowHeaderClick(index),
350
+ 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'))),
351
+ style: {
352
+ width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4
353
+ }
354
+ }, index + 1)), row.cells.map(function (cell, index) {
355
+ return /*#__PURE__*/React.createElement("div", _extends({
356
+ key: "cell_".concat(index),
357
+ "aria-colindex": index + 1
358
+ }, cell.getCellProps(), {
359
+ role: "gridcell",
360
+ style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
361
+ display: 'grid'
362
+ })
363
+ }), /*#__PURE__*/React.createElement("button", {
364
+ id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
365
+ tabIndex: -1,
366
+ "data-row-index": cell.row.index,
367
+ "data-column-index": index,
368
+ className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
369
+ onMouseDown: handleBodyCellClick(cell, index),
370
+ onMouseOver: handleBodyCellHover(cell, index),
371
+ onFocus: function onFocus() {},
372
+ type: "button"
373
+ }, cell.render('Cell')));
374
+ }));
375
+ }
313
376
  }, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
314
377
  var spreadsheetBodyRef = useRef();
315
378
  return /*#__PURE__*/React.createElement("div", _extends({
@@ -318,10 +381,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
318
381
  }, getTableBodyProps()), /*#__PURE__*/React.createElement(FixedSizeList, {
319
382
  className: cx("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
320
383
  height: 400,
321
- itemCount: rows.length,
384
+ itemCount: rows.length || defaultEmptyRowCount,
322
385
  itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
323
386
  width: totalColumnsWidth + scrollBarSize
324
- }, RenderRow));
387
+ }, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
325
388
  });
326
389
  DataSpreadsheetBody.propTypes = {
327
390
  /**
@@ -356,11 +419,21 @@ DataSpreadsheetBody.propTypes = {
356
419
  width: PropTypes.number
357
420
  }),
358
421
 
422
+ /**
423
+ * Sets the number of empty rows to be created when there is no data provided
424
+ */
425
+ defaultEmptyRowCount: PropTypes.number,
426
+
359
427
  /**
360
428
  * Function to set table body prop values
361
429
  */
362
430
  getTableBodyProps: PropTypes.func,
363
431
 
432
+ /**
433
+ * Headers provided from useTable hook
434
+ */
435
+ headerGroups: PropTypes.arrayOf(PropTypes.object),
436
+
364
437
  /**
365
438
  * The spreadsheet id
366
439
  */
@@ -371,6 +444,11 @@ DataSpreadsheetBody.propTypes = {
371
444
  */
372
445
  onActiveCellChange: PropTypes.func,
373
446
 
447
+ /**
448
+ * The event handler that is called to set the rows for the empty spreadsheet
449
+ */
450
+ onDataUpdate: PropTypes.func,
451
+
374
452
  /**
375
453
  * The event handler that is called when the selection areas change
376
454
  */
@@ -406,6 +484,11 @@ DataSpreadsheetBody.propTypes = {
406
484
  */
407
485
  setActiveCellCoordinates: PropTypes.func,
408
486
 
487
+ /**
488
+ * Setter fn for active cell inside of selection area
489
+ */
490
+ setActiveCellInsideSelectionArea: PropTypes.func,
491
+
409
492
  /**
410
493
  * Setter fn for clickAndHold state value
411
494
  */
@@ -17,9 +17,10 @@ import PropTypes from 'prop-types';
17
17
  import cx from 'classnames';
18
18
  import { px } from '@carbon/layout';
19
19
  import { pkg } from '../../settings';
20
+ import { usePreviousValue } from '../../global/js/hooks';
20
21
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
21
22
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
22
- import { usePreviousValue } from '../../global/js/hooks';
23
+ import { selectAllCells } from './utils/selectAllCells';
23
24
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
24
25
  export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
25
26
  var activeCellCoordinates = _ref.activeCellCoordinates,
@@ -33,7 +34,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
33
34
  setCurrentMatcher = _ref.setCurrentMatcher,
34
35
  setSelectionAreas = _ref.setSelectionAreas,
35
36
  setSelectionAreaData = _ref.setSelectionAreaData,
36
- rows = _ref.rows;
37
+ rows = _ref.rows,
38
+ updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
37
39
 
38
40
  var _useState = useState(0),
39
41
  _useState2 = _slicedToArray(_useState, 2),
@@ -55,7 +57,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
55
57
  }, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
56
58
 
57
59
  var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
58
- return function () {
60
+ return function (event) {
61
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
59
62
  handleHeaderCellSelection({
60
63
  type: 'column',
61
64
  activeCellCoordinates: activeCellCoordinates,
@@ -66,13 +69,27 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
66
69
  setSelectionAreas: setSelectionAreas,
67
70
  spreadsheetRef: ref,
68
71
  index: index,
69
- setSelectionAreaData: setSelectionAreaData
72
+ setSelectionAreaData: setSelectionAreaData,
73
+ isHoldingCommandKey: isHoldingCommandKey
70
74
  });
71
75
  };
72
76
  };
73
77
 
78
+ var handleSelectAllClick = function handleSelectAllClick() {
79
+ selectAllCells({
80
+ ref: ref,
81
+ setCurrentMatcher: setCurrentMatcher,
82
+ setSelectionAreas: setSelectionAreas,
83
+ rows: rows,
84
+ columns: columns,
85
+ activeCellCoordinates: activeCellCoordinates,
86
+ updateActiveCellCoordinates: updateActiveCellCoordinates
87
+ });
88
+ };
89
+
74
90
  return /*#__PURE__*/React.createElement("div", {
75
- className: cx("".concat(blockClass, "__header--container"))
91
+ className: cx("".concat(blockClass, "__header--container")),
92
+ role: "rowgroup"
76
93
  }, headerGroups.map(function (headerGroup, index) {
77
94
  return /*#__PURE__*/React.createElement("div", _extends({
78
95
  key: "header_".concat(index)
@@ -81,30 +98,37 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
81
98
  width: px(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
82
99
  }),
83
100
  className: "".concat(blockClass, "__tr")
84
- }), /*#__PURE__*/React.createElement("button", {
101
+ }), /*#__PURE__*/React.createElement("div", {
102
+ role: "columnheader",
103
+ style: {
104
+ width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4,
105
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
106
+ }
107
+ }, /*#__PURE__*/React.createElement("button", {
108
+ id: "".concat(blockClass, "__cell--header--header"),
85
109
  "data-row-index": "header",
86
110
  "data-column-index": "header",
87
111
  type: "button",
88
112
  tabIndex: -1,
89
- 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')),
90
- style: {
91
- width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
92
- height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
93
- }
94
- }, "\xA0"), headerGroup.headers.map(function (column, index) {
95
- return /*#__PURE__*/React.createElement("button", _extends({
113
+ onClick: handleSelectAllClick,
114
+ className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), _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'))
115
+ }, "\xA0")), headerGroup.headers.map(function (column, index) {
116
+ return /*#__PURE__*/React.createElement("div", _extends({
96
117
  key: "column_".concat(index),
118
+ role: "columnheader",
119
+ className: "".concat(blockClass, "__columnheader")
120
+ }, column.getHeaderProps()), /*#__PURE__*/React.createElement("button", {
121
+ id: "".concat(blockClass, "__cell--header--").concat(index),
97
122
  "data-row-index": "header",
98
123
  "data-column-index": index,
99
124
  tabIndex: -1,
100
125
  onClick: handleColumnHeaderClick(index),
101
126
  style: {
102
127
  height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
103
- }
104
- }, column.getHeaderProps(), {
128
+ },
105
129
  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'))),
106
130
  type: "button"
107
- }), column.render('Header'));
131
+ }, column.render('Header')));
108
132
  }));
109
133
  }));
110
134
  });
@@ -174,5 +198,10 @@ DataSpreadsheetHeader.propTypes = {
174
198
  /**
175
199
  * Setter fn for selectionAreas value
176
200
  */
177
- setSelectionAreas: PropTypes.func
201
+ setSelectionAreas: PropTypes.func,
202
+
203
+ /**
204
+ * Function used to update the active cell coordinates
205
+ */
206
+ updateActiveCellCoordinates: PropTypes.func
178
207
  };
@@ -0,0 +1,11 @@
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
+ export { useMoveActiveCell } from './useMoveActiveCell';
8
+ export { useMultipleKeyTracking } from './useMultipleKeyTracking';
9
+ export { useResetSpreadsheetFocus } from './useResetSpreadsheetFocus';
10
+ export { useSpreadsheetOutsideClick } from './useSpreadsheetOutsideClick';
11
+ export { useSpreadsheetEdit } from './useSpreadsheetEdit';
@@ -0,0 +1,139 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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 { useEffect, useState } from 'react';
11
+ import { usePreviousValue } from '../../../global/js/hooks';
12
+ import { includesResourceKey } from '../utils/handleMultipleKeys';
13
+
14
+ var hasFocus = function hasFocus() {
15
+ return typeof document !== 'undefined' && document.hasFocus();
16
+ };
17
+
18
+ export var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
19
+ var ref = _ref.ref,
20
+ containerHasFocus = _ref.containerHasFocus,
21
+ isEditing = _ref.isEditing;
22
+
23
+ var _useState = useState(''),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ usingMac = _useState2[0],
26
+ setUsingMac = _useState2[1];
27
+
28
+ var _useState3 = useState(hasFocus),
29
+ _useState4 = _slicedToArray(_useState3, 2),
30
+ windowFocused = _useState4[0],
31
+ setWindowFocused = _useState4[1];
32
+
33
+ var _useState5 = useState([]),
34
+ _useState6 = _slicedToArray(_useState5, 2),
35
+ keysPressedList = _useState6[0],
36
+ setKeysPressedList = _useState6[1];
37
+
38
+ var previousState = usePreviousValue({
39
+ isEditing: isEditing,
40
+ windowFocused: windowFocused
41
+ }); // useEffect to check for window focus, if window loses focus
42
+ // we need to clear out the keysPressedList
43
+
44
+ useEffect(function () {
45
+ var userAgentString = window.navigator.userAgent;
46
+
47
+ if (userAgentString.includes('Macintosh')) {
48
+ setUsingMac(true);
49
+ } else {
50
+ setUsingMac(false);
51
+ }
52
+
53
+ setWindowFocused(hasFocus());
54
+
55
+ var onWindowFocus = function onWindowFocus() {
56
+ return setWindowFocused(true);
57
+ };
58
+
59
+ var onWindowBlur = function onWindowBlur() {
60
+ return setWindowFocused(false);
61
+ };
62
+
63
+ window.addEventListener('focus', onWindowFocus);
64
+ window.addEventListener('blur', onWindowBlur);
65
+ return function () {
66
+ window.removeEventListener('focus', onWindowFocus);
67
+ window.removeEventListener('blur', onWindowBlur);
68
+ };
69
+ }, []);
70
+ useEffect(function () {
71
+ if (containerHasFocus && !isEditing) {
72
+ ref.current.onkeydown = ref.current.onkeyup = function (event) {
73
+ // If keydown, we will add the new key to the keysPressedList array
74
+ if (event.type === 'keydown') {
75
+ // Prevent multiple keys of the same type being added to our keysPressedList array
76
+ if (keysPressedList.includes(event.code)) {
77
+ return;
78
+ } // Because keyup events are lost when using the Command key
79
+ // we need to remove the previously pressed keys so that we
80
+ // do not have keys in the pressed list that should not be
81
+
82
+
83
+ if (includesResourceKey(keysPressedList, usingMac) && keysPressedList.length > 1) {
84
+ var clonedKeys = _toConsumableArray(keysPressedList);
85
+
86
+ var filteredClonedKeys = clonedKeys.filter(function (item) {
87
+ return item === 'MetaLeft' || item === 'MetaRight';
88
+ });
89
+ filteredClonedKeys.push(event.code);
90
+ return setKeysPressedList(_toConsumableArray(new Set(filteredClonedKeys)));
91
+ }
92
+
93
+ var tempKeys = _toConsumableArray(keysPressedList);
94
+
95
+ tempKeys.push(event.code);
96
+ setKeysPressedList(_toConsumableArray(new Set(tempKeys)));
97
+ } // If keyup, we will remove the key from the keysPressedList array
98
+
99
+
100
+ if (event.type === 'keyup') {
101
+ var _tempKeys = _toConsumableArray(keysPressedList);
102
+
103
+ var filteredClone = _tempKeys.filter(function (item) {
104
+ return item !== event.code;
105
+ }); // Keyup events are lost on all other keys if a Meta key is used
106
+ // so to work around this behavior, we empty out all other keys
107
+ // from the keysPressedList array if we detect a Meta keyup event
108
+
109
+
110
+ if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
111
+ return setKeysPressedList([]);
112
+ }
113
+
114
+ setKeysPressedList(_toConsumableArray(new Set(filteredClone)));
115
+ }
116
+ };
117
+ }
118
+
119
+ if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
120
+ setKeysPressedList([]);
121
+ } // Remove handlers if the spreadsheet container loses focus
122
+ // or is currently in edit mode
123
+
124
+
125
+ if (!containerHasFocus || isEditing) {
126
+ ref.current.onkeydown = undefined;
127
+ ref.current.onkeyup = undefined;
128
+
129
+ if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
130
+ setKeysPressedList([]);
131
+ }
132
+ }
133
+ }, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
134
+ return {
135
+ keysPressedList: keysPressedList,
136
+ windowFocused: windowFocused,
137
+ usingMac: usingMac
138
+ };
139
+ };
@@ -7,8 +7,7 @@
7
7
  import { useEffect } from 'react';
8
8
  import { pkg } from '../../../settings';
9
9
  export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
10
- var activeKeys = _ref.activeKeys,
11
- _ref$blockClass = _ref.blockClass,
10
+ var _ref$blockClass = _ref.blockClass,
12
11
  blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
13
12
  focusedElement = _ref.focusedElement,
14
13
  removeActiveCell = _ref.removeActiveCell,
@@ -18,11 +17,10 @@ export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
18
17
  if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
19
18
  setContainerHasFocus(false);
20
19
  removeActiveCell();
21
- activeKeys.current = [];
22
20
  }
23
21
 
24
22
  if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
25
23
  setContainerHasFocus(true);
26
24
  }
27
- }, [focusedElement, removeActiveCell, activeKeys, blockClass, setContainerHasFocus]);
25
+ }, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
28
26
  };
@@ -0,0 +1,68 @@
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 { useEffect } from 'react';
8
+ import { px } from '@carbon/layout';
9
+ export var useSpreadsheetEdit = function useSpreadsheetEdit(_ref) {
10
+ var isEditing = _ref.isEditing,
11
+ rows = _ref.rows,
12
+ activeCellCoordinates = _ref.activeCellCoordinates,
13
+ activeCellRef = _ref.activeCellRef,
14
+ cellEditorRef = _ref.cellEditorRef,
15
+ cellEditorRulerRef = _ref.cellEditorRulerRef,
16
+ columns = _ref.columns,
17
+ defaultColumn = _ref.defaultColumn,
18
+ cellEditorValue = _ref.cellEditorValue;
19
+ useEffect(function () {
20
+ if (isEditing) {
21
+ var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
22
+
23
+ var cellProps = (_rows$activeCellCoord = rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row]) === null || _rows$activeCellCoord === void 0 ? void 0 : _rows$activeCellCoord.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column];
24
+ var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
25
+ var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
26
+ cellEditorRef.current.style.left = activeCellLeftPosition;
27
+ cellEditorRef.current.style.top = activeCellTopPosition;
28
+ cellEditorRef.current.style.display = 'block';
29
+ cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
30
+ cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
31
+ cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2 - 1, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
32
+
33
+ cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
34
+ (_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
35
+ var rulerWidth = cellEditorRulerRef.current.offsetWidth;
36
+ var cellWidth = activeCellRef.current.offsetWidth;
37
+
38
+ if (rulerWidth >= cellWidth) {
39
+ var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
40
+ var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
41
+ var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
42
+ var totalColumns = columns.length;
43
+ var totalRows = rows.length;
44
+ var totalMultiplierPossible = totalColumns - startingColumnPosition;
45
+ var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
46
+ cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
47
+ cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
48
+ cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
49
+ // Cell editor has reached max height, we need to add the scrolling back.
50
+ // We also need to subtract 1 to account for the fact that the cell editor
51
+ // is placed one pixel below the cell being edited to account for the border
52
+
53
+ if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
54
+ cellEditorRef.current.style.overflow = 'auto';
55
+ } else {
56
+ cellEditorRef.current.style.overflow = 'hidden';
57
+ }
58
+ }
59
+ }
60
+
61
+ if (!isEditing) {
62
+ cellEditorRef.current.style.overflow = 'hidden';
63
+ cellEditorRef.current.style.display = 'none';
64
+ cellEditorRef.current.blur();
65
+ activeCellRef.current.focus();
66
+ }
67
+ }, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn, cellEditorValue, activeCellRef, cellEditorRef, cellEditorRulerRef]);
68
+ };