mirror of
https://github.com/colanode/colanode.git
synced 2025-12-28 16:06:37 +01:00
Handle deleted blocks
This commit is contained in:
@@ -209,7 +209,10 @@ export const applyChangeToYDoc = (doc: Y.Doc, blocks: NodeBlock[]) => {
|
||||
}
|
||||
|
||||
const contentMap = attributesMap.get('content') as Y.Map<any>;
|
||||
const blockIds = new Set<string>();
|
||||
for (const block of blocks) {
|
||||
blockIds.add(block.id);
|
||||
|
||||
if (!contentMap.has(block.id)) {
|
||||
contentMap.set(block.id, new Y.Map());
|
||||
}
|
||||
@@ -217,6 +220,14 @@ export const applyChangeToYDoc = (doc: Y.Doc, blocks: NodeBlock[]) => {
|
||||
const blockMap = contentMap.get(block.id) as Y.Map<any>;
|
||||
applyBlockChangesToYDoc(blockMap, block);
|
||||
}
|
||||
|
||||
const deletedBlockIds = Array.from(contentMap.keys()).filter(
|
||||
(id) => !blockIds.has(id),
|
||||
);
|
||||
|
||||
for (const id of deletedBlockIds) {
|
||||
contentMap.delete(id);
|
||||
}
|
||||
};
|
||||
|
||||
const applyBlockChangesToYDoc = (blockMap: Y.Map<any>, block: NodeBlock) => {
|
||||
|
||||
Reference in New Issue
Block a user