@axium/client 0.38.0 → 0.39.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.
@@ -0,0 +1,15 @@
1
+ <svg width="512" height="512" xmlns="http://www.w3.org/2000/svg">
2
+ <defs>
3
+ <style>
4
+ rect {
5
+ transform-box: fill-box;
6
+ transform-origin: center;
7
+ fill: #ccc;
8
+ }
9
+ </style>
10
+ </defs>
11
+ <rect style="fill: #cdc" x="208" y="256" width="96" height="20" rx="10" />
12
+ <rect style="fill: #ecc" x="244" y="288" width="24" height="128" rx="12" />
13
+ <rect x="184" y="96" width="16" height="320" rx="8" transform="rotate(20)" />
14
+ <rect x="312" y="96" width="16" height="320" rx="8" transform="rotate(-20)" />
15
+ </svg>
package/assets/styles.css CHANGED
@@ -228,7 +228,6 @@ div.success {
228
228
  align-items: center;
229
229
  flex-direction: column;
230
230
  gap: 1em;
231
- overflow-y: scroll;
232
231
  }
233
232
 
234
233
  .danger {
@@ -413,9 +412,9 @@ h6 {
413
412
  }
414
413
 
415
414
  #toasts {
416
- position: absolute;
415
+ position: fixed;
417
416
  right: 1em;
418
- top: 1em;
417
+ top: calc(var(--top-bar-height, 0px) + 1em);
419
418
  width: 0;
420
419
  height: 0;
421
420
  overflow: visible;
@@ -1,5 +1,5 @@
1
1
  import { persistFeaturesTo } from '@axium/core/node/features';
2
- import { loadPlugin } from '@axium/core/node/plugins';
2
+ import { loadPlugin, trackPluginLoading } from '@axium/core/node/plugins';
3
3
  import { Manager as ConfigManager } from '@james-pre/config';
4
4
  import { debug, warn } from 'ioium';
5
5
  import * as io from 'ioium/node';
@@ -23,6 +23,10 @@ export function resolveServerURL(server) {
23
23
  debug('Resolved server URL: ' + url.href);
24
24
  return url.href;
25
25
  }
26
+ async function loadPlugins(path, options) {
27
+ for (const plugin of config.plugins ?? [])
28
+ await loadPlugin('client', plugin, path, options);
29
+ }
26
30
  export const configManager = new ConfigManager(z.looseObject({
27
31
  token: z.base64url().nullish(),
28
32
  server: z.url().nullish(),
@@ -35,11 +39,7 @@ export const configManager = new ConfigManager(z.looseObject({
35
39
  if (config.token)
36
40
  setToken(config.token);
37
41
  })
38
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
39
- .on('post_load', async (path, file, options) => {
40
- for (const plugin of config.plugins ?? [])
41
- await loadPlugin('client', plugin, path, options.plugins);
42
- })
42
+ .on('post_load', (path, file, options) => trackPluginLoading(loadPlugins(path, options.plugins)))
43
43
  .on('load_error', (path, stage, error) => io.warn('Failed to load config:', io.errorText(error)))
44
44
  .on('write', path => io.debug('Saved config to', path));
45
45
  export const config = configManager.data;
package/dist/cli/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  #! /usr/bin/env node
2
2
  import { createPluginCommand } from '@axium/core/node';
3
+ import { waitForPlugins } from '@axium/core/node/plugins';
3
4
  import { _findPlugin, plugins } from '@axium/core/plugins';
4
5
  import { configCommand } from '@james-pre/config/cli';
5
6
  import { Service } from '@james-pre/systemd';
@@ -24,10 +25,11 @@ if (debug)
24
25
  useUserAgent(clientUA);
25
26
  const loadOptions = { plugins: { safe } };
26
27
  configManager.loadDefaults(loadOptions);
28
+ await waitForPlugins();
27
29
  cache.load();
28
30
  process.on('SIGHUP', () => {
29
31
  io.info('Reloading configuration due to SIGHUP.');
30
- configManager.reloadFiles();
32
+ configManager.reloadFiles({ plugins: { safe, reload: true } });
31
33
  });
32
34
  program
33
35
  .version($pkg.version)
@@ -0,0 +1,6 @@
1
+ export interface ErrorLike {
2
+ message: string;
3
+ stack?: string;
4
+ }
5
+ export declare function title(error: ErrorLike | string, titleId?: string): string;
6
+ export declare function message(error: ErrorLike | string, id?: string): string;
package/dist/error.js ADDED
@@ -0,0 +1,14 @@
1
+ import { text } from './locales.js';
2
+ export function title(error, titleId) {
3
+ const message = typeof error == 'string' ? error : error.message;
4
+ if (message?.includes('NetworkError'))
5
+ return text('error.network.title');
6
+ const [defaultTitle] = message?.split('\n') || [];
7
+ return titleId ? text(titleId, { $default: defaultTitle }) : defaultTitle;
8
+ }
9
+ export function message(error, id) {
10
+ const message = typeof error == 'string' ? error : error.message;
11
+ if (message.includes('NetworkError'))
12
+ return text('error.network.message');
13
+ return id ? text(id, { $default: message }) : message;
14
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './access.js';
2
2
  export * from './cache.js';
3
+ export * from './metadata.js';
3
4
  export * from './locales.js';
4
5
  export * as preferences from './preferences.js';
5
6
  export * from './requests.js';
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './access.js';
2
2
  export * from './cache.js';
3
+ export * from './metadata.js';
3
4
  export * from './locales.js';
4
5
  export * as preferences from './preferences.js';
5
6
  export * from './requests.js';
@@ -0,0 +1,2 @@
1
+ import type { InstanceMetadata } from '@axium/core';
2
+ export declare function instanceMetadata(): Promise<InstanceMetadata>;
@@ -0,0 +1,6 @@
1
+ import { fetchAPI } from './requests.js';
2
+ let _metadata;
3
+ export async function instanceMetadata() {
4
+ _metadata ||= await fetchAPI('GET', 'metadata');
5
+ return _metadata;
6
+ }
package/dist/user.d.ts CHANGED
@@ -10,6 +10,10 @@ export declare function loginByUsername(username: string): Promise<NewSessionRes
10
10
  export declare function getCurrentSession(): Promise<Session & {
11
11
  user: User;
12
12
  }>;
13
+ /** Get the current session, or `null` if there isn't a valid one (e.g. missing or expired) */
14
+ export declare function currentSession(): Promise<(Session & {
15
+ user: User;
16
+ }) | null>;
13
17
  export declare function extendCurrentSession(userId: string): Promise<void>;
14
18
  export declare function getSessions(userId: string): Promise<Session[]>;
15
19
  export declare function logout(userId: string, ...sessionId: string[]): Promise<Session[]>;
package/dist/user.js CHANGED
@@ -26,6 +26,18 @@ export async function getCurrentSession() {
26
26
  _currentSession ||= await fetchAPI('GET', 'session');
27
27
  return _currentSession;
28
28
  }
29
+ /** Get the current session, or `null` if there isn't a valid one (e.g. missing or expired) */
30
+ export async function currentSession() {
31
+ try {
32
+ _currentSession ||= await fetchAPI('GET', 'session');
33
+ return _currentSession;
34
+ }
35
+ catch (e) {
36
+ if (typeof e == 'object' && e !== null && 'status' in e && e.status === 401)
37
+ return null;
38
+ throw e;
39
+ }
40
+ }
29
41
  export async function extendCurrentSession(userId) {
30
42
  const optionsJSON = await fetchAPI('PUT', 'users/:id/auth', { type: 'extend_session' }, userId);
31
43
  const response = await startAuthentication({ optionsJSON });
@@ -1 +1,2 @@
1
1
  export declare function isMobile(): boolean;
2
+ export declare function vibrate(duration?: number): void;
@@ -2,3 +2,9 @@ const width = matchMedia('(width <= 700px)');
2
2
  export function isMobile() {
3
3
  return width.matches;
4
4
  }
5
+ const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
6
+ export function vibrate(duration = 10) {
7
+ if (reducedMotion.matches)
8
+ return;
9
+ navigator.vibrate?.(duration);
10
+ }
@@ -1,13 +1,12 @@
1
- /* eslint-disable @typescript-eslint/no-misused-promises */
2
1
  import { base, build, files, version } from '$service-worker';
3
2
  const cacheName = 'axium@' + version;
4
- const versionFile = `${base}/_app/version.json`;
5
- const precache = new Set([...build, ...files]);
3
+ const versionFile = `${base}/_app/version.json`, shell = `${base}/_axium/shell`;
4
+ const precache = new Set([...build, ...files, shell]);
6
5
  async function install() {
7
6
  let error = null;
8
7
  try {
9
8
  const cache = await caches.open(cacheName);
10
- await Promise.all(Array.from(precache).map(url => cache.add(new Request(url, files.includes(url) ? { cache: 'no-cache' } : {}))));
9
+ await Promise.all(Array.from(precache).map(url => cache.add(new Request(url, build.includes(url) ? {} : { cache: 'no-cache' }))));
11
10
  }
12
11
  catch (e) {
13
12
  error = e instanceof Error ? e.message : String(e);
@@ -29,26 +28,37 @@ async function activate() {
29
28
  client.postMessage({ type: 'update', version, base });
30
29
  }
31
30
  globalThis.addEventListener('activate', event => event.waitUntil(activate()));
32
- globalThis.addEventListener('fetch', async (event) => {
31
+ async function maybeCached(request) {
32
+ const { pathname } = new URL(request.url);
33
+ const cache = await caches.open(cacheName);
34
+ const hit = await cache.match(pathname);
35
+ if (hit)
36
+ return hit;
37
+ const response = await fetch(request);
38
+ if (response.ok && response.status != 206)
39
+ await cache.put(pathname, response.clone());
40
+ return response;
41
+ }
42
+ globalThis.addEventListener('fetch', event => {
33
43
  const { request } = event;
34
44
  if (request.method != 'GET')
35
45
  return;
36
46
  const url = new URL(request.url);
37
- if (url.origin != location.origin)
38
- return;
39
- if (url.pathname == versionFile)
47
+ if (url.origin != location.origin || url.pathname == versionFile)
40
48
  return;
49
+ if (request.mode == 'navigate') {
50
+ const res = fetch(request).catch(async (e) => {
51
+ const hit = await caches.match(shell, { cacheName });
52
+ if (hit)
53
+ return hit;
54
+ throw e;
55
+ });
56
+ return event.respondWith(res);
57
+ }
41
58
  // @todo API responses, `/raw`.
42
59
  if (!precache.has(url.pathname))
43
60
  return;
44
- const cache = await caches.open(cacheName);
45
- const hit = await cache.match(url.pathname);
46
- if (hit)
47
- return event.respondWith(hit);
48
- const response = await fetch(request);
49
- if (response.ok && response.status != 206)
50
- await cache.put(url.pathname, response.clone());
51
- return event.respondWith(response);
61
+ event.respondWith(maybeCached(request));
52
62
  });
53
63
  globalThis.addEventListener('message', (event) => {
54
64
  if (!event.data)
@@ -1,35 +1,80 @@
1
1
  <script lang="ts">
2
2
  import { text } from '@axium/client/locales';
3
3
  import { fetchAPI } from '@axium/client/requests';
4
+ import feature from '@axium/core/features';
5
+ import Boundary from './Boundary.svelte';
4
6
  import Icon from './Icon.svelte';
5
7
  import Popover from './Popover.svelte';
6
8
  </script>
7
9
 
8
- <Popover>
10
+ <Popover class="mobile-top">
9
11
  {#snippet toggle()}
10
- <button style:display="contents">
12
+ <button class="AppMenu reset" aria-label={text('AppMenu.label')}>
11
13
  <Icon i="grid" --size="1.5em" />
12
14
  </button>
13
15
  {/snippet}
14
16
 
15
- {#await fetchAPI('GET', 'apps')}
16
- <i>{text('generic.loading')}</i>
17
- {:then apps}
18
- {#each apps as app}
19
- <a class="menu-item" href="/{app.id}">
20
- {#if app.image}
21
- <img src={app.image} alt={app.name} width="1em" height="1em" />
22
- {:else if app.icon}
23
- <Icon i={app.icon} --size="1.5em" />
24
- {:else}
25
- <Icon i="image-circle-xmark" --size="1.5em" />
26
- {/if}
27
- <span>{text('app_name.' + app.id, { $default: app.name })}</span>
28
- </a>
29
- {:else}
30
- <i>{text('AppMenu.none')}</i>
31
- {/each}
32
- {:catch}
33
- <i>{text('AppMenu.failed')}</i>
34
- {/await}
17
+ <Boundary pending="generic.loading" error="AppMenu.failed" inline>
18
+ <div class={['AppList', feature('app-list-is-grid') && 'grid']}>
19
+ {#each await fetchAPI('GET', 'apps') as app}
20
+ <a class="menu-item" href="/{app.id}">
21
+ {#if app.image}
22
+ <img src={app.image} alt={app.name} />
23
+ {:else if app.icon}
24
+ <Icon i={app.icon} --size="1.5em" />
25
+ {:else}
26
+ <Icon i="image-circle-xmark" --size="1.5em" />
27
+ {/if}
28
+ <span>{text('app_name.' + app.id, { $default: app.name || '(unknown)' })}</span>
29
+ </a>
30
+ {:else}
31
+ <i>{text('AppMenu.none')}</i>
32
+ {/each}
33
+ </div>
34
+ </Boundary>
35
35
  </Popover>
36
+
37
+ <style>
38
+ .AppMenu {
39
+ display: inline-flex;
40
+ }
41
+
42
+ .AppList {
43
+ display: flex;
44
+ flex-direction: column;
45
+ gap: 0.1em;
46
+
47
+ img {
48
+ width: 1.5em;
49
+ height: 1.5em;
50
+ }
51
+
52
+ &.grid {
53
+ display: grid;
54
+ grid-template-columns: repeat(3, 6.5em);
55
+ gap: 0.25em;
56
+
57
+ .menu-item {
58
+ flex-direction: column;
59
+ justify-content: center;
60
+ gap: 0.5em;
61
+ padding: 0.75em 0.25em;
62
+ text-align: center;
63
+ font-size: 0.9em;
64
+
65
+ :global(.Icon) {
66
+ --size: 2em;
67
+ }
68
+ }
69
+
70
+ img {
71
+ width: 2em;
72
+ height: 2em;
73
+ }
74
+
75
+ @media (width < 700px) {
76
+ grid-template-columns: repeat(3, 1fr);
77
+ }
78
+ }
79
+ }
80
+ </style>
@@ -0,0 +1,49 @@
1
+ <script lang="ts">
2
+ import * as err from '@axium/client/error';
3
+ import type { Snippet } from 'svelte';
4
+ import { text } from '@axium/client/locales';
5
+
6
+ interface Props {
7
+ children?: Snippet;
8
+ pending?: Snippet | string;
9
+ inline?: boolean;
10
+ showStack?: boolean;
11
+ /** Translation key */
12
+ error?: string;
13
+ }
14
+
15
+ const { children, pending: loading, inline, showStack, error: errorKey }: Props = $props();
16
+ </script>
17
+
18
+ <svelte:boundary onerror={e => console.error(e)}>
19
+ {@render children?.()}
20
+
21
+ {#snippet pending()}
22
+ {#if typeof loading == 'string'}
23
+ <span>{text(loading)}</span>
24
+ {:else}
25
+ {@render loading?.()}
26
+ {/if}
27
+ {/snippet}
28
+
29
+ {#snippet failed(error: any)}
30
+ {const message = err.message(error, errorKey)}
31
+ {#if inline}
32
+ <p class="error boundary">{message}</p>
33
+ {:else}
34
+ <div class="error boundary">
35
+ <p>{message}</p>
36
+
37
+ {#if error.stack && showStack}
38
+ <pre>{error.stack}</pre>
39
+ {/if}
40
+ </div>
41
+ {/if}
42
+ {/snippet}
43
+ </svelte:boundary>
44
+
45
+ <style>
46
+ div.boundary.error {
47
+ margin: 1em;
48
+ }
49
+ </style>
@@ -0,0 +1,34 @@
1
+ <script lang="ts">
2
+ import { page } from '$app/state';
3
+ import { title, message } from '@axium/client/error';
4
+ import { text } from '@axium/client/locales';
5
+
6
+ interface PageError {
7
+ message: string;
8
+ status?: number;
9
+ stack?: string;
10
+ }
11
+
12
+ const error: PageError = page.error || { message: 'Unknown Error' };
13
+
14
+ const showStack = page.url.searchParams.has('stack');
15
+ </script>
16
+
17
+ <svelte:head>
18
+ <title>Error — {title(error)}</title>
19
+ </svelte:head>
20
+
21
+ <div class="error">
22
+ <h2>{message(error)}</h2>
23
+ {#if error.stack && showStack}
24
+ <pre>{error.stack}</pre>
25
+ {/if}
26
+ </div>
27
+
28
+ <button onclick={() => location.reload()}>{text('error.Page.reload')}</button>
29
+
30
+ <style>
31
+ .error {
32
+ margin: 1em;
33
+ }
34
+ </style>
@@ -34,7 +34,7 @@
34
34
  id={'logout-session:' + session.id}
35
35
  submit={async () => {
36
36
  await logout(user.id, session.id);
37
- sessions.splice(sessions.indexOf(session), 1);
37
+ sessions = sessions.filter(s => s.id != session.id);
38
38
  if (session.id == currentSession?.id) window.location.href = '/';
39
39
  }}
40
40
  submitText={text('generic.logout')}
@@ -44,7 +44,7 @@
44
44
  .sidebar-container {
45
45
  display: grid;
46
46
  grid-template-columns: 15em 1fr;
47
- height: 100%;
47
+ min-height: calc(100dvh - var(--top-bar-height, 0px));
48
48
 
49
49
  @media (width < 700px) {
50
50
  grid-template-columns: 1fr;
@@ -57,14 +57,20 @@
57
57
  display: inline-flex;
58
58
  flex-direction: column;
59
59
  gap: 0.5em;
60
- padding: 1em;
61
- padding-left: 0;
60
+ padding: 0 1em 1em 0;
62
61
  border-radius: 0 1em 1em 0;
62
+ position: sticky;
63
+ top: var(--top-bar-height, 0px);
64
+ align-self: start;
65
+ height: calc(100dvh - var(--top-bar-height, 0px));
66
+ overflow-y: auto;
63
67
 
64
68
  @media (width < 700px) {
65
69
  position: fixed;
66
70
  grid-column: unset;
67
71
  inset: auto 0 0;
72
+ height: auto;
73
+ overflow-y: visible;
68
74
  border-radius: 1em;
69
75
  display: flex;
70
76
  flex-direction: row;
@@ -105,8 +111,8 @@
105
111
  .sidebar-content {
106
112
  grid-column: 2;
107
113
  padding: 1em;
108
- overflow-x: hidden;
109
- overflow-y: scroll;
114
+ min-width: 0;
115
+ overflow-x: clip;
110
116
 
111
117
  @media (width < 700px) {
112
118
  padding-bottom: 5em;
@@ -0,0 +1,136 @@
1
+ <script lang="ts">
2
+ import { instanceMetadata } from '@axium/client';
3
+ import type { UserPublic } from '@axium/core/user';
4
+ import AppMenu from './AppMenu.svelte';
5
+ import Icon from './Icon.svelte';
6
+ import PWAIndicator from './PWAIndicator.svelte';
7
+ import { currentContent } from './TopBarContent.svelte';
8
+ import UserMenu from './UserMenu.svelte';
9
+ import Boundary from './Boundary.svelte';
10
+
11
+ const { user }: { user?: UserPublic } = $props();
12
+
13
+ const content = $derived(currentContent());
14
+ </script>
15
+
16
+ <header class="TopBar">
17
+ {#if content}
18
+ <a class="title" href={content.href}>
19
+ {#if content.icon}<Icon i={content.icon} --size="1.25em" />{/if}
20
+ <span>{content.name}</span>
21
+ </a>
22
+ {#if content.children}
23
+ <div class="middle" style:justify-content={content.align ?? 'center'}>{@render content.children()}</div>
24
+ {/if}
25
+ {:else}
26
+ <a class="title" href="/">
27
+ <img src="/favicon.svg" alt="" />
28
+ <Boundary inline>
29
+ {#await instanceMetadata() then { name }}<span>{name}</span>{/await}
30
+ </Boundary>
31
+ </a>
32
+ {/if}
33
+
34
+ <div class="end">
35
+ <PWAIndicator />
36
+ {#if user}<AppMenu />{/if}
37
+ <UserMenu {user} />
38
+ </div>
39
+ </header>
40
+
41
+ <style>
42
+ .TopBar {
43
+ position: sticky;
44
+ top: 0;
45
+ z-index: 20;
46
+ height: var(--top-bar-height);
47
+ display: flex;
48
+ align-items: center;
49
+ gap: 1em;
50
+ padding: 0.5em 1em;
51
+ background-color: var(--bg-normal);
52
+ }
53
+
54
+ @supports (animation-timeline: scroll()) {
55
+ .TopBar {
56
+ animation: top-bar-shadow linear both;
57
+ animation-timeline: scroll(root);
58
+ animation-range: 0 2em;
59
+ }
60
+ }
61
+
62
+ @keyframes top-bar-shadow {
63
+ to {
64
+ box-shadow: 0 0.25em 0.75em -0.25em #0008;
65
+ }
66
+ }
67
+
68
+ .title {
69
+ display: inline-flex;
70
+ align-items: center;
71
+ gap: 0.5em;
72
+ min-width: 0;
73
+ font-size: 1.25em;
74
+ white-space: nowrap;
75
+
76
+ span {
77
+ overflow: hidden;
78
+ text-overflow: ellipsis;
79
+ }
80
+
81
+ img {
82
+ width: 1.25em;
83
+ height: 1.25em;
84
+ }
85
+ }
86
+
87
+ .middle {
88
+ flex: 1 1 auto;
89
+ min-width: 0;
90
+ display: flex;
91
+ }
92
+
93
+ .end {
94
+ margin-left: auto;
95
+ flex-shrink: 0;
96
+ display: flex;
97
+ align-items: center;
98
+ gap: 1em;
99
+ }
100
+
101
+ @media (width < 700px) {
102
+ .TopBar {
103
+ gap: 0.75em;
104
+ padding: 0.5em 0.75em;
105
+ }
106
+
107
+ .TopBar:has(.middle) .title span {
108
+ display: none;
109
+ }
110
+
111
+ .end {
112
+ gap: 0.75em;
113
+ }
114
+ }
115
+
116
+ @media (width >= 700px) {
117
+ .end :global(:popover-open) {
118
+ left: auto;
119
+ right: anchor(right);
120
+ top: calc(anchor(bottom) + 0.5em);
121
+ position-try-fallbacks: none;
122
+ width: max-content;
123
+ height: fit-content;
124
+ }
125
+ }
126
+
127
+ :global {
128
+ html:has(.TopBar) {
129
+ --top-bar-height: 3.5rem;
130
+ }
131
+
132
+ body:has(.TopBar) {
133
+ margin: 0;
134
+ }
135
+ }
136
+ </style>
@@ -0,0 +1,31 @@
1
+ <script module lang="ts">
2
+ import type { Snippet } from 'svelte';
3
+
4
+ export interface TopBarContentProps {
5
+ name: string;
6
+ icon?: string;
7
+ href: string;
8
+ /** How to align the content. Defaults to centered. */
9
+ align?: 'left' | 'center' | 'right';
10
+ /** Rendered in the middle of the top bar, e.g. a search bar. */
11
+ children?: Snippet;
12
+ }
13
+
14
+ let stack = $state.raw<TopBarContentProps[]>([]);
15
+
16
+ /** The content registered by the most recently mounted `TopBarContent`. */
17
+ export function currentContent(): TopBarContentProps | undefined {
18
+ return stack.at(-1);
19
+ }
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import { onDestroy } from 'svelte';
24
+
25
+ const props: TopBarContentProps = $props();
26
+
27
+ stack = [...stack, props];
28
+ onDestroy(() => {
29
+ stack = stack.filter(entry => entry !== props);
30
+ });
31
+ </script>
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { fetchAPI, text } from '@axium/client';
2
+ import { text } from '@axium/client';
3
3
  import type { UserPublic } from '@axium/core/user';
4
4
  import Icon from './Icon.svelte';
5
5
  import Logout from './Logout.svelte';
@@ -12,12 +12,19 @@
12
12
  {#if user}
13
13
  <Popover class="mobile-top">
14
14
  {#snippet toggle()}
15
- <div class="UserMenu toggle">
15
+ <button class="UserMenu reset" aria-label={user.name}>
16
16
  <UserPFP {user} />
17
- {user.name}
18
- </div>
17
+ </button>
19
18
  {/snippet}
20
19
 
20
+ <div class="UserMenu-header">
21
+ <UserPFP {user} --size="2.5em" />
22
+ <div>
23
+ <strong>{user.name}</strong>
24
+ {#if user.email}<span class="subtle">{user.email}</span>{/if}
25
+ </div>
26
+ </div>
27
+
21
28
  <a class="menu-item" href="/account">
22
29
  <Icon i="user" --size="1.5em" />
23
30
  <span>{text('UserMenu.account')}</span>
@@ -30,27 +37,6 @@
30
37
  </a>
31
38
  {/if}
32
39
 
33
- {#await fetchAPI('GET', 'apps')}
34
- <i>{text('generic.loading')}</i>
35
- {:then apps}
36
- {#each apps as app}
37
- <a class="menu-item" href="/{app.id}">
38
- {#if app.image}
39
- <img src={app.image} alt={app.name} width="1em" height="1em" />
40
- {:else if app.icon}
41
- <Icon i={app.icon} --size="1.5em" />
42
- {:else}
43
- <Icon i="image-circle-xmark" --size="1.5em" />
44
- {/if}
45
- <span>{text('app_name.' + app.id, { $default: app.name })}</span>
46
- </a>
47
- {:else}
48
- <i>{text('AppMenu.none')}</i>
49
- {/each}
50
- {:catch}
51
- <i>{text('AppMenu.failed')}</i>
52
- {/await}
53
-
54
40
  <button class="menu-item danger reset" command="show-modal" commandfor="logout">
55
41
  <Icon i="right-from-bracket" --size="1.5em" />
56
42
  <span>{text('generic.logout')}</span>
@@ -59,30 +45,42 @@
59
45
 
60
46
  <Logout />
61
47
  {:else}
62
- <div class="UserMenu login">
63
- <a href="/login?after={location.pathname}">Login</a>
64
- </div>
48
+ <a class="UserMenu login" href="/login?after={location.pathname}">{text('UserMenu.login')}</a>
65
49
  {/if}
66
50
 
67
51
  <style>
68
52
  .UserMenu {
53
+ display: inline-flex;
54
+ border-radius: 50%;
55
+
56
+ :global(.UserPFP) {
57
+ margin: 0;
58
+ }
59
+ }
60
+
61
+ .login {
69
62
  border-radius: 0.5em;
70
- padding: 0.5em;
63
+ padding: 0.5em 0.75em;
71
64
  border: var(--border-accent);
72
- cursor: pointer;
73
65
  background-color: var(--bg-alt);
74
66
  }
75
67
 
76
- :global(.UserMenu + div:popover-open) {
77
- cursor: default;
68
+ .UserMenu-header {
69
+ display: flex;
70
+ align-items: center;
71
+ gap: 0.75em;
72
+ padding: 0.5em 0.75em 0.75em;
73
+ margin-bottom: 0.25em;
74
+ border-bottom: var(--border-accent);
75
+
76
+ :global(.UserPFP) {
77
+ margin: 0;
78
+ }
78
79
 
79
- @media (width > 700px) {
80
- position: fixed;
81
- left: unset;
82
- right: anchor(right);
83
- top: calc(anchor(bottom) + 0.5em);
84
- width: fit-content;
85
- height: fit-content;
80
+ div {
81
+ display: flex;
82
+ flex-direction: column;
83
+ min-width: 0;
86
84
  }
87
85
  }
88
86
  </style>
@@ -1,4 +1,4 @@
1
- import { isMobile } from '@axium/client/web';
1
+ import { vibrate, isMobile } from '@axium/client/web';
2
2
  import { mount, unmount } from 'svelte';
3
3
  import type { Attachment } from 'svelte/attachments';
4
4
  import Icon from '../Icon.svelte';
@@ -87,7 +87,10 @@ export function contextMenu(...menuItems: ContextMenuEntry[] | [() => ContextMen
87
87
  menu.showPopover();
88
88
  _forcePopover = true;
89
89
 
90
- if (isMobile()) return;
90
+ if (isMobile()) {
91
+ vibrate();
92
+ return;
93
+ }
91
94
 
92
95
  const x = e.clientX;
93
96
  const y = e.clientY;
@@ -18,20 +18,31 @@ export function dynamicRows(max: number = 40, min: number = 3): Attachment<HTMLT
18
18
  element.style.resize = 'none';
19
19
  element.style.fieldSizing = 'content';
20
20
  element.style.height = 'max-content';
21
- element.style.overflowY = 'scroll';
21
+ element.style.overflowY = 'auto';
22
22
 
23
+ /** Counts wrapped lines as well as explicit ones. */
23
24
  function update() {
24
- if (!element.value) return;
25
- element.rows = Math.max(Math.min(element.value.split('\n').length, max), min);
25
+ element.rows = 2;
26
+ const twoRows = element.clientHeight;
27
+ element.rows = 1;
28
+ const oneRow = element.clientHeight;
29
+ const lines = 1 + Math.round((element.scrollHeight - oneRow) / (twoRows - oneRow));
30
+ element.rows = Math.max(Math.min(lines, max), min);
26
31
  }
27
32
 
28
- if (!navigator.userAgent.includes('Firefox')) return;
33
+ if (CSS.supports('field-sizing', 'content')) return;
29
34
  update();
30
35
  element.addEventListener('input', update);
31
- element.addEventListener('keyup', update);
36
+ let width = element.clientWidth;
37
+ const resize = new ResizeObserver(() => {
38
+ if (element.clientWidth == width) return;
39
+ width = element.clientWidth;
40
+ update();
41
+ });
42
+ resize.observe(element);
32
43
  return () => {
33
44
  element.removeEventListener('input', update);
34
- element.removeEventListener('keyup', update);
45
+ resize.disconnect();
35
46
  };
36
47
  };
37
48
  }
package/lib/index.ts CHANGED
@@ -3,10 +3,12 @@ export { default as AppMenu } from './AppMenu.svelte';
3
3
  export { default as AppPreferences } from './AppPreferences.svelte';
4
4
  export { default as AppPreferencesDialog } from './AppPreferencesDialog.svelte';
5
5
  export { default as Audio } from './Audio.svelte';
6
+ export { default as Boundary } from './Boundary.svelte';
6
7
  export { default as ColorPicker } from './ColorPicker.svelte';
7
8
  export { default as ClipboardCopy } from './ClipboardCopy.svelte';
8
9
  export { default as Discovery } from './Discovery.svelte';
9
10
  export * as discovery from './Discovery.svelte';
11
+ export { default as ErrorPage } from './ErrorPage.svelte';
10
12
  export { default as FormDialog } from './FormDialog.svelte';
11
13
  export { default as Icon } from './Icon.svelte';
12
14
  export { default as InlineEdit } from './InlineEdit.svelte';
@@ -20,6 +22,8 @@ export { default as PWAIndicator } from './PWAIndicator.svelte';
20
22
  export { default as Register } from './Register.svelte';
21
23
  export { default as SessionList } from './SessionList.svelte';
22
24
  export { default as SidebarLayout } from './SidebarLayout.svelte';
25
+ export { default as TopBar } from './TopBar.svelte';
26
+ export { default as TopBarContent } from './TopBarContent.svelte';
23
27
  export { default as Upload } from './Upload.svelte';
24
28
  export { default as URLText } from './URLText.svelte';
25
29
  export { default as UserCard } from './UserCard.svelte';
package/lib/toast.ts CHANGED
@@ -83,73 +83,89 @@ export async function toastStatus(promise: Promise<unknown>, successMessage: str
83
83
  }
84
84
  }
85
85
 
86
- let progressToast: HTMLDivElement | undefined,
87
- progressMain: HTMLSpanElement,
88
- progressMessage: HTMLSpanElement,
89
- progressBar: HTMLProgressElement,
90
- progressCancelButton: HTMLButtonElement,
91
- progressCancel: (() => void) | undefined;
86
+ export interface ProgressToast extends Disposable {
87
+ /** Aborted when the toast's cancel button is clicked */
88
+ readonly signal: AbortSignal;
89
+ progress(this: void, value: number, max: number, message?: any): void;
90
+ done(this: void): void;
91
+ }
92
+
93
+ let activeProgressToasts = 0;
92
94
 
93
95
  function warnBeforeUnload(e: BeforeUnloadEvent) {
94
96
  e.preventDefault();
95
97
  }
96
98
 
97
99
  /**
98
- * Register a callback used to cancel the operation shown in the progress toast.
99
- * The toast's cancel button is only shown while a callback is registered.
100
+ * Show an operation's progress in its own toast until it is done.
101
+ * Leaving the page asks for confirmation while any progress toast is shown.
100
102
  */
101
- export function setProgressCancel(cancel?: () => void): void {
102
- progressCancel = cancel;
103
- if (progressToast) progressCancelButton.style.display = cancel ? '' : 'none';
103
+ export function progressToast(message: string, cancellable: boolean = true): ProgressToast {
104
+ const controller = new AbortController();
105
+
106
+ const toast = document.createElement('div');
107
+ toast.classList.add('toast', 'progress');
108
+
109
+ const header = document.createElement('div');
110
+ header.classList.add('toast-header');
111
+ toast.appendChild(header);
112
+
113
+ const main = document.createElement('span');
114
+ main.textContent = message;
115
+ header.appendChild(main);
116
+
117
+ if (cancellable) {
118
+ const cancel = document.createElement('button');
119
+ cancel.classList.add('reset');
120
+ cancel.onclick = () => controller.abort();
121
+ mount(Icon, { target: cancel, props: { i: 'xmark-large' } });
122
+ header.appendChild(cancel);
123
+ }
124
+
125
+ const subtle = document.createElement('span');
126
+ subtle.classList.add('subtle');
127
+ toast.appendChild(subtle);
128
+
129
+ const bar = document.createElement('progress');
130
+ toast.appendChild(bar);
131
+
132
+ list.appendChild(toast);
133
+ if (!activeProgressToasts++) addEventListener('beforeunload', warnBeforeUnload);
134
+
135
+ let isDone = false;
136
+
137
+ return {
138
+ signal: controller.signal,
139
+ progress(value, max, message) {
140
+ bar.value = value;
141
+ bar.max = max;
142
+ subtle.textContent = message == undefined ? '' : String(message);
143
+ },
144
+ done() {
145
+ if (isDone) return;
146
+ isDone = true;
147
+ toast.remove();
148
+ if (!--activeProgressToasts) removeEventListener('beforeunload', warnBeforeUnload);
149
+ },
150
+ [Symbol.dispose]() {
151
+ this.done();
152
+ },
153
+ };
104
154
  }
105
155
 
156
+ let ioProgress: ProgressToast | undefined;
157
+
106
158
  useProgress({
107
159
  start(message: string): void {
108
- if (!progressToast) {
109
- progressToast = document.createElement('div');
110
- progressToast.classList.add('toast', 'progress');
111
-
112
- const header = document.createElement('div');
113
- header.classList.add('toast-header');
114
- progressToast.appendChild(header);
115
-
116
- progressMain = document.createElement('span');
117
- header.appendChild(progressMain);
118
-
119
- progressCancelButton = document.createElement('button');
120
- progressCancelButton.classList.add('reset');
121
- progressCancelButton.onclick = () => progressCancel?.();
122
- mount(Icon, { target: progressCancelButton, props: { i: 'xmark-large' } });
123
- header.appendChild(progressCancelButton);
124
-
125
- progressMessage = document.createElement('span');
126
- progressMessage.classList.add('subtle');
127
- progressToast.appendChild(progressMessage);
128
-
129
- progressBar = document.createElement('progress');
130
- progressToast.appendChild(progressBar);
131
-
132
- list.appendChild(progressToast);
133
- addEventListener('beforeunload', warnBeforeUnload);
134
- }
135
- progressMain.textContent = message;
136
- progressMessage.textContent = '';
137
- progressCancelButton.style.display = progressCancel ? '' : 'none';
138
- progressBar.removeAttribute('value');
139
- progressBar.max = 1;
160
+ ioProgress?.done();
161
+ ioProgress = progressToast(message, false);
140
162
  },
141
163
  progress(value: number, max: number, message?: any): void {
142
- if (!progressToast) return;
143
- progressBar.value = value;
144
- progressBar.max = max;
145
- progressMessage.textContent = message == undefined ? '' : String(message);
164
+ ioProgress?.progress(value, max, message);
146
165
  },
147
166
  done(): void {
148
- if (!progressToast) return;
149
- progressToast.remove();
150
- progressToast = undefined;
151
- progressCancel = undefined;
152
- removeEventListener('beforeunload', warnBeforeUnload);
167
+ ioProgress?.done();
168
+ ioProgress = undefined;
153
169
  },
154
170
  });
155
171
 
package/locales/en.json CHANGED
@@ -10,6 +10,7 @@
10
10
  "placeholder": "Add users and roles"
11
11
  },
12
12
  "AppMenu": {
13
+ "label": "Apps",
13
14
  "failed": "Couldn't load apps.",
14
15
  "none": "No apps available."
15
16
  },
@@ -50,7 +51,8 @@
50
51
  },
51
52
  "UserMenu": {
52
53
  "account": "Your Account",
53
- "admin": "Administration"
54
+ "admin": "Administration",
55
+ "login": "Log in"
54
56
  },
55
57
  "Version": {
56
58
  "error": "Latest unknown",
@@ -60,6 +62,15 @@
60
62
  "ZodInput": {
61
63
  "invalid_type": "Invalid input type: {type}"
62
64
  },
65
+ "error": {
66
+ "network": {
67
+ "title": "Offline",
68
+ "message": "Couldn't reach the server. Check your connection and try again."
69
+ },
70
+ "Page": {
71
+ "reload": "Reload"
72
+ }
73
+ },
63
74
  "generic": {
64
75
  "action_irreversible": "This action can't be undone.",
65
76
  "cancel": "Cancel",
@@ -97,6 +108,11 @@
97
108
  "edit_username": "Pick a unique username",
98
109
  "email_verified_on": "Email verified on {date}",
99
110
  "greeting": "Welcome, {name}",
111
+ "load_failed": {
112
+ "passkeys": "Couldn't load your passkeys",
113
+ "recovery": "Couldn't load your recovery options",
114
+ "sessions": "Couldn't load your sessions"
115
+ },
100
116
  "passkeys": {
101
117
  "backed_up": "This passkey is backed up",
102
118
  "create": "Create",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.38.0",
3
+ "version": "0.39.0",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -49,7 +49,7 @@
49
49
  "build": "tsc"
50
50
  },
51
51
  "peerDependencies": {
52
- "@axium/core": ">=0.40.0",
52
+ "@axium/core": ">=0.41.0",
53
53
  "ioium": "^1.7.0",
54
54
  "semver": "^7.7.4",
55
55
  "svelte": "^5.36.0",
package/styles/list.css CHANGED
@@ -2,7 +2,7 @@ div:has(> .list) {
2
2
  display: flex;
3
3
  flex-direction: column;
4
4
  min-height: 0;
5
- overflow-y: hidden;
5
+ overflow-y: clip;
6
6
 
7
7
  > :where(button),
8
8
  > .Popover > :where(button) {
@@ -14,8 +14,7 @@ div:has(> .list) {
14
14
  display: flex;
15
15
  flex-direction: column;
16
16
  min-height: 0;
17
- overflow-x: hidden;
18
- overflow-y: scroll;
17
+ overflow-x: clip;
19
18
  margin: 0.5em 0;
20
19
  }
21
20
 
@@ -24,7 +23,7 @@ div.list-header {
24
23
  border-bottom: 1.5px solid var(--fg-accent);
25
24
  position: sticky;
26
25
  background-color: inherit;
27
- top: 0em;
26
+ top: var(--top-bar-height, 0px);
28
27
  z-index: 1;
29
28
 
30
29
  @media (width < 700px) {