Closes #8051. - The scrolling problem reported in the issue is solved with Monaco's `alwaysConsumeMouseWheel` property. - In addition to that, it is necessary to dynamically adjust the height of the editor so that it fits its content and does not require scrolling. - Additionally, I disabled the `overviewRuler` which is the indicator strip on the side (above the scrollbar) that makes no sense when there is no scroll. **Gotchas** - Unfortunately, there is a bit of CLS since the editor doesn't know the height of its content before rendering. In Lexical these things are possible since it has a lifecycle that allows interaction before or after rendering, but this is not the case with Monaco. - I've noticed that sometimes when I press enter the letters in the editor flicker or move with a small, rapid shake. Maybe it has to do with the new height being calculated as an effect. ## Before https://github.com/user-attachments/assets/0747f79d-a3ac-42ae-8454-0bf46dc43f34 ## After https://github.com/user-attachments/assets/976ab97c-9d20-4e93-afb5-023083a6608b
294 lines
5.5 KiB
TypeScript
294 lines
5.5 KiB
TypeScript
import type { ArrayField, Block } from 'payload'
|
|
|
|
import { BlocksFeature, FixedToolbarFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
|
|
import { textFieldsSlug } from '../Text/shared.js'
|
|
|
|
export const BlockColumns = ({ name }: { name: string }): ArrayField => ({
|
|
type: 'array',
|
|
name,
|
|
interfaceName: 'BlockColumns',
|
|
admin: {
|
|
initCollapsed: true,
|
|
},
|
|
fields: [
|
|
{
|
|
name: 'text',
|
|
type: 'text',
|
|
},
|
|
{
|
|
name: 'subArray',
|
|
type: 'array',
|
|
fields: [
|
|
{
|
|
name: 'requiredText',
|
|
type: 'text',
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
export const ConditionalLayoutBlock: Block = {
|
|
fields: [
|
|
{
|
|
label: 'Layout',
|
|
name: 'layout',
|
|
type: 'select',
|
|
options: ['1', '2', '3'],
|
|
defaultValue: '1',
|
|
required: true,
|
|
},
|
|
{
|
|
...BlockColumns({ name: 'columns' }),
|
|
admin: {
|
|
condition: (data, siblingData) => {
|
|
return ['1'].includes(siblingData.layout)
|
|
},
|
|
},
|
|
minRows: 1,
|
|
maxRows: 1,
|
|
},
|
|
{
|
|
...BlockColumns({ name: 'columns2' }),
|
|
admin: {
|
|
condition: (data, siblingData) => {
|
|
return ['2'].includes(siblingData.layout)
|
|
},
|
|
},
|
|
minRows: 2,
|
|
maxRows: 2,
|
|
},
|
|
{
|
|
...BlockColumns({ name: 'columns3' }),
|
|
admin: {
|
|
condition: (data, siblingData) => {
|
|
return ['3'].includes(siblingData.layout)
|
|
},
|
|
},
|
|
minRows: 3,
|
|
maxRows: 3,
|
|
},
|
|
],
|
|
slug: 'conditionalLayout',
|
|
}
|
|
|
|
export const TextBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'text',
|
|
type: 'text',
|
|
required: true,
|
|
},
|
|
],
|
|
slug: 'text',
|
|
}
|
|
|
|
export const RadioButtonsBlock: Block = {
|
|
interfaceName: 'LexicalBlocksRadioButtonsBlock',
|
|
fields: [
|
|
{
|
|
name: 'radioButtons',
|
|
type: 'radio',
|
|
options: [
|
|
{
|
|
label: 'Option 1',
|
|
value: 'option1',
|
|
},
|
|
{
|
|
label: 'Option 2',
|
|
value: 'option2',
|
|
},
|
|
{
|
|
label: 'Option 3',
|
|
value: 'option3',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
slug: 'radioButtons',
|
|
}
|
|
|
|
export const RichTextBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'richTextField',
|
|
type: 'richText',
|
|
editor: lexicalEditor({
|
|
features: ({ defaultFeatures }) => [
|
|
...defaultFeatures,
|
|
FixedToolbarFeature(),
|
|
BlocksFeature({
|
|
blocks: [
|
|
{
|
|
fields: [
|
|
{
|
|
name: 'subRichTextField',
|
|
type: 'richText',
|
|
editor: lexicalEditor({}),
|
|
},
|
|
{
|
|
name: 'subUploadField',
|
|
type: 'upload',
|
|
relationTo: 'uploads',
|
|
},
|
|
],
|
|
slug: 'lexicalAndUploadBlock',
|
|
},
|
|
],
|
|
}),
|
|
],
|
|
}),
|
|
},
|
|
],
|
|
slug: 'richTextBlock',
|
|
}
|
|
|
|
export const UploadAndRichTextBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'upload',
|
|
type: 'upload',
|
|
relationTo: 'uploads',
|
|
required: true,
|
|
},
|
|
{
|
|
name: 'richText',
|
|
type: 'richText',
|
|
editor: lexicalEditor(),
|
|
},
|
|
],
|
|
slug: 'uploadAndRichText',
|
|
}
|
|
|
|
export const RelationshipHasManyBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'rel',
|
|
type: 'relationship',
|
|
hasMany: true,
|
|
relationTo: [textFieldsSlug, 'uploads'],
|
|
required: true,
|
|
},
|
|
],
|
|
slug: 'relationshipHasManyBlock',
|
|
}
|
|
export const RelationshipBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'rel',
|
|
type: 'relationship',
|
|
relationTo: 'uploads',
|
|
required: true,
|
|
},
|
|
],
|
|
slug: 'relationshipBlock',
|
|
}
|
|
|
|
export const SelectFieldBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'select',
|
|
type: 'select',
|
|
options: [
|
|
{
|
|
label: 'Option 1',
|
|
value: 'option1',
|
|
},
|
|
{
|
|
label: 'Option 2',
|
|
value: 'option2',
|
|
},
|
|
{
|
|
label: 'Option 3',
|
|
value: 'option3',
|
|
},
|
|
{
|
|
label: 'Option 4',
|
|
value: 'option4',
|
|
},
|
|
{
|
|
label: 'Option 5',
|
|
value: 'option5',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
slug: 'select',
|
|
}
|
|
|
|
export const SubBlockBlock: Block = {
|
|
slug: 'subBlock',
|
|
fields: [
|
|
{
|
|
name: 'subBlocks',
|
|
type: 'blocks',
|
|
blocks: [
|
|
{
|
|
slug: 'contentBlock',
|
|
fields: [
|
|
{
|
|
name: 'richText',
|
|
type: 'richText',
|
|
required: true,
|
|
editor: lexicalEditor(),
|
|
},
|
|
],
|
|
},
|
|
{
|
|
slug: 'textArea',
|
|
fields: [
|
|
{
|
|
name: 'content',
|
|
type: 'textarea',
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
SelectFieldBlock,
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
export const TabBlock: Block = {
|
|
slug: 'tabBlock',
|
|
fields: [
|
|
{
|
|
type: 'tabs',
|
|
tabs: [
|
|
{
|
|
label: 'Tab1',
|
|
name: 'tab1',
|
|
fields: [
|
|
{
|
|
name: 'text1',
|
|
type: 'text',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
label: 'Tab2',
|
|
name: 'tab2',
|
|
fields: [
|
|
{
|
|
name: 'text2',
|
|
type: 'text',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
}
|
|
|
|
export const CodeBlock: Block = {
|
|
fields: [
|
|
{
|
|
name: 'code',
|
|
type: 'code',
|
|
},
|
|
],
|
|
slug: 'code',
|
|
}
|