@@ -65,6 +65,7 @@ export class OpenSCD extends LitElement {
65
65
.docId=${ this . docId }
66
66
.host=${ this }
67
67
.editCount=${ this . historyState . editCount }
68
+ .compasApi=${ this . compasApi }
68
69
>
69
70
<compas-layout
70
71
@add-external-plugin=${ this . handleAddExternalPlugin }
@@ -77,6 +78,7 @@ export class OpenSCD extends LitElement {
77
78
.editCount=${ this . historyState . editCount }
78
79
.historyState=${ this . historyState }
79
80
.plugins=${ this . storedPlugins }
81
+ .compasApi=${ this . compasApi }
80
82
>
81
83
</compas-layout>
82
84
</oscd-editor>
@@ -131,15 +133,30 @@ export class OpenSCD extends LitElement {
131
133
if ( src . startsWith ( 'blob:' ) ) URL . revokeObjectURL ( src ) ;
132
134
}
133
135
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 ;
143
160
}
144
161
}
145
162
@@ -444,13 +461,13 @@ export class OpenSCD extends LitElement {
444
461
.nsdoc=${ this . nsdoc }
445
462
.docs=${ this . docs }
446
463
.locale=${ this . locale }
464
+ .compasApi=${ this . compasApi }
447
465
class="${ classMap ( {
448
466
plugin : true ,
449
467
menu : plugin . kind === 'menu' ,
450
468
validator : plugin . kind === 'validator' ,
451
469
editor : plugin . kind === 'editor' ,
452
470
} ) } "
453
- @request-libdoc=${ ( e : CustomEvent ) => this . loadLNodeLib ( e ) }
454
471
></${ tag } >` ;
455
472
} ,
456
473
} ;
@@ -564,6 +581,14 @@ export function newSetPluginsEvent(selectedPlugins: Plugin[]): SetPluginsEvent {
564
581
} ) ;
565
582
}
566
583
584
+
585
+ export interface CompasApi {
586
+ lNodeLibrary : {
587
+ loadLNodeLibrary : ( ) => Promise < Document | null > ;
588
+ lNodeLibrary : ( ) => Document | null ;
589
+ } ;
590
+ }
591
+
567
592
/**
568
593
* This is a template literal tag function. See:
569
594
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
0 commit comments