Skip to content

Commit

Permalink
example with shadcn ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Darginec05 committed Sep 25, 2024
1 parent b289c8d commit 49ee90a
Show file tree
Hide file tree
Showing 21 changed files with 1,135 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/plugins/blockquote/src/plugin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Elements, generateId, serializeTextNodesIntoMarkdown, YooptaPlugin } from '@yoopta/editor';
import { Element, Transforms } from 'slate';
import { serializeTextNodesIntoMarkdown, YooptaPlugin } from '@yoopta/editor';
import { BlockquoteCommands } from '../commands';
import { BlockquoteElement } from '../types';
import { BlockquoteRender } from '../ui/Blockquote';

const Blockquote = new YooptaPlugin({
const Blockquote = new YooptaPlugin<Record<'blockquote', BlockquoteElement>>({
type: 'Blockquote',
elements: {
blockquote: {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/headings/src/plugin/HeadingOne.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { YooptaPlugin, PluginElementRenderProps, serializeTextNodesIntoMarkdown } from '@yoopta/editor';
import { HeadingOneCommands } from '../commands';
import { HeadingOneElement } from '../types';

const HeadingOneRender = ({ extendRender, ...props }: PluginElementRenderProps) => {
const { element, HTMLAttributes = {}, attributes, children } = props;
Expand All @@ -16,7 +17,7 @@ const HeadingOneRender = ({ extendRender, ...props }: PluginElementRenderProps)

HeadingOneRender.displayName = 'HeadingOne';

const HeadingOne = new YooptaPlugin({
const HeadingOne = new YooptaPlugin<Record<'heading-one', HeadingOneElement>>({
type: 'HeadingOne',
elements: {
'heading-one': {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/headings/src/plugin/HeadingThree.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PluginElementRenderProps, serializeTextNodesIntoMarkdown, YooptaPlugin } from '@yoopta/editor';
import { HeadingThreeCommands } from '../commands';
import { HeadingThreeElement } from '../types';

const HeadingThreeRender = ({ extendRender, ...props }: PluginElementRenderProps) => {
const { element, HTMLAttributes = {}, attributes, children } = props;
Expand All @@ -22,7 +23,7 @@ const HeadingThreeRender = ({ extendRender, ...props }: PluginElementRenderProps

HeadingThreeRender.displayName = 'HeadingThree';

const HeadingThree = new YooptaPlugin({
const HeadingThree = new YooptaPlugin<Record<'heading-three', HeadingThreeElement>>({
type: 'HeadingThree',
elements: {
'heading-three': {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/headings/src/plugin/HeadingTwo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PluginElementRenderProps, serializeTextNodesIntoMarkdown, YooptaPlugin } from '@yoopta/editor';
import { HeadingTwoCommands } from '../commands';
import { HeadingTwoElement } from '../types';

const HeadingTwoRender = ({ extendRender, ...props }: PluginElementRenderProps) => {
const { element, HTMLAttributes = {}, attributes, children } = props;
Expand All @@ -16,7 +17,7 @@ const HeadingTwoRender = ({ extendRender, ...props }: PluginElementRenderProps)

HeadingTwoRender.displayName = 'HeadingTwo';

const HeadingTwo = new YooptaPlugin({
const HeadingTwo = new YooptaPlugin<Record<'heading-two', HeadingTwoElement>>({
type: 'HeadingTwo',
elements: {
'heading-two': {
Expand Down
3 changes: 2 additions & 1 deletion web/next-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"@emotion/styled": "^11.11.5",
"@floating-ui/react": "^0.26.11",
"@mui/material": "^5.16.0",
"@radix-ui/react-accordion": "^1.2.0",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.0.2",
"@types/js-beautify": "^1.14.3",
"@uiw/codemirror-theme-vscode": "^4.21.24",
"@uiw/react-codemirror": "^4.21.25",
"class-variance-authority": "^0.7.0",
"@yoopta/accordion": "^4.8.2",
"@yoopta/action-menu-list": "^4.8.2",
"@yoopta/blockquote": "^4.8.2",
Expand All @@ -45,6 +45,7 @@
"@yoopta/table": "^4.8.2",
"@yoopta/toolbar": "^4.8.2",
"@yoopta/video": "^4.8.2",
"class-variance-authority": "^0.7.0",
"classnames": "^2.5.1",
"clsx": "^2.1.0",
"codemirror": "^6.0.1",
Expand Down
189 changes: 189 additions & 0 deletions web/next-example/src/components/examples/withShadcnUILibrary/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import YooptaEditor, { createYooptaEditor, Elements, Blocks, useYooptaEditor } from '@yoopta/editor';

import Paragraph from '@yoopta/paragraph';
import Blockquote from '@yoopta/blockquote';
import Embed from '@yoopta/embed';
import Image from '@yoopta/image';
import Link from '@yoopta/link';
import Callout from '@yoopta/callout';
import Video from '@yoopta/video';
import File from '@yoopta/file';
import Accordion from '@yoopta/accordion';
import { NumberedList, BulletedList, TodoList } from '@yoopta/lists';
import { Bold, Italic, CodeMark, Underline, Strike, Highlight } from '@yoopta/marks';
import { HeadingOne, HeadingThree, HeadingTwo } from '@yoopta/headings';
import Code from '@yoopta/code';
import Table, { TableCommands } from '@yoopta/table';
import Divider from '@yoopta/divider';
import ActionMenuList, { DefaultActionMenuRender } from '@yoopta/action-menu-list';
import Toolbar, { DefaultToolbarRender } from '@yoopta/toolbar';
import LinkTool, { DefaultLinkToolRender } from '@yoopta/link-tool';

import { uploadToCloudinary } from '@/utils/cloudinary';
import { useEffect, useMemo, useRef } from 'react';
import { initValue } from './initValue';
import { TypographyP } from '@/components/libraries/shadcn/TypographyP';
import { TypographyH1 } from '@/components/libraries/shadcn/TypographyH1';
import { TypographyH2 } from '@/components/libraries/shadcn/TypographyH2';
import { TypographyH3 } from '@/components/libraries/shadcn/TypographyH3';
import { TypographyBlockquote } from '@/components/libraries/shadcn/TypographyBlockquote';
import { TypographyLink } from '@/components/libraries/shadcn/TypographyLink';
import {
AccordionItem as AccordionItemShadcn,
Accordion as AccordionShadcn,
AccordionContent as AccordionContentShadcn,
} from '@/components/ui/accordion';
import {
AccordionList,
AccordionListItem,
AccordionListItemContent,
AccordionListItemHeading,
} from '@/components/libraries/shadcn/Accordion';

const plugins = [
Paragraph.extend({
renders: {
paragraph: TypographyP,
},
}),
HeadingOne.extend({
renders: {
'heading-one': TypographyH1,
},
}),
HeadingTwo.extend({
renders: {
'heading-two': TypographyH2,
},
}),
,
HeadingThree.extend({
renders: {
'heading-three': TypographyH3,
},
}),
,
Blockquote.extend({
renders: {
blockquote: TypographyBlockquote,
},
}),
Link.extend({
renders: {
link: TypographyLink,
},
}),
Accordion.extend({
renders: {
'accordion-list': AccordionList,
'accordion-list-item': AccordionListItem,
'accordion-list-item-content': AccordionListItemContent,
'accordion-list-item-heading': AccordionListItemHeading,
},
}),
Table,
NumberedList,
BulletedList,
TodoList,
Divider.extend({
elementProps: {
divider: (props) => ({
...props,
color: 'hsl(240 3.7% 15.9%)',
}),
},
}),
Callout,
Code,
Embed,
Image.extend({
options: {
async onUpload(file) {
const data = await uploadToCloudinary(file, 'image');

return {
src: data.secure_url,
alt: 'cloudinary',
sizes: {
width: data.width,
height: data.height,
},
};
},
},
}),
Video.extend({
options: {
onUpload: async (file) => {
const data = await uploadToCloudinary(file, 'video');
return {
src: data.secure_url,
alt: 'cloudinary',
sizes: {
width: data.width,
height: data.height,
},
};
},
onUploadPoster: async (file) => {
const image = await uploadToCloudinary(file, 'image');
return image.secure_url;
},
},
}),
File.extend({
options: {
onUpload: async (file) => {
const response = await uploadToCloudinary(file, 'auto');
return { src: response.secure_url, format: response.format, name: response.name, size: response.bytes };
},
},
}),
];

const TOOLS = {
ActionMenu: {
render: DefaultActionMenuRender,
tool: ActionMenuList,
},
Toolbar: {
render: DefaultToolbarRender,
tool: Toolbar,
},
LinkTool: {
render: DefaultLinkToolRender,
tool: LinkTool,
},
};

const MARKS = [Bold, Italic, CodeMark, Underline, Strike, Highlight];

function WithShadcnUILibrary() {
const editor = useMemo(() => createYooptaEditor(), []);
const selectionRef = useRef(null);

useEffect(() => {
editor.on('change', (value) => {
console.log('value', value);
});
}, []);

return (
<div
className="md:py-[100px] md:pl-[200px] md:pr-[80px] px-[20px] pt-[80px] pb-[40px] flex justify-center"
ref={selectionRef}
>
<YooptaEditor
editor={editor}
plugins={plugins}
tools={TOOLS}
marks={MARKS}
selectionBoxRoot={selectionRef}
value={initValue}
autoFocus
/>
</div>
);
}

export default WithShadcnUILibrary;
Loading

0 comments on commit 49ee90a

Please sign in to comment.