@@ -3,19 +3,21 @@ import { createGroq } from "@ai-sdk/groq";
3
3
import { createMistral } from "@ai-sdk/mistral" ;
4
4
import { createOpenAI } from "@ai-sdk/openai" ;
5
5
import { createOpenAICompatible } from "@ai-sdk/openai-compatible" ;
6
+ import "@mantine/core/styles.css" ;
6
7
import { BlockNoteEditor , filterSuggestionItems } from "@blocknote/core" ;
7
8
import "@blocknote/core/fonts/inter.css" ;
8
9
import { en } from "@blocknote/core/locales" ;
9
10
import { BlockNoteView } from "@blocknote/mantine" ;
10
- import "@mantine/core/styles.css" ;
11
11
import "@blocknote/mantine/style.css" ;
12
12
import {
13
13
FormattingToolbar ,
14
14
FormattingToolbarController ,
15
15
SuggestionMenuController ,
16
16
getDefaultReactSlashMenuItems ,
17
17
getFormattingToolbarItems ,
18
+ useBlockNoteContext ,
18
19
useCreateBlockNote ,
20
+ usePrefersColorScheme ,
19
21
} from "@blocknote/react" ;
20
22
import {
21
23
AIMenuController ,
@@ -136,74 +138,88 @@ export default function App() {
136
138
137
139
const stream = useStore ( ai . options , ( state ) => state . stream ) ;
138
140
141
+ const themePreference = usePrefersColorScheme ( ) ;
142
+ const existingContext = useBlockNoteContext ( ) ;
143
+
144
+ const theme =
145
+ existingContext ?. colorSchemePreference ||
146
+ ( themePreference === "no-preference" ? "light" : themePreference ) ;
147
+
139
148
return (
140
- < MantineProvider >
141
- < div >
142
- < Fieldset legend = "Model settings" style = { { maxWidth : "500px" } } >
143
- < BasicAutocomplete
144
- error = { model === "unknown-model" ? "Unknown model" : undefined }
145
- value = { modelString }
146
- onChange = { setModelString }
147
- />
148
- < RadioGroupComponent
149
- label = "Data format"
150
- items = { [
151
- { name : "HTML" , description : "HTML" , value : "html" } ,
152
- {
153
- name : "JSON" ,
154
- description : "JSON (experimental)" ,
155
- value : "json" ,
156
- } ,
157
- {
158
- name : "Markdown" ,
159
- description : "Markdown (experimental)" ,
160
- value : "markdown" ,
161
- } ,
162
- ] }
163
- value = { dataFormat }
164
- onChange = { ( value ) => {
165
- const dataFormat =
166
- value === "markdown"
167
- ? llmFormats . _experimental_markdown
168
- : value === "json"
169
- ? llmFormats . _experimental_json
170
- : llmFormats . html ;
171
- ai . options . setState ( {
172
- dataFormat,
173
- } ) ;
174
- setDataFormat ( value ) ;
175
- } }
176
- />
177
-
178
- < Switch
179
- checked = { stream }
180
- onChange = { ( e ) => ai . options . setState ( { stream : e . target . checked } ) }
181
- label = "Streaming"
182
- />
183
- </ Fieldset >
184
-
185
- < BlockNoteView
186
- editor = { editor }
187
- formattingToolbar = { false }
188
- slashMenu = { false }
189
- >
190
- { /* Add the AI Command menu to the editor */ }
191
- < AIMenuController />
192
-
193
- { /* We disabled the default formatting toolbar with `formattingToolbar=false`
149
+ < div >
150
+ < MantineProvider
151
+ cssVariablesSelector = ".model-settings"
152
+ getRootElement = { ( ) => undefined }
153
+ >
154
+ < div className = "model-settings" data-mantine-color-scheme = { theme } >
155
+ < Fieldset legend = "Model settings" style = { { maxWidth : "500px" } } >
156
+ < BasicAutocomplete
157
+ error = { model === "unknown-model" ? "Unknown model" : undefined }
158
+ value = { modelString }
159
+ onChange = { setModelString }
160
+ />
161
+ < RadioGroupComponent
162
+ label = "Data format"
163
+ items = { [
164
+ { name : "HTML" , description : "HTML" , value : "html" } ,
165
+ {
166
+ name : "JSON" ,
167
+ description : "JSON (experimental)" ,
168
+ value : "json" ,
169
+ } ,
170
+ {
171
+ name : "Markdown" ,
172
+ description : "Markdown (experimental)" ,
173
+ value : "markdown" ,
174
+ } ,
175
+ ] }
176
+ value = { dataFormat }
177
+ onChange = { ( value ) => {
178
+ const dataFormat =
179
+ value === "markdown"
180
+ ? llmFormats . _experimental_markdown
181
+ : value === "json"
182
+ ? llmFormats . _experimental_json
183
+ : llmFormats . html ;
184
+ ai . options . setState ( {
185
+ dataFormat,
186
+ } ) ;
187
+ setDataFormat ( value ) ;
188
+ } }
189
+ />
190
+
191
+ < Switch
192
+ checked = { stream }
193
+ onChange = { ( e ) =>
194
+ ai . options . setState ( { stream : e . target . checked } )
195
+ }
196
+ label = "Streaming"
197
+ />
198
+ </ Fieldset >
199
+ </ div >
200
+ </ MantineProvider >
201
+
202
+ < BlockNoteView
203
+ editor = { editor }
204
+ formattingToolbar = { false }
205
+ slashMenu = { false }
206
+ >
207
+ { /* Add the AI Command menu to the editor */ }
208
+ < AIMenuController />
209
+
210
+ { /* We disabled the default formatting toolbar with `formattingToolbar=false`
194
211
and replace it for one with an "AI button" (defined below).
195
212
(See "Formatting Toolbar" in docs)
196
213
*/ }
197
- < FormattingToolbarWithAI />
214
+ < FormattingToolbarWithAI />
198
215
199
- { /* We disabled the default SlashMenu with `slashMenu=false`
216
+ { /* We disabled the default SlashMenu with `slashMenu=false`
200
217
and replace it for one with an AI option (defined below).
201
218
(See "Suggestion Menus" in docs)
202
219
*/ }
203
- < SuggestionMenuWithAI editor = { editor } />
204
- </ BlockNoteView >
205
- </ div >
206
- </ MantineProvider >
220
+ < SuggestionMenuWithAI editor = { editor } />
221
+ </ BlockNoteView >
222
+ </ div >
207
223
) ;
208
224
}
209
225
0 commit comments