blocks
6 days ago
build
6 days ago
fonts
1 year ago
genericons
5 months ago
lib
6 days ago
accessible-focus.js
6 years ago
blogging-prompts.php
1 month ago
class.jetpack-provision.php
7 months ago
content-guidelines-ai.js
1 week ago
content-guidelines-ai.php
6 days ago
crowdsignal-shortcode.js
1 year ago
crowdsignal-survey.js
6 years ago
deprecate.js
8 months ago
facebook-embed.js
4 years ago
gallery-settings.js
6 years ago
genericons.php
1 year ago
jetpack-admin.js
3 years ago
jetpack-deactivate-dialog.js
1 year ago
jetpack-modules.js
1 year ago
jetpack-modules.models.js
8 months ago
jetpack-modules.views.js
8 months ago
polldaddy-shortcode.js
2 weeks ago
site-switcher-endpoint.php
6 months ago
site-switcher.jsx
1 week ago
site-switcher.php
6 months ago
social-logos.php
4 months ago
twitter-timeline.js
1 month ago
content-guidelines-ai.js
35 lines
| 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 |