@elliemae/ds-treeview 2.2.0-next.3 → 2.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/TreeView.js +49 -27
- package/cjs/TreeView.js.map +7 -0
- package/cjs/TreeViewContext.js +61 -37
- 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 +116 -78
- package/cjs/config/useTreeview.js.map +7 -0
- package/cjs/index.js +37 -26
- 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/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 +147 -141
- 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 +119 -130
- package/cjs/parts/TreeList.js.map +7 -0
- package/cjs/plugins/dnd/TreeDndPlugin.js +59 -7
- package/cjs/plugins/dnd/TreeDndPlugin.js.map +7 -0
- package/cjs/plugins/dnd/index.js +28 -9
- package/cjs/plugins/dnd/index.js.map +7 -0
- package/cjs/plugins/index.js +34 -21
- 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 +82 -54
- 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/dnd-helpers.js +146 -0
- package/cjs/utils/dnd-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 +85 -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 +105 -161
- package/cjs/utils/tree-helpers.js.map +7 -0
- package/cjs/utils/useDnDHelpers.js +199 -0
- package/cjs/utils/useDnDHelpers.js.map +7 -0
- package/cjs/utils/useInstanceRefActions.js +54 -43
- package/cjs/utils/useInstanceRefActions.js.map +7 -0
- package/cjs/utils/useTree.js +76 -80
- package/cjs/utils/useTree.js.map +7 -0
- package/esm/TreeView.js +18 -16
- package/esm/TreeView.js.map +7 -0
- package/esm/TreeViewContext.js +32 -31
- 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 +73 -56
- package/esm/config/useTreeview.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/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 +114 -125
- 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 +91 -119
- package/esm/parts/TreeList.js.map +7 -0
- package/esm/plugins/dnd/TreeDndPlugin.js +30 -3
- 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 +47 -44
- 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/dnd-helpers.js +117 -0
- package/esm/utils/dnd-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 +46 -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 +73 -143
- package/esm/utils/tree-helpers.js.map +7 -0
- package/esm/utils/useDnDHelpers.js +170 -0
- package/esm/utils/useDnDHelpers.js.map +7 -0
- package/esm/utils/useInstanceRefActions.js +21 -35
- package/esm/utils/useInstanceRefActions.js.map +7 -0
- package/esm/utils/useTree.js +35 -59
- package/esm/utils/useTree.js.map +7 -0
- package/package.json +19 -35
- package/types/TreeView.d.ts +1 -1
- package/types/parts/TreeItem.d.ts +11 -4
- package/types/parts/TreeList.d.ts +4 -0
- package/types/plugins/dnd/TreeDndPlugin.d.ts +2 -0
- package/types/react-desc-prop-types.d.ts +3 -17
- package/types/sharedTypes.d.ts +8 -1
- package/types/utils/dnd-helpers.d.ts +39 -0
- package/types/utils/keyboard-helpers.d.ts +1 -2
- package/types/utils/refs-helpers.d.ts +1 -1
- package/types/utils/tree-helpers.d.ts +1 -4
- package/types/utils/useDnDHelpers.d.ts +26 -0
- package/types/utils/useTree.d.ts +0 -1
- 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/parts/DnDHandle.js +0 -46
- package/cjs/parts/DropIndicator.js +0 -75
- 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/parts/DnDHandle.js +0 -38
- package/esm/parts/DropIndicator.js +0 -68
- 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/parts/DnDHandle.d.ts +0 -6
- package/types/parts/DropIndicator.d.ts +0 -10
|
@@ -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,127 +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) => {
|
|
40
|
+
const ctx = (0, import_react.useContext)(import_TreeViewContext.default);
|
|
24
41
|
const {
|
|
25
|
-
props: {
|
|
26
|
-
onItemFocus
|
|
27
|
-
},
|
|
42
|
+
props: { onItemFocus },
|
|
28
43
|
triggerTreeRerender,
|
|
44
|
+
isDragging,
|
|
29
45
|
visibleItems,
|
|
30
46
|
setFocusedItem,
|
|
31
47
|
setSelectedItem,
|
|
32
48
|
setLatestToggledItem,
|
|
33
49
|
updateUserExpandedState,
|
|
34
|
-
virtualListHelpers: {
|
|
35
|
-
scrollToIndex
|
|
36
|
-
}
|
|
50
|
+
virtualListHelpers: { scrollToIndex }
|
|
37
51
|
} = ctx;
|
|
38
|
-
const {
|
|
39
|
-
|
|
40
|
-
isExpanded
|
|
41
|
-
} = item;
|
|
42
|
-
const onItemFocusCurry = React.useCallback(newFocusItem => onItemFocus({
|
|
52
|
+
const { isGroup, isExpanded } = item;
|
|
53
|
+
const onItemFocusCurry = (0, import_react.useCallback)((newFocusItem) => onItemFocus({
|
|
43
54
|
itemIndex: newFocusItem.virtualIndex,
|
|
44
|
-
scrollToItem:
|
|
45
|
-
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
46
|
-
align: 'start'
|
|
47
|
-
};
|
|
48
|
-
return scrollToIndex(newFocusItem.virtualIndex, opts);
|
|
49
|
-
},
|
|
55
|
+
scrollToItem: (opts = { align: "start" }) => scrollToIndex(newFocusItem.virtualIndex, opts),
|
|
50
56
|
item: newFocusItem
|
|
51
57
|
}), [onItemFocus, scrollToIndex]);
|
|
52
|
-
const onItemKeyDown =
|
|
53
|
-
const {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (keyCode !== 9) e.preventDefault(); // allow tab/shift+tab
|
|
59
|
-
|
|
60
|
-
if ((keyCode === 13 || keyCode === 32) && e.target.tagName === 'LI') {
|
|
58
|
+
const onItemKeyDown = (0, import_react.useCallback)((e) => {
|
|
59
|
+
const { keyCode } = e;
|
|
60
|
+
if (!isDragging) {
|
|
61
|
+
if (keyCode !== 9)
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
if (keyCode === 13 || keyCode === 32)
|
|
61
64
|
setSelectedItem(item);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
65
|
if (keyCode === 37) {
|
|
65
66
|
if (isGroup && isExpanded) {
|
|
66
|
-
|
|
67
|
+
(0, import_group_expands_helpers.toggleItemExpand)(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
|
|
67
68
|
setLatestToggledItem(item);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
|
|
71
71
|
if (keyCode === 39) {
|
|
72
72
|
if (isGroup && !isExpanded) {
|
|
73
|
-
|
|
73
|
+
(0, import_group_expands_helpers.toggleItemExpand)(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
|
|
74
74
|
setLatestToggledItem(item);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
virtualIndex
|
|
80
|
-
} = item;
|
|
81
|
-
|
|
82
|
-
if (typeof virtualIndex === 'number') {
|
|
77
|
+
const { virtualIndex } = item;
|
|
78
|
+
if (typeof virtualIndex === "number") {
|
|
83
79
|
const lastItemIndex = visibleItems.length - 1;
|
|
84
|
-
|
|
85
80
|
if (keyCode === 38) {
|
|
86
81
|
const isLoopedFocus = virtualIndex === 0;
|
|
87
82
|
const newFocusIndex = isLoopedFocus ? lastItemIndex : virtualIndex - 1;
|
|
88
83
|
const newFocusItem = visibleItems[newFocusIndex];
|
|
89
84
|
scrollToIndex(newFocusIndex);
|
|
90
|
-
|
|
91
85
|
if (isLoopedFocus) {
|
|
92
|
-
// when looping the list from start to end we need to wait a bit before focusing
|
|
93
86
|
setTimeout(() => {
|
|
94
87
|
setFocusedItem(newFocusItem);
|
|
95
|
-
|
|
88
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
96
89
|
onItemFocusCurry(newFocusItem);
|
|
97
90
|
}, 300);
|
|
98
91
|
} else {
|
|
99
92
|
setFocusedItem(newFocusItem);
|
|
100
93
|
onItemFocusCurry(newFocusItem);
|
|
101
|
-
|
|
94
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
102
95
|
}
|
|
103
96
|
}
|
|
104
|
-
|
|
105
97
|
if (keyCode === 40) {
|
|
106
98
|
const isLoopedFocus = virtualIndex === lastItemIndex;
|
|
107
99
|
const newFocusIndex = isLoopedFocus ? 0 : virtualIndex + 1;
|
|
108
100
|
const newFocusItem = visibleItems[newFocusIndex];
|
|
109
101
|
scrollToIndex(newFocusIndex);
|
|
110
|
-
|
|
111
102
|
if (isLoopedFocus) {
|
|
112
|
-
// when looping the list from start to end we need to wait a bit before focusing
|
|
113
103
|
setTimeout(() => {
|
|
114
104
|
setFocusedItem(newFocusItem);
|
|
115
105
|
onItemFocusCurry(newFocusItem);
|
|
116
|
-
|
|
106
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
117
107
|
}, 300);
|
|
118
108
|
} else {
|
|
119
109
|
setFocusedItem(newFocusItem);
|
|
120
110
|
onItemFocusCurry(newFocusItem);
|
|
121
|
-
|
|
111
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
122
112
|
}
|
|
123
113
|
}
|
|
124
|
-
|
|
125
114
|
if (keyCode === 35) {
|
|
126
115
|
if (virtualIndex !== lastItemIndex) {
|
|
127
116
|
const newFocusItem = visibleItems[lastItemIndex];
|
|
@@ -129,11 +118,10 @@ const useOnItemKeyDown = (item, draggableProps) => {
|
|
|
129
118
|
setTimeout(() => {
|
|
130
119
|
setFocusedItem(newFocusItem);
|
|
131
120
|
onItemFocusCurry(newFocusItem);
|
|
132
|
-
|
|
121
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
133
122
|
}, 300);
|
|
134
123
|
}
|
|
135
124
|
}
|
|
136
|
-
|
|
137
125
|
if (keyCode === 36) {
|
|
138
126
|
if (virtualIndex !== 0) {
|
|
139
127
|
const newFocusItem = visibleItems[0];
|
|
@@ -141,35 +129,42 @@ const useOnItemKeyDown = (item, draggableProps) => {
|
|
|
141
129
|
setTimeout(() => {
|
|
142
130
|
setFocusedItem(newFocusItem);
|
|
143
131
|
onItemFocusCurry(newFocusItem);
|
|
144
|
-
|
|
132
|
+
(0, import_tree_helpers.focusItem)(newFocusItem);
|
|
145
133
|
}, 300);
|
|
146
134
|
}
|
|
147
135
|
}
|
|
148
136
|
}
|
|
149
137
|
}
|
|
150
|
-
}, [
|
|
138
|
+
}, [
|
|
139
|
+
isDragging,
|
|
140
|
+
setSelectedItem,
|
|
141
|
+
item,
|
|
142
|
+
isGroup,
|
|
143
|
+
isExpanded,
|
|
144
|
+
triggerTreeRerender,
|
|
145
|
+
scrollToIndex,
|
|
146
|
+
setLatestToggledItem,
|
|
147
|
+
visibleItems,
|
|
148
|
+
setFocusedItem,
|
|
149
|
+
onItemFocusCurry,
|
|
150
|
+
updateUserExpandedState
|
|
151
|
+
]);
|
|
151
152
|
return onItemKeyDown;
|
|
152
153
|
};
|
|
153
|
-
const useGlobalKeyboardListener = func => {
|
|
154
|
-
|
|
155
|
-
document.addEventListener(
|
|
156
|
-
return () => document.removeEventListener(
|
|
154
|
+
const useGlobalKeyboardListener = (func) => {
|
|
155
|
+
(0, import_react.useEffect)(() => {
|
|
156
|
+
document.addEventListener("keydown", func);
|
|
157
|
+
return () => document.removeEventListener("keydown", func);
|
|
157
158
|
}, [func]);
|
|
158
159
|
};
|
|
159
160
|
const useGlobalToggleAllExpandShortcut = (treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
|
|
160
|
-
const memoizedToggleAllKeyboardShortcut =
|
|
161
|
-
const {
|
|
162
|
-
shiftKey,
|
|
163
|
-
keyCode
|
|
164
|
-
} = e;
|
|
165
|
-
|
|
161
|
+
const memoizedToggleAllKeyboardShortcut = (0, import_react.useCallback)((e) => {
|
|
162
|
+
const { shiftKey, keyCode } = e;
|
|
166
163
|
if (shiftKey && keyCode === 56) {
|
|
167
|
-
|
|
164
|
+
(0, import_group_expands_helpers.toggleExpandAllHelper)("toggle", treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
|
|
168
165
|
}
|
|
169
166
|
}, [setLatestToggledItem, treeRoot, triggerTreeRerender, updateUserExpandedState]);
|
|
170
167
|
return useGlobalKeyboardListener(memoizedToggleAllKeyboardShortcut);
|
|
171
168
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
exports.useGlobalToggleAllExpandShortcut = useGlobalToggleAllExpandShortcut;
|
|
175
|
-
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';\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) => {\n const ctx = useContext(TreeViewContext);\n const {\n props: { onItemFocus },\n triggerTreeRerender,\n isDragging,\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 (!isDragging) {\n if (keyCode !== 9) e.preventDefault(); // allow tab/shift+tab\n if (keyCode === 13 || keyCode === 32) setSelectedItem(item);\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 isDragging,\n setSelectedItem,\n item,\n isGroup,\n isExpanded,\n triggerTreeRerender,\n scrollToIndex,\n setLatestToggledItem,\n visibleItems,\n setFocusedItem,\n onItemFocusCurry,\n updateUserExpandedState,\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
|
+
}
|