Skip to content

Commit 8f9e0dc

Browse files
committed
PB-170: TinyMCE Performance is very poor with multiple instances on Stage
- Refactor code for selection - Add default line height to reduce jumping - Rename tinymce utility to editor
1 parent 2d8e9d2 commit 8f9e0dc

File tree

9 files changed

+143
-166
lines changed

9 files changed

+143
-166
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
z-index: 20;
1717
}
1818
> .inline-wysiwyg {
19+
line-height: 1.3;
1920
min-height: 1rem;
2021
overflow: auto;
2122

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

Lines changed: 6 additions & 12 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/text/preview.js

Lines changed: 6 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/converter/html/directive.js

Lines changed: 2 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/utils/tinymce.js renamed to app/code/Magento/PageBuilder/view/adminhtml/web/js/utils/editor.js

Lines changed: 62 additions & 64 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/slide/preview.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {OptionsInterface} from "../../content-type-menu/option.types";
1414
import {DataObject} from "../../data-store";
1515
import Uploader from "../../uploader";
1616
import delayUntil from "../../utils/delay-until";
17+
import {createBookmark, isWysiwygSupported, lockImageSize, moveToBookmark, unlockImageSize} from "../../utils/editor";
1718
import nestingLinkDialog from "../../utils/nesting-link-dialog";
18-
import {getSelection, isWysiwygSupported, restoreSelection} from "../../utils/tinymce";
1919
import WysiwygFactory from "../../wysiwyg/factory";
2020
import WysiwygInterface from "../../wysiwyg/wysiwyg-interface";
2121
import {ContentTypeMountEventParamsInterface} from "../content-type-events.types";
@@ -158,20 +158,16 @@ export default class Preview extends BasePreview {
158158
* @returns {Boolean}
159159
*/
160160
public activateEditor(preview: Preview, event: JQueryEventObject) {
161-
const activate = () => {
162-
const element = this.wysiwyg && this.element || this.textarea;
163-
element.focus();
164-
};
165-
166161
if (this.element && !this.wysiwyg) {
167-
const selection = getSelection();
162+
const bookmark = createBookmark(event);
163+
lockImageSize(this.element);
168164
this.element.removeAttribute("contenteditable");
169165
_.defer(() => {
170166
this.initWysiwyg(true)
171167
.then(() => delayUntil(
172168
() => {
173-
activate();
174-
restoreSelection(this.element, selection);
169+
moveToBookmark(bookmark);
170+
unlockImageSize(this.element);
175171
},
176172
() => this.element.classList.contains("mce-edit-focus"),
177173
10,
@@ -180,8 +176,6 @@ export default class Preview extends BasePreview {
180176
console.error(error);
181177
});
182178
});
183-
} else {
184-
activate();
185179
}
186180
}
187181

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import _ from "underscore";
99
import HideShowOption from "../../content-type-menu/hide-show-option";
1010
import {OptionsInterface} from "../../content-type-menu/option.types";
1111
import delayUntil from "../../utils/delay-until";
12-
import {createBookmark, isWysiwygSupported, moveToBookmark} from "../../utils/tinymce";
12+
import {createBookmark, isWysiwygSupported, lockImageSize, moveToBookmark, unlockImageSize} from "../../utils/editor";
1313
import WysiwygFactory from "../../wysiwyg/factory";
1414
import WysiwygInterface from "../../wysiwyg/wysiwyg-interface";
1515
import BasePreview from "../preview";
@@ -134,13 +134,14 @@ export default class Preview extends BasePreview {
134134
public activateEditor(preview: Preview, event: JQueryEventObject) {
135135
if (this.element && !this.wysiwyg) {
136136
const bookmark = createBookmark(event);
137+
lockImageSize(this.element);
137138
this.element.removeAttribute("contenteditable");
138139
_.defer(() => {
139140
this.initWysiwyg(true)
140141
.then(() => delayUntil(
141142
() => {
142-
console.log(bookmark);
143143
moveToBookmark(bookmark);
144+
unlockImageSize(this.element);
144145
},
145146
() => this.element.classList.contains("mce-edit-focus"),
146147
10,

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/converter/html/directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import {DataObject} from "../../data-store";
77
import {convertMediaDirectivesToUrls, removeQuotesInMediaDirectives} from "../../utils/directives";
8+
import {encodeContent} from "../../utils/editor";
89
import {get} from "../../utils/object";
9-
import {encodeContent} from "../../utils/tinymce";
1010
import ConverterInterface from "../converter-interface";
1111

1212
/**

0 commit comments

Comments
 (0)