/** * The source region of `TemplatedTextField`: the inline/stored toggle and its * editors while storage is present, a stand-in while presence is unknown, and the * read-only stored reference (never converted, dropped, or blanked) when storage * is absent. */ import type { ReactNode } from 'react'; import { Field } from './field'; import { Textarea } from './inputs'; import { ErrorState, Skeleton } from './primitives'; import { RadioGroup } from './radio-group'; import { Select } from './select'; import type { TemplatedTextInlineProps, TemplatedTextTemplateOption } from './templated-text-field'; import type { Mode } from './templated-text-kwargs'; /** A labeled read-only reference to a stored template id, plus the note that * stored templates are unavailable here — NOT an editable field. */ function ReadOnlyStoredReference({ id }: { readonly id: string }): ReactNode { return ( <>
Stored template {id}

Stored templates are unavailable — this deployment has no storage backend.

); } interface PresentStorageSourceProps { readonly label: string; readonly mode: Mode; readonly disabled: boolean; readonly inlineEditor: ReactNode; readonly error?: string; readonly storedDraft: string; readonly templates: readonly TemplatedTextTemplateOption[]; readonly templateOptions: readonly { value: string; label: string }[]; readonly templatesLoading: boolean; readonly templatesError?: string; readonly onTemplatesRetry?: () => void; readonly unresolvedId?: string; readonly resolveError?: string; readonly onModeChange: (mode: Mode) => void; readonly onStoredChange: (stored: string) => void; } /** The inline/stored toggle, the mode's editor, and the unresolved-id note, for * the storage-present configuration. */ function PresentStorageSource({ label, mode, disabled, inlineEditor, error, storedDraft, templates, templateOptions, templatesLoading, templatesError, onTemplatesRetry, unresolvedId, resolveError, onModeChange, onStoredChange, }: PresentStorageSourceProps): ReactNode { return ( <> { onModeChange(next as Mode); }} /> {mode === 'inline' ? ( inlineEditor ) : templatesError !== undefined ? ( ) : templatesLoading ? ( ) : (