126
126
<script >
127
127
import Vue from ' vue'
128
128
import Prompts from ' ../mixins/Prompts'
129
+ import Movable from ' ../mixins/Movable'
129
130
130
131
import WIDGET_REMOVE from ' ../graphql/widgetRemove.gql'
131
132
import WIDGET_MOVE from ' ../graphql/widgetMove.gql'
@@ -163,6 +164,11 @@ export default {
163
164
}
164
165
})
165
166
}
167
+ }),
168
+
169
+ Movable ({
170
+ field: ' widget' ,
171
+ gridSize: GRID_SIZE
166
172
})
167
173
],
168
174
@@ -180,7 +186,6 @@ export default {
180
186
181
187
data () {
182
188
return {
183
- moveState: null ,
184
189
resizeState: null ,
185
190
showConfig: false ,
186
191
injected: {
@@ -196,7 +201,7 @@ export default {
196
201
style () {
197
202
if (this .moveState ) {
198
203
return {
199
- ... this .getPositionStyle (this .moveState .x , this .moveState .y ),
204
+ ... this .getPositionStyle (this .moveState .pxX , this .moveState .pxY ),
200
205
... this .getSizeStyle ()
201
206
}
202
207
}
@@ -214,7 +219,7 @@ export default {
214
219
215
220
moveGhostStyle () {
216
221
return {
217
- ... this .getPositionStyle (GRID_SIZE * this .moveState .gridX , GRID_SIZE * this .moveState .gridY ),
222
+ ... this .getPositionStyle (GRID_SIZE * this .moveState .x , GRID_SIZE * this .moveState .y ),
218
223
... this .getSizeStyle ()
219
224
}
220
225
},
@@ -259,7 +264,6 @@ export default {
259
264
},
260
265
261
266
beforeDestroy () {
262
- this .removeMoveListeners ()
263
267
this .removeResizeListeners ()
264
268
},
265
269
@@ -299,7 +303,7 @@ export default {
299
303
},
300
304
301
305
openDetails () {
302
- // TODOnv
306
+ // TODO
303
307
},
304
308
305
309
remove () {
@@ -321,64 +325,19 @@ export default {
321
325
})
322
326
},
323
327
324
- // Moving
325
-
326
- removeMoveListeners () {
327
- window .removeEventListener (' mousemove' , this .onMoveUpdate )
328
- window .removeEventListener (' mouseup' , this .onMoveEnd )
329
- },
330
-
331
- updateMoveState (e ) {
332
- const mouseDeltaX = e .clientX - this .$_initalMousePosition .x
333
- const mouseDeltaY = e .clientY - this .$_initalMousePosition .y
334
- const x = this .$_initialPosition .x + mouseDeltaX / 0.7
335
- const y = this .$_initialPosition .y + mouseDeltaY / 0.7
336
- let gridX = Math .round (x / GRID_SIZE )
337
- let gridY = Math .round (y / GRID_SIZE )
338
- if (gridX < 0 ) gridX = 0
339
- if (gridY < 0 ) gridY = 0
340
- this .moveState = {
341
- x,
342
- y,
343
- gridX,
344
- gridY
345
- }
346
- },
347
-
348
- onMoveStart (e ) {
349
- this .$_initalMousePosition = {
350
- x: e .clientX ,
351
- y: e .clientY
352
- }
353
- this .$_initialPosition = {
354
- x: this .widget .x * GRID_SIZE ,
355
- y: this .widget .y * GRID_SIZE
356
- }
357
- this .updateMoveState (e)
358
- window .addEventListener (' mousemove' , this .onMoveUpdate )
359
- window .addEventListener (' mouseup' , this .onMoveEnd )
360
- },
361
-
362
- onMoveUpdate (e ) {
363
- this .updateMoveState (e)
364
- },
365
-
366
- async onMoveEnd (e ) {
367
- this .updateMoveState (e)
368
- this .removeMoveListeners ()
328
+ async onMoved () {
369
329
await this .$apollo .mutate ({
370
330
mutation: WIDGET_MOVE ,
371
331
variables: {
372
332
input: {
373
333
id: this .widget .id ,
374
- x: this .moveState .gridX ,
375
- y: this .moveState .gridY ,
334
+ x: this .moveState .x ,
335
+ y: this .moveState .y ,
376
336
width: this .widget .width ,
377
337
height: this .widget .height
378
338
}
379
339
}
380
340
})
381
- this .moveState = null
382
341
},
383
342
384
343
// Resizing
@@ -466,7 +425,6 @@ export default {
466
425
}
467
426
})
468
427
this .resizeState = null
469
- console .log (' resize end' )
470
428
}
471
429
}
472
430
}
0 commit comments