UNPKG

edix

Version:

An experimental, type-safe, framework agnostic and small (5kB+) contenteditable state manager.

49 lines (48 loc) 1.58 kB
import type { Fragment, Position, Path, Node } from "./types.js"; declare const OP_DELETE = "delete"; type DeleteOperation = Readonly<{ type: typeof OP_DELETE; start: Position; end: Position; }>; declare const OP_INSERT_TEXT = "insert_text"; type InsertTextOperation = Readonly<{ type: typeof OP_INSERT_TEXT; at: Position; text: string; }>; declare const OP_INSERT_NODE = "insert_node"; type InsertNodeOperation = Readonly<{ type: typeof OP_INSERT_NODE; at: Position; fragment: Fragment; }>; declare const OP_SET_ATTR = "set_attr"; type SetAttrOperation = Readonly<{ type: typeof OP_SET_ATTR; start: Position; end: Position; key: string; value: unknown; }>; declare const OP_SET_NODE_ATTR = "set_node_attr"; type SetNodeAttrOperation = Readonly<{ type: typeof OP_SET_NODE_ATTR; path: Path; key: string; value: unknown; }>; export type Operation = DeleteOperation | InsertTextOperation | InsertNodeOperation | SetAttrOperation | SetNodeAttrOperation; export declare class Transaction { private readonly _ops; constructor(ops?: readonly Operation[]); get ops(): readonly Operation[]; insertText(at: Position, text: string): this; insertFragment(at: Position, fragment: Fragment): this; delete(start: Position, end: Position): this; format(start: Position, end: Position, key: string, value: unknown): this; attr(at: Path, key: string, value: unknown): this; transform(position: Position): Position; } export declare const getNodeSize: (node: Node) => number; export {};