@react-aria/selection 3.17.5 → 3.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ListKeyboardDelegate.main.js +200 -0
- package/dist/ListKeyboardDelegate.main.js.map +1 -0
- package/dist/ListKeyboardDelegate.mjs +195 -0
- package/dist/ListKeyboardDelegate.module.js +195 -0
- package/dist/ListKeyboardDelegate.module.js.map +1 -0
- package/dist/import.mjs +5 -794
- package/dist/main.js +10 -799
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -794
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useSelectableCollection.main.js +304 -0
- package/dist/useSelectableCollection.main.js.map +1 -0
- package/dist/useSelectableCollection.mjs +299 -0
- package/dist/useSelectableCollection.module.js +299 -0
- package/dist/useSelectableCollection.module.js.map +1 -0
- package/dist/useSelectableItem.main.js +213 -0
- package/dist/useSelectableItem.main.js.map +1 -0
- package/dist/useSelectableItem.mjs +208 -0
- package/dist/useSelectableItem.module.js +208 -0
- package/dist/useSelectableItem.module.js.map +1 -0
- package/dist/useSelectableList.main.js +61 -0
- package/dist/useSelectableList.main.js.map +1 -0
- package/dist/useSelectableList.mjs +56 -0
- package/dist/useSelectableList.module.js +56 -0
- package/dist/useSelectableList.module.js.map +1 -0
- package/dist/useTypeSelect.main.js +73 -0
- package/dist/useTypeSelect.main.js.map +1 -0
- package/dist/useTypeSelect.mjs +68 -0
- package/dist/useTypeSelect.module.js +68 -0
- package/dist/useTypeSelect.module.js.map +1 -0
- package/dist/utils.main.js +32 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +26 -0
- package/dist/utils.module.js +26 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +8 -8
- package/src/ListKeyboardDelegate.ts +15 -7
- package/src/useSelectableCollection.ts +5 -3
- package/src/useSelectableItem.ts +4 -2
- package/src/useSelectableList.ts +7 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import {isCtrlKeyPressed as $feb5ffebff200149$export$16792effe837dba3, isNonContiguousSelectionModifier as $feb5ffebff200149$export$d3e3bd3e26688c04} from "./utils.module.js";
|
|
2
|
+
import {focusSafely as $581M0$focusSafely} from "@react-aria/focus";
|
|
3
|
+
import {useRouter as $581M0$useRouter, openLink as $581M0$openLink, mergeProps as $581M0$mergeProps} from "@react-aria/utils";
|
|
4
|
+
import {usePress as $581M0$usePress, useLongPress as $581M0$useLongPress} from "@react-aria/interactions";
|
|
5
|
+
import {useEffect as $581M0$useEffect, useRef as $581M0$useRef} from "react";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
* governing permissions and limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function $880e95eb8b93ba9a$export$ecf600387e221c37(options) {
|
|
23
|
+
let { selectionManager: manager, key: key, ref: ref, shouldSelectOnPressUp: shouldSelectOnPressUp, shouldUseVirtualFocus: shouldUseVirtualFocus, focus: focus, isDisabled: isDisabled, onAction: onAction, allowsDifferentPressOrigin: allowsDifferentPressOrigin, linkBehavior: linkBehavior = 'action' } = options;
|
|
24
|
+
let router = (0, $581M0$useRouter)();
|
|
25
|
+
let onSelect = (e)=>{
|
|
26
|
+
if (e.pointerType === 'keyboard' && (0, $feb5ffebff200149$export$d3e3bd3e26688c04)(e)) manager.toggleSelection(key);
|
|
27
|
+
else {
|
|
28
|
+
if (manager.selectionMode === 'none') return;
|
|
29
|
+
if (manager.isLink(key)) {
|
|
30
|
+
if (linkBehavior === 'selection') {
|
|
31
|
+
let itemProps = manager.getItemProps(key);
|
|
32
|
+
router.open(ref.current, e, itemProps.href, itemProps.routerOptions);
|
|
33
|
+
// Always set selected keys back to what they were so that select and combobox close.
|
|
34
|
+
manager.setSelectedKeys(manager.selectedKeys);
|
|
35
|
+
return;
|
|
36
|
+
} else if (linkBehavior === 'override' || linkBehavior === 'none') return;
|
|
37
|
+
}
|
|
38
|
+
if (manager.selectionMode === 'single') {
|
|
39
|
+
if (manager.isSelected(key) && !manager.disallowEmptySelection) manager.toggleSelection(key);
|
|
40
|
+
else manager.replaceSelection(key);
|
|
41
|
+
} else if (e && e.shiftKey) manager.extendSelection(key);
|
|
42
|
+
else if (manager.selectionBehavior === 'toggle' || e && ((0, $feb5ffebff200149$export$16792effe837dba3)(e) || e.pointerType === 'touch' || e.pointerType === 'virtual')) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
|
|
43
|
+
manager.toggleSelection(key);
|
|
44
|
+
else manager.replaceSelection(key);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
// Focus the associated DOM node when this item becomes the focusedKey
|
|
48
|
+
(0, $581M0$useEffect)(()=>{
|
|
49
|
+
let isFocused = key === manager.focusedKey;
|
|
50
|
+
if (isFocused && manager.isFocused && !shouldUseVirtualFocus) {
|
|
51
|
+
if (focus) focus();
|
|
52
|
+
else if (document.activeElement !== ref.current) (0, $581M0$focusSafely)(ref.current);
|
|
53
|
+
}
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
+
}, [
|
|
56
|
+
ref,
|
|
57
|
+
key,
|
|
58
|
+
manager.focusedKey,
|
|
59
|
+
manager.childFocusStrategy,
|
|
60
|
+
manager.isFocused,
|
|
61
|
+
shouldUseVirtualFocus
|
|
62
|
+
]);
|
|
63
|
+
isDisabled = isDisabled || manager.isDisabled(key);
|
|
64
|
+
// Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
|
|
65
|
+
// item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
|
|
66
|
+
// on iOS 14 doesn't try to move real DOM focus to the item anyway.
|
|
67
|
+
let itemProps = {};
|
|
68
|
+
if (!shouldUseVirtualFocus && !isDisabled) itemProps = {
|
|
69
|
+
tabIndex: key === manager.focusedKey ? 0 : -1,
|
|
70
|
+
onFocus (e) {
|
|
71
|
+
if (e.target === ref.current) manager.setFocusedKey(key);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
else if (isDisabled) itemProps.onMouseDown = (e)=>{
|
|
75
|
+
// Prevent focus going to the body when clicking on a disabled item.
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
};
|
|
78
|
+
// With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.
|
|
79
|
+
// Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.
|
|
80
|
+
// With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.
|
|
81
|
+
// With touch, onAction occurs on single tap, and long press enters selection mode.
|
|
82
|
+
let isLinkOverride = manager.isLink(key) && linkBehavior === 'override';
|
|
83
|
+
let hasLinkAction = manager.isLink(key) && linkBehavior !== 'selection' && linkBehavior !== 'none';
|
|
84
|
+
let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;
|
|
85
|
+
let allowsActions = (onAction || hasLinkAction) && !isDisabled;
|
|
86
|
+
let hasPrimaryAction = allowsActions && (manager.selectionBehavior === 'replace' ? !allowsSelection : !allowsSelection || manager.isEmpty);
|
|
87
|
+
let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === 'replace';
|
|
88
|
+
let hasAction = hasPrimaryAction || hasSecondaryAction;
|
|
89
|
+
let modality = (0, $581M0$useRef)(null);
|
|
90
|
+
let longPressEnabled = hasAction && allowsSelection;
|
|
91
|
+
let longPressEnabledOnPressStart = (0, $581M0$useRef)(false);
|
|
92
|
+
let hadPrimaryActionOnPressStart = (0, $581M0$useRef)(false);
|
|
93
|
+
let performAction = (e)=>{
|
|
94
|
+
if (onAction) onAction();
|
|
95
|
+
if (hasLinkAction) {
|
|
96
|
+
let itemProps = manager.getItemProps(key);
|
|
97
|
+
router.open(ref.current, e, itemProps.href, itemProps.routerOptions);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
// By default, selection occurs on pointer down. This can be strange if selecting an
|
|
101
|
+
// item causes the UI to disappear immediately (e.g. menus).
|
|
102
|
+
// If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
|
|
103
|
+
// onPress requires a pointer down event on the same element as pointer up. For menus,
|
|
104
|
+
// we want to be able to have the pointer down on the trigger that opens the menu and
|
|
105
|
+
// the pointer up on the menu item rather than requiring a separate press.
|
|
106
|
+
// For keyboard events, selection still occurs on key down.
|
|
107
|
+
let itemPressProps = {};
|
|
108
|
+
if (shouldSelectOnPressUp) {
|
|
109
|
+
itemPressProps.onPressStart = (e)=>{
|
|
110
|
+
modality.current = e.pointerType;
|
|
111
|
+
longPressEnabledOnPressStart.current = longPressEnabled;
|
|
112
|
+
if (e.pointerType === 'keyboard' && (!hasAction || $880e95eb8b93ba9a$var$isSelectionKey())) onSelect(e);
|
|
113
|
+
};
|
|
114
|
+
// If allowsDifferentPressOrigin, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)
|
|
115
|
+
// Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)
|
|
116
|
+
if (!allowsDifferentPressOrigin) itemPressProps.onPress = (e)=>{
|
|
117
|
+
if (hasPrimaryAction || hasSecondaryAction && e.pointerType !== 'mouse') {
|
|
118
|
+
if (e.pointerType === 'keyboard' && !$880e95eb8b93ba9a$var$isActionKey()) return;
|
|
119
|
+
performAction(e);
|
|
120
|
+
} else if (e.pointerType !== 'keyboard' && allowsSelection) onSelect(e);
|
|
121
|
+
};
|
|
122
|
+
else {
|
|
123
|
+
itemPressProps.onPressUp = hasPrimaryAction ? null : (e)=>{
|
|
124
|
+
if (e.pointerType !== 'keyboard' && allowsSelection) onSelect(e);
|
|
125
|
+
};
|
|
126
|
+
itemPressProps.onPress = hasPrimaryAction ? performAction : null;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
itemPressProps.onPressStart = (e)=>{
|
|
130
|
+
modality.current = e.pointerType;
|
|
131
|
+
longPressEnabledOnPressStart.current = longPressEnabled;
|
|
132
|
+
hadPrimaryActionOnPressStart.current = hasPrimaryAction;
|
|
133
|
+
// Select on mouse down unless there is a primary action which will occur on mouse up.
|
|
134
|
+
// For keyboard, select on key down. If there is an action, the Space key selects on key down,
|
|
135
|
+
// and the Enter key performs onAction on key up.
|
|
136
|
+
if (allowsSelection && (e.pointerType === 'mouse' && !hasPrimaryAction || e.pointerType === 'keyboard' && (!allowsActions || $880e95eb8b93ba9a$var$isSelectionKey()))) onSelect(e);
|
|
137
|
+
};
|
|
138
|
+
itemPressProps.onPress = (e)=>{
|
|
139
|
+
// Selection occurs on touch up. Primary actions always occur on pointer up.
|
|
140
|
+
// Both primary and secondary actions occur on Enter key up. The only exception
|
|
141
|
+
// is secondary actions, which occur on double click with a mouse.
|
|
142
|
+
if (e.pointerType === 'touch' || e.pointerType === 'pen' || e.pointerType === 'virtual' || e.pointerType === 'keyboard' && hasAction && $880e95eb8b93ba9a$var$isActionKey() || e.pointerType === 'mouse' && hadPrimaryActionOnPressStart.current) {
|
|
143
|
+
if (hasAction) performAction(e);
|
|
144
|
+
else if (allowsSelection) onSelect(e);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
itemProps['data-key'] = key;
|
|
149
|
+
itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;
|
|
150
|
+
let { pressProps: pressProps, isPressed: isPressed } = (0, $581M0$usePress)(itemPressProps);
|
|
151
|
+
// Double clicking with a mouse with selectionBehavior = 'replace' performs an action.
|
|
152
|
+
let onDoubleClick = hasSecondaryAction ? (e)=>{
|
|
153
|
+
if (modality.current === 'mouse') {
|
|
154
|
+
e.stopPropagation();
|
|
155
|
+
e.preventDefault();
|
|
156
|
+
performAction(e);
|
|
157
|
+
}
|
|
158
|
+
} : undefined;
|
|
159
|
+
// Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior
|
|
160
|
+
// to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to
|
|
161
|
+
// selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.
|
|
162
|
+
let { longPressProps: longPressProps } = (0, $581M0$useLongPress)({
|
|
163
|
+
isDisabled: !longPressEnabled,
|
|
164
|
+
onLongPress (e) {
|
|
165
|
+
if (e.pointerType === 'touch') {
|
|
166
|
+
onSelect(e);
|
|
167
|
+
manager.setSelectionBehavior('toggle');
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
// Prevent native drag and drop on long press if we also select on long press.
|
|
172
|
+
// Once the user is in selection mode, they can long press again to drag.
|
|
173
|
+
// Use a capturing listener to ensure this runs before useDrag, regardless of
|
|
174
|
+
// the order the props get merged.
|
|
175
|
+
let onDragStartCapture = (e)=>{
|
|
176
|
+
if (modality.current === 'touch' && longPressEnabledOnPressStart.current) e.preventDefault();
|
|
177
|
+
};
|
|
178
|
+
// Prevent default on link clicks so that we control exactly
|
|
179
|
+
// when they open (to match selection behavior).
|
|
180
|
+
let onClick = manager.isLink(key) ? (e)=>{
|
|
181
|
+
if (!(0, $581M0$openLink).isOpening) e.preventDefault();
|
|
182
|
+
} : undefined;
|
|
183
|
+
return {
|
|
184
|
+
itemProps: (0, $581M0$mergeProps)(itemProps, allowsSelection || hasPrimaryAction ? pressProps : {}, longPressEnabled ? longPressProps : {}, {
|
|
185
|
+
onDoubleClick: onDoubleClick,
|
|
186
|
+
onDragStartCapture: onDragStartCapture,
|
|
187
|
+
onClick: onClick
|
|
188
|
+
}),
|
|
189
|
+
isPressed: isPressed,
|
|
190
|
+
isSelected: manager.isSelected(key),
|
|
191
|
+
isFocused: manager.isFocused && manager.focusedKey === key,
|
|
192
|
+
isDisabled: isDisabled,
|
|
193
|
+
allowsSelection: allowsSelection,
|
|
194
|
+
hasAction: hasAction
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function $880e95eb8b93ba9a$var$isActionKey() {
|
|
198
|
+
let event = window.event;
|
|
199
|
+
return (event === null || event === void 0 ? void 0 : event.key) === 'Enter';
|
|
200
|
+
}
|
|
201
|
+
function $880e95eb8b93ba9a$var$isSelectionKey() {
|
|
202
|
+
let event = window.event;
|
|
203
|
+
return (event === null || event === void 0 ? void 0 : event.key) === ' ' || (event === null || event === void 0 ? void 0 : event.code) === 'Space';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
export {$880e95eb8b93ba9a$export$ecf600387e221c37 as useSelectableItem};
|
|
208
|
+
//# sourceMappingURL=useSelectableItem.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkGM,SAAS,0CAAkB,OAA8B;IAC9D,IAAI,EACF,kBAAkB,OAAO,OACzB,GAAG,OACH,GAAG,yBACH,qBAAqB,yBACrB,qBAAqB,SACrB,KAAK,cACL,UAAU,YACV,QAAQ,8BACR,0BAA0B,gBAC1B,eAAe,UAChB,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,gBAAQ;IAErB,IAAI,WAAW,CAAC;QACd,IAAI,EAAE,WAAW,KAAK,cAAc,CAAA,GAAA,yCAA+B,EAAE,IACnE,QAAQ,eAAe,CAAC;aACnB;YACL,IAAI,QAAQ,aAAa,KAAK,QAC5B;YAGF,IAAI,QAAQ,MAAM,CAAC,MAAM;gBACvB,IAAI,iBAAiB,aAAa;oBAChC,IAAI,YAAY,QAAQ,YAAY,CAAC;oBACrC,OAAO,IAAI,CAAC,IAAI,OAAO,EAAE,GA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\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, FocusableElement, Key, LongPressEvent, PressEvent} from '@react-types/shared';\nimport {focusSafely} from '@react-aria/focus';\nimport {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';\nimport {mergeProps, openLink, useRouter} from '@react-aria/utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {PressProps, useLongPress, usePress} from '@react-aria/interactions';\nimport {RefObject, useEffect, useRef} from 'react';\n\nexport interface SelectableItemOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<FocusableElement>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or triggers selection on\n * the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /** Whether the item is disabled. */\n isDisabled?: boolean,\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override' | 'none'\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean,\n /** Whether the item is currently selected. */\n isSelected: boolean,\n /** Whether the item is currently focused. */\n isFocused: boolean,\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may\n * not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean,\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and `disabledBehavior`.\n */\n allowsSelection: boolean,\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n shouldUseVirtualFocus,\n focus,\n isDisabled,\n onAction,\n allowsDifferentPressOrigin,\n linkBehavior = 'action'\n } = options;\n let router = useRouter();\n\n let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {\n manager.toggleSelection(key);\n } else {\n if (manager.selectionMode === 'none') {\n return;\n }\n\n if (manager.isLink(key)) {\n if (linkBehavior === 'selection') {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n // Always set selected keys back to what they were so that select and combobox close.\n manager.setSelectedKeys(manager.selectedKeys);\n return;\n } else if (linkBehavior === 'override' || linkBehavior === 'none') {\n return;\n }\n }\n\n if (manager.selectionMode === 'single') {\n if (manager.isSelected(key) && !manager.disallowEmptySelection) {\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n manager.extendSelection(key);\n } else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(e) || e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n useEffect(() => {\n let isFocused = key === manager.focusedKey;\n if (isFocused && manager.isFocused && !shouldUseVirtualFocus) {\n if (focus) {\n focus();\n } else if (document.activeElement !== ref.current) {\n focusSafely(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref, key, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n isDisabled = isDisabled || manager.isDisabled(key);\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus && !isDisabled) {\n itemProps = {\n tabIndex: key === manager.focusedKey ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n } else if (isDisabled) {\n itemProps.onMouseDown = (e) => {\n // Prevent focus going to the body when clicking on a disabled item.\n e.preventDefault();\n };\n }\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n let isLinkOverride = manager.isLink(key) && linkBehavior === 'override';\n let hasLinkAction = manager.isLink(key) && linkBehavior !== 'selection' && linkBehavior !== 'none';\n let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;\n let allowsActions = (onAction || hasLinkAction) && !isDisabled;\n let hasPrimaryAction = allowsActions && (\n manager.selectionBehavior === 'replace'\n ? !allowsSelection\n : !allowsSelection || manager.isEmpty\n );\n let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === 'replace';\n let hasAction = hasPrimaryAction || hasSecondaryAction;\n let modality = useRef(null);\n\n let longPressEnabled = hasAction && allowsSelection;\n let longPressEnabledOnPressStart = useRef(false);\n let hadPrimaryActionOnPressStart = useRef(false);\n\n let performAction = (e) => {\n if (onAction) {\n onAction();\n }\n\n if (hasLinkAction) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n let itemPressProps: PressProps = {};\n if (shouldSelectOnPressUp) {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n if (e.pointerType === 'keyboard' && (!hasAction || isSelectionKey())) {\n onSelect(e);\n }\n };\n\n // If allowsDifferentPressOrigin, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (!allowsDifferentPressOrigin) {\n itemPressProps.onPress = (e) => {\n if (hasPrimaryAction || (hasSecondaryAction && e.pointerType !== 'mouse')) {\n if (e.pointerType === 'keyboard' && !isActionKey()) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== 'keyboard' && allowsSelection) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPressUp = hasPrimaryAction ? null : (e) => {\n if (e.pointerType !== 'keyboard' && allowsSelection) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction ? performAction : null;\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n hadPrimaryActionOnPressStart.current = hasPrimaryAction;\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection && (\n (e.pointerType === 'mouse' && !hasPrimaryAction) ||\n (e.pointerType === 'keyboard' && (!allowsActions || isSelectionKey()))\n )\n ) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = (e) => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === 'touch' ||\n e.pointerType === 'pen' ||\n e.pointerType === 'virtual' ||\n (e.pointerType === 'keyboard' && hasAction && isActionKey()) ||\n (e.pointerType === 'mouse' && hadPrimaryActionOnPressStart.current)\n ) {\n if (hasAction) {\n performAction(e);\n } else if (allowsSelection) {\n onSelect(e);\n }\n }\n };\n }\n\n itemProps['data-key'] = key;\n itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;\n let {pressProps, isPressed} = usePress(itemPressProps);\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n let onDoubleClick = hasSecondaryAction ? (e) => {\n if (modality.current === 'mouse') {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n } : undefined;\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n let {longPressProps} = useLongPress({\n isDisabled: !longPressEnabled,\n onLongPress(e) {\n if (e.pointerType === 'touch') {\n onSelect(e);\n manager.setSelectionBehavior('toggle');\n }\n }\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n let onDragStartCapture = e => {\n if (modality.current === 'touch' && longPressEnabledOnPressStart.current) {\n e.preventDefault();\n }\n };\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n let onClick = manager.isLink(key) ? e => {\n if (!(openLink as any).isOpening) {\n e.preventDefault();\n }\n } : undefined;\n\n return {\n itemProps: mergeProps(\n itemProps,\n allowsSelection || hasPrimaryAction ? pressProps : {},\n longPressEnabled ? longPressProps : {},\n {onDoubleClick, onDragStartCapture, onClick}\n ),\n isPressed,\n isSelected: manager.isSelected(key),\n isFocused: manager.isFocused && manager.focusedKey === key,\n isDisabled,\n allowsSelection,\n hasAction\n };\n}\n\nfunction isActionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === 'Enter';\n}\n\nfunction isSelectionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === ' ' || event?.code === 'Space';\n}\n"],"names":[],"version":3,"file":"useSelectableItem.module.js.map"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var $b6837c2f80a3c32f$exports = require("./useSelectableCollection.main.js");
|
|
2
|
+
var $836f880b12dcae5c$exports = require("./ListKeyboardDelegate.main.js");
|
|
3
|
+
var $lm2JY$reactariai18n = require("@react-aria/i18n");
|
|
4
|
+
var $lm2JY$react = require("react");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
$parcel$export(module.exports, "useSelectableList", () => $bd230acee196f50c$export$b95089534ab7c1fd);
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function $bd230acee196f50c$export$b95089534ab7c1fd(props) {
|
|
27
|
+
let { selectionManager: selectionManager, collection: collection, disabledKeys: disabledKeys, ref: ref, keyboardDelegate: keyboardDelegate } = props;
|
|
28
|
+
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
29
|
+
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
30
|
+
let collator = (0, $lm2JY$reactariai18n.useCollator)({
|
|
31
|
+
usage: 'search',
|
|
32
|
+
sensitivity: 'base'
|
|
33
|
+
});
|
|
34
|
+
let disabledBehavior = selectionManager.disabledBehavior;
|
|
35
|
+
let delegate = (0, $lm2JY$react.useMemo)(()=>keyboardDelegate || new (0, $836f880b12dcae5c$exports.ListKeyboardDelegate)({
|
|
36
|
+
collection: collection,
|
|
37
|
+
disabledKeys: disabledKeys,
|
|
38
|
+
disabledBehavior: disabledBehavior,
|
|
39
|
+
ref: ref,
|
|
40
|
+
collator: collator
|
|
41
|
+
}), [
|
|
42
|
+
keyboardDelegate,
|
|
43
|
+
collection,
|
|
44
|
+
disabledKeys,
|
|
45
|
+
ref,
|
|
46
|
+
collator,
|
|
47
|
+
disabledBehavior
|
|
48
|
+
]);
|
|
49
|
+
let { collectionProps: collectionProps } = (0, $b6837c2f80a3c32f$exports.useSelectableCollection)({
|
|
50
|
+
...props,
|
|
51
|
+
ref: ref,
|
|
52
|
+
selectionManager: selectionManager,
|
|
53
|
+
keyboardDelegate: delegate
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
listProps: collectionProps
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=useSelectableList.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAkB,KAAgC;IAChE,IAAI,oBACF,gBAAgB,cAChB,UAAU,gBACV,YAAY,OACZ,GAAG,oBACH,gBAAgB,EACjB,GAAG;IAEJ,0HAA0H;IAC1H,qFAAqF;IACrF,IAAI,WAAW,CAAA,GAAA,gCAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,mBAAmB,iBAAiB,gBAAgB;IACxD,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE,IACrB,oBAAoB,IAAI,CAAA,GAAA,8CAAmB,EAAE;wBAC3C;0BACA;8BACA;iBACA;sBACA;QACF,IACC;QAAC;QAAkB;QAAY;QAAc;QAAK;QAAU;KAAiB;IAEhF,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,iDAAsB,EAAE;QAC9C,GAAG,KAAK;aACR;0BACA;QACA,kBAAkB;IACpB;IAEA,OAAO;QACL,WAAW;IACb;AACF","sources":["packages/@react-aria/selection/src/useSelectableList.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaSelectableCollectionOptions, useSelectableCollection} from './useSelectableCollection';\nimport {Collection, DOMAttributes, Key, KeyboardDelegate, Node} from '@react-types/shared';\nimport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nimport {useCollator} from '@react-aria/i18n';\nimport {useMemo} from 'react';\n\nexport interface AriaSelectableListOptions extends Omit<AriaSelectableCollectionOptions, 'keyboardDelegate'> {\n /**\n * State of the collection.\n */\n collection: Collection<Node<unknown>>,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.\n */\n disabledKeys: Set<Key>\n}\n\nexport interface SelectableListAria {\n /**\n * Props for the option element.\n */\n listProps: DOMAttributes\n}\n\n/**\n * Handles interactions with a selectable list.\n */\nexport function useSelectableList(props: AriaSelectableListOptions): SelectableListAria {\n let {\n selectionManager,\n collection,\n disabledKeys,\n ref,\n keyboardDelegate\n } = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let disabledBehavior = selectionManager.disabledBehavior;\n let delegate = useMemo(() => (\n keyboardDelegate || new ListKeyboardDelegate({\n collection,\n disabledKeys,\n disabledBehavior,\n ref,\n collator\n })\n ), [keyboardDelegate, collection, disabledKeys, ref, collator, disabledBehavior]);\n\n let {collectionProps} = useSelectableCollection({\n ...props,\n ref,\n selectionManager,\n keyboardDelegate: delegate\n });\n\n return {\n listProps: collectionProps\n };\n}\n"],"names":[],"version":3,"file":"useSelectableList.main.js.map"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {useSelectableCollection as $ae20dd8cbca75726$export$d6daf82dcd84e87c} from "./useSelectableCollection.mjs";
|
|
2
|
+
import {ListKeyboardDelegate as $2a25aae57d74318e$export$a05409b8bb224a5a} from "./ListKeyboardDelegate.mjs";
|
|
3
|
+
import {useCollator as $1aJk5$useCollator} from "@react-aria/i18n";
|
|
4
|
+
import {useMemo as $1aJk5$useMemo} from "react";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function $982254629710d113$export$b95089534ab7c1fd(props) {
|
|
21
|
+
let { selectionManager: selectionManager, collection: collection, disabledKeys: disabledKeys, ref: ref, keyboardDelegate: keyboardDelegate } = props;
|
|
22
|
+
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
23
|
+
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
24
|
+
let collator = (0, $1aJk5$useCollator)({
|
|
25
|
+
usage: 'search',
|
|
26
|
+
sensitivity: 'base'
|
|
27
|
+
});
|
|
28
|
+
let disabledBehavior = selectionManager.disabledBehavior;
|
|
29
|
+
let delegate = (0, $1aJk5$useMemo)(()=>keyboardDelegate || new (0, $2a25aae57d74318e$export$a05409b8bb224a5a)({
|
|
30
|
+
collection: collection,
|
|
31
|
+
disabledKeys: disabledKeys,
|
|
32
|
+
disabledBehavior: disabledBehavior,
|
|
33
|
+
ref: ref,
|
|
34
|
+
collator: collator
|
|
35
|
+
}), [
|
|
36
|
+
keyboardDelegate,
|
|
37
|
+
collection,
|
|
38
|
+
disabledKeys,
|
|
39
|
+
ref,
|
|
40
|
+
collator,
|
|
41
|
+
disabledBehavior
|
|
42
|
+
]);
|
|
43
|
+
let { collectionProps: collectionProps } = (0, $ae20dd8cbca75726$export$d6daf82dcd84e87c)({
|
|
44
|
+
...props,
|
|
45
|
+
ref: ref,
|
|
46
|
+
selectionManager: selectionManager,
|
|
47
|
+
keyboardDelegate: delegate
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
listProps: collectionProps
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export {$982254629710d113$export$b95089534ab7c1fd as useSelectableList};
|
|
56
|
+
//# sourceMappingURL=useSelectableList.module.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {useSelectableCollection as $ae20dd8cbca75726$export$d6daf82dcd84e87c} from "./useSelectableCollection.module.js";
|
|
2
|
+
import {ListKeyboardDelegate as $2a25aae57d74318e$export$a05409b8bb224a5a} from "./ListKeyboardDelegate.module.js";
|
|
3
|
+
import {useCollator as $1aJk5$useCollator} from "@react-aria/i18n";
|
|
4
|
+
import {useMemo as $1aJk5$useMemo} from "react";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function $982254629710d113$export$b95089534ab7c1fd(props) {
|
|
21
|
+
let { selectionManager: selectionManager, collection: collection, disabledKeys: disabledKeys, ref: ref, keyboardDelegate: keyboardDelegate } = props;
|
|
22
|
+
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
23
|
+
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
24
|
+
let collator = (0, $1aJk5$useCollator)({
|
|
25
|
+
usage: 'search',
|
|
26
|
+
sensitivity: 'base'
|
|
27
|
+
});
|
|
28
|
+
let disabledBehavior = selectionManager.disabledBehavior;
|
|
29
|
+
let delegate = (0, $1aJk5$useMemo)(()=>keyboardDelegate || new (0, $2a25aae57d74318e$export$a05409b8bb224a5a)({
|
|
30
|
+
collection: collection,
|
|
31
|
+
disabledKeys: disabledKeys,
|
|
32
|
+
disabledBehavior: disabledBehavior,
|
|
33
|
+
ref: ref,
|
|
34
|
+
collator: collator
|
|
35
|
+
}), [
|
|
36
|
+
keyboardDelegate,
|
|
37
|
+
collection,
|
|
38
|
+
disabledKeys,
|
|
39
|
+
ref,
|
|
40
|
+
collator,
|
|
41
|
+
disabledBehavior
|
|
42
|
+
]);
|
|
43
|
+
let { collectionProps: collectionProps } = (0, $ae20dd8cbca75726$export$d6daf82dcd84e87c)({
|
|
44
|
+
...props,
|
|
45
|
+
ref: ref,
|
|
46
|
+
selectionManager: selectionManager,
|
|
47
|
+
keyboardDelegate: delegate
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
listProps: collectionProps
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export {$982254629710d113$export$b95089534ab7c1fd as useSelectableList};
|
|
56
|
+
//# sourceMappingURL=useSelectableList.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiCM,SAAS,0CAAkB,KAAgC;IAChE,IAAI,oBACF,gBAAgB,cAChB,UAAU,gBACV,YAAY,OACZ,GAAG,oBACH,gBAAgB,EACjB,GAAG;IAEJ,0HAA0H;IAC1H,qFAAqF;IACrF,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE;QAAC,OAAO;QAAU,aAAa;IAAM;IAChE,IAAI,mBAAmB,iBAAiB,gBAAgB;IACxD,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IACrB,oBAAoB,IAAI,CAAA,GAAA,yCAAmB,EAAE;wBAC3C;0BACA;8BACA;iBACA;sBACA;QACF,IACC;QAAC;QAAkB;QAAY;QAAc;QAAK;QAAU;KAAiB;IAEhF,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,yCAAsB,EAAE;QAC9C,GAAG,KAAK;aACR;0BACA;QACA,kBAAkB;IACpB;IAEA,OAAO;QACL,WAAW;IACb;AACF","sources":["packages/@react-aria/selection/src/useSelectableList.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaSelectableCollectionOptions, useSelectableCollection} from './useSelectableCollection';\nimport {Collection, DOMAttributes, Key, KeyboardDelegate, Node} from '@react-types/shared';\nimport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nimport {useCollator} from '@react-aria/i18n';\nimport {useMemo} from 'react';\n\nexport interface AriaSelectableListOptions extends Omit<AriaSelectableCollectionOptions, 'keyboardDelegate'> {\n /**\n * State of the collection.\n */\n collection: Collection<Node<unknown>>,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate?: KeyboardDelegate,\n /**\n * The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.\n */\n disabledKeys: Set<Key>\n}\n\nexport interface SelectableListAria {\n /**\n * Props for the option element.\n */\n listProps: DOMAttributes\n}\n\n/**\n * Handles interactions with a selectable list.\n */\nexport function useSelectableList(props: AriaSelectableListOptions): SelectableListAria {\n let {\n selectionManager,\n collection,\n disabledKeys,\n ref,\n keyboardDelegate\n } = props;\n\n // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n // When virtualized, the layout object will be passed in as a prop and override this.\n let collator = useCollator({usage: 'search', sensitivity: 'base'});\n let disabledBehavior = selectionManager.disabledBehavior;\n let delegate = useMemo(() => (\n keyboardDelegate || new ListKeyboardDelegate({\n collection,\n disabledKeys,\n disabledBehavior,\n ref,\n collator\n })\n ), [keyboardDelegate, collection, disabledKeys, ref, collator, disabledBehavior]);\n\n let {collectionProps} = useSelectableCollection({\n ...props,\n ref,\n selectionManager,\n keyboardDelegate: delegate\n });\n\n return {\n listProps: collectionProps\n };\n}\n"],"names":[],"version":3,"file":"useSelectableList.module.js.map"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var $3XJlT$react = require("react");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $parcel$export(e, n, v, s) {
|
|
5
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
$parcel$export(module.exports, "useTypeSelect", () => $a1189052f36475e8$export$e32c88dfddc6e1d8);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Controls how long to wait before clearing the typeahead buffer.
|
|
22
|
+
*/ const $a1189052f36475e8$var$TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second
|
|
23
|
+
function $a1189052f36475e8$export$e32c88dfddc6e1d8(options) {
|
|
24
|
+
let { keyboardDelegate: keyboardDelegate, selectionManager: selectionManager, onTypeSelect: onTypeSelect } = options;
|
|
25
|
+
let state = (0, $3XJlT$react.useRef)({
|
|
26
|
+
search: '',
|
|
27
|
+
timeout: null
|
|
28
|
+
}).current;
|
|
29
|
+
let onKeyDown = (e)=>{
|
|
30
|
+
let character = $a1189052f36475e8$var$getStringForKey(e.key);
|
|
31
|
+
if (!character || e.ctrlKey || e.metaKey || !e.currentTarget.contains(e.target)) return;
|
|
32
|
+
// Do not propagate the Spacebar event if it's meant to be part of the search.
|
|
33
|
+
// When we time out, the search term becomes empty, hence the check on length.
|
|
34
|
+
// Trimming is to account for the case of pressing the Spacebar more than once,
|
|
35
|
+
// which should cycle through the selection/deselection of the focused item.
|
|
36
|
+
if (character === ' ' && state.search.trim().length > 0) {
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
39
|
+
}
|
|
40
|
+
state.search += character;
|
|
41
|
+
// Use the delegate to find a key to focus.
|
|
42
|
+
// Prioritize items after the currently focused item, falling back to searching the whole list.
|
|
43
|
+
let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
|
|
44
|
+
// If no key found, search from the top.
|
|
45
|
+
if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
|
|
46
|
+
if (key != null) {
|
|
47
|
+
selectionManager.setFocusedKey(key);
|
|
48
|
+
if (onTypeSelect) onTypeSelect(key);
|
|
49
|
+
}
|
|
50
|
+
clearTimeout(state.timeout);
|
|
51
|
+
state.timeout = setTimeout(()=>{
|
|
52
|
+
state.search = '';
|
|
53
|
+
}, $a1189052f36475e8$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
typeSelectProps: {
|
|
57
|
+
// Using a capturing listener to catch the keydown event before
|
|
58
|
+
// other hooks in order to handle the Spacebar event.
|
|
59
|
+
onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function $a1189052f36475e8$var$getStringForKey(key) {
|
|
64
|
+
// If the key is of length 1, it is an ASCII value.
|
|
65
|
+
// Otherwise, if there are no ASCII characters in the key name,
|
|
66
|
+
// it is a Unicode character.
|
|
67
|
+
// See https://www.w3.org/TR/uievents-key/
|
|
68
|
+
if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=useTypeSelect.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAMD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,QAAQ;QACR,SAAS;IACX,GAAG,OAAO;IAEV,IAAI,YAAY,CAAC;QACf,IAAI,YAAY,sCAAgB,EAAE,GAAG;QACrC,IAAI,CAAC,aAAa,EAAE,OAAO,IAAI,EAAE,OAAO,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAC5E;QAGF,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,4EAA4E;QAC5E,IAAI,cAAc,OAAO,MAAM,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG;YACvD,EAAE,cAAc;YAChB,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;QAErB;QAEA,MAAM,MAAM,IAAI;QAEhB,2CAA2C;QAC3C,+FAA+F;QAC/F,IAAI,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM,EAAE,iBAAiB,UAAU;QAEpF,wCAAwC;QACxC,IAAI,OAAO,MACT,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM;QAGrD,IAAI,OAAO,MAAM;YACf,iBAAiB,aAAa,CAAC;YAC/B,IAAI,cACF,aAAa;QAEjB;QAEA,aAAa,MAAM,OAAO;QAC1B,MAAM,OAAO,GAAG,WAAW;YACzB,MAAM,MAAM,GAAG;QACjB,GAAG;IACL;IAEA,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,YAAY;QACnE;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/@react-aria/selection/src/useTypeSelect.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {KeyboardEvent, useRef} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * Called when an item is focused by typing.\n */\n onTypeSelect?: (key: Key) => void\n}\n\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef({\n search: '',\n timeout: null\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (!character || e.ctrlKey || e.metaKey || !e.currentTarget.contains(e.target as HTMLElement)) {\n return;\n }\n\n // Do not propagate the Spacebar event if it's meant to be part of the search.\n // When we time out, the search term becomes empty, hence the check on length.\n // Trimming is to account for the case of pressing the Spacebar more than once,\n // which should cycle through the selection/deselection of the focused item.\n if (character === ' ' && state.search.trim().length > 0) {\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n }\n\n state.search += character;\n\n // Use the delegate to find a key to focus.\n // Prioritize items after the currently focused item, falling back to searching the whole list.\n let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n };\n\n return {\n typeSelectProps: {\n // Using a capturing listener to catch the keydown event before\n // other hooks in order to handle the Spacebar event.\n onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null\n }\n };\n}\n\nfunction getStringForKey(key: string) {\n // If the key is of length 1, it is an ASCII value.\n // Otherwise, if there are no ASCII characters in the key name,\n // it is a Unicode character.\n // See https://www.w3.org/TR/uievents-key/\n if (key.length === 1 || !/^[A-Z]/i.test(key)) {\n return key;\n }\n\n return '';\n}\n"],"names":[],"version":3,"file":"useTypeSelect.main.js.map"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {useRef as $dAE4Y$useRef} from "react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Controls how long to wait before clearing the typeahead buffer.
|
|
16
|
+
*/ const $fb3050f43d946246$var$TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second
|
|
17
|
+
function $fb3050f43d946246$export$e32c88dfddc6e1d8(options) {
|
|
18
|
+
let { keyboardDelegate: keyboardDelegate, selectionManager: selectionManager, onTypeSelect: onTypeSelect } = options;
|
|
19
|
+
let state = (0, $dAE4Y$useRef)({
|
|
20
|
+
search: '',
|
|
21
|
+
timeout: null
|
|
22
|
+
}).current;
|
|
23
|
+
let onKeyDown = (e)=>{
|
|
24
|
+
let character = $fb3050f43d946246$var$getStringForKey(e.key);
|
|
25
|
+
if (!character || e.ctrlKey || e.metaKey || !e.currentTarget.contains(e.target)) return;
|
|
26
|
+
// Do not propagate the Spacebar event if it's meant to be part of the search.
|
|
27
|
+
// When we time out, the search term becomes empty, hence the check on length.
|
|
28
|
+
// Trimming is to account for the case of pressing the Spacebar more than once,
|
|
29
|
+
// which should cycle through the selection/deselection of the focused item.
|
|
30
|
+
if (character === ' ' && state.search.trim().length > 0) {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
33
|
+
}
|
|
34
|
+
state.search += character;
|
|
35
|
+
// Use the delegate to find a key to focus.
|
|
36
|
+
// Prioritize items after the currently focused item, falling back to searching the whole list.
|
|
37
|
+
let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
|
|
38
|
+
// If no key found, search from the top.
|
|
39
|
+
if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
|
|
40
|
+
if (key != null) {
|
|
41
|
+
selectionManager.setFocusedKey(key);
|
|
42
|
+
if (onTypeSelect) onTypeSelect(key);
|
|
43
|
+
}
|
|
44
|
+
clearTimeout(state.timeout);
|
|
45
|
+
state.timeout = setTimeout(()=>{
|
|
46
|
+
state.search = '';
|
|
47
|
+
}, $fb3050f43d946246$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
typeSelectProps: {
|
|
51
|
+
// Using a capturing listener to catch the keydown event before
|
|
52
|
+
// other hooks in order to handle the Spacebar event.
|
|
53
|
+
onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function $fb3050f43d946246$var$getStringForKey(key) {
|
|
58
|
+
// If the key is of length 1, it is an ASCII value.
|
|
59
|
+
// Otherwise, if there are no ASCII characters in the key name,
|
|
60
|
+
// it is a Unicode character.
|
|
61
|
+
// See https://www.w3.org/TR/uievents-key/
|
|
62
|
+
if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export {$fb3050f43d946246$export$e32c88dfddc6e1d8 as useTypeSelect};
|
|
68
|
+
//# sourceMappingURL=useTypeSelect.module.js.map
|