From 33ac099ce9364d9d5e6cecf264ee7d94b1fad078 Mon Sep 17 00:00:00 2001 From: Anton Lavrenov Date: Wed, 3 Jun 2020 13:57:57 -0500 Subject: [PATCH] fix dblclick and dbltap triggers. fix #917 --- CHANGELOG.md | 5 +- konva.js | 4 +- konva.min.js | 4 +- src/Stage.ts | 2 + test/functional/MouseEvents-test.js | 72 +++++++++++++++++++++++++++++ test/functional/TouchEvents-test.js | 72 +++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41ba3a01..3a402bb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Not released: * `inherit` option is removed from `visible` and `listening`. They now just have boolean values `true` or `false`. If you do `group.listeng(false);` then whole group and all its children will be removed from the hitgraph (and they will not listen to events); -* `layer.hitGraphEnabled()` is deprecated. Just use `layer.listening()` instead +* `layer.hitGraphEnabled()` is deprecated. Just use `layer.listening(false)` instead * Some performance fixes and code size optimizations -* Better support for fonts with spaces inside (like `Font Awesome 5`). +* Better support for font families with spaces inside (like `Font Awesome 5`). +* Fix possible `dblclick` and `dbltap` triggers ## 6.0.0 - 2020-05-08 diff --git a/konva.js b/konva.js index aed3fa28..d4b15d11 100644 --- a/konva.js +++ b/konva.js @@ -8,7 +8,7 @@ * Konva JavaScript Framework v6.0.0 * http://konvajs.org/ * Licensed under the MIT - * Date: Tue Jun 02 2020 + * Date: Wed Jun 03 2020 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) @@ -6226,6 +6226,7 @@ } } else { + this.clickEndShape = null; this._fire(MOUSEUP, { evt: evt, target: this, @@ -6411,6 +6412,7 @@ }); } if (Konva.listenClickTap && !tapTriggered) { + this.clickEndShape = null; this._fire(TAP, { evt: evt, target: this, diff --git a/konva.min.js b/konva.min.js index dc18e0a3..52fff0f6 100644 --- a/konva.min.js +++ b/konva.min.js @@ -3,10 +3,10 @@ * Konva JavaScript Framework v6.0.0 * http://konvajs.org/ * Licensed under the MIT - * Date: Tue Jun 02 2020 + * Date: Wed Jun 03 2020 * * Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS) * Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva) * * @license - */var e=Math.PI/180;function t(t){var e=t.toLowerCase(),i=/(chrome)[ /]([\w.]+)/.exec(e)||/(webkit)[ /]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ /]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[],n=!!t.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i),r=!!t.match(/IEMobile/i);return{browser:i[1]||"",version:i[2]||"0",isIE:function(t){var e=t.indexOf("msie ");if(0>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in p?{r:(e=p[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",A._namedColorToRBA(t)||A._hex3ColorToRGBA(t)||A._hex6ColorToRGBA(t)||A._rgbColorToRGBA(t)||A._rgbaColorToRGBA(t)||A._hslColorToRGBA(t)},_namedColorToRBA:function(t){var e=p[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=(e[0],e.slice(1)),n=Number(i[0])/360,r=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0==r)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var c=2*o-(a=o<.5?o*(1+r):o+r-o*r),l=[0,0,0],d=0;d<3;d++)(s=n+1/3*-(d-1))<0&&s++,1t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length&&(r=e,e=t,t=r),n=0;n=this.parent.children.length)&&A.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},dt.prototype.getAbsoluteOpacity=function(){return this._getCache(Z,this._getAbsoluteOpacity)},dt.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},dt.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},dt.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],A.isObject(e)&&!A._isPlainObject(e)&&!A._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),A._prepareToStringify(n)},dt.prototype.toJSON=function(){return JSON.stringify(this.toObject())},dt.prototype.getParent=function(){return this.parent},dt.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},dt.prototype.isAncestorOf=function(t){return!1},dt.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},dt.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);for(var e,i=t.replace(/ /g,"").split(","),n=i.length,r=0;rthis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},Ae.prototype.getTime=function(){return this._time},Ae.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},Ae.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},Ae.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},Ae.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},Ae.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},Ae.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},Ae.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},Ae.prototype.update=function(){this.setPosition(this.getPosition(this._time))},Ae.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},Ae.prototype.pause=function(){this.state=1,this.fire("onPause")},Ae.prototype.getTimer=function(){return(new Date).getTime()},Ae);function Ae(t,e,i,n,r,o,a){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}var Me=(Ge.prototype._addAttr=function(t,e){var i,n,r,o,a,s,h,c,l=this.node,d=l._id,p=Ge.tweens[d][t];if(p&&delete Ge.attrs[d][p][t],i=l.getAttr(t),A._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(s=i,i=A._prepareArrayForTween(i,e,l.closed())):(a=e,e=A._prepareArrayForTween(e,i,l.closed()))),0===t.indexOf("fill"))for(r=0;rthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var r=this.dataArray[i],o=r.points;switch(r.command){case"L":return li.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return li.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return li.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":var a=o[0],s=o[1],h=o[2],c=o[3],l=o[4],d=o[5],p=o[6];return l+=d*t/r.pathLength,li.getPointOnEllipticalArc(a,s,h,c,l,p)}return null},li.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},li.getPointOnLine=function(t,e,i,n,r,o,a){void 0===o&&(o=e),void 0===a&&(a=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,A=_.slice(0,1+T),M=this._getTextWidth(A)+y;M<=c?(w=1+T,P=A+(g?"…":""),k=M):C=T}if(!P)break;if(!f||0<(S=(" "===(x=_[P.length])||"-"===x)&&k<=c?P.length:Math.max(P.lastIndexOf(" "),P.lastIndexOf("-"))+1)&&(w=S,P=P.slice(0,w),k=this._getTextWidth(P)),P=P.trimRight(),this._addTextLine(P),i=Math.max(i,k),d+=n,!u||s&&le?g=ci.getPointOnLine(e,f.x,f.y,y.points[0],y.points[1],f.x,f.y):y=void 0;break;case"A":var a=y.points[4],s=y.points[5],h=y.points[4]+s;0===m?m=a+1e-8:iy.pathLength?1e-8:e/y.pathLength:ic.x?-1:1,d=this.findOne(".top-left").y()>c.y?-1:1,w=s*this.cos*l,C=s*this.sin*d,this.findOne(".top-left").x(c.x-w),this.findOne(".top-left").y(c.y-C)):"top-center"===this._movingAnchorName?this.findOne(".top-left").y(e.y()):"top-right"===this._movingAnchorName?(a&&(c=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()},s=Math.sqrt(Math.pow(e.x()-c.x,2)+Math.pow(c.y-e.y(),2)),l=this.findOne(".top-right").x()c.y?-1:1,w=s*this.cos*l,C=s*this.sin*d,this.findOne(".top-right").x(c.x+w),this.findOne(".top-right").y(c.y-C)),h=e.position(),this.findOne(".top-left").y(h.y),this.findOne(".bottom-right").x(h.x)):"middle-left"===this._movingAnchorName?this.findOne(".top-left").x(e.x()):"middle-right"===this._movingAnchorName?this.findOne(".bottom-right").x(e.x()):"bottom-left"===this._movingAnchorName?(a&&(c=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()},s=Math.sqrt(Math.pow(c.x-e.x(),2)+Math.pow(e.y()-c.y,2)),l=c.x>N,0!==w?(w=255/w,P[a]=(h*B>>N)*w,P[a+1]=(c*B>>N)*w,P[a+2]=(l*B>>N)*w):P[a]=P[a+1]=P[a+2]=0,h-=p,c-=u,l-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=s+((r=i+e+1)>N,0>N)*w,P[r+1]=(c*B>>N)*w,P[r+2]=(l*B>>N)*w):P[r]=P[r+1]=P[r+2]=0,h-=p,c-=u,l-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=i+((r=n+R)>16&255,g:e>>8&255,b:255&e}},getRandomColor:function(){for(var t=(16777215*Math.random()<<0).toString(16);t.length<6;)t="0"+t;return"#"+t},get:function(t,e){return void 0===t?e:t},getRGB:function(t){var e;return t in p?{r:(e=p[t])[0],g:e[1],b:e[2]}:"#"===t[0]?this._hexToRgb(t.substring(1)):"rgb("===t.substr(0,4)?(e=u.exec(t.replace(/ /g,"")),{r:parseInt(e[1],10),g:parseInt(e[2],10),b:parseInt(e[3],10)}):{r:0,g:0,b:0}},colorToRGBA:function(t){return t=t||"black",A._namedColorToRBA(t)||A._hex3ColorToRGBA(t)||A._hex6ColorToRGBA(t)||A._rgbColorToRGBA(t)||A._rgbaColorToRGBA(t)||A._hslColorToRGBA(t)},_namedColorToRBA:function(t){var e=p[t.toLowerCase()];return e?{r:e[0],g:e[1],b:e[2],a:1}:null},_rgbColorToRGBA:function(t){if(0===t.indexOf("rgb(")){var e=(t=t.match(/rgb\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:1}}},_rgbaColorToRGBA:function(t){if(0===t.indexOf("rgba(")){var e=(t=t.match(/rgba\(([^)]+)\)/)[1]).split(/ *, */).map(Number);return{r:e[0],g:e[1],b:e[2],a:e[3]}}},_hex6ColorToRGBA:function(t){if("#"===t[0]&&7===t.length)return{r:parseInt(t.slice(1,3),16),g:parseInt(t.slice(3,5),16),b:parseInt(t.slice(5,7),16),a:1}},_hex3ColorToRGBA:function(t){if("#"===t[0]&&4===t.length)return{r:parseInt(t[1]+t[1],16),g:parseInt(t[2]+t[2],16),b:parseInt(t[3]+t[3],16),a:1}},_hslColorToRGBA:function(t){if(/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.test(t)){var e=/hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(t),i=(e[0],e.slice(1)),n=Number(i[0])/360,r=Number(i[1])/100,o=Number(i[2])/100,a=void 0,s=void 0,h=void 0;if(0==r)return h=255*o,{r:Math.round(h),g:Math.round(h),b:Math.round(h),a:1};for(var c=2*o-(a=o<.5?o*(1+r):o+r-o*r),l=[0,0,0],d=0;d<3;d++)(s=n+1/3*-(d-1))<0&&s++,1t.x+t.width||e.x+e.widtht.y+t.height||e.y+e.heighte.length&&(r=e,e=t,t=r),n=0;n=this.parent.children.length)&&A.warn("Unexpected value "+t+" for zIndex property. zIndex is just index of a node in children of its parent. Expected value is from 0 to "+(this.parent.children.length-1)+".");var e=this.index;return this.parent.children.splice(e,1),this.parent.children.splice(t,0,this),this.parent._setChildrenIndices(),this},dt.prototype.getAbsoluteOpacity=function(){return this._getCache(Z,this._getAbsoluteOpacity)},dt.prototype._getAbsoluteOpacity=function(){var t=this.opacity(),e=this.getParent();return e&&!e._isUnderCache&&(t*=e.getAbsoluteOpacity()),t},dt.prototype.moveTo=function(t){return this.getParent()!==t&&(this._remove(),t.add(this)),this},dt.prototype.toObject=function(){var t,e,i,n={},r=this.getAttrs();for(t in n.attrs={},r)e=r[t],A.isObject(e)&&!A._isPlainObject(e)&&!A._isArray(e)||(i="function"==typeof this[t]&&this[t],delete r[t],(i?i.call(this):null)!==(r[t]=e)&&(n.attrs[t]=e));return n.className=this.getClassName(),A._prepareToStringify(n)},dt.prototype.toJSON=function(){return JSON.stringify(this.toObject())},dt.prototype.getParent=function(){return this.parent},dt.prototype.findAncestors=function(t,e,i){var n=[];e&&this._isMatch(t)&&n.push(this);for(var r=this.parent;r;){if(r===i)return n;r._isMatch(t)&&n.push(r),r=r.parent}return n},dt.prototype.isAncestorOf=function(t){return!1},dt.prototype.findAncestor=function(t,e,i){return this.findAncestors(t,e,i)[0]},dt.prototype._isMatch=function(t){if(!t)return!1;if("function"==typeof t)return t(this);for(var e,i=t.replace(/ /g,"").split(","),n=i.length,r=0;rthis.duration?this.yoyo?(this._time=this.duration,this.reverse()):this.finish():t<0?this.yoyo?(this._time=0,this.play()):this.reset():(this._time=t,this.update())},Ae.prototype.getTime=function(){return this._time},Ae.prototype.setPosition=function(t){this.prevPos=this._pos,this.propFunc(t),this._pos=t},Ae.prototype.getPosition=function(t){return void 0===t&&(t=this._time),this.func(t,this.begin,this._change,this.duration)},Ae.prototype.play=function(){this.state=2,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onPlay")},Ae.prototype.reverse=function(){this.state=3,this._time=this.duration-this._time,this._startTime=this.getTimer()-this._time,this.onEnterFrame(),this.fire("onReverse")},Ae.prototype.seek=function(t){this.pause(),this._time=t,this.update(),this.fire("onSeek")},Ae.prototype.reset=function(){this.pause(),this._time=0,this.update(),this.fire("onReset")},Ae.prototype.finish=function(){this.pause(),this._time=this.duration,this.update(),this.fire("onFinish")},Ae.prototype.update=function(){this.setPosition(this.getPosition(this._time))},Ae.prototype.onEnterFrame=function(){var t=this.getTimer()-this._startTime;2===this.state?this.setTime(t):3===this.state&&this.setTime(this.duration-t)},Ae.prototype.pause=function(){this.state=1,this.fire("onPause")},Ae.prototype.getTimer=function(){return(new Date).getTime()},Ae);function Ae(t,e,i,n,r,o,a){this.prop=t,this.propFunc=e,this.begin=n,this._pos=n,this.duration=o,this._change=0,this.prevPos=0,this.yoyo=a,this._time=0,this._position=0,this._startTime=0,this._finish=0,this.func=i,this._change=r-this.begin,this.pause()}var Me=(Ge.prototype._addAttr=function(t,e){var i,n,r,o,a,s,h,c,l=this.node,d=l._id,p=Ge.tweens[d][t];if(p&&delete Ge.attrs[d][p][t],i=l.getAttr(t),A._isArray(e))if(n=[],o=Math.max(e.length,i.length),"points"===t&&e.length!==i.length&&(e.length>i.length?(s=i,i=A._prepareArrayForTween(i,e,l.closed())):(a=e,e=A._prepareArrayForTween(e,i,l.closed()))),0===t.indexOf("fill"))for(r=0;rthis.dataArray[i].pathLength;)t-=this.dataArray[i].pathLength,++i;if(i===n)return{x:(e=this.dataArray[i-1].points.slice(-2))[0],y:e[1]};if(t<.01)return{x:(e=this.dataArray[i].points.slice(0,2))[0],y:e[1]};var r=this.dataArray[i],o=r.points;switch(r.command){case"L":return li.getPointOnLine(t,r.start.x,r.start.y,o[0],o[1]);case"C":return li.getPointOnCubicBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3],o[4],o[5]);case"Q":return li.getPointOnQuadraticBezier(t/r.pathLength,r.start.x,r.start.y,o[0],o[1],o[2],o[3]);case"A":var a=o[0],s=o[1],h=o[2],c=o[3],l=o[4],d=o[5],p=o[6];return l+=d*t/r.pathLength,li.getPointOnEllipticalArc(a,s,h,c,l,p)}return null},li.getLineLength=function(t,e,i,n){return Math.sqrt((i-t)*(i-t)+(n-e)*(n-e))},li.getPointOnLine=function(t,e,i,n,r,o,a){void 0===o&&(o=e),void 0===a&&(a=i);var s=(r-i)/(n-e+1e-8),h=Math.sqrt(t*t/(1+s*s));n>>1,A=_.slice(0,1+T),M=this._getTextWidth(A)+y;M<=c?(w=1+T,P=A+(g?"…":""),k=M):C=T}if(!P)break;if(!f||0<(S=(" "===(x=_[P.length])||"-"===x)&&k<=c?P.length:Math.max(P.lastIndexOf(" "),P.lastIndexOf("-"))+1)&&(w=S,P=P.slice(0,w),k=this._getTextWidth(P)),P=P.trimRight(),this._addTextLine(P),i=Math.max(i,k),d+=n,!u||s&&le?g=ci.getPointOnLine(e,f.x,f.y,y.points[0],y.points[1],f.x,f.y):y=void 0;break;case"A":var a=y.points[4],s=y.points[5],h=y.points[4]+s;0===m?m=a+1e-8:iy.pathLength?1e-8:e/y.pathLength:ic.x?-1:1,d=this.findOne(".top-left").y()>c.y?-1:1,w=s*this.cos*l,C=s*this.sin*d,this.findOne(".top-left").x(c.x-w),this.findOne(".top-left").y(c.y-C)):"top-center"===this._movingAnchorName?this.findOne(".top-left").y(e.y()):"top-right"===this._movingAnchorName?(a&&(c=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".bottom-left").x(),y:this.findOne(".bottom-left").y()},s=Math.sqrt(Math.pow(e.x()-c.x,2)+Math.pow(c.y-e.y(),2)),l=this.findOne(".top-right").x()c.y?-1:1,w=s*this.cos*l,C=s*this.sin*d,this.findOne(".top-right").x(c.x+w),this.findOne(".top-right").y(c.y-C)),h=e.position(),this.findOne(".top-left").y(h.y),this.findOne(".bottom-right").x(h.x)):"middle-left"===this._movingAnchorName?this.findOne(".top-left").x(e.x()):"middle-right"===this._movingAnchorName?this.findOne(".bottom-right").x(e.x()):"bottom-left"===this._movingAnchorName?(a&&(c=p?{x:this.width()/2,y:this.height()/2}:{x:this.findOne(".top-right").x(),y:this.findOne(".top-right").y()},s=Math.sqrt(Math.pow(c.x-e.x(),2)+Math.pow(e.y()-c.y,2)),l=c.x>N,0!==w?(w=255/w,P[a]=(h*B>>N)*w,P[a+1]=(c*B>>N)*w,P[a+2]=(l*B>>N)*w):P[a]=P[a+1]=P[a+2]=0,h-=p,c-=u,l-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=s+((r=i+e+1)>N,0>N)*w,P[r+1]=(c*B>>N)*w,P[r+2]=(l*B>>N)*w):P[r]=P[r+1]=P[r+2]=0,h-=p,c-=u,l-=f,d-=g,p-=O.r,u-=O.g,f-=O.b,g-=O.a,r=i+((r=n+R) { } } } else { + this.clickEndShape = null; this._fire(MOUSEUP, { evt: evt, target: this, @@ -816,6 +817,7 @@ export class Stage extends Container { } if (Konva.listenClickTap && !tapTriggered) { + this.clickEndShape = null; this._fire(TAP, { evt: evt, target: this, diff --git a/test/functional/MouseEvents-test.js b/test/functional/MouseEvents-test.js index 2df8eb7b..69413623 100644 --- a/test/functional/MouseEvents-test.js +++ b/test/functional/MouseEvents-test.js @@ -1938,6 +1938,78 @@ suite('MouseEvents', function () { }); }); + test('click on stage and second click on shape should not trigger double click (check after dblclick)', function (done) { + var stage = addStage(); + var layer = new Konva.Layer(); + stage.add(layer); + + var bigRect = new Konva.Rect({ + x: 50, + y: 50, + width: 200, + height: 200, + fill: 'yellow', + }); + layer.add(bigRect); + + layer.draw(); + + var bigClicks = 0; + var bigDblClicks = 0; + + // make dblclick + stage.simulateMouseDown({ + x: 100, + y: 100, + }); + stage.simulateMouseUp({ + x: 100, + y: 100, + }); + stage.simulateMouseDown({ + x: 100, + y: 100, + }); + stage.simulateMouseUp({ + x: 100, + y: 100, + }); + + bigRect.on('click', function () { + bigClicks += 1; + }); + + bigRect.on('dblclick', function () { + bigDblClicks += 1; + }); + + stage.simulateMouseDown({ + x: 10, + y: 10, + }); + stage.simulateMouseUp({ + x: 10, + y: 10, + }); + + assert.equal(bigClicks, 0); + assert.equal(bigDblClicks, 0); + + stage.simulateMouseDown({ + x: 100, + y: 100, + }); + stage.simulateMouseUp({ + x: 100, + y: 100, + }); + + assert.equal(bigClicks, 1); + assert.equal(bigDblClicks, 0); + + done(); + }); + test('double click after drag should trigger event', function (done) { var stage = addStage(); var layer = new Konva.Layer(); diff --git a/test/functional/TouchEvents-test.js b/test/functional/TouchEvents-test.js index 8ca13afb..f78b7693 100644 --- a/test/functional/TouchEvents-test.js +++ b/test/functional/TouchEvents-test.js @@ -180,6 +180,78 @@ suite('TouchEvents', function () { }, 17); }); + test('tap on stage and second tap on shape should not trigger double tap (check after dbltap)', function (done) { + var stage = addStage(); + var layer = new Konva.Layer(); + stage.add(layer); + + var bigRect = new Konva.Rect({ + x: 50, + y: 50, + width: 200, + height: 200, + fill: 'yellow', + }); + layer.add(bigRect); + + layer.draw(); + + var bigClicks = 0; + var bigDblClicks = 0; + + // make dblclick + stage.simulateTouchStart({ + x: 100, + y: 100, + }); + stage.simulateTouchEnd({ + x: 100, + y: 100, + }); + stage.simulateTouchStart({ + x: 100, + y: 100, + }); + stage.simulateTouchEnd({ + x: 100, + y: 100, + }); + + bigRect.on('tap', function () { + bigClicks += 1; + }); + + bigRect.on('dbltap', function () { + bigDblClicks += 1; + }); + + stage.simulateTouchStart({ + x: 10, + y: 10, + }); + stage.simulateTouchEnd({ + x: 10, + y: 10, + }); + + assert.equal(bigClicks, 0); + assert.equal(bigDblClicks, 0); + + stage.simulateTouchStart({ + x: 100, + y: 100, + }); + stage.simulateTouchEnd({ + x: 100, + y: 100, + }); + + assert.equal(bigClicks, 1); + assert.equal(bigDblClicks, 0); + + done(); + }); + // test for https://github.com/konvajs/konva/issues/156 test('touchstart out of shape, then touch end inside shape', function () { var stage = addStage();