@@ -46,12 +46,10 @@ import { RiAlertFill } from "react-icons/ri";
4646
4747import { createAlertBlock , insertAlert } from " ./Alert" ;
4848
49- const theme = " light" ;
50-
5149// The custom schema, including all default blocks and the custom Alert block
5250export const schemaWithAlert = {
5351 ... defaultBlockSchema ,
54- alert: createAlertBlock (theme ),
52+ alert: createAlertBlock (" {{ getTheme(isDark) }} " ),
5553};
5654
5755export default function App() {
@@ -64,7 +62,7 @@ export default function App() {
6462 });
6563
6664 return (
67- <BlockNoteView editor = { editor } theme = { theme } >
65+ <BlockNoteView editor = { editor } theme = { " {{ getTheme(isDark) }} " } >
6866 { /* Adds alert item to block type dropdown in the Formatting Toolbar*/ }
6967 <FormattingToolbarPositioner
7068 editor = { editor }
@@ -107,7 +105,6 @@ import {
107105 InlineContent ,
108106 ReactSlashMenuItem ,
109107} from " @blocknote/react" ;
110- import { useState } from " react" ;
111108import { RiAlertFill } from " react-icons/ri" ;
112109import { MdCancel , MdCheckCircle , MdError , MdInfo } from " react-icons/md" ;
113110import { Menu } from " @mantine/core" ;
@@ -161,23 +158,27 @@ export const alertPropSchema = {
161158// Component for the Alert block
162159export const Alert = (props : {
163160 block: SpecificBlock <
164- DefaultBlockSchema & { alert: BlockSpec <" alert" , typeof alertPropSchema > },
161+ DefaultBlockSchema & {
162+ alert: BlockSpec <" alert" , typeof alertPropSchema , true >;
163+ },
165164 " alert"
166165 >;
167166 editor: BlockNoteEditor <
168- DefaultBlockSchema & { alert: BlockSpec <" alert" , typeof alertPropSchema > }
167+ DefaultBlockSchema & {
168+ alert: BlockSpec <" alert" , typeof alertPropSchema , true >;
169+ }
169170 >;
170171 theme: " light" | " dark" ;
171172}) => {
172- const [type, setType] = useState (props .block .props .type );
173- const Icon = alertTypes [type ].icon ;
173+ const Icon = alertTypes [props .block .props .type ].icon ;
174174
175175 return (
176176 < div
177177 className = {" alert" }
178178 style = {{
179179 ... alertStyles ,
180- backgroundColor : alertTypes [type ].backgroundColor [props .theme ],
180+ backgroundColor :
181+ alertTypes [props .block .props .type ].backgroundColor [props .theme ],
181182 }}>
182183 {/* Icon which opens a menu to choose the Alert type*/ }
183184 < Menu zIndex = {99999 }>
@@ -187,13 +188,18 @@ export const Alert = (props: {
187188 className = {" alert-icon-wrapper" }
188189 style = {{
189190 ... alertIconWrapperStyles ,
190- backgroundColor : alertTypes [type ].color ,
191+ backgroundColor : alertTypes [props . block . props . type ].color ,
191192 }}
192193 contentEditable = {false }>
193194 {/* Icon itself*/ }
194195 < Icon
195196 className = {" alert-icon" }
196- style = {{ color : alertTypes [type ].backgroundColor [props .theme ] }}
197+ style = {{
198+ color :
199+ alertTypes [props .block .props .type ].backgroundColor [
200+ props .theme
201+ ],
202+ }}
197203 size = {32 }
198204 / >
199205 < / div >
@@ -204,12 +210,17 @@ export const Alert = (props: {
204210 < Menu .Divider / >
205211 {Object .entries (alertTypes ).map (([key , value ]) = > {
206212 const ItemIcon = value .icon ;
207-
213+
208214 return (
209215 <Menu.Item
210216 key = {key }
211217 icon = {<ItemIcon color = {value.color } / > }
212- onClick = {() => setType(key as keyof typeof alertTypes )}>
218+ onClick = {() =>
219+ props.editor.updateBlock(props.block , {
220+ type : " alert" ,
221+ props : { type : key as keyof typeof alertTypes },
222+ })
223+ }>
213224 {key .slice (0, 1).toUpperCase () + key .slice (1)}
214225 </Menu.Item>
215226 );
@@ -229,7 +240,9 @@ export const createAlertBlock = (theme: "light" | "dark") =>
229240 " alert" ,
230241 typeof alertPropSchema ,
231242 true ,
232- DefaultBlockSchema & { alert : BlockSpec < " alert" , typeof alertPropSchema > }
243+ DefaultBlockSchema & {
244+ alert : BlockSpec < " alert" , typeof alertPropSchema , true > ;
245+ }
233246 > ({
234247 type: " alert" as const ,
235248 propSchema: {
@@ -249,7 +262,7 @@ export const insertAlert = {
249262 name: " Alert" ,
250263 execute : (editor ) => {
251264 const block = editor .getTextCursorPosition ().block ;
252- const blockIsEmpty = block .content .length === 0 ;
265+ const blockIsEmpty = block .content ! .length === 0 ;
253266
254267 // Updates current block to an Alert if it's empty, otherwise inserts a new
255268 // one below
@@ -281,7 +294,9 @@ export const insertAlert = {
281294 icon: <RiAlertFill />,
282295 hint: " Used to emphasize text" ,
283296} satisfies ReactSlashMenuItem <
284- DefaultBlockSchema & { alert: BlockSpec <" alert" , typeof alertPropSchema > }
297+ DefaultBlockSchema & {
298+ alert: BlockSpec <" alert" , typeof alertPropSchema , true >;
299+ }
285300>;
286301
287302const alertStyles = {
0 commit comments