@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.
@@ -0,0 +1,323 @@
1
+ <script lang="ts">
2
+ import {
3
+ fill,
4
+ passwordGoes,
5
+ qrCode,
6
+ SIGN_IN_TOKEN_LIVES,
7
+ signInRedirectAddress,
8
+ signInScopeItems,
9
+ signInRoleItems,
10
+ signInServiceLabel,
11
+ signInServiceName,
12
+ signInServicePicker,
13
+ signInServiceQuiet,
14
+ signInTestLabel,
15
+ type Catalog,
16
+ type SignInApi,
17
+ type SignInTileField,
18
+ type SignInTileFlow,
19
+ type SignInTileLabelKeys,
20
+ type SignInTileState,
21
+ type SignInTileText,
22
+ } from "@glimstone/core";
23
+ import Accordion from "./Accordion.svelte";
24
+ import CopyField from "./CopyField.svelte";
25
+ import FieldRow from "./FieldRow.svelte";
26
+ import FieldRowGroup from "./FieldRowGroup.svelte";
27
+ import PasswordField from "./PasswordField.svelte";
28
+ import PickerWindow from "./PickerWindow.svelte";
29
+ import Selector from "./Selector.svelte";
30
+ import TextField from "./TextField.svelte";
31
+ import Window, { type WindowAction } from "./Window.svelte";
32
+ import { glyphFor, IconCancel, IconCheck, IconClose } from "./glyphs.js";
33
+
34
+ // The window the sign-in tile has open: the password's removal, two-factor's
35
+ // setup, codes and turning off, a passkey's name, a new token and the picker
36
+ // with the form of a sign-in service.
37
+ let {
38
+ flow,
39
+ flowState: s,
40
+ api,
41
+ text,
42
+ lang,
43
+ scopes,
44
+ providers,
45
+ keys,
46
+ }: {
47
+ flow: SignInTileFlow;
48
+ flowState: SignInTileState;
49
+ api: SignInApi;
50
+ text: SignInTileText;
51
+ lang: string;
52
+ scopes: string[];
53
+ providers: Catalog;
54
+ keys: SignInTileLabelKeys;
55
+ } = $props();
56
+
57
+ const w = $derived(s.window!);
58
+ const words = $derived({ cancel: text.cancel, close: text.close });
59
+ const eye = $derived({ show: text.show, hide: text.hide, confirm: text.confirmPassword, mismatch: text.mismatch });
60
+ const copyWords = $derived({ copy: text.copy, copied: text.copied });
61
+ const err = (field: SignInTileField) => (s.invalid?.field === field ? s.invalid.message : undefined);
62
+ const cancel = $derived<WindowAction>({ label: text.cancel, labelKey: "common.cancel", glyph: IconCancel, wayOut: true });
63
+
64
+ function act(label: string, labelKey: string, hook: string, run: () => Promise<void> | void, more: Partial<WindowAction> = {}): WindowAction {
65
+ return {
66
+ label,
67
+ labelKey,
68
+ busy: s.busy === hook,
69
+ attrs: { "data-signin-tile": hook },
70
+ onClick: () => {
71
+ void run();
72
+ return false;
73
+ },
74
+ ...more,
75
+ };
76
+ }
77
+ const enter = (run: () => Promise<void> | void) => (e: KeyboardEvent) => {
78
+ if (e.key === "Enter") {
79
+ e.preventDefault();
80
+ void run();
81
+ }
82
+ };
83
+
84
+ const picker = $derived(signInServicePicker(providers, text, lang, s.services, () => glyphFor(keys.service)!));
85
+ const pickerText = $derived({
86
+ search: text.services.search,
87
+ none: text.services.searchNone,
88
+ clear: text.services.clear,
89
+ close: text.close,
90
+ cancel: text.cancel,
91
+ back: text.back,
92
+ });
93
+ </script>
94
+
95
+ {#snippet said()}
96
+ {#if s.said}
97
+ <p class={s.said.ok ? "glim-signin-tile-said" : "glim-signin-tile-said glim-signin-tile-said--fail"} role={s.said.ok ? "status" : "alert"}>{s.said.message}</p>
98
+ {/if}
99
+ {/snippet}
100
+
101
+ {#if w.kind === "removePassword"}
102
+ {@const t = text.password}
103
+ {@const goes = passwordGoes(text, lang, s)}
104
+ <Window title={t.removeTitle} text={words} closeOnBackdrop={false} onClose={flow.close} actions={[cancel, act(t.remove, keys.removePassword, "remove-password", flow.removePassword)]}>
105
+ <div class="glim-signin-tile-body">
106
+ <p class="glim-signin-tile-text">{t.removeText}</p>
107
+ {#if goes.length > 0}
108
+ <ul class="glim-signin-tile-goes">
109
+ {#each goes as g (g)}<li>{g}</li>{/each}
110
+ </ul>
111
+ {/if}
112
+ <FieldRow label={t.current}>
113
+ <PasswordField
114
+ autocomplete="current-password"
115
+ value={s.draft.current}
116
+ oninput={(e) => flow.set("current", e.currentTarget.value)}
117
+ onkeydown={enter(flow.removePassword)}
118
+ text={eye}
119
+ error={err("current")}
120
+ />
121
+ </FieldRow>
122
+ </div>
123
+ </Window>
124
+ {:else if w.kind === "twoFactorSetup" || w.kind === "twoFactorOff"}
125
+ {@const t = text.twoFactor}
126
+ {@const setup = w.kind === "twoFactorSetup"}
127
+ {@const run = setup ? flow.confirmTwoFactor : flow.turnTwoFactorOff}
128
+ {@const empty = s.draft.code.trim() === ""}
129
+ {@const qr = w.kind === "twoFactorSetup" ? qrCode(w.uri) : null}
130
+ <Window
131
+ title={setup ? t.setupTitle : t.offTitle}
132
+ text={words}
133
+ closeOnBackdrop={false}
134
+ onClose={flow.close}
135
+ actions={setup
136
+ ? [act(t.confirm, keys.confirm, "two-factor-confirm", run, { primary: true, disabled: empty })]
137
+ : [cancel, act(t.offConfirm, keys.turnOff, "two-factor-off", run, { disabled: empty })]}
138
+ >
139
+ <div class="glim-signin-tile-body">
140
+ <p class="glim-signin-tile-text">{setup ? t.scan : t.offText}</p>
141
+ {#if qr}
142
+ <svg class="glim-signin-tile-qr" viewBox={`-2 -2 ${qr.size + 4} ${qr.size + 4}`} role="img" aria-label={t.qr}>
143
+ <path d={qr.path} />
144
+ </svg>
145
+ {/if}
146
+ {#if w.kind === "twoFactorSetup"}
147
+ <FieldRow label={t.key}>
148
+ <CopyField value={w.secret.replace(/(.{4})(?=.)/g, "$1 ")} text={copyWords} />
149
+ </FieldRow>
150
+ {/if}
151
+ <FieldRow label={t.code}>
152
+ <TextField
153
+ inputmode={setup ? "numeric" : "text"}
154
+ autocomplete="one-time-code"
155
+ spellcheck={false}
156
+ width="short"
157
+ value={s.draft.code}
158
+ oninput={(e) => flow.set("code", e.currentTarget.value)}
159
+ onkeydown={enter(run)}
160
+ error={err("code")}
161
+ />
162
+ </FieldRow>
163
+ </div>
164
+ </Window>
165
+ {:else if w.kind === "recoveryCodes"}
166
+ {@const t = text.twoFactor}
167
+ <Window
168
+ title={t.codesTitle}
169
+ text={words}
170
+ closeOnBackdrop={false}
171
+ onClose={flow.close}
172
+ actions={[
173
+ act(t.copyCodes, keys.copy, "two-factor-copy", flow.copyCodes),
174
+ { label: t.codesSaved, labelKey: keys.confirm, primary: true, wayOut: true, attrs: { "data-signin-tile": "two-factor-saved" } },
175
+ ]}
176
+ >
177
+ <div class="glim-signin-tile-body">
178
+ <p class="glim-signin-tile-text">{t.codesText}</p>
179
+ <ul class="glim-signin-tile-codes">
180
+ {#each w.codes as c (c)}<li>{c}</li>{/each}
181
+ </ul>
182
+ </div>
183
+ </Window>
184
+ {:else if w.kind === "addPasskey" || w.kind === "renamePasskey"}
185
+ {@const t = text.passkeys}
186
+ {@const add = w.kind === "addPasskey"}
187
+ {@const run = add ? flow.addPasskey : flow.renamePasskey}
188
+ <Window
189
+ title={add ? t.addTitle : t.renameTitle}
190
+ text={words}
191
+ closeOnBackdrop={false}
192
+ onClose={flow.close}
193
+ actions={[add ? act(t.continue, keys.passkey, "passkey-add", run, { primary: true }) : act(text.save, keys.save, "passkey-rename", run, { primary: true })]}
194
+ >
195
+ <div class="glim-signin-tile-body">
196
+ <FieldRow label={t.name} hint={t.nameHint}>
197
+ <TextField value={s.draft.name} oninput={(e) => flow.set("name", e.currentTarget.value)} onkeydown={enter(run)} error={err("name")} />
198
+ </FieldRow>
199
+ {@render said()}
200
+ </div>
201
+ </Window>
202
+ {:else if w.kind === "newToken"}
203
+ {@const t = text.tokens}
204
+ <Window title={t.newTitle} text={words} closeOnBackdrop={false} onClose={flow.close} actions={[act(t.make, keys.createToken, "token-make", flow.makeToken, { primary: true })]}>
205
+ <div class="glim-signin-tile-body">
206
+ {#if s.me?.via === "open"}<p class="glim-signin-tile-text">{t.openHint}</p>{/if}
207
+ <FieldRowGroup>
208
+ <FieldRow label={t.name} hint={t.nameHint}>
209
+ <TextField value={s.draft.name} oninput={(e) => flow.set("name", e.currentTarget.value)} onkeydown={enter(flow.makeToken)} error={err("name")} />
210
+ </FieldRow>
211
+ <FieldRow label={t.scope}>
212
+ <Selector inline activation="manual" value={s.draft.scope} onChange={(v) => flow.set("scope", v)} items={signInScopeItems(scopes, t.scopes)} />
213
+ </FieldRow>
214
+ <FieldRow label={t.lifetime}>
215
+ <Selector
216
+ inline
217
+ activation="manual"
218
+ value={s.draft.life}
219
+ onChange={(v) => flow.set("life", v)}
220
+ items={SIGN_IN_TOKEN_LIVES.map((id) => ({ id, label: t.lifetimes[id] }))}
221
+ />
222
+ </FieldRow>
223
+ </FieldRowGroup>
224
+ </div>
225
+ </Window>
226
+ {:else if w.kind === "tokenShown"}
227
+ {@const t = text.tokens}
228
+ <Window title={t.shownTitle} text={words} closeOnBackdrop={false} onClose={flow.close} actions={[{ label: t.shownDone, labelKey: keys.confirm, primary: true, wayOut: true }]}>
229
+ <div class="glim-signin-tile-body">
230
+ <p class="glim-signin-tile-text">{t.shownText}</p>
231
+ <FieldRow label={w.name}>
232
+ <CopyField value={w.value} text={copyWords} />
233
+ </FieldRow>
234
+ </div>
235
+ </Window>
236
+ {:else if w.kind === "pickService"}
237
+ <PickerWindow
238
+ title={text.services.pick}
239
+ hint={text.services.pickHint}
240
+ items={picker.items}
241
+ groups={picker.groups}
242
+ text={pickerText}
243
+ onPick={flow.chooseService}
244
+ onClose={flow.close}
245
+ />
246
+ {:else}
247
+ {@const t = text.services}
248
+ {@const name = signInServiceName(text, w.provider, s.draft.label, providers.entries.find((e) => e.id === w.provider)?.name)}
249
+ {@const editing = s.services?.find((x) => x.id === w.edit)}
250
+ {@const test = s.formTest}
251
+ {#snippet field(key: SignInTileField, label: string, hint?: string, placeholder?: string)}
252
+ <FieldRow {label} {hint}>
253
+ <TextField
254
+ mono={key !== "label"}
255
+ value={s.draft[key]}
256
+ {placeholder}
257
+ oninput={(e) => flow.set(key, e.currentTarget.value)}
258
+ onpaste={key === "clientId" ? (e) => flow.pasteClient(e.clipboardData?.getData("text") ?? "") && e.preventDefault() : undefined}
259
+ error={err(key)}
260
+ data-signin-field={key}
261
+ />
262
+ </FieldRow>
263
+ {/snippet}
264
+ {#snippet more()}
265
+ <FieldRowGroup>
266
+ {@render field("scopes", t.scopes)}
267
+ {@render field("nameClaim", t.nameClaim)}
268
+ {@render field("groupsClaim", t.groupsClaim)}
269
+ </FieldRowGroup>
270
+ {/snippet}
271
+ <PickerWindow
272
+ title={name}
273
+ items={picker.items}
274
+ groups={picker.groups}
275
+ text={pickerText}
276
+ selected={w.provider}
277
+ onPick={flow.chooseService}
278
+ onBack={w.edit ? flow.close : flow.pickService}
279
+ onClose={flow.close}
280
+ actions={[
281
+ act(signInTestLabel(text, test), "test", "service-test", flow.testDraft, {
282
+ glyph: test?.tone === "ok" ? IconCheck : test?.tone === "danger" ? IconClose : undefined,
283
+ tone: test?.busy ? undefined : test?.tone,
284
+ busy: !!test?.busy,
285
+ title: test?.title,
286
+ }),
287
+ w.edit
288
+ ? act(text.save, keys.save, "service-save", flow.saveService, { primary: true })
289
+ : { label: t.turnOn, labelKey: keys.turnOn, primary: true, disabled: true, title: t.mustTest, attrs: { "data-signin-tile": "service-turn-on" } },
290
+ ]}
291
+ >
292
+ <div class="glim-signin-tile-form" data-signin-form={w.provider}>
293
+ <p class="glim-signin-tile-text">{fill(t.formHint, { name })}</p>
294
+ <FieldRowGroup>
295
+ {@render field("issuer", t.issuer, t.issuerHint)}
296
+ {@render field("clientId", t.clientId)}
297
+ <FieldRow label={t.secret} hint={w.edit ? t.secretKept : undefined}>
298
+ <PasswordField
299
+ autocomplete="off"
300
+ value={s.draft.secret}
301
+ oninput={(e) => flow.set("secret", e.currentTarget.value)}
302
+ text={eye}
303
+ error={err("secret")}
304
+ data-signin-field="secret"
305
+ />
306
+ </FieldRow>
307
+ <FieldRow label={t.redirect} hint={t.redirectHint}>
308
+ <CopyField value={signInRedirectAddress(api, editing)} text={copyWords} />
309
+ </FieldRow>
310
+ {@render field("label", t.label, undefined, signInServiceLabel({ provider: w.provider }, providers, text).name)}
311
+ {@const roleItems = signInRoleItems(text, s.roles)}
312
+ {#if roleItems}
313
+ <FieldRow label={t.role} data-signin-field="role">
314
+ <Selector inline activation="manual" value={s.draft.role} onChange={(v) => flow.set("role", v)} items={roleItems} />
315
+ </FieldRow>
316
+ {/if}
317
+ </FieldRowGroup>
318
+ <Accordion items={[{ value: "more", title: t.more }]} content={more} />
319
+ <p class="glim-signin-tile-quiet">{signInServiceQuiet(text, s, name)}</p>
320
+ {@render said()}
321
+ </div>
322
+ </PickerWindow>
323
+ {/if}
@@ -0,0 +1,14 @@
1
+ import { type Catalog, type SignInApi, type SignInTileFlow, type SignInTileLabelKeys, type SignInTileState, type SignInTileText } from "@glimstone/core";
2
+ type $$ComponentProps = {
3
+ flow: SignInTileFlow;
4
+ flowState: SignInTileState;
5
+ api: SignInApi;
6
+ text: SignInTileText;
7
+ lang: string;
8
+ scopes: string[];
9
+ providers: Catalog;
10
+ keys: SignInTileLabelKeys;
11
+ };
12
+ declare const SignInTileWindow: import("svelte").Component<$$ComponentProps, {}, "">;
13
+ type SignInTileWindow = ReturnType<typeof SignInTileWindow>;
14
+ export default SignInTileWindow;
package/dist/index.d.ts CHANGED
@@ -54,8 +54,10 @@ export { default as RowMark, type RowMarkProps } from "./RowMark.svelte";
54
54
  export { default as Selector, selectorTabId, type SelectMode, type SelectorActivation, type SelectorItem, type SelectorOrientation, type SelectorProps, type SelectorSize, type SelectorVariant } from "./Selector.svelte";
55
55
  export { default as Sheet, type SheetProps } from "./Sheet.svelte";
56
56
  export { default as SidebarRow, type SidebarCount, type SidebarRowProps } from "./SidebarRow.svelte";
57
- export { default as SignInCard, type ResetAnswer, type SignInAnswer, type SignInCardProps, type SignInLabelKeys, type SignInText } from "./SignInCard.svelte";
57
+ export { default as SignInCard, type ResetAnswer, type SignInAnswer, type SignInCardProps, type SignInCardService, type SignInLabelKeys, type SignInText } from "./SignInCard.svelte";
58
58
  export { default as SignInField, type SignInFieldProps } from "./SignInField.svelte";
59
+ export { default as SignInReauthWindow, type SignInReauthText, type SignInReauthWindowProps } from "./SignInReauthWindow.svelte";
60
+ export { default as SignInTile, type SignInTileCard, type SignInTileLabelKeys, type SignInTileProps, type SignInTileText } from "./SignInTile.svelte";
59
61
  export { default as SkeletonRow, type SkeletonRowProps } from "./SkeletonRow.svelte";
60
62
  export { default as SubCard, type SubCardProps } from "./SubCard.svelte";
61
63
  export { default as Table, type TableColumn, type TableProps } from "./Table.svelte";
package/dist/index.js CHANGED
@@ -56,6 +56,8 @@ export { default as Sheet } from "./Sheet.svelte";
56
56
  export { default as SidebarRow } from "./SidebarRow.svelte";
57
57
  export { default as SignInCard } from "./SignInCard.svelte";
58
58
  export { default as SignInField } from "./SignInField.svelte";
59
+ export { default as SignInReauthWindow } from "./SignInReauthWindow.svelte";
60
+ export { default as SignInTile } from "./SignInTile.svelte";
59
61
  export { default as SkeletonRow } from "./SkeletonRow.svelte";
60
62
  export { default as SubCard } from "./SubCard.svelte";
61
63
  export { default as Table } from "./Table.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glimstone/svelte",
3
- "version": "4.8.4",
3
+ "version": "4.9.0",
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.8.4"
144
+ "@glimstone/core": "4.9.0"
145
145
  },
146
146
  "peerDependencies": {
147
147
  "@internationalized/date": "^3.12.4",