Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: add math commands & tools

thecodrra0af81e39de9
diff --git a/packages/editor/dist/extensions/math/mathblock.d.ts b/packages/editor/dist/extensions/math/mathblock.d.ts
index 419bb7458..5c266e9e8 100644
--- a/packages/editor/dist/extensions/math/mathblock.d.ts
+++ b/packages/editor/dist/extensions/math/mathblock.d.ts
@@ -1,2 +1,9 @@
import { Node } from "@tiptap/core";
+declare module "@tiptap/core" {
+ interface Commands<ReturnType> {
+ mathBlock: {
+ insertMathBlock: () => ReturnType;
+ };
+ }
+}
export declare const MathBlock: Node<any, any>;
diff --git a/packages/editor/dist/extensions/math/mathblock.js b/packages/editor/dist/extensions/math/mathblock.js
index af36cedd1..42ebb0312 100644
--- a/packages/editor/dist/extensions/math/mathblock.js
+++ b/packages/editor/dist/extensions/math/mathblock.js
@@ -1,8 +1,8 @@
import { Node, mergeAttributes } from "@tiptap/core";
import { inputRules } from "prosemirror-inputrules";
-import { makeBlockMathInputRule, REGEX_BLOCK_MATH_DOLLARS, } from "./plugin";
+import { insertMathNode, makeBlockMathInputRule, REGEX_BLOCK_MATH_DOLLARS, } from "./plugin";
export var MathBlock = Node.create({
- name: "math_display",
+ name: "mathBlock",
group: "block math",
content: "text*",
atom: true,
@@ -22,6 +22,17 @@ export var MathBlock = Node.create({
0,
];
},
+ addCommands: function () {
+ var _this = this;
+ return {
+ insertMathBlock: function () {
+ return function (_a) {
+ var state = _a.state, dispatch = _a.dispatch, view = _a.view;
+ return insertMathNode(_this.type)(state, dispatch, view);
+ };
+ },
+ };
+ },
addProseMirrorPlugins: function () {
var inputRulePlugin = inputRules({
rules: [makeBlockMathInputRule(REGEX_BLOCK_MATH_DOLLARS, this.type)],
diff --git a/packages/editor/dist/extensions/math/mathinline.d.ts b/packages/editor/dist/extensions/math/mathinline.d.ts
index 515259f03..56a7ec49f 100644
--- a/packages/editor/dist/extensions/math/mathinline.d.ts
+++ b/packages/editor/dist/extensions/math/mathinline.d.ts
@@ -1,2 +1,9 @@
import { Node } from "@tiptap/core";
+declare module "@tiptap/core" {
+ interface Commands<ReturnType> {
+ mathInline: {
+ insertMathInline: () => ReturnType;
+ };
+ }
+}
export declare const MathInline: Node<any, any>;
diff --git a/packages/editor/dist/extensions/math/mathinline.js b/packages/editor/dist/extensions/math/mathinline.js
index bad67778c..763a53e53 100644
--- a/packages/editor/dist/extensions/math/mathinline.js
+++ b/packages/editor/dist/extensions/math/mathinline.js
@@ -1,8 +1,8 @@
import { Node, mergeAttributes } from "@tiptap/core";
import { inputRules } from "prosemirror-inputrules";
-import { makeInlineMathInputRule, REGEX_INLINE_MATH_DOLLARS, mathPlugin, } from "./plugin";
+import { makeInlineMathInputRule, REGEX_INLINE_MATH_DOLLARS, mathPlugin, insertMathNode, } from "./plugin";
export var MathInline = Node.create({
- name: "math_inline",
+ name: "mathInline",
group: "inline math",
content: "text*",
inline: true,
@@ -23,6 +23,17 @@ export var MathInline = Node.create({
0,
];
},
+ addCommands: function () {
+ var _this = this;
+ return {
+ insertMathInline: function () {
+ return function (_a) {
+ var state = _a.state, dispatch = _a.dispatch, view = _a.view;
+ return insertMathNode(_this.type)(state, dispatch, view);
+ };
+ },
+ };
+ },
addProseMirrorPlugins: function () {
var inputRulePlugin = inputRules({
rules: [makeInlineMathInputRule(REGEX_INLINE_MATH_DOLLARS, this.type)],
diff --git a/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.d.ts b/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.d.ts
index c315ac00a..a3210bd68 100644
--- a/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.d.ts
+++ b/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.d.ts
@@ -13,4 +13,4 @@ import { EditorView } from "prosemirror-view";
* (inner) selection is empty.
* @returns A new ProseMirror command based on the input configuration.
*/
-export declare function collapseMathCmd(outerView: EditorView, dir: 1 | -1, requireOnBorder: boolean, requireEmptySelection?: boolean): Command;
+export declare function collapseMathNode(outerView: EditorView, dir: 1 | -1, requireOnBorder: boolean, requireEmptySelection?: boolean): Command;
diff --git a/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.js b/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.js
index 617ed9838..70502e16b 100644
--- a/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.js
+++ b/packages/editor/dist/extensions/math/plugin/commands/collapse-math-cmd.js
@@ -12,7 +12,7 @@ import { TextSelection } from "prosemirror-state";
* (inner) selection is empty.
* @returns A new ProseMirror command based on the input configuration.
*/
-export function collapseMathCmd(outerView, dir, requireOnBorder, requireEmptySelection) {
+export function collapseMathNode(outerView, dir, requireOnBorder, requireEmptySelection) {
if (requireEmptySelection === void 0) { requireEmptySelection = true; }
// create a new ProseMirror command based on the input conditions
return function (innerState, dispatch) {
diff --git a/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.d.ts b/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.d.ts
new file mode 100644
index 000000000..a3210bd68
--- /dev/null
+++ b/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.d.ts
@@ -0,0 +1,16 @@
+import { Command } from "prosemirror-state";
+import { EditorView } from "prosemirror-view";
+/**
+ * A ProseMirror command for determining whether to exit a math block, based on
+ * specific conditions. Normally called when the user has
+ *
+ * @param outerView The main ProseMirror EditorView containing this math node.
+ * @param dir Used to indicate desired cursor position upon closing a math node.
+ * When set to -1, cursor will be placed BEFORE the math node.
+ * When set to +1, cursor will be placed AFTER the math node.
+ * @param borderMode An exit condition based on cursor position and direction.
+ * @param requireEmptySelection When TRUE, only exit the math node when the
+ * (inner) selection is empty.
+ * @returns A new ProseMirror command based on the input configuration.
+ */
+export declare function collapseMathNode(outerView: EditorView, dir: 1 | -1, requireOnBorder: boolean, requireEmptySelection?: boolean): Command;
diff --git a/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.js b/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.js
new file mode 100644
index 000000000..70502e16b
--- /dev/null
+++ b/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.js
@@ -0,0 +1,51 @@
+import { TextSelection } from "prosemirror-state";
+/**
+ * A ProseMirror command for determining whether to exit a math block, based on
+ * specific conditions. Normally called when the user has
+ *
+ * @param outerView The main ProseMirror EditorView containing this math node.
+ * @param dir Used to indicate desired cursor position upon closing a math node.
+ * When set to -1, cursor will be placed BEFORE the math node.
+ * When set to +1, cursor will be placed AFTER the math node.
+ * @param borderMode An exit condition based on cursor position and direction.
+ * @param requireEmptySelection When TRUE, only exit the math node when the
+ * (inner) selection is empty.
+ * @returns A new ProseMirror command based on the input configuration.
+ */
+export function collapseMathNode(outerView, dir, requireOnBorder, requireEmptySelection) {
+ if (requireEmptySelection === void 0) { requireEmptySelection = true; }
+ // create a new ProseMirror command based on the input conditions
+ return function (innerState, dispatch) {
+ // get selection info
+ var outerState = outerView.state;
+ var _a = outerState.selection, outerTo = _a.to, outerFrom = _a.from;
+ var _b = innerState.selection, innerTo = _b.to, innerFrom = _b.from;
+ // only exit math node when selection is empty
+ if (requireEmptySelection && innerTo !== innerFrom) {
+ return false;
+ }
+ var currentPos = dir > 0 ? innerTo : innerFrom;
+ // when requireOnBorder is TRUE, collapse only when cursor
+ // is about to leave the bounds of the math node
+ if (requireOnBorder) {
+ // (subtract two from nodeSize to account for start and end tokens)
+ var nodeSize = innerState.doc.nodeSize - 2;
+ // early return if exit conditions not met
+ if (dir > 0 && currentPos < nodeSize) {
+ return false;
+ }
+ if (dir < 0 && currentPos > 0) {
+ return false;
+ }
+ }
+ // all exit conditions met, so close the math node by moving the cursor outside
+ if (dispatch) {
+ // set outer selection to be outside of the nodeview
+ var targetPos = dir > 0 ? outerTo : outerFrom;
+ outerView.dispatch(outerState.tr.setSelection(TextSelection.create(outerState.doc, targetPos)));
+ // must return focus to the outer view, otherwise no cursor will appear
+ outerView.focus();
+ }
+ return true;
+ };
+}
diff --git a/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.d.ts b/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.d.ts
index 52e3b7a12..4d8ba65ba 100644
--- a/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.d.ts
+++ b/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.d.ts
@@ -9,4 +9,4 @@ import { NodeType } from "prosemirror-model";
* NodeType. Must belong to the same schema that your EditorState uses!
* @param initialText (optional) The initial source content for the math editor.
*/
-export declare function insertMathCmd(mathNodeType: NodeType, initialText?: string): Command;
+export declare function insertMathNode(mathNodeType: NodeType, initialText?: string): Command;
diff --git a/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.js b/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.js
index ce7bfcf35..554814a3a 100644
--- a/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.js
+++ b/packages/editor/dist/extensions/math/plugin/commands/insert-math-cmd.js
@@ -9,7 +9,7 @@ import { NodeSelection } from "prosemirror-state";
* NodeType. Must belong to the same schema that your EditorState uses!
* @param initialText (optional) The initial source content for the math editor.
*/
-export function insertMathCmd(mathNodeType, initialText) {
+export function insertMathNode(mathNodeType, initialText) {
if (initialText === void 0) { initialText = ""; }
return function (state, dispatch) {
var $from = state.selection.$from, index = $from.index();
diff --git a/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.d.ts b/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.d.ts
new file mode 100644
index 000000000..4d8ba65ba
--- /dev/null
+++ b/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.d.ts
@@ -0,0 +1,12 @@
+import { Command } from "prosemirror-state";
+import { NodeType } from "prosemirror-model";
+/**
+ * Returns a new command that can be used to inserts a new math node at the
+ * user's current document position, provided that the document schema actually
+ * allows a math node to be placed there.
+ *
+ * @param mathNodeType An instance for either your math_inline or math_display
+ * NodeType. Must belong to the same schema that your EditorState uses!
+ * @param initialText (optional) The initial source content for the math editor.
+ */
+export declare function insertMathNode(mathNodeType: NodeType, initialText?: string): Command;
diff --git a/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.js b/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.js
new file mode 100644
index 000000000..554814a3a
--- /dev/null
+++ b/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.js
@@ -0,0 +1,27 @@
+import { NodeSelection } from "prosemirror-state";
+////////////////////////////////////////////////////////////////////////////////
+/**
+ * Returns a new command that can be used to inserts a new math node at the
+ * user's current document position, provided that the document schema actually
+ * allows a math node to be placed there.
+ *
+ * @param mathNodeType An instance for either your math_inline or math_display
+ * NodeType. Must belong to the same schema that your EditorState uses!
+ * @param initialText (optional) The initial source content for the math editor.
+ */
+export function insertMathNode(mathNodeType, initialText) {
+ if (initialText === void 0) { initialText = ""; }
+ return function (state, dispatch) {
+ var $from = state.selection.$from, index = $from.index();
+ if (!$from.parent.canReplaceWith(index, index, mathNodeType)) {
+ return false;
+ }
+ if (dispatch) {
+ var mathNode = mathNodeType.create({}, initialText ? state.schema.text(initialText) : null);
+ var tr = state.tr.replaceSelectionWith(mathNode);
+ tr = tr.setSelection(NodeSelection.create(tr.doc, $from.pos));
+ dispatch(tr);
+ }
+ return true;
+ };
+}
diff --git a/packages/editor/dist/extensions/math/plugin/index.d.ts b/packages/editor/dist/extensions/math/plugin/index.d.ts
index aac183ae8..13e02011b 100644
--- a/packages/editor/dist/extensions/math/plugin/index.d.ts
+++ b/packages/editor/dist/extensions/math/plugin/index.d.ts
@@ -4,6 +4,6 @@ export { mathSchemaSpec, createMathSchema } from "./math-schema";
export { mathBackspaceCmd } from "./plugins/math-backspace";
export { makeBlockMathInputRule, makeInlineMathInputRule, REGEX_BLOCK_MATH_DOLLARS, REGEX_INLINE_MATH_DOLLARS, REGEX_INLINE_MATH_DOLLARS_ESCAPED, } from "./plugins/math-input-rules";
export { mathSelectPlugin } from "./plugins/math-select";
-export { insertMathCmd } from "./commands/insert-math-cmd";
+export { insertMathNode } from "./commands/insert-math-node";
export { mathSerializer } from "./utils/text-serializer";
export * from "./utils/types";
diff --git a/packages/editor/dist/extensions/math/plugin/index.js b/packages/editor/dist/extensions/math/plugin/index.js
index 5433d8045..bb3ad0ec5 100644
--- a/packages/editor/dist/extensions/math/plugin/index.js
+++ b/packages/editor/dist/extensions/math/plugin/index.js
@@ -12,7 +12,7 @@ export { makeBlockMathInputRule, makeInlineMathInputRule, REGEX_BLOCK_MATH_DOLLA
// optional / experimental plugins
export { mathSelectPlugin } from "./plugins/math-select";
// commands
-export { insertMathCmd } from "./commands/insert-math-cmd";
+export { insertMathNode } from "./commands/insert-math-node";
// utilities
export { mathSerializer } from "./utils/text-serializer";
export * from "./utils/types";
diff --git a/packages/editor/dist/extensions/math/plugin/math-nodeview.d.ts b/packages/editor/dist/extensions/math/plugin/math-nodeview.d.ts
index b11bb5d34..9d1e9ae52 100644
--- a/packages/editor/dist/extensions/math/plugin/math-nodeview.d.ts
+++ b/packages/editor/dist/extensions/math/plugin/math-nodeview.d.ts
@@ -15,7 +15,7 @@ interface IMathViewOptions {
/** Used to render the Tex input */
renderer: MathRenderFn;
/** Should be true if node is inline */
- inline?: boolean;
+ className?: string;
}
export declare class MathView implements NodeView, ICursorPosObserver {
private _node;
diff --git a/packages/editor/dist/extensions/math/plugin/math-nodeview.js b/packages/editor/dist/extensions/math/plugin/math-nodeview.js
index 43e424707..0160fbfa0 100644
--- a/packages/editor/dist/extensions/math/plugin/math-nodeview.js
+++ b/packages/editor/dist/extensions/math/plugin/math-nodeview.js
@@ -7,7 +7,7 @@ import { EditorView, } from "prosemirror-view";
import { StepMap } from "prosemirror-transform";
import { keymap } from "prosemirror-keymap";
import { newlineInCode, chainCommands, deleteSelection, } from "prosemirror-commands";
-import { collapseMathCmd } from "./commands/collapse-math-cmd";
+import { collapseMathNode } from "./commands/collapse-math-node";
var MathView = /** @class */ (function () {
// == Lifecycle ===================================== //
/**
@@ -34,10 +34,8 @@ var MathView = /** @class */ (function () {
this._tagName = options.tagName || this._node.type.name.replace("_", "-");
// create dom representation of nodeview
this.dom = document.createElement(this._tagName);
- if (options.inline)
- this.dom.classList.add("math-inline");
- else
- this.dom.classList.add("math-display");
+ if (options.className)
+ this.dom.classList.add(options.className);
this.dom.classList.add("math-node");
this._mathRenderElt = document.createElement("span");
this._mathRenderElt.textContent = "";
@@ -235,12 +233,12 @@ var MathView = /** @class */ (function () {
// this._outerView.focus();
// return true;
// },
- Enter: chainCommands(newlineInCode, collapseMathCmd(this._outerView, +1, false)),
- "Ctrl-Enter": collapseMathCmd(this._outerView, +1, false),
- ArrowLeft: collapseMathCmd(this._outerView, -1, true),
- ArrowRight: collapseMathCmd(this._outerView, +1, true),
- ArrowUp: collapseMathCmd(this._outerView, -1, true),
- ArrowDown: collapseMathCmd(this._outerView, +1, true),
+ Enter: chainCommands(newlineInCode, collapseMathNode(this._outerView, +1, false)),
+ "Ctrl-Enter": collapseMathNode(this._outerView, +1, false),
+ ArrowLeft: collapseMathNode(this._outerView, -1, true),
+ ArrowRight: collapseMathNode(this._outerView, +1, true),
+ ArrowUp: collapseMathNode(this._outerView, -1, true),
+ ArrowDown: collapseMathNode(this._outerView, +1, true),
}),
],
}),
diff --git a/packages/editor/dist/extensions/math/plugin/math-plugin.js b/packages/editor/dist/extensions/math/plugin/math-plugin.js
index f5d52a27e..0cee5e45e 100644
--- a/packages/editor/dist/extensions/math/plugin/math-plugin.js
+++ b/packages/editor/dist/extensions/math/plugin/math-plugin.js
@@ -25,7 +25,7 @@ export function createMathView(inline) {
var nodeViews = pluginState.activeNodeViews;
// set up NodeView
var nodeView = new MathView(node, view, getPos, {
- inline: inline,
+ className: inline ? "math-inline" : "math-block",
renderer: inline ? KatexRenderer.inline : KatexRenderer.block,
tagName: inline ? "span" : "div",
}, MATH_PLUGIN_KEY, function () {
@@ -63,8 +63,8 @@ var mathPluginSpec = {
},
props: {
nodeViews: {
- math_inline: createMathView(true),
- math_display: createMathView(false),
+ mathInline: createMathView(true),
+ mathBlock: createMathView(false),
},
},
};
diff --git a/packages/editor/dist/toolbar/components/toolbutton.d.ts b/packages/editor/dist/toolbar/components/toolbutton.d.ts
index 74e32eb1e..2cde85f8c 100644
--- a/packages/editor/dist/toolbar/components/toolbutton.d.ts
+++ b/packages/editor/dist/toolbar/components/toolbutton.d.ts
@@ -14,8 +14,8 @@ export declare type ToolButtonProps = ButtonProps & {
};
export declare const ToolButton: React.NamedExoticComponent<ButtonProps & {
icon: IconNames;
- iconColor?: "background" | "border" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "icon" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "hover" | "fontSecondary" | "fontTertiary" | "overlay" | "secondary" | undefined;
- iconSize?: number | "big" | "small" | "medium" | undefined;
+ iconColor?: "background" | "border" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "icon" | "overlay" | "hover" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "fontSecondary" | "fontTertiary" | "secondary" | undefined;
+ iconSize?: number | "small" | "big" | "medium" | undefined;
toggled: boolean;
buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined> | undefined;
variant?: ToolButtonVariant | undefined;
diff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/toolbar/icons.d.ts
index 934932c6b..f590b325e 100644
--- a/packages/editor/dist/toolbar/icons.d.ts
+++ b/packages/editor/dist/toolbar/icons.d.ts
@@ -74,6 +74,8 @@ export declare const Icons: {
embedSettings: string;
palette: string;
tableSettings: string;
+ math: string;
+ mathBlock: string;
plus: string;
minus: string;
close: string;
diff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/toolbar/icons.js
index 6a8332195..b90ad6744 100644
--- a/packages/editor/dist/toolbar/icons.js
+++ b/packages/editor/dist/toolbar/icons.js
@@ -1,4 +1,4 @@
-import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusAfter, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiFormatColorFill, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTableMergeCells, mdiTableSplitCell, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, mdiChevronRight, mdiTableColumnWidth, mdiTableRowHeight, mdiMinus, mdiPaletteOutline, mdiCircle, mdiChevronLeft, mdiTableCog, mdiTableOff, mdiRectangle, mdiImageEditOutline, mdiArrowLeft, mdiMovieCogOutline, mdiLinkOff, mdiOpenInNew, mdiCameraOutline, } from "@mdi/js";
+import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusAfter, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiFormatColorFill, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTableMergeCells, mdiTableSplitCell, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, mdiChevronRight, mdiTableColumnWidth, mdiTableRowHeight, mdiMinus, mdiPaletteOutline, mdiCircle, mdiChevronLeft, mdiTableCog, mdiTableOff, mdiRectangle, mdiImageEditOutline, mdiArrowLeft, mdiMovieCogOutline, mdiLinkOff, mdiOpenInNew, mdiCameraOutline, mdiMathIntegral, mdiFunctionVariant, } from "@mdi/js";
export var Icons = {
bold: mdiFormatBold,
italic: mdiFormatItalic,
@@ -75,6 +75,8 @@ export var Icons = {
embedSettings: mdiMovieCogOutline,
palette: mdiPaletteOutline,
tableSettings: mdiTableCog,
+ math: mdiFunctionVariant,
+ mathBlock: mdiMathIntegral,
plus: mdiPlus,
minus: mdiMinus,
close: mdiClose,
diff --git a/packages/editor/dist/toolbar/tooldefinitions.d.ts b/packages/editor/dist/toolbar/tooldefinitions.d.ts
index 090996161..71e62199d 100644
--- a/packages/editor/dist/toolbar/tooldefinitions.d.ts
+++ b/packages/editor/dist/toolbar/tooldefinitions.d.ts
@@ -1,4 +1,5 @@
import { ToolbarDefinition, ToolDefinition } from "./types";
import { ToolId } from "./tools";
export declare function getToolDefinition(id: ToolId): ToolDefinition;
+export declare function getAllTools(): Record<"bold" | "italic" | "underline" | "strikethrough" | "code" | "codeRemove" | "subscript" | "superscript" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "linkSettings" | "openLink" | "insertBlock" | "numberedList" | "bulletList" | "fontSize" | "fontFamily" | "headings" | "alignCenter" | "alignRight" | "alignLeft" | "alignJustify" | "ltr" | "rtl" | "textColor" | "highlight" | "math" | "imageSettings" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "embedSettings" | "attachmentSettings" | "downloadAttachment" | "removeAttachment" | "tableSettings" | "columnProperties" | "rowProperties" | "cellProperties" | "insertColumnLeft" | "insertColumnRight" | "moveColumnLeft" | "moveColumnRight" | "deleteColumn" | "splitCells" | "mergeCells" | "cellBackgroundColor" | "cellBorderColor" | "cellTextColor" | "cellBorderWidth" | "insertRowAbove" | "insertRowBelow" | "moveRowUp" | "moveRowDown" | "deleteRow" | "deleteTable", ToolDefinition>;
export declare const DEFAULT_TOOLS: ToolbarDefinition;
diff --git a/packages/editor/dist/toolbar/tooldefinitions.js b/packages/editor/dist/toolbar/tooldefinitions.js
index 2f013afad..409281f81 100644
--- a/packages/editor/dist/toolbar/tooldefinitions.js
+++ b/packages/editor/dist/toolbar/tooldefinitions.js
@@ -116,6 +116,10 @@ var tools = {
icon: "textColor",
title: "Text color",
},
+ math: {
+ icon: "math",
+ title: "Math (inline)",
+ },
tableSettings: {
icon: "tableSettings",
title: "Table settings",
@@ -290,6 +294,9 @@ var tools = {
export function getToolDefinition(id) {
return tools[id];
}
+export function getAllTools() {
+ return tools;
+}
export var DEFAULT_TOOLS = [
[
"insertBlock",
@@ -311,6 +318,7 @@ export var DEFAULT_TOOLS = [
"superscript",
"highlight",
"textColor",
+ "math",
],
],
["fontSize"],
diff --git a/packages/editor/dist/toolbar/tools/block.js b/packages/editor/dist/toolbar/tools/block.js
index 04fa65cd6..2ec74796d 100644
--- a/packages/editor/dist/toolbar/tools/block.js
+++ b/packages/editor/dist/toolbar/tools/block.js
@@ -47,6 +47,7 @@ export function InsertBlock(props) {
tasklist(editor),
horizontalRule(editor),
codeblock(editor),
+ mathblock(editor),
blockquote(editor),
image(editor, isMobile),
attachment(editor),
@@ -96,6 +97,14 @@ var blockquote = function (editor) { return ({
isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("blockQuote"),
onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBlockquote().run(); },
}); };
+var mathblock = function (editor) { return ({
+ key: "math",
+ type: "button",
+ title: "Math & formulas",
+ icon: "mathBlock",
+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("mathBlock"),
+ onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathBlock().run(); },
+}); };
var image = function (editor, isMobile) { return ({
key: "image",
type: "button",
diff --git a/packages/editor/dist/toolbar/tools/index.d.ts b/packages/editor/dist/toolbar/tools/index.d.ts
index 598ca9b2d..df50761f4 100644
--- a/packages/editor/dist/toolbar/tools/index.d.ts
+++ b/packages/editor/dist/toolbar/tools/index.d.ts
@@ -1,6 +1,6 @@
import React from "react";
import { ToolProps } from "../types";
-import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove } from "./inline";
+import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math } from "./inline";
import { InsertBlock } from "./block";
import { FontSize, FontFamily } from "./font";
import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";
@@ -43,6 +43,7 @@ declare const tools: {
rtl: typeof RightToLeft;
textColor: typeof TextColor;
highlight: typeof Highlight;
+ math: typeof Math;
imageSettings: typeof ImageSettings;
imageAlignCenter: typeof ImageAlignCenter;
imageAlignLeft: typeof ImageAlignLeft;
diff --git a/packages/editor/dist/toolbar/tools/index.js b/packages/editor/dist/toolbar/tools/index.js
index bcb64f5dd..401f877aa 100644
--- a/packages/editor/dist/toolbar/tools/index.js
+++ b/packages/editor/dist/toolbar/tools/index.js
@@ -1,4 +1,4 @@
-import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, } from "./inline";
+import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math, } from "./inline";
import { InsertBlock } from "./block";
import { FontSize, FontFamily } from "./font";
import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";
@@ -40,6 +40,7 @@ var tools = {
rtl: RightToLeft,
textColor: TextColor,
highlight: Highlight,
+ math: Math,
imageSettings: ImageSettings,
imageAlignCenter: ImageAlignCenter,
imageAlignLeft: ImageAlignLeft,
diff --git a/packages/editor/dist/toolbar/tools/inline.d.ts b/packages/editor/dist/toolbar/tools/inline.d.ts
index 50238429c..f8a5deb2c 100644
--- a/packages/editor/dist/toolbar/tools/inline.d.ts
+++ b/packages/editor/dist/toolbar/tools/inline.d.ts
@@ -9,3 +9,4 @@ export declare function Subscript(props: ToolProps): JSX.Element;
export declare function Superscript(props: ToolProps): JSX.Element;
export declare function ClearFormatting(props: ToolProps): JSX.Element;
export declare function CodeRemove(props: ToolProps): JSX.Element | null;
+export declare function Math(props: ToolProps): JSX.Element;
diff --git a/packages/editor/dist/toolbar/tools/inline.js b/packages/editor/dist/toolbar/tools/inline.js
index e1a71f437..41a61da83 100644
--- a/packages/editor/dist/toolbar/tools/inline.js
+++ b/packages/editor/dist/toolbar/tools/inline.js
@@ -54,3 +54,7 @@ export function CodeRemove(props) {
return null;
return (_jsx(ToolButton, __assign({}, props, { toggled: false, onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().unsetMark("code").run(); } })));
}
+export function Math(props) {
+ var editor = props.editor;
+ return (_jsx(ToolButton, __assign({}, props, { toggled: false, onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathInline().run(); } })));
+}
diff --git a/packages/editor/src/extensions/math/math-block.ts b/packages/editor/src/extensions/math/math-block.ts
index fac66712a..288a03d28 100644
--- a/packages/editor/src/extensions/math/math-block.ts
+++ b/packages/editor/src/extensions/math/math-block.ts
@@ -1,13 +1,21 @@
import { Node, mergeAttributes } from "@tiptap/core";
import { inputRules } from "prosemirror-inputrules";
import {
- mathPlugin,
+ insertMathNode,
makeBlockMathInputRule,
REGEX_BLOCK_MATH_DOLLARS,
} from "./plugin";
+declare module "@tiptap/core" {
+ interface Commands<ReturnType> {
+ mathBlock: {
+ insertMathBlock: () => ReturnType;
+ };
+ }
+}
+
export const MathBlock = Node.create({
- name: "math_display",
+ name: "mathBlock",
group: "block math",
content: "text*", // important!
atom: true, // important!
@@ -29,6 +37,16 @@ export const MathBlock = Node.create({
];
},
+ addCommands() {
+ return {
+ insertMathBlock:
+ () =>
+ ({ state, dispatch, view }) => {
+ return insertMathNode(this.type)(state, dispatch, view);
+ },
+ };
+ },
+
addProseMirrorPlugins() {
const inputRulePlugin = inputRules({
rules: [makeBlockMathInputRule(REGEX_BLOCK_MATH_DOLLARS, this.type)],
diff --git a/packages/editor/src/extensions/math/math-inline.ts b/packages/editor/src/extensions/math/math-inline.ts
index dd9936839..1349fc728 100644
--- a/packages/editor/src/extensions/math/math-inline.ts
+++ b/packages/editor/src/extensions/math/math-inline.ts
@@ -4,10 +4,19 @@ import {
makeInlineMathInputRule,
REGEX_INLINE_MATH_DOLLARS,
mathPlugin,
+ insertMathNode,
} from "./plugin";
+declare module "@tiptap/core" {
+ interface Commands<ReturnType> {
+ mathInline: {
+ insertMathInline: () => ReturnType;
+ };
+ }
+}
+
export const MathInline = Node.create({
- name: "math_inline",
+ name: "mathInline",
group: "inline math",
content: "text*", // important!
inline: true, // important!
@@ -30,6 +39,16 @@ export const MathInline = Node.create({
];
},
+ addCommands() {
+ return {
+ insertMathInline:
+ () =>
+ ({ state, dispatch, view }) => {
+ return insertMathNode(this.type)(state, dispatch, view);
+ },
+ };
+ },
+
addProseMirrorPlugins() {
const inputRulePlugin = inputRules({
rules: [makeInlineMathInputRule(REGEX_INLINE_MATH_DOLLARS, this.type)],
diff --git a/packages/editor/src/extensions/math/plugin/commands/collapse-math-cmd.ts b/packages/editor/src/extensions/math/plugin/commands/collapse-math-node.ts
similarity index 98%
rename from packages/editor/src/extensions/math/plugin/commands/collapse-math-cmd.ts
rename to packages/editor/src/extensions/math/plugin/commands/collapse-math-node.ts
index c2fd675a0..13af4f9be 100644
--- a/packages/editor/src/extensions/math/plugin/commands/collapse-math-cmd.ts
+++ b/packages/editor/src/extensions/math/plugin/commands/collapse-math-node.ts
@@ -15,7 +15,7 @@ import { EditorView } from "prosemirror-view";
* (inner) selection is empty.
* @returns A new ProseMirror command based on the input configuration.
*/
-export function collapseMathCmd(
+export function collapseMathNode(
outerView: EditorView,
dir: 1 | -1,
requireOnBorder: boolean,
diff --git a/packages/editor/src/extensions/math/plugin/commands/insert-math-cmd.ts b/packages/editor/src/extensions/math/plugin/commands/insert-math-node.ts
similarity index 97%
rename from packages/editor/src/extensions/math/plugin/commands/insert-math-cmd.ts
rename to packages/editor/src/extensions/math/plugin/commands/insert-math-node.ts
index 88be960b6..f7fd383e1 100644
--- a/packages/editor/src/extensions/math/plugin/commands/insert-math-cmd.ts
+++ b/packages/editor/src/extensions/math/plugin/commands/insert-math-node.ts
@@ -13,7 +13,7 @@ import { EditorState, NodeSelection, Transaction } from "prosemirror-state";
* NodeType. Must belong to the same schema that your EditorState uses!
* @param initialText (optional) The initial source content for the math editor.
*/
-export function insertMathCmd(
+export function insertMathNode(
mathNodeType: NodeType,
initialText = ""
): Command {
diff --git a/packages/editor/src/extensions/math/plugin/index.ts b/packages/editor/src/extensions/math/plugin/index.ts
index 3a1a38b66..89bfb9054 100644
--- a/packages/editor/src/extensions/math/plugin/index.ts
+++ b/packages/editor/src/extensions/math/plugin/index.ts
@@ -26,7 +26,7 @@ export {
export { mathSelectPlugin } from "./plugins/math-select";
// commands
-export { insertMathCmd } from "./commands/insert-math-cmd";
+export { insertMathNode } from "./commands/insert-math-node";
// utilities
export { mathSerializer } from "./utils/text-serializer";
diff --git a/packages/editor/src/extensions/math/plugin/math-node-view.ts b/packages/editor/src/extensions/math/plugin/math-node-view.ts
index 29d787dc7..dd91d4fea 100644
--- a/packages/editor/src/extensions/math/plugin/math-node-view.ts
+++ b/packages/editor/src/extensions/math/plugin/math-node-view.ts
@@ -25,7 +25,7 @@ import {
deleteSelection,
} from "prosemirror-commands";
-import { collapseMathCmd } from "./commands/collapse-math-cmd";
+import { collapseMathNode } from "./commands/collapse-math-node";
import { IMathPluginState } from "./math-plugin";
import { MathRenderer, MathRenderFn } from "./renderers/types";
@@ -45,7 +45,7 @@ interface IMathViewOptions {
renderer: MathRenderFn;
/** Should be true if node is inline */
- inline?: boolean;
+ className?: string;
}
export class MathView implements NodeView, ICursorPosObserver {
@@ -102,8 +102,7 @@ export class MathView implements NodeView, ICursorPosObserver {
// create dom representation of nodeview
this.dom = document.createElement(this._tagName);
- if (options.inline) this.dom.classList.add("math-inline");
- else this.dom.classList.add("math-display");
+ if (options.className) this.dom.classList.add(options.className);
this.dom.classList.add("math-node");
this._mathRenderElt = document.createElement("span");
@@ -342,13 +341,13 @@ export class MathView implements NodeView, ICursorPosObserver {
// },
Enter: chainCommands(
newlineInCode,
- collapseMathCmd(this._outerView, +1, false)
+ collapseMathNode(this._outerView, +1, false)
),
- "Ctrl-Enter": collapseMathCmd(this._outerView, +1, false),
- ArrowLeft: collapseMathCmd(this._outerView, -1, true),
- ArrowRight: collapseMathCmd(this._outerView, +1, true),
- ArrowUp: collapseMathCmd(this._outerView, -1, true),
- ArrowDown: collapseMathCmd(this._outerView, +1, true),
+ "Ctrl-Enter": collapseMathNode(this._outerView, +1, false),
+ ArrowLeft: collapseMathNode(this._outerView, -1, true),
+ ArrowRight: collapseMathNode(this._outerView, +1, true),
+ ArrowUp: collapseMathNode(this._outerView, -1, true),
+ ArrowDown: collapseMathNode(this._outerView, +1, true),
}),
],
}),
diff --git a/packages/editor/src/extensions/math/plugin/math-plugin.ts b/packages/editor/src/extensions/math/plugin/math-plugin.ts
index e5702ec72..c2a9c8d7e 100644
--- a/packages/editor/src/extensions/math/plugin/math-plugin.ts
+++ b/packages/editor/src/extensions/math/plugin/math-plugin.ts
@@ -58,7 +58,7 @@ export function createMathView(inline: boolean) {
view,
getPos as () => number,
{
- inline,
+ className: inline ? "math-inline" : "math-block",
renderer: inline ? KatexRenderer.inline : KatexRenderer.block,
tagName: inline ? "span" : "div",
},
@@ -102,8 +102,8 @@ let mathPluginSpec: PluginSpec<IMathPluginState> = {
},
props: {
nodeViews: {
- math_inline: createMathView(true),
- math_display: createMathView(false),
+ mathInline: createMathView(true),
+ mathBlock: createMathView(false),
},
},
};
diff --git a/packages/editor/src/styles.css b/packages/editor/src/styles.css
index 119db826e..52446af8f 100644
--- a/packages/editor/src/styles.css
+++ b/packages/editor/src/styles.css
@@ -335,22 +335,22 @@ span:focus .fake-cursor {
/* -- Block Math ---------------------------------------- */
-.math-display {
+.math-block {
display: block;
}
-.math-display .math-render {
+.math-block .math-render {
display: block;
}
-.math-display.ProseMirror-selectednode {
+.math-block.ProseMirror-selectednode {
background-color: var(--bgSecondary);
padding: 10px;
border-radius: 5px;
border: 1px solid var(--border);
}
-.math-display .math-src .ProseMirror {
+.math-block .math-src .ProseMirror {
width: 100%;
display: block;
margin-top: 10px;
@@ -358,15 +358,15 @@ span:focus .fake-cursor {
Liberation Mono, monospace !important;
}
-/* .math-display .math-src::after, */
-.math-display .math-src::before {
+/* .math-block .math-src::after, */
+.math-block .math-src::before {
content: "Math";
text-align: left;
color: var(--disabled);
margin-bottom: 10px;
}
-.math-display .katex-display {
+.math-block .katex-display {
margin: 0;
}
diff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.ts
index c87d18608..9092de0aa 100644
--- a/packages/editor/src/toolbar/icons.ts
+++ b/packages/editor/src/toolbar/icons.ts
@@ -38,16 +38,13 @@ import {
mdiTableColumnRemove,
mdiUploadOutline,
mdiPlus,
- mdiSquareRoundedBadgeOutline,
mdiFormatColorFill,
- mdiBorderAllVariant,
mdiClose,
mdiSortDescending,
mdiArrowExpandRight,
mdiArrowExpandLeft,
mdiArrowExpandDown,
mdiArrowExpandUp,
- mdiTrashCanOutline,
mdiTableMergeCells,
mdiTableSplitCell,
mdiDeleteOutline,
@@ -58,28 +55,12 @@ import {
mdiChevronUp,
mdiArrowUp,
mdiArrowDown,
- mdiText,
- mdiTextBoxMultipleOutline,
- mdiTextBoxOutline,
- mdiAllInclusiveBoxOutline,
- mdiSetAll,
- mdiArrowCollapseAll,
- mdiArrowExpandAll,
- mdiClipboardMultipleOutline,
- mdiBackspaceReverseOutline,
- mdiRepeat,
- mdiRepeatOnce,
- mdiRepeatVariant,
- mdiCaseSensitiveAlt,
mdiRegex,
- mdiFormatFont,
mdiFormatLetterCase,
mdiFormatLetterMatches,
mdiMoviePlusOutline,
mdiLink,
mdiChevronRight,
- mdiTableRow,
- mdiTableColumn,
mdiTableColumnWidth,
mdiTableRowHeight,
mdiMinus,
@@ -87,18 +68,16 @@ import {
mdiCircle,
mdiChevronLeft,
mdiTableCog,
- mdiVectorRectangle,
- mdiSquareOutline,
mdiTableOff,
- mdiRectangleOutline,
mdiRectangle,
- mdiImageEdit,
mdiImageEditOutline,
mdiArrowLeft,
mdiMovieCogOutline,
mdiLinkOff,
mdiOpenInNew,
mdiCameraOutline,
+ mdiMathIntegral,
+ mdiFunctionVariant,
} from "@mdi/js";
export const Icons = {
@@ -186,6 +165,8 @@ export const Icons = {
embedSettings: mdiMovieCogOutline,
palette: mdiPaletteOutline,
tableSettings: mdiTableCog,
+ math: mdiFunctionVariant,
+ mathBlock: mdiMathIntegral,
plus: mdiPlus,
minus: mdiMinus,
diff --git a/packages/editor/src/toolbar/tool-definitions.ts b/packages/editor/src/toolbar/tool-definitions.ts
index 0e1aa1c11..f78e3c6ed 100644
--- a/packages/editor/src/toolbar/tool-definitions.ts
+++ b/packages/editor/src/toolbar/tool-definitions.ts
@@ -119,6 +119,10 @@ const tools: Record<ToolId, ToolDefinition> = {
icon: "textColor",
title: "Text color",
},
+ math: {
+ icon: "math",
+ title: "Math (inline)",
+ },
tableSettings: {
icon: "tableSettings",
@@ -297,6 +301,10 @@ export function getToolDefinition(id: ToolId) {
return tools[id];
}
+export function getAllTools() {
+ return tools;
+}
+
export const DEFAULT_TOOLS: ToolbarDefinition = [
[
"insertBlock",
@@ -318,6 +326,7 @@ export const DEFAULT_TOOLS: ToolbarDefinition = [
"superscript",
"highlight",
"textColor",
+ "math",
],
],
["fontSize"],
diff --git a/packages/editor/src/toolbar/tools/block.tsx b/packages/editor/src/toolbar/tools/block.tsx
index 1a4554e42..5356df7bf 100644
--- a/packages/editor/src/toolbar/tools/block.tsx
+++ b/packages/editor/src/toolbar/tools/block.tsx
@@ -24,6 +24,7 @@ export function InsertBlock(props: ToolProps) {
tasklist(editor),
horizontalRule(editor),
codeblock(editor),
+ mathblock(editor),
blockquote(editor),
image(editor, isMobile),
attachment(editor),
@@ -99,6 +100,15 @@ const blockquote = (editor: Editor): MenuItem => ({
onClick: () => editor.current?.chain().focus().toggleBlockquote().run(),
});
+const mathblock = (editor: Editor): MenuItem => ({
+ key: "math",
+ type: "button",
+ title: "Math & formulas",
+ icon: "mathBlock",
+ isChecked: editor?.isActive("mathBlock"),
+ onClick: () => editor.current?.chain().focus().insertMathBlock().run(),
+});
+
const image = (editor: Editor, isMobile: boolean): MenuItem => ({
key: "image",
type: "button",
diff --git a/packages/editor/src/toolbar/tools/index.ts b/packages/editor/src/toolbar/tools/index.ts
index c1f6164c9..82d9d4db4 100644
--- a/packages/editor/src/toolbar/tools/index.ts
+++ b/packages/editor/src/toolbar/tools/index.ts
@@ -10,6 +10,7 @@ import {
Superscript,
ClearFormatting,
CodeRemove,
+ Math,
} from "./inline";
import { InsertBlock } from "./block";
import { FontSize, FontFamily } from "./font";
@@ -92,6 +93,7 @@ const tools = {
rtl: RightToLeft,
textColor: TextColor,
highlight: Highlight,
+ math: Math,
imageSettings: ImageSettings,
imageAlignCenter: ImageAlignCenter,
diff --git a/packages/editor/src/toolbar/tools/inline.tsx b/packages/editor/src/toolbar/tools/inline.tsx
index 9ffd8eb8f..43011b96f 100644
--- a/packages/editor/src/toolbar/tools/inline.tsx
+++ b/packages/editor/src/toolbar/tools/inline.tsx
@@ -112,3 +112,14 @@ export function CodeRemove(props: ToolProps) {
/>
);
}
+
+export function Math(props: ToolProps) {
+ const { editor } = props;
+ return (
+ <ToolButton
+ {...props}
+ toggled={false}
+ onClick={() => editor.current?.chain().focus().insertMathInline().run()}
+ />
+ );
+}