Skip to content

Commit 49fa9d7

Browse files
committed
feat: more progress into the version history demo
1 parent 13e2e64 commit 49fa9d7

13 files changed

Lines changed: 791 additions & 521 deletions

File tree

examples/07-collaboration/10-versioning/src/App.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import "@blocknote/core/fonts/inter.css";
2-
import { SuggestionsExtension, VersioningExtension } from "@blocknote/core/y";
2+
import {
3+
withCollaboration,
4+
localStorageEndpoints,
5+
SuggestionsExtension,
6+
VersioningExtension,
7+
} from "@blocknote/core/y";
38
import {
49
BlockNoteViewEditor,
510
FloatingComposerController,
@@ -82,23 +87,18 @@ export default function App() {
8287
);
8388
}, [doc, activeUser]);
8489

85-
const editor = useCreateBlockNote({
86-
collaboration: {
87-
provider,
88-
suggestionDoc: suggestionModeDoc,
89-
attributionManager: suggestionModeAttributionManager,
90-
fragment: doc.get(),
91-
user: { color: getRandomColor(), name: activeUser.username },
92-
},
93-
extensions: [
94-
CommentsExtension({ threadStore, resolveUsers }),
95-
SuggestionsExtension(),
96-
VersioningExtension({
97-
endpoints: {} as any,
90+
const editor = useCreateBlockNote(
91+
withCollaboration({
92+
collaboration: {
93+
provider,
94+
suggestionDoc: suggestionModeDoc,
95+
attributionManager: suggestionModeAttributionManager,
9896
fragment: doc.get(),
99-
}),
100-
],
101-
});
97+
user: { color: getRandomColor(), name: activeUser.username },
98+
versioningEndpoints: localStorageEndpoints,
99+
},
100+
}),
101+
);
102102

103103
const {
104104
enableSuggestions,
@@ -111,8 +111,8 @@ export default function App() {
111111
editor,
112112
});
113113

114-
const { selectSnapshot } = useExtension(VersioningExtension, { editor });
115-
const { selectedSnapshotId } = useExtensionState(VersioningExtension, {
114+
const { exitPreview } = useExtension(VersioningExtension, { editor });
115+
const { previewedSnapshotId } = useExtensionState(VersioningExtension, {
116116
editor,
117117
});
118118

@@ -124,7 +124,7 @@ export default function App() {
124124
disableSuggestions();
125125
setEditingMode("editing");
126126
}
127-
}, [selectedSnapshotId]);
127+
}, [previewedSnapshotId]);
128128
const [sidebar, setSidebar] = useState<
129129
"comments" | "versionHistory" | "none"
130130
>("none");
@@ -134,7 +134,7 @@ export default function App() {
134134
className={"full-collaboration"}
135135
editor={editor}
136136
editable={
137-
(sidebar !== "versionHistory" || selectedSnapshotId === undefined) &&
137+
(sidebar !== "versionHistory" || previewedSnapshotId === undefined) &&
138138
activeUser.role === "editor"
139139
}
140140
// In other examples, `BlockNoteView` renders both editor element itself,
@@ -160,7 +160,7 @@ export default function App() {
160160
setSidebar((sidebar) =>
161161
sidebar !== "versionHistory" ? "versionHistory" : "none",
162162
);
163-
selectSnapshot(undefined);
163+
exitPreview();
164164
}}
165165
>
166166
<RiHistoryLine />
@@ -180,7 +180,7 @@ export default function App() {
180180
</div>
181181
<div className={"editor-section"}>
182182
{/* <h1>Editor</h1> */}
183-
{selectedSnapshotId === undefined && (
183+
{previewedSnapshotId === undefined && (
184184
<div className={"settings"}>
185185
<SettingsSelect
186186
label={"User"}

examples/07-collaboration/11-yhub/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import "./style.css";
12
import "@blocknote/core/fonts/inter.css";
23
import "@blocknote/mantine/style.css";
34
import { BlockNoteView } from "@blocknote/mantine";
45
import { useCreateBlockNote } from "@blocknote/react";
56
import { Awareness } from "@y/protocols/awareness";
67
import { withCollaboration } from "@blocknote/core/y";
78
import * as Y from "@y/y";
8-
import { useEffect } from "react";
99

1010
const doc = new Y.Doc();
1111
const provider = {
@@ -38,7 +38,7 @@ suggestingProvider.awareness.setLocalStateField("user", {
3838
const suggestingAttributionManager = Y.createAttributionManagerFromDiff(
3939
doc,
4040
suggestingDoc,
41-
{ attrs },
41+
// { attrs },
4242
);
4343
suggestingAttributionManager.suggestionMode = false;
4444

@@ -53,7 +53,7 @@ suggestionModeProvider.awareness.setLocalStateField("user", {
5353
const suggestionModeAttributionManager = Y.createAttributionManagerFromDiff(
5454
doc,
5555
suggestionModeDoc,
56-
{ attrs },
56+
// { attrs },
5757
);
5858
suggestionModeAttributionManager.suggestionMode = true;
5959

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ins {
2+
background-color: hsl(120 100 90);
3+
color: hsl(120 100 30);
4+
position: relative;
5+
}
6+
7+
ins:hover::after {
8+
content: attr(data-user);
9+
position: absolute;
10+
top: 100%;
11+
left: 50%;
12+
transform: translateX(-50%);
13+
margin-top: 4px;
14+
padding: 4px 8px;
15+
background-color: rgba(0, 0, 0, 0.9);
16+
color: white;
17+
border-radius: 4px;
18+
font-size: 12px;
19+
white-space: nowrap;
20+
pointer-events: none;
21+
z-index: 1000;
22+
}
23+
24+
.dark ins {
25+
background-color: hsl(120 100 10);
26+
color: hsl(120 80 70);
27+
}
28+
29+
.dark ins:hover::after {
30+
background-color: rgba(30, 30, 30, 0.95);
31+
color: hsl(120 80 70);
32+
border: 1px solid rgba(255, 255, 255, 0.1);
33+
}
34+
35+
del {
36+
background-color: hsl(0 100 90);
37+
color: hsl(0 100 30);
38+
position: relative;
39+
}
40+
41+
del:hover::after {
42+
content: attr(data-user);
43+
position: absolute;
44+
top: 100%;
45+
left: 50%;
46+
transform: translateX(-50%);
47+
margin-top: 4px;
48+
padding: 4px 8px;
49+
background-color: rgba(0, 0, 0, 0.9);
50+
color: white;
51+
border-radius: 4px;
52+
font-size: 12px;
53+
white-space: nowrap;
54+
pointer-events: none;
55+
z-index: 1000;
56+
}
57+
58+
.dark del {
59+
background-color: hsl(0 100 10);
60+
color: hsl(0 80 70);
61+
}
62+
63+
.dark del:hover::after {
64+
background-color: rgba(30, 30, 30, 0.95);
65+
color: hsl(0 80 70);
66+
border: 1px solid rgba(255, 255, 255, 0.1);
67+
}

0 commit comments

Comments
 (0)