mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 09:47:20 +00:00
feat: add types for shell/plugins and logger
This commit is contained in:
parent
5e96db046e
commit
bddaa537e1
@ -30,7 +30,8 @@ material.setAssets(assets);
|
||||
|
||||
通过物料中心接口动态引入资产包
|
||||
```typescript
|
||||
import { ILowCodePluginContext, material, plugins } from '@alilc/lowcode-engine'
|
||||
import { material, plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
// 动态加载 assets
|
||||
plugins.register((ctx: ILowCodePluginContext) => {
|
||||
|
||||
@ -26,6 +26,7 @@ pluginConfigCreator 是一个 ILowCodePluginConfig 生成函数,ILowCodePlugin
|
||||
#### 简单示例
|
||||
```typescript
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const builtinPluginRegistry = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
@ -58,6 +59,7 @@ await plugins.register(builtinPluginRegistry);
|
||||
#### 使用 exports 示例
|
||||
```typescript
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const pluginA = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
@ -89,6 +91,7 @@ await plugins.register(pluginB);
|
||||
#### 设置兼容引擎版本示例
|
||||
```typescript
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const builtinPluginRegistry = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
@ -108,6 +111,7 @@ await plugins.register(builtinPluginRegistry);
|
||||
#### 设置插件参数版本示例
|
||||
```typescript
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const builtinPluginRegistry = (ctx: ILowCodePluginContext, options: any) => {
|
||||
return {
|
||||
@ -223,16 +227,16 @@ plugins.delete('builtinPluginRegistry');
|
||||
**类型定义**
|
||||
```typescript
|
||||
export interface ILowCodePluginContext {
|
||||
skeleton: Skeleton; // 参考面板 API
|
||||
hotkey: Hotkey; // 参考快捷键 API
|
||||
setters: Setters; // 参考设置器 API
|
||||
config: EngineConfig; // 参考配置 API
|
||||
material: Material; // 参考物料 API
|
||||
event: Event; // 参考事件 API
|
||||
project: Project; // 参考模型 API
|
||||
common: Common; // 参考模型 API
|
||||
logger: Logger; // 参考日志 API
|
||||
plugins: ILowCodePluginManager; // 即本文档描述内容
|
||||
get skeleton(): IPublicApiSkeleton;
|
||||
get hotkey(): IPublicApiHotkey;
|
||||
get setters(): IPublicApiSetters;
|
||||
get config(): IEngineConfig;
|
||||
get material(): IPublicApiMaterial;
|
||||
get event(): IPublicApiEvent;
|
||||
get project(): IPublicApiProject;
|
||||
get common(): IPublicApiCommon;
|
||||
logger: IPublicApiLogger;
|
||||
plugins: IPublicApiPlugins;
|
||||
preference: IPluginPreferenceMananger;
|
||||
}
|
||||
```
|
||||
|
||||
@ -79,8 +79,8 @@ addPropsTransducer(transducer: PropsTransducer, stage: TransformStage)
|
||||
|
||||
**示例 1:在保存的时候删除每一个组件的 props.hidden**
|
||||
```typescript
|
||||
import { ILowCodePluginContext, project } from '@alilc/lowcode-engine';
|
||||
import { CompositeObject, TransformStage } from '@alilc/lowcode-types';
|
||||
import { project } from '@alilc/lowcode-engine';
|
||||
import { CompositeObject, TransformStage, ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
export const deleteHiddenTransducer = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
|
||||
@ -38,6 +38,7 @@ function registerSetter(
|
||||
```typescript
|
||||
import { setters, skeleton } from '@alilc/lowcode-engine';
|
||||
import { setterMap, pluginMap } from '@alilc/lowcode-engine-ext';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const setterRegistry = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
@ -209,6 +210,7 @@ function registerSetter(
|
||||
```typescript
|
||||
import { setters, skeleton } from '@alilc/lowcode-engine';
|
||||
import { setterMap, pluginMap } from '@alilc/lowcode-engine-ext';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const setterRegistry = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
|
||||
@ -130,6 +130,7 @@ npm publish
|
||||
2. 在引擎初始化侧引入插件
|
||||
```typescript
|
||||
import Inject, { injectAssets } from '@alilc/lowcode-plugin-inject';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
export default async () => {
|
||||
// 注意 Inject 插件必须在其他插件前注册,且所有插件的注册必须 await
|
||||
|
||||
@ -270,7 +270,8 @@ npm publish
|
||||
|
||||
### 在项目中引入资产包
|
||||
```typescript
|
||||
import { ILowCodePluginContext, material, plugins } from '@alilc/lowcode-engine';
|
||||
import { material, plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
// 动态加载 assets
|
||||
plugins.register((ctx: ILowCodePluginContext) => {
|
||||
|
||||
@ -10,6 +10,7 @@ sidebar_position: 6
|
||||
|
||||
```typescript
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
import { Icon, Message } from '@alifd/next';
|
||||
|
||||
const addHelloAction = (ctx: ILowCodePluginContext) => {
|
||||
@ -46,6 +47,7 @@ await plugins.register(addHelloAction);
|
||||
|
||||
```typescript
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const removeCopyAction = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
|
||||
@ -17,7 +17,8 @@ sidebar_position: 5
|
||||
## 注册插件 API
|
||||
|
||||
```typescript
|
||||
import { plugins, ILowCodePluginContext } from '@alilc/lowcode-engine';
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const pluginA = (ctx: ILowCodePluginContext, options: any) => {
|
||||
return {
|
||||
|
||||
@ -34,7 +34,8 @@ material.setAssets(assets);
|
||||
|
||||
也可以通过异步加载物料中心上的物料。
|
||||
```typescript
|
||||
import { ILowCodePluginContext, material, plugins } from '@alilc/lowcode-engine';
|
||||
import { material, plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
// 动态加载 assets
|
||||
plugins.register((ctx: ILowCodePluginContext) => {
|
||||
@ -57,7 +58,8 @@ plugins.register((ctx: ILowCodePluginContext) => {
|
||||
### 配置插件
|
||||
可以通过 npm 包的方式引入社区插件,配置如下所示:
|
||||
```typescript
|
||||
import { ILowCodePluginContext, plugins } from '@alilc/lowcode-engine';
|
||||
import { plugins } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
import PluginIssueTracker from '@alilc/lowcode-plugin-issue-tracker';
|
||||
|
||||
// 注册一个提 issue 组件到您的编辑器中,方位默认在左栏下侧
|
||||
|
||||
@ -125,7 +125,7 @@ Demo 根据**不同的设计器所需要的物料不同**,分为了下面的 8
|
||||
可以在 demo/sample-plugins 直接新增插件,这里我新增的插件目录是 plugin-demo。并且新增了 index.tsx 文件,将下面的代码粘贴到 index.tsx 中。
|
||||
```javascript
|
||||
import * as React from 'react';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-engine';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
const LowcodePluginPluginDemo = (ctx: ILowCodePluginContext) => {
|
||||
return {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
/* eslint-disable no-multi-assign */
|
||||
import { EngineConfig, engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { ILowCodePluginManager } from '@alilc/lowcode-designer';
|
||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
IPublicApiHotkey,
|
||||
IPublicApiProject,
|
||||
@ -9,14 +8,16 @@ import {
|
||||
IPublicApiMaterial,
|
||||
IPublicApiEvent,
|
||||
IPublicApiCommon,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { getLogger, Logger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
ILowCodePluginContext,
|
||||
IPluginPreferenceMananger,
|
||||
PreferenceValueType,
|
||||
IEngineConfig,
|
||||
IPublicApiLogger,
|
||||
IPublicApiPlugins,
|
||||
} from '@alilc/lowcode-types';
|
||||
import {
|
||||
IPluginContextOptions,
|
||||
ILowCodePluginPreferenceDeclaration,
|
||||
PreferenceValueType,
|
||||
IPluginPreferenceMananger,
|
||||
ILowCodePluginContextApiAssembler,
|
||||
ILowCodePluginContextPrivate,
|
||||
} from './plugin-types';
|
||||
@ -30,20 +31,18 @@ export default class PluginContext implements ILowCodePluginContext, ILowCodePlu
|
||||
setters: IPublicApiSetters;
|
||||
material: IPublicApiMaterial;
|
||||
event: IPublicApiEvent;
|
||||
config: EngineConfig;
|
||||
config: IEngineConfig;
|
||||
common: IPublicApiCommon;
|
||||
logger: Logger;
|
||||
plugins: ILowCodePluginManager;
|
||||
logger: IPublicApiLogger;
|
||||
plugins: IPublicApiPlugins;
|
||||
preference: IPluginPreferenceMananger;
|
||||
|
||||
constructor(
|
||||
plugins: ILowCodePluginManager,
|
||||
options: IPluginContextOptions,
|
||||
contextApiAssembler: ILowCodePluginContextApiAssembler,
|
||||
) {
|
||||
contextApiAssembler.assembleApis(this);
|
||||
const { pluginName = 'anonymous' } = options;
|
||||
this.logger = getLogger({ level: 'warn', bizName: `designer:plugin:${pluginName}` });
|
||||
contextApiAssembler.assembleApis(this, pluginName);
|
||||
|
||||
const enhancePluginContextHook = engineConfig.get('enhancePluginContextHook');
|
||||
if (enhancePluginContextHook) {
|
||||
|
||||
@ -2,12 +2,8 @@ import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
ILowCodePlugin,
|
||||
ILowCodePluginConfig,
|
||||
ILowCodePluginManager,
|
||||
ILowCodePluginContext,
|
||||
ILowCodeRegisterOptions,
|
||||
IPluginContextOptions,
|
||||
PreferenceValueType,
|
||||
ILowCodePluginConfigMeta,
|
||||
PluginPreference,
|
||||
ILowCodePluginPreferenceDeclaration,
|
||||
@ -21,6 +17,12 @@ import LowCodePluginContext from './plugin-context';
|
||||
import { invariant } from '../utils';
|
||||
import sequencify from './sequencify';
|
||||
import semverSatisfies from 'semver/functions/satisfies';
|
||||
import {
|
||||
ILowCodePluginContext,
|
||||
ILowCodePluginConfig,
|
||||
ILowCodeRegisterOptions,
|
||||
PreferenceValueType,
|
||||
} from '@alilc/lowcode-types';
|
||||
|
||||
const logger = getLogger({ level: 'warn', bizName: 'designer:pluginManager' });
|
||||
|
||||
@ -38,7 +40,7 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
}
|
||||
|
||||
_getLowCodePluginContext = (options: IPluginContextOptions) => {
|
||||
return new LowCodePluginContext(this, options, this.contextApiAssembler);
|
||||
return new LowCodePluginContext(options, this.contextApiAssembler);
|
||||
};
|
||||
|
||||
isEngineVersionMatched(versionExp: string): boolean {
|
||||
@ -105,7 +107,8 @@ export class LowCodePluginManager implements ILowCodePluginManager {
|
||||
}
|
||||
|
||||
const plugin = new LowCodePlugin(pluginName, this, config, meta);
|
||||
// support initialization of those plugins which registered after normal initialization by plugin-manager
|
||||
// support initialization of those plugins which registered
|
||||
// after normal initialization by plugin-manager
|
||||
if (registerOptions?.autoInit) {
|
||||
// debugger
|
||||
await plugin.init();
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import Logger from 'zen-logger';
|
||||
import {
|
||||
IPublicApiHotkey,
|
||||
IPublicApiProject,
|
||||
@ -11,11 +10,13 @@ import {
|
||||
ComponentAction,
|
||||
MetadataTransducer,
|
||||
IPublicApiPlugins,
|
||||
ILowCodePluginContext,
|
||||
ILowCodePluginConfig,
|
||||
IPublicApiLogger,
|
||||
ILowCodeRegisterOptions,
|
||||
PreferenceValueType,
|
||||
IEngineConfig,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { EngineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { Setters } from '../types';
|
||||
|
||||
export type PreferenceValueType = string | number | boolean;
|
||||
|
||||
export interface ILowCodePluginPreferenceDeclarationProperty {
|
||||
// shape like 'name' or 'group.name' or 'group.subGroup.name'
|
||||
@ -52,12 +53,6 @@ export interface ILowCodePluginPreferenceDeclaration {
|
||||
|
||||
export type PluginPreference = Map<string, Record<string, PreferenceValueType>>;
|
||||
|
||||
export interface ILowCodePluginConfig {
|
||||
dep?: string | string[];
|
||||
init?(): void;
|
||||
destroy?(): void;
|
||||
exports?(): any;
|
||||
}
|
||||
|
||||
export interface ILowCodePluginConfigMetaEngineConfig {
|
||||
lowcodeEngine?: string;
|
||||
@ -74,7 +69,7 @@ export interface ILowCodePluginCore {
|
||||
dep: string[];
|
||||
disabled: boolean;
|
||||
config: ILowCodePluginConfig;
|
||||
logger: Logger;
|
||||
logger: IPublicApiLogger;
|
||||
on(event: string | symbol, listener: (...args: any[]) => void): any;
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
removeAllListeners(event?: string | symbol): this;
|
||||
@ -97,43 +92,22 @@ export interface IDesignerCabin {
|
||||
removeBuiltinComponentAction: (actionName: string) => void;
|
||||
}
|
||||
|
||||
export interface IPluginPreferenceMananger {
|
||||
// eslint-disable-next-line max-len
|
||||
getPreferenceValue: (
|
||||
key: string,
|
||||
defaultValue?: PreferenceValueType,
|
||||
) => PreferenceValueType | undefined;
|
||||
}
|
||||
|
||||
export interface ILowCodePluginContext {
|
||||
get skeleton(): IPublicApiSkeleton;
|
||||
get hotkey(): IPublicApiHotkey;
|
||||
get setters(): IPublicApiSetters;
|
||||
get config(): EngineConfig;
|
||||
get material(): IPublicApiMaterial;
|
||||
get event(): IPublicApiEvent;
|
||||
get project(): IPublicApiProject;
|
||||
get common(): IPublicApiCommon;
|
||||
logger: Logger;
|
||||
plugins: ILowCodePluginManager;
|
||||
preference: IPluginPreferenceMananger;
|
||||
}
|
||||
export interface ILowCodePluginContextPrivate {
|
||||
set hotkey(hotkey: IPublicApiHotkey);
|
||||
set project(project: IPublicApiProject);
|
||||
set skeleton(skeleton: IPublicApiSkeleton);
|
||||
set setters(setters: Setters);
|
||||
set setters(setters: IPublicApiSetters);
|
||||
set material(material: IPublicApiMaterial);
|
||||
set event(event: IPublicApiEvent);
|
||||
set config(config: EngineConfig);
|
||||
set config(config: IEngineConfig);
|
||||
set common(common: IPublicApiCommon);
|
||||
set plugins(plugins: IPublicApiPlugins);
|
||||
set logger(plugins: IPublicApiLogger);
|
||||
}
|
||||
export interface ILowCodePluginContextApiAssembler {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate) => void;
|
||||
assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string) => void;
|
||||
}
|
||||
|
||||
|
||||
interface ILowCodePluginManagerPluginAccessor {
|
||||
[pluginName: string]: ILowCodePlugin | any;
|
||||
}
|
||||
@ -159,15 +133,6 @@ export function isLowCodeRegisterOptions(opts: any): opts is ILowCodeRegisterOpt
|
||||
return opts && ('autoInit' in opts || 'override' in opts);
|
||||
}
|
||||
|
||||
export interface ILowCodeRegisterOptions {
|
||||
/** Will enable plugin registered with auto-initialization immediately
|
||||
* other than plugin-manager init all plugins at certain time.
|
||||
* It is helpful when plugin register is later than plugin-manager initialization. */
|
||||
autoInit?: boolean;
|
||||
/** allow overriding existing plugin with same name when override === true */
|
||||
override?: boolean;
|
||||
}
|
||||
|
||||
export interface IPluginContextOptions {
|
||||
pluginName: string;
|
||||
}
|
||||
@ -180,14 +145,4 @@ export interface IPluginMetaDefinition {
|
||||
/** e.g. '^1.0.0' */
|
||||
lowcodeEngine?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface IPluginConfigCreatorFn<T extends Record<string, any> = Record<string, any>> {
|
||||
(ctx: ILowCodePluginContext, pluginOptions?: T): ILowCodePluginConfig;
|
||||
}
|
||||
|
||||
export type IPluginConfigCreator<T extends Record<string, any> = Record<string, any>> =
|
||||
IPluginConfigCreatorFn<T> & {
|
||||
pluginName: string;
|
||||
meta?: IPluginMetaDefinition;
|
||||
};
|
||||
}
|
||||
@ -1,10 +1,12 @@
|
||||
import { getLogger, Logger } from '@alilc/lowcode-utils';
|
||||
import {
|
||||
ILowCodePlugin,
|
||||
ILowCodePluginConfig,
|
||||
ILowCodePluginManager,
|
||||
ILowCodePluginConfigMeta,
|
||||
} from './plugin-types';
|
||||
import {
|
||||
ILowCodePluginConfig,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { EventEmitter } from 'events';
|
||||
import { invariant } from '../utils';
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import '../fixtures/window';
|
||||
import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { LowCodePluginManager } from '../../src/plugin/plugin-manager';
|
||||
import { ILowCodePluginContext, ILowCodePluginManager, ILowCodePluginContextApiAssembler } from '../../src/plugin/plugin-types';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
import { ILowCodePluginManager } from '../../src/plugin/plugin-types';
|
||||
|
||||
const editor = new Editor();
|
||||
const contextApiAssembler = {
|
||||
|
||||
@ -8,8 +8,10 @@ import {
|
||||
Setters as InnerSetters,
|
||||
Hotkey as InnerHotkey,
|
||||
} from '@alilc/lowcode-editor-core';
|
||||
import { EngineOptions,
|
||||
import {
|
||||
EngineOptions,
|
||||
IPublicModelDocumentModel,
|
||||
ILowCodePluginContext,
|
||||
} from '@alilc/lowcode-types';
|
||||
import {
|
||||
Designer,
|
||||
@ -35,10 +37,10 @@ import {
|
||||
Material,
|
||||
Event,
|
||||
Plugins,
|
||||
DocumentModel,
|
||||
Common,
|
||||
Logger,
|
||||
} from '@alilc/lowcode-shell';
|
||||
import { getLogger, isPlainObject } from '@alilc/lowcode-utils';
|
||||
import { isPlainObject } from '@alilc/lowcode-utils';
|
||||
import './modules/live-editing';
|
||||
import classes from './modules/classes';
|
||||
import symbols from './modules/symbols';
|
||||
@ -81,12 +83,12 @@ editor.set('material', material);
|
||||
editor.set('innerHotkey', innerHotkey);
|
||||
const config = engineConfig;
|
||||
const event = new Event(editor, { prefix: 'common' });
|
||||
const logger = getLogger({ level: 'warn', bizName: 'common' });
|
||||
const logger = new Logger({ level: 'warn', bizName: 'common' });
|
||||
const common = new Common(editor, innerSkeleton);
|
||||
let plugins: Plugins;
|
||||
|
||||
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string) => {
|
||||
context.hotkey = hotkey;
|
||||
context.project = project;
|
||||
context.skeleton = skeleton;
|
||||
@ -96,6 +98,7 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||
context.config = config;
|
||||
context.common = common;
|
||||
context.plugins = plugins;
|
||||
context.logger = new Logger({ level: 'warn', bizName: `plugin:${pluginName}` });
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -6,8 +6,10 @@ import {
|
||||
insertChildren,
|
||||
TransformStage,
|
||||
clipboard,
|
||||
ILowCodePluginContext,
|
||||
} from '@alilc/lowcode-designer';
|
||||
import {
|
||||
ILowCodePluginContext,
|
||||
} from '@alilc/lowcode-types';
|
||||
|
||||
export function isInLiveEditing() {
|
||||
const workSpace = globalContext.get('workSpace');
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-designer';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
export const componentMetaParser = (designer: any) => {
|
||||
const fun = (ctx: ILowCodePluginContext) => {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-designer';
|
||||
import { engineConfig } from '@alilc/lowcode-editor-core';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
import { SettingsPrimaryPane } from '@alilc/lowcode-editor-skeleton';
|
||||
import DesignerPlugin from '@alilc/lowcode-plugin-designer';
|
||||
import Outline, { getTreeMaster, OutlineBackupPane } from '@alilc/lowcode-plugin-outline-pane';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-designer';
|
||||
import { ILowCodePluginContext } from '@alilc/lowcode-types';
|
||||
|
||||
// 注册默认的 setters
|
||||
export const setterRegistry = (ctx: ILowCodePluginContext) => {
|
||||
|
||||
@ -9,8 +9,5 @@ export type EditingTarget = designerCabin.EditingTarget;
|
||||
export type SaveHandler = designerCabin.SaveHandler;
|
||||
export type ComponentMeta = designerCabin.ComponentMeta;
|
||||
export type SettingField = designerCabin.SettingField;
|
||||
export type ILowCodePluginConfig = designerCabin.ILowCodePluginConfig;
|
||||
export type ILowCodePluginManager = designerCabin.ILowCodePluginManager;
|
||||
export type ILowCodePluginContext = designerCabin.ILowCodePluginContext;
|
||||
export type IPluginConfigCreator = designerCabin.IPluginConfigCreator;
|
||||
export type PluginPreference = designerCabin.PluginPreference;
|
||||
@ -16,6 +16,7 @@ import SettingPropEntry from './setting-prop-entry';
|
||||
import SettingTopEntry from './setting-top-entry';
|
||||
import Common from './common';
|
||||
import Plugins from './plugins';
|
||||
import Logger from './logger';
|
||||
|
||||
export * from './symbols';
|
||||
|
||||
@ -46,4 +47,5 @@ export {
|
||||
Common,
|
||||
getEvent,
|
||||
Plugins,
|
||||
Logger,
|
||||
};
|
||||
41
packages/shell/src/logger.ts
Normal file
41
packages/shell/src/logger.ts
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { IPublicApiLogger, ILoggerOptions } from '@alilc/lowcode-types';
|
||||
|
||||
const innerLoggerSymbol = Symbol('logger');
|
||||
|
||||
export default class Logger implements IPublicApiLogger {
|
||||
private readonly [innerLoggerSymbol]: any;
|
||||
|
||||
constructor(options: ILoggerOptions) {
|
||||
this[innerLoggerSymbol] = getLogger(options as any);
|
||||
}
|
||||
|
||||
/**
|
||||
* debug info
|
||||
*/
|
||||
debug(...args: any | any[]): void {
|
||||
this[innerLoggerSymbol].debug(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* normal info output
|
||||
*/
|
||||
info(...args: any | any[]): void {
|
||||
this[innerLoggerSymbol].info(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* warning info output
|
||||
*/
|
||||
warn(...args: any | any[]): void {
|
||||
this[innerLoggerSymbol].warn(...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* error info output
|
||||
*/
|
||||
error(...args: any | any[]): void {
|
||||
this[innerLoggerSymbol].error(...args);
|
||||
}
|
||||
}
|
||||
@ -4,6 +4,10 @@ import {
|
||||
import { globalContext } from '@alilc/lowcode-editor-core';
|
||||
import {
|
||||
IPublicApiPlugins,
|
||||
ILowCodePluginContext,
|
||||
ILowCodePluginConfig,
|
||||
ILowCodeRegisterOptions,
|
||||
PreferenceValueType,
|
||||
} from '@alilc/lowcode-types';
|
||||
import { pluginsSymbol } from './symbols';
|
||||
|
||||
@ -27,9 +31,9 @@ export default class Plugins implements IPublicApiPlugins {
|
||||
}
|
||||
|
||||
async register(
|
||||
pluginConfigCreator: (ctx: any, options: any) => any,
|
||||
pluginConfigCreator: (ctx: ILowCodePluginContext, options: any) => ILowCodePluginConfig,
|
||||
options?: any,
|
||||
registerOptions?: any,
|
||||
registerOptions?: ILowCodeRegisterOptions,
|
||||
): Promise<void> {
|
||||
await this[pluginsSymbol].register(pluginConfigCreator, options, registerOptions);
|
||||
}
|
||||
@ -38,8 +42,8 @@ export default class Plugins implements IPublicApiPlugins {
|
||||
await this[pluginsSymbol].init(registerOptions);
|
||||
}
|
||||
|
||||
async getPluginPreference(pluginName: string) {
|
||||
await this[pluginsSymbol].getPluginPreference(pluginName);
|
||||
getPluginPreference(pluginName: string): Record<string, PreferenceValueType> | null | undefined {
|
||||
return this[pluginsSymbol].getPluginPreference(pluginName);
|
||||
}
|
||||
|
||||
toProxy() {
|
||||
|
||||
@ -7,3 +7,4 @@ export * from './setters';
|
||||
export * from './simulator-host';
|
||||
export * from './skeleton';
|
||||
export * from './plugins';
|
||||
export * from './logger';
|
||||
|
||||
28
packages/types/src/shell/api/logger.ts
Normal file
28
packages/types/src/shell/api/logger.ts
Normal file
@ -0,0 +1,28 @@
|
||||
export type LoggerLevel = 'debug' | 'log' | 'info' | 'warn' | 'error';
|
||||
export interface ILoggerOptions {
|
||||
level?: LoggerLevel;
|
||||
bizName?: string;
|
||||
}
|
||||
|
||||
export interface IPublicApiLogger {
|
||||
|
||||
/**
|
||||
* debug info
|
||||
*/
|
||||
debug(...args: any | any[]): void;
|
||||
|
||||
/**
|
||||
* normal info output
|
||||
*/
|
||||
info(...args: any | any[]): void;
|
||||
|
||||
/**
|
||||
* warning info output
|
||||
*/
|
||||
warn(...args: any | any[]): void;
|
||||
|
||||
/**
|
||||
* error info output
|
||||
*/
|
||||
error(...args: any | any[]): void;
|
||||
}
|
||||
@ -1,7 +1,61 @@
|
||||
import {
|
||||
IPublicApiSkeleton,
|
||||
IPublicApiHotkey,
|
||||
IPublicApiSetters,
|
||||
IPublicApiMaterial,
|
||||
IPublicApiEvent,
|
||||
IPublicApiProject,
|
||||
IPublicApiCommon,
|
||||
IPublicApiLogger,
|
||||
} from './';
|
||||
|
||||
import { IEngineConfig } from '../../engine-config';
|
||||
|
||||
export type PreferenceValueType = string | number | boolean;
|
||||
|
||||
export interface IPluginPreferenceMananger {
|
||||
// eslint-disable-next-line max-len
|
||||
getPreferenceValue: (
|
||||
key: string,
|
||||
defaultValue?: PreferenceValueType,
|
||||
) => PreferenceValueType | undefined;
|
||||
}
|
||||
|
||||
export interface ILowCodePluginContext {
|
||||
get skeleton(): IPublicApiSkeleton;
|
||||
get hotkey(): IPublicApiHotkey;
|
||||
get setters(): IPublicApiSetters;
|
||||
get config(): IEngineConfig;
|
||||
get material(): IPublicApiMaterial;
|
||||
get event(): IPublicApiEvent;
|
||||
get project(): IPublicApiProject;
|
||||
get common(): IPublicApiCommon;
|
||||
get plugins(): IPublicApiPlugins;
|
||||
get logger(): IPublicApiLogger;
|
||||
preference: IPluginPreferenceMananger;
|
||||
}
|
||||
|
||||
export interface ILowCodePluginConfig {
|
||||
init?(): void;
|
||||
destroy?(): void;
|
||||
exports?(): any;
|
||||
}
|
||||
|
||||
export interface ILowCodeRegisterOptions {
|
||||
/** Will enable plugin registered with auto-initialization immediately
|
||||
* other than plugin-manager init all plugins at certain time.
|
||||
* It is helpful when plugin register is later than plugin-manager initialization. */
|
||||
autoInit?: boolean;
|
||||
/** allow overriding existing plugin with same name when override === true */
|
||||
override?: boolean;
|
||||
}
|
||||
|
||||
export interface IPublicApiPlugins {
|
||||
register(
|
||||
pluginConfigCreator: (ctx: any, options: any) => any,
|
||||
pluginConfigCreator: (ctx: ILowCodePluginContext, options: any) => ILowCodePluginConfig,
|
||||
options?: any,
|
||||
registerOptions?: any,
|
||||
registerOptions?: ILowCodeRegisterOptions,
|
||||
): Promise<void>;
|
||||
|
||||
getPluginPreference(pluginName: string): Record<string, PreferenceValueType> | null | undefined ;
|
||||
}
|
||||
@ -23,6 +23,7 @@ import {
|
||||
Material,
|
||||
Event,
|
||||
Common,
|
||||
Logger,
|
||||
} from '@alilc/lowcode-shell';
|
||||
import { getLogger } from '@alilc/lowcode-utils';
|
||||
import { setterRegistry } from 'engine/src/inner-plugins/setter-registry';
|
||||
@ -98,7 +99,7 @@ export class BasicContext {
|
||||
let plugins: any;
|
||||
|
||||
const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate) => {
|
||||
assembleApis: (context: ILowCodePluginContextPrivate, pluginName: string) => {
|
||||
context.hotkey = hotkey;
|
||||
context.project = project;
|
||||
context.skeleton = skeleton;
|
||||
@ -108,6 +109,7 @@ export class BasicContext {
|
||||
context.config = config;
|
||||
context.common = common;
|
||||
context.plugins = plugins;
|
||||
context.logger = new Logger({ level: 'warn', bizName: `plugin:${pluginName}` });
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user