mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
feat: 导出的schema增加componentsMap
This commit is contained in:
parent
87c2e0b386
commit
dbc958c6bc
@ -20,6 +20,15 @@ export type GetDataType<T, NodeType> = T extends undefined
|
||||
: any
|
||||
: T;
|
||||
|
||||
export interface ComponentMap {
|
||||
componentName: string;
|
||||
package: string;
|
||||
version?: string;
|
||||
destructuring?: boolean;
|
||||
exportName?: string;
|
||||
subName?: string;
|
||||
}
|
||||
|
||||
export class DocumentModel {
|
||||
/**
|
||||
* 根节点 类型有:Page/Component/Block
|
||||
@ -493,9 +502,13 @@ export class DocumentModel {
|
||||
}
|
||||
|
||||
// add toData
|
||||
toData() {
|
||||
toData(extraComps?: string[]) {
|
||||
const node = this.project?.currentDocument?.export(TransformStage.Save);
|
||||
return { componentsTree: [node] };
|
||||
const data = {
|
||||
componentsMap: this.getComponentsMap(extraComps),
|
||||
componentsTree: [node],
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
getHistory(): History {
|
||||
@ -564,6 +577,37 @@ export class DocumentModel {
|
||||
return this.rootNodeVisitorMap[name];
|
||||
}
|
||||
|
||||
getComponentsMap(extraComps?: string[]) {
|
||||
const componentsMap: ComponentMap[] = [];
|
||||
// 组件去重
|
||||
const map: any = {};
|
||||
for (let node of this.nodesMap.values()) {
|
||||
const { componentName } = node || {};
|
||||
if (!map[componentName] && node?.componentMeta?.npm?.package) {
|
||||
map[componentName] = true;
|
||||
componentsMap.push({
|
||||
componentName,
|
||||
package: node?.componentMeta?.npm?.package,
|
||||
});
|
||||
}
|
||||
}
|
||||
// 合并外界传入的自定义渲染的组件
|
||||
if (Array.isArray(extraComps)) {
|
||||
extraComps.forEach(c => {
|
||||
if (c && !map[c]) {
|
||||
const m = this.getComponentMeta(c);
|
||||
if (m && m.npm?.package) {
|
||||
componentsMap.push({
|
||||
componentName: c,
|
||||
package: m.npm?.package,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return componentsMap;
|
||||
}
|
||||
|
||||
onNodeCreate(func: (node: Node) => void) {
|
||||
this.emitter.on('nodecreate', func);
|
||||
return () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user