components
1 year ago
css
2 years ago
attributes.js
3 years ago
block.js
1 year ago
deprecated.js
3 years ago
edit.js
2 years ago
editor.scss
1 year ago
element-icons.js
2 years ago
markformat.js
4 years ago
save.js
4 years ago
transforms.js
1 year ago
edit.js
110 lines
| 1 | import './markformat'; |
| 2 | import { applyFilters } from '@wordpress/hooks'; |
| 3 | import BlockControls from './components/BlockControls'; |
| 4 | import { Fragment, useEffect, useRef } from '@wordpress/element'; |
| 5 | import InspectorAdvancedControls from './components/InspectorAdvancedControls'; |
| 6 | import GoogleFontLink from '../../components/google-font-link'; |
| 7 | import ComponentCSS from './components/ComponentCSS'; |
| 8 | import { createBlock } from '@wordpress/blocks'; |
| 9 | import { compose } from '@wordpress/compose'; |
| 10 | import { withDeviceType, withUniqueId } from '../../hoc'; |
| 11 | import withDynamicContent from '../../extend/dynamic-content/hoc/withDynamicContent'; |
| 12 | import HeadlineContentRenderer from './components/HeadlineContentRenderer'; |
| 13 | import { withBlockContext } from '../../block-context'; |
| 14 | import GenerateBlocksInspectorControls from '../../extend/inspector-control'; |
| 15 | import withHeadlineLegacyMigration from '../../hoc/withHeadlineLegacyMigration'; |
| 16 | import getDeviceType from '../../utils/get-device-type'; |
| 17 | import withSetAttributes from '../../hoc/withSetAttributes'; |
| 18 | |
| 19 | const onSplit = ( attributes, clientId ) => ( ( value, isOriginal ) => { |
| 20 | let block; |
| 21 | |
| 22 | if ( isOriginal || value ) { |
| 23 | block = createBlock( 'generateblocks/headline', { |
| 24 | ...attributes, |
| 25 | content: value, |
| 26 | } ); |
| 27 | } else { |
| 28 | block = createBlock( 'core/paragraph' ); |
| 29 | } |
| 30 | |
| 31 | if ( isOriginal ) { |
| 32 | block.clientId = clientId; |
| 33 | } |
| 34 | |
| 35 | return block; |
| 36 | } ); |
| 37 | |
| 38 | const HeadlineEdit = ( props ) => { |
| 39 | const { |
| 40 | attributes, |
| 41 | setAttributes, |
| 42 | ContentRenderer = HeadlineContentRenderer, |
| 43 | context, |
| 44 | } = props; |
| 45 | |
| 46 | const { |
| 47 | anchor, |
| 48 | typography, |
| 49 | googleFont, |
| 50 | googleFontVariants, |
| 51 | icon, |
| 52 | hasIcon, |
| 53 | isBlockPreview = false, |
| 54 | } = attributes; |
| 55 | |
| 56 | const ref = useRef( null ); |
| 57 | const deviceType = getDeviceType(); |
| 58 | |
| 59 | useEffect( () => { |
| 60 | if ( ! hasIcon && icon ) { |
| 61 | setAttributes( { hasIcon: true } ); |
| 62 | } |
| 63 | }, [] ); |
| 64 | |
| 65 | return ( |
| 66 | <Fragment> |
| 67 | <BlockControls |
| 68 | attributes={ attributes } |
| 69 | setAttributes={ setAttributes } |
| 70 | context={ context } |
| 71 | /> |
| 72 | |
| 73 | <GenerateBlocksInspectorControls |
| 74 | attributes={ attributes } |
| 75 | setAttributes={ setAttributes } |
| 76 | > |
| 77 | { applyFilters( 'generateblocks.editor.settingsPanel', undefined, { ...props, device: deviceType } ) } |
| 78 | </GenerateBlocksInspectorControls> |
| 79 | |
| 80 | <InspectorAdvancedControls |
| 81 | anchor={ anchor } |
| 82 | setAttributes={ setAttributes } |
| 83 | attributes={ attributes } |
| 84 | /> |
| 85 | |
| 86 | <ComponentCSS { ...props } deviceType={ deviceType } /> |
| 87 | |
| 88 | <GoogleFontLink |
| 89 | fontFamily={ typography.fontFamily } |
| 90 | googleFont={ googleFont } |
| 91 | googleFontVariants={ googleFontVariants } |
| 92 | isBlockPreview={ isBlockPreview } |
| 93 | /> |
| 94 | |
| 95 | { applyFilters( 'generateblocks.editor.beforeHeadlineElement', '', props ) } |
| 96 | |
| 97 | <ContentRenderer { ...props } onSplit={ onSplit } headlineRef={ ref } /> |
| 98 | </Fragment> |
| 99 | ); |
| 100 | }; |
| 101 | |
| 102 | export default compose( |
| 103 | withSetAttributes, |
| 104 | withDeviceType, |
| 105 | withBlockContext, |
| 106 | withDynamicContent, |
| 107 | withUniqueId, |
| 108 | withHeadlineLegacyMigration |
| 109 | )( HeadlineEdit ); |
| 110 |