@wordpress/block-library 6.0.6 → 6.0.10
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.
- package/build/cover/edit.js +8 -3
- package/build/cover/edit.js.map +1 -1
- package/build/cover/transforms.js +2 -0
- package/build/cover/transforms.js.map +1 -1
- package/build/gallery/edit.js +1 -1
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/v1/update-gallery-modal.js +1 -1
- package/build/gallery/v1/update-gallery-modal.js.map +1 -1
- package/build/index.js +4 -3
- package/build/index.js.map +1 -1
- package/build/navigation/deprecated.js +118 -12
- package/build/navigation/deprecated.js.map +1 -1
- package/build/navigation/edit/index.js +59 -33
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +1 -1
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation/edit/navigation-menu-selector.js +2 -2
- package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build/navigation/edit/placeholder/index.js +16 -48
- package/build/navigation/edit/placeholder/index.js.map +1 -1
- package/build/navigation/edit/responsive-wrapper.js +5 -2
- package/build/navigation/edit/responsive-wrapper.js.map +1 -1
- package/build/navigation/edit/unsaved-inner-blocks.js +4 -35
- package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build/navigation/edit/use-create-navigation-menu.js +50 -0
- package/build/navigation/edit/use-create-navigation-menu.js.map +1 -0
- package/build/navigation/edit/use-generate-default-navigation-title.js +73 -0
- package/build/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
- package/build/navigation/index.js +1 -1
- package/build/navigation/save.js +2 -2
- package/build/navigation/save.js.map +1 -1
- package/build/navigation/use-navigation-menu.js +19 -8
- package/build/navigation/use-navigation-menu.js.map +1 -1
- package/build/navigation-area/edit.js +5 -0
- package/build/navigation-area/edit.js.map +1 -1
- package/build/page-list/edit.js +40 -42
- package/build/page-list/edit.js.map +1 -1
- package/build/pattern/index.js +1 -1
- package/build/post-featured-image/edit.js +53 -23
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-terms/index.js +1 -1
- package/build/post-title/edit.js +2 -2
- package/build/post-title/edit.js.map +1 -1
- package/build/query-title/index.js +1 -1
- package/build/site-logo/index.js +1 -1
- package/build/site-tagline/index.js +1 -1
- package/build/site-title/index.js +1 -1
- package/build/template-part/edit/placeholder/index.js +1 -1
- package/build/template-part/edit/placeholder/index.js.map +1 -1
- package/build/template-part/index.js +2 -1
- package/build/template-part/index.js.map +1 -1
- package/build-module/cover/edit.js +8 -3
- package/build-module/cover/edit.js.map +1 -1
- package/build-module/cover/transforms.js +2 -0
- package/build-module/cover/transforms.js.map +1 -1
- package/build-module/gallery/edit.js +1 -1
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/v1/update-gallery-modal.js +1 -1
- package/build-module/gallery/v1/update-gallery-modal.js.map +1 -1
- package/build-module/index.js +4 -3
- package/build-module/index.js.map +1 -1
- package/build-module/navigation/deprecated.js +118 -12
- package/build-module/navigation/deprecated.js.map +1 -1
- package/build-module/navigation/edit/index.js +60 -33
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +1 -1
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/navigation-menu-selector.js +2 -2
- package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
- package/build-module/navigation/edit/placeholder/index.js +15 -45
- package/build-module/navigation/edit/placeholder/index.js.map +1 -1
- package/build-module/navigation/edit/responsive-wrapper.js +5 -2
- package/build-module/navigation/edit/responsive-wrapper.js.map +1 -1
- package/build-module/navigation/edit/unsaved-inner-blocks.js +6 -35
- package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
- package/build-module/navigation/edit/use-create-navigation-menu.js +36 -0
- package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -0
- package/build-module/navigation/edit/use-generate-default-navigation-title.js +57 -0
- package/build-module/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
- package/build-module/navigation/index.js +1 -1
- package/build-module/navigation/save.js +2 -2
- package/build-module/navigation/save.js.map +1 -1
- package/build-module/navigation/use-navigation-menu.js +19 -8
- package/build-module/navigation/use-navigation-menu.js.map +1 -1
- package/build-module/navigation-area/edit.js +4 -0
- package/build-module/navigation-area/edit.js.map +1 -1
- package/build-module/page-list/edit.js +41 -43
- package/build-module/page-list/edit.js.map +1 -1
- package/build-module/pattern/index.js +1 -1
- package/build-module/post-featured-image/edit.js +55 -26
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-terms/index.js +1 -1
- package/build-module/post-title/edit.js +2 -2
- package/build-module/post-title/edit.js.map +1 -1
- package/build-module/query-title/index.js +1 -1
- package/build-module/site-logo/index.js +1 -1
- package/build-module/site-tagline/index.js +1 -1
- package/build-module/site-title/index.js +1 -1
- package/build-module/template-part/edit/placeholder/index.js +2 -2
- package/build-module/template-part/edit/placeholder/index.js.map +1 -1
- package/build-module/template-part/index.js +2 -1
- package/build-module/template-part/index.js.map +1 -1
- package/build-style/code/theme-rtl.css +1 -1
- package/build-style/code/theme.css +1 -1
- package/build-style/cover/style-rtl.css +8 -2
- package/build-style/cover/style.css +8 -2
- package/build-style/editor-rtl.css +104 -53
- package/build-style/editor.css +104 -53
- package/build-style/gallery/editor-rtl.css +1 -0
- package/build-style/gallery/editor.css +1 -0
- package/build-style/navigation/style-rtl.css +40 -3
- package/build-style/navigation/style.css +40 -3
- package/build-style/post-comments-form/style-rtl.css +18 -0
- package/build-style/post-comments-form/style.css +18 -0
- package/build-style/post-featured-image/editor-rtl.css +100 -16
- package/build-style/post-featured-image/editor.css +100 -16
- package/build-style/site-logo/editor-rtl.css +2 -2
- package/build-style/site-logo/editor.css +2 -2
- package/build-style/social-links/editor-rtl.css +1 -35
- package/build-style/social-links/editor.css +1 -35
- package/build-style/style-rtl.css +66 -27
- package/build-style/style.css +66 -27
- package/build-style/theme-rtl.css +1 -1
- package/build-style/theme.css +1 -1
- package/package.json +8 -8
- package/src/calendar/index.php +3 -3
- package/src/code/theme.scss +1 -1
- package/src/cover/edit.js +8 -1
- package/src/cover/style.scss +9 -2
- package/src/cover/transforms.js +2 -0
- package/src/gallery/edit.js +1 -1
- package/src/gallery/editor.scss +1 -0
- package/src/gallery/index.php +1 -1
- package/src/gallery/v1/update-gallery-modal.js +1 -1
- package/src/home-link/index.php +1 -1
- package/src/image/index.php +1 -1
- package/src/index.js +28 -26
- package/src/navigation/block.json +1 -1
- package/src/navigation/deprecated.js +105 -4
- package/src/navigation/edit/index.js +68 -36
- package/src/navigation/edit/inner-blocks.js +2 -1
- package/src/navigation/edit/navigation-menu-selector.js +2 -2
- package/src/navigation/edit/placeholder/index.js +16 -62
- package/src/navigation/edit/responsive-wrapper.js +8 -1
- package/src/navigation/edit/unsaved-inner-blocks.js +6 -57
- package/src/navigation/edit/use-create-navigation-menu.js +39 -0
- package/src/navigation/edit/use-generate-default-navigation-title.js +79 -0
- package/src/navigation/index.php +173 -19
- package/src/navigation/save.js +2 -2
- package/src/navigation/style.scss +56 -5
- package/src/navigation/use-navigation-menu.js +20 -9
- package/src/navigation-area/edit.js +5 -0
- package/src/navigation-area/index.php +2 -1
- package/src/navigation-link/index.php +1 -1
- package/src/navigation-submenu/index.php +2 -8
- package/src/page-list/edit.js +35 -44
- package/src/page-list/index.php +10 -5
- package/src/pattern/block.json +1 -1
- package/src/post-comments-form/style.scss +20 -1
- package/src/post-featured-image/edit.js +58 -26
- package/src/post-featured-image/editor.scss +124 -20
- package/src/post-terms/block.json +1 -1
- package/src/post-title/edit.js +2 -2
- package/src/query-title/block.json +1 -1
- package/src/site-logo/block.json +1 -1
- package/src/site-logo/editor.scss +3 -2
- package/src/site-tagline/block.json +1 -1
- package/src/site-title/block.json +1 -1
- package/src/social-links/editor.scss +1 -47
- package/src/style.scss +0 -1
- package/src/table-of-contents/index.php +1 -1
- package/src/template-part/block.json +2 -1
- package/src/template-part/edit/placeholder/index.js +2 -2
- package/src/template-part/index.php +2 -1
- package/build/navigation/edit/navigation-menu-name-modal.js +0 -55
- package/build/navigation/edit/navigation-menu-name-modal.js.map +0 -1
- package/build/navigation/edit/navigation-menu-publish-button.js +0 -53
- package/build/navigation/edit/navigation-menu-publish-button.js.map +0 -1
- package/build-module/navigation/edit/navigation-menu-name-modal.js +0 -47
- package/build-module/navigation/edit/navigation-menu-name-modal.js.map +0 -1
- package/build-module/navigation/edit/navigation-menu-publish-button.js +0 -40
- package/build-module/navigation/edit/navigation-menu-publish-button.js.map +0 -1
- package/build-style/navigation-submenu/style-rtl.css +0 -97
- package/build-style/navigation-submenu/style.css +0 -97
- package/src/navigation/edit/navigation-menu-name-modal.js +0 -69
- package/src/navigation/edit/navigation-menu-publish-button.js +0 -57
- package/src/navigation-submenu/style.scss +0 -25
package/src/navigation/index.php
CHANGED
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Server-side rendering of the `core/navigation` block.
|
|
4
4
|
*
|
|
5
|
-
* @package
|
|
5
|
+
* @package WordPress
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
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
|
|
12
|
+
* @param array $attributes Navigation block attributes.
|
|
13
|
+
*
|
|
13
14
|
* @return array Colors CSS classes and inline styles.
|
|
14
15
|
*/
|
|
15
16
|
function block_core_navigation_build_css_colors( $attributes ) {
|
|
16
17
|
$colors = array(
|
|
17
|
-
'css_classes'
|
|
18
|
-
'inline_styles'
|
|
18
|
+
'css_classes' => array(),
|
|
19
|
+
'inline_styles' => '',
|
|
20
|
+
'overlay_css_classes' => array(),
|
|
21
|
+
'overlay_inline_styles' => '',
|
|
19
22
|
);
|
|
20
23
|
|
|
21
24
|
// Text color.
|
|
@@ -54,6 +57,42 @@ function block_core_navigation_build_css_colors( $attributes ) {
|
|
|
54
57
|
$colors['inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] );
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
// Overlay text color.
|
|
61
|
+
$has_named_overlay_text_color = array_key_exists( 'overlayTextColor', $attributes );
|
|
62
|
+
$has_custom_overlay_text_color = array_key_exists( 'customOverlayTextColor', $attributes );
|
|
63
|
+
|
|
64
|
+
// If has overlay text color.
|
|
65
|
+
if ( $has_custom_overlay_text_color || $has_named_overlay_text_color ) {
|
|
66
|
+
// Add has-text-color class.
|
|
67
|
+
$colors['overlay_css_classes'][] = 'has-text-color';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ( $has_named_overlay_text_color ) {
|
|
71
|
+
// Add the overlay color class.
|
|
72
|
+
$colors['overlay_css_classes'][] = sprintf( 'has-%s-color', $attributes['overlayTextColor'] );
|
|
73
|
+
} elseif ( $has_custom_overlay_text_color ) {
|
|
74
|
+
// Add the custom overlay color inline style.
|
|
75
|
+
$colors['overlay_inline_styles'] .= sprintf( 'color: %s;', $attributes['customOverlayTextColor'] );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Overlay background color.
|
|
79
|
+
$has_named_overlay_background_color = array_key_exists( 'overlayBackgroundColor', $attributes );
|
|
80
|
+
$has_custom_overlay_background_color = array_key_exists( 'customOverlayBackgroundColor', $attributes );
|
|
81
|
+
|
|
82
|
+
// If has overlay background color.
|
|
83
|
+
if ( $has_custom_overlay_background_color || $has_named_overlay_background_color ) {
|
|
84
|
+
// Add has-background class.
|
|
85
|
+
$colors['overlay_css_classes'][] = 'has-background';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if ( $has_named_overlay_background_color ) {
|
|
89
|
+
// Add the overlay background-color class.
|
|
90
|
+
$colors['overlay_css_classes'][] = sprintf( 'has-%s-background-color', $attributes['overlayBackgroundColor'] );
|
|
91
|
+
} elseif ( $has_custom_overlay_background_color ) {
|
|
92
|
+
// Add the custom overlay background-color inline style.
|
|
93
|
+
$colors['overlay_inline_styles'] .= sprintf( 'background-color: %s;', $attributes['customOverlayBackgroundColor'] );
|
|
94
|
+
}
|
|
95
|
+
|
|
57
96
|
return $colors;
|
|
58
97
|
}
|
|
59
98
|
|
|
@@ -61,7 +100,8 @@ function block_core_navigation_build_css_colors( $attributes ) {
|
|
|
61
100
|
* Build an array with CSS classes and inline styles defining the font sizes
|
|
62
101
|
* which will be applied to the navigation markup in the front-end.
|
|
63
102
|
*
|
|
64
|
-
* @param
|
|
103
|
+
* @param array $attributes Navigation block attributes.
|
|
104
|
+
*
|
|
65
105
|
* @return array Font size CSS classes and inline styles.
|
|
66
106
|
*/
|
|
67
107
|
function block_core_navigation_build_css_font_sizes( $attributes ) {
|
|
@@ -94,6 +134,100 @@ function block_core_navigation_render_submenu_icon() {
|
|
|
94
134
|
return '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" role="img" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
|
|
95
135
|
}
|
|
96
136
|
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Finds the first non-empty `wp_navigation` Post.
|
|
140
|
+
*
|
|
141
|
+
* @return WP_Post|null the first non-empty Navigation or null.
|
|
142
|
+
*/
|
|
143
|
+
function block_core_navigation_get_first_non_empty_navigation() {
|
|
144
|
+
// Order and orderby args set to mirror those in `wp_get_nav_menus`
|
|
145
|
+
// see:
|
|
146
|
+
// - https://github.com/WordPress/wordpress-develop/blob/ba943e113d3b31b121f77a2d30aebe14b047c69d/src/wp-includes/nav-menu.php#L613-L619.
|
|
147
|
+
// - https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters.
|
|
148
|
+
$navigation_posts = get_posts(
|
|
149
|
+
array(
|
|
150
|
+
'post_type' => 'wp_navigation',
|
|
151
|
+
'order' => 'ASC',
|
|
152
|
+
'orderby' => 'name',
|
|
153
|
+
'posts_per_page' => 1, // only the first post.
|
|
154
|
+
's' => '<!-- wp:', // look for block indicators to ensure we only include non-empty Navigations.
|
|
155
|
+
)
|
|
156
|
+
);
|
|
157
|
+
return count( $navigation_posts ) ? $navigation_posts[0] : null;
|
|
158
|
+
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Filter out empty "null" blocks from the block list.
|
|
163
|
+
* 'parse_blocks' includes a null block with '\n\n' as the content when
|
|
164
|
+
* it encounters whitespace. This is not a bug but rather how the parser
|
|
165
|
+
* is designed.
|
|
166
|
+
*
|
|
167
|
+
* @param array $parsed_blocks the parsed blocks to be normalized.
|
|
168
|
+
* @return array the normalized parsed blocks.
|
|
169
|
+
*/
|
|
170
|
+
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
|
|
171
|
+
$filtered = array_filter(
|
|
172
|
+
$parsed_blocks,
|
|
173
|
+
function( $block ) {
|
|
174
|
+
return isset( $block['blockName'] );
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Reset keys.
|
|
179
|
+
return array_values( $filtered );
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves the appropriate fallback to be used on the front of the
|
|
184
|
+
* site when there is no menu assigned to the Nav block.
|
|
185
|
+
*
|
|
186
|
+
* This aims to mirror how the fallback mechanic for wp_nav_menu works.
|
|
187
|
+
* See https://developer.wordpress.org/reference/functions/wp_nav_menu/#more-information.
|
|
188
|
+
*
|
|
189
|
+
* @return array the array of blocks to be used as a fallback.
|
|
190
|
+
*/
|
|
191
|
+
function block_core_navigation_get_fallback_blocks() {
|
|
192
|
+
$page_list_fallback = array(
|
|
193
|
+
array(
|
|
194
|
+
'blockName' => 'core/page-list',
|
|
195
|
+
'attrs' => array(
|
|
196
|
+
'__unstableMaxPages' => 4,
|
|
197
|
+
),
|
|
198
|
+
),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
$registry = WP_Block_Type_Registry::get_instance();
|
|
202
|
+
|
|
203
|
+
// If `core/page-list` is not registered then return empty blocks.
|
|
204
|
+
$fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();
|
|
205
|
+
|
|
206
|
+
// Default to a list of Pages.
|
|
207
|
+
|
|
208
|
+
$navigation_post = block_core_navigation_get_first_non_empty_navigation();
|
|
209
|
+
|
|
210
|
+
// Prefer using the first non-empty Navigation as fallback if available.
|
|
211
|
+
if ( $navigation_post ) {
|
|
212
|
+
$maybe_fallback = block_core_navigation_filter_out_empty_blocks( parse_blocks( $navigation_post->post_content ) );
|
|
213
|
+
|
|
214
|
+
// Normalizing blocks may result in an empty array of blocks if they were all `null` blocks.
|
|
215
|
+
// In this case default to the (Page List) fallback.
|
|
216
|
+
$fallback_blocks = ! empty( $maybe_fallback ) ? $maybe_fallback : $fallback_blocks;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Filters the fallback experience for the Navigation block.
|
|
221
|
+
*
|
|
222
|
+
* Returning a falsey value will opt out of the fallback and cause the block not to render.
|
|
223
|
+
* To customise the blocks provided return an array of blocks - these should be valid
|
|
224
|
+
* children of the `core/navigation` block.
|
|
225
|
+
*
|
|
226
|
+
* @param array[] default fallback blocks provided by the default block mechanic.
|
|
227
|
+
*/
|
|
228
|
+
return apply_filters( 'block_core_navigation_render_fallback', $fallback_blocks );
|
|
229
|
+
}
|
|
230
|
+
|
|
97
231
|
/**
|
|
98
232
|
* Renders the `core/navigation` block on server.
|
|
99
233
|
*
|
|
@@ -104,6 +238,11 @@ function block_core_navigation_render_submenu_icon() {
|
|
|
104
238
|
* @return string Returns the post content with the legacy widget added.
|
|
105
239
|
*/
|
|
106
240
|
function render_block_core_navigation( $attributes, $content, $block ) {
|
|
241
|
+
|
|
242
|
+
// Flag used to indicate whether the rendered output is considered to be
|
|
243
|
+
// a fallback (i.e. the block has no menu associated with it).
|
|
244
|
+
$is_fallback = false;
|
|
245
|
+
|
|
107
246
|
/**
|
|
108
247
|
* Deprecated:
|
|
109
248
|
* The rgbTextColor and rgbBackgroundColor attributes
|
|
@@ -149,13 +288,17 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
149
288
|
$area = $block->context['navigationArea'];
|
|
150
289
|
$mapping = get_option( 'wp_navigation_areas', array() );
|
|
151
290
|
if ( ! empty( $mapping[ $area ] ) ) {
|
|
152
|
-
$attributes['
|
|
291
|
+
$attributes['ref'] = $mapping[ $area ];
|
|
153
292
|
}
|
|
154
293
|
}
|
|
155
294
|
|
|
156
|
-
//
|
|
295
|
+
// Ensure that blocks saved with the legacy ref attribute name (navigationMenuId) continue to render.
|
|
157
296
|
if ( array_key_exists( 'navigationMenuId', $attributes ) ) {
|
|
158
|
-
$
|
|
297
|
+
$attributes['ref'] = $attributes['navigationMenuId'];
|
|
298
|
+
}
|
|
299
|
+
// Load inner blocks from the navigation post.
|
|
300
|
+
if ( array_key_exists( 'ref', $attributes ) ) {
|
|
301
|
+
$navigation_post = get_post( $attributes['ref'] );
|
|
159
302
|
if ( ! isset( $navigation_post ) ) {
|
|
160
303
|
return '';
|
|
161
304
|
}
|
|
@@ -164,20 +307,26 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
164
307
|
|
|
165
308
|
// 'parse_blocks' includes a null block with '\n\n' as the content when
|
|
166
309
|
// it encounters whitespace. This code strips it.
|
|
167
|
-
$compacted_blocks =
|
|
168
|
-
$parsed_blocks,
|
|
169
|
-
function( $block ) {
|
|
170
|
-
return isset( $block['blockName'] );
|
|
171
|
-
}
|
|
172
|
-
);
|
|
310
|
+
$compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
|
|
173
311
|
|
|
174
312
|
// TODO - this uses the full navigation block attributes for the
|
|
175
313
|
// context which could be refined.
|
|
176
314
|
$inner_blocks = new WP_Block_List( $compacted_blocks, $attributes );
|
|
177
315
|
}
|
|
178
316
|
|
|
317
|
+
// If there are no inner blocks then fallback to rendering an appropriate fallback.
|
|
179
318
|
if ( empty( $inner_blocks ) ) {
|
|
180
|
-
|
|
319
|
+
$is_fallback = true; // indicate we are rendering the fallback.
|
|
320
|
+
|
|
321
|
+
$fallback_blocks = block_core_navigation_get_fallback_blocks();
|
|
322
|
+
|
|
323
|
+
// Fallback my have been filtered so do basic test for validity.
|
|
324
|
+
if ( empty( $fallback_blocks ) || ! is_array( $fallback_blocks ) ) {
|
|
325
|
+
return '';
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
$inner_blocks = new WP_Block_List( $fallback_blocks, $attributes );
|
|
329
|
+
|
|
181
330
|
}
|
|
182
331
|
|
|
183
332
|
// Restore legacy classnames for submenu positioning.
|
|
@@ -196,7 +345,8 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
196
345
|
$colors['css_classes'],
|
|
197
346
|
$font_sizes['css_classes'],
|
|
198
347
|
$is_responsive_menu ? array( 'is-responsive' ) : array(),
|
|
199
|
-
$layout_class ? array( $layout_class ) : array()
|
|
348
|
+
$layout_class ? array( $layout_class ) : array(),
|
|
349
|
+
$is_fallback ? array( 'is-fallback' ) : array()
|
|
200
350
|
);
|
|
201
351
|
|
|
202
352
|
$inner_blocks_html = '';
|
|
@@ -247,6 +397,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
247
397
|
$responsive_container_classes = array(
|
|
248
398
|
'wp-block-navigation__responsive-container',
|
|
249
399
|
$is_hidden_by_default ? 'hidden-by-default' : '',
|
|
400
|
+
implode( ' ', $colors['overlay_css_classes'] ),
|
|
250
401
|
);
|
|
251
402
|
$open_button_classes = array(
|
|
252
403
|
'wp-block-navigation__responsive-container-open',
|
|
@@ -255,7 +406,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
255
406
|
|
|
256
407
|
$responsive_container_markup = sprintf(
|
|
257
408
|
'<button aria-expanded="false" aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger="modal-%1$s"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" 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></button>
|
|
258
|
-
<div class="%5$s" id="modal-%1$s">
|
|
409
|
+
<div class="%5$s" style="%7$s" id="modal-%1$s">
|
|
259
410
|
<div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close>
|
|
260
411
|
<div class="wp-block-navigation__responsive-dialog" role="dialog" aria-modal="true" aria-labelledby="modal-%1$s-title" >
|
|
261
412
|
<button aria-label="%4$s" data-micromodal-close class="wp-block-navigation__responsive-container-close"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" 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></button>
|
|
@@ -270,7 +421,8 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
270
421
|
__( 'Open menu' ), // Open button label.
|
|
271
422
|
__( 'Close menu' ), // Close button label.
|
|
272
423
|
implode( ' ', $responsive_container_classes ),
|
|
273
|
-
implode( ' ', $open_button_classes )
|
|
424
|
+
implode( ' ', $open_button_classes ),
|
|
425
|
+
$colors['overlay_inline_styles']
|
|
274
426
|
);
|
|
275
427
|
|
|
276
428
|
return sprintf(
|
|
@@ -283,8 +435,8 @@ function render_block_core_navigation( $attributes, $content, $block ) {
|
|
|
283
435
|
/**
|
|
284
436
|
* Register the navigation block.
|
|
285
437
|
*
|
|
286
|
-
* @uses render_block_core_navigation()
|
|
287
438
|
* @throws WP_Error An WP_Error exception parsing the block definition.
|
|
439
|
+
* @uses render_block_core_navigation()
|
|
288
440
|
*/
|
|
289
441
|
function register_block_core_navigation() {
|
|
290
442
|
register_block_type_from_metadata(
|
|
@@ -301,6 +453,7 @@ add_action( 'init', 'register_block_core_navigation' );
|
|
|
301
453
|
* Filter that changes the parsed attribute values of navigation blocks contain typographic presets to contain the values directly.
|
|
302
454
|
*
|
|
303
455
|
* @param array $parsed_block The block being rendered.
|
|
456
|
+
*
|
|
304
457
|
* @return array The block being rendered without typographic presets.
|
|
305
458
|
*/
|
|
306
459
|
function block_core_navigation_typographic_presets_backcompatibility( $parsed_block ) {
|
|
@@ -324,6 +477,7 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
|
|
|
324
477
|
}
|
|
325
478
|
}
|
|
326
479
|
}
|
|
480
|
+
|
|
327
481
|
return $parsed_block;
|
|
328
482
|
}
|
|
329
483
|
|
package/src/navigation/save.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { InnerBlocks } from '@wordpress/block-editor';
|
|
5
5
|
|
|
6
6
|
export default function save( { attributes } ) {
|
|
7
|
-
if ( attributes.
|
|
8
|
-
// Avoid rendering inner blocks when a
|
|
7
|
+
if ( attributes.ref ) {
|
|
8
|
+
// Avoid rendering inner blocks when a ref is defined.
|
|
9
9
|
// When this id is defined the inner blocks are loaded from the
|
|
10
10
|
// `wp_navigation` entity rather than the hard-coded block html.
|
|
11
11
|
return;
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
|
|
79
79
|
// Submenu indicator.
|
|
80
80
|
.wp-block-navigation__submenu-icon {
|
|
81
|
-
align-self: center;
|
|
82
|
-
height: inherit;
|
|
81
|
+
align-self: center; // This one affects nested submenu indicators.
|
|
83
82
|
line-height: 0;
|
|
84
|
-
|
|
83
|
+
display: inline-block;
|
|
84
|
+
vertical-align: middle;
|
|
85
85
|
|
|
86
86
|
// Affect the button as well.
|
|
87
87
|
padding: 0;
|
|
@@ -89,9 +89,16 @@
|
|
|
89
89
|
color: currentColor;
|
|
90
90
|
border: none;
|
|
91
91
|
|
|
92
|
+
// Scale to font size.
|
|
93
|
+
margin-left: 0.25em;
|
|
94
|
+
width: 0.6em;
|
|
95
|
+
height: 0.6em;
|
|
96
|
+
|
|
92
97
|
svg {
|
|
93
98
|
display: inline-block;
|
|
94
99
|
stroke: currentColor;
|
|
100
|
+
width: inherit;
|
|
101
|
+
height: inherit;
|
|
95
102
|
}
|
|
96
103
|
}
|
|
97
104
|
}
|
|
@@ -219,6 +226,36 @@
|
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
|
|
229
|
+
// General submenu colors.
|
|
230
|
+
// These styles are stored here as opposed to in the separate submenu block,
|
|
231
|
+
// so that they can affect both submenus and page lists with submenu items both.
|
|
232
|
+
.wp-block-navigation-submenu {
|
|
233
|
+
position: relative;
|
|
234
|
+
display: flex;
|
|
235
|
+
|
|
236
|
+
.wp-block-navigation__submenu-icon svg {
|
|
237
|
+
stroke: currentColor;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
button.wp-block-navigation-item__content {
|
|
242
|
+
background-color: transparent;
|
|
243
|
+
border: none;
|
|
244
|
+
color: currentColor;
|
|
245
|
+
font-size: inherit;
|
|
246
|
+
font-family: inherit;
|
|
247
|
+
line-height: inherit;
|
|
248
|
+
|
|
249
|
+
// Buttons default to center alignment. This becomes visible
|
|
250
|
+
// when a menu item label is long enough to wrap.
|
|
251
|
+
text-align: left;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.wp-block-navigation-submenu__toggle {
|
|
255
|
+
cursor: pointer;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
222
259
|
/**
|
|
223
260
|
* Margins
|
|
224
261
|
*/
|
|
@@ -325,6 +362,13 @@
|
|
|
325
362
|
}
|
|
326
363
|
}
|
|
327
364
|
|
|
365
|
+
// Allow menu items to be spaced out by space-between when only navigation links are present.
|
|
366
|
+
.wp-block-navigation__container:only-child,
|
|
367
|
+
.wp-block-page-list:only-child {
|
|
368
|
+
flex-grow: 1;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
|
|
328
372
|
/**
|
|
329
373
|
* Mobile menu.
|
|
330
374
|
*/
|
|
@@ -345,6 +389,13 @@
|
|
|
345
389
|
align-items: var(--layout-align, initial);
|
|
346
390
|
}
|
|
347
391
|
|
|
392
|
+
// If the responsive wrapper is present but overlay is not open,
|
|
393
|
+
// overlay styles shouldn't apply.
|
|
394
|
+
&:not(.is-menu-open.is-menu-open) {
|
|
395
|
+
color: inherit !important;
|
|
396
|
+
background-color: inherit !important;
|
|
397
|
+
}
|
|
398
|
+
|
|
348
399
|
// Overlay menu.
|
|
349
400
|
// Provide an opinionated default style for menu items inside.
|
|
350
401
|
// Inherit as much as we can regarding colors, fonts, sizes,
|
|
@@ -432,9 +483,9 @@
|
|
|
432
483
|
|
|
433
484
|
// Remove background colors for items inside the overlay menu.
|
|
434
485
|
// Has to be !important to override global styles.
|
|
435
|
-
// @todo: We should revisit this so that the overlay colors can be applied, instead of the background.
|
|
436
486
|
.wp-block-navigation-item .wp-block-navigation__submenu-container,
|
|
437
|
-
.wp-block-navigation-item
|
|
487
|
+
.wp-block-navigation-item,
|
|
488
|
+
.wp-block-page-list {
|
|
438
489
|
color: inherit !important;
|
|
439
490
|
background: transparent !important;
|
|
440
491
|
}
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
import { store as coreStore } from '@wordpress/core-data';
|
|
5
5
|
import { useSelect } from '@wordpress/data';
|
|
6
6
|
|
|
7
|
-
export default function useNavigationMenu(
|
|
7
|
+
export default function useNavigationMenu( ref ) {
|
|
8
8
|
return useSelect(
|
|
9
9
|
( select ) => {
|
|
10
10
|
const {
|
|
11
|
+
getEntityRecord,
|
|
11
12
|
getEditedEntityRecord,
|
|
12
13
|
getEntityRecords,
|
|
13
14
|
hasFinishedResolution,
|
|
@@ -16,12 +17,22 @@ export default function useNavigationMenu( navigationMenuId ) {
|
|
|
16
17
|
const navigationMenuSingleArgs = [
|
|
17
18
|
'postType',
|
|
18
19
|
'wp_navigation',
|
|
19
|
-
|
|
20
|
+
ref,
|
|
20
21
|
];
|
|
21
|
-
const
|
|
22
|
+
const rawNavigationMenu = ref
|
|
23
|
+
? getEntityRecord( ...navigationMenuSingleArgs )
|
|
24
|
+
: null;
|
|
25
|
+
let navigationMenu = ref
|
|
22
26
|
? getEditedEntityRecord( ...navigationMenuSingleArgs )
|
|
23
27
|
: null;
|
|
24
|
-
|
|
28
|
+
|
|
29
|
+
// getEditedEntityRecord will return the post regardless of status.
|
|
30
|
+
// Therefore if the found post is not published then we should ignore it.
|
|
31
|
+
if ( navigationMenu?.status !== 'publish' ) {
|
|
32
|
+
navigationMenu = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const hasResolvedNavigationMenu = ref
|
|
25
36
|
? hasFinishedResolution(
|
|
26
37
|
'getEditedEntityRecord',
|
|
27
38
|
navigationMenuSingleArgs
|
|
@@ -31,21 +42,21 @@ export default function useNavigationMenu( navigationMenuId ) {
|
|
|
31
42
|
const navigationMenuMultipleArgs = [
|
|
32
43
|
'postType',
|
|
33
44
|
'wp_navigation',
|
|
34
|
-
{ per_page: -1 },
|
|
45
|
+
{ per_page: -1, status: 'publish' },
|
|
35
46
|
];
|
|
36
47
|
const navigationMenus = getEntityRecords(
|
|
37
48
|
...navigationMenuMultipleArgs
|
|
38
49
|
);
|
|
39
50
|
|
|
40
|
-
const canSwitchNavigationMenu =
|
|
51
|
+
const canSwitchNavigationMenu = ref
|
|
41
52
|
? navigationMenus?.length > 1
|
|
42
53
|
: navigationMenus?.length > 0;
|
|
43
54
|
|
|
44
55
|
return {
|
|
45
56
|
isNavigationMenuResolved: hasResolvedNavigationMenu,
|
|
46
57
|
isNavigationMenuMissing:
|
|
47
|
-
!
|
|
48
|
-
( hasResolvedNavigationMenu && !
|
|
58
|
+
! ref ||
|
|
59
|
+
( hasResolvedNavigationMenu && ! rawNavigationMenu ),
|
|
49
60
|
canSwitchNavigationMenu,
|
|
50
61
|
hasResolvedNavigationMenus: hasFinishedResolution(
|
|
51
62
|
'getEntityRecords',
|
|
@@ -55,6 +66,6 @@ export default function useNavigationMenu( navigationMenuId ) {
|
|
|
55
66
|
navigationMenus,
|
|
56
67
|
};
|
|
57
68
|
},
|
|
58
|
-
[
|
|
69
|
+
[ ref ]
|
|
59
70
|
);
|
|
60
71
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { __, _x } from '@wordpress/i18n';
|
|
5
|
+
import deprecated from '@wordpress/deprecated';
|
|
5
6
|
import { store as coreStore } from '@wordpress/core-data';
|
|
6
7
|
import {
|
|
7
8
|
MenuGroup,
|
|
@@ -51,6 +52,10 @@ function NavigationAreaBlock( { attributes, setAttributes } ) {
|
|
|
51
52
|
[ navigationAreas ]
|
|
52
53
|
);
|
|
53
54
|
|
|
55
|
+
deprecated( 'wp.blockLibrary.NavigationArea', {
|
|
56
|
+
since: '5.9',
|
|
57
|
+
} );
|
|
58
|
+
|
|
54
59
|
return (
|
|
55
60
|
<>
|
|
56
61
|
<BlockControls>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Server-side rendering of the `core/navigation-submenu` block.
|
|
4
4
|
*
|
|
5
|
-
* @package
|
|
5
|
+
* @package WordPress
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -19,7 +19,7 @@ function block_core_navigation_submenu_build_css_colors( $context, $attributes )
|
|
|
19
19
|
'inline_styles' => '',
|
|
20
20
|
);
|
|
21
21
|
|
|
22
|
-
$is_sub_menu = isset( $attributes['
|
|
22
|
+
$is_sub_menu = isset( $attributes['isTopLevelItem'] ) ? ( ! $attributes['isTopLevelItem'] ) : false;
|
|
23
23
|
|
|
24
24
|
// Text color.
|
|
25
25
|
$named_text_color = null;
|
|
@@ -150,12 +150,6 @@ function render_block_core_navigation_submenu( $attributes, $content, $block ) {
|
|
|
150
150
|
$has_submenu = count( $block->inner_blocks ) > 0;
|
|
151
151
|
$is_active = ! empty( $attributes['id'] ) && ( get_the_ID() === $attributes['id'] );
|
|
152
152
|
|
|
153
|
-
$class_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false;
|
|
154
|
-
|
|
155
|
-
if ( false !== $class_name ) {
|
|
156
|
-
$css_classes .= ' ' . $class_name;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
153
|
$show_submenu_indicators = isset( $block->context['showSubmenuIcon'] ) && $block->context['showSubmenuIcon'];
|
|
160
154
|
$open_on_click = isset( $block->context['openSubmenusOnClick'] ) && $block->context['openSubmenusOnClick'];
|
|
161
155
|
$open_on_hover_and_click = isset( $block->context['openSubmenusOnClick'] ) && ! $block->context['openSubmenusOnClick'] &&
|
package/src/page-list/edit.js
CHANGED
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
} from '@wordpress/block-editor';
|
|
15
15
|
import { ToolbarButton, Placeholder, Spinner } from '@wordpress/components';
|
|
16
16
|
import { __ } from '@wordpress/i18n';
|
|
17
|
-
import {
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
17
|
+
import { useMemo, useState, memo } from '@wordpress/element';
|
|
18
|
+
import { useSelect } from '@wordpress/data';
|
|
19
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Internal dependencies
|
|
@@ -70,7 +70,7 @@ export default function PageListEdit( { context, clientId } ) {
|
|
|
70
70
|
clientId={ clientId }
|
|
71
71
|
/>
|
|
72
72
|
) }
|
|
73
|
-
{ totalPages ===
|
|
73
|
+
{ totalPages === undefined && (
|
|
74
74
|
<div { ...blockProps }>
|
|
75
75
|
<Placeholder>
|
|
76
76
|
<Spinner />
|
|
@@ -95,48 +95,39 @@ export default function PageListEdit( { context, clientId } ) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
function usePagesByParentId() {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
order: 'asc',
|
|
110
|
-
_fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ],
|
|
111
|
-
per_page: -1,
|
|
112
|
-
} ),
|
|
113
|
-
} );
|
|
114
|
-
|
|
115
|
-
// TODO: Once the REST API supports passing multiple values to
|
|
116
|
-
// 'orderby', this can be removed.
|
|
117
|
-
// https://core.trac.wordpress.org/ticket/39037
|
|
118
|
-
pages = sortBy( pages, [ 'menu_order', 'title.rendered' ] );
|
|
119
|
-
|
|
120
|
-
setPagesByParentId(
|
|
121
|
-
pages.reduce( ( accumulator, page ) => {
|
|
122
|
-
const { parent } = page;
|
|
123
|
-
if ( accumulator.has( parent ) ) {
|
|
124
|
-
accumulator.get( parent ).push( page );
|
|
125
|
-
} else {
|
|
126
|
-
accumulator.set( parent, [ page ] );
|
|
127
|
-
}
|
|
128
|
-
return accumulator;
|
|
129
|
-
}, new Map() )
|
|
130
|
-
);
|
|
131
|
-
setTotalPages( pages.length );
|
|
132
|
-
}
|
|
133
|
-
performFetch();
|
|
98
|
+
const { pages } = useSelect( ( select ) => {
|
|
99
|
+
const { getEntityRecords } = select( coreStore );
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
pages: getEntityRecords( 'postType', 'page', {
|
|
103
|
+
orderby: 'menu_order',
|
|
104
|
+
order: 'asc',
|
|
105
|
+
_fields: [ 'id', 'link', 'parent', 'title', 'menu_order' ],
|
|
106
|
+
per_page: -1,
|
|
107
|
+
} ),
|
|
108
|
+
};
|
|
134
109
|
}, [] );
|
|
135
110
|
|
|
136
|
-
return {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
return useMemo( () => {
|
|
112
|
+
// TODO: Once the REST API supports passing multiple values to
|
|
113
|
+
// 'orderby', this can be removed.
|
|
114
|
+
// https://core.trac.wordpress.org/ticket/39037
|
|
115
|
+
const sortedPages = sortBy( pages, [ 'menu_order', 'title.rendered' ] );
|
|
116
|
+
const pagesByParentId = sortedPages.reduce( ( accumulator, page ) => {
|
|
117
|
+
const { parent } = page;
|
|
118
|
+
if ( accumulator.has( parent ) ) {
|
|
119
|
+
accumulator.get( parent ).push( page );
|
|
120
|
+
} else {
|
|
121
|
+
accumulator.set( parent, [ page ] );
|
|
122
|
+
}
|
|
123
|
+
return accumulator;
|
|
124
|
+
}, new Map() );
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
pagesByParentId,
|
|
128
|
+
totalPages: pages?.length,
|
|
129
|
+
};
|
|
130
|
+
}, [ pages ] );
|
|
140
131
|
}
|
|
141
132
|
|
|
142
133
|
const PageItems = memo( function PageItems( {
|