@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 3.24 kB
JavaScript
import{tenantAccessAllowed as e}from"../../../utils/helpers/tenants.mjs";import{isStorageMode as t}from"../../../libs/collection/custom-fields/storage/index.mjs";import n from"./get-translated-field-details.mjs";import r from"../../../libs/collection/custom-fields/registered-fields.mjs";import{generateHTML as i}from"@lucidcms/rich-text/server";const a=e=>{if(!e||typeof e!=`object`)return e;try{return i(e)}catch{return e}},o=(e,t)=>e.type===`rich-text`?a(t):t,s=(e,t)=>e.type===`rich-text`?Object.fromEntries(Object.entries(t).map(([e,t])=>[e,a(t)])):t,c=(e,t)=>{let n=e.groups?.toSorted((e,t)=>(e.order??0)-(t.order??0)).map(e=>l(e.fields,t))??[];if(n.length!==0)return n},l=(e,n)=>e?.length?e.reduce((e,i)=>{let a=n.get(i.key);if(!a||i.type!==a.type)return e;let l=r[a.type].config.database,u=t(l,`tree-table`)?c(i,n):void 0;return u===void 0?i.translations===void 0?(i.value!==void 0&&(e[a.key]=o(a,i.value)),e):(e[a.key]=s(a,i.translations),e):(e[a.key]=u,e)},{}):{},u=(e,t)=>e.brickInstances.find(e=>e.key===t.key),d=e=>{if(`fields`in e&&Array.isArray(e.fields))return e.fields},f=(e,t)=>{if(!(`options`in t)||!Array.isArray(t.options))return;let n=e.translate.forLocale(e.config.i18n.defaultLocale),r=t.options.flatMap(e=>{if(typeof e.value!=`string`)return[];let t=n(e.label);return[{value:e.value,...t?{label:t}:{}}]});if(r.length!==0)return r},p=e=>{if(`collection`in e)return e.collection},m=e=>{if(`multiple`in e&&typeof e.multiple==`boolean`)return e.multiple},h=e=>{if(e.type===`range`)return{min:e.min,max:e.max,step:e.step,...e.thumbs?{thumbs:e.thumbs}:{}}},g=e=>e.fields.reduce((t,r)=>{let i=e.instances.get(r.key);if(!i||r.type!==i.type)return t;let a=d(r),o=n(e.context,i),s=p(r),c=m(r),l=h(r),u=f(e.context,r);return t[i.key]={type:i.type,localized:e.collection.getData.localized===!0&&i.localizedEnabled===!0,...o?.label?{label:o.label}:{},...o?.summary?{summary:o.summary}:{},...s?{collection:s}:{},...c===void 0?{}:{multiple:c},...l??{},...u?{options:u}:{},...a?{fields:g({context:e.context,collection:e.collection,fields:a,instances:e.instances})}:{}},t},{}),_=(e,t)=>{let n=e.translate.forLocale(e.config.i18n.defaultLocale),r=n(t.config.details.name),i=n(t.config.details.summary);if(!(!r&&!i))return{...r?{name:r}:{},...i?{summary:i}:{}}},v=t=>(t.bricks??[]).filter(n=>e(n.config.tenants,t.context.request.tenantKey)).reduce((e,n)=>{let r=_(t.context,n);return e[n.key]={...r??{},fields:g({context:t.context,collection:t.collection,fields:n.fieldTree,instances:n.fields})},e},{}),y=e=>({fields:g({context:e.context,collection:e.collection,fields:e.collection.fieldTree,instances:e.collection.fields}),fixedBricks:v({context:e.context,collection:e.collection,bricks:e.collection.config.bricks?.fixed}),builderBricks:v({context:e.context,collection:e.collection,bricks:e.collection.config.bricks?.builder})}),b=t=>({fields:l(t.document?.fields,t.collection.fields),bricks:t.document?.bricks?.flatMap(n=>{let r=u(t.collection,n);return!r||!e(r.config.tenants,t.context.request.tenantKey)?[]:[{key:n.key,type:n.type,fields:l(n.fields,r.fields)}]})??[]});export{b as default,y as formatCustomFieldCollectionDefinition,_ as getTranslatedBrickDetails};
//# sourceMappingURL=format-custom-field-document-context.mjs.map