@carbon/ibm-products 1.59.1 → 1.60.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. package/css/index-full-carbon.css +42 -21
  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 +42 -21
  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 +42 -21
  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/Datagrid/Datagrid/Datagrid.js +2 -1
  14. package/es/components/Datagrid/Datagrid/DatagridContent.js +7 -1
  15. package/es/components/Datagrid/Datagrid/DatagridEmptyBody.js +4 -4
  16. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +13 -1
  17. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +3 -15
  18. package/es/components/Datagrid/Datagrid/DraggableElement.js +32 -135
  19. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +14 -38
  20. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -0
  21. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +128 -40
  22. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +7 -6
  23. package/es/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +104 -18
  24. package/es/components/Datagrid/Datagrid/addons/Filtering/constants.js +1 -0
  25. package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +37 -4
  26. package/es/components/Datagrid/useFiltering.js +4 -1
  27. package/es/components/Datagrid/useNestedRowExpander.js +22 -9
  28. package/es/components/Datagrid/useRowExpander.js +22 -9
  29. package/es/components/Datagrid/utils/getArgTypes.js +12 -0
  30. package/es/components/EmptyStates/EmptyState.js +1 -1
  31. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -1
  32. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -1
  33. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -1
  34. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -1
  35. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -1
  36. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -1
  37. package/es/components/EmptyStates/assets/ErrorIllustration.js +6 -11
  38. package/es/components/EmptyStates/assets/NoDataIllustration.js +6 -11
  39. package/es/components/EmptyStates/assets/NoTagsIllustration.js +6 -12
  40. package/es/components/EmptyStates/assets/NotFoundIllustration.js +6 -12
  41. package/es/components/EmptyStates/assets/NotificationsIllustration.js +6 -12
  42. package/es/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -12
  43. package/es/components/FilterSummary/FilterSummary.js +9 -3
  44. package/es/components/TagSet/TagSet.js +3 -7
  45. package/es/global/js/hooks/useWindowScroll.js +5 -0
  46. package/lib/components/Datagrid/Datagrid/Datagrid.js +2 -1
  47. package/lib/components/Datagrid/Datagrid/DatagridContent.js +6 -0
  48. package/lib/components/Datagrid/Datagrid/DatagridEmptyBody.js +3 -3
  49. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +13 -1
  50. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +3 -15
  51. package/lib/components/Datagrid/Datagrid/DraggableElement.js +34 -140
  52. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +17 -38
  53. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsTearsheet.js +1 -0
  54. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/DraggableItemsList.js +128 -47
  55. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +7 -6
  56. package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterProvider.js +104 -24
  57. package/lib/components/Datagrid/Datagrid/addons/Filtering/constants.js +4 -2
  58. package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +36 -3
  59. package/lib/components/Datagrid/useFiltering.js +4 -1
  60. package/lib/components/Datagrid/useNestedRowExpander.js +24 -9
  61. package/lib/components/Datagrid/useRowExpander.js +24 -9
  62. package/lib/components/Datagrid/utils/getArgTypes.js +12 -0
  63. package/lib/components/EmptyStates/EmptyState.js +1 -1
  64. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +1 -1
  65. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +1 -1
  66. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +1 -1
  67. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +1 -1
  68. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +1 -1
  69. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +1 -1
  70. package/lib/components/EmptyStates/assets/ErrorIllustration.js +6 -11
  71. package/lib/components/EmptyStates/assets/NoDataIllustration.js +6 -11
  72. package/lib/components/EmptyStates/assets/NoTagsIllustration.js +6 -12
  73. package/lib/components/EmptyStates/assets/NotFoundIllustration.js +6 -12
  74. package/lib/components/EmptyStates/assets/NotificationsIllustration.js +6 -12
  75. package/lib/components/EmptyStates/assets/UnauthorizedIllustration.js +6 -12
  76. package/lib/components/FilterSummary/FilterSummary.js +9 -10
  77. package/lib/components/TagSet/TagSet.js +2 -6
  78. package/lib/global/js/hooks/useWindowScroll.js +6 -0
  79. package/package.json +6 -5
  80. package/scss/components/Datagrid/_datagrid.scss +1 -1
  81. package/scss/components/Datagrid/styles/_draggableElement.scss +44 -20
  82. package/scss/components/Datagrid/styles/addons/_CustomizeColumnsTearsheet.scss +0 -1
@@ -9,7 +9,7 @@ import _extends from "@babel/runtime/helpers/extends";
9
9
  import React from 'react';
10
10
  import { pkg } from '../../../settings';
11
11
  import { DataTable } from 'carbon-components-react';
12
- import { NoDataEmptyState, ErrorEmptyState, NotFoundEmptyState } from '../../EmptyStates';
12
+ import { NoDataEmptyState, ErrorEmptyState, NotFoundEmptyState, EmptyState } from '../../EmptyStates';
13
13
  var blockClass = "".concat(pkg.prefix, "--datagrid");
14
14
  var TableBody = DataTable.TableBody,
15
15
  TableRow = DataTable.TableRow,
@@ -33,13 +33,13 @@ var DatagridEmptyBody = function DatagridEmptyBody(datagridState) {
33
33
  action: emptyStateAction,
34
34
  link: emptyStateLink
35
35
  };
36
+ var validEmptyStates = ['error', 'noData', 'notFound'];
36
37
  return /*#__PURE__*/React.createElement(TableBody, _extends({}, getTableBodyProps({
37
38
  role: false
38
39
  }), {
39
40
  className: "".concat(blockClass, "__empty-state-body")
40
41
  }), /*#__PURE__*/React.createElement(TableRow, null, /*#__PURE__*/React.createElement(TableCell, {
41
- colSpan: headers.length,
42
- className: "".concat(blockClass, "__empty-state-cell")
43
- }, emptyStateType === 'error' && /*#__PURE__*/React.createElement(ErrorEmptyState, emptyStateProps), emptyStateType === 'noData' && /*#__PURE__*/React.createElement(NoDataEmptyState, emptyStateProps), emptyStateType === 'notFound' && /*#__PURE__*/React.createElement(NotFoundEmptyState, emptyStateProps))));
42
+ colSpan: headers.length
43
+ }, validEmptyStates.includes(emptyStateType) ? /*#__PURE__*/React.createElement(React.Fragment, null, emptyStateType === 'error' && /*#__PURE__*/React.createElement(ErrorEmptyState, emptyStateProps), emptyStateType === 'noData' && /*#__PURE__*/React.createElement(NoDataEmptyState, emptyStateProps), emptyStateType === 'notFound' && /*#__PURE__*/React.createElement(NotFoundEmptyState, emptyStateProps)) : /*#__PURE__*/React.createElement(EmptyState, emptyStateProps))));
44
44
  };
45
45
  export default DatagridEmptyBody;
@@ -50,11 +50,23 @@ var SelectAll = function SelectAll(datagridState) {
50
50
  var _getProps = getProps(),
51
51
  onChange = _getProps.onChange,
52
52
  selectProps = _objectWithoutProperties(_getProps, _excluded);
53
+ var _ref = selectProps || {},
54
+ indeterminate = _ref.indeterminate;
55
+ var handleSelectAllChange = function handleSelectAllChange(event) {
56
+ if (indeterminate) {
57
+ return onChange === null || onChange === void 0 ? void 0 : onChange({
58
+ target: {
59
+ checked: false
60
+ }
61
+ });
62
+ }
63
+ return onChange === null || onChange === void 0 ? void 0 : onChange(event);
64
+ };
53
65
  return /*#__PURE__*/React.createElement("div", {
54
66
  className: cx("".concat(blockClass, "__head-select-all"), "".concat(blockClass, "__checkbox-cell"), _defineProperty({}, "".concat(blockClass, "__checkbox-cell-sticky-left"), isFirstColumnStickyLeft && windowSize > 671))
55
67
  }, /*#__PURE__*/React.createElement(TableSelectAll, _extends({}, selectProps, {
56
68
  name: "".concat(tableId, "-select-all-checkbox-name"),
57
- onSelect: onChange,
69
+ onSelect: handleSelectAllChange,
58
70
  disabled: isFetching || selectProps.disabled,
59
71
  id: "".concat(tableId, "-select-all-checkbox-id")
60
72
  })));
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  /**
4
- * Copyright IBM Corp. 2022, 2022
4
+ * Copyright IBM Corp. 2022, 2023
5
5
  *
6
6
  * This source code is licensed under the Apache-2.0 license found in the
7
7
  * LICENSE file in the root directory of this source tree.
@@ -70,20 +70,8 @@ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridS
70
70
  menuOptionsClass: "".concat(blockClass, "__button-menu-options"),
71
71
  flipped: true
72
72
  }, toolbarBatchActions && toolbarBatchActions.map(function (batchAction, index) {
73
- if (index < 2) {
74
- if (displayAllInMenu) {
75
- return /*#__PURE__*/React.createElement(ButtonMenuItem, {
76
- key: "".concat(batchAction.label, "-").concat(index),
77
- itemText: batchAction.label,
78
- onClick: function onClick() {
79
- batchAction.onClick();
80
- if (batchAction.type === 'select_all') {
81
- toggleAllRowsSelected(true);
82
- }
83
- }
84
- });
85
- }
86
- return null;
73
+ if (index < 2 && !displayAllInMenu) {
74
+ return;
87
75
  }
88
76
  return /*#__PURE__*/React.createElement(ButtonMenuItem, {
89
77
  key: "".concat(batchAction.label, "-").concat(index),
@@ -1,5 +1,5 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  // @flow
4
4
  /*
5
5
  * Licensed Materials - Property of IBM
@@ -8,166 +8,63 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
8
8
  * US Government Users Restricted Rights - Use, duplication or disclosure
9
9
  * restricted by GSA ADP Schedule Contract with IBM Corp.
10
10
  */
11
- import * as React from 'react';
11
+ import React from 'react';
12
12
  import PropTypes from 'prop-types';
13
13
  import { Draggable16, Locked16 } from '@carbon/icons-react';
14
- import { useDrag, useDrop } from 'react-dnd';
15
14
  import cx from 'classnames';
16
15
  import { pkg } from '../../../settings';
17
- var useEffect = React.useEffect,
18
- useRef = React.useRef,
19
- useState = React.useState;
16
+ import { CSS } from '@dnd-kit/utilities';
17
+ import { useSortable } from '@dnd-kit/sortable';
20
18
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
- var DRAG_TYPE = "".concat(blockClass, "__shared-ui-draggable-element");
22
19
  var DraggableElement = function DraggableElement(_ref) {
23
20
  var _cx;
24
21
  var id = _ref.id,
25
- index = _ref.index,
26
- listData = _ref.listData,
27
22
  children = _ref.children,
28
- type = _ref.type,
23
+ classList = _ref.classList,
29
24
  disabled = _ref.disabled,
30
25
  ariaLabel = _ref.ariaLabel,
31
- onGrab = _ref.onGrab,
32
- onArrowKeyDown = _ref.onArrowKeyDown,
33
- isFocused = _ref.isFocused,
34
26
  isSticky = _ref.isSticky,
35
- moveElement = _ref.moveElement,
36
- selected = _ref.selected,
37
- _ref$positionLabel = _ref.positionLabel,
38
- positionLabel = _ref$positionLabel === void 0 ? 'Current position {index} of {total}' : _ref$positionLabel,
39
- _ref$grabbedLabel = _ref.grabbedLabel,
40
- grabbedLabel = _ref$grabbedLabel === void 0 ? '{itemName} grabbed.' : _ref$grabbedLabel,
41
- _ref$droppedLabel = _ref.droppedLabel,
42
- droppedLabel = _ref$droppedLabel === void 0 ? '{itemName} dropped.' : _ref$droppedLabel;
43
- var ref = useRef();
44
- var _useDrop = useDrop({
45
- accept: DRAG_TYPE + type,
46
- collect: function collect(monitor) {
47
- return {
48
- isOver: !!monitor.isOver()
49
- };
50
- },
51
- drop: function drop(item) {
52
- moveElement(item.index, index);
53
- },
54
- canDrop: function canDrop() {
55
- return !disabled;
56
- },
57
- hover: function hover(item) {
58
- var dragIndex = item.index;
59
- var hoverIndex = index;
60
- // Don't replace items with themselves
61
- if (dragIndex === hoverIndex || disabled) {
62
- return;
63
- }
64
- moveElement(dragIndex, hoverIndex);
65
- // Time to actually perform the action
66
- // Note: we're mutating the monitor item here!
67
- // Generally it's better to avoid mutations,
68
- // but it's good here for the sake of performance
69
- // to avoid expensive index searches.
70
- // eslint-disable-next-line no-param-reassign
71
- item.index = hoverIndex;
72
- }
27
+ selected = _ref.selected;
28
+ var _useSortable = useSortable({
29
+ id: id
73
30
  }),
74
- _useDrop2 = _slicedToArray(_useDrop, 2),
75
- isOver = _useDrop2[0].isOver,
76
- drop = _useDrop2[1];
77
- var _useDrag = useDrag({
78
- type: DRAG_TYPE + type,
79
- item: {
80
- id: id,
81
- index: index
82
- },
83
- canDrag: function canDrag() {
84
- return !disabled;
85
- },
86
- collect: function collect(monitor) {
87
- return {
88
- isDragging: monitor.isDragging()
89
- };
90
- }
91
- }),
92
- _useDrag2 = _slicedToArray(_useDrag, 3),
93
- isDragging = _useDrag2[0].isDragging,
94
- drag = _useDrag2[1],
95
- preview = _useDrag2[2];
96
- useEffect(function () {
97
- if (isFocused && ref && ref.current) {
98
- ref.current.focus();
99
- }
100
- }, [isFocused]);
101
- var _useState = useState(false),
102
- _useState2 = _slicedToArray(_useState, 2),
103
- isGrabbed = _useState2[0],
104
- setIsGrabbed = _useState2[1];
105
- var _useState3 = useState(isFocused),
106
- _useState4 = _slicedToArray(_useState3, 2),
107
- isFocusedOnItem = _useState4[0],
108
- setIsFocusedOnItem = _useState4[1];
109
- drop(ref);
31
+ attributes = _useSortable.attributes,
32
+ isDragging = _useSortable.isDragging,
33
+ listeners = _useSortable.listeners,
34
+ setNodeRef = _useSortable.setNodeRef,
35
+ transform = _useSortable.transform,
36
+ transition = _useSortable.transition;
110
37
  var content = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
111
38
  className: cx({
112
39
  disabled: disabled
113
40
  }, "".concat(blockClass, "__draggable-handleStyle"))
114
41
  }, isSticky ? /*#__PURE__*/React.createElement(Locked16, null) : /*#__PURE__*/React.createElement(Draggable16, null)), children);
115
- return /*#__PURE__*/React.createElement("li", {
116
- className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-isOver"), isOver && !disabled), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-grabbed"), isGrabbed), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--sticky"), isSticky), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder"), !selected), _cx)),
117
- ref: ref,
118
- "aria-selected": isFocused,
119
- role: "option",
120
- tabIndex: isFocused ? 0 : -1,
121
- onKeyPress: function onKeyPress(e) {
122
- if (e.key === ' ' && e.target === e.currentTarget && !disabled) {
123
- var positionText = positionLabel.replace('{index}', index + 1).replace('{total}', listData.length);
124
- var grabAriaText = (isGrabbed ? droppedLabel : grabbedLabel).replace('{itemName}', ariaLabel);
125
- onGrab(grabAriaText + positionText);
126
- setIsGrabbed(!isGrabbed);
127
- e.preventDefault();
128
- }
129
- },
130
- onKeyDown: function onKeyDown(e) {
131
- if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
132
- onArrowKeyDown(e, isGrabbed, index);
133
- }
134
- },
135
- onBlur: function onBlur(e) {
136
- // handle when focus move to inner elements
137
- setIsFocusedOnItem(e.currentTarget === e.target);
138
- },
139
- onFocus: function onFocus(e) {
140
- // handle when focus move to li element
141
- setIsFocusedOnItem(e.currentTarget === e.target);
142
- }
143
- }, /*#__PURE__*/React.createElement("span", {
42
+ var style = {
43
+ transform: CSS.Transform.toString(transform),
44
+ transition: transition
45
+ };
46
+ return /*#__PURE__*/React.createElement("li", _extends({
47
+ className: cx(classList, "".concat(blockClass, "__draggable-handleHolder"), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--sticky"), isSticky), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder--dragging"), isDragging), _cx)),
48
+ id: id,
49
+ ref: setNodeRef,
50
+ style: style
51
+ }, attributes, listeners, {
52
+ disabled: disabled,
53
+ "aria-selected": selected,
54
+ role: "option"
55
+ }), /*#__PURE__*/React.createElement("span", {
144
56
  className: "".concat(blockClass, "__shared-ui--assistive-text")
145
- }, ariaLabel), isDragging && !isOver ? /*#__PURE__*/React.createElement("div", {
146
- ref: preview,
147
- className: "".concat(blockClass, "__draggable-handleHolder-droppable ").concat(blockClass, "__draggable-handleHolder-droppable--origin")
148
- }, content) : /*#__PURE__*/React.createElement("div", {
149
- ref: drag,
150
- "aria-hidden": isFocused && isFocusedOnItem // if focus on li, hide the children from aria
151
- ,
57
+ }, ariaLabel), /*#__PURE__*/React.createElement("div", {
152
58
  className: cx(_defineProperty({}, "".concat(blockClass, "__draggable-handleStyle"), !disabled), ["".concat(blockClass, "__draggable-handleHolder-droppable")])
153
- }, (!isOver || disabled) && content));
59
+ }, content));
154
60
  };
155
61
  DraggableElement.propTypes = {
156
62
  ariaLabel: PropTypes.string.isRequired,
157
63
  children: PropTypes.element.isRequired,
64
+ classList: PropTypes.string,
158
65
  disabled: PropTypes.bool,
159
- droppedLabel: PropTypes.string,
160
- grabbedLabel: PropTypes.string,
161
66
  id: PropTypes.string.isRequired,
162
- index: PropTypes.number.isRequired,
163
- isFocused: PropTypes.bool.isRequired,
164
67
  isSticky: PropTypes.bool,
165
- listData: PropTypes.array.isRequired,
166
- moveElement: PropTypes.func.isRequired,
167
- onArrowKeyDown: PropTypes.func.isRequired,
168
- onGrab: PropTypes.func.isRequired,
169
- positionLabel: PropTypes.string,
170
- selected: PropTypes.bool,
171
- type: PropTypes.string.isRequired
68
+ selected: PropTypes.bool
172
69
  };
173
70
  export default DraggableElement;
@@ -1,32 +1,21 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  /**
4
- * Copyright IBM Corp. 2022, 2022
4
+ * Copyright IBM Corp. 2022, 2023
5
5
  *
6
6
  * This source code is licensed under the Apache-2.0 license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
 
10
- import React from 'react';
10
+ import React, { useRef } from 'react';
11
11
  import PropTypes from 'prop-types';
12
- import { DndProvider } from 'react-dnd';
13
- import { HTML5Backend } from 'react-dnd-html5-backend';
14
12
  import { Checkbox } from 'carbon-components-react';
15
13
  import update from 'immutability-helper';
16
14
  import { pkg } from '../../../../../settings';
17
15
  import classNames from 'classnames';
18
16
  import { DraggableItemsList } from './DraggableItemsList';
17
+ import uuidv4 from '../../../../../global/js/utils/uuidv4';
19
18
  var blockClass = "".concat(pkg.prefix, "--datagrid");
20
- var getNextIndex = function getNextIndex(array, currentIndex, key) {
21
- var newIndex = -1;
22
- if (key === 'ArrowUp') {
23
- newIndex = currentIndex - 1 >= 0 ? currentIndex - 1 : array.length - 1;
24
- }
25
- if (key === 'ArrowDown') {
26
- newIndex = currentIndex + 1 < array.length ? currentIndex + 1 : 0;
27
- }
28
- return newIndex;
29
- };
30
19
  var Columns = function Columns(_ref) {
31
20
  var getVisibleColumnsCount = _ref.getVisibleColumnsCount,
32
21
  filterString = _ref.filterString,
@@ -36,36 +25,26 @@ var Columns = function Columns(_ref) {
36
25
  assistiveTextInstructionsLabel = _ref.assistiveTextInstructionsLabel,
37
26
  assistiveTextDisabledInstructionsLabel = _ref.assistiveTextDisabledInstructionsLabel,
38
27
  selectAllLabel = _ref.selectAllLabel;
28
+ var listId = useRef(uuidv4()); // keep id between renders
29
+ var listRef = useRef(null);
39
30
  var _React$useState = React.useState(''),
40
31
  _React$useState2 = _slicedToArray(_React$useState, 2),
41
32
  ariaRegionText = _React$useState2[0],
42
33
  setAriaRegionText = _React$useState2[1];
43
- var _React$useState3 = React.useState(-1),
44
- _React$useState4 = _slicedToArray(_React$useState3, 2),
45
- focusIndex = _React$useState4[0],
46
- setFocusIndex = _React$useState4[1];
47
- var moveElement = React.useCallback(function (dragIndex, hoverIndex) {
48
- var dragCard = columns[dragIndex];
34
+ // after a drag/drop action set the columns
35
+ var moveElement = React.useCallback(function (from, to) {
36
+ var fromCol = columns[from];
49
37
  setColumnsObject(update(columns, {
50
- $splice: [[dragIndex, 1], [hoverIndex, 0, dragCard]]
38
+ $splice: [[from, 1], [to, 0, fromCol]]
51
39
  }));
52
40
  }, [columns, setColumnsObject]);
53
41
  return /*#__PURE__*/React.createElement("div", {
54
- className: "".concat(blockClass, "__customize-columns-column-list")
55
- }, /*#__PURE__*/React.createElement(DndProvider, {
56
- backend: HTML5Backend
42
+ className: "".concat(blockClass, "__customize-columns-column-list"),
43
+ ref: listRef
57
44
  }, /*#__PURE__*/React.createElement("ol", {
58
45
  className: "".concat(blockClass, "__customize-columns-column-list--focus"),
59
46
  role: "listbox",
60
47
  "aria-describedby": "".concat(blockClass, "__customize-columns--instructions"),
61
- onKeyDown: function onKeyDown(e) {
62
- var nextIndex = getNextIndex(columns, focusIndex, e.key);
63
- if (nextIndex >= 0) {
64
- setFocusIndex(nextIndex);
65
- e.preventDefault();
66
- e.stopPropagation();
67
- }
68
- },
69
48
  tabIndex: 0
70
49
  }, /*#__PURE__*/React.createElement("span", {
71
50
  "aria-live": "assertive",
@@ -87,16 +66,13 @@ var Columns = function Columns(_ref) {
87
66
  id: "".concat(blockClass, "__customization-column-select-all"),
88
67
  labelText: selectAllLabel
89
68
  })), /*#__PURE__*/React.createElement(DraggableItemsList, {
69
+ id: listId.current,
90
70
  columns: columns,
91
71
  filterString: filterString,
92
- focusIndex: focusIndex,
93
- getNextIndex: getNextIndex,
94
72
  moveElement: moveElement,
95
- onSelectColumn: onSelectColumn,
96
73
  setAriaRegionText: setAriaRegionText,
97
- setColumnsObject: setColumnsObject,
98
- setFocusIndex: setFocusIndex
99
- }))));
74
+ onSelectColumn: onSelectColumn
75
+ })));
100
76
  };
101
77
  Columns.propTypes = {
102
78
  assistiveTextDisabledInstructionsLabel: PropTypes.string,
@@ -75,6 +75,7 @@ var CustomizeColumnsTearsheet = function CustomizeColumnsTearsheet(_ref) {
75
75
  isDirty = _useState10[0],
76
76
  setIsDirty = _useState10[1];
77
77
  var onRequestClose = function onRequestClose() {
78
+ setColumnObjects(columnDefinitions);
78
79
  setIsTearsheetOpen(false);
79
80
  };
80
81
  var onRequestSubmit = function onRequestSubmit() {
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
1
4
  /**
2
5
  * Copyright IBM Corp. 2023, 2023
3
6
  *
@@ -12,18 +15,21 @@ import { isColumnVisible } from './common';
12
15
  import DraggableElement from '../../DraggableElement';
13
16
  import { pkg } from '../../../../../settings';
14
17
  import getColTitle from '../../../utils/getColTitle';
18
+ import { DndContext, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors } from '@dnd-kit/core';
19
+ import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
15
20
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
+ var matchedColsById = function matchedColsById(col1, col2) {
22
+ return col1 && col2 && col1.id === col2.id;
23
+ };
16
24
  export var DraggableItemsList = function DraggableItemsList(_ref) {
17
25
  var columns = _ref.columns,
18
26
  filterString = _ref.filterString,
19
- focusIndex = _ref.focusIndex,
20
- getNextIndex = _ref.getNextIndex,
27
+ id = _ref.id,
21
28
  moveElement = _ref.moveElement,
22
29
  onSelectColumn = _ref.onSelectColumn,
23
- setAriaRegionText = _ref.setAriaRegionText,
24
- setColumnsObject = _ref.setColumnsObject,
25
- setFocusIndex = _ref.setFocusIndex;
26
- return /*#__PURE__*/React.createElement(React.Fragment, null, columns
30
+ setAriaRegionText = _ref.setAriaRegionText;
31
+ var draggableClass = "".concat(blockClass, "__draggable-item");
32
+ var visibleCols = columns
27
33
  // hide the columns without Header, e.g the sticky actions, spacer
28
34
  .filter(function (colDef) {
29
35
  return !!getColTitle(colDef);
@@ -32,7 +38,108 @@ export var DraggableItemsList = function DraggableItemsList(_ref) {
32
38
  }).filter(function (colDef) {
33
39
  var _getColTitle;
34
40
  return filterString.length === 0 || ((_getColTitle = getColTitle(colDef)) === null || _getColTitle === void 0 ? void 0 : _getColTitle.toLowerCase().includes(filterString)) && colDef.id !== 'spacer';
35
- }).map(function (colDef, i) {
41
+ });
42
+
43
+ // let localRefCopy;
44
+ var handleDragEnd = function handleDragEnd(event) {
45
+ var active = event.active,
46
+ over = event.over;
47
+ var fromVisibleIndex = columns.findIndex(function (col) {
48
+ return matchedColsById(col, active);
49
+ });
50
+ var toVisibleIndex = columns.findIndex(function (col) {
51
+ return matchedColsById(col, over);
52
+ });
53
+ var colTitle = getColTitle(visibleCols[fromVisibleIndex]);
54
+ setAriaRegionText("".concat(colTitle, " dropped. New position ").concat(toVisibleIndex + 1, " of ").concat(visibleCols.length, "."));
55
+ var fromIndex = columns.findIndex(function (col) {
56
+ return matchedColsById(col, active);
57
+ });
58
+ var toIndex = columns.findIndex(function (col) {
59
+ return matchedColsById(col, over);
60
+ });
61
+ moveElement(fromIndex, toIndex);
62
+ };
63
+ var handleDragStart = function handleDragStart(event) {
64
+ var active = event.active;
65
+ var fromIndex = visibleCols.findIndex(function (col) {
66
+ return matchedColsById(col, active);
67
+ });
68
+ var colTitle = getColTitle(visibleCols[fromIndex]);
69
+ setAriaRegionText("".concat(colTitle, " grabbed. Current position ").concat(fromIndex + 1, " of ").concat(visibleCols.length, "."));
70
+ };
71
+ var handleDragUpdate = function handleDragUpdate(event) {
72
+ var active = event.active,
73
+ over = event.over;
74
+ var fromIndex = visibleCols.findIndex(function (col) {
75
+ return matchedColsById(col, active);
76
+ });
77
+ var toIndex = visibleCols.findIndex(function (col) {
78
+ return matchedColsById(col, over);
79
+ });
80
+ var colTitle = getColTitle(visibleCols[fromIndex]);
81
+ setAriaRegionText("".concat(colTitle, " grabbed. Original position ").concat(fromIndex + 1, ", new position ").concat(toIndex + 1, " of ").concat(visibleCols.length, "."));
82
+ };
83
+ var pointerSensor = useSensor(PointerSensor, {
84
+ // Require the mouse to move by 10 pixels before activating
85
+ activationConstraint: {
86
+ distance: 4
87
+ }
88
+ });
89
+ var keyboardSensor = useSensor(KeyboardSensor, {
90
+ coordinateGetter: function coordinateGetter(event, args) {
91
+ var currentCoordinates = args.currentCoordinates;
92
+ var target = event.target;
93
+ while (target && !target.classList.contains(draggableClass)) {
94
+ target = target.parentNode;
95
+ }
96
+ var delta = target.offsetHeight;
97
+ switch (event.code) {
98
+ case 'ArrowRight':
99
+ case 'ArrowLeft':
100
+ // ignore right and left
101
+ return currentCoordinates;
102
+ case 'ArrowUp':
103
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
104
+ y: currentCoordinates.y - delta
105
+ });
106
+ case 'ArrowDown':
107
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
108
+ y: currentCoordinates.y + delta
109
+ });
110
+ case 'Space':
111
+ break;
112
+ }
113
+ }
114
+ });
115
+ var sensors = useSensors(pointerSensor, keyboardSensor);
116
+ var handleCheckboxKeydown = function handleCheckboxKeydown(event, colDef) {
117
+ if (event.code === 'Space') {
118
+ onSelectColumn(colDef, !isColumnVisible(colDef));
119
+ event.preventDefault();
120
+ event.stopPropagation();
121
+ return false;
122
+ }
123
+ };
124
+ return /*#__PURE__*/React.createElement(DndContext, {
125
+ collisionDetection: closestCenter,
126
+ onDragEnd: handleDragEnd,
127
+ onDragStart: handleDragStart,
128
+ onDragMove: handleDragUpdate,
129
+ sensors: sensors
130
+ }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
131
+ className: "".concat(blockClass, "__draggable-underlay"),
132
+ "aria-hidden": "true",
133
+ key: "draggable-underlay-".concat(id)
134
+ }, visibleCols.map(function (colDef) {
135
+ return /*#__PURE__*/React.createElement("div", {
136
+ className: "".concat(blockClass, "__draggable-underlay-item"),
137
+ key: colDef.id
138
+ });
139
+ })), /*#__PURE__*/React.createElement(SortableContext, {
140
+ items: visibleCols,
141
+ strategy: verticalListSortingStrategy
142
+ }, visibleCols.map(function (colDef) {
36
143
  var colHeaderTitle = getColTitle(colDef);
37
144
  var searchString = new RegExp('(' + filterString + ')');
38
145
  var res = filterString.length ? colHeaderTitle.toLowerCase().split(searchString) : null;
@@ -40,60 +147,41 @@ export var DraggableItemsList = function DraggableItemsList(_ref) {
40
147
  var highlightedText = res !== null ? res[0] === '' ? "<strong>".concat(firstWord, "</strong>") + res[2] : firstWord + "<strong>".concat(res[1], "</strong>") + res[2] : colHeaderTitle;
41
148
  var isFrozenColumn = !!colDef.sticky;
42
149
  var listContents = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Checkbox, {
43
- wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox-wrapper"),
44
150
  checked: isColumnVisible(colDef),
45
151
  disabled: isFrozenColumn,
46
- onChange: onSelectColumn.bind(null, colDef),
152
+ onChange: function onChange(checked) {
153
+ return onSelectColumn(colDef, checked);
154
+ },
47
155
  id: "".concat(blockClass, "__customization-column-").concat(colDef.id),
48
156
  labelText: colHeaderTitle,
49
157
  title: colHeaderTitle,
50
158
  className: "".concat(blockClass, "__customize-columns-checkbox"),
51
- hideLabel: true
159
+ hideLabel: true,
160
+ onKeyDown: function onKeyDown(event) {
161
+ return handleCheckboxKeydown(event, colDef);
162
+ }
52
163
  }), /*#__PURE__*/React.createElement("div", {
53
164
  dangerouslySetInnerHTML: {
54
165
  __html: highlightedText
55
- }
166
+ },
167
+ className: "".concat(blockClass, "__customize-columns-checkbox-visible-label")
56
168
  }));
57
169
  return /*#__PURE__*/React.createElement(DraggableElement, {
170
+ classList: draggableClass,
58
171
  key: colDef.id,
59
- index: i,
60
- listData: columns,
61
- setListData: setColumnsObject,
62
- id: "dnd-datagrid-columns-".concat(colDef.id),
63
- type: "column-customization",
172
+ id: colDef.id,
64
173
  disabled: filterString.length > 0 || isFrozenColumn,
65
174
  ariaLabel: colHeaderTitle,
66
- onGrab: setAriaRegionText,
67
- isFocused: focusIndex === i,
68
- moveElement: moveElement,
69
- onArrowKeyDown: function onArrowKeyDown(e, isGrabbed, currentIndex) {
70
- if (isGrabbed) {
71
- var _columns$nextIndex;
72
- var nextIndex = getNextIndex(columns, currentIndex, e.key);
73
- e.preventDefault();
74
- e.stopPropagation();
75
- if (nextIndex >= 0 && !((_columns$nextIndex = columns[nextIndex]) !== null && _columns$nextIndex !== void 0 && _columns$nextIndex.sticky)) {
76
- setFocusIndex(nextIndex);
77
- moveElement(currentIndex, nextIndex);
78
- e.target.scrollIntoView({
79
- block: 'center'
80
- });
81
- }
82
- }
83
- },
84
175
  isSticky: isFrozenColumn,
85
176
  selected: isColumnVisible(colDef)
86
177
  }, listContents);
87
- }));
178
+ }))));
88
179
  };
89
180
  DraggableItemsList.propTypes = {
90
181
  columns: PropTypes.array.isRequired,
91
182
  filterString: PropTypes.string.isRequired,
92
- focusIndex: PropTypes.number.isRequired,
93
- getNextIndex: PropTypes.func.isRequired,
183
+ id: PropTypes.string.isRequired,
94
184
  moveElement: PropTypes.func.isRequired,
95
185
  onSelectColumn: PropTypes.func.isRequired,
96
- setAriaRegionText: PropTypes.func.isRequired,
97
- setColumnsObject: PropTypes.func.isRequired,
98
- setFocusIndex: PropTypes.func.isRequired
186
+ setAriaRegionText: PropTypes.func.isRequired
99
187
  };
@@ -61,13 +61,19 @@ var FilterPanel = function FilterPanel(_ref) {
61
61
  _useState2 = _slicedToArray(_useState, 2),
62
62
  showDividerLine = _useState2[0],
63
63
  setShowDividerLine = _useState2[1];
64
+
65
+ /** Context */
66
+ var _useContext = useContext(FilterContext),
67
+ panelOpen = _useContext.panelOpen,
68
+ setPanelOpen = _useContext.setPanelOpen;
64
69
  var _useFilters = useFilters({
65
70
  updateMethod: updateMethod,
66
71
  filters: filterSections,
67
72
  setAllFilters: setAllFilters,
68
73
  variation: PANEL,
69
74
  reactTableFiltersState: reactTableFiltersState,
70
- onCancel: onCancel
75
+ onCancel: onCancel,
76
+ panelOpen: panelOpen
71
77
  }),
72
78
  filtersState = _useFilters.filtersState,
73
79
  prevFiltersObjectArrayRef = _useFilters.prevFiltersObjectArrayRef,
@@ -99,11 +105,6 @@ var FilterPanel = function FilterPanel(_ref) {
99
105
  return updateMethod === BATCH;
100
106
  }, [updateMethod]);
101
107
 
102
- /** Context */
103
- var _useContext = useContext(FilterContext),
104
- panelOpen = _useContext.panelOpen,
105
- setPanelOpen = _useContext.setPanelOpen;
106
-
107
108
  /** Methods */
108
109
  var closePanel = function closePanel() {
109
110
  cancel();