@wordpress/editor 14.33.2 → 14.33.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/build/bindings/post-data.js +10 -17
  2. package/build/bindings/post-data.js.map +2 -2
  3. package/build/bindings/post-meta.js +7 -14
  4. package/build/bindings/post-meta.js.map +2 -2
  5. package/build/bindings/term-data.js +6 -16
  6. package/build/bindings/term-data.js.map +2 -2
  7. package/build/components/collab-sidebar/add-comment.js +26 -3
  8. package/build/components/collab-sidebar/add-comment.js.map +3 -3
  9. package/build/components/collab-sidebar/comment-indicator-toolbar.js +6 -22
  10. package/build/components/collab-sidebar/comment-indicator-toolbar.js.map +3 -3
  11. package/build/components/collab-sidebar/comments.js +112 -33
  12. package/build/components/collab-sidebar/comments.js.map +3 -3
  13. package/build/components/collab-sidebar/hooks.js +14 -8
  14. package/build/components/collab-sidebar/hooks.js.map +2 -2
  15. package/build/components/collab-sidebar/index.js +51 -59
  16. package/build/components/collab-sidebar/index.js.map +3 -3
  17. package/build/components/editor/index.js +2 -0
  18. package/build/components/editor/index.js.map +3 -3
  19. package/build/components/header/index.js +0 -3
  20. package/build/components/header/index.js.map +3 -3
  21. package/build/components/post-template/hooks.js +7 -38
  22. package/build/components/post-template/hooks.js.map +2 -2
  23. package/build/components/provider/index.js +1 -1
  24. package/build/components/provider/index.js.map +2 -2
  25. package/build/store/actions.js +1 -1
  26. package/build/store/actions.js.map +2 -2
  27. package/build-module/bindings/post-data.js +10 -17
  28. package/build-module/bindings/post-data.js.map +2 -2
  29. package/build-module/bindings/post-meta.js +7 -14
  30. package/build-module/bindings/post-meta.js.map +2 -2
  31. package/build-module/bindings/term-data.js +6 -16
  32. package/build-module/bindings/term-data.js.map +2 -2
  33. package/build-module/components/collab-sidebar/add-comment.js +27 -4
  34. package/build-module/components/collab-sidebar/add-comment.js.map +2 -2
  35. package/build-module/components/collab-sidebar/comment-indicator-toolbar.js +6 -12
  36. package/build-module/components/collab-sidebar/comment-indicator-toolbar.js.map +2 -2
  37. package/build-module/components/collab-sidebar/comments.js +121 -36
  38. package/build-module/components/collab-sidebar/comments.js.map +2 -2
  39. package/build-module/components/collab-sidebar/hooks.js +14 -8
  40. package/build-module/components/collab-sidebar/hooks.js.map +2 -2
  41. package/build-module/components/collab-sidebar/index.js +51 -59
  42. package/build-module/components/collab-sidebar/index.js.map +2 -2
  43. package/build-module/components/editor/index.js +2 -0
  44. package/build-module/components/editor/index.js.map +2 -2
  45. package/build-module/components/header/index.js +0 -3
  46. package/build-module/components/header/index.js.map +2 -2
  47. package/build-module/components/post-template/hooks.js +7 -38
  48. package/build-module/components/post-template/hooks.js.map +2 -2
  49. package/build-module/components/provider/index.js +1 -1
  50. package/build-module/components/provider/index.js.map +2 -2
  51. package/build-module/store/actions.js +1 -1
  52. package/build-module/store/actions.js.map +2 -2
  53. package/build-style/style-rtl.css +1 -16
  54. package/build-style/style.css +1 -16
  55. package/build-types/bindings/post-data.d.ts +6 -16
  56. package/build-types/bindings/post-meta.d.ts +6 -13
  57. package/build-types/bindings/term-data.d.ts +6 -16
  58. package/build-types/components/collab-sidebar/add-comment.d.ts +6 -1
  59. package/build-types/components/collab-sidebar/add-comment.d.ts.map +1 -1
  60. package/build-types/components/collab-sidebar/comment-indicator-toolbar.d.ts +1 -2
  61. package/build-types/components/collab-sidebar/comment-indicator-toolbar.d.ts.map +1 -1
  62. package/build-types/components/collab-sidebar/comments.d.ts +12 -26
  63. package/build-types/components/collab-sidebar/comments.d.ts.map +1 -1
  64. package/build-types/components/collab-sidebar/hooks.d.ts +0 -1
  65. package/build-types/components/collab-sidebar/hooks.d.ts.map +1 -1
  66. package/build-types/components/collab-sidebar/index.d.ts +1 -4
  67. package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
  68. package/build-types/components/editor/index.d.ts.map +1 -1
  69. package/build-types/components/header/index.d.ts.map +1 -1
  70. package/build-types/components/post-template/hooks.d.ts +1 -1
  71. package/build-types/components/post-template/hooks.d.ts.map +1 -1
  72. package/build-types/components/provider/index.d.ts.map +1 -1
  73. package/build-types/store/actions.d.ts.map +1 -1
  74. package/package.json +38 -38
  75. package/src/bindings/post-data.js +9 -20
  76. package/src/bindings/post-meta.js +6 -17
  77. package/src/bindings/term-data.js +6 -21
  78. package/src/components/collab-sidebar/add-comment.js +31 -3
  79. package/src/components/collab-sidebar/comment-indicator-toolbar.js +6 -22
  80. package/src/components/collab-sidebar/comments.js +128 -51
  81. package/src/components/collab-sidebar/hooks.js +18 -12
  82. package/src/components/collab-sidebar/index.js +67 -67
  83. package/src/components/collab-sidebar/style.scss +1 -22
  84. package/src/components/editor/index.js +2 -0
  85. package/src/components/header/index.js +0 -7
  86. package/src/components/post-template/hooks.js +10 -51
  87. package/src/components/provider/index.js +1 -4
  88. package/src/store/actions.js +4 -1
  89. package/tsconfig.tsbuildinfo +1 -1
@@ -6,11 +6,6 @@ import { __, _n, sprintf } from '@wordpress/i18n';
6
6
  import { useMemo } from '@wordpress/element';
7
7
  import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
8
8
 
9
- /**
10
- * External dependencies
11
- */
12
- import clsx from 'clsx';
13
-
14
9
  /**
15
10
  * Internal dependencies
16
11
  */
@@ -19,7 +14,7 @@ import { getAvatarBorderColor } from './utils';
19
14
 
20
15
  const { CommentIconToolbarSlotFill } = unlock( blockEditorPrivateApis );
21
16
 
22
- const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
17
+ const CommentAvatarIndicator = ( { onClick, thread } ) => {
23
18
  const threadParticipants = useMemo( () => {
24
19
  if ( ! thread ) {
25
20
  return [];
@@ -34,15 +29,13 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
34
29
  allComments.forEach( ( comment ) => {
35
30
  // Track thread participants (original commenter + repliers).
36
31
  if ( comment.author_name && comment.author_avatar_urls ) {
37
- const authorKey = `${ comment.author }-${ comment.author_name }`;
38
- if ( ! participantsMap.has( authorKey ) ) {
39
- participantsMap.set( authorKey, {
32
+ if ( ! participantsMap.has( comment.author ) ) {
33
+ participantsMap.set( comment.author, {
40
34
  name: comment.author_name,
41
35
  avatar:
42
36
  comment.author_avatar_urls?.[ '48' ] ||
43
37
  comment.author_avatar_urls?.[ '96' ],
44
38
  id: comment.author,
45
- isOriginalCommenter: comment.id === thread.id,
46
39
  date: comment.date,
47
40
  } );
48
41
  }
@@ -52,14 +45,6 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
52
45
  return Array.from( participantsMap.values() );
53
46
  }, [ thread ] );
54
47
 
55
- const hasUnresolved = thread?.status !== 'approved';
56
-
57
- // Check if this specific thread has more participants due to pagination.
58
- // If we have pagination AND this thread + its replies equals or exceeds the API limit,
59
- // then this thread likely has more participants that weren't loaded.
60
- const threadHasMoreParticipants =
61
- hasMoreComments && thread?.reply && 1 + thread.reply.length >= 100;
62
-
63
48
  if ( ! threadParticipants.length ) {
64
49
  return null;
65
50
  }
@@ -68,6 +53,7 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
68
53
  const maxAvatars = 3;
69
54
  const visibleParticipants = threadParticipants.slice( 0, maxAvatars );
70
55
  const overflowCount = Math.max( 0, threadParticipants.length - maxAvatars );
56
+ const threadHasMoreParticipants = threadParticipants.length > 100;
71
57
 
72
58
  // If we hit the comment limit, show "100+" instead of exact overflow count.
73
59
  const overflowText =
@@ -95,9 +81,7 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
95
81
  return (
96
82
  <CommentIconToolbarSlotFill.Fill>
97
83
  <ToolbarButton
98
- className={ clsx( 'comment-avatar-indicator', {
99
- 'has-unresolved': hasUnresolved,
100
- } ) }
84
+ className="comment-avatar-indicator"
101
85
  label={ __( 'View notes' ) }
102
86
  onClick={ onClick }
103
87
  showTooltip
@@ -105,7 +89,7 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
105
89
  <div className="comment-avatar-stack">
106
90
  { visibleParticipants.map( ( participant, index ) => (
107
91
  <img
108
- key={ participant.name + index }
92
+ key={ participant.id }
109
93
  src={ participant.avatar }
110
94
  alt={ participant.name }
111
95
  className="comment-avatar"
@@ -6,7 +6,13 @@ import clsx from 'clsx';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { useState, RawHTML, useEffect, useCallback } from '@wordpress/element';
9
+ import {
10
+ useState,
11
+ RawHTML,
12
+ useEffect,
13
+ useCallback,
14
+ useMemo,
15
+ } from '@wordpress/element';
10
16
  import {
11
17
  __experimentalText as Text,
12
18
  __experimentalHStack as HStack,
@@ -33,32 +39,19 @@ import {
33
39
  import { unlock } from '../../lock-unlock';
34
40
  import CommentAuthorInfo from './comment-author-info';
35
41
  import CommentForm from './comment-form';
36
- import { getCommentExcerpt, focusCommentThread } from './utils';
42
+ import { focusCommentThread, getCommentExcerpt } from './utils';
37
43
  import { useFloatingThread } from './hooks';
44
+ import { AddComment } from './add-comment';
38
45
 
39
46
  const { useBlockElement } = unlock( blockEditorPrivateApis );
40
47
  const { Menu } = unlock( componentsPrivateApis );
41
48
 
42
- /**
43
- * Renders the Comments component.
44
- *
45
- * @param {Object} props - The component props.
46
- * @param {Array} props.threads - The array of comment threads.
47
- * @param {Function} props.onEditComment - The function to handle comment editing.
48
- * @param {Function} props.onAddReply - The function to add a reply to a comment.
49
- * @param {Function} props.onCommentDelete - The function to delete a comment.
50
- * @param {Function} props.setShowCommentBoard - The function to set the comment board visibility.
51
- * @param {Ref} props.commentSidebarRef - The ref to the comment sidebar.
52
- * @param {Function} props.reflowComments - The function to call indicating a comment is updated.
53
- * @param {boolean} props.isFloating - Whether the comment thread is floating.
54
- * @param {number} props.commentLastUpdated - Timestamp of the last comment update.
55
- * @return {React.ReactNode} The rendered Comments component.
56
- */
57
49
  export function Comments( {
58
- threads,
50
+ threads: noteThreads,
59
51
  onEditComment,
60
52
  onAddReply,
61
53
  onCommentDelete,
54
+ showCommentBoard,
62
55
  setShowCommentBoard,
63
56
  commentSidebarRef,
64
57
  reflowComments,
@@ -70,20 +63,62 @@ export function Comments( {
70
63
  const [ boardOffsets, setBoardOffsets ] = useState( {} );
71
64
  const [ blockRefs, setBlockRefs ] = useState( {} );
72
65
 
73
- const { blockCommentId, selectedBlockClientId } = useSelect( ( select ) => {
74
- const { getBlockAttributes, getSelectedBlockClientId } =
75
- select( blockEditorStore );
76
- const clientId = getSelectedBlockClientId();
77
- return {
78
- blockCommentId: clientId
79
- ? getBlockAttributes( clientId )?.metadata?.noteId
80
- : null,
81
- selectedBlockClientId: clientId,
82
- };
83
- }, [] );
66
+ const { blockCommentId, selectedBlockClientId, orderedBlockIds } =
67
+ useSelect( ( select ) => {
68
+ const { getBlockAttributes, getSelectedBlockClientId } =
69
+ select( blockEditorStore );
70
+ const clientId = getSelectedBlockClientId();
71
+ return {
72
+ blockCommentId: clientId
73
+ ? getBlockAttributes( clientId )?.metadata?.noteId
74
+ : null,
75
+ selectedBlockClientId: clientId,
76
+ orderedBlockIds: select( blockEditorStore ).getBlockOrder(),
77
+ };
78
+ }, [] );
84
79
 
85
80
  const relatedBlockElement = useBlockElement( selectedBlockClientId );
86
81
 
82
+ const threads = useMemo( () => {
83
+ const t = [ ...noteThreads ];
84
+ const orderedThreads = [];
85
+ // In floating mode, when the note board is shown, and as long
86
+ // as the selected block doesn't have an existing note attached -
87
+ // add a "new note" entry to the threads. This special thread type
88
+ // gets sorted and floated like regular threads, but shows an AddComment
89
+ // component instead of a regular comment thread.
90
+ if ( isFloating && showCommentBoard && undefined === blockCommentId ) {
91
+ // Insert the new note entry at the correct location for its blockId.
92
+ const newNoteThread = {
93
+ id: 'new-note-thread',
94
+ blockClientId: selectedBlockClientId,
95
+ content: { rendered: '' },
96
+ };
97
+ // Insert the new comment block at the right order within the threads.
98
+ orderedBlockIds.forEach( ( blockId ) => {
99
+ if ( blockId === selectedBlockClientId ) {
100
+ orderedThreads.push( newNoteThread );
101
+ } else {
102
+ const threadForBlock = t.find(
103
+ ( thread ) => thread.blockClientId === blockId
104
+ );
105
+ if ( threadForBlock ) {
106
+ orderedThreads.push( threadForBlock );
107
+ }
108
+ }
109
+ } );
110
+ return orderedThreads;
111
+ }
112
+ return t;
113
+ }, [
114
+ noteThreads,
115
+ isFloating,
116
+ showCommentBoard,
117
+ blockCommentId,
118
+ selectedBlockClientId,
119
+ orderedBlockIds,
120
+ ] );
121
+
87
122
  const handleDelete = async ( comment ) => {
88
123
  const currentIndex = threads.findIndex( ( t ) => t.id === comment.id );
89
124
  const nextThread = threads[ currentIndex + 1 ];
@@ -247,17 +282,33 @@ export function Comments( {
247
282
  const hasThreads = Array.isArray( threads ) && threads.length > 0;
248
283
  if ( ! hasThreads && ! isFloating ) {
249
284
  return (
250
- <VStack alignment="left" justify="flex-start" spacing="2">
285
+ <>
286
+ <AddComment
287
+ onSubmit={ onAddReply }
288
+ showCommentBoard={ showCommentBoard }
289
+ setShowCommentBoard={ setShowCommentBoard }
290
+ commentSidebarRef={ commentSidebarRef }
291
+ />
251
292
  <Text as="p">{ __( 'No notes available.' ) }</Text>
252
293
  <Text as="p" variant="muted">
253
294
  { __( 'Only logged in users can see Notes.' ) }
254
295
  </Text>
255
- </VStack>
296
+ </>
256
297
  );
257
298
  }
258
299
 
259
300
  return (
260
- <VStack spacing="3">
301
+ <>
302
+ { ! isFloating &&
303
+ showCommentBoard &&
304
+ undefined === blockCommentId && (
305
+ <AddComment
306
+ onSubmit={ onAddReply }
307
+ showCommentBoard={ showCommentBoard }
308
+ setShowCommentBoard={ setShowCommentBoard }
309
+ commentSidebarRef={ commentSidebarRef }
310
+ />
311
+ ) }
261
312
  { threads.map( ( thread ) => (
262
313
  <Thread
263
314
  key={ thread.id }
@@ -276,9 +327,10 @@ export function Comments( {
276
327
  setBlockRef={ setBlockRef }
277
328
  selectedThread={ selectedThread }
278
329
  commentLastUpdated={ commentLastUpdated }
330
+ showCommentBoard={ showCommentBoard }
279
331
  />
280
332
  ) ) }
281
- </VStack>
333
+ </>
282
334
  );
283
335
  }
284
336
 
@@ -298,6 +350,7 @@ function Thread( {
298
350
  setSelectedThread,
299
351
  selectedThread,
300
352
  commentLastUpdated,
353
+ showCommentBoard,
301
354
  } ) {
302
355
  const { toggleBlockHighlight, selectBlock, toggleBlockSpotlight } = unlock(
303
356
  useDispatch( blockEditorStore )
@@ -327,9 +380,11 @@ function Thread( {
327
380
  const handleCommentSelect = () => {
328
381
  setShowCommentBoard( false );
329
382
  setSelectedThread( thread.id );
330
- // pass `null` as the second parameter to prevent focusing the block.
331
- selectBlock( thread.blockClientId, null );
332
- toggleBlockSpotlight( thread.blockClientId, true );
383
+ if ( !! thread.blockClientId ) {
384
+ // Pass `null` as the second parameter to prevent focusing the block.
385
+ selectBlock( thread.blockClientId, null );
386
+ toggleBlockSpotlight( thread.blockClientId, true );
387
+ }
333
388
  };
334
389
 
335
390
  const unselectThread = () => {
@@ -345,10 +400,10 @@ function Thread( {
345
400
  const restReplies = allReplies.length > 0 ? allReplies.slice( 0, -1 ) : [];
346
401
 
347
402
  const commentExcerpt = getCommentExcerpt(
348
- stripHTML( thread.content.rendered ),
403
+ stripHTML( thread.content?.rendered ),
349
404
  10
350
405
  );
351
- const ariaLabel = relatedBlockElement
406
+ const ariaLabel = !! thread.blockClientId
352
407
  ? sprintf(
353
408
  // translators: %s: note excerpt
354
409
  __( 'Note: %s' ),
@@ -360,6 +415,21 @@ function Thread( {
360
415
  commentExcerpt
361
416
  );
362
417
 
418
+ if ( 'new-note-thread' === thread.id && showCommentBoard && isFloating ) {
419
+ return (
420
+ <AddComment
421
+ onSubmit={ onAddReply }
422
+ showCommentBoard={ showCommentBoard }
423
+ setShowCommentBoard={ setShowCommentBoard }
424
+ commentSidebarRef={ commentSidebarRef }
425
+ reflowComments={ reflowComments }
426
+ isFloating={ isFloating }
427
+ y={ y }
428
+ refs={ refs }
429
+ />
430
+ );
431
+ }
432
+
363
433
  return (
364
434
  // Disable reason: role="listitem" does in fact support aria-expanded.
365
435
  // eslint-disable-next-line jsx-a11y/role-supports-aria-props
@@ -376,6 +446,9 @@ function Thread( {
376
446
  onFocus={ onMouseEnter }
377
447
  onBlur={ onMouseLeave }
378
448
  onKeyDown={ ( event ) => {
449
+ if ( event.defaultPrevented ) {
450
+ return;
451
+ }
379
452
  // Expand or Collapse thread.
380
453
  if (
381
454
  event.key === 'Enter' &&
@@ -414,7 +487,7 @@ function Thread( {
414
487
  >
415
488
  { __( 'Add new note' ) }
416
489
  </Button>
417
- { ! relatedBlockElement && (
490
+ { ! thread.blockClientId && (
418
491
  <Text as="p" weight={ 500 } variant="muted">
419
492
  { __( 'Original block deleted.' ) }
420
493
  </Text>
@@ -533,17 +606,19 @@ function Thread( {
533
606
  </VStack>
534
607
  </VStack>
535
608
  ) }
536
- <Button
537
- className="editor-collab-sidebar-panel__skip-to-block"
538
- variant="secondary"
539
- size="compact"
540
- onClick={ ( event ) => {
541
- event.stopPropagation();
542
- relatedBlockElement?.focus();
543
- } }
544
- >
545
- { __( 'Back to block' ) }
546
- </Button>
609
+ { !! thread.blockClientId && (
610
+ <Button
611
+ className="editor-collab-sidebar-panel__skip-to-block"
612
+ variant="secondary"
613
+ size="compact"
614
+ onClick={ ( event ) => {
615
+ event.stopPropagation();
616
+ relatedBlockElement?.focus();
617
+ } }
618
+ >
619
+ { __( 'Back to block' ) }
620
+ </Button>
621
+ ) }
547
622
  </VStack>
548
623
  );
549
624
  }
@@ -741,7 +816,9 @@ const CommentBoard = ( {
741
816
  onCancel={ handleCancel }
742
817
  confirmButtonText={ __( 'Delete' ) }
743
818
  >
744
- { __( 'Are you sure you want to delete this note?' ) }
819
+ { __(
820
+ "Are you sure you want to delete this note? This will also delete all of this note's replies."
821
+ ) }
745
822
  </ConfirmDialog>
746
823
  ) }
747
824
  </VStack>
@@ -50,10 +50,10 @@ export function useBlockComments( postId ) {
50
50
  post: postId,
51
51
  type: 'note',
52
52
  status: 'all',
53
- per_page: 100,
53
+ per_page: -1,
54
54
  };
55
55
 
56
- const { records: threads, totalPages } = useEntityRecords(
56
+ const { records: threads } = useEntityRecords(
57
57
  'root',
58
58
  'comment',
59
59
  queryArgs,
@@ -160,7 +160,6 @@ export function useBlockComments( postId ) {
160
160
  return {
161
161
  resultComments,
162
162
  unresolvedSortedThreads,
163
- totalPages,
164
163
  reflowComments,
165
164
  commentLastUpdated,
166
165
  };
@@ -339,17 +338,24 @@ export function useEnableFloatingSidebar( enabled = false ) {
339
338
  return;
340
339
  }
341
340
 
342
- return registry.subscribe( () => {
343
- const activeSidebar = registry
344
- .select( interfaceStore )
345
- .getActiveComplementaryArea( 'core' );
341
+ const { getActiveComplementaryArea } =
342
+ registry.select( interfaceStore );
343
+ const { disableComplementaryArea, enableComplementaryArea } =
344
+ registry.dispatch( interfaceStore );
346
345
 
347
- if ( ! activeSidebar ) {
348
- registry
349
- .dispatch( interfaceStore )
350
- .enableComplementaryArea( 'core', collabSidebarName );
346
+ const unsubscribe = registry.subscribe( () => {
347
+ // Return `null` to indicate the user hid the complementary area.
348
+ if ( getActiveComplementaryArea( 'core' ) === null ) {
349
+ enableComplementaryArea( 'core', collabSidebarName );
351
350
  }
352
351
  } );
352
+
353
+ return () => {
354
+ unsubscribe();
355
+ if ( getActiveComplementaryArea( 'core' ) === collabSidebarName ) {
356
+ disableComplementaryArea( 'core', collabSidebarName );
357
+ }
358
+ };
353
359
  }, [ enabled, registry ] );
354
360
  }
355
361
 
@@ -392,7 +398,7 @@ export function useFloatingThread( {
392
398
  if ( blockRef.current ) {
393
399
  refs.setReference( blockRef.current );
394
400
  }
395
- }, [ blockRef, refs ] );
401
+ }, [ blockRef, refs, commentLastUpdated ] );
396
402
 
397
403
  // Track thread heights.
398
404
  useEffect( () => {
@@ -20,7 +20,6 @@ import {
20
20
  SIDEBARS,
21
21
  } from './constants';
22
22
  import { Comments } from './comments';
23
- import { AddComment } from './add-comment';
24
23
  import { store as editorStore } from '../../store';
25
24
  import AddCommentMenuItem from './comment-menu-item';
26
25
  import CommentAvatarIndicator from './comment-indicator-toolbar';
@@ -31,9 +30,9 @@ import {
31
30
  useEnableFloatingSidebar,
32
31
  } from './hooks';
33
32
  import { focusCommentThread } from './utils';
34
- import PluginMoreMenuItem from '../plugin-more-menu-item';
33
+ import PostTypeSupportCheck from '../post-type-support-check';
35
34
 
36
- function CollabSidebarContent( {
35
+ function NotesSidebarContent( {
37
36
  showCommentBoard,
38
37
  setShowCommentBoard,
39
38
  styles,
@@ -54,16 +53,13 @@ function CollabSidebarContent( {
54
53
  spacing="3"
55
54
  justify="flex-start"
56
55
  ref={ ( node ) => {
57
- // Keeps the ref fresh when switching between floating and pinned sidebar.
58
- commentSidebarRef.current = node;
56
+ // Sometimes previous sidebar unmounts after the new one mounts.
57
+ // This ensures we always have the latest reference.
58
+ if ( node ) {
59
+ commentSidebarRef.current = node;
60
+ }
59
61
  } }
60
62
  >
61
- <AddComment
62
- onSubmit={ onCreate }
63
- showCommentBoard={ showCommentBoard }
64
- setShowCommentBoard={ setShowCommentBoard }
65
- commentSidebarRef={ commentSidebarRef }
66
- />
67
63
  <Comments
68
64
  threads={ comments }
69
65
  onEditComment={ onEdit }
@@ -80,22 +76,14 @@ function CollabSidebarContent( {
80
76
  );
81
77
  }
82
78
 
83
- /**
84
- * Renders the Collab sidebar.
85
- */
86
- export default function CollabSidebar() {
79
+ function NotesSidebar( { postId, mode } ) {
87
80
  const [ showCommentBoard, setShowCommentBoard ] = useState( false );
88
81
  const { getActiveComplementaryArea } = useSelect( interfaceStore );
89
82
  const { enableComplementaryArea } = useDispatch( interfaceStore );
90
83
  const isLargeViewport = useViewportMatch( 'medium' );
91
84
  const commentSidebarRef = useRef( null );
92
85
 
93
- const { postId } = useSelect( ( select ) => {
94
- const { getCurrentPostId } = select( editorStore );
95
- return {
96
- postId: getCurrentPostId(),
97
- };
98
- }, [] );
86
+ const showFloatingSidebar = isLargeViewport && mode === 'post-only';
99
87
 
100
88
  const blockCommentId = useSelect( ( select ) => {
101
89
  const { getBlockAttributes, getSelectedBlockClientId } =
@@ -109,13 +97,13 @@ export default function CollabSidebar() {
109
97
  const {
110
98
  resultComments,
111
99
  unresolvedSortedThreads,
112
- totalPages,
113
100
  reflowComments,
114
101
  commentLastUpdated,
115
102
  } = useBlockComments( postId );
116
- useEnableFloatingSidebar( resultComments.length > 0 );
117
-
118
- const hasMoreComments = totalPages && totalPages > 1;
103
+ useEnableFloatingSidebar(
104
+ showFloatingSidebar &&
105
+ ( unresolvedSortedThreads.length > 0 || showCommentBoard )
106
+ );
119
107
 
120
108
  // Get the global styles to set the background color of the sidebar.
121
109
  const { merged: GlobalStyles } = useGlobalStylesContext();
@@ -126,18 +114,19 @@ export default function CollabSidebar() {
126
114
  ? resultComments.find( ( thread ) => thread.id === blockCommentId )
127
115
  : null;
128
116
 
129
- // If postId is not a valid number, do not render the comment sidebar.
130
- if ( ! ( !! postId && typeof postId === 'number' ) ) {
131
- return null;
132
- }
133
-
134
117
  async function openTheSidebar() {
135
118
  const prevArea = await getActiveComplementaryArea( 'core' );
136
119
  const activeNotesArea = SIDEBARS.find( ( name ) => name === prevArea );
137
120
 
138
- // If the notes sidebar is not already active, enable the pinned sidebar.
139
- if ( ! activeNotesArea ) {
140
- enableComplementaryArea( 'core', collabSidebarName );
121
+ if ( currentThread?.status === 'approved' ) {
122
+ enableComplementaryArea( 'core', collabHistorySidebarName );
123
+ } else if ( ! activeNotesArea ) {
124
+ enableComplementaryArea(
125
+ 'core',
126
+ showFloatingSidebar
127
+ ? collabSidebarName
128
+ : collabHistorySidebarName
129
+ );
141
130
  }
142
131
 
143
132
  const currentArea = await getActiveComplementaryArea( 'core' );
@@ -160,18 +149,18 @@ export default function CollabSidebar() {
160
149
  { blockCommentId && (
161
150
  <CommentAvatarIndicator
162
151
  thread={ currentThread }
163
- hasMoreComments={ hasMoreComments }
164
152
  onClick={ openTheSidebar }
165
153
  />
166
154
  ) }
167
155
  <AddCommentMenuItem onClick={ openTheSidebar } />
168
156
  <PluginSidebar
169
157
  identifier={ collabHistorySidebarName }
158
+ name={ collabHistorySidebarName }
170
159
  title={ __( 'Notes' ) }
171
160
  icon={ commentIcon }
172
161
  closeLabel={ __( 'Close Notes' ) }
173
162
  >
174
- <CollabSidebarContent
163
+ <NotesSidebarContent
175
164
  comments={ resultComments }
176
165
  showCommentBoard={ showCommentBoard }
177
166
  setShowCommentBoard={ setShowCommentBoard }
@@ -180,38 +169,49 @@ export default function CollabSidebar() {
180
169
  commentLastUpdated={ commentLastUpdated }
181
170
  />
182
171
  </PluginSidebar>
183
- { isLargeViewport &&
184
- ( unresolvedSortedThreads.length > 0 || showCommentBoard ) && (
185
- <PluginSidebar
186
- isPinnable={ false }
187
- header={ false }
188
- identifier={ collabSidebarName }
189
- className="editor-collab-sidebar"
190
- headerClassName="editor-collab-sidebar__header"
191
- backgroundColor={ backgroundColor }
192
- >
193
- <CollabSidebarContent
194
- comments={ unresolvedSortedThreads }
195
- showCommentBoard={ showCommentBoard }
196
- setShowCommentBoard={ setShowCommentBoard }
197
- commentSidebarRef={ commentSidebarRef }
198
- reflowComments={ reflowComments }
199
- commentLastUpdated={ commentLastUpdated }
200
- styles={ {
201
- backgroundColor,
202
- } }
203
- isFloating
204
- />
205
- </PluginSidebar>
206
- ) }
207
- <PluginMoreMenuItem
208
- icon={ commentIcon }
209
- onClick={ () =>
210
- enableComplementaryArea( 'core', collabHistorySidebarName )
211
- }
212
- >
213
- { __( 'Notes' ) }
214
- </PluginMoreMenuItem>
172
+ { isLargeViewport && (
173
+ <PluginSidebar
174
+ isPinnable={ false }
175
+ header={ false }
176
+ identifier={ collabSidebarName }
177
+ className="editor-collab-sidebar"
178
+ headerClassName="editor-collab-sidebar__header"
179
+ backgroundColor={ backgroundColor }
180
+ >
181
+ <NotesSidebarContent
182
+ comments={ unresolvedSortedThreads }
183
+ showCommentBoard={ showCommentBoard }
184
+ setShowCommentBoard={ setShowCommentBoard }
185
+ commentSidebarRef={ commentSidebarRef }
186
+ reflowComments={ reflowComments }
187
+ commentLastUpdated={ commentLastUpdated }
188
+ styles={ {
189
+ backgroundColor,
190
+ } }
191
+ isFloating
192
+ />
193
+ </PluginSidebar>
194
+ ) }
215
195
  </>
216
196
  );
217
197
  }
198
+
199
+ export default function NotesSidebarContainer() {
200
+ const { postId, mode } = useSelect( ( select ) => {
201
+ const { getCurrentPostId, getRenderingMode } = select( editorStore );
202
+ return {
203
+ postId: getCurrentPostId(),
204
+ mode: getRenderingMode(),
205
+ };
206
+ }, [] );
207
+
208
+ if ( ! postId || typeof postId !== 'number' ) {
209
+ return null;
210
+ }
211
+
212
+ return (
213
+ <PostTypeSupportCheck supportKeys="editor.notes">
214
+ <NotesSidebar postId={ postId } mode={ mode } />
215
+ </PostTypeSupportCheck>
216
+ );
217
+ }
@@ -16,7 +16,7 @@
16
16
  }
17
17
 
18
18
  .editor-collab-sidebar-panel {
19
- padding: $grid-unit-20;
19
+ padding: $grid-unit-20 $grid-unit-20 $grid-unit-30;
20
20
  height: 100%;
21
21
  overflow: hidden;
22
22
  }
@@ -161,27 +161,6 @@
161
161
  min-width: auto;
162
162
  background: transparent;
163
163
  border: none;
164
-
165
- &:hover::before {
166
- background: rgba(0, 0, 0, 0.04);
167
- }
168
-
169
- &.has-unresolved {
170
- .comment-avatar-stack {
171
- &::after {
172
- content: "";
173
- position: absolute;
174
- top: -2px;
175
- right: -2px;
176
- width: $grid-unit-10;
177
- height: $grid-unit-10;
178
- background: #d63638;
179
- border-radius: $radius-round;
180
- border: $border-width solid $white;
181
- z-index: 10;
182
- }
183
- }
184
- }
185
164
  }
186
165
 
187
166
  .comment-avatar-stack {