@flowuent-org/diagramming-core 1.0.8 → 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.
Files changed (40) hide show
  1. package/apps/diagramming/src/AutomationDiagramData.ts +22 -0
  2. package/apps/diagramming/src/components/AddNodeView.tsx +252 -252
  3. package/apps/diagramming/src/main.tsx +463 -463
  4. package/apps/diagramming/src/node-data.ts +664 -664
  5. package/apps/diagramming/src/stencil-items.ts +31 -31
  6. package/apps/diagramming/src/vite-env.d.ts +1 -1
  7. package/package.json +1 -1
  8. package/packages/diagrams/NODE_DATA_UPDATE_API.md +430 -430
  9. package/packages/diagrams/README.md +7 -463
  10. package/packages/diagrams/UNDO_REDO_API.md +306 -306
  11. package/packages/diagrams/package.json +27 -27
  12. package/packages/diagrams/project.json +42 -42
  13. package/packages/diagrams/rollup.config.js +26 -26
  14. package/packages/diagrams/src/DiagramFlow.tsx +7 -7
  15. package/packages/diagrams/src/index.ts +116 -116
  16. package/packages/diagrams/src/index.ts.bak +99 -99
  17. package/packages/diagrams/src/lib/atoms/CardEditableTitle.tsx +76 -76
  18. package/packages/diagrams/src/lib/atoms/ExpressionInput.tsx +437 -437
  19. package/packages/diagrams/src/lib/components/DiagramPanel.tsx +331 -331
  20. package/packages/diagrams/src/lib/components/automation/AISuggestionsModal.tsx +269 -0
  21. package/packages/diagrams/src/lib/components/automation/AISuggestionsPanel.tsx +227 -0
  22. package/packages/diagrams/src/lib/components/automation/AutomationAISuggestionNode.tsx +178 -115
  23. package/packages/diagrams/src/lib/components/automation/AutomationApiNode.tsx +133 -27
  24. package/packages/diagrams/src/lib/components/automation/AutomationEndNode.tsx +134 -28
  25. package/packages/diagrams/src/lib/components/automation/AutomationFormattingNode.tsx +132 -27
  26. package/packages/diagrams/src/lib/components/automation/AutomationNoteNode.tsx +124 -17
  27. package/packages/diagrams/src/lib/components/automation/AutomationSheetsNode.tsx +122 -15
  28. package/packages/diagrams/src/lib/components/automation/index.ts +3 -0
  29. package/packages/diagrams/src/lib/contexts/onWorkflowNodeDelete.ts +65 -65
  30. package/packages/diagrams/src/lib/organisms/CustomEdge/useCreateBendPoint.tsx +121 -121
  31. package/packages/diagrams/src/lib/organisms/WorkFlowNode/NodeActionButtons.tsx +45 -45
  32. package/packages/diagrams/src/lib/templates/node-forms/CallForm.tsx +370 -370
  33. package/packages/diagrams/src/lib/templates/systemFlow/components/FloatingEdge.tsx +219 -219
  34. package/packages/diagrams/src/lib/types/card-node.ts +68 -68
  35. package/packages/diagrams/src/lib/types/node-types.ts +29 -29
  36. package/packages/diagrams/src/lib/utils/AutomationExecutionEngine.ts +1179 -1179
  37. package/packages/diagrams/tsconfig.lib.json +25 -25
  38. package/tsconfig.base.json +29 -30
  39. package/TRANSLATION_FIX_SUMMARY.md +0 -118
  40. package/packages/diagrams/I18N_SETUP.md +0 -126
@@ -1,463 +1,7 @@
1
- # @flowuent-labs/diagrams
2
-
3
- A comprehensive React diagramming library built with React Flow, providing various diagram types including sequence diagrams, state machines, collaboration diagrams, and more.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install @flowuent-labs/diagrams
9
- # or
10
- yarn add @flowuent-labs/diagrams
11
- ```
12
-
13
- ## Quick Start
14
-
15
- ### 1. Initialize i18n (Required)
16
-
17
- ⚠️ **Important**: Before using any components from this library, you must initialize i18n to ensure translations work correctly.
18
-
19
- ```typescript
20
- import { initDiagramsI18n } from '@flowuent-labs/diagrams';
21
-
22
- // Initialize with default translations
23
- initDiagramsI18n();
24
- ```
25
-
26
- ### 2. Use the DiagrammingPage Component
27
-
28
- ⚠️ **Critical**: You MUST use the complete `DiagrammingPage` component which includes all necessary providers. Do not try to use individual internal components like hooks, atoms, or molecules directly without wrapping them in `DiagrammingPage`.
29
-
30
- ```typescript
31
- import { DiagrammingPage } from '@flowuent-labs/diagrams';
32
- import type { DiagrammingPageRef } from '@flowuent-labs/diagrams';
33
-
34
- function App() {
35
- const diagramRef = React.useRef<DiagrammingPageRef>(null);
36
-
37
- return (
38
- <DiagrammingPage
39
- ref={diagramRef}
40
- id={1}
41
- diagramType="workflow" // or 'sequence', 'state-machine', etc.
42
- defaultNodes={[]}
43
- defaultEdges={[]}
44
- availableFunctions={[]}
45
- availableVariables={[]}
46
- onChange={(nodes, edges) => {
47
- console.log('Diagram changed:', nodes, edges);
48
- }}
49
- >
50
- {/* Optional: Your custom content */}
51
- </DiagrammingPage>
52
- );
53
- }
54
- ```
55
-
56
- ### Required Props
57
-
58
- | Prop | Type | Description |
59
- |------|------|-------------|
60
- | `id` | `number` | Unique identifier for the diagram instance |
61
- | `diagramType` | `DiagramTypes` | Type of diagram: `'workflow'`, `'sequence'`, `'state-machine'`, `'collaboration'`, `'use-case'`, `'system-flow'`, or `'cloud-arch'` |
62
- | `defaultNodes` | `ICardNode[]` | Initial nodes for the diagram |
63
- | `defaultEdges` | `Edge[]` | Initial edges for the diagram |
64
- | `availableFunctions` | `FunctionSignature[]` | Functions available for workflow nodes |
65
-
66
- ### Optional Props
67
-
68
- | Prop | Type | Description |
69
- |------|------|-------------|
70
- | `availableVariables` | `AvailableVariable[]` | Variables available in the diagram |
71
- | `onChange` | `(nodes, edges) => void` | Callback when diagram changes |
72
- | `onNodeSelect` | `(payload) => void` | Callback when a node is selected |
73
- | `workflowNodeContent` | `WorkflowNodeContentType` | Custom content for workflow nodes |
74
- | `renderAddNodeView` | `RenderAddNodeViewType` | Custom add node view renderer |
75
- | `getDefaultNodeData` | `(type: string) => any` | Function to get default data for new nodes |
76
- | `conditionBuilderStates` | `ConditionBuilderState` | States for condition builder |
77
- | `enableNodeJsonPopover` | `boolean` | Enable/disable JSON popover (default: `true`) |
78
- | `showAutomationExecutionPanel` | `boolean` | Show automation execution panel |
79
- | `className` | `string` | Custom CSS class for the diagram container |
80
-
81
- ## i18n Setup
82
-
83
- The library includes built-in translation support. For detailed i18n setup instructions, see [I18N_SETUP.md](./I18N_SETUP.md).
84
-
85
- ### Quick Setup
86
-
87
- ```typescript
88
- // In your main.tsx or index.tsx
89
- import React from 'react';
90
- import ReactDOM from 'react-dom/client';
91
- import { initDiagramsI18n } from '@flowuent-labs/diagrams';
92
- import App from './App';
93
-
94
- // Initialize i18n BEFORE rendering
95
- initDiagramsI18n();
96
-
97
- ReactDOM.createRoot(document.getElementById('root')!).render(
98
- <React.StrictMode>
99
- <App />
100
- </React.StrictMode>
101
- );
102
- ```
103
-
104
- ### Custom Translations
105
-
106
- ```typescript
107
- import { initDiagramsI18n, translationEN } from '@flowuent-labs/diagrams';
108
-
109
- initDiagramsI18n({
110
- en: {
111
- translation: {
112
- ...translationEN,
113
- // Add your custom translations
114
- },
115
- },
116
- es: {
117
- translation: {
118
- // Spanish translations
119
- },
120
- },
121
- });
122
- ```
123
-
124
- ## Troubleshooting
125
-
126
- ### "DiagramStore context provider not initialized" Error
127
-
128
- If you see this error, it means you're trying to use internal library components or hooks **outside** of the `DiagrammingPage` component.
129
-
130
- **Common Causes:**
131
-
132
- 1. **Importing internal components directly:**
133
- ```typescript
134
- // ❌ WRONG - Don't do this
135
- import { useDiagram, EntityNode } from '@flowuent-labs/diagrams';
136
-
137
- function MyComponent() {
138
- const nodes = useDiagram(state => state.nodes); // This will fail!
139
- return <EntityNode />; // This will also fail!
140
- }
141
- ```
142
-
143
- 2. **Not using DiagrammingPage component:**
144
- ```typescript
145
- // ❌ WRONG
146
- import { Stencil, DiagramContainer } from '@flowuent-labs/diagrams';
147
-
148
- function App() {
149
- return <DiagramContainer>...</DiagramContainer>; // Missing provider!
150
- }
151
- ```
152
-
153
- **Solution:**
154
-
155
- Always use the complete `DiagrammingPage` component which includes all necessary providers:
156
-
157
- ```typescript
158
- // ✅ CORRECT
159
- import { DiagrammingPage } from '@flowuent-labs/diagrams';
160
-
161
- function App() {
162
- return (
163
- <DiagrammingPage
164
- id={1}
165
- diagramType="workflow"
166
- defaultNodes={[]}
167
- defaultEdges={[]}
168
- availableFunctions={[]}
169
- />
170
- );
171
- }
172
- ```
173
-
174
- If you need to extend functionality, pass custom content as children or use the provided callback props like `onChange`, `onNodeSelect`, etc.
175
-
176
- ### Translation Keys Showing Instead of Text
177
-
178
- If you see keys like `tooltip.clear` or `button.save` instead of actual text:
179
-
180
- 1. Make sure you called `initDiagramsI18n()` before rendering any components
181
- 2. Verify the call is in your main entry file (e.g., `main.tsx` or `index.tsx`)
182
- 3. Ensure the initialization happens before `ReactDOM.render()` or `createRoot()`
183
-
184
- Example:
185
- ```typescript
186
- // ✅ Correct order
187
- initDiagramsI18n();
188
- ReactDOM.createRoot(document.getElementById('root')!).render(<App />);
189
-
190
- // ❌ Wrong - components render before i18n initializes
191
- ReactDOM.createRoot(document.getElementById('root')!).render(<App />);
192
- initDiagramsI18n(); // Too late!
193
- ```
194
-
195
- ## Features
196
-
197
- - Multiple diagram types:
198
- - Sequence Diagrams
199
- - State Machine Diagrams
200
- - Collaboration Diagrams
201
- - Use Case Diagrams
202
- - System Flow Diagrams
203
- - Cloud Architecture Diagrams
204
- - Workflow/Automation Diagrams
205
- - Built-in i18n support
206
- - Customizable styling and themes
207
- - Export to JSON and images
208
- - Import/Export functionality
209
- - Undo/Redo support
210
-
211
- ## Complete Working Example
212
-
213
- Here's a complete, minimal example to get you started:
214
-
215
- ```typescript
216
- // main.tsx or index.tsx
217
- import React from 'react';
218
- import ReactDOM from 'react-dom/client';
219
- import { initDiagramsI18n, DiagrammingPage } from '@flowuent-labs/diagrams';
220
- import '@xyflow/react/dist/style.css'; // Required for React Flow styles
221
-
222
- // Step 1: Initialize i18n BEFORE rendering
223
- initDiagramsI18n();
224
-
225
- // Step 2: Create your App component
226
- function App() {
227
- const diagramRef = React.useRef(null);
228
-
229
- const handleDiagramChange = (nodes, edges) => {
230
- console.log('Diagram updated:', { nodes, edges });
231
- };
232
-
233
- return (
234
- <div style={{ width: '100vw', height: '100vh' }}>
235
- <DiagrammingPage
236
- ref={diagramRef}
237
- id={1}
238
- diagramType="workflow"
239
- defaultNodes={[]}
240
- defaultEdges={[]}
241
- availableFunctions={[]}
242
- onChange={handleDiagramChange}
243
- />
244
- </div>
245
- );
246
- }
247
-
248
- // Step 3: Render your app
249
- ReactDOM.createRoot(document.getElementById('root')!).render(
250
- <React.StrictMode>
251
- <App />
252
- </React.StrictMode>
253
- );
254
- ```
255
-
256
- ## Using with Imperative Methods
257
-
258
- The `DiagrammingPage` component exposes several methods through a ref:
259
-
260
- ```typescript
261
- import { DiagrammingPage, DiagrammingPageRef } from '@flowuent-labs/diagrams';
262
-
263
- function App() {
264
- const diagramRef = React.useRef<DiagrammingPageRef>(null);
265
-
266
- const handleUndo = () => {
267
- diagramRef.current?.undo();
268
- };
269
-
270
- const handleRedo = () => {
271
- diagramRef.current?.redo();
272
- };
273
-
274
- const handleReset = () => {
275
- diagramRef.current?.reset();
276
- };
277
-
278
- const getSelectedNode = () => {
279
- const nodeId = diagramRef.current?.getSelectedNode();
280
- if (nodeId) {
281
- const nodeData = diagramRef.current?.getNodeData(nodeId);
282
- console.log('Selected node data:', nodeData);
283
- }
284
- };
285
-
286
- const updateNode = (nodeId: string, data: any) => {
287
- const success = diagramRef.current?.updateNodeData(nodeId, data);
288
- console.log('Node updated:', success);
289
- };
290
-
291
- return (
292
- <div>
293
- <div>
294
- <button onClick={handleUndo}>Undo</button>
295
- <button onClick={handleRedo}>Redo</button>
296
- <button onClick={handleReset}>Reset</button>
297
- <button onClick={getSelectedNode}>Get Selected Node</button>
298
- </div>
299
- <DiagrammingPage
300
- ref={diagramRef}
301
- id={1}
302
- diagramType="workflow"
303
- defaultNodes={[]}
304
- defaultEdges={[]}
305
- availableFunctions={[]}
306
- />
307
- </div>
308
- );
309
- }
310
- ```
311
-
312
- ### Available Ref Methods
313
-
314
- - `undo()` - Undo last change
315
- - `redo()` - Redo last undone change
316
- - `canUndo()` - Check if undo is available
317
- - `canRedo()` - Check if redo is available
318
- - `reset()` - Clear the diagram
319
- - `getHistoryLength()` - Get history stack length
320
- - `getHistoryIndex()` - Get current history position
321
- - `getNodeData(nodeId)` - Get data for a specific node
322
- - `updateNodeData(nodeId, data)` - Update a specific node's data
323
- - `getSelectedNode()` - Get ID of currently selected node
324
- - `getNodes()` - Get all nodes
325
- - `getEdges()` - Get all edges
326
-
327
- ## Automation Workflows
328
-
329
- The library includes powerful automation workflow capabilities with an execution engine and UI panel.
330
-
331
- ### Using AutomationExecutionPanel
332
-
333
- The `AutomationExecutionPanel` component provides a UI for executing automation workflows with real-time status updates:
334
-
335
- ```typescript
336
- import { useState } from 'react';
337
- import { useNodesState, useEdgesState } from '@xyflow/react';
338
- import { AutomationExecutionPanel } from '@flowuent-labs/diagrams';
339
-
340
- function MyWorkflow() {
341
- const [nodes, setNodes, onNodesChange] = useNodesState([]);
342
- const [edges, setEdges, onEdgesChange] = useEdgesState([]);
343
-
344
- // CRITICAL: You must provide onNodeUpdate callback to see status changes
345
- const handleNodeUpdate = (nodeId: string, updatedData: any) => {
346
- setNodes((nds) =>
347
- nds.map((node) => {
348
- if (node.id === nodeId) {
349
- return { ...node, data: { ...node.data, ...updatedData } };
350
- }
351
- return node;
352
- })
353
- );
354
- };
355
-
356
- return (
357
- <div>
358
- {/* Your React Flow diagram */}
359
- <AutomationExecutionPanel
360
- nodes={nodes}
361
- edges={edges}
362
- workflowId="my-workflow-1"
363
- onNodeUpdate={handleNodeUpdate} // MUST provide this!
364
- />
365
- </div>
366
- );
367
- }
368
- ```
369
-
370
- ### Why onNodeUpdate is Required
371
-
372
- The `AutomationExecutionEngine` updates node status during execution (`Ready` → `Running` → `Completed` / `Error`). Without the `onNodeUpdate` callback:
373
- - ❌ Node status changes won't trigger React re-renders
374
- - ❌ UI won't show real-time execution progress
375
- - ❌ Visual feedback will be missing
376
-
377
- With `onNodeUpdate`:
378
- - ✅ Real-time status updates in the UI
379
- - ✅ Visual feedback as nodes execute
380
- - ✅ Proper React state synchronization
381
-
382
- **Important**: The engine creates new object references when calling `onNodeUpdate` to ensure React detects changes. Make sure your callback updates state properly:
383
-
384
- ```typescript
385
- const handleNodeUpdate = (nodeId: string, updatedData: any) => {
386
- setNodes((nds) =>
387
- nds.map((node) => {
388
- if (node.id === nodeId) {
389
- // This creates a new node object with updated data
390
- return { ...node, data: updatedData };
391
- }
392
- return node;
393
- })
394
- );
395
- };
396
- ```
397
-
398
- ### Using AutomationExecutionEngine Directly
399
-
400
- You can also use the execution engine programmatically:
401
-
402
- ```typescript
403
- import { AutomationExecutionEngine } from '@flowuent-labs/diagrams';
404
- import type { AutomationLog, AutomationResult } from '@flowuent-labs/diagrams';
405
-
406
- async function executeWorkflow(nodes, edges) {
407
- const engine = new AutomationExecutionEngine(
408
- nodes,
409
- edges,
410
- // onNodeUpdate callback - updates node status in real-time
411
- (nodeId, updatedData) => {
412
- console.log(`Node ${nodeId} updated:`, updatedData);
413
- // Update your state here to reflect changes in UI
414
- },
415
- // onLog callback - streams execution logs
416
- (log: AutomationLog) => {
417
- console.log(`[${log.level}] ${log.message}`);
418
- }
419
- );
420
-
421
- try {
422
- const result: AutomationResult = await engine.executeWorkflow();
423
- console.log('Workflow completed:', result);
424
- return result;
425
- } catch (error) {
426
- console.error('Workflow failed:', error);
427
- throw error;
428
- }
429
- }
430
- ```
431
-
432
- ### Available Automation Node Types
433
-
434
- The library exports these automation node components:
435
- - `AutomationStartNode` - Workflow entry point
436
- - `AutomationApiNode` - HTTP API calls
437
- - `AutomationFormattingNode` - Data transformation
438
- - `AutomationSheetsNode` - Google Sheets integration
439
- - `AutomationAISuggestionNode` - AI-powered suggestions
440
- - `AutomationNoteNode` - Documentation/comments
441
- - `AutomationEndNode` - Workflow exit point
442
-
443
- All node types and their data structures are exported from the library.
444
-
445
- ## Development
446
-
447
- This library was generated with [Nx](https://nx.dev).
448
-
449
- ### Building
450
-
451
- ```bash
452
- nx build diagrams
453
- ```
454
-
455
- ### Running unit tests
456
-
457
- ```bash
458
- nx test diagrams
459
- ```
460
-
461
- ## License
462
-
463
- MIT
1
+ # common
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test common` to execute the unit tests via [Jest](https://jestjs.io).