alibaba / alibaba/lowcode-engine

「讨论」基于1.0.x版本引擎实现 自由布局 及 磁贴网格布局

Open
#1,775 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
15.9k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

我们目前的实现思路如下,希望官方及各位大佬给出更好的方案:
1. 设置引擎选项,允许事件冒泡
```js
config.setEngineOptions({
enableMouseEventPropagationInCanvas: true,
});
```
2. 重写dragon中处理事件的方法boost,主要是通过动态设置node.isRGLContainer属性,修改默认的拖拽行为
实现见:[dragon.zip](https://github.com/alibaba/lowcode-engine/files/11048555/dragon.zip)
```ts
import {
ILowCodePluginContext,
plugins,
project,
config,
} from '@alilc/lowcode-engine';
import DragonWrapper from './plugin/dragon';
export async function init() {
const editorInit = (ctx: ILowCodePluginContext) => {
return {
name: 'editor-init',
async init() {
DragonWrapper(config.get('designer').dragon);
},
};
};
editorInit.pluginName = 'editorInit';
await plugins.register(editorInit);
}
```
3. 使用react-moveable或其它库构建自由布局物料,在物料中监听move、resize等变化并设置节点属性
物料 如absolute-layout(自由布局容器)、absolute-item(自由布局元素)
absolute-layout/meta.ts部分配置:
```ts
const Meta: ComponentMetadata = {
configure: {
component: {
isContainer: true,
isRGLContainer: true,
},
advanced: {
callbacks: {
onNodeAdd: (addedNode: any, currentNode: any) => {
if(addedNode.parent != currentNode) return;

if(addedNode.componentName != 'AbsoluteItem') {
const snippet = {
...defaultItemSnippet,
children: addedNode.exportSchema(),
}
const item = currentNode.document.createNode(snippet);
currentNode.insertBefore(item, addedNode, false);
addedNode.remove();
setTimeout(() => {
item.select();
}, 500);
}
}
},
},
}
}
```
absolute-item/meta.ts部分配置:
```ts
const Meta: ComponentMetadata = {
configure: {
component: {
isContainer: true,
nestingRule: {
parentWhitelist: ['AbsoluteLayout'],
}
},
advanced: {
callbacks: {
//do nothing, just make sure "props._leaf" accessible
}
}
}
}
```
5. 同上使用react-grid-layout或其它库构建网格布局物料,在物料中监听布局变化并设置节点属性
实现上和自由布局差不多

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the issue's DragonWrapper implementation in dragon.zip, the engine option enableMouseEventPropagationInCanvas, and the examples in absolute-layout/meta.ts and absolute-item/meta.ts. Compare the proposed react-moveable and react-grid-layout integrations with the 1.0.x engine behavior. The issue does not define an agreed implementation or acceptance criteria, so the expected result needs maintainer clarification.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
design, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.