@glimstone/svelte 4.7.0 → 4.8.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.
@@ -1,10 +1,12 @@
1
1
  <script lang="ts" module>
2
2
  import type { Snippet } from "svelte";
3
3
  import type { HTMLAttributes } from "svelte/elements";
4
- import type { ConnectionRowLabelKeys, ConnectionRowText, ConnectionTest, TileMark } from "@glimstone/core";
4
+ import type { ConnectionAction as CoreConnectionAction, ConnectionRowLabelKeys, ConnectionRowText, ConnectionTest, TileMark } from "@glimstone/core";
5
5
 
6
6
  export type { ConnectionRowLabelKeys, ConnectionRowText, ConnectionTest } from "@glimstone/core";
7
7
 
8
+ export type ConnectionAction = CoreConnectionAction<Snippet>;
9
+
8
10
  export interface ConnectionRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "class"> {
9
11
  /** The service's name, also the row's accessible name. */
10
12
  name: string;
@@ -18,6 +20,8 @@
18
20
  children?: Snippet;
19
21
  /** Where the test stands: `busy` while it runs, then `tone` and a `title` with what it found. */
20
22
  test?: ConnectionTest;
23
+ /** Buttons of the app's own, such as Mount, before Test, Edit and Remove, so those keep their places at the end. */
24
+ actions?: ConnectionAction[];
21
25
  text: ConnectionRowText;
22
26
  labelKeys?: Partial<ConnectionRowLabelKeys>;
23
27
  onTest?: () => void;
@@ -28,31 +32,34 @@
28
32
  </script>
29
33
 
30
34
  <script lang="ts">
31
- import { CONNECTION_ROW_KEYS, connectionTestFace, connectionTile } from "@glimstone/core";
35
+ import { connectionButtons, connectionTestFace, connectionTile } from "@glimstone/core";
32
36
  import BrandMark from "./BrandMark.svelte";
33
37
  import Button from "./Button.svelte";
34
- import { IconCheck, IconClose } from "./glyphs.js";
38
+ import { IconCheck, IconClose, IconPencil, IconTrash } from "./glyphs.js";
35
39
  import { css } from "./style.js";
36
40
 
37
41
  // A connected service or account as a compact row ("Connections" in the design
38
42
  // language): its mark lit on a tile the row's whole height, its name with any
39
- // badges, one quiet line on how it stands, and its test, edit and remove at
40
- // the end. A button stands only where its handler is passed. The other props
41
- // of a <div> go to the row.
42
- let { name, mark, status, badges, children, test, text, labelKeys, onTest, onEdit, onRemove, class: className, ...rest }: ConnectionRowProps = $props();
43
+ // badges, one quiet line on how it stands, and at the end the app's own
44
+ // actions, then its test, edit and remove. A built-in button stands only where
45
+ // its handler is passed. The other props of a <div> go to the row.
46
+ let { name, mark, status, badges, children, test, actions, text, labelKeys, onTest, onEdit, onRemove, class: className, ...rest }: ConnectionRowProps = $props();
43
47
 
44
48
  // On a phone the buttons show their glyphs alone, so they keep to one line.
45
49
  const NARROW = 640;
46
50
 
47
- const keys = $derived({ ...CONNECTION_ROW_KEYS, ...labelKeys });
48
51
  const tile = $derived(connectionTile(mark));
49
- const face = $derived(connectionTestFace(test));
50
- const outcome = $derived(face.outcome === "check" ? IconCheck : face.outcome === "cross" ? IconClose : undefined);
52
+ const buttons = $derived(
53
+ connectionButtons({ actions, test, text, labelKeys, onTest, onEdit, onRemove }, { test: IconCheck, edit: IconPencil, remove: IconTrash }).map((b) => {
54
+ const face = connectionTestFace(b);
55
+ return { ...b, face, glyph: face.outcome === "check" ? IconCheck : face.outcome === "cross" ? IconClose : b.glyph };
56
+ }),
57
+ );
51
58
  </script>
52
59
 
53
60
  <div data-glim="ConnectionRow" role="group" aria-label={name} {...rest} class={["glim-well glim-connection", className].filter(Boolean).join(" ")}>
54
61
  <span class="glim-connection-tile" style={css(tile.style)} aria-hidden="true">
55
- <span class="glim-connection-mark">
62
+ <span class={tile.wordmark ? "glim-connection-mark glim-connection-mark--wordmark" : "glim-connection-mark"}>
56
63
  {#if tile.svg !== undefined}<BrandMark svg={tile.svg} />{:else}{@render (mark as Snippet)()}{/if}
57
64
  </span>
58
65
  </span>
@@ -66,24 +73,23 @@
66
73
  {#if status}<p class="glim-connection-status">{status}</p>{/if}
67
74
  {@render children?.()}
68
75
  </div>
69
- {#if onTest || onEdit || onRemove}
76
+ {#if buttons.length > 0}
70
77
  <span class="glim-connection-actions">
71
- {#if onTest}
78
+ {#each buttons as b (b.id)}
72
79
  <Button
73
- label={text.test}
74
- labelKey={keys.test}
75
- glyph={outcome}
76
- tone={face.tone}
77
- busy={test?.busy}
78
- title={test?.title}
80
+ label={b.label}
81
+ labelKey={b.labelKey}
82
+ glyph={b.glyph}
83
+ tone={b.face.tone}
84
+ busy={b.busy}
85
+ title={b.title}
86
+ disabled={b.disabled}
79
87
  compactBelow={NARROW}
80
- class={face.shake ? "glim-shake" : ""}
81
- data-connection="test"
82
- onClick={onTest}
88
+ class={b.face.shake ? "glim-shake" : ""}
89
+ data-connection={b.id}
90
+ onClick={b.onClick}
83
91
  />
84
- {/if}
85
- {#if onEdit}<Button label={text.edit} labelKey={keys.edit} compactBelow={NARROW} data-connection="edit" onClick={onEdit} />{/if}
86
- {#if onRemove}<Button label={text.remove} labelKey={keys.remove} compactBelow={NARROW} data-connection="remove" onClick={onRemove} />{/if}
92
+ {/each}
87
93
  </span>
88
94
  {/if}
89
95
  </div>
@@ -1,7 +1,8 @@
1
1
  import type { Snippet } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
- import type { ConnectionRowLabelKeys, ConnectionRowText, ConnectionTest, TileMark } from "@glimstone/core";
3
+ import type { ConnectionAction as CoreConnectionAction, ConnectionRowLabelKeys, ConnectionRowText, ConnectionTest, TileMark } from "@glimstone/core";
4
4
  export type { ConnectionRowLabelKeys, ConnectionRowText, ConnectionTest } from "@glimstone/core";
5
+ export type ConnectionAction = CoreConnectionAction<Snippet>;
5
6
  export interface ConnectionRowProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "class"> {
6
7
  /** The service's name, also the row's accessible name. */
7
8
  name: string;
@@ -15,6 +16,8 @@ export interface ConnectionRowProps extends Omit<HTMLAttributes<HTMLDivElement>,
15
16
  children?: Snippet;
16
17
  /** Where the test stands: `busy` while it runs, then `tone` and a `title` with what it found. */
17
18
  test?: ConnectionTest;
19
+ /** Buttons of the app's own, such as Mount, before Test, Edit and Remove, so those keep their places at the end. */
20
+ actions?: ConnectionAction[];
18
21
  text: ConnectionRowText;
19
22
  labelKeys?: Partial<ConnectionRowLabelKeys>;
20
23
  onTest?: () => void;
@@ -1,15 +1,19 @@
1
1
  <script lang="ts" module>
2
2
  import type { HTMLInputAttributes } from "svelte/elements";
3
- import type { FieldWidth } from "@glimstone/core";
3
+ import type { FieldWidth, PasswordFieldText } from "@glimstone/core";
4
4
 
5
5
  export interface PasswordFieldProps extends Omit<HTMLInputAttributes, "type" | "width" | "class"> {
6
6
  width?: FieldWidth;
7
7
  /** Attributes for the eye, such as a data hook. */
8
8
  eyeAttrs?: Record<string, string>;
9
- /** The eye's name and bubble while the secret is hidden, and once it shows. */
10
- text?: { show: string; hide: string };
9
+ /** The eye's words, and the second field's with `confirm`. English where left out. */
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
+ /** Asks for the password again in a second field, which stands once the first holds something. */
14
+ confirm?: boolean;
15
+ /** Whether both fields hold the same password, each time that changes. Set password waits for true. */
16
+ onConfirmedChange?: (confirmed: boolean) => void;
13
17
  /** Classes for the wrapper, which carries the field's width. */
14
18
  class?: string;
15
19
  /** The <input>, bound with `bind:ref`. */
@@ -18,7 +22,7 @@
18
22
  </script>
19
23
 
20
24
  <script lang="ts">
21
- import { fieldErrorView, fieldWidthClass } from "@glimstone/core";
25
+ import { fieldErrorView, fieldWidthClass, PASSWORD_FIELD_TEXT, passwordConfirmView } from "@glimstone/core";
22
26
  import FieldError from "./FieldError.svelte";
23
27
  import { useFieldName } from "./fieldName.js";
24
28
  import { IconEye, IconEyeOff } from "./glyphs.js";
@@ -28,11 +32,14 @@
28
32
  // design language). The props are a native <input>'s, so a call site swaps
29
33
  // `<input type="password"` for `<PasswordField` and keeps its own listeners;
30
34
  // the secret is bound with `bind:value`. Inside a FieldRow the row names it.
35
+ // With `confirm` it takes a new password, typed twice.
31
36
  let {
32
37
  width,
33
38
  eyeAttrs,
34
- text = { show: "Show", hide: "Hide" },
39
+ text,
35
40
  error,
41
+ confirm = false,
42
+ onConfirmedChange,
36
43
  class: className,
37
44
  ref = $bindable(null),
38
45
  disabled,
@@ -42,15 +49,26 @@
42
49
  ...rest
43
50
  }: PasswordFieldProps = $props();
44
51
 
52
+ const words = $derived({ ...PASSWORD_FIELD_TEXT, ...text });
45
53
  let shown = $state(false);
54
+ let repeatShown = $state(false);
55
+ let repeat = $state("");
46
56
  const name = useFieldName(() => ariaLabel ?? undefined);
47
57
  const own = $props.id();
48
- const err = $derived(fieldErrorView(error, rest.id ?? own, describedBy ?? undefined));
58
+ const id = $derived(rest.id ?? own);
59
+ const err = $derived(fieldErrorView(error, id, describedBy ?? undefined));
60
+ const view = $derived(passwordConfirmView(value == null ? "" : String(value), repeat));
61
+ const mismatch = $derived(fieldErrorView(view.mismatch ? words.mismatch : undefined, `${id}-confirm`));
62
+ $effect(() => {
63
+ if (!view.shown) repeat = "";
64
+ });
65
+ const confirmed = $derived(confirm && view.confirmed);
66
+ $effect(() => onConfirmedChange?.(confirmed));
49
67
  </script>
50
68
 
51
69
  <span data-glim="PasswordField" class={["glim-secret", fieldWidthClass(width), className].filter(Boolean).join(" ")}>
52
70
  <input
53
- autocomplete="current-password"
71
+ autocomplete={confirm ? "new-password" : "current-password"}
54
72
  spellcheck={false}
55
73
  {...rest}
56
74
  aria-label={name()}
@@ -62,8 +80,34 @@
62
80
  type={shown ? "text" : "password"}
63
81
  class="glim-input"
64
82
  />
65
- <IconTipButton {...eyeAttrs} tip={shown ? text.hide : text.show} class="glim-secret-eye" disabled={!!disabled} onclick={() => (shown = !shown)}>
83
+ <IconTipButton {...eyeAttrs} tip={shown ? words.hide : words.show} class="glim-secret-eye" disabled={!!disabled} onclick={() => (shown = !shown)}>
66
84
  {#if shown}{@render IconEyeOff()}{:else}{@render IconEye()}{/if}
67
85
  </IconTipButton>
68
86
  </span>
69
87
  {#if err.errorId}<FieldError id={err.errorId}>{error}</FieldError>{/if}
88
+ {#if confirm && view.shown}
89
+ <span class="glim-secret-confirm">
90
+ <label for="{id}-confirm" class="glim-secret-confirm-label">{words.confirm}</label>
91
+ <span class={["glim-secret-confirm-box", fieldWidthClass(width)].filter(Boolean).join(" ")}>
92
+ <span class="glim-secret">
93
+ <input
94
+ id="{id}-confirm"
95
+ autocomplete="new-password"
96
+ spellcheck={false}
97
+ bind:value={repeat}
98
+ aria-invalid={mismatch.invalid}
99
+ aria-describedby={mismatch.describedBy}
100
+ {disabled}
101
+ type={repeatShown ? "text" : "password"}
102
+ class="glim-input"
103
+ />
104
+ <IconTipButton tip={repeatShown ? words.hide : words.show} class="glim-secret-eye" disabled={!!disabled} onclick={() => (repeatShown = !repeatShown)}>
105
+ {#if repeatShown}{@render IconEyeOff()}{:else}{@render IconEye()}{/if}
106
+ </IconTipButton>
107
+ </span>
108
+ <span aria-live="polite" class="glim-secret-confirm-live">
109
+ {#if mismatch.errorId}<FieldError id={mismatch.errorId}>{words.mismatch}</FieldError>{/if}
110
+ </span>
111
+ </span>
112
+ </span>
113
+ {/if}
@@ -1,16 +1,17 @@
1
1
  import type { HTMLInputAttributes } from "svelte/elements";
2
- import type { FieldWidth } from "@glimstone/core";
2
+ import type { FieldWidth, PasswordFieldText } from "@glimstone/core";
3
3
  export interface PasswordFieldProps extends Omit<HTMLInputAttributes, "type" | "width" | "class"> {
4
4
  width?: FieldWidth;
5
5
  /** Attributes for the eye, such as a data hook. */
6
6
  eyeAttrs?: Record<string, string>;
7
- /** The eye's name and bubble while the secret is hidden, and once it shows. */
8
- text?: {
9
- show: string;
10
- hide: string;
11
- };
7
+ /** The eye's words, and the second field's with `confirm`. English where left out. */
8
+ text?: Partial<PasswordFieldText>;
12
9
  /** Why the value cannot stand, as a line under the field until it is fixed. */
13
10
  error?: string;
11
+ /** Asks for the password again in a second field, which stands once the first holds something. */
12
+ confirm?: boolean;
13
+ /** Whether both fields hold the same password, each time that changes. Set password waits for true. */
14
+ onConfirmedChange?: (confirmed: boolean) => void;
14
15
  /** Classes for the wrapper, which carries the field's width. */
15
16
  class?: string;
16
17
  /** The <input>, bound with `bind:ref`. */
@@ -26,7 +26,7 @@
26
26
  </script>
27
27
 
28
28
  <script lang="ts">
29
- import { windowFoot } from "@glimstone/core";
29
+ import { footStartShows, windowFoot } from "@glimstone/core";
30
30
  import Button from "./Button.svelte";
31
31
  import { IconCancel, IconClose } from "./glyphs.js";
32
32
 
@@ -44,8 +44,9 @@
44
44
  onClose: () => void;
45
45
  } = $props();
46
46
 
47
+ const hasStart = $derived(footStartShows(start));
47
48
  const foot = $derived(
48
- windowFoot<WindowAction>(actions, start !== undefined, {
49
+ windowFoot<WindowAction>(actions, hasStart, {
49
50
  cancel: { label: text.cancel, labelKey: "common.cancel", glyph: IconCancel, wayOut: true },
50
51
  close: { label: text.close, labelKey: "common.close", glyph: IconClose, wayOut: true },
51
52
  }),
@@ -54,23 +55,25 @@
54
55
 
55
56
  {#if foot.length > 0}
56
57
  <div class="glim-modal-foot">
57
- {#if start !== undefined}
58
- <span class="glim-window-start">{#if typeof start === "string"}{start}{:else}{@render start()}{/if}</span>
58
+ {#if hasStart}
59
+ <span class="glim-window-start">{#if typeof start === "string"}{start}{:else}{@render start?.()}{/if}</span>
59
60
  {/if}
60
- {#each foot as a, i (i)}
61
- <Button
62
- {...a.attrs}
63
- label={a.label}
64
- labelKey={a.labelKey}
65
- glyph={a.glyph}
66
- tone={a.tone ?? (a.primary ? "accent" : "neutral")}
67
- busy={a.busy}
68
- title={a.title}
69
- disabled={a.disabled}
70
- onClick={() => {
71
- if (a.onClick?.() !== false) onClose();
72
- }}
73
- />
74
- {/each}
61
+ <div class="glim-window-actions">
62
+ {#each foot as a, i (i)}
63
+ <Button
64
+ {...a.attrs}
65
+ label={a.label}
66
+ labelKey={a.labelKey}
67
+ glyph={a.glyph}
68
+ tone={a.tone ?? (a.primary ? "accent" : "neutral")}
69
+ busy={a.busy}
70
+ title={a.title}
71
+ disabled={a.disabled}
72
+ onClick={() => {
73
+ if (a.onClick?.() !== false) onClose();
74
+ }}
75
+ />
76
+ {/each}
77
+ </div>
75
78
  </div>
76
79
  {/if}
package/dist/glyphs.d.ts CHANGED
@@ -16,6 +16,7 @@ export declare const IconCheck: Snippet<[]>;
16
16
  export declare const IconExpand: Snippet<[]>;
17
17
  export declare const IconFolderOpen: Snippet<[]>;
18
18
  export declare const IconPencil: Snippet<[]>;
19
+ export declare const IconTrash: Snippet<[]>;
19
20
  export declare const IconWindowMinimise: Snippet<[]>;
20
21
  export declare const IconWindowMaximise: Snippet<[]>;
21
22
  export declare const IconWindowRestore: Snippet<[]>;
package/dist/glyphs.js CHANGED
@@ -31,6 +31,7 @@ export const IconCheck = markSnippet(MARKS.check);
31
31
  export const IconExpand = markSnippet(MARKS.expand);
32
32
  export const IconFolderOpen = markSnippet(MARKS.folderOpen);
33
33
  export const IconPencil = markSnippet(MARKS.pencil);
34
+ export const IconTrash = markSnippet(MARKS.trash);
34
35
  export const IconWindowMinimise = markSnippet(MARKS.windowMinimise);
35
36
  export const IconWindowMaximise = markSnippet(MARKS.windowMaximise);
36
37
  export const IconWindowRestore = markSnippet(MARKS.windowRestore);
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { default as Checkbox, type CheckboxProps } from "./Checkbox.svelte";
8
8
  export { default as CoffeeDialog, type CoffeeDialogProps } from "./CoffeeDialog.svelte";
9
9
  export { default as ColorPicker, type ColorName, type ColorPickerPanelText, type ColorPickerProps } from "./ColorPicker.svelte";
10
10
  export { default as ConfirmDialog, type ConfirmDialogProps } from "./ConfirmDialog.svelte";
11
- export { default as ConnectionRow, type ConnectionRowLabelKeys, type ConnectionRowProps, type ConnectionRowText, type ConnectionTest } from "./ConnectionRow.svelte";
11
+ export { default as ConnectionRow, type ConnectionAction, type ConnectionRowLabelKeys, type ConnectionRowProps, type ConnectionRowText, type ConnectionTest } from "./ConnectionRow.svelte";
12
12
  export { default as ContextMenu, type ContextMenuProps, type MenuEntry, type MenuHead, type MenuItem } from "./ContextMenu.svelte";
13
13
  export { default as CopyField, type CopyFieldProps } from "./CopyField.svelte";
14
14
  export { default as CryptoDonateDialog, type CryptoCoin, type CryptoDonateDialogProps, type CryptoNetwork } from "./CryptoDonateDialog.svelte";
@@ -71,7 +71,7 @@ export { useAccent, useDensity, useHue, useLabelMode, useMotion, useRainbow, use
71
71
  export { useConfirm, useDialogKeys, type ConfirmOptions, type ConfirmText } from "./confirm.svelte.js";
72
72
  export { useFieldName } from "./fieldName.js";
73
73
  export { deviceGlyph } from "./fortressParts.js";
74
- export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
74
+ export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconTrash, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
75
75
  export * from "./portalHue.svelte.js";
76
76
  export { useTipBubble, type TipBubble } from "./bubble.svelte.js";
77
77
  export * from "./useDragArmed.svelte.js";
package/dist/index.js CHANGED
@@ -71,7 +71,7 @@ export { useAccent, useDensity, useHue, useLabelMode, useMotion, useRainbow, use
71
71
  export { useConfirm, useDialogKeys } from "./confirm.svelte.js";
72
72
  export { useFieldName } from "./fieldName.js";
73
73
  export { deviceGlyph } from "./fortressParts.js";
74
- export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
74
+ export { glyphFor, IconBack, IconCalendar, IconCancel, IconCheck, IconClose, IconCopy, IconExpand, IconEye, IconEyeOff, IconFolderOpen, IconForward, IconPause, IconPencil, IconPlay, IconResetArrow, IconSearch, IconStar, IconTrash, IconUpload, IconWindowMaximise, IconWindowMinimise, IconWindowRestore, setGlyphResolver } from "./glyphs.js";
75
75
  export * from "./portalHue.svelte.js";
76
76
  export { useTipBubble } from "./bubble.svelte.js";
77
77
  export * from "./useDragArmed.svelte.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/svelte",
3
- "version": "4.7.0",
3
+ "version": "4.8.1",
4
4
  "description": "GlimStone's components for Svelte",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -141,7 +141,7 @@
141
141
  "build": "svelte-package -i src -o dist"
142
142
  },
143
143
  "dependencies": {
144
- "@glimstone/core": "4.7.0"
144
+ "@glimstone/core": "4.8.1"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@internationalized/date": "^3.12.4",