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