@carbon/ibm-products 1.12.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css +47 -0
  2. package/css/components/Datagrid/styles/addons/CustomizeColumnsModal.css.map +1 -0
  3. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css +20 -0
  4. package/css/components/Datagrid/styles/addons/RowSizeDropdown.css.map +1 -0
  5. package/css/components/Datagrid/styles/datagrid.css +264 -0
  6. package/css/components/Datagrid/styles/datagrid.css.map +1 -0
  7. package/css/components/Datagrid/styles/index.css +509 -0
  8. package/css/components/Datagrid/styles/index.css.map +1 -0
  9. package/css/components/Datagrid/styles/useActionsColumn.css +23 -0
  10. package/css/components/Datagrid/styles/useActionsColumn.css.map +1 -0
  11. package/css/components/Datagrid/styles/useColumnRightAlign.css +28 -0
  12. package/css/components/Datagrid/styles/useColumnRightAlign.css.map +1 -0
  13. package/css/components/Datagrid/styles/useNestedRows.css +15 -0
  14. package/css/components/Datagrid/styles/useNestedRows.css.map +1 -0
  15. package/css/components/Datagrid/styles/useNestedTable.css +25 -0
  16. package/css/components/Datagrid/styles/useNestedTable.css.map +1 -0
  17. package/css/components/Datagrid/styles/useSelectAllToggle.css +28 -0
  18. package/css/components/Datagrid/styles/useSelectAllToggle.css.map +1 -0
  19. package/css/components/Datagrid/styles/useSortableColumns.css +50 -0
  20. package/css/components/Datagrid/styles/useSortableColumns.css.map +1 -0
  21. package/css/components/Datagrid/styles/useStickyColumn.css +35 -0
  22. package/css/components/Datagrid/styles/useStickyColumn.css.map +1 -0
  23. package/css/index-full-carbon.css +653 -21
  24. package/css/index-full-carbon.css.map +1 -1
  25. package/css/index-full-carbon.min.css +6 -6
  26. package/css/index-full-carbon.min.css.map +1 -1
  27. package/css/index-without-carbon-released-only.css +21 -10
  28. package/css/index-without-carbon-released-only.css.map +1 -1
  29. package/css/index-without-carbon-released-only.min.css +2 -2
  30. package/css/index-without-carbon-released-only.min.css.map +1 -1
  31. package/css/index-without-carbon.css +653 -21
  32. package/css/index-without-carbon.css.map +1 -1
  33. package/css/index-without-carbon.min.css +5 -5
  34. package/css/index-without-carbon.min.css.map +1 -1
  35. package/css/index.css +653 -21
  36. package/css/index.css.map +1 -1
  37. package/css/index.min.css +6 -6
  38. package/css/index.min.css.map +1 -1
  39. package/es/components/ActionBar/ActionBar.js +3 -1
  40. package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
  41. package/es/components/AddSelect/AddSelect.js +98 -40
  42. package/es/components/AddSelect/AddSelectFilter.js +129 -0
  43. package/es/components/AddSelect/AddSelectList.js +27 -1
  44. package/es/components/AddSelect/AddSelectSidebar.js +15 -5
  45. package/es/components/AddSelect/add-select-utils.js +30 -0
  46. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  47. package/es/components/DataSpreadsheet/DataSpreadsheet.js +269 -142
  48. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +122 -39
  49. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +46 -17
  50. package/es/components/DataSpreadsheet/hooks/index.js +11 -0
  51. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +139 -0
  52. package/es/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  53. package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -0
  54. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -6
  55. package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
  56. package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
  57. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
  58. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
  59. package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
  60. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +42 -8
  61. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +225 -13
  62. package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
  63. package/es/components/Datagrid/Datagrid/Datagrid.js +70 -0
  64. package/es/components/Datagrid/Datagrid/DatagridBody.js +36 -0
  65. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +19 -0
  66. package/es/components/Datagrid/Datagrid/DatagridExpandedRow.js +26 -0
  67. package/es/components/Datagrid/Datagrid/DatagridHead.js +31 -0
  68. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +57 -0
  69. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +37 -0
  70. package/es/components/Datagrid/Datagrid/DatagridRow.js +50 -0
  71. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +50 -0
  72. package/es/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +122 -0
  73. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +36 -0
  74. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +22 -0
  75. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +87 -0
  76. package/es/components/Datagrid/Datagrid/DraggableElement.js +188 -0
  77. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +78 -0
  78. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +51 -0
  79. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +140 -0
  80. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +157 -0
  81. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +62 -0
  82. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +13 -0
  83. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +9 -0
  84. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +62 -0
  85. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +139 -0
  86. package/es/components/Datagrid/Datagrid/addons/RowSize/index.js +8 -0
  87. package/es/components/Datagrid/Datagrid/index.js +8 -0
  88. package/es/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +6 -0
  89. package/es/components/Datagrid/Datagrid.stories/LeftPanelStory.js +6 -0
  90. package/es/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +6 -0
  91. package/es/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +6 -0
  92. package/es/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +92 -0
  93. package/es/components/Datagrid/Datagrid.stories/common.js +199 -0
  94. package/es/components/Datagrid/Datagrid.stories/index.js +5 -0
  95. package/es/components/Datagrid/common-column-ids.js +8 -0
  96. package/es/components/Datagrid/index.js +22 -0
  97. package/es/components/Datagrid/useActionsColumn.js +86 -0
  98. package/es/components/Datagrid/useColumnRightAlign.js +52 -0
  99. package/es/components/Datagrid/useCustomizeColumns.js +45 -0
  100. package/es/components/Datagrid/useDatagrid.js +44 -0
  101. package/es/components/Datagrid/useDefaultStringRenderer.js +48 -0
  102. package/es/components/Datagrid/useDisableSelectRows.js +84 -0
  103. package/es/components/Datagrid/useExpandedRow.js +52 -0
  104. package/es/components/Datagrid/useFlexResize.js +51 -0
  105. package/es/components/Datagrid/useFloatingScroll.js +88 -0
  106. package/es/components/Datagrid/useInfiniteScroll.js +54 -0
  107. package/es/components/Datagrid/useNestedRows.js +53 -0
  108. package/es/components/Datagrid/useOnRowClick.js +37 -0
  109. package/es/components/Datagrid/useParentDimensions.js +65 -0
  110. package/es/components/Datagrid/useResizeTable.js +40 -0
  111. package/es/components/Datagrid/useRowExpander.js +34 -0
  112. package/es/components/Datagrid/useRowIsMouseOver.js +61 -0
  113. package/es/components/Datagrid/useRowRenderer.js +30 -0
  114. package/es/components/Datagrid/useRowSize.js +56 -0
  115. package/es/components/Datagrid/useSelectAllToggle.js +74 -0
  116. package/es/components/Datagrid/useSelectRows.js +107 -0
  117. package/es/components/Datagrid/useSkeletonRows.js +32 -0
  118. package/es/components/Datagrid/useSortableColumns.js +110 -0
  119. package/es/components/Datagrid/useStickyColumn.js +183 -0
  120. package/es/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  121. package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  122. package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  123. package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
  124. package/es/components/PageHeader/PageHeader.js +3 -1
  125. package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
  126. package/es/components/TagSet/TagSet.js +22 -6
  127. package/es/components/Tearsheet/TearsheetShell.js +34 -10
  128. package/es/components/UserProfileImage/UserProfileImage.js +37 -9
  129. package/es/components/index.js +2 -1
  130. package/es/global/js/package-settings.js +4 -2
  131. package/lib/components/ActionBar/ActionBar.js +3 -1
  132. package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
  133. package/lib/components/AddSelect/AddSelect.js +97 -38
  134. package/lib/components/AddSelect/AddSelectFilter.js +147 -0
  135. package/lib/components/AddSelect/AddSelectList.js +28 -1
  136. package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
  137. package/lib/components/AddSelect/add-select-utils.js +35 -2
  138. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  139. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +279 -145
  140. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +121 -45
  141. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +47 -17
  142. package/lib/components/DataSpreadsheet/hooks/index.js +45 -0
  143. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +151 -0
  144. package/lib/components/DataSpreadsheet/hooks/useResetSpreadsheetFocus.js +2 -4
  145. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +79 -0
  146. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -5
  147. package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
  148. package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
  149. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
  150. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
  151. package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
  152. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +44 -8
  153. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +235 -20
  154. package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
  155. package/lib/components/Datagrid/Datagrid/Datagrid.js +86 -0
  156. package/lib/components/Datagrid/Datagrid/DatagridBody.js +50 -0
  157. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +31 -0
  158. package/lib/components/Datagrid/Datagrid/DatagridExpandedRow.js +38 -0
  159. package/lib/components/Datagrid/Datagrid/DatagridHead.js +43 -0
  160. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +73 -0
  161. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +44 -0
  162. package/lib/components/Datagrid/Datagrid/DatagridRow.js +56 -0
  163. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +55 -0
  164. package/lib/components/Datagrid/Datagrid/DatagridSelectAllWithToggle.js +139 -0
  165. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +44 -0
  166. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +35 -0
  167. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +101 -0
  168. package/lib/components/Datagrid/Datagrid/DraggableElement.js +210 -0
  169. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +92 -0
  170. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ButtonWrapper.js +65 -0
  171. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +166 -0
  172. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +173 -0
  173. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +73 -0
  174. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/common.js +25 -0
  175. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/index.js +23 -0
  176. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +80 -0
  177. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +160 -0
  178. package/lib/components/Datagrid/Datagrid/addons/RowSize/index.js +15 -0
  179. package/lib/components/Datagrid/Datagrid/index.js +15 -0
  180. package/lib/components/Datagrid/Datagrid.stories/CustomizeColumnStory.js +13 -0
  181. package/lib/components/Datagrid/Datagrid.stories/LeftPanelStory.js +13 -0
  182. package/lib/components/Datagrid/Datagrid.stories/RowSizeDropdownStory.js +13 -0
  183. package/lib/components/Datagrid/Datagrid.stories/SelectAllWithToggleStory.js +13 -0
  184. package/lib/components/Datagrid/Datagrid.stories/StickyActionsColumnStory.js +112 -0
  185. package/lib/components/Datagrid/Datagrid.stories/common.js +215 -0
  186. package/lib/components/Datagrid/Datagrid.stories/index.js +47 -0
  187. package/lib/components/Datagrid/common-column-ids.js +16 -0
  188. package/lib/components/Datagrid/index.js +127 -0
  189. package/lib/components/Datagrid/useActionsColumn.js +94 -0
  190. package/lib/components/Datagrid/useColumnRightAlign.js +59 -0
  191. package/lib/components/Datagrid/useCustomizeColumns.js +55 -0
  192. package/lib/components/Datagrid/useDatagrid.js +58 -0
  193. package/lib/components/Datagrid/useDefaultStringRenderer.js +54 -0
  194. package/lib/components/Datagrid/useDisableSelectRows.js +92 -0
  195. package/lib/components/Datagrid/useExpandedRow.js +58 -0
  196. package/lib/components/Datagrid/useFlexResize.js +61 -0
  197. package/lib/components/Datagrid/useFloatingScroll.js +101 -0
  198. package/lib/components/Datagrid/useInfiniteScroll.js +67 -0
  199. package/lib/components/Datagrid/useNestedRows.js +65 -0
  200. package/lib/components/Datagrid/useOnRowClick.js +45 -0
  201. package/lib/components/Datagrid/useParentDimensions.js +75 -0
  202. package/lib/components/Datagrid/useResizeTable.js +48 -0
  203. package/lib/components/Datagrid/useRowExpander.js +45 -0
  204. package/lib/components/Datagrid/useRowIsMouseOver.js +66 -0
  205. package/lib/components/Datagrid/useRowRenderer.js +40 -0
  206. package/lib/components/Datagrid/useRowSize.js +67 -0
  207. package/lib/components/Datagrid/useSelectAllToggle.js +88 -0
  208. package/lib/components/Datagrid/useSelectRows.js +119 -0
  209. package/lib/components/Datagrid/useSkeletonRows.js +42 -0
  210. package/lib/components/Datagrid/useSortableColumns.js +117 -0
  211. package/lib/components/Datagrid/useStickyColumn.js +190 -0
  212. package/lib/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  213. package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  214. package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  215. package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
  216. package/lib/components/PageHeader/PageHeader.js +3 -1
  217. package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
  218. package/lib/components/TagSet/TagSet.js +22 -6
  219. package/lib/components/Tearsheet/TearsheetShell.js +36 -10
  220. package/lib/components/UserProfileImage/UserProfileImage.js +37 -9
  221. package/lib/components/index.js +9 -1
  222. package/lib/global/js/package-settings.js +4 -2
  223. package/package.json +20 -16
  224. package/scss/components/AboutModal/_about-modal.scss +4 -0
  225. package/scss/components/AddSelect/_add-select.scss +51 -2
  226. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +72 -9
  227. package/scss/components/Datagrid/_datagrid.scss +66 -0
  228. package/scss/components/Datagrid/_index.scss +8 -0
  229. package/scss/components/Datagrid/_storybook-styles.scss +26 -0
  230. package/scss/components/Datagrid/styles/_variables.scss +9 -0
  231. package/scss/components/Datagrid/styles/addons/CustomizeColumnsModal.scss +48 -0
  232. package/scss/components/Datagrid/styles/addons/RowSizeDropdown.scss +23 -0
  233. package/scss/components/Datagrid/styles/datagrid.scss +318 -0
  234. package/scss/components/Datagrid/styles/index.scss +17 -0
  235. package/scss/components/Datagrid/styles/useActionsColumn.scss +24 -0
  236. package/scss/components/Datagrid/styles/useColumnRightAlign.scss +29 -0
  237. package/scss/components/Datagrid/styles/useNestedRows.scss +17 -0
  238. package/scss/components/Datagrid/styles/useNestedTable.scss +28 -0
  239. package/scss/components/Datagrid/styles/useSelectAllToggle.scss +28 -0
  240. package/scss/components/Datagrid/styles/useSortableColumns.scss +55 -0
  241. package/scss/components/Datagrid/styles/useStickyColumn.scss +38 -0
  242. package/scss/components/ExportModal/_export-modal.scss +0 -4
  243. package/scss/components/HTTPErrors/_http-errors.scss +16 -16
  244. package/scss/components/PageHeader/_page-header.scss +4 -0
  245. package/scss/components/Tearsheet/_tearsheet.scss +4 -0
  246. package/scss/components/_index.scss +1 -0
@@ -1,9 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _typeof from "@babel/runtime/helpers/typeof";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
6
- var _excluded = ["cellSize", "className", "columns", "data", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
6
+ var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
7
7
 
8
8
  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; }
9
9
 
@@ -29,13 +29,17 @@ import { getDevtoolsProps } from '../../global/js/utils/devtools';
29
29
  import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
30
30
  import { useActiveElement, usePreviousValue } from '../../global/js/hooks';
31
31
  import uuidv4 from '../../global/js/utils/uuidv4';
32
- import { useResetSpreadsheetFocus } from './hooks/useResetSpreadsheetFocus';
33
- import { useSpreadsheetOutsideClick } from './hooks/useSpreadsheetOutsideClick';
34
- import { useMoveActiveCell } from './hooks/useMoveActiveCell';
32
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
33
+ import { useResetSpreadsheetFocus, useSpreadsheetOutsideClick, useMoveActiveCell, useMultipleKeyTracking, useSpreadsheetEdit } from './hooks';
35
34
  import { createActiveCellFn } from './utils/createActiveCellFn';
36
35
  import { getCellSize } from './utils/getCellSize';
37
- import { handleMultipleKeys } from './utils/handleMultipleKeys';
38
- import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection'; // cspell:words rowcount colcount
36
+ import { handleMultipleKeys, includesResourceKey, includesShift } from './utils/handleMultipleKeys';
37
+ import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
38
+ import { removeCellSelections } from './utils/removeCellSelections';
39
+ import { selectAllCells } from './utils/selectAllCells';
40
+ import { handleEditSubmit } from './utils/handleEditSubmit';
41
+ import { handleActiveCellInSelectionEnter } from './utils/handleActiveCellInSelectionEnter';
42
+ import { handleActiveCellInSelectionTab } from './utils/handleActiveCellInSelectionTab'; // cspell:words rowcount colcount
39
43
  // The block part of our conventional BEM class names (blockClass__E--M).
40
44
 
41
45
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
@@ -45,6 +49,7 @@ var defaults = {
45
49
  cellSize: 'standard',
46
50
  columns: Object.freeze([]),
47
51
  data: Object.freeze([]),
52
+ defaultEmptyRowCount: 16,
48
53
  onDataUpdate: Object.freeze(function () {}),
49
54
  onActiveCellChange: Object.freeze(function () {}),
50
55
  onSelectionAreaChange: Object.freeze(function () {})
@@ -61,6 +66,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
61
66
  columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
62
67
  _ref$data = _ref.data,
63
68
  data = _ref$data === void 0 ? defaults.data : _ref$data,
69
+ _ref$defaultEmptyRowC = _ref.defaultEmptyRowCount,
70
+ defaultEmptyRowCount = _ref$defaultEmptyRowC === void 0 ? defaults.defaultEmptyRowCount : _ref$defaultEmptyRowC,
64
71
  _ref$onDataUpdate = _ref.onDataUpdate,
65
72
  onDataUpdate = _ref$onDataUpdate === void 0 ? defaults.onDataUpdate : _ref$onDataUpdate,
66
73
  id = _ref.id,
@@ -70,6 +77,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
70
77
  onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
71
78
  rest = _objectWithoutProperties(_ref, _excluded);
72
79
 
80
+ var multiKeyTrackingRef = useRef();
73
81
  var localRef = useRef();
74
82
  var spreadsheetRef = ref || localRef;
75
83
  var focusedElement = useActiveElement();
@@ -114,19 +122,25 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
114
122
  cellEditorValue = _useState16[0],
115
123
  setCellEditorValue = _useState16[1];
116
124
 
125
+ var _useState17 = useState(false),
126
+ _useState18 = _slicedToArray(_useState17, 2),
127
+ activeCellInsideSelectionArea = _useState18[0],
128
+ setActiveCellInsideSelectionArea = _useState18[1];
129
+
117
130
  var previousState = usePreviousValue({
118
- activeCellCoordinates: activeCellCoordinates
131
+ activeCellCoordinates: activeCellCoordinates,
132
+ isEditing: isEditing
119
133
  });
120
134
  var cellSizeValue = getCellSize(cellSize);
121
135
  var cellEditorRef = useRef();
122
136
 
123
- var _useState17 = useState(),
124
- _useState18 = _slicedToArray(_useState17, 2),
125
- activeCellContent = _useState18[0],
126
- setActiveCellContent = _useState18[1];
137
+ var _useState19 = useState(),
138
+ _useState20 = _slicedToArray(_useState19, 2),
139
+ activeCellContent = _useState20[0],
140
+ setActiveCellContent = _useState20[1];
127
141
 
128
- var activeKeys = useRef([]);
129
142
  var activeCellRef = useRef();
143
+ var cellEditorRulerRef = useRef();
130
144
  var defaultColumn = useMemo(function () {
131
145
  return {
132
146
  width: 150,
@@ -134,6 +148,15 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
134
148
  rowHeight: cellSizeValue
135
149
  };
136
150
  }, [cellSizeValue]);
151
+
152
+ var _useMultipleKeyTracki = useMultipleKeyTracking({
153
+ ref: multiKeyTrackingRef,
154
+ containerHasFocus: containerHasFocus,
155
+ isEditing: isEditing
156
+ }),
157
+ keysPressedList = _useMultipleKeyTracki.keysPressedList,
158
+ usingMac = _useMultipleKeyTracki.usingMac;
159
+
137
160
  var scrollBarSize = useMemo(function () {
138
161
  return getScrollbarWidth();
139
162
  }, []);
@@ -174,23 +197,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
174
197
  setCellEditorValue('');
175
198
  setIsEditing(false);
176
199
  cellEditorRef.current.style.display = 'none';
177
- }, []); // Removes the cell selection elements
178
-
179
- var removeCellSelections = useCallback(function (matcher) {
180
- if (matcher && typeof matcher === 'string') {
181
- var selectionToRemove = spreadsheetRef.current.querySelector("[data-matcher-id=\"".concat(matcher, "\"]"));
182
-
183
- if (selectionToRemove) {
184
- selectionToRemove.remove();
185
- }
186
- } else {
187
- var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
188
-
189
- _toConsumableArray(cellSelections).forEach(function (element) {
190
- return element.remove();
191
- });
192
- }
193
- }, [spreadsheetRef]); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
200
+ }, []); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
194
201
  // happen if you click on another cell while isEditing is true
195
202
 
196
203
  useEffect(function () {
@@ -200,6 +207,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
200
207
  var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
201
208
  removeCellEditor();
202
209
  updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
210
+ cellEditorRulerRef.current.textContent = '';
203
211
  }
204
212
 
205
213
  if ((prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) || (prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column)) {
@@ -238,7 +246,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
238
246
  }
239
247
  }, [spreadsheetRef, rows, onActiveCellChange, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, defaultColumn]);
240
248
  useResetSpreadsheetFocus({
241
- activeKeys: activeKeys,
242
249
  focusedElement: focusedElement,
243
250
  removeActiveCell: removeActiveCell,
244
251
  setContainerHasFocus: setContainerHasFocus
@@ -250,7 +257,6 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
250
257
  removeActiveCell: removeActiveCell,
251
258
  removeCellSelections: removeCellSelections,
252
259
  setContainerHasFocus: setContainerHasFocus,
253
- activeKeys: activeKeys,
254
260
  removeCellEditor: removeCellEditor
255
261
  });
256
262
  useMoveActiveCell({
@@ -262,6 +268,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
262
268
  var handleInitialArrowPress = useCallback(function () {
263
269
  // If activeCellCoordinates is null then we need to set an initial value
264
270
  // which will place the activeCell on the select all cell/button
271
+ setActiveCellInsideSelectionArea(false);
272
+
265
273
  if (!activeCellCoordinates) {
266
274
  setActiveCellCoordinates({
267
275
  column: 'header',
@@ -272,16 +280,20 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
272
280
  return;
273
281
  }, [activeCellCoordinates]);
274
282
  var updateActiveCellCoordinates = useCallback(function (_ref3) {
275
- var coords = _ref3.coords,
276
- updatedValue = _ref3.updatedValue;
283
+ var _ref3$coords = _ref3.coords,
284
+ coords = _ref3$coords === void 0 ? _objectSpread({}, activeCellCoordinates) : _ref3$coords,
285
+ updatedValue = _ref3.updatedValue,
286
+ _ref3$optOutOfSelecti = _ref3.optOutOfSelectionAreaUpdate,
287
+ optOutOfSelectionAreaUpdate = _ref3$optOutOfSelecti === void 0 ? false : _ref3$optOutOfSelecti;
277
288
 
278
289
  var newActiveCell = _objectSpread(_objectSpread({}, coords), updatedValue);
279
290
 
280
291
  setActiveCellCoordinates(newActiveCell); // Only run if the active cell is _not_ a header cell. This will add a point1 object
281
292
  // to selectionAreas every time the active cell changes, allowing us to create cell
282
- // selections using keyboard
293
+ // selections using keyboard. Opting out of the selection area updates here means
294
+ // that the active cell is being moved within a selection area
283
295
 
284
- if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header') {
296
+ if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header' && !optOutOfSelectionAreaUpdate) {
285
297
  var tempMatcher = uuidv4();
286
298
  setSelectionAreas([{
287
299
  point1: newActiveCell,
@@ -289,11 +301,29 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
289
301
  }]);
290
302
  setCurrentMatcher(tempMatcher);
291
303
  }
292
- }, []);
304
+ }, [activeCellCoordinates]);
305
+ var handleHomeEndKey = useCallback(function (_ref4) {
306
+ var type = _ref4.type;
307
+
308
+ var coordinatesClone = _objectSpread({}, activeCellCoordinates);
309
+
310
+ updateActiveCellCoordinates({
311
+ coords: coordinatesClone,
312
+ updatedValue: {
313
+ column: type === 'home' ? 0 : columns.length - 1
314
+ }
315
+ });
316
+ removeCellSelections({
317
+ spreadsheetRef: spreadsheetRef
318
+ });
319
+ }, [activeCellCoordinates, updateActiveCellCoordinates, spreadsheetRef, columns.length]);
293
320
  var handleKeyPress = useCallback(function (event) {
294
- var _activeKeys$current, _activeKeys$current2;
321
+ var key = event.key;
322
+
323
+ if (isEditing) {
324
+ return;
325
+ } // Command keys need to be returned as there is default browser behavior with these keys
295
326
 
296
- var key = event.key; // Command keys need to be returned as there is default browser behavior with these keys
297
327
 
298
328
  if (key === 'Meta' || key === 'Control') {
299
329
  return;
@@ -310,44 +340,90 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
310
340
 
311
341
 
312
342
  if (['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1) {
313
- if (isEditing) {
314
- return;
315
- }
316
-
317
- if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
343
+ if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && keysPressedList.length < 2 && !includesShift(keysPressedList)) {
318
344
  setSelectionAreas([]);
319
345
  setSelectionAreaData([]);
320
346
  removeCellSelections({
321
347
  spreadsheetRef: spreadsheetRef
322
348
  });
323
349
  }
324
- } // Update list of activeKeys
325
-
326
-
327
- if (!((_activeKeys$current = activeKeys.current) !== null && _activeKeys$current !== void 0 && _activeKeys$current.includes(key))) {
328
- var activeClone = _toConsumableArray(activeKeys.current);
329
-
330
- activeKeys.current = [].concat(_toConsumableArray(activeClone), [key]);
331
350
  }
332
351
 
333
- if (((_activeKeys$current2 = activeKeys.current) === null || _activeKeys$current2 === void 0 ? void 0 : _activeKeys$current2.length) > 1) {
352
+ if (!isEditing && (keysPressedList === null || keysPressedList === void 0 ? void 0 : keysPressedList.length) > 1) {
334
353
  handleMultipleKeys({
335
- activeKeys: activeKeys,
354
+ activeCellCoordinates: activeCellCoordinates,
355
+ event: event,
356
+ keysPressedList: keysPressedList,
336
357
  selectionAreas: selectionAreas,
337
358
  currentMatcher: currentMatcher,
338
359
  rows: rows,
339
360
  setSelectionAreas: setSelectionAreas,
340
- columns: columns
361
+ columns: columns,
362
+ updateActiveCellCoordinates: updateActiveCellCoordinates,
363
+ spreadsheetRef: spreadsheetRef,
364
+ removeCellSelections: removeCellSelections,
365
+ blockClass: blockClass,
366
+ setCurrentMatcher: setCurrentMatcher,
367
+ usingMac: usingMac
341
368
  });
342
369
  } // Allow arrow key navigation if there are less than two activeKeys OR
343
370
  // if one of the activeCellCoordinates is in a header position
344
371
 
345
372
 
346
- if (!activeKeys.current.includes('Shift') || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
373
+ if (keysPressedList.length < 2 && !includesShift(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
347
374
  switch (key) {
375
+ // Enter
376
+ case 'Enter':
377
+ {
378
+ handleActiveCellInSelectionEnter({
379
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
380
+ activeCellCoordinates: activeCellCoordinates,
381
+ activeCellRef: activeCellRef,
382
+ selectionAreas: selectionAreas,
383
+ updateActiveCellCoordinates: updateActiveCellCoordinates
384
+ });
385
+ break;
386
+ }
387
+ // HOME
388
+
389
+ case 'Home':
390
+ {
391
+ if (includesResourceKey(keysPressedList, usingMac)) {
392
+ return;
393
+ }
394
+
395
+ handleHomeEndKey({
396
+ type: 'home'
397
+ });
398
+ break;
399
+ }
400
+
401
+ case 'End':
402
+ {
403
+ if (includesResourceKey(keysPressedList, usingMac)) {
404
+ return;
405
+ }
406
+
407
+ handleHomeEndKey({
408
+ type: 'end'
409
+ });
410
+ break;
411
+ }
348
412
  // Tab
413
+
349
414
  case 'Tab':
350
415
  {
416
+ if (activeCellInsideSelectionArea) {
417
+ event.preventDefault();
418
+ return handleActiveCellInSelectionTab({
419
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
420
+ activeCellCoordinates: activeCellCoordinates,
421
+ activeCellRef: activeCellRef,
422
+ selectionAreas: selectionAreas,
423
+ updateActiveCellCoordinates: updateActiveCellCoordinates
424
+ });
425
+ }
426
+
351
427
  setSelectionAreas([]);
352
428
  removeActiveCell();
353
429
  removeCellEditor();
@@ -494,24 +570,59 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
494
570
  }
495
571
  }
496
572
  }
497
- }, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, removeCellSelections, selectionAreas]);
573
+ }, [activeCellInsideSelectionArea, updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList, usingMac]);
498
574
 
499
575
  var startEditMode = function startEditMode() {
500
576
  setIsEditing(true);
501
577
  var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
502
578
  var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
503
579
  setCellEditorValue(activeCellValue);
504
- };
580
+ cellEditorRulerRef.current.textContent = activeCellValue;
581
+ }; // Sets the initial placement of the cell editor cursor at the end of the text area
582
+ // this is not done for us by default in Safari
583
+
584
+
585
+ useEffect(function () {
586
+ if (isEditing && !(previousState !== null && previousState !== void 0 && previousState.isEditing)) {
587
+ cellEditorRef.current.setSelectionRange(cellEditorRulerRef.current.textContent.length, cellEditorRulerRef.current.textContent.length);
588
+ cellEditorRef.current.focus();
589
+ }
590
+ }, [isEditing, previousState === null || previousState === void 0 ? void 0 : previousState.isEditing]);
505
591
 
506
592
  var handleActiveCellClick = function handleActiveCellClick() {
507
593
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
508
594
  var indexValue = (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column : activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
595
+
596
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
597
+ return;
598
+ }
599
+
509
600
  handleRowColumnHeaderClick({
510
601
  isKeyboard: false,
511
602
  index: indexValue
512
603
  });
513
604
  }
514
605
 
606
+ return;
607
+ }; // Mouse down on active cell
608
+
609
+
610
+ var handleActiveCellMouseDown = function handleActiveCellMouseDown() {
611
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
612
+ var tempMatcher = uuidv4();
613
+ setClickAndHoldActive(true);
614
+ removeCellSelections({
615
+ spreadsheetRef: spreadsheetRef
616
+ });
617
+ setSelectionAreas([{
618
+ point1: activeCellCoordinates,
619
+ matcher: tempMatcher
620
+ }]);
621
+ setCurrentMatcher(tempMatcher);
622
+ setSelectionAreaData([]);
623
+ setActiveCellInsideSelectionArea(false);
624
+ }
625
+
515
626
  return;
516
627
  }; // Go into edit mode if 'Enter' key is pressed on activeCellRef
517
628
 
@@ -519,7 +630,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
519
630
  var handleActiveCellKeyDown = function handleActiveCellKeyDown(event) {
520
631
  var key = event.key;
521
632
 
522
- if (key === 'Enter') {
633
+ if (key === 'Enter' && !activeCellInsideSelectionArea) {
523
634
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
524
635
  startEditMode();
525
636
  }
@@ -532,10 +643,10 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
532
643
  }
533
644
  };
534
645
 
535
- var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref4) {
536
- var isKeyboard = _ref4.isKeyboard,
537
- _ref4$index = _ref4.index,
538
- index = _ref4$index === void 0 ? null : _ref4$index;
646
+ var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref5) {
647
+ var isKeyboard = _ref5.isKeyboard,
648
+ _ref5$index = _ref5.index,
649
+ index = _ref5$index === void 0 ? null : _ref5$index;
539
650
  var handleHeaderCellProps = {
540
651
  activeCellCoordinates: activeCellCoordinates,
541
652
  rows: rows,
@@ -549,113 +660,100 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
549
660
  index: index
550
661
  }; // Select an entire column
551
662
 
552
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
663
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
553
664
  handleHeaderCellSelection(_objectSpread({
554
665
  type: 'column'
555
666
  }, handleHeaderCellProps));
556
667
  } // Select an entire row
557
668
 
558
669
 
559
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
670
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
560
671
  handleHeaderCellSelection(_objectSpread({
561
672
  type: 'row'
562
673
  }, handleHeaderCellProps));
563
674
  }
564
- }; // Go into edit mode if double click is detected on activeCellRef
565
-
566
-
567
- var handleActiveCellDoubleClick = function handleActiveCellDoubleClick() {
568
- startEditMode();
569
- }; // Update the data
570
-
571
-
572
- var handleEditSubmit = function handleEditSubmit(event) {
573
- var key = event.key;
574
-
575
- var submitEditChanges = function submitEditChanges() {
576
- var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
577
- var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
578
- removeCellEditor();
579
- updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
580
- };
581
675
 
582
- if (key === 'Enter') {
583
- submitEditChanges();
584
- setActiveCellCoordinates(function (prev) {
585
- return _objectSpread(_objectSpread({}, prev), {}, {
586
- row: prev.row === rows.length - 1 ? prev.row : prev.row + 1 // do not move to next cell below if we're already in the last row
587
-
588
- });
676
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
677
+ selectAllCells({
678
+ ref: spreadsheetRef,
679
+ setCurrentMatcher: setCurrentMatcher,
680
+ setSelectionAreas: setSelectionAreas,
681
+ rows: rows,
682
+ columns: columns,
683
+ activeCellCoordinates: activeCellCoordinates,
684
+ updateActiveCellCoordinates: updateActiveCellCoordinates
589
685
  });
590
686
  }
687
+ }; // Go into edit mode if double click is detected on activeCellRef
591
688
 
592
- if (key === 'Tab') {
593
- event.preventDefault();
594
- submitEditChanges();
595
- setActiveCellCoordinates(function (prev) {
596
- return _objectSpread(_objectSpread({}, prev), {}, {
597
- column: prev.column === columns.length - 1 ? prev.column : prev.column + 1 // do not move to next cell below if we're already in the last column
598
-
599
- });
600
- });
601
- }
602
689
 
603
- return;
690
+ var handleActiveCellDoubleClick = function handleActiveCellDoubleClick() {
691
+ startEditMode();
604
692
  };
605
693
 
606
- useEffect(function () {
607
- if (isEditing) {
608
- var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
609
-
610
- 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];
611
- var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
612
- var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
613
- cellEditorRef.current.style.left = activeCellLeftPosition;
614
- cellEditorRef.current.style.top = activeCellTopPosition;
615
- cellEditorRef.current.style.display = 'block';
616
- cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
617
- cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
618
- 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
619
-
620
- 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';
621
- (_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
622
- }
623
-
624
- if (!isEditing) {
625
- cellEditorRef.current.style.display = 'none';
626
- cellEditorRef.current.blur();
627
- activeCellRef.current.focus();
694
+ useSpreadsheetEdit({
695
+ isEditing: isEditing,
696
+ rows: rows,
697
+ activeCellCoordinates: activeCellCoordinates,
698
+ activeCellRef: activeCellRef,
699
+ cellEditorRef: cellEditorRef,
700
+ cellEditorRulerRef: cellEditorRulerRef,
701
+ columns: columns,
702
+ defaultColumn: defaultColumn,
703
+ cellEditorValue: cellEditorValue
704
+ });
705
+ var handleActiveCellMouseEnter = useCallback(function () {
706
+ handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
707
+ }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]); // Only update if there are cell selection areas
708
+ // Find point object that matches currentMatcher and remove the second point
709
+ // because hovering over the active cell while clicking and holding should
710
+ // remove the previously existing selection area
711
+
712
+ var handleActiveCellMouseEnterCallback = useCallback(function (areas, clickHold) {
713
+ if (!currentMatcher) {
714
+ return;
628
715
  }
629
- }, [isEditing, activeCellCoordinates, rows]);
630
716
 
631
- var handleKeyUp = function handleKeyUp(event) {
632
- var _activeKeys$current3;
717
+ if (areas && areas.length && clickHold && currentMatcher) {
718
+ setSelectionAreas(function (prev) {
719
+ var selectionAreaClone = deepCloneObject(prev);
720
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
721
+ return item.matcher === currentMatcher;
722
+ });
633
723
 
634
- var key = event.key; // Remove key from active keys array on key up
724
+ if (indexOfItemToUpdate === -1) {
725
+ return prev;
726
+ }
635
727
 
636
- if ((_activeKeys$current3 = activeKeys.current) !== null && _activeKeys$current3 !== void 0 && _activeKeys$current3.includes(key)) {
637
- var activeKeysClone = _toConsumableArray(activeKeys.current);
728
+ if (_typeof(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
729
+ selectionAreaClone[indexOfItemToUpdate].point2 = selectionAreaClone[indexOfItemToUpdate].point1;
730
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
731
+ setActiveCellInsideSelectionArea(false);
732
+ removeCellSelections({
733
+ matcher: currentMatcher,
734
+ spreadsheetRef: spreadsheetRef
735
+ });
736
+ return selectionAreaClone;
737
+ }
638
738
 
639
- var filteredKeysClone = activeKeysClone.filter(function (item) {
640
- return item !== key;
739
+ return prev;
641
740
  });
642
- activeKeys.current = filteredKeysClone;
643
741
  }
644
- };
645
-
742
+ }, [spreadsheetRef, currentMatcher]);
646
743
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
647
- className: cx(blockClass, className, _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
744
+ className: cx(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
648
745
  ref: spreadsheetRef,
649
746
  role: "grid",
650
747
  tabIndex: 0,
651
748
  "aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
652
749
  "aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
653
750
  onKeyDown: handleKeyPress,
654
- onKeyUp: handleKeyUp,
655
751
  onFocus: function onFocus() {
656
752
  return setContainerHasFocus(true);
657
753
  }
658
- }), /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
754
+ }), /*#__PURE__*/React.createElement("div", {
755
+ ref: multiKeyTrackingRef
756
+ }, /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
659
757
  ref: spreadsheetRef,
660
758
  activeCellCoordinates: activeCellCoordinates,
661
759
  cellSize: cellSize,
@@ -668,7 +766,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
668
766
  setActiveCellCoordinates: setActiveCellCoordinates,
669
767
  setSelectionAreas: setSelectionAreas,
670
768
  setCurrentMatcher: setCurrentMatcher,
671
- setSelectionAreaData: setSelectionAreaData
769
+ setSelectionAreaData: setSelectionAreaData,
770
+ updateActiveCellCoordinates: updateActiveCellCoordinates
672
771
  }), /*#__PURE__*/React.createElement(DataSpreadsheetBody, {
673
772
  activeCellCoordinates: activeCellCoordinates,
674
773
  ref: spreadsheetRef,
@@ -680,8 +779,10 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
680
779
  selectionAreas: selectionAreas,
681
780
  setSelectionAreas: setSelectionAreas,
682
781
  cellSize: cellSize,
782
+ headerGroups: headerGroups,
683
783
  defaultColumn: defaultColumn,
684
784
  getTableBodyProps: getTableBodyProps,
785
+ onDataUpdate: onDataUpdate,
685
786
  onActiveCellChange: onActiveCellChange,
686
787
  onSelectionAreaChange: onSelectionAreaChange,
687
788
  prepareRow: prepareRow,
@@ -692,25 +793,46 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
692
793
  scrollBarSize: scrollBarSize,
693
794
  totalColumnsWidth: totalColumnsWidth,
694
795
  id: id,
695
- columns: columns
796
+ columns: columns,
797
+ defaultEmptyRowCount: defaultEmptyRowCount,
798
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
696
799
  }), /*#__PURE__*/React.createElement("button", {
800
+ onMouseDown: handleActiveCellMouseDown,
697
801
  onClick: handleActiveCellClick,
698
802
  onKeyDown: handleActiveCellKeyDown,
699
803
  onDoubleClick: handleActiveCellDoubleClick,
804
+ onMouseEnter: handleActiveCellMouseEnter,
700
805
  ref: activeCellRef,
701
- className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
806
+ className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight"), _defineProperty({}, "".concat(blockClass, "__active-cell--with-selection"), activeCellInsideSelectionArea)),
702
807
  type: "button"
703
808
  }, activeCellContent), /*#__PURE__*/React.createElement(TextArea, {
704
809
  value: cellEditorValue,
705
- onKeyDown: handleEditSubmit,
810
+ onKeyDown: handleEditSubmit({
811
+ activeCellCoordinates: activeCellCoordinates,
812
+ cellEditorRulerRef: cellEditorRulerRef,
813
+ columns: columns,
814
+ previousState: previousState,
815
+ removeCellEditor: removeCellEditor,
816
+ rows: rows,
817
+ setActiveCellCoordinates: setActiveCellCoordinates,
818
+ setCurrentMatcher: setCurrentMatcher,
819
+ setSelectionAreas: setSelectionAreas,
820
+ spreadsheetRef: spreadsheetRef,
821
+ updateData: updateData
822
+ }),
706
823
  onChange: function onChange(event) {
707
- return setCellEditorValue(event.target.value);
824
+ setCellEditorValue(event.target.value);
825
+ cellEditorRulerRef.current.textContent = event.target.value;
708
826
  },
709
827
  ref: cellEditorRef,
710
828
  labelText: "",
711
- "aria-labelledby": activeCellCoordinates ? "[data-row-index=\"".concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, "\"][data-column-index=\"").concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column, "\"]") : null,
829
+ "aria-labelledby": activeCellCoordinates ? "#".concat(blockClass, "__cell--").concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, "--").concat(activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) : null,
712
830
  className: cx("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), _defineProperty({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
713
- }));
831
+ }), /*#__PURE__*/React.createElement("pre", {
832
+ "aria-hidden": true,
833
+ ref: cellEditorRulerRef,
834
+ className: "".concat(blockClass, "__cell-editor-ruler")
835
+ })));
714
836
  }); // Return a placeholder if not released and not enabled by feature flag
715
837
 
716
838
  DataSpreadsheet = pkg.checkComponentEnabled(DataSpreadsheet, componentName); // The display name of the component, used by React. Note that displayName
@@ -746,6 +868,11 @@ DataSpreadsheet.propTypes = {
746
868
  */
747
869
  data: PropTypes.arrayOf(PropTypes.shape),
748
870
 
871
+ /**
872
+ * Sets the number of empty rows to be created when there is no data provided
873
+ */
874
+ defaultEmptyRowCount: PropTypes.number,
875
+
749
876
  /**
750
877
  * The spreadsheet id
751
878
  */