@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
@@ -24,28 +24,36 @@ var range = function range(len) {
24
24
  return arr;
25
25
  };
26
26
 
27
- var newPet = function newPet() {
28
- return {
27
+ var newPet = function newPet(extraColumns) {
28
+ var extraDataProps = extraColumns && {
29
+ ownerName: petNames[Math.floor(Math.random() * petNames.length)],
30
+ weight: Math.floor(Math.random() * 40)
31
+ };
32
+ var defaultPet = {
29
33
  petType: pets[Math.floor(Math.random() * pets.length)],
30
34
  firstName: petNames[Math.floor(Math.random() * petNames.length)],
31
35
  age: Math.floor(Math.random() * 30),
32
36
  visits: Math.floor(Math.random() * 40),
33
37
  health: Math.floor(Math.random() * 100)
34
38
  };
35
- };
36
39
 
37
- export var generateData = function generateData() {
38
- for (var _len = arguments.length, lens = new Array(_len), _key = 0; _key < _len; _key++) {
39
- lens[_key] = arguments[_key];
40
+ if (extraColumns) {
41
+ return _objectSpread(_objectSpread({}, defaultPet), extraDataProps);
40
42
  }
41
43
 
44
+ return defaultPet;
45
+ };
46
+
47
+ export var generateData = function generateData(_ref) {
48
+ var rows = _ref.rows,
49
+ extraColumns = _ref.extraColumns;
50
+
42
51
  var makeDataLevel = function makeDataLevel() {
43
52
  var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
53
+ var lens = [rows];
44
54
  var len = lens[depth];
45
55
  return range(len).map(function () {
46
- return _objectSpread(_objectSpread({}, newPet()), {}, {
47
- subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined
48
- });
56
+ return _objectSpread({}, newPet(extraColumns));
49
57
  });
50
58
  };
51
59
 
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export var getSelectionAreaPoints = function getSelectionAreaPoints(area) {
8
+ var greatestRowIndex = Math.max(area.point1.row, area.point2.row);
9
+ var greatestColumnIndex = Math.max(area.point1.column, area.point2.column);
10
+ var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
11
+ var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
12
+ return {
13
+ greatestRowIndex: greatestRowIndex,
14
+ greatestColumnIndex: greatestColumnIndex,
15
+ lowestColumnIndex: lowestColumnIndex,
16
+ lowestRowIndex: lowestRowIndex
17
+ };
18
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { px } from '@carbon/layout';
8
+ export var getSpreadsheetWidth = function getSpreadsheetWidth(_ref) {
9
+ var type = _ref.type,
10
+ headerGroup = _ref.headerGroup,
11
+ scrollBarSizeValue = _ref.scrollBarSizeValue,
12
+ totalVisibleColumns = _ref.totalVisibleColumns,
13
+ defaultColumn = _ref.defaultColumn,
14
+ totalColumnsWidth = _ref.totalColumnsWidth;
15
+ var additionalWidth = scrollBarSizeValue + defaultColumn.rowHeaderWidth;
16
+
17
+ if (!totalVisibleColumns) {
18
+ if (type === 'header') {
19
+ return px(parseInt(headerGroup.getHeaderGroupProps().style.width) + additionalWidth);
20
+ }
21
+
22
+ if (type !== 'header') {
23
+ return totalColumnsWidth + additionalWidth;
24
+ }
25
+ }
26
+
27
+ if (totalVisibleColumns) {
28
+ return totalVisibleColumns * (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width) + additionalWidth;
29
+ }
30
+ };
@@ -0,0 +1,121 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ 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; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+
7
+ /**
8
+ * Copyright IBM Corp. 2022, 2022
9
+ *
10
+ * This source code is licensed under the Apache-2.0 license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+ import { getSelectionAreaPoints } from './getSelectionAreaPoints';
14
+ export var handleActiveCellInSelectionEnter = function handleActiveCellInSelectionEnter(_ref) {
15
+ var activeCellInsideSelectionArea = _ref.activeCellInsideSelectionArea,
16
+ activeCellCoordinates = _ref.activeCellCoordinates,
17
+ activeCellRef = _ref.activeCellRef,
18
+ selectionAreas = _ref.selectionAreas,
19
+ updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
20
+
21
+ if (!activeCellInsideSelectionArea) {
22
+ return;
23
+ }
24
+
25
+ var activeCellSelectionId = activeCellRef.current.getAttribute('data-selection-id');
26
+ var activeCellIndexInSelectionAreas = selectionAreas.findIndex(function (item) {
27
+ return item.matcher === activeCellSelectionId;
28
+ });
29
+ var selectionAreaToNavigate = selectionAreas[activeCellIndexInSelectionAreas];
30
+
31
+ var _getSelectionAreaPoin = getSelectionAreaPoints(selectionAreaToNavigate),
32
+ lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
33
+ lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
34
+ greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
35
+ greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex; // Move active cell down one row if possible
36
+
37
+
38
+ var coordinatesClone = _objectSpread({}, activeCellCoordinates);
39
+
40
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) < greatestRowIndex) {
41
+ updateActiveCellCoordinates({
42
+ coords: coordinatesClone,
43
+ updatedValue: {
44
+ row: (coordinatesClone === null || coordinatesClone === void 0 ? void 0 : coordinatesClone.row) + 1
45
+ },
46
+ optOutOfSelectionAreaUpdate: true
47
+ });
48
+ } // Move active cell to next column of selection area if it exists
49
+ // If not, find the next selection area and update active cell to
50
+ // be the first cell in that selection
51
+
52
+
53
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === greatestRowIndex) {
54
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) < greatestColumnIndex) {
55
+ updateActiveCellCoordinates({
56
+ coords: coordinatesClone,
57
+ updatedValue: {
58
+ column: (coordinatesClone === null || coordinatesClone === void 0 ? void 0 : coordinatesClone.column) + 1,
59
+ row: lowestRowIndex
60
+ },
61
+ optOutOfSelectionAreaUpdate: true
62
+ });
63
+ } // Move to next selection area if there is one, or back to
64
+ // the beginning of the current selection
65
+
66
+
67
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === greatestColumnIndex) {
68
+ if (selectionAreas.length > 1) {
69
+ if (selectionAreas[activeCellIndexInSelectionAreas + 1]) {
70
+ // Update activeCellRef data-selection-id attribute to the matcher of the next selection area
71
+ activeCellRef.current.setAttribute('data-selection-id', selectionAreas[activeCellIndexInSelectionAreas + 1].matcher);
72
+ var nextSelectionArea = selectionAreas[activeCellIndexInSelectionAreas + 1];
73
+
74
+ var _getSelectionAreaPoin2 = getSelectionAreaPoints(nextSelectionArea),
75
+ _lowestColumnIndex = _getSelectionAreaPoin2.lowestColumnIndex,
76
+ _lowestRowIndex = _getSelectionAreaPoin2.lowestRowIndex;
77
+
78
+ updateActiveCellCoordinates({
79
+ coords: coordinatesClone,
80
+ updatedValue: {
81
+ column: _lowestColumnIndex,
82
+ row: _lowestRowIndex
83
+ },
84
+ optOutOfSelectionAreaUpdate: true
85
+ });
86
+ return;
87
+ } else {
88
+ // There are multiple selection areas and the active cell is in the last one
89
+ // So we need to move the active cell to the first cell in the first selection area
90
+ activeCellRef.current.setAttribute('data-selection-id', selectionAreas[0].matcher);
91
+ var firstSelectionArea = selectionAreas[0];
92
+
93
+ var _getSelectionAreaPoin3 = getSelectionAreaPoints(firstSelectionArea),
94
+ _lowestColumnIndex2 = _getSelectionAreaPoin3.lowestColumnIndex,
95
+ _lowestRowIndex2 = _getSelectionAreaPoin3.lowestRowIndex;
96
+
97
+ updateActiveCellCoordinates({
98
+ coords: coordinatesClone,
99
+ updatedValue: {
100
+ column: _lowestColumnIndex2,
101
+ row: _lowestRowIndex2
102
+ },
103
+ optOutOfSelectionAreaUpdate: true
104
+ });
105
+ }
106
+ } // Only one selection area, go back to first cell in the selection
107
+
108
+
109
+ if (selectionAreas.length === 1) {
110
+ return updateActiveCellCoordinates({
111
+ coords: coordinatesClone,
112
+ updatedValue: {
113
+ column: lowestColumnIndex,
114
+ row: lowestRowIndex
115
+ },
116
+ optOutOfSelectionAreaUpdate: true
117
+ });
118
+ }
119
+ }
120
+ }
121
+ };
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { getSelectionAreaPoints } from './getSelectionAreaPoints';
8
+ export var handleActiveCellInSelectionTab = function handleActiveCellInSelectionTab(_ref) {
9
+ var activeCellInsideSelectionArea = _ref.activeCellInsideSelectionArea,
10
+ activeCellCoordinates = _ref.activeCellCoordinates,
11
+ activeCellRef = _ref.activeCellRef,
12
+ selectionAreas = _ref.selectionAreas,
13
+ updateActiveCellCoordinates = _ref.updateActiveCellCoordinates;
14
+
15
+ if (!activeCellInsideSelectionArea) {
16
+ return;
17
+ }
18
+
19
+ var activeCellSelectionId = activeCellRef.current.getAttribute('data-selection-id');
20
+ var activeCellIndexInSelectionAreas = selectionAreas.findIndex(function (item) {
21
+ return item.matcher === activeCellSelectionId;
22
+ });
23
+ var selectionAreaToNavigate = selectionAreas[activeCellIndexInSelectionAreas];
24
+
25
+ var _getSelectionAreaPoin = getSelectionAreaPoints(selectionAreaToNavigate),
26
+ lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
27
+ lowestRowIndex = _getSelectionAreaPoin.lowestRowIndex,
28
+ greatestColumnIndex = _getSelectionAreaPoin.greatestColumnIndex,
29
+ greatestRowIndex = _getSelectionAreaPoin.greatestRowIndex; // Move active cell to next column in selection area
30
+
31
+
32
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) < greatestColumnIndex) {
33
+ updateActiveCellCoordinates({
34
+ updatedValue: {
35
+ column: (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) + 1
36
+ },
37
+ optOutOfSelectionAreaUpdate: true
38
+ });
39
+ } // Move active cell to next row of selection area if it exists
40
+ // If not, find the next selection area and update active cell to
41
+ // be the first cell in that selection
42
+
43
+
44
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === greatestColumnIndex) {
45
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) < greatestRowIndex) {
46
+ updateActiveCellCoordinates({
47
+ updatedValue: {
48
+ column: lowestColumnIndex,
49
+ row: (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) + 1
50
+ },
51
+ optOutOfSelectionAreaUpdate: true
52
+ });
53
+ } // Move to next selection area if there is on, or back to
54
+ // the beginning of the current selection
55
+
56
+
57
+ if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === greatestRowIndex) {
58
+ if (selectionAreas.length > 1) {
59
+ if (selectionAreas[activeCellIndexInSelectionAreas + 1]) {
60
+ // Update activeCellRef data-selection-id attribute to the matcher of the next selection area
61
+ activeCellRef.current.setAttribute('data-selection-id', selectionAreas[activeCellIndexInSelectionAreas + 1].matcher);
62
+ var nextSelectionArea = selectionAreas[activeCellIndexInSelectionAreas + 1];
63
+
64
+ var _getSelectionAreaPoin2 = getSelectionAreaPoints(nextSelectionArea),
65
+ _lowestColumnIndex = _getSelectionAreaPoin2.lowestColumnIndex,
66
+ _lowestRowIndex = _getSelectionAreaPoin2.lowestRowIndex;
67
+
68
+ updateActiveCellCoordinates({
69
+ updatedValue: {
70
+ column: _lowestColumnIndex,
71
+ row: _lowestRowIndex
72
+ },
73
+ optOutOfSelectionAreaUpdate: true
74
+ });
75
+ return;
76
+ } else {
77
+ // There are multiple selection areas and the active cell is in the last one
78
+ // So we need to move the active cell to the first cell in the first selection area
79
+ activeCellRef.current.setAttribute('data-selection-id', selectionAreas[0].matcher);
80
+ var firstSelectionArea = selectionAreas[0];
81
+
82
+ var _getSelectionAreaPoin3 = getSelectionAreaPoints(firstSelectionArea),
83
+ _lowestColumnIndex2 = _getSelectionAreaPoin3.lowestColumnIndex,
84
+ _lowestRowIndex2 = _getSelectionAreaPoin3.lowestRowIndex;
85
+
86
+ updateActiveCellCoordinates({
87
+ updatedValue: {
88
+ column: _lowestColumnIndex2,
89
+ row: _lowestRowIndex2
90
+ },
91
+ optOutOfSelectionAreaUpdate: true
92
+ });
93
+ }
94
+ } // Only one selection area, go back to first cell in the selection
95
+
96
+
97
+ if (selectionAreas.length === 1) {
98
+ return updateActiveCellCoordinates({
99
+ updatedValue: {
100
+ column: lowestColumnIndex,
101
+ row: lowestRowIndex
102
+ },
103
+ optOutOfSelectionAreaUpdate: true
104
+ });
105
+ }
106
+ }
107
+ }
108
+ };
@@ -0,0 +1,87 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+
3
+ 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; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+
7
+ /**
8
+ * Copyright IBM Corp. 2022, 2022
9
+ *
10
+ * This source code is licensed under the Apache-2.0 license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+ import { removeCellSelections } from './removeCellSelections';
14
+ import uuidv4 from '../../../global/js/utils/uuidv4'; // Update the data
15
+
16
+ export var handleEditSubmit = function handleEditSubmit(_ref) {
17
+ var activeCellCoordinates = _ref.activeCellCoordinates,
18
+ cellEditorRulerRef = _ref.cellEditorRulerRef,
19
+ columns = _ref.columns,
20
+ previousState = _ref.previousState,
21
+ removeCellEditor = _ref.removeCellEditor,
22
+ rows = _ref.rows,
23
+ setActiveCellCoordinates = _ref.setActiveCellCoordinates,
24
+ setCurrentMatcher = _ref.setCurrentMatcher,
25
+ setSelectionAreas = _ref.setSelectionAreas,
26
+ spreadsheetRef = _ref.spreadsheetRef,
27
+ updateData = _ref.updateData;
28
+ return function (event) {
29
+ var key = event.key;
30
+
31
+ var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref2) {
32
+ var type = _ref2.type;
33
+
34
+ var submitEditChanges = function submitEditChanges() {
35
+ var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
36
+ var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
37
+ removeCellEditor();
38
+ updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
39
+ };
40
+
41
+ removeCellSelections({
42
+ spreadsheetRef: spreadsheetRef
43
+ });
44
+ submitEditChanges();
45
+ var tempMatcher = uuidv4();
46
+ var newSelectionArea = {
47
+ row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
48
+ column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
49
+ };
50
+ setSelectionAreas([{
51
+ point1: newSelectionArea,
52
+ point2: newSelectionArea,
53
+ matcher: tempMatcher,
54
+ areaCreated: false
55
+ }]);
56
+ setCurrentMatcher(tempMatcher);
57
+ cellEditorRulerRef.current.textContent = '';
58
+ };
59
+
60
+ if (key === 'Enter') {
61
+ updateSelectionAreaOnCellEditSubmit({
62
+ type: 'Enter'
63
+ });
64
+ setActiveCellCoordinates(function (prev) {
65
+ return _objectSpread(_objectSpread({}, prev), {}, {
66
+ 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
67
+
68
+ });
69
+ });
70
+ }
71
+
72
+ if (key === 'Tab') {
73
+ event.preventDefault();
74
+ updateSelectionAreaOnCellEditSubmit({
75
+ type: 'Tab'
76
+ });
77
+ setActiveCellCoordinates(function (prev) {
78
+ return _objectSpread(_objectSpread({}, prev), {}, {
79
+ 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
80
+
81
+ });
82
+ });
83
+ }
84
+
85
+ return;
86
+ };
87
+ };
@@ -1,11 +1,15 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+
1
3
  /**
2
4
  * Copyright IBM Corp. 2022, 2022
3
5
  *
4
6
  * This source code is licensed under the Apache-2.0 license found in the
5
7
  * LICENSE file in the root directory of this source tree.
6
8
  */
9
+ import { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
7
10
  import uuidv4 from '../../../global/js/utils/uuidv4';
8
11
  import { removeCellSelections } from './removeCellSelections';
12
+ import { checkActiveHeaderCell } from './checkActiveHeaderCell';
9
13
  export var handleHeaderCellSelection = function handleHeaderCellSelection(_ref) {
10
14
  var type = _ref.type,
11
15
  activeCellCoordinates = _ref.activeCellCoordinates,
@@ -17,8 +21,16 @@ export var handleHeaderCellSelection = function handleHeaderCellSelection(_ref)
17
21
  spreadsheetRef = _ref.spreadsheetRef,
18
22
  index = _ref.index,
19
23
  isKeyboard = _ref.isKeyboard,
20
- setSelectionAreaData = _ref.setSelectionAreaData;
21
- setSelectionAreaData([]);
24
+ setSelectionAreaData = _ref.setSelectionAreaData,
25
+ isHoldingCommandKey = _ref.isHoldingCommandKey;
26
+
27
+ if (!isHoldingCommandKey) {
28
+ setSelectionAreaData([]);
29
+ removeCellSelections({
30
+ spreadsheetRef: spreadsheetRef
31
+ });
32
+ }
33
+
22
34
  var rowValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row : index;
23
35
  var columnValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column : index;
24
36
  var point1 = {
@@ -36,13 +48,39 @@ export var handleHeaderCellSelection = function handleHeaderCellSelection(_ref)
36
48
  column: type === 'column' ? columnValue : 0
37
49
  });
38
50
  setCurrentMatcher(tempMatcher);
39
- removeCellSelections({
40
- spreadsheetRef: spreadsheetRef
41
- });
42
- setSelectionAreas([{
51
+ var newSelectionArea = {
43
52
  point1: point1,
44
53
  point2: point2,
45
54
  areaCreated: false,
46
- matcher: tempMatcher
47
- }]);
55
+ matcher: tempMatcher,
56
+ header: {
57
+ type: type,
58
+ index: index
59
+ }
60
+ };
61
+ setSelectionAreas(function (prev) {
62
+ var selectionsClone = deepCloneObject(prev);
63
+
64
+ if (isHoldingCommandKey) {
65
+ var selectionsFromHeaderCell = selectionsClone.filter(function (item) {
66
+ var _item$header;
67
+
68
+ return (_item$header = item.header) === null || _item$header === void 0 ? void 0 : _item$header.type;
69
+ });
70
+ var previouslyCreatedHeaderSelection = selectionsFromHeaderCell.filter(function (item) {
71
+ var _item$header2;
72
+
73
+ return ((_item$header2 = item.header) === null || _item$header2 === void 0 ? void 0 : _item$header2.type) === type;
74
+ });
75
+ var isHeaderPartOfPreviousSelection = checkActiveHeaderCell(index, previouslyCreatedHeaderSelection, type); // Prevents row/column header selections from being created multiple times
76
+
77
+ if (previouslyCreatedHeaderSelection.length && isHeaderPartOfPreviousSelection) {
78
+ return prev;
79
+ }
80
+
81
+ return [].concat(_toConsumableArray(prev), [newSelectionArea]);
82
+ }
83
+
84
+ return [newSelectionArea];
85
+ });
48
86
  };