mirror of
https://github.com/yjs/yjs.git
synced 2026-02-24 12:10:16 +01:00
add another example and create a writeup for attributing content.
This commit is contained in:
@@ -105,7 +105,11 @@ export {
|
||||
IdMap,
|
||||
createIdMap,
|
||||
createAttribution,
|
||||
Attribution
|
||||
createInsertionSetFromStructStore,
|
||||
diffIdMap,
|
||||
diffIdSet,
|
||||
Attribution,
|
||||
encodeIdMap
|
||||
} from './internals.js'
|
||||
|
||||
const glo = /** @type {any} */ (typeof globalThis !== 'undefined'
|
||||
|
||||
@@ -355,6 +355,37 @@ export const createDeleteSetFromStructStore = ss => {
|
||||
return ds
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../internals.js').StructStore} ss
|
||||
*/
|
||||
export const createInsertionSetFromStructStore = ss => {
|
||||
const idset = createIdSet()
|
||||
ss.clients.forEach((structs, client) => {
|
||||
/**
|
||||
* @type {Array<IdRange>}
|
||||
*/
|
||||
const iditems = []
|
||||
for (let i = 0; i < structs.length; i++) {
|
||||
const struct = structs[i]
|
||||
if (!struct.deleted) {
|
||||
const clock = struct.id.clock
|
||||
let len = struct.length
|
||||
if (i + 1 < structs.length) {
|
||||
for (let next = structs[i + 1]; i + 1 < structs.length && !next.deleted; next = structs[++i + 1]) {
|
||||
len += next.length
|
||||
}
|
||||
}
|
||||
iditems.push(new IdRange(clock, len))
|
||||
}
|
||||
}
|
||||
if (iditems.length > 0) {
|
||||
idset.clients.set(client, new IdRanges(iditems))
|
||||
}
|
||||
})
|
||||
return idset
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param {IdSetEncoderV1 | IdSetEncoderV2} encoder
|
||||
* @param {IdSet} idSet
|
||||
|
||||
Reference in New Issue
Block a user