update CHANGELOG with new version

This commit is contained in:
Anton Lavrenov 2021-11-15 08:27:41 -05:00
parent cbe2e2f2ef
commit 4dfdd6eeaf
5 changed files with 76 additions and 31 deletions

View File

@ -3,7 +3,9 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
### ## 8.2.4 (2021-12-15)
- Fix not working `Konva.Transformer` when several transformers were used
## 8.2.2 ## 8.2.2

View File

@ -8,7 +8,7 @@
* Konva JavaScript Framework v8.2.3 * Konva JavaScript Framework v8.2.3
* http://konvajs.org/ * http://konvajs.org/
* Licensed under the MIT * Licensed under the MIT
* Date: Fri Oct 22 2021 * Date: Mon Nov 15 2021
* *
* 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)
@ -14463,9 +14463,7 @@
'offsetYChange', 'offsetYChange',
'transformsEnabledChange', 'transformsEnabledChange',
'strokeWidthChange', 'strokeWidthChange',
] ];
.map((e) => e + `.${EVENTS_NAME}`)
.join(' ');
var ANGLES = { var ANGLES = {
'top-left': -45, 'top-left': -45,
'top-center': 0, 'top-center': 0,
@ -14641,6 +14639,9 @@
getNode() { getNode() {
return this._nodes && this._nodes[0]; return this._nodes && this._nodes[0];
} }
_getEventNamespace() {
return EVENTS_NAME + this._id;
}
setNodes(nodes = []) { setNodes(nodes = []) {
if (this._nodes && this._nodes.length) { if (this._nodes && this._nodes.length) {
this.detach(); this.detach();
@ -14653,9 +14654,6 @@
this.rotation(0); this.rotation(0);
} }
this._nodes.forEach((node) => { this._nodes.forEach((node) => {
const additionalEvents = node._attrsAffectingSize
.map((prop) => prop + 'Change.' + EVENTS_NAME)
.join(' ');
const onChange = () => { const onChange = () => {
if (this.nodes().length === 1 && this.useSingleNodeRotation()) { if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
this.rotation(this.nodes()[0].getAbsoluteRotation()); this.rotation(this.nodes()[0].getAbsoluteRotation());
@ -14665,10 +14663,12 @@
this.update(); this.update();
} }
}; };
const additionalEvents = node._attrsAffectingSize
.map((prop) => prop + 'Change.' + this._getEventNamespace())
.join(' ');
node.on(additionalEvents, onChange); node.on(additionalEvents, onChange);
node.on(TRANSFORM_CHANGE_STR, onChange); node.on(TRANSFORM_CHANGE_STR.map((e) => e + `.${this._getEventNamespace()}`).join(' '), onChange);
node.on(`absoluteTransformChange.${EVENTS_NAME}`, onChange); node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange);
this._proxyDrag(node); this._proxyDrag(node);
}); });
this._resetTransformCache(); this._resetTransformCache();
@ -14682,7 +14682,7 @@
} }
_proxyDrag(node) { _proxyDrag(node) {
let lastPos; let lastPos;
node.on(`dragstart.${EVENTS_NAME}`, (e) => { node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
lastPos = node.getAbsolutePosition(); lastPos = node.getAbsolutePosition();
// actual dragging of Transformer doesn't make sense // actual dragging of Transformer doesn't make sense
// but we need to make sure it also has all drag events // but we need to make sure it also has all drag events
@ -14690,7 +14690,7 @@
this.startDrag(e, false); this.startDrag(e, false);
} }
}); });
node.on(`dragmove.${EVENTS_NAME}`, (e) => { node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
if (!lastPos) { if (!lastPos) {
return; return;
} }
@ -14740,7 +14740,7 @@
// remove events // remove events
if (this._nodes) { if (this._nodes) {
this._nodes.forEach((node) => { this._nodes.forEach((node) => {
node.off('.' + EVENTS_NAME); node.off('.' + this._getEventNamespace());
}); });
} }
this._nodes = []; this._nodes = [];

4
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -76,9 +76,7 @@ var TRANSFORM_CHANGE_STR = [
'offsetYChange', 'offsetYChange',
'transformsEnabledChange', 'transformsEnabledChange',
'strokeWidthChange', 'strokeWidthChange',
] ];
.map((e) => e + `.${EVENTS_NAME}`)
.join(' ');
var ANGLES = { var ANGLES = {
'top-left': -45, 'top-left': -45,
@ -282,6 +280,10 @@ export class Transformer extends Group {
return this._nodes && this._nodes[0]; return this._nodes && this._nodes[0];
} }
_getEventNamespace() {
return EVENTS_NAME + this._id;
}
setNodes(nodes: Array<Node> = []) { setNodes(nodes: Array<Node> = []) {
if (this._nodes && this._nodes.length) { if (this._nodes && this._nodes.length) {
this.detach(); this.detach();
@ -293,10 +295,6 @@ export class Transformer extends Group {
this.rotation(0); this.rotation(0);
} }
this._nodes.forEach((node) => { this._nodes.forEach((node) => {
const additionalEvents = node._attrsAffectingSize
.map((prop) => prop + 'Change.' + EVENTS_NAME)
.join(' ');
const onChange = () => { const onChange = () => {
if (this.nodes().length === 1 && this.useSingleNodeRotation()) { if (this.nodes().length === 1 && this.useSingleNodeRotation()) {
this.rotation(this.nodes()[0].getAbsoluteRotation()); this.rotation(this.nodes()[0].getAbsoluteRotation());
@ -307,10 +305,17 @@ export class Transformer extends Group {
this.update(); this.update();
} }
}; };
const additionalEvents = node._attrsAffectingSize
.map((prop) => prop + 'Change.' + this._getEventNamespace())
.join(' ');
node.on(additionalEvents, onChange); node.on(additionalEvents, onChange);
node.on(TRANSFORM_CHANGE_STR, onChange); node.on(
node.on(`absoluteTransformChange.${EVENTS_NAME}`, onChange); TRANSFORM_CHANGE_STR.map(
node.on(`xChange.${EVENTS_NAME} yChange.${EVENTS_NAME}`, onChange); (e) => e + `.${this._getEventNamespace()}`
).join(' '),
onChange
);
node.on(`absoluteTransformChange.${this._getEventNamespace()}`, onChange);
this._proxyDrag(node); this._proxyDrag(node);
}); });
this._resetTransformCache(); this._resetTransformCache();
@ -325,7 +330,7 @@ export class Transformer extends Group {
_proxyDrag(node: Node) { _proxyDrag(node: Node) {
let lastPos; let lastPos;
node.on(`dragstart.${EVENTS_NAME}`, (e) => { node.on(`dragstart.${this._getEventNamespace()}`, (e) => {
lastPos = node.getAbsolutePosition(); lastPos = node.getAbsolutePosition();
// actual dragging of Transformer doesn't make sense // actual dragging of Transformer doesn't make sense
// but we need to make sure it also has all drag events // but we need to make sure it also has all drag events
@ -333,7 +338,7 @@ export class Transformer extends Group {
this.startDrag(e, false); this.startDrag(e, false);
} }
}); });
node.on(`dragmove.${EVENTS_NAME}`, (e) => { node.on(`dragmove.${this._getEventNamespace()}`, (e) => {
if (!lastPos) { if (!lastPos) {
return; return;
} }
@ -384,7 +389,7 @@ export class Transformer extends Group {
// remove events // remove events
if (this._nodes) { if (this._nodes) {
this._nodes.forEach((node) => { this._nodes.forEach((node) => {
node.off('.' + EVENTS_NAME); node.off('.' + this._getEventNamespace());
}); });
} }
this._nodes = []; this._nodes = [];

View File

@ -4636,7 +4636,7 @@ describe('Transformer', function () {
width: 100, width: 100,
height: 100, height: 100,
fill: 'yellow', fill: 'yellow',
rotation: 45 rotation: 45,
}); });
layer.add(rect); layer.add(rect);
@ -4651,4 +4651,42 @@ describe('Transformer', function () {
assert.equal(tr.rotation(), 0); assert.equal(tr.rotation(), 0);
}); });
it('use several transformers on a single node', function () {
var stage = addStage();
var layer = new Konva.Layer();
stage.add(layer);
var rect = new Konva.Rect({
x: 100,
y: 60,
draggable: true,
width: 100,
height: 100,
fill: 'yellow',
});
layer.add(rect);
var tr1 = new Konva.Transformer({
nodes: [rect],
});
layer.add(tr1);
var tr2 = new Konva.Transformer({
nodes: [rect],
});
layer.add(tr2);
// detach tr1
tr1.nodes([]);
// update rect
rect.setAttrs({ x: 0, y: 0, width: 50, height: 50 });
// it should update second transformer
assert.equal(tr2.x(), rect.x());
assert.equal(tr2.y(), rect.y());
assert.equal(tr2.width(), rect.width());
assert.equal(tr2.height(), rect.height());
});
}); });