Skip to content

Commit 4d5db10

Browse files
Merge pull request #336 from adobe-commerce-tier-4/T4-PR-06-14-2024
[Support Tier-4 chittima] 06-14-2024 Regular delivery of bugfixes and improvements
2 parents 894680a + 5ba4de8 commit 4d5db10

File tree

12 files changed

+167
-31
lines changed

12 files changed

+167
-31
lines changed

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminPageBuilderImageTest/ImageTestCMSPageOnTabletTest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@
9494
<dontSeeElement selector="{{ImageOnStorefront.imageMobile('1')}}" stepKey="dontSeeMobileImageOnDefaultRes"/>
9595

9696
<!-- Validate images with window width of 768px -->
97-
<resizeWindow width="769" height="1024" stepKey="resizeWindowTo768by1024"/>
97+
<resizeWindow width="768" height="1024" stepKey="resizeWindowTo768by1024"/>
9898
<seeElement selector="{{ImageOnStorefront.imageDesktop('1')}}" stepKey="seeMainImageOn768by1024"/>
9999
<dontSeeElement selector="{{ImageOnStorefront.imageMobile('1')}}" stepKey="dontSeeMobileImageOn768by1024"/>
100100

101101
<!-- Validate images with window width of 767px -->
102-
<resizeWindow width="768" height="1024" stepKey="resizeWindowTo767by1024"/>
102+
<resizeWindow width="767" height="1024" stepKey="resizeWindowTo767by1024"/>
103103
<seeElement selector="{{ImageOnStorefront.imageMobile('1')}}" stepKey="seeMobileImageOn767by1024"/>
104104
<dontSeeElement selector="{{ImageOnStorefront.imageDesktop('1')}}" stepKey="dontSeeDesktopImageOn767by1024"/>
105105
</test>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\ViewModel;
9+
10+
use Magento\Backend\ViewModel\RequireJsConfigModifierInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
13+
/**
14+
* Modifies requirejs configuration for the stage render frame
15+
*
16+
* Override the text! plugin within the iframe to ensure we can pipe any XHR requests through to the parent window
17+
* as the same origin policy will not allow us to load the templates within this iframe.
18+
* It is important that this mapping is configured before requirejs-config.js to ensure the text! plugin is overridden
19+
* for all requests.
20+
*/
21+
class StageRenderFrameRequireJsConfigModifier implements ArgumentInterface, RequireJsConfigModifierInterface
22+
{
23+
/**
24+
* @inheritDoc
25+
*/
26+
public function modify(array $config): array
27+
{
28+
$config['map']['*'] = array_merge(
29+
$config['map']['*'] ?? [],
30+
[
31+
'text' => 'Magento_PageBuilder/js/master-format/render/requirejs/text',
32+
'Magento_PageBuilder/js/events' => 'Magento_PageBuilder/js/master-format/render/events'
33+
]
34+
);
35+
return $config;
36+
}
37+
}

app/code/Magento/PageBuilder/etc/view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
<var name="stage">true</var>
6363
<var name="class">mobile-switcher</var>
6464
<var name="icon">Magento_PageBuilder::css/images/switcher/switcher-mobile.svg</var>
65-
<var name="media">only screen and (max-width: 768px)</var>
65+
<var name="media">only screen and (max-width: 767px)</var>
6666
<var name="conditions">
67-
<var name="max-width">768px</var>
67+
<var name="max-width">767px</var>
6868
<var name="min-width">640px</var>
6969
</var>
7070
<var name="options">

app/code/Magento/PageBuilder/view/adminhtml/layout/pagebuilder_stage_render.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
<remove src="css/styles.css"/>
1515
</head>
1616
<body>
17+
<referenceBlock name="require.js">
18+
<arguments>
19+
<argument name="config_modifier" xsi:type="object">
20+
Magento\PageBuilder\ViewModel\StageRenderFrameRequireJsConfigModifier
21+
</argument>
22+
</arguments>
23+
</referenceBlock>
1724
<referenceContainer name="backend.page" remove="true"/>
1825
<referenceContainer name="menu.wrapper" remove="true"/>
1926
<referenceContainer name="root">

app/code/Magento/PageBuilder/view/adminhtml/templates/stage/render.phtml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,16 @@
1010
*/
1111
?>
1212

13-
<?php
14-
/**
15-
* Override the text! plugin within the iframe to ensure we can pipe any XHR requests through to the parent window
16-
* as the same origin policy will not allow us to load the templates within this iframe.
17-
*/
18-
?>
1913
<?php
2014
$pageBuilderConfig = $block->getPageBuilderConfig();
2115

22-
$script = <<<SCRIPT
23-
require.config({
24-
'map': {
25-
'*': {
26-
'text': 'Magento_PageBuilder/js/master-format/render/requirejs/text',
27-
'Magento_PageBuilder/js/events': 'Magento_PageBuilder/js/master-format/render/events'
28-
}
29-
}
30-
});
31-
SCRIPT;
32-
3316
/**
3417
* To be able to override the text plugin we need the Magento template engine to be used, as the template engine
3518
* within lib has a dependency on the text! plugin we need to ensure we set the template engine before the
3619
* dependency blocks us. If we try to just override using the RequireJS config above our !text plugin will never
3720
* get overridden as our template engine cannot load.
3821
*/
39-
$script .= <<<SCRIPT
22+
$script = <<<SCRIPT
4023
require([
4124
'ko',
4225
'Magento_Ui/js/lib/knockout/template/engine'

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

Lines changed: 8 additions & 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/utils/editor.js

Lines changed: 2 additions & 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/template/page-builder.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<with args="stage">
3232
<render></render>
3333
</with>
34-
<iframe attr="id: 'render_frame_' + id" sandbox="allow-scripts allow-same-origin" style="position: absolute; width:0; height:0; border: none;"></iframe>
34+
<!-- Do not modify the "sandbox" attribute without approval from a security engineer -->
35+
<iframe attr="id: 'render_frame_' + id" sandbox="allow-scripts" style="position: absolute; width:0; height:0; border: none;"></iframe>
3536
</if>
3637
</div>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import $ from "jquery";
77
import events from "Magento_PageBuilder/js/events";
8+
import {Editor} from "tinymce";
89
import _ from "underscore";
910
import HideShowOption from "../../content-type-menu/hide-show-option";
1011
import {OptionsInterface} from "../../content-type-menu/option.types";
@@ -158,7 +159,16 @@ export default class Preview extends BasePreview {
158159

159160
if (focus) {
160161
wysiwygConfig.adapter.settings.auto_focus = this.element.id;
161-
wysiwygConfig.adapter.settings.init_instance_callback = () => {
162+
wysiwygConfig.adapter.settings.init_instance_callback = (editor: Editor) => {
163+
editor.on("mousedown", (event) => {
164+
if (event.target.nodeName === "IMG"
165+
&& event.button !== 2
166+
&& editor.dom.getRoot() !== document.activeElement
167+
) {
168+
editor.selection.select(event.target);
169+
editor.nodeChanged();
170+
}
171+
});
162172
_.defer(() => {
163173
this.element.blur();
164174
this.element.focus();

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/utils/editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ export function createBookmark(event: JQueryEventObject): Bookmark {
279279
* @param bookmark
280280
*/
281281
export function moveToBookmark(bookmark: Bookmark) {
282-
((window as any).tinymce.activeEditor as Editor).selection.moveToBookmark(bookmark);
282+
getActiveEditor().selection.moveToBookmark(bookmark);
283+
getActiveEditor().nodeChanged();
283284
}
284285

285286
/**

0 commit comments

Comments
 (0)