File Handler

Paste and drop files into the document as image nodes.

UIrich-text-editor-file-handlerView JSON

Files are inserted as image nodes, so install the image node too. The default reads the file into a data URL, which keeps the document self-contained; pass `onFile` to upload the file first and insert the returned URL instead.

Preview

Installation

Add the item with the shadcn CLI, or copy the source manually.

pnpm dlx shadcn@latest add litingyes/blocove/rich-text-editor-file-handler

Requires a shadcn/ui project set up with Base UI primitives. Blocove is developed against the b0 preset, but it installs no base config or theme tokens: your own preset, fonts and colors stay in place.

Or install from the namespace after adding the registry: npx shadcn@latest add @blocove/rich-text-editor-file-handler

Typography is provided by shadcn/typeset. Copy typeset.css next to your stylesheet, import it after Tailwind and add the .typeset-docs preset. See the Rich text editor setup.

Usage

Upload the file yourself
import { EditorFileHandler } from "@/components/blocove/rich-text-editor/file-handler"
async function upload(file: File) {  const body = new FormData()  body.append("file", file)  const response = await fetch("/api/upload", { method: "POST", body })  const { url } = await response.json()  return url}
export function UploadEditor() {  return (    <Editor>      <EditorFileHandler onFile={upload} />      <EditorContent />    </Editor>  )}

API Reference

Props accepted by the exported components.

EditorFileHandler

Registers the paste and drop handler for files.

PropTypeDefault
allowedMimeTypesstring[]PNG, JPEG, GIF and WebP
onFile(file: File) => Promise<string> | stringReads the file as a data URL