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

Typix
Loading preview…
import {  createEditorConfig,  defaultExtensionNodes,  defaultTheme,  EditorContent,  EditorRoot,} from "@typix-editor/react";import { DragDropPasteExtension } from "@typix-editor/extension-drag-drop-paste";import { Toolbar } from "./Toolbar";const config = createEditorConfig({  extensionNodes: defaultExtensionNodes,  theme: defaultTheme,});export default function DragDropPasteExample() {  return (    <EditorRoot config={config}>      <div className="editor-container">        <Toolbar />        <EditorContent placeholder="Try dragging or pasting an image here..." />      </div>      <DragDropPasteExtension        acceptedTypes={["image/png", "image/jpeg"]}        maxFileSize={5 * 1024 * 1024}        onFilesAdded={async (files) => {          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