@@ -90,53 +90,96 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
9090
9191 inputFieldArguments = inputFieldArguments . map ( x => x . trim ( ) ) ;
9292 for ( const inputFieldArgument of inputFieldArguments ) {
93- if ( inputFieldArgument . startsWith ( 'class' ) ) {
94- let classArgumentsString : string = inputFieldArgumentsRegExp . exec ( inputFieldArgument ) [ 0 ] ;
95- if ( ! classArgumentsString && classArgumentsString . length >= 2 ) {
96- throw new Error ( 'class needs an argument' ) ;
97- }
98- classArgumentsString = classArgumentsString . substring ( 1 , classArgumentsString . length - 1 ) ;
99- if ( ! classArgumentsString ) {
100- throw new Error ( 'class argument can not be empty' ) ;
101- }
93+ const inputFieldArgumentName : string = this . extractInputFieldArgumentName ( inputFieldArgument ) ;
10294
103- let inputFieldStyleArgument : { name : string , value : string } = { name : 'class' , value : classArgumentsString } ;
95+ if ( inputFieldArgumentName === 'class' ) {
96+ const inputFieldArgumentValue : string = this . extractInputFieldArgumentValue ( inputFieldArgument ) ;
10497
105- this . arguments . push ( inputFieldStyleArgument ) ;
98+ let inputFieldClassArgument : { name : string , value : string } = { name : inputFieldArgumentName , value : inputFieldArgumentValue } ;
99+ this . arguments . push ( inputFieldClassArgument ) ;
106100 }
107101
108- if ( inputFieldArgument . startsWith ( 'addLabels' ) ) {
102+ if ( inputFieldArgumentName === 'addLabels' ) {
109103 this . arguments . push ( { name : 'labels' , value : true } ) ;
110104 }
105+
106+ if ( inputFieldArgumentName === 'minValue' ) {
107+ const inputFieldArgumentValue : string = this . extractInputFieldArgumentValue ( inputFieldArgument ) ;
108+ const inputFieldArgumentValueAsNumber : number = Number . parseInt ( inputFieldArgumentValue ) ;
109+
110+ if ( Number . isNaN ( inputFieldArgumentValueAsNumber ) ) {
111+ throw new Error ( `argument \'${ inputFieldArgumentName } \' value must be of type number` ) ;
112+ }
113+
114+ let inputFieldClassArgument : { name : string , value : number } = { name : inputFieldArgumentName , value : inputFieldArgumentValueAsNumber } ;
115+ this . arguments . push ( inputFieldClassArgument ) ;
116+ }
117+
118+ if ( inputFieldArgumentName === 'maxValue' ) {
119+ const inputFieldArgumentValue : string = this . extractInputFieldArgumentValue ( inputFieldArgument ) ;
120+ const inputFieldArgumentValueAsNumber : number = Number . parseInt ( inputFieldArgumentValue ) ;
121+
122+ if ( Number . isNaN ( inputFieldArgumentValueAsNumber ) ) {
123+ throw new Error ( `argument \'${ inputFieldArgumentName } \' value must be of type number` ) ;
124+ }
125+
126+ let inputFieldClassArgument : { name : string , value : number } = { name : inputFieldArgumentName , value : inputFieldArgumentValueAsNumber } ;
127+ this . arguments . push ( inputFieldClassArgument ) ;
128+ }
111129 }
112130 }
113131
132+ extractInputFieldArgumentName ( argumentString : string ) : string {
133+ const argumentsRegExp : RegExp = new RegExp ( / \( .* \) / ) ;
134+
135+ return argumentString . replace ( argumentsRegExp , '' ) ;
136+ }
137+
138+ extractInputFieldArgumentValue ( argumentString : string ) : string {
139+ const argumentsRegExp : RegExp = new RegExp ( / \( .* \) / ) ;
140+
141+ let argumentName = this . extractInputFieldArgumentName ( argumentString ) ;
142+
143+ let argumentValueRegExpResult = argumentsRegExp . exec ( argumentString ) ;
144+ if ( ! argumentValueRegExpResult ) {
145+ throw new Error ( `argument \'${ argumentName } \' requires a value` ) ;
146+ }
147+ let argumentValue = argumentsRegExp . exec ( argumentString ) [ 0 ] ;
148+ if ( ! argumentValue && argumentValue . length >= 2 ) {
149+ throw new Error ( `argument \'${ argumentName } \' requires a value` ) ;
150+ }
151+ argumentValue = argumentValue . substring ( 1 , argumentValue . length - 1 ) ;
152+ if ( ! argumentValue ) {
153+ throw new Error ( `argument \'${ argumentName } \' value can not be empty` ) ;
154+ }
155+
156+ return argumentValue ;
157+ }
158+
114159 parseBindTarget ( bindTarget : string ) {
115160 let bindTargetParts = bindTarget . split ( '#' ) ;
116161 if ( bindTargetParts . length === 1 ) { // same file
117162 this . bindTargetMetadataField = bindTarget ;
118163 const files = this . plugin . getFilesByName ( this . filePath ) ;
119164 if ( files . length === 0 ) {
120- this . error = 'file not fond.' ;
121- return ;
165+ throw new Error ( 'file not found' ) ;
122166 } else if ( files . length === 1 ) {
123167 this . file = files [ 0 ] ;
124168 } else {
125- throw new Error ( 'multiple files found. please specify the file path. ' ) ;
169+ throw new Error ( 'multiple files found. please specify the file path' ) ;
126170 }
127171 } else if ( bindTargetParts . length === 2 ) {
128172 this . bindTargetMetadataField = bindTargetParts [ 1 ] ;
129173 const files = this . plugin . getFilesByName ( bindTargetParts [ 0 ] ) ;
130174 if ( files . length === 0 ) {
131- this . error = 'file not fond.' ;
132- return ;
175+ throw new Error ( 'file not found' ) ;
133176 } else if ( files . length === 1 ) {
134177 this . file = files [ 0 ] ;
135178 } else {
136- throw new Error ( 'multiple files found. please specify the file path. ' ) ;
179+ throw new Error ( 'multiple files found. please specify the file path' ) ;
137180 }
138181 } else {
139- throw new Error ( 'invalid binding. ' ) ;
182+ throw new Error ( 'invalid binding' ) ;
140183 }
141184 this . metaData = this . plugin . getMetaDataForFile ( this . file ) ;
142185 }
@@ -170,8 +213,12 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
170213 }
171214 }
172215
216+ getArguments ( name : string ) {
217+ return this . arguments . filter ( x => x . name === name ) ;
218+ }
219+
173220 getArgument ( name : string ) {
174- return this . arguments . filter ( x => x . name === name ) . first ( ) ;
221+ return this . getArguments ( name ) . first ( ) ;
175222 }
176223
177224 async onload ( ) {
@@ -193,9 +240,9 @@ export class InputFieldMarkdownRenderChild extends MarkdownRenderChild {
193240
194241 this . inputField . render ( container ) ;
195242
196- const classArgument = this . getArgument ( 'class' ) ;
243+ const classArgument = this . getArguments ( 'class' ) ;
197244 if ( classArgument ) {
198- this . inputField . getHtmlElement ( ) . addClass ( classArgument . value ) ;
245+ this . inputField . getHtmlElement ( ) . addClasses ( classArgument . map ( x => x . value ) ) ;
199246 }
200247
201248 this . containerEl . empty ( ) ;
0 commit comments