Skip to content

Commit 4846716

Browse files
committed
MC-4262: Column Rearranging Drop Zone Indicators Are Too Small & Sometimes Hard To Activate
- Refactor move logic to better present action when moving within current group
1 parent 25e581b commit 4846716

File tree

3 files changed

+58
-70
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

3 files changed

+58
-70
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/column-group/_default.less

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
// Default appearance styles
88
// _____________________________________________
99

10+
@keyframes inner-pulsate {
11+
0% {
12+
box-shadow: inset 0 0 0 1px rgba(142, 0, 6, 0);
13+
}
14+
50% {
15+
box-shadow: inset 0 0 0 8px rgba(142, 0, 6, .1);
16+
}
17+
100% {
18+
box-shadow: inset 0 0 0 2px rgba(142, 0, 6, 0);
19+
}
20+
}
21+
1022
.pagebuilder-content-type {
1123
.pagebuilder-column-group {
1224
border: none;
@@ -39,21 +51,23 @@
3951
}
4052

4153
.move-placeholder {
54+
animation: inner-pulsate 1s infinite ease-in-out;
4255
background: rgba(142, 0, 6, .3);
43-
bottom: -1px;
56+
bottom: 0;
4457
opacity: 0;
4558
position: absolute;
46-
top: -1px;
59+
top: 0;
60+
transition: .25s opacity;
4761
visibility: hidden;
4862
width: 6px;
49-
z-index: 26;
63+
z-index: 10;
5064

5165
.no-user-select;
5266
.no-pointer-events;
5367

5468
&.active {
5569
opacity: 1;
56-
transition: .5s opacity;
70+
transition: .25s opacity;
5771
visibility: visible;
5872
}
5973
}

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

Lines changed: 18 additions & 33 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/ts/js/content-type/column-group/preview.ts

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export default class Preview extends PreviewCollection {
8080
private resizeUtils: Resize;
8181
private gridSizeHistory: Map<number, number[]> = new Map();
8282
private interactionLevel: number = 0;
83+
private startDragEvent: JQueryEventObject;
8384

8485
/**
8586
*
@@ -345,11 +346,12 @@ export default class Preview extends PreviewCollection {
345346
});
346347
return helper;
347348
},
348-
start: (event: Event) => {
349+
start: (event: JQueryEventObject) => {
349350
const columnInstance: ContentTypeCollectionInterface = ko.dataFor($(event.target)[0]);
350351
// Use the global state as columns can be dragged between groups
351352
setDragColumn((columnInstance.parent as ContentTypeCollectionInterface<ColumnPreview>));
352353
this.dropPositions = calculateDropPositions(this.parent);
354+
this.startDragEvent = event;
353355

354356
events.trigger("column:dragStart", {
355357
column: columnInstance,
@@ -372,6 +374,7 @@ export default class Preview extends PreviewCollection {
372374

373375
this.dropPlaceholder.removeClass("left right");
374376
this.movePlaceholder.removeClass("active");
377+
this.startDragEvent = null;
375378

376379
events.trigger("column:dragStop", {
377380
column: draggedColumn,
@@ -783,44 +786,30 @@ export default class Preview extends PreviewCollection {
783786
const currentX = event.pageX - groupPosition.left;
784787

785788
// Are we within the same column group or have we ended up over another?
786-
if (columnInstance.parent === this.parent) {
787-
const currentColumn = dragColumn.preview.element;
788-
const currentColumnRight = currentColumn.position().left + currentColumn.width();
789-
const lastColInGroup = (this.parent.children()[this.parent.children().length - 1]
790-
.preview as ColumnPreview).element;
791-
const insertLastPos = lastColInGroup.position().left + (lastColInGroup.width() / 2);
789+
if (columnInstance.parent === this.parent && this.startDragEvent) {
790+
const dragDirection = (event.pageX <= this.startDragEvent.pageX ? "left" : "right");
791+
const adjacentLeftColumn = getAdjacentColumn(dragColumn, "-1");
792792

793+
// Determine the current move position based on the cursors position and direction of drag
793794
this.movePosition = this.dropPositions.find((position) => {
794-
// Only ever look for the left placement, except the last item where we look on the right
795-
const placement = (currentX >= insertLastPos ? "right" : "left");
796-
// There is 200px area over each column borders
797-
return comparator(currentX, position[placement], 100) &&
798-
!comparator(currentX, currentColumnRight, 100) &&
799-
position.affectedColumn !== columnInstance && // Check affected column isn't the current column
800-
position.placement === placement; // Verify the position, we only check left on sorting
795+
return currentX > position.left && currentX < position.right &&
796+
position.placement === dragDirection && position.affectedColumn !== dragColumn;
801797
});
802798

799+
// Differences in the element & event positions cause a right movement to activate on the left column
800+
if (this.movePosition && dragDirection === "right" &&
801+
this.movePosition.affectedColumn === adjacentLeftColumn
802+
) {
803+
this.movePosition = null;
804+
}
805+
803806
if (this.movePosition) {
804807
this.dropPlaceholder.removeClass("left right");
805-
const width = dragColumn.preview.element.outerWidth();
806-
let left = (this.movePosition.placement === "left" ? this.movePosition.left : null);
807-
// The right position is only used when moving a column to the last position in the group
808-
const right = (this.movePosition.placement === "right" ?
809-
groupPosition.outerWidth - this.movePosition.right : null
810-
);
811-
/**
812-
* If we're dragging the column from the left to the right we need to show the placeholder on
813-
* the left hand side.
814-
*/
815-
if (left !== null && this.parent.children().indexOf(dragColumn) <
816-
this.parent.children().indexOf(this.movePosition.affectedColumn)
817-
) {
818-
left = left - width;
819-
}
820-
this.movePlaceholder.css({
821-
width,
822-
left,
823-
right,
808+
this.movePlaceholder.removeClass("left right").css({
809+
left: (this.movePosition.placement === "left" ? this.movePosition.left : ""),
810+
right: (this.movePosition.placement === "right"
811+
? groupPosition.width - this.movePosition.right : ""),
812+
width: dragColumn.preview.element.outerWidth() + "px",
824813
}).addClass("active");
825814
} else {
826815
this.movePlaceholder.removeClass("active");

0 commit comments

Comments
 (0)