use-long-press
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react");var c=(e=>(e.Mouse="mouse",e.Touch="touch",e.Pointer="pointer",e))(c||{}),P=(e=>(e.CancelledByMovement="cancelled-by-movement",e.CancelledByRelease="cancelled-by-release",e))(P||{});function b(e){const{nativeEvent:n}=e;return n?window.TouchEvent&&n instanceof TouchEvent||"touches"in n:!1}function B(e){return e.nativeEvent instanceof MouseEvent}function D(e){const{nativeEvent:n}=e;return n?window.PointerEvent&&n instanceof PointerEvent||"pointerId"in n:!1}function C(e){return B(e)||b(e)||D(e)}function L(e){return b(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:B(e)||D(e)?{x:e.pageX,y:e.pageY}:null}function S(e){return{target:e.target,currentTarget:e.currentTarget,nativeEvent:e,persist:()=>{}}}function A(e,{threshold:n=400,captureEvent:l=!1,detect:m=c.Pointer,cancelOnMovement:d=!1,filterEvents:g,onStart:T,onMove:y,onFinish:x,onCancel:M}={}){const p=t.useRef(!1),i=t.useRef(!1),s=t.useRef(),a=t.useRef(),v=t.useRef(e),f=t.useRef(null),w=t.useCallback(r=>{i.current||C(r)&&(g!==void 0&&!g(r)||(l&&r.persist(),T?.(r,{context:s.current}),f.current=L(r),i.current=!0,a.current=setTimeout(()=>{v.current&&(v.current(r,{context:s.current}),p.current=!0)},n)))},[l,g,T,n]),o=t.useCallback((r,u)=>{C(r)&&i.current&&(f.current=null,l&&r.persist(),p.current?x?.(r,{context:s.current}):i.current&&M?.(r,{context:s.current,reason:u??P.CancelledByRelease}),p.current=!1,i.current=!1,a.current!==void 0&&clearTimeout(a.current))},[l,x,M]),E=t.useCallback(r=>{if(y?.(r,{context:s.current}),d&&f.current){const u=L(r);if(u){const h=d===!0?25:d,R={x:Math.abs(u.x-f.current.x),y:Math.abs(u.y-f.current.y)};(R.x>h||R.y>h)&&o(r,P.CancelledByMovement)}}},[o,d,y]);return t.useEffect(()=>{function r(u){const h=S(u);o(h)}return window.addEventListener("mouseup",r),window.addEventListener("touchend",r),window.addEventListener("pointerup",r),()=>{window.removeEventListener("mouseup",r),window.removeEventListener("touchend",r),window.removeEventListener("pointerup",r)}},[o]),t.useEffect(()=>()=>{a.current!==void 0&&clearTimeout(a.current)},[]),t.useEffect(()=>{v.current=e},[e]),t.useCallback(r=>{if(s.current=r,e===null)return{};switch(m){case c.Mouse:return{onMouseDown:w,onMouseMove:E,onMouseUp:o};case c.Touch:return{onTouchStart:w,onTouchMove:E,onTouchEnd:o};case c.Pointer:return{onPointerDown:w,onPointerMove:E,onPointerUp:o}}},[e,o,m,E,w])}exports.LongPressCallbackReason=P;exports.LongPressEventType=c;exports.useLongPress=A; | ||
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react");var i=(e=>(e.Mouse="mouse",e.Touch="touch",e.Pointer="pointer",e))(i||{}),h=(e=>(e.CancelledByMovement="cancelled-by-movement",e.CancelledByRelease="cancelled-by-release",e))(h||{});function b(e){const{nativeEvent:n}=e;return n?window.TouchEvent&&n instanceof TouchEvent||"touches"in n:!1}function B(e){return e.nativeEvent instanceof MouseEvent&&!(e.nativeEvent instanceof PointerEvent)}function D(e){const{nativeEvent:n}=e;return n?window.PointerEvent&&n instanceof PointerEvent||"pointerId"in n:!1}function C(e){return B(e)||b(e)||D(e)}function L(e){return b(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:B(e)||D(e)?{x:e.pageX,y:e.pageY}:null}function S(e){return{target:e.target,currentTarget:e.currentTarget,nativeEvent:e,persist:()=>{}}}function A(e,{threshold:n=400,captureEvent:l=!1,detect:m=i.Pointer,cancelOnMovement:d=!1,filterEvents:v,onStart:T,onMove:y,onFinish:x,onCancel:M}={}){const g=t.useRef(!1),c=t.useRef(!1),s=t.useRef(),a=t.useRef(),p=t.useRef(e),f=t.useRef(null),E=t.useCallback(r=>{c.current||C(r)&&(v!==void 0&&!v(r)||(l&&r.persist(),T?.(r,{context:s.current}),f.current=L(r),c.current=!0,a.current=setTimeout(()=>{p.current&&(p.current(r,{context:s.current}),g.current=!0)},n)))},[l,v,T,n]),o=t.useCallback((r,u)=>{C(r)&&c.current&&(f.current=null,l&&r.persist(),g.current?x?.(r,{context:s.current}):c.current&&M?.(r,{context:s.current,reason:u??h.CancelledByRelease}),g.current=!1,c.current=!1,a.current!==void 0&&clearTimeout(a.current))},[l,x,M]),w=t.useCallback(r=>{if(y?.(r,{context:s.current}),d&&f.current){const u=L(r);if(u){const P=d===!0?25:d,R={x:Math.abs(u.x-f.current.x),y:Math.abs(u.y-f.current.y)};(R.x>P||R.y>P)&&o(r,h.CancelledByMovement)}}},[o,d,y]);return t.useEffect(()=>{function r(u){const P=S(u);o(P)}return window.addEventListener("mouseup",r),window.addEventListener("touchend",r),window.addEventListener("pointerup",r),()=>{window.removeEventListener("mouseup",r),window.removeEventListener("touchend",r),window.removeEventListener("pointerup",r)}},[o]),t.useEffect(()=>()=>{a.current!==void 0&&clearTimeout(a.current)},[]),t.useEffect(()=>{p.current=e},[e]),t.useCallback(r=>{if(s.current=r,e===null)return{};switch(m){case i.Mouse:return{onMouseDown:E,onMouseMove:w,onMouseUp:o};case i.Touch:return{onTouchStart:E,onTouchMove:w,onTouchEnd:o};case i.Pointer:return{onPointerDown:E,onPointerMove:w,onPointerUp:o}}},[e,o,m,w,E])}exports.LongPressCallbackReason=h;exports.LongPressEventType=i;exports.useLongPress=A; |
{ | ||
"name": "use-long-press", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "React hook for detecting click, tap or point and hold event. Easy to use, highly customizable options, thoroughly tested.", | ||
@@ -8,11 +8,8 @@ "author": "minwork", | ||
"keywords": [ | ||
"react", | ||
"long press", | ||
"hook", | ||
"react", | ||
"click and hold", | ||
"tap and hold", | ||
"point and hold", | ||
"mouse", | ||
"touch", | ||
"pointer" | ||
"point and hold" | ||
], | ||
@@ -19,0 +16,0 @@ "scripts": { |
# React Long Press Hook :point_down: | ||
> React hook for detecting _click_, _tap_ or _point_ and _hold_ event | ||
> React hook for detecting _click_ / _tap_ / _point_ and _hold_ event | ||
[![codecov](https://codecov.io/gh/minwork/react/branch/main/graph/badge.svg?token=2KPMMSLDOM)](https://codecov.io/gh/minwork/react) | ||
![npm type definitions](https://img.shields.io/npm/types/use-long-press) | ||
@@ -312,3 +313,3 @@ ![npm bundle size](https://img.shields.io/bundlephobia/min/use-long-press) | ||
Overall considering the reasons mentioned above, maintaining old versions was no longer a viable option hence why the deprecation. | ||
Overall considering the reasons mentioned above, maintaining old versions was no longer a viable option hence why the deprecation. If you want to upgrade from v1 or v2 see [migration guide](#migration). | ||
@@ -315,0 +316,0 @@ ### Moving to new repository |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
328
30216
8