Skip to content

Commit ac8aa2c

Browse files
committed
fix: bugfix
1 parent 61bc8e6 commit ac8aa2c

File tree

5 files changed

+78
-63
lines changed

5 files changed

+78
-63
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './context';
22
export * from './plugin';
3-
export type * from '@alilc/lowcode-renderer-router';
3+
export type { Router, RouterHistory } from '@alilc/lowcode-renderer-router';

packages/renderer-core/src/services/extension/extensionHostService.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ export class ExtensionHostService implements IExtensionHostService {
5757
continue;
5858
}
5959

60-
await this.doSetupPlugin(plugin);
60+
const pluginRuntime = plugin as IPluginRuntime;
61+
62+
pluginRuntime.status = 'ready';
63+
this.pluginRuntimes.push(pluginRuntime);
64+
65+
await this.doSetupPlugin(pluginRuntime);
6166
}
6267
}
6368

64-
private async doSetupPlugin(plugin: Plugin) {
65-
const pluginRuntime = plugin as IPluginRuntime;
66-
67-
this.pluginRuntimes.push({
68-
...pluginRuntime,
69-
status: 'ready',
70-
});
69+
private async doSetupPlugin(pluginRuntime: IPluginRuntime) {
70+
if (pluginRuntime.status === 'setup') return;
7171

7272
const isSetup = (name: string) => {
7373
const setupPlugins = this.pluginRuntimes.filter((item) => item.status === 'setup');

packages/renderer-core/src/services/package/managementService.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ export interface IPackageManagementService {
3333

3434
setLibraryByPackageName(packageName: string, library: any): void;
3535

36+
getLibraryByComponentMap(componentMap: Spec.ComponentMap): any;
37+
3638
/** 解析组件映射 */
3739
resolveComponentMaps(componentMaps: Spec.ComponentMap[]): void;
40+
3841
/** 获取组件映射对象,key = componentName value = component */
3942
getComponentsNameRecord<C = unknown>(
4043
componentMaps?: Spec.ComponentMap[],
4144
): Record<string, C | LowCodeComponent>;
45+
4246
/** 通过组件名获取对应的组件 */
4347
getComponent<C = unknown>(componentName: string): C | LowCodeComponent | undefined;
4448
/** 注册组件 */
@@ -105,6 +109,33 @@ export class PackageManagementService implements IPackageManagementService {
105109
this.packageStore.set(packageName, library);
106110
}
107111

112+
getLibraryByComponentMap(componentMap: Spec.ComponentMap) {
113+
if (this.packageStore.has(componentMap.package!)) {
114+
const library = this.packageStore.get(componentMap.package!);
115+
// export { exportName } from xxx exportName === global.libraryName.exportName
116+
// export exportName from xxx exportName === global.libraryName.default || global.libraryName
117+
// export { exportName as componentName } from package
118+
// if exportName == null exportName === componentName;
119+
// const componentName = exportName.subName, if exportName empty subName donot use
120+
const paths =
121+
componentMap.exportName && componentMap.subName ? componentMap.subName.split('.') : [];
122+
const exportName = componentMap.exportName ?? componentMap.componentName;
123+
124+
if (componentMap.destructuring) {
125+
paths.unshift(exportName);
126+
}
127+
128+
let result = library;
129+
for (const path of paths) {
130+
result = result[path] || result;
131+
}
132+
133+
return result;
134+
}
135+
136+
return undefined;
137+
}
138+
108139
resolveComponentMaps(componentMaps: Spec.ComponentMap[]) {
109140
for (const map of componentMaps) {
110141
if (map.devMode === 'lowCode') {
@@ -114,28 +145,8 @@ export class PackageManagementService implements IPackageManagementService {
114145
this.componentsRecord[map.componentName] = packageInfo;
115146
}
116147
} else {
117-
if (this.packageStore.has(map.package!)) {
118-
const library = this.packageStore.get(map.package!);
119-
// export { exportName } from xxx exportName === global.libraryName.exportName
120-
// export exportName from xxx exportName === global.libraryName.default || global.libraryName
121-
// export { exportName as componentName } from package
122-
// if exportName == null exportName === componentName;
123-
// const componentName = exportName.subName, if exportName empty subName donot use
124-
const paths = map.exportName && map.subName ? map.subName.split('.') : [];
125-
const exportName = map.exportName ?? map.componentName;
126-
127-
if (map.destructuring) {
128-
paths.unshift(exportName);
129-
}
130-
131-
let result = library;
132-
for (const path of paths) {
133-
result = result[path] || result;
134-
}
135-
136-
const recordName = map.componentName ?? map.exportName;
137-
if (recordName && result) this.componentsRecord[recordName] = result;
138-
}
148+
const result = this.getLibraryByComponentMap(map);
149+
if (map.componentName && result) this.componentsRecord[map.componentName] = result;
139150
}
140151
}
141152
}
Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { type AnyFunction, type Spec, createDecorator, Provide } from '@alilc/lowcode-shared';
1+
import {
2+
type AnyFunction,
3+
type Spec,
4+
createDecorator,
5+
Provide,
6+
type PlainObject,
7+
} from '@alilc/lowcode-shared';
8+
import { isPlainObject } from 'lodash-es';
29
import { IPackageManagementService } from './package';
310
import { ICodeRuntimeService } from './code-runtime';
411
import { ILifeCycleService, LifecyclePhase } from './lifeCycleService';
512
import { ISchemaService } from './schema';
613

714
export interface IRuntimeUtilService {
815
add(utilItem: Spec.Util): void;
9-
add(name: string, fn: AnyFunction): void;
16+
add(name: string, target: AnyFunction | PlainObject): void;
1017

1118
remove(name: string): void;
1219
}
@@ -15,7 +22,7 @@ export const IRuntimeUtilService = createDecorator<IRuntimeUtilService>('rendere
1522

1623
@Provide(IRuntimeUtilService)
1724
export class RuntimeUtilService implements IRuntimeUtilService {
18-
private utilsMap: Map<string, AnyFunction> = new Map();
25+
private utilsMap: Map<string, any> = new Map();
1926

2027
constructor(
2128
@ICodeRuntimeService private codeRuntimeService: ICodeRuntimeService,
@@ -33,22 +40,41 @@ export class RuntimeUtilService implements IRuntimeUtilService {
3340
}
3441

3542
add(utilItem: Spec.Util): void;
36-
add(name: string, fn: AnyFunction): void;
37-
add(name: Spec.Util | string, fn?: AnyFunction): void {
43+
add(name: string, fn: AnyFunction | PlainObject): void;
44+
add(name: Spec.Util | string, fn?: AnyFunction | PlainObject): void {
3845
if (typeof name === 'string') {
39-
if (typeof fn === 'function') {
40-
this.utilsMap.set(name, fn as AnyFunction);
46+
if (fn) {
47+
if (isPlainObject(fn)) {
48+
if ((fn as PlainObject).destructuring) {
49+
for (const key of Object.keys(fn)) {
50+
this.add(key, (fn as PlainObject)[key]);
51+
}
52+
} else {
53+
this.utilsMap.set(name, fn);
54+
}
55+
} else if (typeof fn === 'function') {
56+
this.utilsMap.set(name, fn);
57+
}
4158
}
4259
} else {
43-
const fn = this.parseUtil(name);
44-
if (fn) this.utilsMap.set(name.name, fn);
60+
const util = this.parseUtil(name);
61+
if (util) this.add(name.name, util);
4562
}
4663
}
4764

4865
remove(name: string): void {
4966
this.utilsMap.delete(name);
5067
}
5168

69+
private parseUtil(utilItem: Spec.Util) {
70+
if (utilItem.type === 'function') {
71+
const { content } = utilItem;
72+
return this.codeRuntimeService.run(content.value);
73+
} else {
74+
return this.packageManagementService.getLibraryByComponentMap(utilItem.content);
75+
}
76+
}
77+
5278
private toExpose(): void {
5379
const exposed = new Proxy(Object.create(null), {
5480
get: (_, p: string) => {
@@ -64,26 +90,4 @@ export class RuntimeUtilService implements IRuntimeUtilService {
6490

6591
this.codeRuntimeService.getScope().set('utils', exposed);
6692
}
67-
68-
private parseUtil(utilItem: Spec.Util) {
69-
if (utilItem.type === 'function') {
70-
const { content } = utilItem;
71-
72-
return this.codeRuntimeService.run(content.value);
73-
} else {
74-
const {
75-
content: { package: packageName, destructuring, exportName, subName },
76-
} = utilItem;
77-
let library: any = this.packageManagementService.getLibraryByPackageName(packageName!);
78-
79-
if (library) {
80-
if (destructuring) {
81-
const target = library[exportName!];
82-
library = subName ? target[subName] : target;
83-
}
84-
85-
return library;
86-
}
87-
}
88-
}
8993
}

packages/shared/src/types/specs/lowcode-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ export interface ComponentNodeProps {
329329
export interface NPMUtil {
330330
name: string;
331331
type: 'npm';
332-
content: Omit<ComponentMap, 'componentName'>;
332+
content: ComponentMap;
333333
}
334334

335335
export interface FunctionUtil {

0 commit comments

Comments
 (0)