Skip to content

Commit

Permalink
Merge pull request #125 from commonknowledge/add-rich-text-editor-puc…
Browse files Browse the repository at this point in the history
…k-cms

Add rich text editor puck cms
  • Loading branch information
Moggach committed Jul 31, 2024
2 parents 825487b + 6208992 commit d52c1aa
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 10 deletions.
Binary file added libsass-0.23.0-cp312-cp312-linux_aarch64.whl
Binary file not shown.
112 changes: 106 additions & 6 deletions nextjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"react-hook-form": "^7.51.0",
"react-loader-spinner": "^6.1.6",
"react-map-gl": "^7.1.7",
"react-quill": "^2.0.0",
"react-simple-code-editor": "^0.13.1",
"slug": "^9.1.0",
"sonner": "^1.4.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ul {
list-style-type: disc;
padding-left: 24px;
}

ol {
list-style-type: decimal;
padding-left: 24px;
}

a {
text-decoration: underline;
}

.size-small {
font-size: 16px;
}

.size-medium {
font-size: 20px;
}

.size-large {
font-size: 24px;
}
55 changes: 55 additions & 0 deletions nextjs/src/data/puck/config/blocks/RichText/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { ComponentConfig } from "@measured/puck";
import ReactQuill, { Quill } from 'react-quill';
import 'react-quill/dist/quill.snow.css';
import './customRichTextStyles.css';

const Parchment = Quill.import('parchment');
const SizeClass = new Parchment.Attributor.Class('size', 'size', {
scope: Parchment.Scope.INLINE,
whitelist: ['small', 'medium', 'large']
});
Quill.register(SizeClass, true);

export type RichTextProps = {
content: string
};

const modules = {
toolbar: [
[{ 'size': ['small', 'medium', 'large' ] }],
[ 'italic', 'underline', 'strike'],
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
['link'],
['clean']
],
};

const formats = [
'size', 'italic', 'underline', 'strike',
'list', 'bullet', 'link'
];

export const RichText: ComponentConfig<RichTextProps> = {
label: "RichText",
fields: {
content: {
type: "custom",
render: ({ onChange, value }) => (
<ReactQuill
value={value}
onChange={(e: string) => onChange(e)}
modules={modules}
formats={formats}
/>
),
}
},
render: ({ content }) => {
return (
<div className='max-w-prose'
dangerouslySetInnerHTML={{ __html: content }}
/>
);
},
};
8 changes: 4 additions & 4 deletions nextjs/src/data/puck/config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Config } from "@measured/puck";
import { PuckRichText } from "@tohuhono/puck-rich-text"
import Root, { RootProps } from "./root";
import { ButtonGroup, ButtonGroupProps } from "./blocks/ButtonGroup";
import { Card, CardProps } from "./blocks/Card";
Expand All @@ -21,6 +20,7 @@ import { Image, ImageProps } from "./blocks/Image";
import { HomepageItemsAlias } from "./blocks/HomepageItemsAlias";
import { About } from "./blocks/About";
import { HTMLEmbed, HTMLEmbedProps } from "./blocks/HTMLEmbed";
import { RichText, RichTextProps } from "./blocks/RichText";
import { Iframe, IframeProps } from "./blocks/Iframe";

export type Props = {
Expand All @@ -44,7 +44,8 @@ export type Props = {
HomepageItemsAlias: any;
About: any;
HTMLEmbed: HTMLEmbedProps;
Iframe: IframeProps
Iframe: IframeProps;
RichText: RichTextProps
};

export type UserConfig = Config
Expand Down Expand Up @@ -99,7 +100,6 @@ export const conf: UserConfig = {
},
content: {
components: [
"Text",
"RichText",
"HTMLEmbed",
"Iframe",
Expand All @@ -121,7 +121,7 @@ export const conf: UserConfig = {
EventList,
Image,
HomepageItemsAlias,
RichText: PuckRichText,
RichText,
About,
HTMLEmbed,
Iframe
Expand Down

0 comments on commit d52c1aa

Please sign in to comment.