Prosemirror transaction on a ydoc server side..?

So with the Prosemirror state on the backend, we would generally write a transaction like this…

function addThewordSample(state) {
      const transaction = state.tr.insertText('sample',10, 20);
      return state.applyTransaction(transaction)
}

Once we have converted to a ydoc this kind of logic appears to have to change. Has anyone managed to apply a prosemirror transaction like this using the ydoc?

function addThewordSample(ydoc??) {
      const transaction = state.tr.insertText('sample',10, 20);
      return state.applyTransaction(transaction)
}

Thanks for any help here…

The ProseMirror content is mapped to a shared type (a Y.XmlFragment). Yjs has an extensive API for manipulating content https://docs.yjs.dev/getting-started/working-with-shared-types.

You could do something like: yfragment.get(0).insert(0, 'sample') to insert “sample” in the first paragraph.