@@ -12,6 +12,7 @@ A reusable React library for building serverless workflow editors using React Fl
1212- ** 🎨 Smart Edge Styling** : Automatic edge styling with animations, colors, and labels based on node types
1313- ** ⏮️ Undo/Redo Support** : Built-in history management with undo/redo functionality
1414- ** 📁 Import/Export** : Load and save workflows in standard Serverless Workflow JSON format
15+ - ** 🗺️ Layout Management** : Export, import, and preserve React Flow node positions and workflow layouts
1516- ** 🎨 Pre-configured Styling** : Beautiful CSS styles for nodes and edges with theme support
1617- ** 🔧 Extensible** : Easy to customize and extend with your own node types and styling
1718- ** 📱 Responsive** : Works on desktop and mobile devices
@@ -868,7 +869,13 @@ const {
868869 fitView, // Fit view to all nodes
869870 centerOnNode, // Center view on specific node
870871 getWorkflowStats, // Get workflow statistics
871- reactFlowInstance // React Flow instance
872+ reactFlowInstance, // React Flow instance
873+ // Layout management functions
874+ exportLayout, // Export current layout as object
875+ exportLayoutAsString, // Export current layout as JSON string
876+ downloadLayout, // Download layout as JSON file
877+ importLayout, // Import layout from JSON string/object
878+ copyLayoutToClipboard // Copy layout JSON to clipboard
872879} = useWorkflowState (initialNodes, initialEdges, initialMetadata);
873880```
874881
@@ -902,6 +909,67 @@ const stats = getWorkflowStats();
902909console .log (` Total nodes: ${ stats .totalNodes } ` );
903910```
904911
912+ #### Layout Management
913+
914+ The ` useWorkflowState ` hook includes powerful layout management functions for preserving and restoring React Flow node positions and workflow structure:
915+
916+ ``` jsx
917+ const {
918+ exportLayout ,
919+ exportLayoutAsString ,
920+ downloadLayout ,
921+ importLayout ,
922+ copyLayoutToClipboard
923+ } = useWorkflowState (initialNodes, initialEdges, initialMetadata);
924+
925+ // Export current layout as object
926+ const layoutData = exportLayout ();
927+ console .log (' Current layout:' , layoutData);
928+
929+ // Export as JSON string
930+ const layoutString = exportLayoutAsString ();
931+ console .log (' Layout JSON:' , layoutString);
932+
933+ // Download layout as file
934+ downloadLayout (); // Downloads 'workflow-layout.json'
935+
936+ // Copy to clipboard
937+ try {
938+ await copyLayoutToClipboard ();
939+ console .log (' Layout copied to clipboard!' );
940+ } catch (error) {
941+ console .error (' Failed to copy:' , error);
942+ }
943+
944+ // Import layout from JSON
945+ try {
946+ const result = importLayout (layoutString);
947+ // Update workflow state with imported data
948+ updateNodes (result .nodes );
949+ updateEdges (result .edges );
950+ updateWorkflowMetadata (result .metadata );
951+ } catch (error) {
952+ console .error (' Import failed:' , error .message );
953+ }
954+ ```
955+
956+ ** Layout Data Structure:**
957+ ``` jsx
958+ {
959+ nodes: [... ], // React Flow nodes with positions
960+ edges: [... ], // React Flow edges
961+ metadata: {... }, // Workflow metadata
962+ exportedAt: " 2024-01-01T12:00:00.000Z" ,
963+ version: " 1.0"
964+ }
965+ ```
966+
967+ ** Use Cases:**
968+ - ** Workflow Templates** : Save and share workflow layouts
969+ - ** Backup & Restore** : Preserve exact node positions
970+ - ** Version Control** : Track layout changes over time
971+ - ** Collaboration** : Share workflows with preserved positioning
972+
905973### useWorkflowActions
906974
907975Provides functions to programmatically add, remove, and manipulate workflow nodes.
@@ -1200,7 +1268,7 @@ const [edges, setEdges] = useState(defaultInitialEdges);
12001268### Hooks
12011269
12021270- ` useHistory ` - Undo/redo functionality
1203- - ` useWorkflowState ` - Main workflow state management
1271+ - ` useWorkflowState ` - Main workflow state management with layout import/export
12041272- ` useEdgeConnection ` - Edge connection handling
12051273- ` useWorkflowActions ` - Programmatic node manipulation
12061274- ` useNodePropertiesPanel ` - Properties panel state management
0 commit comments