11import { useState , useEffect , useCallback } from '@wordpress/element' ;
2- import { PluginDocumentSettingPanel } from '@wordpress/editor' ;
2+ import {
3+ PluginDocumentSettingPanel ,
4+ store as editorStore ,
5+ } from '@wordpress/editor' ;
36import { useSelect } from '@wordpress/data' ;
47import { store as coreStore } from '@wordpress/core-data' ;
5- import { store as editorStore } from '@wordpress/editor' ;
68import { __ , sprintf } from '@wordpress/i18n' ;
79import apiFetch from '@wordpress/api-fetch' ;
810import {
@@ -22,6 +24,10 @@ const NAMESPACE = '/multi-author-posts/v1';
2224
2325/**
2426 * A single co-author row.
27+ * @param root0
28+ * @param root0.author
29+ * @param root0.canManage
30+ * @param root0.onRemove
2531 */
2632function AuthorCard ( { author, canManage, onRemove } ) {
2733 return (
@@ -44,7 +50,10 @@ function AuthorCard( { author, canManage, onRemove } ) {
4450 onClick = { ( ) => onRemove ( author . id ) }
4551 aria-label = {
4652 /* translators: %s: author display name */
47- sprintf ( __ ( 'Remove %s' , 'multi-author-posts' ) , author . name )
53+ sprintf (
54+ __ ( 'Remove %s' , 'multi-author-posts' ) ,
55+ author . name
56+ )
4857 }
4958 >
5059 { __ ( 'Remove' , 'multi-author-posts' ) }
@@ -56,6 +65,9 @@ function AuthorCard( { author, canManage, onRemove } ) {
5665
5766/**
5867 * User search + direct-add UI (shown only when the current user can manage co-authors).
68+ * @param root0
69+ * @param root0.postId
70+ * @param root0.onAdd
5971 */
6072function DirectAdd ( { postId, onAdd } ) {
6173 const [ search , setSearch ] = useState ( '' ) ;
@@ -71,7 +83,9 @@ function DirectAdd( { postId, onAdd } ) {
7183 setIsSearching ( true ) ;
7284 const controller = new AbortController ( ) ;
7385 apiFetch ( {
74- path : `${ NAMESPACE } /posts/${ postId } /suggested-authors?search=${ encodeURIComponent ( search ) } ` ,
86+ path : `${ NAMESPACE } /posts/${ postId } /suggested-authors?search=${ encodeURIComponent (
87+ search
88+ ) } `,
7589 signal : controller . signal ,
7690 } )
7791 . then ( ( data ) => {
@@ -104,7 +118,10 @@ function DirectAdd( { postId, onAdd } ) {
104118 label = { __ ( 'Add existing author' , 'multi-author-posts' ) }
105119 value = { search }
106120 onChange = { setSearch }
107- placeholder = { __ ( 'Search by name or email…' , 'multi-author-posts' ) }
121+ placeholder = { __ (
122+ 'Search by name or email…' ,
123+ 'multi-author-posts'
124+ ) }
108125 />
109126 { isSearching && < Spinner /> }
110127 { suggestions . length > 0 && (
@@ -119,7 +136,12 @@ function DirectAdd( { postId, onAdd } ) {
119136 width = { 28 }
120137 height = { 28 }
121138 />
122- < span > < TextHighlight text = { user . name } highlight = { search } /> </ span >
139+ < span >
140+ < TextHighlight
141+ text = { user . name }
142+ highlight = { search }
143+ />
144+ </ span >
123145 </ HStack >
124146 < Button
125147 variant = "secondary"
@@ -133,17 +155,24 @@ function DirectAdd( { postId, onAdd } ) {
133155 ) ) }
134156 </ ul >
135157 ) }
136- { search . length >= 2 && ! isSearching && suggestions . length === 0 && (
137- < p className = "map-no-suggestions" >
138- { __ ( 'No matching authors found.' , 'multi-author-posts' ) }
139- </ p >
140- ) }
158+ { search . length >= 2 &&
159+ ! isSearching &&
160+ suggestions . length === 0 && (
161+ < p className = "map-no-suggestions" >
162+ { __ (
163+ 'No matching authors found.' ,
164+ 'multi-author-posts'
165+ ) }
166+ </ p >
167+ ) }
141168 </ VStack >
142169 ) ;
143170}
144171
145172/**
146173 * Invite-link section (shown only when the current user can manage co-authors).
174+ * @param root0
175+ * @param root0.postId
147176 */
148177function InviteSection ( { postId } ) {
149178 // Plaintext URL is only available in-memory, immediately after creation.
@@ -186,18 +215,24 @@ function InviteSection( { postId } ) {
186215 } , [ postId ] ) ;
187216
188217 const handleCopy = useCallback ( ( ) => {
189- if ( ! inviteUrl ) return ;
218+ if ( ! inviteUrl ) {
219+ return ;
220+ }
190221 navigator . clipboard ?. writeText ( inviteUrl ) . then ( ( ) => {
191222 setCopied ( true ) ;
192223 setTimeout ( ( ) => setCopied ( false ) , 2000 ) ;
193224 } ) ;
194225 } , [ inviteUrl ] ) ;
195226
196- if ( isLoading ) return < Spinner /> ;
227+ if ( isLoading ) {
228+ return < Spinner /> ;
229+ }
197230
198231 return (
199232 < VStack spacing = { 2 } className = "map-invite-section" >
200- < strong > { __ ( 'Shared invite link' , 'multi-author-posts' ) } </ strong >
233+ < strong >
234+ { __ ( 'Shared invite link' , 'multi-author-posts' ) }
235+ </ strong >
201236 < p className = "map-invite-description" >
202237 { __ (
203238 'Anyone with this link who is registered on the network can join as a co-author. The link is valid for 24 hours and is only shown once — copy it now.' ,
@@ -213,7 +248,11 @@ function InviteSection( { postId } ) {
213248 onClick = { ( e ) => e . target . select ( ) }
214249 />
215250 < HStack justify = "flex-start" spacing = { 2 } >
216- < Button variant = "secondary" onClick = { handleCopy } disabled = { copied } >
251+ < Button
252+ variant = "secondary"
253+ onClick = { handleCopy }
254+ disabled = { copied }
255+ >
217256 { copied
218257 ? __ ( 'Copied!' , 'multi-author-posts' )
219258 : __ ( 'Copy link' , 'multi-author-posts' ) }
@@ -223,7 +262,10 @@ function InviteSection( { postId } ) {
223262 ) }
224263 { ! inviteUrl && isActive && (
225264 < p className = "map-invite-active" >
226- { __ ( 'An invite link is active. Regenerate to issue a new one (the previous link will stop working) or revoke it.' , 'multi-author-posts' ) }
265+ { __ (
266+ 'An invite link is active. Regenerate to issue a new one (the previous link will stop working) or revoke it.' ,
267+ 'multi-author-posts'
268+ ) }
227269 </ p >
228270 ) }
229271 < HStack justify = "flex-start" spacing = { 2 } >
@@ -233,7 +275,11 @@ function InviteSection( { postId } ) {
233275 : __ ( 'Generate invite link' , 'multi-author-posts' ) }
234276 </ Button >
235277 { isActive && (
236- < Button variant = "tertiary" isDestructive onClick = { handleRevoke } >
278+ < Button
279+ variant = "tertiary"
280+ isDestructive
281+ onClick = { handleRevoke }
282+ >
237283 { __ ( 'Revoke' , 'multi-author-posts' ) }
238284 </ Button >
239285 ) }
@@ -263,13 +309,14 @@ export default function MultiAuthorPlugin() {
263309 // Post author and any existing co-author share the same management trust.
264310 // The REST API enforces the same rule server-side.
265311 const canManage =
266- ! ! currentUserId && (
267- currentUserId === postAuthorId ||
268- coAuthors . some ( ( a ) => a . id === currentUserId )
269- ) ;
312+ ! ! currentUserId &&
313+ ( currentUserId === postAuthorId ||
314+ coAuthors . some ( ( a ) => a . id === currentUserId ) ) ;
270315
271316 useEffect ( ( ) => {
272- if ( ! postId ) return ;
317+ if ( ! postId ) {
318+ return ;
319+ }
273320 setIsLoading ( true ) ;
274321 apiFetch ( { path : `${ NAMESPACE } /posts/${ postId } /co-authors` } )
275322 . then ( ( data ) => {
@@ -299,14 +346,19 @@ export default function MultiAuthorPlugin() {
299346 . catch ( ( err ) =>
300347 setError (
301348 err ?. message ??
302- __ ( 'Could not remove co-author.' , 'multi-author-posts' )
349+ __ (
350+ 'Could not remove co-author.' ,
351+ 'multi-author-posts'
352+ )
303353 )
304354 ) ;
305355 } ,
306356 [ postId ]
307357 ) ;
308358
309- if ( ! postId ) return null ;
359+ if ( ! postId ) {
360+ return null ;
361+ }
310362
311363 return (
312364 < PluginDocumentSettingPanel
0 commit comments