@wordpress/block-library 9.33.2-next.36001005c.0 → 9.34.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 +2 -0
- package/build/accordion/block.json +1 -1
- package/build/accordion/edit.js +11 -9
- package/build/accordion/edit.js.map +2 -2
- package/build/accordion-heading/block.json +1 -1
- package/build/accordion-item/block.json +2 -2
- package/build/accordion-panel/block.json +1 -1
- package/build/breadcrumbs/block.json +3 -4
- package/build/breadcrumbs/edit.js +43 -77
- package/build/breadcrumbs/edit.js.map +2 -2
- package/build/buttons/transforms.js +1 -0
- package/build/buttons/transforms.js.map +2 -2
- package/build/categories/edit.js +8 -4
- package/build/categories/edit.js.map +2 -2
- package/build/code/transforms.js +2 -0
- package/build/code/transforms.js.map +2 -2
- package/build/home-link/block.json +2 -1
- package/build/image/view.js +4 -1
- package/build/image/view.js.map +2 -2
- package/build/latest-comments/block.json +4 -3
- package/build/latest-comments/deprecated.js +56 -0
- package/build/latest-comments/deprecated.js.map +7 -0
- package/build/latest-comments/edit.js +16 -10
- package/build/latest-comments/edit.js.map +2 -2
- package/build/latest-comments/index.js +3 -1
- package/build/latest-comments/index.js.map +3 -3
- package/build/math/deprecated.js +54 -0
- package/build/math/deprecated.js.map +7 -0
- package/build/math/edit.js +1 -0
- package/build/math/edit.js.map +2 -2
- package/build/math/index.js +3 -1
- package/build/math/index.js.map +3 -3
- package/build/math/save.js +2 -3
- package/build/math/save.js.map +2 -2
- package/build/navigation/menu-items-to-blocks.js +8 -3
- package/build/navigation/menu-items-to-blocks.js.map +2 -2
- package/build/navigation/view.js +2 -2
- package/build/navigation/view.js.map +2 -2
- package/build/navigation-link/link-ui/page-creator.js +20 -0
- package/build/navigation-link/link-ui/page-creator.js.map +3 -3
- package/build/post-date/block.json +1 -1
- package/build/post-date/edit.js +11 -5
- package/build/post-date/edit.js.map +3 -3
- package/build/post-date/variations.js +4 -7
- package/build/post-date/variations.js.map +2 -2
- package/build/post-template/edit.js +13 -1
- package/build/post-template/edit.js.map +2 -2
- package/build/query/index.js +11 -1
- package/build/query/index.js.map +2 -2
- package/build/query/variations.js +16 -11
- package/build/query/variations.js.map +2 -2
- package/build/search/view.js +4 -4
- package/build/search/view.js.map +2 -2
- package/build/terms-query/edit/inspector-controls/index.js +1 -1
- package/build/terms-query/edit/inspector-controls/index.js.map +2 -2
- package/build/terms-query/edit/inspector-controls/inherit-control.js +2 -4
- package/build/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
- package/build/utils/get-transformed-attributes.js +1 -10
- package/build/utils/get-transformed-attributes.js.map +2 -2
- package/build-module/accordion/block.json +1 -1
- package/build-module/accordion/edit.js +11 -9
- package/build-module/accordion/edit.js.map +2 -2
- package/build-module/accordion-heading/block.json +1 -1
- package/build-module/accordion-item/block.json +2 -2
- package/build-module/accordion-panel/block.json +1 -1
- package/build-module/breadcrumbs/block.json +3 -4
- package/build-module/breadcrumbs/edit.js +44 -78
- package/build-module/breadcrumbs/edit.js.map +2 -2
- package/build-module/buttons/transforms.js +1 -0
- package/build-module/buttons/transforms.js.map +2 -2
- package/build-module/categories/edit.js +8 -4
- package/build-module/categories/edit.js.map +2 -2
- package/build-module/code/transforms.js +2 -0
- package/build-module/code/transforms.js.map +2 -2
- package/build-module/home-link/block.json +2 -1
- package/build-module/image/view.js +4 -1
- package/build-module/image/view.js.map +2 -2
- package/build-module/latest-comments/block.json +4 -3
- package/build-module/latest-comments/deprecated.js +36 -0
- package/build-module/latest-comments/deprecated.js.map +7 -0
- package/build-module/latest-comments/edit.js +17 -10
- package/build-module/latest-comments/edit.js.map +2 -2
- package/build-module/latest-comments/index.js +3 -1
- package/build-module/latest-comments/index.js.map +2 -2
- package/build-module/math/deprecated.js +34 -0
- package/build-module/math/deprecated.js.map +7 -0
- package/build-module/math/edit.js +1 -0
- package/build-module/math/edit.js.map +2 -2
- package/build-module/math/index.js +3 -1
- package/build-module/math/index.js.map +2 -2
- package/build-module/math/save.js +2 -3
- package/build-module/math/save.js.map +2 -2
- package/build-module/navigation/menu-items-to-blocks.js +8 -3
- package/build-module/navigation/menu-items-to-blocks.js.map +2 -2
- package/build-module/navigation/view.js +2 -2
- package/build-module/navigation/view.js.map +2 -2
- package/build-module/navigation-link/link-ui/page-creator.js +21 -1
- package/build-module/navigation-link/link-ui/page-creator.js.map +2 -2
- package/build-module/post-date/block.json +1 -1
- package/build-module/post-date/edit.js +11 -5
- package/build-module/post-date/edit.js.map +2 -2
- package/build-module/post-date/variations.js +4 -7
- package/build-module/post-date/variations.js.map +2 -2
- package/build-module/post-template/edit.js +13 -1
- package/build-module/post-template/edit.js.map +2 -2
- package/build-module/query/index.js +11 -1
- package/build-module/query/index.js.map +2 -2
- package/build-module/query/variations.js +16 -11
- package/build-module/query/variations.js.map +2 -2
- package/build-module/search/view.js +4 -4
- package/build-module/search/view.js.map +2 -2
- package/build-module/terms-query/edit/inspector-controls/index.js +1 -1
- package/build-module/terms-query/edit/inspector-controls/index.js.map +2 -2
- package/build-module/terms-query/edit/inspector-controls/inherit-control.js +2 -4
- package/build-module/terms-query/edit/inspector-controls/inherit-control.js.map +2 -2
- package/build-module/utils/get-transformed-attributes.js +1 -10
- package/build-module/utils/get-transformed-attributes.js.map +2 -2
- package/build-style/editor-rtl.css +5 -0
- package/build-style/editor.css +6 -0
- package/build-style/math/editor-rtl.css +49 -0
- package/build-style/math/editor.css +50 -0
- package/build-style/math/style-rtl.css +4 -0
- package/build-style/math/style.css +4 -0
- package/build-style/style-rtl.css +5 -0
- package/build-style/style.css +5 -0
- package/package.json +37 -37
- package/src/accordion/block.json +1 -1
- package/src/accordion/edit.js +16 -16
- package/src/accordion-heading/block.json +1 -1
- package/src/accordion-item/block.json +2 -2
- package/src/accordion-panel/block.json +1 -1
- package/src/breadcrumbs/block.json +3 -4
- package/src/breadcrumbs/edit.js +96 -132
- package/src/breadcrumbs/index.php +203 -50
- package/src/buttons/transforms.js +1 -0
- package/src/categories/edit.js +10 -6
- package/src/categories/index.php +1 -1
- package/src/code/transforms.js +2 -0
- package/src/editor.scss +1 -0
- package/src/home-link/block.json +2 -1
- package/src/image/index.php +9 -9
- package/src/image/view.js +11 -1
- package/src/latest-comments/block.json +4 -3
- package/src/latest-comments/deprecated.js +37 -0
- package/src/latest-comments/edit.js +17 -10
- package/src/latest-comments/index.js +2 -0
- package/src/latest-comments/index.php +11 -2
- package/src/math/deprecated.js +44 -0
- package/src/math/edit.js +1 -0
- package/src/math/editor.scss +7 -0
- package/src/math/index.js +2 -0
- package/src/math/save.js +6 -5
- package/src/math/style.scss +4 -0
- package/src/navigation/index.php +7 -7
- package/src/navigation/menu-items-to-blocks.js +12 -2
- package/src/navigation/test/menu-items-to-blocks.js +144 -0
- package/src/navigation/view.js +2 -2
- package/src/navigation-link/link-ui/page-creator.js +25 -2
- package/src/post-date/block.json +1 -1
- package/src/post-date/edit.js +15 -10
- package/src/post-date/variations.js +2 -5
- package/src/post-template/edit.js +13 -1
- package/src/query/index.js +10 -0
- package/src/query/variations.js +17 -11
- package/src/query-pagination-next/index.php +1 -1
- package/src/query-pagination-previous/index.php +1 -1
- package/src/search/index.php +2 -2
- package/src/search/view.js +4 -4
- package/src/style.scss +1 -0
- package/src/term-template/index.php +8 -2
- package/src/terms-query/edit/inspector-controls/index.js +2 -2
- package/src/terms-query/edit/inspector-controls/inherit-control.js +1 -3
- package/src/utils/get-transformed-attributes.js +5 -16
package/src/image/index.php
CHANGED
|
@@ -250,12 +250,12 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
250
250
|
// Image.
|
|
251
251
|
$processor->next_tag( 'img' );
|
|
252
252
|
$processor->set_attribute( 'data-wp-init', 'callbacks.setButtonStyles' );
|
|
253
|
-
$processor->set_attribute( 'data-wp-on
|
|
254
|
-
$processor->set_attribute( 'data-wp-on-
|
|
253
|
+
$processor->set_attribute( 'data-wp-on--load', 'callbacks.setButtonStyles' );
|
|
254
|
+
$processor->set_attribute( 'data-wp-on-window--resize', 'callbacks.setButtonStyles' );
|
|
255
255
|
// Sets an event callback on the `img` because the `figure` element can also
|
|
256
256
|
// contain a caption, and we don't want to trigger the lightbox when the
|
|
257
257
|
// caption is clicked.
|
|
258
|
-
$processor->set_attribute( 'data-wp-on
|
|
258
|
+
$processor->set_attribute( 'data-wp-on--click', 'actions.showLightbox' );
|
|
259
259
|
$processor->set_attribute( 'data-wp-class--hide', 'state.isContentHidden' );
|
|
260
260
|
$processor->set_attribute( 'data-wp-class--show', 'state.isContentVisible' );
|
|
261
261
|
|
|
@@ -273,7 +273,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
273
273
|
aria-haspopup="dialog"
|
|
274
274
|
aria-label="' . esc_attr( $aria_label ) . '"
|
|
275
275
|
data-wp-init="callbacks.initTriggerButton"
|
|
276
|
-
data-wp-on
|
|
276
|
+
data-wp-on--click="actions.showLightbox"
|
|
277
277
|
data-wp-style--right="state.imageButtonRight"
|
|
278
278
|
data-wp-style--top="state.imageButtonTop"
|
|
279
279
|
>
|
|
@@ -324,12 +324,12 @@ function block_core_image_print_lightbox_overlay() {
|
|
|
324
324
|
data-wp-class--show-closing-animation="state.overlayOpened"
|
|
325
325
|
data-wp-watch="callbacks.setOverlayFocus"
|
|
326
326
|
data-wp-on--keydown="actions.handleKeydown"
|
|
327
|
-
data-wp-on
|
|
327
|
+
data-wp-on--touchstart="actions.handleTouchStart"
|
|
328
328
|
data-wp-on--touchmove="actions.handleTouchMove"
|
|
329
|
-
data-wp-on
|
|
330
|
-
data-wp-on
|
|
331
|
-
data-wp-on-
|
|
332
|
-
data-wp-on-
|
|
329
|
+
data-wp-on--touchend="actions.handleTouchEnd"
|
|
330
|
+
data-wp-on--click="actions.hideLightbox"
|
|
331
|
+
data-wp-on-window--resize="callbacks.setOverlayStyles"
|
|
332
|
+
data-wp-on-window--scroll="actions.handleScroll"
|
|
333
333
|
data-wp-bind--style="state.overlayStyles"
|
|
334
334
|
tabindex="-1"
|
|
335
335
|
>
|
package/src/image/view.js
CHANGED
|
@@ -356,9 +356,19 @@ const { state, actions, callbacks } = store(
|
|
|
356
356
|
`;
|
|
357
357
|
},
|
|
358
358
|
setButtonStyles() {
|
|
359
|
-
const { imageId } = getContext();
|
|
360
359
|
const { ref } = getElement();
|
|
361
360
|
|
|
361
|
+
// This guard prevents errors in images with the `srcset`
|
|
362
|
+
// attribute, which can dispatch `load` events even after DOM
|
|
363
|
+
// removal. Preact doesn't automatically clean up `load` event
|
|
364
|
+
// listeners on unmounted `img` elements (see
|
|
365
|
+
// https://github.com/preactjs/preact/issues/3141).
|
|
366
|
+
if ( ! ref ) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const { imageId } = getContext();
|
|
371
|
+
|
|
362
372
|
state.metadata[ imageId ].imageRef = ref;
|
|
363
373
|
state.metadata[ imageId ].currentSrc = ref.currentSrc;
|
|
364
374
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const v1 = {
|
|
6
|
+
attributes: {
|
|
7
|
+
commentsToShow: {
|
|
8
|
+
type: 'number',
|
|
9
|
+
default: 5,
|
|
10
|
+
minimum: 1,
|
|
11
|
+
maximum: 100,
|
|
12
|
+
},
|
|
13
|
+
displayAvatar: {
|
|
14
|
+
type: 'boolean',
|
|
15
|
+
default: true,
|
|
16
|
+
},
|
|
17
|
+
displayDate: {
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
default: true,
|
|
20
|
+
},
|
|
21
|
+
displayExcerpt: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
default: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
isEligible( attributes ) {
|
|
27
|
+
return attributes?.displayExcerpt === false;
|
|
28
|
+
},
|
|
29
|
+
migrate( attributes ) {
|
|
30
|
+
return {
|
|
31
|
+
...attributes,
|
|
32
|
+
displayContent: attributes.displayExcerpt ? 'excerpt' : 'none',
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default [ v1 ];
|
|
@@ -5,6 +5,7 @@ import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
|
|
|
5
5
|
import {
|
|
6
6
|
Disabled,
|
|
7
7
|
RangeControl,
|
|
8
|
+
SelectControl,
|
|
8
9
|
ToggleControl,
|
|
9
10
|
__experimentalToolsPanel as ToolsPanel,
|
|
10
11
|
__experimentalToolsPanelItem as ToolsPanelItem,
|
|
@@ -31,7 +32,7 @@ const MIN_COMMENTS = 1;
|
|
|
31
32
|
const MAX_COMMENTS = 100;
|
|
32
33
|
|
|
33
34
|
export default function LatestComments( { attributes, setAttributes } ) {
|
|
34
|
-
const { commentsToShow, displayAvatar, displayDate,
|
|
35
|
+
const { commentsToShow, displayAvatar, displayDate, displayContent } =
|
|
35
36
|
attributes;
|
|
36
37
|
|
|
37
38
|
const serverSideAttributes = {
|
|
@@ -54,7 +55,7 @@ export default function LatestComments( { attributes, setAttributes } ) {
|
|
|
54
55
|
commentsToShow: 5,
|
|
55
56
|
displayAvatar: true,
|
|
56
57
|
displayDate: true,
|
|
57
|
-
|
|
58
|
+
displayContent: 'excerpt',
|
|
58
59
|
} );
|
|
59
60
|
} }
|
|
60
61
|
dropdownMenuProps={ dropdownMenuProps }
|
|
@@ -98,20 +99,26 @@ export default function LatestComments( { attributes, setAttributes } ) {
|
|
|
98
99
|
</ToolsPanelItem>
|
|
99
100
|
|
|
100
101
|
<ToolsPanelItem
|
|
101
|
-
hasValue={ () =>
|
|
102
|
-
label={ __( 'Display
|
|
102
|
+
hasValue={ () => displayContent !== 'excerpt' }
|
|
103
|
+
label={ __( 'Display content' ) }
|
|
103
104
|
onDeselect={ () =>
|
|
104
|
-
setAttributes( {
|
|
105
|
+
setAttributes( { displayContent: 'excerpt' } )
|
|
105
106
|
}
|
|
106
107
|
isShownByDefault
|
|
107
108
|
>
|
|
108
|
-
<
|
|
109
|
+
<SelectControl
|
|
109
110
|
__nextHasNoMarginBottom
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
__next40pxDefaultSize
|
|
112
|
+
label={ __( 'Display content' ) }
|
|
113
|
+
value={ displayContent }
|
|
114
|
+
options={ [
|
|
115
|
+
{ label: __( 'No content' ), value: 'none' },
|
|
116
|
+
{ label: __( 'Excerpt' ), value: 'excerpt' },
|
|
117
|
+
{ label: __( 'Full content' ), value: 'full' },
|
|
118
|
+
] }
|
|
119
|
+
onChange={ ( value ) =>
|
|
113
120
|
setAttributes( {
|
|
114
|
-
|
|
121
|
+
displayContent: value,
|
|
115
122
|
} )
|
|
116
123
|
}
|
|
117
124
|
/>
|
|
@@ -9,6 +9,7 @@ import { comment as icon } from '@wordpress/icons';
|
|
|
9
9
|
import initBlock from '../utils/init-block';
|
|
10
10
|
import metadata from './block.json';
|
|
11
11
|
import edit from './edit';
|
|
12
|
+
import deprecated from './deprecated';
|
|
12
13
|
|
|
13
14
|
const { name } = metadata;
|
|
14
15
|
|
|
@@ -18,6 +19,7 @@ export const settings = {
|
|
|
18
19
|
icon,
|
|
19
20
|
example: {},
|
|
20
21
|
edit,
|
|
22
|
+
deprecated,
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export const init = () => initBlock( { name, metadata, settings } );
|
|
@@ -43,6 +43,13 @@ function wp_latest_comments_draft_or_post_title( $post = 0 ) {
|
|
|
43
43
|
* @return string Returns the post content with latest comments added.
|
|
44
44
|
*/
|
|
45
45
|
function render_block_core_latest_comments( $attributes ) {
|
|
46
|
+
// Handle backward compatibility: check for old displayExcerpt attribute
|
|
47
|
+
if ( isset( $attributes['displayExcerpt'] ) ) {
|
|
48
|
+
$display_content = $attributes['displayExcerpt'] ? 'excerpt' : 'none';
|
|
49
|
+
} else {
|
|
50
|
+
$display_content = isset( $attributes['displayContent'] ) ? $attributes['displayContent'] : 'excerpt';
|
|
51
|
+
}
|
|
52
|
+
|
|
46
53
|
$comments = get_comments(
|
|
47
54
|
/** This filter is documented in wp-includes/widgets/class-wp-widget-recent-comments.php */
|
|
48
55
|
apply_filters(
|
|
@@ -112,7 +119,9 @@ function render_block_core_latest_comments( $attributes ) {
|
|
|
112
119
|
);
|
|
113
120
|
}
|
|
114
121
|
$list_items_markup .= '</footer>';
|
|
115
|
-
if (
|
|
122
|
+
if ( 'full' === $display_content ) {
|
|
123
|
+
$list_items_markup .= '<div class="wp-block-latest-comments__comment-excerpt">' . wpautop( get_comment_text( $comment ) ) . '</div>';
|
|
124
|
+
} elseif ( 'excerpt' === $display_content ) {
|
|
116
125
|
$list_items_markup .= '<div class="wp-block-latest-comments__comment-excerpt">' . wpautop( get_comment_excerpt( $comment ) ) . '</div>';
|
|
117
126
|
}
|
|
118
127
|
$list_items_markup .= '</article></li>';
|
|
@@ -126,7 +135,7 @@ function render_block_core_latest_comments( $attributes ) {
|
|
|
126
135
|
if ( $attributes['displayDate'] ) {
|
|
127
136
|
$classnames[] = 'has-dates';
|
|
128
137
|
}
|
|
129
|
-
if (
|
|
138
|
+
if ( 'none' !== $display_content ) {
|
|
130
139
|
$classnames[] = 'has-excerpts';
|
|
131
140
|
}
|
|
132
141
|
if ( empty( $comments ) ) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useBlockProps } from '@wordpress/block-editor';
|
|
5
|
+
|
|
6
|
+
// v1: Add a wrapper div around the math element.
|
|
7
|
+
const v1 = {
|
|
8
|
+
attributes: {
|
|
9
|
+
latex: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
role: 'content',
|
|
12
|
+
},
|
|
13
|
+
mathML: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
source: 'html',
|
|
16
|
+
selector: 'math',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
save( { attributes } ) {
|
|
20
|
+
const { latex, mathML } = attributes;
|
|
21
|
+
|
|
22
|
+
if ( ! latex ) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<math
|
|
28
|
+
{ ...useBlockProps.save() }
|
|
29
|
+
display="block"
|
|
30
|
+
dangerouslySetInnerHTML={ { __html: mathML } }
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* New deprecations need to be placed first
|
|
38
|
+
* for them to have higher priority.
|
|
39
|
+
*
|
|
40
|
+
* Old deprecations may need to be updated as well.
|
|
41
|
+
*
|
|
42
|
+
* See block-deprecation.md
|
|
43
|
+
*/
|
|
44
|
+
export default [ v1 ];
|
package/src/math/edit.js
CHANGED
|
@@ -82,6 +82,7 @@ export default function MathEdit( { attributes, setAttributes, isSelected } ) {
|
|
|
82
82
|
label={ __( 'LaTeX math syntax' ) }
|
|
83
83
|
hideLabelFromVision
|
|
84
84
|
value={ latex }
|
|
85
|
+
className="wp-block-math__textarea-control"
|
|
85
86
|
onChange={ ( newLatex ) => {
|
|
86
87
|
if ( ! latexToMathML ) {
|
|
87
88
|
setAttributes( { latex: newLatex } );
|
package/src/math/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import initBlock from '../utils/init-block';
|
|
|
10
10
|
import edit from './edit';
|
|
11
11
|
import metadata from './block.json';
|
|
12
12
|
import save from './save';
|
|
13
|
+
import deprecated from './deprecated';
|
|
13
14
|
|
|
14
15
|
const { name } = metadata;
|
|
15
16
|
|
|
@@ -26,6 +27,7 @@ export const settings = {
|
|
|
26
27
|
},
|
|
27
28
|
edit,
|
|
28
29
|
save,
|
|
30
|
+
deprecated,
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export const init = () => initBlock( { name, metadata, settings } );
|
package/src/math/save.js
CHANGED
|
@@ -11,10 +11,11 @@ export default function save( { attributes } ) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
<div { ...useBlockProps.save() }>
|
|
15
|
+
<math
|
|
16
|
+
display="block"
|
|
17
|
+
dangerouslySetInnerHTML={ { __html: mathML } }
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
19
20
|
);
|
|
20
21
|
}
|
package/src/navigation/index.php
CHANGED
|
@@ -497,7 +497,7 @@ class WP_Navigation_Block_Renderer {
|
|
|
497
497
|
$close_button_directives = '';
|
|
498
498
|
if ( $is_interactive ) {
|
|
499
499
|
$open_button_directives = '
|
|
500
|
-
data-wp-on
|
|
500
|
+
data-wp-on--click="actions.openMenuOnClick"
|
|
501
501
|
data-wp-on--keydown="actions.handleMenuKeydown"
|
|
502
502
|
';
|
|
503
503
|
$responsive_container_directives = '
|
|
@@ -505,7 +505,7 @@ class WP_Navigation_Block_Renderer {
|
|
|
505
505
|
data-wp-class--is-menu-open="state.isMenuOpen"
|
|
506
506
|
data-wp-watch="callbacks.initMenu"
|
|
507
507
|
data-wp-on--keydown="actions.handleMenuKeydown"
|
|
508
|
-
data-wp-on
|
|
508
|
+
data-wp-on--focusout="actions.handleMenuFocusout"
|
|
509
509
|
tabindex="-1"
|
|
510
510
|
';
|
|
511
511
|
$responsive_dialog_directives = '
|
|
@@ -514,7 +514,7 @@ class WP_Navigation_Block_Renderer {
|
|
|
514
514
|
data-wp-bind--role="state.roleAttribute"
|
|
515
515
|
';
|
|
516
516
|
$close_button_directives = '
|
|
517
|
-
data-wp-on
|
|
517
|
+
data-wp-on--click="actions.closeMenuOnClick"
|
|
518
518
|
';
|
|
519
519
|
$responsive_container_content_directives = '
|
|
520
520
|
data-wp-watch="callbacks.focusFirstElement"
|
|
@@ -830,8 +830,8 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
|
|
|
830
830
|
$tags->set_attribute( 'tabindex', '-1' );
|
|
831
831
|
|
|
832
832
|
if ( ! isset( $block_attributes['openSubmenusOnClick'] ) || false === $block_attributes['openSubmenusOnClick'] ) {
|
|
833
|
-
$tags->set_attribute( 'data-wp-on
|
|
834
|
-
$tags->set_attribute( 'data-wp-on
|
|
833
|
+
$tags->set_attribute( 'data-wp-on--mouseenter', 'actions.openMenuOnHover' );
|
|
834
|
+
$tags->set_attribute( 'data-wp-on--mouseleave', 'actions.closeMenuOnHover' );
|
|
835
835
|
}
|
|
836
836
|
|
|
837
837
|
// Add directives to the toggle submenu button.
|
|
@@ -841,7 +841,7 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
|
|
|
841
841
|
'class_name' => 'wp-block-navigation-submenu__toggle',
|
|
842
842
|
)
|
|
843
843
|
) ) {
|
|
844
|
-
$tags->set_attribute( 'data-wp-on
|
|
844
|
+
$tags->set_attribute( 'data-wp-on--click', 'actions.toggleMenuOnClick' );
|
|
845
845
|
$tags->set_attribute( 'data-wp-bind--aria-expanded', 'state.isMenuOpen' );
|
|
846
846
|
// The `aria-expanded` attribute for SSR is already added in the submenu block.
|
|
847
847
|
}
|
|
@@ -852,7 +852,7 @@ function block_core_navigation_add_directives_to_submenu( $tags, $block_attribut
|
|
|
852
852
|
'class_name' => 'wp-block-navigation__submenu-container',
|
|
853
853
|
)
|
|
854
854
|
) ) {
|
|
855
|
-
$tags->set_attribute( 'data-wp-on
|
|
855
|
+
$tags->set_attribute( 'data-wp-on--focus', 'actions.openMenuOnFocus' );
|
|
856
856
|
}
|
|
857
857
|
|
|
858
858
|
// Iterate through subitems if exist.
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
import { createBlock, parse } from '@wordpress/blocks';
|
|
5
5
|
import { applyFilters } from '@wordpress/hooks';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { buildNavigationLinkEntityBinding } from '../navigation-link/shared/use-entity-binding';
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Convert a flat menu item structure to a nested blocks structure.
|
|
9
14
|
*
|
|
@@ -145,12 +150,14 @@ function menuItemToBlockAttributes(
|
|
|
145
150
|
object = 'tag';
|
|
146
151
|
}
|
|
147
152
|
|
|
153
|
+
const inferredKind = menuItemTypeField?.replace( '_', '-' ) || 'custom';
|
|
154
|
+
|
|
148
155
|
return {
|
|
149
156
|
label: menuItemTitleField?.rendered || '',
|
|
150
157
|
...( object?.length && {
|
|
151
158
|
type: object,
|
|
152
159
|
} ),
|
|
153
|
-
kind:
|
|
160
|
+
kind: inferredKind,
|
|
154
161
|
url: url || '',
|
|
155
162
|
...( xfn?.length &&
|
|
156
163
|
xfn.join( ' ' ).trim() && {
|
|
@@ -165,8 +172,11 @@ function menuItemToBlockAttributes(
|
|
|
165
172
|
title: attr_title,
|
|
166
173
|
} ),
|
|
167
174
|
...( object_id &&
|
|
168
|
-
'
|
|
175
|
+
( inferredKind === 'post-type' || inferredKind === 'taxonomy' ) && {
|
|
169
176
|
id: object_id,
|
|
177
|
+
metadata: {
|
|
178
|
+
bindings: buildNavigationLinkEntityBinding( inferredKind ),
|
|
179
|
+
},
|
|
170
180
|
} ),
|
|
171
181
|
/* eslint-enable camelcase */
|
|
172
182
|
...( description?.length && {
|
|
@@ -371,4 +371,148 @@ describe( 'converting menu items to blocks', () => {
|
|
|
371
371
|
const { innerBlocks: actual } = menuItemsToBlocks( [] );
|
|
372
372
|
expect( actual ).toEqual( [] );
|
|
373
373
|
} );
|
|
374
|
+
|
|
375
|
+
it( 'adds entity bindings for non-custom menu items', () => {
|
|
376
|
+
const { innerBlocks: actual } = menuItemsToBlocks( [
|
|
377
|
+
{
|
|
378
|
+
id: 1,
|
|
379
|
+
title: {
|
|
380
|
+
raw: 'Page Item',
|
|
381
|
+
rendered: 'Page Item',
|
|
382
|
+
},
|
|
383
|
+
url: 'http://localhost:8889/page-item/',
|
|
384
|
+
attr_title: '',
|
|
385
|
+
description: '',
|
|
386
|
+
type: 'post_type',
|
|
387
|
+
type_label: 'Page',
|
|
388
|
+
object: 'page',
|
|
389
|
+
object_id: 123,
|
|
390
|
+
parent: 0,
|
|
391
|
+
menu_order: 1,
|
|
392
|
+
target: '',
|
|
393
|
+
classes: [ '' ],
|
|
394
|
+
xfn: [ '' ],
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
id: 2,
|
|
398
|
+
title: {
|
|
399
|
+
raw: 'Category Item',
|
|
400
|
+
rendered: 'Category Item',
|
|
401
|
+
},
|
|
402
|
+
url: 'http://localhost:8889/category/category-item/',
|
|
403
|
+
attr_title: '',
|
|
404
|
+
description: '',
|
|
405
|
+
type: 'taxonomy',
|
|
406
|
+
type_label: 'Category',
|
|
407
|
+
object: 'category',
|
|
408
|
+
object_id: 456,
|
|
409
|
+
parent: 0,
|
|
410
|
+
menu_order: 2,
|
|
411
|
+
target: '',
|
|
412
|
+
classes: [ '' ],
|
|
413
|
+
xfn: [ '' ],
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
id: 3,
|
|
417
|
+
title: {
|
|
418
|
+
raw: 'Custom Item',
|
|
419
|
+
rendered: 'Custom Item',
|
|
420
|
+
},
|
|
421
|
+
url: 'http://localhost:8889/custom-link/',
|
|
422
|
+
attr_title: '',
|
|
423
|
+
description: '',
|
|
424
|
+
type: 'custom',
|
|
425
|
+
type_label: 'Custom Link',
|
|
426
|
+
object: 'custom',
|
|
427
|
+
parent: 0,
|
|
428
|
+
menu_order: 3,
|
|
429
|
+
target: '',
|
|
430
|
+
classes: [ '' ],
|
|
431
|
+
xfn: [ '' ],
|
|
432
|
+
},
|
|
433
|
+
] );
|
|
434
|
+
|
|
435
|
+
expect( actual ).toEqual( [
|
|
436
|
+
expect.objectContaining( {
|
|
437
|
+
name: 'core/navigation-link',
|
|
438
|
+
attributes: expect.objectContaining( {
|
|
439
|
+
label: 'Page Item',
|
|
440
|
+
id: 123,
|
|
441
|
+
metadata: {
|
|
442
|
+
bindings: {
|
|
443
|
+
url: {
|
|
444
|
+
source: 'core/post-data',
|
|
445
|
+
args: {
|
|
446
|
+
field: 'link',
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
} ),
|
|
452
|
+
innerBlocks: [],
|
|
453
|
+
} ),
|
|
454
|
+
expect.objectContaining( {
|
|
455
|
+
name: 'core/navigation-link',
|
|
456
|
+
attributes: expect.objectContaining( {
|
|
457
|
+
label: 'Category Item',
|
|
458
|
+
id: 456,
|
|
459
|
+
metadata: {
|
|
460
|
+
bindings: {
|
|
461
|
+
url: {
|
|
462
|
+
source: 'core/term-data',
|
|
463
|
+
args: {
|
|
464
|
+
field: 'link',
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
},
|
|
469
|
+
} ),
|
|
470
|
+
innerBlocks: [],
|
|
471
|
+
} ),
|
|
472
|
+
expect.objectContaining( {
|
|
473
|
+
name: 'core/navigation-link',
|
|
474
|
+
attributes: expect.objectContaining( {
|
|
475
|
+
label: 'Custom Item',
|
|
476
|
+
// Custom items should NOT have id, metadata, or bindings
|
|
477
|
+
} ),
|
|
478
|
+
innerBlocks: [],
|
|
479
|
+
} ),
|
|
480
|
+
] );
|
|
481
|
+
|
|
482
|
+
// Verify custom item does NOT have bindings
|
|
483
|
+
expect( actual[ 2 ].attributes ).not.toHaveProperty( 'id' );
|
|
484
|
+
expect( actual[ 2 ].attributes ).not.toHaveProperty( 'metadata' );
|
|
485
|
+
} );
|
|
486
|
+
|
|
487
|
+
it( 'does not add bindings for invalid kinds even when object_id is present', () => {
|
|
488
|
+
const { innerBlocks: actual } = menuItemsToBlocks( [
|
|
489
|
+
{
|
|
490
|
+
id: 10,
|
|
491
|
+
title: {
|
|
492
|
+
raw: 'Invalid Kind Item',
|
|
493
|
+
rendered: 'Invalid Kind Item',
|
|
494
|
+
},
|
|
495
|
+
url: 'http://localhost:8889/invalid-kind-item/',
|
|
496
|
+
attr_title: '',
|
|
497
|
+
description: '',
|
|
498
|
+
type: 'invalid', // becomes inferred kind 'invalid'
|
|
499
|
+
type_label: 'Invalid',
|
|
500
|
+
object: 'page',
|
|
501
|
+
object_id: 999,
|
|
502
|
+
parent: 0,
|
|
503
|
+
menu_order: 1,
|
|
504
|
+
target: '',
|
|
505
|
+
classes: [ '' ],
|
|
506
|
+
xfn: [ '' ],
|
|
507
|
+
},
|
|
508
|
+
] );
|
|
509
|
+
|
|
510
|
+
expect( actual ).toHaveLength( 1 );
|
|
511
|
+
expect( actual[ 0 ].name ).toBe( 'core/navigation-link' );
|
|
512
|
+
// Should not set id or metadata when kind is not supported
|
|
513
|
+
expect( actual[ 0 ].attributes ).not.toHaveProperty( 'id' );
|
|
514
|
+
expect( actual[ 0 ].attributes ).not.toHaveProperty( 'metadata' );
|
|
515
|
+
// Label should still be set correctly
|
|
516
|
+
expect( actual[ 0 ].attributes.label ).toBe( 'Invalid Kind Item' );
|
|
517
|
+
} );
|
|
374
518
|
} );
|
package/src/navigation/view.js
CHANGED
|
@@ -144,7 +144,7 @@ const { state, actions } = store(
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
} ),
|
|
147
|
-
handleMenuFocusout( event ) {
|
|
147
|
+
handleMenuFocusout: withSyncEvent( ( event ) => {
|
|
148
148
|
const { modal, type } = getContext();
|
|
149
149
|
// If focus is outside modal, and in the document, close menu
|
|
150
150
|
// event.target === The element losing focus
|
|
@@ -162,7 +162,7 @@ const { state, actions } = store(
|
|
|
162
162
|
actions.closeMenu( 'click' );
|
|
163
163
|
actions.closeMenu( 'focus' );
|
|
164
164
|
}
|
|
165
|
-
},
|
|
165
|
+
} ),
|
|
166
166
|
|
|
167
167
|
openMenu( menuOpenedOn = 'click' ) {
|
|
168
168
|
const { type } = getContext();
|
|
@@ -9,9 +9,10 @@ import {
|
|
|
9
9
|
__experimentalVStack as VStack,
|
|
10
10
|
__experimentalHStack as HStack,
|
|
11
11
|
} from '@wordpress/components';
|
|
12
|
-
import { __ } from '@wordpress/i18n';
|
|
12
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
13
13
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
14
14
|
import { store as coreStore } from '@wordpress/core-data';
|
|
15
|
+
import { store as noticesStore } from '@wordpress/notices';
|
|
15
16
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
16
17
|
import { useState } from '@wordpress/element';
|
|
17
18
|
|
|
@@ -57,6 +58,8 @@ export function LinkUIPageCreator( {
|
|
|
57
58
|
);
|
|
58
59
|
|
|
59
60
|
const { saveEntityRecord } = useDispatch( coreStore );
|
|
61
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
62
|
+
useDispatch( noticesStore );
|
|
60
63
|
|
|
61
64
|
async function createPage( event ) {
|
|
62
65
|
event.preventDefault();
|
|
@@ -85,10 +88,30 @@ export function LinkUIPageCreator( {
|
|
|
85
88
|
kind: 'post-type',
|
|
86
89
|
};
|
|
87
90
|
|
|
91
|
+
// Show success notice
|
|
92
|
+
createSuccessNotice(
|
|
93
|
+
sprintf(
|
|
94
|
+
// translators: %s: the name of the new page being created.
|
|
95
|
+
__( '%s page created successfully.' ),
|
|
96
|
+
decodeEntities( savedRecord.title.rendered )
|
|
97
|
+
),
|
|
98
|
+
{
|
|
99
|
+
type: 'snackbar',
|
|
100
|
+
id: 'page-created-success',
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
|
|
88
104
|
onPageCreated( pageLink );
|
|
89
105
|
}
|
|
90
106
|
} catch ( error ) {
|
|
91
|
-
//
|
|
107
|
+
// Show error notice
|
|
108
|
+
createErrorNotice(
|
|
109
|
+
__( 'Failed to create page. Please try again.' ),
|
|
110
|
+
{
|
|
111
|
+
type: 'snackbar',
|
|
112
|
+
id: 'page-created-error',
|
|
113
|
+
}
|
|
114
|
+
);
|
|
92
115
|
}
|
|
93
116
|
}
|
|
94
117
|
|
package/src/post-date/block.json
CHANGED