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