Skip to content

Commit

Permalink
fix(cms): rich text editor admin config schema changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzzy committed Aug 30, 2024
1 parent bc39163 commit 932b8d0
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 71 deletions.
13 changes: 8 additions & 5 deletions apps/cms/src/blocks/Media.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Block } from 'payload/types';
import { slateEditor } from "@payloadcms/richtext-slate";

export const MediaBlock: Block = {
slug: 'media',
Expand Down Expand Up @@ -74,11 +75,13 @@ export const MediaBlock: Block = {
name: 'caption',
label: 'Caption',
type: 'richText',
admin: {
elements: [
'link',
],
},
editor: slateEditor({
admin: {
elements: [
'link',
],
},
})
},
],
};
140 changes: 74 additions & 66 deletions apps/cms/src/fields/richText/richtext.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,101 @@
import { RichTextElement, RichTextField, RichTextLeaf } from 'payload/dist/fields/config/types';
import deepMerge from '../../utilities/deepMerge';
import { RichTextField } from "payload/dist/fields/config/types";
import {
slateEditor,
RichTextElement,
RichTextLeaf,
} from "@payloadcms/richtext-slate";
import deepMerge from "../../utilities/deepMerge";
// import elements from './elements';
// import leaves from './leaves';
// import link from '../link';

type RichText = (
overrides?: Partial<RichTextField>,
additions?: {
elements?: RichTextElement[]
leaves?: RichTextLeaf[]
}
) => RichTextField
elements?: RichTextElement[];
leaves?: RichTextLeaf[];
},
) => RichTextField;

const richText: RichText = (
overrides,
_additions = {
elements: [],
leaves: [],
},
) => deepMerge<RichTextField, Partial<RichTextField>>(
{
name: 'richText',
type: 'richText',
admin: {
upload: {
collections: {
media: {
fields: [
{
type: 'richText',
name: 'caption',
label: 'Caption',
// admin: {
// elements: [
// ...elements,
// ],
// leaves: [
// ...leaves,
// ],
// },
},
{
type: 'radio',
name: 'alignment',
label: 'Alignment',
options: [
) =>
deepMerge<RichTextField, Partial<RichTextField>>(
{
name: "richText",
type: "richText",
editor: slateEditor({
admin: {
upload: {
collections: {
media: {
fields: [
{
label: 'Left',
value: 'left',
type: "richText",
name: "caption",
label: "Caption",
// admin: {
// elements: [
// ...elements,
// ],
// leaves: [
// ...leaves,
// ],
// },
},
{
label: 'Center',
value: 'center',
type: "radio",
name: "alignment",
label: "Alignment",
options: [
{
label: "Left",
value: "left",
},
{
label: "Center",
value: "center",
},
{
label: "Right",
value: "right",
},
],
},
{
label: 'Right',
value: 'right',
name: "enableLink",
type: "checkbox",
label: "Enable Link",
},
// link({
// appearances: false,
// disableLabel: true,
// overrides: {
// admin: {
// condition: (_, data) => Boolean(data?.enableLink),
// },
// },
// }),
],
},
{
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 || [],
// ],
},
},
// elements: [
// ...elements,
// ...additions.elements || [],
// ],
// leaves: [
// ...leaves,
// ...additions.leaves || [],
// ],
}),
},
},
overrides,
);
overrides,
);

export default richText;

0 comments on commit 932b8d0

Please sign in to comment.