feat(14.2.1-05): hydrate ML create/GET/save through TranslatedExact

Form schema meta lists enabled locales, Show/save expand mltext maps
without D-11 fallback, and the SPA seeds and adopt-merges every locale.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-10-06 15:37:00 +02:00
parent ed81f2a0c1
commit 0f8d13738d
11 changed files with 309 additions and 34 deletions

View File

@@ -92,8 +92,9 @@ export function presetValue(type: string, source: unknown): string {
.replace(/^-+|-+$/g, '')
}
/** Initial values of a new record: schema defaults, toggles off, no ids. */
export function initialValues(fields: FormField[]): AdminRecord {
/** Initial values of a new record: schema defaults, toggles off, no ids.
* ML fields seed an empty string for every enabled locale. */
export function initialValues(fields: FormField[], enabledLocales: readonly string[] = []): AdminRecord {
const out: AdminRecord = {}
for (const field of fields) {
if (field.default !== undefined) {
@@ -103,12 +104,38 @@ export function initialValues(fields: FormField[]): AdminRecord {
} else if (field.type === 'relation' && field.multiple) {
out[field.name] = []
} else if (field.type === 'mltext' || field.type === 'mlmarkdown') {
out[field.name] = {}
const seed: Record<string, string> = {}
for (const code of enabledLocales) {
seed[code] = ''
}
out[field.name] = seed
}
}
return out
}
/** Content locales from form schema meta; empty when the writer is unpublished. */
export function schemaEnabledLocales(meta: { enabledLocales?: readonly string[] } | null | undefined): readonly string[] {
return meta?.enabledLocales ?? []
}
/** Merge a GET/save ML value onto a seed map of every enabled locale. A host
* string becomes the first enabled locale; it never replaces sibling keys. */
export function mergeMLValue(incoming: unknown, enabledLocales: readonly string[]): Record<string, string> {
const seeded: Record<string, string> = {}
for (const code of enabledLocales) {
seeded[code] = ''
}
if (typeof incoming === 'string') {
const fallback = enabledLocales[0]
if (fallback) {
seeded[fallback] = incoming
}
return seeded
}
return { ...seeded, ...localeRecord(incoming) }
}
/** D-10 422 details (field -> messages) as a string-list map. */
export function fieldErrors(details: ErrorBody['details'] | undefined): Record<string, string[]> {
const out: Record<string, string[]> = {}