@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.57 kB
JavaScript
import{copy as e}from"../../../../i18n/copy.mjs";import t from"../../../../../utils/helpers/deep-merge.mjs";import n from"../../utils/zod-safe-parse.mjs";import r from"../../custom-field.mjs";import i from"../../utils/key-to-title.mjs";import{selectFieldConfig as a}from"./config.mjs";import o from"zod";var s=class extends r{type=a.type;config;key;props;constructor(t,n){super(),this.key=t,this.props=n,this.config={key:this.key,type:this.type,details:{label:this.props?.details?.label??e(`admin:fields.${this.type}.${this.key}.label`,{defaultMessage:i(this.key)}),summary:this.props?.details?.summary,placeholder:this.props?.details?.placeholder},options:this.props?.options??[],localized:this.props?.localized??!1,default:this.props?.default??``,index:this.props?.index,ui:{hidden:this.props?.ui?.hidden,disabled:this.props?.ui?.disabled,condition:this.props?.ui?.condition,width:this.props?.ui?.width},validation:this.props?.validation}}get errors(){return t(super.errors,{required:{message:e(`server:core.fields.select.validation.required`)}})}normalizeInputValue(e){return typeof e==`string`?e.trim():e}getSchemaDefinition(e){return{data:{columns:[{name:this.key,type:e.db.getDataType(`text`),nullable:!0}]},error:void 0}}formatResponseValue(e){return e??this.config.default??null}uniqueValidation(t){let r=n(t,o.string());return r.valid?this.config.options&&!this.config.options.map(e=>e.value).includes(t)?{valid:!1,message:e(`server:core.fields.select.validation.option.invalid`)}:{valid:!0}:r}};export{s as default};
//# sourceMappingURL=custom-field.mjs.map