@carbon/ibm-products 1.11.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. package/README.md +0 -3
  2. package/css/index-full-carbon.css +1445 -369
  3. package/css/index-full-carbon.css.map +1 -1
  4. package/css/index-full-carbon.min.css +6 -6
  5. package/css/index-full-carbon.min.css.map +1 -1
  6. package/css/index-without-carbon-released-only.css +15 -6
  7. package/css/index-without-carbon-released-only.css.map +1 -1
  8. package/css/index-without-carbon-released-only.min.css +2 -2
  9. package/css/index-without-carbon-released-only.min.css.map +1 -1
  10. package/css/index-without-carbon.css +109 -16
  11. package/css/index-without-carbon.css.map +1 -1
  12. package/css/index-without-carbon.min.css +5 -5
  13. package/css/index-without-carbon.min.css.map +1 -1
  14. package/css/index.css +109 -16
  15. package/css/index.css.map +1 -1
  16. package/css/index.min.css +6 -6
  17. package/css/index.min.css.map +1 -1
  18. package/es/components/ActionBar/ActionBar.js +3 -1
  19. package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
  20. package/es/components/AddSelect/AddSelect.js +63 -12
  21. package/es/components/AddSelect/AddSelectColumn.js +0 -1
  22. package/es/components/AddSelect/AddSelectList.js +59 -13
  23. package/es/components/AddSelect/AddSelectSidebar.js +15 -5
  24. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  25. package/es/components/CreateFullPage/CreateFullPageStep.js +4 -4
  26. package/es/components/CreateTearsheet/CreateTearsheetStep.js +4 -4
  27. package/es/components/DataSpreadsheet/DataSpreadsheet.js +193 -119
  28. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +178 -51
  29. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +50 -2
  30. package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -4
  31. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
  32. package/es/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  33. package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  34. package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  35. package/es/components/ImportModal/ImportModal.js +2 -2
  36. package/es/components/TagSet/TagSet.js +12 -3
  37. package/es/components/UserProfileImage/UserProfileImage.js +38 -10
  38. package/lib/components/ActionBar/ActionBar.js +3 -1
  39. package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
  40. package/lib/components/AddSelect/AddSelect.js +63 -12
  41. package/lib/components/AddSelect/AddSelectColumn.js +0 -1
  42. package/lib/components/AddSelect/AddSelectList.js +61 -12
  43. package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
  44. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
  45. package/lib/components/CreateFullPage/CreateFullPageStep.js +4 -4
  46. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +4 -4
  47. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +196 -120
  48. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +178 -51
  49. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +52 -7
  50. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -3
  51. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
  52. package/lib/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
  53. package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
  54. package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
  55. package/lib/components/ImportModal/ImportModal.js +1 -1
  56. package/lib/components/TagSet/TagSet.js +12 -3
  57. package/lib/components/UserProfileImage/UserProfileImage.js +38 -10
  58. package/package.json +15 -15
  59. package/scss/components/AboutModal/_about-modal.scss +2 -2
  60. package/scss/components/ActionSet/_action-set.scss +3 -1
  61. package/scss/components/AddSelect/_add-select.scss +50 -3
  62. package/scss/components/CreateModal/_create-modal.scss +7 -5
  63. package/scss/components/CreateModal/_storybook-styles.scss +8 -7
  64. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +57 -7
  65. package/scss/components/ExportModal/_export-modal.scss +3 -3
  66. package/scss/components/HTTPErrors/_http-errors.scss +16 -16
  67. package/scss/components/InlineEdit/_inline-edit.scss +0 -1
  68. package/scss/components/ModifiedTabs/_modified-tabs.scss +0 -10
  69. package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -3
  70. package/scss/components/OptionsTile/_options-tile.scss +0 -1
  71. package/scss/components/PageHeader/_page-header.scss +4 -0
  72. package/scss/components/RemoveModal/_remove-modal.scss +3 -3
  73. package/scss/components/TagSet/_tag-set.scss +2 -1
  74. package/scss/components/Tearsheet/_tearsheet.scss +1 -2
@@ -1,10 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _typeof from "@babel/runtime/helpers/typeof";
3
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
6
5
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
7
- var _excluded = ["cellSize", "className", "columns", "data", "onDataUpdate", "id", "onActiveCellChange"];
6
+ var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
8
7
 
9
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; }
10
9
 
@@ -18,7 +17,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
18
17
  */
19
18
  // Import portions of React that are needed.
20
19
  import React, { useMemo, useRef, useState, useCallback, useEffect } from 'react';
21
- import { useBlockLayout, useTable } from 'react-table'; // Other standard imports.
20
+ import { useBlockLayout, useTable } from 'react-table';
21
+ import { px } from '@carbon/layout'; // Other standard imports.
22
22
 
23
23
  import PropTypes from 'prop-types';
24
24
  import cx from 'classnames';
@@ -28,9 +28,7 @@ import { DataSpreadsheetBody } from './DataSpreadsheetBody';
28
28
  import { DataSpreadsheetHeader } from './DataSpreadsheetHeader';
29
29
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
30
30
  import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
31
- import { useActiveElement } from '../../global/js/hooks';
32
- import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
33
- import { usePreviousValue } from '../../global/js/hooks';
31
+ import { useActiveElement, usePreviousValue } from '../../global/js/hooks';
34
32
  import uuidv4 from '../../global/js/utils/uuidv4';
35
33
  import { useResetSpreadsheetFocus } from './hooks/useResetSpreadsheetFocus';
36
34
  import { useSpreadsheetOutsideClick } from './hooks/useSpreadsheetOutsideClick';
@@ -38,7 +36,8 @@ import { useMoveActiveCell } from './hooks/useMoveActiveCell';
38
36
  import { createActiveCellFn } from './utils/createActiveCellFn';
39
37
  import { getCellSize } from './utils/getCellSize';
40
38
  import { handleMultipleKeys } from './utils/handleMultipleKeys';
41
- import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection'; // cspell:words rowcount colcount
39
+ import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
40
+ import { removeCellSelections } from './utils/removeCellSelections'; // cspell:words rowcount colcount
42
41
  // The block part of our conventional BEM class names (blockClass__E--M).
43
42
 
44
43
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
@@ -48,7 +47,10 @@ var defaults = {
48
47
  cellSize: 'standard',
49
48
  columns: Object.freeze([]),
50
49
  data: Object.freeze([]),
51
- onDataUpdate: Object.freeze(function () {})
50
+ defaultEmptyRowCount: 16,
51
+ onDataUpdate: Object.freeze(function () {}),
52
+ onActiveCellChange: Object.freeze(function () {}),
53
+ onSelectionAreaChange: Object.freeze(function () {})
52
54
  };
53
55
  /**
54
56
  * DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
@@ -62,10 +64,15 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
62
64
  columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
63
65
  _ref$data = _ref.data,
64
66
  data = _ref$data === void 0 ? defaults.data : _ref$data,
67
+ _ref$defaultEmptyRowC = _ref.defaultEmptyRowCount,
68
+ defaultEmptyRowCount = _ref$defaultEmptyRowC === void 0 ? defaults.defaultEmptyRowCount : _ref$defaultEmptyRowC,
65
69
  _ref$onDataUpdate = _ref.onDataUpdate,
66
70
  onDataUpdate = _ref$onDataUpdate === void 0 ? defaults.onDataUpdate : _ref$onDataUpdate,
67
71
  id = _ref.id,
68
- onActiveCellChange = _ref.onActiveCellChange,
72
+ _ref$onActiveCellChan = _ref.onActiveCellChange,
73
+ onActiveCellChange = _ref$onActiveCellChan === void 0 ? defaults.onActiveCellChange : _ref$onActiveCellChan,
74
+ _ref$onSelectionAreaC = _ref.onSelectionAreaChange,
75
+ onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
69
76
  rest = _objectWithoutProperties(_ref, _excluded);
70
77
 
71
78
  var localRef = useRef();
@@ -87,34 +94,45 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
87
94
  selectionAreas = _useState6[0],
88
95
  setSelectionAreas = _useState6[1];
89
96
 
90
- var _useState7 = useState(false),
97
+ var _useState7 = useState([]),
91
98
  _useState8 = _slicedToArray(_useState7, 2),
92
- clickAndHoldActive = _useState8[0],
93
- setClickAndHoldActive = _useState8[1];
99
+ selectionAreaData = _useState8[0],
100
+ setSelectionAreaData = _useState8[1];
94
101
 
95
- var _useState9 = useState(''),
102
+ var _useState9 = useState(false),
96
103
  _useState10 = _slicedToArray(_useState9, 2),
97
- currentMatcher = _useState10[0],
98
- setCurrentMatcher = _useState10[1];
104
+ clickAndHoldActive = _useState10[0],
105
+ setClickAndHoldActive = _useState10[1];
99
106
 
100
- var _useState11 = useState(false),
107
+ var _useState11 = useState(''),
101
108
  _useState12 = _slicedToArray(_useState11, 2),
102
- isEditing = _useState12[0],
103
- setIsEditing = _useState12[1];
109
+ currentMatcher = _useState12[0],
110
+ setCurrentMatcher = _useState12[1];
104
111
 
105
- var _useState13 = useState(''),
112
+ var _useState13 = useState(false),
106
113
  _useState14 = _slicedToArray(_useState13, 2),
107
- cellEditorValue = _useState14[0],
108
- setCellEditorValue = _useState14[1];
114
+ isEditing = _useState14[0],
115
+ setIsEditing = _useState14[1];
116
+
117
+ var _useState15 = useState(''),
118
+ _useState16 = _slicedToArray(_useState15, 2),
119
+ cellEditorValue = _useState16[0],
120
+ setCellEditorValue = _useState16[1];
109
121
 
110
122
  var previousState = usePreviousValue({
111
123
  activeCellCoordinates: activeCellCoordinates
112
124
  });
113
125
  var cellSizeValue = getCellSize(cellSize);
114
126
  var cellEditorRef = useRef();
115
- var currentMatcherRef = useRef();
127
+
128
+ var _useState17 = useState(),
129
+ _useState18 = _slicedToArray(_useState17, 2),
130
+ activeCellContent = _useState18[0],
131
+ setActiveCellContent = _useState18[1];
132
+
116
133
  var activeKeys = useRef([]);
117
134
  var activeCellRef = useRef();
135
+ var cellEditorRulerRef = useRef();
118
136
  var defaultColumn = useMemo(function () {
119
137
  return {
120
138
  width: 150,
@@ -162,23 +180,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
162
180
  setCellEditorValue('');
163
181
  setIsEditing(false);
164
182
  cellEditorRef.current.style.display = 'none';
165
- }, []); // Removes the cell selection elements
166
-
167
- var removeCellSelections = useCallback(function (matcher) {
168
- if (matcher && typeof matcher === 'string') {
169
- var selectionToRemove = spreadsheetRef.current.querySelector("[data-matcher-id=\"".concat(matcher, "\"]"));
170
-
171
- if (selectionToRemove) {
172
- selectionToRemove.remove();
173
- }
174
- } else {
175
- var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
176
-
177
- _toConsumableArray(cellSelections).forEach(function (element) {
178
- return element.remove();
179
- });
180
- }
181
- }, [spreadsheetRef]); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
183
+ }, []); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
182
184
  // happen if you click on another cell while isEditing is true
183
185
 
184
186
  useEffect(function () {
@@ -188,11 +190,20 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
188
190
  var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
189
191
  removeCellEditor();
190
192
  updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
193
+ cellEditorRulerRef.current.textContent = '';
191
194
  }
192
- }, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor]);
193
- var handleActiveCellMouseEnter = useCallback(function () {
194
- handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
195
- }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]);
195
+
196
+ 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)) {
197
+ if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
198
+ 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;
199
+ setActiveCellContent(activeCellFullData.render('Cell'));
200
+ }
201
+
202
+ if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
203
+ setActiveCellContent(null);
204
+ }
205
+ }
206
+ }, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor, activeCellContent]);
196
207
  var createActiveCell = useCallback(function (_ref2) {
197
208
  var placementElement = _ref2.placementElement,
198
209
  coords = _ref2.coords,
@@ -296,6 +307,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
296
307
 
297
308
  if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
298
309
  setSelectionAreas([]);
310
+ setSelectionAreaData([]);
299
311
  removeCellSelections({
300
312
  spreadsheetRef: spreadsheetRef
301
313
  });
@@ -473,13 +485,26 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
473
485
  }
474
486
  }
475
487
  }
476
- }, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, removeCellSelections, selectionAreas]);
488
+ }, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas]);
477
489
 
478
490
  var startEditMode = function startEditMode() {
479
491
  setIsEditing(true);
480
492
  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;
481
493
  var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
482
494
  setCellEditorValue(activeCellValue);
495
+ cellEditorRulerRef.current.textContent = activeCellValue;
496
+ };
497
+
498
+ var handleActiveCellClick = function handleActiveCellClick() {
499
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
500
+ 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;
501
+ handleRowColumnHeaderClick({
502
+ isKeyboard: false,
503
+ index: indexValue
504
+ });
505
+ }
506
+
507
+ return;
483
508
  }; // Go into edit mode if 'Enter' key is pressed on activeCellRef
484
509
 
485
510
 
@@ -492,41 +517,51 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
492
517
  }
493
518
 
494
519
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
495
- var handleHeaderCellProps = {
496
- activeCellCoordinates: activeCellCoordinates,
497
- rows: rows,
498
- columns: columns,
499
- setActiveCellCoordinates: setActiveCellCoordinates,
500
- setCurrentMatcher: setCurrentMatcher,
501
- setSelectionAreas: setSelectionAreas,
502
- spreadsheetRef: spreadsheetRef,
520
+ handleRowColumnHeaderClick({
503
521
  isKeyboard: true
504
- }; // Select an entire column
505
-
506
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
507
- handleHeaderCellSelection(_objectSpread({
508
- type: 'column'
509
- }, handleHeaderCellProps));
510
- } // Select an entire row
511
-
512
-
513
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
514
- handleHeaderCellSelection(_objectSpread({
515
- type: 'row'
516
- }, handleHeaderCellProps));
517
- }
522
+ });
518
523
  }
519
524
  }
525
+ };
526
+
527
+ var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref4) {
528
+ var isKeyboard = _ref4.isKeyboard,
529
+ _ref4$index = _ref4.index,
530
+ index = _ref4$index === void 0 ? null : _ref4$index;
531
+ var handleHeaderCellProps = {
532
+ activeCellCoordinates: activeCellCoordinates,
533
+ rows: rows,
534
+ columns: columns,
535
+ setActiveCellCoordinates: setActiveCellCoordinates,
536
+ setCurrentMatcher: setCurrentMatcher,
537
+ setSelectionAreas: setSelectionAreas,
538
+ spreadsheetRef: spreadsheetRef,
539
+ isKeyboard: isKeyboard,
540
+ setSelectionAreaData: setSelectionAreaData,
541
+ index: index
542
+ }; // Select an entire column
543
+
544
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
545
+ handleHeaderCellSelection(_objectSpread({
546
+ type: 'column'
547
+ }, handleHeaderCellProps));
548
+ } // Select an entire row
549
+
550
+
551
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
552
+ handleHeaderCellSelection(_objectSpread({
553
+ type: 'row'
554
+ }, handleHeaderCellProps));
555
+ }
520
556
  }; // Go into edit mode if double click is detected on activeCellRef
521
557
 
522
558
 
523
559
  var handleActiveCellDoubleClick = function handleActiveCellDoubleClick() {
524
560
  startEditMode();
525
- }; // Update the data
526
-
561
+ };
527
562
 
528
- var handleEditSubmit = function handleEditSubmit(event) {
529
- var key = event.key;
563
+ var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref5) {
564
+ var type = _ref5.type;
530
565
 
531
566
  var submitEditChanges = function submitEditChanges() {
532
567
  var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
@@ -535,8 +570,33 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
535
570
  updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
536
571
  };
537
572
 
573
+ removeCellSelections({
574
+ spreadsheetRef: spreadsheetRef
575
+ });
576
+ submitEditChanges();
577
+ var tempMatcher = uuidv4();
578
+ var newSelectionArea = {
579
+ row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
580
+ column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
581
+ };
582
+ setSelectionAreas([{
583
+ point1: newSelectionArea,
584
+ point2: newSelectionArea,
585
+ matcher: tempMatcher,
586
+ areaCreated: false
587
+ }]);
588
+ setCurrentMatcher(tempMatcher);
589
+ cellEditorRulerRef.current.textContent = '';
590
+ }; // Update the data
591
+
592
+
593
+ var handleEditSubmit = function handleEditSubmit(event) {
594
+ var key = event.key;
595
+
538
596
  if (key === 'Enter') {
539
- submitEditChanges();
597
+ updateSelectionAreaOnCellEditSubmit({
598
+ type: 'Enter'
599
+ });
540
600
  setActiveCellCoordinates(function (prev) {
541
601
  return _objectSpread(_objectSpread({}, prev), {}, {
542
602
  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
@@ -547,7 +607,9 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
547
607
 
548
608
  if (key === 'Tab') {
549
609
  event.preventDefault();
550
- submitEditChanges();
610
+ updateSelectionAreaOnCellEditSubmit({
611
+ type: 'Tab'
612
+ });
551
613
  setActiveCellCoordinates(function (prev) {
552
614
  return _objectSpread(_objectSpread({}, prev), {}, {
553
615
  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
@@ -557,44 +619,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
557
619
  }
558
620
 
559
621
  return;
560
- }; // Only update if there are cell selection areas
561
- // Find point object that matches currentMatcher and remove the second point
562
- // because hovering over the active cell while clicking and holding should
563
- // remove the previously existing selection area
564
-
565
-
566
- var handleActiveCellMouseEnterCallback = useCallback(function (areas, clickHold) {
567
- var freshMatcherValue = currentMatcherRef.current;
568
-
569
- if (!freshMatcherValue) {
570
- return;
571
- }
572
-
573
- if (areas && areas.length && clickHold && freshMatcherValue) {
574
- setSelectionAreas(function (prev) {
575
- var selectionAreaClone = deepCloneObject(prev);
576
- var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
577
- return item.matcher === freshMatcherValue;
578
- });
579
-
580
- if (indexOfItemToUpdate === -1) {
581
- return prev;
582
- }
583
-
584
- if (_typeof(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
585
- selectionAreaClone[indexOfItemToUpdate].point2 = null;
586
- selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
587
- removeCellSelections({
588
- matcher: freshMatcherValue,
589
- spreadsheetRef: spreadsheetRef
590
- });
591
- return selectionAreaClone;
592
- }
622
+ };
593
623
 
594
- return prev;
595
- });
596
- }
597
- }, [spreadsheetRef, removeCellSelections]);
598
624
  useEffect(function () {
599
625
  if (isEditing) {
600
626
  var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
@@ -607,18 +633,43 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
607
633
  cellEditorRef.current.style.display = 'block';
608
634
  cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
609
635
  cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
610
- cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
636
+ 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
611
637
 
612
638
  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';
613
639
  (_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
640
+ var rulerWidth = cellEditorRulerRef.current.offsetWidth;
641
+ var cellWidth = activeCellRef.current.offsetWidth;
642
+
643
+ if (rulerWidth >= cellWidth) {
644
+ var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
645
+ var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
646
+ var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
647
+ var totalColumns = columns.length;
648
+ var totalRows = rows.length;
649
+ var totalMultiplierPossible = totalColumns - startingColumnPosition;
650
+ var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
651
+ cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
652
+ cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
653
+ cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
654
+ // Cell editor has reached max height, we need to add the scrolling back.
655
+ // We also need to subtract 1 to account for the fact that the cell editor
656
+ // is placed one pixel below the cell being edited to account for the border
657
+
658
+ if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
659
+ cellEditorRef.current.style.overflow = 'auto';
660
+ } else {
661
+ cellEditorRef.current.style.overflow = 'hidden';
662
+ }
663
+ }
614
664
  }
615
665
 
616
666
  if (!isEditing) {
667
+ cellEditorRef.current.style.overflow = 'hidden';
617
668
  cellEditorRef.current.style.display = 'none';
618
669
  cellEditorRef.current.blur();
619
670
  activeCellRef.current.focus();
620
671
  }
621
- }, [isEditing, activeCellCoordinates, rows]);
672
+ }, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
622
673
 
623
674
  var handleKeyUp = function handleKeyUp(event) {
624
675
  var _activeKeys$current3;
@@ -636,7 +687,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
636
687
  };
637
688
 
638
689
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
639
- className: cx(blockClass, className, _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
690
+ className: cx(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
640
691
  ref: spreadsheetRef,
641
692
  role: "grid",
642
693
  tabIndex: 0,
@@ -650,15 +701,17 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
650
701
  }), /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
651
702
  ref: spreadsheetRef,
652
703
  activeCellCoordinates: activeCellCoordinates,
653
- cellSizeValue: cellSizeValue,
704
+ cellSize: cellSize,
654
705
  columns: columns,
655
706
  defaultColumn: defaultColumn,
656
707
  headerGroups: headerGroups,
657
708
  rows: rows,
709
+ scrollBarSize: scrollBarSize,
658
710
  selectionAreas: selectionAreas,
659
711
  setActiveCellCoordinates: setActiveCellCoordinates,
660
712
  setSelectionAreas: setSelectionAreas,
661
- setCurrentMatcher: setCurrentMatcher
713
+ setCurrentMatcher: setCurrentMatcher,
714
+ setSelectionAreaData: setSelectionAreaData
662
715
  }), /*#__PURE__*/React.createElement(DataSpreadsheetBody, {
663
716
  activeCellCoordinates: activeCellCoordinates,
664
717
  ref: spreadsheetRef,
@@ -670,33 +723,44 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
670
723
  selectionAreas: selectionAreas,
671
724
  setSelectionAreas: setSelectionAreas,
672
725
  cellSize: cellSize,
726
+ headerGroups: headerGroups,
673
727
  defaultColumn: defaultColumn,
674
728
  getTableBodyProps: getTableBodyProps,
729
+ onDataUpdate: onDataUpdate,
675
730
  onActiveCellChange: onActiveCellChange,
731
+ onSelectionAreaChange: onSelectionAreaChange,
676
732
  prepareRow: prepareRow,
677
733
  rows: rows,
734
+ selectionAreaData: selectionAreaData,
735
+ setSelectionAreaData: setSelectionAreaData,
678
736
  setActiveCellCoordinates: setActiveCellCoordinates,
679
737
  scrollBarSize: scrollBarSize,
680
738
  totalColumnsWidth: totalColumnsWidth,
681
739
  id: id,
682
- columns: columns
740
+ columns: columns,
741
+ defaultEmptyRowCount: defaultEmptyRowCount
683
742
  }), /*#__PURE__*/React.createElement("button", {
743
+ onClick: handleActiveCellClick,
684
744
  onKeyDown: handleActiveCellKeyDown,
685
- onMouseEnter: handleActiveCellMouseEnter,
686
745
  onDoubleClick: handleActiveCellDoubleClick,
687
746
  ref: activeCellRef,
688
747
  className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
689
748
  type: "button"
690
- }), /*#__PURE__*/React.createElement(TextArea, {
749
+ }, activeCellContent), /*#__PURE__*/React.createElement(TextArea, {
691
750
  value: cellEditorValue,
692
751
  onKeyDown: handleEditSubmit,
693
752
  onChange: function onChange(event) {
694
- return setCellEditorValue(event.target.value);
753
+ setCellEditorValue(event.target.value);
754
+ cellEditorRulerRef.current.textContent = event.target.value;
695
755
  },
696
756
  ref: cellEditorRef,
697
757
  labelText: "",
698
758
  "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,
699
759
  className: cx("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), _defineProperty({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
760
+ }), /*#__PURE__*/React.createElement("pre", {
761
+ "aria-hidden": true,
762
+ ref: cellEditorRulerRef,
763
+ className: "".concat(blockClass, "__cell-editor-ruler")
700
764
  }));
701
765
  }); // Return a placeholder if not released and not enabled by feature flag
702
766
 
@@ -733,6 +797,11 @@ DataSpreadsheet.propTypes = {
733
797
  */
734
798
  data: PropTypes.arrayOf(PropTypes.shape),
735
799
 
800
+ /**
801
+ * Sets the number of empty rows to be created when there is no data provided
802
+ */
803
+ defaultEmptyRowCount: PropTypes.number,
804
+
736
805
  /**
737
806
  * The spreadsheet id
738
807
  */
@@ -746,7 +815,12 @@ DataSpreadsheet.propTypes = {
746
815
  /**
747
816
  * The setter fn for the data prop
748
817
  */
749
- onDataUpdate: PropTypes.func
818
+ onDataUpdate: PropTypes.func,
819
+
820
+ /**
821
+ * The event handler that is called when the selection area values change
822
+ */
823
+ onSelectionAreaChange: PropTypes.func
750
824
  /* TODO: add types and DocGen for all props. */
751
825
 
752
826
  };