@wordpress/block-library 8.28.1 → 8.28.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/build/button/edit.js +2 -4
  2. package/build/button/edit.js.map +1 -1
  3. package/build/button/index.js +0 -1
  4. package/build/button/index.js.map +1 -1
  5. package/build/heading/index.js +0 -1
  6. package/build/heading/index.js.map +1 -1
  7. package/build/image/edit.js +2 -4
  8. package/build/image/edit.js.map +1 -1
  9. package/build/image/image.js +75 -6
  10. package/build/image/image.js.map +1 -1
  11. package/build/image/index.js +1 -1
  12. package/build/navigation/constants.js +1 -2
  13. package/build/navigation/constants.js.map +1 -1
  14. package/build/navigation/edit/index.js +0 -4
  15. package/build/navigation/edit/index.js.map +1 -1
  16. package/build/navigation/view.js +0 -23
  17. package/build/navigation/view.js.map +1 -1
  18. package/build/paragraph/index.js +1 -1
  19. package/build/paragraph/transforms.js +1 -1
  20. package/build-module/button/edit.js +2 -4
  21. package/build-module/button/edit.js.map +1 -1
  22. package/build-module/button/index.js +0 -1
  23. package/build-module/button/index.js.map +1 -1
  24. package/build-module/heading/index.js +0 -1
  25. package/build-module/heading/index.js.map +1 -1
  26. package/build-module/image/edit.js +2 -4
  27. package/build-module/image/edit.js.map +1 -1
  28. package/build-module/image/image.js +76 -7
  29. package/build-module/image/image.js.map +1 -1
  30. package/build-module/image/index.js +1 -1
  31. package/build-module/navigation/constants.js +0 -1
  32. package/build-module/navigation/constants.js.map +1 -1
  33. package/build-module/navigation/edit/index.js +1 -5
  34. package/build-module/navigation/edit/index.js.map +1 -1
  35. package/build-module/navigation/view.js +0 -23
  36. package/build-module/navigation/view.js.map +1 -1
  37. package/build-module/paragraph/index.js +1 -1
  38. package/build-module/paragraph/transforms.js +1 -1
  39. package/build-style/editor-rtl.css +8 -2
  40. package/build-style/editor.css +8 -2
  41. package/build-style/image/editor-rtl.css +4 -0
  42. package/build-style/image/editor.css +4 -0
  43. package/build-style/navigation/editor-rtl.css +4 -2
  44. package/build-style/navigation/editor.css +4 -2
  45. package/build-style/navigation/style-rtl.css +18 -14
  46. package/build-style/navigation/style.css +18 -14
  47. package/build-style/style-rtl.css +18 -14
  48. package/build-style/style.css +18 -14
  49. package/package.json +34 -34
  50. package/src/button/block.json +0 -1
  51. package/src/button/edit.js +4 -4
  52. package/src/footnotes/index.php +24 -11
  53. package/src/heading/block.json +0 -1
  54. package/src/image/block.json +1 -6
  55. package/src/image/edit.js +4 -4
  56. package/src/image/editor.scss +5 -0
  57. package/src/image/image.js +127 -8
  58. package/src/navigation/constants.js +0 -2
  59. package/src/navigation/edit/index.js +1 -11
  60. package/src/navigation/editor.scss +1 -1
  61. package/src/navigation/index.php +95 -54
  62. package/src/navigation/style.scss +16 -18
  63. package/src/navigation/view.js +0 -26
  64. package/src/navigation-link/index.php +0 -1
  65. package/src/paragraph/block.json +1 -1
  66. package/src/search/index.php +1 -1
@@ -218,7 +218,7 @@ class WP_Navigation_Block_Renderer {
218
218
  // it encounters whitespace. This code strips it.
219
219
  $blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
220
220
 
221
- if ( function_exists( 'get_hooked_block_markup' ) ) {
221
+ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) ) {
222
222
  // Run Block Hooks algorithm to inject hooked blocks.
223
223
  $markup = block_core_navigation_insert_hooked_blocks( $blocks, $navigation_post );
224
224
  $root_nav_block = parse_blocks( $markup )[0];
@@ -390,25 +390,16 @@ class WP_Navigation_Block_Renderer {
390
390
  $text_decoration = $attributes['style']['typography']['textDecoration'] ?? null;
391
391
  $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
392
392
 
393
- // Sets the is-collapsed class when the navigation is set to always use the overlay.
394
- // This saves us from needing to do this check in the view.js file (see the collapseNav function).
395
- $is_collapsed_class = static::is_always_overlay( $attributes ) ? array( 'is-collapsed' ) : array();
396
-
397
393
  $classes = array_merge(
398
394
  $colors['css_classes'],
399
395
  $font_sizes['css_classes'],
400
396
  $is_responsive_menu ? array( 'is-responsive' ) : array(),
401
397
  $layout_class ? array( $layout_class ) : array(),
402
- $text_decoration ? array( $text_decoration_class ) : array(),
403
- $is_collapsed_class
398
+ $text_decoration ? array( $text_decoration_class ) : array()
404
399
  );
405
400
  return implode( ' ', $classes );
406
401
  }
407
402
 
408
- private static function is_always_overlay( $attributes ) {
409
- return isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu'];
410
- }
411
-
412
403
  /**
413
404
  * Get styles for the navigation block.
414
405
  *
@@ -435,12 +426,16 @@ class WP_Navigation_Block_Renderer {
435
426
  $colors = block_core_navigation_build_css_colors( $attributes );
436
427
  $modal_unique_id = wp_unique_id( 'modal-' );
437
428
 
429
+ $is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu'];
430
+
438
431
  $responsive_container_classes = array(
439
432
  'wp-block-navigation__responsive-container',
433
+ $is_hidden_by_default ? 'hidden-by-default' : '',
440
434
  implode( ' ', $colors['overlay_css_classes'] ),
441
435
  );
442
436
  $open_button_classes = array(
443
437
  'wp-block-navigation__responsive-container-open',
438
+ $is_hidden_by_default ? 'always-shown' : '',
444
439
  );
445
440
 
446
441
  $should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon'];
@@ -538,7 +533,7 @@ class WP_Navigation_Block_Renderer {
538
533
  );
539
534
 
540
535
  if ( $is_responsive_menu ) {
541
- $nav_element_directives = static::get_nav_element_directives( $is_interactive, $attributes );
536
+ $nav_element_directives = static::get_nav_element_directives( $is_interactive );
542
537
  $wrapper_attributes .= ' ' . $nav_element_directives;
543
538
  }
544
539
 
@@ -552,7 +547,7 @@ class WP_Navigation_Block_Renderer {
552
547
  * @param array $attributes The block attributes.
553
548
  * @return string the directives for the navigation element.
554
549
  */
555
- private static function get_nav_element_directives( $is_interactive, $attributes ) {
550
+ private static function get_nav_element_directives( $is_interactive ) {
556
551
  if ( ! $is_interactive ) {
557
552
  return '';
558
553
  }
@@ -569,16 +564,6 @@ class WP_Navigation_Block_Renderer {
569
564
  data-wp-interactive="core/navigation"'
570
565
  . $nav_element_context;
571
566
 
572
- /*
573
- * When the navigation's 'overlayMenu' attribute is set to 'always', JavaScript
574
- * is not needed for collapsing the menu because the class is set manually.
575
- */
576
- if ( ! static::is_always_overlay( $attributes ) ) {
577
- $nav_element_directives .= 'data-wp-init="callbacks.initNav"';
578
- $nav_element_directives .= ' '; // space separator
579
- $nav_element_directives .= 'data-wp-class--is-collapsed="context.isCollapsed"';
580
- }
581
-
582
567
  return $nav_element_directives;
583
568
  }
584
569
 
@@ -1024,7 +1009,7 @@ function block_core_navigation_get_fallback_blocks() {
1024
1009
  // In this case default to the (Page List) fallback.
1025
1010
  $fallback_blocks = ! empty( $maybe_fallback ) ? $maybe_fallback : $fallback_blocks;
1026
1011
 
1027
- if ( function_exists( 'get_hooked_block_markup' ) ) {
1012
+ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) ) {
1028
1013
  // Run Block Hooks algorithm to inject hooked blocks.
1029
1014
  // We have to run it here because we need the post ID of the Navigation block to track ignored hooked blocks.
1030
1015
  $markup = block_core_navigation_insert_hooked_blocks( $fallback_blocks, $navigation_post );
@@ -1369,25 +1354,28 @@ function block_core_navigation_get_most_recently_published_navigation() {
1369
1354
  }
1370
1355
 
1371
1356
  /**
1372
- * Insert hooked blocks into a Navigation block.
1373
- *
1374
- * Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object,
1375
- * this function inserts hooked blocks into it, and returns the serialized inner blocks in a
1376
- * mock Navigation block wrapper.
1357
+ * Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the inner blocks.
1377
1358
  *
1378
- * If there are any hooked blocks that need to be inserted as the Navigation block's first or last
1379
- * children, the `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is checked to see if any
1380
- * of those hooked blocks should be exempted from insertion.
1359
+ * @param string $serialized_block The serialized markup of a block and its inner blocks.
1360
+ * @return string
1361
+ */
1362
+ function block_core_navigation_remove_serialized_parent_block( $serialized_block ) {
1363
+ $start = strpos( $serialized_block, '-->' ) + strlen( '-->' );
1364
+ $end = strrpos( $serialized_block, '<!--' );
1365
+ return substr( $serialized_block, $start, $end - $start );
1366
+ }
1367
+
1368
+ /**
1369
+ * Mock a parsed block for the Navigation block given its inner blocks and the `wp_navigation` post object.
1370
+ * The `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is queried to add the `metadata.ignoredHookedBlocks` attribute.
1381
1371
  *
1382
1372
  * @param array $inner_blocks Parsed inner blocks of a Navigation block.
1383
1373
  * @param WP_Post $post `wp_navigation` post object corresponding to the block.
1384
- * @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any.
1374
+ *
1375
+ * @return array the normalized parsed blocks.
1385
1376
  */
1386
- function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
1387
- $before_block_visitor = null;
1388
- $after_block_visitor = null;
1389
- $hooked_blocks = get_hooked_blocks();
1390
- $attributes = array();
1377
+ function block_core_navigation_mock_parsed_block( $inner_blocks, $post ) {
1378
+ $attributes = array();
1391
1379
 
1392
1380
  if ( isset( $post->ID ) ) {
1393
1381
  $ignored_hooked_blocks = get_post_meta( $post->ID, '_wp_ignored_hooked_blocks', true );
@@ -1405,15 +1393,62 @@ function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
1405
1393
  'innerBlocks' => $inner_blocks,
1406
1394
  'innerContent' => array_fill( 0, count( $inner_blocks ), null ),
1407
1395
  );
1408
- $before_block_visitor = null;
1409
- $after_block_visitor = null;
1396
+
1397
+ return $mock_anchor_parent_block;
1398
+ }
1399
+
1400
+ /**
1401
+ * Insert hooked blocks into a Navigation block.
1402
+ *
1403
+ * Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object,
1404
+ * this function inserts hooked blocks into it, and returns the serialized inner blocks in a
1405
+ * mock Navigation block wrapper.
1406
+ *
1407
+ * If there are any hooked blocks that need to be inserted as the Navigation block's first or last
1408
+ * children, the `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is checked to see if any
1409
+ * of those hooked blocks should be exempted from insertion.
1410
+ *
1411
+ * @param array $inner_blocks Parsed inner blocks of a Navigation block.
1412
+ * @param WP_Post $post `wp_navigation` post object corresponding to the block.
1413
+ * @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any.
1414
+ */
1415
+ function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
1416
+ $mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );
1417
+ $hooked_blocks = get_hooked_blocks();
1418
+ $before_block_visitor = null;
1419
+ $after_block_visitor = null;
1410
1420
 
1411
1421
  if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
1412
- $before_block_visitor = make_before_block_visitor( $hooked_blocks, $post );
1413
- $after_block_visitor = make_after_block_visitor( $hooked_blocks, $post );
1422
+ $before_block_visitor = make_before_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
1423
+ $after_block_visitor = make_after_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
1414
1424
  }
1415
1425
 
1416
- return traverse_and_serialize_block( $mock_anchor_parent_block, $before_block_visitor, $after_block_visitor );
1426
+ return traverse_and_serialize_block( $mock_navigation_block, $before_block_visitor, $after_block_visitor );
1427
+ }
1428
+
1429
+ /**
1430
+ * Insert ignoredHookedBlocks meta into the Navigation block and its inner blocks.
1431
+ *
1432
+ * Given a Navigation block's inner blocks and its corresponding `wp_navigation` post object,
1433
+ * this function inserts ignoredHookedBlocks meta into it, and returns the serialized inner blocks in a
1434
+ * mock Navigation block wrapper.
1435
+ *
1436
+ * @param array $inner_blocks Parsed inner blocks of a Navigation block.
1437
+ * @param WP_Post $post `wp_navigation` post object corresponding to the block.
1438
+ * @return string Serialized inner blocks in mock Navigation block wrapper, with hooked blocks inserted, if any.
1439
+ */
1440
+ function block_core_navigation_set_ignored_hooked_blocks_metadata( $inner_blocks, $post ) {
1441
+ $mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );
1442
+ $hooked_blocks = get_hooked_blocks();
1443
+ $before_block_visitor = null;
1444
+ $after_block_visitor = null;
1445
+
1446
+ if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
1447
+ $before_block_visitor = make_before_block_visitor( $hooked_blocks, $post, 'set_ignored_hooked_blocks_metadata' );
1448
+ $after_block_visitor = make_after_block_visitor( $hooked_blocks, $post, 'set_ignored_hooked_blocks_metadata' );
1449
+ }
1450
+
1451
+ return traverse_and_serialize_block( $mock_navigation_block, $before_block_visitor, $after_block_visitor );
1417
1452
  }
1418
1453
 
1419
1454
  /**
@@ -1422,12 +1457,11 @@ function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
1422
1457
  * @param WP_Post $post Post object.
1423
1458
  */
1424
1459
  function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
1425
- // We run the Block Hooks mechanism so it will return the list of ignored hooked blocks
1426
- // in the mock root Navigation block's metadata attribute.
1427
- // We ignore the rest of the returned `$markup`; `$post->post_content` already has the hooked
1428
- // blocks inserted, whereas `$markup` will have them inserted twice.
1429
- $blocks = parse_blocks( $post->post_content );
1430
- $markup = block_core_navigation_insert_hooked_blocks( $blocks, $post );
1460
+ // We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
1461
+ // all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
1462
+ $blocks = parse_blocks( $post->post_content );
1463
+ $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, $post );
1464
+
1431
1465
  $root_nav_block = parse_blocks( $markup )[0];
1432
1466
  $ignored_hooked_blocks = isset( $root_nav_block['attrs']['metadata']['ignoredHookedBlocks'] )
1433
1467
  ? $root_nav_block['attrs']['metadata']['ignoredHookedBlocks']
@@ -1441,6 +1475,15 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
1441
1475
  }
1442
1476
  update_post_meta( $post->ID, '_wp_ignored_hooked_blocks', json_encode( $ignored_hooked_blocks ) );
1443
1477
  }
1478
+
1479
+ $serialized_inner_blocks = block_core_navigation_remove_serialized_parent_block( $markup );
1480
+
1481
+ wp_update_post(
1482
+ array(
1483
+ 'ID' => $post->ID,
1484
+ 'post_content' => $serialized_inner_blocks,
1485
+ )
1486
+ );
1444
1487
  }
1445
1488
 
1446
1489
  // Before adding our filter, we verify if it's already added in Core.
@@ -1450,7 +1493,7 @@ $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ig
1450
1493
 
1451
1494
  // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1452
1495
  // that are not present in Gutenberg's WP 6.5 compatibility layer.
1453
- if ( function_exists( 'get_hooked_block_markup' ) && ! has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1496
+ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1454
1497
  add_action( 'rest_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10, 3 );
1455
1498
  }
1456
1499
 
@@ -1470,9 +1513,7 @@ function block_core_navigation_insert_hooked_blocks_into_rest_response( $respons
1470
1513
  $content = block_core_navigation_insert_hooked_blocks( $parsed_blocks, $post );
1471
1514
 
1472
1515
  // Remove mock Navigation block wrapper.
1473
- $start = strpos( $content, '-->' ) + strlen( '-->' );
1474
- $end = strrpos( $content, '<!--' );
1475
- $content = substr( $content, $start, $end - $start );
1516
+ $content = block_core_navigation_remove_serialized_parent_block( $content );
1476
1517
 
1477
1518
  $response->data['content']['raw'] = $content;
1478
1519
  $response->data['content']['rendered'] = apply_filters( 'the_content', $content );
@@ -1487,6 +1528,6 @@ $rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_h
1487
1528
 
1488
1529
  // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1489
1530
  // that are not present in Gutenberg's WP 6.5 compatibility layer.
1490
- if ( function_exists( 'get_hooked_block_markup' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) {
1531
+ if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) {
1491
1532
  add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
1492
1533
  }
@@ -611,19 +611,18 @@ button.wp-block-navigation-item__content {
611
611
  }
612
612
  }
613
613
 
614
- // When the menu is collapsed, the menu button is visible.
615
- // We are using the > selector combined with the :not(is-collapsed) selector
616
- // as a way to target the class being added to the parent nav element.
617
- :not(.is-collapsed) > & {
618
- &:not(.is-menu-open) {
619
- display: block;
620
- width: 100%;
621
- position: relative;
622
- z-index: auto;
623
- background-color: inherit;
624
-
625
- .wp-block-navigation__responsive-container-close {
626
- display: none;
614
+ @include break-small() {
615
+ &:not(.hidden-by-default) {
616
+ &:not(.is-menu-open) {
617
+ display: block;
618
+ width: 100%;
619
+ position: relative;
620
+ z-index: auto;
621
+ background-color: inherit;
622
+
623
+ .wp-block-navigation__responsive-container-close {
624
+ display: none;
625
+ }
627
626
  }
628
627
  }
629
628
 
@@ -687,11 +686,10 @@ button.wp-block-navigation-item__content {
687
686
  font-size: inherit;
688
687
  }
689
688
 
690
- // When the menu is collapsed, the menu button is visible.
691
- // We are using the > selector combined with the :not(is-collapsed) selector
692
- // as a way to target the class being added to the parent nav element.
693
- :not(.is-collapsed) > & {
694
- display: none;
689
+ &:not(.always-shown) {
690
+ @include break-small {
691
+ display: none;
692
+ }
695
693
  }
696
694
  }
697
695
 
@@ -3,11 +3,6 @@
3
3
  */
4
4
  import { store, getContext, getElement } from '@wordpress/interactivity';
5
5
 
6
- /**
7
- * Internal dependencies
8
- */
9
- import { NAVIGATION_MOBILE_COLLAPSE } from './constants';
10
-
11
6
  const focusableSelectors = [
12
7
  'a[href]',
13
8
  'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
@@ -201,27 +196,6 @@ const { state, actions } = store(
201
196
  focusableElements?.[ 0 ]?.focus();
202
197
  }
203
198
  },
204
- initNav() {
205
- const context = getContext();
206
- const mediaQuery = window.matchMedia(
207
- `(max-width: ${ NAVIGATION_MOBILE_COLLAPSE })`
208
- );
209
-
210
- // Run once to set the initial state.
211
- context.isCollapsed = mediaQuery.matches;
212
-
213
- function handleCollapse( event ) {
214
- context.isCollapsed = event.matches;
215
- }
216
-
217
- // Run on resize to update the state.
218
- mediaQuery.addEventListener( 'change', handleCollapse );
219
-
220
- // Remove the listener when the component is unmounted.
221
- return () => {
222
- mediaQuery.removeEventListener( 'change', handleCollapse );
223
- };
224
- },
225
199
  },
226
200
  },
227
201
  { lock: true }
@@ -392,7 +392,6 @@ function block_core_navigation_link_build_variations() {
392
392
  * Registers the navigation link block.
393
393
  *
394
394
  * @uses render_block_core_navigation_link()
395
- * @uses build_navigation_link_block_variations()
396
395
  * @throws WP_Error An WP_Error exception parsing the block definition.
397
396
  */
398
397
  function register_block_core_navigation_link() {
@@ -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", "pattern/overrides" ],
10
+ "usesContext": [ "postId" ],
11
11
  "attributes": {
12
12
  "align": {
13
13
  "type": "string"
@@ -188,7 +188,7 @@ function render_block_core_search( $attributes ) {
188
188
  )
189
189
  );
190
190
  $form_directives = '
191
- data-wp-interactive=\'"core/search"\''
191
+ data-wp-interactive="core/search"'
192
192
  . $form_context .
193
193
  'data-wp-class--wp-block-search__searchfield-hidden="!context.isSearchInputVisible"
194
194
  data-wp-on--keydown="actions.handleSearchKeydown"