PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 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 All 508 releases
← All changes | _inc/content-guidelines-ai.js +34 -0 16.2-beta → 16.3-beta View file →
@@ -1,0 +1,34 @@
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 +}