@carbon/ibm-products 1.11.1 → 1.13.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 +1445 -369
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +6 -6
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +15 -6
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +2 -2
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +109 -16
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +5 -5
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +109 -16
- package/css/index.css.map +1 -1
- package/css/index.min.css +6 -6
- package/css/index.min.css.map +1 -1
- package/es/components/ActionBar/ActionBar.js +3 -1
- package/es/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/es/components/AddSelect/AddSelect.js +63 -12
- package/es/components/AddSelect/AddSelectColumn.js +0 -1
- package/es/components/AddSelect/AddSelectList.js +59 -13
- package/es/components/AddSelect/AddSelectSidebar.js +15 -5
- package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
- package/es/components/CreateFullPage/CreateFullPageStep.js +4 -4
- package/es/components/CreateTearsheet/CreateTearsheetStep.js +4 -4
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +193 -119
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +178 -51
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +50 -2
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -4
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/es/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
- package/es/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
- package/es/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
- package/es/components/ImportModal/ImportModal.js +2 -2
- package/es/components/TagSet/TagSet.js +12 -3
- package/es/components/UserProfileImage/UserProfileImage.js +38 -10
- package/lib/components/ActionBar/ActionBar.js +3 -1
- package/lib/components/ActionBar/ActionBarOverflowItems.js +5 -3
- package/lib/components/AddSelect/AddSelect.js +63 -12
- package/lib/components/AddSelect/AddSelectColumn.js +0 -1
- package/lib/components/AddSelect/AddSelectList.js +61 -12
- package/lib/components/AddSelect/AddSelectSidebar.js +15 -11
- package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +2 -0
- package/lib/components/CreateFullPage/CreateFullPageStep.js +4 -4
- package/lib/components/CreateTearsheet/CreateTearsheetStep.js +4 -4
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +196 -120
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +178 -51
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +52 -7
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetOutsideClick.js +6 -3
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
- package/lib/components/HTTPErrors/assets/HTTPErrorSvg403.js +2 -3
- package/lib/components/HTTPErrors/assets/HTTPErrorSvg404.js +2 -3
- package/lib/components/HTTPErrors/assets/HTTPErrorSvgOther.js +2 -3
- package/lib/components/ImportModal/ImportModal.js +1 -1
- package/lib/components/TagSet/TagSet.js +12 -3
- package/lib/components/UserProfileImage/UserProfileImage.js +38 -10
- package/package.json +15 -15
- 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 +50 -3
- 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 +57 -7
- package/scss/components/ExportModal/_export-modal.scss +3 -3
- package/scss/components/HTTPErrors/_http-errors.scss +16 -16
- 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/PageHeader/_page-header.scss +4 -0
- 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
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
4
|
|
5
|
-
var
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
6
6
|
|
7
7
|
Object.defineProperty(exports, "__esModule", {
|
8
8
|
value: true
|
@@ -11,8 +11,6 @@ exports.DataSpreadsheet = void 0;
|
|
11
11
|
|
12
12
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
13
13
|
|
14
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
15
|
-
|
16
14
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
17
15
|
|
18
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
@@ -25,6 +23,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
25
23
|
|
26
24
|
var _reactTable = require("react-table");
|
27
25
|
|
26
|
+
var _layout = require("@carbon/layout");
|
27
|
+
|
28
28
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
29
29
|
|
30
30
|
var _classnames = _interopRequireDefault(require("classnames"));
|
@@ -43,8 +43,6 @@ var _getScrollbarWidth = require("../../global/js/utils/getScrollbarWidth");
|
|
43
43
|
|
44
44
|
var _hooks = require("../../global/js/hooks");
|
45
45
|
|
46
|
-
var _deepCloneObject = require("../../global/js/utils/deepCloneObject");
|
47
|
-
|
48
46
|
var _uuidv = _interopRequireDefault(require("../../global/js/utils/uuidv4"));
|
49
47
|
|
50
48
|
var _useResetSpreadsheetFocus = require("./hooks/useResetSpreadsheetFocus");
|
@@ -61,11 +59,13 @@ var _handleMultipleKeys = require("./utils/handleMultipleKeys");
|
|
61
59
|
|
62
60
|
var _handleHeaderCellSelection = require("./utils/handleHeaderCellSelection");
|
63
61
|
|
64
|
-
var
|
62
|
+
var _removeCellSelections = require("./utils/removeCellSelections");
|
63
|
+
|
64
|
+
var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange"];
|
65
65
|
|
66
66
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
67
67
|
|
68
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
68
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
69
69
|
|
70
70
|
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; }
|
71
71
|
|
@@ -80,7 +80,10 @@ var defaults = {
|
|
80
80
|
cellSize: 'standard',
|
81
81
|
columns: Object.freeze([]),
|
82
82
|
data: Object.freeze([]),
|
83
|
-
|
83
|
+
defaultEmptyRowCount: 16,
|
84
|
+
onDataUpdate: Object.freeze(function () {}),
|
85
|
+
onActiveCellChange: Object.freeze(function () {}),
|
86
|
+
onSelectionAreaChange: Object.freeze(function () {})
|
84
87
|
};
|
85
88
|
/**
|
86
89
|
* DataSpreadsheet: used to organize and display large amounts of structured data, separated by columns and rows in a grid-like format.
|
@@ -94,10 +97,15 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
94
97
|
columns = _ref$columns === void 0 ? defaults.columns : _ref$columns,
|
95
98
|
_ref$data = _ref.data,
|
96
99
|
data = _ref$data === void 0 ? defaults.data : _ref$data,
|
100
|
+
_ref$defaultEmptyRowC = _ref.defaultEmptyRowCount,
|
101
|
+
defaultEmptyRowCount = _ref$defaultEmptyRowC === void 0 ? defaults.defaultEmptyRowCount : _ref$defaultEmptyRowC,
|
97
102
|
_ref$onDataUpdate = _ref.onDataUpdate,
|
98
103
|
onDataUpdate = _ref$onDataUpdate === void 0 ? defaults.onDataUpdate : _ref$onDataUpdate,
|
99
104
|
id = _ref.id,
|
100
|
-
|
105
|
+
_ref$onActiveCellChan = _ref.onActiveCellChange,
|
106
|
+
onActiveCellChange = _ref$onActiveCellChan === void 0 ? defaults.onActiveCellChange : _ref$onActiveCellChan,
|
107
|
+
_ref$onSelectionAreaC = _ref.onSelectionAreaChange,
|
108
|
+
onSelectionAreaChange = _ref$onSelectionAreaC === void 0 ? defaults.onSelectionAreaChange : _ref$onSelectionAreaC,
|
101
109
|
rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
102
110
|
var localRef = (0, _react.useRef)();
|
103
111
|
var spreadsheetRef = ref || localRef;
|
@@ -118,34 +126,45 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
118
126
|
selectionAreas = _useState6[0],
|
119
127
|
setSelectionAreas = _useState6[1];
|
120
128
|
|
121
|
-
var _useState7 = (0, _react.useState)(
|
129
|
+
var _useState7 = (0, _react.useState)([]),
|
122
130
|
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
123
|
-
|
124
|
-
|
131
|
+
selectionAreaData = _useState8[0],
|
132
|
+
setSelectionAreaData = _useState8[1];
|
125
133
|
|
126
|
-
var _useState9 = (0, _react.useState)(
|
134
|
+
var _useState9 = (0, _react.useState)(false),
|
127
135
|
_useState10 = (0, _slicedToArray2.default)(_useState9, 2),
|
128
|
-
|
129
|
-
|
136
|
+
clickAndHoldActive = _useState10[0],
|
137
|
+
setClickAndHoldActive = _useState10[1];
|
130
138
|
|
131
|
-
var _useState11 = (0, _react.useState)(
|
139
|
+
var _useState11 = (0, _react.useState)(''),
|
132
140
|
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
133
|
-
|
134
|
-
|
141
|
+
currentMatcher = _useState12[0],
|
142
|
+
setCurrentMatcher = _useState12[1];
|
135
143
|
|
136
|
-
var _useState13 = (0, _react.useState)(
|
144
|
+
var _useState13 = (0, _react.useState)(false),
|
137
145
|
_useState14 = (0, _slicedToArray2.default)(_useState13, 2),
|
138
|
-
|
139
|
-
|
146
|
+
isEditing = _useState14[0],
|
147
|
+
setIsEditing = _useState14[1];
|
148
|
+
|
149
|
+
var _useState15 = (0, _react.useState)(''),
|
150
|
+
_useState16 = (0, _slicedToArray2.default)(_useState15, 2),
|
151
|
+
cellEditorValue = _useState16[0],
|
152
|
+
setCellEditorValue = _useState16[1];
|
140
153
|
|
141
154
|
var previousState = (0, _hooks.usePreviousValue)({
|
142
155
|
activeCellCoordinates: activeCellCoordinates
|
143
156
|
});
|
144
157
|
var cellSizeValue = (0, _getCellSize.getCellSize)(cellSize);
|
145
158
|
var cellEditorRef = (0, _react.useRef)();
|
146
|
-
|
159
|
+
|
160
|
+
var _useState17 = (0, _react.useState)(),
|
161
|
+
_useState18 = (0, _slicedToArray2.default)(_useState17, 2),
|
162
|
+
activeCellContent = _useState18[0],
|
163
|
+
setActiveCellContent = _useState18[1];
|
164
|
+
|
147
165
|
var activeKeys = (0, _react.useRef)([]);
|
148
166
|
var activeCellRef = (0, _react.useRef)();
|
167
|
+
var cellEditorRulerRef = (0, _react.useRef)();
|
149
168
|
var defaultColumn = (0, _react.useMemo)(function () {
|
150
169
|
return {
|
151
170
|
width: 150,
|
@@ -193,22 +212,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
193
212
|
setCellEditorValue('');
|
194
213
|
setIsEditing(false);
|
195
214
|
cellEditorRef.current.style.display = 'none';
|
196
|
-
}, []); //
|
197
|
-
|
198
|
-
var removeCellSelections = (0, _react.useCallback)(function (matcher) {
|
199
|
-
if (matcher && typeof matcher === 'string') {
|
200
|
-
var selectionToRemove = spreadsheetRef.current.querySelector("[data-matcher-id=\"".concat(matcher, "\"]"));
|
201
|
-
|
202
|
-
if (selectionToRemove) {
|
203
|
-
selectionToRemove.remove();
|
204
|
-
}
|
205
|
-
} else {
|
206
|
-
var cellSelections = spreadsheetRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
|
207
|
-
(0, _toConsumableArray2.default)(cellSelections).forEach(function (element) {
|
208
|
-
return element.remove();
|
209
|
-
});
|
210
|
-
}
|
211
|
-
}, [spreadsheetRef]); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
|
215
|
+
}, []); // Remove cell editor if the active cell coordinates change and save with new cell data, this will
|
212
216
|
// happen if you click on another cell while isEditing is true
|
213
217
|
|
214
218
|
(0, _react.useEffect)(function () {
|
@@ -218,11 +222,20 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
218
222
|
var cellProps = rows[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row].cells[prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.column];
|
219
223
|
removeCellEditor();
|
220
224
|
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
225
|
+
cellEditorRulerRef.current.textContent = '';
|
221
226
|
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
227
|
+
|
228
|
+
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)) {
|
229
|
+
if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) !== 'header' && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) !== 'header') {
|
230
|
+
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;
|
231
|
+
setActiveCellContent(activeCellFullData.render('Cell'));
|
232
|
+
}
|
233
|
+
|
234
|
+
if (activeCellCoordinates && (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
235
|
+
setActiveCellContent(null);
|
236
|
+
}
|
237
|
+
}
|
238
|
+
}, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor, activeCellContent]);
|
226
239
|
var createActiveCell = (0, _react.useCallback)(function (_ref2) {
|
227
240
|
var placementElement = _ref2.placementElement,
|
228
241
|
coords = _ref2.coords,
|
@@ -258,7 +271,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
258
271
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
259
272
|
setSelectionAreas: setSelectionAreas,
|
260
273
|
removeActiveCell: removeActiveCell,
|
261
|
-
removeCellSelections: removeCellSelections,
|
274
|
+
removeCellSelections: _removeCellSelections.removeCellSelections,
|
262
275
|
setContainerHasFocus: setContainerHasFocus,
|
263
276
|
activeKeys: activeKeys,
|
264
277
|
removeCellEditor: removeCellEditor
|
@@ -326,7 +339,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
326
339
|
|
327
340
|
if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && key !== 'Shift' && !activeKeys.current.includes('Shift')) {
|
328
341
|
setSelectionAreas([]);
|
329
|
-
|
342
|
+
setSelectionAreaData([]);
|
343
|
+
(0, _removeCellSelections.removeCellSelections)({
|
330
344
|
spreadsheetRef: spreadsheetRef
|
331
345
|
});
|
332
346
|
}
|
@@ -502,13 +516,26 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
502
516
|
}
|
503
517
|
}
|
504
518
|
}
|
505
|
-
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor,
|
519
|
+
}, [updateActiveCellCoordinates, handleInitialArrowPress, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, isEditing, removeCellEditor, selectionAreas]);
|
506
520
|
|
507
521
|
var startEditMode = function startEditMode() {
|
508
522
|
setIsEditing(true);
|
509
523
|
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;
|
510
524
|
var activeCellValue = activeCellFullData ? Object.values(activeCellFullData.row.values)[activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column] : null;
|
511
525
|
setCellEditorValue(activeCellValue);
|
526
|
+
cellEditorRulerRef.current.textContent = activeCellValue;
|
527
|
+
};
|
528
|
+
|
529
|
+
var handleActiveCellClick = function handleActiveCellClick() {
|
530
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
531
|
+
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;
|
532
|
+
handleRowColumnHeaderClick({
|
533
|
+
isKeyboard: false,
|
534
|
+
index: indexValue
|
535
|
+
});
|
536
|
+
}
|
537
|
+
|
538
|
+
return;
|
512
539
|
}; // Go into edit mode if 'Enter' key is pressed on activeCellRef
|
513
540
|
|
514
541
|
|
@@ -521,41 +548,51 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
521
548
|
}
|
522
549
|
|
523
550
|
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header' || (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
524
|
-
|
525
|
-
activeCellCoordinates: activeCellCoordinates,
|
526
|
-
rows: rows,
|
527
|
-
columns: columns,
|
528
|
-
setActiveCellCoordinates: setActiveCellCoordinates,
|
529
|
-
setCurrentMatcher: setCurrentMatcher,
|
530
|
-
setSelectionAreas: setSelectionAreas,
|
531
|
-
spreadsheetRef: spreadsheetRef,
|
551
|
+
handleRowColumnHeaderClick({
|
532
552
|
isKeyboard: true
|
533
|
-
};
|
534
|
-
|
535
|
-
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
536
|
-
(0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
|
537
|
-
type: 'column'
|
538
|
-
}, handleHeaderCellProps));
|
539
|
-
} // Select an entire row
|
540
|
-
|
541
|
-
|
542
|
-
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
543
|
-
(0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
|
544
|
-
type: 'row'
|
545
|
-
}, handleHeaderCellProps));
|
546
|
-
}
|
553
|
+
});
|
547
554
|
}
|
548
555
|
}
|
556
|
+
};
|
557
|
+
|
558
|
+
var handleRowColumnHeaderClick = function handleRowColumnHeaderClick(_ref4) {
|
559
|
+
var isKeyboard = _ref4.isKeyboard,
|
560
|
+
_ref4$index = _ref4.index,
|
561
|
+
index = _ref4$index === void 0 ? null : _ref4$index;
|
562
|
+
var handleHeaderCellProps = {
|
563
|
+
activeCellCoordinates: activeCellCoordinates,
|
564
|
+
rows: rows,
|
565
|
+
columns: columns,
|
566
|
+
setActiveCellCoordinates: setActiveCellCoordinates,
|
567
|
+
setCurrentMatcher: setCurrentMatcher,
|
568
|
+
setSelectionAreas: setSelectionAreas,
|
569
|
+
spreadsheetRef: spreadsheetRef,
|
570
|
+
isKeyboard: isKeyboard,
|
571
|
+
setSelectionAreaData: setSelectionAreaData,
|
572
|
+
index: index
|
573
|
+
}; // Select an entire column
|
574
|
+
|
575
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === 'header') {
|
576
|
+
(0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
|
577
|
+
type: 'column'
|
578
|
+
}, handleHeaderCellProps));
|
579
|
+
} // Select an entire row
|
580
|
+
|
581
|
+
|
582
|
+
if ((activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column) === 'header') {
|
583
|
+
(0, _handleHeaderCellSelection.handleHeaderCellSelection)(_objectSpread({
|
584
|
+
type: 'row'
|
585
|
+
}, handleHeaderCellProps));
|
586
|
+
}
|
549
587
|
}; // Go into edit mode if double click is detected on activeCellRef
|
550
588
|
|
551
589
|
|
552
590
|
var handleActiveCellDoubleClick = function handleActiveCellDoubleClick() {
|
553
591
|
startEditMode();
|
554
|
-
};
|
555
|
-
|
592
|
+
};
|
556
593
|
|
557
|
-
var
|
558
|
-
var
|
594
|
+
var updateSelectionAreaOnCellEditSubmit = function updateSelectionAreaOnCellEditSubmit(_ref5) {
|
595
|
+
var type = _ref5.type;
|
559
596
|
|
560
597
|
var submitEditChanges = function submitEditChanges() {
|
561
598
|
var prevCoords = previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates;
|
@@ -564,8 +601,33 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
564
601
|
updateData(prevCoords === null || prevCoords === void 0 ? void 0 : prevCoords.row, cellProps.column.id);
|
565
602
|
};
|
566
603
|
|
604
|
+
(0, _removeCellSelections.removeCellSelections)({
|
605
|
+
spreadsheetRef: spreadsheetRef
|
606
|
+
});
|
607
|
+
submitEditChanges();
|
608
|
+
var tempMatcher = (0, _uuidv.default)();
|
609
|
+
var newSelectionArea = {
|
610
|
+
row: type === 'Enter' ? activeCellCoordinates.row === rows.length - 1 ? activeCellCoordinates.row : activeCellCoordinates.row + 1 : activeCellCoordinates.row,
|
611
|
+
column: type === 'Tab' ? activeCellCoordinates.column === columns.length - 1 ? activeCellCoordinates.column : activeCellCoordinates.column + 1 : activeCellCoordinates.column
|
612
|
+
};
|
613
|
+
setSelectionAreas([{
|
614
|
+
point1: newSelectionArea,
|
615
|
+
point2: newSelectionArea,
|
616
|
+
matcher: tempMatcher,
|
617
|
+
areaCreated: false
|
618
|
+
}]);
|
619
|
+
setCurrentMatcher(tempMatcher);
|
620
|
+
cellEditorRulerRef.current.textContent = '';
|
621
|
+
}; // Update the data
|
622
|
+
|
623
|
+
|
624
|
+
var handleEditSubmit = function handleEditSubmit(event) {
|
625
|
+
var key = event.key;
|
626
|
+
|
567
627
|
if (key === 'Enter') {
|
568
|
-
|
628
|
+
updateSelectionAreaOnCellEditSubmit({
|
629
|
+
type: 'Enter'
|
630
|
+
});
|
569
631
|
setActiveCellCoordinates(function (prev) {
|
570
632
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
571
633
|
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
|
@@ -576,7 +638,9 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
576
638
|
|
577
639
|
if (key === 'Tab') {
|
578
640
|
event.preventDefault();
|
579
|
-
|
641
|
+
updateSelectionAreaOnCellEditSubmit({
|
642
|
+
type: 'Tab'
|
643
|
+
});
|
580
644
|
setActiveCellCoordinates(function (prev) {
|
581
645
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
582
646
|
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
|
@@ -586,44 +650,8 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
586
650
|
}
|
587
651
|
|
588
652
|
return;
|
589
|
-
};
|
590
|
-
// Find point object that matches currentMatcher and remove the second point
|
591
|
-
// because hovering over the active cell while clicking and holding should
|
592
|
-
// remove the previously existing selection area
|
593
|
-
|
594
|
-
|
595
|
-
var handleActiveCellMouseEnterCallback = (0, _react.useCallback)(function (areas, clickHold) {
|
596
|
-
var freshMatcherValue = currentMatcherRef.current;
|
597
|
-
|
598
|
-
if (!freshMatcherValue) {
|
599
|
-
return;
|
600
|
-
}
|
601
|
-
|
602
|
-
if (areas && areas.length && clickHold && freshMatcherValue) {
|
603
|
-
setSelectionAreas(function (prev) {
|
604
|
-
var selectionAreaClone = (0, _deepCloneObject.deepCloneObject)(prev);
|
605
|
-
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
606
|
-
return item.matcher === freshMatcherValue;
|
607
|
-
});
|
608
|
-
|
609
|
-
if (indexOfItemToUpdate === -1) {
|
610
|
-
return prev;
|
611
|
-
}
|
612
|
-
|
613
|
-
if ((0, _typeof2.default)(selectionAreaClone[indexOfItemToUpdate].point2) === 'object' && selectionAreaClone[indexOfItemToUpdate].areaCreated) {
|
614
|
-
selectionAreaClone[indexOfItemToUpdate].point2 = null;
|
615
|
-
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
616
|
-
removeCellSelections({
|
617
|
-
matcher: freshMatcherValue,
|
618
|
-
spreadsheetRef: spreadsheetRef
|
619
|
-
});
|
620
|
-
return selectionAreaClone;
|
621
|
-
}
|
653
|
+
};
|
622
654
|
|
623
|
-
return prev;
|
624
|
-
});
|
625
|
-
}
|
626
|
-
}, [spreadsheetRef, removeCellSelections]);
|
627
655
|
(0, _react.useEffect)(function () {
|
628
656
|
if (isEditing) {
|
629
657
|
var _rows$activeCellCoord, _cellProps$column, _cellEditorRef$curren;
|
@@ -636,18 +664,43 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
636
664
|
cellEditorRef.current.style.display = 'block';
|
637
665
|
cellEditorRef.current.style.width = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.width;
|
638
666
|
cellEditorRef.current.style.height = activeCellRef === null || activeCellRef === void 0 ? void 0 : activeCellRef.current.style.height;
|
639
|
-
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
|
667
|
+
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
|
640
668
|
|
641
669
|
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';
|
642
670
|
(_cellEditorRef$curren = cellEditorRef.current) === null || _cellEditorRef$curren === void 0 ? void 0 : _cellEditorRef$curren.focus();
|
671
|
+
var rulerWidth = cellEditorRulerRef.current.offsetWidth;
|
672
|
+
var cellWidth = activeCellRef.current.offsetWidth;
|
673
|
+
|
674
|
+
if (rulerWidth >= cellWidth) {
|
675
|
+
var widthMultiplier = Math.floor(rulerWidth / cellWidth) + 1;
|
676
|
+
var startingColumnPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column;
|
677
|
+
var startingRowPosition = activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row;
|
678
|
+
var totalColumns = columns.length;
|
679
|
+
var totalRows = rows.length;
|
680
|
+
var totalMultiplierPossible = totalColumns - startingColumnPosition;
|
681
|
+
var totalCellEditorMaxHeight = (totalRows - startingRowPosition) * defaultColumn.rowHeight;
|
682
|
+
cellEditorRef.current.style.maxHeight = (0, _layout.px)(totalCellEditorMaxHeight);
|
683
|
+
cellEditorRef.current.style.width = (0, _layout.px)(cellWidth * (widthMultiplier <= totalMultiplierPossible ? widthMultiplier : totalMultiplierPossible));
|
684
|
+
cellEditorRef.current.style.height = (0, _layout.px)(cellEditorRef.current.scrollHeight); // adds dynamic height to cell editor
|
685
|
+
// Cell editor has reached max height, we need to add the scrolling back.
|
686
|
+
// We also need to subtract 1 to account for the fact that the cell editor
|
687
|
+
// is placed one pixel below the cell being edited to account for the border
|
688
|
+
|
689
|
+
if (cellEditorRef.current.clientHeight === totalCellEditorMaxHeight - 1) {
|
690
|
+
cellEditorRef.current.style.overflow = 'auto';
|
691
|
+
} else {
|
692
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
693
|
+
}
|
694
|
+
}
|
643
695
|
}
|
644
696
|
|
645
697
|
if (!isEditing) {
|
698
|
+
cellEditorRef.current.style.overflow = 'hidden';
|
646
699
|
cellEditorRef.current.style.display = 'none';
|
647
700
|
cellEditorRef.current.blur();
|
648
701
|
activeCellRef.current.focus();
|
649
702
|
}
|
650
|
-
}, [isEditing, activeCellCoordinates, rows]);
|
703
|
+
}, [isEditing, activeCellCoordinates, rows, cellEditorValue, columns.length, defaultColumn]);
|
651
704
|
|
652
705
|
var handleKeyUp = function handleKeyUp(event) {
|
653
706
|
var _activeKeys$current3;
|
@@ -664,7 +717,7 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
664
717
|
};
|
665
718
|
|
666
719
|
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, getTableProps(), (0, _devtools.getDevtoolsProps)(componentName), {
|
667
|
-
className: (0, _classnames.default)(blockClass, className, (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
|
720
|
+
className: (0, _classnames.default)(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), (0, _defineProperty2.default)({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus)),
|
668
721
|
ref: spreadsheetRef,
|
669
722
|
role: "grid",
|
670
723
|
tabIndex: 0,
|
@@ -678,15 +731,17 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
678
731
|
}), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetHeader.DataSpreadsheetHeader, {
|
679
732
|
ref: spreadsheetRef,
|
680
733
|
activeCellCoordinates: activeCellCoordinates,
|
681
|
-
|
734
|
+
cellSize: cellSize,
|
682
735
|
columns: columns,
|
683
736
|
defaultColumn: defaultColumn,
|
684
737
|
headerGroups: headerGroups,
|
685
738
|
rows: rows,
|
739
|
+
scrollBarSize: scrollBarSize,
|
686
740
|
selectionAreas: selectionAreas,
|
687
741
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
688
742
|
setSelectionAreas: setSelectionAreas,
|
689
|
-
setCurrentMatcher: setCurrentMatcher
|
743
|
+
setCurrentMatcher: setCurrentMatcher,
|
744
|
+
setSelectionAreaData: setSelectionAreaData
|
690
745
|
}), /*#__PURE__*/_react.default.createElement(_DataSpreadsheetBody.DataSpreadsheetBody, {
|
691
746
|
activeCellCoordinates: activeCellCoordinates,
|
692
747
|
ref: spreadsheetRef,
|
@@ -698,33 +753,44 @@ var DataSpreadsheet = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref
|
|
698
753
|
selectionAreas: selectionAreas,
|
699
754
|
setSelectionAreas: setSelectionAreas,
|
700
755
|
cellSize: cellSize,
|
756
|
+
headerGroups: headerGroups,
|
701
757
|
defaultColumn: defaultColumn,
|
702
758
|
getTableBodyProps: getTableBodyProps,
|
759
|
+
onDataUpdate: onDataUpdate,
|
703
760
|
onActiveCellChange: onActiveCellChange,
|
761
|
+
onSelectionAreaChange: onSelectionAreaChange,
|
704
762
|
prepareRow: prepareRow,
|
705
763
|
rows: rows,
|
764
|
+
selectionAreaData: selectionAreaData,
|
765
|
+
setSelectionAreaData: setSelectionAreaData,
|
706
766
|
setActiveCellCoordinates: setActiveCellCoordinates,
|
707
767
|
scrollBarSize: scrollBarSize,
|
708
768
|
totalColumnsWidth: totalColumnsWidth,
|
709
769
|
id: id,
|
710
|
-
columns: columns
|
770
|
+
columns: columns,
|
771
|
+
defaultEmptyRowCount: defaultEmptyRowCount
|
711
772
|
}), /*#__PURE__*/_react.default.createElement("button", {
|
773
|
+
onClick: handleActiveCellClick,
|
712
774
|
onKeyDown: handleActiveCellKeyDown,
|
713
|
-
onMouseEnter: handleActiveCellMouseEnter,
|
714
775
|
onDoubleClick: handleActiveCellDoubleClick,
|
715
776
|
ref: activeCellRef,
|
716
777
|
className: (0, _classnames.default)("".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__active-cell--highlight")),
|
717
778
|
type: "button"
|
718
|
-
}), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TextArea, {
|
779
|
+
}, activeCellContent), /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.TextArea, {
|
719
780
|
value: cellEditorValue,
|
720
781
|
onKeyDown: handleEditSubmit,
|
721
782
|
onChange: function onChange(event) {
|
722
|
-
|
783
|
+
setCellEditorValue(event.target.value);
|
784
|
+
cellEditorRulerRef.current.textContent = event.target.value;
|
723
785
|
},
|
724
786
|
ref: cellEditorRef,
|
725
787
|
labelText: "",
|
726
788
|
"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,
|
727
789
|
className: (0, _classnames.default)("".concat(blockClass, "__cell-editor"), "".concat(blockClass, "--interactive-cell-element"), "".concat(blockClass, "__cell-editor--").concat(cellSize), (0, _defineProperty2.default)({}, "".concat(blockClass, "__cell-editor--active"), isEditing))
|
790
|
+
}), /*#__PURE__*/_react.default.createElement("pre", {
|
791
|
+
"aria-hidden": true,
|
792
|
+
ref: cellEditorRulerRef,
|
793
|
+
className: "".concat(blockClass, "__cell-editor-ruler")
|
728
794
|
}));
|
729
795
|
}); // Return a placeholder if not released and not enabled by feature flag
|
730
796
|
|
@@ -763,6 +829,11 @@ DataSpreadsheet.propTypes = {
|
|
763
829
|
*/
|
764
830
|
data: _propTypes.default.arrayOf(_propTypes.default.shape),
|
765
831
|
|
832
|
+
/**
|
833
|
+
* Sets the number of empty rows to be created when there is no data provided
|
834
|
+
*/
|
835
|
+
defaultEmptyRowCount: _propTypes.default.number,
|
836
|
+
|
766
837
|
/**
|
767
838
|
* The spreadsheet id
|
768
839
|
*/
|
@@ -776,7 +847,12 @@ DataSpreadsheet.propTypes = {
|
|
776
847
|
/**
|
777
848
|
* The setter fn for the data prop
|
778
849
|
*/
|
779
|
-
onDataUpdate: _propTypes.default.func
|
850
|
+
onDataUpdate: _propTypes.default.func,
|
851
|
+
|
852
|
+
/**
|
853
|
+
* The event handler that is called when the selection area values change
|
854
|
+
*/
|
855
|
+
onSelectionAreaChange: _propTypes.default.func
|
780
856
|
/* TODO: add types and DocGen for all props. */
|
781
857
|
|
782
858
|
};
|