@lapis-notes/ui 0.2.5 → 0.2.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @lapis-notes/ui
2
2
 
3
+ ## 0.2.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#186](https://github.com/lapismd/lapis-notes/pull/186)
8
+ [`46e024b`](https://github.com/lapismd/lapis-notes/commit/46e024b7aa84aa507930f35e463aaf960257553e)
9
+ Thanks [@stevejuma](https://github.com/stevejuma)! - Align CLI settings with
10
+ the declarative app settings surface, including platform-aware downloads,
11
+ semantic status and actions, and full-width failure alerts.
12
+
13
+ ## 0.2.6
14
+
15
+ ### Patch Changes
16
+
17
+ - [#184](https://github.com/lapismd/lapis-notes/pull/184)
18
+ [`daef091`](https://github.com/lapismd/lapis-notes/commit/daef0915b7c5c88da7b8997097a5dee896f72bdf)
19
+ Thanks
20
+ [@lapismd-dependency-bot](https://github.com/apps/lapismd-dependency-bot)! -
21
+ Refresh first-party Lapis dependencies to the published versions recorded in
22
+ this pull request.
23
+
3
24
  ## 0.2.5
4
25
 
5
26
  ### Patch Changes
@@ -2,7 +2,10 @@
2
2
  import { onMount } from "svelte";
3
3
  import * as Button from "@lapismd/design-core/shadcn/button";
4
4
  import type { CliAccessHost, CliAccessStatus } from "./cli-settings";
5
- let { host }: { host: CliAccessHost } = $props();
5
+ let {
6
+ host,
7
+ embedded = false,
8
+ }: { host: CliAccessHost; embedded?: boolean } = $props();
6
9
  let status = $state<CliAccessStatus>();
7
10
  let busy = $state(false);
8
11
  let error = $state("");
@@ -41,11 +44,13 @@
41
44
  </script>
42
45
 
43
46
  <section aria-label="Desktop CLI access">
44
- <h3>Connect to desktop vaults</h3>
45
- <p>
46
- Allow explicitly scoped commands while this desktop app is running.
47
- Installing the command does not enable access.
48
- </p>
47
+ {#if !embedded}
48
+ <h3>Connect to desktop vaults</h3>
49
+ <p>
50
+ Allow explicitly scoped commands while this desktop app is running.
51
+ Installing the command does not enable access.
52
+ </p>
53
+ {/if}
49
54
  {#if status}
50
55
  <Button.Root
51
56
  disabled={busy}
@@ -134,8 +139,6 @@
134
139
  section {
135
140
  display: grid;
136
141
  gap: 0.75rem;
137
- border-top: 1px solid var(--border);
138
- padding-top: 1rem;
139
142
  }
140
143
  h3,
141
144
  p {
@@ -1,6 +1,7 @@
1
1
  import type { CliAccessHost } from "./cli-settings";
2
2
  type $$ComponentProps = {
3
3
  host: CliAccessHost;
4
+ embedded?: boolean;
4
5
  };
5
6
  declare const CliAccessSettings: import("svelte").Component<$$ComponentProps, {}, "">;
6
7
  type CliAccessSettings = ReturnType<typeof CliAccessSettings>;
@@ -1,251 +1,20 @@
1
1
  <script lang="ts">
2
- import { onMount } from "svelte";
3
- import * as Button from "@lapismd/design-core/shadcn/button";
4
- import * as Dialog from "@lapismd/design-core/shadcn/dialog";
5
- import type {
6
- CliSettingsHost,
7
- CliDownload,
8
- CliInstallationStatus,
9
- } from "./cli-settings";
10
- import CliAccessSettings from "./CliAccessSettings.svelte";
11
- let { host, embedded = false }: { host: CliSettingsHost; embedded?: boolean } = $props();
12
- let status = $state<CliInstallationStatus>();
13
- let downloads = $state<CliDownload[]>([]);
14
- let selectedDownload = $state("");
15
- const download = $derived(downloads.find(file => file.url === selectedDownload));
16
- let busy = $state(false);
17
- let error = $state("");
18
- let setup = $state(false);
19
- let remove = $state(false);
20
- let shell = $state("none");
21
- let removePath = $state(false);
22
- let alive = true;
23
- async function refresh() {
24
- const [next, files] = await Promise.all([
25
- host.installation?.status(),
26
- host.downloads?.(),
27
- ]);
28
- if (alive) {
29
- status = next;
30
- downloads = files ?? [];
31
- }
32
- }
33
- async function run(action: () => Promise<void>, refreshAfter = true) {
34
- if (busy) return;
35
- busy = true;
36
- error = "";
37
- try {
38
- await action();
39
- if (refreshAfter) await refresh();
40
- setup = false;
41
- remove = false;
42
- } catch (failure) {
43
- if (alive) {
44
- error = failure instanceof Error ? failure.message : String(failure);
45
- if (refreshAfter) await refresh().catch(() => {});
46
- }
47
- } finally {
48
- if (alive) busy = false;
49
- }
50
- }
51
- onMount(() => {
52
- void run(refresh, false);
53
- return () => {
54
- alive = false;
55
- };
2
+ import { onDestroy, untrack } from "svelte";
3
+ import {
4
+ DeclarativeSettingsSection,
5
+ WorkspaceSettingsController,
6
+ } from "@lapismd/design-core/workspace/settings";
7
+ import { registerCliSettings, type CliSettingsHost } from "./cli-settings";
8
+
9
+ let { host }: { host: CliSettingsHost; embedded?: boolean } = $props();
10
+ const controller = new WorkspaceSettingsController();
11
+ const dispose = registerCliSettings(controller, untrack(() => host));
12
+ const section = controller.sections.find((candidate) => candidate.id === "general");
13
+ if (!section) throw new Error("CLI General settings were not registered");
14
+ onDestroy(() => {
15
+ dispose();
16
+ controller.destroy();
56
17
  });
57
18
  </script>
58
19
 
59
- <section
60
- data-ui-component="lapis-cli-settings"
61
- aria-label="Command line interface"
62
- >
63
- <div class="row">
64
- <div>
65
- {#if !embedded}
66
- <h3>Command line interface</h3>
67
- <p>Use the <code>lapis</code> command from your terminal.</p>
68
- {/if}
69
- {#if status}
70
- <p>
71
- {status.state === "installed"
72
- ? "Installed"
73
- : status.state === "broken"
74
- ? "Needs repair"
75
- : status.state === "conflict"
76
- ? "Another command occupies this path"
77
- : "Not installed"} · bundled CLI {status.version}
78
- </p>
79
- <code>{status.destination}</code>
80
- {/if}
81
- </div>
82
- {#if host.installation}
83
- {#if status?.state === "installed"}
84
- <Button.Root
85
- variant="outline"
86
- disabled={busy}
87
- onclick={() => (remove = true)}>Uninstall CLI</Button.Root
88
- >
89
- {:else}
90
- <Button.Root
91
- disabled={busy || !status || status.state === "conflict"}
92
- onclick={() => (setup = true)}
93
- >{status?.state === "broken"
94
- ? "Repair CLI"
95
- : "Install CLI"}</Button.Root
96
- >
97
- {/if}
98
- {/if}
99
- </div>
100
- {#if status?.state === "installed"}
101
- <p>
102
- Open a new terminal and run <code>command -v lapis</code> and
103
- <code>lapis --version</code>.
104
- </p>
105
- {/if}
106
- {#if host.downloads}
107
- <p>
108
- Install on this computer. Your browser cannot inspect or change your local
109
- PATH.
110
- </p>
111
- {#if downloads.length}
112
- <label>Platform
113
- <select bind:value={selectedDownload}>
114
- <option value="">Choose your operating system and architecture</option>
115
- {#each downloads as file (file.url)}<option value={file.url}>{file.label}</option>{/each}
116
- </select>
117
- </label>
118
- {/if}
119
- {#if download}
120
- <div class="download">
121
- <a href={download.url} download>Download {download.label}</a>
122
- <p>SHA-256: <code>{download.sha256}</code></p>
123
- </div>
124
- {/if}
125
- {#if downloads.length}
126
- <p>Choose the matching archive, verify its checksum, and extract it. To connect, enable Content API and MCP under Core plugins and create a scoped credential.</p>
127
- <p>Install or remove the command on this computer:</p>
128
- <pre>./lapis cli install
129
- # Optional PATH setup (choose your shell):
130
- ./lapis cli install --setup-path zsh
131
- # Remove the command later:
132
- lapis cli uninstall --remove-path</pre>
133
- <p>
134
- Use <code>--setup-path bash</code> for Bash. For another shell, add
135
- <code>~/.local/bin</code> to PATH manually.
136
- </p>
137
- {/if}
138
- {/if}
139
- {#if error && !setup && !remove}<p role="alert">{error}</p>{/if}
140
- <Button.Root variant="ghost" disabled={busy} onclick={() => run(refresh, false)}
141
- >Refresh status</Button.Root
142
- >
143
- {#if host.access}<CliAccessSettings host={host.access} />{/if}
144
- </section>
145
-
146
- <Dialog.Root bind:open={setup}>
147
- <Dialog.Content>
148
- <Dialog.Header>
149
- <Dialog.Title>Set up CLI to work in the terminal</Dialog.Title>
150
- <Dialog.Description
151
- >Register “lapis” at ~/.local/bin/lapis for your user. Administrator
152
- access is not required. An existing Lapis-owned CLI copy will be
153
- replaced.</Dialog.Description
154
- >
155
- </Dialog.Header>
156
- <label
157
- >Shell PATH setup
158
- <select bind:value={shell} disabled={busy}>
159
- <option value="none">Leave shell configuration unchanged</option>
160
- <option value="zsh">Add ~/.local/bin to Zsh PATH</option>
161
- <option value="bash">Add ~/.local/bin to Bash PATH</option>
162
- </select>
163
- </label>
164
- <p>
165
- PATH setup adds a marked entry to your shell configuration. Other shells
166
- require manual setup.
167
- </p>
168
- {#if error}<p role="alert">{error}</p>{/if}
169
- <Dialog.Footer>
170
- <Button.Root
171
- variant="outline"
172
- disabled={busy}
173
- onclick={() => (setup = false)}>Cancel</Button.Root
174
- >
175
- <Button.Root
176
- disabled={busy}
177
- onclick={() =>
178
- run(() =>
179
- host.installation!.install(
180
- shell === "bash" || shell === "zsh" ? shell : undefined,
181
- ),
182
- )}>Register</Button.Root
183
- >
184
- </Dialog.Footer>
185
- </Dialog.Content>
186
- </Dialog.Root>
187
- <Dialog.Root bind:open={remove}>
188
- <Dialog.Content>
189
- <Dialog.Header>
190
- <Dialog.Title>Uninstall the CLI command?</Dialog.Title>
191
- <Dialog.Description
192
- >Your vaults, credentials and application data will be retained.</Dialog.Description
193
- >
194
- </Dialog.Header>
195
- <label
196
- ><input type="checkbox" bind:checked={removePath} disabled={busy} /> Remove
197
- unchanged Lapis PATH entries</label
198
- >
199
- {#if error}<p role="alert">{error}</p>{/if}
200
- <Dialog.Footer>
201
- <Button.Root
202
- variant="outline"
203
- disabled={busy}
204
- onclick={() => (remove = false)}>Cancel</Button.Root
205
- >
206
- <Button.Root
207
- disabled={busy}
208
- onclick={() => run(() => host.installation!.uninstall(removePath))}
209
- >Uninstall</Button.Root
210
- >
211
- </Dialog.Footer>
212
- </Dialog.Content>
213
- </Dialog.Root>
214
-
215
- <style>
216
- section {
217
- display: grid;
218
- gap: 1rem;
219
- color: var(--ui-workspace-view-foreground, inherit);
220
- }
221
- .row {
222
- display: flex;
223
- align-items: center;
224
- justify-content: space-between;
225
- gap: 1rem;
226
- flex-wrap: wrap;
227
- }
228
- h3,
229
- p {
230
- margin: 0.3rem 0;
231
- }
232
- code,
233
- pre {
234
- overflow-wrap: anywhere;
235
- white-space: pre-wrap;
236
- }
237
- .download {
238
- padding-block: 0.5rem;
239
- }
240
- label {
241
- display: grid;
242
- gap: 0.5rem;
243
- }
244
- select {
245
- color: inherit;
246
- background: transparent;
247
- padding: 0.5rem;
248
- border: 1px solid var(--border);
249
- border-radius: var(--radius);
250
- }
251
- </style>
20
+ <DeclarativeSettingsSection {controller} {section} />
@@ -1,4 +1,4 @@
1
- import type { CliSettingsHost } from "./cli-settings";
1
+ import { type CliSettingsHost } from "./cli-settings";
2
2
  type $$ComponentProps = {
3
3
  host: CliSettingsHost;
4
4
  embedded?: boolean;
@@ -0,0 +1,480 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import * as Alert from "@lapismd/design-core/shadcn/alert";
4
+ import * as Button from "@lapismd/design-core/shadcn/button";
5
+ import { CodeBlock } from "@lapismd/design-core/shadcn/code-block";
6
+ import { Badge } from "@lapismd/design-core/shadcn/badge";
7
+ import * as Dialog from "@lapismd/design-core/shadcn/dialog";
8
+ import * as Select from "@lapismd/design-core/shadcn/select";
9
+ import { CopyableValue } from "@lapismd/design-core/workspace/settings";
10
+ import AppleIcon from "@lucide/svelte/icons/apple";
11
+ import AppWindowIcon from "@lucide/svelte/icons/app-window";
12
+ import DownloadIcon from "@lucide/svelte/icons/download";
13
+ import CircleAlertIcon from "@lucide/svelte/icons/circle-alert";
14
+ import CircleCheckIcon from "@lucide/svelte/icons/circle-check";
15
+ import CircleMinusIcon from "@lucide/svelte/icons/circle-minus";
16
+ import CircleXIcon from "@lucide/svelte/icons/circle-x";
17
+ import LoaderCircleIcon from "@lucide/svelte/icons/loader-circle";
18
+ import GlobeIcon from "@lucide/svelte/icons/globe";
19
+ import RefreshCwIcon from "@lucide/svelte/icons/refresh-cw";
20
+ import Trash2Icon from "@lucide/svelte/icons/trash-2";
21
+ import TriangleAlertIcon from "@lucide/svelte/icons/triangle-alert";
22
+ import WrenchIcon from "@lucide/svelte/icons/wrench";
23
+ import TerminalIcon from "@lucide/svelte/icons/terminal";
24
+ import {
25
+ cliDownloadOperatingSystem,
26
+ cliDownloadPlatformLabel,
27
+ } from "./cli-download";
28
+ import type { CliSettingsState } from "./cli-settings-state.svelte";
29
+ import CliAccessSettings from "./CliAccessSettings.svelte";
30
+
31
+ type CliSettingsControlKind =
32
+ | "status-badge"
33
+ | "status-path"
34
+ | "installation-action"
35
+ | "installation-error"
36
+ | "refresh"
37
+ | "platform"
38
+ | "checksum"
39
+ | "commands"
40
+ | "access";
41
+
42
+ let {
43
+ model,
44
+ kind,
45
+ controlId,
46
+ }: {
47
+ model: CliSettingsState;
48
+ kind: CliSettingsControlKind;
49
+ controlId: string;
50
+ } = $props();
51
+ const selectedDownloadLabel = $derived(
52
+ model.selectedDownload
53
+ ? cliDownloadPlatformLabel(model.selectedDownload)
54
+ : "Choose your operating system and architecture",
55
+ );
56
+ const installCommands = `./lapis cli install
57
+
58
+ shell_name="bash" # Use "zsh" on macOS.
59
+ ./lapis cli install --setup-path "$shell_name"
60
+
61
+ lapis cli uninstall --remove-path`;
62
+
63
+ onMount(() => model.start());
64
+
65
+ async function install() {
66
+ const installed = await model.run(() =>
67
+ model.host.installation!.install(
68
+ model.shell === "bash" || model.shell === "zsh"
69
+ ? model.shell
70
+ : undefined,
71
+ ),
72
+ );
73
+ if (installed) model.setupOpen = false;
74
+ }
75
+
76
+ async function uninstall() {
77
+ const uninstalled = await model.run(() =>
78
+ model.host.installation!.uninstall(model.removePath),
79
+ );
80
+ if (uninstalled) model.removeOpen = false;
81
+ }
82
+
83
+ function downloadSelectedArchive() {
84
+ const download = model.selectedDownload;
85
+ if (!download) return;
86
+ const anchor = document.createElement("a");
87
+ anchor.href = download.url;
88
+ anchor.download = download.file ?? "";
89
+ anchor.rel = "noopener noreferrer";
90
+ anchor.click();
91
+ }
92
+ </script>
93
+
94
+ {#snippet platformIcon(download = model.selectedDownload)}
95
+ {#if download && cliDownloadOperatingSystem(download) === "macos"}
96
+ <AppleIcon aria-hidden="true" />
97
+ {:else if download && cliDownloadOperatingSystem(download) === "linux"}
98
+ <TerminalIcon aria-hidden="true" />
99
+ {:else if download && cliDownloadOperatingSystem(download) === "windows"}
100
+ <AppWindowIcon aria-hidden="true" />
101
+ {:else}
102
+ <GlobeIcon aria-hidden="true" />
103
+ {/if}
104
+ {/snippet}
105
+
106
+ {#snippet errorAlert()}
107
+ <Alert.Root variant="destructive">
108
+ <CircleAlertIcon aria-hidden="true" />
109
+ <Alert.Description class="cli-error-description">
110
+ {model.error}
111
+ </Alert.Description>
112
+ </Alert.Root>
113
+ {/snippet}
114
+
115
+ {#if kind === "status-badge"}
116
+ <Badge
117
+ id={controlId}
118
+ variant={model.status?.state === "conflict"
119
+ ? "destructive"
120
+ : model.status?.state === "broken"
121
+ ? "default"
122
+ : model.status?.state === "installed"
123
+ ? "default"
124
+ : "outline"}
125
+ data-tone={model.status?.state === "installed"
126
+ ? "success"
127
+ : model.status?.state === "broken"
128
+ ? "warning"
129
+ : undefined}
130
+ aria-live="polite"
131
+ >
132
+ {#if model.status?.state === "installed"}
133
+ <CircleCheckIcon data-icon="inline-start" />
134
+ Installed
135
+ {:else if model.status?.state === "broken"}
136
+ <TriangleAlertIcon data-icon="inline-start" />
137
+ Needs repair
138
+ {:else if model.status?.state === "conflict"}
139
+ <CircleXIcon data-icon="inline-start" />
140
+ Path conflict
141
+ {:else if model.status}
142
+ <CircleMinusIcon data-icon="inline-start" />
143
+ Not installed
144
+ {:else}
145
+ <LoaderCircleIcon data-icon="inline-start" />
146
+ Checking
147
+ {/if}
148
+ {#if model.status}<span>v{model.status.version}</span>{/if}
149
+ </Badge>
150
+ {:else if kind === "status-path"}
151
+ <div id={controlId} class="status-path">
152
+ <TerminalIcon aria-hidden="true" />
153
+ <span>{model.status?.destination ?? "Checking command path…"}</span>
154
+ </div>
155
+ {:else if kind === "installation-action"}
156
+ <span id={controlId}>
157
+ {#if model.status?.state === "installed"}
158
+ <Button.Root
159
+ class="cli-action-button"
160
+ variant="secondary"
161
+ disabled={model.busy}
162
+ onclick={() => (model.removeOpen = true)}
163
+ >
164
+ <Trash2Icon data-icon="inline-start" />
165
+ Uninstall CLI
166
+ </Button.Root>
167
+ {:else}
168
+ <Button.Root
169
+ class="cli-action-button"
170
+ variant="secondary"
171
+ data-tone={model.status?.state === "broken" ? "warning" : undefined}
172
+ disabled={model.busy || !model.status || model.status.state === "conflict"}
173
+ onclick={() => (model.setupOpen = true)}
174
+ >
175
+ {#if model.status?.state === "broken"}
176
+ <WrenchIcon data-icon="inline-start" />
177
+ {:else}
178
+ <DownloadIcon data-icon="inline-start" />
179
+ {/if}
180
+ {model.status?.state === "broken" ? "Repair CLI" : "Install CLI"}
181
+ </Button.Root>
182
+ {/if}
183
+ </span>
184
+ {:else if kind === "installation-error"}
185
+ {#if model.error && !model.setupOpen && !model.removeOpen}{@render errorAlert()}{/if}
186
+ {:else if kind === "refresh"}
187
+ <Button.Root
188
+ id={controlId}
189
+ class="cli-action-button"
190
+ variant="default"
191
+ disabled={model.busy}
192
+ onclick={() => model.run(() => model.refresh(), false)}
193
+ >
194
+ <RefreshCwIcon data-icon="inline-start" />
195
+ Refresh status
196
+ </Button.Root>
197
+ {:else if kind === "platform"}
198
+ <div class="platform-control">
199
+ <Select.Root type="single" bind:value={model.selectedDownloadUrl}>
200
+ <Select.Trigger id={controlId} class="platform-trigger" aria-label="Platform">
201
+ <span class="platform-option">
202
+ {@render platformIcon()}
203
+ <span>{selectedDownloadLabel}</span>
204
+ </span>
205
+ </Select.Trigger>
206
+ <Select.Content aria-label="Platform options">
207
+ <Select.Group>
208
+ {#each model.downloads as download (download.url)}
209
+ <Select.Item
210
+ value={download.url}
211
+ label={cliDownloadPlatformLabel(download)}
212
+ >
213
+ <span class="platform-option">
214
+ {@render platformIcon(download)}
215
+ <span>{cliDownloadPlatformLabel(download)}</span>
216
+ </span>
217
+ </Select.Item>
218
+ {/each}
219
+ </Select.Group>
220
+ </Select.Content>
221
+ </Select.Root>
222
+ <Button.Root
223
+ variant="outline"
224
+ size="icon-sm"
225
+ disabled={!model.selectedDownload}
226
+ aria-label={`Download ${selectedDownloadLabel} archive`}
227
+ title="Download selected archive"
228
+ onclick={downloadSelectedArchive}
229
+ >
230
+ <DownloadIcon aria-hidden="true" />
231
+ </Button.Root>
232
+ </div>
233
+ {:else if kind === "checksum"}
234
+ {#if model.selectedDownload}
235
+ <span id={controlId}>
236
+ <CopyableValue
237
+ value={model.selectedDownload.sha256}
238
+ label="SHA-256 checksum"
239
+ leadingCharacters={12}
240
+ trailingCharacters={8}
241
+ />
242
+ </span>
243
+ {:else}
244
+ <span id={controlId}>Unavailable until a platform is selected</span>
245
+ {/if}
246
+ {:else if kind === "commands"}
247
+ <CodeBlock
248
+ id={controlId}
249
+ code={installCommands}
250
+ language="bash"
251
+ highlightMode="spans"
252
+ width="100%"
253
+ isWrapped
254
+ style="--ui-code-syntax-background: var(--ui-workspace-background)"
255
+ />
256
+ {:else if kind === "access" && model.host.access}
257
+ <div id={controlId}>
258
+ <CliAccessSettings host={model.host.access} embedded />
259
+ </div>
260
+ {/if}
261
+
262
+ {#if kind === "installation-action"}
263
+ <Dialog.Root bind:open={model.setupOpen}>
264
+ <Dialog.Content>
265
+ <Dialog.Header>
266
+ <Dialog.Title>Set up CLI to work in the terminal</Dialog.Title>
267
+ <Dialog.Description>
268
+ Register “lapis” at ~/.local/bin/lapis for your user. Administrator
269
+ access is not required. An existing Lapis-owned CLI copy will be
270
+ replaced.
271
+ </Dialog.Description>
272
+ </Dialog.Header>
273
+ <label id="cli-shell-setup-label">Shell PATH setup
274
+ <Select.Root
275
+ type="single"
276
+ bind:value={model.shell}
277
+ disabled={model.busy}
278
+ >
279
+ <Select.Trigger aria-labelledby="cli-shell-setup-label">
280
+ {model.shell === "zsh"
281
+ ? "Add ~/.local/bin to Zsh PATH"
282
+ : model.shell === "bash"
283
+ ? "Add ~/.local/bin to Bash PATH"
284
+ : "Leave shell configuration unchanged"}
285
+ </Select.Trigger>
286
+ <Select.Content aria-label="Shell PATH setup options">
287
+ <Select.Group>
288
+ <Select.Item
289
+ value="none"
290
+ label="Leave shell configuration unchanged"
291
+ />
292
+ <Select.Item value="zsh" label="Add ~/.local/bin to Zsh PATH" />
293
+ <Select.Item value="bash" label="Add ~/.local/bin to Bash PATH" />
294
+ </Select.Group>
295
+ </Select.Content>
296
+ </Select.Root>
297
+ </label>
298
+ <p>
299
+ PATH setup adds a marked entry to your shell configuration. Other shells
300
+ require manual setup.
301
+ </p>
302
+ {#if model.error}{@render errorAlert()}{/if}
303
+ <Dialog.Footer>
304
+ <Button.Root
305
+ variant="outline"
306
+ disabled={model.busy}
307
+ onclick={() => (model.setupOpen = false)}>Cancel</Button.Root
308
+ >
309
+ <Button.Root disabled={model.busy} onclick={install}>
310
+ {#if model.status?.state === "broken"}
311
+ <WrenchIcon data-icon="inline-start" />
312
+ Repair CLI
313
+ {:else}
314
+ <DownloadIcon data-icon="inline-start" />
315
+ Install CLI
316
+ {/if}
317
+ </Button.Root>
318
+ </Dialog.Footer>
319
+ </Dialog.Content>
320
+ </Dialog.Root>
321
+
322
+ <Dialog.Root bind:open={model.removeOpen}>
323
+ <Dialog.Content>
324
+ <Dialog.Header>
325
+ <Dialog.Title>Uninstall the CLI command?</Dialog.Title>
326
+ <Dialog.Description>
327
+ Your vaults, credentials and application data will be retained.
328
+ </Dialog.Description>
329
+ </Dialog.Header>
330
+ <label>
331
+ <input
332
+ type="checkbox"
333
+ bind:checked={model.removePath}
334
+ disabled={model.busy}
335
+ />
336
+ Remove unchanged Lapis PATH entries
337
+ </label>
338
+ {#if model.error}{@render errorAlert()}{/if}
339
+ <Dialog.Footer>
340
+ <Button.Root
341
+ variant="outline"
342
+ disabled={model.busy}
343
+ onclick={() => (model.removeOpen = false)}>Cancel</Button.Root
344
+ >
345
+ <Button.Root
346
+ variant="destructive"
347
+ disabled={model.busy}
348
+ onclick={uninstall}
349
+ >
350
+ <Trash2Icon data-icon="inline-start" />
351
+ Uninstall
352
+ </Button.Root>
353
+ </Dialog.Footer>
354
+ </Dialog.Content>
355
+ </Dialog.Root>
356
+ {/if}
357
+
358
+ <style>
359
+ .status-path {
360
+ display: flex;
361
+ width: 100%;
362
+ min-width: 0;
363
+ align-items: center;
364
+ gap: 0.5rem;
365
+ }
366
+ .status-path span {
367
+ min-width: 0;
368
+ color: var(--ui-workspace-muted-foreground, var(--muted-foreground));
369
+ font-family: inherit;
370
+ font-size: var(--ui-workspace-settings-description-size, 0.875rem);
371
+ line-height: 1.3;
372
+ overflow-wrap: anywhere;
373
+ white-space: normal;
374
+ }
375
+ .status-path :global(svg) {
376
+ width: 0.875rem;
377
+ height: 0.875rem;
378
+ flex: 0 0 auto;
379
+ }
380
+ :global(.cli-action-button) {
381
+ width: 10rem;
382
+ max-width: 100%;
383
+ }
384
+ :global(.cli-action-button[data-variant="secondary"]) {
385
+ border-color: var(--ui-workspace-border);
386
+ color: var(--ui-workspace-panel-action-hover-foreground);
387
+ background-color: color-mix(
388
+ in srgb,
389
+ var(--ui-workspace-panel-action-hover-background) 70%,
390
+ var(--ui-workspace-panel)
391
+ );
392
+ }
393
+ @media (hover: hover) {
394
+ :global(.cli-action-button[data-variant="secondary"]:hover:not(:disabled)) {
395
+ color: var(--ui-workspace-panel-action-hover-foreground);
396
+ background-color: var(--ui-workspace-panel-action-hover-background);
397
+ }
398
+ }
399
+ :global(.cli-action-button[data-tone="warning"]) {
400
+ border-color: var(--ui-workspace-warning);
401
+ color: var(--primary-foreground);
402
+ background-color: color-mix(
403
+ in srgb,
404
+ var(--ui-workspace-warning) 62%,
405
+ #000000
406
+ );
407
+ }
408
+ @media (hover: hover) {
409
+ :global(.cli-action-button[data-tone="warning"]:hover:not(:disabled)) {
410
+ color: var(--primary-foreground);
411
+ background-color: color-mix(
412
+ in srgb,
413
+ var(--ui-workspace-warning) 70%,
414
+ #000000
415
+ );
416
+ }
417
+ }
418
+ :global([data-ui-component="badge"][data-tone="success"]) {
419
+ --ui-badge-background: var(--ui-workspace-success, #15803d);
420
+ --ui-badge-foreground: var(--primary-foreground);
421
+ }
422
+ :global([data-ui-component="badge"][data-tone="warning"]) {
423
+ --ui-badge-background: color-mix(
424
+ in srgb,
425
+ var(--ui-workspace-warning) 62%,
426
+ #000000
427
+ );
428
+ --ui-badge-foreground: var(--primary-foreground);
429
+ }
430
+ :global(
431
+ .ui-workspace-setting-item[data-setting-id="cli.installation"]:not(
432
+ :has(> .ui-workspace-setting-item__control > *)
433
+ )
434
+ ) {
435
+ row-gap: 0;
436
+ }
437
+ :global(
438
+ .ui-workspace-setting-item[data-setting-id="cli.installation"]
439
+ > .ui-workspace-setting-item__control:not(:has(> *))
440
+ ) {
441
+ display: none;
442
+ }
443
+ :global(.cli-error-description) {
444
+ font-family: inherit;
445
+ font-size: var(--ui-workspace-settings-description-size);
446
+ line-height: 1.3;
447
+ }
448
+ .platform-control,
449
+ .platform-option {
450
+ display: flex;
451
+ min-width: 0;
452
+ align-items: center;
453
+ gap: 0.5rem;
454
+ }
455
+ .platform-control {
456
+ width: 100%;
457
+ }
458
+ .platform-control :global(.platform-trigger) {
459
+ min-width: 0;
460
+ flex: 1 1 auto;
461
+ }
462
+ .platform-option {
463
+ flex: 1 1 auto;
464
+ }
465
+ .platform-option > span {
466
+ min-width: 0;
467
+ overflow: hidden;
468
+ text-overflow: ellipsis;
469
+ white-space: nowrap;
470
+ }
471
+ .platform-option :global(svg) {
472
+ width: 0.875rem;
473
+ height: 0.875rem;
474
+ flex: 0 0 auto;
475
+ }
476
+ label {
477
+ display: grid;
478
+ gap: 0.5rem;
479
+ }
480
+ </style>
@@ -0,0 +1,10 @@
1
+ import type { CliSettingsState } from "./cli-settings-state.svelte";
2
+ type CliSettingsControlKind = "status-badge" | "status-path" | "installation-action" | "installation-error" | "refresh" | "platform" | "checksum" | "commands" | "access";
3
+ type $$ComponentProps = {
4
+ model: CliSettingsState;
5
+ kind: CliSettingsControlKind;
6
+ controlId: string;
7
+ };
8
+ declare const CliSettingsControl: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type CliSettingsControl = ReturnType<typeof CliSettingsControl>;
10
+ export default CliSettingsControl;
@@ -0,0 +1,13 @@
1
+ import type { CliDownload } from "./cli-settings";
2
+ export type CliOperatingSystem = "linux" | "macos" | "windows";
3
+ export interface CliBrowserIdentity {
4
+ platform?: string;
5
+ userAgent?: string;
6
+ userAgentData?: {
7
+ platform?: string;
8
+ };
9
+ }
10
+ export declare function cliDownloadLabel(download: CliDownload): string;
11
+ export declare function cliDownloadPlatformLabel(download: CliDownload): string;
12
+ export declare function cliDownloadOperatingSystem(download: CliDownload): CliOperatingSystem | undefined;
13
+ export declare function preferredCliDownloadUrl(downloads: readonly CliDownload[], browser?: CliBrowserIdentity | undefined): string;
@@ -0,0 +1,66 @@
1
+ function platformFromText(value) {
2
+ const text = value.toLowerCase();
3
+ const os = /(?:mac|darwin)/u.test(text)
4
+ ? "macos"
5
+ : /(?:linux|ubuntu)/u.test(text)
6
+ ? "linux"
7
+ : /(?:win|mingw|msvc)/u.test(text)
8
+ ? "windows"
9
+ : undefined;
10
+ const architecture = /(?:aarch64|arm64|armv8)/u.test(text)
11
+ ? "arm64"
12
+ : /(?:x86_64|x64|amd64|win64|wow64)/u.test(text)
13
+ ? "x64"
14
+ : undefined;
15
+ return { os, architecture };
16
+ }
17
+ function downloadPlatform(download) {
18
+ return platformFromText([download.target, download.label, download.file, download.url]
19
+ .filter(Boolean)
20
+ .join(" "));
21
+ }
22
+ export function cliDownloadLabel(download) {
23
+ if (download.label)
24
+ return download.label;
25
+ const platform = downloadPlatform(download);
26
+ const os = platform.os === "macos"
27
+ ? "macOS"
28
+ : platform.os === "linux"
29
+ ? "Linux"
30
+ : platform.os === "windows"
31
+ ? "Windows"
32
+ : "CLI";
33
+ const architecture = platform.architecture === "arm64"
34
+ ? "ARM64"
35
+ : platform.architecture === "x64"
36
+ ? "x64"
37
+ : undefined;
38
+ return `Lapis CLI · ${os}${architecture ? ` · ${architecture}` : ""}`;
39
+ }
40
+ export function cliDownloadPlatformLabel(download) {
41
+ if (download.label) {
42
+ return download.label.replace(/^Lapis CLI\s*·\s*/u, "");
43
+ }
44
+ return cliDownloadLabel(download).replace(/^Lapis CLI\s*·\s*/u, "");
45
+ }
46
+ export function cliDownloadOperatingSystem(download) {
47
+ return downloadPlatform(download).os;
48
+ }
49
+ export function preferredCliDownloadUrl(downloads, browser = globalThis.navigator) {
50
+ if (!browser)
51
+ return "";
52
+ const detected = platformFromText([browser.userAgentData?.platform, browser.platform, browser.userAgent]
53
+ .filter(Boolean)
54
+ .join(" "));
55
+ if (!detected.os)
56
+ return "";
57
+ const operatingSystemMatches = downloads.filter((download) => downloadPlatform(download).os === detected.os);
58
+ if (detected.architecture) {
59
+ const exact = operatingSystemMatches.find((download) => downloadPlatform(download).architecture === detected.architecture);
60
+ if (exact)
61
+ return exact.url;
62
+ }
63
+ return operatingSystemMatches.length === 1
64
+ ? operatingSystemMatches[0].url
65
+ : "";
66
+ }
@@ -0,0 +1,20 @@
1
+ import type { CliDownload, CliInstallationStatus, CliSettingsHost } from "./cli-settings";
2
+ export declare class CliSettingsState {
3
+ #private;
4
+ readonly host: CliSettingsHost;
5
+ status: CliInstallationStatus | undefined;
6
+ downloads: CliDownload[];
7
+ selectedDownloadUrl: string;
8
+ busy: boolean;
9
+ error: string;
10
+ setupOpen: boolean;
11
+ removeOpen: boolean;
12
+ shell: "none" | "bash" | "zsh";
13
+ removePath: boolean;
14
+ constructor(host: CliSettingsHost);
15
+ get selectedDownload(): CliDownload | undefined;
16
+ start(): void;
17
+ dispose(): void;
18
+ refresh(): Promise<void>;
19
+ run(action: () => Promise<void>, refreshAfter?: boolean): Promise<boolean>;
20
+ }
@@ -0,0 +1,68 @@
1
+ import { preferredCliDownloadUrl } from "./cli-download";
2
+ export class CliSettingsState {
3
+ host;
4
+ status = $state();
5
+ downloads = $state([]);
6
+ selectedDownloadUrl = $state("");
7
+ busy = $state(false);
8
+ error = $state("");
9
+ setupOpen = $state(false);
10
+ removeOpen = $state(false);
11
+ shell = $state("none");
12
+ removePath = $state(false);
13
+ #started = false;
14
+ #disposed = false;
15
+ constructor(host) {
16
+ this.host = host;
17
+ }
18
+ get selectedDownload() {
19
+ return this.downloads.find((download) => download.url === this.selectedDownloadUrl);
20
+ }
21
+ start() {
22
+ if (this.#started || this.#disposed)
23
+ return;
24
+ this.#started = true;
25
+ void this.run(() => this.refresh(), false);
26
+ }
27
+ dispose() {
28
+ this.#disposed = true;
29
+ }
30
+ async refresh() {
31
+ const [status, downloads] = await Promise.all([
32
+ this.host.installation?.status(),
33
+ this.host.downloads?.(),
34
+ ]);
35
+ if (this.#disposed)
36
+ return;
37
+ this.status = status;
38
+ this.downloads = downloads ?? [];
39
+ if (!this.downloads.some((download) => download.url === this.selectedDownloadUrl)) {
40
+ this.selectedDownloadUrl = preferredCliDownloadUrl(this.downloads);
41
+ }
42
+ }
43
+ async run(action, refreshAfter = true) {
44
+ if (this.busy || this.#disposed)
45
+ return false;
46
+ this.busy = true;
47
+ this.error = "";
48
+ try {
49
+ await action();
50
+ if (refreshAfter)
51
+ await this.refresh();
52
+ return true;
53
+ }
54
+ catch (failure) {
55
+ if (!this.#disposed) {
56
+ this.error =
57
+ failure instanceof Error ? failure.message : String(failure);
58
+ if (refreshAfter)
59
+ await this.refresh().catch(() => { });
60
+ }
61
+ return false;
62
+ }
63
+ finally {
64
+ if (!this.#disposed)
65
+ this.busy = false;
66
+ }
67
+ }
68
+ }
@@ -5,7 +5,11 @@ export interface CliInstallationStatus {
5
5
  version: string;
6
6
  }
7
7
  export interface CliDownload {
8
- label: string;
8
+ /** Human-readable override; release manifests may rely on target instead. */
9
+ label?: string;
10
+ /** Rust release target, such as aarch64-apple-darwin. */
11
+ target?: string;
12
+ file?: string;
9
13
  url: string;
10
14
  sha256: string;
11
15
  }
@@ -1,4 +1,5 @@
1
- import CliSettingsField from "./CliSettingsField.svelte";
1
+ import CliSettingsControl from "./CliSettingsControl.svelte";
2
+ import { CliSettingsState } from "./cli-settings-state.svelte";
2
3
  const hosts = new WeakMap();
3
4
  const fieldHosts = new WeakMap();
4
5
  export function cliSettingsFieldHost(field) {
@@ -20,34 +21,109 @@ export function registerCliSettings(settings, host) {
20
21
  }
21
22
  const entry = { host };
22
23
  hosts.set(settings, entry);
23
- const field = {
24
- id: "cli",
25
- title: "Command line interface",
26
- description: "Use the lapis command from your terminal.",
27
- type: "custom",
28
- presentation: "full-width",
29
- component: (anchor) => {
24
+ const state = new CliSettingsState(host);
25
+ const ownedFields = [];
26
+ const adapters = [];
27
+ function controlComponent(kind, id) {
28
+ return (anchor) => {
30
29
  if (hosts.get(settings) !== entry) {
31
30
  throw new Error("CLI settings host is not bound");
32
31
  }
33
- CliSettingsField(anchor, { host: entry.host });
32
+ CliSettingsControl(anchor, {
33
+ model: state,
34
+ kind,
35
+ controlId: `setting-${id}`,
36
+ });
34
37
  return {};
38
+ };
39
+ }
40
+ function customField(id, title, description, kind, presentation = "row") {
41
+ const field = {
42
+ id,
43
+ title,
44
+ description,
45
+ type: "custom",
46
+ presentation,
47
+ component: controlComponent(kind, id),
48
+ };
49
+ fieldHosts.set(field, host);
50
+ ownedFields.push(field);
51
+ return field;
52
+ }
53
+ const advancedFields = [];
54
+ if (host.installation) {
55
+ const statusField = {
56
+ id: "cli.status",
57
+ title: "Status",
58
+ description: "Check the installed command and bundled CLI version.",
59
+ type: "custom",
60
+ adapter: "lapis.cli.status",
61
+ presentation: "full-width",
62
+ };
63
+ fieldHosts.set(statusField, host);
64
+ ownedFields.push(statusField);
65
+ adapters.push({
66
+ id: "lapis.cli.status",
67
+ component: controlComponent("status-path", statusField.id),
68
+ headerComponent: controlComponent("status-badge", `${statusField.id}-badge`),
69
+ });
70
+ const installationField = {
71
+ id: "cli.installation",
72
+ title: "Installation",
73
+ description: "Install, repair or remove the per-user terminal command.",
74
+ type: "custom",
75
+ adapter: "lapis.cli.installation",
76
+ presentation: "full-width",
77
+ };
78
+ fieldHosts.set(installationField, host);
79
+ ownedFields.push(installationField);
80
+ adapters.push({
81
+ id: "lapis.cli.installation",
82
+ component: controlComponent("installation-error", `${installationField.id}-error`),
83
+ headerComponent: controlComponent("installation-action", installationField.id),
84
+ });
85
+ advancedFields.push(statusField, installationField);
86
+ }
87
+ advancedFields.push(customField("cli.refresh", "Refresh status", "Check the bundled CLI and available downloads again.", "refresh"));
88
+ const groups = [
89
+ {
90
+ id: "advanced",
91
+ title: "Advanced",
92
+ description: "Configure the Lapis command-line interface.",
93
+ type: "group",
94
+ fields: advancedFields,
35
95
  },
36
- };
37
- fieldHosts.set(field, host);
38
- const dispose = settings.registerSection({
96
+ ];
97
+ if (host.downloads) {
98
+ groups.push({
99
+ id: "cli.browser-installation",
100
+ title: "Browser installation",
101
+ description: "Choose the matching archive, verify it, and install the command locally.",
102
+ type: "group",
103
+ fields: [
104
+ customField("cli.platform", "Platform", "Choose your operating system and architecture.", "platform"),
105
+ customField("cli.checksum", "SHA-256", "Copy the checksum to verify the downloaded archive.", "checksum"),
106
+ customField("cli.commands", "Install from the archive", "Run these commands after extracting the archive. Choose Bash or Zsh for PATH setup; for another shell, add ~/.local/bin manually.", "commands", "full-width"),
107
+ ],
108
+ });
109
+ }
110
+ if (host.access) {
111
+ groups.push({
112
+ id: "cli.desktop-access",
113
+ title: "Desktop access",
114
+ description: "Allow explicitly scoped commands while the desktop app is running.",
115
+ type: "group",
116
+ fields: [
117
+ customField("cli.access", "Connect to desktop vaults", "Installing the command does not enable access.", "access", "full-width"),
118
+ ],
119
+ });
120
+ }
121
+ const section = {
39
122
  id: "general",
40
123
  title: "General",
41
124
  navigationGroupId: "options",
42
125
  order: 0,
43
- fields: [
44
- {
45
- id: "advanced",
46
- title: "Advanced",
47
- type: "group",
48
- fields: [field],
49
- },
50
- ],
126
+ fields: groups,
51
127
  searchEntries: [
52
128
  {
53
129
  id: "cli",
@@ -56,14 +132,24 @@ export function registerCliSettings(settings, host) {
56
132
  keywords: ["cli", "lapis", "PATH", "install", "terminal"],
57
133
  },
58
134
  ],
59
- });
135
+ };
136
+ const source = {
137
+ get: () => undefined,
138
+ set: async () => undefined,
139
+ subscribe: () => () => undefined,
140
+ };
141
+ const dispose = settings.registerDefinition({ section, source, adapters });
60
142
  return () => {
61
143
  if (hosts.get(settings) !== entry) {
62
- fieldHosts.delete(field);
144
+ for (const field of ownedFields)
145
+ fieldHosts.delete(field);
146
+ state.dispose();
63
147
  return;
64
148
  }
65
149
  dispose();
66
150
  hosts.delete(settings);
67
- fieldHosts.delete(field);
151
+ for (const field of ownedFields)
152
+ fieldHosts.delete(field);
153
+ state.dispose();
68
154
  };
69
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lapis-notes/ui",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Public UI primitives required by Lapis Notes API consumers",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -96,7 +96,7 @@
96
96
  "dependencies": {
97
97
  "@dnd-kit/dom": "^0.4.0",
98
98
  "@dnd-kit/svelte": "^0.4.0",
99
- "@lapismd/design-core": "^0.13.5",
99
+ "@lapismd/design-core": "^0.13.6",
100
100
  "@lucide/svelte": "^0.515.0",
101
101
  "bits-ui": "2.20.2",
102
102
  "clsx": "^2.1.1",
@@ -1,8 +0,0 @@
1
- <script lang="ts">
2
- import type { CliSettingsHost } from "./cli-settings";
3
- import CliSettings from "./CliSettings.svelte";
4
-
5
- let { host }: { host: CliSettingsHost } = $props();
6
- </script>
7
-
8
- <CliSettings {host} embedded />
@@ -1,7 +0,0 @@
1
- import type { CliSettingsHost } from "./cli-settings";
2
- type $$ComponentProps = {
3
- host: CliSettingsHost;
4
- };
5
- declare const CliSettingsField: import("svelte").Component<$$ComponentProps, {}, "">;
6
- type CliSettingsField = ReturnType<typeof CliSettingsField>;
7
- export default CliSettingsField;