Skip to content

Commit

Permalink
fix: pluginContext
Browse files Browse the repository at this point in the history
  • Loading branch information
JackLian committed Dec 22, 2022
1 parent 51628cd commit fa20830
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
9 changes: 8 additions & 1 deletion packages/designer/src/plugin/plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
private plugins: ILowCodePluginRuntime[] = [];

pluginsMap: Map<string, ILowCodePluginRuntime> = new Map();
pluginContextMap: Map<string, LowCodePluginContext> = new Map();

private pluginPreference?: PluginPreference = new Map();

Expand All @@ -39,7 +40,13 @@ export class LowCodePluginManager implements ILowCodePluginManager {
}

_getLowCodePluginContext = (options: IPluginContextOptions) => {
return new LowCodePluginContext(options, this.contextApiAssembler);
const { pluginName } = options;
let context = this.pluginContextMap.get(pluginName);
if (!context) {
context = new LowCodePluginContext(options, this.contextApiAssembler);
this.pluginContextMap.set(pluginName, context);
}
return context;
};

isEngineVersionMatched(versionExp: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-skeleton/src/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export class Skeleton {
};
parsedConfig.contentProps = {
pluginContext: this.editor.get('innerPlugins')?._getLowCodePluginContext({
pluginName: 'any',
pluginName: parsedConfig.pluginName,
}),
...(parsedConfig.contentProps || {}),
};
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/src/engine-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const { project: innerProject } = designer;
const innerHotkey = new InnerHotkey();
const hotkey = new Hotkey(innerHotkey);
const project = new Project(innerProject);
const skeleton = new Skeleton(innerSkeleton);
const skeleton = new Skeleton(innerSkeleton, 'any', false);
const innerSetters = new InnerSetters();
const setters = new Setters(innerSetters);

Expand All @@ -98,7 +98,7 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string, meta: IPublicTypePluginMeta) => {
context.hotkey = hotkey;
context.project = project;
context.skeleton = skeleton;
context.skeleton = new Skeleton(innerSkeleton, pluginName, false);
context.setters = setters;
context.material = material;
const eventPrefix = meta?.eventPrefix || 'common';
Expand Down
10 changes: 8 additions & 2 deletions packages/shell/src/api/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IPublicApiSkeleton, IPublicTypeWidgetBaseConfig, IPublicTypeWidgetConfi
const innerSkeletonSymbol = Symbol('skeleton');
export class Skeleton implements IPublicApiSkeleton {
private readonly [innerSkeletonSymbol]: InnerSkeleton;
private readonly pluginName: string;

get [skeletonSymbol]() {
if (this.workspaceMode) {
Expand All @@ -22,8 +23,9 @@ export class Skeleton implements IPublicApiSkeleton {
return this[innerSkeletonSymbol];
}

constructor(skeleton: InnerSkeleton, readonly workspaceMode: boolean = false) {
constructor(skeleton: InnerSkeleton, pluginName: string, readonly workspaceMode: boolean = false) {
this[innerSkeletonSymbol] = skeleton;
this.pluginName = pluginName;
}

/**
Expand All @@ -33,7 +35,11 @@ export class Skeleton implements IPublicApiSkeleton {
* @returns
*/
add(config: IPublicTypeWidgetBaseConfig, extraConfig?: Record<string, any>) {
return this[skeletonSymbol].add(config, extraConfig);
const configWithName = {
...config,
pluginName: this.pluginName,
};
return this[skeletonSymbol].add(configWithName, extraConfig);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace/src/base-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class BasicContext {
const config = engineConfig;
const event = new Event(editor, { prefix: 'common' });
const logger = getLogger({ level: 'warn', bizName: 'common' });
const skeleton = new Skeleton(innerSkeleton, true);
const skeleton = new Skeleton(innerSkeleton, 'any', true);
editor.set('setters', setters);
editor.set('project', project);
editor.set('material', material);
Expand Down Expand Up @@ -110,7 +110,7 @@ export class BasicContext {
context.workspace = workspace;
context.hotkey = hotkey;
context.project = project;
context.skeleton = skeleton;
context.skeleton = new Skeleton(innerSkeleton, pluginName, true);
context.setters = setters;
context.material = material;
const eventPrefix = meta?.eventPrefix || 'common';
Expand Down

0 comments on commit fa20830

Please sign in to comment.