mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 17:57:13 +00:00
chore: up
This commit is contained in:
parent
344c0113a2
commit
0061b72c3c
@ -1,4 +1,4 @@
|
||||
import { Editor, engineConfig } from '@ali/lowcode-editor-core';
|
||||
import { Editor, EngineConfig, engineConfig } from '@ali/lowcode-editor-core';
|
||||
import { Designer } from '@ali/lowcode-designer';
|
||||
import { Skeleton as InnerSkeleton } from '@ali/lowcode-editor-skeleton';
|
||||
import {
|
||||
@ -7,12 +7,13 @@ import {
|
||||
Skeleton,
|
||||
Setters,
|
||||
Material,
|
||||
Event,
|
||||
editorSymbol,
|
||||
designerSymbol,
|
||||
skeletonSymbol,
|
||||
} from '@ali/lowcode-shell';
|
||||
import { getLogger, Logger } from '../utils/logger';
|
||||
import { ILowCodePluginContext } from './plugin-types';
|
||||
import { getLogger, Logger } from '@ali/lowcode-utils';
|
||||
import { ILowCodePluginContext, PluginContextOptions } from './plugin-types';
|
||||
|
||||
/**
|
||||
* 一些 API 设计约定:
|
||||
@ -29,14 +30,15 @@ export default class PluginContext implements ILowCodePluginContext {
|
||||
public logger: Logger;
|
||||
public setters: Setters;
|
||||
public material: Material;
|
||||
public config: EngineConfig;
|
||||
public event: Event;
|
||||
|
||||
constructor(editor: Editor) {
|
||||
constructor(editor: Editor, options: PluginContextOptions) {
|
||||
this[editorSymbol] = editor;
|
||||
const designer = this[designerSymbol] = editor.get('designer')!;
|
||||
const skeleton = this[skeletonSymbol] = editor.get('skeleton')!;
|
||||
|
||||
// TODO: to be deleted
|
||||
// this.editor = editor;
|
||||
const { pluginName = 'anonymous' } = options;
|
||||
const project = designer.project;
|
||||
this.hotkey = new Hotkey();
|
||||
this.project = new Project(project);
|
||||
@ -44,7 +46,7 @@ export default class PluginContext implements ILowCodePluginContext {
|
||||
this.setters = new Setters();
|
||||
this.material = new Material(editor);
|
||||
this.config = engineConfig;
|
||||
// TODO: pluginName
|
||||
this.logger = getLogger({ level: 'warn', bizName: 'designer:plugin:' });
|
||||
this.event = new Event(editor, { prefix: `plugin:${pluginName}` });
|
||||
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,16 @@
|
||||
import { Editor } from '@ali/lowcode-editor-core';
|
||||
import { ILowCodePlugin, ILowCodePluginConfig, ILowCodePluginManager, ILowCodePluginContext, LowCodeRegisterOptions } from './plugin-types';
|
||||
import { getLogger } from '@ali/lowcode-utils';
|
||||
import {
|
||||
ILowCodePlugin,
|
||||
ILowCodePluginConfig,
|
||||
ILowCodePluginManager,
|
||||
ILowCodePluginContext,
|
||||
LowCodeRegisterOptions,
|
||||
PluginContextOptions,
|
||||
} from './plugin-types';
|
||||
import { LowCodePlugin } from './plugin';
|
||||
import LowCodePluginContext from './plugin-context';
|
||||
import { getLogger, invariant } from '../utils';
|
||||
import { invariant } from '../utils';
|
||||
import sequencify from './sequencify';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'designer:pluginManager' });
|
||||
@ -18,24 +26,22 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
private _getLowCodePluginContext(config: any) {
|
||||
return new LowCodePluginContext(this.editor, config);
|
||||
private _getLowCodePluginContext(options: PluginContextOptions) {
|
||||
return new LowCodePluginContext(this.editor, options);
|
||||
}
|
||||
|
||||
// private getNewContext(config: any) {
|
||||
// return new LowCodePluginContext2(this.editor, config);
|
||||
// }
|
||||
|
||||
async register(
|
||||
pluginConfigCreator: (ctx: ILowCodePluginContext, pluginOptions?: any) => ILowCodePluginConfig,
|
||||
pluginOptions?: any,
|
||||
options?: LowCodeRegisterOptions,
|
||||
): Promise<void> {
|
||||
const ctx = this._getLowCodePluginContext({ name: pluginConfigCreator.pluginName });
|
||||
// ctx.newCtx = this.getNewContext();
|
||||
const ctx = this._getLowCodePluginContext({ pluginName: pluginConfigCreator.pluginName });
|
||||
const config = pluginConfigCreator(ctx, pluginOptions);
|
||||
invariant(config.name, `${config.name} required`, config);
|
||||
// ctx.setLogger(config);
|
||||
invariant(
|
||||
pluginConfigCreator.pluginName || config.name,
|
||||
'pluginConfigCreator.pluginName required',
|
||||
config,
|
||||
);
|
||||
const allowOverride = options?.override === true;
|
||||
if (this.pluginsMap.has(config.name)) {
|
||||
if (!allowOverride) {
|
||||
@ -43,7 +49,12 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
} else {
|
||||
// clear existing plugin
|
||||
const originalPlugin = this.pluginsMap.get(config.name);
|
||||
logger.log('plugin override, originalPlugin with name ', config.name, ' will be destroyed, config:', originalPlugin?.config);
|
||||
logger.log(
|
||||
'plugin override, originalPlugin with name ',
|
||||
config.name,
|
||||
' will be destroyed, config:',
|
||||
originalPlugin?.config,
|
||||
);
|
||||
originalPlugin?.destroy();
|
||||
this.pluginsMap.delete(config.name);
|
||||
}
|
||||
@ -70,7 +81,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
}
|
||||
|
||||
async delete(pluginName: string): Promise<boolean> {
|
||||
const idx = this.plugins.findIndex(plugin => plugin.name === pluginName);
|
||||
const idx = this.plugins.findIndex((plugin) => plugin.name === pluginName);
|
||||
if (idx === -1) return false;
|
||||
const plugin = this.plugins[idx];
|
||||
await plugin.destroy();
|
||||
@ -82,7 +93,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
async init() {
|
||||
const pluginNames: string[] = [];
|
||||
const pluginObj: { [name: string]: ILowCodePlugin } = {};
|
||||
this.plugins.forEach(plugin => {
|
||||
this.plugins.forEach((plugin) => {
|
||||
pluginNames.push(plugin.name);
|
||||
pluginObj[plugin.name] = plugin;
|
||||
});
|
||||
@ -94,7 +105,9 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
try {
|
||||
await this.pluginsMap.get(pluginName)!.init();
|
||||
} catch (e) {
|
||||
logger.error(`Failed to init plugin:${pluginName}, it maybe affect those plugins which depend on this.`);
|
||||
logger.error(
|
||||
`Failed to init plugin:${pluginName}, it maybe affect those plugins which depend on this.`,
|
||||
);
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
MetadataTransducer,
|
||||
Designer,
|
||||
} from '@ali/lowcode-designer';
|
||||
import { Event, Material } from '@ali/lowcode-shell';
|
||||
import { Setters, Utils } from '../types';
|
||||
|
||||
export interface ILowCodePluginConfig {
|
||||
@ -55,7 +56,8 @@ export interface ILowCodePluginContext {
|
||||
setters: Setters;
|
||||
// utils: Utils;
|
||||
engineConfig: EngineConfig;
|
||||
material: any;
|
||||
material: Material;
|
||||
event: Event;
|
||||
}
|
||||
|
||||
interface ILowCodePluginManagerPluginAccessor {
|
||||
@ -83,3 +85,7 @@ export type LowCodeRegisterOptions = {
|
||||
// allow overriding existing plugin with same name when override === true
|
||||
override?: boolean;
|
||||
};
|
||||
|
||||
export type PluginContextOptions = {
|
||||
pluginName: string;
|
||||
};
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
import { CompositeObject } from '@ali/lowcode-types';
|
||||
import { getLogger, Logger } from '@ali/lowcode-utils';
|
||||
import {
|
||||
ILowCodePlugin,
|
||||
ILowCodePluginConfig,
|
||||
ILowCodePluginManager,
|
||||
} from './plugin-types';
|
||||
import { CompositeObject } from '@ali/lowcode-types';
|
||||
import { EventEmitter } from 'events';
|
||||
import { getLogger, Logger, invariant } from '../utils';
|
||||
import { invariant } from '../utils';
|
||||
|
||||
export class LowCodePlugin implements ILowCodePlugin {
|
||||
config: ILowCodePluginConfig;
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
export * from './invariant';
|
||||
export * from './slot';
|
||||
export * from './tree';
|
||||
export * from './logger';
|
||||
|
||||
@ -1,3 +1,34 @@
|
||||
export default class Event {
|
||||
import { Editor as InnerEditor } from '@ali/lowcode-editor-core';
|
||||
import { getLogger } from '@ali/lowcode-utils';
|
||||
import { editorSymbol } from './symbols';
|
||||
|
||||
}
|
||||
const logger = getLogger({ level: 'warn', bizName: 'shell:event:' });
|
||||
|
||||
type EventOptions = {
|
||||
prefix: string;
|
||||
};
|
||||
|
||||
export default class Event {
|
||||
private readonly [editorSymbol]: InnerEditor;
|
||||
private readonly options: EventOptions;
|
||||
|
||||
constructor(editor: InnerEditor, options: EventOptions) {
|
||||
this[editorSymbol] = editor;
|
||||
this.options = options;
|
||||
if (!this.options.prefix) {
|
||||
logger.warn('prefix is required while initializing Event');
|
||||
}
|
||||
}
|
||||
|
||||
on(event: string, listener: (...args: unknown[]) => void) {
|
||||
this[editorSymbol].on(event, listener);
|
||||
}
|
||||
|
||||
emit(event: string, ...args: unknown[]) {
|
||||
if (!this.options.prefix) {
|
||||
logger.warn('Event#emit has been forbidden while prefix is not specified');
|
||||
return;
|
||||
}
|
||||
this[editorSymbol].emit(`${this.options.prefix}:${event}`, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Prop as InnerProp } from '@ali/lowcode-designer';
|
||||
import { CompositeValue } from '@ali/lowcode-types';
|
||||
import { CompositeValue, TransformStage } from '@ali/lowcode-types';
|
||||
import { propSymbol } from './symbols';
|
||||
import Node from './node';
|
||||
|
||||
@ -27,5 +27,7 @@ export default class Prop {
|
||||
return this[propSymbol].getValue();
|
||||
}
|
||||
|
||||
exportSchema() {}
|
||||
exportSchema(stage: TransformStage) {
|
||||
return this[propSymbol].export(stage);
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,8 @@
|
||||
"@ali/lowcode-types": "1.0.74",
|
||||
"@alifd/next": "^1.19.16",
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^16"
|
||||
"react": "^16",
|
||||
"zen-logger": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@alib/build-scripts": "^0.1.18",
|
||||
|
||||
@ -24,4 +24,5 @@ export * from './misc';
|
||||
export * from './schema';
|
||||
export * from './node-helper';
|
||||
export * from './clone-enumerable-property';
|
||||
export * from './logger';
|
||||
export * as css from './css-helper';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user