-
Notifications
You must be signed in to change notification settings - Fork 0
/
addon.js
67 lines (67 loc) · 1.96 KB
/
addon.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
{
let UIChan = channels.get('UI');
if(!UIState) {
var UIState = {};
}
let idkey = 0;
let group = [];
let stack = [group];
var UI = {
done() {
UIChan.send(group);
},
button(name, {key = name} = {}) {
stack[0].push({t: 'button', name, key});
old = UIState[key];
UIState[key] = false;
return old;
},
toggle(name, {key = name, def = false} = {}) {
let val = UIState[key] ?? def;
stack[0].push({t: 'toggle', name, key, val});
return val;
},
line() {
stack[0].push({t: 'line', key: idkey++});
},
field(key, {def = ''} = {}) {
let val = UIState[key] ?? def;
stack[0].push({t: 'field', key, val});
return val;
},
label(label) {
stack[0].push({t: 'label', label: label, key: idkey++});
},
range(key, min, max, {def = min} = {}) {
let val = UIState[key] ?? def;
stack[0].push({t: 'range', min, max, key, val});
return val;
},
select(key, options, {def} = {}) {
let val = UIState[key] ?? def;
if(Array.isArray(options)) {
options = Object.fromEntries(options.map(opt => ([opt, opt])));
}
stack[0].push({t: 'select', options, key, val});
return val;
},
pickSpot(name, {key = name} = {}) {
stack[0].push({t: 'pickSpot', name, key});
return UIState[key];
},
beginCol({grow = false} = {}) {
let newCol = [];
stack[0].push({t: 'col', items: newCol, key: idkey++, grow});
stack.unshift(newCol);
},
endCol() {
stack.shift();
}
}
let data = channels.recv('UI');
if(data) {
for(var d of data) {
UIState[d.key] = d.value;
}
}
}