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 1.1.0 to 1.1.1

8

dist/index.d.ts

@@ -9,3 +9,3 @@ import { MouseEvent as ReactMouseEvent, MouseEventHandler, TouchEvent as ReactTouchEvent, TouchEventHandler } from 'react';

}
export declare type LongPressResult<Target, Callback, DetectType extends LongPressDetectEvents = LongPressDetectEvents.BOTH> = DetectType extends LongPressDetectEvents.BOTH ? {
export declare type LongPressResult<Target, DetectType extends LongPressDetectEvents = LongPressDetectEvents.BOTH> = DetectType extends LongPressDetectEvents.BOTH ? {
onMouseDown: MouseEventHandler<Target>;

@@ -38,4 +38,4 @@ onMouseUp: MouseEventHandler<Target>;

}
export declare function useLongPress<Target = Element>(callback: null, options?: LongPressOptions<Target>): {};
export declare function useLongPress<Target = Element, Callback extends LongPressCallback<Target> = LongPressCallback<Target>>(callback: Callback, options?: LongPressOptions<Target>): LongPressResult<Target, Callback>;
export declare function useLongPress<Target = Element, Callback extends LongPressCallback<Target> = LongPressCallback<Target>>(callback: Callback | null, options?: LongPressOptions<Target>): LongPressResult<Target, Callback> | {};
export declare function useLongPress<Target = Element>(callback: null, options?: LongPressOptions<Target>): Record<string, never>;
export declare function useLongPress<Target = Element, Callback extends LongPressCallback<Target> = LongPressCallback<Target>>(callback: Callback, options?: LongPressOptions<Target>): LongPressResult<Target>;
export declare function useLongPress<Target = Element, Callback extends LongPressCallback<Target> = LongPressCallback<Target>>(callback: Callback | null, options?: LongPressOptions<Target>): LongPressResult<Target> | Record<string, never>;

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

var e,n=require("react");function t(){return(t=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 r(e){return e.nativeEvent instanceof TouchEvent}function u(e){return e.nativeEvent instanceof MouseEvent}function o(e){return r(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:u(e)?{x:e.pageX,y:e.pageY}:null}exports.LongPressDetectEvents=void 0,(e=exports.LongPressDetectEvents||(exports.LongPressDetectEvents={})).BOTH="both",e.MOUSE="mouse",e.TOUCH="touch",exports.useLongPress=function(e,c){var s=void 0===c?{}:c,a=s.threshold,l=void 0===a?400:a,i=s.captureEvent,v=void 0!==i&&i,f=s.detect,p=void 0===f?exports.LongPressDetectEvents.BOTH:f,h=s.cancelOnMovement,E=void 0!==h&&h,g=s.onStart,x=s.onMove,M=s.onFinish,d=s.onCancel,T=n.useRef(!1),O=n.useRef(!1),y=n.useRef(),b=n.useRef(e),L=n.useRef(null),P=n.useCallback(function(e){O.current||(u(e)||r(e))&&(L.current=o(e),v&&e.persist(),v?null==g||g(e):null==g||g(),O.current=!0,y.current=setTimeout(function(){b.current&&(v?b.current(e):b.current(),T.current=!0)},l))},[v,g,l]),D=n.useCallback(function(e){(u(e)||r(e))&&(L.current=null,v&&e.persist(),T.current?v?null==M||M(e):null==M||M():O.current&&(v?null==d||d(e):null==d||d()),T.current=!1,O.current=!1,void 0!==y.current&&clearTimeout(y.current))},[v,M,d]),C=n.useCallback(function(e){if(v?null==x||x(e):null==x||x(),E&&L.current){var n=o(e);if(n){var t=!0===E?25:E,r={x:Math.abs(n.x-L.current.x),y:Math.abs(n.y-L.current.y)};(r.x>t||r.y>t)&&D(e)}}},[D,E,v,x]);n.useEffect(function(){return function(){void 0!==y.current&&clearTimeout(y.current)}},[]),n.useEffect(function(){b.current=e},[e]);var m={onMouseDown:P,onMouseMove:C,onMouseUp:D,onMouseLeave:D},R={onTouchStart:P,onTouchMove:C,onTouchEnd:D};return null===e?{}:p===exports.LongPressDetectEvents.MOUSE?m:p===exports.LongPressDetectEvents.TOUCH?R:t({},m,R)};
var e,n=require("react");function t(){return(t=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 r(e){var n=e.nativeEvent;return window.TouchEvent?n instanceof TouchEvent:"touches"in n}function u(e){return e.nativeEvent instanceof MouseEvent}function o(e){return r(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:u(e)?{x:e.pageX,y:e.pageY}:null}exports.LongPressDetectEvents=void 0,(e=exports.LongPressDetectEvents||(exports.LongPressDetectEvents={})).BOTH="both",e.MOUSE="mouse",e.TOUCH="touch",exports.useLongPress=function(e,c){var s=void 0===c?{}:c,a=s.threshold,i=void 0===a?400:a,l=s.captureEvent,v=void 0!==l&&l,f=s.detect,p=void 0===f?exports.LongPressDetectEvents.BOTH:f,h=s.cancelOnMovement,E=void 0!==h&&h,g=s.onStart,x=s.onMove,M=s.onFinish,d=s.onCancel,T=n.useRef(!1),O=n.useRef(!1),y=n.useRef(),b=n.useRef(e),L=n.useRef(null),P=n.useCallback(function(e){O.current||(u(e)||r(e))&&(L.current=o(e),v&&e.persist(),v?null==g||g(e):null==g||g(),O.current=!0,y.current=setTimeout(function(){b.current&&(v?b.current(e):b.current(),T.current=!0)},i))},[v,g,i]),D=n.useCallback(function(e){(u(e)||r(e))&&(L.current=null,v&&e.persist(),T.current?v?null==M||M(e):null==M||M():O.current&&(v?null==d||d(e):null==d||d()),T.current=!1,O.current=!1,void 0!==y.current&&clearTimeout(y.current))},[v,M,d]),C=n.useCallback(function(e){if(v?null==x||x(e):null==x||x(),E&&L.current){var n=o(e);if(n){var t=!0===E?25:E,r={x:Math.abs(n.x-L.current.x),y:Math.abs(n.y-L.current.y)};(r.x>t||r.y>t)&&D(e)}}},[D,E,v,x]);n.useEffect(function(){return function(){void 0!==y.current&&clearTimeout(y.current)}},[]),n.useEffect(function(){b.current=e},[e]);var m={onMouseDown:P,onMouseMove:C,onMouseUp:D,onMouseLeave:D},R={onTouchStart:P,onTouchMove:C,onTouchEnd:D};return null===e?{}:p===exports.LongPressDetectEvents.MOUSE?m:p===exports.LongPressDetectEvents.TOUCH?R:t({},m,R)};
//# sourceMappingURL=index.js.map

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

import{useRef as n,useCallback as t,useEffect as r}from"react";function e(){return(e=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n}).apply(this,arguments)}function u(n){return n.nativeEvent instanceof TouchEvent}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}var i;function a(a,l){var v=void 0===l?{}:l,s=v.threshold,f=void 0===s?400:s,h=v.captureEvent,p=void 0!==h&&h,M=v.detect,T=void 0===M?i.BOTH:M,d=v.cancelOnMovement,O=void 0!==d&&d,y=v.onStart,E=v.onMove,m=v.onFinish,x=v.onCancel,g=n(!1),b=n(!1),U=n(),H=n(a),S=n(null),C=t(function(n){b.current||(o(n)||u(n))&&(S.current=c(n),p&&n.persist(),p?null==y||y(n):null==y||y(),b.current=!0,U.current=setTimeout(function(){H.current&&(p?H.current(n):H.current(),g.current=!0)},f))},[p,y,f]),j=t(function(n){(o(n)||u(n))&&(S.current=null,p&&n.persist(),g.current?p?null==m||m(n):null==m||m():b.current&&(p?null==x||x(n):null==x||x()),g.current=!1,b.current=!1,void 0!==U.current&&clearTimeout(U.current))},[p,m,x]),w=t(function(n){if(p?null==E||E(n):null==E||E(),O&&S.current){var t=c(n);if(t){var r=!0===O?25:O,e={x:Math.abs(t.x-S.current.x),y:Math.abs(t.y-S.current.y)};(e.x>r||e.y>r)&&j(n)}}},[j,O,p,E]);r(function(){return function(){void 0!==U.current&&clearTimeout(U.current)}},[]),r(function(){H.current=a},[a]);var B={onMouseDown:C,onMouseMove:w,onMouseUp:j,onMouseLeave:j},X={onTouchStart:C,onTouchMove:w,onTouchEnd:j};return null===a?{}:T===i.MOUSE?B:T===i.TOUCH?X:e({},B,X)}!function(n){n.BOTH="both",n.MOUSE="mouse",n.TOUCH="touch"}(i||(i={}));export{i as LongPressDetectEvents,a as useLongPress};
import{useRef as n,useCallback as t,useEffect as r}from"react";function e(){return(e=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n}).apply(this,arguments)}function u(n){var t=n.nativeEvent;return window.TouchEvent?t instanceof TouchEvent:"touches"in t}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}var i;function a(a,l){var v=void 0===l?{}:l,s=v.threshold,f=void 0===s?400:s,h=v.captureEvent,p=void 0!==h&&h,M=v.detect,T=void 0===M?i.BOTH:M,d=v.cancelOnMovement,O=void 0!==d&&d,y=v.onStart,E=v.onMove,m=v.onFinish,x=v.onCancel,g=n(!1),b=n(!1),U=n(),w=n(a),H=n(null),S=t(function(n){b.current||(o(n)||u(n))&&(H.current=c(n),p&&n.persist(),p?null==y||y(n):null==y||y(),b.current=!0,U.current=setTimeout(function(){w.current&&(p?w.current(n):w.current(),g.current=!0)},f))},[p,y,f]),C=t(function(n){(o(n)||u(n))&&(H.current=null,p&&n.persist(),g.current?p?null==m||m(n):null==m||m():b.current&&(p?null==x||x(n):null==x||x()),g.current=!1,b.current=!1,void 0!==U.current&&clearTimeout(U.current))},[p,m,x]),j=t(function(n){if(p?null==E||E(n):null==E||E(),O&&H.current){var t=c(n);if(t){var r=!0===O?25:O,e={x:Math.abs(t.x-H.current.x),y:Math.abs(t.y-H.current.y)};(e.x>r||e.y>r)&&C(n)}}},[C,O,p,E]);r(function(){return function(){void 0!==U.current&&clearTimeout(U.current)}},[]),r(function(){w.current=a},[a]);var B={onMouseDown:S,onMouseMove:j,onMouseUp:C,onMouseLeave:C},X={onTouchStart:S,onTouchMove:j,onTouchEnd:C};return null===a?{}:T===i.MOUSE?B:T===i.TOUCH?X:e({},B,X)}!function(n){n.BOTH="both",n.MOUSE="mouse",n.TOUCH="touch"}(i||(i={}));export{i as LongPressDetectEvents,a 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 r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function r(e){return e.nativeEvent instanceof TouchEvent}function u(e){return e.nativeEvent instanceof MouseEvent}function o(e){return r(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:u(e)?{x:e.pageX,y:e.pageY}:null}var c;e.LongPressDetectEvents=void 0,(c=e.LongPressDetectEvents||(e.LongPressDetectEvents={})).BOTH="both",c.MOUSE="mouse",c.TOUCH="touch",e.useLongPress=function(c,s){var i=void 0===s?{}:s,l=i.threshold,a=void 0===l?400:l,f=i.captureEvent,v=void 0!==f&&f,d=i.detect,p=void 0===d?e.LongPressDetectEvents.BOTH:d,h=i.cancelOnMovement,g=void 0!==h&&h,E=i.onStart,y=i.onMove,M=i.onFinish,T=i.onCancel,b=n.useRef(!1),O=n.useRef(!1),x=n.useRef(),L=n.useRef(c),P=n.useRef(null),m=n.useCallback(function(e){O.current||(u(e)||r(e))&&(P.current=o(e),v&&e.persist(),v?null==E||E(e):null==E||E(),O.current=!0,x.current=setTimeout(function(){L.current&&(v?L.current(e):L.current(),b.current=!0)},a))},[v,E,a]),D=n.useCallback(function(e){(u(e)||r(e))&&(P.current=null,v&&e.persist(),b.current?v?null==M||M(e):null==M||M():O.current&&(v?null==T||T(e):null==T||T()),b.current=!1,O.current=!1,void 0!==x.current&&clearTimeout(x.current))},[v,M,T]),C=n.useCallback(function(e){if(v?null==y||y(e):null==y||y(),g&&P.current){var n=o(e);if(n){var t=!0===g?25:g,r={x:Math.abs(n.x-P.current.x),y:Math.abs(n.y-P.current.y)};(r.x>t||r.y>t)&&D(e)}}},[D,g,v,y]);n.useEffect(function(){return function(){void 0!==x.current&&clearTimeout(x.current)}},[]),n.useEffect(function(){L.current=c},[c]);var R={onMouseDown:m,onMouseMove:C,onMouseUp:D,onMouseLeave:D},U={onTouchStart:m,onTouchMove:C,onTouchEnd:D};return null===c?{}:p===e.LongPressDetectEvents.MOUSE?R:p===e.LongPressDetectEvents.TOUCH?U:t({},R,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 r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function r(e){var n=e.nativeEvent;return window.TouchEvent?n instanceof TouchEvent:"touches"in n}function u(e){return e.nativeEvent instanceof MouseEvent}function o(e){return r(e)?{x:e.touches[0].pageX,y:e.touches[0].pageY}:u(e)?{x:e.pageX,y:e.pageY}:null}var c;e.LongPressDetectEvents=void 0,(c=e.LongPressDetectEvents||(e.LongPressDetectEvents={})).BOTH="both",c.MOUSE="mouse",c.TOUCH="touch",e.useLongPress=function(c,s){var i=void 0===s?{}:s,a=i.threshold,l=void 0===a?400:a,f=i.captureEvent,v=void 0!==f&&f,d=i.detect,h=void 0===d?e.LongPressDetectEvents.BOTH:d,p=i.cancelOnMovement,E=void 0!==p&&p,g=i.onStart,T=i.onMove,y=i.onFinish,M=i.onCancel,b=n.useRef(!1),O=n.useRef(!1),x=n.useRef(),L=n.useRef(c),P=n.useRef(null),m=n.useCallback(function(e){O.current||(u(e)||r(e))&&(P.current=o(e),v&&e.persist(),v?null==g||g(e):null==g||g(),O.current=!0,x.current=setTimeout(function(){L.current&&(v?L.current(e):L.current(),b.current=!0)},l))},[v,g,l]),D=n.useCallback(function(e){(u(e)||r(e))&&(P.current=null,v&&e.persist(),b.current?v?null==y||y(e):null==y||y():O.current&&(v?null==M||M(e):null==M||M()),b.current=!1,O.current=!1,void 0!==x.current&&clearTimeout(x.current))},[v,y,M]),C=n.useCallback(function(e){if(v?null==T||T(e):null==T||T(),E&&P.current){var n=o(e);if(n){var t=!0===E?25:E,r={x:Math.abs(n.x-P.current.x),y:Math.abs(n.y-P.current.y)};(r.x>t||r.y>t)&&D(e)}}},[D,E,v,T]);n.useEffect(function(){return function(){void 0!==x.current&&clearTimeout(x.current)}},[]),n.useEffect(function(){L.current=c},[c]);var R={onMouseDown:m,onMouseMove:C,onMouseUp:D,onMouseLeave:D},U={onTouchStart:m,onTouchMove:C,onTouchEnd:D};return null===c?{}:h===e.LongPressDetectEvents.MOUSE?R:h===e.LongPressDetectEvents.TOUCH?U:t({},R,U)}});
//# sourceMappingURL=index.umd.js.map
{
"name": "use-long-press",
"version": "1.1.0",
"version": "1.1.1",
"description": "React hook for detecting click (or tap) 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

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