Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the mapping when converting Prosemirror (JSON) to Y.Doc instances #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ export const relativePositionToAbsolutePosition = (y, documentType, relPos, mapp
*
* @param {Node} doc
* @param {string} xmlFragment
* @param {ProsemirrorMapping} mapping
* @return {Y.Doc}
*/
export function prosemirrorToYDoc (doc, xmlFragment = 'prosemirror') {
export function prosemirrorToYDoc (doc, xmlFragment = 'prosemirror', mapping = new Map()) {
const ydoc = new Y.Doc()
const type = ydoc.get(xmlFragment, Y.XmlFragment)
if (!type.doc) {
return ydoc
}

updateYFragment(type.doc, type, doc, new Map())
updateYFragment(type.doc, type, doc, mapping)
return type.doc
}

Expand All @@ -216,11 +217,12 @@ export function prosemirrorToYDoc (doc, xmlFragment = 'prosemirror') {
* @param {Schema} schema
* @param {any} state
* @param {string} xmlFragment
* @param {ProsemirrorMapping} mapping
* @return {Y.Doc}
*/
export function prosemirrorJSONToYDoc (schema, state, xmlFragment = 'prosemirror') {
export function prosemirrorJSONToYDoc (schema, state, xmlFragment = 'prosemirror', mapping = new Map()) {
const doc = Node.fromJSON(schema, state)
return prosemirrorToYDoc(doc, xmlFragment)
return prosemirrorToYDoc(doc, xmlFragment, mapping)
}

/**
Expand Down