Skip to content

Commit

Permalink
fixed rare problem when extensions resets after block transformation …
Browse files Browse the repository at this point in the history
…from deprecated version
  • Loading branch information
nk-o committed Feb 8, 2024
1 parent 7d4b336 commit e687dc5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 73 deletions.
90 changes: 39 additions & 51 deletions gutenberg/extend/deprecated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
30 changes: 8 additions & 22 deletions gutenberg/extend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit e687dc5

Please sign in to comment.