{
if (e.detail == propertyType || suggestion) return
const staticTemplate = isStaticTemplate(inputCat)
if (e.detail === 'ai') {
// Switch to AI mode: static with no value
if (arg) {
arg.type = 'ai'
arg.value = undefined
arg.expr = undefined
}
propertyType = 'ai'
} else if (e.detail === 'javascript') {
if (arg.expr == undefined) {
arg.expr = getDefaultExpr(
argName,
previousModuleId,
staticTemplate
? `\`${escapeTemplateBackticks(arg?.value?.toString() ?? '')}\``
: arg.value
? '(' + JSON.stringify(arg?.value, null, 4) + ')'
: ''
)
}
if (arg) {
arg.value = undefined
arg.type = 'javascript'
}
propertyType = 'javascript'
} else {
if (staticTemplate) {
if (arg) {
arg.value = codeToStaticTemplate(arg.expr)
arg.expr = undefined
// Stated here, as the other branches state it. `setPropertyType`
// only writes a type when the text is an interpolation, so leaving
// it to that call means a field switched off `ai` keeps carrying
// `ai` and reads straight back as it on the next render.
arg.type = 'static'
}
setPropertyType(arg?.value)
} else if (inputCat == 'list' || inputCat == 'object') {
if (arg) {
try {
let newExpr = arg.expr
if (newExpr.startsWith('(') && newExpr.endsWith(')')) {
newExpr = newExpr.slice(1, -1)
}
arg.value = JSON.parse(newExpr)
} catch (e) {
arg.value = undefined
}
arg.expr = undefined
arg.type = 'static'
}
} else {
if (arg) {
arg.type = 'static'
arg.value = undefined
arg.expr = undefined
}
}
// On a field the agent can fill, "static with no value" is itself the
// AI state (see `getPropertyType`), so leaving the value unset reads
// this choice straight back as AI and the field can never be typed
// into. An empty value of the field's own kind is what makes "I will
// supply this one" representable.
if (fieldAllowsAi && arg && arg.value === undefined) {
arg.value = isStaticTemplate(inputCat) ? '' : null
}
propertyType = 'static'
}
}}
>
{#snippet children({ item })}
{#if fieldAllowsAi}
{/if}
{#if staticTemplateOffered}
{:else}
{/if}
{#if noJavascript && propertyType !== 'javascript'}
{:else if codeInjectionDetected && propertyType == 'static'}
{:else}
{/if}
{/snippet}