diff --git a/src/js/editor.js b/src/js/editor.js index 19d982b..f987539 100644 --- a/src/js/editor.js +++ b/src/js/editor.js @@ -11,6 +11,41 @@ import { import { dispatch } from '@wordpress/data'; import domReady from '@wordpress/dom-ready'; +/** + * Register block styles + * + * @type {Object} Add the names of blocks and styles to register here + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/ + */ +const registerBlockStyles = { + // "core/cover": [ + // { + // name: "hero", + // label: "Hero", + // }, + // ] +}; + +/** + * Register block variations + * + * @type {Object} Add the names of blocks and variations to register here + * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/ + */ +const registerBlockVariations = { + // "core/columns": { + // name: "three-columns-wide-left", + // title: "50 / 25 / 25", + // description: "Three columns; wide left column", + // innerBlocks: [ + // ["core/column", { width: "50%" }], + // ["core/column", { width: "25%" }], + // ["core/column", { width: "25%" }], + // ], + // scope: ["block"], + // }, +}; + /** * Unregister blocks * @@ -41,21 +76,6 @@ const unregisterBlockStyles = { // "core/button": "outline", }; -/** - * Register block styles - * - * @type {Object} Add the names of blocks and styles to register here - * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/ - */ -const registerBlockStyles = { - // "core/cover": [ - // { - // name: "hero", - // label: "Hero", - // }, - // ] -}; - /** * Remove block variations * @@ -66,32 +86,18 @@ const unregisterBlockVariations = { // "core/columns": "two-columns-two-thirds-one-third", }; -/** - * Register block variations - * - * @type {Object} Add the names of blocks and variations to register here - * @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/ - */ -const registerBlockVariations = { - // "core/columns": { - // name: "three-columns-wide-left", - // title: "50 / 25 / 25", - // description: "Three columns; wide left column", - // innerBlocks: [ - // ["core/column", { width: "50%" }], - // ["core/column", { width: "25%" }], - // ["core/column", { width: "25%" }], - // ], - // scope: ["block"], - // }, -}; - /** * Here we hook into the editor initialization and unregister the blocks, * remove editor panels, remove block styles, remove block variations, * register block styles, and register block variations – all as defined above. */ domReady( function () { + Object.keys( registerBlockStyles ).forEach( ( block ) => { + registerBlockStyle( block, registerBlockStyles[ block ] ); + } ); + Object.keys( registerBlockVariations ).forEach( ( block ) => { + registerBlockVariation( block, registerBlockVariations[ block ] ); + } ); unregisterBlocks.forEach( ( block ) => { unregisterBlockType( block ); } ); @@ -109,10 +115,4 @@ domReady( function () { Object.keys( unregisterBlockVariations ).forEach( ( block ) => { unregisterBlockVariation( block, unregisterBlockVariations[ block ] ); } ); - Object.keys( registerBlockStyles ).forEach( ( block ) => { - registerBlockStyle( block, registerBlockStyles[ block ] ); - } ); - Object.keys( registerBlockVariations ).forEach( ( block ) => { - registerBlockVariation( block, registerBlockVariations[ block ] ); - } ); } );