@ddd-ts/event-tree-viewer 0.0.0-eventviz.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/cli.mjs +20 -0
  4. package/index.html +13 -0
  5. package/package.json +67 -0
  6. package/src/App.tsx +153 -0
  7. package/src/application/trpc-client.ts +6 -0
  8. package/src/application/use-direction.ts +18 -0
  9. package/src/application/use-domains.ts +9 -0
  10. package/src/application/use-expansion.ts +42 -0
  11. package/src/application/use-filters.ts +78 -0
  12. package/src/application/use-graph.ts +38 -0
  13. package/src/application/use-reveal.ts +26 -0
  14. package/src/application/use-selection.ts +15 -0
  15. package/src/application/use-settings.ts +84 -0
  16. package/src/application/use-view-mode.ts +14 -0
  17. package/src/assets/fonts/Monor_Regular.otf +0 -0
  18. package/src/assets/fonts/Supreme-Variable.woff2 +0 -0
  19. package/src/assets/fonts/Supreme-VariableItalic.woff2 +0 -0
  20. package/src/assets/fonts/monor-bold.otf +0 -0
  21. package/src/assets/react.svg +1 -0
  22. package/src/cli.ts +29 -0
  23. package/src/components/direction-toggle.tsx +28 -0
  24. package/src/components/domain-header.tsx +44 -0
  25. package/src/components/export-dialog.tsx +164 -0
  26. package/src/components/filter-bar.tsx +17 -0
  27. package/src/components/header.tsx +37 -0
  28. package/src/components/inspector.tsx +183 -0
  29. package/src/components/kind-filter.tsx +70 -0
  30. package/src/components/node-badge.tsx +19 -0
  31. package/src/components/node-name.tsx +66 -0
  32. package/src/components/settings-menu.tsx +147 -0
  33. package/src/components/ui/badge.tsx +52 -0
  34. package/src/components/ui/button.tsx +56 -0
  35. package/src/components/ui/card.tsx +103 -0
  36. package/src/components/ui/checkbox.tsx +28 -0
  37. package/src/components/ui/dialog.tsx +108 -0
  38. package/src/components/ui/input.tsx +20 -0
  39. package/src/components/ui/popover.tsx +88 -0
  40. package/src/components/ui/scroll-area.tsx +54 -0
  41. package/src/components/ui/select.tsx +88 -0
  42. package/src/components/ui/separator.tsx +23 -0
  43. package/src/components/ui/toggle-group.tsx +89 -0
  44. package/src/components/ui/toggle.tsx +43 -0
  45. package/src/components/view-switcher.tsx +28 -0
  46. package/src/components/views/graph-view.tsx +1203 -0
  47. package/src/components/views/list-view.tsx +109 -0
  48. package/src/components/views/tree-view.tsx +485 -0
  49. package/src/domain/cypher-export.ts +66 -0
  50. package/src/domain/direction.ts +1 -0
  51. package/src/domain/domain-grouping.ts +217 -0
  52. package/src/domain/edge.ts +37 -0
  53. package/src/domain/filter.ts +21 -0
  54. package/src/domain/flatten-tree.ts +167 -0
  55. package/src/domain/graph.ts +42 -0
  56. package/src/domain/node.ts +28 -0
  57. package/src/domain/roots.ts +18 -0
  58. package/src/domain/traversal.ts +60 -0
  59. package/src/index.css +205 -0
  60. package/src/lib/utils.ts +6 -0
  61. package/src/main.tsx +16 -0
  62. package/src/server/router.ts +87 -0
  63. package/src/server/vite-plugin.ts +99 -0
  64. package/vite.config.ts +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Aetherall
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # React + TypeScript + Vite + shadcn/ui
2
+
3
+ This is a template for a new Vite project with React, TypeScript, and shadcn/ui.
4
+
5
+ ## Adding components
6
+
7
+ To add components to your app, run the following command:
8
+
9
+ ```bash
10
+ npx shadcn@latest add button
11
+ ```
12
+
13
+ This will place the ui components in the `src/components` directory.
14
+
15
+ ## Using components
16
+
17
+ To use the components in your app, import them as follows:
18
+
19
+ ```tsx
20
+ import { Button } from "@/components/ui/button"
21
+ ```
package/dist/cli.mjs ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import path from "node:path";
3
+ import { styleText } from "node:util";
4
+ import { createServer } from "vite";
5
+ //#region src/cli.ts
6
+ const dirname = typeof __dirname === "undefined" ? path.dirname(new URL(import.meta.url).pathname) : __dirname;
7
+ const server = await (await createServer({
8
+ root: path.resolve(dirname, "../"),
9
+ configFile: path.resolve(dirname, "../vite.config.ts"),
10
+ logLevel: "error"
11
+ })).listen(20031);
12
+ const SCAN_ROOT = path.resolve(process.env.EVENTVIZ_SCAN_ROOT ?? process.cwd());
13
+ console.log(styleText(["bold", "underline"], "Event Tree Viewer"));
14
+ console.log(` Status ${styleText("green", "running")}`);
15
+ console.log(` URL ${styleText("cyan", server.resolvedUrls?.local[0] ?? "unknown")}`);
16
+ console.log(` Root ${styleText("yellow", SCAN_ROOT)}`);
17
+ console.log();
18
+ console.log(styleText("dim", "Press Ctrl+C to stop the server"));
19
+ //#endregion
20
+ export {};
package/index.html ADDED
@@ -0,0 +1,13 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>vite-app</title>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@ddd-ts/event-tree-viewer",
3
+ "version": "0.0.0-eventviz.10",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "url": "git+https://github.com/ddd-ts/monorepo"
8
+ },
9
+ "bin": {
10
+ "event-tree-viewer": "./dist/cli.mjs"
11
+ },
12
+ "files": [
13
+ "./src",
14
+ "./vite.config.ts",
15
+ "./index.html",
16
+ "./dist"
17
+ ],
18
+ "dependencies": {
19
+ "@base-ui/react": "^1.4.1",
20
+ "@phosphor-icons/react": "^2.1.10",
21
+ "@tailwindcss/vite": "^4.2.1",
22
+ "@tanstack/react-query": "^5.100.11",
23
+ "@tanstack/react-virtual": "^3.13.24",
24
+ "@trpc/client": "^11",
25
+ "@trpc/server": "^11",
26
+ "@vitejs/plugin-react": "^5.2.0",
27
+ "class-variance-authority": "^0.7.1",
28
+ "clsx": "^2.1.1",
29
+ "elkjs": "^0.11.1",
30
+ "globals": "^16.5.0",
31
+ "launch-editor": "^2.13.2",
32
+ "react": "^19.2.4",
33
+ "react-dom": "^19.2.4",
34
+ "shadcn": "^4.7.0",
35
+ "tailwind-merge": "^3.6.0",
36
+ "tailwindcss": "^4.2.1",
37
+ "tw-animate-css": "^1.4.0",
38
+ "vite": "^7.3.1",
39
+ "zod": "^4.4.3",
40
+ "@ddd-ts/event-tree": "^0.0.0-eventviz.10"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "devDependencies": {
46
+ "@ddd-ts/tools": "0.0.0-eventviz.10",
47
+ "@eslint/js": "^9.39.4",
48
+ "@types/node": "^24.12.0",
49
+ "@types/react": "^19.2.14",
50
+ "@types/react-dom": "^19.2.3",
51
+ "eslint": "^9.39.4",
52
+ "eslint-plugin-react-hooks": "^7.0.1",
53
+ "eslint-plugin-react-refresh": "^0.5.2",
54
+ "prettier": "^3.8.1",
55
+ "prettier-plugin-tailwindcss": "^0.7.2",
56
+ "typescript": "~5.9.3",
57
+ "typescript-eslint": "^8.57.1"
58
+ },
59
+ "scripts": {
60
+ "dev": "vite",
61
+ "lint": "eslint .",
62
+ "format": "prettier --write \"**/*.{ts,tsx}\"",
63
+ "typecheck": "tsc --noEmit",
64
+ "preview": "vite preview",
65
+ "build": "tsdown --config node_modules/@ddd-ts/tools/tsdown.config.js --no-exports --deps.skipNodeModulesBundle --format esm src/cli.ts"
66
+ }
67
+ }
package/src/App.tsx ADDED
@@ -0,0 +1,153 @@
1
+ import { Activity } from "react"
2
+ import { useGraph } from "@/application/use-graph"
3
+ import { useFilters } from "@/application/use-filters"
4
+ import { useSelection } from "@/application/use-selection"
5
+ import { useViewMode } from "@/application/use-view-mode"
6
+ import { useDirection } from "@/application/use-direction"
7
+ import { useDomains } from "@/application/use-domains"
8
+ import { useSettings } from "@/application/use-settings"
9
+ import { useExpansion } from "@/application/use-expansion"
10
+ import { Button } from "@/components/ui/button"
11
+ import { Header } from "@/components/header"
12
+ import { FilterBar } from "@/components/filter-bar"
13
+ import { ViewSwitcher } from "@/components/view-switcher"
14
+ import { DirectionToggle } from "@/components/direction-toggle"
15
+ import { Inspector } from "@/components/inspector"
16
+ import { ListView } from "@/components/views/list-view"
17
+ import { TreeView } from "@/components/views/tree-view"
18
+ import { GraphView } from "@/components/views/graph-view"
19
+
20
+ export function App() {
21
+ const { index, status, error, refetch } = useGraph()
22
+ const domains = useDomains(index)
23
+ const direction = useDirection()
24
+ const filters = useFilters(index)
25
+ const selection = useSelection()
26
+ const viewMode = useViewMode()
27
+ const settings = useSettings()
28
+ const expansion = useExpansion()
29
+
30
+ return (
31
+ <div className="flex h-svh flex-col bg-background">
32
+ <Header
33
+ index={index}
34
+ visibleNodes={filters.visibleNodes}
35
+ settings={settings}
36
+ />
37
+ <FilterBar filters={filters} />
38
+ <div className="flex items-center justify-between gap-3 border-b px-6 py-2">
39
+ <ViewSwitcher view={viewMode} />
40
+ {viewMode.view === "tree" && (
41
+ <div className="flex items-center gap-2">
42
+ <div className="flex items-center -space-x-px">
43
+ <Button variant="outline" size="sm" onClick={expansion.expandAll}>
44
+ Expand
45
+ </Button>
46
+ <Button
47
+ variant="outline"
48
+ size="sm"
49
+ onClick={expansion.collapseAll}
50
+ >
51
+ Collapse
52
+ </Button>
53
+ </div>
54
+ <DirectionToggle direction={direction} />
55
+ </div>
56
+ )}
57
+ {viewMode.view === "graph" && (
58
+ <div className="flex items-center gap-2">
59
+ <div className="flex items-center -space-x-px">
60
+ <Button variant="outline" size="sm" onClick={expansion.expandAll}>
61
+ Expand
62
+ </Button>
63
+ <Button
64
+ variant="outline"
65
+ size="sm"
66
+ onClick={expansion.collapseAll}
67
+ >
68
+ Collapse
69
+ </Button>
70
+ </div>
71
+ <DirectionToggle direction={direction} />
72
+ </div>
73
+ )}
74
+ </div>
75
+
76
+ <main className="flex min-h-0 flex-1">
77
+ <div className="min-w-0 flex-1">
78
+ {status === "loading" && (
79
+ <p className="px-6 py-4 text-sm text-muted-foreground">
80
+ Scanning project…
81
+ </p>
82
+ )}
83
+ {status === "error" && (
84
+ <div className="px-6 py-4 text-sm">
85
+ <p className="text-destructive">Failed to load graph: {error}</p>
86
+ <button
87
+ type="button"
88
+ onClick={refetch}
89
+ className="mt-2 text-muted-foreground underline"
90
+ >
91
+ Retry
92
+ </button>
93
+ </div>
94
+ )}
95
+ {status === "ready" && (
96
+ <>
97
+ <Activity
98
+ mode={viewMode.view === "list" ? "visible" : "hidden"}
99
+ name="list-view"
100
+ >
101
+ <ListView
102
+ nodes={filters.visibleNodes}
103
+ selectedId={selection.selectedId}
104
+ onSelect={selection.select}
105
+ />
106
+ </Activity>
107
+ <Activity
108
+ mode={viewMode.view === "tree" ? "visible" : "hidden"}
109
+ name="tree-view"
110
+ >
111
+ <TreeView
112
+ index={index}
113
+ visibleNodes={filters.visibleNodes}
114
+ domains={domains}
115
+ direction={direction.direction}
116
+ settings={settings.settings}
117
+ expansion={expansion}
118
+ selectedId={selection.selectedId}
119
+ onSelect={selection.select}
120
+ />
121
+ </Activity>
122
+ <Activity
123
+ mode={viewMode.view === "graph" ? "visible" : "hidden"}
124
+ name="graph-view"
125
+ >
126
+ <GraphView
127
+ index={index}
128
+ visibleNodes={filters.visibleNodes}
129
+ domains={domains}
130
+ direction={direction.direction}
131
+ settings={settings.settings}
132
+ expansion={expansion}
133
+ selectedId={selection.selectedId}
134
+ onSelect={selection.select}
135
+ />
136
+ </Activity>
137
+ </>
138
+ )}
139
+ </div>
140
+ {selection.selectedId && (
141
+ <Inspector
142
+ index={index}
143
+ selectedId={selection.selectedId}
144
+ onSelect={selection.select}
145
+ onClose={selection.clear}
146
+ />
147
+ )}
148
+ </main>
149
+ </div>
150
+ )
151
+ }
152
+
153
+ export default App
@@ -0,0 +1,6 @@
1
+ import { createTRPCClient, httpBatchLink } from "@trpc/client"
2
+ import type { AppRouter } from "@/server/router"
3
+
4
+ export const trpc = createTRPCClient<AppRouter>({
5
+ links: [httpBatchLink({ url: "/trpc" })],
6
+ })
@@ -0,0 +1,18 @@
1
+ import { useCallback, useState } from "react"
2
+ import type { Direction } from "@/domain/direction"
3
+
4
+ export interface DirectionApi {
5
+ direction: Direction
6
+ setDirection: (d: Direction) => void
7
+ toggle: () => void
8
+ }
9
+
10
+ export function useDirection(initial: Direction = "forward"): DirectionApi {
11
+ const [direction, setDirection] = useState<Direction>(initial)
12
+ const set = useCallback((d: Direction) => setDirection(d), [])
13
+ const toggle = useCallback(
14
+ () => setDirection((d) => (d === "forward" ? "reverse" : "forward")),
15
+ []
16
+ )
17
+ return { direction, setDirection: set, toggle }
18
+ }
@@ -0,0 +1,9 @@
1
+ import { useMemo } from "react"
2
+ import { computeDomains, type NodeDomain } from "@/domain/domain-grouping"
3
+ import type { GraphIndex, NodeId } from "@/domain/graph"
4
+
5
+ export type DomainMap = ReadonlyMap<NodeId, NodeDomain>
6
+
7
+ export function useDomains(index: GraphIndex): DomainMap {
8
+ return useMemo(() => computeDomains(index.graph.nodes), [index])
9
+ }
@@ -0,0 +1,42 @@
1
+ import { useCallback, useMemo, useState } from "react"
2
+
3
+ export interface ExpansionApi {
4
+ isExpanded: (path: string) => boolean
5
+ toggle: (path: string) => void
6
+ expandAll: () => void
7
+ collapseAll: () => void
8
+ }
9
+
10
+ type State = { mode: "expanded" | "collapsed"; overrides: Set<string> }
11
+
12
+ const EXPANDED: State = { mode: "expanded", overrides: new Set() }
13
+ const COLLAPSED: State = { mode: "collapsed", overrides: new Set() }
14
+
15
+ export function useExpansion(): ExpansionApi {
16
+ const [state, setState] = useState<State>(EXPANDED)
17
+
18
+ const isExpanded = useCallback(
19
+ (path: string) => {
20
+ const overridden = state.overrides.has(path)
21
+ return state.mode === "expanded" ? !overridden : overridden
22
+ },
23
+ [state]
24
+ )
25
+
26
+ const toggle = useCallback((path: string) => {
27
+ setState((prev) => {
28
+ const next = new Set(prev.overrides)
29
+ if (next.has(path)) next.delete(path)
30
+ else next.add(path)
31
+ return { mode: prev.mode, overrides: next }
32
+ })
33
+ }, [])
34
+
35
+ const expandAll = useCallback(() => setState(EXPANDED), [])
36
+ const collapseAll = useCallback(() => setState(COLLAPSED), [])
37
+
38
+ return useMemo(
39
+ () => ({ isExpanded, toggle, expandAll, collapseAll }),
40
+ [isExpanded, toggle, expandAll, collapseAll]
41
+ )
42
+ }
@@ -0,0 +1,78 @@
1
+ import { useMemo, useState, useCallback } from "react"
2
+ import { NODE_KINDS, type NodeKind } from "@/domain/node"
3
+ import { matchesFilter, type NodeFilter } from "@/domain/filter"
4
+ import { nodeId, type GraphIndex, type NodeId } from "@/domain/graph"
5
+
6
+ export interface FiltersApi {
7
+ filter: NodeFilter
8
+ visibleNodes: GraphIndex["graph"]["nodes"]
9
+ setSearch: (value: string) => void
10
+ toggleKind: (kind: NodeKind) => void
11
+ reset: () => void
12
+ }
13
+
14
+ const ALL_KINDS = new Set<NodeKind>(NODE_KINDS)
15
+
16
+ export function useFilters(index: GraphIndex): FiltersApi {
17
+ const [search, setSearch] = useState("")
18
+ const [kinds, setKinds] = useState<ReadonlySet<NodeKind>>(ALL_KINDS)
19
+
20
+ const filter = useMemo<NodeFilter>(() => ({ search, kinds }), [search, kinds])
21
+
22
+ const visibleNodes = useMemo(() => {
23
+ const passingKind = index.graph.nodes.filter((n) => filter.kinds.has(n.type))
24
+ if (!filter.search.trim()) return passingKind
25
+ const directMatches = passingKind.filter((n) => matchesFilter(n, filter))
26
+ if (directMatches.length === 0) return []
27
+ const expanded = expandConnected(index, directMatches)
28
+ return passingKind.filter((n) => expanded.has(nodeId(n.type, n.name)))
29
+ }, [index, filter])
30
+
31
+ const toggleKind = useCallback((kind: NodeKind) => {
32
+ setKinds((prev) => {
33
+ const next = new Set(prev)
34
+ if (next.has(kind)) next.delete(kind)
35
+ else next.add(kind)
36
+ return next
37
+ })
38
+ }, [])
39
+
40
+ const reset = useCallback(() => {
41
+ setSearch("")
42
+ setKinds(ALL_KINDS)
43
+ }, [])
44
+
45
+ return { filter, visibleNodes, setSearch, toggleKind, reset }
46
+ }
47
+
48
+ function expandConnected(
49
+ index: GraphIndex,
50
+ matches: GraphIndex["graph"]["nodes"]
51
+ ): Set<string> {
52
+ const visible = new Set<string>()
53
+ const seeds: string[] = []
54
+ for (const n of matches) {
55
+ const id = nodeId(n.type, n.name) as string
56
+ if (!visible.has(id)) {
57
+ visible.add(id)
58
+ seeds.push(id)
59
+ }
60
+ }
61
+ const bfs = (start: string[], edgeMap: GraphIndex["outgoing"], side: "to" | "from") => {
62
+ const queue = [...start]
63
+ while (queue.length) {
64
+ const id = queue.shift()!
65
+ for (const edge of edgeMap.get(id as NodeId) ?? []) {
66
+ const peer = edge[side]
67
+ const peerId = nodeId(peer.type, peer.name) as string
68
+ if (!visible.has(peerId)) {
69
+ visible.add(peerId)
70
+ queue.push(peerId)
71
+ }
72
+ }
73
+ }
74
+ }
75
+ bfs(seeds, index.outgoing, "to")
76
+ bfs(seeds, index.incoming, "from")
77
+ return visible
78
+ }
@@ -0,0 +1,38 @@
1
+ import { useMemo } from "react"
2
+ import { useQuery } from "@tanstack/react-query"
3
+ import { indexGraph, type GraphIndex } from "@/domain/graph"
4
+ import { trpc } from "./trpc-client"
5
+
6
+ export interface UseGraphResult {
7
+ status: "loading" | "ready" | "error"
8
+ index: GraphIndex
9
+ error: string | null
10
+ refetch: () => void
11
+ }
12
+
13
+ const EMPTY: GraphIndex = indexGraph({ nodes: [], edges: [] })
14
+
15
+ export function useGraph(): UseGraphResult {
16
+ const { data, error, refetch, isPending } = useQuery({
17
+ queryKey: ["graph"],
18
+ queryFn: () =>
19
+ trpc.graph.get.query() as Promise<{
20
+ nodes: unknown[]
21
+ edges: unknown[]
22
+ }>,
23
+ })
24
+
25
+ const index = useMemo(() => {
26
+ if (!data) return EMPTY
27
+ return indexGraph(data as Parameters<typeof indexGraph>[0])
28
+ }, [data])
29
+
30
+ return {
31
+ status: error ? "error" : isPending ? "loading" : "ready",
32
+ index,
33
+ error: error ? String(error.message ?? error) : null,
34
+ refetch: () => {
35
+ void refetch()
36
+ },
37
+ }
38
+ }
@@ -0,0 +1,26 @@
1
+ import { useCallback, useMemo, useState } from "react"
2
+
3
+ export interface RevealApi {
4
+ isRevealed: (path: string) => boolean
5
+ toggle: (path: string) => void
6
+ }
7
+
8
+ export function useReveal(): RevealApi {
9
+ const [revealed, setRevealed] = useState<Set<string>>(() => new Set())
10
+
11
+ const isRevealed = useCallback(
12
+ (path: string) => revealed.has(path),
13
+ [revealed]
14
+ )
15
+
16
+ const toggle = useCallback((path: string) => {
17
+ setRevealed((prev) => {
18
+ const next = new Set(prev)
19
+ if (next.has(path)) next.delete(path)
20
+ else next.add(path)
21
+ return next
22
+ })
23
+ }, [])
24
+
25
+ return useMemo(() => ({ isRevealed, toggle }), [isRevealed, toggle])
26
+ }
@@ -0,0 +1,15 @@
1
+ import { useCallback, useState } from "react"
2
+ import { type NodeId } from "@/domain/graph"
3
+
4
+ export interface SelectionApi {
5
+ selectedId: NodeId | null
6
+ select: (id: NodeId) => void
7
+ clear: () => void
8
+ }
9
+
10
+ export function useSelection(): SelectionApi {
11
+ const [selectedId, setSelectedId] = useState<NodeId | null>(null)
12
+ const select = useCallback((id: NodeId) => setSelectedId(id), [])
13
+ const clear = useCallback(() => setSelectedId(null), [])
14
+ return { selectedId, select, clear }
15
+ }
@@ -0,0 +1,84 @@
1
+ import {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useState,
6
+ useSyncExternalStore,
7
+ } from "react"
8
+
9
+ export type FontSize = "sm" | "md" | "lg"
10
+ export type Theme = "light" | "auto" | "dark"
11
+
12
+ export interface Settings {
13
+ hideDomainPrefix: boolean
14
+ fontSize: FontSize
15
+ theme: Theme
16
+ }
17
+
18
+ type BoolKey = {
19
+ [K in keyof Settings]: Settings[K] extends boolean ? K : never
20
+ }[keyof Settings]
21
+
22
+ export interface SettingsApi {
23
+ settings: Settings
24
+ toggle: (key: BoolKey) => void
25
+ setFontSize: (size: FontSize) => void
26
+ setTheme: (theme: Theme) => void
27
+ }
28
+
29
+ const DEFAULTS: Settings = {
30
+ hideDomainPrefix: true,
31
+ fontSize: "md",
32
+ theme: "auto",
33
+ }
34
+
35
+ export function useSettings(initial: Partial<Settings> = {}): SettingsApi {
36
+ const [settings, setSettings] = useState<Settings>({
37
+ ...DEFAULTS,
38
+ ...initial,
39
+ })
40
+ const prefersDark = usePrefersDark()
41
+
42
+ useEffect(() => {
43
+ const root = document.documentElement
44
+ const dark =
45
+ settings.theme === "dark" || (settings.theme === "auto" && prefersDark)
46
+ root.classList.add("theme-switching")
47
+ root.classList.toggle("dark", dark)
48
+ const id = requestAnimationFrame(() => {
49
+ root.classList.remove("theme-switching")
50
+ })
51
+ return () => cancelAnimationFrame(id)
52
+ }, [settings.theme, prefersDark])
53
+
54
+ const toggle = useCallback((key: BoolKey) => {
55
+ setSettings((prev) => ({ ...prev, [key]: !prev[key] }))
56
+ }, [])
57
+
58
+ const setFontSize = useCallback((fontSize: FontSize) => {
59
+ setSettings((prev) => ({ ...prev, fontSize }))
60
+ }, [])
61
+
62
+ const setTheme = useCallback((theme: Theme) => {
63
+ setSettings((prev) => ({ ...prev, theme }))
64
+ }, [])
65
+
66
+ return useMemo(
67
+ () => ({ settings, toggle, setFontSize, setTheme }),
68
+ [settings, toggle, setFontSize, setTheme]
69
+ )
70
+ }
71
+
72
+ function usePrefersDark(): boolean {
73
+ return useSyncExternalStore(
74
+ subscribePrefersDark,
75
+ () => window.matchMedia("(prefers-color-scheme: dark)").matches,
76
+ () => false
77
+ )
78
+ }
79
+
80
+ function subscribePrefersDark(onChange: () => void): () => void {
81
+ const mql = window.matchMedia("(prefers-color-scheme: dark)")
82
+ mql.addEventListener("change", onChange)
83
+ return () => mql.removeEventListener("change", onChange)
84
+ }
@@ -0,0 +1,14 @@
1
+ import { useCallback, useState } from "react"
2
+
3
+ export type ViewMode = "list" | "tree" | "graph"
4
+
5
+ export interface ViewModeApi {
6
+ view: ViewMode
7
+ setView: (view: ViewMode) => void
8
+ }
9
+
10
+ export function useViewMode(initial: ViewMode = "tree"): ViewModeApi {
11
+ const [view, setView] = useState<ViewMode>(initial)
12
+ const set = useCallback((next: ViewMode) => setView(next), [])
13
+ return { view, setView: set }
14
+ }
Binary file
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>