-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSparqlEditor.js
55 lines (44 loc) · 1007 Bytes
/
SparqlEditor.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
/* global CustomEvent */
import { Parser } from 'sparqljs'
import BaseEditor from './src/BaseEditor.js'
class SparqlEditor extends BaseEditor {
static get properties () {
return {
query: {
type: Object
}
}
}
firstUpdated () {
super.firstUpdated()
this._validate()
}
_emitChange () {
this._validate()
const options = {
detail: {
error: this.status.error,
query: this.query,
value: this.value
}
}
this.dispatchEvent(new CustomEvent('change', options))
}
_validate () {
try {
const parser = new Parser()
this.query = parser.parse(this.value)
this.status = {
message: this.query.queryType ? `${this.query.queryType} query` : ''
}
} catch (error) {
this.query = null
this.status = {
error,
message: error.message.split('\n').join(' ')
}
}
setTimeout(() => this.editor.dispatch(), 0)
}
}
export default SparqlEditor