@carbon/ibm-products 2.33.0 → 2.34.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. package/css/index-full-carbon.css +303 -11
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon.css +303 -11
  6. package/css/index-without-carbon.css.map +1 -1
  7. package/css/index-without-carbon.min.css +1 -1
  8. package/css/index-without-carbon.min.css.map +1 -1
  9. package/css/index.css +303 -11
  10. package/css/index.css.map +1 -1
  11. package/css/index.min.css +1 -1
  12. package/css/index.min.css.map +1 -1
  13. package/es/components/CreateSidePanel/CreateSidePanel.d.ts +81 -2
  14. package/es/components/CreateSidePanel/CreateSidePanel.js +5 -2
  15. package/es/components/DataSpreadsheet/DataSpreadsheet.js +5 -117
  16. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +12 -111
  17. package/es/components/DataSpreadsheet/utils/commonEventHandlers.d.ts +4 -0
  18. package/es/components/DataSpreadsheet/utils/commonEventHandlers.js +304 -0
  19. package/es/components/Datagrid/Datagrid/DatagridContent.js +2 -1
  20. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +4 -1
  21. package/es/components/Datagrid/Datagrid/DatagridRefBody.js +3 -1
  22. package/es/components/Datagrid/Datagrid/DatagridSimpleBody.js +4 -1
  23. package/es/components/Datagrid/Datagrid/DatagridVirtualBody.js +6 -2
  24. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.d.ts +1 -1
  25. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +4 -0
  26. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.d.ts +2 -1
  27. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +4 -3
  28. package/es/components/EditSidePanel/EditSidePanel.d.ts +92 -2
  29. package/es/components/EditSidePanel/EditSidePanel.js +8 -10
  30. package/es/components/FilterPanel/FilterPanelAccordion/FilterPanelAccordion.d.ts +5 -0
  31. package/es/components/FilterPanel/FilterPanelAccordion/FilterPanelAccordion.js +83 -0
  32. package/es/components/FilterPanel/FilterPanelAccordionItem/FilterPanelAccordionItem.d.ts +5 -0
  33. package/es/components/FilterPanel/FilterPanelAccordionItem/FilterPanelAccordionItem.js +94 -0
  34. package/es/components/FilterPanel/FilterPanelCheckbox/FilterPanelCheckbox.js +3 -1
  35. package/es/components/FilterPanel/FilterPanelCheckbox/index.d.ts +1 -0
  36. package/es/components/FilterPanel/FilterPanelCheckboxWithOverflow/FilterPanelCheckboxWithOverflow.d.ts +10 -0
  37. package/es/components/FilterPanel/FilterPanelCheckboxWithOverflow/FilterPanelCheckboxWithOverflow.js +157 -0
  38. package/es/components/FilterPanel/FilterPanelGroup/FilterPanelGroup.d.ts +5 -0
  39. package/es/components/FilterPanel/FilterPanelGroup/FilterPanelGroup.js +72 -0
  40. package/es/components/FilterPanel/FilterPanelLabel/FilterPanelLabel.js +2 -2
  41. package/es/components/FilterPanel/index.d.ts +4 -0
  42. package/es/components/OptionsTile/OptionsTile.d.ts +77 -3
  43. package/es/components/OptionsTile/OptionsTile.js +9 -20
  44. package/es/components/RemoveModal/RemoveModal.d.ts +81 -7
  45. package/es/components/RemoveModal/RemoveModal.js +1 -0
  46. package/es/components/ScrollGradient/ScrollGradient.d.ts +5 -0
  47. package/es/components/ScrollGradient/ScrollGradient.js +156 -0
  48. package/es/components/ScrollGradient/constants.d.ts +15 -0
  49. package/es/components/ScrollGradient/constants.js +121 -0
  50. package/es/components/ScrollGradient/index.d.ts +1 -0
  51. package/es/components/SidePanel/SidePanel.d.ts +144 -2
  52. package/es/components/SidePanel/SidePanel.js +57 -48
  53. package/es/components/StatusIcon/StatusIcon.d.ts +34 -2
  54. package/es/components/StatusIcon/StatusIcon.js +97 -95
  55. package/es/components/TruncatedList/TruncatedList.js +5 -3
  56. package/es/components/UserAvatar/UserAvatar.js +3 -2
  57. package/es/components/index.d.ts +2 -1
  58. package/es/global/js/package-settings.d.ts +5 -0
  59. package/es/global/js/package-settings.js +5 -0
  60. package/es/index.js +5 -0
  61. package/es/settings.d.ts +5 -0
  62. package/lib/components/CreateSidePanel/CreateSidePanel.d.ts +81 -2
  63. package/lib/components/CreateSidePanel/CreateSidePanel.js +5 -2
  64. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +5 -117
  65. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +12 -111
  66. package/lib/components/DataSpreadsheet/utils/commonEventHandlers.d.ts +4 -0
  67. package/lib/components/DataSpreadsheet/utils/commonEventHandlers.js +311 -0
  68. package/lib/components/Datagrid/Datagrid/DatagridContent.js +2 -1
  69. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +4 -1
  70. package/lib/components/Datagrid/Datagrid/DatagridRefBody.js +3 -1
  71. package/lib/components/Datagrid/Datagrid/DatagridSimpleBody.js +4 -1
  72. package/lib/components/Datagrid/Datagrid/DatagridVirtualBody.js +5 -1
  73. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.d.ts +1 -1
  74. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +4 -0
  75. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.d.ts +2 -1
  76. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +4 -3
  77. package/lib/components/EditSidePanel/EditSidePanel.d.ts +92 -2
  78. package/lib/components/EditSidePanel/EditSidePanel.js +8 -10
  79. package/lib/components/FilterPanel/FilterPanelAccordion/FilterPanelAccordion.d.ts +5 -0
  80. package/lib/components/FilterPanel/FilterPanelAccordion/FilterPanelAccordion.js +90 -0
  81. package/lib/components/FilterPanel/FilterPanelAccordionItem/FilterPanelAccordionItem.d.ts +5 -0
  82. package/lib/components/FilterPanel/FilterPanelAccordionItem/FilterPanelAccordionItem.js +101 -0
  83. package/lib/components/FilterPanel/FilterPanelCheckbox/FilterPanelCheckbox.js +3 -1
  84. package/lib/components/FilterPanel/FilterPanelCheckbox/index.d.ts +1 -0
  85. package/lib/components/FilterPanel/FilterPanelCheckboxWithOverflow/FilterPanelCheckboxWithOverflow.d.ts +10 -0
  86. package/lib/components/FilterPanel/FilterPanelCheckboxWithOverflow/FilterPanelCheckboxWithOverflow.js +164 -0
  87. package/lib/components/FilterPanel/FilterPanelGroup/FilterPanelGroup.d.ts +5 -0
  88. package/lib/components/FilterPanel/FilterPanelGroup/FilterPanelGroup.js +79 -0
  89. package/lib/components/FilterPanel/FilterPanelLabel/FilterPanelLabel.js +2 -2
  90. package/lib/components/FilterPanel/index.d.ts +4 -0
  91. package/lib/components/OptionsTile/OptionsTile.d.ts +77 -3
  92. package/lib/components/OptionsTile/OptionsTile.js +9 -20
  93. package/lib/components/RemoveModal/RemoveModal.d.ts +81 -7
  94. package/lib/components/RemoveModal/RemoveModal.js +1 -0
  95. package/lib/components/ScrollGradient/ScrollGradient.d.ts +5 -0
  96. package/lib/components/ScrollGradient/ScrollGradient.js +163 -0
  97. package/lib/components/ScrollGradient/constants.d.ts +15 -0
  98. package/lib/components/ScrollGradient/constants.js +128 -0
  99. package/lib/components/ScrollGradient/index.d.ts +1 -0
  100. package/lib/components/SidePanel/SidePanel.d.ts +144 -2
  101. package/lib/components/SidePanel/SidePanel.js +57 -48
  102. package/lib/components/StatusIcon/StatusIcon.d.ts +34 -2
  103. package/lib/components/StatusIcon/StatusIcon.js +97 -95
  104. package/lib/components/TruncatedList/TruncatedList.js +5 -3
  105. package/lib/components/UserAvatar/UserAvatar.js +3 -2
  106. package/lib/components/index.d.ts +2 -1
  107. package/lib/global/js/package-settings.d.ts +5 -0
  108. package/lib/global/js/package-settings.js +5 -0
  109. package/lib/index.js +25 -0
  110. package/lib/settings.d.ts +5 -0
  111. package/package.json +3 -3
  112. package/scss/components/FilterPanel/_filter-panel-accordion-item.scss +56 -0
  113. package/scss/components/FilterPanel/_filter-panel-accordion.scss +6 -0
  114. package/scss/components/FilterPanel/_filter-panel-checkbox-with-overflow.scss +62 -0
  115. package/scss/components/FilterPanel/_filter-panel-checkbox.scss +25 -3
  116. package/scss/components/FilterPanel/_filter-panel-group.scss +39 -0
  117. package/scss/components/FilterPanel/_filter-panel-label.scss +0 -8
  118. package/scss/components/FilterPanel/_filter-panel.scss +2 -0
  119. package/scss/components/FilterPanel/_index-with-carbon.scss +4 -0
  120. package/scss/components/FilterPanel/_index.scss +4 -0
  121. package/scss/components/ScrollGradient/_carbon-imports.scss +9 -0
  122. package/scss/components/ScrollGradient/_index-with-carbon.scss +9 -0
  123. package/scss/components/ScrollGradient/_index.scss +8 -0
  124. package/scss/components/ScrollGradient/_scroll-gradient.scss +102 -0
  125. package/scss/components/UserAvatar/_user-avatar.scss +37 -4
  126. package/scss/components/_index-with-carbon.scss +1 -0
  127. package/scss/components/_index.scss +1 -0
@@ -1,5 +1,84 @@
1
+ /**
2
+ * Copyright IBM Corp. 2021, 2024
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 React, { ReactNode } from 'react';
8
+ interface CreateSidePanelProps {
9
+ /**
10
+ * Provide an optional class to be applied to the containing node.
11
+ */
12
+ className?: string;
13
+ /**
14
+ * The description of the CreateSidePanel serves to provide more information about the form within the panel.
15
+ */
16
+ description?: ReactNode;
17
+ /**
18
+ * Specifies a boolean for disabling or enabling the primary button. This is important for form validation
19
+ * Returning `true` prevents the primary button from being clicked until required fields are completed.
20
+ */
21
+ disableSubmit?: boolean;
22
+ /**
23
+ * Specifies an optional field that provides a additional context for a form
24
+ */
25
+ formDescription?: ReactNode;
26
+ /**
27
+ * Specifies a required field that provides a title for a form
28
+ */
29
+ formTitle: ReactNode;
30
+ /**
31
+ * Unique identifier
32
+ */
33
+ id?: string;
34
+ /**
35
+ * Specifies an optional handler which is called when the CreateSidePanel
36
+ * is closed.
37
+ */
38
+ onRequestClose?(): void;
39
+ /**
40
+ * Specifies an optional handler which is called when the CreateSidePanel
41
+ * primary button is pressed.
42
+ */
43
+ onRequestSubmit?(): void;
44
+ /**
45
+ * Specifies whether the CreateSidePanel is open or not.
46
+ */
47
+ open: boolean;
48
+ /**
49
+ * Specifies the primary button's text in the modal.
50
+ */
51
+ primaryButtonText: string;
52
+ /**
53
+ * Specifies the secondary button's text in the modal.
54
+ */
55
+ secondaryButtonText: string;
56
+ /**
57
+ * This is the selector to the element that contains all of the page content that will shrink when the panel is a slide in.
58
+ * This prop is required since create flows use the `slideIn` variant of the side panel.
59
+ */
60
+ selectorPageContent: string;
61
+ /**
62
+ * Specifies which DOM element in the form should be focused.
63
+ */
64
+ selectorPrimaryFocus: string;
65
+ /**
66
+ * **Experimental:** Provide a `Slug` component to be rendered inside the `SidePanel` component
67
+ */
68
+ slug?: ReactNode;
69
+ /**
70
+ * The subtitle of the CreateSidePanel is optional and serves to provide more information about the modal.
71
+ */
72
+ subtitle?: ReactNode;
73
+ /**
74
+ * The title of the CreateSidePanel is usually the product or service name.
75
+ */
76
+ title: string;
77
+ }
1
78
  /**
2
79
  * Use with medium complexity creations if the user needs page context. On-page content can be seen and interacted with.
3
80
  */
4
- export let CreateSidePanel: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
5
- import React from 'react';
81
+ export declare let CreateSidePanel: React.ForwardRefExoticComponent<CreateSidePanelProps & {
82
+ children?: React.ReactNode;
83
+ } & React.RefAttributes<HTMLDivElement>>;
84
+ export {};
@@ -47,7 +47,7 @@ var CreateSidePanel = /*#__PURE__*/React__default.forwardRef(function (_ref, ref
47
47
  label: primaryButtonText,
48
48
  onClick: function onClick(event) {
49
49
  event.preventDefault();
50
- onRequestSubmit();
50
+ onRequestSubmit === null || onRequestSubmit === void 0 || onRequestSubmit();
51
51
  },
52
52
  kind: 'primary',
53
53
  disabled: disableSubmit,
@@ -90,6 +90,7 @@ CreateSidePanel.propTypes = {
90
90
  /**
91
91
  * Sets the body content of the create side panel
92
92
  */
93
+ /**@ts-ignore*/
93
94
  children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
94
95
  /**
95
96
  * Provide an optional class to be applied to the containing node.
@@ -129,6 +130,7 @@ CreateSidePanel.propTypes = {
129
130
  /**
130
131
  * Specifies whether the CreateSidePanel is open or not.
131
132
  */
133
+ /**@ts-ignore*/
132
134
  open: PropTypes.bool,
133
135
  /**
134
136
  * Specifies the primary button's text in the modal.
@@ -146,6 +148,7 @@ CreateSidePanel.propTypes = {
146
148
  /**
147
149
  * Specifies which DOM element in the form should be focused.
148
150
  */
151
+ /**@ts-ignore*/
149
152
  selectorPrimaryFocus: PropTypes.node.isRequired,
150
153
  /**
151
154
  * **Experimental:** Provide a `Slug` component to be rendered inside the `SidePanel` component
@@ -158,7 +161,7 @@ CreateSidePanel.propTypes = {
158
161
  /**
159
162
  * The title of the CreateSidePanel is usually the product or service name.
160
163
  */
161
- title: PropTypes.node.isRequired
164
+ title: PropTypes.string.isRequired
162
165
  };
163
166
 
164
167
  export { CreateSidePanel };
@@ -19,14 +19,11 @@ import uuidv4 from '../../global/js/utils/uuidv4.js';
19
19
  import { deepCloneObject } from '../../global/js/utils/deepCloneObject.js';
20
20
  import { createActiveCellFn } from './utils/createActiveCellFn.js';
21
21
  import { getCellSize } from './utils/getCellSize.js';
22
- import { includesShift, handleMultipleKeys, includesResourceKey } from './utils/handleMultipleKeys.js';
23
22
  import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection.js';
24
23
  import { removeCellSelections } from './utils/removeCellSelections.js';
25
24
  import { selectAllCells } from './utils/selectAllCells.js';
26
25
  import { handleEditSubmit } from './utils/handleEditSubmit.js';
27
- import { handleActiveCellInSelectionEnter } from './utils/handleActiveCellInSelectionEnter.js';
28
- import { handleActiveCellInSelectionTab } from './utils/handleActiveCellInSelectionTab.js';
29
- import { handleCellDeletion } from './utils/handleCellDeletion.js';
26
+ import { handleKeyPress } from './utils/commonEventHandlers.js';
30
27
  import { useActiveElement } from '../../global/js/hooks/useActiveElement.js';
31
28
  import { usePreviousValue } from '../../global/js/hooks/usePreviousValue.js';
32
29
  import { useMultipleKeyTracking } from './hooks/useMultipleKeyTracking.js';
@@ -36,7 +33,6 @@ import { useMoveActiveCell } from './hooks/useMoveActiveCell.js';
36
33
  import { useSpreadsheetEdit } from './hooks/useSpreadsheetEdit.js';
37
34
 
38
35
  var _excluded = ["cellSize", "className", "columns", "data", "defaultEmptyRowCount", "onDataUpdate", "id", "onActiveCellChange", "onSelectionAreaChange", "selectAllAriaLabel", "spreadsheetAriaLabel", "theme", "totalVisibleColumns"];
39
- // cspell:words rowcount colcount
40
36
 
41
37
  // The block part of our conventional BEM class names (blockClass__E--M).
42
38
  var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
@@ -404,117 +400,8 @@ var DataSpreadsheet = /*#__PURE__*/React__default.forwardRef(function (_ref, ref
404
400
  });
405
401
  }
406
402
  }, [handleInitialArrowPress, updateActiveCellCoordinates, activeCellCoordinates, columns, rows]);
407
- var handleKeyPress = useCallback(function (event) {
408
- var key = event.key;
409
- // Command keys need to be returned as there is default browser behavior with these keys
410
- // Needs to be returned in editing mode
411
- if (checkForReturnCondition(key)) {
412
- return;
413
- }
414
-
415
- // Clear out all cell selection areas if user uses any arrow key, except if the shift key is being held
416
- if (['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'].indexOf(key) > -1) {
417
- if (selectionAreas !== null && selectionAreas !== void 0 && selectionAreas.length && keysPressedList.length < 2 && !includesShift(keysPressedList)) {
418
- setSelectionAreas([]);
419
- setSelectionAreaData([]);
420
- removeCellSelections({
421
- spreadsheetRef: spreadsheetRef
422
- });
423
- }
424
- }
425
- if ((keysPressedList === null || keysPressedList === void 0 ? void 0 : keysPressedList.length) > 1) {
426
- handleMultipleKeys({
427
- activeCellCoordinates: activeCellCoordinates,
428
- event: event,
429
- keysPressedList: keysPressedList,
430
- selectionAreas: selectionAreas,
431
- currentMatcher: currentMatcher,
432
- rows: rows,
433
- setSelectionAreas: setSelectionAreas,
434
- columns: columns,
435
- updateActiveCellCoordinates: updateActiveCellCoordinates,
436
- spreadsheetRef: spreadsheetRef,
437
- removeCellSelections: removeCellSelections,
438
- blockClass: blockClass,
439
- setCurrentMatcher: setCurrentMatcher,
440
- usingMac: usingMac
441
- });
442
- }
443
-
444
- // Allow arrow key navigation if there are less than two activeKeys OR
445
- // if one of the activeCellCoordinates is in a header position
446
- // Prevent arrow keys, home key, and end key from scrolling the page when the data spreadsheet container has focus
447
-
448
- if (keysPressedList.length < 2 && !includesShift(keysPressedList) || activeCellCoordinates.row === 'header' || activeCellCoordinates.column === 'header') {
449
- switch (key) {
450
- case 'Backspace':
451
- case 'Delete':
452
- {
453
- var deleteParams = {
454
- selectionAreas: selectionAreas,
455
- currentMatcher: currentMatcher,
456
- rows: rows,
457
- setActiveCellContent: setActiveCellContent,
458
- updateData: updateData,
459
- activeCellCoordinates: activeCellCoordinates
460
- };
461
- handleCellDeletion(deleteParams);
462
- break;
463
- }
464
- // Enter
465
- case 'Enter':
466
- {
467
- handleActiveCellInSelectionEnter({
468
- activeCellInsideSelectionArea: activeCellInsideSelectionArea,
469
- activeCellCoordinates: activeCellCoordinates,
470
- activeCellRef: activeCellRef,
471
- selectionAreas: selectionAreas,
472
- updateActiveCellCoordinates: updateActiveCellCoordinates
473
- });
474
- break;
475
- }
476
- // HOME
477
- case 'Home':
478
- case 'End':
479
- {
480
- event.preventDefault();
481
- if (includesResourceKey(keysPressedList, usingMac)) {
482
- return;
483
- }
484
- handleHomeEndKey({
485
- type: key
486
- });
487
- break;
488
- }
489
- // Tab
490
- case 'Tab':
491
- {
492
- if (activeCellInsideSelectionArea) {
493
- event.preventDefault();
494
- return handleActiveCellInSelectionTab({
495
- activeCellInsideSelectionArea: activeCellInsideSelectionArea,
496
- activeCellCoordinates: activeCellCoordinates,
497
- activeCellRef: activeCellRef,
498
- selectionAreas: selectionAreas,
499
- updateActiveCellCoordinates: updateActiveCellCoordinates
500
- });
501
- }
502
- setSelectionAreas([]);
503
- removeActiveCell();
504
- removeCellEditor();
505
- setContainerHasFocus(false);
506
- setActiveCellCoordinates(null);
507
- break;
508
- }
509
- case 'ArrowLeft':
510
- case 'ArrowUp':
511
- case 'ArrowRight':
512
- case 'ArrowDown':
513
- {
514
- handleArrowKeyPress(key);
515
- }
516
- }
517
- }
403
+ var handleKeyPressEvent = useCallback(function (event) {
404
+ handleKeyPress(event, activeCellInsideSelectionArea, updateActiveCellCoordinates, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList, usingMac, updateData, checkForReturnCondition, handleArrowKeyPress, setSelectionAreas, setSelectionAreaData, setCurrentMatcher, activeCellRef, setActiveCellCoordinates, setContainerHasFocus, setActiveCellContent);
518
405
  }, [activeCellInsideSelectionArea, updateActiveCellCoordinates, activeCellCoordinates, removeActiveCell, columns, rows, spreadsheetRef, currentMatcher, removeCellEditor, selectionAreas, handleHomeEndKey, keysPressedList, usingMac, updateData, checkForReturnCondition, handleArrowKeyPress]);
519
406
  var startEditMode = function startEditMode() {
520
407
  setIsEditing(true);
@@ -678,6 +565,7 @@ var DataSpreadsheet = /*#__PURE__*/React__default.forwardRef(function (_ref, ref
678
565
  var handleActiveCellMouseEnter = useCallback(function () {
679
566
  handleActiveCellMouseEnterCallback(selectionAreas, clickAndHoldActive);
680
567
  }, [clickAndHoldActive, selectionAreas, handleActiveCellMouseEnterCallback]);
568
+ // cspell:words rowcount colcount
681
569
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, getTableProps(), getDevtoolsProps(componentName), {
682
570
  className: cx(blockClass, className, "".concat(blockClass, "--interactive-cell-element"), _defineProperty(_defineProperty({}, "".concat(blockClass, "__container-has-focus"), containerHasFocus), "".concat(blockClass, "__").concat(theme), theme === 'dark')),
683
571
  ref: spreadsheetRef,
@@ -686,7 +574,7 @@ var DataSpreadsheet = /*#__PURE__*/React__default.forwardRef(function (_ref, ref
686
574
  "aria-rowcount": (rows === null || rows === void 0 ? void 0 : rows.length) || 0,
687
575
  "aria-colcount": (columns === null || columns === void 0 ? void 0 : columns.length) || 0,
688
576
  "aria-label": spreadsheetAriaLabel,
689
- onKeyDown: handleKeyPress,
577
+ onKeyDown: handleKeyPressEvent,
690
578
  onFocus: function onFocus() {
691
579
  return setContainerHasFocus(true);
692
580
  }
@@ -13,14 +13,12 @@ import cx from 'classnames';
13
13
  import { px } from '@carbon/layout';
14
14
  import { pkg } from '../../settings.js';
15
15
  import { deepCloneObject } from '../../global/js/utils/deepCloneObject.js';
16
- import uuidv4 from '../../global/js/utils/uuidv4.js';
17
16
  import { removeCellSelections } from './utils/removeCellSelections.js';
18
17
  import { createCellSelectionArea } from './utils/createCellSelectionArea.js';
19
18
  import { checkActiveHeaderCell } from './utils/checkActiveHeaderCell.js';
20
19
  import { checkSelectedHeaderCell } from './utils/checkSelectedHeaderCell.js';
21
- import { handleHeaderCellSelection } from './utils/handleHeaderCellSelection.js';
22
20
  import { getSpreadsheetWidth } from './utils/getSpreadsheetWidth.js';
23
- import { checkForHoldingKey } from './utils/checkForHoldingKey.js';
21
+ import { handleBodyCellClick, handleBodyCellHover, handleRowHeaderClick } from './utils/commonEventHandlers.js';
24
22
  import { usePreviousValue } from '../../global/js/hooks/usePreviousValue.js';
25
23
  import { useSpreadsheetMouseUp } from './hooks/useSpreadsheetMouseUp.js';
26
24
 
@@ -241,71 +239,10 @@ var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
241
239
 
242
240
  // onClick fn for each cell in the data spreadsheet body,
243
241
  // adds the active cell highlight
244
- var handleBodyCellClick = useCallback(function (cell, columnIndex) {
245
- return function (event) {
246
- event.preventDefault();
247
- var closestBodyCell = event.target.closest(".".concat(blockClass, "__body--td"));
248
- var isValidSelectionAreaStart = closestBodyCell.classList.contains("".concat(blockClass, "__body--td"));
249
- setValidStartingPoint(isValidSelectionAreaStart);
250
- var isHoldingCommandKey = checkForHoldingKey(event, 'cmd');
251
- var isHoldingShiftKey = checkForHoldingKey(event, 'shiftKey');
252
- setContainerHasFocus(true);
253
- var activeCoordinates = {
254
- row: cell.row.index,
255
- column: columnIndex
256
- };
257
- var tempMatcher = uuidv4();
258
- setClickAndHoldActive(true);
259
242
 
260
- // prevent multiple selections unless cmd key is held
261
- // meaning that selectionAreas should only have one item by default
262
- if (isHoldingCommandKey) {
263
- var activeCellElement = ref.current.querySelector(".".concat(blockClass, "__active-cell--highlight"));
264
- activeCellElement.setAttribute('data-selection-id', tempMatcher);
265
- setActiveCellInsideSelectionArea(true);
266
- setActiveCellCoordinates(activeCoordinates);
267
- setCurrentMatcher(tempMatcher);
268
- setSelectionAreas(function (prev) {
269
- return [].concat(_toConsumableArray(prev), [{
270
- point1: activeCoordinates,
271
- matcher: tempMatcher
272
- }]);
273
- });
274
- } else if (isHoldingShiftKey) {
275
- setContainerHasFocus(true);
276
- var selectionAreaClone = deepCloneObject(selectionAreas);
277
- var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
278
- return item.matcher === currentMatcher;
279
- });
280
- if (indexOfItemToUpdate === -1) {
281
- // There is always a selectionArea with a point1 object that updates
282
- // whenever the activeCellCoordinates update, we should always be able
283
- // to find an index, but if we do not for some reason we should return
284
- // at this point.
285
- return;
286
- } else {
287
- // Update the selectionArea that was found, do not update currentMatcher
288
- selectionAreaClone[indexOfItemToUpdate].point1 = activeCellCoordinates;
289
- selectionAreaClone[indexOfItemToUpdate].point2 = activeCoordinates;
290
- selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
291
- selectionAreaClone[indexOfItemToUpdate].matcher = currentMatcher;
292
- setSelectionAreas(selectionAreaClone);
293
- }
294
- } else {
295
- activeCellRef.current.style.display = 'none';
296
- setActiveCellInsideSelectionArea(false);
297
- setActiveCellCoordinates(activeCoordinates);
298
- // remove all previous cell selections
299
- removeCellSelections({
300
- spreadsheetRef: ref
301
- });
302
- setSelectionAreas([{
303
- point1: activeCoordinates,
304
- matcher: tempMatcher
305
- }]);
306
- setCurrentMatcher(tempMatcher);
307
- setSelectionAreaData([]);
308
- }
243
+ var handleBodyCellClickEvent = useCallback(function (cell, columnIndex) {
244
+ return function (event) {
245
+ handleBodyCellClick(cell, columnIndex, event, currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea, activeCellRef, setValidStartingPoint);
309
246
  };
310
247
  }, [currentMatcher, activeCellCoordinates, selectionAreas, setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher, ref, setSelectionAreaData, setActiveCellInsideSelectionArea, activeCellRef]);
311
248
  var handleBodyScroll = function handleBodyScroll() {
@@ -321,50 +258,14 @@ var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
321
258
  contentScrollElementRef.removeEventListener('scroll', handleBodyScroll);
322
259
  };
323
260
  });
324
- var handleBodyCellHover = useCallback(function (cell, columnIndex) {
261
+ var handleBodyCellHoverEvent = useCallback(function (cell, columnIndex) {
325
262
  return function () {
326
- if (clickAndHoldActive) {
327
- var cellCoordinates = {
328
- row: cell.row.index,
329
- column: columnIndex
330
- };
331
- setSelectionAreas(function (prev) {
332
- var _selectionAreaClone$i, _selectionAreaClone$i2;
333
- var selectionAreaClone = deepCloneObject(prev);
334
- var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
335
- return item.matcher === currentMatcher;
336
- });
337
- // No items in the array match up with the currentMatcher value
338
- if (indexOfItemToUpdate === -1) {
339
- return prev;
340
- }
341
- // Do not update state if you're still hovering on the same cell
342
- if (((_selectionAreaClone$i = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i === void 0 ? void 0 : _selectionAreaClone$i.row) === cellCoordinates.row && ((_selectionAreaClone$i2 = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i2 === void 0 ? void 0 : _selectionAreaClone$i2.column) === cellCoordinates.column) {
343
- return prev;
344
- }
345
- selectionAreaClone[indexOfItemToUpdate].point2 = cellCoordinates;
346
- selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
347
- return selectionAreaClone;
348
- });
349
- }
263
+ handleBodyCellHover(cell, columnIndex, clickAndHoldActive, currentMatcher, setSelectionAreas);
350
264
  };
351
265
  }, [clickAndHoldActive, currentMatcher, setSelectionAreas]);
352
- var handleRowHeaderClick = useCallback(function (index) {
266
+ var handleRowHeaderClickEvent = useCallback(function (index) {
353
267
  return function (event) {
354
- var isHoldingCommandKey = checkForHoldingKey(event, 'cmd');
355
- handleHeaderCellSelection({
356
- type: 'row',
357
- activeCellCoordinates: activeCellCoordinates,
358
- rows: rows,
359
- columns: columns,
360
- setActiveCellCoordinates: setActiveCellCoordinates,
361
- setCurrentMatcher: setCurrentMatcher,
362
- setSelectionAreas: setSelectionAreas,
363
- spreadsheetRef: ref,
364
- index: index,
365
- setSelectionAreaData: setSelectionAreaData,
366
- isHoldingCommandKey: isHoldingCommandKey
367
- });
268
+ handleRowHeaderClick(index, event, columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData);
368
269
  };
369
270
  }, [columns, ref, setSelectionAreas, setCurrentMatcher, setActiveCellCoordinates, activeCellCoordinates, rows, setSelectionAreaData]);
370
271
 
@@ -414,7 +315,7 @@ var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
414
315
  "data-row-index": index,
415
316
  "data-column-index": "header",
416
317
  type: "button",
417
- onClick: handleRowHeaderClick(index),
318
+ onClick: handleRowHeaderClickEvent(index),
418
319
  className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element"), _defineProperty(_defineProperty({}, "".concat(blockClass, "__td-th--active-header"), (activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row) === index || checkActiveHeaderCell(index, selectionAreas, 'row')), "".concat(blockClass, "__td-th--selected-header"), checkSelectedHeaderCell(index, selectionAreas, 'row', columns))),
419
320
  style: {
420
321
  width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
@@ -436,14 +337,14 @@ var DataSpreadsheetBody = /*#__PURE__*/forwardRef(function (_ref, ref) {
436
337
  "data-row-index": cell.row.index,
437
338
  "data-column-index": index,
438
339
  className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
439
- onMouseDown: handleBodyCellClick(cell, index),
440
- onMouseOver: handleBodyCellHover(cell, index),
340
+ onMouseDown: handleBodyCellClickEvent(cell, index),
341
+ onMouseOver: handleBodyCellHoverEvent(cell, index),
441
342
  onFocus: function onFocus() {},
442
343
  type: "button"
443
344
  }, cell.render('Cell')));
444
345
  }));
445
346
  }
446
- }, [prepareRow, rows, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClick, handleBodyCellClick, handleBodyCellHover, defaultColumn, columns]);
347
+ }, [prepareRow, rows, activeCellCoordinates === null || activeCellCoordinates === void 0 ? void 0 : activeCellCoordinates.row, selectionAreas, handleRowHeaderClickEvent, handleBodyCellClickEvent, handleBodyCellHoverEvent, defaultColumn, columns]);
447
348
  var spreadsheetBodyRef = useRef();
448
349
  return /*#__PURE__*/React__default.createElement("div", _extends({
449
350
  ref: spreadsheetBodyRef,
@@ -0,0 +1,4 @@
1
+ export function handleBodyCellClick(cell: any, columnIndex: any, event: any, ...rest: any[]): void;
2
+ export function handleBodyCellHover(cell: any, columnIndex: any, ...rest: any[]): void;
3
+ export function handleRowHeaderClick(index: any, event: any, ...rest: any[]): void;
4
+ export function handleKeyPress(event: any, ...rest: any[]): any;