ui/highlight: add global highlighter store
This commit is contained in:
42
pkgs/clan-app/ui/src/scene/highlightStore.tsx
Normal file
42
pkgs/clan-app/ui/src/scene/highlightStore.tsx
Normal 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 };
|
||||
Reference in New Issue
Block a user