Skip to content

Commit

Permalink
feat: added workspace api to support registration of multiple resources
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Dec 29, 2022
1 parent 0a24273 commit dae09e3
Show file tree
Hide file tree
Showing 36 changed files with 720 additions and 311 deletions.
36 changes: 31 additions & 5 deletions docs/docs/api/model/window.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,41 @@ sidebar_position: 12

低代码设计器窗口模型

## 变量

### id

窗口唯一 id

### title

窗口标题

### resourceName

窗口资源名字

## 方法签名

### importSchema(schema: IPublicTypeNodeSchema)
当前窗口导入 schema
### importSchema
当前窗口导入 schema, 会调用当前窗口对应资源的 import 钩子

```typescript
function importSchema(schema: IPublicTypeNodeSchema): void
```

相关类型:[IPublicTypeNodeSchema](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/node-schema.ts)

### changeViewType(viewName: string)
### changeViewType
修改当前窗口视图类型

### async save()
调用当前窗口视图保存钩子
```typescript
function changeViewType(viewName: string): void
```

### save
当前窗口的保存方法,会调用当前窗口对应资源的 save 钩子

```typescript
function save(): Promise(void)
```
40 changes: 40 additions & 0 deletions docs/docs/api/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@ sidebar_position: 12

当前设计器窗口模型

```typescript
get window(): IPublicModelWindow
```

关联模型 [IPublicModelWindow](./model/window)

### plugins

应用级别的插件注册

```typescript
get plugins(): IPublicApiPlugins
```

关联模型 [IPublicApiPlugins](./plugins)

### windows

当前设计器的编辑窗口

```typescript
get window(): IPublicModelWindow[]
```

关联模型 [IPublicModelWindow](./model/window)

## 方法签名
Expand All @@ -34,3 +58,19 @@ registerResourceType(resourceName: string, resourceType: 'editor', options: IPub
```

相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts)

### onChangeWindows

窗口新增/删除的事件

```typescript
function onChangeWindows(fn: () => void): void;
```

### onChangeActiveWindow

active 窗口变更事件

```typescript
function onChangeActiveWindow(fn: () => void): void;
```
155 changes: 155 additions & 0 deletions packages/designer/src/component-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { IPublicTypeComponentAction, IPublicTypeMetadataTransducer } from '@alilc/lowcode-types';
import { engineConfig } from '@alilc/lowcode-editor-core';
import { intlNode } from './locale';
import {
IconLock,
IconUnlock,
IconRemove,
IconClone,
IconHidden,
} from './icons';
import { Node } from './document';
import { componentDefaults, legacyIssues } from './transducers';

export class ComponentActions {
actions: IPublicTypeComponentAction[] = [
{
name: 'remove',
content: {
icon: IconRemove,
title: intlNode('remove'),
/* istanbul ignore next */
action(node: Node) {
node.remove();
},
},
important: true,
},
{
name: 'hide',
content: {
icon: IconHidden,
title: intlNode('hide'),
/* istanbul ignore next */
action(node: Node) {
node.setVisible(false);
},
},
/* istanbul ignore next */
condition: (node: Node) => {
return node.componentMeta.isModal;
},
important: true,
},
{
name: 'copy',
content: {
icon: IconClone,
title: intlNode('copy'),
/* istanbul ignore next */
action(node: Node) {
// node.remove();
const { document: doc, parent, index } = node;
if (parent) {
const newNode = doc.insertNode(parent, node, index + 1, true);
newNode.select();
const { isRGL, rglNode } = node.getRGL();
if (isRGL) {
// 复制 layout 信息
let layout = rglNode.getPropValue('layout') || [];
let curLayout = layout.filter((item) => item.i === node.getPropValue('fieldId'));
if (curLayout && curLayout[0]) {
layout.push({
...curLayout[0],
i: newNode.getPropValue('fieldId'),
});
rglNode.setPropValue('layout', layout);
// 如果是磁贴块复制,则需要滚动到影响位置
setTimeout(() => newNode.document.simulator?.scrollToNode(newNode), 10);
}
}
}
},
},
important: true,
},
{
name: 'lock',
content: {
icon: IconLock, // 锁定 icon
title: intlNode('lock'),
/* istanbul ignore next */
action(node: Node) {
node.lock();
},
},
/* istanbul ignore next */
condition: (node: Node) => {
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && !node.isLocked;
},
important: true,
},
{
name: 'unlock',
content: {
icon: IconUnlock, // 解锁 icon
title: intlNode('unlock'),
/* istanbul ignore next */
action(node: Node) {
node.lock(false);
},
},
/* istanbul ignore next */
condition: (node: Node) => {
return engineConfig.get('enableCanvasLock', false) && node.isContainer() && node.isLocked;
},
important: true,
},
];

constructor() {
this.registerMetadataTransducer(legacyIssues, 2, 'legacy-issues'); // should use a high level priority, eg: 2
this.registerMetadataTransducer(componentDefaults, 100, 'component-defaults');
}

removeBuiltinComponentAction(name: string) {
const i = this.actions.findIndex((action) => action.name === name);
if (i > -1) {
this.actions.splice(i, 1);
}
}
addBuiltinComponentAction(action: IPublicTypeComponentAction) {
this.actions.push(action);
}

modifyBuiltinComponentAction(
actionName: string,
handle: (action: IPublicTypeComponentAction) => void,
) {
const builtinAction = this.actions.find((action) => action.name === actionName);
if (builtinAction) {
handle(builtinAction);
}
}

private metadataTransducers: IPublicTypeMetadataTransducer[] = [];

registerMetadataTransducer(
transducer: IPublicTypeMetadataTransducer,
level = 100,
id?: string,
) {
transducer.level = level;
transducer.id = id;
const i = this.metadataTransducers.findIndex((item) => item.level != null && item.level > level);
if (i < 0) {
this.metadataTransducers.push(transducer);
} else {
this.metadataTransducers.splice(i, 0, transducer);
}
}

getRegisteredMetadataTransducers(): IPublicTypeMetadataTransducer[] {
return this.metadataTransducers;
}
}
Loading

0 comments on commit dae09e3

Please sign in to comment.