Edit json, record and list values in the JSON dialog

An inject's payload and a flow input's starting value of those types use
JsonField instead of a one-line text field. The field can now hold no value
(shown as the placeholder; an emptied editor saves null) and checks the shape:
a record must be an object, a list an array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013GAeg4Jo6xjZzjwy9QDWMQ
This commit is contained in:
2026-10-06 07:24:43 +02:00
co-authored by Claude Opus 5.5
parent 4f4de1fd9d
commit 457b88ed14
3 changed files with 69 additions and 10 deletions
+32 -1
View File
@@ -20,6 +20,7 @@ import {
} from "@/components/ui/tooltip"
import { cn } from "@/lib/utils"
import { qualify } from "./deriveEdges"
import { JsonField } from "./JsonField"
import { useLiveValue } from "./liveStore"
import { asText, DTYPES } from "./NodePanel"
import { InfoTip, PANEL_SECTION } from "./SidePanel"
@@ -51,10 +52,25 @@ export function parseByDtype(dtype: DType | undefined, raw: string): unknown {
}
}
/** Why a parsed value is not the shape its type declares, or null. */
function shapeError(dtype: DType | undefined, value: unknown): string | null {
if (
dtype === "record" &&
(value === null || typeof value !== "object" || Array.isArray(value))
) {
return "A record is an object: { … }"
}
if (dtype === "list" && !Array.isArray(value)) {
return "A list is an array: [ … ]"
}
return null
}
/**
* One literal, entered the way its type is entered.
*
* A flag has two values and gets a choice of them; everything else is typed
* A flag has two values and gets a choice of them; JSON, a record and a list
* get the JSON editor, which also holds their shape; everything else is typed
* and read back with {@link parseByDtype}. Deliberately not `type="number"`
* for the numbers — see that function on why half-typed input must survive.
*
@@ -99,6 +115,21 @@ export function DtypeValue({
)
}
if (dtype === "json" || dtype === "record" || dtype === "list") {
return (
<JsonField
id={id}
value={value}
label={label}
// Empty is no value here, as it is in the text field below.
placeholder={placeholder ?? ""}
check={(next) => shapeError(dtype, next)}
className={className}
onChange={onChange}
/>
)
}
return (
<Input
id={id}