effect-atom-svelte-devtools 0.2.0 → 0.2.2
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 +197 -19
- package/dist/atom-devtools.svelte.d.ts +14 -3
- package/dist/graph/atom-graph.svelte +3 -0
- package/dist/graph/frame-graph.svelte +1 -1
- package/dist/graph/layout.js +3 -0
- 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 +94 -20
- package/dist/internal/graph-view.svelte +10 -3
- package/dist/internal/model.svelte.js +2 -0
- package/dist/internal/names.d.ts +1 -1
- package/dist/internal/names.js +20 -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 +25 -0
- package/dist/internal/shortcut.js +102 -0
- package/dist/internal/timeline-view.svelte +10 -5
- package/dist/internal/transform.js +79 -4
- package/dist/vite.js +3 -1
- package/package.json +3 -3
package/dist/internal/format.js
CHANGED
|
@@ -15,6 +15,59 @@ const hasToJSON = (value) => typeof value.toJSON === "function";
|
|
|
15
15
|
// How much of a value is written out: deeper or longer parts are cut short.
|
|
16
16
|
const maxDepth = 5;
|
|
17
17
|
const maxItems = 50;
|
|
18
|
+
// Values JSON has no words for, written out bare: `NaN`, `Infinity`, `undefined`.
|
|
19
|
+
const bare = (text) => `\u0000${text}\u0000`;
|
|
20
|
+
const json = (data, indent) => (typeof data === "string"
|
|
21
|
+
? JSON.stringify(data)
|
|
22
|
+
: (JSON.stringify(data, undefined, indent) ?? String(data))).replaceAll(/"\\u0000(?<text>.*?)\\u0000"/gu, "$<text>");
|
|
23
|
+
/** An error's name: a tagged error's `_tag`, an `Error`'s `name`, or the value as a string. */
|
|
24
|
+
const errorName = (error) => {
|
|
25
|
+
if (typeof error === "object" && error !== null) {
|
|
26
|
+
if ("_tag" in error && typeof error._tag === "string") {
|
|
27
|
+
return error._tag;
|
|
28
|
+
}
|
|
29
|
+
if (error instanceof Error) {
|
|
30
|
+
return error.name;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return String(error);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* An error with its fields, each written by `write`, as `CityNotFound { city: "Atlantis" }`, or
|
|
37
|
+
* its message if it has one.
|
|
38
|
+
*/
|
|
39
|
+
const errorText = (error, write) => {
|
|
40
|
+
const name = errorName(error);
|
|
41
|
+
if (typeof error !== "object" || error === null) {
|
|
42
|
+
return name;
|
|
43
|
+
}
|
|
44
|
+
if ("message" in error &&
|
|
45
|
+
typeof error.message === "string" &&
|
|
46
|
+
error.message !== "") {
|
|
47
|
+
return `${name}: ${error.message}`;
|
|
48
|
+
}
|
|
49
|
+
const fields = Object.entries(error).filter(([key]) => key !== "_tag");
|
|
50
|
+
const body = fields.map(([key, field]) => `${key}: ${write(field)}`);
|
|
51
|
+
return body.length > 0 ? `${name} { ${body.join(", ")} }` : name;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* What a failure failed with, from its first reason: a typed error by its name (`CityNotFound`),
|
|
55
|
+
* or with its fields, each written by `write`, when given; a defect as `defect: TypeError`; an
|
|
56
|
+
* interruption as `interrupted`.
|
|
57
|
+
*/
|
|
58
|
+
export const failureText = (cause, write) => {
|
|
59
|
+
const [reason] = cause.reasons;
|
|
60
|
+
if (reason === undefined) {
|
|
61
|
+
return "empty cause";
|
|
62
|
+
}
|
|
63
|
+
if (Cause.isFailReason(reason)) {
|
|
64
|
+
return write ? errorText(reason.error, write) : errorName(reason.error);
|
|
65
|
+
}
|
|
66
|
+
if (Cause.isDieReason(reason)) {
|
|
67
|
+
return `defect: ${write ? errorText(reason.defect, write) : errorName(reason.defect)}`;
|
|
68
|
+
}
|
|
69
|
+
return "interrupted";
|
|
70
|
+
};
|
|
18
71
|
const plainResult = (result, inner) => {
|
|
19
72
|
switch (result._tag) {
|
|
20
73
|
case "Initial": {
|
|
@@ -28,14 +81,27 @@ const plainResult = (result, inner) => {
|
|
|
28
81
|
};
|
|
29
82
|
}
|
|
30
83
|
default: {
|
|
84
|
+
// What it failed with, fields and all, as the graph's note promises; then the whole cause.
|
|
85
|
+
// oxlint-disable-next-line eslint/sort-keys -- what it failed with reads before the whole cause
|
|
31
86
|
return {
|
|
32
87
|
_tag: "Failure",
|
|
88
|
+
error: failureText(result.cause, (field) => json(inner(field))),
|
|
33
89
|
cause: Cause.pretty(result.cause),
|
|
34
90
|
waiting: result.waiting,
|
|
35
91
|
};
|
|
36
92
|
}
|
|
37
93
|
}
|
|
38
94
|
};
|
|
95
|
+
/** The first `maxItems` items, and how many more there are. */
|
|
96
|
+
const listed = (items, inner) => {
|
|
97
|
+
const shown = items.slice(0, maxItems).map(inner);
|
|
98
|
+
return items.length > maxItems
|
|
99
|
+
? [...shown, `… ${items.length - maxItems} more`]
|
|
100
|
+
: shown;
|
|
101
|
+
};
|
|
102
|
+
/** An object cut to `maxItems` entries, saying how many more there are. */
|
|
103
|
+
const withMore = (object, count) => count > maxItems ? { ...object, "…": `${count - maxItems} more` } : object;
|
|
104
|
+
const isPrimitive = (value) => value === null || (typeof value !== "object" && typeof value !== "function");
|
|
39
105
|
const plainObject = (value, inner) => {
|
|
40
106
|
if (AsyncResult.isAsyncResult(value)) {
|
|
41
107
|
return plainResult(value, inner);
|
|
@@ -44,31 +110,36 @@ const plainObject = (value, inner) => {
|
|
|
44
110
|
return value.toISOString();
|
|
45
111
|
}
|
|
46
112
|
if (value instanceof Error) {
|
|
47
|
-
|
|
113
|
+
// A tagged error's fields, as `CityNotFound { city: "Atlantis" }`.
|
|
114
|
+
return errorText(value, (field) => json(inner(field)));
|
|
48
115
|
}
|
|
49
116
|
if (value instanceof Map) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
117
|
+
const entries = [...value];
|
|
118
|
+
// Primitive keys that stay distinct as strings make an object; any other keys would collide
|
|
119
|
+
// or lose themselves as strings, so those maps are written as `[key, value]` pairs.
|
|
120
|
+
const keys = entries.map(([key]) => key);
|
|
121
|
+
if (keys.every((key) => isPrimitive(key)) &&
|
|
122
|
+
new Set(keys.map(String)).size === keys.length) {
|
|
123
|
+
return withMore(Object.fromEntries(entries
|
|
124
|
+
.slice(0, maxItems)
|
|
125
|
+
.map(([key, entry]) => [String(key), inner(entry)])), entries.length);
|
|
126
|
+
}
|
|
127
|
+
return listed(entries, ([key, entry]) => [inner(key), inner(entry)]);
|
|
53
128
|
}
|
|
54
129
|
if (value instanceof Set) {
|
|
55
|
-
return [...value]
|
|
130
|
+
return listed([...value], inner);
|
|
56
131
|
}
|
|
57
132
|
if (Array.isArray(value)) {
|
|
58
|
-
|
|
59
|
-
return value.length > maxItems
|
|
60
|
-
? [...items, `… ${value.length - maxItems} more`]
|
|
61
|
-
: items;
|
|
133
|
+
return listed(value, inner);
|
|
62
134
|
}
|
|
63
135
|
if (hasToJSON(value)) {
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
return inner(
|
|
136
|
+
const data = value.toJSON();
|
|
137
|
+
if (data !== value) {
|
|
138
|
+
return inner(data);
|
|
67
139
|
}
|
|
68
140
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.map(([key, entry]) => [key, inner(entry)]));
|
|
141
|
+
const entries = Object.entries(value);
|
|
142
|
+
return withMore(Object.fromEntries(entries.slice(0, maxItems).map(([key, entry]) => [key, inner(entry)])), entries.length);
|
|
72
143
|
};
|
|
73
144
|
/**
|
|
74
145
|
* Turns a value into plain data to print: an `AsyncResult` as its tag and contents, a failure's
|
|
@@ -86,6 +157,12 @@ export const plain = (value, depth = 0, seen = new Set()) => {
|
|
|
86
157
|
case "symbol": {
|
|
87
158
|
return value.toString();
|
|
88
159
|
}
|
|
160
|
+
case "number": {
|
|
161
|
+
return Number.isFinite(value) ? value : bare(String(value));
|
|
162
|
+
}
|
|
163
|
+
case "undefined": {
|
|
164
|
+
return depth === 0 ? value : bare("undefined");
|
|
165
|
+
}
|
|
89
166
|
case "object": {
|
|
90
167
|
break;
|
|
91
168
|
}
|
|
@@ -113,19 +190,16 @@ export const plain = (value, depth = 0, seen = new Set()) => {
|
|
|
113
190
|
seen.delete(value);
|
|
114
191
|
}
|
|
115
192
|
};
|
|
116
|
-
const json = (data, indent) => typeof data === "string"
|
|
117
|
-
? JSON.stringify(data)
|
|
118
|
-
: (JSON.stringify(data, undefined, indent) ?? String(data));
|
|
119
193
|
/** The value written out in full, for its sheet. */
|
|
120
194
|
export const detail = (value) => json(plain(value), 2);
|
|
121
|
-
/** An `AsyncResult` on one line: its value, through `inner`, or
|
|
195
|
+
/** An `AsyncResult` on one line: its value, through `inner`, or what it failed with. */
|
|
122
196
|
const resultText = (result, inner) => {
|
|
123
197
|
let text = "Initial";
|
|
124
198
|
if (result._tag === "Success") {
|
|
125
199
|
text = inner(result.value);
|
|
126
200
|
}
|
|
127
201
|
else if (result._tag === "Failure") {
|
|
128
|
-
text =
|
|
202
|
+
text = failureText(result.cause, (field) => json(plain(field)));
|
|
129
203
|
}
|
|
130
204
|
return result.waiting ? `${text}, waiting` : text;
|
|
131
205
|
};
|
|
@@ -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
|
}
|
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`. */
|
|
@@ -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,25 @@
|
|
|
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
|
+
/**
|
|
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
|
+
*/
|
|
20
|
+
export declare const matchesShortcut: (event: KeyboardEvent, shortcut: Shortcut) => boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The shortcut a key press makes, when recording a new one: `undefined` for a modifier on its own,
|
|
23
|
+
* and for a key without Ctrl, Alt or Meta (other than a function key), which would catch typing.
|
|
24
|
+
*/
|
|
25
|
+
export declare const shortcutFromEvent: (event: KeyboardEvent) => Shortcut | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
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 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);
|
|
19
|
+
/** The code a key's name stands for: `a` is `KeyA`, `1` is `Digit1`, and anything else as it is. */
|
|
20
|
+
const codeOf = (key) => {
|
|
21
|
+
if (/^[a-z]$/iu.test(key)) {
|
|
22
|
+
return `Key${key.toUpperCase()}`;
|
|
23
|
+
}
|
|
24
|
+
if (/^\d$/u.test(key)) {
|
|
25
|
+
return `Digit${key}`;
|
|
26
|
+
}
|
|
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;
|
|
32
|
+
};
|
|
33
|
+
/** Reads "alt+shift+a" (or "Ctrl+Shift+F2", "meta+k"); `undefined` when there is no key. */
|
|
34
|
+
export const parseShortcut = (text) => {
|
|
35
|
+
const parts = text
|
|
36
|
+
.split("+")
|
|
37
|
+
.map((part) => part.trim())
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
const key = parts.pop();
|
|
40
|
+
if (key === undefined) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const mods = new Set(parts.map((part) => part.toLowerCase()));
|
|
44
|
+
return {
|
|
45
|
+
alt: mods.has("alt") || mods.has("option"),
|
|
46
|
+
code: codeOf(key),
|
|
47
|
+
ctrl: mods.has("ctrl") || mods.has("control"),
|
|
48
|
+
meta: mods.has("meta") || mods.has("cmd") || mods.has("command"),
|
|
49
|
+
shift: mods.has("shift"),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/** The key's own name, as a person reads it: `KeyA` is `A`, `Digit1` is `1`. */
|
|
53
|
+
const keyName = (code) => code.replace(/^Key(?=[A-Z]$)/u, "").replace(/^Digit(?=\d$)/u, "");
|
|
54
|
+
/** The string form, as `parseShortcut` reads it and the settings save it: "alt+shift+a". */
|
|
55
|
+
export const stringifyShortcut = (shortcut) => [
|
|
56
|
+
shortcut.ctrl && "ctrl",
|
|
57
|
+
shortcut.meta && "meta",
|
|
58
|
+
shortcut.alt && "alt",
|
|
59
|
+
shortcut.shift && "shift",
|
|
60
|
+
keyName(shortcut.code).toLowerCase(),
|
|
61
|
+
]
|
|
62
|
+
.filter(Boolean)
|
|
63
|
+
.join("+");
|
|
64
|
+
/** For display: "Alt Shift A", or "⌘ ⇧ A" on a Mac. */
|
|
65
|
+
export const formatShortcut = (shortcut, mac) => [
|
|
66
|
+
shortcut.ctrl && (mac ? "⌃" : "Ctrl"),
|
|
67
|
+
shortcut.meta && (mac ? "⌘" : "Meta"),
|
|
68
|
+
shortcut.alt && (mac ? "⌥" : "Alt"),
|
|
69
|
+
shortcut.shift && (mac ? "⇧" : "Shift"),
|
|
70
|
+
keyName(shortcut.code),
|
|
71
|
+
]
|
|
72
|
+
.filter(Boolean)
|
|
73
|
+
.join(" ");
|
|
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) => event.code.toLowerCase() === shortcut.code.toLowerCase() &&
|
|
79
|
+
event.altKey === shortcut.alt &&
|
|
80
|
+
event.ctrlKey === shortcut.ctrl &&
|
|
81
|
+
event.metaKey === shortcut.meta &&
|
|
82
|
+
event.shiftKey === shortcut.shift;
|
|
83
|
+
/**
|
|
84
|
+
* The shortcut a key press makes, when recording a new one: `undefined` for a modifier on its own,
|
|
85
|
+
* and for a key without Ctrl, Alt or Meta (other than a function key), which would catch typing.
|
|
86
|
+
*/
|
|
87
|
+
export const shortcutFromEvent = (event) => {
|
|
88
|
+
if (modifierCodes.has(event.code)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const functionKey = /^F\d{1,2}$/u.test(event.code);
|
|
92
|
+
if (!(event.altKey || event.ctrlKey || event.metaKey || functionKey)) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
alt: event.altKey,
|
|
97
|
+
code: event.code,
|
|
98
|
+
ctrl: event.ctrlKey,
|
|
99
|
+
meta: event.metaKey,
|
|
100
|
+
shift: event.shiftKey,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
@@ -50,8 +50,13 @@
|
|
|
50
50
|
updated: true,
|
|
51
51
|
});
|
|
52
52
|
let search = $state("");
|
|
53
|
-
// An atom picked from the list: its rows only.
|
|
54
|
-
|
|
53
|
+
// An atom picked from the list: its rows only. Ids are the model's, so a pick lasts only as long
|
|
54
|
+
// as the model it was made in: another registry's model has its own.
|
|
55
|
+
let picked = $state.raw<{ readonly model: Model; readonly id: number }>();
|
|
56
|
+
const only = $derived(picked?.model === model ? picked.id : undefined);
|
|
57
|
+
const pick = (id: number | undefined) => {
|
|
58
|
+
picked = id === undefined ? undefined : { id, model };
|
|
59
|
+
};
|
|
55
60
|
|
|
56
61
|
const byId = $derived(new Map(model.atoms.map((view) => [view.id, view])));
|
|
57
62
|
const nameOf = (id: number) => byId.get(id)?.name ?? `atom #${id}`;
|
|
@@ -93,7 +98,7 @@
|
|
|
93
98
|
{/each}
|
|
94
99
|
<span class="spacer"></span>
|
|
95
100
|
{#if only !== undefined}
|
|
96
|
-
<button class="tool" onclick={() => (
|
|
101
|
+
<button class="tool" onclick={() => pick(undefined)} type="button">
|
|
97
102
|
only {nameOf(only)} ✕
|
|
98
103
|
</button>
|
|
99
104
|
{/if}
|
|
@@ -111,14 +116,14 @@
|
|
|
111
116
|
<li class="row {kinds[entry.tag]}" class:alert={entry.tag === "Interrupted"}>
|
|
112
117
|
<span class="when">{time(entry)}</span>
|
|
113
118
|
<span class="what">{verbs[entry.tag]}</span>
|
|
114
|
-
<button class="atom" class:plumbing={byId.get(entry.atom)?.plumbing} onclick={() => (
|
|
119
|
+
<button class="atom" class:plumbing={byId.get(entry.atom)?.plumbing} onclick={() => pick(entry.atom)} ondblclick={() => onselect(entry.atom)} title="Click: only this atom's rows. Double-click: its sheet." type="button">
|
|
115
120
|
{nameOf(entry.atom)}
|
|
116
121
|
</button>
|
|
117
122
|
<span class="detail">
|
|
118
123
|
{#if entry.tag === "Built" && entry.related.length > 0}
|
|
119
124
|
because
|
|
120
125
|
{#each entry.related as id, index (id)}{#if index > 0},{/if}
|
|
121
|
-
<button class="atom inline" onclick={() => (
|
|
126
|
+
<button class="atom inline" onclick={() => pick(id)} type="button">{nameOf(id)}</button>{/each}
|
|
122
127
|
changed
|
|
123
128
|
{:else if entry.tag === "Built"}
|
|
124
129
|
{entry.detail === "first read" ? "first read" : `because it was ${entry.detail}`}
|