From 8bdd707e55c60701d3e19aa8db22763dd40d9d9e Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 4 Jan 2023 10:37:13 +0100 Subject: [PATCH] feat: add support for yaml format as a string format --- frontend/src/lib/components/ArgInput.svelte | 8 ++-- .../lib/components/InputTransformForm.svelte | 2 +- .../src/lib/components/SimpleEditor.svelte | 11 ++++++ .../lib/components/StringTypeNarrowing.svelte | 39 +++++++++++++++---- frontend/src/lib/editorUtils.ts | 2 + frontend/src/lib/infer.ts | 3 ++ frontend/src/lib/utils.ts | 3 ++ 7 files changed, 55 insertions(+), 13 deletions(-) diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index 281de1069e..79360ff3eb 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -183,7 +183,7 @@ bind:value={description} placeholder="Field description" /> - {#if type == 'string' && !contentEncoding && format != 'date-time'} + {#if type == 'string' && format != 'date-time'} {:else if type == 'object'} @@ -326,13 +326,13 @@ {:else if inputCat == 'date'} - {:else if inputCat == 'sql'} -
+ {:else if inputCat == 'sql' || inputCat == 'yaml'} +
dispatch('focus')} on:blur={() => dispatch('blur')} bind:this={editor} - lang="sql" + lang={inputCat} bind:code={value} class="few-lines-editor" on:change={async () => { diff --git a/frontend/src/lib/components/InputTransformForm.svelte b/frontend/src/lib/components/InputTransformForm.svelte index 627a3443b0..74bdc6ad06 100644 --- a/frontend/src/lib/components/InputTransformForm.svelte +++ b/frontend/src/lib/components/InputTransformForm.svelte @@ -74,7 +74,7 @@ } function isStaticTemplate(inputCat: InputCat) { - return inputCat === 'string' || inputCat === 'sql' + return inputCat === 'string' || inputCat === 'sql' || inputCat == 'yaml' } function connectProperty(rawValue: string) { diff --git a/frontend/src/lib/components/SimpleEditor.svelte b/frontend/src/lib/components/SimpleEditor.svelte index 872a056aee..8e1af88a60 100644 --- a/frontend/src/lib/components/SimpleEditor.svelte +++ b/frontend/src/lib/components/SimpleEditor.svelte @@ -14,6 +14,17 @@ import libStdContent from '$lib/es5.d.ts.txt?raw' + meditor.defineTheme('myTheme', { + base: 'vs', + inherit: true, + rules: [], + colors: { + 'editorLineNumber.foreground': '#999', + 'editorGutter.background': '#F9FAFB' + } + }) + meditor.setTheme('myTheme') + languages.typescript.javascriptDefaults.setCompilerOptions({ target: languages.typescript.ScriptTarget.Latest, allowNonTsExtensions: true, diff --git a/frontend/src/lib/components/StringTypeNarrowing.svelte b/frontend/src/lib/components/StringTypeNarrowing.svelte index 74df9fef38..8306b24b15 100644 --- a/frontend/src/lib/components/StringTypeNarrowing.svelte +++ b/frontend/src/lib/components/StringTypeNarrowing.svelte @@ -8,7 +8,7 @@ export let format: string | undefined export let contentEncoding: 'base64' | 'binary' | undefined - let kind: 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'base64' = 'none' + let kind: 'none' | 'pattern' | 'enum' | 'resource' | 'format' | 'base64' = computeKind() let patternStr: string = pattern ?? '' let resource: string | undefined @@ -18,7 +18,9 @@ 'hostname', 'uri', 'uuid', - 'ipv4' + 'ipv4', + 'yaml', + 'sql' // 'time', // 'date', // 'duration', @@ -41,6 +43,25 @@ enum_ = undefined } } + + function computeKind(): 'base64' | 'none' | 'pattern' | 'enum' | 'resource' | 'format' { + if (enum_ != undefined) { + return 'enum' + } + if (contentEncoding == 'base64') { + return 'base64' + } + if (pattern != undefined) { + return 'pattern' + } + if (format != undefined) { + if (format.startsWith('resource')) { + return 'resource' + } + return 'format' + } + return 'none' + } Enums - {#each enum_ || [] as e} -
- - -
- {/each} +
+ {#each enum_ || [] as e} +
+ + +
+ {/each} +