11/* eslint-disable import/no-extraneous-dependencies */
2- import { css , html , LitElement } from 'lit' ;
2+ import { css , html , LitElement , nothing } from 'lit' ;
33import { property , state } from 'lit/decorators.js' ;
4- import { classMap } from 'lit/directives/class-map.js' ;
54
65import { ScopedElementsMixin } from '@open-wc/scoped-elements/lit-element.js' ;
76
@@ -12,6 +11,17 @@ import { GseControlEditor } from './editors/gsecontrol/gse-control-editor.js';
1211import { ReportControlEditor } from './editors/report/report-control-editor.js' ;
1312import { SampledValueControlEditor } from './editors/sampledvalue/sampled-value-control-editor.js' ;
1413
14+ const EditorSelector = {
15+ Report : 'report-control-editor' ,
16+ GOOSE : 'gse-control-editor' ,
17+ SampledValue : 'sampled-value-control-editor' ,
18+ DataSet : 'data-set-editor' ,
19+ } as const ;
20+
21+ type PublisherType = 'Report' | 'GOOSE' | 'SampledValue' | 'DataSet' ;
22+
23+ type EditorSelectorType = ( typeof EditorSelector ) [ keyof typeof EditorSelector ] ;
24+
1525/** An editor [[`plugin`]] to configure `Report`, `GOOSE`, `SampledValue` control blocks and its `DataSet` */
1626export default class PublisherPlugin extends ScopedElementsMixin ( LitElement ) {
1727 static scopedElements = {
@@ -31,8 +41,62 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
3141 editCount = 0 ;
3242
3343 @state ( )
34- private publisherType : 'Report' | 'GOOSE' | 'SampledValue' | 'DataSet' =
35- 'GOOSE' ;
44+ private publisherType : PublisherType = 'GOOSE' ;
45+
46+ private filterValues : Record < PublisherType , string > = {
47+ Report : '' ,
48+ GOOSE : '' ,
49+ SampledValue : '' ,
50+ DataSet : '' ,
51+ } ;
52+
53+ private saveCurrentSearchValue ( ) {
54+ const selector : EditorSelectorType = EditorSelector [ this . publisherType ] ;
55+ const editor = this . renderRoot . querySelector ( selector ) as {
56+ selectionList ?: { searchValue : string } ;
57+ } | null ;
58+
59+ if ( editor ) {
60+ this . filterValues [ this . publisherType ] =
61+ editor . selectionList ?. searchValue || '' ;
62+ }
63+ }
64+
65+ private handlePublisherTypeChange ( newType : PublisherType ) {
66+ this . saveCurrentSearchValue ( ) ;
67+ this . publisherType = newType ;
68+ }
69+
70+ private renderEditor ( ) {
71+ switch ( this . publisherType ) {
72+ case 'Report' :
73+ return html `<repor t- control- edito r
74+ .doc = ${ this . doc }
75+ .editCount = ${ this . editCount }
76+ .searchValue = ${ this . filterValues . Report }
77+ > </ repor t- control- edito r> ` ;
78+ case 'GOOSE' :
79+ return html `<gse- control- edito r
80+ .doc = ${ this . doc }
81+ .editCount = ${ this . editCount }
82+ .searchValue = ${ this . filterValues . GOOSE }
83+ > </ gse- control- edito r> ` ;
84+ case 'SampledValue' :
85+ return html `<sampled- value-control- edito r
86+ .doc = ${ this . doc }
87+ .editCount = ${ this . editCount }
88+ .searchValue = ${ this . filterValues . SampledValue }
89+ > </ sampled- value-control- edito r> ` ;
90+ case 'DataSet' :
91+ return html `<data- set- edito r
92+ .doc = ${ this . doc }
93+ .editCount = ${ this . editCount }
94+ .searchValue = ${ this . filterValues . DataSet }
95+ > </ data- set- edito r> ` ;
96+ default :
97+ return nothing ;
98+ }
99+ }
36100
37101 render ( ) {
38102 return html `<for m class= "publishertypeselector" >
@@ -41,9 +105,7 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
41105 id= "report-radio"
42106 value = "repor t"
43107 ?checked= ${ this . publisherType === 'Report' }
44- @change = ${ ( ) => {
45- this . publisherType = 'Report' ;
46- } }
108+ @change = ${ ( ) => this . handlePublisherTypeChange ( 'Report' ) }
47109 > </ md- radio>
48110 <label for = "report-radio" > Report </ label>
49111 </ span>
@@ -52,9 +114,7 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
52114 id= "goose-radio"
53115 value = "goose"
54116 ?checked= ${ this . publisherType === 'GOOSE' }
55- @change = ${ ( ) => {
56- this . publisherType = 'GOOSE' ;
57- } }
117+ @change = ${ ( ) => this . handlePublisherTypeChange ( 'GOOSE' ) }
58118 > </ md- radio>
59119 <label for = "goose-radio" > GOOSE </ label>
60120 </ span>
@@ -63,9 +123,7 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
63123 id= "smv-radio"
64124 value = "smv"
65125 ?checked= ${ this . publisherType === 'SampledValue' }
66- @change = ${ ( ) => {
67- this . publisherType = 'SampledValue' ;
68- } }
126+ @change = ${ ( ) => this . handlePublisherTypeChange ( 'SampledValue' ) }
69127 > </ md- radio>
70128 <label for = "smv-radio" > SampledValue </ label>
71129 </ span>
@@ -74,41 +132,12 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
74132 id= "ds-radio"
75133 value = "ds"
76134 ?checked= ${ this . publisherType === 'DataSet' }
77- @change = ${ ( ) => {
78- this . publisherType = 'DataSet' ;
79- } }
135+ @change = ${ ( ) => this . handlePublisherTypeChange ( 'DataSet' ) }
80136 > </ md- radio>
81137 <label for = "ds-radio" > DataSet </ label>
82138 </ span>
83139 </ for m>
84- <repor t- control- edito r
85- .doc = ${ this . doc }
86- editCount= "${ this . editCount } "
87- class = "${ classMap ( {
88- hidden : this . publisherType !== 'Report' ,
89- } ) } "
90- > </ repor t- control- edito r
91- > <gse- control- edito r
92- .doc = ${ this . doc }
93- editCount= "${ this . editCount } "
94- class = "${ classMap ( {
95- hidden : this . publisherType !== 'GOOSE' ,
96- } ) } "
97- > </ gse- control- edito r
98- > <sampled- value-control- edito r
99- .doc = ${ this . doc }
100- editCount= "${ this . editCount } "
101- class = "${ classMap ( {
102- hidden : this . publisherType !== 'SampledValue' ,
103- } ) } "
104- > </ sampled- value-control- edito r
105- > <data- set- edito r
106- .doc = ${ this . doc }
107- editCount= "${ this . editCount } "
108- class = "${ classMap ( {
109- hidden : this . publisherType !== 'DataSet' ,
110- } ) } "
111- > </ data- set- edito r> ` ;
140+ ${ this . renderEditor ( ) } ` ;
112141 }
113142
114143 static styles = css `
@@ -123,7 +152,7 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
123152 --md-sys-color-on-primary : var (--oscd-base2 );
124153 --md-sys-color-on-surface-variant : var (--oscd-base00 );
125154 --md-menu-container-color : var (--oscd-base3 );
126- font-family : var (--oscd-theme-text-font );
155+ font-family : var (--oscd-theme-text-font , Roboto );
127156 --md-sys-color-surface-container-highest : var (--oscd-base2 );
128157 --md-dialog-container-color : var (--oscd-base3 );
129158
0 commit comments