Skip to content

feat: add support for tiptap / liveblocks comments #1442

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

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 11 additions & 5 deletions packages/core/src/api/nodeConversions/nodeToBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ export function contentNodeToInlineContent<
return;
}

if (
node.type.name !== "link" &&
node.type.name !== "text" &&
inlineContentSchema[node.type.name]
) {
if (node.type.name !== "link" && node.type.name !== "text") {
if (!inlineContentSchema[node.type.name]) {
// eslint-disable-next-line no-console
console.warn("unrecognized inline content type", node.type.name);
return;
}
if (currentContent) {
content.push(currentContent);
currentContent = undefined;
Expand All @@ -130,6 +131,11 @@ export function contentNodeToInlineContent<
} else {
const config = styleSchema[mark.type.name];
if (!config) {
if (mark.type.spec.blocknoteIgnore) {
// at this point, we don't want to show certain marks (such as comments)
// in the BlockNote JSON output. These marks should be tagged with "blocknoteIgnore" in the spec
continue;
}
throw new Error(`style ${mark.type.name} not found in styleSchema`);
}
if (config.propSchema === "boolean") {
Expand Down
15 changes: 12 additions & 3 deletions packages/core/src/editor/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ export class BlockNoteEditor<
this.resolveFileUrl = newOptions.resolveFileUrl;
this.headless = newOptions._headless;

if (newOptions.collaboration && newOptions.initialContent) {
const collaborationEnabled =
"collaboration" in this.extensions ||
"liveblocksExtension" in this.extensions;

if (collaborationEnabled && newOptions.initialContent) {
// eslint-disable-next-line no-console
console.warn(
"When using Collaboration, initialContent might cause conflicts, because changes should come from the collaboration provider"
Expand All @@ -498,7 +502,7 @@ export class BlockNoteEditor<

const initialContent =
newOptions.initialContent ||
(options.collaboration
(collaborationEnabled
? [
{
type: "paragraph",
Expand Down Expand Up @@ -930,7 +934,12 @@ export class BlockNoteEditor<
for (const mark of marks) {
const config = this.schema.styleSchema[mark.type.name];
if (!config) {
if (mark.type.name !== "link") {
if (
// Links are not considered styles in blocknote
mark.type.name !== "link" &&
// "blocknoteIgnore" tagged marks (such as comments) are also not considered BlockNote "styles"
!mark.type.spec.blocknoteIgnore
) {
// eslint-disable-next-line no-console
console.warn("mark not found in styleschema", mark.type.name);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ export const ar: Dictionary = {
align_justify: {
tooltip: "ضبط النص",
},
comment: {
tooltip: "إضافة ملاحظة",
},
},
file_panel: {
upload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ export const de = {
align_justify: {
tooltip: "Text Blocksatz",
},
comment: {
tooltip: "Kommentar hinzufügen",
},
},
file_panel: {
upload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ export const en = {
align_justify: {
tooltip: "Justify text",
},
comment: {
tooltip: "Add comment",
},
},
file_panel: {
upload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ export const es = {
align_justify: {
tooltip: "Justificar texto",
},
comment: {
tooltip: "Agregar comentario",
},
},
file_panel: {
upload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ export const fr: Dictionary = {
align_justify: {
tooltip: "Justifier le texte",
},
comment: {
tooltip: "Ajouter un commentaire",
},
},
file_panel: {
upload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/hr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export const hr = {
align_justify: {
tooltip: "Poravnaj tekst obostrano",
},
comment: {
tooltip: "Dodaj komentar",
},
},
file_panel: {
upload: {
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/i18n/locales/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ export const is: Dictionary = {
align_justify: {
tooltip: "Jafna texta",
},
comment: {
tooltip: "Bæta við athugun",
},
},
file_panel: {
upload: {
Expand Down
Loading
Loading