-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (123 loc) · 3.81 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
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
<!doctype html>
<html lang="en-US" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/codemirror.min.css"></link>
<style>
* {
box-sizing: border-box;
}
body {
height: 100vh;
margin: 0;
padding: 10px;
}
body > * {
flex: 1;
}
output {
font-family: monospace;
white-space: pre;
overflow: scroll;
}
.CodeMirror {
flex: 1;
border: solid 1px gray;
min-width: 300px;
height: auto;
min-height: 300px;
}
x-row, x-col {
display: flex;
align-items: stretch;
flex: 1;
}
x-row {
flex-flow: row wrap;
}
select {
height: 20px;
}
</style>
<script>
window.app = {}
window.module = {}
</script>
</head>
<body>
<x-row>
<select id="js-docs">
<option selected disabled>Pick a file</option>
</select>
</x-row>
<x-row id="app">
<textarea id="js-fileinput"></textarea>
<textarea id="js-fileoutput"></textarea>
</x-row>
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.18.2/mode/javascript/javascript.min.js"></script>
<script src="./html.js"></script>
<script src="./bonapp.js"></script>
<script>window.app.parser = module.exports</script>
<script>
function loadDoc(data) {
data = data.split('\n')
if (!data[0].trim().startsWith('MEALPLANTRANLEDG')) {
data = data.slice(11)
}
data = data.join('\n')
let out = JSON.stringify(app.parser.parse(data), null, 2)
return out
}
</script>
<script>
let textCm = CodeMirror.fromTextArea(document.querySelector('#js-fileinput'), {
lineWrapping: true,
smartIndent: false,
})
let jsCm = CodeMirror.fromTextArea(document.querySelector('#js-fileoutput'), {
mode: "javascript",
lineWrapping: true,
readOnly: 'nocursor',
});
textCm.on('change', () => jsCm.setValue(loadDoc(textCm.getValue())))
</script>
<script>
const text = resp => resp.text()
function status(response) {
if (response.status >= 200 && response.status < 300) {
return response
} else {
var error = new Error(response.statusText)
error.response = response
throw error
}
}
function fetchDocList() {
return fetch('./datafiles.txt').then(status).then(text)
.then(t =>
t.split('\n')
.map(l => l.trim())
.filter(l => l))
}
function fetchDoc(fn) {
return fetch(`./data-raw/${fn}`).then(status).then(text)
}
function init() {
fetchDocList()
.then(docs => {
let opts = docs.map(d => html`<option value="${d}">${d}</option>`)
opts.forEach(o => document.querySelector('#js-docs').add(o))
})
}
document.addEventListener('DOMContentLoaded', init)
document.querySelector('#js-docs').addEventListener('change', e => {
let fn = e.target.value
console.log('selected', fn)
fetchDoc(fn)
.then(data => textCm.setValue(data))
})
</script>
</body>
</html>