autoresize textare and improved performance for string templates

This commit is contained in:
Ruben Fiszel
2022-08-06 18:45:15 +02:00
parent f697a7d443
commit df3ebc9c0c
2 changed files with 20 additions and 16 deletions
+17 -9
View File
@@ -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 @@
<textarea
{disabled}
style="min-height: {minHeight}; max-height: {maxHeight}"
on:input={async () => recomputeRowSize(rawValue ?? '')}
class="col-span-10 {valid
? ''
: 'border border-red-700 border-opacity-30 focus:border-red-700 focus:border-opacity-30 bg-red-100'}"
@@ -313,7 +318,10 @@
: 'border border-red-700 border-opacity-30 focus:border-red-700 focus:border-opacity-30 bg-red-100'}"
placeholder={defaultValue ?? ''}
bind:value
on:input={() => dispatch('input', { rawValue: value, isRaw: false })}
on:input={async () => {
recomputeRowSize(value)
dispatch('input', { rawValue: value, isRaw: false })
}}
/>
{/if}
{#if !required && inputCat != 'resource-object'}
+3 -7
View File
@@ -151,6 +151,8 @@ export async function loadSchemaFromModule(module: FlowModule): Promise<{
}
}
const returnStatementRegex = new RegExp(/\$\{(.*)\}/)
export function isCodeInjection(expr: string | undefined): boolean {
if (!expr) {
return false
@@ -158,13 +160,7 @@ export function isCodeInjection(expr: string | undefined): boolean {
const lines = expr.split('\n')
const [returnStatement] = lines.reverse()
const returnStatementRegex = new RegExp(/\$\{(.*)\}/)
if (returnStatementRegex.test(returnStatement)) {
const [_, argName] = returnStatement.split(returnStatementRegex)
return Boolean(argName)
}
return false
return returnStatementRegex.test(returnStatement)
}
export function getDefaultExpr(i: number, key: string = 'myfield', previousExpr?: string) {