@cyoda/workflow-react 0.1.0 → 0.2.0
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/README.md +165 -14
- package/dist/index.cjs +6821 -971
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +368 -4
- package/dist/index.d.ts +368 -4
- package/dist/index.js +6783 -897
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,31 +1,182 @@
|
|
|
1
1
|
# `@cyoda/workflow-react`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Full workflow editor shell for Cyoda workflows, built on React Flow with
|
|
4
|
+
an Inspector panel, toolbar, and modals.
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npm install @cyoda/workflow-core @cyoda/workflow-graph @cyoda/workflow-layout
|
|
9
|
+
npm install @cyoda/workflow-core @cyoda/workflow-graph @cyoda/workflow-layout \
|
|
10
|
+
@cyoda/workflow-viewer @cyoda/workflow-react \
|
|
11
|
+
react react-dom reactflow
|
|
10
12
|
```
|
|
11
13
|
|
|
12
|
-
##
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { parseImportPayload } from "@cyoda/workflow-core";
|
|
18
|
+
import { WorkflowEditor } from "@cyoda/workflow-react";
|
|
19
|
+
import "reactflow/dist/style.css";
|
|
20
|
+
|
|
21
|
+
const { document } = parseImportPayload(workflowJson);
|
|
22
|
+
|
|
23
|
+
export function App() {
|
|
24
|
+
return (
|
|
25
|
+
<WorkflowEditor
|
|
26
|
+
document={document}
|
|
27
|
+
mode="editor"
|
|
28
|
+
onSave={(doc) => pushToBackend(doc)}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Editing capabilities
|
|
35
|
+
|
|
36
|
+
- **States**: add (toolbar / `A` key), rename with collision guard, delete
|
|
37
|
+
with cascade confirmation, set initial state, visual badges
|
|
38
|
+
(Initial / Terminal / Unreachable).
|
|
39
|
+
- **Transitions**: drag-connect with auto-suggested name, rename with
|
|
40
|
+
collision guard, retarget via inspector dropdown, move to a different
|
|
41
|
+
source state (`moveTransitionSource`), toggle manual/disabled, reorder,
|
|
42
|
+
delete.
|
|
43
|
+
- **Criteria**: compact inspector summary cards open a focused modal editor
|
|
44
|
+
for `simple`, `group` (recursive), `function`, `lifecycle`, and `array`
|
|
45
|
+
types; raw JSON escape hatch; draft editing where Apply commits one patch
|
|
46
|
+
and Cancel discards local changes.
|
|
47
|
+
- **Processors**: compact transition summary rows for the documented
|
|
48
|
+
`externalized` and `scheduled` processor types; modal-local draft editing
|
|
49
|
+
where Apply commits one patch and Cancel discards local changes;
|
|
50
|
+
externalized support for `SYNC`, `ASYNC_SAME_TX`, `ASYNC_NEW_TX`, and
|
|
51
|
+
`COMMIT_BEFORE_DISPATCH` plus `startNewTxOnDispatch`; scheduled duration
|
|
52
|
+
inputs for `delayMs` and `timeoutMs`; `calculationNodesTags` serialized as
|
|
53
|
+
a comma-separated string; free-form string `context`; no arbitrary custom
|
|
54
|
+
config keys.
|
|
55
|
+
- **Manual layout**: drag states to persist positions; Reset Layout /
|
|
56
|
+
Auto Layout toolbar buttons; `L` / `Shift+L` keyboard shortcuts.
|
|
57
|
+
- **Comments**: add free-floating sticky notes via `+ Note` toolbar
|
|
58
|
+
button; double-click to edit; drag to reposition; delete.
|
|
59
|
+
- **Undo / redo**: every edit creates one undo step including cascading
|
|
60
|
+
operations via `PatchTransaction`; `Ctrl/Cmd+Z` / `Ctrl/Cmd+Shift+Z`.
|
|
61
|
+
- **Validation**: errors/warnings as toolbar pills; inline in inspector.
|
|
62
|
+
- **Save**: `Ctrl/Cmd+S`; blocked on validation errors.
|
|
63
|
+
|
|
64
|
+
## Props
|
|
65
|
+
|
|
66
|
+
| Prop | Type | Default | Notes |
|
|
67
|
+
|---|---|---|---|
|
|
68
|
+
| `document` | `WorkflowEditorDocument` | required | From `parseImportPayload`. |
|
|
69
|
+
| `mode` | `"viewer" \| "playground" \| "editor"` | `"editor"` | `"viewer"` hides edit affordances. |
|
|
70
|
+
| `messages` | `PartialMessages` | English | i18n overrides. |
|
|
71
|
+
| `layoutOptions` | `LayoutOptions` | – | ELK preset and orientation. |
|
|
72
|
+
| `chrome` | `ChromeOptions` | all true | Toggle toolbar / tabs / inspector / minimap / controls. |
|
|
73
|
+
| `localStorageKey` | `string \| null` | `"cyoda-editor-layout"` | localStorage key for editor metadata persistence (`layout`, `comments`, `edgeAnchors`, `viewports`). `null` disables. |
|
|
74
|
+
| `layoutMetadata` | `WorkflowUiMeta` | – | Host-controlled UI metadata (overrides localStorage). |
|
|
75
|
+
| `onLayoutMetadataChange` | `(meta: WorkflowUiMeta) => void` | – | Fires when editor-only metadata changes. |
|
|
76
|
+
| `onChange` | `(doc: WorkflowEditorDocument) => void` | – | Fires after every patch. |
|
|
77
|
+
| `onSave` | `(doc: WorkflowEditorDocument) => void` | – | Fires on Ctrl/Cmd+S. |
|
|
78
|
+
| `enableJsonEditor` | `boolean` | `false` | Enables the built-in Monaco-backed JSON editor surface. |
|
|
79
|
+
| `jsonEditorPlacement` | `"tab" \| "split"` | `"tab"` | Renders JSON as a tab or alongside the graph. |
|
|
80
|
+
| `jsonEditor` | `WorkflowJsonEditorConfig \| null` | `null` | Host-supplied Monaco runtime/config. Pass `monaco` here to enable editing. |
|
|
81
|
+
| `onJsonStatusChange` | `(status: JsonEditStatus) => void` | – | Reports JSON parse/schema/apply state for host UX. |
|
|
82
|
+
| `hintProvider` | `EntityFieldHintProvider` | – | Optional model-schema autocomplete source for criterion `jsonPath` inputs. Omit for plain free-text `jsonPath` fields. |
|
|
83
|
+
| `developerMode` | `boolean` | `false` | Show developer-oriented affordances (raw JSON tab in the inspector). Defaults to `false`. Opt in to restore the JSON tab for developer/admin surfaces. |
|
|
84
|
+
|
|
85
|
+
## JSON editor
|
|
86
|
+
|
|
87
|
+
`WorkflowEditor` keeps the graph and JSON views pointed at the same canonical `WorkflowEditorDocument`.
|
|
88
|
+
|
|
89
|
+
- Graph edit -> JSON sync: visual edits update the Monaco model without recreating the editor instance.
|
|
90
|
+
- JSON edit -> graph sync: valid JSON emits a canonical `replaceSession` patch and updates the graph.
|
|
91
|
+
- Invalid JSON handling: invalid syntax or schema never mutates the canonical document; `onJsonStatusChange` reports `"invalid-json"` or `"invalid-schema"` and save stays blocked.
|
|
92
|
+
- Export cleanliness: `layout`, `comments`, `edgeAnchors`, and `viewports` stay in `doc.meta.workflowUi` and never appear in exported Cyoda workflow JSON.
|
|
93
|
+
|
|
94
|
+
### JSON types
|
|
95
|
+
|
|
96
|
+
- `JsonEditStatus`: status union emitted by `onJsonStatusChange`, including idle, invalid JSON/schema, and successful apply states.
|
|
97
|
+
- `WorkflowJsonEditorConfig`: host config for the embedded Monaco editor. Supply `monaco`, plus optional `modelUri`, `editorOptions`, and `debounceMs`.
|
|
13
98
|
|
|
14
|
-
|
|
15
|
-
- Imports `reactflow/dist/style.css` as part of the public entrypoint.
|
|
16
|
-
- Not server-renderable in a plain Node.js runtime without a bundler setup that handles CSS imports.
|
|
99
|
+
### Minimal JSON-enabled usage
|
|
17
100
|
|
|
18
|
-
|
|
101
|
+
```tsx
|
|
102
|
+
import * as monaco from "monaco-editor";
|
|
103
|
+
import { parseImportPayload } from "@cyoda/workflow-core";
|
|
104
|
+
import {
|
|
105
|
+
WorkflowEditor,
|
|
106
|
+
type JsonEditStatus,
|
|
107
|
+
type WorkflowJsonEditorConfig,
|
|
108
|
+
} from "@cyoda/workflow-react";
|
|
109
|
+
import "reactflow/dist/style.css";
|
|
110
|
+
|
|
111
|
+
const { document } = parseImportPayload(workflowJson);
|
|
112
|
+
|
|
113
|
+
const jsonEditor: WorkflowJsonEditorConfig = {
|
|
114
|
+
monaco,
|
|
115
|
+
debounceMs: 150,
|
|
116
|
+
editorOptions: { glyphMargin: false },
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export function App() {
|
|
120
|
+
const handleJsonStatusChange = (status: JsonEditStatus) => {
|
|
121
|
+
console.log(status.status);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<WorkflowEditor
|
|
126
|
+
document={document}
|
|
127
|
+
enableJsonEditor
|
|
128
|
+
jsonEditorPlacement="split"
|
|
129
|
+
jsonEditor={jsonEditor}
|
|
130
|
+
onJsonStatusChange={handleJsonStatusChange}
|
|
131
|
+
/>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Keyboard shortcuts
|
|
137
|
+
|
|
138
|
+
| Key | Action |
|
|
139
|
+
|---|---|
|
|
140
|
+
| `A` | Add state |
|
|
141
|
+
| `L` | Auto layout |
|
|
142
|
+
| `Shift+L` | Reset layout |
|
|
143
|
+
| `Ctrl/Cmd+Z` | Undo |
|
|
144
|
+
| `Ctrl/Cmd+Shift+Z` / `Ctrl+Y` | Redo |
|
|
145
|
+
| `Ctrl/Cmd+S` | Save |
|
|
146
|
+
|
|
147
|
+
## Exported symbols
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import {
|
|
151
|
+
WorkflowEditor, // Main editor component
|
|
152
|
+
useSaveFlow, // Save-flow hook
|
|
153
|
+
SaveConfirmModal, // MERGE/REPLACE/ACTIVATE confirmation modal
|
|
154
|
+
ConflictBanner, // HTTP 409 conflict UI
|
|
155
|
+
ConflictBannerProps,
|
|
156
|
+
diffSummary, // Terse server vs local diff string
|
|
157
|
+
I18nContext,
|
|
158
|
+
useMessages,
|
|
159
|
+
mergeMessages,
|
|
160
|
+
defaultMessages,
|
|
161
|
+
} from "@cyoda/workflow-react";
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Editor metadata: what stays out of exported JSON
|
|
165
|
+
|
|
166
|
+
Layout positions, comments, edge anchors, and viewport data live in
|
|
167
|
+
`doc.meta.workflowUi` and are **never** written to exported Cyoda workflow
|
|
168
|
+
JSON. `serializeImportPayload(doc)` always produces a clean, canonical
|
|
169
|
+
output regardless of what has been dragged or annotated.
|
|
170
|
+
|
|
171
|
+
## Runtime notes
|
|
19
172
|
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
173
|
+
- Browser-only (React 18, DOM required).
|
|
174
|
+
- Imports `reactflow/dist/style.css` — ensure your bundler handles CSS.
|
|
175
|
+
- `reactflow` must be installed as a peer dependency (`^11`).
|
|
23
176
|
|
|
24
177
|
## Documentation
|
|
25
178
|
|
|
26
|
-
See the
|
|
27
|
-
[repository README](https://github.com/Cyoda-platform/cyoda-workflow-editor#readme)
|
|
28
|
-
for package relationships, usage examples, and release notes.
|
|
179
|
+
See the [repository README](https://github.com/Cyoda-platform/cyoda-workflow-editor#readme).
|
|
29
180
|
|
|
30
181
|
## License
|
|
31
182
|
|