@axium/client 0.43.0 → 0.44.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.
package/assets/theme.css CHANGED
@@ -30,6 +30,9 @@
30
30
 
31
31
  /* html is used so themes can use :root to override these if needed */
32
32
  html {
33
+ --color-scheme: dark;
34
+ color-scheme: var(--color-scheme);
35
+
33
36
  --bg-normal: hsl(0 0 var(--bg-light));
34
37
  --bg-menu: hsl(0 0 calc(var(--bg-light) - var(--light-step)));
35
38
  --bg-accent: hsl(var(--hue) 15 calc(var(--bg-light) + (var(--light-step) * 2)));
@@ -53,7 +56,7 @@ html {
53
56
 
54
57
  --green: hsl(140 50 50);
55
58
 
56
- --border-disabled: 1px solid hsl(0 5 calc(var(--bg-light) - var(--light-step)));
59
+ --border-disabled: 1px solid hsl(0 5 calc(var(--bg-light) + (var(--light-step) * 2)));
57
60
  --border-accent: 1px solid hsl(var(--hue) 10 calc(var(--bg-light) + (var(--light-step) * 3)));
58
61
  --border-alt: 1px solid var(--bg-alt);
59
62
  --border-strong: 1px solid hsl(var(--hue) 20 calc(var(--bg-light) + (var(--light-step) * 3)));
package/dist/themes.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const themeStyles = Object.assign(Object.create(null), {
2
2
  light: {
3
+ 'color-scheme': 'light',
3
4
  'fg-light': '10%',
4
5
  'bg-light': '70%',
5
6
  'light-step': '-6%',
@@ -15,6 +16,7 @@ export const themeStyles = Object.assign(Object.create(null), {
15
16
  'light-step': '2.5%',
16
17
  },
17
18
  beach: {
19
+ 'color-scheme': 'light',
18
20
  hue: '50',
19
21
  'fg-light': '30%',
20
22
  'bg-light': '60%',
@@ -95,6 +95,7 @@
95
95
  margin: -0.1em 0;
96
96
  font: inherit;
97
97
  color: inherit;
98
+ width: 100%;
98
99
  min-width: 0;
99
100
  flex: 1 1 auto;
100
101
  anchor-name: --inline-edit;
@@ -0,0 +1,98 @@
1
+ <script lang="ts">
2
+ import { text } from '@axium/client';
3
+ import type { SecretInfo, SecretStore } from '@axium/core';
4
+ import ClipboardCopy from './ClipboardCopy.svelte';
5
+ import FormDialog from './FormDialog.svelte';
6
+ import Icon from './Icon.svelte';
7
+
8
+ interface Props {
9
+ info: SecretInfo;
10
+ /** Title of the edit dialog */
11
+ label?: string;
12
+ /** Stores a new value, which allows editing when the secret is editable */
13
+ save?(value: string): unknown;
14
+ minLength?: number | null;
15
+ maxLength?: number | null;
16
+ }
17
+
18
+ const { info, label, save, minLength, maxLength }: Props = $props();
19
+
20
+ let dialog = $state<HTMLDialogElement>(),
21
+ saved = $state(false);
22
+
23
+ const source = $derived<SecretStore | null>(saved ? info.store : info.source);
24
+
25
+ async function submit(data: Record<string, FormDataEntryValue>) {
26
+ await save!(String(data.value));
27
+ saved = true;
28
+ dialog?.querySelector('form')?.reset();
29
+ }
30
+ </script>
31
+
32
+ <span class={['Secret', !source && 'unset']}>
33
+ <Icon
34
+ i={(source ?? info.store) == 'systemd' ? 'lock-keyhole' : 'file-lock'}
35
+ title={text(`Secret.${source ?? 'unset'}`, { id: info.id })}
36
+ />
37
+ <code>{info.id}</code>
38
+ <ClipboardCopy value={info.id} />
39
+ {#if save && info.editable}
40
+ <button type="button" title={text(source ? 'Secret.replace' : 'Secret.add')} onclick={() => dialog?.showModal()}>
41
+ <Icon i="pencil" />
42
+ </button>
43
+ <FormDialog bind:dialog clearOnCancel submitText={text('Secret.save')} {submit}>
44
+ <div class="Secret-heading">
45
+ {#if label}<strong>{label}</strong>{/if}
46
+ {#if source}<span>{text('Secret.replace_notice')}</span>{/if}
47
+ </div>
48
+ <textarea
49
+ name="value"
50
+ autocomplete="off"
51
+ autocapitalize="off"
52
+ spellcheck="false"
53
+ required
54
+ minlength={minLength || 1}
55
+ maxlength={maxLength ?? undefined}></textarea>
56
+ </FormDialog>
57
+ {/if}
58
+ </span>
59
+
60
+ <style>
61
+ .Secret {
62
+ display: inline-flex;
63
+ align-items: center;
64
+ gap: 0.5em;
65
+ min-width: 0;
66
+
67
+ &.unset > code {
68
+ color: var(--fg-disabled);
69
+ }
70
+
71
+ > button {
72
+ display: inline-flex;
73
+ padding: 0;
74
+ border: none;
75
+ background: transparent;
76
+ }
77
+ }
78
+
79
+ code {
80
+ overflow: hidden;
81
+ text-overflow: ellipsis;
82
+ }
83
+
84
+ .Secret-heading {
85
+ display: flex;
86
+ flex-direction: column;
87
+ gap: 0.25em;
88
+ }
89
+
90
+ textarea {
91
+ width: min(30em, 70vw);
92
+ field-sizing: content;
93
+ resize: none;
94
+ min-height: 3lh;
95
+ max-height: 10lh;
96
+ font-family: monospace;
97
+ }
98
+ </style>
package/lib/TopBar.svelte CHANGED
@@ -4,7 +4,7 @@
4
4
  import AppMenu from './AppMenu.svelte';
5
5
  import Icon from './Icon.svelte';
6
6
  import PWAIndicator from './PWAIndicator.svelte';
7
- import { currentContent } from './TopBarContent.svelte';
7
+ import { currentContent, topBarMiddle } from './TopBarContent.svelte';
8
8
  import UserMenu from './UserMenu.svelte';
9
9
  import Boundary from './Boundary.svelte';
10
10
 
@@ -19,9 +19,6 @@
19
19
  {#if content.icon}<Icon i={content.icon} --size="1.25em" />{/if}
20
20
  <span>{content.name}</span>
21
21
  </a>
22
- {#if content.children}
23
- <div class="middle" style:justify-content={content.align ?? 'center'}>{@render content.children()}</div>
24
- {/if}
25
22
  {:else}
26
23
  <a class="title" href="/">
27
24
  <img src="/favicon.svg" alt="" />
@@ -31,6 +28,8 @@
31
28
  </a>
32
29
  {/if}
33
30
 
31
+ <div class="middle" style:justify-content={content?.align ?? 'center'} {@attach topBarMiddle}></div>
32
+
34
33
  <div class="end">
35
34
  <PWAIndicator />
36
35
  {#if user}<AppMenu />{/if}
@@ -104,7 +103,7 @@
104
103
  padding: 0.5em 0.75em;
105
104
  }
106
105
 
107
- .TopBar:has(.middle) .title span {
106
+ .TopBar:has(.middle:not(:empty)) .title span {
108
107
  display: none;
109
108
  }
110
109
 
@@ -1,5 +1,6 @@
1
1
  <script module lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
+ import type { Attachment } from 'svelte/attachments';
3
4
 
4
5
  export interface TopBarContentProps {
5
6
  name: string;
@@ -12,11 +13,20 @@
12
13
  }
13
14
 
14
15
  let stack = $state.raw<TopBarContentProps[]>([]);
16
+ let middle = $state<HTMLElement>();
15
17
 
16
18
  /** The content registered by the most recently mounted `TopBarContent`. */
17
19
  export function currentContent(): TopBarContentProps | undefined {
18
20
  return stack.at(-1);
19
21
  }
22
+
23
+ /** Marks the element in the top bar that the current content's children are moved into. */
24
+ export const topBarMiddle: Attachment<HTMLElement> = element => {
25
+ middle = element;
26
+ return () => {
27
+ if (middle === element) middle = undefined;
28
+ };
29
+ };
20
30
  </script>
21
31
 
22
32
  <script lang="ts">
@@ -28,4 +38,19 @@
28
38
  onDestroy(() => {
29
39
  stack = stack.filter(entry => entry !== props);
30
40
  });
41
+
42
+ const moveToTopBar: Attachment<HTMLElement> = element => {
43
+ middle?.append(element);
44
+ return () => element.remove();
45
+ };
31
46
  </script>
47
+
48
+ {#if props.children && currentContent() === props && middle}
49
+ <div class="TopBarContent" {@attach moveToTopBar}>{@render props.children()}</div>
50
+ {/if}
51
+
52
+ <style>
53
+ .TopBarContent {
54
+ display: contents;
55
+ }
56
+ </style>
@@ -1,8 +1,12 @@
1
1
  <script lang="ts" module>
2
- import type { ZodPref } from '@axium/core';
2
+ import type { SecretInfo, ZodPref } from '@axium/core';
3
3
  import feature from '@axium/core/features';
4
4
  import * as locales from '@james-pre/locales';
5
5
 
6
+ /** Context holding a getter for information about secret fields, keyed by path */
7
+ export const secretsContext = Symbol('ZodForm:secrets');
8
+ export type SecretsGetter = () => Record<string, SecretInfo> | undefined;
9
+
6
10
  /** The schema a modifier or composite is rendered as */
7
11
  function inner(schema: ZodPref): ZodPref | undefined {
8
12
  switch (schema.type) {
@@ -48,6 +52,7 @@
48
52
 
49
53
  <script lang="ts">
50
54
  import { text } from '@axium/client';
55
+ import { getContext, setContext } from 'svelte';
51
56
  import { getByString } from 'utilium';
52
57
  import Icon from './Icon.svelte';
53
58
  import ZodInput from './ZodInput.svelte';
@@ -55,7 +60,8 @@
55
60
  interface Props {
56
61
  rootValue: any;
57
62
  schema: Extract<ZodPref, { type: 'object' | 'record' }>;
58
- updateValue(value: any): void;
63
+ /** May return a promise, which secret fields wait on to report errors */
64
+ updateValue(value: any): unknown;
59
65
  idPrefix?: string;
60
66
  /** Where the value is in `rootValue`, which renders the form as a section when set */
61
67
  path?: string;
@@ -63,6 +69,8 @@
63
69
  localeInfo?: locales.ZodInfo;
64
70
  /** Whether fields are ordered by key instead of by the schema */
65
71
  sort?: boolean;
72
+ /** Information about secret fields, keyed by path */
73
+ secrets?: Record<string, SecretInfo>;
66
74
  }
67
75
 
68
76
  let {
@@ -74,8 +82,12 @@
74
82
  label,
75
83
  localeInfo = locales.zod.get(schema),
76
84
  sort,
85
+ secrets,
77
86
  }: Props = $props();
78
87
 
88
+ const parentSecrets = getContext<SecretsGetter | undefined>(secretsContext);
89
+ setContext<SecretsGetter>(secretsContext, () => secrets ?? parentSecrets?.());
90
+
79
91
  /** A section's `enabled` field, which disables the rest of the section when false */
80
92
  const toggle = $derived.by((): ZodPref | undefined => {
81
93
  if (!path || schema.type != 'object') return;
@@ -90,9 +102,9 @@
90
102
  /** A copy of this object's value, replaced when a field changes since `rootValue` may not be deeply reactive */
91
103
  let value = $derived(valueAt(rootValue));
92
104
 
93
- function update(root: any) {
105
+ function update(root: any): unknown {
94
106
  value = valueAt(root);
95
- updateValue(root);
107
+ return updateValue(root);
96
108
  }
97
109
 
98
110
  /** Whether each sibling field named in `requires` has one of the values it lists */
@@ -3,11 +3,13 @@
3
3
  import type { ZodPref } from '@axium/core';
4
4
  import feature from '@axium/core/features';
5
5
  import * as locales from '@james-pre/locales';
6
+ import { getContext } from 'svelte';
6
7
  import type { HTMLInputAttributes } from 'svelte/elements';
7
8
  import { getByString, pick, setByString } from 'utilium';
8
9
  import { prettifyError, type z } from 'zod';
9
10
  import Icon from './Icon.svelte';
10
- import ZodForm from './ZodForm.svelte';
11
+ import Secret from './Secret.svelte';
12
+ import ZodForm, { secretsContext, type SecretsGetter } from './ZodForm.svelte';
11
13
  import ZodInput from './ZodInput.svelte';
12
14
 
13
15
  interface Props {
@@ -22,7 +24,7 @@
22
24
  optional?: boolean;
23
25
  readonly?: boolean;
24
26
  noLabel?: boolean | 'placeholder';
25
- updateValue(value: any): void;
27
+ updateValue(value: any): unknown;
26
28
  }
27
29
 
28
30
  let { rootValue = $bindable(), ...props }: Props = $props();
@@ -43,6 +45,8 @@
43
45
 
44
46
  const id = (idPrefix ? idPrefix + ':' : '') + path.replaceAll(' ', '_');
45
47
 
48
+ const secrets = getContext<SecretsGetter | undefined>(secretsContext);
49
+
46
50
  let value = $state<any>(getByString(rootValue, path));
47
51
 
48
52
  let lastRoot = rootValue;
@@ -97,15 +101,31 @@
97
101
  const oldValue = getByString(rootValue, path);
98
102
  if (val == oldValue) return;
99
103
 
100
- if (defaultValue == val) {
101
- const parts = path.split('.');
102
- const prop = parts.pop()!;
103
- delete getByString<Record<string, any>>(rootValue, parts.join('.'))![prop];
104
- } else setByString(rootValue, path, val);
104
+ if (defaultValue == val) removeValue();
105
+ else setByString(rootValue, path, val);
105
106
 
106
107
  updateValue(rootValue);
107
108
  }
108
109
 
110
+ function removeValue() {
111
+ const parts = path.split('.');
112
+ const prop = parts.pop()!;
113
+ delete getByString<Record<string, any>>(rootValue, parts.join('.'))![prop];
114
+ }
115
+
116
+ /** Sends a new secret, then drops it from `rootValue` so later updates don't send it again */
117
+ async function saveSecret(secret: string) {
118
+ const result = schema.safeParse(secret);
119
+ if (!result.success) throw prettifyError(result.error);
120
+
121
+ setByString(rootValue, path, result.data);
122
+ try {
123
+ await updateValue(rootValue);
124
+ } finally {
125
+ removeValue();
126
+ }
127
+ }
128
+
109
129
  const oninput = onchange;
110
130
 
111
131
  function isSchemaPart(part: unknown): part is z.core.$ZodType {
@@ -189,6 +209,17 @@
189
209
 
190
210
  {#if localeInfo?.feature && !feature(localeInfo.feature)}
191
211
  <meta data-feature={localeInfo.feature} />
212
+ {:else if schema.type == 'string' && localeInfo?.secret}
213
+ <div class={['ZodInput', noLabel && 'no-label']}>
214
+ {@render labelFor(id)}
215
+ <Secret
216
+ info={secrets?.()?.[path] ?? { id: path, source: null, store: 'file', editable: true }}
217
+ label={labelText}
218
+ save={readonly ? undefined : saveSecret}
219
+ minLength={schema.minLength}
220
+ maxLength={schema.maxLength}
221
+ />
222
+ </div>
192
223
  {:else if schema.type == 'string' && localeInfo?.multiline}
193
224
  <div class={['ZodInput', 'multiline', noLabel && 'no-label']}>
194
225
  {@render labelFor(id)}
@@ -482,5 +513,12 @@
482
513
  > label.checkbox {
483
514
  justify-self: start;
484
515
  }
516
+
517
+ @media (width < 700px) {
518
+ &:not(:has(> label.checkbox)) {
519
+ grid-template-columns: minmax(0, 1fr);
520
+ row-gap: 0.25em;
521
+ }
522
+ }
485
523
  }
486
524
  </style>
@@ -117,7 +117,7 @@ export function contextMenu(...menuItems: ContextMenuEntry[] | [() => ContextMen
117
117
  if (!_forcePopover) return;
118
118
  e.stopPropagation();
119
119
  e.preventDefault();
120
- menu.togglePopover();
120
+ if (!menu.matches(':popover-open')) menu.showPopover();
121
121
  _forcePopover = false;
122
122
  };
123
123
 
package/lib/index.ts CHANGED
@@ -22,6 +22,7 @@ export { default as ProgressBar } from './ProgressBar.svelte';
22
22
  export { default as ProgressRing } from './ProgressRing.svelte';
23
23
  export { default as PWAIndicator } from './PWAIndicator.svelte';
24
24
  export { default as Register } from './Register.svelte';
25
+ export { default as Secret } from './Secret.svelte';
25
26
  export { default as SessionList } from './SessionList.svelte';
26
27
  export { default as SidebarLayout } from './SidebarLayout.svelte';
27
28
  export { default as TopBar } from './TopBar.svelte';
package/locales/en.json CHANGED
@@ -65,6 +65,15 @@
65
65
  "latest": "Latest",
66
66
  "upgrade": "<span class=\"version\">{latest}</span> available"
67
67
  },
68
+ "Secret": {
69
+ "add": "Set",
70
+ "file": "Stored in the secrets file. Change it with `axium secret set {id}`.",
71
+ "replace": "Replace",
72
+ "replace_notice": "This replaces the current value.",
73
+ "save": "Save",
74
+ "systemd": "Stored as a systemd credential. Change it with `axium secret set {id}`.",
75
+ "unset": "Not set. Store it with `axium secret set {id}`."
76
+ },
68
77
  "ZodInput": {
69
78
  "experimental": "Experimental",
70
79
  "invalid_type": "Invalid input type: {type}"
@@ -206,6 +215,7 @@
206
215
  "config": {
207
216
  "active": "Active Configuration",
208
217
  "loaded_files": "Loaded Files",
218
+ "secrets": "Secrets",
209
219
  "title": "Admin — Configuration"
210
220
  },
211
221
  "dashboard": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.43.0",
3
+ "version": "0.44.1",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -50,7 +50,7 @@
50
50
  "build": "tsc"
51
51
  },
52
52
  "peerDependencies": {
53
- "@axium/core": ">=0.45.0",
53
+ "@axium/core": ">=0.46.0",
54
54
  "@james-pre/locales": "^1.0.0",
55
55
  "ioium": "^1.7.0",
56
56
  "semver": "^7.7.4",