Skip to content

Commit

Permalink
Tweak: Adjusted AI features to support updated WordPress UI v6.6 [ED-…
Browse files Browse the repository at this point in the history
…15387] (elementor#28152)
  • Loading branch information
DennisNerush authored Jul 22, 2024
1 parent 78b4fbb commit 0d8e786
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion modules/ai/assets/js/gutenberg/excerpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const GenerateExcerptWithAI = () => {
};

return (
<div style={ { paddingBottom: '0.6em' } }>
<div style={ { paddingTop: '0.6em' } }>
<RequestIdsProvider>
<Icon className={ 'eicon-ai' } />
<AiLink onClick={ handleButtonClick }>{ __( 'Generate with Elementor AI', 'elementor' ) }</AiLink>
Expand Down
17 changes: 16 additions & 1 deletion modules/ai/assets/js/gutenberg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { EditTextWithAi } from './edit-text-with-ai';
};

const addTextWithAI = ( blockName, blockClientId ) => {
const textPanel = document.querySelector( '.block-editor-block-card__content' );
const textPanel = document.querySelector( '.block-editor-block-card__description, .block-editor-block-card__content' );
if ( textPanel && ! document.querySelector( `.e-text-ai[data-client-id="${ blockClientId }"]` ) ) {
removeAiIndicator();
const rootElement = document.createElement( 'div' );
Expand Down Expand Up @@ -93,6 +93,21 @@ import { EditTextWithAi } from './edit-text-with-ai';
addAiIndicator( 'featured-image', addGenerateFeaturedImageWithAI );
addAiIndicatorToTextBlock( [ 'paragraph', 'heading' ] );
} );

const observer = new MutationObserver( ( mutationsList ) => {
for ( const mutation of mutationsList ) {
if ( 'childList' === mutation.type ) {
if ( document.querySelector( '.editor-post-excerpt' ) ) {
addGenerateExcerptWithAI();
}
}
}
} );

observer.observe( document.body, { childList: true, subtree: true } );
window.addEventListener( 'beforeunload', () => {
observer.disconnect();
} );
} );
} )( jQuery );

Expand Down

0 comments on commit 0d8e786

Please sign in to comment.