added utilities to make and recover snapshots
This commit is contained in:
@@ -8,7 +8,7 @@ import { ItemJSON } from '../structs/ItemJSON.js'
|
||||
import * as stringify from '../utils/structStringify.js'
|
||||
import { YEvent } from '../utils/YEvent.js'
|
||||
import { ItemBinary } from '../structs/ItemBinary.js'
|
||||
import { isVisible } from '../utils/snapshot.js';
|
||||
import { isVisible } from '../utils/snapshot.js'
|
||||
|
||||
/**
|
||||
* Event that describes the changes on a YMap.
|
||||
@@ -82,11 +82,11 @@ export class YMap extends Type {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let key in this._map) {
|
||||
if (this.has(key, snapshot)) {
|
||||
this._map.forEach((_, key) => {
|
||||
if (YMap.prototype.has.call(this, key, snapshot)) {
|
||||
keys.push(key)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
@@ -572,11 +572,12 @@ export class YText extends YArray {
|
||||
* Returns the Delta representation of this YText type.
|
||||
*
|
||||
* @param {import('../protocols/history.js').HistorySnapshot} [snapshot]
|
||||
* @param {import('../protocols/history.js').HistorySnapshot} [prevSnapshot]
|
||||
* @return {Delta} The Delta representation of this type.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
toDelta (snapshot) {
|
||||
toDelta (snapshot, prevSnapshot) {
|
||||
let ops = []
|
||||
let currentAttributes = new Map()
|
||||
let str = ''
|
||||
@@ -602,9 +603,24 @@ export class YText extends YArray {
|
||||
}
|
||||
}
|
||||
while (n !== null) {
|
||||
if (isVisible(n, snapshot)) {
|
||||
if (isVisible(n, snapshot) || (prevSnapshot !== undefined && isVisible(n, prevSnapshot))) {
|
||||
switch (n.constructor) {
|
||||
case ItemString:
|
||||
const cur = currentAttributes.get('ychange')
|
||||
if (snapshot !== undefined && !isVisible(n, snapshot)) {
|
||||
if (cur === undefined || cur.user !== n._id.user || cur.state !== 'removed') {
|
||||
packStr()
|
||||
currentAttributes.set('ychange', { user: n._id.user, state: 'removed' })
|
||||
}
|
||||
} else if (prevSnapshot !== undefined && !isVisible(n, prevSnapshot)) {
|
||||
if (cur === undefined || cur.user !== n._id.user || cur.state !== 'added') {
|
||||
packStr()
|
||||
currentAttributes.set('ychange', { user: n._id.user, state: 'added' })
|
||||
}
|
||||
} else if (cur !== undefined) {
|
||||
packStr()
|
||||
currentAttributes.delete('ychange')
|
||||
}
|
||||
str += n._content
|
||||
break
|
||||
case ItemFormat:
|
||||
|
||||
@@ -326,9 +326,9 @@ export class YXmlElement extends YXmlFragment {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (let key in this._map) {
|
||||
return YMap.prototype.get.call(this, key, snapshot)
|
||||
}
|
||||
YMap.prototype.keys.call(this, snapshot).forEach(key => {
|
||||
obj[key] = YMap.prototype.get.call(this, key, snapshot)
|
||||
})
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user