feat(map): add reference layers and stabilize workspace controls
This commit is contained in:
@@ -16,21 +16,29 @@ export interface InspectorSectionSpec {
|
||||
export interface InspectorProps {
|
||||
sections: InspectorSectionSpec[];
|
||||
defaultOpen?: string[];
|
||||
openSections?: string[];
|
||||
activeId?: string;
|
||||
singleOpen?: boolean;
|
||||
className?: string;
|
||||
onOpenSectionsChange?: (ids: string[]) => void;
|
||||
onActiveChange?: (id: string) => void;
|
||||
}
|
||||
|
||||
export function Inspector({
|
||||
sections,
|
||||
defaultOpen = [],
|
||||
openSections,
|
||||
activeId,
|
||||
singleOpen = false,
|
||||
className,
|
||||
onOpenSectionsChange,
|
||||
onActiveChange,
|
||||
}: InspectorProps) {
|
||||
const [openIds, setOpenIds] = useState(() => new Set(defaultOpen));
|
||||
const [internalOpenIds, setInternalOpenIds] = useState(() => new Set(defaultOpen));
|
||||
const openIds = useMemo(
|
||||
() => openSections === undefined ? internalOpenIds : new Set(openSections),
|
||||
[internalOpenIds, openSections],
|
||||
);
|
||||
const groups = useMemo(() => {
|
||||
const result: Array<{ label?: string; sections: InspectorSectionSpec[] }> = [];
|
||||
sections.forEach((section) => {
|
||||
@@ -45,12 +53,11 @@ export function Inspector({
|
||||
}, [sections]);
|
||||
|
||||
const toggle = (id: string) => {
|
||||
setOpenIds((current) => {
|
||||
const next = singleOpen ? new Set<string>() : new Set(current);
|
||||
if (current.has(id)) next.delete(id);
|
||||
else next.add(id);
|
||||
return next;
|
||||
});
|
||||
const next = singleOpen ? new Set<string>() : new Set(openIds);
|
||||
if (openIds.has(id)) next.delete(id);
|
||||
else next.add(id);
|
||||
if (openSections === undefined) setInternalOpenIds(next);
|
||||
onOpenSectionsChange?.([...next]);
|
||||
onActiveChange?.(id);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user