@elliemae/ds-treeview 2.2.0-alpha.2 → 2.2.0-beta.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/TreeView.js +31 -49
- package/cjs/TreeViewContext.js +35 -53
- package/cjs/config/cssClassesConstants.js +13 -41
- package/cjs/config/useTreeview.js +80 -108
- package/cjs/index.js +27 -37
- package/cjs/parts/CheckboxSelectable.js +59 -70
- package/cjs/parts/ChildrenCountDisplayer.js +28 -45
- 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 +147 -128
- package/cjs/parts/TreeItemText.js +95 -88
- package/cjs/parts/TreeList.js +130 -117
- package/cjs/plugins/dnd/TreeDndPlugin.js +36 -51
- package/cjs/plugins/dnd/index.js +10 -28
- package/cjs/plugins/index.js +22 -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 +53 -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/dnd-helpers.js +84 -90
- package/cjs/utils/group-expands-helpers.js +59 -86
- package/cjs/utils/keyboard-helpers.js +88 -84
- 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 +135 -105
- package/cjs/utils/useDnDHelpers.js +118 -97
- package/cjs/utils/useInstanceRefActions.js +43 -54
- package/cjs/utils/useTree.js +78 -76
- package/esm/TreeView.js +20 -18
- package/esm/TreeViewContext.js +29 -24
- package/esm/config/cssClassesConstants.js +6 -12
- package/esm/config/useTreeview.js +54 -61
- package/esm/index.js +9 -8
- package/esm/parts/CheckboxSelectable.js +46 -36
- package/esm/parts/ChildrenCountDisplayer.js +20 -16
- 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 +127 -91
- package/esm/parts/TreeItemText.js +85 -58
- package/esm/parts/TreeList.js +117 -88
- package/esm/plugins/dnd/TreeDndPlugin.js +26 -21
- 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 +43 -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/dnd-helpers.js +73 -58
- package/esm/utils/group-expands-helpers.js +46 -56
- package/esm/utils/keyboard-helpers.js +72 -45
- 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 +119 -74
- package/esm/utils/useDnDHelpers.js +106 -60
- package/esm/utils/useInstanceRefActions.js +35 -21
- package/esm/utils/useTree.js +57 -35
- package/package.json +10 -10
- package/types/TreeView.d.ts +1 -1
- 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.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.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.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.map +0 -7
- package/esm/utils/useInstanceRefActions.js.map +0 -7
- package/esm/utils/useTree.js.map +0 -7
|
@@ -1,164 +1,194 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
cloneNode: () => cloneNode,
|
|
31
|
-
enrichNodeModelInPlace: () => enrichNodeModelInPlace,
|
|
32
|
-
focusItem: () => focusItem,
|
|
33
|
-
getChildrenMatchesSearchQuery: () => getChildrenMatchesSearchQuery,
|
|
34
|
-
getItemsParentNode: () => getItemsParentNode,
|
|
35
|
-
getNodeById: () => getNodeById,
|
|
36
|
-
getNodeMatchesSearchQuery: () => getNodeMatchesSearchQuery,
|
|
37
|
-
itemsShareSameParent: () => itemsShareSameParent,
|
|
38
|
-
walkAllNodeChildren: () => walkAllNodeChildren,
|
|
39
|
-
walkParents: () => walkParents,
|
|
40
|
-
walkVisibles: () => walkVisibles
|
|
41
|
-
});
|
|
42
|
-
var React = __toESM(require("react"));
|
|
43
|
-
var import_react = __toESM(require("react"));
|
|
44
|
-
var import_string_helpers = __toESM(require("./string-helpers"));
|
|
45
|
-
const walkVisibles = (node, callback, skipRoot = true, highlightOnlyQuery = false) => {
|
|
46
|
-
const { children, model } = node;
|
|
47
|
-
const { name, isExpanded, childrenMatchesSearchQuery, matchesSearchQuery } = model;
|
|
48
|
-
const shouldSkipBecauseIsRoot = skipRoot && name === "__root";
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.find.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.find.js');
|
|
11
|
+
require('core-js/modules/esnext.async-iterator.every.js');
|
|
12
|
+
require('core-js/modules/esnext.iterator.every.js');
|
|
13
|
+
var React = require('react');
|
|
14
|
+
var stringHelpers = require('./string-helpers.js');
|
|
15
|
+
|
|
16
|
+
const walkVisibles = function (node, callback) {
|
|
17
|
+
let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
18
|
+
let highlightOnlyQuery = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
19
|
+
const {
|
|
20
|
+
children,
|
|
21
|
+
model
|
|
22
|
+
} = node;
|
|
23
|
+
const {
|
|
24
|
+
name,
|
|
25
|
+
isExpanded,
|
|
26
|
+
childrenMatchesSearchQuery,
|
|
27
|
+
matchesSearchQuery
|
|
28
|
+
} = model;
|
|
29
|
+
const shouldSkipBecauseIsRoot = skipRoot && name === '__root';
|
|
49
30
|
const queryRestrictionsPassed = !!(highlightOnlyQuery || childrenMatchesSearchQuery || matchesSearchQuery);
|
|
50
|
-
if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed)
|
|
51
|
-
callback(node);
|
|
31
|
+
if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed) callback(node);
|
|
52
32
|
const shouldWalkChildren = !!(children.length > 0 && isExpanded && queryRestrictionsPassed);
|
|
33
|
+
|
|
53
34
|
if (shouldWalkChildren) {
|
|
54
|
-
children.forEach(
|
|
35
|
+
children.forEach(childNode => {
|
|
55
36
|
walkVisibles(childNode, callback, skipRoot, highlightOnlyQuery);
|
|
56
37
|
});
|
|
57
38
|
}
|
|
58
39
|
};
|
|
59
|
-
const walkParents = (nodePath, callback
|
|
40
|
+
const walkParents = function (nodePath, callback) {
|
|
41
|
+
let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
60
42
|
const parents = [...nodePath].reverse();
|
|
61
|
-
parents.shift();
|
|
62
|
-
|
|
63
|
-
|
|
43
|
+
parents.shift(); // remove current node from the parents array
|
|
44
|
+
|
|
45
|
+
if (skipRoot) parents.pop(); // remove the root from the parents if skipping root
|
|
46
|
+
|
|
64
47
|
parents.forEach(callback);
|
|
65
48
|
};
|
|
66
|
-
const walkAllNodeChildren = (node, callback
|
|
67
|
-
|
|
49
|
+
const walkAllNodeChildren = function (node, callback) {
|
|
50
|
+
let isFirst = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
51
|
+
const {
|
|
52
|
+
children = []
|
|
53
|
+
} = node;
|
|
68
54
|
const shouldWalkChildren = children.length;
|
|
69
|
-
if (!isFirst)
|
|
70
|
-
|
|
55
|
+
if (!isFirst) callback(node);
|
|
56
|
+
|
|
71
57
|
if (shouldWalkChildren) {
|
|
72
|
-
children.forEach(
|
|
58
|
+
children.forEach(childNode => {
|
|
73
59
|
walkAllNodeChildren(childNode, callback, false);
|
|
74
60
|
});
|
|
75
61
|
}
|
|
76
62
|
};
|
|
77
63
|
const getNodeById = (treeRoot, id) => {
|
|
78
|
-
const nodes = treeRoot.all(
|
|
64
|
+
const nodes = treeRoot.all(node => node.model.id === id);
|
|
79
65
|
return nodes[0];
|
|
80
66
|
};
|
|
81
67
|
const cloneNode = (tree, node) => tree.parse(node.model);
|
|
82
|
-
const itemsShareSameParent = (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (items.length === 1)
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const firstExistingItemPath = firstExistingItem.node.getPath();
|
|
68
|
+
const itemsShareSameParent = function () {
|
|
69
|
+
let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
70
|
+
if (items.length === 0) throw new Error('Received empty items for comparison');
|
|
71
|
+
if (items.length === 1) return true; // when moving in first position we receive [undefined,...{items}]
|
|
72
|
+
// when moving in last position we receive [...{items}, undefined]
|
|
73
|
+
|
|
74
|
+
const firstExistingItem = items.find(item => !!item);
|
|
75
|
+
if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
|
|
76
|
+
const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
|
|
77
|
+
// length -1 is the current-node
|
|
78
|
+
// length -2 is the parent-node
|
|
79
|
+
// root node is not printed and is always present so minimum path length is 2 (root + currentNode)
|
|
80
|
+
|
|
91
81
|
const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
|
|
92
|
-
return items.every(
|
|
93
|
-
|
|
94
|
-
|
|
82
|
+
return items.every(item => {
|
|
83
|
+
// undefined nodes count as having the same parent
|
|
84
|
+
if (!item) return true;
|
|
95
85
|
const itemPath = item.node.getPath();
|
|
96
86
|
const itemDirectParent = itemPath[itemPath.length - 2];
|
|
97
87
|
return directParentNode === itemDirectParent;
|
|
98
88
|
});
|
|
99
89
|
};
|
|
100
|
-
const getItemsParentNode = (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
90
|
+
const getItemsParentNode = function () {
|
|
91
|
+
let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
92
|
+
let skipSameParentCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
93
|
+
if (items.length === 0) throw new Error("Received empty items, can't retrieve parent"); // in case we already know the items compared shares the same parent
|
|
94
|
+
|
|
95
|
+
if (!skipSameParentCheck) if (!itemsShareSameParent(items)) // if we don't know (default, we don't) check if they share the parent
|
|
96
|
+
throw new Error("Received items don't share the same parent, can't retrieve parent"); // when moving in first position we receive [undefined,...{items}]
|
|
97
|
+
// when moving in last position we receive [...{items}, undefined]
|
|
98
|
+
|
|
99
|
+
const firstExistingItem = items.find(item => !!item);
|
|
100
|
+
if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
|
|
101
|
+
const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
|
|
102
|
+
// length -1 is the current-node
|
|
103
|
+
// length -2 is the parent-node
|
|
104
|
+
// root node is not printed and is always present so minimum path length is 2 (root + currentNode)
|
|
105
|
+
|
|
111
106
|
const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
|
|
112
107
|
return directParentNode;
|
|
113
108
|
};
|
|
114
|
-
const getNodeMatchesSearchQuery = (node
|
|
115
|
-
|
|
116
|
-
const
|
|
109
|
+
const getNodeMatchesSearchQuery = function (node) {
|
|
110
|
+
let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
111
|
+
const standardizedName = stringHelpers.standardizeSearchQueryString(node.model.name);
|
|
112
|
+
const standardizedSearchQuery = stringHelpers.standardizeSearchQueryString(searchQuery);
|
|
117
113
|
return standardizedName.includes(standardizedSearchQuery);
|
|
118
114
|
};
|
|
119
|
-
const getChildrenMatchesSearchQuery = (parentNode
|
|
115
|
+
const getChildrenMatchesSearchQuery = function (parentNode) {
|
|
116
|
+
let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
120
117
|
let anyChildMatch = false;
|
|
121
|
-
walkAllNodeChildren(parentNode,
|
|
122
|
-
if (getNodeMatchesSearchQuery(node, searchQuery))
|
|
123
|
-
anyChildMatch = true;
|
|
118
|
+
walkAllNodeChildren(parentNode, node => {
|
|
119
|
+
if (getNodeMatchesSearchQuery(node, searchQuery)) anyChildMatch = true;
|
|
124
120
|
});
|
|
125
121
|
return anyChildMatch;
|
|
126
122
|
};
|
|
127
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Mutate in place a node from tree-model normalizing object properties like "isGroup" even if user didn't specify it explicitly,
|
|
125
|
+
* after execution the node will have "nodePath" "treeDepth" "nodeItemRef" "isGroup" "isExpanded"
|
|
126
|
+
* (optionally, based on the provided arguments) "matchesSearchQuery" "childrenMatchesSearchQuery" "isChecked"
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} node - node (based on 'tree-model' lib) that you wish to mutate with extra props
|
|
129
|
+
* @param {string} [searchQuery=''] - optional string used to parse "matchesSearchQuery"/"childrenMatchesSearchQuery" properties
|
|
130
|
+
* @param {Object} [selection=null] - optional selection hashmap used to parse "isChecked" properties
|
|
131
|
+
* @param {Object} [expanded=null] - optional expanded hashmap used to parse "isExpanded" properties
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
const enrichNodeModelInPlace = function (node) {
|
|
135
|
+
var _node$model, _node$model$children;
|
|
136
|
+
|
|
137
|
+
let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
138
|
+
let selection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
139
|
+
let expanded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
128
140
|
const path = node.getPath();
|
|
129
141
|
const depth = path.length - 1;
|
|
130
142
|
node.model.nodePath = path;
|
|
131
143
|
node.model.treeDepth = depth;
|
|
144
|
+
|
|
132
145
|
if (!node.model.nodeItemRef) {
|
|
133
|
-
node.model.nodeItemRef =
|
|
134
|
-
}
|
|
135
|
-
|
|
146
|
+
node.model.nodeItemRef = /*#__PURE__*/React.createRef();
|
|
147
|
+
} // if a node has children but was not marked as isGroup, force-mark as group
|
|
148
|
+
// this is useful to avoid having to always check both the flag and the children.length...
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
if (typeof node.model.isGroup !== 'boolean' && ((_node$model = node.model) === null || _node$model === void 0 ? void 0 : (_node$model$children = _node$model.children) === null || _node$model$children === void 0 ? void 0 : _node$model$children.length) > 0) {
|
|
136
152
|
node.model.isGroup = true;
|
|
137
153
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
else if (typeof node.model.isExpanded !== "boolean") {
|
|
154
|
+
|
|
155
|
+
if (node.model.isGroup && node.model.id !== '__ds_tree_root') {
|
|
156
|
+
if (expanded) node.model.isExpanded = !!expanded[node.model.id];else if (typeof node.model.isExpanded !== 'boolean') {
|
|
142
157
|
node.model.isExpanded = false;
|
|
143
158
|
}
|
|
144
159
|
}
|
|
160
|
+
|
|
145
161
|
node.model.matchesSearchQuery = true;
|
|
146
162
|
node.model.childrenMatchesSearchQuery = false;
|
|
147
163
|
const partiallyEnrichedNode = node;
|
|
164
|
+
|
|
148
165
|
if (searchQuery) {
|
|
149
166
|
partiallyEnrichedNode.model.matchesSearchQuery = getNodeMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
|
|
167
|
+
|
|
150
168
|
if (partiallyEnrichedNode.model.isGroup === true) {
|
|
151
169
|
partiallyEnrichedNode.model.childrenMatchesSearchQuery = getChildrenMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
|
|
152
|
-
if (partiallyEnrichedNode.model.childrenMatchesSearchQuery)
|
|
153
|
-
partiallyEnrichedNode.model.isExpanded = true;
|
|
170
|
+
if (partiallyEnrichedNode.model.childrenMatchesSearchQuery) partiallyEnrichedNode.model.isExpanded = true;
|
|
154
171
|
}
|
|
155
172
|
}
|
|
173
|
+
|
|
156
174
|
if (selection && selection[partiallyEnrichedNode.model.id]) {
|
|
157
175
|
partiallyEnrichedNode.model.isChecked = selection[partiallyEnrichedNode.model.id];
|
|
158
176
|
}
|
|
159
177
|
};
|
|
160
|
-
const focusItem =
|
|
161
|
-
|
|
178
|
+
const focusItem = item => {
|
|
179
|
+
var _item$nodeItemRef, _item$nodeItemRef$cur;
|
|
180
|
+
|
|
181
|
+
item === null || item === void 0 ? void 0 : (_item$nodeItemRef = item.nodeItemRef) === null || _item$nodeItemRef === void 0 ? void 0 : (_item$nodeItemRef$cur = _item$nodeItemRef.current) === null || _item$nodeItemRef$cur === void 0 ? void 0 : _item$nodeItemRef$cur.focus();
|
|
162
182
|
};
|
|
163
|
-
|
|
164
|
-
|
|
183
|
+
|
|
184
|
+
exports.cloneNode = cloneNode;
|
|
185
|
+
exports.enrichNodeModelInPlace = enrichNodeModelInPlace;
|
|
186
|
+
exports.focusItem = focusItem;
|
|
187
|
+
exports.getChildrenMatchesSearchQuery = getChildrenMatchesSearchQuery;
|
|
188
|
+
exports.getItemsParentNode = getItemsParentNode;
|
|
189
|
+
exports.getNodeById = getNodeById;
|
|
190
|
+
exports.getNodeMatchesSearchQuery = getNodeMatchesSearchQuery;
|
|
191
|
+
exports.itemsShareSameParent = itemsShareSameParent;
|
|
192
|
+
exports.walkAllNodeChildren = walkAllNodeChildren;
|
|
193
|
+
exports.walkParents = walkParents;
|
|
194
|
+
exports.walkVisibles = walkVisibles;
|
|
@@ -1,44 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
|
-
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
-
return (module2, temp) => {
|
|
25
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var useDnDHelpers_exports = {};
|
|
29
|
-
__export(useDnDHelpers_exports, {
|
|
30
|
-
useDnDHelpers: () => useDnDHelpers
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
var import_react = __toESM(require("react"));
|
|
34
|
-
var import_lodash = __toESM(require("lodash"));
|
|
35
|
-
var import_TreeViewContext = __toESM(require("../TreeViewContext"));
|
|
36
|
-
var import_tree_helpers = __toESM(require("./tree-helpers"));
|
|
37
|
-
var import_dnd_helpers = __toESM(require("./dnd-helpers"));
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.constructor.js');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.drop.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.drop.js');
|
|
9
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
10
|
+
var React = require('react');
|
|
11
|
+
var lodash = require('lodash');
|
|
12
|
+
var TreeViewContext = require('../TreeViewContext.js');
|
|
13
|
+
var treeHelpers = require('./tree-helpers.js');
|
|
14
|
+
var dndHelpers = require('./dnd-helpers.js');
|
|
15
|
+
|
|
38
16
|
const useDnDHelpers = () => {
|
|
39
|
-
const ctx =
|
|
17
|
+
const ctx = React.useContext(TreeViewContext["default"]);
|
|
40
18
|
const {
|
|
41
|
-
props: {
|
|
19
|
+
props: {
|
|
20
|
+
data,
|
|
21
|
+
onOrderChange,
|
|
22
|
+
restrictDragAndDrop
|
|
23
|
+
},
|
|
42
24
|
relativeMouseCord,
|
|
43
25
|
setRelativeMouseCord,
|
|
44
26
|
visibleItems,
|
|
@@ -53,28 +35,45 @@ const useDnDHelpers = () => {
|
|
|
53
35
|
treeRoot,
|
|
54
36
|
draggedItem
|
|
55
37
|
} = ctx;
|
|
56
|
-
const onSortEnd =
|
|
57
|
-
|
|
38
|
+
const onSortEnd = React.useCallback(_ref => {
|
|
39
|
+
let {
|
|
40
|
+
oldIndex,
|
|
41
|
+
newIndex,
|
|
42
|
+
isKeySorting
|
|
43
|
+
} = _ref;
|
|
44
|
+
const {
|
|
45
|
+
isBefore,
|
|
46
|
+
isAfter,
|
|
47
|
+
item: overItem,
|
|
48
|
+
isValid
|
|
49
|
+
} = relativeMouseCord;
|
|
50
|
+
|
|
58
51
|
if (draggedItem && tree && treeRoot && overItem) {
|
|
59
|
-
let newItems =
|
|
52
|
+
let newItems = lodash.cloneDeep(data); // if dropping in same position do nothing
|
|
53
|
+
// if the drop is not allowed do nothing
|
|
54
|
+
|
|
60
55
|
if (oldIndex === newIndex || !isValid) {
|
|
56
|
+
// onOrderChange(newItems, data);
|
|
61
57
|
setIsDragging(false);
|
|
62
58
|
setDraggedItem(null);
|
|
63
59
|
triggerTreeRerender();
|
|
64
60
|
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
61
|
+
} // if we are moving from topToBottom the offset changes
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const movementDirection = newIndex > oldIndex ? 'topToBottom' : 'bottomToTop';
|
|
67
65
|
let newNestedIndex;
|
|
68
66
|
let newParentNode;
|
|
67
|
+
|
|
69
68
|
if (isKeySorting) {
|
|
70
|
-
const kinship =
|
|
69
|
+
const kinship = dndHelpers.inferKeyboardKinshipDrop({
|
|
71
70
|
items: visibleItems,
|
|
72
71
|
newIndex
|
|
73
72
|
});
|
|
74
73
|
newNestedIndex = kinship.newNestedIndex;
|
|
75
74
|
newParentNode = kinship.newParentNode;
|
|
76
75
|
} else {
|
|
77
|
-
const kinship =
|
|
76
|
+
const kinship = dndHelpers.inferHoverItemKinshipDrop({
|
|
78
77
|
isBefore,
|
|
79
78
|
isAfter,
|
|
80
79
|
overItem,
|
|
@@ -84,81 +83,99 @@ const useDnDHelpers = () => {
|
|
|
84
83
|
newNestedIndex = kinship.newNestedIndex;
|
|
85
84
|
newParentNode = kinship.newParentNode;
|
|
86
85
|
}
|
|
86
|
+
|
|
87
87
|
const newMovedItemNode = tree.parse(draggedItem.node.model);
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
treeHelpers.getNodeById(treeRoot, draggedItem.id).drop();
|
|
89
|
+
|
|
90
|
+
if (newParentNode && typeof newNestedIndex === 'number') {
|
|
90
91
|
newParentNode.addChildAtIndex(newMovedItemNode, newNestedIndex);
|
|
92
|
+
|
|
91
93
|
if (newParentNode.isRoot()) {
|
|
92
94
|
newItems = [...newParentNode.model.children];
|
|
93
95
|
} else {
|
|
94
96
|
newItems = [...treeRoot.model.children];
|
|
95
97
|
}
|
|
96
98
|
}
|
|
99
|
+
|
|
97
100
|
onOrderChange(newItems, data, draggedItem);
|
|
98
101
|
setIsDragging(false);
|
|
99
102
|
setDraggedItem(null);
|
|
100
103
|
triggerTreeRerender();
|
|
101
104
|
}
|
|
102
|
-
}, [
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const { index, isKeySorting } = beforeStartArgs;
|
|
105
|
+
}, [data, draggedItem, relativeMouseCord, visibleItems, tree, treeRoot, onOrderChange, triggerTreeRerender, setIsDragging, setDraggedItem]);
|
|
106
|
+
const onSortStart = React.useCallback(() => {}, // ({ node, index, collection, isKeySorting }, event) => {
|
|
107
|
+
// console.log('node :>> ', node);
|
|
108
|
+
// console.log('isKeySorting :>> ', isKeySorting);
|
|
109
|
+
// console.log('event :>> ', event);
|
|
110
|
+
// const item = collection?.[index] || visibleItems[index];
|
|
111
|
+
// setIsDragging(true);
|
|
112
|
+
// setDraggedItem(item);
|
|
113
|
+
// },
|
|
114
|
+
[]);
|
|
115
|
+
const updateBeforeSortStart = React.useCallback(beforeStartArgs => new Promise(resolve => {
|
|
116
|
+
const {
|
|
117
|
+
index,
|
|
118
|
+
isKeySorting
|
|
119
|
+
} = beforeStartArgs;
|
|
118
120
|
const item = visibleItems[index];
|
|
119
|
-
const {
|
|
121
|
+
const {
|
|
122
|
+
isExpanded
|
|
123
|
+
} = item.node.model;
|
|
124
|
+
|
|
120
125
|
if (isExpanded) {
|
|
121
126
|
item.node.model.isExpanded = false;
|
|
122
127
|
triggerTreeRerender();
|
|
123
128
|
}
|
|
124
|
-
|
|
129
|
+
|
|
130
|
+
setRelativeMouseCord(TreeViewContext.defaultRelativeMouseCoord);
|
|
125
131
|
setIsKeyboardDragging(isKeySorting);
|
|
126
132
|
setIsDragging(true);
|
|
127
133
|
setDraggedItem(item);
|
|
128
|
-
|
|
134
|
+
treeHelpers.focusItem(null);
|
|
129
135
|
setFocusedItem(null);
|
|
130
|
-
if (document.activeElement && typeof document.activeElement.blur ===
|
|
131
|
-
document.activeElement.blur();
|
|
136
|
+
if (document.activeElement && typeof document.activeElement.blur === 'function') document.activeElement.blur();
|
|
132
137
|
resolve(true);
|
|
133
|
-
}), [
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
138
|
+
}), [visibleItems, setRelativeMouseCord, setIsKeyboardDragging, setIsDragging, setDraggedItem, setFocusedItem, triggerTreeRerender]); // tracks mouse coords relative to an element to check if the drop happens
|
|
139
|
+
// at the top/center/bottom of an element to choose where to move the element
|
|
140
|
+
// requested in the specs
|
|
141
|
+
|
|
142
|
+
const onMouseDragOverItem = React.useCallback(_ref2 => {
|
|
143
|
+
let {
|
|
144
|
+
event,
|
|
145
|
+
item,
|
|
146
|
+
itemIndex,
|
|
147
|
+
setIsDraggingOverThis,
|
|
148
|
+
openFolderOnHoverTimeout
|
|
149
|
+
} = _ref2;
|
|
150
|
+
const {
|
|
151
|
+
node
|
|
152
|
+
} = item;
|
|
153
|
+
const {
|
|
154
|
+
nodeItemRef
|
|
155
|
+
} = node.model;
|
|
156
|
+
|
|
151
157
|
if (isDragging && !isKeyboardDragging && draggedItem) {
|
|
152
|
-
|
|
158
|
+
var _nodeItemRef$current;
|
|
159
|
+
|
|
160
|
+
const rect = nodeItemRef === null || nodeItemRef === void 0 ? void 0 : (_nodeItemRef$current = nodeItemRef.current) === null || _nodeItemRef$current === void 0 ? void 0 : _nodeItemRef$current.getBoundingClientRect();
|
|
161
|
+
|
|
153
162
|
if (rect) {
|
|
154
|
-
const x = event.clientX - rect.left;
|
|
155
|
-
|
|
156
|
-
const
|
|
163
|
+
const x = event.clientX - rect.left; // x position within the element.
|
|
164
|
+
|
|
165
|
+
const y = event.clientY - rect.top; // y position within the element.
|
|
166
|
+
// by spec we need to track where the drop will happens
|
|
167
|
+
// if drop happens on top 25% drop before
|
|
168
|
+
// if drop happens on bottom of 25% drop after
|
|
169
|
+
// if drop happens in the middle 50% either invalid or drop into children
|
|
170
|
+
|
|
171
|
+
const {
|
|
172
|
+
height: elementHeight
|
|
173
|
+
} = rect;
|
|
157
174
|
const dropBeforeMaxY = elementHeight * 0.25;
|
|
158
175
|
const dropAfterMinY = elementHeight - elementHeight * 0.25;
|
|
159
176
|
const isBefore = y < dropBeforeMaxY;
|
|
160
177
|
const isAfter = y > dropAfterMinY;
|
|
161
|
-
const isValid =
|
|
178
|
+
const isValid = dndHelpers.isDropValid({
|
|
162
179
|
isBefore,
|
|
163
180
|
isAfter,
|
|
164
181
|
draggedItem,
|
|
@@ -176,16 +193,20 @@ const useDnDHelpers = () => {
|
|
|
176
193
|
relativeElementIndex: itemIndex
|
|
177
194
|
});
|
|
178
195
|
setIsDraggingOverThis(true);
|
|
179
|
-
|
|
196
|
+
|
|
197
|
+
if (!(openFolderOnHoverTimeout !== null && openFolderOnHoverTimeout !== void 0 && openFolderOnHoverTimeout.current) && // only set the interval if it wasn't set already once
|
|
198
|
+
(draggedItem === null || draggedItem === void 0 ? void 0 : draggedItem.id) !== (item === null || item === void 0 ? void 0 : item.id) && ( // don't open ghost element
|
|
199
|
+
item.isGroup || item.children.length > 0) && // only open groups
|
|
200
|
+
!restrictDragAndDrop) {
|
|
180
201
|
openFolderOnHoverTimeout.current = setTimeout(() => {
|
|
181
202
|
item.node.model.isExpanded = true;
|
|
182
203
|
openFolderOnHoverTimeout.current = null;
|
|
183
204
|
triggerTreeRerender();
|
|
184
|
-
},
|
|
205
|
+
}, 1000);
|
|
185
206
|
}
|
|
186
207
|
}
|
|
187
208
|
} else {
|
|
188
|
-
setRelativeMouseCord(
|
|
209
|
+
setRelativeMouseCord(TreeViewContext.defaultRelativeMouseCoord);
|
|
189
210
|
}
|
|
190
211
|
}, [isDragging, isKeyboardDragging, draggedItem, restrictDragAndDrop, setRelativeMouseCord, triggerTreeRerender]);
|
|
191
212
|
return {
|
|
@@ -195,5 +216,5 @@ const useDnDHelpers = () => {
|
|
|
195
216
|
onMouseDragOverItem
|
|
196
217
|
};
|
|
197
218
|
};
|
|
198
|
-
|
|
199
|
-
|
|
219
|
+
|
|
220
|
+
exports.useDnDHelpers = useDnDHelpers;
|