Skip to content

Commit

Permalink
Revert format types hook refactor (#56859)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Dec 7, 2023
1 parent 3514f11 commit e63ef38
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions packages/block-editor/src/components/rich-text/use-format-types.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as richTextStore } from '@wordpress/rich-text';

function formatTypesSelector( select ) {
return select( richTextStore ).getFormatTypes();
}

/**
* Set of all interactive content tags.
*
Expand Down Expand Up @@ -59,50 +64,45 @@ export function useFormatTypes( {
withoutInteractiveFormatting,
allowedFormats,
} ) {
const { formatTypes, ...keyedSelected } = useSelect(
( select ) => {
const _formatTypes = select( richTextStore )
.getFormatTypes()
.filter( ( { name, interactive, tagName } ) => {
if ( allowedFormats && ! allowedFormats.includes( name ) ) {
return false;
}
const allFormatTypes = useSelect( formatTypesSelector, [] );
const formatTypes = useMemo( () => {
return allFormatTypes.filter( ( { name, interactive, tagName } ) => {
if ( allowedFormats && ! allowedFormats.includes( name ) ) {
return false;
}

if (
withoutInteractiveFormatting &&
( interactive || interactiveContentTags.has( tagName ) )
) {
return false;
}
if (
withoutInteractiveFormatting &&
( interactive || interactiveContentTags.has( tagName ) )
) {
return false;
}

return true;
} );
return _formatTypes.reduce(
( accumulator, type ) => {
if (
! type.__experimentalGetPropsForEditableTreePreparation
) {
return accumulator;
}
return true;
} );
}, [ allFormatTypes, allowedFormats, withoutInteractiveFormatting ] );
const keyedSelected = useSelect(
( select ) =>
formatTypes.reduce( ( accumulator, type ) => {
if ( ! type.__experimentalGetPropsForEditableTreePreparation ) {
return accumulator;
}

return {
...accumulator,
...prefixSelectKeys(
type.__experimentalGetPropsForEditableTreePreparation(
select,
{
richTextIdentifier: identifier,
blockClientId: clientId,
}
),
type.name
return {
...accumulator,
...prefixSelectKeys(
type.__experimentalGetPropsForEditableTreePreparation(
select,
{
richTextIdentifier: identifier,
blockClientId: clientId,
}
),
};
},
{ formatTypes: _formatTypes }
);
},
[ clientId, identifier, allowedFormats, withoutInteractiveFormatting ]
type.name
),
};
}, {} ),
[ formatTypes, clientId, identifier ]
);
const dispatch = useDispatch();
const prepareHandlers = [];
Expand Down

1 comment on commit e63ef38

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e63ef38.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7128165601
📝 Reported issues:

Please sign in to comment.