Skip to content

Commit 3446f74

Browse files
committed
feature: add option to load libDoc
1 parent 2af123a commit 3446f74

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/compas-open-scd/src/open-scd.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import {
4141
} from '@openscd/open-scd/src/plugin.events.js';
4242
import { newLogEvent } from '@openscd/core/foundation/deprecated/history.js';
4343
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';
4448

4549
/** The `<open-scd>` custom element is the main entry point of the
4650
* Open Substation Configuration Designer. */
@@ -127,6 +131,18 @@ export class OpenSCD extends LitElement {
127131
if (src.startsWith('blob:')) URL.revokeObjectURL(src);
128132
}
129133

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);
143+
}
144+
}
145+
130146
/**
131147
*
132148
* @deprecated Use `handleConfigurationPluginEvent` instead
@@ -434,6 +450,7 @@ export class OpenSCD extends LitElement {
434450
validator: plugin.kind === 'validator',
435451
editor: plugin.kind === 'editor',
436452
})}"
453+
@request-libdoc=${(e: CustomEvent) => this.loadLNodeLib(e)}
437454
></${tag}>`;
438455
},
439456
};

0 commit comments

Comments
 (0)