WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.36k stars 4.14k forks source link

Explore adding `media` related roles to block attributes #65186

Open ntsekouras opened 2 weeks ago

ntsekouras commented 2 weeks ago

For a while now we have introduced the __experimentalRole property for block attributes. In spite of its name, the feature is considered stable, since it's been in many WP releases.

It's usage right now is having a content value, that is used in various features like the contentOnly mode and pattern transformations. Recently we expanded its usage by supporting a local value.

This role could be useful for marking some media attributes too, and handle cases where we could easily create previews of media blocks (like Image, Media Text etc..), support more blocks in the post publish panel to upload external images, etc..

In order to make some media blocks more semantic, we'd need more than one role though. For start we'd need the id and the url, which could have different names in blocks. For example the id in Image block is id and in Media Text is mediaId.

We will most certainly need a mediaType role as well. An example would be video and audio have different tag attributes and a preview for them would have to be generated differently. You can see an example of such handling for media tab in inserter.

Finally, right now these attributes have the content role assigned and that could simply mean that the new media roles are also considered content. This would require more testing though in order to validate that this is the case for all blocks that use them.

mtias commented 2 weeks ago

Thanks for starting this one—defining a good set of attribute roles is going to be key to normalize a lot of the behaviors that otherwise require very ad hoc handling across blocks. It's the way in which we can scale good user experience across the block ecosystem.