@godfreykaris/tiptap-math-block
Version:
A TipTap extension + React NodeView for editable math blocks (MathQuill + KaTeX)
89 lines (83 loc) • 2.44 kB
TypeScript
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$2>;
}) => void;
id: string;
/** seed matrices when opening the modal */
initialMatrices?: Record<string, MatrixRec$2>;
}
type MatrixRec$2 = {
id: string;
label: string;
rows: number;
cols: number;
cells: string[][];
};
declare const MathModal: React.FC<MathModalProps>;
type MatrixRec$1 = {
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$1>;
}) => ReturnType;
setMathBlockAlignment: (alignment: "left" | "center" | "right") => ReturnType;
};
}
}
declare const MathExtension: 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;
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;
};
declare function useMathModalBridge(): {
modalProps: {
isOpen: boolean;
onClose: () => void;
initialLatex: string;
initialMatrices: Record<string, MatrixRec>;
onSave: (payload: OnSavePayload) => void;
id: string;
};
openState: BridgeState;
close: () => void;
};
export { MathExtension, MathModal, addMathBlockOnNextLine as addMathBlockAfterSelection, useMathModalBridge };