Skip to content

Commit

Permalink
Feature/y sync options: allow passing ySyncOptions to extension-colla…
Browse files Browse the repository at this point in the history
…boration (#4976)

* extension-collaboration: allow passing ySyncOptions

* fixes import
  • Loading branch information
janthurau committed Apr 11, 2024
1 parent a06ec40 commit e73073c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/extension-collaboration/src/collaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from 'y-prosemirror'
import { UndoManager } from 'yjs'

type YSyncOpts = Parameters<typeof ySyncPlugin>[1]

declare module '@tiptap/core' {
interface Commands<ReturnType> {
collaboration: {
Expand Down Expand Up @@ -41,6 +43,8 @@ export interface CollaborationOptions {
* Fired when the content from Yjs is initially rendered to Tiptap.
*/
onFirstRender?: () => void,

ySyncOptions?: YSyncOpts
}

export const Collaboration = Extension.create<CollaborationOptions>({
Expand Down Expand Up @@ -149,8 +153,11 @@ export const Collaboration = Extension.create<CollaborationOptions>({
}
}

const onFirstRender = this.options.onFirstRender
const ySyncPluginOptions = onFirstRender ? { onFirstRender } : {}
const ySyncPluginOptions: YSyncOpts = {
...(this.options.ySyncOptions ? { ...this.options.ySyncOptions } : {}),
...(this.options.onFirstRender ? { ...this.options.onFirstRender } : {}),
}

const ySyncPluginInstance = ySyncPlugin(fragment, ySyncPluginOptions)

return [ySyncPluginInstance, yUndoPluginInstance]
Expand Down

0 comments on commit e73073c

Please sign in to comment.