-
Notifications
You must be signed in to change notification settings - Fork 45
/
index.tsx
136 lines (129 loc) · 4.5 KB
/
index.tsx
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*******************************************************************************
* Copyright (c) 2019, 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 { loadDevMessages, loadErrorMessages } from '@apollo/client/dev';
import { NodeTypeContribution } from '@eclipse-sirius/sirius-components-diagrams-reactflow';
import {
GQLWidget,
PropertySectionComponent,
PropertySectionComponentRegistry,
PropertySectionContext,
PropertySectionContextValue,
WidgetContribution,
} from '@eclipse-sirius/sirius-components-forms';
import {
GQLReferenceWidget,
ReferenceIcon,
ReferencePreview,
ReferencePropertySection,
} from '@eclipse-sirius/sirius-components-widget-reference';
import {
DiagramRepresentationConfiguration,
NodeTypeRegistry,
SiriusWebApplication,
} from '@eclipse-sirius/sirius-web-application';
import LinearScaleOutlinedIcon from '@material-ui/icons/LinearScaleOutlined';
import ReactDOM from 'react-dom';
import { httpOrigin, wsOrigin } from './core/URL';
import { EllipseNode } from './nodes/EllipseNode';
import { EllipseNodeConverterHandler } from './nodes/EllipseNodeConverterHandler';
import { EllipseNodeLayoutHandler } from './nodes/EllipseNodeLayoutHandler';
import { GQLSlider } from './widgets/SliderFragment.types';
import { SliderPreview } from './widgets/SliderPreview';
import { SliderPropertySection } from './widgets/SliderPropertySection';
import './Sprotty.css';
import './fonts.css';
import './reset.css';
import './variables.css';
if (process.env.NODE_ENV !== 'production') {
loadDevMessages();
loadErrorMessages();
}
const isSlider = (widget: GQLWidget): widget is GQLSlider => widget.__typename === 'Slider';
const isReferenceWidget = (widget: GQLWidget): widget is GQLReferenceWidget => widget.__typename === 'ReferenceWidget';
const propertySectionsRegistry: PropertySectionComponentRegistry = {
getComponent: (widget: GQLWidget): PropertySectionComponent<GQLWidget> | null => {
if (isSlider(widget)) {
return SliderPropertySection;
} else if (isReferenceWidget(widget)) {
return ReferencePropertySection;
}
return null;
},
getPreviewComponent: (widget: GQLWidget) => {
if (widget.__typename === 'Slider') {
return SliderPreview;
} else if (widget.__typename === 'ReferenceWidget') {
return ReferencePreview;
}
return null;
},
getWidgetContributions: () => {
const sliderWidgetContribution: WidgetContribution = {
name: 'Slider',
fields: `label iconURL minValue maxValue currentValue`,
icon: <LinearScaleOutlinedIcon />,
};
const referenceWidget: WidgetContribution = {
name: 'ReferenceWidget',
fields: `label
iconURL
ownerId
descriptionId
reference {
ownerKind
referenceKind
containment
manyValued
}
referenceValues {
id
label
kind
iconURL
hasClickAction
}
style {
color
fontSize
italic
bold
underline
strikeThrough
}`,
icon: <ReferenceIcon />,
};
return [sliderWidgetContribution, referenceWidget];
},
};
const propertySectionRegistryValue: PropertySectionContextValue = {
propertySectionsRegistry,
};
const nodeTypeRegistry: NodeTypeRegistry = {
graphQLNodeStyleFragments: [
{
type: 'EllipseNodeStyle',
fields: `borderColor borderSize borderStyle color`,
},
],
nodeLayoutHandlers: [new EllipseNodeLayoutHandler()],
nodeConverterHandlers: [new EllipseNodeConverterHandler()],
nodeTypeContributions: [<NodeTypeContribution component={EllipseNode} type={'ellipseNode'} />],
};
ReactDOM.render(
<PropertySectionContext.Provider value={propertySectionRegistryValue}>
<SiriusWebApplication httpOrigin={httpOrigin} wsOrigin={wsOrigin}>
<DiagramRepresentationConfiguration nodeTypeRegistry={nodeTypeRegistry} />
</SiriusWebApplication>
</PropertySectionContext.Provider>,
document.getElementById('root')
);