@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,41 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (let key of __getOwnPropNames(module2))
|
|
15
|
-
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
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 useInstanceRefActions_exports = {};
|
|
29
|
-
__export(useInstanceRefActions_exports, {
|
|
30
|
-
useInstanceRefActions: () => useInstanceRefActions
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
var import_react = require("react");
|
|
34
|
-
var import_tree_helpers = require("./tree-helpers");
|
|
35
|
-
var import_group_expands_helpers = require("./group-expands-helpers");
|
|
36
|
-
const useInstanceRefActions = ({ actions }, ctx) => {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var treeHelpers = require('./tree-helpers.js');
|
|
8
|
+
var groupExpandsHelpers = require('./group-expands-helpers.js');
|
|
9
|
+
|
|
10
|
+
const useInstanceRefActions = (_ref, ctx) => {
|
|
11
|
+
let {
|
|
12
|
+
actions
|
|
13
|
+
} = _ref;
|
|
37
14
|
const {
|
|
38
|
-
props: {
|
|
15
|
+
props: {
|
|
16
|
+
onItemFocus
|
|
17
|
+
},
|
|
39
18
|
virtualListHelpers,
|
|
40
19
|
treeRoot,
|
|
41
20
|
visibleItems,
|
|
@@ -45,54 +24,64 @@ const useInstanceRefActions = ({ actions }, ctx) => {
|
|
|
45
24
|
setFocusedItem,
|
|
46
25
|
setLatestToggledItem
|
|
47
26
|
} = ctx;
|
|
48
|
-
const {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
27
|
+
const {
|
|
28
|
+
current: promises
|
|
29
|
+
} = React.useRef({});
|
|
30
|
+
const {
|
|
31
|
+
scrollToIndex
|
|
32
|
+
} = React.useMemo(() => virtualListHelpers, [virtualListHelpers]);
|
|
33
|
+
const [expandPromise, setPromise] = React.useState();
|
|
34
|
+
React.useEffect(() => {
|
|
52
35
|
if (expandPromise && promises.expandResolve) {
|
|
53
36
|
promises.expandResolve(visibleItems);
|
|
54
37
|
promises.expandResolve = null;
|
|
55
38
|
setPromise(null);
|
|
56
39
|
}
|
|
57
40
|
}, [visibleItems, expandPromise, promises]);
|
|
58
|
-
actions.toggleExpandAll =
|
|
59
|
-
const p = new Promise(
|
|
41
|
+
actions.toggleExpandAll = React.useCallback(isExpand => {
|
|
42
|
+
const p = new Promise(resolve => {
|
|
60
43
|
promises.expandResolve = resolve;
|
|
61
|
-
if (treeRoot)
|
|
62
|
-
(0, import_group_expands_helpers.toggleExpandAllHelper)(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
44
|
+
if (treeRoot) groupExpandsHelpers.toggleExpandAllHelper(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
63
45
|
});
|
|
64
46
|
setPromise(p);
|
|
65
47
|
return p;
|
|
66
48
|
}, [promises, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState]);
|
|
67
|
-
actions.scrollTo =
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
actions.scrollTo = React.useCallback(function (indx) {
|
|
50
|
+
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
51
|
+
align: 'start'
|
|
52
|
+
};
|
|
53
|
+
if (scrollToIndex) scrollToIndex(indx, opts);
|
|
70
54
|
}, [scrollToIndex]);
|
|
71
|
-
actions.setSelectedItemByVirtualIndex =
|
|
55
|
+
actions.setSelectedItemByVirtualIndex = React.useCallback(index => {
|
|
72
56
|
const itemByIndex = visibleItems[index];
|
|
73
57
|
setSelectedItem(itemByIndex);
|
|
74
58
|
}, [visibleItems, setSelectedItem]);
|
|
75
|
-
actions.setFocusedItemByVirtualIndex =
|
|
59
|
+
actions.setFocusedItemByVirtualIndex = React.useCallback(function (index) {
|
|
60
|
+
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
61
|
+
align: 'start',
|
|
62
|
+
withScroll: false
|
|
63
|
+
};
|
|
76
64
|
const itemByIndex = visibleItems[index];
|
|
77
65
|
const onItemFocusParams = {
|
|
78
66
|
itemIndex: itemByIndex.virtualIndex,
|
|
79
67
|
scrollToItem: () => scrollToIndex(index, opts),
|
|
80
68
|
item: itemByIndex
|
|
81
69
|
};
|
|
70
|
+
|
|
82
71
|
if (opts.withScroll && scrollToIndex) {
|
|
83
72
|
scrollToIndex(index, opts);
|
|
84
73
|
setTimeout(() => {
|
|
85
74
|
setFocusedItem(itemByIndex);
|
|
86
|
-
|
|
75
|
+
treeHelpers.focusItem(itemByIndex);
|
|
87
76
|
onItemFocus(onItemFocusParams);
|
|
88
77
|
}, 300);
|
|
89
78
|
} else {
|
|
90
79
|
setFocusedItem(itemByIndex);
|
|
91
|
-
|
|
80
|
+
treeHelpers.focusItem(itemByIndex);
|
|
92
81
|
onItemFocus(onItemFocusParams);
|
|
93
82
|
}
|
|
94
83
|
}, [visibleItems, scrollToIndex, setFocusedItem, onItemFocus]);
|
|
95
84
|
return actions;
|
|
96
85
|
};
|
|
97
|
-
|
|
98
|
-
|
|
86
|
+
|
|
87
|
+
exports.useInstanceRefActions = useInstanceRefActions;
|
package/cjs/utils/useTree.js
CHANGED
|
@@ -1,98 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
-
var useTree_exports = {};
|
|
29
|
-
__export(useTree_exports, {
|
|
30
|
-
useTree: () => useTree
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
var import_react = require("react");
|
|
34
|
-
var import_tree_model = __toESM(require("tree-model"));
|
|
35
|
-
var import_lodash = require("lodash");
|
|
36
|
-
var import_tree_helpers = require("./tree-helpers");
|
|
37
|
-
var import_group_expands_helpers = require("./group-expands-helpers");
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
7
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
11
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
12
|
+
var React = require('react');
|
|
13
|
+
var TreeModel = require('tree-model');
|
|
14
|
+
var lodash = require('lodash');
|
|
15
|
+
var treeHelpers = require('./tree-helpers.js');
|
|
16
|
+
var groupExpandsHelpers = require('./group-expands-helpers.js');
|
|
17
|
+
|
|
18
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
21
|
+
var TreeModel__default = /*#__PURE__*/_interopDefaultLegacy(TreeModel);
|
|
22
|
+
|
|
23
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
24
|
+
|
|
25
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
38
26
|
const useTree = (data, props, states) => {
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
const {
|
|
28
|
+
setExpandedGroups
|
|
29
|
+
} = states;
|
|
30
|
+
const unfrozenData = React.useMemo(() => lodash.cloneDeep(data), [data]); // convert data into a TreeModel with extra isExpanded prop
|
|
31
|
+
// root element type is an exception, children model is based on what the dev passed on
|
|
32
|
+
// since root is an excepcion we must typecast
|
|
33
|
+
|
|
34
|
+
const tree = React.useMemo(() => new TreeModel__default["default"](), []);
|
|
35
|
+
const [treeData, setTreeData] = React.useState({
|
|
36
|
+
id: '__ds_tree_root',
|
|
37
|
+
name: '__root',
|
|
45
38
|
isExpanded: true,
|
|
46
39
|
children: unfrozenData
|
|
47
40
|
});
|
|
48
|
-
|
|
41
|
+
React.useEffect(() => {
|
|
49
42
|
setTreeData({
|
|
50
|
-
id:
|
|
51
|
-
name:
|
|
43
|
+
id: '__ds_tree_root',
|
|
44
|
+
name: '__root',
|
|
52
45
|
isExpanded: true,
|
|
53
46
|
children: unfrozenData
|
|
54
47
|
});
|
|
55
|
-
}, [unfrozenData]);
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
}, [unfrozenData]); // expose a way to rerender the tree
|
|
49
|
+
// used for expand functionality
|
|
50
|
+
|
|
51
|
+
const [rerenderItems, setRerenderItems] = React.useState({});
|
|
52
|
+
const triggerTreeRerender = React.useCallback(() => {
|
|
58
53
|
setRerenderItems({});
|
|
59
|
-
}, []);
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
}, []); // when re-rendering we re-parse the list
|
|
55
|
+
|
|
56
|
+
const [treeRoot, setTreeRoot] = React.useState(tree.parse(treeData));
|
|
57
|
+
React.useEffect(() => {
|
|
62
58
|
setTreeRoot(tree.parse(treeData));
|
|
63
59
|
}, [treeData, rerenderItems, tree]);
|
|
64
|
-
const [visibleItems, setVisibleItems] =
|
|
65
|
-
const {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
const [visibleItems, setVisibleItems] = React.useState([]);
|
|
61
|
+
const {
|
|
62
|
+
searchQuery,
|
|
63
|
+
highlightOnlyQuery,
|
|
64
|
+
onVisibleItemsChange,
|
|
65
|
+
selection,
|
|
66
|
+
expanded,
|
|
67
|
+
onExpandChange
|
|
68
|
+
} = props;
|
|
69
|
+
const updateUserExpandedState = React.useCallback(() => {
|
|
70
|
+
groupExpandsHelpers.updateExpandedState(treeRoot, onExpandChange);
|
|
71
|
+
}, [treeRoot, onExpandChange]); // we add missing properties to the received Items
|
|
72
|
+
// not the best of the patterns, but it works
|
|
73
|
+
// this is where we convert "SimpleItems" to "Items"
|
|
74
|
+
// this was done to avoid breaking changes back in v1
|
|
75
|
+
|
|
76
|
+
React.useEffect(() => {
|
|
70
77
|
const parsedVisibleItems = [];
|
|
71
78
|
const newExpandedHashMap = {};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
|
|
80
|
+
|
|
81
|
+
treeRoot.walk(node => {
|
|
82
|
+
treeHelpers.enrichNodeModelInPlace(node, searchQuery, selection, expanded);
|
|
83
|
+
if (node.model.id && node.model.isGroup && node.model.isExpanded) newExpandedHashMap[node.model.id] = true;
|
|
77
84
|
return shouldContinueWalking;
|
|
78
85
|
});
|
|
79
|
-
|
|
80
|
-
parsedVisibleItems.push({
|
|
86
|
+
treeHelpers.walkVisibles(treeRoot, node => {
|
|
87
|
+
parsedVisibleItems.push(_objectSpread(_objectSpread({}, node.model), {}, {
|
|
88
|
+
node
|
|
89
|
+
}));
|
|
81
90
|
}, true, highlightOnlyQuery);
|
|
82
91
|
setVisibleItems(parsedVisibleItems);
|
|
83
92
|
onVisibleItemsChange(parsedVisibleItems);
|
|
84
|
-
setExpandedGroups(newExpandedHashMap);
|
|
85
|
-
}, [
|
|
86
|
-
treeRoot,
|
|
87
|
-
rerenderItems,
|
|
88
|
-
searchQuery,
|
|
89
|
-
highlightOnlyQuery,
|
|
90
|
-
selection,
|
|
91
|
-
expanded,
|
|
92
|
-
setExpandedGroups
|
|
93
|
+
setExpandedGroups(newExpandedHashMap); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, [treeRoot, rerenderItems, searchQuery, highlightOnlyQuery, selection, expanded, setExpandedGroups // onVisibleItemsChange // evaluate potential performance hit?
|
|
93
95
|
]);
|
|
96
|
+
const flattenedItems = React.useMemo(() => treeHelpers.flattenTreeForDnD(data), [data]);
|
|
94
97
|
return {
|
|
95
98
|
visibleItems,
|
|
99
|
+
flattenedItems,
|
|
96
100
|
tree,
|
|
97
101
|
treeRoot,
|
|
98
102
|
rerenderItems,
|
|
@@ -100,5 +104,5 @@ const useTree = (data, props, states) => {
|
|
|
100
104
|
updateUserExpandedState
|
|
101
105
|
};
|
|
102
106
|
};
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
|
|
108
|
+
exports.useTree = useTree;
|
package/esm/TreeView.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { describe } from
|
|
4
|
-
import { TreeViewPropTypes } from
|
|
5
|
-
import TreeViewContext from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'react';
|
|
3
|
+
import { describe } from 'react-desc';
|
|
4
|
+
import { TreeViewPropTypes } from './react-desc-prop-types.js';
|
|
5
|
+
import TreeViewContext from './TreeViewContext.js';
|
|
6
|
+
import { useTreeview } from './config/useTreeview.js';
|
|
7
|
+
import { TreeList } from './parts/TreeList.js';
|
|
8
|
+
|
|
9
|
+
var _TreeList;
|
|
9
10
|
function TreeView(props) {
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
ctx
|
|
13
|
+
} = useTreeview(props);
|
|
14
|
+
return /*#__PURE__*/_jsx(TreeViewContext.Provider, {
|
|
13
15
|
value: ctx
|
|
14
|
-
},
|
|
16
|
+
}, void 0, _TreeList || (_TreeList = /*#__PURE__*/_jsx(TreeList, {})));
|
|
15
17
|
}
|
|
16
|
-
TreeView.propTypes = TreeViewPropTypes;
|
|
17
18
|
const TreeViewWithSchema = describe(TreeView);
|
|
18
19
|
TreeViewWithSchema.propTypes = TreeViewPropTypes;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
TreeViewWithSchema
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=TreeView.js.map
|
|
20
|
+
|
|
21
|
+
export { TreeView, TreeViewWithSchema };
|
package/esm/TreeViewContext.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createRef, createContext } from 'react';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-unused-vars */
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
function noop() {}
|
|
7
|
+
|
|
5
8
|
const defaultProps = {
|
|
6
9
|
plugins: [],
|
|
7
10
|
selection: {},
|
|
8
|
-
instanceRef: createRef(),
|
|
11
|
+
instanceRef: /*#__PURE__*/createRef(),
|
|
9
12
|
isItemDisabled: () => false,
|
|
10
13
|
disableIcons: false,
|
|
11
14
|
fluid: false,
|
|
12
15
|
isMultiSelect: false,
|
|
13
16
|
isSingleSelect: false,
|
|
17
|
+
getIsDropValid: () => true,
|
|
14
18
|
restrictDragAndDrop: false,
|
|
15
19
|
showChildrenAmount: false,
|
|
16
20
|
sortable: false,
|
|
@@ -23,15 +27,20 @@ const defaultProps = {
|
|
|
23
27
|
onSelectionChange: noop,
|
|
24
28
|
onExpandChange: noop,
|
|
25
29
|
onInstanceRefInitialized: noop,
|
|
26
|
-
rowSize:
|
|
27
|
-
labelOverflow:
|
|
28
|
-
noItemsPlaceholder:
|
|
29
|
-
nameKey:
|
|
30
|
-
width:
|
|
31
|
-
height:
|
|
30
|
+
rowSize: 'normal',
|
|
31
|
+
labelOverflow: 'wrap',
|
|
32
|
+
noItemsPlaceholder: 'No items found',
|
|
33
|
+
nameKey: 'name',
|
|
34
|
+
width: '100%',
|
|
35
|
+
height: '100%',
|
|
32
36
|
groupIcon: null,
|
|
33
37
|
itemIcon: null,
|
|
34
|
-
searchQuery:
|
|
38
|
+
searchQuery: '' // workaround on the typings over the fact that
|
|
39
|
+
// when we instantiate the context we can't have all the props
|
|
40
|
+
// we only have a part of them but the final typings will include missing props
|
|
41
|
+
// this is safe to do because
|
|
42
|
+
// we will "mergeWithDefaults" + "validatePropTypes" when we do instantiate the context
|
|
43
|
+
|
|
35
44
|
};
|
|
36
45
|
const defaultRelativeMouseCoord = {
|
|
37
46
|
isBefore: false,
|
|
@@ -46,28 +55,21 @@ const defaultRelativeMouseCoord = {
|
|
|
46
55
|
const defaultContext = {
|
|
47
56
|
props: defaultProps,
|
|
48
57
|
visibleItems: [],
|
|
58
|
+
flattenedItems: [],
|
|
49
59
|
withRadioChecks: false,
|
|
50
60
|
withCheckboxChecks: false,
|
|
51
61
|
withDragAndDrop: false,
|
|
52
|
-
relativeMouseCord: defaultRelativeMouseCoord,
|
|
53
|
-
setRelativeMouseCord: noop,
|
|
54
62
|
triggerTreeRerender: noop,
|
|
55
|
-
tree:
|
|
56
|
-
treeRoot:
|
|
63
|
+
tree: undefined,
|
|
64
|
+
treeRoot: undefined,
|
|
57
65
|
virtualListHelpers: {
|
|
58
66
|
virtualItems: [],
|
|
59
67
|
totalSize: 0,
|
|
60
68
|
scrollToOffset: noop,
|
|
61
69
|
scrollToIndex: noop
|
|
62
70
|
},
|
|
63
|
-
virtualListRef:
|
|
64
|
-
|
|
65
|
-
setIsDragging: noop,
|
|
66
|
-
isKeyboardDragging: false,
|
|
67
|
-
setIsKeyboardDragging: noop,
|
|
68
|
-
draggedItem: null,
|
|
69
|
-
setDraggedItem: noop,
|
|
70
|
-
uniqueTreeViewUUID: "",
|
|
71
|
+
virtualListRef: undefined,
|
|
72
|
+
uniqueTreeViewUUID: '',
|
|
71
73
|
selectedItem: null,
|
|
72
74
|
setSelectedItem: noop,
|
|
73
75
|
focusedItem: null,
|
|
@@ -83,11 +85,8 @@ const defaultContext = {
|
|
|
83
85
|
handleExpandGroup: noop,
|
|
84
86
|
updateUserExpandedState: noop
|
|
85
87
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
defaultRelativeMouseCoord
|
|
92
|
-
};
|
|
93
|
-
//# sourceMappingURL=TreeViewContext.js.map
|
|
88
|
+
/** Context for cross component communication */
|
|
89
|
+
|
|
90
|
+
const TreeViewContext = /*#__PURE__*/createContext(defaultContext);
|
|
91
|
+
|
|
92
|
+
export { TreeViewContext as default, defaultProps, defaultRelativeMouseCoord };
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
DSTreeViewPrefix,
|
|
8
|
-
treeItemBlockName,
|
|
9
|
-
treeListBlockName,
|
|
10
|
-
treeListNoItemsBn
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=cssClassesConstants.js.map
|
|
1
|
+
const DSTreeViewPrefix = 'em-ds';
|
|
2
|
+
const treeItemBlockName = 'tree-item';
|
|
3
|
+
const treeListBlockName = 'tree-list';
|
|
4
|
+
const treeListNoItemsBn = "".concat(treeListBlockName, "-no-items");
|
|
5
|
+
|
|
6
|
+
export { DSTreeViewPrefix, treeItemBlockName, treeListBlockName, treeListNoItemsBn };
|