-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
config.ts
67 lines (59 loc) · 1.58 KB
/
config.ts
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
import {get} from '../../../state';
import {CustomElement} from '../../../util/custom-element';
import './config.css';
// State keys we care about.
const keys = ['page', 'page.header', 'page.footer'].reduce<string[]>(
(out, key) =>
out.concat([
`config.style.${key}.font`,
`config.style.${key}.color`,
`config.style.${key}.link.font`,
`config.style.${key}.link.color`,
`config.style.${key}.link.lineColor`,
`config.style.${key}.link.active.font`,
`config.style.${key}.link.active.color`,
`config.style.${key}.link.active.lineColor`
]),
[]
);
/**
* Shows a read-only text field showing code that reflects the current style.
* It's available as `<backstage-style-config>` and is used by the Config
* section of the Style backstage tab.
*/
export class StyleConfig extends CustomElement {
connectedCallback() {
this.defaultHtml(`
<details open>
<summary>Config</summary>
<label for="cb-backstage-style-config">
Enter this code into your first passage’s variables section to
permanently use this style:
</label>
<textarea
readonly
id="cb-backstage-style-config"
></textarea>
</details>
`);
window.addEventListener('state-change', this);
this.update();
}
disconnectedCallback() {
window.removeEventListener('state-change', this);
}
handleEvent() {
this.update();
}
update() {
this.query<HTMLTextAreaElement>('textarea').value = keys
.reduce((out, key) => {
const value = get(key);
if (value) {
return out + `${key}: ${JSON.stringify(value)}\n`;
}
return out;
}, '')
.trim();
}
}