Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize the Experimental block supports property #67073

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference-guides/data/data-core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ _Parameters_

- _state_ `Object`: Data state.
- _nameOrType_ `(string|Object)`: Block name or type object
- _feature_ `Array|string`: Feature to retrieve
- _features_ `Array|string`: Feature to retrieve
- _defaultSupports_ `*`: Default value to return if not explicitly defined

_Returns_
Expand Down
34 changes: 27 additions & 7 deletions packages/blocks/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export const getChildBlockNames = createSelector(
*
* @param {Object} state Data state.
* @param {(string|Object)} nameOrType Block name or type object
* @param {Array|string} feature Feature to retrieve
* @param {Array|string} features Feature to retrieve
* @param {*} defaultSupports Default value to return if not
* explicitly defined
*
Expand Down Expand Up @@ -629,19 +629,39 @@ export const getChildBlockNames = createSelector(
export const getBlockSupport = (
state,
nameOrType,
feature,
features,
defaultSupports
) => {
const blockType = getNormalizedBlockType( state, nameOrType );
if ( ! blockType?.supports ) {
return defaultSupports;
}

return getValueFromObjectPath(
blockType.supports,
feature,
defaultSupports
);
const featuresArray = Array.isArray( features ) ? features : [ features ];

let supportValue;
for ( const feature of featuresArray ) {
// Check for the feature directly
supportValue = getValueFromObjectPath( blockType.supports, feature );

// Check for `defaultControls` if the feature has it
if ( supportValue?.defaultControls ) {
return supportValue.defaultControls;
}

// Check for `__experimentalDefaultControls` if `defaultControls` is not found
if ( supportValue?.__experimentalDefaultControls ) {
return supportValue.__experimentalDefaultControls;
}

// If a value is found, return it
if ( supportValue !== undefined ) {
return supportValue;
}
}

// Return the default value if none of the features are found
return defaultSupports;
};

/**
Expand Down
Loading