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

Docs: Add explanations about attributes of each Core Block in the documentation (and in the source code) #64057

Open
juanmaguitar opened this issue Jul 29, 2024 · 5 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Status] Blocked Used to indicate that a current effort isn't able to move forward [Type] Developer Documentation Documentation for developers [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.

Comments

@juanmaguitar
Copy link
Contributor

juanmaguitar commented Jul 29, 2024

The only official documentation available for core blocks is located at Block Editor Handbook > Reference Guides > Core Blocks Reference. This page lacks detailed explanations about each core block’s attributes and points the user to the source code for more information.

Providing extra explanations about the attributes of core blocks is essential for developers to fully understand and utilize these blocks effectively.

I propose including JSDoc comments in the Edit component of each block to explain the props.attributes object received by every core block’s edit component.

Besides providing extra info on these attributes directly in the source code, these descriptions could also be used (with some custom extra code) by gen-block-lib-list.js to generate more extended info for each block at Block Editor Handbook > Reference Guides > Core Blocks Reference

@priethor priethor added [Type] Developer Documentation Documentation for developers [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues. labels Jul 29, 2024
@ndiego ndiego added the [Feature] Extensibility The ability to extend blocks or the editing experience label Aug 12, 2024
@vipul0425
Copy link
Contributor

Hi @juanmaguitar,

I’ve created an initial PR for this issue (#68508). It includes the additional code changes to the gen-block-lib-list.js script and adds the documentation comment for the archives block.
For the JSDoc comment, I referred to the guidance shared here: #22891 (comment), as mentioned by @t-hamano.

Looking forward to your feedback.
Thanks 🙇

@stokesman
Copy link
Contributor

stokesman commented Jan 25, 2025

I agree with the idea here. My initial thought on the proposal of adding JSDoc comments to the Edit components is that it introduces duplication and therefore seems less than ideal for maintenance.

Has adding this directly in block json been considered? There each attribute already supports some relevant metadata (type and default). What about adding a description for attributes? I can think of two ways that might be done. Either adding it as a property or supporting JSON5 and adding it as a comment.

Adding a description property to attributes seems the simpler idea. However, ideally their data wouldn’t contribute to any bundle size increases and for that it seems a custom JSON loader for Webpack that could strip such properties would be wanted. Additionally—though likely of lesser concern—the generation of blocks-json.php in core might also strip the properties.

Supporting JSON5 would probably be more work yet would seemingly have a broader appeal. Adding attribute descriptions in the way of comments should avoid the concern of bundle size increases. However, that might be less simple with regards to generating docs.

@Mamaduka
Copy link
Member

Putting this proposal on hold until the following items are considered/resolved:

  • Standardized way of documenting block attributes. I agree with @stokesman that JSDoc comments might not be the best option.
  • A parser that can include these details in documentation. There's already one parsing block attribute name from the block.json file; it might be easier to reuse that.

tl;dr, we need to have a good plan before moving forward and updating dozens of files.

cc @vipul0425, @Anuj-Rathore24, @dhruvikpatel18

@Mamaduka Mamaduka added the [Status] Blocked Used to indicate that a current effort isn't able to move forward label Jan 27, 2025
@t-hamano
Copy link
Contributor

If we wanted to use JSON5 or JSONC to be able to insert comments, we'd probably have to convert all block.json to block.json5 or block.jsonc, and the @wordpress/scripts would have to support the new extensions, right?

On the other hand, because additionalProperties is not defined in the attributes field, any field can be added, so it would be possible to add a field such as description. However, ideally additional fields should not be allowed.

@Mamaduka
Copy link
Member

IIRC, JSON5 or JSONC aren't supported by default in PHP, so I doubt the format change.

P.S. There was a similar conversation for the theme.json format change, and I remember that was one of the reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Status] Blocked Used to indicate that a current effort isn't able to move forward [Type] Developer Documentation Documentation for developers [Type] Tracking Issue Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Projects
None yet
Development

No branches or pull requests

7 participants