Skip to content
Permalink
Newer
Older
100644 70 lines (61 sloc) 1.95 KB
December 8, 2022 23:58
1
// A color used to encode color data for nodes and edges
2
// can be a number (like "1") representing one of the (currently 6) supported colors.
3
// or can be a custom color using the hex format "#FFFFFFF".
4
export type CanvasColor = string;
5
6
// The overall canvas file's JSON
7
export interface CanvasData {
December 20, 2022 00:02
8
nodes: AllCanvasNodeData[];
December 8, 2022 23:58
9
edges: CanvasEdgeData[];
10
}
11
12
// A node
13
export interface CanvasNodeData {
14
// The unique ID for this node
15
id: string;
16
// The positional data
17
x: number;
18
y: number;
19
width: number;
20
height: number;
21
// The color of this node
22
color?: CanvasColor;
23
}
24
December 20, 2022 00:02
25
export type AllCanvasNodeData = CanvasFileData | CanvasTextData | CanvasLinkData | CanvasGroupData;
26
December 8, 2022 23:58
27
// A node that is a file, where the file is located somewhere in the vault.
28
export interface CanvasFileData extends CanvasNodeData {
29
type: 'file';
30
file: string;
December 20, 2022 00:02
31
// An optional subpath which links to a heading or a block. Always starts with a `#`.
32
subpath?: string;
December 8, 2022 23:58
33
}
34
35
// A node that is plaintext.
36
export interface CanvasTextData extends CanvasNodeData {
37
type: 'text';
38
text: string;
39
}
40
41
// A node that is an external resource.
42
export interface CanvasLinkData extends CanvasNodeData {
43
type: 'link';
44
url: string;
45
}
46
December 20, 2022 00:02
47
// A node that represents a group.
48
export interface CanvasGroupData extends CanvasNodeData {
49
type: 'group';
50
label?: string;
51
}
52
December 8, 2022 23:58
53
// The side of the node that a connection is connected to
54
export type NodeSide = 'top' | 'right' | 'bottom' | 'left';
55
56
// An edge
57
export interface CanvasEdgeData {
58
// The unique ID for this edge
59
id: string;
60
// The node ID and side where this edge starts
61
fromNode: string;
62
fromSide: NodeSide;
63
// The node ID and side where this edge ends
64
toNode: string;
65
toSide: NodeSide;
66
// The color of this edge
67
color?: CanvasColor;
68
// The text label of this edge, if available
69
label?: string;
December 20, 2022 00:02
70
}