effect-atom-svelte-devtools 0.0.0-stage → 0.2.0
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.
- package/LICENSE +21 -0
- package/README.md +86 -2
- package/dist/atom-devtools.svelte +585 -0
- package/dist/atom-devtools.svelte.d.ts +28 -0
- package/dist/graph/atom-graph.svelte +244 -0
- package/dist/graph/atom-graph.svelte.d.ts +38 -0
- package/dist/graph/frame-graph.svelte +408 -0
- package/dist/graph/frame-graph.svelte.d.ts +52 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.js +7 -0
- package/dist/graph/layout.d.ts +65 -0
- package/dist/graph/layout.js +531 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/internal/format.d.ts +20 -0
- package/dist/internal/format.js +138 -0
- package/dist/internal/graph-view.svelte +127 -0
- package/dist/internal/graph-view.svelte.d.ts +10 -0
- package/dist/internal/label.d.ts +35 -0
- package/dist/internal/label.js +139 -0
- package/dist/internal/model.svelte.d.ts +75 -0
- package/dist/internal/model.svelte.js +286 -0
- package/dist/internal/names.d.ts +29 -0
- package/dist/internal/names.js +55 -0
- package/dist/internal/sheets-view.svelte +446 -0
- package/dist/internal/sheets-view.svelte.d.ts +11 -0
- package/dist/internal/timeline-view.svelte +291 -0
- package/dist/internal/timeline-view.svelte.d.ts +9 -0
- package/dist/internal/transform.d.ts +17 -0
- package/dist/internal/transform.js +401 -0
- package/dist/vite.d.ts +52 -0
- package/dist/vite.js +97 -0
- package/package.json +78 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jarred Norris
|
|
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
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# effect-atom-svelte-devtools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Developer tools for [effect-atom-svelte](https://atom.jarrednorris.dev): a panel that shows your atom registry live, and a Vite plugin that names your atoms after their variables and keeps their state across hot reloads.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bun add -D effect-atom-svelte-devtools
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It reads effect-atom-svelte's inspector, which is new in effect-atom-svelte 0.2: devtools 0.2 goes with effect-atom-svelte 0.2.
|
|
10
|
+
|
|
11
|
+
## The panel
|
|
12
|
+
|
|
13
|
+
`<AtomDevtools />` docks a panel along the bottom of the window that shows your app's atom registry live. Put it inside your `RegistryProvider`, behind Vite's `import.meta.env.DEV`, so production builds leave it out entirely:
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<!-- src/routes/+layout.svelte -->
|
|
17
|
+
<RegistryProvider>
|
|
18
|
+
{@render children()}
|
|
19
|
+
{#if import.meta.env.DEV}
|
|
20
|
+
{#await import("effect-atom-svelte-devtools") then { AtomDevtools }}
|
|
21
|
+
<AtomDevtools />
|
|
22
|
+
{/await}
|
|
23
|
+
{/if}
|
|
24
|
+
</RegistryProvider>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Use `import.meta.env.DEV` rather than SvelteKit's `dev`: Vite replaces it with `false` in a build, so the import is dropped, where `dev` leaves the panel's code in the build unused.
|
|
28
|
+
|
|
29
|
+
Closed, it's a small "Atoms" button in the corner with the registry's count. Open, drag its top line to make it taller or shorter (double-click to reset; with the keyboard, focus it and use the arrow keys), or enlarge it to most of the window; the page gets room below it while it's open, and Escape closes it while focus is inside it. It's drawn in hairlines with mono labels, in the page's own colours where your app has shadcn-style tokens (`--background`, `--foreground`, `--border`, `--brand`), and in zinc and amber, light or dark, where it doesn't. Its bar counts the registry's atoms, readers, updates and interruptions.
|
|
30
|
+
|
|
31
|
+
It has three views:
|
|
32
|
+
|
|
33
|
+
- **Graph**: the atoms and what reads what, laid out on tracks with sources on the left, as the effect-atom-svelte docs draw their examples. A value that changes rings, in green when it's a `Success` and red when it's a `Failure`; a cross marks an interrupted effect or a removed atom; a family's atoms share a row of dots. Click an atom to open its sheet. "Plumbing" shows the atoms runtimes, mutations and stores make, which are hidden by default; an atom that reads one is linked to whatever is upstream of it.
|
|
34
|
+
- **Sheets**: a cover sheet with the registry's totals, then one sheet per atom: its value or `AsyncResult` state, what it reads and what reads it, what happened to it lately, and a title block with where it was declared (click to open it in your editor), keep-alive, idle TTL and readers.
|
|
35
|
+
- **Timeline**: every computation, update, interruption and finalizer, newest first. A computation says why it ran: its first read, a refresh, or which atoms it reads changed. Click an atom to see only its rows.
|
|
36
|
+
|
|
37
|
+
It follows the registry of the nearest `RegistryProvider`, or a `registry` you pass it. With more than one provider mounted, a picker switches between them. It reads what the registry does through `effect-atom-svelte/inspector`, which starts watching when the panel mounts and costs nothing before.
|
|
38
|
+
|
|
39
|
+
## The graph
|
|
40
|
+
|
|
41
|
+
The graph the panel draws is also yours to use, from `effect-atom-svelte-devtools/graph`. It has no dependencies beyond Svelte, so unlike the panel it can go in production pages: the effect-atom-svelte docs draw each example's atoms with it, from an inspector scope.
|
|
42
|
+
|
|
43
|
+
- `layoutGraph({ atoms, links, readers }, width)` lays atoms, the links between them and the components that read them out on tracks.
|
|
44
|
+
- `<AtomGraph graph={…} />` draws a layout live. Call its `pulse(id, tone)` when an atom's value changes and `interrupt(id)` when its effect is interrupted; give it `onselect` to make atoms clickable.
|
|
45
|
+
- `<FrameGraph nodes={…} edges={…} />` draws nodes and edges you place yourself, on a frame's 1px lines.
|
|
46
|
+
|
|
47
|
+
It reads your page's design tokens where it has them and falls back to a neutral palette.
|
|
48
|
+
|
|
49
|
+
## Atom names
|
|
50
|
+
|
|
51
|
+
Most atoms have no label, so tools can only show them as "atom". `atomLabels()` labels each atom declared at the top level of a module, or of a component's `<script>` or `<script module>`, with its variable's name and where it is declared:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
export const todosAtom = Atom.make(...)
|
|
55
|
+
// todosAtom.label: ["todosAtom", "at todosAtom (/src/lib/todos.ts:4:14)"]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// vite.config.ts
|
|
60
|
+
import { sveltekit } from "@sveltejs/kit/vite";
|
|
61
|
+
import { atomLabels } from "effect-atom-svelte-devtools/vite";
|
|
62
|
+
import { defineConfig } from "vite";
|
|
63
|
+
|
|
64
|
+
export default defineConfig({
|
|
65
|
+
plugins: [atomLabels(), sveltekit()],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- Only the dev server applies it. Production builds are left as they are.
|
|
70
|
+
- Put it before `sveltekit()` or `svelte()`, so it sees components before they are compiled. It warns if it comes after.
|
|
71
|
+
- The atom is labelled in place and keeps its identity. `Atom.withLabel` would return a copy.
|
|
72
|
+
- A label your code sets with `Atom.withLabel` wins. The one an `Atom.serializable` atom takes from its key (an RPC query's `AtomRpc:listTodos:home-todos`) gives way to the variable's name.
|
|
73
|
+
- Members of an `Atom.family` are labelled with their argument, as `todoAtom(3)`.
|
|
74
|
+
- A call to a function whose name ends in `Atom` (`mapDraftAtom(key)`, `makeSessionAtom(user)`) names the atom it returns after the call and its arguments, as `mapDraftAtom({"doc":1})`. Every call's atom is named, so two atoms made for equal keys share a name: what a hand-rolled cache that keeps making new atoms looks like. A more specific label wins: a family's, a top-level variable's, or one your code set. Only plain calls count, not methods (`store.todoAtom(1)`).
|
|
75
|
+
- It wraps any top-level `const x = f(...)` and checks at run time whether the value is an atom, so `runtime.atom(...)`, `TodosRpc.query(...)` and your own helpers are labelled too. Runes and `use*` hooks are left alone.
|
|
76
|
+
- An atom in a top-level object literal is named by its path: `const pair = { todosAtom: Atom.make(...) }` labels `pair.todosAtom`.
|
|
77
|
+
- Inside functions, only `Atom.*` calls are labelled, so a function that makes atoms names them without every other call in it being wrapped.
|
|
78
|
+
- Atoms in mdsvex (`.md`) pages aren't labelled.
|
|
79
|
+
- Each component's instance script also starts by naming the component (`Counter`, from `counter.svelte`), so an inspector scope (`provideInspectorScope` in `effect-atom-svelte/inspector`) can say which component reads each atom.
|
|
80
|
+
|
|
81
|
+
## State across hot reloads
|
|
82
|
+
|
|
83
|
+
A hot reload runs a module again, which makes new atoms, so state written to them is lost. With the plugin, a state atom a module declares (`Atom.make` of a plain value, such as `Atom.make(0)` or `Atom.make([]).pipe(Atom.keepAlive)`, in a module or a `<script module>`) takes the value of the atom it replaces. Edit a component and its counters keep their counts.
|
|
84
|
+
|
|
85
|
+
- Edit the atom's own declaration and it starts from its new value: the old one no longer applies.
|
|
86
|
+
- Derived atoms compute again from the kept values, and effects run again, as their code may have changed.
|
|
87
|
+
- Atoms in a component's `<script>` aren't kept: there is one per instance, so there is no telling which old one a new one replaces.
|
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A panel docked along the bottom of the window that shows the atom registry live: its dependency
|
|
4
|
+
graph, a sheet per atom and a timeline of everything it does. Development only: in a production
|
|
5
|
+
build, or on the server, it renders nothing.
|
|
6
|
+
|
|
7
|
+
It's drawn like the effect-atom-svelte docs: ruled in hairlines, with mono labels, numbered views
|
|
8
|
+
and an amber accent, in the page's own colours where it has them (--background, --foreground,
|
|
9
|
+
--border, --brand and the rest) and the docs' zinc and amber where it doesn't. Drag its top line
|
|
10
|
+
to make it taller or shorter; the page gets room below it for as long as it's open.
|
|
11
|
+
|
|
12
|
+
It follows the registry of the nearest `RegistryProvider`, or the one given as `registry`. When
|
|
13
|
+
the app has several, a picker in the panel switches between them.
|
|
14
|
+
|
|
15
|
+
Render it only in development, behind Vite's `DEV` flag, so a build leaves it out: the README
|
|
16
|
+
shows how.
|
|
17
|
+
-->
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { BROWSER, DEV } from "esm-env";
|
|
20
|
+
import type { AtomRegistry } from "effect/reactivity";
|
|
21
|
+
import { getRegistry } from "effect-atom-svelte";
|
|
22
|
+
import { inspect, watchRegistries } from "effect-atom-svelte/inspector";
|
|
23
|
+
import { onMount, tick } from "svelte";
|
|
24
|
+
|
|
25
|
+
import GraphView from "./internal/graph-view.svelte";
|
|
26
|
+
import { Model } from "./internal/model.svelte.js";
|
|
27
|
+
import SheetsView from "./internal/sheets-view.svelte";
|
|
28
|
+
import TimelineView from "./internal/timeline-view.svelte";
|
|
29
|
+
|
|
30
|
+
interface Props {
|
|
31
|
+
/** The registry to show. Defaults to the nearest `RegistryProvider`'s. */
|
|
32
|
+
readonly registry?: AtomRegistry.AtomRegistry | undefined;
|
|
33
|
+
/** Whether the panel starts open. Defaults to how it was left. */
|
|
34
|
+
readonly open?: boolean | undefined;
|
|
35
|
+
/** Light paper, a dark blueprint, or the page's own (`auto`: a `dark` class on `<html>`, or the system's). */
|
|
36
|
+
readonly theme?: "auto" | "light" | "dark" | undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const { registry, open: startOpen, theme = "auto" }: Props = $props();
|
|
40
|
+
|
|
41
|
+
type Tab = "graph" | "sheets" | "timeline";
|
|
42
|
+
interface Saved {
|
|
43
|
+
readonly open: boolean;
|
|
44
|
+
readonly tab: Tab;
|
|
45
|
+
readonly plumbing: boolean;
|
|
46
|
+
readonly expanded: boolean;
|
|
47
|
+
readonly height: number;
|
|
48
|
+
}
|
|
49
|
+
const storageKey = "effect-atom-svelte-devtools";
|
|
50
|
+
const load = (): Partial<Saved> => {
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(localStorage.getItem(storageKey) ?? "{}") as Partial<Saved>;
|
|
53
|
+
} catch {
|
|
54
|
+
return {};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const enabled = DEV && BROWSER;
|
|
59
|
+
// The registry in context, read while the component sets up, as context must be.
|
|
60
|
+
// svelte-ignore state_referenced_locally
|
|
61
|
+
const nearest = enabled ? (registry ?? getRegistry()) : undefined;
|
|
62
|
+
|
|
63
|
+
let mounted = $state(false);
|
|
64
|
+
let open = $state(false);
|
|
65
|
+
let tab = $state<Tab>("graph");
|
|
66
|
+
let showPlumbing = $state(false);
|
|
67
|
+
let expanded = $state(false);
|
|
68
|
+
// The dock's height, in pixels, when not enlarged; dragging its top line changes it.
|
|
69
|
+
let height = $state(320);
|
|
70
|
+
let innerHeight = $state(800);
|
|
71
|
+
let selected = $state<number>();
|
|
72
|
+
let dark = $state(false);
|
|
73
|
+
let registries = $state.raw<readonly AtomRegistry.AtomRegistry[]>([]);
|
|
74
|
+
let chosen = $state.raw<AtomRegistry.AtomRegistry | undefined>(nearest);
|
|
75
|
+
let model = $state.raw<Model>();
|
|
76
|
+
let dock = $state<HTMLElement>();
|
|
77
|
+
let launcher = $state<HTMLElement>();
|
|
78
|
+
// Opened from the launcher, the dock takes focus; opened as it was left, on load, it doesn't.
|
|
79
|
+
let focusOnOpen = false;
|
|
80
|
+
|
|
81
|
+
onMount(() => {
|
|
82
|
+
if (!enabled) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const saved = load();
|
|
86
|
+
open = startOpen ?? saved.open ?? false;
|
|
87
|
+
tab = saved.tab ?? "graph";
|
|
88
|
+
showPlumbing = saved.plumbing ?? false;
|
|
89
|
+
expanded = saved.expanded ?? false;
|
|
90
|
+
height = saved.height ?? 320;
|
|
91
|
+
mounted = true;
|
|
92
|
+
|
|
93
|
+
const stopWatching = watchRegistries((list) => {
|
|
94
|
+
// A registry given as a prop stays in the picker, even one no provider holds.
|
|
95
|
+
registries = registry !== undefined && !list.includes(registry) ? [registry, ...list] : list;
|
|
96
|
+
if (chosen === undefined || !registries.includes(chosen)) {
|
|
97
|
+
chosen = nearest !== undefined && registries.includes(nearest) ? nearest : (registries[0] ?? nearest);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// The page's theme: a `dark` or `light` class on <html>, or the system's.
|
|
102
|
+
const root = document.documentElement;
|
|
103
|
+
const media = matchMedia("(prefers-color-scheme: dark)");
|
|
104
|
+
const readTheme = () => {
|
|
105
|
+
dark =
|
|
106
|
+
theme === "dark" ||
|
|
107
|
+
(theme === "auto" &&
|
|
108
|
+
(root.classList.contains("dark") ||
|
|
109
|
+
(!root.classList.contains("light") && media.matches)));
|
|
110
|
+
};
|
|
111
|
+
readTheme();
|
|
112
|
+
const observer = new MutationObserver(readTheme);
|
|
113
|
+
observer.observe(root, { attributeFilter: ["class"], attributes: true });
|
|
114
|
+
media.addEventListener("change", readTheme);
|
|
115
|
+
return () => {
|
|
116
|
+
stopWatching();
|
|
117
|
+
observer.disconnect();
|
|
118
|
+
media.removeEventListener("change", readTheme);
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// One model per registry shown, following it from the moment it is chosen, open or not, so the
|
|
123
|
+
// timeline has the page's history when the panel opens.
|
|
124
|
+
$effect(() => {
|
|
125
|
+
if (!enabled || chosen === undefined) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const next = new Model(inspect(chosen));
|
|
129
|
+
model = next;
|
|
130
|
+
selected = undefined;
|
|
131
|
+
return next.start();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
$effect(() => {
|
|
135
|
+
if (!enabled || !mounted) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const saved: Saved = { expanded, height, open, plumbing: showPlumbing, tab };
|
|
139
|
+
try {
|
|
140
|
+
localStorage.setItem(storageKey, JSON.stringify(saved));
|
|
141
|
+
} catch {
|
|
142
|
+
// Storage may be full or turned off; the panel then starts as it starts.
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// How tall the dock is drawn: enlarged, it takes most of the window; otherwise what was dragged,
|
|
147
|
+
// kept between a usable minimum and most of the window.
|
|
148
|
+
const shown = $derived(
|
|
149
|
+
expanded ? Math.round(innerHeight * 0.85) : Math.min(Math.max(height, 160), innerHeight * 0.85)
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// While open, the page gets room below its end, so the dock never hides the last of it.
|
|
153
|
+
$effect(() => {
|
|
154
|
+
if (!enabled || !open || !mounted) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const { body } = document;
|
|
158
|
+
const before = body.style.paddingBottom;
|
|
159
|
+
body.style.paddingBottom = `${shown}px`;
|
|
160
|
+
return () => {
|
|
161
|
+
body.style.paddingBottom = before;
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
/** Drags the dock's top line: the dock follows the pointer until it's let go. */
|
|
166
|
+
const resize = (event: PointerEvent) => {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
const handle = event.currentTarget as HTMLElement;
|
|
169
|
+
handle.setPointerCapture(event.pointerId);
|
|
170
|
+
const start = event.clientY;
|
|
171
|
+
const from = shown;
|
|
172
|
+
expanded = false;
|
|
173
|
+
const move = (next: PointerEvent) => {
|
|
174
|
+
height = Math.round(from + start - next.clientY);
|
|
175
|
+
};
|
|
176
|
+
const stop = () => {
|
|
177
|
+
handle.removeEventListener("pointermove", move);
|
|
178
|
+
handle.removeEventListener("pointerup", stop);
|
|
179
|
+
handle.removeEventListener("pointercancel", stop);
|
|
180
|
+
};
|
|
181
|
+
handle.addEventListener("pointermove", move);
|
|
182
|
+
handle.addEventListener("pointerup", stop);
|
|
183
|
+
handle.addEventListener("pointercancel", stop);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
$effect(() => {
|
|
187
|
+
if (dock !== undefined && focusOnOpen) {
|
|
188
|
+
focusOnOpen = false;
|
|
189
|
+
dock.focus();
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const openPanel = () => {
|
|
194
|
+
focusOnOpen = true;
|
|
195
|
+
open = true;
|
|
196
|
+
};
|
|
197
|
+
/** Closes the dock; focus inside it goes back to the launcher, rather than to the page's start. */
|
|
198
|
+
const closePanel = async () => {
|
|
199
|
+
const inside = dock?.contains(document.activeElement) ?? false;
|
|
200
|
+
open = false;
|
|
201
|
+
if (inside) {
|
|
202
|
+
await tick();
|
|
203
|
+
launcher?.focus();
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/** The dock's top line from the keyboard: arrows make it taller or shorter, Home resets it. */
|
|
208
|
+
const resizeByKey = (event: KeyboardEvent) => {
|
|
209
|
+
const step = event.shiftKey ? 96 : 24;
|
|
210
|
+
const by = { ArrowDown: -step, ArrowUp: step }[event.key];
|
|
211
|
+
if (by !== undefined) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
expanded = false;
|
|
214
|
+
height = Math.round(shown + by);
|
|
215
|
+
} else if (event.key === "Home") {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
expanded = false;
|
|
218
|
+
height = 320;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const pad = (count: number) => String(count).padStart(2, "0");
|
|
223
|
+
|
|
224
|
+
const select = (id: number | undefined) => {
|
|
225
|
+
selected = id;
|
|
226
|
+
tab = "sheets";
|
|
227
|
+
};
|
|
228
|
+
const registryName = (index: number) => (index === 0 ? "registry 1" : `registry ${index + 1}`);
|
|
229
|
+
const tabs: readonly { readonly id: Tab; readonly label: string }[] = [
|
|
230
|
+
{ id: "graph", label: "Graph" },
|
|
231
|
+
{ id: "sheets", label: "Sheets" },
|
|
232
|
+
{ id: "timeline", label: "Timeline" },
|
|
233
|
+
];
|
|
234
|
+
</script>
|
|
235
|
+
|
|
236
|
+
<svelte:window bind:innerHeight />
|
|
237
|
+
|
|
238
|
+
{#if enabled && mounted && model}
|
|
239
|
+
<div class="devtools" class:dark>
|
|
240
|
+
{#if open}
|
|
241
|
+
<!-- A region of the page, not a modal: the page stays usable with it open. Escape from anything
|
|
242
|
+
in it closes it. -->
|
|
243
|
+
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
244
|
+
<section
|
|
245
|
+
bind:this={dock}
|
|
246
|
+
style:height="{shown}px"
|
|
247
|
+
aria-label="Atom devtools"
|
|
248
|
+
class="dock"
|
|
249
|
+
onkeydown={(event) => {
|
|
250
|
+
if (event.key === "Escape") {
|
|
251
|
+
void closePanel();
|
|
252
|
+
}
|
|
253
|
+
}}
|
|
254
|
+
tabindex="-1">
|
|
255
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
|
|
256
|
+
<div
|
|
257
|
+
aria-label="Resize the panel"
|
|
258
|
+
aria-orientation="horizontal"
|
|
259
|
+
aria-valuemax={Math.round(innerHeight * 0.85)}
|
|
260
|
+
aria-valuemin={160}
|
|
261
|
+
aria-valuenow={Math.round(shown)}
|
|
262
|
+
class="resize"
|
|
263
|
+
ondblclick={() => (height = 320)}
|
|
264
|
+
onkeydown={resizeByKey}
|
|
265
|
+
onpointerdown={resize}
|
|
266
|
+
role="separator"
|
|
267
|
+
tabindex="0"
|
|
268
|
+
title="Drag to resize; double-click to reset"></div>
|
|
269
|
+
<header class="bar">
|
|
270
|
+
<span class="cell title"><b aria-hidden="true">◎</b> Atoms</span>
|
|
271
|
+
<nav aria-label="Views" class="tabs">
|
|
272
|
+
{#each tabs as item, index (item.id)}
|
|
273
|
+
<button aria-pressed={tab === item.id} class="cell tab" onclick={() => (tab = item.id)} type="button">
|
|
274
|
+
<b>{pad(index + 1)}</b>
|
|
275
|
+
{item.label}
|
|
276
|
+
</button>
|
|
277
|
+
{/each}
|
|
278
|
+
</nav>
|
|
279
|
+
<span class="spacer"></span>
|
|
280
|
+
<span class="cell count">Atoms <b>{pad(model.totals.atoms)}</b></span>
|
|
281
|
+
<span class="cell count">Readers <b>{pad(model.totals.readers)}</b></span>
|
|
282
|
+
<span class="cell count">Updates <b>{pad(model.totals.updates)}</b></span>
|
|
283
|
+
<span class="cell count" class:alert={model.totals.interruptions > 0}>Interrupted <b>{pad(model.totals.interruptions)}</b></span>
|
|
284
|
+
{#if registries.length > 1}
|
|
285
|
+
<label class="cell">
|
|
286
|
+
<span class="sr">Registry</span>
|
|
287
|
+
<select
|
|
288
|
+
class="picker"
|
|
289
|
+
onchange={(event) => (chosen = registries[Number(event.currentTarget.value)])}
|
|
290
|
+
value={String(registries.indexOf(chosen as AtomRegistry.AtomRegistry))}>
|
|
291
|
+
{#each registries as item, index (item)}
|
|
292
|
+
<option value={String(index)}>{registryName(index)}{item === nearest ? " (this one)" : ""}</option>
|
|
293
|
+
{/each}
|
|
294
|
+
</select>
|
|
295
|
+
</label>
|
|
296
|
+
{/if}
|
|
297
|
+
<label class="cell toggle">
|
|
298
|
+
<input bind:checked={showPlumbing} type="checkbox" />
|
|
299
|
+
Plumbing
|
|
300
|
+
</label>
|
|
301
|
+
<button aria-label={expanded ? "Shrink the panel" : "Enlarge the panel"} class="cell icon" onclick={() => (expanded = !expanded)} title={expanded ? "Shrink" : "Enlarge"} type="button">
|
|
302
|
+
<svg aria-hidden="true" height="12" viewBox="0 0 12 12" width="12">
|
|
303
|
+
{#if expanded}
|
|
304
|
+
<path d="M2 5h8M2 7h8" fill="none" stroke="currentColor" stroke-width="1.25" />
|
|
305
|
+
{:else}
|
|
306
|
+
<path d="M2 4l4-3 4 3M2 8l4 3 4-3" fill="none" stroke="currentColor" stroke-width="1.25" />
|
|
307
|
+
{/if}
|
|
308
|
+
</svg>
|
|
309
|
+
</button>
|
|
310
|
+
<button aria-label="Close the panel" class="cell icon" onclick={closePanel} title="Close (Esc)" type="button">
|
|
311
|
+
<svg aria-hidden="true" height="12" viewBox="0 0 12 12" width="12">
|
|
312
|
+
<path d="M2.5 2.5l7 7M9.5 2.5l-7 7" fill="none" stroke="currentColor" stroke-width="1.25" />
|
|
313
|
+
</svg>
|
|
314
|
+
</button>
|
|
315
|
+
</header>
|
|
316
|
+
|
|
317
|
+
{#if model.partial}
|
|
318
|
+
<p class="notice">
|
|
319
|
+
This registry isn't the one effect-atom-svelte's inspector was written for (a newer Effect?), so only atoms added and removed are shown.
|
|
320
|
+
</p>
|
|
321
|
+
{:else if model.unlabelled}
|
|
322
|
+
<p class="notice">
|
|
323
|
+
No atom has a name. Add <code>atomLabels()</code> from <code>effect-atom-svelte-devtools/vite</code> to your Vite config to name them after their variables.
|
|
324
|
+
</p>
|
|
325
|
+
{/if}
|
|
326
|
+
|
|
327
|
+
<div class="body">
|
|
328
|
+
{#if tab === "graph"}
|
|
329
|
+
<div class="scroll">
|
|
330
|
+
<GraphView atoms={model.atoms} onselect={select} {selected} {showPlumbing} />
|
|
331
|
+
</div>
|
|
332
|
+
{:else if tab === "sheets"}
|
|
333
|
+
<SheetsView {model} onselect={select} {selected} {showPlumbing} />
|
|
334
|
+
{:else}
|
|
335
|
+
<TimelineView {model} onselect={select} {showPlumbing} />
|
|
336
|
+
{/if}
|
|
337
|
+
</div>
|
|
338
|
+
</section>
|
|
339
|
+
{:else}
|
|
340
|
+
<button bind:this={launcher} aria-label="Open the atom devtools" class="launcher" onclick={openPanel} type="button">
|
|
341
|
+
<b aria-hidden="true">◎</b> Atoms <span class="n">{pad(model.totals.atoms)}</span>
|
|
342
|
+
</button>
|
|
343
|
+
{/if}
|
|
344
|
+
</div>
|
|
345
|
+
{/if}
|
|
346
|
+
|
|
347
|
+
<style>
|
|
348
|
+
/*
|
|
349
|
+
* The docs' design language: zinc and amber, hairlines, mono labels. Each token reads the page's
|
|
350
|
+
* own where it has one (an app built on the docs' or shadcn's tokens), and falls back to the docs'
|
|
351
|
+
* values. The views use the short names; the graph module reads the page's names, so the dock
|
|
352
|
+
* hands those on too (on .dock, a level down, so neither refers to itself).
|
|
353
|
+
*/
|
|
354
|
+
.devtools {
|
|
355
|
+
--paper: var(--background, #fff);
|
|
356
|
+
--ink: var(--foreground, #18181b);
|
|
357
|
+
--muted: var(--muted-foreground, #52525b);
|
|
358
|
+
--subtle: var(--subtle-foreground, #a1a1aa);
|
|
359
|
+
--line: var(--border, #e4e4e7);
|
|
360
|
+
--faint: color-mix(in oklab, var(--ink) 5%, transparent);
|
|
361
|
+
--accent: var(--brand, #d97706);
|
|
362
|
+
--accent-text: var(--brand-text, #b45309);
|
|
363
|
+
--pulse: var(--accent);
|
|
364
|
+
--success: var(--tone-success, #16a34a);
|
|
365
|
+
--alert: var(--tone-failure, #dc2626);
|
|
366
|
+
--mono: var(--font-mono, ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace);
|
|
367
|
+
--serif: "Libron", ui-serif, Georgia, "Times New Roman", serif;
|
|
368
|
+
--sans: var(--font-sans, ui-sans-serif, system-ui, sans-serif);
|
|
369
|
+
--radius: 6px;
|
|
370
|
+
color: var(--ink);
|
|
371
|
+
font-family: var(--mono);
|
|
372
|
+
font-size: 13px;
|
|
373
|
+
line-height: 1.4;
|
|
374
|
+
}
|
|
375
|
+
.devtools.dark {
|
|
376
|
+
--paper: var(--background, #09090b);
|
|
377
|
+
--ink: var(--foreground, #fafafa);
|
|
378
|
+
--muted: var(--muted-foreground, #a1a1aa);
|
|
379
|
+
--subtle: var(--subtle-foreground, #71717a);
|
|
380
|
+
--line: var(--border, #27272a);
|
|
381
|
+
--accent: var(--brand, #f59e0b);
|
|
382
|
+
--accent-text: var(--brand-text, #f59e0b);
|
|
383
|
+
--success: var(--tone-success, #22c55e);
|
|
384
|
+
--alert: var(--tone-failure, #ef4444);
|
|
385
|
+
}
|
|
386
|
+
.devtools :global(*) {
|
|
387
|
+
box-sizing: border-box;
|
|
388
|
+
}
|
|
389
|
+
/* The launcher: one ruled cell in the corner, like a cell of the dock's bar. */
|
|
390
|
+
.launcher {
|
|
391
|
+
align-items: center;
|
|
392
|
+
background: var(--paper);
|
|
393
|
+
border: 1px solid var(--line);
|
|
394
|
+
border-radius: var(--radius);
|
|
395
|
+
bottom: 16px;
|
|
396
|
+
color: var(--muted);
|
|
397
|
+
cursor: pointer;
|
|
398
|
+
display: inline-flex;
|
|
399
|
+
font-family: var(--mono);
|
|
400
|
+
font-size: 10.5px;
|
|
401
|
+
gap: 0.5rem;
|
|
402
|
+
height: 32px;
|
|
403
|
+
letter-spacing: 0.08em;
|
|
404
|
+
padding: 0 0.75rem;
|
|
405
|
+
position: fixed;
|
|
406
|
+
right: 16px;
|
|
407
|
+
text-transform: uppercase;
|
|
408
|
+
z-index: 2147483000;
|
|
409
|
+
}
|
|
410
|
+
.launcher:hover {
|
|
411
|
+
border-color: var(--accent);
|
|
412
|
+
color: var(--ink);
|
|
413
|
+
}
|
|
414
|
+
.launcher b {
|
|
415
|
+
color: var(--accent);
|
|
416
|
+
font-weight: 400;
|
|
417
|
+
}
|
|
418
|
+
.launcher .n {
|
|
419
|
+
color: var(--ink);
|
|
420
|
+
font-variant-numeric: tabular-nums;
|
|
421
|
+
}
|
|
422
|
+
/* The dock: across the bottom of the window, ruled off from the page by its top line. */
|
|
423
|
+
.dock {
|
|
424
|
+
--background: var(--paper);
|
|
425
|
+
--foreground: var(--ink);
|
|
426
|
+
--muted-foreground: var(--muted);
|
|
427
|
+
--subtle-foreground: var(--subtle);
|
|
428
|
+
--border: var(--line);
|
|
429
|
+
--brand: var(--accent);
|
|
430
|
+
--brand-text: var(--accent-text);
|
|
431
|
+
--tone-success: var(--success);
|
|
432
|
+
--tone-failure: var(--alert);
|
|
433
|
+
--font-mono: var(--mono);
|
|
434
|
+
background: var(--paper);
|
|
435
|
+
border-top: 1px solid var(--line);
|
|
436
|
+
bottom: 0;
|
|
437
|
+
display: flex;
|
|
438
|
+
flex-direction: column;
|
|
439
|
+
left: 0;
|
|
440
|
+
position: fixed;
|
|
441
|
+
right: 0;
|
|
442
|
+
z-index: 2147483000;
|
|
443
|
+
animation: rise 0.2s cubic-bezier(0.2, 0.7, 0.2, 1) both;
|
|
444
|
+
}
|
|
445
|
+
.resize {
|
|
446
|
+
cursor: ns-resize;
|
|
447
|
+
height: 7px;
|
|
448
|
+
left: 0;
|
|
449
|
+
position: absolute;
|
|
450
|
+
right: 0;
|
|
451
|
+
top: -4px;
|
|
452
|
+
z-index: 1;
|
|
453
|
+
}
|
|
454
|
+
.resize:focus-visible {
|
|
455
|
+
box-shadow: inset 0 -2px 0 var(--accent);
|
|
456
|
+
outline: none;
|
|
457
|
+
}
|
|
458
|
+
.dock:focus-visible {
|
|
459
|
+
outline: none;
|
|
460
|
+
}
|
|
461
|
+
.resize:hover {
|
|
462
|
+
box-shadow: inset 0 -1px 0 color-mix(in oklab, var(--accent) 60%, transparent);
|
|
463
|
+
}
|
|
464
|
+
/* The bar: a row of ruled cells, as the docs' site header is. */
|
|
465
|
+
.bar {
|
|
466
|
+
align-items: stretch;
|
|
467
|
+
border-bottom: 1px solid var(--line);
|
|
468
|
+
display: flex;
|
|
469
|
+
flex: none;
|
|
470
|
+
height: 36px;
|
|
471
|
+
overflow-x: auto;
|
|
472
|
+
}
|
|
473
|
+
.cell {
|
|
474
|
+
align-items: center;
|
|
475
|
+
background: none;
|
|
476
|
+
border: 0;
|
|
477
|
+
border-left: 1px solid var(--line);
|
|
478
|
+
color: var(--muted);
|
|
479
|
+
display: inline-flex;
|
|
480
|
+
flex: none;
|
|
481
|
+
font: inherit;
|
|
482
|
+
font-size: 10.5px;
|
|
483
|
+
gap: 0.45rem;
|
|
484
|
+
letter-spacing: 0.08em;
|
|
485
|
+
padding: 0 0.9rem;
|
|
486
|
+
text-transform: uppercase;
|
|
487
|
+
white-space: nowrap;
|
|
488
|
+
}
|
|
489
|
+
.cell b {
|
|
490
|
+
color: var(--accent-text);
|
|
491
|
+
font-weight: 400;
|
|
492
|
+
}
|
|
493
|
+
.title {
|
|
494
|
+
border-left: 0;
|
|
495
|
+
color: var(--ink);
|
|
496
|
+
}
|
|
497
|
+
.tabs {
|
|
498
|
+
display: flex;
|
|
499
|
+
}
|
|
500
|
+
.tab {
|
|
501
|
+
cursor: pointer;
|
|
502
|
+
}
|
|
503
|
+
.tab:hover,
|
|
504
|
+
.icon:hover {
|
|
505
|
+
background: var(--faint);
|
|
506
|
+
color: var(--ink);
|
|
507
|
+
}
|
|
508
|
+
.tab[aria-pressed="true"] {
|
|
509
|
+
box-shadow: inset 0 -2px 0 var(--accent);
|
|
510
|
+
color: var(--ink);
|
|
511
|
+
}
|
|
512
|
+
.spacer {
|
|
513
|
+
border-left: 1px solid var(--line);
|
|
514
|
+
flex: 1;
|
|
515
|
+
}
|
|
516
|
+
.count b {
|
|
517
|
+
color: var(--ink);
|
|
518
|
+
font-variant-numeric: tabular-nums;
|
|
519
|
+
}
|
|
520
|
+
.count.alert b {
|
|
521
|
+
color: var(--alert);
|
|
522
|
+
}
|
|
523
|
+
.picker {
|
|
524
|
+
background: var(--paper);
|
|
525
|
+
border: 1px solid var(--line);
|
|
526
|
+
border-radius: 4px;
|
|
527
|
+
color: var(--ink);
|
|
528
|
+
font: inherit;
|
|
529
|
+
letter-spacing: normal;
|
|
530
|
+
padding: 0.1rem 0.25rem;
|
|
531
|
+
text-transform: none;
|
|
532
|
+
}
|
|
533
|
+
.toggle {
|
|
534
|
+
cursor: pointer;
|
|
535
|
+
}
|
|
536
|
+
.toggle input {
|
|
537
|
+
accent-color: var(--accent);
|
|
538
|
+
margin: 0;
|
|
539
|
+
}
|
|
540
|
+
.icon {
|
|
541
|
+
cursor: pointer;
|
|
542
|
+
justify-content: center;
|
|
543
|
+
padding: 0;
|
|
544
|
+
width: 36px;
|
|
545
|
+
}
|
|
546
|
+
.sr {
|
|
547
|
+
clip-path: inset(50%);
|
|
548
|
+
height: 1px;
|
|
549
|
+
overflow: hidden;
|
|
550
|
+
position: absolute;
|
|
551
|
+
width: 1px;
|
|
552
|
+
}
|
|
553
|
+
.notice {
|
|
554
|
+
border-bottom: 1px solid var(--line);
|
|
555
|
+
color: var(--muted);
|
|
556
|
+
flex: none;
|
|
557
|
+
font-family: var(--serif);
|
|
558
|
+
font-style: italic;
|
|
559
|
+
margin: 0;
|
|
560
|
+
padding: 0.45rem 0.9rem;
|
|
561
|
+
}
|
|
562
|
+
.notice code {
|
|
563
|
+
font-family: var(--mono);
|
|
564
|
+
font-style: normal;
|
|
565
|
+
}
|
|
566
|
+
.body {
|
|
567
|
+
flex: 1;
|
|
568
|
+
min-height: 0;
|
|
569
|
+
}
|
|
570
|
+
.scroll {
|
|
571
|
+
height: 100%;
|
|
572
|
+
overflow: auto;
|
|
573
|
+
}
|
|
574
|
+
@keyframes rise {
|
|
575
|
+
from {
|
|
576
|
+
transform: translateY(12px);
|
|
577
|
+
opacity: 0;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
@media (prefers-reduced-motion: reduce) {
|
|
581
|
+
.dock {
|
|
582
|
+
animation: none;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
</style>
|