From 8b01825dc979b8f0a642908edaa0d20bc1aaf85f Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Tue, 23 Sep 2025 16:50:23 +0200 Subject: [PATCH] prettier json toggle and array inputs --- frontend/src/lib/components/ArgInput.svelte | 110 ++++++++++++------ .../lib/components/ModulePreviewForm.svelte | 20 ++-- frontend/src/lib/components/Toggle.svelte | 16 ++- 3 files changed, 98 insertions(+), 48 deletions(-) diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index c1715bda30..a26f754f99 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -470,6 +470,7 @@ let { debounced, clearDebounce } = debounce(() => compareValues(value), 50) let inputCat = $derived(computeInputCat(type, format, itemsType?.type, enum_, contentEncoding)) + let displayJsonToggleHeader = $derived(displayHeader && inputCat === 'list') $effect(() => { oneOf && untrack(() => updateOneOfSelected(oneOf)) }) @@ -606,7 +607,26 @@ css?.label?.class )} /> - {@render fieldHeaderActions?.()} +
+ {#if displayJsonToggleHeader} + { + // Once the user has changed the input type, we should not change it back automatically + if (!hasIsListJsonChanged) { + hasIsListJsonChanged = true + } + + evalValueToRaw() + isListJson = !isListJson + }} + checked={isListJson} + textClass="text-secondary" + size="xs" + options={{ left: 'json' }} + /> + {/if} + {@render fieldHeaderActions?.()} +
{/if} @@ -793,8 +813,28 @@ {#each value ?? [] as v, i} {#if i < itemsLimit}
+ {#snippet deleteItemBtn()} + + {/snippet} {#if itemsType?.type == 'number'} - + +
+ {@render deleteItemBtn()} +
{:else if itemsType?.type == 'string' && itemsType?.contentEncoding == 'base64'} fileChanged(x, (val) => (value[i] = val))} multiple={false} /> + {@render deleteItemBtn()} {:else if itemsType?.type == 'object' && itemsType?.resourceType === undefined && itemsType?.properties === undefined && !(format?.startsWith('resource-') && resourceTypes?.includes(format.split('-')[1]))} {#await import('$lib/components/JsonEditor.svelte')} @@ -811,6 +852,7 @@ bind:value={value[i]} /> {/await} + {@render deleteItemBtn()} {:else if Array.isArray(itemsType?.enum)} + {@render deleteItemBtn()} {:else if (itemsType?.type == 'resource' && itemsType?.resourceType && resourceTypes?.includes(itemsType.resourceType)) || (format?.startsWith('resource-') && resourceTypes?.includes(format.split('-')[1]))} {@const resourceFormat = itemsType?.type == 'resource' && @@ -840,6 +883,7 @@ format={resourceFormat} defaultValue={undefined} /> + {@render deleteItemBtn()} {:else if itemsType?.type == 'resource'} {#await import('$lib/components/JsonEditor.svelte')} @@ -856,6 +900,7 @@ bind:value={value[i]} /> {/await} + {@render deleteItemBtn()} {:else if itemsType?.type === 'object' && itemsType?.properties}
+ {@render deleteItemBtn()} {:else} - + +
+ {@render deleteItemBtn()} +
{/if} -
{/if} {/each} @@ -938,23 +980,25 @@ {/if} -
- { - // Once the user has changed the input type, we should not change it back automatically - if (!hasIsListJsonChanged) { - hasIsListJsonChanged = true - } + {#if !displayHeader} +
+ { + // Once the user has changed the input type, we should not change it back automatically + if (!hasIsListJsonChanged) { + hasIsListJsonChanged = true + } - evalValueToRaw() - isListJson = !isListJson - }} - checked={isListJson} - textClass="text-secondary" - size="xs" - options={{ right: 'json' }} - /> -
+ evalValueToRaw() + isListJson = !isListJson + }} + checked={isListJson} + textClass="text-secondary" + size="xs" + options={{ left: 'json' }} + /> +
+ {/if} {:else if inputCat == 'dynamic'} @@ -1212,8 +1256,8 @@ /> {/await} {/if} - {#if inputCat == 'list'} -
+ {#if inputCat == 'list' && !displayHeader} +
{ isListJson = !isListJson @@ -1221,7 +1265,7 @@ checked={isListJson} textClass="text-secondary" size="xs" - options={{ right: 'json' }} + options={{ left: 'json' }} />
{/if} diff --git a/frontend/src/lib/components/ModulePreviewForm.svelte b/frontend/src/lib/components/ModulePreviewForm.svelte index 0fc226a3e3..1a32024fb7 100644 --- a/frontend/src/lib/components/ModulePreviewForm.svelte +++ b/frontend/src/lib/components/ModulePreviewForm.svelte @@ -153,17 +153,15 @@ > {#snippet fieldHeaderActions()} {#if stepsInputArgs?.isArgManuallySet(mod.id, argName)} -
- -
+ {/if} {/snippet} diff --git a/frontend/src/lib/components/Toggle.svelte b/frontend/src/lib/components/Toggle.svelte index c59a79ffb2..f567d4a042 100644 --- a/frontend/src/lib/components/Toggle.svelte +++ b/frontend/src/lib/components/Toggle.svelte @@ -43,8 +43,12 @@ {#if Boolean(options?.left)}