@wordpress/block-library 8.22.0 → 8.23.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 (175) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/block/edit.js +3 -2
  3. package/build/block/edit.js.map +1 -1
  4. package/build/button/edit.js +57 -2
  5. package/build/button/edit.js.map +1 -1
  6. package/build/code/transforms.js +20 -7
  7. package/build/code/transforms.js.map +1 -1
  8. package/build/comments/edit/comments-inspector-controls.js +1 -0
  9. package/build/comments/edit/comments-inspector-controls.js.map +1 -1
  10. package/build/cover/edit/inspector-controls.js +1 -0
  11. package/build/cover/edit/inspector-controls.js.map +1 -1
  12. package/build/details/edit.js +1 -2
  13. package/build/details/edit.js.map +1 -1
  14. package/build/form/index.js +1 -1
  15. package/build/form/index.js.map +1 -1
  16. package/build/form-submit-button/edit.js +2 -1
  17. package/build/form-submit-button/edit.js.map +1 -1
  18. package/build/gallery/gap-styles.js +12 -7
  19. package/build/gallery/gap-styles.js.map +1 -1
  20. package/build/group/edit.js +1 -0
  21. package/build/group/edit.js.map +1 -1
  22. package/build/html/transforms.js +7 -2
  23. package/build/html/transforms.js.map +1 -1
  24. package/build/image/deprecated.js +8 -0
  25. package/build/image/deprecated.js.map +1 -1
  26. package/build/image/view.js +10 -7
  27. package/build/image/view.js.map +1 -1
  28. package/build/missing/index.js +1 -1
  29. package/build/navigation/edit/overlay-menu-preview.js +1 -1
  30. package/build/navigation/edit/overlay-menu-preview.js.map +1 -1
  31. package/build/navigation/use-template-part-area-label.js +2 -1
  32. package/build/navigation/use-template-part-area-label.js.map +1 -1
  33. package/build/navigation-link/edit.js +1 -1
  34. package/build/navigation-link/edit.js.map +1 -1
  35. package/build/pattern/edit.js +1 -1
  36. package/build/pattern/edit.js.map +1 -1
  37. package/build/post-author/edit.js +0 -1
  38. package/build/post-author/edit.js.map +1 -1
  39. package/build/post-featured-image/edit.js +21 -6
  40. package/build/post-featured-image/edit.js.map +1 -1
  41. package/build/post-template/edit.js +2 -8
  42. package/build/post-template/edit.js.map +1 -1
  43. package/build/post-template/index.js +1 -1
  44. package/build/post-terms/edit.js +0 -2
  45. package/build/post-terms/edit.js.map +1 -1
  46. package/build/preformatted/transforms.js +1 -4
  47. package/build/preformatted/transforms.js.map +1 -1
  48. package/build/query/edit/query-content.js +1 -0
  49. package/build/query/edit/query-content.js.map +1 -1
  50. package/build/quote/index.js +6 -0
  51. package/build/quote/index.js.map +1 -1
  52. package/build/template-part/edit/advanced-controls.js +1 -0
  53. package/build/template-part/edit/advanced-controls.js.map +1 -1
  54. package/build/template-part/edit/index.js +3 -7
  55. package/build/template-part/edit/index.js.map +1 -1
  56. package/build/template-part/index.js +6 -2
  57. package/build/template-part/index.js.map +1 -1
  58. package/build/template-part/variations.js +5 -1
  59. package/build/template-part/variations.js.map +1 -1
  60. package/build-module/block/edit.js +3 -2
  61. package/build-module/block/edit.js.map +1 -1
  62. package/build-module/button/edit.js +61 -6
  63. package/build-module/button/edit.js.map +1 -1
  64. package/build-module/code/transforms.js +20 -7
  65. package/build-module/code/transforms.js.map +1 -1
  66. package/build-module/comments/edit/comments-inspector-controls.js +1 -0
  67. package/build-module/comments/edit/comments-inspector-controls.js.map +1 -1
  68. package/build-module/cover/edit/inspector-controls.js +1 -0
  69. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  70. package/build-module/details/edit.js +1 -2
  71. package/build-module/details/edit.js.map +1 -1
  72. package/build-module/form/index.js +1 -1
  73. package/build-module/form/index.js.map +1 -1
  74. package/build-module/form-submit-button/edit.js +2 -1
  75. package/build-module/form-submit-button/edit.js.map +1 -1
  76. package/build-module/gallery/gap-styles.js +13 -8
  77. package/build-module/gallery/gap-styles.js.map +1 -1
  78. package/build-module/group/edit.js +1 -0
  79. package/build-module/group/edit.js.map +1 -1
  80. package/build-module/html/transforms.js +7 -2
  81. package/build-module/html/transforms.js.map +1 -1
  82. package/build-module/image/deprecated.js +8 -0
  83. package/build-module/image/deprecated.js.map +1 -1
  84. package/build-module/image/view.js +10 -7
  85. package/build-module/image/view.js.map +1 -1
  86. package/build-module/missing/index.js +1 -1
  87. package/build-module/navigation/edit/overlay-menu-preview.js +1 -1
  88. package/build-module/navigation/edit/overlay-menu-preview.js.map +1 -1
  89. package/build-module/navigation/use-template-part-area-label.js +2 -1
  90. package/build-module/navigation/use-template-part-area-label.js.map +1 -1
  91. package/build-module/navigation-link/edit.js +2 -2
  92. package/build-module/navigation-link/edit.js.map +1 -1
  93. package/build-module/pattern/edit.js +1 -1
  94. package/build-module/pattern/edit.js.map +1 -1
  95. package/build-module/post-author/edit.js +0 -1
  96. package/build-module/post-author/edit.js.map +1 -1
  97. package/build-module/post-featured-image/edit.js +21 -6
  98. package/build-module/post-featured-image/edit.js.map +1 -1
  99. package/build-module/post-template/edit.js +2 -8
  100. package/build-module/post-template/edit.js.map +1 -1
  101. package/build-module/post-template/index.js +1 -1
  102. package/build-module/post-terms/edit.js +0 -2
  103. package/build-module/post-terms/edit.js.map +1 -1
  104. package/build-module/preformatted/transforms.js +1 -4
  105. package/build-module/preformatted/transforms.js.map +1 -1
  106. package/build-module/query/edit/query-content.js +1 -0
  107. package/build-module/query/edit/query-content.js.map +1 -1
  108. package/build-module/quote/index.js +6 -0
  109. package/build-module/quote/index.js.map +1 -1
  110. package/build-module/template-part/edit/advanced-controls.js +1 -0
  111. package/build-module/template-part/edit/advanced-controls.js.map +1 -1
  112. package/build-module/template-part/edit/index.js +5 -9
  113. package/build-module/template-part/edit/index.js.map +1 -1
  114. package/build-module/template-part/index.js +6 -2
  115. package/build-module/template-part/index.js.map +1 -1
  116. package/build-module/template-part/variations.js +5 -1
  117. package/build-module/template-part/variations.js.map +1 -1
  118. package/build-style/editor-rtl.css +12 -0
  119. package/build-style/editor.css +12 -0
  120. package/build-style/image/editor-rtl.css +3 -0
  121. package/build-style/image/editor.css +3 -0
  122. package/build-style/image/style-rtl.css +19 -13
  123. package/build-style/image/style.css +19 -13
  124. package/build-style/post-featured-image/editor-rtl.css +9 -0
  125. package/build-style/post-featured-image/editor.css +9 -0
  126. package/build-style/quote/style-rtl.css +3 -0
  127. package/build-style/quote/style.css +3 -0
  128. package/build-style/read-more/style-rtl.css +2 -2
  129. package/build-style/read-more/style.css +2 -2
  130. package/build-style/style-rtl.css +24 -15
  131. package/build-style/style.css +24 -15
  132. package/package.json +32 -32
  133. package/src/block/edit.js +2 -1
  134. package/src/button/edit.js +70 -4
  135. package/src/code/transforms.js +14 -8
  136. package/src/comments/edit/comments-inspector-controls.js +1 -0
  137. package/src/cover/edit/inspector-controls.js +1 -0
  138. package/src/details/edit.js +0 -1
  139. package/src/form/index.js +1 -1
  140. package/src/form-submit-button/edit.js +1 -0
  141. package/src/gallery/gap-styles.js +10 -9
  142. package/src/group/edit.js +1 -0
  143. package/src/html/transforms.js +5 -2
  144. package/src/image/deprecated.js +8 -0
  145. package/src/image/editor.scss +7 -0
  146. package/src/image/index.php +3 -4
  147. package/src/image/style.scss +18 -13
  148. package/src/image/view.js +24 -11
  149. package/src/missing/block.json +1 -1
  150. package/src/navigation/edit/overlay-menu-preview.js +1 -1
  151. package/src/navigation/index.php +37 -402
  152. package/src/navigation/use-template-part-area-label.js +4 -2
  153. package/src/navigation-link/edit.js +2 -2
  154. package/src/navigation-link/index.php +57 -0
  155. package/src/paragraph/test/__snapshots__/transforms.native.js.snap +6 -0
  156. package/src/paragraph/test/transforms.native.js +1 -0
  157. package/src/pattern/edit.js +2 -1
  158. package/src/pattern/index.php +6 -1
  159. package/src/post-author/edit.js +0 -1
  160. package/src/post-featured-image/edit.js +38 -5
  161. package/src/post-featured-image/editor.scss +19 -0
  162. package/src/post-template/block.json +0 -1
  163. package/src/post-template/edit.js +1 -5
  164. package/src/post-terms/edit.js +0 -2
  165. package/src/preformatted/transforms.js +1 -4
  166. package/src/query/edit/query-content.js +1 -0
  167. package/src/query/index.php +6 -2
  168. package/src/quote/block.json +6 -0
  169. package/src/quote/style.scss +4 -0
  170. package/src/read-more/style.scss +1 -1
  171. package/src/template-part/edit/advanced-controls.js +1 -0
  172. package/src/template-part/edit/index.js +7 -14
  173. package/src/template-part/index.js +4 -3
  174. package/src/template-part/index.php +4 -4
  175. package/src/template-part/variations.js +4 -2
@@ -65,68 +65,84 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
65
65
 
66
66
  return $menu_items_by_parent_id;
67
67
  }
68
- }
69
68
 
69
+ /**
70
+ * Gets the inner blocks for the navigation block from the unstable location attribute.
71
+ *
72
+ * @param array $attributes The block attributes.
73
+ * @return WP_Block_List Returns the inner blocks for the navigation block.
74
+ */
75
+ function block_core_navigation_get_inner_blocks_from_unstable_location( $attributes ) {
76
+ $menu_items = block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] );
77
+ if ( empty( $menu_items ) ) {
78
+ return '';
79
+ }
80
+
81
+ $menu_items_by_parent_id = block_core_navigation_sort_menu_items_by_parent_id( $menu_items );
82
+ $parsed_blocks = block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id );
83
+ return new WP_Block_List( $parsed_blocks, $attributes );
84
+ }
85
+ }
70
86
 
71
87
  /**
72
88
  * Add Interactivity API directives to the navigation-submenu and page-list
73
89
  * blocks markup using the Tag Processor.
74
90
  *
75
- * @param WP_HTML_Tag_Processor $w Markup of the navigation block.
91
+ * @param WP_HTML_Tag_Processor $tags Markup of the navigation block.
76
92
  * @param array $block_attributes Block attributes.
77
93
  *
78
94
  * @return string Submenu markup with the directives injected.
79
95
  */
80
- function block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
81
- while ( $w->next_tag(
96
+ function block_core_navigation_add_directives_to_submenu( $tags, $block_attributes ) {
97
+ while ( $tags->next_tag(
82
98
  array(
83
99
  'tag_name' => 'LI',
84
100
  'class_name' => 'has-child',
85
101
  )
86
102
  ) ) {
87
103
  // Add directives to the parent `<li>`.
88
- $w->set_attribute( 'data-wp-interactive', true );
89
- $w->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "submenuOpenedBy": {}, "type": "submenu" } } }' );
90
- $w->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
91
- $w->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
92
- $w->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
104
+ $tags->set_attribute( 'data-wp-interactive', true );
105
+ $tags->set_attribute( 'data-wp-context', '{ "core": { "navigation": { "submenuOpenedBy": {}, "type": "submenu" } } }' );
106
+ $tags->set_attribute( 'data-wp-effect', 'effects.core.navigation.initMenu' );
107
+ $tags->set_attribute( 'data-wp-on--focusout', 'actions.core.navigation.handleMenuFocusout' );
108
+ $tags->set_attribute( 'data-wp-on--keydown', 'actions.core.navigation.handleMenuKeydown' );
93
109
 
94
110
  // This is a fix for Safari. Without it, Safari doesn't change the active
95
111
  // element when the user clicks on a button. It can be removed once we add
96
112
  // an overlay to capture the clicks, instead of relying on the focusout
97
113
  // event.
98
- $w->set_attribute( 'tabindex', '-1' );
114
+ $tags->set_attribute( 'tabindex', '-1' );
99
115
 
100
116
  if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
101
- $w->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
102
- $w->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
117
+ $tags->set_attribute( 'data-wp-on--mouseenter', 'actions.core.navigation.openMenuOnHover' );
118
+ $tags->set_attribute( 'data-wp-on--mouseleave', 'actions.core.navigation.closeMenuOnHover' );
103
119
  }
104
120
 
105
121
  // Add directives to the toggle submenu button.
106
- if ( $w->next_tag(
122
+ if ( $tags->next_tag(
107
123
  array(
108
124
  'tag_name' => 'BUTTON',
109
125
  'class_name' => 'wp-block-navigation-submenu__toggle',
110
126
  )
111
127
  ) ) {
112
- $w->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
113
- $w->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
128
+ $tags->set_attribute( 'data-wp-on--click', 'actions.core.navigation.toggleMenuOnClick' );
129
+ $tags->set_attribute( 'data-wp-bind--aria-expanded', 'selectors.core.navigation.isMenuOpen' );
114
130
  // The `aria-expanded` attribute for SSR is already added in the submenu block.
115
131
  }
116
132
  // Add directives to the submenu.
117
- if ( $w->next_tag(
133
+ if ( $tags->next_tag(
118
134
  array(
119
135
  'tag_name' => 'UL',
120
136
  'class_name' => 'wp-block-navigation__submenu-container',
121
137
  )
122
138
  ) ) {
123
- $w->set_attribute( 'data-wp-on--focus', 'actions.core.navigation.openMenuOnFocus' );
139
+ $tags->set_attribute( 'data-wp-on--focus', 'actions.core.navigation.openMenuOnFocus' );
124
140
  }
125
141
 
126
142
  // Iterate through subitems if exist.
127
- block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
143
+ block_core_navigation_add_directives_to_submenu( $tags, $block_attributes );
128
144
  }
129
- return $w->get_updated_html();
145
+ return $tags->get_updated_html();
130
146
  }
131
147
 
132
148
  /**
@@ -391,391 +407,10 @@ function block_core_navigation_from_block_get_post_ids( $block ) {
391
407
  * @param string $content The saved content.
392
408
  * @param WP_Block $block The parsed block.
393
409
  *
394
- * @return string Returns the post content with the legacy widget added.
410
+ * @return string Returns the navigation block markup.
395
411
  */
396
412
  function render_block_core_navigation( $attributes, $content, $block ) {
397
- static $seen_menu_names = array();
398
-
399
- // Flag used to indicate whether the rendered output is considered to be
400
- // a fallback (i.e. the block has no menu associated with it).
401
- $is_fallback = false;
402
-
403
- $nav_menu_name = $attributes['ariaLabel'] ?? '';
404
-
405
- /**
406
- * Deprecated:
407
- * The rgbTextColor and rgbBackgroundColor attributes
408
- * have been deprecated in favor of
409
- * customTextColor and customBackgroundColor ones.
410
- * Move the values from old attrs to the new ones.
411
- */
412
- if ( isset( $attributes['rgbTextColor'] ) && empty( $attributes['textColor'] ) ) {
413
- $attributes['customTextColor'] = $attributes['rgbTextColor'];
414
- }
415
-
416
- if ( isset( $attributes['rgbBackgroundColor'] ) && empty( $attributes['backgroundColor'] ) ) {
417
- $attributes['customBackgroundColor'] = $attributes['rgbBackgroundColor'];
418
- }
419
-
420
- unset( $attributes['rgbTextColor'], $attributes['rgbBackgroundColor'] );
421
-
422
- /**
423
- * This is for backwards compatibility after `isResponsive` attribute has been removed.
424
- */
425
- $has_old_responsive_attribute = ! empty( $attributes['isResponsive'] ) && $attributes['isResponsive'];
426
- $is_responsive_menu = isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'] || $has_old_responsive_attribute;
427
-
428
- $inner_blocks = $block->inner_blocks;
429
-
430
- // Ensure that blocks saved with the legacy ref attribute name (navigationMenuId) continue to render.
431
- if ( array_key_exists( 'navigationMenuId', $attributes ) ) {
432
- $attributes['ref'] = $attributes['navigationMenuId'];
433
- }
434
-
435
- // If:
436
- // - the gutenberg plugin is active
437
- // - `__unstableLocation` is defined
438
- // - we have menu items at the defined location
439
- // - we don't have a relationship to a `wp_navigation` Post (via `ref`).
440
- // ...then create inner blocks from the classic menu assigned to that location.
441
- if (
442
- defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN &&
443
- array_key_exists( '__unstableLocation', $attributes ) &&
444
- ! array_key_exists( 'ref', $attributes ) &&
445
- ! empty( block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
446
- ) {
447
- $menu_items = block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] );
448
- if ( empty( $menu_items ) ) {
449
- return '';
450
- }
451
-
452
- $menu_items_by_parent_id = block_core_navigation_sort_menu_items_by_parent_id( $menu_items );
453
- $parsed_blocks = block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id );
454
- $inner_blocks = new WP_Block_List( $parsed_blocks, $attributes );
455
- }
456
-
457
- // Load inner blocks from the navigation post.
458
- if ( array_key_exists( 'ref', $attributes ) ) {
459
- $navigation_post = get_post( $attributes['ref'] );
460
- if ( ! isset( $navigation_post ) ) {
461
- return '';
462
- }
463
-
464
- // Only published posts are valid. If this is changed then a corresponding change
465
- // must also be implemented in `use-navigation-menu.js`.
466
- if ( 'publish' === $navigation_post->post_status ) {
467
- $nav_menu_name = $navigation_post->post_title;
468
-
469
- if ( isset( $seen_menu_names[ $nav_menu_name ] ) ) {
470
- ++$seen_menu_names[ $nav_menu_name ];
471
- } else {
472
- $seen_menu_names[ $nav_menu_name ] = 1;
473
- }
474
-
475
- $parsed_blocks = parse_blocks( $navigation_post->post_content );
476
-
477
- // 'parse_blocks' includes a null block with '\n\n' as the content when
478
- // it encounters whitespace. This code strips it.
479
- $compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
480
-
481
- // TODO - this uses the full navigation block attributes for the
482
- // context which could be refined.
483
- $inner_blocks = new WP_Block_List( $compacted_blocks, $attributes );
484
- }
485
- }
486
-
487
- // If there are no inner blocks then fallback to rendering an appropriate fallback.
488
- if ( empty( $inner_blocks ) ) {
489
- $is_fallback = true; // indicate we are rendering the fallback.
490
-
491
- $fallback_blocks = block_core_navigation_get_fallback_blocks();
492
-
493
- // Fallback my have been filtered so do basic test for validity.
494
- if ( empty( $fallback_blocks ) || ! is_array( $fallback_blocks ) ) {
495
- return '';
496
- }
497
-
498
- $inner_blocks = new WP_Block_List( $fallback_blocks, $attributes );
499
- }
500
-
501
- if ( block_core_navigation_block_contains_core_navigation( $inner_blocks ) ) {
502
- return '';
503
- }
504
-
505
- /**
506
- * Filter navigation block $inner_blocks.
507
- * Allows modification of a navigation block menu items.
508
- *
509
- * @since 6.1.0
510
- *
511
- * @param \WP_Block_List $inner_blocks
512
- */
513
- $inner_blocks = apply_filters( 'block_core_navigation_render_inner_blocks', $inner_blocks );
514
-
515
- $layout_justification = array(
516
- 'left' => 'items-justified-left',
517
- 'right' => 'items-justified-right',
518
- 'center' => 'items-justified-center',
519
- 'space-between' => 'items-justified-space-between',
520
- );
521
-
522
- // Restore legacy classnames for submenu positioning.
523
- $layout_class = '';
524
- if (
525
- isset( $attributes['layout']['justifyContent'] ) &&
526
- isset( $layout_justification[ $attributes['layout']['justifyContent'] ] )
527
- ) {
528
- $layout_class .= $layout_justification[ $attributes['layout']['justifyContent'] ];
529
- }
530
- if ( isset( $attributes['layout']['orientation'] ) && 'vertical' === $attributes['layout']['orientation'] ) {
531
- $layout_class .= ' is-vertical';
532
- }
533
-
534
- if ( isset( $attributes['layout']['flexWrap'] ) && 'nowrap' === $attributes['layout']['flexWrap'] ) {
535
- $layout_class .= ' no-wrap';
536
- }
537
-
538
- // Manually add block support text decoration as CSS class.
539
- $text_decoration = $attributes['style']['typography']['textDecoration'] ?? null;
540
- $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
541
-
542
- $colors = block_core_navigation_build_css_colors( $attributes );
543
- $font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
544
- $classes = array_merge(
545
- $colors['css_classes'],
546
- $font_sizes['css_classes'],
547
- $is_responsive_menu ? array( 'is-responsive' ) : array(),
548
- $layout_class ? array( $layout_class ) : array(),
549
- $is_fallback ? array( 'is-fallback' ) : array(),
550
- $text_decoration ? array( $text_decoration_class ) : array()
551
- );
552
-
553
- $post_ids = block_core_navigation_get_post_ids( $inner_blocks );
554
- if ( $post_ids ) {
555
- _prime_post_caches( $post_ids, false, false );
556
- }
557
-
558
- $list_item_nav_blocks = array(
559
- 'core/navigation-link',
560
- 'core/home-link',
561
- 'core/site-title',
562
- 'core/site-logo',
563
- 'core/navigation-submenu',
564
- );
565
-
566
- $needs_list_item_wrapper = array(
567
- 'core/site-title',
568
- 'core/site-logo',
569
- );
570
-
571
- $block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
572
- $style = $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'];
573
- $class = implode( ' ', $classes );
574
-
575
- // If the menu name has been used previously then append an ID
576
- // to the name to ensure uniqueness across a given post.
577
- if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) {
578
- $count = $seen_menu_names[ $nav_menu_name ];
579
- $nav_menu_name = $nav_menu_name . ' ' . ( $count );
580
- }
581
-
582
- $wrapper_attributes = get_block_wrapper_attributes(
583
- array(
584
- 'class' => $class,
585
- 'style' => $style,
586
- 'aria-label' => $nav_menu_name,
587
- )
588
- );
589
-
590
- $container_attributes = get_block_wrapper_attributes(
591
- array(
592
- 'class' => 'wp-block-navigation__container ' . $class,
593
- 'style' => $style,
594
- )
595
- );
596
-
597
- $inner_blocks_html = '';
598
- $is_list_open = false;
599
- $has_submenus = false;
600
- foreach ( $inner_blocks as $inner_block ) {
601
- $is_list_item = in_array( $inner_block->name, $list_item_nav_blocks, true );
602
-
603
- if ( $is_list_item && ! $is_list_open ) {
604
- $is_list_open = true;
605
- $inner_blocks_html .= sprintf(
606
- '<ul %1$s>',
607
- $container_attributes
608
- );
609
- }
610
-
611
- if ( ! $is_list_item && $is_list_open ) {
612
- $is_list_open = false;
613
- $inner_blocks_html .= '</ul>';
614
- }
615
-
616
- $inner_block_content = $inner_block->render();
617
- $p = new WP_HTML_Tag_Processor( $inner_block_content );
618
- if ( $p->next_tag(
619
- array(
620
- 'name' => 'LI',
621
- 'class_name' => 'has-child',
622
- )
623
- ) ) {
624
- $has_submenus = true;
625
- }
626
- if ( ! empty( $inner_block_content ) ) {
627
- if ( in_array( $inner_block->name, $needs_list_item_wrapper, true ) ) {
628
- $inner_blocks_html .= '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>';
629
- } else {
630
- $inner_blocks_html .= $inner_block_content;
631
- }
632
- }
633
- }
634
-
635
- if ( $is_list_open ) {
636
- $inner_blocks_html .= '</ul>';
637
- }
638
-
639
- $should_load_view_script = ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) || $is_responsive_menu;
640
- $view_js_file = 'wp-block-navigation-view';
641
-
642
- // If the script already exists, there is no point in removing it from viewScript.
643
- if ( ! wp_script_is( $view_js_file ) ) {
644
- $script_handles = $block->block_type->view_script_handles;
645
-
646
- // If the script is not needed, and it is still in the `view_script_handles`, remove it.
647
- if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
648
- $block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
649
- }
650
- // If the script is needed, but it was previously removed, add it again.
651
- if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
652
- $block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
653
- }
654
- }
655
-
656
- // Add directives to the submenu if needed.
657
- if ( $has_submenus && $should_load_view_script ) {
658
- $w = new WP_HTML_Tag_Processor( $inner_blocks_html );
659
- $inner_blocks_html = block_core_navigation_add_directives_to_submenu( $w, $attributes );
660
- }
661
-
662
- $modal_unique_id = wp_unique_id( 'modal-' );
663
-
664
- // Determine whether or not navigation elements should be wrapped in the markup required to make it responsive,
665
- // return early if they don't.
666
- if ( ! $is_responsive_menu ) {
667
- return sprintf(
668
- '<nav %1$s>%2$s</nav>',
669
- $wrapper_attributes,
670
- $inner_blocks_html
671
- );
672
- }
673
-
674
- $is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu'];
675
-
676
- $responsive_container_classes = array(
677
- 'wp-block-navigation__responsive-container',
678
- $is_hidden_by_default ? 'hidden-by-default' : '',
679
- implode( ' ', $colors['overlay_css_classes'] ),
680
- );
681
- $open_button_classes = array(
682
- 'wp-block-navigation__responsive-container-open',
683
- $is_hidden_by_default ? 'always-shown' : '',
684
- );
685
-
686
- $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon'];
687
- $toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg>';
688
- if ( isset( $attributes['icon'] ) ) {
689
- if ( 'menu' === $attributes['icon'] ) {
690
- $toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 5v1.5h14V5H5zm0 7.8h14v-1.5H5v1.5zM5 19h14v-1.5H5V19z" /></svg>';
691
- }
692
- }
693
- $toggle_button_content = $should_display_icon_label ? $toggle_button_icon : __( 'Menu' );
694
- $toggle_close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" aria-hidden="true" focusable="false"><path d="M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"></path></svg>';
695
- $toggle_close_button_content = $should_display_icon_label ? $toggle_close_button_icon : __( 'Close' );
696
- $toggle_aria_label_open = $should_display_icon_label ? 'aria-label="' . __( 'Open menu' ) . '"' : ''; // Open button label.
697
- $toggle_aria_label_close = $should_display_icon_label ? 'aria-label="' . __( 'Close menu' ) . '"' : ''; // Close button label.
698
-
699
- // Add Interactivity API directives to the markup if needed.
700
- $nav_element_directives = '';
701
- $open_button_directives = '';
702
- $responsive_container_directives = '';
703
- $responsive_dialog_directives = '';
704
- $close_button_directives = '';
705
- if ( $should_load_view_script ) {
706
- $nav_element_context = wp_json_encode(
707
- array(
708
- 'core' => array(
709
- 'navigation' => array(
710
- 'overlayOpenedBy' => array(),
711
- 'type' => 'overlay',
712
- 'roleAttribute' => '',
713
- 'ariaLabel' => __( 'Menu' ),
714
- ),
715
- ),
716
- ),
717
- JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
718
- );
719
- $nav_element_directives = '
720
- data-wp-interactive
721
- data-wp-context=\'' . $nav_element_context . '\'
722
- ';
723
- $open_button_directives = '
724
- data-wp-on--click="actions.core.navigation.openMenuOnClick"
725
- data-wp-on--keydown="actions.core.navigation.handleMenuKeydown"
726
- ';
727
- $responsive_container_directives = '
728
- data-wp-class--has-modal-open="selectors.core.navigation.isMenuOpen"
729
- data-wp-class--is-menu-open="selectors.core.navigation.isMenuOpen"
730
- data-wp-effect="effects.core.navigation.initMenu"
731
- data-wp-on--keydown="actions.core.navigation.handleMenuKeydown"
732
- data-wp-on--focusout="actions.core.navigation.handleMenuFocusout"
733
- tabindex="-1"
734
- ';
735
- $responsive_dialog_directives = '
736
- data-wp-bind--aria-modal="selectors.core.navigation.ariaModal"
737
- data-wp-bind--aria-label="selectors.core.navigation.ariaLabel"
738
- data-wp-bind--role="selectors.core.navigation.roleAttribute"
739
- data-wp-effect="effects.core.navigation.focusFirstElement"
740
- ';
741
- $close_button_directives = '
742
- data-wp-on--click="actions.core.navigation.closeMenuOnClick"
743
- ';
744
- }
745
-
746
- $responsive_container_markup = sprintf(
747
- '<button aria-haspopup="dialog" %3$s class="%6$s" %10$s>%8$s</button>
748
- <div class="%5$s" style="%7$s" id="%1$s" %11$s>
749
- <div class="wp-block-navigation__responsive-close" tabindex="-1">
750
- <div class="wp-block-navigation__responsive-dialog" %12$s>
751
- <button %4$s class="wp-block-navigation__responsive-container-close" %13$s>%9$s</button>
752
- <div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
753
- %2$s
754
- </div>
755
- </div>
756
- </div>
757
- </div>',
758
- esc_attr( $modal_unique_id ),
759
- $inner_blocks_html,
760
- $toggle_aria_label_open,
761
- $toggle_aria_label_close,
762
- esc_attr( implode( ' ', $responsive_container_classes ) ),
763
- esc_attr( implode( ' ', $open_button_classes ) ),
764
- esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) ),
765
- $toggle_button_content,
766
- $toggle_close_button_content,
767
- $open_button_directives,
768
- $responsive_container_directives,
769
- $responsive_dialog_directives,
770
- $close_button_directives
771
- );
772
-
773
- return sprintf(
774
- '<nav %1$s %3$s>%2$s</nav>',
775
- $wrapper_attributes,
776
- $responsive_container_markup,
777
- $nav_element_directives
778
- );
413
+ return WP_Navigation_Block_Renderer::render( $attributes, $content, $block );
779
414
  }
780
415
 
781
416
  /**
@@ -45,14 +45,16 @@ export default function useTemplatePartAreaLabel( clientId ) {
45
45
  'core/editor'
46
46
  ).__experimentalGetDefaultTemplatePartAreas();
47
47
  /* eslint-enable @wordpress/data-no-store-string-literals */
48
- const { getEditedEntityRecord } = select( coreStore );
48
+ const { getCurrentTheme, getEditedEntityRecord } =
49
+ select( coreStore );
49
50
 
50
51
  for ( const templatePartClientId of parentTemplatePartClientIds ) {
51
52
  const templatePartBlock = getBlock( templatePartClientId );
52
53
 
53
54
  // The 'area' usually isn't stored on the block, but instead
54
55
  // on the entity.
55
- const { theme, slug } = templatePartBlock.attributes;
56
+ const { theme = getCurrentTheme()?.stylesheet, slug } =
57
+ templatePartBlock.attributes;
56
58
  const templatePartEntityId = createTemplatePartId(
57
59
  theme,
58
60
  slug
@@ -27,7 +27,7 @@ import {
27
27
  getColorClassName,
28
28
  useInnerBlocksProps,
29
29
  } from '@wordpress/block-editor';
30
- import { isURL, prependHTTP } from '@wordpress/url';
30
+ import { isURL, prependHTTP, safeDecodeURI } from '@wordpress/url';
31
31
  import { useState, useEffect, useRef } from '@wordpress/element';
32
32
  import {
33
33
  placeCaretAtHorizontalEdge,
@@ -432,7 +432,7 @@ export default function NavigationLinkEdit( {
432
432
  />
433
433
  <TextControl
434
434
  __nextHasNoMarginBottom
435
- value={ url || '' }
435
+ value={ url ? safeDecodeURI( url ) : '' }
436
436
  onChange={ ( urlValue ) => {
437
437
  updateAttributes(
438
438
  { url: urlValue },
@@ -322,6 +322,25 @@ function build_variation_for_navigation_link( $entity, $kind ) {
322
322
  return $variation;
323
323
  }
324
324
 
325
+ /**
326
+ * Register a variation for a post type / taxonomy for the navigation link block
327
+ *
328
+ * @param array $variation Variation array from build_variation_for_navigation_link.
329
+ * @return void
330
+ */
331
+ function register_block_core_navigation_link_variation( $variation ) {
332
+ // Directly set the variations on the registered block type
333
+ // because there's no server side registration for variations (see #47170).
334
+ $navigation_block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' );
335
+ // If the block is not registered yet, bail early.
336
+ // Variation will be registered in register_block_core_navigation_link then.
337
+ if ( ! $navigation_block_type ) {
338
+ return;
339
+ }
340
+
341
+ $navigation_block_type->variations[] = $variation;
342
+ }
343
+
325
344
  /**
326
345
  * Register the navigation link block.
327
346
  *
@@ -329,6 +348,9 @@ function build_variation_for_navigation_link( $entity, $kind ) {
329
348
  * @throws WP_Error An WP_Error exception parsing the block definition.
330
349
  */
331
350
  function register_block_core_navigation_link() {
351
+ // This will only handle post types and taxonomies registered until this point (init on priority 9).
352
+ // See action hooks below for other post types and taxonomies.
353
+ // See https://github.com/WordPress/gutenberg/issues/53826 for details.
332
354
  $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'objects' );
333
355
  $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'objects' );
334
356
 
@@ -369,3 +391,38 @@ function register_block_core_navigation_link() {
369
391
  );
370
392
  }
371
393
  add_action( 'init', 'register_block_core_navigation_link' );
394
+ // Register actions for all post types and taxonomies, to add variations when they are registered.
395
+ // 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 );
398
+
399
+ /**
400
+ * Register custom post type variations for navigation link on post type registration
401
+ * Handles all post types registered after the block is registered in register_navigation_link_post_type_variations
402
+ *
403
+ * @param string $post_type The post type name passed from registered_post_type filter.
404
+ * @param WP_Post_Type $post_type_object The post type object passed from registered_post_type.
405
+ * @return void
406
+ */
407
+ function register_block_core_navigation_link_post_type_variation( $post_type, $post_type_object ) {
408
+ if ( $post_type_object->show_in_nav_menus ) {
409
+ $variation = build_variation_for_navigation_link( $post_type_object, 'post-type' );
410
+ register_block_core_navigation_link_variation( $variation );
411
+ }
412
+ }
413
+
414
+ /**
415
+ * Register a custom taxonomy variation for navigation link on taxonomy registration
416
+ * Handles all taxonomies registered after the block is registered in register_navigation_link_post_type_variations
417
+ *
418
+ * @param string $taxonomy Taxonomy slug.
419
+ * @param array|string $object_type Object type or array of object types.
420
+ * @param array $args Array of taxonomy registration arguments.
421
+ * @return void
422
+ */
423
+ function register_block_core_navigation_link_taxonomy_variation( $taxonomy, $object_type, $args ) {
424
+ if ( isset( $args['show_in_nav_menus'] ) && $args['show_in_nav_menus'] ) {
425
+ $variation = build_variation_for_navigation_link( (object) $args, 'post-type' );
426
+ register_block_core_navigation_link_variation( $variation );
427
+ }
428
+ }
@@ -1,5 +1,11 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
+ exports[`Paragraph block transforms to Code block 1`] = `
4
+ "<!-- wp:code -->
5
+ <pre class="wp-block-code"><code>Example text</code></pre>
6
+ <!-- /wp:code -->"
7
+ `;
8
+
3
9
  exports[`Paragraph block transforms to Columns block 1`] = `
4
10
  "<!-- wp:columns -->
5
11
  <div class="wp-block-columns"><!-- wp:column {"width":"100%"} -->
@@ -23,6 +23,7 @@ const blockTransforms = [
23
23
  'Preformatted',
24
24
  'Pullquote',
25
25
  'Verse',
26
+ 'Code',
26
27
  ...transformsWithInnerBlocks,
27
28
  ];
28
29
 
@@ -20,7 +20,8 @@ const PatternEdit = ( { attributes, clientId } ) => {
20
20
  );
21
21
 
22
22
  const currentThemeStylesheet = useSelect(
23
- ( select ) => select( coreStore ).getCurrentTheme().stylesheet
23
+ ( select ) => select( coreStore ).getCurrentTheme()?.stylesheet,
24
+ []
24
25
  );
25
26
 
26
27
  const { replaceBlocks, __unstableMarkNextChangeAsNotPersistent } =
@@ -48,7 +48,12 @@ function render_block_core_pattern( $attributes ) {
48
48
  $content = gutenberg_serialize_blocks( $blocks );
49
49
  }
50
50
 
51
- return do_blocks( $content );
51
+ $content = do_blocks( $content );
52
+
53
+ global $wp_embed;
54
+ $content = $wp_embed->autoembed( $content );
55
+
56
+ return $content;
52
57
  }
53
58
 
54
59
  add_action( 'init', 'register_block_core_pattern' );
@@ -196,7 +196,6 @@ function PostAuthorEdit( {
196
196
  { ( ! RichText.isEmpty( byline ) || isSelected ) && (
197
197
  <RichText
198
198
  className="wp-block-post-author__byline"
199
- multiline={ false }
200
199
  aria-label={ __( 'Post author byline text' ) }
201
200
  placeholder={ __( 'Write byline…' ) }
202
201
  value={ byline }