From e687dc5acdc2f8a4806d6973cff0cfb9e330719b Mon Sep 17 00:00:00 2001 From: Nikita Date: Thu, 8 Feb 2024 10:48:50 +0300 Subject: [PATCH] fixed rare problem when extensions resets after block transformation from deprecated version --- gutenberg/extend/deprecated/index.js | 90 ++++++++++++---------------- gutenberg/extend/index.js | 30 +++------- 2 files changed, 47 insertions(+), 73 deletions(-) diff --git a/gutenberg/extend/deprecated/index.js b/gutenberg/extend/deprecated/index.js index 4ceb5619..b1644024 100644 --- a/gutenberg/extend/deprecated/index.js +++ b/gutenberg/extend/deprecated/index.js @@ -77,58 +77,46 @@ const withInspectorControl = createHigherOrderComponent( * @return {Object} Filtered block settings. */ function addAttribute(blockSettings) { - // prepare settings of block + deprecated blocks. - const eachSettings = [blockSettings]; - if (blockSettings.deprecated && blockSettings.deprecated.length) { - blockSettings.deprecated.forEach((item) => { - eachSettings.push(item); - }); + if (!blockSettings.attributes.ghostkitId) { + blockSettings.attributes.ghostkitId = { + type: 'string', + }; + } + if (!blockSettings.attributes.ghostkitClassname) { + blockSettings.attributes.ghostkitClassname = { + type: 'string', + }; + } + if (!blockSettings.attributes.ghostkitStyles) { + blockSettings.attributes.ghostkitStyles = { + type: 'object', + }; + } + if (!blockSettings.attributes.ghostkitSR) { + blockSettings.attributes.ghostkitSR = { + type: 'string', + }; + } + if (!blockSettings.attributes.ghostkitCustomCSS) { + blockSettings.attributes.ghostkitCustomCSS = { + type: 'string', + }; + } + if (!blockSettings.attributes.ghostkitPosition) { + blockSettings.attributes.ghostkitPosition = { + type: 'object', + }; + } + if (!blockSettings.attributes.ghostkitSpacings) { + blockSettings.attributes.ghostkitSpacings = { + type: 'object', + }; + } + if (!blockSettings.attributes.ghostkitFrame) { + blockSettings.attributes.ghostkitFrame = { + type: 'object', + }; } - - eachSettings.forEach((settings) => { - if (settings.attributes) { - if (!settings.attributes.ghostkitId) { - settings.attributes.ghostkitId = { - type: 'string', - }; - } - if (!settings.attributes.ghostkitClassname) { - settings.attributes.ghostkitClassname = { - type: 'string', - }; - } - if (!settings.attributes.ghostkitStyles) { - settings.attributes.ghostkitStyles = { - type: 'object', - }; - } - if (!settings.attributes.ghostkitSR) { - settings.attributes.ghostkitSR = { - type: 'string', - }; - } - if (!settings.attributes.ghostkitCustomCSS) { - settings.attributes.ghostkitCustomCSS = { - type: 'string', - }; - } - if (!settings.attributes.ghostkitPosition) { - settings.attributes.ghostkitPosition = { - type: 'object', - }; - } - if (!settings.attributes.ghostkitSpacings) { - settings.attributes.ghostkitSpacings = { - type: 'object', - }; - } - if (!settings.attributes.ghostkitFrame) { - settings.attributes.ghostkitFrame = { - type: 'object', - }; - } - } - }); return blockSettings; } diff --git a/gutenberg/extend/index.js b/gutenberg/extend/index.js index 4cf78ddb..25f7a5ac 100644 --- a/gutenberg/extend/index.js +++ b/gutenberg/extend/index.js @@ -66,33 +66,19 @@ const withGhostKitExtensions = createHigherOrderComponent( * Add `ghostkit` attribute to deprecated blocks settings. * * @param {Object} blockSettings Original block settings. - * @param {string} name Original block name. * * @return {Object} Filtered block settings. */ -function addAttribute(blockSettings, name) { - if (!hasBlockSupport(name, 'ghostkit')) { - return blockSettings; +function addAttribute(blockSettings) { + // Add attribute to All blocks. + // Previously we used hasBlockSupport function, but it's not working correctly for all blocks + // and leads to issues with blocks that are not registered yet (probably in deprecated block variations). + if (blockSettings.attributes && !blockSettings.attributes.ghostkit) { + blockSettings.attributes.ghostkit = { + type: 'object', + }; } - // prepare settings of block + deprecated blocks. - const eachSettings = [blockSettings]; - if (blockSettings.deprecated && blockSettings.deprecated.length) { - blockSettings.deprecated.forEach((item) => { - eachSettings.push(item); - }); - } - - eachSettings.forEach((settings) => { - if (settings.attributes) { - if (!settings.attributes.ghostkit) { - settings.attributes.ghostkit = { - type: 'object', - }; - } - } - }); - return blockSettings; }