API / @aionbuilders/nabu/extend

PasteFileHandler

Type Stability: stable

What an extension does with a FILE pasted from the clipboard (a screenshot, a file copied from the OS): it makes a block of it. The engine reads the bytes, stores them through Files (in the document, or sent to files.onBeforePersist with the optimistic pending block) and inserts the blocks at the caret, in the order of the files, as ONE undo step. The engine names no block type: whatever an extension accepts is its own business.

Definition

TypeScript
import type { PasteFileHandler } from '@aionbuilders/nabu/extend';
TypeScript
interface PasteFileHandler {
  accepts: (file: File, nabu: Nabu) => boolean;
  block: (file: File, nabu: Nabu) => PasteBlock | null;
  priority?: number;
}

Properties

Properties of PasteFileHandler
PropertyTypeDescription
accepts(file: File, nabu: Nabu) => boolean

Whether this handler takes file (by MIME type, name…)

block(file: File, nabu: Nabu) => PasteBlock | null

The block the file becomes: type and the props other than ref (name, alt…), which the engine sets to the stored file. null declines the file.

priorityoptionalnumber

Higher is asked first (default 0). The first handler that accepts a file takes it.

Source: src/lib/utils/extensions.js:34