@nymphjs/tilmeld-components 1.0.0-beta.15 → 1.0.0-beta.150

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,11 +1,13 @@
1
- {#if clientConfig != null && clientConfig.pwRecovery}
1
+ <svelte:options runes />
2
+
3
+ {#if $clientConfig != null && $clientConfig.pwRecovery}
2
4
  <Dialog
3
- use={usePass}
5
+ {use}
4
6
  bind:open
5
7
  aria-labelledby="tilmeld-recovery-title"
6
8
  aria-describedby="tilmeld-recovery-content"
7
9
  surface$class="tilmeld-recover-dialog-surface"
8
- {...exclude($$restProps, [
10
+ {...exclude(restProps, [
9
11
  'recoveryTypePassword$',
10
12
  'recoveryTypeUsername$',
11
13
  'account$',
@@ -26,179 +28,199 @@
26
28
  {#if successRecoveredMessage}
27
29
  {successRecoveredMessage}
28
30
  {:else}
29
- {#if !hasSentSecret}
30
- {#if !clientConfig.emailUsernames}
31
- <div>
32
- <FormField style="margin-right: 1em;">
33
- <Radio
34
- bind:group={recoveryType}
35
- value="password"
36
- {...prefixFilter($$restProps, 'recoveryTypePassword$')}
37
- />
38
- <span slot="label">I don't know my password.</span>
39
- </FormField>
40
- <FormField style="margin-right: 1em;">
41
- <Radio
42
- bind:group={recoveryType}
43
- value="username"
44
- {...prefixFilter($$restProps, 'recoveryTypeUsername$')}
45
- />
46
- <span slot="label">I don't know my username.</span>
47
- </FormField>
48
- </div>
49
- {/if}
50
-
51
- <div>
52
- {#if recoveryType === 'password'}
53
- <p>
54
- To reset your password, type the {clientConfig.emailUsernames
55
- ? 'email'
56
- : 'username'}
57
- you use to sign in below.
58
- </p>
31
+ <form
32
+ onsubmit={preventDefault(
33
+ stopPropagation(() => {
34
+ if (!successRecoveredMessage) {
35
+ if (!hasSentSecret) {
36
+ sendRecovery();
37
+ } else {
38
+ recover();
39
+ }
40
+ }
41
+ }),
42
+ )}
43
+ >
44
+ {#if !hasSentSecret}
45
+ {#if !$clientConfig.emailUsernames}
46
+ <div>
47
+ <FormField style="margin-right: 1em;">
48
+ <Radio
49
+ bind:group={recoveryType}
50
+ value="password"
51
+ {...prefixFilter(restProps, 'recoveryTypePassword$')}
52
+ />
53
+ {#snippet label()}
54
+ I don't know my password.
55
+ {/snippet}
56
+ </FormField>
57
+ <FormField style="margin-right: 1em;">
58
+ <Radio
59
+ bind:group={recoveryType}
60
+ value="username"
61
+ {...prefixFilter(restProps, 'recoveryTypeUsername$')}
62
+ />
63
+ {#snippet label()}
64
+ I don't know my username.
65
+ {/snippet}
66
+ </FormField>
67
+ </div>
59
68
  {/if}
60
- {#if recoveryType === 'username'}
61
- <p>
62
- To get your username, type your email as you entered it when
63
- creating your account.
64
- </p>
65
- {/if}
66
- </div>
67
69
 
68
- <div>
69
- <Textfield
70
- bind:this={accountElem}
71
- bind:value={account}
72
- label={clientConfig.emailUsernames || recoveryType === 'username'
73
- ? 'Email Address'
74
- : 'Username'}
75
- type={clientConfig.emailUsernames || recoveryType === 'username'
76
- ? 'email'
77
- : 'text'}
78
- input$autocomplete={clientConfig.emailUsernames ||
79
- recoveryType === 'username'
80
- ? 'email'
81
- : 'username'}
82
- input$autocapitalize="off"
83
- input$spellcheck="false"
84
- {...prefixFilter($$restProps, 'account$')}
85
- />
86
- </div>
87
-
88
- {#if recoveryType === 'password'}
89
- <div class="tilmeld-recover-action">
90
- <a
91
- href="javascript:void(0);"
92
- on:click={() => (hasSentSecret = 1)}
93
- {...prefixFilter($$restProps, 'alreadyGotCodeLink$')}
94
- >
95
- Already Got a Code?
96
- </a>
70
+ <div>
71
+ {#if recoveryType === 'password'}
72
+ <p>
73
+ To reset your password, type the {$clientConfig.emailUsernames
74
+ ? 'email'
75
+ : 'username'}
76
+ you use to sign in below.
77
+ </p>
78
+ {/if}
79
+ {#if recoveryType === 'username'}
80
+ <p>
81
+ To get your username, type your email as you entered it when
82
+ creating your account.
83
+ </p>
84
+ {/if}
97
85
  </div>
98
- {/if}
99
- {:else}
100
- <div>
101
- <p {...prefixFilter($$restProps, 'codeSentMessage$')}>
102
- A code has been sent to you by email. Enter that code here, and a
103
- new password for your account.
104
- </p>
105
- </div>
106
86
 
107
- {#if hasSentSecret === 1}
108
87
  <div>
109
88
  <Textfield
110
89
  bind:this={accountElem}
111
90
  bind:value={account}
112
- label={clientConfig.emailUsernames
91
+ label={$clientConfig.emailUsernames ||
92
+ recoveryType === 'username'
113
93
  ? 'Email Address'
114
94
  : 'Username'}
115
- type={clientConfig.emailUsernames ? 'email' : 'text'}
116
- input$autocomplete={clientConfig.emailUsernames
95
+ type={$clientConfig.emailUsernames ||
96
+ recoveryType === 'username'
97
+ ? 'email'
98
+ : 'text'}
99
+ input$autocomplete={$clientConfig.emailUsernames ||
100
+ recoveryType === 'username'
117
101
  ? 'email'
118
102
  : 'username'}
119
103
  input$autocapitalize="off"
120
104
  input$spellcheck="false"
121
- {...prefixFilter($$restProps, 'account$')}
105
+ {...prefixFilter(restProps, 'account$')}
122
106
  />
123
107
  </div>
124
- {/if}
125
108
 
126
- <div>
127
- <Textfield
128
- bind:value={secret}
129
- label="Recovery Code"
130
- type="text"
131
- input$autocomplete="one-time-code"
132
- {...prefixFilter($$restProps, 'recoveryCode$')}
133
- />
134
- </div>
109
+ {#if recoveryType === 'password'}
110
+ <div class="tilmeld-recover-action">
111
+ <a
112
+ href={'javascript:void(0);'}
113
+ onclick={() => (hasSentSecret = 1)}
114
+ {...prefixFilter(restProps, 'alreadyGotCodeLink$')}
115
+ >
116
+ Already Got a Code?
117
+ </a>
118
+ </div>
119
+ {/if}
120
+ {:else}
121
+ <div>
122
+ <p {...prefixFilter(restProps, 'codeSentMessage$')}>
123
+ A code has been sent to you by email. Enter that code here, and
124
+ a new password for your account.
125
+ </p>
126
+ </div>
127
+
128
+ {#if hasSentSecret === 1}
129
+ <div>
130
+ <Textfield
131
+ bind:this={accountElem}
132
+ bind:value={account}
133
+ label={$clientConfig.emailUsernames
134
+ ? 'Email Address'
135
+ : 'Username'}
136
+ type={$clientConfig.emailUsernames ? 'email' : 'text'}
137
+ input$autocomplete={$clientConfig.emailUsernames
138
+ ? 'email'
139
+ : 'username'}
140
+ input$autocapitalize="off"
141
+ input$spellcheck="false"
142
+ {...prefixFilter(restProps, 'account$')}
143
+ />
144
+ </div>
145
+ {/if}
146
+
147
+ <div>
148
+ <Textfield
149
+ bind:value={secret}
150
+ label="Recovery Code"
151
+ type="text"
152
+ input$autocomplete="one-time-code"
153
+ {...prefixFilter(restProps, 'recoveryCode$')}
154
+ />
155
+ </div>
135
156
 
136
- <div>
137
- <Textfield
138
- bind:value={password}
139
- label="Password"
140
- type="password"
141
- input$autocomplete="new-password"
142
- {...prefixFilter($$restProps, 'password$')}
143
- />
144
- </div>
157
+ <div>
158
+ <Textfield
159
+ bind:value={password}
160
+ label="Password"
161
+ type="password"
162
+ input$autocomplete="new-password"
163
+ {...prefixFilter(restProps, 'password$')}
164
+ />
165
+ </div>
145
166
 
146
- <div>
147
- <Textfield
148
- bind:value={password2}
149
- label="Re-enter Password"
150
- type="password"
151
- input$autocomplete="new-password"
152
- {...prefixFilter($$restProps, 'password2$')}
153
- />
154
- </div>
167
+ <div>
168
+ <Textfield
169
+ bind:value={password2}
170
+ label="Re-enter Password"
171
+ type="password"
172
+ input$autocomplete="new-password"
173
+ {...prefixFilter(restProps, 'password2$')}
174
+ />
175
+ </div>
155
176
 
156
- <div class="tilmeld-recover-action">
157
- <a
158
- href="javascript:void(0);"
159
- on:click={() => (hasSentSecret = false)}
160
- {...prefixFilter($$restProps, 'needCodeLink$')}
161
- >
162
- Need a New Code?
163
- </a>
164
- </div>
165
- {/if}
177
+ <div class="tilmeld-recover-action">
178
+ <a
179
+ href={'javascript:void(0);'}
180
+ onclick={() => (hasSentSecret = false)}
181
+ {...prefixFilter(restProps, 'needCodeLink$')}
182
+ >
183
+ Need a New Code?
184
+ </a>
185
+ </div>
186
+ {/if}
166
187
 
167
- {#if failureMessage}
168
- <div class="tilmeld-recover-failure">
169
- {failureMessage}
170
- </div>
171
- {/if}
188
+ {#if failureMessage}
189
+ <div class="tilmeld-recover-failure">
190
+ {failureMessage}
191
+ </div>
192
+ {/if}
172
193
 
173
- {#if recovering}
174
- <div class="tilmeld-recover-loading">
175
- <CircularProgress
176
- style="height: 24px; width: 24px;"
177
- indeterminate
178
- {...prefixFilter($$restProps, 'progress$')}
179
- />
180
- </div>
181
- {/if}
194
+ {#if loading}
195
+ <div class="tilmeld-recover-loading">
196
+ <CircularProgress
197
+ style="height: 24px; width: 24px;"
198
+ indeterminate
199
+ {...prefixFilter(restProps, 'progress$')}
200
+ />
201
+ </div>
202
+ {/if}
203
+ </form>
182
204
  {/if}
183
205
  </Content>
184
206
  <Actions>
185
- <Button on:click={() => (open = false)} disabled={recovering}>
207
+ <Button onclick={() => (open = false)} disabled={loading}>
186
208
  <Label>{successRecoveredMessage ? 'Close' : 'Cancel'}</Label>
187
209
  </Button>
188
210
  {#if !successRecoveredMessage}
189
211
  {#if !hasSentSecret}
190
212
  <Button
191
- on:click$preventDefault$stopPropagation={sendRecovery}
192
- disabled={recovering}
193
- {...prefixFilter($$restProps, 'sendCodeButton$')}
213
+ onclick={preventDefault(stopPropagation(sendRecovery))}
214
+ disabled={loading}
215
+ {...prefixFilter(restProps, 'sendCodeButton$')}
194
216
  >
195
217
  <Label>Send Recovery</Label>
196
218
  </Button>
197
219
  {:else}
198
220
  <Button
199
- on:click$preventDefault$stopPropagation={recover}
200
- disabled={recovering}
201
- {...prefixFilter($$restProps, 'resetPasswordButton$')}
221
+ onclick={preventDefault(stopPropagation(recover))}
222
+ disabled={loading}
223
+ {...prefixFilter(restProps, 'resetPasswordButton$')}
202
224
  >
203
225
  <Label>Reset Password</Label>
204
226
  </Button>
@@ -209,8 +231,10 @@
209
231
  {/if}
210
232
 
211
233
  <script lang="ts">
234
+ import type { ComponentProps } from 'svelte';
212
235
  import { onMount } from 'svelte';
213
- import { get_current_component } from 'svelte/internal';
236
+ import type { Writable } from 'svelte/store';
237
+ import { writable } from 'svelte/store';
214
238
  import CircularProgress from '@smui/circular-progress';
215
239
  import Dialog, { Title, Content, Actions } from '@smui/dialog';
216
240
  import Textfield from '@smui/textfield';
@@ -218,53 +242,147 @@
218
242
  import FormField from '@smui/form-field';
219
243
  import Radio from '@smui/radio';
220
244
  import type { ActionArray } from '@smui/common/internal';
221
- import {
222
- forwardEventsBuilder,
223
- exclude,
224
- prefixFilter,
225
- } from '@smui/common/internal';
245
+ import { exclude, prefixFilter } from '@smui/common/internal';
246
+ import { preventDefault, stopPropagation } from '@smui/common/events';
247
+ import type { SmuiElementPropMap } from '@smui/common';
226
248
  import type {
227
249
  User as UserClass,
228
250
  ClientConfig,
229
251
  } from '@nymphjs/tilmeld-client';
230
252
 
231
- const forwardEvents = forwardEventsBuilder(get_current_component());
232
-
233
- export let use: ActionArray = [];
234
- $: usePass = [forwardEvents, ...use] as ActionArray;
235
- export let open = false;
236
- export let title = 'Recover Your Account';
237
- export let clientConfig: ClientConfig | undefined = undefined;
238
- export let User: typeof UserClass;
253
+ type OwnProps = {
254
+ /**
255
+ * An array of Action or [Action, ActionProps] to be applied to the element.
256
+ */
257
+ use?: ActionArray;
258
+ /**
259
+ * Whether the dialog is open.
260
+ */
261
+ open?: boolean;
262
+ /**
263
+ * The title of the dialog.
264
+ */
265
+ title?: string;
266
+ /**
267
+ * A writable store of the Nymph client config.
268
+ *
269
+ * It will be retrieved from the server if not provided.
270
+ */
271
+ clientConfig?: Writable<ClientConfig | undefined>;
272
+ /**
273
+ * The User class from Nymph.
274
+ */
275
+ User: typeof UserClass;
276
+ /**
277
+ * Give focus to the account box when the form is ready.
278
+ */
279
+ autofocus?: boolean;
280
+ /**
281
+ * The type of recovery being requested.
282
+ *
283
+ * User provided. You can bind to it if you need to.
284
+ */
285
+ recoveryType?: 'username' | 'password';
286
+ /**
287
+ * User provided. You can bind to it if you need to.
288
+ */
289
+ account?: string;
290
+ /**
291
+ * User provided. You can bind to it if you need to.
292
+ */
293
+ secret?: string;
294
+ /**
295
+ * User provided. You can bind to it if you need to.
296
+ */
297
+ password?: string;
298
+ /**
299
+ * User provided. You can bind to it if you need to.
300
+ */
301
+ password2?: string;
302
+ };
303
+ let {
304
+ use = [],
305
+ open = $bindable(false),
306
+ title = 'Recover Your Account',
307
+ clientConfig = $bindable(writable(false as unknown as undefined)),
308
+ User,
309
+ autofocus = true,
310
+ recoveryType = $bindable('password'),
311
+ account = $bindable(''),
312
+ secret = $bindable(''),
313
+ password = $bindable(''),
314
+ password2 = $bindable(''),
315
+ ...restProps
316
+ }: OwnProps & {
317
+ [
318
+ k in keyof ComponentProps<typeof Radio> as `recoveryTypePassword\$${k}`
319
+ ]?: ComponentProps<typeof Radio>[k];
320
+ } & {
321
+ [
322
+ k in keyof ComponentProps<typeof Radio> as `recoveryTypeUsername\$${k}`
323
+ ]?: ComponentProps<typeof Radio>[k];
324
+ } & {
325
+ [
326
+ k in keyof ComponentProps<typeof Textfield> as `account\$${k}`
327
+ ]?: ComponentProps<typeof Textfield>[k];
328
+ } & {
329
+ [
330
+ k in keyof SmuiElementPropMap['a'] as `alreadyGotCodeLink\$${k}`
331
+ ]?: SmuiElementPropMap['a'][k];
332
+ } & {
333
+ [
334
+ k in keyof SmuiElementPropMap['p'] as `codeSentMessage\$${k}`
335
+ ]?: SmuiElementPropMap['p'][k];
336
+ } & {
337
+ [
338
+ k in keyof ComponentProps<typeof Textfield> as `recoveryCode\$${k}`
339
+ ]?: ComponentProps<typeof Textfield>[k];
340
+ } & {
341
+ [
342
+ k in keyof ComponentProps<typeof Textfield> as `password\$${k}`
343
+ ]?: ComponentProps<typeof Textfield>[k];
344
+ } & {
345
+ [
346
+ k in keyof ComponentProps<typeof Textfield> as `password2\$${k}`
347
+ ]?: ComponentProps<typeof Textfield>[k];
348
+ } & {
349
+ [
350
+ k in keyof SmuiElementPropMap['a'] as `needCodeLink\$${k}`
351
+ ]?: SmuiElementPropMap['a'][k];
352
+ } & {
353
+ [
354
+ k in keyof ComponentProps<typeof CircularProgress> as `progress\$${k}`
355
+ ]?: ComponentProps<typeof CircularProgress>[k];
356
+ } & {
357
+ [
358
+ k in keyof ComponentProps<
359
+ typeof Button<undefined, 'button'>
360
+ > as `sendCodeButton\$${k}`
361
+ ]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
362
+ } & {
363
+ [
364
+ k in keyof ComponentProps<
365
+ typeof Button<undefined, 'button'>
366
+ > as `resetPasswordButton\$${k}`
367
+ ]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
368
+ } = $props();
239
369
 
240
- // Give focus to the account box when the form is ready.
241
- export let autofocus = true;
242
- export let recoveryType: 'username' | 'password' = 'password';
370
+ let loading = $state(false);
371
+ let hasSentSecret: number | boolean = $state(false);
372
+ let accountElem: Textfield | undefined = $state();
373
+ let failureMessage: string | undefined = $state();
374
+ let successRecoveredMessage: string | undefined = $state();
243
375
 
244
- /** User provided. You can bind to it if you need to. */
245
- export let account = '';
246
- /** User provided. You can bind to it if you need to. */
247
- export let secret = '';
248
- /** User provided. You can bind to it if you need to. */
249
- export let password = '';
250
- /** User provided. You can bind to it if you need to. */
251
- export let password2 = '';
252
-
253
- let recovering = false;
254
- let hasSentSecret: number | boolean = false;
255
- let accountElem: Textfield;
256
- let failureMessage: string | undefined = undefined;
257
- let successRecoveredMessage: string | undefined = undefined;
258
-
259
- $: {
376
+ $effect(() => {
260
377
  if (open && autofocus && accountElem) {
261
378
  accountElem.focus();
262
379
  }
263
- }
380
+ });
264
381
 
265
382
  onMount(async () => {
266
- if (clientConfig === undefined) {
267
- clientConfig = await User.getClientConfig();
383
+ if ($clientConfig === (false as unknown as undefined)) {
384
+ $clientConfig = undefined;
385
+ $clientConfig = await User.getClientConfig();
268
386
  }
269
387
  });
270
388
 
@@ -272,7 +390,7 @@
272
390
  if (account === '') {
273
391
  failureMessage =
274
392
  'You need to enter ' +
275
- (clientConfig?.emailUsernames || recoveryType === 'username'
393
+ ($clientConfig?.emailUsernames || recoveryType === 'username'
276
394
  ? 'an email address'
277
395
  : 'a username') +
278
396
  '.';
@@ -280,7 +398,7 @@
280
398
  }
281
399
 
282
400
  failureMessage = undefined;
283
- recovering = true;
401
+ loading = true;
284
402
 
285
403
  try {
286
404
  const data = await User.sendRecovery({
@@ -299,14 +417,14 @@
299
417
  } catch (e: any) {
300
418
  failureMessage = e?.message;
301
419
  }
302
- recovering = false;
420
+ loading = false;
303
421
  }
304
422
 
305
423
  async function recover() {
306
424
  if (account === '') {
307
425
  failureMessage =
308
426
  'You need to enter ' +
309
- (clientConfig?.emailUsernames || recoveryType === 'username'
427
+ ($clientConfig?.emailUsernames || recoveryType === 'username'
310
428
  ? 'an email address'
311
429
  : 'a username') +
312
430
  '.';
@@ -322,7 +440,7 @@
322
440
  }
323
441
 
324
442
  failureMessage = undefined;
325
- recovering = true;
443
+ loading = true;
326
444
  try {
327
445
  const data = await User.recover({
328
446
  username: account,
@@ -337,7 +455,7 @@
337
455
  } catch (e: any) {
338
456
  failureMessage = e?.message;
339
457
  }
340
- recovering = false;
458
+ loading = false;
341
459
  }
342
460
  </script>
343
461