@wordpress/block-library 9.13.0 → 9.13.1-next.cd6172eb0.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 (127) hide show
  1. package/build/block/edit.js +2 -29
  2. package/build/block/edit.js.map +1 -1
  3. package/build/cover/edit/index.js +4 -2
  4. package/build/cover/edit/index.js.map +1 -1
  5. package/build/cover/edit/inspector-controls.js +6 -4
  6. package/build/cover/edit/inspector-controls.js.map +1 -1
  7. package/build/list-item/hooks/use-merge.js +2 -2
  8. package/build/list-item/hooks/use-merge.js.map +1 -1
  9. package/build/navigation/edit/deleted-navigation-warning.js +9 -2
  10. package/build/navigation/edit/deleted-navigation-warning.js.map +1 -1
  11. package/build/navigation-submenu/edit.js +3 -0
  12. package/build/navigation-submenu/edit.js.map +1 -1
  13. package/build/pattern/recursion-detector.js +0 -1
  14. package/build/pattern/recursion-detector.js.map +1 -1
  15. package/build/query/edit/index.js +2 -2
  16. package/build/query/edit/index.js.map +1 -1
  17. package/build/query/edit/inspector-controls/author-control.js +0 -1
  18. package/build/query/edit/inspector-controls/author-control.js.map +1 -1
  19. package/build/query/edit/inspector-controls/parent-control.js +0 -1
  20. package/build/query/edit/inspector-controls/parent-control.js.map +1 -1
  21. package/build/query/edit/inspector-controls/taxonomy-controls.js +0 -1
  22. package/build/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  23. package/build/query/edit/{pattern-selection-modal.js → pattern-selection.js} +55 -36
  24. package/build/query/edit/pattern-selection.js.map +1 -0
  25. package/build/query/edit/query-content.js +5 -8
  26. package/build/query/edit/query-content.js.map +1 -1
  27. package/build/query/edit/query-placeholder.js +5 -11
  28. package/build/query/edit/query-placeholder.js.map +1 -1
  29. package/build/query/edit/query-toolbar.js +31 -11
  30. package/build/query/edit/query-toolbar.js.map +1 -1
  31. package/build/separator/deprecated.js +2 -1
  32. package/build/separator/deprecated.js.map +1 -1
  33. package/build/separator/edit.js +29 -4
  34. package/build/separator/edit.js.map +1 -1
  35. package/build/separator/index.js +5 -0
  36. package/build/separator/index.js.map +1 -1
  37. package/build/separator/save.js +3 -2
  38. package/build/separator/save.js.map +1 -1
  39. package/build/template-part/edit/import-controls.js +0 -1
  40. package/build/template-part/edit/import-controls.js.map +1 -1
  41. package/build-module/block/edit.js +3 -30
  42. package/build-module/block/edit.js.map +1 -1
  43. package/build-module/cover/edit/index.js +4 -2
  44. package/build-module/cover/edit/index.js.map +1 -1
  45. package/build-module/cover/edit/inspector-controls.js +6 -4
  46. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  47. package/build-module/list-item/hooks/use-merge.js +2 -2
  48. package/build-module/list-item/hooks/use-merge.js.map +1 -1
  49. package/build-module/navigation/edit/deleted-navigation-warning.js +10 -3
  50. package/build-module/navigation/edit/deleted-navigation-warning.js.map +1 -1
  51. package/build-module/navigation-submenu/edit.js +3 -0
  52. package/build-module/navigation-submenu/edit.js.map +1 -1
  53. package/build-module/pattern/recursion-detector.js +0 -1
  54. package/build-module/pattern/recursion-detector.js.map +1 -1
  55. package/build-module/query/edit/index.js +1 -1
  56. package/build-module/query/edit/index.js.map +1 -1
  57. package/build-module/query/edit/inspector-controls/author-control.js +0 -1
  58. package/build-module/query/edit/inspector-controls/author-control.js.map +1 -1
  59. package/build-module/query/edit/inspector-controls/parent-control.js +0 -1
  60. package/build-module/query/edit/inspector-controls/parent-control.js.map +1 -1
  61. package/build-module/query/edit/inspector-controls/taxonomy-controls.js +0 -1
  62. package/build-module/query/edit/inspector-controls/taxonomy-controls.js.map +1 -1
  63. package/build-module/query/edit/{pattern-selection-modal.js → pattern-selection.js} +53 -36
  64. package/build-module/query/edit/pattern-selection.js.map +1 -0
  65. package/build-module/query/edit/query-content.js +5 -8
  66. package/build-module/query/edit/query-content.js.map +1 -1
  67. package/build-module/query/edit/query-placeholder.js +6 -12
  68. package/build-module/query/edit/query-placeholder.js.map +1 -1
  69. package/build-module/query/edit/query-toolbar.js +31 -13
  70. package/build-module/query/edit/query-toolbar.js.map +1 -1
  71. package/build-module/separator/deprecated.js +2 -1
  72. package/build-module/separator/deprecated.js.map +1 -1
  73. package/build-module/separator/edit.js +32 -7
  74. package/build-module/separator/edit.js.map +1 -1
  75. package/build-module/separator/index.js +5 -0
  76. package/build-module/separator/index.js.map +1 -1
  77. package/build-module/separator/save.js +3 -2
  78. package/build-module/separator/save.js.map +1 -1
  79. package/build-module/template-part/edit/import-controls.js +0 -1
  80. package/build-module/template-part/edit/import-controls.js.map +1 -1
  81. package/build-style/comments-pagination/editor-rtl.css +1 -0
  82. package/build-style/comments-pagination/editor.css +1 -0
  83. package/build-style/comments-pagination/style-rtl.css +1 -0
  84. package/build-style/comments-pagination/style.css +1 -0
  85. package/build-style/editor-rtl.css +31 -0
  86. package/build-style/editor.css +31 -0
  87. package/build-style/image/style-rtl.css +3 -2
  88. package/build-style/image/style.css +3 -2
  89. package/build-style/pullquote/style-rtl.css +1 -0
  90. package/build-style/pullquote/style.css +1 -0
  91. package/build-style/query/editor-rtl.css +30 -0
  92. package/build-style/query/editor.css +30 -0
  93. package/build-style/style-rtl.css +5 -2
  94. package/build-style/style.css +5 -2
  95. package/build-types/lock-unlock.d.ts +1 -1
  96. package/build-types/lock-unlock.d.ts.map +1 -1
  97. package/package.json +34 -34
  98. package/src/block/edit.js +6 -51
  99. package/src/comments-pagination/editor.scss +1 -0
  100. package/src/comments-pagination/style.scss +1 -0
  101. package/src/cover/edit/index.js +4 -1
  102. package/src/cover/edit/inspector-controls.js +10 -3
  103. package/src/cover/index.php +2 -2
  104. package/src/image/style.scss +4 -3
  105. package/src/list-item/hooks/use-merge.js +2 -2
  106. package/src/missing/test/edit.native.js +0 -1
  107. package/src/navigation/README.md +1 -0
  108. package/src/navigation/edit/deleted-navigation-warning.js +11 -2
  109. package/src/navigation/index.php +9 -35
  110. package/src/navigation-submenu/edit.js +5 -0
  111. package/src/navigation-submenu/index.php +17 -1
  112. package/src/pullquote/style.scss +1 -0
  113. package/src/query/edit/index.js +1 -1
  114. package/src/query/edit/{pattern-selection-modal.js → pattern-selection.js} +53 -33
  115. package/src/query/edit/query-content.js +4 -10
  116. package/src/query/edit/query-placeholder.js +5 -14
  117. package/src/query/edit/query-toolbar.js +38 -17
  118. package/src/query/editor.scss +30 -0
  119. package/src/search/index.php +3 -3
  120. package/src/separator/block.json +5 -0
  121. package/src/separator/deprecated.js +1 -0
  122. package/src/separator/edit.js +28 -3
  123. package/src/separator/save.js +2 -2
  124. package/src/separator/test/edit.js +1 -0
  125. package/tsconfig.tsbuildinfo +1 -1
  126. package/build/query/edit/pattern-selection-modal.js.map +0 -1
  127. package/build-module/query/edit/pattern-selection-modal.js.map +0 -1
package/src/block/edit.js CHANGED
@@ -7,7 +7,7 @@ import clsx from 'clsx';
7
7
  * WordPress dependencies
8
8
  */
9
9
  import { useSelect, useDispatch } from '@wordpress/data';
10
- import { useRef, useMemo, useEffect } from '@wordpress/element';
10
+ import { useRef, useMemo } from '@wordpress/element';
11
11
  import {
12
12
  useEntityRecord,
13
13
  store as coreStore,
@@ -37,12 +37,10 @@ import { getBlockBindingsSource } from '@wordpress/blocks';
37
37
  /**
38
38
  * Internal dependencies
39
39
  */
40
- import { name as patternBlockName } from './index';
41
40
  import { unlock } from '../lock-unlock';
42
41
 
43
42
  const { useLayoutClasses } = unlock( blockEditorPrivateApis );
44
- const { isOverridableBlock, hasOverridableBlocks } =
45
- unlock( patternsPrivateApis );
43
+ const { hasOverridableBlocks } = unlock( patternsPrivateApis );
46
44
 
47
45
  const fullAlignments = [ 'full', 'wide', 'left', 'right' ];
48
46
 
@@ -75,22 +73,6 @@ const useInferredLayout = ( blocks, parentLayout ) => {
75
73
  }, [ blocks, parentLayout ] );
76
74
  };
77
75
 
78
- function setBlockEditMode( setEditMode, blocks, mode ) {
79
- blocks.forEach( ( block ) => {
80
- const editMode =
81
- mode ||
82
- ( isOverridableBlock( block ) ? 'contentOnly' : 'disabled' );
83
- setEditMode( block.clientId, editMode );
84
-
85
- setBlockEditMode(
86
- setEditMode,
87
- block.innerBlocks,
88
- // Disable editing for nested patterns.
89
- block.name === patternBlockName ? 'disabled' : mode
90
- );
91
- } );
92
- }
93
-
94
76
  function RecursionWarning() {
95
77
  const blockProps = useBlockProps();
96
78
  return (
@@ -171,7 +153,6 @@ function ReusableBlockEdit( {
171
153
  name,
172
154
  attributes: { ref, content },
173
155
  __unstableParentLayout: parentLayout,
174
- clientId: patternClientId,
175
156
  setAttributes,
176
157
  } ) {
177
158
  const { record, hasResolved } = useEntityRecord(
@@ -184,49 +165,24 @@ function ReusableBlockEdit( {
184
165
  } );
185
166
  const isMissing = hasResolved && ! record;
186
167
 
187
- const { setBlockEditingMode, __unstableMarkLastChangeAsPersistent } =
168
+ const { __unstableMarkLastChangeAsPersistent } =
188
169
  useDispatch( blockEditorStore );
189
170
 
190
- const {
191
- innerBlocks,
192
- onNavigateToEntityRecord,
193
- editingMode,
194
- hasPatternOverridesSource,
195
- } = useSelect(
171
+ const { onNavigateToEntityRecord, hasPatternOverridesSource } = useSelect(
196
172
  ( select ) => {
197
- const { getBlocks, getSettings, getBlockEditingMode } =
198
- select( blockEditorStore );
173
+ const { getSettings } = select( blockEditorStore );
199
174
  // For editing link to the site editor if the theme and user permissions support it.
200
175
  return {
201
- innerBlocks: getBlocks( patternClientId ),
202
176
  onNavigateToEntityRecord:
203
177
  getSettings().onNavigateToEntityRecord,
204
- editingMode: getBlockEditingMode( patternClientId ),
205
178
  hasPatternOverridesSource: !! getBlockBindingsSource(
206
179
  'core/pattern-overrides'
207
180
  ),
208
181
  };
209
182
  },
210
- [ patternClientId ]
183
+ []
211
184
  );
212
185
 
213
- // Sync the editing mode of the pattern block with the inner blocks.
214
- useEffect( () => {
215
- setBlockEditMode(
216
- setBlockEditingMode,
217
- innerBlocks,
218
- // Disable editing if the pattern itself is disabled.
219
- editingMode === 'disabled' || ! hasPatternOverridesSource
220
- ? 'disabled'
221
- : undefined
222
- );
223
- }, [
224
- editingMode,
225
- innerBlocks,
226
- setBlockEditingMode,
227
- hasPatternOverridesSource,
228
- ] );
229
-
230
186
  const canOverrideBlocks = useMemo(
231
187
  () => hasPatternOverridesSource && hasOverridableBlocks( blocks ),
232
188
  [ hasPatternOverridesSource, blocks ]
@@ -244,7 +200,6 @@ function ReusableBlockEdit( {
244
200
  } );
245
201
 
246
202
  const innerBlocksProps = useInnerBlocksProps( blockProps, {
247
- templateLock: 'all',
248
203
  layout,
249
204
  value: blocks,
250
205
  onInput: NOOP,
@@ -26,6 +26,7 @@ $pagination-margin: 0.5em;
26
26
  margin-right: $pagination-margin;
27
27
  margin-bottom: $pagination-margin;
28
28
 
29
+ font-size: inherit;
29
30
  &:last-child {
30
31
  /*rtl:ignore*/
31
32
  margin-right: 0;
@@ -8,6 +8,7 @@ $pagination-margin: 0.5em;
8
8
  margin-right: $pagination-margin;
9
9
  margin-bottom: $pagination-margin;
10
10
 
11
+ font-size: inherit;
11
12
  &:last-child {
12
13
  /*rtl:ignore*/
13
14
  margin-right: 0;
@@ -120,7 +120,9 @@ function CoverEdit( {
120
120
  select( coreStore ).getMedia( featuredImage, { context: 'view' } ),
121
121
  [ featuredImage ]
122
122
  );
123
- const mediaUrl = media?.source_url;
123
+ const mediaUrl =
124
+ media?.media_details?.sizes?.[ sizeSlug ]?.source_url ??
125
+ media?.source_url;
124
126
 
125
127
  // User can change the featured image outside of the block, but we still
126
128
  // need to update the block when that happens. This effect should only
@@ -451,6 +453,7 @@ function CoverEdit( {
451
453
  toggleUseFeaturedImage={ toggleUseFeaturedImage }
452
454
  updateDimRatio={ onUpdateDimRatio }
453
455
  onClearMedia={ onClearMedia }
456
+ featuredImage={ media }
454
457
  />
455
458
  );
456
459
 
@@ -96,6 +96,7 @@ export default function CoverInspectorControls( {
96
96
  coverRef,
97
97
  currentSettings,
98
98
  updateDimRatio,
99
+ featuredImage,
99
100
  } ) {
100
101
  const {
101
102
  useFeaturedImage,
@@ -132,8 +133,12 @@ export default function CoverInspectorControls( {
132
133
  [ id, isImageBackground ]
133
134
  );
134
135
 
136
+ const currentBackgroundImage = useFeaturedImage ? featuredImage : image;
137
+
135
138
  function updateImage( newSizeSlug ) {
136
- const newUrl = image?.media_details?.sizes?.[ newSizeSlug ]?.source_url;
139
+ const newUrl =
140
+ currentBackgroundImage?.media_details?.sizes?.[ newSizeSlug ]
141
+ ?.source_url;
137
142
  if ( ! newUrl ) {
138
143
  return null;
139
144
  }
@@ -146,7 +151,9 @@ export default function CoverInspectorControls( {
146
151
 
147
152
  const imageSizeOptions = imageSizes
148
153
  ?.filter(
149
- ( { slug } ) => image?.media_details?.sizes?.[ slug ]?.source_url
154
+ ( { slug } ) =>
155
+ currentBackgroundImage?.media_details?.sizes?.[ slug ]
156
+ ?.source_url
150
157
  )
151
158
  ?.map( ( { name, slug } ) => ( { value: slug, label: name } ) );
152
159
 
@@ -321,7 +328,7 @@ export default function CoverInspectorControls( {
321
328
  />
322
329
  </ToolsPanelItem>
323
330
  ) }
324
- { ! useFeaturedImage && !! imageSizeOptions?.length && (
331
+ { !! imageSizeOptions?.length && (
325
332
  <ResolutionTool
326
333
  value={ sizeSlug }
327
334
  onChange={ updateImage }
@@ -35,12 +35,12 @@ function render_block_core_cover( $attributes, $content ) {
35
35
  $attr['style'] = 'object-position:' . $object_position . ';';
36
36
  }
37
37
 
38
- $image = get_the_post_thumbnail( null, 'post-thumbnail', $attr );
38
+ $image = get_the_post_thumbnail( null, $attributes['sizeSlug'] ?? 'post-thumbnail', $attr );
39
39
  } else {
40
40
  if ( in_the_loop() ) {
41
41
  update_post_thumbnail_cache();
42
42
  }
43
- $current_featured_image = get_the_post_thumbnail_url();
43
+ $current_featured_image = get_the_post_thumbnail_url( null, $attributes['sizeSlug'] ?? null );
44
44
  if ( ! $current_featured_image ) {
45
45
  return $content;
46
46
  }
@@ -1,6 +1,7 @@
1
1
  .wp-block-image {
2
2
 
3
- a {
3
+ > a,
4
+ > figure > a {
4
5
  display: inline-block;
5
6
  }
6
7
 
@@ -42,8 +43,8 @@
42
43
  text-align: center;
43
44
  }
44
45
 
45
- &.alignfull a,
46
- &.alignwide a {
46
+ &.alignfull > a,
47
+ &.alignwide > a {
47
48
  width: 100%;
48
49
  }
49
50
 
@@ -49,7 +49,7 @@ export default function useMerge( clientId, onMerge ) {
49
49
  * return the next list item of the parent list item if it exists.
50
50
  *
51
51
  * @param {string} id A list item client ID.
52
- * @return {string?} The client ID of the next list item.
52
+ * @return {?string} The client ID of the next list item.
53
53
  */
54
54
  function _getNextId( id ) {
55
55
  const next = getNextBlockClientId( id );
@@ -68,7 +68,7 @@ export default function useMerge( clientId, onMerge ) {
68
68
  * line, regardless of indentation level.
69
69
  *
70
70
  * @param {string} id The client ID of the current list item.
71
- * @return {string?} The client ID of the next list item.
71
+ * @return {?string} The client ID of the next list item.
72
72
  */
73
73
  function getNextId( id ) {
74
74
  const order = getBlockOrder( id );
@@ -10,7 +10,6 @@ import { Text } from 'react-native';
10
10
  import { BottomSheet, Icon } from '@wordpress/components';
11
11
  import { help, plugins } from '@wordpress/icons';
12
12
  import { storeConfig } from '@wordpress/block-editor';
13
- jest.mock( '@wordpress/blocks' );
14
13
  jest.mock( '@wordpress/block-editor/src/store/selectors' );
15
14
 
16
15
  /**
@@ -10,4 +10,5 @@ The structural CSS for the navigation block targets generic classnames across me
10
10
  - `.wp-block-navigation-item` is applied to every menu item.
11
11
  - `.wp-block-navigation-item__content` is applied to the link inside a menu item.
12
12
  - `.wp-block-navigation-item__label` is applied to the innermost container around the menu item text label.
13
+ - `.wp-block-navigation-item__description` is applied to the innermost container around the menu item description.
13
14
  - `.wp-block-navigation__submenu-icon` is applied to the submenu indicator (chevron).
@@ -4,9 +4,16 @@
4
4
  import { Warning } from '@wordpress/block-editor';
5
5
  import { Button, Notice } from '@wordpress/components';
6
6
  import { __ } from '@wordpress/i18n';
7
- import { createInterpolateElement } from '@wordpress/element';
7
+ import { useState, createInterpolateElement } from '@wordpress/element';
8
8
 
9
9
  function DeletedNavigationWarning( { onCreateNew, isNotice = false } ) {
10
+ const [ isButtonDisabled, setIsButtonDisabled ] = useState( false );
11
+
12
+ const handleButtonClick = () => {
13
+ setIsButtonDisabled( true );
14
+ onCreateNew();
15
+ };
16
+
10
17
  const message = createInterpolateElement(
11
18
  __(
12
19
  'Navigation Menu has been deleted or is unavailable. <button>Create a new Menu?</button>'
@@ -15,8 +22,10 @@ function DeletedNavigationWarning( { onCreateNew, isNotice = false } ) {
15
22
  button: (
16
23
  <Button
17
24
  __next40pxDefaultSize
18
- onClick={ onCreateNew }
25
+ onClick={ handleButtonClick }
19
26
  variant="link"
27
+ disabled={ isButtonDisabled }
28
+ accessibleWhenDisabled
20
29
  />
21
30
  ),
22
31
  }
@@ -567,13 +567,14 @@ class WP_Navigation_Block_Renderer {
567
567
  $is_responsive_menu = static::is_responsive( $attributes );
568
568
  $style = static::get_styles( $attributes );
569
569
  $class = static::get_classes( $attributes );
570
- $wrapper_attributes = get_block_wrapper_attributes(
571
- array(
572
- 'class' => $class,
573
- 'style' => $style,
574
- 'aria-label' => $nav_menu_name,
575
- )
570
+ $extra_attributes = array(
571
+ 'class' => $class,
572
+ 'style' => $style,
576
573
  );
574
+ if ( ! empty( $nav_menu_name ) ) {
575
+ $extra_attributes['aria-label'] = $nav_menu_name;
576
+ }
577
+ $wrapper_attributes = get_block_wrapper_attributes( $extra_attributes );
577
578
 
578
579
  if ( $is_responsive_menu ) {
579
580
  $nav_element_directives = static::get_nav_element_directives( $is_interactive );
@@ -1436,20 +1437,6 @@ function block_core_navigation_get_most_recently_published_navigation() {
1436
1437
  return null;
1437
1438
  }
1438
1439
 
1439
- /**
1440
- * Accepts the serialized markup of a block and its inner blocks, and returns serialized markup of the inner blocks.
1441
- *
1442
- * @since 6.5.0
1443
- *
1444
- * @param string $serialized_block The serialized markup of a block and its inner blocks.
1445
- * @return string
1446
- */
1447
- function block_core_navigation_remove_serialized_parent_block( $serialized_block ) {
1448
- $start = strpos( $serialized_block, '-->' ) + strlen( '-->' );
1449
- $end = strrpos( $serialized_block, '<!--' );
1450
- return substr( $serialized_block, $start, $end - $start );
1451
- }
1452
-
1453
1440
  /**
1454
1441
  * Mock a parsed block for the Navigation block given its inner blocks and the `wp_navigation` post object.
1455
1442
  * The `wp_navigation` post's `_wp_ignored_hooked_blocks` meta is queried to add the `metadata.ignoredHookedBlocks` attribute.
@@ -1504,19 +1491,6 @@ function block_core_navigation_mock_parsed_block( $inner_blocks, $post ) {
1504
1491
  function block_core_navigation_insert_hooked_blocks( $inner_blocks, $post ) {
1505
1492
  $mock_navigation_block = block_core_navigation_mock_parsed_block( $inner_blocks, $post );
1506
1493
 
1507
- if ( function_exists( 'apply_block_hooks_to_content' ) ) {
1508
- $mock_navigation_block_markup = serialize_block( $mock_navigation_block );
1509
- return apply_block_hooks_to_content( $mock_navigation_block_markup, $post, 'insert_hooked_blocks' );
1510
- }
1511
-
1512
- $hooked_blocks = get_hooked_blocks();
1513
- $before_block_visitor = null;
1514
- $after_block_visitor = null;
1515
-
1516
- if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
1517
- $before_block_visitor = make_before_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
1518
- $after_block_visitor = make_after_block_visitor( $hooked_blocks, $post, 'insert_hooked_blocks' );
1519
- }
1520
-
1521
- return traverse_and_serialize_block( $mock_navigation_block, $before_block_visitor, $after_block_visitor );
1494
+ $mock_navigation_block_markup = serialize_block( $mock_navigation_block );
1495
+ return apply_block_hooks_to_content( $mock_navigation_block_markup, $post, 'insert_hooked_blocks' );
1522
1496
  }
@@ -474,6 +474,11 @@ export default function NavigationSubmenuEdit( {
474
474
  }
475
475
  } }
476
476
  />
477
+ { description && (
478
+ <span className="wp-block-navigation-item__description">
479
+ { description }
480
+ </span>
481
+ ) }
477
482
  { ! openSubmenusOnClick && isLinkOpen && (
478
483
  <LinkUI
479
484
  clientId={ clientId }
@@ -159,7 +159,16 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
159
159
  $html .= '>';
160
160
  // End appending HTML attributes to anchor tag.
161
161
 
162
+ $html .= '<span class="wp-block-navigation-item__label">';
162
163
  $html .= $label;
164
+ $html .= '</span>';
165
+
166
+ // Add description if available.
167
+ if ( ! empty( $attributes['description'] ) ) {
168
+ $html .= '<span class="wp-block-navigation-item__description">';
169
+ $html .= wp_kses_post( $attributes['description'] );
170
+ $html .= '</span>';
171
+ }
163
172
 
164
173
  $html .= '</a>';
165
174
  // End anchor tag content.
@@ -180,6 +189,13 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
180
189
 
181
190
  $html .= '</span>';
182
191
 
192
+ // Add description if available.
193
+ if ( ! empty( $attributes['description'] ) ) {
194
+ $html .= '<span class="wp-block-navigation-item__description">';
195
+ $html .= wp_kses_post( $attributes['description'] );
196
+ $html .= '</span>';
197
+ }
198
+
183
199
  $html .= '</button>';
184
200
 
185
201
  $html .= '<span class="wp-block-navigation__submenu-icon">' . block_core_navigation_submenu_render_submenu_icon() . '</span>';
@@ -222,7 +238,7 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
222
238
 
223
239
  if ( strpos( $inner_blocks_html, 'current-menu-item' ) ) {
224
240
  $tag_processor = new WP_HTML_Tag_Processor( $html );
225
- while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item__content' ) ) ) {
241
+ while ( $tag_processor->next_tag( array( 'class_name' => 'wp-block-navigation-item' ) ) ) {
226
242
  $tag_processor->add_class( 'current-menu-ancestor' );
227
243
  }
228
244
  $html = $tag_processor->get_updated_html();
@@ -72,4 +72,5 @@
72
72
 
73
73
  .wp-block-pullquote cite {
74
74
  color: inherit;
75
+ display: block;
75
76
  }
@@ -10,7 +10,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
10
10
  */
11
11
  import QueryContent from './query-content';
12
12
  import QueryPlaceholder from './query-placeholder';
13
- import PatternSelectionModal from './pattern-selection-modal';
13
+ import { PatternSelectionModal } from './pattern-selection';
14
14
 
15
15
  const QueryEdit = ( props ) => {
16
16
  const { clientId, attributes } = props;
@@ -21,48 +21,67 @@ import {
21
21
  } from '../utils';
22
22
  import { searchPatterns } from '../../utils/search-patterns';
23
23
 
24
- export default function PatternSelectionModal( {
24
+ export function PatternSelectionModal( {
25
25
  clientId,
26
26
  attributes,
27
27
  setIsPatternSelectionModalOpen,
28
+ } ) {
29
+ return (
30
+ <Modal
31
+ overlayClassName="block-library-query-pattern__selection-modal"
32
+ title={ __( 'Choose a pattern' ) }
33
+ onRequestClose={ () => setIsPatternSelectionModalOpen( false ) }
34
+ isFullScreen
35
+ >
36
+ <PatternSelection clientId={ clientId } attributes={ attributes } />
37
+ </Modal>
38
+ );
39
+ }
40
+
41
+ export function useBlockPatterns( clientId, attributes ) {
42
+ const blockNameForPatterns = useBlockNameForPatterns(
43
+ clientId,
44
+ attributes
45
+ );
46
+ return usePatterns( clientId, blockNameForPatterns );
47
+ }
48
+
49
+ export default function PatternSelection( {
50
+ clientId,
51
+ attributes,
52
+ showTitlesAsTooltip = false,
53
+ showSearch = true,
28
54
  } ) {
29
55
  const [ searchValue, setSearchValue ] = useState( '' );
30
56
  const { replaceBlock, selectBlock } = useDispatch( blockEditorStore );
31
- const onBlockPatternSelect = ( pattern, blocks ) => {
32
- const { newBlocks, queryClientIds } = getTransformedBlocksFromPattern(
33
- blocks,
34
- attributes
35
- );
36
- replaceBlock( clientId, newBlocks );
37
- if ( queryClientIds[ 0 ] ) {
38
- selectBlock( queryClientIds[ 0 ] );
39
- }
40
- };
41
- // When we preview Query Loop blocks we should prefer the current
42
- // block's postType, which is passed through block context.
57
+ const blockPatterns = useBlockPatterns( clientId, attributes );
58
+ /*
59
+ * When we preview Query Loop blocks we should prefer the current
60
+ * block's postType, which is passed through block context.
61
+ */
43
62
  const blockPreviewContext = useMemo(
44
63
  () => ( {
45
64
  previewPostType: attributes.query.postType,
46
65
  } ),
47
66
  [ attributes.query.postType ]
48
67
  );
49
- const blockNameForPatterns = useBlockNameForPatterns(
50
- clientId,
51
- attributes
52
- );
53
- const blockPatterns = usePatterns( clientId, blockNameForPatterns );
54
68
  const filteredBlockPatterns = useMemo( () => {
55
69
  return searchPatterns( blockPatterns, searchValue );
56
70
  }, [ blockPatterns, searchValue ] );
57
71
 
72
+ const onBlockPatternSelect = ( pattern, blocks ) => {
73
+ const { newBlocks, queryClientIds } = getTransformedBlocksFromPattern(
74
+ blocks,
75
+ attributes
76
+ );
77
+ replaceBlock( clientId, newBlocks );
78
+ if ( queryClientIds[ 0 ] ) {
79
+ selectBlock( queryClientIds[ 0 ] );
80
+ }
81
+ };
58
82
  return (
59
- <Modal
60
- overlayClassName="block-library-query-pattern__selection-modal"
61
- title={ __( 'Choose a pattern' ) }
62
- onRequestClose={ () => setIsPatternSelectionModalOpen( false ) }
63
- isFullScreen
64
- >
65
- <div className="block-library-query-pattern__selection-content">
83
+ <div className="block-library-query-pattern__selection-content">
84
+ { showSearch && (
66
85
  <div className="block-library-query-pattern__selection-search">
67
86
  <SearchControl
68
87
  __nextHasNoMarginBottom
@@ -72,13 +91,14 @@ export default function PatternSelectionModal( {
72
91
  placeholder={ __( 'Search' ) }
73
92
  />
74
93
  </div>
75
- <BlockContextProvider value={ blockPreviewContext }>
76
- <BlockPatternsList
77
- blockPatterns={ filteredBlockPatterns }
78
- onClickPattern={ onBlockPatternSelect }
79
- />
80
- </BlockContextProvider>
81
- </div>
82
- </Modal>
94
+ ) }
95
+ <BlockContextProvider value={ blockPreviewContext }>
96
+ <BlockPatternsList
97
+ blockPatterns={ filteredBlockPatterns }
98
+ onClickPattern={ onBlockPatternSelect }
99
+ showTitlesAsTooltip={ showTitlesAsTooltip }
100
+ />
101
+ </BlockContextProvider>
102
+ </div>
83
103
  );
84
104
  }
@@ -19,10 +19,10 @@ import { store as coreStore } from '@wordpress/core-data';
19
19
  * Internal dependencies
20
20
  */
21
21
  import EnhancedPaginationControl from './inspector-controls/enhanced-pagination-control';
22
- import QueryToolbar from './query-toolbar';
23
22
  import QueryInspectorControls from './inspector-controls';
24
23
  import EnhancedPaginationModal from './enhanced-pagination-modal';
25
24
  import { getQueryContextFromTemplate } from '../utils';
25
+ import QueryToolbar from './query-toolbar';
26
26
 
27
27
  const DEFAULTS_POSTS_PER_PAGE = 3;
28
28
 
@@ -30,10 +30,9 @@ const TEMPLATE = [ [ 'core/post-template' ] ];
30
30
  export default function QueryContent( {
31
31
  attributes,
32
32
  setAttributes,
33
- openPatternSelectionModal,
34
- name,
35
33
  clientId,
36
34
  context,
35
+ name,
37
36
  } ) {
38
37
  const {
39
38
  queryId,
@@ -154,6 +153,7 @@ export default function QueryContent( {
154
153
  />
155
154
  <InspectorControls>
156
155
  <QueryInspectorControls
156
+ name={ name }
157
157
  attributes={ attributes }
158
158
  setQuery={ updateQuery }
159
159
  setDisplayLayout={ updateDisplayLayout }
@@ -163,13 +163,7 @@ export default function QueryContent( {
163
163
  />
164
164
  </InspectorControls>
165
165
  <BlockControls>
166
- <QueryToolbar
167
- name={ name }
168
- clientId={ clientId }
169
- attributes={ attributes }
170
- setQuery={ updateQuery }
171
- openPatternSelectionModal={ openPatternSelectionModal }
172
- />
166
+ <QueryToolbar attributes={ attributes } clientId={ clientId } />
173
167
  </BlockControls>
174
168
  <InspectorControls group="advanced">
175
169
  <SelectControl
@@ -18,7 +18,8 @@ import { __ } from '@wordpress/i18n';
18
18
  /**
19
19
  * Internal dependencies
20
20
  */
21
- import { useScopedBlockVariations, useBlockNameForPatterns } from '../utils';
21
+ import { useScopedBlockVariations } from '../utils';
22
+ import { useBlockPatterns } from './pattern-selection';
22
23
 
23
24
  export default function QueryPlaceholder( {
24
25
  attributes,
@@ -28,31 +29,21 @@ export default function QueryPlaceholder( {
28
29
  } ) {
29
30
  const [ isStartingBlank, setIsStartingBlank ] = useState( false );
30
31
  const blockProps = useBlockProps();
31
- const blockNameForPatterns = useBlockNameForPatterns(
32
- clientId,
33
- attributes
34
- );
35
- const { blockType, activeBlockVariation, hasPatterns } = useSelect(
32
+ const { blockType, activeBlockVariation } = useSelect(
36
33
  ( select ) => {
37
34
  const { getActiveBlockVariation, getBlockType } =
38
35
  select( blocksStore );
39
- const { getBlockRootClientId, getPatternsByBlockTypes } =
40
- select( blockEditorStore );
41
- const rootClientId = getBlockRootClientId( clientId );
42
36
  return {
43
37
  blockType: getBlockType( name ),
44
38
  activeBlockVariation: getActiveBlockVariation(
45
39
  name,
46
40
  attributes
47
41
  ),
48
- hasPatterns: !! getPatternsByBlockTypes(
49
- blockNameForPatterns,
50
- rootClientId
51
- ).length,
52
42
  };
53
43
  },
54
- [ name, blockNameForPatterns, clientId, attributes ]
44
+ [ name, attributes ]
55
45
  );
46
+ const hasPatterns = !! useBlockPatterns( clientId, attributes ).length;
56
47
  const icon =
57
48
  activeBlockVariation?.icon?.src ||
58
49
  activeBlockVariation?.icon ||