Overview
The Image extension provides support for embedding images in your editor with features like drag-and-drop upload, paste handling, dimension management, and asynchronous upload with progress tracking.Installation
Basic Usage
Image Attributes
Images support the following attributes:Commands
insertImage
Inserts an image node at the current position or specified position.src: The image URL (optional, can be null for placeholders)width: Image width in pixels (optional)height: Image height in pixels (optional)
uploadImage
Uploads an image file and inserts it with a temporary URL that updates once the upload completes.file: TheFileobject to uploaduploader: Function that handles the upload and returns the final URLpos: Optional position to insert the imagereplace: Whether to replace an existing image atpos(default:false)onError: Optional error handler
Upload Handler
The extension supports automatic file handling for drag-and-drop and paste events.defineImageUploadHandler
Sets up automatic image upload handling:uploader: Async function that uploads the file and returns the URLcanDrop: Optional predicate to determine if a dropped file should be handledcanPaste: Optional predicate to determine if a pasted file should be handled
Uploader Function
The uploader function receives options and should return a promise:Upload Progress Tracking
Track upload progress using theUploadTask class:
Complete Upload Example
Filtering Files
Control which files can be dropped or pasted:Replacing Images
Replace an existing image by specifying position and replace option:Error Handling
Handle upload errors gracefully:Utilities
replaceImageURL
Replace temporary URLs with final URLs after upload:Styling Images
Images render as standard<img> elements and can be styled with CSS:
Image Properties
Images are defined as:- Block-level nodes in the document structure
- Draggable for repositioning
- Defining (cannot be split or joined)
Advanced Features
Custom Upload Service
Image Validation
Related Extensions
- Use with
defineFile()for general file handling - Combine with
defineTable()to embed images in table cells - Works with drag-and-drop indicators for visual feedback