Files
NapCatQQ/.pnpm-store/v3/files/ea/6cf028052724ec63eb4ca67e3e103d5ad09f487c20eabed0f3dba3cb4161c5669c170417a4ee47d4117ee4df3a74673ac4488c66cf74078e4480c6f9d90b86
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

104 lines
5.6 KiB
Plaintext

import $4stjr$intlStringsmodulejs from "./intlStrings.mjs";
import {announce as $4stjr$announce} from "@react-aria/live-announcer";
import {useEffectEvent as $4stjr$useEffectEvent, useUpdateEffect as $4stjr$useUpdateEffect} from "@react-aria/utils";
import {useLocalizedStringFormatter as $4stjr$useLocalizedStringFormatter} from "@react-aria/i18n";
import {useRef as $4stjr$useRef} from "react";
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
/*
* Copyright 2022 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 $92599c3fd427b763$export$137e594ef3218a10(props, state) {
let { getRowText: getRowText = (key)=>{
var _state_collection_getTextValue, _state_collection, _state_collection_getItem;
var _state_collection_getTextValue1;
return (_state_collection_getTextValue1 = (_state_collection_getTextValue = (_state_collection = state.collection).getTextValue) === null || _state_collection_getTextValue === void 0 ? void 0 : _state_collection_getTextValue.call(_state_collection, key)) !== null && _state_collection_getTextValue1 !== void 0 ? _state_collection_getTextValue1 : (_state_collection_getItem = state.collection.getItem(key)) === null || _state_collection_getItem === void 0 ? void 0 : _state_collection_getItem.textValue;
} } = props;
let stringFormatter = (0, $4stjr$useLocalizedStringFormatter)((0, ($parcel$interopDefault($4stjr$intlStringsmodulejs))), '@react-aria/grid');
// Many screen readers do not announce when items in a grid are selected/deselected.
// We do this using an ARIA live region.
let selection = state.selectionManager.rawSelection;
let lastSelection = (0, $4stjr$useRef)(selection);
let announceSelectionChange = (0, $4stjr$useEffectEvent)(()=>{
var _lastSelection_current;
if (!state.selectionManager.isFocused || selection === lastSelection.current) {
lastSelection.current = selection;
return;
}
let addedKeys = $92599c3fd427b763$var$diffSelection(selection, lastSelection.current);
let removedKeys = $92599c3fd427b763$var$diffSelection(lastSelection.current, selection);
// If adding or removing a single row from the selection, announce the name of that item.
let isReplace = state.selectionManager.selectionBehavior === 'replace';
let messages = [];
if (state.selectionManager.selectedKeys.size === 1 && isReplace) {
let firstKey = state.selectionManager.selectedKeys.keys().next().value;
if (firstKey != null && state.collection.getItem(firstKey)) {
let currentSelectionText = getRowText(firstKey);
if (currentSelectionText) messages.push(stringFormatter.format('selectedItem', {
item: currentSelectionText
}));
}
} else if (addedKeys.size === 1 && removedKeys.size === 0) {
let firstKey = addedKeys.keys().next().value;
if (firstKey != null) {
let addedText = getRowText(firstKey);
if (addedText) messages.push(stringFormatter.format('selectedItem', {
item: addedText
}));
}
} else if (removedKeys.size === 1 && addedKeys.size === 0) {
let firstKey = removedKeys.keys().next().value;
if (firstKey != null && state.collection.getItem(firstKey)) {
let removedText = getRowText(firstKey);
if (removedText) messages.push(stringFormatter.format('deselectedItem', {
item: removedText
}));
}
}
// Announce how many items are selected, except when selecting the first item.
if (state.selectionManager.selectionMode === 'multiple') {
if (messages.length === 0 || selection === 'all' || selection.size > 1 || lastSelection.current === 'all' || ((_lastSelection_current = lastSelection.current) === null || _lastSelection_current === void 0 ? void 0 : _lastSelection_current.size) > 1) messages.push(selection === 'all' ? stringFormatter.format('selectedAll') : stringFormatter.format('selectedCount', {
count: selection.size
}));
}
if (messages.length > 0) (0, $4stjr$announce)(messages.join(' '));
lastSelection.current = selection;
});
(0, $4stjr$useUpdateEffect)(()=>{
if (state.selectionManager.isFocused) announceSelectionChange();
else {
// Wait a frame in case the collection is about to become focused (e.g. on mouse down).
let raf = requestAnimationFrame(announceSelectionChange);
return ()=>cancelAnimationFrame(raf);
}
}, [
selection,
state.selectionManager.isFocused
]);
}
function $92599c3fd427b763$var$diffSelection(a, b) {
let res = new Set();
if (a === 'all' || b === 'all') return res;
for (let key of a.keys())if (!b.has(key)) res.add(key);
return res;
}
export {$92599c3fd427b763$export$137e594ef3218a10 as useGridSelectionAnnouncement};
//# sourceMappingURL=useGridSelectionAnnouncement.module.js.map