Skip to content

Is there any way to make it collaborative with YJS? #1005

Answered by linspw
linspw asked this question in Q&A
Discussion options

You must be logged in to vote

Working hook for Vue-Flow Collab:

Collab Hook:

import { HocuspocusProvider } from '@hocuspocus/provider'
import * as Y from 'yjs'
import { useVueFlow, FlowElements } from '@vue-flow/core'
import { createYdocUrl } from './create-ydoc-url-and-token'

export const useDiagramCollab = (diagramId: number) => {
  const { onNodesChange, applyNodeChanges, onEdgesChange, applyEdgeChanges } =
    useVueFlow()

  const elements = ref<FlowElements>([])

  const { documentName, url, cookie } = createYdocUrl(
    diagramId,
    'diagram',
    'diagrams'
  )
  const ydoc = new Y.Doc()
  const provider = new HocuspocusProvider({
    url,
    name: documentName,
    document: ydoc,
    token: cookie.value,
  

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@linspw
Comment options

Answer selected by bcakmakoglu
@linspw
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant