@carbon/ibm-products 1.14.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. package/css/components/Datagrid/styles/datagrid.css +4 -0
  2. package/css/components/Datagrid/styles/datagrid.css.map +1 -1
  3. package/css/components/Datagrid/styles/index.css +5 -1
  4. package/css/components/Datagrid/styles/index.css.map +1 -1
  5. package/css/components/Datagrid/styles/useNestedRows.css +1 -1
  6. package/css/index-full-carbon.css +75 -16
  7. package/css/index-full-carbon.css.map +1 -1
  8. package/css/index-full-carbon.min.css +6 -3
  9. package/css/index-full-carbon.min.css.map +1 -1
  10. package/css/index-without-carbon-released-only.css +13 -7
  11. package/css/index-without-carbon-released-only.css.map +1 -1
  12. package/css/index-without-carbon-released-only.min.css +5 -2
  13. package/css/index-without-carbon-released-only.min.css.map +1 -1
  14. package/css/index-without-carbon.css +75 -16
  15. package/css/index-without-carbon.css.map +1 -1
  16. package/css/index-without-carbon.min.css +6 -3
  17. package/css/index-without-carbon.min.css.map +1 -1
  18. package/css/index.css +75 -16
  19. package/css/index.css.map +1 -1
  20. package/css/index.min.css +6 -3
  21. package/css/index.min.css.map +1 -1
  22. package/es/components/AddSelect/AddSelect.js +34 -23
  23. package/es/components/AddSelect/AddSelectFilter.js +52 -9
  24. package/es/components/DataSpreadsheet/DataSpreadsheet.js +186 -129
  25. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +67 -15
  26. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +55 -11
  27. package/es/components/DataSpreadsheet/hooks/index.js +2 -1
  28. package/es/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +36 -8
  29. package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +113 -0
  30. package/es/components/DataSpreadsheet/utils/checkSelectedHeaderCell.js +16 -0
  31. package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +29 -12
  32. package/es/components/DataSpreadsheet/utils/generateData.js +17 -9
  33. package/es/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +18 -0
  34. package/es/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +30 -0
  35. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +121 -0
  36. package/es/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +108 -0
  37. package/es/components/DataSpreadsheet/utils/handleEditSubmit.js +87 -0
  38. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +46 -8
  39. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +153 -15
  40. package/es/components/DataSpreadsheet/utils/selectAllCells.js +53 -0
  41. package/es/components/Datagrid/Datagrid/Datagrid.js +24 -12
  42. package/es/components/Datagrid/Datagrid/DatagridHead.js +8 -16
  43. package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +10 -10
  44. package/es/components/Datagrid/Datagrid/DatagridRow.js +12 -2
  45. package/es/components/Datagrid/Datagrid/index.js +6 -7
  46. package/es/components/Datagrid/index.js +1 -1
  47. package/es/components/Datagrid/useNestedRows.js +3 -3
  48. package/es/components/Datagrid/useRowExpander.js +1 -1
  49. package/es/components/ExportModal/ExportModal.js +10 -5
  50. package/es/components/MultiAddSelect/MultiAddSelect.js +150 -3
  51. package/es/components/PageHeader/PageHeader.js +3 -1
  52. package/es/components/SidePanel/SidePanel.js +5 -1
  53. package/es/components/SingleAddSelect/SingleAddSelect.js +90 -4
  54. package/es/components/TagSet/TagSet.js +13 -6
  55. package/es/components/Tearsheet/TearsheetShell.js +34 -10
  56. package/es/components/WebTerminal/WebTerminal.js +36 -11
  57. package/es/components/WebTerminal/WebTerminalContentWrapper.js +49 -0
  58. package/es/components/WebTerminal/index.js +2 -1
  59. package/es/components/index.js +1 -1
  60. package/es/global/js/package-settings.js +3 -1
  61. package/lib/components/AddSelect/AddSelect.js +34 -23
  62. package/lib/components/AddSelect/AddSelectFilter.js +51 -8
  63. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +190 -128
  64. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +69 -15
  65. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +58 -12
  66. package/lib/components/DataSpreadsheet/hooks/index.js +9 -1
  67. package/lib/components/DataSpreadsheet/hooks/useMultipleKeyTracking.js +36 -8
  68. package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +129 -0
  69. package/lib/components/DataSpreadsheet/utils/checkSelectedHeaderCell.js +26 -0
  70. package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +31 -13
  71. package/lib/components/DataSpreadsheet/utils/generateData.js +17 -9
  72. package/lib/components/DataSpreadsheet/utils/getSelectionAreaPoints.js +27 -0
  73. package/lib/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +40 -0
  74. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionEnter.js +127 -0
  75. package/lib/components/DataSpreadsheet/utils/handleActiveCellInSelectionTab.js +118 -0
  76. package/lib/components/DataSpreadsheet/utils/handleEditSubmit.js +94 -0
  77. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +48 -8
  78. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +161 -22
  79. package/lib/components/DataSpreadsheet/utils/selectAllCells.js +60 -0
  80. package/lib/components/Datagrid/Datagrid/Datagrid.js +25 -8
  81. package/lib/components/Datagrid/Datagrid/DatagridHead.js +8 -16
  82. package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +10 -10
  83. package/lib/components/Datagrid/Datagrid/DatagridRow.js +14 -2
  84. package/lib/components/Datagrid/Datagrid/index.js +3 -5
  85. package/lib/components/Datagrid/index.js +2 -2
  86. package/lib/components/Datagrid/useNestedRows.js +3 -3
  87. package/lib/components/Datagrid/useRowExpander.js +1 -1
  88. package/lib/components/ExportModal/ExportModal.js +9 -4
  89. package/lib/components/MultiAddSelect/MultiAddSelect.js +150 -2
  90. package/lib/components/PageHeader/PageHeader.js +3 -1
  91. package/lib/components/SidePanel/SidePanel.js +5 -1
  92. package/lib/components/SingleAddSelect/SingleAddSelect.js +91 -3
  93. package/lib/components/TagSet/TagSet.js +13 -6
  94. package/lib/components/Tearsheet/TearsheetShell.js +36 -10
  95. package/lib/components/WebTerminal/WebTerminal.js +36 -10
  96. package/lib/components/WebTerminal/WebTerminalContentWrapper.js +58 -0
  97. package/lib/components/WebTerminal/index.js +9 -1
  98. package/lib/components/index.js +6 -0
  99. package/lib/global/js/package-settings.js +3 -1
  100. package/package.json +13 -13
  101. package/scss/components/AboutModal/_about-modal.scss +4 -0
  102. package/scss/components/AddSelect/_add-select.scss +9 -2
  103. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +39 -2
  104. package/scss/components/Datagrid/styles/datagrid.scss +8 -0
  105. package/scss/components/Datagrid/styles/useNestedRows.scss +1 -1
  106. package/scss/components/ExportModal/_export-modal.scss +0 -4
  107. package/scss/components/SidePanel/_side-panel.scss +22 -3
  108. package/scss/components/WebTerminal/_storybook-styles.scss +5 -0
  109. package/scss/components/WebTerminal/_web-terminal.scss +14 -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
 
58
- var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
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
+
68
+ var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange", "totalVisibleColumns"];
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
 
@@ -100,6 +110,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
100
110
  onActiveCellChange = _ref$onActiveCellChan === void 0 ? defaults.onActiveCellChange : _ref$onActiveCellChan,
101
111
  _ref$onSelectionAreaC = _ref.onSelectionAreaChange,
102
112
  onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
113
+ totalVisibleColumns = _ref.totalVisibleColumns,
103
114
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
104
115
  var multiKeyTrackingRef = (0, _react.useRef)();
105
116
  var localRef = (0, _react.useRef)();
@@ -146,6 +157,11 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
146
157
  cellEditorValue = _useState16[0],
147
158
  setCellEditorValue = _useState16[1];
148
159
 
160
+ var _useState17 = (0, _react.useState)(false),
161
+ _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
162
+ activeCellInsideSelectionArea = _useState18[0],
163
+ setActiveCellInsideSelectionArea = _useState18[1];
164
+
149
165
  var previousState = (0, _hooks.usePreviousValue)({
150
166
  activeCellCoordinates: activeCellCoordinates,
151
167
  isEditing: isEditing
@@ -153,10 +169,10 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
153
169
  var cellSizeValue = (0, _getCellSize.getCellSize)(cellSize);
154
170
  var cellEditorRef = (0, _react.useRef)();
155
171
 
156
- var _useState17 = (0, _react.useState)(),
157
- _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
158
- activeCellContent = _useState18[0],
159
- setActiveCellContent = _useState18[1];
172
+ var _useState19 = (0, _react.useState)(),
173
+ _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
174
+ activeCellContent = _useState20[0],
175
+ setActiveCellContent = _useState20[1];
160
176
 
161
177
  var activeCellRef = (0, _react.useRef)();
162
178
  var cellEditorRulerRef = (0, _react.useRef)();
@@ -173,7 +189,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
173
189
  containerHasFocus: containerHasFocus,
174
190
  isEditing: isEditing
175
191
  }),
176
- keysPressedList = _useMultipleKeyTracki.keysPressedList;
192
+ keysPressedList = _useMultipleKeyTracki.keysPressedList,
193
+ usingMac = _useMultipleKeyTracki.usingMac;
177
194
 
178
195
  var scrollBarSize = (0, _react.useMemo)(function () {
179
196
  return (0, _getScrollbarWidth.getScrollbarWidth)();
@@ -286,6 +303,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
286
303
  var handleInitialArrowPress = (0, _react.useCallback)(function () {
287
304
  // If activeCellCoordinates is null then we need to set an initial value
288
305
  // which will place the activeCell on the select all cell/button
306
+ setActiveCellInsideSelectionArea(false);
307
+
289
308
  if (!activeCellCoordinates) {
290
309
  setActiveCellCoordinates({
291
310
  column: 'header',
@@ -296,16 +315,20 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
296
315
  return;
297
316
  }, [activeCellCoordinates]);
298
317
  var updateActiveCellCoordinates = (0, _react.useCallback)(function (_ref3) {
299
- var coords = _ref3.coords,
300
- updatedValue = _ref3.updatedValue;
318
+ var _ref3$coords = _ref3.coords,
319
+ coords = _ref3$coords === void 0 ? _objectSpread({}, activeCellCoordinates) : _ref3$coords,
320
+ updatedValue = _ref3.updatedValue,
321
+ _ref3$optOutOfSelecti = _ref3.optOutOfSelectionAreaUpdate,
322
+ optOutOfSelectionAreaUpdate = _ref3$optOutOfSelecti === void 0 ? false : _ref3$optOutOfSelecti;
301
323
 
302
324
  var newActiveCell = _objectSpread(_objectSpread({}, coords), updatedValue);
303
325
 
304
326
  setActiveCellCoordinates(newActiveCell); // Only run if the active cell is _not_ a header cell. This will add a point1 object
305
327
  // to selectionAreas every time the active cell changes, allowing us to create cell
306
- // selections using keyboard
328
+ // selections using keyboard. Opting out of the selection area updates here means
329
+ // that the active cell is being moved within a selection area
307
330
 
308
- if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header') {
331
+ if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header' && !optOutOfSelectionAreaUpdate) {
309
332
  var tempMatcher = (0, _uuidv.default)();
310
333
  setSelectionAreas([{
311
334
  point1: newActiveCell,
@@ -313,7 +336,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
313
336
  }]);
314
337
  setCurrentMatcher(tempMatcher);
315
338
  }
316
- }, []);
339
+ }, [activeCellCoordinates]);
317
340
  var handleHomeEndKey = (0, _react.useCallback)(function (_ref4) {
318
341
  var type = _ref4.type;
319
342
 
@@ -370,7 +393,13 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
370
393
  currentMatcher: currentMatcher,
371
394
  rows: rows,
372
395
  setSelectionAreas: setSelectionAreas,
373
- columns: columns
396
+ columns: columns,
397
+ updateActiveCellCoordinates: updateActiveCellCoordinates,
398
+ spreadsheetRef: spreadsheetRef,
399
+ removeCellSelections: _removeCellSelections.removeCellSelections,
400
+ blockClass: blockClass,
401
+ setCurrentMatcher: setCurrentMatcher,
402
+ usingMac: usingMac
374
403
  });
375
404
  } // Allow arrow key navigation if there are less than two activeKeys OR
376
405
  // if one of the activeCellCoordinates is in a header position
@@ -378,9 +407,26 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
378
407
 
379
408
  if (keysPressedList.length < 2 && !(0, _handleMultipleKeys.includesShift)(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
380
409
  switch (key) {
410
+ // Enter
411
+ case 'Enter':
412
+ {
413
+ (0, _handleActiveCellInSelectionEnter.handleActiveCellInSelectionEnter)({
414
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
415
+ activeCellCoordinates: activeCellCoordinates,
416
+ activeCellRef: activeCellRef,
417
+ selectionAreas: selectionAreas,
418
+ updateActiveCellCoordinates: updateActiveCellCoordinates
419
+ });
420
+ break;
421
+ }
381
422
  // HOME
423
+
382
424
  case 'Home':
383
425
  {
426
+ if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac)) {
427
+ return;
428
+ }
429
+
384
430
  handleHomeEndKey({
385
431
  type: 'home'
386
432
  });
@@ -389,6 +435,10 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
389
435
 
390
436
  case 'End':
391
437
  {
438
+ if ((0, _handleMultipleKeys.includesResourceKey)(keysPressedList, usingMac)) {
439
+ return;
440
+ }
441
+
392
442
  handleHomeEndKey({
393
443
  type: 'end'
394
444
  });
@@ -398,6 +448,17 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
398
448
 
399
449
  case 'Tab':
400
450
  {
451
+ if (activeCellInsideSelectionArea) {
452
+ event.preventDefault();
453
+ return (0, _handleActiveCellInSelectionTab.handleActiveCellInSelectionTab)({
454
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
455
+ activeCellCoordinates: activeCellCoordinates,
456
+ activeCellRef: activeCellRef,
457
+ selectionAreas: selectionAreas,
458
+ updateActiveCellCoordinates: updateActiveCellCoordinates
459
+ });
460
+ }
461
+
401
462
  setSelectionAreas([]);
402
463
  removeActiveCell();
403
464
  removeCellEditor();
@@ -544,7 +605,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
544
605
  }
545
606
  }
546
607
  }
547
- }, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList]);
608
+ }, [activeCellInsideSelectionArea, updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList, usingMac]);
548
609
 
549
610
  var startEditMode = function startEditMode() {
550
611
  setIsEditing(true);
@@ -552,6 +613,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
552
613
  var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
553
614
  setCellEditorValue(activeCellValue);
554
615
  cellEditorRulerRef.current.textContent = activeCellValue;
616
+ cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
555
617
  }; // Sets the initial placement of the cell editor cursor at the end of the text area
556
618
  // this is not done for us by default in Safari
557
619
 
@@ -566,12 +628,37 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
566
628
  var handleActiveCellClick = function handleActiveCellClick() {
567
629
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
568
630
  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;
631
+
632
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
633
+ return;
634
+ }
635
+
569
636
  handleRowColumnHeaderClick({
570
637
  isKeyboard: false,
571
638
  index: indexValue
572
639
  });
573
640
  }
574
641
 
642
+ return;
643
+ }; // Mouse down on active cell
644
+
645
+
646
+ var handleActiveCellMouseDown = function handleActiveCellMouseDown() {
647
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
648
+ var tempMatcher = (0, _uuidv.default)();
649
+ setClickAndHoldActive(true);
650
+ (0, _removeCellSelections.removeCellSelections)({
651
+ spreadsheetRef: spreadsheetRef
652
+ });
653
+ setSelectionAreas([{
654
+ point1: activeCellCoordinates,
655
+ matcher: tempMatcher
656
+ }]);
657
+ setCurrentMatcher(tempMatcher);
658
+ setSelectionAreaData([]);
659
+ setActiveCellInsideSelectionArea(false);
660
+ }
661
+
575
662
  return;
576
663
  }; // Go into edit mode if 'Enter' key is pressed on activeCellRef
577
664
 
@@ -579,7 +666,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
579
666
  var handleActiveCellKeyDown = function handleActiveCellKeyDown(event) {
580
667
  var key = event.key;
581
668
 
582
- if (key === 'Enter') {
669
+ if (key === 'Enter' && !activeCellInsideSelectionArea) {
583
670
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
584
671
  startEditMode();
585
672
  }
@@ -609,18 +696,30 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
609
696
  index: index
610
697
  }; // Select an entire column
611
698
 
612
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
699
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
613
700
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
614
701
  type: 'column'
615
702
  }, handleHeaderCellProps));
616
703
  } // Select an entire row
617
704
 
618
705
 
619
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
706
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
620
707
  (0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
621
708
  type: 'row'
622
709
  }, handleHeaderCellProps));
623
710
  }
711
+
712
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
713
+ (0, _selectAllCells.selectAllCells)({
714
+ ref: spreadsheetRef,
715
+ setCurrentMatcher: setCurrentMatcher,
716
+ setSelectionAreas: setSelectionAreas,
717
+ rows: rows,
718
+ columns: columns,
719
+ activeCellCoordinates: activeCellCoordinates,
720
+ updateActiveCellCoordinates: updateActiveCellCoordinates
721
+ });
722
+ }
624
723
  }; // Go into edit mode if double click is detected on activeCellRef
625
724
 
626
725
 
@@ -628,116 +727,55 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
628
727
  startEditMode();
629
728
  };
630
729
 
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
- });
730
+ (0, _hooks2.useSpreadsheetEdit)({
731
+ isEditing: isEditing,
732
+ rows: rows,
733
+ activeCellCoordinates: activeCellCoordinates,
734
+ activeCellRef: activeCellRef,
735
+ cellEditorRef: cellEditorRef,
736
+ cellEditorRulerRef: cellEditorRulerRef,
737
+ columns: columns,
738
+ defaultColumn: defaultColumn,
739
+ cellEditorValue: cellEditorValue
740
+ });
741
+ var handleActiveCellMouseEnter = (0, _react.useCallback)(function () {
742
+ handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
743
+ }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]); // Only update if there are cell selection areas
744
+ // Find point object that matches currentMatcher and remove the second point
745
+ // because hovering over the active cell while clicking and holding should
746
+ // remove the previously existing selection area
747
+
748
+ var handleActiveCellMouseEnterCallback = (0, _react.useCallback)(function (areas, clickHold) {
749
+ if (!currentMatcher) {
750
+ return;
674
751
  }
675
752
 
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
-
753
+ if (areas && areas.length && clickHold && currentMatcher) {
754
+ setSelectionAreas(function (prev) {
755
+ var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(prev);
756
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
757
+ return item.matcher === currentMatcher;
685
758
  });
686
- });
687
- }
688
759
 
689
- return;
690
- };
760
+ if (indexOfItemToUpdate === -1) {
761
+ return prev;
762
+ }
691
763
 
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';
764
+ if ((0, _typeof2.default)(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
765
+ selectionAreaClone[indexOfItemToUpdate].point2 = selectionAreaClone[indexOfItemToUpdate].point1;
766
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
767
+ setActiveCellInsideSelectionArea(false);
768
+ (0, _removeCellSelections.removeCellSelections)({
769
+ matcher: currentMatcher,
770
+ spreadsheetRef: spreadsheetRef
771
+ });
772
+ return selectionAreaClone;
730
773
  }
731
- }
732
- }
733
774
 
734
- if (!isEditing) {
735
- cellEditorRef.current.style.overflow = 'hidden';
736
- cellEditorRef.current.style.display = 'none';
737
- cellEditorRef.current.blur();
738
- activeCellRef.current.focus();
775
+ return prev;
776
+ });
739
777
  }
740
- }, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
778
+ }, [spreadsheetRef, currentMatcher]);
741
779
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, getTableProps(), (0, _devtools.getDevtoolsProps)(componentName), {
742
780
  className: (0, _classnames.default)(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
743
781
  ref: spreadsheetRef,
@@ -764,7 +802,9 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
764
802
  setActiveCellCoordinates: setActiveCellCoordinates,
765
803
  setSelectionAreas: setSelectionAreas,
766
804
  setCurrentMatcher: setCurrentMatcher,
767
- setSelectionAreaData: setSelectionAreaData
805
+ setSelectionAreaData: setSelectionAreaData,
806
+ totalVisibleColumns: totalVisibleColumns,
807
+ updateActiveCellCoordinates: updateActiveCellCoordinates
768
808
  }), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetBody.DataSpreadsheetBody, {
769
809
  activeCellCoordinates: activeCellCoordinates,
770
810
  ref: spreadsheetRef,
@@ -791,24 +831,40 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
791
831
  totalColumnsWidth: totalColumnsWidth,
792
832
  id: id,
793
833
  columns: columns,
794
- defaultEmptyRowCount: defaultEmptyRowCount
834
+ defaultEmptyRowCount: defaultEmptyRowCount,
835
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea,
836
+ totalVisibleColumns: totalVisibleColumns
795
837
  }), /*#__PURE__*/_react.default.createElement("button", {
838
+ onMouseDown: handleActiveCellMouseDown,
796
839
  onClick: handleActiveCellClick,
797
840
  onKeyDown: handleActiveCellKeyDown,
798
841
  onDoubleClick: handleActiveCellDoubleClick,
842
+ onMouseEnter: handleActiveCellMouseEnter,
799
843
  ref: activeCellRef,
800
- className: (0, _classnames.default)("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
844
+ 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
845
  type: "button"
802
846
  }, activeCellContent), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TextArea, {
803
847
  value: cellEditorValue,
804
- onKeyDown: handleEditSubmit,
848
+ onKeyDown: (0, _handleEditSubmit.handleEditSubmit)({
849
+ activeCellCoordinates: activeCellCoordinates,
850
+ cellEditorRulerRef: cellEditorRulerRef,
851
+ columns: columns,
852
+ previousState: previousState,
853
+ removeCellEditor: removeCellEditor,
854
+ rows: rows,
855
+ setActiveCellCoordinates: setActiveCellCoordinates,
856
+ setCurrentMatcher: setCurrentMatcher,
857
+ setSelectionAreas: setSelectionAreas,
858
+ spreadsheetRef: spreadsheetRef,
859
+ updateData: updateData
860
+ }),
805
861
  onChange: function onChange(event) {
806
862
  setCellEditorValue(event.target.value);
807
863
  cellEditorRulerRef.current.textContent = event.target.value;
808
864
  },
809
865
  ref: cellEditorRef,
810
866
  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,
867
+ "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
868
  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
869
  }), /*#__PURE__*/_react.default.createElement("pre", {
814
870
  "aria-hidden": true,
@@ -875,7 +931,13 @@ DataSpreadsheet.propTypes = {
875
931
  /**
876
932
  * The event handler that is called when the selection area values change
877
933
  */
878
- onSelectionAreaChange: _propTypes.default.func
934
+ onSelectionAreaChange: _propTypes.default.func,
935
+
936
+ /**
937
+ * The total number of columns to be initially visible, additional columns will be rendered and
938
+ * visible via horizontal scrollbar
939
+ */
940
+ totalVisibleColumns: _propTypes.default.number
879
941
  /* TODO: add types and DocGen for all props. */
880
942
 
881
943
  };