-
-
Notifications
You must be signed in to change notification settings - Fork 532
/
Copy pathApp.tsx
122 lines (120 loc) · 3.24 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import {
BlockNoteSchema,
combineByGroup,
filterSuggestionItems,
} from "@blocknote/core";
import * as locales from "@blocknote/core/locales";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
SuggestionMenuController,
getDefaultReactSlashMenuItems,
useCreateBlockNote,
} from "@blocknote/react";
import {
getMultiColumnSlashMenuItems,
multiColumnDropCursor,
locales as multiColumnLocales,
withMultiColumn,
} from "@blocknote/xl-multi-column";
import { useMemo } from "react";
export default function App() {
// Creates a new editor instance.
const editor = useCreateBlockNote({
// Adds column and column list blocks to the schema.
schema: withMultiColumn(BlockNoteSchema.create()),
// The default drop cursor only shows up above and below blocks - we replace
// it with the multi-column one that also shows up on the sides of blocks.
dropCursor: multiColumnDropCursor,
// Merges the default dictionary with the multi-column dictionary.
dictionary: {
...locales.en,
multi_column: multiColumnLocales.en,
},
initialContent: [
{
type: "paragraph",
content: "Welcome to this demo!",
},
{
type: "columnList",
children: [
{
type: "column",
props: {
width: 0.8,
},
children: [
{
type: "paragraph",
content: "This paragraph is in a column!",
},
],
},
{
type: "column",
props: {
width: 1.4,
},
children: [
{
type: "heading",
content: "So is this heading!",
},
],
},
{
type: "column",
props: {
width: 0.8,
},
children: [
{
type: "paragraph",
content: "You can have multiple blocks in a column too",
},
{
type: "bulletListItem",
content: "Block 1",
},
{
type: "bulletListItem",
content: "Block 2",
},
{
type: "bulletListItem",
content: "Block 3",
},
],
},
],
},
{
type: "paragraph",
},
],
});
// Gets the default slash menu items merged with the multi-column ones.
const getSlashMenuItems = useMemo(() => {
return async (query: string) =>
filterSuggestionItems(
combineByGroup(
getDefaultReactSlashMenuItems(editor),
getMultiColumnSlashMenuItems(editor)
),
query
);
}, [editor]);
// Renders the editor instance using a React component.
return (
<BlockNoteView editor={editor} slashMenu={false}>
{/* Replaces the default slash menu with one that has both the default
items and the multi-column ones. */}
<SuggestionMenuController
triggerCharacter={"/"}
getItems={getSlashMenuItems}
/>
</BlockNoteView>
);
}