mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 13:03:10 +08:00
Merge branch 'master' of https://github.com/D31T4/konva into D31T4-master
This commit is contained in:
commit
78c0bddafa
@ -288,7 +288,37 @@ 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 ancestors = this.getAncestors();
|
||||||
|
|
||||||
|
const filteredNodes = nodes.filter(node => {
|
||||||
|
// check if ancestor of the transformer
|
||||||
|
if (ancestors.includes(node))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let pointer = node.parent;
|
||||||
|
|
||||||
|
// check if descendant of any transformer
|
||||||
|
while (pointer) {
|
||||||
|
const type = pointer.getType();
|
||||||
|
if (type != 'Group' && type != 'Shape')
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (pointer.className == Transformer.prototype.className)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
pointer = pointer.parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filteredNodes.length != nodes.length) {
|
||||||
|
Util.error('nodes should not be descendants of a transformer, or ancestors of this transformer.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
@ -4769,4 +4769,32 @@ 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('`transformer.nodes( )` should filter invalid nodes if they are descendants of a transformer or parent of the transformer', function () {
|
||||||
|
it('should filter children of a transformer', function () {
|
||||||
|
const stage = addStage()!;
|
||||||
|
|
||||||
|
const layer = new Konva.Layer();
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
const tr = new Konva.Transformer();
|
||||||
|
layer.add(tr);
|
||||||
|
|
||||||
|
tr.nodes([tr.children![0]]);
|
||||||
|
assert.equal(tr.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