diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index 7894607778..1ab0073e0e 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -166,7 +166,7 @@ value = undefined } if ((value == undefined || value == null) && !ignoreValueUndefined) { - value = defaultValue + value = structuredClone(defaultValue) if (defaultValue === undefined || defaultValue === null) { if (inputCat === 'string') { value = nullable ? null : '' @@ -246,17 +246,47 @@ ) } + function isRawStringEditor(inputCat?: string) { + return inputCat == 'sql' || inputCat == 'yaml' + } + function evalValueToRaw() { - rawValue = isObjectCat(inputCat) ? JSON.stringify(value, null, 2) : undefined - rawValue && editor?.getCode() != rawValue && editor?.setCode(rawValue) + if (setCodeDisabled) { + return + } + const newRawValue = + value == undefined || value == null + ? '' + : isObjectCat(inputCat) + ? JSON.stringify(value, null, 2) + : isRawStringEditor(inputCat) + ? typeof value == 'string' + ? value + : JSON.stringify(value, null, 2) + : undefined + + if (newRawValue != rawValue) { + rawValue = newRawValue + rawValue != undefined && editor?.getCode() != rawValue && editor?.setCode(rawValue) + } // console.log('evalValueToRaw', value, rawValue, inputCat, label) } - $: inputCat && - isObjectCat(inputCat) && - rawValue == undefined && - value != undefined && - evalValueToRaw() + let setCodeDisabled = false + $: (inputCat && (isObjectCat(inputCat) || isRawStringEditor(inputCat)) && evalValueToRaw()) || + value + + let timeout: NodeJS.Timeout | undefined = undefined + function setNewValueFromCode(nvalue: any) { + if (!deepEqual(nvalue, value)) { + value = nvalue + timeout && clearTimeout(timeout) + setCodeDisabled = true + timeout = setTimeout(() => { + setCodeDisabled = false + }, 1000) + } + } onMount(() => { computeDefaultValue() @@ -713,7 +743,9 @@ dispatch('blur') }} code={JSON.stringify(value ?? defaultValue ?? { s3: '' }, null, 2)} - bind:value + on:changeValue={(e) => { + setNewValueFromCode(e.detail) + }} /> {/await}