Skip to content

Commit

Permalink
add cursors but broken
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <[email protected]>
  • Loading branch information
mattkrick committed Feb 19, 2025
1 parent d6108ac commit 02e131d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
33 changes: 20 additions & 13 deletions packages/client/hooks/useTipTapPageEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {TiptapCollabProvider, TiptapCollabProviderWebsocket} from '@hocuspocus/p
import {SearchAndReplace} from '@sereneinserenade/tiptap-search-and-replace'
import CharacterCount from '@tiptap/extension-character-count'
import Collaboration from '@tiptap/extension-collaboration'
import CollaborationCursor from '@tiptap/extension-collaboration-cursor'
import Document from '@tiptap/extension-document'
import Focus from '@tiptap/extension-focus'
import Mention from '@tiptap/extension-mention'
Expand All @@ -11,7 +12,7 @@ import {TaskList} from '@tiptap/extension-task-list'
import Underline from '@tiptap/extension-underline'
import {generateJSON, generateText, useEditor} from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
import {useEffect, useRef, useState} from 'react'
import {useRef, useState} from 'react'
import * as Y from 'yjs'
import {LoomExtension} from '../components/promptResponse/loomExtension'
import {TiptapLinkExtension} from '../components/promptResponse/TiptapLinkExtension'
Expand Down Expand Up @@ -51,7 +52,7 @@ export const useTipTapPageEditor = (
const {teamId, placeholder} = options
const atmosphere = useAtmosphere()
const {history} = useRouter<{meetingId: string}>()
const [doc] = useState(() => {
const [document] = useState(() => {
const doc = new Y.Doc()
const frag = doc.getXmlFragment('default')
// update the URL to match the title
Expand All @@ -78,6 +79,15 @@ export const useTipTapPageEditor = (
})
const placeholderRef = useRef(placeholder)
placeholderRef.current = placeholder
// Connect to your Collaboration server
const provider = useState(() => {
if (!pageId) return
return new TiptapCollabProvider({
websocketProvider: makeHocusPocusSocket(atmosphere.authToken),
name: `page:${pageId}`,
document
})
})
const editor = useEditor(
{
content: '',
Expand Down Expand Up @@ -122,23 +132,20 @@ export const useTipTapPageEditor = (
limit: 1900
}),
Collaboration.configure({
document: doc // Configure Y.Doc for collaboration
document
}),
CollaborationCursor.configure({
provider,
user: {
name: 'Cyndi Lauper',
color: '#f783ac'
}
})
],
autofocus: true,
editable: true
},
[]
)
// Connect to your Collaboration server
useEffect(() => {
if (!pageId) return
new TiptapCollabProvider({
websocketProvider: makeHocusPocusSocket(atmosphere.authToken),
name: `page:${pageId}`,
document: doc
})
}, [])

return {editor}
}
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@tiptap/core": "^2.11.5",
"@tiptap/extension-character-count": "^2.11.5",
"@tiptap/extension-collaboration": "^2.11.5",
"@tiptap/extension-collaboration-cursor": "^2.11.5",
"@tiptap/extension-focus": "^2.11.5",
"@tiptap/extension-image": "^2.11.5",
"@tiptap/extension-link": "^2.11.5",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7768,6 +7768,11 @@
resolved "https://registry.yarnpkg.com/@tiptap/extension-code/-/extension-code-2.11.5.tgz#a550c544804e65507ab66dc8ab89a1e2f7d9228d"
integrity sha512-xOvHevNIQIcCCVn9tpvXa1wBp0wHN/2umbAZGTVzS+AQtM7BTo0tz8IyzwxkcZJaImONcUVYLOLzt2AgW1LltA==

"@tiptap/extension-collaboration-cursor@^2.11.5":
version "2.11.5"
resolved "https://registry.yarnpkg.com/@tiptap/extension-collaboration-cursor/-/extension-collaboration-cursor-2.11.5.tgz#967ae84534f8ea8e25229cfbecfd0ee9a46ba759"
integrity sha512-sazBzi5HCHgGRihSzWHhHFMSI9oU0v/qqiDZYJ/zhzCKEWONx8WlS6WTxo6z3l6/Qz9lm7clmHNUQNWxnssAOA==

"@tiptap/extension-collaboration@^2.11.5":
version "2.11.5"
resolved "https://registry.yarnpkg.com/@tiptap/extension-collaboration/-/extension-collaboration-2.11.5.tgz#7edbcf88b3659dfb18c44aa45c50bbbf31ac1405"
Expand Down

0 comments on commit 02e131d

Please sign in to comment.