[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
+1
-1
@@ -49,7 +49,7 @@ export { exportProjectName, competitionIdentity, isAnonymous, competitionKeyword
|
||||
export type { CompetitionIdentity } from "../export/competitionIdentity";
|
||||
export { anonymityFindings } from "../export/competitionCheck";
|
||||
export type { AnonymityFinding, AnonymityKind } from "../export/competitionCheck";
|
||||
export { buildAreaReport, areaReportToCsv, parseAreaReportCsv, areaReportToSvg, buildAreaReportPdf } from "../export/areaReport";
|
||||
export { isAreaReportEmpty, buildAreaReport, areaReportToCsv, parseAreaReportCsv, areaReportToSvg, buildAreaReportPdf } from "../export/areaReport";
|
||||
export { setPdfFontLoader } from "../export/pdfFonts";
|
||||
export type { AreaReport, AreaReportOptions } from "../export/areaReport";
|
||||
export { sunPosition, shadowPolygons, shadowOfPrism, projectLatLon } from "../analysis/sun";
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { emptyProject, sampleProject } from "../model/sampleProject";
|
||||
import type { Project, Room, Wall } from "../model/types";
|
||||
import { computeAreaTable, computeIvhb } from "../analysis/areaTable";
|
||||
import { areaReportToCsv, areaReportToSvg, buildAreaReport, buildAreaReportPdf, layoutAreaReport, parseAreaReportCsv } from "./areaReport";
|
||||
import { isAreaReportEmpty, areaReportToCsv, areaReportToSvg, buildAreaReport, buildAreaReportPdf, layoutAreaReport, parseAreaReportCsv } from "./areaReport";
|
||||
|
||||
// Einfaches Haus: Achsen 10 × 8 m, Wände 0.3 m, EG-Räume innen 9.7 × 7.7 m (Handrechnung siehe flaechen.rs).
|
||||
function house(): Project {
|
||||
@@ -113,3 +113,10 @@ describe("Bericht", () => {
|
||||
expect(lay.pages.length).toBeGreaterThan(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isAreaReportEmpty [263]", () => {
|
||||
it("leeres Projekt: leer; Musterhaus: nicht leer", () => {
|
||||
expect(isAreaReportEmpty(emptyProject)).toBe(true);
|
||||
expect(isAreaReportEmpty(sampleProject)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -65,6 +65,12 @@ function areaCells(r: AreaRow): Cell[] {
|
||||
return [r.hnf, r.nnf, r.nf, r.vf, r.ff, r.ngf, r.kf, r.gf, r.agf].map((v) => num(v, 2)).concat(num(r.gv, 1));
|
||||
}
|
||||
|
||||
/** [263] Ohne Bauteile (kein Raum, keine Fläche, kein Volumen) wäre der Nachweis nur Nullen: dann kein Export, sondern ein Hinweis. */
|
||||
export function isAreaReportEmpty(project: Project): boolean {
|
||||
const { total, gv } = computeAreaTable(project);
|
||||
return [total.hnf, total.nnf, total.vf, total.ff, total.kf, total.gf, total.agf, total.rooms, gv].every((v) => !(Math.abs(v) > 0));
|
||||
}
|
||||
|
||||
/** Baut den Bericht aus dem Projekt. */
|
||||
export function buildAreaReport(project: Project, opts: AreaReportOptions = {}): AreaReport {
|
||||
const sections: ReportSection[] = [];
|
||||
|
||||
@@ -2607,6 +2607,7 @@ export const de = {
|
||||
"areas.basisInput": "aGF der AZ",
|
||||
"areas.includeUnderground": "Untergeschosse anrechnen",
|
||||
"areas.exportCsv": "CSV",
|
||||
"areas.export.empty": "Noch keine Bauteile — der Nachweis wäre leer. Es wurde nichts exportiert.",
|
||||
"areas.exportPdf": "PDF",
|
||||
"areas.exportPdf.fail": "PDF konnte nicht erstellt werden.",
|
||||
"areas.noLevels": "Keine Geschosse mit Räumen.",
|
||||
@@ -4464,6 +4465,10 @@ export const de = {
|
||||
"menu.help": "Hilfe",
|
||||
"menu.help.shortcuts": "Tastaturkürzel …",
|
||||
"menu.help.about": "Über dossier …",
|
||||
"menu.help.guide": "Kurzanleitung …",
|
||||
"menu.help.bugReport": "Fehler melden …",
|
||||
"help.guide.title": "Kurzanleitung",
|
||||
"help.bugReport.body": "Version: {version}\n\nWas ist passiert?\n\nWas hast du erwartet?\n\nSchritte zum Nachstellen:\n1. \n",
|
||||
"help.shortcuts.title": "Tastaturkürzel",
|
||||
"help.shortcuts.intro": "Tastenkombinationen und Befehlskürzel, wie sie gerade gelten (inklusive eigener Änderungen aus den Einstellungen).",
|
||||
"help.shortcuts.filter": "Suchen …",
|
||||
|
||||
@@ -2595,6 +2595,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"areas.basisInput": "aGF for AZ",
|
||||
"areas.includeUnderground": "Credit underground levels",
|
||||
"areas.exportCsv": "CSV",
|
||||
"areas.export.empty": "No building elements yet — the report would be empty. Nothing was exported.",
|
||||
"areas.exportPdf": "PDF",
|
||||
"areas.exportPdf.fail": "Could not create the PDF.",
|
||||
"areas.noLevels": "No levels with rooms.",
|
||||
@@ -4450,6 +4451,10 @@ export const en: Record<TranslationKey, string> = {
|
||||
"menu.help": "Help",
|
||||
"menu.help.shortcuts": "Keyboard Shortcuts …",
|
||||
"menu.help.about": "About dossier …",
|
||||
"menu.help.guide": "Quick Guide …",
|
||||
"menu.help.bugReport": "Report a Bug …",
|
||||
"help.guide.title": "Quick Guide (German)",
|
||||
"help.bugReport.body": "Version: {version}\n\nWhat happened?\n\nWhat did you expect?\n\nSteps to reproduce:\n1. \n",
|
||||
"help.shortcuts.title": "Keyboard Shortcuts",
|
||||
"help.shortcuts.intro": "Key combinations and command aliases as they apply now (including your changes from Settings).",
|
||||
"help.shortcuts.filter": "Search …",
|
||||
|
||||
+10
-1
@@ -17,6 +17,7 @@ import { isTauriRuntime } from "./projectFile";
|
||||
import { t } from "../i18n";
|
||||
import { openRenderDialog } from "../state/renderDialogHook";
|
||||
import { openShortcutOverview } from "../state/shortcutOverviewHook";
|
||||
import { openBugReport, openQuickGuide } from "../state/helpMenuHook";
|
||||
import { openImageExportDialog } from "../state/imageExportDialogHook";
|
||||
import { APP_VERSION } from "../ui/TopBar";
|
||||
import { BUILD_INFO } from "../update/buildInfo";
|
||||
@@ -502,14 +503,22 @@ export function useNativeAppMenu(
|
||||
],
|
||||
});
|
||||
|
||||
// [210] Hilfe → Tastaturkürzel (Overlay-Dialog in der App).
|
||||
// [210] Hilfe → Tastaturkürzel (Overlay-Dialog in der App); [263] Kurzanleitung (Dialog), Fehler melden (System-Browser).
|
||||
const helpMenu = await Submenu.new({
|
||||
text: t("menu.help"),
|
||||
items: [
|
||||
await MenuItem.new({
|
||||
text: t("menu.help.guide"),
|
||||
action: () => openQuickGuide(),
|
||||
}),
|
||||
await MenuItem.new({
|
||||
text: t("menu.help.shortcuts"),
|
||||
action: () => openShortcutOverview(),
|
||||
}),
|
||||
await MenuItem.new({
|
||||
text: t("menu.help.bugReport"),
|
||||
action: () => openBugReport(),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { exportProjectName, areaReportToCsv, buildAreaReport, buildAreaReportPdf } from "../core";
|
||||
import { exportProjectName, areaReportToCsv, buildAreaReport, buildAreaReportPdf, isAreaReportEmpty } from "../core";
|
||||
import type { AgfBasis } from "../core";
|
||||
import { DEFAULT_AREA_INPUTS, ivhbOptionsOf, type AreaInputs } from "./areaInputs";
|
||||
import { downloadCsv } from "./downloadFile";
|
||||
@@ -29,7 +29,18 @@ export function AreaTableSection() {
|
||||
const set = (patch: Partial<AreaInputs>) => setInputs((i) => ({ ...i, ...patch }));
|
||||
const stem = `${exportProjectName(project) || "projekt"}-flaechen`;
|
||||
|
||||
// [263] Leeres Projekt: kein Export von Nullen, sondern ein Hinweis (sonst sähe die Datei wie ein Ergebnis aus).
|
||||
const emptyHint = () => {
|
||||
if (!isAreaReportEmpty(project)) return false;
|
||||
notify(t("areas.export.empty"));
|
||||
return true;
|
||||
};
|
||||
const exportCsv = () => {
|
||||
if (emptyHint()) return;
|
||||
runWithAnonymityGate(project, [`${stem}.csv`], () => downloadCsv(`${stem}.csv`, areaReportToCsv(report)));
|
||||
};
|
||||
const exportPdf = () => {
|
||||
if (emptyHint()) return;
|
||||
runWithAnonymityGate(project, [`${stem}.pdf`], async () => {
|
||||
try {
|
||||
(await buildAreaReportPdf(report)).save(`${stem}.pdf`);
|
||||
@@ -44,7 +55,7 @@ export function AreaTableSection() {
|
||||
<div className="balance-head">
|
||||
<span className="balance-section-label">{t("areas.title")}</span>
|
||||
<span className="area-actions">
|
||||
<button type="button" className="balance-export" onClick={() => runWithAnonymityGate(project, [`${stem}.csv`], () => downloadCsv(`${stem}.csv`, areaReportToCsv(report)))}>
|
||||
<button type="button" className="balance-export" onClick={exportCsv}>
|
||||
{t("areas.exportCsv")}
|
||||
</button>
|
||||
<button type="button" className="balance-export" onClick={exportPdf}>
|
||||
|
||||
Vendored
+5
@@ -4,3 +4,8 @@ declare module "*?raw" {
|
||||
const content: string;
|
||||
export default content;
|
||||
}
|
||||
|
||||
// [263] Vite `import.meta.glob` (Kurzanleitung-Bilder in `ui/QuickGuideDialog.tsx`), ohne die vite/client-Typen.
|
||||
interface ImportMeta {
|
||||
glob(pattern: string, options?: { query?: string; import?: string; eager?: boolean }): Record<string, unknown>;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// [263] Hilfe-Menü: Kurzanleitung und Fehler melden. Der Dialog (`ui/QuickGuideDialog.tsx`) registriert seinen Öffner;
|
||||
// „Fehler melden …“ öffnet die Issue-Seite im System-Browser (Muster `shortcutOverviewHook`, `aboutDialogHook`).
|
||||
|
||||
import { t } from "../i18n";
|
||||
import { bugReportUrl } from "../update/bugReport";
|
||||
import { openExternalUrl } from "../native/blender";
|
||||
|
||||
let opener: (() => void) | null = null;
|
||||
|
||||
export function setQuickGuideOpener(fn: (() => void) | null): void {
|
||||
opener = fn;
|
||||
}
|
||||
|
||||
export function openQuickGuide(): void {
|
||||
opener?.();
|
||||
}
|
||||
|
||||
/** Öffnet die Issue-Seite (Tauri: System-Browser, sonst neuer Tab), vorbefüllt mit Version und Build. */
|
||||
export function openBugReport(): void {
|
||||
void openExternalUrl(bugReportUrl(t("help.bugReport.body"), t("about.build")));
|
||||
}
|
||||
+50
-2
@@ -5767,7 +5767,7 @@ body {
|
||||
display: grid;
|
||||
/* [263] Label-Spalte höchstens 42 %: ein langes Label („Strichmuster-Massstab“) presste sonst die
|
||||
Wert-Spalte auf 120 px, und die Quellen-Auswahl neben dem Zahlenfeld schrumpfte auf „e ▾“. */
|
||||
grid-template-columns: minmax(80px, 42%) 1fr;
|
||||
grid-template-columns: minmax(80px, 36%) 1fr;
|
||||
align-items: stretch;
|
||||
gap: 0;
|
||||
padding: 0;
|
||||
@@ -5797,10 +5797,20 @@ body {
|
||||
min-width: 0;
|
||||
justify-content: space-between;
|
||||
}
|
||||
/* [263] Quellen-Auswahl neben einem Zahlenfeld: nie unter die Breite von „eigener Wert“ schrumpfen. */
|
||||
/* [263] Quellen-Auswahl neben einem Zahlenfeld: nie unter die Breite von „eigener Wert“ schrumpfen; dafür gibt das
|
||||
Zahlenfeld nach (im 270-px-Panel ragte die Auswahl sonst rechts aus dem Panel: „eigener Wer“). */
|
||||
.attr-val > .attr-num {
|
||||
flex: 0 1 auto;
|
||||
min-width: 58px;
|
||||
}
|
||||
/* Das Drehfeld (Pfeile) frisst in dem schmalen Feld die Ziffern („0.3“); Eingabe per Tastatur/Mausrad bleibt. */
|
||||
.attr-val > input.attr-num[type="number"]::-webkit-inner-spin-button {
|
||||
display: none;
|
||||
}
|
||||
.attr-val > .attr-num ~ .tb-dd-trigger {
|
||||
flex: 1 0 auto;
|
||||
min-width: 84px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.attr-readonly {
|
||||
color: var(--label);
|
||||
@@ -9551,3 +9561,41 @@ body {
|
||||
.floating-panel:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* [263] Kurzanleitung (Hilfe-Menü): breiter Dialog, lesbarer Fliesstext, Bilder auf Dialogbreite. */
|
||||
.imp-dialog.quick-guide {
|
||||
width: min(760px, 94vw);
|
||||
max-height: 90vh;
|
||||
}
|
||||
.quick-guide-body {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
line-height: 1.55;
|
||||
color: var(--label);
|
||||
outline: none;
|
||||
}
|
||||
.quick-guide-body h2 { font-size: 18px; margin: 0 0 8px; }
|
||||
.quick-guide-body h3 { font-size: 15px; margin: 22px 0 6px; }
|
||||
.quick-guide-body h4 { font-size: 13px; margin: 14px 0 4px; }
|
||||
.quick-guide-body p,
|
||||
.quick-guide-body ul,
|
||||
.quick-guide-body ol,
|
||||
.quick-guide-body blockquote { margin: 0 0 10px; }
|
||||
.quick-guide-body ul,
|
||||
.quick-guide-body ol { padding-left: 22px; }
|
||||
.quick-guide-body li { margin-bottom: 3px; }
|
||||
.quick-guide-body blockquote {
|
||||
padding: 6px 10px;
|
||||
border-left: 3px solid var(--line);
|
||||
background: var(--panel-2);
|
||||
border-radius: 3px;
|
||||
}
|
||||
.quick-guide-body code {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||
font-size: 12px;
|
||||
background: var(--panel-2);
|
||||
padding: 0 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.quick-guide-body hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
|
||||
.quick-guide-body img { display: block; max-width: 100%; height: auto; margin: 6px 0 12px; background: #fff; border: 1px solid var(--line); }
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { BUG_REPORT_URL, bugReportUrl } from "./bugReport";
|
||||
|
||||
describe("bugReportUrl [263]", () => {
|
||||
it("zeigt auf die Issue-Seite und trägt nur Version und Build", () => {
|
||||
const url = bugReportUrl("Version: {version}\n\nWas passiert?", "Build", { version: "1.0.0-beta.1", build: "261116.1" });
|
||||
expect(url.startsWith(`${BUG_REPORT_URL}?body=`)).toBe(true);
|
||||
const body = decodeURIComponent(url.split("?body=")[1]!);
|
||||
expect(body).toBe("Version: 1.0.0-beta.1 (Build 261116.1)\n\nWas passiert?");
|
||||
expect(new URL(url).hostname).toBe("git.openbureau.ch");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
// [263] Hilfe → „Fehler melden …“: Adresse der Issue-Seite im Gitea des Projekts, mit Version und Build vorbefüllt.
|
||||
// Bewusst nichts weiter (keine Projektdaten, kein Dateiname, keine Systemangaben): die Person ergänzt selbst.
|
||||
|
||||
import { BUILD_INFO, formatBuildInfo, type BuildInfo } from "./buildInfo";
|
||||
|
||||
export const BUG_REPORT_URL = "https://git.openbureau.ch/karim/dossier/issues/new";
|
||||
|
||||
/** `versionLine` kommt fertig übersetzt (z. B. „Version 1.0.0-beta.1 (Build 261115.1)“), `bodyTemplate` enthält `{version}`. */
|
||||
export function bugReportUrl(bodyTemplate: string, buildWord: string, info: BuildInfo = BUILD_INFO): string {
|
||||
const body = bodyTemplate.replace("{version}", formatBuildInfo(info, buildWord));
|
||||
return `${BUG_REPORT_URL}?body=${encodeURIComponent(body)}`;
|
||||
}
|
||||
Reference in new issue
Block a user