feat(crdt): Create YjsDocument class with project structure
This commit is contained in:
@@ -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<string, any>;
|
||||
};
|
||||
|
||||
type Block = {
|
||||
id: string;
|
||||
name: string;
|
||||
elements: string[]; // element IDs
|
||||
};
|
||||
|
||||
type BlockInstance = {
|
||||
id: string;
|
||||
blockId: string;
|
||||
x: number;
|
||||
y: number;
|
||||
properties: Record<string, any>;
|
||||
};
|
||||
|
||||
export class YjsDocument {
|
||||
doc: Y.Doc;
|
||||
projectMeta: Y.Map<any>;
|
||||
layers: Y.Map<Layer>;
|
||||
elements: Y.Array<Element>;
|
||||
blocks: Y.Map<Block>;
|
||||
blockInstances: Y.Array<BlockInstance>;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user