@axium/client 0.18.3 → 0.19.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/dist/requests.js CHANGED
@@ -31,11 +31,6 @@ export async function fetchAPI(method, endpoint, data, ...params) {
31
31
  catch (e) {
32
32
  throw prettifyError(e);
33
33
  }
34
- if (method !== 'GET' && method !== 'HEAD')
35
- options.body = JSON.stringify(data);
36
- const search = method != 'GET' || typeof data != 'object' || data == null || !Object.keys(data).length
37
- ? ''
38
- : '?' + new URLSearchParams(JSON.parse(JSON.stringify(data))).toString();
39
34
  if (token)
40
35
  options.headers.Authorization = 'Bearer ' + token;
41
36
  if (userAgent)
@@ -51,7 +46,17 @@ export async function fetchAPI(method, endpoint, data, ...params) {
51
46
  throw new Error(`Missing parameter "${part.slice(1)}"`);
52
47
  parts.push(value);
53
48
  }
54
- const response = await fetch(prefix + parts.join('/') + search, options);
49
+ let url = prefix + parts.join('/');
50
+ if (method !== 'GET' && method !== 'HEAD')
51
+ options.body = JSON.stringify(data);
52
+ if (method == 'GET' && typeof data == 'object' && data != null && Object.keys(data).length) {
53
+ const search = new URLSearchParams();
54
+ for (const [key, value] of Object.entries(data)) {
55
+ search.set(key, JSON.stringify(value));
56
+ }
57
+ url += '?' + search.toString();
58
+ }
59
+ const response = await fetch(url, options);
55
60
  if (!response.headers.get('Content-Type')?.includes('application/json')) {
56
61
  throw new Error(`Unexpected response type: ${response.headers.get('Content-Type')}`);
57
62
  }
@@ -3,11 +3,12 @@
3
3
  import type { AccessControllable, AccessTarget, User } from '@axium/core';
4
4
  import { getTarget, pickPermissions } from '@axium/core';
5
5
  import { errorText } from '@axium/core/io';
6
- import { toastStatus } from './toast.js';
7
6
  import type { HTMLDialogAttributes } from 'svelte/elements';
8
7
  import Icon from './Icon.svelte';
9
8
  import UserCard from './UserCard.svelte';
10
9
  import UserDiscovery from './UserDiscovery.svelte';
10
+ import { closeOnBackGesture } from './attachments.js';
11
+ import { toastStatus } from './toast.js';
11
12
 
12
13
  interface Props extends HTMLDialogAttributes {
13
14
  editable: boolean;
@@ -28,7 +29,7 @@
28
29
  }
29
30
  </script>
30
31
 
31
- <dialog bind:this={dialog} {...rest} onclick={e => e.stopPropagation()}>
32
+ <dialog bind:this={dialog} {...rest} onclick={e => e.stopPropagation()} {@attach closeOnBackGesture}>
32
33
  {#if item.name}
33
34
  <h3>{@html text('component.AccessControlDialog.named_title', { $html: true, name: item.name })}</h3>
34
35
  {:else}
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { text } from '@axium/client';
3
3
  import type { HTMLDialogAttributes } from 'svelte/elements';
4
+ import { closeOnBackGesture } from './attachments.js';
4
5
 
5
6
  let {
6
7
  children,
@@ -62,7 +63,7 @@
62
63
  <button type="submit" class={['submit', submitDanger && 'danger']}>{submitText}</button>
63
64
  {/snippet}
64
65
 
65
- <dialog bind:this={dialog} {onclose} {...rest} onclick={e => e.stopPropagation()}>
66
+ <dialog bind:this={dialog} {onclose} {...rest} onclick={e => e.stopPropagation()} {@attach closeOnBackGesture}>
66
67
  {@render header?.()}
67
68
  <form {onsubmit} class="main" method="dialog">
68
69
  {#if error}
@@ -1,21 +1,31 @@
1
1
  <script lang="ts">
2
2
  import Icon from './Icon.svelte';
3
- import { capitalize } from 'utilium';
4
3
 
5
4
  interface Tab {
6
5
  href: string;
7
6
  name: string;
8
7
  icon: string;
9
8
  active: boolean;
9
+ mobile?: false;
10
10
  }
11
11
 
12
- let { children, tabs, bottom }: { children(): any; tabs: Tab[]; bottom?(): any } = $props();
12
+ interface MobileTab {
13
+ href: string;
14
+ icon: string;
15
+ active: boolean;
16
+ mobile: true;
17
+ }
18
+
19
+ let { children, tabs, bottom }: { children(): any; tabs: (Tab | MobileTab)[]; bottom?(): any } = $props();
13
20
  </script>
14
21
 
15
22
  <div class="sidebar-container">
16
23
  <div class="sidebar">
17
- {#each tabs as { href, name, icon: i, active }}
18
- <a {href} class={['item', 'icon-text', active && 'active']}><Icon {i} /> <span class="sidebar-text">{name}</span></a>
24
+ {#each tabs as tab}
25
+ <a href={tab.href} class={['item', 'icon-text', tab.active && 'active', tab.mobile && 'mobile-only']}>
26
+ <Icon i={tab.icon} />
27
+ {#if !tab.mobile}<span class="sidebar-text">{tab.name}</span>{/if}
28
+ </a>
19
29
  {/each}
20
30
 
21
31
  {#if bottom}
@@ -98,12 +108,17 @@
98
108
  overflow-y: scroll;
99
109
 
100
110
  @media (width < 700px) {
101
- padding-bottom: 4em;
111
+ padding-bottom: 5em;
102
112
  grid-column: 1;
103
113
  }
104
114
  }
105
115
 
106
116
  .sidebar-bottom {
107
117
  margin-top: auto;
118
+ margin-left: 1em;
119
+
120
+ @media (width < 700px) {
121
+ display: none;
122
+ }
108
123
  }
109
124
  </style>
@@ -3,8 +3,8 @@
3
3
  * @see https://svelte.dev/docs/svelte/@attach
4
4
  */
5
5
  import { mount, unmount } from 'svelte';
6
- import Icon from './Icon.svelte';
7
6
  import type { Attachment } from 'svelte/attachments';
7
+ import Icon from './Icon.svelte';
8
8
 
9
9
  export interface ContextMenuItem {
10
10
  /** Icon name */
@@ -95,8 +95,12 @@ export function contextMenu(...menuItems: (ContextMenuItem | false | null | unde
95
95
  };
96
96
  }
97
97
 
98
+ /**
99
+ * Dynamically resize `<textarea>`s based on content.
100
+ * @todo Remove this once `field-sizing` works everywhere
101
+ */
98
102
  export function dynamicRows(max: number = 40, min: number = 3): Attachment<HTMLTextAreaElement> {
99
- return function _attackDynamicRows(element: HTMLTextAreaElement) {
103
+ return function _attachDynamicRows(element: HTMLTextAreaElement) {
100
104
  element.style.resize = 'none';
101
105
  // @ts-expect-error field-sizing is not yet in the types
102
106
  element.style.fieldSizing = 'content';
@@ -118,3 +122,38 @@ export function dynamicRows(max: number = 40, min: number = 3): Attachment<HTMLT
118
122
  };
119
123
  };
120
124
  }
125
+
126
+ /**
127
+ * Enabled the use of back gestures to close dialogs
128
+ */
129
+ export function closeOnBackGesture(element: HTMLDialogElement) {
130
+ if (!globalThis.history) {
131
+ throw new Error('Can not attach back gesture handling because the History API is unavailable');
132
+ }
133
+
134
+ const showModal = element.showModal.bind(element);
135
+
136
+ let closedByBack = false,
137
+ historyKey = Math.random().toString(16).slice(2);
138
+
139
+ element.showModal = () => {
140
+ closedByBack = false;
141
+ /* popstate's state will be the "upcoming" state.
142
+ i.e, the state after having pushed 1 then 2 would be 1 */
143
+ history.replaceState(historyKey, '');
144
+ history.pushState(null, '');
145
+ showModal();
146
+ };
147
+
148
+ element.addEventListener('close', () => {
149
+ if (closedByBack) return;
150
+ history.replaceState(null, '');
151
+ });
152
+
153
+ window.addEventListener('popstate', e => {
154
+ if (e.state != historyKey) return;
155
+ closedByBack = true;
156
+ element.close();
157
+ });
158
+ }
159
+ closeOnBackGesture satisfies Attachment<HTMLDialogElement>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/client",
3
- "version": "0.18.3",
3
+ "version": "0.19.0",
4
4
  "author": "James Prevett <jp@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",
package/styles/list.css CHANGED
@@ -1,23 +1,31 @@
1
- .list-container {
2
- overflow-x: hidden;
3
- overflow-y: scroll;
1
+ div:has(> .list) {
2
+ display: flex;
3
+ flex-direction: column;
4
+ min-height: 0;
5
+ overflow-y: hidden;
4
6
 
5
- .list {
6
- height: 100%;
7
+ > :where(button),
8
+ > .Popover > :where(button) {
9
+ align-self: flex-start;
7
10
  }
8
11
  }
9
12
 
10
13
  .list {
11
14
  display: flex;
12
15
  flex-direction: column;
13
- padding: 0.5em;
16
+ min-height: 0;
17
+ overflow-x: hidden;
18
+ overflow-y: scroll;
19
+ margin: 0.5em 0;
14
20
  }
15
21
 
16
22
  div.list-header {
17
23
  font-weight: bold;
18
24
  border-bottom: 1.5px solid var(--fg-accent);
19
25
  position: sticky;
26
+ background-color: var(--bg-normal);
20
27
  top: 0em;
28
+ z-index: 1;
21
29
 
22
30
  @media (width < 700px) {
23
31
  display: none !important;
@@ -36,6 +44,7 @@ div.list-header {
36
44
  padding: 0.5em;
37
45
  overflow: hidden;
38
46
  text-wrap: nowrap;
47
+ flex: 0 0 auto;
39
48
  }
40
49
 
41
50
  .list-item:not(.list-header, :first-child) {