add another example and create a writeup for attributing content.

This commit is contained in:
Kevin Jahns
2025-04-24 00:03:00 +02:00
parent f03a2426c5
commit 1e8ea641ea
4 changed files with 200 additions and 1 deletions

View File

@@ -105,7 +105,11 @@ export {
IdMap,
createIdMap,
createAttribution,
Attribution
createInsertionSetFromStructStore,
diffIdMap,
diffIdSet,
Attribution,
encodeIdMap
} from './internals.js'
const glo = /** @type {any} */ (typeof globalThis !== 'undefined'

View File

@@ -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