UNPKG

@godfreykaris/tiptap-math-block

Version:

A TipTap extension + React NodeView for editable math blocks (MathQuill + KaTeX)

116 lines (109 loc) 3.17 kB
import React from 'react'; import { Node, Editor } from '@tiptap/core'; interface MathModalProps { isOpen: boolean; onClose: () => void; initialLatex: string; /** latex is kept with ⟦Mx⟧ placeholders; matrices carries the registry */ onSave: (payload: { latex: string; matrices: Record<string, MatrixRec$3>; }) => void; id: string; /** seed matrices when opening the modal */ initialMatrices?: Record<string, MatrixRec$3>; mode: "inline" | "block"; } type MatrixRec$3 = { id: string; label: string; rows: number; cols: number; cells: string[][]; }; declare const MathModal: React.FC<MathModalProps>; type MatrixRec$2 = { id: string; label: string; rows: number; cols: number; cells: string[][]; }; declare module '@tiptap/core' { interface Commands<ReturnType> { mathBlock: { addMathBlock: (attributes?: { latex?: string; id?: string; alignment?: 'left' | 'center' | 'right'; matrices?: Record<string, MatrixRec$2>; }) => ReturnType; setMathBlockAlignment: (alignment: 'left' | 'center' | 'right') => ReturnType; }; } } declare const MathExtension: Node<any, any>; type MatrixRec$1 = { id: string; label: string; rows: number; cols: number; cells: string[][]; }; declare module '@tiptap/core' { interface Commands<ReturnType> { mathInline: { addMathInline: (attributes?: { latex?: string; id?: string; matrices?: Record<string, MatrixRec$1>; }) => ReturnType; }; } } declare const MathInlineExtension: Node<any, any>; /** * Insert a math block on the "next line" after the current block, * regardless of current selection type (text, node, inside inline content, etc.). * Falls back gracefully at document boundaries. */ declare function addMathBlockOnNextLine(editor: Editor, initialLatex?: string, { ensureSpacerParagraph }?: { ensureSpacerParagraph?: boolean; }): boolean; /** * Insert inline math at the current cursor position. */ declare function addMathInlineAtSelection(editor: Editor, initialLatex?: string): boolean; type MatrixRec = { id: string; label: string; rows: number; cols: number; cells: string[][]; }; type OnSavePayload = { latex: string; matrices: Record<string, MatrixRec>; }; type BridgeState = { isOpen: boolean; latex: string; id: string; matrices: Record<string, MatrixRec>; onSave: (payload: OnSavePayload) => void; mode: 'inline' | 'block'; }; declare function useMathModalBridge(): { modalProps: { isOpen: boolean; onClose: () => void; initialLatex: string; initialMatrices: Record<string, MatrixRec>; onSave: (payload: OnSavePayload) => void; id: string; mode: "inline" | "block"; }; openState: BridgeState; close: () => void; }; export { MathExtension, MathInlineExtension, MathModal, addMathBlockOnNextLine, addMathInlineAtSelection, useMathModalBridge };