@@ -3,6 +3,7 @@ import marked from 'marked';
3
3
import Prism from 'prismjs' ;
4
4
5
5
import { unsafeHTML } from 'lit-html/directives/unsafe-html' ;
6
+ import { live } from 'lit-html/directives/live' ;
6
7
import TableStyles from '@/styles/table-styles' ;
7
8
import FlexStyles from '@/styles/flex-styles' ;
8
9
import InputStyles from '@/styles/input-styles' ;
@@ -172,6 +173,24 @@ export default class ApiRequest extends LitElement {
172
173
` ;
173
174
}
174
175
176
+ updated ( changedProperties ) {
177
+ // In focused mode after navbar click, update the textareas(which contains examples) with the original values
178
+ // as user may update the dom by editing the textarea's which will not trigger any futher dom-change events
179
+ if ( this . renderStyle === 'focused' ) {
180
+ if ( changedProperties . size === 1 && changedProperties . has ( 'activeSchemaTab' ) ) {
181
+ // dont update example as only tabs is switched
182
+ } else {
183
+ const exampleTextAreaEls = [ ...this . shadowRoot . querySelectorAll ( 'textarea[data-ptype="form-data"]' ) ] ;
184
+ exampleTextAreaEls . forEach ( ( el ) => {
185
+ const origExampleEl = this . shadowRoot . querySelector ( `textarea[data-pname='hidden-${ el . dataset . pname } ']` ) ;
186
+ if ( origExampleEl ) {
187
+ el . value = origExampleEl . value ;
188
+ }
189
+ } ) ;
190
+ }
191
+ }
192
+ }
193
+
175
194
/* eslint-disable indent */
176
195
inputParametersTemplate ( paramType ) {
177
196
let title = '' ;
@@ -246,7 +265,7 @@ export default class ApiRequest extends LitElement {
246
265
data-param-serialize-explode = "${ paramExplode } "
247
266
data-array = "true "
248
267
placeholder = "add-multiple ⮐ "
249
- .value = "${ inputVal } "
268
+ .value = "${ live ( inputVal ) } "
250
269
>
251
270
</ tag-input > `
252
271
: paramSchema . type === 'object'
@@ -265,7 +284,7 @@ export default class ApiRequest extends LitElement {
265
284
data-pname ="${ param . name } "
266
285
data-ptype ="${ paramType } "
267
286
data-array ="false "
268
- value ="${ inputVal } "
287
+ . value ="${ live ( inputVal ) } "
269
288
/> `
270
289
}
271
290
</ td > `
@@ -623,13 +642,15 @@ export default class ApiRequest extends LitElement {
623
642
data-pname = "${ fieldName } "
624
643
spellcheck = "false "
625
644
> ${ formdataPartExample [ 0 ] . exampleValue } </ textarea >
645
+ <!-- This textarea(hidden) is to store the original example value, in focused mode on navbar change it is used to update the example text -->
646
+ < textarea data-pname = "hidden- ${ fieldName } " data-ptype = "${ mimeType . includes ( 'form-urlencode' ) ? 'hidden-form-urlencode' : 'hidden-form-data' } " style ="display:none "> ${ formdataPartExample [ 0 ] . exampleValue } </ textarea >
626
647
</ div > `
627
648
}
628
649
</ div > `
629
650
: html `
630
651
${ this . allowTry === 'true' || fieldSchema . example
631
652
? html `< input
632
- value = "${ fieldSchema . example || '' } "
653
+ . value = "${ live ( fieldSchema . example || '' ) } "
633
654
spellcheck = "false "
634
655
type = "${ fieldSchema . format === 'binary' ? 'file' : fieldSchema . format === 'password' ? 'password' : 'text' } "
635
656
style = "width:200px "
0 commit comments