Repository navigation
Adds JSdoc for avatar block's edit.js
#68867
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b258918
feat: Adds Jsdoc comment for avatar block.
dhruvikpatel18 ee02ca2
Merge branch 'trunk' into feat/64057-avatar
dhruvikpatel18 1e922a5
Refactor: Update JSDoc comments for Avatar block components
dhruvikpatel18 0d6157c
Refactor: Improve JSDoc comments for UserEdit component in Avatar block
dhruvikpatel18 359ed22
Refactor: Update return type in JSDoc for AvatarLinkWrapper component
dhruvikpatel18 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,17 @@ import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; | |
| import { useCommentAvatar, useUserAvatar } from './hooks'; | ||
| import UserControl from './user-control'; | ||
|
|
||
| /** | ||
| * Renders the inspector controls for the `core/avatar` block. | ||
| * | ||
| * @param {Object} props React props. | ||
| * @param {Function} props.setAttributes Callback for updating block attributes. | ||
| * @param {Object} props.avatar Avatar data returned by `useCommentAvatar` or `useUserAvatar`, with the `minSize` and `maxSize` bounds of the size control. | ||
| * @param {Object} props.attributes Block attributes: `size`, `isLink`, `linkTarget` and `userId`. | ||
| * @param {boolean} props.selectUser Whether to render the user selection control. | ||
| * | ||
| * @return {React.JSX.Element} React element. | ||
| */ | ||
| const AvatarInspectorControls = ( { | ||
| setAttributes, | ||
| avatar, | ||
|
|
@@ -115,6 +126,17 @@ const AvatarInspectorControls = ( { | |
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Wraps the avatar image in a placeholder link when the block links to the user | ||
| * profile. The link is inert in the editor: it points at a fragment and its | ||
| * click handler prevents navigation. | ||
| * | ||
| * @param {Object} props React props. | ||
| * @param {React.ReactNode} props.children Avatar image to wrap. | ||
| * @param {boolean} props.isLink Whether to wrap the children in a link. | ||
| * | ||
| * @return {React.JSX.Element} React element. | ||
| */ | ||
| const AvatarLinkWrapper = ( { children, isLink } ) => | ||
| isLink ? ( | ||
| <a | ||
|
|
@@ -128,6 +150,19 @@ const AvatarLinkWrapper = ( { children, isLink } ) => | |
| children | ||
| ); | ||
|
|
||
| /** | ||
| * Renders the avatar image inside a `ResizableBox` so its size can be adjusted | ||
| * by dragging. Resizing keeps the aspect ratio and updates the `size` attribute. | ||
| * | ||
| * @param {Object} props React props. | ||
| * @param {Function} props.setAttributes Callback for updating block attributes. | ||
| * @param {Object} props.attributes Block attributes: `size` and `isLink`, plus the border support values read by `useBorderProps`. | ||
| * @param {Object} props.avatar Avatar data returned by `useCommentAvatar` or `useUserAvatar`, with the image `src` and `alt` and the `minSize` and `maxSize` resize bounds. | ||
| * @param {Object} props.blockProps Props returned by `useBlockProps`, applied to the wrapper element. | ||
| * @param {boolean} props.isSelected Whether the block is selected. Resize handles are only shown when it is. | ||
| * | ||
| * @return {React.JSX.Element} React element. | ||
| */ | ||
| const ResizableAvatar = ( { | ||
| setAttributes, | ||
| attributes, | ||
|
|
@@ -187,6 +222,20 @@ const ResizableAvatar = ( { | |
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Renders the block for a comment author, resolving the avatar from the | ||
| * `commentId` context. The user selection control is not offered here because | ||
| * the author is determined by the comment. | ||
| * | ||
| * @param {Object} props React props. | ||
| * @param {Object} props.attributes Block attributes. | ||
| * @param {Object} props.context Inherited context, from which the comment ID is read. | ||
| * @param {Function} props.setAttributes Callback for updating block attributes. | ||
| * @param {boolean} props.isSelected Whether the block is selected. | ||
| * | ||
| * @return {React.JSX.Element} React element. | ||
| */ | ||
| const CommentEdit = ( { attributes, context, setAttributes, isSelected } ) => { | ||
| const { commentId } = context; | ||
| const blockProps = useBlockProps(); | ||
|
|
@@ -210,6 +259,19 @@ const CommentEdit = ( { attributes, context, setAttributes, isSelected } ) => { | |
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Renders the block for a user, resolving the avatar from the `userId` | ||
| * attribute when set, and otherwise from the author of the post identified by | ||
| * the `postType` and `postId` context. | ||
| * | ||
| * @param {Object} props React props. | ||
| * @param {Object} props.attributes Block attributes, from which the `userId` is read. | ||
| * @param {Object} props.context Inherited context, from which the post type and post ID are read. | ||
| * @param {Function} props.setAttributes Callback for updating block attributes. | ||
| * @param {boolean} props.isSelected Whether the block is selected. | ||
| * | ||
| * @return {React.JSX.Element} React element. | ||
| */ | ||
| const UserEdit = ( { attributes, context, setAttributes, isSelected } ) => { | ||
| const { postId, postType } = context; | ||
| const avatar = useUserAvatar( { | ||
|
|
@@ -238,6 +300,22 @@ const UserEdit = ( { attributes, context, setAttributes, isSelected } ) => { | |
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Renders the `core/avatar` block on the editor. All props are forwarded to | ||
| * either `CommentEdit` or `UserEdit`, depending on whether the block is used | ||
| * inside a comment. | ||
| * | ||
| * @param {Object} props React props. | ||
| * @param {Object} props.attributes Block attributes. | ||
| * @param {Object} props.context Inherited context. | ||
| * @param {number} [props.context.commentId] The comment ID. Present, possibly as `null` in the Site Editor, when the block is used inside a comment. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it be The code explicitly expects |
||
| * @param {string} [props.context.postType] The post type of the current post. | ||
| * @param {number} [props.context.postId] The ID of the current post. | ||
| * @param {Function} props.setAttributes Callback for updating block attributes. | ||
| * @param {boolean} props.isSelected Whether the block is selected. | ||
| * | ||
| * @return {React.JSX.Element} React element. | ||
| */ | ||
| export default function Edit( props ) { | ||
| // Don't show the Comment Edit controls if we have a comment ID set, or if we're in the Site Editor (where it is `null`). | ||
| if ( props?.context?.commentId || props?.context?.commentId === null ) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React.ReactNodewould be the correct type here IMO, as it handles both scenarios, unlikeReact.JSX.Element, which only covers the rendered element case.