@@ -13,6 +13,7 @@ import { useCreateBlockNote } from '@blocknote/react';
1313import { HocuspocusProvider } from '@hocuspocus/provider' ;
1414import { useEffect } from 'react' ;
1515import { useTranslation } from 'react-i18next' ;
16+ import { css } from 'styled-components' ;
1617import * as Y from 'yjs' ;
1718
1819import { Box , TextErrors } from '@/components' ;
@@ -33,6 +34,7 @@ import { randomColor } from '../utils';
3334
3435import { BlockNoteSuggestionMenu } from './BlockNoteSuggestionMenu' ;
3536import { BlockNoteToolbar } from './BlockNoteToolBar/BlockNoteToolbar' ;
37+ import { cssComments , useComments } from './comments/' ;
3638import {
3739 AccessibleImageBlock ,
3840 CalloutBlock ,
@@ -80,6 +82,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
8082 const { isEditable, isLoading } = useIsCollaborativeEditable ( doc ) ;
8183 const isConnectedToCollabServer = provider . isSynced ;
8284 const readOnly = ! doc . abilities . partial_update || ! isEditable || isLoading ;
85+ const canSeeComment = doc . abilities . comment ;
8386
8487 useSaveDoc ( doc . id , provider . document , ! readOnly , isConnectedToCollabServer ) ;
8588 const { i18n } = useTranslation ( ) ;
@@ -92,6 +95,8 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
9295 : user ?. full_name || user ?. email || t ( 'Anonymous' ) ;
9396 const showCursorLabels : 'always' | 'activity' | ( string & { } ) = 'activity' ;
9497
98+ const threadStore = useComments ( provider . document , doc , user ) ;
99+
95100 const editor : DocsBlockNoteEditor = useCreateBlockNote (
96101 {
97102 codeBlock,
@@ -144,11 +149,25 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
144149 } ,
145150 showCursorLabels : showCursorLabels as 'always' | 'activity' ,
146151 } ,
152+ comments : { threadStore } ,
147153 dictionary : {
148154 ...locales [ lang as keyof typeof locales ] ,
149155 multi_column :
150156 multiColumnLocales ?. [ lang as keyof typeof multiColumnLocales ] ,
151157 } ,
158+ resolveUsers : async ( userIds ) => {
159+ return Promise . resolve (
160+ userIds . map ( ( encodedURIUserId ) => {
161+ const fullName = decodeURIComponent ( encodedURIUserId ) ;
162+
163+ return {
164+ id : encodedURIUserId ,
165+ username : fullName ,
166+ avatarUrl : 'https://i.pravatar.cc/300' ,
167+ } ;
168+ } ) ,
169+ ) ;
170+ } ,
152171 tables : {
153172 splitCells : true ,
154173 cellBackgroundColor : true ,
@@ -159,7 +178,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
159178 schema : blockNoteSchema ,
160179 dropCursor : multiColumnDropCursor ,
161180 } ,
162- [ collabName , lang , provider , uploadFile ] ,
181+ [ collabName , lang , provider , uploadFile , threadStore ] ,
163182 ) ;
164183
165184 useHeadings ( editor ) ;
@@ -178,7 +197,10 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
178197 < Box
179198 $padding = { { top : 'md' } }
180199 $background = "white"
181- $css = { cssEditor ( readOnly ) }
200+ $css = { css `
201+ ${ cssEditor ( readOnly ) } ;
202+ ${ cssComments ( canSeeComment ) }
203+ ` }
182204 className = "--docs--editor-container"
183205 >
184206 { errorAttachment && (
@@ -192,11 +214,13 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
192214 ) }
193215
194216 < BlockNoteView
217+ className = "--docs--main-editor"
195218 editor = { editor }
196219 formattingToolbar = { false }
197220 slashMenu = { false }
198221 editable = { ! readOnly }
199222 theme = "light"
223+ comments = { canSeeComment }
200224 >
201225 < BlockNoteSuggestionMenu />
202226 < BlockNoteToolbar />
@@ -230,7 +254,12 @@ export const BlockNoteEditorVersion = ({
230254
231255 return (
232256 < Box $css = { cssEditor ( readOnly ) } className = "--docs--editor-container" >
233- < BlockNoteView editor = { editor } editable = { ! readOnly } theme = "light" />
257+ < BlockNoteView
258+ className = "--docs--main-editor"
259+ editor = { editor }
260+ editable = { ! readOnly }
261+ theme = "light"
262+ />
234263 </ Box >
235264 ) ;
236265} ;
0 commit comments