Items accept origins as IDs
This commit is contained in:
@@ -335,7 +335,7 @@ export const typeArrayInsertGenericsAfter = (transaction, parent, referenceItem,
|
||||
let jsonContent = []
|
||||
const packJsonContent = () => {
|
||||
if (jsonContent.length > 0) {
|
||||
const item = new ItemJSON(nextID(transaction), left, right, parent, null, jsonContent)
|
||||
const item = new ItemJSON(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, jsonContent)
|
||||
item.integrate(transaction)
|
||||
jsonContent = []
|
||||
}
|
||||
@@ -353,11 +353,11 @@ export const typeArrayInsertGenericsAfter = (transaction, parent, referenceItem,
|
||||
switch (c.constructor) {
|
||||
case ArrayBuffer:
|
||||
// @ts-ignore c is definitely an ArrayBuffer
|
||||
new ItemBinary(nextID(transaction), left, right, parent, null, c).integrate(transaction)
|
||||
new ItemBinary(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, c).integrate(transaction)
|
||||
break
|
||||
default:
|
||||
if (c instanceof AbstractType) {
|
||||
new ItemType(nextID(transaction), left, right, parent, null, c).integrate(transaction)
|
||||
new ItemType(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, c).integrate(transaction)
|
||||
} else {
|
||||
throw new Error('Unexpected content type in insert operation')
|
||||
}
|
||||
@@ -383,7 +383,7 @@ export const typeArrayInsertGenerics = (transaction, parent, index, content) =>
|
||||
if (index <= n.length) {
|
||||
if (index < n.length) {
|
||||
// insert in-between
|
||||
getItemCleanStart(transaction.y.store, transaction, createID(n.id.client, n.id.clock + index))
|
||||
getItemCleanStart(transaction.y.store, createID(n.id.client, n.id.clock + index))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -405,7 +405,7 @@ export const typeArrayDelete = (transaction, parent, index, length) => {
|
||||
if (!n.deleted && n.countable) {
|
||||
if (index <= n.length) {
|
||||
if (index < n.length) {
|
||||
n = getItemCleanStart(transaction.y.store, transaction, createID(n.id.client, n.id.clock + index))
|
||||
n = getItemCleanStart(transaction.y.store, createID(n.id.client, n.id.clock + index))
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -415,7 +415,7 @@ export const typeArrayDelete = (transaction, parent, index, length) => {
|
||||
while (length > 0 && n !== null) {
|
||||
if (!n.deleted) {
|
||||
if (length < n.length) {
|
||||
getItemCleanEnd(transaction.y.store, transaction, createID(n.id.client, n.id.clock + length))
|
||||
getItemCleanEnd(transaction.y.store, createID(n.id.client, n.id.clock + length))
|
||||
}
|
||||
n.delete(transaction)
|
||||
length -= n.length
|
||||
@@ -445,7 +445,7 @@ export const typeMapDelete = (transaction, parent, key) => {
|
||||
export const typeMapSet = (transaction, parent, key, value) => {
|
||||
const right = parent._map.get(key) || null
|
||||
if (value == null) {
|
||||
new ItemJSON(nextID(transaction), null, right, parent, key, [value]).integrate(transaction)
|
||||
new ItemJSON(nextID(transaction), null, null, right, right === null ? null : right.id, parent, key, [value]).integrate(transaction)
|
||||
return
|
||||
}
|
||||
switch (value.constructor) {
|
||||
@@ -453,14 +453,14 @@ export const typeMapSet = (transaction, parent, key, value) => {
|
||||
case Object:
|
||||
case Array:
|
||||
case String:
|
||||
new ItemJSON(nextID(transaction), null, right, parent, key, [value]).integrate(transaction)
|
||||
new ItemJSON(nextID(transaction), null, null, right, right === null ? null : right.id, parent, key, [value]).integrate(transaction)
|
||||
break
|
||||
case ArrayBuffer:
|
||||
new ItemBinary(nextID(transaction), null, right, parent, key, value).integrate(transaction)
|
||||
new ItemBinary(nextID(transaction), null, null, right, right === null ? null : right.id, parent, key, value).integrate(transaction)
|
||||
break
|
||||
default:
|
||||
if (value instanceof AbstractType) {
|
||||
new ItemType(nextID(transaction), null, right, parent, key, value).integrate(transaction)
|
||||
new ItemType(nextID(transaction), null, null, right, right === null ? null : right.id, parent, key, value).integrate(transaction)
|
||||
} else {
|
||||
throw new Error('Unexpected content type')
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ const findNextPosition = (transaction, store, currentAttributes, left, right, co
|
||||
case ItemString:
|
||||
if (!right.deleted) {
|
||||
if (count < right.length) {
|
||||
right = getItemCleanStart(store, transaction, createID(right.id.client, right.id.clock + count))
|
||||
right = getItemCleanStart(store, createID(right.id.client, right.id.clock + count))
|
||||
left = right.left
|
||||
count = 0
|
||||
} else {
|
||||
@@ -102,7 +102,7 @@ const insertNegatedAttributes = (transaction, parent, left, right, negatedAttrib
|
||||
right = right.right
|
||||
}
|
||||
for (let [key, val] of negatedAttributes) {
|
||||
left = new ItemFormat(nextID(transaction), left, right, parent, null, key, val)
|
||||
left = new ItemFormat(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, key, val)
|
||||
left.integrate(transaction)
|
||||
}
|
||||
return {left, right}
|
||||
@@ -171,7 +171,7 @@ const insertAttributes = (transaction, parent, left, right, currentAttributes, a
|
||||
if (currentVal !== val) {
|
||||
// save negated attribute (set null if currentVal undefined)
|
||||
negatedAttributes.set(key, currentVal || null)
|
||||
left = new ItemFormat(nextID(transaction), left, right, parent, null, key, val)
|
||||
left = new ItemFormat(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, key, val)
|
||||
left.integrate(transaction)
|
||||
}
|
||||
}
|
||||
@@ -199,9 +199,9 @@ const insertText = (transaction, parent, left, right, currentAttributes, text, a
|
||||
const insertPos = insertAttributes(transaction, parent, minPos.left, minPos.right, currentAttributes, attributes)
|
||||
// insert content
|
||||
if (text.constructor === String) {
|
||||
left = new ItemString(nextID(transaction), insertPos.left, insertPos.right, parent, null, text)
|
||||
left = new ItemString(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, text)
|
||||
} else {
|
||||
left = new ItemEmbed(nextID(transaction), insertPos.left, insertPos.right, parent, null, text)
|
||||
left = new ItemEmbed(nextID(transaction), left, left === null ? null : left.lastId, right, right === null ? null : right.id, parent, null, text)
|
||||
}
|
||||
left.integrate(transaction)
|
||||
return insertNegatedAttributes(transaction, parent, left, insertPos.right, insertPos.negatedAttributes)
|
||||
@@ -249,7 +249,7 @@ const formatText = (transaction, parent, left, right, currentAttributes, length,
|
||||
case ItemEmbed:
|
||||
case ItemString:
|
||||
if (length < right.length) {
|
||||
getItemCleanStart(transaction.y.store, transaction, createID(right.id.client, right.id.clock + length))
|
||||
getItemCleanStart(transaction.y.store, createID(right.id.client, right.id.clock + length))
|
||||
}
|
||||
length -= right.length
|
||||
break
|
||||
@@ -282,7 +282,7 @@ const deleteText = (transaction, parent, left, right, currentAttributes, length)
|
||||
case ItemEmbed:
|
||||
case ItemString:
|
||||
if (length < right.length) {
|
||||
getItemCleanStart(transaction.y.store, transaction, createID(right.id.client, right.id.clock + length))
|
||||
getItemCleanStart(transaction.y.store, createID(right.id.client, right.id.clock + length))
|
||||
}
|
||||
length -= right.length
|
||||
right.delete(transaction)
|
||||
|
||||
Reference in New Issue
Block a user