mirror of
https://github.com/konvajs/konva.git
synced 2026-01-23 05:14:58 +08:00
Warn on undefined return value of dragBoundFunc. close #764
This commit is contained in:
@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Not released:
|
## Not released:
|
||||||
|
|
||||||
|
* Warn on undefined return value of `dragBoundFunc`.
|
||||||
|
|
||||||
## 4.0.15 - 2019-10-15
|
## 4.0.15 - 2019-10-15
|
||||||
|
|
||||||
* TS fixes
|
* TS fixes
|
||||||
|
|||||||
12
konva.js
12
konva.js
@@ -8,7 +8,7 @@
|
|||||||
* Konva JavaScript Framework v4.0.15
|
* Konva JavaScript Framework v4.0.15
|
||||||
* http://konvajs.org/
|
* http://konvajs.org/
|
||||||
* Licensed under the MIT
|
* Licensed under the MIT
|
||||||
* Date: Tue Oct 15 2019
|
* Date: Fri Oct 18 2019
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
||||||
@@ -4374,7 +4374,6 @@
|
|||||||
// const pointers = this.getStage().getPointersPositions();
|
// const pointers = this.getStage().getPointersPositions();
|
||||||
// const pos = pointers.find(p => p.id === this._dragEventId);
|
// const pos = pointers.find(p => p.id === this._dragEventId);
|
||||||
var pos = this.getStage()._getPointerById(elem.pointerId);
|
var pos = this.getStage()._getPointerById(elem.pointerId);
|
||||||
var dbf = this.dragBoundFunc();
|
|
||||||
if (!pos) {
|
if (!pos) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4382,8 +4381,15 @@
|
|||||||
x: pos.x - elem.offset.x,
|
x: pos.x - elem.offset.x,
|
||||||
y: pos.y - elem.offset.y
|
y: pos.y - elem.offset.y
|
||||||
};
|
};
|
||||||
|
var dbf = this.dragBoundFunc();
|
||||||
if (dbf !== undefined) {
|
if (dbf !== undefined) {
|
||||||
newNodePos = dbf.call(this, newNodePos, evt);
|
var bounded = dbf.call(this, newNodePos, evt);
|
||||||
|
if (!bounded) {
|
||||||
|
Util.warn('dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newNodePos = bounded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!this._lastPos ||
|
if (!this._lastPos ||
|
||||||
this._lastPos.x !== newNodePos.x ||
|
this._lastPos.x !== newNodePos.x ||
|
||||||
|
|||||||
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
11
src/Node.ts
11
src/Node.ts
@@ -2294,7 +2294,6 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
// const pos = pointers.find(p => p.id === this._dragEventId);
|
// const pos = pointers.find(p => p.id === this._dragEventId);
|
||||||
const pos = this.getStage()._getPointerById(elem.pointerId);
|
const pos = this.getStage()._getPointerById(elem.pointerId);
|
||||||
|
|
||||||
var dbf = this.dragBoundFunc();
|
|
||||||
if (!pos) {
|
if (!pos) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2303,8 +2302,16 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|||||||
y: pos.y - elem.offset.y
|
y: pos.y - elem.offset.y
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var dbf = this.dragBoundFunc();
|
||||||
if (dbf !== undefined) {
|
if (dbf !== undefined) {
|
||||||
newNodePos = dbf.call(this, newNodePos, evt);
|
const bounded = dbf.call(this, newNodePos, evt);
|
||||||
|
if (!bounded) {
|
||||||
|
Util.warn(
|
||||||
|
'dragBoundFunc did not return any value. That is unexpected behavior. You must return new absolute position from dragBoundFunc.'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
newNodePos = bounded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -1057,6 +1057,39 @@ suite('DragAndDrop', function() {
|
|||||||
stage.simulateMouseUp({ x: 80, y: 80 });
|
stage.simulateMouseUp({ x: 80, y: 80 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('warn on bad dragBoundFunc', function() {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer({
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
var circle = new Konva.Circle({
|
||||||
|
x: 70,
|
||||||
|
y: 70,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
name: 'myCircle',
|
||||||
|
draggable: true,
|
||||||
|
dragBoundFunc: () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
var counter = 0;
|
||||||
|
var oldWarn = Konva.Util.warn;
|
||||||
|
Konva.Util.warn = function() {
|
||||||
|
counter += 1;
|
||||||
|
};
|
||||||
|
stage.simulateMouseDown({ x: 70, y: 70 });
|
||||||
|
stage.simulateMouseMove({ x: 80, y: 80 });
|
||||||
|
stage.simulateMouseUp({ x: 80, y: 80 });
|
||||||
|
assert.equal(counter > 0, true);
|
||||||
|
Konva.Util.warn = oldWarn;
|
||||||
|
});
|
||||||
|
|
||||||
test('deletage drag', function() {
|
test('deletage drag', function() {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
stage.draggable(true);
|
stage.draggable(true);
|
||||||
|
|||||||
Reference in New Issue
Block a user