Files
NapCatQQ/.pnpm-store/v3/files/03/3e2fe6cac874d83e1175ac5950295346547ee6e667ba99e3fb975d6b239a63196951f6e36bdde4a6334b076ccd856147646045dd2e9562f30216d7387b587a
T
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

41 lines
1.1 KiB
Plaintext

// src/use-multiselect-list-state.ts
import { useListState } from "@react-stately/list";
import { useMemo } from "react";
function useMultiSelectListState(props) {
const {
collection,
disabledKeys,
selectionManager,
selectionManager: { setSelectedKeys, selectedKeys, selectionMode }
} = useListState(props);
const missingKeys = useMemo(() => {
if (!props.isLoading && selectedKeys.size !== 0) {
return Array.from(selectedKeys).filter(Boolean).filter((key) => !collection.getItem(key));
}
return [];
}, [selectedKeys, collection]);
const selectedItems = selectedKeys.size !== 0 ? Array.from(selectedKeys).map((key) => {
return collection.getItem(key);
}).filter(Boolean) : null;
if (missingKeys.length) {
console.warn(
`Select: Keys "${missingKeys.join(
", "
)}" passed to "selectedKeys" are not present in the collection.`
);
}
return {
collection,
disabledKeys,
selectionManager,
selectionMode,
selectedKeys,
setSelectedKeys: setSelectedKeys.bind(selectionManager),
selectedItems
};
}
export {
useMultiSelectListState
};