-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
68 lines (59 loc) · 2.27 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
import rulesBasic from './packages/rdf2dot/rules/basic.n3?raw'
import rulesDefault from './packages/rdf2dot/rules/default.n3?raw'
import { saveAs } from 'file-saver'
import '@rdfjs-elements/rdf-editor'
import './packages/rdf2dot-wc/index.js'
const fileInput = document.getElementById("fileInput")
const rulesInput = document.getElementById("rulesInput")
const showButton = document.getElementById("show")
const saveButton = document.getElementById("save")
const graph = document.getElementById("graph")
const data = document.getElementById("data")
const rules = document.getElementById("rules")
const toggleRulesButton = document.getElementById("toggleRules")
const defaultRulesButton = document.getElementById("loadDefaultRules")
const basicRulesButton = document.getElementById("loadBasicRules")
const rulesLabel = document.getElementById("rulesLabel")
rules.value = rulesDefault
rulesLabel.textContent = "Using Default Rules"
rulesInput.addEventListener("change", () => {
const [file] = rulesInput.files;
if (file) {
const reader = new FileReader();
reader.addEventListener("load", () => {
rules.value = reader.result
rulesLabel.textContent = "Using Custom Rules " + file.name
})
reader.readAsText(file)
}
})
fileInput.addEventListener("change", () => {
const [file] = fileInput.files;
if (file) {
const reader = new FileReader();
reader.addEventListener("load", () => {
data.value = reader.result
})
reader.readAsText(file);
}
})
showButton.addEventListener("click", async () => {
graph.rules = rules.value
graph.data = data.value
saveButton.removeAttribute("disabled")
})
saveButton.addEventListener("click", () => {
saveAs(new File([graph.svg.outerHTML], "rdf.svg", {type: "image/svg+xml"}))
})
toggleRulesButton.addEventListener("click", () => {
rules.classList.toggle("hidden")
toggleRulesButton.textContent = rules.classList.contains("hidden") ? "Show Rules Editor" : "Hide Rules Editor"
})
defaultRulesButton.addEventListener("click", () => {
rules.value = rulesDefault
rulesLabel.textContent = "Using Default Rules"
})
basicRulesButton.addEventListener("click", () => {
rules.value = rulesBasic
rulesLabel.textContent = "Using Basic Rules"
})