Files
NapCatQQ/.pnpm-store/v3/files/bb/8683906ee5c39ff652ae59f55e18dee7517f6282db12417f165258e6bd8587c9f31293daacb43465f20dc99478d81ecde709c17a4b0f8b9370f1cce11e3eff
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

72 lines
1.8 KiB
Plaintext

import {
useMultiSelectListState
} from "./chunk-RVB7J7GX.mjs";
// src/use-multiselect-state.ts
import { useMenuTriggerState } from "@react-stately/menu";
import { useFormValidationState } from "@react-stately/form";
import { useState } from "react";
function useMultiSelectState({
validate,
validationBehavior,
...props
}) {
const [isFocused, setFocused] = useState(false);
const [focusStrategy, setFocusStrategy] = useState(null);
const triggerState = useMenuTriggerState(props);
const listState = useMultiSelectListState({
...props,
onSelectionChange: (keys) => {
if (props.onSelectionChange != null) {
if (keys === "all") {
props.onSelectionChange(new Set(listState.collection.getKeys()));
} else {
props.onSelectionChange(keys);
}
}
if (props.selectionMode === "single") {
triggerState.close();
}
}
});
const validationState = useFormValidationState({
...props,
validationBehavior,
validate: (value) => {
if (!validate)
return;
const keys = Array.from(value);
return validate(props.selectionMode === "single" ? keys[0] : keys);
},
value: listState.selectedKeys
});
const shouldHideContent = listState.collection.size === 0 && props.hideEmptyContent;
return {
...validationState,
...listState,
...triggerState,
focusStrategy,
close() {
triggerState.close();
},
open(focusStrategy2 = null) {
if (shouldHideContent)
return;
setFocusStrategy(focusStrategy2);
triggerState.open();
},
toggle(focusStrategy2 = null) {
if (shouldHideContent)
return;
setFocusStrategy(focusStrategy2);
triggerState.toggle();
},
isFocused,
setFocused
};
}
export {
useMultiSelectState
};