| 1 |
import { createRoot } from '@wordpress/element'; |
| 2 |
import { registerPlugin } from '@wordpress/plugins'; |
| 3 |
import { MainButton } from '@library/components/MainButton'; |
| 4 |
import { Modal } from '@library/components/Modal'; |
| 5 |
import './library.css'; |
| 6 |
|
| 7 |
registerPlugin('extendify-library', { |
| 8 |
render: () => { |
| 9 |
if (typeof createRoot !== 'function') return; |
| 10 |
const id = 'extendify-library-btn'; |
| 11 |
const className = 'extendify-library'; |
| 12 |
const page = '.edit-post-header-toolbar'; |
| 13 |
const fse = '.edit-site-header-edit-mode__start'; |
| 14 |
if (!document.querySelector(page) && !document.querySelector(fse)) { |
| 15 |
return; |
| 16 |
} |
| 17 |
requestAnimationFrame(() => { |
| 18 |
if (document.getElementById(id)) return; |
| 19 |
const btnWrap = document.createElement('div'); |
| 20 |
const btn = Object.assign(btnWrap, { id, className }); |
| 21 |
document.querySelector(page)?.append(btn); |
| 22 |
document.querySelector(fse)?.append(btn); |
| 23 |
createRoot(btn).render(<MainButton />); |
| 24 |
|
| 25 |
const mdl = 'extendify-library-modal'; |
| 26 |
if (document.getElementById(mdl)) return; |
| 27 |
const modalWrap = document.createElement('div'); |
| 28 |
const modal = Object.assign(modalWrap, { id: mdl, className }); |
| 29 |
document.body.append(modal); |
| 30 |
createRoot(modal).render(<Modal />); |
| 31 |
}); |
| 32 |
}, |
| 33 |
}); |
| 34 |
|