effect-atom-svelte-devtools 0.2.1 → 0.3.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/dist/atom-devtools.svelte +164 -43
- package/dist/atom-devtools.svelte.d.ts +2 -1
- package/dist/graph/atom-graph.svelte +40 -9
- package/dist/graph/frame-graph.svelte +45 -37
- package/dist/graph/frame-graph.svelte.d.ts +1 -24
- package/dist/graph/graph-types.d.ts +28 -0
- package/dist/graph/graph-types.js +2 -0
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/layout.d.ts +5 -2
- package/dist/graph/layout.js +8 -4
- package/dist/internal/format.d.ts +6 -6
- package/dist/internal/format.js +106 -70
- package/dist/internal/graph-view.svelte +23 -16
- package/dist/internal/label.js +40 -17
- package/dist/internal/model.svelte.js +41 -29
- package/dist/internal/names.d.ts +1 -1
- package/dist/internal/names.js +24 -4
- package/dist/internal/settings-view.svelte +35 -8
- package/dist/internal/sheets-view.svelte +112 -36
- package/dist/internal/shortcut.d.ts +4 -1
- package/dist/internal/shortcut.js +19 -7
- package/dist/internal/timeline-view.svelte +79 -26
- package/dist/internal/transform.js +179 -74
- package/dist/vite.js +4 -2
- package/package.json +9 -8
package/dist/internal/names.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface Identity {
|
|
|
17
17
|
* The place a stack frame points at. The plugin's frames hold the file as the dev server addresses
|
|
18
18
|
* it; `Atom.withLabel`'s are the browser's, a URL with the dev server's origin and a query.
|
|
19
19
|
*/
|
|
20
|
-
export declare const parseFrame: (frame: string) => Place | undefined;
|
|
20
|
+
export declare const parseFrame: (frame: string, name?: string) => Place | undefined;
|
|
21
21
|
export declare const identify: (atom: Atom.Atom<unknown>) => Identity;
|
|
22
22
|
/** The file's name without its folders, for a short reference: `todos.ts:12`. */
|
|
23
23
|
export declare const shortPlace: (place: Place) => string;
|
package/dist/internal/names.js
CHANGED
|
@@ -2,12 +2,29 @@
|
|
|
2
2
|
import { Atom } from "effect/reactivity";
|
|
3
3
|
// The last `file:line:column` in a stack frame, with or without parentheses around it.
|
|
4
4
|
const framePattern = /(?<file>[^\s()]+):(?<line>\d+):(?<column>\d+)\)?\s*$/u;
|
|
5
|
+
// A place as the plugin writes it, `/src/lib/todos.ts:4:14`, whatever the file's name holds.
|
|
6
|
+
const ownPattern = /^(?<file>.+):(?<line>\d+):(?<column>\d+)$/u;
|
|
7
|
+
// A browser frame's URL, which may hold parentheses, as a SvelteKit route group's folder does.
|
|
8
|
+
const urlPattern = /(?<file>[a-z][\w+.-]*:\/\/\S+?):(?<line>\d+):(?<column>\d+)\)?\s*$/iu;
|
|
5
9
|
/**
|
|
6
10
|
* The place a stack frame points at. The plugin's frames hold the file as the dev server addresses
|
|
7
11
|
* it; `Atom.withLabel`'s are the browser's, a URL with the dev server's origin and a query.
|
|
8
12
|
*/
|
|
9
|
-
export const parseFrame = (frame) => {
|
|
10
|
-
|
|
13
|
+
export const parseFrame = (frame, name) => {
|
|
14
|
+
// The plugin's own frame, `at ${name} (${place})`: its place is all inside the parentheses, which
|
|
15
|
+
// a SvelteKit route group, as in `/src/routes/(app)/+page.svelte`, has some of.
|
|
16
|
+
const prefix = name === undefined ? undefined : `at ${name} (`;
|
|
17
|
+
const own = prefix !== undefined && frame.startsWith(prefix) && frame.endsWith(")")
|
|
18
|
+
? ownPattern.exec(frame.slice(prefix.length, -1))?.groups
|
|
19
|
+
: undefined;
|
|
20
|
+
if (own?.file !== undefined) {
|
|
21
|
+
return {
|
|
22
|
+
column: Number(own.column),
|
|
23
|
+
file: own.file,
|
|
24
|
+
line: Number(own.line),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const groups = (urlPattern.exec(frame) ?? framePattern.exec(frame))?.groups;
|
|
11
28
|
if (groups?.file === undefined) {
|
|
12
29
|
return undefined;
|
|
13
30
|
}
|
|
@@ -28,7 +45,7 @@ export const identify = (atom) => {
|
|
|
28
45
|
return {
|
|
29
46
|
key,
|
|
30
47
|
name,
|
|
31
|
-
place: frame === undefined ? undefined : parseFrame(frame),
|
|
48
|
+
place: frame === undefined ? undefined : parseFrame(frame, name),
|
|
32
49
|
};
|
|
33
50
|
};
|
|
34
51
|
/** The file's name without its folders, for a short reference: `todos.ts:12`. */
|
|
@@ -38,6 +55,7 @@ export const shortPlace = (place) => `${place.file.split("/").at(-1) ?? place.fi
|
|
|
38
55
|
* relative to the project's root or a full one: `/src/a.ts` becomes `src/a.ts`, and
|
|
39
56
|
* `/@fs/home/me/a.ts` or `/@fs/C:/a.ts` the full path after `/@fs`.
|
|
40
57
|
*/
|
|
58
|
+
// oxlint-disable-next-line effecttsgo/async-function -- a click handler in the panel, outside any Effect program
|
|
41
59
|
export const openInEditor = async (place) => {
|
|
42
60
|
const full = place.file.startsWith("/@fs/")
|
|
43
61
|
? place.file.slice("/@fs".length)
|
|
@@ -46,8 +64,10 @@ export const openInEditor = async (place) => {
|
|
|
46
64
|
if (full !== undefined) {
|
|
47
65
|
file = /^\/[a-z]:\//iu.test(full) ? full.slice(1) : full;
|
|
48
66
|
}
|
|
67
|
+
const target = encodeURIComponent(`${file}:${place.line}:${place.column}`);
|
|
49
68
|
try {
|
|
50
|
-
|
|
69
|
+
// oxlint-disable-next-line effecttsgo/global-fetch -- one request to the Vite dev server, from the panel, outside any Effect program
|
|
70
|
+
await fetch(`/__open-in-editor?file=${target}`);
|
|
51
71
|
}
|
|
52
72
|
catch {
|
|
53
73
|
// Not a Vite dev server, or it isn't running: there is no editor to open.
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
-->
|
|
5
5
|
<script module lang="ts">
|
|
6
6
|
/** Where the launcher sits. */
|
|
7
|
-
export type Corner =
|
|
7
|
+
export type Corner =
|
|
8
|
+
| "bottom-right"
|
|
9
|
+
| "bottom-left"
|
|
10
|
+
| "top-right"
|
|
11
|
+
| "top-left";
|
|
8
12
|
</script>
|
|
9
13
|
|
|
10
14
|
<script lang="ts">
|
|
@@ -35,7 +39,9 @@
|
|
|
35
39
|
shortcut = $bindable(),
|
|
36
40
|
}: Props = $props();
|
|
37
41
|
|
|
38
|
-
const mac =
|
|
42
|
+
const mac =
|
|
43
|
+
typeof navigator !== "undefined" &&
|
|
44
|
+
/Mac|iPhone|iPad/u.test(navigator.platform);
|
|
39
45
|
const shown = $derived.by(() => {
|
|
40
46
|
const parsed = parseShortcut(shortcut);
|
|
41
47
|
return parsed === undefined ? "none" : formatShortcut(parsed, mac);
|
|
@@ -74,15 +80,29 @@
|
|
|
74
80
|
<div class="row">
|
|
75
81
|
<span class="key" id="devtools-shortcut">Shortcut</span>
|
|
76
82
|
<div class="value">
|
|
77
|
-
<kbd aria-labelledby="devtools-shortcut"
|
|
78
|
-
|
|
83
|
+
<kbd aria-labelledby="devtools-shortcut"
|
|
84
|
+
>{recording ? "Press a shortcut…" : shown}</kbd
|
|
85
|
+
>
|
|
86
|
+
<button
|
|
87
|
+
aria-pressed={recording}
|
|
88
|
+
class="tool"
|
|
89
|
+
onclick={() => (recording = !recording)}
|
|
90
|
+
type="button"
|
|
91
|
+
>
|
|
79
92
|
{recording ? "Cancel" : "Change"}
|
|
80
93
|
</button>
|
|
81
|
-
<button
|
|
94
|
+
<button
|
|
95
|
+
class="tool"
|
|
96
|
+
disabled={shortcut === defaultShortcut}
|
|
97
|
+
onclick={() => (shortcut = defaultShortcut)}
|
|
98
|
+
type="button"
|
|
99
|
+
>
|
|
82
100
|
Reset
|
|
83
101
|
</button>
|
|
84
102
|
<p class="note">
|
|
85
|
-
Opens and closes the panel anywhere on the page. It needs Ctrl, Alt or {mac
|
|
103
|
+
Opens and closes the panel anywhere on the page. It needs Ctrl, Alt or {mac
|
|
104
|
+
? "⌘"
|
|
105
|
+
: "Meta"} (or a function key), so it can't catch typing.
|
|
86
106
|
</p>
|
|
87
107
|
</div>
|
|
88
108
|
</div>
|
|
@@ -91,7 +111,12 @@
|
|
|
91
111
|
<div class="value">
|
|
92
112
|
<div aria-labelledby="devtools-corner" class="corners" role="group">
|
|
93
113
|
{#each corners as item (item.id)}
|
|
94
|
-
<button
|
|
114
|
+
<button
|
|
115
|
+
aria-pressed={corner === item.id}
|
|
116
|
+
class="tool"
|
|
117
|
+
onclick={() => (corner = item.id)}
|
|
118
|
+
type="button"
|
|
119
|
+
>
|
|
95
120
|
{item.label}
|
|
96
121
|
</button>
|
|
97
122
|
{/each}
|
|
@@ -104,7 +129,9 @@
|
|
|
104
129
|
<span class="value">
|
|
105
130
|
<input bind:value={opacity} max="1" min="0.2" step="0.05" type="range" />
|
|
106
131
|
<output>{Math.round(opacity * 100)}%</output>
|
|
107
|
-
<span class="note"
|
|
132
|
+
<span class="note"
|
|
133
|
+
>The button is opaque again while you point at it or focus it.</span
|
|
134
|
+
>
|
|
108
135
|
</span>
|
|
109
136
|
</label>
|
|
110
137
|
<label class="row">
|
|
@@ -26,17 +26,22 @@
|
|
|
26
26
|
model.atoms
|
|
27
27
|
.filter(
|
|
28
28
|
(view) =>
|
|
29
|
-
|
|
30
|
-
(showPlumbing || !view.plumbing
|
|
29
|
+
view.id === selected ||
|
|
30
|
+
(view.live && (showPlumbing || !view.plumbing))
|
|
31
31
|
)
|
|
32
32
|
.toSorted(
|
|
33
33
|
(a, b) =>
|
|
34
|
-
Number(a.plumbing) - Number(b.plumbing) ||
|
|
34
|
+
Number(a.plumbing) - Number(b.plumbing) ||
|
|
35
|
+
a.name.localeCompare(b.name)
|
|
35
36
|
)
|
|
36
37
|
);
|
|
37
|
-
const current = $derived(
|
|
38
|
+
const current = $derived(
|
|
39
|
+
selected === undefined ? undefined : byId.get(selected)
|
|
40
|
+
);
|
|
38
41
|
const number = $derived(
|
|
39
|
-
current === undefined
|
|
42
|
+
current === undefined
|
|
43
|
+
? 0
|
|
44
|
+
: sheets.findIndex((view) => view.id === current.id) + 1
|
|
40
45
|
);
|
|
41
46
|
const recent = $derived(
|
|
42
47
|
current === undefined
|
|
@@ -55,7 +60,9 @@
|
|
|
55
60
|
if (view.idleTTL === undefined || view.idleTTL === 0) {
|
|
56
61
|
return "none";
|
|
57
62
|
}
|
|
58
|
-
return view.idleTTL >= 1000
|
|
63
|
+
return view.idleTTL >= 1000
|
|
64
|
+
? `${view.idleTTL / 1000} s`
|
|
65
|
+
: `${view.idleTTL} ms`;
|
|
59
66
|
};
|
|
60
67
|
const time = (entry: TimelineEntry) => `${(entry.time / 1000).toFixed(3)} s`;
|
|
61
68
|
const verbs: Record<TimelineEntry["tag"], string> = {
|
|
@@ -68,24 +75,43 @@
|
|
|
68
75
|
Updated: "updated",
|
|
69
76
|
};
|
|
70
77
|
const states = $derived(
|
|
71
|
-
Object.entries(model.totals.states).toSorted(([a], [b]) =>
|
|
78
|
+
Object.entries(model.totals.states).toSorted(([a], [b]) =>
|
|
79
|
+
a.localeCompare(b)
|
|
80
|
+
)
|
|
72
81
|
);
|
|
73
82
|
</script>
|
|
74
83
|
|
|
75
84
|
{#snippet link(id: number)}
|
|
76
85
|
{@const view = byId.get(id)}
|
|
77
|
-
<button
|
|
86
|
+
<button
|
|
87
|
+
class="link"
|
|
88
|
+
class:plumbing={view?.plumbing}
|
|
89
|
+
onclick={() => onselect(id)}
|
|
90
|
+
type="button"
|
|
91
|
+
>
|
|
78
92
|
{view?.name ?? `atom #${id}`}
|
|
79
93
|
</button>
|
|
80
94
|
{/snippet}
|
|
81
95
|
|
|
82
96
|
<div class="set">
|
|
83
97
|
<nav aria-label="Sheets" class="index">
|
|
84
|
-
<button
|
|
98
|
+
<button
|
|
99
|
+
class="entry"
|
|
100
|
+
class:current={current === undefined}
|
|
101
|
+
onclick={() => onselect(undefined)}
|
|
102
|
+
type="button"
|
|
103
|
+
>
|
|
85
104
|
<span class="no">00</span> Cover sheet
|
|
86
105
|
</button>
|
|
87
106
|
{#each sheets as view, index (view.id)}
|
|
88
|
-
<button
|
|
107
|
+
<button
|
|
108
|
+
class="entry"
|
|
109
|
+
class:current={current?.id === view.id}
|
|
110
|
+
class:plumbing={view.plumbing}
|
|
111
|
+
class:gone={!view.live}
|
|
112
|
+
onclick={() => onselect(view.id)}
|
|
113
|
+
type="button"
|
|
114
|
+
>
|
|
89
115
|
<span class="no">{pad(index + 1)}</span>
|
|
90
116
|
{view.name}
|
|
91
117
|
</button>
|
|
@@ -99,40 +125,66 @@
|
|
|
99
125
|
<span>COVER · THE REGISTRY</span>
|
|
100
126
|
</header>
|
|
101
127
|
<div class="totals">
|
|
102
|
-
<div class="total"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
<div class="total"
|
|
106
|
-
|
|
107
|
-
|
|
128
|
+
<div class="total">
|
|
129
|
+
<b>{pad(model.totals.atoms)}</b><span>atoms</span>
|
|
130
|
+
</div>
|
|
131
|
+
<div class="total">
|
|
132
|
+
<b>{pad(model.totals.readers)}</b><span>readers</span>
|
|
133
|
+
</div>
|
|
134
|
+
<div class="total">
|
|
135
|
+
<b>{pad(model.totals.builds)}</b><span>computations</span>
|
|
136
|
+
</div>
|
|
137
|
+
<div class="total">
|
|
138
|
+
<b>{pad(model.totals.updates)}</b><span>updates</span>
|
|
139
|
+
</div>
|
|
140
|
+
<div class="total">
|
|
141
|
+
<b>{pad(model.totals.interruptions)}</b><span>interruptions</span>
|
|
142
|
+
</div>
|
|
143
|
+
<div class="total">
|
|
144
|
+
<b>{pad(model.totals.finalizers)}</b><span>finalizers run</span>
|
|
145
|
+
</div>
|
|
108
146
|
</div>
|
|
109
147
|
<section class="block">
|
|
110
148
|
<h3 class="key">VALUES</h3>
|
|
111
149
|
<p class="states">
|
|
112
150
|
{#each states as [state, count] (state)}
|
|
113
|
-
<span
|
|
151
|
+
<span
|
|
152
|
+
><b>{count}</b> {state === "Value" ? "plain values" : state}</span
|
|
153
|
+
>
|
|
114
154
|
{/each}
|
|
115
155
|
</p>
|
|
116
156
|
<p class="caption">
|
|
117
|
-
{model.totals.plumbing} of the {model.totals.atoms} atoms are plumbing:
|
|
118
|
-
mutation or a store rather than declared by the app.
|
|
119
|
-
|
|
120
|
-
|
|
157
|
+
{model.totals.plumbing} of the {model.totals.atoms} atoms are plumbing:
|
|
158
|
+
made by a runtime, a mutation or a store rather than declared by the app.
|
|
159
|
+
They have no label, and the sheets and graph {showPlumbing
|
|
160
|
+
? "show them, last"
|
|
161
|
+
: "leave them out"}. Counts of computations and updates start when
|
|
162
|
+
the panel does.
|
|
121
163
|
</p>
|
|
122
164
|
</section>
|
|
123
165
|
{:else}
|
|
124
166
|
<header class="strip">
|
|
125
167
|
<span><b>SHEET {pad(number)}</b> OF {pad(sheets.length)}</span>
|
|
126
|
-
<span
|
|
168
|
+
<span
|
|
169
|
+
>{current.live
|
|
170
|
+
? current.plumbing
|
|
171
|
+
? "PLUMBING"
|
|
172
|
+
: "ATOM"
|
|
173
|
+
: "REMOVED"}</span
|
|
174
|
+
>
|
|
127
175
|
</header>
|
|
128
176
|
|
|
129
|
-
<section class="block
|
|
177
|
+
<section class="value block">
|
|
130
178
|
<h3 class="key">
|
|
131
179
|
VALUE{#if current.state._tag !== "Value"}<span
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
180
|
+
class="badge"
|
|
181
|
+
class:failure={current.state._tag === "Failure" &&
|
|
182
|
+
!current.state.waiting}
|
|
183
|
+
class:success={current.state._tag === "Success" &&
|
|
184
|
+
!current.state.waiting}
|
|
185
|
+
class:waiting={current.state.waiting}
|
|
186
|
+
>{stateText(current.state)}</span
|
|
187
|
+
>{/if}
|
|
136
188
|
</h3>
|
|
137
189
|
{#if current.hasValue}
|
|
138
190
|
<pre>{detail(current.value)}</pre>
|
|
@@ -148,7 +200,9 @@
|
|
|
148
200
|
<p class="caption">Nothing: it is a source.</p>
|
|
149
201
|
{:else}
|
|
150
202
|
<ul>
|
|
151
|
-
{#each current.parents as id (id)}<li>
|
|
203
|
+
{#each current.parents as id (id)}<li>
|
|
204
|
+
{@render link(id)}
|
|
205
|
+
</li>{/each}
|
|
152
206
|
</ul>
|
|
153
207
|
{/if}
|
|
154
208
|
</section>
|
|
@@ -158,14 +212,19 @@
|
|
|
158
212
|
<p class="caption">No atom reads it.</p>
|
|
159
213
|
{:else}
|
|
160
214
|
<ul>
|
|
161
|
-
{#each current.children as id (id)}<li>
|
|
215
|
+
{#each current.children as id (id)}<li>
|
|
216
|
+
{@render link(id)}
|
|
217
|
+
</li>{/each}
|
|
162
218
|
</ul>
|
|
163
219
|
{/if}
|
|
164
220
|
</section>
|
|
165
221
|
</div>
|
|
166
222
|
|
|
167
223
|
<section class="block">
|
|
168
|
-
<h3 class="key">
|
|
224
|
+
<h3 class="key">
|
|
225
|
+
LATELY · {current.builds} COMPUTATIONS, {current.updates} UPDATES, {current.interruptions}
|
|
226
|
+
INTERRUPTIONS
|
|
227
|
+
</h3>
|
|
169
228
|
{#if recent.length === 0}
|
|
170
229
|
<p class="caption">Nothing since the panel started.</p>
|
|
171
230
|
{:else}
|
|
@@ -174,7 +233,10 @@
|
|
|
174
233
|
<li class:alert={entry.tag === "Interrupted"}>
|
|
175
234
|
<span class="when">{time(entry)}</span>
|
|
176
235
|
<span class="what">{verbs[entry.tag]}</span>
|
|
177
|
-
<span class="detail"
|
|
236
|
+
<span class="detail"
|
|
237
|
+
>{entry.detail}{#if entry.source}
|
|
238
|
+
({entry.source}){/if}</span
|
|
239
|
+
>
|
|
178
240
|
</li>
|
|
179
241
|
{/each}
|
|
180
242
|
</ol>
|
|
@@ -189,7 +251,12 @@
|
|
|
189
251
|
{@const place = current.identity.place}
|
|
190
252
|
<!-- Only the dev server can open a file in the editor. -->
|
|
191
253
|
{#if DEV}
|
|
192
|
-
<button
|
|
254
|
+
<button
|
|
255
|
+
class="link"
|
|
256
|
+
onclick={() => void openInEditor(place)}
|
|
257
|
+
title="Open {place.file}:{place.line} in the editor"
|
|
258
|
+
type="button">{shortPlace(place)}</button
|
|
259
|
+
>
|
|
193
260
|
{:else}
|
|
194
261
|
<span title="{place.file}:{place.line}">{shortPlace(place)}</span>
|
|
195
262
|
{/if}
|
|
@@ -197,11 +264,17 @@
|
|
|
197
264
|
—
|
|
198
265
|
{/if}
|
|
199
266
|
</div>
|
|
200
|
-
<div class="cell"
|
|
267
|
+
<div class="cell">
|
|
268
|
+
<span class="key">KEEP-ALIVE</span>{current.keepAlive ? "yes" : "no"}
|
|
269
|
+
</div>
|
|
201
270
|
<div class="cell"><span class="key">IDLE TTL</span>{ttl(current)}</div>
|
|
202
|
-
<div class="cell"
|
|
271
|
+
<div class="cell">
|
|
272
|
+
<span class="key">READERS</span>{current.readers}
|
|
273
|
+
</div>
|
|
203
274
|
{#if current.identity.key && current.identity.key !== current.name}
|
|
204
|
-
<div class="cell wide"
|
|
275
|
+
<div class="cell wide">
|
|
276
|
+
<span class="key">KEY</span>{current.identity.key}
|
|
277
|
+
</div>
|
|
205
278
|
{/if}
|
|
206
279
|
</footer>
|
|
207
280
|
{/if}
|
|
@@ -387,7 +460,10 @@
|
|
|
387
460
|
.title-block {
|
|
388
461
|
border-top: 1px solid var(--line);
|
|
389
462
|
display: grid;
|
|
390
|
-
grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.6fr) repeat(
|
|
463
|
+
grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.6fr) repeat(
|
|
464
|
+
3,
|
|
465
|
+
minmax(0, 1fr)
|
|
466
|
+
);
|
|
391
467
|
margin-top: auto;
|
|
392
468
|
}
|
|
393
469
|
.cell {
|
|
@@ -13,7 +13,10 @@ export declare const parseShortcut: (text: string) => Shortcut | undefined;
|
|
|
13
13
|
export declare const stringifyShortcut: (shortcut: Shortcut) => string;
|
|
14
14
|
/** For display: "Alt Shift A", or "⌘ ⇧ A" on a Mac. */
|
|
15
15
|
export declare const formatShortcut: (shortcut: Shortcut, mac: boolean) => string;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* Whether a key press is the shortcut, with exactly its modifiers. The code is compared without
|
|
18
|
+
* case: the settings save it in lower case, and a code such as `ArrowUp` doesn't read back as it was.
|
|
19
|
+
*/
|
|
17
20
|
export declare const matchesShortcut: (event: KeyboardEvent, shortcut: Shortcut) => boolean;
|
|
18
21
|
/**
|
|
19
22
|
* The shortcut a key press makes, when recording a new one: `undefined` for a modifier on its own,
|
|
@@ -12,6 +12,10 @@ const modifierCodes = new Set([
|
|
|
12
12
|
"ShiftLeft",
|
|
13
13
|
"ShiftRight",
|
|
14
14
|
]);
|
|
15
|
+
// The first words of codes with two words, so a code saved in lower case reads back as the key's
|
|
16
|
+
// code does: "arrowup" is `ArrowUp`, "pagedown" is `PageDown`, "bracketleft" is `BracketLeft`.
|
|
17
|
+
const twoWordCode = /^(?<first>arrow|bracket|caps|context|numpad|num|page|print|scroll)(?<second>[a-z]+)$/iu;
|
|
18
|
+
const capitalise = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
15
19
|
/** The code a key's name stands for: `a` is `KeyA`, `1` is `Digit1`, and anything else as it is. */
|
|
16
20
|
const codeOf = (key) => {
|
|
17
21
|
if (/^[a-z]$/iu.test(key)) {
|
|
@@ -20,7 +24,11 @@ const codeOf = (key) => {
|
|
|
20
24
|
if (/^\d$/u.test(key)) {
|
|
21
25
|
return `Digit${key}`;
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
const { first, second } = twoWordCode.exec(key)?.groups ?? {};
|
|
28
|
+
if (first !== undefined && second !== undefined) {
|
|
29
|
+
return capitalise(first.toLowerCase()) + capitalise(second.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
return key.length > 1 ? capitalise(key) : key;
|
|
24
32
|
};
|
|
25
33
|
/** Reads "alt+shift+a" (or "Ctrl+Shift+F2", "meta+k"); `undefined` when there is no key. */
|
|
26
34
|
export const parseShortcut = (text) => {
|
|
@@ -63,12 +71,16 @@ export const formatShortcut = (shortcut, mac) => [
|
|
|
63
71
|
]
|
|
64
72
|
.filter(Boolean)
|
|
65
73
|
.join(" ");
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
event.
|
|
74
|
+
/**
|
|
75
|
+
* Whether a key press is the shortcut, with exactly its modifiers. The code is compared without
|
|
76
|
+
* case: the settings save it in lower case, and a code such as `ArrowUp` doesn't read back as it was.
|
|
77
|
+
*/
|
|
78
|
+
export const matchesShortcut = (event, shortcut) => {
|
|
79
|
+
const pressed = [event.altKey, event.ctrlKey, event.metaKey, event.shiftKey];
|
|
80
|
+
const held = [shortcut.alt, shortcut.ctrl, shortcut.meta, shortcut.shift];
|
|
81
|
+
return (event.code.toLowerCase() === shortcut.code.toLowerCase() &&
|
|
82
|
+
pressed.every((down, index) => down === held[index]));
|
|
83
|
+
};
|
|
72
84
|
/**
|
|
73
85
|
* The shortcut a key press makes, when recording a new one: `undefined` for a modifier on its own,
|
|
74
86
|
* and for a key without Ctrl, Alt or Meta (other than a function key), which would catch typing.
|
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
|
|
14
14
|
const { model, showPlumbing, onselect }: Props = $props();
|
|
15
15
|
|
|
16
|
-
type Kind =
|
|
16
|
+
type Kind =
|
|
17
|
+
| "computed"
|
|
18
|
+
| "updated"
|
|
19
|
+
| "interrupted"
|
|
20
|
+
| "finalized"
|
|
21
|
+
| "readers"
|
|
22
|
+
| "added";
|
|
17
23
|
const kinds: Record<TimelineEntry["tag"], Kind> = {
|
|
18
24
|
Built: "computed",
|
|
19
25
|
Finalized: "finalized",
|
|
@@ -50,41 +56,63 @@
|
|
|
50
56
|
updated: true,
|
|
51
57
|
});
|
|
52
58
|
let search = $state("");
|
|
53
|
-
// An atom picked from the list: its rows only.
|
|
54
|
-
|
|
59
|
+
// An atom picked from the list: its rows only. Ids are the model's, so a pick lasts only as long
|
|
60
|
+
// as the model it was made in: another registry's model has its own.
|
|
61
|
+
let picked = $state.raw<{ readonly model: Model; readonly id: number }>();
|
|
62
|
+
const only = $derived(picked?.model === model ? picked.id : undefined);
|
|
63
|
+
const pick = (id: number | undefined) => {
|
|
64
|
+
picked = id === undefined ? undefined : { id, model };
|
|
65
|
+
};
|
|
55
66
|
|
|
56
67
|
const byId = $derived(new Map(model.atoms.map((view) => [view.id, view])));
|
|
57
68
|
const nameOf = (id: number) => byId.get(id)?.name ?? `atom #${id}`;
|
|
58
69
|
const shownRows = 400;
|
|
70
|
+
/** Whether the timeline lists the entry, given the kinds shown, the atom picked and the search. */
|
|
71
|
+
const shows = (entry: TimelineEntry, query: string) => {
|
|
72
|
+
if (!shownKinds[kinds[entry.tag]]) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
only !== undefined &&
|
|
77
|
+
entry.atom !== only &&
|
|
78
|
+
!entry.related.includes(only)
|
|
79
|
+
) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (!showPlumbing && byId.get(entry.atom)?.plumbing && only === undefined) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return query === "" || nameOf(entry.atom).toLowerCase().includes(query);
|
|
86
|
+
};
|
|
59
87
|
const rows = $derived.by(() => {
|
|
60
88
|
const query = search.trim().toLowerCase();
|
|
61
89
|
const matching: TimelineEntry[] = [];
|
|
62
|
-
for (
|
|
90
|
+
for (
|
|
91
|
+
let index = model.timeline.length - 1;
|
|
92
|
+
index >= 0 && matching.length < shownRows;
|
|
93
|
+
index -= 1
|
|
94
|
+
) {
|
|
63
95
|
const entry = model.timeline[index];
|
|
64
|
-
if (entry
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
if (only !== undefined && entry.atom !== only && !entry.related.includes(only)) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (!showPlumbing && byId.get(entry.atom)?.plumbing && only === undefined) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (query !== "" && !nameOf(entry.atom).toLowerCase().includes(query)) {
|
|
74
|
-
continue;
|
|
96
|
+
if (entry !== undefined && shows(entry, query)) {
|
|
97
|
+
matching.push(entry);
|
|
75
98
|
}
|
|
76
|
-
matching.push(entry);
|
|
77
99
|
}
|
|
78
100
|
return matching;
|
|
79
101
|
});
|
|
80
102
|
|
|
81
103
|
const start = $derived(model.timeline[0]?.time ?? 0);
|
|
82
|
-
const time = (entry: TimelineEntry) =>
|
|
104
|
+
const time = (entry: TimelineEntry) =>
|
|
105
|
+
`+${((entry.time - start) / 1000).toFixed(3)}`;
|
|
83
106
|
</script>
|
|
84
107
|
|
|
85
108
|
<div class="timeline">
|
|
86
109
|
<div class="toolbar">
|
|
87
|
-
<input
|
|
110
|
+
<input
|
|
111
|
+
aria-label="Filter by atom name"
|
|
112
|
+
bind:value={search}
|
|
113
|
+
placeholder="atom name"
|
|
114
|
+
type="search"
|
|
115
|
+
/>
|
|
88
116
|
{#each Object.keys(labels) as Kind[] as kind (kind)}
|
|
89
117
|
<label class="kind">
|
|
90
118
|
<input bind:checked={shownKinds[kind]} type="checkbox" />
|
|
@@ -93,35 +121,60 @@
|
|
|
93
121
|
{/each}
|
|
94
122
|
<span class="spacer"></span>
|
|
95
123
|
{#if only !== undefined}
|
|
96
|
-
<button class="tool" onclick={() => (
|
|
124
|
+
<button class="tool" onclick={() => pick(undefined)} type="button">
|
|
97
125
|
only {nameOf(only)} ✕
|
|
98
126
|
</button>
|
|
99
127
|
{/if}
|
|
100
|
-
<button
|
|
128
|
+
<button
|
|
129
|
+
class="tool"
|
|
130
|
+
aria-pressed={model.paused}
|
|
131
|
+
onclick={() => (model.paused = !model.paused)}
|
|
132
|
+
type="button"
|
|
133
|
+
>
|
|
101
134
|
{model.paused ? "resume" : "pause"}
|
|
102
135
|
</button>
|
|
103
|
-
<button class="tool" onclick={() => model.clearTimeline()} type="button"
|
|
136
|
+
<button class="tool" onclick={() => model.clearTimeline()} type="button"
|
|
137
|
+
>clear</button
|
|
138
|
+
>
|
|
104
139
|
</div>
|
|
105
140
|
|
|
106
141
|
{#if rows.length === 0}
|
|
107
|
-
<p class="empty">
|
|
142
|
+
<p class="empty">
|
|
143
|
+
Nothing yet. Use the page: every computation and update lands here.
|
|
144
|
+
</p>
|
|
108
145
|
{:else}
|
|
109
146
|
<ol class="rows">
|
|
110
147
|
{#each rows as entry (entry.seq)}
|
|
111
|
-
<li
|
|
148
|
+
<li
|
|
149
|
+
class="row {kinds[entry.tag]}"
|
|
150
|
+
class:alert={entry.tag === "Interrupted"}
|
|
151
|
+
>
|
|
112
152
|
<span class="when">{time(entry)}</span>
|
|
113
153
|
<span class="what">{verbs[entry.tag]}</span>
|
|
114
|
-
<button
|
|
154
|
+
<button
|
|
155
|
+
class="atom"
|
|
156
|
+
class:plumbing={byId.get(entry.atom)?.plumbing}
|
|
157
|
+
onclick={() => pick(entry.atom)}
|
|
158
|
+
ondblclick={() => onselect(entry.atom)}
|
|
159
|
+
title="Click: only this atom's rows. Double-click: its sheet."
|
|
160
|
+
type="button"
|
|
161
|
+
>
|
|
115
162
|
{nameOf(entry.atom)}
|
|
116
163
|
</button>
|
|
117
164
|
<span class="detail">
|
|
118
165
|
{#if entry.tag === "Built" && entry.related.length > 0}
|
|
119
166
|
because
|
|
120
167
|
{#each entry.related as id, index (id)}{#if index > 0},{/if}
|
|
121
|
-
<button
|
|
168
|
+
<button
|
|
169
|
+
class="atom inline"
|
|
170
|
+
onclick={() => pick(id)}
|
|
171
|
+
type="button">{nameOf(id)}</button
|
|
172
|
+
>{/each}
|
|
122
173
|
changed
|
|
123
174
|
{:else if entry.tag === "Built"}
|
|
124
|
-
{entry.detail === "first read"
|
|
175
|
+
{entry.detail === "first read"
|
|
176
|
+
? "first read"
|
|
177
|
+
: `because it was ${entry.detail}`}
|
|
125
178
|
{:else}
|
|
126
179
|
{entry.detail}
|
|
127
180
|
{/if}
|