@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,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 = __toESM(require("react"));
|
|
34
|
-
var import_tree_helpers = __toESM(require("./tree-helpers"));
|
|
35
|
-
var import_group_expands_helpers = __toESM(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,95 +1,97 @@
|
|
|
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 = __toESM(require("react"));
|
|
34
|
-
var import_tree_model = __toESM(require("tree-model"));
|
|
35
|
-
var import_lodash = __toESM(require("lodash"));
|
|
36
|
-
var import_tree_helpers = __toESM(require("./tree-helpers"));
|
|
37
|
-
var import_group_expands_helpers = __toESM(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
|
-
treeRoot.walk(
|
|
73
|
-
const shouldContinueWalking = true;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
treeRoot.walk(node => {
|
|
80
|
+
const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
|
|
81
|
+
|
|
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
|
]);
|
|
94
96
|
return {
|
|
95
97
|
visibleItems,
|
|
@@ -100,5 +102,5 @@ const useTree = (data, props, states) => {
|
|
|
100
102
|
updateUserExpandedState
|
|
101
103
|
};
|
|
102
104
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
|
|
106
|
+
exports.useTree = useTree;
|
package/esm/TreeView.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { describe } from
|
|
4
|
-
import { TreeViewPropTypes } from
|
|
5
|
-
import TreeViewContext from
|
|
6
|
-
import {
|
|
7
|
-
import { useTreeview } from
|
|
8
|
-
import { TreeList } from
|
|
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 { TreeDndPlugin, TreeDnD } from './plugins/dnd/TreeDndPlugin.js';
|
|
7
|
+
import { useTreeview } from './config/useTreeview.js';
|
|
8
|
+
import { TreeList } from './parts/TreeList.js';
|
|
9
|
+
|
|
10
|
+
var _TreeDnD, _TreeList;
|
|
9
11
|
function TreeView(props) {
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const {
|
|
13
|
+
plugins
|
|
14
|
+
} = props;
|
|
15
|
+
const {
|
|
16
|
+
ctx
|
|
17
|
+
} = useTreeview(props);
|
|
18
|
+
return /*#__PURE__*/_jsx(TreeViewContext.Provider, {
|
|
13
19
|
value: ctx
|
|
14
|
-
}, plugins
|
|
20
|
+
}, void 0, plugins !== null && plugins !== void 0 && plugins.includes(TreeDndPlugin) ? _TreeDnD || (_TreeDnD = /*#__PURE__*/_jsx(TreeDnD, {})) : _TreeList || (_TreeList = /*#__PURE__*/_jsx(TreeList, {})));
|
|
15
21
|
}
|
|
16
|
-
TreeView.propTypes = TreeViewPropTypes;
|
|
17
22
|
const TreeViewWithSchema = describe(TreeView);
|
|
18
23
|
TreeViewWithSchema.propTypes = TreeViewPropTypes;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
TreeViewWithSchema
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=TreeView.js.map
|
|
24
|
+
|
|
25
|
+
export { TreeView, TreeViewWithSchema };
|
package/esm/TreeViewContext.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
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,
|
|
@@ -23,15 +26,20 @@ const defaultProps = {
|
|
|
23
26
|
onSelectionChange: noop,
|
|
24
27
|
onExpandChange: noop,
|
|
25
28
|
onInstanceRefInitialized: noop,
|
|
26
|
-
rowSize:
|
|
27
|
-
labelOverflow:
|
|
28
|
-
noItemsPlaceholder:
|
|
29
|
-
nameKey:
|
|
30
|
-
width:
|
|
31
|
-
height:
|
|
29
|
+
rowSize: 'normal',
|
|
30
|
+
labelOverflow: 'wrap',
|
|
31
|
+
noItemsPlaceholder: 'No items found',
|
|
32
|
+
nameKey: 'name',
|
|
33
|
+
width: '100%',
|
|
34
|
+
height: '100%',
|
|
32
35
|
groupIcon: null,
|
|
33
36
|
itemIcon: null,
|
|
34
|
-
searchQuery:
|
|
37
|
+
searchQuery: '' // workaround on the typings over the fact that
|
|
38
|
+
// when we instantiate the context we can't have all the props
|
|
39
|
+
// we only have a part of them but the final typings will include missing props
|
|
40
|
+
// this is safe to do because
|
|
41
|
+
// we will "mergeWithDefaults" + "validatePropTypes" when we do instantiate the context
|
|
42
|
+
|
|
35
43
|
};
|
|
36
44
|
const defaultRelativeMouseCoord = {
|
|
37
45
|
isBefore: false,
|
|
@@ -52,22 +60,22 @@ const defaultContext = {
|
|
|
52
60
|
relativeMouseCord: defaultRelativeMouseCoord,
|
|
53
61
|
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:
|
|
71
|
+
virtualListRef: undefined,
|
|
64
72
|
isDragging: false,
|
|
65
73
|
setIsDragging: noop,
|
|
66
74
|
isKeyboardDragging: false,
|
|
67
75
|
setIsKeyboardDragging: noop,
|
|
68
76
|
draggedItem: null,
|
|
69
77
|
setDraggedItem: noop,
|
|
70
|
-
uniqueTreeViewUUID:
|
|
78
|
+
uniqueTreeViewUUID: '',
|
|
71
79
|
selectedItem: null,
|
|
72
80
|
setSelectedItem: noop,
|
|
73
81
|
focusedItem: null,
|
|
@@ -83,11 +91,8 @@ const defaultContext = {
|
|
|
83
91
|
handleExpandGroup: noop,
|
|
84
92
|
updateUserExpandedState: noop
|
|
85
93
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
defaultRelativeMouseCoord
|
|
92
|
-
};
|
|
93
|
-
//# sourceMappingURL=TreeViewContext.js.map
|
|
94
|
+
/** Context for cross component communication */
|
|
95
|
+
|
|
96
|
+
const TreeViewContext = /*#__PURE__*/createContext(defaultContext);
|
|
97
|
+
|
|
98
|
+
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 };
|
|
@@ -1,28 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
8
|
+
import { useRef, useState, useCallback, useMemo, useEffect } from 'react';
|
|
9
|
+
import { useVirtual } from 'react-virtual';
|
|
10
|
+
import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
|
|
11
|
+
import { v4 } from 'uuid';
|
|
12
|
+
import { TreeViewPropTypes } from '../react-desc-prop-types.js';
|
|
13
|
+
import { defaultProps, defaultRelativeMouseCoord } from '../TreeViewContext.js';
|
|
14
|
+
import { TreeDndPlugin } from '../plugins/dnd/TreeDndPlugin.js';
|
|
15
|
+
import { useTree } from '../utils/useTree.js';
|
|
16
|
+
import { toggleItemExpand, useNotifyExpandedChange } from '../utils/group-expands-helpers.js';
|
|
17
|
+
import { useInstanceRefActions } from '../utils/useInstanceRefActions.js';
|
|
18
|
+
import { useGlobalToggleAllExpandShortcut } from '../utils/keyboard-helpers.js';
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
const useTreeview = props => {
|
|
14
24
|
const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
|
|
15
25
|
useValidateTypescriptPropTypes(propsWithDefault, TreeViewPropTypes);
|
|
16
26
|
const defaultActions = {
|
|
17
27
|
actions: {
|
|
18
|
-
toggleExpandAll: () => {
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
setSelectedItemByVirtualIndex: () => {
|
|
23
|
-
},
|
|
24
|
-
setFocusedItemByVirtualIndex: () => {
|
|
25
|
-
}
|
|
28
|
+
toggleExpandAll: () => {},
|
|
29
|
+
scrollTo: () => {},
|
|
30
|
+
setSelectedItemByVirtualIndex: () => {},
|
|
31
|
+
setFocusedItemByVirtualIndex: () => {}
|
|
26
32
|
}
|
|
27
33
|
};
|
|
28
34
|
const treeRef = useRef(defaultActions);
|
|
@@ -39,26 +45,32 @@ const useTreeview = (props) => {
|
|
|
39
45
|
const [isDragging, setIsDragging] = useState(false);
|
|
40
46
|
const [isKeyboardDragging, setIsKeyboardDragging] = useState(false);
|
|
41
47
|
const [relativeMouseCord, setRelativeMouseCord] = useState(defaultRelativeMouseCoord);
|
|
42
|
-
const [uniqueTreeViewUUID] = useState(
|
|
48
|
+
const [uniqueTreeViewUUID] = useState(v4());
|
|
43
49
|
const [draggedItem, setDraggedItem] = useState(null);
|
|
44
50
|
const [hoverItem, setHoverItem] = useState(null);
|
|
45
51
|
const [latestToggledItem, setLatestToggledItem] = useState(null);
|
|
46
52
|
const [selectedItem, setSelectedItem] = useState(null);
|
|
47
53
|
const [focusedItem, setFocusedItem] = useState(null);
|
|
48
|
-
const [selectedCheckboxes, setSelectedCheckboxes] = useState({
|
|
49
|
-
...selection
|
|
50
|
-
});
|
|
54
|
+
const [selectedCheckboxes, setSelectedCheckboxes] = useState(_objectSpread({}, selection));
|
|
51
55
|
const [expandedGroups, setExpandedGroups] = useState({});
|
|
52
|
-
const {
|
|
56
|
+
const {
|
|
57
|
+
visibleItems,
|
|
58
|
+
tree,
|
|
59
|
+
treeRoot,
|
|
60
|
+
triggerTreeRerender,
|
|
61
|
+
updateUserExpandedState
|
|
62
|
+
} = useTree(data, propsWithDefault, {
|
|
53
63
|
setExpandedGroups
|
|
54
64
|
});
|
|
55
|
-
const virtualListRef = useRef();
|
|
65
|
+
const virtualListRef = useRef(); // estimateSize should not be really required given what was stated on
|
|
66
|
+
// https://github.com/tannerlinsley/react-virtual/issues/23
|
|
67
|
+
|
|
56
68
|
const virtualListHelpers = useVirtual({
|
|
57
69
|
size: visibleItems.length,
|
|
58
70
|
parentRef: virtualListRef,
|
|
59
71
|
overscan: 15
|
|
60
72
|
});
|
|
61
|
-
const withDragAndDrop = !!(plugins
|
|
73
|
+
const withDragAndDrop = !!(plugins !== null && plugins !== void 0 && plugins.includes(TreeDndPlugin) && onOrderChange);
|
|
62
74
|
const withRadioChecks = isSingleSelect && !isMultiSelect;
|
|
63
75
|
const withCheckboxChecks = !isSingleSelect && isMultiSelect;
|
|
64
76
|
const handleExpandGroup = useCallback(toggleItemExpand, []);
|
|
@@ -96,41 +108,22 @@ const useTreeview = (props) => {
|
|
|
96
108
|
setHoverItem,
|
|
97
109
|
handleExpandGroup,
|
|
98
110
|
updateUserExpandedState
|
|
99
|
-
}), [
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
handleExpandGroup,
|
|
104
|
-
hoverItem,
|
|
105
|
-
isDragging,
|
|
106
|
-
isKeyboardDragging,
|
|
107
|
-
latestToggledItem,
|
|
108
|
-
propsWithDefault,
|
|
109
|
-
relativeMouseCord,
|
|
110
|
-
selectedCheckboxes,
|
|
111
|
-
selectedItem,
|
|
112
|
-
tree,
|
|
113
|
-
treeRoot,
|
|
114
|
-
triggerTreeRerender,
|
|
115
|
-
uniqueTreeViewUUID,
|
|
116
|
-
virtualListHelpers,
|
|
117
|
-
visibleItems,
|
|
118
|
-
withCheckboxChecks,
|
|
119
|
-
withDragAndDrop,
|
|
120
|
-
withRadioChecks,
|
|
121
|
-
updateUserExpandedState
|
|
122
|
-
]);
|
|
123
|
-
if (instanceRef)
|
|
124
|
-
instanceRef.current = treeRef.current;
|
|
111
|
+
}), [draggedItem, expandedGroups, focusedItem, handleExpandGroup, hoverItem, isDragging, isKeyboardDragging, latestToggledItem, propsWithDefault, relativeMouseCord, selectedCheckboxes, selectedItem, tree, treeRoot, triggerTreeRerender, uniqueTreeViewUUID, virtualListHelpers, visibleItems, withCheckboxChecks, withDragAndDrop, withRadioChecks, updateUserExpandedState]); // this hooks can't use the context because the context provider doesn't wrap this
|
|
112
|
+
// as such we manually pass the second parameter as fit
|
|
113
|
+
|
|
114
|
+
if (instanceRef) instanceRef.current = treeRef.current;
|
|
125
115
|
useInstanceRefActions(treeRef.current, ctx);
|
|
126
116
|
useGlobalToggleAllExpandShortcut(treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
127
|
-
useNotifyExpandedChange(propsWithDefault, ctx);
|
|
117
|
+
useNotifyExpandedChange(propsWithDefault, ctx); // this is an horrible hack.
|
|
118
|
+
// this is required because there is no "on rendered" react-way to check if every children has finished rendering
|
|
119
|
+
// this should be working for now, in the future we may want to review this for a better solution
|
|
120
|
+
|
|
128
121
|
useEffect(() => {
|
|
129
|
-
setTimeout(() => onInstanceRefInitialized(treeRef), 100);
|
|
122
|
+
setTimeout(() => onInstanceRefInitialized(treeRef), 100); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
123
|
}, []);
|
|
131
|
-
return useMemo(() => ({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
useTreeview
|
|
124
|
+
return useMemo(() => ({
|
|
125
|
+
ctx
|
|
126
|
+
}), [ctx]);
|
|
135
127
|
};
|
|
136
|
-
|
|
128
|
+
|
|
129
|
+
export { useTreeview };
|