@qualtrics/ui-react 2.50.0 → 2.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/__shared/cjs/{index-19ecf96e.js → index-7c2fdea8.js} +262 -281
  3. package/dist/__shared/cjs/{index-e9e9ae0e.js → index-f4a0f3d1.js} +39 -3
  4. package/dist/components/Accordion/Accordion2.js +3 -3
  5. package/dist/components/Accordion/AccordionPanel.js +3 -24
  6. package/dist/components/Button/Button.js +3 -3
  7. package/dist/components/Button/Button2.js +9 -13
  8. package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
  9. package/dist/components/Checkbox/Checkbox2.js +3 -3
  10. package/dist/components/ColorPicker/ColorPicker2.js +3 -3
  11. package/dist/components/ColorPicker/Palette.js +33 -39
  12. package/dist/components/Combobox/Combobox.js +1 -1
  13. package/dist/components/Combobox/Combobox2.js +3 -3
  14. package/dist/components/ConfigPane/ConfigPane.js +5 -6
  15. package/dist/components/ConfigPane/ConfigPane2.js +3 -3
  16. package/dist/components/Divider/Divider2.js +3 -3
  17. package/dist/components/Dropdown/Dropdown.js +1 -1
  18. package/dist/components/Dropdown/Dropdown2.js +3 -3
  19. package/dist/components/Dropdown/DropdownButton.js +9 -9
  20. package/dist/components/FilePicker/FilePicker2.js +3 -3
  21. package/dist/components/FormField/Caption.js +3 -3
  22. package/dist/components/FormField/FormField2.js +3 -3
  23. package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
  24. package/dist/components/Icon/IconTypes.js +9 -0
  25. package/dist/components/IconButton/IconButton2.js +3 -3
  26. package/dist/components/InlineInput/InlineInput2.js +3 -3
  27. package/dist/components/Input/Input2.js +3 -3
  28. package/dist/components/InputGroup/InputGroup2.js +3 -3
  29. package/dist/components/Label/Label2.js +3 -3
  30. package/dist/components/Link/Link2.js +3 -3
  31. package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
  32. package/dist/components/LogicEditor/LogicEditor2.js +3 -3
  33. package/dist/components/Modal/Modal2.js +3 -3
  34. package/dist/components/NewMenu/BaseMenu.js +3 -3
  35. package/dist/components/NewMenu/NewMenu.js +3 -3
  36. package/dist/components/NumberStepper/NumberStepper2.js +3 -3
  37. package/dist/components/PageLayout/PageLayout.js +3 -3
  38. package/dist/components/Pagination/Pagination2.js +3 -3
  39. package/dist/components/Popover/Popover2.js +3 -3
  40. package/dist/components/QuickSearch/QuickSearch2.js +3 -3
  41. package/dist/components/Radio/Radio2.js +3 -3
  42. package/dist/components/SearchInput/SearchInput.js +7 -2
  43. package/dist/components/SearchInput/SearchInput2.js +3 -3
  44. package/dist/components/SidebarNav/SidebarNav2.js +3 -3
  45. package/dist/components/Slider/Slider2.js +3 -3
  46. package/dist/components/Switch/Switch2.js +3 -3
  47. package/dist/components/Table/Table2.js +3 -3
  48. package/dist/components/Tabs/TabContextProvider.js +0 -2
  49. package/dist/components/Tabs/Tabs2.js +3 -3
  50. package/dist/components/Tooltip/Tooltip.js +31 -41
  51. package/dist/components/Tooltip/Tooltip2.js +3 -3
  52. package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
  53. package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
  54. package/dist/components/deprecated_NumberStepper/NumberStepperDecrement.js +1 -1
  55. package/dist/components/deprecated_NumberStepper/NumberStepperIncrement.js +1 -1
  56. package/dist/components/deprecated_Tabs/Tabs.js +2 -2
  57. package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
  58. package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
  59. package/dist/hooks/useOverlay/useOverlay2.js +3 -3
  60. package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
  61. package/dist/icons/Icon.js +3 -3
  62. package/dist/icons/components/GridBottomHalfIcon.js +6 -0
  63. package/dist/icons/components/GridBottomLeftIcon.js +6 -0
  64. package/dist/icons/components/GridBottomRightIcon.js +6 -0
  65. package/dist/icons/components/GridLeftHalfIcon.js +6 -0
  66. package/dist/icons/components/GridRightHalfIcon.js +6 -0
  67. package/dist/icons/components/GridTopHalfIcon.js +6 -0
  68. package/dist/icons/components/GridTopLeftIcon.js +6 -0
  69. package/dist/icons/components/GridTopRightIcon.js +6 -0
  70. package/dist/icons/components/SocialChannelsIcon.js +6 -0
  71. package/dist/icons/index.d.ts +18 -2
  72. package/dist/icons/index.es.js +9 -0
  73. package/dist/icons/index.js +10 -1
  74. package/dist/index.d.ts +27 -4
  75. package/dist/index.es.js +1 -1
  76. package/dist/index.js +3 -3
  77. package/dist/next/AdvancedTable/AdvancedTable.js +9 -7
  78. package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
  79. package/dist/next/AdvancedTable/AdvancedTableCheckbox.js +6 -1
  80. package/dist/next/AdvancedTable/AdvancedTableColumnHeader.js +15 -6
  81. package/dist/next/AdvancedTable/AdvancedTableDnDContext.js +32 -0
  82. package/dist/next/AdvancedTable/AdvancedTableDragPreview.js +9 -11
  83. package/dist/next/AdvancedTable/AdvancedTablePagination.js +19 -2
  84. package/dist/next/AdvancedTable/AdvancedTableRow.js +6 -1
  85. package/dist/next/AdvancedTable/AdvancedTableRowExpandButton.js +12 -3
  86. package/dist/next/AdvancedTable/useAdvancedTableDragAndDrop.js +30 -138
  87. package/dist/next/AdvancedTable/useDragAndDropConfig.js +191 -0
  88. package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
  89. package/dist/next/Combobox/Combobox2.js +3 -3
  90. package/dist/next/Drawer/Drawer.js +1 -1
  91. package/dist/next/Drawer/Drawer2.js +3 -3
  92. package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
  93. package/dist/next/Form/FormFields/InputField.js +3 -3
  94. package/dist/next/Input/Input2.js +3 -3
  95. package/dist/next/Menu/Hooks/usePaneSearch.js +12 -7
  96. package/dist/next/Menu/Menu2.js +3 -3
  97. package/dist/next/PhoneNumberInput/PhoneNumberInput.js +1 -0
  98. package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
  99. package/dist/next/Select/Select2.js +3 -3
  100. package/dist/next/SplitButton/SplitButton2.js +3 -3
  101. package/dist/next/TimePicker/TimePicker2.js +3 -3
  102. package/dist/next/ToggleButton/styles.js +3 -3
  103. package/dist/next/index.d.ts +14 -12
  104. package/dist/next/index.js +316 -162
  105. package/dist/utils/Flyout/Flyout2.js +3 -3
  106. package/dist/utils/Popper/Popper.js +5 -3
  107. package/dist/utils/Text/Text.js +1 -1
  108. package/dist/utils/Translation/containsComponentOrElement.js +6 -3
  109. package/dist/utils/Translation/useTranslation.js +5 -1
  110. package/icons/package.json +10 -10
  111. package/next/package.json +11 -11
  112. package/package.json +41 -41
@@ -4,6 +4,7 @@ import styles from './AdvancedTable2.js';
4
4
  import Check from '../../components/Checkbox/Check.js';
5
5
  import '../../utils/index.js';
6
6
  import '../../hooks/index.js';
7
+ import { useAdvancedTableDnDContext } from './AdvancedTableDnDContext.js';
7
8
  import useTranslation from '../../utils/Translation/useTranslation.js';
8
9
  import useScreenReaderAnnouncement from '../../hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement.js';
9
10
 
@@ -21,6 +22,9 @@ const AdvancedTableCheckbox = _ref => {
21
22
  const {
22
23
  translate
23
24
  } = useTranslation();
25
+ const {
26
+ isDragging
27
+ } = useAdvancedTableDnDContext();
24
28
  const label = useMemo(() => {
25
29
  const labels = {
26
30
  true: translate('checked'),
@@ -39,7 +43,8 @@ const AdvancedTableCheckbox = _ref => {
39
43
  "data-testid": dataTestId,
40
44
  onClick: onClick,
41
45
  className: classNames(styles.advancedTableCheckbox, className, {
42
- [styles.header]: variant === 'header'
46
+ [styles.header]: variant === 'header',
47
+ [styles.isColumnDragging]: isDragging
43
48
  }),
44
49
  role: "presentation"
45
50
  }, /*#__PURE__*/React__default.createElement(Check, {
@@ -10,6 +10,7 @@ import '../../icons/index.es.js';
10
10
  import '../../utils/index.js';
11
11
  import '../../hooks/index.js';
12
12
  import useComputedWidth from './useComputedWidth.js';
13
+ import { useAdvancedTableDnDContext } from './AdvancedTableDnDContext.js';
13
14
  import useEventListener from '../../hooks/useEventListener/useEventListener.js';
14
15
  import useTranslation from '../../utils/Translation/useTranslation.js';
15
16
  import Tooltip from '../../components/Tooltip/Tooltip.js';
@@ -56,6 +57,9 @@ const AdvancedTableColumnHeader = /*#__PURE__*/forwardRef((_ref, ref) => {
56
57
  const [ellipsisShown, setEllipsisShown] = useState();
57
58
  const columnHeaderRef = useRef(null);
58
59
  const labelContainerRef = useRef(null);
60
+ const {
61
+ isDragging: isUserDragging
62
+ } = useAdvancedTableDnDContext();
59
63
  const isSortable = Boolean(sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.length);
60
64
  const isSorted = isSortable && selectedSortOption.columnId === id && selectedSortOption.index >= 0 && selectedSortOption.index < (sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.length) && (selectedSortOption.direction === 'ascending' || selectedSortOption.direction === 'descending');
61
65
  const selectedSortIndex = isSorted ? selectedSortOption.index : -1;
@@ -94,7 +98,8 @@ const AdvancedTableColumnHeader = /*#__PURE__*/forwardRef((_ref, ref) => {
94
98
  const hasDraggableColumns = !disableUserPinnableColumns && !disableUserReorderableColumns && !isRowActionMenuColumn;
95
99
  const {
96
100
  dragRef,
97
- dropRef
101
+ dropRef,
102
+ listeners
98
103
  } = useDragAndDrop({
99
104
  isEnabled: hasDraggableColumns,
100
105
  id,
@@ -247,7 +252,7 @@ const AdvancedTableColumnHeader = /*#__PURE__*/forwardRef((_ref, ref) => {
247
252
  return /*#__PURE__*/React__default.createElement(Tooltip, {
248
253
  content: label,
249
254
  disabled: !ellipsisShown
250
- }, /*#__PURE__*/React__default.createElement("div", {
255
+ }, /*#__PURE__*/React__default.createElement("div", _extends({
251
256
  role: "columnheader",
252
257
  "data-testid": dataTestId,
253
258
  "aria-rowindex": 1,
@@ -271,13 +276,15 @@ const AdvancedTableColumnHeader = /*#__PURE__*/forwardRef((_ref, ref) => {
271
276
  [styles.isSorted]: isSorted,
272
277
  [styles.showFocusRing]: isHiddenMenuOpen,
273
278
  [styles.isDragging]: isDragging,
274
- [styles.fillRemainingSpace]: width === undefined
279
+ [styles.fillRemainingSpace]: width === undefined,
280
+ [styles.isColumnDragging]: isUserDragging
275
281
  }),
276
282
  style: {
277
283
  width: computedWidth
278
284
  },
279
- ref: mergeRefs(columnHeaderRef, dragRef, dropRef, ref)
280
- }, /*#__PURE__*/React__default.createElement("div", {
285
+ ref: mergeRefs(columnHeaderRef, dragRef, dropRef, ref),
286
+ draggable: hasDraggableColumns
287
+ }, listeners), /*#__PURE__*/React__default.createElement("div", {
281
288
  role: isSortable ? 'button' : undefined,
282
289
  className: classNames(styles.advancedTableColumnHeaderLabel, {
283
290
  [styles.leftAligned]: alignment === 'left',
@@ -298,7 +305,9 @@ const AdvancedTableColumnHeader = /*#__PURE__*/forwardRef((_ref, ref) => {
298
305
  anchor: /*#__PURE__*/React__default.createElement(IconButton, {
299
306
  tabIndex: -1,
300
307
  "aria-hidden": "true",
301
- className: styles.advancedTableColumnHeaderMenu
308
+ className: classNames(styles.advancedTableColumnHeaderMenu, {
309
+ [styles.isColumnDragging]: isUserDragging
310
+ })
302
311
  }, /*#__PURE__*/React__default.createElement(ChevronDownIcon, null))
303
312
  })), /*#__PURE__*/React__default.createElement(AdvancedTableColumnHeaderMenu, _extends({}, commonMenuProps, {
304
313
  isOpen: isHiddenMenuOpen,
@@ -0,0 +1,32 @@
1
+ import React__default, { createContext, useState, useMemo, useContext } from 'react';
2
+ import { DndContext } from '@dnd-kit/core';
3
+ import useDragAndDropConfig from './useDragAndDropConfig.js';
4
+
5
+ const defaultAdvancedTableDnDContext = {
6
+ isDragging: false,
7
+ setIsDragging: () => {}
8
+ };
9
+ const AdvancedTableDnDContext = /*#__PURE__*/createContext(defaultAdvancedTableDnDContext);
10
+ const AdvancedTableDnDContextProvider = _ref => {
11
+ let {
12
+ children,
13
+ setColumnOrder,
14
+ setDropTargetSide,
15
+ setPinnedColumns,
16
+ setDropTarget,
17
+ setDragSource,
18
+ dropTargetSide
19
+ } = _ref;
20
+ const [isDragging, setIsDragging] = useState(false);
21
+ const context = useMemo(() => ({
22
+ isDragging,
23
+ setIsDragging
24
+ }), [isDragging]);
25
+ const dndConfig = useDragAndDropConfig(setDragSource, setDropTarget, setDropTargetSide, setPinnedColumns, setColumnOrder, setIsDragging, dropTargetSide);
26
+ return /*#__PURE__*/React__default.createElement(AdvancedTableDnDContext.Provider, {
27
+ value: context
28
+ }, /*#__PURE__*/React__default.createElement(DndContext, dndConfig, children));
29
+ };
30
+ const useAdvancedTableDnDContext = () => useContext(AdvancedTableDnDContext);
31
+
32
+ export { AdvancedTableDnDContextProvider, useAdvancedTableDnDContext };
@@ -1,5 +1,5 @@
1
1
  import React__default from 'react';
2
- import { useDragLayer } from 'react-dnd';
2
+ import { useDndContext } from '@dnd-kit/core';
3
3
  import '../../utils/index.js';
4
4
  import styles from './AdvancedTable2.js';
5
5
  import Portal from '../../utils/Portal/Portal.js';
@@ -11,16 +11,14 @@ const AdvancedTableDragPreview = _ref => {
11
11
  columnHeaderRefs
12
12
  } = _ref;
13
13
  const {
14
- item,
15
- currentOffset
16
- } = useDragLayer(monitor => ({
17
- item: monitor.getItem(),
18
- currentOffset: monitor.getSourceClientOffset()
19
- }));
20
- const width = columnHeaderRefs === null || columnHeaderRefs === void 0 || (_columnHeaderRefs$ite = columnHeaderRefs[item === null || item === void 0 ? void 0 : item.columnIndex]) === null || _columnHeaderRefs$ite === void 0 || (_columnHeaderRefs$ite = _columnHeaderRefs$ite.getBoundingClientRect()) === null || _columnHeaderRefs$ite === void 0 ? void 0 : _columnHeaderRefs$ite.width;
21
- const height = (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 || (_tableRef$current = _tableRef$current.getBoundingClientRect()) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.height;
22
- const top = (currentOffset === null || currentOffset === void 0 ? void 0 : currentOffset.y) || 0;
23
- const left = (currentOffset === null || currentOffset === void 0 ? void 0 : currentOffset.x) || 0;
14
+ active
15
+ } = useDndContext();
16
+ const item = active === null || active === void 0 ? void 0 : active.data.current;
17
+ const position = active === null || active === void 0 ? void 0 : active.rect.current.translated;
18
+ const width = (columnHeaderRefs === null || columnHeaderRefs === void 0 || (_columnHeaderRefs$ite = columnHeaderRefs[item === null || item === void 0 ? void 0 : item.columnIndex]) === null || _columnHeaderRefs$ite === void 0 || (_columnHeaderRefs$ite = _columnHeaderRefs$ite.getBoundingClientRect()) === null || _columnHeaderRefs$ite === void 0 ? void 0 : _columnHeaderRefs$ite.width) || 0;
19
+ const height = ((_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 || (_tableRef$current = _tableRef$current.getBoundingClientRect()) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.height) || 0;
20
+ const top = ((position === null || position === void 0 ? void 0 : position.top) || 0) + window.scrollY;
21
+ const left = ((position === null || position === void 0 ? void 0 : position.left) || 0) + window.scrollX;
24
22
  return /*#__PURE__*/React__default.createElement(Portal, null, /*#__PURE__*/React__default.createElement("div", {
25
23
  className: styles.dragPreview,
26
24
  style: {
@@ -1,4 +1,4 @@
1
- import React__default from 'react';
1
+ import React__default, { useCallback, useMemo } from 'react';
2
2
  import styles from './AdvancedTable2.js';
3
3
  import '../../components/Pagination/index.js';
4
4
  import Pagination from '../../components/Pagination/Pagination.js';
@@ -21,12 +21,29 @@ const AdvancedTablePagination = _ref => {
21
21
  setCurrentPage(page);
22
22
  onPageChange === null || onPageChange === void 0 || onPageChange(page);
23
23
  };
24
+ const getExpandedChildren = useCallback(() => {
25
+ let count = 0;
26
+ const stack = [...rows];
27
+ while (stack.length > 0) {
28
+ const row = stack.pop();
29
+ if (!row) {
30
+ break;
31
+ }
32
+ if (row.isExpanded) {
33
+ var _row$childRows;
34
+ count += ((_row$childRows = row.childRows) === null || _row$childRows === void 0 ? void 0 : _row$childRows.length) || 0;
35
+ stack.push(...(row.childRows || []));
36
+ }
37
+ }
38
+ return count;
39
+ }, [rows]);
40
+ const visibleRows = useMemo(() => rows.length + getExpandedChildren(), [getExpandedChildren, rows]);
24
41
  return /*#__PURE__*/React__default.createElement("div", {
25
42
  className: styles.advancedTablePaginationContainer
26
43
  }, /*#__PURE__*/React__default.createElement(Pagination, {
27
44
  className: styles.advancedTablePagination,
28
45
  "aria-label": ariaLabel,
29
- numPages: Math.max(Math.ceil(rows.length / rowsPerPage), 1),
46
+ numPages: Math.max(Math.ceil(visibleRows / rowsPerPage), 1),
30
47
  currentPage: currentPage,
31
48
  onPageChange: handlePageChange,
32
49
  "data-testid": dataTestId
@@ -2,6 +2,7 @@ import _extends from '@babel/runtime-corejs3/helpers/extends';
2
2
  import React__default, { forwardRef } from 'react';
3
3
  import classNames from 'classnames';
4
4
  import styles from './AdvancedTable2.js';
5
+ import { useAdvancedTableDnDContext } from './AdvancedTableDnDContext.js';
5
6
 
6
7
  const AdvancedTableRow = /*#__PURE__*/forwardRef((_ref, ref) => {
7
8
  let {
@@ -17,6 +18,9 @@ const AdvancedTableRow = /*#__PURE__*/forwardRef((_ref, ref) => {
17
18
  children,
18
19
  ...rest
19
20
  } = _ref;
21
+ const {
22
+ isDragging
23
+ } = useAdvancedTableDnDContext();
20
24
  return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
21
25
  role: "row",
22
26
  "data-testid": dataTestId,
@@ -28,7 +32,8 @@ const AdvancedTableRow = /*#__PURE__*/forwardRef((_ref, ref) => {
28
32
  className: classNames(styles.advancedTableRow, {
29
33
  [styles.hasRowAction]: hasOnRowSelect,
30
34
  [styles.isSelected]: hasOnRowSelect && isSelected,
31
- [styles.advancedTableRowRestrictedWidth]: restrictedWidth
35
+ [styles.advancedTableRowRestrictedWidth]: restrictedWidth,
36
+ [styles.isColumnDragging]: isDragging
32
37
  }),
33
38
  ref: isFocusable ? ref : undefined
34
39
  }), children);
@@ -1,7 +1,9 @@
1
- import React__default from 'react';
1
+ import React__default, { useMemo } from 'react';
2
+ import classNames from 'classnames';
2
3
  import '../../utils/index.js';
3
4
  import '../../icons/index.es.js';
4
5
  import '../../components/index.js';
6
+ import { useAdvancedTableDnDContext } from './AdvancedTableDnDContext.js';
5
7
  import iconButtonStyles from '../../components/IconButton/IconButton2.js';
6
8
  import useTranslation from '../../utils/Translation/useTranslation.js';
7
9
  import Tooltip from '../../components/Tooltip/Tooltip.js';
@@ -18,17 +20,24 @@ const AdvancedTableRowExpandButton = _ref => {
18
20
  const {
19
21
  translate
20
22
  } = useTranslation();
23
+ const {
24
+ isDragging
25
+ } = useAdvancedTableDnDContext();
21
26
  const state = isRowExpanded ? 'expanded' : 'collapsed';
22
27
  const labels = {
23
28
  expanded: translate('advancedTable.collapseRow'),
24
29
  collapsed: translate('advancedTable.expandRow')
25
30
  };
31
+ const buttonClasses = useMemo(() => classNames(iconButtonStyles.button, {
32
+ [iconButtonStyles.disabled]: isDragging
33
+ }), [isDragging]);
26
34
  return /*#__PURE__*/React__default.createElement("div", {
27
35
  onClick: onClick
28
36
  }, /*#__PURE__*/React__default.createElement(Tooltip, {
29
- content: labels[state]
37
+ content: labels[state],
38
+ disabled: isDragging
30
39
  }, /*#__PURE__*/React__default.createElement("div", {
31
- className: iconButtonStyles.button,
40
+ className: buttonClasses,
32
41
  "data-testid": dataTestId,
33
42
  role: "presentation"
34
43
  }, state === 'expanded' ? /*#__PURE__*/React__default.createElement(CaretDownIcon, {
@@ -1,8 +1,5 @@
1
1
  import { useEffect } from 'react';
2
- import { useDrag, useDrop } from 'react-dnd';
3
- import { getEmptyImage } from 'react-dnd-html5-backend';
4
- import '../../hooks/index.js';
5
- import useLatest from '../../hooks/useLatest/useLatest.js';
2
+ import { useDraggable, useDroppable } from '@dnd-kit/core';
6
3
 
7
4
  const useDragAndDrop = _ref => {
8
5
  let {
@@ -12,143 +9,37 @@ const useDragAndDrop = _ref => {
12
9
  columnIndex,
13
10
  columnHeaderRef,
14
11
  isPinned,
15
- setPinnedColumns,
16
- setColumnOrder,
17
- setDragSource,
18
12
  setDropTarget,
19
- dropTargetSide,
20
13
  setDropTargetSide
21
14
  } = _ref;
22
- const [, dragRef, dragPreviewRef] = useDrag(() => ({
23
- type: tableId,
24
- item: () => {
25
- setDragSource(id);
26
- return {
27
- id,
28
- isPinned,
29
- columnIndex
30
- };
31
- },
32
- end: () => {
33
- setDragSource('');
34
- setDropTarget('');
35
- setDropTargetSide(undefined);
36
- },
37
- canDrag: () => isEnabled,
38
- options: {
39
- dropEffect: 'move'
15
+ const {
16
+ setNodeRef: dragRef,
17
+ listeners
18
+ } = useDraggable({
19
+ id,
20
+ disabled: !isEnabled,
21
+ data: {
22
+ type: tableId,
23
+ isPinned,
24
+ columnIndex,
25
+ id,
26
+ columnHeaderRef
40
27
  }
41
- }), [id, tableId, isPinned, columnIndex, isEnabled, setDragSource, setDropTarget, setDropTargetSide]);
42
-
43
- // Remove HTML5 DnD preview
44
- useEffect(() => {
45
- dragPreviewRef(getEmptyImage(), {
46
- captureDraggingState: false
47
- });
48
- }, [dragPreviewRef, id, isPinned, columnIndex]); // id, isPinned, and columnIndex included intentionally
49
-
50
- const dropTargetSideRef = useLatest(dropTargetSide);
51
- const [{
52
- isOver
53
- }, dropRef] = useDrop(() => ({
54
- accept: tableId,
55
- hover: (item, monitor) => {
56
- var _monitor$getClientOff, _columnHeaderRef$curr;
57
- const {
58
- id: dragSourceId,
59
- columnIndex: dragSourceColumnIndex,
60
- isPinned: dragSourceIsPinned
61
- } = item;
62
- setDropTarget(id);
63
- if (id === dragSourceId) {
64
- setDropTargetSide(undefined);
65
- return;
66
- }
67
-
68
- // Calculate which column line is closest
69
- const dropX = (_monitor$getClientOff = monitor.getClientOffset()) === null || _monitor$getClientOff === void 0 ? void 0 : _monitor$getClientOff.x;
70
- const {
71
- x,
72
- width
73
- } = (_columnHeaderRef$curr = columnHeaderRef.current) === null || _columnHeaderRef$curr === void 0 ? void 0 : _columnHeaderRef$curr.getBoundingClientRect();
74
- const diffLeft = Math.abs(dropX - x) || 0;
75
- const diffRight = Math.abs(dropX - (x + width)) || 0;
76
- if (diffLeft < diffRight) {
77
- // hover over left side
78
- if (columnIndex - dragSourceColumnIndex === 1 && isPinned === dragSourceIsPinned) {
79
- setDropTargetSide(undefined);
80
- } else {
81
- setDropTargetSide('left');
82
- }
83
- } else if (diffLeft >= diffRight) {
84
- // hover over right side
85
- if (dragSourceColumnIndex - columnIndex === 1 && isPinned === dragSourceIsPinned) {
86
- setDropTargetSide(undefined);
87
- } else {
88
- setDropTargetSide('right');
89
- }
90
- }
91
- },
92
- drop: item => {
93
- const {
94
- id: dragSourceId,
95
- columnIndex: dragSourceColumnIndex,
96
- isPinned: dragSourceIsPinned
97
- } = item;
98
- if (id === dragSourceId || dropTargetSideRef.current === undefined) {
99
- return;
100
- }
101
- if (isPinned && !dragSourceIsPinned) {
102
- // Dragging from an unpinned column onto a pinned column
103
- setPinnedColumns(pinnedColumns => {
104
- const newPinnedColumns = [...pinnedColumns];
105
- const newIndex = dropTargetSideRef.current === 'right' ? columnIndex + 1 : columnIndex;
106
- newPinnedColumns.splice(newIndex, 0, dragSourceId);
107
- return newPinnedColumns;
108
- });
109
- } else if (!isPinned && dragSourceIsPinned) {
110
- // Dragging from a pinned column onto an upinned column
111
- setPinnedColumns(pinnedColumns => {
112
- const newPinnedColumns = [...pinnedColumns];
113
- newPinnedColumns.splice(dragSourceColumnIndex, 1);
114
- return newPinnedColumns;
115
- });
116
- setColumnOrder(currentColumnOrder => {
117
- const newColumnOrder = [...currentColumnOrder];
118
- const dragSourceColumnOrderIndex = newColumnOrder.indexOf(dragSourceId);
119
- newColumnOrder.splice(dragSourceColumnOrderIndex, 1);
120
- const columnOrderIndex = newColumnOrder.indexOf(id);
121
- const newIndex = dropTargetSideRef.current === 'right' ? columnOrderIndex + 1 : columnOrderIndex;
122
- newColumnOrder.splice(newIndex, 0, dragSourceId);
123
- return newColumnOrder;
124
- });
125
- } else if (isPinned) {
126
- // Dragging from a pinned column onto a pinned column
127
- setPinnedColumns(pinnedColumns => {
128
- const newPinnedColumns = [...pinnedColumns];
129
- newPinnedColumns.splice(dragSourceColumnIndex, 1);
130
- const newIndex = dropTargetSideRef.current === 'right' ? columnIndex + 1 : columnIndex;
131
- newPinnedColumns.splice(newIndex, 0, dragSourceId);
132
- return newPinnedColumns;
133
- });
134
- } else {
135
- // Dragging from an upinned column onto an upinned column
136
- setColumnOrder(currentColumnOrder => {
137
- const newColumnOrder = [...currentColumnOrder];
138
- const dropIndex = newColumnOrder.indexOf(dragSourceId);
139
- newColumnOrder.splice(dropIndex, 1);
140
- const columnOrderIndex = newColumnOrder.indexOf(id);
141
- const newIndex = dropTargetSideRef.current === 'right' ? columnOrderIndex + 1 : columnOrderIndex;
142
- newColumnOrder.splice(newIndex, 0, dragSourceId);
143
- return newColumnOrder;
144
- });
145
- }
146
- },
147
- canDrop: () => isEnabled,
148
- collect: monitor => ({
149
- isOver: monitor.isOver()
150
- })
151
- }), [id, tableId, isPinned, columnIndex, isEnabled, setDropTarget, dropTargetSideRef, setDropTargetSide]);
28
+ });
29
+ const {
30
+ isOver,
31
+ setNodeRef: dropRef
32
+ } = useDroppable({
33
+ id,
34
+ disabled: !isEnabled,
35
+ data: {
36
+ type: tableId,
37
+ isPinned,
38
+ columnIndex,
39
+ id,
40
+ columnHeaderRef
41
+ }
42
+ });
152
43
 
153
44
  // Clear dropTarget when header is no longer being hovered
154
45
  useEffect(() => {
@@ -164,7 +55,8 @@ const useDragAndDrop = _ref => {
164
55
  }, [id, isOver, setDropTarget, setDropTargetSide]);
165
56
  return {
166
57
  dragRef,
167
- dropRef
58
+ dropRef,
59
+ listeners
168
60
  };
169
61
  };
170
62
 
@@ -0,0 +1,191 @@
1
+ import { useState } from 'react';
2
+ import { useSensors, useSensor, MouseSensor, pointerWithin, getClientRect, MeasuringStrategy, MeasuringFrequency } from '@dnd-kit/core';
3
+ import { restrictToWindowEdges } from '@dnd-kit/modifiers';
4
+ import '../../hooks/index.js';
5
+ import useLatest from '../../hooks/useLatest/useLatest.js';
6
+
7
+ const useDragAndDropConfig = (setDragSource, setDropTarget, setDropTargetSide, setPinnedColumns, setColumnOrder, setIsDragging, dropTargetSide) => {
8
+ const dropTargetSideRef = useLatest(dropTargetSide);
9
+ const [initSourcePos, setInitSourcePos] = useState(0);
10
+ const dragAndDropMonitorConfig = {
11
+ onDragStart: event => {
12
+ var _event$active$data$cu, _event$active;
13
+ setDragSource((_event$active$data$cu = event.active.data.current) === null || _event$active$data$cu === void 0 ? void 0 : _event$active$data$cu.id);
14
+ setIsDragging(true);
15
+ const {
16
+ x
17
+ } = ((_event$active = event.active) === null || _event$active === void 0 || (_event$active = _event$active.data.current) === null || _event$active === void 0 || (_event$active = _event$active.columnHeaderRef) === null || _event$active === void 0 || (_event$active = _event$active.current) === null || _event$active === void 0 ? void 0 : _event$active.getBoundingClientRect()) || {
18
+ x: 0
19
+ };
20
+ setInitSourcePos(x);
21
+ },
22
+ onDragCancel: () => {
23
+ setDragSource('');
24
+ setDropTarget('');
25
+ setDropTargetSide(undefined);
26
+ setIsDragging(false);
27
+ },
28
+ onDragEnd: event => {
29
+ setDragSource('');
30
+ setDropTarget('');
31
+ setDropTargetSide(undefined);
32
+ setIsDragging(false);
33
+ const {
34
+ active,
35
+ over
36
+ } = event;
37
+ if (!over) return;
38
+ const {
39
+ id: dragSourceId,
40
+ columnIndex: dragSourceColumnIndex,
41
+ isPinned: dragSourceIsPinned
42
+ } = active.data.current;
43
+ const {
44
+ id,
45
+ columnIndex,
46
+ isPinned
47
+ } = over.data.current;
48
+ if (id === dragSourceId || dropTargetSideRef.current === undefined) {
49
+ return;
50
+ }
51
+ if (isPinned && !dragSourceIsPinned) {
52
+ // Dragging from an unpinned column onto a pinned column
53
+ setPinnedColumns(pinnedColumns => {
54
+ const newPinnedColumns = [...pinnedColumns];
55
+ const newIndex = dropTargetSideRef.current === 'right' ? columnIndex + 1 : columnIndex;
56
+ newPinnedColumns.splice(newIndex, 0, dragSourceId);
57
+ return newPinnedColumns;
58
+ });
59
+ } else if (!isPinned && dragSourceIsPinned) {
60
+ // Dragging from a pinned column onto an upinned column
61
+ setPinnedColumns(pinnedColumns => {
62
+ const newPinnedColumns = [...pinnedColumns];
63
+ newPinnedColumns.splice(dragSourceColumnIndex, 1);
64
+ return newPinnedColumns;
65
+ });
66
+ setColumnOrder(currentColumnOrder => {
67
+ const newColumnOrder = [...currentColumnOrder];
68
+ const dragSourceColumnOrderIndex = newColumnOrder.indexOf(dragSourceId);
69
+ newColumnOrder.splice(dragSourceColumnOrderIndex, 1);
70
+ const columnOrderIndex = newColumnOrder.indexOf(id);
71
+ const newIndex = dropTargetSideRef.current === 'right' ? columnOrderIndex + 1 : columnOrderIndex;
72
+ newColumnOrder.splice(newIndex, 0, dragSourceId);
73
+ return newColumnOrder;
74
+ });
75
+ } else if (isPinned) {
76
+ // Dragging from a pinned column onto a pinned column
77
+ setPinnedColumns(pinnedColumns => {
78
+ const newPinnedColumns = [...pinnedColumns];
79
+ newPinnedColumns.splice(dragSourceColumnIndex, 1);
80
+ const newIndex = dropTargetSideRef.current === 'right' ? columnIndex + 1 : columnIndex;
81
+ newPinnedColumns.splice(newIndex, 0, dragSourceId);
82
+ return newPinnedColumns;
83
+ });
84
+ } else {
85
+ // Dragging from an upinned column onto an upinned column
86
+ setColumnOrder(currentColumnOrder => {
87
+ const newColumnOrder = [...currentColumnOrder];
88
+ const dropIndex = newColumnOrder.indexOf(dragSourceId);
89
+ newColumnOrder.splice(dropIndex, 1);
90
+ const columnOrderIndex = newColumnOrder.indexOf(id);
91
+ const newIndex = dropTargetSideRef.current === 'right' ? columnOrderIndex + 1 : columnOrderIndex;
92
+ newColumnOrder.splice(newIndex, 0, dragSourceId);
93
+ return newColumnOrder;
94
+ });
95
+ }
96
+ },
97
+ onDragMove: event => {
98
+ var _columnHeaderRef$curr, _DragSourceRef$curren;
99
+ const {
100
+ active,
101
+ over,
102
+ activatorEvent,
103
+ delta
104
+ } = event;
105
+ if (!over) return;
106
+ const {
107
+ id: dragSourceId,
108
+ columnIndex: dragSourceColumnIndex,
109
+ isPinned: dragSourceIsPinned,
110
+ columnHeaderRef: DragSourceRef
111
+ } = active.data.current;
112
+ const {
113
+ id,
114
+ columnIndex,
115
+ isPinned,
116
+ columnHeaderRef
117
+ } = over.data.current;
118
+ setDropTarget(id);
119
+ if (id === dragSourceId) {
120
+ setDropTargetSide(undefined);
121
+ return;
122
+ }
123
+
124
+ // Calculate which column line is closest
125
+ const {
126
+ x: targetX,
127
+ width: targetWidth
128
+ } = (columnHeaderRef === null || columnHeaderRef === void 0 || (_columnHeaderRef$curr = columnHeaderRef.current) === null || _columnHeaderRef$curr === void 0 ? void 0 : _columnHeaderRef$curr.getBoundingClientRect()) || {
129
+ x: 0,
130
+ width: 0
131
+ };
132
+ const {
133
+ x: sourceX
134
+ } = (DragSourceRef === null || DragSourceRef === void 0 || (_DragSourceRef$curren = DragSourceRef.current) === null || _DragSourceRef$curren === void 0 ? void 0 : _DragSourceRef$curren.getBoundingClientRect()) || {
135
+ x: 0
136
+ };
137
+
138
+ // Getting scroll position based on initial and current position
139
+ const scrollOffset = sourceX - initSourcePos;
140
+ const {
141
+ clientX: startPosition
142
+ } = activatorEvent;
143
+ const dropX = startPosition + delta.x;
144
+ const diffLeft = Math.abs(dropX - targetX + scrollOffset) || 0;
145
+ const diffRight = Math.abs(dropX - (targetX + targetWidth) + scrollOffset) || 0;
146
+ if (diffLeft < diffRight) {
147
+ // hover over left side
148
+ if (columnIndex - dragSourceColumnIndex === 1 && isPinned === dragSourceIsPinned) {
149
+ setDropTargetSide(undefined);
150
+ } else {
151
+ setDropTargetSide('left');
152
+ }
153
+ } else if (diffLeft >= diffRight) {
154
+ // hover over right side
155
+ if (dragSourceColumnIndex - columnIndex === 1 && isPinned === dragSourceIsPinned) {
156
+ setDropTargetSide(undefined);
157
+ } else {
158
+ setDropTargetSide('right');
159
+ }
160
+ }
161
+ }
162
+ };
163
+ const sensors = useSensors(useSensor(MouseSensor, {
164
+ activationConstraint: {
165
+ distance: 1
166
+ }
167
+ }));
168
+ return {
169
+ ...dragAndDropMonitorConfig,
170
+ sensors,
171
+ collisionDetection: pointerWithin,
172
+ modifiers: [restrictToWindowEdges],
173
+ measuring: {
174
+ droppable: {
175
+ measure: element => getClientRect(element, {
176
+ ignoreTransform: false
177
+ }),
178
+ strategy: MeasuringStrategy.WhileDragging,
179
+ frequency: MeasuringFrequency.Optimized
180
+ }
181
+ },
182
+ accessibility: {
183
+ screenReaderInstructions: {
184
+ draggable: 'draggable'
185
+ }
186
+ },
187
+ autoscroll: false
188
+ };
189
+ };
190
+
191
+ export { useDragAndDropConfig as default };
@@ -1,8 +1,8 @@
1
1
  import styleInject from './../../__node_modules/style-inject/dist/style-inject.es.js';
2
2
 
3
- var css_248z = "._IgA-r{display:inline-block;width:36px;transition:width .25s ease-out}._wlU91{width:100%}._U8YqK>input{padding-right:0!important}._WZR4j>svg{fill:#515559}";
4
- var styles = {"collapsibleSearchInput":"_IgA-r","searchInput":"_wlU91","searchInputCollapsed":"_U8YqK","iconButton":"_WZR4j"};
5
- var stylesheet="._IgA-r{display:inline-block;width:36px;transition:width .25s ease-out}._wlU91{width:100%}._U8YqK>input{padding-right:0!important}._WZR4j>svg{fill:#515559}";
3
+ var css_248z = "._sD9-6{display:inline-block;width:36px;transition:width .25s ease-out}._v8-p7{width:100%}._SaDAB>input{padding-right:0!important}._i44ff>svg{fill:#515559}";
4
+ var styles = {"collapsibleSearchInput":"_sD9-6","searchInput":"_v8-p7","searchInputCollapsed":"_SaDAB","iconButton":"_i44ff"};
5
+ var stylesheet="._sD9-6{display:inline-block;width:36px;transition:width .25s ease-out}._v8-p7{width:100%}._SaDAB>input{padding-right:0!important}._i44ff>svg{fill:#515559}";
6
6
  if(typeof process !== 'object' || !process.hasOwnProperty('env') || process.env.NODE_ENV !== 'test'){styleInject(css_248z);}
7
7
 
8
8
  export { styles as default, stylesheet };