Skip to content

Commit

Permalink
Add support for custom selection builders (#4128)
Browse files Browse the repository at this point in the history
* Add support for custom cursor builders

* Add documentation for selectionRender

---------

Co-authored-by: Ben Lewis <[email protected]>
  • Loading branch information
benglewis and Ben Lewis committed Aug 3, 2023
1 parent d1e879d commit 7cf17d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/api/extensions/collaboration-cursor.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Default: `{ user: null, color: null }`
### render
A render function for the cursor, look at [the extension source code](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-collaboration-cursor/) for an example.

### selectionRender
A render function for the selection, look at [the extension source code](https://github.com/ueberdosis/tiptap/blob/main/packages/extension-collaboration-cursor/) for an example.

## Commands

### updateUser()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Extension } from '@tiptap/core'
import { yCursorPlugin } from 'y-prosemirror'
import { DecorationAttrs } from 'prosemirror-view'
import { defaultSelectionBuilder, yCursorPlugin } from 'y-prosemirror'

type CollaborationCursorStorage = {
users: { clientId: number, [key: string]: any }[],
Expand All @@ -9,6 +10,7 @@ export interface CollaborationCursorOptions {
provider: any,
user: Record<string, any>,
render (user: Record<string, any>): HTMLElement,
selectionRender (user: Record<string, any>): DecorationAttrs
/**
* @deprecated The "onUpdate" option is deprecated. Please use `editor.storage.collaborationCursor.users` instead. Read more: https://tiptap.dev/api/extensions/collaboration-cursor
*/
Expand Down Expand Up @@ -68,6 +70,7 @@ export const CollaborationCursor = Extension.create<CollaborationCursorOptions,

return cursor
},
selectionRender: defaultSelectionBuilder,
onUpdate: defaultOnUpdate,
}
},
Expand Down Expand Up @@ -118,6 +121,7 @@ export const CollaborationCursor = Extension.create<CollaborationCursorOptions,
// @ts-ignore
{
cursorBuilder: this.options.render,
selectionBuilder: this.options.selectionRender,
},
),
]
Expand Down

0 comments on commit 7cf17d0

Please sign in to comment.