mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-07 10:57:19 +00:00
fix: init
This commit is contained in:
parent
bf0ffc55fb
commit
1fa525d64a
@ -418,7 +418,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
|
|||||||
this.renderer?.rerender?.();
|
this.renderer?.rerender?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
async mountContentFrame(iframe: HTMLIFrameElement | null) {
|
async mountContentFrame(iframe: HTMLIFrameElement | null): Promise<void> {
|
||||||
if (!iframe || this._iframe === iframe) {
|
if (!iframe || this._iframe === iframe) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -399,12 +399,12 @@ export class Designer {
|
|||||||
const { components, packages } = incrementalAssets;
|
const { components, packages } = incrementalAssets;
|
||||||
components && this.buildComponentMetasMap(components);
|
components && this.buildComponentMetasMap(components);
|
||||||
if (packages) {
|
if (packages) {
|
||||||
await this.project.simulator!.setupComponents(packages);
|
await this.project.simulator?.setupComponents(packages);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (components) {
|
if (components) {
|
||||||
// 合并 assets
|
// 合并 assets
|
||||||
let assets = this.editor.get('assets');
|
let assets = this.editor.get('assets') || {};
|
||||||
let newAssets = megreAssets(assets, incrementalAssets);
|
let newAssets = megreAssets(assets, incrementalAssets);
|
||||||
// 对于 assets 存在需要二次网络下载的过程,必须 await 等待结束之后,再进行事件触发
|
// 对于 assets 存在需要二次网络下载的过程,必须 await 等待结束之后,再进行事件触发
|
||||||
await this.editor.set('assets', newAssets);
|
await this.editor.set('assets', newAssets);
|
||||||
|
|||||||
@ -113,10 +113,25 @@ export class Editor extends (EventEmitter as any) implements IEditor {
|
|||||||
if (remoteComponentDescriptions && remoteComponentDescriptions.length) {
|
if (remoteComponentDescriptions && remoteComponentDescriptions.length) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
remoteComponentDescriptions.map(async (component: any) => {
|
remoteComponentDescriptions.map(async (component: any) => {
|
||||||
const { exportName, url } = component;
|
const { exportName, url, npm } = component;
|
||||||
await (new AssetLoader()).load(url);
|
await (new AssetLoader()).load(url);
|
||||||
if (window[exportName]) {
|
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 || []);
|
assets.componentList = assets.componentList.concat(window[exportName].componentList || []);
|
||||||
}
|
}
|
||||||
return window[exportName];
|
return window[exportName];
|
||||||
@ -124,6 +139,7 @@ export class Editor extends (EventEmitter as any) implements IEditor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.context.set('assets', assets);
|
this.context.set('assets', assets);
|
||||||
this.notifyGot('assets');
|
this.notifyGot('assets');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -376,6 +376,7 @@ body {
|
|||||||
}
|
}
|
||||||
.lc-main-area {
|
.lc-main-area {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
background-color: #edeff3;
|
||||||
}
|
}
|
||||||
.lc-bottom-area {
|
.lc-bottom-area {
|
||||||
height: var(--bottom-area-height);
|
height: var(--bottom-area-height);
|
||||||
|
|||||||
@ -36,7 +36,7 @@ type PropChangeOptions = {
|
|||||||
oldValue: any;
|
oldValue: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Events = {
|
export const Events = {
|
||||||
IMPORT_SCHEMA: 'shell.document.importSchema',
|
IMPORT_SCHEMA: 'shell.document.importSchema',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export default class Material {
|
|||||||
private readonly [innerEditorSymbol]: Editor;
|
private readonly [innerEditorSymbol]: Editor;
|
||||||
// private readonly [designerSymbol]: Designer;
|
// private readonly [designerSymbol]: Designer;
|
||||||
|
|
||||||
get [editorSymbol]() {
|
get [editorSymbol](): Editor {
|
||||||
if (this.workspaceMode) {
|
if (this.workspaceMode) {
|
||||||
return this[innerEditorSymbol];
|
return this[innerEditorSymbol];
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ export default class Material {
|
|||||||
return this[innerEditorSymbol];
|
return this[innerEditorSymbol];
|
||||||
}
|
}
|
||||||
|
|
||||||
get [designerSymbol]() {
|
get [designerSymbol](): Designer {
|
||||||
return this[editorSymbol].get('designer')!;
|
return this[editorSymbol].get('designer')!;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +66,10 @@ export default class Material {
|
|||||||
return this[editorSymbol].get('assets');
|
return this[editorSymbol].get('assets');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async asyncGetAssets() {
|
||||||
|
return await this[editorSymbol].get('assets');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载增量的「资产包」结构,该增量包会与原有的合并
|
* 加载增量的「资产包」结构,该增量包会与原有的合并
|
||||||
* @param incrementalAssets
|
* @param incrementalAssets
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
} from '@alilc/lowcode-designer';
|
} from '@alilc/lowcode-designer';
|
||||||
import { RootSchema, ProjectSchema, IEditor } from '@alilc/lowcode-types';
|
import { RootSchema, ProjectSchema, IEditor } from '@alilc/lowcode-types';
|
||||||
import { globalContext } from '@alilc/lowcode-editor-core';
|
import { globalContext } from '@alilc/lowcode-editor-core';
|
||||||
import DocumentModel from './document-model';
|
import DocumentModel, { Events } from './document-model';
|
||||||
import SimulatorHost from './simulator-host';
|
import SimulatorHost from './simulator-host';
|
||||||
import { editorSymbol, projectSymbol, simulatorHostSymbol, simulatorRendererSymbol, documentSymbol } from './symbols';
|
import { editorSymbol, projectSymbol, simulatorHostSymbol, simulatorRendererSymbol, documentSymbol } from './symbols';
|
||||||
|
|
||||||
@ -129,6 +129,7 @@ export default class Project {
|
|||||||
*/
|
*/
|
||||||
importSchema(schema?: ProjectSchema) {
|
importSchema(schema?: ProjectSchema) {
|
||||||
this[projectSymbol].load(schema, true);
|
this[projectSymbol].load(schema, true);
|
||||||
|
// this[editorSymbol].emit(Events.IMPORT_SCHEMA, schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -53,10 +53,9 @@ export function megreAssets(assets: AssetsJson, incrementalAssets: AssetsJson):
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (incrementalAssets.components) {
|
if (incrementalAssets.components) {
|
||||||
assets.components = [...assets.components, ...incrementalAssets.components];
|
assets.components = [...(assets.components || []), ...incrementalAssets.components];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
megreAssetsComponentList(assets, incrementalAssets, 'componentList');
|
megreAssetsComponentList(assets, incrementalAssets, 'componentList');
|
||||||
megreAssetsComponentList(assets, incrementalAssets, 'bizComponentList');
|
megreAssetsComponentList(assets, incrementalAssets, 'bizComponentList');
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,15 @@ export class EditorWindow {
|
|||||||
this.init();
|
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() {
|
async init() {
|
||||||
await this.initViewTypes();
|
await this.initViewTypes();
|
||||||
await this.execViewTypesInit();
|
await this.execViewTypesInit();
|
||||||
@ -17,7 +26,7 @@ export class EditorWindow {
|
|||||||
|
|
||||||
initViewTypes = async () => {
|
initViewTypes = async () => {
|
||||||
const editorViews = this.resource.editorViews;
|
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;
|
const name = editorViews[i].name;
|
||||||
await this.initViewType(name);
|
await this.initViewType(name);
|
||||||
if (!this.editorView) {
|
if (!this.editorView) {
|
||||||
@ -28,7 +37,7 @@ export class EditorWindow {
|
|||||||
|
|
||||||
execViewTypesInit = async () => {
|
execViewTypesInit = async () => {
|
||||||
const editorViews = this.resource.editorViews;
|
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;
|
const name = editorViews[i].name;
|
||||||
this.changeViewType(name);
|
this.changeViewType(name);
|
||||||
await this.editorViews.get(name)?.init();
|
await this.editorViews.get(name)?.init();
|
||||||
|
|||||||
@ -67,6 +67,7 @@ export interface ResourceOptions {
|
|||||||
editorViews?: EditorViewOptions[];
|
editorViews?: EditorViewOptions[];
|
||||||
init: (ctx: any) => Promise<void>;
|
init: (ctx: any) => Promise<void>;
|
||||||
dispose: (ctx: any) => Promise<void>;
|
dispose: (ctx: any) => Promise<void>;
|
||||||
|
import: (ctx: any) => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EditorViewOptions {
|
export interface EditorViewOptions {
|
||||||
|
|||||||
@ -19,6 +19,10 @@ export class Resource {
|
|||||||
this.options.init(ctx);
|
this.options.init(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async import(schema: any) {
|
||||||
|
return await this.options.import?.(schema);
|
||||||
|
}
|
||||||
|
|
||||||
getEditorView(name: string) {
|
getEditorView(name: string) {
|
||||||
return this.editorViewMap.get(name);
|
return this.editorViewMap.get(name);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user