Skip to content

fix: get POC running on the latest version of blocknote again #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
54 changes: 17 additions & 37 deletions hocuspocus-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions hocuspocus-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,37 @@
"clean": "rimraf dist && rimraf types"
},
"dependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0",
"@blocknote/react": "^0.25.0",
"@blocknote/core": "^0.25.0",
"@hono/node-ws": "^1.0.8",
"@blocknote/core": "^0.25.1",
"@blocknote/react": "^0.25.1",
"@blocknote/server-util": "^0.25.0",
"@hocuspocus/extension-sqlite": "^2.15.2",
"@hocuspocus/server": "^2.15.2",
"@hono/node-server": "^1.0.8",
"@hono/node-ws": "^1.0.8",
"@tiptap/core": "2.11.5",
"hono": "^4.7.2",
"@hocuspocus/server": "^2.15.2",
"@hocuspocus/extension-sqlite": "^2.15.2",
"prosemirror-state": "^1.4.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"y-prosemirror": "^1.2.15",
"@blocknote/server-util": "^0.25.0",
"yjs": "^13.6.23",
"prosemirror-state": "^1.4.1"
"yjs": "^13.6.23"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"eslint": "^8.10.0",
"eslint-config-react-app": "^7.0.0",
"eslint-plugin-import": "^2.31.0",
"prettier": "^2.7.1",
"rimraf": "^5.0.5",
"rollup-plugin-webpack-stats": "^0.2.2",
"typescript": "^5.3.3",
"undici": "^6",
"vite": "^5.3.4",
"vite-node": "^2.1.6",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-externalize-deps": "^0.8.0",
"vitest": "^2.0.3",
"undici": "^6",
"@typescript-eslint/eslint-plugin": "^5.5.0",
"@typescript-eslint/parser": "^5.5.0",
"eslint-config-react-app": "^7.0.0",
"eslint-plugin-import": "^2.31.0"
"vitest": "^2.0.3"
},
"eslintConfig": {
"extends": [
Expand Down
71 changes: 70 additions & 1 deletion hocuspocus-server/src/setMark.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ServerBlockNoteEditor } from "@blocknote/server-util";
import { Mark, mergeAttributes } from "@tiptap/core";
import { Document } from "@hocuspocus/server";
import { EditorState, TextSelection } from "prosemirror-state";
import {
Expand All @@ -23,7 +24,75 @@ export function setMark(
) {
// needed to get the pmSchema
// if you use a BlockNote custom schema, make sure to pass it to the create options
const editor = ServerBlockNoteEditor.create();
const editor = ServerBlockNoteEditor.create({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's try with just passing comments to the editor options before merging this, I think that should work right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried this, but it wanted a ydoc I think. Maybe your PR will help this

_extensions: {
// TODO to get this to work, I needed to pass a copy of the comment mark to get it into the schema
comments: Mark.create({
name: "comment",
excludes: "",
inclusive: false,
keepOnSplit: true,
group: "blocknoteIgnore", // ignore in blocknote json
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to figure out what to do about this...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! this was a leftover, it's been fixed already. will make a PR


addAttributes() {
// Return an object with attribute configuration
return {
// orphans are marks that currently don't have an active thread. It could be
// that users have resolved the thread. Resolved threads by default are not shown in the document,
// but we need to keep the mark (positioning) data so we can still "revive" it when the thread is unresolved
// or we enter a "comments" view that includes resolved threads.
orphan: {
parseHTML: (element) => !!element.getAttribute("data-orphan"),
renderHTML: (attributes) => {
return (attributes as { orphan: boolean }).orphan
? {
"data-orphan": "true",
}
: {};
},
default: false,
},
threadId: {
parseHTML: (element) => element.getAttribute("data-bn-thread-id"),
renderHTML: (attributes) => {
return {
"data-bn-thread-id": (attributes as { threadId: string })
.threadId,
};
},
default: "",
},
};
},

renderHTML({
HTMLAttributes,
}: {
HTMLAttributes: Record<string, any>;
}) {
return [
"span",
mergeAttributes(HTMLAttributes, {
class: "bn-thread-mark",
}),
];
},

parseHTML() {
return [{ tag: "span.bn-thread-mark" }];
},

extendMarkSchema(extension) {
if (extension.name === "comment") {
return {
blocknoteIgnore: true,
};
}
return {};
},
}),
},
});

// get the prosemirror document
const { doc: pNode, mapping } = initProseMirrorDoc(
Expand Down
7 changes: 5 additions & 2 deletions hocuspocus-server/src/threads.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DefaultThreadStoreAuth, YjsThreadStore } from "@blocknote/core";
import {
DefaultThreadStoreAuth,
YjsThreadStore,
} from "@blocknote/core/comments";
import { Document } from "@hocuspocus/server";
import { Hono, Next } from "hono";
import { createMiddleware } from "hono/factory";
Expand Down Expand Up @@ -50,7 +53,7 @@ const threadStoreMiddleware = (options: { threadsMapKey: string }) =>
c.get("document").getMap(options.threadsMapKey),
new DefaultThreadStoreAuth(
c.get("userId"),
c.get("role") === "COMMENT-ONLY" ? "commenter" : "editor"
c.get("role") === "COMMENT-ONLY" ? "comment" : "editor"
)
);

Expand Down
2 changes: 1 addition & 1 deletion hocuspocus-server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ESNext", "DOM", "DOM.Iterable"],
"moduleResolution": "Node",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"sourceMap": true,
Expand Down
5 changes: 4 additions & 1 deletion next-app/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use client"; // this registers <Editor> as a Client Component
import { DefaultThreadStoreAuth, RESTYjsThreadStore } from "@blocknote/core";
import {
DefaultThreadStoreAuth,
RESTYjsThreadStore,
} from "@blocknote/core/comments";
import "@blocknote/core/fonts/inter.css";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
Expand Down
49 changes: 25 additions & 24 deletions next-app/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NextConfig } from "next";
import path from "path";

const nextConfig: NextConfig = {
/* config options here */
Expand All @@ -11,31 +12,31 @@ const nextConfig: NextConfig = {
// };

// uncomment to directly load blocknote local blocknote dev
// config.resolve.alias = {
// yjs: path.resolve(__dirname, "./node_modules/yjs"),
// "@blocknote/core/fonts/inter.css": path.resolve(
// __dirname,
// "../../BlockNote/packages/core/src/fonts/inter.css"
// ),
// "@blocknote/mantine/style.css": path.resolve(
// __dirname,
// "../../BlockNote/packages/mantine/dist/style.css"
// ),
config.resolve.alias = {
yjs: path.resolve(__dirname, "./node_modules/yjs"),
// "@blocknote/core/fonts/inter.css": path.resolve(
// __dirname,
// "../../BlockNote/packages/core/src/fonts/inter.css"
// ),
// "@blocknote/mantine/style.css": path.resolve(
// __dirname,
// "../../BlockNote/packages/mantine/dist/style.css"
// ),

// "@blocknote/core": path.resolve(
// __dirname,
// "../../BlockNote/packages/core/"
// ),
// "@blocknote/react": path.resolve(
// __dirname,
// "../../BlockNote/packages/react/"
// ),
// "@blocknote/mantine": path.resolve(
// __dirname,
// "../../BlockNote/packages/mantine/"
// ),
// ...config.resolve.alias,
// };
// "@blocknote/core": path.resolve(
// __dirname,
// "../../BlockNote/packages/core/"
// ),
// "@blocknote/react": path.resolve(
// __dirname,
// "../../BlockNote/packages/react/"
// ),
// "@blocknote/mantine": path.resolve(
// __dirname,
// "../../BlockNote/packages/mantine/"
// ),
...config.resolve.alias,
};

return config;
},
Expand Down
Loading