@elliemae/ds-treeview 2.3.1 → 3.0.0-alpha.3
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/dist/cjs/TreeView.js +50 -0
- package/dist/cjs/TreeView.js.map +7 -0
- package/dist/cjs/TreeViewContext.js +116 -0
- package/dist/cjs/TreeViewContext.js.map +7 -0
- package/dist/cjs/config/cssClassesConstants.js +41 -0
- package/dist/cjs/config/cssClassesConstants.js.map +7 -0
- package/dist/cjs/config/useTreeview.js +163 -0
- package/dist/cjs/config/useTreeview.js.map +7 -0
- package/dist/cjs/hoc/DnDTreeContext.js +45 -0
- package/dist/cjs/hoc/DnDTreeContext.js.map +7 -0
- package/dist/cjs/hoc/SortableItemContext.js +46 -0
- package/dist/cjs/hoc/SortableItemContext.js.map +7 -0
- package/dist/cjs/hoc/WithConditionalDnDContext.js +134 -0
- package/dist/cjs/hoc/WithConditionalDnDContext.js.map +7 -0
- package/dist/cjs/hoc/WithDnDSortableItemContext.js +83 -0
- package/dist/cjs/hoc/WithDnDSortableItemContext.js.map +7 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/parts/CheckboxSelectable.js +111 -0
- package/dist/cjs/parts/CheckboxSelectable.js.map +7 -0
- package/dist/cjs/parts/ChildrenCountDisplayer.js +47 -0
- package/dist/cjs/parts/ChildrenCountDisplayer.js.map +7 -0
- package/dist/cjs/parts/DnDHandle.js +71 -0
- package/dist/cjs/parts/DnDHandle.js.map +7 -0
- package/dist/cjs/parts/DropIndicator.js +80 -0
- package/dist/cjs/parts/DropIndicator.js.map +7 -0
- package/dist/cjs/parts/ExpandCaret.js +96 -0
- package/dist/cjs/parts/ExpandCaret.js.map +7 -0
- package/dist/cjs/parts/Icon.js +52 -0
- package/dist/cjs/parts/Icon.js.map +7 -0
- package/dist/cjs/parts/NestingSpace.js +55 -0
- package/dist/cjs/parts/NestingSpace.js.map +7 -0
- package/dist/cjs/parts/RadioSelectable.js +74 -0
- package/dist/cjs/parts/RadioSelectable.js.map +7 -0
- package/dist/cjs/parts/TreeItem.js +180 -0
- package/dist/cjs/parts/TreeItem.js.map +7 -0
- package/dist/cjs/parts/TreeItemText.js +101 -0
- package/dist/cjs/parts/TreeItemText.js.map +7 -0
- package/dist/cjs/parts/TreeList.js +135 -0
- package/dist/cjs/parts/TreeList.js.map +7 -0
- package/dist/cjs/plugins/dnd/TreeDndPlugin.js +35 -0
- package/dist/cjs/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/dist/cjs/plugins/dnd/index.js +28 -0
- package/dist/cjs/plugins/dnd/index.js.map +7 -0
- package/dist/cjs/plugins/index.js +34 -0
- package/dist/cjs/plugins/index.js.map +7 -0
- package/dist/cjs/plugins/roving/TreeRovingPlugin.js +35 -0
- package/dist/cjs/plugins/roving/TreeRovingPlugin.js.map +7 -0
- package/dist/cjs/plugins/roving/index.js +28 -0
- package/dist/cjs/plugins/roving/index.js.map +7 -0
- package/dist/cjs/plugins/searchable/SearchableTreePlugin.js +35 -0
- package/dist/cjs/plugins/searchable/SearchableTreePlugin.js.map +7 -0
- package/dist/cjs/plugins/searchable/index.js +28 -0
- package/dist/cjs/plugins/searchable/index.js.map +7 -0
- package/dist/cjs/plugins/selectable/SelectablePluginTree.js +35 -0
- package/dist/cjs/plugins/selectable/SelectablePluginTree.js.map +7 -0
- package/dist/cjs/plugins/selectable/index.js +28 -0
- package/dist/cjs/plugins/selectable/index.js.map +7 -0
- package/dist/cjs/plugins/toolbar/TreeToolbarPlugin.js +35 -0
- package/dist/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
- package/dist/cjs/plugins/toolbar/index.js +28 -0
- package/dist/cjs/plugins/toolbar/index.js.map +7 -0
- package/dist/cjs/plugins/tree/TreeDataPlugin.js +35 -0
- package/dist/cjs/plugins/tree/TreeDataPlugin.js.map +7 -0
- package/dist/cjs/plugins/tree/index.js +28 -0
- package/dist/cjs/plugins/tree/index.js.map +7 -0
- package/dist/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +35 -0
- package/dist/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
- package/dist/cjs/plugins/virtualization/index.js +28 -0
- package/dist/cjs/plugins/virtualization/index.js.map +7 -0
- package/dist/cjs/react-desc-prop-types.js +85 -0
- package/dist/cjs/react-desc-prop-types.js.map +7 -0
- package/dist/cjs/related-components/TreeViewSearchBar.js +50 -0
- package/dist/cjs/related-components/TreeViewSearchBar.js.map +7 -0
- package/dist/cjs/sharedTypes.js +27 -0
- package/dist/cjs/sharedTypes.js.map +7 -0
- package/dist/cjs/utils/array-helpers.js +48 -0
- package/dist/cjs/utils/array-helpers.js.map +7 -0
- package/dist/cjs/utils/group-expands-helpers.js +138 -0
- package/dist/cjs/utils/group-expands-helpers.js.map +7 -0
- package/dist/cjs/utils/keyboard-helpers.js +170 -0
- package/dist/cjs/utils/keyboard-helpers.js.map +7 -0
- package/dist/cjs/utils/object-helpers.js +76 -0
- package/dist/cjs/utils/object-helpers.js.map +7 -0
- package/dist/cjs/utils/refs-helpers.js +52 -0
- package/dist/cjs/utils/refs-helpers.js.map +7 -0
- package/dist/cjs/utils/selectable-helper.js +102 -0
- package/dist/cjs/utils/selectable-helper.js.map +7 -0
- package/dist/cjs/utils/string-helpers.js +35 -0
- package/dist/cjs/utils/string-helpers.js.map +7 -0
- package/dist/cjs/utils/tree-helpers.js +184 -0
- package/dist/cjs/utils/tree-helpers.js.map +7 -0
- package/dist/cjs/utils/useInstanceRefActions.js +98 -0
- package/dist/cjs/utils/useInstanceRefActions.js.map +7 -0
- package/dist/cjs/utils/useTree.js +123 -0
- package/dist/cjs/utils/useTree.js.map +7 -0
- package/dist/esm/TreeView.js +21 -0
- package/dist/esm/TreeView.js.map +7 -0
- package/{esm → dist/esm}/TreeViewContext.js +24 -29
- package/dist/esm/TreeViewContext.js.map +7 -0
- package/dist/esm/config/cssClassesConstants.js +12 -0
- package/dist/esm/config/cssClassesConstants.js.map +7 -0
- package/dist/esm/config/useTreeview.js +136 -0
- package/dist/esm/config/useTreeview.js.map +7 -0
- package/dist/esm/hoc/DnDTreeContext.js +16 -0
- package/dist/esm/hoc/DnDTreeContext.js.map +7 -0
- package/dist/esm/hoc/SortableItemContext.js +17 -0
- package/dist/esm/hoc/SortableItemContext.js.map +7 -0
- package/dist/esm/hoc/WithConditionalDnDContext.js +107 -0
- package/dist/esm/hoc/WithConditionalDnDContext.js.map +7 -0
- package/dist/esm/hoc/WithDnDSortableItemContext.js +56 -0
- package/dist/esm/hoc/WithDnDSortableItemContext.js.map +7 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/parts/CheckboxSelectable.js +84 -0
- package/dist/esm/parts/CheckboxSelectable.js.map +7 -0
- package/dist/esm/parts/ChildrenCountDisplayer.js +18 -0
- package/dist/esm/parts/ChildrenCountDisplayer.js.map +7 -0
- package/dist/esm/parts/DnDHandle.js +44 -0
- package/dist/esm/parts/DnDHandle.js.map +7 -0
- package/dist/esm/parts/DropIndicator.js +51 -0
- package/dist/esm/parts/DropIndicator.js.map +7 -0
- package/dist/esm/parts/ExpandCaret.js +67 -0
- package/dist/esm/parts/ExpandCaret.js.map +7 -0
- package/dist/esm/parts/Icon.js +23 -0
- package/dist/esm/parts/Icon.js.map +7 -0
- package/dist/esm/parts/NestingSpace.js +26 -0
- package/dist/esm/parts/NestingSpace.js.map +7 -0
- package/dist/esm/parts/RadioSelectable.js +45 -0
- package/dist/esm/parts/RadioSelectable.js.map +7 -0
- package/dist/esm/parts/TreeItem.js +153 -0
- package/dist/esm/parts/TreeItem.js.map +7 -0
- package/dist/esm/parts/TreeItemText.js +72 -0
- package/dist/esm/parts/TreeItemText.js.map +7 -0
- package/dist/esm/parts/TreeList.js +108 -0
- package/dist/esm/parts/TreeList.js.map +7 -0
- package/dist/esm/plugins/dnd/TreeDndPlugin.js +6 -0
- package/dist/esm/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/dist/esm/plugins/dnd/index.js +3 -0
- package/dist/esm/plugins/dnd/index.js.map +7 -0
- package/dist/esm/plugins/index.js +9 -0
- package/dist/esm/plugins/index.js.map +7 -0
- package/dist/esm/plugins/roving/TreeRovingPlugin.js +6 -0
- package/dist/esm/plugins/roving/TreeRovingPlugin.js.map +7 -0
- package/dist/esm/plugins/roving/index.js +3 -0
- package/dist/esm/plugins/roving/index.js.map +7 -0
- package/dist/esm/plugins/searchable/SearchableTreePlugin.js +6 -0
- package/dist/esm/plugins/searchable/SearchableTreePlugin.js.map +7 -0
- package/dist/esm/plugins/searchable/index.js +3 -0
- package/dist/esm/plugins/searchable/index.js.map +7 -0
- package/dist/esm/plugins/selectable/SelectablePluginTree.js +6 -0
- package/dist/esm/plugins/selectable/SelectablePluginTree.js.map +7 -0
- package/dist/esm/plugins/selectable/index.js +3 -0
- package/dist/esm/plugins/selectable/index.js.map +7 -0
- package/dist/esm/plugins/toolbar/TreeToolbarPlugin.js +6 -0
- package/dist/esm/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
- package/dist/esm/plugins/toolbar/index.js +3 -0
- package/dist/esm/plugins/toolbar/index.js.map +7 -0
- package/dist/esm/plugins/tree/TreeDataPlugin.js +6 -0
- package/dist/esm/plugins/tree/TreeDataPlugin.js.map +7 -0
- package/dist/esm/plugins/tree/index.js +3 -0
- package/dist/esm/plugins/tree/index.js.map +7 -0
- package/dist/esm/plugins/virtualization/TreeVirtualizationPlugin.js +6 -0
- package/dist/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
- package/dist/esm/plugins/virtualization/index.js +3 -0
- package/dist/esm/plugins/virtualization/index.js.map +7 -0
- package/dist/esm/react-desc-prop-types.js +56 -0
- package/dist/esm/react-desc-prop-types.js.map +7 -0
- package/dist/esm/related-components/TreeViewSearchBar.js +21 -0
- package/dist/esm/related-components/TreeViewSearchBar.js.map +7 -0
- package/dist/esm/sharedTypes.js +2 -0
- package/dist/esm/sharedTypes.js.map +7 -0
- package/{esm → dist/esm}/utils/array-helpers.js +6 -6
- package/dist/esm/utils/array-helpers.js.map +7 -0
- package/dist/esm/utils/group-expands-helpers.js +109 -0
- package/dist/esm/utils/group-expands-helpers.js.map +7 -0
- package/{esm → dist/esm}/utils/keyboard-helpers.js +43 -71
- package/dist/esm/utils/keyboard-helpers.js.map +7 -0
- package/dist/esm/utils/object-helpers.js +47 -0
- package/dist/esm/utils/object-helpers.js.map +7 -0
- package/dist/esm/utils/refs-helpers.js +23 -0
- package/dist/esm/utils/refs-helpers.js.map +7 -0
- package/dist/esm/utils/selectable-helper.js +75 -0
- package/dist/esm/utils/selectable-helper.js.map +7 -0
- package/dist/esm/utils/string-helpers.js +6 -0
- package/dist/esm/utils/string-helpers.js.map +7 -0
- package/dist/esm/utils/tree-helpers.js +155 -0
- package/dist/esm/utils/tree-helpers.js.map +7 -0
- package/{esm → dist/esm}/utils/useInstanceRefActions.js +21 -35
- package/dist/esm/utils/useInstanceRefActions.js.map +7 -0
- package/dist/esm/utils/useTree.js +96 -0
- package/dist/esm/utils/useTree.js.map +7 -0
- package/package.json +133 -123
- package/cjs/TreeView.js +0 -30
- package/cjs/TreeViewContext.js +0 -98
- package/cjs/config/cssClassesConstants.js +0 -13
- package/cjs/config/useTreeview.js +0 -127
- package/cjs/hoc/DnDTreeContext.js +0 -18
- package/cjs/hoc/SortableItemContext.js +0 -21
- package/cjs/hoc/WithConditionalDnDContext.js +0 -138
- package/cjs/hoc/WithDnDSortableItemContext.js +0 -70
- package/cjs/index.js +0 -26
- package/cjs/parts/CheckboxSelectable.js +0 -86
- package/cjs/parts/ChildrenCountDisplayer.js +0 -30
- package/cjs/parts/DnDHandle.js +0 -46
- package/cjs/parts/DropIndicator.js +0 -75
- package/cjs/parts/ExpandCaret.js +0 -94
- package/cjs/parts/Icon.js +0 -37
- package/cjs/parts/NestingSpace.js +0 -47
- package/cjs/parts/RadioSelectable.js +0 -59
- package/cjs/parts/TreeItem.js +0 -185
- package/cjs/parts/TreeItemText.js +0 -108
- package/cjs/parts/TreeList.js +0 -139
- package/cjs/plugins/dnd/TreeDndPlugin.js +0 -7
- package/cjs/plugins/dnd/index.js +0 -9
- package/cjs/plugins/index.js +0 -21
- package/cjs/plugins/roving/TreeRovingPlugin.js +0 -7
- package/cjs/plugins/roving/index.js +0 -9
- package/cjs/plugins/searchable/SearchableTreePlugin.js +0 -7
- package/cjs/plugins/searchable/index.js +0 -9
- package/cjs/plugins/selectable/SelectablePluginTree.js +0 -7
- package/cjs/plugins/selectable/index.js +0 -9
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js +0 -7
- package/cjs/plugins/toolbar/index.js +0 -9
- package/cjs/plugins/tree/TreeDataPlugin.js +0 -7
- package/cjs/plugins/tree/index.js +0 -9
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +0 -7
- package/cjs/plugins/virtualization/index.js +0 -9
- package/cjs/react-desc-prop-types.js +0 -56
- package/cjs/related-components/TreeViewSearchBar.js +0 -48
- package/cjs/sharedTypes.js +0 -2
- package/cjs/utils/array-helpers.js +0 -24
- package/cjs/utils/group-expands-helpers.js +0 -111
- package/cjs/utils/keyboard-helpers.js +0 -175
- package/cjs/utils/object-helpers.js +0 -69
- package/cjs/utils/refs-helpers.js +0 -31
- package/cjs/utils/selectable-helper.js +0 -80
- package/cjs/utils/string-helpers.js +0 -7
- package/cjs/utils/tree-helpers.js +0 -220
- package/cjs/utils/useInstanceRefActions.js +0 -87
- package/cjs/utils/useTree.js +0 -108
- package/esm/TreeView.js +0 -21
- package/esm/config/cssClassesConstants.js +0 -6
- package/esm/config/useTreeview.js +0 -119
- package/esm/hoc/DnDTreeContext.js +0 -14
- package/esm/hoc/SortableItemContext.js +0 -17
- package/esm/hoc/WithConditionalDnDContext.js +0 -128
- package/esm/hoc/WithDnDSortableItemContext.js +0 -61
- package/esm/index.js +0 -9
- package/esm/parts/CheckboxSelectable.js +0 -78
- package/esm/parts/ChildrenCountDisplayer.js +0 -22
- package/esm/parts/DnDHandle.js +0 -38
- package/esm/parts/DropIndicator.js +0 -68
- package/esm/parts/ExpandCaret.js +0 -85
- package/esm/parts/Icon.js +0 -29
- package/esm/parts/NestingSpace.js +0 -39
- package/esm/parts/RadioSelectable.js +0 -53
- package/esm/parts/TreeItem.js +0 -173
- package/esm/parts/TreeItemText.js +0 -99
- package/esm/parts/TreeList.js +0 -127
- package/esm/plugins/dnd/TreeDndPlugin.js +0 -3
- package/esm/plugins/dnd/index.js +0 -1
- package/esm/plugins/index.js +0 -7
- package/esm/plugins/roving/TreeRovingPlugin.js +0 -3
- package/esm/plugins/roving/index.js +0 -1
- package/esm/plugins/searchable/SearchableTreePlugin.js +0 -3
- package/esm/plugins/searchable/index.js +0 -1
- package/esm/plugins/selectable/SelectablePluginTree.js +0 -3
- package/esm/plugins/selectable/index.js +0 -1
- package/esm/plugins/toolbar/TreeToolbarPlugin.js +0 -3
- package/esm/plugins/toolbar/index.js +0 -1
- package/esm/plugins/tree/TreeDataPlugin.js +0 -3
- package/esm/plugins/tree/index.js +0 -1
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +0 -3
- package/esm/plugins/virtualization/index.js +0 -1
- package/esm/react-desc-prop-types.js +0 -52
- package/esm/related-components/TreeViewSearchBar.js +0 -40
- package/esm/sharedTypes.js +0 -1
- package/esm/utils/group-expands-helpers.js +0 -99
- package/esm/utils/object-helpers.js +0 -64
- package/esm/utils/refs-helpers.js +0 -27
- package/esm/utils/selectable-helper.js +0 -70
- package/esm/utils/string-helpers.js +0 -3
- package/esm/utils/tree-helpers.js +0 -205
- package/esm/utils/useTree.js +0 -99
- package/types/TreeView.d.ts +0 -13
- package/types/TreeViewContext.d.ts +0 -17
- package/types/config/cssClassesConstants.d.ts +0 -4
- package/types/config/useTreeview.d.ts +0 -7
- package/types/hoc/DnDTreeContext.d.ts +0 -14
- package/types/hoc/SortableItemContext.d.ts +0 -19
- package/types/hoc/WithConditionalDnDContext.d.ts +0 -4
- package/types/hoc/WithDnDSortableItemContext.d.ts +0 -4
- package/types/index.d.ts +0 -3
- package/types/parts/CheckboxSelectable.d.ts +0 -8
- package/types/parts/ChildrenCountDisplayer.d.ts +0 -7
- package/types/parts/DnDHandle.d.ts +0 -6
- package/types/parts/DropIndicator.d.ts +0 -10
- package/types/parts/ExpandCaret.d.ts +0 -7
- package/types/parts/Icon.d.ts +0 -7
- package/types/parts/NestingSpace.d.ts +0 -8
- package/types/parts/RadioSelectable.d.ts +0 -8
- package/types/parts/TreeItem.d.ts +0 -17
- package/types/parts/TreeItemText.d.ts +0 -7
- package/types/parts/TreeList.d.ts +0 -20
- package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -1
- package/types/plugins/dnd/index.d.ts +0 -1
- package/types/plugins/index.d.ts +0 -7
- package/types/plugins/roving/TreeRovingPlugin.d.ts +0 -1
- package/types/plugins/roving/index.d.ts +0 -1
- package/types/plugins/searchable/SearchableTreePlugin.d.ts +0 -1
- package/types/plugins/searchable/index.d.ts +0 -1
- package/types/plugins/selectable/SelectablePluginTree.d.ts +0 -1
- package/types/plugins/selectable/index.d.ts +0 -1
- package/types/plugins/toolbar/TreeToolbarPlugin.d.ts +0 -1
- package/types/plugins/toolbar/index.d.ts +0 -1
- package/types/plugins/tree/TreeDataPlugin.d.ts +0 -1
- package/types/plugins/tree/index.d.ts +0 -1
- package/types/plugins/virtualization/TreeVirtualizationPlugin.d.ts +0 -1
- package/types/plugins/virtualization/index.d.ts +0 -1
- package/types/react-desc-prop-types.d.ts +0 -210
- package/types/related-components/TreeViewSearchBar.d.ts +0 -16
- package/types/sharedTypes.d.ts +0 -47
- package/types/utils/array-helpers.d.ts +0 -2
- package/types/utils/group-expands-helpers.d.ts +0 -14
- package/types/utils/keyboard-helpers.d.ts +0 -6
- package/types/utils/object-helpers.d.ts +0 -6
- package/types/utils/refs-helpers.d.ts +0 -4
- package/types/utils/selectable-helper.d.ts +0 -7
- package/types/utils/string-helpers.d.ts +0 -1
- package/types/utils/tree-helpers.d.ts +0 -28
- package/types/utils/useInstanceRefActions.d.ts +0 -3
- package/types/utils/useTree.d.ts +0 -14
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
-
import 'core-js/modules/esnext.async-iterator.reduce.js';
|
|
5
|
-
import 'core-js/modules/esnext.iterator.reduce.js';
|
|
6
|
-
|
|
7
|
-
/* eslint-disable no-sequences */
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-return-assign */
|
|
10
|
-
|
|
11
|
-
/* eslint-disable no-restricted-syntax */
|
|
12
|
-
|
|
13
|
-
/* eslint-disable guard-for-in */
|
|
14
|
-
function isObjectADate(o) {
|
|
15
|
-
var _o$constructor;
|
|
16
|
-
|
|
17
|
-
return (o === null || o === void 0 ? void 0 : (_o$constructor = o.constructor) === null || _o$constructor === void 0 ? void 0 : _o$constructor.name) === 'Date';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function isObjectAnArray(o) {
|
|
21
|
-
return Array.isArray(o);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function isObjectAString(o) {
|
|
25
|
-
return typeof o === 'object';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const unfreeze = o => {
|
|
29
|
-
let oo;
|
|
30
|
-
|
|
31
|
-
if (o === null) {
|
|
32
|
-
oo = null;
|
|
33
|
-
} else if (o === undefined) {
|
|
34
|
-
oo = undefined;
|
|
35
|
-
} else if (isObjectADate(o)) {
|
|
36
|
-
oo = new Date(o);
|
|
37
|
-
} else if (isObjectAnArray(o)) {
|
|
38
|
-
oo = [];
|
|
39
|
-
o.forEach(v => {
|
|
40
|
-
oo.push(v);
|
|
41
|
-
});
|
|
42
|
-
} else if (isObjectAString(o)) {
|
|
43
|
-
oo = String(o);
|
|
44
|
-
} else if (isObjectAString(o)) {
|
|
45
|
-
oo = {};
|
|
46
|
-
|
|
47
|
-
for (const property in o) {
|
|
48
|
-
oo[property] = o[property];
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
oo = o;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return oo;
|
|
55
|
-
};
|
|
56
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
|
-
function filterObject(obj, predicate) {
|
|
58
|
-
return Object.keys(obj).reduce((res, key) => {
|
|
59
|
-
if (predicate(obj[key])) res[key] = obj[key];
|
|
60
|
-
return res;
|
|
61
|
-
}, {});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { filterObject, unfreeze };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
-
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
-
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
-
|
|
7
|
-
// allow multiple refs to be set to point to the same DOM element
|
|
8
|
-
const setMultipleRefs = function () {
|
|
9
|
-
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
10
|
-
refs[_key] = arguments[_key];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const filteredRefs = refs.filter(Boolean);
|
|
14
|
-
if (!filteredRefs.length) return () => {};
|
|
15
|
-
if (filteredRefs.length === 0) return () => {};
|
|
16
|
-
return newRef => {
|
|
17
|
-
filteredRefs.forEach(refToBeUpdated => {
|
|
18
|
-
if (typeof refToBeUpdated === 'function') {
|
|
19
|
-
refToBeUpdated(newRef);
|
|
20
|
-
} else if (refToBeUpdated) {
|
|
21
|
-
refToBeUpdated.current = newRef;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { setMultipleRefs };
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
-
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
-
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
-
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
-
import { walkAllNodeChildren, walkParents } from './tree-helpers.js';
|
|
8
|
-
|
|
9
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
-
|
|
11
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
const getGroupCheckState = node => {
|
|
13
|
-
let childAllChecked = true;
|
|
14
|
-
let anyChildChecked = false;
|
|
15
|
-
walkAllNodeChildren(node, childNode => {
|
|
16
|
-
const {
|
|
17
|
-
model: {
|
|
18
|
-
isChecked
|
|
19
|
-
}
|
|
20
|
-
} = childNode;
|
|
21
|
-
if (isChecked === 'mixed' || isChecked === true) anyChildChecked = true;else childAllChecked = false;
|
|
22
|
-
});
|
|
23
|
-
if (childAllChecked) return true;
|
|
24
|
-
if (anyChildChecked) return 'mixed';
|
|
25
|
-
return false;
|
|
26
|
-
};
|
|
27
|
-
const selectCheckboxItemModelParentsTillRoot = function (modelToCheck) {
|
|
28
|
-
let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
29
|
-
const newSelections = {};
|
|
30
|
-
const {
|
|
31
|
-
nodePath
|
|
32
|
-
} = modelToCheck;
|
|
33
|
-
walkParents(nodePath, parentNode => {
|
|
34
|
-
const nextState = getGroupCheckState(parentNode);
|
|
35
|
-
parentNode.model.isChecked = nextState;
|
|
36
|
-
newSelections[parentNode.model.id] = nextState;
|
|
37
|
-
});
|
|
38
|
-
if (triggerTreeRerender) triggerTreeRerender();
|
|
39
|
-
return newSelections;
|
|
40
|
-
};
|
|
41
|
-
const toggleCheckboxItem = function (itemToSelect) {
|
|
42
|
-
let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
43
|
-
const {
|
|
44
|
-
node: {
|
|
45
|
-
model: {
|
|
46
|
-
id,
|
|
47
|
-
isChecked,
|
|
48
|
-
children = []
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} = itemToSelect;
|
|
52
|
-
const newSelections = {}; // 'mixed' -> true -> false -> true [...->false -> true]
|
|
53
|
-
|
|
54
|
-
const nextState = isChecked === 'mixed' ? true : !isChecked;
|
|
55
|
-
itemToSelect.node.model.isChecked = nextState;
|
|
56
|
-
newSelections[id] = nextState;
|
|
57
|
-
|
|
58
|
-
if (children.length > 0 && (nextState === true || nextState === false)) {
|
|
59
|
-
walkAllNodeChildren(itemToSelect.node, childNode => {
|
|
60
|
-
childNode.model.isChecked = nextState;
|
|
61
|
-
newSelections[childNode.model.id] = nextState;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const parentsNewSelections = selectCheckboxItemModelParentsTillRoot(itemToSelect);
|
|
66
|
-
if (triggerTreeRerender) triggerTreeRerender();
|
|
67
|
-
return _objectSpread(_objectSpread({}, parentsNewSelections), newSelections);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export { getGroupCheckState, selectCheckboxItemModelParentsTillRoot, toggleCheckboxItem };
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
-
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
-
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
-
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
-
import 'core-js/modules/esnext.async-iterator.find.js';
|
|
6
|
-
import 'core-js/modules/esnext.iterator.find.js';
|
|
7
|
-
import 'core-js/modules/esnext.async-iterator.every.js';
|
|
8
|
-
import 'core-js/modules/esnext.iterator.every.js';
|
|
9
|
-
import { createRef } from 'react';
|
|
10
|
-
import { standardizeSearchQueryString } from './string-helpers.js';
|
|
11
|
-
|
|
12
|
-
const walkVisibles = function (node, callback) {
|
|
13
|
-
let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
14
|
-
let highlightOnlyQuery = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
15
|
-
const {
|
|
16
|
-
children,
|
|
17
|
-
model
|
|
18
|
-
} = node;
|
|
19
|
-
const {
|
|
20
|
-
name,
|
|
21
|
-
isExpanded,
|
|
22
|
-
childrenMatchesSearchQuery,
|
|
23
|
-
matchesSearchQuery
|
|
24
|
-
} = model;
|
|
25
|
-
const shouldSkipBecauseIsRoot = skipRoot && name === '__root';
|
|
26
|
-
const queryRestrictionsPassed = !!(highlightOnlyQuery || childrenMatchesSearchQuery || matchesSearchQuery);
|
|
27
|
-
if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed) callback(node);
|
|
28
|
-
const shouldWalkChildren = !!(children.length > 0 && isExpanded && queryRestrictionsPassed);
|
|
29
|
-
|
|
30
|
-
if (shouldWalkChildren) {
|
|
31
|
-
children.forEach(childNode => {
|
|
32
|
-
walkVisibles(childNode, callback, skipRoot, highlightOnlyQuery);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const walkParents = function (nodePath, callback) {
|
|
37
|
-
let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
38
|
-
const parents = [...nodePath].reverse();
|
|
39
|
-
parents.shift(); // remove current node from the parents array
|
|
40
|
-
|
|
41
|
-
if (skipRoot) parents.pop(); // remove the root from the parents if skipping root
|
|
42
|
-
|
|
43
|
-
parents.forEach(callback);
|
|
44
|
-
};
|
|
45
|
-
const walkAllNodeChildren = function (node, callback) {
|
|
46
|
-
let isFirst = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
47
|
-
const {
|
|
48
|
-
children = []
|
|
49
|
-
} = node;
|
|
50
|
-
const shouldWalkChildren = children.length;
|
|
51
|
-
if (!isFirst) callback(node);
|
|
52
|
-
|
|
53
|
-
if (shouldWalkChildren) {
|
|
54
|
-
children.forEach(childNode => {
|
|
55
|
-
walkAllNodeChildren(childNode, callback, false);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const getNodeById = (treeRoot, id) => {
|
|
60
|
-
const nodes = treeRoot.all(node => node.model.id === id);
|
|
61
|
-
return nodes[0];
|
|
62
|
-
};
|
|
63
|
-
const cloneNode = (tree, node) => tree.parse(node.model);
|
|
64
|
-
const itemsShareSameParent = function () {
|
|
65
|
-
let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
66
|
-
if (items.length === 0) throw new Error('Received empty items for comparison');
|
|
67
|
-
if (items.length === 1) return true; // when moving in first position we receive [undefined,...{items}]
|
|
68
|
-
// when moving in last position we receive [...{items}, undefined]
|
|
69
|
-
|
|
70
|
-
const firstExistingItem = items.find(item => !!item);
|
|
71
|
-
if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
|
|
72
|
-
const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
|
|
73
|
-
// length -1 is the current-node
|
|
74
|
-
// length -2 is the parent-node
|
|
75
|
-
// root node is not printed and is always present so minimum path length is 2 (root + currentNode)
|
|
76
|
-
|
|
77
|
-
const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
|
|
78
|
-
return items.every(item => {
|
|
79
|
-
// undefined nodes count as having the same parent
|
|
80
|
-
if (!item) return true;
|
|
81
|
-
const itemPath = item.node.getPath();
|
|
82
|
-
const itemDirectParent = itemPath[itemPath.length - 2];
|
|
83
|
-
return directParentNode === itemDirectParent;
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
const getItemsParentNode = function () {
|
|
87
|
-
let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
88
|
-
let skipSameParentCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
89
|
-
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
|
|
90
|
-
|
|
91
|
-
if (!skipSameParentCheck) if (!itemsShareSameParent(items)) // if we don't know (default, we don't) check if they share the parent
|
|
92
|
-
throw new Error("Received items don't share the same parent, can't retrieve parent"); // when moving in first position we receive [undefined,...{items}]
|
|
93
|
-
// when moving in last position we receive [...{items}, undefined]
|
|
94
|
-
|
|
95
|
-
const firstExistingItem = items.find(item => !!item);
|
|
96
|
-
if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
|
|
97
|
-
const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
|
|
98
|
-
// length -1 is the current-node
|
|
99
|
-
// length -2 is the parent-node
|
|
100
|
-
// root node is not printed and is always present so minimum path length is 2 (root + currentNode)
|
|
101
|
-
|
|
102
|
-
const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
|
|
103
|
-
return directParentNode;
|
|
104
|
-
};
|
|
105
|
-
const getNodeMatchesSearchQuery = function (node) {
|
|
106
|
-
let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
107
|
-
const standardizedName = standardizeSearchQueryString(node.model.name);
|
|
108
|
-
const standardizedSearchQuery = standardizeSearchQueryString(searchQuery);
|
|
109
|
-
return standardizedName.includes(standardizedSearchQuery);
|
|
110
|
-
};
|
|
111
|
-
const getChildrenMatchesSearchQuery = function (parentNode) {
|
|
112
|
-
let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
113
|
-
let anyChildMatch = false;
|
|
114
|
-
walkAllNodeChildren(parentNode, node => {
|
|
115
|
-
if (getNodeMatchesSearchQuery(node, searchQuery)) anyChildMatch = true;
|
|
116
|
-
});
|
|
117
|
-
return anyChildMatch;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Mutate in place a node from tree-model normalizing object properties like "isGroup" even if user didn't specify it explicitly,
|
|
121
|
-
* after execution the node will have "nodePath" "treeDepth" "nodeItemRef" "isGroup" "isExpanded"
|
|
122
|
-
* (optionally, based on the provided arguments) "matchesSearchQuery" "childrenMatchesSearchQuery" "isChecked"
|
|
123
|
-
*
|
|
124
|
-
* @param {Object} node - node (based on 'tree-model' lib) that you wish to mutate with extra props
|
|
125
|
-
* @param {string} [searchQuery=''] - optional string used to parse "matchesSearchQuery"/"childrenMatchesSearchQuery" properties
|
|
126
|
-
* @param {Object} [selection=null] - optional selection hashmap used to parse "isChecked" properties
|
|
127
|
-
* @param {Object} [expanded=null] - optional expanded hashmap used to parse "isExpanded" properties
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
const enrichNodeModelInPlace = function (node) {
|
|
131
|
-
var _node$model$children$, _node$model, _node$model$children;
|
|
132
|
-
|
|
133
|
-
let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
134
|
-
let selection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
135
|
-
let expanded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
136
|
-
const path = node.getPath();
|
|
137
|
-
const depth = path.length - 1;
|
|
138
|
-
node.model.nodePath = path;
|
|
139
|
-
node.model.treeDepth = depth;
|
|
140
|
-
|
|
141
|
-
if (!node.model.nodeItemRef) {
|
|
142
|
-
node.model.nodeItemRef = /*#__PURE__*/createRef();
|
|
143
|
-
} // if a node has children but was not marked as isGroup, force-mark as group
|
|
144
|
-
// this is useful to avoid having to always check both the flag and the children.length...
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
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) {
|
|
148
|
-
node.model.isGroup = true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (node.model.isGroup && node.model.id !== '__ds_tree_root') {
|
|
152
|
-
if (expanded) node.model.isExpanded = !!expanded[node.model.id];else if (typeof node.model.isExpanded !== 'boolean') {
|
|
153
|
-
node.model.isExpanded = false;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
node.model.matchesSearchQuery = true;
|
|
158
|
-
node.model.childrenMatchesSearchQuery = false;
|
|
159
|
-
const partiallyEnrichedNode = node;
|
|
160
|
-
|
|
161
|
-
if (searchQuery) {
|
|
162
|
-
partiallyEnrichedNode.model.matchesSearchQuery = getNodeMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
|
|
163
|
-
|
|
164
|
-
if (partiallyEnrichedNode.model.isGroup === true) {
|
|
165
|
-
partiallyEnrichedNode.model.childrenMatchesSearchQuery = getChildrenMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
|
|
166
|
-
if (partiallyEnrichedNode.model.childrenMatchesSearchQuery) partiallyEnrichedNode.model.isExpanded = true;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (selection && selection[partiallyEnrichedNode.model.id]) {
|
|
171
|
-
partiallyEnrichedNode.model.isChecked = selection[partiallyEnrichedNode.model.id];
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
const focusItem = item => {
|
|
175
|
-
var _item$nodeItemRef, _item$nodeItemRef$cur;
|
|
176
|
-
|
|
177
|
-
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();
|
|
178
|
-
};
|
|
179
|
-
const flattenTreeForDnD = function (data) {
|
|
180
|
-
let shouldDescend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => true;
|
|
181
|
-
const flattenedTree = [];
|
|
182
|
-
let index = 0;
|
|
183
|
-
|
|
184
|
-
const doit = function (node) {
|
|
185
|
-
var _node$children$length, _node$children, _node$children2;
|
|
186
|
-
|
|
187
|
-
let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
188
|
-
let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
189
|
-
flattenedTree.push({
|
|
190
|
-
uid: node.id.toString(),
|
|
191
|
-
depth,
|
|
192
|
-
realIndex: index,
|
|
193
|
-
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,
|
|
194
|
-
parentId: parentId !== null ? parentId.toString() : null,
|
|
195
|
-
original: node
|
|
196
|
-
});
|
|
197
|
-
index += 1;
|
|
198
|
-
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()));
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
data.forEach(datum => doit(datum));
|
|
202
|
-
return flattenedTree;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export { cloneNode, enrichNodeModelInPlace, flattenTreeForDnD, focusItem, getChildrenMatchesSearchQuery, getItemsParentNode, getNodeById, getNodeMatchesSearchQuery, itemsShareSameParent, walkAllNodeChildren, walkParents, walkVisibles };
|
package/esm/utils/useTree.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
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 { useMemo, useState, useEffect, useCallback } from 'react';
|
|
9
|
-
import TreeModel from 'tree-model';
|
|
10
|
-
import { cloneDeep } from 'lodash';
|
|
11
|
-
import { enrichNodeModelInPlace, walkVisibles, flattenTreeForDnD } from './tree-helpers.js';
|
|
12
|
-
import { updateExpandedState } from './group-expands-helpers.js';
|
|
13
|
-
|
|
14
|
-
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; }
|
|
15
|
-
|
|
16
|
-
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; }
|
|
17
|
-
const useTree = (data, props, states) => {
|
|
18
|
-
const {
|
|
19
|
-
setExpandedGroups
|
|
20
|
-
} = states;
|
|
21
|
-
const unfrozenData = useMemo(() => cloneDeep(data), [data]); // convert data into a TreeModel with extra isExpanded prop
|
|
22
|
-
// root element type is an exception, children model is based on what the dev passed on
|
|
23
|
-
// since root is an excepcion we must typecast
|
|
24
|
-
|
|
25
|
-
const tree = useMemo(() => new TreeModel(), []);
|
|
26
|
-
const [treeData, setTreeData] = useState({
|
|
27
|
-
id: '__ds_tree_root',
|
|
28
|
-
name: '__root',
|
|
29
|
-
isExpanded: true,
|
|
30
|
-
children: unfrozenData
|
|
31
|
-
});
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
setTreeData({
|
|
34
|
-
id: '__ds_tree_root',
|
|
35
|
-
name: '__root',
|
|
36
|
-
isExpanded: true,
|
|
37
|
-
children: unfrozenData
|
|
38
|
-
});
|
|
39
|
-
}, [unfrozenData]); // expose a way to rerender the tree
|
|
40
|
-
// used for expand functionality
|
|
41
|
-
|
|
42
|
-
const [rerenderItems, setRerenderItems] = useState({});
|
|
43
|
-
const triggerTreeRerender = useCallback(() => {
|
|
44
|
-
setRerenderItems({});
|
|
45
|
-
}, []); // when re-rendering we re-parse the list
|
|
46
|
-
|
|
47
|
-
const [treeRoot, setTreeRoot] = useState(tree.parse(treeData));
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
setTreeRoot(tree.parse(treeData));
|
|
50
|
-
}, [treeData, rerenderItems, tree]);
|
|
51
|
-
const [visibleItems, setVisibleItems] = useState([]);
|
|
52
|
-
const {
|
|
53
|
-
searchQuery,
|
|
54
|
-
highlightOnlyQuery,
|
|
55
|
-
onVisibleItemsChange,
|
|
56
|
-
selection,
|
|
57
|
-
expanded,
|
|
58
|
-
onExpandChange
|
|
59
|
-
} = props;
|
|
60
|
-
const updateUserExpandedState = useCallback(() => {
|
|
61
|
-
updateExpandedState(treeRoot, onExpandChange);
|
|
62
|
-
}, [treeRoot, onExpandChange]); // we add missing properties to the received Items
|
|
63
|
-
// not the best of the patterns, but it works
|
|
64
|
-
// this is where we convert "SimpleItems" to "Items"
|
|
65
|
-
// this was done to avoid breaking changes back in v1
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
const parsedVisibleItems = [];
|
|
69
|
-
const newExpandedHashMap = {};
|
|
70
|
-
const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
|
|
71
|
-
|
|
72
|
-
treeRoot.walk(node => {
|
|
73
|
-
enrichNodeModelInPlace(node, searchQuery, selection, expanded);
|
|
74
|
-
if (node.model.id && node.model.isGroup && node.model.isExpanded) newExpandedHashMap[node.model.id] = true;
|
|
75
|
-
return shouldContinueWalking;
|
|
76
|
-
});
|
|
77
|
-
walkVisibles(treeRoot, node => {
|
|
78
|
-
parsedVisibleItems.push(_objectSpread(_objectSpread({}, node.model), {}, {
|
|
79
|
-
node
|
|
80
|
-
}));
|
|
81
|
-
}, true, highlightOnlyQuery);
|
|
82
|
-
setVisibleItems(parsedVisibleItems);
|
|
83
|
-
onVisibleItemsChange(parsedVisibleItems);
|
|
84
|
-
setExpandedGroups(newExpandedHashMap); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
85
|
-
}, [treeRoot, rerenderItems, searchQuery, highlightOnlyQuery, selection, expanded, setExpandedGroups // onVisibleItemsChange // evaluate potential performance hit?
|
|
86
|
-
]);
|
|
87
|
-
const flattenedItems = useMemo(() => flattenTreeForDnD(data), [data]);
|
|
88
|
-
return {
|
|
89
|
-
visibleItems,
|
|
90
|
-
flattenedItems,
|
|
91
|
-
tree,
|
|
92
|
-
treeRoot,
|
|
93
|
-
rerenderItems,
|
|
94
|
-
triggerTreeRerender,
|
|
95
|
-
updateUserExpandedState
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export { useTree };
|
package/types/TreeView.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import type { DSTreeviewT } from './react-desc-prop-types';
|
|
4
|
-
export declare function TreeView(props: DSTreeviewT.Props): JSX.Element;
|
|
5
|
-
export declare namespace TreeView {
|
|
6
|
-
var propTypes: React.WeakValidationMap<unknown>;
|
|
7
|
-
}
|
|
8
|
-
declare const TreeViewWithSchema: {
|
|
9
|
-
(props?: unknown): JSX.Element;
|
|
10
|
-
propTypes: unknown;
|
|
11
|
-
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
12
|
-
};
|
|
13
|
-
export { TreeViewWithSchema };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { DSTreeviewT } from './react-desc-prop-types';
|
|
3
|
-
import type { DSTreeviewInternalsT } from './sharedTypes';
|
|
4
|
-
export declare const defaultProps: DSTreeviewT.Props;
|
|
5
|
-
export declare const defaultRelativeMouseCoord: {
|
|
6
|
-
isBefore: boolean;
|
|
7
|
-
isAfter: boolean;
|
|
8
|
-
isValid: boolean;
|
|
9
|
-
item: null;
|
|
10
|
-
x: null;
|
|
11
|
-
y: null;
|
|
12
|
-
relativeElementDOMRect: null;
|
|
13
|
-
relativeElementIndex: null;
|
|
14
|
-
};
|
|
15
|
-
/** Context for cross component communication */
|
|
16
|
-
declare const TreeViewContext: import("react").Context<DSTreeviewInternalsT.CTX>;
|
|
17
|
-
export default TreeViewContext;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { DSTreeviewT } from '../react-desc-prop-types';
|
|
2
|
-
import type { DSTreeviewInternalsT } from '../sharedTypes';
|
|
3
|
-
declare type UseTreeviewT = (props: DSTreeviewT.Props) => {
|
|
4
|
-
ctx: DSTreeviewInternalsT.CTX;
|
|
5
|
-
};
|
|
6
|
-
export declare const useTreeview: UseTreeviewT;
|
|
7
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { DSTreeviewT } from '../react-desc-prop-types';
|
|
3
|
-
import { DropIndicatorPosition } from './SortableItemContext';
|
|
4
|
-
declare type DnDTreeContextType = {
|
|
5
|
-
depth: number | undefined;
|
|
6
|
-
activeIndex: number | undefined;
|
|
7
|
-
visibleItems: DSTreeviewT.Item[] | undefined;
|
|
8
|
-
dropIndicatorPosition: DropIndicatorPosition;
|
|
9
|
-
lastActiveId: string | undefined;
|
|
10
|
-
setLastActiveId: React.Dispatch<React.SetStateAction<string>> | undefined;
|
|
11
|
-
isDropValid: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare const DnDTreeContext: import("react").Context<DnDTreeContextType>;
|
|
14
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { useSortable } from '@dnd-kit/sortable';
|
|
3
|
-
export declare enum DropIndicatorPosition {
|
|
4
|
-
None = 0,
|
|
5
|
-
Before = 1,
|
|
6
|
-
After = 2,
|
|
7
|
-
Inside = 3
|
|
8
|
-
}
|
|
9
|
-
export declare type SortableItemContextType = {
|
|
10
|
-
draggableProps: false | (ReturnType<typeof useSortable> & {
|
|
11
|
-
dropIndicatorPosition: DropIndicatorPosition;
|
|
12
|
-
shouldShowDropIndicatorPosition: boolean;
|
|
13
|
-
lastActiveId?: string;
|
|
14
|
-
setLastActiveId?: React.Dispatch<React.SetStateAction<string>>;
|
|
15
|
-
isDropValid: boolean;
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
/** Context for cross component communication */
|
|
19
|
-
export declare const SortableItemContext: import("react").Context<SortableItemContextType>;
|
package/types/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { DSTreeviewT } from '../react-desc-prop-types';
|
|
3
|
-
interface PropsT {
|
|
4
|
-
item: DSTreeviewT.Item;
|
|
5
|
-
itemIndex: number;
|
|
6
|
-
}
|
|
7
|
-
declare function CheckboxSelectable(props: PropsT): JSX.Element | null;
|
|
8
|
-
export default CheckboxSelectable;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DropIndicatorPosition } from '../hoc/SortableItemContext';
|
|
3
|
-
interface DropIndicatorProps {
|
|
4
|
-
vertical?: boolean;
|
|
5
|
-
dropIndicatorPosition: DropIndicatorPosition | false;
|
|
6
|
-
isLast?: boolean;
|
|
7
|
-
isDropValid?: boolean;
|
|
8
|
-
}
|
|
9
|
-
declare const DropIndicator: React.ComponentType<DropIndicatorProps>;
|
|
10
|
-
export default DropIndicator;
|
package/types/parts/Icon.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { DSTreeviewT } from '../react-desc-prop-types';
|
|
3
|
-
declare type NestingSpacePropsType = {
|
|
4
|
-
item: DSTreeviewT.Item;
|
|
5
|
-
spaceForNestingLevel: number;
|
|
6
|
-
};
|
|
7
|
-
export declare const NestingSpace: (props: NestingSpacePropsType) => JSX.Element | null;
|
|
8
|
-
export {};
|