@wordpress/editor 14.33.4 → 14.33.5

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 (39) hide show
  1. package/build/components/collab-sidebar/add-comment.js +1 -1
  2. package/build/components/collab-sidebar/add-comment.js.map +1 -1
  3. package/build/components/collab-sidebar/comment-menu-item.js +36 -6
  4. package/build/components/collab-sidebar/comment-menu-item.js.map +3 -3
  5. package/build/components/collab-sidebar/comments.js +287 -296
  6. package/build/components/collab-sidebar/comments.js.map +3 -3
  7. package/build/components/collab-sidebar/index.js +23 -10
  8. package/build/components/collab-sidebar/index.js.map +3 -3
  9. package/build/components/collab-sidebar/utils.js +6 -3
  10. package/build/components/collab-sidebar/utils.js.map +2 -2
  11. package/build/components/editor/index.js +2 -2
  12. package/build/components/editor/index.js.map +3 -3
  13. package/build-module/components/collab-sidebar/add-comment.js +1 -1
  14. package/build-module/components/collab-sidebar/add-comment.js.map +1 -1
  15. package/build-module/components/collab-sidebar/comment-menu-item.js +40 -7
  16. package/build-module/components/collab-sidebar/comment-menu-item.js.map +2 -2
  17. package/build-module/components/collab-sidebar/comments.js +287 -296
  18. package/build-module/components/collab-sidebar/comments.js.map +2 -2
  19. package/build-module/components/collab-sidebar/index.js +23 -10
  20. package/build-module/components/collab-sidebar/index.js.map +2 -2
  21. package/build-module/components/collab-sidebar/utils.js +6 -3
  22. package/build-module/components/collab-sidebar/utils.js.map +2 -2
  23. package/build-module/components/editor/index.js +2 -2
  24. package/build-module/components/editor/index.js.map +2 -2
  25. package/build-types/components/collab-sidebar/comment-menu-item.d.ts +3 -2
  26. package/build-types/components/collab-sidebar/comment-menu-item.d.ts.map +1 -1
  27. package/build-types/components/collab-sidebar/comments.d.ts +1 -1
  28. package/build-types/components/collab-sidebar/comments.d.ts.map +1 -1
  29. package/build-types/components/collab-sidebar/index.d.ts.map +1 -1
  30. package/build-types/components/collab-sidebar/utils.d.ts +2 -2
  31. package/build-types/components/collab-sidebar/utils.d.ts.map +1 -1
  32. package/package.json +7 -7
  33. package/src/components/collab-sidebar/add-comment.js +1 -1
  34. package/src/components/collab-sidebar/comment-menu-item.js +51 -11
  35. package/src/components/collab-sidebar/comments.js +8 -19
  36. package/src/components/collab-sidebar/index.js +51 -33
  37. package/src/components/collab-sidebar/utils.js +15 -5
  38. package/src/components/editor/index.js +1 -1
  39. package/tsconfig.tsbuildinfo +1 -1
@@ -4,8 +4,12 @@
4
4
  import { MenuItem } from '@wordpress/components';
5
5
  import { __ } from '@wordpress/i18n';
6
6
  import { comment as commentIcon } from '@wordpress/icons';
7
-
8
- import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
7
+ import {
8
+ privateApis as blockEditorPrivateApis,
9
+ store as blockEditorStore,
10
+ } from '@wordpress/block-editor';
11
+ import { useSelect } from '@wordpress/data';
12
+ import { getUnregisteredTypeHandlerName } from '@wordpress/blocks';
9
13
 
10
14
  /**
11
15
  * Internal dependencies
@@ -14,23 +18,59 @@ import { unlock } from '../../lock-unlock';
14
18
 
15
19
  const { CommentIconSlotFill } = unlock( blockEditorPrivateApis );
16
20
 
17
- const AddCommentMenuItem = ( { onClick } ) => {
21
+ const AddCommentMenuItem = ( { clientId, onClick, isDistractionFree } ) => {
22
+ const block = useSelect(
23
+ ( select ) => {
24
+ return select( blockEditorStore ).getBlock( clientId );
25
+ },
26
+ [ clientId ]
27
+ );
28
+
29
+ if (
30
+ ! block?.isValid ||
31
+ block?.name === getUnregisteredTypeHandlerName()
32
+ ) {
33
+ return null;
34
+ }
35
+
36
+ const isDisabled = isDistractionFree || block?.name === 'core/freeform';
37
+
38
+ let infoText;
39
+
40
+ if ( isDistractionFree ) {
41
+ infoText = __( 'Notes are disabled in distraction free mode.' );
42
+ } else if ( block?.name === 'core/freeform' ) {
43
+ infoText = __( 'Convert to blocks to add notes.' );
44
+ }
45
+
46
+ return (
47
+ <MenuItem
48
+ icon={ commentIcon }
49
+ onClick={ onClick }
50
+ aria-haspopup="dialog"
51
+ disabled={ isDisabled }
52
+ info={ infoText }
53
+ >
54
+ { __( 'Add note' ) }
55
+ </MenuItem>
56
+ );
57
+ };
58
+
59
+ const AddCommentMenuItemFill = ( { onClick, isDistractionFree } ) => {
18
60
  return (
19
61
  <CommentIconSlotFill.Fill>
20
- { ( { onClose } ) => (
21
- <MenuItem
22
- icon={ commentIcon }
62
+ { ( { clientId, onClose } ) => (
63
+ <AddCommentMenuItem
64
+ clientId={ clientId }
65
+ isDistractionFree={ isDistractionFree }
23
66
  onClick={ () => {
24
67
  onClick();
25
68
  onClose();
26
69
  } }
27
- aria-haspopup="dialog"
28
- >
29
- { __( 'Add note' ) }
30
- </MenuItem>
70
+ />
31
71
  ) }
32
72
  </CommentIconSlotFill.Fill>
33
73
  );
34
74
  };
35
75
 
36
- export default AddCommentMenuItem;
76
+ export default AddCommentMenuItemFill;
@@ -308,21 +308,9 @@ export function Comments( {
308
308
  ] );
309
309
 
310
310
  const hasThreads = Array.isArray( threads ) && threads.length > 0;
311
+ // This should no longer happen since https://github.com/WordPress/gutenberg/pull/72872.
311
312
  if ( ! hasThreads && ! isFloating ) {
312
- return (
313
- <>
314
- <AddComment
315
- onSubmit={ onAddReply }
316
- showCommentBoard={ showCommentBoard }
317
- setShowCommentBoard={ setShowCommentBoard }
318
- commentSidebarRef={ commentSidebarRef }
319
- />
320
- <Text as="p">{ __( 'No notes available.' ) }</Text>
321
- <Text as="p" variant="muted">
322
- { __( 'Only logged in users can see Notes.' ) }
323
- </Text>
324
- </>
325
- );
313
+ return null;
326
314
  }
327
315
 
328
316
  return (
@@ -459,8 +447,6 @@ function Thread( {
459
447
  }
460
448
 
461
449
  return (
462
- // Disable reason: role="listitem" does in fact support aria-expanded.
463
- // eslint-disable-next-line jsx-a11y/role-supports-aria-props
464
450
  <VStack
465
451
  className={ clsx( 'editor-collab-sidebar-panel__thread', {
466
452
  'is-selected': isSelected,
@@ -495,7 +481,7 @@ function Thread( {
495
481
  }
496
482
  } }
497
483
  tabIndex={ 0 }
498
- role="listitem"
484
+ role="treeitem"
499
485
  aria-label={ ariaLabel }
500
486
  aria-expanded={ isSelected }
501
487
  ref={ isFloating ? refs.setFloating : undefined }
@@ -586,7 +572,7 @@ function Thread( {
586
572
  />
587
573
  ) }
588
574
  { isSelected && (
589
- <VStack spacing="2">
575
+ <VStack spacing="2" role="treeitem">
590
576
  <HStack alignment="left" spacing="3" justify="flex-start">
591
577
  <CommentAuthorInfo />
592
578
  </HStack>
@@ -716,7 +702,10 @@ const CommentBoard = ( {
716
702
  : [];
717
703
 
718
704
  return (
719
- <VStack spacing="2">
705
+ <VStack
706
+ spacing="2"
707
+ role={ thread.parent !== 0 ? 'treeitem' : undefined }
708
+ >
720
709
  <HStack alignment="left" spacing="3" justify="flex-start">
721
710
  <CommentAuthorInfo
722
711
  avatar={ thread?.author_avatar_urls?.[ 48 ] }
@@ -50,7 +50,7 @@ function NotesSidebarContent( {
50
50
  <VStack
51
51
  className="editor-collab-sidebar-panel"
52
52
  style={ styles }
53
- role="list"
53
+ role="tree"
54
54
  spacing="3"
55
55
  justify="flex-start"
56
56
  ref={ ( node ) => {
@@ -60,6 +60,9 @@ function NotesSidebarContent( {
60
60
  commentSidebarRef.current = node;
61
61
  }
62
62
  } }
63
+ aria-label={
64
+ isFloating ? __( 'Unresolved notes' ) : __( 'All notes' )
65
+ }
63
66
  >
64
67
  <Comments
65
68
  threads={ comments }
@@ -87,17 +90,24 @@ function NotesSidebar( { postId, mode } ) {
87
90
 
88
91
  const showFloatingSidebar = isLargeViewport && mode === 'post-only';
89
92
 
90
- const { clientId, blockCommentId } = useSelect( ( select ) => {
91
- const { getBlockAttributes, getSelectedBlockClientId } =
92
- select( blockEditorStore );
93
- const _clientId = getSelectedBlockClientId();
94
- return {
95
- clientId: _clientId,
96
- blockCommentId: _clientId
97
- ? getBlockAttributes( _clientId )?.metadata?.noteId
98
- : null,
99
- };
100
- }, [] );
93
+ const { clientId, blockCommentId, isDistractionFree } = useSelect(
94
+ ( select ) => {
95
+ const {
96
+ getBlockAttributes,
97
+ getSelectedBlockClientId,
98
+ getSettings,
99
+ } = select( blockEditorStore );
100
+ const _clientId = getSelectedBlockClientId();
101
+ return {
102
+ clientId: _clientId,
103
+ blockCommentId: _clientId
104
+ ? getBlockAttributes( _clientId )?.metadata?.noteId
105
+ : null,
106
+ isDistractionFree: getSettings().isDistractionFree,
107
+ };
108
+ },
109
+ []
110
+ );
101
111
 
102
112
  const {
103
113
  resultComments,
@@ -118,6 +128,8 @@ function NotesSidebar( { postId, mode } ) {
118
128
  const currentThread = blockCommentId
119
129
  ? resultComments.find( ( thread ) => thread.id === blockCommentId )
120
130
  : null;
131
+ const showAllNotesSidebar =
132
+ resultComments.length > 0 || ! showFloatingSidebar;
121
133
 
122
134
  async function openTheSidebar() {
123
135
  const prevArea = await getActiveComplementaryArea( 'core' );
@@ -150,6 +162,10 @@ function NotesSidebar( { postId, mode } ) {
150
162
  toggleBlockSpotlight( clientId, true );
151
163
  }
152
164
 
165
+ if ( isDistractionFree ) {
166
+ return <AddCommentMenuItem isDistractionFree />;
167
+ }
168
+
153
169
  return (
154
170
  <>
155
171
  { blockCommentId && (
@@ -159,27 +175,29 @@ function NotesSidebar( { postId, mode } ) {
159
175
  />
160
176
  ) }
161
177
  <AddCommentMenuItem onClick={ openTheSidebar } />
162
- <PluginSidebar
163
- identifier={ collabHistorySidebarName }
164
- name={ collabHistorySidebarName }
165
- title={ __( 'All notes' ) }
166
- header={
167
- <h2 className="interface-complementary-area-header__title">
168
- { __( 'All notes' ) }
169
- </h2>
170
- }
171
- icon={ commentIcon }
172
- closeLabel={ __( 'Close Notes' ) }
173
- >
174
- <NotesSidebarContent
175
- comments={ resultComments }
176
- showCommentBoard={ showCommentBoard }
177
- setShowCommentBoard={ setShowCommentBoard }
178
- commentSidebarRef={ commentSidebarRef }
179
- reflowComments={ reflowComments }
180
- commentLastUpdated={ commentLastUpdated }
181
- />
182
- </PluginSidebar>
178
+ { showAllNotesSidebar && (
179
+ <PluginSidebar
180
+ identifier={ collabHistorySidebarName }
181
+ name={ collabHistorySidebarName }
182
+ title={ __( 'All notes' ) }
183
+ header={
184
+ <h2 className="interface-complementary-area-header__title">
185
+ { __( 'All notes' ) }
186
+ </h2>
187
+ }
188
+ icon={ commentIcon }
189
+ closeLabel={ __( 'Close Notes' ) }
190
+ >
191
+ <NotesSidebarContent
192
+ comments={ resultComments }
193
+ showCommentBoard={ showCommentBoard }
194
+ setShowCommentBoard={ setShowCommentBoard }
195
+ commentSidebarRef={ commentSidebarRef }
196
+ reflowComments={ reflowComments }
197
+ commentLastUpdated={ commentLastUpdated }
198
+ />
199
+ </PluginSidebar>
200
+ ) }
183
201
  { isLargeViewport && (
184
202
  <PluginSidebar
185
203
  isPinnable={ false }
@@ -99,23 +99,32 @@ export function getCommentExcerpt( text, excerptLength = 10 ) {
99
99
  * @typedef {import('@wordpress/element').RefObject} RefObject
100
100
  *
101
101
  * @param {string} commentId The ID of the comment thread to focus.
102
- * @param {?HTMLElement} container The container element to search within.
102
+ * @param {?HTMLElement} threadContainer The container element to search within.
103
103
  * @param {string} additionalSelector The additional selector to focus on.
104
104
  */
105
- export function focusCommentThread( commentId, container, additionalSelector ) {
106
- if ( ! container ) {
105
+ export function focusCommentThread(
106
+ commentId,
107
+ threadContainer,
108
+ additionalSelector
109
+ ) {
110
+ if ( ! threadContainer ) {
107
111
  return;
108
112
  }
109
113
 
110
114
  // A thread without a commentId is a new comment thread.
111
115
  const threadSelector = commentId
112
- ? `[role=listitem][id="comment-thread-${ commentId }"]`
113
- : '[role=listitem]:not([id])';
116
+ ? `[role=treeitem][id="comment-thread-${ commentId }"]`
117
+ : '[role=treeitem]:not([id])';
114
118
  const selector = additionalSelector
115
119
  ? `${ threadSelector } ${ additionalSelector }`
116
120
  : threadSelector;
117
121
 
118
122
  return new Promise( ( resolve ) => {
123
+ // Watch the sidebar skeleton in case the sidebar disappears and re-appears.
124
+ const container = threadContainer.closest(
125
+ '.interface-interface-skeleton__sidebar'
126
+ );
127
+
119
128
  if ( container.querySelector( selector ) ) {
120
129
  return resolve( container.querySelector( selector ) );
121
130
  }
@@ -129,6 +138,7 @@ export function focusCommentThread( commentId, container, additionalSelector ) {
129
138
  resolve( container.querySelector( selector ) );
130
139
  }
131
140
  } );
141
+
132
142
  observer.observe( container, {
133
143
  childList: true,
134
144
  subtree: true,
@@ -87,11 +87,11 @@ function Editor( {
87
87
  { extraContent }
88
88
  </EditorInterface>
89
89
  { children }
90
- <NotesSidebar />
91
90
  <Sidebar
92
91
  onActionPerformed={ onActionPerformed }
93
92
  extraPanels={ extraSidebarPanels }
94
93
  />
94
+ <NotesSidebar />
95
95
  </ExperimentalEditorProvider>
96
96
  ) }
97
97
  </>