Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 21 additions & 31 deletions packages/react/src/editor/BlockNoteView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function BlockNoteViewComponent<
editorProps: {
autoFocus,
contentEditableProps,
editable,
},
defaultUIProps: {
formattingToolbar,
Expand All @@ -185,6 +186,7 @@ function BlockNoteViewComponent<
}, [
autoFocus,
contentEditableProps,
editable,
formattingToolbar,
linkToolbar,
slashMenu,
Expand All @@ -202,7 +204,6 @@ function BlockNoteViewComponent<
<BlockNoteViewContainer
className={className}
renderEditor={renderEditor}
editable={editable}
editorColorScheme={editorColorScheme}
ref={ref}
{...rest}
Expand All @@ -222,34 +223,26 @@ const BlockNoteViewContainer = React.forwardRef<
HTMLDivElement,
{
renderEditor: boolean;
editable?: boolean;
editorColorScheme: "light" | "dark";
children: ReactNode;
} & Omit<
HTMLAttributes<HTMLDivElement>,
"onChange" | "onSelectionChange" | "children"
>
>(
(
{ className, renderEditor, editable, editorColorScheme, children, ...rest },
ref,
) => (
<div
className={mergeCSSClasses("bn-container", editorColorScheme, className)}
data-color-scheme={editorColorScheme}
{...rest}
ref={ref}
>
{renderEditor ? (
<BlockNoteViewEditor editable={editable}>
{children}
</BlockNoteViewEditor>
) : (
children
)}
</div>
),
);
>(({ className, renderEditor, editorColorScheme, children, ...rest }, ref) => (
<div
className={mergeCSSClasses("bn-container", editorColorScheme, className)}
data-color-scheme={editorColorScheme}
{...rest}
ref={ref}
>
{renderEditor ? (
<BlockNoteViewEditor>{children}</BlockNoteViewEditor>
) : (
children
)}
</div>
));

// https://fettblog.eu/typescript-react-generic-forward-refs/
export const BlockNoteViewRaw = React.forwardRef(BlockNoteViewComponent) as <
Expand All @@ -269,10 +262,7 @@ export const BlockNoteViewRaw = React.forwardRef(BlockNoteViewComponent) as <
* Renders the contentEditable editor itself (.bn-editor element) and the
* default UI elements.
*/
export const BlockNoteViewEditor = (props: {
editable?: boolean;
children?: ReactNode;
}) => {
export const BlockNoteViewEditor = (props: { children?: ReactNode }) => {
const ctx = useBlockNoteViewContext()!;
const editor = useBlockNoteEditor();

Expand All @@ -283,10 +273,10 @@ export const BlockNoteViewEditor = (props: {
const mount = useCallback(
(element: HTMLElement | null) => {
if (
props.editable !== undefined &&
props.editable !== editor.isEditable
ctx.editorProps.editable !== undefined &&
ctx.editorProps.editable !== editor.isEditable
) {
editor.isEditable = props.editable;
editor.isEditable = ctx.editorProps.editable;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this is needed, don't we already do this on line 145? Can we find edge-cases why we also need to set this here on mount / why we added it originally?

}
// Since we are not using TipTap's React Components, we need to set up the contentComponent it expects
// This is a simple replacement for the state management that Tiptap does internally
Expand All @@ -297,7 +287,7 @@ export const BlockNoteViewEditor = (props: {
editor.unmount();
}
},
[editor, portalManager, props.editable],
[ctx.editorProps.editable, editor, portalManager],
);

return (
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/editor/BlockNoteViewContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type BlockNoteViewContextValue = {
editorProps: {
autoFocus?: boolean;
contentEditableProps?: Record<string, any>;
editable?: boolean;
};
defaultUIProps: BlockNoteDefaultUIProps;
};
Expand Down
Loading