Skip to content

Commit 72c8726

Browse files
committed
MC-18601: Page Builder Render
1 parent 7f3f07f commit 72c8726

File tree

8 files changed

+71
-16
lines changed

8 files changed

+71
-16
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/config.js

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

Lines changed: 5 additions & 6 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/page-builder.js

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

Lines changed: 6 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/config.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import _ from "underscore";
77
import ContentTypeConfigInterface from "./content-type-config.types";
88

9-
export default class Config {
9+
export type Mode = "Preview" | "Master";
1010

11+
export default class Config {
1112
/**
1213
* Set the initial config
1314
*
@@ -17,6 +18,22 @@ export default class Config {
1718
Config.config = _.extend(Config.config, config);
1819
}
1920

21+
/**
22+
* Set the applications mode
23+
*
24+
* @param mode
25+
*/
26+
public static setMode(mode: Mode): void {
27+
Config.mode = mode;
28+
}
29+
30+
/**
31+
* Retrieve the applications mode
32+
*/
33+
public static getMode(): Mode {
34+
return Config.mode;
35+
}
36+
2037
/**
2138
* Retrieve the init config
2239
*
@@ -50,4 +67,5 @@ export default class Config {
5067
private static config: any = {
5168
dataContentTypeAttributeName: "data-content-type",
5269
};
70+
private static mode: Mode;
5371
}

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

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

66
import events from "Magento_PageBuilder/js/events";
77
import _ from "underscore";
8+
import Config, {Mode} from "./config";
89
import ContentType from "./content-type";
910
import ContentTypeCollectionInterface from "./content-type-collection.types";
1011
import ContentTypeConfigInterface, {ConfigFieldInterface} from "./content-type-config.types";
1112
import ContentTypeInterface from "./content-type.types";
1213
import {ContentTypeMountEventParamsInterface} from "./content-type/content-type-events.types";
14+
import Master from "./content-type/master";
15+
import MasterCollection from "./content-type/master-collection";
1316
import masterFactory from "./content-type/master-factory";
17+
import Preview from "./content-type/preview";
18+
import PreviewCollection from "./content-type/preview-collection";
1419
import previewFactory from "./content-type/preview-factory";
1520
import loadModule from "./utils/loader";
1621

22+
type ViewFactory = (
23+
contentType: ContentTypeInterface | ContentTypeCollectionInterface,
24+
config: ContentTypeConfigInterface,
25+
) => Promise<Preview | PreviewCollection | Master | MasterCollection>;
26+
1727
/**
1828
* Create new content type
1929
*
@@ -43,14 +53,10 @@ export default function createContentType(
4353
config,
4454
stageId,
4555
);
46-
Promise.all(
47-
[
48-
previewFactory(contentType, config),
49-
masterFactory(contentType, config),
50-
],
51-
).then(([previewComponent, masterComponent]) => {
52-
contentType.preview = previewComponent;
53-
contentType.content = masterComponent;
56+
const viewFactory: ViewFactory = Config.getMode() === "Preview" ? previewFactory : masterFactory;
57+
viewFactory(contentType, config).then((viewComponent) => {
58+
const viewName = Config.getMode() === "Preview" ? "preview" : "content";
59+
contentType[viewName] = viewComponent;
5460
contentType.dataStore.setState(
5561
prepareData(config, data),
5662
);

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/page-builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ko from "knockout";
88
import events from "Magento_PageBuilder/js/events";
99
import utils from "mageUtils";
1010
import _ from "underscore";
11-
import Config from "./config";
11+
import Config, {Mode} from "./config";
1212
import ContentTypeCollectionInterface from "./content-type-collection";
1313
import createContentType from "./content-type-factory";
1414
import PageBuilderInterface from "./page-builder.types";
@@ -33,6 +33,7 @@ export default class PageBuilder implements PageBuilderInterface {
3333

3434
constructor(config: any, initialValue: string) {
3535
Config.setConfig(config);
36+
Config.setMode("Preview");
3637
this.initialValue = initialValue;
3738
this.isFullScreen(config.isFullScreen);
3839
this.config = config;

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/render/frame.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const deferredTemplates: {[key: string]: JQueryDeferred<string>} = {};
2323
*/
2424
export default function listen(config: object) {
2525
Config.setConfig(config);
26+
Config.setMode("Master");
2627
window.addEventListener(
2728
"message",
2829
(event) => {
@@ -108,6 +109,8 @@ function render(message: {stageId: string, tree: TreeItem}) {
108109
},
109110
},
110111
);
112+
}).catch((error) => {
113+
reject(error);
111114
});
112115
});
113116
}
@@ -148,6 +151,8 @@ function createRenderTree(
148151
} else {
149152
resolve(contentType);
150153
}
154+
}).catch((error) => {
155+
reject(error);
151156
});
152157
});
153158
}

0 commit comments

Comments
 (0)