-
-
Notifications
You must be signed in to change notification settings - Fork 532
/
Copy pathApp.tsx
90 lines (85 loc) · 2.79 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
import { filterSuggestionItems } from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import {
BlockNoteViewRaw,
getDefaultReactSlashMenuItems,
SideMenuController,
SuggestionMenuController,
useCreateBlockNote,
} from "@blocknote/react";
import "@blocknote/react/style.css";
import { createTheme, ThemeProvider, useMediaQuery } from "@mui/material";
import { useMemo } from "react";
import { schema } from "./schema.js";
import { CustomMUIFormattingToolbar } from "./MUIFormattingToolbar.js";
import { CustomMUISideMenu } from "./MUISideMenu.js";
import { MUISuggestionMenu } from "./MUISuggestionMenu.js";
import "./style.css";
export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
schema,
initialContent: [
{
type: "paragraph",
content: "Welcome to this demo!",
},
{
type: "paragraph",
},
],
});
// Automatically sets light/dark mode based on the user's system preferences.
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
const theme = useMemo(
() =>
createTheme({
palette: {
mode: prefersDarkMode ? "dark" : "light",
},
}),
[prefersDarkMode]
);
// Renders the editor instance.
return (
// Provides theming for Material UI.
<ThemeProvider theme={theme}>
<BlockNoteViewRaw
editor={editor}
// Disables the UI components we'll be replacing.
formattingToolbar={false}
slashMenu={false}
sideMenu={false}
// Disables remaining UI elements.
linkToolbar={false}
filePanel={false}
tableHandles={false}
emojiPicker={false}>
{/* Adds the custom Formatting Toolbar. */}
{/* `FormattingToolbarController isn't used since we make the custom */}
{/* toolbar static and always visible above the editor for this */}
{/* example. */}
<CustomMUIFormattingToolbar />
{/* Adds the custom Side Menu and Slash Menu. */}
{/* These use controllers since we want them to be positioned and */}
{/* show/hide the same as the default ones. */}
<SideMenuController sideMenu={CustomMUISideMenu} />
<SuggestionMenuController
triggerCharacter={"/"}
// We use the default slash menu items but exclude the `Emoji` one as
// we disabled the Emoji Picker.
getItems={async (query) =>
filterSuggestionItems(
getDefaultReactSlashMenuItems(editor).filter(
(item) => item.title !== "Emoji"
),
query
)
}
suggestionMenuComponent={MUISuggestionMenu}
onItemClick={(i) => i.onItemClick()}
/>
</BlockNoteViewRaw>
</ThemeProvider>
);
}