Skip to content

Commit 5de6f84

Browse files
committed
improve(pages): improve math extensions
1 parent 4137bb8 commit 5de6f84

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

apps/client/src/code/tiptap/inline-math/extension.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { VueNodeViewRenderer } from '@tiptap/vue-3';
33

44
import NodeView from './NodeView.vue';
55

6+
declare module '@tiptap/core' {
7+
interface Commands<ReturnType> {
8+
inlineMath: {
9+
addInlineMath: () => ReturnType;
10+
};
11+
}
12+
}
13+
614
export const InlineMathExtension = Node.create({
715
name: 'inlineMath',
816

@@ -41,14 +49,19 @@ export const InlineMathExtension = Node.create({
4149
return VueNodeViewRenderer(NodeView);
4250
},
4351

44-
addCommands(): any {
52+
addCommands() {
4553
return {
4654
addInlineMath:
47-
(options: any) =>
48-
({ commands }: any) =>
55+
() =>
56+
({ commands, state }) =>
4957
commands.insertContent({
5058
type: this.name,
51-
attrs: options,
59+
attrs: {
60+
input: state.doc.textBetween(
61+
state.selection.from,
62+
state.selection.to,
63+
),
64+
},
5265
}),
5366
};
5467
},

apps/client/src/code/tiptap/math-block/extension.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { VueNodeViewRenderer } from '@tiptap/vue-3';
33

44
import NodeView from './NodeView.vue';
55

6+
declare module '@tiptap/core' {
7+
interface Commands<ReturnType> {
8+
mathBlock: {
9+
addMathBlock: () => ReturnType;
10+
};
11+
}
12+
}
13+
614
export const MathBlockExtension = Node.create({
715
name: 'mathBlock',
816

@@ -40,14 +48,19 @@ export const MathBlockExtension = Node.create({
4048
return VueNodeViewRenderer(NodeView);
4149
},
4250

43-
addCommands(): any {
51+
addCommands() {
4452
return {
4553
addMathBlock:
46-
(options: any) =>
47-
({ commands }: any) =>
54+
() =>
55+
({ commands, state }) =>
4856
commands.insertContent({
4957
type: this.name,
50-
attrs: options,
58+
attrs: {
59+
input: state.doc.textBetween(
60+
state.selection.from,
61+
state.selection.to,
62+
),
63+
},
5164
}),
5265
};
5366
},

apps/client/src/layouts/PagesLayout/MainToolbar/ObjectBtns.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
icon="mdi-sigma-lower"
2727
icon-size="24px"
2828
:disable="page.react.readOnly || !page.activeElem.react.exists"
29-
@click="page.selection.format((chain) => (chain as any).addInlineMath())"
29+
@click="page.selection.format((chain) => chain.addInlineMath())"
3030
/>
3131
<ToolbarBtn
3232
:tooltip="`Math block`"
3333
icon="mdi-sigma"
3434
icon-size="24px"
3535
:disable="page.react.readOnly || !page.activeElem.react.exists"
36-
@click="page.selection.format((chain) => (chain as any).addMathBlock())"
36+
@click="page.selection.format((chain) => chain.addMathBlock())"
3737
/>
3838

3939
<q-separator

0 commit comments

Comments
 (0)