@@ -10,8 +10,8 @@ import {
1010 useBlockNoteContext ,
1111 usePrefersColorScheme ,
1212} from "@blocknote/react" ;
13- import { MantineProvider } from "@mantine/core" ;
14- import React , { useCallback } from "react" ;
13+ import { MantineContext , MantineProvider } from "@mantine/core" ;
14+ import React , { useCallback , useContext } from "react" ;
1515import {
1616 applyBlockNoteCSSVariablesFromTheme ,
1717 removeBlockNoteCSSVariables ,
@@ -20,11 +20,6 @@ import {
2020import { components } from "./components.js" ;
2121import "./style.css" ;
2222
23- const mantineTheme = {
24- // Removes button press effect
25- activeClassName : "" ,
26- } ;
27-
2823export const BlockNoteView = <
2924 BSchema extends BlockSchema ,
3025 ISchema extends InlineContentSchema ,
@@ -76,34 +71,43 @@ export const BlockNoteView = <
7671 [ defaultColorScheme , theme ] ,
7772 ) ;
7873
74+ const mantineContext = useContext ( MantineContext ) ;
75+
7976 const finalTheme =
8077 typeof theme === "string"
8178 ? theme
8279 : defaultColorScheme !== "no-preference"
8380 ? defaultColorScheme
8481 : "light" ;
8582
86- return (
83+ const view = (
8784 < ComponentsContext . Provider value = { components } >
88- < MantineProvider
89- theme = { mantineTheme }
90- // Scopes Mantine CSS variables to only the editor, as proposed here:
91- // https://github.com/orgs/mantinedev/discussions/5685
92- cssVariablesSelector = ".bn-mantine"
93- // This gets the element to set `data-mantine-color-scheme` on. This
94- // element needs to already be rendered, so we can't set it to the
95- // editor container element. Instead, we set it to `undefined` and set it
96- // manually in `BlockNoteViewRaw`.
97- getRootElement = { ( ) => undefined }
98- >
99- < BlockNoteViewRaw
100- data-mantine-color-scheme = { finalTheme }
101- className = { mergeCSSClasses ( "bn-mantine" , className || "" ) }
102- theme = { typeof theme === "object" ? undefined : theme }
103- { ...rest }
104- ref = { ref }
105- />
106- </ MantineProvider >
85+ < BlockNoteViewRaw
86+ data-mantine-color-scheme = { finalTheme }
87+ className = { mergeCSSClasses ( "bn-mantine" , className || "" ) }
88+ theme = { typeof theme === "object" ? undefined : theme }
89+ { ...rest }
90+ ref = { ref }
91+ />
10792 </ ComponentsContext . Provider >
10893 ) ;
94+
95+ if ( mantineContext ) {
96+ return view ;
97+ }
98+
99+ return (
100+ < MantineProvider
101+ // Scopes Mantine CSS variables to only the editor, as proposed here:
102+ // https://github.com/orgs/mantinedev/discussions/5685
103+ cssVariablesSelector = ".bn-mantine"
104+ // This gets the element to set `data-mantine-color-scheme` on. This
105+ // element needs to already be rendered, so we can't set it to the
106+ // editor container element. Instead, we set it to `undefined` and set it
107+ // manually in `BlockNoteViewRaw`.
108+ getRootElement = { ( ) => undefined }
109+ >
110+ { view }
111+ </ MantineProvider >
112+ ) ;
109113} ;
0 commit comments