@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
package/src/image/image.js
CHANGED
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
MediaReplaceFlow,
|
|
26
26
|
store as blockEditorStore,
|
|
27
27
|
useSettings,
|
|
28
|
-
BlockAlignmentControl,
|
|
29
28
|
__experimentalImageEditor as ImageEditor,
|
|
30
29
|
__experimentalGetElementClassName,
|
|
31
30
|
__experimentalUseBorderProps as useBorderProps,
|
|
@@ -83,9 +82,29 @@ const scaleOptions = [
|
|
|
83
82
|
},
|
|
84
83
|
];
|
|
85
84
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
// If the image has a href, wrap in an <a /> tag to trigger any inherited link element styles.
|
|
86
|
+
const ImageWrapper = ( { href, children } ) => {
|
|
87
|
+
if ( ! href ) {
|
|
88
|
+
return children;
|
|
89
|
+
}
|
|
90
|
+
return (
|
|
91
|
+
<a
|
|
92
|
+
href={ href }
|
|
93
|
+
onClick={ ( event ) => event.preventDefault() }
|
|
94
|
+
aria-disabled={ true }
|
|
95
|
+
style={ {
|
|
96
|
+
// When the Image block is linked,
|
|
97
|
+
// it's wrapped with a disabled <a /> tag.
|
|
98
|
+
// Restore cursor style so it doesn't appear 'clickable'
|
|
99
|
+
// and remove pointer events. Safari needs the display property.
|
|
100
|
+
pointerEvents: 'none',
|
|
101
|
+
cursor: 'default',
|
|
102
|
+
display: 'inline',
|
|
103
|
+
} }
|
|
104
|
+
>
|
|
105
|
+
{ children }
|
|
106
|
+
</a>
|
|
107
|
+
);
|
|
89
108
|
};
|
|
90
109
|
|
|
91
110
|
export default function Image( {
|
|
@@ -333,21 +352,6 @@ export default function Image( {
|
|
|
333
352
|
} );
|
|
334
353
|
}
|
|
335
354
|
|
|
336
|
-
function updateAlignment( nextAlign ) {
|
|
337
|
-
const extraUpdatedAttributes = [ 'wide', 'full' ].includes( nextAlign )
|
|
338
|
-
? {
|
|
339
|
-
width: undefined,
|
|
340
|
-
height: undefined,
|
|
341
|
-
aspectRatio: undefined,
|
|
342
|
-
scale: undefined,
|
|
343
|
-
}
|
|
344
|
-
: {};
|
|
345
|
-
setAttributes( {
|
|
346
|
-
...extraUpdatedAttributes,
|
|
347
|
-
align: nextAlign,
|
|
348
|
-
} );
|
|
349
|
-
}
|
|
350
|
-
|
|
351
355
|
useEffect( () => {
|
|
352
356
|
if ( ! isSelected ) {
|
|
353
357
|
setIsEditingImage( false );
|
|
@@ -435,12 +439,6 @@ export default function Image( {
|
|
|
435
439
|
const controls = (
|
|
436
440
|
<>
|
|
437
441
|
<BlockControls group="block">
|
|
438
|
-
{ hasNonContentControls && (
|
|
439
|
-
<BlockAlignmentControl
|
|
440
|
-
value={ align }
|
|
441
|
-
onChange={ updateAlignment }
|
|
442
|
-
/>
|
|
443
|
-
) }
|
|
444
442
|
{ hasNonContentControls && (
|
|
445
443
|
<ToolbarButton
|
|
446
444
|
onClick={ () => {
|
|
@@ -653,25 +651,31 @@ export default function Image( {
|
|
|
653
651
|
|
|
654
652
|
if ( canEditImage && isEditingImage ) {
|
|
655
653
|
img = (
|
|
656
|
-
<
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
654
|
+
<ImageWrapper href={ href }>
|
|
655
|
+
<ImageEditor
|
|
656
|
+
id={ id }
|
|
657
|
+
url={ url }
|
|
658
|
+
width={ numericWidth }
|
|
659
|
+
height={ numericHeight }
|
|
660
|
+
clientWidth={ fallbackClientWidth }
|
|
661
|
+
naturalHeight={ naturalHeight }
|
|
662
|
+
naturalWidth={ naturalWidth }
|
|
663
|
+
onSaveImage={ ( imageAttributes ) =>
|
|
664
|
+
setAttributes( imageAttributes )
|
|
665
|
+
}
|
|
666
|
+
onFinishEditing={ () => {
|
|
667
|
+
setIsEditingImage( false );
|
|
668
|
+
} }
|
|
669
|
+
borderProps={ isRounded ? undefined : borderProps }
|
|
670
|
+
/>
|
|
671
|
+
</ImageWrapper>
|
|
672
672
|
);
|
|
673
673
|
} else if ( ! isResizable ) {
|
|
674
|
-
img =
|
|
674
|
+
img = (
|
|
675
|
+
<div style={ { width, height, aspectRatio } }>
|
|
676
|
+
<ImageWrapper href={ href }>{ img }</ImageWrapper>
|
|
677
|
+
</div>
|
|
678
|
+
);
|
|
675
679
|
} else {
|
|
676
680
|
const numericRatio = aspectRatio && evalAspectRatio( aspectRatio );
|
|
677
681
|
const customRatio = numericWidth / numericHeight;
|
|
@@ -774,7 +778,7 @@ export default function Image( {
|
|
|
774
778
|
} }
|
|
775
779
|
resizeRatio={ align === 'center' ? 2 : 1 }
|
|
776
780
|
>
|
|
777
|
-
{ img }
|
|
781
|
+
<ImageWrapper href={ href }>{ img }</ImageWrapper>
|
|
778
782
|
</ResizableBox>
|
|
779
783
|
);
|
|
780
784
|
}
|
|
@@ -788,14 +792,7 @@ export default function Image( {
|
|
|
788
792
|
{ /* Hide controls during upload to avoid component remount,
|
|
789
793
|
which causes duplicated image upload. */ }
|
|
790
794
|
{ ! temporaryURL && controls }
|
|
791
|
-
{
|
|
792
|
-
{ !! href ? (
|
|
793
|
-
<a href={ href } { ...disabledClickProps }>
|
|
794
|
-
{ img }
|
|
795
|
-
</a>
|
|
796
|
-
) : (
|
|
797
|
-
img
|
|
798
|
-
) }
|
|
795
|
+
{ img }
|
|
799
796
|
{ showCaption &&
|
|
800
797
|
( ! RichText.isEmpty( caption ) || isSelected ) && (
|
|
801
798
|
<RichText
|
package/src/image/index.php
CHANGED
|
@@ -37,6 +37,7 @@ function render_block_core_image( $attributes, $content, $block ) {
|
|
|
37
37
|
$link_destination = isset( $attributes['linkDestination'] ) ? $attributes['linkDestination'] : 'none';
|
|
38
38
|
$lightbox_settings = block_core_image_get_lightbox_settings( $block->parsed_block );
|
|
39
39
|
|
|
40
|
+
$is_gutenberg_plugin = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
|
|
40
41
|
$view_js_file_handle = 'wp-block-image-view';
|
|
41
42
|
$script_handles = $block->block_type->view_script_handles;
|
|
42
43
|
|
|
@@ -50,9 +51,11 @@ function render_block_core_image( $attributes, $content, $block ) {
|
|
|
50
51
|
isset( $lightbox_settings['enabled'] ) &&
|
|
51
52
|
true === $lightbox_settings['enabled']
|
|
52
53
|
) {
|
|
53
|
-
$
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if ( $is_gutenberg_plugin ) {
|
|
55
|
+
gutenberg_enqueue_module( '@wordpress/block-library/image' );
|
|
56
|
+
// Remove the view script because we are using the module.
|
|
57
|
+
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) );
|
|
58
|
+
} elseif ( ! in_array( $view_js_file_handle, $script_handles, true ) ) {
|
|
56
59
|
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_js_file_handle ) );
|
|
57
60
|
}
|
|
58
61
|
|
|
@@ -71,6 +74,7 @@ function render_block_core_image( $attributes, $content, $block ) {
|
|
|
71
74
|
* other Image blocks.
|
|
72
75
|
*/
|
|
73
76
|
remove_filter( 'render_block_core/image', 'block_core_image_render_lightbox', 15 );
|
|
77
|
+
|
|
74
78
|
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
|
|
75
79
|
if ( in_array( $view_js_file_handle, $script_handles, true ) ) {
|
|
76
80
|
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_js_file_handle ) );
|
|
@@ -187,27 +191,23 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
187
191
|
$w = new WP_HTML_Tag_Processor( $block_content );
|
|
188
192
|
$w->next_tag( 'figure' );
|
|
189
193
|
$w->add_class( 'wp-lightbox-container' );
|
|
190
|
-
$w->set_attribute( 'data-wp-interactive',
|
|
194
|
+
$w->set_attribute( 'data-wp-interactive', '{"namespace":"core/image"}' );
|
|
191
195
|
|
|
192
196
|
$w->set_attribute(
|
|
193
197
|
'data-wp-context',
|
|
194
198
|
sprintf(
|
|
195
|
-
'{
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
"scaleAttr": "%s",
|
|
208
|
-
"dialogLabel": "%s"
|
|
209
|
-
}
|
|
210
|
-
}
|
|
199
|
+
'{ "imageLoaded": false,
|
|
200
|
+
"initialized": false,
|
|
201
|
+
"lightboxEnabled": false,
|
|
202
|
+
"hideAnimationEnabled": false,
|
|
203
|
+
"preloadInitialized": false,
|
|
204
|
+
"lightboxAnimation": "%s",
|
|
205
|
+
"imageUploadedSrc": "%s",
|
|
206
|
+
"imageCurrentSrc": "",
|
|
207
|
+
"targetWidth": "%s",
|
|
208
|
+
"targetHeight": "%s",
|
|
209
|
+
"scaleAttr": "%s",
|
|
210
|
+
"dialogLabel": "%s"
|
|
211
211
|
}',
|
|
212
212
|
$lightbox_animation,
|
|
213
213
|
$img_uploaded_src,
|
|
@@ -218,14 +218,14 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
218
218
|
)
|
|
219
219
|
);
|
|
220
220
|
$w->next_tag( 'img' );
|
|
221
|
-
$w->set_attribute( 'data-wp-init', '
|
|
222
|
-
$w->set_attribute( 'data-wp-on--load', 'actions.
|
|
223
|
-
$w->set_attribute( 'data-wp-
|
|
221
|
+
$w->set_attribute( 'data-wp-init', 'callbacks.initOriginImage' );
|
|
222
|
+
$w->set_attribute( 'data-wp-on--load', 'actions.handleLoad' );
|
|
223
|
+
$w->set_attribute( 'data-wp-watch', 'callbacks.setButtonStyles' );
|
|
224
224
|
// We need to set an event callback on the `img` specifically
|
|
225
225
|
// because the `figure` element can also contain a caption, and
|
|
226
226
|
// we don't want to trigger the lightbox when the caption is clicked.
|
|
227
|
-
$w->set_attribute( 'data-wp-on--click', 'actions.
|
|
228
|
-
$w->set_attribute( 'data-wp-
|
|
227
|
+
$w->set_attribute( 'data-wp-on--click', 'actions.showLightbox' );
|
|
228
|
+
$w->set_attribute( 'data-wp-watch--setStylesOnResize', 'callbacks.setStylesOnResize' );
|
|
229
229
|
$body_content = $w->get_updated_html();
|
|
230
230
|
|
|
231
231
|
// Add a button alongside image in the body content.
|
|
@@ -239,13 +239,12 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
239
239
|
type="button"
|
|
240
240
|
aria-haspopup="dialog"
|
|
241
241
|
aria-label="' . esc_attr( $aria_label ) . '"
|
|
242
|
-
data-wp-on--click="actions.
|
|
243
|
-
data-wp-style--right="context.
|
|
244
|
-
data-wp-style--top="context.
|
|
245
|
-
style="background: #000"
|
|
242
|
+
data-wp-on--click="actions.showLightbox"
|
|
243
|
+
data-wp-style--right="context.imageButtonRight"
|
|
244
|
+
data-wp-style--top="context.imageButtonTop"
|
|
246
245
|
>
|
|
247
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
248
|
-
<
|
|
246
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
|
|
247
|
+
<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
|
|
249
248
|
</svg>
|
|
250
249
|
</button>';
|
|
251
250
|
|
|
@@ -268,8 +267,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
268
267
|
// use the exact same image as in the content when the lightbox is first opened while
|
|
269
268
|
// we wait for the larger image to load.
|
|
270
269
|
$m->set_attribute( 'src', '' );
|
|
271
|
-
$m->set_attribute( 'data-wp-bind--src', 'context.
|
|
272
|
-
$m->set_attribute( 'data-wp-style--object-fit', '
|
|
270
|
+
$m->set_attribute( 'data-wp-bind--src', 'context.imageCurrentSrc' );
|
|
271
|
+
$m->set_attribute( 'data-wp-style--object-fit', 'state.lightboxObjectFit' );
|
|
273
272
|
$initial_image_content = $m->get_updated_html();
|
|
274
273
|
|
|
275
274
|
$q = new WP_HTML_Tag_Processor( $block_content );
|
|
@@ -284,8 +283,8 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
284
283
|
// and Chrome (see https://github.com/WordPress/gutenberg/pull/52765#issuecomment-1674008151). Until that
|
|
285
284
|
// is resolved, manually setting the 'src' seems to be the best solution to load the large image on demand.
|
|
286
285
|
$q->set_attribute( 'src', '' );
|
|
287
|
-
$q->set_attribute( 'data-wp-bind--src', '
|
|
288
|
-
$q->set_attribute( 'data-wp-style--object-fit', '
|
|
286
|
+
$q->set_attribute( 'data-wp-bind--src', 'state.enlargedImgSrc' );
|
|
287
|
+
$q->set_attribute( 'data-wp-style--object-fit', 'state.lightboxObjectFit' );
|
|
289
288
|
$enlarged_image_content = $q->get_updated_html();
|
|
290
289
|
|
|
291
290
|
// If the current theme does NOT have a `theme.json`, or the colors are not defined,
|
|
@@ -303,26 +302,26 @@ function block_core_image_render_lightbox( $block_content, $block ) {
|
|
|
303
302
|
}
|
|
304
303
|
}
|
|
305
304
|
|
|
306
|
-
$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="
|
|
305
|
+
$close_button_icon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" 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>';
|
|
307
306
|
$close_button_label = esc_attr__( 'Close' );
|
|
308
307
|
|
|
309
308
|
$lightbox_html = <<<HTML
|
|
310
309
|
<div data-wp-body="" class="wp-lightbox-overlay $lightbox_animation"
|
|
311
|
-
data-wp-bind--role="
|
|
312
|
-
data-wp-bind--aria-label="
|
|
313
|
-
data-wp-class--initialized="context.
|
|
314
|
-
data-wp-class--active="context.
|
|
315
|
-
data-wp-class--hideAnimationEnabled="context.
|
|
316
|
-
data-wp-bind--aria-modal="
|
|
317
|
-
data-wp-
|
|
318
|
-
data-wp-on--keydown="actions.
|
|
319
|
-
data-wp-on--touchstart="actions.
|
|
320
|
-
data-wp-on--touchmove="actions.
|
|
321
|
-
data-wp-on--touchend="actions.
|
|
322
|
-
data-wp-on--click="actions.
|
|
310
|
+
data-wp-bind--role="state.roleAttribute"
|
|
311
|
+
data-wp-bind--aria-label="state.dialogLabel"
|
|
312
|
+
data-wp-class--initialized="context.initialized"
|
|
313
|
+
data-wp-class--active="context.lightboxEnabled"
|
|
314
|
+
data-wp-class--hideAnimationEnabled="context.hideAnimationEnabled"
|
|
315
|
+
data-wp-bind--aria-modal="state.ariaModal"
|
|
316
|
+
data-wp-watch="callbacks.initLightbox"
|
|
317
|
+
data-wp-on--keydown="actions.handleKeydown"
|
|
318
|
+
data-wp-on--touchstart="actions.handleTouchStart"
|
|
319
|
+
data-wp-on--touchmove="actions.handleTouchMove"
|
|
320
|
+
data-wp-on--touchend="actions.handleTouchEnd"
|
|
321
|
+
data-wp-on--click="actions.hideLightbox"
|
|
323
322
|
tabindex="-1"
|
|
324
323
|
>
|
|
325
|
-
<button type="button" aria-label="$close_button_label" style="fill: $close_button_color" class="close-button" data-wp-on--click="actions.
|
|
324
|
+
<button type="button" aria-label="$close_button_label" style="fill: $close_button_color" class="close-button" data-wp-on--click="actions.hideLightbox">
|
|
326
325
|
$close_button_icon
|
|
327
326
|
</button>
|
|
328
327
|
<div class="lightbox-image-container">$initial_image_content</div>
|
|
@@ -363,5 +362,14 @@ function register_block_core_image() {
|
|
|
363
362
|
'render_callback' => 'render_block_core_image',
|
|
364
363
|
)
|
|
365
364
|
);
|
|
365
|
+
|
|
366
|
+
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
|
|
367
|
+
gutenberg_register_module(
|
|
368
|
+
'@wordpress/block-library/image',
|
|
369
|
+
gutenberg_url( '/build/interactivity/image.min.js' ),
|
|
370
|
+
array( '@wordpress/interactivity' ),
|
|
371
|
+
defined( 'GUTENBERG_VERSION' ) ? GUTENBERG_VERSION : get_bloginfo( 'version' )
|
|
372
|
+
);
|
|
373
|
+
}
|
|
366
374
|
}
|
|
367
375
|
add_action( 'init', 'register_block_core_image' );
|
package/src/image/style.scss
CHANGED
|
@@ -168,22 +168,27 @@
|
|
|
168
168
|
button {
|
|
169
169
|
opacity: 0;
|
|
170
170
|
border: none;
|
|
171
|
-
background:
|
|
171
|
+
background-color: rgb(90 90 90 / 25%);
|
|
172
|
+
backdrop-filter: blur($grid-unit-20) saturate(180%);
|
|
172
173
|
cursor: zoom-in;
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
display: flex;
|
|
175
|
+
justify-content: center;
|
|
176
|
+
align-items: center;
|
|
177
|
+
width: 20px;
|
|
178
|
+
height: 20px;
|
|
175
179
|
position: absolute;
|
|
176
180
|
z-index: 100;
|
|
177
|
-
top:
|
|
178
|
-
right:
|
|
181
|
+
top: 16px;
|
|
182
|
+
right: 16px;
|
|
179
183
|
text-align: center;
|
|
180
184
|
padding: 0;
|
|
181
|
-
border-radius:
|
|
185
|
+
border-radius: 4px;
|
|
186
|
+
transition: opacity 0.2s ease;
|
|
182
187
|
|
|
183
188
|
&:focus-visible {
|
|
184
|
-
outline:
|
|
185
|
-
outline:
|
|
186
|
-
outline-offset:
|
|
189
|
+
outline: 3px auto rgb(90 90 90 / 25%);
|
|
190
|
+
outline: 3px auto -webkit-focus-ring-color;
|
|
191
|
+
outline-offset: 3px;
|
|
187
192
|
}
|
|
188
193
|
|
|
189
194
|
&:hover {
|
|
@@ -198,7 +203,7 @@
|
|
|
198
203
|
&:hover,
|
|
199
204
|
&:focus,
|
|
200
205
|
&:not(:hover):not(:active):not(.has-background) {
|
|
201
|
-
background:
|
|
206
|
+
background-color: rgb(90 90 90 / 25%);
|
|
202
207
|
border: none;
|
|
203
208
|
}
|
|
204
209
|
}
|
|
@@ -210,7 +215,7 @@
|
|
|
210
215
|
left: 0;
|
|
211
216
|
z-index: 100000;
|
|
212
217
|
overflow: hidden;
|
|
213
|
-
width:
|
|
218
|
+
width: 100%;
|
|
214
219
|
height: 100vh;
|
|
215
220
|
box-sizing: border-box;
|
|
216
221
|
visibility: hidden;
|
|
@@ -367,7 +372,7 @@
|
|
|
367
372
|
|
|
368
373
|
@keyframes lightbox-zoom-in {
|
|
369
374
|
0% {
|
|
370
|
-
transform: translate(calc(-
|
|
375
|
+
transform: translate(calc((-100vw + var(--wp--lightbox-scrollbar-width)) / 2 + var(--wp--lightbox-initial-left-position)), calc(-50vh + var(--wp--lightbox-initial-top-position))) scale(var(--wp--lightbox-scale));
|
|
371
376
|
}
|
|
372
377
|
100% {
|
|
373
378
|
transform: translate(-50%, -50%) scale(1, 1);
|
|
@@ -384,6 +389,6 @@
|
|
|
384
389
|
}
|
|
385
390
|
100% {
|
|
386
391
|
visibility: hidden;
|
|
387
|
-
transform: translate(calc(-
|
|
392
|
+
transform: translate(calc((-100vw + var(--wp--lightbox-scrollbar-width)) / 2 + var(--wp--lightbox-initial-left-position)), calc(-50vh + var(--wp--lightbox-initial-top-position))) scale(var(--wp--lightbox-scale));
|
|
388
393
|
}
|
|
389
394
|
}
|