@@ -22,7 +22,7 @@ export function lnHeader(ln: Element, nsDoc: Nsdoc): string {
22
22
23
23
const data = nsDoc . getDataDescription ( ln ) ;
24
24
25
- return `${ prefix != null ? `${ prefix } - ` : `` } ${ data . label } ${ inst ? ` - ${ inst } ` : `` } ` ;
25
+ return `${ prefix != null ? `${ prefix } - ` : `` } ${ data . label } ${ inst ? ` - ${ inst } ` : `` } ` ;
26
26
}
27
27
28
28
export function lDeviceHeader ( lDevice : Element ) : string {
@@ -34,9 +34,9 @@ export function lDeviceHeader(lDevice: Element): string {
34
34
35
35
export function iedHeader ( ied : Element ) : string {
36
36
const name = getNameAttribute ( ied ) ;
37
- const description = getDescriptionAttribute ( ied ) ;
37
+ const desc = getDescriptionAttribute ( ied ) ;
38
38
39
- return `${ name } ${ description !== undefined ? ' (' + description + ')' : '' } ` ;
39
+ return `${ name } ${ desc ? ' (' + desc + ')' : '' } ` ;
40
40
}
41
41
42
42
@@ -60,30 +60,35 @@ export function addPrefixAndNamespaceToDocument(element: Element): void {
60
60
}
61
61
}
62
62
63
- export function getPrivate ( element : Element ) : Element {
63
+ export function getPrivate ( element : Element ) : Element | null {
64
64
return element . querySelector ( `Private[type="${ LOCAMATION_PRIVATE } "]` ) ! ;
65
65
}
66
66
67
- export function createEditorAction ( locamationPrivate : Element , fieldType : string , value : string | null ) : SimpleAction [ ] {
68
- let privateField = Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ fieldType } "]` ) )
69
- . filter ( element => element . namespaceURI === LOCAMATION_NS )
70
- . pop ( ) ;
71
- if ( ! privateField ) {
72
- // Make sure the namespace is configured on the root element with the known prefix.
73
- addPrefixAndNamespaceToDocument ( locamationPrivate ) ;
74
-
75
- privateField = locamationPrivate . ownerDocument . createElementNS ( LOCAMATION_NS , "P" ) ;
76
- privateField . setAttribute ( "type" , fieldType ) ;
77
- privateField . textContent = value ;
78
- return [ { new : { parent : locamationPrivate , element : privateField } } ] ;
79
- }
67
+ export function createEditorAction ( locamationPrivate : Element | null , fieldType : string , value : string | null ) : SimpleAction [ ] {
68
+ if ( locamationPrivate ) {
69
+ let privateField = Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ fieldType } "]` ) )
70
+ . filter ( element => element . namespaceURI === LOCAMATION_NS )
71
+ . pop ( ) ;
72
+ if ( ! privateField ) {
73
+ // Make sure the namespace is configured on the root element with the known prefix.
74
+ addPrefixAndNamespaceToDocument ( locamationPrivate ) ;
75
+
76
+ privateField = locamationPrivate . ownerDocument . createElementNS ( LOCAMATION_NS , "P" ) ;
77
+ privateField . setAttribute ( "type" , fieldType ) ;
78
+ privateField . textContent = value ;
79
+ return [ { new : { parent : locamationPrivate , element : privateField } } ] ;
80
+ }
80
81
81
- const newPrivateField = cloneElement ( privateField , { } ) ;
82
- newPrivateField . textContent = value ;
83
- return [ { old : { element : privateField } , new : { element : newPrivateField } } ] ;
82
+ if ( privateField . textContent !== value ) {
83
+ const newPrivateField = cloneElement ( privateField , { } ) ;
84
+ newPrivateField . textContent = value ;
85
+ return [ { old : { element : privateField } , new : { element : newPrivateField } } ] ;
86
+ }
87
+ }
88
+ return [ ] ;
84
89
}
85
90
86
- export function hasPrivateElement ( locamationPrivate : Element , type : string ) : boolean {
91
+ export function hasPrivateElement ( locamationPrivate : Element | null , type : string ) : boolean {
87
92
if ( locamationPrivate ) {
88
93
return Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ type } "]` ) )
89
94
. filter ( element => element . namespaceURI === LOCAMATION_NS )
@@ -92,7 +97,7 @@ export function hasPrivateElement(locamationPrivate: Element, type: string): boo
92
97
return false ;
93
98
}
94
99
95
- export function getPrivateTextValue ( locamationPrivate : Element , type : string ) : string | null {
100
+ export function getPrivateTextValue ( locamationPrivate : Element | null , type : string ) : string | null {
96
101
if ( locamationPrivate ) {
97
102
const privateElement =
98
103
Array . from ( locamationPrivate . querySelectorAll ( `P[type="${ type } "]` ) )
0 commit comments