Repository navigation
Expand file tree
/
Copy pathcontract.ts
More file actions
59 lines (59 loc) · 1.54 KB
/
Copy pathcontract.ts
File metadata and controls
59 lines (59 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export type Element = Record<string, unknown> & {
id: string;
type: string;
x: number;
y: number;
width: number;
height: number;
version: number;
isDeleted?: boolean;
};
export interface Scene {
elements: Element[];
appState: Record<string, unknown>;
files: Record<string, Record<string, unknown>>;
}
export interface Diagram {
id: string;
title: string;
revision: number;
scene: Scene;
updatedAt: number;
}
export interface DiagramRef {
id: string;
title: string;
revision: number;
uri: string;
elementCount: number;
}
export type Operation =
| { type: "add"; element: Record<string, unknown> }
| { type: "update"; id: string; changes: Record<string, unknown> }
| { type: "delete"; id: string };
export interface Commit {
id: string;
expectedRevision: number;
operationId: string;
scene: Scene;
title?: string;
}
export interface DocumentStore {
create(title: string, scene: Scene, id?: string): Promise<Diagram>;
read(id: string): Promise<Diagram>;
list(): Promise<Array<Omit<Diagram, "scene">>>;
commit(input: Commit): Promise<Diagram>;
apply(input: Omit<Commit, "scene"> & { operations: Operation[] }): Promise<Diagram>;
close(): Promise<void>;
}
export class DiagramError extends Error {
readonly code: string;
constructor(code: string, message: string) {
super(message);
this.code = code;
this.name = "DiagramError";
}
}
export const MAX_SCENE_BYTES = 6 * 1024 * 1024;
export const PANEL_URI = "ui://excalidraw/panel.html";
export const DOCUMENT_PREFIX = "excalidraw://document/";