-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
73 lines (62 loc) · 2 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
<script src="https://unpkg.com/sparql-blockly/sparql-blockly.min.js"></script>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
flex-direction: column
}
textarea {
height: 10em;
padding: 20px;
}
section {
flex-grow: 1;
}
</style>
<script>
window.addEventListener("load", initialiseBlockly)
async function initialiseBlockly() {
const toolbox = await getToolboxData()
const options = { toolbox, sounds: false }
const container = document.querySelector("section")
const workspace = Blockly.inject(container, options)
workspace.addChangeListener(blocklyChanged)
}
function blocklyChanged(e) {
switch (e.type) {
case Blockly.Events.CHANGE:
case Blockly.Events.DELETE:
case Blockly.Events.MOVE:
generateCode()
}
}
function generateCode() {
const workspace = Blockly.getMainWorkspace()
populateTextarea("")
for (const block of workspace.getTopBlocks(false)) {
switch (block.type) {
case "sparql11_query":
case "sparql11_update":
populateTextarea(SparqlBlockly.blocklyToSparql(block))
}
}
}
function populateTextarea(sparql) {
document.querySelector("textarea").value = sparql
}
async function getToolboxData() {
const response = await fetch("../toolbox.xml")
return await response.text()
}
</script>
</head>
<body>
<textarea placeholder="Interact with Blockly canvas below to generate SPARQL code here." readonly></textarea>
<section></section>
</body>
</html>