PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / _inc / content-guidelines-ai.js

content-guidelines-ai.js in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at _inc/content-guidelines-ai.js

35 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Content Guidelines AI — Entry point.
3 *
4 * Injects Jetpack AI-powered generate/improve buttons into the
5 * Content Guidelines admin page (Gutenberg experimental feature).
6 */
7 import { mapAiFeatureResponseToAiFeatureProps } from '@automattic/jetpack-shared-stores';
8 import '@automattic/jetpack-shared-extension-utils/store/wordpress-com';
9 import { dispatch } from '@wordpress/data';
10 import './content-guidelines-ai/store';
11 import './content-guidelines-ai/style.scss';
12 import { startInjection } from './content-guidelines-ai/lib/inject';
13
14 // The AI feature state is resolved server-side and preloaded into the page
15 // (see _inc/content-guidelines-ai.php), so components render the correct
16 // locked/unlocked state on first paint with no client-side plan fetch.
17 // Without the preload (server-side lookup failed) render no AI UI at all —
18 // the store's optimistic hasFeature default would show unlocked buttons
19 // whose requests are destined to fail.
20 const aiFeature = window.jetpackContentGuidelinesAi?.aiFeature;
21
22 if ( aiFeature ) {
23 const plansDispatch = dispatch( 'wordpress-com/plans' );
24 plansDispatch.storeAiAssistantFeature( mapAiFeatureResponseToAiFeatureProps( aiFeature ) );
25 // Mark the selector resolved so its resolver never fires a redundant
26 // fetch when components select getAiAssistantFeature.
27 plansDispatch.finishResolution( 'getAiAssistantFeature', [] );
28
29 if ( document.readyState === 'loading' ) {
30 document.addEventListener( 'DOMContentLoaded', startInjection );
31 } else {
32 startInjection();
33 }
34 }
35