@lapis-notes/ui 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @lapis-notes/ui
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#116](https://github.com/lapismd/lapis-notes/pull/116)
8
+ [`c7af79f`](https://github.com/lapismd/lapis-notes/commit/c7af79fc40d261e18e92c985bf817f1054471560)
9
+ Thanks [@stevejuma](https://github.com/stevejuma)! - Expose host-owned CLI
10
+ installation, download and desktop-access settings under General → Advanced.
11
+
3
12
  ## 0.1.10
4
13
 
5
14
  ### Patch Changes
package/README.md CHANGED
@@ -44,3 +44,10 @@ pnpm --filter @lapis-notes/ui check
44
44
 
45
45
  - [Package spec](spec.md)
46
46
  - [Canonical spec](../../spec/src/ui-and-styling.md)
47
+
48
+ ### CLI settings
49
+
50
+ `@lapis-notes/ui/cli` exports `CliSettings`, `registerCliSettings` and typed host ports. Register against the owning
51
+ workspace settings controller and dispose with that workspace. Hosts implement
52
+ installation, downloads and optional scoped desktop access; this UI package
53
+ does not install executables, issue credentials or persist secrets.
@@ -0,0 +1,173 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import * as Button from "@lapismd/design-core/shadcn/button";
4
+ import type { CliAccessHost, CliAccessStatus } from "./cli-settings";
5
+ let { host }: { host: CliAccessHost } = $props();
6
+ let status = $state<CliAccessStatus>();
7
+ let busy = $state(false);
8
+ let error = $state("");
9
+ let label = $state("CLI client");
10
+ let hours = $state(1);
11
+ let selected = $state<string[]>([]);
12
+ let permissions = $state<string[]>([]);
13
+ let command = $state("");
14
+ let alive = true;
15
+ async function refresh() {
16
+ const next = await host.status();
17
+ if (alive) status = next;
18
+ }
19
+ async function run(action: () => Promise<void>, refreshAfter = true) {
20
+ if (busy) return;
21
+ busy = true;
22
+ error = "";
23
+ command = "";
24
+ try {
25
+ await action();
26
+ if (refreshAfter) await refresh();
27
+ } catch (failure) {
28
+ if (alive)
29
+ error = failure instanceof Error ? failure.message : String(failure);
30
+ } finally {
31
+ if (alive) busy = false;
32
+ }
33
+ }
34
+ onMount(() => {
35
+ void run(refresh, false);
36
+ return () => {
37
+ alive = false;
38
+ command = "";
39
+ };
40
+ });
41
+ </script>
42
+
43
+ <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>
49
+ {#if status}
50
+ <Button.Root
51
+ disabled={busy}
52
+ variant="outline"
53
+ onclick={() => run(() => host.enable(!status!.enabled))}
54
+ >{status.enabled
55
+ ? "Disable desktop access"
56
+ : "Enable desktop access"}</Button.Root
57
+ >
58
+ {#if status.enabled}
59
+ <p>Target: <code>{status.target}</code></p>
60
+ <label
61
+ >Credential name <input
62
+ bind:value={label}
63
+ maxlength="128"
64
+ disabled={busy}
65
+ /></label
66
+ >
67
+ <fieldset disabled={busy}>
68
+ <legend>Vault access</legend>
69
+ {#each status.vaults as vault (vault.id)}
70
+ <label
71
+ ><input type="checkbox" bind:group={selected} value={vault.id} />
72
+ {vault.name}</label
73
+ >
74
+ {/each}
75
+ </fieldset>
76
+ <fieldset disabled={busy}>
77
+ <legend>Optional plugin permissions (read-only by default)</legend>
78
+ {#each status.permissions as permission (permission)}
79
+ <label
80
+ ><input
81
+ type="checkbox"
82
+ bind:group={permissions}
83
+ value={permission}
84
+ />
85
+ {permission}</label
86
+ >
87
+ {/each}
88
+ </fieldset>
89
+ <label
90
+ >Expires after (hours) <input
91
+ type="number"
92
+ min="1"
93
+ max="24"
94
+ bind:value={hours}
95
+ disabled={busy}
96
+ /></label
97
+ >
98
+ <Button.Root
99
+ disabled={busy ||
100
+ selected.length === 0 ||
101
+ !label.trim() ||
102
+ !Number.isInteger(hours) ||
103
+ hours < 1 ||
104
+ hours > 24}
105
+ onclick={() =>
106
+ run(async () => {
107
+ const result = await host.create({
108
+ label,
109
+ vaultIds: selected,
110
+ hours,
111
+ permissions,
112
+ });
113
+ if (alive) command = result.command;
114
+ })}>Create credential and save token file</Button.Root
115
+ >
116
+ {#if command}<p>Credential saved privately. Run:</p>
117
+ <pre>{command}</pre>{/if}
118
+ {#each status.grants as grant (grant.id)}
119
+ <div class="grant">
120
+ <span>{grant.label}</span><Button.Root
121
+ disabled={busy}
122
+ variant="outline"
123
+ onclick={() => run(() => host.revoke(grant.id))}
124
+ >Revoke {grant.label}</Button.Root
125
+ >
126
+ </div>
127
+ {/each}
128
+ {/if}
129
+ {/if}
130
+ {#if error}<p role="alert">{error}</p>{/if}
131
+ </section>
132
+
133
+ <style>
134
+ section {
135
+ display: grid;
136
+ gap: 0.75rem;
137
+ border-top: 1px solid var(--border);
138
+ padding-top: 1rem;
139
+ }
140
+ h3,
141
+ p {
142
+ margin: 0;
143
+ }
144
+ label {
145
+ display: flex;
146
+ align-items: center;
147
+ gap: 0.5rem;
148
+ flex-wrap: wrap;
149
+ }
150
+ input:not([type="checkbox"]) {
151
+ color: inherit;
152
+ background: transparent;
153
+ padding: 0.4rem;
154
+ border: 1px solid var(--border);
155
+ border-radius: var(--radius);
156
+ }
157
+ fieldset {
158
+ display: grid;
159
+ gap: 0.5rem;
160
+ border: 1px solid var(--border);
161
+ }
162
+ .grant {
163
+ display: flex;
164
+ justify-content: space-between;
165
+ align-items: center;
166
+ gap: 1rem;
167
+ }
168
+ code,
169
+ pre {
170
+ white-space: pre-wrap;
171
+ overflow-wrap: anywhere;
172
+ }
173
+ </style>
@@ -0,0 +1,7 @@
1
+ import type { CliAccessHost } from "./cli-settings";
2
+ type $$ComponentProps = {
3
+ host: CliAccessHost;
4
+ };
5
+ declare const CliAccessSettings: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type CliAccessSettings = ReturnType<typeof CliAccessSettings>;
7
+ export default CliAccessSettings;
@@ -0,0 +1,249 @@
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 }: { host: CliSettingsHost } = $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
+ };
56
+ });
57
+ </script>
58
+
59
+ <section
60
+ data-ui-component="lapis-cli-settings"
61
+ aria-label="Command line interface"
62
+ >
63
+ <div class="row">
64
+ <div>
65
+ <h3>Command line interface</h3>
66
+ <p>Use the <code>lapis</code> command from your terminal.</p>
67
+ {#if status}
68
+ <p>
69
+ {status.state === "installed"
70
+ ? "Installed"
71
+ : status.state === "broken"
72
+ ? "Needs repair"
73
+ : status.state === "conflict"
74
+ ? "Another command occupies this path"
75
+ : "Not installed"} · bundled CLI {status.version}
76
+ </p>
77
+ <code>{status.destination}</code>
78
+ {/if}
79
+ </div>
80
+ {#if host.installation}
81
+ {#if status?.state === "installed"}
82
+ <Button.Root
83
+ variant="outline"
84
+ disabled={busy}
85
+ onclick={() => (remove = true)}>Uninstall CLI</Button.Root
86
+ >
87
+ {:else}
88
+ <Button.Root
89
+ disabled={busy || !status || status.state === "conflict"}
90
+ onclick={() => (setup = true)}
91
+ >{status?.state === "broken"
92
+ ? "Repair CLI"
93
+ : "Install CLI"}</Button.Root
94
+ >
95
+ {/if}
96
+ {/if}
97
+ </div>
98
+ {#if status?.state === "installed"}
99
+ <p>
100
+ Open a new terminal and run <code>command -v lapis</code> and
101
+ <code>lapis --version</code>.
102
+ </p>
103
+ {/if}
104
+ {#if host.downloads}
105
+ <p>
106
+ Install on this computer. Your browser cannot inspect or change your local
107
+ PATH.
108
+ </p>
109
+ {#if downloads.length}
110
+ <label>Platform
111
+ <select bind:value={selectedDownload}>
112
+ <option value="">Choose your operating system and architecture</option>
113
+ {#each downloads as file (file.url)}<option value={file.url}>{file.label}</option>{/each}
114
+ </select>
115
+ </label>
116
+ {/if}
117
+ {#if download}
118
+ <div class="download">
119
+ <a href={download.url} download>Download {download.label}</a>
120
+ <p>SHA-256: <code>{download.sha256}</code></p>
121
+ </div>
122
+ {/if}
123
+ {#if downloads.length}
124
+ <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>
125
+ <p>Install or remove the command on this computer:</p>
126
+ <pre>./lapis cli install
127
+ # Optional PATH setup (choose your shell):
128
+ ./lapis cli install --setup-path zsh
129
+ # Remove the command later:
130
+ lapis cli uninstall --remove-path</pre>
131
+ <p>
132
+ Use <code>--setup-path bash</code> for Bash. For another shell, add
133
+ <code>~/.local/bin</code> to PATH manually.
134
+ </p>
135
+ {/if}
136
+ {/if}
137
+ {#if error && !setup && !remove}<p role="alert">{error}</p>{/if}
138
+ <Button.Root variant="ghost" disabled={busy} onclick={() => run(refresh, false)}
139
+ >Refresh status</Button.Root
140
+ >
141
+ {#if host.access}<CliAccessSettings host={host.access} />{/if}
142
+ </section>
143
+
144
+ <Dialog.Root bind:open={setup}>
145
+ <Dialog.Content>
146
+ <Dialog.Header>
147
+ <Dialog.Title>Set up CLI to work in the terminal</Dialog.Title>
148
+ <Dialog.Description
149
+ >Register “lapis” at ~/.local/bin/lapis for your user. Administrator
150
+ access is not required. An existing Lapis-owned CLI copy will be
151
+ replaced.</Dialog.Description
152
+ >
153
+ </Dialog.Header>
154
+ <label
155
+ >Shell PATH setup
156
+ <select bind:value={shell} disabled={busy}>
157
+ <option value="none">Leave shell configuration unchanged</option>
158
+ <option value="zsh">Add ~/.local/bin to Zsh PATH</option>
159
+ <option value="bash">Add ~/.local/bin to Bash PATH</option>
160
+ </select>
161
+ </label>
162
+ <p>
163
+ PATH setup adds a marked entry to your shell configuration. Other shells
164
+ require manual setup.
165
+ </p>
166
+ {#if error}<p role="alert">{error}</p>{/if}
167
+ <Dialog.Footer>
168
+ <Button.Root
169
+ variant="outline"
170
+ disabled={busy}
171
+ onclick={() => (setup = false)}>Cancel</Button.Root
172
+ >
173
+ <Button.Root
174
+ disabled={busy}
175
+ onclick={() =>
176
+ run(() =>
177
+ host.installation!.install(
178
+ shell === "bash" || shell === "zsh" ? shell : undefined,
179
+ ),
180
+ )}>Register</Button.Root
181
+ >
182
+ </Dialog.Footer>
183
+ </Dialog.Content>
184
+ </Dialog.Root>
185
+ <Dialog.Root bind:open={remove}>
186
+ <Dialog.Content>
187
+ <Dialog.Header>
188
+ <Dialog.Title>Uninstall the CLI command?</Dialog.Title>
189
+ <Dialog.Description
190
+ >Your vaults, credentials and application data will be retained.</Dialog.Description
191
+ >
192
+ </Dialog.Header>
193
+ <label
194
+ ><input type="checkbox" bind:checked={removePath} disabled={busy} /> Remove
195
+ unchanged Lapis PATH entries</label
196
+ >
197
+ {#if error}<p role="alert">{error}</p>{/if}
198
+ <Dialog.Footer>
199
+ <Button.Root
200
+ variant="outline"
201
+ disabled={busy}
202
+ onclick={() => (remove = false)}>Cancel</Button.Root
203
+ >
204
+ <Button.Root
205
+ disabled={busy}
206
+ onclick={() => run(() => host.installation!.uninstall(removePath))}
207
+ >Uninstall</Button.Root
208
+ >
209
+ </Dialog.Footer>
210
+ </Dialog.Content>
211
+ </Dialog.Root>
212
+
213
+ <style>
214
+ section {
215
+ display: grid;
216
+ gap: 1rem;
217
+ color: var(--ui-workspace-view-foreground, inherit);
218
+ }
219
+ .row {
220
+ display: flex;
221
+ align-items: center;
222
+ justify-content: space-between;
223
+ gap: 1rem;
224
+ flex-wrap: wrap;
225
+ }
226
+ h3,
227
+ p {
228
+ margin: 0.3rem 0;
229
+ }
230
+ code,
231
+ pre {
232
+ overflow-wrap: anywhere;
233
+ white-space: pre-wrap;
234
+ }
235
+ .download {
236
+ padding-block: 0.5rem;
237
+ }
238
+ label {
239
+ display: grid;
240
+ gap: 0.5rem;
241
+ }
242
+ select {
243
+ color: inherit;
244
+ background: transparent;
245
+ padding: 0.5rem;
246
+ border: 1px solid var(--border);
247
+ border-radius: var(--radius);
248
+ }
249
+ </style>
@@ -0,0 +1,7 @@
1
+ import type { CliSettingsHost } from "./cli-settings";
2
+ type $$ComponentProps = {
3
+ host: CliSettingsHost;
4
+ };
5
+ declare const CliSettings: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type CliSettings = ReturnType<typeof CliSettings>;
7
+ export default CliSettings;
@@ -0,0 +1,12 @@
1
+ <script lang="ts">
2
+ import { untrack } from "svelte";
3
+ import type { WorkspaceSettingsPageProps } from "@lapismd/design-core/workspace/settings";
4
+ import { cliSettingsHost } from "./cli-settings";
5
+ import CliSettings from "./CliSettings.svelte";
6
+ let { controller }: WorkspaceSettingsPageProps = $props();
7
+ const host = untrack(() => cliSettingsHost(controller));
8
+ </script>
9
+
10
+ <h1>General</h1>
11
+ <h2>Advanced</h2>
12
+ <CliSettings {host} />
@@ -0,0 +1,4 @@
1
+ import type { WorkspaceSettingsPageProps } from "@lapismd/design-core/workspace/settings";
2
+ declare const GeneralCliSettingsPage: import("svelte").Component<WorkspaceSettingsPageProps, {}, "">;
3
+ type GeneralCliSettingsPage = ReturnType<typeof GeneralCliSettingsPage>;
4
+ export default GeneralCliSettingsPage;
@@ -0,0 +1,49 @@
1
+ import type { WorkspaceSettingsController } from "@lapismd/design-core/workspace/settings";
2
+ export interface CliInstallationStatus {
3
+ state: "not-installed" | "installed" | "broken" | "conflict";
4
+ destination: string;
5
+ version: string;
6
+ }
7
+ export interface CliDownload {
8
+ label: string;
9
+ url: string;
10
+ sha256: string;
11
+ }
12
+ export interface CliAccessStatus {
13
+ enabled: boolean;
14
+ target: string | null;
15
+ vaults: {
16
+ id: string;
17
+ name: string;
18
+ }[];
19
+ permissions: string[];
20
+ grants: {
21
+ id: string;
22
+ label: string;
23
+ }[];
24
+ }
25
+ export interface CliAccessHost {
26
+ status(): Promise<CliAccessStatus>;
27
+ enable(enabled: boolean): Promise<void>;
28
+ create(input: {
29
+ label: string;
30
+ vaultIds: string[];
31
+ hours: number;
32
+ permissions: string[];
33
+ }): Promise<{
34
+ command: string;
35
+ }>;
36
+ revoke(id: string): Promise<void>;
37
+ }
38
+ /** Host authority stays outside the shared settings presentation. */
39
+ export interface CliSettingsHost {
40
+ installation?: {
41
+ status(): Promise<CliInstallationStatus>;
42
+ install(shell?: "bash" | "zsh"): Promise<void>;
43
+ uninstall(removePath: boolean): Promise<void>;
44
+ };
45
+ downloads?: () => Promise<CliDownload[]>;
46
+ access?: CliAccessHost;
47
+ }
48
+ export declare function cliSettingsHost(controller: WorkspaceSettingsController): CliSettingsHost;
49
+ export declare function registerCliSettings(settings: WorkspaceSettingsController, host: CliSettingsHost): () => void;
@@ -0,0 +1,37 @@
1
+ import GeneralCliSettingsPage from "./GeneralCliSettingsPage.svelte";
2
+ const hosts = new WeakMap();
3
+ export function cliSettingsHost(controller) {
4
+ const host = hosts.get(controller);
5
+ if (!host)
6
+ throw new Error("CLI settings host is not bound");
7
+ return host.host;
8
+ }
9
+ export function registerCliSettings(settings, host) {
10
+ if (!hosts.has(settings) &&
11
+ settings.sections.some((section) => section.id === "general")) {
12
+ throw new Error("General settings already have an owner");
13
+ }
14
+ const entry = { host };
15
+ hosts.set(settings, entry);
16
+ const dispose = settings.registerSection({
17
+ id: "general",
18
+ title: "General",
19
+ navigationGroupId: "options",
20
+ order: 0,
21
+ page: GeneralCliSettingsPage,
22
+ searchEntries: [
23
+ {
24
+ id: "cli",
25
+ title: "Command line interface",
26
+ path: ["General", "Advanced"],
27
+ keywords: ["cli", "lapis", "PATH", "install", "terminal"],
28
+ },
29
+ ],
30
+ });
31
+ return () => {
32
+ if (hosts.get(settings) !== entry)
33
+ return;
34
+ dispose();
35
+ hosts.delete(settings);
36
+ };
37
+ }
@@ -0,0 +1,4 @@
1
+ /** Host-independent CLI settings; does not require a particular App API version. */
2
+ export { registerCliSettings } from "./cli-settings";
3
+ export type { CliSettingsHost, CliInstallationStatus, CliDownload, CliAccessHost, CliAccessStatus, } from "./cli-settings";
4
+ export { default as CliSettings } from "./CliSettings.svelte";
@@ -0,0 +1,3 @@
1
+ /** Host-independent CLI settings; does not require a particular App API version. */
2
+ export { registerCliSettings } from "./cli-settings";
3
+ export { default as CliSettings } from "./CliSettings.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lapis-notes/ui",
3
- "version": "0.1.10",
3
+ "version": "0.2.0",
4
4
  "description": "Public UI primitives required by Lapis Notes API consumers",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -61,6 +61,12 @@
61
61
  "svelte": "./dist/components/ui/*/index.js",
62
62
  "import": "./dist/components/ui/*/index.js",
63
63
  "default": "./dist/components/ui/*/index.js"
64
+ },
65
+ "./cli": {
66
+ "types": "./dist/cli/index.d.ts",
67
+ "svelte": "./dist/cli/index.js",
68
+ "import": "./dist/cli/index.js",
69
+ "default": "./dist/cli/index.js"
64
70
  }
65
71
  },
66
72
  "peerDependencies": {