@01.software/sdk 0.2.9-dev.260306.4e16dd4 → 0.2.9-dev.260309.c56872d

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/flow.d.cts CHANGED
@@ -1,31 +1,12 @@
1
1
  import React from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
2
3
 
3
- declare const FLOW_NODE_TYPES: readonly ["text", "image", "iframe", "note"];
4
- type FlowNodeType = (typeof FLOW_NODE_TYPES)[number];
5
- interface BaseNodeData {
4
+ interface DynamicNodeData {
5
+ nodeTypeSlug: string;
6
6
  label: string;
7
+ fields: Record<string, unknown>;
7
8
  }
8
- interface TextNodeData extends BaseNodeData {
9
- nodeType: 'text';
10
- body?: string;
11
- }
12
- interface ImageNodeData extends BaseNodeData {
13
- nodeType: 'image';
14
- imageId?: string;
15
- imageUrl?: string;
16
- alt?: string;
17
- caption?: string;
18
- }
19
- interface IframeNodeData extends BaseNodeData {
20
- nodeType: 'iframe';
21
- url?: string;
22
- }
23
- interface NoteNodeData extends BaseNodeData {
24
- nodeType: 'note';
25
- body?: string;
26
- color?: string;
27
- }
28
- type FlowNodeData = (TextNodeData | ImageNodeData | IframeNodeData | NoteNodeData) & Record<string, unknown>;
9
+ type FlowNodeData = DynamicNodeData & Record<string, unknown>;
29
10
  interface FlowNodePosition {
30
11
  x: number;
31
12
  y: number;
@@ -42,6 +23,7 @@ interface FlowNode {
42
23
  width?: number;
43
24
  height?: number;
44
25
  };
26
+ draggable?: boolean;
45
27
  [key: string]: unknown;
46
28
  }
47
29
  interface FlowEdge {
@@ -52,6 +34,8 @@ interface FlowEdge {
52
34
  targetHandle?: string | null;
53
35
  type?: string;
54
36
  style?: React.CSSProperties;
37
+ edgeTypeSlug?: string;
38
+ fields?: Record<string, unknown>;
55
39
  [key: string]: unknown;
56
40
  }
57
41
  interface FlowViewport {
@@ -64,28 +48,82 @@ interface CanvasData {
64
48
  edges: FlowEdge[];
65
49
  viewport: FlowViewport;
66
50
  }
67
- interface TextNodeSlotProps {
51
+ interface NodeTypeFieldDef {
52
+ name: string;
53
+ label: string;
54
+ fieldType: 'text' | 'textarea' | 'number' | 'url' | 'color' | 'image' | 'select' | 'toggle';
55
+ options?: {
56
+ label: string;
57
+ value: string;
58
+ }[];
59
+ defaultValue?: string;
60
+ required?: boolean;
61
+ }
62
+ interface NodeTypeDef {
63
+ slug: string;
64
+ name: string;
65
+ color: string;
66
+ defaultSize: {
67
+ width: number;
68
+ height: number;
69
+ };
70
+ fields: NodeTypeFieldDef[];
71
+ transparentBackground?: boolean;
72
+ }
73
+ interface EdgeTypeDef {
74
+ slug: string;
75
+ name: string;
76
+ color: string;
77
+ strokeWidth: number;
78
+ animated: boolean;
79
+ lineStyle: string;
80
+ fields: NodeTypeFieldDef[];
81
+ }
82
+ declare function isDynamicNode(node: FlowNode): node is FlowNode & {
83
+ data: DynamicNodeData;
84
+ };
85
+ declare function isFrameNode(node: FlowNode): node is FlowNode & {
86
+ data: FrameNodeData;
87
+ };
88
+ interface DynamicNodeSlotProps {
68
89
  id: string;
69
- data: TextNodeData;
90
+ nodeTypeSlug: string;
91
+ label: string;
92
+ fields: Record<string, unknown>;
93
+ nodeTypeDef?: NodeTypeDef;
70
94
  }
71
- interface ImageNodeSlotProps {
72
- id: string;
73
- data: ImageNodeData;
95
+ interface FrameNodeData {
96
+ label: string;
97
+ color?: string;
98
+ padding?: number;
74
99
  }
75
- interface IframeNodeSlotProps {
76
- id: string;
77
- data: IframeNodeData;
100
+
101
+ declare const BUILT_IN_NODE_TYPES: NodeTypeDef[];
102
+
103
+ declare const BUILT_IN_EDGE_TYPES: EdgeTypeDef[];
104
+
105
+ interface FlowClient {
106
+ from(collection: string): {
107
+ find(options?: Record<string, unknown>): Promise<{
108
+ docs: Record<string, unknown>[];
109
+ }>;
110
+ findById(id: string, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
111
+ };
112
+ queryClient: QueryClient;
78
113
  }
79
- interface NoteNodeSlotProps {
80
- id: string;
81
- data: NoteNodeData;
114
+ interface UseFlowOptions {
115
+ client: FlowClient;
116
+ enabled?: boolean;
82
117
  }
83
- interface FlowNodeComponents {
84
- Text?: React.ComponentType<TextNodeSlotProps>;
85
- Image?: React.ComponentType<ImageNodeSlotProps>;
86
- Iframe?: React.ComponentType<IframeNodeSlotProps>;
87
- Note?: React.ComponentType<NoteNodeSlotProps>;
118
+ interface UseFlowResult {
119
+ data: CanvasData | undefined;
120
+ nodeTypeDefs: NodeTypeDef[];
121
+ edgeTypeDefs: EdgeTypeDef[];
122
+ flow: Record<string, unknown> | undefined;
123
+ isLoading: boolean;
124
+ error: Error | null;
88
125
  }
126
+ declare function useFlow(slugOrId: string, options: UseFlowOptions): UseFlowResult;
89
127
 
90
128
  /**
91
129
  * Renders a Flow canvas in read-only mode.
@@ -102,15 +140,21 @@ interface FlowRendererProps {
102
140
  className?: string;
103
141
  /** Container style */
104
142
  style?: React.CSSProperties;
105
- /** Custom node type components (memoize or define outside component to avoid re-renders) */
106
- nodeComponents?: FlowNodeComponents;
143
+ /** Custom renderers by node type slug (e.g., `{ 'product-card': MyProductCard }`) */
144
+ nodeRenderers?: Record<string, React.ComponentType<DynamicNodeSlotProps>>;
145
+ /** Node type definitions for enhanced rendering (color badges, field-type-aware display) */
146
+ nodeTypeDefs?: NodeTypeDef[];
107
147
  /** Show background pattern (default: true) */
108
148
  background?: boolean;
109
149
  /** Allow user interaction - pan, zoom (default: false for read-only display) */
110
150
  interactive?: boolean;
111
151
  /** Fit view on mount (default: true) */
112
152
  fitView?: boolean;
153
+ /** Called when a node is clicked */
154
+ onNodeClick?: (event: React.MouseEvent, node: FlowNode) => void;
155
+ /** Called when an edge is clicked */
156
+ onEdgeClick?: (event: React.MouseEvent, edge: FlowEdge) => void;
113
157
  }
114
- declare function FlowRenderer({ data, className, style, nodeComponents, background, interactive, fitView, }: FlowRendererProps): React.JSX.Element;
158
+ declare function FlowRenderer({ data, className, style, nodeRenderers, nodeTypeDefs, background, interactive, fitView, onNodeClick, onEdgeClick, }: FlowRendererProps): React.JSX.Element | null;
115
159
 
116
- export { type CanvasData, FLOW_NODE_TYPES, type FlowEdge, type FlowNode, type FlowNodeComponents, type FlowNodeData, type FlowNodePosition, type FlowNodeType, FlowRenderer, type FlowRendererProps, type FlowViewport, type IframeNodeData, type IframeNodeSlotProps, type ImageNodeData, type ImageNodeSlotProps, type NoteNodeData, type NoteNodeSlotProps, type TextNodeData, type TextNodeSlotProps };
160
+ export { BUILT_IN_EDGE_TYPES, BUILT_IN_NODE_TYPES, type CanvasData, type DynamicNodeData, type DynamicNodeSlotProps, type EdgeTypeDef, type FlowEdge, type FlowNode, type FlowNodeData, type FlowNodePosition, FlowRenderer, type FlowRendererProps, type FlowViewport, type FrameNodeData, type NodeTypeDef, type NodeTypeFieldDef, type UseFlowOptions, type UseFlowResult, isDynamicNode, isFrameNode, useFlow };
package/dist/flow.d.ts CHANGED
@@ -1,31 +1,12 @@
1
1
  import React from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
2
3
 
3
- declare const FLOW_NODE_TYPES: readonly ["text", "image", "iframe", "note"];
4
- type FlowNodeType = (typeof FLOW_NODE_TYPES)[number];
5
- interface BaseNodeData {
4
+ interface DynamicNodeData {
5
+ nodeTypeSlug: string;
6
6
  label: string;
7
+ fields: Record<string, unknown>;
7
8
  }
8
- interface TextNodeData extends BaseNodeData {
9
- nodeType: 'text';
10
- body?: string;
11
- }
12
- interface ImageNodeData extends BaseNodeData {
13
- nodeType: 'image';
14
- imageId?: string;
15
- imageUrl?: string;
16
- alt?: string;
17
- caption?: string;
18
- }
19
- interface IframeNodeData extends BaseNodeData {
20
- nodeType: 'iframe';
21
- url?: string;
22
- }
23
- interface NoteNodeData extends BaseNodeData {
24
- nodeType: 'note';
25
- body?: string;
26
- color?: string;
27
- }
28
- type FlowNodeData = (TextNodeData | ImageNodeData | IframeNodeData | NoteNodeData) & Record<string, unknown>;
9
+ type FlowNodeData = DynamicNodeData & Record<string, unknown>;
29
10
  interface FlowNodePosition {
30
11
  x: number;
31
12
  y: number;
@@ -42,6 +23,7 @@ interface FlowNode {
42
23
  width?: number;
43
24
  height?: number;
44
25
  };
26
+ draggable?: boolean;
45
27
  [key: string]: unknown;
46
28
  }
47
29
  interface FlowEdge {
@@ -52,6 +34,8 @@ interface FlowEdge {
52
34
  targetHandle?: string | null;
53
35
  type?: string;
54
36
  style?: React.CSSProperties;
37
+ edgeTypeSlug?: string;
38
+ fields?: Record<string, unknown>;
55
39
  [key: string]: unknown;
56
40
  }
57
41
  interface FlowViewport {
@@ -64,28 +48,82 @@ interface CanvasData {
64
48
  edges: FlowEdge[];
65
49
  viewport: FlowViewport;
66
50
  }
67
- interface TextNodeSlotProps {
51
+ interface NodeTypeFieldDef {
52
+ name: string;
53
+ label: string;
54
+ fieldType: 'text' | 'textarea' | 'number' | 'url' | 'color' | 'image' | 'select' | 'toggle';
55
+ options?: {
56
+ label: string;
57
+ value: string;
58
+ }[];
59
+ defaultValue?: string;
60
+ required?: boolean;
61
+ }
62
+ interface NodeTypeDef {
63
+ slug: string;
64
+ name: string;
65
+ color: string;
66
+ defaultSize: {
67
+ width: number;
68
+ height: number;
69
+ };
70
+ fields: NodeTypeFieldDef[];
71
+ transparentBackground?: boolean;
72
+ }
73
+ interface EdgeTypeDef {
74
+ slug: string;
75
+ name: string;
76
+ color: string;
77
+ strokeWidth: number;
78
+ animated: boolean;
79
+ lineStyle: string;
80
+ fields: NodeTypeFieldDef[];
81
+ }
82
+ declare function isDynamicNode(node: FlowNode): node is FlowNode & {
83
+ data: DynamicNodeData;
84
+ };
85
+ declare function isFrameNode(node: FlowNode): node is FlowNode & {
86
+ data: FrameNodeData;
87
+ };
88
+ interface DynamicNodeSlotProps {
68
89
  id: string;
69
- data: TextNodeData;
90
+ nodeTypeSlug: string;
91
+ label: string;
92
+ fields: Record<string, unknown>;
93
+ nodeTypeDef?: NodeTypeDef;
70
94
  }
71
- interface ImageNodeSlotProps {
72
- id: string;
73
- data: ImageNodeData;
95
+ interface FrameNodeData {
96
+ label: string;
97
+ color?: string;
98
+ padding?: number;
74
99
  }
75
- interface IframeNodeSlotProps {
76
- id: string;
77
- data: IframeNodeData;
100
+
101
+ declare const BUILT_IN_NODE_TYPES: NodeTypeDef[];
102
+
103
+ declare const BUILT_IN_EDGE_TYPES: EdgeTypeDef[];
104
+
105
+ interface FlowClient {
106
+ from(collection: string): {
107
+ find(options?: Record<string, unknown>): Promise<{
108
+ docs: Record<string, unknown>[];
109
+ }>;
110
+ findById(id: string, options?: Record<string, unknown>): Promise<Record<string, unknown>>;
111
+ };
112
+ queryClient: QueryClient;
78
113
  }
79
- interface NoteNodeSlotProps {
80
- id: string;
81
- data: NoteNodeData;
114
+ interface UseFlowOptions {
115
+ client: FlowClient;
116
+ enabled?: boolean;
82
117
  }
83
- interface FlowNodeComponents {
84
- Text?: React.ComponentType<TextNodeSlotProps>;
85
- Image?: React.ComponentType<ImageNodeSlotProps>;
86
- Iframe?: React.ComponentType<IframeNodeSlotProps>;
87
- Note?: React.ComponentType<NoteNodeSlotProps>;
118
+ interface UseFlowResult {
119
+ data: CanvasData | undefined;
120
+ nodeTypeDefs: NodeTypeDef[];
121
+ edgeTypeDefs: EdgeTypeDef[];
122
+ flow: Record<string, unknown> | undefined;
123
+ isLoading: boolean;
124
+ error: Error | null;
88
125
  }
126
+ declare function useFlow(slugOrId: string, options: UseFlowOptions): UseFlowResult;
89
127
 
90
128
  /**
91
129
  * Renders a Flow canvas in read-only mode.
@@ -102,15 +140,21 @@ interface FlowRendererProps {
102
140
  className?: string;
103
141
  /** Container style */
104
142
  style?: React.CSSProperties;
105
- /** Custom node type components (memoize or define outside component to avoid re-renders) */
106
- nodeComponents?: FlowNodeComponents;
143
+ /** Custom renderers by node type slug (e.g., `{ 'product-card': MyProductCard }`) */
144
+ nodeRenderers?: Record<string, React.ComponentType<DynamicNodeSlotProps>>;
145
+ /** Node type definitions for enhanced rendering (color badges, field-type-aware display) */
146
+ nodeTypeDefs?: NodeTypeDef[];
107
147
  /** Show background pattern (default: true) */
108
148
  background?: boolean;
109
149
  /** Allow user interaction - pan, zoom (default: false for read-only display) */
110
150
  interactive?: boolean;
111
151
  /** Fit view on mount (default: true) */
112
152
  fitView?: boolean;
153
+ /** Called when a node is clicked */
154
+ onNodeClick?: (event: React.MouseEvent, node: FlowNode) => void;
155
+ /** Called when an edge is clicked */
156
+ onEdgeClick?: (event: React.MouseEvent, edge: FlowEdge) => void;
113
157
  }
114
- declare function FlowRenderer({ data, className, style, nodeComponents, background, interactive, fitView, }: FlowRendererProps): React.JSX.Element;
158
+ declare function FlowRenderer({ data, className, style, nodeRenderers, nodeTypeDefs, background, interactive, fitView, onNodeClick, onEdgeClick, }: FlowRendererProps): React.JSX.Element | null;
115
159
 
116
- export { type CanvasData, FLOW_NODE_TYPES, type FlowEdge, type FlowNode, type FlowNodeComponents, type FlowNodeData, type FlowNodePosition, type FlowNodeType, FlowRenderer, type FlowRendererProps, type FlowViewport, type IframeNodeData, type IframeNodeSlotProps, type ImageNodeData, type ImageNodeSlotProps, type NoteNodeData, type NoteNodeSlotProps, type TextNodeData, type TextNodeSlotProps };
160
+ export { BUILT_IN_EDGE_TYPES, BUILT_IN_NODE_TYPES, type CanvasData, type DynamicNodeData, type DynamicNodeSlotProps, type EdgeTypeDef, type FlowEdge, type FlowNode, type FlowNodeData, type FlowNodePosition, FlowRenderer, type FlowRendererProps, type FlowViewport, type FrameNodeData, type NodeTypeDef, type NodeTypeFieldDef, type UseFlowOptions, type UseFlowResult, isDynamicNode, isFrameNode, useFlow };