reactjs-tiptap-editor
repository·main·Indexed 20 days ago
https://github.com/hunghg255/reactjs-tiptap-editorA modern WYSIWYG rich text editor for React applications, built on Tiptap and utilizing shadcn ui components. Version 1.0.31 provides a ready-to-use editor interface with various extensions including Attachment, Blockquote, Bold, BulletList, and Callout, each offering both core logic and corresponding toolbar UI components.
What's inside reactjs-tiptap-editor
- A modern WYSIWYG rich-text editor built on top of Tiptap that utilizes Shadcn components for its UI. It provides a ready-to-use editor interface for React applications.
Keyboard shortcut behavior for Color
mainThe default shortcut
Mod-Shift-C(Cmd-Shift-C on Mac, Ctrl-Shift-C on Windows/Linux) features intelligent toggle logic:- No color applied: Applies the currently selected color to the selection.
- Same color already applied: Removes the color (toggles it off).
- Different color applied: Replaces the existing color with the currently selected color.
- "No Fill" selected: Does nothing, preventing the application of an undefined color.
Understand Inline vs Block images
mainThe
Image.configure()method registers two node types to ensure compatibility and flexibility:image: A legacy inline node used for ProseMirror JSON compatibility and when images are wrapped in<span>tags withinline="true"in HTML.imageBlock: A block-level node used whendefaultInlineis set tofalseor when usingsetImageBlock(). In HTML, these are parsed from<div class="image"><img ... /></div>.
Migration Note: If you are migrating old JSON data where
type: "image"is used, use themigrateImageJSONToImageBlock(json)function before saving the document to convert them to the new block format.Understand Highlight color synchronization
mainThe Highlight extension maintains a shared state for the selected color across all UI components. This ensures a consistent user experience:
- Selecting a color in the toolbar updates the bubble menu.
- Selecting a color in the bubble menu updates the toolbar.
- The keyboard shortcut always uses the last selected color.
- All color pickers (palette, recent, custom) stay in sync.
- Selecting "No Fill" clears the stored color state.
Understand Video upload behavior and lifecycle
mainUpload Lifecycle
- During Upload: The toolbar and slash-command dialogs remain open but the upload button is disabled.
- Progress: If
showUploadProgressis true, the editor displays overall and per-file progress. If theuploadfunction ignores theonProgresscallback, an indeterminate spinner is shown. - Completion: When all uploads resolve, URLs are inserted in the order files were selected, and the dialog closes. Files that reach 100% but are still resolving are marked as 'processing'.
- Failures: If one upload fails, successful uploads are still inserted. The failed file remains visible in the dialog for retry. If no
onErrorhandler is provided, a default error toast is shown.
Validation
acceptMimesandmaxSizeare checked before the upload begins.- With
multiple: true, valid files are queued and processed according touploadConcurrency.
How to create a code block in the editor
mainTo trigger a code block, type the triple backtick sequence```and press <kbd>Enter</kbd>. The editor will load the language on the fly.Understand Highlight keyboard shortcut behavior
mainThe default shortcut
Mod-Shift-H(Ctrl-Shift-H on Windows/Linux, Cmd-Shift-H on Mac) follows an intelligent toggle logic:- No highlight applied: Applies the currently selected highlight color.
- Same color already applied: Removes the highlight (toggles off).
- Different color applied: Replaces the existing highlight with the currently selected color.
- "No Fill" selected: Does nothing (prevents applying an undefined highlight).
Pair RichText components with their required extensions
mainThe
reactjs-tiptap-editoruses specific component-to-extension pairings. If you use aRichTextUI component, you must include the corresponding Tiptap extension in your configuration:UI Component Required Extension RichTextImageImageRichTextBubbleImageImageSlashCommandListSlashCommandRichTextUndo/RichTextRedoHistoryRichTextBubbleCodeBlockCodeBlockRichTextTable/RichTextBubbleTableTableServer Rendering (SSR) and Next.js Notes
mainThe Tiptap editor UI is client-side only and must be rendered in a browser/client component.
- Next.js App Router: Add the
'use client'directive at the top of your editor component file. - Avoid Global APIs: Do not attempt to access
window,document,FileReader, or object URLs during the server rendering phase.
- Next.js App Router: Add the
Avoid common reactjs-tiptap-editor anti-patterns
mainTo ensure a stable and performant editor, avoid these common mistakes:
- Missing Extensions: Never render a UI component like
RichTextBold,RichTextImage,SlashCommandList, orRichTextBubble*without including its corresponding extension in theextensionsarray. The UI will exist, but it will not function. - Blind StarterKit Usage: Do not use
@tiptap/starter-kitif you are already importing individual base extensions manually, as this can lead to redundancy. - Missing Styles: Always ensure
reactjs-tiptap-editor/style.cssis imported. Without it, the editor UI will be broken. - Server-Side Rendering Errors: Do not attempt to render editor code in a React Server Component. Use a client boundary (
'use client') in frameworks like Next.js. - Bloated Bundles: Avoid importing every available extension "just in case". Only import what is strictly necessary for the requested features.
- Incorrect Upload Handlers: In production, ensure upload callbacks return a
Promise<string>representing the URL of the uploaded asset.
- Missing Extensions: Never render a UI component like
How Color selection synchronization works
mainThe Color extension implements a shared color state across all UI instances. This ensures a consistent user experience:
- Toolbar & Bubble Menu: Selecting a color in the toolbar automatically updates the bubble menu, and vice versa.
- Keyboard Shortcuts: The shortcut uses the most recently selected color.
- Picker Consistency: All active color pickers in the editor will display the same currently selected color.
Configure Feature-Specific Dependencies
mainSome features require additional third-party packages or specific configurations to function:
- Image Crop UI: Install
react-image-cropand importreact-image-crop/dist/ReactCrop.css. - CodeBlock Syntax Highlighting: Install
highlight.jsandlowlight, then configure usingCodeBlock.configure({ lowlight }). - ImageGif with Giphy: Configure using
ImageGif.configure({ provider: 'giphy', API_KEY }). - Mandatory Styles: Always ensure you import
reactjs-tiptap-editor/style.css.
- Image Crop UI: Install