mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-01 05:30:40 +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 Prototype, { isPrototype } from './prototype';
|
||||
import { designer } from '../editor';
|
||||
import trunk from './trunk';
|
||||
|
||||
function basename(name: string) {
|
||||
return name ? (/[^\/]+$/.exec(name) || [''])[0] : '';
|
||||
@ -65,6 +66,22 @@ export default class Bundle {
|
||||
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 {
|
||||
|
||||
@ -213,8 +213,8 @@ class Prototype {
|
||||
static addGlobalExtraActions = addGlobalExtraActions;
|
||||
static removeGlobalPropsConfigure = removeGlobalPropsConfigure;
|
||||
static overridePropsConfigure = overridePropsConfigure;
|
||||
static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, lookup: boolean = false) {
|
||||
return new Prototype(config, lookup);
|
||||
static create(config: OldPrototypeConfig | ComponentMetadata | ComponentMeta, extraConfigs: any = null, lookup: boolean = false) {
|
||||
return new Prototype(config, extraConfigs, lookup);
|
||||
}
|
||||
|
||||
readonly isPrototype = true;
|
||||
@ -224,7 +224,7 @@ class Prototype {
|
||||
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) {
|
||||
this.meta = designer.getComponentMeta(input.componentName);
|
||||
this.options = this.meta.getMetadata();
|
||||
@ -279,15 +279,15 @@ class Prototype {
|
||||
|
||||
private category?: string;
|
||||
getCategory() {
|
||||
if (this.category != null) {
|
||||
return this.category;
|
||||
if (this.options.category != null) {
|
||||
return this.options.category;
|
||||
}
|
||||
|
||||
return this.meta.getMetadata().tags?.[0] || '*';
|
||||
}
|
||||
|
||||
setCategory(category: string) {
|
||||
this.category = category;
|
||||
this.options.category = category;
|
||||
}
|
||||
|
||||
getIcon() {
|
||||
|
||||
@ -3,11 +3,13 @@ import { EventEmitter } from 'events';
|
||||
import { registerSetter, RegisteredSetter, getSetter } from '@ali/lowcode-editor-core';
|
||||
import Bundle from './bundle';
|
||||
import { CustomView } from '@ali/lowcode-types';
|
||||
import Prototype from './prototype';
|
||||
|
||||
export class Trunk {
|
||||
private trunk: any[] = [];
|
||||
private emitter: EventEmitter = new EventEmitter();
|
||||
private metaBundle = new Bundle();
|
||||
private componentPrototypeMocker: any;
|
||||
|
||||
isReady() {
|
||||
return this.getList().length > 0;
|
||||
@ -25,7 +27,13 @@ export class Trunk {
|
||||
|
||||
getList(): any[] {
|
||||
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) {
|
||||
@ -98,8 +106,16 @@ export class Trunk {
|
||||
console.warn('Trunk.afterLoadBundle is deprecated');
|
||||
}
|
||||
|
||||
registerComponentPrototypeMocker() {
|
||||
console.warn('Trunk.registerComponentPrototypeMocker is deprecated');
|
||||
registerComponentPrototypeMocker(mocker: any) {
|
||||
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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user