@carbon/ibm-products 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. package/README.md +0 -3
  2. package/css/index-full-carbon.css +1543 -529
  3. package/css/index-full-carbon.css.map +1 -1
  4. package/css/index-full-carbon.min.css +5 -5
  5. package/css/index-full-carbon.min.css.map +1 -1
  6. package/css/index-without-carbon-released-only.css +12 -0
  7. package/css/index-without-carbon-released-only.css.map +1 -1
  8. package/css/index-without-carbon-released-only.min.css +2 -2
  9. package/css/index-without-carbon-released-only.min.css.map +1 -1
  10. package/css/index-without-carbon.css +77 -187
  11. package/css/index-without-carbon.css.map +1 -1
  12. package/css/index-without-carbon.min.css +4 -4
  13. package/css/index-without-carbon.min.css.map +1 -1
  14. package/css/index.css +194 -187
  15. package/css/index.css.map +1 -1
  16. package/css/index.min.css +5 -5
  17. package/css/index.min.css.map +1 -1
  18. package/es/components/AddSelect/AddSelect.js +63 -12
  19. package/es/components/AddSelect/AddSelectColumn.js +58 -22
  20. package/es/components/AddSelect/AddSelectList.js +38 -18
  21. package/es/components/AddSelect/AddSelectSidebar.js +2 -1
  22. package/es/components/ButtonMenu/ButtonMenu.js +11 -3
  23. package/es/components/CreateFullPage/CreateFullPageStep.js +4 -4
  24. package/es/components/CreateTearsheet/CreateTearsheetStep.js +4 -4
  25. package/es/components/DataSpreadsheet/DataSpreadsheet.js +107 -89
  26. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +93 -20
  27. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +50 -2
  28. package/es/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
  29. package/es/components/ImportModal/ImportModal.js +2 -2
  30. package/es/components/UserProfileImage/UserProfileImage.js +1 -1
  31. package/es/components/index.js +0 -1
  32. package/es/global/js/package-settings.js +1 -2
  33. package/lib/components/AddSelect/AddSelect.js +63 -12
  34. package/lib/components/AddSelect/AddSelectColumn.js +57 -21
  35. package/lib/components/AddSelect/AddSelectList.js +39 -17
  36. package/lib/components/AddSelect/AddSelectSidebar.js +2 -1
  37. package/lib/components/ButtonMenu/ButtonMenu.js +11 -3
  38. package/lib/components/CreateFullPage/CreateFullPageStep.js +4 -4
  39. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +4 -4
  40. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +108 -91
  41. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +94 -20
  42. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +52 -7
  43. package/lib/components/DataSpreadsheet/utils/handleHeaderCellSelection.js +3 -1
  44. package/lib/components/ImportModal/ImportModal.js +1 -1
  45. package/lib/components/UserProfileImage/UserProfileImage.js +1 -1
  46. package/lib/components/index.js +0 -8
  47. package/lib/global/js/package-settings.js +1 -2
  48. package/package.json +16 -16
  49. package/scss/components/AboutModal/_about-modal.scss +2 -2
  50. package/scss/components/ActionSet/_action-set.scss +3 -1
  51. package/scss/components/AddSelect/_add-select.scss +41 -2
  52. package/scss/components/CreateModal/_create-modal.scss +7 -5
  53. package/scss/components/CreateModal/_storybook-styles.scss +8 -7
  54. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +21 -3
  55. package/scss/components/ExportModal/_export-modal.scss +3 -3
  56. package/scss/components/InlineEdit/_inline-edit.scss +3 -0
  57. package/scss/components/ModifiedTabs/_modified-tabs.scss +4 -9
  58. package/scss/components/NotificationsPanel/_notifications-panel.scss +9 -5
  59. package/scss/components/OptionsTile/_options-tile.scss +0 -1
  60. package/scss/components/RemoveModal/_remove-modal.scss +3 -3
  61. package/scss/components/TagSet/_tag-set.scss +2 -1
  62. package/scss/components/Tearsheet/_tearsheet.scss +4 -1
  63. package/scss/components/_index.scss +0 -1
  64. package/es/components/LoadingBar/LoadingBar.js +0 -156
  65. package/es/components/LoadingBar/index.js +0 -7
  66. package/lib/components/LoadingBar/LoadingBar.js +0 -170
  67. package/lib/components/LoadingBar/index.js +0 -13
  68. package/scss/components/LoadingBar/_index.scss +0 -8
  69. package/scss/components/LoadingBar/_loading-bar.scss +0 -224
  70. package/scss/components/LoadingBar/_storybook-styles.scss +0 -14
@@ -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
- onActiveCellChange = _ref.onActiveCellChange,
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(false),
92
+ var _useState7 = useState([]),
91
93
  _useState8 = _slicedToArray(_useState7, 2),
92
- clickAndHoldActive = _useState8[0],
93
- setClickAndHoldActive = _useState8[1];
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
- currentMatcher = _useState10[0],
98
- setCurrentMatcher = _useState10[1];
99
+ clickAndHoldActive = _useState10[0],
100
+ setClickAndHoldActive = _useState10[1];
99
101
 
100
- var _useState11 = useState(false),
102
+ var _useState11 = useState(''),
101
103
  _useState12 = _slicedToArray(_useState11, 2),
102
- isEditing = _useState12[0],
103
- setIsEditing = _useState12[1];
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
- cellEditorValue = _useState14[0],
108
- setCellEditorValue = _useState14[1];
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
- var currentMatcherRef = useRef();
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
- }, [activeCellCoordinates, previousState === null || previousState === void 0 ? void 0 : previousState.activeCellCoordinates, updateData, rows, isEditing, removeCellEditor]);
193
- var handleActiveCellMouseEnter = useCallback(function () {
194
- handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
195
- }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]);
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
- var handleHeaderCellProps = {
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
- }; // Select an entire column
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
- }; // Only update if there are cell selection areas
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
- cellSizeValue: cellSizeValue,
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
- // Create cell selection areas based on selectionAreas array
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
- if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
46
- // Do not create a cell selection area if point1 and point2 have the same values
47
- // Cell selections must have two distinctly different points for an area to be created
48
- if (area.point1.row === area.point2.row && area.point1.column === area.point2.column) {
49
- var selectionAreasClone = deepCloneObject(selectionAreas);
50
- var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
51
- return item.matcher === area.matcher;
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
- selectionAreasClone[indexOfCurrentArea].areaCreated = false;
54
- selectionAreasClone[indexOfCurrentArea].point2 = null;
55
- return setSelectionAreas(selectionAreasClone);
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]); // Mouse up
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 (_ref2) {
222
- var index = _ref2.index,
223
- style = _ref2.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
  */
@@ -1,5 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+
5
+ 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; }
6
+
7
+ 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; }
3
8
 
4
9
  /**
5
10
  * Copyright IBM Corp. 2022, 2022
@@ -7,24 +12,48 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
12
  * This source code is licensed under the Apache-2.0 license found in the
8
13
  * LICENSE file in the root directory of this source tree.
9
14
  */
10
- import React, { forwardRef } from 'react';
15
+ import React, { forwardRef, useEffect, useState } from 'react';
11
16
  import PropTypes from 'prop-types';
12
17
  import cx from 'classnames';
18
+ import { px } from '@carbon/layout';
13
19
  import { pkg } from '../../settings';
14
20
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell';
15
21
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection';
22
+ import { usePreviousValue } from '../../global/js/hooks';
16
23
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
17
24
  export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref) {
18
25
  var activeCellCoordinates = _ref.activeCellCoordinates,
26
+ cellSize = _ref.cellSize,
19
27
  columns = _ref.columns,
20
28
  defaultColumn = _ref.defaultColumn,
21
29
  headerGroups = _ref.headerGroups,
30
+ scrollBarSize = _ref.scrollBarSize,
22
31
  selectionAreas = _ref.selectionAreas,
23
32
  setActiveCellCoordinates = _ref.setActiveCellCoordinates,
24
33
  setCurrentMatcher = _ref.setCurrentMatcher,
25
34
  setSelectionAreas = _ref.setSelectionAreas,
35
+ setSelectionAreaData = _ref.setSelectionAreaData,
26
36
  rows = _ref.rows;
27
37
 
38
+ var _useState = useState(0),
39
+ _useState2 = _slicedToArray(_useState, 2),
40
+ scrollBarSizeValue = _useState2[0],
41
+ setScrollBarSizeValue = _useState2[1];
42
+
43
+ var previousState = usePreviousValue({
44
+ cellSize: cellSize
45
+ });
46
+ useEffect(function () {
47
+ if ((previousState === null || previousState === void 0 ? void 0 : previousState.cellSize) !== cellSize) {
48
+ var _ref$current;
49
+
50
+ var scrollContainer = ref === null || ref === void 0 ? void 0 : (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.querySelector(".".concat(blockClass, "__list--container"));
51
+ var hasScrollBar = (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollHeight) > (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.clientHeight);
52
+ var scrollBarValue = hasScrollBar ? 0 : scrollBarSize;
53
+ setScrollBarSizeValue(scrollBarValue);
54
+ }
55
+ }, [cellSize, ref, scrollBarSize, previousState === null || previousState === void 0 ? void 0 : previousState.cellSize]);
56
+
28
57
  var handleColumnHeaderClick = function handleColumnHeaderClick(index) {
29
58
  return function () {
30
59
  handleHeaderCellSelection({
@@ -36,7 +65,8 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
36
65
  setCurrentMatcher: setCurrentMatcher,
37
66
  setSelectionAreas: setSelectionAreas,
38
67
  spreadsheetRef: ref,
39
- index: index
68
+ index: index,
69
+ setSelectionAreaData: setSelectionAreaData
40
70
  });
41
71
  };
42
72
  };
@@ -47,6 +77,9 @@ export var DataSpreadsheetHeader = /*#__PURE__*/forwardRef(function (_ref, ref)
47
77
  return /*#__PURE__*/React.createElement("div", _extends({
48
78
  key: "header_".concat(index)
49
79
  }, headerGroup.getHeaderGroupProps(), {
80
+ style: _objectSpread(_objectSpread({}, headerGroup.getHeaderGroupProps().style), {}, {
81
+ width: px(parseInt(headerGroup.getHeaderGroupProps().style.width) + scrollBarSizeValue)
82
+ }),
50
83
  className: "".concat(blockClass, "__tr")
51
84
  }), /*#__PURE__*/React.createElement("button", {
52
85
  "data-row-index": "header",
@@ -84,6 +117,11 @@ DataSpreadsheetHeader.propTypes = {
84
117
  column: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
85
118
  }),
86
119
 
120
+ /**
121
+ * Specifies the cell height
122
+ */
123
+ cellSize: PropTypes.oneOf(['compact', 'standard', 'medium', 'large']),
124
+
87
125
  /**
88
126
  * All of the spreadsheet columns
89
127
  */
@@ -108,6 +146,11 @@ DataSpreadsheetHeader.propTypes = {
108
146
  */
109
147
  rows: PropTypes.arrayOf(PropTypes.object),
110
148
 
149
+ /**
150
+ * The scrollbar width
151
+ */
152
+ scrollBarSize: PropTypes.number,
153
+
111
154
  /**
112
155
  * All of the cell selection area items
113
156
  */
@@ -123,6 +166,11 @@ DataSpreadsheetHeader.propTypes = {
123
166
  */
124
167
  setCurrentMatcher: PropTypes.func,
125
168
 
169
+ /**
170
+ * Setter fn for selectionAreaData state value
171
+ */
172
+ setSelectionAreaData: PropTypes.func,
173
+
126
174
  /**
127
175
  * Setter fn for selectionAreas value
128
176
  */
@@ -16,7 +16,9 @@ export var handleHeaderCellSelection = function handleHeaderCellSelection(_ref)
16
16
  setSelectionAreas = _ref.setSelectionAreas,
17
17
  spreadsheetRef = _ref.spreadsheetRef,
18
18
  index = _ref.index,
19
- isKeyboard = _ref.isKeyboard;
19
+ isKeyboard = _ref.isKeyboard,
20
+ setSelectionAreaData = _ref.setSelectionAreaData;
21
+ setSelectionAreaData([]);
20
22
  var rowValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row : index;
21
23
  var columnValue = isKeyboard ? activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.column : index;
22
24
  var point1 = {
@@ -23,7 +23,7 @@ import cx from 'classnames';
23
23
  import PropTypes from 'prop-types';
24
24
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
25
25
  import uuidv4 from '../../global/js/utils/uuidv4';
26
- import { pkg } from '../../settings';
26
+ import { pkg, carbon } from '../../settings';
27
27
  var componentName = 'ImportModal'; // Default values for props
28
28
 
29
29
  var defaults = {
@@ -254,7 +254,7 @@ export var ImportModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
254
254
  size: "sm",
255
255
  disabled: importButtonDisabled
256
256
  }, inputButtonText)), /*#__PURE__*/React.createElement("div", {
257
- className: "bx--file-container ".concat(blockClass, "__file-container")
257
+ className: "".concat(carbon.prefix, "--file-container ").concat(blockClass, "__file-container")
258
258
  }, hasFiles && /*#__PURE__*/React.createElement("p", {
259
259
  className: "".concat(blockClass, "__helper-text")
260
260
  }, fileStatusString), files.map(function (file) {