@@ -65,6 +65,7 @@ export class OpenSCD extends LitElement {
6565 .docId=${ this . docId }
6666 .host=${ this }
6767 .editCount=${ this . historyState . editCount }
68+ .compasApi=${ this . compasApi }
6869 >
6970 <compas-layout
7071 @add-external-plugin=${ this . handleAddExternalPlugin }
@@ -77,6 +78,7 @@ export class OpenSCD extends LitElement {
7778 .editCount=${ this . historyState . editCount }
7879 .historyState=${ this . historyState }
7980 .plugins=${ this . storedPlugins }
81+ .compasApi=${ this . compasApi }
8082 >
8183 </compas-layout>
8284 </oscd-editor>
@@ -131,15 +133,30 @@ export class OpenSCD extends LitElement {
131133 if ( src . startsWith ( 'blob:' ) ) URL . revokeObjectURL ( src ) ;
132134 }
133135
134- /** Loads the LNodeTypeDB.ssd document from the CompasSclDataService */
135- private async loadLNodeLib ( e : CustomEvent ) : Promise < void > {
136- const doc = await CompasSclDataService ( )
137- . getSclDocument ( this , 'SSD' , LNODE_LIB_DOC_ID )
138- . catch ( reason => createLogEvent ( this , reason ) ) ;
139- if ( doc instanceof Document ) {
140- e . detail . callback ( doc ) ;
141- } else {
142- e . detail . callback ( undefined ) ;
136+ private _lNodeLibrary : Document | null = null ;
137+ public compasApi : CompasApi ;
138+
139+ constructor ( ) {
140+ super ( ) ;
141+ this . compasApi = {
142+ lNodeLibrary : {
143+ loadLNodeLibrary : async ( ) => {
144+ if ( this . _lNodeLibrary ) return this . _lNodeLibrary ;
145+ this . _lNodeLibrary = await this . loadLNodeLibrary ( ) ;
146+ return this . _lNodeLibrary ;
147+ } ,
148+ lNodeLibrary : ( ) => this . _lNodeLibrary ,
149+ } ,
150+ } ;
151+ }
152+
153+ private async loadLNodeLibrary ( ) : Promise < Document | null > {
154+ try {
155+ const doc = await CompasSclDataService ( ) . getSclDocument ( this , 'SSD' , LNODE_LIB_DOC_ID ) ;
156+ return doc instanceof Document ? doc : null ;
157+ } catch ( reason ) {
158+ createLogEvent ( this , reason ) ;
159+ return null ;
143160 }
144161 }
145162
@@ -444,13 +461,13 @@ export class OpenSCD extends LitElement {
444461 .nsdoc=${ this . nsdoc }
445462 .docs=${ this . docs }
446463 .locale=${ this . locale }
464+ .compasApi=${ this . compasApi }
447465 class="${ classMap ( {
448466 plugin : true ,
449467 menu : plugin . kind === 'menu' ,
450468 validator : plugin . kind === 'validator' ,
451469 editor : plugin . kind === 'editor' ,
452470 } ) } "
453- @request-libdoc=${ ( e : CustomEvent ) => this . loadLNodeLib ( e ) }
454471 ></${ tag } >` ;
455472 } ,
456473 } ;
@@ -564,6 +581,14 @@ export function newSetPluginsEvent(selectedPlugins: Plugin[]): SetPluginsEvent {
564581 } ) ;
565582}
566583
584+
585+ export interface CompasApi {
586+ lNodeLibrary : {
587+ loadLNodeLibrary : ( ) => Promise < Document | null > ;
588+ lNodeLibrary : ( ) => Document | null ;
589+ } ;
590+ }
591+
567592/**
568593 * This is a template literal tag function. See:
569594 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
0 commit comments