Remove fonts duplication
[MAILPOET-2849]
This commit is contained in:
@ -2,73 +2,9 @@ import React from 'react';
|
|||||||
import {
|
import {
|
||||||
CustomSelectControl,
|
CustomSelectControl,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
|
import { useSelect } from '@wordpress/data';
|
||||||
import MailPoet from 'mailpoet';
|
import MailPoet from 'mailpoet';
|
||||||
|
|
||||||
export const customFonts = [
|
|
||||||
'Abril FatFace',
|
|
||||||
'Alegreya',
|
|
||||||
'Alegreya Sans',
|
|
||||||
'Amatic SC',
|
|
||||||
'Anonymous Pro',
|
|
||||||
'Architects Daughter',
|
|
||||||
'Archivo',
|
|
||||||
'Archivo Narrow',
|
|
||||||
'Asap',
|
|
||||||
'Barlow',
|
|
||||||
'BioRhyme',
|
|
||||||
'Bonbon',
|
|
||||||
'Cabin',
|
|
||||||
'Cairo',
|
|
||||||
'Cardo',
|
|
||||||
'Chivo',
|
|
||||||
'Concert One',
|
|
||||||
'Cormorant',
|
|
||||||
'Crimson Text',
|
|
||||||
'Eczar',
|
|
||||||
'Exo 2',
|
|
||||||
'Fira Sans',
|
|
||||||
'Fjalla One',
|
|
||||||
'Frank Ruhl Libre',
|
|
||||||
'Great Vibes',
|
|
||||||
'Heebo',
|
|
||||||
'IBM Plex',
|
|
||||||
'Inconsolata',
|
|
||||||
'Indie Flower',
|
|
||||||
'Inknut Antiqua',
|
|
||||||
'Inter',
|
|
||||||
'Karla',
|
|
||||||
'Libre Baskerville',
|
|
||||||
'Libre Franklin',
|
|
||||||
'Montserrat',
|
|
||||||
'Neuton',
|
|
||||||
'Notable',
|
|
||||||
'Nothing You Could Do',
|
|
||||||
'Noto Sans',
|
|
||||||
'Nunito',
|
|
||||||
'Old Standard TT',
|
|
||||||
'Oxygen',
|
|
||||||
'Pacifico',
|
|
||||||
'Poppins',
|
|
||||||
'Proza Libre',
|
|
||||||
'PT Sans',
|
|
||||||
'PT Serif',
|
|
||||||
'Rakkas',
|
|
||||||
'Reenie Beanie',
|
|
||||||
'Roboto Slab',
|
|
||||||
'Ropa Sans',
|
|
||||||
'Rubik',
|
|
||||||
'Shadows Into Light',
|
|
||||||
'Space Mono',
|
|
||||||
'Spectral',
|
|
||||||
'Sue Ellen Francisco',
|
|
||||||
'Titillium Web',
|
|
||||||
'Ubuntu',
|
|
||||||
'Varela',
|
|
||||||
'Vollkorn',
|
|
||||||
'Work Sans',
|
|
||||||
'Yatra One',
|
|
||||||
];
|
|
||||||
|
|
||||||
const standardFonts = [
|
const standardFonts = [
|
||||||
'Arial',
|
'Arial',
|
||||||
'Comic Sans MS',
|
'Comic Sans MS',
|
||||||
@ -92,6 +28,10 @@ const FontFamilySettings = ({
|
|||||||
value,
|
value,
|
||||||
name,
|
name,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
|
const customFonts = useSelect(
|
||||||
|
(select) => select('mailpoet-form-editor').getAllCustomFonts(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
const disabledStyle = {
|
const disabledStyle = {
|
||||||
color: 'lightgray',
|
color: 'lightgray',
|
||||||
backgroundColor: 'white',
|
backgroundColor: 'white',
|
||||||
@ -155,14 +95,19 @@ const FontFamilySettings = ({
|
|||||||
|
|
||||||
export default FontFamilySettings;
|
export default FontFamilySettings;
|
||||||
|
|
||||||
const customFontsUrl = customFonts
|
export const CustomFontsStyleSheetLink = () => {
|
||||||
.map((fontName) => fontName.replace(' ', '+'))
|
const customFonts = useSelect(
|
||||||
.map((fontName) => fontName.concat(':400,400i,700,700'))
|
(select) => select('mailpoet-form-editor').getAllCustomFonts(),
|
||||||
.join('|');
|
[]
|
||||||
|
);
|
||||||
export const CustomFontsStyleSheetLink = () => (
|
const customFontsUrl = customFonts
|
||||||
<link
|
.map((fontName) => fontName.replace(' ', '+'))
|
||||||
rel="stylesheet"
|
.map((fontName) => fontName.concat(':400,400i,700,700'))
|
||||||
href={`https://fonts.googleapis.com/css?family=${customFontsUrl}`}
|
.join('|');
|
||||||
/>
|
return (
|
||||||
);
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href={`https://fonts.googleapis.com/css?family=${customFontsUrl}`}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -116,6 +116,9 @@ export default {
|
|||||||
getPreviewPageUrl(state) {
|
getPreviewPageUrl(state) {
|
||||||
return state.previewPageUrl;
|
return state.previewPageUrl;
|
||||||
},
|
},
|
||||||
|
getAllCustomFonts(state) {
|
||||||
|
return state.customFonts;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Goes thru all parents of the block and return
|
* Goes thru all parents of the block and return
|
||||||
|
@ -61,6 +61,7 @@ export default () => {
|
|||||||
previewSettings,
|
previewSettings,
|
||||||
editorUrl: window.location.href,
|
editorUrl: window.location.href,
|
||||||
previewPageUrl: window.mailpoet_form_preview_page,
|
previewPageUrl: window.mailpoet_form_preview_page,
|
||||||
|
customFonts: window.mailpoet_custom_fonts,
|
||||||
};
|
};
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -8,6 +8,7 @@ use MailPoet\CustomFields\CustomFieldsRepository;
|
|||||||
use MailPoet\Form\Block;
|
use MailPoet\Form\Block;
|
||||||
use MailPoet\Form\FormFactory;
|
use MailPoet\Form\FormFactory;
|
||||||
use MailPoet\Form\Renderer as FormRenderer;
|
use MailPoet\Form\Renderer as FormRenderer;
|
||||||
|
use MailPoet\Form\Util\CustomFonts;
|
||||||
use MailPoet\Form\Util\Export;
|
use MailPoet\Form\Util\Export;
|
||||||
use MailPoet\Models\Form;
|
use MailPoet\Models\Form;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
@ -35,9 +36,7 @@ class FormEditor {
|
|||||||
/** @var WPFunctions */
|
/** @var WPFunctions */
|
||||||
private $wp;
|
private $wp;
|
||||||
|
|
||||||
/**
|
/** @var FormFactory */
|
||||||
* @var FormFactory
|
|
||||||
*/
|
|
||||||
private $formsFactory;
|
private $formsFactory;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@ -98,6 +97,7 @@ class FormEditor {
|
|||||||
'sub_menu' => 'mailpoet-forms',
|
'sub_menu' => 'mailpoet-forms',
|
||||||
'custom_fields' => $this->customFieldsResponseBuilder->buildBatch($customFields),
|
'custom_fields' => $this->customFieldsResponseBuilder->buildBatch($customFields),
|
||||||
'preview_page_url' => $this->getPreviewPageUrl(),
|
'preview_page_url' => $this->getPreviewPageUrl(),
|
||||||
|
'custom_fonts' => CustomFonts::FONTS,
|
||||||
];
|
];
|
||||||
$this->wp->wpEnqueueMedia();
|
$this->wp->wpEnqueueMedia();
|
||||||
$this->pageRenderer->displayPage('form/editor.html', $data);
|
$this->pageRenderer->displayPage('form/editor.html', $data);
|
||||||
|
@ -5,7 +5,7 @@ namespace MailPoet\Form\Util;
|
|||||||
use MailPoet\WP\Functions;
|
use MailPoet\WP\Functions;
|
||||||
|
|
||||||
class CustomFonts {
|
class CustomFonts {
|
||||||
const fonts = [
|
const FONTS = [
|
||||||
'Abril FatFace',
|
'Abril FatFace',
|
||||||
'Alegreya',
|
'Alegreya',
|
||||||
'Alegreya Sans',
|
'Alegreya Sans',
|
||||||
@ -81,10 +81,10 @@ class CustomFonts {
|
|||||||
$this->wp->wpEnqueueStyle('mailpoet_custom_fonts_css', $this->generateLink());
|
$this->wp->wpEnqueueStyle('mailpoet_custom_fonts_css', $this->generateLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateLink():string {
|
private function generateLink(): string {
|
||||||
$fonts = array_map(function ($fontName) {
|
$fonts = array_map(function ($fontName) {
|
||||||
return urlencode($fontName) . ':400,400i,700,700i';
|
return urlencode($fontName) . ':400,400i,700,700i';
|
||||||
}, self::fonts);
|
}, self::FONTS);
|
||||||
$fonts = implode('|', $fonts);
|
$fonts = implode('|', $fonts);
|
||||||
return 'https://fonts.googleapis.com/css?family=' . $fonts;
|
return 'https://fonts.googleapis.com/css?family=' . $fonts;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
var mailpoet_date_formats = <%= json_encode(date_formats) %>;
|
var mailpoet_date_formats = <%= json_encode(date_formats) %>;
|
||||||
var mailpoet_month_names = <%= json_encode(month_names) %>;
|
var mailpoet_month_names = <%= json_encode(month_names) %>;
|
||||||
var mailpoet_form_preview_page = <%= json_encode(preview_page_url) %>;
|
var mailpoet_form_preview_page = <%= json_encode(preview_page_url) %>;
|
||||||
|
var mailpoet_custom_fonts = <%= json_encode(custom_fonts) %>;
|
||||||
<% endautoescape %>
|
<% endautoescape %>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user