From 49dda19c97046a8f158a37b210a5a704a5b9166f Mon Sep 17 00:00:00 2001 From: Alireza Date: Tue, 30 Jan 2024 18:53:58 +0100 Subject: [PATCH] feat(realSwipe): add `touchMoveDelay` option closes #620 --- README.md | 1 + cypress/e2e/swipe.cy.ts | 11 +++++++++++ .../swipe-touch-move-delay/index.f3612ef8.js | 2 ++ cypress/fixtures/swipe-touch-move-delay/index.html | 12 ++++++++++++ src/commands/realPress.ts | 3 ++- src/commands/realSwipe.ts | 14 ++++++++++++++ src/commands/realType.ts | 3 ++- src/utils.ts | 6 ++++++ 8 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 cypress/fixtures/swipe-touch-move-delay/index.f3612ef8.js create mode 100644 cypress/fixtures/swipe-touch-move-delay/index.html create mode 100644 src/utils.ts diff --git a/README.md b/README.md index 5dad939..58191b1 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,7 @@ Options: - `Optional` **x**: undefined \| number ([more about coordinates](#coordinates)) - `Optional` **y**: undefined \| number ([more about coordinates](#coordinates)) - `Optional` **touchPosition**: "topLeft" | "top" | "topRight" | "left" | "center" | "right" | "bottomLeft" | "bottom" | "bottomRight" +- `Optional` **touchMoveDelay**: undefined \| number **`default`** 0 ## cy.realMouseDown diff --git a/cypress/e2e/swipe.cy.ts b/cypress/e2e/swipe.cy.ts index ce0971a..7e38e49 100644 --- a/cypress/e2e/swipe.cy.ts +++ b/cypress/e2e/swipe.cy.ts @@ -57,3 +57,14 @@ describe("cy.realSwipe", () => { }); }); }); + +describe("touchMoveDelay", () => { + it("adds a delay between touch start and touch move events", () => { + cy.visit("./cypress/fixtures/swipe-touch-move-delay"); + cy.get("[role=gridcell]").contains("14").realSwipe("toRight", { + touchMoveDelay: 300, + length: 70, + }); + cy.get("[role=gridcell][aria-selected=true]").should("have.length", 3); + }); +}); diff --git a/cypress/fixtures/swipe-touch-move-delay/index.f3612ef8.js b/cypress/fixtures/swipe-touch-move-delay/index.f3612ef8.js new file mode 100644 index 0000000..af4f529 --- /dev/null +++ b/cypress/fixtures/swipe-touch-move-delay/index.f3612ef8.js @@ -0,0 +1,2 @@ +let e,t,n;function r(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}function a(e){return e&&e.__esModule?e.default:e}var u,l,i,o,s,c,d,f,p,m,h,g,v,y,b,D,E,w,x,C,S,k,B,F,P,R,_,T,M,I,L,A,N,$,z,O,U,j,H,q,V,W,Y,Q,K,G,X,Z,J,ee,et,en,er,ea,eu,el,ei,eo,es,ec,ed,ef,ep,em,eh,eg,ev,ey,eb,eD,eE,ew,ex,eC,eS,ek,eB,eF,eP,eR,e_,eT,eM,eI,eL,eA,eN,e$,ez,eO,eU,ej,eH,eq,eV,eW,eY,eQ,eK,eG,eX,eZ,eJ,e0,e1,e4,e3,e2,e5,e6,e8,e7,e9,te,tt,tn,tr,ta,tu,tl,ti,to,ts,tc,td,tf,tp,tm,th,tg,tv,ty,tb,tD,tE,tw,tx,tC,tS,tk,tB,tF,tP,tR,t_,tT,tM,tI,tL,tA,tN,t$,tz,tO,tU,tj,tH,tq,tV,tW,tY,tQ,tK,tG,tX,tZ,tJ,t0,t1,t4,t3,t2,t5,t6,t8,t7,t9,ne,nt,nn,nr,na,nu,nl,ni,no,ns,nc,nd,nf,np,nm,nh,ng,nv,ny,nb,nD,nE,nw,nx,nC,nS,nk,nB,nF,nP,nR,n_,nT,nM,nI,nL,nA,nN,n$,nz,nO,nU,nj,nH,nq,nV,nW,nY,nQ,nK,nG,nX,nZ,nJ,n0,n1,n4,n3,n2,n5,n6,n8,n7,n9,re,rt,rn,rr,ra,ru,rl,ri,ro,rs,rc,rd,rf,rp,rm,rh,rg,rv,ry,rb,rD,rE,rw,rx,rC,rS,rk,rB,rF=globalThis,rP={},rR={},r_=rF.parcelRequire52ef;null==r_&&((r_=function(e){if(e in rP)return rP[e].exports;if(e in rR){var t=rR[e];delete rR[e];var n={id:e,exports:{}};return rP[e]=n,t.call(n.exports,n,n.exports),n.exports}var r=Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}).register=function(e,t){rR[e]=t},rF.parcelRequire52ef=r_);var rT=r_.register;rT("1b2ls",function(e,t){r(e.exports,"Fragment",()=>n,e=>n=e),r(e.exports,"jsx",()=>a,e=>a=e),r(e.exports,"jsxs",()=>u,e=>u=e);var n,a,u,l=r_("acw62"),i=Symbol.for("react.element"),o=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,c=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,d={key:!0,ref:!0,__self:!0,__source:!0};function f(e,t,n){var r,a={},u=null,l=null;for(r in void 0!==n&&(u=""+n),void 0!==t.key&&(u=""+t.key),void 0!==t.ref&&(l=t.ref),t)s.call(t,r)&&!d.hasOwnProperty(r)&&(a[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===a[r]&&(a[r]=t[r]);return{$$typeof:i,type:e,key:u,ref:l,props:a,_owner:c.current}}n=o,a=f,u=f}),rT("acw62",function(e,t){e.exports=r_("2pUnB")}),rT("2pUnB",function(e,t){r(e.exports,"Children",()=>n,e=>n=e),r(e.exports,"Component",()=>a,e=>a=e),r(e.exports,"Fragment",()=>u,e=>u=e),r(e.exports,"Profiler",()=>l,e=>l=e),r(e.exports,"PureComponent",()=>i,e=>i=e),r(e.exports,"StrictMode",()=>o,e=>o=e),r(e.exports,"Suspense",()=>s,e=>s=e),r(e.exports,"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",()=>c,e=>c=e),r(e.exports,"cloneElement",()=>d,e=>d=e),r(e.exports,"createContext",()=>f,e=>f=e),r(e.exports,"createElement",()=>p,e=>p=e),r(e.exports,"createFactory",()=>m,e=>m=e),r(e.exports,"createRef",()=>h,e=>h=e),r(e.exports,"forwardRef",()=>g,e=>g=e),r(e.exports,"isValidElement",()=>v,e=>v=e),r(e.exports,"lazy",()=>y,e=>y=e),r(e.exports,"memo",()=>b,e=>b=e),r(e.exports,"startTransition",()=>D,e=>D=e),r(e.exports,"unstable_act",()=>E,e=>E=e),r(e.exports,"useCallback",()=>w,e=>w=e),r(e.exports,"useContext",()=>x,e=>x=e),r(e.exports,"useDebugValue",()=>C,e=>C=e),r(e.exports,"useDeferredValue",()=>S,e=>S=e),r(e.exports,"useEffect",()=>k,e=>k=e),r(e.exports,"useId",()=>B,e=>B=e),r(e.exports,"useImperativeHandle",()=>F,e=>F=e),r(e.exports,"useInsertionEffect",()=>P,e=>P=e),r(e.exports,"useLayoutEffect",()=>R,e=>R=e),r(e.exports,"useMemo",()=>_,e=>_=e),r(e.exports,"useReducer",()=>T,e=>T=e),r(e.exports,"useRef",()=>M,e=>M=e),r(e.exports,"useState",()=>I,e=>I=e),r(e.exports,"useSyncExternalStore",()=>L,e=>L=e),r(e.exports,"useTransition",()=>A,e=>A=e),r(e.exports,"version",()=>N,e=>N=e);var n,a,u,l,i,o,s,c,d,f,p,m,h,g,v,y,b,D,E,w,x,C,S,k,B,F,P,R,_,T,M,I,L,A,N,$=Symbol.for("react.element"),z=Symbol.for("react.portal"),O=Symbol.for("react.fragment"),U=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),H=Symbol.for("react.provider"),q=Symbol.for("react.context"),V=Symbol.for("react.forward_ref"),W=Symbol.for("react.suspense"),Y=Symbol.for("react.memo"),Q=Symbol.for("react.lazy"),K=Symbol.iterator,G={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},X=Object.assign,Z={};function J(e,t,n){this.props=e,this.context=t,this.refs=Z,this.updater=n||G}function ee(){}function et(e,t,n){this.props=e,this.context=t,this.refs=Z,this.updater=n||G}J.prototype.isReactComponent={},J.prototype.setState=function(e,t){if("object"!=typeof e&&"function"!=typeof e&&null!=e)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")},J.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},ee.prototype=J.prototype;var en=et.prototype=new ee;en.constructor=et,X(en,J.prototype),en.isPureReactComponent=!0;var er=Array.isArray,ea=Object.prototype.hasOwnProperty,eu={current:null},el={key:!0,ref:!0,__self:!0,__source:!0};function ei(e,t,n){var r,a={},u=null,l=null;if(null!=t)for(r in void 0!==t.ref&&(l=t.ref),void 0!==t.key&&(u=""+t.key),t)ea.call(t,r)&&!el.hasOwnProperty(r)&&(a[r]=t[r]);var i=arguments.length-2;if(1===i)a.children=n;else if(1j,e=>j=e),r(e.exports,"createPortal",()=>H,e=>H=e),r(e.exports,"createRoot",()=>q,e=>q=e),r(e.exports,"findDOMNode",()=>V,e=>V=e),r(e.exports,"flushSync",()=>W,e=>W=e),r(e.exports,"hydrate",()=>Y,e=>Y=e),r(e.exports,"hydrateRoot",()=>Q,e=>Q=e),r(e.exports,"render",()=>K,e=>K=e),r(e.exports,"unmountComponentAtNode",()=>G,e=>G=e),r(e.exports,"unstable_batchedUpdates",()=>X,e=>X=e),r(e.exports,"unstable_renderSubtreeIntoContainer",()=>Z,e=>Z=e),r(e.exports,"version",()=>J,e=>J=e);var n,a,u,l,i,o,s=r_("acw62"),c=r_("fO90s");function d(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n