@tiptap/extension-mathematics 3.0.0-beta.15 → 3.0.0-beta.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,28 +1,129 @@
1
- import { Editor, Extension } from '@tiptap/core';
2
- import { EditorState, Plugin } from '@tiptap/pm/state';
3
- import { Node } from '@tiptap/pm/model';
1
+ import { Node as Node$1, Editor, Extension } from '@tiptap/core';
4
2
  import { KatexOptions } from 'katex';
5
- import { DecorationSet } from '@tiptap/pm/view';
3
+ import { Node } from '@tiptap/pm/model';
4
+
5
+ type BlockMathOptions = {
6
+ onClick?: (node: Node, pos: number) => void;
7
+ };
8
+ declare module '@tiptap/core' {
9
+ interface Commands<ReturnType> {
10
+ blockMath: {
11
+ /**
12
+ * Set block math node with LaTeX string.
13
+ * @param options - Options for setting block math.
14
+ * @returns ReturnType
15
+ */
16
+ setBlockMath: (options: {
17
+ latex: string;
18
+ pos?: number;
19
+ }) => ReturnType;
20
+ /**
21
+ * Unset block math node.
22
+ * @returns ReturnType
23
+ */
24
+ unsetBlockMath: (options?: {
25
+ pos?: number;
26
+ }) => ReturnType;
27
+ /**
28
+ * Update block math node with optional LaTeX string.
29
+ * @param options - Options for updating block math.
30
+ * @returns ReturnType
31
+ */
32
+ updateBlockMath: (options?: {
33
+ latex?: string;
34
+ pos?: number;
35
+ }) => ReturnType;
36
+ };
37
+ }
38
+ }
39
+ /**
40
+ * BlockMath is a Tiptap extension for rendering block mathematical expressions using KaTeX.
41
+ * It allows users to insert LaTeX formatted math expressions block within text.
42
+ * It supports rendering, input rules for LaTeX syntax, and click handling for interaction.
43
+ *
44
+ * @example
45
+ * ```javascript
46
+ * import { BlockMath } from 'your-extension-path'
47
+ * import { Editor } from '@tiptap/core'
48
+ *
49
+ * const editor = new Editor({
50
+ * extensions: [
51
+ * BlockMath.configure({
52
+ * onClick: (node, pos) => {
53
+ * console.log('Block math clicked:', node.attrs.latex, 'at position:', pos)
54
+ * },
55
+ * }),
56
+ * ],
57
+ * })
58
+ */
59
+ declare const BlockMath: Node$1<any, any>;
60
+
61
+ type InlineMathOptions = {
62
+ onClick?: (node: Node, pos: number) => void;
63
+ };
64
+ declare module '@tiptap/core' {
65
+ interface Commands<ReturnType> {
66
+ inlineMath: {
67
+ /**
68
+ * Set inline math node with LaTeX string.
69
+ * @param options - Options for setting inline math.
70
+ * @returns ReturnType
71
+ */
72
+ setInlineMath: (options: {
73
+ latex: string;
74
+ pos?: number;
75
+ }) => ReturnType;
76
+ /**
77
+ * Unset inline math node.
78
+ * @returns ReturnType
79
+ */
80
+ unsetInlineMath: (options?: {
81
+ pos?: number;
82
+ }) => ReturnType;
83
+ /**
84
+ * Update inline math node with optional LaTeX string.
85
+ * @param options - Options for updating inline math.
86
+ * @returns ReturnType
87
+ */
88
+ updateInlineMath: (options?: {
89
+ latex?: string;
90
+ pos?: number;
91
+ }) => ReturnType;
92
+ };
93
+ }
94
+ }
95
+ /**
96
+ * InlineMath is a Tiptap extension for rendering inline mathematical expressions using KaTeX.
97
+ * It allows users to insert LaTeX formatted math expressions inline within text.
98
+ * It supports rendering, input rules for LaTeX syntax, and click handling for interaction.
99
+ *
100
+ * @example
101
+ * ```javascript
102
+ * import { InlineMath } from 'your-extension-path'
103
+ * import { Editor } from '@tiptap/core'
104
+ *
105
+ * const editor = new Editor({
106
+ * extensions: [
107
+ * InlineMath.configure({
108
+ * onClick: (node, pos) => {
109
+ * console.log('Inline math clicked:', node.attrs.latex, 'at position:', pos)
110
+ * },
111
+ * }),
112
+ * ],
113
+ * })
114
+ */
115
+ declare const InlineMath: Node$1<InlineMathOptions, any>;
6
116
 
7
117
  type MathematicsOptions = {
8
- regex: RegExp;
118
+ inlineOptions?: InlineMathOptions;
119
+ blockOptions?: BlockMathOptions;
9
120
  katexOptions?: KatexOptions;
10
- shouldRender: (state: EditorState, pos: number, node: Node) => boolean;
11
121
  };
12
122
  type MathematicsOptionsWithEditor = MathematicsOptions & {
13
123
  editor: Editor;
14
124
  };
15
125
 
16
- declare const defaultShouldRender: (state: EditorState, pos: number) => boolean;
126
+ declare const Math: Extension<MathematicsOptions, any>;
17
127
  declare const Mathematics: Extension<MathematicsOptions, any>;
18
128
 
19
- type PluginState = {
20
- decorations: DecorationSet;
21
- isEditable: boolean;
22
- } | {
23
- decorations: undefined;
24
- isEditable: undefined;
25
- };
26
- declare const MathematicsPlugin: (options: MathematicsOptionsWithEditor) => Plugin<PluginState>;
27
-
28
- export { Mathematics, type MathematicsOptions, type MathematicsOptionsWithEditor, MathematicsPlugin, Mathematics as default, defaultShouldRender };
129
+ export { BlockMath, type BlockMathOptions, InlineMath, type InlineMathOptions, Math, Mathematics, type MathematicsOptions, type MathematicsOptionsWithEditor, Math as default };
package/dist/index.js CHANGED
@@ -1,169 +1,285 @@
1
1
  // src/mathematics.ts
2
2
  import { Extension } from "@tiptap/core";
3
3
 
4
- // src/MathematicsPlugin.ts
5
- import { getChangedRanges } from "@tiptap/core";
6
- import { Plugin, PluginKey } from "@tiptap/pm/state";
7
- import { Decoration, DecorationSet } from "@tiptap/pm/view";
4
+ // src/extensions/BlockMath.ts
5
+ import { InputRule, mergeAttributes, Node } from "@tiptap/core";
8
6
  import katex from "katex";
9
- function getAffectedRange(newState, previousPluginState, isEditable, tr, state) {
10
- const docSize = newState.doc.nodeSize - 2;
11
- let minFrom = 0;
12
- let maxTo = docSize;
13
- if (previousPluginState.isEditable !== isEditable) {
14
- minFrom = 0;
15
- maxTo = docSize;
16
- } else if (tr.docChanged) {
17
- minFrom = docSize;
18
- maxTo = 0;
19
- getChangedRanges(tr).forEach((range) => {
20
- minFrom = Math.min(minFrom, range.newRange.from - 1, range.oldRange.from - 1);
21
- maxTo = Math.max(maxTo, range.newRange.to + 1, range.oldRange.to + 1);
22
- });
23
- } else if (tr.selectionSet) {
24
- const { $from, $to } = state.selection;
25
- const { $from: $newFrom, $to: $newTo } = newState.selection;
26
- minFrom = Math.min(
27
- // Purposefully over scan the range to ensure we catch all decorations
28
- $from.depth === 0 ? 0 : $from.before(),
29
- $newFrom.depth === 0 ? 0 : $newFrom.before()
30
- );
31
- maxTo = Math.max($to.depth === 0 ? maxTo : $to.after(), $newTo.depth === 0 ? maxTo : $newTo.after());
32
- }
33
- return {
34
- minFrom: Math.max(minFrom, 0),
35
- maxTo: Math.min(maxTo, docSize)
36
- };
37
- }
38
- var MathematicsPlugin = (options) => {
39
- const { regex, katexOptions = {}, editor, shouldRender } = options;
40
- return new Plugin({
41
- key: new PluginKey("mathematics"),
42
- state: {
43
- init() {
44
- return { decorations: void 0, isEditable: void 0 };
7
+ var BlockMath = Node.create({
8
+ name: "blockMath",
9
+ group: "block",
10
+ atom: true,
11
+ addOptions() {
12
+ return {
13
+ onClick: void 0
14
+ };
15
+ },
16
+ addAttributes() {
17
+ return {
18
+ latex: {
19
+ default: "",
20
+ parseHTML: (element) => element.getAttribute("data-latex"),
21
+ renderHTML: (attributes) => {
22
+ return {
23
+ "data-latex": attributes.latex
24
+ };
25
+ }
26
+ }
27
+ };
28
+ },
29
+ addCommands() {
30
+ return {
31
+ setBlockMath: (options) => ({ commands, editor }) => {
32
+ const { latex, pos } = options;
33
+ return commands.insertContentAt(pos != null ? pos : editor.state.selection.from, {
34
+ type: this.name,
35
+ attrs: { latex }
36
+ });
37
+ },
38
+ unsetBlockMath: (options) => ({ editor, tr }) => {
39
+ var _a;
40
+ const pos = (_a = options == null ? void 0 : options.pos) != null ? _a : editor.state.selection.$from.pos;
41
+ const node = editor.state.doc.nodeAt(pos);
42
+ if (!node || node.type.name !== this.name) {
43
+ return false;
44
+ }
45
+ tr.delete(pos, pos + node.nodeSize);
46
+ return true;
45
47
  },
46
- apply(tr, previousPluginState, state, newState) {
47
- if (!tr.docChanged && !tr.selectionSet && previousPluginState.decorations) {
48
- return previousPluginState;
49
- }
50
- const nextDecorationSet = (previousPluginState.decorations || DecorationSet.empty).map(tr.mapping, tr.doc);
51
- const { selection } = newState;
52
- const isEditable = editor.isEditable;
53
- const decorationsToAdd = [];
54
- const { minFrom, maxTo } = getAffectedRange(newState, previousPluginState, isEditable, tr, state);
55
- newState.doc.nodesBetween(minFrom, maxTo, (node, pos) => {
56
- const enabled = shouldRender(newState, pos, node);
57
- if (node.isText && node.text && enabled) {
58
- let match;
59
- while (match = regex.exec(node.text)) {
60
- const from = pos + match.index;
61
- const to = from + match[0].length;
62
- const content = match.slice(1).find(Boolean);
63
- if (content) {
64
- const selectionSize = selection.from - selection.to;
65
- const anchorIsInside = selection.anchor >= from && selection.anchor <= to;
66
- const rangeIsInside = selection.from >= from && selection.to <= to;
67
- const isEditing = selectionSize === 0 && anchorIsInside || rangeIsInside;
68
- if (
69
- // Are the decorations already present?
70
- nextDecorationSet.find(
71
- from,
72
- to,
73
- (deco) => isEditing === deco.isEditing && content === deco.content && isEditable === deco.isEditable && katexOptions === deco.katexOptions
74
- ).length
75
- ) {
76
- continue;
77
- }
78
- decorationsToAdd.push(
79
- Decoration.inline(
80
- from,
81
- to,
82
- {
83
- class: isEditing && isEditable ? "Tiptap-mathematics-editor" : "Tiptap-mathematics-editor Tiptap-mathematics-editor--hidden",
84
- style: !isEditing || !isEditable ? "display: inline-block; height: 0; opacity: 0; overflow: hidden; position: absolute; width: 0;" : void 0
85
- },
86
- {
87
- content,
88
- isEditable,
89
- isEditing,
90
- katexOptions
91
- }
92
- )
93
- );
94
- if (!isEditable || !isEditing) {
95
- decorationsToAdd.push(
96
- Decoration.widget(
97
- from,
98
- () => {
99
- const element = document.createElement("span");
100
- element.classList.add("Tiptap-mathematics-render");
101
- if (isEditable) {
102
- element.classList.add("Tiptap-mathematics-render--editable");
103
- }
104
- try {
105
- katex.render(content, element, katexOptions);
106
- } catch {
107
- element.innerHTML = content;
108
- }
109
- return element;
110
- },
111
- {
112
- content,
113
- isEditable,
114
- isEditing,
115
- katexOptions
116
- }
117
- )
118
- );
119
- }
120
- }
121
- }
122
- }
48
+ updateBlockMath: (options) => ({ editor, tr }) => {
49
+ const latex = options == null ? void 0 : options.latex;
50
+ let pos = options == null ? void 0 : options.pos;
51
+ if (pos === void 0) {
52
+ pos = editor.state.selection.$from.pos;
53
+ }
54
+ const node = editor.state.doc.nodeAt(pos);
55
+ if (!node || node.type.name !== this.name) {
56
+ return false;
57
+ }
58
+ tr.setNodeMarkup(pos, this.type, {
59
+ ...node.attrs,
60
+ latex: latex || node.attrs.latex
123
61
  });
124
- const decorationsToRemove = decorationsToAdd.flatMap((deco) => nextDecorationSet.find(deco.from, deco.to));
125
- return {
126
- decorations: nextDecorationSet.remove(decorationsToRemove).add(tr.doc, decorationsToAdd),
127
- isEditable
128
- };
62
+ return true;
63
+ }
64
+ };
65
+ },
66
+ parseHTML() {
67
+ return [
68
+ {
69
+ tag: 'div[data-type="block-math"]'
129
70
  }
130
- },
131
- props: {
132
- decorations(state) {
133
- var _a, _b;
134
- return (_b = (_a = this.getState(state)) == null ? void 0 : _a.decorations) != null ? _b : DecorationSet.empty;
71
+ ];
72
+ },
73
+ renderHTML({ HTMLAttributes }) {
74
+ return ["div", mergeAttributes(HTMLAttributes, { "data-type": "block-math" })];
75
+ },
76
+ addInputRules() {
77
+ return [
78
+ new InputRule({
79
+ find: /^\$\$\$([^$]+)\$\$\$$/,
80
+ handler: ({ state, range, match }) => {
81
+ const [, latex] = match;
82
+ const { tr } = state;
83
+ const start = range.from;
84
+ const end = range.to;
85
+ tr.replaceWith(start, end, this.type.create({ latex }));
86
+ }
87
+ })
88
+ ];
89
+ },
90
+ addNodeView() {
91
+ return ({ node, getPos }) => {
92
+ const wrapper = document.createElement("div");
93
+ const innerWrapper = document.createElement("div");
94
+ wrapper.className = "Tiptap-mathematics-render Tiptap-mathematics-render--editable";
95
+ innerWrapper.className = "block-math-inner";
96
+ wrapper.dataset.type = "block-math";
97
+ wrapper.setAttribute("data-latex", node.attrs.latex);
98
+ wrapper.appendChild(innerWrapper);
99
+ function renderMath() {
100
+ try {
101
+ katex.render(node.attrs.latex, innerWrapper);
102
+ wrapper.classList.remove("block-math-error");
103
+ } catch {
104
+ wrapper.textContent = node.attrs.latex;
105
+ wrapper.classList.add("block-math-error");
106
+ }
135
107
  }
136
- }
137
- });
138
- };
108
+ const handleClick = (event) => {
109
+ event.preventDefault();
110
+ event.stopPropagation();
111
+ const pos = getPos();
112
+ if (pos == null) {
113
+ return;
114
+ }
115
+ if (this.options.onClick) {
116
+ this.options.onClick(node, pos);
117
+ }
118
+ };
119
+ if (this.options.onClick) {
120
+ wrapper.addEventListener("click", handleClick);
121
+ }
122
+ renderMath();
123
+ return {
124
+ dom: wrapper,
125
+ destroy() {
126
+ wrapper.removeEventListener("click", handleClick);
127
+ }
128
+ };
129
+ };
130
+ }
131
+ });
132
+
133
+ // src/extensions/InlineMath.ts
134
+ import { InputRule as InputRule2, mergeAttributes as mergeAttributes2, Node as Node2 } from "@tiptap/core";
135
+ import katex2 from "katex";
136
+ var InlineMath = Node2.create({
137
+ name: "inlineMath",
138
+ group: "inline",
139
+ inline: true,
140
+ atom: true,
141
+ addOptions() {
142
+ return {
143
+ onClick: void 0
144
+ };
145
+ },
146
+ addAttributes() {
147
+ return {
148
+ latex: {
149
+ default: "",
150
+ parseHTML: (element) => element.getAttribute("data-latex"),
151
+ renderHTML: (attributes) => {
152
+ return {
153
+ "data-latex": attributes.latex
154
+ };
155
+ }
156
+ }
157
+ };
158
+ },
159
+ addCommands() {
160
+ return {
161
+ setInlineMath: (options) => ({ editor, tr }) => {
162
+ var _a;
163
+ const latex = options == null ? void 0 : options.latex;
164
+ const pos = (_a = options == null ? void 0 : options.pos) != null ? _a : editor.state.selection.$from.pos;
165
+ if (!latex) {
166
+ return false;
167
+ }
168
+ tr.replaceWith(pos, pos, this.type.create({ latex }));
169
+ return true;
170
+ },
171
+ unsetInlineMath: (options) => ({ editor, tr }) => {
172
+ var _a;
173
+ const pos = (_a = options == null ? void 0 : options.pos) != null ? _a : editor.state.selection.$from.pos;
174
+ const node = editor.state.doc.nodeAt(pos);
175
+ if (!node || node.type.name !== this.name) {
176
+ return false;
177
+ }
178
+ tr.delete(pos, pos + node.nodeSize);
179
+ return true;
180
+ },
181
+ updateInlineMath: (options) => ({ editor, tr }) => {
182
+ const latex = options == null ? void 0 : options.latex;
183
+ let pos = options == null ? void 0 : options.pos;
184
+ if (pos === void 0) {
185
+ pos = editor.state.selection.$from.pos;
186
+ }
187
+ const node = editor.state.doc.nodeAt(pos);
188
+ if (!node || node.type.name !== this.name) {
189
+ return false;
190
+ }
191
+ tr.setNodeMarkup(pos, this.type, { ...node.attrs, latex });
192
+ return true;
193
+ }
194
+ };
195
+ },
196
+ parseHTML() {
197
+ return [
198
+ {
199
+ tag: 'span[data-type="inline-math"]'
200
+ }
201
+ ];
202
+ },
203
+ renderHTML({ HTMLAttributes }) {
204
+ return ["span", mergeAttributes2(HTMLAttributes, { "data-type": "inline-math" })];
205
+ },
206
+ addInputRules() {
207
+ return [
208
+ new InputRule2({
209
+ find: /(?<!\$)\$\$([^$\n]+)\$\$(?!\$)$/,
210
+ handler: ({ state, range, match }) => {
211
+ const [, latex] = match;
212
+ const { tr } = state;
213
+ const start = range.from;
214
+ const end = range.to;
215
+ tr.replaceWith(start, end, this.type.create({ latex }));
216
+ }
217
+ })
218
+ ];
219
+ },
220
+ addNodeView() {
221
+ return ({ node, getPos }) => {
222
+ const wrapper = document.createElement("span");
223
+ wrapper.className = "Tiptap-mathematics-render Tiptap-mathematics-render--editable";
224
+ wrapper.dataset.type = "inline-math";
225
+ wrapper.setAttribute("data-latex", node.attrs.latex);
226
+ function renderMath() {
227
+ try {
228
+ katex2.render(node.attrs.latex, wrapper);
229
+ wrapper.classList.remove("inline-math-error");
230
+ } catch {
231
+ wrapper.textContent = node.attrs.latex;
232
+ wrapper.classList.add("inline-math-error");
233
+ }
234
+ }
235
+ const handleClick = (event) => {
236
+ event.preventDefault();
237
+ event.stopPropagation();
238
+ const pos = getPos();
239
+ if (pos == null) {
240
+ return;
241
+ }
242
+ if (this.options.onClick) {
243
+ this.options.onClick(node, pos);
244
+ }
245
+ };
246
+ if (this.options.onClick) {
247
+ wrapper.addEventListener("click", handleClick);
248
+ }
249
+ renderMath();
250
+ return {
251
+ dom: wrapper,
252
+ destroy() {
253
+ wrapper.removeEventListener("click", handleClick);
254
+ }
255
+ };
256
+ };
257
+ }
258
+ });
139
259
 
140
260
  // src/mathematics.ts
141
- var defaultShouldRender = (state, pos) => {
142
- const $pos = state.doc.resolve(pos);
143
- const isInCodeBlock = $pos.parent.type.name === "codeBlock";
144
- return !isInCodeBlock;
145
- };
146
- var Mathematics = Extension.create({
261
+ var Math = Extension.create({
147
262
  name: "Mathematics",
148
263
  addOptions() {
149
264
  return {
150
- // eslint-disable-next-line no-useless-escape
151
- regex: /\$([^\$]*)\$/gi,
152
- katexOptions: void 0,
153
- shouldRender: defaultShouldRender
265
+ inlineOptions: void 0,
266
+ blockOptions: void 0,
267
+ katexOptions: void 0
154
268
  };
155
269
  },
156
- addProseMirrorPlugins() {
157
- return [MathematicsPlugin({ ...this.options, editor: this.editor })];
270
+ addExtensions() {
271
+ return [BlockMath.configure(this.options.blockOptions), InlineMath.configure(this.options.inlineOptions)];
158
272
  }
159
273
  });
274
+ var Mathematics = Math;
160
275
 
161
276
  // src/index.ts
162
- var index_default = Mathematics;
277
+ var index_default = Math;
163
278
  export {
279
+ BlockMath,
280
+ InlineMath,
281
+ Math,
164
282
  Mathematics,
165
- MathematicsPlugin,
166
- index_default as default,
167
- defaultShouldRender
283
+ index_default as default
168
284
  };
169
285
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mathematics.ts","../src/MathematicsPlugin.ts","../src/index.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport type { EditorState } from '@tiptap/pm/state'\n\nimport { MathematicsPlugin } from './MathematicsPlugin.js'\nimport type { MathematicsOptions } from './types.js'\n\nexport const defaultShouldRender = (state: EditorState, pos: number) => {\n const $pos = state.doc.resolve(pos)\n const isInCodeBlock = $pos.parent.type.name === 'codeBlock'\n\n return !isInCodeBlock\n}\n\nexport const Mathematics = Extension.create<MathematicsOptions>({\n name: 'Mathematics',\n\n addOptions() {\n return {\n // eslint-disable-next-line no-useless-escape\n regex: /\\$([^\\$]*)\\$/gi,\n katexOptions: undefined,\n shouldRender: defaultShouldRender,\n }\n },\n\n addProseMirrorPlugins() {\n return [MathematicsPlugin({ ...this.options, editor: this.editor })]\n },\n})\n\nexport default Mathematics\n","import { getChangedRanges } from '@tiptap/core'\nimport type { EditorState, Transaction } from '@tiptap/pm/state'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\nimport katex from 'katex'\n\nimport type { MathematicsOptionsWithEditor } from './types.js'\n\ntype DecoSpec = {\n isEditable: boolean\n isEditing: boolean\n katexOptions: MathematicsOptionsWithEditor['katexOptions']\n content: string\n}\n\ntype Deco = Omit<Decoration, 'spec'> & { spec: DecoSpec }\n\ntype PluginState =\n | { decorations: DecorationSet; isEditable: boolean }\n | { decorations: undefined; isEditable: undefined }\n\n/**\n * Get the range of positions that have been affected by a transaction\n */\nfunction getAffectedRange(\n newState: EditorState,\n previousPluginState: PluginState,\n isEditable: boolean,\n tr: Transaction,\n state: EditorState,\n) {\n const docSize = newState.doc.nodeSize - 2\n let minFrom = 0\n let maxTo = docSize\n\n if (previousPluginState.isEditable !== isEditable) {\n // When the editable state changes, run on all nodes just to be safe\n minFrom = 0\n maxTo = docSize\n } else if (tr.docChanged) {\n // When the document changes, only run on the nodes that have changed\n minFrom = docSize\n maxTo = 0\n\n getChangedRanges(tr).forEach(range => {\n // Purposefully over scan the range to ensure we catch all decorations\n minFrom = Math.min(minFrom, range.newRange.from - 1, range.oldRange.from - 1)\n maxTo = Math.max(maxTo, range.newRange.to + 1, range.oldRange.to + 1)\n })\n } else if (tr.selectionSet) {\n const { $from, $to } = state.selection\n const { $from: $newFrom, $to: $newTo } = newState.selection\n\n // When the selection changes, run on all the nodes between the old and new selection\n minFrom = Math.min(\n // Purposefully over scan the range to ensure we catch all decorations\n $from.depth === 0 ? 0 : $from.before(),\n $newFrom.depth === 0 ? 0 : $newFrom.before(),\n )\n maxTo = Math.max($to.depth === 0 ? maxTo : $to.after(), $newTo.depth === 0 ? maxTo : $newTo.after())\n }\n\n return {\n minFrom: Math.max(minFrom, 0),\n maxTo: Math.min(maxTo, docSize),\n }\n}\n\nexport const MathematicsPlugin = (options: MathematicsOptionsWithEditor) => {\n const { regex, katexOptions = {}, editor, shouldRender } = options\n\n return new Plugin<PluginState>({\n key: new PluginKey('mathematics'),\n\n state: {\n init() {\n return { decorations: undefined, isEditable: undefined }\n },\n apply(tr, previousPluginState, state, newState) {\n if (!tr.docChanged && !tr.selectionSet && previousPluginState.decorations) {\n // Just reuse the existing decorations, since nothing should have changed\n return previousPluginState\n }\n\n const nextDecorationSet = (previousPluginState.decorations || DecorationSet.empty).map(tr.mapping, tr.doc)\n const { selection } = newState\n const isEditable = editor.isEditable\n const decorationsToAdd = [] as Deco[]\n const { minFrom, maxTo } = getAffectedRange(newState, previousPluginState, isEditable, tr, state)\n\n newState.doc.nodesBetween(minFrom, maxTo, (node, pos) => {\n const enabled = shouldRender(newState, pos, node)\n\n if (node.isText && node.text && enabled) {\n let match: RegExpExecArray | null\n\n // eslint-disable-next-line no-cond-assign\n while ((match = regex.exec(node.text))) {\n const from = pos + match.index\n const to = from + match[0].length\n const content = match.slice(1).find(Boolean)\n\n if (content) {\n const selectionSize = selection.from - selection.to\n const anchorIsInside = selection.anchor >= from && selection.anchor <= to\n const rangeIsInside = selection.from >= from && selection.to <= to\n const isEditing = (selectionSize === 0 && anchorIsInside) || rangeIsInside\n\n if (\n // Are the decorations already present?\n nextDecorationSet.find(\n from,\n to,\n (deco: DecoSpec) =>\n isEditing === deco.isEditing &&\n content === deco.content &&\n isEditable === deco.isEditable &&\n katexOptions === deco.katexOptions,\n ).length\n ) {\n // Decoration exists in set, no need to add it again\n continue\n }\n // Use an inline decoration to either hide original (preview is showing) or show it (editing \"mode\")\n decorationsToAdd.push(\n Decoration.inline(\n from,\n to,\n {\n class:\n isEditing && isEditable\n ? 'Tiptap-mathematics-editor'\n : 'Tiptap-mathematics-editor Tiptap-mathematics-editor--hidden',\n style:\n !isEditing || !isEditable\n ? 'display: inline-block; height: 0; opacity: 0; overflow: hidden; position: absolute; width: 0;'\n : undefined,\n },\n {\n content,\n isEditable,\n isEditing,\n katexOptions,\n } satisfies DecoSpec,\n ),\n )\n\n if (!isEditable || !isEditing) {\n // Create decoration widget and add KaTeX preview if selection is not within the math-editor\n decorationsToAdd.push(\n Decoration.widget(\n from,\n () => {\n const element = document.createElement('span')\n\n // TODO: changeable class names\n element.classList.add('Tiptap-mathematics-render')\n\n if (isEditable) {\n element.classList.add('Tiptap-mathematics-render--editable')\n }\n\n try {\n katex.render(content!, element, katexOptions)\n } catch {\n element.innerHTML = content!\n }\n\n return element\n },\n {\n content,\n isEditable,\n isEditing,\n katexOptions,\n } satisfies DecoSpec,\n ),\n )\n }\n }\n }\n }\n })\n\n // Remove any decorations that exist at the same position, they will be replaced by the new decorations\n const decorationsToRemove = decorationsToAdd.flatMap(deco => nextDecorationSet.find(deco.from, deco.to))\n\n return {\n decorations: nextDecorationSet\n // Remove existing decorations that are going to be replaced\n .remove(decorationsToRemove)\n // Add any new decorations\n .add(tr.doc, decorationsToAdd),\n isEditable,\n }\n },\n },\n\n props: {\n decorations(state) {\n return this.getState(state)?.decorations ?? DecorationSet.empty\n },\n },\n })\n}\n","import { Mathematics } from './mathematics.js'\n\nexport * from './mathematics.js'\nexport * from './MathematicsPlugin.js'\nexport * from './types.js'\n\nexport default Mathematics\n"],"mappings":";AAAA,SAAS,iBAAiB;;;ACA1B,SAAS,wBAAwB;AAEjC,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AAC1C,OAAO,WAAW;AAoBlB,SAAS,iBACP,UACA,qBACA,YACA,IACA,OACA;AACA,QAAM,UAAU,SAAS,IA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AAAA,MACd,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,CAAC,kBAAkB,EAAE,GAAG,KAAK,SAAS,QAAQ,KAAK,OAAO,CAAC,CAAC;AAAA,EACrE;AACF,CAAC;;;AEtBD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/mathematics.ts","../src/extensions/BlockMath.ts","../src/extensions/InlineMath.ts","../src/index.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\n\nimport { BlockMath, InlineMath } from './extensions/index.js'\nimport type { MathematicsOptions } from './types.js'\n\nexport const Math = Extension.create<MathematicsOptions>({\n name: 'Mathematics',\n\n addOptions() {\n return {\n inlineOptions: undefined,\n blockOptions: undefined,\n katexOptions: undefined,\n }\n },\n\n addExtensions() {\n return [BlockMath.configure(this.options.blockOptions), InlineMath.configure(this.options.inlineOptions)]\n },\n})\n\nexport const Mathematics = Math\n\nexport default Math\n","import { InputRule, mergeAttributes, Node } from '@tiptap/core'\nimport type { Node as PMNode } from '@tiptap/pm/model'\nimport katex from 'katex'\n\nexport type BlockMathOptions = {\n onClick?: (node: PMNode, pos: number) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n blockMath: {\n /**\n * Set block math node with LaTeX string.\n * @param options - Options for setting block math.\n * @returns ReturnType\n */\n setBlockMath: (options: { latex: string; pos?: number }) => ReturnType\n\n /**\n * Unset block math node.\n * @returns ReturnType\n */\n unsetBlockMath: (options?: { pos?: number }) => ReturnType\n\n /**\n * Update block math node with optional LaTeX string.\n * @param options - Options for updating block math.\n * @returns ReturnType\n */\n updateBlockMath: (options?: { latex?: string; pos?: number }) => ReturnType\n }\n }\n}\n\n/**\n * BlockMath is a Tiptap extension for rendering block mathematical expressions using KaTeX.\n * It allows users to insert LaTeX formatted math expressions block within text.\n * It supports rendering, input rules for LaTeX syntax, and click handling for interaction.\n *\n * @example\n * ```javascript\n * import { BlockMath } from 'your-extension-path'\n * import { Editor } from '@tiptap/core'\n *\n * const editor = new Editor({\n * extensions: [\n * BlockMath.configure({\n * onClick: (node, pos) => {\n * console.log('Block math clicked:', node.attrs.latex, 'at position:', pos)\n * },\n * }),\n * ],\n * })\n */\nexport const BlockMath = Node.create({\n name: 'blockMath',\n\n group: 'block',\n\n atom: true,\n\n addOptions() {\n return {\n onClick: undefined,\n }\n },\n\n addAttributes() {\n return {\n latex: {\n default: '',\n parseHTML: element => element.getAttribute('data-latex'),\n renderHTML: attributes => {\n return {\n 'data-latex': attributes.latex,\n }\n },\n },\n }\n },\n\n addCommands() {\n return {\n setBlockMath:\n options =>\n ({ commands, editor }) => {\n const { latex, pos } = options\n return commands.insertContentAt(pos ?? editor.state.selection.from, {\n type: this.name,\n attrs: { latex },\n })\n },\n\n unsetBlockMath:\n options =>\n ({ editor, tr }) => {\n const pos = options?.pos ?? editor.state.selection.$from.pos\n const node = editor.state.doc.nodeAt(pos)\n\n if (!node || node.type.name !== this.name) {\n return false\n }\n\n tr.delete(pos, pos + node.nodeSize)\n return true\n },\n\n updateBlockMath:\n options =>\n ({ editor, tr }) => {\n const latex = options?.latex\n let pos = options?.pos\n\n if (pos === undefined) {\n pos = editor.state.selection.$from.pos\n }\n\n const node = editor.state.doc.nodeAt(pos)\n\n if (!node || node.type.name !== this.name) {\n return false\n }\n\n tr.setNodeMarkup(pos, this.type, {\n ...node.attrs,\n latex: latex || node.attrs.latex,\n })\n\n return true\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-type=\"block-math\"]',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['div', mergeAttributes(HTMLAttributes, { 'data-type': 'block-math' })]\n },\n\n addInputRules() {\n return [\n new InputRule({\n find: /^\\$\\$\\$([^$]+)\\$\\$\\$$/,\n handler: ({ state, range, match }) => {\n const [, latex] = match\n const { tr } = state\n const start = range.from\n const end = range.to\n\n tr.replaceWith(start, end, this.type.create({ latex }))\n },\n }),\n ]\n },\n\n addNodeView() {\n return ({ node, getPos }) => {\n const wrapper = document.createElement('div')\n const innerWrapper = document.createElement('div')\n wrapper.className = 'Tiptap-mathematics-render Tiptap-mathematics-render--editable'\n innerWrapper.className = 'block-math-inner'\n wrapper.dataset.type = 'block-math'\n wrapper.setAttribute('data-latex', node.attrs.latex)\n wrapper.appendChild(innerWrapper)\n\n function renderMath() {\n try {\n katex.render(node.attrs.latex, innerWrapper)\n wrapper.classList.remove('block-math-error')\n } catch {\n wrapper.textContent = node.attrs.latex\n wrapper.classList.add('block-math-error')\n }\n }\n\n const handleClick = (event: MouseEvent) => {\n event.preventDefault()\n event.stopPropagation()\n const pos = getPos()\n\n if (pos == null) {\n return\n }\n\n if (this.options.onClick) {\n this.options.onClick(node, pos)\n }\n }\n\n if (this.options.onClick) {\n wrapper.addEventListener('click', handleClick)\n }\n\n renderMath()\n\n return {\n dom: wrapper,\n destroy() {\n wrapper.removeEventListener('click', handleClick)\n },\n }\n }\n },\n})\n","import { InputRule, mergeAttributes, Node } from '@tiptap/core'\nimport type { Node as PMNode } from '@tiptap/pm/model'\nimport katex from 'katex'\n\nexport type InlineMathOptions = {\n onClick?: (node: PMNode, pos: number) => void\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n inlineMath: {\n /**\n * Set inline math node with LaTeX string.\n * @param options - Options for setting inline math.\n * @returns ReturnType\n */\n setInlineMath: (options: { latex: string; pos?: number }) => ReturnType\n\n /**\n * Unset inline math node.\n * @returns ReturnType\n */\n unsetInlineMath: (options?: { pos?: number }) => ReturnType\n\n /**\n * Update inline math node with optional LaTeX string.\n * @param options - Options for updating inline math.\n * @returns ReturnType\n */\n updateInlineMath: (options?: { latex?: string; pos?: number }) => ReturnType\n }\n }\n}\n\n/**\n * InlineMath is a Tiptap extension for rendering inline mathematical expressions using KaTeX.\n * It allows users to insert LaTeX formatted math expressions inline within text.\n * It supports rendering, input rules for LaTeX syntax, and click handling for interaction.\n *\n * @example\n * ```javascript\n * import { InlineMath } from 'your-extension-path'\n * import { Editor } from '@tiptap/core'\n *\n * const editor = new Editor({\n * extensions: [\n * InlineMath.configure({\n * onClick: (node, pos) => {\n * console.log('Inline math clicked:', node.attrs.latex, 'at position:', pos)\n * },\n * }),\n * ],\n * })\n */\nexport const InlineMath = Node.create<InlineMathOptions>({\n name: 'inlineMath',\n\n group: 'inline',\n\n inline: true,\n\n atom: true,\n\n addOptions() {\n return {\n onClick: undefined,\n }\n },\n\n addAttributes() {\n return {\n latex: {\n default: '',\n parseHTML: element => element.getAttribute('data-latex'),\n renderHTML: attributes => {\n return {\n 'data-latex': attributes.latex,\n }\n },\n },\n }\n },\n\n addCommands() {\n return {\n setInlineMath:\n options =>\n ({ editor, tr }) => {\n const latex = options?.latex\n const pos = options?.pos ?? editor.state.selection.$from.pos\n\n if (!latex) {\n return false\n }\n\n tr.replaceWith(pos, pos, this.type.create({ latex }))\n return true\n },\n\n unsetInlineMath:\n options =>\n ({ editor, tr }) => {\n const pos = options?.pos ?? editor.state.selection.$from.pos\n const node = editor.state.doc.nodeAt(pos)\n\n if (!node || node.type.name !== this.name) {\n return false\n }\n\n tr.delete(pos, pos + node.nodeSize)\n return true\n },\n\n updateInlineMath:\n options =>\n ({ editor, tr }) => {\n const latex = options?.latex\n let pos = options?.pos\n\n if (pos === undefined) {\n pos = editor.state.selection.$from.pos\n }\n\n const node = editor.state.doc.nodeAt(pos)\n\n if (!node || node.type.name !== this.name) {\n return false\n }\n\n tr.setNodeMarkup(pos, this.type, { ...node.attrs, latex })\n\n return true\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span[data-type=\"inline-math\"]',\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['span', mergeAttributes(HTMLAttributes, { 'data-type': 'inline-math' })]\n },\n\n addInputRules() {\n return [\n new InputRule({\n find: /(?<!\\$)\\$\\$([^$\\n]+)\\$\\$(?!\\$)$/,\n handler: ({ state, range, match }) => {\n const [, latex] = match\n const { tr } = state\n const start = range.from\n const end = range.to\n\n tr.replaceWith(start, end, this.type.create({ latex }))\n },\n }),\n ]\n },\n\n addNodeView() {\n return ({ node, getPos }) => {\n const wrapper = document.createElement('span')\n wrapper.className = 'Tiptap-mathematics-render Tiptap-mathematics-render--editable'\n wrapper.dataset.type = 'inline-math'\n wrapper.setAttribute('data-latex', node.attrs.latex)\n\n function renderMath() {\n try {\n katex.render(node.attrs.latex, wrapper)\n wrapper.classList.remove('inline-math-error')\n } catch {\n wrapper.textContent = node.attrs.latex\n wrapper.classList.add('inline-math-error')\n }\n }\n\n const handleClick = (event: MouseEvent) => {\n event.preventDefault()\n event.stopPropagation()\n const pos = getPos()\n\n if (pos == null) {\n return\n }\n\n if (this.options.onClick) {\n this.options.onClick(node, pos)\n }\n }\n\n if (this.options.onClick) {\n wrapper.addEventListener('click', handleClick)\n }\n\n renderMath()\n\n return {\n dom: wrapper,\n destroy() {\n wrapper.removeEventListener('click', handleClick)\n },\n }\n }\n },\n})\n","import { Math } from './mathematics.js'\n\nexport * from './extensions/index.js'\nexport * from './mathematics.js'\nexport * from './types.js'\n\nexport default Math\n"],"mappings":";AAAA,SAAS,iBAAiB;;;ACA1B,SAAS,WAAW,iBAAiB,YAAY;AAEjD,OAAO,WAAW;AAoDX,IAAM,YAAY,KAAK,OAAO;AAAA,EACnC,MAAM;AAAA,EAEN,OAAO;AAAA,EAEP,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,SAAS;AAAA,IACX;AAAA,EACF;AAAA,EAEA,gBAAgB;AACd,WAAO;AAAA,MACL,OAAO;AAAA,QACL,SAAS;AAAA,QACT,WAAW,aAAW,QAAQ,aAAa,YAAY;AAAA,QACvD,YAAY,gBAAc;AACxB,iBAAO;AAAA,YACL,cAAc,WAAW;AAAA,UAC3B;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,cACE,aACA,CAAC,EAAE,UAAU,OAAO,MAAM;AACxB,cAAM,EAAE,OAAO,IA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