@elliemae/ds-treeview 2.2.0-alpha.4 → 3.0.0-next.2
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/TreeView.js +27 -49
- package/cjs/TreeViewContext.js +37 -61
- package/cjs/config/cssClassesConstants.js +13 -41
- package/cjs/config/useTreeview.js +78 -116
- package/cjs/hoc/DnDTreeContext.js +18 -0
- package/cjs/hoc/SortableItemContext.js +21 -0
- package/cjs/hoc/WithConditionalDnDContext.js +138 -0
- package/cjs/hoc/WithDnDSortableItemContext.js +70 -0
- package/cjs/index.js +26 -37
- package/cjs/parts/CheckboxSelectable.js +59 -70
- package/cjs/parts/ChildrenCountDisplayer.js +28 -45
- package/cjs/parts/DnDHandle.js +46 -0
- package/cjs/parts/DropIndicator.js +75 -0
- package/cjs/parts/ExpandCaret.js +83 -85
- package/cjs/parts/Icon.js +31 -46
- package/cjs/parts/NestingSpace.js +35 -43
- package/cjs/parts/RadioSelectable.js +37 -52
- package/cjs/parts/TreeItem.js +141 -147
- package/cjs/parts/TreeItemText.js +95 -88
- package/cjs/parts/TreeList.js +130 -119
- package/cjs/plugins/dnd/TreeDndPlugin.js +7 -59
- package/cjs/plugins/dnd/index.js +9 -28
- package/cjs/plugins/index.js +21 -34
- package/cjs/plugins/roving/TreeRovingPlugin.js +7 -35
- package/cjs/plugins/roving/index.js +9 -28
- package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -35
- package/cjs/plugins/searchable/index.js +9 -28
- package/cjs/plugins/selectable/SelectablePluginTree.js +7 -35
- package/cjs/plugins/selectable/index.js +9 -28
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -35
- package/cjs/plugins/toolbar/index.js +9 -28
- package/cjs/plugins/tree/TreeDataPlugin.js +7 -35
- package/cjs/plugins/tree/index.js +9 -28
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -35
- package/cjs/plugins/virtualization/index.js +9 -28
- package/cjs/react-desc-prop-types.js +54 -82
- package/cjs/related-components/TreeViewSearchBar.js +40 -42
- package/cjs/sharedTypes.js +2 -27
- package/cjs/utils/array-helpers.js +11 -35
- package/cjs/utils/group-expands-helpers.js +59 -86
- package/cjs/utils/keyboard-helpers.js +90 -85
- package/cjs/utils/object-helpers.js +36 -43
- package/cjs/utils/refs-helpers.js +22 -43
- package/cjs/utils/selectable-helper.js +53 -61
- package/cjs/utils/string-helpers.js +7 -35
- package/cjs/utils/tree-helpers.js +161 -105
- package/cjs/utils/useInstanceRefActions.js +43 -54
- package/cjs/utils/useTree.js +80 -76
- package/esm/TreeView.js +16 -18
- package/esm/TreeViewContext.js +31 -32
- package/esm/config/cssClassesConstants.js +6 -12
- package/esm/config/useTreeview.js +56 -73
- package/esm/hoc/DnDTreeContext.js +14 -0
- package/esm/hoc/SortableItemContext.js +17 -0
- package/esm/hoc/WithConditionalDnDContext.js +128 -0
- package/esm/hoc/WithDnDSortableItemContext.js +61 -0
- package/esm/index.js +9 -8
- package/esm/parts/CheckboxSelectable.js +46 -36
- package/esm/parts/ChildrenCountDisplayer.js +20 -16
- package/esm/parts/DnDHandle.js +38 -0
- package/esm/parts/DropIndicator.js +68 -0
- package/esm/parts/ExpandCaret.js +72 -54
- package/esm/parts/Icon.js +22 -16
- package/esm/parts/NestingSpace.js +27 -14
- package/esm/parts/RadioSelectable.js +28 -20
- package/esm/parts/TreeItem.js +125 -114
- package/esm/parts/TreeItemText.js +85 -58
- package/esm/parts/TreeList.js +119 -91
- package/esm/plugins/dnd/TreeDndPlugin.js +3 -30
- package/esm/plugins/dnd/index.js +1 -3
- package/esm/plugins/index.js +7 -9
- package/esm/plugins/roving/TreeRovingPlugin.js +3 -6
- package/esm/plugins/roving/index.js +1 -3
- package/esm/plugins/searchable/SearchableTreePlugin.js +3 -6
- package/esm/plugins/searchable/index.js +1 -3
- package/esm/plugins/selectable/SelectablePluginTree.js +3 -6
- package/esm/plugins/selectable/index.js +1 -3
- package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -6
- package/esm/plugins/toolbar/index.js +1 -3
- package/esm/plugins/tree/TreeDataPlugin.js +3 -6
- package/esm/plugins/tree/index.js +1 -3
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -6
- package/esm/plugins/virtualization/index.js +1 -3
- package/esm/react-desc-prop-types.js +44 -47
- package/esm/related-components/TreeViewSearchBar.js +32 -13
- package/esm/sharedTypes.js +1 -2
- package/esm/utils/array-helpers.js +6 -6
- package/esm/utils/group-expands-helpers.js +46 -56
- package/esm/utils/keyboard-helpers.js +74 -46
- package/esm/utils/object-helpers.js +31 -14
- package/esm/utils/refs-helpers.js +19 -15
- package/esm/utils/selectable-helper.js +43 -32
- package/esm/utils/string-helpers.js +3 -6
- package/esm/utils/tree-helpers.js +143 -73
- package/esm/utils/useInstanceRefActions.js +35 -21
- package/esm/utils/useTree.js +59 -35
- package/package.json +35 -19
- package/types/hoc/DnDTreeContext.d.ts +14 -0
- package/types/hoc/SortableItemContext.d.ts +19 -0
- package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
- package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
- package/types/parts/DnDHandle.d.ts +6 -0
- package/types/parts/DropIndicator.d.ts +10 -0
- package/types/parts/TreeItem.d.ts +4 -11
- package/types/parts/TreeList.d.ts +0 -4
- package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
- package/types/react-desc-prop-types.d.ts +17 -3
- package/types/sharedTypes.d.ts +1 -8
- package/types/utils/keyboard-helpers.d.ts +2 -1
- package/types/utils/refs-helpers.d.ts +1 -1
- package/types/utils/tree-helpers.d.ts +4 -1
- package/types/utils/useTree.d.ts +1 -0
- package/cjs/TreeView.js.map +0 -7
- package/cjs/TreeViewContext.js.map +0 -7
- package/cjs/config/cssClassesConstants.js.map +0 -7
- package/cjs/config/useTreeview.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/parts/CheckboxSelectable.js.map +0 -7
- package/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
- package/cjs/parts/ExpandCaret.js.map +0 -7
- package/cjs/parts/Icon.js.map +0 -7
- package/cjs/parts/NestingSpace.js.map +0 -7
- package/cjs/parts/RadioSelectable.js.map +0 -7
- package/cjs/parts/TreeItem.js.map +0 -7
- package/cjs/parts/TreeItemText.js.map +0 -7
- package/cjs/parts/TreeList.js.map +0 -7
- package/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
- package/cjs/plugins/dnd/index.js.map +0 -7
- package/cjs/plugins/index.js.map +0 -7
- package/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
- package/cjs/plugins/roving/index.js.map +0 -7
- package/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
- package/cjs/plugins/searchable/index.js.map +0 -7
- package/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
- package/cjs/plugins/selectable/index.js.map +0 -7
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
- package/cjs/plugins/toolbar/index.js.map +0 -7
- package/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
- package/cjs/plugins/tree/index.js.map +0 -7
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
- package/cjs/plugins/virtualization/index.js.map +0 -7
- package/cjs/react-desc-prop-types.js.map +0 -7
- package/cjs/related-components/TreeViewSearchBar.js.map +0 -7
- package/cjs/sharedTypes.js.map +0 -7
- package/cjs/utils/array-helpers.js.map +0 -7
- package/cjs/utils/dnd-helpers.js +0 -146
- package/cjs/utils/dnd-helpers.js.map +0 -7
- package/cjs/utils/group-expands-helpers.js.map +0 -7
- package/cjs/utils/keyboard-helpers.js.map +0 -7
- package/cjs/utils/object-helpers.js.map +0 -7
- package/cjs/utils/refs-helpers.js.map +0 -7
- package/cjs/utils/selectable-helper.js.map +0 -7
- package/cjs/utils/string-helpers.js.map +0 -7
- package/cjs/utils/tree-helpers.js.map +0 -7
- package/cjs/utils/useDnDHelpers.js +0 -199
- package/cjs/utils/useDnDHelpers.js.map +0 -7
- package/cjs/utils/useInstanceRefActions.js.map +0 -7
- package/cjs/utils/useTree.js.map +0 -7
- package/esm/TreeView.js.map +0 -7
- package/esm/TreeViewContext.js.map +0 -7
- package/esm/config/cssClassesConstants.js.map +0 -7
- package/esm/config/useTreeview.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/parts/CheckboxSelectable.js.map +0 -7
- package/esm/parts/ChildrenCountDisplayer.js.map +0 -7
- package/esm/parts/ExpandCaret.js.map +0 -7
- package/esm/parts/Icon.js.map +0 -7
- package/esm/parts/NestingSpace.js.map +0 -7
- package/esm/parts/RadioSelectable.js.map +0 -7
- package/esm/parts/TreeItem.js.map +0 -7
- package/esm/parts/TreeItemText.js.map +0 -7
- package/esm/parts/TreeList.js.map +0 -7
- package/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
- package/esm/plugins/dnd/index.js.map +0 -7
- package/esm/plugins/index.js.map +0 -7
- package/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
- package/esm/plugins/roving/index.js.map +0 -7
- package/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
- package/esm/plugins/searchable/index.js.map +0 -7
- package/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
- package/esm/plugins/selectable/index.js.map +0 -7
- package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
- package/esm/plugins/toolbar/index.js.map +0 -7
- package/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
- package/esm/plugins/tree/index.js.map +0 -7
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
- package/esm/plugins/virtualization/index.js.map +0 -7
- package/esm/react-desc-prop-types.js.map +0 -7
- package/esm/related-components/TreeViewSearchBar.js.map +0 -7
- package/esm/sharedTypes.js.map +0 -7
- package/esm/utils/array-helpers.js.map +0 -7
- package/esm/utils/dnd-helpers.js +0 -117
- package/esm/utils/dnd-helpers.js.map +0 -7
- package/esm/utils/group-expands-helpers.js.map +0 -7
- package/esm/utils/keyboard-helpers.js.map +0 -7
- package/esm/utils/object-helpers.js.map +0 -7
- package/esm/utils/refs-helpers.js.map +0 -7
- package/esm/utils/selectable-helper.js.map +0 -7
- package/esm/utils/string-helpers.js.map +0 -7
- package/esm/utils/tree-helpers.js.map +0 -7
- package/esm/utils/useDnDHelpers.js +0 -170
- package/esm/utils/useDnDHelpers.js.map +0 -7
- package/esm/utils/useInstanceRefActions.js.map +0 -7
- package/esm/utils/useTree.js.map +0 -7
- package/types/utils/dnd-helpers.d.ts +0 -39
- package/types/utils/useDnDHelpers.d.ts +0 -26
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
8
|
+
import { useRef, useState, useCallback, useMemo, useEffect } from 'react';
|
|
9
|
+
import { useVirtual } from 'react-virtual';
|
|
10
|
+
import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
|
|
11
|
+
import { v4 } from 'uuid';
|
|
12
|
+
import { TreeViewPropTypes } from '../react-desc-prop-types.js';
|
|
13
|
+
import { defaultProps } from '../TreeViewContext.js';
|
|
14
|
+
import { TreeDndPlugin } from '../plugins/dnd/TreeDndPlugin.js';
|
|
15
|
+
import { useTree } from '../utils/useTree.js';
|
|
16
|
+
import { toggleItemExpand, useNotifyExpandedChange } from '../utils/group-expands-helpers.js';
|
|
17
|
+
import { useInstanceRefActions } from '../utils/useInstanceRefActions.js';
|
|
18
|
+
import { useGlobalToggleAllExpandShortcut } from '../utils/keyboard-helpers.js';
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
const useTreeview = props => {
|
|
14
24
|
const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
|
|
15
25
|
useValidateTypescriptPropTypes(propsWithDefault, TreeViewPropTypes);
|
|
16
26
|
const defaultActions = {
|
|
17
27
|
actions: {
|
|
18
|
-
toggleExpandAll: () => {
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
setSelectedItemByVirtualIndex: () => {
|
|
23
|
-
},
|
|
24
|
-
setFocusedItemByVirtualIndex: () => {
|
|
25
|
-
}
|
|
28
|
+
toggleExpandAll: () => {},
|
|
29
|
+
scrollTo: () => {},
|
|
30
|
+
setSelectedItemByVirtualIndex: () => {},
|
|
31
|
+
setFocusedItemByVirtualIndex: () => {}
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
const treeRef = useRef(defaultActions);
|
|
@@ -36,48 +42,44 @@ const useTreeview = (props) => {
|
|
|
36
42
|
selection,
|
|
37
43
|
onInstanceRefInitialized
|
|
38
44
|
} = propsWithDefault;
|
|
39
|
-
const [
|
|
40
|
-
const [isKeyboardDragging, setIsKeyboardDragging] = useState(false);
|
|
41
|
-
const [relativeMouseCord, setRelativeMouseCord] = useState(defaultRelativeMouseCoord);
|
|
42
|
-
const [uniqueTreeViewUUID] = useState(uuidv4());
|
|
43
|
-
const [draggedItem, setDraggedItem] = useState(null);
|
|
45
|
+
const [uniqueTreeViewUUID] = useState(v4());
|
|
44
46
|
const [hoverItem, setHoverItem] = useState(null);
|
|
45
47
|
const [latestToggledItem, setLatestToggledItem] = useState(null);
|
|
46
48
|
const [selectedItem, setSelectedItem] = useState(null);
|
|
47
49
|
const [focusedItem, setFocusedItem] = useState(null);
|
|
48
|
-
const [selectedCheckboxes, setSelectedCheckboxes] = useState({
|
|
49
|
-
...selection
|
|
50
|
-
});
|
|
50
|
+
const [selectedCheckboxes, setSelectedCheckboxes] = useState(_objectSpread({}, selection));
|
|
51
51
|
const [expandedGroups, setExpandedGroups] = useState({});
|
|
52
|
-
const {
|
|
52
|
+
const {
|
|
53
|
+
visibleItems,
|
|
54
|
+
flattenedItems,
|
|
55
|
+
tree,
|
|
56
|
+
treeRoot,
|
|
57
|
+
triggerTreeRerender,
|
|
58
|
+
updateUserExpandedState
|
|
59
|
+
} = useTree(data, propsWithDefault, {
|
|
53
60
|
setExpandedGroups
|
|
54
61
|
});
|
|
55
|
-
const virtualListRef = useRef();
|
|
62
|
+
const virtualListRef = useRef(); // estimateSize should not be really required given what was stated on
|
|
63
|
+
// https://github.com/tannerlinsley/react-virtual/issues/23
|
|
64
|
+
|
|
56
65
|
const virtualListHelpers = useVirtual({
|
|
57
66
|
size: visibleItems.length,
|
|
58
67
|
parentRef: virtualListRef,
|
|
59
68
|
overscan: 15
|
|
60
69
|
});
|
|
61
|
-
const withDragAndDrop = !!(plugins
|
|
70
|
+
const withDragAndDrop = !!(plugins !== null && plugins !== void 0 && plugins.includes(TreeDndPlugin) && onOrderChange);
|
|
62
71
|
const withRadioChecks = isSingleSelect && !isMultiSelect;
|
|
63
72
|
const withCheckboxChecks = !isSingleSelect && isMultiSelect;
|
|
64
73
|
const handleExpandGroup = useCallback(toggleItemExpand, []);
|
|
65
74
|
const ctx = useMemo(() => ({
|
|
66
75
|
props: propsWithDefault,
|
|
67
|
-
setRelativeMouseCord,
|
|
68
|
-
relativeMouseCord,
|
|
69
76
|
virtualListHelpers,
|
|
70
77
|
virtualListRef,
|
|
71
78
|
tree,
|
|
72
79
|
treeRoot,
|
|
73
80
|
visibleItems,
|
|
81
|
+
flattenedItems,
|
|
74
82
|
triggerTreeRerender,
|
|
75
|
-
isDragging,
|
|
76
|
-
setIsDragging,
|
|
77
|
-
isKeyboardDragging,
|
|
78
|
-
setIsKeyboardDragging,
|
|
79
|
-
draggedItem,
|
|
80
|
-
setDraggedItem,
|
|
81
83
|
withRadioChecks,
|
|
82
84
|
withCheckboxChecks,
|
|
83
85
|
withDragAndDrop,
|
|
@@ -96,41 +98,22 @@ const useTreeview = (props) => {
|
|
|
96
98
|
setHoverItem,
|
|
97
99
|
handleExpandGroup,
|
|
98
100
|
updateUserExpandedState
|
|
99
|
-
}), [
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
handleExpandGroup,
|
|
104
|
-
hoverItem,
|
|
105
|
-
isDragging,
|
|
106
|
-
isKeyboardDragging,
|
|
107
|
-
latestToggledItem,
|
|
108
|
-
propsWithDefault,
|
|
109
|
-
relativeMouseCord,
|
|
110
|
-
selectedCheckboxes,
|
|
111
|
-
selectedItem,
|
|
112
|
-
tree,
|
|
113
|
-
treeRoot,
|
|
114
|
-
triggerTreeRerender,
|
|
115
|
-
uniqueTreeViewUUID,
|
|
116
|
-
virtualListHelpers,
|
|
117
|
-
visibleItems,
|
|
118
|
-
withCheckboxChecks,
|
|
119
|
-
withDragAndDrop,
|
|
120
|
-
withRadioChecks,
|
|
121
|
-
updateUserExpandedState
|
|
122
|
-
]);
|
|
123
|
-
if (instanceRef)
|
|
124
|
-
instanceRef.current = treeRef.current;
|
|
101
|
+
}), [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
|
|
102
|
+
// as such we manually pass the second parameter as fit
|
|
103
|
+
|
|
104
|
+
if (instanceRef) instanceRef.current = treeRef.current;
|
|
125
105
|
useInstanceRefActions(treeRef.current, ctx);
|
|
126
106
|
useGlobalToggleAllExpandShortcut(treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
127
|
-
useNotifyExpandedChange(propsWithDefault, ctx);
|
|
107
|
+
useNotifyExpandedChange(propsWithDefault, ctx); // this is an horrible hack.
|
|
108
|
+
// this is required because there is no "on rendered" react-way to check if every children has finished rendering
|
|
109
|
+
// this should be working for now, in the future we may want to review this for a better solution
|
|
110
|
+
|
|
128
111
|
useEffect(() => {
|
|
129
|
-
setTimeout(() => onInstanceRefInitialized(treeRef), 100);
|
|
112
|
+
setTimeout(() => onInstanceRefInitialized(treeRef), 100); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
113
|
}, []);
|
|
131
|
-
return useMemo(() => ({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
useTreeview
|
|
114
|
+
return useMemo(() => ({
|
|
115
|
+
ctx
|
|
116
|
+
}), [ctx]);
|
|
135
117
|
};
|
|
136
|
-
|
|
118
|
+
|
|
119
|
+
export { useTreeview };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
import { DropIndicatorPosition } from './SortableItemContext.js';
|
|
3
|
+
|
|
4
|
+
const DnDTreeContext = /*#__PURE__*/createContext({
|
|
5
|
+
depth: undefined,
|
|
6
|
+
activeIndex: undefined,
|
|
7
|
+
visibleItems: undefined,
|
|
8
|
+
dropIndicatorPosition: DropIndicatorPosition.None,
|
|
9
|
+
lastActiveId: undefined,
|
|
10
|
+
setLastActiveId: undefined,
|
|
11
|
+
isDropValid: false
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export { DnDTreeContext };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
let DropIndicatorPosition;
|
|
4
|
+
|
|
5
|
+
(function (DropIndicatorPosition) {
|
|
6
|
+
DropIndicatorPosition[DropIndicatorPosition["None"] = 0] = "None";
|
|
7
|
+
DropIndicatorPosition[DropIndicatorPosition["Before"] = 1] = "Before";
|
|
8
|
+
DropIndicatorPosition[DropIndicatorPosition["After"] = 2] = "After";
|
|
9
|
+
DropIndicatorPosition[DropIndicatorPosition["Inside"] = 3] = "Inside";
|
|
10
|
+
})(DropIndicatorPosition || (DropIndicatorPosition = {}));
|
|
11
|
+
|
|
12
|
+
/** Context for cross component communication */
|
|
13
|
+
const SortableItemContext = /*#__PURE__*/createContext({
|
|
14
|
+
draggableProps: false
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { DropIndicatorPosition, SortableItemContext };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
3
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
5
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
6
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
8
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
10
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
11
|
+
import 'core-js/modules/esnext.async-iterator.find.js';
|
|
12
|
+
import 'core-js/modules/esnext.iterator.find.js';
|
|
13
|
+
import React, { useContext, useMemo, useCallback } from 'react';
|
|
14
|
+
import { DndContext, DragOverlay } from '@dnd-kit/core';
|
|
15
|
+
import { SortableContext } from '@dnd-kit/sortable';
|
|
16
|
+
import { useTreeDndkitConfig } from '@elliemae/ds-drag-and-drop';
|
|
17
|
+
import TreeViewContext from '../TreeViewContext.js';
|
|
18
|
+
import { TreeItem } from '../parts/TreeItem.js';
|
|
19
|
+
import { DnDTreeContext } from './DnDTreeContext.js';
|
|
20
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
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; }
|
|
25
|
+
|
|
26
|
+
const ensure = function (argument) {
|
|
27
|
+
let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'This should never happen';
|
|
28
|
+
|
|
29
|
+
if (argument === undefined || argument === null) {
|
|
30
|
+
throw new TypeError(message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return argument;
|
|
34
|
+
}; // only wraps in "DnDContext" and "DnDTreeContext" if any Drag and Drop functionality is requested
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const withConditionalDnDRowContext = Component => props => {
|
|
38
|
+
const [lastActiveId, setLastActiveId] = React.useState('');
|
|
39
|
+
const {
|
|
40
|
+
props: {
|
|
41
|
+
data,
|
|
42
|
+
onOrderChange,
|
|
43
|
+
getIsDropValid
|
|
44
|
+
},
|
|
45
|
+
flattenedItems,
|
|
46
|
+
visibleItems: flattenedVisibleTree,
|
|
47
|
+
withDragAndDrop
|
|
48
|
+
} = useContext(TreeViewContext);
|
|
49
|
+
const flattenedVisibleTreeForDnD = useMemo(() => flattenedVisibleTree.map((item, index) => {
|
|
50
|
+
var _item$treeDepth, _item$children$length, _item$children, _item$node$parent$mod, _item$node$parent, _item$node$parent$mod2, _item$node$parent$mod3;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
uid: item.id.toString(),
|
|
54
|
+
depth: ((_item$treeDepth = item.treeDepth) !== null && _item$treeDepth !== void 0 ? _item$treeDepth : 1) - 1,
|
|
55
|
+
realIndex: index,
|
|
56
|
+
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,
|
|
57
|
+
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,
|
|
58
|
+
original: item
|
|
59
|
+
};
|
|
60
|
+
}), [flattenedVisibleTree]);
|
|
61
|
+
const onReorder = useCallback((tree, indexes) => {
|
|
62
|
+
// Pull the row's original data into an object
|
|
63
|
+
const nodes = {};
|
|
64
|
+
tree.forEach(item => {
|
|
65
|
+
const originalItem = item.original;
|
|
66
|
+
originalItem.children = [];
|
|
67
|
+
nodes[item.uid] = item.original;
|
|
68
|
+
});
|
|
69
|
+
const newUserTree = [];
|
|
70
|
+
tree.forEach(item => {
|
|
71
|
+
// If row has parent, insert it to it's subrows
|
|
72
|
+
// otherwise append it to the new user data
|
|
73
|
+
if (item.parentId !== null && item.parentId !== undefined && item.parentId !== '__ds_tree_root') {
|
|
74
|
+
var _parentNode$children;
|
|
75
|
+
|
|
76
|
+
const parentNode = nodes[item.parentId];
|
|
77
|
+
(_parentNode$children = parentNode.children) === null || _parentNode$children === void 0 ? void 0 : _parentNode$children.push(item.original);
|
|
78
|
+
} else if (item.uid !== '__ds_tree_root') newUserTree.push(item.original);
|
|
79
|
+
}); // Tell the user that the order has change, he can chose to commit it or not
|
|
80
|
+
|
|
81
|
+
onOrderChange(newUserTree, data, flattenedItems[indexes.fromIndex]);
|
|
82
|
+
}, [onOrderChange, data, flattenedItems]);
|
|
83
|
+
const {
|
|
84
|
+
dndContextProps,
|
|
85
|
+
sortableContextProps,
|
|
86
|
+
activeId,
|
|
87
|
+
activeIndex,
|
|
88
|
+
depth,
|
|
89
|
+
dropIndicatorPosition,
|
|
90
|
+
visibleItems,
|
|
91
|
+
isDropValid
|
|
92
|
+
} = useTreeDndkitConfig({
|
|
93
|
+
flattenedItems,
|
|
94
|
+
visibleItems: flattenedVisibleTreeForDnD,
|
|
95
|
+
isHorizontalDnD: false,
|
|
96
|
+
isExpandable: true,
|
|
97
|
+
onReorder,
|
|
98
|
+
getIsDropValid,
|
|
99
|
+
maxDragAndDropLevel: Infinity
|
|
100
|
+
});
|
|
101
|
+
if (lastActiveId !== activeId && activeId) setLastActiveId(activeId);
|
|
102
|
+
if (withDragAndDrop) return /*#__PURE__*/jsxs(DndContext, _objectSpread(_objectSpread({}, dndContextProps), {}, {
|
|
103
|
+
children: [/*#__PURE__*/jsx(SortableContext, _objectSpread(_objectSpread({}, sortableContextProps), {}, {
|
|
104
|
+
children: /*#__PURE__*/_jsx(DnDTreeContext.Provider, {
|
|
105
|
+
value: {
|
|
106
|
+
activeIndex,
|
|
107
|
+
depth,
|
|
108
|
+
visibleItems: visibleItems.map(item => item.original),
|
|
109
|
+
dropIndicatorPosition,
|
|
110
|
+
lastActiveId,
|
|
111
|
+
setLastActiveId,
|
|
112
|
+
isDropValid
|
|
113
|
+
}
|
|
114
|
+
}, void 0, /*#__PURE__*/jsx(Component, _objectSpread({}, props)))
|
|
115
|
+
})), /*#__PURE__*/_jsx(DragOverlay, {
|
|
116
|
+
style: {
|
|
117
|
+
width: 'auto'
|
|
118
|
+
}
|
|
119
|
+
}, void 0, activeId ? /*#__PURE__*/_jsx(TreeItem, {
|
|
120
|
+
itemIndex: activeIndex,
|
|
121
|
+
item: ensure(flattenedVisibleTree.find(item => item.id.toString() === activeId)),
|
|
122
|
+
isDragOverlay: true
|
|
123
|
+
}) : null)]
|
|
124
|
+
}));
|
|
125
|
+
return /*#__PURE__*/jsx(Component, _objectSpread({}, props));
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export { withConditionalDnDRowContext };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
8
|
+
import { useContext, useMemo } from 'react';
|
|
9
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
10
|
+
import { SortableItemContext } from './SortableItemContext.js';
|
|
11
|
+
import TreeViewContext from '../TreeViewContext.js';
|
|
12
|
+
import { DnDTreeContext } from './DnDTreeContext.js';
|
|
13
|
+
import { jsx } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
const withDnDSortableItemContext = Component => props => {
|
|
19
|
+
const {
|
|
20
|
+
withDragAndDrop
|
|
21
|
+
} = useContext(TreeViewContext);
|
|
22
|
+
const {
|
|
23
|
+
dropIndicatorPosition,
|
|
24
|
+
lastActiveId,
|
|
25
|
+
setLastActiveId,
|
|
26
|
+
isDropValid
|
|
27
|
+
} = useContext(DnDTreeContext);
|
|
28
|
+
const id = props.item.id.toString(); // onMount generate unique options, so everyting is only ran once
|
|
29
|
+
|
|
30
|
+
const draggableOptions = useMemo(() => ({
|
|
31
|
+
id
|
|
32
|
+
}), [id]);
|
|
33
|
+
const useSortableHelpers = useSortable(draggableOptions); // calculate all the "useSortable" values as per required
|
|
34
|
+
|
|
35
|
+
const draggableProps = useMemo(() => {
|
|
36
|
+
if (!withDragAndDrop) return false;
|
|
37
|
+
const {
|
|
38
|
+
index,
|
|
39
|
+
overIndex
|
|
40
|
+
} = useSortableHelpers;
|
|
41
|
+
return _objectSpread(_objectSpread({}, useSortableHelpers), {}, {
|
|
42
|
+
shouldShowDropIndicatorPosition: overIndex === index,
|
|
43
|
+
dropIndicatorPosition,
|
|
44
|
+
lastActiveId,
|
|
45
|
+
setLastActiveId,
|
|
46
|
+
isDropValid
|
|
47
|
+
});
|
|
48
|
+
}, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid]); // we use a context so we can easly access information wherever without bubbling down
|
|
49
|
+
// this context is all Memoized so as long as component is not re-mounted,
|
|
50
|
+
// the context won't trigger un-required renders per-se...
|
|
51
|
+
|
|
52
|
+
const ctx = useMemo(() => ({
|
|
53
|
+
draggableProps
|
|
54
|
+
}), [draggableProps]); // we always add the context, if draggableProps===false we don't have the DnD enabled.
|
|
55
|
+
|
|
56
|
+
return /*#__PURE__*/_jsx(SortableItemContext.Provider, {
|
|
57
|
+
value: ctx
|
|
58
|
+
}, void 0, /*#__PURE__*/jsx(Component, _objectSpread({}, props)));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { withDnDSortableItemContext };
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
|
|
1
|
+
export { TreeView, TreeViewWithSchema } from './TreeView.js';
|
|
2
|
+
export { TreeDndPlugin } from './plugins/dnd/TreeDndPlugin.js';
|
|
3
|
+
export { TreeRovingPlugin } from './plugins/roving/TreeRovingPlugin.js';
|
|
4
|
+
export { SelectablePluginTree } from './plugins/selectable/SelectablePluginTree.js';
|
|
5
|
+
export { TreeToolbarPlugin } from './plugins/toolbar/TreeToolbarPlugin.js';
|
|
6
|
+
export { TreePluginList } from './plugins/tree/TreeDataPlugin.js';
|
|
7
|
+
export { TreeVirtualizationPlugin } from './plugins/virtualization/TreeVirtualizationPlugin.js';
|
|
8
|
+
export { SearchableTreePlugin } from './plugins/searchable/SearchableTreePlugin.js';
|
|
9
|
+
export { TreeViewSearchBar } from './related-components/TreeViewSearchBar.js';
|
|
@@ -1,58 +1,71 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
7
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
8
|
+
import { useContext, useCallback, useMemo } from 'react';
|
|
9
|
+
import { DSCheckbox } from '@elliemae/ds-form';
|
|
10
|
+
import styled from 'styled-components';
|
|
11
|
+
import TreeViewContext from '../TreeViewContext.js';
|
|
12
|
+
import { toggleCheckboxItem } from '../utils/selectable-helper.js';
|
|
13
|
+
import { filterObject } from '../utils/object-helpers.js';
|
|
14
|
+
|
|
15
|
+
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; }
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
const StyledCheckboxWrapper = /*#__PURE__*/styled.span.withConfig({
|
|
19
|
+
componentId: "sc-1tyhs3t-0"
|
|
20
|
+
})(["padding-top:3px;"]);
|
|
21
|
+
|
|
11
22
|
function CheckboxSelectable(props) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
23
|
+
const {
|
|
24
|
+
item,
|
|
25
|
+
itemIndex
|
|
26
|
+
} = props;
|
|
27
|
+
const {
|
|
28
|
+
id
|
|
29
|
+
} = item;
|
|
14
30
|
const ctx = useContext(TreeViewContext);
|
|
15
31
|
const {
|
|
16
|
-
props: {
|
|
17
|
-
|
|
32
|
+
props: {
|
|
33
|
+
onSelectionChange,
|
|
34
|
+
isItemDisabled
|
|
35
|
+
},
|
|
36
|
+
virtualListHelpers: {
|
|
37
|
+
scrollToIndex
|
|
38
|
+
},
|
|
18
39
|
triggerTreeRerender,
|
|
19
40
|
selectedCheckboxes,
|
|
20
41
|
setSelectedCheckboxes
|
|
21
42
|
} = ctx;
|
|
22
43
|
const onCheckboxChange = useCallback(() => {
|
|
23
44
|
const newSelections = toggleCheckboxItem(item);
|
|
24
|
-
const newSelectionHasmap = filterObject({
|
|
45
|
+
const newSelectionHasmap = filterObject(_objectSpread(_objectSpread({}, selectedCheckboxes), newSelections), value => value !== false);
|
|
25
46
|
setSelectedCheckboxes(newSelectionHasmap);
|
|
26
47
|
triggerTreeRerender();
|
|
27
48
|
const indexAndScrollTo = {
|
|
28
49
|
scrollToItem: () => {
|
|
29
|
-
if (typeof item.virtualIndex ===
|
|
30
|
-
scrollToIndex(item.virtualIndex);
|
|
50
|
+
if (typeof item.virtualIndex === 'number') scrollToIndex(item.virtualIndex);
|
|
31
51
|
},
|
|
32
52
|
itemIndex
|
|
33
53
|
};
|
|
34
|
-
if (onSelectionChange)
|
|
35
|
-
|
|
36
|
-
}, [
|
|
37
|
-
item,
|
|
38
|
-
triggerTreeRerender,
|
|
39
|
-
onSelectionChange,
|
|
40
|
-
itemIndex,
|
|
41
|
-
scrollToIndex,
|
|
42
|
-
selectedCheckboxes,
|
|
43
|
-
setSelectedCheckboxes
|
|
44
|
-
]);
|
|
54
|
+
if (onSelectionChange) onSelectionChange(newSelectionHasmap, item, indexAndScrollTo);
|
|
55
|
+
}, [item, triggerTreeRerender, onSelectionChange, itemIndex, scrollToIndex, selectedCheckboxes, setSelectedCheckboxes]);
|
|
45
56
|
const isChecked = useMemo(() => {
|
|
46
|
-
if (selectedCheckboxes[id] ===
|
|
47
|
-
return
|
|
57
|
+
if (selectedCheckboxes[id] === 'mixed') {
|
|
58
|
+
return 'mixed';
|
|
48
59
|
}
|
|
60
|
+
|
|
49
61
|
if (selectedCheckboxes[id] === true) {
|
|
50
62
|
return true;
|
|
51
63
|
}
|
|
64
|
+
|
|
52
65
|
return false;
|
|
53
66
|
}, [selectedCheckboxes, id]);
|
|
54
67
|
const isDisabled = useMemo(() => isItemDisabled(item), [item, isItemDisabled]);
|
|
55
|
-
return
|
|
68
|
+
return /*#__PURE__*/_jsx(StyledCheckboxWrapper, {}, void 0, /*#__PURE__*/_jsx(DSCheckbox, {
|
|
56
69
|
checked: isChecked,
|
|
57
70
|
disabled: isDisabled,
|
|
58
71
|
className: "em-ds-tree-item-checkbox",
|
|
@@ -61,8 +74,5 @@ function CheckboxSelectable(props) {
|
|
|
61
74
|
tabIndex: "0"
|
|
62
75
|
}));
|
|
63
76
|
}
|
|
64
|
-
|
|
65
|
-
export {
|
|
66
|
-
CheckboxSelectable_default as default
|
|
67
|
-
};
|
|
68
|
-
//# sourceMappingURL=CheckboxSelectable.js.map
|
|
77
|
+
|
|
78
|
+
export { CheckboxSelectable as default };
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { DSTreeViewPrefix, treeItemBlockName } from
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'react';
|
|
3
|
+
import { DSTreeViewPrefix, treeItemBlockName } from '../config/cssClassesConstants.js';
|
|
4
|
+
|
|
5
|
+
const className = "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName, "-children-count-displayer");
|
|
6
|
+
const ChildrenCountDisplayer = props => {
|
|
7
|
+
const {
|
|
8
|
+
item
|
|
9
|
+
} = props;
|
|
10
|
+
const {
|
|
11
|
+
isGroup,
|
|
12
|
+
children
|
|
13
|
+
} = item;
|
|
14
|
+
if (!isGroup) return null; // return ` | ${children.length} Items`;
|
|
15
|
+
|
|
16
|
+
return /*#__PURE__*/_jsx("span", {
|
|
11
17
|
"data-testid": "tree-item-children-count-displayer",
|
|
12
|
-
className
|
|
13
|
-
},
|
|
18
|
+
className: className
|
|
19
|
+
}, void 0, " | ".concat(children.length, " Items"));
|
|
14
20
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=ChildrenCountDisplayer.js.map
|
|
21
|
+
|
|
22
|
+
export { ChildrenCountDisplayer };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import { useContext, createElement } from 'react';
|
|
8
|
+
import { GripperVertical } from '@elliemae/ds-icons';
|
|
9
|
+
import { SortableItemContext } from '../hoc/SortableItemContext.js';
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
13
|
+
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; }
|
|
14
|
+
const DnDHandle = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
id,
|
|
17
|
+
isDragOverlay
|
|
18
|
+
} = _ref;
|
|
19
|
+
const {
|
|
20
|
+
draggableProps
|
|
21
|
+
} = useContext(SortableItemContext);
|
|
22
|
+
const isDragging = draggableProps && draggableProps.isDragging;
|
|
23
|
+
return /*#__PURE__*/createElement(GripperVertical, _objectSpread(_objectSpread({
|
|
24
|
+
role: "button"
|
|
25
|
+
}, draggableProps && _objectSpread(_objectSpread({}, draggableProps.listeners), draggableProps.attributes)), {}, {
|
|
26
|
+
"data-testid": "drag-handle",
|
|
27
|
+
"data-isactive": draggableProps && !!draggableProps.active,
|
|
28
|
+
"data-isdragoverlay": isDragOverlay,
|
|
29
|
+
id: "".concat(id, "-drag-handle"),
|
|
30
|
+
key: "".concat(id, "-drag-handle"),
|
|
31
|
+
className: "drag-handle ".concat(isDragging ? '' : 'focuseable'),
|
|
32
|
+
color: ['brand-primary', '800'],
|
|
33
|
+
size: "s",
|
|
34
|
+
tabIndex: 0
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { DnDHandle };
|