mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-10 03:22:23 +08:00
fix(editor): stage-overlay状态更新
This commit is contained in:
parent
01f8040a1a
commit
2432bc5a69
@ -892,6 +892,8 @@ class Editor extends BaseService {
|
|||||||
this.addModifiedNodeId(parent.id);
|
this.addModifiedNodeId(parent.id);
|
||||||
|
|
||||||
this.pushHistoryState();
|
this.pushHistoryState();
|
||||||
|
|
||||||
|
this.emit('drag-to', { index, targetIndex, config, parent, targetParent });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,6 +51,8 @@ class StageOverlay extends BaseService {
|
|||||||
editorService.on('update', this.updateHandler);
|
editorService.on('update', this.updateHandler);
|
||||||
editorService.on('add', this.addHandler);
|
editorService.on('add', this.addHandler);
|
||||||
editorService.on('remove', this.removeHandler);
|
editorService.on('remove', this.removeHandler);
|
||||||
|
editorService.on('drag-to', this.updateHandler);
|
||||||
|
editorService.on('move-layer', this.updateHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public closeOverlay() {
|
public closeOverlay() {
|
||||||
@ -67,6 +69,8 @@ class StageOverlay extends BaseService {
|
|||||||
editorService.off('update', this.updateHandler);
|
editorService.off('update', this.updateHandler);
|
||||||
editorService.off('add', this.addHandler);
|
editorService.off('add', this.addHandler);
|
||||||
editorService.off('remove', this.removeHandler);
|
editorService.off('remove', this.removeHandler);
|
||||||
|
editorService.off('drag-to', this.updateHandler);
|
||||||
|
editorService.off('move-layer', this.updateHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateOverlay() {
|
public updateOverlay() {
|
||||||
@ -99,13 +103,6 @@ class StageOverlay extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wrapDiv = this.get('wrapDiv');
|
const wrapDiv = this.get('wrapDiv');
|
||||||
const sourceEl = this.get('sourceEl');
|
|
||||||
|
|
||||||
wrapDiv.style.cssText = `
|
|
||||||
width: ${sourceEl?.scrollWidth}px;
|
|
||||||
height: ${sourceEl?.scrollHeight}px;
|
|
||||||
background-color: #fff;
|
|
||||||
`;
|
|
||||||
|
|
||||||
await this.render();
|
await this.render();
|
||||||
|
|
||||||
@ -141,12 +138,19 @@ class StageOverlay extends BaseService {
|
|||||||
this.createContentEl();
|
this.createContentEl();
|
||||||
|
|
||||||
const contentEl = this.get('contentEl');
|
const contentEl = this.get('contentEl');
|
||||||
|
const sourceEl = this.get('sourceEl');
|
||||||
const wrapDiv = this.get('wrapDiv');
|
const wrapDiv = this.get('wrapDiv');
|
||||||
const subStage = this.get('stage');
|
const subStage = this.get('stage');
|
||||||
const stageOptions = this.get('stageOptions');
|
const stageOptions = this.get('stageOptions');
|
||||||
|
|
||||||
if (!contentEl) return;
|
if (!contentEl) return;
|
||||||
|
|
||||||
|
wrapDiv.style.cssText = `
|
||||||
|
width: ${sourceEl?.scrollWidth}px;
|
||||||
|
height: ${sourceEl?.scrollHeight}px;
|
||||||
|
background-color: #fff;
|
||||||
|
`;
|
||||||
|
|
||||||
Array.from(wrapDiv.children).forEach((element) => {
|
Array.from(wrapDiv.children).forEach((element) => {
|
||||||
element.remove();
|
element.remove();
|
||||||
});
|
});
|
||||||
@ -162,19 +166,37 @@ class StageOverlay extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateHandler = () => {
|
private updateHandler = () => {
|
||||||
this.render();
|
setTimeout(() => {
|
||||||
this.updateOverlay();
|
this.render();
|
||||||
|
this.updateOverlay();
|
||||||
|
|
||||||
|
this.updateSelectStatus();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private addHandler = () => {
|
private addHandler = () => {
|
||||||
this.render();
|
this.render();
|
||||||
this.updateOverlay();
|
this.updateOverlay();
|
||||||
|
|
||||||
|
this.updateSelectStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
private removeHandler = () => {
|
private removeHandler = () => {
|
||||||
this.render();
|
this.render();
|
||||||
this.updateOverlay();
|
this.updateOverlay();
|
||||||
|
|
||||||
|
this.updateSelectStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private updateSelectStatus() {
|
||||||
|
const subStage = this.get('stage');
|
||||||
|
const nodes = editorService.get('nodes');
|
||||||
|
if (nodes.length > 1) {
|
||||||
|
subStage?.multiSelect(nodes.map((n) => n.id));
|
||||||
|
} else {
|
||||||
|
subStage?.select(nodes[0].id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StageOverlayService = StageOverlay;
|
export type StageOverlayService = StageOverlay;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user