mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 19:52:51 +00:00
fix: bugfix
This commit is contained in:
parent
61bc8e6c3d
commit
ac8aa2c5a4
@ -1,3 +1,3 @@
|
||||
export * from './context';
|
||||
export * from './plugin';
|
||||
export type * from '@alilc/lowcode-renderer-router';
|
||||
export type { Router, RouterHistory } from '@alilc/lowcode-renderer-router';
|
||||
|
||||
@ -57,17 +57,17 @@ export class ExtensionHostService implements IExtensionHostService {
|
||||
continue;
|
||||
}
|
||||
|
||||
await this.doSetupPlugin(plugin);
|
||||
const pluginRuntime = plugin as IPluginRuntime;
|
||||
|
||||
pluginRuntime.status = 'ready';
|
||||
this.pluginRuntimes.push(pluginRuntime);
|
||||
|
||||
await this.doSetupPlugin(pluginRuntime);
|
||||
}
|
||||
}
|
||||
|
||||
private async doSetupPlugin(plugin: Plugin) {
|
||||
const pluginRuntime = plugin as IPluginRuntime;
|
||||
|
||||
this.pluginRuntimes.push({
|
||||
...pluginRuntime,
|
||||
status: 'ready',
|
||||
});
|
||||
private async doSetupPlugin(pluginRuntime: IPluginRuntime) {
|
||||
if (pluginRuntime.status === 'setup') return;
|
||||
|
||||
const isSetup = (name: string) => {
|
||||
const setupPlugins = this.pluginRuntimes.filter((item) => item.status === 'setup');
|
||||
|
||||
@ -33,12 +33,16 @@ export interface IPackageManagementService {
|
||||
|
||||
setLibraryByPackageName(packageName: string, library: any): void;
|
||||
|
||||
getLibraryByComponentMap(componentMap: Spec.ComponentMap): any;
|
||||
|
||||
/** 解析组件映射 */
|
||||
resolveComponentMaps(componentMaps: Spec.ComponentMap[]): void;
|
||||
|
||||
/** 获取组件映射对象,key = componentName value = component */
|
||||
getComponentsNameRecord<C = unknown>(
|
||||
componentMaps?: Spec.ComponentMap[],
|
||||
): Record<string, C | LowCodeComponent>;
|
||||
|
||||
/** 通过组件名获取对应的组件 */
|
||||
getComponent<C = unknown>(componentName: string): C | LowCodeComponent | undefined;
|
||||
/** 注册组件 */
|
||||
@ -105,6 +109,33 @@ export class PackageManagementService implements IPackageManagementService {
|
||||
this.packageStore.set(packageName, library);
|
||||
}
|
||||
|
||||
getLibraryByComponentMap(componentMap: Spec.ComponentMap) {
|
||||
if (this.packageStore.has(componentMap.package!)) {
|
||||
const library = this.packageStore.get(componentMap.package!);
|
||||
// export { exportName } from xxx exportName === global.libraryName.exportName
|
||||
// export exportName from xxx exportName === global.libraryName.default || global.libraryName
|
||||
// export { exportName as componentName } from package
|
||||
// if exportName == null exportName === componentName;
|
||||
// const componentName = exportName.subName, if exportName empty subName donot use
|
||||
const paths =
|
||||
componentMap.exportName && componentMap.subName ? componentMap.subName.split('.') : [];
|
||||
const exportName = componentMap.exportName ?? componentMap.componentName;
|
||||
|
||||
if (componentMap.destructuring) {
|
||||
paths.unshift(exportName);
|
||||
}
|
||||
|
||||
let result = library;
|
||||
for (const path of paths) {
|
||||
result = result[path] || result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
resolveComponentMaps(componentMaps: Spec.ComponentMap[]) {
|
||||
for (const map of componentMaps) {
|
||||
if (map.devMode === 'lowCode') {
|
||||
@ -114,28 +145,8 @@ export class PackageManagementService implements IPackageManagementService {
|
||||
this.componentsRecord[map.componentName] = packageInfo;
|
||||
}
|
||||
} else {
|
||||
if (this.packageStore.has(map.package!)) {
|
||||
const library = this.packageStore.get(map.package!);
|
||||
// export { exportName } from xxx exportName === global.libraryName.exportName
|
||||
// export exportName from xxx exportName === global.libraryName.default || global.libraryName
|
||||
// export { exportName as componentName } from package
|
||||
// if exportName == null exportName === componentName;
|
||||
// const componentName = exportName.subName, if exportName empty subName donot use
|
||||
const paths = map.exportName && map.subName ? map.subName.split('.') : [];
|
||||
const exportName = map.exportName ?? map.componentName;
|
||||
|
||||
if (map.destructuring) {
|
||||
paths.unshift(exportName);
|
||||
}
|
||||
|
||||
let result = library;
|
||||
for (const path of paths) {
|
||||
result = result[path] || result;
|
||||
}
|
||||
|
||||
const recordName = map.componentName ?? map.exportName;
|
||||
if (recordName && result) this.componentsRecord[recordName] = result;
|
||||
}
|
||||
const result = this.getLibraryByComponentMap(map);
|
||||
if (map.componentName && result) this.componentsRecord[map.componentName] = result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,11 @@
|
||||
import { type AnyFunction, type Spec, createDecorator, Provide } from '@alilc/lowcode-shared';
|
||||
import {
|
||||
type AnyFunction,
|
||||
type Spec,
|
||||
createDecorator,
|
||||
Provide,
|
||||
type PlainObject,
|
||||
} from '@alilc/lowcode-shared';
|
||||
import { isPlainObject } from 'lodash-es';
|
||||
import { IPackageManagementService } from './package';
|
||||
import { ICodeRuntimeService } from './code-runtime';
|
||||
import { ILifeCycleService, LifecyclePhase } from './lifeCycleService';
|
||||
@ -6,7 +13,7 @@ import { ISchemaService } from './schema';
|
||||
|
||||
export interface IRuntimeUtilService {
|
||||
add(utilItem: Spec.Util): void;
|
||||
add(name: string, fn: AnyFunction): void;
|
||||
add(name: string, target: AnyFunction | PlainObject): void;
|
||||
|
||||
remove(name: string): void;
|
||||
}
|
||||
@ -15,7 +22,7 @@ export const IRuntimeUtilService = createDecorator<IRuntimeUtilService>('rendere
|
||||
|
||||
@Provide(IRuntimeUtilService)
|
||||
export class RuntimeUtilService implements IRuntimeUtilService {
|
||||
private utilsMap: Map<string, AnyFunction> = new Map();
|
||||
private utilsMap: Map<string, any> = new Map();
|
||||
|
||||
constructor(
|
||||
@ICodeRuntimeService private codeRuntimeService: ICodeRuntimeService,
|
||||
@ -33,15 +40,25 @@ export class RuntimeUtilService implements IRuntimeUtilService {
|
||||
}
|
||||
|
||||
add(utilItem: Spec.Util): void;
|
||||
add(name: string, fn: AnyFunction): void;
|
||||
add(name: Spec.Util | string, fn?: AnyFunction): void {
|
||||
add(name: string, fn: AnyFunction | PlainObject): void;
|
||||
add(name: Spec.Util | string, fn?: AnyFunction | PlainObject): void {
|
||||
if (typeof name === 'string') {
|
||||
if (typeof fn === 'function') {
|
||||
this.utilsMap.set(name, fn as AnyFunction);
|
||||
if (fn) {
|
||||
if (isPlainObject(fn)) {
|
||||
if ((fn as PlainObject).destructuring) {
|
||||
for (const key of Object.keys(fn)) {
|
||||
this.add(key, (fn as PlainObject)[key]);
|
||||
}
|
||||
} else {
|
||||
this.utilsMap.set(name, fn);
|
||||
}
|
||||
} else if (typeof fn === 'function') {
|
||||
this.utilsMap.set(name, fn);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const fn = this.parseUtil(name);
|
||||
if (fn) this.utilsMap.set(name.name, fn);
|
||||
const util = this.parseUtil(name);
|
||||
if (util) this.add(name.name, util);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,6 +66,15 @@ export class RuntimeUtilService implements IRuntimeUtilService {
|
||||
this.utilsMap.delete(name);
|
||||
}
|
||||
|
||||
private parseUtil(utilItem: Spec.Util) {
|
||||
if (utilItem.type === 'function') {
|
||||
const { content } = utilItem;
|
||||
return this.codeRuntimeService.run(content.value);
|
||||
} else {
|
||||
return this.packageManagementService.getLibraryByComponentMap(utilItem.content);
|
||||
}
|
||||
}
|
||||
|
||||
private toExpose(): void {
|
||||
const exposed = new Proxy(Object.create(null), {
|
||||
get: (_, p: string) => {
|
||||
@ -64,26 +90,4 @@ export class RuntimeUtilService implements IRuntimeUtilService {
|
||||
|
||||
this.codeRuntimeService.getScope().set('utils', exposed);
|
||||
}
|
||||
|
||||
private parseUtil(utilItem: Spec.Util) {
|
||||
if (utilItem.type === 'function') {
|
||||
const { content } = utilItem;
|
||||
|
||||
return this.codeRuntimeService.run(content.value);
|
||||
} else {
|
||||
const {
|
||||
content: { package: packageName, destructuring, exportName, subName },
|
||||
} = utilItem;
|
||||
let library: any = this.packageManagementService.getLibraryByPackageName(packageName!);
|
||||
|
||||
if (library) {
|
||||
if (destructuring) {
|
||||
const target = library[exportName!];
|
||||
library = subName ? target[subName] : target;
|
||||
}
|
||||
|
||||
return library;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,7 +329,7 @@ export interface ComponentNodeProps {
|
||||
export interface NPMUtil {
|
||||
name: string;
|
||||
type: 'npm';
|
||||
content: Omit<ComponentMap, 'componentName'>;
|
||||
content: ComponentMap;
|
||||
}
|
||||
|
||||
export interface FunctionUtil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user