mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(stage): 增加当前拖动的节点的z-index
This commit is contained in:
parent
bfdd813531
commit
7f3d6c5438
@ -35,6 +35,7 @@ import {
|
||||
UpdateData,
|
||||
UpdateEventData,
|
||||
} from './types';
|
||||
import { addSelectedClassName, removeSelectedClassName } from './util';
|
||||
|
||||
export default class StageCore extends EventEmitter {
|
||||
public selectedDom: Element | undefined;
|
||||
@ -135,7 +136,8 @@ export default class StageCore extends EventEmitter {
|
||||
|
||||
if (el === this.selectedDom) return;
|
||||
|
||||
const runtime = await this.renderer?.getRuntime();
|
||||
const runtime = await this.renderer.getRuntime();
|
||||
|
||||
if (runtime?.beforeSelect) {
|
||||
await runtime.beforeSelect(el);
|
||||
}
|
||||
@ -143,6 +145,13 @@ export default class StageCore extends EventEmitter {
|
||||
this.mask.setLayout(el);
|
||||
this.dr?.select(el, event);
|
||||
this.selectedDom = el;
|
||||
|
||||
if (this.renderer.contentWindow) {
|
||||
removeSelectedClassName(this.renderer.contentWindow.document);
|
||||
if (this.selectedDom) {
|
||||
addSelectedClassName(this.selectedDom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import { SELECTED_CLASS, ZIndex } from './const';
|
||||
import StageCore from './StageCore';
|
||||
import type { Runtime, RuntimeWindow, StageRenderConfig } from './types';
|
||||
import { getHost, isSameDomain } from './util';
|
||||
@ -114,11 +115,23 @@ export default class StageRender extends EventEmitter {
|
||||
|
||||
private loadHandler = async () => {
|
||||
this.emit('onload');
|
||||
|
||||
if (this.render) {
|
||||
const el = await this.render(this.core);
|
||||
if (el) {
|
||||
this.iframe?.contentDocument?.body?.appendChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.contentWindow) {
|
||||
const style = this.contentWindow.document.createElement('style');
|
||||
style.id = 'tmagic-stage-render';
|
||||
style.innerHTML = `
|
||||
.${SELECTED_CLASS}, .${SELECTED_CLASS}-parent {
|
||||
z-index: ${ZIndex.SELECTED_EL};
|
||||
}
|
||||
`;
|
||||
this.contentWindow.document.head.appendChild(style);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ export enum GuidesType {
|
||||
|
||||
export enum ZIndex {
|
||||
MASK = '99999',
|
||||
SELECTED_EL = '666',
|
||||
}
|
||||
|
||||
export enum MouseButton {
|
||||
@ -42,3 +43,5 @@ export enum Mode {
|
||||
FIXED = 'fixed',
|
||||
SORTABLE = 'sortable',
|
||||
}
|
||||
|
||||
export const SELECTED_CLASS = 'tmagic-stage-selected-area';
|
||||
|
@ -16,7 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Mode } from './const';
|
||||
import { Mode, SELECTED_CLASS } from './const';
|
||||
import type { Offset } from './types';
|
||||
|
||||
export const getOffset = (el: HTMLElement): Offset => {
|
||||
@ -154,3 +154,17 @@ export const createDiv = ({ className, cssText }: { className: string; cssText:
|
||||
el.style.cssText = cssText;
|
||||
return el;
|
||||
};
|
||||
|
||||
export const removeSelectedClassName = (doc: Document) => {
|
||||
const oldEl = doc.querySelector(`.${SELECTED_CLASS}`);
|
||||
|
||||
if (oldEl) {
|
||||
oldEl.classList.remove(SELECTED_CLASS);
|
||||
(oldEl.parentNode as HTMLDivElement)?.classList.remove(`${SELECTED_CLASS}-parent`);
|
||||
}
|
||||
};
|
||||
|
||||
export const addSelectedClassName = (el: Element) => {
|
||||
el.classList.add(SELECTED_CLASS);
|
||||
(el.parentNode as Element)?.classList.add(`${SELECTED_CLASS}-parent`);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user