Feature/y sync options: allow passing ySyncOptions to extension-collaboration (#4976)

* extension-collaboration: allow passing ySyncOptions

* fixes import
This commit is contained in:
Jan Thurau 2024-03-27 19:37:18 +01:00
parent a06ec40138
commit e73073c020
No known key found for this signature in database
GPG Key ID: 60B3EB3A1C49AC04

View File

@ -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: {
@ -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>({
@ -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]