@squeed/flow-sdk 0.1.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 +234 -0
- package/dist/index.cjs +358 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +192 -0
- package/dist/index.js +30584 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# @squeed/flow-sdk
|
|
2
|
+
|
|
3
|
+
Standalone React component for rendering interactive flow diagrams from JSON.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @squeed/flow-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `react`, `react-dom`, `@chakra-ui/react`, `@chakra-ui/icons`, `@emotion/react`, `@emotion/styled`, `framer-motion`
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { FlowDiagram } from "@squeed/flow-sdk";
|
|
17
|
+
|
|
18
|
+
function App() {
|
|
19
|
+
return (
|
|
20
|
+
<FlowDiagram
|
|
21
|
+
json={{ name: "Hello", version: "1.0", nested: { key: "value" } }}
|
|
22
|
+
title="My Diagram"
|
|
23
|
+
config={{ direction: "LR", colorMode: "dark", themeColor: "blue.500" }}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Props
|
|
30
|
+
|
|
31
|
+
### `FlowDiagramProps`
|
|
32
|
+
|
|
33
|
+
| Prop | Type | Description |
|
|
34
|
+
|------|------|-------------|
|
|
35
|
+
| `json` | `any` | JSON object or string to render as a flow diagram |
|
|
36
|
+
| `title` | `string` | Title shown on the root node (default: `"untitled"`) |
|
|
37
|
+
| `nodes` | `FlowDiagramNode[]` | Pre-computed nodes (alternative to `json`) |
|
|
38
|
+
| `edges` | `FlowDiagramEdge[]` | Pre-computed edges (alternative to `json`) |
|
|
39
|
+
| `config` | `FlowDiagramConfig` | Diagram configuration |
|
|
40
|
+
| `callbacks` | `FlowDiagramCallbacks` | Event callbacks |
|
|
41
|
+
| `showBottomBar` | `boolean` | Show the direction/mode bottom bar (default: `true`) |
|
|
42
|
+
| `className` | `string` | CSS class name |
|
|
43
|
+
| `style` | `CSSProperties` | Inline styles |
|
|
44
|
+
|
|
45
|
+
You can provide either `json` (auto-generates nodes/edges) or `nodes` + `edges` (pre-computed).
|
|
46
|
+
|
|
47
|
+
## Config
|
|
48
|
+
|
|
49
|
+
### `FlowDiagramConfig`
|
|
50
|
+
|
|
51
|
+
| Option | Type | Default | Description |
|
|
52
|
+
|--------|------|---------|-------------|
|
|
53
|
+
| `direction` | `"LR" \| "RL" \| "TB" \| "BT"` | `"LR"` | Layout direction |
|
|
54
|
+
| `layout` | `"dagre" \| "elk" \| "tidytree" \| "concentric" \| "cose"` | `"dagre"` | Layout algorithm |
|
|
55
|
+
| `themeColor` | `string` | `"blue.500"` | Accent color (Chakra token) |
|
|
56
|
+
| `colorMode` | `"light" \| "dark"` | `"light"` | Color mode |
|
|
57
|
+
| `backgroundPattern` | `"dot" \| "grid" \| "steel" \| "none"` | `"dot"` | Background pattern |
|
|
58
|
+
| `backgroundColor` | `string` | — | Background color override |
|
|
59
|
+
| `edgeColor` | `string` | — | Edge/line color override |
|
|
60
|
+
| `minZoom` | `number` | `0.01` | Minimum zoom level |
|
|
61
|
+
| `maxZoom` | `number` | `1.5` | Maximum zoom level |
|
|
62
|
+
| `initialViewport` | `{ pan: { x, y }, zoom }` | — | Initial viewport |
|
|
63
|
+
| `edgeHandles` | `boolean` | `true` | Enable edge drawing handles |
|
|
64
|
+
| `readOnly` | `boolean` | `false` | Disable all interactions |
|
|
65
|
+
| `editable` | `boolean` | `false` | Enable inline node label editing |
|
|
66
|
+
| `autoCollapse` | `boolean \| AutoCollapseConfig` | — | Auto-collapse deep nodes for large data |
|
|
67
|
+
| `nodeOverlayActions` | `NodeOverlayAction[]` | — | Actions in node hover overlay |
|
|
68
|
+
| `renderNodeOverlay` | `(props: NodeOverlayProps) => ReactNode` | — | Custom node hover overlay |
|
|
69
|
+
| `renderSelectedNodeToolbar` | `(props: SelectedNodeToolbarProps) => ReactNode` | — | Custom multi-select toolbar |
|
|
70
|
+
|
|
71
|
+
## Auto-Collapse
|
|
72
|
+
|
|
73
|
+
For large JSON structures, enable auto-collapse to keep the diagram manageable. Nodes are collapsed at every Nth depth level when the data exceeds size thresholds.
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
// Use defaults (800+ lines AND 5+ depth triggers collapse every 3 levels)
|
|
77
|
+
<FlowDiagram json={largeJson} config={{ autoCollapse: true }} />
|
|
78
|
+
|
|
79
|
+
// Custom thresholds
|
|
80
|
+
<FlowDiagram
|
|
81
|
+
json={largeJson}
|
|
82
|
+
config={{
|
|
83
|
+
autoCollapse: {
|
|
84
|
+
minLines: 200,
|
|
85
|
+
minDepth: 3,
|
|
86
|
+
collapseEveryNLevels: 2,
|
|
87
|
+
},
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### `AutoCollapseConfig`
|
|
93
|
+
|
|
94
|
+
| Option | Type | Default | Description |
|
|
95
|
+
|--------|------|---------|-------------|
|
|
96
|
+
| `minLines` | `number` | `800` | Min JSON lines to trigger |
|
|
97
|
+
| `minDepth` | `number` | `5` | Min depth to trigger |
|
|
98
|
+
| `collapseEveryNLevels` | `number` | `3` | Collapse every Nth depth level |
|
|
99
|
+
|
|
100
|
+
Both `minLines` and `minDepth` must be exceeded for auto-collapse to apply.
|
|
101
|
+
|
|
102
|
+
## Callbacks
|
|
103
|
+
|
|
104
|
+
### Node Events
|
|
105
|
+
|
|
106
|
+
| Callback | Signature | Description |
|
|
107
|
+
|----------|-----------|-------------|
|
|
108
|
+
| `onNodeSelect` | `(nodeId, nodeData) => void` | Node clicked/selected |
|
|
109
|
+
| `onNodeDeselect` | `() => void` | Selection cleared |
|
|
110
|
+
| `onNodeDoubleClick` | `(nodeId, nodeData) => void` | Node double-clicked |
|
|
111
|
+
| `onNodeCreate` | `(params) => void` | Node created via edge drawing into empty space |
|
|
112
|
+
| `onNodeDelete` | `(nodeId, nodeData) => void` | Node deleted |
|
|
113
|
+
| `onNodeLabelChange` | `(nodeId, newLabel) => void` | Node label edited inline |
|
|
114
|
+
| `onNodeCollapse` | `(nodeId, collapsed) => void` | Collapse toggle clicked |
|
|
115
|
+
| `onNodeColorChange` | `(nodeId, colorType, color) => void` | Node color changed via toolbar |
|
|
116
|
+
| `onNodeHoverAction` | `(actionId, nodeId, nodeData) => void` | Hover overlay action clicked |
|
|
117
|
+
|
|
118
|
+
### Edge Events
|
|
119
|
+
|
|
120
|
+
| Callback | Signature | Description |
|
|
121
|
+
|----------|-----------|-------------|
|
|
122
|
+
| `onEdgeCreate` | `(sourceId, targetId) => void` | New edge drawn between nodes |
|
|
123
|
+
| `onEdgeSelect` | `(edgeId, edgeData) => void` | Edge clicked/selected |
|
|
124
|
+
| `onEdgeDeselect` | `() => void` | Edge selection cleared |
|
|
125
|
+
| `onEdgeRemove` | `(edgeId, edgeData) => void` | Edge removed |
|
|
126
|
+
| `onEdgeColorChange` | `(edgeId, color) => void` | Edge color changed |
|
|
127
|
+
|
|
128
|
+
### Diagram Events
|
|
129
|
+
|
|
130
|
+
| Callback | Signature | Description |
|
|
131
|
+
|----------|-----------|-------------|
|
|
132
|
+
| `onViewportChange` | `(viewport) => void` | Pan/zoom changed |
|
|
133
|
+
| `onDirectionChange` | `(direction) => void` | Direction changed via bottom bar |
|
|
134
|
+
| `onArrayModeChange` | `(isArrayMode) => void` | Array/set mode toggled |
|
|
135
|
+
| `onCyInit` | `(cy) => void` | Cytoscape instance initialized |
|
|
136
|
+
|
|
137
|
+
## JSON Conventions
|
|
138
|
+
|
|
139
|
+
Special `$`-prefixed keys control node rendering:
|
|
140
|
+
|
|
141
|
+
| Key | Description |
|
|
142
|
+
|-----|-------------|
|
|
143
|
+
| `$label` | Display label for the node |
|
|
144
|
+
| `$bgColor` | Background color (Chakra token, e.g. `"blue.500"`) |
|
|
145
|
+
| `$textColor` | Text color |
|
|
146
|
+
| `$collapsed` | `true` to collapse children, `false` to force expanded |
|
|
147
|
+
| `$parent` | Parent node ID (creates compound/container nodes) |
|
|
148
|
+
| `$` | Array value (creates array child list, e.g. `{ $: ["a", "b"] }`) |
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"$label": "Server",
|
|
153
|
+
"$bgColor": "green.500",
|
|
154
|
+
"$collapsed": false,
|
|
155
|
+
"host": "localhost",
|
|
156
|
+
"port": 3000,
|
|
157
|
+
"routes": {
|
|
158
|
+
"$label": "API Routes",
|
|
159
|
+
"$collapsed": true,
|
|
160
|
+
"users": "/api/users",
|
|
161
|
+
"auth": "/api/auth"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Exported Utilities
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { createFlowDiagram, getJsonSize, applyAutoCollapse } from "@squeed/flow-sdk";
|
|
170
|
+
|
|
171
|
+
// Generate nodes/edges from JSON manually
|
|
172
|
+
const { nodes, edges } = createFlowDiagram(json, "root", [], [], "Title", {
|
|
173
|
+
hideDefaultObject: false,
|
|
174
|
+
sprtObjctKy: false,
|
|
175
|
+
isCntr: false,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Measure JSON complexity
|
|
179
|
+
const { lines, depth, nodes: nodeCount } = getJsonSize(json);
|
|
180
|
+
|
|
181
|
+
// Apply auto-collapse manually
|
|
182
|
+
const collapsed = applyAutoCollapse(structuredClone(json), 3); // collapse every 3 levels
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Custom Overlays
|
|
186
|
+
|
|
187
|
+
### Node Hover Overlay
|
|
188
|
+
|
|
189
|
+
```tsx
|
|
190
|
+
<FlowDiagram
|
|
191
|
+
json={data}
|
|
192
|
+
config={{
|
|
193
|
+
renderNodeOverlay: ({ nodeId, nodeData, isRoot }) => (
|
|
194
|
+
<HStack bg="gray.800" px={2} py={1} borderRadius={15}>
|
|
195
|
+
<IconButton icon={<EditIcon />} size="xs" onClick={() => edit(nodeId)} />
|
|
196
|
+
{!isRoot && <IconButton icon={<DeleteIcon />} size="xs" onClick={() => remove(nodeId)} />}
|
|
197
|
+
</HStack>
|
|
198
|
+
),
|
|
199
|
+
}}
|
|
200
|
+
/>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Selection Toolbar
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
<FlowDiagram
|
|
207
|
+
json={data}
|
|
208
|
+
config={{
|
|
209
|
+
renderSelectedNodeToolbar: ({ selectedNodeIds, onDeselect }) => (
|
|
210
|
+
<HStack bg="gray.800" px={3} py={2} borderRadius={15}>
|
|
211
|
+
<Text fontSize="xs">{selectedNodeIds.length} selected</Text>
|
|
212
|
+
<IconButton icon={<CloseIcon />} size="xs" onClick={onDeselect} />
|
|
213
|
+
</HStack>
|
|
214
|
+
),
|
|
215
|
+
}}
|
|
216
|
+
/>
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Keyboard Shortcuts
|
|
220
|
+
|
|
221
|
+
| Key | Action |
|
|
222
|
+
|-----|--------|
|
|
223
|
+
| `Z` | Toggle zoom mode (scroll to zoom) |
|
|
224
|
+
| `M` | Toggle multi-select mode |
|
|
225
|
+
| `D` | Toggle drag/pan mode |
|
|
226
|
+
|
|
227
|
+
## Theme Utilities
|
|
228
|
+
|
|
229
|
+
```tsx
|
|
230
|
+
import { useCustomColors, getChakraColorHex, getColorVariant } from "@squeed/flow-sdk";
|
|
231
|
+
|
|
232
|
+
const { background, colorText, border } = useCustomColors();
|
|
233
|
+
const hex = getChakraColorHex("blue.500"); // → "#3182ce"
|
|
234
|
+
```
|