@carbon/ibm-products 1.11.2 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/README.md +0 -3
  2. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +47 -0
  3. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +1 -0
  4. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +20 -0
  5. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +1 -0
  6. package/css/components/Datagrid/styles/datagrid.css +264 -0
  7. package/css/components/Datagrid/styles/datagrid.css.map +1 -0
  8. package/css/components/Datagrid/styles/index.css +509 -0
  9. package/css/components/Datagrid/styles/index.css.map +1 -0
  10. package/css/components/Datagrid/styles/useActionsColumn.css +23 -0
  11. package/css/components/Datagrid/styles/useActionsColumn.css.map +1 -0
  12. package/css/components/Datagrid/styles/useColumnRightAlign.css +28 -0
  13. package/css/components/Datagrid/styles/useColumnRightAlign.css.map +1 -0
  14. package/css/components/Datagrid/styles/useNestedRows.css +15 -0
  15. package/css/components/Datagrid/styles/useNestedRows.css.map +1 -0
  16. package/css/components/Datagrid/styles/useNestedTable.css +25 -0
  17. package/css/components/Datagrid/styles/useNestedTable.css.map +1 -0
  18. package/css/components/Datagrid/styles/useSelectAllToggle.css +28 -0
  19. package/css/components/Datagrid/styles/useSelectAllToggle.css.map +1 -0
  20. package/css/components/Datagrid/styles/useSortableColumns.css +50 -0
  21. package/css/components/Datagrid/styles/useSortableColumns.css.map +1 -0
  22. package/css/components/Datagrid/styles/useStickyColumn.css +35 -0
  23. package/css/components/Datagrid/styles/useStickyColumn.css.map +1 -0
  24. package/css/index-full-carbon.css +2019 -376
  25. package/css/index-full-carbon.css.map +1 -1
  26. package/css/index-full-carbon.min.css +6 -6
  27. package/css/index-full-carbon.min.css.map +1 -1
  28. package/css/index-without-carbon-released-only.css +18 -6
  29. package/css/index-without-carbon-released-only.css.map +1 -1
  30. package/css/index-without-carbon-released-only.min.css +2 -2
  31. package/css/index-without-carbon-released-only.min.css.map +1 -1
  32. package/css/index-without-carbon.css +679 -19
  33. package/css/index-without-carbon.css.map +1 -1
  34. package/css/index-without-carbon.min.css +5 -5
  35. package/css/index-without-carbon.min.css.map +1 -1
  36. package/css/index.css +679 -19
  37. package/css/index.css.map +1 -1
  38. package/css/index.min.css +6 -6
  39. package/css/index.min.css.map +1 -1
  40. package/es/components/ActionBar/ActionBar.js +3 -1
  41. package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
  42. package/es/components/AddSelect/AddSelect.js +133 -30
  43. package/es/components/AddSelect/AddSelectColumn.js +0 -1
  44. package/es/components/AddSelect/AddSelectFilter.js +129 -0
  45. package/es/components/AddSelect/AddSelectList.js +59 -13
  46. package/es/components/AddSelect/AddSelectSidebar.js +15 -5
  47. package/es/components/AddSelect/add-select-utils.js +30 -0
  48. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  49. package/es/components/DataSpreadsheet/DataSpreadsheet.js +262 -164
  50. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +191 -51
  51. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +65 -13
  52. package/es/components/DataSpreadsheet/hooks/index.js +10 -0
  53. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +111 -0
  54. package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  55. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -6
  56. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
  57. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +80 -6
  58. package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
  59. package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
  60. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
  61. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
  62. package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
  63. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
  64. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
  65. package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
  66. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
  67. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
  68. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
  69. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
  70. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
  71. package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
  72. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
  73. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
  74. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
  75. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
  76. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
  77. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
  78. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
  79. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
  80. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
  81. package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
  82. package/es/components/Datagrid/Datagrid/index.js +8 -0
  83. package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
  84. package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
  85. package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
  86. package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
  87. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
  88. package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
  89. package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
  90. package/es/components/Datagrid/common-column-ids.js +8 -0
  91. package/es/components/Datagrid/index.js +22 -0
  92. package/es/components/Datagrid/useActionsColumn.js +86 -0
  93. package/es/components/Datagrid/useColumnRightAlign.js +52 -0
  94. package/es/components/Datagrid/useCustomizeColumns.js +45 -0
  95. package/es/components/Datagrid/useDatagrid.js +44 -0
  96. package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
  97. package/es/components/Datagrid/useDisableSelectRows.js +84 -0
  98. package/es/components/Datagrid/useExpandedRow.js +52 -0
  99. package/es/components/Datagrid/useFlexResize.js +51 -0
  100. package/es/components/Datagrid/useFloatingScroll.js +88 -0
  101. package/es/components/Datagrid/useInfiniteScroll.js +54 -0
  102. package/es/components/Datagrid/useNestedRows.js +53 -0
  103. package/es/components/Datagrid/useOnRowClick.js +37 -0
  104. package/es/components/Datagrid/useParentDimensions.js +65 -0
  105. package/es/components/Datagrid/useResizeTable.js +40 -0
  106. package/es/components/Datagrid/useRowExpander.js +34 -0
  107. package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
  108. package/es/components/Datagrid/useRowRenderer.js +30 -0
  109. package/es/components/Datagrid/useRowSize.js +56 -0
  110. package/es/components/Datagrid/useSelectAllToggle.js +74 -0
  111. package/es/components/Datagrid/useSelectRows.js +107 -0
  112. package/es/components/Datagrid/useSkeletonRows.js +32 -0
  113. package/es/components/Datagrid/useSortableColumns.js +110 -0
  114. package/es/components/Datagrid/useStickyColumn.js +183 -0
  115. package/es/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  116. package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  117. package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  118. package/es/components/ImportModal/ImportModal.js +2 -2
  119. package/es/components/TagSet/TagSet.js +12 -3
  120. package/es/components/UserProfileImage/UserProfileImage.js +38 -10
  121. package/es/components/index.js +2 -1
  122. package/es/global/js/package-settings.js +2 -1
  123. package/lib/components/ActionBar/ActionBar.js +3 -1
  124. package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
  125. package/lib/components/AddSelect/AddSelect.js +132 -28
  126. package/lib/components/AddSelect/AddSelectColumn.js +0 -1
  127. package/lib/components/AddSelect/AddSelectFilter.js +147 -0
  128. package/lib/components/AddSelect/AddSelectList.js +61 -12
  129. package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
  130. package/lib/components/AddSelect/add-select-utils.js +35 -2
  131. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  132. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +267 -168
  133. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +191 -57
  134. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +67 -18
  135. package/lib/components/DataSpreadsheet/hooks/index.js +37 -0
  136. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +123 -0
  137. package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  138. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -5
  139. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
  140. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +83 -7
  141. package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
  142. package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
  143. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
  144. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
  145. package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
  146. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
  147. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
  148. package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
  149. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
  150. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
  151. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
  152. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
  153. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
  154. package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
  155. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
  156. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
  157. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
  158. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
  159. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
  160. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
  161. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
  162. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
  163. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
  164. package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
  165. package/lib/components/Datagrid/Datagrid/index.js +15 -0
  166. package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
  167. package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
  168. package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
  169. package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
  170. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
  171. package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
  172. package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
  173. package/lib/components/Datagrid/common-column-ids.js +16 -0
  174. package/lib/components/Datagrid/index.js +127 -0
  175. package/lib/components/Datagrid/useActionsColumn.js +94 -0
  176. package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
  177. package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
  178. package/lib/components/Datagrid/useDatagrid.js +58 -0
  179. package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
  180. package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
  181. package/lib/components/Datagrid/useExpandedRow.js +58 -0
  182. package/lib/components/Datagrid/useFlexResize.js +61 -0
  183. package/lib/components/Datagrid/useFloatingScroll.js +101 -0
  184. package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
  185. package/lib/components/Datagrid/useNestedRows.js +65 -0
  186. package/lib/components/Datagrid/useOnRowClick.js +45 -0
  187. package/lib/components/Datagrid/useParentDimensions.js +75 -0
  188. package/lib/components/Datagrid/useResizeTable.js +48 -0
  189. package/lib/components/Datagrid/useRowExpander.js +45 -0
  190. package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
  191. package/lib/components/Datagrid/useRowRenderer.js +40 -0
  192. package/lib/components/Datagrid/useRowSize.js +67 -0
  193. package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
  194. package/lib/components/Datagrid/useSelectRows.js +119 -0
  195. package/lib/components/Datagrid/useSkeletonRows.js +42 -0
  196. package/lib/components/Datagrid/useSortableColumns.js +117 -0
  197. package/lib/components/Datagrid/useStickyColumn.js +190 -0
  198. package/lib/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  199. package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  200. package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  201. package/lib/components/ImportModal/ImportModal.js +1 -1
  202. package/lib/components/TagSet/TagSet.js +12 -3
  203. package/lib/components/UserProfileImage/UserProfileImage.js +38 -10
  204. package/lib/components/index.js +9 -1
  205. package/lib/global/js/package-settings.js +2 -1
  206. package/package.json +19 -15
  207. package/scss/components/AboutModal/_about-modal.scss +2 -2
  208. package/scss/components/ActionSet/_action-set.scss +3 -1
  209. package/scss/components/AddSelect/_add-select.scss +87 -3
  210. package/scss/components/CreateModal/_create-modal.scss +7 -5
  211. package/scss/components/CreateModal/_storybook-styles.scss +8 -7
  212. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +70 -10
  213. package/scss/components/Datagrid/_datagrid.scss +66 -0
  214. package/scss/components/Datagrid/_index.scss +8 -0
  215. package/scss/components/Datagrid/_storybook-styles.scss +26 -0
  216. package/scss/components/Datagrid/styles/_variables.scss +9 -0
  217. package/scss/components/Datagrid/styles/addons/CustomizeColumnsModal.scss +48 -0
  218. package/scss/components/Datagrid/styles/addons/RowSizeDropdown.scss +23 -0
  219. package/scss/components/Datagrid/styles/datagrid.scss +318 -0
  220. package/scss/components/Datagrid/styles/index.scss +17 -0
  221. package/scss/components/Datagrid/styles/useActionsColumn.scss +24 -0
  222. package/scss/components/Datagrid/styles/useColumnRightAlign.scss +29 -0
  223. package/scss/components/Datagrid/styles/useNestedRows.scss +17 -0
  224. package/scss/components/Datagrid/styles/useNestedTable.scss +28 -0
  225. package/scss/components/Datagrid/styles/useSelectAllToggle.scss +28 -0
  226. package/scss/components/Datagrid/styles/useSortableColumns.scss +55 -0
  227. package/scss/components/Datagrid/styles/useStickyColumn.scss +38 -0
  228. package/scss/components/ExportModal/_export-modal.scss +3 -3
  229. package/scss/components/HTTPErrors/_http-errors.scss +16 -16
  230. package/scss/components/InlineEdit/_inline-edit.scss +0 -1
  231. package/scss/components/ModifiedTabs/_modified-tabs.scss +0 -10
  232. package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -3
  233. package/scss/components/OptionsTile/_options-tile.scss +0 -1
  234. package/scss/components/PageHeader/_page-header.scss +4 -0
  235. package/scss/components/RemoveModal/_remove-modal.scss +3 -3
  236. package/scss/components/TagSet/_tag-set.scss +2 -1
  237. package/scss/components/Tearsheet/_tearsheet.scss +5 -2
  238. 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,9 +16,11 @@ 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';
23
+ import { usePreviousValue } from '../../global/js/hooks';
18
24
  import { removeCellSelections } from './utils/removeCellSelections';
19
25
  import { createCellSelectionArea } from './utils/createCellSelectionArea';
20
26
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
@@ -24,10 +30,15 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
24
30
  var columns = _ref.columns,
25
31
  activeCellCoordinates = _ref.activeCellCoordinates,
26
32
  defaultColumn = _ref.defaultColumn,
33
+ defaultEmptyRowCount = _ref.defaultEmptyRowCount,
27
34
  getTableBodyProps = _ref.getTableBodyProps,
35
+ headerGroups = _ref.headerGroups,
28
36
  id = _ref.id,
37
+ onDataUpdate = _ref.onDataUpdate,
29
38
  prepareRow = _ref.prepareRow,
30
39
  rows = _ref.rows,
40
+ selectionAreaData = _ref.selectionAreaData,
41
+ setSelectionAreaData = _ref.setSelectionAreaData,
31
42
  setActiveCellCoordinates = _ref.setActiveCellCoordinates,
32
43
  selectionAreas = _ref.selectionAreas,
33
44
  setContainerHasFocus = _ref.setContainerHasFocus,
@@ -37,24 +48,64 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
37
48
  clickAndHoldActive = _ref.clickAndHoldActive,
38
49
  setClickAndHoldActive = _ref.setClickAndHoldActive,
39
50
  currentMatcher = _ref.currentMatcher,
40
- setCurrentMatcher = _ref.setCurrentMatcher;
41
- // Create cell selection areas based on selectionAreas array
51
+ setCurrentMatcher = _ref.setCurrentMatcher,
52
+ onSelectionAreaChange = _ref.onSelectionAreaChange;
53
+ var previousState = usePreviousValue({
54
+ selectionAreaData: selectionAreaData,
55
+ clickAndHoldActive: clickAndHoldActive
56
+ }); // Set custom css property containing the spreadsheet total width
57
+
58
+ useEffect(function () {
59
+ ref === null || ref === void 0 ? void 0 : ref.current.style.setProperty("--".concat(blockClass, "--total-width"), px(totalColumnsWidth + scrollBarSize));
60
+ }, [ref, scrollBarSize, totalColumnsWidth]); // Call the `onSelectionAreaChange` handler to send selection area data
61
+ // back to the consumer
62
+
63
+ useEffect(function () {
64
+ if (selectionAreaData.length) {
65
+ var _previousState$select;
66
+
67
+ if (!clickAndHoldActive && previousState !== null && previousState !== void 0 && previousState.clickAndHoldActive || (previousState === null || previousState === void 0 ? void 0 : (_previousState$select = previousState.selectionAreaData) === null || _previousState$select === void 0 ? void 0 : _previousState$select.length) !== (selectionAreaData === null || selectionAreaData === void 0 ? void 0 : selectionAreaData.length)) {
68
+ onSelectionAreaChange(selectionAreaData);
69
+ }
70
+ }
71
+ }, [previousState === null || previousState === void 0 ? void 0 : previousState.selectionAreaData, selectionAreaData, onSelectionAreaChange, clickAndHoldActive, previousState === null || previousState === void 0 ? void 0 : previousState.clickAndHoldActive]); // Create cell selection areas based on selectionAreas array
72
+
42
73
  useEffect(function () {
43
74
  if (selectionAreas && selectionAreas.length) {
44
75
  selectionAreas.map(function (area) {
45
- if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
46
- // Do not create a cell selection area if point1 and point2 have the same values
47
- // Cell selections must have two distinctly different points for an area to be created
48
- if (area.point1.row === area.point2.row && area.point1.column === area.point2.column) {
49
- var selectionAreasClone = deepCloneObject(selectionAreas);
50
- var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
51
- return item.matcher === area.matcher;
76
+ // Setup selection area data that will be sent back to consumer via onSelectionAreaChange prop
77
+ if (area.areaCreated) {
78
+ var rowStart = Math.min(area.point1.row, area.point2.row);
79
+ var rowEnd = Math.max(area.point1.row, area.point2.row);
80
+ var columnStart = Math.min(area.point1.column, area.point2.column);
81
+ var columnEnd = Math.max(area.point1.column, area.point2.column);
82
+ var selectionData = {
83
+ rows: {
84
+ start: rowStart,
85
+ end: rowEnd
86
+ },
87
+ columns: {
88
+ start: columnStart,
89
+ end: columnEnd
90
+ },
91
+ cells: populateSelectionAreaCellData({
92
+ rowStart: rowStart,
93
+ rowEnd: rowEnd,
94
+ columnStart: columnStart,
95
+ columnEnd: columnEnd
96
+ }),
97
+ selectionId: area.matcher
98
+ };
99
+ setSelectionAreaData(function (prev) {
100
+ var prevValues = deepCloneObject(prev);
101
+ var newAreaData = prevValues.filter(function (item) {
102
+ return item.selectionId !== area.matcher;
52
103
  });
53
- selectionAreasClone[indexOfCurrentArea].areaCreated = false;
54
- selectionAreasClone[indexOfCurrentArea].point2 = null;
55
- return setSelectionAreas(selectionAreasClone);
56
- }
104
+ return [].concat(_toConsumableArray(newAreaData), [selectionData]);
105
+ });
106
+ }
57
107
 
108
+ if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
58
109
  createCellSelectionArea({
59
110
  area: area,
60
111
  blockClass: blockClass,
@@ -67,7 +118,24 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
67
118
  return;
68
119
  });
69
120
  }
70
- }, [selectionAreas, setSelectionAreas, defaultColumn]); // Mouse up
121
+ }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
122
+
123
+ var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
124
+ var rowStart = _ref2.rowStart,
125
+ rowEnd = _ref2.rowEnd,
126
+ columnStart = _ref2.columnStart,
127
+ columnEnd = _ref2.columnEnd;
128
+ var cellContainer = [];
129
+
130
+ for (var rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
131
+ for (var columnIndex = columnStart; columnIndex <= columnEnd; columnIndex++) {
132
+ cellContainer.push([rowIndex, columnIndex]);
133
+ }
134
+ }
135
+
136
+ return cellContainer;
137
+ }; // Mouse up
138
+
71
139
 
72
140
  useEffect(function () {
73
141
  var handleMouseUp = function handleMouseUp(event) {
@@ -168,9 +236,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
168
236
  matcher: tempMatcher
169
237
  }]);
170
238
  setCurrentMatcher(tempMatcher);
239
+ setSelectionAreaData([]);
171
240
  }
172
241
  };
173
- }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref]);
242
+ }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
174
243
  var handleBodyCellHover = useCallback(function (cell, columnIndex) {
175
244
  return function () {
176
245
  if (clickAndHoldActive) {
@@ -213,45 +282,86 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
213
282
  setCurrentMatcher: setCurrentMatcher,
214
283
  setSelectionAreas: setSelectionAreas,
215
284
  spreadsheetRef: ref,
216
- index: index
285
+ index: index,
286
+ setSelectionAreaData: setSelectionAreaData
217
287
  });
218
288
  };
219
- }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows]); // Renders each row/cell in the spreadsheet body
289
+ }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
290
+ // using defaultEmptyRowCount to determine how many empty rows are created.
291
+
292
+ useEffect(function () {
293
+ if (!(rows !== null && rows !== void 0 && rows.length)) {
294
+ var buildEmptyRows = function buildEmptyRows() {
295
+ var emptyRowData = [];
296
+
297
+ _toConsumableArray(Array(defaultEmptyRowCount)).map(function () {
298
+ var _headerGroups$;
299
+
300
+ var emptyCell = {};
301
+ (_headerGroups$ = headerGroups[0]) === null || _headerGroups$ === void 0 ? void 0 : _headerGroups$.headers.map(function (header) {
302
+ emptyCell[header.id] = null;
303
+ });
304
+ emptyRowData.push(emptyCell);
305
+ });
306
+
307
+ onDataUpdate(emptyRowData);
308
+ };
220
309
 
221
- var RenderRow = useCallback(function (_ref2) {
222
- var index = _ref2.index,
223
- style = _ref2.style;
310
+ buildEmptyRows();
311
+ }
312
+ }, [rows, headerGroups, defaultEmptyRowCount, onDataUpdate]);
313
+
314
+ var RenderEmptyRows = function RenderEmptyRows() {
315
+ return /*#__PURE__*/React.createElement("div", null);
316
+ }; // Renders each row/cell in the spreadsheet body
317
+
318
+
319
+ var RenderRow = useCallback(function (_ref3) {
320
+ var index = _ref3.index,
321
+ style = _ref3.style;
224
322
  var row = rows[index];
225
- prepareRow(row);
226
- return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
227
- style: style
228
- }), {
229
- className: cx("".concat(blockClass, "__tr")),
230
- "data-row-index": index
231
- }), /*#__PURE__*/React.createElement("button", {
232
- tabIndex: -1,
233
- "data-row-index": index,
234
- "data-column-index": "header",
235
- type: "button",
236
- onClick: handleRowHeaderClick(index),
237
- 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'))),
238
- style: {
239
- width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
240
- }
241
- }, index + 1), row.cells.map(function (cell, index) {
242
- return /*#__PURE__*/React.createElement("button", _extends({
323
+
324
+ if (rows && rows.length) {
325
+ prepareRow(row);
326
+ return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
327
+ style: style
328
+ }), {
329
+ className: cx("".concat(blockClass, "__tr")),
330
+ "data-row-index": index,
331
+ "aria-rowindex": index
332
+ }), /*#__PURE__*/React.createElement("div", {
333
+ role: "rowheader"
334
+ }, /*#__PURE__*/React.createElement("button", {
243
335
  tabIndex: -1,
244
- "data-row-index": cell.row.index,
245
- "data-column-index": index
246
- }, cell.getCellProps(), {
247
- className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
248
- key: "cell_".concat(index),
249
- onMouseDown: handleBodyCellClick(cell, index),
250
- onMouseOver: handleBodyCellHover(cell, index),
251
- onFocus: function onFocus() {},
252
- type: "button"
253
- }), cell.render('Cell'));
254
- }));
336
+ "data-row-index": index,
337
+ "data-column-index": "header",
338
+ type: "button",
339
+ onClick: handleRowHeaderClick(index),
340
+ 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'))),
341
+ style: {
342
+ width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4
343
+ }
344
+ }, index + 1)), row.cells.map(function (cell, index) {
345
+ return /*#__PURE__*/React.createElement("div", _extends({
346
+ key: "cell_".concat(index),
347
+ "aria-colindex": index
348
+ }, cell.getCellProps(), {
349
+ role: "gridcell",
350
+ style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
351
+ display: 'grid'
352
+ })
353
+ }), /*#__PURE__*/React.createElement("button", {
354
+ tabIndex: -1,
355
+ "data-row-index": cell.row.index,
356
+ "data-column-index": index,
357
+ className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
358
+ onMouseDown: handleBodyCellClick(cell, index),
359
+ onMouseOver: handleBodyCellHover(cell, index),
360
+ onFocus: function onFocus() {},
361
+ type: "button"
362
+ }, cell.render('Cell')));
363
+ }));
364
+ }
255
365
  }, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
256
366
  var spreadsheetBodyRef = useRef();
257
367
  return /*#__PURE__*/React.createElement("div", _extends({
@@ -260,10 +370,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
260
370
  }, getTableBodyProps()), /*#__PURE__*/React.createElement(FixedSizeList, {
261
371
  className: cx("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
262
372
  height: 400,
263
- itemCount: rows.length,
373
+ itemCount: rows.length || defaultEmptyRowCount,
264
374
  itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
265
375
  width: totalColumnsWidth + scrollBarSize
266
- }, RenderRow));
376
+ }, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
267
377
  });
268
378
  DataSpreadsheetBody.propTypes = {
269
379
  /**
@@ -298,11 +408,21 @@ DataSpreadsheetBody.propTypes = {
298
408
  width: PropTypes.number
299
409
  }),
300
410
 
411
+ /**
412
+ * Sets the number of empty rows to be created when there is no data provided
413
+ */
414
+ defaultEmptyRowCount: PropTypes.number,
415
+
301
416
  /**
302
417
  * Function to set table body prop values
303
418
  */
304
419
  getTableBodyProps: PropTypes.func,
305
420
 
421
+ /**
422
+ * Headers provided from useTable hook
423
+ */
424
+ headerGroups: PropTypes.arrayOf(PropTypes.object),
425
+
306
426
  /**
307
427
  * The spreadsheet id
308
428
  */
@@ -313,6 +433,16 @@ DataSpreadsheetBody.propTypes = {
313
433
  */
314
434
  onActiveCellChange: PropTypes.func,
315
435
 
436
+ /**
437
+ * The event handler that is called to set the rows for the empty spreadsheet
438
+ */
439
+ onDataUpdate: PropTypes.func,
440
+
441
+ /**
442
+ * The event handler that is called when the selection areas change
443
+ */
444
+ onSelectionAreaChange: PropTypes.func,
445
+
316
446
  /**
317
447
  * Prepare row function from react-table
318
448
  */
@@ -328,6 +458,11 @@ DataSpreadsheetBody.propTypes = {
328
458
  */
329
459
  scrollBarSize: PropTypes.number,
330
460
 
461
+ /**
462
+ * Array of selection area data
463
+ */
464
+ selectionAreaData: PropTypes.array,
465
+
331
466
  /**
332
467
  * Array of selection areas
333
468
  */
@@ -353,6 +488,11 @@ DataSpreadsheetBody.propTypes = {
353
488
  */
354
489
  setCurrentMatcher: PropTypes.func,
355
490
 
491
+ /**
492
+ * Setter fn for selectionAreaData state value
493
+ */
494
+ setSelectionAreaData: PropTypes.func,
495
+
356
496
  /**
357
497
  * Setter fn for selectionAreas state value
358
498
  */
@@ -1,5 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
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; }
3
8
 
4
9
  /**
5
10
  * Copyright IBM Corp. 2022, 2022
@@ -7,24 +12,48 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
12
  * This source code is licensed under the Apache-2.0 license found in the
8
13
  * LICENSE file in the root directory of this source tree.
9
14
  */
10
- import React, { forwardRef } from 'react';
15
+ import React, { forwardRef, useEffect, useState } from 'react';
11
16
  import PropTypes from 'prop-types';
12
17
  import cx from 'classnames';
18
+ import { px } from '@carbon/layout';
13
19
  import { pkg } from '../../settings';
14
20
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
15
21
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
22
+ import { usePreviousValue } from '../../global/js/hooks';
16
23
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
17
24
  export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
18
25
  var activeCellCoordinates = _ref.activeCellCoordinates,
26
+ cellSize = _ref.cellSize,
19
27
  columns = _ref.columns,
20
28
  defaultColumn = _ref.defaultColumn,
21
29
  headerGroups = _ref.headerGroups,
30
+ scrollBarSize = _ref.scrollBarSize,
22
31
  selectionAreas = _ref.selectionAreas,
23
32
  setActiveCellCoordinates = _ref.setActiveCellCoordinates,
24
33
  setCurrentMatcher = _ref.setCurrentMatcher,
25
34
  setSelectionAreas = _ref.setSelectionAreas,
35
+ setSelectionAreaData = _ref.setSelectionAreaData,
26
36
  rows = _ref.rows;
27
37
 
38
+ var _useState = useState(0),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ scrollBarSizeValue = _useState2[0],
41
+ setScrollBarSizeValue = _useState2[1];
42
+
43
+ var previousState = usePreviousValue({
44
+ cellSize: cellSize
45
+ });
46
+ useEffect(function () {
47
+ if ((previousState === null || previousState === void 0 ? void 0 : previousState.cellSize) !== cellSize) {
48
+ var _ref$current;
49
+
50
+ var scrollContainer = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector(".".concat(blockClass, "__list--container"));
51
+ var hasScrollBar = (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollHeight) > (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.clientHeight);
52
+ var scrollBarValue = hasScrollBar ? 0 : scrollBarSize;
53
+ setScrollBarSizeValue(scrollBarValue);
54
+ }
55
+ }, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
56
+
28
57
  var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
29
58
  return function () {
30
59
  handleHeaderCellSelection({
@@ -36,7 +65,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
36
65
  setCurrentMatcher: setCurrentMatcher,
37
66
  setSelectionAreas: setSelectionAreas,
38
67
  spreadsheetRef: ref,
39
- index: index
68
+ index: index,
69
+ setSelectionAreaData: setSelectionAreaData
40
70
  });
41
71
  };
42
72
  };
@@ -47,31 +77,38 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
47
77
  return /*#__PURE__*/React.createElement("div", _extends({
48
78
  key: "header_".concat(index)
49
79
  }, headerGroup.getHeaderGroupProps(), {
80
+ style: _objectSpread(_objectSpread({}, headerGroup.getHeaderGroupProps().style), {}, {
81
+ width: px(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
82
+ }),
50
83
  className: "".concat(blockClass, "__tr")
51
- }), /*#__PURE__*/React.createElement("button", {
84
+ }), /*#__PURE__*/React.createElement("div", {
85
+ role: "columnheader",
86
+ style: {
87
+ width: (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth) - 4,
88
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
89
+ }
90
+ }, /*#__PURE__*/React.createElement("button", {
52
91
  "data-row-index": "header",
53
92
  "data-column-index": "header",
54
93
  type: "button",
55
94
  tabIndex: -1,
56
- 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')),
57
- style: {
58
- width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
59
- height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
60
- }
61
- }, "\xA0"), headerGroup.headers.map(function (column, index) {
62
- return /*#__PURE__*/React.createElement("button", _extends({
95
+ 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'))
96
+ }, "\xA0")), headerGroup.headers.map(function (column, index) {
97
+ return /*#__PURE__*/React.createElement("div", _extends({
63
98
  key: "column_".concat(index),
99
+ role: "columnheader",
100
+ className: "".concat(blockClass, "__columnheader")
101
+ }, column.getHeaderProps()), /*#__PURE__*/React.createElement("button", {
64
102
  "data-row-index": "header",
65
103
  "data-column-index": index,
66
104
  tabIndex: -1,
67
105
  onClick: handleColumnHeaderClick(index),
68
106
  style: {
69
107
  height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
70
- }
71
- }, column.getHeaderProps(), {
108
+ },
72
109
  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'))),
73
110
  type: "button"
74
- }), column.render('Header'));
111
+ }, column.render('Header')));
75
112
  }));
76
113
  }));
77
114
  });
@@ -84,6 +121,11 @@ DataSpreadsheetHeader.propTypes = {
84
121
  column: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
85
122
  }),
86
123
 
124
+ /**
125
+ * Specifies the cell height
126
+ */
127
+ cellSize: PropTypes.oneOf(['compact', 'standard', 'medium', 'large']),
128
+
87
129
  /**
88
130
  * All of the spreadsheet columns
89
131
  */
@@ -108,6 +150,11 @@ DataSpreadsheetHeader.propTypes = {
108
150
  */
109
151
  rows: PropTypes.arrayOf(PropTypes.object),
110
152
 
153
+ /**
154
+ * The scrollbar width
155
+ */
156
+ scrollBarSize: PropTypes.number,
157
+
111
158
  /**
112
159
  * All of the cell selection area items
113
160
  */
@@ -123,6 +170,11 @@ DataSpreadsheetHeader.propTypes = {
123
170
  */
124
171
  setCurrentMatcher: PropTypes.func,
125
172
 
173
+ /**
174
+ * Setter fn for selectionAreaData state value
175
+ */
176
+ setSelectionAreaData: PropTypes.func,
177
+
126
178
  /**
127
179
  * Setter fn for selectionAreas value
128
180
  */
@@ -0,0 +1,10 @@
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';
@@ -0,0 +1,111 @@
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
+
13
+ var hasFocus = function hasFocus() {
14
+ return typeof document !== 'undefined' && document.hasFocus();
15
+ };
16
+
17
+ export var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
18
+ var ref = _ref.ref,
19
+ containerHasFocus = _ref.containerHasFocus,
20
+ isEditing = _ref.isEditing;
21
+
22
+ var _useState = useState(hasFocus),
23
+ _useState2 = _slicedToArray(_useState, 2),
24
+ windowFocused = _useState2[0],
25
+ setWindowFocused = _useState2[1];
26
+
27
+ var _useState3 = useState([]),
28
+ _useState4 = _slicedToArray(_useState3, 2),
29
+ keysPressedList = _useState4[0],
30
+ setKeysPressedList = _useState4[1];
31
+
32
+ var previousState = usePreviousValue({
33
+ isEditing: isEditing,
34
+ windowFocused: windowFocused
35
+ }); // useEffect to check for window focus, if window loses focus
36
+ // we need to clear out the keysPressedList
37
+
38
+ useEffect(function () {
39
+ setWindowFocused(hasFocus());
40
+
41
+ var onWindowFocus = function onWindowFocus() {
42
+ return setWindowFocused(true);
43
+ };
44
+
45
+ var onWindowBlur = function onWindowBlur() {
46
+ return setWindowFocused(false);
47
+ };
48
+
49
+ window.addEventListener('focus', onWindowFocus);
50
+ window.addEventListener('blur', onWindowBlur);
51
+ return function () {
52
+ window.removeEventListener('focus', onWindowFocus);
53
+ window.removeEventListener('blur', onWindowBlur);
54
+ };
55
+ }, []);
56
+ useEffect(function () {
57
+ if (containerHasFocus && !isEditing) {
58
+ ref.current.onkeydown = ref.current.onkeyup = function (event) {
59
+ // If keydown, we will add the new key to the keysPressedList array
60
+ if (event.type === 'keydown') {
61
+ // Prevent multiple keys of the same type being added to our keysPressedList array
62
+ if (keysPressedList.includes(event.code)) {
63
+ return;
64
+ }
65
+
66
+ var tempKeys = _toConsumableArray(keysPressedList);
67
+
68
+ tempKeys.push(event.code);
69
+ setKeysPressedList(_toConsumableArray(new Set(tempKeys)));
70
+ } // If keyup, we will remove the key from the keysPressedList array
71
+
72
+
73
+ if (event.type === 'keyup') {
74
+ var _tempKeys = _toConsumableArray(keysPressedList);
75
+
76
+ var filteredClone = _tempKeys.filter(function (item) {
77
+ return item !== event.code;
78
+ }); // Keyup events are lost on all other keys if a Meta key is used
79
+ // so to work around this behavior, we empty out all other keys
80
+ // from the keysPressedList array if we detect a Meta keyup event
81
+
82
+
83
+ if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
84
+ return setKeysPressedList([]);
85
+ }
86
+
87
+ setKeysPressedList(_toConsumableArray(new Set(filteredClone)));
88
+ }
89
+ };
90
+ }
91
+
92
+ if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
93
+ setKeysPressedList([]);
94
+ } // Remove handlers if the spreadsheet container loses focus
95
+ // or is currently in edit mode
96
+
97
+
98
+ if (!containerHasFocus || isEditing) {
99
+ ref.current.onkeydown = undefined;
100
+ ref.current.onkeyup = undefined;
101
+
102
+ if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
103
+ setKeysPressedList([]);
104
+ }
105
+ }
106
+ }, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused]);
107
+ return {
108
+ keysPressedList: keysPressedList,
109
+ windowFocused: windowFocused
110
+ };
111
+ };
@@ -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
  };