import{IdentityAssigner as e}from"../node-structure";import{input as t}from"../components/flow-editor";import{FlowNode as o,ConnectionLine as i}from"../flow-viewer";export class CopyPasteManager{get isFull(){return!this.clipboard}putInClipboard(e,t){this.copyOrigin=t,this.clipboard=e}getFromClipboard(e){let t=this.cloneIsolated(this.clipboard,0),o={x:e.x-this.copyOrigin.x,y:e.y-this.copyOrigin.y};return t.nodes.forEach(e=>{e.position.x+=o.x,e.position.y+=o.y}),t}cloneIsolated(t,o=50){let i={},n=JSON.parse(JSON.stringify(t));return n.nodes.forEach(t=>{let n=e.generateIdentity();i[t.id]=n,t.position.x+=o,t.position.y+=o,t.id=n,t.inputs.forEach(t=>{let o=e.generateIdentity();i[t.id]=o,t.id=o,t.nodeId=n}),t.outputs.forEach(t=>{let o=e.generateIdentity();i[t.id]=o,t.id=o,t.nodeId=n})}),n.connections.forEach(e=>{e.from=i[e.from],e.to=i[e.to]}),n}copy(e,n){let r=t.selected.filter(e=>e instanceof o&&e.selected),s=t.selected.filter(e=>e instanceof i&&e.selected);this.putInClipboard({nodes:r.map(e=>e.node),connections:s.map(e=>e.connection)},{x:e,y:n})}}