@elliemae/ds-treeview 2.2.0-alpha.2 → 2.2.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/TreeView.js +27 -49
- package/cjs/TreeViewContext.js +37 -61
- package/cjs/config/cssClassesConstants.js +13 -41
- package/cjs/config/useTreeview.js +78 -116
- package/cjs/hoc/DnDTreeContext.js +18 -0
- package/cjs/hoc/SortableItemContext.js +21 -0
- package/cjs/hoc/WithConditionalDnDContext.js +138 -0
- package/cjs/hoc/WithDnDSortableItemContext.js +70 -0
- package/cjs/index.js +26 -37
- package/cjs/parts/CheckboxSelectable.js +59 -70
- package/cjs/parts/ChildrenCountDisplayer.js +28 -45
- package/cjs/parts/DnDHandle.js +46 -0
- package/cjs/parts/DropIndicator.js +75 -0
- package/cjs/parts/ExpandCaret.js +83 -85
- package/cjs/parts/Icon.js +31 -46
- package/cjs/parts/NestingSpace.js +35 -43
- package/cjs/parts/RadioSelectable.js +37 -52
- package/cjs/parts/TreeItem.js +141 -147
- package/cjs/parts/TreeItemText.js +95 -88
- package/cjs/parts/TreeList.js +130 -119
- package/cjs/plugins/dnd/TreeDndPlugin.js +7 -59
- package/cjs/plugins/dnd/index.js +9 -28
- package/cjs/plugins/index.js +21 -34
- package/cjs/plugins/roving/TreeRovingPlugin.js +7 -35
- package/cjs/plugins/roving/index.js +9 -28
- package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -35
- package/cjs/plugins/searchable/index.js +9 -28
- package/cjs/plugins/selectable/SelectablePluginTree.js +7 -35
- package/cjs/plugins/selectable/index.js +9 -28
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -35
- package/cjs/plugins/toolbar/index.js +9 -28
- package/cjs/plugins/tree/TreeDataPlugin.js +7 -35
- package/cjs/plugins/tree/index.js +9 -28
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -35
- package/cjs/plugins/virtualization/index.js +9 -28
- package/cjs/react-desc-prop-types.js +54 -82
- package/cjs/related-components/TreeViewSearchBar.js +40 -42
- package/cjs/sharedTypes.js +2 -27
- package/cjs/utils/array-helpers.js +11 -35
- package/cjs/utils/group-expands-helpers.js +59 -86
- package/cjs/utils/keyboard-helpers.js +90 -85
- package/cjs/utils/object-helpers.js +36 -43
- package/cjs/utils/refs-helpers.js +22 -43
- package/cjs/utils/selectable-helper.js +53 -61
- package/cjs/utils/string-helpers.js +7 -35
- package/cjs/utils/tree-helpers.js +161 -105
- package/cjs/utils/useInstanceRefActions.js +43 -54
- package/cjs/utils/useTree.js +80 -76
- package/esm/TreeView.js +16 -18
- package/esm/TreeViewContext.js +31 -32
- package/esm/config/cssClassesConstants.js +6 -12
- package/esm/config/useTreeview.js +56 -73
- package/esm/hoc/DnDTreeContext.js +14 -0
- package/esm/hoc/SortableItemContext.js +17 -0
- package/esm/hoc/WithConditionalDnDContext.js +128 -0
- package/esm/hoc/WithDnDSortableItemContext.js +61 -0
- package/esm/index.js +9 -8
- package/esm/parts/CheckboxSelectable.js +46 -36
- package/esm/parts/ChildrenCountDisplayer.js +20 -16
- package/esm/parts/DnDHandle.js +38 -0
- package/esm/parts/DropIndicator.js +68 -0
- package/esm/parts/ExpandCaret.js +72 -54
- package/esm/parts/Icon.js +22 -16
- package/esm/parts/NestingSpace.js +27 -14
- package/esm/parts/RadioSelectable.js +28 -20
- package/esm/parts/TreeItem.js +125 -114
- package/esm/parts/TreeItemText.js +85 -58
- package/esm/parts/TreeList.js +119 -91
- package/esm/plugins/dnd/TreeDndPlugin.js +3 -30
- package/esm/plugins/dnd/index.js +1 -3
- package/esm/plugins/index.js +7 -9
- package/esm/plugins/roving/TreeRovingPlugin.js +3 -6
- package/esm/plugins/roving/index.js +1 -3
- package/esm/plugins/searchable/SearchableTreePlugin.js +3 -6
- package/esm/plugins/searchable/index.js +1 -3
- package/esm/plugins/selectable/SelectablePluginTree.js +3 -6
- package/esm/plugins/selectable/index.js +1 -3
- package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -6
- package/esm/plugins/toolbar/index.js +1 -3
- package/esm/plugins/tree/TreeDataPlugin.js +3 -6
- package/esm/plugins/tree/index.js +1 -3
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -6
- package/esm/plugins/virtualization/index.js +1 -3
- package/esm/react-desc-prop-types.js +44 -47
- package/esm/related-components/TreeViewSearchBar.js +32 -13
- package/esm/sharedTypes.js +1 -2
- package/esm/utils/array-helpers.js +6 -6
- package/esm/utils/group-expands-helpers.js +46 -56
- package/esm/utils/keyboard-helpers.js +74 -46
- package/esm/utils/object-helpers.js +31 -14
- package/esm/utils/refs-helpers.js +19 -15
- package/esm/utils/selectable-helper.js +43 -32
- package/esm/utils/string-helpers.js +3 -6
- package/esm/utils/tree-helpers.js +143 -73
- package/esm/utils/useInstanceRefActions.js +35 -21
- package/esm/utils/useTree.js +59 -35
- package/package.json +35 -19
- package/types/hoc/DnDTreeContext.d.ts +14 -0
- package/types/hoc/SortableItemContext.d.ts +19 -0
- package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
- package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
- package/types/parts/DnDHandle.d.ts +6 -0
- package/types/parts/DropIndicator.d.ts +10 -0
- package/types/parts/TreeItem.d.ts +4 -11
- package/types/parts/TreeList.d.ts +0 -4
- package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
- package/types/react-desc-prop-types.d.ts +17 -3
- package/types/sharedTypes.d.ts +1 -8
- package/types/utils/keyboard-helpers.d.ts +2 -1
- package/types/utils/refs-helpers.d.ts +1 -1
- package/types/utils/tree-helpers.d.ts +4 -1
- package/types/utils/useTree.d.ts +1 -0
- package/cjs/TreeView.js.map +0 -7
- package/cjs/TreeViewContext.js.map +0 -7
- package/cjs/config/cssClassesConstants.js.map +0 -7
- package/cjs/config/useTreeview.js.map +0 -7
- package/cjs/index.js.map +0 -7
- package/cjs/parts/CheckboxSelectable.js.map +0 -7
- package/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
- package/cjs/parts/ExpandCaret.js.map +0 -7
- package/cjs/parts/Icon.js.map +0 -7
- package/cjs/parts/NestingSpace.js.map +0 -7
- package/cjs/parts/RadioSelectable.js.map +0 -7
- package/cjs/parts/TreeItem.js.map +0 -7
- package/cjs/parts/TreeItemText.js.map +0 -7
- package/cjs/parts/TreeList.js.map +0 -7
- package/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
- package/cjs/plugins/dnd/index.js.map +0 -7
- package/cjs/plugins/index.js.map +0 -7
- package/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
- package/cjs/plugins/roving/index.js.map +0 -7
- package/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
- package/cjs/plugins/searchable/index.js.map +0 -7
- package/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
- package/cjs/plugins/selectable/index.js.map +0 -7
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
- package/cjs/plugins/toolbar/index.js.map +0 -7
- package/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
- package/cjs/plugins/tree/index.js.map +0 -7
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
- package/cjs/plugins/virtualization/index.js.map +0 -7
- package/cjs/react-desc-prop-types.js.map +0 -7
- package/cjs/related-components/TreeViewSearchBar.js.map +0 -7
- package/cjs/sharedTypes.js.map +0 -7
- package/cjs/utils/array-helpers.js.map +0 -7
- package/cjs/utils/dnd-helpers.js +0 -146
- package/cjs/utils/dnd-helpers.js.map +0 -7
- package/cjs/utils/group-expands-helpers.js.map +0 -7
- package/cjs/utils/keyboard-helpers.js.map +0 -7
- package/cjs/utils/object-helpers.js.map +0 -7
- package/cjs/utils/refs-helpers.js.map +0 -7
- package/cjs/utils/selectable-helper.js.map +0 -7
- package/cjs/utils/string-helpers.js.map +0 -7
- package/cjs/utils/tree-helpers.js.map +0 -7
- package/cjs/utils/useDnDHelpers.js +0 -199
- package/cjs/utils/useDnDHelpers.js.map +0 -7
- package/cjs/utils/useInstanceRefActions.js.map +0 -7
- package/cjs/utils/useTree.js.map +0 -7
- package/esm/TreeView.js.map +0 -7
- package/esm/TreeViewContext.js.map +0 -7
- package/esm/config/cssClassesConstants.js.map +0 -7
- package/esm/config/useTreeview.js.map +0 -7
- package/esm/index.js.map +0 -7
- package/esm/parts/CheckboxSelectable.js.map +0 -7
- package/esm/parts/ChildrenCountDisplayer.js.map +0 -7
- package/esm/parts/ExpandCaret.js.map +0 -7
- package/esm/parts/Icon.js.map +0 -7
- package/esm/parts/NestingSpace.js.map +0 -7
- package/esm/parts/RadioSelectable.js.map +0 -7
- package/esm/parts/TreeItem.js.map +0 -7
- package/esm/parts/TreeItemText.js.map +0 -7
- package/esm/parts/TreeList.js.map +0 -7
- package/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
- package/esm/plugins/dnd/index.js.map +0 -7
- package/esm/plugins/index.js.map +0 -7
- package/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
- package/esm/plugins/roving/index.js.map +0 -7
- package/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
- package/esm/plugins/searchable/index.js.map +0 -7
- package/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
- package/esm/plugins/selectable/index.js.map +0 -7
- package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
- package/esm/plugins/toolbar/index.js.map +0 -7
- package/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
- package/esm/plugins/tree/index.js.map +0 -7
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
- package/esm/plugins/virtualization/index.js.map +0 -7
- package/esm/react-desc-prop-types.js.map +0 -7
- package/esm/related-components/TreeViewSearchBar.js.map +0 -7
- package/esm/sharedTypes.js.map +0 -7
- package/esm/utils/array-helpers.js.map +0 -7
- package/esm/utils/dnd-helpers.js +0 -117
- package/esm/utils/dnd-helpers.js.map +0 -7
- package/esm/utils/group-expands-helpers.js.map +0 -7
- package/esm/utils/keyboard-helpers.js.map +0 -7
- package/esm/utils/object-helpers.js.map +0 -7
- package/esm/utils/refs-helpers.js.map +0 -7
- package/esm/utils/selectable-helper.js.map +0 -7
- package/esm/utils/string-helpers.js.map +0 -7
- package/esm/utils/tree-helpers.js.map +0 -7
- package/esm/utils/useDnDHelpers.js +0 -170
- package/esm/utils/useDnDHelpers.js.map +0 -7
- package/esm/utils/useInstanceRefActions.js.map +0 -7
- package/esm/utils/useTree.js.map +0 -7
- package/types/utils/dnd-helpers.d.ts +0 -39
- package/types/utils/useDnDHelpers.d.ts +0 -26
|
@@ -1,88 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
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 selectable_helper_exports = {};
|
|
29
|
-
__export(selectable_helper_exports, {
|
|
30
|
-
getGroupCheckState: () => getGroupCheckState,
|
|
31
|
-
selectCheckboxItemModelParentsTillRoot: () => selectCheckboxItemModelParentsTillRoot,
|
|
32
|
-
toggleCheckboxItem: () => toggleCheckboxItem
|
|
33
|
-
});
|
|
34
|
-
var React = __toESM(require("react"));
|
|
35
|
-
var import_tree_helpers = __toESM(require("./tree-helpers"));
|
|
36
|
-
const getGroupCheckState = (node) => {
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
10
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
11
|
+
var treeHelpers = require('./tree-helpers.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
16
|
+
|
|
17
|
+
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; }
|
|
18
|
+
|
|
19
|
+
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; }
|
|
20
|
+
const getGroupCheckState = node => {
|
|
37
21
|
let childAllChecked = true;
|
|
38
22
|
let anyChildChecked = false;
|
|
39
|
-
|
|
23
|
+
treeHelpers.walkAllNodeChildren(node, childNode => {
|
|
40
24
|
const {
|
|
41
|
-
model: {
|
|
25
|
+
model: {
|
|
26
|
+
isChecked
|
|
27
|
+
}
|
|
42
28
|
} = childNode;
|
|
43
|
-
if (isChecked ===
|
|
44
|
-
anyChildChecked = true;
|
|
45
|
-
else
|
|
46
|
-
childAllChecked = false;
|
|
29
|
+
if (isChecked === 'mixed' || isChecked === true) anyChildChecked = true;else childAllChecked = false;
|
|
47
30
|
});
|
|
48
|
-
if (childAllChecked)
|
|
49
|
-
|
|
50
|
-
if (anyChildChecked)
|
|
51
|
-
return "mixed";
|
|
31
|
+
if (childAllChecked) return true;
|
|
32
|
+
if (anyChildChecked) return 'mixed';
|
|
52
33
|
return false;
|
|
53
34
|
};
|
|
54
|
-
const selectCheckboxItemModelParentsTillRoot = (modelToCheck
|
|
35
|
+
const selectCheckboxItemModelParentsTillRoot = function (modelToCheck) {
|
|
36
|
+
let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
55
37
|
const newSelections = {};
|
|
56
|
-
const {
|
|
57
|
-
|
|
38
|
+
const {
|
|
39
|
+
nodePath
|
|
40
|
+
} = modelToCheck;
|
|
41
|
+
treeHelpers.walkParents(nodePath, parentNode => {
|
|
58
42
|
const nextState = getGroupCheckState(parentNode);
|
|
59
43
|
parentNode.model.isChecked = nextState;
|
|
60
44
|
newSelections[parentNode.model.id] = nextState;
|
|
61
45
|
});
|
|
62
|
-
if (triggerTreeRerender)
|
|
63
|
-
triggerTreeRerender();
|
|
46
|
+
if (triggerTreeRerender) triggerTreeRerender();
|
|
64
47
|
return newSelections;
|
|
65
48
|
};
|
|
66
|
-
const toggleCheckboxItem = (itemToSelect
|
|
49
|
+
const toggleCheckboxItem = function (itemToSelect) {
|
|
50
|
+
let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
67
51
|
const {
|
|
68
52
|
node: {
|
|
69
|
-
model: {
|
|
53
|
+
model: {
|
|
54
|
+
id,
|
|
55
|
+
isChecked,
|
|
56
|
+
children = []
|
|
57
|
+
}
|
|
70
58
|
}
|
|
71
59
|
} = itemToSelect;
|
|
72
|
-
const newSelections = {};
|
|
73
|
-
|
|
60
|
+
const newSelections = {}; // 'mixed' -> true -> false -> true [...->false -> true]
|
|
61
|
+
|
|
62
|
+
const nextState = isChecked === 'mixed' ? true : !isChecked;
|
|
74
63
|
itemToSelect.node.model.isChecked = nextState;
|
|
75
64
|
newSelections[id] = nextState;
|
|
65
|
+
|
|
76
66
|
if (children.length > 0 && (nextState === true || nextState === false)) {
|
|
77
|
-
|
|
67
|
+
treeHelpers.walkAllNodeChildren(itemToSelect.node, childNode => {
|
|
78
68
|
childNode.model.isChecked = nextState;
|
|
79
69
|
newSelections[childNode.model.id] = nextState;
|
|
80
70
|
});
|
|
81
71
|
}
|
|
72
|
+
|
|
82
73
|
const parentsNewSelections = selectCheckboxItemModelParentsTillRoot(itemToSelect);
|
|
83
|
-
if (triggerTreeRerender)
|
|
84
|
-
|
|
85
|
-
return { ...parentsNewSelections, ...newSelections };
|
|
74
|
+
if (triggerTreeRerender) triggerTreeRerender();
|
|
75
|
+
return _objectSpread(_objectSpread({}, parentsNewSelections), newSelections);
|
|
86
76
|
};
|
|
87
|
-
|
|
88
|
-
|
|
77
|
+
|
|
78
|
+
exports.getGroupCheckState = getGroupCheckState;
|
|
79
|
+
exports.selectCheckboxItemModelParentsTillRoot = selectCheckboxItemModelParentsTillRoot;
|
|
80
|
+
exports.toggleCheckboxItem = toggleCheckboxItem;
|
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
-
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
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 string_helpers_exports = {};
|
|
29
|
-
__export(string_helpers_exports, {
|
|
30
|
-
standardizeSearchQueryString: () => standardizeSearchQueryString
|
|
31
|
-
});
|
|
32
|
-
var React = __toESM(require("react"));
|
|
33
|
-
const standardizeSearchQueryString = (input) => input.trim().toLowerCase();
|
|
34
|
-
module.exports = __toCommonJS(string_helpers_exports);
|
|
35
|
-
//# sourceMappingURL=string-helpers.js.map
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const standardizeSearchQueryString = input => input.trim().toLowerCase();
|
|
6
|
+
|
|
7
|
+
exports.standardizeSearchQueryString = standardizeSearchQueryString;
|
|
@@ -1,164 +1,220 @@
|
|
|
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$children$, _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$children$ = (_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) !== null && _node$model$children$ !== void 0 ? _node$model$children$ : 0) > 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();
|
|
182
|
+
};
|
|
183
|
+
const flattenTreeForDnD = function (data) {
|
|
184
|
+
let shouldDescend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => true;
|
|
185
|
+
const flattenedTree = [];
|
|
186
|
+
let index = 0;
|
|
187
|
+
|
|
188
|
+
const doit = function (node) {
|
|
189
|
+
var _node$children$length, _node$children, _node$children2;
|
|
190
|
+
|
|
191
|
+
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
192
|
+
let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
193
|
+
flattenedTree.push({
|
|
194
|
+
uid: node.id.toString(),
|
|
195
|
+
depth,
|
|
196
|
+
realIndex: index,
|
|
197
|
+
childrenCount: (_node$children$length = (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) !== null && _node$children$length !== void 0 ? _node$children$length : 0,
|
|
198
|
+
parentId: parentId !== null ? parentId.toString() : null,
|
|
199
|
+
original: node
|
|
200
|
+
});
|
|
201
|
+
index += 1;
|
|
202
|
+
if (shouldDescend(node)) (_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.forEach(child => doit(child, depth + 1, node.id.toString()));
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
data.forEach(datum => doit(datum));
|
|
206
|
+
return flattenedTree;
|
|
162
207
|
};
|
|
163
|
-
|
|
164
|
-
|
|
208
|
+
|
|
209
|
+
exports.cloneNode = cloneNode;
|
|
210
|
+
exports.enrichNodeModelInPlace = enrichNodeModelInPlace;
|
|
211
|
+
exports.flattenTreeForDnD = flattenTreeForDnD;
|
|
212
|
+
exports.focusItem = focusItem;
|
|
213
|
+
exports.getChildrenMatchesSearchQuery = getChildrenMatchesSearchQuery;
|
|
214
|
+
exports.getItemsParentNode = getItemsParentNode;
|
|
215
|
+
exports.getNodeById = getNodeById;
|
|
216
|
+
exports.getNodeMatchesSearchQuery = getNodeMatchesSearchQuery;
|
|
217
|
+
exports.itemsShareSameParent = itemsShareSameParent;
|
|
218
|
+
exports.walkAllNodeChildren = walkAllNodeChildren;
|
|
219
|
+
exports.walkParents = walkParents;
|
|
220
|
+
exports.walkVisibles = walkVisibles;
|