- 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
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
/** The multilingual field types: their value is a locale -> text map. */
|
|
export const ML_FIELD_TYPES: ReadonlySet<string> = new Set(['mltext', 'mltextarea', 'mlmarkdown'])
|
|
|
|
/** Reports whether a field type holds a locale -> text map. */
|
|
export function isMLFieldType(type: string | undefined): boolean {
|
|
return type !== undefined && ML_FIELD_TYPES.has(type)
|
|
}
|
|
|
|
/** Window event that keeps every ML control on one active locale. */
|
|
export const ML_LOCALE_CHANGE = 'summer:ml-locale'
|
|
|
|
/** Broadcast the locale the administrator selected on any ML control. */
|
|
export function broadcastMLLocale(locale: string): void {
|
|
if (typeof window === 'undefined' || locale === '') {
|
|
return
|
|
}
|
|
window.dispatchEvent(new CustomEvent(ML_LOCALE_CHANGE, { detail: locale }))
|
|
}
|
|
|
|
/** Locale → text map as it is sent on save: only string values. */
|
|
export function localeRecord(value: unknown): Record<string, string> {
|
|
const out: Record<string, string> = {}
|
|
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
return out
|
|
}
|
|
for (const [locale, text] of Object.entries(value as Record<string, unknown>)) {
|
|
if (typeof text === 'string') {
|
|
out[locale] = text
|
|
}
|
|
}
|
|
return out
|
|
}
|