@wordpress/block-library 7.3.2 → 7.4.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 (266) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/archives/edit.js +1 -1
  3. package/build/archives/edit.js.map +1 -1
  4. package/build/audio/edit.js +1 -1
  5. package/build/audio/edit.js.map +1 -1
  6. package/build/audio/edit.native.js +1 -1
  7. package/build/audio/edit.native.js.map +1 -1
  8. package/build/categories/edit.js +8 -3
  9. package/build/categories/edit.js.map +1 -1
  10. package/build/categories/index.js +4 -0
  11. package/build/categories/index.js.map +1 -1
  12. package/build/column/index.js +10 -0
  13. package/build/column/index.js.map +1 -1
  14. package/build/comment-template/hooks.js +11 -3
  15. package/build/comment-template/hooks.js.map +1 -1
  16. package/build/comments-pagination/edit.js +18 -1
  17. package/build/comments-pagination/edit.js.map +1 -1
  18. package/build/comments-query-loop/edit.js +1 -1
  19. package/build/comments-query-loop/edit.js.map +1 -1
  20. package/build/comments-title/edit.js +149 -0
  21. package/build/comments-title/edit.js.map +1 -0
  22. package/build/comments-title/index.js +101 -0
  23. package/build/comments-title/index.js.map +1 -0
  24. package/build/embed/edit.js +12 -18
  25. package/build/embed/edit.js.map +1 -1
  26. package/build/embed/edit.native.js +1 -7
  27. package/build/embed/edit.native.js.map +1 -1
  28. package/build/embed/util.js +29 -4
  29. package/build/embed/util.js.map +1 -1
  30. package/build/file/inspector.js +2 -4
  31. package/build/file/inspector.js.map +1 -1
  32. package/build/gallery/edit.js +1 -1
  33. package/build/gallery/edit.js.map +1 -1
  34. package/build/gallery/v1/edit.js +1 -1
  35. package/build/gallery/v1/edit.js.map +1 -1
  36. package/build/html/edit.js +2 -2
  37. package/build/html/edit.js.map +1 -1
  38. package/build/image/edit.js +4 -6
  39. package/build/image/edit.js.map +1 -1
  40. package/build/image/edit.native.js +1 -1
  41. package/build/image/edit.native.js.map +1 -1
  42. package/build/image/image.js +1 -1
  43. package/build/image/image.js.map +1 -1
  44. package/build/index.js +3 -1
  45. package/build/index.js.map +1 -1
  46. package/build/index.native.js +14 -3
  47. package/build/index.native.js.map +1 -1
  48. package/build/latest-comments/edit.js +1 -1
  49. package/build/latest-comments/edit.js.map +1 -1
  50. package/build/loginout/edit.js +1 -1
  51. package/build/loginout/edit.js.map +1 -1
  52. package/build/media-text/edit.js +1 -2
  53. package/build/media-text/edit.js.map +1 -1
  54. package/build/media-text/edit.native.js +1 -1
  55. package/build/media-text/edit.native.js.map +1 -1
  56. package/build/navigation/edit/index.js +17 -1
  57. package/build/navigation/edit/index.js.map +1 -1
  58. package/build/navigation/edit/navigation-menu-selector.js +7 -2
  59. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  60. package/build/navigation/edit/unsaved-inner-blocks.js +5 -4
  61. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  62. package/build/navigation/index.js +1 -1
  63. package/build/navigation/view-modal.js +37 -0
  64. package/build/navigation/view-modal.js.map +1 -0
  65. package/build/navigation/view.js +1 -34
  66. package/build/navigation/view.js.map +1 -1
  67. package/build/paragraph/edit.native.js +6 -2
  68. package/build/paragraph/edit.native.js.map +1 -1
  69. package/build/post-author/edit.js +1 -1
  70. package/build/post-author/edit.js.map +1 -1
  71. package/build/post-excerpt/edit.js +1 -1
  72. package/build/post-excerpt/edit.js.map +1 -1
  73. package/build/quote/index.js +6 -0
  74. package/build/quote/index.js.map +1 -1
  75. package/build/quote/v2/edit.js +11 -3
  76. package/build/quote/v2/edit.js.map +1 -1
  77. package/build/rss/edit.js +1 -1
  78. package/build/rss/edit.js.map +1 -1
  79. package/build/search/edit.js +11 -9
  80. package/build/search/edit.js.map +1 -1
  81. package/build/spacer/constants.js +9 -0
  82. package/build/spacer/constants.js.map +1 -0
  83. package/build/spacer/controls.js +3 -3
  84. package/build/spacer/controls.js.map +1 -1
  85. package/build/spacer/controls.native.js +2 -2
  86. package/build/spacer/controls.native.js.map +1 -1
  87. package/build/spacer/edit.js +5 -6
  88. package/build/spacer/edit.js.map +1 -1
  89. package/build/table/edit.js +8 -2
  90. package/build/table/edit.js.map +1 -1
  91. package/build/tag-cloud/edit.js +1 -1
  92. package/build/tag-cloud/edit.js.map +1 -1
  93. package/build/video/edit.js +1 -1
  94. package/build/video/edit.js.map +1 -1
  95. package/build/video/edit.native.js +1 -1
  96. package/build/video/edit.native.js.map +1 -1
  97. package/build-module/archives/edit.js +1 -1
  98. package/build-module/archives/edit.js.map +1 -1
  99. package/build-module/audio/edit.js +1 -1
  100. package/build-module/audio/edit.js.map +1 -1
  101. package/build-module/audio/edit.native.js +1 -1
  102. package/build-module/audio/edit.native.js.map +1 -1
  103. package/build-module/categories/edit.js +8 -3
  104. package/build-module/categories/edit.js.map +1 -1
  105. package/build-module/categories/index.js +4 -0
  106. package/build-module/categories/index.js.map +1 -1
  107. package/build-module/column/index.js +10 -0
  108. package/build-module/column/index.js.map +1 -1
  109. package/build-module/comment-template/hooks.js +11 -3
  110. package/build-module/comment-template/hooks.js.map +1 -1
  111. package/build-module/comments-pagination/edit.js +19 -2
  112. package/build-module/comments-pagination/edit.js.map +1 -1
  113. package/build-module/comments-query-loop/edit.js +1 -1
  114. package/build-module/comments-query-loop/edit.js.map +1 -1
  115. package/build-module/comments-title/edit.js +133 -0
  116. package/build-module/comments-title/edit.js.map +1 -0
  117. package/build-module/comments-title/index.js +88 -0
  118. package/build-module/comments-title/index.js.map +1 -0
  119. package/build-module/embed/edit.js +13 -19
  120. package/build-module/embed/edit.js.map +1 -1
  121. package/build-module/embed/edit.native.js +2 -8
  122. package/build-module/embed/edit.native.js.map +1 -1
  123. package/build-module/embed/util.js +25 -3
  124. package/build-module/embed/util.js.map +1 -1
  125. package/build-module/file/inspector.js +2 -4
  126. package/build-module/file/inspector.js.map +1 -1
  127. package/build-module/gallery/edit.js +1 -1
  128. package/build-module/gallery/edit.js.map +1 -1
  129. package/build-module/gallery/v1/edit.js +1 -1
  130. package/build-module/gallery/v1/edit.js.map +1 -1
  131. package/build-module/html/edit.js +2 -2
  132. package/build-module/html/edit.js.map +1 -1
  133. package/build-module/image/edit.js +4 -6
  134. package/build-module/image/edit.js.map +1 -1
  135. package/build-module/image/edit.native.js +1 -1
  136. package/build-module/image/edit.native.js.map +1 -1
  137. package/build-module/image/image.js +1 -1
  138. package/build-module/image/image.js.map +1 -1
  139. package/build-module/index.js +2 -1
  140. package/build-module/index.js.map +1 -1
  141. package/build-module/index.native.js +14 -3
  142. package/build-module/index.native.js.map +1 -1
  143. package/build-module/latest-comments/edit.js +1 -1
  144. package/build-module/latest-comments/edit.js.map +1 -1
  145. package/build-module/loginout/edit.js +1 -1
  146. package/build-module/loginout/edit.js.map +1 -1
  147. package/build-module/media-text/edit.js +1 -2
  148. package/build-module/media-text/edit.js.map +1 -1
  149. package/build-module/media-text/edit.native.js +1 -1
  150. package/build-module/media-text/edit.native.js.map +1 -1
  151. package/build-module/navigation/edit/index.js +17 -1
  152. package/build-module/navigation/edit/index.js.map +1 -1
  153. package/build-module/navigation/edit/navigation-menu-selector.js +6 -2
  154. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  155. package/build-module/navigation/edit/unsaved-inner-blocks.js +5 -4
  156. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  157. package/build-module/navigation/index.js +1 -1
  158. package/build-module/navigation/view-modal.js +32 -0
  159. package/build-module/navigation/view-modal.js.map +1 -0
  160. package/build-module/navigation/view.js +1 -30
  161. package/build-module/navigation/view.js.map +1 -1
  162. package/build-module/paragraph/edit.native.js +6 -2
  163. package/build-module/paragraph/edit.native.js.map +1 -1
  164. package/build-module/post-author/edit.js +1 -1
  165. package/build-module/post-author/edit.js.map +1 -1
  166. package/build-module/post-excerpt/edit.js +1 -1
  167. package/build-module/post-excerpt/edit.js.map +1 -1
  168. package/build-module/quote/index.js +1 -1
  169. package/build-module/quote/index.js.map +1 -1
  170. package/build-module/quote/v2/edit.js +10 -3
  171. package/build-module/quote/v2/edit.js.map +1 -1
  172. package/build-module/rss/edit.js +1 -1
  173. package/build-module/rss/edit.js.map +1 -1
  174. package/build-module/search/edit.js +11 -9
  175. package/build-module/search/edit.js.map +1 -1
  176. package/build-module/spacer/constants.js +2 -0
  177. package/build-module/spacer/constants.js.map +1 -0
  178. package/build-module/spacer/controls.js +2 -2
  179. package/build-module/spacer/controls.js.map +1 -1
  180. package/build-module/spacer/controls.native.js +1 -1
  181. package/build-module/spacer/controls.native.js.map +1 -1
  182. package/build-module/spacer/edit.js +1 -1
  183. package/build-module/spacer/edit.js.map +1 -1
  184. package/build-module/table/edit.js +9 -3
  185. package/build-module/table/edit.js.map +1 -1
  186. package/build-module/tag-cloud/edit.js +1 -1
  187. package/build-module/tag-cloud/edit.js.map +1 -1
  188. package/build-module/video/edit.js +1 -1
  189. package/build-module/video/edit.js.map +1 -1
  190. package/build-module/video/edit.native.js +1 -1
  191. package/build-module/video/edit.native.js.map +1 -1
  192. package/build-style/comments-title/editor-rtl.css +79 -0
  193. package/build-style/comments-title/editor.css +79 -0
  194. package/build-style/common-rtl.css +32 -0
  195. package/build-style/common.css +32 -0
  196. package/build-style/editor-rtl.css +12 -0
  197. package/build-style/editor.css +12 -0
  198. package/build-style/post-comments-form/style-rtl.css +9 -0
  199. package/build-style/post-comments-form/style.css +9 -0
  200. package/build-style/style-rtl.css +79 -0
  201. package/build-style/style.css +79 -0
  202. package/build-style/table/editor-rtl.css +8 -0
  203. package/build-style/table/editor.css +8 -0
  204. package/build-style/table/style-rtl.css +38 -0
  205. package/build-style/table/style.css +38 -0
  206. package/package.json +28 -28
  207. package/src/archives/edit.js +1 -1
  208. package/src/audio/edit.js +1 -1
  209. package/src/audio/edit.native.js +1 -1
  210. package/src/categories/block.json +4 -0
  211. package/src/categories/edit.js +8 -2
  212. package/src/categories/index.php +1 -0
  213. package/src/column/block.json +10 -0
  214. package/src/comment-template/hooks.js +13 -1
  215. package/src/comment-template/index.php +13 -4
  216. package/src/comments-pagination/edit.js +23 -0
  217. package/src/comments-query-loop/edit.js +1 -0
  218. package/src/comments-title/block.json +70 -0
  219. package/src/comments-title/edit.js +197 -0
  220. package/src/comments-title/editor.scss +4 -0
  221. package/src/comments-title/index.js +18 -0
  222. package/src/comments-title/index.php +68 -0
  223. package/src/common.scss +24 -1
  224. package/src/editor.scss +1 -0
  225. package/src/embed/edit.js +19 -24
  226. package/src/embed/edit.native.js +9 -14
  227. package/src/embed/util.js +34 -2
  228. package/src/file/inspector.js +1 -3
  229. package/src/gallery/edit.js +1 -1
  230. package/src/gallery/v1/edit.js +1 -1
  231. package/src/html/edit.js +2 -2
  232. package/src/image/edit.js +2 -4
  233. package/src/image/edit.native.js +1 -1
  234. package/src/image/image.js +1 -1
  235. package/src/index.js +3 -0
  236. package/src/index.native.js +12 -2
  237. package/src/latest-comments/edit.js +1 -1
  238. package/src/loginout/edit.js +1 -1
  239. package/src/media-text/edit.js +1 -2
  240. package/src/media-text/edit.native.js +1 -1
  241. package/src/navigation/block.json +1 -1
  242. package/src/navigation/edit/index.js +24 -0
  243. package/src/navigation/edit/navigation-menu-selector.js +15 -9
  244. package/src/navigation/edit/unsaved-inner-blocks.js +5 -4
  245. package/src/navigation/index.php +5 -0
  246. package/src/navigation/view-modal.js +36 -0
  247. package/src/navigation/view.js +0 -35
  248. package/src/paragraph/edit.native.js +13 -1
  249. package/src/post-author/edit.js +1 -1
  250. package/src/post-comments-form/style.scss +11 -0
  251. package/src/post-excerpt/edit.js +1 -1
  252. package/src/quote/index.js +1 -1
  253. package/src/quote/v2/edit.js +3 -0
  254. package/src/rss/edit.js +1 -1
  255. package/src/search/edit.js +13 -7
  256. package/src/search/index.php +84 -33
  257. package/src/spacer/constants.js +1 -0
  258. package/src/spacer/controls.js +2 -2
  259. package/src/spacer/controls.native.js +1 -1
  260. package/src/spacer/edit.js +1 -2
  261. package/src/table/edit.js +11 -2
  262. package/src/table/editor.scss +13 -0
  263. package/src/table/style.scss +52 -0
  264. package/src/tag-cloud/edit.js +1 -1
  265. package/src/video/edit.js +1 -1
  266. package/src/video/edit.native.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/block-library",
3
- "version": "7.3.2",
3
+ "version": "7.4.0",
4
4
  "description": "Block library for the WordPress editor.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -33,32 +33,32 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@babel/runtime": "^7.16.0",
36
- "@wordpress/a11y": "^3.6.1",
37
- "@wordpress/api-fetch": "^6.3.1",
38
- "@wordpress/autop": "^3.6.1",
39
- "@wordpress/blob": "^3.6.1",
40
- "@wordpress/block-editor": "^8.5.2",
41
- "@wordpress/blocks": "^11.5.2",
42
- "@wordpress/components": "^19.8.1",
43
- "@wordpress/compose": "^5.4.1",
44
- "@wordpress/core-data": "^4.4.2",
45
- "@wordpress/data": "^6.6.1",
46
- "@wordpress/date": "^4.6.1",
47
- "@wordpress/deprecated": "^3.6.1",
48
- "@wordpress/dom": "^3.6.1",
49
- "@wordpress/element": "^4.4.1",
50
- "@wordpress/hooks": "^3.6.1",
51
- "@wordpress/html-entities": "^3.6.1",
52
- "@wordpress/i18n": "^4.6.1",
53
- "@wordpress/icons": "^8.2.1",
54
- "@wordpress/keycodes": "^3.6.1",
55
- "@wordpress/notices": "^3.6.1",
56
- "@wordpress/primitives": "^3.4.1",
57
- "@wordpress/reusable-blocks": "^3.4.2",
58
- "@wordpress/rich-text": "^5.4.1",
59
- "@wordpress/server-side-render": "^3.4.2",
60
- "@wordpress/url": "^3.7.1",
61
- "@wordpress/viewport": "^4.4.1",
36
+ "@wordpress/a11y": "^3.7.0",
37
+ "@wordpress/api-fetch": "^6.4.0",
38
+ "@wordpress/autop": "^3.7.0",
39
+ "@wordpress/blob": "^3.7.0",
40
+ "@wordpress/block-editor": "^8.6.0",
41
+ "@wordpress/blocks": "^11.6.0",
42
+ "@wordpress/components": "^19.9.0",
43
+ "@wordpress/compose": "^5.5.0",
44
+ "@wordpress/core-data": "^4.5.0",
45
+ "@wordpress/data": "^6.7.0",
46
+ "@wordpress/date": "^4.7.0",
47
+ "@wordpress/deprecated": "^3.7.0",
48
+ "@wordpress/dom": "^3.7.0",
49
+ "@wordpress/element": "^4.5.0",
50
+ "@wordpress/hooks": "^3.7.0",
51
+ "@wordpress/html-entities": "^3.7.0",
52
+ "@wordpress/i18n": "^4.7.0",
53
+ "@wordpress/icons": "^8.3.0",
54
+ "@wordpress/keycodes": "^3.7.0",
55
+ "@wordpress/notices": "^3.7.0",
56
+ "@wordpress/primitives": "^3.5.0",
57
+ "@wordpress/reusable-blocks": "^3.5.0",
58
+ "@wordpress/rich-text": "^5.5.0",
59
+ "@wordpress/server-side-render": "^3.5.0",
60
+ "@wordpress/url": "^3.8.0",
61
+ "@wordpress/viewport": "^4.5.0",
62
62
  "classnames": "^2.3.1",
63
63
  "colord": "^2.7.0",
64
64
  "fast-average-color": "4.3.0",
@@ -74,5 +74,5 @@
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  },
77
- "gitHead": "446565ecaa40370173c18926535e975ec5652b71"
77
+ "gitHead": "1ba52312b56db563df2d8d4fba5b00613fb46d8c"
78
78
  }
@@ -17,7 +17,7 @@ export default function ArchivesEdit( { attributes, setAttributes } ) {
17
17
  return (
18
18
  <>
19
19
  <InspectorControls>
20
- <PanelBody title={ __( 'Archives settings' ) }>
20
+ <PanelBody title={ __( 'Settings' ) }>
21
21
  <ToggleControl
22
22
  label={ __( 'Display as dropdown' ) }
23
23
  checked={ displayAsDropdown }
package/src/audio/edit.js CHANGED
@@ -159,7 +159,7 @@ function AudioEdit( {
159
159
  />
160
160
  </BlockControls>
161
161
  <InspectorControls>
162
- <PanelBody title={ __( 'Audio settings' ) }>
162
+ <PanelBody title={ __( 'Settings' ) }>
163
163
  <ToggleControl
164
164
  label={ __( 'Autoplay' ) }
165
165
  onChange={ toggleAttribute( 'autoplay' ) }
@@ -177,7 +177,7 @@ function AudioEdit( {
177
177
  >
178
178
  <View>
179
179
  <InspectorControls>
180
- <PanelBody title={ __( 'Audio settings' ) }>
180
+ <PanelBody title={ __( 'Settings' ) }>
181
181
  <ToggleControl
182
182
  label={ __( 'Autoplay' ) }
183
183
  onChange={ toggleAttribute( 'autoplay' ) }
@@ -22,6 +22,10 @@
22
22
  "showOnlyTopLevel": {
23
23
  "type": "boolean",
24
24
  "default": false
25
+ },
26
+ "showEmpty": {
27
+ "type": "boolean",
28
+ "default": false
25
29
  }
26
30
  },
27
31
  "supports": {
@@ -25,11 +25,12 @@ export default function CategoriesEdit( {
25
25
  showHierarchy,
26
26
  showPostCounts,
27
27
  showOnlyTopLevel,
28
+ showEmpty,
28
29
  },
29
30
  setAttributes,
30
31
  } ) {
31
32
  const selectId = useInstanceId( CategoriesEdit, 'blocks-category-select' );
32
- const query = { per_page: -1, hide_empty: true, context: 'view' };
33
+ const query = { per_page: -1, hide_empty: ! showEmpty, context: 'view' };
33
34
  if ( showOnlyTopLevel ) {
34
35
  query.parent = 0;
35
36
  }
@@ -128,7 +129,7 @@ export default function CategoriesEdit( {
128
129
  return (
129
130
  <div { ...useBlockProps() }>
130
131
  <InspectorControls>
131
- <PanelBody title={ __( 'Categories settings' ) }>
132
+ <PanelBody title={ __( 'Settings' ) }>
132
133
  <ToggleControl
133
134
  label={ __( 'Display as dropdown' ) }
134
135
  checked={ displayAsDropdown }
@@ -144,6 +145,11 @@ export default function CategoriesEdit( {
144
145
  checked={ showOnlyTopLevel }
145
146
  onChange={ toggleAttribute( 'showOnlyTopLevel' ) }
146
147
  />
148
+ <ToggleControl
149
+ label={ __( 'Show empty categories' ) }
150
+ checked={ showEmpty }
151
+ onChange={ toggleAttribute( 'showEmpty' ) }
152
+ />
147
153
  { ! showOnlyTopLevel && (
148
154
  <ToggleControl
149
155
  label={ __( 'Show hierarchy' ) }
@@ -22,6 +22,7 @@ function render_block_core_categories( $attributes ) {
22
22
  'orderby' => 'name',
23
23
  'show_count' => ! empty( $attributes['showPostCounts'] ),
24
24
  'title_li' => '',
25
+ 'hide_empty' => empty( $attributes['showEmpty'] ),
25
26
  );
26
27
  if ( ! empty( $attributes['showOnlyTopLevel'] ) && $attributes['showOnlyTopLevel'] ) {
27
28
  $args['parent'] = 0;
@@ -41,6 +41,16 @@
41
41
  "padding": true
42
42
  }
43
43
  },
44
+ "__experimentalBorder": {
45
+ "color": true,
46
+ "style": true,
47
+ "width": true,
48
+ "__experimentalDefaultControls": {
49
+ "color": true,
50
+ "style": true,
51
+ "width": true
52
+ }
53
+ },
44
54
  "__experimentalLayout": true
45
55
  }
46
56
  }
@@ -7,6 +7,9 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
7
7
  import { addQueryArgs } from '@wordpress/url';
8
8
  import apiFetch from '@wordpress/api-fetch';
9
9
 
10
+ // This is limited by WP REST API
11
+ const MAX_COMMENTS_PER_PAGE = 100;
12
+
10
13
  /**
11
14
  * Return an object with the query args needed to fetch the default page of
12
15
  * comments.
@@ -29,7 +32,8 @@ export const useCommentQueryArgs = ( { postId } ) => {
29
32
 
30
33
  // Get the Discussion settings that may be needed to query the comments.
31
34
  const {
32
- commentsPerPage: perPage,
35
+ pageComments,
36
+ commentsPerPage,
33
37
  defaultCommentsPage: defaultPage,
34
38
  } = useSelect( ( select ) => {
35
39
  const { getSettings } = select( blockEditorStore );
@@ -37,6 +41,14 @@ export const useCommentQueryArgs = ( { postId } ) => {
37
41
  return __experimentalDiscussionSettings;
38
42
  } );
39
43
 
44
+ // WP REST API doesn't allow fetching more than max items limit set per single page of data.
45
+ // As for the editor performance is more important than completeness of data and fetching only the
46
+ // max allowed for single page should be enough for the purpose of design and laying out the page.
47
+ // Fetching over the limit would return an error here but would work with backend query.
48
+ const perPage = pageComments
49
+ ? Math.min( commentsPerPage, MAX_COMMENTS_PER_PAGE )
50
+ : MAX_COMMENTS_PER_PAGE;
51
+
40
52
  // Get the number of the default page.
41
53
  const page = useDefaultPageIndex( {
42
54
  defaultPage,
@@ -8,6 +8,8 @@
8
8
  /**
9
9
  * Function that recursively renders a list of nested comments.
10
10
  *
11
+ * @global int $comment_depth
12
+ *
11
13
  * @param WP_Comment[] $comments The array of comments.
12
14
  * @param WP_Block $block Block instance.
13
15
  * @return string
@@ -31,6 +33,17 @@ function block_core_comment_template_render_comments( $comments, $block ) {
31
33
 
32
34
  $children = $comment->get_children();
33
35
 
36
+ /*
37
+ * We need to create the CSS classes BEFORE recursing into the children.
38
+ * This is because comment_class() uses globals like `$comment_alt`
39
+ * and `$comment_thread_alt` which are order-sensitive.
40
+ *
41
+ * The `false` parameter at the end means that we do NOT want the function
42
+ * to `echo` the output but to return a string.
43
+ * See https://developer.wordpress.org/reference/functions/comment_class/#parameters.
44
+ */
45
+ $comment_classes = comment_class( '', $comment->comment_ID, $comment->comment_post_ID, false );
46
+
34
47
  // If the comment has children, recurse to create the HTML for the nested
35
48
  // comments.
36
49
  if ( ! empty( $children ) ) {
@@ -43,10 +56,6 @@ function block_core_comment_template_render_comments( $comments, $block ) {
43
56
  $comment_depth -= 1;
44
57
  }
45
58
 
46
- // The `false` parameter at the end means that we do NOT want the function to `echo` the output but to return a string.
47
- // See https://developer.wordpress.org/reference/functions/comment_class/#parameters.
48
- $comment_classes = comment_class( '', $comment->comment_ID, $comment->comment_post_ID, false );
49
-
50
59
  $content .= sprintf( '<li id="comment-%1$s" %2$s>%3$s</li>', $comment->comment_ID, $comment_classes, $block_content );
51
60
  }
52
61
 
@@ -7,6 +7,7 @@ import {
7
7
  useBlockProps,
8
8
  useInnerBlocksProps,
9
9
  store as blockEditorStore,
10
+ Warning,
10
11
  } from '@wordpress/block-editor';
11
12
  import { useSelect } from '@wordpress/data';
12
13
  import { getBlockSupport } from '@wordpress/blocks';
@@ -53,6 +54,7 @@ export default function QueryPaginationEdit( {
53
54
  ].includes( innerBlock.name );
54
55
  } );
55
56
  }, [] );
57
+
56
58
  const blockProps = useBlockProps();
57
59
  const innerBlocksProps = useInnerBlocksProps( blockProps, {
58
60
  template: TEMPLATE,
@@ -63,6 +65,27 @@ export default function QueryPaginationEdit( {
63
65
  ],
64
66
  __experimentalLayout: usedLayout,
65
67
  } );
68
+
69
+ // Get the Discussion settings
70
+ const pageComments = useSelect( ( select ) => {
71
+ const { getSettings } = select( blockEditorStore );
72
+ const { __experimentalDiscussionSettings } = getSettings();
73
+ return __experimentalDiscussionSettings?.pageComments;
74
+ }, [] );
75
+
76
+ // If paging comments is not enabled in the Discussion Settings then hide the pagination
77
+ // controls. We don't want to remove them from the template so that when the user enables
78
+ // paging comments, the controls will be visible.
79
+ if ( ! pageComments ) {
80
+ return (
81
+ <Warning>
82
+ { __(
83
+ 'Comments Pagination block: paging comments is disabled in the Discussion Settings'
84
+ ) }
85
+ </Warning>
86
+ );
87
+ }
88
+
66
89
  return (
67
90
  <>
68
91
  { hasNextPreviousBlocks && (
@@ -9,6 +9,7 @@ import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';
9
9
  import CommentsInspectorControls from './edit/comments-inspector-controls';
10
10
 
11
11
  const TEMPLATE = [
12
+ [ 'core/comments-title' ],
12
13
  [
13
14
  'core/comment-template',
14
15
  {},
@@ -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' );