Skip to content

Commit 740c12f

Browse files
committed
fix(site): add utils directory
1 parent ebe778f commit 740c12f

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

packages/site/src/app.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import Share from './component/Share';
55
import Setting from './component/Setting';
66
import Links from './component/Links';
77
import './index.less';
8-
import CustomNode from './lib/utils/registerNode';
9-
import CustomListener from './lib/utils/addListener';
8+
import CustomNode from './utils/registerNode';
9+
import CustomListener from './utils/addListener';
1010

1111
LogicFlow.use(Snapshot);
1212
LogicFlow.use(Dnd);
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import LogicFlow from '@logicflow/core';
2+
3+
class CustomListener {
4+
lf: LogicFlow;
5+
6+
constructor(lf: LogicFlow) {
7+
this.lf = lf;
8+
}
9+
10+
addAll() {
11+
this.addNodeListener();
12+
// ...
13+
}
14+
15+
addNodeListener() {
16+
const { lf } = this;
17+
lf.on('node:click', ({ data }) => {
18+
console.log('单击', data);
19+
});
20+
lf.on('node:dbclick', ({ data }) => {
21+
console.log('双击', data);
22+
});
23+
}
24+
}
25+
26+
export default CustomListener;
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import LogicFlow from '@logicflow/core';
2+
3+
class CustomNode {
4+
lf: LogicFlow;
5+
6+
constructor(lf: LogicFlow) {
7+
this.lf = lf;
8+
}
9+
10+
// 注册所有的自定义节点
11+
registerAll() {
12+
this.registerRect();
13+
// ...
14+
}
15+
16+
registerRect() {
17+
this.lf.register('rect', ({ RectNode, RectNodeModel }) => {
18+
class CustomRectModel extends RectNodeModel {
19+
getConnectedSourceRules() {
20+
const rules = super.getConnectedSourceRules();
21+
const rule = {
22+
message: '不满足连线的校验规则',
23+
validate: (source, target) => {
24+
console.log(target);
25+
// 校验规则
26+
return true;
27+
},
28+
};
29+
rules.push(rule);
30+
return rules;
31+
}
32+
}
33+
return {
34+
view: RectNode,
35+
model: CustomRectModel,
36+
};
37+
});
38+
}
39+
}
40+
41+
export default CustomNode;

0 commit comments

Comments
 (0)