@@ -14,7 +14,6 @@ import { useStore } from "@nanostores/react";
14
14
import {
15
15
DataSources ,
16
16
Resource ,
17
- ResourceRequest ,
18
17
type DataSource ,
19
18
type Page ,
20
19
} from "@webstudio-is/sdk" ;
@@ -26,7 +25,7 @@ import {
26
25
SYSTEM_VARIABLE_ID ,
27
26
systemParameter ,
28
27
} from "@webstudio-is/sdk" ;
29
- import { sitemapResourceUrl } from "@webstudio-is/sdk/runtime" ;
28
+ import { serializeValue , sitemapResourceUrl } from "@webstudio-is/sdk/runtime" ;
30
29
import {
31
30
Box ,
32
31
Flex ,
@@ -127,7 +126,7 @@ export const UrlField = ({
127
126
value : string ;
128
127
onChange : (
129
128
urlExpression : string ,
130
- searchParams ?: ResourceRequest [ "searchParams" ]
129
+ searchParams ?: Resource [ "searchParams" ]
131
130
) => void ;
132
131
onCurlPaste : ( curl : CurlRequest ) => void ;
133
132
} ) => {
@@ -176,7 +175,7 @@ export const UrlField = ({
176
175
}
177
176
try {
178
177
const url = new URL ( value ) ;
179
- const searchParams : ResourceRequest [ "searchParams" ] = [ ] ;
178
+ const searchParams : Resource [ "searchParams" ] = [ ] ;
180
179
for ( const [ name , value ] of url . searchParams ) {
181
180
searchParams . push ( { name, value : JSON . stringify ( value ) } ) ;
182
181
}
@@ -245,6 +244,10 @@ const SearchParamPair = ({
245
244
onChange : ( name : string , value : string ) => void ;
246
245
onDelete : ( ) => void ;
247
246
} ) => {
247
+ const evaluatedValue = evaluateExpressionWithinScope ( value , scope ) ;
248
+ // expressions with variables or objects cannot be edited from input
249
+ const isValueUnbound =
250
+ isLiteralExpression ( value ) && typeof evaluatedValue === "string" ;
248
251
return (
249
252
< Grid
250
253
gap = { 2 }
@@ -259,19 +262,13 @@ const SearchParamPair = ({
259
262
value = { name }
260
263
onChange = { ( event ) => onChange ( event . target . value , value ) }
261
264
/>
262
- < input
263
- hidden = { true }
264
- readOnly = { true }
265
- name = "search-param-value"
266
- value = { value }
267
- />
265
+ < input type = "hidden" name = "search-param-value" value = { value } />
268
266
< BindingControl >
269
267
< InputField
270
268
placeholder = "Value"
271
269
name = "search-param-value-literal"
272
- // expressions with variables cannot be edited
273
- disabled = { isLiteralExpression ( value ) === false }
274
- value = { String ( evaluateExpressionWithinScope ( value , scope ) ) }
270
+ disabled = { ! isValueUnbound }
271
+ value = { serializeValue ( evaluatedValue ) }
275
272
// update text value as string literal
276
273
onChange = { ( event ) =>
277
274
onChange ( name , JSON . stringify ( event . target . value ) )
@@ -280,7 +277,7 @@ const SearchParamPair = ({
280
277
< BindingPopover
281
278
scope = { scope }
282
279
aliases = { aliases }
283
- variant = { isLiteralExpression ( value ) ? "default" : "bound" }
280
+ variant = { isValueUnbound ? "default" : "bound" }
284
281
value = { value }
285
282
onChange = { ( newValue ) => onChange ( name , newValue ) }
286
283
onRemove = { ( evaluatedValue ) =>
@@ -371,6 +368,10 @@ const HeaderPair = ({
371
368
onChange : ( name : string , value : string ) => void ;
372
369
onDelete : ( ) => void ;
373
370
} ) => {
371
+ const evaluatedValue = evaluateExpressionWithinScope ( value , scope ) ;
372
+ // expressions with variables or objects cannot be edited from input
373
+ const isValueUnbound =
374
+ isLiteralExpression ( value ) && typeof evaluatedValue === "string" ;
374
375
return (
375
376
< Grid
376
377
gap = { 2 }
@@ -390,9 +391,8 @@ const HeaderPair = ({
390
391
< InputField
391
392
placeholder = "Value"
392
393
name = "header-value-validator"
393
- // expressions with variables cannot be edited
394
- disabled = { isLiteralExpression ( value ) === false }
395
- value = { String ( evaluateExpressionWithinScope ( value , scope ) ) }
394
+ disabled = { ! isValueUnbound }
395
+ value = { serializeValue ( evaluatedValue ) }
396
396
// update text value as string literal
397
397
onChange = { ( event ) =>
398
398
onChange ( name , JSON . stringify ( event . target . value ) )
@@ -401,7 +401,7 @@ const HeaderPair = ({
401
401
< BindingPopover
402
402
scope = { scope }
403
403
aliases = { aliases }
404
- variant = { isLiteralExpression ( value ) ? "default" : "bound" }
404
+ variant = { isValueUnbound ? "default" : "bound" }
405
405
value = { value }
406
406
onChange = { ( newValue ) => onChange ( name , newValue ) }
407
407
onRemove = { ( evaluatedValue ) =>
0 commit comments