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