Skip to content

Commit a6f0f2e

Browse files
committed
PB-108 add the ability to add column line to the bottom of a column group
1 parent 2068cdc commit a6f0f2e

File tree

3 files changed

+120
-13
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

3 files changed

+120
-13
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/column-line/preview.js

Lines changed: 57 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/column-line/default/preview.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
afterRender="function (element) { bindInteractions.call($data, element); }">
1717
<render args="{name: preview.template, data: preview}" />
1818
</div>
19+
<div class="bottom-drop-placeholder" afterRender="function (element) { bindColumnLineBottomDropPlaceholder.call($data, element); }" style="background: rgba(142, 0, 6, 0.3); height:30px; display:none; z-index:26;" ></div>
1920
</div>

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/column-line/preview.ts

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default class Preview extends PreviewCollection {
8080
private resizeGhost: JQuery;
8181
private resizeLeftLastColumnShrunk: ContentTypeCollectionInterface<ColumnPreview>;
8282
private resizeRightLastColumnShrunk: ContentTypeCollectionInterface<ColumnPreview>;
83+
private columnLineBottomDropPlaceholder: JQuery;
8384

8485

8586

@@ -173,6 +174,15 @@ export default class Preview extends PreviewCollection {
173174
this.dropPlaceholder = $(element);
174175
}
175176

177+
/**
178+
* Init the drop placeholder
179+
*
180+
* @param {Element} element
181+
*/
182+
public bindColumnLineBottomDropPlaceholder(element: Element) {
183+
this.columnLineBottomDropPlaceholder = $(element);
184+
}
185+
176186
/**
177187
* Init the drop placeholder
178188
*
@@ -375,6 +385,8 @@ export default class Preview extends PreviewCollection {
375385
this.dropPosition = null;
376386
this.dropPlaceholder.removeClass("left right");
377387
this.columnLineDropPlaceholder.removeClass("active");
388+
this.columnLineBottomDropPlaceholder.removeClass("active");
389+
this.columnLineBottomDropPlaceholder.hide();
378390
this.columnLineDropPlaceholder.hide();
379391
//@todo combine active and show/hide functionality for columnLineDropPlaceholder
380392
// this.movePlaceholder.css("left", "").removeClass("active");
@@ -413,6 +425,8 @@ export default class Preview extends PreviewCollection {
413425
this.dropPosition = null;
414426
this.dropPlaceholder.removeClass("left right");
415427
this.columnLineDropPlaceholder.removeClass("active");
428+
this.columnLineBottomDropPlaceholder.removeClass("active");
429+
this.columnLineBottomDropPlaceholder.hide();
416430
this.columnLineDropPlaceholder.hide();
417431
this.resizing(false);
418432
this.resizeMouseDown = null;
@@ -438,14 +452,18 @@ export default class Preview extends PreviewCollection {
438452

439453
let index = -1;
440454
let self = this;
441-
if (this.columnLineDropPlaceholder.hasClass('active')) {
455+
if (this.columnLineDropPlaceholder.hasClass('active') || this.columnLineBottomDropPlaceholder.hasClass("active")) {
442456

443457
for (var child of this.contentType.parentContentType.children()) {
444458
index++;
445459
if (child.id == self.contentType.id) {
446460
break;
447461
}
448462
}
463+
if (this.columnLineBottomDropPlaceholder.hasClass("active")) {
464+
//show the bottom drop placeholder
465+
index++;
466+
}
449467
createColumnLine(
450468
this.contentType.parentContentType,
451469
this.resizeUtils.getSmallestColumnWidth(),
@@ -680,11 +698,37 @@ export default class Preview extends PreviewCollection {
680698
*/
681699
private isNewLinePlaceDropPlaceholderVisible(event: JQueryEventObject, linePosition: LinePositionCache): boolean {
682700

683-
return this.dropOverElement &&
701+
const siblings = this.contentType.parentContentType.children();
702+
const id = this.contentType.id;
703+
let index = 0;
704+
siblings.forEach(columnLine => {
705+
if (columnLine.id == id){
706+
return false;
707+
}
708+
index++;
709+
});
710+
//show column line drop placeholder only for top column line in a group
711+
712+
return index === 0 && this.dropOverElement &&
684713
event.pageY > linePosition.top &&
685714
event.pageY < linePosition.top + this.lineDropperHeight
686715
}
687716

717+
718+
/**
719+
*
720+
* @param event
721+
* @param linePosition
722+
* @private
723+
*/
724+
private isNewLineBottomPlaceDropPlaceholderVisible(event: JQueryEventObject, linePosition: LinePositionCache): boolean {
725+
726+
return this.dropOverElement &&
727+
(event.pageY < linePosition.top + this.element.outerHeight() &&
728+
event.pageY > linePosition.top + this.element.outerHeight() - this.lineDropperHeight )
729+
730+
}
731+
688732
/**
689733
*
690734
* @param event
@@ -693,9 +737,9 @@ export default class Preview extends PreviewCollection {
693737
*/
694738
private isNewColumnDropPlaceholderVisible(event: JQueryEventObject, linePosition: LinePositionCache): boolean {
695739

696-
return this.dropOverElement &&
697-
event.pageY > linePosition.top + 50 &&
698-
event.pageY < linePosition.top + linePosition.outerHeight
740+
return this.dropOverElement &&
741+
event.pageY > linePosition.top + this.lineDropperHeight &&
742+
event.pageY < linePosition.top + linePosition.outerHeight - this.lineDropperHeight;
699743
}
700744
/**
701745
* Handle mouse move events on when dropping elements
@@ -711,15 +755,27 @@ export default class Preview extends PreviewCollection {
711755
this.dropPosition = null;
712756
this.dropPlaceholder.removeClass("left right");
713757
this.columnLineDropPlaceholder.addClass("active");
758+
this.columnLineDropPlaceholder.show();
714759
return this.handleLineDropMouseMove(event, line, linePosition);
715-
} else if(this.dropOverElement) {
760+
} else if (this.isNewLineBottomPlaceDropPlaceholderVisible(event, linePosition)) {
761+
this.dropPosition = null;
762+
this.dropPlaceholder.removeClass("left right");
763+
this.columnLineBottomDropPlaceholder.addClass("active");
764+
this.columnLineBottomDropPlaceholder.show();
765+
return this.handleLineDropMouseMove(event, line, linePosition);
766+
}
767+
else if(this.dropOverElement) {
716768
this.columnLineDropPlaceholder.hide();
769+
this.columnLineBottomDropPlaceholder.hide();
770+
this.columnLineBottomDropPlaceholder.removeClass("active");
717771
this.columnLineDropPlaceholder.removeClass("active");
718772

719773
}
720774
if (this.isNewColumnDropPlaceholderVisible(event, linePosition)) {
721775
this.columnLineDropPlaceholder.hide();
722776
this.columnLineDropPlaceholder.removeClass("active");
777+
this.columnLineBottomDropPlaceholder.hide();
778+
this.columnLineBottomDropPlaceholder.removeClass("active");
723779
return this.handleColumnDropMouseMove(event, line, linePosition);
724780
}
725781
}
@@ -739,8 +795,6 @@ export default class Preview extends PreviewCollection {
739795
if (elementChildrenParent.data("ui-sortable")) {
740796
elementChildrenParent.sortable("option", "disabled", true);
741797
}
742-
743-
this.columnLineDropPlaceholder.show();
744798
}
745799

746800
/**

0 commit comments

Comments
 (0)