@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
@@ -23,6 +23,8 @@ var _reactWindow = require("react-window");
23
23
 
24
24
  var _classnames = _interopRequireDefault(require("classnames"));
25
25
 
26
+ var _layout = require("@carbon/layout");
27
+
26
28
  var _settings = require("../../settings");
27
29
 
28
30
  var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
@@ -43,19 +45,20 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
43
45
 
44
46
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
45
47
 
46
- /**
47
- * Copyright IBM Corp. 2022, 2022
48
- *
49
- * This source code is licensed under the Apache-2.0 license found in the
50
- * LICENSE file in the root directory of this source tree.
51
- */
48
+ 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; }
49
+
50
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
+
52
52
  var blockClass = "".concat(_settings.pkg.prefix, "--data-spreadsheet");
53
53
  var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
54
54
  var columns = _ref.columns,
55
55
  activeCellCoordinates = _ref.activeCellCoordinates,
56
56
  defaultColumn = _ref.defaultColumn,
57
+ defaultEmptyRowCount = _ref.defaultEmptyRowCount,
57
58
  getTableBodyProps = _ref.getTableBodyProps,
59
+ headerGroups = _ref.headerGroups,
58
60
  id = _ref.id,
61
+ onDataUpdate = _ref.onDataUpdate,
59
62
  prepareRow = _ref.prepareRow,
60
63
  rows = _ref.rows,
61
64
  selectionAreaData = _ref.selectionAreaData,
@@ -70,11 +73,16 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
70
73
  setClickAndHoldActive = _ref.setClickAndHoldActive,
71
74
  currentMatcher = _ref.currentMatcher,
72
75
  setCurrentMatcher = _ref.setCurrentMatcher,
73
- onSelectionAreaChange = _ref.onSelectionAreaChange;
76
+ onSelectionAreaChange = _ref.onSelectionAreaChange,
77
+ setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
74
78
  var previousState = (0, _hooks.usePreviousValue)({
75
79
  selectionAreaData: selectionAreaData,
76
80
  clickAndHoldActive: clickAndHoldActive
77
- }); // Call the `onSelectionAreaChange` handler to send selection area data
81
+ }); // Set custom css property containing the spreadsheet total width
82
+
83
+ (0, _react.useEffect)(function () {
84
+ ref === null || ref === void 0 ? void 0 : ref.current.style.setProperty("--".concat(blockClass, "--total-width"), (0, _layout.px)(totalColumnsWidth + scrollBarSize));
85
+ }, [ref, scrollBarSize, totalColumnsWidth]); // Call the `onSelectionAreaChange` handler to send selection area data
78
86
  // back to the consumer
79
87
 
80
88
  (0, _react.useEffect)(function () {
@@ -124,18 +132,20 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
124
132
 
125
133
  if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
126
134
  (0, _createCellSelectionArea.createCellSelectionArea)({
135
+ ref: ref,
127
136
  area: area,
128
137
  blockClass: blockClass,
129
138
  defaultColumn: defaultColumn,
130
139
  selectionAreas: selectionAreas,
131
- setSelectionAreas: setSelectionAreas
140
+ setSelectionAreas: setSelectionAreas,
141
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
132
142
  });
133
143
  }
134
144
 
135
145
  return;
136
146
  });
137
147
  }
138
- }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
148
+ }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
139
149
 
140
150
  var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
141
151
  var rowStart = _ref2.rowStart,
@@ -213,6 +223,9 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
213
223
  // meaning that selectionAreas should only have one item by default
214
224
 
215
225
  if (isHoldingCommandKey) {
226
+ var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
227
+ activeCellElement.setAttribute('data-selection-id', tempMatcher);
228
+ setActiveCellInsideSelectionArea(true);
216
229
  setActiveCellCoordinates(activeCoordinates);
217
230
  setCurrentMatcher(tempMatcher);
218
231
  setSelectionAreas(function (prev) {
@@ -243,6 +256,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
243
256
  setSelectionAreas(selectionAreaClone);
244
257
  }
245
258
  } else {
259
+ setActiveCellInsideSelectionArea(false);
246
260
  setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
247
261
 
248
262
  (0, _removeCellSelections.removeCellSelections)({
@@ -256,7 +270,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
256
270
  setSelectionAreaData([]);
257
271
  }
258
272
  };
259
- }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
273
+ }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
260
274
  var handleBodyCellHover = (0, _react.useCallback)(function (cell, columnIndex) {
261
275
  return function () {
262
276
  if (clickAndHoldActive) {
@@ -289,7 +303,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
289
303
  };
290
304
  }, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
291
305
  var handleRowHeaderClick = (0, _react.useCallback)(function (index) {
292
- return function () {
306
+ return function (event) {
307
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
293
308
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)({
294
309
  type: 'row',
295
310
  activeCellCoordinates: activeCellCoordinates,
@@ -300,45 +315,86 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
300
315
  setSelectionAreas: setSelectionAreas,
301
316
  spreadsheetRef: ref,
302
317
  index: index,
303
- setSelectionAreaData: setSelectionAreaData
318
+ setSelectionAreaData: setSelectionAreaData,
319
+ isHoldingCommandKey: isHoldingCommandKey
304
320
  });
305
321
  };
306
- }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Renders each row/cell in the spreadsheet body
322
+ }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
323
+ // using defaultEmptyRowCount to determine how many empty rows are created.
324
+
325
+ (0, _react.useEffect)(function () {
326
+ if (!(rows !== null && rows !== void 0 && rows.length)) {
327
+ var buildEmptyRows = function buildEmptyRows() {
328
+ var emptyRowData = [];
329
+ (0, _toConsumableArray2.default)(Array(defaultEmptyRowCount)).map(function () {
330
+ var _headerGroups$;
331
+
332
+ var emptyCell = {};
333
+ (_headerGroups$ = headerGroups[0]) === null || _headerGroups$ === void 0 ? void 0 : _headerGroups$.headers.map(function (header) {
334
+ emptyCell[header.id] = null;
335
+ });
336
+ emptyRowData.push(emptyCell);
337
+ });
338
+ onDataUpdate(emptyRowData);
339
+ };
340
+
341
+ buildEmptyRows();
342
+ }
343
+ }, [rows, headerGroups, defaultEmptyRowCount, onDataUpdate]);
344
+
345
+ var RenderEmptyRows = function RenderEmptyRows() {
346
+ return /*#__PURE__*/_react.default.createElement("div", null);
347
+ }; // Renders each row/cell in the spreadsheet body
348
+
307
349
 
308
350
  var RenderRow = (0, _react.useCallback)(function (_ref3) {
309
351
  var index = _ref3.index,
310
352
  style = _ref3.style;
311
353
  var row = rows[index];
312
- prepareRow(row);
313
- return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, row.getRowProps({
314
- style: style
315
- }), {
316
- className: (0, _classnames.default)("".concat(blockClass, "__tr")),
317
- "data-row-index": index
318
- }), /*#__PURE__*/_react.default.createElement("button", {
319
- tabIndex: -1,
320
- "data-row-index": index,
321
- "data-column-index": "header",
322
- type: "button",
323
- onClick: handleRowHeaderClick(index),
324
- className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'row'))),
325
- style: {
326
- width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
327
- }
328
- }, index + 1), row.cells.map(function (cell, index) {
329
- return /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
354
+
355
+ if (rows && rows.length) {
356
+ prepareRow(row);
357
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, row.getRowProps({
358
+ style: style
359
+ }), {
360
+ className: (0, _classnames.default)("".concat(blockClass, "__tr")),
361
+ "data-row-index": index,
362
+ "aria-rowindex": index + 1
363
+ }), /*#__PURE__*/_react.default.createElement("div", {
364
+ role: "rowheader"
365
+ }, /*#__PURE__*/_react.default.createElement("button", {
366
+ id: "".concat(blockClass, "__cell--").concat(index, "--header"),
330
367
  tabIndex: -1,
331
- "data-row-index": cell.row.index,
332
- "data-column-index": index
333
- }, cell.getCellProps(), {
334
- className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
335
- key: "cell_".concat(index),
336
- onMouseDown: handleBodyCellClick(cell, index),
337
- onMouseOver: handleBodyCellHover(cell, index),
338
- onFocus: function onFocus() {},
339
- type: "button"
340
- }), cell.render('Cell'));
341
- }));
368
+ "data-row-index": index,
369
+ "data-column-index": "header",
370
+ type: "button",
371
+ onClick: handleRowHeaderClick(index),
372
+ className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'row'))),
373
+ style: {
374
+ width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4
375
+ }
376
+ }, index + 1)), row.cells.map(function (cell, index) {
377
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
378
+ key: "cell_".concat(index),
379
+ "aria-colindex": index + 1
380
+ }, cell.getCellProps(), {
381
+ role: "gridcell",
382
+ style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
383
+ display: 'grid'
384
+ })
385
+ }), /*#__PURE__*/_react.default.createElement("button", {
386
+ id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
387
+ tabIndex: -1,
388
+ "data-row-index": cell.row.index,
389
+ "data-column-index": index,
390
+ className: (0, _classnames.default)("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
391
+ onMouseDown: handleBodyCellClick(cell, index),
392
+ onMouseOver: handleBodyCellHover(cell, index),
393
+ onFocus: function onFocus() {},
394
+ type: "button"
395
+ }, cell.render('Cell')));
396
+ }));
397
+ }
342
398
  }, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
343
399
  var spreadsheetBodyRef = (0, _react.useRef)();
344
400
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
@@ -347,10 +403,10 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
347
403
  }, getTableBodyProps()), /*#__PURE__*/_react.default.createElement(_reactWindow.FixedSizeList, {
348
404
  className: (0, _classnames.default)("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
349
405
  height: 400,
350
- itemCount: rows.length,
406
+ itemCount: rows.length || defaultEmptyRowCount,
351
407
  itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
352
408
  width: totalColumnsWidth + scrollBarSize
353
- }, RenderRow));
409
+ }, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
354
410
  });
355
411
  exports.DataSpreadsheetBody = DataSpreadsheetBody;
356
412
  DataSpreadsheetBody.propTypes = {
@@ -386,11 +442,21 @@ DataSpreadsheetBody.propTypes = {
386
442
  width: _propTypes.default.number
387
443
  }),
388
444
 
445
+ /**
446
+ * Sets the number of empty rows to be created when there is no data provided
447
+ */
448
+ defaultEmptyRowCount: _propTypes.default.number,
449
+
389
450
  /**
390
451
  * Function to set table body prop values
391
452
  */
392
453
  getTableBodyProps: _propTypes.default.func,
393
454
 
455
+ /**
456
+ * Headers provided from useTable hook
457
+ */
458
+ headerGroups: _propTypes.default.arrayOf(_propTypes.default.object),
459
+
394
460
  /**
395
461
  * The spreadsheet id
396
462
  */
@@ -401,6 +467,11 @@ DataSpreadsheetBody.propTypes = {
401
467
  */
402
468
  onActiveCellChange: _propTypes.default.func,
403
469
 
470
+ /**
471
+ * The event handler that is called to set the rows for the empty spreadsheet
472
+ */
473
+ onDataUpdate: _propTypes.default.func,
474
+
404
475
  /**
405
476
  * The event handler that is called when the selection areas change
406
477
  */
@@ -436,6 +507,11 @@ DataSpreadsheetBody.propTypes = {
436
507
  */
437
508
  setActiveCellCoordinates: _propTypes.default.func,
438
509
 
510
+ /**
511
+ * Setter fn for active cell inside of selection area
512
+ */
513
+ setActiveCellInsideSelectionArea: _propTypes.default.func,
514
+
439
515
  /**
440
516
  * Setter fn for clickAndHold state value
441
517
  */
@@ -25,11 +25,13 @@ var _layout = require("@carbon/layout");
25
25
 
26
26
  var _settings = require("../../settings");
27
27
 
28
+ var _hooks = require("../../global/js/hooks");
29
+
28
30
  var _checkActiveHeaderCell = require("./utils/checkActiveHeaderCell");
29
31
 
30
32
  var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
31
33
 
32
- var _hooks = require("../../global/js/hooks");
34
+ var _selectAllCells = require("./utils/selectAllCells");
33
35
 
34
36
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
37
 
@@ -52,7 +54,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
52
54
  setCurrentMatcher = _ref.setCurrentMatcher,
53
55
  setSelectionAreas = _ref.setSelectionAreas,
54
56
  setSelectionAreaData = _ref.setSelectionAreaData,
55
- rows = _ref.rows;
57
+ rows = _ref.rows,
58
+ updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
56
59
 
57
60
  var _useState = (0, _react.useState)(0),
58
61
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -74,7 +77,8 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
74
77
  }, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
75
78
 
76
79
  var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
77
- return function () {
80
+ return function (event) {
81
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
78
82
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)({
79
83
  type: 'column',
80
84
  activeCellCoordinates: activeCellCoordinates,
@@ -85,13 +89,27 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
85
89
  setSelectionAreas: setSelectionAreas,
86
90
  spreadsheetRef: ref,
87
91
  index: index,
88
- setSelectionAreaData: setSelectionAreaData
92
+ setSelectionAreaData: setSelectionAreaData,
93
+ isHoldingCommandKey: isHoldingCommandKey
89
94
  });
90
95
  };
91
96
  };
92
97
 
98
+ var handleSelectAllClick = function handleSelectAllClick() {
99
+ (0, _selectAllCells.selectAllCells)({
100
+ ref: ref,
101
+ setCurrentMatcher: setCurrentMatcher,
102
+ setSelectionAreas: setSelectionAreas,
103
+ rows: rows,
104
+ columns: columns,
105
+ activeCellCoordinates: activeCellCoordinates,
106
+ updateActiveCellCoordinates: updateActiveCellCoordinates
107
+ });
108
+ };
109
+
93
110
  return /*#__PURE__*/_react.default.createElement("div", {
94
- className: (0, _classnames.default)("".concat(blockClass, "__header--container"))
111
+ className: (0, _classnames.default)("".concat(blockClass, "__header--container")),
112
+ role: "rowgroup"
95
113
  }, headerGroups.map(function (headerGroup, index) {
96
114
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
97
115
  key: "header_".concat(index)
@@ -100,30 +118,37 @@ var DataSpreadsheetHeader = /*#__PURE__*/(0, _react.forwardRef)(function (_ref,
100
118
  width: (0, _layout.px)(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
101
119
  }),
102
120
  className: "".concat(blockClass, "__tr")
103
- }), /*#__PURE__*/_react.default.createElement("button", {
121
+ }), /*#__PURE__*/_react.default.createElement("div", {
122
+ role: "columnheader",
123
+ style: {
124
+ width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4,
125
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
126
+ }
127
+ }, /*#__PURE__*/_react.default.createElement("button", {
128
+ id: "".concat(blockClass, "__cell--header--header"),
104
129
  "data-row-index": "header",
105
130
  "data-column-index": "header",
106
131
  type: "button",
107
132
  tabIndex: -1,
108
- className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".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')),
109
- style: {
110
- width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
111
- height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
112
- }
113
- }, "\xA0"), headerGroup.headers.map(function (column, index) {
114
- return /*#__PURE__*/_react.default.createElement("button", (0, _extends2.default)({
133
+ onClick: handleSelectAllClick,
134
+ className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__th--select-all"), (0, _defineProperty2.default)({}, "".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'))
135
+ }, "\xA0")), headerGroup.headers.map(function (column, index) {
136
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
115
137
  key: "column_".concat(index),
138
+ role: "columnheader",
139
+ className: "".concat(blockClass, "__columnheader")
140
+ }, column.getHeaderProps()), /*#__PURE__*/_react.default.createElement("button", {
141
+ id: "".concat(blockClass, "__cell--header--").concat(index),
116
142
  "data-row-index": "header",
117
143
  "data-column-index": index,
118
144
  tabIndex: -1,
119
145
  onClick: handleColumnHeaderClick(index),
120
146
  style: {
121
147
  height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
122
- }
123
- }, column.getHeaderProps(), {
148
+ },
124
149
  className: (0, _classnames.default)("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || (0, _checkActiveHeaderCell.checkActiveHeaderCell)(index, selectionAreas, 'column'))),
125
150
  type: "button"
126
- }), column.render('Header'));
151
+ }, column.render('Header')));
127
152
  }));
128
153
  }));
129
154
  });
@@ -194,5 +219,10 @@ DataSpreadsheetHeader.propTypes = {
194
219
  /**
195
220
  * Setter fn for selectionAreas value
196
221
  */
197
- setSelectionAreas: _propTypes.default.func
222
+ setSelectionAreas: _propTypes.default.func,
223
+
224
+ /**
225
+ * Function used to update the active cell coordinates
226
+ */
227
+ updateActiveCellCoordinates: _propTypes.default.func
198
228
  };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useMoveActiveCell", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _useMoveActiveCell.useMoveActiveCell;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "useMultipleKeyTracking", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _useMultipleKeyTracking.useMultipleKeyTracking;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "useResetSpreadsheetFocus", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _useResetSpreadsheetFocus.useResetSpreadsheetFocus;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useSpreadsheetEdit", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _useSpreadsheetEdit.useSpreadsheetEdit;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "useSpreadsheetOutsideClick", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _useSpreadsheetOutsideClick.useSpreadsheetOutsideClick;
34
+ }
35
+ });
36
+
37
+ var _useMoveActiveCell = require("./useMoveActiveCell");
38
+
39
+ var _useMultipleKeyTracking = require("./useMultipleKeyTracking");
40
+
41
+ var _useResetSpreadsheetFocus = require("./useResetSpreadsheetFocus");
42
+
43
+ var _useSpreadsheetOutsideClick = require("./useSpreadsheetOutsideClick");
44
+
45
+ var _useSpreadsheetEdit = require("./useSpreadsheetEdit");
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useMultipleKeyTracking = void 0;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
+
14
+ var _react = require("react");
15
+
16
+ var _hooks = require("../../../global/js/hooks");
17
+
18
+ var _handleMultipleKeys = require("../utils/handleMultipleKeys");
19
+
20
+ /**
21
+ * Copyright IBM Corp. 2022, 2022
22
+ *
23
+ * This source code is licensed under the Apache-2.0 license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ */
26
+ var hasFocus = function hasFocus() {
27
+ return typeof document !== 'undefined' && document.hasFocus();
28
+ };
29
+
30
+ var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
31
+ var ref = _ref.ref,
32
+ containerHasFocus = _ref.containerHasFocus,
33
+ isEditing = _ref.isEditing;
34
+
35
+ var _useState = (0, _react.useState)(''),
36
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
+ usingMac = _useState2[0],
38
+ setUsingMac = _useState2[1];
39
+
40
+ var _useState3 = (0, _react.useState)(hasFocus),
41
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
42
+ windowFocused = _useState4[0],
43
+ setWindowFocused = _useState4[1];
44
+
45
+ var _useState5 = (0, _react.useState)([]),
46
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
47
+ keysPressedList = _useState6[0],
48
+ setKeysPressedList = _useState6[1];
49
+
50
+ var previousState = (0, _hooks.usePreviousValue)({
51
+ isEditing: isEditing,
52
+ windowFocused: windowFocused
53
+ }); // useEffect to check for window focus, if window loses focus
54
+ // we need to clear out the keysPressedList
55
+
56
+ (0, _react.useEffect)(function () {
57
+ var userAgentString = window.navigator.userAgent;
58
+
59
+ if (userAgentString.includes('Macintosh')) {
60
+ setUsingMac(true);
61
+ } else {
62
+ setUsingMac(false);
63
+ }
64
+
65
+ setWindowFocused(hasFocus());
66
+
67
+ var onWindowFocus = function onWindowFocus() {
68
+ return setWindowFocused(true);
69
+ };
70
+
71
+ var onWindowBlur = function onWindowBlur() {
72
+ return setWindowFocused(false);
73
+ };
74
+
75
+ window.addEventListener('focus', onWindowFocus);
76
+ window.addEventListener('blur', onWindowBlur);
77
+ return function () {
78
+ window.removeEventListener('focus', onWindowFocus);
79
+ window.removeEventListener('blur', onWindowBlur);
80
+ };
81
+ }, []);
82
+ (0, _react.useEffect)(function () {
83
+ if (containerHasFocus && !isEditing) {
84
+ ref.current.onkeydown = ref.current.onkeyup = function (event) {
85
+ // If keydown, we will add the new key to the keysPressedList array
86
+ if (event.type === 'keydown') {
87
+ // Prevent multiple keys of the same type being added to our keysPressedList array
88
+ if (keysPressedList.includes(event.code)) {
89
+ return;
90
+ } // Because keyup events are lost when using the Command key
91
+ // we need to remove the previously pressed keys so that we
92
+ // do not have keys in the pressed list that should not be
93
+
94
+
95
+ if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac) && keysPressedList.length > 1) {
96
+ var clonedKeys = (0, _toConsumableArray2.default)(keysPressedList);
97
+ var filteredClonedKeys = clonedKeys.filter(function (item) {
98
+ return item === 'MetaLeft' || item === 'MetaRight';
99
+ });
100
+ filteredClonedKeys.push(event.code);
101
+ return setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClonedKeys)));
102
+ }
103
+
104
+ var tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
105
+ tempKeys.push(event.code);
106
+ setKeysPressedList((0, _toConsumableArray2.default)(new Set(tempKeys)));
107
+ } // If keyup, we will remove the key from the keysPressedList array
108
+
109
+
110
+ if (event.type === 'keyup') {
111
+ var _tempKeys = (0, _toConsumableArray2.default)(keysPressedList);
112
+
113
+ var filteredClone = _tempKeys.filter(function (item) {
114
+ return item !== event.code;
115
+ }); // Keyup events are lost on all other keys if a Meta key is used
116
+ // so to work around this behavior, we empty out all other keys
117
+ // from the keysPressedList array if we detect a Meta keyup event
118
+
119
+
120
+ if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
121
+ return setKeysPressedList([]);
122
+ }
123
+
124
+ setKeysPressedList((0, _toConsumableArray2.default)(new Set(filteredClone)));
125
+ }
126
+ };
127
+ }
128
+
129
+ if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
130
+ setKeysPressedList([]);
131
+ } // Remove handlers if the spreadsheet container loses focus
132
+ // or is currently in edit mode
133
+
134
+
135
+ if (!containerHasFocus || isEditing) {
136
+ ref.current.onkeydown = undefined;
137
+ ref.current.onkeyup = undefined;
138
+
139
+ if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
140
+ setKeysPressedList([]);
141
+ }
142
+ }
143
+ }, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
144
+ return {
145
+ keysPressedList: keysPressedList,
146
+ windowFocused: windowFocused,
147
+ usingMac: usingMac
148
+ };
149
+ };
150
+
151
+ exports.useMultipleKeyTracking = useMultipleKeyTracking;
@@ -16,8 +16,7 @@ var _settings = require("../../../settings");
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  */
18
18
  var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
19
- var activeKeys = _ref.activeKeys,
20
- _ref$blockClass = _ref.blockClass,
19
+ var _ref$blockClass = _ref.blockClass,
21
20
  blockClass = _ref$blockClass === void 0 ? "".concat(_settings.pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
22
21
  focusedElement = _ref.focusedElement,
23
22
  removeActiveCell = _ref.removeActiveCell,
@@ -27,13 +26,12 @@ var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
27
26
  if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
28
27
  setContainerHasFocus(false);
29
28
  removeActiveCell();
30
- activeKeys.current = [];
31
29
  }
32
30
 
33
31
  if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
34
32
  setContainerHasFocus(true);
35
33
  }
36
- }, [focusedElement, removeActiveCell, activeKeys, blockClass, setContainerHasFocus]);
34
+ }, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
37
35
  };
38
36
 
39
37
  exports.useResetSpreadsheetFocus = useResetSpreadsheetFocus;