edix
Version:
An experimental, type-safe, framework agnostic and small (5kB+) contenteditable state manager.
44 lines (43 loc) • 2.12 kB
TypeScript
import type { Editor } from "./editor.js";
import type { DocNode, InferBlockNode, InferInlineNode, Path, Position, Range, TextNode } from "./doc/types.js";
export type EditorCommand<A extends unknown[], T extends DocNode> = (this: Editor<T>, ...args: A) => void;
/**
* Delete content in the selection or specified range.
*/
export declare function Delete(this: Editor, range?: Range): void;
/**
* Insert text at the caret or specified position.
*/
export declare function InsertText(this: Editor, text: string, position?: Position): void;
/**
* Insert node at the caret or specified position.
*/
export declare function InsertNode<T extends DocNode>(this: Editor<T>, node: Exclude<InferInlineNode<T>, TextNode>, position?: Position): void;
/**
* Replace text in the selection or specified range.
*/
export declare function ReplaceText(this: Editor, text: string): void;
/**
* Replace all content in the editor.
*/
export declare function ReplaceAll(this: Editor, text: string): void;
type ToggleableKey<T> = {
[K in keyof T]-?: T[K] extends boolean | undefined ? K : never;
}[keyof T];
/**
* Format content in the selection or specified range.
*/
export declare function Format<T extends DocNode, N extends Omit<InferInlineNode<T>, "text">, K extends Extract<keyof N, string>>(this: Editor<T>, key: K, value: N[K], range?: Range): void;
/**
* Toggle formatting in the selection or specified range.
*/
export declare function ToggleFormat<T extends DocNode>(this: Editor<T>, key: Extract<ToggleableKey<Omit<InferInlineNode<T>, "text">>, string>, range?: Range): void;
/**
* Set attr to a block node at the caret or specified position.
*/
export declare function SetBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends Extract<keyof N, string>>(this: Editor<T>, key: K, value: N[K], path?: Path): void;
/**
* Toggle attr of block node at the caret or specified position.
*/
export declare function ToggleBlockAttr<T extends DocNode, N extends InferBlockNode<T>, K extends Extract<keyof N, string>>(this: Editor<T>, key: K, onValue: N[K], offValue: N[K], path?: Path): void;
export {};