@carbon/ibm-products 1.11.2 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +0 -3
- package/css/index-full-carbon.css +1387 -358
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +2 -2
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +1 -0
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +1 -1
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +51 -5
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +2 -2
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +51 -5
- package/css/index.css.map +1 -1
- package/css/index.min.css +2 -2
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +63 -12
- package/es/components/AddSelect/AddSelectColumn.js +0 -1
- package/es/components/AddSelect/AddSelectList.js +33 -13
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +107 -89
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +93 -20
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +50 -2
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/es/components/ImportModal/ImportModal.js +2 -2
- package/es/components/UserProfileImage/UserProfileImage.js +1 -1
- package/lib/components/AddSelect/AddSelect.js +63 -12
- package/lib/components/AddSelect/AddSelectColumn.js +0 -1
- package/lib/components/AddSelect/AddSelectList.js +34 -12
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +108 -91
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +94 -20
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +52 -7
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/lib/components/ImportModal/ImportModal.js +1 -1
- package/lib/components/UserProfileImage/UserProfileImage.js +1 -1
- package/package.json +13 -13
- package/scss/components/AboutModal/_about-modal.scss +2 -2
- package/scss/components/ActionSet/_action-set.scss +3 -1
- package/scss/components/AddSelect/_add-select.scss +37 -2
- package/scss/components/CreateModal/_create-modal.scss +7 -5
- package/scss/components/CreateModal/_storybook-styles.scss +8 -7
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +21 -3
- package/scss/components/ExportModal/_export-modal.scss +3 -3
- package/scss/components/InlineEdit/_inline-edit.scss +0 -1
- package/scss/components/ModifiedTabs/_modified-tabs.scss +0 -10
- package/scss/components/NotificationsPanel/_notifications-panel.scss +3 -3
- package/scss/components/OptionsTile/_options-tile.scss +0 -1
- package/scss/components/RemoveModal/_remove-modal.scss +3 -3
- package/scss/components/TagSet/_tag-set.scss +2 -1
- package/scss/components/Tearsheet/_tearsheet.scss +1 -2
@@ -1,3 +1,4 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2
3
|
//
|
3
4
|
// Copyright IBM Corp. 2022
|
@@ -6,14 +7,15 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
6
7
|
// LICENSE file in the root directory of this source tree.
|
7
8
|
//
|
8
9
|
import React from 'react';
|
9
|
-
import { Checkbox, RadioButton, StructuredListRow, StructuredListWrapper, StructuredListBody, StructuredListCell } from 'carbon-components-react';
|
10
|
+
import { Checkbox, RadioButton, StructuredListRow, StructuredListWrapper, StructuredListBody, StructuredListCell, Dropdown } from 'carbon-components-react';
|
10
11
|
import { ChevronRight16 } from '@carbon/icons-react';
|
11
12
|
import PropTypes from 'prop-types';
|
13
|
+
import cx from 'classnames';
|
12
14
|
import { pkg } from '../../settings';
|
13
15
|
var componentName = 'AddSelectList';
|
14
16
|
export var AddSelectList = function AddSelectList(_ref) {
|
15
17
|
var filteredItems = _ref.filteredItems,
|
16
|
-
|
18
|
+
modifiers = _ref.modifiers,
|
17
19
|
multi = _ref.multi,
|
18
20
|
multiSelection = _ref.multiSelection,
|
19
21
|
path = _ref.path,
|
@@ -99,32 +101,50 @@ export var AddSelectList = function AddSelectList(_ref) {
|
|
99
101
|
}
|
100
102
|
};
|
101
103
|
|
104
|
+
var isSelected = function isSelected(id) {
|
105
|
+
return multiSelection.includes(id);
|
106
|
+
};
|
107
|
+
|
102
108
|
return /*#__PURE__*/React.createElement("div", {
|
103
109
|
className: "".concat(blockClass, "-wrapper")
|
104
110
|
}, /*#__PURE__*/React.createElement(StructuredListWrapper, {
|
105
111
|
selection: true,
|
106
112
|
className: "".concat(blockClass)
|
107
113
|
}, /*#__PURE__*/React.createElement(StructuredListBody, null, filteredItems.map(function (item) {
|
114
|
+
var _modifiers$options;
|
115
|
+
|
108
116
|
return /*#__PURE__*/React.createElement(StructuredListRow, {
|
109
117
|
key: item.id,
|
110
|
-
className: "".concat(blockClass, "-row")
|
118
|
+
className: cx("".concat(blockClass, "-row"), _defineProperty({}, "".concat(blockClass, "-row-selected"), isSelected(item.id)))
|
111
119
|
}, /*#__PURE__*/React.createElement(StructuredListCell, {
|
112
120
|
className: "".concat(blockClass, "-cell")
|
113
121
|
}, /*#__PURE__*/React.createElement("div", {
|
114
122
|
className: "".concat(blockClass, "-cell-wrapper")
|
115
|
-
}, multi ? /*#__PURE__*/React.createElement(
|
116
|
-
className: "".concat(blockClass, "-checkbox")
|
123
|
+
}, multi ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
124
|
+
className: "".concat(blockClass, "-checkbox")
|
125
|
+
}, /*#__PURE__*/React.createElement(Checkbox, {
|
117
126
|
onChange: function onChange(checked) {
|
118
127
|
return handleMultiSelection(item.id, checked);
|
119
128
|
},
|
120
|
-
labelText:
|
121
|
-
className: "".concat(blockClass, "-cell-title")
|
122
|
-
}, item.title), /*#__PURE__*/React.createElement("span", {
|
123
|
-
className: "".concat(blockClass, "-cell-subtitle")
|
124
|
-
}, item.subtitle)) : item.title,
|
129
|
+
labelText: item.title,
|
125
130
|
id: item.id,
|
126
|
-
checked:
|
127
|
-
|
131
|
+
checked: isSelected(item.id),
|
132
|
+
className: "".concat(blockClass, "-checkbox-wrapper")
|
133
|
+
}), /*#__PURE__*/React.createElement("div", {
|
134
|
+
className: "".concat(blockClass, "-checkbox-label-text")
|
135
|
+
}, /*#__PURE__*/React.createElement("span", {
|
136
|
+
className: "".concat(blockClass, "-cell-title")
|
137
|
+
}, item.title), item.subtitle && /*#__PURE__*/React.createElement("span", {
|
138
|
+
className: "".concat(blockClass, "-cell-subtitle")
|
139
|
+
}, item.subtitle))), (modifiers === null || modifiers === void 0 ? void 0 : (_modifiers$options = modifiers.options) === null || _modifiers$options === void 0 ? void 0 : _modifiers$options.length) && /*#__PURE__*/React.createElement(Dropdown, {
|
140
|
+
id: "".concat(item.id, "-modifier"),
|
141
|
+
type: "inline",
|
142
|
+
items: modifiers === null || modifiers === void 0 ? void 0 : modifiers.options,
|
143
|
+
light: true,
|
144
|
+
label: modifiers === null || modifiers === void 0 ? void 0 : modifiers.label,
|
145
|
+
disabled: !isSelected(item.id),
|
146
|
+
className: "".concat(blockClass, "-dropdown")
|
147
|
+
})) : /*#__PURE__*/React.createElement(RadioButton, {
|
128
148
|
className: "".concat(blockClass, "-radio"),
|
129
149
|
name: "add-select-selections",
|
130
150
|
id: item.id,
|
@@ -141,7 +161,7 @@ export var AddSelectList = function AddSelectList(_ref) {
|
|
141
161
|
};
|
142
162
|
AddSelectList.propTypes = {
|
143
163
|
filteredItems: PropTypes.array,
|
144
|
-
|
164
|
+
modifiers: PropTypes.object,
|
145
165
|
multi: PropTypes.bool,
|
146
166
|
multiSelection: PropTypes.array,
|
147
167
|
path: PropTypes.array,
|
@@ -1,10 +1,9 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
|
-
import _typeof from "@babel/runtime/helpers/typeof";
|
3
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
4
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
5
4
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
6
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
7
|
-
var _excluded = ["cellSize", "className", "columns", "data", "onDataUpdate", "id", "onActiveCellChange"];
|
6
|
+
var _excluded = ["cellSize", "className", "columns", "data", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
|
8
7
|
|
9
8
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
10
9
|
|
@@ -28,9 +27,7 @@ import { DataSpreadsheetBody } from './DataSpreadsheetBody';
|
|
28
27
|
import { DataSpreadsheetHeader } from './DataSpreadsheetHeader';
|
29
28
|
import { getDevtoolsProps } from '../../global/js/utils/devtools';
|
30
29
|
import { getScrollbarWidth } from '../../global/js/utils/getScrollbarWidth';
|
31
|
-
import { useActiveElement } from '../../global/js/hooks';
|
32
|
-
import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
|
33
|
-
import { usePreviousValue } from '../../global/js/hooks';
|
30
|
+
import { useActiveElement, usePreviousValue } from '../../global/js/hooks';
|
34
31
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
35
32
|
import { useResetSpreadsheetFocus } from './hooks/useResetSpreadsheetFocus';
|
36
33
|
import { useSpreadsheetOutsideClick } from './hooks/useSpreadsheetOutsideClick';
|
@@ -48,7 +45,9 @@ var defaults = {
|
|
48
45
|
cellSize: 'standard',
|
49
46
|
columns: Object.freeze([]),
|
50
47
|
data: Object.freeze([]),
|
51
|
-
onDataUpdate: Object.freeze(function () {})
|
48
|
+
onDataUpdate: Object.freeze(function () {}),
|
49
|
+
onActiveCellChange: Object.freeze(function () {}),
|
50
|
+
onSelectionAreaChange: Object.freeze(function () {})
|
52
51
|
};
|
53
52
|
/**
|
54
53
|
* DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
|
@@ -65,7 +64,10 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
65
64
|
_ref$onDataUpdate = _ref.onDataUpdate,
|
66
65
|
onDataUpdate = _ref$onDataUpdate === void 0 ? defaults.onDataUpdate : _ref$onDataUpdate,
|
67
66
|
id = _ref.id,
|
68
|
-
|
67
|
+
_ref$onActiveCellChan = _ref.onActiveCellChange,
|
68
|
+
onActiveCellChange = _ref$onActiveCellChan === void 0 ? defaults.onActiveCellChange : _ref$onActiveCellChan,
|
69
|
+
_ref$onSelectionAreaC = _ref.onSelectionAreaChange,
|
70
|
+
onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
|
69
71
|
rest = _objectWithoutProperties(_ref, _excluded);
|
70
72
|
|
71
73
|
var localRef = useRef();
|
@@ -87,32 +89,42 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
87
89
|
selectionAreas = _useState6[0],
|
88
90
|
setSelectionAreas = _useState6[1];
|
89
91
|
|
90
|
-
var _useState7 = useState(
|
92
|
+
var _useState7 = useState([]),
|
91
93
|
_useState8 = _slicedToArray(_useState7, 2),
|
92
|
-
|
93
|
-
|
94
|
+
selectionAreaData = _useState8[0],
|
95
|
+
setSelectionAreaData = _useState8[1];
|
94
96
|
|
95
|
-
var _useState9 = useState(
|
97
|
+
var _useState9 = useState(false),
|
96
98
|
_useState10 = _slicedToArray(_useState9, 2),
|
97
|
-
|
98
|
-
|
99
|
+
clickAndHoldActive = _useState10[0],
|
100
|
+
setClickAndHoldActive = _useState10[1];
|
99
101
|
|
100
|
-
var _useState11 = useState(
|
102
|
+
var _useState11 = useState(''),
|
101
103
|
_useState12 = _slicedToArray(_useState11, 2),
|
102
|
-
|
103
|
-
|
104
|
+
currentMatcher = _useState12[0],
|
105
|
+
setCurrentMatcher = _useState12[1];
|
104
106
|
|
105
|
-
var _useState13 = useState(
|
107
|
+
var _useState13 = useState(false),
|
106
108
|
_useState14 = _slicedToArray(_useState13, 2),
|
107
|
-
|
108
|
-
|
109
|
+
isEditing = _useState14[0],
|
110
|
+
setIsEditing = _useState14[1];
|
111
|
+
|
112
|
+
var _useState15 = useState(''),
|
113
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
114
|
+
cellEditorValue = _useState16[0],
|
115
|
+
setCellEditorValue = _useState16[1];
|
109
116
|
|
110
117
|
var previousState = usePreviousValue({
|
111
118
|
activeCellCoordinates: activeCellCoordinates
|
112
119
|
});
|
113
120
|
var cellSizeValue = getCellSize(cellSize);
|
114
121
|
var cellEditorRef = useRef();
|
115
|
-
|
122
|
+
|
123
|
+
var _useState17 = useState(),
|
124
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
125
|
+
activeCellContent = _useState18[0],
|
126
|
+
setActiveCellContent = _useState18[1];
|
127
|
+
|
116
128
|
var activeKeys = useRef([]);
|
117
129
|
var activeCellRef = useRef();
|
118
130
|
var defaultColumn = useMemo(function () {
|
@@ -189,10 +201,18 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
189
201
|
removeCellEditor();
|
190
202
|
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
191
203
|
}
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
204
|
+
|
205
|
+
if ((prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) || (prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column) !== (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column)) {
|
206
|
+
if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
|
207
|
+
var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
208
|
+
setActiveCellContent(activeCellFullData.render('Cell'));
|
209
|
+
}
|
210
|
+
|
211
|
+
if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
212
|
+
setActiveCellContent(null);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor, activeCellContent]);
|
196
216
|
var createActiveCell = useCallback(function (_ref2) {
|
197
217
|
var placementElement = _ref2.placementElement,
|
198
218
|
coords = _ref2.coords,
|
@@ -296,6 +316,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
296
316
|
|
297
317
|
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
|
298
318
|
setSelectionAreas([]);
|
319
|
+
setSelectionAreaData([]);
|
299
320
|
removeCellSelections({
|
300
321
|
spreadsheetRef: spreadsheetRef
|
301
322
|
});
|
@@ -480,6 +501,18 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
480
501
|
var activeCellFullData = typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'number' && typeof (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'number' ? rows[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row].cells[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
481
502
|
var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
482
503
|
setCellEditorValue(activeCellValue);
|
504
|
+
};
|
505
|
+
|
506
|
+
var handleActiveCellClick = function handleActiveCellClick() {
|
507
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
508
|
+
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;
|
509
|
+
handleRowColumnHeaderClick({
|
510
|
+
isKeyboard: false,
|
511
|
+
index: indexValue
|
512
|
+
});
|
513
|
+
}
|
514
|
+
|
515
|
+
return;
|
483
516
|
}; // Go into edit mode if 'Enter' key is pressed on activeCellRef
|
484
517
|
|
485
518
|
|
@@ -492,31 +525,42 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
492
525
|
}
|
493
526
|
|
494
527
|
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
495
|
-
|
496
|
-
activeCellCoordinates: activeCellCoordinates,
|
497
|
-
rows: rows,
|
498
|
-
columns: columns,
|
499
|
-
setActiveCellCoordinates: setActiveCellCoordinates,
|
500
|
-
setCurrentMatcher: setCurrentMatcher,
|
501
|
-
setSelectionAreas: setSelectionAreas,
|
502
|
-
spreadsheetRef: spreadsheetRef,
|
528
|
+
handleRowColumnHeaderClick({
|
503
529
|
isKeyboard: true
|
504
|
-
};
|
505
|
-
|
506
|
-
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
507
|
-
handleHeaderCellSelection(_objectSpread({
|
508
|
-
type: 'column'
|
509
|
-
}, handleHeaderCellProps));
|
510
|
-
} // Select an entire row
|
511
|
-
|
512
|
-
|
513
|
-
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
514
|
-
handleHeaderCellSelection(_objectSpread({
|
515
|
-
type: 'row'
|
516
|
-
}, handleHeaderCellProps));
|
517
|
-
}
|
530
|
+
});
|
518
531
|
}
|
519
532
|
}
|
533
|
+
};
|
534
|
+
|
535
|
+
var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref4) {
|
536
|
+
var isKeyboard = _ref4.isKeyboard,
|
537
|
+
_ref4$index = _ref4.index,
|
538
|
+
index = _ref4$index === void 0 ? null : _ref4$index;
|
539
|
+
var handleHeaderCellProps = {
|
540
|
+
activeCellCoordinates: activeCellCoordinates,
|
541
|
+
rows: rows,
|
542
|
+
columns: columns,
|
543
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
544
|
+
setCurrentMatcher: setCurrentMatcher,
|
545
|
+
setSelectionAreas: setSelectionAreas,
|
546
|
+
spreadsheetRef: spreadsheetRef,
|
547
|
+
isKeyboard: isKeyboard,
|
548
|
+
setSelectionAreaData: setSelectionAreaData,
|
549
|
+
index: index
|
550
|
+
}; // Select an entire column
|
551
|
+
|
552
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
553
|
+
handleHeaderCellSelection(_objectSpread({
|
554
|
+
type: 'column'
|
555
|
+
}, handleHeaderCellProps));
|
556
|
+
} // Select an entire row
|
557
|
+
|
558
|
+
|
559
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
560
|
+
handleHeaderCellSelection(_objectSpread({
|
561
|
+
type: 'row'
|
562
|
+
}, handleHeaderCellProps));
|
563
|
+
}
|
520
564
|
}; // Go into edit mode if double click is detected on activeCellRef
|
521
565
|
|
522
566
|
|
@@ -557,44 +601,8 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
557
601
|
}
|
558
602
|
|
559
603
|
return;
|
560
|
-
};
|
561
|
-
// Find point object that matches currentMatcher and remove the second point
|
562
|
-
// because hovering over the active cell while clicking and holding should
|
563
|
-
// remove the previously existing selection area
|
564
|
-
|
565
|
-
|
566
|
-
var handleActiveCellMouseEnterCallback = useCallback(function (areas, clickHold) {
|
567
|
-
var freshMatcherValue = currentMatcherRef.current;
|
568
|
-
|
569
|
-
if (!freshMatcherValue) {
|
570
|
-
return;
|
571
|
-
}
|
572
|
-
|
573
|
-
if (areas && areas.length && clickHold && freshMatcherValue) {
|
574
|
-
setSelectionAreas(function (prev) {
|
575
|
-
var selectionAreaClone = deepCloneObject(prev);
|
576
|
-
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
577
|
-
return item.matcher === freshMatcherValue;
|
578
|
-
});
|
579
|
-
|
580
|
-
if (indexOfItemToUpdate === -1) {
|
581
|
-
return prev;
|
582
|
-
}
|
583
|
-
|
584
|
-
if (_typeof(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
|
585
|
-
selectionAreaClone[indexOfItemToUpdate].point2 = null;
|
586
|
-
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
587
|
-
removeCellSelections({
|
588
|
-
matcher: freshMatcherValue,
|
589
|
-
spreadsheetRef: spreadsheetRef
|
590
|
-
});
|
591
|
-
return selectionAreaClone;
|
592
|
-
}
|
604
|
+
};
|
593
605
|
|
594
|
-
return prev;
|
595
|
-
});
|
596
|
-
}
|
597
|
-
}, [spreadsheetRef, removeCellSelections]);
|
598
606
|
useEffect(function () {
|
599
607
|
if (isEditing) {
|
600
608
|
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
@@ -607,7 +615,7 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
607
615
|
cellEditorRef.current.style.display = 'block';
|
608
616
|
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
609
617
|
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
610
|
-
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
618
|
+
cellEditorRef.current.style.paddingTop = "".concat((parseInt(activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height) - 16) / 2 - 1, "px"); // calculate paddingTop based on cellHeight which could be variable depending on the cellSize prop
|
611
619
|
|
612
620
|
cellEditorRef.current.style.textAlign = (cellProps === null || cellProps === void 0 ? void 0 : (_cellProps$column = cellProps.column) === null || _cellProps$column === void 0 ? void 0 : _cellProps$column.placement) === 'right' ? 'right' : 'left';
|
613
621
|
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
@@ -650,15 +658,17 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
650
658
|
}), /*#__PURE__*/React.createElement(DataSpreadsheetHeader, {
|
651
659
|
ref: spreadsheetRef,
|
652
660
|
activeCellCoordinates: activeCellCoordinates,
|
653
|
-
|
661
|
+
cellSize: cellSize,
|
654
662
|
columns: columns,
|
655
663
|
defaultColumn: defaultColumn,
|
656
664
|
headerGroups: headerGroups,
|
657
665
|
rows: rows,
|
666
|
+
scrollBarSize: scrollBarSize,
|
658
667
|
selectionAreas: selectionAreas,
|
659
668
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
660
669
|
setSelectionAreas: setSelectionAreas,
|
661
|
-
setCurrentMatcher: setCurrentMatcher
|
670
|
+
setCurrentMatcher: setCurrentMatcher,
|
671
|
+
setSelectionAreaData: setSelectionAreaData
|
662
672
|
}), /*#__PURE__*/React.createElement(DataSpreadsheetBody, {
|
663
673
|
activeCellCoordinates: activeCellCoordinates,
|
664
674
|
ref: spreadsheetRef,
|
@@ -673,21 +683,24 @@ export var DataSpreadsheet = /*#__PURE__*/React.forwardRef(function (_ref, ref)
|
|
673
683
|
defaultColumn: defaultColumn,
|
674
684
|
getTableBodyProps: getTableBodyProps,
|
675
685
|
onActiveCellChange: onActiveCellChange,
|
686
|
+
onSelectionAreaChange: onSelectionAreaChange,
|
676
687
|
prepareRow: prepareRow,
|
677
688
|
rows: rows,
|
689
|
+
selectionAreaData: selectionAreaData,
|
690
|
+
setSelectionAreaData: setSelectionAreaData,
|
678
691
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
679
692
|
scrollBarSize: scrollBarSize,
|
680
693
|
totalColumnsWidth: totalColumnsWidth,
|
681
694
|
id: id,
|
682
695
|
columns: columns
|
683
696
|
}), /*#__PURE__*/React.createElement("button", {
|
697
|
+
onClick: handleActiveCellClick,
|
684
698
|
onKeyDown: handleActiveCellKeyDown,
|
685
|
-
onMouseEnter: handleActiveCellMouseEnter,
|
686
699
|
onDoubleClick: handleActiveCellDoubleClick,
|
687
700
|
ref: activeCellRef,
|
688
701
|
className: cx("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
|
689
702
|
type: "button"
|
690
|
-
}), /*#__PURE__*/React.createElement(TextArea, {
|
703
|
+
}, activeCellContent), /*#__PURE__*/React.createElement(TextArea, {
|
691
704
|
value: cellEditorValue,
|
692
705
|
onKeyDown: handleEditSubmit,
|
693
706
|
onChange: function onChange(event) {
|
@@ -746,7 +759,12 @@ DataSpreadsheet.propTypes = {
|
|
746
759
|
/**
|
747
760
|
* The setter fn for the data prop
|
748
761
|
*/
|
749
|
-
onDataUpdate: PropTypes.func
|
762
|
+
onDataUpdate: PropTypes.func,
|
763
|
+
|
764
|
+
/**
|
765
|
+
* The event handler that is called when the selection area values change
|
766
|
+
*/
|
767
|
+
onSelectionAreaChange: PropTypes.func
|
750
768
|
/* TODO: add types and DocGen for all props. */
|
751
769
|
|
752
770
|
};
|
@@ -15,6 +15,7 @@ import cx from 'classnames';
|
|
15
15
|
import { pkg } from '../../settings';
|
16
16
|
import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
|
17
17
|
import uuidv4 from '../../global/js/utils/uuidv4';
|
18
|
+
import { usePreviousValue } from '../../global/js/hooks';
|
18
19
|
import { removeCellSelections } from './utils/removeCellSelections';
|
19
20
|
import { createCellSelectionArea } from './utils/createCellSelectionArea';
|
20
21
|
import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
|
@@ -28,6 +29,8 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
28
29
|
id = _ref.id,
|
29
30
|
prepareRow = _ref.prepareRow,
|
30
31
|
rows = _ref.rows,
|
32
|
+
selectionAreaData = _ref.selectionAreaData,
|
33
|
+
setSelectionAreaData = _ref.setSelectionAreaData,
|
31
34
|
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
32
35
|
selectionAreas = _ref.selectionAreas,
|
33
36
|
setContainerHasFocus = _ref.setContainerHasFocus,
|
@@ -37,24 +40,60 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
37
40
|
clickAndHoldActive = _ref.clickAndHoldActive,
|
38
41
|
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
39
42
|
currentMatcher = _ref.currentMatcher,
|
40
|
-
setCurrentMatcher = _ref.setCurrentMatcher
|
41
|
-
|
43
|
+
setCurrentMatcher = _ref.setCurrentMatcher,
|
44
|
+
onSelectionAreaChange = _ref.onSelectionAreaChange;
|
45
|
+
var previousState = usePreviousValue({
|
46
|
+
selectionAreaData: selectionAreaData,
|
47
|
+
clickAndHoldActive: clickAndHoldActive
|
48
|
+
}); // Call the `onSelectionAreaChange` handler to send selection area data
|
49
|
+
// back to the consumer
|
50
|
+
|
51
|
+
useEffect(function () {
|
52
|
+
if (selectionAreaData.length) {
|
53
|
+
var _previousState$select;
|
54
|
+
|
55
|
+
if (!clickAndHoldActive && previousState !== null && previousState !== void 0 && previousState.clickAndHoldActive || (previousState === null || previousState === void 0 ? void 0 : (_previousState$select = previousState.selectionAreaData) === null || _previousState$select === void 0 ? void 0 : _previousState$select.length) !== (selectionAreaData === null || selectionAreaData === void 0 ? void 0 : selectionAreaData.length)) {
|
56
|
+
onSelectionAreaChange(selectionAreaData);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}, [previousState === null || previousState === void 0 ? void 0 : previousState.selectionAreaData, selectionAreaData, onSelectionAreaChange, clickAndHoldActive, previousState === null || previousState === void 0 ? void 0 : previousState.clickAndHoldActive]); // Create cell selection areas based on selectionAreas array
|
60
|
+
|
42
61
|
useEffect(function () {
|
43
62
|
if (selectionAreas && selectionAreas.length) {
|
44
63
|
selectionAreas.map(function (area) {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
64
|
+
// Setup selection area data that will be sent back to consumer via onSelectionAreaChange prop
|
65
|
+
if (area.areaCreated) {
|
66
|
+
var rowStart = Math.min(area.point1.row, area.point2.row);
|
67
|
+
var rowEnd = Math.max(area.point1.row, area.point2.row);
|
68
|
+
var columnStart = Math.min(area.point1.column, area.point2.column);
|
69
|
+
var columnEnd = Math.max(area.point1.column, area.point2.column);
|
70
|
+
var selectionData = {
|
71
|
+
rows: {
|
72
|
+
start: rowStart,
|
73
|
+
end: rowEnd
|
74
|
+
},
|
75
|
+
columns: {
|
76
|
+
start: columnStart,
|
77
|
+
end: columnEnd
|
78
|
+
},
|
79
|
+
cells: populateSelectionAreaCellData({
|
80
|
+
rowStart: rowStart,
|
81
|
+
rowEnd: rowEnd,
|
82
|
+
columnStart: columnStart,
|
83
|
+
columnEnd: columnEnd
|
84
|
+
}),
|
85
|
+
selectionId: area.matcher
|
86
|
+
};
|
87
|
+
setSelectionAreaData(function (prev) {
|
88
|
+
var prevValues = deepCloneObject(prev);
|
89
|
+
var newAreaData = prevValues.filter(function (item) {
|
90
|
+
return item.selectionId !== area.matcher;
|
52
91
|
});
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
92
|
+
return [].concat(_toConsumableArray(newAreaData), [selectionData]);
|
93
|
+
});
|
94
|
+
}
|
57
95
|
|
96
|
+
if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
|
58
97
|
createCellSelectionArea({
|
59
98
|
area: area,
|
60
99
|
blockClass: blockClass,
|
@@ -67,7 +106,24 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
67
106
|
return;
|
68
107
|
});
|
69
108
|
}
|
70
|
-
}, [selectionAreas, setSelectionAreas, defaultColumn]);
|
109
|
+
}, [selectionAreas, setSelectionAreas, defaultColumn, onSelectionAreaChange, setSelectionAreaData]);
|
110
|
+
|
111
|
+
var populateSelectionAreaCellData = function populateSelectionAreaCellData(_ref2) {
|
112
|
+
var rowStart = _ref2.rowStart,
|
113
|
+
rowEnd = _ref2.rowEnd,
|
114
|
+
columnStart = _ref2.columnStart,
|
115
|
+
columnEnd = _ref2.columnEnd;
|
116
|
+
var cellContainer = [];
|
117
|
+
|
118
|
+
for (var rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
|
119
|
+
for (var columnIndex = columnStart; columnIndex <= columnEnd; columnIndex++) {
|
120
|
+
cellContainer.push([rowIndex, columnIndex]);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
return cellContainer;
|
125
|
+
}; // Mouse up
|
126
|
+
|
71
127
|
|
72
128
|
useEffect(function () {
|
73
129
|
var handleMouseUp = function handleMouseUp(event) {
|
@@ -168,9 +224,10 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
168
224
|
matcher: tempMatcher
|
169
225
|
}]);
|
170
226
|
setCurrentMatcher(tempMatcher);
|
227
|
+
setSelectionAreaData([]);
|
171
228
|
}
|
172
229
|
};
|
173
|
-
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref]);
|
230
|
+
}, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData]);
|
174
231
|
var handleBodyCellHover = useCallback(function (cell, columnIndex) {
|
175
232
|
return function () {
|
176
233
|
if (clickAndHoldActive) {
|
@@ -213,14 +270,15 @@ export var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
213
270
|
setCurrentMatcher: setCurrentMatcher,
|
214
271
|
setSelectionAreas: setSelectionAreas,
|
215
272
|
spreadsheetRef: ref,
|
216
|
-
index: index
|
273
|
+
index: index,
|
274
|
+
setSelectionAreaData: setSelectionAreaData
|
217
275
|
});
|
218
276
|
};
|
219
|
-
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows]); // Renders each row/cell in the spreadsheet body
|
277
|
+
}, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]); // Renders each row/cell in the spreadsheet body
|
220
278
|
|
221
|
-
var RenderRow = useCallback(function (
|
222
|
-
var index =
|
223
|
-
style =
|
279
|
+
var RenderRow = useCallback(function (_ref3) {
|
280
|
+
var index = _ref3.index,
|
281
|
+
style = _ref3.style;
|
224
282
|
var row = rows[index];
|
225
283
|
prepareRow(row);
|
226
284
|
return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
|
@@ -313,6 +371,11 @@ DataSpreadsheetBody.propTypes = {
|
|
313
371
|
*/
|
314
372
|
onActiveCellChange: PropTypes.func,
|
315
373
|
|
374
|
+
/**
|
375
|
+
* The event handler that is called when the selection areas change
|
376
|
+
*/
|
377
|
+
onSelectionAreaChange: PropTypes.func,
|
378
|
+
|
316
379
|
/**
|
317
380
|
* Prepare row function from react-table
|
318
381
|
*/
|
@@ -328,6 +391,11 @@ DataSpreadsheetBody.propTypes = {
|
|
328
391
|
*/
|
329
392
|
scrollBarSize: PropTypes.number,
|
330
393
|
|
394
|
+
/**
|
395
|
+
* Array of selection area data
|
396
|
+
*/
|
397
|
+
selectionAreaData: PropTypes.array,
|
398
|
+
|
331
399
|
/**
|
332
400
|
* Array of selection areas
|
333
401
|
*/
|
@@ -353,6 +421,11 @@ DataSpreadsheetBody.propTypes = {
|
|
353
421
|
*/
|
354
422
|
setCurrentMatcher: PropTypes.func,
|
355
423
|
|
424
|
+
/**
|
425
|
+
* Setter fn for selectionAreaData state value
|
426
|
+
*/
|
427
|
+
setSelectionAreaData: PropTypes.func,
|
428
|
+
|
356
429
|
/**
|
357
430
|
* Setter fn for selectionAreas state value
|
358
431
|
*/
|