blob: a4b51dd95114cd4c00fd1dfcc0d2719dd4bff63b (
plain)
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
|
/**
* `<vevent-dl />`
*
* A description list of a vevent, used for debugging.
*
* No guarantees are given about the contents of the data fields, more
* than that they are related to the value in question.
*
* @category Web Components
* @mergeTarget components
* @module
*/
export { VEventDL }
import { ComponentVEvent } from './vevent'
import { VEvent } from '../vevent'
import { makeElement } from '../lib'
import { RecurrenceRule } from '../vevent'
/* <vevent-dl /> */
class VEventDL extends ComponentVEvent {
redraw(obj: VEvent) {
let dl = buildDescriptionList(
Array.from(obj.boundProperties)
.map(key => [key, obj.getProperty(key)]))
this.replaceChildren(dl);
}
}
function buildDescriptionList(data: [string, any][]): HTMLElement {
let dl = document.createElement('dl');
for (let [key, val] of data) {
dl.appendChild(makeElement('dt', { textContent: key }))
let fmtVal: string = val;
if (val instanceof Date) {
fmtVal = val.format(
val.dateonly
? '~Y-~m-~d'
: '~Y-~m-~dT~H:~M:~S');
} else if (val instanceof RecurrenceRule) {
fmtVal = JSON.stringify(val.to_jcal())
}
dl.appendChild(makeElement('dd', { textContent: fmtVal }))
}
return dl;
}
|