feat(admin): render mltextarea fields per locale
- MLField.vue is the one locale-switching wrapper; MLTextField, MLMarkdownField and the new MLTextareaField are shells around it - isMLFieldType replaces the inline ML type-name checks in formState, FormView and RelationChildModal - register mltextarea as a group-labelled control; rebuild dist
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
// filtering, the save payload, 422 detail mapping and focus.
|
||||
import type { AdminRecord, ErrorBody, FormField } from '../../api/types'
|
||||
import { permissionValues } from './control'
|
||||
import { localeRecord } from './mlLocale'
|
||||
import { isMLFieldType, localeRecord } from './mlLocale'
|
||||
import { isRegistered } from './registry'
|
||||
|
||||
export { ML_LOCALE_CHANGE, broadcastMLLocale, localeRecord } from './mlLocale'
|
||||
export { ML_LOCALE_CHANGE, broadcastMLLocale, isMLFieldType, localeRecord } from './mlLocale'
|
||||
|
||||
/** The screen a field is filtered for: the two form modes and the read-only preview (D-11). */
|
||||
export type FormMode = 'create' | 'update' | 'preview'
|
||||
@@ -65,7 +65,7 @@ export function editablePayload(fields: FormField[], values: AdminRecord, mode:
|
||||
out[field.name] = permissionValues(field, value)
|
||||
continue
|
||||
}
|
||||
if (field.type === 'mltext' || field.type === 'mlmarkdown') {
|
||||
if (isMLFieldType(field.type)) {
|
||||
out[field.name] = localeRecord(value)
|
||||
continue
|
||||
}
|
||||
@@ -111,10 +111,6 @@ export function changedLocales(previous: unknown, next: unknown): string[] {
|
||||
* whole field when no locale is given, one locale of an ML target otherwise. */
|
||||
export type PresetEdited = (target: string, locale?: string) => boolean
|
||||
|
||||
function isMLType(type: string | undefined): boolean {
|
||||
return type === 'mltext' || type === 'mlmarkdown'
|
||||
}
|
||||
|
||||
/**
|
||||
* The preset targets of `source` (fields.yaml `preset`) to rewrite after the
|
||||
* source changed from `previous` to `next`: target name -> new value. Targets
|
||||
@@ -140,7 +136,7 @@ export function presetUpdates(
|
||||
isEdited: PresetEdited,
|
||||
): AdminRecord {
|
||||
const out: AdminRecord = {}
|
||||
const sourceML = isMLType(fields.find((field) => field.name === source)?.type)
|
||||
const sourceML = isMLFieldType(fields.find((field) => field.name === source)?.type)
|
||||
for (const field of fields) {
|
||||
const preset = field.preset
|
||||
if (!preset || preset.field !== source || (field.type !== 'text' && field.type !== 'mltext')) {
|
||||
@@ -188,7 +184,7 @@ export function initialValues(fields: FormField[], enabledLocales: readonly stri
|
||||
out[field.name] = false
|
||||
} else if (field.type === 'relation' && field.multiple) {
|
||||
out[field.name] = []
|
||||
} else if (field.type === 'mltext' || field.type === 'mlmarkdown') {
|
||||
} else if (isMLFieldType(field.type)) {
|
||||
const seed: Record<string, string> = {}
|
||||
for (const code of enabledLocales) {
|
||||
seed[code] = ''
|
||||
|
||||
Reference in New Issue
Block a user