@carbon/ibm-products 1.15.0 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +30 -27
- package/css/components/Datagrid/styles/datagrid.css +4 -0
- package/css/components/Datagrid/styles/datagrid.css.map +1 -1
- package/css/components/Datagrid/styles/index.css +5 -1
- package/css/components/Datagrid/styles/index.css.map +1 -1
- package/css/components/Datagrid/styles/useNestedRows.css +1 -1
- package/css/index-full-carbon.css +195 -88
- package/css/index-full-carbon.css.map +1 -1
- package/css/index-full-carbon.min.css +7 -4
- package/css/index-full-carbon.min.css.map +1 -1
- package/css/index-without-carbon-released-only.css +9 -3
- package/css/index-without-carbon-released-only.css.map +1 -1
- package/css/index-without-carbon-released-only.min.css +4 -1
- package/css/index-without-carbon-released-only.min.css.map +1 -1
- package/css/index-without-carbon.css +78 -22
- package/css/index-without-carbon.css.map +1 -1
- package/css/index-without-carbon.min.css +6 -3
- package/css/index-without-carbon.min.css.map +1 -1
- package/css/index.css +104 -53
- package/css/index.css.map +1 -1
- package/css/index.min.css +7 -4
- package/css/index.min.css.map +1 -1
- package/es/components/AddSelect/AddSelect.js +39 -10
- package/es/components/AddSelect/AddSelectColumn.js +31 -73
- package/es/components/AddSelect/AddSelectFilter.js +48 -5
- package/es/components/AddSelect/AddSelectSort.js +61 -0
- package/es/components/AddSelect/add-select-utils.js +21 -0
- package/es/components/AddSelect/hooks/useItemSort.js +20 -0
- package/es/components/DataSpreadsheet/DataSpreadsheet.js +38 -15
- package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +93 -46
- package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +82 -6
- package/es/components/DataSpreadsheet/hooks/index.js +3 -1
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +65 -19
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetMouseMove.js +60 -0
- package/es/components/DataSpreadsheet/hooks/useSpreadsheetMouseUp.js +153 -0
- package/es/components/DataSpreadsheet/utils/checkSelectedHeaderCell.js +16 -0
- package/es/components/DataSpreadsheet/utils/createCellSelectionArea.js +11 -6
- package/es/components/DataSpreadsheet/utils/generateData.js +17 -9
- package/es/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +30 -0
- package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +6 -2
- package/es/components/DataSpreadsheet/utils/moveColumnIndicatorLine.js +34 -0
- package/es/components/Datagrid/Datagrid/Datagrid.js +24 -12
- package/es/components/Datagrid/Datagrid/DatagridHead.js +8 -16
- package/es/components/Datagrid/Datagrid/DatagridHeaderRow.js +10 -10
- package/es/components/Datagrid/Datagrid/DatagridRow.js +12 -2
- package/es/components/Datagrid/Datagrid/index.js +6 -7
- package/es/components/Datagrid/index.js +1 -1
- package/es/components/Datagrid/useNestedRows.js +3 -3
- package/es/components/Datagrid/useRowExpander.js +1 -1
- package/es/components/ExportModal/ExportModal.js +10 -5
- package/es/components/SidePanel/SidePanel.js +5 -1
- package/es/components/WebTerminal/WebTerminal.js +36 -11
- package/es/components/WebTerminal/WebTerminalContentWrapper.js +49 -0
- package/es/components/WebTerminal/index.js +2 -1
- package/es/components/index.js +1 -1
- package/es/global/js/package-settings.js +1 -0
- package/lib/components/AddSelect/AddSelect.js +40 -10
- package/lib/components/AddSelect/AddSelectColumn.js +32 -71
- package/lib/components/AddSelect/AddSelectFilter.js +47 -4
- package/lib/components/AddSelect/AddSelectSort.js +79 -0
- package/lib/components/AddSelect/add-select-utils.js +29 -2
- package/lib/components/AddSelect/hooks/useItemSort.js +33 -0
- package/lib/components/DataSpreadsheet/DataSpreadsheet.js +37 -14
- package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +96 -45
- package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +85 -6
- package/lib/components/DataSpreadsheet/hooks/index.js +17 -1
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetEdit.js +68 -18
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetMouseMove.js +74 -0
- package/lib/components/DataSpreadsheet/hooks/useSpreadsheetMouseUp.js +161 -0
- package/lib/components/DataSpreadsheet/utils/checkSelectedHeaderCell.js +26 -0
- package/lib/components/DataSpreadsheet/utils/createCellSelectionArea.js +11 -6
- package/lib/components/DataSpreadsheet/utils/generateData.js +17 -9
- package/lib/components/DataSpreadsheet/utils/getSpreadsheetWidth.js +40 -0
- package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +6 -2
- package/lib/components/DataSpreadsheet/utils/moveColumnIndicatorLine.js +45 -0
- package/lib/components/Datagrid/Datagrid/Datagrid.js +25 -8
- package/lib/components/Datagrid/Datagrid/DatagridHead.js +8 -16
- package/lib/components/Datagrid/Datagrid/DatagridHeaderRow.js +10 -10
- package/lib/components/Datagrid/Datagrid/DatagridRow.js +14 -2
- package/lib/components/Datagrid/Datagrid/index.js +3 -5
- package/lib/components/Datagrid/index.js +2 -2
- package/lib/components/Datagrid/useNestedRows.js +3 -3
- package/lib/components/Datagrid/useRowExpander.js +1 -1
- package/lib/components/ExportModal/ExportModal.js +9 -4
- package/lib/components/SidePanel/SidePanel.js +5 -1
- package/lib/components/WebTerminal/WebTerminal.js +36 -10
- package/lib/components/WebTerminal/WebTerminalContentWrapper.js +58 -0
- package/lib/components/WebTerminal/index.js +9 -1
- package/lib/components/index.js +6 -0
- package/lib/global/js/package-settings.js +1 -0
- package/package.json +14 -13
- package/scss/components/AddSelect/_add-select.scss +15 -2
- package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +38 -14
- package/scss/components/Datagrid/styles/datagrid.scss +8 -0
- package/scss/components/Datagrid/styles/useNestedRows.scss +1 -1
- package/scss/components/SidePanel/_side-panel.scss +22 -3
- package/scss/components/WebTerminal/_storybook-styles.scss +5 -0
- package/scss/components/WebTerminal/_web-terminal.scss +14 -4
@@ -0,0 +1,153 @@
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
3
|
+
|
4
|
+
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; }
|
5
|
+
|
6
|
+
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; }
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Copyright IBM Corp. 2022, 2022
|
10
|
+
*
|
11
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
13
|
+
*/
|
14
|
+
import { useEffect } from 'react';
|
15
|
+
import { px } from '@carbon/layout';
|
16
|
+
import { pkg } from '../../../settings';
|
17
|
+
import { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
|
18
|
+
export var useSpreadsheetMouseUp = function useSpreadsheetMouseUp(_ref) {
|
19
|
+
var currentMatcher = _ref.currentMatcher,
|
20
|
+
setSelectionAreas = _ref.setSelectionAreas,
|
21
|
+
setClickAndHoldActive = _ref.setClickAndHoldActive,
|
22
|
+
setValidStartingPoint = _ref.setValidStartingPoint,
|
23
|
+
validStartingPoint = _ref.validStartingPoint,
|
24
|
+
_ref$blockClass = _ref.blockClass,
|
25
|
+
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
26
|
+
ref = _ref.ref,
|
27
|
+
setHeaderCellHoldActive = _ref.setHeaderCellHoldActive,
|
28
|
+
setColumnOrder = _ref.setColumnOrder,
|
29
|
+
visibleColumns = _ref.visibleColumns,
|
30
|
+
setActiveCellCoordinates = _ref.setActiveCellCoordinates,
|
31
|
+
activeCellCoordinates = _ref.activeCellCoordinates,
|
32
|
+
rows = _ref.rows,
|
33
|
+
defaultColumn = _ref.defaultColumn;
|
34
|
+
useEffect(function () {
|
35
|
+
var handleMouseUp = function handleMouseUp(event) {
|
36
|
+
// Remove the cloned selection area on mouse up
|
37
|
+
if (!validStartingPoint) {
|
38
|
+
setHeaderCellHoldActive(false);
|
39
|
+
var selectionAreaCloneElement = ref.current.querySelector(".".concat(blockClass, "__selection-area--element-cloned"));
|
40
|
+
|
41
|
+
if (!selectionAreaCloneElement) {
|
42
|
+
return;
|
43
|
+
} // Mouse up while a cloned selection area exists/a column is being reordered
|
44
|
+
|
45
|
+
|
46
|
+
if (selectionAreaCloneElement) {
|
47
|
+
var closestCell = event.target.closest(".".concat(blockClass, "--interactive-cell-element"));
|
48
|
+
var newColumnIndex = closestCell === null || closestCell === void 0 ? void 0 : closestCell.getAttribute('data-column-index');
|
49
|
+
var originalColumnIndex = selectionAreaCloneElement === null || selectionAreaCloneElement === void 0 ? void 0 : selectionAreaCloneElement.getAttribute('data-column-index-original');
|
50
|
+
var columnToMoveToElement = ref.current.querySelector("[data-row-index=\"header\"][data-column-index=\"".concat(newColumnIndex, "\"]")); // Mouse up element was not part of the spreadsheet component
|
51
|
+
|
52
|
+
if (!columnToMoveToElement) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
|
56
|
+
var selectionAreaToMove = ref.current.querySelector("[data-matcher-id=\"".concat(currentMatcher, "\"]"));
|
57
|
+
var spreadsheetPosition = ref.current.getBoundingClientRect();
|
58
|
+
var newIndexPosition = columnToMoveToElement.getBoundingClientRect();
|
59
|
+
var relativeNewPosition = newIndexPosition.left - spreadsheetPosition.left;
|
60
|
+
var cloneColumnWidth = selectionAreaCloneElement.offsetWidth;
|
61
|
+
var columnsWidthUpToNewIndex = 0;
|
62
|
+
var newIndexLessThanStarting = newColumnIndex < originalColumnIndex;
|
63
|
+
visibleColumns.forEach(function (item, index) {
|
64
|
+
if (newIndexLessThanStarting && index === visibleColumns.length - 1) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
|
68
|
+
if (index <= newColumnIndex) {
|
69
|
+
columnsWidthUpToNewIndex += (item === null || item === void 0 ? void 0 : item.width) || (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
var updatedSelectionAreaPlacement = newIndexLessThanStarting ? relativeNewPosition : columnsWidthUpToNewIndex - cloneColumnWidth + (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth);
|
73
|
+
selectionAreaToMove.style.left = px(updatedSelectionAreaPlacement);
|
74
|
+
setSelectionAreas(function (prev) {
|
75
|
+
var selectionAreaClone = deepCloneObject(prev);
|
76
|
+
|
77
|
+
if (originalColumnIndex === newColumnIndex) {
|
78
|
+
return prev;
|
79
|
+
}
|
80
|
+
|
81
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
82
|
+
return item.matcher === currentMatcher;
|
83
|
+
});
|
84
|
+
|
85
|
+
if (indexOfItemToUpdate === -1) {
|
86
|
+
return prev;
|
87
|
+
}
|
88
|
+
|
89
|
+
selectionAreaClone[indexOfItemToUpdate].header.index = Number(newColumnIndex);
|
90
|
+
selectionAreaClone[indexOfItemToUpdate].point1.column = Number(newColumnIndex);
|
91
|
+
selectionAreaClone[indexOfItemToUpdate].point2.column = Number(newColumnIndex);
|
92
|
+
return selectionAreaClone;
|
93
|
+
});
|
94
|
+
var columnIdArray = visibleColumns.map(function (column) {
|
95
|
+
return column.id;
|
96
|
+
});
|
97
|
+
|
98
|
+
var columnIdArrayClone = _toConsumableArray(columnIdArray); // Remove one element at the original index
|
99
|
+
|
100
|
+
|
101
|
+
columnIdArrayClone.splice(originalColumnIndex, 1); // Add one element at the new index
|
102
|
+
|
103
|
+
columnIdArrayClone.splice(newColumnIndex, 0, columnIdArray[originalColumnIndex]);
|
104
|
+
setColumnOrder(columnIdArrayClone); // Function provided by useTable (react-table) hook to reorder columns
|
105
|
+
|
106
|
+
var newCellCoords = _objectSpread(_objectSpread({}, activeCellCoordinates), {}, {
|
107
|
+
column: Number(newColumnIndex)
|
108
|
+
});
|
109
|
+
|
110
|
+
setActiveCellCoordinates(newCellCoords); // Remove the cloned column and indicator elements
|
111
|
+
|
112
|
+
var indicatorLineElement = ref.current.querySelector(".".concat(blockClass, "__reorder-indicator-line"));
|
113
|
+
indicatorLineElement === null || indicatorLineElement === void 0 ? void 0 : indicatorLineElement.remove();
|
114
|
+
selectionAreaCloneElement === null || selectionAreaCloneElement === void 0 ? void 0 : selectionAreaCloneElement.remove();
|
115
|
+
}
|
116
|
+
} // Mouse up was on a spreadsheet body cell which is a valid
|
117
|
+
// start/end point for creating a selection area
|
118
|
+
|
119
|
+
|
120
|
+
if (validStartingPoint) {
|
121
|
+
setClickAndHoldActive(false);
|
122
|
+
setValidStartingPoint(false);
|
123
|
+
var cellButton = event.target.closest(".".concat(blockClass, "__body--td"));
|
124
|
+
|
125
|
+
if (cellButton) {
|
126
|
+
var endCellCoordinates = {
|
127
|
+
row: Number(cellButton.getAttribute('data-row-index')),
|
128
|
+
column: Number(cellButton.getAttribute('data-column-index'))
|
129
|
+
};
|
130
|
+
setSelectionAreas(function (prev) {
|
131
|
+
var selectionAreaClone = deepCloneObject(prev);
|
132
|
+
var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
|
133
|
+
return item.matcher === currentMatcher;
|
134
|
+
}); // No items in the array have an object that matches the value of currentMatcher
|
135
|
+
|
136
|
+
if (indexOfItemToUpdate === -1) {
|
137
|
+
return prev;
|
138
|
+
}
|
139
|
+
|
140
|
+
selectionAreaClone[indexOfItemToUpdate].point2 = endCellCoordinates;
|
141
|
+
selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
|
142
|
+
return selectionAreaClone;
|
143
|
+
});
|
144
|
+
}
|
145
|
+
}
|
146
|
+
};
|
147
|
+
|
148
|
+
document.addEventListener('mouseup', handleMouseUp);
|
149
|
+
return function () {
|
150
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
151
|
+
};
|
152
|
+
}, [blockClass, currentMatcher, setSelectionAreas, setClickAndHoldActive, setValidStartingPoint, validStartingPoint, ref, setHeaderCellHoldActive, setColumnOrder, visibleColumns, setActiveCellCoordinates, activeCellCoordinates, rows, defaultColumn]);
|
153
|
+
};
|
@@ -0,0 +1,16 @@
|
|
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 { deepCloneObject } from '../../../global/js/utils/deepCloneObject';
|
8
|
+
export var checkSelectedHeaderCell = function checkSelectedHeaderCell(headerIndex, selectionAreas, headerType) {
|
9
|
+
var areasCloned = deepCloneObject(selectionAreas);
|
10
|
+
var isSelectedHeader = areasCloned.some(function (area) {
|
11
|
+
var _area$header, _area$header2;
|
12
|
+
|
13
|
+
return (area === null || area === void 0 ? void 0 : (_area$header = area.header) === null || _area$header === void 0 ? void 0 : _area$header.type) === headerType && headerIndex === (area === null || area === void 0 ? void 0 : (_area$header2 = area.header) === null || _area$header2 === void 0 ? void 0 : _area$header2.index);
|
14
|
+
});
|
15
|
+
return isSelectedHeader;
|
16
|
+
};
|
@@ -14,7 +14,8 @@ export var createCellSelectionArea = function createCellSelectionArea(_ref) {
|
|
14
14
|
defaultColumn = _ref.defaultColumn,
|
15
15
|
selectionAreas = _ref.selectionAreas,
|
16
16
|
setSelectionAreas = _ref.setSelectionAreas,
|
17
|
-
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea
|
17
|
+
setActiveCellInsideSelectionArea = _ref.setActiveCellInsideSelectionArea,
|
18
|
+
visibleColumns = _ref.visibleColumns;
|
18
19
|
|
19
20
|
var _getSelectionAreaPoin = getSelectionAreaPoints(area),
|
20
21
|
lowestColumnIndex = _getSelectionAreaPoin.lowestColumnIndex,
|
@@ -28,24 +29,28 @@ export var createCellSelectionArea = function createCellSelectionArea(_ref) {
|
|
28
29
|
activeCellElement.setAttribute('data-selection-id', area.matcher);
|
29
30
|
}
|
30
31
|
|
31
|
-
var
|
32
|
+
var selectionAreaVariableWidth = 0;
|
33
|
+
visibleColumns.forEach(function (item, index) {
|
34
|
+
if (index >= lowestColumnIndex && index <= greatestColumnIndex) {
|
35
|
+
selectionAreaVariableWidth += (item === null || item === void 0 ? void 0 : item.width) || (defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.width);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]")) || document.querySelector(".".concat(blockClass, "__body--td")); // if we can't find the point1 element (this can happen in the case where a virtualized row is not present anymore in the DOM), we get the default height of the first body cell we find
|
32
39
|
|
33
|
-
var selectionAreaCellWidth = point1Element.offsetWidth;
|
34
40
|
var selectionAreaCellHeight = point1Element.offsetHeight;
|
35
|
-
var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumnIndex - lowestColumnIndex + 1);
|
36
41
|
var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRowIndex - lowestRowIndex + 1);
|
37
42
|
var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
|
38
43
|
var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
|
39
44
|
var relativePosition = {
|
40
45
|
top: placementElement ? placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top : lowestRowIndex === 0 ? 0 : selectionAreaCellHeight * lowestRowIndex,
|
41
46
|
// calculate top value here if virtualized row is not in DOM
|
42
|
-
left: placementElement ? placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left : lowestColumnIndex === 0 ? 0 + (defaultColumn.rowHeaderWidth - 4) :
|
47
|
+
left: placementElement ? placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left : lowestColumnIndex === 0 ? 0 + (defaultColumn.rowHeaderWidth - 4) : defaultColumn.width * lowestColumnIndex + (defaultColumn.rowHeaderWidth - 4) // calculate left value here if virtualized row is not in DOM, accounting for row header cell width (including borders)
|
43
48
|
|
44
49
|
};
|
45
50
|
var selectionAreaElement = document.querySelector("[data-matcher-id=\"".concat(area.matcher, "\"]")) || document.createElement('div');
|
46
51
|
selectionAreaElement.classList.add("".concat(blockClass, "__selection-area--element"));
|
47
52
|
selectionAreaElement.setAttribute('data-matcher-id', area.matcher);
|
48
|
-
selectionAreaElement.style.width = px(
|
53
|
+
selectionAreaElement.style.width = px(selectionAreaVariableWidth);
|
49
54
|
selectionAreaElement.style.height = px(selectionAreaTotalHeight);
|
50
55
|
selectionAreaElement.style.left = px(relativePosition.left);
|
51
56
|
selectionAreaElement.style.top = px(relativePosition.top);
|
@@ -24,28 +24,36 @@ var range = function range(len) {
|
|
24
24
|
return arr;
|
25
25
|
};
|
26
26
|
|
27
|
-
var newPet = function newPet() {
|
28
|
-
|
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
|
-
|
38
|
-
|
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(
|
47
|
-
subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined
|
48
|
-
});
|
56
|
+
return _objectSpread({}, newPet(extraColumns));
|
49
57
|
});
|
50
58
|
};
|
51
59
|
|
@@ -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
|
+
};
|
@@ -63,10 +63,14 @@ export var handleHeaderCellSelection = function handleHeaderCellSelection(_ref)
|
|
63
63
|
|
64
64
|
if (isHoldingCommandKey) {
|
65
65
|
var selectionsFromHeaderCell = selectionsClone.filter(function (item) {
|
66
|
-
|
66
|
+
var _item$header;
|
67
|
+
|
68
|
+
return (_item$header = item.header) === null || _item$header === void 0 ? void 0 : _item$header.type;
|
67
69
|
});
|
68
70
|
var previouslyCreatedHeaderSelection = selectionsFromHeaderCell.filter(function (item) {
|
69
|
-
|
71
|
+
var _item$header2;
|
72
|
+
|
73
|
+
return ((_item$header2 = item.header) === null || _item$header2 === void 0 ? void 0 : _item$header2.type) === type;
|
70
74
|
});
|
71
75
|
var isHeaderPartOfPreviousSelection = checkActiveHeaderCell(index, previouslyCreatedHeaderSelection, type); // Prevents row/column header selections from being created multiple times
|
72
76
|
|
@@ -0,0 +1,34 @@
|
|
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
|
+
import { pkg } from '../../../settings';
|
9
|
+
export var moveColumnIndicatorLine = function moveColumnIndicatorLine(_ref) {
|
10
|
+
var _ref$blockClass = _ref.blockClass,
|
11
|
+
blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
|
12
|
+
clonedSelectionElement = _ref.clonedSelectionElement,
|
13
|
+
ref = _ref.ref,
|
14
|
+
spreadsheetCoords = _ref.spreadsheetCoords;
|
15
|
+
var closestCell = event.target.closest(".".concat(blockClass, "--interactive-cell-element"));
|
16
|
+
var newColumnIndex = closestCell === null || closestCell === void 0 ? void 0 : closestCell.getAttribute('data-column-index');
|
17
|
+
var originalColumnIndex = clonedSelectionElement === null || clonedSelectionElement === void 0 ? void 0 : clonedSelectionElement.getAttribute('data-column-index-original');
|
18
|
+
var closestCellCoords = closestCell.getBoundingClientRect();
|
19
|
+
var indicatorLineElement = ref.current.querySelector(".".concat(blockClass, "__reorder-indicator-line"));
|
20
|
+
var matcherId = clonedSelectionElement === null || clonedSelectionElement === void 0 ? void 0 : clonedSelectionElement.getAttribute('data-matcher-id');
|
21
|
+
var selectionAreaOrigin = ref.current.querySelector("[data-matcher-id=\"".concat(matcherId, "\"]"));
|
22
|
+
|
23
|
+
if (Number(newColumnIndex) > Number(originalColumnIndex)) {
|
24
|
+
indicatorLineElement.style.left = px(closestCellCoords.left - spreadsheetCoords.left + closestCell.offsetWidth - 2);
|
25
|
+
}
|
26
|
+
|
27
|
+
if (Number(newColumnIndex) < Number(originalColumnIndex)) {
|
28
|
+
indicatorLineElement.style.left = px(closestCellCoords.left - spreadsheetCoords.left);
|
29
|
+
}
|
30
|
+
|
31
|
+
if (Number(newColumnIndex) === Number(originalColumnIndex)) {
|
32
|
+
indicatorLineElement.style.left = selectionAreaOrigin.style.left;
|
33
|
+
}
|
34
|
+
};
|
@@ -1,16 +1,16 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
4
|
-
var _excluded = ["
|
4
|
+
var _excluded = ["datagridState"];
|
5
5
|
|
6
|
-
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
6
|
+
/**
|
7
|
+
* Copyright IBM Corp. 2020, 2022
|
8
|
+
*
|
9
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
12
11
|
*/
|
13
12
|
import React from 'react';
|
13
|
+
import PropTypes from 'prop-types';
|
14
14
|
import { DataTable } from 'carbon-components-react';
|
15
15
|
import cx from 'classnames';
|
16
16
|
import DatagridHead from './DatagridHead';
|
@@ -18,13 +18,22 @@ import DatagridBody from './DatagridBody';
|
|
18
18
|
import DatagridToolbar from './DatagridToolbar';
|
19
19
|
import { getDevtoolsProps } from '../../../global/js/utils/devtools';
|
20
20
|
import { pkg } from '../../../settings';
|
21
|
+
import pconsole from '../../../global/js/utils/pconsole';
|
21
22
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
22
23
|
var componentName = 'Datagrid';
|
23
24
|
var TableContainer = DataTable.TableContainer,
|
24
25
|
Table = DataTable.Table;
|
25
|
-
var Datagrid = /*#__PURE__*/React.forwardRef(function (
|
26
|
+
export var Datagrid = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
26
27
|
var _getTableProps;
|
27
28
|
|
29
|
+
var datagridState = _ref.datagridState,
|
30
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
31
|
+
|
32
|
+
if (!datagridState) {
|
33
|
+
pconsole.warn('Datagrid was not passed datagridState which is required to render this component.');
|
34
|
+
return null;
|
35
|
+
}
|
36
|
+
|
28
37
|
var _datagridState$getTab = datagridState.getTableProps,
|
29
38
|
getTableProps = _datagridState$getTab === void 0 ? function () {} : _datagridState$getTab,
|
30
39
|
withVirtualScroll = datagridState.withVirtualScroll,
|
@@ -37,9 +46,7 @@ var Datagrid = /*#__PURE__*/React.forwardRef(function (datagridState, ref) {
|
|
37
46
|
_datagridState$vertic = datagridState.verticalAlign,
|
38
47
|
verticalAlign = _datagridState$vertic === void 0 ? 'center' : _datagridState$vertic,
|
39
48
|
variableRowHeight = datagridState.variableRowHeight,
|
40
|
-
className = datagridState.className
|
41
|
-
rest = _objectWithoutProperties(datagridState, _excluded);
|
42
|
-
|
49
|
+
className = datagridState.className;
|
43
50
|
var rows = DatagridPagination && datagridState.page || datagridState.rows;
|
44
51
|
var dataGrid = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TableContainer, {
|
45
52
|
className: cx("".concat(blockClass, "__grid-container"), withVirtualScroll || fullHeightDatagrid ? "".concat(blockClass, "__full-height") : '')
|
@@ -67,4 +74,9 @@ Datagrid = pkg.checkComponentEnabled(Datagrid, componentName); // The display na
|
|
67
74
|
// is used in preference to relying on function.name.
|
68
75
|
|
69
76
|
Datagrid.displayName = componentName;
|
70
|
-
|
77
|
+
Datagrid.propTypes = {
|
78
|
+
/**
|
79
|
+
* The data grid state, much of it being supplied by the useDatagrid hook
|
80
|
+
*/
|
81
|
+
datagridState: PropTypes.object.isRequired
|
82
|
+
};
|
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
*
|
5
|
-
*
|
6
|
-
* (c) Copyright IBM Corp. 2020, 2021
|
7
|
-
* US Government Users Restricted Rights - Use, duplication or disclosure
|
8
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2020, 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.
|
9
6
|
*/
|
10
7
|
import React from 'react';
|
11
8
|
import { DataTable } from 'carbon-components-react';
|
@@ -16,14 +13,9 @@ var DatagridHead = function DatagridHead(datagridState) {
|
|
16
13
|
headerGroups = _datagridState$header === void 0 ? [] : _datagridState$header,
|
17
14
|
headRef = datagridState.headRef,
|
18
15
|
HeaderRow = datagridState.HeaderRow;
|
19
|
-
return /*#__PURE__*/React.createElement(TableHead, null, headerGroups.map(function (headerGroup
|
20
|
-
return (
|
21
|
-
|
22
|
-
// doesn't support header grouping.
|
23
|
-
React.createElement("div", _extends({}, headerGroup.getHeaderGroupProps(), {
|
24
|
-
ref: headRef,
|
25
|
-
key: "header_".concat(index)
|
26
|
-
}), HeaderRow(datagridState))
|
16
|
+
return /*#__PURE__*/React.createElement(TableHead, null, headerGroups.map(function (headerGroup) {
|
17
|
+
return (// doesn't support header grouping.
|
18
|
+
HeaderRow(datagridState, headRef, headerGroup)
|
27
19
|
);
|
28
20
|
}));
|
29
21
|
};
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
3
|
|
4
|
-
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
4
|
+
/**
|
5
|
+
* Copyright IBM Corp. 2020, 2022
|
6
|
+
*
|
7
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
10
9
|
*/
|
11
10
|
// @flow
|
12
11
|
import React from 'react';
|
@@ -16,10 +15,11 @@ import { selectionColumnId } from '../common-column-ids';
|
|
16
15
|
import { pkg } from '../../../settings';
|
17
16
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
18
17
|
|
19
|
-
var HeaderRow = function HeaderRow(datagridState) {
|
20
|
-
return /*#__PURE__*/React.createElement(TableRow, {
|
21
|
-
className: "".concat(blockClass, "__head")
|
22
|
-
|
18
|
+
var HeaderRow = function HeaderRow(datagridState, headRef, headerGroup) {
|
19
|
+
return /*#__PURE__*/React.createElement(TableRow, _extends({}, headerGroup.getHeaderGroupProps(), {
|
20
|
+
className: cx("".concat(blockClass, "__head"), headerGroup.getHeaderGroupProps().className),
|
21
|
+
ref: headRef
|
22
|
+
}), datagridState.headers.filter(function (_ref) {
|
23
23
|
var isVisible = _ref.isVisible;
|
24
24
|
return isVisible;
|
25
25
|
}).map(function (header) {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
4
|
var _excluded = ["children"];
|
4
5
|
|
5
6
|
/*
|
@@ -13,6 +14,7 @@ var _excluded = ["children"];
|
|
13
14
|
import React from 'react';
|
14
15
|
import { DataTable, SkeletonText } from 'carbon-components-react';
|
15
16
|
import { selectionColumnId } from '../common-column-ids';
|
17
|
+
import cx from 'classnames';
|
16
18
|
import { pkg } from '../../../settings';
|
17
19
|
var blockClass = "".concat(pkg.prefix, "--datagrid");
|
18
20
|
var TableRow = DataTable.TableRow,
|
@@ -21,9 +23,17 @@ var TableRow = DataTable.TableRow,
|
|
21
23
|
var DatagridRow = function DatagridRow(datagridState) {
|
22
24
|
var row = datagridState.row;
|
23
25
|
return /*#__PURE__*/React.createElement(TableRow, _extends({
|
24
|
-
className: "".concat(blockClass, "__carbon-row")
|
26
|
+
className: cx("".concat(blockClass, "__carbon-row"), _defineProperty({}, "".concat(blockClass, "__carbon-row-expanded"), row.isExpanded))
|
25
27
|
}, row.getRowProps(), {
|
26
|
-
key: row.id
|
28
|
+
key: row.id,
|
29
|
+
onMouseEnter: function onMouseEnter(event) {
|
30
|
+
var hoverRow = event.target.closest(".".concat(blockClass, "__carbon-row-expanded"));
|
31
|
+
hoverRow === null || hoverRow === void 0 ? void 0 : hoverRow.classList.add("".concat(blockClass, "__carbon-row-expanded-hover-active"));
|
32
|
+
},
|
33
|
+
onMouseLeave: function onMouseLeave(event) {
|
34
|
+
var hoverRow = event.target.closest(".".concat(blockClass, "__carbon-row-expanded"));
|
35
|
+
hoverRow === null || hoverRow === void 0 ? void 0 : hoverRow.classList.remove("".concat(blockClass, "__carbon-row-expanded-hover-active"));
|
36
|
+
}
|
27
37
|
}), row.cells.map(function (cell) {
|
28
38
|
var cellProps = cell.getCellProps();
|
29
39
|
|
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
1
|
+
/**
|
2
|
+
* Copyright IBM Corp. 2020, 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.
|
7
6
|
*/
|
8
|
-
export {
|
7
|
+
export { Datagrid } from './Datagrid';
|
@@ -5,7 +5,7 @@
|
|
5
5
|
* US Government Users Restricted Rights - Use, duplication or disclosure
|
6
6
|
* restricted by GSA ADP Schedule Contract with IBM Corp.
|
7
7
|
*/
|
8
|
-
export {
|
8
|
+
export { Datagrid } from './Datagrid';
|
9
9
|
export { default as useDatagrid } from './useDatagrid';
|
10
10
|
export { default as useInfiniteScroll } from './useInfiniteScroll';
|
11
11
|
export { default as useNestedRows } from './useNestedRows';
|
@@ -11,7 +11,7 @@ var blockClass = "".concat(pkg.prefix, "--datagrid");
|
|
11
11
|
|
12
12
|
var useNestedRows = function useNestedRows(hooks) {
|
13
13
|
useRowExpander(hooks);
|
14
|
-
var marginLeft =
|
14
|
+
var marginLeft = 24;
|
15
15
|
|
16
16
|
var getRowProps = function getRowProps(props, _ref) {
|
17
17
|
var row = _ref.row;
|
@@ -25,7 +25,7 @@ var useNestedRows = function useNestedRows(hooks) {
|
|
25
25
|
return [props, {
|
26
26
|
style: {
|
27
27
|
marginLeft: "".concat(row.depth > 0 ? marginLeft : 0, "px"),
|
28
|
-
paddingLeft: "".concat(row.depth > 1 ? marginLeft * (row.depth - 1) : 0, "px"),
|
28
|
+
paddingLeft: "".concat(row.depth > 1 ? marginLeft * (row.depth - 1) + marginLeft : row.depth === 1 ? marginLeft : 0, "px"),
|
29
29
|
maxWidth: "calc(100% - ".concat(marginLeft * row.depth, "px)")
|
30
30
|
}
|
31
31
|
}];
|
@@ -40,7 +40,7 @@ var useNestedRows = function useNestedRows(hooks) {
|
|
40
40
|
}) === 0;
|
41
41
|
return [props, {
|
42
42
|
style: {
|
43
|
-
marginRight: isFirstCell ? "-".concat(marginLeft * cell.row.depth, "px") : ''
|
43
|
+
marginRight: "".concat(isFirstCell && cell.row.depth > 0 ? "-".concat(marginLeft * (cell.row.depth + 1), "px") : '')
|
44
44
|
}
|
45
45
|
}];
|
46
46
|
};
|
@@ -20,7 +20,7 @@ var useRowExpander = function useRowExpander(hooks) {
|
|
20
20
|
var row = _ref.row;
|
21
21
|
return row.canExpand && /*#__PURE__*/React.createElement("span", row.getToggleRowExpandedProps(), row.isExpanded ? /*#__PURE__*/React.createElement(ChevronUp16, null) : /*#__PURE__*/React.createElement(ChevronDown16, null));
|
22
22
|
},
|
23
|
-
width:
|
23
|
+
width: 48,
|
24
24
|
disableResizing: true,
|
25
25
|
disableSortBy: true,
|
26
26
|
Header: ''
|
@@ -14,7 +14,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
14
14
|
// This source code is licensed under the Apache-2.0 license found in the
|
15
15
|
// LICENSE file in the root directory of this source tree.
|
16
16
|
//
|
17
|
-
import React, { useState, useRef, forwardRef } from 'react';
|
17
|
+
import React, { useState, useRef, forwardRef, useEffect } from 'react';
|
18
18
|
import { Button, ComposedModal, ModalHeader, ModalFooter, ModalBody, TextInput, RadioButton, RadioButtonGroup, FormGroup, Loading, PasswordInput } from 'carbon-components-react';
|
19
19
|
import cx from 'classnames';
|
20
20
|
import { ErrorFilled16, CheckmarkFilled16 } from '@carbon/icons-react';
|
@@ -30,8 +30,6 @@ var defaults = {
|
|
30
30
|
validExtensions: Object.freeze([])
|
31
31
|
};
|
32
32
|
export var ExportModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
33
|
-
var _preformattedExtensio;
|
34
|
-
|
35
33
|
var body = _ref.body,
|
36
34
|
className = _ref.className,
|
37
35
|
error = _ref.error,
|
@@ -60,7 +58,7 @@ export var ExportModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
60
58
|
validExtensions = _ref$validExtensions === void 0 ? defaults.validExtensions : _ref$validExtensions,
|
61
59
|
rest = _objectWithoutProperties(_ref, _excluded);
|
62
60
|
|
63
|
-
var _useState = useState(
|
61
|
+
var _useState = useState(''),
|
64
62
|
_useState2 = _slicedToArray(_useState, 2),
|
65
63
|
name = _useState2[0],
|
66
64
|
setName = _useState2[1];
|
@@ -71,11 +69,18 @@ export var ExportModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
71
69
|
setDirtyInput = _useState4[1]; // by default (if it exists) use the first extension in the extension array
|
72
70
|
|
73
71
|
|
74
|
-
var _useState5 = useState(
|
72
|
+
var _useState5 = useState(''),
|
75
73
|
_useState6 = _slicedToArray(_useState5, 2),
|
76
74
|
extension = _useState6[0],
|
77
75
|
setExtension = _useState6[1];
|
78
76
|
|
77
|
+
useEffect(function () {
|
78
|
+
var _preformattedExtensio;
|
79
|
+
|
80
|
+
setName(filename);
|
81
|
+
setExtension(preformattedExtensions === null || preformattedExtensions === void 0 ? void 0 : (_preformattedExtensio = preformattedExtensions[0]) === null || _preformattedExtensio === void 0 ? void 0 : _preformattedExtensio.extension);
|
82
|
+
}, [filename, preformattedExtensions]);
|
83
|
+
|
79
84
|
var onNameChangeHandler = function onNameChangeHandler(evt) {
|
80
85
|
setName(evt.target.value);
|
81
86
|
};
|