@elliemae/ds-treeview 2.2.0-alpha.1 → 3.0.0-next.1

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 (60) hide show
  1. package/cjs/TreeView.js +2 -6
  2. package/cjs/TreeViewContext.js +2 -8
  3. package/cjs/config/useTreeview.js +3 -13
  4. package/cjs/hoc/DnDTreeContext.js +18 -0
  5. package/cjs/hoc/SortableItemContext.js +21 -0
  6. package/cjs/hoc/WithConditionalDnDContext.js +138 -0
  7. package/cjs/hoc/WithDnDSortableItemContext.js +70 -0
  8. package/cjs/index.js +0 -1
  9. package/cjs/parts/DnDHandle.js +46 -0
  10. package/cjs/parts/DropIndicator.js +75 -0
  11. package/cjs/parts/TreeItem.js +43 -68
  12. package/cjs/parts/TreeList.js +15 -17
  13. package/cjs/plugins/dnd/TreeDndPlugin.js +0 -37
  14. package/cjs/plugins/dnd/index.js +0 -1
  15. package/cjs/plugins/index.js +0 -1
  16. package/cjs/react-desc-prop-types.js +1 -0
  17. package/cjs/utils/keyboard-helpers.js +6 -5
  18. package/cjs/utils/tree-helpers.js +28 -2
  19. package/cjs/utils/useTree.js +4 -2
  20. package/esm/TreeView.js +2 -6
  21. package/esm/TreeViewContext.js +2 -8
  22. package/esm/config/useTreeview.js +4 -14
  23. package/esm/hoc/DnDTreeContext.js +14 -0
  24. package/esm/hoc/SortableItemContext.js +17 -0
  25. package/esm/hoc/WithConditionalDnDContext.js +128 -0
  26. package/esm/hoc/WithDnDSortableItemContext.js +61 -0
  27. package/esm/index.js +1 -1
  28. package/esm/parts/DnDHandle.js +38 -0
  29. package/esm/parts/DropIndicator.js +68 -0
  30. package/esm/parts/TreeItem.js +42 -67
  31. package/esm/parts/TreeList.js +16 -17
  32. package/esm/plugins/dnd/TreeDndPlugin.js +1 -33
  33. package/esm/plugins/dnd/index.js +1 -1
  34. package/esm/plugins/index.js +1 -1
  35. package/esm/react-desc-prop-types.js +1 -0
  36. package/esm/utils/keyboard-helpers.js +6 -5
  37. package/esm/utils/tree-helpers.js +28 -3
  38. package/esm/utils/useTree.js +5 -3
  39. package/package.json +35 -19
  40. package/types/hoc/DnDTreeContext.d.ts +14 -0
  41. package/types/hoc/SortableItemContext.d.ts +19 -0
  42. package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
  43. package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
  44. package/types/parts/DnDHandle.d.ts +6 -0
  45. package/types/parts/DropIndicator.d.ts +10 -0
  46. package/types/parts/TreeItem.d.ts +4 -11
  47. package/types/parts/TreeList.d.ts +0 -4
  48. package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
  49. package/types/react-desc-prop-types.d.ts +17 -3
  50. package/types/sharedTypes.d.ts +1 -8
  51. package/types/utils/keyboard-helpers.d.ts +2 -1
  52. package/types/utils/refs-helpers.d.ts +1 -1
  53. package/types/utils/tree-helpers.d.ts +4 -1
  54. package/types/utils/useTree.d.ts +1 -0
  55. package/cjs/utils/dnd-helpers.js +0 -140
  56. package/cjs/utils/useDnDHelpers.js +0 -220
  57. package/esm/utils/dnd-helpers.js +0 -132
  58. package/esm/utils/useDnDHelpers.js +0 -216
  59. package/types/utils/dnd-helpers.d.ts +0 -39
  60. package/types/utils/useDnDHelpers.d.ts +0 -26
package/cjs/TreeView.js CHANGED
@@ -7,7 +7,6 @@ require('react');
7
7
  var reactDesc = require('react-desc');
8
8
  var reactDescPropTypes = require('./react-desc-prop-types.js');
9
9
  var TreeViewContext = require('./TreeViewContext.js');
10
- var TreeDndPlugin = require('./plugins/dnd/TreeDndPlugin.js');
11
10
  var useTreeview = require('./config/useTreeview.js');
12
11
  var TreeList = require('./parts/TreeList.js');
13
12
 
@@ -15,17 +14,14 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
15
14
 
16
15
  var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
17
16
 
18
- var _TreeDnD, _TreeList;
17
+ var _TreeList;
19
18
  function TreeView(props) {
20
- const {
21
- plugins
22
- } = props;
23
19
  const {
24
20
  ctx
25
21
  } = useTreeview.useTreeview(props);
26
22
  return /*#__PURE__*/_jsx__default["default"](TreeViewContext["default"].Provider, {
27
23
  value: ctx
28
- }, void 0, plugins !== null && plugins !== void 0 && plugins.includes(TreeDndPlugin.TreeDndPlugin) ? _TreeDnD || (_TreeDnD = /*#__PURE__*/_jsx__default["default"](TreeDndPlugin.TreeDnD, {})) : _TreeList || (_TreeList = /*#__PURE__*/_jsx__default["default"](TreeList.TreeList, {})));
24
+ }, void 0, _TreeList || (_TreeList = /*#__PURE__*/_jsx__default["default"](TreeList.TreeList, {})));
29
25
  }
30
26
  const TreeViewWithSchema = reactDesc.describe(TreeView);
31
27
  TreeViewWithSchema.propTypes = reactDescPropTypes.TreeViewPropTypes;
@@ -18,6 +18,7 @@ const defaultProps = {
18
18
  fluid: false,
19
19
  isMultiSelect: false,
20
20
  isSingleSelect: false,
21
+ getIsDropValid: () => true,
21
22
  restrictDragAndDrop: false,
22
23
  showChildrenAmount: false,
23
24
  sortable: false,
@@ -58,11 +59,10 @@ const defaultRelativeMouseCoord = {
58
59
  const defaultContext = {
59
60
  props: defaultProps,
60
61
  visibleItems: [],
62
+ flattenedItems: [],
61
63
  withRadioChecks: false,
62
64
  withCheckboxChecks: false,
63
65
  withDragAndDrop: false,
64
- relativeMouseCord: defaultRelativeMouseCoord,
65
- setRelativeMouseCord: noop,
66
66
  triggerTreeRerender: noop,
67
67
  tree: undefined,
68
68
  treeRoot: undefined,
@@ -73,12 +73,6 @@ const defaultContext = {
73
73
  scrollToIndex: noop
74
74
  },
75
75
  virtualListRef: undefined,
76
- isDragging: false,
77
- setIsDragging: noop,
78
- isKeyboardDragging: false,
79
- setIsKeyboardDragging: noop,
80
- draggedItem: null,
81
- setDraggedItem: noop,
82
76
  uniqueTreeViewUUID: '',
83
77
  selectedItem: null,
84
78
  setSelectedItem: noop,
@@ -50,11 +50,7 @@ const useTreeview = props => {
50
50
  selection,
51
51
  onInstanceRefInitialized
52
52
  } = propsWithDefault;
53
- const [isDragging, setIsDragging] = React.useState(false);
54
- const [isKeyboardDragging, setIsKeyboardDragging] = React.useState(false);
55
- const [relativeMouseCord, setRelativeMouseCord] = React.useState(TreeViewContext.defaultRelativeMouseCoord);
56
53
  const [uniqueTreeViewUUID] = React.useState(uuid.v4());
57
- const [draggedItem, setDraggedItem] = React.useState(null);
58
54
  const [hoverItem, setHoverItem] = React.useState(null);
59
55
  const [latestToggledItem, setLatestToggledItem] = React.useState(null);
60
56
  const [selectedItem, setSelectedItem] = React.useState(null);
@@ -63,6 +59,7 @@ const useTreeview = props => {
63
59
  const [expandedGroups, setExpandedGroups] = React.useState({});
64
60
  const {
65
61
  visibleItems,
62
+ flattenedItems,
66
63
  tree,
67
64
  treeRoot,
68
65
  triggerTreeRerender,
@@ -84,20 +81,13 @@ const useTreeview = props => {
84
81
  const handleExpandGroup = React.useCallback(groupExpandsHelpers.toggleItemExpand, []);
85
82
  const ctx = React.useMemo(() => ({
86
83
  props: propsWithDefault,
87
- setRelativeMouseCord,
88
- relativeMouseCord,
89
84
  virtualListHelpers,
90
85
  virtualListRef,
91
86
  tree,
92
87
  treeRoot,
93
88
  visibleItems,
89
+ flattenedItems,
94
90
  triggerTreeRerender,
95
- isDragging,
96
- setIsDragging,
97
- isKeyboardDragging,
98
- setIsKeyboardDragging,
99
- draggedItem,
100
- setDraggedItem,
101
91
  withRadioChecks,
102
92
  withCheckboxChecks,
103
93
  withDragAndDrop,
@@ -116,7 +106,7 @@ const useTreeview = props => {
116
106
  setHoverItem,
117
107
  handleExpandGroup,
118
108
  updateUserExpandedState
119
- }), [draggedItem, expandedGroups, focusedItem, handleExpandGroup, hoverItem, isDragging, isKeyboardDragging, latestToggledItem, propsWithDefault, relativeMouseCord, selectedCheckboxes, selectedItem, tree, treeRoot, triggerTreeRerender, uniqueTreeViewUUID, virtualListHelpers, visibleItems, withCheckboxChecks, withDragAndDrop, withRadioChecks, updateUserExpandedState]); // this hooks can't use the context because the context provider doesn't wrap this
109
+ }), [propsWithDefault, virtualListHelpers, tree, treeRoot, visibleItems, flattenedItems, triggerTreeRerender, withRadioChecks, withCheckboxChecks, withDragAndDrop, uniqueTreeViewUUID, selectedCheckboxes, selectedItem, expandedGroups, latestToggledItem, focusedItem, hoverItem, handleExpandGroup, updateUserExpandedState]); // this hooks can't use the context because the context provider doesn't wrap this
120
110
  // as such we manually pass the second parameter as fit
121
111
 
122
112
  if (instanceRef) instanceRef.current = treeRef.current;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var SortableItemContext = require('./SortableItemContext.js');
7
+
8
+ const DnDTreeContext = /*#__PURE__*/React.createContext({
9
+ depth: undefined,
10
+ activeIndex: undefined,
11
+ visibleItems: undefined,
12
+ dropIndicatorPosition: SortableItemContext.DropIndicatorPosition.None,
13
+ lastActiveId: undefined,
14
+ setLastActiveId: undefined,
15
+ isDropValid: false
16
+ });
17
+
18
+ exports.DnDTreeContext = DnDTreeContext;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+
7
+ exports.DropIndicatorPosition = void 0;
8
+
9
+ (function (DropIndicatorPosition) {
10
+ DropIndicatorPosition[DropIndicatorPosition["None"] = 0] = "None";
11
+ DropIndicatorPosition[DropIndicatorPosition["Before"] = 1] = "Before";
12
+ DropIndicatorPosition[DropIndicatorPosition["After"] = 2] = "After";
13
+ DropIndicatorPosition[DropIndicatorPosition["Inside"] = 3] = "Inside";
14
+ })(exports.DropIndicatorPosition || (exports.DropIndicatorPosition = {}));
15
+
16
+ /** Context for cross component communication */
17
+ const SortableItemContext = /*#__PURE__*/React.createContext({
18
+ draggableProps: false
19
+ });
20
+
21
+ exports.SortableItemContext = SortableItemContext;
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _jsx = require('@babel/runtime/helpers/jsx');
6
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
7
+ require('core-js/modules/web.dom-collections.iterator.js');
8
+ require('core-js/modules/esnext.async-iterator.map.js');
9
+ require('core-js/modules/esnext.iterator.map.js');
10
+ require('core-js/modules/esnext.async-iterator.for-each.js');
11
+ require('core-js/modules/esnext.iterator.constructor.js');
12
+ require('core-js/modules/esnext.iterator.for-each.js');
13
+ require('core-js/modules/esnext.async-iterator.find.js');
14
+ require('core-js/modules/esnext.iterator.find.js');
15
+ require('core-js/modules/esnext.async-iterator.filter.js');
16
+ require('core-js/modules/esnext.iterator.filter.js');
17
+ var React = require('react');
18
+ var core = require('@dnd-kit/core');
19
+ var sortable = require('@dnd-kit/sortable');
20
+ var dsDragAndDrop = require('@elliemae/ds-drag-and-drop');
21
+ var TreeViewContext = require('../TreeViewContext.js');
22
+ var TreeItem = require('../parts/TreeItem.js');
23
+ var DnDTreeContext = require('./DnDTreeContext.js');
24
+ var jsxRuntime = require('react/jsx-runtime');
25
+
26
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
27
+
28
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
29
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
30
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
31
+
32
+ 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; }
33
+
34
+ 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__default["default"](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; }
35
+
36
+ const ensure = function (argument) {
37
+ let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'This should never happen';
38
+
39
+ if (argument === undefined || argument === null) {
40
+ throw new TypeError(message);
41
+ }
42
+
43
+ return argument;
44
+ }; // only wraps in "DnDContext" and "DnDTreeContext" if any Drag and Drop functionality is requested
45
+
46
+
47
+ const withConditionalDnDRowContext = Component => props => {
48
+ const [lastActiveId, setLastActiveId] = React__default["default"].useState('');
49
+ const {
50
+ props: {
51
+ data,
52
+ onOrderChange,
53
+ getIsDropValid
54
+ },
55
+ flattenedItems,
56
+ visibleItems: flattenedVisibleTree,
57
+ withDragAndDrop
58
+ } = React.useContext(TreeViewContext["default"]);
59
+ const flattenedVisibleTreeForDnD = React.useMemo(() => flattenedVisibleTree.map((item, index) => {
60
+ var _item$treeDepth, _item$children$length, _item$children, _item$node$parent$mod, _item$node$parent, _item$node$parent$mod2, _item$node$parent$mod3;
61
+
62
+ return {
63
+ uid: item.id.toString(),
64
+ depth: ((_item$treeDepth = item.treeDepth) !== null && _item$treeDepth !== void 0 ? _item$treeDepth : 1) - 1,
65
+ realIndex: index,
66
+ childrenCount: (_item$children$length = (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) !== null && _item$children$length !== void 0 ? _item$children$length : 0,
67
+ parentId: (_item$node$parent$mod = (_item$node$parent = item.node.parent) === null || _item$node$parent === void 0 ? void 0 : (_item$node$parent$mod2 = _item$node$parent.model) === null || _item$node$parent$mod2 === void 0 ? void 0 : (_item$node$parent$mod3 = _item$node$parent$mod2.id) === null || _item$node$parent$mod3 === void 0 ? void 0 : _item$node$parent$mod3.toString()) !== null && _item$node$parent$mod !== void 0 ? _item$node$parent$mod : null,
68
+ original: item
69
+ };
70
+ }), [flattenedVisibleTree]);
71
+ const onReorder = React.useCallback((tree, indexes) => {
72
+ // Pull the row's original data into an object
73
+ const nodes = {};
74
+ tree.forEach(item => {
75
+ const originalItem = item.original;
76
+ originalItem.children = [];
77
+ nodes[item.uid] = item.original;
78
+ });
79
+ const newUserTree = [];
80
+ tree.forEach(item => {
81
+ // If row has parent, insert it to it's subrows
82
+ // otherwise append it to the new user data
83
+ if (item.parentId !== null && item.parentId !== undefined && item.parentId !== '__ds_tree_root') {
84
+ var _parentNode$children;
85
+
86
+ const parentNode = nodes[item.parentId];
87
+ (_parentNode$children = parentNode.children) === null || _parentNode$children === void 0 ? void 0 : _parentNode$children.push(item.original);
88
+ } else if (item.uid !== '__ds_tree_root') newUserTree.push(item.original);
89
+ }); // Tell the user that the order has change, he can chose to commit it or not
90
+
91
+ onOrderChange(newUserTree, data, flattenedItems[indexes.fromIndex]);
92
+ }, [onOrderChange, data, flattenedItems]);
93
+ const {
94
+ dndContextProps,
95
+ sortableContextProps,
96
+ activeId,
97
+ activeIndex,
98
+ depth,
99
+ dropIndicatorPosition,
100
+ visibleItems,
101
+ isDropValid
102
+ } = dsDragAndDrop.useTreeDndkitConfig({
103
+ flattenedItems,
104
+ visibleItems: flattenedVisibleTreeForDnD,
105
+ isHorizontalDnD: false,
106
+ isExpandable: true,
107
+ onReorder,
108
+ getIsDropValid,
109
+ maxDragAndDropLevel: Infinity
110
+ });
111
+ if (lastActiveId !== activeId && activeId) setLastActiveId(activeId);
112
+ if (withDragAndDrop) return /*#__PURE__*/jsxRuntime.jsxs(core.DndContext, _objectSpread(_objectSpread({}, dndContextProps), {}, {
113
+ children: [/*#__PURE__*/jsxRuntime.jsx(sortable.SortableContext, _objectSpread(_objectSpread({}, sortableContextProps), {}, {
114
+ children: /*#__PURE__*/_jsx__default["default"](DnDTreeContext.DnDTreeContext.Provider, {
115
+ value: {
116
+ activeIndex,
117
+ depth,
118
+ visibleItems: visibleItems.map(item => item.original),
119
+ dropIndicatorPosition,
120
+ lastActiveId,
121
+ setLastActiveId,
122
+ isDropValid
123
+ }
124
+ }, void 0, /*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread({}, props)))
125
+ })), /*#__PURE__*/_jsx__default["default"](core.DragOverlay, {
126
+ style: {
127
+ width: 'auto'
128
+ }
129
+ }, void 0, activeId ? /*#__PURE__*/_jsx__default["default"](TreeItem.TreeItem, {
130
+ itemIndex: activeIndex,
131
+ item: ensure(flattenedVisibleTree.find(item => item.id.toString() === activeId)),
132
+ isDragOverlay: true
133
+ }) : null)]
134
+ }));
135
+ return /*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread({}, props));
136
+ };
137
+
138
+ exports.withConditionalDnDRowContext = withConditionalDnDRowContext;
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _jsx = require('@babel/runtime/helpers/jsx');
11
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
12
+ var React = require('react');
13
+ var sortable = require('@dnd-kit/sortable');
14
+ var SortableItemContext = require('./SortableItemContext.js');
15
+ var TreeViewContext = require('../TreeViewContext.js');
16
+ var DnDTreeContext = require('./DnDTreeContext.js');
17
+ var jsxRuntime = require('react/jsx-runtime');
18
+
19
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
+
21
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
22
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
23
+
24
+ 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; }
25
+
26
+ 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__default["default"](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; }
27
+ const withDnDSortableItemContext = Component => props => {
28
+ const {
29
+ withDragAndDrop
30
+ } = React.useContext(TreeViewContext["default"]);
31
+ const {
32
+ dropIndicatorPosition,
33
+ lastActiveId,
34
+ setLastActiveId,
35
+ isDropValid
36
+ } = React.useContext(DnDTreeContext.DnDTreeContext);
37
+ const id = props.item.id.toString(); // onMount generate unique options, so everyting is only ran once
38
+
39
+ const draggableOptions = React.useMemo(() => ({
40
+ id
41
+ }), [id]);
42
+ const useSortableHelpers = sortable.useSortable(draggableOptions); // calculate all the "useSortable" values as per required
43
+
44
+ const draggableProps = React.useMemo(() => {
45
+ if (!withDragAndDrop) return false;
46
+ const {
47
+ index,
48
+ overIndex
49
+ } = useSortableHelpers;
50
+ return _objectSpread(_objectSpread({}, useSortableHelpers), {}, {
51
+ shouldShowDropIndicatorPosition: overIndex === index,
52
+ dropIndicatorPosition,
53
+ lastActiveId,
54
+ setLastActiveId,
55
+ isDropValid
56
+ });
57
+ }, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid]); // we use a context so we can easly access information wherever without bubbling down
58
+ // this context is all Memoized so as long as component is not re-mounted,
59
+ // the context won't trigger un-required renders per-se...
60
+
61
+ const ctx = React.useMemo(() => ({
62
+ draggableProps
63
+ }), [draggableProps]); // we always add the context, if draggableProps===false we don't have the DnD enabled.
64
+
65
+ return /*#__PURE__*/_jsx__default["default"](SortableItemContext.SortableItemContext.Provider, {
66
+ value: ctx
67
+ }, void 0, /*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread({}, props)));
68
+ };
69
+
70
+ exports.withDnDSortableItemContext = withDnDSortableItemContext;
package/cjs/index.js CHANGED
@@ -16,7 +16,6 @@ var TreeViewSearchBar = require('./related-components/TreeViewSearchBar.js');
16
16
 
17
17
  exports.TreeView = TreeView.TreeView;
18
18
  exports.TreeViewWithSchema = TreeView.TreeViewWithSchema;
19
- exports.TreeDnD = TreeDndPlugin.TreeDnD;
20
19
  exports.TreeDndPlugin = TreeDndPlugin.TreeDndPlugin;
21
20
  exports.TreeRovingPlugin = TreeRovingPlugin.TreeRovingPlugin;
22
21
  exports.SelectablePluginTree = SelectablePluginTree.SelectablePluginTree;
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
+ var React = require('react');
12
+ var dsIcons = require('@elliemae/ds-icons');
13
+ var SortableItemContext = require('../hoc/SortableItemContext.js');
14
+
15
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
+
17
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
18
+
19
+ 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; }
20
+
21
+ 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__default["default"](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; }
22
+ const DnDHandle = _ref => {
23
+ let {
24
+ id,
25
+ isDragOverlay
26
+ } = _ref;
27
+ const {
28
+ draggableProps
29
+ } = React.useContext(SortableItemContext.SortableItemContext);
30
+ const isDragging = draggableProps && draggableProps.isDragging;
31
+ return /*#__PURE__*/React.createElement(dsIcons.GripperVertical, _objectSpread(_objectSpread({
32
+ role: "button"
33
+ }, draggableProps && _objectSpread(_objectSpread({}, draggableProps.listeners), draggableProps.attributes)), {}, {
34
+ "data-testid": "drag-handle",
35
+ "data-isactive": draggableProps && !!draggableProps.active,
36
+ "data-isdragoverlay": isDragOverlay,
37
+ id: "".concat(id, "-drag-handle"),
38
+ key: "".concat(id, "-drag-handle"),
39
+ className: "drag-handle ".concat(isDragging ? '' : 'focuseable'),
40
+ color: ['brand-primary', '800'],
41
+ size: "s",
42
+ tabIndex: 0
43
+ }));
44
+ };
45
+
46
+ exports.DnDHandle = DnDHandle;
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ var _jsx = require('@babel/runtime/helpers/jsx');
4
+ require('react');
5
+ var styled = require('styled-components');
6
+ var SortableItemContext = require('../hoc/SortableItemContext.js');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
12
+ var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
13
+
14
+ const getPositionStyles = _ref => {
15
+ let {
16
+ dropIndicatorPosition
17
+ } = _ref;
18
+ return "\n top: ".concat(dropIndicatorPosition === SortableItemContext.DropIndicatorPosition.Before ? '0' : 'unset', ";\n bottom: ").concat(dropIndicatorPosition === SortableItemContext.DropIndicatorPosition.After ? '0' : 'unset', ";\n left: -2px;\n ");
19
+ };
20
+
21
+ const getCircleStyles = _ref2 => {
22
+ let {
23
+ dropIndicatorPosition
24
+ } = _ref2;
25
+ return {
26
+ position: 'absolute',
27
+ zIndex: 20,
28
+ top: dropIndicatorPosition === SortableItemContext.DropIndicatorPosition.After ? 'unset' : '-2px',
29
+ bottom: dropIndicatorPosition === SortableItemContext.DropIndicatorPosition.Before ? 'unset' : '-2px',
30
+ left: '0px',
31
+ opacity: 1
32
+ };
33
+ };
34
+
35
+ const StyledIndicator = /*#__PURE__*/styled__default["default"].div.withConfig({
36
+ componentId: "sc-1812zh0-0"
37
+ })(["position:absolute;", " box-sizing:border-box;width:", ";height:", ";background-color:", ";z-index:20;"], getPositionStyles, props => props.vertical ? '2px' : '100%', props => props.vertical ? '100%' : '2px', _ref3 => {
38
+ let {
39
+ isDropValid,
40
+ theme
41
+ } = _ref3;
42
+ return isDropValid ? theme.colors.brand[600] : theme.colors.danger[900];
43
+ });
44
+
45
+ const CircleIndicator = (style, isDropValid) => /*#__PURE__*/_jsx__default["default"]("svg", {
46
+ height: "6",
47
+ width: "6",
48
+ style: style
49
+ }, void 0, /*#__PURE__*/_jsx__default["default"]("circle", {
50
+ cx: "3",
51
+ cy: "3",
52
+ r: "3",
53
+ strokeWidth: "0",
54
+ fill: isDropValid ? '#1E79C2' : '#C64252'
55
+ }));
56
+
57
+ const DropIndicator = _ref4 => {
58
+ let {
59
+ dropIndicatorPosition,
60
+ isLast,
61
+ isDropValid
62
+ } = _ref4;
63
+ if (![SortableItemContext.DropIndicatorPosition.After, SortableItemContext.DropIndicatorPosition.Before].includes(dropIndicatorPosition)) return null;
64
+ const safeDropIndicatorPosition = isLast ? SortableItemContext.DropIndicatorPosition.Before : dropIndicatorPosition;
65
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
66
+ children: [CircleIndicator(getCircleStyles({
67
+ dropIndicatorPosition: safeDropIndicatorPosition
68
+ }), isDropValid), /*#__PURE__*/_jsx__default["default"](StyledIndicator, {
69
+ dropIndicatorPosition: safeDropIndicatorPosition,
70
+ isDropValid: isDropValid
71
+ })]
72
+ });
73
+ };
74
+
75
+ module.exports = DropIndicator;