ngx-workflow 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Your Name/Organization
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # ngx-workflow
2
+
3
+ An Angular library for building interactive workflow diagrams with drag-and-drop nodes and connectable edges.
4
+
5
+ ## Features
6
+
7
+ - đŸŽ¯ **Drag & Drop Nodes** - Reposition nodes by dragging
8
+ - 🔗 **Connect Edges** - Connect nodes via handles with bezier/straight/step paths
9
+ - 🔍 **Pan & Zoom** - Navigate large diagrams with mouse wheel zoom and canvas panning
10
+ - 🎨 **Customizable** - Style nodes and edges via CSS variables or custom components
11
+ - â†Šī¸ **Undo/Redo** - Full undo/redo support for all diagram changes
12
+ - âŒ¨ī¸ **Keyboard Shortcuts** - Delete, undo (Ctrl+Z), redo (Ctrl+Shift+Z)
13
+ - đŸ“Ļ **Lasso Selection** - Select multiple nodes (Shift + drag)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install ngx-workflow
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Declarative Approach (Recommended)
24
+
25
+ Use `@Input()` and `@Output()` properties for a more Angular-friendly, template-driven approach:
26
+
27
+ ```typescript
28
+ import { Component } from '@angular/core';
29
+ import { Node, Edge } from 'ngx-workflow';
30
+
31
+ @Component({
32
+ selector: 'app-workflow',
33
+ template: `
34
+ <div style="width: 100%; height: 600px;">
35
+ <ngx-diagram
36
+ [initialNodes]="nodes"
37
+ [initialEdges]="edges"
38
+ (nodeClick)="onNodeClick($event)"
39
+ (connect)="onConnect($event)"
40
+ ></ngx-diagram>
41
+ </div>
42
+ `
43
+ })
44
+ export class WorkflowComponent {
45
+ nodes: Node[] = [
46
+ {
47
+ id: '1',
48
+ position: { x: 50, y: 50 },
49
+ data: { label: 'Start' },
50
+ draggable: true
51
+ },
52
+ {
53
+ id: '2',
54
+ position: { x: 300, y: 50 },
55
+ data: { label: 'Process' },
56
+ draggable: true
57
+ }
58
+ ];
59
+
60
+ edges: Edge[] = [
61
+ {
62
+ id: 'e1',
63
+ source: '1',
64
+ sourceHandle: 'right',
65
+ target: '2',
66
+ targetHandle: 'left',
67
+ type: 'bezier'
68
+ }
69
+ ];
70
+
71
+ onNodeClick(node: Node) {
72
+ console.log('Node clicked:', node);
73
+ }
74
+
75
+ onConnect(connection: { source: string; target: string }) {
76
+ console.log('New connection:', connection);
77
+ // Add new edge to your data
78
+ this.edges = [...this.edges, {
79
+ id: Date.now().toString(),
80
+ ...connection,
81
+ type: 'bezier'
82
+ }];
83
+ }
84
+ }
85
+ ```
86
+
87
+ ### Imperative Approach (Service Injection)
88
+
89
+ Use `DiagramStateService` for programmatic control:
90
+
91
+ ```typescript
92
+ import { NgxFlowModule } from 'ngx-workflow';
93
+
94
+ @NgModule({
95
+ imports: [NgxFlowModule],
96
+ })
97
+ export class AppModule {}
98
+ ```
99
+
100
+ ### 2. Use the Component
101
+
102
+ ```typescript
103
+ import { Component } from '@angular/core';
104
+ import { DiagramStateService } from 'ngx-workflow';
105
+
106
+ @Component({
107
+ selector: 'app-workflow',
108
+ template: `
109
+ <div style="width: 100%; height: 600px;">
110
+ <ngx-diagram></ngx-diagram>
111
+ </div>
112
+ <button (click)="addNode()">Add Node</button>
113
+ `
114
+ })
115
+ export class WorkflowComponent {
116
+ constructor(private diagramState: DiagramStateService) {
117
+ // Add initial nodes
118
+ this.diagramState.addNode({
119
+ id: '1',
120
+ position: { x: 50, y: 50 },
121
+ data: { label: 'Start' },
122
+ draggable: true,
123
+ width: 170,
124
+ height: 60
125
+ });
126
+
127
+ this.diagramState.addNode({
128
+ id: '2',
129
+ position: { x: 300, y: 50 },
130
+ data: { label: 'Process' },
131
+ draggable: true,
132
+ width: 170,
133
+ height: 60
134
+ });
135
+
136
+ // Add an edge
137
+ this.diagramState.addEdge({
138
+ id: 'e1',
139
+ source: '1',
140
+ sourceHandle: 'right',
141
+ target: '2',
142
+ targetHandle: 'left',
143
+ type: 'bezier'
144
+ });
145
+ }
146
+
147
+ addNode() {
148
+ this.diagramState.addNode({
149
+ id: Date.now().toString(),
150
+ position: { x: 200, y: 200 },
151
+ data: { label: 'New Node' },
152
+ draggable: true
153
+ });
154
+ }
155
+ }
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### DiagramComponent
161
+
162
+ #### Inputs
163
+
164
+ - `[initialNodes]` - Initial array of nodes to display
165
+ - `[initialEdges]` - Initial array of edges to display
166
+ - `[initialViewport]` - Initial viewport state `{ x: number, y: number, zoom: number }`
167
+
168
+ #### Outputs
169
+
170
+ - `(nodeClick)` - Emitted when a node is clicked. Payload: `Node`
171
+ - `(edgeClick)` - Emitted when an edge is clicked. Payload: `Edge`
172
+ - `(connect)` - Emitted when a new edge is created. Payload: `{ source: string, sourceHandle?: string, target: string, targetHandle?: string }`
173
+ - `(nodesChange)` - Emitted when nodes change. Payload: `Node[]`
174
+ - `(edgesChange)` - Emitted when edges change. Payload: `Edge[]`
175
+
176
+ ### DiagramStateService
177
+
178
+ The main service for managing diagram state.
179
+
180
+ #### Methods
181
+
182
+ - `addNode(node: Node): void` - Add a new node
183
+ - `removeNode(nodeId: string): void` - Remove a node
184
+ - `moveNode(nodeId: string, position: XYPosition): void` - Move a node
185
+ - `addEdge(edge: Edge): void` - Add a new edge
186
+ - `removeEdge(edgeId: string): void` - Remove an edge
187
+ - `selectNodes(nodeIds: string[], append?: boolean): void` - Select nodes
188
+ - `undo(): void` - Undo last change
189
+ - `redo(): void` - Redo last undone change
190
+
191
+ #### Signals
192
+
193
+ - `nodes()` - Current nodes array
194
+ - `edges()` - Current edges array
195
+ - `viewport()` - Current viewport state (x, y, zoom)
196
+
197
+ #### Events
198
+
199
+ - `nodeClick` - Emitted when a node is clicked
200
+ - `edgeClick` - Emitted when an edge is clicked
201
+ - `connect` - Emitted when a new edge is created
202
+ - `nodesChange` - Emitted when nodes change
203
+ - `edgesChange` - Emitted when edges change
204
+
205
+ ### Node Interface
206
+
207
+ ```typescript
208
+ interface Node {
209
+ id: string;
210
+ position: { x: number; y: number };
211
+ data?: any;
212
+ width?: number; // Default: 170
213
+ height?: number; // Default: 60
214
+ selected?: boolean;
215
+ dragging?: boolean;
216
+ draggable?: boolean; // Default: true
217
+ type?: string;
218
+ }
219
+ ```
220
+
221
+ ### Edge Interface
222
+
223
+ ```typescript
224
+ interface Edge {
225
+ id: string;
226
+ source: string;
227
+ sourceHandle?: string; // 'top' | 'right' | 'bottom' | 'left'
228
+ target: string;
229
+ targetHandle?: string; // 'top' | 'right' | 'bottom' | 'left'
230
+ type?: 'bezier' | 'straight' | 'step'; // Default: 'bezier'
231
+ animated?: boolean;
232
+ style?: { [key: string]: any };
233
+ }
234
+ ```
235
+
236
+ ## Interactions
237
+
238
+ ### Node Dragging
239
+ - Click and drag on a node's body to move it
240
+ - Nodes must have `draggable: true` to be draggable
241
+
242
+ ### Creating Edges
243
+ 1. Click on a handle (small blue circle at node edges)
244
+ 2. Drag to another node's handle
245
+ 3. Release to create the connection
246
+
247
+ ### Panning
248
+ - Click and drag on empty canvas to pan
249
+ - Or use middle mouse button
250
+
251
+ ### Zooming
252
+ - Use mouse wheel to zoom in/out
253
+ - Zoom is centered on mouse position
254
+
255
+ ### Selection
256
+ - Click a node to select it
257
+ - Ctrl/Cmd + click to add to selection
258
+ - Shift + drag on canvas for lasso selection
259
+ - Press Delete to remove selected nodes/edges
260
+
261
+ ### Undo/Redo
262
+ - Ctrl/Cmd + Z to undo
263
+ - Ctrl/Cmd + Shift + Z to redo
264
+
265
+ ## Customization
266
+
267
+ ### CSS Variables
268
+
269
+ ```css
270
+ :host {
271
+ --ngx-workflow-primary: #3b82f6;
272
+ --ngx-workflow-primary-hover: #2563eb;
273
+ --ngx-workflow-bg: #f8fafc;
274
+ --ngx-workflow-surface: #ffffff;
275
+ --ngx-workflow-border: #e2e8f0;
276
+ --ngx-workflow-text-primary: #1e293b;
277
+ --ngx-workflow-text-secondary: #64748b;
278
+ --ngx-workflow-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
279
+ --ngx-workflow-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
280
+ --ngx-workflow-glass-bg: rgba(255, 255, 255, 0.8);
281
+ --ngx-workflow-glass-blur: blur(12px);
282
+ }
283
+ ```
284
+
285
+ ## License
286
+
287
+ MIT
288
+
289
+ ## Contributing
290
+
291
+ Contributions are welcome! Please open an issue or submit a pull request.