@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
@@ -12,23 +12,26 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
12
12
  // LICENSE file in the root directory of this source tree.
13
13
  //
14
14
  import React, { useState } from 'react';
15
- import { Button, ButtonSet, Dropdown, TextInput } from 'carbon-components-react';
15
+ import { Button, ButtonSet, Dropdown, TextInput, Tag } from 'carbon-components-react';
16
16
  import PropTypes from 'prop-types';
17
17
  import { Filter16 } from '@carbon/icons-react';
18
18
  import { pkg } from '../../settings';
19
19
  var componentName = 'AddSelectFilter';
20
20
  export var AddSelectFilter = function AddSelectFilter(_ref) {
21
- var filterOpts = _ref.filterOpts,
21
+ var appliedFilters = _ref.appliedFilters,
22
+ clearFiltersText = _ref.clearFiltersText,
23
+ filterOpts = _ref.filterOpts,
22
24
  handleFilter = _ref.handleFilter,
23
25
  handleSearch = _ref.handleSearch,
26
+ hasFiltersApplied = _ref.hasFiltersApplied,
24
27
  iconDescription = _ref.iconDescription,
28
+ inputLabel = _ref.inputLabel,
25
29
  inputPlaceholder = _ref.inputPlaceholder,
26
30
  multi = _ref.multi,
27
31
  placeholder = _ref.placeholder,
28
32
  primaryButtonText = _ref.primaryButtonText,
29
33
  searchTerm = _ref.searchTerm,
30
- secondaryButtonText = _ref.secondaryButtonText,
31
- textInputLabel = _ref.textInputLabel;
34
+ secondaryButtonText = _ref.secondaryButtonText;
32
35
 
33
36
  var _useState = useState({}),
34
37
  _useState2 = _slicedToArray(_useState, 2),
@@ -50,6 +53,14 @@ export var AddSelectFilter = function AddSelectFilter(_ref) {
50
53
  var selectedItem = _ref2.selectedItem;
51
54
  setFilters(_objectSpread(_objectSpread({}, filters), {}, _defineProperty({}, id, selectedItem)));
52
55
  };
56
+ /**
57
+ * this component needs to manage it's own internal state of filters before they're applied
58
+ * setFilters manages the local filter state
59
+ * applyFilters adds the filter state to the parent
60
+ * resetFilters resets the local state
61
+ * clearFilters resets both
62
+ */
63
+
53
64
 
54
65
  var applyFilters = function applyFilters() {
55
66
  handleFilter(filters);
@@ -59,16 +70,29 @@ export var AddSelectFilter = function AddSelectFilter(_ref) {
59
70
  setFilters({});
60
71
  };
61
72
 
73
+ var clearFilters = function clearFilters() {
74
+ resetFilters();
75
+ handleFilter({});
76
+ };
77
+
78
+ var removeTag = function removeTag(key) {
79
+ var newFilters = _objectSpread({}, filters);
80
+
81
+ delete newFilters[key];
82
+ setFilters(newFilters);
83
+ handleFilter(newFilters);
84
+ };
85
+
62
86
  var getSelectedItem = function getSelectedItem(id) {
63
87
  return filters[id] || '';
64
88
  };
65
89
 
66
90
  var showFilter = multi && (filterOpts === null || filterOpts === void 0 ? void 0 : filterOpts.length) > 0;
67
- return /*#__PURE__*/React.createElement("div", {
91
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
68
92
  className: "".concat(blockClass, "-search")
69
93
  }, /*#__PURE__*/React.createElement(TextInput, {
70
94
  id: "temp-id",
71
- labelText: textInputLabel,
95
+ labelText: inputLabel,
72
96
  placeholder: inputPlaceholder,
73
97
  value: searchTerm,
74
98
  onChange: searchHandler
@@ -111,19 +135,38 @@ export var AddSelectFilter = function AddSelectFilter(_ref) {
111
135
  kind: "primary",
112
136
  onClick: applyFilters,
113
137
  className: "".concat(blockClass, "-button")
114
- }, primaryButtonText))));
138
+ }, primaryButtonText)))), hasFiltersApplied && /*#__PURE__*/React.createElement("div", {
139
+ className: "".concat(blockClass, "-applied")
140
+ }, Object.keys(appliedFilters).map(function (filterType) {
141
+ return /*#__PURE__*/React.createElement(Tag, {
142
+ key: filterType,
143
+ type: "gray",
144
+ size: "sm",
145
+ onClose: function onClose() {
146
+ return removeTag(filterType);
147
+ },
148
+ filter: true
149
+ }, "".concat(filterType, ": ").concat(appliedFilters[filterType]));
150
+ }), /*#__PURE__*/React.createElement(Button, {
151
+ kind: "ghost",
152
+ size: "sm",
153
+ onClick: clearFilters
154
+ }, clearFiltersText)));
115
155
  };
116
156
  AddSelectFilter.propTypes = {
157
+ appliedFilters: PropTypes.object,
158
+ clearFiltersText: PropTypes.string,
117
159
  filterOpts: PropTypes.array,
118
160
  handleFilter: PropTypes.func,
119
161
  handleSearch: PropTypes.func,
162
+ hasFiltersApplied: PropTypes.bool,
120
163
  iconDescription: PropTypes.string,
164
+ inputLabel: PropTypes.string,
121
165
  inputPlaceholder: PropTypes.string,
122
166
  multi: PropTypes.bool,
123
167
  placeholder: PropTypes.string,
124
168
  primaryButtonText: PropTypes.string,
125
169
  searchTerm: PropTypes.string,
126
- secondaryButtonText: PropTypes.string,
127
- textInputLabel: PropTypes.string
170
+ secondaryButtonText: PropTypes.string
128
171
  };
129
172
  AddSelectFilter.displayName = componentName;
@@ -1,8 +1,9 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _typeof from "@babel/runtime/helpers/typeof";
2
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
5
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
6
+ var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange", "totalVisibleColumns"];
6
7
 
7
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; }
8
9
 
@@ -16,8 +17,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
16
17
  */
17
18
  // Import portions of React that are needed.
18
19
  import React, { useMemo, useRef, useState, useCallback, useEffect } from 'react';
19
- import { useBlockLayout, useTable } from 'react-table';
20
- import { px } from '@carbon/layout'; // Other standard imports.
20
+ import { useBlockLayout, useTable } from 'react-table'; // Other standard imports.
21
21
 
22
22
  import PropTypes from 'prop-types';
23
23
  import cx from 'classnames';
@@ -29,12 +29,17 @@ import { getDevtoolsProps } from '../../global/js/utils/devtools';
29
29
  import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
30
30
  import { useActiveElement, usePreviousValue } from '../../global/js/hooks';
31
31
  import uuidv4 from '../../global/js/utils/uuidv4';
32
- import { useResetSpreadsheetFocus, useSpreadsheetOutsideClick, useMoveActiveCell, useMultipleKeyTracking } from './hooks';
32
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
33
+ import { useResetSpreadsheetFocus, useSpreadsheetOutsideClick, useMoveActiveCell, useMultipleKeyTracking, useSpreadsheetEdit } from './hooks';
33
34
  import { createActiveCellFn } from './utils/createActiveCellFn';
34
35
  import { getCellSize } from './utils/getCellSize';
35
- import { handleMultipleKeys, includesShift } from './utils/handleMultipleKeys';
36
+ import { handleMultipleKeys, includesResourceKey, includesShift } from './utils/handleMultipleKeys';
36
37
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
37
- import { removeCellSelections } from './utils/removeCellSelections'; // cspell:words rowcount colcount
38
+ import { removeCellSelections } from './utils/removeCellSelections';
39
+ import { selectAllCells } from './utils/selectAllCells';
40
+ import { handleEditSubmit } from './utils/handleEditSubmit';
41
+ import { handleActiveCellInSelectionEnter } from './utils/handleActiveCellInSelectionEnter';
42
+ import { handleActiveCellInSelectionTab } from './utils/handleActiveCellInSelectionTab'; // cspell:words rowcount colcount
38
43
  // The block part of our conventional BEM class names (blockClass__E--M).
39
44
 
40
45
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
@@ -70,6 +75,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
70
75
  onActiveCellChange = _ref$onActiveCellChan === void 0 ? defaults.onActiveCellChange : _ref$onActiveCellChan,
71
76
  _ref$onSelectionAreaC = _ref.onSelectionAreaChange,
72
77
  onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
78
+ totalVisibleColumns = _ref.totalVisibleColumns,
73
79
  rest = _objectWithoutProperties(_ref, _excluded);
74
80
 
75
81
  var multiKeyTrackingRef = useRef();
@@ -117,6 +123,11 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
117
123
  cellEditorValue = _useState16[0],
118
124
  setCellEditorValue = _useState16[1];
119
125
 
126
+ var _useState17 = useState(false),
127
+ _useState18 = _slicedToArray(_useState17, 2),
128
+ activeCellInsideSelectionArea = _useState18[0],
129
+ setActiveCellInsideSelectionArea = _useState18[1];
130
+
120
131
  var previousState = usePreviousValue({
121
132
  activeCellCoordinates: activeCellCoordinates,
122
133
  isEditing: isEditing
@@ -124,10 +135,10 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
124
135
  var cellSizeValue = getCellSize(cellSize);
125
136
  var cellEditorRef = useRef();
126
137
 
127
- var _useState17 = useState(),
128
- _useState18 = _slicedToArray(_useState17, 2),
129
- activeCellContent = _useState18[0],
130
- setActiveCellContent = _useState18[1];
138
+ var _useState19 = useState(),
139
+ _useState20 = _slicedToArray(_useState19, 2),
140
+ activeCellContent = _useState20[0],
141
+ setActiveCellContent = _useState20[1];
131
142
 
132
143
  var activeCellRef = useRef();
133
144
  var cellEditorRulerRef = useRef();
@@ -144,7 +155,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
144
155
  containerHasFocus: containerHasFocus,
145
156
  isEditing: isEditing
146
157
  }),
147
- keysPressedList = _useMultipleKeyTracki.keysPressedList;
158
+ keysPressedList = _useMultipleKeyTracki.keysPressedList,
159
+ usingMac = _useMultipleKeyTracki.usingMac;
148
160
 
149
161
  var scrollBarSize = useMemo(function () {
150
162
  return getScrollbarWidth();
@@ -257,6 +269,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
257
269
  var handleInitialArrowPress = useCallback(function () {
258
270
  // If activeCellCoordinates is null then we need to set an initial value
259
271
  // which will place the activeCell on the select all cell/button
272
+ setActiveCellInsideSelectionArea(false);
273
+
260
274
  if (!activeCellCoordinates) {
261
275
  setActiveCellCoordinates({
262
276
  column: 'header',
@@ -267,16 +281,20 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
267
281
  return;
268
282
  }, [activeCellCoordinates]);
269
283
  var updateActiveCellCoordinates = useCallback(function (_ref3) {
270
- var coords = _ref3.coords,
271
- updatedValue = _ref3.updatedValue;
284
+ var _ref3$coords = _ref3.coords,
285
+ coords = _ref3$coords === void 0 ? _objectSpread({}, activeCellCoordinates) : _ref3$coords,
286
+ updatedValue = _ref3.updatedValue,
287
+ _ref3$optOutOfSelecti = _ref3.optOutOfSelectionAreaUpdate,
288
+ optOutOfSelectionAreaUpdate = _ref3$optOutOfSelecti === void 0 ? false : _ref3$optOutOfSelecti;
272
289
 
273
290
  var newActiveCell = _objectSpread(_objectSpread({}, coords), updatedValue);
274
291
 
275
292
  setActiveCellCoordinates(newActiveCell); // Only run if the active cell is _not_ a header cell. This will add a point1 object
276
293
  // to selectionAreas every time the active cell changes, allowing us to create cell
277
- // selections using keyboard
294
+ // selections using keyboard. Opting out of the selection area updates here means
295
+ // that the active cell is being moved within a selection area
278
296
 
279
- if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header') {
297
+ if (newActiveCell.row !== 'header' && newActiveCell.column !== 'header' && !optOutOfSelectionAreaUpdate) {
280
298
  var tempMatcher = uuidv4();
281
299
  setSelectionAreas([{
282
300
  point1: newActiveCell,
@@ -284,7 +302,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
284
302
  }]);
285
303
  setCurrentMatcher(tempMatcher);
286
304
  }
287
- }, []);
305
+ }, [activeCellCoordinates]);
288
306
  var handleHomeEndKey = useCallback(function (_ref4) {
289
307
  var type = _ref4.type;
290
308
 
@@ -341,7 +359,13 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
341
359
  currentMatcher: currentMatcher,
342
360
  rows: rows,
343
361
  setSelectionAreas: setSelectionAreas,
344
- columns: columns
362
+ columns: columns,
363
+ updateActiveCellCoordinates: updateActiveCellCoordinates,
364
+ spreadsheetRef: spreadsheetRef,
365
+ removeCellSelections: removeCellSelections,
366
+ blockClass: blockClass,
367
+ setCurrentMatcher: setCurrentMatcher,
368
+ usingMac: usingMac
345
369
  });
346
370
  } // Allow arrow key navigation if there are less than two activeKeys OR
347
371
  // if one of the activeCellCoordinates is in a header position
@@ -349,9 +373,26 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
349
373
 
350
374
  if (keysPressedList.length < 2 && !includesShift(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
351
375
  switch (key) {
376
+ // Enter
377
+ case 'Enter':
378
+ {
379
+ handleActiveCellInSelectionEnter({
380
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
381
+ activeCellCoordinates: activeCellCoordinates,
382
+ activeCellRef: activeCellRef,
383
+ selectionAreas: selectionAreas,
384
+ updateActiveCellCoordinates: updateActiveCellCoordinates
385
+ });
386
+ break;
387
+ }
352
388
  // HOME
389
+
353
390
  case 'Home':
354
391
  {
392
+ if (includesResourceKey(keysPressedList, usingMac)) {
393
+ return;
394
+ }
395
+
355
396
  handleHomeEndKey({
356
397
  type: 'home'
357
398
  });
@@ -360,6 +401,10 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
360
401
 
361
402
  case 'End':
362
403
  {
404
+ if (includesResourceKey(keysPressedList, usingMac)) {
405
+ return;
406
+ }
407
+
363
408
  handleHomeEndKey({
364
409
  type: 'end'
365
410
  });
@@ -369,6 +414,17 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
369
414
 
370
415
  case 'Tab':
371
416
  {
417
+ if (activeCellInsideSelectionArea) {
418
+ event.preventDefault();
419
+ return handleActiveCellInSelectionTab({
420
+ activeCellInsideSelectionArea: activeCellInsideSelectionArea,
421
+ activeCellCoordinates: activeCellCoordinates,
422
+ activeCellRef: activeCellRef,
423
+ selectionAreas: selectionAreas,
424
+ updateActiveCellCoordinates: updateActiveCellCoordinates
425
+ });
426
+ }
427
+
372
428
  setSelectionAreas([]);
373
429
  removeActiveCell();
374
430
  removeCellEditor();
@@ -515,7 +571,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
515
571
  }
516
572
  }
517
573
  }
518
- }, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList]);
574
+ }, [activeCellInsideSelectionArea, updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList, usingMac]);
519
575
 
520
576
  var startEditMode = function startEditMode() {
521
577
  setIsEditing(true);
@@ -523,6 +579,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
523
579
  var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
524
580
  setCellEditorValue(activeCellValue);
525
581
  cellEditorRulerRef.current.textContent = activeCellValue;
582
+ cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
526
583
  }; // Sets the initial placement of the cell editor cursor at the end of the text area
527
584
  // this is not done for us by default in Safari
528
585
 
@@ -537,12 +594,37 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
537
594
  var handleActiveCellClick = function handleActiveCellClick() {
538
595
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
539
596
  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;
597
+
598
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
599
+ return;
600
+ }
601
+
540
602
  handleRowColumnHeaderClick({
541
603
  isKeyboard: false,
542
604
  index: indexValue
543
605
  });
544
606
  }
545
607
 
608
+ return;
609
+ }; // Mouse down on active cell
610
+
611
+
612
+ var handleActiveCellMouseDown = function handleActiveCellMouseDown() {
613
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
614
+ var tempMatcher = uuidv4();
615
+ setClickAndHoldActive(true);
616
+ removeCellSelections({
617
+ spreadsheetRef: spreadsheetRef
618
+ });
619
+ setSelectionAreas([{
620
+ point1: activeCellCoordinates,
621
+ matcher: tempMatcher
622
+ }]);
623
+ setCurrentMatcher(tempMatcher);
624
+ setSelectionAreaData([]);
625
+ setActiveCellInsideSelectionArea(false);
626
+ }
627
+
546
628
  return;
547
629
  }; // Go into edit mode if 'Enter' key is pressed on activeCellRef
548
630
 
@@ -550,7 +632,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
550
632
  var handleActiveCellKeyDown = function handleActiveCellKeyDown(event) {
551
633
  var key = event.key;
552
634
 
553
- if (key === 'Enter') {
635
+ if (key === 'Enter' && !activeCellInsideSelectionArea) {
554
636
  if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
555
637
  startEditMode();
556
638
  }
@@ -580,18 +662,30 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
580
662
  index: index
581
663
  }; // Select an entire column
582
664
 
583
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
665
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
584
666
  handleHeaderCellSelection(_objectSpread({
585
667
  type: 'column'
586
668
  }, handleHeaderCellProps));
587
669
  } // Select an entire row
588
670
 
589
671
 
590
- if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
672
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header') {
591
673
  handleHeaderCellSelection(_objectSpread({
592
674
  type: 'row'
593
675
  }, handleHeaderCellProps));
594
676
  }
677
+
678
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
679
+ selectAllCells({
680
+ ref: spreadsheetRef,
681
+ setCurrentMatcher: setCurrentMatcher,
682
+ setSelectionAreas: setSelectionAreas,
683
+ rows: rows,
684
+ columns: columns,
685
+ activeCellCoordinates: activeCellCoordinates,
686
+ updateActiveCellCoordinates: updateActiveCellCoordinates
687
+ });
688
+ }
595
689
  }; // Go into edit mode if double click is detected on activeCellRef
596
690
 
597
691
 
@@ -599,116 +693,55 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
599
693
  startEditMode();
600
694
  };
601
695
 
602
- var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref6) {
603
- var type = _ref6.type;
604
-
605
- var submitEditChanges = function submitEditChanges() {
606
- var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
607
- var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
608
- removeCellEditor();
609
- updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
610
- };
611
-
612
- removeCellSelections({
613
- spreadsheetRef: spreadsheetRef
614
- });
615
- submitEditChanges();
616
- var tempMatcher = uuidv4();
617
- var newSelectionArea = {
618
- row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
619
- column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
620
- };
621
- setSelectionAreas([{
622
- point1: newSelectionArea,
623
- point2: newSelectionArea,
624
- matcher: tempMatcher,
625
- areaCreated: false
626
- }]);
627
- setCurrentMatcher(tempMatcher);
628
- cellEditorRulerRef.current.textContent = '';
629
- }; // Update the data
630
-
631
-
632
- var handleEditSubmit = function handleEditSubmit(event) {
633
- var key = event.key;
634
-
635
- if (key === 'Enter') {
636
- updateSelectionAreaOnCellEditSubmit({
637
- type: 'Enter'
638
- });
639
- setActiveCellCoordinates(function (prev) {
640
- return _objectSpread(_objectSpread({}, prev), {}, {
641
- 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
642
-
643
- });
644
- });
696
+ useSpreadsheetEdit({
697
+ isEditing: isEditing,
698
+ rows: rows,
699
+ activeCellCoordinates: activeCellCoordinates,
700
+ activeCellRef: activeCellRef,
701
+ cellEditorRef: cellEditorRef,
702
+ cellEditorRulerRef: cellEditorRulerRef,
703
+ columns: columns,
704
+ defaultColumn: defaultColumn,
705
+ cellEditorValue: cellEditorValue
706
+ });
707
+ var handleActiveCellMouseEnter = useCallback(function () {
708
+ handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
709
+ }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]); // Only update if there are cell selection areas
710
+ // Find point object that matches currentMatcher and remove the second point
711
+ // because hovering over the active cell while clicking and holding should
712
+ // remove the previously existing selection area
713
+
714
+ var handleActiveCellMouseEnterCallback = useCallback(function (areas, clickHold) {
715
+ if (!currentMatcher) {
716
+ return;
645
717
  }
646
718
 
647
- if (key === 'Tab') {
648
- event.preventDefault();
649
- updateSelectionAreaOnCellEditSubmit({
650
- type: 'Tab'
651
- });
652
- setActiveCellCoordinates(function (prev) {
653
- return _objectSpread(_objectSpread({}, prev), {}, {
654
- 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
655
-
719
+ if (areas && areas.length && clickHold && currentMatcher) {
720
+ setSelectionAreas(function (prev) {
721
+ var selectionAreaClone = deepCloneObject(prev);
722
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
723
+ return item.matcher === currentMatcher;
656
724
  });
657
- });
658
- }
659
725
 
660
- return;
661
- };
726
+ if (indexOfItemToUpdate === -1) {
727
+ return prev;
728
+ }
662
729
 
663
- useEffect(function () {
664
- if (isEditing) {
665
- var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
666
-
667
- 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];
668
- var activeCellLeftPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.left;
669
- var activeCellTopPosition = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.top;
670
- cellEditorRef.current.style.left = activeCellLeftPosition;
671
- cellEditorRef.current.style.top = activeCellTopPosition;
672
- cellEditorRef.current.style.display = 'block';
673
- cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
674
- cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
675
- 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
676
-
677
- 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';
678
- (_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
679
- var rulerWidth = cellEditorRulerRef.current.offsetWidth;
680
- var cellWidth = activeCellRef.current.offsetWidth;
681
-
682
- if (rulerWidth >= cellWidth) {
683
- var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
684
- var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
685
- var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
686
- var totalColumns = columns.length;
687
- var totalRows = rows.length;
688
- var totalMultiplierPossible = totalColumns - startingColumnPosition;
689
- var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
690
- cellEditorRef.current.style.maxHeight = px(totalCellEditorMaxHeight);
691
- cellEditorRef.current.style.width = px(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
692
- cellEditorRef.current.style.height = px(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
693
- // Cell editor has reached max height, we need to add the scrolling back.
694
- // We also need to subtract 1 to account for the fact that the cell editor
695
- // is placed one pixel below the cell being edited to account for the border
696
-
697
- if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
698
- cellEditorRef.current.style.overflow = 'auto';
699
- } else {
700
- cellEditorRef.current.style.overflow = 'hidden';
730
+ if (_typeof(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
731
+ selectionAreaClone[indexOfItemToUpdate].point2 = selectionAreaClone[indexOfItemToUpdate].point1;
732
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
733
+ setActiveCellInsideSelectionArea(false);
734
+ removeCellSelections({
735
+ matcher: currentMatcher,
736
+ spreadsheetRef: spreadsheetRef
737
+ });
738
+ return selectionAreaClone;
701
739
  }
702
- }
703
- }
704
740
 
705
- if (!isEditing) {
706
- cellEditorRef.current.style.overflow = 'hidden';
707
- cellEditorRef.current.style.display = 'none';
708
- cellEditorRef.current.blur();
709
- activeCellRef.current.focus();
741
+ return prev;
742
+ });
710
743
  }
711
- }, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
744
+ }, [spreadsheetRef, currentMatcher]);
712
745
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
713
746
  className: cx(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), _defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
714
747
  ref: spreadsheetRef,
@@ -735,7 +768,9 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
735
768
  setActiveCellCoordinates: setActiveCellCoordinates,
736
769
  setSelectionAreas: setSelectionAreas,
737
770
  setCurrentMatcher: setCurrentMatcher,
738
- setSelectionAreaData: setSelectionAreaData
771
+ setSelectionAreaData: setSelectionAreaData,
772
+ totalVisibleColumns: totalVisibleColumns,
773
+ updateActiveCellCoordinates: updateActiveCellCoordinates
739
774
  }), /*#__PURE__*/React.createElement(DataSpreadsheetBody, {
740
775
  activeCellCoordinates: activeCellCoordinates,
741
776
  ref: spreadsheetRef,
@@ -762,24 +797,40 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
762
797
  totalColumnsWidth: totalColumnsWidth,
763
798
  id: id,
764
799
  columns: columns,
765
- defaultEmptyRowCount: defaultEmptyRowCount
800
+ defaultEmptyRowCount: defaultEmptyRowCount,
801
+ setActiveCellInsideSelectionArea: setActiveCellInsideSelectionArea,
802
+ totalVisibleColumns: totalVisibleColumns
766
803
  }), /*#__PURE__*/React.createElement("button", {
804
+ onMouseDown: handleActiveCellMouseDown,
767
805
  onClick: handleActiveCellClick,
768
806
  onKeyDown: handleActiveCellKeyDown,
769
807
  onDoubleClick: handleActiveCellDoubleClick,
808
+ onMouseEnter: handleActiveCellMouseEnter,
770
809
  ref: activeCellRef,
771
- className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
810
+ className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight"), _defineProperty({}, "".concat(blockClass, "__active-cell--with-selection"), activeCellInsideSelectionArea)),
772
811
  type: "button"
773
812
  }, activeCellContent), /*#__PURE__*/React.createElement(TextArea, {
774
813
  value: cellEditorValue,
775
- onKeyDown: handleEditSubmit,
814
+ onKeyDown: handleEditSubmit({
815
+ activeCellCoordinates: activeCellCoordinates,
816
+ cellEditorRulerRef: cellEditorRulerRef,
817
+ columns: columns,
818
+ previousState: previousState,
819
+ removeCellEditor: removeCellEditor,
820
+ rows: rows,
821
+ setActiveCellCoordinates: setActiveCellCoordinates,
822
+ setCurrentMatcher: setCurrentMatcher,
823
+ setSelectionAreas: setSelectionAreas,
824
+ spreadsheetRef: spreadsheetRef,
825
+ updateData: updateData
826
+ }),
776
827
  onChange: function onChange(event) {
777
828
  setCellEditorValue(event.target.value);
778
829
  cellEditorRulerRef.current.textContent = event.target.value;
779
830
  },
780
831
  ref: cellEditorRef,
781
832
  labelText: "",
782
- "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,
833
+ "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,
783
834
  className: cx("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), _defineProperty({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
784
835
  }), /*#__PURE__*/React.createElement("pre", {
785
836
  "aria-hidden": true,
@@ -844,7 +895,13 @@ DataSpreadsheet.propTypes = {
844
895
  /**
845
896
  * The event handler that is called when the selection area values change
846
897
  */
847
- onSelectionAreaChange: PropTypes.func
898
+ onSelectionAreaChange: PropTypes.func,
899
+
900
+ /**
901
+ * The total number of columns to be initially visible, additional columns will be rendered and
902
+ * visible via horizontal scrollbar
903
+ */
904
+ totalVisibleColumns: PropTypes.number
848
905
  /* TODO: add types and DocGen for all props. */
849
906
 
850
907
  };