Skip to content

Commit 67eaaef

Browse files
committed
Merge remote-tracking branch 'remotes/origin/MC-15238-live-edit' into cms-team-1-delivery
2 parents 9c57a12 + 6bdc2e5 commit 67eaaef

File tree

10 files changed

+47
-26
lines changed

10 files changed

+47
-26
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
z-index: auto;
1717

1818
[contenteditable=true] {
19-
display: inline-block;
19+
display: block;
2020
min-height: 18px;
2121
min-width: 20px;
2222
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
span[contenteditable=true] {
3838
display: block;
39+
overflow: hidden;
3940
}
4041
}
4142

app/code/Magento/PageBuilder/view/adminhtml/web/js/binding/live-edit.js

Lines changed: 15 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/js/content-type/buttons/preview.js

Lines changed: 5 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/js/content-type/preview.js

Lines changed: 1 addition & 3 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/tab-item/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/ts/js/binding/live-edit.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import $ from "jquery";
99
import ko from "knockout";
1010
import keyCodes from "Magento_Ui/js/lib/key-codes";
1111
import _ from "underscore";
12+
import {DataObject} from "../data-store";
1213

1314
/**
1415
* Strip HTML and return text
@@ -54,13 +55,15 @@ ko.bindingHandlers.liveEdit = {
5455
let focusedValue = element.innerHTML;
5556
let previouslyFocused: boolean = false;
5657
let blurTimeout: number;
58+
let lastUpdateValue: string;
5759

5860
/**
5961
* Record the value on focus, only conduct an update when data changes
6062
*/
6163
const onFocus = () => {
6264
clearTimeout(blurTimeout);
6365
focusedValue = stripHtml(element.innerHTML);
66+
lastUpdateValue = focusedValue;
6467

6568
if (selectAll && element.innerHTML !== "" && !previouslyFocused) {
6669
_.defer(() => {
@@ -123,8 +126,10 @@ ko.bindingHandlers.liveEdit = {
123126
* On key up update the view model to ensure all changes are saved
124127
*/
125128
const onKeyUp = () => {
126-
if (focusedValue !== stripHtml(element.innerHTML)) {
127-
viewModel.updateData(field, stripHtml(element.innerHTML));
129+
const strippedValue = stripHtml(element.innerHTML);
130+
if (focusedValue !== strippedValue) {
131+
lastUpdateValue = strippedValue;
132+
viewModel.updateData(field, strippedValue);
128133
}
129134
};
130135

@@ -165,6 +170,7 @@ ko.bindingHandlers.liveEdit = {
165170
// Allow the paste action to update the content
166171
_.defer(() => {
167172
const strippedValue = stripHtml(element.innerHTML);
173+
lastUpdateValue = strippedValue;
168174
element.innerHTML = strippedValue;
169175
/**
170176
* Calculate the position the caret should end up at, the difference in string length + the original
@@ -200,9 +206,13 @@ ko.bindingHandlers.liveEdit = {
200206
handlePlaceholderClass(element);
201207

202208
// Create a subscription onto the original data to update the internal value
203-
viewModel.contentType.dataStore.subscribe(() => {
204-
element.textContent = viewModel.contentType.dataStore.get(field);
205-
handlePlaceholderClass(element);
209+
viewModel.contentType.dataStore.subscribe((data: DataObject) => {
210+
// Only update the value if it differs from the last value added within live edit
211+
if (lastUpdateValue !== data[field]) {
212+
lastUpdateValue = data[field];
213+
element.textContent = data[field];
214+
handlePlaceholderClass(element);
215+
}
206216
}, field);
207217

208218
// Resolve issues of content editable being within an anchor

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,13 @@ export default class Preview extends PreviewCollection {
259259
if (this.contentType.dataStore.get("is_same_width") === "true") {
260260
if (buttonItems.length > 0) {
261261
const currentLargestButtonWidth = this.findLargestButtonWidth(buttonItems);
262-
const parentWrapperWidth = $(this.wrapperElement).width();
262+
const parentWrapperWidth = $(this.wrapperElement).find(".buttons-container").width();
263263
if (currentLargestButtonWidth === 0) {
264264
return;
265265
}
266266
buttonResizeValue = Math.min(currentLargestButtonWidth, parentWrapperWidth);
267267
}
268268
}
269-
270269
buttonItems.css("min-width", buttonResizeValue);
271270
}
272271
}
@@ -292,8 +291,11 @@ export default class Preview extends PreviewCollection {
292291
return 0;
293292
}
294293
const widthProperties = ["paddingLeft", "paddingRight", "borderLeftWidth", "borderRightWidth"];
294+
const buttonText = buttonItem.find("[data-element='link_text']");
295+
const textWidth = buttonText.css("display", "inline-block").width();
296+
buttonText.css("display", "");
295297
return widthProperties.reduce((accumulatedWidth, widthProperty): number => {
296298
return accumulatedWidth + (parseInt(buttonItem.css(widthProperty), 10) || 0);
297-
}, buttonItem.find("[data-element='link_text']").width());
299+
}, textWidth);
298300
}
299301
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import ContentTypeInterface from "../content-type.types";
2525
import {DataObject} from "../data-store";
2626
import {getDraggedContentTypeConfig} from "../drag-drop/registry";
2727
import {getSortableOptions} from "../drag-drop/sortable";
28-
import {get, set} from "../utils/object";
28+
import {get} from "../utils/object";
2929
import appearanceConfig from "./appearance-config";
3030
import ObservableUpdater from "./observable-updater";
3131
import ObservableObject from "./observable-updater.types";
@@ -147,10 +147,7 @@ export default class Preview implements PreviewInterface {
147147
* @param {string} value
148148
*/
149149
public updateData(key: string, value: string) {
150-
const data = this.contentType.dataStore.getState();
151-
152-
set(data, key, value);
153-
this.contentType.dataStore.setState(data);
150+
this.contentType.dataStore.set(key, value);
154151
}
155152

156153
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class Preview extends PreviewCollection {
7070
tabItem.contentType &&
7171
tabItem.contentType.parentContentType &&
7272
tabItem.contentType.parentContentType.id ===
73-
tabItem.contentType.parentContentType.parentContentType.id
73+
this.contentType.parentContentType.id
7474
) {
7575
const newIndex = tabItem
7676
.contentType

0 commit comments

Comments
 (0)