Skip to content

Commit 56020a3

Browse files
committed
feat: de-couple yjs from blocknote/core
1 parent e62880b commit 56020a3

45 files changed

Lines changed: 357 additions & 358 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/07-collaboration/01-partykit/src/App.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { BlockNoteView } from "@blocknote/mantine";
44
import "@blocknote/mantine/style.css";
55
import YPartyKitProvider from "y-partykit/provider";
66
import * as Y from "yjs";
7+
import { withCollaboration } from "@blocknote/core/yjs";
78

89
// Sets up Yjs document and PartyKit Yjs provider.
910
const doc = new Y.Doc();
@@ -15,19 +16,21 @@ const provider = new YPartyKitProvider(
1516
);
1617

1718
export default function App() {
18-
const editor = useCreateBlockNote({
19-
collaboration: {
20-
// The Yjs Provider responsible for transporting updates:
21-
provider,
22-
// Where to store BlockNote data in the Y.Doc:
23-
fragment: doc.getXmlFragment("document-store"),
24-
// Information (name and color) for this user:
25-
user: {
26-
name: "My Username",
27-
color: "#ff0000",
19+
const editor = useCreateBlockNote(
20+
withCollaboration({
21+
collaboration: {
22+
// The Yjs Provider responsible for transporting updates:
23+
provider,
24+
// Where to store BlockNote data in the Y.Doc:
25+
fragment: doc.getXmlFragment("document-store"),
26+
// Information (name and color) for this user:
27+
user: {
28+
name: "My Username",
29+
color: "#ff0000",
30+
},
2831
},
29-
},
30-
});
32+
}),
33+
);
3134

3235
// Renders the editor instance.
3336
return <BlockNoteView editor={editor} />;

examples/07-collaboration/03-y-sweet/src/App.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useYDoc, useYjsProvider, YDocProvider } from "@y-sweet/react";
44
import { useCreateBlockNote } from "@blocknote/react";
55
import { BlockNoteView } from "@blocknote/mantine";
6+
import { withCollaboration } from "@blocknote/core/yjs";
67

78
import "@blocknote/mantine/style.css";
89

@@ -23,13 +24,15 @@ function Document() {
2324
const provider = useYjsProvider();
2425
const doc = useYDoc();
2526

26-
const editor = useCreateBlockNote({
27-
collaboration: {
28-
provider,
29-
fragment: doc.getXmlFragment("blocknote"),
30-
user: { color: "#ff0000", name: "My Username" },
31-
},
32-
});
27+
const editor = useCreateBlockNote(
28+
withCollaboration({
29+
collaboration: {
30+
provider,
31+
fragment: doc.getXmlFragment("blocknote"),
32+
user: { color: "#ff0000", name: "My Username" },
33+
},
34+
}),
35+
);
3336

3437
return <BlockNoteView editor={editor} />;
3538
}

examples/07-collaboration/05-comments/src/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import {
44
CommentsExtension,
55
DefaultThreadStoreAuth,
6-
YjsThreadStore,
76
} from "@blocknote/core/comments";
7+
import { withCollaboration, YjsThreadStore } from "@blocknote/core/yjs";
8+
89
import { BlockNoteView } from "@blocknote/mantine";
910
import "@blocknote/mantine/style.css";
1011
import { useCreateBlockNote } from "@blocknote/react";
@@ -74,14 +75,14 @@ function Document() {
7475

7576
// setup the editor with comments and collaboration
7677
const editor = useCreateBlockNote(
77-
{
78+
withCollaboration({
7879
collaboration: {
7980
provider,
8081
fragment: doc.getXmlFragment("blocknote"),
8182
user: { color: getRandomColor(), name: activeUser.username },
8283
},
8384
extensions: [CommentsExtension({ threadStore, resolveUsers })],
84-
},
85+
}),
8586
[activeUser, threadStore],
8687
);
8788

examples/07-collaboration/06-comments-with-sidebar/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import {
44
DefaultThreadStoreAuth,
5-
YjsThreadStore,
65
CommentsExtension,
76
} from "@blocknote/core/comments";
7+
import { withCollaboration, YjsThreadStore } from "@blocknote/core/yjs";
88
import { BlockNoteView } from "@blocknote/mantine";
99
import "@blocknote/mantine/style.css";
1010
import {
@@ -77,14 +77,14 @@ export default function App() {
7777

7878
// setup the editor with comments and collaboration
7979
const editor = useCreateBlockNote(
80-
{
80+
withCollaboration({
8181
collaboration: {
8282
provider,
8383
fragment: doc.getXmlFragment("blocknote"),
8484
user: { color: getRandomColor(), name: activeUser.username },
8585
},
8686
extensions: [CommentsExtension({ threadStore, resolveUsers })],
87-
},
87+
}),
8888
[activeUser, threadStore],
8989
);
9090

examples/07-collaboration/07-ghost-writer/src/App.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "@blocknote/core/fonts/inter.css";
22
import "@blocknote/mantine/style.css";
33
import { BlockNoteView } from "@blocknote/mantine";
44
import { useCreateBlockNote } from "@blocknote/react";
5+
import { withCollaboration } from "@blocknote/core/yjs";
56

67
import YPartyKitProvider from "y-partykit/provider";
78
import * as Y from "yjs";
@@ -38,21 +39,23 @@ const ghostContent =
3839
export default function App() {
3940
const [numGhostWriters, setNumGhostWriters] = useState(1);
4041
const [isPaused, setIsPaused] = useState(false);
41-
const editor = useCreateBlockNote({
42-
collaboration: {
43-
// The Yjs Provider responsible for transporting updates:
44-
provider,
45-
// Where to store BlockNote data in the Y.Doc:
46-
fragment: doc.getXmlFragment("document-store"),
47-
// Information (name and color) for this user:
48-
user: {
49-
name: isGhostWriting
50-
? `Ghost Writer #${ghostWriterIndex}`
51-
: "My Username",
52-
color: isGhostWriting ? "#CCCCCC" : "#00ff00",
42+
const editor = useCreateBlockNote(
43+
withCollaboration({
44+
collaboration: {
45+
// The Yjs Provider responsible for transporting updates:
46+
provider,
47+
// Where to store BlockNote data in the Y.Doc:
48+
fragment: doc.getXmlFragment("document-store"),
49+
// Information (name and color) for this user:
50+
user: {
51+
name: isGhostWriting
52+
? `Ghost Writer #${ghostWriterIndex}`
53+
: "My Username",
54+
color: isGhostWriting ? "#CCCCCC" : "#00ff00",
55+
},
5356
},
54-
},
55-
});
57+
}),
58+
);
5659

5760
useEffect(() => {
5861
if (!isGhostWriting || isPaused) {
@@ -101,7 +104,8 @@ export default function App() {
101104
`${window.location.origin}${window.location.pathname}?room=${roomName}&index=-1`,
102105
"_blank",
103106
);
104-
}}>
107+
}}
108+
>
105109
Ghost Writer in a new window
106110
</button>
107111
</>

examples/07-collaboration/08-forking/src/App.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "@blocknote/core/fonts/inter.css";
2-
import {} from "@blocknote/core";
3-
import { ForkYDocExtension } from "@blocknote/core/extensions";
2+
import { ForkYDocExtension, withCollaboration } from "@blocknote/core/yjs";
43
import {
54
useCreateBlockNote,
65
useExtension,
@@ -21,19 +20,21 @@ const provider = new YPartyKitProvider(
2120
);
2221

2322
export default function App() {
24-
const editor = useCreateBlockNote({
25-
collaboration: {
26-
// The Yjs Provider responsible for transporting updates:
27-
provider,
28-
// Where to store BlockNote data in the Y.Doc:
29-
fragment: doc.getXmlFragment("document-store"),
30-
// Information (name and color) for this user:
31-
user: {
32-
name: "My Username",
33-
color: "#ff0000",
23+
const editor = useCreateBlockNote(
24+
withCollaboration({
25+
collaboration: {
26+
// The Yjs Provider responsible for transporting updates:
27+
provider,
28+
// Where to store BlockNote data in the Y.Doc:
29+
fragment: doc.getXmlFragment("document-store"),
30+
// Information (name and color) for this user:
31+
user: {
32+
name: "My Username",
33+
color: "#ff0000",
34+
},
3435
},
35-
},
36-
});
36+
}),
37+
);
3738
const forkYDocPlugin = useExtension(ForkYDocExtension, { editor });
3839
const isForked = useExtensionState(ForkYDocExtension, {
3940
editor,

examples/07-collaboration/09-comments-testing/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import {
44
CommentsExtension,
55
DefaultThreadStoreAuth,
6-
YjsThreadStore,
76
} from "@blocknote/core/comments";
7+
import { YjsThreadStore } from "@blocknote/core/yjs";
88
import { BlockNoteView } from "@blocknote/mantine";
99
import "@blocknote/mantine/style.css";
1010
import { useCreateBlockNote } from "@blocknote/react";

0 commit comments

Comments
 (0)