mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
feat: feat: remove circular dependency between designer and shell
This commit is contained in:
parent
da010eef42
commit
20c8419f22
@ -223,15 +223,16 @@ plugins.delete('builtinPluginRegistry');
|
|||||||
**类型定义**
|
**类型定义**
|
||||||
```typescript
|
```typescript
|
||||||
export interface ILowCodePluginContext {
|
export interface ILowCodePluginContext {
|
||||||
skeleton: Skeleton; // 参考面板 API
|
skeleton: Skeleton; // 参考面板 API
|
||||||
hotkey: Hotkey; // 参考快捷键 API
|
hotkey: Hotkey; // 参考快捷键 API
|
||||||
logger: Logger; // 参考日志 API
|
setters: Setters; // 参考设置器 API
|
||||||
plugins: ILowCodePluginManager; // 参考插件 API
|
config: EngineConfig; // 参考配置 API
|
||||||
setters: Setters; // 参考设置器 API
|
material: Material; // 参考物料 API
|
||||||
config: EngineConfig; // 参考配置 API
|
event: Event; // 参考事件 API
|
||||||
material: Material; // 参考物料 API
|
project: Project; // 参考模型 API
|
||||||
event: Event; // 参考事件 API
|
common: Common; // 参考模型 API
|
||||||
project: Project; // 参考模型 API
|
logger: Logger; // 参考日志 API
|
||||||
|
plugins: ILowCodePluginManager; // 即本文档描述内容
|
||||||
preference: IPluginPreferenceMananger;
|
preference: IPluginPreferenceMananger;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@ -91,6 +91,7 @@ sidebar_position: 2
|
|||||||
2. 拉 release 分支,此处以 1.0.1 版本做示例
|
2. 拉 release 分支,此处以 1.0.1 版本做示例
|
||||||
```bash
|
```bash
|
||||||
git checkout -b release/1.0.1-beta
|
git checkout -b release/1.0.1-beta
|
||||||
|
git push --set-upstream origin release/1.0.1-beta
|
||||||
```
|
```
|
||||||
3. build
|
3. build
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@ -10,6 +10,7 @@ const jestConfig = {
|
|||||||
// // '^.+\\.(js|jsx)$': 'babel-jest',
|
// // '^.+\\.(js|jsx)$': 'babel-jest',
|
||||||
// },
|
// },
|
||||||
// testMatch: ['**/node-children.test.ts'],
|
// testMatch: ['**/node-children.test.ts'],
|
||||||
|
// testMatch: ['**/plugin-manager.test.ts'],
|
||||||
// testMatch: ['**/history/history.test.ts'],
|
// testMatch: ['**/history/history.test.ts'],
|
||||||
// testMatch: ['**/host-view.test.tsx'],
|
// testMatch: ['**/host-view.test.tsx'],
|
||||||
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
|
// testMatch: ['(/tests?/.*(test))\\.[jt]s$'],
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/* eslint-disable no-multi-assign */
|
/* eslint-disable no-multi-assign */
|
||||||
import { Editor, EngineConfig, engineConfig } from '@alilc/lowcode-editor-core';
|
import { EngineConfig, engineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { Designer, ILowCodePluginManager } from '@alilc/lowcode-designer';
|
import { ILowCodePluginManager } from '@alilc/lowcode-designer';
|
||||||
import { Skeleton as InnerSkeleton } from '@alilc/lowcode-editor-skeleton';
|
|
||||||
import {
|
import {
|
||||||
Hotkey,
|
Hotkey,
|
||||||
Project,
|
Project,
|
||||||
@ -9,9 +8,7 @@ import {
|
|||||||
Setters,
|
Setters,
|
||||||
Material,
|
Material,
|
||||||
Event,
|
Event,
|
||||||
editorSymbol,
|
Common,
|
||||||
designerSymbol,
|
|
||||||
skeletonSymbol,
|
|
||||||
} from '@alilc/lowcode-shell';
|
} from '@alilc/lowcode-shell';
|
||||||
import { getLogger, Logger } from '@alilc/lowcode-utils';
|
import { getLogger, Logger } from '@alilc/lowcode-utils';
|
||||||
import {
|
import {
|
||||||
@ -20,45 +17,40 @@ import {
|
|||||||
ILowCodePluginPreferenceDeclaration,
|
ILowCodePluginPreferenceDeclaration,
|
||||||
PreferenceValueType,
|
PreferenceValueType,
|
||||||
IPluginPreferenceMananger,
|
IPluginPreferenceMananger,
|
||||||
|
ILowCodePluginContextApiAssembler,
|
||||||
|
ILowCodePluginContextPrivate,
|
||||||
} from './plugin-types';
|
} from './plugin-types';
|
||||||
import { isValidPreferenceKey } from './plugin-utils';
|
import { isValidPreferenceKey } from './plugin-utils';
|
||||||
|
|
||||||
export default class PluginContext implements ILowCodePluginContext {
|
|
||||||
private readonly [editorSymbol]: Editor;
|
export default class PluginContext implements ILowCodePluginContext, ILowCodePluginContextPrivate {
|
||||||
private readonly [designerSymbol]: Designer;
|
|
||||||
private readonly [skeletonSymbol]: InnerSkeleton;
|
|
||||||
hotkey: Hotkey;
|
hotkey: Hotkey;
|
||||||
project: Project;
|
project: Project;
|
||||||
skeleton: Skeleton;
|
skeleton: Skeleton;
|
||||||
logger: Logger;
|
|
||||||
setters: Setters;
|
setters: Setters;
|
||||||
material: Material;
|
material: Material;
|
||||||
config: EngineConfig;
|
|
||||||
event: Event;
|
event: Event;
|
||||||
|
config: EngineConfig;
|
||||||
|
common: Common;
|
||||||
|
logger: Logger;
|
||||||
plugins: ILowCodePluginManager;
|
plugins: ILowCodePluginManager;
|
||||||
preference: IPluginPreferenceMananger;
|
preference: IPluginPreferenceMananger;
|
||||||
|
|
||||||
constructor(plugins: ILowCodePluginManager, options: IPluginContextOptions) {
|
constructor(
|
||||||
const editor = this[editorSymbol] = plugins.editor;
|
plugins: ILowCodePluginManager,
|
||||||
const designer = this[designerSymbol] = editor.get('designer')!;
|
options: IPluginContextOptions,
|
||||||
const skeleton = this[skeletonSymbol] = editor.get('skeleton')!;
|
contextApiAssembler: ILowCodePluginContextApiAssembler,
|
||||||
|
) {
|
||||||
const { pluginName = 'anonymous' } = options;
|
|
||||||
const project = designer?.project;
|
|
||||||
this.hotkey = new Hotkey();
|
|
||||||
this.project = new Project(project);
|
|
||||||
this.skeleton = new Skeleton(skeleton);
|
|
||||||
this.setters = new Setters();
|
|
||||||
this.material = new Material(editor);
|
|
||||||
this.config = engineConfig;
|
|
||||||
this.plugins = plugins;
|
this.plugins = plugins;
|
||||||
this.event = new Event(editor, { prefix: 'common' });
|
const { pluginName = 'anonymous' } = options;
|
||||||
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
||||||
|
|
||||||
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
|
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
|
||||||
if (enhancePluginContextHook) {
|
if (enhancePluginContextHook) {
|
||||||
enhancePluginContextHook(this);
|
enhancePluginContextHook(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contextApiAssembler.assembleApis(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
setPreference(
|
setPreference(
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
|
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { getLogger } from '@alilc/lowcode-utils';
|
import { getLogger } from '@alilc/lowcode-utils';
|
||||||
import {
|
import {
|
||||||
ILowCodePlugin,
|
ILowCodePlugin,
|
||||||
@ -12,9 +12,11 @@ import {
|
|||||||
PluginPreference,
|
PluginPreference,
|
||||||
ILowCodePluginPreferenceDeclaration,
|
ILowCodePluginPreferenceDeclaration,
|
||||||
isLowCodeRegisterOptions,
|
isLowCodeRegisterOptions,
|
||||||
|
ILowCodePluginContextApiAssembler,
|
||||||
} from './plugin-types';
|
} from './plugin-types';
|
||||||
import { filterValidOptions } from './plugin-utils';
|
import { filterValidOptions } from './plugin-utils';
|
||||||
import { LowCodePlugin } from './plugin';
|
import { LowCodePlugin } from './plugin';
|
||||||
|
// eslint-disable-next-line import/no-named-as-default
|
||||||
import LowCodePluginContext from './plugin-context';
|
import LowCodePluginContext from './plugin-context';
|
||||||
import { invariant } from '../utils';
|
import { invariant } from '../utils';
|
||||||
import sequencify from './sequencify';
|
import sequencify from './sequencify';
|
||||||
@ -28,14 +30,15 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
|||||||
private pluginsMap: Map<string, ILowCodePlugin> = new Map();
|
private pluginsMap: Map<string, ILowCodePlugin> = new Map();
|
||||||
|
|
||||||
private pluginPreference?: PluginPreference = new Map();
|
private pluginPreference?: PluginPreference = new Map();
|
||||||
private editor: Editor;
|
|
||||||
|
|
||||||
constructor(editor: Editor) {
|
contextApiAssembler: ILowCodePluginContextApiAssembler;
|
||||||
this.editor = editor;
|
|
||||||
|
constructor(contextApiAssembler: ILowCodePluginContextApiAssembler) {
|
||||||
|
this.contextApiAssembler = contextApiAssembler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getLowCodePluginContext(options: IPluginContextOptions) {
|
private _getLowCodePluginContext(options: IPluginContextOptions) {
|
||||||
return new LowCodePluginContext(this, options);
|
return new LowCodePluginContext(this, options, this.contextApiAssembler);
|
||||||
}
|
}
|
||||||
|
|
||||||
isEngineVersionMatched(versionExp: string): boolean {
|
isEngineVersionMatched(versionExp: string): boolean {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { CompositeObject, ComponentAction } from '@alilc/lowcode-types';
|
import { CompositeObject, ComponentAction } from '@alilc/lowcode-types';
|
||||||
import Logger from 'zen-logger';
|
import Logger from 'zen-logger';
|
||||||
import { Hotkey, Skeleton, Project, Event, Material } from '@alilc/lowcode-shell';
|
import { Hotkey, Skeleton, Project, Event, Material, Common } from '@alilc/lowcode-shell';
|
||||||
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { MetadataTransducer } from '@alilc/lowcode-designer';
|
import { MetadataTransducer } from '@alilc/lowcode-designer';
|
||||||
import { Setters } from '../types';
|
import { Setters } from '../types';
|
||||||
@ -96,17 +96,32 @@ export interface IPluginPreferenceMananger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ILowCodePluginContext {
|
export interface ILowCodePluginContext {
|
||||||
skeleton: Skeleton;
|
get skeleton(): Skeleton;
|
||||||
hotkey: Hotkey;
|
get hotkey(): Hotkey;
|
||||||
|
get setters(): Setters;
|
||||||
|
get config(): EngineConfig;
|
||||||
|
get material(): Material;
|
||||||
|
get event(): Event;
|
||||||
|
get project(): Project;
|
||||||
|
get common(): Common;
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
plugins: ILowCodePluginManager;
|
plugins: ILowCodePluginManager;
|
||||||
setters: Setters;
|
|
||||||
config: EngineConfig;
|
|
||||||
material: Material;
|
|
||||||
event: Event;
|
|
||||||
project: Project;
|
|
||||||
preference: IPluginPreferenceMananger;
|
preference: IPluginPreferenceMananger;
|
||||||
}
|
}
|
||||||
|
export interface ILowCodePluginContextPrivate {
|
||||||
|
set hotkey(hotkey: Hotkey);
|
||||||
|
set project(project: Project);
|
||||||
|
set skeleton(skeleton: Skeleton);
|
||||||
|
set setters(setters: Setters);
|
||||||
|
set material(material: Material);
|
||||||
|
set event(event: Event);
|
||||||
|
set config(config: EngineConfig);
|
||||||
|
set common(common: Common);
|
||||||
|
}
|
||||||
|
export interface ILowCodePluginContextApiAssembler {
|
||||||
|
assembleApis: (context: ILowCodePluginContextPrivate) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
interface ILowCodePluginManagerPluginAccessor {
|
interface ILowCodePluginManagerPluginAccessor {
|
||||||
[pluginName: string]: ILowCodePlugin | any;
|
[pluginName: string]: ILowCodePlugin | any;
|
||||||
|
|||||||
@ -1,14 +1,19 @@
|
|||||||
import '../fixtures/window';
|
import '../fixtures/window';
|
||||||
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
|
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
|
||||||
import { LowCodePluginManager } from '../../src/plugin/plugin-manager';
|
import { LowCodePluginManager } from '../../src/plugin/plugin-manager';
|
||||||
import { ILowCodePluginContext, ILowCodePluginManager } from '../../src/plugin/plugin-types';
|
import { ILowCodePluginContext, ILowCodePluginManager, ILowCodePluginContextApiAssembler } from '../../src/plugin/plugin-types';
|
||||||
|
|
||||||
const editor = new Editor();
|
const editor = new Editor();
|
||||||
|
const contextApiAssembler = {
|
||||||
|
assembleApis(){
|
||||||
|
// mock set apis
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
describe('plugin 测试', () => {
|
describe('plugin 测试', () => {
|
||||||
let pluginManager: ILowCodePluginManager;
|
let pluginManager: ILowCodePluginManager;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
pluginManager = new LowCodePluginManager(editor).toProxy();
|
pluginManager = new LowCodePluginManager(contextApiAssembler).toProxy();
|
||||||
});
|
});
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
pluginManager.dispose();
|
pluginManager.dispose();
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable no-param-reassign */
|
||||||
import { createElement } from 'react';
|
import { createElement } from 'react';
|
||||||
import { render, unmountComponentAtNode } from 'react-dom';
|
import { render, unmountComponentAtNode } from 'react-dom';
|
||||||
import { globalContext, Editor, engineConfig, EngineOptions } from '@alilc/lowcode-editor-core';
|
import { globalContext, Editor, engineConfig, EngineOptions } from '@alilc/lowcode-editor-core';
|
||||||
@ -5,6 +6,8 @@ import {
|
|||||||
Designer,
|
Designer,
|
||||||
LowCodePluginManager,
|
LowCodePluginManager,
|
||||||
ILowCodePluginContext,
|
ILowCodePluginContext,
|
||||||
|
ILowCodePluginContextPrivate,
|
||||||
|
ILowCodePluginContextApiAssembler,
|
||||||
PluginPreference,
|
PluginPreference,
|
||||||
} from '@alilc/lowcode-designer';
|
} from '@alilc/lowcode-designer';
|
||||||
import {
|
import {
|
||||||
@ -46,10 +49,6 @@ editor.set('skeleton' as any, innerSkeleton);
|
|||||||
|
|
||||||
const designer = new Designer({ editor });
|
const designer = new Designer({ editor });
|
||||||
editor.set('designer' as any, designer);
|
editor.set('designer' as any, designer);
|
||||||
|
|
||||||
const plugins = new LowCodePluginManager(editor).toProxy();
|
|
||||||
editor.set('plugins' as any, plugins);
|
|
||||||
|
|
||||||
const { project: innerProject } = designer;
|
const { project: innerProject } = designer;
|
||||||
|
|
||||||
const hotkey = new Hotkey();
|
const hotkey = new Hotkey();
|
||||||
@ -62,6 +61,21 @@ const event = new Event(editor, { prefix: 'common' });
|
|||||||
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
||||||
const common = new Common(editor, innerSkeleton);
|
const common = new Common(editor, innerSkeleton);
|
||||||
|
|
||||||
|
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||||
|
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||||
|
context.hotkey = hotkey;
|
||||||
|
context.project = project;
|
||||||
|
context.skeleton = skeleton;
|
||||||
|
context.setters = setters;
|
||||||
|
context.material = material;
|
||||||
|
context.event = event;
|
||||||
|
context.config = config;
|
||||||
|
context.common = common;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const plugins = new LowCodePluginManager(pluginContextApiAssembler).toProxy();
|
||||||
|
editor.set('plugins' as any, plugins);
|
||||||
|
|
||||||
export {
|
export {
|
||||||
skeleton,
|
skeleton,
|
||||||
plugins,
|
plugins,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user