@wordpress/block-library 8.22.0 → 8.24.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.
- package/CHANGELOG.md +4 -0
- package/build/block/edit.js +11 -13
- package/build/block/edit.js.map +1 -1
- package/build/block/edit.native.js +3 -4
- package/build/block/edit.native.js.map +1 -1
- package/build/button/edit.js +61 -9
- package/build/button/edit.js.map +1 -1
- package/build/code/transforms.js +20 -7
- package/build/code/transforms.js.map +1 -1
- package/build/column/edit.js +1 -1
- package/build/column/edit.js.map +1 -1
- package/build/column/edit.native.js +1 -1
- package/build/column/edit.native.js.map +1 -1
- package/build/comments/edit/comments-inspector-controls.js +1 -0
- package/build/comments/edit/comments-inspector-controls.js.map +1 -1
- package/build/cover/edit/index.js +2 -1
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +1 -0
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/details/edit.js +1 -2
- package/build/details/edit.js.map +1 -1
- package/build/file/edit.js +8 -9
- package/build/file/edit.js.map +1 -1
- package/build/file/view.js +4 -6
- package/build/file/view.js.map +1 -1
- package/build/form/index.js +1 -1
- package/build/form/index.js.map +1 -1
- package/build/form-submit-button/edit.js +2 -1
- package/build/form-submit-button/edit.js.map +1 -1
- package/build/gallery/gap-styles.js +12 -7
- package/build/gallery/gap-styles.js.map +1 -1
- package/build/group/edit.js +4 -7
- package/build/group/edit.js.map +1 -1
- package/build/html/transforms.js +7 -2
- package/build/html/transforms.js.map +1 -1
- package/build/image/deprecated.js +8 -0
- package/build/image/deprecated.js.map +1 -1
- package/build/image/edit.js +17 -18
- package/build/image/edit.js.map +1 -1
- package/build/image/edit.native.js +22 -15
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +35 -27
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +2 -3
- package/build/image/index.js.map +1 -1
- package/build/image/view.js +234 -266
- package/build/image/view.js.map +1 -1
- package/build/missing/index.js +1 -1
- package/build/navigation/edit/overlay-menu-preview.js +1 -1
- package/build/navigation/edit/overlay-menu-preview.js.map +1 -1
- package/build/navigation/use-template-part-area-label.js +2 -1
- package/build/navigation/use-template-part-area-label.js.map +1 -1
- package/build/navigation/view.js +153 -176
- package/build/navigation/view.js.map +1 -1
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/index.js +2 -1
- package/build/navigation-link/index.js.map +1 -1
- package/build/pattern/edit.js +2 -4
- package/build/pattern/edit.js.map +1 -1
- package/build/post-author/edit.js +0 -1
- package/build/post-author/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +21 -6
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-template/edit.js +2 -8
- package/build/post-template/edit.js.map +1 -1
- package/build/post-template/index.js +1 -1
- package/build/post-terms/edit.js +0 -2
- package/build/post-terms/edit.js.map +1 -1
- package/build/preformatted/transforms.js +1 -4
- package/build/preformatted/transforms.js.map +1 -1
- package/build/query/edit/query-content.js +1 -0
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/view.js +52 -60
- package/build/query/view.js.map +1 -1
- package/build/quote/index.js +6 -0
- package/build/quote/index.js.map +1 -1
- package/build/search/view.js +66 -74
- package/build/search/view.js.map +1 -1
- package/build/template-part/edit/advanced-controls.js +1 -0
- package/build/template-part/edit/advanced-controls.js.map +1 -1
- package/build/template-part/edit/index.js +3 -7
- package/build/template-part/edit/index.js.map +1 -1
- package/build/template-part/index.js +6 -2
- package/build/template-part/index.js.map +1 -1
- package/build/template-part/variations.js +5 -1
- package/build/template-part/variations.js.map +1 -1
- package/build/utils/remove-anchor-tag.js +17 -0
- package/build/utils/remove-anchor-tag.js.map +1 -0
- package/build-module/block/edit.js +11 -13
- package/build-module/block/edit.js.map +1 -1
- package/build-module/block/edit.native.js +3 -4
- package/build-module/block/edit.native.js.map +1 -1
- package/build-module/button/edit.js +65 -13
- package/build-module/button/edit.js.map +1 -1
- package/build-module/code/transforms.js +20 -7
- package/build-module/code/transforms.js.map +1 -1
- package/build-module/column/edit.js +1 -1
- package/build-module/column/edit.js.map +1 -1
- package/build-module/column/edit.native.js +1 -1
- package/build-module/column/edit.native.js.map +1 -1
- package/build-module/comments/edit/comments-inspector-controls.js +1 -0
- package/build-module/comments/edit/comments-inspector-controls.js.map +1 -1
- package/build-module/cover/edit/index.js +2 -1
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +1 -0
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/details/edit.js +1 -2
- package/build-module/details/edit.js.map +1 -1
- package/build-module/file/edit.js +8 -9
- package/build-module/file/edit.js.map +1 -1
- package/build-module/file/view.js +5 -7
- package/build-module/file/view.js.map +1 -1
- package/build-module/form/index.js +1 -1
- package/build-module/form/index.js.map +1 -1
- package/build-module/form-submit-button/edit.js +2 -1
- package/build-module/form-submit-button/edit.js.map +1 -1
- package/build-module/gallery/gap-styles.js +13 -8
- package/build-module/gallery/gap-styles.js.map +1 -1
- package/build-module/group/edit.js +4 -7
- package/build-module/group/edit.js.map +1 -1
- package/build-module/html/transforms.js +7 -2
- package/build-module/html/transforms.js.map +1 -1
- package/build-module/image/deprecated.js +8 -0
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/edit.js +18 -19
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/edit.native.js +23 -16
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +36 -28
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +2 -3
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/view.js +235 -267
- package/build-module/image/view.js.map +1 -1
- package/build-module/missing/index.js +1 -1
- package/build-module/navigation/edit/overlay-menu-preview.js +1 -1
- package/build-module/navigation/edit/overlay-menu-preview.js.map +1 -1
- package/build-module/navigation/use-template-part-area-label.js +2 -1
- package/build-module/navigation/use-template-part-area-label.js.map +1 -1
- package/build-module/navigation/view.js +154 -177
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/navigation-link/edit.js +2 -2
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/index.js +2 -1
- package/build-module/navigation-link/index.js.map +1 -1
- package/build-module/pattern/edit.js +2 -4
- package/build-module/pattern/edit.js.map +1 -1
- package/build-module/post-author/edit.js +0 -1
- package/build-module/post-author/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +21 -6
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-template/edit.js +2 -8
- package/build-module/post-template/edit.js.map +1 -1
- package/build-module/post-template/index.js +1 -1
- package/build-module/post-terms/edit.js +0 -2
- package/build-module/post-terms/edit.js.map +1 -1
- package/build-module/preformatted/transforms.js +1 -4
- package/build-module/preformatted/transforms.js.map +1 -1
- package/build-module/query/edit/query-content.js +1 -0
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/view.js +53 -61
- package/build-module/query/view.js.map +1 -1
- package/build-module/quote/index.js +6 -0
- package/build-module/quote/index.js.map +1 -1
- package/build-module/search/view.js +67 -75
- package/build-module/search/view.js.map +1 -1
- package/build-module/template-part/edit/advanced-controls.js +1 -0
- package/build-module/template-part/edit/advanced-controls.js.map +1 -1
- package/build-module/template-part/edit/index.js +5 -9
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/template-part/index.js +6 -2
- package/build-module/template-part/index.js.map +1 -1
- package/build-module/template-part/variations.js +5 -1
- package/build-module/template-part/variations.js.map +1 -1
- package/build-module/utils/remove-anchor-tag.js +11 -0
- package/build-module/utils/remove-anchor-tag.js.map +1 -0
- package/build-style/cover/style-rtl.css +14 -14
- package/build-style/cover/style.css +14 -14
- package/build-style/editor-rtl.css +15 -6
- package/build-style/editor.css +15 -6
- package/build-style/gallery/style-rtl.css +28 -0
- package/build-style/gallery/style.css +28 -0
- package/build-style/image/style-rtl.css +19 -13
- package/build-style/image/style.css +19 -13
- package/build-style/post-featured-image/editor-rtl.css +9 -0
- package/build-style/post-featured-image/editor.css +9 -0
- package/build-style/quote/style-rtl.css +3 -0
- package/build-style/quote/style.css +3 -0
- package/build-style/read-more/style-rtl.css +2 -2
- package/build-style/read-more/style.css +2 -2
- package/build-style/style-rtl.css +66 -29
- package/build-style/style.css +66 -29
- package/package.json +32 -32
- package/src/block/edit.js +20 -20
- package/src/block/edit.native.js +5 -13
- package/src/button/edit.js +76 -10
- package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
- package/src/buttons/test/edit.native.js +0 -27
- package/src/code/transforms.js +14 -8
- package/src/column/edit.js +1 -1
- package/src/column/edit.native.js +1 -1
- package/src/comments/edit/comments-inspector-controls.js +1 -0
- package/src/cover/edit/index.js +1 -0
- package/src/cover/edit/inspector-controls.js +1 -0
- package/src/cover/style.scss +1 -1
- package/src/cover/test/edit.js +1 -1
- package/src/details/edit.js +0 -1
- package/src/editor.scss +6 -6
- package/src/file/edit.js +11 -10
- package/src/file/index.php +30 -11
- package/src/file/view.js +5 -7
- package/src/form/index.js +1 -1
- package/src/form-submit-button/edit.js +1 -0
- package/src/gallery/gap-styles.js +10 -9
- package/src/gallery/style.scss +1 -0
- package/src/group/edit.js +4 -11
- package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
- package/src/heading/test/index.native.js +40 -0
- package/src/html/transforms.js +5 -2
- package/src/image/block.json +2 -3
- package/src/image/deprecated.js +8 -0
- package/src/image/edit.js +16 -21
- package/src/image/edit.native.js +17 -18
- package/src/image/image.js +48 -51
- package/src/image/index.php +57 -49
- package/src/image/style.scss +18 -13
- package/src/image/view.js +281 -324
- package/src/missing/block.json +1 -1
- package/src/navigation/edit/overlay-menu-preview.js +1 -1
- package/src/navigation/index.php +46 -402
- package/src/navigation/use-template-part-area-label.js +4 -2
- package/src/navigation/view.js +159 -192
- package/src/navigation-link/block.json +2 -1
- package/src/navigation-link/edit.js +2 -2
- package/src/navigation-link/index.php +57 -0
- package/src/paragraph/test/__snapshots__/transforms.native.js.snap +6 -0
- package/src/paragraph/test/edit.native.js +37 -1
- package/src/paragraph/test/transforms.native.js +1 -0
- package/src/pattern/edit.js +7 -4
- package/src/pattern/index.php +6 -1
- package/src/post-author/edit.js +0 -1
- package/src/post-featured-image/edit.js +38 -5
- package/src/post-featured-image/editor.scss +19 -0
- package/src/post-template/block.json +0 -1
- package/src/post-template/edit.js +1 -5
- package/src/post-terms/edit.js +0 -2
- package/src/preformatted/transforms.js +1 -4
- package/src/query/edit/query-content.js +1 -0
- package/src/query/index.php +42 -24
- package/src/query/view.js +58 -65
- package/src/query-pagination-next/index.php +3 -3
- package/src/query-pagination-numbers/index.php +1 -1
- package/src/query-pagination-previous/index.php +3 -3
- package/src/quote/block.json +6 -0
- package/src/quote/style.scss +4 -0
- package/src/read-more/style.scss +1 -1
- package/src/search/index.php +40 -40
- package/src/search/view.js +58 -63
- package/src/template-part/edit/advanced-controls.js +1 -0
- package/src/template-part/edit/index.js +7 -14
- package/src/template-part/index.js +4 -3
- package/src/template-part/index.php +4 -4
- package/src/template-part/variations.js +4 -2
- package/src/utils/remove-anchor-tag.js +10 -0
- package/tsconfig.json +1 -0
|
@@ -20,7 +20,7 @@ export default function OverlayMenuPreview( { setAttributes, hasIcon, icon } ) {
|
|
|
20
20
|
__nextHasNoMarginBottom
|
|
21
21
|
label={ __( 'Show icon button' ) }
|
|
22
22
|
help={ __(
|
|
23
|
-
'Configure the visual appearance of the button
|
|
23
|
+
'Configure the visual appearance of the button that toggles the overlay menu.'
|
|
24
24
|
) }
|
|
25
25
|
onChange={ ( value ) => setAttributes( { hasIcon: value } ) }
|
|
26
26
|
checked={ hasIcon }
|
package/src/navigation/index.php
CHANGED
|
@@ -65,68 +65,84 @@ if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
|
|
65
65
|
|
|
66
66
|
return $menu_items_by_parent_id;
|
|
67
67
|
}
|
|
68
|
-
}
|
|
69
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Gets the inner blocks for the navigation block from the unstable location attribute.
|
|
71
|
+
*
|
|
72
|
+
* @param array $attributes The block attributes.
|
|
73
|
+
* @return WP_Block_List Returns the inner blocks for the navigation block.
|
|
74
|
+
*/
|
|
75
|
+
function block_core_navigation_get_inner_blocks_from_unstable_location( $attributes ) {
|
|
76
|
+
$menu_items = block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] );
|
|
77
|
+
if ( empty( $menu_items ) ) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
$menu_items_by_parent_id = block_core_navigation_sort_menu_items_by_parent_id( $menu_items );
|
|
82
|
+
$parsed_blocks = block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id );
|
|
83
|
+
return new WP_Block_List( $parsed_blocks, $attributes );
|
|
84
|
+
}
|
|
85
|
+
}
|
|
70
86
|
|
|
71
87
|
/**
|
|
72
88
|
* Add Interactivity API directives to the navigation-submenu and page-list
|
|
73
89
|
* blocks markup using the Tag Processor.
|
|
74
90
|
*
|
|
75
|
-
* @param WP_HTML_Tag_Processor $
|
|
91
|
+
* @param WP_HTML_Tag_Processor $tags Markup of the navigation block.
|
|
76
92
|
* @param array $block_attributes Block attributes.
|
|
77
93
|
*
|
|
78
94
|
* @return string Submenu markup with the directives injected.
|
|
79
95
|
*/
|
|
80
|
-
function block_core_navigation_add_directives_to_submenu( $
|
|
81
|
-
while ( $
|
|
96
|
+
function block_core_navigation_add_directives_to_submenu( $tags, $block_attributes ) {
|
|
97
|
+
while ( $tags->next_tag(
|
|
82
98
|
array(
|
|
83
99
|
'tag_name' => 'LI',
|
|
84
100
|
'class_name' => 'has-child',
|
|
85
101
|
)
|
|
86
102
|
) ) {
|
|
87
103
|
// Add directives to the parent `<li>`.
|
|
88
|
-
$
|
|
89
|
-
$
|
|
90
|
-
$
|
|
91
|
-
$
|
|
92
|
-
$
|
|
104
|
+
$tags->set_attribute( 'data-wp-interactive', '{ "namespace": "core/navigation" }' );
|
|
105
|
+
$tags->set_attribute( 'data-wp-context', '{ "submenuOpenedBy": {}, "type": "submenu" }' );
|
|
106
|
+
$tags->set_attribute( 'data-wp-watch', 'callbacks.initMenu' );
|
|
107
|
+
$tags->set_attribute( 'data-wp-on--focusout', 'actions.handleMenuFocusout' );
|
|
108
|
+
$tags->set_attribute( 'data-wp-on--keydown', 'actions.handleMenuKeydown' );
|
|
93
109
|
|
|
94
110
|
// This is a fix for Safari. Without it, Safari doesn't change the active
|
|
95
111
|
// element when the user clicks on a button. It can be removed once we add
|
|
96
112
|
// an overlay to capture the clicks, instead of relying on the focusout
|
|
97
113
|
// event.
|
|
98
|
-
$
|
|
114
|
+
$tags->set_attribute( 'tabindex', '-1' );
|
|
99
115
|
|
|
100
116
|
if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
|
|
101
|
-
$
|
|
102
|
-
$
|
|
117
|
+
$tags->set_attribute( 'data-wp-on--mouseenter', 'actions.openMenuOnHover' );
|
|
118
|
+
$tags->set_attribute( 'data-wp-on--mouseleave', 'actions.closeMenuOnHover' );
|
|
103
119
|
}
|
|
104
120
|
|
|
105
121
|
// Add directives to the toggle submenu button.
|
|
106
|
-
if ( $
|
|
122
|
+
if ( $tags->next_tag(
|
|
107
123
|
array(
|
|
108
124
|
'tag_name' => 'BUTTON',
|
|
109
125
|
'class_name' => 'wp-block-navigation-submenu__toggle',
|
|
110
126
|
)
|
|
111
127
|
) ) {
|
|
112
|
-
$
|
|
113
|
-
$
|
|
128
|
+
$tags->set_attribute( 'data-wp-on--click', 'actions.toggleMenuOnClick' );
|
|
129
|
+
$tags->set_attribute( 'data-wp-bind--aria-expanded', 'state.isMenuOpen' );
|
|
114
130
|
// The `aria-expanded` attribute for SSR is already added in the submenu block.
|
|
115
131
|
}
|
|
116
132
|
// Add directives to the submenu.
|
|
117
|
-
if ( $
|
|
133
|
+
if ( $tags->next_tag(
|
|
118
134
|
array(
|
|
119
135
|
'tag_name' => 'UL',
|
|
120
136
|
'class_name' => 'wp-block-navigation__submenu-container',
|
|
121
137
|
)
|
|
122
138
|
) ) {
|
|
123
|
-
$
|
|
139
|
+
$tags->set_attribute( 'data-wp-on--focus', 'actions.openMenuOnFocus' );
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
// Iterate through subitems if exist.
|
|
127
|
-
block_core_navigation_add_directives_to_submenu( $
|
|
143
|
+
block_core_navigation_add_directives_to_submenu( $tags, $block_attributes );
|
|
128
144
|
}
|
|
129
|
-
return $
|
|
145
|
+
return $tags->get_updated_html();
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
/**
|
|
@@ -391,391 +407,10 @@ function block_core_navigation_from_block_get_post_ids( $block ) {
|
|
|
391
407
|
* @param string $content The saved content.
|
|
392
408
|
* @param WP_Block $block The parsed block.
|
|
393
409
|
*
|
|
394
|
-
* @return string Returns the
|
|
410
|
+
* @return string Returns the navigation block markup.
|
|
395
411
|
*/
|
|
396
412
|
function render_block_core_navigation( $attributes, $content, $block ) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
// Flag used to indicate whether the rendered output is considered to be
|
|
400
|
-
// a fallback (i.e. the block has no menu associated with it).
|
|
401
|
-
$is_fallback = false;
|
|
402
|
-
|
|
403
|
-
$nav_menu_name = $attributes['ariaLabel'] ?? '';
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Deprecated:
|
|
407
|
-
* The rgbTextColor and rgbBackgroundColor attributes
|
|
408
|
-
* have been deprecated in favor of
|
|
409
|
-
* customTextColor and customBackgroundColor ones.
|
|
410
|
-
* Move the values from old attrs to the new ones.
|
|
411
|
-
*/
|
|
412
|
-
if ( isset( $attributes['rgbTextColor'] ) && empty( $attributes['textColor'] ) ) {
|
|
413
|
-
$attributes['customTextColor'] = $attributes['rgbTextColor'];
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if ( isset( $attributes['rgbBackgroundColor'] ) && empty( $attributes['backgroundColor'] ) ) {
|
|
417
|
-
$attributes['customBackgroundColor'] = $attributes['rgbBackgroundColor'];
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
unset( $attributes['rgbTextColor'], $attributes['rgbBackgroundColor'] );
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* This is for backwards compatibility after `isResponsive` attribute has been removed.
|
|
424
|
-
*/
|
|
425
|
-
$has_old_responsive_attribute = ! empty( $attributes['isResponsive'] ) && $attributes['isResponsive'];
|
|
426
|
-
$is_responsive_menu = isset( $attributes['overlayMenu'] ) && 'never' !== $attributes['overlayMenu'] || $has_old_responsive_attribute;
|
|
427
|
-
|
|
428
|
-
$inner_blocks = $block->inner_blocks;
|
|
429
|
-
|
|
430
|
-
// Ensure that blocks saved with the legacy ref attribute name (navigationMenuId) continue to render.
|
|
431
|
-
if ( array_key_exists( 'navigationMenuId', $attributes ) ) {
|
|
432
|
-
$attributes['ref'] = $attributes['navigationMenuId'];
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// If:
|
|
436
|
-
// - the gutenberg plugin is active
|
|
437
|
-
// - `__unstableLocation` is defined
|
|
438
|
-
// - we have menu items at the defined location
|
|
439
|
-
// - we don't have a relationship to a `wp_navigation` Post (via `ref`).
|
|
440
|
-
// ...then create inner blocks from the classic menu assigned to that location.
|
|
441
|
-
if (
|
|
442
|
-
defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN &&
|
|
443
|
-
array_key_exists( '__unstableLocation', $attributes ) &&
|
|
444
|
-
! array_key_exists( 'ref', $attributes ) &&
|
|
445
|
-
! empty( block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
|
|
446
|
-
) {
|
|
447
|
-
$menu_items = block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] );
|
|
448
|
-
if ( empty( $menu_items ) ) {
|
|
449
|
-
return '';
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
$menu_items_by_parent_id = block_core_navigation_sort_menu_items_by_parent_id( $menu_items );
|
|
453
|
-
$parsed_blocks = block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id );
|
|
454
|
-
$inner_blocks = new WP_Block_List( $parsed_blocks, $attributes );
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
// Load inner blocks from the navigation post.
|
|
458
|
-
if ( array_key_exists( 'ref', $attributes ) ) {
|
|
459
|
-
$navigation_post = get_post( $attributes['ref'] );
|
|
460
|
-
if ( ! isset( $navigation_post ) ) {
|
|
461
|
-
return '';
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// Only published posts are valid. If this is changed then a corresponding change
|
|
465
|
-
// must also be implemented in `use-navigation-menu.js`.
|
|
466
|
-
if ( 'publish' === $navigation_post->post_status ) {
|
|
467
|
-
$nav_menu_name = $navigation_post->post_title;
|
|
468
|
-
|
|
469
|
-
if ( isset( $seen_menu_names[ $nav_menu_name ] ) ) {
|
|
470
|
-
++$seen_menu_names[ $nav_menu_name ];
|
|
471
|
-
} else {
|
|
472
|
-
$seen_menu_names[ $nav_menu_name ] = 1;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
$parsed_blocks = parse_blocks( $navigation_post->post_content );
|
|
476
|
-
|
|
477
|
-
// 'parse_blocks' includes a null block with '\n\n' as the content when
|
|
478
|
-
// it encounters whitespace. This code strips it.
|
|
479
|
-
$compacted_blocks = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );
|
|
480
|
-
|
|
481
|
-
// TODO - this uses the full navigation block attributes for the
|
|
482
|
-
// context which could be refined.
|
|
483
|
-
$inner_blocks = new WP_Block_List( $compacted_blocks, $attributes );
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// If there are no inner blocks then fallback to rendering an appropriate fallback.
|
|
488
|
-
if ( empty( $inner_blocks ) ) {
|
|
489
|
-
$is_fallback = true; // indicate we are rendering the fallback.
|
|
490
|
-
|
|
491
|
-
$fallback_blocks = block_core_navigation_get_fallback_blocks();
|
|
492
|
-
|
|
493
|
-
// Fallback my have been filtered so do basic test for validity.
|
|
494
|
-
if ( empty( $fallback_blocks ) || ! is_array( $fallback_blocks ) ) {
|
|
495
|
-
return '';
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
$inner_blocks = new WP_Block_List( $fallback_blocks, $attributes );
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
if ( block_core_navigation_block_contains_core_navigation( $inner_blocks ) ) {
|
|
502
|
-
return '';
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Filter navigation block $inner_blocks.
|
|
507
|
-
* Allows modification of a navigation block menu items.
|
|
508
|
-
*
|
|
509
|
-
* @since 6.1.0
|
|
510
|
-
*
|
|
511
|
-
* @param \WP_Block_List $inner_blocks
|
|
512
|
-
*/
|
|
513
|
-
$inner_blocks = apply_filters( 'block_core_navigation_render_inner_blocks', $inner_blocks );
|
|
514
|
-
|
|
515
|
-
$layout_justification = array(
|
|
516
|
-
'left' => 'items-justified-left',
|
|
517
|
-
'right' => 'items-justified-right',
|
|
518
|
-
'center' => 'items-justified-center',
|
|
519
|
-
'space-between' => 'items-justified-space-between',
|
|
520
|
-
);
|
|
521
|
-
|
|
522
|
-
// Restore legacy classnames for submenu positioning.
|
|
523
|
-
$layout_class = '';
|
|
524
|
-
if (
|
|
525
|
-
isset( $attributes['layout']['justifyContent'] ) &&
|
|
526
|
-
isset( $layout_justification[ $attributes['layout']['justifyContent'] ] )
|
|
527
|
-
) {
|
|
528
|
-
$layout_class .= $layout_justification[ $attributes['layout']['justifyContent'] ];
|
|
529
|
-
}
|
|
530
|
-
if ( isset( $attributes['layout']['orientation'] ) && 'vertical' === $attributes['layout']['orientation'] ) {
|
|
531
|
-
$layout_class .= ' is-vertical';
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
if ( isset( $attributes['layout']['flexWrap'] ) && 'nowrap' === $attributes['layout']['flexWrap'] ) {
|
|
535
|
-
$layout_class .= ' no-wrap';
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// Manually add block support text decoration as CSS class.
|
|
539
|
-
$text_decoration = $attributes['style']['typography']['textDecoration'] ?? null;
|
|
540
|
-
$text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration );
|
|
541
|
-
|
|
542
|
-
$colors = block_core_navigation_build_css_colors( $attributes );
|
|
543
|
-
$font_sizes = block_core_navigation_build_css_font_sizes( $attributes );
|
|
544
|
-
$classes = array_merge(
|
|
545
|
-
$colors['css_classes'],
|
|
546
|
-
$font_sizes['css_classes'],
|
|
547
|
-
$is_responsive_menu ? array( 'is-responsive' ) : array(),
|
|
548
|
-
$layout_class ? array( $layout_class ) : array(),
|
|
549
|
-
$is_fallback ? array( 'is-fallback' ) : array(),
|
|
550
|
-
$text_decoration ? array( $text_decoration_class ) : array()
|
|
551
|
-
);
|
|
552
|
-
|
|
553
|
-
$post_ids = block_core_navigation_get_post_ids( $inner_blocks );
|
|
554
|
-
if ( $post_ids ) {
|
|
555
|
-
_prime_post_caches( $post_ids, false, false );
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
$list_item_nav_blocks = array(
|
|
559
|
-
'core/navigation-link',
|
|
560
|
-
'core/home-link',
|
|
561
|
-
'core/site-title',
|
|
562
|
-
'core/site-logo',
|
|
563
|
-
'core/navigation-submenu',
|
|
564
|
-
);
|
|
565
|
-
|
|
566
|
-
$needs_list_item_wrapper = array(
|
|
567
|
-
'core/site-title',
|
|
568
|
-
'core/site-logo',
|
|
569
|
-
);
|
|
570
|
-
|
|
571
|
-
$block_styles = isset( $attributes['styles'] ) ? $attributes['styles'] : '';
|
|
572
|
-
$style = $block_styles . $colors['inline_styles'] . $font_sizes['inline_styles'];
|
|
573
|
-
$class = implode( ' ', $classes );
|
|
574
|
-
|
|
575
|
-
// If the menu name has been used previously then append an ID
|
|
576
|
-
// to the name to ensure uniqueness across a given post.
|
|
577
|
-
if ( isset( $seen_menu_names[ $nav_menu_name ] ) && $seen_menu_names[ $nav_menu_name ] > 1 ) {
|
|
578
|
-
$count = $seen_menu_names[ $nav_menu_name ];
|
|
579
|
-
$nav_menu_name = $nav_menu_name . ' ' . ( $count );
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
$wrapper_attributes = get_block_wrapper_attributes(
|
|
583
|
-
array(
|
|
584
|
-
'class' => $class,
|
|
585
|
-
'style' => $style,
|
|
586
|
-
'aria-label' => $nav_menu_name,
|
|
587
|
-
)
|
|
588
|
-
);
|
|
589
|
-
|
|
590
|
-
$container_attributes = get_block_wrapper_attributes(
|
|
591
|
-
array(
|
|
592
|
-
'class' => 'wp-block-navigation__container ' . $class,
|
|
593
|
-
'style' => $style,
|
|
594
|
-
)
|
|
595
|
-
);
|
|
596
|
-
|
|
597
|
-
$inner_blocks_html = '';
|
|
598
|
-
$is_list_open = false;
|
|
599
|
-
$has_submenus = false;
|
|
600
|
-
foreach ( $inner_blocks as $inner_block ) {
|
|
601
|
-
$is_list_item = in_array( $inner_block->name, $list_item_nav_blocks, true );
|
|
602
|
-
|
|
603
|
-
if ( $is_list_item && ! $is_list_open ) {
|
|
604
|
-
$is_list_open = true;
|
|
605
|
-
$inner_blocks_html .= sprintf(
|
|
606
|
-
'<ul %1$s>',
|
|
607
|
-
$container_attributes
|
|
608
|
-
);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
if ( ! $is_list_item && $is_list_open ) {
|
|
612
|
-
$is_list_open = false;
|
|
613
|
-
$inner_blocks_html .= '</ul>';
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
$inner_block_content = $inner_block->render();
|
|
617
|
-
$p = new WP_HTML_Tag_Processor( $inner_block_content );
|
|
618
|
-
if ( $p->next_tag(
|
|
619
|
-
array(
|
|
620
|
-
'name' => 'LI',
|
|
621
|
-
'class_name' => 'has-child',
|
|
622
|
-
)
|
|
623
|
-
) ) {
|
|
624
|
-
$has_submenus = true;
|
|
625
|
-
}
|
|
626
|
-
if ( ! empty( $inner_block_content ) ) {
|
|
627
|
-
if ( in_array( $inner_block->name, $needs_list_item_wrapper, true ) ) {
|
|
628
|
-
$inner_blocks_html .= '<li class="wp-block-navigation-item">' . $inner_block_content . '</li>';
|
|
629
|
-
} else {
|
|
630
|
-
$inner_blocks_html .= $inner_block_content;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
if ( $is_list_open ) {
|
|
636
|
-
$inner_blocks_html .= '</ul>';
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
$should_load_view_script = ( $has_submenus && ( $attributes['openSubmenusOnClick'] || $attributes['showSubmenuIcon'] ) ) || $is_responsive_menu;
|
|
640
|
-
$view_js_file = 'wp-block-navigation-view';
|
|
641
|
-
|
|
642
|
-
// If the script already exists, there is no point in removing it from viewScript.
|
|
643
|
-
if ( ! wp_script_is( $view_js_file ) ) {
|
|
644
|
-
$script_handles = $block->block_type->view_script_handles;
|
|
645
|
-
|
|
646
|
-
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
647
|
-
if ( ! $should_load_view_script && in_array( $view_js_file, $script_handles, true ) ) {
|
|
648
|
-
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
|
649
|
-
}
|
|
650
|
-
// If the script is needed, but it was previously removed, add it again.
|
|
651
|
-
if ( $should_load_view_script && ! in_array( $view_js_file, $script_handles, true ) ) {
|
|
652
|
-
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
// Add directives to the submenu if needed.
|
|
657
|
-
if ( $has_submenus && $should_load_view_script ) {
|
|
658
|
-
$w = new WP_HTML_Tag_Processor( $inner_blocks_html );
|
|
659
|
-
$inner_blocks_html = block_core_navigation_add_directives_to_submenu( $w, $attributes );
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
$modal_unique_id = wp_unique_id( 'modal-' );
|
|
663
|
-
|
|
664
|
-
// Determine whether or not navigation elements should be wrapped in the markup required to make it responsive,
|
|
665
|
-
// return early if they don't.
|
|
666
|
-
if ( ! $is_responsive_menu ) {
|
|
667
|
-
return sprintf(
|
|
668
|
-
'<nav %1$s>%2$s</nav>',
|
|
669
|
-
$wrapper_attributes,
|
|
670
|
-
$inner_blocks_html
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
$is_hidden_by_default = isset( $attributes['overlayMenu'] ) && 'always' === $attributes['overlayMenu'];
|
|
675
|
-
|
|
676
|
-
$responsive_container_classes = array(
|
|
677
|
-
'wp-block-navigation__responsive-container',
|
|
678
|
-
$is_hidden_by_default ? 'hidden-by-default' : '',
|
|
679
|
-
implode( ' ', $colors['overlay_css_classes'] ),
|
|
680
|
-
);
|
|
681
|
-
$open_button_classes = array(
|
|
682
|
-
'wp-block-navigation__responsive-container-open',
|
|
683
|
-
$is_hidden_by_default ? 'always-shown' : '',
|
|
684
|
-
);
|
|
685
|
-
|
|
686
|
-
$should_display_icon_label = isset( $attributes['hasIcon'] ) && true === $attributes['hasIcon'];
|
|
687
|
-
$toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" 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>';
|
|
688
|
-
if ( isset( $attributes['icon'] ) ) {
|
|
689
|
-
if ( 'menu' === $attributes['icon'] ) {
|
|
690
|
-
$toggle_button_icon = '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 5v1.5h14V5H5zm0 7.8h14v-1.5H5v1.5zM5 19h14v-1.5H5V19z" /></svg>';
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
$toggle_button_content = $should_display_icon_label ? $toggle_button_icon : __( 'Menu' );
|
|
694
|
-
$toggle_close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" 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>';
|
|
695
|
-
$toggle_close_button_content = $should_display_icon_label ? $toggle_close_button_icon : __( 'Close' );
|
|
696
|
-
$toggle_aria_label_open = $should_display_icon_label ? 'aria-label="' . __( 'Open menu' ) . '"' : ''; // Open button label.
|
|
697
|
-
$toggle_aria_label_close = $should_display_icon_label ? 'aria-label="' . __( 'Close menu' ) . '"' : ''; // Close button label.
|
|
698
|
-
|
|
699
|
-
// Add Interactivity API directives to the markup if needed.
|
|
700
|
-
$nav_element_directives = '';
|
|
701
|
-
$open_button_directives = '';
|
|
702
|
-
$responsive_container_directives = '';
|
|
703
|
-
$responsive_dialog_directives = '';
|
|
704
|
-
$close_button_directives = '';
|
|
705
|
-
if ( $should_load_view_script ) {
|
|
706
|
-
$nav_element_context = wp_json_encode(
|
|
707
|
-
array(
|
|
708
|
-
'core' => array(
|
|
709
|
-
'navigation' => array(
|
|
710
|
-
'overlayOpenedBy' => array(),
|
|
711
|
-
'type' => 'overlay',
|
|
712
|
-
'roleAttribute' => '',
|
|
713
|
-
'ariaLabel' => __( 'Menu' ),
|
|
714
|
-
),
|
|
715
|
-
),
|
|
716
|
-
),
|
|
717
|
-
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP
|
|
718
|
-
);
|
|
719
|
-
$nav_element_directives = '
|
|
720
|
-
data-wp-interactive
|
|
721
|
-
data-wp-context=\'' . $nav_element_context . '\'
|
|
722
|
-
';
|
|
723
|
-
$open_button_directives = '
|
|
724
|
-
data-wp-on--click="actions.core.navigation.openMenuOnClick"
|
|
725
|
-
data-wp-on--keydown="actions.core.navigation.handleMenuKeydown"
|
|
726
|
-
';
|
|
727
|
-
$responsive_container_directives = '
|
|
728
|
-
data-wp-class--has-modal-open="selectors.core.navigation.isMenuOpen"
|
|
729
|
-
data-wp-class--is-menu-open="selectors.core.navigation.isMenuOpen"
|
|
730
|
-
data-wp-effect="effects.core.navigation.initMenu"
|
|
731
|
-
data-wp-on--keydown="actions.core.navigation.handleMenuKeydown"
|
|
732
|
-
data-wp-on--focusout="actions.core.navigation.handleMenuFocusout"
|
|
733
|
-
tabindex="-1"
|
|
734
|
-
';
|
|
735
|
-
$responsive_dialog_directives = '
|
|
736
|
-
data-wp-bind--aria-modal="selectors.core.navigation.ariaModal"
|
|
737
|
-
data-wp-bind--aria-label="selectors.core.navigation.ariaLabel"
|
|
738
|
-
data-wp-bind--role="selectors.core.navigation.roleAttribute"
|
|
739
|
-
data-wp-effect="effects.core.navigation.focusFirstElement"
|
|
740
|
-
';
|
|
741
|
-
$close_button_directives = '
|
|
742
|
-
data-wp-on--click="actions.core.navigation.closeMenuOnClick"
|
|
743
|
-
';
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
$responsive_container_markup = sprintf(
|
|
747
|
-
'<button aria-haspopup="dialog" %3$s class="%6$s" %10$s>%8$s</button>
|
|
748
|
-
<div class="%5$s" style="%7$s" id="%1$s" %11$s>
|
|
749
|
-
<div class="wp-block-navigation__responsive-close" tabindex="-1">
|
|
750
|
-
<div class="wp-block-navigation__responsive-dialog" %12$s>
|
|
751
|
-
<button %4$s class="wp-block-navigation__responsive-container-close" %13$s>%9$s</button>
|
|
752
|
-
<div class="wp-block-navigation__responsive-container-content" id="%1$s-content">
|
|
753
|
-
%2$s
|
|
754
|
-
</div>
|
|
755
|
-
</div>
|
|
756
|
-
</div>
|
|
757
|
-
</div>',
|
|
758
|
-
esc_attr( $modal_unique_id ),
|
|
759
|
-
$inner_blocks_html,
|
|
760
|
-
$toggle_aria_label_open,
|
|
761
|
-
$toggle_aria_label_close,
|
|
762
|
-
esc_attr( implode( ' ', $responsive_container_classes ) ),
|
|
763
|
-
esc_attr( implode( ' ', $open_button_classes ) ),
|
|
764
|
-
esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) ),
|
|
765
|
-
$toggle_button_content,
|
|
766
|
-
$toggle_close_button_content,
|
|
767
|
-
$open_button_directives,
|
|
768
|
-
$responsive_container_directives,
|
|
769
|
-
$responsive_dialog_directives,
|
|
770
|
-
$close_button_directives
|
|
771
|
-
);
|
|
772
|
-
|
|
773
|
-
return sprintf(
|
|
774
|
-
'<nav %1$s %3$s>%2$s</nav>',
|
|
775
|
-
$wrapper_attributes,
|
|
776
|
-
$responsive_container_markup,
|
|
777
|
-
$nav_element_directives
|
|
778
|
-
);
|
|
413
|
+
return WP_Navigation_Block_Renderer::render( $attributes, $content, $block );
|
|
779
414
|
}
|
|
780
415
|
|
|
781
416
|
/**
|
|
@@ -791,6 +426,15 @@ function register_block_core_navigation() {
|
|
|
791
426
|
'render_callback' => 'render_block_core_navigation',
|
|
792
427
|
)
|
|
793
428
|
);
|
|
429
|
+
|
|
430
|
+
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
|
431
|
+
gutenberg_register_module(
|
|
432
|
+
'@wordpress/block-library/navigation-block',
|
|
433
|
+
gutenberg_url( '/build/interactivity/navigation.min.js' ),
|
|
434
|
+
array( '@wordpress/interactivity' ),
|
|
435
|
+
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
|
|
436
|
+
);
|
|
437
|
+
}
|
|
794
438
|
}
|
|
795
439
|
|
|
796
440
|
add_action( 'init', 'register_block_core_navigation' );
|
|
@@ -45,14 +45,16 @@ export default function useTemplatePartAreaLabel( clientId ) {
|
|
|
45
45
|
'core/editor'
|
|
46
46
|
).__experimentalGetDefaultTemplatePartAreas();
|
|
47
47
|
/* eslint-enable @wordpress/data-no-store-string-literals */
|
|
48
|
-
const { getEditedEntityRecord } =
|
|
48
|
+
const { getCurrentTheme, getEditedEntityRecord } =
|
|
49
|
+
select( coreStore );
|
|
49
50
|
|
|
50
51
|
for ( const templatePartClientId of parentTemplatePartClientIds ) {
|
|
51
52
|
const templatePartBlock = getBlock( templatePartClientId );
|
|
52
53
|
|
|
53
54
|
// The 'area' usually isn't stored on the block, but instead
|
|
54
55
|
// on the entity.
|
|
55
|
-
const { theme, slug } =
|
|
56
|
+
const { theme = getCurrentTheme()?.stylesheet, slug } =
|
|
57
|
+
templatePartBlock.attributes;
|
|
56
58
|
const templatePartEntityId = createTemplatePartId(
|
|
57
59
|
theme,
|
|
58
60
|
slug
|