UNPKG

@lucidcms/core

Version:

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

2 lines 1.46 kB
import{copy as e}from"../../../../i18n/copy.mjs";import t from"../../utils/zod-safe-parse.mjs";import n from"../../custom-field.mjs";import r from"../../utils/key-to-title.mjs";import{datetimeFieldConfig as i}from"./config.mjs";import a from"zod";import{isValid as o}from"date-fns";var s=class extends n{type=i.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:r(this.key)}),summary:this.props?.details?.summary,placeholder:this.props?.details?.placeholder},localized:this.props?.localized??!1,time:this.props?.time??!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}}getSchemaDefinition(e){return{data:{columns:[{name:this.key,type:e.db.getDataType(`timestamp`),nullable:!0,default:this.config.default===``?void 0:this.config.default}]},error:void 0}}formatResponseValue(e){return e??this.config.default??null}normalizeInputValue(e){return typeof e==`string`?e.trim():e}uniqueValidation(n){let r=t(n,a.union([a.string(),a.number(),a.date()]));return r.valid?o(new Date(n))?{valid:!0}:{valid:!1,message:e(`server:core.fields.date.validation.invalid`)}:r}};export{s as default}; //# sourceMappingURL=custom-field.mjs.map