diff --git a/packages/compas-open-scd/src/open-scd.ts b/packages/compas-open-scd/src/open-scd.ts index 71ec8cf65b..dcc778e20b 100644 --- a/packages/compas-open-scd/src/open-scd.ts +++ b/packages/compas-open-scd/src/open-scd.ts @@ -41,6 +41,10 @@ import { } from '@openscd/open-scd/src/plugin.events.js'; import { newLogEvent } from '@openscd/core/foundation/deprecated/history.js'; import packageJson from '../package.json'; +import { CompasSclDataService } from './compas-services/CompasSclDataService.js'; +import { createLogEvent } from './compas-services/foundation.js'; + +const LNODE_LIB_DOC_ID = '3942f511-7d87-4482-bff9-056a98c6ce15'; /** The `` custom element is the main entry point of the * Open Substation Configuration Designer. */ @@ -61,6 +65,7 @@ export class OpenSCD extends LitElement { .docId=${this.docId} .host=${this} .editCount=${this.historyState.editCount} + .compasApi=${this.compasApi} > @@ -127,6 +133,36 @@ export class OpenSCD extends LitElement { if (src.startsWith('blob:')) URL.revokeObjectURL(src); } + private _lNodeLibrary: Document | null = null; + public compasApi: CompasApi; + + constructor() { + super(); + this.compasApi = { + lNodeLibrary: { + loadLNodeLibrary: async () => { + const doc = await this.loadLNodeLibrary(); + return doc; + }, + lNodeLibrary: () => this._lNodeLibrary, + }, + }; + } + + private async loadLNodeLibrary(): Promise { + try { + const doc = await CompasSclDataService().getSclDocument(this, 'SSD', LNODE_LIB_DOC_ID); + if (doc instanceof Document) { + this._lNodeLibrary = doc; + return doc; + } + return null; + } catch (reason) { + createLogEvent(this, reason); + return null; + } + } + /** * * @deprecated Use `handleConfigurationPluginEvent` instead @@ -428,6 +464,7 @@ export class OpenSCD extends LitElement { .nsdoc=${this.nsdoc} .docs=${this.docs} .locale=${this.locale} + .compasApi=${this.compasApi} class="${classMap({ plugin: true, menu: plugin.kind === 'menu', @@ -547,6 +584,14 @@ export function newSetPluginsEvent(selectedPlugins: Plugin[]): SetPluginsEvent { }); } + +export interface CompasApi { + lNodeLibrary: { + loadLNodeLibrary: () => Promise; + lNodeLibrary: () => Document | null; + }; +} + /** * This is a template literal tag function. See: * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates