components
1 year ago
css
2 years ago
attributes.js
1 year ago
edit.js
2 years ago
editor.scss
3 years ago
index.js
1 year ago
save.js
4 years ago
transforms.js
1 year ago
index.js
59 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { registerBlockType } from '@wordpress/blocks'; |
| 5 | import { __ } from '@wordpress/i18n'; |
| 6 | |
| 7 | /** |
| 8 | * Internal dependencies |
| 9 | */ |
| 10 | import edit from './edit'; |
| 11 | import save from './save'; |
| 12 | import transforms from './transforms'; |
| 13 | import dynamicContentAttributes from '../../extend/dynamic-content/attributes'; |
| 14 | import getIcon from '../../utils/get-icon'; |
| 15 | import { getBlockAttributes } from '../../block-context'; |
| 16 | import imageContext from '../../block-context/image'; |
| 17 | import blockAttributes from './attributes'; |
| 18 | |
| 19 | const attributes = Object.assign( |
| 20 | {}, |
| 21 | getBlockAttributes( blockAttributes, imageContext, generateBlocksDefaults.image ), |
| 22 | dynamicContentAttributes |
| 23 | ); |
| 24 | |
| 25 | registerBlockType( 'generateblocks/image', { |
| 26 | apiVersion: 3, |
| 27 | title: __( 'Image', 'generateblocks' ), |
| 28 | category: 'generateblocks', |
| 29 | description: __( 'Add images to your content to make a visual statement.', 'generateblocks' ), |
| 30 | icon: getIcon( 'image' ), |
| 31 | attributes, |
| 32 | edit, |
| 33 | save, |
| 34 | transforms, |
| 35 | __experimentalLabel: ( attrs, { context } ) => { |
| 36 | const customName = attrs?.metadata?.name; |
| 37 | |
| 38 | if ( 'list-view' === context && customName ) { |
| 39 | return customName; |
| 40 | } |
| 41 | |
| 42 | if ( |
| 43 | context === 'list-view' && |
| 44 | ! attrs.useDynamicData && |
| 45 | ( attrs.alt || attrs.title ) |
| 46 | ) { |
| 47 | return attrs.alt || attrs.title; |
| 48 | } |
| 49 | |
| 50 | return __( 'Image', 'generateblocks' ); |
| 51 | }, |
| 52 | usesContext: [ 'postId', 'postType' ], |
| 53 | supports: { |
| 54 | className: false, |
| 55 | customClassName: true, |
| 56 | html: false, |
| 57 | }, |
| 58 | } ); |
| 59 |