@carbon/ibm-products 1.14.0 → 1.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. package/css/index-full-carbon.css +23 -5
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +4 -4
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +2 -2
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +23 -5
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +23 -5
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/AddSelect/AddSelect.js +25 -19
  18. package/es/components/AddSelect/AddSelectFilter.js +5 -5
  19. package/es/components/DataSpreadsheet/DataSpreadsheet.js +174 -127
  20. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +24 -8
  21. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +31 -6
  22. package/es/components/DataSpreadsheet/hooks/index.js +2 -1
  23. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +36 -8
  24. package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -0
  25. package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +20 -8
  26. package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
  27. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
  28. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
  29. package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
  30. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +42 -8
  31. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +153 -15
  32. package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
  33. package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
  34. package/es/components/PageHeader/PageHeader.js +3 -1
  35. package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
  36. package/es/components/TagSet/TagSet.js +13 -6
  37. package/es/components/Tearsheet/TearsheetShell.js +34 -10
  38. package/es/global/js/package-settings.js +2 -1
  39. package/lib/components/AddSelect/AddSelect.js +25 -19
  40. package/lib/components/AddSelect/AddSelectFilter.js +5 -5
  41. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +178 -126
  42. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +24 -8
  43. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +32 -6
  44. package/lib/components/DataSpreadsheet/hooks/index.js +9 -1
  45. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +36 -8
  46. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +79 -0
  47. package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +21 -8
  48. package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
  49. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
  50. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
  51. package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
  52. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +44 -8
  53. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +161 -22
  54. package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
  55. package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
  56. package/lib/components/PageHeader/PageHeader.js +3 -1
  57. package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
  58. package/lib/components/TagSet/TagSet.js +13 -6
  59. package/lib/components/Tearsheet/TearsheetShell.js +36 -10
  60. package/lib/global/js/package-settings.js +2 -1
  61. package/package.json +11 -11
  62. package/scss/components/AboutModal/_about-modal.scss +4 -0
  63. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +22 -1
  64. package/scss/components/ExportModal/_export-modal.scss +0 -4
@@ -2,7 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _typeof = require("@babel/runtime/helpers/typeof");
5
+ var _typeof3 = require("@babel/runtime/helpers/typeof");
6
6
 
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
@@ -11,6 +11,8 @@ exports.DataSpreadsheet = void 0;
11
11
 
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
13
 
14
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
15
+
14
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
17
 
16
18
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
@@ -21,8 +23,6 @@ var _react = _interopRequireWildcard(require("react"));
21
23
 
22
24
  var _reactTable = require("react-table");
23
25
 
24
- var _layout = require("@carbon/layout");
25
-
26
26
  var _propTypes = _interopRequireDefault(require("prop-types"));
27
27
 
28
28
  var _classnames = _interopRequireDefault(require("classnames"));
@@ -43,6 +43,8 @@ var _hooks = require("../../global/js/hooks");
43
43
 
44
44
  var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
45
45
 
46
+ var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
47
+
46
48
  var _hooks2 = require("./hooks");
47
49
 
48
50
  var _createActiveCellFn = require("./utils/createActiveCellFn");
@@ -55,11 +57,19 @@ var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
55
57
 
56
58
  var _removeCellSelections = require("./utils/removeCellSelections");
57
59
 
60
+ var _selectAllCells = require("./utils/selectAllCells");
61
+
62
+ var _handleEditSubmit = require("./utils/handleEditSubmit");
63
+
64
+ var _handleActiveCellInSelectionEnter = require("./utils/handleActiveCellInSelectionEnter");
65
+
66
+ var _handleActiveCellInSelectionTab = require("./utils/handleActiveCellInSelectionTab");
67
+
58
68
  var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
59
69
 
60
70
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
61
71
 
62
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
72
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
63
73
 
64
74
  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; }
65
75
 
@@ -146,6 +156,11 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
146
156
  cellEditorValue = _useState16[0],
147
157
  setCellEditorValue = _useState16[1];
148
158
 
159
+ var _useState17 = (0, _react.useState)(false),
160
+ _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
161
+ activeCellInsideSelectionArea = _useState18[0],
162
+ setActiveCellInsideSelectionArea = _useState18[1];
163
+
149
164
  var previousState = (0, _hooks.usePreviousValue)({
150
165
  activeCellCoordinates: activeCellCoordinates,
151
166
  isEditing: isEditing
@@ -153,10 +168,10 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
153
168
  var cellSizeValue = (0, _getCellSize.getCellSize)(cellSize);
154
169
  var cellEditorRef = (0, _react.useRef)();
155
170
 
156
- var _useState17 = (0, _react.useState)(),
157
- _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
158
- activeCellContent = _useState18[0],
159
- setActiveCellContent = _useState18[1];
171
+ var _useState19 = (0, _react.useState)(),
172
+ _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
173
+ activeCellContent = _useState20[0],
174
+ setActiveCellContent = _useState20[1];
160
175
 
161
176
  var activeCellRef = (0, _react.useRef)();
162
177
  var cellEditorRulerRef = (0, _react.useRef)();
@@ -173,7 +188,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
173
188
  containerHasFocus: containerHasFocus,
174
189
  isEditing: isEditing
175
190
  }),
176
- keysPressedList = _useMultipleKeyTracki.keysPressedList;
191
+ keysPressedList = _useMultipleKeyTracki.keysPressedList,
192
+ usingMac = _useMultipleKeyTracki.usingMac;
177
193
 
178
194
  var scrollBarSize = (0, _react.useMemo)(function () {
179
195
  return (0, _getScrollbarWidth.getScrollbarWidth)();
@@ -286,6 +302,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
286
302
  var handleInitialArrowPress = (0, _react.useCallback)(function () {
287
303
  // If activeCellCoordinates is null then we need to set an initial value
288
304
  // which will place the activeCell on the select all cell/button
305
+ setActiveCellInsideSelectionArea(false);
306
+
289
307
  if (!activeCellCoordinates) {
290
308
  setActiveCellCoordinates({
291
309
  column: 'header',
@@ -296,16 +314,20 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
296
314
  return;
297
315
  }, [activeCellCoordinates]);
298
316
  var updateActiveCellCoordinates = (0, _react.useCallback)(function (_ref3) {
299
- var coords = _ref3.coords,
300
- updatedValue = _ref3.updatedValue;
317
+ var _ref3$coords = _ref3.coords,
318
+ coords = _ref3$coords === void 0 ? _objectSpread({}, activeCellCoordinates) : _ref3$coords,
319
+ updatedValue = _ref3.updatedValue,
320
+ _ref3$optOutOfSelecti = _ref3.optOutOfSelectionAreaUpdate,
321
+ optOutOfSelectionAreaUpdate = _ref3$optOutOfSelecti === void 0 ? false : _ref3$optOutOfSelecti;
301
322
 
302
323
  var newActiveCell = _objectSpread(_objectSpread({}, coords), updatedValue);
303
324
 
304
325
  setActiveCellCoordinates(newActiveCell); // Only run if the active cell is _not_ a header cell. This will add a point1 object
305
326
  // to selectionAreas every time the active cell changes, allowing us to create cell
306
- // selections using keyboard
327
+ // selections using keyboard. Opting out of the selection area updates here means
328
+ // that the active cell is being moved within a selection area
307
329
 
308
- if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header') {
330
+ if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header' && !optOutOfSelectionAreaUpdate) {
309
331
  var tempMatcher = (0, _uuidv.default)();
310
332
  setSelectionAreas([{
311
333
  point1: newActiveCell,
@@ -313,7 +335,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
313
335
  }]);
314
336
  setCurrentMatcher(tempMatcher);
315
337
  }
316
- }, []);
338
+ }, [activeCellCoordinates]);
317
339
  var handleHomeEndKey = (0, _react.useCallback)(function (_ref4) {
318
340
  var type = _ref4.type;
319
341
 
@@ -370,7 +392,13 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
370
392
  currentMatcher: currentMatcher,
371
393
  rows: rows,
372
394
  setSelectionAreas: setSelectionAreas,
373
- columns: columns
395
+ columns: columns,
396
+ updateActiveCellCoordinates: updateActiveCellCoordinates,
397
+ spreadsheetRef: spreadsheetRef,
398
+ removeCellSelections: _removeCellSelections.removeCellSelections,
399
+ blockClass: blockClass,
400
+ setCurrentMatcher: setCurrentMatcher,
401
+ usingMac: usingMac
374
402
  });
375
403
  } // Allow arrow key navigation if there are less than two activeKeys OR
376
404
  // if one of the activeCellCoordinates is in a header position
@@ -378,9 +406,26 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
378
406
 
379
407
  if (keysPressedList.length < 2 && !(0, _handleMultipleKeys.includesShift)(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
380
408
  switch (key) {
409
+ // Enter
410
+ case 'Enter':
411
+ {
412
+ (0, _handleActiveCellInSelectionEnter.handleActiveCellInSelectionEnter)({
413
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
414
+ activeCellCoordinates: activeCellCoordinates,
415
+ activeCellRef: activeCellRef,
416
+ selectionAreas: selectionAreas,
417
+ updateActiveCellCoordinates: updateActiveCellCoordinates
418
+ });
419
+ break;
420
+ }
381
421
  // HOME
422
+
382
423
  case 'Home':
383
424
  {
425
+ if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac)) {
426
+ return;
427
+ }
428
+
384
429
  handleHomeEndKey({
385
430
  type: 'home'
386
431
  });
@@ -389,6 +434,10 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
389
434
 
390
435
  case 'End':
391
436
  {
437
+ if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac)) {
438
+ return;
439
+ }
440
+
392
441
  handleHomeEndKey({
393
442
  type: 'end'
394
443
  });
@@ -398,6 +447,17 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
398
447
 
399
448
  case 'Tab':
400
449
  {
450
+ if (activeCellInsideSelectionArea) {
451
+ event.preventDefault();
452
+ return (0, _handleActiveCellInSelectionTab.handleActiveCellInSelectionTab)({
453
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
454
+ activeCellCoordinates: activeCellCoordinates,
455
+ activeCellRef: activeCellRef,
456
+ selectionAreas: selectionAreas,
457
+ updateActiveCellCoordinates: updateActiveCellCoordinates
458
+ });
459
+ }
460
+
401
461
  setSelectionAreas([]);
402
462
  removeActiveCell();
403
463
  removeCellEditor();
@@ -544,7 +604,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
544
604
  }
545
605
  }
546
606
  }
547
- }, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList]);
607
+ }, [activeCellInsideSelectionArea, updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList, usingMac]);
548
608
 
549
609
  var startEditMode = function startEditMode() {
550
610
  setIsEditing(true);
@@ -566,12 +626,37 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
566
626
  var handleActiveCellClick = function handleActiveCellClick() {
567
627
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
568
628
  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;
629
+
630
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
631
+ return;
632
+ }
633
+
569
634
  handleRowColumnHeaderClick({
570
635
  isKeyboard: false,
571
636
  index: indexValue
572
637
  });
573
638
  }
574
639
 
640
+ return;
641
+ }; // Mouse down on active cell
642
+
643
+
644
+ var handleActiveCellMouseDown = function handleActiveCellMouseDown() {
645
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
646
+ var tempMatcher = (0, _uuidv.default)();
647
+ setClickAndHoldActive(true);
648
+ (0, _removeCellSelections.removeCellSelections)({
649
+ spreadsheetRef: spreadsheetRef
650
+ });
651
+ setSelectionAreas([{
652
+ point1: activeCellCoordinates,
653
+ matcher: tempMatcher
654
+ }]);
655
+ setCurrentMatcher(tempMatcher);
656
+ setSelectionAreaData([]);
657
+ setActiveCellInsideSelectionArea(false);
658
+ }
659
+
575
660
  return;
576
661
  }; // Go into edit mode if 'Enter' key is pressed on activeCellRef
577
662
 
@@ -579,7 +664,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
579
664
  var handleActiveCellKeyDown = function handleActiveCellKeyDown(event) {
580
665
  var key = event.key;
581
666
 
582
- if (key === 'Enter') {
667
+ if (key === 'Enter' && !activeCellInsideSelectionArea) {
583
668
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
584
669
  startEditMode();
585
670
  }
@@ -609,18 +694,30 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
609
694
  index: index
610
695
  }; // Select an entire column
611
696
 
612
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
697
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
613
698
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
614
699
  type: 'column'
615
700
  }, handleHeaderCellProps));
616
701
  } // Select an entire row
617
702
 
618
703
 
619
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
704
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
620
705
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
621
706
  type: 'row'
622
707
  }, handleHeaderCellProps));
623
708
  }
709
+
710
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
711
+ (0, _selectAllCells.selectAllCells)({
712
+ ref: spreadsheetRef,
713
+ setCurrentMatcher: setCurrentMatcher,
714
+ setSelectionAreas: setSelectionAreas,
715
+ rows: rows,
716
+ columns: columns,
717
+ activeCellCoordinates: activeCellCoordinates,
718
+ updateActiveCellCoordinates: updateActiveCellCoordinates
719
+ });
720
+ }
624
721
  }; // Go into edit mode if double click is detected on activeCellRef
625
722
 
626
723
 
@@ -628,116 +725,55 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
628
725
  startEditMode();
629
726
  };
630
727
 
631
- var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref6) {
632
- var type = _ref6.type;
633
-
634
- var submitEditChanges = function submitEditChanges() {
635
- var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
636
- var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
637
- removeCellEditor();
638
- updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
639
- };
640
-
641
- (0, _removeCellSelections.removeCellSelections)({
642
- spreadsheetRef: spreadsheetRef
643
- });
644
- submitEditChanges();
645
- var tempMatcher = (0, _uuidv.default)();
646
- var newSelectionArea = {
647
- row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
648
- column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
649
- };
650
- setSelectionAreas([{
651
- point1: newSelectionArea,
652
- point2: newSelectionArea,
653
- matcher: tempMatcher,
654
- areaCreated: false
655
- }]);
656
- setCurrentMatcher(tempMatcher);
657
- cellEditorRulerRef.current.textContent = '';
658
- }; // Update the data
659
-
660
-
661
- var handleEditSubmit = function handleEditSubmit(event) {
662
- var key = event.key;
663
-
664
- if (key === 'Enter') {
665
- updateSelectionAreaOnCellEditSubmit({
666
- type: 'Enter'
667
- });
668
- setActiveCellCoordinates(function (prev) {
669
- return _objectSpread(_objectSpread({}, prev), {}, {
670
- 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
671
-
672
- });
673
- });
728
+ (0, _hooks2.useSpreadsheetEdit)({
729
+ isEditing: isEditing,
730
+ rows: rows,
731
+ activeCellCoordinates: activeCellCoordinates,
732
+ activeCellRef: activeCellRef,
733
+ cellEditorRef: cellEditorRef,
734
+ cellEditorRulerRef: cellEditorRulerRef,
735
+ columns: columns,
736
+ defaultColumn: defaultColumn,
737
+ cellEditorValue: cellEditorValue
738
+ });
739
+ var handleActiveCellMouseEnter = (0, _react.useCallback)(function () {
740
+ handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
741
+ }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]); // Only update if there are cell selection areas
742
+ // Find point object that matches currentMatcher and remove the second point
743
+ // because hovering over the active cell while clicking and holding should
744
+ // remove the previously existing selection area
745
+
746
+ var handleActiveCellMouseEnterCallback = (0, _react.useCallback)(function (areas, clickHold) {
747
+ if (!currentMatcher) {
748
+ return;
674
749
  }
675
750
 
676
- if (key === 'Tab') {
677
- event.preventDefault();
678
- updateSelectionAreaOnCellEditSubmit({
679
- type: 'Tab'
680
- });
681
- setActiveCellCoordinates(function (prev) {
682
- return _objectSpread(_objectSpread({}, prev), {}, {
683
- 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
684
-
751
+ if (areas && areas.length && clickHold && currentMatcher) {
752
+ setSelectionAreas(function (prev) {
753
+ var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(prev);
754
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
755
+ return item.matcher === currentMatcher;
685
756
  });
686
- });
687
- }
688
757
 
689
- return;
690
- };
758
+ if (indexOfItemToUpdate === -1) {
759
+ return prev;
760
+ }
691
761
 
692
- (0, _react.useEffect)(function () {
693
- if (isEditing) {
694
- var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
695
-
696
- 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];
697
- var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
698
- var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
699
- cellEditorRef.current.style.left = activeCellLeftPosition;
700
- cellEditorRef.current.style.top = activeCellTopPosition;
701
- cellEditorRef.current.style.display = 'block';
702
- cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
703
- cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
704
- 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
705
-
706
- 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';
707
- (_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
708
- var rulerWidth = cellEditorRulerRef.current.offsetWidth;
709
- var cellWidth = activeCellRef.current.offsetWidth;
710
-
711
- if (rulerWidth >= cellWidth) {
712
- var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
713
- var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
714
- var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
715
- var totalColumns = columns.length;
716
- var totalRows = rows.length;
717
- var totalMultiplierPossible = totalColumns - startingColumnPosition;
718
- var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
719
- cellEditorRef.current.style.maxHeight = (0, _layout.px)(totalCellEditorMaxHeight);
720
- cellEditorRef.current.style.width = (0, _layout.px)(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
721
- cellEditorRef.current.style.height = (0, _layout.px)(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
722
- // Cell editor has reached max height, we need to add the scrolling back.
723
- // We also need to subtract 1 to account for the fact that the cell editor
724
- // is placed one pixel below the cell being edited to account for the border
725
-
726
- if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
727
- cellEditorRef.current.style.overflow = 'auto';
728
- } else {
729
- cellEditorRef.current.style.overflow = 'hidden';
762
+ if ((0, _typeof2.default)(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
763
+ selectionAreaClone[indexOfItemToUpdate].point2 = selectionAreaClone[indexOfItemToUpdate].point1;
764
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
765
+ setActiveCellInsideSelectionArea(false);
766
+ (0, _removeCellSelections.removeCellSelections)({
767
+ matcher: currentMatcher,
768
+ spreadsheetRef: spreadsheetRef
769
+ });
770
+ return selectionAreaClone;
730
771
  }
731
- }
732
- }
733
772
 
734
- if (!isEditing) {
735
- cellEditorRef.current.style.overflow = 'hidden';
736
- cellEditorRef.current.style.display = 'none';
737
- cellEditorRef.current.blur();
738
- activeCellRef.current.focus();
773
+ return prev;
774
+ });
739
775
  }
740
- }, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
776
+ }, [spreadsheetRef, currentMatcher]);
741
777
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, getTableProps(), (0, _devtools.getDevtoolsProps)(componentName), {
742
778
  className: (0, _classnames.default)(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
743
779
  ref: spreadsheetRef,
@@ -764,7 +800,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
764
800
  setActiveCellCoordinates: setActiveCellCoordinates,
765
801
  setSelectionAreas: setSelectionAreas,
766
802
  setCurrentMatcher: setCurrentMatcher,
767
- setSelectionAreaData: setSelectionAreaData
803
+ setSelectionAreaData: setSelectionAreaData,
804
+ updateActiveCellCoordinates: updateActiveCellCoordinates
768
805
  }), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetBody.DataSpreadsheetBody, {
769
806
  activeCellCoordinates: activeCellCoordinates,
770
807
  ref: spreadsheetRef,
@@ -791,24 +828,39 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
791
828
  totalColumnsWidth: totalColumnsWidth,
792
829
  id: id,
793
830
  columns: columns,
794
- defaultEmptyRowCount: defaultEmptyRowCount
831
+ defaultEmptyRowCount: defaultEmptyRowCount,
832
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
795
833
  }), /*#__PURE__*/_react.default.createElement("button", {
834
+ onMouseDown: handleActiveCellMouseDown,
796
835
  onClick: handleActiveCellClick,
797
836
  onKeyDown: handleActiveCellKeyDown,
798
837
  onDoubleClick: handleActiveCellDoubleClick,
838
+ onMouseEnter: handleActiveCellMouseEnter,
799
839
  ref: activeCellRef,
800
- className: (0, _classnames.default)("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
840
+ className: (0, _classnames.default)("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__active-cell--with-selection"), activeCellInsideSelectionArea)),
801
841
  type: "button"
802
842
  }, activeCellContent), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TextArea, {
803
843
  value: cellEditorValue,
804
- onKeyDown: handleEditSubmit,
844
+ onKeyDown: (0, _handleEditSubmit.handleEditSubmit)({
845
+ activeCellCoordinates: activeCellCoordinates,
846
+ cellEditorRulerRef: cellEditorRulerRef,
847
+ columns: columns,
848
+ previousState: previousState,
849
+ removeCellEditor: removeCellEditor,
850
+ rows: rows,
851
+ setActiveCellCoordinates: setActiveCellCoordinates,
852
+ setCurrentMatcher: setCurrentMatcher,
853
+ setSelectionAreas: setSelectionAreas,
854
+ spreadsheetRef: spreadsheetRef,
855
+ updateData: updateData
856
+ }),
805
857
  onChange: function onChange(event) {
806
858
  setCellEditorValue(event.target.value);
807
859
  cellEditorRulerRef.current.textContent = event.target.value;
808
860
  },
809
861
  ref: cellEditorRef,
810
862
  labelText: "",
811
- "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,
863
+ "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,
812
864
  className: (0, _classnames.default)("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), (0, _defineProperty2.default)({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
813
865
  }), /*#__PURE__*/_react.default.createElement("pre", {
814
866
  "aria-hidden": true,
@@ -73,7 +73,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
73
73
  setClickAndHoldActive = _ref.setClickAndHoldActive,
74
74
  currentMatcher = _ref.currentMatcher,
75
75
  setCurrentMatcher = _ref.setCurrentMatcher,
76
- onSelectionAreaChange = _ref.onSelectionAreaChange;
76
+ onSelectionAreaChange = _ref.onSelectionAreaChange,
77
+ setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea;
77
78
  var previousState = (0, _hooks.usePreviousValue)({
78
79
  selectionAreaData: selectionAreaData,
79
80
  clickAndHoldActive: clickAndHoldActive
@@ -131,18 +132,20 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
131
132
 
132
133
  if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
133
134
  (0, _createCellSelectionArea.createCellSelectionArea)({
135
+ ref: ref,
134
136
  area: area,
135
137
  blockClass: blockClass,
136
138
  defaultColumn: defaultColumn,
137
139
  selectionAreas: selectionAreas,
138
- setSelectionAreas: setSelectionAreas
140
+ setSelectionAreas: setSelectionAreas,
141
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea
139
142
  });
140
143
  }
141
144
 
142
145
  return;
143
146
  });
144
147
  }
145
- }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
148
+ }, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData, ref, activeCellCoordinates, setActiveCellInsideSelectionArea]);
146
149
 
147
150
  var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
148
151
  var rowStart = _ref2.rowStart,
@@ -220,6 +223,9 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
220
223
  // meaning that selectionAreas should only have one item by default
221
224
 
222
225
  if (isHoldingCommandKey) {
226
+ var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
227
+ activeCellElement.setAttribute('data-selection-id', tempMatcher);
228
+ setActiveCellInsideSelectionArea(true);
223
229
  setActiveCellCoordinates(activeCoordinates);
224
230
  setCurrentMatcher(tempMatcher);
225
231
  setSelectionAreas(function (prev) {
@@ -250,6 +256,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
250
256
  setSelectionAreas(selectionAreaClone);
251
257
  }
252
258
  } else {
259
+ setActiveCellInsideSelectionArea(false);
253
260
  setActiveCellCoordinates(activeCoordinates); // remove all previous cell selections
254
261
 
255
262
  (0, _removeCellSelections.removeCellSelections)({
@@ -263,7 +270,7 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
263
270
  setSelectionAreaData([]);
264
271
  }
265
272
  };
266
- }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
273
+ }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea]);
267
274
  var handleBodyCellHover = (0, _react.useCallback)(function (cell, columnIndex) {
268
275
  return function () {
269
276
  if (clickAndHoldActive) {
@@ -296,7 +303,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
296
303
  };
297
304
  }, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
298
305
  var handleRowHeaderClick = (0, _react.useCallback)(function (index) {
299
- return function () {
306
+ return function (event) {
307
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
300
308
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)({
301
309
  type: 'row',
302
310
  activeCellCoordinates: activeCellCoordinates,
@@ -307,7 +315,8 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
307
315
  setSelectionAreas: setSelectionAreas,
308
316
  spreadsheetRef: ref,
309
317
  index: index,
310
- setSelectionAreaData: setSelectionAreaData
318
+ setSelectionAreaData: setSelectionAreaData,
319
+ isHoldingCommandKey: isHoldingCommandKey
311
320
  });
312
321
  };
313
322
  }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Builds the empty rows and calls `onDataUpdate` to set the new empty rows
@@ -350,10 +359,11 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
350
359
  }), {
351
360
  className: (0, _classnames.default)("".concat(blockClass, "__tr")),
352
361
  "data-row-index": index,
353
- "aria-rowindex": index
362
+ "aria-rowindex": index + 1
354
363
  }), /*#__PURE__*/_react.default.createElement("div", {
355
364
  role: "rowheader"
356
365
  }, /*#__PURE__*/_react.default.createElement("button", {
366
+ id: "".concat(blockClass, "__cell--").concat(index, "--header"),
357
367
  tabIndex: -1,
358
368
  "data-row-index": index,
359
369
  "data-column-index": "header",
@@ -366,13 +376,14 @@ var DataSpreadsheetBody = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, re
366
376
  }, index + 1)), row.cells.map(function (cell, index) {
367
377
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
368
378
  key: "cell_".concat(index),
369
- "aria-colindex": index
379
+ "aria-colindex": index + 1
370
380
  }, cell.getCellProps(), {
371
381
  role: "gridcell",
372
382
  style: _objectSpread(_objectSpread({}, cell.getCellProps().style), {}, {
373
383
  display: 'grid'
374
384
  })
375
385
  }), /*#__PURE__*/_react.default.createElement("button", {
386
+ id: "".concat(blockClass, "__cell--").concat(cell.row.index, "--").concat(index),
376
387
  tabIndex: -1,
377
388
  "data-row-index": cell.row.index,
378
389
  "data-column-index": index,
@@ -496,6 +507,11 @@ DataSpreadsheetBody.propTypes = {
496
507
  */
497
508
  setActiveCellCoordinates: _propTypes.default.func,
498
509
 
510
+ /**
511
+ * Setter fn for active cell inside of selection area
512
+ */
513
+ setActiveCellInsideSelectionArea: _propTypes.default.func,
514
+
499
515
  /**
500
516
  * Setter fn for clickAndHold state value
501
517
  */