forked from obsidianmd/jsoncanvas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON schema for JsonCanvas, CanvasNode, CanvasColor, and Edge int…
…erfaces. 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
- Loading branch information
Showing
2 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/JsonCanvas", | ||
"definitions": { | ||
"JsonCanvas": { | ||
"type": "object", | ||
"properties": { | ||
"nodes": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/CanvasNode" | ||
} | ||
}, | ||
"edges": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/definitions/Edge" | ||
} | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"description": "Top-level interface for the JSON Canvas Spec" | ||
}, | ||
"CanvasNode": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string", | ||
"enum": [ | ||
"text", | ||
"file", | ||
"link", | ||
"group" | ||
] | ||
}, | ||
"x": { | ||
"type": "number" | ||
}, | ||
"y": { | ||
"type": "number" | ||
}, | ||
"width": { | ||
"type": "number" | ||
}, | ||
"height": { | ||
"type": "number" | ||
}, | ||
"color": { | ||
"$ref": "#/definitions/CanvasColor" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"type", | ||
"x", | ||
"y", | ||
"width", | ||
"height" | ||
], | ||
"additionalProperties": false, | ||
"description": "Base node interface for common attributes" | ||
}, | ||
"CanvasColor": { | ||
"anyOf": [ | ||
{ | ||
"type": "string" | ||
}, | ||
{ | ||
"type": "number", | ||
"const": 1 | ||
}, | ||
{ | ||
"type": "number", | ||
"const": 2 | ||
}, | ||
{ | ||
"type": "number", | ||
"const": 3 | ||
}, | ||
{ | ||
"type": "number", | ||
"const": 4 | ||
}, | ||
{ | ||
"type": "number", | ||
"const": 5 | ||
}, | ||
{ | ||
"type": "number", | ||
"const": 6 | ||
} | ||
], | ||
"description": "Type for color, either a string for hex values or a number for preset colors" | ||
}, | ||
"Edge": { | ||
"type": "object", | ||
"properties": { | ||
"id": { | ||
"type": "string" | ||
}, | ||
"fromNode": { | ||
"type": "string" | ||
}, | ||
"fromSide": { | ||
"type": "string", | ||
"enum": [ | ||
"top", | ||
"right", | ||
"bottom", | ||
"left" | ||
], | ||
"description": "Optional side of the node where the edge starts" | ||
}, | ||
"fromEnd": { | ||
"type": "string", | ||
"enum": [ | ||
"none", | ||
"arrow" | ||
], | ||
"description": "Optional style of the edge end" | ||
}, | ||
"toNode": { | ||
"type": "string" | ||
}, | ||
"toSide": { | ||
"type": "string", | ||
"enum": [ | ||
"top", | ||
"right", | ||
"bottom", | ||
"left" | ||
], | ||
"description": "Optional side of the node where the edge ends" | ||
}, | ||
"toEnd": { | ||
"type": "string", | ||
"enum": [ | ||
"none", | ||
"arrow" | ||
], | ||
"description": "Optional style of the edge end" | ||
}, | ||
"color": { | ||
"$ref": "#/definitions/CanvasColor" | ||
}, | ||
"label": { | ||
"type": "string", | ||
"description": "Optional label for the edge" | ||
} | ||
}, | ||
"required": [ | ||
"id", | ||
"fromNode", | ||
"toNode" | ||
], | ||
"additionalProperties": false, | ||
"description": "Edge interface for connections between nodes" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/** | ||
* Top-level interface for the JSON Canvas Spec | ||
*/ | ||
export interface JsonCanvas { | ||
nodes?: CanvasNode[]; | ||
edges?: Edge[]; | ||
} | ||
|
||
export default JsonCanvas; | ||
|
||
/** | ||
* Base node interface for common attributes | ||
*/ | ||
export interface CanvasNode { | ||
id: string; | ||
type: "text" | "file" | "link" | "group"; | ||
x: number; | ||
y: number; | ||
width: number; | ||
height: number; | ||
color?: CanvasColor; | ||
} | ||
|
||
/** | ||
* Extended node interface for TextNode type | ||
*/ | ||
export interface TextNode extends CanvasNode { | ||
type: "text"; | ||
/** | ||
* Text content with Markdown syntax | ||
*/ | ||
text: string; | ||
} | ||
|
||
/** | ||
* Extended node interface for FileNode type | ||
*/ | ||
export interface FileNode extends CanvasNode { | ||
type: "file"; | ||
/** | ||
* Path to the file | ||
*/ | ||
file: string; | ||
/** | ||
* Optional subpath within the file | ||
*/ | ||
subpath?: string; | ||
} | ||
|
||
/** | ||
* Extended node interface for LinkNode type | ||
*/ | ||
export interface LinkNode extends CanvasNode { | ||
type: "link"; | ||
/** | ||
* URL the node references | ||
*/ | ||
url: string; | ||
} | ||
|
||
/** | ||
* Extended node interface for GroupNode type | ||
*/ | ||
export interface GroupNode extends CanvasNode { | ||
type: "group"; | ||
/** | ||
* Optional text label for the group | ||
*/ | ||
label?: string; | ||
/** | ||
* Optional path to a background image | ||
*/ | ||
background?: string; | ||
/** | ||
* Optional rendering style of the background | ||
*/ | ||
backgroundStyle?: "cover" | "ratio" | "repeat"; | ||
} | ||
|
||
/** | ||
* Union type for all node types | ||
*/ | ||
export type AllNodes = TextNode | FileNode | LinkNode | GroupNode; | ||
|
||
/** | ||
* Edge interface for connections between nodes | ||
*/ | ||
export interface Edge { | ||
id: string; | ||
fromNode: string; | ||
/** | ||
* Optional side of the node where the edge starts | ||
*/ | ||
fromSide?: "top" | "right" | "bottom" | "left"; | ||
/** | ||
* Optional style of the edge end | ||
*/ | ||
fromEnd?: "none" | "arrow"; | ||
toNode: string; | ||
/** | ||
* Optional side of the node where the edge ends | ||
*/ | ||
toSide?: "top" | "right" | "bottom" | "left"; | ||
/** | ||
* Optional style of the edge end | ||
*/ | ||
toEnd?: "none" | "arrow"; | ||
color?: CanvasColor; | ||
/** | ||
* Optional label for the edge | ||
*/ | ||
label?: string; | ||
} | ||
|
||
/** | ||
* Type for color, either a string for hex values or a number for preset colors | ||
*/ | ||
export type CanvasColor = string | 1 | 2 | 3 | 4 | 5 | 6; |