-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
176 lines (153 loc) · 4.83 KB
/
index.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import CodeMirror from 'codemirror';
import 'codemirror/mode/groovy/groovy';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/htmlmixed/htmlmixed';
import 'codemirror/mode/properties/properties';
import 'codemirror/mode/yaml/yaml';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/idea.css';
// This addon is required to be installed by the caller
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/addon/hint/show-hint';
import 'lsp-editor-adapter/lib/codemirror-lsp.css';
import { LspWsConnection, CodeMirrorAdapter } from 'lsp-editor-adapter';
let sampleXml =
`<camelContext id="example-context" xmlns="http://camel.apache.org/schema/blueprint">
<route id="direct-input">
<from id="_from1" uri="file:work/input"/>
<to id="_processing" uri="direct:processing"/>
</route>
</camelContext>
`;
let sampleJava =
`import org.apache.camel.builder.RouteBuilder;
/**
* A Camel Java DSL Router
*/
public class MyRouteBuilder extends RouteBuilder {
/**
* Let's configure the Camel routing rules using Java code...
*/
public void configure() {
// here is a sample which processes the input files
// (leaving them in place - see the 'noop' flag)
// then performs content based routing on the message using XPath
from("file:src/data?noop=true&antExclude=aa&antFilterCaseSensitive=true&runLoggingLevel=OFF")
.choice()
.when(xpath("/person/city = 'London'"))
.to("file:target/messages/uk")
.otherwise()
.to("file:target/messages/others");
}
}
`;
let sampleKotlin =
`from("timer:kotlin?period=1s")
.routeId("kotlin")
.setBody()
.constant("Hello Camel K!")
.process().message {
it.headers["RandomValue"] = rnd.nextInt()
}
.to("log:info?showAll=true&multiline=true")
`;
let sampleJavascript =
`from('timer:js?period=1s')
.routeId('js')
.setBody()
.simple('Hello Camel K from CodeMirror')
.to('log:info?multiline=true')`;
let sampleGroovy =
`from('direct:greeting-api')
.to('log:api?showAll=true&multiline=true')
.setBody()
.simple('Hello from CodeMirror')`;
let sampleYaml =
`- id: "rest"
group: "routes"
rest:
verb: "post"
uri: "/api/route"
accepts: "text/plain"
binding-mode: "off"
steps:
- convert-body:
type: "java.lang.String"
- to:
uri: "log:in"`;
let sampleKafkaConnectProperties =
`name=CamelAWSS3SourceConnector
connector.class=org.apache.camel.kafkaconnector.CamelSourceConnector
key.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=org.apache.camel.kafkaconnector.converters.S3ObjectConverter
camel.source.maxPollDuration=10000
camel.source.kafka.topic=mytopic1
camel.source.url=aws-s3://bucket?autocloseBody=false
camel.component.aws-s3.configuration.access-key=<youraccesskey>
camel.component.aws-s3.configuration.secret-key=<yoursecretkey>
camel.component.aws-s3.configuration.region=<yourregion>`;
let modes = {
xml: 'xml',
java: 'java',
yaml: 'yaml',
kotlin: 'kotlin',
javascript: 'javascript',
properties: 'properties',
groovy: 'groovy'
};
let documents = {
xml: 'camel.xml',
java: 'CamelRoute.java',
yaml: 'file.camelk.yaml',
kotlin: 'file.camelk.kts',
javascript: 'file.camelk.js',
properties: 'camelKafkaConnect.properties',
groovy: 'file.camelk.groovy'
};
let editor = CodeMirror(document.querySelector('.editor'), {
theme: 'idea',
lineNumbers: true,
value: sampleXml,
gutters: ['CodeMirror-lsp'],
});
document.querySelector('select').addEventListener('change', () => {
switchSources();
});
let connection;
let adapter;
function switchSources() {
if (connection) {
connection.close();
}
if (adapter) {
adapter.remove();
}
let value = document.querySelector('select').value.toLowerCase();
editor.setOption('mode', modes[value]);
if(value === "xml") {
editor.setValue(sampleXml);
} else if(value === "java") {
editor.setValue(sampleJava);
} else if(value === "groovy") {
editor.setValue(sampleGroovy);
} else if(value === "javascript") {
editor.setValue(sampleJavascript);
} else if(value === "properties") {
editor.setValue(sampleKafkaConnectProperties);
} else if(value === "kotlin") {
editor.setValue(sampleKotlin);
} else if(value === "yaml") {
editor.setValue(sampleYaml);
}
connection = new LspWsConnection({
serverUri: 'ws://localhost:8025/camel-language-server',
languageId: "Apache Camel",
rootUri: 'file:///usr/src/app/sources',
documentUri: 'file:///usr/src/app/sources/' + documents[value],
documentText: () => editor.getValue(),
}).connect(new WebSocket('ws://localhost:8025/camel-language-server'));
adapter = new CodeMirrorAdapter(connection, {
quickSuggestionsDelay: 10,
}, editor);
}
switchSources();