Skip to content

Commit 5ed6464

Browse files
committed
PB-108 improvements to moving and duplication of column content type to preserve column width
1 parent 315a45d commit 5ed6464

File tree

6 files changed

+89
-13
lines changed

6 files changed

+89
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
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/column/preview.js

Lines changed: 24 additions & 6 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/column/resize.js

Lines changed: 17 additions & 2 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-line/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ export default class Preview extends PreviewCollection {
404404

405405
newNeighbour = getAdjacentColumn(newNeighbour, direction);
406406
if (!newNeighbour) {
407-
updateColumnWidth(column, oldWidth - totalWidthAdjusted);
407+
updateColumnWidth(column, totalWidthAdjusted);
408408
break;
409409
}
410410
let neighbourExistingWidth = this.resizeUtils.getColumnWidth(newNeighbour);

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {getDefaultGridSize} from "../column-group/grid-size";
1919
import ColumnGroupPreview from "../column-group/preview";
2020
import ColumnLinePreview from "../column-line/preview";
2121
import {
22-
ContentTypeDroppedCreateEventParamsInterface, ContentTypeDuplicateEventParamsInterface,
23-
ContentTypeMountEventParamsInterface,
22+
ContentTypeDroppedCreateEventParamsInterface,
23+
ContentTypeDuplicateEventParamsInterface,
2424
ContentTypeMoveEventParamsInterface,
2525
ContentTypeRemovedEventParamsInterface,
2626
} from "../content-type-events.types";
@@ -226,7 +226,32 @@ export default class Preview extends PreviewCollection {
226226
return super.clone(contentType, autoAppend);
227227
}
228228

229-
// Attempt to split the current column into parts
229+
let shrinkableColumn = resizeUtils.findBiggerShrinkableColumn(contentType);
230+
if (shrinkableColumn) {
231+
const shrinkableClone = super.clone(contentType, autoAppend);
232+
if (shrinkableClone) {
233+
let newShrinkableColumnWidth = resizeUtils.getColumnWidth(shrinkableColumn)
234+
- resizeUtils.getColumnWidth(contentType);
235+
let duplicateColumnWidth = resizeUtils.getColumnWidth(contentType);
236+
shrinkableClone.then((duplicateContentType: ContentTypeCollectionInterface<Preview>) => {
237+
updateColumnWidth(
238+
shrinkableColumn,
239+
resizeUtils.getAcceptedColumnWidth(
240+
(newShrinkableColumnWidth).toString(),
241+
),
242+
);
243+
updateColumnWidth(
244+
duplicateContentType,
245+
duplicateColumnWidth
246+
);
247+
248+
return duplicateContentType;
249+
});
250+
}
251+
return;
252+
}
253+
254+
// Attempt to split the current column into parts
230255
const splitTimes = Math.round(resizeUtils.getColumnWidth(contentType) / resizeUtils.getSmallestColumnWidth());
231256
if (splitTimes > 1) {
232257
const splitClone = super.clone(contentType, autoAppend);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,24 @@ export default class Resize {
206206
);
207207
}
208208

209+
/**
210+
* Find a shrinkable column of a greater size outwards from the current column
211+
*
212+
* @param {ContentTypeCollectionInterface<ColumnPreview>} column
213+
* @returns {ContentTypeCollectionInterface<ColumnPreview>}
214+
*/
215+
public findBiggerShrinkableColumn(
216+
column: ContentTypeCollectionInterface<ColumnPreview>,
217+
): ContentTypeCollectionInterface<ColumnPreview> {
218+
return outwardSearch(
219+
column.parentContentType.children(),
220+
getColumnIndexInGroup(column),
221+
(neighbourColumn) => {
222+
return this.getColumnWidth(neighbourColumn) > this.getColumnWidth(column);
223+
},
224+
);
225+
}
226+
209227
/**
210228
* Calculate the ghost size for the resizing action
211229
*

0 commit comments

Comments
 (0)