Skip to content

Commit 40eba12

Browse files
committed
Merge remote-tracking branch 'TypeCellOS/main' into refactor/tables-customelements-copypaste
2 parents 8047945 + ef11604 commit 40eba12

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/extensions/UniqueID/UniqueID.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,33 @@ const UniqueID = Extension.create({
172172
? void 0
173173
: _a.attrs[attributeName];
174174
if (id === null) {
175+
// edge case, when using collaboration, yjs will set the id to null in `_forceRerender`
176+
// when loading the editor
177+
// this checks for this case and keeps it at initialBlockId so there will be no change
178+
const initialDoc = oldState.doc.type.createAndFill()!.content;
179+
const wasInitial =
180+
oldState.doc.content.findDiffStart(initialDoc) === null;
181+
182+
if (wasInitial) {
183+
// the old state was the "initial content"
184+
const jsonNode = JSON.parse(
185+
JSON.stringify(newState.doc.toJSON())
186+
);
187+
jsonNode.content[0].content[0].attrs.id = "initialBlockId";
188+
// would the new state with the fix also be the "initial content"?
189+
if (
190+
JSON.stringify(jsonNode.content) ===
191+
JSON.stringify(initialDoc.toJSON())
192+
) {
193+
// yes, apply the fix
194+
tr.setNodeMarkup(pos, undefined, {
195+
...node.attrs,
196+
[attributeName]: "initialBlockId",
197+
});
198+
return;
199+
}
200+
}
201+
175202
tr.setNodeMarkup(pos, undefined, {
176203
...node.attrs,
177204
[attributeName]: generateID(),
@@ -285,5 +312,5 @@ const UniqueID = Extension.create({
285312
},
286313
});
287314

288-
export { UniqueID, UniqueID as default };
315+
export { UniqueID as default, UniqueID };
289316
//# sourceMappingURL=tiptap-extension-unique-id.esm.js.map

packages/website/docs/.vitepress/theme/components/Examples/BlockNote/ReactBlockNote.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export function ReactBlockNote(props: { theme: "light" | "dark" }) {
4545
const doc = new Y.Doc();
4646
const provider = new YPartyKitProvider(
4747
"blocknote.yousefed.partykit.dev",
48-
"homepage-1",
48+
// "127.0.0.1:1999", // (dev server)
49+
"homepage-2",
4950
doc
5051
);
5152
return [doc, provider];

packages/website/docs/docs/real-time-collaboration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ When a user edits the document, an incremental change (or "update") is captured
5757
For development purposes, you can use our Partykit server to test collaborative features. Replace the `WebrtcProvider` provider in the example below with a `YPartyKitProvider`:
5858

5959
```typescript
60-
// npm install y-partykit@beta
60+
// npm install y-partykit
6161
import YPartyKitProvider from "y-partykit/provider";
6262

6363
const provider = new YPartyKitProvider(

packages/website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@vercel/og": "^0.5.6",
1717
"veaury": "^2.3.12",
1818
"vue-github-button": "^3.1.0",
19-
"y-partykit": "^0.0.0-4d484bc",
19+
"y-partykit": "^0.0.10",
2020
"yjs": "^13.6.1"
2121
},
2222
"devDependencies": {

packages/website/partykitserver.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
import type { PartyKitServer } from "partykit/server";
1+
import type * as Party from "partykit/server";
22
import { onConnect } from "y-partykit";
33

4-
// deploy with npx partykit@beta deploy partykitserver.ts --name blocknote
5-
// preview with npx partykit@beta dev partykitserver.ts
6-
export default {
7-
onConnect(ws, room) {
8-
return onConnect(ws, room, { persist: false, gc: true });
9-
},
10-
} satisfies PartyKitServer;
4+
const EXPIRY_PERIOD_MILLISECONDS = 60 * 60 * 1000; // 1 hour
5+
6+
// deploy with npx partykit deploy partykitserver.ts --name blocknote
7+
// preview with npx partykit dev partykitserver.ts
8+
export default class Server implements Party.Server {
9+
constructor(readonly party: Party.Party) {}
10+
11+
onConnect(conn: Party.Connection, ctx: Party.ConnectionContext) {
12+
// A websocket just connected!
13+
14+
return onConnect(conn, this.party, { persist: false, gc: true });
15+
}
16+
17+
async onMessage(message: string) {
18+
// const data = JSON.parse(message);
19+
// do something, and save to storage
20+
// await this.party.storage.put(data.id, data);
21+
// console.log("on message");
22+
await this.party.storage.setAlarm(Date.now() + EXPIRY_PERIOD_MILLISECONDS);
23+
}
24+
25+
async onAlarm() {
26+
// clear all storage in this room
27+
console.log("alarm, delete storage");
28+
await this.party.storage.deleteAll();
29+
}
30+
}
31+
32+
Server satisfies Party.Worker;

0 commit comments

Comments
 (0)