effect-atom-svelte-devtools 0.2.0 → 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/README.md +40 -4
- package/dist/atom-devtools.svelte +187 -19
- package/dist/atom-devtools.svelte.d.ts +14 -3
- package/dist/graph/frame-graph.svelte +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/format.d.ts +7 -0
- package/dist/internal/format.js +47 -2
- package/dist/internal/graph-view.svelte +10 -3
- package/dist/internal/settings-view.svelte +198 -0
- package/dist/internal/settings-view.svelte.d.ts +16 -0
- package/dist/internal/sheets-view.svelte +8 -1
- package/dist/internal/shortcut.d.ts +22 -0
- package/dist/internal/shortcut.js +91 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -26,16 +26,52 @@ It reads effect-atom-svelte's inspector, which is new in effect-atom-svelte 0.2:
|
|
|
26
26
|
|
|
27
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
28
|
|
|
29
|
-
|
|
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
30
|
|
|
31
|
-
|
|
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:
|
|
32
42
|
|
|
33
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.
|
|
34
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.
|
|
35
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`.
|
|
36
47
|
|
|
37
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.
|
|
38
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
|
+
|
|
39
75
|
## The graph
|
|
40
76
|
|
|
41
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.
|
|
@@ -44,7 +80,7 @@ The graph the panel draws is also yours to use, from `effect-atom-svelte-devtool
|
|
|
44
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.
|
|
45
81
|
- `<FrameGraph nodes={…} edges={…} />` draws nodes and edges you place yourself, on a frame's 1px lines.
|
|
46
82
|
|
|
47
|
-
It reads
|
|
83
|
+
It reads the same variables as the panel ([Theming](#theming)) and falls back to a neutral palette.
|
|
48
84
|
|
|
49
85
|
## Atom names
|
|
50
86
|
|
|
@@ -66,7 +102,7 @@ export default defineConfig({
|
|
|
66
102
|
});
|
|
67
103
|
```
|
|
68
104
|
|
|
69
|
-
- Only the dev server applies it
|
|
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.
|
|
70
106
|
- Put it before `sveltekit()` or `svelte()`, so it sees components before they are compiled. It warns if it comes after.
|
|
71
107
|
- The atom is labelled in place and keeps its identity. `Atom.withLabel` would return a copy.
|
|
72
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.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
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
|
|
5
|
-
build, or on the server, it renders nothing.
|
|
4
|
+
graph, a sheet per atom and a timeline of everything it does. Development only unless you set
|
|
5
|
+
`production`: in a production build without it, or on the server, it renders nothing.
|
|
6
6
|
|
|
7
7
|
It's drawn like the effect-atom-svelte docs: ruled in hairlines, with mono labels, numbered views
|
|
8
8
|
and an amber accent, in the page's own colours where it has them (--background, --foreground,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
the app has several, a picker in the panel switches between them.
|
|
14
14
|
|
|
15
15
|
Render it only in development, behind Vite's `DEV` flag, so a build leaves it out: the README
|
|
16
|
-
shows how.
|
|
16
|
+
shows how. To show it in production too, as the effect-atom-svelte docs do, set `production`.
|
|
17
17
|
-->
|
|
18
18
|
<script lang="ts">
|
|
19
19
|
import { BROWSER, DEV } from "esm-env";
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
|
|
25
25
|
import GraphView from "./internal/graph-view.svelte";
|
|
26
26
|
import { Model } from "./internal/model.svelte.js";
|
|
27
|
+
import SettingsView from "./internal/settings-view.svelte";
|
|
28
|
+
import type { Corner } from "./internal/settings-view.svelte";
|
|
29
|
+
import { defaultShortcut, formatShortcut, matchesShortcut, parseShortcut } from "./internal/shortcut.js";
|
|
27
30
|
import SheetsView from "./internal/sheets-view.svelte";
|
|
28
31
|
import TimelineView from "./internal/timeline-view.svelte";
|
|
29
32
|
|
|
@@ -34,17 +37,38 @@
|
|
|
34
37
|
readonly open?: boolean | undefined;
|
|
35
38
|
/** Light paper, a dark blueprint, or the page's own (`auto`: a `dark` class on `<html>`, or the system's). */
|
|
36
39
|
readonly theme?: "auto" | "light" | "dark" | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Shows the panel in production builds too, for a site that lets its visitors watch its atoms.
|
|
42
|
+
* Without it the panel renders nothing outside development. In production it follows the
|
|
43
|
+
* nearest provider's registry, or `registry`, with no picker: only development lists the rest.
|
|
44
|
+
*/
|
|
45
|
+
readonly production?: boolean | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* The keyboard shortcut that opens and closes the panel, as "alt+shift+a" (the default) or
|
|
48
|
+
* "ctrl+shift+f2". Whoever uses the panel can change it in its settings.
|
|
49
|
+
*/
|
|
50
|
+
readonly shortcut?: string | undefined;
|
|
37
51
|
}
|
|
38
52
|
|
|
39
|
-
const {
|
|
53
|
+
const {
|
|
54
|
+
registry,
|
|
55
|
+
open: startOpen,
|
|
56
|
+
production = false,
|
|
57
|
+
shortcut: appShortcut = defaultShortcut,
|
|
58
|
+
theme = "auto",
|
|
59
|
+
}: Props = $props();
|
|
40
60
|
|
|
41
|
-
type Tab = "graph" | "sheets" | "timeline";
|
|
61
|
+
type Tab = "graph" | "sheets" | "timeline" | "settings";
|
|
42
62
|
interface Saved {
|
|
43
63
|
readonly open: boolean;
|
|
44
64
|
readonly tab: Tab;
|
|
45
65
|
readonly plumbing: boolean;
|
|
46
66
|
readonly expanded: boolean;
|
|
47
67
|
readonly height: number;
|
|
68
|
+
readonly shortcut: string;
|
|
69
|
+
readonly corner: Corner;
|
|
70
|
+
readonly opacity: number;
|
|
71
|
+
readonly scale: number;
|
|
48
72
|
}
|
|
49
73
|
const storageKey = "effect-atom-svelte-devtools";
|
|
50
74
|
const load = (): Partial<Saved> => {
|
|
@@ -55,7 +79,8 @@
|
|
|
55
79
|
}
|
|
56
80
|
};
|
|
57
81
|
|
|
58
|
-
|
|
82
|
+
// svelte-ignore state_referenced_locally
|
|
83
|
+
const enabled = BROWSER && (DEV || production);
|
|
59
84
|
// The registry in context, read while the component sets up, as context must be.
|
|
60
85
|
// svelte-ignore state_referenced_locally
|
|
61
86
|
const nearest = enabled ? (registry ?? getRegistry()) : undefined;
|
|
@@ -67,7 +92,14 @@
|
|
|
67
92
|
let expanded = $state(false);
|
|
68
93
|
// The dock's height, in pixels, when not enlarged; dragging its top line changes it.
|
|
69
94
|
let height = $state(320);
|
|
95
|
+
// svelte-ignore state_referenced_locally
|
|
96
|
+
let shortcut = $state(appShortcut);
|
|
97
|
+
let corner = $state<Corner>("bottom-right");
|
|
98
|
+
// The launcher's opacity while nothing points at it, and its size.
|
|
99
|
+
let opacity = $state(1);
|
|
100
|
+
let scale = $state(1);
|
|
70
101
|
let innerHeight = $state(800);
|
|
102
|
+
let innerWidth = $state(1200);
|
|
71
103
|
let selected = $state<number>();
|
|
72
104
|
let dark = $state(false);
|
|
73
105
|
let registries = $state.raw<readonly AtomRegistry.AtomRegistry[]>([]);
|
|
@@ -88,6 +120,10 @@
|
|
|
88
120
|
showPlumbing = saved.plumbing ?? false;
|
|
89
121
|
expanded = saved.expanded ?? false;
|
|
90
122
|
height = saved.height ?? 320;
|
|
123
|
+
shortcut = saved.shortcut ?? appShortcut;
|
|
124
|
+
corner = saved.corner ?? "bottom-right";
|
|
125
|
+
opacity = saved.opacity ?? 1;
|
|
126
|
+
scale = saved.scale ?? 1;
|
|
91
127
|
mounted = true;
|
|
92
128
|
|
|
93
129
|
const stopWatching = watchRegistries((list) => {
|
|
@@ -135,7 +171,17 @@
|
|
|
135
171
|
if (!enabled || !mounted) {
|
|
136
172
|
return;
|
|
137
173
|
}
|
|
138
|
-
const saved: Saved = {
|
|
174
|
+
const saved: Saved = {
|
|
175
|
+
corner,
|
|
176
|
+
expanded,
|
|
177
|
+
height,
|
|
178
|
+
opacity,
|
|
179
|
+
open,
|
|
180
|
+
plumbing: showPlumbing,
|
|
181
|
+
scale,
|
|
182
|
+
shortcut,
|
|
183
|
+
tab,
|
|
184
|
+
};
|
|
139
185
|
try {
|
|
140
186
|
localStorage.setItem(storageKey, JSON.stringify(saved));
|
|
141
187
|
} catch {
|
|
@@ -219,6 +265,82 @@
|
|
|
219
265
|
}
|
|
220
266
|
};
|
|
221
267
|
|
|
268
|
+
const mac = BROWSER && /Mac|iPhone|iPad/u.test(navigator.platform);
|
|
269
|
+
const shortcutLabel = $derived.by(() => {
|
|
270
|
+
const parsed = parseShortcut(shortcut);
|
|
271
|
+
return parsed === undefined ? "no shortcut" : formatShortcut(parsed, mac);
|
|
272
|
+
});
|
|
273
|
+
// As aria-keyshortcuts writes it: "Alt+Shift+A".
|
|
274
|
+
const keyShortcuts = $derived.by(() => {
|
|
275
|
+
const parsed = parseShortcut(shortcut);
|
|
276
|
+
return parsed === undefined ? undefined : formatShortcut(parsed, false).replaceAll(" ", "+").replace("Ctrl", "Control");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
/** The shortcut, from anywhere on the page: opens the panel, or closes it. */
|
|
280
|
+
const onShortcut = (event: KeyboardEvent) => {
|
|
281
|
+
const parsed = parseShortcut(shortcut);
|
|
282
|
+
if (!enabled || !mounted || parsed === undefined || !matchesShortcut(event, parsed)) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
if (open) {
|
|
287
|
+
void closePanel();
|
|
288
|
+
} else {
|
|
289
|
+
openPanel();
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Dragging the launcher: it follows the pointer, then settles in the corner nearest where it was
|
|
294
|
+
// let go. A press that barely moves is a click.
|
|
295
|
+
let dragAt = $state<{ readonly x: number; readonly y: number }>();
|
|
296
|
+
let dragged = false;
|
|
297
|
+
const drag = (event: PointerEvent) => {
|
|
298
|
+
if (event.button !== 0) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const button = event.currentTarget as HTMLElement;
|
|
302
|
+
const box = button.getBoundingClientRect();
|
|
303
|
+
const offsetX = event.clientX - box.left;
|
|
304
|
+
const offsetY = event.clientY - box.top;
|
|
305
|
+
const startX = event.clientX;
|
|
306
|
+
const startY = event.clientY;
|
|
307
|
+
dragged = false;
|
|
308
|
+
// No text selection: a selection would make the next press start the browser's own drag of
|
|
309
|
+
// it, which cancels the pointer.
|
|
310
|
+
event.preventDefault();
|
|
311
|
+
// From the press on, so a quick drag that leaves the button still moves it.
|
|
312
|
+
button.setPointerCapture(event.pointerId);
|
|
313
|
+
const move = (next: PointerEvent) => {
|
|
314
|
+
if (!dragged && Math.hypot(next.clientX - startX, next.clientY - startY) < 5) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
dragged = true;
|
|
318
|
+
dragAt = { x: next.clientX - offsetX, y: next.clientY - offsetY };
|
|
319
|
+
};
|
|
320
|
+
const stop = (last: PointerEvent) => {
|
|
321
|
+
button.removeEventListener("pointermove", move);
|
|
322
|
+
button.removeEventListener("pointerup", stop);
|
|
323
|
+
button.removeEventListener("pointercancel", stop);
|
|
324
|
+
if (dragged) {
|
|
325
|
+
const top = last.clientY < innerHeight / 2;
|
|
326
|
+
const left = last.clientX < innerWidth / 2;
|
|
327
|
+
corner = `${top ? "top" : "bottom"}-${left ? "left" : "right"}`;
|
|
328
|
+
}
|
|
329
|
+
dragAt = undefined;
|
|
330
|
+
};
|
|
331
|
+
button.addEventListener("pointermove", move);
|
|
332
|
+
button.addEventListener("pointerup", stop);
|
|
333
|
+
button.addEventListener("pointercancel", stop);
|
|
334
|
+
};
|
|
335
|
+
const launch = () => {
|
|
336
|
+
// The click that ends a drag doesn't open the panel.
|
|
337
|
+
if (dragged) {
|
|
338
|
+
dragged = false;
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
openPanel();
|
|
342
|
+
};
|
|
343
|
+
|
|
222
344
|
const pad = (count: number) => String(count).padStart(2, "0");
|
|
223
345
|
|
|
224
346
|
const select = (id: number | undefined) => {
|
|
@@ -230,13 +352,15 @@
|
|
|
230
352
|
{ id: "graph", label: "Graph" },
|
|
231
353
|
{ id: "sheets", label: "Sheets" },
|
|
232
354
|
{ id: "timeline", label: "Timeline" },
|
|
355
|
+
{ id: "settings", label: "Settings" },
|
|
233
356
|
];
|
|
234
357
|
</script>
|
|
235
358
|
|
|
236
|
-
<svelte:window bind:innerHeight />
|
|
359
|
+
<svelte:window bind:innerHeight bind:innerWidth onkeydown={onShortcut} />
|
|
237
360
|
|
|
238
361
|
{#if enabled && mounted && model}
|
|
239
|
-
|
|
362
|
+
<!-- data-atom-devtools: where an app sets the panel's own colours and fonts (README, Theming). -->
|
|
363
|
+
<div class="devtools" class:dark data-atom-devtools>
|
|
240
364
|
{#if open}
|
|
241
365
|
<!-- A region of the page, not a modal: the page stays usable with it open. Escape from anything
|
|
242
366
|
in it closes it. -->
|
|
@@ -331,13 +455,27 @@
|
|
|
331
455
|
</div>
|
|
332
456
|
{:else if tab === "sheets"}
|
|
333
457
|
<SheetsView {model} onselect={select} {selected} {showPlumbing} />
|
|
334
|
-
{:else}
|
|
458
|
+
{:else if tab === "timeline"}
|
|
335
459
|
<TimelineView {model} onselect={select} {showPlumbing} />
|
|
460
|
+
{:else}
|
|
461
|
+
<SettingsView bind:corner bind:opacity bind:scale bind:shortcut defaultShortcut={appShortcut} />
|
|
336
462
|
{/if}
|
|
337
463
|
</div>
|
|
338
464
|
</section>
|
|
339
465
|
{:else}
|
|
340
|
-
<button
|
|
466
|
+
<button
|
|
467
|
+
bind:this={launcher}
|
|
468
|
+
style:--launcher-opacity={opacity}
|
|
469
|
+
style:--launcher-scale={scale}
|
|
470
|
+
style:left={dragAt ? `${dragAt.x}px` : undefined}
|
|
471
|
+
style:top={dragAt ? `${dragAt.y}px` : undefined}
|
|
472
|
+
aria-keyshortcuts={keyShortcuts}
|
|
473
|
+
aria-label="Open the atom devtools"
|
|
474
|
+
class={["launcher", corner, dragAt && "dragging"]}
|
|
475
|
+
onclick={launch}
|
|
476
|
+
onpointerdown={drag}
|
|
477
|
+
title="Atom devtools ({shortcutLabel}). Drag to move."
|
|
478
|
+
type="button">
|
|
341
479
|
<b aria-hidden="true">◎</b> Atoms <span class="n">{pad(model.totals.atoms)}</span>
|
|
342
480
|
</button>
|
|
343
481
|
{/if}
|
|
@@ -364,8 +502,7 @@
|
|
|
364
502
|
--success: var(--tone-success, #16a34a);
|
|
365
503
|
--alert: var(--tone-failure, #dc2626);
|
|
366
504
|
--mono: var(--font-mono, ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace);
|
|
367
|
-
--serif:
|
|
368
|
-
--sans: var(--font-sans, ui-sans-serif, system-ui, sans-serif);
|
|
505
|
+
--serif: var(--font-serif, ui-serif, Georgia, "Times New Roman", serif);
|
|
369
506
|
--radius: 6px;
|
|
370
507
|
color: var(--ink);
|
|
371
508
|
font-family: var(--mono);
|
|
@@ -392,21 +529,51 @@
|
|
|
392
529
|
background: var(--paper);
|
|
393
530
|
border: 1px solid var(--line);
|
|
394
531
|
border-radius: var(--radius);
|
|
395
|
-
bottom: 16px;
|
|
396
532
|
color: var(--muted);
|
|
397
533
|
cursor: pointer;
|
|
398
534
|
display: inline-flex;
|
|
399
535
|
font-family: var(--mono);
|
|
400
|
-
font-size: 10.5px;
|
|
401
|
-
gap: 0.5rem;
|
|
402
|
-
height: 32px;
|
|
536
|
+
font-size: calc(10.5px * var(--launcher-scale, 1));
|
|
537
|
+
gap: calc(0.5rem * var(--launcher-scale, 1));
|
|
538
|
+
height: calc(32px * var(--launcher-scale, 1));
|
|
403
539
|
letter-spacing: 0.08em;
|
|
404
|
-
|
|
540
|
+
opacity: var(--launcher-opacity, 1);
|
|
541
|
+
padding: 0 calc(0.75rem * var(--launcher-scale, 1));
|
|
405
542
|
position: fixed;
|
|
406
|
-
right: 16px;
|
|
407
543
|
text-transform: uppercase;
|
|
544
|
+
touch-action: none;
|
|
545
|
+
transition: opacity 0.15s;
|
|
546
|
+
user-select: none;
|
|
408
547
|
z-index: 2147483000;
|
|
409
548
|
}
|
|
549
|
+
.launcher.bottom-right {
|
|
550
|
+
bottom: 16px;
|
|
551
|
+
right: 16px;
|
|
552
|
+
}
|
|
553
|
+
.launcher.bottom-left {
|
|
554
|
+
bottom: 16px;
|
|
555
|
+
left: 16px;
|
|
556
|
+
}
|
|
557
|
+
.launcher.top-right {
|
|
558
|
+
right: 16px;
|
|
559
|
+
top: 16px;
|
|
560
|
+
}
|
|
561
|
+
.launcher.top-left {
|
|
562
|
+
left: 16px;
|
|
563
|
+
top: 16px;
|
|
564
|
+
}
|
|
565
|
+
/* While dragged, it's placed by its left and top alone. */
|
|
566
|
+
.launcher.dragging {
|
|
567
|
+
bottom: auto;
|
|
568
|
+
cursor: grabbing;
|
|
569
|
+
right: auto;
|
|
570
|
+
}
|
|
571
|
+
/* Faded or not, it's opaque while pointed at, focused or dragged. */
|
|
572
|
+
.launcher:hover,
|
|
573
|
+
.launcher:focus-visible,
|
|
574
|
+
.launcher.dragging {
|
|
575
|
+
opacity: 1;
|
|
576
|
+
}
|
|
410
577
|
.launcher:hover {
|
|
411
578
|
border-color: var(--accent);
|
|
412
579
|
color: var(--ink);
|
|
@@ -431,6 +598,7 @@
|
|
|
431
598
|
--tone-success: var(--success);
|
|
432
599
|
--tone-failure: var(--alert);
|
|
433
600
|
--font-mono: var(--mono);
|
|
601
|
+
--font-serif: var(--serif);
|
|
434
602
|
background: var(--paper);
|
|
435
603
|
border-top: 1px solid var(--line);
|
|
436
604
|
bottom: 0;
|
|
@@ -6,11 +6,22 @@ interface Props {
|
|
|
6
6
|
readonly open?: boolean | undefined;
|
|
7
7
|
/** Light paper, a dark blueprint, or the page's own (`auto`: a `dark` class on `<html>`, or the system's). */
|
|
8
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;
|
|
9
20
|
}
|
|
10
21
|
/**
|
|
11
22
|
* A panel docked along the bottom of the window that shows the atom registry live: its dependency
|
|
12
|
-
* graph, a sheet per atom and a timeline of everything it does. Development only
|
|
13
|
-
* build, or on the server, it renders nothing.
|
|
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.
|
|
14
25
|
*
|
|
15
26
|
* It's drawn like the effect-atom-svelte docs: ruled in hairlines, with mono labels, numbered views
|
|
16
27
|
* and an amber accent, in the page's own colours where it has them (--background, --foreground,
|
|
@@ -21,7 +32,7 @@ interface Props {
|
|
|
21
32
|
* the app has several, a picker in the panel switches between them.
|
|
22
33
|
*
|
|
23
34
|
* Render it only in development, behind Vite's `DEV` flag, so a build leaves it out: the README
|
|
24
|
-
* shows how.
|
|
35
|
+
* shows how. To show it in production too, as the effect-atom-svelte docs do, set `production`.
|
|
25
36
|
*/
|
|
26
37
|
declare const AtomDevtools: import("svelte").Component<Props, {}, "">;
|
|
27
38
|
type AtomDevtools = ReturnType<typeof AtomDevtools>;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* A panel docked along the bottom of the window, with the registry's dependency graph, a sheet per
|
|
8
|
-
* atom and a timeline of everything the registry does. Development only
|
|
8
|
+
* atom and a timeline of everything the registry does. Development only, unless `production` is
|
|
9
|
+
* set.
|
|
9
10
|
*
|
|
10
11
|
* @since 0.2.0
|
|
11
12
|
* @category components
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
7
|
* A panel docked along the bottom of the window, with the registry's dependency graph, a sheet per
|
|
8
|
-
* atom and a timeline of everything the registry does. Development only
|
|
8
|
+
* atom and a timeline of everything the registry does. Development only, unless `production` is
|
|
9
|
+
* set.
|
|
9
10
|
*
|
|
10
11
|
* @since 0.2.0
|
|
11
12
|
* @category components
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Cause } from "effect";
|
|
1
2
|
/** The state of an atom's value, for its marks and its sheet. */
|
|
2
3
|
export type ValueState = {
|
|
3
4
|
readonly _tag: "Value";
|
|
@@ -16,5 +17,11 @@ export declare const stateText: (state: ValueState) => string;
|
|
|
16
17
|
export declare const plain: (value: unknown, depth?: number, seen?: Set<object>) => unknown;
|
|
17
18
|
/** The value written out in full, for its sheet. */
|
|
18
19
|
export declare const detail: (value: unknown) => string;
|
|
20
|
+
/**
|
|
21
|
+
* What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
|
|
22
|
+
* or with its fields when `full`; a defect as `defect: TypeError`; an interruption as
|
|
23
|
+
* `interrupted`.
|
|
24
|
+
*/
|
|
25
|
+
export declare const failureText: (cause: Cause.Cause<unknown>, full?: boolean) => string;
|
|
19
26
|
/** The value on one line, cut to `length` characters. */
|
|
20
27
|
export declare const preview: (value: unknown, length?: number) => string;
|
package/dist/internal/format.js
CHANGED
|
@@ -118,14 +118,59 @@ const json = (data, indent) => typeof data === "string"
|
|
|
118
118
|
: (JSON.stringify(data, undefined, indent) ?? String(data));
|
|
119
119
|
/** The value written out in full, for its sheet. */
|
|
120
120
|
export const detail = (value) => json(plain(value), 2);
|
|
121
|
-
/** An
|
|
121
|
+
/** An error's name: a tagged error's `_tag`, an `Error`'s `name`, or the value as a string. */
|
|
122
|
+
const errorName = (error) => {
|
|
123
|
+
if (typeof error === "object" && error !== null) {
|
|
124
|
+
if ("_tag" in error && typeof error._tag === "string") {
|
|
125
|
+
return error._tag;
|
|
126
|
+
}
|
|
127
|
+
if (error instanceof Error) {
|
|
128
|
+
return error.name;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return String(error);
|
|
132
|
+
};
|
|
133
|
+
/** An error with its fields, as `CityNotFound { city: "Atlantis" }`, or its message if it has one. */
|
|
134
|
+
const errorText = (error) => {
|
|
135
|
+
const name = errorName(error);
|
|
136
|
+
if (typeof error !== "object" || error === null) {
|
|
137
|
+
return name;
|
|
138
|
+
}
|
|
139
|
+
if ("message" in error &&
|
|
140
|
+
typeof error.message === "string" &&
|
|
141
|
+
error.message !== "") {
|
|
142
|
+
return `${name}: ${error.message}`;
|
|
143
|
+
}
|
|
144
|
+
const fields = Object.entries(error).filter(([key]) => key !== "_tag");
|
|
145
|
+
const body = fields.map(([key, field]) => `${key}: ${json(plain(field))}`);
|
|
146
|
+
return body.length > 0 ? `${name} { ${body.join(", ")} }` : name;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
|
|
150
|
+
* or with its fields when `full`; a defect as `defect: TypeError`; an interruption as
|
|
151
|
+
* `interrupted`.
|
|
152
|
+
*/
|
|
153
|
+
export const failureText = (cause, full = false) => {
|
|
154
|
+
const [reason] = cause.reasons;
|
|
155
|
+
if (reason === undefined) {
|
|
156
|
+
return "empty cause";
|
|
157
|
+
}
|
|
158
|
+
if (Cause.isFailReason(reason)) {
|
|
159
|
+
return full ? errorText(reason.error) : errorName(reason.error);
|
|
160
|
+
}
|
|
161
|
+
if (Cause.isDieReason(reason)) {
|
|
162
|
+
return `defect: ${full ? errorText(reason.defect) : errorName(reason.defect)}`;
|
|
163
|
+
}
|
|
164
|
+
return "interrupted";
|
|
165
|
+
};
|
|
166
|
+
/** An `AsyncResult` on one line: its value, through `inner`, or what it failed with. */
|
|
122
167
|
const resultText = (result, inner) => {
|
|
123
168
|
let text = "Initial";
|
|
124
169
|
if (result._tag === "Success") {
|
|
125
170
|
text = inner(result.value);
|
|
126
171
|
}
|
|
127
172
|
else if (result._tag === "Failure") {
|
|
128
|
-
text =
|
|
173
|
+
text = failureText(result.cause, true);
|
|
129
174
|
}
|
|
130
175
|
return result.waiting ? `${text}, waiting` : text;
|
|
131
176
|
};
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
<script lang="ts">
|
|
7
7
|
import { AtomGraph, toneOf } from "../graph/index.js";
|
|
8
8
|
import type { GraphAtom, GraphInput } from "../graph/index.js";
|
|
9
|
-
import {
|
|
9
|
+
import { AsyncResult } from "effect/reactivity";
|
|
10
|
+
|
|
11
|
+
import { failureText, preview, stateText } from "./format.js";
|
|
10
12
|
import type { AtomView } from "./model.svelte.js";
|
|
11
13
|
import { lingerFor } from "./model.svelte.js";
|
|
12
14
|
|
|
@@ -48,8 +50,13 @@
|
|
|
48
50
|
return "removed · finalizers ran";
|
|
49
51
|
}
|
|
50
52
|
const state = stateText(view.state);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
let value = view.hasValue ? preview(view.value, 26) : "";
|
|
54
|
+
// A failure shows what it failed with, by name: its fields are on its sheet.
|
|
55
|
+
if (AsyncResult.isAsyncResult(view.value) && AsyncResult.isFailure(view.value)) {
|
|
56
|
+
value = failureText(view.value.cause);
|
|
57
|
+
}
|
|
58
|
+
const withValue = state === "" || view.state._tag === "Success" || view.state._tag === "Failure";
|
|
59
|
+
const parts = [state, withValue ? value : ""];
|
|
53
60
|
if (view.readers === 0 && view.children.length === 0) {
|
|
54
61
|
parts.push(heldBecause(view));
|
|
55
62
|
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The panel's settings: the shortcut that opens and closes it, and where the launcher sits, how
|
|
3
|
+
opaque it is and how big. The panel saves them with the rest of its state.
|
|
4
|
+
-->
|
|
5
|
+
<script module lang="ts">
|
|
6
|
+
/** Where the launcher sits. */
|
|
7
|
+
export type Corner = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<script lang="ts">
|
|
11
|
+
import {
|
|
12
|
+
formatShortcut,
|
|
13
|
+
parseShortcut,
|
|
14
|
+
shortcutFromEvent,
|
|
15
|
+
stringifyShortcut,
|
|
16
|
+
} from "./shortcut.js";
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
/** The shortcut, as "alt+shift+a". */
|
|
20
|
+
shortcut: string;
|
|
21
|
+
/** The shortcut the app set (`shortcut` prop), which Reset goes back to. */
|
|
22
|
+
readonly defaultShortcut: string;
|
|
23
|
+
corner: Corner;
|
|
24
|
+
/** The launcher's opacity while nothing points at it, from 0.2 to 1. */
|
|
25
|
+
opacity: number;
|
|
26
|
+
/** The launcher's size, from 0.75 to 1.5. */
|
|
27
|
+
scale: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
corner = $bindable(),
|
|
32
|
+
defaultShortcut,
|
|
33
|
+
opacity = $bindable(),
|
|
34
|
+
scale = $bindable(),
|
|
35
|
+
shortcut = $bindable(),
|
|
36
|
+
}: Props = $props();
|
|
37
|
+
|
|
38
|
+
const mac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/u.test(navigator.platform);
|
|
39
|
+
const shown = $derived.by(() => {
|
|
40
|
+
const parsed = parseShortcut(shortcut);
|
|
41
|
+
return parsed === undefined ? "none" : formatShortcut(parsed, mac);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// While recording, the next key press that can be a shortcut becomes it; Escape cancels.
|
|
45
|
+
let recording = $state(false);
|
|
46
|
+
const record = (event: KeyboardEvent) => {
|
|
47
|
+
if (!recording) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
if (event.key === "Escape") {
|
|
53
|
+
recording = false;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const next = shortcutFromEvent(event);
|
|
57
|
+
if (next !== undefined) {
|
|
58
|
+
shortcut = stringifyShortcut(next);
|
|
59
|
+
recording = false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const corners: readonly { readonly id: Corner; readonly label: string }[] = [
|
|
64
|
+
{ id: "top-left", label: "Top left" },
|
|
65
|
+
{ id: "top-right", label: "Top right" },
|
|
66
|
+
{ id: "bottom-left", label: "Bottom left" },
|
|
67
|
+
{ id: "bottom-right", label: "Bottom right" },
|
|
68
|
+
];
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<svelte:window onkeydowncapture={record} />
|
|
72
|
+
|
|
73
|
+
<div class="settings">
|
|
74
|
+
<div class="row">
|
|
75
|
+
<span class="key" id="devtools-shortcut">Shortcut</span>
|
|
76
|
+
<div class="value">
|
|
77
|
+
<kbd aria-labelledby="devtools-shortcut">{recording ? "Press a shortcut…" : shown}</kbd>
|
|
78
|
+
<button aria-pressed={recording} class="tool" onclick={() => (recording = !recording)} type="button">
|
|
79
|
+
{recording ? "Cancel" : "Change"}
|
|
80
|
+
</button>
|
|
81
|
+
<button class="tool" disabled={shortcut === defaultShortcut} onclick={() => (shortcut = defaultShortcut)} type="button">
|
|
82
|
+
Reset
|
|
83
|
+
</button>
|
|
84
|
+
<p class="note">
|
|
85
|
+
Opens and closes the panel anywhere on the page. It needs Ctrl, Alt or {mac ? "⌘" : "Meta"} (or a function key), so it can't catch typing.
|
|
86
|
+
</p>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
<div class="row">
|
|
90
|
+
<span class="key" id="devtools-corner">Button</span>
|
|
91
|
+
<div class="value">
|
|
92
|
+
<div aria-labelledby="devtools-corner" class="corners" role="group">
|
|
93
|
+
{#each corners as item (item.id)}
|
|
94
|
+
<button aria-pressed={corner === item.id} class="tool" onclick={() => (corner = item.id)} type="button">
|
|
95
|
+
{item.label}
|
|
96
|
+
</button>
|
|
97
|
+
{/each}
|
|
98
|
+
</div>
|
|
99
|
+
<p class="note">Or drag the button: it settles in the nearest corner.</p>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
<label class="row">
|
|
103
|
+
<span class="key">Opacity</span>
|
|
104
|
+
<span class="value">
|
|
105
|
+
<input bind:value={opacity} max="1" min="0.2" step="0.05" type="range" />
|
|
106
|
+
<output>{Math.round(opacity * 100)}%</output>
|
|
107
|
+
<span class="note">The button is opaque again while you point at it or focus it.</span>
|
|
108
|
+
</span>
|
|
109
|
+
</label>
|
|
110
|
+
<label class="row">
|
|
111
|
+
<span class="key">Size</span>
|
|
112
|
+
<span class="value">
|
|
113
|
+
<input bind:value={scale} max="1.5" min="0.75" step="0.05" type="range" />
|
|
114
|
+
<output>{Math.round(scale * 100)}%</output>
|
|
115
|
+
</span>
|
|
116
|
+
</label>
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<style>
|
|
120
|
+
.settings {
|
|
121
|
+
font-family: var(--mono);
|
|
122
|
+
font-size: 0.74rem;
|
|
123
|
+
height: 100%;
|
|
124
|
+
overflow: auto;
|
|
125
|
+
}
|
|
126
|
+
.row {
|
|
127
|
+
align-items: baseline;
|
|
128
|
+
border-bottom: 1px solid var(--line);
|
|
129
|
+
display: grid;
|
|
130
|
+
gap: 1rem;
|
|
131
|
+
grid-template-columns: 7rem minmax(0, 1fr);
|
|
132
|
+
padding: 0.75rem 0.9rem;
|
|
133
|
+
}
|
|
134
|
+
.key {
|
|
135
|
+
color: var(--muted);
|
|
136
|
+
font-size: 10.5px;
|
|
137
|
+
letter-spacing: 0.08em;
|
|
138
|
+
text-transform: uppercase;
|
|
139
|
+
}
|
|
140
|
+
.value {
|
|
141
|
+
align-items: center;
|
|
142
|
+
display: flex;
|
|
143
|
+
flex-wrap: wrap;
|
|
144
|
+
gap: 0.5rem 0.75rem;
|
|
145
|
+
}
|
|
146
|
+
kbd {
|
|
147
|
+
border: 1px solid var(--line);
|
|
148
|
+
border-radius: 4px;
|
|
149
|
+
color: var(--ink);
|
|
150
|
+
font: inherit;
|
|
151
|
+
min-width: 6rem;
|
|
152
|
+
padding: 0.2rem 0.6rem;
|
|
153
|
+
text-align: center;
|
|
154
|
+
}
|
|
155
|
+
.corners {
|
|
156
|
+
display: flex;
|
|
157
|
+
flex-wrap: wrap;
|
|
158
|
+
gap: 0.4rem;
|
|
159
|
+
}
|
|
160
|
+
.tool {
|
|
161
|
+
background: none;
|
|
162
|
+
border: 1px solid var(--line);
|
|
163
|
+
border-radius: 4px;
|
|
164
|
+
color: var(--ink);
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
font: inherit;
|
|
167
|
+
letter-spacing: 0.04em;
|
|
168
|
+
padding: 0.2rem 0.6rem;
|
|
169
|
+
}
|
|
170
|
+
.tool:hover:not(:disabled) {
|
|
171
|
+
border-color: var(--accent);
|
|
172
|
+
}
|
|
173
|
+
.tool:disabled {
|
|
174
|
+
color: var(--subtle);
|
|
175
|
+
cursor: default;
|
|
176
|
+
}
|
|
177
|
+
.tool[aria-pressed="true"] {
|
|
178
|
+
background: color-mix(in oklab, var(--accent) 12%, transparent);
|
|
179
|
+
border-color: var(--accent);
|
|
180
|
+
}
|
|
181
|
+
input[type="range"] {
|
|
182
|
+
accent-color: var(--accent);
|
|
183
|
+
width: 12rem;
|
|
184
|
+
}
|
|
185
|
+
output {
|
|
186
|
+
color: var(--ink);
|
|
187
|
+
font-variant-numeric: tabular-nums;
|
|
188
|
+
min-width: 3rem;
|
|
189
|
+
}
|
|
190
|
+
.note {
|
|
191
|
+
color: var(--muted);
|
|
192
|
+
flex-basis: 100%;
|
|
193
|
+
font-family: var(--serif);
|
|
194
|
+
font-size: 0.8rem;
|
|
195
|
+
font-style: italic;
|
|
196
|
+
margin: 0;
|
|
197
|
+
}
|
|
198
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Where the launcher sits. */
|
|
2
|
+
export type Corner = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
3
|
+
interface Props {
|
|
4
|
+
/** The shortcut, as "alt+shift+a". */
|
|
5
|
+
shortcut: string;
|
|
6
|
+
/** The shortcut the app set (`shortcut` prop), which Reset goes back to. */
|
|
7
|
+
readonly defaultShortcut: string;
|
|
8
|
+
corner: Corner;
|
|
9
|
+
/** The launcher's opacity while nothing points at it, from 0.2 to 1. */
|
|
10
|
+
opacity: number;
|
|
11
|
+
/** The launcher's size, from 0.75 to 1.5. */
|
|
12
|
+
scale: number;
|
|
13
|
+
}
|
|
14
|
+
declare const SettingsView: import("svelte").Component<Props, {}, "corner" | "opacity" | "scale" | "shortcut">;
|
|
15
|
+
type SettingsView = ReturnType<typeof SettingsView>;
|
|
16
|
+
export default SettingsView;
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
happened to it lately.
|
|
5
5
|
-->
|
|
6
6
|
<script lang="ts">
|
|
7
|
+
import { DEV } from "esm-env";
|
|
8
|
+
|
|
7
9
|
import { detail, stateText } from "./format.js";
|
|
8
10
|
import type { AtomView, Model, TimelineEntry } from "./model.svelte.js";
|
|
9
11
|
import { openInEditor, shortPlace } from "./names.js";
|
|
@@ -185,7 +187,12 @@
|
|
|
185
187
|
<span class="key">DECLARED</span>
|
|
186
188
|
{#if current.identity.place}
|
|
187
189
|
{@const place = current.identity.place}
|
|
188
|
-
|
|
190
|
+
<!-- Only the dev server can open a file in the editor. -->
|
|
191
|
+
{#if DEV}
|
|
192
|
+
<button class="link" onclick={() => void openInEditor(place)} title="Open {place.file}:{place.line} in the editor" type="button">{shortPlace(place)}</button>
|
|
193
|
+
{:else}
|
|
194
|
+
<span title="{place.file}:{place.line}">{shortPlace(place)}</span>
|
|
195
|
+
{/if}
|
|
189
196
|
{:else}
|
|
190
197
|
—
|
|
191
198
|
{/if}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** A shortcut: its modifiers and the `KeyboardEvent.code` of its key, such as `KeyA` or `F2`. */
|
|
2
|
+
export interface Shortcut {
|
|
3
|
+
readonly alt: boolean;
|
|
4
|
+
readonly ctrl: boolean;
|
|
5
|
+
readonly meta: boolean;
|
|
6
|
+
readonly shift: boolean;
|
|
7
|
+
readonly code: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const defaultShortcut = "alt+shift+a";
|
|
10
|
+
/** Reads "alt+shift+a" (or "Ctrl+Shift+F2", "meta+k"); `undefined` when there is no key. */
|
|
11
|
+
export declare const parseShortcut: (text: string) => Shortcut | undefined;
|
|
12
|
+
/** The string form, as `parseShortcut` reads it and the settings save it: "alt+shift+a". */
|
|
13
|
+
export declare const stringifyShortcut: (shortcut: Shortcut) => string;
|
|
14
|
+
/** For display: "Alt Shift A", or "⌘ ⇧ A" on a Mac. */
|
|
15
|
+
export declare const formatShortcut: (shortcut: Shortcut, mac: boolean) => string;
|
|
16
|
+
/** Whether a key press is the shortcut, with exactly its modifiers. */
|
|
17
|
+
export declare const matchesShortcut: (event: KeyboardEvent, shortcut: Shortcut) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The shortcut a key press makes, when recording a new one: `undefined` for a modifier on its own,
|
|
20
|
+
* and for a key without Ctrl, Alt or Meta (other than a function key), which would catch typing.
|
|
21
|
+
*/
|
|
22
|
+
export declare const shortcutFromEvent: (event: KeyboardEvent) => Shortcut | undefined;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The keyboard shortcut that opens and closes the panel: written as a string such as "alt+shift+a"
|
|
2
|
+
// (the `shortcut` prop, and what the settings save), matched against the key's physical code, so a
|
|
3
|
+
// layout or a modifier that changes the character typed (Alt on a Mac) doesn't break it.
|
|
4
|
+
export const defaultShortcut = "alt+shift+a";
|
|
5
|
+
const modifierCodes = new Set([
|
|
6
|
+
"AltLeft",
|
|
7
|
+
"AltRight",
|
|
8
|
+
"ControlLeft",
|
|
9
|
+
"ControlRight",
|
|
10
|
+
"MetaLeft",
|
|
11
|
+
"MetaRight",
|
|
12
|
+
"ShiftLeft",
|
|
13
|
+
"ShiftRight",
|
|
14
|
+
]);
|
|
15
|
+
/** The code a key's name stands for: `a` is `KeyA`, `1` is `Digit1`, and anything else as it is. */
|
|
16
|
+
const codeOf = (key) => {
|
|
17
|
+
if (/^[a-z]$/iu.test(key)) {
|
|
18
|
+
return `Key${key.toUpperCase()}`;
|
|
19
|
+
}
|
|
20
|
+
if (/^\d$/u.test(key)) {
|
|
21
|
+
return `Digit${key}`;
|
|
22
|
+
}
|
|
23
|
+
return key.length > 1 ? key.charAt(0).toUpperCase() + key.slice(1) : key;
|
|
24
|
+
};
|
|
25
|
+
/** Reads "alt+shift+a" (or "Ctrl+Shift+F2", "meta+k"); `undefined` when there is no key. */
|
|
26
|
+
export const parseShortcut = (text) => {
|
|
27
|
+
const parts = text
|
|
28
|
+
.split("+")
|
|
29
|
+
.map((part) => part.trim())
|
|
30
|
+
.filter(Boolean);
|
|
31
|
+
const key = parts.pop();
|
|
32
|
+
if (key === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const mods = new Set(parts.map((part) => part.toLowerCase()));
|
|
36
|
+
return {
|
|
37
|
+
alt: mods.has("alt") || mods.has("option"),
|
|
38
|
+
code: codeOf(key),
|
|
39
|
+
ctrl: mods.has("ctrl") || mods.has("control"),
|
|
40
|
+
meta: mods.has("meta") || mods.has("cmd") || mods.has("command"),
|
|
41
|
+
shift: mods.has("shift"),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** The key's own name, as a person reads it: `KeyA` is `A`, `Digit1` is `1`. */
|
|
45
|
+
const keyName = (code) => code.replace(/^Key(?=[A-Z]$)/u, "").replace(/^Digit(?=\d$)/u, "");
|
|
46
|
+
/** The string form, as `parseShortcut` reads it and the settings save it: "alt+shift+a". */
|
|
47
|
+
export const stringifyShortcut = (shortcut) => [
|
|
48
|
+
shortcut.ctrl && "ctrl",
|
|
49
|
+
shortcut.meta && "meta",
|
|
50
|
+
shortcut.alt && "alt",
|
|
51
|
+
shortcut.shift && "shift",
|
|
52
|
+
keyName(shortcut.code).toLowerCase(),
|
|
53
|
+
]
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join("+");
|
|
56
|
+
/** For display: "Alt Shift A", or "⌘ ⇧ A" on a Mac. */
|
|
57
|
+
export const formatShortcut = (shortcut, mac) => [
|
|
58
|
+
shortcut.ctrl && (mac ? "⌃" : "Ctrl"),
|
|
59
|
+
shortcut.meta && (mac ? "⌘" : "Meta"),
|
|
60
|
+
shortcut.alt && (mac ? "⌥" : "Alt"),
|
|
61
|
+
shortcut.shift && (mac ? "⇧" : "Shift"),
|
|
62
|
+
keyName(shortcut.code),
|
|
63
|
+
]
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.join(" ");
|
|
66
|
+
/** Whether a key press is the shortcut, with exactly its modifiers. */
|
|
67
|
+
export const matchesShortcut = (event, shortcut) => event.code === shortcut.code &&
|
|
68
|
+
event.altKey === shortcut.alt &&
|
|
69
|
+
event.ctrlKey === shortcut.ctrl &&
|
|
70
|
+
event.metaKey === shortcut.meta &&
|
|
71
|
+
event.shiftKey === shortcut.shift;
|
|
72
|
+
/**
|
|
73
|
+
* The shortcut a key press makes, when recording a new one: `undefined` for a modifier on its own,
|
|
74
|
+
* and for a key without Ctrl, Alt or Meta (other than a function key), which would catch typing.
|
|
75
|
+
*/
|
|
76
|
+
export const shortcutFromEvent = (event) => {
|
|
77
|
+
if (modifierCodes.has(event.code)) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
const functionKey = /^F\d{1,2}$/u.test(event.code);
|
|
81
|
+
if (!(event.altKey || event.ctrlKey || event.metaKey || functionKey)) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
alt: event.altKey,
|
|
86
|
+
code: event.code,
|
|
87
|
+
ctrl: event.ctrlKey,
|
|
88
|
+
meta: event.metaKey,
|
|
89
|
+
shift: event.shiftKey,
|
|
90
|
+
};
|
|
91
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effect-atom-svelte-devtools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Developer tools for effect-atom-svelte: atom names from your source, and a live view of the registry",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"devtools",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@sveltejs/vite-plugin-svelte": "^7.2.0",
|
|
61
61
|
"@types/node": "^24",
|
|
62
62
|
"effect": "4.0.1",
|
|
63
|
-
"effect-atom-svelte": "
|
|
63
|
+
"effect-atom-svelte": "workspace:*",
|
|
64
64
|
"svelte": "^5.57.2",
|
|
65
65
|
"svelte-check": "^4.6.0",
|
|
66
66
|
"vite": "^8.3.0",
|