@nethesis/phone-island
Version:
NethVoice CTI Phone Island
3 lines (2 loc) • 1.19 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){(function(e){return"touches"in e})(e)&&e.touches.length<2&&e.preventDefault&&e.preventDefault()}exports.useLongPress=function(n,r,o,u,a){var c=void 0===a?{}:a,s=c.shouldPreventDefault,i=void 0===s||s,d=c.delay,f=void 0===d?300:d,p=e.useState(!1),v=p[0],l=p[1],g=e.useRef(),h=e.useRef(),N=e.useCallback((function(e){u(),i&&e.target&&(e.target.addEventListener("touchend",t,{passive:!1}),h.current=e.target),g.current=setTimeout((function(){n(e),l(!0)}),f)}),[n,f,i]),P=e.useCallback((function(e,n){void 0===n&&(n=!0),g.current&&clearTimeout(g.current),n&&!v&&!o&&!function(e){if(e&&e.dataset.stopPropagation||e&&e.parentNode&&e.parentNode.dataset.stopPropagation||e&&e.parentNode.parentNode&&e.parentNode.parentNode.dataset.stopPropagation)return!0;return!1}(h.current)&&r(),l(!1),i&&h.current&&h.current.removeEventListener("touchend",t)}),[i,r,o,v]);return{onMouseDown:function(e){return N(e)},onTouchStart:function(e){return N(e)},onMouseUp:function(e){return P(e)},onMouseLeave:function(e){return P(e,!1)},onTouchEnd:function(e){return P(e)}}};
//# sourceMappingURL=useLongPress.js.map