mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
fix: compatiable old VE api
This commit is contained in:
parent
c0a523584e
commit
45af1c53de
@ -1,5 +1,5 @@
|
||||
import { ComponentType, ReactElement } from 'react';
|
||||
import { ComponentMetadata, FieldConfig, InitialItem, FilterItem } from '@ali/lowcode-types';
|
||||
import { ComponentMetadata, FieldConfig, InitialItem, FilterItem, AutorunItem } from '@ali/lowcode-types';
|
||||
import {
|
||||
ComponentMeta,
|
||||
addBuiltinComponentAction,
|
||||
@ -22,12 +22,14 @@ const GlobalPropsConfigure: Array<{
|
||||
position: string;
|
||||
initials?: InitialItem[];
|
||||
filters?: FilterItem[];
|
||||
autoruns?: AutorunItem[];
|
||||
config: FieldConfig
|
||||
}> = [];
|
||||
const Overrides: {
|
||||
[componentName: string]: {
|
||||
initials?: InitialItem[];
|
||||
filters?: FilterItem[];
|
||||
autoruns?: AutorunItem[];
|
||||
override: any;
|
||||
};
|
||||
} = {};
|
||||
@ -35,10 +37,12 @@ const Overrides: {
|
||||
function addGlobalPropsConfigure(config: OldGlobalPropConfig) {
|
||||
const initials: InitialItem[] = [];
|
||||
const filters: FilterItem[] = [];
|
||||
const autoruns: AutorunItem[] = [];
|
||||
GlobalPropsConfigure.push({
|
||||
position: config.position || 'bottom',
|
||||
initials,
|
||||
filters,
|
||||
autoruns,
|
||||
config: upgradePropConfig(config, {
|
||||
addInitial: (item) => {
|
||||
initials.push(item);
|
||||
@ -46,6 +50,9 @@ function addGlobalPropsConfigure(config: OldGlobalPropConfig) {
|
||||
addFilter: (item) => {
|
||||
filters.push(item);
|
||||
},
|
||||
addAutorun: (item) => {
|
||||
autoruns.push(item);
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
@ -60,24 +67,29 @@ function removeGlobalPropsConfigure(name: string) {
|
||||
function overridePropsConfigure(componentName: string, config: { [name: string]: OldPropConfig } | OldPropConfig[]) {
|
||||
const initials: InitialItem[] = [];
|
||||
const filters: FilterItem[] = [];
|
||||
const autoruns: AutorunItem[] = [];
|
||||
const addInitial = (item: InitialItem) => {
|
||||
initials.push(item);
|
||||
};
|
||||
const addFilter = (item: FilterItem) => {
|
||||
filters.push(item);
|
||||
};
|
||||
const addAutorun = (item: AutorunItem) => {
|
||||
autoruns.push(item);
|
||||
};
|
||||
let override: any;
|
||||
if (Array.isArray(config)) {
|
||||
override = upgradeConfigure(config, { addInitial, addFilter });
|
||||
override = upgradeConfigure(config, { addInitial, addFilter, addAutorun });
|
||||
} else {
|
||||
override = {};
|
||||
Object.keys(config).forEach(key => {
|
||||
override[key] = upgradePropConfig(config[key], { addInitial, addFilter });
|
||||
override[key] = upgradePropConfig(config[key], { addInitial, addFilter, addAutorun });
|
||||
});
|
||||
}
|
||||
Overrides[componentName] = {
|
||||
initials,
|
||||
filters,
|
||||
autoruns,
|
||||
override,
|
||||
};
|
||||
}
|
||||
@ -107,6 +119,7 @@ registerMetadataTransducer(
|
||||
} else if (position === 'bottom') {
|
||||
bottom.push(item.config);
|
||||
}
|
||||
// TODO: replace autoruns,initials,filters
|
||||
});
|
||||
|
||||
const override = Overrides[componentName]?.override;
|
||||
@ -127,6 +140,7 @@ registerMetadataTransducer(
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: replace autoruns,initials,filters
|
||||
}
|
||||
|
||||
return metadata;
|
||||
@ -202,7 +216,7 @@ class Prototype {
|
||||
return new Prototype(config);
|
||||
}
|
||||
|
||||
private id: string;
|
||||
readonly isPrototype = true;
|
||||
private meta: ComponentMeta;
|
||||
readonly options: OldPrototypeConfig | ComponentMetadata;
|
||||
|
||||
@ -215,11 +229,10 @@ class Prototype {
|
||||
const metadata = isNewSpec(input) ? input : upgradeMetadata(input);
|
||||
this.meta = designer.createComponentMeta(metadata);
|
||||
}
|
||||
this.id = uniqueId('prototype');
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.id;
|
||||
return this.getComponentName();
|
||||
}
|
||||
|
||||
getConfig(configName?: keyof (OldPrototypeConfig | ComponentMetadata)) {
|
||||
@ -316,4 +329,8 @@ class Prototype {
|
||||
}
|
||||
}
|
||||
|
||||
export function isPrototype(obj: any): obj is Prototype {
|
||||
return obj && obj.isPrototype;
|
||||
}
|
||||
|
||||
export default Prototype;
|
||||
|
||||
@ -41,6 +41,10 @@ export class Trunk {
|
||||
return this.metaBundle.getFromMeta(name);
|
||||
}
|
||||
|
||||
getPrototypeById(id: string) {
|
||||
return this.getPrototype(id);
|
||||
}
|
||||
|
||||
listByCategory() {
|
||||
const categories: any[] = [];
|
||||
const categoryMap: any = {};
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { designer } from './editor';
|
||||
import { DragObjectType, isNode, isDragNodeDataObject } from '@ali/lowcode-designer';
|
||||
import { isPrototype } from './bundle/prototype';
|
||||
|
||||
const dragon = designer.dragon;
|
||||
const DragEngine = {
|
||||
@ -9,7 +10,14 @@ const DragEngine = {
|
||||
if (!r) {
|
||||
return null;
|
||||
}
|
||||
if (isNode(r)) {
|
||||
if (isPrototype(r)) {
|
||||
return {
|
||||
type: DragObjectType.NodeData,
|
||||
data: {
|
||||
componentName: r.getComponentName(),
|
||||
},
|
||||
};
|
||||
} else if (isNode(r)) {
|
||||
return {
|
||||
type: DragObjectType.Node,
|
||||
nodes: [r],
|
||||
|
||||
@ -164,7 +164,7 @@ export {
|
||||
const version = '6.0.0(LowcodeEngine 0.9.0-beta)';
|
||||
|
||||
console.log(
|
||||
`%cVisionEngine %cv${version}`,
|
||||
"color:#000;font-weight:bold;",
|
||||
"color:green;font-weight:bold;"
|
||||
`%c VisionEngine %c v${version} `,
|
||||
"padding: 2px 1px; border-radius: 3px 0 0 3px; color: #fff; background: #606060;font-weight:bold;",
|
||||
"padding: 2px 1px; border-radius: 0 3px 3px 0; color: #fff; background: #42c02e;font-weight:bold;"
|
||||
);
|
||||
|
||||
@ -4,34 +4,60 @@ import { DocumentModel } from '@ali/lowcode-designer';
|
||||
|
||||
const { project } = designer;
|
||||
|
||||
export interface OldPageData {
|
||||
export interface PageDataV1 {
|
||||
id: string;
|
||||
componentsTree: RootSchema[];
|
||||
layout: RootSchema;
|
||||
[dataAddon: string]: any;
|
||||
}
|
||||
|
||||
export interface PageDataV2 {
|
||||
id: string;
|
||||
componentsTree: RootSchema[];
|
||||
[dataAddon: string]: any;
|
||||
}
|
||||
|
||||
function isPageDataV1(obj: any): obj is PageDataV1 {
|
||||
return obj && obj.layout;
|
||||
}
|
||||
function isPageDataV2(obj: any): obj is PageDataV2 {
|
||||
return obj && obj.componentsTree && Array.isArray(obj.componentsTree);
|
||||
}
|
||||
|
||||
type OldPageData = PageDataV1 | PageDataV2;
|
||||
|
||||
const pages = Object.assign(project, {
|
||||
setPages(pages: OldPageData[]) {
|
||||
if (!pages || !Array.isArray(pages) || pages.length === 0) {
|
||||
throw new Error('pages schema 不合法');
|
||||
}
|
||||
|
||||
if (pages[0].componentsTree[0]) {
|
||||
pages[0].componentsTree[0].componentName = 'Page';
|
||||
// FIXME
|
||||
pages[0].componentsTree[0].lifeCycles = {};
|
||||
pages[0].componentsTree[0].methods = {};
|
||||
let componentsTree: any;
|
||||
if (isPageDataV1(pages[0])) {
|
||||
componentsTree = [pages[0].layout];
|
||||
} else {
|
||||
componentsTree = pages[0].componentsTree;
|
||||
if (componentsTree[0]) {
|
||||
componentsTree[0].componentName = 'Page';
|
||||
// FIXME
|
||||
componentsTree[0].lifeCycles = {};
|
||||
componentsTree[0].methods = {};
|
||||
}
|
||||
}
|
||||
|
||||
project.load({
|
||||
version: '1.0.0',
|
||||
componentsMap: [],
|
||||
componentsTree: pages[0].componentsTree,
|
||||
componentsTree,
|
||||
}, true);
|
||||
},
|
||||
// FIXME:
|
||||
addPage(data: OldPageData) {
|
||||
return project.open(data.layout);
|
||||
addPage(data: OldPageData | RootSchema) {
|
||||
if (isPageDataV1(data)) {
|
||||
data = data.layout;
|
||||
} else if (isPageDataV2(data)) {
|
||||
data = data.componentsTree[0];
|
||||
}
|
||||
return project.open(data);
|
||||
},
|
||||
getPage(fnOrIndex: ((page: DocumentModel) => boolean) | number) {
|
||||
if (typeof fnOrIndex === 'number') {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user