Skip to content

Commit 2c06a58

Browse files
committed
implement blocknote snapshot for example
1 parent 1e5a6a4 commit 2c06a58

File tree

3 files changed

+91
-77
lines changed

3 files changed

+91
-77
lines changed

example/convex/example.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { getSchema } from "@tiptap/core";
66
import { Transform, Step } from "@tiptap/pm/transform";
77
import { EditorState } from "@tiptap/pm/state";
88
import { extensions } from "../src/extensions";
9+
import { Schema } from "@tiptap/pm/model";
10+
import { BlockNoteEditor } from "@blocknote/core";
911

1012
const prosemirrorSync = new ProsemirrorSync(components.prosemirrorSync);
1113
export const {
@@ -27,10 +29,22 @@ export const {
2729
// ...do something with the snapshot, like store a copy in another table,
2830
// save a text version of the document for text search, or generate
2931
// embeddings for vector search.
30-
const node = getSchema(extensions).nodeFromJSON(JSON.parse(snapshot));
32+
const snapshotJSON = JSON.parse(snapshot);
33+
let schema: Schema;
34+
// A hack for our demo which uses both BlockNote and Tiptap.
35+
if (id.endsWith("-blocknote")) {
36+
// Parse the snapshot from BlockNote.
37+
const editor = BlockNoteEditor.create({ _headless: true });
38+
schema = editor.pmSchema;
39+
} else {
40+
// Fetching the content from Tiptap, using your extensions.
41+
schema = getSchema(extensions);
42+
}
43+
const node = schema.nodeFromJSON(snapshotJSON);
44+
const content = node.textContent;
3145
await ctx.scheduler.runAfter(0, internal.example.updateDocSearchIndex, {
3246
id,
33-
content: node.textContent,
47+
content,
3448
});
3549
},
3650
});

example/package-lock.json

Lines changed: 73 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ function App(props: { id: string }) {
2626
<div className="card">
2727
<strong>{editor}</strong>
2828
{useBlockNote ? (
29-
<BlockNoteExample id={props.id} />
29+
<BlockNoteExample id={props.id + "-blocknote"} />
3030
) : (
31-
<TipTapExample id={props.id} />
31+
<TipTapExample id={props.id + "-tiptap"} />
3232
)}
3333
</div>
3434
<footer>

0 commit comments

Comments
 (0)