@elliemae/ds-treeview 2.3.2-next.0 → 2.4.0-next.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.
- package/cjs/hoc/DnDTreeContext.js +0 -2
- package/cjs/hoc/WithConditionalDnDContext.js +24 -7
- package/cjs/hoc/WithDnDSortableItemContext.js +1 -5
- package/cjs/utils/group-expands-helpers.js +1 -1
- package/esm/hoc/DnDTreeContext.js +0 -2
- package/esm/hoc/WithConditionalDnDContext.js +27 -9
- package/esm/hoc/WithDnDSortableItemContext.js +1 -5
- package/esm/utils/group-expands-helpers.js +1 -1
- package/package.json +10 -10
- package/types/hoc/DnDTreeContext.d.ts +0 -2
- package/types/hoc/SortableItemContext.d.ts +0 -2
|
@@ -10,8 +10,6 @@ const DnDTreeContext = /*#__PURE__*/React.createContext({
|
|
|
10
10
|
activeIndex: undefined,
|
|
11
11
|
visibleItems: undefined,
|
|
12
12
|
dropIndicatorPosition: SortableItemContext.DropIndicatorPosition.None,
|
|
13
|
-
lastActiveId: undefined,
|
|
14
|
-
setLastActiveId: undefined,
|
|
15
13
|
isDropValid: false
|
|
16
14
|
});
|
|
17
15
|
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
6
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
7
|
-
require('core-js/modules/web.dom-collections.iterator.js');
|
|
8
7
|
require('core-js/modules/esnext.async-iterator.map.js');
|
|
9
8
|
require('core-js/modules/esnext.iterator.map.js');
|
|
10
9
|
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
@@ -21,13 +20,14 @@ var dsDragAndDrop = require('@elliemae/ds-drag-and-drop');
|
|
|
21
20
|
var TreeViewContext = require('../TreeViewContext.js');
|
|
22
21
|
var TreeItem = require('../parts/TreeItem.js');
|
|
23
22
|
var DnDTreeContext = require('./DnDTreeContext.js');
|
|
23
|
+
var SortableItemContext = require('./SortableItemContext.js');
|
|
24
|
+
var groupExpandsHelpers = require('../utils/group-expands-helpers.js');
|
|
24
25
|
var jsxRuntime = require('react/jsx-runtime');
|
|
25
26
|
|
|
26
27
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
27
28
|
|
|
28
29
|
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
29
30
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
30
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
31
31
|
|
|
32
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
33
|
|
|
@@ -45,7 +45,6 @@ const ensure = function (argument) {
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
const withConditionalDnDRowContext = Component => props => {
|
|
48
|
-
const [lastActiveId, setLastActiveId] = React__default["default"].useState('');
|
|
49
48
|
const {
|
|
50
49
|
props: {
|
|
51
50
|
data,
|
|
@@ -53,6 +52,8 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
53
52
|
getIsDropValid
|
|
54
53
|
},
|
|
55
54
|
flattenedItems,
|
|
55
|
+
updateUserExpandedState,
|
|
56
|
+
triggerTreeRerender,
|
|
56
57
|
visibleItems: flattenedVisibleTree,
|
|
57
58
|
withDragAndDrop
|
|
58
59
|
} = React.useContext(TreeViewContext["default"]);
|
|
@@ -98,7 +99,8 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
98
99
|
depth,
|
|
99
100
|
dropIndicatorPosition,
|
|
100
101
|
visibleItems,
|
|
101
|
-
isDropValid
|
|
102
|
+
isDropValid,
|
|
103
|
+
overId
|
|
102
104
|
} = dsDragAndDrop.useTreeDndkitConfig({
|
|
103
105
|
flattenedItems,
|
|
104
106
|
visibleItems: flattenedVisibleTreeForDnD,
|
|
@@ -108,7 +110,24 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
108
110
|
getIsDropValid,
|
|
109
111
|
maxDragAndDropLevel: Infinity
|
|
110
112
|
});
|
|
111
|
-
|
|
113
|
+
const timeoutRef = React.useRef();
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
116
|
+
|
|
117
|
+
if (dropIndicatorPosition === SortableItemContext.DropIndicatorPosition.Inside && overId) {
|
|
118
|
+
timeoutRef.current = setTimeout(() => {
|
|
119
|
+
const overItem = visibleItems.find(item => item.uid === overId);
|
|
120
|
+
|
|
121
|
+
if (overItem) {
|
|
122
|
+
const realOverItem = overItem.original;
|
|
123
|
+
|
|
124
|
+
if (realOverItem.isGroup && !realOverItem.isExpanded) {
|
|
125
|
+
groupExpandsHelpers.toggleItemExpand(realOverItem, triggerTreeRerender, updateUserExpandedState);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}, 1000);
|
|
129
|
+
}
|
|
130
|
+
}, [overId, dropIndicatorPosition, triggerTreeRerender, visibleItems, updateUserExpandedState]);
|
|
112
131
|
if (withDragAndDrop) return /*#__PURE__*/jsxRuntime.jsxs(core.DndContext, _objectSpread(_objectSpread({}, dndContextProps), {}, {
|
|
113
132
|
children: [/*#__PURE__*/jsxRuntime.jsx(sortable.SortableContext, _objectSpread(_objectSpread({}, sortableContextProps), {}, {
|
|
114
133
|
children: /*#__PURE__*/_jsx__default["default"](DnDTreeContext.DnDTreeContext.Provider, {
|
|
@@ -117,8 +136,6 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
117
136
|
depth,
|
|
118
137
|
visibleItems: visibleItems.map(item => item.original),
|
|
119
138
|
dropIndicatorPosition,
|
|
120
|
-
lastActiveId,
|
|
121
|
-
setLastActiveId,
|
|
122
139
|
isDropValid
|
|
123
140
|
}
|
|
124
141
|
}, void 0, /*#__PURE__*/jsxRuntime.jsx(Component, _objectSpread({}, props)))
|
|
@@ -30,8 +30,6 @@ const withDnDSortableItemContext = Component => props => {
|
|
|
30
30
|
} = React.useContext(TreeViewContext["default"]);
|
|
31
31
|
const {
|
|
32
32
|
dropIndicatorPosition,
|
|
33
|
-
lastActiveId,
|
|
34
|
-
setLastActiveId,
|
|
35
33
|
isDropValid
|
|
36
34
|
} = React.useContext(DnDTreeContext.DnDTreeContext);
|
|
37
35
|
const id = props.item.id.toString(); // onMount generate unique options, so everyting is only ran once
|
|
@@ -50,11 +48,9 @@ const withDnDSortableItemContext = Component => props => {
|
|
|
50
48
|
return _objectSpread(_objectSpread({}, useSortableHelpers), {}, {
|
|
51
49
|
shouldShowDropIndicatorPosition: overIndex === index,
|
|
52
50
|
dropIndicatorPosition,
|
|
53
|
-
lastActiveId,
|
|
54
|
-
setLastActiveId,
|
|
55
51
|
isDropValid
|
|
56
52
|
});
|
|
57
|
-
}, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition,
|
|
53
|
+
}, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, isDropValid]); // we use a context so we can easly access information wherever without bubbling down
|
|
58
54
|
// this context is all Memoized so as long as component is not re-mounted,
|
|
59
55
|
// the context won't trigger un-required renders per-se...
|
|
60
56
|
|
|
@@ -32,8 +32,8 @@ const toggleItemExpand = function (itemToToggle, triggerTreeRerender, updateUser
|
|
|
32
32
|
|
|
33
33
|
if (itemToToggle.node.model.isGroup) {
|
|
34
34
|
itemToToggle.node.model.isExpanded = !isExpanded;
|
|
35
|
-
triggerTreeRerender();
|
|
36
35
|
updateUserExpandedState();
|
|
36
|
+
triggerTreeRerender();
|
|
37
37
|
setTimeout(() => {
|
|
38
38
|
if (typeof virtualIndex === 'number') scrollTo(virtualIndex, {
|
|
39
39
|
align: 'start'
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.filter.js';
|
|
3
1
|
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
4
2
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
5
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
6
3
|
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
7
4
|
import 'core-js/modules/esnext.iterator.map.js';
|
|
8
5
|
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
@@ -10,13 +7,17 @@ import 'core-js/modules/esnext.iterator.constructor.js';
|
|
|
10
7
|
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
11
8
|
import 'core-js/modules/esnext.async-iterator.find.js';
|
|
12
9
|
import 'core-js/modules/esnext.iterator.find.js';
|
|
13
|
-
import
|
|
10
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
11
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
12
|
+
import { useContext, useMemo, useCallback, useRef, useEffect } from 'react';
|
|
14
13
|
import { DndContext, DragOverlay } from '@dnd-kit/core';
|
|
15
14
|
import { SortableContext } from '@dnd-kit/sortable';
|
|
16
15
|
import { useTreeDndkitConfig } from '@elliemae/ds-drag-and-drop';
|
|
17
16
|
import TreeViewContext from '../TreeViewContext.js';
|
|
18
17
|
import { TreeItem } from '../parts/TreeItem.js';
|
|
19
18
|
import { DnDTreeContext } from './DnDTreeContext.js';
|
|
19
|
+
import { DropIndicatorPosition } from './SortableItemContext.js';
|
|
20
|
+
import { toggleItemExpand } from '../utils/group-expands-helpers.js';
|
|
20
21
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
21
22
|
|
|
22
23
|
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; }
|
|
@@ -35,7 +36,6 @@ const ensure = function (argument) {
|
|
|
35
36
|
|
|
36
37
|
|
|
37
38
|
const withConditionalDnDRowContext = Component => props => {
|
|
38
|
-
const [lastActiveId, setLastActiveId] = React.useState('');
|
|
39
39
|
const {
|
|
40
40
|
props: {
|
|
41
41
|
data,
|
|
@@ -43,6 +43,8 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
43
43
|
getIsDropValid
|
|
44
44
|
},
|
|
45
45
|
flattenedItems,
|
|
46
|
+
updateUserExpandedState,
|
|
47
|
+
triggerTreeRerender,
|
|
46
48
|
visibleItems: flattenedVisibleTree,
|
|
47
49
|
withDragAndDrop
|
|
48
50
|
} = useContext(TreeViewContext);
|
|
@@ -88,7 +90,8 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
88
90
|
depth,
|
|
89
91
|
dropIndicatorPosition,
|
|
90
92
|
visibleItems,
|
|
91
|
-
isDropValid
|
|
93
|
+
isDropValid,
|
|
94
|
+
overId
|
|
92
95
|
} = useTreeDndkitConfig({
|
|
93
96
|
flattenedItems,
|
|
94
97
|
visibleItems: flattenedVisibleTreeForDnD,
|
|
@@ -98,7 +101,24 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
98
101
|
getIsDropValid,
|
|
99
102
|
maxDragAndDropLevel: Infinity
|
|
100
103
|
});
|
|
101
|
-
|
|
104
|
+
const timeoutRef = useRef();
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
|
107
|
+
|
|
108
|
+
if (dropIndicatorPosition === DropIndicatorPosition.Inside && overId) {
|
|
109
|
+
timeoutRef.current = setTimeout(() => {
|
|
110
|
+
const overItem = visibleItems.find(item => item.uid === overId);
|
|
111
|
+
|
|
112
|
+
if (overItem) {
|
|
113
|
+
const realOverItem = overItem.original;
|
|
114
|
+
|
|
115
|
+
if (realOverItem.isGroup && !realOverItem.isExpanded) {
|
|
116
|
+
toggleItemExpand(realOverItem, triggerTreeRerender, updateUserExpandedState);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, 1000);
|
|
120
|
+
}
|
|
121
|
+
}, [overId, dropIndicatorPosition, triggerTreeRerender, visibleItems, updateUserExpandedState]);
|
|
102
122
|
if (withDragAndDrop) return /*#__PURE__*/jsxs(DndContext, _objectSpread(_objectSpread({}, dndContextProps), {}, {
|
|
103
123
|
children: [/*#__PURE__*/jsx(SortableContext, _objectSpread(_objectSpread({}, sortableContextProps), {}, {
|
|
104
124
|
children: /*#__PURE__*/_jsx(DnDTreeContext.Provider, {
|
|
@@ -107,8 +127,6 @@ const withConditionalDnDRowContext = Component => props => {
|
|
|
107
127
|
depth,
|
|
108
128
|
visibleItems: visibleItems.map(item => item.original),
|
|
109
129
|
dropIndicatorPosition,
|
|
110
|
-
lastActiveId,
|
|
111
|
-
setLastActiveId,
|
|
112
130
|
isDropValid
|
|
113
131
|
}
|
|
114
132
|
}, void 0, /*#__PURE__*/jsx(Component, _objectSpread({}, props)))
|
|
@@ -21,8 +21,6 @@ const withDnDSortableItemContext = Component => props => {
|
|
|
21
21
|
} = useContext(TreeViewContext);
|
|
22
22
|
const {
|
|
23
23
|
dropIndicatorPosition,
|
|
24
|
-
lastActiveId,
|
|
25
|
-
setLastActiveId,
|
|
26
24
|
isDropValid
|
|
27
25
|
} = useContext(DnDTreeContext);
|
|
28
26
|
const id = props.item.id.toString(); // onMount generate unique options, so everyting is only ran once
|
|
@@ -41,11 +39,9 @@ const withDnDSortableItemContext = Component => props => {
|
|
|
41
39
|
return _objectSpread(_objectSpread({}, useSortableHelpers), {}, {
|
|
42
40
|
shouldShowDropIndicatorPosition: overIndex === index,
|
|
43
41
|
dropIndicatorPosition,
|
|
44
|
-
lastActiveId,
|
|
45
|
-
setLastActiveId,
|
|
46
42
|
isDropValid
|
|
47
43
|
});
|
|
48
|
-
}, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition,
|
|
44
|
+
}, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, isDropValid]); // we use a context so we can easly access information wherever without bubbling down
|
|
49
45
|
// this context is all Memoized so as long as component is not re-mounted,
|
|
50
46
|
// the context won't trigger un-required renders per-se...
|
|
51
47
|
|
|
@@ -28,8 +28,8 @@ const toggleItemExpand = function (itemToToggle, triggerTreeRerender, updateUser
|
|
|
28
28
|
|
|
29
29
|
if (itemToToggle.node.model.isGroup) {
|
|
30
30
|
itemToToggle.node.model.isExpanded = !isExpanded;
|
|
31
|
-
triggerTreeRerender();
|
|
32
31
|
updateUserExpandedState();
|
|
32
|
+
triggerTreeRerender();
|
|
33
33
|
setTimeout(() => {
|
|
34
34
|
if (typeof virtualIndex === 'number') scrollTo(virtualIndex, {
|
|
35
35
|
align: 'start'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-treeview",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-next.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Tree View",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -229,15 +229,15 @@
|
|
|
229
229
|
"dependencies": {
|
|
230
230
|
"@dnd-kit/core": "~4.0.1",
|
|
231
231
|
"@dnd-kit/sortable": "~5.0.0",
|
|
232
|
-
"@elliemae/ds-button": "2.
|
|
233
|
-
"@elliemae/ds-circular-progress-indicator": "2.
|
|
234
|
-
"@elliemae/ds-classnames": "2.
|
|
235
|
-
"@elliemae/ds-drag-and-drop": "2.
|
|
236
|
-
"@elliemae/ds-form": "2.
|
|
237
|
-
"@elliemae/ds-icons": "2.
|
|
238
|
-
"@elliemae/ds-props-helpers": "2.
|
|
239
|
-
"@elliemae/ds-truncated-tooltip-text": "2.
|
|
240
|
-
"@elliemae/ds-utilities": "2.
|
|
232
|
+
"@elliemae/ds-button": "2.4.0-next.0",
|
|
233
|
+
"@elliemae/ds-circular-progress-indicator": "2.4.0-next.0",
|
|
234
|
+
"@elliemae/ds-classnames": "2.4.0-next.0",
|
|
235
|
+
"@elliemae/ds-drag-and-drop": "2.4.0-next.0",
|
|
236
|
+
"@elliemae/ds-form": "2.4.0-next.0",
|
|
237
|
+
"@elliemae/ds-icons": "2.4.0-next.0",
|
|
238
|
+
"@elliemae/ds-props-helpers": "2.4.0-next.0",
|
|
239
|
+
"@elliemae/ds-truncated-tooltip-text": "2.4.0-next.0",
|
|
240
|
+
"@elliemae/ds-utilities": "2.4.0-next.0",
|
|
241
241
|
"react-desc": "~4.1.3",
|
|
242
242
|
"react-highlight-words": "~0.17.0",
|
|
243
243
|
"react-virtual": "~2.8.2",
|
|
@@ -6,8 +6,6 @@ declare type DnDTreeContextType = {
|
|
|
6
6
|
activeIndex: number | undefined;
|
|
7
7
|
visibleItems: DSTreeviewT.Item[] | undefined;
|
|
8
8
|
dropIndicatorPosition: DropIndicatorPosition;
|
|
9
|
-
lastActiveId: string | undefined;
|
|
10
|
-
setLastActiveId: React.Dispatch<React.SetStateAction<string>> | undefined;
|
|
11
9
|
isDropValid: boolean;
|
|
12
10
|
};
|
|
13
11
|
export declare const DnDTreeContext: import("react").Context<DnDTreeContextType>;
|
|
@@ -10,8 +10,6 @@ export declare type SortableItemContextType = {
|
|
|
10
10
|
draggableProps: false | (ReturnType<typeof useSortable> & {
|
|
11
11
|
dropIndicatorPosition: DropIndicatorPosition;
|
|
12
12
|
shouldShowDropIndicatorPosition: boolean;
|
|
13
|
-
lastActiveId?: string;
|
|
14
|
-
setLastActiveId?: React.Dispatch<React.SetStateAction<string>>;
|
|
15
13
|
isDropValid: boolean;
|
|
16
14
|
});
|
|
17
15
|
};
|