@intinyagroup/diagram 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,65 @@
1
+ <script lang="ts">
2
+ import { SvelteFlow, Background, Controls, MiniMap } from "@xyflow/svelte";
3
+ import type { Snippet } from "svelte";
4
+ import type {
5
+ GraphEdge,
6
+ GraphNode,
7
+ GraphNodeTypeMap,
8
+ GraphViewport,
9
+ } from "./types.js";
10
+
11
+ let {
12
+ nodes = [],
13
+ edges = [],
14
+ nodeTypes = {},
15
+ viewport,
16
+ fitView = true,
17
+ showBackground = true,
18
+ showControls = true,
19
+ showMiniMap = false,
20
+ class: className,
21
+ children,
22
+ onConnect,
23
+ onNodeClick,
24
+ onPaneClick,
25
+ }: {
26
+ nodes?: GraphNode[];
27
+ edges?: GraphEdge[];
28
+ nodeTypes?: GraphNodeTypeMap;
29
+ viewport?: GraphViewport;
30
+ fitView?: boolean;
31
+ showBackground?: boolean;
32
+ showControls?: boolean;
33
+ showMiniMap?: boolean;
34
+ class?: string;
35
+ children?: Snippet;
36
+ onConnect?: (connection: unknown) => void;
37
+ onNodeClick?: (event: MouseEvent | TouchEvent, node: GraphNode) => void;
38
+ onPaneClick?: (event: MouseEvent) => void;
39
+ } = $props();
40
+
41
+ const flowNodes = $derived(
42
+ nodes.map((node) => ({ ...node, data: node.data ?? {} })),
43
+ );
44
+ </script>
45
+
46
+ <div
47
+ class={`relative h-full min-h-0 w-full overflow-hidden ${className ?? ""}`}
48
+ data-slot="flow-canvas"
49
+ >
50
+ <SvelteFlow
51
+ nodes={flowNodes as any}
52
+ edges={edges as any}
53
+ {nodeTypes}
54
+ {fitView}
55
+ {viewport}
56
+ onconnect={(connection) => onConnect?.(connection)}
57
+ onnodeclick={({ event, node }) => onNodeClick?.(event, node as GraphNode)}
58
+ onpaneclick={({ event }) => onPaneClick?.(event)}
59
+ >
60
+ {#if showBackground}<Background />{/if}
61
+ {#if showControls}<Controls />{/if}
62
+ {#if showMiniMap}<MiniMap />{/if}
63
+ {@render children?.()}
64
+ </SvelteFlow>
65
+ </div>
@@ -0,0 +1,20 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { GraphEdge, GraphNode, GraphNodeTypeMap, GraphViewport } from "./types.js";
3
+ type $$ComponentProps = {
4
+ nodes?: GraphNode[];
5
+ edges?: GraphEdge[];
6
+ nodeTypes?: GraphNodeTypeMap;
7
+ viewport?: GraphViewport;
8
+ fitView?: boolean;
9
+ showBackground?: boolean;
10
+ showControls?: boolean;
11
+ showMiniMap?: boolean;
12
+ class?: string;
13
+ children?: Snippet;
14
+ onConnect?: (connection: unknown) => void;
15
+ onNodeClick?: (event: MouseEvent | TouchEvent, node: GraphNode) => void;
16
+ onPaneClick?: (event: MouseEvent) => void;
17
+ };
18
+ declare const FlowCanvas: import("svelte").Component<$$ComponentProps, {}, "">;
19
+ type FlowCanvas = ReturnType<typeof FlowCanvas>;
20
+ export default FlowCanvas;
@@ -0,0 +1,12 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ let { children, class: className }: { children?: Snippet; class?: string } =
4
+ $props();
5
+ </script>
6
+
7
+ <div
8
+ class={`pointer-events-auto absolute left-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border bg-card/95 p-1 shadow-lg backdrop-blur-xl ${className ?? ""}`}
9
+ data-slot="graph-toolbar"
10
+ >
11
+ {@render children?.()}
12
+ </div>
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children?: Snippet;
4
+ class?: string;
5
+ };
6
+ declare const GraphToolbar: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type GraphToolbar = ReturnType<typeof GraphToolbar>;
8
+ export default GraphToolbar;
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ let {
4
+ title = "Inspector",
5
+ description,
6
+ children,
7
+ class: className,
8
+ }: {
9
+ title?: string;
10
+ description?: string;
11
+ children?: Snippet;
12
+ class?: string;
13
+ } = $props();
14
+ </script>
15
+
16
+ <aside
17
+ class={`flex h-full w-80 flex-col border-l border-border bg-card text-card-foreground ${className ?? ""}`}
18
+ data-slot="inspector-shell"
19
+ aria-label={title}
20
+ >
21
+ <header class="shrink-0 border-b border-border px-4 py-3">
22
+ <h2 class="text-sm font-semibold">{title}</h2>
23
+ {#if description}<p class="mt-1 text-xs text-muted-foreground">
24
+ {description}
25
+ </p>{/if}
26
+ </header>
27
+ <div class="min-h-0 flex-1 overflow-y-auto p-4">
28
+ {@render children?.()}
29
+ </div>
30
+ </aside>
@@ -0,0 +1,10 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ title?: string;
4
+ description?: string;
5
+ children?: Snippet;
6
+ class?: string;
7
+ };
8
+ declare const InspectorShell: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type InspectorShell = ReturnType<typeof InspectorShell>;
10
+ export default InspectorShell;
@@ -0,0 +1,16 @@
1
+ import type { GraphEdge, GraphNode, GraphViewport } from "./types.js";
2
+ export type GraphDocument = {
3
+ version: 1;
4
+ nodes: GraphNode[];
5
+ edges: GraphEdge[];
6
+ viewport?: GraphViewport;
7
+ };
8
+ export declare function graphToJson(document: GraphDocument): string;
9
+ export declare function graphFromJson(input: string): GraphDocument;
10
+ export declare function createGraphAdapter(initial?: GraphDocument): {
11
+ readonly snapshot: GraphDocument;
12
+ setNodes(nodes: GraphNode[]): void;
13
+ setEdges(edges: GraphEdge[]): void;
14
+ setViewport(viewport: GraphViewport): void;
15
+ toJSON(): string;
16
+ };
@@ -0,0 +1,40 @@
1
+ export function graphToJson(document) {
2
+ return JSON.stringify(document, null, 2);
3
+ }
4
+ export function graphFromJson(input) {
5
+ const parsed = JSON.parse(input);
6
+ if (!parsed || typeof parsed !== "object")
7
+ throw new Error("Graph document must be an object");
8
+ const value = parsed;
9
+ if (value.version !== 1 ||
10
+ !Array.isArray(value.nodes) ||
11
+ !Array.isArray(value.edges)) {
12
+ throw new Error("Unsupported graph document");
13
+ }
14
+ return {
15
+ version: 1,
16
+ nodes: value.nodes,
17
+ edges: value.edges,
18
+ viewport: value.viewport,
19
+ };
20
+ }
21
+ export function createGraphAdapter(initial = { version: 1, nodes: [], edges: [] }) {
22
+ let document = structuredClone(initial);
23
+ return {
24
+ get snapshot() {
25
+ return structuredClone(document);
26
+ },
27
+ setNodes(nodes) {
28
+ document = { ...document, nodes: structuredClone(nodes) };
29
+ },
30
+ setEdges(edges) {
31
+ document = { ...document, edges: structuredClone(edges) };
32
+ },
33
+ setViewport(viewport) {
34
+ document = { ...document, viewport: { ...viewport } };
35
+ },
36
+ toJSON() {
37
+ return graphToJson(document);
38
+ },
39
+ };
40
+ }
@@ -0,0 +1,6 @@
1
+ export { Handle as FlowHandle, Position } from "@xyflow/svelte";
2
+ export { default as FlowCanvas } from "./FlowCanvas.svelte";
3
+ export { default as GraphToolbar } from "./GraphToolbar.svelte";
4
+ export { default as InspectorShell } from "./InspectorShell.svelte";
5
+ export type { GraphNode, GraphEdge, GraphHandle, GraphViewport, GraphChange, GraphNodeTypeMap, InspectorField, } from "./types.js";
6
+ export { createGraphAdapter, graphToJson, graphFromJson, } from "./graph-adapter.js";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { Handle as FlowHandle, Position } from "@xyflow/svelte";
2
+ export { default as FlowCanvas } from "./FlowCanvas.svelte";
3
+ export { default as GraphToolbar } from "./GraphToolbar.svelte";
4
+ export { default as InspectorShell } from "./InspectorShell.svelte";
5
+ export { createGraphAdapter, graphToJson, graphFromJson, } from "./graph-adapter.js";
@@ -0,0 +1,74 @@
1
+ import type { Component, Snippet } from "svelte";
2
+ export type GraphViewport = {
3
+ x: number;
4
+ y: number;
5
+ zoom: number;
6
+ };
7
+ export type GraphHandle = {
8
+ id: string;
9
+ type: "source" | "target";
10
+ position?: "top" | "right" | "bottom" | "left";
11
+ dataType?: string;
12
+ multiple?: boolean;
13
+ };
14
+ export type GraphNode = {
15
+ id: string;
16
+ type: string;
17
+ position: {
18
+ x: number;
19
+ y: number;
20
+ };
21
+ data?: Record<string, unknown>;
22
+ handles?: GraphHandle[];
23
+ selected?: boolean;
24
+ hidden?: boolean;
25
+ };
26
+ export type GraphEdge = {
27
+ id: string;
28
+ source: string;
29
+ target: string;
30
+ sourceHandle?: string;
31
+ targetHandle?: string;
32
+ type?: string;
33
+ data?: Record<string, unknown>;
34
+ selected?: boolean;
35
+ animated?: boolean;
36
+ };
37
+ export type GraphChange = {
38
+ type: "node-position";
39
+ id: string;
40
+ position: {
41
+ x: number;
42
+ y: number;
43
+ };
44
+ } | {
45
+ type: "node-select";
46
+ id: string;
47
+ selected: boolean;
48
+ } | {
49
+ type: "node-remove";
50
+ id: string;
51
+ } | {
52
+ type: "edge-remove";
53
+ id: string;
54
+ } | {
55
+ type: "edge-add";
56
+ edge: GraphEdge;
57
+ };
58
+ export type GraphNodeTypeMap = Record<string, Component>;
59
+ export type InspectorField = {
60
+ id: string;
61
+ label: string;
62
+ type: "text" | "number" | "select" | "boolean" | "textarea" | "secret";
63
+ description?: string;
64
+ options?: Array<{
65
+ label: string;
66
+ value: string;
67
+ }>;
68
+ required?: boolean;
69
+ };
70
+ export type InspectorShellProps = {
71
+ title?: string;
72
+ description?: string;
73
+ children?: Snippet;
74
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@intinyagroup/diagram",
3
+ "version": "0.1.0",
4
+ "description": "Reusable Svelte node-graph and workflow canvas primitives",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "svelte": "./dist/index.js",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "scripts": {
19
+ "build": "svelte-package -o dist",
20
+ "check": "svelte-check --tsconfig ./tsconfig.json",
21
+ "test": "vitest run"
22
+ },
23
+ "dependencies": {
24
+ "@intinyagroup/ui": "workspace:*",
25
+ "@xyflow/svelte": "^1.6.6"
26
+ },
27
+ "devDependencies": {
28
+ "@intinyagroup/vitest-preset": "workspace:*",
29
+ "@sveltejs/package": "^2.5.8",
30
+ "@sveltejs/vite-plugin-svelte": "^5.1.1",
31
+ "svelte": "^5.55.2",
32
+ "svelte-check": "^4.4.6",
33
+ "typescript": "^6.0.2",
34
+ "vitest": "^5.0.0"
35
+ },
36
+ "peerDependencies": {
37
+ "svelte": "^5.0.0"
38
+ },
39
+ "license": "MIT",
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }