effect-atom-svelte-devtools 0.0.0-stage → 0.2.1
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 +122 -2
- package/dist/atom-devtools.svelte +753 -0
- package/dist/atom-devtools.svelte.d.ts +39 -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 +14 -0
- package/dist/index.js +14 -0
- package/dist/internal/format.d.ts +27 -0
- package/dist/internal/format.js +183 -0
- package/dist/internal/graph-view.svelte +134 -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/settings-view.svelte +198 -0
- package/dist/internal/settings-view.svelte.d.ts +16 -0
- package/dist/internal/sheets-view.svelte +453 -0
- package/dist/internal/sheets-view.svelte.d.ts +11 -0
- package/dist/internal/shortcut.d.ts +22 -0
- package/dist/internal/shortcut.js +91 -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,123 @@
|
|
|
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
|
+
The panel renders nothing in a production build, so leaving out the `DEV` check only costs the download. To show it in production on purpose, say for a demo that lets its visitors watch its atoms (as the effect-atom-svelte docs do), render it without the check and set `production`:
|
|
30
|
+
|
|
31
|
+
```svelte
|
|
32
|
+
<AtomDevtools production />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
In production it shows the registry of the nearest `RegistryProvider`, or the one you pass, with no picker: only development keeps the list of every provider's registry. Declarations aren't links to your editor, which only the dev server can open, and atoms have names only if `atomLabels({ builds: true })` labels the build.
|
|
36
|
+
|
|
37
|
+
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 your page's colours and fonts where it has them (see [Theming](#theming)), and in zinc and amber, light or dark, where it doesn't. Its bar counts the registry's atoms, readers, updates and interruptions.
|
|
38
|
+
|
|
39
|
+
Alt+Shift+A opens and closes it from anywhere on the page. Set the app's own with the `shortcut` prop (`<AtomDevtools shortcut="ctrl+shift+f2" />`); whoever uses the panel can change it in its settings.
|
|
40
|
+
|
|
41
|
+
It has three views, and settings:
|
|
42
|
+
|
|
43
|
+
- **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.
|
|
44
|
+
- **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.
|
|
45
|
+
- **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.
|
|
46
|
+
- **Settings**: the shortcut (click Change and press a new one: it needs Ctrl, Alt or Meta, or a function key, so it can't catch typing), and the button's corner, opacity and size. Drag the button to move it, too: it settles in the nearest corner. A faded button is opaque again while you point at it or focus it. The panel saves its settings in `localStorage`.
|
|
47
|
+
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
### Theming
|
|
51
|
+
|
|
52
|
+
The panel takes its colours and fonts from CSS variables. It reads the ones a Tailwind or shadcn app already has, so it often matches your app with no setup:
|
|
53
|
+
|
|
54
|
+
| Variable | What it colours or sets |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `--background`, `--foreground` | The panel, and its text |
|
|
57
|
+
| `--muted-foreground`, `--subtle-foreground` | Quieter text: labels, notes, timestamps |
|
|
58
|
+
| `--border` | Its hairlines |
|
|
59
|
+
| `--brand`, `--brand-text` | The accent: atoms' rings, the current tab, numbers |
|
|
60
|
+
| `--tone-success`, `--tone-failure` | A success's green ring, a failure's red one |
|
|
61
|
+
| `--font-mono` | Labels, names and values |
|
|
62
|
+
| `--font-serif` | The italic notes |
|
|
63
|
+
|
|
64
|
+
Any it doesn't find fall back to zinc and amber, a monospace and the system serif. To give the panel colours or fonts of its own, different from the page's, set the variables on `[data-atom-devtools]`:
|
|
65
|
+
|
|
66
|
+
```css
|
|
67
|
+
[data-atom-devtools] {
|
|
68
|
+
--brand: oklch(0.6 0.2 300);
|
|
69
|
+
--font-serif: "Iowan Old Style", Georgia, serif;
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`theme` picks light or dark (`auto`, the default, follows a `dark` class on `<html>`, or the system's setting). The graph module reads the same variables.
|
|
74
|
+
|
|
75
|
+
## The graph
|
|
76
|
+
|
|
77
|
+
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.
|
|
78
|
+
|
|
79
|
+
- `layoutGraph({ atoms, links, readers }, width)` lays atoms, the links between them and the components that read them out on tracks.
|
|
80
|
+
- `<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.
|
|
81
|
+
- `<FrameGraph nodes={…} edges={…} />` draws nodes and edges you place yourself, on a frame's 1px lines.
|
|
82
|
+
|
|
83
|
+
It reads the same variables as the panel ([Theming](#theming)) and falls back to a neutral palette.
|
|
84
|
+
|
|
85
|
+
## Atom names
|
|
86
|
+
|
|
87
|
+
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:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
export const todosAtom = Atom.make(...)
|
|
91
|
+
// todosAtom.label: ["todosAtom", "at todosAtom (/src/lib/todos.ts:4:14)"]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
// vite.config.ts
|
|
96
|
+
import { sveltekit } from "@sveltejs/kit/vite";
|
|
97
|
+
import { atomLabels } from "effect-atom-svelte-devtools/vite";
|
|
98
|
+
import { defineConfig } from "vite";
|
|
99
|
+
|
|
100
|
+
export default defineConfig({
|
|
101
|
+
plugins: [atomLabels(), sveltekit()],
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
- Only the dev server applies it, unless you pass `builds: true`: then production builds are labelled too (without keeping values across reloads, which builds don't have), for a page that shows atoms' names in production.
|
|
106
|
+
- Put it before `sveltekit()` or `svelte()`, so it sees components before they are compiled. It warns if it comes after.
|
|
107
|
+
- The atom is labelled in place and keeps its identity. `Atom.withLabel` would return a copy.
|
|
108
|
+
- 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.
|
|
109
|
+
- Members of an `Atom.family` are labelled with their argument, as `todoAtom(3)`.
|
|
110
|
+
- 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)`).
|
|
111
|
+
- 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.
|
|
112
|
+
- An atom in a top-level object literal is named by its path: `const pair = { todosAtom: Atom.make(...) }` labels `pair.todosAtom`.
|
|
113
|
+
- Inside functions, only `Atom.*` calls are labelled, so a function that makes atoms names them without every other call in it being wrapped.
|
|
114
|
+
- Atoms in mdsvex (`.md`) pages aren't labelled.
|
|
115
|
+
- 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.
|
|
116
|
+
|
|
117
|
+
## State across hot reloads
|
|
118
|
+
|
|
119
|
+
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.
|
|
120
|
+
|
|
121
|
+
- Edit the atom's own declaration and it starts from its new value: the old one no longer applies.
|
|
122
|
+
- Derived atoms compute again from the kept values, and effects run again, as their code may have changed.
|
|
123
|
+
- 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.
|