From 63cc719be06bc91d1d5796eb7cc50441216ed35f Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 8 Nov 2018 09:03:26 +0100 Subject: [PATCH] Format library: Allow explicit registration when using npm packages --- lib/client-assets.php | 5 ++++ packages/format-library/src/index.js | 38 ++++++++++++++++++---------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index 3cdfda9619901f..423539c10b5f30 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -544,6 +544,11 @@ function gutenberg_register_scripts_and_styles() { filemtime( gutenberg_dir_path() . 'build/format-library/index.js' ), true ); + wp_add_inline_script( + 'wp-format-library', + 'wp.formatLibrary.registerCoreFormatTypes();', + 'after' + ); gutenberg_override_script( 'wp-nux', gutenberg_url( 'build/nux/index.js' ), diff --git a/packages/format-library/src/index.js b/packages/format-library/src/index.js index 387c2666f7e0e6..21ce2fec9f71c1 100644 --- a/packages/format-library/src/index.js +++ b/packages/format-library/src/index.js @@ -1,3 +1,10 @@ +/** + * WordPress dependencies + */ +import { + registerFormatType, +} from '@wordpress/rich-text'; + /** * Internal dependencies */ @@ -8,18 +15,21 @@ import { italic } from './italic'; import { link } from './link'; import { strikethrough } from './strikethrough'; -/** - * WordPress dependencies - */ -import { - registerFormatType, -} from '@wordpress/rich-text'; +export function getCoreFormatTypes() { + return [ + bold, + code, + image, + italic, + link, + strikethrough, + ].map( + ( { name, ...settings } ) => [ name, settings ] + ); +} -[ - bold, - code, - image, - italic, - link, - strikethrough, -].forEach( ( { name, ...settings } ) => registerFormatType( name, settings ) ); +export function registerCoreFormatTypes() { + getCoreFormatTypes().forEach( + ( params ) => registerFormatType( ...params ) + ); +}