@utisha/graph-editor 1.0.0 → 1.0.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.
@@ -34,6 +34,7 @@ export declare class GraphEditorComponent implements OnInit, OnChanges {
34
34
  canvasClick: EventEmitter<Position>;
35
35
  contextMenu: EventEmitter<ContextMenuEvent>;
36
36
  private readonly canvasSvgRef;
37
+ private readonly historyService;
37
38
  internalGraph: import("@angular/core").WritableSignal<Graph>;
38
39
  selection: import("@angular/core").WritableSignal<SelectionState>;
39
40
  validationResult: import("@angular/core").WritableSignal<ValidationResult | null>;
@@ -42,6 +43,8 @@ export declare class GraphEditorComponent implements OnInit, OnChanges {
42
43
  scale: import("@angular/core").WritableSignal<number>;
43
44
  private draggedNode;
44
45
  private dragOffset;
46
+ private draggedNodeOffsets;
47
+ private didDrag;
45
48
  private isPanning;
46
49
  private lastMousePos;
47
50
  private draggedEdge;
@@ -57,6 +60,14 @@ export declare class GraphEditorComponent implements OnInit, OnChanges {
57
60
  source: Position;
58
61
  target: Position;
59
62
  } | null>;
63
+ private isBoxSelecting;
64
+ private boxSelectStart;
65
+ selectionBox: import("@angular/core").WritableSignal<{
66
+ x: number;
67
+ y: number;
68
+ width: number;
69
+ height: number;
70
+ } | null>;
60
71
  transform: import("@angular/core").Signal<string>;
61
72
  gridBounds: import("@angular/core").Signal<{
62
73
  x: number;
@@ -79,6 +90,10 @@ export declare class GraphEditorComponent implements OnInit, OnChanges {
79
90
  updateNode(nodeId: string, updates: Partial<GraphNode>): void;
80
91
  selectNode(nodeId: string | null): void;
81
92
  selectEdge(edgeId: string | null): void;
93
+ /** Toggle a node in/out of the current selection (for Ctrl+Click) */
94
+ toggleNodeSelection(nodeId: string): void;
95
+ /** Toggle an edge in/out of the current selection (for Ctrl+Click) */
96
+ toggleEdgeSelection(edgeId: string): void;
82
97
  onKeyDown(event: KeyboardEvent): void;
83
98
  switchTool(tool: 'hand' | 'line'): void;
84
99
  /** @deprecated Use switchTool('line') instead */
@@ -101,6 +116,16 @@ export declare class GraphEditorComponent implements OnInit, OnChanges {
101
116
  onWheel(event: WheelEvent): void;
102
117
  onContextMenu(event: MouseEvent): void;
103
118
  private emitGraphChange;
119
+ /** Undo the last action (Ctrl+Z) */
120
+ undo(): boolean;
121
+ /** Redo the last undone action (Ctrl+Y / Ctrl+Shift+Z) */
122
+ redo(): boolean;
123
+ /** Check if undo is available */
124
+ canUndo(): boolean;
125
+ /** Check if redo is available */
126
+ canRedo(): boolean;
127
+ /** Clear history and reset to current state */
128
+ clearHistory(): void;
104
129
  private generateId;
105
130
  private recalculateEdgePorts;
106
131
  getNodeSize(node: GraphNode): {
@@ -115,6 +140,22 @@ export declare class GraphEditorComponent implements OnInit, OnChanges {
115
140
  getEdgeSourcePoint(edge: GraphEdge): Position;
116
141
  getEdgeTargetPoint(edge: GraphEdge): Position;
117
142
  getNodeTypeIcon(node: GraphNode): string;
143
+ /**
144
+ * Get custom image URL for a node.
145
+ * Checks node.data['imageUrl'] first, then falls back to nodeType.defaultData['imageUrl'].
146
+ * Returns null if no image is configured (will render text icon instead).
147
+ */
148
+ getNodeImage(node: GraphNode): string | null;
149
+ /**
150
+ * Get the position for the node image (top-left corner of image).
151
+ * Uses same positioning logic as icon but accounts for image dimensions.
152
+ */
153
+ getImagePosition(node: GraphNode): Position;
154
+ /**
155
+ * Get the size (width/height) for node images.
156
+ * Images are rendered as squares, sized proportionally to node height.
157
+ */
158
+ getImageSize(node: GraphNode): number;
118
159
  getIconPosition(node: GraphNode): Position;
119
160
  getLabelPosition(node: GraphNode): Position;
120
161
  private findNodeAtPosition;
@@ -49,6 +49,13 @@ export interface NodeTypeDefinition {
49
49
  configComponent?: Type<any>;
50
50
  /** Default data when node is created */
51
51
  defaultData: Record<string, any>;
52
+ /**
53
+ * Optional image URL for node icon. When set, renders an <image> element instead of text icon.
54
+ * Can be overridden per-instance via node.data['imageUrl'].
55
+ * Supports: SVG, PNG, JPG, data URLs, or any valid image URL.
56
+ * @example '/assets/icons/agent.svg'
57
+ * @example 'data:image/svg+xml;base64,...'
58
+ */
52
59
  /** Port definitions */
53
60
  ports?: PortConfig;
54
61
  /** Connection constraints */
@@ -0,0 +1,57 @@
1
+ import { Graph } from '../graph.model';
2
+ import * as i0 from "@angular/core";
3
+ /**
4
+ * Service for managing undo/redo history of graph state.
5
+ *
6
+ * Uses a simple snapshot-based approach where each history entry
7
+ * is a deep copy of the entire graph state.
8
+ */
9
+ export declare class GraphHistoryService {
10
+ private history;
11
+ private historyIndex;
12
+ private maxHistorySize;
13
+ /** Signal to track if an undo/redo operation is in progress */
14
+ readonly isUndoRedo: import("@angular/core").WritableSignal<boolean>;
15
+ /**
16
+ * Initialize history with the given graph state.
17
+ * Clears any existing history.
18
+ */
19
+ init(graph: Graph): void;
20
+ /**
21
+ * Push a new state to the history stack.
22
+ * If we're not at the end of history, truncates future states.
23
+ * Prevents duplicate consecutive states.
24
+ *
25
+ * @returns true if state was pushed, false if it was a duplicate
26
+ */
27
+ push(graph: Graph): boolean;
28
+ /**
29
+ * Undo the last action.
30
+ * @returns The previous graph state, or null if nothing to undo
31
+ */
32
+ undo(): Graph | null;
33
+ /**
34
+ * Redo the last undone action.
35
+ * @returns The next graph state, or null if nothing to redo
36
+ */
37
+ redo(): Graph | null;
38
+ /**
39
+ * Complete an undo/redo operation.
40
+ * Call this after applying the state returned by undo() or redo().
41
+ */
42
+ completeUndoRedo(): void;
43
+ /** Check if undo is available */
44
+ canUndo(): boolean;
45
+ /** Check if redo is available */
46
+ canRedo(): boolean;
47
+ /** Clear history and reset to given state */
48
+ clear(graph: Graph): void;
49
+ /** Get current history size */
50
+ get size(): number;
51
+ /** Get current position in history (0-indexed) */
52
+ get position(): number;
53
+ /** Set maximum history size */
54
+ setMaxSize(size: number): void;
55
+ static ɵfac: i0.ɵɵFactoryDeclaration<GraphHistoryService, never>;
56
+ static ɵprov: i0.ɵɵInjectableDeclaration<GraphHistoryService>;
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utisha/graph-editor",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Configuration-driven visual graph editor for Angular 19+",
5
5
  "author": "Utisha",
6
6
  "license": "MIT",