dragstart fixes when transformer is used

This commit is contained in:
Anton Lavrenov
2020-09-02 12:50:41 -05:00
parent 7ae8415da8
commit 4a29a1e109
7 changed files with 73 additions and 1327 deletions

View File

@@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### not released: ### not released:
* fixes for `dragstart` event when `Konva.Transformer` is used. `dragstart` will not bubble from transformer.
* `string` and `fill` properties validation can accept `CanvasGradient` as valid value * `string` and `fill` properties validation can accept `CanvasGradient` as valid value
## 7.0.6 ## 7.0.6

1371
konva.js

File diff suppressed because it is too large Load Diff

View File

@@ -2347,7 +2347,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
* @method * @method
* @name Konva.Node#startDrag * @name Konva.Node#startDrag
*/ */
startDrag(evt?: any) { startDrag(evt?: any, bubbleEvent = true) {
if (!DD._dragElements.has(this._id)) { if (!DD._dragElements.has(this._id)) {
this._createDragElement(evt); this._createDragElement(evt);
} }
@@ -2361,7 +2361,7 @@ export abstract class Node<Config extends NodeConfig = NodeConfig> {
target: this, target: this,
evt: evt && evt.evt, evt: evt && evt.evt,
}, },
true bubbleEvent
); );
} }

View File

@@ -320,7 +320,7 @@ export class Transformer extends Group {
// actual dragging of Transformer doesn't make sense // actual dragging of Transformer doesn't make sense
// but we need to proxy drag events // but we need to proxy drag events
if (!this.isDragging() && node !== this.findOne('.back')) { if (!this.isDragging() && node !== this.findOne('.back')) {
this.startDrag(); this.startDrag(e, false);
} }
}); });
node.on(`dragmove.${EVENTS_NAME}`, (e) => { node.on(`dragmove.${EVENTS_NAME}`, (e) => {

View File

@@ -227,6 +227,15 @@ beforeEach(function () {
Konva.inDblClickWindow = false; Konva.inDblClickWindow = false;
Konva.DD && (Konva.DD.isDragging = false); Konva.DD && (Konva.DD.isDragging = false);
Konva.DD && (Konva.DD.node = undefined); Konva.DD && (Konva.DD.node = undefined);
if (
!(
this.currentTest.body.indexOf('assert') !== -1 ||
this.currentTest.body.toLowerCase().indexOf('compare') !== -1
)
) {
debugger;
}
}); });
Konva.UA.mobile = false; Konva.UA.mobile = false;

View File

@@ -434,6 +434,8 @@ suite('Node', function () {
layer.drawHit(); layer.drawHit();
showHit(layer); showHit(layer);
assert.equal(layer.getIntersection({ x: 60, y: 60 }), null);
}); });
// ====================================================== // ======================================================

View File

@@ -3873,7 +3873,8 @@ suite('Transformer', function () {
}); });
// make sure drag also triggers on the transformer. // make sure drag also triggers on the transformer.
tr.on('dragstart', () => { tr.on('dragstart', (e) => {
assert.equal(!!e.evt, true);
dragstart += 1; dragstart += 1;
}); });
tr.on('dragmove', () => { tr.on('dragmove', () => {
@@ -3883,6 +3884,12 @@ suite('Transformer', function () {
dragend += 1; dragend += 1;
}); });
// also drag should bubble to stage
// two times for two rects
stage.on('dragstart', () => {
dragstart += 1;
});
layer.add(tr); layer.add(tr);
layer.draw(); layer.draw();
@@ -3908,7 +3915,7 @@ suite('Transformer', function () {
// proxy drag to other nodes // proxy drag to other nodes
assert.equal(rect2.x(), 110); assert.equal(rect2.x(), 110);
assert.equal(rect2.y(), 110); assert.equal(rect2.y(), 110);
assert.equal(dragstart, 2); assert.equal(dragstart, 4);
assert.equal(dragmove, 3); assert.equal(dragmove, 3);
assert.equal(dragend, 2); assert.equal(dragend, 2);
}); });