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

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,14 +1,17 @@
1
- {#if user != null}
1
+ <svelte:options runes />
2
+
3
+ {#if $user != null}
2
4
  <Dialog
3
- use={usePass}
5
+ {use}
4
6
  bind:open
5
7
  aria-labelledby="tilmeld-password-title"
6
8
  aria-describedby="tilmeld-password-content"
7
9
  surface$class="tilmeld-password-dialog-surface"
8
- {...exclude($$restProps, [
10
+ {...exclude(restProps, [
9
11
  'password$',
10
12
  'newPassword$',
11
13
  'newPassword2$',
14
+ 'revokeTokens$',
12
15
  'closeButton$',
13
16
  'saveButton$',
14
17
  'progress$',
@@ -17,68 +20,84 @@
17
20
  <!-- Title cannot contain leading whitespace due to mdc-typography-baseline-top() -->
18
21
  <Title id="tilmeld-password-title">{title}</Title>
19
22
  <Content id="tilmeld-password-content">
20
- <div>
21
- <Textfield
22
- bind:value={currentPassword}
23
- label="Current Password"
24
- type="password"
25
- style="width: 100%;"
26
- input$autocomplete="current-password"
27
- {...prefixFilter($$restProps, 'password$')}
28
- />
29
- </div>
30
-
31
- <div>
32
- <Textfield
33
- bind:value={newPassword}
34
- label="New Password"
35
- type="password"
36
- style="width: 100%;"
37
- input$autocomplete="new-password"
38
- {...prefixFilter($$restProps, 'newPassword$')}
39
- />
40
- </div>
41
-
42
- <div>
43
- <Textfield
44
- bind:value={newPassword2}
45
- label="Re-enter New Password"
46
- type="password"
47
- style="width: 100%;"
48
- input$autocomplete="new-password"
49
- {...prefixFilter($$restProps, 'newPassword2$')}
50
- />
51
- </div>
52
-
53
- <slot name="additional" />
54
-
55
- {#if failureMessage}
56
- <div class="tilmeld-password-failure">
57
- {failureMessage}
23
+ <form onsubmit={preventDefault(stopPropagation(changePassword))}>
24
+ <div>
25
+ <Textfield
26
+ bind:value={currentPassword}
27
+ label="Current Password"
28
+ type="password"
29
+ style="width: 100%;"
30
+ input$autocomplete="current-password"
31
+ {...prefixFilter(restProps, 'password$')}
32
+ />
58
33
  </div>
59
- {/if}
60
-
61
- {#if changing}
62
- <div class="tilmeld-password-loading">
63
- <CircularProgress
64
- style="height: 24px; width: 24px;"
65
- indeterminate
66
- {...prefixFilter($$restProps, 'progress$')}
34
+
35
+ <div>
36
+ <Textfield
37
+ bind:value={newPassword}
38
+ label="New Password"
39
+ type="password"
40
+ style="width: 100%;"
41
+ input$autocomplete="new-password"
42
+ {...prefixFilter(restProps, 'newPassword$')}
67
43
  />
68
44
  </div>
69
- {/if}
45
+
46
+ <div>
47
+ <Textfield
48
+ bind:value={newPassword2}
49
+ label="Re-enter New Password"
50
+ type="password"
51
+ style="width: 100%;"
52
+ input$autocomplete="new-password"
53
+ {...prefixFilter(restProps, 'newPassword2$')}
54
+ />
55
+ </div>
56
+
57
+ <div style="margin: 1em 0;">
58
+ <FormField>
59
+ <Checkbox
60
+ bind:checked={revokeCurrentTokens}
61
+ {...prefixFilter(restProps, 'revokeTokens$')}
62
+ />
63
+ {#snippet label()}
64
+ Log out of all other sessions.
65
+ <span
66
+ style="display: block; font-size: 0.7em; height: 0; overflow: visible;"
67
+ >
68
+ Use this if you think you've been hacked.
69
+ </span>
70
+ {/snippet}
71
+ </FormField>
72
+ </div>
73
+
74
+ {@render additional?.()}
75
+
76
+ {#if failureMessage}
77
+ <div class="tilmeld-password-failure">
78
+ {failureMessage}
79
+ </div>
80
+ {/if}
81
+
82
+ {#if loading}
83
+ <div class="tilmeld-password-loading">
84
+ <CircularProgress
85
+ style="height: 24px; width: 24px;"
86
+ indeterminate
87
+ {...prefixFilter(restProps, 'progress$')}
88
+ />
89
+ </div>
90
+ {/if}
91
+ </form>
70
92
  </Content>
71
93
  <Actions>
72
- <Button
73
- disabled={changing}
74
- {...prefixFilter($$restProps, 'closeButton$')}
75
- >
94
+ <Button disabled={loading} {...prefixFilter(restProps, 'closeButton$')}>
76
95
  <Label>Close</Label>
77
96
  </Button>
78
97
  <Button
79
- on:click$preventDefault$stopPropagation={changePassword}
80
- disabled={changing}
81
- {...prefixFilter($$restProps, 'saveButton$')}
98
+ onclick={preventDefault(stopPropagation(changePassword))}
99
+ disabled={loading}
100
+ {...prefixFilter(restProps, 'saveButton$')}
82
101
  >
83
102
  <Label>Change Password</Label>
84
103
  </Button>
@@ -87,62 +106,140 @@
87
106
  {/if}
88
107
 
89
108
  <script lang="ts">
109
+ import type { ComponentProps, Snippet } from 'svelte';
90
110
  import { onMount, onDestroy } from 'svelte';
91
- import { get_current_component } from 'svelte/internal';
111
+ import type { Writable } from 'svelte/store';
112
+ import { writable } from 'svelte/store';
92
113
  import CircularProgress from '@smui/circular-progress';
93
114
  import Dialog, { Title, Content, Actions } from '@smui/dialog';
94
115
  import Textfield from '@smui/textfield';
116
+ import Checkbox from '@smui/checkbox';
117
+ import FormField from '@smui/form-field';
95
118
  import Button, { Label } from '@smui/button';
96
119
  import type { ActionArray } from '@smui/common/internal';
97
- import {
98
- forwardEventsBuilder,
99
- exclude,
100
- prefixFilter,
101
- } from '@smui/common/internal';
120
+ import { exclude, prefixFilter } from '@smui/common/internal';
121
+ import { preventDefault, stopPropagation } from '@smui/common/events';
102
122
  import type { CurrentUserData } from '@nymphjs/tilmeld-client';
103
123
  import type { User as UserClass } from '@nymphjs/tilmeld-client';
104
124
 
105
- const forwardEvents = forwardEventsBuilder(get_current_component());
125
+ type OwnProps = {
126
+ /**
127
+ * An array of Action or [Action, ActionProps] to be applied to the element.
128
+ */
129
+ use?: ActionArray;
130
+ /**
131
+ * Whether the dialog is open.
132
+ */
133
+ open?: boolean;
134
+ /**
135
+ * The title of the dialog.
136
+ */
137
+ title?: string;
138
+ /**
139
+ * The User class from Nymph.
140
+ */
141
+ User: typeof UserClass;
142
+ /**
143
+ * A writable store of the current user.
144
+ *
145
+ * It will be retrieved from the server if not provided.
146
+ */
147
+ user?: Writable<(UserClass & CurrentUserData) | null | undefined>;
148
+ /**
149
+ * User provided. You can bind to it if you need to.
150
+ */
151
+ currentPassword?: string;
152
+ /**
153
+ * User provided. You can bind to it if you need to.
154
+ */
155
+ newPassword?: string;
156
+ /**
157
+ * User provided. You can bind to it if you need to.
158
+ */
159
+ newPassword2?: string;
160
+ /**
161
+ * User provided. You can bind to it if you need to.
162
+ */
163
+ revokeCurrentTokens?: boolean;
106
164
 
107
- export let use: ActionArray = [];
108
- $: usePass = [forwardEvents, ...use] as ActionArray;
109
- export let open = false;
110
- export let title = 'Change Your Password';
111
- export let User: typeof UserClass;
112
- export let user: (UserClass & CurrentUserData) | undefined = undefined;
113
-
114
- let changing = false;
115
- let failureMessage: string | undefined = undefined;
165
+ /**
166
+ * A spot for additional content.
167
+ */
168
+ additional?: Snippet;
169
+ };
170
+ let {
171
+ use = [],
172
+ open = $bindable(false),
173
+ title = 'Change Your Password',
174
+ User,
175
+ user = $bindable(writable(false as unknown as undefined)),
176
+ currentPassword = $bindable(''),
177
+ newPassword = $bindable(''),
178
+ newPassword2 = $bindable(''),
179
+ revokeCurrentTokens = $bindable(false),
180
+ additional,
181
+ ...restProps
182
+ }: OwnProps & {
183
+ [
184
+ k in keyof ComponentProps<typeof Textfield> as `password\$${k}`
185
+ ]?: ComponentProps<typeof Textfield>[k];
186
+ } & {
187
+ [
188
+ k in keyof ComponentProps<typeof Textfield> as `newPassword\$${k}`
189
+ ]?: ComponentProps<typeof Textfield>[k];
190
+ } & {
191
+ [
192
+ k in keyof ComponentProps<typeof Textfield> as `newPassword2\$${k}`
193
+ ]?: ComponentProps<typeof Textfield>[k];
194
+ } & {
195
+ [
196
+ k in keyof ComponentProps<typeof Checkbox> as `revokeTokens\$${k}`
197
+ ]?: ComponentProps<typeof Checkbox>[k];
198
+ } & {
199
+ [
200
+ k in keyof ComponentProps<typeof CircularProgress> as `progress\$${k}`
201
+ ]?: ComponentProps<typeof CircularProgress>[k];
202
+ } & {
203
+ [
204
+ k in keyof ComponentProps<
205
+ typeof Button<undefined, 'button'>
206
+ > as `closeButton\$${k}`
207
+ ]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
208
+ } & {
209
+ [
210
+ k in keyof ComponentProps<
211
+ typeof Button<undefined, 'button'>
212
+ > as `saveButton\$${k}`
213
+ ]?: ComponentProps<typeof Button<undefined, 'button'>>[k];
214
+ } = $props();
116
215
 
117
- /** User provided. You can bind to it if you need to. */
118
- export let currentPassword = '';
119
- /** User provided. You can bind to it if you need to. */
120
- export let newPassword = '';
121
- /** User provided. You can bind to it if you need to. */
122
- export let newPassword2 = '';
216
+ let loading = $state(false);
217
+ let failureMessage: string | undefined = $state();
123
218
 
124
- $: {
219
+ $effect(() => {
125
220
  if (!open) {
126
- changing = false;
221
+ loading = false;
127
222
  failureMessage = undefined;
128
223
  currentPassword = '';
129
224
  newPassword = '';
130
225
  newPassword2 = '';
226
+ revokeCurrentTokens = false;
131
227
  }
132
- }
228
+ });
133
229
 
134
230
  const onLogin = (currentUser: UserClass & CurrentUserData) => {
135
- user = currentUser;
231
+ $user = currentUser;
136
232
  };
137
233
  const onLogout = () => {
138
- user = undefined;
234
+ $user = null;
139
235
  };
140
236
 
141
237
  onMount(async () => {
142
238
  User.on('login', onLogin);
143
239
  User.on('logout', onLogout);
144
- if (user === undefined) {
145
- user = (await User.current()) ?? undefined;
240
+ if ($user === (false as unknown as undefined)) {
241
+ $user = undefined;
242
+ $user = await User.current();
146
243
  }
147
244
  });
148
245
 
@@ -166,22 +263,23 @@
166
263
  }
167
264
 
168
265
  failureMessage = undefined;
169
- changing = true;
266
+ loading = true;
170
267
 
171
268
  // Get the current user again, in case their data has changed.
172
- user = (await User.current()) ?? undefined;
269
+ $user = await User.current();
173
270
 
174
- if (user == null) {
271
+ if ($user == null) {
175
272
  failureMessage = 'You must be logged in.';
176
- changing = false;
273
+ loading = false;
177
274
  return;
178
275
  }
179
276
 
180
277
  try {
181
278
  // Change the user's password.
182
- const data = await user.$changePassword({
279
+ const data = await $user.$changePassword({
183
280
  currentPassword,
184
281
  newPassword,
282
+ revokeCurrentTokens,
185
283
  });
186
284
 
187
285
  if (!data.result) {
@@ -192,7 +290,7 @@
192
290
  } catch (e: any) {
193
291
  failureMessage = e?.message;
194
292
  }
195
- changing = false;
293
+ loading = false;
196
294
  }
197
295
  </script>
198
296