Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions packages/compas-open-scd/src/open-scd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<open-scd>` custom element is the main entry point of the
* Open Substation Configuration Designer. */
Expand All @@ -61,6 +65,7 @@ export class OpenSCD extends LitElement {
.docId=${this.docId}
.host=${this}
.editCount=${this.historyState.editCount}
.compasApi=${this.compasApi}
>
<compas-layout
@add-external-plugin=${this.handleAddExternalPlugin}
Expand All @@ -73,6 +78,7 @@ export class OpenSCD extends LitElement {
.editCount=${this.historyState.editCount}
.historyState=${this.historyState}
.plugins=${this.storedPlugins}
.compasApi=${this.compasApi}
>
</compas-layout>
</oscd-editor>
Expand Down Expand Up @@ -127,6 +133,33 @@ 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 () => {
if (this._lNodeLibrary) return this._lNodeLibrary;
this._lNodeLibrary = await this.loadLNodeLibrary();
return this._lNodeLibrary;
},
lNodeLibrary: () => this._lNodeLibrary,
},
};
}

private async loadLNodeLibrary(): Promise<Document | null> {
try {
const doc = await CompasSclDataService().getSclDocument(this, 'SSD', LNODE_LIB_DOC_ID);
return doc instanceof Document ? doc : null;
} catch (reason) {
createLogEvent(this, reason);
return null;
}
}

/**
*
* @deprecated Use `handleConfigurationPluginEvent` instead
Expand Down Expand Up @@ -428,6 +461,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',
Expand Down Expand Up @@ -547,6 +581,14 @@ export function newSetPluginsEvent(selectedPlugins: Plugin[]): SetPluginsEvent {
});
}


export interface CompasApi {
lNodeLibrary: {
loadLNodeLibrary: () => Promise<Document | null>;
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
Expand Down