F:\git\Melex_2\payload\src\fields\richText\index.ts:38
link({
^
TypeError: (0 , link_1.default) is not a function
Any ideas?
Also, I'm setting up a boilerplate template to service clients and give them the option to add their own pages, with Blocks layouts. I assume this RichText component is fundamental to a good content editing experience and this template I'm aiming to create?
import type { RichTextElement, RichTextField, RichTextLeaf } from 'payload/dist/fields/config/types'
import deepMerge from '../../utilities/deepMerge'
import link from '../link'
import elements from './elements'
import leaves from './leaves'
type RichText = (
overrides?: Partial<RichTextField>,
additions?: {
elements?: RichTextElement[]
leaves?: RichTextLeaf[]
},
) => RichTextField
const richText: RichText = (
overrides,
additions = {
elements: [],
leaves: [],
},
) =>
deepMerge<RichTextField, Partial<RichTextField>>(
{
name: 'richText',
type: 'richText',
required: true,
admin: {
upload: {
collections: {
media: {
fields: [
{
name: 'enableLink',
type: 'checkbox',
label: 'Enable Link',
},
link({
appearances: false,
disableLabel: true,
overrides: {
admin: {
condition: (_, data) => Boolean(data?.enableLink),
},
},
}),
],
},
},
},
elements: [...elements, ...(additions.elements || [])],
leaves: [...leaves, ...(additions.leaves || [])],
},
},
overrides,
)
export default richText
Within link.ts, I'm receiving an error regarding the PageType - does this correlate to the OP error? How might I solve?
Hi @taun2160 - looks like you need to import
PageType
. Likely needs to be imported from your
payload-types.ts
In your
link.ts
file can you show me where
link
is getting exported?
Thanks @jesschow.
Here's link.ts
import { Field } from 'payload/types';
import { PageType } from 'payload/types';
export type Type = {
type: 'page' | 'custom'
label: string
page?: PageType
url?: string
}
const link: Field = {
name: 'link',
type: 'group',
fields: [
{
name: 'type',
type: 'radio',
options: [
{
label: 'Page',
value: 'page',
},
{
label: 'Custom URL',
value: 'custom',
},
],
defaultValue: 'page',
admin: {
layout: 'horizontal',
},
},
{
type: 'row',
fields: [
{
name: 'label',
label: 'Label',
type: 'text',
required: true,
admin: {
width: '50%',
},
},
{
name: 'page',
label: 'Page to link to',
type: 'relationship',
relationTo: 'pages',
required: true,
admin: {
condition: (_, siblingData) => siblingData?.type === 'page',
width: '50%',
},
},
{
name: 'url',
label: 'Custom URL',
type: 'text',
required: true,
admin: {
condition: (_, siblingData) => siblingData?.type === 'custom',
width: '50%',
},
},
],
},
],
};
export default link;
PageType doesn't exist in payload-types and I can't access payload-type from the payload-main repo. Do you know what PageType should be defined as?
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.