@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
@@ -6,65 +6,89 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { useSelect } from '@wordpress/data';
10
9
  import {
11
10
  AlignmentControl,
12
11
  BlockControls,
13
12
  Warning,
14
13
  useBlockProps,
14
+ store as blockEditorStore,
15
15
  } from '@wordpress/block-editor';
16
- import { __ } from '@wordpress/i18n';
17
- import { RawHTML } from '@wordpress/element';
18
- import { store as coreStore } from '@wordpress/core-data';
19
-
20
- function PostCommentsDisplay( { postId } ) {
21
- return useSelect(
22
- ( select ) => {
23
- const comments = select( coreStore ).getEntityRecords(
24
- 'root',
25
- 'comment',
26
- {
27
- post: postId,
28
- }
29
- );
30
- // TODO: "No Comments" placeholder should be editable.
31
- return comments && comments.length
32
- ? comments.map( ( comment ) => (
33
- <RawHTML
34
- className="wp-block-post-comments__comment"
35
- key={ comment.id }
36
- >
37
- { comment.content.rendered }
38
- </RawHTML>
39
- ) )
40
- : __( 'No comments.' );
41
- },
42
- [ postId ]
43
- );
44
- }
16
+ import { __, sprintf } from '@wordpress/i18n';
17
+ import { useSelect } from '@wordpress/data';
18
+ import { useEntityProp, store as coreStore } from '@wordpress/core-data';
19
+ import {
20
+ __experimentalUseDisabled as useDisabled,
21
+ useInstanceId,
22
+ } from '@wordpress/compose';
45
23
 
46
24
  export default function PostCommentsEdit( {
47
- attributes,
25
+ attributes: { textAlign },
48
26
  setAttributes,
49
- context,
27
+ context: { postType, postId },
50
28
  } ) {
51
- const { postType, postId } = context;
52
- const { textAlign } = attributes;
29
+ let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId );
30
+ postTitle = postTitle || __( 'Post Title' );
31
+
32
+ const [ commentStatus ] = useEntityProp(
33
+ 'postType',
34
+ postType,
35
+ 'comment_status',
36
+ postId
37
+ );
38
+
39
+ const { avatarURL, defaultCommentStatus } = useSelect(
40
+ ( select ) =>
41
+ select( blockEditorStore ).getSettings()
42
+ .__experimentalDiscussionSettings
43
+ );
44
+
45
+ const isSiteEditor = postType === undefined || postId === undefined;
46
+
47
+ const postTypeSupportsComments = useSelect( ( select ) =>
48
+ postType
49
+ ? !! select( coreStore ).getPostType( postType )?.supports.comments
50
+ : false
51
+ );
52
+
53
+ let warning = __(
54
+ 'Post Comments block: This is just a placeholder, not a real comment. The final styling may differ because it also depends on the current theme. For better compatibility with the Block Editor, please consider replacing this block with the "Comments Query Loop" block.'
55
+ );
56
+ let showPlacholder = true;
57
+
58
+ if ( ! isSiteEditor && 'open' !== commentStatus ) {
59
+ if ( 'closed' === commentStatus ) {
60
+ warning = sprintf(
61
+ /* translators: 1: Post type (i.e. "post", "page") */
62
+ __(
63
+ 'Post Comments block: Comments to this %s are not allowed.'
64
+ ),
65
+ postType
66
+ );
67
+ showPlacholder = false;
68
+ } else if ( ! postTypeSupportsComments ) {
69
+ warning = sprintf(
70
+ /* translators: 1: Post type (i.e. "post", "page") */
71
+ __(
72
+ 'Post Comments block: Comments for this post type (%s) are not enabled.'
73
+ ),
74
+ postType
75
+ );
76
+ showPlacholder = false;
77
+ } else if ( 'open' !== defaultCommentStatus ) {
78
+ warning = __( 'Post Comments block: Comments are not enabled.' );
79
+ showPlacholder = false;
80
+ }
81
+ }
82
+
53
83
  const blockProps = useBlockProps( {
54
84
  className: classnames( {
55
85
  [ `has-text-align-${ textAlign }` ]: textAlign,
56
86
  } ),
57
87
  } );
58
88
 
59
- if ( ! postType || ! postId ) {
60
- return (
61
- <div { ...blockProps }>
62
- <Warning>
63
- { __( 'Post comments block: no post found.' ) }
64
- </Warning>
65
- </div>
66
- );
67
- }
89
+ const disabledRef = useDisabled();
90
+
91
+ const textareaId = useInstanceId( PostCommentsEdit );
68
92
 
69
93
  return (
70
94
  <>
@@ -78,7 +102,143 @@ export default function PostCommentsEdit( {
78
102
  </BlockControls>
79
103
 
80
104
  <div { ...blockProps }>
81
- <PostCommentsDisplay postId={ postId } />
105
+ <Warning>{ warning }</Warning>
106
+
107
+ { showPlacholder && (
108
+ <div
109
+ className="wp-block-post-comments__placeholder"
110
+ ref={ disabledRef }
111
+ >
112
+ <h3>
113
+ { __( 'One response to' ) } “{ postTitle }”
114
+ </h3>
115
+
116
+ <div className="navigation">
117
+ <div className="alignleft">
118
+ <a href="#top">« { __( 'Older Comments' ) }</a>
119
+ </div>
120
+ <div className="alignright">
121
+ <a href="#top">{ __( 'Newer Comments' ) } »</a>
122
+ </div>
123
+ </div>
124
+
125
+ <ol className="commentlist">
126
+ <li className="comment even thread-even depth-1">
127
+ <article className="comment-body">
128
+ <footer className="comment-meta">
129
+ <div className="comment-author vcard">
130
+ <img
131
+ alt="Commenter Avatar"
132
+ src={ avatarURL }
133
+ className="avatar avatar-32 photo"
134
+ height="32"
135
+ width="32"
136
+ loading="lazy"
137
+ />
138
+ <b className="fn">
139
+ <a href="#top" className="url">
140
+ { __(
141
+ 'A WordPress Commenter'
142
+ ) }
143
+ </a>
144
+ </b>{ ' ' }
145
+ <span className="says">
146
+ { __( 'says' ) }:
147
+ </span>
148
+ </div>
149
+
150
+ <div className="comment-metadata">
151
+ <a href="#top">
152
+ <time dateTime="2000-01-01T00:00:00+00:00">
153
+ { __(
154
+ 'January 1, 2000 at 00:00 am'
155
+ ) }
156
+ </time>
157
+ </a>{ ' ' }
158
+ <span className="edit-link">
159
+ <a
160
+ className="comment-edit-link"
161
+ href="#top"
162
+ >
163
+ { __( 'Edit' ) }
164
+ </a>
165
+ </span>
166
+ </div>
167
+ </footer>
168
+
169
+ <div className="comment-content">
170
+ <p>
171
+ { __( 'Hi, this is a comment.' ) }
172
+ <br />
173
+ { __(
174
+ 'To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.'
175
+ ) }
176
+ <br />
177
+ { __(
178
+ 'Commenter avatars come from'
179
+ ) }{ ' ' }
180
+ <a href="https://gravatar.com/">
181
+ Gravatar
182
+ </a>
183
+ .
184
+ </p>
185
+ </div>
186
+
187
+ <div className="reply">
188
+ <a
189
+ className="comment-reply-link"
190
+ href="#top"
191
+ aria-label="Reply to A WordPress Commenter"
192
+ >
193
+ { __( 'Reply' ) }
194
+ </a>
195
+ </div>
196
+ </article>
197
+ </li>
198
+ </ol>
199
+
200
+ <div className="navigation">
201
+ <div className="alignleft">
202
+ <a href="#top">« { __( 'Older Comments' ) }</a>
203
+ </div>
204
+ <div className="alignright">
205
+ <a href="#top">{ __( 'Newer Comments' ) } »</a>
206
+ </div>
207
+ </div>
208
+
209
+ <div className="comment-respond">
210
+ <h3 className="comment-reply-title">
211
+ { __( 'Leave a Reply' ) }
212
+ </h3>
213
+
214
+ <form className="comment-form" noValidate>
215
+ <p className="comment-form-comment">
216
+ <label
217
+ htmlFor={ `comment-${ textareaId }` }
218
+ >
219
+ { __( 'Comment' ) }{ ' ' }
220
+ <span className="required">*</span>
221
+ </label>
222
+ <textarea
223
+ id={ `comment-${ textareaId }` }
224
+ name="comment"
225
+ cols="45"
226
+ rows="8"
227
+ required
228
+ />
229
+ </p>
230
+ <p className="form-submit wp-block-button">
231
+ <input
232
+ name="submit"
233
+ type="submit"
234
+ className="submit wp-block-button__link"
235
+ value={ __( 'Post Comment' ) }
236
+ />
237
+ </p>
238
+ </form>
239
+ </div>
240
+ </div>
241
+ ) }
82
242
  </div>
83
243
  </>
84
244
  );
@@ -0,0 +1,3 @@
1
+ .wp-block-post-comments__placeholder * {
2
+ pointer-events: none;
3
+ }
@@ -1,10 +1,6 @@
1
1
  .wp-block-post-comments {
2
- // Remove extraneous top padding added to the first heading of the block.
3
- > h3:first-of-type {
4
- margin-top: 0;
5
- }
6
-
7
2
  .commentlist {
3
+ clear: both;
8
4
  list-style: none;
9
5
  margin: 0;
10
6
  padding: 0;
@@ -34,6 +34,7 @@
34
34
  }
35
35
  }
36
36
  },
37
+ "editorStyle": "wp-block-post-comments-form-editor",
37
38
  "style": [
38
39
  "wp-block-post-comments-form",
39
40
  "wp-block-buttons",
@@ -14,6 +14,10 @@ import {
14
14
  } from '@wordpress/block-editor';
15
15
  import { useEntityProp } from '@wordpress/core-data';
16
16
  import { __, sprintf } from '@wordpress/i18n';
17
+ import {
18
+ __experimentalUseDisabled as useDisabled,
19
+ useInstanceId,
20
+ } from '@wordpress/compose';
17
21
 
18
22
  export default function PostCommentsFormEdit( {
19
23
  attributes,
@@ -36,6 +40,10 @@ export default function PostCommentsFormEdit( {
36
40
 
37
41
  const isInSiteEditor = postType === undefined || postId === undefined;
38
42
 
43
+ const disabledFormRef = useDisabled();
44
+
45
+ const instanceId = useInstanceId( PostCommentsFormEdit );
46
+
39
47
  return (
40
48
  <>
41
49
  <BlockControls group="block">
@@ -67,8 +75,37 @@ export default function PostCommentsFormEdit( {
67
75
  </Warning>
68
76
  ) }
69
77
 
70
- { ( 'open' === commentStatus || isInSiteEditor ) &&
71
- __( 'Post Comments Form' ) }
78
+ { ( 'open' === commentStatus || isInSiteEditor ) && (
79
+ <div>
80
+ <h3>{ __( 'Leave a Reply' ) }</h3>
81
+ <form
82
+ noValidate
83
+ className="comment-form"
84
+ ref={ disabledFormRef }
85
+ >
86
+ <p>
87
+ <label htmlFor={ `comment-${ instanceId }` }>
88
+ { __( 'Comment' ) }
89
+ </label>
90
+ <textarea
91
+ id={ `comment-${ instanceId }` }
92
+ name="comment"
93
+ cols="45"
94
+ rows="8"
95
+ />
96
+ </p>
97
+ <p>
98
+ <input
99
+ name="submit"
100
+ className="submit wp-block-button__link"
101
+ label={ __( 'Post Comment' ) }
102
+ value={ __( 'Post Comment' ) }
103
+ readOnly
104
+ />
105
+ </p>
106
+ </form>
107
+ </div>
108
+ ) }
72
109
  </div>
73
110
  </>
74
111
  );
@@ -0,0 +1,3 @@
1
+ .wp-block-post-comments-form * {
2
+ pointer-events: none;
3
+ }
@@ -67,4 +67,15 @@
67
67
  margin-top: 0.35em;
68
68
  }
69
69
  }
70
+
71
+ .comment-reply-title {
72
+ align-items: baseline;
73
+ display: flex;
74
+ justify-content: space-between;
75
+ margin-bottom: 0;
76
+
77
+ :where(small) {
78
+ font-size: var(--wp--preset--font-size--medium, smaller);
79
+ }
80
+ }
70
81
  }
@@ -9,7 +9,7 @@ const TEMPLATE = [
9
9
  'core/paragraph',
10
10
  {
11
11
  placeholder: __(
12
- 'Add a text or blocks that will display when the query returns no results.'
12
+ 'Add text or blocks that will display when the query returns no results.'
13
13
  ),
14
14
  },
15
15
  ],