mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-15 22:22:51 +00:00
Compare commits
34 Commits
v1.3.1-bet
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6305c2284 | ||
|
|
2892a01d29 | ||
|
|
bd85ca3ca6 | ||
|
|
44beb2a25a | ||
|
|
86d50e0946 | ||
|
|
19eb917259 | ||
|
|
501ad872c4 | ||
|
|
76b2a05049 | ||
|
|
5657d9c084 | ||
|
|
5b46d96df7 | ||
|
|
24393211b4 | ||
|
|
de95b87b1e | ||
|
|
43921cea2d | ||
|
|
557a462b9f | ||
|
|
80bb7102b6 | ||
|
|
ed7befbff0 | ||
|
|
e3a19896d7 | ||
|
|
dfe6878028 | ||
|
|
6e89d4d605 | ||
|
|
739572172a | ||
|
|
b97570f10c | ||
|
|
b29c53901e | ||
|
|
b3880e9a96 | ||
|
|
947c621822 | ||
|
|
dca3448cbf | ||
|
|
0e65f02116 | ||
|
|
cd67a8cea3 | ||
|
|
e6ba79b4d7 | ||
|
|
de738b5d7c | ||
|
|
9b19d8f889 | ||
|
|
4025a7d2e0 | ||
|
|
8f8908c832 | ||
|
|
a8b9b2b5e1 | ||
|
|
84b4c76db2 |
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# These owners will be the default owners for everything in
|
# These owners will be the default owners for everything in
|
||||||
# the repo. Unless a later match takes precedence
|
# the repo. Unless a later match takes precedence
|
||||||
* @liujuping @JackLian
|
* @liujuping @1ncounter
|
||||||
|
|
||||||
/modules/material-parser @akirakai
|
/modules/material-parser @akirakai
|
||||||
/modules/code-generator @qingniaotonghua
|
/modules/code-generator @qingniaotonghua
|
||||||
|
|||||||
34
.github/workflows/pre build.yml
vendored
Normal file
34
.github/workflows/pre build.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
name: Pre Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- 'packages/**'
|
||||||
|
- '!packages/**.md'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'packages/**'
|
||||||
|
- '!packages/**.md'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Install dependencies and setup
|
||||||
|
run: npm install && npm run setup
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Check build status
|
||||||
|
run: |
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Build succeeded!"
|
||||||
|
else
|
||||||
|
echo "Build failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
2
.github/workflows/publish engine.yml
vendored
2
.github/workflows/publish engine.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: >-
|
if: >-
|
||||||
contains(github.ref, 'refs/heads/release/') &&
|
contains(github.ref, 'refs/heads/release/') &&
|
||||||
(github.actor == 'JackLian' || github.actor == 'liujuping')
|
(github.actor == '1ncounter' || github.actor == 'liujuping')
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
|
|||||||
32
.github/workflows/test packages.yml
vendored
32
.github/workflows/test packages.yml
vendored
@ -106,3 +106,35 @@ jobs:
|
|||||||
|
|
||||||
- name: test
|
- name: test
|
||||||
run: cd packages/utils && npm test
|
run: cd packages/utils && npm test
|
||||||
|
|
||||||
|
test-editor-core:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '14'
|
||||||
|
|
||||||
|
- name: install
|
||||||
|
run: npm i && npm run setup:skip-build
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
run: cd packages/editor-core && npm test
|
||||||
|
|
||||||
|
test-plugin-command:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '14'
|
||||||
|
|
||||||
|
- name: install
|
||||||
|
run: npm i && npm run setup:skip-build
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
run: cd packages/plugin-command && npm test
|
||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: canvas - 画布 API
|
title: canvas - 画布 API
|
||||||
sidebar_position: 12
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicApiCanvas](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/canvas.ts)<br/>
|
> **@types** [IPublicApiCanvas](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/canvas.ts)<br/>
|
||||||
|
|||||||
101
docs/docs/api/command.md
Normal file
101
docs/docs/api/command.md
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
---
|
||||||
|
title: command - 指令 API
|
||||||
|
sidebar_position: 10
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 模块概览
|
||||||
|
|
||||||
|
该模块使得与命令系统的交互成为可能,提供了一种全面的方式来处理、执行和管理应用程序中的命令。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 接口
|
||||||
|
|
||||||
|
### IPublicApiCommand
|
||||||
|
|
||||||
|
与命令交互的接口。它提供了注册、注销、执行和管理命令的方法。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 方法
|
||||||
|
|
||||||
|
### registerCommand
|
||||||
|
|
||||||
|
注册一个新命令及其处理函数。
|
||||||
|
|
||||||
|
```
|
||||||
|
typescriptCopy code
|
||||||
|
/**
|
||||||
|
* 注册一个新的命令及其处理程序。
|
||||||
|
* @param command {IPublicTypeCommand} - 要注册的命令。
|
||||||
|
*/
|
||||||
|
registerCommand(command: IPublicTypeCommand): void;
|
||||||
|
```
|
||||||
|
|
||||||
|
### unregisterCommand
|
||||||
|
|
||||||
|
注销一个已存在的命令。
|
||||||
|
|
||||||
|
```
|
||||||
|
typescriptCopy code
|
||||||
|
/**
|
||||||
|
* 注销一个已存在的命令。
|
||||||
|
* @param name {string} - 要注销的命令的名称。
|
||||||
|
*/
|
||||||
|
unregisterCommand(name: string): void;
|
||||||
|
```
|
||||||
|
|
||||||
|
### executeCommand
|
||||||
|
|
||||||
|
根据名称和提供的参数执行命令,确保参数符合命令的定义。
|
||||||
|
|
||||||
|
```
|
||||||
|
typescriptCopy code
|
||||||
|
/**
|
||||||
|
* 根据名称和提供的参数执行命令。
|
||||||
|
* @param name {string} - 要执行的命令的名称。
|
||||||
|
* @param args {IPublicTypeCommandHandlerArgs} - 命令的参数。
|
||||||
|
*/
|
||||||
|
executeCommand(name: string, args?: IPublicTypeCommandHandlerArgs): void;
|
||||||
|
```
|
||||||
|
|
||||||
|
### batchExecuteCommand
|
||||||
|
|
||||||
|
批量执行命令,在所有命令执行后进行重绘,历史记录中只记录一次。
|
||||||
|
|
||||||
|
```
|
||||||
|
typescriptCopy code
|
||||||
|
/**
|
||||||
|
* 批量执行命令,随后进行重绘,历史记录中只记录一次。
|
||||||
|
* @param commands {Array} - 命令对象的数组,包含名称和可选参数。
|
||||||
|
*/
|
||||||
|
batchExecuteCommand(commands: { name: string; args?: IPublicTypeCommandHandlerArgs }[]): void;
|
||||||
|
```
|
||||||
|
|
||||||
|
### listCommands
|
||||||
|
|
||||||
|
列出所有已注册的命令。
|
||||||
|
|
||||||
|
```
|
||||||
|
typescriptCopy code
|
||||||
|
/**
|
||||||
|
* 列出所有已注册的命令。
|
||||||
|
* @returns {IPublicTypeListCommand[]} - 已注册命令的数组。
|
||||||
|
*/
|
||||||
|
listCommands(): IPublicTypeListCommand[];
|
||||||
|
```
|
||||||
|
|
||||||
|
### onCommandError
|
||||||
|
|
||||||
|
为命令执行过程中的错误注册错误处理回调函数。
|
||||||
|
|
||||||
|
```
|
||||||
|
typescriptCopy code
|
||||||
|
/**
|
||||||
|
* 为命令执行过程中的错误注册一个回调函数。
|
||||||
|
* @param callback {(name: string, error: Error) => void} - 错误处理的回调函数。
|
||||||
|
*/
|
||||||
|
onCommandError(callback: (name: string, error: Error) => void): void;
|
||||||
|
```
|
||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: common - 通用 API
|
title: common - 通用 API
|
||||||
sidebar_position: 11
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicApiCommon](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/common.ts)<br/>
|
> **@types** [IPublicApiCommon](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/common.ts)<br/>
|
||||||
@ -82,7 +82,7 @@ executeTransaction(fn: () => void, type: IPublicEnumTransitionType): void;
|
|||||||
```
|
```
|
||||||
**@since v1.0.16**
|
**@since v1.0.16**
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { common } from '@alilc/lowcode-engine';
|
import { common } from '@alilc/lowcode-engine';
|
||||||
import { IPublicEnumTransitionType } from '@alilc/lowcode-types';
|
import { IPublicEnumTransitionType } from '@alilc/lowcode-types';
|
||||||
@ -132,7 +132,8 @@ createIntl(instance: string | object): {
|
|||||||
|
|
||||||
**@since v1.0.17**
|
**@since v1.0.17**
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
import { common } from '@alilc/lowcode-engine';
|
import { common } from '@alilc/lowcode-engine';
|
||||||
import enUS from './en-US.json';
|
import enUS from './en-US.json';
|
||||||
@ -156,7 +157,7 @@ i18n 转换方法
|
|||||||
intl(data: IPublicTypeI18nData | string, params?: object): string;
|
intl(data: IPublicTypeI18nData | string, params?: object): string;
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```
|
```
|
||||||
const title = common.utils.intl(node.title)
|
const title = common.utils.intl(node.title)
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: commonUI - UI 组件库
|
title: commonUI - UI 组件库
|
||||||
sidebar_position: 11
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
## 简介
|
## 简介
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: config - 配置 API
|
title: config - 配置 API
|
||||||
sidebar_position: 8
|
sidebar_position: 5
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicModelEngineConfig](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/engine-config.ts)<br/>
|
> **@types** [IPublicModelEngineConfig](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/engine-config.ts)<br/>
|
||||||
@ -24,7 +24,7 @@ sidebar_position: 8
|
|||||||
*/
|
*/
|
||||||
get(key: string, defaultValue?: any): any;
|
get(key: string, defaultValue?: any): any;
|
||||||
```
|
```
|
||||||
#### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { config } from '@alilc/lowcode-engine';
|
import { config } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ config.get('keyB', { a: 1 });
|
|||||||
*/
|
*/
|
||||||
set(key: string, value: any): void;
|
set(key: string, value: any): void;
|
||||||
```
|
```
|
||||||
#### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { config } from '@alilc/lowcode-engine';
|
import { config } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ config.set('keyC', 1);
|
|||||||
has(key: string): boolean;
|
has(key: string): boolean;
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { config } from '@alilc/lowcode-engine';
|
import { config } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ config.has('keyD');
|
|||||||
*/
|
*/
|
||||||
setConfig(config: { [key: string]: any }): void;
|
setConfig(config: { [key: string]: any }): void;
|
||||||
```
|
```
|
||||||
#### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { config } from '@alilc/lowcode-engine';
|
import { config } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ config.getPreference().set(`${panelName}-pinned-status-isFloat`, false, 'skeleto
|
|||||||
*/
|
*/
|
||||||
onceGot(key: string): Promise<any>;
|
onceGot(key: string): Promise<any>;
|
||||||
```
|
```
|
||||||
#### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { config } from '@alilc/lowcode-engine';
|
import { config } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ const value = await config.onceGot('keyA');
|
|||||||
*/
|
*/
|
||||||
onGot(key: string, fn: (data: any) => void): () => void;
|
onGot(key: string, fn: (data: any) => void): () => void;
|
||||||
```
|
```
|
||||||
#### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { config } from '@alilc/lowcode-engine';
|
import { config } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: config options - 配置列表
|
title: config options - 配置列表
|
||||||
sidebar_position: 13
|
sidebar_position: 5
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicTypeEngineOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/engine-options.ts)<br/>
|
> **@types** [IPublicTypeEngineOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/engine-options.ts)<br/>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: event - 事件 API
|
title: event - 事件 API
|
||||||
sidebar_position: 7
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicApiEvent](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/event.ts)<br/>
|
> **@types** [IPublicApiEvent](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/event.ts)<br/>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: hotkey - 快捷键 API
|
title: hotkey - 快捷键 API
|
||||||
sidebar_position: 5
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicApiHotkey](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/hotkey.ts)<br/>
|
> **@types** [IPublicApiHotkey](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/hotkey.ts)<br/>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: init - 初始化 API
|
title: init - 初始化 API
|
||||||
sidebar_position: 10
|
sidebar_position: 0
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@since** v1.0.0
|
> **@since** v1.0.0
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: logger - 日志 API
|
title: logger - 日志 API
|
||||||
sidebar_position: 9
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicApiLogger](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/logger.ts)<br/>
|
> **@types** [IPublicApiLogger](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/logger.ts)<br/>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: material - 物料 API
|
title: material - 物料 API
|
||||||
sidebar_position: 2
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **@types** [IPublicApiMaterial](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/material.ts)<br/>
|
> **@types** [IPublicApiMaterial](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/material.ts)<br/>
|
||||||
@ -39,7 +39,7 @@ setAssets(assets: IPublicTypeAssetsJson): void;
|
|||||||
相关类型:[IPublicTypeAssetsJson](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/assets-json.ts)
|
相关类型:[IPublicTypeAssetsJson](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/assets-json.ts)
|
||||||
|
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
直接在项目中引用 npm 包
|
直接在项目中引用 npm 包
|
||||||
```javascript
|
```javascript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
@ -85,7 +85,7 @@ getAssets(): IPublicTypeAssetsJson;
|
|||||||
相关类型:[IPublicTypeAssetsJson](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/assets-json.ts)
|
相关类型:[IPublicTypeAssetsJson](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/assets-json.ts)
|
||||||
|
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ loadIncrementalAssets(incrementalAssets: IPublicTypeAssetsJson): Promise<void>;
|
|||||||
```
|
```
|
||||||
相关类型:[IPublicTypeAssetsJson](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/assets-json.ts)
|
相关类型:[IPublicTypeAssetsJson](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/assets-json.ts)
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
import assets1 from '@alilc/mc-assets-<siteId>/assets.json';
|
import assets1 from '@alilc/mc-assets-<siteId>/assets.json';
|
||||||
@ -146,7 +146,7 @@ addBuiltinComponentAction(action: IPublicTypeComponentAction): void;
|
|||||||
相关类型:[IPublicTypeComponentAction](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/component-action.ts)
|
相关类型:[IPublicTypeComponentAction](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/component-action.ts)
|
||||||
|
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
新增设计扩展位,并绑定事件
|
新增设计扩展位,并绑定事件
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
@ -186,7 +186,7 @@ removeBuiltinComponentAction(name: string): void;
|
|||||||
- lock:锁定,不可编辑
|
- lock:锁定,不可编辑
|
||||||
- unlock:解锁,可编辑
|
- unlock:解锁,可编辑
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ modifyBuiltinComponentAction(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
给原始的 remove 扩展时间添加执行前后的日志
|
给原始的 remove 扩展时间添加执行前后的日志
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
@ -335,7 +335,7 @@ getComponentMeta(componentName: string): IPublicModelComponentMeta | null;
|
|||||||
```
|
```
|
||||||
相关类型:[IPublicModelComponentMeta](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/component-meta.ts)
|
相关类型:[IPublicModelComponentMeta](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/component-meta.ts)
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ material.getComponentMeta('Input');
|
|||||||
```
|
```
|
||||||
相关类型:[IPublicModelComponentMeta](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/component-meta.ts)
|
相关类型:[IPublicModelComponentMeta](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/model/component-meta.ts)
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
@ -393,7 +393,7 @@ registerMetadataTransducer(
|
|||||||
): void;
|
): void;
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
给每一个组件的配置添加高级配置面板,其中有一个是否渲染配置项
|
给每一个组件的配置添加高级配置面板,其中有一个是否渲染配置项
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine'
|
import { material } from '@alilc/lowcode-engine'
|
||||||
@ -475,7 +475,7 @@ material.registerMetadataTransducer((transducer) => {
|
|||||||
getRegisteredMetadataTransducers(): IPublicTypeMetadataTransducer[];
|
getRegisteredMetadataTransducers(): IPublicTypeMetadataTransducer[];
|
||||||
```
|
```
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine'
|
import { material } from '@alilc/lowcode-engine'
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ onChangeAssets(fn: () => void): IPublicTypeDisposable;
|
|||||||
|
|
||||||
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
|
相关类型:[IPublicTypeDisposable](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/disposable.ts)
|
||||||
|
|
||||||
##### 示例
|
**示例**
|
||||||
```typescript
|
```typescript
|
||||||
import { material } from '@alilc/lowcode-engine';
|
import { material } from '@alilc/lowcode-engine';
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"label": "模型定义 Models",
|
"label": "模型定义 Models",
|
||||||
"position": 14,
|
"position": 100,
|
||||||
"collapsed": false,
|
"collapsed": false,
|
||||||
"collapsible": true
|
"collapsible": true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: plugins - 插件 API
|
title: plugins - 插件 API
|
||||||
sidebar_position: 4
|
sidebar_position: 2
|
||||||
---
|
---
|
||||||
> **@types** [IPublicApiPlugins](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/plugins.ts)<br/>
|
> **@types** [IPublicApiPlugins](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/plugins.ts)<br/>
|
||||||
> **@since** v1.0.0
|
> **@since** v1.0.0
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: project - 模型 API
|
title: project - 模型 API
|
||||||
sidebar_position: 3
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
## 模块简介
|
## 模块简介
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ addPropsTransducer(
|
|||||||
- [IPublicTypePropsTransducer](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/props-transducer.ts)
|
- [IPublicTypePropsTransducer](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/props-transducer.ts)
|
||||||
- [IPublicEnumTransformStage](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/enum/transform-stage.ts)
|
- [IPublicEnumTransformStage](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/enum/transform-stage.ts)
|
||||||
|
|
||||||
#### 示例
|
**示例**
|
||||||
在保存的时候删除每一个组件的 props.hidden
|
在保存的时候删除每一个组件的 props.hidden
|
||||||
```typescript
|
```typescript
|
||||||
import { project } from '@alilc/lowcode-engine';
|
import { project } from '@alilc/lowcode-engine';
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: setters - 设置器 API
|
title: setters - 设置器 API
|
||||||
sidebar_position: 6
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
> **@types** [IPublicApiSetters](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/setters.ts)<br/>
|
> **@types** [IPublicApiSetters](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/setters.ts)<br/>
|
||||||
> **@since** v1.0.0
|
> **@since** v1.0.0
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: simulatorHost - 模拟器 API
|
title: simulatorHost - 模拟器 API
|
||||||
sidebar_position: 3
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
> **@types** [IPublicApiSimulatorHost](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/simulator-host.ts)<br/>
|
> **@types** [IPublicApiSimulatorHost](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/simulator-host.ts)<br/>
|
||||||
> **@since** v1.0.0
|
> **@since** v1.0.0
|
||||||
@ -20,7 +20,7 @@ sidebar_position: 3
|
|||||||
*/
|
*/
|
||||||
set(key: string, value: any): void;
|
set(key: string, value: any): void;
|
||||||
```
|
```
|
||||||
#### 示例
|
**示例**
|
||||||
设置若干用于画布渲染的变量,比如画布大小、locale 等。
|
设置若干用于画布渲染的变量,比如画布大小、locale 等。
|
||||||
|
|
||||||
以设置画布大小为例:
|
以设置画布大小为例:
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: skeleton - 面板 API
|
title: skeleton - 面板 API
|
||||||
sidebar_position: 1
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
> **@types** [IPublicApiSkeleton](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/skeleton.ts)<br/>
|
> **@types** [IPublicApiSkeleton](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/api/skeleton.ts)<br/>
|
||||||
> **@since** v1.0.0
|
> **@since** v1.0.0
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: workspace - 应用级 API
|
title: workspace - 应用级 API
|
||||||
sidebar_position: 12
|
sidebar_position: 10
|
||||||
---
|
---
|
||||||
|
|
||||||
> **[@experimental](./#experimental)**<br/>
|
> **[@experimental](./#experimental)**<br/>
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
title: 3. 如何通过按钮展示/隐藏弹窗
|
title: 3. 如何通过按钮展示/隐藏弹窗
|
||||||
sidebar_position: 1
|
sidebar_position: 1
|
||||||
---
|
---
|
||||||
|
> 说明:这个方式依赖低代码弹窗组件是否对外保留了相关的 API,不同的物料支持的方式不一样,这里只针对综合场景的弹窗物料。
|
||||||
|
|
||||||
## 1.拖拽一个按钮
|
## 1.拖拽一个按钮
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-engine-docs",
|
"name": "@alilc/lowcode-engine-docs",
|
||||||
"version": "1.2.28",
|
"version": "1.2.31",
|
||||||
"description": "低代码引擎版本化文档",
|
"description": "低代码引擎版本化文档",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"lerna": "4.0.0",
|
"lerna": "4.0.0",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"npmClient": "yarn",
|
"npmClient": "yarn",
|
||||||
"useWorkspaces": true,
|
"useWorkspaces": true,
|
||||||
"packages": [
|
"packages": [
|
||||||
|
|||||||
@ -54,7 +54,7 @@
|
|||||||
"yarn": "^1.22.17",
|
"yarn": "^1.22.17",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"@types/react-router": "5.1.18",
|
"@types/react-router": "5.1.18",
|
||||||
"@alilc/build-plugin-lce": "^0.0.4",
|
"@alilc/build-plugin-lce": "^0.0.5",
|
||||||
"babel-jest": "^26.5.2",
|
"babel-jest": "^26.5.2",
|
||||||
"@alilc/lowcode-test-mate": "^1.0.1"
|
"@alilc/lowcode-test-mate": "^1.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -21,6 +21,7 @@ const jestConfig = {
|
|||||||
// testMatch: ['**/builtin-hotkey.test.ts'],
|
// testMatch: ['**/builtin-hotkey.test.ts'],
|
||||||
// testMatch: ['**/selection.test.ts'],
|
// testMatch: ['**/selection.test.ts'],
|
||||||
// testMatch: ['**/plugin/sequencify.test.ts'],
|
// testMatch: ['**/plugin/sequencify.test.ts'],
|
||||||
|
// testMatch: ['**/builtin-simulator/utils/parse-metadata.test.ts'],
|
||||||
transformIgnorePatterns: [
|
transformIgnorePatterns: [
|
||||||
`/node_modules/(?!${esModules})/`,
|
`/node_modules/(?!${esModules})/`,
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-designer",
|
"name": "@alilc/lowcode-designer",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Designer for Ali LowCode Engine",
|
"description": "Designer for Ali LowCode Engine",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
@ -15,9 +15,9 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alilc/lowcode-editor-core": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-core": "1.3.2",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"react": "^16",
|
"react": "^16",
|
||||||
"react-dom": "^16.7.0",
|
"react-dom": "^16.7.0",
|
||||||
@ -52,7 +52,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/designer"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/designer"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,16 @@ export const primitiveTypes = [
|
|||||||
'any',
|
'any',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
interface LowcodeCheckType {
|
||||||
|
// isRequired, props, propName, componentName, location, propFullName, secret
|
||||||
|
(props: any, propName: string, componentName: string, ...rest: any[]): Error | null;
|
||||||
|
// (...reset: any[]): Error | null;
|
||||||
|
isRequired?: LowcodeCheckType;
|
||||||
|
type?: string | object;
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
function makeRequired(propType: any, lowcodeType: string | object) {
|
function makeRequired(propType: any, lowcodeType: string | object): LowcodeCheckType {
|
||||||
function lowcodeCheckTypeIsRequired(...rest: any[]) {
|
function lowcodeCheckTypeIsRequired(...rest: any[]) {
|
||||||
return propType.isRequired(...rest);
|
return propType.isRequired(...rest);
|
||||||
}
|
}
|
||||||
@ -34,7 +42,7 @@ function makeRequired(propType: any, lowcodeType: string | object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||||
function define(propType: any = PropTypes.any, lowcodeType: string | object = {}) {
|
function define(propType: any = PropTypes.any, lowcodeType: string | object = {}): LowcodeCheckType {
|
||||||
if (!propType._inner && propType.name !== 'lowcodeCheckType') {
|
if (!propType._inner && propType.name !== 'lowcodeCheckType') {
|
||||||
propType.lowcodeType = lowcodeType;
|
propType.lowcodeType = lowcodeType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,7 +70,7 @@ export class Transducer {
|
|||||||
}
|
}
|
||||||
if (isDynamicSetter(setter) && isDynamic) {
|
if (isDynamicSetter(setter) && isDynamic) {
|
||||||
try {
|
try {
|
||||||
setter = setter.call(context, context);
|
setter = setter.call(context.internalToShellField(), context.internalToShellField());
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -353,7 +353,6 @@ export class Prop implements IProp, IPropParent {
|
|||||||
@action
|
@action
|
||||||
setValue(val: IPublicTypeCompositeValue) {
|
setValue(val: IPublicTypeCompositeValue) {
|
||||||
if (val === this._value) return;
|
if (val === this._value) return;
|
||||||
const editor = this.owner.document?.designer.editor;
|
|
||||||
const oldValue = this._value;
|
const oldValue = this._value;
|
||||||
this._value = val;
|
this._value = val;
|
||||||
this._code = null;
|
this._code = null;
|
||||||
@ -386,22 +385,31 @@ export class Prop implements IProp, IPropParent {
|
|||||||
this.setupItems();
|
this.setupItems();
|
||||||
|
|
||||||
if (oldValue !== this._value) {
|
if (oldValue !== this._value) {
|
||||||
const propsInfo = {
|
this.emitChange({ oldValue });
|
||||||
key: this.key,
|
|
||||||
prop: this,
|
|
||||||
oldValue,
|
|
||||||
newValue: this._value,
|
|
||||||
};
|
|
||||||
|
|
||||||
editor?.eventBus.emit(GlobalEvent.Node.Prop.InnerChange, {
|
|
||||||
node: this.owner as any,
|
|
||||||
...propsInfo,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.owner?.emitPropChange?.(propsInfo);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitChange = ({
|
||||||
|
oldValue,
|
||||||
|
}: {
|
||||||
|
oldValue: IPublicTypeCompositeValue | UNSET;
|
||||||
|
}) => {
|
||||||
|
const editor = this.owner.document?.designer.editor;
|
||||||
|
const propsInfo = {
|
||||||
|
key: this.key,
|
||||||
|
prop: this,
|
||||||
|
oldValue,
|
||||||
|
newValue: this.type === 'unset' ? undefined : this._value,
|
||||||
|
};
|
||||||
|
|
||||||
|
editor?.eventBus.emit(GlobalEvent.Node.Prop.InnerChange, {
|
||||||
|
node: this.owner as any,
|
||||||
|
...propsInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.owner?.emitPropChange?.(propsInfo);
|
||||||
|
};
|
||||||
|
|
||||||
getValue(): IPublicTypeCompositeValue {
|
getValue(): IPublicTypeCompositeValue {
|
||||||
return this.export(IPublicEnumTransformStage.Serilize);
|
return this.export(IPublicEnumTransformStage.Serilize);
|
||||||
}
|
}
|
||||||
@ -462,7 +470,12 @@ export class Prop implements IProp, IPropParent {
|
|||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
unset() {
|
unset() {
|
||||||
this._type = 'unset';
|
if (this._type !== 'unset') {
|
||||||
|
this._type = 'unset';
|
||||||
|
this.emitChange({
|
||||||
|
oldValue: this._value,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -557,6 +570,7 @@ export class Prop implements IProp, IPropParent {
|
|||||||
@action
|
@action
|
||||||
remove() {
|
remove() {
|
||||||
this.parent.delete(this);
|
this.parent.delete(this);
|
||||||
|
this.unset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import {
|
|||||||
IPublicModelWindow,
|
IPublicModelWindow,
|
||||||
IPublicEnumPluginRegisterLevel,
|
IPublicEnumPluginRegisterLevel,
|
||||||
IPublicApiCommonUI,
|
IPublicApiCommonUI,
|
||||||
|
IPublicApiCommand,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import PluginContext from './plugin-context';
|
import PluginContext from './plugin-context';
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ export interface ILowCodePluginContextPrivate {
|
|||||||
set registerLevel(level: IPublicEnumPluginRegisterLevel);
|
set registerLevel(level: IPublicEnumPluginRegisterLevel);
|
||||||
set isPluginRegisteredInWorkspace(flag: boolean);
|
set isPluginRegisteredInWorkspace(flag: boolean);
|
||||||
set commonUI(commonUI: IPublicApiCommonUI);
|
set commonUI(commonUI: IPublicApiCommonUI);
|
||||||
|
set command(command: IPublicApiCommand);
|
||||||
}
|
}
|
||||||
export interface ILowCodePluginContextApiAssembler {
|
export interface ILowCodePluginContextApiAssembler {
|
||||||
assembleApis(
|
assembleApis(
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import '../../fixtures/window';
|
import '../../fixtures/window';
|
||||||
import { parseMetadata } from '../../../src/builtin-simulator/utils/parse-metadata';
|
import PropTypes from 'prop-types';
|
||||||
|
import { LowcodeTypes, parseMetadata, parseProps } from '../../../src/builtin-simulator/utils/parse-metadata';
|
||||||
|
import { default as ReactPropTypesSecret } from 'prop-types/lib/ReactPropTypesSecret';
|
||||||
|
|
||||||
describe('parseMetadata', () => {
|
describe('parseMetadata', () => {
|
||||||
it('parseMetadata', async () => {
|
it('parseMetadata', async () => {
|
||||||
@ -11,3 +13,165 @@ describe('parseMetadata', () => {
|
|||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('LowcodeTypes basic type validators', () => {
|
||||||
|
it('should validate string types', () => {
|
||||||
|
const stringValidator = LowcodeTypes.string;
|
||||||
|
// 对 stringValidator 进行测试
|
||||||
|
const props = { testProp: 'This is a string' };
|
||||||
|
const propName = 'testProp';
|
||||||
|
const componentName = 'TestComponent';
|
||||||
|
|
||||||
|
const result = stringValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeNull(); // No error for valid string
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail with a non-string type', () => {
|
||||||
|
const stringValidator = LowcodeTypes.string;
|
||||||
|
const props = { testProp: 42 };
|
||||||
|
const propName = 'testProp';
|
||||||
|
const componentName = 'TestComponent';
|
||||||
|
|
||||||
|
const result = stringValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeInstanceOf(Error); // Error for non-string type
|
||||||
|
expect(result.message).toContain('Invalid prop `testProp` of type `number` supplied to `TestComponent`, expected `string`.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should pass with a valid number', () => {
|
||||||
|
const numberValidator = LowcodeTypes.number;
|
||||||
|
const props = { testProp: 42 };
|
||||||
|
const propName = 'testProp';
|
||||||
|
const componentName = 'TestComponent';
|
||||||
|
|
||||||
|
const result = numberValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeNull(); // No error for valid number
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail with a non-number type', () => {
|
||||||
|
const numberValidator = LowcodeTypes.number;
|
||||||
|
const props = { testProp: 'Not a number' };
|
||||||
|
const propName = 'testProp';
|
||||||
|
const componentName = 'TestComponent';
|
||||||
|
|
||||||
|
const result = numberValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeInstanceOf(Error); // Error for non-number type
|
||||||
|
expect(result.message).toContain('Invalid prop `testProp` of type `string` supplied to `TestComponent`, expected `number`.');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Custom type constructors', () => {
|
||||||
|
it('should create a custom type validator using define', () => {
|
||||||
|
const customType = LowcodeTypes.define(PropTypes.string, 'customType');
|
||||||
|
const props = { testProp: 'This is a string' };
|
||||||
|
const propName = 'testProp';
|
||||||
|
const componentName = 'TestComponent';
|
||||||
|
|
||||||
|
// 测试有效值
|
||||||
|
const validResult = customType(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(validResult).toBeNull(); // No error for valid string
|
||||||
|
|
||||||
|
// 测试无效值
|
||||||
|
const invalidProps = { testProp: 42 };
|
||||||
|
const invalidResult = customType(invalidProps, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(invalidResult).toBeInstanceOf(Error); // Error for non-string type
|
||||||
|
|
||||||
|
// 验证 lowcodeType 属性
|
||||||
|
expect(customType.lowcodeType).toEqual('customType');
|
||||||
|
|
||||||
|
// 验证 isRequired 属性
|
||||||
|
const requiredResult = customType.isRequired(invalidProps, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(requiredResult).toBeInstanceOf(Error); // Error for non-string type
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('Advanced type constructors', () => {
|
||||||
|
describe('oneOf Type Validator', () => {
|
||||||
|
const oneOfValidator = LowcodeTypes.oneOf(['red', 'green', 'blue']);
|
||||||
|
const propName = 'color';
|
||||||
|
const componentName = 'ColorPicker';
|
||||||
|
|
||||||
|
it('should pass with a valid value', () => {
|
||||||
|
const props = { color: 'red' };
|
||||||
|
const result = oneOfValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeNull(); // No error for valid value
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail with an invalid value', () => {
|
||||||
|
const props = { color: 'yellow' };
|
||||||
|
const result = oneOfValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeInstanceOf(Error); // Error for invalid value
|
||||||
|
expect(result.message).toContain(`Invalid prop \`${propName}\` of value \`yellow\` supplied to \`${componentName}\`, expected one of ["red","green","blue"].`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fail with a non-existing value', () => {
|
||||||
|
const props = { color: 'others' };
|
||||||
|
const result = oneOfValidator(props, propName, componentName, 'prop', null, ReactPropTypesSecret);
|
||||||
|
expect(result).toBeInstanceOf(Error); // Error for non-existing value
|
||||||
|
expect(result.message).toContain(`Invalid prop \`${propName}\` of value \`others\` supplied to \`${componentName}\`, expected one of ["red","green","blue"].`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('parseProps function', () => {
|
||||||
|
it('should correctly parse propTypes and defaultProps', () => {
|
||||||
|
const component = {
|
||||||
|
propTypes: {
|
||||||
|
name: LowcodeTypes.string,
|
||||||
|
age: LowcodeTypes.number,
|
||||||
|
},
|
||||||
|
defaultProps: {
|
||||||
|
name: 'John Doe',
|
||||||
|
age: 30,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const parsedProps = parseProps(component);
|
||||||
|
|
||||||
|
// 测试结果长度
|
||||||
|
expect(parsedProps.length).toBe(2);
|
||||||
|
|
||||||
|
// 测试 name 属性
|
||||||
|
const nameProp: any = parsedProps.find(prop => prop.name === 'name');
|
||||||
|
expect(nameProp).toBeDefined();
|
||||||
|
expect(nameProp.propType).toEqual('string');
|
||||||
|
expect(nameProp.defaultValue).toEqual('John Doe');
|
||||||
|
|
||||||
|
// 测试 age 属性
|
||||||
|
const ageProp: any = parsedProps.find(prop => prop.name === 'age');
|
||||||
|
expect(ageProp).toBeDefined();
|
||||||
|
expect(ageProp.propType).toEqual('number');
|
||||||
|
expect(ageProp.defaultValue).toEqual(30);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('parseProps function', () => {
|
||||||
|
it('should correctly parse propTypes and defaultProps', () => {
|
||||||
|
const component = {
|
||||||
|
propTypes: {
|
||||||
|
name: LowcodeTypes.string,
|
||||||
|
age: LowcodeTypes.number,
|
||||||
|
},
|
||||||
|
defaultProps: {
|
||||||
|
name: 'John Doe',
|
||||||
|
age: 30,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const parsedProps = parseProps(component);
|
||||||
|
|
||||||
|
// 测试结果长度
|
||||||
|
expect(parsedProps.length).toBe(2);
|
||||||
|
|
||||||
|
// 测试 name 属性
|
||||||
|
const nameProp: any = parsedProps.find(prop => prop.name === 'name');
|
||||||
|
expect(nameProp).toBeDefined();
|
||||||
|
expect(nameProp.propType).toEqual('string');
|
||||||
|
expect(nameProp.defaultValue).toEqual('John Doe');
|
||||||
|
|
||||||
|
// 测试 age 属性
|
||||||
|
const ageProp: any = parsedProps.find(prop => prop.name === 'age');
|
||||||
|
expect(ageProp).toBeDefined();
|
||||||
|
expect(ageProp.propType).toEqual('number');
|
||||||
|
expect(ageProp.defaultValue).toEqual(30);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { Editor, engineConfig } from '@alilc/lowcode-editor-core';
|
|||||||
import { Designer } from '../../../../src/designer/designer';
|
import { Designer } from '../../../../src/designer/designer';
|
||||||
import { DocumentModel } from '../../../../src/document/document-model';
|
import { DocumentModel } from '../../../../src/document/document-model';
|
||||||
import { Prop, isProp, isValidArrayIndex } from '../../../../src/document/node/props/prop';
|
import { Prop, isProp, isValidArrayIndex } from '../../../../src/document/node/props/prop';
|
||||||
import { IPublicEnumTransformStage } from '@alilc/lowcode-types';
|
import { GlobalEvent, IPublicEnumTransformStage } from '@alilc/lowcode-types';
|
||||||
import { shellModelFactory } from '../../../../../engine/src/modules/shell-model-factory';
|
import { shellModelFactory } from '../../../../../engine/src/modules/shell-model-factory';
|
||||||
|
|
||||||
const slotNodeImportMockFn = jest.fn();
|
const slotNodeImportMockFn = jest.fn();
|
||||||
@ -24,14 +24,24 @@ const mockOwner = {
|
|||||||
remove: slotNodeRemoveMockFn,
|
remove: slotNodeRemoveMockFn,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
designer: {},
|
designer: {
|
||||||
|
editor: {
|
||||||
|
eventBus: {
|
||||||
|
emit: jest.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
isInited: true,
|
isInited: true,
|
||||||
|
emitPropChange: jest.fn(),
|
||||||
|
delete() {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockPropsInst = {
|
const mockPropsInst = {
|
||||||
owner: mockOwner,
|
owner: mockOwner,
|
||||||
|
delete() {},
|
||||||
};
|
};
|
||||||
|
|
||||||
mockPropsInst.props = mockPropsInst;
|
mockPropsInst.props = mockPropsInst;
|
||||||
|
|
||||||
describe('Prop 类测试', () => {
|
describe('Prop 类测试', () => {
|
||||||
@ -564,3 +574,124 @@ describe('其他导出函数', () => {
|
|||||||
expect(isValidArrayIndex('2', 1)).toBeFalsy();
|
expect(isValidArrayIndex('2', 1)).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setValue with event', () => {
|
||||||
|
let propInstance;
|
||||||
|
let mockEmitChange;
|
||||||
|
let mockEventBusEmit;
|
||||||
|
let mockEmitPropChange;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
// Initialize the instance of your class
|
||||||
|
propInstance = new Prop(mockPropsInst, true, 'stringProp');;
|
||||||
|
|
||||||
|
// Mock necessary methods and properties
|
||||||
|
mockEmitChange = jest.spyOn(propInstance, 'emitChange');
|
||||||
|
propInstance.owner = {
|
||||||
|
document: {
|
||||||
|
designer: {
|
||||||
|
editor: {
|
||||||
|
eventBus: {
|
||||||
|
emit: jest.fn(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
emitPropChange: jest.fn(),
|
||||||
|
delete() {},
|
||||||
|
};
|
||||||
|
mockEventBusEmit = jest.spyOn(propInstance.owner.document.designer.editor.eventBus, 'emit');
|
||||||
|
mockEmitPropChange = jest.spyOn(propInstance.owner, 'emitPropChange');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.restoreAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly handle string values and emit changes', () => {
|
||||||
|
const oldValue = propInstance._value;
|
||||||
|
const newValue = 'new string value';
|
||||||
|
|
||||||
|
propInstance.setValue(newValue);
|
||||||
|
|
||||||
|
const expectedPartialPropsInfo = expect.objectContaining({
|
||||||
|
key: propInstance.key,
|
||||||
|
newValue, // You can specifically test only certain keys
|
||||||
|
oldValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(propInstance.getValue()).toBe(newValue);
|
||||||
|
expect(propInstance.type).toBe('literal');
|
||||||
|
expect(mockEmitChange).toHaveBeenCalledWith({ oldValue });
|
||||||
|
expect(mockEventBusEmit).toHaveBeenCalledWith(GlobalEvent.Node.Prop.InnerChange, expectedPartialPropsInfo);
|
||||||
|
expect(mockEmitPropChange).toHaveBeenCalledWith(expectedPartialPropsInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle object values and set type to map', () => {
|
||||||
|
const oldValue = propInstance._value;
|
||||||
|
const newValue = 234;
|
||||||
|
|
||||||
|
const expectedPartialPropsInfo = expect.objectContaining({
|
||||||
|
key: propInstance.key,
|
||||||
|
newValue, // You can specifically test only certain keys
|
||||||
|
oldValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
propInstance.setValue(newValue);
|
||||||
|
|
||||||
|
expect(propInstance.getValue()).toEqual(newValue);
|
||||||
|
expect(propInstance.type).toBe('literal');
|
||||||
|
expect(mockEmitChange).toHaveBeenCalledWith({ oldValue });
|
||||||
|
expect(mockEventBusEmit).toHaveBeenCalledWith(GlobalEvent.Node.Prop.InnerChange, expectedPartialPropsInfo);
|
||||||
|
expect(mockEmitPropChange).toHaveBeenCalledWith(expectedPartialPropsInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should has event when unset call', () => {
|
||||||
|
const oldValue = propInstance._value;
|
||||||
|
|
||||||
|
propInstance.unset();
|
||||||
|
|
||||||
|
const expectedPartialPropsInfo = expect.objectContaining({
|
||||||
|
key: propInstance.key,
|
||||||
|
newValue: undefined, // You can specifically test only certain keys
|
||||||
|
oldValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(propInstance.getValue()).toEqual(undefined);
|
||||||
|
expect(propInstance.type).toBe('unset');
|
||||||
|
expect(mockEmitChange).toHaveBeenCalledWith({
|
||||||
|
oldValue,
|
||||||
|
newValue: undefined,
|
||||||
|
});
|
||||||
|
expect(mockEventBusEmit).toHaveBeenCalledWith(GlobalEvent.Node.Prop.InnerChange, expectedPartialPropsInfo);
|
||||||
|
expect(mockEmitPropChange).toHaveBeenCalledWith(expectedPartialPropsInfo);
|
||||||
|
|
||||||
|
propInstance.unset();
|
||||||
|
expect(mockEmitChange).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove
|
||||||
|
it('should has event when remove call', () => {
|
||||||
|
const oldValue = propInstance._value;
|
||||||
|
|
||||||
|
propInstance.remove();
|
||||||
|
|
||||||
|
const expectedPartialPropsInfo = expect.objectContaining({
|
||||||
|
key: propInstance.key,
|
||||||
|
newValue: undefined, // You can specifically test only certain keys
|
||||||
|
oldValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(propInstance.getValue()).toEqual(undefined);
|
||||||
|
// expect(propInstance.type).toBe('unset');
|
||||||
|
expect(mockEmitChange).toHaveBeenCalledWith({
|
||||||
|
oldValue,
|
||||||
|
newValue: undefined,
|
||||||
|
});
|
||||||
|
expect(mockEventBusEmit).toHaveBeenCalledWith(GlobalEvent.Node.Prop.InnerChange, expectedPartialPropsInfo);
|
||||||
|
expect(mockEmitPropChange).toHaveBeenCalledWith(expectedPartialPropsInfo);
|
||||||
|
|
||||||
|
propInstance.remove();
|
||||||
|
expect(mockEmitChange).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
9
packages/editor-core/build.test.json
Normal file
9
packages/editor-core/build.test.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"@alilc/build-plugin-lce",
|
||||||
|
"@alilc/lowcode-test-mate/plugin/index.ts"
|
||||||
|
],
|
||||||
|
"babelPlugins": [
|
||||||
|
["@babel/plugin-proposal-private-property-in-object", { "loose": true }]
|
||||||
|
]
|
||||||
|
}
|
||||||
26
packages/editor-core/jest.config.js
Normal file
26
packages/editor-core/jest.config.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const { join } = require('path');
|
||||||
|
const esModules = [].join('|');
|
||||||
|
const pkgNames = fs.readdirSync(join('..')).filter(pkgName => !pkgName.startsWith('.'));
|
||||||
|
|
||||||
|
const jestConfig = {
|
||||||
|
transformIgnorePatterns: [
|
||||||
|
`/node_modules/(?!${esModules})/`,
|
||||||
|
],
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
|
||||||
|
collectCoverage: false,
|
||||||
|
collectCoverageFrom: [
|
||||||
|
'src/**/*.ts',
|
||||||
|
'!src/**/*.d.ts',
|
||||||
|
'!src/icons/**',
|
||||||
|
'!src/locale/**',
|
||||||
|
'!**/node_modules/**',
|
||||||
|
'!**/vendor/**',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// 只对本仓库内的 pkg 做 mapping
|
||||||
|
jestConfig.moduleNameMapper = {};
|
||||||
|
jestConfig.moduleNameMapper[`^@alilc/lowcode\\-(${pkgNames.join('|')})$`] = '<rootDir>/../$1/src';
|
||||||
|
|
||||||
|
module.exports = jestConfig;
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-editor-core",
|
"name": "@alilc/lowcode-editor-core",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Core Api for Ali lowCode engine",
|
"description": "Core Api for Ali lowCode engine",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
@ -10,12 +10,14 @@
|
|||||||
"es"
|
"es"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "build-scripts build"
|
"build": "build-scripts build",
|
||||||
|
"test": "build-scripts test --config build.test.json",
|
||||||
|
"test:cov": "build-scripts test --config build.test.json --jest-coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alifd/next": "^1.19.16",
|
"@alifd/next": "^1.19.16",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"intl-messageformat": "^9.3.1",
|
"intl-messageformat": "^9.3.1",
|
||||||
@ -47,7 +49,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/editor-core"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/editor-core"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
91
packages/editor-core/src/command.ts
Normal file
91
packages/editor-core/src/command.ts
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
import { IPublicApiCommand, IPublicEnumTransitionType, IPublicModelPluginContext, IPublicTypeCommand, IPublicTypeCommandHandlerArgs, IPublicTypeListCommand } from '@alilc/lowcode-types';
|
||||||
|
import { checkPropTypes } from '@alilc/lowcode-utils';
|
||||||
|
export interface ICommand extends Omit<IPublicApiCommand, 'registerCommand' | 'batchExecuteCommand'> {
|
||||||
|
registerCommand(command: IPublicTypeCommand, options?: {
|
||||||
|
commandScope?: string;
|
||||||
|
}): void;
|
||||||
|
|
||||||
|
batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[], pluginContext?: IPublicModelPluginContext): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ICommandOptions {
|
||||||
|
commandScope?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Command implements ICommand {
|
||||||
|
private commands: Map<string, IPublicTypeCommand> = new Map();
|
||||||
|
private commandErrors: Function[] = [];
|
||||||
|
|
||||||
|
registerCommand(command: IPublicTypeCommand, options?: ICommandOptions): void {
|
||||||
|
if (!options?.commandScope) {
|
||||||
|
throw new Error('plugin meta.commandScope is required.');
|
||||||
|
}
|
||||||
|
const name = `${options.commandScope}:${command.name}`;
|
||||||
|
if (this.commands.has(name)) {
|
||||||
|
throw new Error(`Command '${command.name}' is already registered.`);
|
||||||
|
}
|
||||||
|
this.commands.set(name, {
|
||||||
|
...command,
|
||||||
|
name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
unregisterCommand(name: string): void {
|
||||||
|
if (!this.commands.has(name)) {
|
||||||
|
throw new Error(`Command '${name}' is not registered.`);
|
||||||
|
}
|
||||||
|
this.commands.delete(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void {
|
||||||
|
const command = this.commands.get(name);
|
||||||
|
if (!command) {
|
||||||
|
throw new Error(`Command '${name}' is not registered.`);
|
||||||
|
}
|
||||||
|
command.parameters?.forEach(d => {
|
||||||
|
if (!checkPropTypes(args[d.name], d.name, d.propType, 'command')) {
|
||||||
|
throw new Error(`Command '${name}' arguments ${d.name} is invalid.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
command.handler(args);
|
||||||
|
} catch (error) {
|
||||||
|
if (this.commandErrors && this.commandErrors.length) {
|
||||||
|
this.commandErrors.forEach(callback => callback(name, error));
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[], pluginContext: IPublicModelPluginContext): void {
|
||||||
|
if (!commands || !commands.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pluginContext.common.utils.executeTransaction(() => {
|
||||||
|
commands.forEach(command => this.executeCommand(command.name, command.args));
|
||||||
|
}, IPublicEnumTransitionType.REPAINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
listCommands(): IPublicTypeListCommand[] {
|
||||||
|
return Array.from(this.commands.values()).map(d => {
|
||||||
|
const result: IPublicTypeListCommand = {
|
||||||
|
name: d.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (d.description) {
|
||||||
|
result.description = d.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (d.parameters) {
|
||||||
|
result.parameters = d.parameters;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommandError(callback: (name: string, error: Error) => void): void {
|
||||||
|
this.commandErrors.push(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import { ReactNode } from 'react';
|
import { ReactNode } from 'react';
|
||||||
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
import { IPublicApiSetters, IPublicModelSettingField, IPublicTypeCustomView, IPublicTypeRegisteredSetter } from '@alilc/lowcode-types';
|
||||||
import { createContent, isCustomView } from '@alilc/lowcode-utils';
|
import { createContent, isCustomView } from '@alilc/lowcode-utils';
|
||||||
|
|
||||||
const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
const settersMap = new Map<string, IPublicTypeRegisteredSetter & {
|
||||||
@ -28,7 +28,7 @@ export function registerSetter(
|
|||||||
if (!setter.initialValue) {
|
if (!setter.initialValue) {
|
||||||
const initial = getInitialFromSetter(setter.component);
|
const initial = getInitialFromSetter(setter.component);
|
||||||
if (initial) {
|
if (initial) {
|
||||||
setter.initialValue = (field: any) => {
|
setter.initialValue = (field: IPublicModelSettingField) => {
|
||||||
return initial.call(field, field.getValue());
|
return initial.call(field, field.getValue());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ export class Setters implements ISetters {
|
|||||||
if (!setter.initialValue) {
|
if (!setter.initialValue) {
|
||||||
const initial = getInitialFromSetter(setter.component);
|
const initial = getInitialFromSetter(setter.component);
|
||||||
if (initial) {
|
if (initial) {
|
||||||
setter.initialValue = (field: any) => {
|
setter.initialValue = (field: IPublicModelSettingField) => {
|
||||||
return initial.call(field, field.getValue());
|
return initial.call(field, field.getValue());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,3 +6,4 @@ export * from './hotkey';
|
|||||||
export * from './widgets';
|
export * from './widgets';
|
||||||
export * from './config';
|
export * from './config';
|
||||||
export * from './event-bus';
|
export * from './event-bus';
|
||||||
|
export * from './command';
|
||||||
|
|||||||
326
packages/editor-core/test/command.test.ts
Normal file
326
packages/editor-core/test/command.test.ts
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
import { Command } from '../src/command';
|
||||||
|
|
||||||
|
describe('Command', () => {
|
||||||
|
let commandInstance;
|
||||||
|
let mockHandler;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
commandInstance = new Command();
|
||||||
|
mockHandler = jest.fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('registerCommand', () => {
|
||||||
|
it('should register a command successfully', () => {
|
||||||
|
const command = {
|
||||||
|
name: 'testCommand',
|
||||||
|
handler: mockHandler,
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command, { commandScope: 'testScope' });
|
||||||
|
|
||||||
|
const registeredCommand = commandInstance.listCommands().find(c => c.name === 'testScope:testCommand');
|
||||||
|
expect(registeredCommand).toBeDefined();
|
||||||
|
expect(registeredCommand.name).toBe('testScope:testCommand');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if commandScope is not provided', () => {
|
||||||
|
const command = {
|
||||||
|
name: 'testCommand',
|
||||||
|
handler: mockHandler,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.registerCommand(command);
|
||||||
|
}).toThrow('plugin meta.commandScope is required.');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if command is already registered', () => {
|
||||||
|
const command = {
|
||||||
|
name: 'testCommand',
|
||||||
|
handler: mockHandler,
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command, { commandScope: 'testScope' });
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.registerCommand(command, { commandScope: 'testScope' });
|
||||||
|
}).toThrow(`Command 'testCommand' is already registered.`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('unregisterCommand', () => {
|
||||||
|
let commandInstance;
|
||||||
|
let mockHandler;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
commandInstance = new Command();
|
||||||
|
mockHandler = jest.fn();
|
||||||
|
// 先注册一个命令以便之后注销
|
||||||
|
const command = {
|
||||||
|
name: 'testCommand',
|
||||||
|
handler: mockHandler,
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command, { commandScope: 'testScope' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should unregister a command successfully', () => {
|
||||||
|
const commandName = 'testScope:testCommand';
|
||||||
|
expect(commandInstance.listCommands().find(c => c.name === commandName)).toBeDefined();
|
||||||
|
|
||||||
|
commandInstance.unregisterCommand(commandName);
|
||||||
|
|
||||||
|
expect(commandInstance.listCommands().find(c => c.name === commandName)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if the command is not registered', () => {
|
||||||
|
const nonExistingCommandName = 'testScope:nonExistingCommand';
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.unregisterCommand(nonExistingCommandName);
|
||||||
|
}).toThrow(`Command '${nonExistingCommandName}' is not registered.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('executeCommand', () => {
|
||||||
|
let commandInstance;
|
||||||
|
let mockHandler;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
commandInstance = new Command();
|
||||||
|
mockHandler = jest.fn();
|
||||||
|
// 注册一个带参数校验的命令
|
||||||
|
const command = {
|
||||||
|
name: 'testCommand',
|
||||||
|
handler: mockHandler,
|
||||||
|
parameters: [
|
||||||
|
{ name: 'param1', propType: 'string' },
|
||||||
|
{ name: 'param2', propType: 'number' }
|
||||||
|
],
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command, { commandScope: 'testScope' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should execute a command successfully', () => {
|
||||||
|
const commandName = 'testScope:testCommand';
|
||||||
|
const args = { param1: 'test', param2: 42 };
|
||||||
|
|
||||||
|
commandInstance.executeCommand(commandName, args);
|
||||||
|
|
||||||
|
expect(mockHandler).toHaveBeenCalledWith(args);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if the command is not registered', () => {
|
||||||
|
const nonExistingCommandName = 'testScope:nonExistingCommand';
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.executeCommand(nonExistingCommandName, {});
|
||||||
|
}).toThrow(`Command '${nonExistingCommandName}' is not registered.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if arguments are invalid', () => {
|
||||||
|
const commandName = 'testScope:testCommand';
|
||||||
|
const invalidArgs = { param1: 'test', param2: 'not-a-number' }; // param2 should be a number
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.executeCommand(commandName, invalidArgs);
|
||||||
|
}).toThrow(`Command '${commandName}' arguments param2 is invalid.`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle errors thrown by the command handler', () => {
|
||||||
|
const commandName = 'testScope:testCommand';
|
||||||
|
const args = { param1: 'test', param2: 42 };
|
||||||
|
const errorMessage = 'Command handler error';
|
||||||
|
mockHandler.mockImplementation(() => {
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.executeCommand(commandName, args);
|
||||||
|
}).toThrow(errorMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('batchExecuteCommand', () => {
|
||||||
|
let commandInstance;
|
||||||
|
let mockHandler;
|
||||||
|
let mockExecuteTransaction;
|
||||||
|
let mockPluginContext;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
commandInstance = new Command();
|
||||||
|
mockHandler = jest.fn();
|
||||||
|
mockExecuteTransaction = jest.fn(callback => callback());
|
||||||
|
mockPluginContext = {
|
||||||
|
common: {
|
||||||
|
utils: {
|
||||||
|
executeTransaction: mockExecuteTransaction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 注册几个命令
|
||||||
|
const command1 = {
|
||||||
|
name: 'testCommand1',
|
||||||
|
handler: mockHandler,
|
||||||
|
};
|
||||||
|
const command2 = {
|
||||||
|
name: 'testCommand2',
|
||||||
|
handler: mockHandler,
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command1, { commandScope: 'testScope' });
|
||||||
|
commandInstance.registerCommand(command2, { commandScope: 'testScope' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should execute a batch of commands', () => {
|
||||||
|
const commands = [
|
||||||
|
{ name: 'testScope:testCommand1', args: { param: 'value1' } },
|
||||||
|
{ name: 'testScope:testCommand2', args: { param: 'value2' } },
|
||||||
|
];
|
||||||
|
|
||||||
|
commandInstance.batchExecuteCommand(commands, mockPluginContext);
|
||||||
|
|
||||||
|
expect(mockExecuteTransaction).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockHandler).toHaveBeenCalledWith({ param: 'value1' });
|
||||||
|
expect(mockHandler).toHaveBeenCalledWith({ param: 'value2' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not execute anything if commands array is empty', () => {
|
||||||
|
commandInstance.batchExecuteCommand([], mockPluginContext);
|
||||||
|
|
||||||
|
expect(mockExecuteTransaction).not.toHaveBeenCalled();
|
||||||
|
expect(mockHandler).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle errors thrown during command execution', () => {
|
||||||
|
const errorMessage = 'Command handler error';
|
||||||
|
mockHandler.mockImplementation(() => {
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
const commands = [
|
||||||
|
{ name: 'testScope:testCommand1', args: { param: 'value1' } },
|
||||||
|
{ name: 'testScope:testCommand2', args: { param: 'value2' } },
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.batchExecuteCommand(commands, mockPluginContext);
|
||||||
|
}).toThrow(errorMessage);
|
||||||
|
|
||||||
|
expect(mockExecuteTransaction).toHaveBeenCalledTimes(1); // Still called once
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('listCommands', () => {
|
||||||
|
let commandInstance;
|
||||||
|
let mockHandler;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
commandInstance = new Command();
|
||||||
|
mockHandler = jest.fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should list all registered commands', () => {
|
||||||
|
// 注册几个命令
|
||||||
|
const command1 = {
|
||||||
|
name: 'testCommand1',
|
||||||
|
handler: mockHandler,
|
||||||
|
description: 'Test Command 1',
|
||||||
|
parameters: [{ name: 'param1', propType: 'string' }]
|
||||||
|
};
|
||||||
|
const command2 = {
|
||||||
|
name: 'testCommand2',
|
||||||
|
handler: mockHandler,
|
||||||
|
description: 'Test Command 2',
|
||||||
|
parameters: [{ name: 'param2', propType: 'number' }]
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command1, { commandScope: 'testScope' });
|
||||||
|
commandInstance.registerCommand(command2, { commandScope: 'testScope' });
|
||||||
|
|
||||||
|
const listedCommands = commandInstance.listCommands();
|
||||||
|
|
||||||
|
expect(listedCommands.length).toBe(2);
|
||||||
|
expect(listedCommands).toEqual(expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
name: 'testScope:testCommand1',
|
||||||
|
description: 'Test Command 1',
|
||||||
|
parameters: [{ name: 'param1', propType: 'string' }]
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
name: 'testScope:testCommand2',
|
||||||
|
description: 'Test Command 2',
|
||||||
|
parameters: [{ name: 'param2', propType: 'number' }]
|
||||||
|
})
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return an empty array if no commands are registered', () => {
|
||||||
|
const listedCommands = commandInstance.listCommands();
|
||||||
|
expect(listedCommands).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onCommandError', () => {
|
||||||
|
let commandInstance;
|
||||||
|
let mockHandler;
|
||||||
|
let mockErrorHandler1;
|
||||||
|
let mockErrorHandler2;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
commandInstance = new Command();
|
||||||
|
mockHandler = jest.fn();
|
||||||
|
mockErrorHandler1 = jest.fn();
|
||||||
|
mockErrorHandler2 = jest.fn();
|
||||||
|
|
||||||
|
// 注册一个命令,该命令会抛出错误
|
||||||
|
const command = {
|
||||||
|
name: 'testCommand',
|
||||||
|
handler: () => {
|
||||||
|
throw new Error('Command execution failed');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
commandInstance.registerCommand(command, { commandScope: 'testScope' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call all registered error handlers when a command throws an error', () => {
|
||||||
|
const commandName = 'testScope:testCommand';
|
||||||
|
commandInstance.onCommandError(mockErrorHandler1);
|
||||||
|
commandInstance.onCommandError(mockErrorHandler2);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.executeCommand(commandName, {});
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
// 确保所有错误处理函数都被调用,并且传递了正确的参数
|
||||||
|
expect(mockErrorHandler1).toHaveBeenCalledWith(commandName, expect.any(Error));
|
||||||
|
expect(mockErrorHandler2).toHaveBeenCalledWith(commandName, expect.any(Error));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw the error if no error handlers are registered', () => {
|
||||||
|
const commandName = 'testScope:testCommand';
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
commandInstance.executeCommand(commandName, {});
|
||||||
|
}).toThrow('Command execution failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-editor-skeleton",
|
"name": "@alilc/lowcode-editor-skeleton",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "alibaba lowcode editor skeleton",
|
"description": "alibaba lowcode editor skeleton",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
@ -19,10 +19,10 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alifd/next": "^1.20.12",
|
"@alifd/next": "^1.20.12",
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@alilc/lowcode-editor-core": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-core": "1.3.2",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"react": "^16.8.1",
|
"react": "^16.8.1",
|
||||||
"react-dom": "^16.8.1"
|
"react-dom": "^16.8.1"
|
||||||
@ -42,7 +42,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/editor-skeleton"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/editor-skeleton"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -225,7 +225,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
|
|
||||||
const value = this.value;
|
const value = this.value;
|
||||||
|
|
||||||
let _onChange = extraProps?.onChange;
|
let onChangeAPI = extraProps?.onChange;
|
||||||
let stageName = this.stageName;
|
let stageName = this.stageName;
|
||||||
|
|
||||||
return createField(
|
return createField(
|
||||||
@ -261,7 +261,7 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
|
|||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
field.setValue(value, true);
|
field.setValue(value, true);
|
||||||
if (_onChange) _onChange(value, field);
|
if (onChangeAPI) onChangeAPI(value, field.internalToShellField());
|
||||||
},
|
},
|
||||||
onInitial: () => {
|
onInitial: () => {
|
||||||
if (initialValue == null) {
|
if (initialValue == null) {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import {
|
|||||||
IPublicTypeTransformedComponentMetadata,
|
IPublicTypeTransformedComponentMetadata,
|
||||||
IPublicTypeOneOfType,
|
IPublicTypeOneOfType,
|
||||||
ConfigureSupportEvent,
|
ConfigureSupportEvent,
|
||||||
|
IPublicModelSettingField,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
|
|
||||||
function propConfigToFieldConfig(propConfig: IPublicTypePropConfig): IPublicTypeFieldConfig {
|
function propConfigToFieldConfig(propConfig: IPublicTypePropConfig): IPublicTypeFieldConfig {
|
||||||
@ -102,7 +103,7 @@ function propTypeToSetter(propType: IPublicTypePropType): IPublicTypeSetterType
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
isRequired,
|
isRequired,
|
||||||
initialValue: (field: any) => {
|
initialValue: (field: IPublicModelSettingField) => {
|
||||||
const data: any = {};
|
const data: any = {};
|
||||||
items.forEach((item: any) => {
|
items.forEach((item: any) => {
|
||||||
let initial = item.defaultValue;
|
let initial = item.defaultValue;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-engine",
|
"name": "@alilc/lowcode-engine",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "An enterprise-class low-code technology stack with scale-out design / 一套面向扩展设计的企业级低代码技术体系",
|
"description": "An enterprise-class low-code technology stack with scale-out design / 一套面向扩展设计的企业级低代码技术体系",
|
||||||
"main": "lib/engine-core.js",
|
"main": "lib/engine-core.js",
|
||||||
"module": "es/engine-core.js",
|
"module": "es/engine-core.js",
|
||||||
@ -19,15 +19,16 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alifd/next": "^1.19.12",
|
"@alifd/next": "^1.19.12",
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@alilc/lowcode-editor-core": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-core": "1.3.2",
|
||||||
"@alilc/lowcode-editor-skeleton": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-skeleton": "1.3.2",
|
||||||
"@alilc/lowcode-engine-ext": "^1.0.0",
|
"@alilc/lowcode-engine-ext": "^1.0.0",
|
||||||
"@alilc/lowcode-plugin-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-plugin-command": "1.3.2",
|
||||||
"@alilc/lowcode-plugin-outline-pane": "1.3.1-beta.1",
|
"@alilc/lowcode-plugin-designer": "1.3.2",
|
||||||
"@alilc/lowcode-shell": "1.3.1-beta.1",
|
"@alilc/lowcode-plugin-outline-pane": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-shell": "1.3.2",
|
||||||
"@alilc/lowcode-workspace": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
|
"@alilc/lowcode-workspace": "1.3.2",
|
||||||
"react": "^16.8.1",
|
"react": "^16.8.1",
|
||||||
"react-dom": "^16.8.1"
|
"react-dom": "^16.8.1"
|
||||||
},
|
},
|
||||||
@ -53,7 +54,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/engine"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/engine"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import {
|
|||||||
Setters as InnerSetters,
|
Setters as InnerSetters,
|
||||||
Hotkey as InnerHotkey,
|
Hotkey as InnerHotkey,
|
||||||
IEditor,
|
IEditor,
|
||||||
|
Command as InnerCommand,
|
||||||
} from '@alilc/lowcode-editor-core';
|
} from '@alilc/lowcode-editor-core';
|
||||||
import {
|
import {
|
||||||
IPublicTypeEngineOptions,
|
IPublicTypeEngineOptions,
|
||||||
@ -19,6 +20,7 @@ import {
|
|||||||
IPublicApiPlugins,
|
IPublicApiPlugins,
|
||||||
IPublicApiWorkspace,
|
IPublicApiWorkspace,
|
||||||
IPublicEnumPluginRegisterLevel,
|
IPublicEnumPluginRegisterLevel,
|
||||||
|
IPublicModelPluginContext,
|
||||||
} from '@alilc/lowcode-types';
|
} from '@alilc/lowcode-types';
|
||||||
import {
|
import {
|
||||||
Designer,
|
Designer,
|
||||||
@ -52,6 +54,7 @@ import {
|
|||||||
Workspace,
|
Workspace,
|
||||||
Config,
|
Config,
|
||||||
CommonUI,
|
CommonUI,
|
||||||
|
Command,
|
||||||
} from '@alilc/lowcode-shell';
|
} from '@alilc/lowcode-shell';
|
||||||
import { isPlainObject } from '@alilc/lowcode-utils';
|
import { isPlainObject } from '@alilc/lowcode-utils';
|
||||||
import './modules/live-editing';
|
import './modules/live-editing';
|
||||||
@ -63,6 +66,7 @@ import { defaultPanelRegistry } from './inner-plugins/default-panel-registry';
|
|||||||
import { shellModelFactory } from './modules/shell-model-factory';
|
import { shellModelFactory } from './modules/shell-model-factory';
|
||||||
import { builtinHotkey } from './inner-plugins/builtin-hotkey';
|
import { builtinHotkey } from './inner-plugins/builtin-hotkey';
|
||||||
import { defaultContextMenu } from './inner-plugins/default-context-menu';
|
import { defaultContextMenu } from './inner-plugins/default-context-menu';
|
||||||
|
import { CommandPlugin } from '@alilc/lowcode-plugin-command';
|
||||||
import { OutlinePlugin } from '@alilc/lowcode-plugin-outline-pane';
|
import { OutlinePlugin } from '@alilc/lowcode-plugin-outline-pane';
|
||||||
|
|
||||||
export * from './modules/skeleton-types';
|
export * from './modules/skeleton-types';
|
||||||
@ -80,6 +84,7 @@ async function registryInnerPlugin(designer: IDesigner, editor: IEditor, plugins
|
|||||||
await plugins.register(builtinHotkey);
|
await plugins.register(builtinHotkey);
|
||||||
await plugins.register(registerDefaults, {}, { autoInit: true });
|
await plugins.register(registerDefaults, {}, { autoInit: true });
|
||||||
await plugins.register(defaultContextMenu);
|
await plugins.register(defaultContextMenu);
|
||||||
|
await plugins.register(CommandPlugin, {});
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
plugins.delete(OutlinePlugin.pluginName);
|
plugins.delete(OutlinePlugin.pluginName);
|
||||||
@ -89,6 +94,7 @@ async function registryInnerPlugin(designer: IDesigner, editor: IEditor, plugins
|
|||||||
plugins.delete(builtinHotkey.pluginName);
|
plugins.delete(builtinHotkey.pluginName);
|
||||||
plugins.delete(registerDefaults.pluginName);
|
plugins.delete(registerDefaults.pluginName);
|
||||||
plugins.delete(defaultContextMenu.pluginName);
|
plugins.delete(defaultContextMenu.pluginName);
|
||||||
|
plugins.delete(CommandPlugin.pluginName);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,6 +105,8 @@ globalContext.register(editor, Editor);
|
|||||||
globalContext.register(editor, 'editor');
|
globalContext.register(editor, 'editor');
|
||||||
globalContext.register(innerWorkspace, 'workspace');
|
globalContext.register(innerWorkspace, 'workspace');
|
||||||
|
|
||||||
|
const engineContext: Partial<ILowCodePluginContextPrivate> = {};
|
||||||
|
|
||||||
const innerSkeleton = new InnerSkeleton(editor);
|
const innerSkeleton = new InnerSkeleton(editor);
|
||||||
editor.set('skeleton' as any, innerSkeleton);
|
editor.set('skeleton' as any, innerSkeleton);
|
||||||
|
|
||||||
@ -113,6 +121,8 @@ const project = new Project(innerProject);
|
|||||||
const skeleton = new Skeleton(innerSkeleton, 'any', false);
|
const skeleton = new Skeleton(innerSkeleton, 'any', false);
|
||||||
const innerSetters = new InnerSetters();
|
const innerSetters = new InnerSetters();
|
||||||
const setters = new Setters(innerSetters);
|
const setters = new Setters(innerSetters);
|
||||||
|
const innerCommand = new InnerCommand();
|
||||||
|
const command = new Command(innerCommand, engineContext as IPublicModelPluginContext);
|
||||||
|
|
||||||
const material = new Material(editor);
|
const material = new Material(editor);
|
||||||
const commonUI = new CommonUI(editor);
|
const commonUI = new CommonUI(editor);
|
||||||
@ -136,6 +146,7 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
|||||||
context.setters = setters;
|
context.setters = setters;
|
||||||
context.material = material;
|
context.material = material;
|
||||||
const eventPrefix = meta?.eventPrefix || 'common';
|
const eventPrefix = meta?.eventPrefix || 'common';
|
||||||
|
const commandScope = meta?.commandScope;
|
||||||
context.event = new Event(commonEvent, { prefix: eventPrefix });
|
context.event = new Event(commonEvent, { prefix: eventPrefix });
|
||||||
context.config = config;
|
context.config = config;
|
||||||
context.common = common;
|
context.common = common;
|
||||||
@ -144,6 +155,9 @@ const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = {
|
|||||||
context.logger = new Logger({ level: 'warn', bizName: `plugin:${pluginName}` });
|
context.logger = new Logger({ level: 'warn', bizName: `plugin:${pluginName}` });
|
||||||
context.workspace = workspace;
|
context.workspace = workspace;
|
||||||
context.commonUI = commonUI;
|
context.commonUI = commonUI;
|
||||||
|
context.command = new Command(innerCommand, context as IPublicModelPluginContext, {
|
||||||
|
commandScope,
|
||||||
|
});
|
||||||
context.registerLevel = IPublicEnumPluginRegisterLevel.Default;
|
context.registerLevel = IPublicEnumPluginRegisterLevel.Default;
|
||||||
context.isPluginRegisteredInWorkspace = false;
|
context.isPluginRegisteredInWorkspace = false;
|
||||||
editor.set('pluginContext', context);
|
editor.set('pluginContext', context);
|
||||||
@ -155,6 +169,20 @@ plugins = new Plugins(innerPlugins).toProxy();
|
|||||||
editor.set('innerPlugins' as any, innerPlugins);
|
editor.set('innerPlugins' as any, innerPlugins);
|
||||||
editor.set('plugins' as any, plugins);
|
editor.set('plugins' as any, plugins);
|
||||||
|
|
||||||
|
engineContext.skeleton = skeleton;
|
||||||
|
engineContext.plugins = plugins;
|
||||||
|
engineContext.project = project;
|
||||||
|
engineContext.setters = setters;
|
||||||
|
engineContext.material = material;
|
||||||
|
engineContext.event = event;
|
||||||
|
engineContext.logger = logger;
|
||||||
|
engineContext.hotkey = hotkey;
|
||||||
|
engineContext.common = common;
|
||||||
|
engineContext.workspace = workspace;
|
||||||
|
engineContext.canvas = canvas;
|
||||||
|
engineContext.commonUI = commonUI;
|
||||||
|
engineContext.command = command;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
skeleton,
|
skeleton,
|
||||||
plugins,
|
plugins,
|
||||||
@ -169,6 +197,7 @@ export {
|
|||||||
workspace,
|
workspace,
|
||||||
canvas,
|
canvas,
|
||||||
commonUI,
|
commonUI,
|
||||||
|
command,
|
||||||
};
|
};
|
||||||
// declare this is open-source version
|
// declare this is open-source version
|
||||||
export const isOpenSource = true;
|
export const isOpenSource = true;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-ignitor",
|
"name": "@alilc/lowcode-ignitor",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "点火器,bootstrap lce project",
|
"description": "点火器,bootstrap lce project",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
11
packages/plugin-command/README.md
Normal file
11
packages/plugin-command/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# `@alilc/plugin-command`
|
||||||
|
|
||||||
|
> TODO: description
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
const pluginCommand = require('@alilc/plugin-command');
|
||||||
|
|
||||||
|
// TODO: DEMONSTRATE API
|
||||||
|
```
|
||||||
110
packages/plugin-command/__tests__/node-command.test.ts
Normal file
110
packages/plugin-command/__tests__/node-command.test.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { checkPropTypes } from '@alilc/lowcode-utils/src/check-prop-types';
|
||||||
|
import { nodeSchemaPropType } from '../src/node-command';
|
||||||
|
|
||||||
|
describe('nodeSchemaPropType', () => {
|
||||||
|
const componentName = 'NodeComponent';
|
||||||
|
const getPropType = (name: string) => nodeSchemaPropType.value.find(d => d.name === name)?.propType;
|
||||||
|
|
||||||
|
it('should validate the id as a string', () => {
|
||||||
|
const validId = 'node1';
|
||||||
|
const invalidId = 123; // Not a string
|
||||||
|
expect(checkPropTypes(validId, 'id', getPropType('id'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidId, 'id', getPropType('id'), componentName)).toBe(false);
|
||||||
|
// is not required
|
||||||
|
expect(checkPropTypes(undefined, 'id', getPropType('id'), componentName)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the componentName as a string', () => {
|
||||||
|
const validComponentName = 'Button';
|
||||||
|
const invalidComponentName = false; // Not a string
|
||||||
|
expect(checkPropTypes(validComponentName, 'componentName', getPropType('componentName'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidComponentName, 'componentName', getPropType('componentName'), componentName)).toBe(false);
|
||||||
|
// isRequired
|
||||||
|
expect(checkPropTypes(undefined, 'componentName', getPropType('componentName'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the props as an object', () => {
|
||||||
|
const validProps = { key: 'value' };
|
||||||
|
const invalidProps = 'Not an object'; // Not an object
|
||||||
|
expect(checkPropTypes(validProps, 'props', getPropType('props'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidProps, 'props', getPropType('props'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the props as a JSExpression', () => {
|
||||||
|
const validProps = { type: 'JSExpression', value: 'props' };
|
||||||
|
expect(checkPropTypes(validProps, 'props', getPropType('props'), componentName)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the props as a JSFunction', () => {
|
||||||
|
const validProps = { type: 'JSFunction', value: 'props' };
|
||||||
|
expect(checkPropTypes(validProps, 'props', getPropType('props'), componentName)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the props as a JSSlot', () => {
|
||||||
|
const validProps = { type: 'JSSlot', value: 'props' };
|
||||||
|
expect(checkPropTypes(validProps, 'props', getPropType('props'), componentName)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the condition as a bool', () => {
|
||||||
|
const validCondition = true;
|
||||||
|
const invalidCondition = 'Not a bool'; // Not a boolean
|
||||||
|
expect(checkPropTypes(validCondition, 'condition', getPropType('condition'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidCondition, 'condition', getPropType('condition'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the condition as a JSExpression', () => {
|
||||||
|
const validCondition = { type: 'JSExpression', value: '1 + 1 === 2' };
|
||||||
|
const invalidCondition = { type: 'JSExpression', value: 123 }; // Not a string
|
||||||
|
expect(checkPropTypes(validCondition, 'condition', getPropType('condition'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidCondition, 'condition', getPropType('condition'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the loop as an array', () => {
|
||||||
|
const validLoop = ['item1', 'item2'];
|
||||||
|
const invalidLoop = 'Not an array'; // Not an array
|
||||||
|
expect(checkPropTypes(validLoop, 'loop', getPropType('loop'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidLoop, 'loop', getPropType('loop'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the loop as a JSExpression', () => {
|
||||||
|
const validLoop = { type: 'JSExpression', value: 'items' };
|
||||||
|
const invalidLoop = { type: 'JSExpression', value: 123 }; // Not a string
|
||||||
|
expect(checkPropTypes(validLoop, 'loop', getPropType('loop'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidLoop, 'loop', getPropType('loop'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the loopArgs as an array', () => {
|
||||||
|
const validLoopArgs = ['item'];
|
||||||
|
const invalidLoopArgs = 'Not an array'; // Not an array
|
||||||
|
expect(checkPropTypes(validLoopArgs, 'loopArgs', getPropType('loopArgs'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidLoopArgs, 'loopArgs', getPropType('loopArgs'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the loopArgs as a JSExpression', () => {
|
||||||
|
const validLoopArgs = { type: 'JSExpression', value: 'item' };
|
||||||
|
const invalidLoopArgs = { type: 'JSExpression', value: 123 }; // Not a string
|
||||||
|
const validLoopArgs2 = [{ type: 'JSExpression', value: 'item' }, { type: 'JSExpression', value: 'index' }];
|
||||||
|
expect(checkPropTypes(validLoopArgs, 'loopArgs', getPropType('loopArgs'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidLoopArgs, 'loopArgs', getPropType('loopArgs'), componentName)).toBe(false);
|
||||||
|
expect(checkPropTypes(validLoopArgs2, 'loopArgs', getPropType('loopArgs'), componentName)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate the children as an array', () => {
|
||||||
|
const validChildren = [{
|
||||||
|
id: 'child1',
|
||||||
|
componentName: 'Button',
|
||||||
|
}, {
|
||||||
|
id: 'child2',
|
||||||
|
componentName: 'Button',
|
||||||
|
}];
|
||||||
|
const invalidChildren = 'Not an array'; // Not an array
|
||||||
|
const invalidChildren2 = [{}]; // Not an valid array
|
||||||
|
expect(checkPropTypes(invalidChildren, 'children', getPropType('children'), componentName)).toBe(false);
|
||||||
|
expect(checkPropTypes(validChildren, 'children', getPropType('children'), componentName)).toBe(true);
|
||||||
|
expect(checkPropTypes(invalidChildren2, 'children', getPropType('children'), componentName)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
});
|
||||||
9
packages/plugin-command/build.json
Normal file
9
packages/plugin-command/build.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"@alilc/build-plugin-lce",
|
||||||
|
"build-plugin-fusion",
|
||||||
|
["build-plugin-moment-locales", {
|
||||||
|
"locales": ["zh-cn"]
|
||||||
|
}]
|
||||||
|
]
|
||||||
|
}
|
||||||
19
packages/plugin-command/build.test.json
Normal file
19
packages/plugin-command/build.test.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"@alilc/build-plugin-lce",
|
||||||
|
{
|
||||||
|
"filename": "editor-preset-vision",
|
||||||
|
"library": "LowcodeEditor",
|
||||||
|
"libraryTarget": "umd",
|
||||||
|
"externals": {
|
||||||
|
"react": "var window.React",
|
||||||
|
"react-dom": "var window.ReactDOM",
|
||||||
|
"prop-types": "var window.PropTypes",
|
||||||
|
"rax": "var window.Rax"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@alilc/lowcode-test-mate/plugin/index.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
22
packages/plugin-command/jest.config.js
Normal file
22
packages/plugin-command/jest.config.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const { join } = require('path');
|
||||||
|
const esModules = [].join('|');
|
||||||
|
const pkgNames = fs.readdirSync(join('..')).filter(pkgName => !pkgName.startsWith('.'));
|
||||||
|
|
||||||
|
const jestConfig = {
|
||||||
|
transformIgnorePatterns: [
|
||||||
|
`/node_modules/(?!${esModules})/`,
|
||||||
|
],
|
||||||
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
|
||||||
|
collectCoverage: true,
|
||||||
|
collectCoverageFrom: [
|
||||||
|
'src/**/*.ts',
|
||||||
|
'src/**/*.tsx',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// 只对本仓库内的 pkg 做 mapping
|
||||||
|
jestConfig.moduleNameMapper = {};
|
||||||
|
jestConfig.moduleNameMapper[`^@alilc/lowcode\\-(${pkgNames.join('|')})$`] = '<rootDir>/../$1/src';
|
||||||
|
|
||||||
|
module.exports = jestConfig;
|
||||||
39
packages/plugin-command/package.json
Normal file
39
packages/plugin-command/package.json
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "@alilc/lowcode-plugin-command",
|
||||||
|
"version": "1.3.2",
|
||||||
|
"description": "> TODO: description",
|
||||||
|
"author": "liujuping <liujup@foxmail.com>",
|
||||||
|
"homepage": "https://github.com/alibaba/lowcode-engine#readme",
|
||||||
|
"license": "ISC",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"module": "es/index.js",
|
||||||
|
"directories": {
|
||||||
|
"lib": "lib",
|
||||||
|
"test": "__tests__"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"es"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/alibaba/lowcode-engine.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "build-scripts test --config build.test.json --jest-passWithNoTests",
|
||||||
|
"build": "build-scripts build"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/alibaba/lowcode-engine/issues"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
|
"@alilc/lowcode-utils": "1.3.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@alib/build-scripts": "^0.1.18"
|
||||||
|
}
|
||||||
|
}
|
||||||
43
packages/plugin-command/src/history-command.ts
Normal file
43
packages/plugin-command/src/history-command.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { IPublicModelPluginContext, IPublicTypePlugin } from '@alilc/lowcode-types';
|
||||||
|
|
||||||
|
export const historyCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => {
|
||||||
|
const { command, project } = ctx;
|
||||||
|
return {
|
||||||
|
init() {
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'undo',
|
||||||
|
description: 'Undo the last operation.',
|
||||||
|
handler: () => {
|
||||||
|
const state = project.currentDocument?.history.getState() || 0;
|
||||||
|
const enable = !!(state & 1);
|
||||||
|
if (!enable) {
|
||||||
|
throw new Error('Can not undo.');
|
||||||
|
}
|
||||||
|
project.currentDocument?.history.back();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'redo',
|
||||||
|
description: 'Redo the last operation.',
|
||||||
|
handler: () => {
|
||||||
|
const state = project.currentDocument?.history.getState() || 0;
|
||||||
|
const enable = !!(state & 2);
|
||||||
|
if (!enable) {
|
||||||
|
throw new Error('Can not redo.');
|
||||||
|
}
|
||||||
|
project.currentDocument?.history.forward();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
destroy() {
|
||||||
|
command.unregisterCommand('history:undo');
|
||||||
|
command.unregisterCommand('history:redo');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
historyCommand.pluginName = '___history_command___';
|
||||||
|
historyCommand.meta = {
|
||||||
|
commandScope: 'history',
|
||||||
|
};
|
||||||
25
packages/plugin-command/src/index.ts
Normal file
25
packages/plugin-command/src/index.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { IPublicModelPluginContext, IPublicTypePlugin } from '@alilc/lowcode-types';
|
||||||
|
import { nodeCommand } from './node-command';
|
||||||
|
import { historyCommand } from './history-command';
|
||||||
|
|
||||||
|
export const CommandPlugin: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => {
|
||||||
|
const { plugins } = ctx;
|
||||||
|
|
||||||
|
return {
|
||||||
|
async init() {
|
||||||
|
await plugins.register(nodeCommand, {}, { autoInit: true });
|
||||||
|
await plugins.register(historyCommand, {}, { autoInit: true });
|
||||||
|
},
|
||||||
|
destroy() {
|
||||||
|
plugins.delete(nodeCommand.pluginName);
|
||||||
|
plugins.delete(historyCommand.pluginName);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
CommandPlugin.pluginName = '___default_command___';
|
||||||
|
CommandPlugin.meta = {
|
||||||
|
commandScope: 'common',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CommandPlugin;
|
||||||
497
packages/plugin-command/src/node-command.ts
Normal file
497
packages/plugin-command/src/node-command.ts
Normal file
@ -0,0 +1,497 @@
|
|||||||
|
import { IPublicModelPluginContext, IPublicTypeNodeSchema, IPublicTypePlugin, IPublicTypePropType } from '@alilc/lowcode-types';
|
||||||
|
import { isNodeSchema } from '@alilc/lowcode-utils';
|
||||||
|
|
||||||
|
const sampleNodeSchema: IPublicTypePropType = {
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'id',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'componentName',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'props',
|
||||||
|
propType: 'object',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'condition',
|
||||||
|
propType: 'any',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'loop',
|
||||||
|
propType: 'any',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'loopArgs',
|
||||||
|
propType: 'any',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'children',
|
||||||
|
propType: 'any',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const nodeSchemaPropType: IPublicTypePropType = {
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
sampleNodeSchema.value[0],
|
||||||
|
sampleNodeSchema.value[1],
|
||||||
|
{
|
||||||
|
name: 'props',
|
||||||
|
propType: {
|
||||||
|
type: 'objectOf',
|
||||||
|
value: {
|
||||||
|
type: 'oneOfType',
|
||||||
|
// 不会强制校验,更多作为提示
|
||||||
|
value: [
|
||||||
|
'any',
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSExpression'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSFunction'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSSlot'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: [
|
||||||
|
sampleNodeSchema,
|
||||||
|
{
|
||||||
|
type: 'arrayOf',
|
||||||
|
value: sampleNodeSchema,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'condition',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: [
|
||||||
|
'bool',
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSExpression'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'loop',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: [
|
||||||
|
'array',
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSExpression'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'loopArgs',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
type: 'arrayOf',
|
||||||
|
value: {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: [
|
||||||
|
'any',
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSExpression'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSExpression'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'children',
|
||||||
|
propType: {
|
||||||
|
type: 'arrayOf',
|
||||||
|
value: sampleNodeSchema,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const nodeCommand: IPublicTypePlugin = (ctx: IPublicModelPluginContext) => {
|
||||||
|
const { command, project } = ctx;
|
||||||
|
return {
|
||||||
|
init() {
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'add',
|
||||||
|
description: 'Add a node to the canvas.',
|
||||||
|
handler: (param: {
|
||||||
|
parentNodeId: string;
|
||||||
|
nodeSchema: IPublicTypeNodeSchema;
|
||||||
|
index: number;
|
||||||
|
}) => {
|
||||||
|
const {
|
||||||
|
parentNodeId,
|
||||||
|
nodeSchema,
|
||||||
|
index,
|
||||||
|
} = param;
|
||||||
|
const { project } = ctx;
|
||||||
|
const parentNode = project.currentDocument?.getNodeById(parentNodeId);
|
||||||
|
if (!parentNode) {
|
||||||
|
throw new Error(`Can not find node '${parentNodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!parentNode.isContainerNode) {
|
||||||
|
throw new Error(`Node '${parentNodeId}' is not a container node.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isNodeSchema(nodeSchema)) {
|
||||||
|
throw new Error('Invalid node.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 0 || index > (parentNode.children?.size || 0)) {
|
||||||
|
throw new Error(`Invalid index '${index}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
project.currentDocument?.insertNode(parentNode, nodeSchema, index);
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'parentNodeId',
|
||||||
|
propType: 'string',
|
||||||
|
description: 'The id of the parent node.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'nodeSchema',
|
||||||
|
propType: nodeSchemaPropType,
|
||||||
|
description: 'The node to be added.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'index',
|
||||||
|
propType: 'number',
|
||||||
|
description: 'The index of the node to be added.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'move',
|
||||||
|
description: 'Move a node to another node.',
|
||||||
|
handler(param: {
|
||||||
|
nodeId: string;
|
||||||
|
targetNodeId: string;
|
||||||
|
index: number;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
nodeId,
|
||||||
|
targetNodeId,
|
||||||
|
index = 0,
|
||||||
|
} = param;
|
||||||
|
|
||||||
|
if (!nodeId) {
|
||||||
|
throw new Error('Invalid node id.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetNodeId) {
|
||||||
|
throw new Error('Invalid target node id.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const node = project.currentDocument?.getNodeById(nodeId);
|
||||||
|
const targetNode = project.currentDocument?.getNodeById(targetNodeId);
|
||||||
|
if (!node) {
|
||||||
|
throw new Error(`Can not find node '${nodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetNode) {
|
||||||
|
throw new Error(`Can not find node '${targetNodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!targetNode.isContainerNode) {
|
||||||
|
throw new Error(`Node '${targetNodeId}' is not a container node.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (index < 0 || index > (targetNode.children?.size || 0)) {
|
||||||
|
throw new Error(`Invalid index '${index}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
project.currentDocument?.removeNode(node);
|
||||||
|
project.currentDocument?.insertNode(targetNode, node, index);
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'nodeId',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
description: 'The id of the node to be moved.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'targetNodeId',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
description: 'The id of the target node.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'index',
|
||||||
|
propType: 'number',
|
||||||
|
description: 'The index of the node to be moved.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'remove',
|
||||||
|
description: 'Remove a node from the canvas.',
|
||||||
|
handler(param: {
|
||||||
|
nodeId: string;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
nodeId,
|
||||||
|
} = param;
|
||||||
|
|
||||||
|
const node = project.currentDocument?.getNodeById(nodeId);
|
||||||
|
if (!node) {
|
||||||
|
throw new Error(`Can not find node '${nodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
project.currentDocument?.removeNode(node);
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'nodeId',
|
||||||
|
propType: 'string',
|
||||||
|
description: 'The id of the node to be removed.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'update',
|
||||||
|
description: 'Update a node.',
|
||||||
|
handler(param: {
|
||||||
|
nodeId: string;
|
||||||
|
nodeSchema: IPublicTypeNodeSchema;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
nodeId,
|
||||||
|
nodeSchema,
|
||||||
|
} = param;
|
||||||
|
|
||||||
|
const node = project.currentDocument?.getNodeById(nodeId);
|
||||||
|
if (!node) {
|
||||||
|
throw new Error(`Can not find node '${nodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isNodeSchema(nodeSchema)) {
|
||||||
|
throw new Error('Invalid node.');
|
||||||
|
}
|
||||||
|
|
||||||
|
node.importSchema(nodeSchema);
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'nodeId',
|
||||||
|
propType: 'string',
|
||||||
|
description: 'The id of the node to be updated.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'nodeSchema',
|
||||||
|
propType: nodeSchemaPropType,
|
||||||
|
description: 'The node to be updated.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'updateProps',
|
||||||
|
description: 'Update the properties of a node.',
|
||||||
|
handler(param: {
|
||||||
|
nodeId: string;
|
||||||
|
props: Record<string, any>;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
nodeId,
|
||||||
|
props,
|
||||||
|
} = param;
|
||||||
|
|
||||||
|
const node = project.currentDocument?.getNodeById(nodeId);
|
||||||
|
if (!node) {
|
||||||
|
throw new Error(`Can not find node '${nodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(props).forEach(key => {
|
||||||
|
node.setPropValue(key, props[key]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'nodeId',
|
||||||
|
propType: 'string',
|
||||||
|
description: 'The id of the node to be updated.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'props',
|
||||||
|
propType: 'object',
|
||||||
|
description: 'The properties to be updated.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
command.registerCommand({
|
||||||
|
name: 'removeProps',
|
||||||
|
description: 'Remove the properties of a node.',
|
||||||
|
handler(param: {
|
||||||
|
nodeId: string;
|
||||||
|
propNames: string[];
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
nodeId,
|
||||||
|
propNames,
|
||||||
|
} = param;
|
||||||
|
|
||||||
|
const node = project.currentDocument?.getNodeById(nodeId);
|
||||||
|
if (!node) {
|
||||||
|
throw new Error(`Can not find node '${nodeId}'.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
propNames.forEach(key => {
|
||||||
|
node.props?.getProp(key)?.remove();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
parameters: [
|
||||||
|
{
|
||||||
|
name: 'nodeId',
|
||||||
|
propType: 'string',
|
||||||
|
description: 'The id of the node to be updated.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'propNames',
|
||||||
|
propType: 'array',
|
||||||
|
description: 'The properties to be removed.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
destroy() {
|
||||||
|
command.unregisterCommand('node:add');
|
||||||
|
command.unregisterCommand('node:move');
|
||||||
|
command.unregisterCommand('node:remove');
|
||||||
|
command.unregisterCommand('node:update');
|
||||||
|
command.unregisterCommand('node:updateProps');
|
||||||
|
command.unregisterCommand('node:removeProps');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nodeCommand.pluginName = '___node_command___';
|
||||||
|
nodeCommand.meta = {
|
||||||
|
commandScope: 'node',
|
||||||
|
};
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-plugin-designer",
|
"name": "@alilc/lowcode-plugin-designer",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "alibaba lowcode editor designer plugin",
|
"description": "alibaba lowcode editor designer plugin",
|
||||||
"files": [
|
"files": [
|
||||||
"es",
|
"es",
|
||||||
@ -18,9 +18,9 @@
|
|||||||
],
|
],
|
||||||
"author": "xiayang.xy",
|
"author": "xiayang.xy",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@alilc/lowcode-editor-core": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-core": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"react": "^16.8.1",
|
"react": "^16.8.1",
|
||||||
"react-dom": "^16.8.1"
|
"react-dom": "^16.8.1"
|
||||||
},
|
},
|
||||||
@ -37,7 +37,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/plugin-designer"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/plugin-designer"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-plugin-outline-pane",
|
"name": "@alilc/lowcode-plugin-outline-pane",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Outline pane for Ali lowCode engine",
|
"description": "Outline pane for Ali lowCode engine",
|
||||||
"files": [
|
"files": [
|
||||||
"es",
|
"es",
|
||||||
@ -13,8 +13,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alifd/next": "^1.19.16",
|
"@alifd/next": "^1.19.16",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"react": "^16",
|
"react": "^16",
|
||||||
"react-dom": "^16.7.0",
|
"react-dom": "^16.7.0",
|
||||||
@ -38,7 +38,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/plugin-outline-pane"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/plugin-outline-pane"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-react-renderer",
|
"name": "@alilc/lowcode-react-renderer",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "react renderer for ali lowcode engine",
|
"description": "react renderer for ali lowcode engine",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
@ -22,7 +22,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alifd/next": "^1.21.16",
|
"@alifd/next": "^1.21.16",
|
||||||
"@alilc/lowcode-renderer-core": "1.3.1-beta.1"
|
"@alilc/lowcode-renderer-core": "1.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@alib/build-scripts": "^0.1.18",
|
"@alib/build-scripts": "^0.1.18",
|
||||||
@ -42,6 +42,6 @@
|
|||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/react-renderer"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/react-renderer"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme",
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme",
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues"
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-react-simulator-renderer",
|
"name": "@alilc/lowcode-react-simulator-renderer",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "react simulator renderer for alibaba lowcode designer",
|
"description": "react simulator renderer for alibaba lowcode designer",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
@ -17,10 +17,10 @@
|
|||||||
"test:cov": "build-scripts test --config build.test.json --jest-coverage"
|
"test:cov": "build-scripts test --config build.test.json --jest-coverage"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@alilc/lowcode-react-renderer": "1.3.1-beta.1",
|
"@alilc/lowcode-react-renderer": "1.3.2",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"mobx": "^6.3.0",
|
"mobx": "^6.3.0",
|
||||||
"mobx-react": "^7.2.0",
|
"mobx-react": "^7.2.0",
|
||||||
@ -43,7 +43,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/react-simulator-renderer"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/react-simulator-renderer"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -614,7 +614,7 @@ function getNodeInstance(fiberNode: any, specId?: string): IPublicTypeNodeInstan
|
|||||||
|
|
||||||
function checkInstanceMounted(instance: any): boolean {
|
function checkInstanceMounted(instance: any): boolean {
|
||||||
if (isElement(instance)) {
|
if (isElement(instance)) {
|
||||||
return instance.parentElement != null;
|
return instance.parentElement != null && window.document.contains(instance);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-renderer-core",
|
"name": "@alilc/lowcode-renderer-core",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "renderer core",
|
"description": "renderer core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
@ -16,8 +16,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alilc/lowcode-datasource-engine": "^1.0.0",
|
"@alilc/lowcode-datasource-engine": "^1.0.0",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"debug": "^4.1.1",
|
"debug": "^4.1.1",
|
||||||
"fetch-jsonp": "^1.1.3",
|
"fetch-jsonp": "^1.1.3",
|
||||||
@ -32,7 +32,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@alib/build-scripts": "^0.1.18",
|
"@alib/build-scripts": "^0.1.18",
|
||||||
"@alifd/next": "^1.26.0",
|
"@alifd/next": "^1.26.0",
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@babel/plugin-transform-typescript": "^7.16.8",
|
"@babel/plugin-transform-typescript": "^7.16.8",
|
||||||
"@testing-library/react": "^11.2.2",
|
"@testing-library/react": "^11.2.2",
|
||||||
"@types/classnames": "^2.2.11",
|
"@types/classnames": "^2.2.11",
|
||||||
@ -55,7 +55,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/renderer-core"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/renderer-core"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { create as createDataSourceEngine } from '@alilc/lowcode-datasource-engine/interpret';
|
import { create as createDataSourceEngine } from '@alilc/lowcode-datasource-engine/interpret';
|
||||||
import { IPublicTypeNodeSchema, IPublicTypeNodeData, IPublicTypeJSONValue, IPublicTypeCompositeValue } from '@alilc/lowcode-types';
|
import { IPublicTypeNodeSchema, IPublicTypeNodeData, IPublicTypeJSONValue, IPublicTypeCompositeValue } from '@alilc/lowcode-types';
|
||||||
import { isI18nData, isJSExpression, isJSFunction } from '@alilc/lowcode-utils';
|
import { checkPropTypes, isI18nData, isJSExpression, isJSFunction } from '@alilc/lowcode-utils';
|
||||||
import adapter from '../adapter';
|
import adapter from '../adapter';
|
||||||
import divFactory from '../components/Div';
|
import divFactory from '../components/Div';
|
||||||
import visualDomFactory from '../components/VisualDom';
|
import visualDomFactory from '../components/VisualDom';
|
||||||
@ -21,7 +21,6 @@ import {
|
|||||||
isFileSchema,
|
isFileSchema,
|
||||||
transformArrayToMap,
|
transformArrayToMap,
|
||||||
transformStringToFunction,
|
transformStringToFunction,
|
||||||
checkPropTypes,
|
|
||||||
getI18n,
|
getI18n,
|
||||||
getFileCssName,
|
getFileCssName,
|
||||||
capitalizeFirstLetter,
|
capitalizeFirstLetter,
|
||||||
|
|||||||
@ -6,16 +6,11 @@ import { isI18nData, isJSExpression } from '@alilc/lowcode-utils';
|
|||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import IntlMessageFormat from 'intl-messageformat';
|
import IntlMessageFormat from 'intl-messageformat';
|
||||||
import pkg from '../../package.json';
|
import pkg from '../../package.json';
|
||||||
import * as ReactIs from 'react-is';
|
|
||||||
import { default as ReactPropTypesSecret } from 'prop-types/lib/ReactPropTypesSecret';
|
|
||||||
import { default as factoryWithTypeCheckers } from 'prop-types/factoryWithTypeCheckers';
|
|
||||||
|
|
||||||
(window as any).sdkVersion = pkg.version;
|
(window as any).sdkVersion = pkg.version;
|
||||||
|
|
||||||
export { pick, isEqualWith as deepEqual, cloneDeep as clone, isEmpty, throttle, debounce } from 'lodash';
|
export { pick, isEqualWith as deepEqual, cloneDeep as clone, isEmpty, throttle, debounce } from 'lodash';
|
||||||
|
|
||||||
const PropTypes2 = factoryWithTypeCheckers(ReactIs.isElement, true);
|
|
||||||
|
|
||||||
const EXPRESSION_TYPE = {
|
const EXPRESSION_TYPE = {
|
||||||
JSEXPRESSION: 'JSExpression',
|
JSEXPRESSION: 'JSExpression',
|
||||||
JSFUNCTION: 'JSFunction',
|
JSFUNCTION: 'JSFunction',
|
||||||
@ -183,31 +178,6 @@ export function transformArrayToMap(arr: any[], key: string, overwrite = true) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkPropTypes(value: any, name: string, rule: any, componentName: string): boolean {
|
|
||||||
let ruleFunction = rule;
|
|
||||||
if (typeof rule === 'string') {
|
|
||||||
ruleFunction = new Function(`"use strict"; const PropTypes = arguments[0]; return ${rule}`)(PropTypes2);
|
|
||||||
}
|
|
||||||
if (!ruleFunction || typeof ruleFunction !== 'function') {
|
|
||||||
logger.warn('checkPropTypes should have a function type rule argument');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
const err = ruleFunction(
|
|
||||||
{
|
|
||||||
[name]: value,
|
|
||||||
},
|
|
||||||
name,
|
|
||||||
componentName,
|
|
||||||
'prop',
|
|
||||||
null,
|
|
||||||
ReactPropTypesSecret,
|
|
||||||
);
|
|
||||||
if (err) {
|
|
||||||
logger.warn(err);
|
|
||||||
}
|
|
||||||
return !err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* transform string to a function
|
* transform string to a function
|
||||||
* @param str function in string form
|
* @param str function in string form
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import factoryWithTypeCheckers from 'prop-types/factoryWithTypeCheckers';
|
|
||||||
import {
|
import {
|
||||||
isSchema,
|
isSchema,
|
||||||
isFileSchema,
|
isFileSchema,
|
||||||
@ -18,14 +17,9 @@ import {
|
|||||||
parseThisRequiredExpression,
|
parseThisRequiredExpression,
|
||||||
parseI18n,
|
parseI18n,
|
||||||
parseData,
|
parseData,
|
||||||
checkPropTypes,
|
|
||||||
} from '../../src/utils/common';
|
} from '../../src/utils/common';
|
||||||
import logger from '../../src/utils/logger';
|
import logger from '../../src/utils/logger';
|
||||||
|
|
||||||
var ReactIs = require('react-is');
|
|
||||||
|
|
||||||
const PropTypes = factoryWithTypeCheckers(ReactIs.isElement, true);
|
|
||||||
|
|
||||||
describe('test isSchema', () => {
|
describe('test isSchema', () => {
|
||||||
it('should be false when empty value is passed', () => {
|
it('should be false when empty value is passed', () => {
|
||||||
expect(isSchema(null)).toBeFalsy();
|
expect(isSchema(null)).toBeFalsy();
|
||||||
@ -467,36 +461,3 @@ describe('test parseData ', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('checkPropTypes', () => {
|
|
||||||
it('should validate correctly with valid prop type', () => {
|
|
||||||
expect(checkPropTypes(123, 'age', PropTypes.number, 'TestComponent')).toBe(true);
|
|
||||||
expect(checkPropTypes('123', 'age', PropTypes.string, 'TestComponent')).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should log a warning and return false with invalid prop type', () => {
|
|
||||||
expect(checkPropTypes(123, 'age', PropTypes.string, 'TestComponent')).toBe(false);
|
|
||||||
expect(checkPropTypes('123', 'age', PropTypes.number, 'TestComponent')).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle custom rule functions correctly', () => {
|
|
||||||
const customRule = (props, propName) => {
|
|
||||||
if (props[propName] !== 123) {
|
|
||||||
return new Error('Invalid value');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const result = checkPropTypes(123, 'customProp', customRule, 'TestComponent');
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
it('should interpret and validate a rule given as a string', () => {
|
|
||||||
const result = checkPropTypes(123, 'age', 'PropTypes.number', 'TestComponent');
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should log a warning for invalid rule type', () => {
|
|
||||||
const result = checkPropTypes(123, 'age', 123, 'TestComponent');
|
|
||||||
expect(result).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-shell",
|
"name": "@alilc/lowcode-shell",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Shell Layer for AliLowCodeEngine",
|
"description": "Shell Layer for AliLowCodeEngine",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
@ -13,12 +13,12 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@alilc/lowcode-editor-core": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-core": "1.3.2",
|
||||||
"@alilc/lowcode-editor-skeleton": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-skeleton": "1.3.2",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"@alilc/lowcode-workspace": "1.3.1-beta.1",
|
"@alilc/lowcode-workspace": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"enzyme": "^3.11.0",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.5",
|
"enzyme-adapter-react-16": "^1.15.5",
|
||||||
@ -48,7 +48,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/shell"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/shell"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
46
packages/shell/src/api/command.ts
Normal file
46
packages/shell/src/api/command.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { IPublicApiCommand, IPublicModelPluginContext, IPublicTypeCommand, IPublicTypeCommandHandlerArgs, IPublicTypeListCommand } from '@alilc/lowcode-types';
|
||||||
|
import { commandSymbol, pluginContextSymbol } from '../symbols';
|
||||||
|
import { ICommand, ICommandOptions } from '@alilc/lowcode-editor-core';
|
||||||
|
|
||||||
|
const optionsSymbol = Symbol('options');
|
||||||
|
const commandScopeSet = new Set<string>();
|
||||||
|
|
||||||
|
export class Command implements IPublicApiCommand {
|
||||||
|
[commandSymbol]: ICommand;
|
||||||
|
[optionsSymbol]?: ICommandOptions;
|
||||||
|
[pluginContextSymbol]?: IPublicModelPluginContext;
|
||||||
|
|
||||||
|
constructor(innerCommand: ICommand, pluginContext?: IPublicModelPluginContext, options?: ICommandOptions) {
|
||||||
|
this[commandSymbol] = innerCommand;
|
||||||
|
this[optionsSymbol] = options;
|
||||||
|
this[pluginContextSymbol] = pluginContext;
|
||||||
|
const commandScope = options?.commandScope;
|
||||||
|
if (commandScope && commandScopeSet.has(commandScope)) {
|
||||||
|
throw new Error(`Command scope "${commandScope}" has been registered.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCommand(command: IPublicTypeCommand): void {
|
||||||
|
this[commandSymbol].registerCommand(command, this[optionsSymbol]);
|
||||||
|
}
|
||||||
|
|
||||||
|
batchExecuteCommand(commands: { name: string; args: IPublicTypeCommandHandlerArgs }[]): void {
|
||||||
|
this[commandSymbol].batchExecuteCommand(commands, this[pluginContextSymbol]);
|
||||||
|
}
|
||||||
|
|
||||||
|
executeCommand(name: string, args: IPublicTypeCommandHandlerArgs): void {
|
||||||
|
this[commandSymbol].executeCommand(name, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
listCommands(): IPublicTypeListCommand[] {
|
||||||
|
return this[commandSymbol].listCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
unregisterCommand(name: string): void {
|
||||||
|
this[commandSymbol].unregisterCommand(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
onCommandError(callback: (name: string, error: Error) => void): void {
|
||||||
|
this[commandSymbol].onCommandError(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ import {
|
|||||||
import { Balloon, Breadcrumb, Button, Card, Checkbox, DatePicker, Dialog, Dropdown, Form, Icon, Input, Loading, Message, Overlay, Pagination, Radio, Search, Select, SplitButton, Step, Switch, Tab, Table, Tree, TreeSelect, Upload, Divider } from '@alifd/next';
|
import { Balloon, Breadcrumb, Button, Card, Checkbox, DatePicker, Dialog, Dropdown, Form, Icon, Input, Loading, Message, Overlay, Pagination, Radio, Search, Select, SplitButton, Step, Switch, Tab, Table, Tree, TreeSelect, Upload, Divider } from '@alifd/next';
|
||||||
import { ContextMenu } from '../components/context-menu';
|
import { ContextMenu } from '../components/context-menu';
|
||||||
import { editorSymbol } from '../symbols';
|
import { editorSymbol } from '../symbols';
|
||||||
|
import { ReactElement } from 'react';
|
||||||
|
|
||||||
export class CommonUI implements IPublicApiCommonUI {
|
export class CommonUI implements IPublicApiCommonUI {
|
||||||
[editorSymbol]: IEditor;
|
[editorSymbol]: IEditor;
|
||||||
@ -23,7 +24,7 @@ export class CommonUI implements IPublicApiCommonUI {
|
|||||||
Form = Form;
|
Form = Form;
|
||||||
Icon = Icon;
|
Icon = Icon;
|
||||||
Input = Input;
|
Input = Input;
|
||||||
Loading = Loading;
|
Loading = Loading as any;
|
||||||
Message = Message;
|
Message = Message;
|
||||||
Overlay = Overlay;
|
Overlay = Overlay;
|
||||||
Pagination = Pagination;
|
Pagination = Pagination;
|
||||||
@ -40,8 +41,27 @@ export class CommonUI implements IPublicApiCommonUI {
|
|||||||
Upload = Upload;
|
Upload = Upload;
|
||||||
Divider = Divider;
|
Divider = Divider;
|
||||||
|
|
||||||
|
ContextMenu: ((props: {
|
||||||
|
menus: IPublicTypeContextMenuAction[];
|
||||||
|
children: React.ReactElement[] | React.ReactElement;
|
||||||
|
}) => ReactElement) & {
|
||||||
|
create(menus: IPublicTypeContextMenuAction[], event: MouseEvent | React.MouseEvent): void;
|
||||||
|
};
|
||||||
|
|
||||||
constructor(editor: IEditor) {
|
constructor(editor: IEditor) {
|
||||||
this[editorSymbol] = editor;
|
this[editorSymbol] = editor;
|
||||||
|
|
||||||
|
const innerContextMenu = (props: any) => {
|
||||||
|
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
|
||||||
|
return <ContextMenu {...props} pluginContext={pluginContext} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
innerContextMenu.create = (menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
|
||||||
|
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
|
||||||
|
return ContextMenu.create(pluginContext, menus, event);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ContextMenu = innerContextMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
get Tip() {
|
get Tip() {
|
||||||
@ -55,19 +75,4 @@ export class CommonUI implements IPublicApiCommonUI {
|
|||||||
get Title() {
|
get Title() {
|
||||||
return InnerTitle;
|
return InnerTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
get ContextMenu() {
|
|
||||||
const editor = this[editorSymbol];
|
|
||||||
const innerContextMenu = (props: any) => {
|
|
||||||
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
|
|
||||||
return <ContextMenu {...props} pluginContext={pluginContext} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
innerContextMenu.create = (menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
|
|
||||||
const pluginContext: IPublicModelPluginContext = editor.get('pluginContext') as IPublicModelPluginContext;
|
|
||||||
return ContextMenu.create(pluginContext, menus, event);
|
|
||||||
};
|
|
||||||
|
|
||||||
return innerContextMenu;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,3 +12,4 @@ export * from './canvas';
|
|||||||
export * from './workspace';
|
export * from './workspace';
|
||||||
export * from './config';
|
export * from './config';
|
||||||
export * from './commonUI';
|
export * from './commonUI';
|
||||||
|
export * from './command';
|
||||||
@ -3,7 +3,7 @@ import {
|
|||||||
IDesigner,
|
IDesigner,
|
||||||
isComponentMeta,
|
isComponentMeta,
|
||||||
} from '@alilc/lowcode-designer';
|
} from '@alilc/lowcode-designer';
|
||||||
import { IPublicTypeAssetsJson } from '@alilc/lowcode-utils';
|
import { IPublicTypeAssetsJson, getLogger } from '@alilc/lowcode-utils';
|
||||||
import {
|
import {
|
||||||
IPublicTypeComponentAction,
|
IPublicTypeComponentAction,
|
||||||
IPublicTypeComponentMetadata,
|
IPublicTypeComponentMetadata,
|
||||||
@ -21,6 +21,8 @@ import { editorSymbol, designerSymbol } from '../symbols';
|
|||||||
import { ComponentMeta as ShellComponentMeta } from '../model';
|
import { ComponentMeta as ShellComponentMeta } from '../model';
|
||||||
import { ComponentType } from 'react';
|
import { ComponentType } from 'react';
|
||||||
|
|
||||||
|
const logger = getLogger({ level: 'warn', bizName: 'shell-material' });
|
||||||
|
|
||||||
const innerEditorSymbol = Symbol('editor');
|
const innerEditorSymbol = Symbol('editor');
|
||||||
export class Material implements IPublicApiMaterial {
|
export class Material implements IPublicApiMaterial {
|
||||||
private readonly [innerEditorSymbol]: IPublicModelEditor;
|
private readonly [innerEditorSymbol]: IPublicModelEditor;
|
||||||
@ -31,6 +33,10 @@ export class Material implements IPublicApiMaterial {
|
|||||||
}
|
}
|
||||||
const workspace: InnerWorkspace = globalContext.get('workspace');
|
const workspace: InnerWorkspace = globalContext.get('workspace');
|
||||||
if (workspace.isActive) {
|
if (workspace.isActive) {
|
||||||
|
if (!workspace.window.editor) {
|
||||||
|
logger.error('Material api 调用时机出现问题,请检查');
|
||||||
|
return this[innerEditorSymbol];
|
||||||
|
}
|
||||||
return workspace.window.editor;
|
return workspace.window.editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -90,7 +90,7 @@ export class Workspace implements IPublicApiWorkspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get plugins() {
|
get plugins() {
|
||||||
return new Plugins(this[workspaceSymbol].plugins, true);
|
return new Plugins(this[workspaceSymbol].plugins, true).toProxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
get skeleton() {
|
get skeleton() {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ export function ContextMenu({ children, menus, pluginContext }: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!menus || !menus.length) {
|
if (!menus) {
|
||||||
return (
|
return (
|
||||||
<>{ children }</>
|
<>{ children }</>
|
||||||
);
|
);
|
||||||
@ -53,6 +53,9 @@ export function ContextMenu({ children, menus, pluginContext }: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ContextMenu.create = (pluginContext: IPublicModelPluginContext, menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
|
ContextMenu.create = (pluginContext: IPublicModelPluginContext, menus: IPublicTypeContextMenuAction[], event: MouseEvent) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
const children: React.ReactNode[] = parseContextMenuAsReactNode(parseContextMenuProperties(menus, {
|
const children: React.ReactNode[] = parseContextMenuAsReactNode(parseContextMenuProperties(menus, {
|
||||||
pluginContext,
|
pluginContext,
|
||||||
}), {
|
}), {
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import {
|
|||||||
SimulatorHost,
|
SimulatorHost,
|
||||||
Config,
|
Config,
|
||||||
CommonUI,
|
CommonUI,
|
||||||
|
Command,
|
||||||
} from './api';
|
} from './api';
|
||||||
|
|
||||||
export * from './symbols';
|
export * from './symbols';
|
||||||
@ -70,4 +71,5 @@ export {
|
|||||||
SettingField,
|
SettingField,
|
||||||
SkeletonItem,
|
SkeletonItem,
|
||||||
CommonUI,
|
CommonUI,
|
||||||
|
Command,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -48,8 +48,8 @@ export class Window implements IPublicModelWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get currentEditorView() {
|
get currentEditorView() {
|
||||||
if (this[windowSymbol].editorView) {
|
if (this[windowSymbol]._editorView) {
|
||||||
return new EditorView(this[windowSymbol].editorView).toProxy() as any;
|
return new EditorView(this[windowSymbol]._editorView).toProxy() as any;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,3 +40,4 @@ export const conditionGroupSymbol = Symbol('conditionGroup');
|
|||||||
export const editorViewSymbol = Symbol('editorView');
|
export const editorViewSymbol = Symbol('editorView');
|
||||||
export const pluginContextSymbol = Symbol('pluginContext');
|
export const pluginContextSymbol = Symbol('pluginContext');
|
||||||
export const skeletonItemSymbol = Symbol('skeletonItem');
|
export const skeletonItemSymbol = Symbol('skeletonItem');
|
||||||
|
export const commandSymbol = Symbol('command');
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-types",
|
"name": "@alilc/lowcode-types",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Types for Ali lowCode engine",
|
"description": "Types for Ali lowCode engine",
|
||||||
"files": [
|
"files": [
|
||||||
"es",
|
"es",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/types"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/types"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
34
packages/types/src/shell/api/command.ts
Normal file
34
packages/types/src/shell/api/command.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import { IPublicTypeCommand, IPublicTypeCommandHandlerArgs, IPublicTypeListCommand } from '../type';
|
||||||
|
|
||||||
|
export interface IPublicApiCommand {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册一个新命令及其处理函数
|
||||||
|
*/
|
||||||
|
registerCommand(command: IPublicTypeCommand): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注销一个已存在的命令
|
||||||
|
*/
|
||||||
|
unregisterCommand(name: string): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过名称和给定参数执行一个命令,会校验参数是否符合命令定义
|
||||||
|
*/
|
||||||
|
executeCommand(name: string, args?: IPublicTypeCommandHandlerArgs): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量执行命令,执行完所有命令后再进行一次重绘,历史记录中只会记录一次
|
||||||
|
*/
|
||||||
|
batchExecuteCommand(commands: { name: string; args?: IPublicTypeCommandHandlerArgs }[]): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列出所有已注册的命令
|
||||||
|
*/
|
||||||
|
listCommands(): IPublicTypeListCommand[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册错误处理回调函数
|
||||||
|
*/
|
||||||
|
onCommandError(callback: (name: string, error: Error) => void): void;
|
||||||
|
}
|
||||||
@ -11,3 +11,4 @@ export * from './logger';
|
|||||||
export * from './canvas';
|
export * from './canvas';
|
||||||
export * from './workspace';
|
export * from './workspace';
|
||||||
export * from './commonUI';
|
export * from './commonUI';
|
||||||
|
export * from './command';
|
||||||
@ -1,8 +1,9 @@
|
|||||||
import { IPublicModelWindow } from '../model';
|
import { IPublicModelWindow } from '../model';
|
||||||
import { IPublicApiPlugins, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
|
import { IPublicApiPlugins, IPublicApiSkeleton, IPublicModelResource, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType } from '@alilc/lowcode-types';
|
||||||
|
|
||||||
export interface IPublicApiWorkspace<
|
export interface IPublicApiWorkspace<
|
||||||
Plugins = IPublicApiPlugins,
|
Plugins = IPublicApiPlugins,
|
||||||
|
Skeleton = IPublicApiSkeleton,
|
||||||
ModelWindow = IPublicModelWindow,
|
ModelWindow = IPublicModelWindow,
|
||||||
Resource = IPublicModelResource,
|
Resource = IPublicModelResource,
|
||||||
> {
|
> {
|
||||||
@ -15,6 +16,8 @@ export interface IPublicApiWorkspace<
|
|||||||
|
|
||||||
plugins: Plugins;
|
plugins: Plugins;
|
||||||
|
|
||||||
|
skeleton: Skeleton;
|
||||||
|
|
||||||
/** 当前设计器的编辑窗口 */
|
/** 当前设计器的编辑窗口 */
|
||||||
windows: ModelWindow[];
|
windows: ModelWindow[];
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
IPublicApiPlugins,
|
IPublicApiPlugins,
|
||||||
IPublicApiWorkspace,
|
IPublicApiWorkspace,
|
||||||
IPublicApiCommonUI,
|
IPublicApiCommonUI,
|
||||||
|
IPublicApiCommand,
|
||||||
} from '../api';
|
} from '../api';
|
||||||
import { IPublicEnumPluginRegisterLevel } from '../enum';
|
import { IPublicEnumPluginRegisterLevel } from '../enum';
|
||||||
import { IPublicModelEngineConfig, IPublicModelWindow } from './';
|
import { IPublicModelEngineConfig, IPublicModelWindow } from './';
|
||||||
@ -109,6 +110,8 @@ export interface IPublicModelPluginContext {
|
|||||||
*/
|
*/
|
||||||
get commonUI(): IPublicApiCommonUI;
|
get commonUI(): IPublicApiCommonUI;
|
||||||
|
|
||||||
|
get command(): IPublicApiCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插件注册层级
|
* 插件注册层级
|
||||||
* @since v1.1.7
|
* @since v1.1.7
|
||||||
|
|||||||
59
packages/types/src/shell/type/command.ts
Normal file
59
packages/types/src/shell/type/command.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import { IPublicTypePropType } from './prop-types';
|
||||||
|
|
||||||
|
// 定义命令处理函数的参数类型
|
||||||
|
export interface IPublicTypeCommandHandlerArgs {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义命令参数的接口
|
||||||
|
export interface IPublicTypeCommandParameter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数名称
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数类型或详细类型描述
|
||||||
|
*/
|
||||||
|
propType: string | IPublicTypePropType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数描述
|
||||||
|
*/
|
||||||
|
description: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数默认值(可选)
|
||||||
|
*/
|
||||||
|
defaultValue?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定义单个命令的接口
|
||||||
|
export interface IPublicTypeCommand {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命令名称
|
||||||
|
* 命名规则:commandName
|
||||||
|
* 使用规则:commandScope:commandName (commandScope 在插件 meta 中定义,用于区分不同插件的命令)
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命令参数
|
||||||
|
*/
|
||||||
|
parameters?: IPublicTypeCommandParameter[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命令描述
|
||||||
|
*/
|
||||||
|
description?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命令处理函数
|
||||||
|
*/
|
||||||
|
handler: (args: any) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPublicTypeListCommand extends Pick<IPublicTypeCommand, 'name' | 'description' | 'parameters'> {
|
||||||
|
}
|
||||||
@ -77,5 +77,5 @@ export interface IPublicTypeFieldExtraProps {
|
|||||||
/**
|
/**
|
||||||
* onChange 事件
|
* onChange 事件
|
||||||
*/
|
*/
|
||||||
onChange?: (value: any, field: any) => void;
|
onChange?: (value: any, field: IPublicModelSettingField) => void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -93,3 +93,4 @@ export * from './scrollable';
|
|||||||
export * from './simulator-renderer';
|
export * from './simulator-renderer';
|
||||||
export * from './config-transducer';
|
export * from './config-transducer';
|
||||||
export * from './context-menu';
|
export * from './context-menu';
|
||||||
|
export * from './command';
|
||||||
@ -1,14 +1,17 @@
|
|||||||
import { IPublicTypePluginDeclaration } from './';
|
import { IPublicTypePluginDeclaration } from './';
|
||||||
|
|
||||||
export interface IPublicTypePluginMeta {
|
export interface IPublicTypePluginMeta {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define dependencies which the plugin depends on
|
* define dependencies which the plugin depends on
|
||||||
*/
|
*/
|
||||||
dependencies?: string[];
|
dependencies?: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* specify which engine version is compatible with the plugin
|
* specify which engine version is compatible with the plugin
|
||||||
*/
|
*/
|
||||||
engines?: {
|
engines?: {
|
||||||
|
|
||||||
/** e.g. '^1.0.0' */
|
/** e.g. '^1.0.0' */
|
||||||
lowcodeEngine?: string;
|
lowcodeEngine?: string;
|
||||||
};
|
};
|
||||||
@ -26,4 +29,9 @@ export interface IPublicTypePluginMeta {
|
|||||||
* event.emit('someEventName') is actually sending event with name 'myEvent:someEventName'
|
* event.emit('someEventName') is actually sending event with name 'myEvent:someEventName'
|
||||||
*/
|
*/
|
||||||
eventPrefix?: string;
|
eventPrefix?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果要使用 command 注册命令,需要在插件 meta 中定义 commandScope
|
||||||
|
*/
|
||||||
|
commandScope?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,20 @@
|
|||||||
|
import { IPublicModelSettingField } from '../model';
|
||||||
import { IPublicTypeCustomView, IPublicTypeTitleContent } from './';
|
import { IPublicTypeCustomView, IPublicTypeTitleContent } from './';
|
||||||
|
|
||||||
export interface IPublicTypeRegisteredSetter {
|
export interface IPublicTypeRegisteredSetter {
|
||||||
component: IPublicTypeCustomView;
|
component: IPublicTypeCustomView;
|
||||||
defaultProps?: object;
|
defaultProps?: object;
|
||||||
title?: IPublicTypeTitleContent;
|
title?: IPublicTypeTitleContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for MixedSetter to check this setter if available
|
* for MixedSetter to check this setter if available
|
||||||
*/
|
*/
|
||||||
condition?: (field: any) => boolean;
|
condition?: (field: IPublicModelSettingField) => boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for MixedSetter to manual change to this setter
|
* for MixedSetter to manual change to this setter
|
||||||
*/
|
*/
|
||||||
initialValue?: any | ((field: any) => any);
|
initialValue?: any | ((field: IPublicModelSettingField) => any);
|
||||||
recommend?: boolean;
|
recommend?: boolean;
|
||||||
// 标识是否为动态 setter,默认为 true
|
// 标识是否为动态 setter,默认为 true
|
||||||
isDynamic?: boolean;
|
isDynamic?: boolean;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-utils",
|
"name": "@alilc/lowcode-utils",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Utils for Ali lowCode engine",
|
"description": "Utils for Ali lowCode engine",
|
||||||
"files": [
|
"files": [
|
||||||
"lib",
|
"lib",
|
||||||
@ -14,9 +14,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alifd/next": "^1.19.16",
|
"@alifd/next": "^1.19.16",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mobx": "^6.3.0",
|
"mobx": "^6.3.0",
|
||||||
|
"prop-types": "^15.8.1",
|
||||||
"react": "^16"
|
"react": "^16"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -35,7 +36,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/utils"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/utils"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
72
packages/utils/src/check-prop-types.ts
Normal file
72
packages/utils/src/check-prop-types.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import * as ReactIs from 'react-is';
|
||||||
|
import { default as ReactPropTypesSecret } from 'prop-types/lib/ReactPropTypesSecret';
|
||||||
|
import { default as factoryWithTypeCheckers } from 'prop-types/factoryWithTypeCheckers';
|
||||||
|
import { IPublicTypePropType } from '@alilc/lowcode-types';
|
||||||
|
import { isRequiredPropType } from './check-types/is-required-prop-type';
|
||||||
|
import { Logger } from './logger';
|
||||||
|
|
||||||
|
const PropTypes2 = factoryWithTypeCheckers(ReactIs.isElement, true);
|
||||||
|
const logger = new Logger({ level: 'warn', bizName: 'utils' });
|
||||||
|
|
||||||
|
export function transformPropTypesRuleToString(rule: IPublicTypePropType | string): string {
|
||||||
|
if (!rule) {
|
||||||
|
return 'PropTypes.any';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof rule === 'string') {
|
||||||
|
return rule.startsWith('PropTypes.') ? rule : `PropTypes.${rule}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isRequiredPropType(rule)) {
|
||||||
|
const { type, isRequired } = rule;
|
||||||
|
return `PropTypes.${type}${isRequired ? '.isRequired' : ''}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { type, value } = rule;
|
||||||
|
switch (type) {
|
||||||
|
case 'oneOf':
|
||||||
|
return `PropTypes.oneOf([${value.map((item: any) => `"${item}"`).join(',')}])`;
|
||||||
|
case 'oneOfType':
|
||||||
|
return `PropTypes.oneOfType([${value.map((item: any) => transformPropTypesRuleToString(item)).join(', ')}])`;
|
||||||
|
case 'arrayOf':
|
||||||
|
case 'objectOf':
|
||||||
|
return `PropTypes.${type}(${transformPropTypesRuleToString(value)})`;
|
||||||
|
case 'shape':
|
||||||
|
case 'exact':
|
||||||
|
return `PropTypes.${type}({${value.map((item: any) => `${item.name}: ${transformPropTypesRuleToString(item.propType)}`).join(',')}})`;
|
||||||
|
default:
|
||||||
|
logger.error(`Unknown prop type: ${type}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'PropTypes.any';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function checkPropTypes(value: any, name: string, rule: any, componentName: string): boolean {
|
||||||
|
let ruleFunction = rule;
|
||||||
|
if (typeof rule === 'object') {
|
||||||
|
// eslint-disable-next-line no-new-func
|
||||||
|
ruleFunction = new Function(`"use strict"; const PropTypes = arguments[0]; return ${transformPropTypesRuleToString(rule)}`)(PropTypes2);
|
||||||
|
}
|
||||||
|
if (typeof rule === 'string') {
|
||||||
|
// eslint-disable-next-line no-new-func
|
||||||
|
ruleFunction = new Function(`"use strict"; const PropTypes = arguments[0]; return ${transformPropTypesRuleToString(rule)}`)(PropTypes2);
|
||||||
|
}
|
||||||
|
if (!ruleFunction || typeof ruleFunction !== 'function') {
|
||||||
|
logger.warn('checkPropTypes should have a function type rule argument');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const err = ruleFunction(
|
||||||
|
{
|
||||||
|
[name]: value,
|
||||||
|
},
|
||||||
|
name,
|
||||||
|
componentName,
|
||||||
|
'prop',
|
||||||
|
null,
|
||||||
|
ReactPropTypesSecret,
|
||||||
|
);
|
||||||
|
if (err) {
|
||||||
|
logger.warn(err);
|
||||||
|
}
|
||||||
|
return !err;
|
||||||
|
}
|
||||||
@ -24,3 +24,5 @@ export * from './is-setting-field';
|
|||||||
export * from './is-lowcode-component-type';
|
export * from './is-lowcode-component-type';
|
||||||
export * from './is-lowcode-project-schema';
|
export * from './is-lowcode-project-schema';
|
||||||
export * from './is-component-schema';
|
export * from './is-component-schema';
|
||||||
|
export * from './is-basic-prop-type';
|
||||||
|
export * from './is-required-prop-type';
|
||||||
8
packages/utils/src/check-types/is-basic-prop-type.ts
Normal file
8
packages/utils/src/check-types/is-basic-prop-type.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { IPublicTypeBasicType, IPublicTypePropType } from '@alilc/lowcode-types';
|
||||||
|
|
||||||
|
export function isBasicPropType(propType: IPublicTypePropType): propType is IPublicTypeBasicType {
|
||||||
|
if (!propType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return typeof propType === 'string';
|
||||||
|
}
|
||||||
8
packages/utils/src/check-types/is-required-prop-type.ts
Normal file
8
packages/utils/src/check-types/is-required-prop-type.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { IPublicTypePropType, IPublicTypeRequiredType } from '@alilc/lowcode-types';
|
||||||
|
|
||||||
|
export function isRequiredPropType(propType: IPublicTypePropType): propType is IPublicTypeRequiredType {
|
||||||
|
if (!propType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return typeof propType === 'object' && propType.type && ['array', 'bool', 'func', 'number', 'object', 'string', 'node', 'element', 'any'].includes(propType.type);
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@ import classNames from 'classnames';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import './context-menu.scss';
|
import './context-menu.scss';
|
||||||
|
|
||||||
const logger = new Logger({ level: 'warn', bizName: 'designer' });
|
const logger = new Logger({ level: 'warn', bizName: 'utils' });
|
||||||
const { Item, Divider, PopupItem } = Menu;
|
const { Item, Divider, PopupItem } = Menu;
|
||||||
|
|
||||||
const MAX_LEVEL = 2;
|
const MAX_LEVEL = 2;
|
||||||
|
|||||||
@ -32,3 +32,4 @@ export { transactionManager } from './transaction-manager';
|
|||||||
export * from './check-types';
|
export * from './check-types';
|
||||||
export * from './workspace';
|
export * from './workspace';
|
||||||
export * from './context-menu';
|
export * from './context-menu';
|
||||||
|
export { checkPropTypes } from './check-prop-types';
|
||||||
255
packages/utils/test/src/check-prop-types.test.ts
Normal file
255
packages/utils/test/src/check-prop-types.test.ts
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
import { checkPropTypes, transformPropTypesRuleToString } from '../../src/check-prop-types';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
describe('checkPropTypes', () => {
|
||||||
|
it('should validate correctly with valid prop type', () => {
|
||||||
|
expect(checkPropTypes(123, 'age', PropTypes.number, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes('123', 'age', PropTypes.string, 'TestComponent')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should log a warning and return false with invalid prop type', () => {
|
||||||
|
expect(checkPropTypes(123, 'age', PropTypes.string, 'TestComponent')).toBe(false);
|
||||||
|
expect(checkPropTypes('123', 'age', PropTypes.number, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate correctly with valid object prop type', () => {
|
||||||
|
expect(checkPropTypes({ a: 123 }, 'age', PropTypes.object, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ a: '123' }, 'age', PropTypes.object, 'TestComponent')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate correctly with valid object string prop type', () => {
|
||||||
|
expect(checkPropTypes({ a: 123 }, 'age', 'object', 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ a: '123' }, 'age', 'object', 'TestComponent')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate correctly with valid isRequired prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.string.isRequired');
|
||||||
|
expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes(undefined, 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle custom rule functions correctly', () => {
|
||||||
|
const customRule = (props, propName) => {
|
||||||
|
if (props[propName] !== 123) {
|
||||||
|
return new Error('Invalid value');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const result = checkPropTypes(123, 'customProp', customRule, 'TestComponent');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should interpret and validate a rule given as a string', () => {
|
||||||
|
const result = checkPropTypes(123, 'age', 'PropTypes.number', 'TestComponent');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interpret and validate a rule given as a string', () => {
|
||||||
|
expect(checkPropTypes(123, 'age', 'number', 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes('123', 'age', 'string', 'TestComponent')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should log a warning for invalid rule type', () => {
|
||||||
|
const result = checkPropTypes(123, 'age', 123, 'TestComponent');
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// oneOf
|
||||||
|
it('should validate correctly with valid oneOf prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['News', 'Photos'],
|
||||||
|
}
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe(`PropTypes.oneOf(["News","Photos"])`);
|
||||||
|
expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes('Others', 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// oneOfType
|
||||||
|
it('should validate correctly with valid oneOfType prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: ['string', 'number', {
|
||||||
|
type: 'array',
|
||||||
|
isRequired: true,
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array.isRequired])');
|
||||||
|
expect(checkPropTypes(['News', 'Photos'], 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes(123, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({}, 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate correctly with valid oneOfType prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'oneOfType',
|
||||||
|
value: [
|
||||||
|
'bool',
|
||||||
|
{
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'type',
|
||||||
|
propType: {
|
||||||
|
type: 'oneOf',
|
||||||
|
value: ['JSExpression'],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'value',
|
||||||
|
propType: 'string',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({type: PropTypes.oneOf(["JSExpression"]),value: PropTypes.string})])');
|
||||||
|
expect(checkPropTypes(true, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ type: 'JSExpression', value: '1 + 1 === 2' }, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ type: 'JSExpression' }, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ type: 'JSExpression', value: 123 }, 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should log a warning for invalid type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'inval',
|
||||||
|
value: ['News', 'Photos'],
|
||||||
|
}
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.any');
|
||||||
|
expect(checkPropTypes('News', 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes('Others', 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
// arrayOf
|
||||||
|
it('should validate correctly with valid arrayOf prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'arrayOf',
|
||||||
|
value: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.arrayOf(PropTypes.string.isRequired)');
|
||||||
|
expect(checkPropTypes(['News', 'Photos'], 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes(['News', 123], 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// objectOf
|
||||||
|
it('should validate correctly with valid objectOf prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'objectOf',
|
||||||
|
value: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.objectOf(PropTypes.string.isRequired)');
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 'Photos' }, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// shape
|
||||||
|
it('should validate correctly with valid shape prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'b',
|
||||||
|
propType: {
|
||||||
|
type: 'number',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.shape({a: PropTypes.string.isRequired,b: PropTypes.number.isRequired})');
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 'Photos' }, 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
|
||||||
|
// isRequired
|
||||||
|
const rule2 = {
|
||||||
|
type: 'shape',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'b',
|
||||||
|
propType: {
|
||||||
|
type: 'number',
|
||||||
|
isRequired: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule2)).toBe('PropTypes.shape({a: PropTypes.string.isRequired,b: PropTypes.number})');
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule2, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ b: 123 }, 'type', rule2, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// exact
|
||||||
|
it('should validate correctly with valid exact prop type', () => {
|
||||||
|
const rule = {
|
||||||
|
type: 'exact',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'b',
|
||||||
|
propType: {
|
||||||
|
type: 'number',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule)).toBe('PropTypes.exact({a: PropTypes.string.isRequired,b: PropTypes.number.isRequired})');
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 'Photos' }, 'type', rule, 'TestComponent')).toBe(false);
|
||||||
|
|
||||||
|
// isRequired
|
||||||
|
const rule2 = {
|
||||||
|
type: 'exact',
|
||||||
|
value: [
|
||||||
|
{
|
||||||
|
name: 'a',
|
||||||
|
propType: {
|
||||||
|
type: 'string',
|
||||||
|
isRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'b',
|
||||||
|
propType: {
|
||||||
|
type: 'number',
|
||||||
|
isRequired: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
expect(transformPropTypesRuleToString(rule2)).toBe('PropTypes.exact({a: PropTypes.string.isRequired,b: PropTypes.number})');
|
||||||
|
expect(checkPropTypes({ a: 'News', b: 123 }, 'type', rule2, 'TestComponent')).toBe(true);
|
||||||
|
expect(checkPropTypes({ b: 123 }, 'type', rule2, 'TestComponent')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
import { isBasicPropType } from '../../../src';
|
||||||
|
|
||||||
|
describe('test isBasicPropType ', () => {
|
||||||
|
it('should work', () => {
|
||||||
|
expect(isBasicPropType(null)).toBeFalsy();
|
||||||
|
expect(isBasicPropType(undefined)).toBeFalsy();
|
||||||
|
expect(isBasicPropType({})).toBeFalsy();
|
||||||
|
expect(isBasicPropType({ type: 'any other type' })).toBeFalsy();
|
||||||
|
expect(isBasicPropType('string')).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
import { isRequiredPropType } from '../../../src';
|
||||||
|
|
||||||
|
describe('test isRequiredType', () => {
|
||||||
|
it('should work', () => {
|
||||||
|
expect(isRequiredPropType(null)).toBeFalsy();
|
||||||
|
expect(isRequiredPropType(undefined)).toBeFalsy();
|
||||||
|
expect(isRequiredPropType({})).toBeFalsy();
|
||||||
|
expect(isRequiredPropType({ type: 'any other type' })).toBeFalsy();
|
||||||
|
expect(isRequiredPropType('string')).toBeFalsy();
|
||||||
|
expect(isRequiredPropType({ type: 'string' })).toBeTruthy();
|
||||||
|
expect(isRequiredPropType({ type: 'string', isRequired: true })).toBeTruthy();
|
||||||
|
});
|
||||||
|
})
|
||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@alilc/lowcode-workspace",
|
"name": "@alilc/lowcode-workspace",
|
||||||
"version": "1.3.1-beta.1",
|
"version": "1.3.2",
|
||||||
"description": "Shell Layer for AliLowCodeEngine",
|
"description": "Shell Layer for AliLowCodeEngine",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"module": "es/index.js",
|
"module": "es/index.js",
|
||||||
@ -15,11 +15,11 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@alilc/lowcode-designer": "1.3.1-beta.1",
|
"@alilc/lowcode-designer": "1.3.2",
|
||||||
"@alilc/lowcode-editor-core": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-core": "1.3.2",
|
||||||
"@alilc/lowcode-editor-skeleton": "1.3.1-beta.1",
|
"@alilc/lowcode-editor-skeleton": "1.3.2",
|
||||||
"@alilc/lowcode-types": "1.3.1-beta.1",
|
"@alilc/lowcode-types": "1.3.2",
|
||||||
"@alilc/lowcode-utils": "1.3.1-beta.1",
|
"@alilc/lowcode-utils": "1.3.2",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"enzyme": "^3.11.0",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.5",
|
"enzyme-adapter-react-16": "^1.15.5",
|
||||||
@ -49,7 +49,7 @@
|
|||||||
"type": "http",
|
"type": "http",
|
||||||
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/workspace"
|
"url": "https://github.com/alibaba/lowcode-engine/tree/main/packages/workspace"
|
||||||
},
|
},
|
||||||
"gitHead": "f9f4d25edceca6bf99f6938d2097f80b7016ee4f",
|
"gitHead": "2669f179e6f899d395ce1942d0fe04f9c5ed48a6",
|
||||||
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
"bugs": "https://github.com/alibaba/lowcode-engine/issues",
|
||||||
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
"homepage": "https://github.com/alibaba/lowcode-engine/#readme"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
commonEvent,
|
commonEvent,
|
||||||
IEngineConfig,
|
IEngineConfig,
|
||||||
IHotKey,
|
IHotKey,
|
||||||
|
Command as InnerCommand,
|
||||||
} from '@alilc/lowcode-editor-core';
|
} from '@alilc/lowcode-editor-core';
|
||||||
import {
|
import {
|
||||||
Designer,
|
Designer,
|
||||||
@ -33,6 +34,7 @@ import {
|
|||||||
Window,
|
Window,
|
||||||
Canvas,
|
Canvas,
|
||||||
CommonUI,
|
CommonUI,
|
||||||
|
Command,
|
||||||
} from '@alilc/lowcode-shell';
|
} from '@alilc/lowcode-shell';
|
||||||
import {
|
import {
|
||||||
IPluginPreferenceMananger,
|
IPluginPreferenceMananger,
|
||||||
@ -94,7 +96,7 @@ export class BasicContext implements IBasicContext {
|
|||||||
designer: IDesigner;
|
designer: IDesigner;
|
||||||
registerInnerPlugins: () => Promise<void>;
|
registerInnerPlugins: () => Promise<void>;
|
||||||
innerSetters: InnerSetters;
|
innerSetters: InnerSetters;
|
||||||
innerSkeleton: InnerSkeleton;
|
innerSkeleton: ISkeleton;
|
||||||
innerHotkey: IHotKey;
|
innerHotkey: IHotKey;
|
||||||
innerPlugins: ILowCodePluginManager;
|
innerPlugins: ILowCodePluginManager;
|
||||||
canvas: IPublicApiCanvas;
|
canvas: IPublicApiCanvas;
|
||||||
@ -129,6 +131,7 @@ export class BasicContext implements IBasicContext {
|
|||||||
const skeleton = new Skeleton(innerSkeleton, 'any', true);
|
const skeleton = new Skeleton(innerSkeleton, 'any', true);
|
||||||
const canvas = new Canvas(editor, true);
|
const canvas = new Canvas(editor, true);
|
||||||
const commonUI = new CommonUI(editor);
|
const commonUI = new CommonUI(editor);
|
||||||
|
const innerCommand = new InnerCommand();
|
||||||
editor.set('setters', setters);
|
editor.set('setters', setters);
|
||||||
editor.set('project', project);
|
editor.set('project', project);
|
||||||
editor.set('material', material);
|
editor.set('material', material);
|
||||||
@ -162,6 +165,7 @@ export class BasicContext implements IBasicContext {
|
|||||||
context.setters = setters;
|
context.setters = setters;
|
||||||
context.material = material;
|
context.material = material;
|
||||||
const eventPrefix = meta?.eventPrefix || 'common';
|
const eventPrefix = meta?.eventPrefix || 'common';
|
||||||
|
const commandScope = meta?.commandScope;
|
||||||
context.event = new Event(commonEvent, { prefix: eventPrefix });
|
context.event = new Event(commonEvent, { prefix: eventPrefix });
|
||||||
context.config = config;
|
context.config = config;
|
||||||
context.common = common;
|
context.common = common;
|
||||||
@ -172,6 +176,9 @@ export class BasicContext implements IBasicContext {
|
|||||||
if (editorWindow) {
|
if (editorWindow) {
|
||||||
context.editorWindow = new Window(editorWindow);
|
context.editorWindow = new Window(editorWindow);
|
||||||
}
|
}
|
||||||
|
context.command = new Command(innerCommand, context as IPublicModelPluginContext, {
|
||||||
|
commandScope,
|
||||||
|
});
|
||||||
context.registerLevel = registerLevel;
|
context.registerLevel = registerLevel;
|
||||||
context.isPluginRegisteredInWorkspace = registerLevel === IPublicEnumPluginRegisterLevel.Workspace;
|
context.isPluginRegisteredInWorkspace = registerLevel === IPublicEnumPluginRegisterLevel.Workspace;
|
||||||
editor.set('pluginContext', context);
|
editor.set('pluginContext', context);
|
||||||
|
|||||||
@ -17,7 +17,7 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan
|
|||||||
|
|
||||||
editorViews: Map<string, IViewContext>;
|
editorViews: Map<string, IViewContext>;
|
||||||
|
|
||||||
editorView: IViewContext;
|
_editorView: IViewContext;
|
||||||
|
|
||||||
changeViewName: (name: string, ignoreEmit?: boolean) => void;
|
changeViewName: (name: string, ignoreEmit?: boolean) => void;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
|
|
||||||
url: string | undefined;
|
url: string | undefined;
|
||||||
|
|
||||||
@obx.ref editorView: Context;
|
@obx.ref _editorView: Context;
|
||||||
|
|
||||||
@obx editorViews: Map<string, Context> = new Map<string, Context>();
|
@obx editorViews: Map<string, Context> = new Map<string, Context>();
|
||||||
|
|
||||||
@ -62,6 +62,13 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
|
|
||||||
sleep: boolean | undefined;
|
sleep: boolean | undefined;
|
||||||
|
|
||||||
|
get editorView() {
|
||||||
|
if (!this._editorView) {
|
||||||
|
return this.editorViews.values().next().value;
|
||||||
|
}
|
||||||
|
return this._editorView;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(readonly resource: IResource, readonly workspace: IWorkspace, private config: IWindowCOnfig) {
|
constructor(readonly resource: IResource, readonly workspace: IWorkspace, private config: IWindowCOnfig) {
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.title = config.title;
|
this.title = config.title;
|
||||||
@ -75,10 +82,10 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
updateState(state: WINDOW_STATE): void {
|
updateState(state: WINDOW_STATE): void {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case WINDOW_STATE.active:
|
case WINDOW_STATE.active:
|
||||||
this.editorView?.setActivate(true);
|
this._editorView?.setActivate(true);
|
||||||
break;
|
break;
|
||||||
case WINDOW_STATE.inactive:
|
case WINDOW_STATE.inactive:
|
||||||
this.editorView?.setActivate(false);
|
this._editorView?.setActivate(false);
|
||||||
break;
|
break;
|
||||||
case WINDOW_STATE.destroyed:
|
case WINDOW_STATE.destroyed:
|
||||||
break;
|
break;
|
||||||
@ -146,7 +153,7 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
for (let i = 0; i < editorViews.length; i++) {
|
for (let i = 0; i < editorViews.length; i++) {
|
||||||
const name = editorViews[i].viewName;
|
const name = editorViews[i].viewName;
|
||||||
await this.initViewType(name);
|
await this.initViewType(name);
|
||||||
if (!this.editorView) {
|
if (!this._editorView) {
|
||||||
this.changeViewName(name);
|
this.changeViewName(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,14 +197,14 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
};
|
};
|
||||||
|
|
||||||
changeViewName = (name: string, ignoreEmit: boolean = true) => {
|
changeViewName = (name: string, ignoreEmit: boolean = true) => {
|
||||||
this.editorView?.setActivate(false);
|
this._editorView?.setActivate(false);
|
||||||
this.editorView = this.editorViews.get(name)!;
|
this._editorView = this.editorViews.get(name)!;
|
||||||
|
|
||||||
if (!this.editorView) {
|
if (!this._editorView) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.editorView.setActivate(true);
|
this._editorView.setActivate(true);
|
||||||
|
|
||||||
if (!ignoreEmit) {
|
if (!ignoreEmit) {
|
||||||
this.emitter.emit('window.change.view.type', name);
|
this.emitter.emit('window.change.view.type', name);
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
lerna run build \
|
lerna run build \
|
||||||
--scope @alilc/lowcode-types \
|
--scope @alilc/lowcode-types \
|
||||||
--scope @alilc/lowcode-utils \
|
--scope @alilc/lowcode-utils \
|
||||||
@ -8,6 +10,7 @@ lerna run build \
|
|||||||
--scope @alilc/lowcode-editor-skeleton \
|
--scope @alilc/lowcode-editor-skeleton \
|
||||||
--scope @alilc/lowcode-designer \
|
--scope @alilc/lowcode-designer \
|
||||||
--scope @alilc/lowcode-plugin-designer \
|
--scope @alilc/lowcode-plugin-designer \
|
||||||
|
--scope @alilc/lowcode-plugin-command \
|
||||||
--scope @alilc/lowcode-plugin-outline-pane \
|
--scope @alilc/lowcode-plugin-outline-pane \
|
||||||
--scope @alilc/lowcode-react-renderer \
|
--scope @alilc/lowcode-react-renderer \
|
||||||
--scope @alilc/lowcode-react-simulator-renderer \
|
--scope @alilc/lowcode-react-simulator-renderer \
|
||||||
|
|||||||
@ -14,3 +14,4 @@ tnpm sync @alilc/lowcode-react-renderer
|
|||||||
tnpm sync @alilc/lowcode-react-simulator-renderer
|
tnpm sync @alilc/lowcode-react-simulator-renderer
|
||||||
tnpm sync @alilc/lowcode-engine
|
tnpm sync @alilc/lowcode-engine
|
||||||
tnpm sync @alilc/lowcode-workspace
|
tnpm sync @alilc/lowcode-workspace
|
||||||
|
tnpm sync @alilc/lowcode-plugin-command
|
||||||
Loading…
x
Reference in New Issue
Block a user