From 796d25c34cdf26d1dd788eb174b18a1b282770d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 1 Sep 2021 12:49:18 +0200 Subject: [PATCH] Blocks: Register block when invalid value provided for the icon (#34350) * Blocks: Register block when invalid value provided for the icon * Include an entry in the package changelog --- package-lock.json | 1 - packages/blocks/CHANGELOG.md | 4 ++ packages/blocks/package.json | 1 - packages/blocks/src/api/constants.js | 2 + packages/blocks/src/api/registration.js | 5 +- packages/blocks/src/api/test/registration.js | 57 ++++++-------------- packages/blocks/src/api/utils.js | 2 + 7 files changed, 25 insertions(+), 47 deletions(-) diff --git a/package-lock.json b/package-lock.json index 691657bafb2674..d4899cfca2fa11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18106,7 +18106,6 @@ "@wordpress/hooks": "file:packages/hooks", "@wordpress/html-entities": "file:packages/html-entities", "@wordpress/i18n": "file:packages/i18n", - "@wordpress/icons": "file:packages/icons", "@wordpress/is-shallow-equal": "file:packages/is-shallow-equal", "@wordpress/shortcode": "file:packages/shortcode", "hpq": "^1.3.0", diff --git a/packages/blocks/CHANGELOG.md b/packages/blocks/CHANGELOG.md index 79f2d8aaee2714..b51c240a069ea1 100644 --- a/packages/blocks/CHANGELOG.md +++ b/packages/blocks/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Backward Compatibility + +- Register a block even when an invalid value provided for the icon setting ([#34350](https://github.com/WordPress/gutenberg/pull/34350)). + ## 11.0.0 (2021-07-29) ### Breaking Change diff --git a/packages/blocks/package.json b/packages/blocks/package.json index 8741fb317c907e..e7c759dbe59137 100644 --- a/packages/blocks/package.json +++ b/packages/blocks/package.json @@ -40,7 +40,6 @@ "@wordpress/hooks": "file:../hooks", "@wordpress/html-entities": "file:../html-entities", "@wordpress/i18n": "file:../i18n", - "@wordpress/icons": "file:../icons", "@wordpress/is-shallow-equal": "file:../is-shallow-equal", "@wordpress/shortcode": "file:../shortcode", "hpq": "^1.3.0", diff --git a/packages/blocks/src/api/constants.js b/packages/blocks/src/api/constants.js index d7ce7cafd25261..5564b339ec4a41 100644 --- a/packages/blocks/src/api/constants.js +++ b/packages/blocks/src/api/constants.js @@ -1,3 +1,5 @@ +export const BLOCK_ICON_DEFAULT = 'block-default'; + /** * Array of valid keys in a block type settings deprecation object. * diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index bd400e148a6ebe..09033b2ef4beb8 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -25,14 +25,13 @@ import { import { applyFilters } from '@wordpress/hooks'; import { select, dispatch } from '@wordpress/data'; import { _x } from '@wordpress/i18n'; -import { blockDefault } from '@wordpress/icons'; /** * Internal dependencies */ import i18nBlockSchema from './i18n-block.json'; import { isValidIcon, normalizeIconObject } from './utils'; -import { DEPRECATED_ENTRY_KEYS } from './constants'; +import { BLOCK_ICON_DEFAULT, DEPRECATED_ENTRY_KEYS } from './constants'; import { store as blocksStore } from '../store'; /** @@ -265,7 +264,7 @@ export function registerBlockType( blockNameOrMetadata, settings ) { settings = { name, - icon: blockDefault, + icon: BLOCK_ICON_DEFAULT, keywords: [], attributes: {}, providesContext: {}, diff --git a/packages/blocks/src/api/test/registration.js b/packages/blocks/src/api/test/registration.js index 49851544dd5ae2..4b3d2864a0b229 100644 --- a/packages/blocks/src/api/test/registration.js +++ b/packages/blocks/src/api/test/registration.js @@ -10,7 +10,6 @@ import { noop, get, omit, pick } from 'lodash'; */ import { addFilter, removeAllFilters, removeFilter } from '@wordpress/hooks'; import { select } from '@wordpress/data'; -import { blockDefault as blockIcon } from '@wordpress/icons'; /** * Internal dependencies @@ -36,7 +35,7 @@ import { serverSideBlockDefinitions, unstable__bootstrapServerSideBlockDefinitions, // eslint-disable-line camelcase } from '../registration'; -import { DEPRECATED_ENTRY_KEYS } from '../constants'; +import { BLOCK_ICON_DEFAULT, DEPRECATED_ENTRY_KEYS } from '../constants'; import { store as blocksStore } from '../../store'; describe( 'blocks', () => { @@ -121,9 +120,7 @@ describe( 'blocks', () => { expect( console ).not.toHaveErrored(); expect( block ).toEqual( { name: 'my-plugin/fancy-block-4', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -268,9 +265,7 @@ describe( 'blocks', () => { name: 'core/test-block-with-defaults', title: 'block title', category: 'text', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -301,9 +296,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: { ok: { type: 'boolean', @@ -338,9 +331,7 @@ describe( 'blocks', () => { name: blockName, save: expect.any( Function ), title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -371,9 +362,7 @@ describe( 'blocks', () => { name: blockName, save: expect.any( Function ), title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: { fontSize: 'fontSize', @@ -410,9 +399,7 @@ describe( 'blocks', () => { save: expect.any( Function ), title: 'block title', category: 'widgets', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -636,9 +623,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -723,7 +708,7 @@ describe( 'blocks', () => { ...omit( { name, - icon: blockIcon, + icon: BLOCK_ICON_DEFAULT, attributes: {}, providesContext: {}, usesContext: [], @@ -960,9 +945,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -979,9 +962,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -1059,9 +1040,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -1085,9 +1064,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -1118,9 +1095,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], @@ -1135,9 +1110,7 @@ describe( 'blocks', () => { save: noop, category: 'text', title: 'block title', - icon: { - src: blockIcon, - }, + icon: { src: BLOCK_ICON_DEFAULT }, attributes: {}, providesContext: {}, usesContext: [], diff --git a/packages/blocks/src/api/utils.js b/packages/blocks/src/api/utils.js index d6b588668b0edd..653676a85fd70a 100644 --- a/packages/blocks/src/api/utils.js +++ b/packages/blocks/src/api/utils.js @@ -14,6 +14,7 @@ import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; /** * Internal dependencies */ +import { BLOCK_ICON_DEFAULT } from './constants'; import { getBlockType, getDefaultBlockName } from './registration'; import { createBlock } from './factory'; @@ -89,6 +90,7 @@ export function isValidIcon( icon ) { * @return {WPBlockTypeIconDescriptor} Object describing the icon. */ export function normalizeIconObject( icon ) { + icon = icon || BLOCK_ICON_DEFAULT; if ( isValidIcon( icon ) ) { return { src: icon }; }