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