[263] UX-Reste: Quellen-Auswahl voll lesbar, Hilfe → Kurzanleitung und Fehler melden, Nachweis-Export im leeren Projekt mit Hinweis
This commit is contained in:
19 files changed
+432
-11
No files matched your search
@@ -33,6 +33,7 @@ import { RenderDialogHost } from "./RenderDialog";
|
||||
import { CameraTourDialogHost } from "./CameraTourDialog";
|
||||
import { ImageExportDialogHost } from "./ImageExportDialog";
|
||||
import { ShortcutOverviewDialogHost } from "./ShortcutOverviewDialog";
|
||||
import { QuickGuideDialogHost } from "./QuickGuideDialog";
|
||||
import { PromptDialog } from "./PromptDialog";
|
||||
import { RecoverAutosaveDialog } from "./RecoverAutosaveDialog";
|
||||
import { BackupOfferDialog } from "./BackupOfferDialog";
|
||||
@@ -176,6 +177,8 @@ export function AppDialogs(props: {
|
||||
<CameraTourDialogHost />
|
||||
{/* [210] Kürzel-Übersicht (Menü Hilfe) */}
|
||||
<ShortcutOverviewDialogHost />
|
||||
{/* [263] Kurzanleitung (Menü Hilfe) */}
|
||||
<QuickGuideDialogHost />
|
||||
{importState && (
|
||||
<ImportDialog
|
||||
fileName={importState.fileName}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { t } from "../i18n";
|
||||
import type { View3d, ViewType } from "../model/viewTypes";
|
||||
import { openRenderDialog } from "../state/renderDialogHook";
|
||||
import { openAboutDialog } from "../state/aboutDialogHook";
|
||||
import { openBugReport, openQuickGuide } from "../state/helpMenuHook";
|
||||
import { openShortcutOverview } from "../state/shortcutOverviewHook";
|
||||
import { openImageExportDialog } from "../state/imageExportDialogHook";
|
||||
|
||||
@@ -190,7 +191,9 @@ export const AppMenuBar = memo(function AppMenuBar({
|
||||
];
|
||||
|
||||
const helpItems: DropdownItem[] = [
|
||||
{ label: t("menu.help.guide"), onSelect: openQuickGuide },
|
||||
{ label: t("menu.help.shortcuts"), onSelect: openShortcutOverview },
|
||||
{ label: t("menu.help.bugReport"), onSelect: openBugReport },
|
||||
{ divider: true },
|
||||
// [263] Auf macOS (natives Menü) steht „Über dossier“ im App-Menü; dieses Menü gibt es nur im Browser/Electron.
|
||||
{ label: t("menu.help.about"), onSelect: openAboutDialog },
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
// [263] Overlay-Dialog „Kurzanleitung“ (Hilfe-Menü, Browser/Electron und natives Menü): der Inhalt von
|
||||
// doc/KURZANLEITUNG.md, beim Build gebündelt (`?raw`, Bilder als Assets) — kein Netz. Die Anleitung ist deutsch
|
||||
// (die Oberfläche übersetzt sie nicht); kein window.alert.
|
||||
|
||||
import { Fragment, memo, useEffect, useMemo, useState, type ReactNode } from "react";
|
||||
import guideMd from "../../doc/KURZANLEITUNG.md?raw";
|
||||
import { t } from "../i18n";
|
||||
import { setQuickGuideOpener } from "../state/helpMenuHook";
|
||||
import { useModalFocus } from "./modalFocus";
|
||||
import { parseMarkdown, type Block, type Inline } from "./miniMarkdown";
|
||||
|
||||
const IMAGES = import.meta.glob("../../doc/kurzanleitung/*.png", { query: "?url", import: "default", eager: true }) as Record<string, string>;
|
||||
|
||||
function imageUrl(src: string): string | undefined {
|
||||
return IMAGES[`../../doc/${src}`];
|
||||
}
|
||||
|
||||
function inline(parts: Inline[]): ReactNode {
|
||||
return parts.map((p, i) => {
|
||||
switch (p.t) {
|
||||
case "b":
|
||||
return <strong key={i}>{p.s}</strong>;
|
||||
case "i":
|
||||
return <em key={i}>{p.s}</em>;
|
||||
case "code":
|
||||
return <code key={i}>{p.s}</code>;
|
||||
default:
|
||||
return <Fragment key={i}>{p.s}</Fragment>;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderBlock(b: Block, i: number): ReactNode {
|
||||
switch (b.t) {
|
||||
case "h":
|
||||
return b.level === 1 ? <h2 key={i}>{inline(b.inl)}</h2> : b.level === 2 ? <h3 key={i}>{inline(b.inl)}</h3> : <h4 key={i}>{inline(b.inl)}</h4>;
|
||||
case "p":
|
||||
return <p key={i}>{inline(b.inl)}</p>;
|
||||
case "quote":
|
||||
return <blockquote key={i}>{inline(b.inl)}</blockquote>;
|
||||
case "ul":
|
||||
return <ul key={i}>{b.items.map((it, j) => <li key={j}>{inline(it)}</li>)}</ul>;
|
||||
case "ol":
|
||||
return <ol key={i}>{b.items.map((it, j) => <li key={j}>{inline(it)}</li>)}</ol>;
|
||||
case "hr":
|
||||
return <hr key={i} />;
|
||||
case "img": {
|
||||
const url = imageUrl(b.src);
|
||||
return url ? <img key={i} src={url} alt={b.alt} loading="lazy" /> : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const QuickGuideDialogHost = memo(function QuickGuideDialogHost() {
|
||||
const [open, setOpen] = useState(false);
|
||||
useEffect(() => {
|
||||
setQuickGuideOpener(() => setOpen(true));
|
||||
return () => setQuickGuideOpener(null);
|
||||
}, []);
|
||||
const dialogRef = useModalFocus({ onEscape: () => setOpen(false) });
|
||||
const blocks = useMemo(() => (open ? parseMarkdown(guideMd) : []), [open]);
|
||||
if (!open) return null;
|
||||
return (
|
||||
<div className="imp-overlay" onClick={() => setOpen(false)}>
|
||||
<div
|
||||
ref={dialogRef}
|
||||
className="imp-dialog quick-guide"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={t("help.guide.title")}
|
||||
data-testid="quick-guide"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("help.guide.title")}</span>
|
||||
<button className="imp-close" onClick={() => setOpen(false)} aria-label={t("export.close")}>
|
||||
×
|
||||
</button>
|
||||
</header>
|
||||
<div className="imp-body quick-guide-body" tabIndex={0}>
|
||||
{blocks.map(renderBlock)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { parseInline, parseMarkdown } from "./miniMarkdown";
|
||||
|
||||
describe("miniMarkdown [263]", () => {
|
||||
it("Inline: fett, kursiv, Code, Rest bleibt Text", () => {
|
||||
expect(parseInline("a **b** *c* `d` e*")).toEqual([
|
||||
{ t: "text", s: "a " }, { t: "b", s: "b" }, { t: "text", s: " " }, { t: "i", s: "c" }, { t: "text", s: " " },
|
||||
{ t: "code", s: "d" }, { t: "text", s: " e*" },
|
||||
]);
|
||||
});
|
||||
it("Blöcke: Überschrift, Absatz über Zeilen, Listen mit Fortsetzung, Zitat, Bild, Linie", () => {
|
||||
const b = parseMarkdown("# T\n\nzeile eins\nzeile zwei\n\n1. a\n weiter\n2. b\n\n- x\n\n> q\n> r\n\n\n\n---\n");
|
||||
expect(b.map((x) => x.t)).toEqual(["h", "p", "ol", "ul", "quote", "img", "hr"]);
|
||||
expect((b[1] as { inl: { s: string }[] }).inl[0]!.s).toBe("zeile eins zeile zwei");
|
||||
expect((b[2] as { items: unknown[][] }).items).toHaveLength(2);
|
||||
expect(b[5]).toEqual({ t: "img", alt: "alt", src: "p/a.png" });
|
||||
});
|
||||
it("die echte Kurzanleitung lässt sich lesen: Überschriften, Bilder, keine Rohzeichen", () => {
|
||||
const md = readFileSync(join(process.cwd(), "doc", "KURZANLEITUNG.md"), "utf8");
|
||||
const b = parseMarkdown(md);
|
||||
expect(b[0]).toMatchObject({ t: "h", level: 1 });
|
||||
expect(b.filter((x) => x.t === "h" && x.level === 2).length).toBeGreaterThanOrEqual(10);
|
||||
expect(b.filter((x) => x.t === "img").length).toBe(5);
|
||||
expect(JSON.stringify(b.filter((x) => x.t !== "img"))).not.toContain("**");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
// [263] Minimaler Markdown-Leser für die Kurzanleitung (doc/KURZANLEITUNG.md) im Hilfe-Dialog: Überschriften, Absätze,
|
||||
// Listen (`-`, `1.`), Zitate, Trennlinie, Bilder und im Text **fett**, *kursiv*, `Code`. Mehr braucht das Dokument nicht;
|
||||
// Tabellen/Codeblöcke gibt es dort nicht. Reine Funktion (Test `miniMarkdown.test.ts`), die Darstellung steht in
|
||||
// `QuickGuideDialog.tsx` (kein dangerouslySetInnerHTML).
|
||||
|
||||
export type Inline = { t: "text" | "b" | "i" | "code"; s: string };
|
||||
export type Block =
|
||||
| { t: "h"; level: 1 | 2 | 3; inl: Inline[] }
|
||||
| { t: "p"; inl: Inline[] }
|
||||
| { t: "quote"; inl: Inline[] }
|
||||
| { t: "ul" | "ol"; items: Inline[][] }
|
||||
| { t: "img"; alt: string; src: string }
|
||||
| { t: "hr" };
|
||||
|
||||
/** Zerlegt eine Zeile in Text-, Fett-, Kursiv- und Code-Stücke. Unabgeschlossene Zeichen bleiben Text. */
|
||||
export function parseInline(src: string): Inline[] {
|
||||
const out: Inline[] = [];
|
||||
const re = /`([^`]+)`|\*\*([^*]+)\*\*|\*([^*\s][^*]*)\*/g;
|
||||
let last = 0;
|
||||
for (const m of src.matchAll(re)) {
|
||||
if (m.index! > last) out.push({ t: "text", s: src.slice(last, m.index) });
|
||||
if (m[1] !== undefined) out.push({ t: "code", s: m[1] });
|
||||
else if (m[2] !== undefined) out.push({ t: "b", s: m[2] });
|
||||
else out.push({ t: "i", s: m[3]! });
|
||||
last = m.index! + m[0].length;
|
||||
}
|
||||
if (last < src.length) out.push({ t: "text", s: src.slice(last) });
|
||||
return out;
|
||||
}
|
||||
|
||||
export function parseMarkdown(md: string): Block[] {
|
||||
const lines = md.replace(/\r\n?/g, "\n").split("\n");
|
||||
const blocks: Block[] = [];
|
||||
let para: string[] = [];
|
||||
let quote: string[] = [];
|
||||
let list: { t: "ul" | "ol"; items: string[] } | null = null;
|
||||
const flush = () => {
|
||||
if (para.length) blocks.push({ t: "p", inl: parseInline(para.join(" ")) });
|
||||
if (quote.length) blocks.push({ t: "quote", inl: parseInline(quote.join(" ")) });
|
||||
if (list) blocks.push({ t: list.t, items: list.items.map(parseInline) });
|
||||
para = [];
|
||||
quote = [];
|
||||
list = null;
|
||||
};
|
||||
for (const raw of lines) {
|
||||
const line = raw.trimEnd();
|
||||
let m: RegExpMatchArray | null;
|
||||
if (!line.trim()) flush();
|
||||
else if ((m = line.match(/^(#{1,3})\s+(.*)$/))) {
|
||||
flush();
|
||||
blocks.push({ t: "h", level: m[1]!.length as 1 | 2 | 3, inl: parseInline(m[2]!) });
|
||||
} else if (/^-{3,}$/.test(line)) {
|
||||
flush();
|
||||
blocks.push({ t: "hr" });
|
||||
} else if ((m = line.match(/^!\[([^\]]*)\]\(([^)]+)\)$/))) {
|
||||
flush();
|
||||
blocks.push({ t: "img", alt: m[1]!, src: m[2]! });
|
||||
} else if ((m = line.match(/^>\s?(.*)$/))) {
|
||||
if (!quote.length) flush();
|
||||
quote.push(m[1]!);
|
||||
} else if ((m = line.match(/^(?:([-*])|(\d+)\.)\s+(.*)$/))) {
|
||||
const kind = m[1] ? "ul" : "ol";
|
||||
if (!list || list.t !== kind) {
|
||||
flush();
|
||||
list = { t: kind, items: [] };
|
||||
}
|
||||
list.items.push(m[3]!);
|
||||
} else if (list && /^\s+\S/.test(raw)) {
|
||||
list.items[list.items.length - 1] += " " + line.trim(); // Fortsetzungszeile eines Listenpunkts
|
||||
} else {
|
||||
if (quote.length || list) flush();
|
||||
para.push(line.trim());
|
||||
}
|
||||
}
|
||||
flush();
|
||||
return blocks;
|
||||
}
|
||||
Reference in new issue
Block a user