@axium/client 0.18.4 → 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.
@@ -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}
@@ -108,7 +108,7 @@
108
108
  overflow-y: scroll;
109
109
 
110
110
  @media (width < 700px) {
111
- padding-bottom: 4em;
111
+ padding-bottom: 5em;
112
112
  grid-column: 1;
113
113
  }
114
114
  }
@@ -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.4",
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
@@ -16,6 +16,7 @@ div:has(> .list) {
16
16
  min-height: 0;
17
17
  overflow-x: hidden;
18
18
  overflow-y: scroll;
19
+ margin: 0.5em 0;
19
20
  }
20
21
 
21
22
  div.list-header {