mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-14 13:03:07 +00:00
fix: project.exportSchema should export componentsMap of all documents
This commit is contained in:
parent
6e96adf217
commit
969a130b37
@ -1,5 +1,5 @@
|
|||||||
import { computed, makeObservable, obx, action, runWithGlobalEventOff, wrapWithEventSwitch } from '@alilc/lowcode-editor-core';
|
import { computed, makeObservable, obx, action, runWithGlobalEventOff, wrapWithEventSwitch } from '@alilc/lowcode-editor-core';
|
||||||
import { NodeData, isJSExpression, isDOMText, NodeSchema, isNodeSchema, RootSchema, PageSchema } from '@alilc/lowcode-types';
|
import { NodeData, isJSExpression, isDOMText, NodeSchema, isNodeSchema, RootSchema, PageSchema, ComponentsMap } from '@alilc/lowcode-types';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { Project } from '../project';
|
import { Project } from '../project';
|
||||||
import { ISimulatorHost } from '../simulator';
|
import { ISimulatorHost } from '../simulator';
|
||||||
@ -19,16 +19,6 @@ export type GetDataType<T, NodeType> = T extends undefined
|
|||||||
: any
|
: any
|
||||||
: T;
|
: T;
|
||||||
|
|
||||||
export interface ComponentMap {
|
|
||||||
componentName: string;
|
|
||||||
package?: string;
|
|
||||||
version?: string;
|
|
||||||
destructuring?: boolean;
|
|
||||||
exportName?: string;
|
|
||||||
subName?: string;
|
|
||||||
devMode?: 'lowCode' | 'proCode';
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DocumentModel {
|
export class DocumentModel {
|
||||||
/**
|
/**
|
||||||
* 根节点 类型有:Page/Component/Block
|
* 根节点 类型有:Page/Component/Block
|
||||||
@ -652,7 +642,7 @@ export class DocumentModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getComponentsMap(extraComps?: string[]) {
|
getComponentsMap(extraComps?: string[]) {
|
||||||
const componentsMap: ComponentMap[] = [];
|
const componentsMap: ComponentsMap = [];
|
||||||
// 组件去重
|
// 组件去重
|
||||||
const exsitingMap: { [componentName: string]: boolean } = {};
|
const exsitingMap: { [componentName: string]: boolean } = {};
|
||||||
for (const node of this._nodesMap.values()) {
|
for (const node of this._nodesMap.values()) {
|
||||||
|
|||||||
@ -2,7 +2,14 @@ import { EventEmitter } from 'events';
|
|||||||
import { obx, computed, makeObservable, action } from '@alilc/lowcode-editor-core';
|
import { obx, computed, makeObservable, action } from '@alilc/lowcode-editor-core';
|
||||||
import { Designer } from '../designer';
|
import { Designer } from '../designer';
|
||||||
import { DocumentModel, isDocumentModel, isPageSchema } from '../document';
|
import { DocumentModel, isDocumentModel, isPageSchema } from '../document';
|
||||||
import { ProjectSchema, RootSchema, TransformStage } from '@alilc/lowcode-types';
|
import {
|
||||||
|
ProjectSchema,
|
||||||
|
RootSchema,
|
||||||
|
ComponentsMap,
|
||||||
|
TransformStage,
|
||||||
|
isLowCodeComponentType,
|
||||||
|
isProCodeComponentType,
|
||||||
|
} from '@alilc/lowcode-types';
|
||||||
import { ISimulatorHost } from '../simulator';
|
import { ISimulatorHost } from '../simulator';
|
||||||
|
|
||||||
export class Project {
|
export class Project {
|
||||||
@ -10,7 +17,12 @@ export class Project {
|
|||||||
|
|
||||||
@obx.shallow readonly documents: DocumentModel[] = [];
|
@obx.shallow readonly documents: DocumentModel[] = [];
|
||||||
|
|
||||||
private data: ProjectSchema = { version: '1.0.0', componentsMap: [], componentsTree: [], i18n: {} };
|
private data: ProjectSchema = {
|
||||||
|
version: '1.0.0',
|
||||||
|
componentsMap: [],
|
||||||
|
componentsTree: [],
|
||||||
|
i18n: {},
|
||||||
|
};
|
||||||
|
|
||||||
private _simulator?: ISimulatorHost;
|
private _simulator?: ISimulatorHost;
|
||||||
|
|
||||||
@ -49,15 +61,45 @@ export class Project {
|
|||||||
this._i18n = value || {};
|
this._i18n = value || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getComponentsMap(): ComponentsMap {
|
||||||
|
return this.documents.reduce((compomentsMap: ComponentsMap, curDoc: DocumentModel) => {
|
||||||
|
const curComponentsMap = curDoc.getComponentsMap();
|
||||||
|
if (Array.isArray(curComponentsMap)) {
|
||||||
|
curComponentsMap.forEach((item) => {
|
||||||
|
const found = compomentsMap.find((eItem) => {
|
||||||
|
if (
|
||||||
|
isProCodeComponentType(eItem) &&
|
||||||
|
isProCodeComponentType(item) &&
|
||||||
|
eItem.package === item.package &&
|
||||||
|
eItem.componentName === item.componentName
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else if (
|
||||||
|
isLowCodeComponentType(eItem) &&
|
||||||
|
eItem.componentName === item.componentName
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
if (found) return;
|
||||||
|
compomentsMap.push(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return compomentsMap;
|
||||||
|
}, [] as ComponentsMap);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目整体 schema
|
* 获取项目整体 schema
|
||||||
*/
|
*/
|
||||||
getSchema(stage: TransformStage = TransformStage.Save): ProjectSchema {
|
getSchema(stage: TransformStage = TransformStage.Save): ProjectSchema {
|
||||||
return {
|
return {
|
||||||
...this.data,
|
...this.data,
|
||||||
// TODO: future change this filter
|
componentsMap: this.getComponentsMap(),
|
||||||
componentsMap: this.currentDocument?.getComponentsMap(),
|
componentsTree: this.documents
|
||||||
componentsTree: this.documents.filter((doc) => !doc.isBlank()).map((doc) => doc.export(stage)),
|
.filter((doc) => !doc.isBlank())
|
||||||
|
.map((doc) => doc.export(stage)),
|
||||||
i18n: this.i18n,
|
i18n: this.i18n,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -100,7 +142,9 @@ export class Project {
|
|||||||
// TODO: 暂时先读 config tabBar 里的值,后面看整个 layout 结构是否能作为引擎规范
|
// TODO: 暂时先读 config tabBar 里的值,后面看整个 layout 结构是否能作为引擎规范
|
||||||
if (this.config?.layout?.props?.tabBar?.items?.length > 0) {
|
if (this.config?.layout?.props?.tabBar?.items?.length > 0) {
|
||||||
// slice(1)这个贼不雅,默认任务fileName 是类'/fileName'的形式
|
// slice(1)这个贼不雅,默认任务fileName 是类'/fileName'的形式
|
||||||
documentInstances.find((i) => i.fileName === this.config.layout.props.tabBar.items[0].path?.slice(1))?.open();
|
documentInstances
|
||||||
|
.find((i) => i.fileName === this.config.layout.props.tabBar.items[0].path?.slice(1))
|
||||||
|
?.open();
|
||||||
} else {
|
} else {
|
||||||
documentInstances[0].open();
|
documentInstances[0].open();
|
||||||
}
|
}
|
||||||
@ -189,11 +233,11 @@ export class Project {
|
|||||||
|
|
||||||
getDocument(id: string): DocumentModel | null {
|
getDocument(id: string): DocumentModel | null {
|
||||||
// 此处不能使用 this.documentsMap.get(id),因为在乐高 rollback 场景,document.id 会被改成其他值
|
// 此处不能使用 this.documentsMap.get(id),因为在乐高 rollback 场景,document.id 会被改成其他值
|
||||||
return this.documents.find(doc => doc.id === id) || null;
|
return this.documents.find((doc) => doc.id === id) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDocumentByFileName(fileName: string): DocumentModel | null {
|
getDocumentByFileName(fileName: string): DocumentModel | null {
|
||||||
return this.documents.find(doc => doc.fileName === fileName) || null;
|
return this.documents.find((doc) => doc.fileName === fileName) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
|||||||
@ -32,4 +32,26 @@ export interface NpmInfo {
|
|||||||
main?: string;
|
main?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ComponentsMap = NpmInfo[];
|
export interface LowCodeComponentType {
|
||||||
|
/**
|
||||||
|
* 研发模式
|
||||||
|
*/
|
||||||
|
devMode: 'lowCode';
|
||||||
|
/**
|
||||||
|
* 组件名称
|
||||||
|
*/
|
||||||
|
componentName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProCodeComponentType = NpmInfo;
|
||||||
|
export type ComponentMap = ProCodeComponentType | LowCodeComponentType;
|
||||||
|
|
||||||
|
export function isProCodeComponentType(desc: ComponentMap): desc is ProCodeComponentType {
|
||||||
|
return 'package' in desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isLowCodeComponentType(desc: ComponentMap): desc is LowCodeComponentType {
|
||||||
|
return !isProCodeComponentType(desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ComponentsMap = ComponentMap[];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user