Skip to content

Commit 2179d0d

Browse files
committed
MC-18601: Page Builder Render
- Create original tree in iframe
1 parent 02fc895 commit 2179d0d

File tree

14 files changed

+178
-160
lines changed

14 files changed

+178
-160
lines changed

app/code/Magento/PageBuilder/Block/Adminhtml/Stage/Render.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,49 @@
1010

1111
use Magento\Framework\View\Element\Template;
1212
use Magento\RequireJs\Model\FileManager;
13+
use Magento\PageBuilder\Model\Stage\Config;
14+
use Magento\Framework\Serialize\Serializer\Json;
1315

1416
/**
1517
* Class Render
1618
*/
1719
class Render extends Template
1820
{
21+
/**
22+
* @var FileManager
23+
*/
1924
private $fileManager;
2025

26+
/**
27+
* @var Config
28+
*/
29+
private $pageBuilderConfig;
30+
31+
/**
32+
* @var Json
33+
*/
34+
private $json;
35+
2136
/**
2237
* @param Template\Context $context
2338
* @param FileManager $fileManager
39+
* @param Config $config
40+
* @param Json $json
2441
* @param array $data
2542
*/
2643
public function __construct(
2744
Template\Context $context,
2845
FileManager $fileManager,
46+
Config $config,
47+
Json $json,
2948
array $data = []
3049
) {
3150
parent::__construct($context, $data);
3251
$this->fileManager = $fileManager;
52+
$this->pageBuilderConfig = $config;
53+
$this->json = $json;
3354
}
3455

35-
3656
/**
3757
* Generate the URL to RequireJS
3858
*
@@ -55,4 +75,14 @@ public function getRequireJsConfigUrl() : string
5575
$requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
5676
return $requireJsConfig->getUrl();
5777
}
78+
79+
/**
80+
* Retrieve the Page Builder's config
81+
*
82+
* @return array
83+
*/
84+
public function getPageBuilderConfig() : string
85+
{
86+
return $this->json->serialize($this->pageBuilderConfig->getConfig());
87+
}
5888
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</script>
6969
<script type="text/javascript">
7070
require(['Magento_PageBuilder/js/render/frame'], function (listen) {
71-
listen();
71+
listen(<?= $this->getPageBuilderConfig(); ?>);
7272
});
7373
</script>
7474
Page Builder Render Frame

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

Lines changed: 8 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/js/master-format/render.js

Lines changed: 4 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/master-format/render/serialize.js

Lines changed: 7 additions & 16 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/render/frame.js

Lines changed: 48 additions & 27 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/stage-builder.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/content-type-factory.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default function createContentType(
3636
(resolve: (contentType: ContentTypeInterface | ContentTypeCollectionInterface) => void,
3737
reject: (error: string) => void,
3838
) => {
39+
const t0 = performance.now();
3940
loadModule([config.component], (contentTypeComponent: typeof ContentType) => {
41+
const t1 = performance.now();
42+
console.log("Call to load " + config.component + " took " + (t1 - t0) + " milliseconds.")
4043
try {
4144
const contentType = new contentTypeComponent(
4245
parentContentType,
@@ -107,6 +110,10 @@ function prepareData(config: ContentTypeConfigInterface, data: {}) {
107110
* @returns {FieldDefaultsInterface}
108111
*/
109112
function prepareDefaults(fields: ConfigFieldInterface): FieldDefaultsInterface {
113+
if (_.isEmpty(fields)) {
114+
return {};
115+
}
116+
110117
return _.mapObject(fields, (field) => {
111118
if (!_.isUndefined(field.default)) {
112119
return field.default;

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/master-format/render.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export default class MasterFormatRenderer {
3636
if (this.ready) {
3737
this.channel.port1.postMessage({
3838
type: "render",
39-
message: getSerializedTree(rootContainer),
39+
message: {
40+
stageId: this.stageId,
41+
tree: getSerializedTree(rootContainer),
42+
},
4043
});
4144
this.channel.port1.onmessage = (event) => {
4245
if (event.isTrusted) {

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/master-format/render/serialize.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55

66
import ContentTypeCollection from "../../content-type-collection";
77
import ContentTypeInterface from "../../content-type.types";
8-
import appearanceConfig from "../../content-type/appearance-config";
98
import {GeneratedElementsData} from "../../content-type/observable-updater";
109
import { DataObject } from "../../data-store";
1110

1211
export interface TreeItem {
13-
template: string;
12+
name: string;
13+
id: string;
1414
data: DataObject;
1515
children: TreeItem[];
1616
}
1717

1818
/**
19-
* Serailize the tree as a simplified object for rendering
19+
* Serialize the tree as a simplified object for rendering
2020
*
2121
* @param contentType
2222
*/
2323
export function buildTree(contentType: ContentTypeInterface) {
24-
const data = getMasterData(contentType);
24+
const data = getData(contentType);
2525
const tree: TreeItem = {
26-
template: getTemplate(contentType, data.appearance),
26+
name: contentType.config.name,
27+
id: contentType.id,
2728
data,
2829
children: [],
2930
};
@@ -46,20 +47,11 @@ export function getSerializedTree(contentType: ContentTypeInterface) {
4647
return buildTree(contentType);
4748
}
4849

49-
/**
50-
* Retrieve the template for the content type \
51-
* @param contentType
52-
* @param appearance
53-
*/
54-
function getTemplate(contentType: ContentTypeInterface, appearance: string): string {
55-
return appearanceConfig(contentType.config.name, appearance).master_template;
56-
}
57-
5850
/**
5951
* Retrieve the master data from the content types instance
6052
*
6153
* @param contentType
6254
*/
63-
function getMasterData(contentType: ContentTypeInterface): GeneratedElementsData {
64-
return contentType.content.getBindings() || {};
55+
function getData(contentType: ContentTypeInterface): GeneratedElementsData {
56+
return contentType.dataStore.getState() || {};
6557
}

0 commit comments

Comments
 (0)