-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
Copy pathApp.tsx
86 lines (80 loc) · 2.05 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
import {
BlockNoteSchema,
defaultBlockSpecs,
filterSuggestionItems,
insertOrUpdateBlock,
} from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
SuggestionMenuController,
getDefaultReactSlashMenuItems,
useCreateBlockNote,
} from "@blocknote/react";
import { RiFilePdfFill } from "react-icons/ri";
import { PDF } from "./PDF";
// Our schema with block specs, which contain the configs and implementations for blocks
// that we want our editor to use.
const schema = BlockNoteSchema.create({
blockSpecs: {
// Adds all default blocks.
...defaultBlockSpecs,
// Adds the PDF block.
pdf: PDF,
},
});
// Slash menu item to insert a PDF block
const insertPDF = (editor: typeof schema.BlockNoteEditor) => ({
key: "pdf",
title: "PDF",
onItemClick: () => {
insertOrUpdateBlock(editor, {
type: "pdf",
});
},
aliases: ["pdf", "document", "embed", "file"],
group: "Other",
icon: <RiFilePdfFill />,
});
export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
schema,
initialContent: [
{
type: "paragraph",
content: "Welcome to this demo!",
},
{
type: "pdf",
props: {
url: "https://pdfobject.com/pdf/sample.pdf",
},
},
{
type: "paragraph",
content: "Press the '/' key to open the Slash Menu and add another PDF",
},
{
type: "paragraph",
},
],
});
// Renders the editor instance.
return (
<BlockNoteView editor={editor} slashMenu={false}>
{/* Replaces the default Slash Menu. */}
<SuggestionMenuController
triggerCharacter={"/"}
getItems={async (query) =>
// Gets all default slash menu items and `insertPDF` item.
filterSuggestionItems(
[...getDefaultReactSlashMenuItems(editor), insertPDF(editor)],
query
)
}
/>
</BlockNoteView>
);
}