mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
Merge branch 'D31T4-master' into master
This commit is contained in:
commit
dda6d30b5a
@ -288,7 +288,20 @@ export class Transformer extends Group {
|
|||||||
if (this._nodes && this._nodes.length) {
|
if (this._nodes && this._nodes.length) {
|
||||||
this.detach();
|
this.detach();
|
||||||
}
|
}
|
||||||
this._nodes = nodes;
|
|
||||||
|
const filteredNodes = nodes.filter((node) => {
|
||||||
|
// check if ancestor of the transformer
|
||||||
|
if (node.isAncestorOf(this)) {
|
||||||
|
Util.error(
|
||||||
|
'Konva.Transformer cannot be an a child of the node you are trying to attach'
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
this._nodes = nodes = filteredNodes;
|
||||||
if (nodes.length === 1 && this.useSingleNodeRotation()) {
|
if (nodes.length === 1 && this.useSingleNodeRotation()) {
|
||||||
this.rotation(nodes[0].getAbsoluteRotation());
|
this.rotation(nodes[0].getAbsoluteRotation());
|
||||||
} else {
|
} else {
|
||||||
|
@ -36,7 +36,7 @@ function simulateMouseUp(tr: Transformer, pos = { x: 0, y: 0 }) {
|
|||||||
su(tr.getStage(), pos || { x: 1, y: 1 });
|
su(tr.getStage(), pos || { x: 1, y: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Transformer', function () {
|
describe.only('Transformer', function () {
|
||||||
// ======================================================
|
// ======================================================
|
||||||
it('init transformer on simple rectangle', function () {
|
it('init transformer on simple rectangle', function () {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
@ -4769,4 +4769,17 @@ describe('Transformer', function () {
|
|||||||
assert.equal(clone.getChildren().length, tr.getChildren().length);
|
assert.equal(clone.getChildren().length, tr.getChildren().length);
|
||||||
assert.equal(clone.nodes().length, 0);
|
assert.equal(clone.nodes().length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should filter parent of the transformer', function () {
|
||||||
|
const stage = addStage();
|
||||||
|
|
||||||
|
const layer = new Konva.Layer();
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
const tr = new Konva.Transformer();
|
||||||
|
layer.add(tr);
|
||||||
|
|
||||||
|
tr.nodes([layer]);
|
||||||
|
assert.equal(tr.nodes().length, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user