@wordpress/block-library 8.26.0 → 8.27.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 (254) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/avatar/edit.js +2 -2
  3. package/build/avatar/edit.js.map +1 -1
  4. package/build/block/edit.js +76 -13
  5. package/build/block/edit.js.map +1 -1
  6. package/build/block/{v1/edit.native.js → edit.native.js} +4 -4
  7. package/build/block/edit.native.js.map +1 -0
  8. package/build/block/index.js +5 -3
  9. package/build/block/index.js.map +1 -1
  10. package/build/button/edit.js +24 -6
  11. package/build/button/edit.js.map +1 -1
  12. package/build/button/index.js +1 -0
  13. package/build/button/index.js.map +1 -1
  14. package/build/button/save.js +3 -1
  15. package/build/button/save.js.map +1 -1
  16. package/build/cover/edit.native.js +1 -0
  17. package/build/cover/edit.native.js.map +1 -1
  18. package/build/embed/edit.js +3 -2
  19. package/build/embed/edit.js.map +1 -1
  20. package/build/file/index.js +0 -1
  21. package/build/file/index.js.map +1 -1
  22. package/build/footnotes/edit.js +2 -1
  23. package/build/footnotes/edit.js.map +1 -1
  24. package/build/footnotes/format.js +17 -19
  25. package/build/footnotes/format.js.map +1 -1
  26. package/build/heading/edit.js +2 -1
  27. package/build/heading/edit.js.map +1 -1
  28. package/build/heading/edit.native.js +141 -0
  29. package/build/heading/edit.native.js.map +1 -0
  30. package/build/heading/index.js +1 -0
  31. package/build/heading/index.js.map +1 -1
  32. package/build/image/edit.js +8 -4
  33. package/build/image/edit.js.map +1 -1
  34. package/build/image/image.js +33 -7
  35. package/build/image/image.js.map +1 -1
  36. package/build/image/index.js +6 -3
  37. package/build/image/index.js.map +1 -1
  38. package/build/more/index.js +4 -0
  39. package/build/more/index.js.map +1 -1
  40. package/build/navigation/edit/index.js +2 -2
  41. package/build/navigation/edit/index.js.map +1 -1
  42. package/build/navigation/index.js +0 -1
  43. package/build/navigation/index.js.map +1 -1
  44. package/build/paragraph/edit.js +2 -1
  45. package/build/paragraph/edit.js.map +1 -1
  46. package/build/paragraph/index.js +1 -2
  47. package/build/paragraph/index.js.map +1 -1
  48. package/build/paragraph/transforms.js +1 -2
  49. package/build/paragraph/transforms.js.map +1 -1
  50. package/build/post-content/edit.js +2 -2
  51. package/build/post-content/edit.js.map +1 -1
  52. package/build/post-date/edit.js +1 -1
  53. package/build/post-date/edit.js.map +1 -1
  54. package/build/post-navigation-link/edit.js +43 -2
  55. package/build/post-navigation-link/edit.js.map +1 -1
  56. package/build/post-navigation-link/index.js +8 -0
  57. package/build/post-navigation-link/index.js.map +1 -1
  58. package/build/pullquote/index.js +4 -0
  59. package/build/pullquote/index.js.map +1 -1
  60. package/build/query/edit/inspector-controls/index.js +3 -3
  61. package/build/query/edit/inspector-controls/index.js.map +1 -1
  62. package/build/query/edit/query-content.js +2 -2
  63. package/build/query/edit/query-content.js.map +1 -1
  64. package/build/query/edit/query-placeholder.js +6 -7
  65. package/build/query/edit/query-placeholder.js.map +1 -1
  66. package/build/query/index.js +1 -2
  67. package/build/query/index.js.map +1 -1
  68. package/build/query/variations.js +8 -1
  69. package/build/query/variations.js.map +1 -1
  70. package/build/query/view.js +31 -12
  71. package/build/query/view.js.map +1 -1
  72. package/build/search/index.js +0 -1
  73. package/build/search/index.js.map +1 -1
  74. package/build/table-of-contents/hooks.js +2 -2
  75. package/build/table-of-contents/hooks.js.map +1 -1
  76. package/build/template-part/edit/advanced-controls.js +1 -4
  77. package/build/template-part/edit/advanced-controls.js.map +1 -1
  78. package/build/template-part/edit/index.js +39 -17
  79. package/build/template-part/edit/index.js.map +1 -1
  80. package/build/video/edit.native.js +7 -2
  81. package/build/video/edit.native.js.map +1 -1
  82. package/build/video/transforms.js +17 -0
  83. package/build/video/transforms.js.map +1 -1
  84. package/build-module/avatar/edit.js +2 -2
  85. package/build-module/avatar/edit.js.map +1 -1
  86. package/build-module/block/edit.js +76 -13
  87. package/build-module/block/edit.js.map +1 -1
  88. package/build-module/block/{v1/edit.native.js → edit.native.js} +3 -3
  89. package/build-module/block/edit.native.js.map +1 -0
  90. package/build-module/block/index.js +5 -3
  91. package/build-module/block/index.js.map +1 -1
  92. package/build-module/button/edit.js +25 -7
  93. package/build-module/button/edit.js.map +1 -1
  94. package/build-module/button/index.js +1 -0
  95. package/build-module/button/index.js.map +1 -1
  96. package/build-module/button/save.js +4 -2
  97. package/build-module/button/save.js.map +1 -1
  98. package/build-module/cover/edit.native.js +1 -0
  99. package/build-module/cover/edit.native.js.map +1 -1
  100. package/build-module/embed/edit.js +3 -2
  101. package/build-module/embed/edit.js.map +1 -1
  102. package/build-module/file/index.js +0 -1
  103. package/build-module/file/index.js.map +1 -1
  104. package/build-module/footnotes/edit.js +2 -1
  105. package/build-module/footnotes/edit.js.map +1 -1
  106. package/build-module/footnotes/format.js +17 -19
  107. package/build-module/footnotes/format.js.map +1 -1
  108. package/build-module/heading/edit.js +3 -2
  109. package/build-module/heading/edit.js.map +1 -1
  110. package/build-module/heading/edit.native.js +132 -0
  111. package/build-module/heading/edit.native.js.map +1 -0
  112. package/build-module/heading/index.js +1 -0
  113. package/build-module/heading/index.js.map +1 -1
  114. package/build-module/image/edit.js +9 -5
  115. package/build-module/image/edit.js.map +1 -1
  116. package/build-module/image/image.js +33 -7
  117. package/build-module/image/image.js.map +1 -1
  118. package/build-module/image/index.js +6 -3
  119. package/build-module/image/index.js.map +1 -1
  120. package/build-module/more/index.js +4 -0
  121. package/build-module/more/index.js.map +1 -1
  122. package/build-module/navigation/edit/index.js +1 -1
  123. package/build-module/navigation/edit/index.js.map +1 -1
  124. package/build-module/navigation/index.js +0 -1
  125. package/build-module/navigation/index.js.map +1 -1
  126. package/build-module/paragraph/edit.js +3 -2
  127. package/build-module/paragraph/edit.js.map +1 -1
  128. package/build-module/paragraph/index.js +1 -2
  129. package/build-module/paragraph/index.js.map +1 -1
  130. package/build-module/paragraph/transforms.js +1 -2
  131. package/build-module/paragraph/transforms.js.map +1 -1
  132. package/build-module/post-content/edit.js +1 -1
  133. package/build-module/post-content/edit.js.map +1 -1
  134. package/build-module/post-date/edit.js +1 -1
  135. package/build-module/post-date/edit.js.map +1 -1
  136. package/build-module/post-navigation-link/edit.js +44 -3
  137. package/build-module/post-navigation-link/edit.js.map +1 -1
  138. package/build-module/post-navigation-link/index.js +8 -0
  139. package/build-module/post-navigation-link/index.js.map +1 -1
  140. package/build-module/pullquote/index.js +4 -0
  141. package/build-module/pullquote/index.js.map +1 -1
  142. package/build-module/query/edit/inspector-controls/index.js +4 -4
  143. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  144. package/build-module/query/edit/query-content.js +2 -2
  145. package/build-module/query/edit/query-content.js.map +1 -1
  146. package/build-module/query/edit/query-placeholder.js +7 -8
  147. package/build-module/query/edit/query-placeholder.js.map +1 -1
  148. package/build-module/query/index.js +1 -2
  149. package/build-module/query/index.js.map +1 -1
  150. package/build-module/query/variations.js +8 -1
  151. package/build-module/query/variations.js.map +1 -1
  152. package/build-module/query/view.js +30 -9
  153. package/build-module/query/view.js.map +1 -1
  154. package/build-module/search/index.js +0 -1
  155. package/build-module/search/index.js.map +1 -1
  156. package/build-module/table-of-contents/hooks.js +2 -2
  157. package/build-module/table-of-contents/hooks.js.map +1 -1
  158. package/build-module/template-part/edit/advanced-controls.js +1 -4
  159. package/build-module/template-part/edit/advanced-controls.js.map +1 -1
  160. package/build-module/template-part/edit/index.js +38 -16
  161. package/build-module/template-part/edit/index.js.map +1 -1
  162. package/build-module/video/edit.native.js +7 -2
  163. package/build-module/video/edit.native.js.map +1 -1
  164. package/build-module/video/transforms.js +17 -0
  165. package/build-module/video/transforms.js.map +1 -1
  166. package/build-style/common-rtl.css +4 -2
  167. package/build-style/common.css +4 -2
  168. package/build-style/cover/style-rtl.css +1 -2
  169. package/build-style/cover/style.css +1 -2
  170. package/build-style/editor-rtl.css +6 -4
  171. package/build-style/editor.css +6 -4
  172. package/build-style/gallery/style-rtl.css +2 -4
  173. package/build-style/gallery/style.css +2 -4
  174. package/build-style/image/editor-rtl.css +6 -0
  175. package/build-style/image/editor.css +6 -0
  176. package/build-style/page-list/editor-rtl.css +0 -4
  177. package/build-style/page-list/editor.css +0 -4
  178. package/build-style/pullquote/style-rtl.css +10 -1
  179. package/build-style/pullquote/style.css +10 -1
  180. package/build-style/search/style-rtl.css +2 -1
  181. package/build-style/search/style.css +2 -1
  182. package/build-style/style-rtl.css +19 -11
  183. package/build-style/style.css +19 -11
  184. package/build-style/video/style-rtl.css +1 -2
  185. package/build-style/video/style.css +1 -2
  186. package/package.json +34 -32
  187. package/src/avatar/edit.js +16 -18
  188. package/src/block/block.json +3 -0
  189. package/src/block/edit.js +102 -20
  190. package/src/block/{v1/edit.native.js → edit.native.js} +4 -4
  191. package/src/block/index.js +2 -3
  192. package/src/block/index.php +3 -31
  193. package/src/button/block.json +1 -0
  194. package/src/button/edit.js +76 -43
  195. package/src/button/save.js +3 -0
  196. package/src/buttons/test/__snapshots__/edit.native.js.snap +6 -0
  197. package/src/buttons/test/edit.native.js +49 -0
  198. package/src/cover/edit.native.js +1 -0
  199. package/src/embed/edit.js +3 -2
  200. package/src/file/block.json +0 -1
  201. package/src/file/index.php +11 -57
  202. package/src/footnotes/edit.js +2 -1
  203. package/src/footnotes/format.js +34 -31
  204. package/src/footnotes/index.php +20 -11
  205. package/src/gallery/index.php +0 -3
  206. package/src/heading/block.json +1 -0
  207. package/src/heading/edit.js +18 -14
  208. package/src/heading/edit.native.js +144 -0
  209. package/src/image/block.json +7 -3
  210. package/src/image/edit.js +19 -6
  211. package/src/image/editor.scss +6 -1
  212. package/src/image/image.js +101 -42
  213. package/src/image/index.js +6 -0
  214. package/src/image/index.php +14 -51
  215. package/src/more/index.js +6 -0
  216. package/src/navigation/block.json +0 -1
  217. package/src/navigation/edit/index.js +2 -2
  218. package/src/navigation/index.php +777 -28
  219. package/src/navigation-link/index.php +78 -16
  220. package/src/page-list/editor.scss +0 -4
  221. package/src/paragraph/block.json +1 -2
  222. package/src/paragraph/edit.js +23 -19
  223. package/src/post-content/edit.js +2 -2
  224. package/src/post-date/edit.js +38 -33
  225. package/src/post-navigation-link/block.json +8 -0
  226. package/src/post-navigation-link/edit.js +63 -1
  227. package/src/post-navigation-link/index.php +17 -3
  228. package/src/post-terms/index.php +13 -4
  229. package/src/pullquote/block.json +4 -0
  230. package/src/pullquote/style.scss +13 -1
  231. package/src/query/block.json +1 -2
  232. package/src/query/edit/inspector-controls/index.js +137 -146
  233. package/src/query/edit/query-content.js +9 -7
  234. package/src/query/edit/query-placeholder.js +11 -11
  235. package/src/query/index.php +33 -71
  236. package/src/query/variations.js +4 -0
  237. package/src/query/view.js +24 -19
  238. package/src/search/block.json +0 -1
  239. package/src/search/index.php +18 -36
  240. package/src/table-of-contents/hooks.js +2 -2
  241. package/src/template-part/edit/advanced-controls.js +2 -3
  242. package/src/template-part/edit/index.js +77 -50
  243. package/src/template-part/index.php +2 -2
  244. package/src/video/edit.native.js +5 -2
  245. package/src/video/test/edit.native.js +38 -0
  246. package/src/video/transforms.js +32 -0
  247. package/tsconfig.json +1 -0
  248. package/build/block/v1/edit.js +0 -116
  249. package/build/block/v1/edit.js.map +0 -1
  250. package/build/block/v1/edit.native.js.map +0 -1
  251. package/build-module/block/v1/edit.js +0 -108
  252. package/build-module/block/v1/edit.js.map +0 -1
  253. package/build-module/block/v1/edit.native.js.map +0 -1
  254. package/src/block/v1/edit.js +0 -163
@@ -1,6 +1,6 @@
1
1
  <?php
2
2
  /**
3
- * Server-side rendering of the `core/navigation-link` block.
3
+ * Server-side registering and rendering of the `core/navigation-link` block.
4
4
  *
5
5
  * @package WordPress
6
6
  */
@@ -323,12 +323,12 @@ function build_variation_for_navigation_link( $entity, $kind ) {
323
323
  }
324
324
 
325
325
  /**
326
- * Register a variation for a post type / taxonomy for the navigation link block
326
+ * Register a variation for a post type / taxonomy for the navigation link block.
327
327
  *
328
328
  * @param array $variation Variation array from build_variation_for_navigation_link.
329
329
  * @return void
330
330
  */
331
- function register_block_core_navigation_link_variation( $variation ) {
331
+ function block_core_navigation_link_register_variation( $variation ) {
332
332
  // Directly set the variations on the registered block type
333
333
  // because there's no server side registration for variations (see #47170).
334
334
  $navigation_block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' );
@@ -338,16 +338,45 @@ function register_block_core_navigation_link_variation( $variation ) {
338
338
  return;
339
339
  }
340
340
 
341
- $navigation_block_type->variations[] = $variation;
341
+ $navigation_block_type->variations = array_merge(
342
+ $navigation_block_type->variations,
343
+ array( $variation )
344
+ );
345
+ }
346
+
347
+ /**
348
+ * Unregister a variation for a post type / taxonomy for the navigation link block.
349
+ *
350
+ * @param string $name Name of the post type / taxonomy (which was used as variation name).
351
+ * @return void
352
+ */
353
+ function block_core_navigation_link_unregister_variation( $name ) {
354
+ // Directly get the variations from the registered block type
355
+ // because there's no server side (un)registration for variations (see #47170).
356
+ $navigation_block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' );
357
+ // If the block is not registered (yet), there's no need to remove a variation.
358
+ if ( ! $navigation_block_type || empty( $navigation_block_type->variations ) ) {
359
+ return;
360
+ }
361
+ $variations = $navigation_block_type->variations;
362
+ // Search for the variation and remove it from the array.
363
+ foreach ( $variations as $i => $variation ) {
364
+ if ( $variation['name'] === $name ) {
365
+ unset( $variations[ $i ] );
366
+ break;
367
+ }
368
+ }
369
+ // Reindex array after removing one variation.
370
+ $navigation_block_type->variations = array_values( $variations );
342
371
  }
343
372
 
344
373
  /**
345
374
  * Register the navigation link block.
375
+ * Returns an array of variations for the navigation link block.
346
376
  *
347
- * @uses render_block_core_navigation()
348
- * @throws WP_Error An WP_Error exception parsing the block definition.
377
+ * @return array
349
378
  */
350
- function register_block_core_navigation_link() {
379
+ function build_navigation_link_block_variations() {
351
380
  // This will only handle post types and taxonomies registered until this point (init on priority 9).
352
381
  // See action hooks below for other post types and taxonomies.
353
382
  // See https://github.com/WordPress/gutenberg/issues/53826 for details.
@@ -382,32 +411,45 @@ function register_block_core_navigation_link() {
382
411
  }
383
412
  }
384
413
 
414
+ return array_merge( $built_ins, $variations );
415
+ }
416
+
417
+ /**
418
+ * Register the navigation link block.
419
+ *
420
+ * @uses render_block_core_navigation()
421
+ * @throws WP_Error An WP_Error exception parsing the block definition.
422
+ */
423
+ function register_block_core_navigation_link() {
385
424
  register_block_type_from_metadata(
386
425
  __DIR__ . '/navigation-link',
387
426
  array(
388
- 'render_callback' => 'render_block_core_navigation_link',
389
- 'variations' => array_merge( $built_ins, $variations ),
427
+ 'render_callback' => 'render_block_core_navigation_link',
428
+ 'variation_callback' => 'build_navigation_link_block_variations',
390
429
  )
391
430
  );
392
431
  }
393
432
  add_action( 'init', 'register_block_core_navigation_link' );
394
433
  // Register actions for all post types and taxonomies, to add variations when they are registered.
395
434
  // All post types/taxonomies registered before register_block_core_navigation_link, will be handled by that function.
396
- add_action( 'registered_post_type', 'register_block_core_navigation_link_post_type_variation', 10, 2 );
397
- add_action( 'registered_taxonomy', 'register_block_core_navigation_link_taxonomy_variation', 10, 3 );
435
+ add_action( 'registered_post_type', 'block_core_navigation_link_register_post_type_variation', 10, 2 );
436
+ add_action( 'registered_taxonomy', 'block_core_navigation_link_register_taxonomy_variation', 10, 3 );
437
+ // Handle unregistering of post types and taxonomies and remove the variations.
438
+ add_action( 'unregistered_post_type', 'block_core_navigation_link_unregister_post_type_variation' );
439
+ add_action( 'unregistered_taxonomy', 'block_core_navigation_link_unregister_taxonomy_variation' );
398
440
 
399
441
  /**
400
442
  * Register custom post type variations for navigation link on post type registration
401
443
  * Handles all post types registered after the block is registered in register_navigation_link_post_type_variations
402
444
  *
403
- * @param string $post_type The post type name passed from registered_post_type filter.
445
+ * @param string $post_type The post type name passed from registered_post_type action hook.
404
446
  * @param WP_Post_Type $post_type_object The post type object passed from registered_post_type.
405
447
  * @return void
406
448
  */
407
- function register_block_core_navigation_link_post_type_variation( $post_type, $post_type_object ) {
449
+ function block_core_navigation_link_register_post_type_variation( $post_type, $post_type_object ) {
408
450
  if ( $post_type_object->show_in_nav_menus ) {
409
451
  $variation = build_variation_for_navigation_link( $post_type_object, 'post-type' );
410
- register_block_core_navigation_link_variation( $variation );
452
+ block_core_navigation_link_register_variation( $variation );
411
453
  }
412
454
  }
413
455
 
@@ -420,9 +462,29 @@ function register_block_core_navigation_link_post_type_variation( $post_type, $p
420
462
  * @param array $args Array of taxonomy registration arguments.
421
463
  * @return void
422
464
  */
423
- function register_block_core_navigation_link_taxonomy_variation( $taxonomy, $object_type, $args ) {
465
+ function block_core_navigation_link_register_taxonomy_variation( $taxonomy, $object_type, $args ) {
424
466
  if ( isset( $args['show_in_nav_menus'] ) && $args['show_in_nav_menus'] ) {
425
467
  $variation = build_variation_for_navigation_link( (object) $args, 'post-type' );
426
- register_block_core_navigation_link_variation( $variation );
468
+ block_core_navigation_link_register_variation( $variation );
427
469
  }
428
470
  }
471
+
472
+ /**
473
+ * Unregisters a custom post type variation for navigation link on post type unregistration.
474
+ *
475
+ * @param string $post_type The post type name passed from unregistered_post_type action hook.
476
+ * @return void
477
+ */
478
+ function block_core_navigation_link_unregister_post_type_variation( $post_type ) {
479
+ block_core_navigation_link_unregister_variation( $post_type );
480
+ }
481
+
482
+ /**
483
+ * Unregisters a custom taxonomy variation for navigation link on taxonomy unregistration.
484
+ *
485
+ * @param string $taxonomy The taxonomy name passed from unregistered_taxonomy action hook.
486
+ * @return void
487
+ */
488
+ function block_core_navigation_link_unregister_taxonomy_variation( $taxonomy ) {
489
+ block_core_navigation_link_unregister_variation( $taxonomy );
490
+ }
@@ -58,10 +58,6 @@
58
58
  }
59
59
  }
60
60
 
61
- .wp-block-page-list .components-notice {
62
- margin-left: 0;
63
- }
64
-
65
61
  // Space spinner to give it breathing
66
62
  // room when block is selected and has focus outline.
67
63
  .wp-block-page-list__loading-indicator-container {
@@ -7,7 +7,7 @@
7
7
  "description": "Start with the basic building block of all narrative.",
8
8
  "keywords": [ "text" ],
9
9
  "textdomain": "default",
10
- "usesContext": [ "postId" ],
10
+ "usesContext": [ "postId", "pattern/overrides" ],
11
11
  "attributes": {
12
12
  "align": {
13
13
  "type": "string"
@@ -41,7 +41,6 @@
41
41
  "text": true
42
42
  }
43
43
  },
44
- "__experimentalConnections": true,
45
44
  "spacing": {
46
45
  "margin": true,
47
46
  "padding": true,
@@ -19,6 +19,7 @@ import {
19
19
  RichText,
20
20
  useBlockProps,
21
21
  useSettings,
22
+ useBlockEditingMode,
22
23
  } from '@wordpress/block-editor';
23
24
  import { createBlock } from '@wordpress/blocks';
24
25
  import { formatLtr } from '@wordpress/icons';
@@ -108,28 +109,31 @@ function ParagraphBlock( {
108
109
  } ),
109
110
  style: { direction },
110
111
  } );
112
+ const blockEditingMode = useBlockEditingMode();
111
113
 
112
114
  return (
113
115
  <>
114
- <BlockControls group="block">
115
- <AlignmentControl
116
- value={ align }
117
- onChange={ ( newAlign ) =>
118
- setAttributes( {
119
- align: newAlign,
120
- dropCap: hasDropCapDisabled( newAlign )
121
- ? false
122
- : dropCap,
123
- } )
124
- }
125
- />
126
- <ParagraphRTLControl
127
- direction={ direction }
128
- setDirection={ ( newDirection ) =>
129
- setAttributes( { direction: newDirection } )
130
- }
131
- />
132
- </BlockControls>
116
+ { blockEditingMode === 'default' && (
117
+ <BlockControls group="block">
118
+ <AlignmentControl
119
+ value={ align }
120
+ onChange={ ( newAlign ) =>
121
+ setAttributes( {
122
+ align: newAlign,
123
+ dropCap: hasDropCapDisabled( newAlign )
124
+ ? false
125
+ : dropCap,
126
+ } )
127
+ }
128
+ />
129
+ <ParagraphRTLControl
130
+ direction={ direction }
131
+ setDirection={ ( newDirection ) =>
132
+ setAttributes( { direction: newDirection } )
133
+ }
134
+ />
135
+ </BlockControls>
136
+ ) }
133
137
  <InspectorControls group="typography">
134
138
  <DropCapControl
135
139
  clientId={ clientId }
@@ -5,8 +5,8 @@ import { __ } from '@wordpress/i18n';
5
5
  import {
6
6
  useBlockProps,
7
7
  useInnerBlocksProps,
8
- __experimentalRecursionProvider as RecursionProvider,
9
- __experimentalUseHasRecursion as useHasRecursion,
8
+ RecursionProvider,
9
+ useHasRecursion,
10
10
  Warning,
11
11
  } from '@wordpress/block-editor';
12
12
  import {
@@ -108,40 +108,45 @@ export default function PostDateEdit( {
108
108
  setAttributes( { textAlign: nextAlign } );
109
109
  } }
110
110
  />
111
- { date && ! isDescendentOfQueryLoop && (
112
- <ToolbarGroup>
113
- <Dropdown
114
- popoverProps={ popoverProps }
115
- renderContent={ ( { onClose } ) => (
116
- <PublishDateTimePicker
117
- currentDate={ date }
118
- onChange={ setDate }
119
- is12Hour={ is12HourFormat(
120
- siteTimeFormat
121
- ) }
122
- onClose={ onClose }
123
- />
124
- ) }
125
- renderToggle={ ( { isOpen, onToggle } ) => {
126
- const openOnArrowDown = ( event ) => {
127
- if ( ! isOpen && event.keyCode === DOWN ) {
128
- event.preventDefault();
129
- onToggle();
130
- }
131
- };
132
- return (
133
- <ToolbarButton
134
- aria-expanded={ isOpen }
135
- icon={ edit }
136
- title={ __( 'Change Date' ) }
137
- onClick={ onToggle }
138
- onKeyDown={ openOnArrowDown }
111
+ { date &&
112
+ displayType === 'date' &&
113
+ ! isDescendentOfQueryLoop && (
114
+ <ToolbarGroup>
115
+ <Dropdown
116
+ popoverProps={ popoverProps }
117
+ renderContent={ ( { onClose } ) => (
118
+ <PublishDateTimePicker
119
+ currentDate={ date }
120
+ onChange={ setDate }
121
+ is12Hour={ is12HourFormat(
122
+ siteTimeFormat
123
+ ) }
124
+ onClose={ onClose }
139
125
  />
140
- );
141
- } }
142
- />
143
- </ToolbarGroup>
144
- ) }
126
+ ) }
127
+ renderToggle={ ( { isOpen, onToggle } ) => {
128
+ const openOnArrowDown = ( event ) => {
129
+ if (
130
+ ! isOpen &&
131
+ event.keyCode === DOWN
132
+ ) {
133
+ event.preventDefault();
134
+ onToggle();
135
+ }
136
+ };
137
+ return (
138
+ <ToolbarButton
139
+ aria-expanded={ isOpen }
140
+ icon={ edit }
141
+ title={ __( 'Change Date' ) }
142
+ onClick={ onToggle }
143
+ onKeyDown={ openOnArrowDown }
144
+ />
145
+ );
146
+ } }
147
+ />
148
+ </ToolbarGroup>
149
+ ) }
145
150
  </BlockControls>
146
151
 
147
152
  <InspectorControls>
@@ -28,8 +28,16 @@
28
28
  "arrow": {
29
29
  "type": "string",
30
30
  "default": "none"
31
+ },
32
+ "inSameTerm": {
33
+ "type": "boolean"
34
+ },
35
+ "taxonomy": {
36
+ "type": "string",
37
+ "default": ""
31
38
  }
32
39
  },
40
+ "usesContext": [ "postType" ],
33
41
  "supports": {
34
42
  "reusable": false,
35
43
  "html": false,
@@ -10,6 +10,7 @@ import {
10
10
  __experimentalToggleGroupControl as ToggleGroupControl,
11
11
  __experimentalToggleGroupControlOption as ToggleGroupControlOption,
12
12
  ToggleControl,
13
+ SelectControl,
13
14
  PanelBody,
14
15
  } from '@wordpress/components';
15
16
  import {
@@ -20,9 +21,20 @@ import {
20
21
  useBlockProps,
21
22
  } from '@wordpress/block-editor';
22
23
  import { __, _x } from '@wordpress/i18n';
24
+ import { useSelect } from '@wordpress/data';
25
+ import { store as coreStore } from '@wordpress/core-data';
23
26
 
24
27
  export default function PostNavigationLinkEdit( {
25
- attributes: { type, label, showTitle, textAlign, linkLabel, arrow },
28
+ context: { postType },
29
+ attributes: {
30
+ type,
31
+ label,
32
+ showTitle,
33
+ textAlign,
34
+ linkLabel,
35
+ arrow,
36
+ taxonomy,
37
+ },
26
38
  setAttributes,
27
39
  } ) {
28
40
  const isNext = type === 'next';
@@ -47,6 +59,40 @@ export default function PostNavigationLinkEdit( {
47
59
  [ `has-text-align-${ textAlign }` ]: textAlign,
48
60
  } ),
49
61
  } );
62
+
63
+ const taxonomies = useSelect(
64
+ ( select ) => {
65
+ const { getTaxonomies } = select( coreStore );
66
+ const filteredTaxonomies = getTaxonomies( {
67
+ type: postType,
68
+ per_page: -1,
69
+ context: 'view',
70
+ } );
71
+ return filteredTaxonomies;
72
+ },
73
+ [ postType ]
74
+ );
75
+ const getTaxonomyOptions = () => {
76
+ const selectOption = {
77
+ label: __( 'Unfiltered' ),
78
+ value: '',
79
+ };
80
+ const taxonomyOptions = ( taxonomies ?? [] )
81
+ .filter(
82
+ ( tax ) =>
83
+ tax.slug !== 'nav_menu' &&
84
+ tax.slug !== 'wp_pattern_category'
85
+ )
86
+ .map( ( item ) => {
87
+ return {
88
+ value: item.slug,
89
+ label: item.name,
90
+ };
91
+ } );
92
+
93
+ return [ selectOption, ...taxonomyOptions ];
94
+ };
95
+
50
96
  return (
51
97
  <>
52
98
  <InspectorControls>
@@ -114,6 +160,22 @@ export default function PostNavigationLinkEdit( {
114
160
  </ToggleGroupControl>
115
161
  </PanelBody>
116
162
  </InspectorControls>
163
+ <InspectorControls group="advanced">
164
+ <SelectControl
165
+ label={ __( 'Filter by taxonomy' ) }
166
+ value={ taxonomy }
167
+ options={ getTaxonomyOptions() }
168
+ onChange={ ( value ) =>
169
+ setAttributes( {
170
+ taxonomy: value,
171
+ inSameTerm: value === '' ? false : true,
172
+ } )
173
+ }
174
+ help={ __(
175
+ 'Only link to posts that have the same taxonomy terms as the current post. For example the same tags or categories.'
176
+ ) }
177
+ />
178
+ </InspectorControls>
117
179
  <BlockControls>
118
180
  <AlignmentToolbar
119
181
  value={ textAlign }
@@ -99,10 +99,24 @@ function render_block_core_post_navigation_link( $attributes, $content ) {
99
99
  }
100
100
  }
101
101
 
102
- // The dynamic portion of the function name, `$navigation_type`,
103
- // refers to the type of adjacency, 'next' or 'previous'.
102
+ $in_same_term = isset( $attributes['inSameTerm'] ) ? $attributes['inSameTerm'] : false;
103
+ $taxonomy = isset( $attributes['taxonomy'] ) && $in_same_term ? $attributes['taxonomy'] : '';
104
+
105
+ /**
106
+ * The dynamic portion of the function name, `$navigation_type`,
107
+ * Refers to the type of adjacency, 'next' or 'previous'.
108
+ *
109
+ * @See https://developer.wordpress.org/reference/functions/get_previous_post_link/
110
+ * @See https://developer.wordpress.org/reference/functions/get_next_post_link/
111
+ */
104
112
  $get_link_function = "get_{$navigation_type}_post_link";
105
- $content = $get_link_function( $format, $link );
113
+
114
+ if ( $in_same_term ) {
115
+ $content = $get_link_function( $format, $link, $in_same_term, '', $taxonomy );
116
+ } else {
117
+ $content = $get_link_function( $format, $link );
118
+ }
119
+
106
120
  return sprintf(
107
121
  '<div %1$s>%2$s</div>',
108
122
  $wrapper_attributes,
@@ -59,9 +59,11 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
59
59
  }
60
60
 
61
61
  /**
62
- * Registers the `core/post-terms` block on the server.
62
+ * Returns the available variations for the `core/post-terms` block.
63
+ *
64
+ * @return array The available variations for the block.
63
65
  */
64
- function register_block_core_post_terms() {
66
+ function build_post_term_block_variations() {
65
67
  $taxonomies = get_taxonomies(
66
68
  array(
67
69
  'publicly_queryable' => true,
@@ -103,11 +105,18 @@ function register_block_core_post_terms() {
103
105
  }
104
106
  }
105
107
 
108
+ return array_merge( $built_ins, $custom_variations );
109
+ }
110
+
111
+ /**
112
+ * Registers the `core/post-terms` block on the server.
113
+ */
114
+ function register_block_core_post_terms() {
106
115
  register_block_type_from_metadata(
107
116
  __DIR__ . '/post-terms',
108
117
  array(
109
- 'render_callback' => 'render_block_core_post_terms',
110
- 'variations' => array_merge( $built_ins, $custom_variations ),
118
+ 'render_callback' => 'render_block_core_post_terms',
119
+ 'variation_callback' => 'build_post_term_block_variations',
111
120
  )
112
121
  );
113
122
  }
@@ -35,6 +35,10 @@
35
35
  "text": true
36
36
  }
37
37
  },
38
+ "spacing": {
39
+ "margin": true,
40
+ "padding": true
41
+ },
38
42
  "typography": {
39
43
  "fontSize": true,
40
44
  "lineHeight": true,
@@ -1,5 +1,5 @@
1
1
  .wp-block-pullquote {
2
- padding: 3em 0;
2
+ padding: 4em 0;
3
3
  text-align: center; // Default text-alignment where the `textAlign` attribute value isn't specified.
4
4
  overflow-wrap: break-word; // Break long strings of text without spaces so they don't overflow the block.
5
5
  box-sizing: border-box;
@@ -10,6 +10,18 @@
10
10
  color: inherit;
11
11
  }
12
12
 
13
+ blockquote {
14
+ margin: 0;
15
+ }
16
+
17
+ p {
18
+ margin-top: 0;
19
+
20
+ &:last-child {
21
+ margin-bottom: 0;
22
+ }
23
+ }
24
+
13
25
  &.alignleft,
14
26
  &.alignright {
15
27
  max-width: $content-width * 0.5;
@@ -52,6 +52,5 @@
52
52
  "layout": true
53
53
  },
54
54
  "editorStyle": "wp-block-query-editor",
55
- "style": "wp-block-query",
56
- "viewScript": "file:./view.min.js"
55
+ "style": "wp-block-query"
57
56
  }