@react-aria/interactions 3.15.1 → 3.17.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 +216 -173
- package/dist/main.js +215 -172
- package/dist/main.js.map +1 -1
- package/dist/module.js +216 -173
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/PressResponder.tsx +1 -0
- package/src/useHover.ts +1 -2
- package/src/useInteractOutside.ts +25 -22
- package/src/useLongPress.ts +1 -0
- package/src/useMove.ts +43 -41
- package/src/usePress.ts +188 -129
- package/src/utils.ts +10 -7
package/dist/import.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
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";
|
|
1
|
+
import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, useEffectEvent as $bx7SL$useEffectEvent, 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
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
|
+
import {_ as $bx7SL$_} from "@swc/helpers/_/_class_private_field_get";
|
|
4
|
+
import {_ as $bx7SL$_1} from "@swc/helpers/_/_class_private_field_init";
|
|
5
|
+
import {_ as $bx7SL$_2} from "@swc/helpers/_/_class_private_field_set";
|
|
3
6
|
import {useIsSSR as $bx7SL$useIsSSR} from "@react-aria/ssr";
|
|
4
7
|
|
|
5
8
|
/*
|
|
@@ -37,6 +40,9 @@ import {useIsSSR as $bx7SL$useIsSSR} from "@react-aria/ssr";
|
|
|
37
40
|
// Original licensing for the following can be found in the
|
|
38
41
|
// NOTICE file in the root directory of this source tree.
|
|
39
42
|
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
40
46
|
/*
|
|
41
47
|
* Copyright 2020 Adobe. All rights reserved.
|
|
42
48
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -128,19 +134,32 @@ function $f6c31cce2adf654f$var$usePressResponderContext(props) {
|
|
|
128
134
|
(0, $bx7SL$useSyncRef)(context, props.ref);
|
|
129
135
|
return props;
|
|
130
136
|
}
|
|
137
|
+
var $f6c31cce2adf654f$var$_shouldStopPropagation = /*#__PURE__*/ new WeakMap();
|
|
138
|
+
class $f6c31cce2adf654f$var$PressEvent {
|
|
139
|
+
continuePropagation() {
|
|
140
|
+
(0, $bx7SL$_2)(this, $f6c31cce2adf654f$var$_shouldStopPropagation, false);
|
|
141
|
+
}
|
|
142
|
+
get shouldStopPropagation() {
|
|
143
|
+
return (0, $bx7SL$_)(this, $f6c31cce2adf654f$var$_shouldStopPropagation);
|
|
144
|
+
}
|
|
145
|
+
constructor(type, pointerType, originalEvent){
|
|
146
|
+
(0, $bx7SL$_1)(this, $f6c31cce2adf654f$var$_shouldStopPropagation, {
|
|
147
|
+
writable: true,
|
|
148
|
+
value: void 0
|
|
149
|
+
});
|
|
150
|
+
(0, $bx7SL$_2)(this, $f6c31cce2adf654f$var$_shouldStopPropagation, true);
|
|
151
|
+
this.type = type;
|
|
152
|
+
this.pointerType = pointerType;
|
|
153
|
+
this.target = originalEvent.currentTarget;
|
|
154
|
+
this.shiftKey = originalEvent.shiftKey;
|
|
155
|
+
this.metaKey = originalEvent.metaKey;
|
|
156
|
+
this.ctrlKey = originalEvent.ctrlKey;
|
|
157
|
+
this.altKey = originalEvent.altKey;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
131
160
|
function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
132
161
|
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
|
|
133
162
|
ref: _ , ...domProps } = $f6c31cce2adf654f$var$usePressResponderContext(props);
|
|
134
|
-
let propsRef = (0, $bx7SL$useRef)(null);
|
|
135
|
-
propsRef.current = {
|
|
136
|
-
onPress: onPress,
|
|
137
|
-
onPressChange: onPressChange,
|
|
138
|
-
onPressStart: onPressStart,
|
|
139
|
-
onPressEnd: onPressEnd,
|
|
140
|
-
onPressUp: onPressUp,
|
|
141
|
-
isDisabled: isDisabled,
|
|
142
|
-
shouldCancelOnPointerExit: shouldCancelOnPointerExit
|
|
143
|
-
};
|
|
144
163
|
let [isPressed, setPressed] = (0, $bx7SL$useState)(false);
|
|
145
164
|
let ref = (0, $bx7SL$useRef)({
|
|
146
165
|
isPressed: false,
|
|
@@ -153,90 +172,83 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
153
172
|
pointerType: null
|
|
154
173
|
});
|
|
155
174
|
let { addGlobalListener: addGlobalListener , removeAllGlobalListeners: removeAllGlobalListeners } = (0, $bx7SL$useGlobalListeners)();
|
|
175
|
+
let triggerPressStart = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType)=>{
|
|
176
|
+
let state = ref.current;
|
|
177
|
+
if (isDisabled || state.didFirePressStart) return;
|
|
178
|
+
let shouldStopPropagation = true;
|
|
179
|
+
if (onPressStart) {
|
|
180
|
+
let event = new $f6c31cce2adf654f$var$PressEvent("pressstart", pointerType, originalEvent);
|
|
181
|
+
onPressStart(event);
|
|
182
|
+
shouldStopPropagation = event.shouldStopPropagation;
|
|
183
|
+
}
|
|
184
|
+
if (onPressChange) onPressChange(true);
|
|
185
|
+
state.didFirePressStart = true;
|
|
186
|
+
setPressed(true);
|
|
187
|
+
return shouldStopPropagation;
|
|
188
|
+
});
|
|
189
|
+
let triggerPressEnd = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType, wasPressed = true)=>{
|
|
190
|
+
let state = ref.current;
|
|
191
|
+
if (!state.didFirePressStart) return;
|
|
192
|
+
state.ignoreClickAfterPress = true;
|
|
193
|
+
state.didFirePressStart = false;
|
|
194
|
+
let shouldStopPropagation = true;
|
|
195
|
+
if (onPressEnd) {
|
|
196
|
+
let event = new $f6c31cce2adf654f$var$PressEvent("pressend", pointerType, originalEvent);
|
|
197
|
+
onPressEnd(event);
|
|
198
|
+
shouldStopPropagation = event.shouldStopPropagation;
|
|
199
|
+
}
|
|
200
|
+
if (onPressChange) onPressChange(false);
|
|
201
|
+
setPressed(false);
|
|
202
|
+
if (onPress && wasPressed && !isDisabled) {
|
|
203
|
+
let event = new $f6c31cce2adf654f$var$PressEvent("press", pointerType, originalEvent);
|
|
204
|
+
onPress(event);
|
|
205
|
+
shouldStopPropagation && (shouldStopPropagation = event.shouldStopPropagation);
|
|
206
|
+
}
|
|
207
|
+
return shouldStopPropagation;
|
|
208
|
+
});
|
|
209
|
+
let triggerPressUp = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType)=>{
|
|
210
|
+
if (isDisabled) return;
|
|
211
|
+
if (onPressUp) {
|
|
212
|
+
let event = new $f6c31cce2adf654f$var$PressEvent("pressup", pointerType, originalEvent);
|
|
213
|
+
onPressUp(event);
|
|
214
|
+
return event.shouldStopPropagation;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
});
|
|
218
|
+
let cancel = (0, $bx7SL$useEffectEvent)((e)=>{
|
|
219
|
+
let state = ref.current;
|
|
220
|
+
if (state.isPressed) {
|
|
221
|
+
if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
222
|
+
state.isPressed = false;
|
|
223
|
+
state.isOverTarget = false;
|
|
224
|
+
state.activePointerId = null;
|
|
225
|
+
state.pointerType = null;
|
|
226
|
+
removeAllGlobalListeners();
|
|
227
|
+
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
let cancelOnPointerExit = (0, $bx7SL$useEffectEvent)((e)=>{
|
|
231
|
+
if (shouldCancelOnPointerExit) cancel(e);
|
|
232
|
+
});
|
|
156
233
|
let pressProps = (0, $bx7SL$useMemo)(()=>{
|
|
157
234
|
let state = ref.current;
|
|
158
|
-
let triggerPressStart = (originalEvent, pointerType)=>{
|
|
159
|
-
let { onPressStart: onPressStart , onPressChange: onPressChange , isDisabled: isDisabled } = propsRef.current;
|
|
160
|
-
if (isDisabled || state.didFirePressStart) return;
|
|
161
|
-
if (onPressStart) onPressStart({
|
|
162
|
-
type: "pressstart",
|
|
163
|
-
pointerType: pointerType,
|
|
164
|
-
target: originalEvent.currentTarget,
|
|
165
|
-
shiftKey: originalEvent.shiftKey,
|
|
166
|
-
metaKey: originalEvent.metaKey,
|
|
167
|
-
ctrlKey: originalEvent.ctrlKey,
|
|
168
|
-
altKey: originalEvent.altKey
|
|
169
|
-
});
|
|
170
|
-
if (onPressChange) onPressChange(true);
|
|
171
|
-
state.didFirePressStart = true;
|
|
172
|
-
setPressed(true);
|
|
173
|
-
};
|
|
174
|
-
let triggerPressEnd = (originalEvent, pointerType, wasPressed = true)=>{
|
|
175
|
-
let { onPressEnd: onPressEnd , onPressChange: onPressChange , onPress: onPress , isDisabled: isDisabled } = propsRef.current;
|
|
176
|
-
if (!state.didFirePressStart) return;
|
|
177
|
-
state.ignoreClickAfterPress = true;
|
|
178
|
-
state.didFirePressStart = false;
|
|
179
|
-
if (onPressEnd) onPressEnd({
|
|
180
|
-
type: "pressend",
|
|
181
|
-
pointerType: pointerType,
|
|
182
|
-
target: originalEvent.currentTarget,
|
|
183
|
-
shiftKey: originalEvent.shiftKey,
|
|
184
|
-
metaKey: originalEvent.metaKey,
|
|
185
|
-
ctrlKey: originalEvent.ctrlKey,
|
|
186
|
-
altKey: originalEvent.altKey
|
|
187
|
-
});
|
|
188
|
-
if (onPressChange) onPressChange(false);
|
|
189
|
-
setPressed(false);
|
|
190
|
-
if (onPress && wasPressed && !isDisabled) onPress({
|
|
191
|
-
type: "press",
|
|
192
|
-
pointerType: pointerType,
|
|
193
|
-
target: originalEvent.currentTarget,
|
|
194
|
-
shiftKey: originalEvent.shiftKey,
|
|
195
|
-
metaKey: originalEvent.metaKey,
|
|
196
|
-
ctrlKey: originalEvent.ctrlKey,
|
|
197
|
-
altKey: originalEvent.altKey
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
let triggerPressUp = (originalEvent, pointerType)=>{
|
|
201
|
-
let { onPressUp: onPressUp , isDisabled: isDisabled } = propsRef.current;
|
|
202
|
-
if (isDisabled) return;
|
|
203
|
-
if (onPressUp) onPressUp({
|
|
204
|
-
type: "pressup",
|
|
205
|
-
pointerType: pointerType,
|
|
206
|
-
target: originalEvent.currentTarget,
|
|
207
|
-
shiftKey: originalEvent.shiftKey,
|
|
208
|
-
metaKey: originalEvent.metaKey,
|
|
209
|
-
ctrlKey: originalEvent.ctrlKey,
|
|
210
|
-
altKey: originalEvent.altKey
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
let cancel = (e)=>{
|
|
214
|
-
if (state.isPressed) {
|
|
215
|
-
if (state.isOverTarget) triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
216
|
-
state.isPressed = false;
|
|
217
|
-
state.isOverTarget = false;
|
|
218
|
-
state.activePointerId = null;
|
|
219
|
-
state.pointerType = null;
|
|
220
|
-
removeAllGlobalListeners();
|
|
221
|
-
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$b0d6fa1ab32e3295)(state.target);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
235
|
let pressProps = {
|
|
225
236
|
onKeyDown (e) {
|
|
226
237
|
if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
|
|
227
238
|
if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
228
|
-
e.stopPropagation();
|
|
229
239
|
// If the event is repeating, it may have started on a different element
|
|
230
240
|
// after which focus moved to the current element. Ignore these events and
|
|
231
241
|
// only handle the first key down event.
|
|
242
|
+
let shouldStopPropagation = true;
|
|
232
243
|
if (!state.isPressed && !e.repeat) {
|
|
233
244
|
state.target = e.currentTarget;
|
|
234
245
|
state.isPressed = true;
|
|
235
|
-
triggerPressStart(e, "keyboard");
|
|
246
|
+
shouldStopPropagation = triggerPressStart(e, "keyboard");
|
|
236
247
|
// Focus may move before the key up event, so register the event on the document
|
|
237
248
|
// instead of the same element where the key down event occurred.
|
|
238
249
|
addGlobalListener(document, "keyup", onKeyUp, false);
|
|
239
250
|
}
|
|
251
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
240
252
|
} 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
|
|
241
253
|
// browser behavior to open the link when pressing Enter. But we still need to prevent
|
|
242
254
|
// default so that elements above do not also handle it (e.g. table row).
|
|
@@ -248,30 +260,32 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
248
260
|
onClick (e) {
|
|
249
261
|
if (e && !e.currentTarget.contains(e.target)) return;
|
|
250
262
|
if (e && e.button === 0) {
|
|
251
|
-
|
|
263
|
+
let shouldStopPropagation = true;
|
|
252
264
|
if (isDisabled) e.preventDefault();
|
|
253
265
|
// If triggered from a screen reader or by using element.click(),
|
|
254
266
|
// trigger as if it were a keyboard click.
|
|
255
267
|
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === "virtual" || (0, $bx7SL$isVirtualClick)(e.nativeEvent))) {
|
|
256
268
|
// Ensure the element receives focus (VoiceOver on iOS does not do this)
|
|
257
269
|
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
258
|
-
triggerPressStart(e, "virtual");
|
|
259
|
-
triggerPressUp(e, "virtual");
|
|
260
|
-
triggerPressEnd(e, "virtual");
|
|
270
|
+
let stopPressStart = triggerPressStart(e, "virtual");
|
|
271
|
+
let stopPressUp = triggerPressUp(e, "virtual");
|
|
272
|
+
let stopPressEnd = triggerPressEnd(e, "virtual");
|
|
273
|
+
shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;
|
|
261
274
|
}
|
|
262
275
|
state.ignoreEmulatedMouseEvents = false;
|
|
263
276
|
state.ignoreClickAfterPress = false;
|
|
277
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
264
278
|
}
|
|
265
279
|
}
|
|
266
280
|
};
|
|
267
281
|
let onKeyUp = (e)=>{
|
|
268
282
|
if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
|
|
269
283
|
if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
|
|
270
|
-
e.stopPropagation();
|
|
271
284
|
state.isPressed = false;
|
|
272
285
|
let target = e.target;
|
|
273
|
-
triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
286
|
+
let shouldStopPropagation = triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), "keyboard", state.target.contains(target));
|
|
274
287
|
removeAllGlobalListeners();
|
|
288
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
275
289
|
// If the target is a link, trigger the click method to open the URL,
|
|
276
290
|
// but defer triggering pressEnd until onClick event handler.
|
|
277
291
|
if (state.target instanceof HTMLElement && state.target.contains(target) && ($f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute("role") === "link")) state.target.click();
|
|
@@ -293,7 +307,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
293
307
|
// default on pointer down and handle focusing the pressable element ourselves.
|
|
294
308
|
if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
|
|
295
309
|
state.pointerType = e.pointerType;
|
|
296
|
-
|
|
310
|
+
let shouldStopPropagation = true;
|
|
297
311
|
if (!state.isPressed) {
|
|
298
312
|
state.isPressed = true;
|
|
299
313
|
state.isOverTarget = true;
|
|
@@ -301,11 +315,12 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
301
315
|
state.target = e.currentTarget;
|
|
302
316
|
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
303
317
|
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
|
|
304
|
-
triggerPressStart(e, state.pointerType);
|
|
318
|
+
shouldStopPropagation = triggerPressStart(e, state.pointerType);
|
|
305
319
|
addGlobalListener(document, "pointermove", onPointerMove, false);
|
|
306
320
|
addGlobalListener(document, "pointerup", onPointerUp, false);
|
|
307
321
|
addGlobalListener(document, "pointercancel", onPointerCancel, false);
|
|
308
322
|
}
|
|
323
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
309
324
|
};
|
|
310
325
|
pressProps.onMouseDown = (e)=>{
|
|
311
326
|
if (!e.currentTarget.contains(e.target)) return;
|
|
@@ -338,7 +353,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
338
353
|
} else if (state.isOverTarget) {
|
|
339
354
|
state.isOverTarget = false;
|
|
340
355
|
triggerPressEnd($f6c31cce2adf654f$var$createEvent(state.target, e), state.pointerType, false);
|
|
341
|
-
|
|
356
|
+
cancelOnPointerExit(e);
|
|
342
357
|
}
|
|
343
358
|
};
|
|
344
359
|
let onPointerUp = (e)=>{
|
|
@@ -368,32 +383,37 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
368
383
|
// Due to browser inconsistencies, especially on mobile browsers, we prevent
|
|
369
384
|
// default on mouse down and handle focusing the pressable element ourselves.
|
|
370
385
|
if ($f6c31cce2adf654f$var$shouldPreventDefault(e.currentTarget)) e.preventDefault();
|
|
371
|
-
|
|
372
|
-
|
|
386
|
+
if (state.ignoreEmulatedMouseEvents) {
|
|
387
|
+
e.stopPropagation();
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
373
390
|
state.isPressed = true;
|
|
374
391
|
state.isOverTarget = true;
|
|
375
392
|
state.target = e.currentTarget;
|
|
376
393
|
state.pointerType = (0, $bx7SL$isVirtualClick)(e.nativeEvent) ? "virtual" : "mouse";
|
|
377
394
|
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
378
|
-
triggerPressStart(e, state.pointerType);
|
|
395
|
+
let shouldStopPropagation = triggerPressStart(e, state.pointerType);
|
|
396
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
379
397
|
addGlobalListener(document, "mouseup", onMouseUp, false);
|
|
380
398
|
};
|
|
381
399
|
pressProps.onMouseEnter = (e)=>{
|
|
382
400
|
if (!e.currentTarget.contains(e.target)) return;
|
|
383
|
-
|
|
401
|
+
let shouldStopPropagation = true;
|
|
384
402
|
if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
|
|
385
403
|
state.isOverTarget = true;
|
|
386
|
-
triggerPressStart(e, state.pointerType);
|
|
404
|
+
shouldStopPropagation = triggerPressStart(e, state.pointerType);
|
|
387
405
|
}
|
|
406
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
388
407
|
};
|
|
389
408
|
pressProps.onMouseLeave = (e)=>{
|
|
390
409
|
if (!e.currentTarget.contains(e.target)) return;
|
|
391
|
-
|
|
410
|
+
let shouldStopPropagation = true;
|
|
392
411
|
if (state.isPressed && !state.ignoreEmulatedMouseEvents) {
|
|
393
412
|
state.isOverTarget = false;
|
|
394
|
-
triggerPressEnd(e, state.pointerType, false);
|
|
395
|
-
|
|
413
|
+
shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
|
|
414
|
+
cancelOnPointerExit(e);
|
|
396
415
|
}
|
|
416
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
397
417
|
};
|
|
398
418
|
pressProps.onMouseUp = (e)=>{
|
|
399
419
|
if (!e.currentTarget.contains(e.target)) return;
|
|
@@ -414,7 +434,6 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
414
434
|
};
|
|
415
435
|
pressProps.onTouchStart = (e)=>{
|
|
416
436
|
if (!e.currentTarget.contains(e.target)) return;
|
|
417
|
-
e.stopPropagation();
|
|
418
437
|
let touch = $f6c31cce2adf654f$var$getTouchFromEvent(e.nativeEvent);
|
|
419
438
|
if (!touch) return;
|
|
420
439
|
state.activePointerId = touch.identifier;
|
|
@@ -427,34 +446,43 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
427
446
|
// on the emulated mouse event and handle focusing the pressable element ourselves.
|
|
428
447
|
if (!isDisabled && !preventFocusOnPress) (0, $bx7SL$focusWithoutScrolling)(e.currentTarget);
|
|
429
448
|
if (!allowTextSelectionOnPress) (0, $14c0b72509d70225$export$16a4697467175487)(state.target);
|
|
430
|
-
triggerPressStart(e, state.pointerType);
|
|
449
|
+
let shouldStopPropagation = triggerPressStart(e, state.pointerType);
|
|
450
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
431
451
|
addGlobalListener(window, "scroll", onScroll, true);
|
|
432
452
|
};
|
|
433
453
|
pressProps.onTouchMove = (e)=>{
|
|
434
454
|
if (!e.currentTarget.contains(e.target)) return;
|
|
435
|
-
|
|
436
|
-
|
|
455
|
+
if (!state.isPressed) {
|
|
456
|
+
e.stopPropagation();
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
437
459
|
let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
|
|
460
|
+
let shouldStopPropagation = true;
|
|
438
461
|
if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
|
|
439
462
|
if (!state.isOverTarget) {
|
|
440
463
|
state.isOverTarget = true;
|
|
441
|
-
triggerPressStart(e, state.pointerType);
|
|
464
|
+
shouldStopPropagation = triggerPressStart(e, state.pointerType);
|
|
442
465
|
}
|
|
443
466
|
} else if (state.isOverTarget) {
|
|
444
467
|
state.isOverTarget = false;
|
|
445
|
-
triggerPressEnd(e, state.pointerType, false);
|
|
446
|
-
|
|
468
|
+
shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
|
|
469
|
+
cancelOnPointerExit(e);
|
|
447
470
|
}
|
|
471
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
448
472
|
};
|
|
449
473
|
pressProps.onTouchEnd = (e)=>{
|
|
450
474
|
if (!e.currentTarget.contains(e.target)) return;
|
|
451
|
-
|
|
452
|
-
|
|
475
|
+
if (!state.isPressed) {
|
|
476
|
+
e.stopPropagation();
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
453
479
|
let touch = $f6c31cce2adf654f$var$getTouchById(e.nativeEvent, state.activePointerId);
|
|
480
|
+
let shouldStopPropagation = true;
|
|
454
481
|
if (touch && $f6c31cce2adf654f$var$isOverTarget(touch, e.currentTarget)) {
|
|
455
482
|
triggerPressUp(e, state.pointerType);
|
|
456
|
-
triggerPressEnd(e, state.pointerType);
|
|
457
|
-
} else if (state.isOverTarget) triggerPressEnd(e, state.pointerType, false);
|
|
483
|
+
shouldStopPropagation = triggerPressEnd(e, state.pointerType);
|
|
484
|
+
} else if (state.isOverTarget) shouldStopPropagation = triggerPressEnd(e, state.pointerType, false);
|
|
485
|
+
if (shouldStopPropagation) e.stopPropagation();
|
|
458
486
|
state.isPressed = false;
|
|
459
487
|
state.activePointerId = null;
|
|
460
488
|
state.isOverTarget = false;
|
|
@@ -487,7 +515,12 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
|
|
|
487
515
|
isDisabled,
|
|
488
516
|
preventFocusOnPress,
|
|
489
517
|
removeAllGlobalListeners,
|
|
490
|
-
allowTextSelectionOnPress
|
|
518
|
+
allowTextSelectionOnPress,
|
|
519
|
+
cancel,
|
|
520
|
+
cancelOnPointerExit,
|
|
521
|
+
triggerPressEnd,
|
|
522
|
+
triggerPressStart,
|
|
523
|
+
triggerPressUp
|
|
491
524
|
]);
|
|
492
525
|
// Remove user-select: none in case component unmounts immediately after pressStart
|
|
493
526
|
// eslint-disable-next-line arrow-body-style
|
|
@@ -568,7 +601,7 @@ function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
|
|
|
568
601
|
}
|
|
569
602
|
function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
|
|
570
603
|
if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
|
|
571
|
-
if (target instanceof HTMLButtonElement) return target.type !== "submit";
|
|
604
|
+
if (target instanceof HTMLButtonElement) return target.type !== "submit" && target.type !== "reset";
|
|
572
605
|
return true;
|
|
573
606
|
}
|
|
574
607
|
const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
|
|
@@ -631,7 +664,10 @@ const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ (0, $bx7SL$react
|
|
|
631
664
|
});
|
|
632
665
|
(0, $bx7SL$useSyncRef)(prevContext, ref);
|
|
633
666
|
(0, $bx7SL$useEffect)(()=>{
|
|
634
|
-
if (!isRegistered.current)
|
|
667
|
+
if (!isRegistered.current) {
|
|
668
|
+
console.warn("A PressResponder was rendered without a pressable child. Either call the usePress hook, or wrap your DOM node with <Pressable> component.");
|
|
669
|
+
isRegistered.current = true; // only warn once in strict mode.
|
|
670
|
+
}
|
|
635
671
|
}, []);
|
|
636
672
|
return /*#__PURE__*/ (0, $bx7SL$react).createElement((0, $ae1eeba8b9eafd08$export$5165eccb35aaadb5).Provider, {
|
|
637
673
|
value: context
|
|
@@ -699,10 +735,8 @@ class $8a9cb279dc87e130$export$905e7fc544a71f36 {
|
|
|
699
735
|
function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
700
736
|
let stateRef = (0, $bx7SL$useRef)({
|
|
701
737
|
isFocused: false,
|
|
702
|
-
onBlur: onBlur,
|
|
703
738
|
observer: null
|
|
704
739
|
});
|
|
705
|
-
stateRef.current.onBlur = onBlur;
|
|
706
740
|
// Clean up MutationObserver on unmount. See below.
|
|
707
741
|
// eslint-disable-next-line arrow-body-style
|
|
708
742
|
(0, $bx7SL$useLayoutEffect)(()=>{
|
|
@@ -714,6 +748,9 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
|
714
748
|
}
|
|
715
749
|
};
|
|
716
750
|
}, []);
|
|
751
|
+
let dispatchBlur = (0, $bx7SL$useEffectEvent)((e)=>{
|
|
752
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
753
|
+
});
|
|
717
754
|
// This function is called during a React onFocus event.
|
|
718
755
|
return (0, $bx7SL$useCallback)((e)=>{
|
|
719
756
|
// React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
|
|
@@ -724,10 +761,9 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
|
724
761
|
stateRef.current.isFocused = true;
|
|
725
762
|
let target = e.target;
|
|
726
763
|
let onBlurHandler = (e)=>{
|
|
727
|
-
var // For backward compatibility, dispatch a (fake) React synthetic event.
|
|
728
|
-
_stateRef_current, _stateRef_current_onBlur;
|
|
729
764
|
stateRef.current.isFocused = false;
|
|
730
|
-
if (target.disabled)
|
|
765
|
+
if (target.disabled) // For backward compatibility, dispatch a (fake) React synthetic event.
|
|
766
|
+
dispatchBlur(new $8a9cb279dc87e130$export$905e7fc544a71f36("blur", e));
|
|
731
767
|
// We no longer need the MutationObserver once the target is blurred.
|
|
732
768
|
if (stateRef.current.observer) {
|
|
733
769
|
stateRef.current.observer.disconnect();
|
|
@@ -740,9 +776,13 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
|
740
776
|
stateRef.current.observer = new MutationObserver(()=>{
|
|
741
777
|
if (stateRef.current.isFocused && target.disabled) {
|
|
742
778
|
stateRef.current.observer.disconnect();
|
|
743
|
-
target.
|
|
779
|
+
let relatedTargetEl = target === document.activeElement ? null : document.activeElement;
|
|
780
|
+
target.dispatchEvent(new FocusEvent("blur", {
|
|
781
|
+
relatedTarget: relatedTargetEl
|
|
782
|
+
}));
|
|
744
783
|
target.dispatchEvent(new FocusEvent("focusout", {
|
|
745
|
-
bubbles: true
|
|
784
|
+
bubbles: true,
|
|
785
|
+
relatedTarget: relatedTargetEl
|
|
746
786
|
}));
|
|
747
787
|
}
|
|
748
788
|
});
|
|
@@ -753,7 +793,9 @@ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
|
753
793
|
]
|
|
754
794
|
});
|
|
755
795
|
}
|
|
756
|
-
}, [
|
|
796
|
+
}, [
|
|
797
|
+
dispatchBlur
|
|
798
|
+
]);
|
|
757
799
|
}
|
|
758
800
|
|
|
759
801
|
|
|
@@ -1176,29 +1218,29 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
1176
1218
|
// NOTICE file in the root directory of this source tree.
|
|
1177
1219
|
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
1178
1220
|
|
|
1221
|
+
|
|
1179
1222
|
function $e0b6e0b68ec7f50f$export$872b660ac5a1ff98(props) {
|
|
1180
1223
|
let { ref: ref , onInteractOutside: onInteractOutside , isDisabled: isDisabled , onInteractOutsideStart: onInteractOutsideStart } = props;
|
|
1181
1224
|
let stateRef = (0, $bx7SL$useRef)({
|
|
1182
1225
|
isPointerDown: false,
|
|
1183
|
-
ignoreEmulatedMouseEvents: false
|
|
1184
|
-
|
|
1185
|
-
|
|
1226
|
+
ignoreEmulatedMouseEvents: false
|
|
1227
|
+
});
|
|
1228
|
+
let onPointerDown = (0, $bx7SL$useEffectEvent)((e)=>{
|
|
1229
|
+
if (onInteractOutside && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) {
|
|
1230
|
+
if (onInteractOutsideStart) onInteractOutsideStart(e);
|
|
1231
|
+
stateRef.current.isPointerDown = true;
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
let triggerInteractOutside = (0, $bx7SL$useEffectEvent)((e)=>{
|
|
1235
|
+
if (onInteractOutside) onInteractOutside(e);
|
|
1186
1236
|
});
|
|
1187
|
-
let state = stateRef.current;
|
|
1188
|
-
state.onInteractOutside = onInteractOutside;
|
|
1189
|
-
state.onInteractOutsideStart = onInteractOutsideStart;
|
|
1190
1237
|
(0, $bx7SL$useEffect)(()=>{
|
|
1238
|
+
let state = stateRef.current;
|
|
1191
1239
|
if (isDisabled) return;
|
|
1192
|
-
let onPointerDown = (e)=>{
|
|
1193
|
-
if ($e0b6e0b68ec7f50f$var$isValidEvent(e, ref) && state.onInteractOutside) {
|
|
1194
|
-
if (state.onInteractOutsideStart) state.onInteractOutsideStart(e);
|
|
1195
|
-
state.isPointerDown = true;
|
|
1196
|
-
}
|
|
1197
|
-
};
|
|
1198
1240
|
// Use pointer events if available. Otherwise, fall back to mouse and touch events.
|
|
1199
1241
|
if (typeof PointerEvent !== "undefined") {
|
|
1200
1242
|
let onPointerUp = (e)=>{
|
|
1201
|
-
if (state.isPointerDown &&
|
|
1243
|
+
if (state.isPointerDown && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) triggerInteractOutside(e);
|
|
1202
1244
|
state.isPointerDown = false;
|
|
1203
1245
|
};
|
|
1204
1246
|
// changing these to capture phase fixed combobox
|
|
@@ -1211,12 +1253,12 @@ function $e0b6e0b68ec7f50f$export$872b660ac5a1ff98(props) {
|
|
|
1211
1253
|
} else {
|
|
1212
1254
|
let onMouseUp = (e)=>{
|
|
1213
1255
|
if (state.ignoreEmulatedMouseEvents) state.ignoreEmulatedMouseEvents = false;
|
|
1214
|
-
else if (state.isPointerDown &&
|
|
1256
|
+
else if (state.isPointerDown && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) triggerInteractOutside(e);
|
|
1215
1257
|
state.isPointerDown = false;
|
|
1216
1258
|
};
|
|
1217
1259
|
let onTouchEnd = (e)=>{
|
|
1218
1260
|
state.ignoreEmulatedMouseEvents = true;
|
|
1219
|
-
if (state.
|
|
1261
|
+
if (state.isPointerDown && $e0b6e0b68ec7f50f$var$isValidEvent(e, ref)) triggerInteractOutside(e);
|
|
1220
1262
|
state.isPointerDown = false;
|
|
1221
1263
|
};
|
|
1222
1264
|
document.addEventListener("mousedown", onPointerDown, true);
|
|
@@ -1232,8 +1274,9 @@ function $e0b6e0b68ec7f50f$export$872b660ac5a1ff98(props) {
|
|
|
1232
1274
|
}
|
|
1233
1275
|
}, [
|
|
1234
1276
|
ref,
|
|
1235
|
-
|
|
1236
|
-
|
|
1277
|
+
isDisabled,
|
|
1278
|
+
onPointerDown,
|
|
1279
|
+
triggerInteractOutside
|
|
1237
1280
|
]);
|
|
1238
1281
|
}
|
|
1239
1282
|
function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
|
|
@@ -1325,46 +1368,46 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
1325
1368
|
id: null
|
|
1326
1369
|
});
|
|
1327
1370
|
let { addGlobalListener: addGlobalListener , removeGlobalListener: removeGlobalListener } = (0, $bx7SL$useGlobalListeners)();
|
|
1328
|
-
let
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
let move = (originalEvent, pointerType, deltaX, deltaY)=>{
|
|
1335
|
-
if (deltaX === 0 && deltaY === 0) return;
|
|
1336
|
-
if (!state.current.didMove) {
|
|
1337
|
-
state.current.didMove = true;
|
|
1338
|
-
onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
|
|
1339
|
-
type: "movestart",
|
|
1340
|
-
pointerType: pointerType,
|
|
1341
|
-
shiftKey: originalEvent.shiftKey,
|
|
1342
|
-
metaKey: originalEvent.metaKey,
|
|
1343
|
-
ctrlKey: originalEvent.ctrlKey,
|
|
1344
|
-
altKey: originalEvent.altKey
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
onMove({
|
|
1348
|
-
type: "move",
|
|
1349
|
-
pointerType: pointerType,
|
|
1350
|
-
deltaX: deltaX,
|
|
1351
|
-
deltaY: deltaY,
|
|
1352
|
-
shiftKey: originalEvent.shiftKey,
|
|
1353
|
-
metaKey: originalEvent.metaKey,
|
|
1354
|
-
ctrlKey: originalEvent.ctrlKey,
|
|
1355
|
-
altKey: originalEvent.altKey
|
|
1356
|
-
});
|
|
1357
|
-
};
|
|
1358
|
-
let end = (originalEvent, pointerType)=>{
|
|
1359
|
-
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
|
|
1360
|
-
if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
1361
|
-
type: "moveend",
|
|
1371
|
+
let move = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType, deltaX, deltaY)=>{
|
|
1372
|
+
if (deltaX === 0 && deltaY === 0) return;
|
|
1373
|
+
if (!state.current.didMove) {
|
|
1374
|
+
state.current.didMove = true;
|
|
1375
|
+
onMoveStart === null || onMoveStart === void 0 ? void 0 : onMoveStart({
|
|
1376
|
+
type: "movestart",
|
|
1362
1377
|
pointerType: pointerType,
|
|
1363
1378
|
shiftKey: originalEvent.shiftKey,
|
|
1364
1379
|
metaKey: originalEvent.metaKey,
|
|
1365
1380
|
ctrlKey: originalEvent.ctrlKey,
|
|
1366
1381
|
altKey: originalEvent.altKey
|
|
1367
1382
|
});
|
|
1383
|
+
}
|
|
1384
|
+
onMove({
|
|
1385
|
+
type: "move",
|
|
1386
|
+
pointerType: pointerType,
|
|
1387
|
+
deltaX: deltaX,
|
|
1388
|
+
deltaY: deltaY,
|
|
1389
|
+
shiftKey: originalEvent.shiftKey,
|
|
1390
|
+
metaKey: originalEvent.metaKey,
|
|
1391
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
1392
|
+
altKey: originalEvent.altKey
|
|
1393
|
+
});
|
|
1394
|
+
});
|
|
1395
|
+
let end = (0, $bx7SL$useEffectEvent)((originalEvent, pointerType)=>{
|
|
1396
|
+
(0, $14c0b72509d70225$export$b0d6fa1ab32e3295)();
|
|
1397
|
+
if (state.current.didMove) onMoveEnd === null || onMoveEnd === void 0 ? void 0 : onMoveEnd({
|
|
1398
|
+
type: "moveend",
|
|
1399
|
+
pointerType: pointerType,
|
|
1400
|
+
shiftKey: originalEvent.shiftKey,
|
|
1401
|
+
metaKey: originalEvent.metaKey,
|
|
1402
|
+
ctrlKey: originalEvent.ctrlKey,
|
|
1403
|
+
altKey: originalEvent.altKey
|
|
1404
|
+
});
|
|
1405
|
+
});
|
|
1406
|
+
let moveProps = (0, $bx7SL$useMemo)(()=>{
|
|
1407
|
+
let moveProps = {};
|
|
1408
|
+
let start = ()=>{
|
|
1409
|
+
(0, $14c0b72509d70225$export$16a4697467175487)();
|
|
1410
|
+
state.current.didMove = false;
|
|
1368
1411
|
};
|
|
1369
1412
|
if (typeof PointerEvent === "undefined") {
|
|
1370
1413
|
let onMouseMove = (e)=>{
|
|
@@ -1512,11 +1555,10 @@ function $e8a7022cf87cba2a$export$36da96379f79f245(props) {
|
|
|
1512
1555
|
return moveProps;
|
|
1513
1556
|
}, [
|
|
1514
1557
|
state,
|
|
1515
|
-
onMoveStart,
|
|
1516
|
-
onMove,
|
|
1517
|
-
onMoveEnd,
|
|
1518
1558
|
addGlobalListener,
|
|
1519
|
-
removeGlobalListener
|
|
1559
|
+
removeGlobalListener,
|
|
1560
|
+
move,
|
|
1561
|
+
end
|
|
1520
1562
|
]);
|
|
1521
1563
|
return {
|
|
1522
1564
|
moveProps: moveProps
|
|
@@ -1577,6 +1619,7 @@ function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
|
|
|
1577
1619
|
let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
|
|
1578
1620
|
isDisabled: isDisabled,
|
|
1579
1621
|
onPressStart (e) {
|
|
1622
|
+
e.continuePropagation();
|
|
1580
1623
|
if (e.pointerType === "mouse" || e.pointerType === "touch") {
|
|
1581
1624
|
if (onLongPressStart) onLongPressStart({
|
|
1582
1625
|
...e,
|