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