app.js (1293B)
1 import ExtendifyLibrary from './ExtendifyLibrary' 2 import { render } from '@wordpress/element' 3 import { useWantedTemplateStore } from './state/Importing' 4 import { injectTemplate } from './util/templateInjection' 5 import './buttons' 6 import './listeners' 7 8 window._wpLoadBlockEditor && window.wp.domReady(() => { 9 // Insert into the editor (note: Modal opens in a portal) 10 const extendify = Object.assign(document.createElement('div'), { id: 'extendify-root' }) 11 document.body.append(extendify) 12 render(<ExtendifyLibrary/>, extendify) 13 14 // Add an extra div to use for utility modals, etc 15 extendify.parentNode.insertBefore(Object.assign(document.createElement('div'), { id: 'extendify-util' }), 16 extendify.nextSibling) 17 18 // Insert a template on page load if it exists in localstorage 19 // Note 6/28/21 - this was moved to after the render to possibly 20 // fix a bug where imports would go from 3->0. 21 if (useWantedTemplateStore.getState().importOnLoad) { 22 const template = useWantedTemplateStore.getState().wantedTemplate 23 setTimeout(() => { injectTemplate(template) }, 0) 24 } 25 26 // Reset template state after checking if we need an import 27 useWantedTemplateStore.setState({ 28 importOnLoad: false, 29 wantedTemplate: {}, 30 }) 31 })