Image plugin for Plate rich text editor that enables embedding, uploading, and managing images with advanced features like drag-and-drop, resizing, and captions.
—
Core plugin factory and configuration options for integrating image functionality into Plate editors.
Creates the main image plugin with configurable options for upload handling and behavior customization.
/**
* Creates an image plugin for Plate editor with configurable options
* @param options - Plugin configuration options
* @returns Configured Plate plugin for image functionality
*/
function createImagePlugin(options?: {
options?: ImagePlugin;
}): PlatePlugin<ImagePlugin>;Usage Examples:
import { createImagePlugin } from "@udecode/plate-image";
// Basic plugin setup
const imagePlugin = createImagePlugin();
// Plugin with custom upload function
const imagePluginWithUpload = createImagePlugin({
options: {
uploadImage: async (dataUrl) => {
const formData = new FormData();
formData.append('image', dataUrl);
const response = await fetch('/api/upload', {
method: 'POST',
body: formData,
});
const result = await response.json();
return result.url;
}
}
});
// Plugin with disabled features
const restrictedImagePlugin = createImagePlugin({
options: {
disableUploadInsert: true,
disableEmbedInsert: false,
}
});The string constant used to identify image elements in the Plate editor.
/**
* Element type constant for image elements ('img')
* Used throughout the plugin system to identify image nodes
*/
const ELEMENT_IMAGE: string;Usage Examples:
import { ELEMENT_IMAGE, getPluginType } from "@udecode/plate-image";
import { getBlockAbove } from "@udecode/plate-core";
// Check if current selection is an image
const entry = getBlockAbove(editor, {
match: { type: getPluginType(editor, ELEMENT_IMAGE) },
});
// Use in plugin configuration
const customImagePlugin = {
key: ELEMENT_IMAGE,
isElement: true,
isVoid: true,
// ... other configuration
};The plugin accepts an ImagePlugin configuration object with the following optional properties:
interface ImagePlugin {
/**
* Custom image upload function
* Receives base64 dataUrl and should return uploaded image URL
*/
uploadImage?: (
dataUrl: string | ArrayBuffer
) => Promise<string | ArrayBuffer> | string | ArrayBuffer;
/**
* Disable automatic file upload on paste/drop
* Default: false
*/
disableUploadInsert?: boolean;
/**
* Disable automatic URL embedding
* Default: false
*/
disableEmbedInsert?: boolean;
}The image plugin provides several automatic behaviors when integrated:
<img> tags to image elements when pasting HTML contentThe plugin integrates seamlessly with Plate's plugin system:
import { createPlateEditor } from "@udecode/plate-core";
import { createImagePlugin } from "@udecode/plate-image";
const editor = createPlateEditor({
plugins: [
// Other plugins...
createImagePlugin({
options: {
uploadImage: async (dataUrl) => {
// Your upload logic here
return uploadedUrl;
}
}
}),
// More plugins...
]
});Install with Tessl CLI
npx tessl i tessl/npm-udecode--plate-image