@flowuent-org/diagramming-core 1.0.6 → 1.0.8
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/TRANSLATION_FIX_SUMMARY.md +118 -0
- package/package.json +1 -1
- package/packages/diagrams/I18N_SETUP.md +126 -0
- package/packages/diagrams/README.md +459 -3
- package/packages/diagrams/locales/en/translation.json +713 -0
- package/packages/diagrams/package.json +27 -25
- package/packages/diagrams/project.json +42 -37
- package/packages/diagrams/rollup.config.js +26 -26
- package/packages/diagrams/src/index.ts +116 -113
- package/packages/diagrams/src/lib/components/automation/AutomationEndNode.tsx +8 -8
- package/packages/diagrams/src/lib/components/automation/AutomationFormattingNode.tsx +8 -8
- package/packages/diagrams/src/lib/components/automation/AutomationStartNode.tsx +9 -9
- package/packages/diagrams/src/lib/i18n.ts +42 -0
- package/packages/diagrams/src/lib/utils/AutomationExecutionEngine.ts +1179 -1162
- package/packages/diagrams/tsconfig.lib.json +25 -25
- package/tsconfig.base.json +30 -30
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Translation Fix Summary
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
Translation keys (like `tooltip.clear`, `button.save`) were showing instead of actual text when using the published npm library in another app.
|
|
5
|
+
|
|
6
|
+
## Root Cause
|
|
7
|
+
The translation files were in the `apps/workflow/locales` folder (not part of the library) and were not being bundled with the published npm package. The library code was using `useTranslation()` hooks but had no way to access the translation resources.
|
|
8
|
+
|
|
9
|
+
## Solution Implemented
|
|
10
|
+
|
|
11
|
+
### 1. Moved Translation Files to Library
|
|
12
|
+
- ✅ Created `packages/diagrams/locales/en/translation.json`
|
|
13
|
+
- ✅ Copied translation files from apps to library
|
|
14
|
+
|
|
15
|
+
### 2. Updated Build Configuration
|
|
16
|
+
- ✅ Modified `packages/diagrams/project.json` to include locales folder in build assets
|
|
17
|
+
- ✅ This ensures translations are bundled with the npm package
|
|
18
|
+
|
|
19
|
+
### 3. Created i18n Configuration
|
|
20
|
+
- ✅ Created `packages/diagrams/src/lib/i18n.ts` with:
|
|
21
|
+
- `initDiagramsI18n()` - Function to initialize translations
|
|
22
|
+
- `translationEN` - Export of translation resources
|
|
23
|
+
- Auto-initialization if i18n not already configured
|
|
24
|
+
|
|
25
|
+
### 4. Updated Package Dependencies
|
|
26
|
+
- ✅ Added `i18next` and `react-i18next` to package.json dependencies
|
|
27
|
+
|
|
28
|
+
### 5. Updated Exports
|
|
29
|
+
- ✅ Modified `packages/diagrams/src/index.ts` to export i18n functionality
|
|
30
|
+
|
|
31
|
+
### 6. Created Documentation
|
|
32
|
+
- ✅ Created `I18N_SETUP.md` with detailed setup instructions
|
|
33
|
+
- ✅ Updated `README.md` with quick start guide
|
|
34
|
+
|
|
35
|
+
## How Consumers Should Use the Library
|
|
36
|
+
|
|
37
|
+
### In their main.tsx or index.tsx (BEFORE rendering components):
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { initDiagramsI18n } from '@flowuent-labs/diagrams';
|
|
41
|
+
|
|
42
|
+
// Initialize i18n
|
|
43
|
+
initDiagramsI18n();
|
|
44
|
+
|
|
45
|
+
// Then render your app
|
|
46
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(<App />);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Next Steps
|
|
50
|
+
|
|
51
|
+
1. **Fix Build Issue** (Separate from i18n):
|
|
52
|
+
The build is failing due to TypeScript path configuration issues (mixing Unix `/Users` and Windows `C:` paths). This is a pre-existing issue unrelated to the i18n changes. You may need to:
|
|
53
|
+
- Check your `tsconfig.json` and `tsconfig.lib.json`
|
|
54
|
+
- Ensure consistent path separators
|
|
55
|
+
- Or build on a single platform (all Unix or all Windows paths)
|
|
56
|
+
|
|
57
|
+
2. **Test the Build**:
|
|
58
|
+
Once the path issue is resolved, rebuild:
|
|
59
|
+
```bash
|
|
60
|
+
nx build diagrams
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
3. **Verify Translation Files Are Included**:
|
|
64
|
+
After successful build, check `dist/packages/diagrams/locales/` exists
|
|
65
|
+
|
|
66
|
+
4. **Publish Updated Package**:
|
|
67
|
+
```bash
|
|
68
|
+
cd packages/diagrams
|
|
69
|
+
npm version patch # or minor/major
|
|
70
|
+
npm publish
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
5. **Update Consumer Apps**:
|
|
74
|
+
In apps using the library:
|
|
75
|
+
```bash
|
|
76
|
+
npm update @flowuent-labs/diagrams
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Then add initialization:
|
|
80
|
+
```typescript
|
|
81
|
+
import { initDiagramsI18n } from '@flowuent-labs/diagrams';
|
|
82
|
+
initDiagramsI18n(); // Add this before rendering
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Alternative: Quick Fix Without Rebuilding
|
|
86
|
+
|
|
87
|
+
If you need an immediate fix before resolving the build issues, consumers can manually add translations:
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import i18n from 'i18next';
|
|
91
|
+
import { initReactI18next } from 'react-i18next';
|
|
92
|
+
|
|
93
|
+
// Manually import/copy the translation.json content
|
|
94
|
+
const translations = { /* paste translation.json content */ };
|
|
95
|
+
|
|
96
|
+
i18n.use(initReactI18next).init({
|
|
97
|
+
resources: {
|
|
98
|
+
en: {
|
|
99
|
+
translation: translations
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
fallbackLng: 'en',
|
|
103
|
+
interpolation: {
|
|
104
|
+
escapeValue: false
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Files Modified/Created
|
|
110
|
+
|
|
111
|
+
1. ✅ `packages/diagrams/locales/en/translation.json` (new)
|
|
112
|
+
2. ✅ `packages/diagrams/src/lib/i18n.ts` (new)
|
|
113
|
+
3. ✅ `packages/diagrams/src/index.ts` (modified)
|
|
114
|
+
4. ✅ `packages/diagrams/project.json` (modified - assets config)
|
|
115
|
+
5. ✅ `packages/diagrams/package.json` (modified - added i18n deps)
|
|
116
|
+
6. ✅ `packages/diagrams/README.md` (updated)
|
|
117
|
+
7. ✅ `packages/diagrams/I18N_SETUP.md` (new)
|
|
118
|
+
|
package/package.json
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Internationalization (i18n) Setup
|
|
2
|
+
|
|
3
|
+
The `@flowuent-labs/diagrams` library includes built-in translation support using i18next. To ensure translations work correctly in your application, you need to initialize i18n before using the library components.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### Option 1: Use Built-in Initialization (Recommended)
|
|
8
|
+
|
|
9
|
+
Import and call the `initDiagramsI18n` function before rendering any diagram components:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { initDiagramsI18n } from '@flowuent-labs/diagrams';
|
|
13
|
+
|
|
14
|
+
// Initialize i18n with default translations
|
|
15
|
+
initDiagramsI18n();
|
|
16
|
+
|
|
17
|
+
// Now you can use any diagram components
|
|
18
|
+
function App() {
|
|
19
|
+
return <YourDiagramComponent />;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Option 2: Manual Initialization with Custom Translations
|
|
24
|
+
|
|
25
|
+
If you want to customize or extend the translations:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { initDiagramsI18n, translationEN } from '@flowuent-labs/diagrams';
|
|
29
|
+
|
|
30
|
+
// Initialize with custom translations
|
|
31
|
+
initDiagramsI18n({
|
|
32
|
+
en: {
|
|
33
|
+
translation: {
|
|
34
|
+
...translationEN,
|
|
35
|
+
// Add your custom translations or overrides here
|
|
36
|
+
customKey: 'Custom value',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
// Add other languages
|
|
40
|
+
es: {
|
|
41
|
+
translation: {
|
|
42
|
+
// Spanish translations
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Option 3: Use Existing i18next Instance
|
|
49
|
+
|
|
50
|
+
If your app already uses i18next, you can add the library's translations to your existing configuration:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import i18n from 'i18next';
|
|
54
|
+
import { initReactI18next } from 'react-i18next';
|
|
55
|
+
import { translationEN } from '@flowuent-labs/diagrams';
|
|
56
|
+
|
|
57
|
+
i18n
|
|
58
|
+
.use(initReactI18next)
|
|
59
|
+
.init({
|
|
60
|
+
resources: {
|
|
61
|
+
en: {
|
|
62
|
+
translation: {
|
|
63
|
+
// Your app translations
|
|
64
|
+
...yourAppTranslations,
|
|
65
|
+
// Library translations
|
|
66
|
+
...translationEN,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
fallbackLng: 'en',
|
|
71
|
+
interpolation: {
|
|
72
|
+
escapeValue: false,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Available Translations
|
|
78
|
+
|
|
79
|
+
The library currently includes:
|
|
80
|
+
- English (en) - `translationEN`
|
|
81
|
+
|
|
82
|
+
## Common Issues
|
|
83
|
+
|
|
84
|
+
### Translation Keys Showing Instead of Text
|
|
85
|
+
|
|
86
|
+
If you see translation keys (e.g., `tooltip.clear`, `button.save`) instead of actual text, it means i18n is not initialized. Make sure to call `initDiagramsI18n()` before rendering any components.
|
|
87
|
+
|
|
88
|
+
### Translations Not Working in Production
|
|
89
|
+
|
|
90
|
+
Ensure your build process includes the `locales` folder from the library. The translation files are automatically included in the npm package.
|
|
91
|
+
|
|
92
|
+
## API Reference
|
|
93
|
+
|
|
94
|
+
### `initDiagramsI18n(customResources?: any): i18n`
|
|
95
|
+
|
|
96
|
+
Initializes or updates the i18next instance with diagram translations.
|
|
97
|
+
|
|
98
|
+
**Parameters:**
|
|
99
|
+
- `customResources` (optional): Custom translation resources object
|
|
100
|
+
|
|
101
|
+
**Returns:**
|
|
102
|
+
- The i18next instance
|
|
103
|
+
|
|
104
|
+
### `translationEN`
|
|
105
|
+
|
|
106
|
+
The default English translation resource object. Can be imported for customization or extension.
|
|
107
|
+
|
|
108
|
+
## Example: Complete Setup
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// main.tsx or index.tsx
|
|
112
|
+
import React from 'react';
|
|
113
|
+
import ReactDOM from 'react-dom/client';
|
|
114
|
+
import { initDiagramsI18n } from '@flowuent-labs/diagrams';
|
|
115
|
+
import App from './App';
|
|
116
|
+
|
|
117
|
+
// Initialize i18n before rendering
|
|
118
|
+
initDiagramsI18n();
|
|
119
|
+
|
|
120
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
121
|
+
<React.StrictMode>
|
|
122
|
+
<App />
|
|
123
|
+
</React.StrictMode>
|
|
124
|
+
);
|
|
125
|
+
```
|
|
126
|
+
|
|
@@ -1,7 +1,463 @@
|
|
|
1
|
-
#
|
|
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
|
|
2
446
|
|
|
3
447
|
This library was generated with [Nx](https://nx.dev).
|
|
4
448
|
|
|
5
|
-
|
|
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
|
|
6
462
|
|
|
7
|
-
|
|
463
|
+
MIT
|