@quantumwake/kgraph 0.1.2
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/LICENSE +21 -0
- package/README.md +245 -0
- package/dist/index.cjs +1347 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +309 -0
- package/dist/index.d.ts +309 -0
- package/dist/index.js +1328 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
|
|
4
|
+
interface KGraphNode {
|
|
5
|
+
id: string;
|
|
6
|
+
type: string;
|
|
7
|
+
position: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
data: Record<string, any>;
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
dragging?: boolean;
|
|
14
|
+
hidden?: boolean;
|
|
15
|
+
width?: number;
|
|
16
|
+
height?: number;
|
|
17
|
+
group?: string;
|
|
18
|
+
}
|
|
19
|
+
interface KGraphEdge {
|
|
20
|
+
id: string;
|
|
21
|
+
source: string;
|
|
22
|
+
target: string;
|
|
23
|
+
sourceHandle?: string;
|
|
24
|
+
targetHandle?: string;
|
|
25
|
+
type?: string;
|
|
26
|
+
data?: Record<string, any>;
|
|
27
|
+
selected?: boolean;
|
|
28
|
+
animated?: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface KGraphConnection {
|
|
31
|
+
source: string;
|
|
32
|
+
target: string;
|
|
33
|
+
sourceHandle?: string;
|
|
34
|
+
targetHandle?: string;
|
|
35
|
+
}
|
|
36
|
+
type HandlePosition = 'top' | 'right' | 'bottom' | 'left';
|
|
37
|
+
type HandleType = 'source' | 'target';
|
|
38
|
+
interface HandleInfo {
|
|
39
|
+
nodeId: string;
|
|
40
|
+
handleId: string;
|
|
41
|
+
type: HandleType;
|
|
42
|
+
position: HandlePosition;
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
}
|
|
46
|
+
type NodeChange = {
|
|
47
|
+
type: 'position';
|
|
48
|
+
id: string;
|
|
49
|
+
position?: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
};
|
|
53
|
+
dragging: boolean;
|
|
54
|
+
} | {
|
|
55
|
+
type: 'select';
|
|
56
|
+
id: string;
|
|
57
|
+
selected: boolean;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'remove';
|
|
60
|
+
id: string;
|
|
61
|
+
} | {
|
|
62
|
+
type: 'add';
|
|
63
|
+
item: KGraphNode;
|
|
64
|
+
} | {
|
|
65
|
+
type: 'dimensions';
|
|
66
|
+
id: string;
|
|
67
|
+
dimensions: {
|
|
68
|
+
width: number;
|
|
69
|
+
height: number;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
type EdgeChange = {
|
|
73
|
+
type: 'select';
|
|
74
|
+
id: string;
|
|
75
|
+
selected: boolean;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'remove';
|
|
78
|
+
id: string;
|
|
79
|
+
} | {
|
|
80
|
+
type: 'add';
|
|
81
|
+
item: KGraphEdge;
|
|
82
|
+
};
|
|
83
|
+
interface KGraphViewport {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
zoom: number;
|
|
87
|
+
}
|
|
88
|
+
interface NodeComponentProps {
|
|
89
|
+
id: string;
|
|
90
|
+
data: Record<string, any>;
|
|
91
|
+
selected: boolean;
|
|
92
|
+
type: string;
|
|
93
|
+
}
|
|
94
|
+
interface EdgeComponentProps {
|
|
95
|
+
id: string;
|
|
96
|
+
sourceX: number;
|
|
97
|
+
sourceY: number;
|
|
98
|
+
targetX: number;
|
|
99
|
+
targetY: number;
|
|
100
|
+
sourcePosition: HandlePosition;
|
|
101
|
+
targetPosition: HandlePosition;
|
|
102
|
+
selected: boolean;
|
|
103
|
+
data?: Record<string, any>;
|
|
104
|
+
animated?: boolean;
|
|
105
|
+
style?: React__default.CSSProperties;
|
|
106
|
+
}
|
|
107
|
+
interface HandleProps {
|
|
108
|
+
id: string;
|
|
109
|
+
type: HandleType;
|
|
110
|
+
position: HandlePosition;
|
|
111
|
+
style?: React__default.CSSProperties;
|
|
112
|
+
className?: string;
|
|
113
|
+
}
|
|
114
|
+
interface KGraphCanvasProps {
|
|
115
|
+
nodes: KGraphNode[];
|
|
116
|
+
edges: KGraphEdge[];
|
|
117
|
+
onNodesChange?: (changes: NodeChange[]) => void;
|
|
118
|
+
onEdgesChange?: (changes: EdgeChange[]) => void;
|
|
119
|
+
onConnect?: (connection: KGraphConnection) => void;
|
|
120
|
+
onNodeClick?: (event: React__default.MouseEvent, node: KGraphNode) => void;
|
|
121
|
+
onEdgeClick?: (event: React__default.MouseEvent, edge: KGraphEdge) => void;
|
|
122
|
+
onPaneClick?: (event: React__default.MouseEvent) => void;
|
|
123
|
+
onDrop?: (event: React__default.DragEvent, position: {
|
|
124
|
+
x: number;
|
|
125
|
+
y: number;
|
|
126
|
+
}) => void;
|
|
127
|
+
onDragOver?: (event: React__default.DragEvent) => void;
|
|
128
|
+
nodeTypes?: Record<string, React__default.ComponentType<NodeComponentProps>>;
|
|
129
|
+
edgeTypes?: Record<string, React__default.ComponentType<EdgeComponentProps>>;
|
|
130
|
+
snapToGrid?: boolean;
|
|
131
|
+
snapGrid?: [number, number];
|
|
132
|
+
panOnDrag?: boolean;
|
|
133
|
+
zoomOnScroll?: boolean;
|
|
134
|
+
nodesDraggable?: boolean;
|
|
135
|
+
nodesConnectable?: boolean;
|
|
136
|
+
elementsSelectable?: boolean;
|
|
137
|
+
fitView?: boolean;
|
|
138
|
+
showMiniMap?: boolean;
|
|
139
|
+
showBackground?: boolean;
|
|
140
|
+
backgroundGap?: number;
|
|
141
|
+
minZoom?: number;
|
|
142
|
+
maxZoom?: number;
|
|
143
|
+
className?: string;
|
|
144
|
+
style?: React__default.CSSProperties;
|
|
145
|
+
children?: React__default.ReactNode;
|
|
146
|
+
}
|
|
147
|
+
interface KGraphContextValue {
|
|
148
|
+
viewport: KGraphViewport;
|
|
149
|
+
setViewport: React__default.Dispatch<React__default.SetStateAction<KGraphViewport>>;
|
|
150
|
+
screenToCanvasPosition: (screenX: number, screenY: number) => {
|
|
151
|
+
x: number;
|
|
152
|
+
y: number;
|
|
153
|
+
};
|
|
154
|
+
canvasToScreenPosition: (canvasX: number, canvasY: number) => {
|
|
155
|
+
x: number;
|
|
156
|
+
y: number;
|
|
157
|
+
};
|
|
158
|
+
fitView: (options?: {
|
|
159
|
+
padding?: number;
|
|
160
|
+
}) => void;
|
|
161
|
+
zoomIn: () => void;
|
|
162
|
+
zoomOut: () => void;
|
|
163
|
+
zoomTo: (level: number) => void;
|
|
164
|
+
registerHandle: (info: HandleInfo) => void;
|
|
165
|
+
unregisterHandle: (nodeId: string, handleId: string) => void;
|
|
166
|
+
getHandlePosition: (nodeId: string, handleId: string) => HandleInfo | undefined;
|
|
167
|
+
getAllHandles: () => Map<string, HandleInfo>;
|
|
168
|
+
containerRef: React__default.RefObject<HTMLDivElement | null>;
|
|
169
|
+
nodes: KGraphNode[];
|
|
170
|
+
edges: KGraphEdge[];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare const KGraphCanvas: React__default.FC<KGraphCanvasProps>;
|
|
174
|
+
|
|
175
|
+
declare function useKGraphContext(): KGraphContextValue;
|
|
176
|
+
interface KGraphProviderProps {
|
|
177
|
+
children: React__default.ReactNode;
|
|
178
|
+
nodes: KGraphNode[];
|
|
179
|
+
edges: KGraphEdge[];
|
|
180
|
+
initialViewport?: KGraphViewport;
|
|
181
|
+
minZoom?: number;
|
|
182
|
+
maxZoom?: number;
|
|
183
|
+
}
|
|
184
|
+
declare const KGraphProvider: React__default.FC<KGraphProviderProps>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Public hook for accessing KGraph viewport controls.
|
|
188
|
+
* Drop-in replacement for ReactFlow's useReactFlow().
|
|
189
|
+
*/
|
|
190
|
+
declare function useKGraph(): {
|
|
191
|
+
screenToCanvasPosition: (screenX: number, screenY: number) => {
|
|
192
|
+
x: number;
|
|
193
|
+
y: number;
|
|
194
|
+
};
|
|
195
|
+
fitView: (options?: {
|
|
196
|
+
padding?: number;
|
|
197
|
+
}) => void;
|
|
198
|
+
zoomIn: () => void;
|
|
199
|
+
zoomOut: () => void;
|
|
200
|
+
zoomTo: (level: number) => void;
|
|
201
|
+
getViewport: () => KGraphViewport;
|
|
202
|
+
setViewport: React.Dispatch<React.SetStateAction<KGraphViewport>>;
|
|
203
|
+
getNodes: () => KGraphNode[];
|
|
204
|
+
getEdges: () => KGraphEdge[];
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
interface KGraphHandleProps extends HandleProps {
|
|
208
|
+
nodeId?: string;
|
|
209
|
+
onConnectionStart?: (nodeId: string, handleId: string, type: 'source' | 'target', e: React__default.MouseEvent) => void;
|
|
210
|
+
}
|
|
211
|
+
declare const Handle: React__default.FC<KGraphHandleProps>;
|
|
212
|
+
|
|
213
|
+
interface EdgeLabelProps {
|
|
214
|
+
x: number;
|
|
215
|
+
y: number;
|
|
216
|
+
zoom: number;
|
|
217
|
+
children: React__default.ReactNode;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* EdgeLabel renders children as an HTML overlay at the given canvas coordinates.
|
|
221
|
+
* Replaces ReactFlow's EdgeLabelRenderer.
|
|
222
|
+
* The content is scaled inversely to the zoom level so it stays a consistent screen size.
|
|
223
|
+
*/
|
|
224
|
+
declare const EdgeLabel: React__default.FC<EdgeLabelProps>;
|
|
225
|
+
|
|
226
|
+
interface NodeRendererProps {
|
|
227
|
+
nodes: KGraphNode[];
|
|
228
|
+
nodeTypes: Record<string, React__default.ComponentType<NodeComponentProps>>;
|
|
229
|
+
defaultNodeType?: React__default.ComponentType<NodeComponentProps>;
|
|
230
|
+
onNodesChange?: (changes: NodeChange[]) => void;
|
|
231
|
+
snapToGrid: boolean;
|
|
232
|
+
snapGrid: [number, number];
|
|
233
|
+
draggable: boolean;
|
|
234
|
+
selectable: boolean;
|
|
235
|
+
onNodeClick?: (event: React__default.MouseEvent, node: KGraphNode) => void;
|
|
236
|
+
onConnectionStart?: (nodeId: string, handleId: string, type: 'source' | 'target', e: React__default.MouseEvent) => void;
|
|
237
|
+
zoom: number;
|
|
238
|
+
}
|
|
239
|
+
declare const NodeRenderer: React__default.FC<NodeRendererProps>;
|
|
240
|
+
|
|
241
|
+
interface EdgeRendererProps {
|
|
242
|
+
edges: KGraphEdge[];
|
|
243
|
+
edgeTypes: Record<string, React__default.ComponentType<EdgeComponentProps>>;
|
|
244
|
+
onEdgeClick?: (event: React__default.MouseEvent, edge: KGraphEdge) => void;
|
|
245
|
+
selectedEdgeId?: string | null;
|
|
246
|
+
}
|
|
247
|
+
declare const EdgeRenderer: React__default.FC<EdgeRendererProps>;
|
|
248
|
+
|
|
249
|
+
interface ConnectionLineProps {
|
|
250
|
+
sourceX: number;
|
|
251
|
+
sourceY: number;
|
|
252
|
+
sourcePosition: HandlePosition;
|
|
253
|
+
targetX: number;
|
|
254
|
+
targetY: number;
|
|
255
|
+
}
|
|
256
|
+
declare const ConnectionLine: React__default.FC<ConnectionLineProps>;
|
|
257
|
+
|
|
258
|
+
interface DotGridProps {
|
|
259
|
+
viewport: KGraphViewport;
|
|
260
|
+
gap?: number;
|
|
261
|
+
color?: string;
|
|
262
|
+
size?: number;
|
|
263
|
+
}
|
|
264
|
+
declare const DotGrid: React__default.FC<DotGridProps>;
|
|
265
|
+
|
|
266
|
+
interface MiniMapProps {
|
|
267
|
+
nodes: KGraphNode[];
|
|
268
|
+
viewport: KGraphViewport;
|
|
269
|
+
width?: number;
|
|
270
|
+
height?: number;
|
|
271
|
+
nodeColor?: string | ((node: KGraphNode) => string);
|
|
272
|
+
maskColor?: string;
|
|
273
|
+
backgroundColor?: string;
|
|
274
|
+
borderColor?: string;
|
|
275
|
+
onViewportChange?: (viewport: KGraphViewport) => void;
|
|
276
|
+
containerWidth: number;
|
|
277
|
+
containerHeight: number;
|
|
278
|
+
}
|
|
279
|
+
declare const MiniMap: React__default.FC<MiniMapProps>;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Compute a cubic bezier path between two points with directional control points.
|
|
283
|
+
* Drop-in replacement for ReactFlow's getBezierPath — uses the same control point
|
|
284
|
+
* algorithm so curves look identical.
|
|
285
|
+
*
|
|
286
|
+
* Returns [pathString, labelX, labelY, offsetX, offsetY]
|
|
287
|
+
*/
|
|
288
|
+
declare function getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, curvature, }: {
|
|
289
|
+
sourceX: number;
|
|
290
|
+
sourceY: number;
|
|
291
|
+
sourcePosition?: HandlePosition;
|
|
292
|
+
targetX: number;
|
|
293
|
+
targetY: number;
|
|
294
|
+
targetPosition?: HandlePosition;
|
|
295
|
+
curvature?: number;
|
|
296
|
+
}): [string, number, number, number, number];
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Apply an array of node changes immutably.
|
|
300
|
+
* Drop-in replacement for ReactFlow's applyNodeChanges.
|
|
301
|
+
*/
|
|
302
|
+
declare function applyNodeChanges(changes: NodeChange[], nodes: KGraphNode[]): KGraphNode[];
|
|
303
|
+
/**
|
|
304
|
+
* Apply an array of edge changes immutably.
|
|
305
|
+
* Drop-in replacement for ReactFlow's applyEdgeChanges.
|
|
306
|
+
*/
|
|
307
|
+
declare function applyEdgeChanges(changes: EdgeChange[], edges: KGraphEdge[]): KGraphEdge[];
|
|
308
|
+
|
|
309
|
+
export { ConnectionLine, DotGrid, type EdgeChange, type EdgeComponentProps, EdgeLabel, EdgeRenderer, Handle, type HandleInfo, type HandlePosition, type HandleProps, type HandleType, KGraphCanvas, type KGraphCanvasProps, type KGraphConnection, type KGraphContextValue, type KGraphEdge, type KGraphNode, KGraphProvider, type KGraphViewport, MiniMap, type NodeChange, type NodeComponentProps, NodeRenderer, applyEdgeChanges, applyNodeChanges, getBezierPath, useKGraph, useKGraphContext };
|