127
127
import Vue from ' vue'
128
128
import Prompts from ' ../mixins/Prompts'
129
129
import Movable from ' ../mixins/Movable'
130
+ import Resizable from ' ../mixins/Resizable'
130
131
131
132
import WIDGET_REMOVE from ' ../graphql/widgetRemove.gql'
132
133
import WIDGET_MOVE from ' ../graphql/widgetMove.gql'
@@ -169,6 +170,11 @@ export default {
169
170
Movable ({
170
171
field: ' widget' ,
171
172
gridSize: GRID_SIZE
173
+ }),
174
+
175
+ Resizable ({
176
+ field: ' widget' ,
177
+ gridSize: GRID_SIZE
172
178
})
173
179
],
174
180
@@ -186,7 +192,6 @@ export default {
186
192
187
193
data () {
188
194
return {
189
- resizeState: null ,
190
195
showConfig: false ,
191
196
injected: {
192
197
data: this .widget ,
@@ -250,23 +255,6 @@ export default {
250
255
}
251
256
},
252
257
253
- created () {
254
- this .resizeHandles = [
255
- ' top-left' ,
256
- ' top' ,
257
- ' top-right' ,
258
- ' right' ,
259
- ' bottom-right' ,
260
- ' bottom' ,
261
- ' bottom-left' ,
262
- ' left'
263
- ]
264
- },
265
-
266
- beforeDestroy () {
267
- this .removeResizeListeners ()
268
- },
269
-
270
258
methods: {
271
259
getPositionStyle (x , y ) {
272
260
return {
@@ -325,6 +313,10 @@ export default {
325
313
})
326
314
},
327
315
316
+ select () {
317
+ state .selectedWidget = this .widget
318
+ },
319
+
328
320
async onMoved () {
329
321
await this .$apollo .mutate ({
330
322
mutation: WIDGET_MOVE ,
@@ -340,78 +332,7 @@ export default {
340
332
})
341
333
},
342
334
343
- // Resizing
344
-
345
- select () {
346
- state .selectedWidget = this .widget
347
- },
348
-
349
- removeResizeListeners () {
350
- window .removeEventListener (' mousemove' , this .onResizeMove )
351
- window .removeEventListener (' mouseup' , this .onResizeEnd )
352
- },
353
-
354
- updateResizeState (e ) {
355
- const mouseDeltaX = (e .clientX - this .$_initalMousePosition .x ) / 0.7
356
- const mouseDeltaY = (e .clientY - this .$_initalMousePosition .y ) / 0.7
357
- const handle = this .$_resizeHandle
358
- let dX = 0
359
- let dY = 0
360
- let dWidth = 0
361
- let dHeight = 0
362
- // TODO
363
- if (handle .includes (' right' )) {
364
- dWidth = mouseDeltaX
365
- }
366
- if (handle .includes (' bottom' )) {
367
- dHeight = mouseDeltaY
368
- }
369
- let gridDX = Math .round (dX / GRID_SIZE )
370
- let gridDY = Math .round (dY / GRID_SIZE )
371
- let gridDWidth = Math .round (dWidth / GRID_SIZE )
372
- let gridDHeight = Math .round (dHeight / GRID_SIZE )
373
- if (this .widget .width + gridDWidth < this .widget .definition .minWidth ) {
374
- gridDWidth = this .widget .definition .minWidth - this .widget .width
375
- }
376
- if (this .widget .width + gridDWidth > this .widget .definition .maxWidth ) {
377
- gridDWidth = this .widget .definition .maxWidth - this .widget .width
378
- }
379
- if (this .widget .height + gridDHeight < this .widget .definition .minHeight ) {
380
- gridDHeight = this .widget .definition .minHeight - this .widget .height
381
- }
382
- if (this .widget .height + gridDHeight > this .widget .definition .maxHeight ) {
383
- gridDHeight = this .widget .definition .maxHeight - this .widget .height
384
- }
385
- this .resizeState = {
386
- x: this .widget .x + gridDX,
387
- y: this .widget .y + gridDY,
388
- width: this .widget .width + gridDWidth,
389
- height: this .widget .height + gridDHeight,
390
- pxX: this .widget .x * GRID_SIZE + dX,
391
- pxY: this .widget .y * GRID_SIZE + dY,
392
- pxWidth: this .widget .width * GRID_SIZE + dWidth,
393
- pxHeight: this .widget .height * GRID_SIZE + dHeight
394
- }
395
- },
396
-
397
- onResizeStart (e , handle ) {
398
- this .$_initalMousePosition = {
399
- x: e .clientX ,
400
- y: e .clientY
401
- }
402
- this .$_resizeHandle = handle
403
- this .updateResizeState (e)
404
- window .addEventListener (' mousemove' , this .onResizeMove )
405
- window .addEventListener (' mouseup' , this .onResizeEnd )
406
- },
407
-
408
- onResizeMove (e ) {
409
- this .updateResizeState (e)
410
- },
411
-
412
- async onResizeEnd (e ) {
413
- this .updateResizeState (e)
414
- this .removeResizeListeners ()
335
+ async onResized () {
415
336
await this .$apollo .mutate ({
416
337
mutation: WIDGET_MOVE ,
417
338
variables: {
@@ -424,7 +345,6 @@ export default {
424
345
}
425
346
}
426
347
})
427
- this .resizeState = null
428
348
}
429
349
}
430
350
}
0 commit comments