fix: init

This commit is contained in:
liujuping 2022-12-08 14:57:02 +08:00
parent bf0ffc55fb
commit 1fa525d64a
11 changed files with 48 additions and 13 deletions

View File

@ -418,7 +418,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
this.renderer?.rerender?.();
}
async mountContentFrame(iframe: HTMLIFrameElement | null) {
async mountContentFrame(iframe: HTMLIFrameElement | null): Promise<void> {
if (!iframe || this._iframe === iframe) {
return;
}

View File

@ -399,12 +399,12 @@ export class Designer {
const { components, packages } = incrementalAssets;
components && this.buildComponentMetasMap(components);
if (packages) {
await this.project.simulator!.setupComponents(packages);
await this.project.simulator?.setupComponents(packages);
}
if (components) {
// 合并 assets
let assets = this.editor.get('assets');
let assets = this.editor.get('assets') || {};
let newAssets = megreAssets(assets, incrementalAssets);
// 对于 assets 存在需要二次网络下载的过程,必须 await 等待结束之后,再进行事件触发
await this.editor.set('assets', newAssets);

View File

@ -113,10 +113,25 @@ export class Editor extends (EventEmitter as any) implements IEditor {
if (remoteComponentDescriptions && remoteComponentDescriptions.length) {
await Promise.all(
remoteComponentDescriptions.map(async (component: any) => {
const { exportName, url } = component;
const { exportName, url, npm } = component;
await (new AssetLoader()).load(url);
if (window[exportName]) {
assets.components = assets.components.concat(window[exportName].components || []);
if (Array.isArray(window[exportName])) {
(window[exportName] as any).forEach((d: any, i: number) => {
assets.components = assets.components.concat({
npm: {
...npm,
exportName: i.toString(),
subName: i.toString(),
},
...d.components,
} || []);
});
}
assets.components = assets.components.concat({
npm,
...window[exportName].components,
} || []);
assets.componentList = assets.componentList.concat(window[exportName].componentList || []);
}
return window[exportName];
@ -124,6 +139,7 @@ export class Editor extends (EventEmitter as any) implements IEditor {
);
}
}
this.context.set('assets', assets);
this.notifyGot('assets');
}

View File

@ -376,6 +376,7 @@ body {
}
.lc-main-area {
flex: 1;
background-color: #edeff3;
}
.lc-bottom-area {
height: var(--bottom-area-height);

View File

@ -36,7 +36,7 @@ type PropChangeOptions = {
oldValue: any;
};
const Events = {
export const Events = {
IMPORT_SCHEMA: 'shell.document.importSchema',
};

View File

@ -21,7 +21,7 @@ export default class Material {
private readonly [innerEditorSymbol]: Editor;
// private readonly [designerSymbol]: Designer;
get [editorSymbol]() {
get [editorSymbol](): Editor {
if (this.workspaceMode) {
return this[innerEditorSymbol];
}
@ -33,7 +33,7 @@ export default class Material {
return this[innerEditorSymbol];
}
get [designerSymbol]() {
get [designerSymbol](): Designer {
return this[editorSymbol].get('designer')!;
}
@ -66,6 +66,10 @@ export default class Material {
return this[editorSymbol].get('assets');
}
async asyncGetAssets() {
return await this[editorSymbol].get('assets');
}
/**
*
* @param incrementalAssets

View File

@ -6,7 +6,7 @@ import {
} from '@alilc/lowcode-designer';
import { RootSchema, ProjectSchema, IEditor } from '@alilc/lowcode-types';
import { globalContext } from '@alilc/lowcode-editor-core';
import DocumentModel from './document-model';
import DocumentModel, { Events } from './document-model';
import SimulatorHost from './simulator-host';
import { editorSymbol, projectSymbol, simulatorHostSymbol, simulatorRendererSymbol, documentSymbol } from './symbols';
@ -129,6 +129,7 @@ export default class Project {
*/
importSchema(schema?: ProjectSchema) {
this[projectSymbol].load(schema, true);
// this[editorSymbol].emit(Events.IMPORT_SCHEMA, schema);
}
/**

View File

@ -53,10 +53,9 @@ export function megreAssets(assets: AssetsJson, incrementalAssets: AssetsJson):
}
if (incrementalAssets.components) {
assets.components = [...assets.components, ...incrementalAssets.components];
assets.components = [...(assets.components || []), ...incrementalAssets.components];
}
megreAssetsComponentList(assets, incrementalAssets, 'componentList');
megreAssetsComponentList(assets, incrementalAssets, 'bizComponentList');

View File

@ -9,6 +9,15 @@ export class EditorWindow {
this.init();
}
async importSchema(schema: any) {
const newSchema = await this.resource.import(schema);
Object.keys(newSchema).forEach(key => {
const view = this.editorViews.get(key);
view?.project.importSchema(newSchema[key]);
});
}
async init() {
await this.initViewTypes();
await this.execViewTypesInit();
@ -17,7 +26,7 @@ export class EditorWindow {
initViewTypes = async () => {
const editorViews = this.resource.editorViews;
for (let i = editorViews.length - 1; i >= 0; i--) {
for (let i = 0; i < editorViews.length; i++) {
const name = editorViews[i].name;
await this.initViewType(name);
if (!this.editorView) {
@ -28,7 +37,7 @@ export class EditorWindow {
execViewTypesInit = async () => {
const editorViews = this.resource.editorViews;
for (let i = editorViews.length - 1; i >= 0; i--) {
for (let i = 0; i < editorViews.length; i++) {
const name = editorViews[i].name;
this.changeViewType(name);
await this.editorViews.get(name)?.init();

View File

@ -67,6 +67,7 @@ export interface ResourceOptions {
editorViews?: EditorViewOptions[];
init: (ctx: any) => Promise<void>;
dispose: (ctx: any) => Promise<void>;
import: (ctx: any) => Promise<any>;
}
export interface EditorViewOptions {

View File

@ -19,6 +19,10 @@ export class Resource {
this.options.init(ctx);
}
async import(schema: any) {
return await this.options.import?.(schema);
}
getEditorView(name: string) {
return this.editorViewMap.get(name);
}