@wordpress/block-library 8.28.6 → 8.28.8

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.
@@ -135,9 +135,9 @@ class WP_Navigation_Block_Renderer {
135
135
  if ( static::does_block_need_a_list_item_wrapper( $inner_block ) ) {
136
136
  return '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>';
137
137
  }
138
-
139
- return $inner_block_content;
140
138
  }
139
+
140
+ return $inner_block_content;
141
141
  }
142
142
 
143
143
  /**
@@ -543,8 +543,7 @@ class WP_Navigation_Block_Renderer {
543
543
  /**
544
544
  * Gets the nav element directives.
545
545
  *
546
- * @param bool $is_interactive Whether the block is interactive.
547
- * @param array $attributes The block attributes.
546
+ * @param bool $is_interactive Whether the block is interactive.
548
547
  * @return string the directives for the navigation element.
549
548
  */
550
549
  private static function get_nav_element_directives( $is_interactive ) {
@@ -1458,17 +1457,33 @@ function block_core_navigation_set_ignored_hooked_blocks_metadata( $inner_blocks
1458
1457
  /**
1459
1458
  * Updates the post meta with the list of ignored hooked blocks when the navigation is created or updated via the REST API.
1460
1459
  *
1460
+ * @access private
1461
+ * @since 6.5.0
1462
+ *
1461
1463
  * @param stdClass $post Post object.
1464
+ * @return stdClass The updated post object.
1462
1465
  */
1463
1466
  function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
1464
- // We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
1465
- // all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
1467
+ /*
1468
+ * In this scenario the user has likely tried to create a navigation via the REST API.
1469
+ * In which case we won't have a post ID to work with and store meta against.
1470
+ */
1471
+ if ( empty( $post->ID ) ) {
1472
+ return $post;
1473
+ }
1474
+
1475
+ /*
1476
+ * We run the Block Hooks mechanism to inject the `metadata.ignoredHookedBlocks` attribute into
1477
+ * all anchor blocks. For the root level, we create a mock Navigation and extract them from there.
1478
+ */
1466
1479
  $blocks = parse_blocks( $post->post_content );
1467
1480
 
1468
- // Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that
1469
- // we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be
1470
- // used as context for hooked blocks insertion).
1471
- // We thus have to look it up from the DB,based on `$post->ID`.
1481
+ /*
1482
+ * Block Hooks logic requires a `WP_Post` object (rather than the `stdClass` with the updates that
1483
+ * we're getting from the `rest_pre_insert_wp_navigation` filter) as its second argument (to be
1484
+ * used as context for hooked blocks insertion).
1485
+ * We thus have to look it up from the DB,based on `$post->ID`.
1486
+ */
1472
1487
  $markup = block_core_navigation_set_ignored_hooked_blocks_metadata( $blocks, get_post( $post->ID ) );
1473
1488
 
1474
1489
  $root_nav_block = parse_blocks( $markup )[0];
@@ -1489,22 +1504,28 @@ function block_core_navigation_update_ignore_hooked_blocks_meta( $post ) {
1489
1504
  return $post;
1490
1505
  }
1491
1506
 
1492
- // Before adding our filter, we verify if it's already added in Core.
1493
- // However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
1494
- // Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
1495
- $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta';
1507
+ /*
1508
+ * Before adding our filter, we verify if it's already added in Core.
1509
+ * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
1510
+ * Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
1511
+ */
1512
+ $rest_insert_wp_navigation_core_callback = 'block_core_navigation_' . 'update_ignore_hooked_blocks_meta'; // phpcs:ignore Generic.Strings.UnnecessaryStringConcat.Found
1496
1513
 
1497
- // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1498
- // that are not present in Gutenberg's WP 6.5 compatibility layer.
1514
+ /*
1515
+ * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1516
+ * that are not present in Gutenberg's WP 6.5 compatibility layer.
1517
+ */
1499
1518
  if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_pre_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1500
- add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta', 10 );
1519
+ add_filter( 'rest_pre_insert_wp_navigation', 'block_core_navigation_update_ignore_hooked_blocks_meta' );
1501
1520
  }
1502
1521
 
1503
- // Previous versions of Gutenberg and WordPress 6.5 Betas were attaching the block_core_navigation_update_ignore_hooked_blocks_meta
1504
- // function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_).
1505
- // To avoid collisions, we need to remove the filter from that action if it's present.
1522
+ /*
1523
+ * Previous versions of Gutenberg were attaching the block_core_navigation_update_ignore_hooked_blocks_meta
1524
+ * function to the `rest_insert_wp_navigation` _action_ (rather than the `rest_pre_insert_wp_navigation` _filter_).
1525
+ * To avoid collisions, we need to remove the filter from that action if it's present.
1526
+ */
1506
1527
  if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback ) ) {
1507
- remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback, 10 );
1528
+ remove_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_callback );
1508
1529
  }
1509
1530
 
1510
1531
  /**
@@ -1512,7 +1533,6 @@ if ( has_filter( 'rest_insert_wp_navigation', $rest_insert_wp_navigation_core_ca
1512
1533
  *
1513
1534
  * @param WP_REST_Response $response The response object.
1514
1535
  * @param WP_Post $post Post object.
1515
- * @param WP_REST_Request $request Request object.
1516
1536
  * @return WP_REST_Response The response object.
1517
1537
  */
1518
1538
  function block_core_navigation_insert_hooked_blocks_into_rest_response( $response, $post ) {
@@ -1531,13 +1551,17 @@ function block_core_navigation_insert_hooked_blocks_into_rest_response( $respons
1531
1551
  return $response;
1532
1552
  }
1533
1553
 
1534
- // Before adding our filter, we verify if it's already added in Core.
1535
- // However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
1536
- // Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
1554
+ /*
1555
+ * Before adding our filter, we verify if it's already added in Core.
1556
+ * However, during the build process, Gutenberg automatically prefixes our functions with "gutenberg_".
1557
+ * Therefore, we concatenate the Core's function name to circumvent this prefix for our check.
1558
+ */
1537
1559
  $rest_prepare_wp_navigation_core_callback = 'block_core_navigation_' . 'insert_hooked_blocks_into_rest_response';
1538
1560
 
1539
- // Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1540
- // that are not present in Gutenberg's WP 6.5 compatibility layer.
1561
+ /*
1562
+ * Injection of hooked blocks into the Navigation block relies on some functions present in WP >= 6.5
1563
+ * that are not present in Gutenberg's WP 6.5 compatibility layer.
1564
+ */
1541
1565
  if ( function_exists( 'set_ignored_hooked_blocks_metadata' ) && ! has_filter( 'rest_prepare_wp_navigation', $rest_prepare_wp_navigation_core_callback ) ) {
1542
1566
  add_filter( 'rest_prepare_wp_navigation', 'block_core_navigation_insert_hooked_blocks_into_rest_response', 10, 3 );
1543
1567
  }
@@ -333,6 +333,7 @@ export default function NavigationLinkEdit( {
333
333
  isKeyboardEvent.primary( event, 'k' ) ||
334
334
  ( ( ! url || isDraft || isInvalid ) && event.keyCode === ENTER )
335
335
  ) {
336
+ event.preventDefault();
336
337
  setIsLinkOpen( true );
337
338
  }
338
339
  }
@@ -279,6 +279,7 @@ export default function NavigationSubmenuEdit( {
279
279
 
280
280
  function onKeyDown( event ) {
281
281
  if ( isKeyboardEvent.primary( event, 'k' ) ) {
282
+ event.preventDefault();
282
283
  setIsLinkOpen( true );
283
284
  }
284
285
  }