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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AtomRegistry } from "effect/reactivity";
|
|
2
|
+
interface Props {
|
|
3
|
+
/** The registry to show. Defaults to the nearest `RegistryProvider`'s. */
|
|
4
|
+
readonly registry?: AtomRegistry.AtomRegistry | undefined;
|
|
5
|
+
/** Whether the panel starts open. Defaults to how it was left. */
|
|
6
|
+
readonly open?: boolean | undefined;
|
|
7
|
+
/** Light paper, a dark blueprint, or the page's own (`auto`: a `dark` class on `<html>`, or the system's). */
|
|
8
|
+
readonly theme?: "auto" | "light" | "dark" | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Shows the panel in production builds too, for a site that lets its visitors watch its atoms.
|
|
11
|
+
* Without it the panel renders nothing outside development. In production it follows the
|
|
12
|
+
* nearest provider's registry, or `registry`, with no picker: only development lists the rest.
|
|
13
|
+
*/
|
|
14
|
+
readonly production?: boolean | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The keyboard shortcut that opens and closes the panel, as "alt+shift+a" (the default) or
|
|
17
|
+
* "ctrl+shift+f2". Whoever uses the panel can change it in its settings.
|
|
18
|
+
*/
|
|
19
|
+
readonly shortcut?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A panel docked along the bottom of the window that shows the atom registry live: its dependency
|
|
23
|
+
* graph, a sheet per atom and a timeline of everything it does. Development only unless you set
|
|
24
|
+
* `production`: in a production build without it, or on the server, it renders nothing.
|
|
25
|
+
*
|
|
26
|
+
* It's drawn like the effect-atom-svelte docs: ruled in hairlines, with mono labels, numbered views
|
|
27
|
+
* and an amber accent, in the page's own colours where it has them (--background, --foreground,
|
|
28
|
+
* --border, --brand and the rest) and the docs' zinc and amber where it doesn't. Drag its top line
|
|
29
|
+
* to make it taller or shorter; the page gets room below it for as long as it's open.
|
|
30
|
+
*
|
|
31
|
+
* It follows the registry of the nearest `RegistryProvider`, or the one given as `registry`. When
|
|
32
|
+
* the app has several, a picker in the panel switches between them.
|
|
33
|
+
*
|
|
34
|
+
* Render it only in development, behind Vite's `DEV` flag, so a build leaves it out: the README
|
|
35
|
+
* shows how. To show it in production too, as the effect-atom-svelte docs do, set `production`.
|
|
36
|
+
*/
|
|
37
|
+
declare const AtomDevtools: import("svelte").Component<Props, {}, "">;
|
|
38
|
+
type AtomDevtools = ReturnType<typeof AtomDevtools>;
|
|
39
|
+
export default AtomDevtools;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A live dependency graph: lays out its `graph` (layout.ts) and draws it on a frame's lines
|
|
4
|
+
(frame-graph.svelte), with a family's or factory's atoms as a row of dots. Call `pulse` when an
|
|
5
|
+
atom's value updates and `interrupt` when its effect is interrupted, from outside any update of
|
|
6
|
+
the registry's (on the next animation frame, say): the graph animates them on its own elements,
|
|
7
|
+
with no Svelte state.
|
|
8
|
+
|
|
9
|
+
```svelte
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import { AtomGraph } from "effect-atom-svelte-devtools/graph";
|
|
12
|
+
|
|
13
|
+
let graph: AtomGraph;
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<AtomGraph bind:this={graph} graph={{ atoms, links, readers }} />
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then, as values change: `graph.pulse(id, "success")`.
|
|
20
|
+
-->
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import FrameGraph from "./frame-graph.svelte";
|
|
23
|
+
import { layoutGraph } from "./layout.js";
|
|
24
|
+
import type { GraphInput, GraphLayout } from "./layout.js";
|
|
25
|
+
|
|
26
|
+
interface Props {
|
|
27
|
+
readonly graph: GraphInput;
|
|
28
|
+
/** Called with an atom's id when it's clicked; atoms are only clickable when this is given. */
|
|
29
|
+
readonly onselect?: ((id: number) => void) | undefined;
|
|
30
|
+
/** The atom to mark as selected. */
|
|
31
|
+
readonly selected?: number | undefined;
|
|
32
|
+
/** Shown in place of the graph while there's nothing to draw. */
|
|
33
|
+
readonly empty?: string | undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { empty, graph, onselect, selected }: Props = $props();
|
|
37
|
+
|
|
38
|
+
// For the gaps at crossings, which are a few pixels wide whatever the graph's width.
|
|
39
|
+
let width = $state(0);
|
|
40
|
+
let host = $state<HTMLElement>();
|
|
41
|
+
|
|
42
|
+
const layout: GraphLayout | undefined = $derived(layoutGraph(graph, width));
|
|
43
|
+
|
|
44
|
+
/** Restarts a class's animation on an element. */
|
|
45
|
+
const replay = (element: HTMLElement, name: string) => {
|
|
46
|
+
element.classList.remove(name);
|
|
47
|
+
// Reading layout makes the browser see the class come off before it goes back on.
|
|
48
|
+
void element.offsetWidth;
|
|
49
|
+
element.classList.add(name);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Rings an atom whose value updated, and flashes the edges into it, in the tone of what it
|
|
54
|
+
* brought: `success` green, `failure` red, or the accent.
|
|
55
|
+
*/
|
|
56
|
+
export const pulse = (id: number, tone: "success" | "failure" | "" = "") => {
|
|
57
|
+
const mark = host?.querySelector<HTMLElement>(`[data-node="a${id}"]`);
|
|
58
|
+
if (mark) {
|
|
59
|
+
mark.dataset.tone = tone;
|
|
60
|
+
replay(mark, "pulse");
|
|
61
|
+
}
|
|
62
|
+
for (const edge of host?.querySelectorAll<HTMLElement>(`[data-to="a${id}"]`) ?? []) {
|
|
63
|
+
edge.dataset.tone = tone;
|
|
64
|
+
replay(edge, "flash");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** Flashes a cross on an atom whose effect was interrupted. */
|
|
69
|
+
export const interrupt = (id: number) => {
|
|
70
|
+
const mark = host?.querySelector<HTMLElement>(`[data-node="a${id}"]`);
|
|
71
|
+
if (mark) {
|
|
72
|
+
replay(mark, "interrupted");
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const click = (event: MouseEvent) => {
|
|
77
|
+
const target = (event.target as Element | null)?.closest<HTMLElement>("[data-node]");
|
|
78
|
+
const id = target?.dataset.node;
|
|
79
|
+
if (onselect && id?.startsWith("a")) {
|
|
80
|
+
onselect(Number(id.slice(1)));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
$effect(() => {
|
|
85
|
+
for (const element of host?.querySelectorAll("[data-node].selected") ?? []) {
|
|
86
|
+
element.classList.remove("selected");
|
|
87
|
+
}
|
|
88
|
+
if (selected !== undefined) {
|
|
89
|
+
host?.querySelector(`[data-node="a${selected}"]`)?.classList.add("selected");
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
95
|
+
<div
|
|
96
|
+
bind:clientWidth={width}
|
|
97
|
+
bind:this={host}
|
|
98
|
+
style:height={layout ? `${layout.height}px` : undefined}
|
|
99
|
+
class="atom-graph"
|
|
100
|
+
class:interactive={onselect !== undefined}
|
|
101
|
+
onclick={onselect ? click : undefined}
|
|
102
|
+
>
|
|
103
|
+
{#if layout}
|
|
104
|
+
<FrameGraph edges={layout.edges} interactive={onselect !== undefined} nodes={layout.nodes} />
|
|
105
|
+
{#each layout.dots as row, index (index)}
|
|
106
|
+
{#each row.dots as dot (dot.id)}
|
|
107
|
+
<span
|
|
108
|
+
style:left="{dot.x * width}px"
|
|
109
|
+
style:top="{dot.y}px"
|
|
110
|
+
class={["dot", dot.read && "read", dot.repeat && "repeat", dot.removed && "removed"]}
|
|
111
|
+
data-node="a{dot.id}"
|
|
112
|
+
title={dot.label}
|
|
113
|
+
>
|
|
114
|
+
<i></i>
|
|
115
|
+
<b class="ring"></b>
|
|
116
|
+
{#if row.keys}<span class="key">{dot.key}</span>{/if}
|
|
117
|
+
</span>
|
|
118
|
+
{/each}
|
|
119
|
+
{/each}
|
|
120
|
+
{:else if empty}
|
|
121
|
+
<p class="empty">{empty}</p>
|
|
122
|
+
{/if}
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<style>
|
|
126
|
+
.atom-graph {
|
|
127
|
+
min-height: 3.5rem;
|
|
128
|
+
position: relative;
|
|
129
|
+
}
|
|
130
|
+
.empty {
|
|
131
|
+
bottom: 1rem;
|
|
132
|
+
color: var(--muted-foreground, #52525b);
|
|
133
|
+
font-family: var(--font-mono, ui-monospace, monospace);
|
|
134
|
+
font-size: 0.7rem;
|
|
135
|
+
left: 1.5rem;
|
|
136
|
+
letter-spacing: 0.08em;
|
|
137
|
+
margin: 0;
|
|
138
|
+
position: absolute;
|
|
139
|
+
text-transform: uppercase;
|
|
140
|
+
}
|
|
141
|
+
/*
|
|
142
|
+
* A family's or factory's atoms as dots on its track: hollow while held with no readers, filled
|
|
143
|
+
* while read, crossed once removed, and red when it's a second atom for a key already seen. Odd
|
|
144
|
+
* sizes and whole-pixel borders keep a dot centred on its 1px line (frame-graph.svelte).
|
|
145
|
+
*/
|
|
146
|
+
.dot {
|
|
147
|
+
--pulse: var(--brand, #d97706);
|
|
148
|
+
height: 1px;
|
|
149
|
+
position: absolute;
|
|
150
|
+
width: 1px;
|
|
151
|
+
z-index: 3;
|
|
152
|
+
}
|
|
153
|
+
.interactive .dot {
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
}
|
|
156
|
+
.dot:global([data-tone="success"]) {
|
|
157
|
+
--pulse: var(--tone-success, #16a34a);
|
|
158
|
+
}
|
|
159
|
+
.dot:global([data-tone="failure"]) {
|
|
160
|
+
--pulse: var(--tone-failure, #dc2626);
|
|
161
|
+
}
|
|
162
|
+
.dot i {
|
|
163
|
+
background: var(--graph-background, var(--background, #fff));
|
|
164
|
+
border: 2px solid var(--brand, #d97706);
|
|
165
|
+
border-radius: 50%;
|
|
166
|
+
height: 11px;
|
|
167
|
+
left: -5px;
|
|
168
|
+
position: absolute;
|
|
169
|
+
top: -5px;
|
|
170
|
+
width: 11px;
|
|
171
|
+
}
|
|
172
|
+
.dot.read i {
|
|
173
|
+
background: var(--brand, #d97706);
|
|
174
|
+
}
|
|
175
|
+
.dot.repeat i {
|
|
176
|
+
border-color: var(--tone-failure, #dc2626);
|
|
177
|
+
}
|
|
178
|
+
.dot.repeat.read i {
|
|
179
|
+
background: var(--tone-failure, #dc2626);
|
|
180
|
+
}
|
|
181
|
+
.dot.removed i {
|
|
182
|
+
background:
|
|
183
|
+
linear-gradient(45deg, transparent 42%, var(--brand-text, #b45309) 42% 58%, transparent 58%),
|
|
184
|
+
linear-gradient(-45deg, transparent 42%, var(--brand-text, #b45309) 42% 58%, transparent 58%);
|
|
185
|
+
border: 0;
|
|
186
|
+
}
|
|
187
|
+
.dot:global(.pulse) i {
|
|
188
|
+
animation: dot-mark 0.9s ease-out;
|
|
189
|
+
}
|
|
190
|
+
.dot:global(.selected) i {
|
|
191
|
+
box-shadow: 0 0 0 3px color-mix(in oklab, var(--brand, #d97706) 40%, transparent);
|
|
192
|
+
}
|
|
193
|
+
.key {
|
|
194
|
+
color: var(--muted-foreground, #52525b);
|
|
195
|
+
font-family: var(--font-mono, ui-monospace, monospace);
|
|
196
|
+
font-size: 0.62rem;
|
|
197
|
+
left: 0;
|
|
198
|
+
position: absolute;
|
|
199
|
+
top: 0.6rem;
|
|
200
|
+
translate: -50% 0;
|
|
201
|
+
white-space: nowrap;
|
|
202
|
+
}
|
|
203
|
+
.dot.read .key {
|
|
204
|
+
color: var(--brand-text, #b45309);
|
|
205
|
+
}
|
|
206
|
+
.dot.repeat .key {
|
|
207
|
+
color: var(--tone-failure-text, var(--tone-failure, #dc2626));
|
|
208
|
+
}
|
|
209
|
+
.dot .ring {
|
|
210
|
+
border: 1.5px solid var(--pulse);
|
|
211
|
+
border-radius: 50%;
|
|
212
|
+
height: 11px;
|
|
213
|
+
left: -5px;
|
|
214
|
+
opacity: 0;
|
|
215
|
+
position: absolute;
|
|
216
|
+
top: -5px;
|
|
217
|
+
width: 11px;
|
|
218
|
+
}
|
|
219
|
+
.dot:global(.pulse) .ring {
|
|
220
|
+
animation: dot-ring 0.9s ease-out both;
|
|
221
|
+
}
|
|
222
|
+
@keyframes dot-mark {
|
|
223
|
+
from {
|
|
224
|
+
background: var(--pulse);
|
|
225
|
+
border-color: var(--pulse);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
@keyframes dot-ring {
|
|
229
|
+
from {
|
|
230
|
+
opacity: 1;
|
|
231
|
+
scale: 1;
|
|
232
|
+
}
|
|
233
|
+
to {
|
|
234
|
+
opacity: 0;
|
|
235
|
+
scale: 2.6;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
@media (prefers-reduced-motion: reduce) {
|
|
239
|
+
.dot:global(.pulse) i,
|
|
240
|
+
.dot:global(.pulse) .ring {
|
|
241
|
+
animation-duration: 0.01s;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
</style>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { GraphInput } from "./layout.ts";
|
|
2
|
+
interface Props {
|
|
3
|
+
readonly graph: GraphInput;
|
|
4
|
+
/** Called with an atom's id when it's clicked; atoms are only clickable when this is given. */
|
|
5
|
+
readonly onselect?: ((id: number) => void) | undefined;
|
|
6
|
+
/** The atom to mark as selected. */
|
|
7
|
+
readonly selected?: number | undefined;
|
|
8
|
+
/** Shown in place of the graph while there's nothing to draw. */
|
|
9
|
+
readonly empty?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A live dependency graph: lays out its `graph` (layout.ts) and draws it on a frame's lines
|
|
13
|
+
* (frame-graph.svelte), with a family's or factory's atoms as a row of dots. Call `pulse` when an
|
|
14
|
+
* atom's value updates and `interrupt` when its effect is interrupted, from outside any update of
|
|
15
|
+
* the registry's (on the next animation frame, say): the graph animates them on its own elements,
|
|
16
|
+
* with no Svelte state.
|
|
17
|
+
*
|
|
18
|
+
* ```svelte
|
|
19
|
+
* <script lang="ts">
|
|
20
|
+
* import { AtomGraph } from "effect-atom-svelte-devtools/graph";
|
|
21
|
+
*
|
|
22
|
+
* let graph: AtomGraph;
|
|
23
|
+
* </script>
|
|
24
|
+
*
|
|
25
|
+
* <AtomGraph bind:this={graph} graph={{ atoms, links, readers }} />
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Then, as values change: `graph.pulse(id, "success")`.
|
|
29
|
+
*/
|
|
30
|
+
declare const AtomGraph: import("svelte").Component<Props, {
|
|
31
|
+
/**
|
|
32
|
+
* Rings an atom whose value updated, and flashes the edges into it, in the tone of what it
|
|
33
|
+
* brought: `success` green, `failure` red, or the accent.
|
|
34
|
+
*/ pulse: (id: number, tone?: "success" | "failure" | "") => void;
|
|
35
|
+
/** Flashes a cross on an atom whose effect was interrupted. */ interrupt: (id: number) => void;
|
|
36
|
+
}, "">;
|
|
37
|
+
type AtomGraph = ReturnType<typeof AtomGraph>;
|
|
38
|
+
export default AtomGraph;
|