1 | import {usePress as $f6c31cce2adf654f$export$45712eceda6fad21} from "./usePress.module.js";
|
2 | import {useGlobalListeners as $4k2kv$useGlobalListeners, useDescription as $4k2kv$useDescription, mergeProps as $4k2kv$mergeProps} from "@react-aria/utils";
|
3 | import {useRef as $4k2kv$useRef} from "react";
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | const $8a26561d2877236e$var$DEFAULT_THRESHOLD = 500;
|
19 | function $8a26561d2877236e$export$c24ed0104d07eab9(props) {
|
20 | let { isDisabled: isDisabled, onLongPressStart: onLongPressStart, onLongPressEnd: onLongPressEnd, onLongPress: onLongPress, threshold: threshold = $8a26561d2877236e$var$DEFAULT_THRESHOLD, accessibilityDescription: accessibilityDescription } = props;
|
21 | const timeRef = (0, $4k2kv$useRef)(undefined);
|
22 | let { addGlobalListener: addGlobalListener, removeGlobalListener: removeGlobalListener } = (0, $4k2kv$useGlobalListeners)();
|
23 | let { pressProps: pressProps } = (0, $f6c31cce2adf654f$export$45712eceda6fad21)({
|
24 | isDisabled: isDisabled,
|
25 | onPressStart (e) {
|
26 | e.continuePropagation();
|
27 | if (e.pointerType === 'mouse' || e.pointerType === 'touch') {
|
28 | if (onLongPressStart) onLongPressStart({
|
29 | ...e,
|
30 | type: 'longpressstart'
|
31 | });
|
32 | timeRef.current = setTimeout(()=>{
|
33 |
|
34 | e.target.dispatchEvent(new PointerEvent('pointercancel', {
|
35 | bubbles: true
|
36 | }));
|
37 | if (onLongPress) onLongPress({
|
38 | ...e,
|
39 | type: 'longpress'
|
40 | });
|
41 | timeRef.current = undefined;
|
42 | }, threshold);
|
43 |
|
44 | if (e.pointerType === 'touch') {
|
45 | let onContextMenu = (e)=>{
|
46 | e.preventDefault();
|
47 | };
|
48 | addGlobalListener(e.target, 'contextmenu', onContextMenu, {
|
49 | once: true
|
50 | });
|
51 | addGlobalListener(window, 'pointerup', ()=>{
|
52 |
|
53 |
|
54 | setTimeout(()=>{
|
55 | removeGlobalListener(e.target, 'contextmenu', onContextMenu);
|
56 | }, 30);
|
57 | }, {
|
58 | once: true
|
59 | });
|
60 | }
|
61 | }
|
62 | },
|
63 | onPressEnd (e) {
|
64 | if (timeRef.current) clearTimeout(timeRef.current);
|
65 | if (onLongPressEnd && (e.pointerType === 'mouse' || e.pointerType === 'touch')) onLongPressEnd({
|
66 | ...e,
|
67 | type: 'longpressend'
|
68 | });
|
69 | }
|
70 | });
|
71 | let descriptionProps = (0, $4k2kv$useDescription)(onLongPress && !isDisabled ? accessibilityDescription : undefined);
|
72 | return {
|
73 | longPressProps: (0, $4k2kv$mergeProps)(pressProps, descriptionProps)
|
74 | };
|
75 | }
|
76 |
|
77 |
|
78 | export {$8a26561d2877236e$export$c24ed0104d07eab9 as useLongPress};
|
79 |
|