@glimstone/svelte 4.8.4 → 4.9.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.
@@ -8,6 +8,10 @@
8
8
  tip?: string | null;
9
9
  /** Sets the name in monospace, for a path. */
10
10
  mono?: boolean;
11
+ /** A quiet line under the name, such as when it was made or where it comes from. */
12
+ meta?: string;
13
+ /** Keeps the buttons in view at rest, for a short list of the person's own things, where each row's buttons are the point. */
14
+ steady?: boolean;
11
15
  /** The glyph at the row's start, which fills with the accent while the row is reached. */
12
16
  tile?: Snippet;
13
17
  /** What stands at the row's end at rest. */
@@ -24,7 +28,7 @@
24
28
  // One row of a list: a glyph tile, the name, badges and buttons that come in on
25
29
  // hover and focus (rule 6). A click handler makes the whole row a way into its
26
30
  // object, by keyboard too. The other props of a <div> go to the row.
27
- let { name, tip, mono, tile, badges, actions, class: className, onclick, onkeydown, ...rest }: ListRowProps = $props();
31
+ let { name, tip, mono, meta, steady, tile, badges, actions, class: className, onclick, onkeydown, ...rest }: ListRowProps = $props();
28
32
 
29
33
  const stay = (e: MouseEvent) => e.stopPropagation();
30
34
 
@@ -34,17 +38,28 @@
34
38
  e.preventDefault();
35
39
  e.currentTarget.click();
36
40
  }
37
- const classes = $derived(["glim-list-row", onclick && "glim-list-row--opens", className].filter(Boolean).join(" "));
41
+ const classes = $derived(["glim-list-row", onclick && "glim-list-row--opens", steady && "glim-list-row--steady", className].filter(Boolean).join(" "));
38
42
  </script>
39
43
 
40
- <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
41
- <div data-glim="ListRow" role="group" aria-label={name} tabindex={onclick ? 0 : undefined} {...rest} {onclick} onkeydown={keys} class={classes}>
42
- {#if tile}<span class="glim-list-row-tile">{@render tile()}</span>{/if}
44
+ {#snippet nameLine()}
43
45
  <span class={mono ? "glim-list-row-name glim-list-row-name--mono" : "glim-list-row-name"}>
44
46
  <span class="glim-list-row-title">{name}</span>
45
47
  <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
46
48
  {#if tip}<span class="glim-list-row-tip" onclick={stay}><InfoBubble {tip} /></span>{/if}
47
49
  </span>
50
+ {/snippet}
51
+
52
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
53
+ <div data-glim="ListRow" role="group" aria-label={name} tabindex={onclick ? 0 : undefined} {...rest} {onclick} onkeydown={keys} class={classes}>
54
+ {#if tile}<span class="glim-list-row-tile">{@render tile()}</span>{/if}
55
+ {#if meta}
56
+ <span class="glim-list-row-text">
57
+ {@render nameLine()}
58
+ <span class="glim-list-row-meta">{meta}</span>
59
+ </span>
60
+ {:else}
61
+ {@render nameLine()}
62
+ {/if}
48
63
  {#if badges}<span class="glim-list-row-badges">{@render badges()}</span>{/if}
49
64
  <!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
50
65
  {#if actions}<span class="glim-list-row-actions" onclick={stay}>{@render actions()}</span>{/if}
@@ -6,6 +6,10 @@ export interface ListRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "chil
6
6
  tip?: string | null;
7
7
  /** Sets the name in monospace, for a path. */
8
8
  mono?: boolean;
9
+ /** A quiet line under the name, such as when it was made or where it comes from. */
10
+ meta?: string;
11
+ /** Keeps the buttons in view at rest, for a short list of the person's own things, where each row's buttons are the point. */
12
+ steady?: boolean;
9
13
  /** The glyph at the row's start, which fills with the accent while the row is reached. */
10
14
  tile?: Snippet;
11
15
  /** What stands at the row's end at rest. */
@@ -10,6 +10,8 @@
10
10
  text?: Partial<PasswordFieldText>;
11
11
  /** Why the value cannot stand, as a line under the field until it is fixed. */
12
12
  error?: string;
13
+ /** A quiet line under the field that only informs, such as a hint about the value. An error takes its place. */
14
+ note?: string;
13
15
  /** Asks for the password again in a second field, which stands once the first holds something. */
14
16
  confirm?: boolean;
15
17
  /** Whether both fields hold the same password, each time that changes. Set password waits for true. */
@@ -22,7 +24,7 @@
22
24
  </script>
23
25
 
24
26
  <script lang="ts">
25
- import { fieldErrorView, fieldWidthClass, PASSWORD_FIELD_TEXT, passwordConfirmView } from "@glimstone/core";
27
+ import { fieldErrorView, fieldNoteView, fieldWidthClass, PASSWORD_FIELD_TEXT, passwordConfirmView } from "@glimstone/core";
26
28
  import FieldError from "./FieldError.svelte";
27
29
  import { useFieldName } from "./fieldName.js";
28
30
  import { IconEye, IconEyeOff } from "./glyphs.js";
@@ -38,6 +40,7 @@
38
40
  eyeAttrs,
39
41
  text,
40
42
  error,
43
+ note,
41
44
  confirm = false,
42
45
  onConfirmedChange,
43
46
  class: className,
@@ -56,7 +59,8 @@
56
59
  const name = useFieldName(() => ariaLabel ?? undefined);
57
60
  const own = $props.id();
58
61
  const id = $derived(rest.id ?? own);
59
- const err = $derived(fieldErrorView(error, id, describedBy ?? undefined));
62
+ const quiet = $derived(fieldNoteView(note, error, id, describedBy ?? undefined));
63
+ const err = $derived(fieldErrorView(error, id, quiet.describedBy));
60
64
  const view = $derived(passwordConfirmView(value == null ? "" : String(value), repeat));
61
65
  const mismatch = $derived(fieldErrorView(view.mismatch ? words.mismatch : undefined, `${id}-confirm`));
62
66
  $effect(() => {
@@ -85,6 +89,7 @@
85
89
  </IconTipButton>
86
90
  </span>
87
91
  {#if err.errorId}<FieldError id={err.errorId}>{error}</FieldError>{/if}
92
+ {#if quiet.noteId}<span id={quiet.noteId} class="glim-field-note">{note}</span>{/if}
88
93
  {#if confirm && view.shown}
89
94
  <span class="glim-secret-confirm">
90
95
  <label for="{id}-confirm" class="glim-secret-confirm-label">{words.confirm}</label>
@@ -8,6 +8,8 @@ export interface PasswordFieldProps extends Omit<HTMLInputAttributes, "type" | "
8
8
  text?: Partial<PasswordFieldText>;
9
9
  /** Why the value cannot stand, as a line under the field until it is fixed. */
10
10
  error?: string;
11
+ /** A quiet line under the field that only informs, such as a hint about the value. An error takes its place. */
12
+ note?: string;
11
13
  /** Asks for the password again in a second field, which stands once the first holds something. */
12
14
  confirm?: boolean;
13
15
  /** Whether both fields hold the same password, each time that changes. Set password waits for true. */
@@ -62,7 +62,9 @@
62
62
  const name = useFieldName(() => label);
63
63
  let box: HTMLSpanElement;
64
64
  let tight = $state(false);
65
+ // Measured once on mount as well, so the button's look is right before anything reads or paints it.
65
66
  $effect(() => {
67
+ tight = box.getBoundingClientRect().width < PATH_ROOM_PX;
66
68
  const watcher = new ResizeObserver(([entry]) => (tight = entry!.contentRect.width < PATH_ROOM_PX));
67
69
  watcher.observe(box);
68
70
  return () => watcher.disconnect();
@@ -1,8 +1,8 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from "svelte";
3
- import type { SignInHandlers, SignInLabelKeys, SignInText } from "@glimstone/core";
3
+ import type { SignInCardService, SignInHandlers, SignInLabelKeys, SignInText } from "@glimstone/core";
4
4
 
5
- export type { ResetAnswer, SignInAnswer, SignInLabelKeys, SignInText } from "@glimstone/core";
5
+ export type { ResetAnswer, SignInAnswer, SignInCardService, SignInLabelKeys, SignInText } from "@glimstone/core";
6
6
 
7
7
  export interface SignInCardProps extends SignInHandlers {
8
8
  /** The app's logo, as an address or as an inline `<svg>` with a viewBox. It stands 7.5rem tall above the name, as wide as its shape asks. */
@@ -10,14 +10,22 @@
10
10
  /** The page's heading. */
11
11
  appName: string;
12
12
  text: SignInText;
13
- /** Offers Sign in with a passkey. Pass it only where a passkey can answer on this address. */
13
+ /** Draws a passkey button, for a server without the browser's offer in the password field. `onPasskeyOffer` needs none. */
14
14
  passkey?: boolean;
15
15
  /** Offers Forgot password? and the reset form. */
16
16
  reset?: boolean;
17
- /** The shortest new password the reset form takes, as the server says. */
17
+ /** Asks for the account's name in the reset form, in an app with several accounts (the kit's options say `owner: false`). */
18
+ resetName?: boolean;
19
+ /** The length, as the server says, under which the reset form suggests a longer password. It never refuses a shorter one. */
18
20
  minPassword?: number;
19
21
  /** One line at the top of the sign-in form, such as "You are signed out". */
20
22
  note?: string;
23
+ /** A refusal from outside the card, such as a sign-in service that sent the person back, said above Sign in until the card's next try. */
24
+ error?: string;
25
+ /** The sign-in service whose button stands under Sign in, the one second way in the page offers. */
26
+ service?: SignInCardService;
27
+ /** Leaves for the sign-in service. */
28
+ onService?: () => void;
21
29
  /** The app's own fields, above the password. */
22
30
  fields?: Snippet;
23
31
  /** The app's own buttons, under Sign in and the passkey. */
@@ -25,7 +33,7 @@
25
33
  /** A step the app runs itself, in place of the card's forms. */
26
34
  step?: Snippet;
27
35
  labelKeys?: Partial<SignInLabelKeys>;
28
- /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-new` and `-confirm` follow it. */
36
+ /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-reset-name`, `-new` and `-confirm` follow it. */
29
37
  idPrefix?: string;
30
38
  /** Puts the focus in the first empty field when the card opens. */
31
39
  autoFocus?: boolean;
@@ -36,8 +44,10 @@
36
44
 
37
45
  <script lang="ts">
38
46
  import { onDestroy, untrack } from "svelte";
39
- import { createSignInFlow, focusFirstField, resetBlocked, showRefusal, signInBlocked, signInStage } from "@glimstone/core";
47
+ import { createSignInFlow, focusFirstField, passkeyOfferKey, resetBlocked, showRefusal, signInBlocked, signInShortHint, signInStage } from "@glimstone/core";
48
+ import BrandMark from "./BrandMark.svelte";
40
49
  import Button from "./Button.svelte";
50
+ import { glyphFor } from "./glyphs.js";
41
51
  import PasswordField from "./PasswordField.svelte";
42
52
  import SignInField from "./SignInField.svelte";
43
53
  import TextField from "./TextField.svelte";
@@ -51,8 +61,12 @@
51
61
  text,
52
62
  passkey = false,
53
63
  reset = false,
64
+ resetName = false,
54
65
  minPassword = 12,
55
66
  note,
67
+ error: outside,
68
+ service,
69
+ onService,
56
70
  fields,
57
71
  actions,
58
72
  step,
@@ -62,6 +76,7 @@
62
76
  class: className,
63
77
  onSignIn,
64
78
  onPasskey,
79
+ onPasskeyOffer,
65
80
  onAskCode,
66
81
  onSetPassword,
67
82
  }: SignInCardProps = $props();
@@ -72,9 +87,10 @@
72
87
  forgot: "forgotPassword",
73
88
  back: "back",
74
89
  setPassword: "setPassword",
90
+ service: "signIn",
75
91
  };
76
92
 
77
- const flow = createSignInFlow(() => ({ onSignIn, onPasskey, onAskCode, onSetPassword, text, minPassword }));
93
+ const flow = createSignInFlow(() => ({ onSignIn, onPasskey, onPasskeyOffer, onAskCode, onSetPassword, text, minPassword, resetName }));
78
94
  let s = $state.raw(flow.state());
79
95
  onDestroy(flow.subscribe(() => (s = flow.state())));
80
96
  const ownId = $props.id();
@@ -100,14 +116,27 @@
100
116
  if (refusal) return showRefusal(card, refusal);
101
117
  });
102
118
 
119
+ const offers = $derived(!!onPasskeyOffer && !step);
120
+ const offer = $derived(offers ? passkeyOfferKey(s) : null);
121
+ $effect(() => {
122
+ if (!offer) return;
123
+ const stop = new AbortController();
124
+ untrack(() => void flow.offer(stop.signal));
125
+ return () => stop.abort();
126
+ });
127
+
103
128
  function submit(e: SubmitEvent) {
104
129
  e.preventDefault();
105
130
  void flow.submit();
106
131
  }
107
132
  </script>
108
133
 
109
- {#snippet error()}
110
- {#if s.error}<p class="glim-signin-error" role="alert">{s.error}</p>{/if}
134
+ {#snippet said(line: string | null | undefined)}
135
+ {#if line}<p class="glim-signin-error" role="alert">{line}</p>{/if}
136
+ {/snippet}
137
+
138
+ {#snippet serviceMark()}
139
+ {#if service?.mark}<BrandMark svg={service.mark.svg} />{/if}
111
140
  {/snippet}
112
141
 
113
142
  {#snippet back()}
@@ -142,6 +171,19 @@
142
171
  placeholder="XXXX-XXXX-XXXX"
143
172
  />
144
173
  </SignInField>
174
+ {#if resetName}
175
+ <SignInField label={text.name} htmlFor={id("reset-name")}>
176
+ <TextField
177
+ id={id("reset-name")}
178
+ data-signin-field="resetName"
179
+ value={s.resetName}
180
+ oninput={(e) => flow.set("resetName", e.currentTarget.value)}
181
+ autocomplete="username"
182
+ autocapitalize="none"
183
+ spellcheck={false}
184
+ />
185
+ </SignInField>
186
+ {/if}
145
187
  <SignInField label={text.newPassword} htmlFor={id("new")}>
146
188
  <PasswordField
147
189
  id={id("new")}
@@ -150,6 +192,7 @@
150
192
  oninput={(e) => flow.set("newPassword", e.currentTarget.value)}
151
193
  autocomplete="new-password"
152
194
  text={eye}
195
+ note={signInShortHint(text.shortHint, s.newPassword, minPassword)}
153
196
  />
154
197
  </SignInField>
155
198
  <SignInField label={text.confirmPassword} htmlFor={id("confirm")}>
@@ -162,7 +205,7 @@
162
205
  text={eye}
163
206
  />
164
207
  </SignInField>
165
- {@render error()}
208
+ {@render said(s.error)}
166
209
  <!-- Stacked, since the longer translations of the two labels do not fit side by side. -->
167
210
  <Button
168
211
  label={text.setPassword}
@@ -170,7 +213,7 @@
170
213
  tone="accent"
171
214
  type="submit"
172
215
  data-signin="set-password"
173
- disabled={resetBlocked(s)}
216
+ disabled={resetBlocked(s, resetName)}
174
217
  busy={s.busy === "setPassword"}
175
218
  title={s.busy === "setPassword" ? text.saving : undefined}
176
219
  />
@@ -187,7 +230,7 @@
187
230
  data-signin-field="password"
188
231
  value={s.password}
189
232
  oninput={(e) => flow.set("password", e.currentTarget.value)}
190
- autocomplete="current-password"
233
+ autocomplete={offers ? "current-password webauthn" : "current-password"}
191
234
  text={eye}
192
235
  />
193
236
  </SignInField>
@@ -208,7 +251,7 @@
208
251
  <p class="glim-signin-hint">{text.codeHint}</p>
209
252
  </div>
210
253
  {/if}
211
- {@render error()}
254
+ {@render said(s.error ?? (s.tried ? null : outside))}
212
255
  <Button
213
256
  label={text.signIn}
214
257
  labelKey={keys.signIn}
@@ -231,19 +274,29 @@
231
274
  onClick={() => void flow.passkey()}
232
275
  />
233
276
  {/if}
277
+ {#if !s.needCode && service}
278
+ <Button
279
+ label={service.name}
280
+ labelKey={null}
281
+ glyph={service.mark ? serviceMark : glyphFor(keys.service)}
282
+ data-signin="service"
283
+ disabled={!!s.busy}
284
+ onClick={() => onService?.()}
285
+ />
286
+ {/if}
234
287
  {#if !s.needCode}{@render actions?.()}{/if}
288
+ <!-- A plain link, the last line of the card: nobody plans to forget a password. -->
235
289
  {#if s.needCode}
236
290
  {@render back()}
237
291
  {:else if reset}
238
- <Button
239
- label={text.forgot}
240
- labelKey={keys.forgot}
241
- tone="subtle"
292
+ <button
293
+ type="button"
294
+ class="glim-signin-forgot"
242
295
  data-signin="forgot"
243
296
  disabled={!!s.busy}
244
- busy={s.busy === "askCode"}
245
- onClick={() => void flow.forgot()}
246
- />
297
+ aria-busy={s.busy === "askCode" || undefined}
298
+ onclick={() => void flow.forgot()}>{text.forgot}</button
299
+ >
247
300
  {/if}
248
301
  </form>
249
302
  {/if}
@@ -1,20 +1,28 @@
1
1
  import type { Snippet } from "svelte";
2
- import type { SignInHandlers, SignInLabelKeys, SignInText } from "@glimstone/core";
3
- export type { ResetAnswer, SignInAnswer, SignInLabelKeys, SignInText } from "@glimstone/core";
2
+ import type { SignInCardService, SignInHandlers, SignInLabelKeys, SignInText } from "@glimstone/core";
3
+ export type { ResetAnswer, SignInAnswer, SignInCardService, SignInLabelKeys, SignInText } from "@glimstone/core";
4
4
  export interface SignInCardProps extends SignInHandlers {
5
5
  /** The app's logo, as an address or as an inline `<svg>` with a viewBox. It stands 7.5rem tall above the name, as wide as its shape asks. */
6
6
  logo?: string | Snippet;
7
7
  /** The page's heading. */
8
8
  appName: string;
9
9
  text: SignInText;
10
- /** Offers Sign in with a passkey. Pass it only where a passkey can answer on this address. */
10
+ /** Draws a passkey button, for a server without the browser's offer in the password field. `onPasskeyOffer` needs none. */
11
11
  passkey?: boolean;
12
12
  /** Offers Forgot password? and the reset form. */
13
13
  reset?: boolean;
14
- /** The shortest new password the reset form takes, as the server says. */
14
+ /** Asks for the account's name in the reset form, in an app with several accounts (the kit's options say `owner: false`). */
15
+ resetName?: boolean;
16
+ /** The length, as the server says, under which the reset form suggests a longer password. It never refuses a shorter one. */
15
17
  minPassword?: number;
16
18
  /** One line at the top of the sign-in form, such as "You are signed out". */
17
19
  note?: string;
20
+ /** A refusal from outside the card, such as a sign-in service that sent the person back, said above Sign in until the card's next try. */
21
+ error?: string;
22
+ /** The sign-in service whose button stands under Sign in, the one second way in the page offers. */
23
+ service?: SignInCardService;
24
+ /** Leaves for the sign-in service. */
25
+ onService?: () => void;
18
26
  /** The app's own fields, above the password. */
19
27
  fields?: Snippet;
20
28
  /** The app's own buttons, under Sign in and the passkey. */
@@ -22,7 +30,7 @@ export interface SignInCardProps extends SignInHandlers {
22
30
  /** A step the app runs itself, in place of the card's forms. */
23
31
  step?: Snippet;
24
32
  labelKeys?: Partial<SignInLabelKeys>;
25
- /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-new` and `-confirm` follow it. */
33
+ /** The start of the fields' ids: `-password`, `-code`, `-reset-code`, `-reset-name`, `-new` and `-confirm` follow it. */
26
34
  idPrefix?: string;
27
35
  /** Puts the focus in the first empty field when the card opens. */
28
36
  autoFocus?: boolean;
@@ -0,0 +1,82 @@
1
+ <script lang="ts" module>
2
+ import type { SignInApi, SignInReauthText } from "@glimstone/core";
3
+
4
+ export type { SignInReauthText } from "@glimstone/core";
5
+
6
+ export interface SignInReauthWindowProps {
7
+ api: SignInApi;
8
+ text: SignInReauthText;
9
+ }
10
+ </script>
11
+
12
+ <script lang="ts">
13
+ import { shake, signInReauthError, type SignInReauthState } from "@glimstone/core";
14
+ import FieldRow from "./FieldRow.svelte";
15
+ import PasswordField from "./PasswordField.svelte";
16
+ import Window from "./Window.svelte";
17
+
18
+ // The password question before a change the kit wants fresh ("The sign-in
19
+ // tile" in the design language). Mounted once beside the tiles, it opens when
20
+ // a change answers signInAgain with askPassword, and the change runs again
21
+ // once the password is confirmed. While it is mounted the client asks.
22
+ let { api, text }: SignInReauthWindowProps = $props();
23
+
24
+ const r = $derived(api.reauth);
25
+ let s = $state.raw<SignInReauthState | null>(null);
26
+ $effect(() => {
27
+ const reauth = r;
28
+ s = reauth.state();
29
+ return reauth.subscribe(() => (s = reauth.state()));
30
+ });
31
+
32
+ const refused = $derived(s?.refused ?? 0);
33
+ $effect(() => {
34
+ if (refused === 0) return;
35
+ const button = document.querySelector<HTMLElement>('[data-signin-reauth="confirm"]');
36
+ if (button) return shake(button);
37
+ });
38
+
39
+ function enter(e: KeyboardEvent) {
40
+ if (e.key !== "Enter") return;
41
+ e.preventDefault();
42
+ void r.submit();
43
+ }
44
+ </script>
45
+
46
+ {#if s?.asking}
47
+ <Window
48
+ data-glim="SignInReauthWindow"
49
+ title={text.title}
50
+ text={{ cancel: text.cancel, close: text.close }}
51
+ closeOnBackdrop={false}
52
+ onClose={r.cancel}
53
+ actions={[
54
+ {
55
+ label: text.confirm,
56
+ labelKey: "confirm",
57
+ primary: true,
58
+ busy: s.busy,
59
+ disabled: s.password === "",
60
+ attrs: { "data-signin-reauth": "confirm" },
61
+ onClick: () => {
62
+ void r.submit();
63
+ return false;
64
+ },
65
+ },
66
+ ]}
67
+ >
68
+ <div class="glim-signin-tile-body">
69
+ <p class="glim-signin-tile-text">{text.text}</p>
70
+ <FieldRow label={text.password}>
71
+ <PasswordField
72
+ autocomplete="current-password"
73
+ value={s.password}
74
+ oninput={(e) => r.set(e.currentTarget.value)}
75
+ onkeydown={enter}
76
+ text={{ show: text.show, hide: text.hide }}
77
+ error={signInReauthError(text, s.error)}
78
+ />
79
+ </FieldRow>
80
+ </div>
81
+ </Window>
82
+ {/if}
@@ -0,0 +1,9 @@
1
+ import type { SignInApi, SignInReauthText } from "@glimstone/core";
2
+ export type { SignInReauthText } from "@glimstone/core";
3
+ export interface SignInReauthWindowProps {
4
+ api: SignInApi;
5
+ text: SignInReauthText;
6
+ }
7
+ declare const SignInReauthWindow: import("svelte").Component<SignInReauthWindowProps, {}, "">;
8
+ type SignInReauthWindow = ReturnType<typeof SignInReauthWindow>;
9
+ export default SignInReauthWindow;