@@ -275,6 +275,7 @@ export default class Preview extends PreviewCollection {
275
275
this . dropPlaceholder . removeClass ( "left right" ) ;
276
276
277
277
this . movePlaceholder . removeClass ( "active" ) ;
278
+ this . movePosition = null ;
278
279
this . startDragEvent = null ;
279
280
280
281
events . trigger ( "column:dragStop" , {
@@ -328,7 +329,7 @@ export default class Preview extends PreviewCollection {
328
329
}
329
330
330
331
/**
331
- * Handle an existing column being dropped into a new column group
332
+ * Handle an existing column being dropped into a different column line
332
333
*
333
334
* @param {DropPosition } movePosition
334
335
*/
@@ -349,26 +350,49 @@ export default class Preview extends PreviewCollection {
349
350
350
351
// Set the column to it's smallest column width
351
352
updateColumnWidth ( column , this . resizeUtils . getSmallestColumnWidth ( ) ) ;
352
-
353
- // Move the content type
354
- moveContentType ( column , movePosition . insertIndex , this . contentType ) ;
355
-
356
353
// Modify the old neighbour
354
+ let oldNeighbourWidth = 100 ;
357
355
if ( modifyOldNeighbour ) {
358
- const oldNeighbourWidth = sourceLinePreview . getResizeUtils ( ) . getAcceptedColumnWidth (
356
+ oldNeighbourWidth = sourceLinePreview . getResizeUtils ( ) . getAcceptedColumnWidth (
359
357
( oldWidth + sourceLinePreview . getResizeUtils ( ) . getColumnWidth ( modifyOldNeighbour ) ) . toString ( ) ,
360
358
) ;
361
- updateColumnWidth ( modifyOldNeighbour , oldNeighbourWidth ) ;
359
+
362
360
}
363
361
364
- // Modify the columns new neighbour
365
- const newNeighbourWidth = this . resizeUtils . getAcceptedColumnWidth (
366
- ( this . resizeUtils . getColumnWidth ( movePosition . affectedColumn ) -
367
- this . resizeUtils . getSmallestColumnWidth ( ) ) . toString ( ) ,
368
- ) ;
362
+ // Move the content type
363
+ if ( this . columnLineDropPlaceholder . hasClass ( 'active' )
364
+ || this . columnLineBottomDropPlaceholder . hasClass ( 'active' ) ) {
365
+ // if new column line placeholders are visible, add new column line and move column there
366
+ createColumnLine (
367
+ this . contentType . parentContentType ,
368
+ this . resizeUtils . getSmallestColumnWidth ( ) ,
369
+ this . getNewColumnLineIndex ( ) ,
370
+ ) . then ( ( columnLine ) => {
371
+
372
+ moveContentType ( column , 0 , columnLine ) ;
373
+ updateColumnWidth ( column , 100 ) ;
374
+ if ( modifyOldNeighbour ) {
375
+ updateColumnWidth ( modifyOldNeighbour , oldNeighbourWidth ) ;
376
+ }
377
+ this . fireMountEvent ( this . contentType , column ) ;
378
+
379
+ } ) ;
380
+ } else {
381
+ //@todo evaluate if this else is needed
382
+ moveContentType ( column , movePosition . insertIndex , this . contentType ) ;
383
+ if ( modifyOldNeighbour ) {
384
+ updateColumnWidth ( modifyOldNeighbour , oldNeighbourWidth ) ;
385
+ }
386
+ const newNeighbourWidth = this . resizeUtils . getAcceptedColumnWidth (
387
+ ( this . resizeUtils . getColumnWidth ( movePosition . affectedColumn ) -
388
+ this . resizeUtils . getSmallestColumnWidth ( ) ) . toString ( ) ,
389
+ ) ;
390
+
391
+ // Reduce the affected columns width by the smallest column width
392
+ updateColumnWidth ( movePosition . affectedColumn , newNeighbourWidth ) ;
393
+
394
+ }
369
395
370
- // Reduce the affected columns width by the smallest column width
371
- updateColumnWidth ( movePosition . affectedColumn , newNeighbourWidth ) ;
372
396
}
373
397
374
398
/**
@@ -469,23 +493,16 @@ export default class Preview extends PreviewCollection {
469
493
470
494
let index = - 1 ;
471
495
const self = this ;
472
- if ( this . columnLineDropPlaceholder . hasClass ( "active" )
473
- || this . columnLineBottomDropPlaceholder . hasClass ( "active" ) ) {
496
+ const dragColumn = getDragColumn ( ) ;
497
+ if ( ( this . columnLineDropPlaceholder . hasClass ( "active" )
498
+ || this . columnLineBottomDropPlaceholder . hasClass ( "active" ) )
499
+ && ! dragColumn ) {
500
+
474
501
475
- for ( const child of this . contentType . parentContentType . children ( ) ) {
476
- index ++ ;
477
- if ( child . id == self . contentType . id ) {
478
- break ;
479
- }
480
- }
481
- if ( this . columnLineBottomDropPlaceholder . hasClass ( "active" ) ) {
482
- // show the bottom drop placeholder
483
- index ++ ;
484
- }
485
502
createColumnLine (
486
503
this . contentType . parentContentType ,
487
504
this . resizeUtils . getSmallestColumnWidth ( ) ,
488
- index ,
505
+ this . getNewColumnLineIndex ( ) ,
489
506
) . then ( ( columnLine ) => {
490
507
events . trigger (
491
508
columnLine . config . name + ":dropAfter" ,
@@ -509,9 +526,10 @@ export default class Preview extends PreviewCollection {
509
526
510
527
const column = getDragColumn ( ) ;
511
528
512
- if ( this . movePosition && column && column . parentContentType !== this . contentType ) {
529
+ if ( this . isColumnBeingMovedToAnotherColumnLine ( ) ) {
513
530
this . onExistingColumnDrop ( this . movePosition ) ;
514
531
}
532
+
515
533
}
516
534
517
535
/**
@@ -564,7 +582,9 @@ export default class Preview extends PreviewCollection {
564
582
this . movePosition = null ;
565
583
}
566
584
567
- if ( this . movePosition ) {
585
+ if ( this . movePosition &&
586
+ ( ! this . isNewLinePlaceDropPlaceholderVisible ( event , linePosition )
587
+ && ! this . isNewLineBottomPlaceDropPlaceholderVisible ( event , linePosition ) ) ) {
568
588
this . dropPlaceholder . removeClass ( "left right" ) ;
569
589
this . movePlaceholder . css ( {
570
590
left : ( this . movePosition . placement === "left" ? this . movePosition . left : "" ) ,
@@ -724,16 +744,11 @@ export default class Preview extends PreviewCollection {
724
744
725
745
const siblings = this . contentType . parentContentType . children ( ) ;
726
746
const id = this . contentType . id ;
727
- let index = 0 ;
728
- siblings . forEach ( ( columnLine ) => {
729
- if ( columnLine . id === id ) {
730
- return false ;
731
- }
732
- index ++ ;
733
- } ) ;
747
+ const firstLine = siblings . shift ( ) ;
734
748
// show column line drop placeholder only for top column line in a group
749
+ const draggedColumn = getDragColumn ( ) ;
735
750
736
- return index === 0 && this . dropOverElement &&
751
+ return ( this . dropOverElement || draggedColumn ) &&
737
752
event . pageY > linePosition . top &&
738
753
event . pageY < linePosition . top + this . lineDropperHeight ;
739
754
}
@@ -749,7 +764,8 @@ export default class Preview extends PreviewCollection {
749
764
linePosition : LinePositionCache ,
750
765
) : boolean {
751
766
752
- return this . dropOverElement &&
767
+ const draggedColumn = getDragColumn ( ) ;
768
+ return ( this . dropOverElement || draggedColumn ) &&
753
769
( event . pageY < linePosition . top + this . element . outerHeight ( ) &&
754
770
event . pageY > linePosition . top + this . element . outerHeight ( ) - this . lineDropperHeight ) ;
755
771
@@ -763,7 +779,8 @@ export default class Preview extends PreviewCollection {
763
779
*/
764
780
private isNewColumnDropPlaceholderVisible ( event : JQueryEventObject , linePosition : LinePositionCache ) : boolean {
765
781
766
- return this . dropOverElement &&
782
+ const draggedColumn = getDragColumn ( ) ;
783
+ return ( this . dropOverElement || draggedColumn ) &&
767
784
event . pageY > linePosition . top + this . lineDropperHeight &&
768
785
event . pageY < linePosition . top + linePosition . outerHeight - this . lineDropperHeight ;
769
786
}
@@ -945,7 +962,8 @@ export default class Preview extends PreviewCollection {
945
962
} ,
946
963
over ( ) {
947
964
// Is the element currently being dragged a column group?
948
- if ( getDraggedContentTypeConfig ( ) === Config . getContentTypeConfig ( "column-group" ) ) {
965
+ if ( getDraggedContentTypeConfig ( ) === Config . getContentTypeConfig ( "column-group" ) ||
966
+ getDraggedContentTypeConfig ( ) === Config . getContentTypeConfig ( "column" ) ) {
949
967
// Always calculate drop positions when an element is dragged over
950
968
const ownContentType = self . contentType as ContentTypeCollectionInterface < ColumnLinePreview > ;
951
969
self . dropPositions = calculateDropPositions ( ownContentType ) ;
@@ -1164,4 +1182,46 @@ export default class Preview extends PreviewCollection {
1164
1182
return ;
1165
1183
}
1166
1184
}
1185
+
1186
+ private getNewColumnLineIndex ( ) : number {
1187
+ let index = - 1 ;
1188
+ const self = this ;
1189
+ alert ( this . contentType . parentContentType . getChildren ( ) ( ) . length ) ;
1190
+ for ( const child of this . contentType . parentContentType . children ( ) ) {
1191
+ index ++ ;
1192
+ if ( child . id == self . contentType . id ) {
1193
+ break ;
1194
+ }
1195
+ }
1196
+ if ( this . columnLineBottomDropPlaceholder . hasClass ( "active" ) ) {
1197
+ // show the bottom drop placeholder
1198
+ index ++ ;
1199
+ }
1200
+ return index ;
1201
+ }
1202
+
1203
+
1204
+ private isColumnBeingMovedToAnotherColumnLine ( ) : boolean {
1205
+ let column = getDragColumn ( ) ;
1206
+ if ( ! column ) {
1207
+ //if no move position, column is not being moved.
1208
+ return false ;
1209
+ }
1210
+
1211
+ if ( column . parentContentType !== this . contentType ) {
1212
+ //if the parent content type is not same as this column line, column is being moved to new column line
1213
+ return true ;
1214
+ }
1215
+
1216
+ if ( column . parentContentType === this . contentType
1217
+ && ( this . columnLineDropPlaceholder . hasClass ( 'active' )
1218
+ || this . columnLineBottomDropPlaceholder . hasClass ( 'active' ) ) ) {
1219
+ //since new column line drop placeholder is visible, column move will introduce a new column line
1220
+ return true ;
1221
+ }
1222
+
1223
+ return false ;
1224
+ }
1225
+
1226
+
1167
1227
}
0 commit comments