Files
NapCatQQ/.pnpm-store/v3/files/b9/cfd6dc6211c4ccec6eab237a932b7790799d1028cef98c2d1b728d305c2d48a46e13695755c0743d25e780508241b7c75adc3fba545a6320af011c8ef96fe2
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

45 lines
1.4 KiB
Plaintext

/*
* 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.
*/
import {Key} from '@react-types/shared';
import {ListState} from '@react-stately/list';
interface ListData {
id?: string,
shouldSelectOnPressUp?: boolean,
shouldFocusOnHover?: boolean,
shouldUseVirtualFocus?: boolean,
isVirtualized?: boolean,
onAction?: (key: Key) => void,
linkBehavior?: 'action' | 'selection' | 'override'
}
export const listData = new WeakMap<ListState<unknown>, ListData>();
function normalizeKey(key: Key): string {
if (typeof key === 'string') {
return key.replace(/\s*/g, '');
}
return '' + key;
}
export function getItemId<T>(state: ListState<T>, itemKey: Key): string {
let data = listData.get(state);
if (!data) {
throw new Error('Unknown list');
}
return `${data.id}-option-${normalizeKey(itemKey)}`;
}