@carbon/ibm-products 1.13.0 → 1.16.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 (230) 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 +268 -0
  6. package/css/components/Datagrid/styles/datagrid.css.map +1 -0
  7. package/css/components/Datagrid/styles/index.css +513 -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 +611 -10
  24. package/css/index-full-carbon.css.map +1 -1
  25. package/css/index-full-carbon.min.css +3 -3
  26. package/css/index-full-carbon.min.css.map +1 -1
  27. package/css/index-without-carbon-released-only.css +7 -4
  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 +611 -10
  32. package/css/index-without-carbon.css.map +1 -1
  33. package/css/index-without-carbon.min.css +3 -3
  34. package/css/index-without-carbon.min.css.map +1 -1
  35. package/css/index.css +611 -10
  36. package/css/index.css.map +1 -1
  37. package/css/index.min.css +3 -3
  38. package/css/index.min.css.map +1 -1
  39. package/es/components/AddSelect/AddSelect.js +106 -43
  40. package/es/components/AddSelect/AddSelectFilter.js +172 -0
  41. package/es/components/AddSelect/add-select-utils.js +30 -0
  42. package/es/components/DataSpreadsheet/DataSpreadsheet.js +255 -175
  43. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +78 -17
  44. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +65 -20
  45. package/es/components/DataSpreadsheet/hooks/index.js +11 -0
  46. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +139 -0
  47. package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  48. package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -0
  49. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +1 -3
  50. package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
  51. package/es/components/DataSpreadsheet/utils/generateData.js +17 -9
  52. package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
  53. package/es/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +30 -0
  54. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
  55. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
  56. package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
  57. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +42 -8
  58. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +225 -13
  59. package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
  60. package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
  61. package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
  62. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
  63. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
  64. package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
  65. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
  66. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
  67. package/es/components/Datagrid/Datagrid/DatagridRow.js +60 -0
  68. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
  69. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
  70. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
  71. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
  72. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
  73. package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
  74. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
  75. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
  76. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
  77. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
  78. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
  79. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
  80. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
  81. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
  82. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
  83. package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
  84. package/es/components/Datagrid/Datagrid/index.js +8 -0
  85. package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
  86. package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
  87. package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
  88. package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
  89. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
  90. package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
  91. package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
  92. package/es/components/Datagrid/common-column-ids.js +8 -0
  93. package/es/components/Datagrid/index.js +22 -0
  94. package/es/components/Datagrid/useActionsColumn.js +86 -0
  95. package/es/components/Datagrid/useColumnRightAlign.js +52 -0
  96. package/es/components/Datagrid/useCustomizeColumns.js +45 -0
  97. package/es/components/Datagrid/useDatagrid.js +44 -0
  98. package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
  99. package/es/components/Datagrid/useDisableSelectRows.js +84 -0
  100. package/es/components/Datagrid/useExpandedRow.js +52 -0
  101. package/es/components/Datagrid/useFlexResize.js +51 -0
  102. package/es/components/Datagrid/useFloatingScroll.js +88 -0
  103. package/es/components/Datagrid/useInfiniteScroll.js +54 -0
  104. package/es/components/Datagrid/useNestedRows.js +53 -0
  105. package/es/components/Datagrid/useOnRowClick.js +37 -0
  106. package/es/components/Datagrid/useParentDimensions.js +65 -0
  107. package/es/components/Datagrid/useResizeTable.js +40 -0
  108. package/es/components/Datagrid/useRowExpander.js +34 -0
  109. package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
  110. package/es/components/Datagrid/useRowRenderer.js +30 -0
  111. package/es/components/Datagrid/useRowSize.js +56 -0
  112. package/es/components/Datagrid/useSelectAllToggle.js +74 -0
  113. package/es/components/Datagrid/useSelectRows.js +107 -0
  114. package/es/components/Datagrid/useSkeletonRows.js +32 -0
  115. package/es/components/Datagrid/useSortableColumns.js +110 -0
  116. package/es/components/Datagrid/useStickyColumn.js +183 -0
  117. package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
  118. package/es/components/PageHeader/PageHeader.js +3 -1
  119. package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
  120. package/es/components/TagSet/TagSet.js +13 -6
  121. package/es/components/Tearsheet/TearsheetShell.js +34 -10
  122. package/es/components/index.js +2 -1
  123. package/es/global/js/package-settings.js +4 -2
  124. package/lib/components/AddSelect/AddSelect.js +105 -41
  125. package/lib/components/AddSelect/AddSelectFilter.js +190 -0
  126. package/lib/components/AddSelect/add-select-utils.js +35 -2
  127. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +261 -177
  128. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +79 -23
  129. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +67 -21
  130. package/lib/components/DataSpreadsheet/hooks/index.js +45 -0
  131. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +151 -0
  132. package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  133. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +79 -0
  134. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +1 -3
  135. package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
  136. package/lib/components/DataSpreadsheet/utils/generateData.js +17 -9
  137. package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
  138. package/lib/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +40 -0
  139. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
  140. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
  141. package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
  142. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +44 -8
  143. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +235 -20
  144. package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
  145. package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
  146. package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
  147. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
  148. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
  149. package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
  150. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
  151. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
  152. package/lib/components/Datagrid/Datagrid/DatagridRow.js +68 -0
  153. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
  154. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
  155. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
  156. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
  157. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
  158. package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
  159. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
  160. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
  161. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
  162. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
  163. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
  164. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
  165. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
  166. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
  167. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
  168. package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
  169. package/lib/components/Datagrid/Datagrid/index.js +15 -0
  170. package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
  171. package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
  172. package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
  173. package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
  174. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
  175. package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
  176. package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
  177. package/lib/components/Datagrid/common-column-ids.js +16 -0
  178. package/lib/components/Datagrid/index.js +127 -0
  179. package/lib/components/Datagrid/useActionsColumn.js +94 -0
  180. package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
  181. package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
  182. package/lib/components/Datagrid/useDatagrid.js +58 -0
  183. package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
  184. package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
  185. package/lib/components/Datagrid/useExpandedRow.js +58 -0
  186. package/lib/components/Datagrid/useFlexResize.js +61 -0
  187. package/lib/components/Datagrid/useFloatingScroll.js +101 -0
  188. package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
  189. package/lib/components/Datagrid/useNestedRows.js +65 -0
  190. package/lib/components/Datagrid/useOnRowClick.js +45 -0
  191. package/lib/components/Datagrid/useParentDimensions.js +75 -0
  192. package/lib/components/Datagrid/useResizeTable.js +48 -0
  193. package/lib/components/Datagrid/useRowExpander.js +45 -0
  194. package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
  195. package/lib/components/Datagrid/useRowRenderer.js +40 -0
  196. package/lib/components/Datagrid/useRowSize.js +67 -0
  197. package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
  198. package/lib/components/Datagrid/useSelectRows.js +119 -0
  199. package/lib/components/Datagrid/useSkeletonRows.js +42 -0
  200. package/lib/components/Datagrid/useSortableColumns.js +117 -0
  201. package/lib/components/Datagrid/useStickyColumn.js +190 -0
  202. package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
  203. package/lib/components/PageHeader/PageHeader.js +3 -1
  204. package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
  205. package/lib/components/TagSet/TagSet.js +13 -6
  206. package/lib/components/Tearsheet/TearsheetShell.js +36 -10
  207. package/lib/components/index.js +9 -1
  208. package/lib/global/js/package-settings.js +4 -2
  209. package/package.json +16 -12
  210. package/scss/components/AboutModal/_about-modal.scss +4 -0
  211. package/scss/components/AddSelect/_add-select.scss +46 -2
  212. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +41 -4
  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 +326 -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 +0 -4
  229. package/scss/components/Tearsheet/_tearsheet.scss +4 -0
  230. 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
  *
@@ -21,6 +25,7 @@ import { removeCellSelections } from './utils/removeCellSelections';
21
25
  import { createCellSelectionArea } from './utils/createCellSelectionArea';
22
26
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
23
27
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
28
+ import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth';
24
29
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
25
30
  export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
26
31
  var columns = _ref.columns,
@@ -45,7 +50,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
45
50
  setClickAndHoldActive = _ref.setClickAndHoldActive,
46
51
  currentMatcher = _ref.currentMatcher,
47
52
  setCurrentMatcher = _ref.setCurrentMatcher,
48
- onSelectionAreaChange = _ref.onSelectionAreaChange;
53
+ onSelectionAreaChange = _ref.onSelectionAreaChange,
54
+ setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea,
55
+ totalVisibleColumns = _ref.totalVisibleColumns;
56
+ var contentScrollRef = useRef();
49
57
  var previousState = usePreviousValue({
50
58
  selectionAreaData: selectionAreaData,
51
59
  clickAndHoldActive: clickAndHoldActive
@@ -103,18 +111,20 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
103
111
 
104
112
  if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
105
113
  createCellSelectionArea({
114
+ ref: ref,
106
115
  area: area,
107
116
  blockClass: blockClass,
108
117
  defaultColumn: defaultColumn,
109
118
  selectionAreas: selectionAreas,
110
- setSelectionAreas: setSelectionAreas
119
+ setSelectionAreas: setSelectionAreas,
120
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
111
121
  });
112
122
  }
113
123
 
114
124
  return;
115
125
  });
116
126
  }
117
- }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
127
+ }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
118
128
 
119
129
  var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
120
130
  var rowStart = _ref2.rowStart,
@@ -192,6 +202,9 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
192
202
  // meaning that selectionAreas should only have one item by default
193
203
 
194
204
  if (isHoldingCommandKey) {
205
+ var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
206
+ activeCellElement.setAttribute('data-selection-id', tempMatcher);
207
+ setActiveCellInsideSelectionArea(true);
195
208
  setActiveCellCoordinates(activeCoordinates);
196
209
  setCurrentMatcher(tempMatcher);
197
210
  setSelectionAreas(function (prev) {
@@ -222,6 +235,7 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
222
235
  setSelectionAreas(selectionAreaClone);
223
236
  }
224
237
  } else {
238
+ setActiveCellInsideSelectionArea(false);
225
239
  setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
226
240
 
227
241
  removeCellSelections({
@@ -235,7 +249,22 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
235
249
  setSelectionAreaData([]);
236
250
  }
237
251
  };
238
- }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
252
+ }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
253
+
254
+ var handleBodyScroll = function handleBodyScroll() {
255
+ var headerRowElement = ref.current.querySelector("\n .".concat(blockClass, "__header--container .").concat(blockClass, "__tr"));
256
+ headerRowElement.scrollLeft = contentScrollRef.current.scrollLeft;
257
+ };
258
+
259
+ useEffect(function () {
260
+ contentScrollRef.current.addEventListener('scroll', function (event) {
261
+ return handleBodyScroll(event);
262
+ });
263
+ var contentScrollElementRef = contentScrollRef.current;
264
+ return function () {
265
+ contentScrollElementRef.removeEventListener('scroll', handleBodyScroll);
266
+ };
267
+ });
239
268
  var handleBodyCellHover = useCallback(function (cell, columnIndex) {
240
269
  return function () {
241
270
  if (clickAndHoldActive) {
@@ -268,7 +297,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
268
297
  };
269
298
  }, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
270
299
  var handleRowHeaderClick = useCallback(function (index) {
271
- return function () {
300
+ return function (event) {
301
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
272
302
  handleHeaderCellSelection({
273
303
  type: 'row',
274
304
  activeCellCoordinates: activeCellCoordinates,
@@ -279,7 +309,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
279
309
  setSelectionAreas: setSelectionAreas,
280
310
  spreadsheetRef: ref,
281
311
  index: index,
282
- setSelectionAreaData: setSelectionAreaData
312
+ setSelectionAreaData: setSelectionAreaData,
313
+ isHoldingCommandKey: isHoldingCommandKey
283
314
  });
284
315
  };
285
316
  }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
@@ -323,8 +354,13 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
323
354
  style: style
324
355
  }), {
325
356
  className: cx("".concat(blockClass, "__tr")),
326
- "data-row-index": index
327
- }), /*#__PURE__*/React.createElement("button", {
357
+ "data-row-index": index,
358
+ "aria-rowindex": index + 1
359
+ }), /*#__PURE__*/React.createElement("div", {
360
+ role: "rowheader",
361
+ className: "".concat(blockClass, "__td-th--cell-container")
362
+ }, /*#__PURE__*/React.createElement("button", {
363
+ id: "".concat(blockClass, "__cell--").concat(index, "--header"),
328
364
  tabIndex: -1,
329
365
  "data-row-index": index,
330
366
  "data-column-index": "header",
@@ -334,22 +370,30 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
334
370
  style: {
335
371
  width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
336
372
  }
337
- }, index + 1), row.cells.map(function (cell, index) {
338
- return /*#__PURE__*/React.createElement("button", _extends({
373
+ }, index + 1)), row.cells.map(function (cell, index) {
374
+ return /*#__PURE__*/React.createElement("div", _extends({
375
+ key: "cell_".concat(index),
376
+ "aria-colindex": index + 1
377
+ }, cell.getCellProps(), {
378
+ role: "gridcell",
379
+ style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
380
+ display: 'grid',
381
+ minWidth: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width
382
+ })
383
+ }), /*#__PURE__*/React.createElement("button", {
384
+ id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
339
385
  tabIndex: -1,
340
386
  "data-row-index": cell.row.index,
341
- "data-column-index": index
342
- }, cell.getCellProps(), {
387
+ "data-column-index": index,
343
388
  className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
344
- key: "cell_".concat(index),
345
389
  onMouseDown: handleBodyCellClick(cell, index),
346
390
  onMouseOver: handleBodyCellHover(cell, index),
347
391
  onFocus: function onFocus() {},
348
392
  type: "button"
349
- }), cell.render('Cell'));
393
+ }, cell.render('Cell')));
350
394
  }));
351
395
  }
352
- }, [prepareRow, rows, defaultColumn.rowHeaderWidth, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover]);
396
+ }, [prepareRow, rows, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover, defaultColumn]);
353
397
  var spreadsheetBodyRef = useRef();
354
398
  return /*#__PURE__*/React.createElement("div", _extends({
355
399
  ref: spreadsheetBodyRef,
@@ -359,7 +403,13 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
359
403
  height: 400,
360
404
  itemCount: rows.length || defaultEmptyRowCount,
361
405
  itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
362
- width: totalColumnsWidth + scrollBarSize
406
+ width: getSpreadsheetWidth({
407
+ scrollBarSizeValue: scrollBarSize,
408
+ totalVisibleColumns: totalVisibleColumns,
409
+ defaultColumn: defaultColumn,
410
+ totalColumnsWidth: totalColumnsWidth
411
+ }),
412
+ outerRef: contentScrollRef
363
413
  }, rows !== null && rows !== void 0 && rows.length ? RenderRow : RenderEmptyRows));
364
414
  });
365
415
  DataSpreadsheetBody.propTypes = {
@@ -460,6 +510,11 @@ DataSpreadsheetBody.propTypes = {
460
510
  */
461
511
  setActiveCellCoordinates: PropTypes.func,
462
512
 
513
+ /**
514
+ * Setter fn for active cell inside of selection area
515
+ */
516
+ setActiveCellInsideSelectionArea: PropTypes.func,
517
+
463
518
  /**
464
519
  * Setter fn for clickAndHold state value
465
520
  */
@@ -488,5 +543,11 @@ DataSpreadsheetBody.propTypes = {
488
543
  /**
489
544
  * The total columns width
490
545
  */
491
- totalColumnsWidth: PropTypes.number
546
+ totalColumnsWidth: PropTypes.number,
547
+
548
+ /**
549
+ * The total number of columns to be initially visible, additional columns will be rendered and
550
+ * visible via horizontal scrollbar
551
+ */
552
+ totalVisibleColumns: PropTypes.number
492
553
  };
@@ -15,11 +15,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
15
15
  import React, { forwardRef, useEffect, useState } from 'react';
16
16
  import PropTypes from 'prop-types';
17
17
  import cx from 'classnames';
18
- import { px } from '@carbon/layout';
19
18
  import { pkg } from '../../settings';
19
+ import { usePreviousValue } from '../../global/js/hooks';
20
20
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
21
21
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
22
- import { usePreviousValue } from '../../global/js/hooks';
22
+ import { selectAllCells } from './utils/selectAllCells';
23
+ import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth';
23
24
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
24
25
  export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
25
26
  var activeCellCoordinates = _ref.activeCellCoordinates,
@@ -33,7 +34,9 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
33
34
  setCurrentMatcher = _ref.setCurrentMatcher,
34
35
  setSelectionAreas = _ref.setSelectionAreas,
35
36
  setSelectionAreaData = _ref.setSelectionAreaData,
36
- rows = _ref.rows;
37
+ rows = _ref.rows,
38
+ totalVisibleColumns = _ref.totalVisibleColumns,
39
+ updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
37
40
 
38
41
  var _useState = useState(0),
39
42
  _useState2 = _slicedToArray(_useState, 2),
@@ -55,7 +58,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
55
58
  }, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
56
59
 
57
60
  var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
58
- return function () {
61
+ return function (event) {
62
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
59
63
  handleHeaderCellSelection({
60
64
  type: 'column',
61
65
  activeCellCoordinates: activeCellCoordinates,
@@ -66,45 +70,75 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
66
70
  setSelectionAreas: setSelectionAreas,
67
71
  spreadsheetRef: ref,
68
72
  index: index,
69
- setSelectionAreaData: setSelectionAreaData
73
+ setSelectionAreaData: setSelectionAreaData,
74
+ isHoldingCommandKey: isHoldingCommandKey
70
75
  });
71
76
  };
72
77
  };
73
78
 
79
+ var handleSelectAllClick = function handleSelectAllClick() {
80
+ selectAllCells({
81
+ ref: ref,
82
+ setCurrentMatcher: setCurrentMatcher,
83
+ setSelectionAreas: setSelectionAreas,
84
+ rows: rows,
85
+ columns: columns,
86
+ activeCellCoordinates: activeCellCoordinates,
87
+ updateActiveCellCoordinates: updateActiveCellCoordinates
88
+ });
89
+ };
90
+
74
91
  return /*#__PURE__*/React.createElement("div", {
75
- className: cx("".concat(blockClass, "__header--container"))
92
+ className: cx("".concat(blockClass, "__header--container")),
93
+ role: "rowgroup"
76
94
  }, headerGroups.map(function (headerGroup, index) {
77
95
  return /*#__PURE__*/React.createElement("div", _extends({
78
96
  key: "header_".concat(index)
79
97
  }, headerGroup.getHeaderGroupProps(), {
80
98
  style: _objectSpread(_objectSpread({}, headerGroup.getHeaderGroupProps().style), {}, {
81
- width: px(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
99
+ width: getSpreadsheetWidth({
100
+ type: 'header',
101
+ headerGroup: headerGroup,
102
+ scrollBarSizeValue: scrollBarSizeValue,
103
+ totalVisibleColumns: totalVisibleColumns,
104
+ defaultColumn: defaultColumn
105
+ }),
106
+ overflow: 'hidden'
82
107
  }),
83
108
  className: "".concat(blockClass, "__tr")
84
- }), /*#__PURE__*/React.createElement("button", {
85
- "data-row-index": "header",
86
- "data-column-index": "header",
87
- type: "button",
88
- tabIndex: -1,
89
- className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header')),
109
+ }), /*#__PURE__*/React.createElement("div", {
110
+ role: "columnheader",
111
+ className: "".concat(blockClass, "__select-all-cell-container"),
90
112
  style: {
91
113
  width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
92
114
  height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
93
115
  }
94
- }, "\xA0"), headerGroup.headers.map(function (column, index) {
95
- return /*#__PURE__*/React.createElement("button", _extends({
116
+ }, /*#__PURE__*/React.createElement("button", {
117
+ id: "".concat(blockClass, "__cell--header--header"),
118
+ "data-row-index": "header",
119
+ "data-column-index": "header",
120
+ type: "button",
121
+ tabIndex: -1,
122
+ onClick: handleSelectAllClick,
123
+ 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'))
124
+ }, "\xA0")), headerGroup.headers.map(function (column, index) {
125
+ return /*#__PURE__*/React.createElement("div", _extends({
96
126
  key: "column_".concat(index),
127
+ role: "columnheader",
128
+ className: "".concat(blockClass, "__columnheader")
129
+ }, column.getHeaderProps()), /*#__PURE__*/React.createElement("button", {
130
+ id: "".concat(blockClass, "__cell--header--").concat(index),
97
131
  "data-row-index": "header",
98
132
  "data-column-index": index,
99
133
  tabIndex: -1,
100
134
  onClick: handleColumnHeaderClick(index),
101
135
  style: {
102
- height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
103
- }
104
- }, column.getHeaderProps(), {
136
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
137
+ width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width
138
+ },
105
139
  className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === index || checkActiveHeaderCell(index, selectionAreas, 'column'))),
106
140
  type: "button"
107
- }), column.render('Header'));
141
+ }, column.render('Header')));
108
142
  }));
109
143
  }));
110
144
  });
@@ -174,5 +208,16 @@ DataSpreadsheetHeader.propTypes = {
174
208
  /**
175
209
  * Setter fn for selectionAreas value
176
210
  */
177
- setSelectionAreas: PropTypes.func
211
+ setSelectionAreas: PropTypes.func,
212
+
213
+ /**
214
+ * The total number of columns to be initially visible, additional columns will be rendered and
215
+ * visible via horizontal scrollbar
216
+ */
217
+ totalVisibleColumns: PropTypes.number,
218
+
219
+ /**
220
+ * Function used to update the active cell coordinates
221
+ */
222
+ updateActiveCellCoordinates: PropTypes.func
178
223
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export { useMoveActiveCell } from './useMoveActiveCell';
8
+ export { useMultipleKeyTracking } from './useMultipleKeyTracking';
9
+ export { useResetSpreadsheetFocus } from './useResetSpreadsheetFocus';
10
+ export { useSpreadsheetOutsideClick } from './useSpreadsheetOutsideClick';
11
+ export { useSpreadsheetEdit } from './useSpreadsheetEdit';
@@ -0,0 +1,139 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+
4
+ /**
5
+ * Copyright IBM Corp. 2022, 2022
6
+ *
7
+ * This source code is licensed under the Apache-2.0 license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ import { useEffect, useState } from 'react';
11
+ import { usePreviousValue } from '../../../global/js/hooks';
12
+ import { includesResourceKey } from '../utils/handleMultipleKeys';
13
+
14
+ var hasFocus = function hasFocus() {
15
+ return typeof document !== 'undefined' && document.hasFocus();
16
+ };
17
+
18
+ export var useMultipleKeyTracking = function useMultipleKeyTracking(_ref) {
19
+ var ref = _ref.ref,
20
+ containerHasFocus = _ref.containerHasFocus,
21
+ isEditing = _ref.isEditing;
22
+
23
+ var _useState = useState(''),
24
+ _useState2 = _slicedToArray(_useState, 2),
25
+ usingMac = _useState2[0],
26
+ setUsingMac = _useState2[1];
27
+
28
+ var _useState3 = useState(hasFocus),
29
+ _useState4 = _slicedToArray(_useState3, 2),
30
+ windowFocused = _useState4[0],
31
+ setWindowFocused = _useState4[1];
32
+
33
+ var _useState5 = useState([]),
34
+ _useState6 = _slicedToArray(_useState5, 2),
35
+ keysPressedList = _useState6[0],
36
+ setKeysPressedList = _useState6[1];
37
+
38
+ var previousState = usePreviousValue({
39
+ isEditing: isEditing,
40
+ windowFocused: windowFocused
41
+ }); // useEffect to check for window focus, if window loses focus
42
+ // we need to clear out the keysPressedList
43
+
44
+ useEffect(function () {
45
+ var userAgentString = window.navigator.userAgent;
46
+
47
+ if (userAgentString.includes('Macintosh')) {
48
+ setUsingMac(true);
49
+ } else {
50
+ setUsingMac(false);
51
+ }
52
+
53
+ setWindowFocused(hasFocus());
54
+
55
+ var onWindowFocus = function onWindowFocus() {
56
+ return setWindowFocused(true);
57
+ };
58
+
59
+ var onWindowBlur = function onWindowBlur() {
60
+ return setWindowFocused(false);
61
+ };
62
+
63
+ window.addEventListener('focus', onWindowFocus);
64
+ window.addEventListener('blur', onWindowBlur);
65
+ return function () {
66
+ window.removeEventListener('focus', onWindowFocus);
67
+ window.removeEventListener('blur', onWindowBlur);
68
+ };
69
+ }, []);
70
+ useEffect(function () {
71
+ if (containerHasFocus && !isEditing) {
72
+ ref.current.onkeydown = ref.current.onkeyup = function (event) {
73
+ // If keydown, we will add the new key to the keysPressedList array
74
+ if (event.type === 'keydown') {
75
+ // Prevent multiple keys of the same type being added to our keysPressedList array
76
+ if (keysPressedList.includes(event.code)) {
77
+ return;
78
+ } // Because keyup events are lost when using the Command key
79
+ // we need to remove the previously pressed keys so that we
80
+ // do not have keys in the pressed list that should not be
81
+
82
+
83
+ if (includesResourceKey(keysPressedList, usingMac) && keysPressedList.length > 1) {
84
+ var clonedKeys = _toConsumableArray(keysPressedList);
85
+
86
+ var filteredClonedKeys = clonedKeys.filter(function (item) {
87
+ return item === 'MetaLeft' || item === 'MetaRight';
88
+ });
89
+ filteredClonedKeys.push(event.code);
90
+ return setKeysPressedList(_toConsumableArray(new Set(filteredClonedKeys)));
91
+ }
92
+
93
+ var tempKeys = _toConsumableArray(keysPressedList);
94
+
95
+ tempKeys.push(event.code);
96
+ setKeysPressedList(_toConsumableArray(new Set(tempKeys)));
97
+ } // If keyup, we will remove the key from the keysPressedList array
98
+
99
+
100
+ if (event.type === 'keyup') {
101
+ var _tempKeys = _toConsumableArray(keysPressedList);
102
+
103
+ var filteredClone = _tempKeys.filter(function (item) {
104
+ return item !== event.code;
105
+ }); // Keyup events are lost on all other keys if a Meta key is used
106
+ // so to work around this behavior, we empty out all other keys
107
+ // from the keysPressedList array if we detect a Meta keyup event
108
+
109
+
110
+ if (event.code === 'MetaLeft' || event.code === 'MetaRight') {
111
+ return setKeysPressedList([]);
112
+ }
113
+
114
+ setKeysPressedList(_toConsumableArray(new Set(filteredClone)));
115
+ }
116
+ };
117
+ }
118
+
119
+ if (previousState !== null && previousState !== void 0 && previousState.windowFocused && !windowFocused) {
120
+ setKeysPressedList([]);
121
+ } // Remove handlers if the spreadsheet container loses focus
122
+ // or is currently in edit mode
123
+
124
+
125
+ if (!containerHasFocus || isEditing) {
126
+ ref.current.onkeydown = undefined;
127
+ ref.current.onkeyup = undefined;
128
+
129
+ if (!(previousState !== null && previousState !== void 0 && previousState.isEditing) && isEditing) {
130
+ setKeysPressedList([]);
131
+ }
132
+ }
133
+ }, [keysPressedList, containerHasFocus, ref, isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing, windowFocused, previousState === null || previousState === void 0 ? void 0 : previousState.windowFocused, usingMac]);
134
+ return {
135
+ keysPressedList: keysPressedList,
136
+ windowFocused: windowFocused,
137
+ usingMac: usingMac
138
+ };
139
+ };
@@ -7,8 +7,7 @@
7
7
  import { useEffect } from 'react';
8
8
  import { pkg } from '../../../settings';
9
9
  export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
10
- var activeKeys = _ref.activeKeys,
11
- _ref$blockClass = _ref.blockClass,
10
+ var _ref$blockClass = _ref.blockClass,
12
11
  blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
13
12
  focusedElement = _ref.focusedElement,
14
13
  removeActiveCell = _ref.removeActiveCell,
@@ -18,11 +17,10 @@ export var useResetSpreadsheetFocus = function useResetSpreadsheetFocus(_ref) {
18
17
  if (!focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
19
18
  setContainerHasFocus(false);
20
19
  removeActiveCell();
21
- activeKeys.current = [];
22
20
  }
23
21
 
24
22
  if (focusedElement.classList.contains(blockClass) || focusedElement.classList.contains("".concat(blockClass, "--interactive-cell-element"))) {
25
23
  setContainerHasFocus(true);
26
24
  }
27
- }, [focusedElement, removeActiveCell, activeKeys, blockClass, setContainerHasFocus]);
25
+ }, [focusedElement, removeActiveCell, blockClass, setContainerHasFocus]);
28
26
  };
@@ -0,0 +1,68 @@
1
+ // /**
2
+ // * Copyright IBM Corp. 2022, 2022
3
+ // *
4
+ // * This source code is licensed under the Apache-2.0 license found in the
5
+ // * LICENSE file in the root directory of this source tree.
6
+ // */
7
+ import { useEffect } from 'react';
8
+ import { px } from '@carbon/layout';
9
+ export var useSpreadsheetEdit = function useSpreadsheetEdit(_ref) {
10
+ var isEditing = _ref.isEditing,
11
+ rows = _ref.rows,
12
+ activeCellCoordinates = _ref.activeCellCoordinates,
13
+ activeCellRef = _ref.activeCellRef,
14
+ cellEditorRef = _ref.cellEditorRef,
15
+ cellEditorRulerRef = _ref.cellEditorRulerRef,
16
+ columns = _ref.columns,
17
+ defaultColumn = _ref.defaultColumn,
18
+ cellEditorValue = _ref.cellEditorValue;
19
+ useEffect(function () {
20
+ if (isEditing) {
21
+ var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
22
+
23
+ var cellProps = (_rows$activeCellCoord = rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row]) === null || _rows$activeCellCoord === void 0 ? void 0 : _rows$activeCellCoord.cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column];
24
+ var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
25
+ var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
26
+ cellEditorRef.current.style.left = activeCellLeftPosition;
27
+ cellEditorRef.current.style.top = activeCellTopPosition;
28
+ cellEditorRef.current.style.display = 'block';
29
+ cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
30
+ cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
31
+ cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2 - 1, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
32
+
33
+ cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
34
+ (_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
35
+ var rulerWidth = cellEditorRulerRef.current.offsetWidth;
36
+ var cellWidth = activeCellRef.current.offsetWidth;
37
+
38
+ if (rulerWidth >= cellWidth) {
39
+ var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
40
+ var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
41
+ var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
42
+ var totalColumns = columns.length;
43
+ var totalRows = rows.length;
44
+ var totalMultiplierPossible = totalColumns - startingColumnPosition;
45
+ var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
46
+ cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
47
+ cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
48
+ cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
49
+ // Cell editor has reached max height, we need to add the scrolling back.
50
+ // We also need to subtract 1 to account for the fact that the cell editor
51
+ // is placed one pixel below the cell being edited to account for the border
52
+
53
+ if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
54
+ cellEditorRef.current.style.overflow = 'auto';
55
+ } else {
56
+ cellEditorRef.current.style.overflow = 'hidden';
57
+ }
58
+ }
59
+ }
60
+
61
+ if (!isEditing) {
62
+ cellEditorRef.current.style.overflow = 'hidden';
63
+ cellEditorRef.current.style.display = 'none';
64
+ cellEditorRef.current.blur();
65
+ activeCellRef.current.focus();
66
+ }
67
+ }, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn, cellEditorValue, activeCellRef, cellEditorRef, cellEditorRulerRef]);
68
+ };
@@ -16,7 +16,6 @@ export var useSpreadsheetOutsideClick = function useSpreadsheetOutsideClick(_ref
16
16
  setSelectionAreas = _ref.setSelectionAreas,
17
17
  removeActiveCell = _ref.removeActiveCell,
18
18
  setContainerHasFocus = _ref.setContainerHasFocus,
19
- activeKeys = _ref.activeKeys,
20
19
  removeCellEditor = _ref.removeCellEditor;
21
20
  useEffect(function () {
22
21
  var handleOutsideClick = function handleOutsideClick(event) {
@@ -32,12 +31,11 @@ export var useSpreadsheetOutsideClick = function useSpreadsheetOutsideClick(_ref
32
31
  });
33
32
  setContainerHasFocus(false);
34
33
  removeCellEditor();
35
- activeKeys.current = [];
36
34
  };
37
35
 
38
36
  document.addEventListener('click', handleOutsideClick);
39
37
  return function () {
40
38
  document.removeEventListener('click', handleOutsideClick);
41
39
  };
42
- }, [spreadsheetRef, removeActiveCell, activeKeys, blockClass, setActiveCellCoordinates, setContainerHasFocus, setSelectionAreas, removeCellEditor]);
40
+ }, [spreadsheetRef, removeActiveCell, blockClass, setActiveCellCoordinates, setContainerHasFocus, setSelectionAreas, removeCellEditor]);
43
41
  };
@@ -6,22 +6,34 @@
6
6
  */
7
7
  import { px } from '@carbon/layout';
8
8
  import { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
9
+ import { getSelectionAreaPoints } from './getSelectionAreaPoints';
9
10
  export var createCellSelectionArea = function createCellSelectionArea(_ref) {
10
- var area = _ref.area,
11
+ var ref = _ref.ref,
12
+ area = _ref.area,
11
13
  blockClass = _ref.blockClass,
12
14
  defaultColumn = _ref.defaultColumn,
13
15
  selectionAreas = _ref.selectionAreas,
14
- setSelectionAreas = _ref.setSelectionAreas;
15
- var greatestRow = Math.max(area.point1.row, area.point2.row);
16
- var greatestColumn = Math.max(area.point1.column, area.point2.column);
17
- var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
18
- var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
16
+ setSelectionAreas = _ref.setSelectionAreas,
17
+ setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
18
+
19
+ var _getSelectionAreaPoin = getSelectionAreaPoints(area),
20
+ lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
21
+ lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
22
+ greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
23
+ greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex;
24
+
25
+ if (greatestRowIndex - lowestRowIndex > 0 || greatestColumnIndex - lowestColumnIndex > 0) {
26
+ setActiveCellInsideSelectionArea(true);
27
+ var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
28
+ activeCellElement.setAttribute('data-selection-id', area.matcher);
29
+ }
30
+
19
31
  var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]")) || document.querySelector(".".concat(blockClass, "__body--td")); // if we can't find the point1 element (this can happen in the case where a virtualized row is not present anymore in the DOM), we get the default height/width of the first body cell we find
20
32
 
21
33
  var selectionAreaCellWidth = point1Element.offsetWidth;
22
34
  var selectionAreaCellHeight = point1Element.offsetHeight;
23
- var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumn - lowestColumnIndex + 1);
24
- var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRow - lowestRowIndex + 1);
35
+ var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumnIndex - lowestColumnIndex + 1);
36
+ var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRowIndex - lowestRowIndex + 1);
25
37
  var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
26
38
  var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
27
39
  var relativePosition = {