Skip to content
Merged
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
5 changes: 0 additions & 5 deletions examples/editor/src/index.css

This file was deleted.

1 change: 0 additions & 1 deletion examples/editor/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./index.css";

window.React = React;

Expand Down
28 changes: 18 additions & 10 deletions packages/core/src/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,36 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
const tiptapOptions: EditorOptions = {
...blockNoteTipTapOptions,
...newOptions._tiptapOptions,
onCreate: () => {
newOptions.onEditorReady?.(this);
this.ready = true;
},
onBeforeCreate(editor) {
if (!initialContent) {
// when using collaboration
return;
}
// we have to set the initial content here, because now we can use the editor schema
// which has been created at this point
const schema = editor.editor.schema;
const ic = initialContent.map((block) => blockToNode(block, schema));

// We always set the initial content to a single paragraph block. This
// allows us to easily replace it with the actual initial content once
// the TipTap editor is initialized.
const schema = editor.editor.schema;
const root = schema.node(
"doc",
undefined,
schema.node("blockGroup", undefined, ic)
schema.node("blockGroup", undefined, [
blockToNode({ id: "initialBlock", type: "paragraph" }, schema),
])
);
// override the initialcontent
editor.editor.options.content = root.toJSON();
},
onCreate: () => {
// We need to wait for the TipTap editor to init before we can set the
// initial content, as the schema may contain custom blocks which need
// it to render.
if (initialContent !== undefined) {
this.replaceBlocks(this.topLevelBlocks, initialContent);
}

newOptions.onEditorReady?.(this);
this.ready = true;
},
onUpdate: () => {
// This seems to be necessary due to a bug in TipTap:
// https://github.com/ueberdosis/tiptap/issues/2583
Expand Down