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