y-prosemirror
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -223,3 +223,3 @@ 'use strict'; | ||
} | ||
let n = type._first !== null ? /** @type {Y.ItemType} */ (type._first).type : null; | ||
let n = type._first === null ? null : /** @type {Y.ContentType} */ (type._first.content).type; | ||
while (n !== null && type !== n) { | ||
@@ -234,3 +234,3 @@ const pNodeSize = (mapping.get(n) || { nodeSize: 0 }).nodeSize; | ||
if (n._item !== null && n._item.next !== null) { | ||
n = /** @type {Y.ItemType} */ (n._item.next).type; | ||
n = /** @type {Y.ContentType} */ (n._item.next.content).type; | ||
} else { | ||
@@ -243,7 +243,7 @@ do { | ||
// @ts-gnore we know that n.next !== null because of above loop conditition | ||
n = n._item === null ? null : /** @type {Y.ItemType} */ (n._item.next).type; | ||
n = n._item === null ? null : /** @type {Y.ContentType} */ (/** @type Y.Item */ (n._item.next).content).type; | ||
} | ||
} | ||
} else if (n._first !== null && pos < pNodeSize) { | ||
n = /** @type {Y.ItemType} */ (n._first).type; | ||
n = /** @type {Y.ContentType} */ (n._first.content).type; | ||
pos--; | ||
@@ -257,3 +257,3 @@ } else { | ||
if (n._item !== null && n._item.next !== null) { | ||
n = /** @type {Y.ItemType} */ (n._item.next).type; | ||
n = /** @type {Y.ContentType} */ (n._item.next.content).type; | ||
} else { | ||
@@ -266,8 +266,9 @@ if (pos === 0) { | ||
do { | ||
n = /** @type {Y.ItemType} */ (n._item).parent; | ||
n = /** @type {Y.Item} */ (n._item).parent; | ||
pos--; | ||
} while (n !== type && /** @type {Y.ItemType} */ (n._item).next === null) | ||
} while (n !== type && /** @type {Y.Item} */ (n._item).next === null) | ||
// if n is null at this point, we have an unexpected case | ||
if (n !== type) { | ||
n = /** @type {Y.ItemType} */ (/** @type {Y.ItemType} */ (n._item).next).type; | ||
// We know that n._item.next is defined because of above loop condition | ||
n = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (/** @type {Y.Item} */ (n._item).next).content).type; | ||
} | ||
@@ -302,12 +303,13 @@ } | ||
} else if (type._item === null || !type._item.deleted) { | ||
let n = /** @type {Y.ItemType} */ (type._first); | ||
let n = type._first; | ||
let i = 0; | ||
while (i < type._length && i < decodedPos.index && n !== null) { | ||
i++; | ||
if (n.type.constructor === Y.XmlText) { | ||
pos += n.type._length; | ||
const t = /** @type {Y.ContentType} */ (n.content).type; | ||
if (t.constructor === Y.XmlText) { | ||
pos += t._length; | ||
} else { | ||
pos += mapping.get(n.type).nodeSize; | ||
pos += mapping.get(t).nodeSize; | ||
} | ||
n = /** @type {Y.ItemType} */ (n.next); | ||
n = /** @type {Y.Item} */ (n.next); | ||
} | ||
@@ -322,14 +324,15 @@ pos += 1; // increase because we go out of n | ||
pos += 1; // the start tag | ||
let n = /** @type {Y.ItemType} */ (parent._first); | ||
let n = parent._first; | ||
// now iterate until we found type | ||
while (n !== null) { | ||
if (n.type === type) { | ||
const contentType = /** @type {Y.ContentType} */ (n.content).type; | ||
if (contentType === type) { | ||
break | ||
} | ||
if (n.type.constructor === Y.XmlText) { | ||
pos += n.type._length; | ||
if (contentType.constructor === Y.XmlText) { | ||
pos += contentType._length; | ||
} else { | ||
pos += mapping.get(n.type).nodeSize; | ||
pos += mapping.get(contentType).nodeSize; | ||
} | ||
n = /** @type {Y.ItemType} */ (n.next); | ||
n = n.next; | ||
} | ||
@@ -411,3 +414,3 @@ } | ||
const delStruct = (_, struct) => this.mapping.delete(struct); | ||
Y.iterateDeletedStructs(transaction.deleteSet, this.doc.store, struct => this.mapping.delete(/** @type {Y.ItemType} */ (struct).type)); | ||
Y.iterateDeletedStructs(transaction.deleteSet, this.doc.store, struct => struct.constructor === Y.Item && this.mapping.delete(/** @type {Y.Item} */ (struct).content.type)); | ||
transaction.changed.forEach(delStruct); | ||
@@ -509,5 +512,5 @@ transaction.changedParentTypes.forEach(delStruct); | ||
if (!isVisible(el, snapshot)) { | ||
attrs.ychange = { client: /** @type {Y.AbstractItem} */ (el._item).id.client, state: 'removed' }; | ||
attrs.ychange = { client: /** @type {Y.Item} */ (el._item).id.client, state: 'removed' }; | ||
} else if (!isVisible(el, prevSnapshot)) { | ||
attrs.ychange = { client: /** @type {Y.AbstractItem} */ (el._item).id.client, state: 'added' }; | ||
attrs.ychange = { client: /** @type {Y.Item} */ (el._item).id.client, state: 'added' }; | ||
} | ||
@@ -519,3 +522,3 @@ } | ||
/** @type {Y.Doc} */ (el.doc).transact(transaction => { | ||
/** @type {Y.ItemType} */ (el._item).delete(transaction); | ||
/** @type {Y.Item} */ (el._item).delete(transaction); | ||
}); | ||
@@ -555,3 +558,3 @@ return null | ||
/** @type {Y.Doc} */ (text.doc).transact(transaction => { | ||
/** @type {Y.ItemType} */ (text._item).delete(transaction); | ||
/** @type {Y.Item} */ (text._item).delete(transaction); | ||
}); | ||
@@ -558,0 +561,0 @@ return null |
{ | ||
"name": "y-prosemirror", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Prosemirror bindings for Yjs", | ||
@@ -37,3 +37,3 @@ "main": "./dist/y-prosemirror.js", | ||
"peerDependencies": { | ||
"yjs": "13.0.0-83", | ||
"yjs": "13.0.0-88", | ||
"y-protocols": ">=0.0.6", | ||
@@ -55,5 +55,5 @@ "prosemirror-model": "^1.7.0", | ||
"rollup-plugin-node-resolve": "^4.2.3", | ||
"yjs": "13.0.0-83", | ||
"yjs": "13.0.0-88", | ||
"y-protocols": "0.0.6" | ||
} | ||
} |
@@ -219,3 +219,3 @@ /** | ||
} | ||
let n = type._first !== null ? /** @type {Y.ItemType} */ (type._first).type : null | ||
let n = type._first === null ? null : /** @type {Y.ContentType} */ (type._first.content).type | ||
while (n !== null && type !== n) { | ||
@@ -230,3 +230,3 @@ const pNodeSize = (mapping.get(n) || { nodeSize: 0 }).nodeSize | ||
if (n._item !== null && n._item.next !== null) { | ||
n = /** @type {Y.ItemType} */ (n._item.next).type | ||
n = /** @type {Y.ContentType} */ (n._item.next.content).type | ||
} else { | ||
@@ -239,7 +239,7 @@ do { | ||
// @ts-gnore we know that n.next !== null because of above loop conditition | ||
n = n._item === null ? null : /** @type {Y.ItemType} */ (n._item.next).type | ||
n = n._item === null ? null : /** @type {Y.ContentType} */ (/** @type Y.Item */ (n._item.next).content).type | ||
} | ||
} | ||
} else if (n._first !== null && pos < pNodeSize) { | ||
n = /** @type {Y.ItemType} */ (n._first).type | ||
n = /** @type {Y.ContentType} */ (n._first.content).type | ||
pos-- | ||
@@ -253,3 +253,3 @@ } else { | ||
if (n._item !== null && n._item.next !== null) { | ||
n = /** @type {Y.ItemType} */ (n._item.next).type | ||
n = /** @type {Y.ContentType} */ (n._item.next.content).type | ||
} else { | ||
@@ -262,8 +262,9 @@ if (pos === 0) { | ||
do { | ||
n = /** @type {Y.ItemType} */ (n._item).parent | ||
n = /** @type {Y.Item} */ (n._item).parent | ||
pos-- | ||
} while (n !== type && /** @type {Y.ItemType} */ (n._item).next === null) | ||
} while (n !== type && /** @type {Y.Item} */ (n._item).next === null) | ||
// if n is null at this point, we have an unexpected case | ||
if (n !== type) { | ||
n = /** @type {Y.ItemType} */ (/** @type {Y.ItemType} */ (n._item).next).type | ||
// We know that n._item.next is defined because of above loop condition | ||
n = /** @type {Y.ContentType} */ (/** @type {Y.Item} */ (/** @type {Y.Item} */ (n._item).next).content).type | ||
} | ||
@@ -298,12 +299,13 @@ } | ||
} else if (type._item === null || !type._item.deleted) { | ||
let n = /** @type {Y.ItemType} */ (type._first) | ||
let n = type._first | ||
let i = 0 | ||
while (i < type._length && i < decodedPos.index && n !== null) { | ||
i++ | ||
if (n.type.constructor === Y.XmlText) { | ||
pos += n.type._length | ||
const t = /** @type {Y.ContentType} */ (n.content).type | ||
if (t.constructor === Y.XmlText) { | ||
pos += t._length | ||
} else { | ||
pos += mapping.get(n.type).nodeSize | ||
pos += mapping.get(t).nodeSize | ||
} | ||
n = /** @type {Y.ItemType} */ (n.next) | ||
n = /** @type {Y.Item} */ (n.next) | ||
} | ||
@@ -318,14 +320,15 @@ pos += 1 // increase because we go out of n | ||
pos += 1 // the start tag | ||
let n = /** @type {Y.ItemType} */ (parent._first) | ||
let n = parent._first | ||
// now iterate until we found type | ||
while (n !== null) { | ||
if (n.type === type) { | ||
const contentType = /** @type {Y.ContentType} */ (n.content).type | ||
if (contentType === type) { | ||
break | ||
} | ||
if (n.type.constructor === Y.XmlText) { | ||
pos += n.type._length | ||
if (contentType.constructor === Y.XmlText) { | ||
pos += contentType._length | ||
} else { | ||
pos += mapping.get(n.type).nodeSize | ||
pos += mapping.get(contentType).nodeSize | ||
} | ||
n = /** @type {Y.ItemType} */ (n.next) | ||
n = n.next | ||
} | ||
@@ -407,3 +410,3 @@ } | ||
const delStruct = (_, struct) => this.mapping.delete(struct) | ||
Y.iterateDeletedStructs(transaction.deleteSet, this.doc.store, struct => this.mapping.delete(/** @type {Y.ItemType} */ (struct).type)) | ||
Y.iterateDeletedStructs(transaction.deleteSet, this.doc.store, struct => struct.constructor === Y.Item && this.mapping.delete(/** @type {Y.Item} */ (struct).content.type)) | ||
transaction.changed.forEach(delStruct) | ||
@@ -505,5 +508,5 @@ transaction.changedParentTypes.forEach(delStruct) | ||
if (!isVisible(el, snapshot)) { | ||
attrs.ychange = { client: /** @type {Y.AbstractItem} */ (el._item).id.client, state: 'removed' } | ||
attrs.ychange = { client: /** @type {Y.Item} */ (el._item).id.client, state: 'removed' } | ||
} else if (!isVisible(el, prevSnapshot)) { | ||
attrs.ychange = { client: /** @type {Y.AbstractItem} */ (el._item).id.client, state: 'added' } | ||
attrs.ychange = { client: /** @type {Y.Item} */ (el._item).id.client, state: 'added' } | ||
} | ||
@@ -515,3 +518,3 @@ } | ||
/** @type {Y.Doc} */ (el.doc).transact(transaction => { | ||
/** @type {Y.ItemType} */ (el._item).delete(transaction) | ||
/** @type {Y.Item} */ (el._item).delete(transaction) | ||
}) | ||
@@ -551,3 +554,3 @@ return null | ||
/** @type {Y.Doc} */ (text.doc).transact(transaction => { | ||
/** @type {Y.ItemType} */ (text._item).delete(transaction) | ||
/** @type {Y.Item} */ (text._item).delete(transaction) | ||
}) | ||
@@ -554,0 +557,0 @@ return null |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2282608
20567