@react-aria/interactions 3.13.1 → 3.14.0
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/import.mjs +1628 -0
- package/dist/main.js +10 -14
- package/dist/main.js.map +1 -1
- package/dist/module.js +10 -14
- package/dist/module.js.map +1 -1
- package/package.json +9 -4
- package/src/useFocus.ts +1 -1
- package/src/useInteractOutside.ts +9 -4
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,1628 @@
|
|
|
1
|
+
import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, isMac as $bx7SL$isMac, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
|
|
2
|
+
import $bx7SL$react, {useRef as $bx7SL$useRef, useContext as $bx7SL$useContext, useState as $bx7SL$useState, useMemo as $bx7SL$useMemo, useEffect as $bx7SL$useEffect, useCallback as $bx7SL$useCallback} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/ /*
|
|
15
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
16
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
17
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
18
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
19
|
+
*
|
|
20
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
21
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
22
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
23
|
+
* governing permissions and limitations under the License.
|
|
24
|
+
*/
|
|
25
|
+
/*
|
|
26
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
27
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
28
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
29
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
30
|
+
*
|
|
31
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
32
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
33
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
34
|
+
* governing permissions and limitations under the License.
|
|
35
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
36
|
+
// Original licensing for the following can be found in the
|
|
37
|
+
// NOTICE file in the root directory of this source tree.
|
|
38
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
39
|
+
/*
|
|
40
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
41
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
42
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
43
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
44
|
+
*
|
|
45
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
46
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
47
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
48
|
+
* governing permissions and limitations under the License.
|
|
49
|
+
*/
|
|
50
|
+
// Note that state only matters here for iOS. Non-iOS gets user-select: none applied to the target element
|
|
51
|
+
// rather than at the document level so we just need to apply/remove user-select: none for each pressed element individually
|
|
52
|
+
let $14c0b72509d70225$var$state = "default";
|
|
53
|
+
let $14c0b72509d70225$var$savedUserSelect = "";
|
|
54
|
+
let $14c0b72509d70225$var$modifiedElementMap = new WeakMap();
|
|
55
|
+
function $14c0b72509d70225$export$16a4697467175487(target) {
|
|
56
|
+
if ((0, $bx7SL$isIOS)()) {
|
|
57
|
+
if ($14c0b72509d70225$var$state === "default") {
|
|
58
|
+
$14c0b72509d70225$var$savedUserSelect = document.documentElement.style.webkitUserSelect;
|
|
59
|
+
document.documentElement.style.webkitUserSelect = "none";
|
|
60
|
+
}
|
|
61
|
+
$14c0b72509d70225$var$state = "disabled";
|
|
62
|
+
} else if (target instanceof HTMLElement || target instanceof SVGElement) {
|
|
63
|
+
// If not iOS, store the target's original user-select and change to user-select: none
|
|
64
|
+
// Ignore state since it doesn't apply for non iOS
|
|
65
|
+
$14c0b72509d70225$var$modifiedElementMap.set(target, target.style.userSelect);
|
|
66
|
+
target.style.userSelect = "none";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
|
|
70
|
+
if ((0, $bx7SL$isIOS)()) {
|
|
71
|
+
// If the state is already default, there's nothing to do.
|
|
72
|
+
// If it is restoring, then there's no need to queue a second restore.
|
|
73
|
+
if ($14c0b72509d70225$var$state !== "disabled") return;
|
|
74
|
+
$14c0b72509d70225$var$state = "restoring";
|
|
75
|
+
// There appears to be a delay on iOS where selection still might occur
|
|
76
|
+
// after pointer up, so wait a bit before removing user-select.
|
|
77
|
+
setTimeout(()=>{
|
|
78
|
+
// Wait for any CSS transitions to complete so we don't recompute style
|
|
79
|
+
// for the whole page in the middle of the animation and cause jank.
|
|
80
|
+
(0, $bx7SL$runAfterTransition)(()=>{
|
|
81
|
+
// Avoid race conditions
|
|
82
|
+
if ($14c0b72509d70225$var$state === "restoring") {
|
|
83
|
+
if (document.documentElement.style.webkitUserSelect === "none") document.documentElement.style.webkitUserSelect = $14c0b72509d70225$var$savedUserSelect || "";
|
|
84
|
+
$14c0b72509d70225$var$savedUserSelect = "";
|
|
85
|
+
$14c0b72509d70225$var$state = "default";
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}, 300);
|
|
89
|
+
} else if (target instanceof HTMLElement || target instanceof SVGElement) // If not iOS, restore the target's original user-select if any
|
|
90
|
+
// Ignore state since it doesn't apply for non iOS
|
|
91
|
+
{
|
|
92
|
+
if (target && $14c0b72509d70225$var$modifiedElementMap.has(target)) {
|
|
93
|
+
let targetOldUserSelect = $14c0b72509d70225$var$modifiedElementMap.get(target);
|
|
94
|
+
if (target.style.userSelect === "none") target.style.userSelect = targetOldUserSelect;
|
|
95
|
+
if (target.getAttribute("style") === "") target.removeAttribute("style");
|
|
96
|
+
$14c0b72509d70225$var$modifiedElementMap.delete(target);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
105
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
107
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
108
|
+
*
|
|
109
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
110
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
111
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
112
|
+
* governing permissions and limitations under the License.
|
|
113
|
+
*/
|
|
114
|
+
const $ae1eeba8b9eafd08$export$5165eccb35aaadb5 = (0, $bx7SL$react).createContext(null);
|
|
115
|
+
$ae1eeba8b9eafd08$export$5165eccb35aaadb5.displayName = "PressResponderContext";
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
function $f6c31cce2adf654f$var$usePressResponderContext(props) {
|
|
120
|
+
// Consume context from <PressResponder> and merge with props.
|
|
121
|
+
let context = (0, $bx7SL$useContext)((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5));
|
|
122
|
+
if (context) {
|
|
123
|
+
let { register: register , ...contextProps } = context;
|
|
124
|
+
props = (0, $bx7SL$mergeProps)(contextProps, props);
|
|
125
|
+
register();
|
|
126
|
+
}
|
|
127
|
+
(0, $bx7SL$useSyncRef)(context, props.ref);
|
|
128
|
+
return props;
|
|
129
|
+
}
|
|
130
|
+
function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
131
|
+
let { onPress: onPress , onPressChange: onPressChange , onPressStart: onPressStart , onPressEnd: onPressEnd , onPressUp: onPressUp , isDisabled: isDisabled , isPressed: isPressedProp , preventFocusOnPress: preventFocusOnPress , shouldCancelOnPointerExit: shouldCancelOnPointerExit , allowTextSelectionOnPress: allowTextSelectionOnPress , // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
132
|
+
ref: _ , ...domProps } = $f6c31cce2adf654f$var$usePressResponderContext(props);
|
|
133
|
+
let propsRef = (0, $bx7SL$useRef)(null);
|
|
134
|
+
propsRef.current = {
|
|
135
|
+
onPress: onPress,
|
|
136
|
+
onPressChange: onPressChange,
|
|
137
|
+
onPressStart: onPressStart,
|
|
138
|
+
onPressEnd: onPressEnd,
|
|
139
|
+
onPressUp: onPressUp,
|
|
140
|
+
isDisabled: isDisabled,
|
|
141
|
+
shouldCancelOnPointerExit: shouldCancelOnPointerExit
|
|
142
|
+
};
|
|
143
|
+
let [isPressed, setPressed] = (0, $bx7SL$useState)(false);
|
|
144
|
+
let ref = (0, $bx7SL$useRef)({
|
|
145
|
+
isPressed: false,
|
|
146
|
+
ignoreEmulatedMouseEvents: false,
|
|
147
|
+
ignoreClickAfterPress: false,
|
|
148
|
+
didFirePressStart: false,
|
|
149
|
+
activePointerId: null,
|
|
150
|
+
target: null,
|
|
151
|
+
isOverTarget: false,
|
|
152
|
+
pointerType: null
|
|
153
|
+
});
|
|
154
|
+
let { addGlobalListener: addGlobalListener , removeAllGlobalListeners: removeAllGlobalListeners } = (0, $bx7SL$useGlobalListeners)();
|
|
155
|
+
let pressProps = (0, $bx7SL$useMemo)(()=>{
|
|
156
|
+
let state = ref.current;
|
|
157
|
+
let triggerPressStart = (originalEvent, pointerType)=>{
|
|
158
|
+
let { onPressStart: onPressStart , onPressChange: onPressChange , isDisabled: isDisabled } = propsRef.current;
|
|
159
|
+
if (isDisabled || state.didFirePressStart) return;
|
|
160
|
+
if (onPressStart) onPressStart({
|
|
161
|
+
type: "pressstart",
|
|
162
|
+
pointerType: pointerType,
|
|
163
|
+
target: originalEvent.currentTarget,
|
|
164
|
+
shiftKey: originalEvent.shiftKey,
|
|
165
|
+
metaKey: originalEvent.metaKey,
|
|
166
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
167
|
+
altKey: originalEvent.altKey
|
|
168
|
+
});
|
|
169
|
+
if (onPressChange) onPressChange(true);
|
|
170
|
+
state.didFirePressStart = true;
|
|
171
|
+
setPressed(true);
|
|
172
|
+
};
|
|
173
|
+
let triggerPressEnd = (originalEvent, pointerType, wasPressed = true)=>{
|
|
174
|
+
let { onPressEnd: onPressEnd , onPressChange: onPressChange , onPress: onPress , isDisabled: isDisabled } = propsRef.current;
|
|
175
|
+
if (!state.didFirePressStart) return;
|
|
176
|
+
state.ignoreClickAfterPress = true;
|
|
177
|
+
state.didFirePressStart = false;
|
|
178
|
+
if (onPressEnd) onPressEnd({
|
|
179
|
+
type: "pressend",
|
|
180
|
+
pointerType: pointerType,
|
|
181
|
+
target: originalEvent.currentTarget,
|
|
182
|
+
shiftKey: originalEvent.shiftKey,
|
|
183
|
+
metaKey: originalEvent.metaKey,
|
|
184
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
185
|
+
altKey: originalEvent.altKey
|
|
186
|
+
});
|
|
187
|
+
if (onPressChange) onPressChange(false);
|
|
188
|
+
setPressed(false);
|
|
189
|
+
if (onPress && wasPressed && !isDisabled) onPress({
|
|
190
|
+
type: "press",
|
|
191
|
+
pointerType: pointerType,
|
|
192
|
+
target: originalEvent.currentTarget,
|
|
193
|
+
shiftKey: originalEvent.shiftKey,
|
|
194
|
+
metaKey: originalEvent.metaKey,
|
|
195
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
196
|
+
altKey: originalEvent.altKey
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
let triggerPressUp = (originalEvent, pointerType)=>{
|
|
200
|
+
let { onPressUp: onPressUp , isDisabled: isDisabled } = propsRef.current;
|
|
201
|
+
if (isDisabled) return;
|
|
202
|
+
if (onPressUp) onPressUp({
|
|
203
|
+
type: "pressup",
|
|
204
|
+
pointerType: pointerType,
|
|
205
|
+
target: originalEvent.currentTarget,
|
|
206
|
+
shiftKey: originalEvent.shiftKey,
|
|
207
|
+
metaKey: originalEvent.metaKey,
|
|
208
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
209
|
+
altKey: originalEvent.altKey
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
let cancel = (e)=>{
|
|
213
|
+
if (state.isPressed) {
|
|
214
|
+
if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
215
|
+
state.isPressed = false;
|
|
216
|
+
state.isOverTarget = false;
|
|
217
|
+
state.activePointerId = null;
|
|
218
|
+
state.pointerType = null;
|
|
219
|
+
removeAllGlobalListeners();
|
|
220
|
+
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
let pressProps = {
|
|
224
|
+
onKeyDown (e) {
|
|
225
|
+
if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
|
|
226
|
+
if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
227
|
+
e.stopPropagation();
|
|
228
|
+
// If the event is repeating, it may have started on a different element
|
|
229
|
+
// after which focus moved to the current element. Ignore these events and
|
|
230
|
+
// only handle the first key down event.
|
|
231
|
+
if (!state.isPressed && !e.repeat) {
|
|
232
|
+
state.target = e.currentTarget;
|
|
233
|
+
state.isPressed = true;
|
|
234
|
+
triggerPressStart(e, "keyboard");
|
|
235
|
+
// Focus may move before the key up event, so register the event on the document
|
|
236
|
+
// instead of the same element where the key down event occurred.
|
|
237
|
+
addGlobalListener(document, "keyup", onKeyUp, false);
|
|
238
|
+
}
|
|
239
|
+
} else if (e.key === "Enter" && $f6c31cce2adf654f$var$isHTMLAnchorLink(e.currentTarget)) // If the target is a link, we won't have handled this above because we want the default
|
|
240
|
+
// browser behavior to open the link when pressing Enter. But we still need to prevent
|
|
241
|
+
// default so that elements above do not also handle it (e.g. table row).
|
|
242
|
+
e.stopPropagation();
|
|
243
|
+
},
|
|
244
|
+
onKeyUp (e) {
|
|
245
|
+
if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard");
|
|
246
|
+
},
|
|
247
|
+
onClick (e) {
|
|
248
|
+
if (e && !e.currentTarget.contains(e.target)) return;
|
|
249
|
+
if (e && e.button === 0) {
|
|
250
|
+
e.stopPropagation();
|
|
251
|
+
if (isDisabled) e.preventDefault();
|
|
252
|
+
// If triggered from a screen reader or by using element.click(),
|
|
253
|
+
// trigger as if it were a keyboard click.
|
|
254
|
+
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $bx7SL$isVirtualClick)(e.nativeEvent))) {
|
|
255
|
+
// Ensure the element receives focus (VoiceOver on iOS does not do this)
|
|
256
|
+
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
257
|
+
triggerPressStart(e, "virtual");
|
|
258
|
+
triggerPressUp(e, "virtual");
|
|
259
|
+
triggerPressEnd(e, "virtual");
|
|
260
|
+
}
|
|
261
|
+
state.ignoreEmulatedMouseEvents = false;
|
|
262
|
+
state.ignoreClickAfterPress = false;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
let onKeyUp = (e)=>{
|
|
267
|
+
if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
|
|
268
|
+
if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
269
|
+
e.stopPropagation();
|
|
270
|
+
state.isPressed = false;
|
|
271
|
+
let target = e.target;
|
|
272
|
+
triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
273
|
+
removeAllGlobalListeners();
|
|
274
|
+
// If the target is a link, trigger the click method to open the URL,
|
|
275
|
+
// but defer triggering pressEnd until onClick event handler.
|
|
276
|
+
if (state.target instanceof HTMLElement && state.target.contains(target) && ($f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute("role") === "link")) state.target.click();
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
if (typeof PointerEvent !== "undefined") {
|
|
280
|
+
pressProps.onPointerDown = (e)=>{
|
|
281
|
+
// Only handle left clicks, and ignore events that bubbled through portals.
|
|
282
|
+
if (e.button !== 0 || !e.currentTarget.contains(e.target)) return;
|
|
283
|
+
// iOS safari fires pointer events from VoiceOver with incorrect coordinates/target.
|
|
284
|
+
// Ignore and let the onClick handler take care of it instead.
|
|
285
|
+
// https://bugs.webkit.org/show_bug.cgi?id=222627
|
|
286
|
+
// https://bugs.webkit.org/show_bug.cgi?id=223202
|
|
287
|
+
if ((0, $bx7SL$isVirtualPointerEvent)(e.nativeEvent)) {
|
|
288
|
+
state.pointerType = "virtual";
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
// Due to browser inconsistencies, especially on mobile browsers, we prevent
|
|
292
|
+
// default on pointer down and handle focusing the pressable element ourselves.
|
|
293
|
+
if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
|
|
294
|
+
state.pointerType = e.pointerType;
|
|
295
|
+
e.stopPropagation();
|
|
296
|
+
if (!state.isPressed) {
|
|
297
|
+
state.isPressed = true;
|
|
298
|
+
state.isOverTarget = true;
|
|
299
|
+
state.activePointerId = e.pointerId;
|
|
300
|
+
state.target = e.currentTarget;
|
|
301
|
+
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
302
|
+
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
|
|
303
|
+
triggerPressStart(e, state.pointerType);
|
|
304
|
+
addGlobalListener(document, "pointermove", onPointerMove, false);
|
|
305
|
+
addGlobalListener(document, "pointerup", onPointerUp, false);
|
|
306
|
+
addGlobalListener(document, "pointercancel", onPointerCancel, false);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
pressProps.onMouseDown = (e)=>{
|
|
310
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
311
|
+
if (e.button === 0) {
|
|
312
|
+
// Chrome and Firefox on touch Windows devices require mouse down events
|
|
313
|
+
// to be canceled in addition to pointer events, or an extra asynchronous
|
|
314
|
+
// focus event will be fired.
|
|
315
|
+
if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
|
|
316
|
+
e.stopPropagation();
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
pressProps.onPointerUp = (e)=>{
|
|
320
|
+
// iOS fires pointerup with zero width and height, so check the pointerType recorded during pointerdown.
|
|
321
|
+
if (!e.currentTarget.contains(e.target) || state.pointerType === "virtual") return;
|
|
322
|
+
// Only handle left clicks
|
|
323
|
+
// Safari on iOS sometimes fires pointerup events, even
|
|
324
|
+
// when the touch isn't over the target, so double check.
|
|
325
|
+
if (e.button === 0 && $f6c31cce2adf654f$var$isOverTarget(e, e.currentTarget)) triggerPressUp(e, state.pointerType || e.pointerType);
|
|
326
|
+
};
|
|
327
|
+
// Safari on iOS < 13.2 does not implement pointerenter/pointerleave events correctly.
|
|
328
|
+
// Use pointer move events instead to implement our own hit testing.
|
|
329
|
+
// See https://bugs.webkit.org/show_bug.cgi?id=199803
|
|
330
|
+
let onPointerMove = (e)=>{
|
|
331
|
+
if (e.pointerId !== state.activePointerId) return;
|
|
332
|
+
if ($f6c31cce2adf654f$var$isOverTarget(e, state.target)) {
|
|
333
|
+
if (!state.isOverTarget) {
|
|
334
|
+
state.isOverTarget = true;
|
|
335
|
+
triggerPressStart($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType);
|
|
336
|
+
}
|
|
337
|
+
} else if (state.isOverTarget) {
|
|
338
|
+
state.isOverTarget = false;
|
|
339
|
+
triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
340
|
+
if (propsRef.current.shouldCancelOnPointerExit) cancel(e);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
let onPointerUp = (e)=>{
|
|
344
|
+
if (e.pointerId === state.activePointerId && state.isPressed && e.button === 0) {
|
|
345
|
+
if ($f6c31cce2adf654f$var$isOverTarget(e, state.target)) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType);
|
|
346
|
+
else if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
347
|
+
state.isPressed = false;
|
|
348
|
+
state.isOverTarget = false;
|
|
349
|
+
state.activePointerId = null;
|
|
350
|
+
state.pointerType = null;
|
|
351
|
+
removeAllGlobalListeners();
|
|
352
|
+
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
let onPointerCancel = (e)=>{
|
|
356
|
+
cancel(e);
|
|
357
|
+
};
|
|
358
|
+
pressProps.onDragStart = (e)=>{
|
|
359
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
360
|
+
// Safari does not call onPointerCancel when a drag starts, whereas Chrome and Firefox do.
|
|
361
|
+
cancel(e);
|
|
362
|
+
};
|
|
363
|
+
} else {
|
|
364
|
+
pressProps.onMouseDown = (e)=>{
|
|
365
|
+
// Only handle left clicks
|
|
366
|
+
if (e.button !== 0 || !e.currentTarget.contains(e.target)) return;
|
|
367
|
+
// Due to browser inconsistencies, especially on mobile browsers, we prevent
|
|
368
|
+
// default on mouse down and handle focusing the pressable element ourselves.
|
|
369
|
+
if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
|
|
370
|
+
e.stopPropagation();
|
|
371
|
+
if (state.ignoreEmulatedMouseEvents) return;
|
|
372
|
+
state.isPressed = true;
|
|
373
|
+
state.isOverTarget = true;
|
|
374
|
+
state.target = e.currentTarget;
|
|
375
|
+
state.pointerType = (0, $bx7SL$isVirtualClick)(e.nativeEvent) ? "virtual" : "mouse";
|
|
376
|
+
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
377
|
+
triggerPressStart(e, state.pointerType);
|
|
378
|
+
addGlobalListener(document, "mouseup", onMouseUp, false);
|
|
379
|
+
};
|
|
380
|
+
pressProps.onMouseEnter = (e)=>{
|
|
381
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
382
|
+
e.stopPropagation();
|
|
383
|
+
if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
|
|
384
|
+
state.isOverTarget = true;
|
|
385
|
+
triggerPressStart(e, state.pointerType);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
pressProps.onMouseLeave = (e)=>{
|
|
389
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
390
|
+
e.stopPropagation();
|
|
391
|
+
if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
|
|
392
|
+
state.isOverTarget = false;
|
|
393
|
+
triggerPressEnd(e, state.pointerType, false);
|
|
394
|
+
if (propsRef.current.shouldCancelOnPointerExit) cancel(e);
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
pressProps.onMouseUp = (e)=>{
|
|
398
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
399
|
+
if (!state.ignoreEmulatedMouseEvents && e.button === 0) triggerPressUp(e, state.pointerType);
|
|
400
|
+
};
|
|
401
|
+
let onMouseUp = (e)=>{
|
|
402
|
+
// Only handle left clicks
|
|
403
|
+
if (e.button !== 0) return;
|
|
404
|
+
state.isPressed = false;
|
|
405
|
+
removeAllGlobalListeners();
|
|
406
|
+
if (state.ignoreEmulatedMouseEvents) {
|
|
407
|
+
state.ignoreEmulatedMouseEvents = false;
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if ($f6c31cce2adf654f$var$isOverTarget(e, state.target)) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType);
|
|
411
|
+
else if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
412
|
+
state.isOverTarget = false;
|
|
413
|
+
};
|
|
414
|
+
pressProps.onTouchStart = (e)=>{
|
|
415
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
416
|
+
e.stopPropagation();
|
|
417
|
+
let touch = $f6c31cce2adf654f$var$getTouchFromEvent(e.nativeEvent);
|
|
418
|
+
if (!touch) return;
|
|
419
|
+
state.activePointerId = touch.identifier;
|
|
420
|
+
state.ignoreEmulatedMouseEvents = true;
|
|
421
|
+
state.isOverTarget = true;
|
|
422
|
+
state.isPressed = true;
|
|
423
|
+
state.target = e.currentTarget;
|
|
424
|
+
state.pointerType = "touch";
|
|
425
|
+
// Due to browser inconsistencies, especially on mobile browsers, we prevent default
|
|
426
|
+
// on the emulated mouse event and handle focusing the pressable element ourselves.
|
|
427
|
+
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
428
|
+
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
|
|
429
|
+
triggerPressStart(e, state.pointerType);
|
|
430
|
+
addGlobalListener(window, "scroll", onScroll, true);
|
|
431
|
+
};
|
|
432
|
+
pressProps.onTouchMove = (e)=>{
|
|
433
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
434
|
+
e.stopPropagation();
|
|
435
|
+
if (!state.isPressed) return;
|
|
436
|
+
let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
|
|
437
|
+
if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
|
|
438
|
+
if (!state.isOverTarget) {
|
|
439
|
+
state.isOverTarget = true;
|
|
440
|
+
triggerPressStart(e, state.pointerType);
|
|
441
|
+
}
|
|
442
|
+
} else if (state.isOverTarget) {
|
|
443
|
+
state.isOverTarget = false;
|
|
444
|
+
triggerPressEnd(e, state.pointerType, false);
|
|
445
|
+
if (propsRef.current.shouldCancelOnPointerExit) cancel(e);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
pressProps.onTouchEnd = (e)=>{
|
|
449
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
450
|
+
e.stopPropagation();
|
|
451
|
+
if (!state.isPressed) return;
|
|
452
|
+
let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
|
|
453
|
+
if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
|
|
454
|
+
triggerPressUp(e, state.pointerType);
|
|
455
|
+
triggerPressEnd(e, state.pointerType);
|
|
456
|
+
} else if (state.isOverTarget) triggerPressEnd(e, state.pointerType, false);
|
|
457
|
+
state.isPressed = false;
|
|
458
|
+
state.activePointerId = null;
|
|
459
|
+
state.isOverTarget = false;
|
|
460
|
+
state.ignoreEmulatedMouseEvents = true;
|
|
461
|
+
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
|
|
462
|
+
removeAllGlobalListeners();
|
|
463
|
+
};
|
|
464
|
+
pressProps.onTouchCancel = (e)=>{
|
|
465
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
466
|
+
e.stopPropagation();
|
|
467
|
+
if (state.isPressed) cancel(e);
|
|
468
|
+
};
|
|
469
|
+
let onScroll = (e)=>{
|
|
470
|
+
if (state.isPressed && e.target.contains(state.target)) cancel({
|
|
471
|
+
currentTarget: state.target,
|
|
472
|
+
shiftKey: false,
|
|
473
|
+
ctrlKey: false,
|
|
474
|
+
metaKey: false,
|
|
475
|
+
altKey: false
|
|
476
|
+
});
|
|
477
|
+
};
|
|
478
|
+
pressProps.onDragStart = (e)=>{
|
|
479
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
480
|
+
cancel(e);
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
return pressProps;
|
|
484
|
+
}, [
|
|
485
|
+
addGlobalListener,
|
|
486
|
+
isDisabled,
|
|
487
|
+
preventFocusOnPress,
|
|
488
|
+
removeAllGlobalListeners,
|
|
489
|
+
allowTextSelectionOnPress
|
|
490
|
+
]);
|
|
491
|
+
// Remove user-select: none in case component unmounts immediately after pressStart
|
|
492
|
+
// eslint-disable-next-line arrow-body-style
|
|
493
|
+
(0, $bx7SL$useEffect)(()=>{
|
|
494
|
+
return ()=>{
|
|
495
|
+
if (!allowTextSelectionOnPress) // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
496
|
+
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(ref.current.target);
|
|
497
|
+
};
|
|
498
|
+
}, [
|
|
499
|
+
allowTextSelectionOnPress
|
|
500
|
+
]);
|
|
501
|
+
return {
|
|
502
|
+
isPressed: isPressedProp || isPressed,
|
|
503
|
+
pressProps: (0, $bx7SL$mergeProps)(domProps, pressProps)
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function $f6c31cce2adf654f$var$isHTMLAnchorLink(target) {
|
|
507
|
+
return target.tagName === "A" && target.hasAttribute("href");
|
|
508
|
+
}
|
|
509
|
+
function $f6c31cce2adf654f$var$isValidKeyboardEvent(event, currentTarget) {
|
|
510
|
+
const { key: key , code: code } = event;
|
|
511
|
+
const element = currentTarget;
|
|
512
|
+
const role = element.getAttribute("role");
|
|
513
|
+
// Accessibility for keyboards. Space and Enter only.
|
|
514
|
+
// "Spacebar" is for IE 11
|
|
515
|
+
return (key === "Enter" || key === " " || key === "Spacebar" || code === "Space") && !(element instanceof HTMLInputElement && !$f6c31cce2adf654f$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && // A link with a valid href should be handled natively,
|
|
516
|
+
// unless it also has role='button' and was triggered using Space.
|
|
517
|
+
(!$f6c31cce2adf654f$var$isHTMLAnchorLink(element) || role === "button" && key !== "Enter") && // An element with role='link' should only trigger with Enter key
|
|
518
|
+
!(role === "link" && key !== "Enter");
|
|
519
|
+
}
|
|
520
|
+
function $f6c31cce2adf654f$var$getTouchFromEvent(event) {
|
|
521
|
+
const { targetTouches: targetTouches } = event;
|
|
522
|
+
if (targetTouches.length > 0) return targetTouches[0];
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
function $f6c31cce2adf654f$var$getTouchById(event, pointerId) {
|
|
526
|
+
const changedTouches = event.changedTouches;
|
|
527
|
+
for(let i = 0; i < changedTouches.length; i++){
|
|
528
|
+
const touch = changedTouches[i];
|
|
529
|
+
if (touch.identifier === pointerId) return touch;
|
|
530
|
+
}
|
|
531
|
+
return null;
|
|
532
|
+
}
|
|
533
|
+
function $f6c31cce2adf654f$var$createEvent(target, e) {
|
|
534
|
+
return {
|
|
535
|
+
currentTarget: target,
|
|
536
|
+
shiftKey: e.shiftKey,
|
|
537
|
+
ctrlKey: e.ctrlKey,
|
|
538
|
+
metaKey: e.metaKey,
|
|
539
|
+
altKey: e.altKey
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
function $f6c31cce2adf654f$var$getPointClientRect(point) {
|
|
543
|
+
let offsetX = point.width / 2 || point.radiusX || 0;
|
|
544
|
+
let offsetY = point.height / 2 || point.radiusY || 0;
|
|
545
|
+
return {
|
|
546
|
+
top: point.clientY - offsetY,
|
|
547
|
+
right: point.clientX + offsetX,
|
|
548
|
+
bottom: point.clientY + offsetY,
|
|
549
|
+
left: point.clientX - offsetX
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
function $f6c31cce2adf654f$var$areRectanglesOverlapping(a, b) {
|
|
553
|
+
// check if they cannot overlap on x axis
|
|
554
|
+
if (a.left > b.right || b.left > a.right) return false;
|
|
555
|
+
// check if they cannot overlap on y axis
|
|
556
|
+
if (a.top > b.bottom || b.top > a.bottom) return false;
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
function $f6c31cce2adf654f$var$isOverTarget(point, target) {
|
|
560
|
+
let rect = target.getBoundingClientRect();
|
|
561
|
+
let pointRect = $f6c31cce2adf654f$var$getPointClientRect(point);
|
|
562
|
+
return $f6c31cce2adf654f$var$areRectanglesOverlapping(rect, pointRect);
|
|
563
|
+
}
|
|
564
|
+
function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
|
|
565
|
+
// We cannot prevent default if the target is a draggable element.
|
|
566
|
+
return !(target instanceof HTMLElement) || !target.draggable;
|
|
567
|
+
}
|
|
568
|
+
function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
|
|
569
|
+
if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
|
|
570
|
+
if (target instanceof HTMLButtonElement) return target.type !== "submit";
|
|
571
|
+
return true;
|
|
572
|
+
}
|
|
573
|
+
const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
|
|
574
|
+
"checkbox",
|
|
575
|
+
"radio",
|
|
576
|
+
"range",
|
|
577
|
+
"color",
|
|
578
|
+
"file",
|
|
579
|
+
"image",
|
|
580
|
+
"button",
|
|
581
|
+
"submit",
|
|
582
|
+
"reset"
|
|
583
|
+
]);
|
|
584
|
+
function $f6c31cce2adf654f$var$isValidInputKey(target, key) {
|
|
585
|
+
// Only space should toggle checkboxes and radios, not enter.
|
|
586
|
+
return target.type === "checkbox" || target.type === "radio" ? key === " " : $f6c31cce2adf654f$var$nonTextInputTypes.has(target.type);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
const $3b117e43dc0ca95d$export$27c701ed9e449e99 = /*#__PURE__*/ (0, $bx7SL$react).forwardRef(({ children: children , ...props }, ref)=>{
|
|
592
|
+
let newRef = (0, $bx7SL$useRef)();
|
|
593
|
+
ref = ref !== null && ref !== void 0 ? ref : newRef;
|
|
594
|
+
let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
|
|
595
|
+
...props,
|
|
596
|
+
ref: ref
|
|
597
|
+
});
|
|
598
|
+
let child = (0, $bx7SL$react).Children.only(children);
|
|
599
|
+
return /*#__PURE__*/ (0, $bx7SL$react).cloneElement(child, // @ts-ignore
|
|
600
|
+
{
|
|
601
|
+
ref: ref,
|
|
602
|
+
...(0, $bx7SL$mergeProps)(child.props, pressProps)
|
|
603
|
+
});
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
/*
|
|
608
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
609
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
610
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
611
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
612
|
+
*
|
|
613
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
614
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
615
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
616
|
+
* governing permissions and limitations under the License.
|
|
617
|
+
*/
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ (0, $bx7SL$react).forwardRef(({ children: children , ...props }, ref)=>{
|
|
621
|
+
let isRegistered = (0, $bx7SL$useRef)(false);
|
|
622
|
+
let prevContext = (0, $bx7SL$useContext)((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5));
|
|
623
|
+
let context = (0, $bx7SL$mergeProps)(prevContext || {}, {
|
|
624
|
+
...props,
|
|
625
|
+
ref: ref || (prevContext === null || prevContext === void 0 ? void 0 : prevContext.ref),
|
|
626
|
+
register () {
|
|
627
|
+
isRegistered.current = true;
|
|
628
|
+
if (prevContext) prevContext.register();
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
(0, $bx7SL$useSyncRef)(prevContext, ref);
|
|
632
|
+
(0, $bx7SL$useEffect)(()=>{
|
|
633
|
+
if (!isRegistered.current) console.warn("A PressResponder was rendered without a pressable child. Either call the usePress hook, or wrap your DOM node with <Pressable> component.");
|
|
634
|
+
}, []);
|
|
635
|
+
return /*#__PURE__*/ (0, $bx7SL$react).createElement((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5).Provider, {
|
|
636
|
+
value: context
|
|
637
|
+
}, children);
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
/*
|
|
642
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
643
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
644
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
645
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
646
|
+
*
|
|
647
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
648
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
649
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
650
|
+
* governing permissions and limitations under the License.
|
|
651
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
652
|
+
// Original licensing for the following can be found in the
|
|
653
|
+
// NOTICE file in the root directory of this source tree.
|
|
654
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
655
|
+
|
|
656
|
+
/*
|
|
657
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
658
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
659
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
660
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
661
|
+
*
|
|
662
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
663
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
664
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
665
|
+
* governing permissions and limitations under the License.
|
|
666
|
+
*/
|
|
667
|
+
|
|
668
|
+
class $8a9cb279dc87e130$export$905e7fc544a71f36 {
|
|
669
|
+
isDefaultPrevented() {
|
|
670
|
+
return this.nativeEvent.defaultPrevented;
|
|
671
|
+
}
|
|
672
|
+
preventDefault() {
|
|
673
|
+
this.defaultPrevented = true;
|
|
674
|
+
this.nativeEvent.preventDefault();
|
|
675
|
+
}
|
|
676
|
+
stopPropagation() {
|
|
677
|
+
this.nativeEvent.stopPropagation();
|
|
678
|
+
this.isPropagationStopped = ()=>true;
|
|
679
|
+
}
|
|
680
|
+
isPropagationStopped() {
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
persist() {}
|
|
684
|
+
constructor(type, nativeEvent){
|
|
685
|
+
this.nativeEvent = nativeEvent;
|
|
686
|
+
this.target = nativeEvent.target;
|
|
687
|
+
this.currentTarget = nativeEvent.currentTarget;
|
|
688
|
+
this.relatedTarget = nativeEvent.relatedTarget;
|
|
689
|
+
this.bubbles = nativeEvent.bubbles;
|
|
690
|
+
this.cancelable = nativeEvent.cancelable;
|
|
691
|
+
this.defaultPrevented = nativeEvent.defaultPrevented;
|
|
692
|
+
this.eventPhase = nativeEvent.eventPhase;
|
|
693
|
+
this.isTrusted = nativeEvent.isTrusted;
|
|
694
|
+
this.timeStamp = nativeEvent.timeStamp;
|
|
695
|
+
this.type = type;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
699
|
+
let stateRef = (0, $bx7SL$useRef)({
|
|
700
|
+
isFocused: false,
|
|
701
|
+
onBlur: onBlur,
|
|
702
|
+
observer: null
|
|
703
|
+
});
|
|
704
|
+
stateRef.current.onBlur = onBlur;
|
|
705
|
+
// Clean up MutationObserver on unmount. See below.
|
|
706
|
+
// eslint-disable-next-line arrow-body-style
|
|
707
|
+
(0, $bx7SL$useLayoutEffect)(()=>{
|
|
708
|
+
const state = stateRef.current;
|
|
709
|
+
return ()=>{
|
|
710
|
+
if (state.observer) {
|
|
711
|
+
state.observer.disconnect();
|
|
712
|
+
state.observer = null;
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}, []);
|
|
716
|
+
// This function is called during a React onFocus event.
|
|
717
|
+
return (0, $bx7SL$useCallback)((e)=>{
|
|
718
|
+
// React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
|
|
719
|
+
// Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
|
|
720
|
+
// MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
|
|
721
|
+
// For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
|
|
722
|
+
if (e.target instanceof HTMLButtonElement || e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement) {
|
|
723
|
+
stateRef.current.isFocused = true;
|
|
724
|
+
let target = e.target;
|
|
725
|
+
let onBlurHandler = (e)=>{
|
|
726
|
+
var // For backward compatibility, dispatch a (fake) React synthetic event.
|
|
727
|
+
_stateRef_current, _stateRef_current_onBlur;
|
|
728
|
+
stateRef.current.isFocused = false;
|
|
729
|
+
if (target.disabled) (_stateRef_current_onBlur = (_stateRef_current = stateRef.current).onBlur) === null || _stateRef_current_onBlur === void 0 ? void 0 : _stateRef_current_onBlur.call(_stateRef_current, new $8a9cb279dc87e130$export$905e7fc544a71f36("blur", e));
|
|
730
|
+
// We no longer need the MutationObserver once the target is blurred.
|
|
731
|
+
if (stateRef.current.observer) {
|
|
732
|
+
stateRef.current.observer.disconnect();
|
|
733
|
+
stateRef.current.observer = null;
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
target.addEventListener("focusout", onBlurHandler, {
|
|
737
|
+
once: true
|
|
738
|
+
});
|
|
739
|
+
stateRef.current.observer = new MutationObserver(()=>{
|
|
740
|
+
if (stateRef.current.isFocused && target.disabled) {
|
|
741
|
+
stateRef.current.observer.disconnect();
|
|
742
|
+
target.dispatchEvent(new FocusEvent("blur"));
|
|
743
|
+
target.dispatchEvent(new FocusEvent("focusout", {
|
|
744
|
+
bubbles: true
|
|
745
|
+
}));
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
stateRef.current.observer.observe(target, {
|
|
749
|
+
attributes: true,
|
|
750
|
+
attributeFilter: [
|
|
751
|
+
"disabled"
|
|
752
|
+
]
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
}, []);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
|
|
760
|
+
let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
|
|
761
|
+
const onBlur = (0, $bx7SL$useCallback)((e)=>{
|
|
762
|
+
if (e.target === e.currentTarget) {
|
|
763
|
+
if (onBlurProp) onBlurProp(e);
|
|
764
|
+
if (onFocusChange) onFocusChange(false);
|
|
765
|
+
return true;
|
|
766
|
+
}
|
|
767
|
+
}, [
|
|
768
|
+
onBlurProp,
|
|
769
|
+
onFocusChange
|
|
770
|
+
]);
|
|
771
|
+
const onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
|
|
772
|
+
const onFocus = (0, $bx7SL$useCallback)((e)=>{
|
|
773
|
+
if (e.target === e.currentTarget) {
|
|
774
|
+
if (onFocusProp) onFocusProp(e);
|
|
775
|
+
if (onFocusChange) onFocusChange(true);
|
|
776
|
+
onSyntheticFocus(e);
|
|
777
|
+
}
|
|
778
|
+
}, [
|
|
779
|
+
onFocusChange,
|
|
780
|
+
onFocusProp,
|
|
781
|
+
onSyntheticFocus
|
|
782
|
+
]);
|
|
783
|
+
return {
|
|
784
|
+
focusProps: {
|
|
785
|
+
onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
|
|
786
|
+
onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : undefined
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
/*
|
|
793
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
794
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
795
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
796
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
797
|
+
*
|
|
798
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
799
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
800
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
801
|
+
* governing permissions and limitations under the License.
|
|
802
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
803
|
+
// Original licensing for the following can be found in the
|
|
804
|
+
// NOTICE file in the root directory of this source tree.
|
|
805
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
let $507fabe10e71c6fb$var$currentModality = null;
|
|
809
|
+
let $507fabe10e71c6fb$var$changeHandlers = new Set();
|
|
810
|
+
let $507fabe10e71c6fb$var$hasSetupGlobalListeners = false;
|
|
811
|
+
let $507fabe10e71c6fb$var$hasEventBeforeFocus = false;
|
|
812
|
+
let $507fabe10e71c6fb$var$hasBlurredWindowRecently = false;
|
|
813
|
+
// Only Tab or Esc keys will make focus visible on text input elements
|
|
814
|
+
const $507fabe10e71c6fb$var$FOCUS_VISIBLE_INPUT_KEYS = {
|
|
815
|
+
Tab: true,
|
|
816
|
+
Escape: true
|
|
817
|
+
};
|
|
818
|
+
function $507fabe10e71c6fb$var$triggerChangeHandlers(modality, e) {
|
|
819
|
+
for (let handler of $507fabe10e71c6fb$var$changeHandlers)handler(modality, e);
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus styles visible.
|
|
823
|
+
*/ function $507fabe10e71c6fb$var$isValidKey(e) {
|
|
824
|
+
// Control and Shift keys trigger when navigating back to the tab with keyboard.
|
|
825
|
+
return !(e.metaKey || !(0, $bx7SL$isMac)() && e.altKey || e.ctrlKey || e.key === "Control" || e.key === "Shift" || e.key === "Meta");
|
|
826
|
+
}
|
|
827
|
+
function $507fabe10e71c6fb$var$handleKeyboardEvent(e) {
|
|
828
|
+
$507fabe10e71c6fb$var$hasEventBeforeFocus = true;
|
|
829
|
+
if ($507fabe10e71c6fb$var$isValidKey(e)) {
|
|
830
|
+
$507fabe10e71c6fb$var$currentModality = "keyboard";
|
|
831
|
+
$507fabe10e71c6fb$var$triggerChangeHandlers("keyboard", e);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
function $507fabe10e71c6fb$var$handlePointerEvent(e) {
|
|
835
|
+
$507fabe10e71c6fb$var$currentModality = "pointer";
|
|
836
|
+
if (e.type === "mousedown" || e.type === "pointerdown") {
|
|
837
|
+
$507fabe10e71c6fb$var$hasEventBeforeFocus = true;
|
|
838
|
+
$507fabe10e71c6fb$var$triggerChangeHandlers("pointer", e);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
function $507fabe10e71c6fb$var$handleClickEvent(e) {
|
|
842
|
+
if ((0, $bx7SL$isVirtualClick)(e)) {
|
|
843
|
+
$507fabe10e71c6fb$var$hasEventBeforeFocus = true;
|
|
844
|
+
$507fabe10e71c6fb$var$currentModality = "virtual";
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
function $507fabe10e71c6fb$var$handleFocusEvent(e) {
|
|
848
|
+
// Firefox fires two extra focus events when the user first clicks into an iframe:
|
|
849
|
+
// first on the window, then on the document. We ignore these events so they don't
|
|
850
|
+
// cause keyboard focus rings to appear.
|
|
851
|
+
if (e.target === window || e.target === document) return;
|
|
852
|
+
// If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
|
|
853
|
+
// This occurs, for example, when navigating a form with the next/previous buttons on iOS.
|
|
854
|
+
if (!$507fabe10e71c6fb$var$hasEventBeforeFocus && !$507fabe10e71c6fb$var$hasBlurredWindowRecently) {
|
|
855
|
+
$507fabe10e71c6fb$var$currentModality = "virtual";
|
|
856
|
+
$507fabe10e71c6fb$var$triggerChangeHandlers("virtual", e);
|
|
857
|
+
}
|
|
858
|
+
$507fabe10e71c6fb$var$hasEventBeforeFocus = false;
|
|
859
|
+
$507fabe10e71c6fb$var$hasBlurredWindowRecently = false;
|
|
860
|
+
}
|
|
861
|
+
function $507fabe10e71c6fb$var$handleWindowBlur() {
|
|
862
|
+
// When the window is blurred, reset state. This is necessary when tabbing out of the window,
|
|
863
|
+
// for example, since a subsequent focus event won't be fired.
|
|
864
|
+
$507fabe10e71c6fb$var$hasEventBeforeFocus = false;
|
|
865
|
+
$507fabe10e71c6fb$var$hasBlurredWindowRecently = true;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Setup global event listeners to control when keyboard focus style should be visible.
|
|
869
|
+
*/ function $507fabe10e71c6fb$var$setupGlobalFocusEvents() {
|
|
870
|
+
if (typeof window === "undefined" || $507fabe10e71c6fb$var$hasSetupGlobalListeners) return;
|
|
871
|
+
// Programmatic focus() calls shouldn't affect the current input modality.
|
|
872
|
+
// However, we need to detect other cases when a focus event occurs without
|
|
873
|
+
// a preceding user event (e.g. screen reader focus). Overriding the focus
|
|
874
|
+
// method on HTMLElement.prototype is a bit hacky, but works.
|
|
875
|
+
let focus = HTMLElement.prototype.focus;
|
|
876
|
+
HTMLElement.prototype.focus = function() {
|
|
877
|
+
$507fabe10e71c6fb$var$hasEventBeforeFocus = true;
|
|
878
|
+
focus.apply(this, arguments);
|
|
879
|
+
};
|
|
880
|
+
document.addEventListener("keydown", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
|
|
881
|
+
document.addEventListener("keyup", $507fabe10e71c6fb$var$handleKeyboardEvent, true);
|
|
882
|
+
document.addEventListener("click", $507fabe10e71c6fb$var$handleClickEvent, true);
|
|
883
|
+
// Register focus events on the window so they are sure to happen
|
|
884
|
+
// before React's event listeners (registered on the document).
|
|
885
|
+
window.addEventListener("focus", $507fabe10e71c6fb$var$handleFocusEvent, true);
|
|
886
|
+
window.addEventListener("blur", $507fabe10e71c6fb$var$handleWindowBlur, false);
|
|
887
|
+
if (typeof PointerEvent !== "undefined") {
|
|
888
|
+
document.addEventListener("pointerdown", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
889
|
+
document.addEventListener("pointermove", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
890
|
+
document.addEventListener("pointerup", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
891
|
+
} else {
|
|
892
|
+
document.addEventListener("mousedown", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
893
|
+
document.addEventListener("mousemove", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
894
|
+
document.addEventListener("mouseup", $507fabe10e71c6fb$var$handlePointerEvent, true);
|
|
895
|
+
}
|
|
896
|
+
$507fabe10e71c6fb$var$hasSetupGlobalListeners = true;
|
|
897
|
+
}
|
|
898
|
+
if (typeof document !== "undefined") {
|
|
899
|
+
if (document.readyState !== "loading") $507fabe10e71c6fb$var$setupGlobalFocusEvents();
|
|
900
|
+
else document.addEventListener("DOMContentLoaded", $507fabe10e71c6fb$var$setupGlobalFocusEvents);
|
|
901
|
+
}
|
|
902
|
+
function $507fabe10e71c6fb$export$b9b3dfddab17db27() {
|
|
903
|
+
return $507fabe10e71c6fb$var$currentModality !== "pointer";
|
|
904
|
+
}
|
|
905
|
+
function $507fabe10e71c6fb$export$630ff653c5ada6a9() {
|
|
906
|
+
return $507fabe10e71c6fb$var$currentModality;
|
|
907
|
+
}
|
|
908
|
+
function $507fabe10e71c6fb$export$8397ddfc504fdb9a(modality) {
|
|
909
|
+
$507fabe10e71c6fb$var$currentModality = modality;
|
|
910
|
+
$507fabe10e71c6fb$var$triggerChangeHandlers(modality, null);
|
|
911
|
+
}
|
|
912
|
+
function $507fabe10e71c6fb$export$98e20ec92f614cfe() {
|
|
913
|
+
$507fabe10e71c6fb$var$setupGlobalFocusEvents();
|
|
914
|
+
let [modality, setModality] = (0, $bx7SL$useState)($507fabe10e71c6fb$var$currentModality);
|
|
915
|
+
(0, $bx7SL$useEffect)(()=>{
|
|
916
|
+
let handler = ()=>{
|
|
917
|
+
setModality($507fabe10e71c6fb$var$currentModality);
|
|
918
|
+
};
|
|
919
|
+
$507fabe10e71c6fb$var$changeHandlers.add(handler);
|
|
920
|
+
return ()=>{
|
|
921
|
+
$507fabe10e71c6fb$var$changeHandlers.delete(handler);
|
|
922
|
+
};
|
|
923
|
+
}, []);
|
|
924
|
+
return modality;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that
|
|
928
|
+
* focus visible style can be properly set.
|
|
929
|
+
*/ function $507fabe10e71c6fb$var$isKeyboardFocusEvent(isTextInput, modality, e) {
|
|
930
|
+
return !(isTextInput && modality === "keyboard" && e instanceof KeyboardEvent && !$507fabe10e71c6fb$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
|
|
931
|
+
}
|
|
932
|
+
function $507fabe10e71c6fb$export$ffd9e5021c1fb2d6(props = {}) {
|
|
933
|
+
let { isTextInput: isTextInput , autoFocus: autoFocus } = props;
|
|
934
|
+
let [isFocusVisibleState, setFocusVisible] = (0, $bx7SL$useState)(autoFocus || $507fabe10e71c6fb$export$b9b3dfddab17db27());
|
|
935
|
+
$507fabe10e71c6fb$export$ec71b4b83ac08ec3((isFocusVisible)=>{
|
|
936
|
+
setFocusVisible(isFocusVisible);
|
|
937
|
+
}, [
|
|
938
|
+
isTextInput
|
|
939
|
+
], {
|
|
940
|
+
isTextInput: isTextInput
|
|
941
|
+
});
|
|
942
|
+
return {
|
|
943
|
+
isFocusVisible: isFocusVisibleState
|
|
944
|
+
};
|
|
945
|
+
}
|
|
946
|
+
function $507fabe10e71c6fb$export$ec71b4b83ac08ec3(fn, deps, opts) {
|
|
947
|
+
$507fabe10e71c6fb$var$setupGlobalFocusEvents();
|
|
948
|
+
(0, $bx7SL$useEffect)(()=>{
|
|
949
|
+
let handler = (modality, e)=>{
|
|
950
|
+
if (!$507fabe10e71c6fb$var$isKeyboardFocusEvent(opts === null || opts === void 0 ? void 0 : opts.isTextInput, modality, e)) return;
|
|
951
|
+
fn($507fabe10e71c6fb$export$b9b3dfddab17db27());
|
|
952
|
+
};
|
|
953
|
+
$507fabe10e71c6fb$var$changeHandlers.add(handler);
|
|
954
|
+
return ()=>{
|
|
955
|
+
$507fabe10e71c6fb$var$changeHandlers.delete(handler);
|
|
956
|
+
};
|
|
957
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
958
|
+
}, deps);
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
/*
|
|
963
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
964
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
965
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
966
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
967
|
+
*
|
|
968
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
969
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
970
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
971
|
+
* governing permissions and limitations under the License.
|
|
972
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
973
|
+
// Original licensing for the following can be found in the
|
|
974
|
+
// NOTICE file in the root directory of this source tree.
|
|
975
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
|
|
979
|
+
let { isDisabled: isDisabled , onBlurWithin: onBlurWithin , onFocusWithin: onFocusWithin , onFocusWithinChange: onFocusWithinChange } = props;
|
|
980
|
+
let state = (0, $bx7SL$useRef)({
|
|
981
|
+
isFocusWithin: false
|
|
982
|
+
});
|
|
983
|
+
let onBlur = (0, $bx7SL$useCallback)((e)=>{
|
|
984
|
+
// We don't want to trigger onBlurWithin and then immediately onFocusWithin again
|
|
985
|
+
// when moving focus inside the element. Only trigger if the currentTarget doesn't
|
|
986
|
+
// include the relatedTarget (where focus is moving).
|
|
987
|
+
if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
|
|
988
|
+
state.current.isFocusWithin = false;
|
|
989
|
+
if (onBlurWithin) onBlurWithin(e);
|
|
990
|
+
if (onFocusWithinChange) onFocusWithinChange(false);
|
|
991
|
+
}
|
|
992
|
+
}, [
|
|
993
|
+
onBlurWithin,
|
|
994
|
+
onFocusWithinChange,
|
|
995
|
+
state
|
|
996
|
+
]);
|
|
997
|
+
let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
|
|
998
|
+
let onFocus = (0, $bx7SL$useCallback)((e)=>{
|
|
999
|
+
if (!state.current.isFocusWithin) {
|
|
1000
|
+
if (onFocusWithin) onFocusWithin(e);
|
|
1001
|
+
if (onFocusWithinChange) onFocusWithinChange(true);
|
|
1002
|
+
state.current.isFocusWithin = true;
|
|
1003
|
+
onSyntheticFocus(e);
|
|
1004
|
+
}
|
|
1005
|
+
}, [
|
|
1006
|
+
onFocusWithin,
|
|
1007
|
+
onFocusWithinChange,
|
|
1008
|
+
onSyntheticFocus
|
|
1009
|
+
]);
|
|
1010
|
+
if (isDisabled) return {
|
|
1011
|
+
focusWithinProps: {
|
|
1012
|
+
onFocus: null,
|
|
1013
|
+
onBlur: null
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
return {
|
|
1017
|
+
focusWithinProps: {
|
|
1018
|
+
onFocus: onFocus,
|
|
1019
|
+
onBlur: onBlur
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
|
|
1025
|
+
/*
|
|
1026
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1027
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1028
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1029
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1030
|
+
*
|
|
1031
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1032
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1033
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1034
|
+
* governing permissions and limitations under the License.
|
|
1035
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
1036
|
+
// Original licensing for the following can be found in the
|
|
1037
|
+
// NOTICE file in the root directory of this source tree.
|
|
1038
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
1039
|
+
|
|
1040
|
+
// iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
|
|
1041
|
+
// We want to ignore these emulated events so they do not trigger hover behavior.
|
|
1042
|
+
// See https://bugs.webkit.org/show_bug.cgi?id=214609.
|
|
1043
|
+
let $6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
|
|
1044
|
+
let $6179b936705e76d3$var$hoverCount = 0;
|
|
1045
|
+
function $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents() {
|
|
1046
|
+
$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = true;
|
|
1047
|
+
// Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter
|
|
1048
|
+
// with pointerType="mouse" immediately after onPointerUp and before onFocus. On other
|
|
1049
|
+
// devices that don't have this quirk, we don't want to ignore a mouse hover sometime in
|
|
1050
|
+
// the distant future because a user previously touched the element.
|
|
1051
|
+
setTimeout(()=>{
|
|
1052
|
+
$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents = false;
|
|
1053
|
+
}, 50);
|
|
1054
|
+
}
|
|
1055
|
+
function $6179b936705e76d3$var$handleGlobalPointerEvent(e) {
|
|
1056
|
+
if (e.pointerType === "touch") $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents();
|
|
1057
|
+
}
|
|
1058
|
+
function $6179b936705e76d3$var$setupGlobalTouchEvents() {
|
|
1059
|
+
if (typeof document === "undefined") return;
|
|
1060
|
+
if (typeof PointerEvent !== "undefined") document.addEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
|
|
1061
|
+
else document.addEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
|
|
1062
|
+
$6179b936705e76d3$var$hoverCount++;
|
|
1063
|
+
return ()=>{
|
|
1064
|
+
$6179b936705e76d3$var$hoverCount--;
|
|
1065
|
+
if ($6179b936705e76d3$var$hoverCount > 0) return;
|
|
1066
|
+
if (typeof PointerEvent !== "undefined") document.removeEventListener("pointerup", $6179b936705e76d3$var$handleGlobalPointerEvent);
|
|
1067
|
+
else document.removeEventListener("touchend", $6179b936705e76d3$var$setGlobalIgnoreEmulatedMouseEvents);
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
1071
|
+
let { onHoverStart: onHoverStart , onHoverChange: onHoverChange , onHoverEnd: onHoverEnd , isDisabled: isDisabled } = props;
|
|
1072
|
+
let [isHovered, setHovered] = (0, $bx7SL$useState)(false);
|
|
1073
|
+
let state = (0, $bx7SL$useRef)({
|
|
1074
|
+
isHovered: false,
|
|
1075
|
+
ignoreEmulatedMouseEvents: false,
|
|
1076
|
+
pointerType: "",
|
|
1077
|
+
target: null
|
|
1078
|
+
}).current;
|
|
1079
|
+
(0, $bx7SL$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
|
|
1080
|
+
let { hoverProps: hoverProps , triggerHoverEnd: triggerHoverEnd } = (0, $bx7SL$useMemo)(()=>{
|
|
1081
|
+
let triggerHoverStart = (event, pointerType)=>{
|
|
1082
|
+
state.pointerType = pointerType;
|
|
1083
|
+
if (isDisabled || pointerType === "touch" || state.isHovered || !event.currentTarget.contains(event.target)) return;
|
|
1084
|
+
state.isHovered = true;
|
|
1085
|
+
let target = event.currentTarget;
|
|
1086
|
+
state.target = target;
|
|
1087
|
+
if (onHoverStart) onHoverStart({
|
|
1088
|
+
type: "hoverstart",
|
|
1089
|
+
target: target,
|
|
1090
|
+
pointerType: pointerType
|
|
1091
|
+
});
|
|
1092
|
+
if (onHoverChange) onHoverChange(true);
|
|
1093
|
+
setHovered(true);
|
|
1094
|
+
};
|
|
1095
|
+
let triggerHoverEnd = (event, pointerType)=>{
|
|
1096
|
+
state.pointerType = "";
|
|
1097
|
+
state.target = null;
|
|
1098
|
+
if (pointerType === "touch" || !state.isHovered) return;
|
|
1099
|
+
state.isHovered = false;
|
|
1100
|
+
let target = event.currentTarget;
|
|
1101
|
+
if (onHoverEnd) onHoverEnd({
|
|
1102
|
+
type: "hoverend",
|
|
1103
|
+
target: target,
|
|
1104
|
+
pointerType: pointerType
|
|
1105
|
+
});
|
|
1106
|
+
if (onHoverChange) onHoverChange(false);
|
|
1107
|
+
setHovered(false);
|
|
1108
|
+
};
|
|
1109
|
+
let hoverProps = {};
|
|
1110
|
+
if (typeof PointerEvent !== "undefined") {
|
|
1111
|
+
hoverProps.onPointerEnter = (e)=>{
|
|
1112
|
+
if ($6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents && e.pointerType === "mouse") return;
|
|
1113
|
+
triggerHoverStart(e, e.pointerType);
|
|
1114
|
+
};
|
|
1115
|
+
hoverProps.onPointerLeave = (e)=>{
|
|
1116
|
+
if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, e.pointerType);
|
|
1117
|
+
};
|
|
1118
|
+
} else {
|
|
1119
|
+
hoverProps.onTouchStart = ()=>{
|
|
1120
|
+
state.ignoreEmulatedMouseEvents = true;
|
|
1121
|
+
};
|
|
1122
|
+
hoverProps.onMouseEnter = (e)=>{
|
|
1123
|
+
if (!state.ignoreEmulatedMouseEvents && !$6179b936705e76d3$var$globalIgnoreEmulatedMouseEvents) triggerHoverStart(e, "mouse");
|
|
1124
|
+
state.ignoreEmulatedMouseEvents = false;
|
|
1125
|
+
};
|
|
1126
|
+
hoverProps.onMouseLeave = (e)=>{
|
|
1127
|
+
if (!isDisabled && e.currentTarget.contains(e.target)) triggerHoverEnd(e, "mouse");
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
return {
|
|
1131
|
+
hoverProps: hoverProps,
|
|
1132
|
+
triggerHoverEnd: triggerHoverEnd
|
|
1133
|
+
};
|
|
1134
|
+
}, [
|
|
1135
|
+
onHoverStart,
|
|
1136
|
+
onHoverChange,
|
|
1137
|
+
onHoverEnd,
|
|
1138
|
+
isDisabled,
|
|
1139
|
+
state
|
|
1140
|
+
]);
|
|
1141
|
+
(0, $bx7SL$useEffect)(()=>{
|
|
1142
|
+
// Call the triggerHoverEnd as soon as isDisabled changes to true
|
|
1143
|
+
// Safe to call triggerHoverEnd, it will early return if we aren't currently hovering
|
|
1144
|
+
if (isDisabled) triggerHoverEnd({
|
|
1145
|
+
currentTarget: state.target
|
|
1146
|
+
}, state.pointerType);
|
|
1147
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1148
|
+
}, [
|
|
1149
|
+
isDisabled
|
|
1150
|
+
]);
|
|
1151
|
+
return {
|
|
1152
|
+
hoverProps: hoverProps,
|
|
1153
|
+
isHovered: isHovered
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
/*
|
|
1159
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1160
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1161
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1162
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1163
|
+
*
|
|
1164
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1165
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1166
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1167
|
+
* governing permissions and limitations under the License.
|
|
1168
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
1169
|
+
// Original licensing for the following can be found in the
|
|
1170
|
+
// NOTICE file in the root directory of this source tree.
|
|
1171
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
1172
|
+
|
|
1173
|
+
function $e0b6e0b68ec7f50f$export$872b660ac5a1ff98(props) {
|
|
1174
|
+
let { ref: ref , onInteractOutside: onInteractOutside , isDisabled: isDisabled , onInteractOutsideStart: onInteractOutsideStart } = props;
|
|
1175
|
+
let stateRef = (0, $bx7SL$useRef)({
|
|
1176
|
+
isPointerDown: false,
|
|
1177
|
+
ignoreEmulatedMouseEvents: false,
|
|
1178
|
+
onInteractOutside: onInteractOutside,
|
|
1179
|
+
onInteractOutsideStart: onInteractOutsideStart
|
|
1180
|
+
});
|
|
1181
|
+
let state = stateRef.current;
|
|
1182
|
+
state.onInteractOutside = onInteractOutside;
|
|
1183
|
+
state.onInteractOutsideStart = onInteractOutsideStart;
|
|
1184
|
+
(0, $bx7SL$useEffect)(()=>{
|
|
1185
|
+
if (isDisabled) return;
|
|
1186
|
+
let onPointerDown = (e)=>{
|
|
1187
|
+
if ($e0b6e0b68ec7f50f$var$isValidEvent(e, ref) && state.onInteractOutside) {
|
|
1188
|
+
if (state.onInteractOutsideStart) state.onInteractOutsideStart(e);
|
|
1189
|
+
state.isPointerDown = true;
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
// Use pointer events if available. Otherwise, fall back to mouse and touch events.
|
|
1193
|
+
if (typeof PointerEvent !== "undefined") {
|
|
1194
|
+
let onPointerUp = (e)=>{
|
|
1195
|
+
if (state.isPointerDown && state.onInteractOutside && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) state.onInteractOutside(e);
|
|
1196
|
+
state.isPointerDown = false;
|
|
1197
|
+
};
|
|
1198
|
+
// changing these to capture phase fixed combobox
|
|
1199
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
1200
|
+
document.addEventListener("pointerup", onPointerUp, true);
|
|
1201
|
+
return ()=>{
|
|
1202
|
+
document.removeEventListener("pointerdown", onPointerDown, true);
|
|
1203
|
+
document.removeEventListener("pointerup", onPointerUp, true);
|
|
1204
|
+
};
|
|
1205
|
+
} else {
|
|
1206
|
+
let onMouseUp = (e)=>{
|
|
1207
|
+
if (state.ignoreEmulatedMouseEvents) state.ignoreEmulatedMouseEvents = false;
|
|
1208
|
+
else if (state.isPointerDown && state.onInteractOutside && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) state.onInteractOutside(e);
|
|
1209
|
+
state.isPointerDown = false;
|
|
1210
|
+
};
|
|
1211
|
+
let onTouchEnd = (e)=>{
|
|
1212
|
+
state.ignoreEmulatedMouseEvents = true;
|
|
1213
|
+
if (state.onInteractOutside && state.isPointerDown && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) state.onInteractOutside(e);
|
|
1214
|
+
state.isPointerDown = false;
|
|
1215
|
+
};
|
|
1216
|
+
document.addEventListener("mousedown", onPointerDown, true);
|
|
1217
|
+
document.addEventListener("mouseup", onMouseUp, true);
|
|
1218
|
+
document.addEventListener("touchstart", onPointerDown, true);
|
|
1219
|
+
document.addEventListener("touchend", onTouchEnd, true);
|
|
1220
|
+
return ()=>{
|
|
1221
|
+
document.removeEventListener("mousedown", onPointerDown, true);
|
|
1222
|
+
document.removeEventListener("mouseup", onMouseUp, true);
|
|
1223
|
+
document.removeEventListener("touchstart", onPointerDown, true);
|
|
1224
|
+
document.removeEventListener("touchend", onTouchEnd, true);
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
}, [
|
|
1228
|
+
ref,
|
|
1229
|
+
state,
|
|
1230
|
+
isDisabled
|
|
1231
|
+
]);
|
|
1232
|
+
}
|
|
1233
|
+
function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
|
|
1234
|
+
if (event.button > 0) return false;
|
|
1235
|
+
if (event.target) {
|
|
1236
|
+
// if the event target is no longer in the document, ignore
|
|
1237
|
+
const ownerDocument = event.target.ownerDocument;
|
|
1238
|
+
if (!ownerDocument || !ownerDocument.documentElement.contains(event.target)) return false;
|
|
1239
|
+
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
1240
|
+
if (event.target.closest("[data-react-aria-top-layer]")) return false;
|
|
1241
|
+
}
|
|
1242
|
+
return ref.current && !ref.current.contains(event.target);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
/*
|
|
1247
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1248
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1249
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1250
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1251
|
+
*
|
|
1252
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1253
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1254
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1255
|
+
* governing permissions and limitations under the License.
|
|
1256
|
+
*/ /*
|
|
1257
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1258
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1259
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1260
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1261
|
+
*
|
|
1262
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1263
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1264
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1265
|
+
* governing permissions and limitations under the License.
|
|
1266
|
+
*/ function $93925083ecbb358c$export$48d1ea6320830260(handler) {
|
|
1267
|
+
if (!handler) return;
|
|
1268
|
+
let shouldStopPropagation = true;
|
|
1269
|
+
return (e)=>{
|
|
1270
|
+
let event = {
|
|
1271
|
+
...e,
|
|
1272
|
+
preventDefault () {
|
|
1273
|
+
e.preventDefault();
|
|
1274
|
+
},
|
|
1275
|
+
isDefaultPrevented () {
|
|
1276
|
+
return e.isDefaultPrevented();
|
|
1277
|
+
},
|
|
1278
|
+
stopPropagation () {
|
|
1279
|
+
console.error("stopPropagation is now the default behavior for events in React Spectrum. You can use continuePropagation() to revert this behavior.");
|
|
1280
|
+
},
|
|
1281
|
+
continuePropagation () {
|
|
1282
|
+
shouldStopPropagation = false;
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
handler(event);
|
|
1286
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
|
|
1291
|
+
function $46d819fcbaf35654$export$8f71654801c2f7cd(props) {
|
|
1292
|
+
return {
|
|
1293
|
+
keyboardProps: props.isDisabled ? {} : {
|
|
1294
|
+
onKeyDown: (0, $93925083ecbb358c$export$48d1ea6320830260)(props.onKeyDown),
|
|
1295
|
+
onKeyUp: (0, $93925083ecbb358c$export$48d1ea6320830260)(props.onKeyUp)
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
/*
|
|
1302
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1303
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1304
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1305
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1306
|
+
*
|
|
1307
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1308
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1309
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1310
|
+
* governing permissions and limitations under the License.
|
|
1311
|
+
*/
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
1315
|
+
let { onMoveStart: onMoveStart , onMove: onMove , onMoveEnd: onMoveEnd } = props;
|
|
1316
|
+
let state = (0, $bx7SL$useRef)({
|
|
1317
|
+
didMove: false,
|
|
1318
|
+
lastPosition: null,
|
|
1319
|
+
id: null
|
|
1320
|
+
});
|
|
1321
|
+
let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $bx7SL$useGlobalListeners)();
|
|
1322
|
+
let moveProps = (0, $bx7SL$useMemo)(()=>{
|
|
1323
|
+
let moveProps = {};
|
|
1324
|
+
let start = ()=>{
|
|
1325
|
+
(0, $14c0b72509d70225$export$16a4697467175487)();
|
|
1326
|
+
state.current.didMove = false;
|
|
1327
|
+
};
|
|
1328
|
+
let move = (originalEvent, pointerType, deltaX, deltaY)=>{
|
|
1329
|
+
if (deltaX === 0 && deltaY === 0) return;
|
|
1330
|
+
if (!state.current.didMove) {
|
|
1331
|
+
state.current.didMove = true;
|
|
1332
|
+
onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
|
|
1333
|
+
type: "movestart",
|
|
1334
|
+
pointerType: pointerType,
|
|
1335
|
+
shiftKey: originalEvent.shiftKey,
|
|
1336
|
+
metaKey: originalEvent.metaKey,
|
|
1337
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
1338
|
+
altKey: originalEvent.altKey
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
onMove({
|
|
1342
|
+
type: "move",
|
|
1343
|
+
pointerType: pointerType,
|
|
1344
|
+
deltaX: deltaX,
|
|
1345
|
+
deltaY: deltaY,
|
|
1346
|
+
shiftKey: originalEvent.shiftKey,
|
|
1347
|
+
metaKey: originalEvent.metaKey,
|
|
1348
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
1349
|
+
altKey: originalEvent.altKey
|
|
1350
|
+
});
|
|
1351
|
+
};
|
|
1352
|
+
let end = (originalEvent, pointerType)=>{
|
|
1353
|
+
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
|
|
1354
|
+
if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
1355
|
+
type: "moveend",
|
|
1356
|
+
pointerType: pointerType,
|
|
1357
|
+
shiftKey: originalEvent.shiftKey,
|
|
1358
|
+
metaKey: originalEvent.metaKey,
|
|
1359
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
1360
|
+
altKey: originalEvent.altKey
|
|
1361
|
+
});
|
|
1362
|
+
};
|
|
1363
|
+
if (typeof PointerEvent === "undefined") {
|
|
1364
|
+
let onMouseMove = (e)=>{
|
|
1365
|
+
if (e.button === 0) {
|
|
1366
|
+
move(e, "mouse", e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
|
|
1367
|
+
state.current.lastPosition = {
|
|
1368
|
+
pageX: e.pageX,
|
|
1369
|
+
pageY: e.pageY
|
|
1370
|
+
};
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
let onMouseUp = (e)=>{
|
|
1374
|
+
if (e.button === 0) {
|
|
1375
|
+
end(e, "mouse");
|
|
1376
|
+
removeGlobalListener(window, "mousemove", onMouseMove, false);
|
|
1377
|
+
removeGlobalListener(window, "mouseup", onMouseUp, false);
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
moveProps.onMouseDown = (e)=>{
|
|
1381
|
+
if (e.button === 0) {
|
|
1382
|
+
start();
|
|
1383
|
+
e.stopPropagation();
|
|
1384
|
+
e.preventDefault();
|
|
1385
|
+
state.current.lastPosition = {
|
|
1386
|
+
pageX: e.pageX,
|
|
1387
|
+
pageY: e.pageY
|
|
1388
|
+
};
|
|
1389
|
+
addGlobalListener(window, "mousemove", onMouseMove, false);
|
|
1390
|
+
addGlobalListener(window, "mouseup", onMouseUp, false);
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
let onTouchMove = (e)=>{
|
|
1394
|
+
let touch = [
|
|
1395
|
+
...e.changedTouches
|
|
1396
|
+
].findIndex(({ identifier: identifier })=>identifier === state.current.id);
|
|
1397
|
+
if (touch >= 0) {
|
|
1398
|
+
let { pageX: pageX , pageY: pageY } = e.changedTouches[touch];
|
|
1399
|
+
move(e, "touch", pageX - state.current.lastPosition.pageX, pageY - state.current.lastPosition.pageY);
|
|
1400
|
+
state.current.lastPosition = {
|
|
1401
|
+
pageX: pageX,
|
|
1402
|
+
pageY: pageY
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
let onTouchEnd = (e)=>{
|
|
1407
|
+
let touch = [
|
|
1408
|
+
...e.changedTouches
|
|
1409
|
+
].findIndex(({ identifier: identifier })=>identifier === state.current.id);
|
|
1410
|
+
if (touch >= 0) {
|
|
1411
|
+
end(e, "touch");
|
|
1412
|
+
state.current.id = null;
|
|
1413
|
+
removeGlobalListener(window, "touchmove", onTouchMove);
|
|
1414
|
+
removeGlobalListener(window, "touchend", onTouchEnd);
|
|
1415
|
+
removeGlobalListener(window, "touchcancel", onTouchEnd);
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
moveProps.onTouchStart = (e)=>{
|
|
1419
|
+
if (e.changedTouches.length === 0 || state.current.id != null) return;
|
|
1420
|
+
let { pageX: pageX , pageY: pageY , identifier: identifier } = e.changedTouches[0];
|
|
1421
|
+
start();
|
|
1422
|
+
e.stopPropagation();
|
|
1423
|
+
e.preventDefault();
|
|
1424
|
+
state.current.lastPosition = {
|
|
1425
|
+
pageX: pageX,
|
|
1426
|
+
pageY: pageY
|
|
1427
|
+
};
|
|
1428
|
+
state.current.id = identifier;
|
|
1429
|
+
addGlobalListener(window, "touchmove", onTouchMove, false);
|
|
1430
|
+
addGlobalListener(window, "touchend", onTouchEnd, false);
|
|
1431
|
+
addGlobalListener(window, "touchcancel", onTouchEnd, false);
|
|
1432
|
+
};
|
|
1433
|
+
} else {
|
|
1434
|
+
let onPointerMove = (e)=>{
|
|
1435
|
+
if (e.pointerId === state.current.id) {
|
|
1436
|
+
let pointerType = e.pointerType || "mouse";
|
|
1437
|
+
// Problems with PointerEvent#movementX/movementY:
|
|
1438
|
+
// 1. it is always 0 on macOS Safari.
|
|
1439
|
+
// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
|
|
1440
|
+
move(e, pointerType, e.pageX - state.current.lastPosition.pageX, e.pageY - state.current.lastPosition.pageY);
|
|
1441
|
+
state.current.lastPosition = {
|
|
1442
|
+
pageX: e.pageX,
|
|
1443
|
+
pageY: e.pageY
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
let onPointerUp = (e)=>{
|
|
1448
|
+
if (e.pointerId === state.current.id) {
|
|
1449
|
+
let pointerType = e.pointerType || "mouse";
|
|
1450
|
+
end(e, pointerType);
|
|
1451
|
+
state.current.id = null;
|
|
1452
|
+
removeGlobalListener(window, "pointermove", onPointerMove, false);
|
|
1453
|
+
removeGlobalListener(window, "pointerup", onPointerUp, false);
|
|
1454
|
+
removeGlobalListener(window, "pointercancel", onPointerUp, false);
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
moveProps.onPointerDown = (e)=>{
|
|
1458
|
+
if (e.button === 0 && state.current.id == null) {
|
|
1459
|
+
start();
|
|
1460
|
+
e.stopPropagation();
|
|
1461
|
+
e.preventDefault();
|
|
1462
|
+
state.current.lastPosition = {
|
|
1463
|
+
pageX: e.pageX,
|
|
1464
|
+
pageY: e.pageY
|
|
1465
|
+
};
|
|
1466
|
+
state.current.id = e.pointerId;
|
|
1467
|
+
addGlobalListener(window, "pointermove", onPointerMove, false);
|
|
1468
|
+
addGlobalListener(window, "pointerup", onPointerUp, false);
|
|
1469
|
+
addGlobalListener(window, "pointercancel", onPointerUp, false);
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
let triggerKeyboardMove = (e, deltaX, deltaY)=>{
|
|
1474
|
+
start();
|
|
1475
|
+
move(e, "keyboard", deltaX, deltaY);
|
|
1476
|
+
end(e, "keyboard");
|
|
1477
|
+
};
|
|
1478
|
+
moveProps.onKeyDown = (e)=>{
|
|
1479
|
+
switch(e.key){
|
|
1480
|
+
case "Left":
|
|
1481
|
+
case "ArrowLeft":
|
|
1482
|
+
e.preventDefault();
|
|
1483
|
+
e.stopPropagation();
|
|
1484
|
+
triggerKeyboardMove(e, -1, 0);
|
|
1485
|
+
break;
|
|
1486
|
+
case "Right":
|
|
1487
|
+
case "ArrowRight":
|
|
1488
|
+
e.preventDefault();
|
|
1489
|
+
e.stopPropagation();
|
|
1490
|
+
triggerKeyboardMove(e, 1, 0);
|
|
1491
|
+
break;
|
|
1492
|
+
case "Up":
|
|
1493
|
+
case "ArrowUp":
|
|
1494
|
+
e.preventDefault();
|
|
1495
|
+
e.stopPropagation();
|
|
1496
|
+
triggerKeyboardMove(e, 0, -1);
|
|
1497
|
+
break;
|
|
1498
|
+
case "Down":
|
|
1499
|
+
case "ArrowDown":
|
|
1500
|
+
e.preventDefault();
|
|
1501
|
+
e.stopPropagation();
|
|
1502
|
+
triggerKeyboardMove(e, 0, 1);
|
|
1503
|
+
break;
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
return moveProps;
|
|
1507
|
+
}, [
|
|
1508
|
+
state,
|
|
1509
|
+
onMoveStart,
|
|
1510
|
+
onMove,
|
|
1511
|
+
onMoveEnd,
|
|
1512
|
+
addGlobalListener,
|
|
1513
|
+
removeGlobalListener
|
|
1514
|
+
]);
|
|
1515
|
+
return {
|
|
1516
|
+
moveProps: moveProps
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
|
|
1522
|
+
/*
|
|
1523
|
+
* Copyright 2021 Adobe. All rights reserved.
|
|
1524
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1525
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1526
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1527
|
+
*
|
|
1528
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1529
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1530
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1531
|
+
* governing permissions and limitations under the License.
|
|
1532
|
+
*/
|
|
1533
|
+
|
|
1534
|
+
function $7d0a636d7a4dcefd$export$2123ff2b87c81ca(props, ref) {
|
|
1535
|
+
let { onScroll: onScroll , isDisabled: isDisabled } = props;
|
|
1536
|
+
let onScrollHandler = (0, $bx7SL$useCallback)((e)=>{
|
|
1537
|
+
// If the ctrlKey is pressed, this is a zoom event, do nothing.
|
|
1538
|
+
if (e.ctrlKey) return;
|
|
1539
|
+
// stop scrolling the page
|
|
1540
|
+
e.preventDefault();
|
|
1541
|
+
e.stopPropagation();
|
|
1542
|
+
if (onScroll) onScroll({
|
|
1543
|
+
deltaX: e.deltaX,
|
|
1544
|
+
deltaY: e.deltaY
|
|
1545
|
+
});
|
|
1546
|
+
}, [
|
|
1547
|
+
onScroll
|
|
1548
|
+
]);
|
|
1549
|
+
(0, $bx7SL$useEvent)(ref, "wheel", isDisabled ? null : onScrollHandler);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
|
|
1553
|
+
/*
|
|
1554
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
1555
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
1556
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
1557
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
1558
|
+
*
|
|
1559
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
1560
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
1561
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
1562
|
+
* governing permissions and limitations under the License.
|
|
1563
|
+
*/
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
const $8a26561d2877236e$var$DEFAULT_THRESHOLD = 500;
|
|
1567
|
+
function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
|
|
1568
|
+
let { isDisabled: isDisabled , onLongPressStart: onLongPressStart , onLongPressEnd: onLongPressEnd , onLongPress: onLongPress , threshold: threshold = $8a26561d2877236e$var$DEFAULT_THRESHOLD , accessibilityDescription: accessibilityDescription } = props;
|
|
1569
|
+
const timeRef = (0, $bx7SL$useRef)(null);
|
|
1570
|
+
let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $bx7SL$useGlobalListeners)();
|
|
1571
|
+
let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
|
|
1572
|
+
isDisabled: isDisabled,
|
|
1573
|
+
onPressStart (e) {
|
|
1574
|
+
if (e.pointerType === "mouse" || e.pointerType === "touch") {
|
|
1575
|
+
if (onLongPressStart) onLongPressStart({
|
|
1576
|
+
...e,
|
|
1577
|
+
type: "longpressstart"
|
|
1578
|
+
});
|
|
1579
|
+
timeRef.current = setTimeout(()=>{
|
|
1580
|
+
// Prevent other usePress handlers from also handling this event.
|
|
1581
|
+
e.target.dispatchEvent(new PointerEvent("pointercancel", {
|
|
1582
|
+
bubbles: true
|
|
1583
|
+
}));
|
|
1584
|
+
if (onLongPress) onLongPress({
|
|
1585
|
+
...e,
|
|
1586
|
+
type: "longpress"
|
|
1587
|
+
});
|
|
1588
|
+
timeRef.current = null;
|
|
1589
|
+
}, threshold);
|
|
1590
|
+
// Prevent context menu, which may be opened on long press on touch devices
|
|
1591
|
+
if (e.pointerType === "touch") {
|
|
1592
|
+
let onContextMenu = (e)=>{
|
|
1593
|
+
e.preventDefault();
|
|
1594
|
+
};
|
|
1595
|
+
addGlobalListener(e.target, "contextmenu", onContextMenu, {
|
|
1596
|
+
once: true
|
|
1597
|
+
});
|
|
1598
|
+
addGlobalListener(window, "pointerup", ()=>{
|
|
1599
|
+
// If no contextmenu event is fired quickly after pointerup, remove the handler
|
|
1600
|
+
// so future context menu events outside a long press are not prevented.
|
|
1601
|
+
setTimeout(()=>{
|
|
1602
|
+
removeGlobalListener(e.target, "contextmenu", onContextMenu);
|
|
1603
|
+
}, 30);
|
|
1604
|
+
}, {
|
|
1605
|
+
once: true
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
},
|
|
1610
|
+
onPressEnd (e) {
|
|
1611
|
+
if (timeRef.current) clearTimeout(timeRef.current);
|
|
1612
|
+
if (onLongPressEnd && (e.pointerType === "mouse" || e.pointerType === "touch")) onLongPressEnd({
|
|
1613
|
+
...e,
|
|
1614
|
+
type: "longpressend"
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
});
|
|
1618
|
+
let descriptionProps = (0, $bx7SL$useDescription)(onLongPress && !isDisabled ? accessibilityDescription : null);
|
|
1619
|
+
return {
|
|
1620
|
+
longPressProps: (0, $bx7SL$mergeProps)(pressProps, descriptionProps)
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
|
|
1626
|
+
|
|
1627
|
+
export {$3b117e43dc0ca95d$export$27c701ed9e449e99 as Pressable, $f1ab8c75478c6f73$export$3351871ee4b288b8 as PressResponder, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus, $507fabe10e71c6fb$export$b9b3dfddab17db27 as isFocusVisible, $507fabe10e71c6fb$export$630ff653c5ada6a9 as getInteractionModality, $507fabe10e71c6fb$export$8397ddfc504fdb9a as setInteractionModality, $507fabe10e71c6fb$export$98e20ec92f614cfe as useInteractionModality, $507fabe10e71c6fb$export$ffd9e5021c1fb2d6 as useFocusVisible, $507fabe10e71c6fb$export$ec71b4b83ac08ec3 as useFocusVisibleListener, $9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin, $6179b936705e76d3$export$ae780daf29e6d456 as useHover, $e0b6e0b68ec7f50f$export$872b660ac5a1ff98 as useInteractOutside, $46d819fcbaf35654$export$8f71654801c2f7cd as useKeyboard, $e8a7022cf87cba2a$export$36da96379f79f245 as useMove, $f6c31cce2adf654f$export$45712eceda6fad21 as usePress, $7d0a636d7a4dcefd$export$2123ff2b87c81ca as useScrollWheel, $8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
|
|
1628
|
+
//# sourceMappingURL=module.js.map
|