PluginProbe
Extendify / 3.1.2
Extendify v3.1.2
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 / QuickEdit / lib / modal-root.js

modal-root.js in Extendify 3.1.2, at src/QuickEdit/lib/modal-root.js

44 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // Lives outside the .extendify-quick-edit prefix scope; modal styles need
2 // the /* no-prefix */ marker to match the body-level DOM wp-components portals to.
3 import { createRoot } from '@wordpress/element';
4
5 const ROOT_ID = 'extendify-quick-edit-modal-root';
6
7 // Override @wordpress/components Modal's default bodyOpenClassName ("modal-open")
8 // so our modals don't trip the wp.media-detection rule in quick-edit.css
9 // (`body.modal-open .components-modal__frame:has(.extendify-quick-edit-modal)`).
10 // Round-6 keyed that rule off `body.modal-open` thinking it was a wp.media-only
11 // signal; @wordpress/components Modal also adds it on mount, so every QE modal
12 // was hiding itself on first open.
13 export const QE_MODAL_BODY_OPEN_CLASS = 'extendify-quick-edit-modal-open';
14
15 let modalRoot = null;
16 let reactRoot = null;
17
18 const ensureNode = () => {
19 if (modalRoot?.isConnected) return modalRoot;
20 modalRoot = document.createElement('div');
21 modalRoot.id = ROOT_ID;
22 modalRoot.className = 'extendify-quick-edit';
23 document.body.appendChild(modalRoot);
24 return modalRoot;
25 };
26
27 export const mountModal = (element) => {
28 const node = ensureNode();
29 if (!reactRoot) reactRoot = createRoot(node);
30 reactRoot.render(element);
31 };
32
33 export const closeModal = (reload) => {
34 if (reactRoot) {
35 reactRoot.unmount();
36 reactRoot = null;
37 }
38 if (modalRoot) {
39 modalRoot.remove();
40 modalRoot = null;
41 }
42 if (reload) window.location.reload();
43 };
44