-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a custom CollaborationCursor Tiptap extension
Needed to define our own render function. Signed-off-by: Jonas <jonas@freesources.org>
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { CollaborationCursor as TiptapCollaborationCursor } from '@tiptap/extension-collaboration-cursor' | ||
|
||
const CollaborationCursor = TiptapCollaborationCursor.extend({ | ||
addOptions() { | ||
return { | ||
provider: null, | ||
user: { | ||
name: null, | ||
color: null, | ||
}, | ||
render: user => { | ||
const cursor = document.createElement('span') | ||
|
||
cursor.classList.add('collaboration-cursor__caret') | ||
cursor.setAttribute('style', `border-color: ${user.color}`) | ||
|
||
const label = document.createElement('div') | ||
|
||
label.classList.add('collaboration-cursor__label') | ||
label.classList.add(`collaboration-cursor__label__${user.name}`) | ||
label.setAttribute('style', `background-color: ${user.color}`) | ||
label.insertBefore(document.createTextNode(user.name), null) | ||
cursor.insertBefore(label, null) | ||
|
||
setTimeout(() => { | ||
label.classList.add('collaboration-cursor__label_fadeout') | ||
}, 5000) | ||
|
||
return cursor | ||
}, | ||
} | ||
}, | ||
onTransaction: (transaction) => { | ||
// console.debug('collab cursor transaction', transaction) | ||
// console.debug('collab cursor transaction getMeta clientID', transaction.getMeta('clientID')) | ||
}, | ||
}) | ||
|
||
export default CollaborationCursor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters