Skip to content

Commit

Permalink
fix(plugin): 优化resize功能
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLanniste authored and Qiu-Jun committed Jul 8, 2024
1 parent 96cad24 commit f53ef2b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/plugin/WorkspacePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class WorkspacePlugin implements IPluginTempl {
];
workspaceEl!: HTMLElement;
workspace: null | fabric.Rect;
resizeObserver!: ResizeObserver;
option: any;
zoomRatio: number;
constructor(public canvas: fabric.Canvas, public editor: IEditor) {
Expand Down Expand Up @@ -99,7 +100,6 @@ class WorkspacePlugin implements IPluginTempl {
if (this.canvas.clearHistory) {
this.canvas.clearHistory();
}
this.auto();
}

// 返回workspace对象
Expand Down Expand Up @@ -129,7 +129,8 @@ class WorkspacePlugin implements IPluginTempl {
this.auto();
}, 50)
);
resizeObserver.observe(this.workspaceEl);
this.resizeObserver = resizeObserver;
this.resizeObserver.observe(this.workspaceEl);
}

setSize(width: number | undefined, height: number | undefined) {
Expand All @@ -143,7 +144,6 @@ class WorkspacePlugin implements IPluginTempl {
this.workspace.set('width', width);
this.workspace.set('height', height);
this.editor.emit('sizeChange', this.workspace.width, this.workspace.height);
this.auto();
}

setZoomAuto(scale: number, cb?: (left?: number, top?: number) => void) {
Expand Down Expand Up @@ -224,6 +224,7 @@ class WorkspacePlugin implements IPluginTempl {
}

destroy() {
this.resizeObserver.disconnect();
console.log('pluginDestroy');
}
}
Expand Down

0 comments on commit f53ef2b

Please sign in to comment.