MCPcopy Create free account
hub / github.com/FlowiseAI/Flowise / duplicateNode

Function duplicateNode

packages/ui/src/store/context/ReactFlowContext.jsx:178–245  ·  view source on GitHub ↗
(id, distance = 50)

Source from the content-addressed store, hash-verified

176 }
177
178 const duplicateNode = (id, distance = 50) => {
179 const nodes = reactFlowInstance.getNodes()
180 const originalNode = nodes.find((n) => n.id === id)
181 if (originalNode) {
182 const newNodeId = getUniqueNodeId(originalNode.data, nodes)
183 const clonedNode = cloneDeep(originalNode)
184
185 const duplicatedNode = {
186 ...clonedNode,
187 id: newNodeId,
188 position: {
189 x: clonedNode.position.x + clonedNode.width + distance,
190 y: clonedNode.position.y
191 },
192 positionAbsolute: {
193 x: clonedNode.positionAbsolute.x + clonedNode.width + distance,
194 y: clonedNode.positionAbsolute.y
195 },
196 data: {
197 ...clonedNode.data,
198 id: newNodeId,
199 label: clonedNode.data.label + ` (${newNodeId.split('_').pop()})`
200 },
201 selected: false
202 }
203
204 const inputKeys = ['inputParams', 'inputAnchors']
205 for (const key of inputKeys) {
206 for (const item of duplicatedNode.data[key]) {
207 if (item.id) {
208 item.id = item.id.replace(id, newNodeId)
209 }
210 }
211 }
212
213 const outputKeys = ['outputAnchors']
214 for (const key of outputKeys) {
215 for (const item of duplicatedNode.data[key]) {
216 if (item.id) {
217 item.id = item.id.replace(id, newNodeId)
218 }
219 if (item.options) {
220 for (const output of item.options) {
221 output.id = output.id.replace(id, newNodeId)
222 }
223 }
224 }
225 }
226
227 // Clear connected inputs
228 for (const inputName in duplicatedNode.data.inputs) {
229 if (
230 typeof duplicatedNode.data.inputs[inputName] === 'string' &&
231 duplicatedNode.data.inputs[inputName].startsWith('{{') &&
232 duplicatedNode.data.inputs[inputName].endsWith('}}')
233 ) {
234 duplicatedNode.data.inputs[inputName] = ''
235 } else if (Array.isArray(duplicatedNode.data.inputs[inputName])) {

Callers 6

CanvasNodeFunction · 0.85
StickyNoteFunction · 0.85
IterationNodeFunction · 0.85
AgentFlowNodeFunction · 0.85
StickyNoteFunction · 0.85

Calls 1

getUniqueNodeIdFunction · 0.90

Tested by

no test coverage detected