mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-05 01:38:57 +08:00
chore(stage): 优化高亮与单选性能
This commit is contained in:
parent
df236d172d
commit
babaadb0cf
@ -85,10 +85,6 @@ export default class DragResizeHelper {
|
|||||||
this.moveableHelper.clear();
|
this.moveableHelper.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroyShadowEl(): void {
|
|
||||||
this.targetShadow.destroyEl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public getShadowEl(): TargetElement | undefined {
|
public getShadowEl(): TargetElement | undefined {
|
||||||
return this.targetShadow.el;
|
return this.targetShadow.el;
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,7 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|||||||
* @param event 鼠标事件
|
* @param event 鼠标事件
|
||||||
*/
|
*/
|
||||||
public select(el: HTMLElement, event?: MouseEvent): void {
|
public select(el: HTMLElement, event?: MouseEvent): void {
|
||||||
// 从不能拖动到能拖动的节点之间切换,要重新创建moveable,不然dragStart不生效
|
if (!this.moveable) {
|
||||||
if (!this.moveable || el !== this.target) {
|
|
||||||
this.initMoveable(el);
|
this.initMoveable(el);
|
||||||
} else {
|
} else {
|
||||||
this.updateMoveable(el);
|
this.updateMoveable(el);
|
||||||
@ -95,14 +94,13 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|||||||
Object.entries(options).forEach(([key, value]) => {
|
Object.entries(options).forEach(([key, value]) => {
|
||||||
(this.moveable as any)[key] = value;
|
(this.moveable as any)[key] = value;
|
||||||
});
|
});
|
||||||
this.moveable.updateTarget();
|
this.moveable.updateRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearSelectStatus(): void {
|
public clearSelectStatus(): void {
|
||||||
if (!this.moveable) return;
|
if (!this.moveable) return;
|
||||||
this.dragResizeHelper.destroyShadowEl();
|
this.moveable.zoom = 0;
|
||||||
this.moveable.target = null;
|
this.moveable.updateRect();
|
||||||
this.moveable.updateTarget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,6 +109,9 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
this.moveable?.destroy();
|
this.moveable?.destroy();
|
||||||
this.dragResizeHelper.destroy();
|
this.dragResizeHelper.destroy();
|
||||||
|
|
||||||
|
this.moveable = undefined;
|
||||||
|
|
||||||
this.dragStatus = StageDragStatus.END;
|
this.dragStatus = StageDragStatus.END;
|
||||||
this.removeAllListeners();
|
this.removeAllListeners();
|
||||||
}
|
}
|
||||||
@ -132,7 +133,7 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|||||||
this.setElementGuidelines([this.target as HTMLElement], elementGuidelines);
|
this.setElementGuidelines([this.target as HTMLElement], elementGuidelines);
|
||||||
|
|
||||||
return this.getOptions(false, {
|
return this.getOptions(false, {
|
||||||
target: this.dragResizeHelper.getShadowEl(),
|
zoom: 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,9 +141,8 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|||||||
const options: MoveableOptions = this.init(el);
|
const options: MoveableOptions = this.init(el);
|
||||||
this.dragResizeHelper.clear();
|
this.dragResizeHelper.clear();
|
||||||
|
|
||||||
this.moveable?.destroy();
|
|
||||||
|
|
||||||
this.moveable = new Moveable(this.container, {
|
this.moveable = new Moveable(this.container, {
|
||||||
|
target: this.dragResizeHelper.getShadowEl(),
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ export default class StageHighlight extends EventEmitter {
|
|||||||
public container: HTMLElement;
|
public container: HTMLElement;
|
||||||
public target?: HTMLElement;
|
public target?: HTMLElement;
|
||||||
public moveable?: Moveable;
|
public moveable?: Moveable;
|
||||||
public targetShadow: TargetShadow;
|
public targetShadow?: TargetShadow;
|
||||||
private getRootContainer: GetRootContainer;
|
private getRootContainer: GetRootContainer;
|
||||||
|
|
||||||
constructor(config: StageHighlightConfig) {
|
constructor(config: StageHighlightConfig) {
|
||||||
@ -52,24 +52,29 @@ export default class StageHighlight extends EventEmitter {
|
|||||||
public highlight(el: HTMLElement): void {
|
public highlight(el: HTMLElement): void {
|
||||||
if (!el || el === this.target) return;
|
if (!el || el === this.target) return;
|
||||||
this.target = el;
|
this.target = el;
|
||||||
this.moveable?.destroy();
|
|
||||||
|
|
||||||
|
this.targetShadow?.update(el);
|
||||||
|
if (this.moveable) {
|
||||||
|
this.moveable.zoom = 2;
|
||||||
|
this.moveable.updateRect();
|
||||||
|
} else {
|
||||||
this.moveable = new Moveable(this.container, {
|
this.moveable = new Moveable(this.container, {
|
||||||
target: this.targetShadow.update(el),
|
target: this.targetShadow?.el,
|
||||||
origin: false,
|
origin: false,
|
||||||
rootContainer: this.getRootContainer(),
|
rootContainer: this.getRootContainer(),
|
||||||
zoom: 2,
|
zoom: 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空高亮
|
* 清空高亮
|
||||||
*/
|
*/
|
||||||
public clearHighlight(): void {
|
public clearHighlight(): void {
|
||||||
if (!this.moveable || !this.target) return;
|
if (!this.moveable || !this.target) return;
|
||||||
|
this.moveable.zoom = 0;
|
||||||
|
this.moveable.updateRect();
|
||||||
this.target = undefined;
|
this.target = undefined;
|
||||||
this.moveable.target = null;
|
|
||||||
this.moveable.updateTarget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,6 +82,8 @@ export default class StageHighlight extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public destroy(): void {
|
public destroy(): void {
|
||||||
this.moveable?.destroy();
|
this.moveable?.destroy();
|
||||||
this.targetShadow.destroy();
|
this.targetShadow?.destroy();
|
||||||
|
this.moveable = undefined;
|
||||||
|
this.targetShadow = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user