MCPcopy
hub / github.com/1Panel-dev/MaxKB / paste_node

Function paste_node

ui/src/workflow/common/shortcut.ts:205–250  ·  view source on GitHub ↗
(e: ClipboardEvent)

Source from the content-addressed store, hash-verified

203 }
204
205 const paste_node = async (e: ClipboardEvent) => {
206 if (lf.graphModel.flowId !== activeCanvasId) {
207 return true
208 }
209 if (!keyboardOptions?.enabled) return true
210 if (graph.textEditElement) return true
211 const text = e.clipboardData?.getData('text/plain') || ''
212 const data = parseAndValidate(text)
213 selected = resetData(data)
214 const workflowMode = lf.graphModel.get_provide(null, null).workflowMode
215 const menus = getMenuNodes(workflowMode)
216 const nodes = menus?.flatMap((m: any) => m.list).map((n) => n.type)
217
218 if (selected && (selected.nodes || selected.edges)) {
219 if (!lastMouse.hasValue) {
220 moveData(data, 40, 40)
221 } else {
222 // LogicFlow 文档里 getPointByClient 会把页面坐标转成画布坐标
223 const point = lf.graphModel.getPointByClient({
224 x: lastMouse.x,
225 y: lastMouse.y,
226 })
227 const mouseCanvasX = point.canvasOverlayPosition.x
228 const mouseCanvasY = point.canvasOverlayPosition.y
229
230 const { minX, maxX, minY, maxY } = getBounds(selected.nodes)
231 const centerX = (minX + maxX) / 2
232 const centerY = (minY + maxY) / 2
233 moveData(data, mouseCanvasX - centerX, mouseCanvasY - centerY)
234 }
235
236 selected.nodes = selected.nodes.filter(
237 (n: any) => nodes?.includes(n.type) || workflowModelDict[workflowMode](n),
238 )
239 lf.clearSelectElements()
240 const addElements = lf.addElements(selected, CHILDREN_TRANSLATION_DISTANCE)
241 if (!addElements) return true
242 addElements.nodes.forEach((node) => lf.selectElementById(node.id, true))
243 addElements.edges.forEach((edge) => lf.selectElementById(edge.id, true))
244 selected.nodes.forEach((node: any) => translationNodeData(node, TRANSLATION_DISTANCE))
245 selected.edges.forEach((edge: any) => translationEdgeData(edge, TRANSLATION_DISTANCE))
246 CHILDREN_TRANSLATION_DISTANCE = CHILDREN_TRANSLATION_DISTANCE + TRANSLATION_DISTANCE
247 }
248 selected = undefined
249 return false
250 }
251
252 const parseAndValidate = (text: string) => {
253 let data: any

Callers

nothing calls this directly

Calls 8

getMenuNodesFunction · 0.90
parseAndValidateFunction · 0.85
resetDataFunction · 0.85
moveDataFunction · 0.85
getBoundsFunction · 0.85
translationNodeDataFunction · 0.85
translationEdgeDataFunction · 0.85
getDataMethod · 0.45

Tested by

no test coverage detected