Images Videos Audio Pricing Docs View as Markdown (Agent) Get started
Human Agent

Lexical image upload for paste and drag-drop

Upload files from Lexical's DRAG_DROP_PASTE command, insert a CDN-backed image node, and skip an upload backend. Use the complete plugin below or hand the ready-made prompt to your coding agent.

Works with Claude CodeCursorWindsurfCopilot
  1. 1
    Copy the prompt

    The one big button below.

  2. 2
    Paste it into your agent

    In your project — Claude Code, Cursor, etc.

  3. 3
    Drop in your key

    Swap pv_pub_REPLACE_ME for a free key. Done.

Prompt for your coding agent
Add image paste-and-host to my Lexical editor using PixelVault.

Context — read this first and use only the documented API:
- Overview + API: https://pixelvault.dev/llms.txt
- PixelVault upload helper (from @pixelvault-dev/paste):
    import { uploadImage } from "@pixelvault-dev/paste";
    const { url } = await uploadImage(file, { publishableKey: "pv_pub_REPLACE_ME" });
    // returns { id, url, mimeType, size }; throws PixelVaultPasteError on failure

Important: Lexical is a contenteditable editor, not a <textarea>, so do NOT use
the paste-react/usePaste widget here — use uploadImage() directly.

Do this:
1. Install: npm install @pixelvault-dev/paste

2. Make sure my editor has an image node registered. Lexical core ships NO
   built-in image node — if my editor doesn't already have one (e.g. the
   Lexical playground's ImageNode), STOP and tell me, because I need one before
   this can insert images.

3. Register a Lexical handler for pasted/dropped image files. The idiomatic hook
   is the DRAG_DROP_PASTE command from @lexical/rich-text:
     editor.registerCommand(DRAG_DROP_PASTE, (files) => { ...; return true; }, COMMAND_PRIORITY_LOW)
   which fires with the dropped/pasted File(s). For each image file: call
   uploadImage(file, { publishableKey }), and on success insert my image node
   with the returned url inside an editor.update() block. Don't await inside the
   command handler — kick off the async upload and return true. Show a fallback
   if the upload throws PixelVaultPasteError.

4. Use my publishable key where I wrote pv_pub_REPLACE_ME (I'll paste my own).

Rules:
- For the PixelVault part, use ONLY uploadImage(file, options) as documented above —
  do NOT invent PixelVault endpoints, options, or other packages.
- Use Lexical's own documented commands and my existing image node for the editor
  side; if I have no image node, STOP and tell me rather than inventing one.
- Don't block the editor on the upload; insert the node when the URL resolves.

What the agent will do

  • Install @pixelvault-dev/paste (core)
  • Register a DRAG_DROP_PASTE handler that uploads via uploadImage()
  • Insert the returned CDN URL as your Lexical image node
  • No backend changes — uploads go straight to PixelVault with your key

Grab your free key

The one thing the agent can't generate is your publishable key (pv_pub_…) — it's origin-scoped and upload-only, safe to ship in browser code. Create one, add your app's origin, and paste it in.

Get your free key →

Free tier: 200 MB storage, 500 uploads/mo, 1 GB bandwidth. No card.

Complete Lexical image upload plugin

This React plugin handles image files from Lexical's DRAG_DROP_PASTE command, uploads them without blocking the editor, and inserts each hosted URL. Lexical does not ship an image node, so register one first and update the ImageNode import to its location in your app.

import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import { DRAG_DROP_PASTE } from "@lexical/rich-text";
import { $insertNodes, COMMAND_PRIORITY_LOW } from "lexical";
import { useEffect } from "react";
import { PixelVaultPasteError, uploadImage } from "@pixelvault-dev/paste";
import { $createImageNode } from "./nodes/ImageNode";

type Props = {
  publishableKey: string;
  onError: (message: string) => void;
};

export function PixelVaultImageUploadPlugin({ publishableKey, onError }: Props) {
  const [editor] = useLexicalComposerContext();

  useEffect(
    () =>
      editor.registerCommand(
        DRAG_DROP_PASTE,
        (files) => {
          const images = files.filter((file) => file.type.startsWith("image/"));
          if (images.length === 0) return false;

          void (async () => {
            for (const file of images) {
              try {
                const { url } = await uploadImage(file, { publishableKey });
                editor.update(() => {
                  $insertNodes([$createImageNode({ src: url, altText: file.name })]);
                });
              } catch (error) {
                onError(
                  error instanceof PixelVaultPasteError
                    ? error.message
                    : "Image upload failed. Try again.",
                );
              }
            }
          })();

          return true;
        },
        COMMAND_PRIORITY_LOW,
      ),
    [editor, onError, publishableKey],
  );

  return null;
}

Render <PixelVaultImageUploadPlugin /> inside your LexicalComposer. Pass the publishable key from your browser-safe configuration and connect onError to your existing toast or inline error state.

Why Lexical needs an image node first

Lexical core deliberately ships without an image node. The upload handler can obtain a hosted URL, but it still needs your editor's node implementation to render that URL. The example uses the conventional $createImageNode({ src, altText }) API from the Lexical playground; keep your node registered in the composer configuration.

How the upload flow works

DRAG_DROP_PASTE supplies the pasted or dropped files. The handler keeps only image MIME types, starts the async upload, and returns true immediately so Lexical does not also process the files. Each successful upload is inserted inside editor.update(). PixelVault's publishable key is upload-only and origin-scoped, so this browser flow needs no API route.

Prefer your coding agent to make the change?

Copy the prompt above. It tells Claude Code, Cursor, Windsurf, or Copilot to find your existing image node, register the same command, and match the conventions already used by your editor. The paste-and-host docs cover the upload helper, and the Quill image upload guide covers Quill's equivalent insertEmbed flow.

FAQ

How do I add image upload to a Lexical editor?

Register DRAG_DROP_PASTE, upload each image with uploadImage(), and insert your existing image node with the returned URL inside editor.update(). The complete React plugin above implements that flow.

Does Lexical have a built-in image node?

No. Register your own image node, or adapt the Lexical playground's ImageNode, before adding the upload plugin.

Do I need an upload backend for Lexical image uploads?

No. uploadImage() uploads directly from the browser with an origin-scoped, upload-only publishable key.