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 2.0.0 to 2.0.2

1

dist/index.d.ts

@@ -5,1 +5,2 @@ import { CallableContextResult, EmptyObject, LongPressCallback, LongPressOptions, LongPressResult } from './types';

export declare function useLongPress<Target = Element, Callback extends LongPressCallback<Target> = LongPressCallback<Target>, Context = unknown>(callback: Callback | null, options?: LongPressOptions<Target>): CallableContextResult<LongPressResult<Target> | EmptyObject, Context>;
export * from './types';

2

dist/index.js

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

var n,e,t=require("react");function r(){return(r=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}function u(n){var e=n.nativeEvent;return window.TouchEvent?e instanceof TouchEvent:"touches"in e}function o(n){return n.nativeEvent instanceof MouseEvent}function c(n){return u(n)?{x:n.touches[0].pageX,y:n.touches[0].pageY}:o(n)?{x:n.pageX,y:n.pageY}:null}!function(n){n.CANCELED_BY_MOVEMENT="canceled-by-movement",n.CANCELED_BY_TIMEOUT="canceled-by-timeout"}(n||(n={})),function(n){n.BOTH="both",n.MOUSE="mouse",n.TOUCH="touch"}(e||(e={})),exports.useLongPress=function(i,a){var s=void 0===a?{}:a,f=s.threshold,l=void 0===f?400:f,v=s.captureEvent,E=void 0!==v&&v,M=s.detect,h=void 0===M?e.BOTH:M,T=s.cancelOnMovement,d=void 0!==T&&T,p=s.filterEvents,C=s.onStart,O=s.onMove,y=s.onFinish,b=s.onCancel,x=t.useRef(!1),m=t.useRef(!1),_=t.useRef(),g=t.useRef(i),U=t.useRef(null),B=t.useCallback(function(n){return function(e){if(!m.current&&(o(e)||u(e))&&(void 0===p||p(e))){U.current=c(e),E&&e.persist();var t=void 0===n?{}:{context:n};null==C||C(e,t),m.current=!0,_.current=setTimeout(function(){g.current&&(g.current(e,t),x.current=!0)},l)}}},[E,p,C,l]),L=t.useCallback(function(e,t){return function(c){if(o(c)||u(c)){U.current=null,E&&c.persist();var i=void 0===e?{}:{context:e};x.current?null==y||y(c,i):m.current&&(null==b||b(c,r({},i,{reason:null!=t?t:n.CANCELED_BY_TIMEOUT}))),x.current=!1,m.current=!1,void 0!==_.current&&clearTimeout(_.current)}}},[E,y,b]),N=t.useCallback(function(e){return function(t){if(null==O||O(t,{context:e}),d&&U.current){var r=c(t);if(r){var u=!0===d?25:d,o={x:Math.abs(r.x-U.current.x),y:Math.abs(r.y-U.current.y)};(o.x>u||o.y>u)&&L(e,n.CANCELED_BY_MOVEMENT)(t)}}}},[L,d,O]);return t.useEffect(function(){return function(){void 0!==_.current&&clearTimeout(_.current)}},[]),t.useEffect(function(){g.current=i},[i]),t.useMemo(function(){return function(n){var t={onMouseDown:B(n),onMouseMove:N(n),onMouseUp:L(n),onMouseLeave:L(n)},u={onTouchStart:B(n),onTouchMove:N(n),onTouchEnd:L(n)};return null===i?{}:h===e.MOUSE?t:h===e.TOUCH?u:r({},t,u)}},[i,L,h,N,B])};
var e,n,t=require("react");function r(){return(r=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function o(e){var n=e.nativeEvent;return window.TouchEvent?n instanceof TouchEvent:"touches"in n}function u(e){return e.nativeEvent instanceof MouseEvent}function s(e){return o(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:u(e)?{x:e.pageX,y:e.pageY}:null}exports.LongPressEventReason=void 0,(e=exports.LongPressEventReason||(exports.LongPressEventReason={})).CANCELED_BY_MOVEMENT="canceled-by-movement",e.CANCELED_BY_TIMEOUT="canceled-by-timeout",exports.LongPressDetectEvents=void 0,(n=exports.LongPressDetectEvents||(exports.LongPressDetectEvents={})).BOTH="both",n.MOUSE="mouse",n.TOUCH="touch",exports.useLongPress=function(e,n){var c=void 0===n?{}:n,i=c.threshold,a=void 0===i?400:i,v=c.captureEvent,E=void 0!==v&&v,f=c.detect,l=void 0===f?exports.LongPressDetectEvents.BOTH:f,p=c.cancelOnMovement,x=void 0!==p&&p,M=c.filterEvents,d=c.onStart,g=c.onMove,h=c.onFinish,T=c.onCancel,L=t.useRef(!1),C=t.useRef(!1),O=t.useRef(),P=t.useRef(e),y=t.useRef(null),D=t.useCallback(function(e){return function(n){if(!C.current&&(u(n)||o(n))&&(void 0===M||M(n))){y.current=s(n),E&&n.persist();var t=void 0===e?{}:{context:e};null==d||d(n,t),C.current=!0,O.current=setTimeout(function(){P.current&&(P.current(n,t),L.current=!0)},a)}}},[E,M,d,a]),b=t.useCallback(function(e,n){return function(t){if(u(t)||o(t)){y.current=null,E&&t.persist();var s=void 0===e?{}:{context:e};L.current?null==h||h(t,s):C.current&&(null==T||T(t,r({},s,{reason:null!=n?n:exports.LongPressEventReason.CANCELED_BY_TIMEOUT}))),L.current=!1,C.current=!1,void 0!==O.current&&clearTimeout(O.current)}}},[E,h,T]),R=t.useCallback(function(e){return function(n){if(null==g||g(n,{context:e}),x&&y.current){var t=s(n);if(t){var r=!0===x?25:x,o={x:Math.abs(t.x-y.current.x),y:Math.abs(t.y-y.current.y)};(o.x>r||o.y>r)&&b(e,exports.LongPressEventReason.CANCELED_BY_MOVEMENT)(n)}}}},[b,x,g]);return t.useEffect(function(){return function(){void 0!==O.current&&clearTimeout(O.current)}},[]),t.useEffect(function(){P.current=e},[e]),t.useMemo(function(){return function(n){var t={onMouseDown:D(n),onMouseMove:R(n),onMouseUp:b(n),onMouseLeave:b(n)},o={onTouchStart:D(n),onTouchMove:R(n),onTouchEnd:b(n)};return null===e?{}:l===exports.LongPressDetectEvents.MOUSE?t:l===exports.LongPressDetectEvents.TOUCH?o:r({},t,o)}},[e,b,l,R,D])};
//# sourceMappingURL=index.js.map

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

import{useRef as n,useCallback as t,useEffect as e,useMemo as r}from"react";function o(){return(o=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}var u,c;function i(n){var t=n.nativeEvent;return window.TouchEvent?t instanceof TouchEvent:"touches"in t}function a(n){return n.nativeEvent instanceof MouseEvent}function v(n){return i(n)?{x:n.touches[0].pageX,y:n.touches[0].pageY}:a(n)?{x:n.pageX,y:n.pageY}:null}function f(f,l){var s=void 0===l?{}:l,E=s.threshold,M=void 0===E?400:E,h=s.captureEvent,T=void 0!==h&&h,d=s.detect,p=void 0===d?c.BOTH:d,O=s.cancelOnMovement,y=void 0!==O&&O,C=s.filterEvents,m=s.onStart,x=s.onMove,_=s.onFinish,b=s.onCancel,U=n(!1),g=n(!1),B=n(),N=n(f),Y=n(null),D=t(function(n){return function(t){if(!g.current&&(a(t)||i(t))&&(void 0===C||C(t))){Y.current=v(t),T&&t.persist();var e=void 0===n?{}:{context:n};null==m||m(t,e),g.current=!0,B.current=setTimeout(function(){N.current&&(N.current(t,e),U.current=!0)},M)}}},[T,C,m,M]),L=t(function(n,t){return function(e){if(a(e)||i(e)){Y.current=null,T&&e.persist();var r=void 0===n?{}:{context:n};U.current?null==_||_(e,r):g.current&&(null==b||b(e,o({},r,{reason:null!=t?t:u.CANCELED_BY_TIMEOUT}))),U.current=!1,g.current=!1,void 0!==B.current&&clearTimeout(B.current)}}},[T,_,b]),w=t(function(n){return function(t){if(null==x||x(t,{context:n}),y&&Y.current){var e=v(t);if(e){var r=!0===y?25:y,o={x:Math.abs(e.x-Y.current.x),y:Math.abs(e.y-Y.current.y)};(o.x>r||o.y>r)&&L(n,u.CANCELED_BY_MOVEMENT)(t)}}}},[L,y,x]);return e(function(){return function(){void 0!==B.current&&clearTimeout(B.current)}},[]),e(function(){N.current=f},[f]),r(function(){return function(n){var t={onMouseDown:D(n),onMouseMove:w(n),onMouseUp:L(n),onMouseLeave:L(n)},e={onTouchStart:D(n),onTouchMove:w(n),onTouchEnd:L(n)};return null===f?{}:p===c.MOUSE?t:p===c.TOUCH?e:o({},t,e)}},[f,L,p,w,D])}!function(n){n.CANCELED_BY_MOVEMENT="canceled-by-movement",n.CANCELED_BY_TIMEOUT="canceled-by-timeout"}(u||(u={})),function(n){n.BOTH="both",n.MOUSE="mouse",n.TOUCH="touch"}(c||(c={}));export{f as useLongPress};
import{useRef as n,useCallback as t,useEffect as e,useMemo as r}from"react";function o(){return(o=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n}).apply(this,arguments)}var u,c;function i(n){var t=n.nativeEvent;return window.TouchEvent?t instanceof TouchEvent:"touches"in t}function a(n){return n.nativeEvent instanceof MouseEvent}function v(n){return i(n)?{x:n.touches[0].pageX,y:n.touches[0].pageY}:a(n)?{x:n.pageX,y:n.pageY}:null}function f(f,l){var s=void 0===l?{}:l,E=s.threshold,M=void 0===E?400:E,h=s.captureEvent,T=void 0!==h&&h,d=s.detect,p=void 0===d?c.BOTH:d,O=s.cancelOnMovement,y=void 0!==O&&O,C=s.filterEvents,m=s.onStart,x=s.onMove,_=s.onFinish,b=s.onCancel,U=n(!1),g=n(!1),B=n(),N=n(f),Y=n(null),D=t(function(n){return function(t){if(!g.current&&(a(t)||i(t))&&(void 0===C||C(t))){Y.current=v(t),T&&t.persist();var e=void 0===n?{}:{context:n};null==m||m(t,e),g.current=!0,B.current=setTimeout(function(){N.current&&(N.current(t,e),U.current=!0)},M)}}},[T,C,m,M]),L=t(function(n,t){return function(e){if(a(e)||i(e)){Y.current=null,T&&e.persist();var r=void 0===n?{}:{context:n};U.current?null==_||_(e,r):g.current&&(null==b||b(e,o({},r,{reason:null!=t?t:u.CANCELED_BY_TIMEOUT}))),U.current=!1,g.current=!1,void 0!==B.current&&clearTimeout(B.current)}}},[T,_,b]),w=t(function(n){return function(t){if(null==x||x(t,{context:n}),y&&Y.current){var e=v(t);if(e){var r=!0===y?25:y,o={x:Math.abs(e.x-Y.current.x),y:Math.abs(e.y-Y.current.y)};(o.x>r||o.y>r)&&L(n,u.CANCELED_BY_MOVEMENT)(t)}}}},[L,y,x]);return e(function(){return function(){void 0!==B.current&&clearTimeout(B.current)}},[]),e(function(){N.current=f},[f]),r(function(){return function(n){var t={onMouseDown:D(n),onMouseMove:w(n),onMouseUp:L(n),onMouseLeave:L(n)},e={onTouchStart:D(n),onTouchMove:w(n),onTouchEnd:L(n)};return null===f?{}:p===c.MOUSE?t:p===c.TOUCH?e:o({},t,e)}},[f,L,p,w,D])}!function(n){n.CANCELED_BY_MOVEMENT="canceled-by-movement",n.CANCELED_BY_TIMEOUT="canceled-by-timeout"}(u||(u={})),function(n){n.BOTH="both",n.MOUSE="mouse",n.TOUCH="touch"}(c||(c={}));export{c as LongPressDetectEvents,u as LongPressEventReason,f as useLongPress};
//# sourceMappingURL=index.module.js.map

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self).useLongPress={},e.react)}(this,function(e,n){function t(){return(t=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var u in t)Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u])}return e}).apply(this,arguments)}var u,r;function o(e){var n=e.nativeEvent;return window.TouchEvent?n instanceof TouchEvent:"touches"in n}function c(e){return e.nativeEvent instanceof MouseEvent}function i(e){return o(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:c(e)?{x:e.pageX,y:e.pageY}:null}!function(e){e.CANCELED_BY_MOVEMENT="canceled-by-movement",e.CANCELED_BY_TIMEOUT="canceled-by-timeout"}(u||(u={})),function(e){e.BOTH="both",e.MOUSE="mouse",e.TOUCH="touch"}(r||(r={})),e.useLongPress=function(e,f){var a=void 0===f?{}:f,s=a.threshold,l=void 0===s?400:s,v=a.captureEvent,E=void 0!==v&&v,d=a.detect,h=void 0===d?r.BOTH:d,p=a.cancelOnMovement,M=void 0!==p&&p,T=a.filterEvents,y=a.onStart,C=a.onMove,O=a.onFinish,b=a.onCancel,x=n.useRef(!1),m=n.useRef(!1),g=n.useRef(),_=n.useRef(e),L=n.useRef(null),U=n.useCallback(function(e){return function(n){if(!m.current&&(c(n)||o(n))&&(void 0===T||T(n))){L.current=i(n),E&&n.persist();var t=void 0===e?{}:{context:e};null==y||y(n,t),m.current=!0,g.current=setTimeout(function(){_.current&&(_.current(n,t),x.current=!0)},l)}}},[E,T,y,l]),B=n.useCallback(function(e,n){return function(r){if(c(r)||o(r)){L.current=null,E&&r.persist();var i=void 0===e?{}:{context:e};x.current?null==O||O(r,i):m.current&&(null==b||b(r,t({},i,{reason:null!=n?n:u.CANCELED_BY_TIMEOUT}))),x.current=!1,m.current=!1,void 0!==g.current&&clearTimeout(g.current)}}},[E,O,b]),N=n.useCallback(function(e){return function(n){if(null==C||C(n,{context:e}),M&&L.current){var t=i(n);if(t){var r=!0===M?25:M,o={x:Math.abs(t.x-L.current.x),y:Math.abs(t.y-L.current.y)};(o.x>r||o.y>r)&&B(e,u.CANCELED_BY_MOVEMENT)(n)}}}},[B,M,C]);return n.useEffect(function(){return function(){void 0!==g.current&&clearTimeout(g.current)}},[]),n.useEffect(function(){_.current=e},[e]),n.useMemo(function(){return function(n){var u={onMouseDown:U(n),onMouseMove:N(n),onMouseUp:B(n),onMouseLeave:B(n)},o={onTouchStart:U(n),onTouchMove:N(n),onTouchEnd:B(n)};return null===e?{}:h===r.MOUSE?u:h===r.TOUCH?o:t({},u,o)}},[e,B,h,N,U])}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],n):n((e||self).useLongPress={},e.react)}(this,function(e,n){function t(){return(t=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e}).apply(this,arguments)}var o,r;function u(e){var n=e.nativeEvent;return window.TouchEvent?n instanceof TouchEvent:"touches"in n}function c(e){return e.nativeEvent instanceof MouseEvent}function s(e){return u(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:c(e)?{x:e.pageX,y:e.pageY}:null}e.LongPressEventReason=void 0,(o=e.LongPressEventReason||(e.LongPressEventReason={})).CANCELED_BY_MOVEMENT="canceled-by-movement",o.CANCELED_BY_TIMEOUT="canceled-by-timeout",e.LongPressDetectEvents=void 0,(r=e.LongPressDetectEvents||(e.LongPressDetectEvents={})).BOTH="both",r.MOUSE="mouse",r.TOUCH="touch",e.useLongPress=function(o,r){var i=void 0===r?{}:r,a=i.threshold,f=void 0===a?400:a,v=i.captureEvent,l=void 0!==v&&v,E=i.detect,d=void 0===E?e.LongPressDetectEvents.BOTH:E,g=i.cancelOnMovement,h=void 0!==g&&g,p=i.filterEvents,M=i.onStart,T=i.onMove,L=i.onFinish,y=i.onCancel,C=n.useRef(!1),O=n.useRef(!1),P=n.useRef(),b=n.useRef(o),x=n.useRef(null),m=n.useCallback(function(e){return function(n){if(!O.current&&(c(n)||u(n))&&(void 0===p||p(n))){x.current=s(n),l&&n.persist();var t=void 0===e?{}:{context:e};null==M||M(n,t),O.current=!0,P.current=setTimeout(function(){b.current&&(b.current(n,t),C.current=!0)},f)}}},[l,p,M,f]),D=n.useCallback(function(n,o){return function(r){if(c(r)||u(r)){x.current=null,l&&r.persist();var s=void 0===n?{}:{context:n};C.current?null==L||L(r,s):O.current&&(null==y||y(r,t({},s,{reason:null!=o?o:e.LongPressEventReason.CANCELED_BY_TIMEOUT}))),C.current=!1,O.current=!1,void 0!==P.current&&clearTimeout(P.current)}}},[l,L,y]),R=n.useCallback(function(n){return function(t){if(null==T||T(t,{context:n}),h&&x.current){var o=s(t);if(o){var r=!0===h?25:h,u={x:Math.abs(o.x-x.current.x),y:Math.abs(o.y-x.current.y)};(u.x>r||u.y>r)&&D(n,e.LongPressEventReason.CANCELED_BY_MOVEMENT)(t)}}}},[D,h,T]);return n.useEffect(function(){return function(){void 0!==P.current&&clearTimeout(P.current)}},[]),n.useEffect(function(){b.current=o},[o]),n.useMemo(function(){return function(n){var r={onMouseDown:m(n),onMouseMove:R(n),onMouseUp:D(n),onMouseLeave:D(n)},u={onTouchStart:m(n),onTouchMove:R(n),onTouchEnd:D(n)};return null===o?{}:d===e.LongPressDetectEvents.MOUSE?r:d===e.LongPressDetectEvents.TOUCH?u:t({},r,u)}},[o,D,d,R,m])}});
//# sourceMappingURL=index.umd.js.map
{
"name": "use-long-press",
"version": "2.0.0",
"version": "2.0.2",
"description": "React hook for detecting click (or tap) and hold event. Easy to use, highly customizable options, thoroughly tested.",

@@ -50,3 +50,3 @@ "author": "minwork",

"peerDependencies": {
"react": "^16.8.0 || ^17.0.0"
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},

@@ -53,0 +53,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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