|
| 1 | +# 🚀 Get Started with Yoopta Editor |
| 2 | + |
| 3 | +## Installing |
| 4 | + |
| 5 | +First, install the core package `@yoopta/editor` with the default plugin `@yoopta/paragraph` and peer dependencies: |
| 6 | + |
| 7 | +```bash |
| 8 | +yarn add @yoopta/editor @yoopta/paragraph slate slate-react |
| 9 | +# or |
| 10 | +npm install @yoopta/editor @yoopta/paragraph slate slate-react |
| 11 | +``` |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Initialize the editor instance, import `YooptaEditor` component, and pass a list of plugins: |
| 18 | + |
| 19 | +```tsx |
| 20 | +import { useMemo, useState } from "react"; |
| 21 | +import YooptaEditor, { createYooptaEditor, YooptaContentValue } from "@yoopta/editor"; |
| 22 | +import Paragraph from "@yoopta/paragraph"; |
| 23 | + |
| 24 | +const plugins = [Paragraph]; |
| 25 | + |
| 26 | +const Editor = () => { |
| 27 | + const editor = useMemo(() => createYooptaEditor(), []); |
| 28 | + const [value, setValue] = useState<YooptaContentValue>(); |
| 29 | + |
| 30 | + const onChange = (value: YooptaContentValue, options: YooptaOnChangeOptions) => { |
| 31 | + setValue(value); |
| 32 | + }; |
| 33 | + |
| 34 | + return ( |
| 35 | + <YooptaEditor |
| 36 | + editor={editor} |
| 37 | + plugins={plugins} |
| 38 | + placeholder="Type something" |
| 39 | + value={value} |
| 40 | + onChange={onChange} |
| 41 | + /> |
| 42 | + ); |
| 43 | +}; |
| 44 | +``` |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## Plugins |
| 49 | + |
| 50 | +Here is a list of available plugins: |
| 51 | + |
| 52 | +``` |
| 53 | +@yoopta/paragraph |
| 54 | +@yoopta/blockquote |
| 55 | +@yoopta/accordion |
| 56 | +@yoopta/code |
| 57 | +@yoopta/embed |
| 58 | +@yoopta/image |
| 59 | +@yoopta/link |
| 60 | +@yoopta/file |
| 61 | +@yoopta/callout |
| 62 | +@yoopta/video |
| 63 | +@yoopta/lists |
| 64 | +@yoopta/headings |
| 65 | +@yoopta/table |
| 66 | +@yoopta/divider |
| 67 | +``` |
| 68 | + |
| 69 | +Install them with: |
| 70 | + |
| 71 | +```bash |
| 72 | +yarn add @yoopta/embed @yoopta/headings @yoopta/image @yoopta/link @yoopta/lists @yoopta/paragraph @yoopta/video @yoopta/blockquote @yoopta/callout @yoopta/code @yoopta/file @yoopta/accordion @yoopta/table @yoopta/divider |
| 73 | + |
| 74 | +# or |
| 75 | + |
| 76 | +npm install @yoopta/embed @yoopta/headings @yoopta/image @yoopta/link @yoopta/lists @yoopta/paragraph @yoopta/video @yoopta/blockquote @yoopta/callout @yoopta/code @yoopta/file @yoopta/accordion @yoopta/table @yoopta/divider |
| 77 | +``` |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## Example Usage with Multiple Plugins |
| 82 | + |
| 83 | +```tsx |
| 84 | +import { useMemo, useState } from 'react'; |
| 85 | +import YooptaEditor, { createYooptaEditor, YooptaContentValue } from '@yoopta/editor'; |
| 86 | +import Paragraph from '@yoopta/paragraph'; |
| 87 | +import Blockquote from '@yoopta/blockquote'; |
| 88 | + |
| 89 | +const plugins = [Paragraph, Blockquote]; |
| 90 | + |
| 91 | +export default function Editor() { |
| 92 | + const editor = useMemo(() => createYooptaEditor(), []); |
| 93 | + const [value, setValue] = useState<YooptaContentValue>(); |
| 94 | + |
| 95 | + const onChange = (value: YooptaContentValue, options: YooptaOnChangeOptions) => { |
| 96 | + setValue(value); |
| 97 | + }; |
| 98 | + |
| 99 | + return ( |
| 100 | + <div> |
| 101 | + <YooptaEditor |
| 102 | + editor={editor} |
| 103 | + placeholder="Type text.." |
| 104 | + value={value} |
| 105 | + onChange={onChange} |
| 106 | + plugins={plugins} |
| 107 | + /> |
| 108 | + </div> |
| 109 | + ); |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## Tools |
| 116 | + |
| 117 | +Yoopta Editor provides useful tools for working with content. |
| 118 | + |
| 119 | +### Available Tools: |
| 120 | + |
| 121 | +``` |
| 122 | +@yoopta/action-menu-list |
| 123 | +@yoopta/toolbar |
| 124 | +@yoopta/link-tool |
| 125 | +@yoopta/chat-gpt-assistant (in progress) |
| 126 | +``` |
| 127 | + |
| 128 | +### How to Use: |
| 129 | + |
| 130 | +```tsx |
| 131 | +import { useMemo, useState } from 'react'; |
| 132 | +import YooptaEditor, { createYooptaEditor, YooptaContentValue } from '@yoopta/editor'; |
| 133 | +import LinkTool, { DefaultLinkToolRender } from '@yoopta/link-tool'; |
| 134 | +import ActionMenu, { DefaultActionMenuRender } from '@yoopta/action-menu-list'; |
| 135 | +import Toolbar, { DefaultToolbarRender } from '@yoopta/toolbar'; |
| 136 | + |
| 137 | +const TOOLS = { |
| 138 | + Toolbar: { |
| 139 | + tool: Toolbar, |
| 140 | + render: DefaultToolbarRender, |
| 141 | + }, |
| 142 | + ActionMenu: { |
| 143 | + tool: ActionMenu, |
| 144 | + render: DefaultActionMenuRender, |
| 145 | + }, |
| 146 | + LinkTool: { |
| 147 | + tool: LinkTool, |
| 148 | + render: DefaultLinkToolRender, |
| 149 | + }, |
| 150 | +}; |
| 151 | + |
| 152 | +export default function Editor() { |
| 153 | + const editor = useMemo(() => createYooptaEditor(), []); |
| 154 | + const [value, setValue] = useState<YooptaContentValue>(); |
| 155 | + |
| 156 | + const onChange = (value: YooptaContentValue, options: YooptaOnChangeOptions) => { |
| 157 | + setValue(value); |
| 158 | + }; |
| 159 | + |
| 160 | + return ( |
| 161 | + <div> |
| 162 | + <YooptaEditor |
| 163 | + editor={editor} |
| 164 | + plugins={plugins} |
| 165 | + placeholder="Type text.." |
| 166 | + value={value} |
| 167 | + onChange={onChange} |
| 168 | + tools={TOOLS} |
| 169 | + /> |
| 170 | + </div> |
| 171 | + ); |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## Marks |
| 178 | + |
| 179 | +Marks are simple text formats provided by the `@yoopta/marks` package. |
| 180 | + |
| 181 | +### Available Marks: |
| 182 | + |
| 183 | +- **Bold** |
| 184 | +- **Italic** |
| 185 | +- **CodeMark** |
| 186 | +- **Underline** |
| 187 | +- **Strike** |
| 188 | +- **Highlight** |
| 189 | + |
| 190 | +### How to Use: |
| 191 | + |
| 192 | +```tsx |
| 193 | +import { useMemo, useState } from 'react'; |
| 194 | +import YooptaEditor, { createYooptaEditor, YooptaContentValue } from '@yoopta/editor'; |
| 195 | +import { Bold, Italic, CodeMark, Underline, Strike, Highlight } from '@yoopta/marks'; |
| 196 | + |
| 197 | +const MARKS = [Bold, Italic, CodeMark, Underline, Strike, Highlight]; |
| 198 | + |
| 199 | +export default function Editor() { |
| 200 | + const editor = useMemo(() => createYooptaEditor(), []); |
| 201 | + const [value, setValue] = useState<YooptaContentValue>(); |
| 202 | + |
| 203 | + const onChange = (value: YooptaContentValue, options: YooptaOnChangeOptions) => { |
| 204 | + setValue(value); |
| 205 | + }; |
| 206 | + |
| 207 | + return ( |
| 208 | + <div> |
| 209 | + <YooptaEditor |
| 210 | + editor={editor} |
| 211 | + placeholder="Type text.." |
| 212 | + plugins={plugins} |
| 213 | + tools={TOOLS} |
| 214 | + value={value} |
| 215 | + onChange={onChange} |
| 216 | + marks={MARKS} |
| 217 | + /> |
| 218 | + </div> |
| 219 | + ); |
| 220 | +} |
| 221 | +``` |
0 commit comments