-
Notifications
You must be signed in to change notification settings - Fork 45
/
IconLabelNodeConverterHandler.ts
113 lines (102 loc) · 3.25 KB
/
IconLabelNodeConverterHandler.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Node, XYPosition } from 'reactflow';
import { GQLNodeDescription } from '../graphql/query/nodeDescriptionFragment.types';
import {
GQLIconLabelNodeStyle,
GQLNode,
GQLNodeStyle,
GQLViewModifier,
} from '../graphql/subscription/nodeFragment.types';
import { BorderNodePositon } from '../renderer/DiagramRenderer.types';
import { ConnectionHandle } from '../renderer/handles/ConnectionHandles.types';
import { IconLabelNodeData } from '../renderer/node/IconsLabelNode.types';
import { IConvertEngine, INodeConverterHandler } from './ConvertEngine.types';
import { convertLabelStyle } from './convertDiagram';
const defaultPosition: XYPosition = { x: 0, y: 0 };
const toIconLabelNode = (
gqlNode: GQLNode<GQLIconLabelNodeStyle>,
gqlParentNode: GQLNode<GQLNodeStyle> | null,
nodeDescription: GQLNodeDescription | undefined,
isBorderNode: boolean
): Node<IconLabelNodeData> => {
const {
targetObjectId,
targetObjectLabel,
targetObjectKind,
descriptionId,
id,
insideLabel,
state,
style,
labelEditable,
} = gqlNode;
const connectionHandles: ConnectionHandle[] = [];
const data: IconLabelNodeData = {
targetObjectId,
targetObjectLabel,
targetObjectKind,
descriptionId,
style: {
textAlign: 'left',
backgroundColor: style.backgroundColor,
},
label: undefined,
isBorderNode: isBorderNode,
borderNodePosition: isBorderNode ? BorderNodePositon.WEST : null,
faded: state === GQLViewModifier.Faded,
nodeDescription,
defaultWidth: gqlNode.defaultWidth,
defaultHeight: gqlNode.defaultHeight,
labelEditable: labelEditable,
connectionHandles,
};
if (insideLabel) {
const labelStyle = insideLabel.style;
data.label = {
id: insideLabel.id,
text: insideLabel.text,
style: {
...convertLabelStyle(labelStyle),
},
iconURL: labelStyle.iconURL,
};
}
const node: Node<IconLabelNodeData> = {
id,
type: 'iconLabelNode',
data,
position: defaultPosition,
hidden: state === GQLViewModifier.Hidden,
};
if (gqlParentNode) {
node.parentNode = gqlParentNode.id;
}
return node;
};
export class IconLabelNodeConverterHandler implements INodeConverterHandler {
canHandle(gqlNode: GQLNode<GQLNodeStyle>) {
return gqlNode.style.__typename === 'IconLabelNodeStyle';
}
handle(
_convertEngine: IConvertEngine,
gqlNode: GQLNode<GQLIconLabelNodeStyle>,
parentNode: GQLNode<GQLNodeStyle> | null,
isBorderNode: boolean,
nodes: Node[],
nodeDescriptions: GQLNodeDescription[]
) {
const nodeDescription = nodeDescriptions.find((description) => description.id === gqlNode.descriptionId);
nodes.push(toIconLabelNode(gqlNode, parentNode, nodeDescription, isBorderNode));
}
}