@squeed/flow-sdk 0.1.14 → 0.1.16

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/dist/index.d.ts CHANGED
@@ -1,8 +1,36 @@
1
1
  import { JSX as JSX_2 } from 'react/jsx-runtime';
2
2
  import { MutableRefObject } from 'react';
3
3
 
4
+ /** Add a child under `parentAddress`. Returns the new node's address. */
5
+ export declare function addChild(json: SqueedJson, parentAddress: string, child: any, key?: string): {
6
+ json: SqueedJson;
7
+ address: string;
8
+ };
9
+
10
+ /** "root.a.b.#" → ["a", "b"] */
11
+ export declare function addressToPath(address: string): string[];
12
+
13
+ /** `$target` cross-link (the compiler supports one per node; an existing one is replaced) */
14
+ export declare const addTargetEdge: (json: SqueedJson, sourceAddress: string, targetAddress: string, label?: string) => SqueedJson;
15
+
16
+ /**
17
+ * For hand-built graphs (no Squeed JSON): hide everything downstream of a node whose
18
+ * `data.config.collapsed` is true, plus the edges touching hidden nodes.
19
+ */
20
+ export declare function applyCollapsed(nodes: FlowDiagramNode[], edges: FlowDiagramEdge[]): {
21
+ nodes: FlowDiagramNode[];
22
+ edges: FlowDiagramEdge[];
23
+ };
24
+
4
25
  export declare type BackgroundPattern = "dot" | "steel" | "grid" | "none";
5
26
 
27
+ /**
28
+ * Wrap consumer callbacks so every toolbar/edit event is applied to `json`
29
+ * with Squeed `$` keys and delivered via `onJsonChange`. Granular callbacks
30
+ * still fire first (for logging/analytics) — consumers must not also mutate.
31
+ */
32
+ export declare function bindSqueedCallbacks(json: SqueedJson, compiledEdges: FlowDiagramEdge[], callbacks: FlowDiagramCallbacks, onJsonChange?: (json: SqueedJson, change: SqueedChange) => void): FlowDiagramCallbacks;
33
+
6
34
  /** Props passed to custom bottom bar renderer */
7
35
  export declare interface BottomBarRenderProps {
8
36
  zoomIn: () => void;
@@ -28,6 +56,25 @@ export declare interface BottomBarRenderProps {
28
56
  callbacks: FlowDiagramCallbacks;
29
57
  }
30
58
 
59
+ export declare interface CompileOptions {
60
+ title?: string;
61
+ /** Root in the middle, children fan out both ways (direction "C") */
62
+ isCenter?: boolean;
63
+ hideDefaultObject?: boolean;
64
+ separateObjectKeys?: boolean;
65
+ }
66
+
67
+ /**
68
+ * `createFlowDiagram` + post-pass:
69
+ * - deterministic edge ids (`source->target[#n]`) so selection survives regeneration
70
+ * - honors `$isEdgeDashed` / `$edgeColor`, which the compiler doesn't read
71
+ * - `$label` wins over the compiler's shared-config `headerTitle` (it leaks the previous node's title)
72
+ */
73
+ export declare function compileSqueed(json: SqueedJson, opts?: CompileOptions): {
74
+ nodes: FlowDiagramNode[];
75
+ edges: FlowDiagramEdge[];
76
+ };
77
+
31
78
  export declare const contentObjTheme: (color: any) => {
32
79
  background: any;
33
80
  highlight: string;
@@ -48,7 +95,7 @@ export declare const DynamicIcon: ({ name, ...props }: {
48
95
  name: any;
49
96
  }) => JSX_2.Element;
50
97
 
51
- export declare function FlowDiagram({ title, nodes, edges, config, callbacks, className, style, showBottomBar, }: FlowDiagramProps & {
98
+ export declare function FlowDiagram({ title, json, nodes, edges, config, callbacks, className, style, showBottomBar, }: FlowDiagramProps & {
52
99
  showBottomBar?: boolean;
53
100
  }): JSX_2.Element;
54
101
 
@@ -87,6 +134,8 @@ export declare interface FlowDiagramCallbacks {
87
134
  onEdgeDeselect?: () => void;
88
135
  /** Fires when an edge is removed */
89
136
  onEdgeRemove?: (edgeId: string, edgeData: any) => void;
137
+ /** Fires when the user deletes an edge from the selection toolbar */
138
+ onEdgeDelete?: (edgeId: string, edgeData: any) => void;
90
139
  /** Fires when an edge's color is changed */
91
140
  onEdgeColorChange?: (edgeId: string, color: string) => void;
92
141
  /** Fires when an edge's label is changed */
@@ -107,6 +156,11 @@ export declare interface FlowDiagramCallbacks {
107
156
  onArrayModeChange?: (isArrayMode: boolean) => void;
108
157
  /** Fires when Cytoscape instance is initialized (for advanced use) */
109
158
  onCyInit?: (cy: any) => void;
159
+ /**
160
+ * Fires with the updated Squeed JSON after any toolbar/inline edit. The SDK applies the
161
+ * edit with `$` schema keys; store the result and pass it back as `json`.
162
+ */
163
+ onJsonChange?: (json: Record<string, any> | any[], change: SqueedChangeInfo) => void;
110
164
  }
111
165
 
112
166
  /** Configuration for the flow diagram appearance and behavior */
@@ -125,6 +179,8 @@ export declare interface FlowDiagramConfig {
125
179
  backgroundColor?: string;
126
180
  /** Edge/line color override */
127
181
  edgeColor?: string;
182
+ /** Default style for all compound/container nodes (per-node `viewProps` override it) */
183
+ parentNodeStyle?: ParentNodeStyle;
128
184
  /** Min zoom level (default: 0.01) */
129
185
  minZoom?: number;
130
186
  /** Max zoom level (default: 1.5) */
@@ -153,6 +209,8 @@ export declare interface FlowDiagramConfig {
153
209
  renderSelectedEdgeToolbar?: (props: SelectedEdgeToolbarProps) => React.ReactNode;
154
210
  /** Custom render function to replace the entire built-in bottom bar */
155
211
  renderBottomBar?: (props: BottomBarRenderProps) => React.ReactNode;
212
+ /** Built-in node/edge selection toolbars (bottom bar swaps to them on select). `false` disables. */
213
+ selectionToolbar?: SelectionToolbarConfig | false;
156
214
  /** Custom node view components to override SDK defaults. Keys: objectView, arrayView, text, parentContainer */
157
215
  customViews?: Record<string, React.ComponentType<any>>;
158
216
  /** Disable built-in keyboard shortcuts (Z/M/D) when the consumer handles its own */
@@ -173,6 +231,8 @@ export declare interface FlowDiagramEdge {
173
231
  source: string;
174
232
  target: string;
175
233
  label?: string;
234
+ /** Chakra token or hex; overrides the theme/edgeColor line color for this edge */
235
+ color?: string;
176
236
  isInverted?: boolean;
177
237
  isEdgeAnimated?: boolean;
178
238
  isEdgeDashed?: boolean;
@@ -198,6 +258,11 @@ export declare interface FlowDiagramNode {
198
258
  export declare interface FlowDiagramProps {
199
259
  /** Title shown on the root node */
200
260
  title?: string;
261
+ /**
262
+ * Squeed JSON document. When provided, nodes/edges are compiled from it and every
263
+ * edit is reported through `callbacks.onJsonChange`. Takes precedence over nodes/edges.
264
+ */
265
+ json?: Record<string, any> | any[];
201
266
  /** Pre-computed nodes */
202
267
  nodes?: FlowDiagramNode[];
203
268
  /** Pre-computed edges */
@@ -212,7 +277,8 @@ export declare interface FlowDiagramProps {
212
277
  style?: React.CSSProperties;
213
278
  }
214
279
 
215
- export declare type FlowDirection = "LR" | "RL" | "TB" | "BT";
280
+ /** "C" = center: root in the middle, children fan out both ways (generate with `isCntr: true`); laid out as LR */
281
+ export declare type FlowDirection = "LR" | "RL" | "TB" | "BT" | "C";
216
282
 
217
283
  export declare const getChakraColorHex: (color?: any, opacity?: any) => any;
218
284
 
@@ -228,6 +294,8 @@ export declare const getColorVariant: (color: string) => {
228
294
 
229
295
  export declare function getDarkerHexColor(hex: string, factor?: number): string;
230
296
 
297
+ export declare function getNode(json: SqueedJson, address: string): any;
298
+
231
299
  export declare type LayoutAlgorithm = "dagre" | "elk" | "tidytree" | "concentric" | "cose";
232
300
 
233
301
  /** Actions shown in the hover overlay above nodes */
@@ -247,6 +315,56 @@ export declare interface NodeOverlayProps {
247
315
  setIsHovered: (v: boolean) => void;
248
316
  }
249
317
 
318
+ /**
319
+ * Style for compound (container) nodes. Set per node via `data.viewProps`,
320
+ * or for all containers via `config.parentNodeStyle` (per-node wins).
321
+ * Colors accept Chakra tokens ("purple.500") or hex.
322
+ */
323
+ export declare interface ParentNodeStyle {
324
+ /** Fill color; also the default border/label color (default: themeColor) */
325
+ bgColor?: string;
326
+ /** Fill opacity 0–1 (default 0.4) */
327
+ bgOpacity?: number;
328
+ borderColor?: string;
329
+ /** px (default 6) */
330
+ borderWidth?: number;
331
+ borderStyle?: "solid" | "dashed" | "dotted" | "double";
332
+ /** Corner radius px (default 50) */
333
+ borderRadius?: number;
334
+ /** Label color (default: bgColor) */
335
+ textColor?: string;
336
+ /** Label size px (default 70) */
337
+ fontSize?: number;
338
+ /** Inner padding px (default 120) */
339
+ padding?: number;
340
+ /** Label placement (default "top") */
341
+ labelPosition?: "top" | "center" | "bottom";
342
+ }
343
+
344
+ /** Removes a `$target` edge; hierarchy edges cannot be removed without removing the child (returns json unchanged). */
345
+ export declare function removeEdge(json: SqueedJson, edge: RenderedEdgeRef): {
346
+ json: SqueedJson;
347
+ removed: boolean;
348
+ };
349
+
350
+ export declare function removeNode(json: SqueedJson, address: string): SqueedJson;
351
+
352
+ export declare interface RenderedEdgeRef {
353
+ source: string;
354
+ target: string;
355
+ isInverted?: boolean | null;
356
+ }
357
+
358
+ /**
359
+ * Resolve which JSON node carries an edge's keys.
360
+ * parent→child edges (implicit hierarchy) are configured on the child;
361
+ * `$target` cross-links are configured on the source node.
362
+ */
363
+ export declare function resolveEdgeOwner(edge: RenderedEdgeRef): {
364
+ address: string;
365
+ kind: "hierarchy" | "target";
366
+ };
367
+
250
368
  /** Props passed to custom edge selection toolbar renderer */
251
369
  export declare interface SelectedEdgeToolbarProps {
252
370
  edgeId: string;
@@ -261,7 +379,64 @@ export declare interface SelectedNodeToolbarProps {
261
379
  onDeselect: () => void;
262
380
  }
263
381
 
382
+ /** Built-in selection toolbars (shown in the bottom bar when a node/edge is selected) */
383
+ export declare interface SelectionToolbarConfig {
384
+ /** Swatches offered for node/edge colors (Chakra tokens or hex). Default: 9 Chakra 500s */
385
+ palette?: string[];
386
+ /** Hide individual controls */
387
+ hide?: Array<"label" | "color" | "textColor" | "style" | "icon" | "collapse" | "delete">;
388
+ }
389
+
390
+ export declare const setCollapsed: (json: SqueedJson, address: string, collapsed: boolean) => SqueedJson;
391
+
392
+ export declare function setEdgeProp(json: SqueedJson, edge: RenderedEdgeRef, key: SqueedEdgeKey, value: any): SqueedJson;
393
+
394
+ export declare const setEdgeStyle: (json: SqueedJson, edge: RenderedEdgeRef, style: "solid" | "dashed" | "animated") => SqueedJson;
395
+
396
+ export declare function setNodeProp(json: SqueedJson, address: string, key: SqueedNodeKey, value: any): SqueedJson;
397
+
398
+ /** What changed in the Squeed document (delivered alongside the new JSON) */
399
+ export declare interface SqueedChange {
400
+ type: "nodeLabel" | "nodeColor" | "nodeIcon" | "nodeCollapse" | "nodeCreate" | "nodeDelete" | "edgeLabel" | "edgeStyle" | "edgeColor" | "edgeCreate" | "edgeDelete";
401
+ /** Node address affected (new node's address for nodeCreate) */
402
+ address?: string;
403
+ edge?: RenderedEdgeRef;
404
+ /** `$` key written, when a single key changed */
405
+ key?: string;
406
+ value?: unknown;
407
+ }
408
+
409
+ /** Describes the edit behind an `onJsonChange` */
410
+ export declare interface SqueedChangeInfo {
411
+ type: "nodeLabel" | "nodeColor" | "nodeIcon" | "nodeCollapse" | "nodeCreate" | "nodeDelete" | "edgeLabel" | "edgeStyle" | "edgeColor" | "edgeCreate" | "edgeDelete";
412
+ address?: string;
413
+ edge?: {
414
+ source: string;
415
+ target: string;
416
+ isInverted?: boolean | null;
417
+ };
418
+ key?: string;
419
+ value?: unknown;
420
+ }
421
+
422
+ /** Schema keys that describe the edge *into* a node (parent → child) */
423
+ export declare type SqueedEdgeKey = "$sourceLabel" | "$isEdgeAnimated" | "$isEdgeDashed" | "$edgeColor";
424
+
425
+ /**
426
+ * Squeed JSON = the source document `createFlowDiagram` compiles into nodes/edges.
427
+ * Node ids are JSON addresses ("root.a.b"); these helpers translate toolbar edits
428
+ * back into `$`-prefixed schema keys at that address. All functions are immutable.
429
+ */
430
+ export declare type SqueedJson = Record<string, any> | any[];
431
+
432
+ /** Schema keys that live on a node */
433
+ export declare type SqueedNodeKey = "$label" | "$bgColor" | "$textColor" | "$borderColor" | "$borderRadius" | "$fontSize" | "$icon" | "$content" | "$media" | "$collapsed" | "$parent";
434
+
435
+ /** Immutable update of the node at `address` (root address updates the document itself) */
436
+ export declare function updateNode(json: SqueedJson, address: string, fn: (node: any) => any): SqueedJson;
437
+
264
438
  export declare function useCustomColors(theme?: any): {
439
+ canvas: string;
265
440
  background: string;
266
441
  backgroundSecondary: string;
267
442
  darkBackgroundSecondary: string;