Skip to content

Commit f159adb

Browse files
committed
MC-3775: Button editable state is not consistent with the options panel appearing
- Remove weird animation from sortable actions - Align sortable settings with tabs & sliders for buttons - Ensure focus on duplicate works as expected
1 parent a4f564d commit f159adb

File tree

9 files changed

+60
-127
lines changed

9 files changed

+60
-127
lines changed

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

Lines changed: 7 additions & 60 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/js/content-type/preview-collection.js

Lines changed: 10 additions & 4 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/js/content-type/preview.js

Lines changed: 14 additions & 7 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/buttons/inline/preview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<div class="pagebuilder-content-type pagebuilder-entity pagebuilder-entity-preview pagebuilder-no-blur pagebuilder-live-edit pagebuilder-buttons" event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false">
99
<render args="getOptions().template" />
10-
<div class="element-children buttons-container" each="parent.getChildren()" attr="Object.assign({}, data.main.attributes(), { id: parent.id + '-children' })" ko-style="data.main.style" css="data.main.css" data-bind="sortableChildren: buttonsSortableOptions()">
10+
<div class="element-children buttons-container" each="parent.getChildren()" attr="Object.assign({}, data.main.attributes(), { id: parent.id + '-children' })" ko-style="data.main.style" css="data.main.css" data-bind="sortableChildren: getSortableOptions()">
1111
<div class="pagebuilder-content-type-wrapper" template="{ name: preview.previewTemplate, data: preview, afterRender: function () { preview.dispatchAfterRenderEvent.apply(preview, arguments); } }" attr="{ id: id }" css="{'pagebuilder-content-type-hidden': !preview.display()}"></div>
1212
</div>
1313
</div>

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/buttons/stacked/preview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<div class="pagebuilder-content-type pagebuilder-entity pagebuilder-entity-preview pagebuilder-no-blur pagebuilder-live-edit pagebuilder-buttons" event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false">
99
<render args="getOptions().template" />
10-
<div class="element-children buttons-container" each="parent.getChildren()" attr="Object.assign({}, data.main.attributes(), { id: parent.id + '-children' })" ko-style="data.main.style" css="data.main.css" data-bind="sortableChildren: buttonsSortableOptions('height', 'pointer')">
10+
<div class="element-children buttons-container" each="parent.getChildren()" attr="Object.assign({}, data.main.attributes(), { id: parent.id + '-children' })" ko-style="data.main.style" css="data.main.css" data-bind="sortableChildren: getSortableOptions('height', 'pointer')">
1111
<div class="pagebuilder-content-type-wrapper" template="{ name: preview.previewTemplate, data: preview, afterRender: function () { preview.dispatchAfterRenderEvent.apply(preview, arguments); } }" attr="{ id: id }"></div>
1212
</div>
1313
</div>

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

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default class Preview extends PreviewCollection {
106106
let duplicatedButton: ContentTypeInterface;
107107
let duplicatedButtonIndex: number;
108108
events.on("button-item:duplicateAfter", (args: ContentTypeDuplicateEventParamsInterface) => {
109-
if (this.parent.id === args.duplicateContentType.parent.id) {
109+
if (this.parent.id === args.duplicateContentType.parent.id && args.direct) {
110110
duplicatedButton = args.duplicateContentType;
111111
duplicatedButtonIndex = args.index;
112112
}
@@ -164,11 +164,10 @@ export default class Preview extends PreviewCollection {
164164
* @param {string} tolerance
165165
* @returns {JQueryUI.Sortable}
166166
*/
167-
public buttonsSortableOptions(
167+
public getSortableOptions(
168168
orientation: string = "width",
169169
tolerance: string = "intersect",
170170
): SortableOptionsInterface {
171-
let placeholderGhost: JQuery;
172171
return {
173172
handle: ".button-item-drag-handle",
174173
items: ".pagebuilder-content-type-wrapper",
@@ -177,6 +176,7 @@ export default class Preview extends PreviewCollection {
177176
tolerance,
178177
revert: 200,
179178
disabled: this.parent.children().length <= 1,
179+
180180
/**
181181
* Provide custom helper element
182182
*
@@ -192,6 +192,7 @@ export default class Preview extends PreviewCollection {
192192
helper[0].querySelector(".pagebuilder-options").remove();
193193
return helper[0];
194194
},
195+
195196
placeholder: {
196197
/**
197198
* Provide custom placeholder element
@@ -204,9 +205,7 @@ export default class Preview extends PreviewCollection {
204205
.clone()
205206
.css({
206207
display: "inline-block",
207-
opacity: 0,
208-
width: item.width(),
209-
height: item.height(),
208+
opacity: "0.3",
210209
})
211210
.removeClass("focused")
212211
.addClass("sortable-placeholder");
@@ -217,54 +216,18 @@ export default class Preview extends PreviewCollection {
217216
return;
218217
},
219218
},
219+
220220
/**
221-
* Logic for starting the sorting and adding the placeholderGhost
222-
*
223-
* @param {Event} event
224-
* @param {JQueryUI.SortableUIParams} element
221+
* Trigger interaction start on sort
225222
*/
226-
start(event: Event, element: JQueryUI.SortableUIParams) {
227-
placeholderGhost = element.placeholder
228-
.clone()
229-
.css({
230-
opacity: 0.3,
231-
position: "absolute",
232-
left: element.placeholder.position().left,
233-
top: element.placeholder.position().top,
234-
});
235-
element.item.parent().append(placeholderGhost);
223+
start() {
236224
events.trigger("stage:interactionStart");
237225
},
226+
238227
/**
239-
* Logic for changing element position
240-
*
241-
* Set the width and height of the moving placeholder animation
242-
* and then add animation of placeholder ghost to the placeholder position.
243-
*
244-
* @param {Event} event
245-
* @param {JQueryUI.SortableUIParams} element
246-
*/
247-
change(event: Event, element: JQueryUI.SortableUIParams) {
248-
element.placeholder.stop(true, false);
249-
if (orientation === "height") {
250-
element.placeholder.css({height: element.item.height() / 1.2});
251-
element.placeholder.animate({height: element.item.height()}, 200, "linear");
252-
}
253-
if (orientation === "width") {
254-
element.placeholder.css({width: element.item.width() / 1.2});
255-
element.placeholder.animate({width: element.item.width()}, 200, "linear");
256-
}
257-
placeholderGhost.stop(true, false).animate({
258-
left: element.placeholder.position().left,
259-
top: element.placeholder.position().top,
260-
}, 200);
261-
},
262-
/**
263-
* Logic for post sorting and removing the placeholderGhost
228+
* Stop stage interaction on stop
264229
*/
265-
stop(event: Event, element: JQueryUI.SortableUIParams) {
266-
placeholderGhost.remove();
267-
element.item.find(".pagebuilder-content-type-active").removeClass("pagebuilder-content-type-active");
230+
stop() {
268231
events.trigger("stage:interactionStop");
269232
},
270233
};

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/content-type-duplicate-event-params.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export default interface ContentTypeDuplicateEventParamsInterface {
1313
originalContentType: ContentTypeInterface & ContentTypeCollectionInterface;
1414
duplicateContentType: ContentTypeInterface & ContentTypeCollectionInterface;
1515
index: number;
16+
direct: boolean;
1617
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@ export default class PreviewCollection extends Preview {
2222
/**
2323
* Duplicate a collection content type
2424
*
25-
* @param {ContentTypeInterface & ContentTypeCollectionInterface} contentType
25+
* @param {ContentTypeCollectionInterface} contentType
2626
* @param {boolean} autoAppend
27+
* @param {boolean} direct
2728
* @returns {Promise<ContentTypeCollectionInterface> | void}
2829
*/
2930
public clone(
3031
contentType: ContentTypeCollectionInterface,
3132
autoAppend: boolean = true,
33+
direct: boolean = false,
3234
): Promise<ContentTypeCollectionInterface> | void {
3335
const index = contentType.parent.getChildren().indexOf(contentType) + 1 || null;
36+
const childrenLength = contentType.children ? contentType.children().length : null;
3437

3538
return new Promise((resolve, reject) => {
3639
createContentType(
3740
contentType.config,
3841
contentType.parent,
3942
contentType.stageId,
4043
contentType.dataStore.get() as DataObject,
44+
childrenLength,
4145
).then((duplicate: ContentTypeCollectionInterface) => {
4246
if (contentType.children && contentType.children().length > 0) {
4347
// Duplicate the instances children into the new duplicate
@@ -61,7 +65,7 @@ export default class PreviewCollection extends Preview {
6165
if (autoAppend) {
6266
contentType.parent.addChild(duplicate, index);
6367
}
64-
this.dispatchContentTypeCloneEvents(contentType, duplicate, index);
68+
this.dispatchContentTypeCloneEvents(contentType, duplicate, index, direct);
6569

6670
resolve(duplicate);
6771
});

0 commit comments

Comments
 (0)