import { css , html , LitElement , query , TemplateResult } from 'lit-element' ; import { newLogEvent , newOpenDocEvent } from '../foundation.js' ; export default class OpenProjectPlugin extends LitElement { @ query ( '#open-plugin-input' ) pluginFileUI ! : HTMLInputElement ; async openDoc ( event ) { const file = ( < HTMLInputElement | null > event . target ) ?. files ?. item ( 0 ) ?? false ; if ( ! file ) return ; const text = await file . text ( ) ; const docName = file . name ; const doc = new DOMParser ( ) . parseFromString ( text , 'application/xml' ) ; document . querySelector ( 'open-scd' ) ! . dispatchEvent ( newLogEvent ( { kind : 'reset' } ) ) ; document . querySelector ( 'open-scd' ) ! . dispatchEvent ( newOpenDocEvent ( doc , docName ) ) ; this . pluginFileUI . onchange = null ; } async run ( ) { this . pluginFileUI . click ( ) ; } render ( ) { return html `<input @click=${ ( event ) => ( ( < HTMLInputElement > event . target ) . value = '' ) } @change=${ this . openDoc } id="open-plugin-input" accept=".sed,.scd,.ssd,.iid,.cid,.icd" type="file"></input>` ; } static styles = css `
    input {
      width: 0;
      height: 0;
      opacity: 0;
    }
  ` ; }