@wordpress/block-library 7.4.0 → 7.5.0

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 (269) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/audio/edit.js +3 -15
  3. package/build/audio/edit.js.map +1 -1
  4. package/build/button/edit.native.js +7 -3
  5. package/build/button/edit.native.js.map +1 -1
  6. package/build/comment-template/edit.js +1 -3
  7. package/build/comment-template/edit.js.map +1 -1
  8. package/build/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  9. package/{build-module/comments-query-loop → build/comments}/edit/comments-inspector-controls.js.map +1 -1
  10. package/build/{comments-query-loop → comments}/edit.js +3 -3
  11. package/build/comments/edit.js.map +1 -0
  12. package/build/{comments-query-loop → comments}/index.js +1 -1
  13. package/build/comments/index.js.map +1 -0
  14. package/build/{comments-query-loop → comments}/save.js +2 -2
  15. package/build/comments/save.js.map +1 -0
  16. package/build/comments-title/edit.js +7 -5
  17. package/build/comments-title/edit.js.map +1 -1
  18. package/build/cover/edit.js +4 -71
  19. package/build/cover/edit.js.map +1 -1
  20. package/build/cover/edit.native.js +36 -15
  21. package/build/cover/edit.native.js.map +1 -1
  22. package/build/cover/transforms.js +77 -6
  23. package/build/cover/transforms.js.map +1 -1
  24. package/build/cover/use-cover-is-dark.js +81 -0
  25. package/build/cover/use-cover-is-dark.js.map +1 -0
  26. package/build/cover/use-cover-is-dark.native.js +60 -0
  27. package/build/cover/use-cover-is-dark.native.js.map +1 -0
  28. package/build/group/index.js +1 -0
  29. package/build/group/index.js.map +1 -1
  30. package/build/heading/transforms.js +8 -4
  31. package/build/heading/transforms.js.map +1 -1
  32. package/build/index.js +4 -6
  33. package/build/index.js.map +1 -1
  34. package/build/latest-posts/edit.native.js +49 -0
  35. package/build/latest-posts/edit.native.js.map +1 -1
  36. package/build/navigation/edit/index.js +5 -28
  37. package/build/navigation/edit/index.js.map +1 -1
  38. package/build/navigation/edit/inner-blocks.js +5 -7
  39. package/build/navigation/edit/inner-blocks.js.map +1 -1
  40. package/build/navigation/index.js +0 -1
  41. package/build/navigation/index.js.map +1 -1
  42. package/build/navigation/view-modal.js +25 -0
  43. package/build/navigation/view-modal.js.map +1 -1
  44. package/build/navigation-link/edit.js +29 -30
  45. package/build/navigation-link/edit.js.map +1 -1
  46. package/build/navigation-submenu/edit.js +14 -14
  47. package/build/navigation-submenu/edit.js.map +1 -1
  48. package/build/paragraph/edit.js +10 -0
  49. package/build/paragraph/edit.js.map +1 -1
  50. package/build/paragraph/use-enter.js +94 -0
  51. package/build/paragraph/use-enter.js.map +1 -0
  52. package/build/post-comment/index.js +1 -1
  53. package/build/post-comments/edit.js +120 -35
  54. package/build/post-comments/edit.js.map +1 -1
  55. package/build/post-comments/index.js +3 -2
  56. package/build/post-comments/index.js.map +1 -1
  57. package/build/post-comments-form/edit.js +38 -4
  58. package/build/post-comments-form/edit.js.map +1 -1
  59. package/build/post-comments-form/form.js +48 -0
  60. package/build/post-comments-form/form.js.map +1 -0
  61. package/build/post-comments-form/index.js +1 -0
  62. package/build/post-comments-form/index.js.map +1 -1
  63. package/build/post-content/edit.js +1 -1
  64. package/build/post-content/edit.js.map +1 -1
  65. package/build/post-excerpt/edit.js +1 -1
  66. package/build/post-excerpt/edit.js.map +1 -1
  67. package/build/post-terms/edit.js +25 -3
  68. package/build/post-terms/edit.js.map +1 -1
  69. package/build/post-terms/index.js +8 -0
  70. package/build/post-terms/index.js.map +1 -1
  71. package/build/query-no-results/edit.js +1 -1
  72. package/build/query-no-results/edit.js.map +1 -1
  73. package/build/quote/index.js +1 -0
  74. package/build/quote/index.js.map +1 -1
  75. package/build/separator/index.js +3 -0
  76. package/build/separator/index.js.map +1 -1
  77. package/build/video/edit.js +3 -7
  78. package/build/video/edit.js.map +1 -1
  79. package/build-module/audio/edit.js +3 -15
  80. package/build-module/audio/edit.js.map +1 -1
  81. package/build-module/button/edit.native.js +7 -3
  82. package/build-module/button/edit.native.js.map +1 -1
  83. package/build-module/comment-template/edit.js +1 -3
  84. package/build-module/comment-template/edit.js.map +1 -1
  85. package/build-module/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  86. package/build-module/comments/edit/comments-inspector-controls.js.map +1 -0
  87. package/build-module/{comments-query-loop → comments}/edit.js +2 -2
  88. package/build-module/comments/edit.js.map +1 -0
  89. package/build-module/{comments-query-loop → comments}/index.js +1 -1
  90. package/build-module/comments/index.js.map +1 -0
  91. package/build-module/{comments-query-loop → comments}/save.js +1 -1
  92. package/build-module/comments/save.js.map +1 -0
  93. package/build-module/comments-title/edit.js +7 -5
  94. package/build-module/comments-title/edit.js.map +1 -1
  95. package/build-module/cover/edit.js +4 -71
  96. package/build-module/cover/edit.js.map +1 -1
  97. package/build-module/cover/edit.native.js +35 -16
  98. package/build-module/cover/edit.native.js.map +1 -1
  99. package/build-module/cover/transforms.js +74 -6
  100. package/build-module/cover/transforms.js.map +1 -1
  101. package/build-module/cover/use-cover-is-dark.js +70 -0
  102. package/build-module/cover/use-cover-is-dark.js.map +1 -0
  103. package/build-module/cover/use-cover-is-dark.native.js +51 -0
  104. package/build-module/cover/use-cover-is-dark.native.js.map +1 -0
  105. package/build-module/group/index.js +1 -0
  106. package/build-module/group/index.js.map +1 -1
  107. package/build-module/heading/transforms.js +8 -4
  108. package/build-module/heading/transforms.js.map +1 -1
  109. package/build-module/index.js +3 -4
  110. package/build-module/index.js.map +1 -1
  111. package/build-module/latest-posts/edit.native.js +51 -2
  112. package/build-module/latest-posts/edit.native.js.map +1 -1
  113. package/build-module/navigation/edit/index.js +6 -28
  114. package/build-module/navigation/edit/index.js.map +1 -1
  115. package/build-module/navigation/edit/inner-blocks.js +5 -7
  116. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  117. package/build-module/navigation/index.js +0 -1
  118. package/build-module/navigation/index.js.map +1 -1
  119. package/build-module/navigation/view-modal.js +24 -0
  120. package/build-module/navigation/view-modal.js.map +1 -1
  121. package/build-module/navigation-link/edit.js +29 -30
  122. package/build-module/navigation-link/edit.js.map +1 -1
  123. package/build-module/navigation-submenu/edit.js +14 -14
  124. package/build-module/navigation-submenu/edit.js.map +1 -1
  125. package/build-module/paragraph/edit.js +9 -0
  126. package/build-module/paragraph/edit.js.map +1 -1
  127. package/build-module/paragraph/use-enter.js +81 -0
  128. package/build-module/paragraph/use-enter.js.map +1 -0
  129. package/build-module/post-comment/index.js +1 -1
  130. package/build-module/post-comments/edit.js +120 -37
  131. package/build-module/post-comments/edit.js.map +1 -1
  132. package/build-module/post-comments/index.js +3 -2
  133. package/build-module/post-comments/index.js.map +1 -1
  134. package/build-module/post-comments-form/edit.js +38 -6
  135. package/build-module/post-comments-form/edit.js.map +1 -1
  136. package/build-module/post-comments-form/form.js +39 -0
  137. package/build-module/post-comments-form/form.js.map +1 -0
  138. package/build-module/post-comments-form/index.js +1 -0
  139. package/build-module/post-comments-form/index.js.map +1 -1
  140. package/build-module/post-content/edit.js +1 -1
  141. package/build-module/post-content/edit.js.map +1 -1
  142. package/build-module/post-excerpt/edit.js +1 -1
  143. package/build-module/post-excerpt/edit.js.map +1 -1
  144. package/build-module/post-terms/edit.js +26 -4
  145. package/build-module/post-terms/edit.js.map +1 -1
  146. package/build-module/post-terms/index.js +8 -0
  147. package/build-module/post-terms/index.js.map +1 -1
  148. package/build-module/query-no-results/edit.js +1 -1
  149. package/build-module/query-no-results/edit.js.map +1 -1
  150. package/build-module/quote/index.js +1 -0
  151. package/build-module/quote/index.js.map +1 -1
  152. package/build-module/separator/index.js +3 -0
  153. package/build-module/separator/index.js.map +1 -1
  154. package/build-module/video/edit.js +3 -7
  155. package/build-module/video/edit.js.map +1 -1
  156. package/build-style/comment-content/style-rtl.css +81 -0
  157. package/build-style/comment-content/style.css +81 -0
  158. package/build-style/{comments-query-loop → comments}/editor-rtl.css +0 -0
  159. package/build-style/{comments-query-loop → comments}/editor.css +0 -0
  160. package/build-style/cover/style-rtl.css +1 -5
  161. package/build-style/cover/style.css +1 -5
  162. package/build-style/editor-rtl.css +12 -4
  163. package/build-style/editor.css +12 -4
  164. package/build-style/latest-posts/style-rtl.css +2 -0
  165. package/build-style/latest-posts/style.css +4 -0
  166. package/build-style/navigation/style-rtl.css +3 -0
  167. package/build-style/navigation/style.css +3 -0
  168. package/build-style/post-comments/editor-rtl.css +79 -0
  169. package/build-style/post-comments/editor.css +79 -0
  170. package/build-style/post-comments/style-rtl.css +6 -4
  171. package/build-style/post-comments/style.css +6 -4
  172. package/build-style/post-comments-form/editor-rtl.css +79 -0
  173. package/build-style/post-comments-form/editor.css +79 -0
  174. package/build-style/style-rtl.css +12 -9
  175. package/build-style/style.css +14 -9
  176. package/package.json +28 -28
  177. package/src/audio/edit.js +2 -7
  178. package/src/button/edit.native.js +6 -3
  179. package/src/comment-author-name/index.php +7 -5
  180. package/src/comment-content/index.php +25 -3
  181. package/src/comment-content/style.scss +5 -0
  182. package/src/comment-edit-link/index.php +1 -4
  183. package/src/comment-reply-link/index.php +1 -4
  184. package/src/comment-template/edit.js +1 -5
  185. package/src/comment-template/index.php +4 -0
  186. package/src/{comments-query-loop → comments}/block.json +1 -1
  187. package/src/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  188. package/src/{comments-query-loop → comments}/edit.js +2 -1
  189. package/src/{comments-query-loop → comments}/editor.scss +0 -0
  190. package/src/{comments-query-loop → comments}/index.js +0 -0
  191. package/src/{comments-query-loop → comments}/save.js +1 -3
  192. package/src/comments-pagination/index.php +4 -0
  193. package/src/comments-title/edit.js +20 -4
  194. package/src/comments-title/index.php +18 -7
  195. package/src/cover/edit.js +2 -67
  196. package/src/cover/edit.native.js +40 -13
  197. package/src/cover/index.php +1 -1
  198. package/src/cover/style.native.scss +4 -0
  199. package/src/cover/style.scss +1 -5
  200. package/src/cover/test/__snapshots__/edit.native.js.snap +6 -6
  201. package/src/cover/test/transforms.js +301 -0
  202. package/src/cover/transforms.js +112 -7
  203. package/src/cover/use-cover-is-dark.js +71 -0
  204. package/src/cover/use-cover-is-dark.native.js +51 -0
  205. package/src/editor.scss +3 -1
  206. package/src/group/block.json +1 -0
  207. package/src/heading/transforms.js +4 -3
  208. package/src/index.js +3 -6
  209. package/src/latest-posts/edit.native.js +56 -1
  210. package/src/latest-posts/style.scss +4 -0
  211. package/src/navigation/block.json +0 -1
  212. package/src/navigation/edit/index.js +6 -36
  213. package/src/navigation/edit/inner-blocks.js +5 -7
  214. package/src/navigation/style.scss +3 -0
  215. package/src/navigation/view-modal.js +32 -0
  216. package/src/navigation-link/edit.js +40 -43
  217. package/src/navigation-submenu/edit.js +13 -17
  218. package/src/paragraph/edit.js +6 -0
  219. package/src/paragraph/use-enter.js +103 -0
  220. package/src/post-author/index.php +1 -1
  221. package/src/post-comment/block.json +1 -1
  222. package/src/post-comments/block.json +3 -2
  223. package/src/post-comments/edit.js +174 -44
  224. package/src/post-comments/editor.scss +3 -0
  225. package/src/post-comments/index.php +2 -0
  226. package/src/post-comments/style.scss +6 -7
  227. package/src/post-comments-form/block.json +1 -0
  228. package/src/post-comments-form/edit.js +52 -23
  229. package/src/post-comments-form/editor.scss +3 -0
  230. package/src/post-comments-form/form.js +43 -0
  231. package/src/post-comments-form/index.php +9 -2
  232. package/src/post-content/edit.js +15 -1
  233. package/src/post-excerpt/edit.js +14 -1
  234. package/src/post-terms/block.json +8 -0
  235. package/src/post-terms/edit.js +28 -1
  236. package/src/post-terms/index.php +12 -2
  237. package/src/query-no-results/edit.js +1 -1
  238. package/src/quote/block.json +1 -0
  239. package/src/separator/block.json +3 -0
  240. package/src/video/edit.js +3 -4
  241. package/build/comments-query-loop/edit/comments-inspector-controls.js.map +0 -1
  242. package/build/comments-query-loop/edit.js.map +0 -1
  243. package/build/comments-query-loop/index.js.map +0 -1
  244. package/build/comments-query-loop/save.js.map +0 -1
  245. package/build/navigation-area/edit.js +0 -110
  246. package/build/navigation-area/edit.js.map +0 -1
  247. package/build/navigation-area/index.js +0 -62
  248. package/build/navigation-area/index.js.map +0 -1
  249. package/build/navigation-area/inner-blocks.js +0 -34
  250. package/build/navigation-area/inner-blocks.js.map +0 -1
  251. package/build/navigation-area/save.js +0 -18
  252. package/build/navigation-area/save.js.map +0 -1
  253. package/build-module/comments-query-loop/edit.js.map +0 -1
  254. package/build-module/comments-query-loop/index.js.map +0 -1
  255. package/build-module/comments-query-loop/save.js.map +0 -1
  256. package/build-module/navigation-area/edit.js +0 -94
  257. package/build-module/navigation-area/edit.js.map +0 -1
  258. package/build-module/navigation-area/index.js +0 -48
  259. package/build-module/navigation-area/index.js.map +0 -1
  260. package/build-module/navigation-area/inner-blocks.js +0 -26
  261. package/build-module/navigation-area/inner-blocks.js.map +0 -1
  262. package/build-module/navigation-area/save.js +0 -10
  263. package/build-module/navigation-area/save.js.map +0 -1
  264. package/src/navigation-area/block.json +0 -23
  265. package/src/navigation-area/edit.js +0 -111
  266. package/src/navigation-area/index.js +0 -26
  267. package/src/navigation-area/index.php +0 -22
  268. package/src/navigation-area/inner-blocks.js +0 -24
  269. package/src/navigation-area/save.js +0 -8
@@ -4,7 +4,7 @@
4
4
  "name": "core/post-comments",
5
5
  "title": "Post Comments (deprecated)",
6
6
  "category": "theme",
7
- "description": "This block is deprecated. Please use the Comments Query Loop block instead.",
7
+ "description": "This block is deprecated. Please use the Comments block instead.",
8
8
  "textdomain": "default",
9
9
  "attributes": {
10
10
  "textAlign": {
@@ -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
  }
@@ -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 { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
20
+
21
+ /**
22
+ * Internal dependencies
23
+ */
24
+ import CommentsForm from '../post-comments-form/form';
45
25
 
46
26
  export default function PostCommentsEdit( {
47
- attributes,
27
+ attributes: { textAlign },
48
28
  setAttributes,
49
- context,
29
+ context: { postType, postId },
50
30
  } ) {
51
- const { postType, postId } = context;
52
- const { textAlign } = attributes;
31
+ let [ postTitle ] = useEntityProp( 'postType', postType, 'title', postId );
32
+ postTitle = postTitle || __( 'Post Title' );
33
+
34
+ const [ commentStatus ] = useEntityProp(
35
+ 'postType',
36
+ postType,
37
+ 'comment_status',
38
+ postId
39
+ );
40
+
41
+ const { avatarURL, defaultCommentStatus } = useSelect(
42
+ ( select ) =>
43
+ select( blockEditorStore ).getSettings()
44
+ .__experimentalDiscussionSettings
45
+ );
46
+
47
+ const isSiteEditor = postType === undefined || postId === undefined;
48
+
49
+ const postTypeSupportsComments = useSelect( ( select ) =>
50
+ postType
51
+ ? !! select( coreStore ).getPostType( postType )?.supports.comments
52
+ : false
53
+ );
54
+
55
+ let warning = __(
56
+ '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" block.'
57
+ );
58
+ let showPlaceholder = true;
59
+
60
+ if ( ! isSiteEditor && 'open' !== commentStatus ) {
61
+ if ( 'closed' === commentStatus ) {
62
+ warning = sprintf(
63
+ /* translators: 1: Post type (i.e. "post", "page") */
64
+ __(
65
+ 'Post Comments block: Comments to this %s are not allowed.'
66
+ ),
67
+ postType
68
+ );
69
+ showPlaceholder = false;
70
+ } else if ( ! postTypeSupportsComments ) {
71
+ warning = sprintf(
72
+ /* translators: 1: Post type (i.e. "post", "page") */
73
+ __(
74
+ 'Post Comments block: Comments for this post type (%s) are not enabled.'
75
+ ),
76
+ postType
77
+ );
78
+ showPlaceholder = false;
79
+ } else if ( 'open' !== defaultCommentStatus ) {
80
+ warning = __( 'Post Comments block: Comments are not enabled.' );
81
+ showPlaceholder = false;
82
+ }
83
+ }
84
+
53
85
  const blockProps = useBlockProps( {
54
86
  className: classnames( {
55
87
  [ `has-text-align-${ textAlign }` ]: textAlign,
56
88
  } ),
57
89
  } );
58
90
 
59
- if ( ! postType || ! postId ) {
60
- return (
61
- <div { ...blockProps }>
62
- <Warning>
63
- { __( 'Post comments block: no post found.' ) }
64
- </Warning>
65
- </div>
66
- );
67
- }
91
+ const disabledRef = useDisabled();
68
92
 
69
93
  return (
70
94
  <>
@@ -78,7 +102,113 @@ export default function PostCommentsEdit( {
78
102
  </BlockControls>
79
103
 
80
104
  <div { ...blockProps }>
81
- <PostCommentsDisplay postId={ postId } />
105
+ <Warning>{ warning }</Warning>
106
+
107
+ { showPlaceholder && (
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
+ <CommentsForm />
210
+ </div>
211
+ ) }
82
212
  </div>
83
213
  </>
84
214
  );
@@ -0,0 +1,3 @@
1
+ .wp-block-post-comments__placeholder * {
2
+ pointer-events: none;
3
+ }
@@ -51,6 +51,8 @@ function render_block_core_post_comments( $attributes, $content, $block ) {
51
51
  $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
52
52
  $output = ob_get_clean();
53
53
 
54
+ wp_enqueue_script( 'comment-reply' );
55
+
54
56
  return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $output );
55
57
  }
56
58
 
@@ -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;
@@ -48,11 +44,14 @@
48
44
  .comment-meta {
49
45
  font-size: 0.875em;
50
46
  line-height: 1.5;
51
- margin-left: -3.25em;
52
-
53
47
  b {
54
48
  font-weight: normal;
55
49
  }
50
+ .comment-awaiting-moderation {
51
+ margin-top: 1em;
52
+ margin-bottom: 1em;
53
+ display: block;
54
+ }
56
55
  }
57
56
 
58
57
  .comment-body .commentmetadata {
@@ -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",
@@ -11,9 +11,15 @@ import {
11
11
  BlockControls,
12
12
  Warning,
13
13
  useBlockProps,
14
+ store as blockEditorStore,
14
15
  } from '@wordpress/block-editor';
15
- import { useEntityProp } from '@wordpress/core-data';
16
+ import { useEntityProp, store as coreStore } from '@wordpress/core-data';
16
17
  import { __, sprintf } from '@wordpress/i18n';
18
+ import { useSelect } from '@wordpress/data';
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+ import CommentsForm from './form';
17
23
 
18
24
  export default function PostCommentsFormEdit( {
19
25
  attributes,
@@ -34,7 +40,49 @@ export default function PostCommentsFormEdit( {
34
40
  } ),
35
41
  } );
36
42
 
37
- const isInSiteEditor = postType === undefined || postId === undefined;
43
+ const isSiteEditor = postType === undefined || postId === undefined;
44
+
45
+ const { defaultCommentStatus } = useSelect(
46
+ ( select ) =>
47
+ select( blockEditorStore ).getSettings()
48
+ .__experimentalDiscussionSettings
49
+ );
50
+
51
+ const postTypeSupportsComments = useSelect( ( select ) =>
52
+ postType
53
+ ? !! select( coreStore ).getPostType( postType )?.supports.comments
54
+ : false
55
+ );
56
+
57
+ let warning = false;
58
+ let showPlaceholder = true;
59
+
60
+ if ( ! isSiteEditor && 'open' !== commentStatus ) {
61
+ if ( 'closed' === commentStatus ) {
62
+ warning = sprintf(
63
+ /* translators: 1: Post type (i.e. "post", "page") */
64
+ __(
65
+ 'Post Comments Form block: Comments on this %s are not allowed.'
66
+ ),
67
+ postType
68
+ );
69
+ showPlaceholder = false;
70
+ } else if ( ! postTypeSupportsComments ) {
71
+ warning = sprintf(
72
+ /* translators: 1: Post type (i.e. "post", "page") */
73
+ __(
74
+ 'Post Comments Form block: Comments for this post type (%s) are not enabled.'
75
+ ),
76
+ postType
77
+ );
78
+ showPlaceholder = false;
79
+ } else if ( 'open' !== defaultCommentStatus ) {
80
+ warning = __(
81
+ 'Post Comments Form block: Comments are not enabled.'
82
+ );
83
+ showPlaceholder = false;
84
+ }
85
+ }
38
86
 
39
87
  return (
40
88
  <>
@@ -47,28 +95,9 @@ export default function PostCommentsFormEdit( {
47
95
  />
48
96
  </BlockControls>
49
97
  <div { ...blockProps }>
50
- { ! commentStatus && ! isInSiteEditor && (
51
- <Warning>
52
- { __(
53
- 'Post Comments Form block: comments are not enabled for this post type.'
54
- ) }
55
- </Warning>
56
- ) }
57
-
58
- { 'open' !== commentStatus && ! isInSiteEditor && (
59
- <Warning>
60
- { sprintf(
61
- /* translators: 1: Post type (i.e. "post", "page") */
62
- __(
63
- 'Post Comments Form block: comments to this %s are not allowed.'
64
- ),
65
- postType
66
- ) }
67
- </Warning>
68
- ) }
98
+ { warning && <Warning>{ warning }</Warning> }
69
99
 
70
- { ( 'open' === commentStatus || isInSiteEditor ) &&
71
- __( 'Post Comments Form' ) }
100
+ { showPlaceholder ? <CommentsForm /> : null }
72
101
  </div>
73
102
  </>
74
103
  );
@@ -0,0 +1,3 @@
1
+ .wp-block-post-comments-form * {
2
+ pointer-events: none;
3
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import {
6
+ __experimentalUseDisabled as useDisabled,
7
+ useInstanceId,
8
+ } from '@wordpress/compose';
9
+
10
+ const CommentsForm = () => {
11
+ const disabledFormRef = useDisabled();
12
+ const instanceId = useInstanceId( CommentsForm );
13
+
14
+ return (
15
+ <div className="comment-respond">
16
+ <h3 className="comment-reply-title">{ __( 'Leave a Reply' ) }</h3>
17
+ <form noValidate className="comment-form" ref={ disabledFormRef }>
18
+ <p>
19
+ <label htmlFor={ `comment-${ instanceId }` }>
20
+ { __( 'Comment' ) }
21
+ </label>
22
+ <textarea
23
+ id={ `comment-${ instanceId }` }
24
+ name="comment"
25
+ cols="45"
26
+ rows="8"
27
+ />
28
+ </p>
29
+ <p className="form-submit wp-block-button">
30
+ <input
31
+ name="submit"
32
+ type="submit"
33
+ className="submit wp-block-button__link"
34
+ label={ __( 'Post Comment' ) }
35
+ value={ __( 'Post Comment' ) }
36
+ />
37
+ </p>
38
+ </form>
39
+ </div>
40
+ );
41
+ };
42
+
43
+ export default CommentsForm;
@@ -18,17 +18,25 @@ function render_block_core_post_comments_form( $attributes, $content, $block ) {
18
18
  return '';
19
19
  }
20
20
 
21
+ if ( post_password_required( $block->context['postId'] ) ) {
22
+ return;
23
+ }
24
+
21
25
  $classes = 'comment-respond'; // See comment further below.
22
26
  if ( isset( $attributes['textAlign'] ) ) {
23
- $classes .= 'has-text-align-' . $attributes['textAlign'];
27
+ $classes .= ' has-text-align-' . $attributes['textAlign'];
24
28
  }
25
29
 
26
30
  $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
27
31
 
32
+ add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );
33
+
28
34
  ob_start();
29
35
  comment_form( array(), $block->context['postId'] );
30
36
  $form = ob_get_clean();
31
37
 
38
+ remove_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );
39
+
32
40
  // We use the outermost wrapping `<div />` returned by `comment_form()`
33
41
  // which is identified by its default classname `comment-respond` to inject
34
42
  // our wrapper attributes. This way, it is guaranteed that all styling applied
@@ -70,4 +78,3 @@ function post_comments_form_block_form_defaults( $fields ) {
70
78
 
71
79
  return $fields;
72
80
  }
73
- add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );
@@ -85,7 +85,21 @@ function Placeholder() {
85
85
  const blockProps = useBlockProps();
86
86
  return (
87
87
  <div { ...blockProps }>
88
- <p>{ __( 'Post Content' ) }</p>
88
+ <p>
89
+ { __(
90
+ 'This is the Post Content block, it will display all the blocks in any single post or page.'
91
+ ) }
92
+ </p>
93
+ <p>
94
+ { __(
95
+ 'That might be a simple arrangement like consecutive paragraphs in a blog post, or a more elaborate composition that includes image galleries, videos, tables, columns, and any other block types.'
96
+ ) }
97
+ </p>
98
+ <p>
99
+ { __(
100
+ 'If there are any Custom Post Types registered at your site, the Post Content block can display the contents of those entries as well.'
101
+ ) }
102
+ </p>
89
103
  </div>
90
104
  );
91
105
  }
@@ -57,7 +57,20 @@ export default function PostExcerptEditor( {
57
57
  return document.body.textContent || document.body.innerText || '';
58
58
  }, [ renderedExcerpt ] );
59
59
  if ( ! postType || ! postId ) {
60
- return <div { ...blockProps }>{ __( 'Post Excerpt' ) }</div>;
60
+ return (
61
+ <div { ...blockProps }>
62
+ <p>
63
+ { __(
64
+ 'This is the Post Excerpt block, it will display the excerpt from single posts.'
65
+ ) }
66
+ </p>
67
+ <p>
68
+ { __(
69
+ 'If there are any Custom Post Types with support for excerpts, the Post Excerpt block can display the excerpts of those entries as well.'
70
+ ) }
71
+ </p>
72
+ </div>
73
+ );
61
74
  }
62
75
  if ( isProtected && ! userCanEdit ) {
63
76
  return (
@@ -16,6 +16,14 @@
16
16
  "separator": {
17
17
  "type": "string",
18
18
  "default": ", "
19
+ },
20
+ "prefix": {
21
+ "type": "string",
22
+ "default": ""
23
+ },
24
+ "suffix": {
25
+ "type": "string",
26
+ "default": ""
19
27
  }
20
28
  },
21
29
  "usesContext": [ "postId", "postType" ],
@@ -13,6 +13,7 @@ import {
13
13
  BlockControls,
14
14
  useBlockProps,
15
15
  useBlockDisplayInformation,
16
+ RichText,
16
17
  } from '@wordpress/block-editor';
17
18
  import { Spinner, TextControl } from '@wordpress/components';
18
19
  import { useSelect } from '@wordpress/data';
@@ -30,7 +31,7 @@ export default function PostTermsEdit( {
30
31
  context,
31
32
  setAttributes,
32
33
  } ) {
33
- const { term, textAlign, separator } = attributes;
34
+ const { term, textAlign, separator, prefix, suffix } = attributes;
34
35
  const { postId, postType } = context;
35
36
 
36
37
  const selectedTerm = useSelect(
@@ -83,6 +84,19 @@ export default function PostTermsEdit( {
83
84
  </InspectorControls>
84
85
  <div { ...blockProps }>
85
86
  { isLoading && <Spinner /> }
87
+ { ! isLoading && hasPostTerms && (
88
+ <RichText
89
+ className="wp-block-post-terms__prefix"
90
+ multiline={ false }
91
+ aria-label={ __( 'Prefix' ) }
92
+ placeholder={ __( 'Prefix' ) + ' ' }
93
+ value={ prefix }
94
+ onChange={ ( value ) =>
95
+ setAttributes( { prefix: value } )
96
+ }
97
+ tagName="span"
98
+ />
99
+ ) }
86
100
  { ! isLoading &&
87
101
  hasPostTerms &&
88
102
  postTerms
@@ -108,6 +122,19 @@ export default function PostTermsEdit( {
108
122
  ! hasPostTerms &&
109
123
  ( selectedTerm?.labels?.no_terms ||
110
124
  __( 'Term items not found.' ) ) }
125
+ { ! isLoading && hasPostTerms && (
126
+ <RichText
127
+ className="wp-block-post-terms__suffix"
128
+ multiline={ false }
129
+ aria-label={ __( 'Suffix' ) }
130
+ placeholder={ ' ' + __( 'Suffix' ) }
131
+ value={ suffix }
132
+ onChange={ ( value ) =>
133
+ setAttributes( { suffix: value } )
134
+ }
135
+ tagName="span"
136
+ />
137
+ ) }
111
138
  </div>
112
139
  </>
113
140
  );
@@ -36,12 +36,22 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
36
36
 
37
37
  $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
38
38
 
39
+ $prefix = "<div $wrapper_attributes>";
40
+ if ( isset( $attributes['prefix'] ) && $attributes['prefix'] ) {
41
+ $prefix .= '<span class="wp-block-post-terms__prefix">' . $attributes['prefix'] . '</span>';
42
+ }
43
+
44
+ $suffix = '</div>';
45
+ if ( isset( $attributes['suffix'] ) && $attributes['suffix'] ) {
46
+ $suffix = '<span class="wp-block-post-terms__suffix">' . $attributes['suffix'] . '</span>' . $suffix;
47
+ }
48
+
39
49
  return get_the_term_list(
40
50
  $block->context['postId'],
41
51
  $attributes['term'],
42
- "<div $wrapper_attributes>",
52
+ $prefix,
43
53
  '<span class="wp-block-post-terms__separator">' . esc_html( $separator ) . '</span>',
44
- '</div>'
54
+ $suffix
45
55
  );
46
56
  }
47
57
 
@@ -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
  ],
@@ -30,6 +30,7 @@
30
30
  "supports": {
31
31
  "anchor": true,
32
32
  "__experimentalSlashInserter": true,
33
+ "__experimentalOnEnter": true,
33
34
  "typography": {
34
35
  "fontSize": true,
35
36
  "lineHeight": true,
@@ -24,6 +24,9 @@
24
24
  "__experimentalDefaultControls": {
25
25
  "background": true
26
26
  }
27
+ },
28
+ "spacing": {
29
+ "margin": [ "top", "bottom" ]
27
30
  }
28
31
  },
29
32
  "styles": [