mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
refactor(stage): 根据cr意见优化stageRender构造函数传参
This commit is contained in:
parent
9787a9e379
commit
554e695ef5
@ -76,7 +76,7 @@ export default class StageCore extends EventEmitter {
|
|||||||
this.containerHighlightDuration = config.containerHighlightDuration || 800;
|
this.containerHighlightDuration = config.containerHighlightDuration || 800;
|
||||||
this.containerHighlightType = config.containerHighlightType;
|
this.containerHighlightType = config.containerHighlightType;
|
||||||
|
|
||||||
this.renderer = new StageRender(config.runtimeUrl, this.render);
|
this.renderer = new StageRender({ runtimeUrl: config.runtimeUrl, render: this.render.bind(this) });
|
||||||
this.mask = new StageMask(this.renderer.getDocument()?.documentElement);
|
this.mask = new StageMask(this.renderer.getDocument()?.documentElement);
|
||||||
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
||||||
this.multiDr = new StageMultiDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
this.multiDr = new StageMultiDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
||||||
|
@ -21,7 +21,7 @@ import { EventEmitter } from 'events';
|
|||||||
import { getHost, injectStyle, isSameDomain } from '@tmagic/utils';
|
import { getHost, injectStyle, isSameDomain } from '@tmagic/utils';
|
||||||
|
|
||||||
import style from './style.css?raw';
|
import style from './style.css?raw';
|
||||||
import type { Runtime, RuntimeWindow } from './types';
|
import type { Runtime, RuntimeWindow, StageRenderConfig } from './types';
|
||||||
|
|
||||||
export default class StageRender extends EventEmitter {
|
export default class StageRender extends EventEmitter {
|
||||||
/** 组件的js、css执行的环境,直接渲染为当前window,iframe渲染则为iframe.contentWindow */
|
/** 组件的js、css执行的环境,直接渲染为当前window,iframe渲染则为iframe.contentWindow */
|
||||||
@ -33,9 +33,9 @@ export default class StageRender extends EventEmitter {
|
|||||||
|
|
||||||
public runtimeUrl?: string;
|
public runtimeUrl?: string;
|
||||||
|
|
||||||
private render: () => Promise<HTMLElement | null>;
|
private render?: () => Promise<HTMLElement | null>;
|
||||||
|
|
||||||
constructor(runtimeUrl: string | undefined, render: () => Promise<HTMLElement | null>) {
|
constructor({ runtimeUrl, render }: StageRenderConfig) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.runtimeUrl = runtimeUrl || '';
|
this.runtimeUrl = runtimeUrl || '';
|
||||||
@ -119,9 +119,11 @@ export default class StageRender extends EventEmitter {
|
|||||||
|
|
||||||
if (!this.contentWindow) return;
|
if (!this.contentWindow) return;
|
||||||
|
|
||||||
const el = await this.render();
|
if (this.render) {
|
||||||
if (el) {
|
const el = await this.render();
|
||||||
this.contentWindow.document?.body?.appendChild(el);
|
if (el) {
|
||||||
|
this.contentWindow.document?.body?.appendChild(el);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('onload');
|
this.emit('onload');
|
||||||
|
@ -54,7 +54,8 @@ export type StageCoreConfig = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export interface StageRenderConfig {
|
export interface StageRenderConfig {
|
||||||
core: StageCore;
|
runtimeUrl?: string;
|
||||||
|
render?: () => Promise<HTMLElement | null>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StageMaskConfig {
|
export interface StageMaskConfig {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user