-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathMerge.ts
44 lines (37 loc) · 1.21 KB
/
Merge.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
import { css, html, LitElement, query, TemplateResult } from 'lit-element';
import { newWizardEvent } from '@openscd/open-scd/src/foundation.js';
import { mergeWizard } from '@openscd/open-scd/src/wizards.js';
export default class MergePlugin extends LitElement {
doc!: XMLDocument;
@query('#merge-plugin-input') pluginFileUI!: HTMLInputElement;
mergeDoc(event: Event): void {
const file =
(<HTMLInputElement | null>event.target)?.files?.item(0) ?? false;
if (file)
file.text().then(text => {
const doc = new DOMParser().parseFromString(text, 'application/xml');
this.dispatchEvent(
newWizardEvent(
mergeWizard(this.doc.documentElement, doc.documentElement)
)
);
});
this.pluginFileUI.onchange = null;
}
async run(): Promise<void> {
this.pluginFileUI.click();
}
render(): TemplateResult {
return html`<input @click=${(event: MouseEvent) =>
((<HTMLInputElement>event.target).value = '')} @change=${
this.mergeDoc
} id="merge-plugin-input" accept=".sed,.scd,.ssd,.isd,.iid,.cid,.icd" type="file"></input>`;
}
static styles = css`
input {
width: 0;
height: 0;
opacity: 0;
}
`;
}