From ed9a80f7669dcaff46011eb1ef28177087e22576 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 07:20:52 +0000 Subject: [PATCH] feat(crdt): Create YjsDocument class with project structure --- frontend/src/crdt/YjsDocument.ts | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 frontend/src/crdt/YjsDocument.ts diff --git a/frontend/src/crdt/YjsDocument.ts b/frontend/src/crdt/YjsDocument.ts new file mode 100644 index 0000000..f566479 --- /dev/null +++ b/frontend/src/crdt/YjsDocument.ts @@ -0,0 +1,62 @@ +import * as Y from 'yjs'; + +type ProjectMeta = { + id: string; + name: string; + createdAt: number; + updatedAt: number; +}; + +type Layer = { + id: string; + name: string; + visible: boolean; + locked: boolean; +}; + +type Element = { + id: string; + type: string; + layerId: string; + x: number; + y: number; + width: number; + height: number; + properties: Record; +}; + +type Block = { + id: string; + name: string; + elements: string[]; // element IDs +}; + +type BlockInstance = { + id: string; + blockId: string; + x: number; + y: number; + properties: Record; +}; + +export class YjsDocument { + doc: Y.Doc; + projectMeta: Y.Map; + layers: Y.Map; + elements: Y.Array; + blocks: Y.Map; + blockInstances: Y.Array; + + constructor() { + this.doc = new Y.Doc(); + this.projectMeta = this.doc.getMap('projectMeta'); + this.layers = this.doc.getMap('layers'); + this.elements = this.doc.getArray('elements'); + this.blocks = this.doc.getMap('blocks'); + this.blockInstances = this.doc.getArray('blockInstances'); + } + + destroy() { + this.doc.destroy(); + } +} \ No newline at end of file