AI-native design editor. Open-source Figma alternative.
import type { Editor, MovePlace } from '@open-pencil/core'
import type { DragState } from '#vue/shared/input/types'
export function duplicateAndDrag(
cx: number,
cy: number,
sx: number,
sy: number,
editor: Editor
): { originals: Map<string, MovePlace>; drag: DragState } {
const previousSelection = new Set(editor.state.selectedIds)
const newIds: string[] = []
const newOriginals = new Map<string, MovePlace>()
for (const id of previousSelection) {
const source = editor.graph.getNode(id)
if (!source) continue
const parentId = source.parentId ?? editor.state.currentPageId
const clone = editor.duplicateNode(source, parentId, { x: source.x, y: source.y })
if (!clone) continue
newIds.push(clone.id)
newOriginals.set(clone.id, {
x: source.x,
y: source.y,
parentId
})
}
editor.select(newIds)
editor.requestRender()
return {
originals: newOriginals,
drag: {
type: 'move',
startX: cx,
startY: cy,
currentX: cx,
currentY: cy,
appliedDx: 0,
appliedDy: 0,
startScreenX: sx,
startScreenY: sy,
dragStarted: true,
originals: newOriginals,
duplicated: true,
duplicatedPreviousSelection: previousSelection
}
}
}