Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-long-press

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-long-press - npm Package Compare versions

Comparing version 3.1.2-alpha.1 to 3.1.2-rc.1

2

index.js

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react");var i=(e=>(e.Mouse="mouse",e.Touch="touch",e.Pointer="pointer",e))(i||{}),a=(e=>(e.CancelledByMovement="cancelled-by-movement",e.CancelledByRelease="cancelled-by-release",e.CancelledOutsideElement="cancelled-outside-element",e))(a||{});const h=global?.PointerEvent??window?.PointerEvent??null,b=global?.TouchEvent??window?.TouchEvent??null;function S(e){const{nativeEvent:o}=e;return o?b&&o instanceof b||"touches"in o:!1}function A(e){return e.nativeEvent instanceof MouseEvent&&!(h&&e.nativeEvent instanceof h)}function U(e){const{nativeEvent:o}=e;return o?h&&o instanceof h||"pointerId"in o:!1}function B(e){return A(e)||S(e)||U(e)}function D(e){return S(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:A(e)||U(e)?{x:e.pageX,y:e.pageY}:null}function Y(e){return{target:e.target,currentTarget:e.currentTarget,nativeEvent:e,persist:()=>{}}}function j(e,{threshold:o=400,captureEvent:E=!1,detect:y=i.Pointer,cancelOnMovement:w=!1,cancelOutsideElement:P=!0,filterEvents:m,onStart:M,onMove:x,onFinish:C,onCancel:L}={}){const T=n.useRef(!1),f=n.useRef(!1),c=n.useRef(),X=n.useRef(),l=n.useRef(),p=n.useRef(e),d=n.useRef(null),v=n.useCallback(t=>{f.current||B(t)&&(m!==void 0&&!m(t)||(E&&t.persist(),M?.(t,{context:c.current}),d.current=D(t),f.current=!0,X.current=t.currentTarget,l.current=setTimeout(()=>{p.current&&(p.current(t,{context:c.current}),T.current=!0)},o)))},[E,m,M,o]),u=n.useCallback((t,r)=>{B(t)&&f.current&&(d.current=null,E&&t.persist(),T.current?C?.(t,{context:c.current}):f.current&&L?.(t,{context:c.current,reason:r??a.CancelledByRelease}),T.current=!1,f.current=!1,l.current!==void 0&&clearTimeout(l.current))},[E,C,L]),g=n.useCallback(t=>{if(x?.(t,{context:c.current}),w&&d.current){const r=D(t);if(r){const s=w===!0?25:w,R={x:Math.abs(r.x-d.current.x),y:Math.abs(r.y-d.current.y)};(R.x>s||R.y>s)&&u(t,a.CancelledByMovement)}}},[u,w,x]);return n.useEffect(()=>{function t(r){const s=Y(r);u(s)}if(window)return window.addEventListener("mouseup",t),window.addEventListener("touchend",t),window.addEventListener("pointerup",t),()=>{window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t),window.removeEventListener("pointerup",t)}},[u]),n.useEffect(()=>()=>{l.current!==void 0&&clearTimeout(l.current)},[]),n.useEffect(()=>{p.current=e},[e]),n.useCallback(t=>{if(c.current=t,e===null)return{};switch(y){case i.Mouse:{const r={onMouseDown:v,onMouseMove:g,onMouseUp:u};return P&&(r.onMouseLeave=s=>{u(s,a.CancelledOutsideElement)}),r}case i.Touch:return{onTouchStart:v,onTouchMove:g,onTouchEnd:u};case i.Pointer:{const r={onPointerDown:v,onPointerMove:g,onPointerUp:u};return P&&(r.onPointerLeave=s=>u(s,a.CancelledOutsideElement)),r}}},[e,u,P,y,g,v])}exports.LongPressCallbackReason=a;exports.LongPressEventType=i;exports.useLongPress=j;
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react");var a=(e=>(e.Mouse="mouse",e.Touch="touch",e.Pointer="pointer",e))(a||{}),f=(e=>(e.CancelledByMovement="cancelled-by-movement",e.CancelledByRelease="cancelled-by-release",e.CancelledOutsideElement="cancelled-outside-element",e))(f||{});const B=()=>global?.PointerEvent??window?.PointerEvent??null,X=()=>global?.TouchEvent??window?.TouchEvent??null;function D(e){const{nativeEvent:r}=e;if(!r)return!1;const u=X();return u&&r instanceof u||"touches"in r}function S(e){const r=B();return e.nativeEvent instanceof MouseEvent&&!(r&&e.nativeEvent instanceof r)}function A(e){const{nativeEvent:r}=e;if(!r)return!1;const u=B();return u&&r instanceof u||"pointerId"in r}function R(e){return S(e)||D(e)||A(e)}function b(e){return D(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:S(e)||A(e)?{x:e.pageX,y:e.pageY}:null}function Y(e){return{target:e.target,currentTarget:e.currentTarget,nativeEvent:e,persist:()=>{}}}function j(e,{threshold:r=400,captureEvent:u=!1,detect:p=a.Pointer,cancelOnMovement:v=!1,cancelOutsideElement:P=!0,filterEvents:h,onStart:y,onMove:M,onFinish:x,onCancel:C}={}){const T=n.useRef(!1),l=n.useRef(!1),i=n.useRef(),U=n.useRef(),d=n.useRef(),m=n.useRef(e),E=n.useRef(null),w=n.useCallback(t=>{l.current||R(t)&&(h!==void 0&&!h(t)||(u&&t.persist(),y?.(t,{context:i.current}),E.current=b(t),l.current=!0,U.current=t.currentTarget,d.current=setTimeout(()=>{m.current&&(m.current(t,{context:i.current}),T.current=!0)},r)))},[u,h,y,r]),s=n.useCallback((t,o)=>{R(t)&&l.current&&(E.current=null,u&&t.persist(),T.current?x?.(t,{context:i.current}):l.current&&C?.(t,{context:i.current,reason:o??f.CancelledByRelease}),T.current=!1,l.current=!1,d.current!==void 0&&clearTimeout(d.current))},[u,x,C]),g=n.useCallback(t=>{if(M?.(t,{context:i.current}),v&&E.current){const o=b(t);if(o){const c=v===!0?25:v,L={x:Math.abs(o.x-E.current.x),y:Math.abs(o.y-E.current.y)};(L.x>c||L.y>c)&&s(t,f.CancelledByMovement)}}},[s,v,M]);return n.useEffect(()=>{function t(o){const c=Y(o);s(c)}if(window)return window.addEventListener("mouseup",t),window.addEventListener("touchend",t),window.addEventListener("pointerup",t),()=>{window.removeEventListener("mouseup",t),window.removeEventListener("touchend",t),window.removeEventListener("pointerup",t)}},[s]),n.useEffect(()=>()=>{d.current!==void 0&&clearTimeout(d.current)},[]),n.useEffect(()=>{m.current=e},[e]),n.useCallback(t=>{if(i.current=t,e===null)return{};switch(p){case a.Mouse:{const o={onMouseDown:w,onMouseMove:g,onMouseUp:s};return P&&(o.onMouseLeave=c=>{s(c,f.CancelledOutsideElement)}),o}case a.Touch:return{onTouchStart:w,onTouchMove:g,onTouchEnd:s};case a.Pointer:{const o={onPointerDown:w,onPointerMove:g,onPointerUp:s};return P&&(o.onPointerLeave=c=>s(c,f.CancelledOutsideElement)),o}}},[e,s,P,p,g,w])}exports.LongPressCallbackReason=f;exports.LongPressEventType=a;exports.useLongPress=j;
{
"name": "use-long-press",
"version": "3.1.2-alpha.1",
"version": "3.1.2-rc.1",
"description": "React hook for detecting click, tap or point and hold event. Easy to use, highly customizable options, thoroughly tested.",

@@ -5,0 +5,0 @@ "author": "minwork",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc