@elliemae/ds-treeview 2.2.0-alpha.2 → 2.2.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.
- 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,109 +1,99 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable max-params */
|
|
3
4
|
const updateExpandedState = (treeRoot, onExpandChange) => {
|
|
4
5
|
const shouldContinueWalking = true;
|
|
5
|
-
const newExpandedHashMap = {
|
|
6
|
-
|
|
6
|
+
const newExpandedHashMap = {
|
|
7
|
+
__ds_tree_root: true
|
|
8
|
+
};
|
|
9
|
+
treeRoot.walk(node => {
|
|
7
10
|
if (!node.isRoot() && node.model.isGroup && node.model.isExpanded) {
|
|
8
11
|
newExpandedHashMap[node.model.id] = true;
|
|
9
12
|
}
|
|
13
|
+
|
|
10
14
|
return shouldContinueWalking;
|
|
11
15
|
});
|
|
12
|
-
if (onExpandChange)
|
|
13
|
-
onExpandChange(newExpandedHashMap, null);
|
|
16
|
+
if (onExpandChange) onExpandChange(newExpandedHashMap, null);
|
|
14
17
|
};
|
|
15
|
-
const toggleItemExpand = (itemToToggle, triggerTreeRerender, updateUserExpandedState
|
|
16
|
-
|
|
18
|
+
const toggleItemExpand = function (itemToToggle, triggerTreeRerender, updateUserExpandedState) {
|
|
19
|
+
let scrollTo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => {};
|
|
17
20
|
const {
|
|
18
21
|
node: {
|
|
19
|
-
model: {
|
|
22
|
+
model: {
|
|
23
|
+
isExpanded
|
|
24
|
+
}
|
|
20
25
|
},
|
|
21
26
|
virtualIndex
|
|
22
27
|
} = itemToToggle;
|
|
28
|
+
|
|
23
29
|
if (itemToToggle.node.model.isGroup) {
|
|
24
30
|
itemToToggle.node.model.isExpanded = !isExpanded;
|
|
25
31
|
triggerTreeRerender();
|
|
26
32
|
updateUserExpandedState();
|
|
27
33
|
setTimeout(() => {
|
|
28
|
-
if (typeof virtualIndex ===
|
|
29
|
-
|
|
34
|
+
if (typeof virtualIndex === 'number') scrollTo(virtualIndex, {
|
|
35
|
+
align: 'start'
|
|
36
|
+
});
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
};
|
|
33
|
-
const expandItemModel =
|
|
34
|
-
if (modelToExpand.isGroup)
|
|
35
|
-
modelToExpand.isExpanded = true;
|
|
40
|
+
const expandItemModel = modelToExpand => {
|
|
41
|
+
if (modelToExpand.isGroup) modelToExpand.isExpanded = true;
|
|
36
42
|
};
|
|
37
|
-
const collapseItemModel =
|
|
38
|
-
if (modelToCollapse.isGroup)
|
|
39
|
-
modelToCollapse.isExpanded = false;
|
|
43
|
+
const collapseItemModel = modelToCollapse => {
|
|
44
|
+
if (modelToCollapse.isGroup) modelToCollapse.isExpanded = false;
|
|
40
45
|
};
|
|
41
46
|
const expandAll = (treeRoot, triggerTreeRerender) => {
|
|
42
47
|
const shouldContinueWalking = true;
|
|
43
|
-
treeRoot.walk(
|
|
44
|
-
if (!node.isRoot())
|
|
45
|
-
expandItemModel(node.model);
|
|
48
|
+
treeRoot.walk(node => {
|
|
49
|
+
if (!node.isRoot()) expandItemModel(node.model);
|
|
46
50
|
return shouldContinueWalking;
|
|
47
51
|
});
|
|
48
52
|
triggerTreeRerender();
|
|
49
53
|
};
|
|
50
54
|
const collapseAll = (treeRoot, triggerTreeRerender) => {
|
|
51
|
-
const shouldContinueWalking = true;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
|
|
56
|
+
|
|
57
|
+
treeRoot.walk(node => {
|
|
58
|
+
if (!node.isRoot()) collapseItemModel(node.model);
|
|
55
59
|
return shouldContinueWalking;
|
|
56
60
|
});
|
|
57
61
|
triggerTreeRerender();
|
|
58
62
|
};
|
|
59
|
-
const getToggleExpandShouldExpand =
|
|
63
|
+
const getToggleExpandShouldExpand = treeRoot => {
|
|
60
64
|
let shouldExpand = false;
|
|
61
|
-
const shouldContinueWalking = true;
|
|
62
|
-
|
|
65
|
+
const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
|
|
66
|
+
|
|
67
|
+
treeRoot.walk(node => {
|
|
63
68
|
if (!node.isRoot()) {
|
|
64
69
|
if (!node.model.isExpanded && node.model.isGroup) {
|
|
65
|
-
shouldExpand = true;
|
|
70
|
+
shouldExpand = true; // eslint-disable-next-line no-useless-return
|
|
71
|
+
|
|
66
72
|
return shouldContinueWalking;
|
|
67
73
|
}
|
|
68
74
|
}
|
|
75
|
+
|
|
69
76
|
return shouldContinueWalking;
|
|
70
77
|
});
|
|
71
78
|
return shouldExpand;
|
|
72
79
|
};
|
|
73
80
|
const toggleExpandAllHelper = (isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
|
|
74
|
-
if (isExpand === true)
|
|
75
|
-
expandAll(treeRoot, triggerTreeRerender);
|
|
76
|
-
else if (isExpand === false)
|
|
77
|
-
collapseAll(treeRoot, triggerTreeRerender);
|
|
78
|
-
else {
|
|
81
|
+
if (isExpand === true) expandAll(treeRoot, triggerTreeRerender);else if (isExpand === false) collapseAll(treeRoot, triggerTreeRerender);else {
|
|
79
82
|
const shouldExpand = getToggleExpandShouldExpand(treeRoot);
|
|
80
|
-
if (shouldExpand === true)
|
|
81
|
-
expandAll(treeRoot, triggerTreeRerender);
|
|
82
|
-
else
|
|
83
|
-
collapseAll(treeRoot, triggerTreeRerender);
|
|
83
|
+
if (shouldExpand === true) expandAll(treeRoot, triggerTreeRerender);else collapseAll(treeRoot, triggerTreeRerender);
|
|
84
84
|
}
|
|
85
85
|
setLatestToggledItem(null);
|
|
86
86
|
updateUserExpandedState();
|
|
87
87
|
};
|
|
88
|
-
const useNotifyExpandedChange = (propsWithDefaults, {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
const useNotifyExpandedChange = (propsWithDefaults, _ref) => {
|
|
89
|
+
let {
|
|
90
|
+
latestToggledItem,
|
|
91
|
+
expandedGroups
|
|
92
|
+
} = _ref;
|
|
93
|
+
const notifyExpandedChange = useCallback(expandedGroupHashmap => propsWithDefaults === null || propsWithDefaults === void 0 ? void 0 : propsWithDefaults.onExpandChange(expandedGroupHashmap || {}, latestToggledItem), [propsWithDefaults, latestToggledItem]);
|
|
93
94
|
useEffect(() => {
|
|
94
|
-
if (!propsWithDefaults.expanded)
|
|
95
|
-
notifyExpandedChange(expandedGroups);
|
|
95
|
+
if (!propsWithDefaults.expanded) notifyExpandedChange(expandedGroups);
|
|
96
96
|
}, [expandedGroups, notifyExpandedChange, propsWithDefaults.expanded]);
|
|
97
97
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
collapseItemModel,
|
|
101
|
-
expandAll,
|
|
102
|
-
expandItemModel,
|
|
103
|
-
getToggleExpandShouldExpand,
|
|
104
|
-
toggleExpandAllHelper,
|
|
105
|
-
toggleItemExpand,
|
|
106
|
-
updateExpandedState,
|
|
107
|
-
useNotifyExpandedChange
|
|
108
|
-
};
|
|
109
|
-
//# sourceMappingURL=group-expands-helpers.js.map
|
|
98
|
+
|
|
99
|
+
export { collapseAll, collapseItemModel, expandAll, expandItemModel, getToggleExpandShouldExpand, toggleExpandAllHelper, toggleItemExpand, updateExpandedState, useNotifyExpandedChange };
|
|
@@ -1,55 +1,91 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { useContext, useCallback, useEffect } from 'react';
|
|
2
|
+
import TreeViewContext from '../TreeViewContext.js';
|
|
3
|
+
import { focusItem } from './tree-helpers.js';
|
|
4
|
+
import { toggleItemExpand, toggleExpandAllHelper } from './group-expands-helpers.js';
|
|
5
|
+
|
|
6
|
+
/* eslint-disable max-params */
|
|
7
|
+
// 9 tab
|
|
8
|
+
// 13 enter
|
|
9
|
+
// 32 space
|
|
10
|
+
// 37 left arrow
|
|
11
|
+
// 38 up arrow
|
|
12
|
+
// 39 right arrow
|
|
13
|
+
// 40 down arrow
|
|
14
|
+
// 35 end
|
|
15
|
+
// 36 home
|
|
16
|
+
// 56 number 8
|
|
17
|
+
// 106 (NumPad) *
|
|
18
|
+
const useOnItemKeyDown = (item, draggableProps) => {
|
|
7
19
|
const ctx = useContext(TreeViewContext);
|
|
8
20
|
const {
|
|
9
|
-
props: {
|
|
21
|
+
props: {
|
|
22
|
+
onItemFocus
|
|
23
|
+
},
|
|
10
24
|
triggerTreeRerender,
|
|
11
|
-
isDragging,
|
|
12
25
|
visibleItems,
|
|
13
26
|
setFocusedItem,
|
|
14
27
|
setSelectedItem,
|
|
15
28
|
setLatestToggledItem,
|
|
16
29
|
updateUserExpandedState,
|
|
17
|
-
virtualListHelpers: {
|
|
30
|
+
virtualListHelpers: {
|
|
31
|
+
scrollToIndex
|
|
32
|
+
}
|
|
18
33
|
} = ctx;
|
|
19
|
-
const {
|
|
20
|
-
|
|
34
|
+
const {
|
|
35
|
+
isGroup,
|
|
36
|
+
isExpanded
|
|
37
|
+
} = item;
|
|
38
|
+
const onItemFocusCurry = useCallback(newFocusItem => onItemFocus({
|
|
21
39
|
itemIndex: newFocusItem.virtualIndex,
|
|
22
|
-
scrollToItem: (
|
|
40
|
+
scrollToItem: function () {
|
|
41
|
+
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
42
|
+
align: 'start'
|
|
43
|
+
};
|
|
44
|
+
return scrollToIndex(newFocusItem.virtualIndex, opts);
|
|
45
|
+
},
|
|
23
46
|
item: newFocusItem
|
|
24
47
|
}), [onItemFocus, scrollToIndex]);
|
|
25
|
-
const onItemKeyDown = useCallback(
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
48
|
+
const onItemKeyDown = useCallback(e => {
|
|
49
|
+
const {
|
|
50
|
+
keyCode
|
|
51
|
+
} = e;
|
|
52
|
+
|
|
53
|
+
if (!(draggableProps && draggableProps.active)) {
|
|
54
|
+
if (keyCode !== 9) e.preventDefault(); // allow tab/shift+tab
|
|
55
|
+
|
|
56
|
+
if ((keyCode === 13 || keyCode === 32) && e.target.tagName === 'LI') {
|
|
31
57
|
setSelectedItem(item);
|
|
58
|
+
}
|
|
59
|
+
|
|
32
60
|
if (keyCode === 37) {
|
|
33
61
|
if (isGroup && isExpanded) {
|
|
34
62
|
toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
|
|
35
63
|
setLatestToggledItem(item);
|
|
36
64
|
}
|
|
37
65
|
}
|
|
66
|
+
|
|
38
67
|
if (keyCode === 39) {
|
|
39
68
|
if (isGroup && !isExpanded) {
|
|
40
69
|
toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
|
|
41
70
|
setLatestToggledItem(item);
|
|
42
71
|
}
|
|
43
72
|
}
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
|
|
74
|
+
const {
|
|
75
|
+
virtualIndex
|
|
76
|
+
} = item;
|
|
77
|
+
|
|
78
|
+
if (typeof virtualIndex === 'number') {
|
|
46
79
|
const lastItemIndex = visibleItems.length - 1;
|
|
80
|
+
|
|
47
81
|
if (keyCode === 38) {
|
|
48
82
|
const isLoopedFocus = virtualIndex === 0;
|
|
49
83
|
const newFocusIndex = isLoopedFocus ? lastItemIndex : virtualIndex - 1;
|
|
50
84
|
const newFocusItem = visibleItems[newFocusIndex];
|
|
51
85
|
scrollToIndex(newFocusIndex);
|
|
86
|
+
|
|
52
87
|
if (isLoopedFocus) {
|
|
88
|
+
// when looping the list from start to end we need to wait a bit before focusing
|
|
53
89
|
setTimeout(() => {
|
|
54
90
|
setFocusedItem(newFocusItem);
|
|
55
91
|
focusItem(newFocusItem);
|
|
@@ -61,12 +97,15 @@ const useOnItemKeyDown = (item) => {
|
|
|
61
97
|
focusItem(newFocusItem);
|
|
62
98
|
}
|
|
63
99
|
}
|
|
100
|
+
|
|
64
101
|
if (keyCode === 40) {
|
|
65
102
|
const isLoopedFocus = virtualIndex === lastItemIndex;
|
|
66
103
|
const newFocusIndex = isLoopedFocus ? 0 : virtualIndex + 1;
|
|
67
104
|
const newFocusItem = visibleItems[newFocusIndex];
|
|
68
105
|
scrollToIndex(newFocusIndex);
|
|
106
|
+
|
|
69
107
|
if (isLoopedFocus) {
|
|
108
|
+
// when looping the list from start to end we need to wait a bit before focusing
|
|
70
109
|
setTimeout(() => {
|
|
71
110
|
setFocusedItem(newFocusItem);
|
|
72
111
|
onItemFocusCurry(newFocusItem);
|
|
@@ -78,6 +117,7 @@ const useOnItemKeyDown = (item) => {
|
|
|
78
117
|
focusItem(newFocusItem);
|
|
79
118
|
}
|
|
80
119
|
}
|
|
120
|
+
|
|
81
121
|
if (keyCode === 35) {
|
|
82
122
|
if (virtualIndex !== lastItemIndex) {
|
|
83
123
|
const newFocusItem = visibleItems[lastItemIndex];
|
|
@@ -89,6 +129,7 @@ const useOnItemKeyDown = (item) => {
|
|
|
89
129
|
}, 300);
|
|
90
130
|
}
|
|
91
131
|
}
|
|
132
|
+
|
|
92
133
|
if (keyCode === 36) {
|
|
93
134
|
if (virtualIndex !== 0) {
|
|
94
135
|
const newFocusItem = visibleItems[0];
|
|
@@ -102,40 +143,27 @@ const useOnItemKeyDown = (item) => {
|
|
|
102
143
|
}
|
|
103
144
|
}
|
|
104
145
|
}
|
|
105
|
-
}, [
|
|
106
|
-
isDragging,
|
|
107
|
-
setSelectedItem,
|
|
108
|
-
item,
|
|
109
|
-
isGroup,
|
|
110
|
-
isExpanded,
|
|
111
|
-
triggerTreeRerender,
|
|
112
|
-
scrollToIndex,
|
|
113
|
-
setLatestToggledItem,
|
|
114
|
-
visibleItems,
|
|
115
|
-
setFocusedItem,
|
|
116
|
-
onItemFocusCurry,
|
|
117
|
-
updateUserExpandedState
|
|
118
|
-
]);
|
|
146
|
+
}, [draggableProps, setSelectedItem, item, isGroup, isExpanded, triggerTreeRerender, updateUserExpandedState, scrollToIndex, setLatestToggledItem, visibleItems, setFocusedItem, onItemFocusCurry]);
|
|
119
147
|
return onItemKeyDown;
|
|
120
148
|
};
|
|
121
|
-
const useGlobalKeyboardListener =
|
|
149
|
+
const useGlobalKeyboardListener = func => {
|
|
122
150
|
useEffect(() => {
|
|
123
|
-
document.addEventListener(
|
|
124
|
-
return () => document.removeEventListener(
|
|
151
|
+
document.addEventListener('keydown', func);
|
|
152
|
+
return () => document.removeEventListener('keydown', func);
|
|
125
153
|
}, [func]);
|
|
126
154
|
};
|
|
127
155
|
const useGlobalToggleAllExpandShortcut = (treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
|
|
128
|
-
const memoizedToggleAllKeyboardShortcut = useCallback(
|
|
129
|
-
const {
|
|
156
|
+
const memoizedToggleAllKeyboardShortcut = useCallback(e => {
|
|
157
|
+
const {
|
|
158
|
+
shiftKey,
|
|
159
|
+
keyCode
|
|
160
|
+
} = e;
|
|
161
|
+
|
|
130
162
|
if (shiftKey && keyCode === 56) {
|
|
131
|
-
toggleExpandAllHelper(
|
|
163
|
+
toggleExpandAllHelper('toggle', treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
132
164
|
}
|
|
133
165
|
}, [setLatestToggledItem, treeRoot, triggerTreeRerender, updateUserExpandedState]);
|
|
134
166
|
return useGlobalKeyboardListener(memoizedToggleAllKeyboardShortcut);
|
|
135
167
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
useGlobalToggleAllExpandShortcut,
|
|
139
|
-
useOnItemKeyDown
|
|
140
|
-
};
|
|
141
|
-
//# sourceMappingURL=keyboard-helpers.js.map
|
|
168
|
+
|
|
169
|
+
export { useGlobalKeyboardListener, useGlobalToggleAllExpandShortcut, useOnItemKeyDown };
|
|
@@ -1,47 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.reduce.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.reduce.js';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-sequences */
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-return-assign */
|
|
10
|
+
|
|
11
|
+
/* eslint-disable no-restricted-syntax */
|
|
12
|
+
|
|
13
|
+
/* eslint-disable guard-for-in */
|
|
2
14
|
function isObjectADate(o) {
|
|
3
|
-
|
|
15
|
+
var _o$constructor;
|
|
16
|
+
|
|
17
|
+
return (o === null || o === void 0 ? void 0 : (_o$constructor = o.constructor) === null || _o$constructor === void 0 ? void 0 : _o$constructor.name) === 'Date';
|
|
4
18
|
}
|
|
19
|
+
|
|
5
20
|
function isObjectAnArray(o) {
|
|
6
21
|
return Array.isArray(o);
|
|
7
22
|
}
|
|
23
|
+
|
|
8
24
|
function isObjectAString(o) {
|
|
9
|
-
return typeof o ===
|
|
25
|
+
return typeof o === 'object';
|
|
10
26
|
}
|
|
11
|
-
|
|
27
|
+
|
|
28
|
+
const unfreeze = o => {
|
|
12
29
|
let oo;
|
|
30
|
+
|
|
13
31
|
if (o === null) {
|
|
14
32
|
oo = null;
|
|
15
|
-
} else if (o ===
|
|
16
|
-
oo =
|
|
33
|
+
} else if (o === undefined) {
|
|
34
|
+
oo = undefined;
|
|
17
35
|
} else if (isObjectADate(o)) {
|
|
18
36
|
oo = new Date(o);
|
|
19
37
|
} else if (isObjectAnArray(o)) {
|
|
20
38
|
oo = [];
|
|
21
|
-
o.forEach(
|
|
39
|
+
o.forEach(v => {
|
|
22
40
|
oo.push(v);
|
|
23
41
|
});
|
|
24
42
|
} else if (isObjectAString(o)) {
|
|
25
43
|
oo = String(o);
|
|
26
44
|
} else if (isObjectAString(o)) {
|
|
27
45
|
oo = {};
|
|
46
|
+
|
|
28
47
|
for (const property in o) {
|
|
29
48
|
oo[property] = o[property];
|
|
30
49
|
}
|
|
31
50
|
} else {
|
|
32
51
|
oo = o;
|
|
33
52
|
}
|
|
53
|
+
|
|
34
54
|
return oo;
|
|
35
55
|
};
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
57
|
function filterObject(obj, predicate) {
|
|
37
58
|
return Object.keys(obj).reduce((res, key) => {
|
|
38
|
-
if (predicate(obj[key]))
|
|
39
|
-
res[key] = obj[key];
|
|
59
|
+
if (predicate(obj[key])) res[key] = obj[key];
|
|
40
60
|
return res;
|
|
41
61
|
}, {});
|
|
42
62
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
unfreeze
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=object-helpers.js.map
|
|
63
|
+
|
|
64
|
+
export { filterObject, unfreeze };
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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
|
+
|
|
7
|
+
// allow multiple refs to be set to point to the same DOM element
|
|
8
|
+
const setMultipleRefs = function () {
|
|
9
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
+
refs[_key] = arguments[_key];
|
|
11
|
+
}
|
|
12
|
+
|
|
3
13
|
const filteredRefs = refs.filter(Boolean);
|
|
4
|
-
if (!filteredRefs.length)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
return (newRef) => {
|
|
11
|
-
filteredRefs.forEach((refToBeUpdated) => {
|
|
12
|
-
if (typeof refToBeUpdated === "function") {
|
|
14
|
+
if (!filteredRefs.length) return () => {};
|
|
15
|
+
if (filteredRefs.length === 0) return () => {};
|
|
16
|
+
return newRef => {
|
|
17
|
+
filteredRefs.forEach(refToBeUpdated => {
|
|
18
|
+
if (typeof refToBeUpdated === 'function') {
|
|
13
19
|
refToBeUpdated(newRef);
|
|
14
20
|
} else if (refToBeUpdated) {
|
|
15
21
|
refToBeUpdated.current = newRef;
|
|
@@ -17,7 +23,5 @@ const setMultipleRefs = (...refs) => {
|
|
|
17
23
|
});
|
|
18
24
|
};
|
|
19
25
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=refs-helpers.js.map
|
|
26
|
+
|
|
27
|
+
export { setMultipleRefs };
|
|
@@ -1,59 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
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 { walkAllNodeChildren, walkParents } from './tree-helpers.js';
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
const getGroupCheckState = node => {
|
|
4
13
|
let childAllChecked = true;
|
|
5
14
|
let anyChildChecked = false;
|
|
6
|
-
walkAllNodeChildren(node,
|
|
15
|
+
walkAllNodeChildren(node, childNode => {
|
|
7
16
|
const {
|
|
8
|
-
model: {
|
|
17
|
+
model: {
|
|
18
|
+
isChecked
|
|
19
|
+
}
|
|
9
20
|
} = childNode;
|
|
10
|
-
if (isChecked ===
|
|
11
|
-
anyChildChecked = true;
|
|
12
|
-
else
|
|
13
|
-
childAllChecked = false;
|
|
21
|
+
if (isChecked === 'mixed' || isChecked === true) anyChildChecked = true;else childAllChecked = false;
|
|
14
22
|
});
|
|
15
|
-
if (childAllChecked)
|
|
16
|
-
|
|
17
|
-
if (anyChildChecked)
|
|
18
|
-
return "mixed";
|
|
23
|
+
if (childAllChecked) return true;
|
|
24
|
+
if (anyChildChecked) return 'mixed';
|
|
19
25
|
return false;
|
|
20
26
|
};
|
|
21
|
-
const selectCheckboxItemModelParentsTillRoot = (modelToCheck
|
|
27
|
+
const selectCheckboxItemModelParentsTillRoot = function (modelToCheck) {
|
|
28
|
+
let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
22
29
|
const newSelections = {};
|
|
23
|
-
const {
|
|
24
|
-
|
|
30
|
+
const {
|
|
31
|
+
nodePath
|
|
32
|
+
} = modelToCheck;
|
|
33
|
+
walkParents(nodePath, parentNode => {
|
|
25
34
|
const nextState = getGroupCheckState(parentNode);
|
|
26
35
|
parentNode.model.isChecked = nextState;
|
|
27
36
|
newSelections[parentNode.model.id] = nextState;
|
|
28
37
|
});
|
|
29
|
-
if (triggerTreeRerender)
|
|
30
|
-
triggerTreeRerender();
|
|
38
|
+
if (triggerTreeRerender) triggerTreeRerender();
|
|
31
39
|
return newSelections;
|
|
32
40
|
};
|
|
33
|
-
const toggleCheckboxItem = (itemToSelect
|
|
41
|
+
const toggleCheckboxItem = function (itemToSelect) {
|
|
42
|
+
let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
34
43
|
const {
|
|
35
44
|
node: {
|
|
36
|
-
model: {
|
|
45
|
+
model: {
|
|
46
|
+
id,
|
|
47
|
+
isChecked,
|
|
48
|
+
children = []
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
51
|
} = itemToSelect;
|
|
39
|
-
const newSelections = {};
|
|
40
|
-
|
|
52
|
+
const newSelections = {}; // 'mixed' -> true -> false -> true [...->false -> true]
|
|
53
|
+
|
|
54
|
+
const nextState = isChecked === 'mixed' ? true : !isChecked;
|
|
41
55
|
itemToSelect.node.model.isChecked = nextState;
|
|
42
56
|
newSelections[id] = nextState;
|
|
57
|
+
|
|
43
58
|
if (children.length > 0 && (nextState === true || nextState === false)) {
|
|
44
|
-
walkAllNodeChildren(itemToSelect.node,
|
|
59
|
+
walkAllNodeChildren(itemToSelect.node, childNode => {
|
|
45
60
|
childNode.model.isChecked = nextState;
|
|
46
61
|
newSelections[childNode.model.id] = nextState;
|
|
47
62
|
});
|
|
48
63
|
}
|
|
64
|
+
|
|
49
65
|
const parentsNewSelections = selectCheckboxItemModelParentsTillRoot(itemToSelect);
|
|
50
|
-
if (triggerTreeRerender)
|
|
51
|
-
|
|
52
|
-
return { ...parentsNewSelections, ...newSelections };
|
|
53
|
-
};
|
|
54
|
-
export {
|
|
55
|
-
getGroupCheckState,
|
|
56
|
-
selectCheckboxItemModelParentsTillRoot,
|
|
57
|
-
toggleCheckboxItem
|
|
66
|
+
if (triggerTreeRerender) triggerTreeRerender();
|
|
67
|
+
return _objectSpread(_objectSpread({}, parentsNewSelections), newSelections);
|
|
58
68
|
};
|
|
59
|
-
|
|
69
|
+
|
|
70
|
+
export { getGroupCheckState, selectCheckboxItemModelParentsTillRoot, toggleCheckboxItem };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
standardizeSearchQueryString
|
|
5
|
-
};
|
|
6
|
-
//# sourceMappingURL=string-helpers.js.map
|
|
1
|
+
const standardizeSearchQueryString = input => input.trim().toLowerCase();
|
|
2
|
+
|
|
3
|
+
export { standardizeSearchQueryString };
|