@@ -202,6 +202,7 @@ function BlockNoteViewComponent<
202
202
< BlockNoteViewContainer
203
203
className = { className }
204
204
renderEditor = { renderEditor }
205
+ editable = { editable }
205
206
editorColorScheme = { editorColorScheme }
206
207
ref = { ref }
207
208
{ ...rest }
@@ -221,26 +222,34 @@ const BlockNoteViewContainer = React.forwardRef<
221
222
HTMLDivElement ,
222
223
{
223
224
renderEditor : boolean ;
225
+ editable ?: boolean ;
224
226
editorColorScheme : "light" | "dark" ;
225
227
children : ReactNode ;
226
228
} & Omit <
227
229
HTMLAttributes < HTMLDivElement > ,
228
230
"onChange" | "onSelectionChange" | "children"
229
231
>
230
- > ( ( { className, renderEditor, editorColorScheme, children, ...rest } , ref ) => (
231
- < div
232
- className = { mergeCSSClasses ( "bn-container" , editorColorScheme , className ) }
233
- data-color-scheme = { editorColorScheme }
234
- { ...rest }
235
- ref = { ref }
236
- >
237
- { renderEditor ? (
238
- < BlockNoteViewEditor > { children } </ BlockNoteViewEditor >
239
- ) : (
240
- children
241
- ) }
242
- </ div >
243
- ) ) ;
232
+ > (
233
+ (
234
+ { className, renderEditor, editable, editorColorScheme, children, ...rest } ,
235
+ ref ,
236
+ ) => (
237
+ < div
238
+ className = { mergeCSSClasses ( "bn-container" , editorColorScheme , className ) }
239
+ data-color-scheme = { editorColorScheme }
240
+ { ...rest }
241
+ ref = { ref }
242
+ >
243
+ { renderEditor ? (
244
+ < BlockNoteViewEditor editable = { editable } >
245
+ { children }
246
+ </ BlockNoteViewEditor >
247
+ ) : (
248
+ children
249
+ ) }
250
+ </ div >
251
+ ) ,
252
+ ) ;
244
253
245
254
// https://fettblog.eu/typescript-react-generic-forward-refs/
246
255
export const BlockNoteViewRaw = React . forwardRef ( BlockNoteViewComponent ) as <
@@ -260,7 +269,10 @@ export const BlockNoteViewRaw = React.forwardRef(BlockNoteViewComponent) as <
260
269
* Renders the contentEditable editor itself (.bn-editor element) and the
261
270
* default UI elements.
262
271
*/
263
- export const BlockNoteViewEditor = ( props : { children ?: ReactNode } ) => {
272
+ export const BlockNoteViewEditor = ( props : {
273
+ editable ?: boolean ;
274
+ children ?: ReactNode ;
275
+ } ) => {
264
276
const ctx = useBlockNoteViewContext ( ) ! ;
265
277
const editor = useBlockNoteEditor ( ) ;
266
278
@@ -270,9 +282,15 @@ export const BlockNoteViewEditor = (props: { children?: ReactNode }) => {
270
282
271
283
const mount = useCallback (
272
284
( element : HTMLElement | null ) => {
285
+ if (
286
+ props . editable !== undefined &&
287
+ props . editable !== editor . isEditable
288
+ ) {
289
+ editor . isEditable = props . editable ;
290
+ }
273
291
editor . mount ( element , portalManager ) ;
274
292
} ,
275
- [ editor , portalManager ] ,
293
+ [ editor , portalManager , props . editable ] ,
276
294
) ;
277
295
278
296
return (
0 commit comments