Skip to content

Commit 5effefa

Browse files
Responsive breakpoint switcher
- prototype
1 parent ff00d17 commit 5effefa

File tree

7 files changed

+120
-3
lines changed

7 files changed

+120
-3
lines changed

app/code/Magento/PageBuilder/Component/Form/Element/Wysiwyg.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\Data\FormFactory;
1212
use Magento\Framework\View\Element\UiComponent\ContextInterface;
13-
use Magento\PageBuilder\Model\View\File\Collector\PageBuilder;
1413
use Magento\Ui\Component\Wysiwyg\ConfigInterface;
1514
use Magento\Catalog\Api\CategoryAttributeRepositoryInterface;
1615
use Magento\Framework\Exception\NoSuchEntityException;
1716
use Magento\PageBuilder\Model\Config as PageBuilderConfig;
1817
use Magento\PageBuilder\Model\State as PageBuilderState;
1918
use Magento\PageBuilder\Model\Stage\Config as Config;
19+
use Magento\Framework\View\ConfigInterface as ViewConfigInterface;
2020

2121
/**
2222
* Updates wysiwyg element with Page Builder specific config
@@ -39,6 +39,7 @@ class Wysiwyg extends \Magento\Ui\Component\Form\Element\Wysiwyg
3939
* @param array $config
4040
* @param PageBuilderConfig|null $pageBuilderConfig
4141
* @param bool $overrideSnapshot
42+
* @param ViewConfigInterface $viewConfig
4243
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
4344
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
4445
* @throws \Magento\Framework\Exception\NoSuchEntityException
@@ -54,8 +55,10 @@ public function __construct(
5455
array $data = [],
5556
array $config = [],
5657
PageBuilderConfig $pageBuilderConfig = null,
57-
bool $overrideSnapshot = false
58+
bool $overrideSnapshot = false,
59+
ViewConfigInterface $viewConfig = null
5860
) {
61+
$viewConfig = $viewConfig ?: ObjectManager::getInstance()->get(ViewConfigInterface::class);
5962
$wysiwygConfigData = isset($config['wysiwygConfigData']) ? $config['wysiwygConfigData'] : [];
6063

6164
// If a dataType is present we're dealing with an attribute
@@ -84,6 +87,10 @@ public function __construct(
8487
$wysiwygConfigData = $stageConfig->getConfig();
8588
$wysiwygConfigData['pagebuilder_button'] = true;
8689
$wysiwygConfigData['pagebuilder_content_snapshot'] = true;
90+
$wysiwygConfigData['viewports'] = $viewConfig->getViewConfig()->getVarValue(
91+
'Magento_PageBuilder',
92+
'breakpoints'
93+
);;
8794

8895
if ($overrideSnapshot) {
8996
$pageBuilderConfig = $pageBuilderConfig ?: ObjectManager::getInstance()->get(PageBuilderConfig::class);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<vars module="Magento_PageBuilder">
2626
<var name="breakpoints">
2727
<var name="desktop">
28+
<var name="label">Desktop</var>
29+
<var name="stage">true</var>
30+
<var name="default">true</var>
31+
<!-- TODO: add button icons /-->
2832
<var name="conditions">
2933
<var name="min-width">1024px</var>
3034
</var>
@@ -53,6 +57,9 @@
5357
</var>
5458
</var>
5559
<var name="mobile">
60+
<var name="label">Mobile</var>
61+
<var name="stage">true</var>
62+
<!-- TODO: add button icons /-->
5663
<var name="conditions">
5764
<var name="max-width">768px</var>
5865
<var name="min-width">640px</var>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// /**
2+
// * Copyright © Magento, Inc. All rights reserved.
3+
// * See COPYING.txt for license details.
4+
// */
5+
6+
7+
.mobile-viewport {
8+
&.pagebuilder-stage-wrapper {
9+
&.stage-full-screen {
10+
.pagebuilder-stage {
11+
.pagebuilder-canvas {
12+
left: 50%;
13+
transform: translateX(-50%);
14+
width: 768px;
15+
}
16+
}
17+
}
18+
}
19+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,9 @@
9292
// _____________________________________________
9393

9494
@import '_template-manager.less';
95+
96+
//
97+
// Import Mobile viewport less
98+
// _____________________________________________
99+
100+
@import '_mobile-viewport.less';

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

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55
*/
66
-->
77
<div class="pagebuilder-stage-wrapper"
8-
css="'stage-full-screen': isFullScreen, 'stage-content-snapshot': isSnapshot, 'transition-out': isSnapshotTransition, 'stage-is-active': (!isSnapshot() || isFullScreen)"
8+
css="Object.assign(
9+
{'stage-full-screen': isFullScreen, 'stage-content-snapshot': isSnapshot, 'transition-out': isSnapshotTransition, 'stage-is-active': (!isSnapshot() || isFullScreen)},
10+
viewportClasses)"
911
ko-style="wrapperStyles">
1012
<div class="admin__field pagebuilder-header"
1113
css="visible: panel.isVisible(), 'transition-out': isSnapshotTransition()"
1214
if="!isSnapshot()">
15+
<each args="data: Object.keys(viewports), as: 'name'">
16+
<button type="button" translate="$parent.viewports[name].label" disable="name === $parent.viewport()" click="$parent.toggleViewport.bind($parent, name)"/>
17+
</each>
1318
<button type="button" translate="'Apply Template'" if="isAllowedTemplateApply" click="toggleTemplateManger"/>
1419
<button type="button" translate="'Save as Template'" if="isAllowedTemplateSave" click="saveAsTemplate"/>
1520
<i click="toggleFullScreen.bind($data, {animate:true})"

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export default class PageBuilder implements PageBuilderInterface {
3939
public stageStyles: KnockoutObservable<{[key: string]: string}> = ko.observable({});
4040
public isAllowedTemplateSave: boolean;
4141
public isAllowedTemplateApply: boolean;
42+
public defaultViewport: string;
43+
public viewport: KnockoutObservable<string> = ko.observable("");
44+
public viewports: {[key: string]: object} = {};
45+
public viewportClasses: {[key: string]: KnockoutObservable<boolean>} = {};
4246
private previousStyles: {[key: string]: string} = {};
4347
private previousPanelHeight: number;
4448
private snapshot: boolean;
@@ -48,6 +52,7 @@ export default class PageBuilder implements PageBuilderInterface {
4852
Config.setMode("Preview");
4953
this.preloadTemplates(config);
5054
this.initialValue = initialValue;
55+
this.initViewports(config);
5156
this.isFullScreen(config.isFullScreen);
5257
this.isSnapshot(!!config.pagebuilder_content_snapshot);
5358
this.isSnapshotTransition(false);
@@ -242,6 +247,20 @@ export default class PageBuilder implements PageBuilderInterface {
242247
return saveAsTemplate(this.stage);
243248
}
244249

250+
public toggleViewport(viewport: string) {
251+
const previousViewport = this.viewport();
252+
253+
this.viewport(viewport);
254+
events.trigger(`stage:${this.id}:viewportChangeAfter`, {
255+
viewport,
256+
previousViewport,
257+
});
258+
_.each(this.viewportClasses, (viewportClass) => {
259+
viewportClass(false);
260+
});
261+
this.viewportClasses[`${viewport}-viewport`](true);
262+
}
263+
245264
/**
246265
* Preload all templates into the window to reduce calls later in the app
247266
*
@@ -258,4 +277,19 @@ export default class PageBuilder implements PageBuilderInterface {
258277
require(previewTemplates);
259278
});
260279
}
280+
281+
private initViewports(config: any): void {
282+
_.each(config.viewports, (viewport: any, name: string) => {
283+
if (viewport.stage) {
284+
this.viewports[name] = viewport;
285+
}
286+
});
287+
this.defaultViewport = _.findKey(this.viewports, (viewport: any) => {
288+
return viewport.default;
289+
});
290+
this.viewport(this.defaultViewport);
291+
_.each(this.viewports, (viewport: {[key: string]: any}, name: string) => {
292+
this.viewportClasses[`${name}-viewport`] = ko.observable(name === this.defaultViewport);
293+
});
294+
}
261295
}

0 commit comments

Comments
 (0)