UNPKG

edix

Version:

An experimental, framework agnostic, small (~3kB) contenteditable state manager.

44 lines (43 loc) 1.16 kB
import { EditableCommand } from "./commands"; import { EditableSchema } from "./schema"; /** * Options of {@link editable}. */ export interface EditableOptions<T> { /** * TODO */ schema: EditableSchema<T>; /** * TODO */ isBlock?: (node: HTMLElement) => boolean; /** * TODO */ onChange: (value: T) => void; } /** * Methods of editor instance. */ export interface EditableHandle { /** * Disposes editor and restores previous DOM state. */ dispose: () => void; /** * Dispatches editing command. * @param fn command function * @param args arguments of command */ command: <A extends unknown[]>(fn: EditableCommand<A>, ...args: A) => void; /** * Changes editor's read-only state. * @param value `true` to read-only. `false` to editable. */ readonly: (value: boolean) => void; } /** * A function to make DOM editable. */ export declare const editable: <T>(element: HTMLElement, { schema: { single: isSingleline, js: docToJS, void: serializeVoid, copy, paste: getPastableData, }, isBlock, onChange, }: EditableOptions<T>) => EditableHandle;