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.1 to 3.1.2-alpha.1

2

index.js

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

"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=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 P=window.PointerEvent??null;function D(e){const{nativeEvent:u}=e;return u?window.TouchEvent&&u instanceof TouchEvent||"touches"in u:!1}function S(e){return e.nativeEvent instanceof MouseEvent&&!(P&&e.nativeEvent instanceof P)}function A(e){const{nativeEvent:u}=e;return u?P&&u instanceof P||"pointerId"in u:!1}function b(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 X(e){return{target:e.target,currentTarget:e.currentTarget,nativeEvent:e,persist:()=>{}}}function Y(e,{threshold:u=400,captureEvent:E=!1,detect:y=i.Pointer,cancelOnMovement:w=!1,cancelOutsideElement:g=!0,filterEvents:m,onStart:M,onMove:x,onFinish:C,onCancel:L}={}){const p=r.useRef(!1),f=r.useRef(!1),c=r.useRef(),U=r.useRef(),l=r.useRef(),T=r.useRef(e),d=r.useRef(null),h=r.useCallback(t=>{f.current||b(t)&&(m!==void 0&&!m(t)||(E&&t.persist(),M?.(t,{context:c.current}),d.current=B(t),f.current=!0,U.current=t.currentTarget,l.current=setTimeout(()=>{T.current&&(T.current(t,{context:c.current}),p.current=!0)},u)))},[E,m,M,u]),o=r.useCallback((t,n)=>{b(t)&&f.current&&(d.current=null,E&&t.persist(),p.current?C?.(t,{context:c.current}):f.current&&L?.(t,{context:c.current,reason:n??a.CancelledByRelease}),p.current=!1,f.current=!1,l.current!==void 0&&clearTimeout(l.current))},[E,C,L]),v=r.useCallback(t=>{if(x?.(t,{context:c.current}),w&&d.current){const n=B(t);if(n){const s=w===!0?25:w,R={x:Math.abs(n.x-d.current.x),y:Math.abs(n.y-d.current.y)};(R.x>s||R.y>s)&&o(t,a.CancelledByMovement)}}},[o,w,x]);return r.useEffect(()=>{function t(n){const s=X(n);o(s)}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)}},[o]),r.useEffect(()=>()=>{l.current!==void 0&&clearTimeout(l.current)},[]),r.useEffect(()=>{T.current=e},[e]),r.useCallback(t=>{if(c.current=t,e===null)return{};switch(y){case i.Mouse:{const n={onMouseDown:h,onMouseMove:v,onMouseUp:o};return g&&(n.onMouseLeave=s=>{o(s,a.CancelledOutsideElement)}),n}case i.Touch:return{onTouchStart:h,onTouchMove:v,onTouchEnd:o};case i.Pointer:{const n={onPointerDown:h,onPointerMove:v,onPointerUp:o};return g&&(n.onPointerLeave=s=>o(s,a.CancelledOutsideElement)),n}}},[e,o,g,y,v,h])}exports.LongPressCallbackReason=a;exports.LongPressEventType=i;exports.useLongPress=Y;
"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;
{
"name": "use-long-press",
"version": "3.1.1",
"version": "3.1.2-alpha.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