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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +122 -2
  3. package/dist/atom-devtools.svelte +753 -0
  4. package/dist/atom-devtools.svelte.d.ts +39 -0
  5. package/dist/graph/atom-graph.svelte +244 -0
  6. package/dist/graph/atom-graph.svelte.d.ts +38 -0
  7. package/dist/graph/frame-graph.svelte +408 -0
  8. package/dist/graph/frame-graph.svelte.d.ts +52 -0
  9. package/dist/graph/index.d.ts +5 -0
  10. package/dist/graph/index.js +7 -0
  11. package/dist/graph/layout.d.ts +65 -0
  12. package/dist/graph/layout.js +531 -0
  13. package/dist/index.d.ts +14 -0
  14. package/dist/index.js +14 -0
  15. package/dist/internal/format.d.ts +27 -0
  16. package/dist/internal/format.js +183 -0
  17. package/dist/internal/graph-view.svelte +134 -0
  18. package/dist/internal/graph-view.svelte.d.ts +10 -0
  19. package/dist/internal/label.d.ts +35 -0
  20. package/dist/internal/label.js +139 -0
  21. package/dist/internal/model.svelte.d.ts +75 -0
  22. package/dist/internal/model.svelte.js +286 -0
  23. package/dist/internal/names.d.ts +29 -0
  24. package/dist/internal/names.js +55 -0
  25. package/dist/internal/settings-view.svelte +198 -0
  26. package/dist/internal/settings-view.svelte.d.ts +16 -0
  27. package/dist/internal/sheets-view.svelte +453 -0
  28. package/dist/internal/sheets-view.svelte.d.ts +11 -0
  29. package/dist/internal/shortcut.d.ts +22 -0
  30. package/dist/internal/shortcut.js +91 -0
  31. package/dist/internal/timeline-view.svelte +291 -0
  32. package/dist/internal/timeline-view.svelte.d.ts +9 -0
  33. package/dist/internal/transform.d.ts +17 -0
  34. package/dist/internal/transform.js +401 -0
  35. package/dist/vite.d.ts +52 -0
  36. package/dist/vite.js +97 -0
  37. package/package.json +78 -4
@@ -0,0 +1,453 @@
1
+ <!--
2
+ The drawing set: a cover sheet with the registry's totals and a list of sheets, then one sheet
3
+ per atom with its title block, its value, its readers, what it reads and what reads it, and what
4
+ happened to it lately.
5
+ -->
6
+ <script lang="ts">
7
+ import { DEV } from "esm-env";
8
+
9
+ import { detail, stateText } from "./format.js";
10
+ import type { AtomView, Model, TimelineEntry } from "./model.svelte.js";
11
+ import { openInEditor, shortPlace } from "./names.js";
12
+
13
+ interface Props {
14
+ readonly model: Model;
15
+ readonly showPlumbing: boolean;
16
+ /** The atom whose sheet is open, or `undefined` for the cover sheet. */
17
+ readonly selected: number | undefined;
18
+ readonly onselect: (id: number | undefined) => void;
19
+ }
20
+
21
+ const { model, showPlumbing, selected, onselect }: Props = $props();
22
+
23
+ const byId = $derived(new Map(model.atoms.map((view) => [view.id, view])));
24
+ // The set: live atoms by name, plumbing last. A removed atom keeps its sheet while it is open.
25
+ const sheets = $derived(
26
+ model.atoms
27
+ .filter(
28
+ (view) =>
29
+ (view.live || view.id === selected) &&
30
+ (showPlumbing || !view.plumbing || view.id === selected)
31
+ )
32
+ .toSorted(
33
+ (a, b) =>
34
+ Number(a.plumbing) - Number(b.plumbing) || a.name.localeCompare(b.name)
35
+ )
36
+ );
37
+ const current = $derived(selected === undefined ? undefined : byId.get(selected));
38
+ const number = $derived(
39
+ current === undefined ? 0 : sheets.findIndex((view) => view.id === current.id) + 1
40
+ );
41
+ const recent = $derived(
42
+ current === undefined
43
+ ? []
44
+ : model.timeline
45
+ .filter((entry) => entry.atom === current.id)
46
+ .slice(-12)
47
+ .toReversed()
48
+ );
49
+
50
+ const pad = (count: number) => String(count).padStart(2, "0");
51
+ const ttl = (view: AtomView) => {
52
+ if (view.keepAlive) {
53
+ return "—";
54
+ }
55
+ if (view.idleTTL === undefined || view.idleTTL === 0) {
56
+ return "none";
57
+ }
58
+ return view.idleTTL >= 1000 ? `${view.idleTTL / 1000} s` : `${view.idleTTL} ms`;
59
+ };
60
+ const time = (entry: TimelineEntry) => `${(entry.time / 1000).toFixed(3)} s`;
61
+ const verbs: Record<TimelineEntry["tag"], string> = {
62
+ Built: "computed",
63
+ Finalized: "finalized",
64
+ Interrupted: "interrupted",
65
+ NodeAdded: "added",
66
+ NodeRemoved: "removed",
67
+ ReadersChanged: "readers",
68
+ Updated: "updated",
69
+ };
70
+ const states = $derived(
71
+ Object.entries(model.totals.states).toSorted(([a], [b]) => a.localeCompare(b))
72
+ );
73
+ </script>
74
+
75
+ {#snippet link(id: number)}
76
+ {@const view = byId.get(id)}
77
+ <button class="link" class:plumbing={view?.plumbing} onclick={() => onselect(id)} type="button">
78
+ {view?.name ?? `atom #${id}`}
79
+ </button>
80
+ {/snippet}
81
+
82
+ <div class="set">
83
+ <nav aria-label="Sheets" class="index">
84
+ <button class="entry" class:current={current === undefined} onclick={() => onselect(undefined)} type="button">
85
+ <span class="no">00</span> Cover sheet
86
+ </button>
87
+ {#each sheets as view, index (view.id)}
88
+ <button class="entry" class:current={current?.id === view.id} class:plumbing={view.plumbing} class:gone={!view.live} onclick={() => onselect(view.id)} type="button">
89
+ <span class="no">{pad(index + 1)}</span>
90
+ {view.name}
91
+ </button>
92
+ {/each}
93
+ </nav>
94
+
95
+ <article class="sheet">
96
+ {#if current === undefined}
97
+ <header class="strip">
98
+ <span><b>SHEET 00</b> OF {pad(sheets.length)}</span>
99
+ <span>COVER · THE REGISTRY</span>
100
+ </header>
101
+ <div class="totals">
102
+ <div class="total"><b>{pad(model.totals.atoms)}</b><span>atoms</span></div>
103
+ <div class="total"><b>{pad(model.totals.readers)}</b><span>readers</span></div>
104
+ <div class="total"><b>{pad(model.totals.builds)}</b><span>computations</span></div>
105
+ <div class="total"><b>{pad(model.totals.updates)}</b><span>updates</span></div>
106
+ <div class="total"><b>{pad(model.totals.interruptions)}</b><span>interruptions</span></div>
107
+ <div class="total"><b>{pad(model.totals.finalizers)}</b><span>finalizers run</span></div>
108
+ </div>
109
+ <section class="block">
110
+ <h3 class="key">VALUES</h3>
111
+ <p class="states">
112
+ {#each states as [state, count] (state)}
113
+ <span><b>{count}</b> {state === "Value" ? "plain values" : state}</span>
114
+ {/each}
115
+ </p>
116
+ <p class="caption">
117
+ {model.totals.plumbing} of the {model.totals.atoms} atoms are plumbing: made by a runtime, a
118
+ mutation or a store rather than declared by the app. They have no label, and the sheets
119
+ and graph {showPlumbing ? "show them, last" : "leave them out"}.
120
+ Counts of computations and updates start when the panel does.
121
+ </p>
122
+ </section>
123
+ {:else}
124
+ <header class="strip">
125
+ <span><b>SHEET {pad(number)}</b> OF {pad(sheets.length)}</span>
126
+ <span>{current.live ? (current.plumbing ? "PLUMBING" : "ATOM") : "REMOVED"}</span>
127
+ </header>
128
+
129
+ <section class="block value">
130
+ <h3 class="key">
131
+ VALUE{#if current.state._tag !== "Value"}<span
132
+ class="badge"
133
+ class:failure={current.state._tag === "Failure" && !current.state.waiting}
134
+ class:success={current.state._tag === "Success" && !current.state.waiting}
135
+ class:waiting={current.state.waiting}>{stateText(current.state)}</span>{/if}
136
+ </h3>
137
+ {#if current.hasValue}
138
+ <pre>{detail(current.value)}</pre>
139
+ {:else}
140
+ <p class="caption">Not computed yet.</p>
141
+ {/if}
142
+ </section>
143
+
144
+ <div class="columns">
145
+ <section class="block">
146
+ <h3 class="key">UPSTREAM · WHAT IT READS</h3>
147
+ {#if current.parents.length === 0}
148
+ <p class="caption">Nothing: it is a source.</p>
149
+ {:else}
150
+ <ul>
151
+ {#each current.parents as id (id)}<li>{@render link(id)}</li>{/each}
152
+ </ul>
153
+ {/if}
154
+ </section>
155
+ <section class="block">
156
+ <h3 class="key">DOWNSTREAM · WHAT READS IT</h3>
157
+ {#if current.children.length === 0}
158
+ <p class="caption">No atom reads it.</p>
159
+ {:else}
160
+ <ul>
161
+ {#each current.children as id (id)}<li>{@render link(id)}</li>{/each}
162
+ </ul>
163
+ {/if}
164
+ </section>
165
+ </div>
166
+
167
+ <section class="block">
168
+ <h3 class="key">LATELY · {current.builds} COMPUTATIONS, {current.updates} UPDATES, {current.interruptions} INTERRUPTIONS</h3>
169
+ {#if recent.length === 0}
170
+ <p class="caption">Nothing since the panel started.</p>
171
+ {:else}
172
+ <ol class="recent">
173
+ {#each recent as entry (entry.seq)}
174
+ <li class:alert={entry.tag === "Interrupted"}>
175
+ <span class="when">{time(entry)}</span>
176
+ <span class="what">{verbs[entry.tag]}</span>
177
+ <span class="detail">{entry.detail}{#if entry.source} ({entry.source}){/if}</span>
178
+ </li>
179
+ {/each}
180
+ </ol>
181
+ {/if}
182
+ </section>
183
+
184
+ <footer class="title-block">
185
+ <div class="cell name"><span class="key">NAME</span>{current.name}</div>
186
+ <div class="cell">
187
+ <span class="key">DECLARED</span>
188
+ {#if current.identity.place}
189
+ {@const place = current.identity.place}
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}
196
+ {:else}
197
+ —
198
+ {/if}
199
+ </div>
200
+ <div class="cell"><span class="key">KEEP-ALIVE</span>{current.keepAlive ? "yes" : "no"}</div>
201
+ <div class="cell"><span class="key">IDLE TTL</span>{ttl(current)}</div>
202
+ <div class="cell"><span class="key">READERS</span>{current.readers}</div>
203
+ {#if current.identity.key && current.identity.key !== current.name}
204
+ <div class="cell wide"><span class="key">KEY</span>{current.identity.key}</div>
205
+ {/if}
206
+ </footer>
207
+ {/if}
208
+ </article>
209
+ </div>
210
+
211
+ <style>
212
+ .set {
213
+ display: grid;
214
+ grid-template-columns: minmax(10rem, 14rem) minmax(0, 1fr);
215
+ height: 100%;
216
+ min-height: 0;
217
+ }
218
+ .index {
219
+ border-right: 1px solid var(--line);
220
+ display: flex;
221
+ flex-direction: column;
222
+ min-height: 0;
223
+ overflow: auto;
224
+ padding: 0.75rem 0.75rem 0.75rem 1rem;
225
+ }
226
+ .entry {
227
+ background: none;
228
+ border: 0;
229
+ border-left: 1px solid var(--line);
230
+ color: var(--muted);
231
+ cursor: pointer;
232
+ font: inherit;
233
+ font-family: var(--mono);
234
+ font-size: 0.75rem;
235
+ overflow: hidden;
236
+ padding: 0.2rem 0.6rem;
237
+ position: relative;
238
+ text-align: left;
239
+ text-overflow: ellipsis;
240
+ white-space: nowrap;
241
+ }
242
+ .entry:hover {
243
+ color: var(--ink);
244
+ }
245
+ .entry.current {
246
+ border-left-color: var(--accent);
247
+ color: var(--ink);
248
+ }
249
+ .entry.plumbing,
250
+ .entry.gone {
251
+ color: var(--subtle);
252
+ }
253
+ .no {
254
+ color: var(--accent-text);
255
+ font-variant-numeric: tabular-nums;
256
+ margin-right: 0.5rem;
257
+ }
258
+ .sheet {
259
+ display: flex;
260
+ flex-direction: column;
261
+ min-height: 0;
262
+ overflow: auto;
263
+ }
264
+ .strip {
265
+ border-bottom: 1px solid var(--line);
266
+ color: var(--muted);
267
+ display: flex;
268
+ font-family: var(--mono);
269
+ font-size: 0.65rem;
270
+ justify-content: space-between;
271
+ letter-spacing: 0.1em;
272
+ padding: 0.55rem 1rem;
273
+ }
274
+ .strip b {
275
+ color: var(--accent-text);
276
+ font-weight: 400;
277
+ }
278
+ .block {
279
+ border-bottom: 1px solid var(--line);
280
+ padding: 0.75rem 1rem;
281
+ }
282
+ .key {
283
+ color: var(--muted);
284
+ font-family: var(--mono);
285
+ font-size: 0.62rem;
286
+ font-weight: normal;
287
+ letter-spacing: 0.1em;
288
+ margin: 0 0 0.4rem;
289
+ }
290
+ .badge {
291
+ border: 1px solid var(--line);
292
+ border-radius: 999px;
293
+ color: var(--ink);
294
+ margin-left: 0.6rem;
295
+ padding: 0 0.45rem;
296
+ }
297
+ .badge.success {
298
+ border-color: var(--success);
299
+ color: var(--success);
300
+ }
301
+ .badge.failure {
302
+ border-color: var(--alert);
303
+ color: var(--alert);
304
+ }
305
+ .badge.waiting {
306
+ border-color: var(--accent);
307
+ color: var(--accent-text);
308
+ }
309
+ pre {
310
+ background: color-mix(in oklab, var(--ink) 4%, transparent);
311
+ border: 1px solid var(--line);
312
+ border-radius: var(--radius);
313
+ padding: 0.5rem 0.65rem;
314
+ font-family: var(--mono);
315
+ font-size: 0.75rem;
316
+ margin: 0;
317
+ max-height: 14rem;
318
+ overflow: auto;
319
+ white-space: pre-wrap;
320
+ word-break: break-word;
321
+ }
322
+ .columns {
323
+ display: grid;
324
+ grid-template-columns: 1fr 1fr;
325
+ }
326
+ .columns .block:first-child {
327
+ border-right: 1px solid var(--line);
328
+ }
329
+ ul,
330
+ ol {
331
+ list-style: none;
332
+ margin: 0;
333
+ padding: 0;
334
+ }
335
+ .link {
336
+ background: none;
337
+ border: 0;
338
+ color: var(--ink);
339
+ cursor: pointer;
340
+ font: inherit;
341
+ font-family: var(--mono);
342
+ font-size: 0.75rem;
343
+ padding: 0;
344
+ text-decoration: underline dotted var(--muted);
345
+ text-underline-offset: 3px;
346
+ }
347
+ .link:hover {
348
+ color: var(--accent-text);
349
+ text-decoration-color: var(--accent);
350
+ }
351
+ .link.plumbing {
352
+ color: var(--muted);
353
+ }
354
+ .caption {
355
+ color: var(--muted);
356
+ font-family: var(--serif);
357
+ font-size: 0.8rem;
358
+ font-style: italic;
359
+ margin: 0;
360
+ }
361
+ .recent li {
362
+ display: grid;
363
+ font-size: 0.72rem;
364
+ gap: 0.75rem;
365
+ grid-template-columns: 5.5rem 6rem minmax(0, 1fr);
366
+ padding: 0.1rem 0;
367
+ }
368
+ .recent li.alert .what,
369
+ .recent li.alert .detail {
370
+ color: var(--alert);
371
+ }
372
+ .when {
373
+ color: var(--muted);
374
+ font-family: var(--mono);
375
+ font-variant-numeric: tabular-nums;
376
+ }
377
+ .what {
378
+ font-family: var(--mono);
379
+ }
380
+ .detail {
381
+ font-family: var(--serif);
382
+ font-style: italic;
383
+ overflow: hidden;
384
+ text-overflow: ellipsis;
385
+ white-space: nowrap;
386
+ }
387
+ .title-block {
388
+ border-top: 1px solid var(--line);
389
+ display: grid;
390
+ grid-template-columns: minmax(0, 1.6fr) minmax(0, 1.6fr) repeat(3, minmax(0, 1fr));
391
+ margin-top: auto;
392
+ }
393
+ .cell {
394
+ white-space: nowrap;
395
+ border-left: 1px solid var(--line);
396
+ display: flex;
397
+ flex-direction: column;
398
+ font-family: var(--mono);
399
+ font-size: 0.78rem;
400
+ gap: 0.15rem;
401
+ overflow: hidden;
402
+ padding: 0.45rem 0.75rem 0.55rem;
403
+ text-overflow: ellipsis;
404
+ }
405
+ .cell:first-child {
406
+ border-left: 0;
407
+ }
408
+ .cell .key {
409
+ margin: 0;
410
+ }
411
+ .cell.wide {
412
+ border-left: 0;
413
+ border-top: 1px solid var(--line);
414
+ grid-column: 1 / -1;
415
+ }
416
+ .totals {
417
+ border-bottom: 1px solid var(--line);
418
+ display: grid;
419
+ grid-template-columns: repeat(3, 1fr);
420
+ }
421
+ .total {
422
+ border-right: 1px solid var(--line);
423
+ border-top: 1px solid var(--line);
424
+ display: flex;
425
+ flex-direction: column;
426
+ padding: 0.75rem 1rem;
427
+ }
428
+ .total:nth-child(-n + 3) {
429
+ border-top: 0;
430
+ }
431
+ .total:nth-child(3n) {
432
+ border-right: 0;
433
+ }
434
+ .total b {
435
+ font-family: var(--mono);
436
+ font-size: 1.5rem;
437
+ font-variant-numeric: tabular-nums;
438
+ font-weight: 600;
439
+ }
440
+ .total span {
441
+ color: var(--muted);
442
+ font-family: var(--serif);
443
+ font-style: italic;
444
+ }
445
+ .states {
446
+ display: flex;
447
+ flex-wrap: wrap;
448
+ font-family: var(--mono);
449
+ font-size: 0.78rem;
450
+ gap: 1rem;
451
+ margin: 0 0 0.6rem;
452
+ }
453
+ </style>
@@ -0,0 +1,11 @@
1
+ import type { Model } from "./model.svelte.ts";
2
+ interface Props {
3
+ readonly model: Model;
4
+ readonly showPlumbing: boolean;
5
+ /** The atom whose sheet is open, or `undefined` for the cover sheet. */
6
+ readonly selected: number | undefined;
7
+ readonly onselect: (id: number | undefined) => void;
8
+ }
9
+ declare const SheetsView: import("svelte").Component<Props, {}, "">;
10
+ type SheetsView = ReturnType<typeof SheetsView>;
11
+ export default SheetsView;
@@ -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
+ };