@blocknote/mantine 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/dist/blocknote-mantine.js +1532 -0
- package/dist/blocknote-mantine.js.map +1 -0
- package/dist/blocknote-mantine.umd.cjs +28 -0
- package/dist/blocknote-mantine.umd.cjs.map +1 -0
- package/dist/style.css +1 -0
- package/dist/webpack-stats.json +1 -0
- package/package.json +88 -0
- package/src/BlockNoteTheme.ts +153 -0
- package/src/defaultThemes.ts +159 -0
- package/src/form/TextInput.tsx +44 -0
- package/src/index.tsx +172 -0
- package/src/mantineStyles.css +138 -0
- package/src/menu/Menu.tsx +252 -0
- package/src/panel/Panel.tsx +50 -0
- package/src/panel/PanelButton.tsx +26 -0
- package/src/panel/PanelFileInput.tsx +26 -0
- package/src/panel/PanelTab.tsx +18 -0
- package/src/panel/PanelTextInput.tsx +27 -0
- package/src/popover/Popover.tsx +53 -0
- package/src/sideMenu/SideMenu.tsx +20 -0
- package/src/sideMenu/SideMenuButton.tsx +57 -0
- package/src/style.css +490 -0
- package/src/suggestionMenu/SuggestionMenu.tsx +25 -0
- package/src/suggestionMenu/SuggestionMenuEmptyItem.tsx +22 -0
- package/src/suggestionMenu/SuggestionMenuItem.tsx +47 -0
- package/src/suggestionMenu/SuggestionMenuLabel.tsx +20 -0
- package/src/suggestionMenu/SuggestionMenuLoader.tsx +20 -0
- package/src/tableHandle/TableHandle.tsx +37 -0
- package/src/toolbar/Toolbar.tsx +36 -0
- package/src/toolbar/ToolbarButton.tsx +106 -0
- package/src/toolbar/ToolbarSelect.tsx +69 -0
- package/types/src/BlockNoteTheme.d.ts +33 -0
- package/types/src/defaultThemes.d.ts +143 -0
- package/types/src/form/TextInput.d.ts +13 -0
- package/types/src/index.d.ts +14 -0
- package/types/src/menu/Menu.d.ts +24 -0
- package/types/src/panel/Panel.d.ts +12 -0
- package/types/src/panel/PanelButton.d.ts +11 -0
- package/types/src/panel/PanelFileInput.d.ts +7 -0
- package/types/src/panel/PanelTab.d.ts +5 -0
- package/types/src/panel/PanelTextInput.d.ts +8 -0
- package/types/src/popover/Popover.d.ts +9 -0
- package/types/src/sideMenu/SideMenu.d.ts +5 -0
- package/types/src/sideMenu/SideMenuButton.d.ts +15 -0
- package/types/src/suggestionMenu/SuggestionMenu.d.ts +6 -0
- package/types/src/suggestionMenu/SuggestionMenuEmptyItem.d.ts +5 -0
- package/types/src/suggestionMenu/SuggestionMenuItem.d.ts +8 -0
- package/types/src/suggestionMenu/SuggestionMenuLabel.d.ts +5 -0
- package/types/src/suggestionMenu/SuggestionMenuLoader.d.ts +5 -0
- package/types/src/tableHandle/TableHandle.d.ts +14 -0
- package/types/src/toolbar/Toolbar.d.ts +10 -0
- package/types/src/toolbar/ToolbarButton.d.ts +12 -0
- package/types/src/toolbar/ToolbarSelect.d.ts +12 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export type CombinedColor = Partial<{
|
|
2
|
+
text: string;
|
|
3
|
+
background: string;
|
|
4
|
+
}>;
|
|
5
|
+
|
|
6
|
+
export type ColorScheme = Partial<{
|
|
7
|
+
editor: CombinedColor;
|
|
8
|
+
menu: CombinedColor;
|
|
9
|
+
tooltip: CombinedColor;
|
|
10
|
+
hovered: CombinedColor;
|
|
11
|
+
selected: CombinedColor;
|
|
12
|
+
disabled: CombinedColor;
|
|
13
|
+
shadow: string;
|
|
14
|
+
border: string;
|
|
15
|
+
sideMenu: string;
|
|
16
|
+
highlights: Partial<{
|
|
17
|
+
gray: CombinedColor;
|
|
18
|
+
brown: CombinedColor;
|
|
19
|
+
red: CombinedColor;
|
|
20
|
+
orange: CombinedColor;
|
|
21
|
+
yellow: CombinedColor;
|
|
22
|
+
green: CombinedColor;
|
|
23
|
+
blue: CombinedColor;
|
|
24
|
+
purple: CombinedColor;
|
|
25
|
+
pink: CombinedColor;
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export type Theme = Partial<{
|
|
30
|
+
colors: ColorScheme;
|
|
31
|
+
borderRadius: number;
|
|
32
|
+
fontFamily: string;
|
|
33
|
+
}>;
|
|
34
|
+
|
|
35
|
+
type NestedObject = { [key: string]: number | string | NestedObject };
|
|
36
|
+
|
|
37
|
+
const cssVariablesHelper = (
|
|
38
|
+
theme: Theme,
|
|
39
|
+
editorDOM: HTMLElement,
|
|
40
|
+
unset = false
|
|
41
|
+
) => {
|
|
42
|
+
const result: string[] = [];
|
|
43
|
+
|
|
44
|
+
function traverse(current: NestedObject, currentKey = "--bn") {
|
|
45
|
+
for (const key in current) {
|
|
46
|
+
const kebabCaseKey = key
|
|
47
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
48
|
+
.toLowerCase();
|
|
49
|
+
const fullKey = `${currentKey}-${kebabCaseKey}`;
|
|
50
|
+
|
|
51
|
+
if (typeof current[key] !== "object") {
|
|
52
|
+
// Convert numbers to px
|
|
53
|
+
if (typeof current[key] === "number") {
|
|
54
|
+
current[key] = `${current[key]}px`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (unset) {
|
|
58
|
+
editorDOM.style.removeProperty(fullKey);
|
|
59
|
+
} else {
|
|
60
|
+
editorDOM.style.setProperty(fullKey, current[key].toString());
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
traverse(current[key] as NestedObject, fullKey);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
traverse(theme);
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const applyBlockNoteCSSVariablesFromTheme = (
|
|
74
|
+
theme: Theme,
|
|
75
|
+
editorDOM: HTMLElement
|
|
76
|
+
) => cssVariablesHelper(theme, editorDOM);
|
|
77
|
+
|
|
78
|
+
// We don't need a theme to remove the CSS variables, but having access to a
|
|
79
|
+
// theme object allows us to use the same logic to set/unset them, so this
|
|
80
|
+
// placeholder theme is used.
|
|
81
|
+
const placeholderTheme: Theme = {
|
|
82
|
+
colors: {
|
|
83
|
+
editor: {
|
|
84
|
+
text: undefined as any,
|
|
85
|
+
background: undefined as any,
|
|
86
|
+
},
|
|
87
|
+
menu: {
|
|
88
|
+
text: undefined as any,
|
|
89
|
+
background: undefined as any,
|
|
90
|
+
},
|
|
91
|
+
tooltip: {
|
|
92
|
+
text: undefined as any,
|
|
93
|
+
background: undefined as any,
|
|
94
|
+
},
|
|
95
|
+
hovered: {
|
|
96
|
+
text: undefined as any,
|
|
97
|
+
background: undefined as any,
|
|
98
|
+
},
|
|
99
|
+
selected: {
|
|
100
|
+
text: undefined as any,
|
|
101
|
+
background: undefined as any,
|
|
102
|
+
},
|
|
103
|
+
disabled: {
|
|
104
|
+
text: undefined as any,
|
|
105
|
+
background: undefined as any,
|
|
106
|
+
},
|
|
107
|
+
shadow: undefined as any,
|
|
108
|
+
border: undefined as any,
|
|
109
|
+
sideMenu: undefined as any,
|
|
110
|
+
highlights: {
|
|
111
|
+
gray: {
|
|
112
|
+
text: undefined as any,
|
|
113
|
+
background: undefined as any,
|
|
114
|
+
},
|
|
115
|
+
brown: {
|
|
116
|
+
text: undefined as any,
|
|
117
|
+
background: undefined as any,
|
|
118
|
+
},
|
|
119
|
+
red: {
|
|
120
|
+
text: undefined as any,
|
|
121
|
+
background: undefined as any,
|
|
122
|
+
},
|
|
123
|
+
orange: {
|
|
124
|
+
text: undefined as any,
|
|
125
|
+
background: undefined as any,
|
|
126
|
+
},
|
|
127
|
+
yellow: {
|
|
128
|
+
text: undefined as any,
|
|
129
|
+
background: undefined as any,
|
|
130
|
+
},
|
|
131
|
+
green: {
|
|
132
|
+
text: undefined as any,
|
|
133
|
+
background: undefined as any,
|
|
134
|
+
},
|
|
135
|
+
blue: {
|
|
136
|
+
text: undefined as any,
|
|
137
|
+
background: undefined as any,
|
|
138
|
+
},
|
|
139
|
+
purple: {
|
|
140
|
+
text: undefined as any,
|
|
141
|
+
background: undefined as any,
|
|
142
|
+
},
|
|
143
|
+
pink: {
|
|
144
|
+
text: undefined as any,
|
|
145
|
+
background: undefined as any,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
borderRadius: undefined as any,
|
|
150
|
+
fontFamily: undefined as any,
|
|
151
|
+
};
|
|
152
|
+
export const removeBlockNoteCSSVariables = (editorDOM: HTMLElement) =>
|
|
153
|
+
cssVariablesHelper(placeholderTheme, editorDOM, true);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Theme } from "./BlockNoteTheme";
|
|
2
|
+
|
|
3
|
+
export const defaultColorScheme = [
|
|
4
|
+
"#FFFFFF",
|
|
5
|
+
"#EFEFEF",
|
|
6
|
+
"#CFCFCF",
|
|
7
|
+
"#AFAFAF",
|
|
8
|
+
"#7F7F7F",
|
|
9
|
+
"#3F3F3F",
|
|
10
|
+
"#1F1F1F",
|
|
11
|
+
"#161616",
|
|
12
|
+
"#0F0F0F",
|
|
13
|
+
"#000000",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export const lightDefaultTheme = {
|
|
17
|
+
colors: {
|
|
18
|
+
editor: {
|
|
19
|
+
text: defaultColorScheme[5],
|
|
20
|
+
background: defaultColorScheme[0],
|
|
21
|
+
},
|
|
22
|
+
menu: {
|
|
23
|
+
text: defaultColorScheme[5],
|
|
24
|
+
background: defaultColorScheme[0],
|
|
25
|
+
},
|
|
26
|
+
tooltip: {
|
|
27
|
+
text: defaultColorScheme[5],
|
|
28
|
+
background: defaultColorScheme[1],
|
|
29
|
+
},
|
|
30
|
+
hovered: {
|
|
31
|
+
text: defaultColorScheme[5],
|
|
32
|
+
background: defaultColorScheme[1],
|
|
33
|
+
},
|
|
34
|
+
selected: {
|
|
35
|
+
text: defaultColorScheme[0],
|
|
36
|
+
background: defaultColorScheme[5],
|
|
37
|
+
},
|
|
38
|
+
disabled: {
|
|
39
|
+
text: defaultColorScheme[3],
|
|
40
|
+
background: defaultColorScheme[1],
|
|
41
|
+
},
|
|
42
|
+
shadow: defaultColorScheme[2],
|
|
43
|
+
border: defaultColorScheme[1],
|
|
44
|
+
sideMenu: defaultColorScheme[2],
|
|
45
|
+
highlights: {
|
|
46
|
+
gray: {
|
|
47
|
+
text: "#9b9a97",
|
|
48
|
+
background: "#ebeced",
|
|
49
|
+
},
|
|
50
|
+
brown: {
|
|
51
|
+
text: "#64473a",
|
|
52
|
+
background: "#e9e5e3",
|
|
53
|
+
},
|
|
54
|
+
red: {
|
|
55
|
+
text: "#e03e3e",
|
|
56
|
+
background: "#fbe4e4",
|
|
57
|
+
},
|
|
58
|
+
orange: {
|
|
59
|
+
text: "#d9730d",
|
|
60
|
+
background: "#f6e9d9",
|
|
61
|
+
},
|
|
62
|
+
yellow: {
|
|
63
|
+
text: "#dfab01",
|
|
64
|
+
background: "#fbf3db",
|
|
65
|
+
},
|
|
66
|
+
green: {
|
|
67
|
+
text: "#4d6461",
|
|
68
|
+
background: "#ddedea",
|
|
69
|
+
},
|
|
70
|
+
blue: {
|
|
71
|
+
text: "#0b6e99",
|
|
72
|
+
background: "#ddebf1",
|
|
73
|
+
},
|
|
74
|
+
purple: {
|
|
75
|
+
text: "#6940a5",
|
|
76
|
+
background: "#eae4f2",
|
|
77
|
+
},
|
|
78
|
+
pink: {
|
|
79
|
+
text: "#ad1a72",
|
|
80
|
+
background: "#f4dfeb",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
borderRadius: 6,
|
|
85
|
+
fontFamily:
|
|
86
|
+
'"Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Open Sans", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif',
|
|
87
|
+
} satisfies Theme;
|
|
88
|
+
|
|
89
|
+
export const darkDefaultTheme = {
|
|
90
|
+
colors: {
|
|
91
|
+
editor: {
|
|
92
|
+
text: defaultColorScheme[2],
|
|
93
|
+
background: defaultColorScheme[6],
|
|
94
|
+
},
|
|
95
|
+
menu: {
|
|
96
|
+
text: defaultColorScheme[2],
|
|
97
|
+
background: defaultColorScheme[6],
|
|
98
|
+
},
|
|
99
|
+
tooltip: {
|
|
100
|
+
text: defaultColorScheme[2],
|
|
101
|
+
background: defaultColorScheme[7],
|
|
102
|
+
},
|
|
103
|
+
hovered: {
|
|
104
|
+
text: defaultColorScheme[2],
|
|
105
|
+
background: defaultColorScheme[7],
|
|
106
|
+
},
|
|
107
|
+
selected: {
|
|
108
|
+
text: defaultColorScheme[2],
|
|
109
|
+
background: defaultColorScheme[8],
|
|
110
|
+
},
|
|
111
|
+
disabled: {
|
|
112
|
+
text: defaultColorScheme[5],
|
|
113
|
+
background: defaultColorScheme[7],
|
|
114
|
+
},
|
|
115
|
+
shadow: defaultColorScheme[8],
|
|
116
|
+
border: defaultColorScheme[7],
|
|
117
|
+
sideMenu: defaultColorScheme[4],
|
|
118
|
+
highlights: {
|
|
119
|
+
gray: {
|
|
120
|
+
text: "#bebdb8",
|
|
121
|
+
background: "#9b9a97",
|
|
122
|
+
},
|
|
123
|
+
brown: {
|
|
124
|
+
text: "#8e6552",
|
|
125
|
+
background: "#64473a",
|
|
126
|
+
},
|
|
127
|
+
red: {
|
|
128
|
+
text: "#ec4040",
|
|
129
|
+
background: "#be3434",
|
|
130
|
+
},
|
|
131
|
+
orange: {
|
|
132
|
+
text: "#e3790d",
|
|
133
|
+
background: "#b7600a",
|
|
134
|
+
},
|
|
135
|
+
yellow: {
|
|
136
|
+
text: "#dfab01",
|
|
137
|
+
background: "#b58b00",
|
|
138
|
+
},
|
|
139
|
+
green: {
|
|
140
|
+
text: "#6b8b87",
|
|
141
|
+
background: "#4d6461",
|
|
142
|
+
},
|
|
143
|
+
blue: {
|
|
144
|
+
text: "#0e87bc",
|
|
145
|
+
background: "#0b6e99",
|
|
146
|
+
},
|
|
147
|
+
purple: {
|
|
148
|
+
text: "#8552d7",
|
|
149
|
+
background: "#6940a5",
|
|
150
|
+
},
|
|
151
|
+
pink: {
|
|
152
|
+
text: "#da208f",
|
|
153
|
+
background: "#ad1a72",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
borderRadius: lightDefaultTheme.borderRadius,
|
|
158
|
+
fontFamily: lightDefaultTheme.fontFamily,
|
|
159
|
+
} satisfies Theme;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as Mantine from "@mantine/core";
|
|
2
|
+
|
|
3
|
+
import { assertEmpty } from "@blocknote/core";
|
|
4
|
+
import { ComponentProps } from "@blocknote/react";
|
|
5
|
+
import { forwardRef } from "react";
|
|
6
|
+
|
|
7
|
+
export const TextInput = forwardRef<
|
|
8
|
+
HTMLInputElement,
|
|
9
|
+
ComponentProps["Generic"]["Form"]["TextInput"]
|
|
10
|
+
>((props, ref) => {
|
|
11
|
+
const {
|
|
12
|
+
className,
|
|
13
|
+
name,
|
|
14
|
+
label,
|
|
15
|
+
icon,
|
|
16
|
+
value,
|
|
17
|
+
autoFocus,
|
|
18
|
+
placeholder,
|
|
19
|
+
onKeyDown,
|
|
20
|
+
onChange,
|
|
21
|
+
onSubmit,
|
|
22
|
+
...rest
|
|
23
|
+
} = props;
|
|
24
|
+
|
|
25
|
+
assertEmpty(rest);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Mantine.TextInput
|
|
29
|
+
size={"xs"}
|
|
30
|
+
className={className}
|
|
31
|
+
ref={ref}
|
|
32
|
+
name={name}
|
|
33
|
+
label={label}
|
|
34
|
+
leftSection={icon}
|
|
35
|
+
value={value}
|
|
36
|
+
autoFocus={autoFocus}
|
|
37
|
+
data-autofocus={autoFocus ? "true" : undefined}
|
|
38
|
+
placeholder={placeholder}
|
|
39
|
+
onKeyDown={onKeyDown}
|
|
40
|
+
onChange={onChange}
|
|
41
|
+
onSubmit={onSubmit}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
});
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { BlockSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
|
|
2
|
+
import {
|
|
3
|
+
BlockNoteViewRaw,
|
|
4
|
+
Components,
|
|
5
|
+
ComponentsContext,
|
|
6
|
+
useBlockNoteContext,
|
|
7
|
+
} from "@blocknote/react";
|
|
8
|
+
import { MantineProvider } from "@mantine/core";
|
|
9
|
+
import { ComponentProps, useCallback } from "react";
|
|
10
|
+
import usePrefersColorScheme from "use-prefers-color-scheme";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
Theme,
|
|
14
|
+
applyBlockNoteCSSVariablesFromTheme,
|
|
15
|
+
removeBlockNoteCSSVariables,
|
|
16
|
+
} from "./BlockNoteTheme";
|
|
17
|
+
import { TextInput } from "./form/TextInput";
|
|
18
|
+
import {
|
|
19
|
+
Menu,
|
|
20
|
+
MenuDivider,
|
|
21
|
+
MenuDropdown,
|
|
22
|
+
MenuItem,
|
|
23
|
+
MenuLabel,
|
|
24
|
+
MenuTrigger,
|
|
25
|
+
} from "./menu/Menu";
|
|
26
|
+
import { Panel } from "./panel/Panel";
|
|
27
|
+
import { PanelButton } from "./panel/PanelButton";
|
|
28
|
+
import { PanelFileInput } from "./panel/PanelFileInput";
|
|
29
|
+
import { PanelTab } from "./panel/PanelTab";
|
|
30
|
+
import { PanelTextInput } from "./panel/PanelTextInput";
|
|
31
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover/Popover";
|
|
32
|
+
import { SideMenu } from "./sideMenu/SideMenu";
|
|
33
|
+
import { SideMenuButton } from "./sideMenu/SideMenuButton";
|
|
34
|
+
import { SuggestionMenu } from "./suggestionMenu/SuggestionMenu";
|
|
35
|
+
import { SuggestionMenuEmptyItem } from "./suggestionMenu/SuggestionMenuEmptyItem";
|
|
36
|
+
import { SuggestionMenuItem } from "./suggestionMenu/SuggestionMenuItem";
|
|
37
|
+
import { SuggestionMenuLabel } from "./suggestionMenu/SuggestionMenuLabel";
|
|
38
|
+
import { SuggestionMenuLoader } from "./suggestionMenu/SuggestionMenuLoader";
|
|
39
|
+
import { TableHandle } from "./tableHandle/TableHandle";
|
|
40
|
+
import { Toolbar } from "./toolbar/Toolbar";
|
|
41
|
+
import { ToolbarButton } from "./toolbar/ToolbarButton";
|
|
42
|
+
import { ToolbarSelect } from "./toolbar/ToolbarSelect";
|
|
43
|
+
|
|
44
|
+
import "./style.css";
|
|
45
|
+
|
|
46
|
+
export * from "./BlockNoteTheme";
|
|
47
|
+
export * from "./defaultThemes";
|
|
48
|
+
|
|
49
|
+
export const components: Components = {
|
|
50
|
+
FormattingToolbar: {
|
|
51
|
+
Root: Toolbar,
|
|
52
|
+
Button: ToolbarButton,
|
|
53
|
+
Select: ToolbarSelect,
|
|
54
|
+
},
|
|
55
|
+
ImagePanel: {
|
|
56
|
+
Root: Panel,
|
|
57
|
+
Button: PanelButton,
|
|
58
|
+
FileInput: PanelFileInput,
|
|
59
|
+
TabPanel: PanelTab,
|
|
60
|
+
TextInput: PanelTextInput,
|
|
61
|
+
},
|
|
62
|
+
LinkToolbar: {
|
|
63
|
+
Root: Toolbar,
|
|
64
|
+
Button: ToolbarButton,
|
|
65
|
+
},
|
|
66
|
+
SideMenu: {
|
|
67
|
+
Root: SideMenu,
|
|
68
|
+
Button: SideMenuButton,
|
|
69
|
+
},
|
|
70
|
+
SuggestionMenu: {
|
|
71
|
+
Root: SuggestionMenu,
|
|
72
|
+
Item: SuggestionMenuItem,
|
|
73
|
+
EmptyItem: SuggestionMenuEmptyItem,
|
|
74
|
+
Label: SuggestionMenuLabel,
|
|
75
|
+
Loader: SuggestionMenuLoader,
|
|
76
|
+
},
|
|
77
|
+
TableHandle: {
|
|
78
|
+
Root: TableHandle,
|
|
79
|
+
},
|
|
80
|
+
Generic: {
|
|
81
|
+
Form: {
|
|
82
|
+
Root: (props) => <div>{props.children}</div>,
|
|
83
|
+
TextInput: TextInput,
|
|
84
|
+
},
|
|
85
|
+
Menu: {
|
|
86
|
+
Root: Menu,
|
|
87
|
+
Trigger: MenuTrigger,
|
|
88
|
+
Dropdown: MenuDropdown,
|
|
89
|
+
Divider: MenuDivider,
|
|
90
|
+
Label: MenuLabel,
|
|
91
|
+
Item: MenuItem,
|
|
92
|
+
},
|
|
93
|
+
Popover: {
|
|
94
|
+
Root: Popover,
|
|
95
|
+
Trigger: PopoverTrigger,
|
|
96
|
+
Content: PopoverContent,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const mantineTheme = {
|
|
102
|
+
// Removes button press effect
|
|
103
|
+
activeClassName: "",
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const BlockNoteView = <
|
|
107
|
+
BSchema extends BlockSchema,
|
|
108
|
+
ISchema extends InlineContentSchema,
|
|
109
|
+
SSchema extends StyleSchema
|
|
110
|
+
>(
|
|
111
|
+
props: Omit<
|
|
112
|
+
ComponentProps<typeof BlockNoteViewRaw<BSchema, ISchema, SSchema>>,
|
|
113
|
+
"theme"
|
|
114
|
+
> & {
|
|
115
|
+
theme?:
|
|
116
|
+
| "light"
|
|
117
|
+
| "dark"
|
|
118
|
+
| Theme
|
|
119
|
+
| {
|
|
120
|
+
light: Theme;
|
|
121
|
+
dark: Theme;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
) => {
|
|
125
|
+
const { theme, ...rest } = props;
|
|
126
|
+
|
|
127
|
+
const existingContext = useBlockNoteContext();
|
|
128
|
+
const systemColorScheme = usePrefersColorScheme();
|
|
129
|
+
const defaultColorScheme =
|
|
130
|
+
existingContext?.colorSchemePreference || systemColorScheme;
|
|
131
|
+
|
|
132
|
+
const ref = useCallback(
|
|
133
|
+
(node: HTMLDivElement | null) => {
|
|
134
|
+
if (!node) {
|
|
135
|
+
// todo: clean variables?
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
removeBlockNoteCSSVariables(node);
|
|
140
|
+
|
|
141
|
+
if (typeof theme === "object") {
|
|
142
|
+
if ("light" in theme && "dark" in theme) {
|
|
143
|
+
applyBlockNoteCSSVariablesFromTheme(
|
|
144
|
+
theme[defaultColorScheme === "dark" ? "dark" : "light"],
|
|
145
|
+
node
|
|
146
|
+
);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
applyBlockNoteCSSVariablesFromTheme(theme, node);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
[defaultColorScheme, theme]
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return (
|
|
158
|
+
<ComponentsContext.Provider value={components}>
|
|
159
|
+
{/* `cssVariablesSelector` scopes Mantine CSS variables to only the editor, */}
|
|
160
|
+
{/* as proposed here: https://github.com/orgs/mantinedev/discussions/5685 */}
|
|
161
|
+
<MantineProvider
|
|
162
|
+
theme={mantineTheme}
|
|
163
|
+
cssVariablesSelector=".bn-container">
|
|
164
|
+
<BlockNoteViewRaw
|
|
165
|
+
theme={typeof theme === "object" ? undefined : theme}
|
|
166
|
+
{...rest}
|
|
167
|
+
ref={ref}
|
|
168
|
+
/>
|
|
169
|
+
</MantineProvider>
|
|
170
|
+
</ComponentsContext.Provider>
|
|
171
|
+
);
|
|
172
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/* Based on https://github.com/orgs/mantinedev/discussions/5685 */
|
|
2
|
+
|
|
3
|
+
/* We need all the Mantine styles except the global styles, so unfortunately our
|
|
4
|
+
only option is to import all the component styles separately. Could consider
|
|
5
|
+
importing only styles for components used in BlockNote in the future. */
|
|
6
|
+
/* Files list: https://mantine.dev/styles/css-files-list/ */
|
|
7
|
+
@import url("@mantine/core/styles/ScrollArea.css");
|
|
8
|
+
@import url("@mantine/core/styles/UnstyledButton.css");
|
|
9
|
+
@import url("@mantine/core/styles/VisuallyHidden.css");
|
|
10
|
+
@import url("@mantine/core/styles/Paper.css");
|
|
11
|
+
@import url("@mantine/core/styles/Popover.css");
|
|
12
|
+
@import url("@mantine/core/styles/CloseButton.css");
|
|
13
|
+
@import url("@mantine/core/styles/Group.css");
|
|
14
|
+
@import url("@mantine/core/styles/Loader.css");
|
|
15
|
+
@import url("@mantine/core/styles/Overlay.css");
|
|
16
|
+
@import url("@mantine/core/styles/ModalBase.css");
|
|
17
|
+
@import url("@mantine/core/styles/Input.css");
|
|
18
|
+
@import url("@mantine/core/styles/Flex.css");
|
|
19
|
+
|
|
20
|
+
@import url("@mantine/core/styles/Accordion.css");
|
|
21
|
+
@import url("@mantine/core/styles/ActionIcon.css");
|
|
22
|
+
@import url("@mantine/core/styles/Affix.css");
|
|
23
|
+
@import url("@mantine/core/styles/Alert.css");
|
|
24
|
+
@import url("@mantine/core/styles/Anchor.css");
|
|
25
|
+
@import url("@mantine/core/styles/AspectRatio.css");
|
|
26
|
+
@import url("@mantine/core/styles/AppShell.css");
|
|
27
|
+
@import url("@mantine/core/styles/Avatar.css");
|
|
28
|
+
@import url("@mantine/core/styles/Badge.css");
|
|
29
|
+
@import url("@mantine/core/styles/BackgroundImage.css");
|
|
30
|
+
@import url("@mantine/core/styles/Blockquote.css");
|
|
31
|
+
@import url("@mantine/core/styles/Breadcrumbs.css");
|
|
32
|
+
@import url("@mantine/core/styles/Button.css");
|
|
33
|
+
@import url("@mantine/core/styles/Burger.css");
|
|
34
|
+
@import url("@mantine/core/styles/Card.css");
|
|
35
|
+
@import url("@mantine/core/styles/Center.css");
|
|
36
|
+
@import url("@mantine/core/styles/Checkbox.css");
|
|
37
|
+
@import url("@mantine/core/styles/Chip.css");
|
|
38
|
+
@import url("@mantine/core/styles/Code.css");
|
|
39
|
+
@import url("@mantine/core/styles/ColorInput.css");
|
|
40
|
+
@import url("@mantine/core/styles/ColorPicker.css");
|
|
41
|
+
@import url("@mantine/core/styles/ColorSwatch.css");
|
|
42
|
+
@import url("@mantine/core/styles/Combobox.css");
|
|
43
|
+
@import url("@mantine/core/styles/Container.css");
|
|
44
|
+
@import url("@mantine/core/styles/Dialog.css");
|
|
45
|
+
@import url("@mantine/core/styles/Divider.css");
|
|
46
|
+
@import url("@mantine/core/styles/Drawer.css");
|
|
47
|
+
@import url("@mantine/core/styles/Fieldset.css");
|
|
48
|
+
@import url("@mantine/core/styles/Grid.css");
|
|
49
|
+
@import url("@mantine/core/styles/Image.css");
|
|
50
|
+
@import url("@mantine/core/styles/Indicator.css");
|
|
51
|
+
@import url("@mantine/core/styles/InlineInput.css");
|
|
52
|
+
@import url("@mantine/core/styles/Kbd.css");
|
|
53
|
+
@import url("@mantine/core/styles/List.css");
|
|
54
|
+
@import url("@mantine/core/styles/LoadingOverlay.css");
|
|
55
|
+
@import url("@mantine/core/styles/Mark.css");
|
|
56
|
+
@import url("@mantine/core/styles/Menu.css");
|
|
57
|
+
@import url("@mantine/core/styles/Modal.css");
|
|
58
|
+
@import url("@mantine/core/styles/NavLink.css");
|
|
59
|
+
@import url("@mantine/core/styles/Notification.css");
|
|
60
|
+
@import url("@mantine/core/styles/NumberInput.css");
|
|
61
|
+
@import url("@mantine/core/styles/Pagination.css");
|
|
62
|
+
@import url("@mantine/core/styles/Pill.css");
|
|
63
|
+
@import url("@mantine/core/styles/PasswordInput.css");
|
|
64
|
+
@import url("@mantine/core/styles/PillsInput.css");
|
|
65
|
+
@import url("@mantine/core/styles/PinInput.css");
|
|
66
|
+
@import url("@mantine/core/styles/Progress.css");
|
|
67
|
+
@import url("@mantine/core/styles/Radio.css");
|
|
68
|
+
@import url("@mantine/core/styles/Rating.css");
|
|
69
|
+
@import url("@mantine/core/styles/RingProgress.css");
|
|
70
|
+
@import url("@mantine/core/styles/SegmentedControl.css");
|
|
71
|
+
@import url("@mantine/core/styles/SimpleGrid.css");
|
|
72
|
+
@import url("@mantine/core/styles/Skeleton.css");
|
|
73
|
+
@import url("@mantine/core/styles/Slider.css");
|
|
74
|
+
@import url("@mantine/core/styles/Spoiler.css");
|
|
75
|
+
@import url("@mantine/core/styles/Stack.css");
|
|
76
|
+
@import url("@mantine/core/styles/Stepper.css");
|
|
77
|
+
@import url("@mantine/core/styles/Switch.css");
|
|
78
|
+
@import url("@mantine/core/styles/Table.css");
|
|
79
|
+
@import url("@mantine/core/styles/Tabs.css");
|
|
80
|
+
@import url("@mantine/core/styles/Text.css");
|
|
81
|
+
@import url("@mantine/core/styles/ThemeIcon.css");
|
|
82
|
+
@import url("@mantine/core/styles/Timeline.css");
|
|
83
|
+
@import url("@mantine/core/styles/Title.css");
|
|
84
|
+
@import url("@mantine/core/styles/Tooltip.css");
|
|
85
|
+
@import url("@mantine/core/styles/TypographyStylesProvider.css");
|
|
86
|
+
|
|
87
|
+
/* Mantine global styles, scoped to bn-container */
|
|
88
|
+
/* Based on @mantine/core/styles/global.css
|
|
89
|
+
(src: https://github.com/mantinedev/mantine/blob/master/packages/%40mantine/core/src/core/MantineProvider/global.css)
|
|
90
|
+
but with styles set on `body` and `html` instead set on `bn-container`, as
|
|
91
|
+
well as other minor changes. */
|
|
92
|
+
.bn-container *, .bn-container :after, .bn-container :before {
|
|
93
|
+
box-sizing: border-box
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.bn-container button,
|
|
97
|
+
.bn-container select {
|
|
98
|
+
text-transform: none
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@media screen and (max-device-width: 500px) {
|
|
102
|
+
.bn-container {
|
|
103
|
+
-webkit-text-size-adjust: 100%
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@media (prefers-reduced-motion: reduce) {
|
|
108
|
+
.bn-container [data-respect-reduced-motion] [data-reduce-motion] {
|
|
109
|
+
animation: none;
|
|
110
|
+
transition: none
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.bn-container [data-mantine-color-scheme=dark] .mantine-dark-hidden, .bn-container [data-mantine-color-scheme=light] .mantine-light-hidden {
|
|
115
|
+
display: none
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.bn-container .mantine-focus-auto:focus-visible {
|
|
119
|
+
outline: calc(.125rem * var(--mantine-scale)) solid var(--mantine-primary-color-filled);
|
|
120
|
+
outline-offset: calc(.125rem * var(--mantine-scale))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.bn-container .mantine-focus-always:focus {
|
|
124
|
+
outline: calc(.125rem * var(--mantine-scale)) solid var(--mantine-primary-color-filled);
|
|
125
|
+
outline-offset: calc(.125rem * var(--mantine-scale))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.bn-container .mantine-focus-never:focus {
|
|
129
|
+
outline: none
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.bn-container .mantine-active:active {
|
|
133
|
+
transform: translateY(calc(.0625rem * var(--mantine-scale)))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.bn-container[dir=rtl] .mantine-rotate-rtl {
|
|
137
|
+
transform: rotate(180deg)
|
|
138
|
+
}
|