ui/highlight: add global highlighter store

This commit is contained in:
Johannes Kirschbauer
2025-08-28 22:35:15 +02:00
parent 803ef5476f
commit fada75144c

View File

@@ -0,0 +1,42 @@
// highlightStore.ts
import { createStore, produce } from "solid-js/store";
// groups: { [groupName: string]: Set<nodeId> }
const [highlightGroups, setHighlightGroups] = createStore<
Record<string, Set<string>>
>({});
// Add highlight
export function highlight(group: string, nodeId: string) {
setHighlightGroups(group, (prev = new Set()) => {
const next = new Set(prev);
next.add(nodeId);
return next;
});
}
// Remove highlight
export function unhighlight(group: string, nodeId: string) {
setHighlightGroups(group, (prev = new Set()) => {
const next = new Set(prev);
next.delete(nodeId);
return next;
});
}
// Clear group
export function clearHighlight(group: string) {
setHighlightGroups(group, () => new Set());
}
export function clearAllHighlights() {
setHighlightGroups(
produce((s) => {
for (const key of Object.keys(s)) {
Reflect.deleteProperty(s, key);
}
}),
);
}
export { highlightGroups, setHighlightGroups };