-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
modularize yDocToProsemirrorJSON
to Y.XmlText
and Y.XmlElement
#64
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @BrianHung,
thanks for working on this. I will give this PR another review if you leave the existing API functional. Unless there is a good reason, we can't change the arguments or the names of the functions without breaking existing code.
src/plugins/sync-plugin.js
Outdated
@@ -469,8 +469,7 @@ const createTextNodesFromYText = (text, schema, mapping, snapshot, prevSnapshot, | |||
const nodes = [] | |||
const deltas = text.toDelta(snapshot, prevSnapshot, computeYChange) | |||
try { | |||
for (let i = 0; i < deltas.length; i++) { | |||
const delta = deltas[i] | |||
for (const delta in deltas) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use for-in loops for arrays as they fail to transpile in old typescript versions. I deliberately only use normal for loops.
src/lib.js
Outdated
const items = ydoc.getXmlFragment(xmlFragment).toArray() | ||
return { | ||
type: 'doc', | ||
content: items.map(typeToProseMirrorJSON).flat() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .flat()
method is a fairly recent addition to EcmaScript. Please use import { flatten } from 'lib0/array'
instead.
@BrianHung, @dmonad, I don't think See my PR here: #53 |
@SamDuvall I agree with both of your points about separating |
fc36506
to
ce9d0d3
Compare
Thanks to @BrianHung and @SamDuvall we now have two competing implementations 🤔 After reviewing this I think you are right that we should change the signature. I would be fine with making another major release for this feature. Could you both please communicate and come up with a solution that works for both of you. I'll merge the version that you both reviewed and agree with. Thanks! |
This PR has everything I need for converting |
To clarify, this would mean in essence deprecating Because if we change the signature of In my view, deprecating Those using the new API but want the old abstraction of // Previously
let json = yDocToProsemirrorJSON(ydoc)
// Now
let xmlFragment = ydoc.getXmlFragment('prosemirror')
let json = {type: 'doc', content: YXmlFragmentToProsemirrorJSON(xmlFragment)} |
If we're doing a major version bump, then I agree with @BrianHung's proposal to just delete @dmonad, if we did a major version bump, would you be okay with taking #34 as-is or would you still like a PR that is backwards-compatible? I'm coming across some issues with annotations/comment/suggestions that would benefit greatly from marks of the same type (e.g. comment) being allowed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a great addition!
I also need to be able to set prosemirror content json to a YFragment, I believe updateYFragment does this, but I'm curious if we should create a separate PR for that:
#53
Any updates here? Having the same issue needing overlapping nodes with different attributes |
Motivation for this PR is to separate out
Y.XmlFragment
fromY.XmlElement
in the scenario of using a custom top-level document withtype
,attrs
, andmarks
defined.Related:
https://discuss.yjs.dev/t/y-prosemirror-ydoctoprosemirrorjson-root-node-type-is-always-doc/642
#48
sync-plugin
still needs to be refactored to allow forXmlElement
to be a top-level document, and #63 is related because the newYXmlElementToProsemirrorJSON
method assumes node-level marks are stored as an array intype.getAttribute('marks)
. Also in #63, node-level marks are serialized usingtoJSON()
which is pretty convenient for this PR as well.