-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jetpack AI Image: add button entrypoint on the image block (#38123)
* Add button to trigger general purpose image generation * Fix button positioning * Let media button follow the same margin/padding rule of other buttons * Fix issue when the selection should be multiple * Move the AI button to it's own component file * Do not add the button when it's a featured image generation * Only support AI button on specific blocks * Add new placement const for the new button * Add media source specific to render general purpose image for blocks * Trigger the general image for block when the button is clicked * Rename original component to follow pattern and refer to media source placement * changelog * Only show the button when the beta extensions are enabled :| --------- Co-authored-by: Douglas <douglas.henri@automattic.com>
- Loading branch information
1 parent
73d2664
commit b556b8f
Showing
10 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-jetpack-ai-image-image-block-entrypoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: other | ||
|
||
Jetpack AI Image: include new entrypoint as a button on the image/gallery/slideshow block. |
9 changes: 7 additions & 2 deletions
9
projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/ai-image/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import FeaturedImage from './featured-image'; | ||
import GeneralPurposeImage from './general-purpose-image'; | ||
import { PLACEMENT_MEDIA_SOURCE_DROPDOWN } from './types'; | ||
import { PLACEMENT_MEDIA_SOURCE_DROPDOWN, PLACEMENT_BLOCK_PLACEHOLDER_BUTTON } from './types'; | ||
|
||
export { FeaturedImage, PLACEMENT_MEDIA_SOURCE_DROPDOWN, GeneralPurposeImage }; | ||
export { | ||
FeaturedImage, | ||
PLACEMENT_MEDIA_SOURCE_DROPDOWN, | ||
PLACEMENT_BLOCK_PLACEHOLDER_BUTTON, | ||
GeneralPurposeImage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
projects/plugins/jetpack/extensions/shared/external-media/media-button/media-ai-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { SOURCE_JETPACK_AI_GENERAL_PURPOSE_IMAGE_FOR_BLOCK } from '../constants'; | ||
|
||
function MediaAiButton( props ) { | ||
const { setSelectedSource } = props; | ||
return ( | ||
<Button | ||
variant="tertiary" | ||
className="jetpack-external-media-button-menu" | ||
aria-haspopup="false" | ||
onClick={ () => { | ||
setSelectedSource( SOURCE_JETPACK_AI_GENERAL_PURPOSE_IMAGE_FOR_BLOCK ); | ||
} } | ||
> | ||
<div className="jetpack-external-media-button-menu__label"> | ||
{ __( 'Generate with AI', 'jetpack' ) } | ||
</div> | ||
</Button> | ||
); | ||
} | ||
|
||
export default MediaAiButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ck/extensions/shared/external-media/sources/jetpack-ai-general-purpose-image-for-block.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
GeneralPurposeImage, | ||
PLACEMENT_BLOCK_PLACEHOLDER_BUTTON, | ||
} from '../../../plugins/ai-assistant-plugin/components/ai-image'; | ||
|
||
function JetpackAIGeneralPurposeImageForBlock( { | ||
onClose = () => {}, | ||
onSelect, | ||
multiple = false, | ||
} ) { | ||
return ( | ||
<GeneralPurposeImage | ||
placement={ PLACEMENT_BLOCK_PLACEHOLDER_BUTTON } | ||
onClose={ onClose } | ||
onSetImage={ image => onSelect( multiple ? [ image ] : image ) } | ||
/> | ||
); | ||
} | ||
|
||
export default JetpackAIGeneralPurposeImageForBlock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters