@@ -41,6 +41,10 @@ import {
41
41
} from '@openscd/open-scd/src/plugin.events.js' ;
42
42
import { newLogEvent } from '@openscd/core/foundation/deprecated/history.js' ;
43
43
import packageJson from '../package.json' ;
44
+ import { CompasSclDataService } from './compas-services/CompasSclDataService.js' ;
45
+ import { createLogEvent } from './compas-services/foundation.js' ;
46
+
47
+ const LNODE_LIB_DOC_ID = '3942f511-7d87-4482-bff9-056a98c6ce15' ;
44
48
45
49
/** The `<open-scd>` custom element is the main entry point of the
46
50
* Open Substation Configuration Designer. */
@@ -61,6 +65,7 @@ export class OpenSCD extends LitElement {
61
65
.docId=${ this . docId }
62
66
.host=${ this }
63
67
.editCount=${ this . historyState . editCount }
68
+ .compasApi=${ this . compasApi }
64
69
>
65
70
<compas-layout
66
71
@add-external-plugin=${ this . handleAddExternalPlugin }
@@ -73,6 +78,7 @@ export class OpenSCD extends LitElement {
73
78
.editCount=${ this . historyState . editCount }
74
79
.historyState=${ this . historyState }
75
80
.plugins=${ this . storedPlugins }
81
+ .compasApi=${ this . compasApi }
76
82
>
77
83
</compas-layout>
78
84
</oscd-editor>
@@ -127,6 +133,36 @@ export class OpenSCD extends LitElement {
127
133
if ( src . startsWith ( 'blob:' ) ) URL . revokeObjectURL ( src ) ;
128
134
}
129
135
136
+ private _lNodeLibrary : Document | null = null ;
137
+ public compasApi : CompasApi ;
138
+
139
+ constructor ( ) {
140
+ super ( ) ;
141
+ this . compasApi = {
142
+ lNodeLibrary : {
143
+ loadLNodeLibrary : async ( ) => {
144
+ const doc = await this . loadLNodeLibrary ( ) ;
145
+ return doc ;
146
+ } ,
147
+ lNodeLibrary : ( ) => this . _lNodeLibrary ,
148
+ } ,
149
+ } ;
150
+ }
151
+
152
+ private async loadLNodeLibrary ( ) : Promise < Document | null > {
153
+ try {
154
+ const doc = await CompasSclDataService ( ) . getSclDocument ( this , 'SSD' , LNODE_LIB_DOC_ID ) ;
155
+ if ( doc instanceof Document ) {
156
+ this . _lNodeLibrary = doc ;
157
+ return doc ;
158
+ }
159
+ return null ;
160
+ } catch ( reason ) {
161
+ createLogEvent ( this , reason ) ;
162
+ return null ;
163
+ }
164
+ }
165
+
130
166
/**
131
167
*
132
168
* @deprecated Use `handleConfigurationPluginEvent` instead
@@ -428,6 +464,7 @@ export class OpenSCD extends LitElement {
428
464
.nsdoc=${ this . nsdoc }
429
465
.docs=${ this . docs }
430
466
.locale=${ this . locale }
467
+ .compasApi=${ this . compasApi }
431
468
class="${ classMap ( {
432
469
plugin : true ,
433
470
menu : plugin . kind === 'menu' ,
@@ -547,6 +584,14 @@ export function newSetPluginsEvent(selectedPlugins: Plugin[]): SetPluginsEvent {
547
584
} ) ;
548
585
}
549
586
587
+
588
+ export interface CompasApi {
589
+ lNodeLibrary : {
590
+ loadLNodeLibrary : ( ) => Promise < Document | null > ;
591
+ lNodeLibrary : ( ) => Document | null ;
592
+ } ;
593
+ }
594
+
550
595
/**
551
596
* This is a template literal tag function. See:
552
597
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
0 commit comments