| 1 |
import { subscribe } from '@wordpress/data'; |
| 2 |
import { preFetchImages as preFetchUnsplashImages } from '@shared/lib/unsplash'; |
| 3 |
import '@draft/app.css'; |
| 4 |
|
| 5 |
const isOnLaunch = () => { |
| 6 |
const query = new URLSearchParams(window.location.search); |
| 7 |
return query.get('page') === 'extendify-launch'; |
| 8 |
}; |
| 9 |
|
| 10 |
(() => { |
| 11 |
// Disable the page editor welcome guide always (they can manually open it) |
| 12 |
const key = `WP_PREFERENCES_USER_${window.extSharedData.userId}`; |
| 13 |
const existing = window.localStorage.getItem(key) || '{}'; |
| 14 |
|
| 15 |
window.localStorage.setItem( |
| 16 |
key, |
| 17 |
JSON.stringify({ |
| 18 |
...JSON.parse(existing), |
| 19 |
'core/edit-post': { |
| 20 |
...(JSON.parse(existing)?.['core/edit-post'] ?? {}), |
| 21 |
welcomeGuide: false, |
| 22 |
}, |
| 23 |
}), |
| 24 |
); |
| 25 |
|
| 26 |
if (isOnLaunch()) return; |
| 27 |
|
| 28 |
preFetchUnsplashImages(); |
| 29 |
|
| 30 |
// TODO: If this PR is released in WP (6.7?), then we can use the localstorage |
| 31 |
// approach that we use above for the welcome guide |
| 32 |
// https://github.com/WordPress/gutenberg/pull/65026 |
| 33 |
|
| 34 |
// If the pattern modal shows up within 3 seconds, close it |
| 35 |
const modalClass = '.editor-start-page-options__modal-content'; |
| 36 |
const modalCloseButton = '.components-modal__header > .components-button'; |
| 37 |
|
| 38 |
// Add CSS to hide the modal initially (avoid content paint flash) |
| 39 |
const style = document.createElement('style'); |
| 40 |
style.innerHTML = |
| 41 |
'.components-modal__screen-overlay { display: none!important }'; |
| 42 |
document.head.appendChild(style); |
| 43 |
|
| 44 |
const unsub = subscribe(() => { |
| 45 |
const modal = document.querySelector(modalClass); |
| 46 |
if (!modal) return; |
| 47 |
modal.style.display = ''; // Temp show to click it |
| 48 |
document.querySelector(modalCloseButton)?.click(); |
| 49 |
}); |
| 50 |
|
| 51 |
setTimeout(() => { |
| 52 |
// Remove the CSS rule always |
| 53 |
document.head.removeChild(style); |
| 54 |
unsub(); |
| 55 |
}, 3000); |
| 56 |
})(); |
| 57 |
|