UNPKG

@lucidcms/core

Version:

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

1 lines 4.1 kB
{"version":3,"file":"custom-field.mjs","names":[],"sources":["../../../../../../src/libs/collection/custom-fields/fields/repeater/custom-field.ts"],"sourcesContent":["import type { ServiceResponse } from \"../../../../../types.js\";\nimport { copy } from \"../../../../i18n/index.js\";\nimport CustomField from \"../../custom-field.js\";\nimport type {\n\tCFConfig,\n\tCFProps,\n\tCFResponse,\n\tGetSchemaDefinitionProps,\n\tSchemaDefinition,\n} from \"../../types.js\";\nimport keyToTitle from \"../../utils/key-to-title.js\";\nimport { repeaterFieldConfig } from \"./config.js\";\n\nclass RepeaterCustomField extends CustomField<\"repeater\"> {\n\ttype = repeaterFieldConfig.type;\n\tconfig;\n\tkey;\n\tprops;\n\tprotected override get sharedValidationFlags() {\n\t\treturn {\n\t\t\tskipValidation: false,\n\t\t\tskipRequiredValidation: true,\n\t\t\tskipZodValidation: true,\n\t\t} as const;\n\t}\n\tconstructor(key: string, props?: CFProps<\"repeater\">) {\n\t\tsuper();\n\t\tthis.key = key;\n\t\tthis.props = props;\n\t\tthis.config = {\n\t\t\tkey: this.key,\n\t\t\ttype: this.type,\n\t\t\tdetails: {\n\t\t\t\tlabel:\n\t\t\t\t\tthis.props?.details?.label ??\n\t\t\t\t\tcopy(`admin:fields.${this.type}.${this.key}.label`, {\n\t\t\t\t\t\tdefaultMessage: keyToTitle(this.key),\n\t\t\t\t\t}),\n\t\t\t\tsummary: this.props?.details?.summary,\n\t\t\t},\n\t\t\tui: {\n\t\t\t\tdisabled: this.props?.ui?.disabled,\n\t\t\t\tcondition: this.props?.ui?.condition,\n\t\t\t\twidth: this.props?.ui?.width,\n\t\t\t},\n\t\t\tfields: [],\n\t\t\tvalidation: this.props?.validation,\n\t\t} satisfies CFConfig<\"repeater\">;\n\t}\n\tgetSchemaDefinition(\n\t\t_props: GetSchemaDefinitionProps,\n\t): Awaited<ServiceResponse<SchemaDefinition>> {\n\t\treturn {\n\t\t\tdata: {\n\t\t\t\tcolumns: [],\n\t\t\t},\n\t\t\terror: undefined,\n\t\t};\n\t}\n\tformatResponseValue() {\n\t\treturn null satisfies CFResponse<\"repeater\">[\"value\"];\n\t}\n\tuniqueValidation(value: unknown) {\n\t\tif (\n\t\t\tArray.isArray(value) &&\n\t\t\ttypeof this.config.validation?.maxGroups === \"number\"\n\t\t) {\n\t\t\tif (value.length > this.config.validation?.maxGroups) {\n\t\t\t\treturn {\n\t\t\t\t\tvalid: false,\n\t\t\t\t\tmessage: copy(\n\t\t\t\t\t\t\"server:core.fields.repeater.validation.max.groups.exceeded\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tgroups: this.config.validation.maxGroups,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tArray.isArray(value) &&\n\t\t\ttypeof this.config.validation?.minGroups === \"number\"\n\t\t) {\n\t\t\tif (this.config.validation?.minGroups > value.length) {\n\t\t\t\treturn {\n\t\t\t\t\tvalid: false,\n\t\t\t\t\tmessage: copy(\n\t\t\t\t\t\t\"server:core.fields.repeater.validation.groups.exceeded.min\",\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tgroups: this.config.validation.minGroups,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn { valid: true };\n\t}\n}\n\nexport default RepeaterCustomField;\n"],"mappings":"sLAaA,IAAM,EAAN,cAAkC,CAAwB,CACzD,KAAO,EAAoB,KAC3B,OACA,IACA,MACA,IAAuB,uBAAwB,CAC9C,MAAO,CACN,eAAgB,GAChB,uBAAwB,GACxB,kBAAmB,EACpB,CACD,CACA,YAAY,EAAa,EAA6B,CACrD,MAAM,EACN,KAAK,IAAM,EACX,KAAK,M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