Typix LogoTypix
Extensions

Drag Drop Paste

Handle image drag-and-drop and paste operations

The Drag Drop Paste extension handles image files dragged, dropped, or pasted into the editor with validation, size limits, and custom upload support.

Demo

Loading preview...
import {  EditorContent,  EditorRoot,  createEditorConfig,  defaultExtensionNodes,} from "@typix-editor/react";import { DragDropPasteExtension } from "@typix-editor/extension-drag-drop-paste";import { theme } from "./theme";import "./style.css";const config = createEditorConfig({  extensionNodes: defaultExtensionNodes,  theme,});export default function DragDropPasteExample() {  return (    <EditorRoot config={config}>      <EditorContent placeholder="Try dragging or pasting an image..." />      <DragDropPasteExtension        acceptedTypes={["image/png", "image/jpeg"]}        maxFileSize={5 * 1024 * 1024}        onFilesAdded={async (files) => {          // Upload files to your server          const urls = await uploadFiles(files);          return urls.map((src) => ({ src }));        }}        onValidationError={(file, reason) => {          console.warn(reason);        }}      />    </EditorRoot>  );}

Installation

pnpm add @typix-editor/extension-drag-drop-paste
npm install @typix-editor/extension-drag-drop-paste
yarn add @typix-editor/extension-drag-drop-paste

Setup

import { DragDropPasteExtension } from '@typix-editor/extension-drag-drop-paste';

function MyEditor() {
  return (
    <EditorRoot>
      <EditorContent />
      <DragDropPasteExtension />
    </EditorRoot>
  );
}

With custom upload handler

<DragDropPasteExtension
  acceptedTypes={['image/png', 'image/jpeg']}
  maxFileSize={5 * 1024 * 1024}
  onFilesAdded={async (files) => {
    const urls = await uploadToS3(files);
    return urls.map(url => ({ src: url }));
  }}
  onValidationError={(file, reason) => {
    toast.error(reason);
  }}
/>

Props

PropTypeDefaultDescription
acceptedTypesstring[]Image MIME typesAccepted file MIME types
maxFileSizenumber10485760 (10MB)Maximum file size in bytes
priorityCommandListenerPriorityCOMMAND_PRIORITY_LOWLexical command priority
onFilesAdded(files: File[]) => Promise<InsertImagePayload[]>Custom upload handler
onValidationError(file: File, reason: string) => voidValidation error callback
transformResult(file: File, result: string) => InsertImagePayloadTransform before inserting
debugbooleanfalseEnable debug logging

Exports

ExportTypeDescription
DragDropPasteExtensionComponentThe drag/drop/paste plugin
DragDropPasteExtensionPropsTypeProps type

On this page