PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / blocks / image / components / Image.js
generateblocks / src / blocks / image / components Last commit date
inspector-controls 2 years ago AlignmentControls.js 4 years ago AnchorTag.js 4 years ago BlockControls.js 2 years ago ComponentCSS.js 1 year ago Image.js 4 years ago ImageContentRenderer.js 3 years ago ImagePlaceholder.js 4 years ago
Image.js
85 lines
1 import { InnerBlocks, BlockContextProvider } from '@wordpress/block-editor';
2 import AnchorTag from './AnchorTag';
3 import classnames from 'classnames';
4 import { applyFilters } from '@wordpress/hooks';
5 import { Spinner } from '@wordpress/components';
6
7 export default function Image( props ) {
8 const {
9 src,
10 alt,
11 title,
12 anchorAttributes,
13 imageRef,
14 setLoadedNaturalSize,
15 naturalWidth,
16 naturalHeight,
17 attributes,
18 temporaryURL,
19 } = props;
20
21 const {
22 uniqueId,
23 anchor,
24 mediaId,
25 dynamicImage,
26 useDynamicData,
27 className,
28 align,
29 } = attributes;
30
31 const htmlAttributes = applyFilters(
32 'generateblocks.frontend.htmlAttributes',
33 {
34 className: classnames( {
35 'gb-image': true,
36 [ `gb-image-${ uniqueId }` ]: true,
37 [ `${ className }` ]: undefined !== className,
38 [ `align${ align }` ]: '' !== align,
39 } ),
40 id: anchor ? anchor : null,
41 width: naturalWidth,
42 height: naturalHeight,
43 src: temporaryURL || src,
44 alt,
45 title,
46 },
47 'generateblocks/image',
48 attributes
49 );
50
51 /* eslint-disable jsx-a11y/alt-text */
52 // The alt tag below is added via htmlAttributes.
53
54 return (
55 <>
56 <AnchorTag { ...anchorAttributes }>
57 <img
58 { ...htmlAttributes }
59 ref={ imageRef }
60 onLoad={ ( event ) => {
61 setLoadedNaturalSize( {
62 loadedNaturalWidth: event.target?.naturalWidth,
63 loadedNaturalHeight: event.target?.naturalHeight,
64 } );
65 } }
66 />
67
68 { temporaryURL && <Spinner /> }
69 </AnchorTag>
70
71 <BlockContextProvider value={ {
72 'generateblocks/dynamicImage': useDynamicData ? parseInt( dynamicImage ) : false,
73 'generateblocks/mediaId': ! useDynamicData ? mediaId : false,
74 } }>
75 <InnerBlocks
76 allowedBlocks={ [ 'generateblocks/headline' ] }
77 renderAppender={ false }
78 />
79 </BlockContextProvider>
80 </>
81 );
82
83 /* eslint-enable jsx-a11y/alt-text */
84 }
85