Skip to content

Commit 77ec738

Browse files
committed
PB-170: TinyMCE Performance is very poor with multiple instances on Stage
- Open TinyMCE on drop
1 parent 072a63d commit 77ec738

File tree

5 files changed

+59
-16
lines changed

5 files changed

+59
-16
lines changed

app/code/Magento/PageBuilder/Model/Stage/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ class Config
101101
* @param \Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor
102102
* @param \Magento\PageBuilder\Model\Wysiwyg\InlineEditingSupportedAdapterList $inlineEditingChecker
103103
* @param \Magento\PageBuilder\Model\WidgetInitializerConfig $widgetInitializerConfig
104+
* @param array $rootContainerConfig
104105
* @param \Magento\Widget\Model\Widget\Config|null $widgetConfig
105106
* @param \Magento\Variable\Model\Variable\Config|null $variableConfig
106-
* @param array $rootContainerConfig
107107
* @param array $data
108108
*
109109
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -118,9 +118,9 @@ public function __construct(
118118
\Magento\Ui\Block\Wysiwyg\ActiveEditor $activeEditor,
119119
\Magento\PageBuilder\Model\Wysiwyg\InlineEditingSupportedAdapterList $inlineEditingChecker,
120120
\Magento\PageBuilder\Model\WidgetInitializerConfig $widgetInitializerConfig,
121+
array $rootContainerConfig = [],
121122
\Magento\Widget\Model\Widget\Config $widgetConfig = null,
122123
\Magento\Variable\Model\Variable\Config $variableConfig = null,
123-
array $rootContainerConfig = [],
124124
array $data = []
125125
) {
126126
$this->config = $config;

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/_typography.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ body {
213213
.magento-placeholder-error,
214214
.magento-placeholder {
215215
img {
216+
display: inline-block;
216217
margin-right: 5px;
217218
max-height: 20px;
218219
vertical-align: middle;
219-
display: inline-block;
220220
}
221221
}
222222
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
}
1818
> .inline-wysiwyg {
1919
line-height: 1.3;
20-
min-height: 1rem;
20+
min-height: 3rem;
2121
overflow: auto;
2222

2323
+ .placeholder-text {

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

Lines changed: 23 additions & 0 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/text/preview.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import WysiwygFactory from "../../wysiwyg/factory";
2121
import WysiwygInterface from "../../wysiwyg/wysiwyg-interface";
2222
import BasePreview from "../preview";
23+
import {ContentTypeMountEventParamsInterface} from "../content-type-events.types";
2324

2425
/**
2526
* @api
@@ -40,6 +41,11 @@ export default class Preview extends BasePreview {
4041
*/
4142
private element: HTMLElement;
4243

44+
/**
45+
* Deferred called once the render is completed
46+
*/
47+
private afterRenderDeferred: JQueryDeferred<HTMLElement> = $.Deferred();
48+
4349
/**
4450
* The textarea element in disabled mode
4551
*/
@@ -84,6 +90,8 @@ export default class Preview extends BasePreview {
8490
this.element = element;
8591
element.id = this.contentType.id + "-editor";
8692

93+
this.afterRenderDeferred.resolve(element);
94+
8795
/**
8896
* afterRenderWysiwyg is called whenever Knockout causes a DOM re-render. This occurs frequently within Slider
8997
* due to Slick's inability to perform a refresh with Knockout managing the DOM. Due to this the original
@@ -200,8 +208,7 @@ export default class Preview extends BasePreview {
200208
/**
201209
* @param {HTMLTextAreaElement} element
202210
*/
203-
public initTextarea(element: HTMLTextAreaElement)
204-
{
211+
public initTextarea(element: HTMLTextAreaElement) {
205212
this.textarea = element;
206213

207214
// set initial value of textarea based on data store
@@ -218,26 +225,23 @@ export default class Preview extends BasePreview {
218225
/**
219226
* Save current value of textarea in data store
220227
*/
221-
public onTextareaKeyUp()
222-
{
228+
public onTextareaKeyUp() {
223229
this.adjustTextareaHeightBasedOnScrollHeight();
224230
this.contentType.dataStore.set("content", this.textarea.value);
225231
}
226232

227233
/**
228234
* Start stage interaction on textarea blur
229235
*/
230-
public onTextareaFocus()
231-
{
236+
public onTextareaFocus() {
232237
$(this.textarea).closest(".pagebuilder-content-type").addClass("pagebuilder-toolbar-active");
233238
events.trigger("stage:interactionStart");
234239
}
235240

236241
/**
237242
* Stop stage interaction on textarea blur
238243
*/
239-
public onTextareaBlur()
240-
{
244+
public onTextareaBlur() {
241245
$(this.textarea).closest(".pagebuilder-content-type").removeClass("pagebuilder-toolbar-active");
242246
events.trigger("stage:interactionStop");
243247
}
@@ -247,8 +251,7 @@ export default class Preview extends BasePreview {
247251
*
248252
* @returns {any}
249253
*/
250-
public getPlaceholderStyle()
251-
{
254+
public getPlaceholderStyle() {
252255
const keys = [
253256
"marginBottom",
254257
"marginLeft",
@@ -265,11 +268,28 @@ export default class Preview extends BasePreview {
265268
});
266269
}
267270

271+
/**
272+
* Bind events
273+
*/
274+
protected bindEvents() {
275+
super.bindEvents();
276+
277+
// After drop of new content type open TinyMCE and focus
278+
events.on("text:dropAfter", (args: ContentTypeMountEventParamsInterface) => {
279+
if (args.id === this.contentType.id) {
280+
this.afterRenderDeferred.then(() => {
281+
if (this.isWysiwygSupported()) {
282+
this.initWysiwyg(true);
283+
}
284+
});
285+
}
286+
});
287+
}
288+
268289
/**
269290
* Adjust textarea's height based on scrollHeight
270291
*/
271-
private adjustTextareaHeightBasedOnScrollHeight()
272-
{
292+
private adjustTextareaHeightBasedOnScrollHeight() {
273293
this.textarea.style.height = "";
274294
const scrollHeight = this.textarea.scrollHeight;
275295
const minHeight = parseInt($(this.textarea).css("min-height"), 10);

0 commit comments

Comments
 (0)