Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: node在初次编辑缩放旋转时回退存在异常 #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/polyfill/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './node';
import './ellipse';
import './line';
import './node';
import './rect';
import './regular-polygon';
import './text';
Expand Down
17 changes: 15 additions & 2 deletions packages/core/src/polyfill/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ import Konva from 'konva';

// 重写toObject方法
const originToObject = Konva.Node.prototype.toObject;
Konva.Node.prototype.toObject = function (this: Konva.Node): any {
return originToObject.call(this);
const newToObject = function (this: Konva.Node): any {
const object = originToObject.call(this);
return {
...object,
attrs: {
...object.attrs,
x: this.x(),
y: this.y(),
scaleX: this.scaleX(),
scaleY: this.scaleY(),
rotation: this.rotation(),
opacity: this.opacity(),
},
};
};
Konva.Node.prototype.toObject = newToObject;

// 重写remove方法
const originRemove = Konva.Node.prototype.remove;
Expand Down