@elliemae/ds-treeview 2.2.0 → 2.3.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/cjs/TreeView.js +47 -31
- package/cjs/TreeView.js.map +7 -0
- package/cjs/TreeViewContext.js +55 -43
- package/cjs/TreeViewContext.js.map +7 -0
- package/cjs/config/cssClassesConstants.js +41 -13
- package/cjs/config/cssClassesConstants.js.map +7 -0
- package/cjs/config/useTreeview.js +102 -88
- package/cjs/config/useTreeview.js.map +7 -0
- package/cjs/hoc/DnDTreeContext.js +45 -0
- package/cjs/hoc/DnDTreeContext.js.map +7 -0
- package/cjs/hoc/SortableItemContext.js +46 -0
- package/cjs/hoc/SortableItemContext.js.map +7 -0
- package/cjs/hoc/WithConditionalDnDContext.js +128 -0
- package/cjs/hoc/WithConditionalDnDContext.js.map +7 -0
- package/cjs/hoc/WithDnDSortableItemContext.js +69 -0
- package/cjs/hoc/WithDnDSortableItemContext.js.map +7 -0
- package/cjs/index.js +37 -27
- package/cjs/index.js.map +7 -0
- package/cjs/parts/CheckboxSelectable.js +70 -59
- package/cjs/parts/CheckboxSelectable.js.map +7 -0
- package/cjs/parts/ChildrenCountDisplayer.js +45 -28
- package/cjs/parts/ChildrenCountDisplayer.js.map +7 -0
- package/cjs/parts/DnDHandle.js +57 -0
- package/cjs/parts/DnDHandle.js.map +7 -0
- package/cjs/parts/DropIndicator.js +80 -0
- package/cjs/parts/DropIndicator.js.map +7 -0
- package/cjs/parts/ExpandCaret.js +85 -83
- package/cjs/parts/ExpandCaret.js.map +7 -0
- package/cjs/parts/Icon.js +46 -31
- package/cjs/parts/Icon.js.map +7 -0
- package/cjs/parts/NestingSpace.js +43 -35
- package/cjs/parts/NestingSpace.js.map +7 -0
- package/cjs/parts/RadioSelectable.js +52 -37
- package/cjs/parts/RadioSelectable.js.map +7 -0
- package/cjs/parts/TreeItem.js +121 -165
- package/cjs/parts/TreeItem.js.map +7 -0
- package/cjs/parts/TreeItemText.js +88 -95
- package/cjs/parts/TreeItemText.js.map +7 -0
- package/cjs/parts/TreeList.js +114 -132
- package/cjs/parts/TreeList.js.map +7 -0
- package/cjs/plugins/dnd/TreeDndPlugin.js +34 -43
- package/cjs/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/cjs/plugins/dnd/index.js +28 -10
- package/cjs/plugins/dnd/index.js.map +7 -0
- package/cjs/plugins/index.js +34 -22
- package/cjs/plugins/index.js.map +7 -0
- package/cjs/plugins/roving/TreeRovingPlugin.js +35 -7
- package/cjs/plugins/roving/TreeRovingPlugin.js.map +7 -0
- package/cjs/plugins/roving/index.js +28 -9
- package/cjs/plugins/roving/index.js.map +7 -0
- package/cjs/plugins/searchable/SearchableTreePlugin.js +35 -7
- package/cjs/plugins/searchable/SearchableTreePlugin.js.map +7 -0
- package/cjs/plugins/searchable/index.js +28 -9
- package/cjs/plugins/searchable/index.js.map +7 -0
- package/cjs/plugins/selectable/SelectablePluginTree.js +35 -7
- package/cjs/plugins/selectable/SelectablePluginTree.js.map +7 -0
- package/cjs/plugins/selectable/index.js +28 -9
- package/cjs/plugins/selectable/index.js.map +7 -0
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js +35 -7
- package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
- package/cjs/plugins/toolbar/index.js +28 -9
- package/cjs/plugins/toolbar/index.js.map +7 -0
- package/cjs/plugins/tree/TreeDataPlugin.js +35 -7
- package/cjs/plugins/tree/TreeDataPlugin.js.map +7 -0
- package/cjs/plugins/tree/index.js +28 -9
- package/cjs/plugins/tree/index.js.map +7 -0
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +35 -7
- package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
- package/cjs/plugins/virtualization/index.js +28 -9
- package/cjs/plugins/virtualization/index.js.map +7 -0
- package/cjs/react-desc-prop-types.js +83 -53
- package/cjs/react-desc-prop-types.js.map +7 -0
- package/cjs/related-components/TreeViewSearchBar.js +42 -40
- package/cjs/related-components/TreeViewSearchBar.js.map +7 -0
- package/cjs/sharedTypes.js +27 -2
- package/cjs/sharedTypes.js.map +7 -0
- package/cjs/utils/array-helpers.js +35 -11
- package/cjs/utils/array-helpers.js.map +7 -0
- package/cjs/utils/group-expands-helpers.js +86 -59
- package/cjs/utils/group-expands-helpers.js.map +7 -0
- package/cjs/utils/keyboard-helpers.js +86 -90
- package/cjs/utils/keyboard-helpers.js.map +7 -0
- package/cjs/utils/object-helpers.js +43 -36
- package/cjs/utils/object-helpers.js.map +7 -0
- package/cjs/utils/refs-helpers.js +43 -22
- package/cjs/utils/refs-helpers.js.map +7 -0
- package/cjs/utils/selectable-helper.js +61 -53
- package/cjs/utils/selectable-helper.js.map +7 -0
- package/cjs/utils/string-helpers.js +35 -7
- package/cjs/utils/string-helpers.js.map +7 -0
- package/cjs/utils/tree-helpers.js +125 -135
- package/cjs/utils/tree-helpers.js.map +7 -0
- package/cjs/utils/useInstanceRefActions.js +54 -43
- package/cjs/utils/useInstanceRefActions.js.map +7 -0
- package/cjs/utils/useTree.js +78 -78
- package/cjs/utils/useTree.js.map +7 -0
- package/esm/TreeView.js +16 -20
- package/esm/TreeView.js.map +7 -0
- package/esm/TreeViewContext.js +26 -37
- package/esm/TreeViewContext.js.map +7 -0
- package/esm/config/cssClassesConstants.js +12 -6
- package/esm/config/cssClassesConstants.js.map +7 -0
- package/esm/config/useTreeview.js +59 -66
- package/esm/config/useTreeview.js.map +7 -0
- package/esm/hoc/DnDTreeContext.js +16 -0
- package/esm/hoc/DnDTreeContext.js.map +7 -0
- package/esm/hoc/SortableItemContext.js +17 -0
- package/esm/hoc/SortableItemContext.js.map +7 -0
- package/esm/hoc/WithConditionalDnDContext.js +99 -0
- package/esm/hoc/WithConditionalDnDContext.js.map +7 -0
- package/esm/hoc/WithDnDSortableItemContext.js +40 -0
- package/esm/hoc/WithDnDSortableItemContext.js.map +7 -0
- package/esm/index.js +8 -9
- package/esm/index.js.map +7 -0
- package/esm/parts/CheckboxSelectable.js +36 -46
- package/esm/parts/CheckboxSelectable.js.map +7 -0
- package/esm/parts/ChildrenCountDisplayer.js +16 -20
- package/esm/parts/ChildrenCountDisplayer.js.map +7 -0
- package/esm/parts/DnDHandle.js +28 -0
- package/esm/parts/DnDHandle.js.map +7 -0
- package/esm/parts/DropIndicator.js +51 -0
- package/esm/parts/DropIndicator.js.map +7 -0
- package/esm/parts/ExpandCaret.js +54 -72
- package/esm/parts/ExpandCaret.js.map +7 -0
- package/esm/parts/Icon.js +16 -22
- package/esm/parts/Icon.js.map +7 -0
- package/esm/parts/NestingSpace.js +14 -27
- package/esm/parts/NestingSpace.js.map +7 -0
- package/esm/parts/RadioSelectable.js +20 -28
- package/esm/parts/RadioSelectable.js.map +7 -0
- package/esm/parts/TreeItem.js +89 -150
- package/esm/parts/TreeItem.js.map +7 -0
- package/esm/parts/TreeItemText.js +58 -85
- package/esm/parts/TreeItemText.js.map +7 -0
- package/esm/parts/TreeList.js +86 -120
- package/esm/parts/TreeList.js.map +7 -0
- package/esm/plugins/dnd/TreeDndPlugin.js +5 -34
- package/esm/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/esm/plugins/dnd/index.js +3 -1
- package/esm/plugins/dnd/index.js.map +7 -0
- package/esm/plugins/index.js +9 -7
- package/esm/plugins/index.js.map +7 -0
- package/esm/plugins/roving/TreeRovingPlugin.js +6 -3
- package/esm/plugins/roving/TreeRovingPlugin.js.map +7 -0
- package/esm/plugins/roving/index.js +3 -1
- package/esm/plugins/roving/index.js.map +7 -0
- package/esm/plugins/searchable/SearchableTreePlugin.js +6 -3
- package/esm/plugins/searchable/SearchableTreePlugin.js.map +7 -0
- package/esm/plugins/searchable/index.js +3 -1
- package/esm/plugins/searchable/index.js.map +7 -0
- package/esm/plugins/selectable/SelectablePluginTree.js +6 -3
- package/esm/plugins/selectable/SelectablePluginTree.js.map +7 -0
- package/esm/plugins/selectable/index.js +3 -1
- package/esm/plugins/selectable/index.js.map +7 -0
- package/esm/plugins/toolbar/TreeToolbarPlugin.js +6 -3
- package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
- package/esm/plugins/toolbar/index.js +3 -1
- package/esm/plugins/toolbar/index.js.map +7 -0
- package/esm/plugins/tree/TreeDataPlugin.js +6 -3
- package/esm/plugins/tree/TreeDataPlugin.js.map +7 -0
- package/esm/plugins/tree/index.js +3 -1
- package/esm/plugins/tree/index.js.map +7 -0
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +6 -3
- package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
- package/esm/plugins/virtualization/index.js +3 -1
- package/esm/plugins/virtualization/index.js.map +7 -0
- package/esm/react-desc-prop-types.js +48 -43
- package/esm/react-desc-prop-types.js.map +7 -0
- package/esm/related-components/TreeViewSearchBar.js +13 -32
- package/esm/related-components/TreeViewSearchBar.js.map +7 -0
- package/esm/sharedTypes.js +2 -1
- package/esm/sharedTypes.js.map +7 -0
- package/esm/utils/array-helpers.js +6 -6
- package/esm/utils/array-helpers.js.map +7 -0
- package/esm/utils/group-expands-helpers.js +56 -46
- package/esm/utils/group-expands-helpers.js.map +7 -0
- package/esm/utils/keyboard-helpers.js +47 -74
- package/esm/utils/keyboard-helpers.js.map +7 -0
- package/esm/utils/object-helpers.js +14 -31
- package/esm/utils/object-helpers.js.map +7 -0
- package/esm/utils/refs-helpers.js +15 -19
- package/esm/utils/refs-helpers.js.map +7 -0
- package/esm/utils/selectable-helper.js +32 -43
- package/esm/utils/selectable-helper.js.map +7 -0
- package/esm/utils/string-helpers.js +6 -3
- package/esm/utils/string-helpers.js.map +7 -0
- package/esm/utils/tree-helpers.js +94 -119
- package/esm/utils/tree-helpers.js.map +7 -0
- package/esm/utils/useInstanceRefActions.js +21 -35
- package/esm/utils/useInstanceRefActions.js.map +7 -0
- package/esm/utils/useTree.js +37 -57
- package/esm/utils/useTree.js.map +7 -0
- package/package.json +34 -18
- 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/utils/dnd-helpers.js +0 -140
- package/cjs/utils/useDnDHelpers.js +0 -220
- package/esm/utils/dnd-helpers.js +0 -132
- package/esm/utils/useDnDHelpers.js +0 -216
- package/types/utils/dnd-helpers.d.ts +0 -39
- package/types/utils/useDnDHelpers.d.ts +0 -26
|
@@ -1,111 +1,138 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
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 group_expands_helpers_exports = {};
|
|
29
|
+
__export(group_expands_helpers_exports, {
|
|
30
|
+
collapseAll: () => collapseAll,
|
|
31
|
+
collapseItemModel: () => collapseItemModel,
|
|
32
|
+
expandAll: () => expandAll,
|
|
33
|
+
expandItemModel: () => expandItemModel,
|
|
34
|
+
getToggleExpandShouldExpand: () => getToggleExpandShouldExpand,
|
|
35
|
+
toggleExpandAllHelper: () => toggleExpandAllHelper,
|
|
36
|
+
toggleItemExpand: () => toggleItemExpand,
|
|
37
|
+
updateExpandedState: () => updateExpandedState,
|
|
38
|
+
useNotifyExpandedChange: () => useNotifyExpandedChange
|
|
39
|
+
});
|
|
40
|
+
var React = __toESM(require("react"));
|
|
41
|
+
var import_react = require("react");
|
|
8
42
|
const updateExpandedState = (treeRoot, onExpandChange) => {
|
|
9
43
|
const shouldContinueWalking = true;
|
|
10
|
-
const newExpandedHashMap = {
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
treeRoot.walk(node => {
|
|
44
|
+
const newExpandedHashMap = { __ds_tree_root: true };
|
|
45
|
+
treeRoot.walk((node) => {
|
|
14
46
|
if (!node.isRoot() && node.model.isGroup && node.model.isExpanded) {
|
|
15
47
|
newExpandedHashMap[node.model.id] = true;
|
|
16
48
|
}
|
|
17
|
-
|
|
18
49
|
return shouldContinueWalking;
|
|
19
50
|
});
|
|
20
|
-
if (onExpandChange)
|
|
51
|
+
if (onExpandChange)
|
|
52
|
+
onExpandChange(newExpandedHashMap, null);
|
|
21
53
|
};
|
|
22
|
-
const toggleItemExpand =
|
|
23
|
-
|
|
54
|
+
const toggleItemExpand = (itemToToggle, triggerTreeRerender, updateUserExpandedState, scrollTo = () => {
|
|
55
|
+
}) => {
|
|
24
56
|
const {
|
|
25
57
|
node: {
|
|
26
|
-
model: {
|
|
27
|
-
isExpanded
|
|
28
|
-
}
|
|
58
|
+
model: { isExpanded }
|
|
29
59
|
},
|
|
30
60
|
virtualIndex
|
|
31
61
|
} = itemToToggle;
|
|
32
|
-
|
|
33
62
|
if (itemToToggle.node.model.isGroup) {
|
|
34
63
|
itemToToggle.node.model.isExpanded = !isExpanded;
|
|
35
64
|
triggerTreeRerender();
|
|
36
65
|
updateUserExpandedState();
|
|
37
66
|
setTimeout(() => {
|
|
38
|
-
if (typeof virtualIndex ===
|
|
39
|
-
align:
|
|
40
|
-
});
|
|
67
|
+
if (typeof virtualIndex === "number")
|
|
68
|
+
scrollTo(virtualIndex, { align: "start" });
|
|
41
69
|
});
|
|
42
70
|
}
|
|
43
71
|
};
|
|
44
|
-
const expandItemModel = modelToExpand => {
|
|
45
|
-
if (modelToExpand.isGroup)
|
|
72
|
+
const expandItemModel = (modelToExpand) => {
|
|
73
|
+
if (modelToExpand.isGroup)
|
|
74
|
+
modelToExpand.isExpanded = true;
|
|
46
75
|
};
|
|
47
|
-
const collapseItemModel = modelToCollapse => {
|
|
48
|
-
if (modelToCollapse.isGroup)
|
|
76
|
+
const collapseItemModel = (modelToCollapse) => {
|
|
77
|
+
if (modelToCollapse.isGroup)
|
|
78
|
+
modelToCollapse.isExpanded = false;
|
|
49
79
|
};
|
|
50
80
|
const expandAll = (treeRoot, triggerTreeRerender) => {
|
|
51
81
|
const shouldContinueWalking = true;
|
|
52
|
-
treeRoot.walk(node => {
|
|
53
|
-
if (!node.isRoot())
|
|
82
|
+
treeRoot.walk((node) => {
|
|
83
|
+
if (!node.isRoot())
|
|
84
|
+
expandItemModel(node.model);
|
|
54
85
|
return shouldContinueWalking;
|
|
55
86
|
});
|
|
56
87
|
triggerTreeRerender();
|
|
57
88
|
};
|
|
58
89
|
const collapseAll = (treeRoot, triggerTreeRerender) => {
|
|
59
|
-
const shouldContinueWalking = true;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
const shouldContinueWalking = true;
|
|
91
|
+
treeRoot.walk((node) => {
|
|
92
|
+
if (!node.isRoot())
|
|
93
|
+
collapseItemModel(node.model);
|
|
63
94
|
return shouldContinueWalking;
|
|
64
95
|
});
|
|
65
96
|
triggerTreeRerender();
|
|
66
97
|
};
|
|
67
|
-
const getToggleExpandShouldExpand = treeRoot => {
|
|
98
|
+
const getToggleExpandShouldExpand = (treeRoot) => {
|
|
68
99
|
let shouldExpand = false;
|
|
69
|
-
const shouldContinueWalking = true;
|
|
70
|
-
|
|
71
|
-
treeRoot.walk(node => {
|
|
100
|
+
const shouldContinueWalking = true;
|
|
101
|
+
treeRoot.walk((node) => {
|
|
72
102
|
if (!node.isRoot()) {
|
|
73
103
|
if (!node.model.isExpanded && node.model.isGroup) {
|
|
74
|
-
shouldExpand = true;
|
|
75
|
-
|
|
104
|
+
shouldExpand = true;
|
|
76
105
|
return shouldContinueWalking;
|
|
77
106
|
}
|
|
78
107
|
}
|
|
79
|
-
|
|
80
108
|
return shouldContinueWalking;
|
|
81
109
|
});
|
|
82
110
|
return shouldExpand;
|
|
83
111
|
};
|
|
84
112
|
const toggleExpandAllHelper = (isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
|
|
85
|
-
if (isExpand === true)
|
|
113
|
+
if (isExpand === true)
|
|
114
|
+
expandAll(treeRoot, triggerTreeRerender);
|
|
115
|
+
else if (isExpand === false)
|
|
116
|
+
collapseAll(treeRoot, triggerTreeRerender);
|
|
117
|
+
else {
|
|
86
118
|
const shouldExpand = getToggleExpandShouldExpand(treeRoot);
|
|
87
|
-
if (shouldExpand === true)
|
|
119
|
+
if (shouldExpand === true)
|
|
120
|
+
expandAll(treeRoot, triggerTreeRerender);
|
|
121
|
+
else
|
|
122
|
+
collapseAll(treeRoot, triggerTreeRerender);
|
|
88
123
|
}
|
|
89
124
|
setLatestToggledItem(null);
|
|
90
125
|
updateUserExpandedState();
|
|
91
126
|
};
|
|
92
|
-
const useNotifyExpandedChange = (propsWithDefaults,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
127
|
+
const useNotifyExpandedChange = (propsWithDefaults, {
|
|
128
|
+
latestToggledItem,
|
|
129
|
+
expandedGroups
|
|
130
|
+
}) => {
|
|
131
|
+
const notifyExpandedChange = (0, import_react.useCallback)((expandedGroupHashmap) => propsWithDefaults?.onExpandChange(expandedGroupHashmap || {}, latestToggledItem), [propsWithDefaults, latestToggledItem]);
|
|
132
|
+
(0, import_react.useEffect)(() => {
|
|
133
|
+
if (!propsWithDefaults.expanded)
|
|
134
|
+
notifyExpandedChange(expandedGroups);
|
|
100
135
|
}, [expandedGroups, notifyExpandedChange, propsWithDefaults.expanded]);
|
|
101
136
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
exports.collapseItemModel = collapseItemModel;
|
|
105
|
-
exports.expandAll = expandAll;
|
|
106
|
-
exports.expandItemModel = expandItemModel;
|
|
107
|
-
exports.getToggleExpandShouldExpand = getToggleExpandShouldExpand;
|
|
108
|
-
exports.toggleExpandAllHelper = toggleExpandAllHelper;
|
|
109
|
-
exports.toggleItemExpand = toggleItemExpand;
|
|
110
|
-
exports.updateExpandedState = updateExpandedState;
|
|
111
|
-
exports.useNotifyExpandedChange = useNotifyExpandedChange;
|
|
137
|
+
module.exports = __toCommonJS(group_expands_helpers_exports);
|
|
138
|
+
//# sourceMappingURL=group-expands-helpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/group-expands-helpers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-params */\nimport { useCallback, useEffect } from 'react';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\n\nexport const updateExpandedState = (\n treeRoot: DSTreeviewT.Item['node'],\n onExpandChange: DSTreeviewT.Props['onExpandChange'] | null | undefined,\n) => {\n const shouldContinueWalking = true;\n const newExpandedHashMap: DSTreeviewT.ExpandedItems = { __ds_tree_root: true };\n treeRoot.walk((node) => {\n if (!node.isRoot() && node.model.isGroup && node.model.isExpanded) {\n newExpandedHashMap[node.model.id] = true;\n }\n return shouldContinueWalking;\n });\n if (onExpandChange) onExpandChange(newExpandedHashMap, null);\n};\n\nexport const toggleItemExpand = (\n itemToToggle: DSTreeviewT.Item,\n triggerTreeRerender: () => void,\n updateUserExpandedState: DSTreeviewInternalsT.CTX['updateUserExpandedState'],\n scrollTo: DSTreeviewT.ScrollToFunc = () => {},\n) => {\n const {\n node: {\n model: { isExpanded },\n },\n virtualIndex,\n } = itemToToggle;\n if (itemToToggle.node.model.isGroup) {\n itemToToggle.node.model.isExpanded = !isExpanded;\n triggerTreeRerender();\n updateUserExpandedState();\n setTimeout(() => {\n if (typeof virtualIndex === 'number') scrollTo(virtualIndex, { align: 'start' });\n });\n }\n};\n\nexport const expandItemModel = (modelToExpand: DSTreeviewT.Item['model']) => {\n if (modelToExpand.isGroup) modelToExpand.isExpanded = true;\n};\n\nexport const collapseItemModel = (modelToCollapse: DSTreeviewT.Item['model']) => {\n if (modelToCollapse.isGroup) modelToCollapse.isExpanded = false;\n};\n\nexport const expandAll = (treeRoot: DSTreeviewT.Item['node'], triggerTreeRerender: () => void) => {\n const shouldContinueWalking = true;\n treeRoot.walk((node) => {\n if (!node.isRoot()) expandItemModel(node.model);\n return shouldContinueWalking;\n });\n triggerTreeRerender();\n};\n\nexport const collapseAll = (treeRoot: DSTreeviewT.Item['node'], triggerTreeRerender: () => void) => {\n const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking\n treeRoot.walk((node) => {\n if (!node.isRoot()) collapseItemModel(node.model);\n return shouldContinueWalking;\n });\n triggerTreeRerender();\n};\n\nexport const getToggleExpandShouldExpand = (treeRoot: DSTreeviewT.Item['node']) => {\n let shouldExpand = false;\n const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking\n treeRoot.walk((node) => {\n if (!node.isRoot()) {\n if (!node.model.isExpanded && node.model.isGroup) {\n shouldExpand = true;\n // eslint-disable-next-line no-useless-return\n return shouldContinueWalking;\n }\n }\n return shouldContinueWalking;\n });\n return shouldExpand;\n};\n\nexport const toggleExpandAllHelper = (\n isExpand: boolean | 'toggle',\n treeRoot: DSTreeviewT.Item['node'],\n triggerTreeRerender: () => void,\n setLatestToggledItem: DSTreeviewInternalsT.CTX['setLatestToggledItem'],\n updateUserExpandedState: DSTreeviewInternalsT.CTX['updateUserExpandedState'],\n) => {\n if (isExpand === true) expandAll(treeRoot, triggerTreeRerender);\n else if (isExpand === false) collapseAll(treeRoot, triggerTreeRerender);\n else {\n const shouldExpand = getToggleExpandShouldExpand(treeRoot);\n if (shouldExpand === true) expandAll(treeRoot, triggerTreeRerender);\n else collapseAll(treeRoot, triggerTreeRerender);\n }\n setLatestToggledItem(null);\n updateUserExpandedState();\n};\n\nexport const useNotifyExpandedChange = (\n propsWithDefaults: DSTreeviewT.Props,\n {\n latestToggledItem,\n expandedGroups,\n }: {\n latestToggledItem?: DSTreeviewInternalsT.CTX['latestToggledItem'];\n expandedGroups?: DSTreeviewInternalsT.CTX['expandedGroups'];\n },\n) => {\n const notifyExpandedChange = useCallback(\n (expandedGroupHashmap?: DSTreeviewInternalsT.CTX['expandedGroups']) =>\n propsWithDefaults?.onExpandChange(expandedGroupHashmap || {}, latestToggledItem),\n [propsWithDefaults, latestToggledItem],\n );\n\n useEffect(() => {\n if (!propsWithDefaults.expanded) notifyExpandedChange(expandedGroups);\n }, [expandedGroups, notifyExpandedChange, propsWithDefaults.expanded]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,mBAAuC;AAIhC,MAAM,sBAAsB,CACjC,UACA,mBACG;AACH,QAAM,wBAAwB;AAC9B,QAAM,qBAAgD,EAAE,gBAAgB;AACxE,WAAS,KAAK,CAAC,SAAS;AACtB,QAAI,CAAC,KAAK,YAAY,KAAK,MAAM,WAAW,KAAK,MAAM,YAAY;AACjE,yBAAmB,KAAK,MAAM,MAAM;AAAA;AAEtC,WAAO;AAAA;AAET,MAAI;AAAgB,mBAAe,oBAAoB;AAAA;AAGlD,MAAM,mBAAmB,CAC9B,cACA,qBACA,yBACA,WAAqC,MAAM;AAAA,MACxC;AACH,QAAM;AAAA,IACJ,MAAM;AAAA,MACJ,OAAO,EAAE;AAAA;AAAA,IAEX;AAAA,MACE;AACJ,MAAI,aAAa,KAAK,MAAM,SAAS;AACnC,iBAAa,KAAK,MAAM,aAAa,CAAC;AACtC;AACA;AACA,eAAW,MAAM;AACf,UAAI,OAAO,iBAAiB;AAAU,iBAAS,cAAc,EAAE,OAAO;AAAA;AAAA;AAAA;AAKrE,MAAM,kBAAkB,CAAC,kBAA6C;AAC3E,MAAI,cAAc;AAAS,kBAAc,aAAa;AAAA;AAGjD,MAAM,oBAAoB,CAAC,oBAA+C;AAC/E,MAAI,gBAAgB;AAAS,oBAAgB,aAAa;AAAA;AAGrD,MAAM,YAAY,CAAC,UAAoC,wBAAoC;AAChG,QAAM,wBAAwB;AAC9B,WAAS,KAAK,CAAC,SAAS;AACtB,QAAI,CAAC,KAAK;AAAU,sBAAgB,KAAK;AACzC,WAAO;AAAA;AAET;AAAA;AAGK,MAAM,cAAc,CAAC,UAAoC,wBAAoC;AAClG,QAAM,wBAAwB;AAC9B,WAAS,KAAK,CAAC,SAAS;AACtB,QAAI,CAAC,KAAK;AAAU,wBAAkB,KAAK;AAC3C,WAAO;AAAA;AAET;AAAA;AAGK,MAAM,8BAA8B,CAAC,aAAuC;AACjF,MAAI,eAAe;AACnB,QAAM,wBAAwB;AAC9B,WAAS,KAAK,CAAC,SAAS;AACtB,QAAI,CAAC,KAAK,UAAU;AAClB,UAAI,CAAC,KAAK,MAAM,cAAc,KAAK,MAAM,SAAS;AAChD,uBAAe;AAEf,eAAO;AAAA;AAAA;AAGX,WAAO;AAAA;AAET,SAAO;AAAA;AAGF,MAAM,wBAAwB,CACnC,UACA,UACA,qBACA,sBACA,4BACG;AACH,MAAI,aAAa;AAAM,cAAU,UAAU;AAAA,WAClC,aAAa;AAAO,gBAAY,UAAU;AAAA,OAC9C;AACH,UAAM,eAAe,4BAA4B;AACjD,QAAI,iBAAiB;AAAM,gBAAU,UAAU;AAAA;AAC1C,kBAAY,UAAU;AAAA;AAE7B,uBAAqB;AACrB;AAAA;AAGK,MAAM,0BAA0B,CACrC,mBACA;AAAA,EACE;AAAA,EACA;AAAA,MAKC;AACH,QAAM,uBAAuB,8BAC3B,CAAC,yBACC,mBAAmB,eAAe,wBAAwB,IAAI,oBAChE,CAAC,mBAAmB;AAGtB,8BAAU,MAAM;AACd,QAAI,CAAC,kBAAkB;AAAU,2BAAqB;AAAA,KACrD,CAAC,gBAAgB,sBAAsB,kBAAkB;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,126 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
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 keyboard_helpers_exports = {};
|
|
29
|
+
__export(keyboard_helpers_exports, {
|
|
30
|
+
useGlobalKeyboardListener: () => useGlobalKeyboardListener,
|
|
31
|
+
useGlobalToggleAllExpandShortcut: () => useGlobalToggleAllExpandShortcut,
|
|
32
|
+
useOnItemKeyDown: () => useOnItemKeyDown
|
|
33
|
+
});
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_TreeViewContext = __toESM(require("../TreeViewContext"));
|
|
37
|
+
var import_tree_helpers = require("./tree-helpers");
|
|
38
|
+
var import_group_expands_helpers = require("./group-expands-helpers");
|
|
39
|
+
const useOnItemKeyDown = (item, draggableProps) => {
|
|
40
|
+
const ctx = (0, import_react.useContext)(import_TreeViewContext.default);
|
|
24
41
|
const {
|
|
25
|
-
props: {
|
|
26
|
-
onItemFocus
|
|
27
|
-
},
|
|
42
|
+
props: { onItemFocus },
|
|
28
43
|
triggerTreeRerender,
|
|
29
|
-
isDragging,
|
|
30
44
|
visibleItems,
|
|
31
45
|
setFocusedItem,
|
|
32
46
|
setSelectedItem,
|
|
33
47
|
setLatestToggledItem,
|
|
34
48
|
updateUserExpandedState,
|
|
35
|
-
virtualListHelpers: {
|
|
36
|
-
scrollToIndex
|
|
37
|
-
}
|
|
49
|
+
virtualListHelpers: { scrollToIndex }
|
|
38
50
|
} = ctx;
|
|
39
|
-
const {
|
|
40
|
-
|
|
41
|
-
isExpanded
|
|
42
|
-
} = item;
|
|
43
|
-
const onItemFocusCurry = React.useCallback(newFocusItem => onItemFocus({
|
|
51
|
+
const { isGroup, isExpanded } = item;
|
|
52
|
+
const onItemFocusCurry = (0, import_react.useCallback)((newFocusItem) => onItemFocus({
|
|
44
53
|
itemIndex: newFocusItem.virtualIndex,
|
|
45
|
-
scrollToItem:
|
|
46
|
-
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
47
|
-
align: 'start'
|
|
48
|
-
};
|
|
49
|
-
return scrollToIndex(newFocusItem.virtualIndex, opts);
|
|
50
|
-
},
|
|
54
|
+
scrollToItem: (opts = { align: "start" }) => scrollToIndex(newFocusItem.virtualIndex, opts),
|
|
51
55
|
item: newFocusItem
|
|
52
56
|
}), [onItemFocus, scrollToIndex]);
|
|
53
|
-
const onItemKeyDown =
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (keyCode === 13 || keyCode === 32) setSelectedItem(item);
|
|
62
|
-
|
|
57
|
+
const onItemKeyDown = (0, import_react.useCallback)((e) => {
|
|
58
|
+
const { keyCode } = e;
|
|
59
|
+
if (!(draggableProps && draggableProps.active)) {
|
|
60
|
+
if (keyCode !== 9)
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
if ((keyCode === 13 || keyCode === 32) && e.target.tagName === "LI") {
|
|
63
|
+
setSelectedItem(item);
|
|
64
|
+
}
|
|
63
65
|
if (keyCode === 37) {
|
|
64
66
|
if (isGroup && isExpanded) {
|
|
65
|
-
|
|
67
|
+
(0, import_group_expands_helpers.toggleItemExpand)(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
|
|
66
68
|
setLatestToggledItem(item);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
|
-
|
|
70
71
|
if (keyCode === 39) {
|
|
71
72
|
if (isGroup && !isExpanded) {
|
|
72
|
-
|
|
73
|
+
(0, import_group_expands_helpers.toggleItemExpand)(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
|
|
73
74
|
setLatestToggledItem(item);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
virtualIndex
|
|
79
|
-
} = item;
|
|
80
|
-
|
|
81
|
-
if (typeof virtualIndex === 'number') {
|
|
77
|
+
const { virtualIndex } = item;
|
|
78
|
+
if (typeof virtualIndex === "number") {
|
|
82
79
|
const lastItemIndex = visibleItems.length - 1;
|
|
83
|
-
|
|
84
80
|
if (keyCode === 38) {
|
|
85
81
|
const isLoopedFocus = virtualIndex === 0;
|
|
86
82
|
const newFocusIndex = isLoopedFocus ? lastItemIndex : virtualIndex - 1;
|
|
87
83
|
const newFocusItem = visibleItems[newFocusIndex];
|
|
88
84
|
scrollToIndex(newFocusIndex);
|
|
89
|
-
|
|
90
85
|
if (isLoopedFocus) {
|
|
91
|
-
// when looping the list from start to end we need to wait a bit before focusing
|
|
92
86
|
setTimeout(() => {
|
|
93
87
|
setFocusedItem(newFocusItem);
|
|
94
|
-
|
|
88
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
95
89
|
onItemFocusCurry(newFocusItem);
|
|
96
90
|
}, 300);
|
|
97
91
|
} else {
|
|
98
92
|
setFocusedItem(newFocusItem);
|
|
99
93
|
onItemFocusCurry(newFocusItem);
|
|
100
|
-
|
|
94
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
101
95
|
}
|
|
102
96
|
}
|
|
103
|
-
|
|
104
97
|
if (keyCode === 40) {
|
|
105
98
|
const isLoopedFocus = virtualIndex === lastItemIndex;
|
|
106
99
|
const newFocusIndex = isLoopedFocus ? 0 : virtualIndex + 1;
|
|
107
100
|
const newFocusItem = visibleItems[newFocusIndex];
|
|
108
101
|
scrollToIndex(newFocusIndex);
|
|
109
|
-
|
|
110
102
|
if (isLoopedFocus) {
|
|
111
|
-
// when looping the list from start to end we need to wait a bit before focusing
|
|
112
103
|
setTimeout(() => {
|
|
113
104
|
setFocusedItem(newFocusItem);
|
|
114
105
|
onItemFocusCurry(newFocusItem);
|
|
115
|
-
|
|
106
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
116
107
|
}, 300);
|
|
117
108
|
} else {
|
|
118
109
|
setFocusedItem(newFocusItem);
|
|
119
110
|
onItemFocusCurry(newFocusItem);
|
|
120
|
-
|
|
111
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
121
112
|
}
|
|
122
113
|
}
|
|
123
|
-
|
|
124
114
|
if (keyCode === 35) {
|
|
125
115
|
if (virtualIndex !== lastItemIndex) {
|
|
126
116
|
const newFocusItem = visibleItems[lastItemIndex];
|
|
@@ -128,11 +118,10 @@ const useOnItemKeyDown = item => {
|
|
|
128
118
|
setTimeout(() => {
|
|
129
119
|
setFocusedItem(newFocusItem);
|
|
130
120
|
onItemFocusCurry(newFocusItem);
|
|
131
|
-
|
|
121
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
132
122
|
}, 300);
|
|
133
123
|
}
|
|
134
124
|
}
|
|
135
|
-
|
|
136
125
|
if (keyCode === 36) {
|
|
137
126
|
if (virtualIndex !== 0) {
|
|
138
127
|
const newFocusItem = visibleItems[0];
|
|
@@ -140,35 +129,42 @@ const useOnItemKeyDown = item => {
|
|
|
140
129
|
setTimeout(() => {
|
|
141
130
|
setFocusedItem(newFocusItem);
|
|
142
131
|
onItemFocusCurry(newFocusItem);
|
|
143
|
-
|
|
132
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
144
133
|
}, 300);
|
|
145
134
|
}
|
|
146
135
|
}
|
|
147
136
|
}
|
|
148
137
|
}
|
|
149
|
-
}, [
|
|
138
|
+
}, [
|
|
139
|
+
draggableProps,
|
|
140
|
+
setSelectedItem,
|
|
141
|
+
item,
|
|
142
|
+
isGroup,
|
|
143
|
+
isExpanded,
|
|
144
|
+
triggerTreeRerender,
|
|
145
|
+
updateUserExpandedState,
|
|
146
|
+
scrollToIndex,
|
|
147
|
+
setLatestToggledItem,
|
|
148
|
+
visibleItems,
|
|
149
|
+
setFocusedItem,
|
|
150
|
+
onItemFocusCurry
|
|
151
|
+
]);
|
|
150
152
|
return onItemKeyDown;
|
|
151
153
|
};
|
|
152
|
-
const useGlobalKeyboardListener = func => {
|
|
153
|
-
|
|
154
|
-
document.addEventListener(
|
|
155
|
-
return () => document.removeEventListener(
|
|
154
|
+
const useGlobalKeyboardListener = (func) => {
|
|
155
|
+
(0, import_react.useEffect)(() => {
|
|
156
|
+
document.addEventListener("keydown", func);
|
|
157
|
+
return () => document.removeEventListener("keydown", func);
|
|
156
158
|
}, [func]);
|
|
157
159
|
};
|
|
158
160
|
const useGlobalToggleAllExpandShortcut = (treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
|
|
159
|
-
const memoizedToggleAllKeyboardShortcut =
|
|
160
|
-
const {
|
|
161
|
-
shiftKey,
|
|
162
|
-
keyCode
|
|
163
|
-
} = e;
|
|
164
|
-
|
|
161
|
+
const memoizedToggleAllKeyboardShortcut = (0, import_react.useCallback)((e) => {
|
|
162
|
+
const { shiftKey, keyCode } = e;
|
|
165
163
|
if (shiftKey && keyCode === 56) {
|
|
166
|
-
|
|
164
|
+
(0, import_group_expands_helpers.toggleExpandAllHelper)("toggle", treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
167
165
|
}
|
|
168
166
|
}, [setLatestToggledItem, treeRoot, triggerTreeRerender, updateUserExpandedState]);
|
|
169
167
|
return useGlobalKeyboardListener(memoizedToggleAllKeyboardShortcut);
|
|
170
168
|
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
exports.useGlobalToggleAllExpandShortcut = useGlobalToggleAllExpandShortcut;
|
|
174
|
-
exports.useOnItemKeyDown = useOnItemKeyDown;
|
|
169
|
+
module.exports = __toCommonJS(keyboard_helpers_exports);
|
|
170
|
+
//# sourceMappingURL=keyboard-helpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/keyboard-helpers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-params */\n/* eslint-disable max-lines */\n/* eslint-disable max-statements */\n/* eslint-disable complexity */\nimport { useCallback, useContext, useEffect } from 'react';\nimport TreeViewContext from '../TreeViewContext';\nimport { focusItem } from './tree-helpers';\nimport { toggleExpandAllHelper, toggleItemExpand } from './group-expands-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\nimport { SortableItemContextType } from '../hoc/SortableItemContext';\n\n// 9 tab\n// 13 enter\n// 32 space\n// 37 left arrow\n// 38 up arrow\n// 39 right arrow\n// 40 down arrow\n// 35 end\n// 36 home\n\n// 56 number 8\n// 106 (NumPad) *\n\nexport const useOnItemKeyDown = (item: DSTreeviewT.Item, draggableProps: SortableItemContextType['draggableProps']) => {\n const ctx = useContext(TreeViewContext);\n const {\n props: { onItemFocus },\n triggerTreeRerender,\n visibleItems,\n setFocusedItem,\n setSelectedItem,\n setLatestToggledItem,\n updateUserExpandedState,\n virtualListHelpers: { scrollToIndex },\n } = ctx;\n const { isGroup, isExpanded } = item;\n const onItemFocusCurry = useCallback(\n (newFocusItem: DSTreeviewT.Item) =>\n onItemFocus({\n itemIndex: newFocusItem.virtualIndex as number,\n scrollToItem: (opts = { align: 'start' }) => scrollToIndex(newFocusItem.virtualIndex as number, opts),\n item: newFocusItem,\n }),\n [onItemFocus, scrollToIndex],\n );\n\n const onItemKeyDown = useCallback(\n (e: React.KeyboardEvent<HTMLLIElement>) => {\n const { keyCode } = e;\n if (!(draggableProps && draggableProps.active)) {\n if (keyCode !== 9) e.preventDefault(); // allow tab/shift+tab\n if ((keyCode === 13 || keyCode === 32) && (e.target as HTMLElement).tagName === 'LI') {\n setSelectedItem(item);\n }\n\n if (keyCode === 37) {\n if (isGroup && isExpanded) {\n toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);\n setLatestToggledItem(item);\n }\n }\n if (keyCode === 39) {\n if (isGroup && !isExpanded) {\n toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);\n setLatestToggledItem(item);\n }\n }\n\n const { virtualIndex } = item;\n if (typeof virtualIndex === 'number') {\n const lastItemIndex = visibleItems.length - 1;\n if (keyCode === 38) {\n const isLoopedFocus = virtualIndex === 0;\n const newFocusIndex = isLoopedFocus ? lastItemIndex : virtualIndex - 1;\n const newFocusItem = visibleItems[newFocusIndex];\n scrollToIndex(newFocusIndex);\n if (isLoopedFocus) {\n // when looping the list from start to end we need to wait a bit before focusing\n setTimeout(() => {\n setFocusedItem(newFocusItem);\n focusItem(newFocusItem);\n onItemFocusCurry(newFocusItem);\n }, 300);\n } else {\n setFocusedItem(newFocusItem);\n onItemFocusCurry(newFocusItem);\n focusItem(newFocusItem);\n }\n }\n if (keyCode === 40) {\n const isLoopedFocus = virtualIndex === lastItemIndex;\n const newFocusIndex = isLoopedFocus ? 0 : virtualIndex + 1;\n const newFocusItem = visibleItems[newFocusIndex];\n scrollToIndex(newFocusIndex);\n if (isLoopedFocus) {\n // when looping the list from start to end we need to wait a bit before focusing\n setTimeout(() => {\n setFocusedItem(newFocusItem);\n onItemFocusCurry(newFocusItem);\n focusItem(newFocusItem);\n }, 300);\n } else {\n setFocusedItem(newFocusItem);\n onItemFocusCurry(newFocusItem);\n focusItem(newFocusItem);\n }\n }\n if (keyCode === 35) {\n if (virtualIndex !== lastItemIndex) {\n const newFocusItem = visibleItems[lastItemIndex];\n scrollToIndex(lastItemIndex);\n setTimeout(() => {\n setFocusedItem(newFocusItem);\n onItemFocusCurry(newFocusItem);\n focusItem(newFocusItem);\n }, 300);\n }\n }\n if (keyCode === 36) {\n if (virtualIndex !== 0) {\n const newFocusItem = visibleItems[0];\n scrollToIndex(0);\n setTimeout(() => {\n setFocusedItem(newFocusItem);\n onItemFocusCurry(newFocusItem);\n focusItem(newFocusItem);\n }, 300);\n }\n }\n }\n }\n },\n [\n draggableProps,\n setSelectedItem,\n item,\n isGroup,\n isExpanded,\n triggerTreeRerender,\n updateUserExpandedState,\n scrollToIndex,\n setLatestToggledItem,\n visibleItems,\n setFocusedItem,\n onItemFocusCurry,\n ],\n );\n\n return onItemKeyDown;\n};\n\nexport const useGlobalKeyboardListener = (func: (e: KeyboardEvent) => void) => {\n useEffect(() => {\n document.addEventListener('keydown', func);\n return () => document.removeEventListener('keydown', func);\n }, [func]);\n};\n\nexport const useGlobalToggleAllExpandShortcut = (\n treeRoot: DSTreeviewT.Item['node'],\n triggerTreeRerender: () => void,\n setLatestToggledItem: DSTreeviewInternalsT.CTX['setLatestToggledItem'],\n updateUserExpandedState: DSTreeviewInternalsT.CTX['updateUserExpandedState'],\n) => {\n const memoizedToggleAllKeyboardShortcut = useCallback(\n (e: KeyboardEvent) => {\n const { shiftKey, keyCode } = e;\n if (shiftKey && keyCode === 56) {\n toggleExpandAllHelper('toggle', treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);\n }\n },\n [setLatestToggledItem, treeRoot, triggerTreeRerender, updateUserExpandedState],\n );\n\n return useGlobalKeyboardListener(memoizedToggleAllKeyboardShortcut);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,69 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
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 object_helpers_exports = {};
|
|
29
|
+
__export(object_helpers_exports, {
|
|
30
|
+
filterObject: () => filterObject,
|
|
31
|
+
unfreeze: () => unfreeze
|
|
32
|
+
});
|
|
33
|
+
var React = __toESM(require("react"));
|
|
18
34
|
function isObjectADate(o) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return (o === null || o === void 0 ? void 0 : (_o$constructor = o.constructor) === null || _o$constructor === void 0 ? void 0 : _o$constructor.name) === 'Date';
|
|
35
|
+
return o?.constructor?.name === "Date";
|
|
22
36
|
}
|
|
23
|
-
|
|
24
37
|
function isObjectAnArray(o) {
|
|
25
38
|
return Array.isArray(o);
|
|
26
39
|
}
|
|
27
|
-
|
|
28
40
|
function isObjectAString(o) {
|
|
29
|
-
return typeof o ===
|
|
41
|
+
return typeof o === "object";
|
|
30
42
|
}
|
|
31
|
-
|
|
32
|
-
const unfreeze = o => {
|
|
43
|
+
const unfreeze = (o) => {
|
|
33
44
|
let oo;
|
|
34
|
-
|
|
35
45
|
if (o === null) {
|
|
36
46
|
oo = null;
|
|
37
|
-
} else if (o ===
|
|
38
|
-
oo =
|
|
47
|
+
} else if (o === void 0) {
|
|
48
|
+
oo = void 0;
|
|
39
49
|
} else if (isObjectADate(o)) {
|
|
40
50
|
oo = new Date(o);
|
|
41
51
|
} else if (isObjectAnArray(o)) {
|
|
42
52
|
oo = [];
|
|
43
|
-
o.forEach(v => {
|
|
53
|
+
o.forEach((v) => {
|
|
44
54
|
oo.push(v);
|
|
45
55
|
});
|
|
46
56
|
} else if (isObjectAString(o)) {
|
|
47
57
|
oo = String(o);
|
|
48
58
|
} else if (isObjectAString(o)) {
|
|
49
59
|
oo = {};
|
|
50
|
-
|
|
51
60
|
for (const property in o) {
|
|
52
61
|
oo[property] = o[property];
|
|
53
62
|
}
|
|
54
63
|
} else {
|
|
55
64
|
oo = o;
|
|
56
65
|
}
|
|
57
|
-
|
|
58
66
|
return oo;
|
|
59
67
|
};
|
|
60
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
68
|
function filterObject(obj, predicate) {
|
|
62
69
|
return Object.keys(obj).reduce((res, key) => {
|
|
63
|
-
if (predicate(obj[key]))
|
|
70
|
+
if (predicate(obj[key]))
|
|
71
|
+
res[key] = obj[key];
|
|
64
72
|
return res;
|
|
65
73
|
}, {});
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
exports.unfreeze = unfreeze;
|
|
75
|
+
module.exports = __toCommonJS(object_helpers_exports);
|
|
76
|
+
//# sourceMappingURL=object-helpers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/object-helpers.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-sequences */\n/* eslint-disable no-return-assign */\n/* eslint-disable no-restricted-syntax */\n/* eslint-disable guard-for-in */\n\nfunction isObjectADate(o: string | number | unknown[] | Date | null | undefined | Record<string, unknown>): o is Date {\n return o?.constructor?.name === 'Date';\n}\nfunction isObjectAnArray(\n o: string | number | unknown[] | Date | null | undefined | Record<string, unknown>,\n): o is unknown[] {\n return Array.isArray(o);\n}\nfunction isObjectAString(\n o: string | number | unknown[] | Date | null | undefined | Record<string, unknown>,\n): o is Record<string, unknown> {\n return typeof o === 'object';\n}\n\nexport const unfreeze = (o: string | number | unknown[] | Date | null | undefined | Record<string, unknown>) => {\n let oo: string | number | unknown[] | Date | null | undefined | Record<string, unknown>;\n if (o === null) {\n oo = null;\n } else if (o === undefined) {\n oo = undefined;\n } else if (isObjectADate(o)) {\n oo = new Date(o);\n } else if (isObjectAnArray(o)) {\n oo = [];\n o.forEach((v) => {\n (oo as unknown[]).push(v);\n });\n } else if (isObjectAString(o)) {\n oo = String(o);\n } else if (isObjectAString(o)) {\n oo = {};\n for (const property in o) {\n oo[property] = o[property];\n }\n } else {\n oo = o;\n }\n return oo;\n};\n\ntype GenericItemT<T = unknown> = { [key: string]: T };\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function filterObject<T = unknown>(obj: GenericItemT<T>, predicate: (val: T) => boolean) {\n return Object.keys(obj).reduce<GenericItemT<T>>((res, key) => {\n if (predicate(obj[key])) res[key] = obj[key];\n return res;\n }, {} as GenericItemT<T>);\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADKvB,uBAAuB,GAA+F;AACpH,SAAO,GAAG,aAAa,SAAS;AAAA;AAElC,yBACE,GACgB;AAChB,SAAO,MAAM,QAAQ;AAAA;AAEvB,yBACE,GAC8B;AAC9B,SAAO,OAAO,MAAM;AAAA;AAGf,MAAM,WAAW,CAAC,MAAuF;AAC9G,MAAI;AACJ,MAAI,MAAM,MAAM;AACd,SAAK;AAAA,aACI,MAAM,QAAW;AAC1B,SAAK;AAAA,aACI,cAAc,IAAI;AAC3B,SAAK,IAAI,KAAK;AAAA,aACL,gBAAgB,IAAI;AAC7B,SAAK;AACL,MAAE,QAAQ,CAAC,MAAM;AACf,MAAC,GAAiB,KAAK;AAAA;AAAA,aAEhB,gBAAgB,IAAI;AAC7B,SAAK,OAAO;AAAA,aACH,gBAAgB,IAAI;AAC7B,SAAK;AACL,eAAW,YAAY,GAAG;AACxB,SAAG,YAAY,EAAE;AAAA;AAAA,SAEd;AACL,SAAK;AAAA;AAEP,SAAO;AAAA;AAKF,sBAAmC,KAAsB,WAAgC;AAC9F,SAAO,OAAO,KAAK,KAAK,OAAwB,CAAC,KAAK,QAAQ;AAC5D,QAAI,UAAU,IAAI;AAAO,UAAI,OAAO,IAAI;AACxC,WAAO;AAAA,KACN;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|