mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-10 09:56:20 +00:00
fix: 支持 AC 组件
This commit is contained in:
parent
c0a6022f75
commit
c287bad37b
@ -2,6 +2,7 @@ import lg from '@ali/vu-logger';
|
|||||||
import { ComponentClass, ComponentType } from 'react';
|
import { ComponentClass, ComponentType } from 'react';
|
||||||
import Prototype, { isPrototype } from './prototype';
|
import Prototype, { isPrototype } from './prototype';
|
||||||
import { designer } from '../editor';
|
import { designer } from '../editor';
|
||||||
|
import trunk from './trunk';
|
||||||
|
|
||||||
function basename(name: string) {
|
function basename(name: string) {
|
||||||
return name ? (/[^\/]+$/.exec(name) || [''])[0] : '';
|
return name ? (/[^\/]+$/.exec(name) || [''])[0] : '';
|
||||||
@ -65,6 +66,22 @@ export default class Bundle {
|
|||||||
this.recursivelyRegisterPrototypes(prototype, item);
|
this.recursivelyRegisterPrototypes(prototype, item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// invoke prototype mocker while the prototype does not exist
|
||||||
|
Object.keys(this.viewsMap).forEach((viewName) => {
|
||||||
|
const test = this;
|
||||||
|
// console.log(test, viewName);
|
||||||
|
if (!this.prototypeList.find((proto) => proto.getComponentName() === viewName)) {
|
||||||
|
const mockedPrototype = trunk.mockComponentPrototype(this.viewsMap[viewName]);
|
||||||
|
if (mockedPrototype) {
|
||||||
|
mockedPrototype.setView(this.viewsMap[viewName]);
|
||||||
|
this.registerPrototype(mockedPrototype);
|
||||||
|
if (!mockedPrototype.getPackageName()) {
|
||||||
|
mockedPrototype.setPackageName((this.viewsMap[viewName] as any)._packageName_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getFromMeta(componentName: string): Prototype {
|
getFromMeta(componentName: string): Prototype {
|
||||||
|
|||||||
@ -213,8 +213,8 @@ class Prototype {
|
|||||||
static addGlobalExtraActions = addGlobalExtraActions;
|
static addGlobalExtraActions = addGlobalExtraActions;
|
||||||
static removeGlobalPropsConfigure = removeGlobalPropsConfigure;
|
static removeGlobalPropsConfigure = removeGlobalPropsConfigure;
|
||||||
static overridePropsConfigure = overridePropsConfigure;
|
static overridePropsConfigure = overridePropsConfigure;
|
||||||
static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) {
|
static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, extraConfigs: any = null, lookup: boolean = false) {
|
||||||
return new Prototype(config, lookup);
|
return new Prototype(config, extraConfigs, lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly isPrototype = true;
|
readonly isPrototype = true;
|
||||||
@ -224,7 +224,7 @@ class Prototype {
|
|||||||
return this.meta.npm?.package;
|
return this.meta.npm?.package;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) {
|
constructor(input: OldPrototypeConfig | ComponentMetadata | ComponentMeta, extraConfigs: any = null, lookup: boolean = false) {
|
||||||
if (lookup) {
|
if (lookup) {
|
||||||
this.meta = designer.getComponentMeta(input.componentName);
|
this.meta = designer.getComponentMeta(input.componentName);
|
||||||
this.options = this.meta.getMetadata();
|
this.options = this.meta.getMetadata();
|
||||||
@ -279,15 +279,15 @@ class Prototype {
|
|||||||
|
|
||||||
private category?: string;
|
private category?: string;
|
||||||
getCategory() {
|
getCategory() {
|
||||||
if (this.category != null) {
|
if (this.options.category != null) {
|
||||||
return this.category;
|
return this.options.category;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.meta.getMetadata().tags?.[0] || '*';
|
return this.meta.getMetadata().tags?.[0] || '*';
|
||||||
}
|
}
|
||||||
|
|
||||||
setCategory(category: string) {
|
setCategory(category: string) {
|
||||||
this.category = category;
|
this.options.category = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
getIcon() {
|
getIcon() {
|
||||||
|
|||||||
@ -3,11 +3,13 @@ import { EventEmitter } from 'events';
|
|||||||
import { registerSetter, RegisteredSetter, getSetter } from '@ali/lowcode-editor-core';
|
import { registerSetter, RegisteredSetter, getSetter } from '@ali/lowcode-editor-core';
|
||||||
import Bundle from './bundle';
|
import Bundle from './bundle';
|
||||||
import { CustomView } from '@ali/lowcode-types';
|
import { CustomView } from '@ali/lowcode-types';
|
||||||
|
import Prototype from './prototype';
|
||||||
|
|
||||||
export class Trunk {
|
export class Trunk {
|
||||||
private trunk: any[] = [];
|
private trunk: any[] = [];
|
||||||
private emitter: EventEmitter = new EventEmitter();
|
private emitter: EventEmitter = new EventEmitter();
|
||||||
private metaBundle = new Bundle();
|
private metaBundle = new Bundle();
|
||||||
|
private componentPrototypeMocker: any;
|
||||||
|
|
||||||
isReady() {
|
isReady() {
|
||||||
return this.getList().length > 0;
|
return this.getList().length > 0;
|
||||||
@ -25,7 +27,13 @@ export class Trunk {
|
|||||||
|
|
||||||
getList(): any[] {
|
getList(): any[] {
|
||||||
const list = this.trunk.reduceRight((prev, cur) => prev.concat(cur.getList()), []);
|
const list = this.trunk.reduceRight((prev, cur) => prev.concat(cur.getList()), []);
|
||||||
return Array.from(new Set(list));
|
const result: Prototype[] = [];
|
||||||
|
list.forEach((item: Prototype) => {
|
||||||
|
if (!result.find(r => r.options.componentName === item.options.componentName)) {
|
||||||
|
result.push(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPrototype(name: string) {
|
getPrototype(name: string) {
|
||||||
@ -98,8 +106,16 @@ export class Trunk {
|
|||||||
console.warn('Trunk.afterLoadBundle is deprecated');
|
console.warn('Trunk.afterLoadBundle is deprecated');
|
||||||
}
|
}
|
||||||
|
|
||||||
registerComponentPrototypeMocker() {
|
registerComponentPrototypeMocker(mocker: any) {
|
||||||
console.warn('Trunk.registerComponentPrototypeMocker is deprecated');
|
this.componentPrototypeMocker = mocker;
|
||||||
|
}
|
||||||
|
|
||||||
|
mockComponentPrototype(bundle: any) {
|
||||||
|
if (!this.componentPrototypeMocker) {
|
||||||
|
lg.error('ERROR: no component prototypeMocker is set');
|
||||||
|
}
|
||||||
|
return this.componentPrototypeMocker
|
||||||
|
&& this.componentPrototypeMocker.mockPrototype(bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
setPackages() {
|
setPackages() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user