UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 1.92 kB
{"version":3,"file":"normalize-field-copy.mjs","names":[],"sources":["../../../../../src/libs/collection/custom-fields/utils/normalize-field-copy.ts"],"sourcesContent":["import { normalizeCopy } from \"../../../i18n/index.js\";\nimport type { AdminCopyInput } from \"../../../i18n/types.js\";\nimport type { CFConfig, FieldTypes } from \"../types.js\";\n\n/** Copy-bearing keys that may appear on a field config's `details` object. */\nconst detailCopyKeys = [\"label\", \"summary\", \"placeholder\", \"true\", \"false\"];\n\n/**\n * Normalises author-supplied copy on a field config in place.\n *\n * Plain strings authored against `details` (label/summary/placeholder, checkbox\n * `true`/`false`) and select `options[].label` become literal copy so the\n * runtime config only ever holds descriptor/literal objects. Keys that are not\n * present are left untouched so the config shape is preserved.\n */\nconst normalizeFieldCopy = (config: CFConfig<FieldTypes>): void => {\n\tconst details = (config as { details?: Record<string, AdminCopyInput> })\n\t\t.details;\n\tif (details) {\n\t\tfor (const key of detailCopyKeys) {\n\t\t\tif (!Object.hasOwn(details, key)) continue;\n\t\t\tdetails[key] = normalizeCopy(details[key]) as AdminCopyInput;\n\t\t}\n\t}\n\n\tconst options = (config as { options?: Array<{ label?: AdminCopyInput }> })\n\t\t.options;\n\tif (Array.isArray(options)) {\n\t\tfor (const option of options) {\n\t\t\tif (!Object.hasOwn(option, \"label\")) continue;\n\t\t\toption.label = normalizeCopy(option.label) as AdminCopyInput;\n\t\t}\n\t}\n};\n\nexport default normalizeFieldCopy;\n"],"mappings":"uDAKA,MAAM,EAAiB,CAAC,QAAS,UAAW,cAAe,OAAQ,OAAO,EAUpE,EAAsB,GAAuC,CAClE,IAAM,EAAW,EACf,QACF,GAAI,EACH,IAAK,IAAM,KAAO,EACZ,OAAO,OAAO,EAAS,CAAG,IAC/B,EAAQ,GAAO,EAAc,EAAQ,EAAI,GAI3C,IAAM,EAAW,EACf,QACF,GAAI,MAAM,QAAQ,CAAO,EACxB,IAAK,IAAM,KAAU,EACf,OAAO,OAAO,EAAQ,OAAO,IAClC,EAAO,MAAQ,EAAc,EAAO,KAAK,EAG5C"}