From df3ebc9c0c62b59649735f149471130968da3bcf Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 6 Aug 2022 18:45:15 +0200 Subject: [PATCH] autoresize textare and improved performance for string templates --- frontend/src/lib/components/ArgInput.svelte | 26 ++++++++++++++------- frontend/src/lib/components/flows/utils.ts | 10 +++----- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/frontend/src/lib/components/ArgInput.svelte b/frontend/src/lib/components/ArgInput.svelte index 09cc62ffae..f042003a70 100644 --- a/frontend/src/lib/components/ArgInput.svelte +++ b/frontend/src/lib/components/ArgInput.svelte @@ -71,14 +71,18 @@ evalValueToRaw() validateInput(pattern, value) } - if (defaultValue) { - let stringified = JSON.stringify(defaultValue, null, 4) - if (stringified.length > 50) { - minRows = 3 - } - if (type != 'string') { - minRows = Math.max(minRows, Math.min(stringified.split(/\r\n|\r|\n/).length + 1, maxRows)) - } + } + + $: { + defaultValue && recomputeRowSize(JSON.stringify(defaultValue, null, 4)) + } + + function recomputeRowSize(str: string) { + if (str.length > 50) { + minRows = 3 + } + if (type != 'string') { + minRows = Math.max(minRows, Math.min(str.split(/\r\n|\r|\n/).length + 1, maxRows)) } } @@ -263,6 +267,7 @@