/* * The help's part of the first load (use-help.js has its state): the "How do I…?" button after More, * which shows its "?" alone where the toolbar is short of room (overflow.js), and the place of what * the help shows besides its list (help-extras.jsx: the help at More, the note on More, the card of * "Show me"). Everything else loads on first use (help-module.js). */ import React, { useEffect, useRef, useState } from "react"; import { MenuPanel, helpNow, loadHelp } from "./lazy-menus.jsx"; import { MenuButton } from "./popover.jsx"; /** * What the help reads of the toolbar (help-extras.jsx: helpReport). * @typedef {{ props: any, bar: React.RefObject, more: React.RefObject, hidden: Set, mod: string }} HelpCtx * props: the toolbar's; hidden: its buttons in More now; mod: "⌘" on a Mac, else "Ctrl+" */ /** * "How do I…?" after More: its text, or its "?" alone with the text as its name and tooltip (`short`). * More's "How do I…?" clicks it (`help.request`). * @param {{ labels: any, short: boolean, ctx: HelpCtx }} props */ export function HelpButton({ labels, short, ctx }) { const request = ctx.props.help.request; const ref = useRef(/** @type {HTMLButtonElement | null} */ (null)); const seen = useRef(request); useEffect(() => { const button = ref.current; if (request !== seen.current && button && button.getAttribute("aria-expanded") !== "true") { button.click(); } seen.current = request; }, [request]); return ( {(close) => } ); } /** * The help's parts besides its list (help-extras.jsx), loaded once one is asked for. * @param {{ ctx: HelpCtx }} props */ export function HelpLater({ ctx }) { const help = ctx.props.help; const wanted = help.atMore || help.hint || help.guide !== null; const [mod, setMod] = useState(() => helpNow()); useEffect(() => { if (wanted && !mod) { loadHelp(ctx.props.labels.lang).then((m) => setMod(() => m), () => undefined); } }, [wanted, mod, ctx.props.labels.lang]); return wanted && mod ? : null; }