@@ -41,6 +41,10 @@ import {
4141} from '@openscd/open-scd/src/plugin.events.js' ;
4242import { newLogEvent } from '@openscd/core/foundation/deprecated/history.js' ;
4343import 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' ;
4448
4549/** The `<open-scd>` custom element is the main entry point of the
4650 * Open Substation Configuration Designer. */
@@ -61,6 +65,7 @@ export class OpenSCD extends LitElement {
6165 .docId=${ this . docId }
6266 .host=${ this }
6367 .editCount=${ this . historyState . editCount }
68+ .compasApi=${ this . compasApi }
6469 >
6570 <compas-layout
6671 @add-external-plugin=${ this . handleAddExternalPlugin }
@@ -73,6 +78,7 @@ export class OpenSCD extends LitElement {
7378 .editCount=${ this . historyState . editCount }
7479 .historyState=${ this . historyState }
7580 .plugins=${ this . storedPlugins }
81+ .compasApi=${ this . compasApi }
7682 >
7783 </compas-layout>
7884 </oscd-editor>
@@ -127,6 +133,36 @@ export class OpenSCD extends LitElement {
127133 if ( src . startsWith ( 'blob:' ) ) URL . revokeObjectURL ( src ) ;
128134 }
129135
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+
130166 /**
131167 *
132168 * @deprecated Use `handleConfigurationPluginEvent` instead
@@ -428,6 +464,7 @@ export class OpenSCD extends LitElement {
428464 .nsdoc=${ this . nsdoc }
429465 .docs=${ this . docs }
430466 .locale=${ this . locale }
467+ .compasApi=${ this . compasApi }
431468 class="${ classMap ( {
432469 plugin : true ,
433470 menu : plugin . kind === 'menu' ,
@@ -547,6 +584,14 @@ export function newSetPluginsEvent(selectedPlugins: Plugin[]): SetPluginsEvent {
547584 } ) ;
548585}
549586
587+
588+ export interface CompasApi {
589+ lNodeLibrary : {
590+ loadLNodeLibrary : ( ) => Promise < Document | null > ;
591+ lNodeLibrary : ( ) => Document | null ;
592+ } ;
593+ }
594+
550595/**
551596 * This is a template literal tag function. See:
552597 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
0 commit comments