Files
supabase/apps/cms/src/fields/defaultLexical.ts
T
Francesco SansalvadoreandIvan Vasilov f7d90bbc30 feat: new cms app (#35999)
* add cms turbo app

* add cms scripts to package.json

* update README

* update README

* update files

* fix formatting

* fix populateAuthors

* sync dependencies

* update launch week field

* update lint config

* Coordinate the deps to be the same as the other apps.

* Remove extra files.

* Run prettier on the CMS files.

* Add commands for cleaning and typechecking.

* Fix weird version of @types/react in docs.

* run pnpm install

* fix pnpm-lock

* fix cms lint

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-06-03 14:26:43 +03:00

48 lines
1.3 KiB
TypeScript

import type { TextFieldSingleValidation } from 'payload'
import {
BoldFeature,
ItalicFeature,
LinkFeature,
ParagraphFeature,
lexicalEditor,
UnderlineFeature,
type LinkFields,
} from '@payloadcms/richtext-lexical'
export const defaultLexical = lexicalEditor({
features: [
ParagraphFeature(),
UnderlineFeature(),
BoldFeature(),
ItalicFeature(),
LinkFeature({
enabledCollections: ['posts'],
fields: ({ defaultFields }) => {
const defaultFieldsWithoutUrl = defaultFields.filter((field) => {
if ('name' in field && field.name === 'url') return false
return true
})
return [
...defaultFieldsWithoutUrl,
{
name: 'url',
type: 'text',
admin: {
condition: (_data, siblingData) => siblingData?.linkType !== 'internal',
},
label: ({ t }) => t('fields:enterURL'),
required: true,
validate: ((value, options) => {
if ((options?.siblingData as LinkFields)?.linkType === 'internal') {
return true // no validation needed, as no url should exist for internal links
}
return value ? true : 'URL is required'
}) as TextFieldSingleValidation,
},
]
},
}),
],
})