UNPKG

@websolutespa/payload-plugin-bowl

Version:

Bowl PayloadCms plugin of the BOM Repository

199 lines (198 loc) 6.38 kB
import { withAction, withAddress, withBlock, withCollection, withEndUser, withGlobal, withMenu, withPage, withStaticCollection, withUser } from './core/collections'; import { withAbstract, withCategory, withCheckbox, withComponents, withDate, withDescription, withId, withIsActive, withIsDefault, withLink, withMarkets, withMedia, withMedias, withName, withNav, withOrder, withRelated, withRichText, withRoles, withSlug, withTemplate, withText, withTitle } from './core/fields'; import { withAnchor } from './core/fields/withAnchor'; import { withNavs } from './core/fields/withNavs'; import { withSelect } from './core/fields/withSelect'; import { withSeoWeight } from './core/fields/withSeoWeight'; import { withTenants } from './core/fields/withTenants'; import { withColor } from './fields'; export function toCollection(collection) { collection = { ...collection }; delete collection.views; const type = collection.type; if (!collection.fields) { console.log('collection', collection); } const fields = (collection.fields || []).map((x)=>toField(x)); delete collection.type; delete collection.fields; const item = { ...collection, fields }; switch(type){ case 'withPage': return withPage(item); // as WithPageProps case 'withCollection': return withCollection(item); case 'withStatic': return withStaticCollection(item); case 'withMenu': return withMenu(item); case 'withAction': return withAction(item); case 'withUser': return withUser(item); case 'withEndUser': return withEndUser(item); case 'withAddress': return withAddress(item); default: return item; } } export function toGlobal(collection) { collection = { ...collection }; delete collection.views; const type = collection.type; const fields = collection.fields.map((x)=>toField(x)); delete collection.type; delete collection.fields; const item = { ...collection, fields }; switch(type){ case 'withGlobal': return withGlobal(item); default: return item; } } export function toField(item) { item = { ...item }; if ('fields' in item) { item.fields = item.fields.map((x)=>toField(x)); } if ('blocks' in item) { item.blocks = item.blocks.map((x)=>toBlock(x)); } if ('tabs' in item) { item.tabs = item.tabs.map((x)=>toTab(x)); } switch(item.type){ case 'withAbstract': delete item.type; return withAbstract(item); case 'withAnchor': delete item.type; return withAnchor(item); case 'withCategory': delete item.type; return withCategory(item); case 'withCheckbox': delete item.type; return withCheckbox(item); case 'withColor': delete item.type; return withColor(item); case 'withComponents': delete item.type; return withComponents(item); case 'withDate': delete item.type; return withDate(item); case 'withDescription': delete item.type; return withDescription(item); case 'withId': delete item.type; return withId(item); case 'withIsActive': delete item.type; return withIsActive(item); case 'withIsDefault': delete item.type; return withIsDefault(item); case 'withLink': delete item.type; return withLink(item); case 'withMarkets': delete item.type; return withMarkets(item); case 'withMedia': delete item.type; return withMedia(item); case 'withMedias': delete item.type; return withMedias(item); case 'withNav': delete item.type; return withNav(item); case 'withNavs': delete item.type; return withNavs(item); case 'withName': delete item.type; return withName(item); case 'withOrder': delete item.type; return withOrder(item); case 'withRelated': delete item.type; return withRelated(item); case 'withRichText': delete item.type; return withRichText(item); case 'withSelect': delete item.type; return withSelect(item); case 'withSeoWeight': delete item.type; return withSeoWeight(item); case 'withSlug': delete item.type; return withSlug(item); case 'withTemplate': delete item.type; return withTemplate(item); case 'withText': delete item.type; return withText(item); case 'withTitle': delete item.type; return withTitle(item); case 'withRoles': delete item.type; return withRoles(item); case 'withTenants': delete item.type; return withTenants(item); case 'array': // const array = item as ArrayField; item.fields = item.fields.map((x)=>toField(x)); return item; case 'blocks': item.blocks = item.blocks.map((x)=>toBlock(x)); return item; case 'collapsible': item.fields = item.fields.map((x)=>toField(x)); return item; case 'group': item.fields = item.fields.map((x)=>toField(x)); return item; case 'row': item.fields = item.fields.map((x)=>toField(x)); return item; case 'tabs': item.tabs = item.tabs.map((x)=>toTab(x)); return item; default: return item; } } export function toBlock(item) { item.fields = item.fields.map((x)=>toField(x)); return withBlock(item); } export function toTab(item) { item.fields = item.fields.map((x)=>toField(x)); return item; } //# sourceMappingURL=mapper.js.map