64 lines
2.9 KiB
Plaintext
64 lines
2.9 KiB
Plaintext
import {TreeCollection as $05ca4cd7c4a5a999$export$863faf230ee2118a} from "./TreeCollection.module.js";
|
|
import {useMultipleSelectionState as $75HV2$useMultipleSelectionState, SelectionManager as $75HV2$SelectionManager} from "@react-stately/selection";
|
|
import {useMemo as $75HV2$useMemo, useCallback as $75HV2$useCallback, useEffect as $75HV2$useEffect} from "react";
|
|
import {useCollection as $75HV2$useCollection} from "@react-stately/collections";
|
|
import {useControlledState as $75HV2$useControlledState} from "@react-stately/utils";
|
|
|
|
/*
|
|
* Copyright 2020 Adobe. All rights reserved.
|
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
* governing permissions and limitations under the License.
|
|
*/
|
|
|
|
|
|
|
|
|
|
function $875d6693e12af071$export$728d6ba534403756(props) {
|
|
let { onExpandedChange: onExpandedChange } = props;
|
|
let [expandedKeys, setExpandedKeys] = (0, $75HV2$useControlledState)(props.expandedKeys ? new Set(props.expandedKeys) : undefined, props.defaultExpandedKeys ? new Set(props.defaultExpandedKeys) : new Set(), onExpandedChange);
|
|
let selectionState = (0, $75HV2$useMultipleSelectionState)(props);
|
|
let disabledKeys = (0, $75HV2$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
|
|
props.disabledKeys
|
|
]);
|
|
let tree = (0, $75HV2$useCollection)(props, (0, $75HV2$useCallback)((nodes)=>new (0, $05ca4cd7c4a5a999$export$863faf230ee2118a)(nodes, {
|
|
expandedKeys: expandedKeys
|
|
}), [
|
|
expandedKeys
|
|
]), null);
|
|
// Reset focused key if that item is deleted from the collection.
|
|
(0, $75HV2$useEffect)(()=>{
|
|
if (selectionState.focusedKey != null && !tree.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [
|
|
tree,
|
|
selectionState.focusedKey
|
|
]);
|
|
let onToggle = (key)=>{
|
|
setExpandedKeys($875d6693e12af071$var$toggleKey(expandedKeys, key));
|
|
};
|
|
return {
|
|
collection: tree,
|
|
expandedKeys: expandedKeys,
|
|
disabledKeys: disabledKeys,
|
|
toggleKey: onToggle,
|
|
setExpandedKeys: setExpandedKeys,
|
|
selectionManager: new (0, $75HV2$SelectionManager)(tree, selectionState)
|
|
};
|
|
}
|
|
function $875d6693e12af071$var$toggleKey(set, key) {
|
|
let res = new Set(set);
|
|
if (res.has(key)) res.delete(key);
|
|
else res.add(key);
|
|
return res;
|
|
}
|
|
|
|
|
|
export {$875d6693e12af071$export$728d6ba534403756 as useTreeState};
|
|
//# sourceMappingURL=useTreeState.module.js.map
|