@wordpress/block-library 8.3.6 → 8.3.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.
Files changed (62) hide show
  1. package/build/list-item/hooks/use-outdent-list-item.js +2 -1
  2. package/build/list-item/hooks/use-outdent-list-item.js.map +1 -1
  3. package/build/navigation/edit/index.js +4 -2
  4. package/build/navigation/edit/index.js.map +1 -1
  5. package/build/navigation/edit/inner-blocks.js +4 -1
  6. package/build/navigation/edit/inner-blocks.js.map +1 -1
  7. package/build/navigation/edit/menu-inspector-controls.js +2 -1
  8. package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
  9. package/build/navigation-link/edit.js +0 -11
  10. package/build/navigation-link/edit.js.map +1 -1
  11. package/build/navigation-submenu/edit.js +1 -13
  12. package/build/navigation-submenu/edit.js.map +1 -1
  13. package/build/page-list/edit.js +5 -1
  14. package/build/page-list/edit.js.map +1 -1
  15. package/build/query/edit/query-placeholder.js +3 -2
  16. package/build/query/edit/query-placeholder.js.map +1 -1
  17. package/build/template-part/edit/import-controls.js +4 -24
  18. package/build/template-part/edit/import-controls.js.map +1 -1
  19. package/build/template-part/edit/utils/transformers.js +69 -19
  20. package/build/template-part/edit/utils/transformers.js.map +1 -1
  21. package/build-module/list-item/hooks/use-outdent-list-item.js +2 -1
  22. package/build-module/list-item/hooks/use-outdent-list-item.js.map +1 -1
  23. package/build-module/navigation/edit/index.js +4 -2
  24. package/build-module/navigation/edit/index.js.map +1 -1
  25. package/build-module/navigation/edit/inner-blocks.js +4 -1
  26. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  27. package/build-module/navigation/edit/menu-inspector-controls.js +2 -1
  28. package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
  29. package/build-module/navigation-link/edit.js +0 -11
  30. package/build-module/navigation-link/edit.js.map +1 -1
  31. package/build-module/navigation-submenu/edit.js +1 -13
  32. package/build-module/navigation-submenu/edit.js.map +1 -1
  33. package/build-module/page-list/edit.js +5 -1
  34. package/build-module/page-list/edit.js.map +1 -1
  35. package/build-module/query/edit/query-placeholder.js +4 -3
  36. package/build-module/query/edit/query-placeholder.js.map +1 -1
  37. package/build-module/template-part/edit/import-controls.js +4 -23
  38. package/build-module/template-part/edit/import-controls.js.map +1 -1
  39. package/build-module/template-part/edit/utils/transformers.js +69 -20
  40. package/build-module/template-part/edit/utils/transformers.js.map +1 -1
  41. package/build-style/editor-rtl.css +5 -1
  42. package/build-style/editor.css +5 -1
  43. package/build-style/navigation/editor-rtl.css +1 -1
  44. package/build-style/navigation/editor.css +1 -1
  45. package/build-style/page-list/editor-rtl.css +4 -0
  46. package/build-style/page-list/editor.css +4 -0
  47. package/package.json +6 -6
  48. package/src/list-item/hooks/use-outdent-list-item.js +2 -1
  49. package/src/navigation/edit/index.js +3 -1
  50. package/src/navigation/edit/inner-blocks.js +3 -0
  51. package/src/navigation/edit/menu-inspector-controls.js +2 -3
  52. package/src/navigation/editor.scss +23 -20
  53. package/src/navigation/index.php +8 -6
  54. package/src/navigation-link/edit.js +0 -9
  55. package/src/navigation-link/index.php +4 -5
  56. package/src/navigation-submenu/edit.js +0 -10
  57. package/src/navigation-submenu/index.php +23 -6
  58. package/src/page-list/edit.js +3 -1
  59. package/src/page-list/editor.scss +6 -0
  60. package/src/query/edit/query-placeholder.js +10 -5
  61. package/src/template-part/edit/import-controls.js +2 -29
  62. package/src/template-part/edit/utils/transformers.js +96 -19
@@ -373,12 +373,14 @@ function block_core_navigation_get_most_recently_published_navigation() {
373
373
 
374
374
  // Default to the most recently created menu.
375
375
  $parsed_args = array(
376
- 'post_type' => 'wp_navigation',
377
- 'no_found_rows' => true,
378
- 'order' => 'DESC',
379
- 'orderby' => 'date',
380
- 'post_status' => 'publish',
381
- 'posts_per_page' => 1, // get only the most recent.
376
+ 'post_type' => 'wp_navigation',
377
+ 'no_found_rows' => true,
378
+ 'update_post_meta_cache' => false,
379
+ 'update_post_term_cache' => false,
380
+ 'order' => 'DESC',
381
+ 'orderby' => 'date',
382
+ 'post_status' => 'publish',
383
+ 'posts_per_page' => 1, // get only the most recent.
382
384
  );
383
385
 
384
386
  $navigation_post = new WP_Query( $parsed_args );
@@ -225,15 +225,6 @@ export default function NavigationLinkEdit( {
225
225
  [ clientId ]
226
226
  );
227
227
 
228
- useEffect( () => {
229
- // This side-effect should not create an undo level as those should
230
- // only be created via user interactions. Mark this change as
231
- // not persistent to avoid undo level creation.
232
- // See https://github.com/WordPress/gutenberg/issues/34564.
233
- __unstableMarkNextChangeAsNotPersistent();
234
- setAttributes( { isTopLevelLink } );
235
- }, [ isTopLevelLink ] );
236
-
237
228
  /**
238
229
  * Transform to submenu block.
239
230
  */
@@ -9,18 +9,17 @@
9
9
  * Build an array with CSS classes and inline styles defining the colors
10
10
  * which will be applied to the navigation markup in the front-end.
11
11
  *
12
- * @param array $context Navigation block context.
13
- * @param array $attributes Block attributes.
12
+ * @param array $context Navigation block context.
13
+ * @param array $attributes Block attributes.
14
+ * @param bool $is_sub_menu Whether the link is part of a sub-menu.
14
15
  * @return array Colors CSS classes and inline styles.
15
16
  */
16
- function block_core_navigation_link_build_css_colors( $context, $attributes ) {
17
+ function block_core_navigation_link_build_css_colors( $context, $attributes, $is_sub_menu = false ) {
17
18
  $colors = array(
18
19
  'css_classes' => array(),
19
20
  'inline_styles' => '',
20
21
  );
21
22
 
22
- $is_sub_menu = isset( $attributes['isTopLevelLink'] ) ? ( ! $attributes['isTopLevelLink'] ) : false;
23
-
24
23
  // Text color.
25
24
  $named_text_color = null;
26
25
  $custom_text_color = null;
@@ -224,16 +224,6 @@ export default function NavigationSubmenuEdit( {
224
224
  }
225
225
  }, [] );
226
226
 
227
- // Store the colors from context as attributes for rendering.
228
- useEffect( () => {
229
- // This side-effect should not create an undo level as those should
230
- // only be created via user interactions. Mark this change as
231
- // not persistent to avoid undo level creation.
232
- // See https://github.com/WordPress/gutenberg/issues/34564.
233
- __unstableMarkNextChangeAsNotPersistent();
234
- setAttributes( { isTopLevelItem } );
235
- }, [ isTopLevelItem ] );
236
-
237
227
  /**
238
228
  * The hook shouldn't be necessary but due to a focus loss happening
239
229
  * when selecting a suggestion in the link popover, we force close on block unselection.
@@ -9,18 +9,17 @@
9
9
  * Build an array with CSS classes and inline styles defining the colors
10
10
  * which will be applied to the navigation markup in the front-end.
11
11
  *
12
- * @param array $context Navigation block context.
13
- * @param array $attributes Block attributes.
12
+ * @param array $context Navigation block context.
13
+ * @param array $attributes Block attributes.
14
+ * @param bool $is_sub_menu Whether the block is a sub-menu.
14
15
  * @return array Colors CSS classes and inline styles.
15
16
  */
16
- function block_core_navigation_submenu_build_css_colors( $context, $attributes ) {
17
+ function block_core_navigation_submenu_build_css_colors( $context, $attributes, $is_sub_menu = false ) {
17
18
  $colors = array(
18
19
  'css_classes' => array(),
19
20
  'inline_styles' => '',
20
21
  );
21
22
 
22
- $is_sub_menu = isset( $attributes['isTopLevelItem'] ) ? ( ! $attributes['isTopLevelItem'] ) : false;
23
-
24
23
  // Text color.
25
24
  $named_text_color = null;
26
25
  $custom_text_color = null;
@@ -250,6 +249,15 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
250
249
  }
251
250
 
252
251
  if ( $has_submenu ) {
252
+ $colors = block_core_navigation_submenu_build_css_colors( $block->context, $attributes, $has_submenu );
253
+ $classes = array_merge(
254
+ array( 'wp-block-navigation__submenu-container' ),
255
+ $colors['css_classes']
256
+ );
257
+ $css_classes = trim( implode( ' ', $classes ) );
258
+
259
+ $style_attribute = $colors['inline_styles'];
260
+
253
261
  $inner_blocks_html = '';
254
262
  foreach ( $block->inner_blocks as $inner_block ) {
255
263
  $inner_blocks_html .= $inner_block->render();
@@ -263,10 +271,19 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
263
271
  $html = $tag_processor->get_updated_html();
264
272
  }
265
273
 
274
+ $wrapper_attributes = get_block_wrapper_attributes(
275
+ array(
276
+ 'class' => $css_classes,
277
+ 'style' => $style_attribute,
278
+ )
279
+ );
280
+
266
281
  $html .= sprintf(
267
- '<ul class="wp-block-navigation__submenu-container">%s</ul>',
282
+ '<ul %s>%s</ul>',
283
+ $wrapper_attributes,
268
284
  $inner_blocks_html
269
285
  );
286
+
270
287
  }
271
288
 
272
289
  $html .= '</li>';
@@ -55,7 +55,9 @@ function BlockContent( {
55
55
  if ( ! hasResolvedPages ) {
56
56
  return (
57
57
  <div { ...blockProps }>
58
- <Spinner />
58
+ <div className="wp-block-page-list__loading-indicator-container">
59
+ <Spinner className="wp-block-page-list__loading-indicator" />
60
+ </div>
59
61
  </div>
60
62
  );
61
63
  }
@@ -61,3 +61,9 @@
61
61
  .wp-block-page-list .components-notice {
62
62
  margin-left: 0;
63
63
  }
64
+
65
+ // Space spinner to give it breathing
66
+ // room when block is selected and has focus outline.
67
+ .wp-block-page-list__loading-indicator-container {
68
+ padding: $grid-unit-10 $grid-unit-15;
69
+ }
@@ -19,7 +19,7 @@ import { __ } from '@wordpress/i18n';
19
19
  /**
20
20
  * Internal dependencies
21
21
  */
22
- import { useScopedBlockVariations } from '../utils';
22
+ import { useScopedBlockVariations, useBlockNameForPatterns } from '../utils';
23
23
 
24
24
  export default function QueryPlaceholder( {
25
25
  attributes,
@@ -30,6 +30,10 @@ export default function QueryPlaceholder( {
30
30
  } ) {
31
31
  const [ isStartingBlank, setIsStartingBlank ] = useState( false );
32
32
  const blockProps = useBlockProps();
33
+ const blockNameForPatterns = useBlockNameForPatterns(
34
+ clientId,
35
+ attributes
36
+ );
33
37
 
34
38
  const { blockType, allVariations, hasPatterns } = useSelect(
35
39
  ( select ) => {
@@ -37,15 +41,16 @@ export default function QueryPlaceholder( {
37
41
  const { getBlockRootClientId, getPatternsByBlockTypes } =
38
42
  select( blockEditorStore );
39
43
  const rootClientId = getBlockRootClientId( clientId );
40
-
41
44
  return {
42
45
  blockType: getBlockType( name ),
43
46
  allVariations: getBlockVariations( name ),
44
- hasPatterns: !! getPatternsByBlockTypes( name, rootClientId )
45
- .length,
47
+ hasPatterns: !! getPatternsByBlockTypes(
48
+ blockNameForPatterns,
49
+ rootClientId
50
+ ).length,
46
51
  };
47
52
  },
48
- [ name, clientId ]
53
+ [ name, blockNameForPatterns, clientId ]
49
54
  );
50
55
 
51
56
  const matchingVariation = getMatchingVariation( attributes, allVariations );
@@ -12,10 +12,6 @@ import {
12
12
  __experimentalHStack as HStack,
13
13
  __experimentalSpacer as Spacer,
14
14
  } from '@wordpress/components';
15
- import {
16
- switchToBlockType,
17
- getPossibleBlockTransformations,
18
- } from '@wordpress/blocks';
19
15
  import { store as coreStore } from '@wordpress/core-data';
20
16
  import { store as noticesStore } from '@wordpress/notices';
21
17
 
@@ -110,36 +106,13 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
110
106
  const blocks = widgets.flatMap( ( widget ) => {
111
107
  const block = transformWidgetToBlock( widget );
112
108
 
113
- if ( block.name !== 'core/legacy-widget' ) {
114
- return block;
115
- }
116
-
117
- const transforms = getPossibleBlockTransformations( [
118
- block,
119
- ] ).filter( ( item ) => {
120
- // The block without any transformations can't be a wildcard.
121
- if ( ! item.transforms ) {
122
- return true;
123
- }
124
-
125
- const hasWildCardFrom = item.transforms?.from?.find(
126
- ( from ) => from.blocks && from.blocks.includes( '*' )
127
- );
128
- const hasWildCardTo = item.transforms?.to?.find(
129
- ( to ) => to.blocks && to.blocks.includes( '*' )
130
- );
131
-
132
- return ! hasWildCardFrom && ! hasWildCardTo;
133
- } );
134
-
135
109
  // Skip the block if we have no matching transformations.
136
- if ( ! transforms.length ) {
110
+ if ( ! block ) {
137
111
  skippedWidgets.add( widget.id_base );
138
112
  return [];
139
113
  }
140
114
 
141
- // Try transforming the Legacy Widget into a first matching block.
142
- return switchToBlockType( block, transforms[ 0 ].name );
115
+ return block;
143
116
  } );
144
117
 
145
118
  await createFromBlocks(
@@ -1,7 +1,14 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createBlock, parse } from '@wordpress/blocks';
4
+ import {
5
+ parse,
6
+ cloneBlock,
7
+ createBlock,
8
+ getGroupingBlockName,
9
+ getPossibleBlockTransformations,
10
+ switchToBlockType,
11
+ } from '@wordpress/blocks';
5
12
 
6
13
  /**
7
14
  * Converts a widget entity record into a block.
@@ -10,28 +17,98 @@ import { createBlock, parse } from '@wordpress/blocks';
10
17
  * @return {Object} a block (converted from the entity record).
11
18
  */
12
19
  export function transformWidgetToBlock( widget ) {
13
- if ( widget.id_base === 'block' ) {
14
- const parsedBlocks = parse( widget.instance.raw.content, {
15
- __unstableSkipAutop: true,
16
- } );
17
- if ( ! parsedBlocks.length ) {
18
- return createBlock( 'core/paragraph', {}, [] );
20
+ if ( widget.id_base !== 'block' ) {
21
+ let attributes;
22
+ if ( widget._embedded.about[ 0 ].is_multi ) {
23
+ attributes = {
24
+ idBase: widget.id_base,
25
+ instance: widget.instance,
26
+ };
27
+ } else {
28
+ attributes = {
29
+ id: widget.id,
30
+ };
19
31
  }
20
32
 
21
- return parsedBlocks[ 0 ];
33
+ return switchLegacyWidgetType(
34
+ createBlock( 'core/legacy-widget', attributes )
35
+ );
22
36
  }
23
37
 
24
- let attributes;
25
- if ( widget._embedded.about[ 0 ].is_multi ) {
26
- attributes = {
27
- idBase: widget.id_base,
28
- instance: widget.instance,
29
- };
30
- } else {
31
- attributes = {
32
- id: widget.id,
33
- };
38
+ const parsedBlocks = parse( widget.instance.raw.content, {
39
+ __unstableSkipAutop: true,
40
+ } );
41
+
42
+ if ( ! parsedBlocks.length ) {
43
+ return undefined;
44
+ }
45
+
46
+ const block = parsedBlocks[ 0 ];
47
+
48
+ if ( block.name === 'core/widget-group' ) {
49
+ return createBlock(
50
+ getGroupingBlockName(),
51
+ undefined,
52
+ transformInnerBlocks( block.innerBlocks )
53
+ );
54
+ }
55
+
56
+ if ( block.innerBlocks.length > 0 ) {
57
+ return cloneBlock(
58
+ block,
59
+ undefined,
60
+ transformInnerBlocks( block.innerBlocks )
61
+ );
62
+ }
63
+
64
+ return block;
65
+ }
66
+
67
+ /**
68
+ * Switch Legacy Widget to the first matching transformation block.
69
+ *
70
+ * @param {Object} block Legacy Widget block object
71
+ * @return {Object|undefined} a block
72
+ */
73
+ function switchLegacyWidgetType( block ) {
74
+ const transforms = getPossibleBlockTransformations( [ block ] ).filter(
75
+ ( item ) => {
76
+ // The block without any transformations can't be a wildcard.
77
+ if ( ! item.transforms ) {
78
+ return true;
79
+ }
80
+
81
+ const hasWildCardFrom = item.transforms?.from?.find(
82
+ ( from ) => from.blocks && from.blocks.includes( '*' )
83
+ );
84
+ const hasWildCardTo = item.transforms?.to?.find(
85
+ ( to ) => to.blocks && to.blocks.includes( '*' )
86
+ );
87
+
88
+ // Skip wildcard transformations.
89
+ return ! hasWildCardFrom && ! hasWildCardTo;
90
+ }
91
+ );
92
+
93
+ if ( ! transforms.length ) {
94
+ return undefined;
34
95
  }
35
96
 
36
- return createBlock( 'core/legacy-widget', attributes, [] );
97
+ return switchToBlockType( block, transforms[ 0 ].name );
98
+ }
99
+
100
+ function transformInnerBlocks( innerBlocks = [] ) {
101
+ return innerBlocks
102
+ .flatMap( ( block ) => {
103
+ if ( block.name === 'core/legacy-widget' ) {
104
+ return switchLegacyWidgetType( block );
105
+ }
106
+
107
+ return createBlock(
108
+ block.name,
109
+ block.attributes,
110
+ transformInnerBlocks( block.innerBlocks )
111
+ );
112
+ } )
113
+ .filter( ( block ) => !! block );
37
114
  }