Skip to content

Image

Usage

tsx
import { Image } from 'reactjs-tiptap-editor/image'; 
import 'react-image-crop/dist/ReactCrop.css'; 

const extensions = [
  ...,
  // Import Extensions Here
  Image.configure({
    upload: (file: File) => {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve(URL.createObjectURL(file))
        }, 500)
      })
    },
  }),
];

Image Gif

  • ImageGif is a node extension that allows you to add an ImageGif to your editor.
  • More: ImageGif

Props

ts
interface IImageOptions extends GeneralOptions<IImageOptions> {
  /** Function for uploading files */
  upload?: (file: File) => Promise<string>

  HTMLAttributes?: any

  multiple?: boolean
  acceptMimes?: string[]
  maxSize?: number

  /** The source URL of the image */
  resourceImage: 'upload' | 'link' | 'both'
  defaultInline?: boolean,

  onError?: (error: {
    type: 'size' | 'type' | 'upload';
    message: string;
    file?: File;
  }) => void;
}
PropertyTypeDescriptionRequiredDefault
upload(file: File) => Promise<string>Custom image upload function that receives a File and returns a Promise with the image URL, suitable for uploading to cloud or local servers.NoNone
HTMLAttributesanyHTML attributes passed to the <img> tag, such as className, style, alt, etc.NoNone
multiplebooleanWhether to allow selecting and uploading multiple images simultaneously.Notrue
acceptMimesstring[]List of allowed image MIME types or file extension restrictions, such as ['image/jpeg', 'image/png'], ['image/*'], or ['.png', '.jpg'], etc. Supports MIME type wildcards and precise file extension restrictions.NoCommon image types ['image/jpeg', 'image/gif', 'image/png', 'image/jpg']
maxSizenumberMaximum size limit for a single image (in bytes), triggers onError when exceeded.No5MB
resourceImage'upload' | 'link' | 'both'Image source method: - 'upload': Upload only - 'link': Link only - 'both': Both supportedYesboth
defaultInlinebooleanWhether to insert images as inline elements by default.Nofalse
onError(error: { type: 'size' | 'type' | 'upload'; message: string; file?: File }) => voidCallback function for upload or validation failures. Contains error type (size, type, upload), error message, and corresponding file.NoNone

resourceImage Type Description

  • 'upload': Users can only select local files for upload
  • 'link': Users can only input image URLs
  • 'both': Supports both upload and URL methods

acceptMimes Usage Instructions

Supports three format types:

  1. MIME types: such as ['image/jpeg', 'image/png']
  2. Wildcard types: such as ['image/*'], matches all image MIME types
  3. Extension types: such as:
ts
[
  '.png', '.jpg', '.jpeg', '.webp', '.gif', '.svg', '.svgz', '.xbm',
  '.tiff', '.ico', '.jfif', '.heic', '.heif', '.avif', '.bmp',
  '.apng', '.pjpeg'
]

onError Example

  • Customize error handling logic to unify system prompts.
  • We recommend using the message field, which has built-in dynamic prompts and i18n internationalization support.
ts
onError: ({ type, message, file }) => {
  switch (type) {
    case 'size':
      console.warn(`File size exceeds limit: ${file?.name}`);
      break;
    case 'type':
      console.warn(`Unsupported file type: ${file?.type}`);
      break;
    case 'upload':
      console.error(`Upload failed: ${message}`);
      break;
  }
}

Source

SourceDocs

Contributors

Changelog

v0.3.16 on 7/29/2025
cbe0c - fix(image): improve crop modal and upload handling
v0.3.15 on 7/27/2025
6eaab - fix(image): enable text wrapping for inline images aligned left or right
v0.1.7 on 11/9/2024
83270 - feat: flip image
v0.1.3 on 11/5/2024
93d97 - fix: parse inline image
v0.0.56 on 10/25/2024
fcd95 - feat: image inline, refactor video upload

Made with ❤️