Files
NapCatQQ/.pnpm-store/v3/files/09/7acb26002d5f31d3ffd116b6cf5581bae0e6fc5a44c4381e1eec5b9cfa9576888ba722a898cd080cc3fd028dcbd990b32f350ae6cff6e587b8935e3ad6d4d6
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

97 lines
2.6 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 {Collection, Direction, Key, KeyboardDelegate, Node, Orientation} from '@react-types/shared';
export class TabsKeyboardDelegate<T> implements KeyboardDelegate {
private collection: Collection<Node<T>>;
private flipDirection: boolean;
private disabledKeys: Set<Key>;
private tabDirection: boolean;
constructor(collection: Collection<Node<T>>, direction: Direction, orientation: Orientation, disabledKeys: Set<Key> = new Set()) {
this.collection = collection;
this.flipDirection = direction === 'rtl' && orientation === 'horizontal';
this.disabledKeys = disabledKeys;
this.tabDirection = orientation === 'horizontal';
}
getKeyLeftOf(key: Key) {
if (this.flipDirection) {
return this.getNextKey(key);
}
return this.getPreviousKey(key);
}
getKeyRightOf(key: Key) {
if (this.flipDirection) {
return this.getPreviousKey(key);
}
return this.getNextKey(key);
}
private isDisabled(key: Key) {
return this.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled;
}
getFirstKey() {
let key = this.collection.getFirstKey();
if (key != null && this.isDisabled(key)) {
key = this.getNextKey(key);
}
return key;
}
getLastKey() {
let key = this.collection.getLastKey();
if (key != null && this.isDisabled(key)) {
key = this.getPreviousKey(key);
}
return key;
}
getKeyAbove(key: Key) {
if (this.tabDirection) {
return null;
}
return this.getPreviousKey(key);
}
getKeyBelow(key: Key) {
if (this.tabDirection) {
return null;
}
return this.getNextKey(key);
}
getNextKey(key) {
do {
key = this.collection.getKeyAfter(key);
if (key == null) {
key = this.collection.getFirstKey();
}
} while (this.isDisabled(key));
return key;
}
getPreviousKey(key) {
do {
key = this.collection.getKeyBefore(key);
if (key == null) {
key = this.collection.getLastKey();
}
} while (this.isDisabled(key));
return key;
}
}