@@ -4,6 +4,11 @@ import {Logger} from './utils/Logger';
44import { AbstractInputField } from './inputFields/AbstractInputField' ;
55import { InputFieldFactory , InputFieldType } from './inputFields/InputFieldFactory' ;
66
7+ export enum InputFieldMarkdownRenderChildType {
8+ INLINE_CODE_BLOCK ,
9+ CODE_BLOCK ,
10+ }
11+
712export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
813 plugin : MetaBindPlugin ;
914 metaData : any ;
@@ -24,7 +29,7 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
2429
2530 arguments : { name : string , value : any } [ ] ;
2631
27- constructor ( containerEl : HTMLElement , fullDeclaration : string , plugin : MetaBindPlugin , filePath : string , uid : number ) {
32+ constructor ( containerEl : HTMLElement , type : InputFieldMarkdownRenderChildType , fullDeclaration : string , plugin : MetaBindPlugin , filePath : string , uid : number ) {
2833 super ( containerEl ) ;
2934
3035 //console.log(this, 2)
@@ -43,6 +48,7 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
4348 this . parseDeclaration ( ) ;
4449
4550 this . inputField = InputFieldFactory . createInputField ( this . inputFieldType , {
51+ type : type ,
4652 inputFieldMarkdownRenderChild : this ,
4753 onValueChanged : this . updateMetaData . bind ( this ) ,
4854 } ) ;
@@ -100,31 +106,54 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
100106 }
101107
102108 if ( inputFieldArgumentName === 'addLabels' ) {
109+ if ( this . inputFieldType !== InputFieldType . SLIDER ) {
110+ throw new Error ( `argument \'${ inputFieldArgumentName } \' is only applicable to slider input fields` ) ;
111+ }
112+
103113 this . arguments . push ( { name : 'labels' , value : true } ) ;
104114 }
105115
106116 if ( inputFieldArgumentName === 'minValue' ) {
117+ if ( this . inputFieldType !== InputFieldType . SLIDER ) {
118+ throw new Error ( `argument \'${ inputFieldArgumentName } \' is only applicable to slider input fields` ) ;
119+ }
120+
107121 const inputFieldArgumentValue : string = this . extractInputFieldArgumentValue ( inputFieldArgument ) ;
108122 const inputFieldArgumentValueAsNumber : number = Number . parseInt ( inputFieldArgumentValue ) ;
109123
110124 if ( Number . isNaN ( inputFieldArgumentValueAsNumber ) ) {
111125 throw new Error ( `argument \'${ inputFieldArgumentName } \' value must be of type number` ) ;
112126 }
113127
114- let inputFieldClassArgument : { name : string , value : number } = { name : inputFieldArgumentName , value : inputFieldArgumentValueAsNumber } ;
115- this . arguments . push ( inputFieldClassArgument ) ;
128+ let inputFieldArgumentObject : { name : string , value : number } = { name : inputFieldArgumentName , value : inputFieldArgumentValueAsNumber } ;
129+ this . arguments . push ( inputFieldArgumentObject ) ;
116130 }
117131
118132 if ( inputFieldArgumentName === 'maxValue' ) {
133+ if ( this . inputFieldType !== InputFieldType . SLIDER ) {
134+ throw new Error ( `argument \'${ inputFieldArgumentName } \' is only applicable to slider input fields` ) ;
135+ }
136+
119137 const inputFieldArgumentValue : string = this . extractInputFieldArgumentValue ( inputFieldArgument ) ;
120138 const inputFieldArgumentValueAsNumber : number = Number . parseInt ( inputFieldArgumentValue ) ;
121139
122140 if ( Number . isNaN ( inputFieldArgumentValueAsNumber ) ) {
123141 throw new Error ( `argument \'${ inputFieldArgumentName } \' value must be of type number` ) ;
124142 }
125143
126- let inputFieldClassArgument : { name : string , value : number } = { name : inputFieldArgumentName , value : inputFieldArgumentValueAsNumber } ;
127- this . arguments . push ( inputFieldClassArgument ) ;
144+ let inputFieldArgumentObject : { name : string , value : number } = { name : inputFieldArgumentName , value : inputFieldArgumentValueAsNumber } ;
145+ this . arguments . push ( inputFieldArgumentObject ) ;
146+ }
147+
148+ if ( inputFieldArgumentName === 'option' ) {
149+ if ( this . inputFieldType !== InputFieldType . SELECT && this . inputFieldType !== InputFieldType . MULTI_SELECT ) {
150+ throw new Error ( `argument \'${ inputFieldArgumentName } \' is only applicable to select and multi-select input fields` ) ;
151+ }
152+
153+ const inputFieldArgumentValue : string = this . extractInputFieldArgumentValue ( inputFieldArgument ) ;
154+
155+ let inputFieldArgumentObject : { name : string , value : string } = { name : inputFieldArgumentName , value : inputFieldArgumentValue } ;
156+ this . arguments . push ( inputFieldArgumentObject ) ;
128157 }
129158 }
130159 }
@@ -200,16 +229,20 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
200229 }
201230
202231 updateValue ( value : any ) {
203- if ( value != null && this . inputField . getValue ( ) !== value && this . valueQueue . length === 0 ) {
204- Logger . logDebug ( `updating input field ${ this . uid } to '${ value . toString ( ) } '` ) ;
232+ if ( value == null ) {
233+ value = this . inputField . getDefaultValue ( ) ;
234+ }
235+
236+ if ( ! this . inputField . isEqualValue ( value ) && this . valueQueue . length === 0 ) {
237+ Logger . logDebug ( `updating input field ${ this . uid } to` , value ) ;
205238 this . inputField . setValue ( value ) ;
206239 }
207240 }
208241
209242 getInitialValue ( ) {
210243 // console.log(this);
211244 if ( this . isBound ) {
212- return this . metaData [ this . bindTargetMetadataField ] ;
245+ return this . metaData [ this . bindTargetMetadataField ] ?? this . inputField . getDefaultValue ( ) ;
213246 }
214247 }
215248
0 commit comments