Get rid of duplicate CSS for template preview
We can reuse the same CSS we pass to editor [MAILPOET-6249]
This commit is contained in:
committed by
Jan Lysý
parent
b6d75410cf
commit
324fedecbf
@@ -2,19 +2,23 @@
|
||||
|
||||
namespace MailPoet\EmailEditor\Engine\Templates;
|
||||
|
||||
use MailPoet\EmailEditor\Engine\SettingsController;
|
||||
use MailPoet\EmailEditor\Engine\ThemeController;
|
||||
use MailPoet\EmailEditor\Validator\Builder;
|
||||
use WP_Theme_JSON;
|
||||
|
||||
class TemplatePreview {
|
||||
private ThemeController $themeController;
|
||||
private SettingsController $settingsController;
|
||||
private Templates $templates;
|
||||
|
||||
public function __construct(
|
||||
ThemeController $themeController,
|
||||
SettingsController $settingsController,
|
||||
Templates $templates
|
||||
) {
|
||||
$this->themeController = $themeController;
|
||||
$this->settingsController = $settingsController;
|
||||
$this->templates = $templates;
|
||||
}
|
||||
|
||||
@@ -40,7 +44,11 @@ class TemplatePreview {
|
||||
if (is_array($templateTheme)) {
|
||||
$editorTheme->merge(new WP_Theme_JSON($templateTheme, 'custom'));
|
||||
}
|
||||
$additionalCSS = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'preview.css');
|
||||
$editorSettings = $this->settingsController->getSettings();
|
||||
$additionalCSS = '';
|
||||
foreach ($editorSettings['styles'] as $style) {
|
||||
$additionalCSS .= $style['css'];
|
||||
}
|
||||
// Set proper content width for previews
|
||||
$layoutSettings = $this->themeController->getLayoutSettings();
|
||||
$additionalCSS .= ".is-root-container { width: {$layoutSettings['contentSize']}; margin: 0 auto; }";
|
||||
|
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* This file contains additional CSS for template previews.
|
||||
* It is loaded in the iframe that displays the preview in select modal.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Alignment CSS - In theme CSS these are prefixed by a layout class
|
||||
* Alignment rules are copied from the CSS generated from theme from class .wp-site-blocks
|
||||
*/
|
||||
.block-editor-block-preview__content-iframe .aligncenter {
|
||||
justify-content: center;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.block-editor-block-preview__content-iframe .alignleft {
|
||||
float: left;
|
||||
margin-right: 2em;
|
||||
}
|
||||
|
||||
.block-editor-block-preview__content-iframe .alignright {
|
||||
float: right;
|
||||
margin-left: 2em;
|
||||
}
|
@@ -109,6 +109,7 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
|
||||
$container->set(TemplatePreview::class, function ($container) {
|
||||
return new TemplatePreview(
|
||||
$container->get(ThemeController::class),
|
||||
$container->get(SettingsController::class),
|
||||
$container->get(Templates::class),
|
||||
);
|
||||
});
|
||||
|
Reference in New Issue
Block a user