You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that the export / import examples are very badly documented. With this it is only possible to export the nodes itself, but the connections and positions can not be restored with that. Therefore I want to provide my code in case you want to update that part of your documentation.
export(){constexported_nodes=[];constnodes=this.editor.getNodes();constconnections=this.editor.getConnections();for(constnodeofnodes){constnode_view=this.area_plugin.nodeViews.get(node.id);exported_nodes.push({node_class: node.constructor.name,id: node.id,name: node.name,config: node.config,params_schema: node.params_schema,position: node_view.position});}return{nodes: exported_nodes,connections: connections};}getNodeClass(node_class_name){constnode_class=nodes_list.find(node_class=>{returnnode_class.name===node_class_name;})if(!node_class){throwError(`Node class not found: ${node_class_name}.`);}else{returnnode_class;}}asyncimport(flow){constflow_data=flow?.flow_data;if(flow_data?.nodes){for(constnodeofflow_data.nodes){constnode_class=this.getNodeClass(node.node_class);awaitthis.createNode(node_class,[node.position.x,node.position.y],node.config,node.id);}}if(flow_data?.nodes&&flow_data?.connections){for(constconnofflow_data.connections){constconnection=newClassicPreset.Connection(this.editor.getNode(conn.source),conn.sourceOutput,this.editor.getNode(conn.target),conn.targetInput);awaitthis.editor.addConnection(connection);}}}asynccreateNode(node_class,position,config=null,id=null){constnode=newnode_class(config);if(id)node.id=id;// reset the id in case it is given (for example during the export)node.editor=this.editor;// give each node a reference to the editor, for advanced functions...node.area=this.area_plugin;// give each node a reference to the area plugin, for advanced functions...node.render=this.render;// give each node a reference to the render plugin, for advanced functions...awaitthis.editor.addNode(node);awaitthis.area_plugin.translate(node.id,{x: position[0],y: position[1]});}
this.editor is the editor plugin reference
this.area_plugin the reference to the area plugin.
and a short example for the nodes list. There are basically the classes that derive from your ClassicPreset.Node.
Description
Hi,
it's me againg the nuisance in person ;-).
I noticed that the export / import examples are very badly documented. With this it is only possible to export the nodes itself, but the connections and positions can not be restored with that. Therefore I want to provide my code in case you want to update that part of your documentation.
this.editor is the editor plugin reference
this.area_plugin the reference to the area plugin.
and a short example for the nodes list. There are basically the classes that derive from your ClassicPreset.Node.
Suggested Solution
Show in your tutorial how to export connections and positions of nodes.
Code of Conduct
The text was updated successfully, but these errors were encountered: