@@ -14,7 +14,6 @@ import { useStore } from "@nanostores/react";
1414import {
1515 DataSources ,
1616 Resource ,
17- ResourceRequest ,
1817 type DataSource ,
1918 type Page ,
2019} from "@webstudio-is/sdk" ;
@@ -26,7 +25,7 @@ import {
2625 SYSTEM_VARIABLE_ID ,
2726 systemParameter ,
2827} from "@webstudio-is/sdk" ;
29- import { sitemapResourceUrl } from "@webstudio-is/sdk/runtime" ;
28+ import { serializeValue , sitemapResourceUrl } from "@webstudio-is/sdk/runtime" ;
3029import {
3130 Box ,
3231 Flex ,
@@ -127,7 +126,7 @@ export const UrlField = ({
127126 value : string ;
128127 onChange : (
129128 urlExpression : string ,
130- searchParams ?: ResourceRequest [ "searchParams" ]
129+ searchParams ?: Resource [ "searchParams" ]
131130 ) => void ;
132131 onCurlPaste : ( curl : CurlRequest ) => void ;
133132} ) => {
@@ -176,7 +175,7 @@ export const UrlField = ({
176175 }
177176 try {
178177 const url = new URL ( value ) ;
179- const searchParams : ResourceRequest [ "searchParams" ] = [ ] ;
178+ const searchParams : Resource [ "searchParams" ] = [ ] ;
180179 for ( const [ name , value ] of url . searchParams ) {
181180 searchParams . push ( { name, value : JSON . stringify ( value ) } ) ;
182181 }
@@ -245,6 +244,10 @@ const SearchParamPair = ({
245244 onChange : ( name : string , value : string ) => void ;
246245 onDelete : ( ) => void ;
247246} ) => {
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" ;
248251 return (
249252 < Grid
250253 gap = { 2 }
@@ -259,19 +262,13 @@ const SearchParamPair = ({
259262 value = { name }
260263 onChange = { ( event ) => onChange ( event . target . value , value ) }
261264 />
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 } />
268266 < BindingControl >
269267 < InputField
270268 placeholder = "Value"
271269 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 ) }
275272 // update text value as string literal
276273 onChange = { ( event ) =>
277274 onChange ( name , JSON . stringify ( event . target . value ) )
@@ -280,7 +277,7 @@ const SearchParamPair = ({
280277 < BindingPopover
281278 scope = { scope }
282279 aliases = { aliases }
283- variant = { isLiteralExpression ( value ) ? "default" : "bound" }
280+ variant = { isValueUnbound ? "default" : "bound" }
284281 value = { value }
285282 onChange = { ( newValue ) => onChange ( name , newValue ) }
286283 onRemove = { ( evaluatedValue ) =>
@@ -371,6 +368,10 @@ const HeaderPair = ({
371368 onChange : ( name : string , value : string ) => void ;
372369 onDelete : ( ) => void ;
373370} ) => {
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" ;
374375 return (
375376 < Grid
376377 gap = { 2 }
@@ -390,9 +391,8 @@ const HeaderPair = ({
390391 < InputField
391392 placeholder = "Value"
392393 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 ) }
396396 // update text value as string literal
397397 onChange = { ( event ) =>
398398 onChange ( name , JSON . stringify ( event . target . value ) )
@@ -401,7 +401,7 @@ const HeaderPair = ({
401401 < BindingPopover
402402 scope = { scope }
403403 aliases = { aliases }
404- variant = { isLiteralExpression ( value ) ? "default" : "bound" }
404+ variant = { isValueUnbound ? "default" : "bound" }
405405 value = { value }
406406 onChange = { ( newValue ) => onChange ( name , newValue ) }
407407 onRemove = { ( evaluatedValue ) =>
0 commit comments