UNPKG

@lucidcms/core

Version:

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

2 lines 2.34 kB
import{copy as e}from"../../../../i18n/copy.mjs";import{getObject as t}from"../../../../../utils/helpers/get-typed-value.mjs";import n from"../../utils/zod-safe-parse.mjs";import r from"../../custom-field.mjs";import i from"../../utils/key-to-title.mjs";import{richTextFieldConfig as a}from"./config.mjs";import{defaultTextFieldAiGuidance as o}from"../../ai-guidance.mjs";import s from"../../../../../utils/helpers/rich-text-has-content.mjs";import c from"zod";var l=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},ai:this.props?.ai,localized:this.props?.localized??!0,default:this.props?.default??{type:`doc`,content:[{type:`paragraph`}]},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 supportsAi(){return!0}get defaultAiGuidance(){return o}get errors(){let e=super.errors;return{...e,required:{condition:n=>e.required.condition?.(n)===!0||t(n)!==null&&!s(n),message:e.required.message}}}get jsonSchema(){return{type:`object`,additionalProperties:!1,required:[`type`,`content`],properties:{type:{type:`string`,const:`doc`},content:{type:`array`,items:{type:`object`,additionalProperties:!1,required:[`type`,`content`],properties:{type:{type:`string`,const:`paragraph`},content:{type:`array`,items:{type:`object`,additionalProperties:!1,required:[`type`,`text`],properties:{type:{type:`string`,const:`text`},text:{type:`string`}}}}}}}}}}getSchemaDefinition(e){return{data:{columns:[{name:this.key,type:e.db.getDataType(`json`),nullable:!0,default:this.config.default}]},error:void 0}}formatResponseValue(e){return e??this.config.default??null}formatAiGeneratedValue(t){return t&&typeof t==`object`&&!Array.isArray(t)?{success:!0,value:t}:{success:!1,message:e(`server:core.routes.ai.generate.error.message`)}}uniqueValidation(e){let t=n(e,c.record(c.union([c.string(),c.number(),c.symbol()]),c.unknown()));return t.valid?{valid:!0}:t}};export{l as default}; //# sourceMappingURL=custom-field.mjs.map