refactor(types): rename EngineOptions, and adjust related docs

This commit is contained in:
JackLian 2023-01-04 14:16:02 +08:00 committed by 刘菊萍(絮黎)
parent 622b3fd958
commit 4ef61183ef
7 changed files with 56 additions and 22 deletions

View File

@ -14,13 +14,13 @@ sidebar_position: 10
**方法定义**
```typescript
function init(container?: Element, options?: EngineOptions): void
function init(container?: Element, options?: IPublicTypeEngineOptions): void
```
**初始化引擎的参数**
```typescript
interface EngineOptions {
interface IPublicTypeEngineOptions {
/**
* 指定初始化的 device
*/
@ -107,7 +107,7 @@ interface EngineOptions {
[key: string]: any;
}
```
> 源码详见 [EngineOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/engine-config.ts)
> 源码详见 [IPublicTypeEngineOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/engine-options.ts)
## 使用示例

View File

@ -1,7 +1,7 @@
import { get as lodashGet } from 'lodash';
import { isPlainObject } from '@alilc/lowcode-utils';
import {
EngineOptions,
IPublicTypeEngineOptions,
IPublicModelEngineConfig,
IPublicModelPreference,
} from '@alilc/lowcode-types';
@ -150,7 +150,7 @@ const VALID_ENGINE_OPTIONS = {
};
const getStrictModeValue = (engineOptions: EngineOptions, defaultValue: boolean): boolean => {
const getStrictModeValue = (engineOptions: IPublicTypeEngineOptions, defaultValue: boolean): boolean => {
if (!engineOptions || !isPlainObject(engineOptions)) {
return defaultValue;
}
@ -165,10 +165,9 @@ export interface IEngineConfigPrivate {
/**
* if engineOptions.strictPluginMode === true, only accept propertied predefined in EngineOptions.
*
* @param {EngineOptions} engineOptions
* @memberof EngineConfig
* @param {IPublicTypeEngineOptions} engineOptions
*/
setEngineOptions(engineOptions: EngineOptions): void;
setEngineOptions(engineOptions: IPublicTypeEngineOptions): void;
notifyGot(key: string): void;
@ -203,7 +202,6 @@ export class EngineConfig implements IPublicModelEngineConfig, IEngineConfigPriv
/**
* 判断指定 key 是否有值
* @param key
* @returns
*/
has(key: string): boolean {
return this.config[key] !== undefined;
@ -213,7 +211,6 @@ export class EngineConfig implements IPublicModelEngineConfig, IEngineConfigPriv
* 获取指定 key 的值
* @param key
* @param defaultValue
* @returns
*/
get(key: string, defaultValue?: any): any {
return lodashGet(this.config, key, defaultValue);
@ -244,10 +241,9 @@ export class EngineConfig implements IPublicModelEngineConfig, IEngineConfigPriv
/**
* if engineOptions.strictPluginMode === true, only accept propertied predefined in EngineOptions.
*
* @param {EngineOptions} engineOptions
* @memberof EngineConfig
* @param {IPublicTypeEngineOptions} engineOptions
*/
setEngineOptions(engineOptions: EngineOptions) {
setEngineOptions(engineOptions: IPublicTypeEngineOptions) {
if (!engineOptions || !isPlainObject(engineOptions)) {
return;
}

View File

@ -11,7 +11,7 @@ import {
Hotkey as InnerHotkey,
} from '@alilc/lowcode-editor-core';
import {
EngineOptions,
IPublicTypeEngineOptions,
IPublicModelDocumentModel,
IPublicTypePluginMeta,
} from '@alilc/lowcode-types';
@ -158,7 +158,7 @@ engineConfig.set('ENGINE_VERSION', version);
export async function init(
container?: HTMLElement,
options?: EngineOptions,
options?: IPublicTypeEngineOptions,
pluginPreference?: PluginPreference,
) {
await destroy();

View File

@ -1,5 +1,5 @@
import { BuiltinSimulatorHost, Node, IPublicTypePropChangeOptions } from '@alilc/lowcode-designer';
import { GlobalEvent, IPublicEnumTransformStage, IPublicTypeNodeSchema, EngineOptions } from '@alilc/lowcode-types';
import { GlobalEvent, IPublicEnumTransformStage, IPublicTypeNodeSchema, IPublicTypeEngineOptions } from '@alilc/lowcode-types';
import { isReactComponent, cloneEnumerableProperty } from '@alilc/lowcode-utils';
import { debounce } from '../utils/common';
import adapter from '../adapter';
@ -30,7 +30,7 @@ export interface IComponentHocState {
nodeProps: any;
}
type DesignMode = Pick<EngineOptions, 'designMode'>['designMode'];
type DesignMode = Pick<IPublicTypeEngineOptions, 'designMode'>['designMode'];
export interface IComponentHoc {
designMode: DesignMode | DesignMode[];

View File

@ -26,6 +26,5 @@ export * from './designer';
export * from './dragon';
export * from './shell';
export * from './shell-model-factory';
export * from './engine-config';
// TODO: remove this in future versions
export * from './deprecated';

View File

@ -1,99 +1,129 @@
import { RequestHandlersMap } from '@alilc/lowcode-datasource-types';
import { ComponentType } from 'react';
export interface EngineOptions {
export interface IPublicTypeEngineOptions {
/**
* 是否开启 condition 的能力,默认在设计器中不管 condition 是啥都正常展示
* when this is true, node that configured as conditional not renderring
* will not display in canvas.
* @default false
*/
enableCondition?: boolean;
/**
* @todo designMode 无法映射到文档渲染模块
* TODO: designMode 无法映射到文档渲染模块
*
* 设计模式,live 模式将会实时展示变量值,默认值:'design'
*
* @default 'design'
* @experimental
*/
designMode?: 'design' | 'live';
/**
* 设备类型,默认值:'default'
* @default 'default'
*/
device?: 'default' | 'mobile' | string;
/**
* 指定初始化的 deviceClassName,挂载到画布的顶层节点上
*/
deviceClassName?: string;
/**
* 语言,默认值:'zh-CN'
* @default 'zh-CN'
*/
locale?: string;
/**
* 渲染器类型,默认值:'react'
*/
renderEnv?: 'react' | 'rax' | string;
/**
* 设备类型映射器,处理设计器与渲染器中 device 的映射
*/
deviceMapper?: {
transform: (originalDevice: string) => string;
};
/**
* 开启严格插件模式,默认值:STRICT_PLUGIN_MODE_DEFAULT , 严格模式下,插件将无法通过 engineOptions 传递自定义配置项
* enable strict plugin mode, default value: false
* under strict mode, customed engineOption is not accepted.
*/
enableStrictPluginMode?: boolean;
enableStrictPluginMode?: boolean;
/**
* 开启拖拽组件时,即将被放入的容器是否有视觉反馈,默认值:false
*/
enableReactiveContainer?: boolean;
/**
* 关闭画布自动渲染,在资产包多重异步加载的场景有效,默认值:false
*/
disableAutoRender?: boolean;
/**
* 关闭拖拽组件时的虚线响应,性能考虑,默认值:false
*/
disableDetecting?: boolean;
/**
* 定制画布中点击被忽略的 selectors,默认值:undefined
*/
customizeIgnoreSelectors?: (defaultIgnoreSelectors: string[], e: MouseEvent) => string[];
/**
* 禁止默认的设置面板,默认值:false
*/
disableDefaultSettingPanel?: boolean;
/**
* 禁止默认的设置器,默认值:false
*/
disableDefaultSetters?: boolean;
/**
* 打开画布的锁定操作,默认值:false
*/
enableCanvasLock?: boolean;
/**
* 容器锁定后,容器本身是否可以设置属性,仅当画布锁定特性开启时生效,默认值为:false
*/
enableLockedNodeSetting?: boolean;
/**
* 当选中节点切换时,是否停留在相同的设置 tab 上,默认值:false
*/
stayOnTheSameSettingTab?: boolean;
/**
* 是否在只有一个 item 的时候隐藏设置 tabs,默认值:false
*/
hideSettingsTabsWhenOnlyOneItem?: boolean;
/**
* 自定义 loading 组件
*/
loadingComponent?: ComponentType;
/**
* 设置所有属性支持变量配置,默认值:false
*/
supportVariableGlobally?: boolean;
/**
* 设置 simulator 相关的 url,默认值:undefined
*/
simulatorUrl?: string[];
/**
* Vision-polyfill settings
* @deprecated this exists for some legacy reasons
*/
visionSettings?: {
// 是否禁用降级 reducer,默认值:false
@ -101,6 +131,7 @@ export interface EngineOptions {
// 是否开启在 render 阶段开启 filter reducer,默认值:false
enableFilterReducerInRenderStage?: boolean;
};
/**
* 与 react-renderer 的 appHelper 一致,https://lowcode-engine.cn/site/docs/guide/expand/runtime/renderer#apphelper
*/
@ -138,3 +169,10 @@ export interface EngineOptions {
*/
enableWorkspaceMode?: boolean;
}
/**
* @deprecated use IPublicTypeEngineOptions instead
*/
export interface EngineOptions {
}

View File

@ -73,4 +73,5 @@ export * from './tip-config';
export * from './widget-config-area';
export * from './hotkey-callback';
export * from './plugin-register-options';
export * from './resource-options';
export * from './resource-options';
export * from './engine-options';