1- import { Nsdoc } from ' @openscd/open-scd/src/foundation/nsdoc.js' ;
1+ import { Nsdoc } from " @openscd/open-scd/src/foundation/nsdoc.js" ;
22
33import {
44 getDescriptionAttribute ,
55 getInstanceAttribute ,
66 getNameAttribute ,
77 getValue ,
8- WizardInputElement ,
9- } from ' @openscd/open-scd/src/foundation.js' ;
10- import { cloneElement } from '@compas-oscd /xml' ;
11- import { SimpleAction } from ' @openscd/core/foundation/deprecated/editor.js' ;
8+ WizardInputElement
9+ } from " @openscd/open-scd/src/foundation.js" ;
10+ import { cloneElement } from '@openscd /xml' ;
11+ import { SimpleAction } from " @openscd/core/foundation/deprecated/editor.js" ;
1212
13- export const LOCAMATION_MANUFACTURER = 'Locamation B.V.' ;
14- export const LOCAMATION_PRIVATE = 'LCMTN_VMU_SENSOR' ;
15- export const LOCAMATION_NS = 'https://www.locamation.com/61850/VMU/SCL' ;
16- export const LOCAMATION_PREFIX = 'lcmtn_ext' ;
13+
14+
15+ export const LOCAMATION_MANUFACTURER = "Locamation B.V." ;
16+ export const LOCAMATION_PRIVATE = "LCMTN_VMU_SENSOR" ;
17+ export const LOCAMATION_NS = "https://www.locamation.com/61850/VMU/SCL" ;
18+ export const LOCAMATION_PREFIX = "lcmtn_ext" ;
1719
1820export function lnHeader ( ln : Element , nsDoc : Nsdoc ) : string {
1921 const prefix = ln . getAttribute ( 'prefix' ) ;
2022 const inst = getInstanceAttribute ( ln ) ;
2123
2224 const data = nsDoc . getDataDescription ( ln ) ;
2325
24- return `${ prefix != null ? `${ prefix } - ` : `` } ${ data . label } ${
25- inst ? ` - ${ inst } ` : ``
26- } `;
26+ return `${ prefix != null ? `${ prefix } - ` : `` } ${ data . label } ${ inst ? ` - ${ inst } ` : `` } ` ;
2727}
2828
2929export function lDeviceHeader ( lDevice : Element ) : string {
@@ -40,99 +40,70 @@ export function iedHeader(ied: Element): string {
4040 return `${ name } ${ desc ? ' (' + desc + ')' : '' } ` ;
4141}
4242
43- export function getInputFieldValue (
44- inputs : WizardInputElement [ ] ,
45- id : string
46- ) : string | null {
43+
44+ export function getInputFieldValue ( inputs : WizardInputElement [ ] , id : string ) : string | null {
4745 return getValue ( inputs . find ( i => i . id === id ) ! ) ;
4846}
4947
50- export function inputFieldChanged (
51- inputs : WizardInputElement [ ] ,
52- id : string ,
53- oldValue : string | null
54- ) : boolean {
48+ export function inputFieldChanged ( inputs : WizardInputElement [ ] , id : string , oldValue : string | null ) : boolean {
5549 const value = getInputFieldValue ( inputs , id ) ;
5650 if ( oldValue ) {
5751 return value !== oldValue ;
5852 }
5953 return value !== null ;
6054}
6155
56+
6257export function addPrefixAndNamespaceToDocument ( element : Element ) : void {
6358 const rootElement = element . ownerDocument . firstElementChild ! ;
6459 if ( ! rootElement . hasAttribute ( 'xmlns:' + LOCAMATION_PREFIX ) ) {
65- rootElement . setAttributeNS (
66- 'http://www.w3.org/2000/xmlns/' ,
67- 'xmlns:' + LOCAMATION_PREFIX ,
68- LOCAMATION_NS
69- ) ;
60+ rootElement . setAttributeNS ( 'http://www.w3.org/2000/xmlns/' , 'xmlns:' + LOCAMATION_PREFIX , LOCAMATION_NS ) ;
7061 }
7162}
7263
7364export function getPrivate ( element : Element ) : Element | null {
7465 return element . querySelector ( `Private[type="${ LOCAMATION_PRIVATE } "]` ) ! ;
7566}
7667
77- export function createEditorAction (
78- locamationPrivate : Element | null ,
79- fieldType : string ,
80- value : string | null
81- ) : SimpleAction [ ] {
68+ export function createEditorAction ( locamationPrivate : Element | null , fieldType : string , value : string | null ) : SimpleAction [ ] {
8269 if ( locamationPrivate ) {
83- let privateField = Array . from (
84- locamationPrivate . querySelectorAll ( `P[type="${ fieldType } "]` )
85- )
70+ let privateField = Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ fieldType } "]` ) )
8671 . filter ( element => element . namespaceURI === LOCAMATION_NS )
8772 . pop ( ) ;
8873 if ( ! privateField ) {
8974 // Make sure the namespace is configured on the root element with the known prefix.
9075 addPrefixAndNamespaceToDocument ( locamationPrivate ) ;
9176
92- privateField = locamationPrivate . ownerDocument . createElementNS (
93- LOCAMATION_NS ,
94- 'P'
95- ) ;
96- privateField . setAttribute ( 'type' , fieldType ) ;
77+ privateField = locamationPrivate . ownerDocument . createElementNS ( LOCAMATION_NS , "P" ) ;
78+ privateField . setAttribute ( "type" , fieldType ) ;
9779 privateField . textContent = value ;
98- return [ { new : { parent : locamationPrivate , element : privateField } } ] ;
80+ return [ { new : { parent : locamationPrivate , element : privateField } } ] ;
9981 }
10082
10183 if ( privateField . textContent !== value ) {
10284 const newPrivateField = cloneElement ( privateField , { } ) ;
10385 newPrivateField . textContent = value ;
104- return [
105- { old : { element : privateField } , new : { element : newPrivateField } } ,
106- ] ;
86+ return [ { old : { element : privateField } , new : { element : newPrivateField } } ] ;
10787 }
10888 }
10989 return [ ] ;
11090}
11191
112- export function hasPrivateElement (
113- locamationPrivate : Element | null ,
114- type : string
115- ) : boolean {
92+ export function hasPrivateElement ( locamationPrivate : Element | null , type : string ) : boolean {
11693 if ( locamationPrivate ) {
117- return (
118- Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ type } "]` ) )
119- . filter ( element => element . namespaceURI === LOCAMATION_NS )
120- . pop ( ) !== undefined
121- ) ;
94+ return Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ type } "]` ) )
95+ . filter ( element => element . namespaceURI === LOCAMATION_NS )
96+ . pop ( ) !== undefined ;
12297 }
12398 return false ;
12499}
125100
126- export function getPrivateTextValue (
127- locamationPrivate : Element | null ,
128- type : string
129- ) : string | null {
101+ export function getPrivateTextValue ( locamationPrivate : Element | null , type : string ) : string | null {
130102 if ( locamationPrivate ) {
131- const privateElement = Array . from (
132- locamationPrivate . querySelectorAll ( `P[type="${ type } "]` )
133- )
134- . filter ( element => element . namespaceURI === LOCAMATION_NS )
135- . pop ( ) ;
103+ const privateElement =
104+ Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ type } "]` ) )
105+ . filter ( element => element . namespaceURI === LOCAMATION_NS )
106+ . pop ( ) ;
136107 if ( privateElement ) {
137108 return privateElement . textContent ;
138109 }
0 commit comments