-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoscd-save.ts
32 lines (27 loc) · 916 Bytes
/
oscd-save.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
import { html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
export default class OscdSave extends LitElement {
@property() doc!: XMLDocument;
@property() docName!: string;
async run() {
if (this.doc) {
const blob = new Blob([new XMLSerializer().serializeToString(this.doc)], {
type: 'application/xml',
});
const a = document.createElement('a');
a.download = this.docName;
a.href = URL.createObjectURL(blob);
a.dataset.downloadurl = ['application/xml', a.download, a.href].join(':');
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
setTimeout(() => {
URL.revokeObjectURL(a.href);
}, 5000); // TODO(ca-d): discuss revoke timeout length
}
}
render() {
return html`<button @click=${() => this.run()}>Save project</button>`;
}
}