// Entry of the WordPress admin bundle: an IIFE with its own React 19 inside. // It never reads or writes `window.React` / `wp.element` — WordPress ships its // own React, and other plugins load theirs — and its stylesheet is scoped // under `#accessibit-admin-root` (see scope-css.ts), with no global preflight. // It exports nothing, so the IIFE puts nothing on `window`; the build fails // if anything lands outside it (see vite.wp.config.ts). import { createRoot } from "react-dom/client"; import brand from "virtual:accessibit-admin-brand"; import messages from "virtual:accessibit-admin-messages"; import "./styles.css"; import { App } from "./App"; import { uiLocaleOf, type WpAdminConfig } from "./config"; import { ROOT_ID } from "./scope"; function mount() { const root = document.getElementById(ROOT_ID); const config = ( window as unknown as { accessibitAdminConfig?: WpAdminConfig } ).accessibitAdminConfig; if (!root || !config) return; // root > frame > (app, portal). The frame carries the input-modality mark, // which the scoped `keyboard:` variant and pointer rule look for on an // ancestor; the select menus are portalled beside the app rather than to //
, which the scoped stylesheet does not reach. const frame = document.createElement("div"); const app = document.createElement("div"); const portal = document.createElement("div"); frame.append(app, portal); root.replaceChildren(frame); // Hands the screen back: an empty, unmarked root is what shows the PHP view // under it again, on the screens that have one. const handBack = () => { root.removeAttribute("data-mounted"); root.replaceChildren(); }; const fallback = () => document.querySelector(`#${ROOT_ID} ~ .accessibit-fallback`); createRoot(app, { // An error nothing caught leaves no app to show. onUncaughtError: (error) => { console.error(error); handBack(); }, }).render(