Skip to content

Commit d21a80b

Browse files
committed
fix: drag elements
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent fc3824c commit d21a80b

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

src/components/DraggableElement.vue

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,18 @@ export default {
153153
},
154154
elementStyle() {
155155
const scale = this.pagesScale || 1
156-
const currentX = this.object.x + this.offsetX + this.resizeOffsetX
157-
const currentY = this.object.y + this.offsetY + this.resizeOffsetY
158-
const currentWidth = this.object.width + this.resizeOffsetW
159-
const currentHeight = this.object.height + this.resizeOffsetH
156+
const isDragging = this.mode === 'drag'
157+
const isResizing = this.mode === 'resize'
158+
const offsetX = isDragging ? this.offsetX : 0
159+
const offsetY = isDragging ? this.offsetY : 0
160+
const resizeOffsetX = isResizing ? this.resizeOffsetX : 0
161+
const resizeOffsetY = isResizing ? this.resizeOffsetY : 0
162+
const resizeOffsetW = isResizing ? this.resizeOffsetW : 0
163+
const resizeOffsetH = isResizing ? this.resizeOffsetH : 0
164+
const currentX = this.object.x + offsetX + resizeOffsetX
165+
const currentY = this.object.y + offsetY + resizeOffsetY
166+
const currentWidth = this.object.width + resizeOffsetW
167+
const currentHeight = this.object.height + resizeOffsetH
160168
return {
161169
left: `${currentX * scale}px`,
162170
top: `${currentY * scale}px`,
@@ -166,9 +174,16 @@ export default {
166174
},
167175
toolbarStyle() {
168176
const scale = this.pagesScale || 1
169-
const x = this.object.x + this.offsetX + this.resizeOffsetX
170-
const y = this.object.y + this.offsetY + this.resizeOffsetY
171-
const width = this.object.width + this.resizeOffsetW
177+
const isDragging = this.mode === 'drag'
178+
const isResizing = this.mode === 'resize'
179+
const offsetX = isDragging ? this.offsetX : 0
180+
const offsetY = isDragging ? this.offsetY : 0
181+
const resizeOffsetX = isResizing ? this.resizeOffsetX : 0
182+
const resizeOffsetY = isResizing ? this.resizeOffsetY : 0
183+
const resizeOffsetW = isResizing ? this.resizeOffsetW : 0
184+
const x = this.object.x + offsetX + resizeOffsetX
185+
const y = this.object.y + offsetY + resizeOffsetY
186+
const width = this.object.width + resizeOffsetW
172187
return {
173188
left: `${(x + width / 2) * scale}px`,
174189
top: `${(y - 60) * scale}px`,

0 commit comments

Comments
 (0)