@@ -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 ,
@@ -79,6 +81,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
7981 const { isEditable, isLoading } = useIsCollaborativeEditable ( doc ) ;
8082 const isConnectedToCollabServer = provider . isSynced ;
8183 const readOnly = ! doc . abilities . partial_update || ! isEditable || isLoading ;
84+ const canSeeComment = doc . abilities . comment ;
8285
8386 useSaveDoc ( doc . id , provider . document , ! readOnly , isConnectedToCollabServer ) ;
8487 const { i18n } = useTranslation ( ) ;
@@ -91,6 +94,8 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
9194 : user ?. full_name || user ?. email || t ( 'Anonymous' ) ;
9295 const showCursorLabels : 'always' | 'activity' | ( string & { } ) = 'activity' ;
9396
97+ const threadStore = useComments ( provider . document , doc , user ) ;
98+
9499 const editor : DocsBlockNoteEditor = useCreateBlockNote (
95100 {
96101 codeBlock,
@@ -143,11 +148,25 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
143148 } ,
144149 showCursorLabels : showCursorLabels as 'always' | 'activity' ,
145150 } ,
151+ comments : { threadStore } ,
146152 dictionary : {
147153 ...locales [ lang as keyof typeof locales ] ,
148154 multi_column :
149155 multiColumnLocales ?. [ lang as keyof typeof multiColumnLocales ] ,
150156 } ,
157+ resolveUsers : async ( userIds ) => {
158+ return Promise . resolve (
159+ userIds . map ( ( encodedURIUserId ) => {
160+ const fullName = decodeURIComponent ( encodedURIUserId ) ;
161+
162+ return {
163+ id : encodedURIUserId ,
164+ username : fullName ,
165+ avatarUrl : 'https://i.pravatar.cc/300' ,
166+ } ;
167+ } ) ,
168+ ) ;
169+ } ,
151170 tables : {
152171 splitCells : true ,
153172 cellBackgroundColor : true ,
@@ -157,7 +176,7 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
157176 uploadFile,
158177 schema : blockNoteSchema ,
159178 } ,
160- [ collabName , lang , provider , uploadFile ] ,
179+ [ collabName , lang , provider , uploadFile , threadStore ] ,
161180 ) ;
162181
163182 useHeadings ( editor ) ;
@@ -176,7 +195,10 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
176195 < Box
177196 $padding = { { top : 'md' } }
178197 $background = "white"
179- $css = { cssEditor ( readOnly ) }
198+ $css = { css `
199+ ${ cssEditor ( readOnly ) } ;
200+ ${ cssComments ( canSeeComment ) }
201+ ` }
180202 className = "--docs--editor-container"
181203 >
182204 { errorAttachment && (
@@ -190,11 +212,13 @@ export const BlockNoteEditor = ({ doc, provider }: BlockNoteEditorProps) => {
190212 ) }
191213
192214 < BlockNoteView
215+ className = "--docs--main-editor"
193216 editor = { editor }
194217 formattingToolbar = { false }
195218 slashMenu = { false }
196219 editable = { ! readOnly }
197220 theme = "light"
221+ comments = { canSeeComment }
198222 >
199223 < BlockNoteSuggestionMenu />
200224 < BlockNoteToolbar />
@@ -228,7 +252,12 @@ export const BlockNoteEditorVersion = ({
228252
229253 return (
230254 < Box $css = { cssEditor ( readOnly ) } className = "--docs--editor-container" >
231- < BlockNoteView editor = { editor } editable = { ! readOnly } theme = "light" />
255+ < BlockNoteView
256+ className = "--docs--main-editor"
257+ editor = { editor }
258+ editable = { ! readOnly }
259+ theme = "light"
260+ />
232261 </ Box >
233262 ) ;
234263} ;
0 commit comments