[239] Abschnitts-Rahmen der Objekt-Info ohne eigene Komponente für Bezugspunkt/Masse/Gelände: Render-Zählung je Wand-Änderung wieder 43 statt 45 [121]

This commit is contained in:
Claude committed 2026-11-13 20:21:31 +00:00
1 parent 93229b79e7
commit eb0ff9c2b2
2 files changed
+37 -21

No files matched your search

+26 -12
View File
@@ -1,25 +1,34 @@
// [189] Einklappbarer Abschnitt der Objekt-Info: Kopfzeile (Knopf mit Pfeil) und Inhalt. Die Abschnitts-
// Komponenten (`WallSection` …) bringen ihre eigene Kopf-Trennlinie mit; die erste blendet das CSS im Rumpf aus.
import { useEffect, useRef, useSyncExternalStore, type ReactNode } from "react";
import { useSyncExternalStore, type ReactNode } from "react";
import { t } from "../../i18n";
import { INFO_GROUP_TITLE, type InfoGroupId } from "./groups";
import { clearInfoGroupFocus, getInfoGroupState, isInfoGroupOpen, subscribeInfoGroups, toggleInfoGroup } from "./infoGroupState";
export function InfoGroup({ id, children }: { id: InfoGroupId; children: ReactNode }) {
const st = useSyncExternalStore(subscribeInfoGroups, getInfoGroupState, getInfoGroupState);
type GroupState = ReturnType<typeof getInfoGroupState>;
/** Zustand der Abschnitte (offen/zu, Fokus-Anfrage) für [`infoGroupFrame`]. */
export function useInfoGroupState(): GroupState {
return useSyncExternalStore(subscribeInfoGroups, getInfoGroupState, getInfoGroupState);
}
/**
* Abschnitt als blosses Markup, ohne eigene Komponente: Das Panel liest den Zustand einmal ([`useInfoGroupState`])
* und rahmt damit mehrere Abschnitte, ohne dass je Abschnitt ein Komponenten-Render bei jeder Änderung des Inhalts
* anfällt ([121], Render-Zählung). Die Fokus-Anfrage löst der Ref des Kopfknopfs ein.
*/
export function infoGroupFrame(st: GroupState, id: InfoGroupId, children: ReactNode): ReactNode {
const open = isInfoGroupOpen(st, id);
const head = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (st.focus?.id !== id) return;
head.current?.scrollIntoView?.({ block: "nearest" });
head.current?.focus();
clearInfoGroupFocus();
}, [st.focus, id]);
return (
<section className="objinfo-group" data-group={id} data-open={open}>
<section key={id} className="objinfo-group" data-group={id} data-open={open}>
<button
ref={head}
ref={(el) => {
if (!el || st.focus?.id !== id) return;
el.scrollIntoView?.({ block: "nearest" });
el.focus();
clearInfoGroupFocus();
}}
type="button"
className="objinfo-group-head"
aria-expanded={open}
@@ -33,3 +42,8 @@ export function InfoGroup({ id, children }: { id: InfoGroupId; children: ReactNo
</section>
);
}
export function InfoGroup({ id, children }: { id: InfoGroupId; children: ReactNode }) {
const st = useInfoGroupState();
return infoGroupFrame(st, id, children);
}