-
-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy pathApp.tsx
91 lines (86 loc) · 2.27 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import {
BlockNoteSchema,
defaultInlineContentSpecs,
filterSuggestionItems,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import {
SuggestionMenuController,
getDefaultReactSlashMenuItems,
useCreateBlockNote,
} from "@blocknote/react";
import { BlockNoteView } from "@blocknote/mantine";
import { RiFormula } from "react-icons/ri";
import "@blocknote/mantine/style.css";
import { InlineEquation } from "./Equation";
// Our schema with block specs, which contain the configs and implementations for blocks
// that we want our editor to use.
const schema = BlockNoteSchema.create({
inlineContentSpecs: {
...defaultInlineContentSpecs,
inlineEquation: InlineEquation,
},
});
// Slash menu item to insert an Alert block
const insertLaTex = (editor: typeof schema.BlockNoteEditor) => ({
icon: <RiFormula size={18}/>,
title: "Inline Equation",
key: "inlineEquation",
subtext: "Insert mathematical symbols in text.",
aliases: ["equation", "latex", "katex"],
group: "Other",
onItemClick: () => {
const view = editor._tiptapEditor.view;
const pos = editor._tiptapEditor.state.selection.from;
const tr = view.state.tr.insert(
pos,
view.state.schema.nodes.inlineEquation.create(),
);
view.dispatch(tr);
},
});
export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
schema,
initialContent: [
{
type: "paragraph",
content: [
"This is an example inline equation ",
{
type: "inlineEquation",
content: "c = \\pm\\sqrt{a^2 + b^2}",
},
],
},
{
type: "paragraph",
content: "Press the '/' key to open the Slash Menu and add another",
},
{
type: "paragraph",
},
{
type: "paragraph",
},
{
type: "paragraph",
},
],
});
// Renders the editor instance.
return (
<BlockNoteView editor={editor} slashMenu={false}>
<SuggestionMenuController
triggerCharacter={"/"}
getItems={async (query: any) =>
filterSuggestionItems(
[...getDefaultReactSlashMenuItems(editor), insertLaTex(editor)],
query
)
}
/>
</BlockNoteView>
);
}