Skip to content

Commit 90b330f

Browse files
committed
Add JSON schema for JsonCanvas, CanvasNode, CanvasColor, and Edge interfaces. Define properties and types for nodes and edges. Include descriptions for clarity. Create TypeScript interfaces for JsonCanvas, CanvasNode, TextNode, FileNode, LinkNode, GroupNode, AllNodes, and Edge with detailed attributes and types.
alternative proposal for obsidianmd#10
1 parent ded83f7 commit 90b330f

File tree

2 files changed

+281
-0
lines changed

2 files changed

+281
-0
lines changed

jsoncanvas.schema.json

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/JsonCanvas",
4+
"definitions": {
5+
"JsonCanvas": {
6+
"type": "object",
7+
"properties": {
8+
"nodes": {
9+
"type": "array",
10+
"items": {
11+
"$ref": "#/definitions/CanvasNode"
12+
}
13+
},
14+
"edges": {
15+
"type": "array",
16+
"items": {
17+
"$ref": "#/definitions/Edge"
18+
}
19+
}
20+
},
21+
"additionalProperties": false,
22+
"description": "Top-level interface for the JSON Canvas Spec"
23+
},
24+
"CanvasNode": {
25+
"type": "object",
26+
"properties": {
27+
"id": {
28+
"type": "string"
29+
},
30+
"type": {
31+
"type": "string",
32+
"enum": [
33+
"text",
34+
"file",
35+
"link",
36+
"group"
37+
]
38+
},
39+
"x": {
40+
"type": "number"
41+
},
42+
"y": {
43+
"type": "number"
44+
},
45+
"width": {
46+
"type": "number"
47+
},
48+
"height": {
49+
"type": "number"
50+
},
51+
"color": {
52+
"$ref": "#/definitions/CanvasColor"
53+
}
54+
},
55+
"required": [
56+
"id",
57+
"type",
58+
"x",
59+
"y",
60+
"width",
61+
"height"
62+
],
63+
"additionalProperties": false,
64+
"description": "Base node interface for common attributes"
65+
},
66+
"CanvasColor": {
67+
"anyOf": [
68+
{
69+
"type": "string"
70+
},
71+
{
72+
"type": "number",
73+
"const": 1
74+
},
75+
{
76+
"type": "number",
77+
"const": 2
78+
},
79+
{
80+
"type": "number",
81+
"const": 3
82+
},
83+
{
84+
"type": "number",
85+
"const": 4
86+
},
87+
{
88+
"type": "number",
89+
"const": 5
90+
},
91+
{
92+
"type": "number",
93+
"const": 6
94+
}
95+
],
96+
"description": "Type for color, either a string for hex values or a number for preset colors"
97+
},
98+
"Edge": {
99+
"type": "object",
100+
"properties": {
101+
"id": {
102+
"type": "string"
103+
},
104+
"fromNode": {
105+
"type": "string"
106+
},
107+
"fromSide": {
108+
"type": "string",
109+
"enum": [
110+
"top",
111+
"right",
112+
"bottom",
113+
"left"
114+
],
115+
"description": "Optional side of the node where the edge starts"
116+
},
117+
"fromEnd": {
118+
"type": "string",
119+
"enum": [
120+
"none",
121+
"arrow"
122+
],
123+
"description": "Optional style of the edge end"
124+
},
125+
"toNode": {
126+
"type": "string"
127+
},
128+
"toSide": {
129+
"type": "string",
130+
"enum": [
131+
"top",
132+
"right",
133+
"bottom",
134+
"left"
135+
],
136+
"description": "Optional side of the node where the edge ends"
137+
},
138+
"toEnd": {
139+
"type": "string",
140+
"enum": [
141+
"none",
142+
"arrow"
143+
],
144+
"description": "Optional style of the edge end"
145+
},
146+
"color": {
147+
"$ref": "#/definitions/CanvasColor"
148+
},
149+
"label": {
150+
"type": "string",
151+
"description": "Optional label for the edge"
152+
}
153+
},
154+
"required": [
155+
"id",
156+
"fromNode",
157+
"toNode"
158+
],
159+
"additionalProperties": false,
160+
"description": "Edge interface for connections between nodes"
161+
}
162+
}
163+
}

src/index.ts

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/**
2+
* Top-level interface for the JSON Canvas Spec
3+
*/
4+
export interface JsonCanvas {
5+
nodes?: CanvasNode[];
6+
edges?: Edge[];
7+
}
8+
9+
export default JsonCanvas;
10+
11+
/**
12+
* Base node interface for common attributes
13+
*/
14+
export interface CanvasNode {
15+
id: string;
16+
type: "text" | "file" | "link" | "group";
17+
x: number;
18+
y: number;
19+
width: number;
20+
height: number;
21+
color?: CanvasColor;
22+
}
23+
24+
/**
25+
* Extended node interface for TextNode type
26+
*/
27+
export interface TextNode extends CanvasNode {
28+
type: "text";
29+
/**
30+
* Text content with Markdown syntax
31+
*/
32+
text: string;
33+
}
34+
35+
/**
36+
* Extended node interface for FileNode type
37+
*/
38+
export interface FileNode extends CanvasNode {
39+
type: "file";
40+
/**
41+
* Path to the file
42+
*/
43+
file: string;
44+
/**
45+
* Optional subpath within the file
46+
*/
47+
subpath?: string;
48+
}
49+
50+
/**
51+
* Extended node interface for LinkNode type
52+
*/
53+
export interface LinkNode extends CanvasNode {
54+
type: "link";
55+
/**
56+
* URL the node references
57+
*/
58+
url: string;
59+
}
60+
61+
/**
62+
* Extended node interface for GroupNode type
63+
*/
64+
export interface GroupNode extends CanvasNode {
65+
type: "group";
66+
/**
67+
* Optional text label for the group
68+
*/
69+
label?: string;
70+
/**
71+
* Optional path to a background image
72+
*/
73+
background?: string;
74+
/**
75+
* Optional rendering style of the background
76+
*/
77+
backgroundStyle?: "cover" | "ratio" | "repeat";
78+
}
79+
80+
/**
81+
* Union type for all node types
82+
*/
83+
export type AllNodes = TextNode | FileNode | LinkNode | GroupNode;
84+
85+
/**
86+
* Edge interface for connections between nodes
87+
*/
88+
export interface Edge {
89+
id: string;
90+
fromNode: string;
91+
/**
92+
* Optional side of the node where the edge starts
93+
*/
94+
fromSide?: "top" | "right" | "bottom" | "left";
95+
/**
96+
* Optional style of the edge end
97+
*/
98+
fromEnd?: "none" | "arrow";
99+
toNode: string;
100+
/**
101+
* Optional side of the node where the edge ends
102+
*/
103+
toSide?: "top" | "right" | "bottom" | "left";
104+
/**
105+
* Optional style of the edge end
106+
*/
107+
toEnd?: "none" | "arrow";
108+
color?: CanvasColor;
109+
/**
110+
* Optional label for the edge
111+
*/
112+
label?: string;
113+
}
114+
115+
/**
116+
* Type for color, either a string for hex values or a number for preset colors
117+
*/
118+
export type CanvasColor = string | 1 | 2 | 3 | 4 | 5 | 6;

0 commit comments

Comments
 (0)