@@ -213,24 +213,51 @@ export default class ApiRequest extends LitElement {
213
213
` ;
214
214
}
215
215
216
- updated ( changedProperties ) {
216
+ /*
217
+ async updated(changedProperties) {
217
218
// In focused mode after rendering the request component, update the text-areas(which contains examples) using
218
219
// the original values from hidden textareas
219
220
// This is done coz, user may update the dom by editing the textarea's and once the DOM is updated externally change detection wont happen, therefore update the values manually
220
221
if (this.renderStyle === 'focused') {
221
222
if (changedProperties.size === 1 && changedProperties.has('activeSchemaTab')) {
222
223
// dont update example as only tabs is switched
223
224
} else {
224
- const exampleTextAreaEls = [ ...this . shadowRoot . querySelectorAll ( 'textarea[data-ptype="form-data"]' ) ] ;
225
- exampleTextAreaEls . forEach ( ( el ) => {
226
- const origExampleEl = this . shadowRoot . querySelector ( `textarea[data-pname='hidden-${ el . dataset . pname } ']` ) ;
227
- if ( origExampleEl ) {
228
- el . value = origExampleEl . value ;
229
- }
230
- } ) ;
225
+ this.requestUpdate();
231
226
}
232
227
}
233
228
}
229
+ */
230
+
231
+ async saveExampleState ( ) {
232
+ if ( this . renderStyle === 'focused' ) {
233
+ const reqBodyTextAreaEls = [ ...this . shadowRoot . querySelectorAll ( 'textarea.request-body-param-user-input' ) ] ;
234
+ reqBodyTextAreaEls . forEach ( ( el ) => {
235
+ el . dataset . user_example = el . value ;
236
+ } ) ;
237
+ const exampleTextAreaEls = [ ...this . shadowRoot . querySelectorAll ( 'textarea[data-ptype="form-data"]' ) ] ;
238
+ exampleTextAreaEls . forEach ( ( el ) => {
239
+ el . dataset . user_example = el . value ;
240
+ } ) ;
241
+ this . requestUpdate ( ) ;
242
+ }
243
+ }
244
+
245
+ async updateExamplesFromDataAttr ( ) {
246
+ // In focused mode after rendering the request component, update the text-areas(which contains examples) using
247
+ // the original values from hidden textareas
248
+ // This is done coz, user may update the dom by editing the textarea's and once the DOM is updated externally change detection wont happen, therefore update the values manually
249
+ if ( this . renderStyle === 'focused' ) {
250
+ const reqBodyTextAreaEls = [ ...this . shadowRoot . querySelectorAll ( 'textarea.request-body-param-user-input' ) ] ;
251
+ reqBodyTextAreaEls . forEach ( ( el ) => {
252
+ el . value = el . dataset . user_example || el . dataset . example ;
253
+ } ) ;
254
+ const exampleTextAreaEls = [ ...this . shadowRoot . querySelectorAll ( 'textarea[data-ptype="form-data"]' ) ] ;
255
+ exampleTextAreaEls . forEach ( ( el ) => {
256
+ el . value = el . dataset . user_example || el . dataset . example ;
257
+ } ) ;
258
+ this . requestUpdate ( ) ;
259
+ }
260
+ }
234
261
235
262
renderExample ( example , paramType , paramName ) {
236
263
return html `
@@ -508,9 +535,16 @@ export default class ApiRequest extends LitElement {
508
535
</ div > ` ;
509
536
}
510
537
511
- resetRequestBodySelection ( ) {
538
+ // This method is called before navigation change in focusd mode
539
+ async beforerNavigationFocusedMode ( ) {
540
+ // this.saveExampleState();
541
+ }
542
+
543
+ // This method is called after navigation change in focusd mode
544
+ async afterNavigationFocusedMode ( ) {
512
545
this . selectedRequestBodyType = '' ;
513
546
this . selectedRequestBodyExample = '' ;
547
+ this . updateExamplesFromDataAttr ( ) ;
514
548
this . clearResponseData ( ) ;
515
549
}
516
550
@@ -724,10 +758,8 @@ export default class ApiRequest extends LitElement {
724
758
< button class ="tab-btn ${ this . activeSchemaTab === 'example' ? 'active' : '' } " data-tab = 'example '> EXAMPLE</ button >
725
759
< button class ="tab-btn ${ this . activeSchemaTab !== 'example' ? 'active' : '' } " data-tab = 'schema '> SCHEMA</ button >
726
760
</ div >
727
- ${ this . activeSchemaTab === 'example'
728
- ? html `< div class ="tab-content col "> ${ reqBodyExampleHtml } </ div > `
729
- : html `< div class ="tab-content col "> ${ reqBodySchemaHtml } </ div > `
730
- }
761
+ ${ html `< div class ="tab-content col " style ="display:${ this . activeSchemaTab === 'example' ? 'block' : 'none' } ; "> ${ reqBodyExampleHtml } </ div > ` }
762
+ ${ html `< div class ="tab-content col " style ="display:${ this . activeSchemaTab === 'example' ? 'none' : 'block' } ; "> ${ reqBodySchemaHtml } </ div > ` }
731
763
</ div > `
732
764
: html `
733
765
${ reqBodyFileInputHtml }
@@ -788,8 +820,6 @@ export default class ApiRequest extends LitElement {
788
820
.textContent = "${ this . fillRequestFieldsWithExample === 'true' ? formdataPartExample [ 0 ] . exampleValue : '' } "
789
821
spellcheck = "false "
790
822
> </ textarea >
791
- <!-- This textarea(hidden) is to store the original example value, in focused mode on navbar change it is used to update the example text -->
792
- < textarea data-pname = "hidden- ${ fieldName } " data-ptype = "${ mimeType . includes ( 'form-urlencode' ) ? 'hidden-form-urlencode' : 'hidden-form-data' } " class ="is-hidden " style ="display:none "> ${ formdataPartExample [ 0 ] . exampleValue } </ textarea >
793
823
</ div > `
794
824
}
795
825
${ html `
0 commit comments