-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoscd-open.ts
38 lines (31 loc) · 939 Bytes
/
oscd-open.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
import { html, LitElement } from 'lit';
import { query } from 'lit/decorators.js';
import { newOpenEvent } from '@openscd/open-scd-core';
export default class OscdOpen extends LitElement {
@query('input')
input!: HTMLInputElement;
async run() {
this.input.click();
}
async openDoc(event: Event): Promise<void> {
const file = (<HTMLInputElement | null>event.target)?.files?.item(0);
if (!file) return;
const text = await file.text();
const docName = file.name;
const doc = new DOMParser().parseFromString(text, 'application/xml');
this.dispatchEvent(newOpenEvent(doc, docName));
this.input.onchange = null;
}
render() {
return html`
<input
@click=${({ target }: MouseEvent) => {
// eslint-disable-next-line no-param-reassign
(<HTMLInputElement>target).value = '';
}}
@change=${this.openDoc}
type="file"
/>
`;
}
}