From 241d5d6d16593c047ddbe03788334b9e0a9ff048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Thibaud?= Date: Thu, 2 Sep 2021 15:34:19 +0200 Subject: [PATCH] #164 feat (blocks) : JS method to deregister embed blocks + core blocks variations --- config/entries.js | 2 +- inc/Services/Assets.php | 10 +-- src/js/editor-script.js | 85 +++++++++++++++++++++ src/js/editor.js | 23 ------ src/scss/{editor.scss => editor-style.scss} | 0 5 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 src/js/editor-script.js delete mode 100644 src/js/editor.js rename src/scss/{editor.scss => editor-style.scss} (100%) diff --git a/config/entries.js b/config/entries.js index 142f37c0..3cb61c5b 100644 --- a/config/entries.js +++ b/config/entries.js @@ -1,4 +1,4 @@ module.exports = { app: ['./src/js/index.js', './src/scss/style.scss'], - editor: ['./src/js/editor.js', './src/scss/editor.scss'], + editor: ['./src/js/editor-script.js', './src/scss/editor-style.scss'], } diff --git a/inc/Services/Assets.php b/inc/Services/Assets.php index a6fabfed..dcf4009a 100644 --- a/inc/Services/Assets.php +++ b/inc/Services/Assets.php @@ -64,7 +64,7 @@ public function register_assets(): void { \wp_register_script( 'global-polyfill', 'https://cdn.polyfill.io/v3/polyfill.min.js?features=es5,es6,fetch,Array.prototype.includes,CustomEvent,Element.prototype.closest,NodeList.prototype.forEach', null, null, true ); //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion // Async and footer - $file = ( ! defined( 'SCRIPT_DEBUG' ) || SCRIPT_DEBUG === false ) ? $this->get_min_file( 'js' ) : 'app.js'; + $file = ( ! defined( 'SCRIPT_DEBUG' ) || SCRIPT_DEBUG === false ) ? $this->get_min_file( 'js' ) : 'index.js'; $this->assets_tools->register_script( 'scripts', 'dist/' . $file, $scripts_dependencies, $theme->get( 'Version' ), true ); // CSS @@ -138,14 +138,14 @@ public function get_min_file( string $type ): string { $file = $assets['app.css']; break; case 'editor-style': - $file = $assets['editor-style.css']; - break; - case 'admin-editor-script': - $file = $assets['gutenberg-editor.js']; + $file = $assets['editor.css']; break; case 'js': $file = $assets['app.js']; break; + case 'editor-script': + $file = $assets['editor.js']; + break; default: $file = null; break; diff --git a/src/js/editor-script.js b/src/js/editor-script.js new file mode 100644 index 00000000..76b6acde --- /dev/null +++ b/src/js/editor-script.js @@ -0,0 +1,85 @@ +import lazySizes from 'lazysizes' +import 'lazysizes/plugins/native-loading/ls.native-loading' +import 'lazysizes/plugins/object-fit/ls.object-fit' + +/** + * LazySizes configuration + * https://github.com/aFarkas/lazysizes/#js-api---options + */ +lazySizes.cfg.nativeLoading = { + setLoadingAttribute: false, +} + +// Native Gutenberg +if (typeof wp !== 'undefined') { + wp.domReady(() => { + // Disable block styles + + // block image + // wp.blocks.unregisterBlockStyle('core/image', 'rounded') + // wp.blocks.unregisterBlockStyle('core/image', 'default') + + // block quote + // wp.blocks.unregisterBlockStyle('core/quote', 'default') + // wp.blocks.unregisterBlockStyle('core/quote', 'large') + + // block pullquote + // wp.blocks.unregisterBlockStyle('core/pullquote', 'default') + // wp.blocks.unregisterBlockStyle('core/pullquote', 'solid-color') + + // block separator + // wp.blocks.unregisterBlockStyle('core/separator', 'default') + // wp.blocks.unregisterBlockStyle('core/separator', 'wide') + // wp.blocks.unregisterBlockStyle('core/separator', 'dots') + + // block table + // wp.blocks.unregisterBlockStyle('core/table', 'regular') + // wp.blocks.unregisterBlockStyle('core/table', 'stripes') + + // Disable core embed blocks + + var embedVariations = [ + 'amazon-kindle', + 'animoto', + 'cloudup', + 'collegehumor', + 'crowdsignal', + 'dailymotion', + 'facebook', + 'flickr', + 'imgur', + 'instagram', + 'issuu', + 'kickstarter', + 'meetup-com', + 'mixcloud', + 'reddit', + 'reverbnation', + 'screencast', + 'scribd', + 'slideshare', + 'smugmug', + 'soundcloud', + 'speaker-deck', + 'spotify', + 'ted', + 'tiktok', + 'tumblr', + 'twitter', + 'videopress', + 'vimeo', + 'wordpress', + 'wordpress-tv', + // 'youtube' + ] + + for (var i = embedVariations.length - 1; i >= 0; i--) { + wp.blocks.unregisterBlockVariation('core/embed', embedVariations[i]) + } + }) +} + +// ACF Blocks +if (window.acf) { + // Do stuff +} diff --git a/src/js/editor.js b/src/js/editor.js deleted file mode 100644 index 94b05e5f..00000000 --- a/src/js/editor.js +++ /dev/null @@ -1,23 +0,0 @@ -import lazySizes from 'lazysizes' -import 'lazysizes/plugins/native-loading/ls.native-loading' -import 'lazysizes/plugins/object-fit/ls.object-fit' - -/** - * LazySizes configuration - * https://github.com/aFarkas/lazysizes/#js-api---options - */ -lazySizes.cfg.nativeLoading = { - setLoadingAttribute: false, -} - -// Native Gutenberg -if (typeof wp !== 'undefined') { - wp.domReady(() => { - // Do stuff - }) -} - -// ACF Blocks -if (window.acf) { - // Do stuff -} diff --git a/src/scss/editor.scss b/src/scss/editor-style.scss similarity index 100% rename from src/scss/editor.scss rename to src/scss/editor-style.scss