useNewNode.ts
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { XYPosition } from '@vue-flow/core';
import { Config as InputConfig } from '../packages/Entry/Input/config';
import { Config as OutputConfig } from '../packages/Flow/Output/config';
import { Config as RuleChainConfig } from '../packages/Flow/RuleChain/config';
import { useAddNodes } from './useAddNodes';
export function useNewNode() {
const getInputNodeConfig = (id?: string) => {
const { getAddNodesParams } = useAddNodes();
const newNode = getAddNodesParams(
{ x: 75, y: 50 },
{
...new InputConfig(),
data: {
name: '输入',
description: '规则链的逻辑输入,将传入消息转发到下一个相关规则节点。',
},
},
{ id, draggable: false, selectable: false }
);
return newNode;
};
const getOutputNodeConfig = (name: string, position: XYPosition, id?: string) => {
const { getAddNodesParams } = useAddNodes();
const newNode = getAddNodesParams(
position,
{
...new OutputConfig(),
data: {
name,
},
},
{ id, draggable: false, selectable: false }
);
return newNode;
};
const getRuleChainNodeConfig = ({
name,
position,
ruleChainId,
id,
}: {
name: string;
position: XYPosition;
ruleChainId: string;
id?: string;
}) => {
const { getAddNodesParams } = useAddNodes();
const newNode = getAddNodesParams(
position,
{
...new RuleChainConfig(),
data: { name, configuration: { ruleChainId } },
},
{
id,
}
);
return newNode;
};
return { getInputNodeConfig, getOutputNodeConfig, getRuleChainNodeConfig };
}