common - 通用 API
@types IPublicApiCommon
@since v1.0.0
模块简介
通用模块里包含除了几大核心模块 API 之外的所有 API,比如通用 utils、面板扩展相关 等。
高能预警:之所以叫 skeletonCabin / designerCabin 跟兼容上一个版本的引擎有关系。若有必要,后面将用更有意义的命名空间来组织这些 API。
变量
utils
通用 utils,详见下方方法签名
skeletonCabin
面板扩展相关,详见下方方法签名
方法
utils
isNodeSchema
是否为合法的 schema 结构
/**
* 是否为合法的 schema 结构
* check if data is valid NodeSchema
*
* @param {*} data
* @returns {boolean}
*/
isNodeSchema(data: any): boolean;
isFormEvent
是否为表单事件类型
/**
* 是否为表单事件类型
* check if e is a form event
* @param {(KeyboardEvent | MouseEvent)} e
* @returns {boolean}
*/
isFormEvent(e: KeyboardEvent | MouseEvent): boolean;
getNodeSchemaById
从 schema 结构中查找指定 id 节点
/**
* 从 schema 结构中查找指定 id 节点
* get node schema from a larger schema with node id
* @param {IPublicTypeNodeSchema} schema
* @param {string} nodeId
* @returns {(IPublicTypeNodeSchema | undefined)}
*/
getNodeSchemaById(
schema: IPublicTypeNodeSchema,
nodeId: string,
): IPublicTypeNodeSchema | undefined;
executeTransaction
批处理事务,用于优化特定场景的性能
/**
* 批处理事务,用于优化特定场景的性能
* excute something in a transaction for performence
*
* @param {() => void} fn
* @param {IPublicEnumTransitionType} type
* @since v1.0.16
*/
executeTransaction(fn: () => void, type: IPublicEnumTransitionType): void;
@since v1.0.16
示例
import { common } from '@alilc/lowcode-engine';
import { IPublicEnumTransitionType } from '@alilc/lowcode-types';
common.utils.startTransaction(() => {
node1.setProps();
node2.setProps();
node3.setProps();
// ...
}, IPublicEnumTransitionType.repaint);
getConvertedExtraKey
props key 转化工具
getConvertedExtraKey(key: string): string
@since v1.0.17
createIntl
i18n 相关工具
/**
* i18n 相关工具
* i18n tools
*
* @param {(string | object)} instance
* @returns {{
* intlNode(id: string, params?: object): ReactNode;
* intl(id: string, params?: object): string;
* getLocale(): string;
* setLocale(locale: string): void;
* }}
* @since v1.0.17
*/
createIntl(instance: string | object): {
intlNode(id: string, params?: object): ReactNode;
intl(id: string, params?: object): string;
getLocale(): string;
setLocale(locale: string): void;
};
@since v1.0.17
示例
import { common } from '@alilc/lowcode-engine';
import enUS from './en-US.json';
import zhCN from './zh-CN.json';
const { intl, getLocale, setLocale } = common.utils.createIntl({
'en-US': enUS,
'zh-CN': zhCN,
});
intl
i18n 转换方法
/**
* i18n 转换方法
*/
intl(data: IPublicTypeI18nData | string, params?: object): string;
示例
const title = common.utils.intl(node.title)
skeletonCabin
Workbench
编辑器框架 View
/**
* 编辑器框架 View
* get Workbench Component
*/
get Workbench(): Component;