| 1 |
import { Agent } from '@agent/Agent.jsx'; |
| 2 |
import { render } from '@shared/lib/dom'; |
| 3 |
import { isEmbedded } from '@shared/lib/embedded-guard'; |
| 4 |
import { isOnLaunch } from '@shared/lib/utils'; |
| 5 |
import domReady from '@wordpress/dom-ready'; |
| 6 |
import '@agent/agent.css'; |
| 7 |
import '@agent/buttons'; |
| 8 |
import { GuidedTour } from '@agent/components/GuidedTour'; |
| 9 |
import { throwSideConfetti } from './lib/confetti'; |
| 10 |
|
| 11 |
domReady(() => { |
| 12 |
// Never activate framed — the Customizer preview, page-builder previews, |
| 13 |
// and the block-editor canvas are all someone else's iframe. |
| 14 |
if (isEmbedded()) return; |
| 15 |
|
| 16 |
// disableForReducedMotion |
| 17 |
// tours |
| 18 |
const tourId = 'extendify-agent-tour'; |
| 19 |
if (document.getElementById(tourId)) return; |
| 20 |
const tour = Object.assign(document.createElement('div'), { |
| 21 |
className: 'extendify-agent-tour', |
| 22 |
id: tourId, |
| 23 |
}); |
| 24 |
render(<GuidedTour />, tour); |
| 25 |
|
| 26 |
const bg = |
| 27 |
// admin area |
| 28 |
document.getElementById('wpwrap') || |
| 29 |
// TODO: is this on all block themes? |
| 30 |
document.querySelector('.wp-site-blocks'); |
| 31 |
if (isOnLaunch() || !bg) return; |
| 32 |
const id = 'extendify-agent-main'; |
| 33 |
if (document.getElementById(id)) return; |
| 34 |
const agent = Object.assign(document.createElement('div'), { |
| 35 |
className: 'extendify-agent', |
| 36 |
id, |
| 37 |
}); |
| 38 |
document.body.appendChild(agent); |
| 39 |
render(<Agent />, agent); |
| 40 |
|
| 41 |
// Runs when extendify-launch-success is in the url |
| 42 |
if (window.extAgentData?.startOnboarding) { |
| 43 |
requestAnimationFrame(() => { |
| 44 |
throwSideConfetti(); |
| 45 |
}); |
| 46 |
} |
| 47 |
}); |
| 48 |
|