Skip to content

Commit ba620cc

Browse files
authored
Merge pull request #7 from yhlchao/master
fix(core): fix checking repeatedly verification rules
2 parents a77ef9c + 1828e60 commit ba620cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+145
-304
lines changed

.markdownlint.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"default": true,
3+
"MD013": {
4+
"line_length": 200
5+
},
6+
"MD024": {
7+
"allow_different_nesting": true
8+
}
9+
}

docs/.vuepress/config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const guide = [
3131
title: '拓展',
3232
collapsable: false,
3333
children: [
34+
'extension/extension-intro',
3435
'extension/extension-components',
3536
'extension/bpmn-element',
3637
'extension/snapshot',
@@ -48,7 +49,15 @@ const api = [
4849
'nodeApi',
4950
'edgeApi',
5051
]
51-
}
52+
},
53+
{
54+
title: '自定义元素',
55+
collapsable: false,
56+
children: [
57+
'customNodeApi',
58+
'customEdgeApi',
59+
]
60+
},
5261
];
5362

5463
const usage = ["bpmn", "approve"];

docs/api/edgeApi.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Logic Flow 的内置连线类型包括
6464

6565
创建边
6666

67-
参数:
67+
#### 参数
6868

6969
| 名称 | 类型 | 描述 |
7070
| :----- | :----- | :------- | :-------------- |
@@ -83,21 +83,21 @@ export type EdgeConifg = {
8383
};
8484
```
8585

86-
返回值
86+
#### 返回值
8787

8888
8989

9090
### lf.getEdgeData
9191

9292
获取边数据
9393

94-
参数:
94+
#### 参数
9595

9696
| 名称 | 类型 | 描述 |
9797
| :----- | :----- | :------- | :-------------- |
9898
| edgeId | string | 边Id |
9999

100-
返回值
100+
#### 返回值
101101

102102
| 名称 | 类型 | 描述 |
103103
| :----- | :----- | :------- | :-------------- |
@@ -121,7 +121,7 @@ type EdgeData = {
121121

122122
修改边数据
123123

124-
参数:
124+
#### 参数
125125

126126
| 名称 | 类型 | 描述 |
127127
| :----- | :----- | :------- | :-------------- |
@@ -141,29 +141,29 @@ type EdgeAttribute = {
141141
};
142142
```
143143

144-
返回值
144+
#### 返回值
145145

146146
147147

148148
### lf.deleteEdge
149149

150150
删除边
151151

152-
参数:
152+
#### 参数
153153

154154
| 名称 | 类型 | 描述 |
155155
| :----- | :----- | :------- | :-------------- |
156156
| edgeId | string | 删除边Id |
157157

158-
返回值
158+
#### 返回值
159159

160160
161161

162162
### lf.removeEdge
163163

164164
基于连线的起终点删除连线
165165

166-
参数:
166+
#### 参数
167167

168168
| 名称 | 类型 | 描述 |
169169
| :----- | :----- | :------- | :-------------- |
@@ -184,7 +184,7 @@ type EdgeFilter = {
184184
- 仅存在targetNodeId,删除以targetNodeId为结束节点的边
185185
- 存在targetNodeId和targetNodeId,删除以sourceNodeId为开始节点,并且以targetNodeId为结束节点的边
186186

187-
返回值
187+
#### 返回值
188188

189189
190190

@@ -196,7 +196,7 @@ type EdgeFilter = {
196196
setDefaultEdgeType(type: string): void
197197
```
198198

199-
参数:
199+
#### 参数
200200

201201
| 名称 | 类型 | 必传 | 默认值 | 描述 |
202202
| :- | :- | :- |:- | :- |
@@ -209,7 +209,7 @@ setDefaultEdgeType(type: string): void
209209
lf.setDefaultEdgeType('beizer')
210210
```
211211

212-
返回值
212+
#### 返回值
213213

214214
215215

docs/article/article01.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ const lf = new LogicFlow({ // 实例化 lf 对象
139139
container: document.querySelector('#graph'), // 获取渲染容器
140140
width: 700,
141141
height: 600,
142-
tool: {
143-
menu: true,
144-
control: true,
145-
},
146142
background: {
147143
color: '#F0F0F0'
148144
},

docs/guide/basic/dnd.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ export default class App extends Component<IProps, IState> {
1515
container: document.querySelector('#graph'),
1616
width: 700,
1717
height: 600,
18-
tool: {
19-
menu: true,
20-
control: false,
21-
},
2218
});
2319
this.lf.render();
2420
}

docs/guide/basic/snapline.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# 对齐线 Snapline
22

3+
对齐线能够在节点移动过程中,将移动节点的位置与画布中其他节点位置进行对比,辅助位置调整。位置对比有如下两个方面。
34

4-
对齐线能够在节点移动过程中,将移动节点的位置与画布中其他节点位置进行对比,辅助位置调整。
5-
> 位置对比有两个方面
6-
> - 节点中心位置
7-
> - 节点的边框
5+
- 节点中心位置
6+
- 节点的边框
87

98
## 对齐线使用
9+
1010
普通编辑模式下,默认开启对齐线,也可通过配置进行关闭。
1111
[静默模式](/guide/basic/silent-mode.html)下,无法移动节点,所以关闭了对齐线功能,无法通过配置开启。
1212

@@ -20,6 +20,7 @@ const lf = new LogicFlow({
2020
## 对齐线样式设置
2121

2222
对齐线的样式包括颜色和宽度,可以通过设置主题的方式进行修改。
23+
2324
```ts
2425
// 默认配置
2526
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# 简介
2+
3+
> Logic Flow 最初的目标就是支持一个扩展性强的流程绘制工具,用来满足各种业务需求。
4+
5+
目前所有内置的拓展都在`@logicflow/extension`包中,其中包括`BpmnElement``Snapshot``Adapter`以及三个内置组件。
6+
7+
## 使用拓展
8+
9+
```js
10+
import { BpmnElement } from '@didi/lf-extension';
11+
LogicFlow.use(BpmnElement);
12+
```
13+
14+
```html
15+
<script src="/logic-flow.js"></script>
16+
<script src="/lib/BpmnElement.js"></script>
17+
<script>
18+
LogicFlow.use(BpmnElement);
19+
</script>
20+
```
21+
22+
## 自定义拓展
23+
24+
实现一个 Logic Flow 的扩展非常简单,那就是对外暴露一个对象,这个对象有一个方法 install。Logic Flow 会在初始化的时候执行这个方法,将其实例传递进来。开发者基于这个实例,利用 Logic Flow 的自定义机制开发,就可以实现一个插件。
25+
26+
```js
27+
window.ResizeNode = {
28+
install: function(lf) {
29+
// 基于lf进行扩展
30+
}
31+
}
32+
```

docs/guide/start.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ const data = {
6565
```js
6666
const lf = new LogicFlow({
6767
container: document.querySelector('#container'),
68-
tool: {
69-
control: false,
70-
},
7168
stopScrollGraph: true,
7269
stopZoomGraph: true,
7370
grid: {
@@ -78,10 +75,11 @@ const lf = new LogicFlow({
7875
```
7976

8077
通过刚才创建的实例,来渲染画布。
78+
8179
```js
8280
lf.render(data);
8381
```
8482

8583
到此,我们就创建好了一个最简单的示例。
8684

87-
<example :height="300" ></example>
85+
<example :height="300" ></example>

docs/usage/approve.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
- 连线规则
2020
在审批流配置过程中,需要有一些控制连接的规则保证流程的正确性,比如申请节点不能被其它节点连接、结束节点不能连接其他节点等,Logic Flow提供了自定义节点`连线规则`功能来实现这个需求。
2121

22-
<example href="/examples/#/extension/approve" :height="650"></example>
22+
<example href="/examples/#/usage/approve" :height="650"></example>
2323

2424
## 审批流配置
2525
### 创建节点
@@ -31,7 +31,7 @@
3131
### 事件
3232
LogicFlow提供了节点和边的交互事件,可以通过监听这些事件,拿到对应的节点和边的`数据`以及`原生事件`信息。事件的详细内容见[事件API](/guide/advance/event.html)
3333
审批中的流程进度预览,设置[静默模式](/guide/basic/silent-mode.html),监听节点hover,使用React组件展示审批详情。
34-
<example :height="350" href="/examples/#/extension/approve/preview"></example>
34+
<example :height="350" href="/examples/#/usage/approve/preview"></example>
3535

3636

3737
## 审批流程主题设置

docs/usage/bpmn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
该示例绘制的图可以在 BPMN 官方 Demo 中正常使用。(此处仅实现了 BPMN 中的一部分节点)
44

5-
<example href="/examples/#/extension/bpmn" :height="600" ></example>
5+
<example href="/examples/#/usage/bpmn" :height="600" ></example>

examples/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"postcss-normalize": "8.0.1",
5858
"postcss-preset-env": "6.7.0",
5959
"postcss-safe-parser": "5.0.2",
60+
"prettier": "^2.2.1",
6061
"prompts": "2.4.0",
6162
"react": "^17.0.1",
6263
"react-app-polyfill": "^2.0.0",

examples/src/pages/basic/keyboard/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import ExampleHeader from '../../../components/example-header';
44
import './index.css';
55

66
const config = {
7+
stopScrollGraph: true,
8+
stopZoomGraph: true,
79
textEdit: false,
810
keyboard: {
911
enabled: true,

examples/src/pages/approve/index.tsx renamed to examples/src/pages/usage/approve/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { message } from 'antd';
33
import LogicFlow from '@logicflow/core';
44
import PropertyPanel from './components/property';
55
import NodePanel from './components/NodePanel';
6-
import RegisteNode from './components/registernNode';
6+
import RegisteNode from './components/registerNode';
77
import { themeApprove, data } from './config';
88
import './index.css';
99

examples/src/pages/approvePreview/index.tsx renamed to examples/src/pages/usage/approvePreview/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect, useState } from 'react';
22
import LogicFlow from '@logicflow/core';
3-
import RegisteNode from './components/registernNode';
3+
import RegisteNode from './components/registerNode';
44
import hoverPanel from './components/hoverPanel';
55
import { themeApprove, data } from './config';
66
import './index.css';

examples/src/routes.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import Rule from './pages/advance/custom-node/rule';
2323
import Process from './pages/advance/custom-edge/process';
2424
import Arrow from './pages/advance/custom-edge/arrow';
2525
import Event from './pages/advance/event';
26-
import Approve from './pages/approve';
27-
import ApprovePreview from './pages/approvePreview';
26+
import Approve from './pages/usage/approve';
27+
import ApprovePreview from './pages/usage/approvePreview';
2828
import BpmnElements from './pages/extension/bpmn/Elements';
2929
import AdapterExample from './pages/extension/adapter';
3030

@@ -52,11 +52,11 @@ export default (
5252
<Route path="/extension/components/dnd" exact component={DndPandel} />
5353
<Route path="/extension/components/custom-menu" exact component={CustomMenu} />
5454
<Route path="/extension/components/custom-dnd" exact component={CustomDnd} />
55-
<Route path="/extension/approve" exact component={Approve} />
56-
<Route path="/extension/approve/preview" exact component={ApprovePreview} />
5755
<Route path="/extension/bpmn-elements" exact component={BpmnElements} />
5856
<Route path="/extension/adapter" exact component={AdapterExample} />
5957
<Route path="/usage/bpmn" exact component={Bpmn} />
58+
<Route path="/usage/approve" exact component={Approve} />
59+
<Route path="/usage/approve/preview" exact component={ApprovePreview} />
6060
<Route path="/" component={Start} />
6161
</Switch>
6262
);

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"webpack": "^4.43.0",
6464
"webpack-bundle-analyzer": "^3.7.0",
6565
"webpack-cli": "^3.3.11",
66-
"webpack-dev-server": "^3.10.3"
66+
"webpack-dev-server": "^3.10.3",
67+
"prettier": "^2.2.1"
6768
},
6869
"browserslist": [
6970
"> 3%",

packages/core/src/model/node/BaseNodeModel.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export default class BaseNodeModel implements IBaseModel {
4848
menu?: MenuConfig[];
4949
targetRules: ConnectRule[] = [];
5050
sourceRules: ConnectRule[] = [];
51+
hasSetTargetRules = false; // 用来限制rules的重复值
52+
hasSetSourceRules = false; // 用来限制rules的重复值
5153
@observable properties = {};
5254
@observable type = '';
5355
@observable x = defaultConfig.x;
@@ -140,7 +142,10 @@ export default class BaseNodeModel implements IBaseModel {
140142
* 在连线的时候,是否允许这个节点为source节点,连线到target节点。
141143
*/
142144
isAllowConnectedAsSource(target: BaseNodeModel): ConnectRuleResult {
143-
const rules = this.getConnectedSourceRules();
145+
const rules = !this.hasSetSourceRules
146+
? this.getConnectedSourceRules()
147+
: this.sourceRules;
148+
this.hasSetSourceRules = true;
144149
let isAllPass = true;
145150
let msg: string;
146151
for (let i = 0; i < rules.length; i++) {
@@ -168,7 +173,10 @@ export default class BaseNodeModel implements IBaseModel {
168173
*/
169174

170175
isAllowConnectedAsTarget(source: BaseNodeModel): ConnectRuleResult {
171-
const rules = this.getConnectedTargetRules();
176+
const rules = !this.hasSetTargetRules
177+
? this.getConnectedTargetRules()
178+
: this.targetRules;
179+
this.hasSetTargetRules = true;
172180
let isAllPass = true;
173181
let msg: string;
174182
for (let i = 0; i < rules.length; i++) {

0 commit comments

Comments
 (0)