@ruckc/truss-graph 1.0.0 → 1.1.1
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.
- package/dist/Graph.svelte.d.ts +46 -0
- package/dist/index.d.ts +4 -0
- package/dist/layout.d.ts +10 -0
- package/dist/routing.d.ts +25 -0
- package/dist/types.d.ts +58 -0
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import { type EdgeType, type GraphEdge, type GraphNode, type NodeRenderer } from './types.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
nodes?: GraphNode[];
|
|
5
|
+
edges?: GraphEdge[];
|
|
6
|
+
/** Selected node ids. */
|
|
7
|
+
selected?: string[];
|
|
8
|
+
selectedEdge?: string;
|
|
9
|
+
height?: number | string;
|
|
10
|
+
/** Default routing for every edge (an edge's own `type` wins): bezier, straight, step, smoothstep, or avoid (steers around nodes). */
|
|
11
|
+
edgeType?: EdgeType;
|
|
12
|
+
/** Which sides the default ports use, and the direction of auto layout. */
|
|
13
|
+
direction?: 'LR' | 'TB';
|
|
14
|
+
/** Drag from an output port to an input port to create edges. */
|
|
15
|
+
connectable?: boolean;
|
|
16
|
+
/** Allow moving and deleting. */
|
|
17
|
+
editable?: boolean;
|
|
18
|
+
fitOnMount?: boolean;
|
|
19
|
+
/** Overview panel showing every node and the current viewport; click or drag it to pan. */
|
|
20
|
+
minimap?: boolean;
|
|
21
|
+
minimapPosition?: 'bottom-right' | 'bottom-left';
|
|
22
|
+
/** Custom node components by `node.type`. Each is a snippet receiving `{ node, selected, dragging, update }` and draws the whole node. */
|
|
23
|
+
nodeTypes?: Record<string, NodeRenderer>;
|
|
24
|
+
/** Custom component for every node that has no matching `nodeTypes` entry. */
|
|
25
|
+
node?: NodeRenderer;
|
|
26
|
+
/** Content inside the default card, under the title. */
|
|
27
|
+
body?: Snippet<[node: GraphNode]>;
|
|
28
|
+
/** Custom component rendered at the middle of each edge (replaces `edge.label`). */
|
|
29
|
+
edgeLabel?: Snippet<[edge: GraphEdge]>;
|
|
30
|
+
/** Return false to reject a connection. */
|
|
31
|
+
isValidConnection?: (from: {
|
|
32
|
+
node: string;
|
|
33
|
+
port: string;
|
|
34
|
+
}, to: {
|
|
35
|
+
node: string;
|
|
36
|
+
port: string;
|
|
37
|
+
}) => boolean;
|
|
38
|
+
onconnect?: (edge: GraphEdge) => void;
|
|
39
|
+
onchange?: () => void;
|
|
40
|
+
};
|
|
41
|
+
declare const Graph: import("svelte").Component<$$ComponentProps, {
|
|
42
|
+
fit: (padding?: number) => void;
|
|
43
|
+
layout: () => void;
|
|
44
|
+
}, "selected" | "nodes" | "edges" | "selectedEdge">;
|
|
45
|
+
type Graph = ReturnType<typeof Graph>;
|
|
46
|
+
export default Graph;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as Graph } from './Graph.svelte';
|
|
2
|
+
export { autoLayout } from './layout.js';
|
|
3
|
+
export { routeEdge, portAnchor, defaultPorts } from './routing.js';
|
|
4
|
+
export type { GraphNode, GraphEdge, GraphPort, NodeKind, NodeCtx, NodeRenderer, EdgeType, Side } from './types.js';
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type GraphEdge, type GraphNode } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Layered (Sugiyama-lite) auto layout: longest-path layering, one barycenter sweep to
|
|
4
|
+
* reduce crossings, columns centred vertically. Cycle-safe. Returns new node objects.
|
|
5
|
+
*/
|
|
6
|
+
export declare function autoLayout(nodes: GraphNode[], edges: GraphEdge[], opts?: {
|
|
7
|
+
gapX?: number;
|
|
8
|
+
gapY?: number;
|
|
9
|
+
direction?: 'LR' | 'TB';
|
|
10
|
+
}): GraphNode[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EdgeType, GraphNode, GraphPort, Side } from './types.js';
|
|
2
|
+
export type Pt = {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
};
|
|
6
|
+
export type Anchor = Pt & {
|
|
7
|
+
side: Side;
|
|
8
|
+
};
|
|
9
|
+
export type Rect = {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
w: number;
|
|
13
|
+
h: number;
|
|
14
|
+
id?: string;
|
|
15
|
+
};
|
|
16
|
+
export type Routed = {
|
|
17
|
+
d: string;
|
|
18
|
+
mid: Pt;
|
|
19
|
+
};
|
|
20
|
+
export declare const opposite: (s: Side) => Side;
|
|
21
|
+
export declare function defaultPorts(n: GraphNode, direction?: 'LR' | 'TB'): GraphPort[];
|
|
22
|
+
/** Where a port sits on its node; several ports on one side are spread evenly. */
|
|
23
|
+
export declare function portAnchor(n: GraphNode, port: GraphPort, ports: GraphPort[]): Anchor;
|
|
24
|
+
/** Route an edge between two anchors with the chosen method. `obstacles` is only used by `avoid`. */
|
|
25
|
+
export declare function routeEdge(type: EdgeType, a: Anchor, b: Anchor, obstacles?: Rect[]): Routed;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type NodeKind = 'neutral' | 'primary' | 'success' | 'warning' | 'danger';
|
|
3
|
+
export type Side = 'left' | 'right' | 'top' | 'bottom';
|
|
4
|
+
export type EdgeType = 'bezier' | 'straight' | 'step' | 'smoothstep' | 'avoid';
|
|
5
|
+
export type GraphPort = {
|
|
6
|
+
id: string;
|
|
7
|
+
side: Side;
|
|
8
|
+
/** `out` ports start connections, `in` ports receive them. */
|
|
9
|
+
kind: 'in' | 'out';
|
|
10
|
+
label?: string;
|
|
11
|
+
};
|
|
12
|
+
export type GraphNode = {
|
|
13
|
+
id: string;
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
label: string;
|
|
17
|
+
subtitle?: string;
|
|
18
|
+
kind?: NodeKind;
|
|
19
|
+
/** Picks a renderer from the `nodeTypes` registry on <Graph>. */
|
|
20
|
+
type?: string;
|
|
21
|
+
/** Fixed size in graph units (edge math relies on it). Defaults 180×56. */
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
/** Shorthand: set false to hide the default input / output port. Ignored when `ports` is set. */
|
|
25
|
+
input?: boolean;
|
|
26
|
+
output?: boolean;
|
|
27
|
+
/** Explicit ports on any side; several per side are spread evenly. */
|
|
28
|
+
ports?: GraphPort[];
|
|
29
|
+
/** Draw the default card around a custom renderer too. By default custom renderers are bare (they draw everything). */
|
|
30
|
+
chrome?: boolean;
|
|
31
|
+
/** Free-form payload for custom node components. */
|
|
32
|
+
data?: Record<string, any>;
|
|
33
|
+
};
|
|
34
|
+
export type GraphEdge = {
|
|
35
|
+
id: string;
|
|
36
|
+
from: string;
|
|
37
|
+
to: string;
|
|
38
|
+
/** Port ids; default to the first `out` port of `from` and first `in` port of `to`. */
|
|
39
|
+
fromPort?: string;
|
|
40
|
+
toPort?: string;
|
|
41
|
+
label?: string;
|
|
42
|
+
kind?: NodeKind;
|
|
43
|
+
/** Overrides the graph-wide `edgeType` for this edge. */
|
|
44
|
+
type?: EdgeType;
|
|
45
|
+
/** Flowing dashes, e.g. for live data. */
|
|
46
|
+
animated?: boolean;
|
|
47
|
+
};
|
|
48
|
+
/** What a custom node component receives. */
|
|
49
|
+
export type NodeCtx = {
|
|
50
|
+
node: GraphNode;
|
|
51
|
+
selected: boolean;
|
|
52
|
+
dragging: boolean;
|
|
53
|
+
/** Patch this node (e.g. `update({ data: { ...node.data, value: 3 } })`). */
|
|
54
|
+
update: (patch: Partial<GraphNode>) => void;
|
|
55
|
+
};
|
|
56
|
+
export type NodeRenderer = Snippet<[ctx: NodeCtx]>;
|
|
57
|
+
export declare const NODE_W = 180;
|
|
58
|
+
export declare const NODE_H = 56;
|