@wordpress/block-library 7.3.2 → 7.3.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 (91) hide show
  1. package/build/comment-template/hooks.js +11 -3
  2. package/build/comment-template/hooks.js.map +1 -1
  3. package/build/comments-pagination/edit.js +18 -1
  4. package/build/comments-pagination/edit.js.map +1 -1
  5. package/build/comments-query-loop/edit.js +2 -2
  6. package/build/comments-query-loop/edit.js.map +1 -1
  7. package/build/comments-title/edit.js +149 -0
  8. package/build/comments-title/edit.js.map +1 -0
  9. package/build/comments-title/index.js +101 -0
  10. package/build/comments-title/index.js.map +1 -0
  11. package/build/index.js +4 -2
  12. package/build/index.js.map +1 -1
  13. package/build/navigation/edit/index.js +17 -1
  14. package/build/navigation/edit/index.js.map +1 -1
  15. package/build/navigation/edit/navigation-menu-selector.js +7 -2
  16. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  17. package/build/post-comments/edit.js +141 -35
  18. package/build/post-comments/edit.js.map +1 -1
  19. package/build/post-comments/index.js +2 -1
  20. package/build/post-comments/index.js.map +1 -1
  21. package/build/post-comments-form/edit.js +22 -1
  22. package/build/post-comments-form/edit.js.map +1 -1
  23. package/build/post-comments-form/index.js +1 -0
  24. package/build/post-comments-form/index.js.map +1 -1
  25. package/build/query-no-results/edit.js +1 -1
  26. package/build/query-no-results/edit.js.map +1 -1
  27. package/build-module/comment-template/hooks.js +11 -3
  28. package/build-module/comment-template/hooks.js.map +1 -1
  29. package/build-module/comments-pagination/edit.js +19 -2
  30. package/build-module/comments-pagination/edit.js.map +1 -1
  31. package/build-module/comments-query-loop/edit.js +2 -2
  32. package/build-module/comments-query-loop/edit.js.map +1 -1
  33. package/build-module/comments-title/edit.js +133 -0
  34. package/build-module/comments-title/edit.js.map +1 -0
  35. package/build-module/comments-title/index.js +88 -0
  36. package/build-module/comments-title/index.js.map +1 -0
  37. package/build-module/index.js +3 -2
  38. package/build-module/index.js.map +1 -1
  39. package/build-module/navigation/edit/index.js +17 -1
  40. package/build-module/navigation/edit/index.js.map +1 -1
  41. package/build-module/navigation/edit/navigation-menu-selector.js +6 -2
  42. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  43. package/build-module/post-comments/edit.js +143 -38
  44. package/build-module/post-comments/edit.js.map +1 -1
  45. package/build-module/post-comments/index.js +2 -1
  46. package/build-module/post-comments/index.js.map +1 -1
  47. package/build-module/post-comments-form/edit.js +21 -1
  48. package/build-module/post-comments-form/edit.js.map +1 -1
  49. package/build-module/post-comments-form/index.js +1 -0
  50. package/build-module/post-comments-form/index.js.map +1 -1
  51. package/build-module/query-no-results/edit.js +1 -1
  52. package/build-module/query-no-results/edit.js.map +1 -1
  53. package/build-style/comments-title/editor-rtl.css +79 -0
  54. package/build-style/comments-title/editor.css +79 -0
  55. package/build-style/editor-rtl.css +12 -0
  56. package/build-style/editor.css +12 -0
  57. package/build-style/post-comments/editor-rtl.css +79 -0
  58. package/build-style/post-comments/editor.css +79 -0
  59. package/build-style/post-comments/style-rtl.css +1 -3
  60. package/build-style/post-comments/style.css +1 -3
  61. package/build-style/post-comments-form/editor-rtl.css +79 -0
  62. package/build-style/post-comments-form/editor.css +79 -0
  63. package/build-style/post-comments-form/style-rtl.css +9 -0
  64. package/build-style/post-comments-form/style.css +9 -0
  65. package/build-style/style-rtl.css +10 -3
  66. package/build-style/style.css +10 -3
  67. package/package.json +9 -9
  68. package/src/comment-edit-link/index.php +1 -4
  69. package/src/comment-reply-link/index.php +1 -4
  70. package/src/comment-template/hooks.js +13 -1
  71. package/src/comment-template/index.php +13 -4
  72. package/src/comments-pagination/edit.js +23 -0
  73. package/src/comments-query-loop/edit.js +2 -0
  74. package/src/comments-title/block.json +70 -0
  75. package/src/comments-title/edit.js +197 -0
  76. package/src/comments-title/editor.scss +4 -0
  77. package/src/comments-title/index.js +18 -0
  78. package/src/comments-title/index.php +68 -0
  79. package/src/editor.scss +3 -0
  80. package/src/index.js +4 -1
  81. package/src/navigation/edit/index.js +24 -0
  82. package/src/navigation/edit/navigation-menu-selector.js +15 -9
  83. package/src/post-comments/block.json +2 -1
  84. package/src/post-comments/edit.js +204 -44
  85. package/src/post-comments/editor.scss +3 -0
  86. package/src/post-comments/style.scss +1 -5
  87. package/src/post-comments-form/block.json +1 -0
  88. package/src/post-comments-form/edit.js +39 -2
  89. package/src/post-comments-form/editor.scss +3 -0
  90. package/src/post-comments-form/style.scss +11 -0
  91. package/src/query-no-results/edit.js +1 -1
@@ -0,0 +1,70 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 2,
4
+ "name": "core/comments-title",
5
+ "title": "Comments Title",
6
+ "category": "theme",
7
+ "ancestor": [ "core/comments-query-loop" ],
8
+ "description": "Displays a title with the number of comments",
9
+ "textdomain": "default",
10
+ "usesContext": [ "postId", "postType" ],
11
+ "attributes": {
12
+ "textAlign": {
13
+ "type": "string"
14
+ },
15
+ "singleCommentLabel": {
16
+ "type": "string"
17
+ },
18
+ "multipleCommentsLabel": {
19
+ "type": "string"
20
+ },
21
+ "showPostTitle": {
22
+ "type": "boolean",
23
+ "default": true
24
+ },
25
+ "showCommentsCount": {
26
+ "type": "boolean",
27
+ "default": true
28
+ },
29
+ "level": {
30
+ "type": "number",
31
+ "default": 2
32
+ }
33
+ },
34
+ "supports": {
35
+ "anchor": false,
36
+ "align": true,
37
+ "html": false,
38
+ "__experimentalBorder": {
39
+ "radius": true,
40
+ "color": true,
41
+ "width": true,
42
+ "style": true
43
+ },
44
+ "color": {
45
+ "gradients": true,
46
+ "__experimentalDefaultControls": {
47
+ "background": true,
48
+ "text": true
49
+ }
50
+ },
51
+ "spacing": {
52
+ "margin": true,
53
+ "padding": true
54
+ },
55
+ "typography": {
56
+ "fontSize": true,
57
+ "lineHeight": true,
58
+ "__experimentalFontStyle": true,
59
+ "__experimentalFontWeight": true,
60
+ "__experimentalFontFamily": true,
61
+ "__experimentalTextTransform": true,
62
+ "__experimentalDefaultControls": {
63
+ "fontSize": true,
64
+ "__experimentalFontFamily": true,
65
+ "__experimentalFontStyle": true,
66
+ "__experimentalFontWeight": true
67
+ }
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,197 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import classnames from 'classnames';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import {
10
+ AlignmentControl,
11
+ BlockControls,
12
+ useBlockProps,
13
+ PlainText,
14
+ InspectorControls,
15
+ } from '@wordpress/block-editor';
16
+ import { __ } from '@wordpress/i18n';
17
+ import { useEntityProp } from '@wordpress/core-data';
18
+ import {
19
+ PanelBody,
20
+ ToggleControl,
21
+ __experimentalToggleGroupControl as ToggleGroupControl,
22
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption,
23
+ } from '@wordpress/components';
24
+ import { useState, useEffect } from '@wordpress/element';
25
+ import apiFetch from '@wordpress/api-fetch';
26
+ import { addQueryArgs } from '@wordpress/url';
27
+
28
+ /**
29
+ * Internal dependencies
30
+ */
31
+ import HeadingLevelDropdown from '../heading/heading-level-dropdown';
32
+
33
+ export default function Edit( {
34
+ attributes: {
35
+ textAlign,
36
+ singleCommentLabel,
37
+ multipleCommentsLabel,
38
+ showPostTitle,
39
+ showCommentsCount,
40
+ level,
41
+ },
42
+ setAttributes,
43
+ context: { postType, postId },
44
+ } ) {
45
+ const TagName = 'h' + level;
46
+ const [ commentsCount, setCommentsCount ] = useState();
47
+ const [ editingMode, setEditingMode ] = useState( 'plural' );
48
+ const [ rawTitle ] = useEntityProp( 'postType', postType, 'title', postId );
49
+ const isSiteEditor = typeof postId === 'undefined';
50
+ const blockProps = useBlockProps( {
51
+ className: classnames( {
52
+ [ `has-text-align-${ textAlign }` ]: textAlign,
53
+ } ),
54
+ } );
55
+
56
+ useEffect( () => {
57
+ if ( isSiteEditor ) {
58
+ setCommentsCount( 3 );
59
+ return;
60
+ }
61
+ const currentPostId = postId;
62
+ apiFetch( {
63
+ path: addQueryArgs( '/wp/v2/comments', {
64
+ post: postId,
65
+ _fields: 'id',
66
+ } ),
67
+ method: 'HEAD',
68
+ parse: false,
69
+ } )
70
+ .then( ( res ) => {
71
+ // Stale requests will have the `currentPostId` of an older closure.
72
+ if ( currentPostId === postId ) {
73
+ setCommentsCount(
74
+ parseInt( res.headers.get( 'X-WP-Total' ) )
75
+ );
76
+ }
77
+ } )
78
+ .catch( () => {
79
+ setCommentsCount( 0 );
80
+ } );
81
+ }, [ postId ] );
82
+
83
+ const blockControls = (
84
+ <BlockControls group="block">
85
+ <AlignmentControl
86
+ value={ textAlign }
87
+ onChange={ ( newAlign ) =>
88
+ setAttributes( { textAlign: newAlign } )
89
+ }
90
+ />
91
+ <HeadingLevelDropdown
92
+ selectedLevel={ level }
93
+ onChange={ ( newLevel ) =>
94
+ setAttributes( { level: newLevel } )
95
+ }
96
+ />
97
+ </BlockControls>
98
+ );
99
+
100
+ const inspectorControls = (
101
+ <InspectorControls>
102
+ <PanelBody title={ __( 'Settings' ) }>
103
+ { isSiteEditor && (
104
+ <ToggleGroupControl
105
+ label={ __( 'Editing mode' ) }
106
+ onChange={ setEditingMode }
107
+ value={ editingMode }
108
+ >
109
+ <ToggleGroupControlOption
110
+ label={ __( 'Singular' ) }
111
+ value="singular"
112
+ />
113
+ <ToggleGroupControlOption
114
+ label={ __( 'Plural' ) }
115
+ value="plural"
116
+ />
117
+ </ToggleGroupControl>
118
+ ) }
119
+ <ToggleControl
120
+ label={ __( 'Show post title' ) }
121
+ checked={ showPostTitle }
122
+ onChange={ ( value ) =>
123
+ setAttributes( { showPostTitle: value } )
124
+ }
125
+ />
126
+ <ToggleControl
127
+ label={ __( 'Show comments count' ) }
128
+ checked={ showCommentsCount }
129
+ onChange={ ( value ) =>
130
+ setAttributes( { showCommentsCount: value } )
131
+ }
132
+ />
133
+ </PanelBody>
134
+ </InspectorControls>
135
+ );
136
+
137
+ const postTitle = isSiteEditor ? __( '"Post Title"' ) : `"${ rawTitle }"`;
138
+
139
+ const singlePlaceholder = showPostTitle
140
+ ? __( 'One response to ' )
141
+ : __( 'One response' );
142
+
143
+ const multiplePlaceholder = showPostTitle
144
+ ? __( 'Responses to ' )
145
+ : __( 'Responses' );
146
+
147
+ return (
148
+ <>
149
+ { blockControls }
150
+ { inspectorControls }
151
+ <TagName { ...blockProps }>
152
+ { editingMode === 'singular' || commentsCount === 1 ? (
153
+ <>
154
+ <PlainText
155
+ __experimentalVersion={ 2 }
156
+ tagName="span"
157
+ aria-label={ singlePlaceholder }
158
+ placeholder={ singlePlaceholder }
159
+ value={ singleCommentLabel }
160
+ onChange={ ( newLabel ) =>
161
+ setAttributes( {
162
+ singleCommentLabel: newLabel,
163
+ } )
164
+ }
165
+ />
166
+ { showPostTitle ? postTitle : null }
167
+ </>
168
+ ) : (
169
+ <>
170
+ { showCommentsCount ? commentsCount : null }
171
+ <PlainText
172
+ __experimentalVersion={ 2 }
173
+ tagName="span"
174
+ aria-label={
175
+ showCommentsCount
176
+ ? ` ${ multiplePlaceholder }`
177
+ : multiplePlaceholder
178
+ }
179
+ placeholder={
180
+ showCommentsCount
181
+ ? ` ${ multiplePlaceholder }`
182
+ : multiplePlaceholder
183
+ }
184
+ value={ multipleCommentsLabel }
185
+ onChange={ ( newLabel ) =>
186
+ setAttributes( {
187
+ multipleCommentsLabel: newLabel,
188
+ } )
189
+ }
190
+ />
191
+ { showPostTitle ? postTitle : null }
192
+ </>
193
+ ) }
194
+ </TagName>
195
+ </>
196
+ );
197
+ }
@@ -0,0 +1,4 @@
1
+
2
+ .wp-block-comments-title.has-background {
3
+ padding: inherit;
4
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { commentTitle as icon } from '@wordpress/icons';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import metadata from './block.json';
10
+ import edit from './edit';
11
+
12
+ const { name } = metadata;
13
+ export { metadata, name };
14
+
15
+ export const settings = {
16
+ icon,
17
+ edit,
18
+ };
@@ -0,0 +1,68 @@
1
+ <?php
2
+ /**
3
+ * Server-side rendering of the `core/comments-title` block.
4
+ *
5
+ * @package WordPress
6
+ */
7
+
8
+ /**
9
+ * Renders the `core/comments-title` block on the server.
10
+ *
11
+ * @param array $attributes Block attributes.
12
+ *
13
+ * @return string Return the post comments title.
14
+ */
15
+ function render_block_core_comments_title( $attributes ) {
16
+
17
+ $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
18
+ $show_post_title = ! empty( $attributes['showPostTitle'] ) && $attributes['showPostTitle'];
19
+ $show_comments_count = ! empty( $attributes['showCommentsCount'] ) && $attributes['showCommentsCount'];
20
+ $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
21
+ $post_title = $show_post_title ? sprintf( '"%1$s"', get_the_title() ) : null;
22
+ $comments_count = number_format_i18n( get_comments_number() );
23
+ $tag_name = 'h2';
24
+ if ( isset( $attributes['level'] ) ) {
25
+ $tag_name = 'h' . $attributes['level'];
26
+ }
27
+
28
+ if ( '0' === $comments_count ) {
29
+ return;
30
+ }
31
+
32
+ $single_default_comment_label = $show_post_title ? __( 'One response to' ) : __( 'One response' );
33
+ $single_comment_label = ! empty( $attributes['singleCommentLabel'] ) ? $attributes['singleCommentLabel'] : $single_default_comment_label;
34
+
35
+ $multiple_default_comment_label = $show_post_title ? __( 'Responses to' ) : __( 'Responses' );
36
+ $multiple_comment_label = ! empty( $attributes['multipleCommentsLabel'] ) ? $attributes['multipleCommentsLabel'] : $multiple_default_comment_label;
37
+
38
+ $comments_title = '%1$s %2$s %3$s';
39
+
40
+ $comments_title = sprintf(
41
+ $comments_title,
42
+ // If there is only one comment, only display the label.
43
+ '1' !== $comments_count && $show_comments_count ? $comments_count : null,
44
+ '1' === $comments_count ? $single_comment_label : $multiple_comment_label,
45
+ $post_title
46
+ );
47
+
48
+ return sprintf(
49
+ '<%1$s id="comments" %2$s>%3$s</%1$s>',
50
+ $tag_name,
51
+ $wrapper_attributes,
52
+ $comments_title
53
+ );
54
+ }
55
+
56
+ /**
57
+ * Registers the `core/comments-title` block on the server.
58
+ */
59
+ function register_block_core_comments_title() {
60
+ register_block_type_from_metadata(
61
+ __DIR__ . '/comments-title',
62
+ array(
63
+ 'render_callback' => 'render_block_core_comments_title',
64
+ )
65
+ );
66
+ }
67
+
68
+ add_action( 'init', 'register_block_core_comments_title' );
package/src/editor.scss CHANGED
@@ -10,6 +10,7 @@
10
10
  @import "./comments-query-loop/editor.scss";
11
11
  @import "./comments-pagination/editor.scss";
12
12
  @import "./comments-pagination-numbers/editor.scss";
13
+ @import "./comments-title/editor.scss";
13
14
  @import "./cover/editor.scss";
14
15
  @import "./embed/editor.scss";
15
16
  @import "./file/editor.scss";
@@ -48,6 +49,8 @@
48
49
  @import "./query-pagination/editor.scss";
49
50
  @import "./query-pagination-numbers/editor.scss";
50
51
  @import "./post-featured-image/editor.scss";
52
+ @import "./post-comments/editor.scss";
53
+ @import "./post-comments-form/editor.scss";
51
54
 
52
55
  :root .editor-styles-wrapper {
53
56
  @include background-colors-deprecated();
package/src/index.js CHANGED
@@ -35,6 +35,7 @@ import * as commentsQueryLoop from './comments-query-loop';
35
35
  import * as commentsPagination from './comments-pagination';
36
36
  import * as commentsPaginationNext from './comments-pagination-next';
37
37
  import * as commentsPaginationNumbers from './comments-pagination-numbers';
38
+ import * as commentsTitle from './comments-title';
38
39
  import * as cover from './cover';
39
40
  import * as embed from './embed';
40
41
  import * as file from './file';
@@ -212,12 +213,15 @@ export const __experimentalGetCoreBlocks = () => [
212
213
  commentEditLink,
213
214
  commentReplyLink,
214
215
  commentTemplate,
216
+ commentsTitle,
215
217
  commentsQueryLoop,
216
218
  commentsPagination,
217
219
  commentsPaginationNext,
218
220
  commentsPaginationNumbers,
219
221
  commentsPaginationPrevious,
222
+
220
223
  postComments,
224
+ postCommentsForm,
221
225
  homeLink,
222
226
  logInOut,
223
227
  termDescription,
@@ -278,7 +282,6 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env
278
282
  navigationArea,
279
283
  postComment,
280
284
  postCommentsCount,
281
- postCommentsForm,
282
285
  postCommentsLink,
283
286
  ]
284
287
  : [] ),
@@ -523,6 +523,11 @@ function Navigation( {
523
523
  ref,
524
524
  ] );
525
525
 
526
+ const navigationSelectorRef = useRef();
527
+ const [
528
+ shouldFocusNavigationSelector,
529
+ setShouldFocusNavigationSelector,
530
+ ] = useState( false );
526
531
  const handleSelectNavigation = useCallback(
527
532
  ( navPostOrClassicMenu ) => {
528
533
  if ( ! navPostOrClassicMenu ) {
@@ -538,10 +543,28 @@ function Navigation( {
538
543
  } else {
539
544
  handleUpdateMenu( navPostOrClassicMenu.id );
540
545
  }
546
+ setShouldFocusNavigationSelector( true );
541
547
  },
542
548
  [ convert, handleUpdateMenu ]
543
549
  );
544
550
 
551
+ // Focus support after menu selection.
552
+ useEffect( () => {
553
+ if (
554
+ isDraftNavigationMenu ||
555
+ ! isEntityAvailable ||
556
+ ! shouldFocusNavigationSelector
557
+ ) {
558
+ return;
559
+ }
560
+ navigationSelectorRef?.current?.focus();
561
+ setShouldFocusNavigationSelector( false );
562
+ }, [
563
+ isDraftNavigationMenu,
564
+ isEntityAvailable,
565
+ shouldFocusNavigationSelector,
566
+ ] );
567
+
545
568
  const resetToEmptyBlock = useCallback( () => {
546
569
  registry.batch( () => {
547
570
  if ( navigationArea ) {
@@ -663,6 +686,7 @@ function Navigation( {
663
686
  { ! isDraftNavigationMenu && isEntityAvailable && (
664
687
  <ToolbarGroup className="wp-block-navigation__toolbar-menu-selector">
665
688
  <NavigationMenuSelector
689
+ ref={ navigationSelectorRef }
666
690
  currentMenuId={ ref }
667
691
  clientId={ clientId }
668
692
  onSelect={ handleSelectNavigation }
@@ -10,7 +10,7 @@ import {
10
10
  import { __, sprintf } from '@wordpress/i18n';
11
11
  import { decodeEntities } from '@wordpress/html-entities';
12
12
  import { addQueryArgs } from '@wordpress/url';
13
- import { useCallback, useMemo } from '@wordpress/element';
13
+ import { forwardRef, useCallback, useMemo } from '@wordpress/element';
14
14
 
15
15
  /**
16
16
  * Internal dependencies
@@ -18,14 +18,17 @@ import { useCallback, useMemo } from '@wordpress/element';
18
18
  import useNavigationMenu from '../use-navigation-menu';
19
19
  import useNavigationEntities from '../use-navigation-entities';
20
20
 
21
- export default function NavigationMenuSelector( {
22
- currentMenuId,
23
- onSelect,
24
- onCreateNew,
25
- showManageActions = false,
26
- actionLabel,
27
- toggleProps = {},
28
- } ) {
21
+ function NavigationMenuSelector(
22
+ {
23
+ currentMenuId,
24
+ onSelect,
25
+ onCreateNew,
26
+ showManageActions = false,
27
+ actionLabel,
28
+ toggleProps = {},
29
+ },
30
+ forwardedRef
31
+ ) {
29
32
  /* translators: %s: The name of a menu. */
30
33
  const createActionLabel = __( "Create from '%s'" );
31
34
 
@@ -92,6 +95,7 @@ export default function NavigationMenuSelector( {
92
95
 
93
96
  return (
94
97
  <ToolbarDropdownMenu
98
+ ref={ forwardedRef }
95
99
  label={ __( 'Select Menu' ) }
96
100
  text={ __( 'Select Menu' ) }
97
101
  icon={ null }
@@ -152,3 +156,5 @@ export default function NavigationMenuSelector( {
152
156
  </ToolbarDropdownMenu>
153
157
  );
154
158
  }
159
+
160
+ export default forwardRef( NavigationMenuSelector );
@@ -40,5 +40,6 @@
40
40
  "wp-block-post-comments",
41
41
  "wp-block-buttons",
42
42
  "wp-block-button"
43
- ]
43
+ ],
44
+ "editorStyle": "wp-block-post-comments-editor"
44
45
  }