@wordpress/block-library 8.20.0 → 8.21.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 +7 -0
- package/README.md +12 -0
- package/build/block/index.js +2 -1
- package/build/block/index.js.map +1 -1
- package/build/code/edit.native.js +8 -2
- package/build/code/edit.native.js.map +1 -1
- package/build/cover/deprecated.js +110 -1
- package/build/cover/deprecated.js.map +1 -1
- package/build/cover/edit/index.js +9 -3
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +1 -2
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/cover/index.js +0 -3
- package/build/cover/index.js.map +1 -1
- package/build/cover/save.js +2 -1
- package/build/cover/save.js.map +1 -1
- package/build/cover/shared.js +1 -1
- package/build/cover/shared.js.map +1 -1
- package/build/footnotes/index.js +1 -0
- package/build/footnotes/index.js.map +1 -1
- package/build/form/edit.js +138 -0
- package/build/form/edit.js.map +1 -0
- package/build/form/index.js +92 -0
- package/build/form/index.js.map +1 -0
- package/build/form/init.js +13 -0
- package/build/form/init.js.map +1 -0
- package/build/form/save.js +28 -0
- package/build/form/save.js.map +1 -0
- package/build/form/utils.js +24 -0
- package/build/form/utils.js.map +1 -0
- package/build/form/variations.js +95 -0
- package/build/form/variations.js.map +1 -0
- package/build/form/view.js +42 -0
- package/build/form/view.js.map +1 -0
- package/build/form-input/edit.js +124 -0
- package/build/form-input/edit.js.map +1 -0
- package/build/form-input/index.js +105 -0
- package/build/form-input/index.js.map +1 -0
- package/build/form-input/init.js +13 -0
- package/build/form-input/init.js.map +1 -0
- package/build/form-input/save.js +87 -0
- package/build/form-input/save.js.map +1 -0
- package/build/form-input/variations.js +93 -0
- package/build/form-input/variations.js.map +1 -0
- package/build/form-submission-notification/edit.js +59 -0
- package/build/form-submission-notification/edit.js.map +1 -0
- package/build/form-submission-notification/index.js +56 -0
- package/build/form-submission-notification/index.js.map +1 -0
- package/build/form-submission-notification/init.js +13 -0
- package/build/form-submission-notification/init.js.map +1 -0
- package/build/form-submission-notification/save.js +33 -0
- package/build/form-submission-notification/save.js.map +1 -0
- package/build/form-submission-notification/variations.js +63 -0
- package/build/form-submission-notification/variations.js.map +1 -0
- package/build/form-submit-button/edit.js +32 -0
- package/build/form-submit-button/edit.js.map +1 -0
- package/build/form-submit-button/index.js +44 -0
- package/build/form-submit-button/index.js.map +1 -0
- package/build/form-submit-button/init.js +13 -0
- package/build/form-submit-button/init.js.map +1 -0
- package/build/form-submit-button/save.js +22 -0
- package/build/form-submit-button/save.js.map +1 -0
- package/build/group/index.js +0 -1
- package/build/group/index.js.map +1 -1
- package/build/heading/index.js +3 -2
- package/build/heading/index.js.map +1 -1
- package/build/image/image.js +4 -1
- package/build/image/image.js.map +1 -1
- package/build/image/view.js +82 -40
- package/build/image/view.js.map +1 -1
- package/build/index.js +10 -0
- package/build/index.js.map +1 -1
- package/build/latest-posts/edit.js +6 -2
- package/build/latest-posts/edit.js.map +1 -1
- package/build/list-item/hooks/use-merge.js +15 -15
- package/build/list-item/hooks/use-merge.js.map +1 -1
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/missing/edit.native.js +14 -62
- package/build/missing/edit.native.js.map +1 -1
- package/build/navigation/edit/index.js +0 -1
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/index.js +2 -1
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/view.js +27 -5
- package/build/navigation/view.js.map +1 -1
- package/build/page-list-item/edit.js +3 -1
- package/build/page-list-item/edit.js.map +1 -1
- package/build/paragraph/index.js +7 -0
- package/build/paragraph/index.js.map +1 -1
- package/build/pattern/index.js +2 -1
- package/build/pattern/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/block/index.js +2 -1
- package/build-module/block/index.js.map +1 -1
- package/build-module/code/edit.native.js +8 -2
- package/build-module/code/edit.native.js.map +1 -1
- package/build-module/cover/deprecated.js +110 -1
- package/build-module/cover/deprecated.js.map +1 -1
- package/build-module/cover/edit/index.js +9 -3
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +1 -2
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/cover/index.js +0 -3
- package/build-module/cover/index.js.map +1 -1
- package/build-module/cover/save.js +2 -1
- package/build-module/cover/save.js.map +1 -1
- package/build-module/cover/shared.js +1 -1
- package/build-module/cover/shared.js.map +1 -1
- package/build-module/footnotes/index.js +1 -0
- package/build-module/footnotes/index.js.map +1 -1
- package/build-module/form/edit.js +130 -0
- package/build-module/form/edit.js.map +1 -0
- package/build-module/form/index.js +82 -0
- package/build-module/form/index.js.map +1 -0
- package/build-module/form/init.js +6 -0
- package/build-module/form/init.js.map +1 -0
- package/build-module/form/save.js +20 -0
- package/build-module/form/save.js.map +1 -0
- package/build-module/form/utils.js +15 -0
- package/build-module/form/utils.js.map +1 -0
- package/build-module/form/variations.js +86 -0
- package/build-module/form/variations.js.map +1 -0
- package/build-module/form/view.js +40 -0
- package/build-module/form/view.js.map +1 -0
- package/build-module/form-input/edit.js +115 -0
- package/build-module/form-input/edit.js.map +1 -0
- package/build-module/form-input/index.js +95 -0
- package/build-module/form-input/index.js.map +1 -0
- package/build-module/form-input/init.js +6 -0
- package/build-module/form-input/init.js.map +1 -0
- package/build-module/form-input/save.js +80 -0
- package/build-module/form-input/save.js.map +1 -0
- package/build-module/form-input/variations.js +85 -0
- package/build-module/form-input/variations.js.map +1 -0
- package/build-module/form-submission-notification/edit.js +50 -0
- package/build-module/form-submission-notification/edit.js.map +1 -0
- package/build-module/form-submission-notification/index.js +47 -0
- package/build-module/form-submission-notification/index.js.map +1 -0
- package/build-module/form-submission-notification/init.js +6 -0
- package/build-module/form-submission-notification/init.js.map +1 -0
- package/build-module/form-submission-notification/save.js +25 -0
- package/build-module/form-submission-notification/save.js.map +1 -0
- package/build-module/form-submission-notification/variations.js +55 -0
- package/build-module/form-submission-notification/variations.js.map +1 -0
- package/build-module/form-submit-button/edit.js +24 -0
- package/build-module/form-submit-button/edit.js.map +1 -0
- package/build-module/form-submit-button/index.js +34 -0
- package/build-module/form-submit-button/index.js.map +1 -0
- package/build-module/form-submit-button/init.js +6 -0
- package/build-module/form-submit-button/init.js.map +1 -0
- package/build-module/form-submit-button/save.js +14 -0
- package/build-module/form-submit-button/save.js.map +1 -0
- package/build-module/group/index.js +0 -1
- package/build-module/group/index.js.map +1 -1
- package/build-module/heading/index.js +3 -2
- package/build-module/heading/index.js.map +1 -1
- package/build-module/image/image.js +4 -1
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/view.js +82 -40
- package/build-module/image/view.js.map +1 -1
- package/build-module/index.js +10 -0
- package/build-module/index.js.map +1 -1
- package/build-module/latest-posts/edit.js +6 -2
- package/build-module/latest-posts/edit.js.map +1 -1
- package/build-module/list-item/hooks/use-merge.js +15 -15
- package/build-module/list-item/hooks/use-merge.js.map +1 -1
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/missing/edit.native.js +17 -65
- package/build-module/missing/edit.native.js.map +1 -1
- package/build-module/navigation/edit/index.js +0 -1
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/index.js +2 -1
- package/build-module/navigation/index.js.map +1 -1
- package/build-module/navigation/view.js +27 -5
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/page-list-item/edit.js +3 -1
- package/build-module/page-list-item/edit.js.map +1 -1
- package/build-module/paragraph/index.js +7 -0
- package/build-module/paragraph/index.js.map +1 -1
- package/build-module/pattern/index.js +2 -1
- package/build-module/pattern/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/editor-rtl.css +50 -0
- package/build-style/editor.css +50 -0
- package/build-style/form-input/editor-rtl.css +106 -0
- package/build-style/form-input/editor.css +106 -0
- package/build-style/form-input/style-rtl.css +135 -0
- package/build-style/form-input/style.css +135 -0
- package/build-style/form-submission-notification/editor-rtl.css +118 -0
- package/build-style/form-submission-notification/editor.css +118 -0
- package/build-style/form-submit-button/style-rtl.css +91 -0
- package/build-style/form-submit-button/style.css +91 -0
- package/build-style/image/style-rtl.css +39 -5
- package/build-style/image/style.css +39 -5
- package/build-style/query/style-rtl.css +0 -10
- package/build-style/query/style.css +0 -10
- package/build-style/style-rtl.css +87 -5
- package/build-style/style.css +87 -5
- package/package.json +32 -32
- package/src/block/block.json +2 -1
- package/src/code/edit.native.js +15 -1
- package/src/cover/block.json +0 -3
- package/src/cover/deprecated.js +151 -1
- package/src/cover/edit/index.js +12 -3
- package/src/cover/edit/inspector-controls.js +19 -25
- package/src/cover/save.js +2 -1
- package/src/cover/shared.js +1 -1
- package/src/editor.scss +2 -0
- package/src/footnotes/block.json +1 -0
- package/src/form/block.json +60 -0
- package/src/form/edit.js +179 -0
- package/src/form/index.js +20 -0
- package/src/form/index.php +214 -0
- package/src/form/init.js +6 -0
- package/src/form/save.js +20 -0
- package/src/form/utils.js +39 -0
- package/src/form/variations.js +139 -0
- package/src/form/view.js +41 -0
- package/src/form-input/block.json +73 -0
- package/src/form-input/edit.js +151 -0
- package/src/form-input/editor.scss +24 -0
- package/src/form-input/index.js +20 -0
- package/src/form-input/index.php +45 -0
- package/src/form-input/init.js +6 -0
- package/src/form-input/save.js +83 -0
- package/src/form-input/style.scss +61 -0
- package/src/form-input/variations.js +82 -0
- package/src/form-submission-notification/block.json +19 -0
- package/src/form-submission-notification/edit.js +63 -0
- package/src/form-submission-notification/editor.scss +45 -0
- package/src/form-submission-notification/index.js +26 -0
- package/src/form-submission-notification/index.php +48 -0
- package/src/form-submission-notification/init.js +6 -0
- package/src/form-submission-notification/save.js +28 -0
- package/src/form-submission-notification/variations.js +59 -0
- package/src/form-submit-button/block.json +14 -0
- package/src/form-submit-button/edit.js +33 -0
- package/src/form-submit-button/index.js +18 -0
- package/src/form-submit-button/init.js +6 -0
- package/src/form-submit-button/save.js +14 -0
- package/src/form-submit-button/style.scss +3 -0
- package/src/group/block.json +0 -1
- package/src/heading/index.js +4 -2
- package/src/image/image.js +10 -0
- package/src/image/index.php +128 -82
- package/src/image/style.scss +49 -5
- package/src/image/view.js +100 -52
- package/src/index.js +10 -0
- package/src/latest-posts/edit.js +11 -2
- package/src/latest-posts/index.php +17 -8
- package/src/list-item/hooks/use-merge.js +20 -23
- package/src/lock-unlock.js +1 -1
- package/src/missing/edit.native.js +17 -115
- package/src/missing/style.native.scss +0 -67
- package/src/missing/test/edit-integration.native.js +135 -49
- package/src/missing/test/edit.native.js +0 -41
- package/src/navigation/block.json +2 -1
- package/src/navigation/edit/index.js +0 -1
- package/src/navigation/index.php +28 -8
- package/src/navigation/view.js +25 -6
- package/src/page-list-item/edit.js +2 -0
- package/src/paragraph/index.js +10 -0
- package/src/pattern/block.json +2 -1
- package/src/pattern/index.php +0 -3
- package/src/post-navigation-link/index.php +2 -1
- package/src/preformatted/test/edit.native.js +38 -0
- package/src/query/index.php +3 -2
- package/src/query/style.scss +0 -11
- package/src/search/index.php +0 -4
- package/src/style.scss +1 -0
- package/src/template-part/block.json +2 -1
- package/src/template-part/index.php +4 -7
- package/src/verse/test/edit.native.js +37 -0
package/src/image/index.php
CHANGED
|
@@ -9,17 +9,20 @@
|
|
|
9
9
|
* Renders the `core/image` block on the server,
|
|
10
10
|
* adding a data-id attribute to the element if core/gallery has added on pre-render.
|
|
11
11
|
*
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
*
|
|
12
|
+
* @param array $attributes The block attributes.
|
|
13
|
+
* @param string $content The block content.
|
|
14
|
+
* @param WP_Block $block The block object.
|
|
15
|
+
*
|
|
16
|
+
* @return string The block content with the data-id attribute added.
|
|
16
17
|
*/
|
|
17
18
|
function render_block_core_image( $attributes, $content, $block ) {
|
|
19
|
+
if ( false === stripos( $content, '<img' ) ) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
$processor = new WP_HTML_Tag_Processor( $content );
|
|
20
|
-
$processor->next_tag( 'img' );
|
|
21
24
|
|
|
22
|
-
if ( $processor->
|
|
25
|
+
if ( ! $processor->next_tag( 'img' ) || null === $processor->get_attribute( 'src' ) ) {
|
|
23
26
|
return '';
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -31,57 +34,60 @@ function render_block_core_image( $attributes, $content, $block ) {
|
|
|
31
34
|
$processor->set_attribute( 'data-id', $attributes['data-id'] );
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
$lightbox_enabled = false;
|
|
35
37
|
$link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';
|
|
36
38
|
$lightbox_settings = block_core_image_get_lightbox_settings( $block->parsed_block );
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
$view_js_file_handle = 'wp-block-image-view';
|
|
41
|
+
$script_handles = $block->block_type->view_script_handles;
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
/*
|
|
44
|
+
* If the lightbox is enabled and the image is not linked, add the filter
|
|
45
|
+
* and the JavaScript view file.
|
|
46
|
+
*/
|
|
47
|
+
if (
|
|
48
|
+
isset( $lightbox_settings ) &&
|
|
49
|
+
'none' === $link_destination &&
|
|
50
|
+
isset( $lightbox_settings['enabled'] ) &&
|
|
51
|
+
true === $lightbox_settings['enabled']
|
|
52
|
+
) {
|
|
48
53
|
$block->block_type->supports['interactivity'] = true;
|
|
49
|
-
}
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if ( ! wp_script_is( $view_js_file ) ) {
|
|
54
|
-
$script_handles = $block->block_type->view_script_handles;
|
|
55
|
-
|
|
56
|
-
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
57
|
-
if ( ! $lightbox_enabled && in_array( $view_js_file, $script_handles, true ) ) {
|
|
58
|
-
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file ) );
|
|
55
|
+
if ( ! in_array( $view_js_file_handle, $script_handles, true ) ) {
|
|
56
|
+
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file_handle ) );
|
|
59
57
|
}
|
|
60
|
-
// If the script is needed, but it was previously removed, add it again.
|
|
61
|
-
if ( $lightbox_enabled && ! in_array( $view_js_file, $script_handles, true ) ) {
|
|
62
|
-
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file ) );
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
/*
|
|
60
|
+
* This render needs to happen in a filter with priority 15 to ensure
|
|
61
|
+
* that it runs after the duotone filter and that duotone styles are
|
|
62
|
+
* applied to the image in the lightbox. We also need to ensure that the
|
|
63
|
+
* lightbox works with any plugins that might use filters as well. We
|
|
64
|
+
* can consider removing this in the future if the way the blocks are
|
|
65
|
+
* rendered changes, or if a new kind of filter is introduced.
|
|
66
|
+
*/
|
|
72
67
|
add_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15, 2 );
|
|
68
|
+
} else {
|
|
69
|
+
/*
|
|
70
|
+
* Remove the filter and the JavaScript view file if previously added by
|
|
71
|
+
* other Image blocks.
|
|
72
|
+
*/
|
|
73
|
+
remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 );
|
|
74
|
+
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
75
|
+
if ( in_array( $view_js_file_handle, $script_handles, true ) ) {
|
|
76
|
+
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) );
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
return $processor->get_updated_html();
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
/**
|
|
79
|
-
*
|
|
84
|
+
* Adds the lightboxEnabled flag to the block data.
|
|
80
85
|
*
|
|
81
86
|
* This is used to determine whether the lightbox should be rendered or not.
|
|
82
87
|
*
|
|
83
|
-
* @param
|
|
84
|
-
*
|
|
88
|
+
* @param array $block Block data.
|
|
89
|
+
*
|
|
90
|
+
* @return array Filtered block data.
|
|
85
91
|
*/
|
|
86
92
|
function block_core_image_get_lightbox_settings( $block ) {
|
|
87
93
|
// Get the lightbox setting from the block attributes.
|
|
@@ -113,43 +119,61 @@ function block_core_image_get_lightbox_settings( $block ) {
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
/**
|
|
116
|
-
*
|
|
122
|
+
* Adds the directives and layout needed for the lightbox behavior.
|
|
123
|
+
*
|
|
124
|
+
* @param string $block_content Rendered block content.
|
|
125
|
+
* @param array $block Block object.
|
|
117
126
|
*
|
|
118
|
-
* @
|
|
119
|
-
* @param array $block Block object.
|
|
120
|
-
* @return string Filtered block content.
|
|
127
|
+
* @return string Filtered block content.
|
|
121
128
|
*/
|
|
122
129
|
function block_core_image_render_lightbox( $block_content, $block ) {
|
|
130
|
+
/*
|
|
131
|
+
* If it's not possible that an IMG element exists then return the given
|
|
132
|
+
* block content as-is. It may be that there's no actual image in the block
|
|
133
|
+
* or it could be that another plugin already modified this HTML.
|
|
134
|
+
*/
|
|
135
|
+
if ( false === stripos( $block_content, '<img' ) ) {
|
|
136
|
+
return $block_content;
|
|
137
|
+
}
|
|
138
|
+
|
|
123
139
|
$processor = new WP_HTML_Tag_Processor( $block_content );
|
|
124
140
|
|
|
125
141
|
$aria_label = __( 'Enlarge image' );
|
|
126
142
|
|
|
143
|
+
/*
|
|
144
|
+
* If there's definitely no IMG element in the block then return the given
|
|
145
|
+
* block content as-is. There's nothing that this code can knowingly modify
|
|
146
|
+
* to add the lightbox behavior.
|
|
147
|
+
*/
|
|
148
|
+
if ( ! $processor->next_tag( 'img' ) ) {
|
|
149
|
+
return $block_content;
|
|
150
|
+
}
|
|
151
|
+
|
|
127
152
|
$alt_attribute = $processor->get_attribute( 'alt' );
|
|
128
153
|
|
|
129
|
-
|
|
154
|
+
// An empty alt attribute `alt=""` is valid for decorative images.
|
|
155
|
+
if ( is_string( $alt_attribute ) ) {
|
|
130
156
|
$alt_attribute = trim( $alt_attribute );
|
|
131
157
|
}
|
|
132
158
|
|
|
159
|
+
// It only makes sense to append the alt text to the button aria-label when the alt text is non-empty.
|
|
133
160
|
if ( $alt_attribute ) {
|
|
134
161
|
/* translators: %s: Image alt text. */
|
|
135
162
|
$aria_label = sprintf( __( 'Enlarge image: %s' ), $alt_attribute );
|
|
136
163
|
}
|
|
137
|
-
$content = $processor->get_updated_html();
|
|
138
164
|
|
|
139
165
|
// Currently, we are only enabling the zoom animation.
|
|
140
166
|
$lightbox_animation = 'zoom';
|
|
141
167
|
|
|
142
|
-
// We want to store the src in the context so we
|
|
143
|
-
|
|
144
|
-
$z->next_tag( 'img' );
|
|
145
|
-
|
|
168
|
+
// Note: We want to store the `src` in the context so we
|
|
169
|
+
// can set it dynamically when the lightbox is opened.
|
|
146
170
|
if ( isset( $block['attrs']['id'] ) ) {
|
|
147
171
|
$img_uploaded_src = wp_get_attachment_url( $block['attrs']['id'] );
|
|
148
172
|
$img_metadata = wp_get_attachment_metadata( $block['attrs']['id'] );
|
|
149
|
-
$img_width = $img_metadata['width'];
|
|
150
|
-
$img_height = $img_metadata['height'];
|
|
173
|
+
$img_width = $img_metadata['width'] ?? 'none';
|
|
174
|
+
$img_height = $img_metadata['height'] ?? 'none';
|
|
151
175
|
} else {
|
|
152
|
-
$img_uploaded_src = $
|
|
176
|
+
$img_uploaded_src = $processor->get_attribute( 'src' );
|
|
153
177
|
$img_width = 'none';
|
|
154
178
|
$img_height = 'none';
|
|
155
179
|
}
|
|
@@ -160,7 +184,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
160
184
|
$scale_attr = false;
|
|
161
185
|
}
|
|
162
186
|
|
|
163
|
-
$w = new WP_HTML_Tag_Processor( $
|
|
187
|
+
$w = new WP_HTML_Tag_Processor( $block_content );
|
|
164
188
|
$w->next_tag( 'figure' );
|
|
165
189
|
$w->add_class( 'wp-lightbox-container' );
|
|
166
190
|
$w->set_attribute( 'data-wp-interactive', true );
|
|
@@ -180,7 +204,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
180
204
|
"imageCurrentSrc": "",
|
|
181
205
|
"targetWidth": "%s",
|
|
182
206
|
"targetHeight": "%s",
|
|
183
|
-
"scaleAttr": "%s"
|
|
207
|
+
"scaleAttr": "%s",
|
|
208
|
+
"dialogLabel": "%s"
|
|
184
209
|
}
|
|
185
210
|
}
|
|
186
211
|
}',
|
|
@@ -188,31 +213,44 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
188
213
|
$img_uploaded_src,
|
|
189
214
|
$img_width,
|
|
190
215
|
$img_height,
|
|
191
|
-
$scale_attr
|
|
216
|
+
$scale_attr,
|
|
217
|
+
__( 'Enlarged image' )
|
|
192
218
|
)
|
|
193
219
|
);
|
|
194
220
|
$w->next_tag( 'img' );
|
|
195
|
-
$w->set_attribute( 'data-wp-init', 'effects.core.image.
|
|
221
|
+
$w->set_attribute( 'data-wp-init', 'effects.core.image.initOriginImage' );
|
|
196
222
|
$w->set_attribute( 'data-wp-on--load', 'actions.core.image.handleLoad' );
|
|
197
223
|
$w->set_attribute( 'data-wp-effect', 'effects.core.image.setButtonStyles' );
|
|
224
|
+
// We need to set an event callback on the `img` specifically
|
|
225
|
+
// because the `figure` element can also contain a caption, and
|
|
226
|
+
// we don't want to trigger the lightbox when the caption is clicked.
|
|
227
|
+
$w->set_attribute( 'data-wp-on--click', 'actions.core.image.showLightbox' );
|
|
228
|
+
$w->set_attribute( 'data-wp-effect--setStylesOnResize', 'effects.core.image.setStylesOnResize' );
|
|
198
229
|
$body_content = $w->get_updated_html();
|
|
199
230
|
|
|
200
|
-
//
|
|
231
|
+
// Add a button alongside image in the body content.
|
|
201
232
|
$img = null;
|
|
202
233
|
preg_match( '/<img[^>]+>/', $body_content, $img );
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
234
|
+
|
|
235
|
+
$button =
|
|
236
|
+
$img[0]
|
|
237
|
+
. '<button
|
|
238
|
+
type="button"
|
|
239
|
+
aria-haspopup="dialog"
|
|
240
|
+
aria-label="' . esc_attr( $aria_label ) . '"
|
|
241
|
+
data-wp-on--click="actions.core.image.showLightbox"
|
|
242
|
+
data-wp-style--right="context.core.image.imageButtonRight"
|
|
243
|
+
data-wp-style--top="context.core.image.imageButtonTop"
|
|
244
|
+
style="background: #000"
|
|
245
|
+
>
|
|
246
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
|
|
247
|
+
<path d="M9 5H5V9" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
248
|
+
<path d="M15 19L19 19L19 15" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
249
|
+
<path d="M15 5H19V9" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
250
|
+
<path d="M9 19L5 19L5 15" stroke="#FFFFFF" stroke-width="1.5"/>
|
|
251
|
+
</svg>
|
|
252
|
+
</button>';
|
|
253
|
+
|
|
216
254
|
$body_content = preg_replace( '/<img[^>]+>/', $button, $body_content );
|
|
217
255
|
|
|
218
256
|
// We need both a responsive image and an enlarged image to animate
|
|
@@ -220,7 +258,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
220
258
|
// image is a copy of the one in the body, which animates immediately
|
|
221
259
|
// as the lightbox is opened, while the enlarged one is a full-sized
|
|
222
260
|
// version that will likely still be loading as the animation begins.
|
|
223
|
-
$m = new WP_HTML_Tag_Processor( $
|
|
261
|
+
$m = new WP_HTML_Tag_Processor( $block_content );
|
|
224
262
|
$m->next_tag( 'figure' );
|
|
225
263
|
$m->add_class( 'responsive-image' );
|
|
226
264
|
$m->next_tag( 'img' );
|
|
@@ -236,7 +274,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
236
274
|
$m->set_attribute( 'data-wp-style--object-fit', 'selectors.core.image.lightboxObjectFit' );
|
|
237
275
|
$initial_image_content = $m->get_updated_html();
|
|
238
276
|
|
|
239
|
-
$q = new WP_HTML_Tag_Processor( $
|
|
277
|
+
$q = new WP_HTML_Tag_Processor( $block_content );
|
|
240
278
|
$q->next_tag( 'figure' );
|
|
241
279
|
$q->add_class( 'enlarged-image' );
|
|
242
280
|
$q->next_tag( 'img' );
|
|
@@ -252,24 +290,32 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
252
290
|
$q->set_attribute( 'data-wp-style--object-fit', 'selectors.core.image.lightboxObjectFit' );
|
|
253
291
|
$enlarged_image_content = $q->get_updated_html();
|
|
254
292
|
|
|
255
|
-
|
|
293
|
+
// If the current theme does NOT have a `theme.json`, or the colors are not defined,
|
|
294
|
+
// we need to set the background color & close button color to some default values
|
|
295
|
+
// because we can't get them from the Global Styles.
|
|
296
|
+
$background_color = '#fff';
|
|
297
|
+
$close_button_color = '#000';
|
|
298
|
+
if ( wp_theme_has_theme_json() ) {
|
|
299
|
+
$global_styles_color = wp_get_global_styles( array( 'color' ) );
|
|
300
|
+
if ( ! empty( $global_styles_color['background'] ) ) {
|
|
301
|
+
$background_color = esc_attr( $global_styles_color['background'] );
|
|
302
|
+
}
|
|
303
|
+
if ( ! empty( $global_styles_color['text'] ) ) {
|
|
304
|
+
$close_button_color = esc_attr( $global_styles_color['text'] );
|
|
305
|
+
}
|
|
306
|
+
}
|
|
256
307
|
|
|
257
308
|
$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="15" height="15" 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>';
|
|
258
|
-
$close_button_color = esc_attr( wp_get_global_styles( array( 'color', 'text' ) ) );
|
|
259
|
-
$dialog_label = $alt_attribute ? esc_attr( $alt_attribute ) : esc_attr__( 'Image' );
|
|
260
309
|
$close_button_label = esc_attr__( 'Close' );
|
|
261
310
|
|
|
262
311
|
$lightbox_html = <<<HTML
|
|
263
312
|
<div data-wp-body="" class="wp-lightbox-overlay $lightbox_animation"
|
|
264
313
|
data-wp-bind--role="selectors.core.image.roleAttribute"
|
|
265
|
-
aria-label="
|
|
314
|
+
data-wp-bind--aria-label="selectors.core.image.dialogLabel"
|
|
266
315
|
data-wp-class--initialized="context.core.image.initialized"
|
|
267
316
|
data-wp-class--active="context.core.image.lightboxEnabled"
|
|
268
317
|
data-wp-class--hideAnimationEnabled="context.core.image.hideAnimationEnabled"
|
|
269
|
-
data-wp-bind--aria-
|
|
270
|
-
aria-hidden="true"
|
|
271
|
-
data-wp-bind--aria-modal="context.core.image.lightboxEnabled"
|
|
272
|
-
aria-modal="false"
|
|
318
|
+
data-wp-bind--aria-modal="selectors.core.image.ariaModal"
|
|
273
319
|
data-wp-effect="effects.core.image.initLightbox"
|
|
274
320
|
data-wp-on--keydown="actions.core.image.handleKeydown"
|
|
275
321
|
data-wp-on--touchstart="actions.core.image.handleTouchStart"
|
|
@@ -282,7 +328,7 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
282
328
|
</button>
|
|
283
329
|
<div class="lightbox-image-container">$initial_image_content</div>
|
|
284
330
|
<div class="lightbox-image-container">$enlarged_image_content</div>
|
|
285
|
-
<div class="scrim" style="background-color: $background_color"></div>
|
|
331
|
+
<div class="scrim" style="background-color: $background_color" aria-hidden="true"></div>
|
|
286
332
|
</div>
|
|
287
333
|
HTML;
|
|
288
334
|
|
|
@@ -290,7 +336,7 @@ HTML;
|
|
|
290
336
|
}
|
|
291
337
|
|
|
292
338
|
/**
|
|
293
|
-
*
|
|
339
|
+
* Ensures that the view script has the `wp-interactivity` dependency.
|
|
294
340
|
*
|
|
295
341
|
* @since 6.4.0
|
|
296
342
|
*
|
package/src/image/style.scss
CHANGED
|
@@ -154,21 +154,53 @@
|
|
|
154
154
|
|
|
155
155
|
.wp-lightbox-container {
|
|
156
156
|
position: relative;
|
|
157
|
+
display: flex;
|
|
158
|
+
flex-direction: column;
|
|
159
|
+
|
|
160
|
+
img {
|
|
161
|
+
cursor: zoom-in;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
img:hover + button {
|
|
165
|
+
opacity: 1;
|
|
166
|
+
}
|
|
157
167
|
|
|
158
168
|
button {
|
|
169
|
+
opacity: 0;
|
|
159
170
|
border: none;
|
|
160
|
-
background:
|
|
171
|
+
background: #000;
|
|
161
172
|
cursor: zoom-in;
|
|
162
|
-
width:
|
|
163
|
-
height:
|
|
173
|
+
width: 24px;
|
|
174
|
+
height: 24px;
|
|
164
175
|
position: absolute;
|
|
165
176
|
z-index: 100;
|
|
177
|
+
top: 10px;
|
|
178
|
+
right: 10px;
|
|
179
|
+
text-align: center;
|
|
180
|
+
padding: 0;
|
|
181
|
+
border-radius: 10%;
|
|
166
182
|
|
|
167
183
|
&:focus-visible {
|
|
168
184
|
outline: 5px auto #212121;
|
|
169
185
|
outline: 5px auto -webkit-focus-ring-color;
|
|
170
186
|
outline-offset: 5px;
|
|
171
187
|
}
|
|
188
|
+
|
|
189
|
+
&:hover {
|
|
190
|
+
cursor: pointer;
|
|
191
|
+
opacity: 1;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
&:focus {
|
|
195
|
+
opacity: 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
&:hover,
|
|
199
|
+
&:focus,
|
|
200
|
+
&:not(:hover):not(:active):not(.has-background) {
|
|
201
|
+
background: #000;
|
|
202
|
+
border: none;
|
|
203
|
+
}
|
|
172
204
|
}
|
|
173
205
|
}
|
|
174
206
|
|
|
@@ -186,11 +218,23 @@
|
|
|
186
218
|
|
|
187
219
|
.close-button {
|
|
188
220
|
position: absolute;
|
|
189
|
-
top: calc(env(safe-area-inset-top) +
|
|
190
|
-
right: calc(env(safe-area-inset-right) +
|
|
221
|
+
top: calc(env(safe-area-inset-top) + 16px); // equivalent to $grid-unit-20
|
|
222
|
+
right: calc(env(safe-area-inset-right) + 16px); // equivalent to $grid-unit-20
|
|
191
223
|
padding: 0;
|
|
192
224
|
cursor: pointer;
|
|
193
225
|
z-index: 5000000;
|
|
226
|
+
min-width: 40px; // equivalent to $button-size-next-default-40px
|
|
227
|
+
min-height: 40px; // equivalent to $button-size-next-default-40px
|
|
228
|
+
display: flex;
|
|
229
|
+
align-items: center;
|
|
230
|
+
justify-content: center;
|
|
231
|
+
|
|
232
|
+
&:hover,
|
|
233
|
+
&:focus,
|
|
234
|
+
&:not(:hover):not(:active):not(.has-background) {
|
|
235
|
+
background: none;
|
|
236
|
+
border: none;
|
|
237
|
+
}
|
|
194
238
|
}
|
|
195
239
|
|
|
196
240
|
.lightbox-image-container {
|