Merge [275] Umbau-Farben: Farbe oder Stift, gedämpfte Vorgabe, eigene Farben je Etappe

This commit is contained in:
Claude committed 2026-11-17 20:22:23 +00:00
commit ff7d80432d
40 files changed
+955 -143

No files matched your search

+3 -2
View File
@@ -6,7 +6,7 @@
import { useEffect, useRef, useState } from "react";
import { t } from "../i18n";
import type { TranslationKey } from "../i18n";
import { renovationFilterLabel, useRenovationControls } from "../state/renovationHook";
import { renovationFilterLabel, useRenovationControls, useRenovationSwatches } from "../state/renovationHook";
import { BUILTIN_RENOVATION_FILTERS, RENOVATION_STATUSES } from "../core";
import type { RenovationStatus } from "../model/types";
@@ -14,6 +14,7 @@ export { renovationFilterLabel };
export function RenovationControl() {
const { draw, setDraw, phases, own, filter, filterPhase, levelEditable, setLevel } = useRenovationControls();
const sw = useRenovationSwatches();
const [open, setOpen] = useState(false);
const wrapRef = useRef<HTMLSpanElement | null>(null);
useEffect(() => {
@@ -42,7 +43,7 @@ export function RenovationControl() {
title={t("renovation.status.hint", { status: statusLabel, filter: filterLabel })}
onClick={() => setOpen((v) => !v)}
>
<span className={`sb-renovation-dot sb-renovation-${draw.status}`} aria-hidden="true" />
<span className={`sb-renovation-dot sb-renovation-${draw.status}`} style={{ background: sw[draw.status].fill }} aria-hidden="true" />
{t("renovation.short", { status: statusLabel })}
</button>
{open && (
+1 -1
View File
@@ -33,7 +33,7 @@ export function RenovationStrip({ pair, width = 150 }: { pair: RenovationPair; w
const sum = (v: RenovationStripPiece[]) => v.reduce((a, q) => a + q.thickness, 0);
const max = Math.max(sum(pair.oldStrip), sum(pair.newStrip), sum(pair.result), 1e-6);
const scale = width / max;
const demolishFill = pair.result.find((q) => q.kind === "demolish")?.fill ?? pair.oldStrip.find((q) => q.kind === "demolish")?.fill ?? "#ffd800";
const demolishFill = pair.result.find((q) => q.kind === "demolish")?.fill ?? pair.oldStrip.find((q) => q.kind === "demolish")?.fill ?? "var(--reno-demolish)";
const row = (label: string, pieces: RenovationStripPiece[], id: string) => (
<div className="reno-strip-row" data-testid={`reno-strip-${id}`}>
<span className="reno-strip-label">{label}</span>
+101
View File
@@ -0,0 +1,101 @@
// [275] Umbau-Farben bearbeiten: je Status Füllung und Linie als freie Farbe ODER Stift (der gemeinsame `PenColorField`
// der App: Frei/Stift-Umschalter, Stift-Raster des aktiven Stiftsatzes), „gestrichelt“, Zurücksetzen je Status. Eine
// Komponente für das Umbau-Panel (Abschnitt „Darstellung“, Etappen) und den Ressourcen-Tab „Umbau“ — reine Darstellung,
// die Änderung geht als ganzes `RenovationStyles` an `onChange` (der Aufrufer macht daraus Ops).
import { t } from "../i18n";
import type { TranslationKey } from "../i18n";
import type { Project, RenovationStatus, RenovationStyle, RenovationStyles } from "../model/types";
import { activePenSet } from "../model/penSets";
import { patchRenovationStyles, RENOVATION_STATUSES } from "../core";
import type { RenovationStyleSet } from "../core";
import { PenColorField } from "./PenColorField";
export interface RenovationStyleEditorProps {
project: Project;
/** Eigene Angaben (Projekt oder Etappe); `undefined` = keine. */
styles: RenovationStyles | undefined;
/** Aufgelöste Farben, die gerade gelten (Kern), für die Anzeige. */
shown: RenovationStyleSet;
onChange: (next: RenovationStyles | undefined, status: RenovationStatus) => void;
statuses?: readonly RenovationStatus[];
/** „gestrichelt“ für diese Status anbieten (Vorgabe: nur Abbruch). */
dashedFor?: readonly RenovationStatus[];
disabled?: boolean;
/** Präfix der `data-testid` (z. B. `reno-style` → `reno-style-new`). */
testId: string;
onSaveColor?: (paletteId: string, hex: string) => void;
}
export function RenovationStyleEditor({ project, styles, shown, onChange, statuses = RENOVATION_STATUSES, dashedFor = ["demolish"], disabled, testId, onSaveColor }: RenovationStyleEditorProps) {
const pens = project.pens ?? [];
const activeStyles = activePenSet(project)?.pens;
const patch = (s: RenovationStatus, p: Partial<RenovationStyle> | null) => onChange(patchRenovationStyles(styles, s, p), s);
return (
<div className="reno-style-grid">
<div className="reno-style-row reno-style-head" aria-hidden="true">
<span />
<span className="reno-style-cap">{t("renovation.styles.fill")}</span>
<span className="reno-style-cap">{t("renovation.styles.line")}</span>
<span />
<span />
</div>
{statuses.map((s) => {
const own = styles?.[s];
const st = shown[s];
return (
<div className="reno-style-row" key={s} data-testid={`${testId}-${s}`} data-fill={st.fill} data-line={st.line ?? ""} data-dashed={String(st.dashed)}>
<span className="reno-style-label">{t(`renovation.status.${s}` as TranslationKey)}</span>
<span className="reno-style-field" title={t("renovation.styles.fill")} data-testid={`${testId}-${s}-fill`}>
<PenColorField
color={st.fill}
penId={own?.fillPen}
pens={pens}
activeStyles={activeStyles}
customPalettes={project.customPalettes}
builtinBanks={project.builtinPaletteBanks}
onSaveColor={onSaveColor}
disabled={disabled}
onColorChange={(fill) => patch(s, { fill })}
onPenChange={(fillPen) => patch(s, fillPen ? { fillPen } : { fillPen: undefined, fill: st.fill })}
/>
</span>
<span className="reno-style-field" title={t("renovation.styles.line")} data-testid={`${testId}-${s}-line`}>
<PenColorField
color={st.line ?? "#000000"}
penId={own?.linePen}
pens={pens}
activeStyles={activeStyles}
customPalettes={project.customPalettes}
builtinBanks={project.builtinPaletteBanks}
onSaveColor={onSaveColor}
disabled={disabled}
onColorChange={(line) => patch(s, { line })}
onPenChange={(linePen) => patch(s, linePen ? { linePen } : { linePen: undefined, ...(st.line ? { line: st.line } : {}) })}
/>
</span>
{dashedFor.includes(s) ? (
<label className="reno-style-dashed">
<input type="checkbox" checked={st.dashed} disabled={disabled} data-testid={`${testId}-${s}-dashed`} onChange={(e) => patch(s, { dashed: e.target.checked })} />
{t("renovation.styles.dashed")}
</label>
) : (
<span />
)}
<button
type="button"
className="reno-icon-btn"
disabled={disabled || !own}
title={t("renovation.styles.reset")}
aria-label={t("renovation.styles.reset")}
data-testid={`${testId}-${s}-reset`}
onClick={() => patch(s, null)}
>
↺
</button>
</div>
);
})}
</div>
);
}
+15 -36
View File
@@ -1,11 +1,12 @@
// [271] Ressourcen-Tab „Umbau“: Etappen (Name, Reihenfolge, hinzufügen/entfernen) und Umbau-Farben je Status
// (Füllung, Linie, gestrichelt; Vorgabe SIA 400: Bestand grau, Abbruch gelb gestrichelt, Neu rot).
// Reine Darstellung über Handler (wie die anderen Tabs, auch im macOS-Nebenfenster).
// Reine Darstellung über Handler (wie die anderen Tabs, auch im macOS-Nebenfenster). [275] Farben als Farbe oder Stift
// über den gemeinsamen Editor (`ui/RenovationStyleEditor.tsx`, wie im Umbau-Panel).
import { t } from "../../i18n";
import type { TranslationKey } from "../../i18n";
import type { Project, RenovationPhase, RenovationStatus, RenovationStyle, RenovationStyles } from "../../model/types";
import { DEFAULT_RENOVATION_STYLES, newPhaseId, RENOVATION_STATUSES, renovationPhases } from "../../core";
import type { Project, RenovationPhase, RenovationStyles } from "../../model/types";
import { newPhaseId, renovationPhases, resolvedRenovationStyles } from "../../core";
import { RenovationStyleEditor } from "../RenovationStyleEditor";
export interface RenovationHandlers {
/** Etappen-Liste ersetzen (Elemente einer entfernten Etappe verlieren sie). */
@@ -16,7 +17,7 @@ export interface RenovationHandlers {
export function RenovationTab({ project, handlers }: { project: Project; handlers: RenovationHandlers }) {
const phases = renovationPhases(project);
const styles = project.renovation?.styles ?? {};
const styles = project.renovation?.styles;
const setPhases = handlers.onSetRenovationPhases;
const setStyles = handlers.onSetRenovationStyles;
const move = (i: number, d: number) => {
@@ -26,13 +27,6 @@ export function RenovationTab({ project, handlers }: { project: Project; handler
[next[i], next[j]] = [next[j], next[i]];
setPhases(next);
};
const patchStyle = (s: RenovationStatus, patch: Partial<RenovationStyle> | null) => {
if (!setStyles) return;
const next: RenovationStyles = { ...styles };
if (patch === null) delete next[s];
else next[s] = { ...(styles[s] ?? {}), ...patch };
setStyles(Object.keys(next).length ? next : undefined);
};
return (
<div className="rm-renovation" data-testid="rm-renovation">
<h4 className="rm-subhead">{t("renovation.phases.title")}</h4>
@@ -70,30 +64,15 @@ export function RenovationTab({ project, handlers }: { project: Project; handler
<h4 className="rm-subhead">{t("renovation.styles.title")}</h4>
<p className="rm-hint">{t("renovation.styles.hint")}</p>
{RENOVATION_STATUSES.map((s) => {
const d = DEFAULT_RENOVATION_STYLES[s];
const own = styles[s] ?? {};
return (
<div className="rm-row" key={s} data-testid={`rm-renovation-style-${s}`}>
<span className="rm-label">{t(`renovation.status.${s}` as TranslationKey)}</span>
<label className="rm-inline">
{t("renovation.styles.fill")}
<input type="color" value={own.fill ?? d.fill} disabled={!setStyles} onChange={(e) => patchStyle(s, { fill: e.target.value })} />
</label>
<label className="rm-inline">
{t("renovation.styles.line")}
<input type="color" value={own.line ?? d.line ?? "#000000"} disabled={!setStyles} onChange={(e) => patchStyle(s, { line: e.target.value })} />
</label>
<label className="rm-inline">
<input type="checkbox" checked={own.dashed ?? d.dashed} disabled={!setStyles} onChange={(e) => patchStyle(s, { dashed: e.target.checked })} />
{t("renovation.styles.dashed")}
</label>
<button type="button" className="rm-icon-btn" disabled={!setStyles || !styles[s]} title={t("renovation.styles.reset")} aria-label={t("renovation.styles.reset")} onClick={() => patchStyle(s, null)}>
↺
</button>
</div>
);
})}
<RenovationStyleEditor
project={project}
styles={styles}
shown={resolvedRenovationStyles(project).project}
testId="rm-renovation-style"
dashedFor={["existing", "demolish", "new"]}
disabled={!setStyles}
onChange={(next) => setStyles?.(next)}
/>
</div>
);
}