PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / Library / library.js

library.js in Extendify 2.2.0, at src/Library/library.js

43 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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