Introduce SettingsController for managing editor settings
[MAILPOET-5637]
This commit is contained in:
committed by
Aschepikov
parent
3e3e081dbf
commit
399ed61503
@@ -1,4 +1,5 @@
|
|||||||
import { State } from './types';
|
import { State } from './types';
|
||||||
|
import { getEditorSettings } from './settings';
|
||||||
|
|
||||||
export function getInitialState(): State {
|
export function getInitialState(): State {
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
@@ -11,15 +12,7 @@ export function getInitialState(): State {
|
|||||||
isOpened: false,
|
isOpened: false,
|
||||||
},
|
},
|
||||||
postId,
|
postId,
|
||||||
editorSettings: {
|
editorSettings: getEditorSettings(),
|
||||||
allowedBlockTypes: [
|
|
||||||
'core/paragraph',
|
|
||||||
'core/heading',
|
|
||||||
'core/column',
|
|
||||||
'core/columns',
|
|
||||||
'core/image',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
preview: {
|
preview: {
|
||||||
deviceType: 'Desktop',
|
deviceType: 'Desktop',
|
||||||
toEmail: window.MailPoetEmailEditor.current_wp_user_email,
|
toEmail: window.MailPoetEmailEditor.current_wp_user_email,
|
||||||
|
11
mailpoet/assets/js/src/email-editor/engine/store/settings.ts
Normal file
11
mailpoet/assets/js/src/email-editor/engine/store/settings.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { SETTINGS_DEFAULTS } from '@wordpress/block-editor';
|
||||||
|
import { EmailEditorSettings } from './types';
|
||||||
|
|
||||||
|
export function getEditorSettings(): EmailEditorSettings {
|
||||||
|
const settings = window.MailPoetEmailEditor
|
||||||
|
.editor_settings as EmailEditorSettings;
|
||||||
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
|
settings.__experimentalFeatures.color.palette.default =
|
||||||
|
SETTINGS_DEFAULTS.colors;
|
||||||
|
return settings;
|
||||||
|
}
|
@@ -1,8 +1,30 @@
|
|||||||
|
import { EditorSettings, EditorColor } from '@wordpress/block-editor';
|
||||||
|
|
||||||
export enum SendingPreviewStatus {
|
export enum SendingPreviewStatus {
|
||||||
SUCCESS = 'success',
|
SUCCESS = 'success',
|
||||||
ERROR = 'error',
|
ERROR = 'error',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ExperimentalSettings = {
|
||||||
|
__experimentalFeatures: {
|
||||||
|
color: {
|
||||||
|
custom: boolean;
|
||||||
|
text: boolean;
|
||||||
|
background: boolean;
|
||||||
|
customGradient: boolean;
|
||||||
|
defaultPalette: boolean;
|
||||||
|
palette: {
|
||||||
|
default: EditorColor[];
|
||||||
|
};
|
||||||
|
gradients: {
|
||||||
|
default: EditorColor[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EmailEditorSettings = EditorSettings & ExperimentalSettings;
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
inserterSidebar: {
|
inserterSidebar: {
|
||||||
isOpened: boolean;
|
isOpened: boolean;
|
||||||
@@ -11,9 +33,7 @@ export type State = {
|
|||||||
isOpened: boolean;
|
isOpened: boolean;
|
||||||
};
|
};
|
||||||
postId: number;
|
postId: number;
|
||||||
editorSettings: {
|
editorSettings: EmailEditorSettings;
|
||||||
allowedBlockTypes: string[];
|
|
||||||
};
|
|
||||||
preview: {
|
preview: {
|
||||||
deviceType: string;
|
deviceType: string;
|
||||||
toEmail: string;
|
toEmail: string;
|
||||||
|
@@ -4,5 +4,6 @@ interface Window {
|
|||||||
api_token: string;
|
api_token: string;
|
||||||
api_version: string;
|
api_version: string;
|
||||||
current_wp_user_email: string;
|
current_wp_user_email: string;
|
||||||
|
editor_settings: unknown; // Can't import type in global.d.ts. Typed in getEditorSettings() in store/settings.ts
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@ namespace MailPoet\AdminPages\Pages;
|
|||||||
|
|
||||||
use MailPoet\API\JSON\API;
|
use MailPoet\API\JSON\API;
|
||||||
use MailPoet\Config\Env;
|
use MailPoet\Config\Env;
|
||||||
|
use MailPoet\EmailEditor\Engine\SettingsController;
|
||||||
use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor as EditorInitController;
|
use MailPoet\EmailEditor\Integrations\MailPoet\EmailEditor as EditorInitController;
|
||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
@@ -11,10 +12,15 @@ class EmailEditor {
|
|||||||
/** @var WPFunctions */
|
/** @var WPFunctions */
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
|
/** @var SettingsController */
|
||||||
|
private $settingsController;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
WPFunctions $wp
|
WPFunctions $wp,
|
||||||
|
SettingsController $settingsController
|
||||||
) {
|
) {
|
||||||
$this->wp = $wp;
|
$this->wp = $wp;
|
||||||
|
$this->settingsController = $settingsController;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
@@ -51,6 +57,7 @@ class EmailEditor {
|
|||||||
'api_token' => esc_js($token),
|
'api_token' => esc_js($token),
|
||||||
'api_version' => esc_js($apiVersion),
|
'api_version' => esc_js($apiVersion),
|
||||||
'current_wp_user_email' => esc_js($currentUserEmail),
|
'current_wp_user_email' => esc_js($currentUserEmail),
|
||||||
|
'editor_settings' => $this->settingsController->getSettings(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -320,6 +320,7 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
// Email Editor
|
// Email Editor
|
||||||
$container->autowire(\MailPoet\EmailEditor\Engine\EmailEditor::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Engine\EmailEditor::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\EmailEditor\Engine\EmailApiController::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Engine\EmailApiController::class)->setPublic(true);
|
||||||
|
$container->autowire(\MailPoet\EmailEditor\Engine\SettingsController::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\Renderer::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\Renderer::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\BlocksRenderer::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\BlocksRenderer::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\BlocksRegistry::class)->setPublic(true);
|
$container->autowire(\MailPoet\EmailEditor\Engine\Renderer\BlocksRegistry::class)->setPublic(true);
|
||||||
|
49
mailpoet/lib/EmailEditor/Engine/SettingsController.php
Normal file
49
mailpoet/lib/EmailEditor/Engine/SettingsController.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php declare(strict_types = 1);
|
||||||
|
|
||||||
|
namespace MailPoet\EmailEditor\Engine;
|
||||||
|
|
||||||
|
class SettingsController {
|
||||||
|
|
||||||
|
const ALLOWED_BLOCK_TYPES = [
|
||||||
|
'core/paragraph',
|
||||||
|
'core/heading',
|
||||||
|
'core/column',
|
||||||
|
'core/columns',
|
||||||
|
'core/image',
|
||||||
|
];
|
||||||
|
|
||||||
|
const DEFAULT_SETTINGS = [
|
||||||
|
'enableCustomSpacing' => true,
|
||||||
|
'enableCustomLineHeight' => true,
|
||||||
|
'disableCustomFontSizes' => false,
|
||||||
|
'enableCustomUnits' => ['px', '%'],
|
||||||
|
'__experimentalFeatures' => [
|
||||||
|
'color' => [
|
||||||
|
'custom' => true,
|
||||||
|
'text' => true,
|
||||||
|
'background' => true,
|
||||||
|
'customGradient' => false,
|
||||||
|
'defaultPalette' => true,
|
||||||
|
'palette' => [
|
||||||
|
'default' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var StylesController */
|
||||||
|
private $stylesController;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
StylesController $stylesController
|
||||||
|
) {
|
||||||
|
$this->stylesController = $stylesController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSettings(): array {
|
||||||
|
$settings = self::DEFAULT_SETTINGS;
|
||||||
|
$settings['allowedBlockTypes'] = self::ALLOWED_BLOCK_TYPES;
|
||||||
|
$settings['defaultEditorStyles'] = [[ 'css' => $this->stylesController->getEmailContentStyles() ]];
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user