@madgex/design-system 13.2.0 → 13.3.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.
- package/dist/assets/icons.json +1 -1
- package/dist/css/index.css +1 -1
- package/dist/js/components/mds-timeout-dialog-standalone.js +1 -1
- package/dist/js/index-fractal.js +1 -1
- package/dist/js/index.js +1 -1
- package/dist/js/timeout-dialog-plrFUmdZ.js +28 -0
- package/package.json +1 -1
- package/src/components/_macro-index.njk +1 -0
- package/src/components/conditional-section/README.md +23 -0
- package/src/components/conditional-section/_macro.njk +3 -0
- package/src/components/conditional-section/_template.njk +7 -0
- package/src/components/conditional-section/conditional-section.config.js +99 -0
- package/src/components/conditional-section/conditional-section.js +62 -0
- package/src/components/conditional-section/conditional-section.njk +17 -0
- package/src/components/timeout-dialog/README.md +69 -17
- package/src/components/timeout-dialog/timeout-dialog.js +191 -71
- package/src/components/timeout-dialog/timeout-dialog.njk +6 -0
- package/src/components/timeout-dialog/timeout-dialog.scss +21 -0
- package/src/js/index.js +4 -0
- package/dist/js/timeout-dialog-DuVVAWa3.js +0 -23
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
const ONE_MINUTE_IN_MS = 60000;
|
|
2
2
|
|
|
3
|
+
const STATE = {
|
|
4
|
+
NONE: 'NONE',
|
|
5
|
+
WARNING: 'WARNING',
|
|
6
|
+
TIMED_OUT: 'TIMED_OUT',
|
|
7
|
+
};
|
|
3
8
|
/**
|
|
4
9
|
* Displays a Dialog box when timeout is about to expire. (representing User's Auth session (auth cookie)).
|
|
5
10
|
*
|
|
@@ -13,60 +18,101 @@ const ONE_MINUTE_IN_MS = 60000;
|
|
|
13
18
|
*
|
|
14
19
|
*/
|
|
15
20
|
export class MdsTimeoutDialog extends HTMLElement {
|
|
21
|
+
#state = STATE.NONE;
|
|
22
|
+
#warningDialogTimeout;
|
|
23
|
+
#timedOutDialogTimeout;
|
|
24
|
+
/**
|
|
25
|
+
* if attributes change, we will need to re-render the template.
|
|
26
|
+
*/
|
|
27
|
+
static get observedAttributes() {
|
|
28
|
+
return [
|
|
29
|
+
't-title',
|
|
30
|
+
't-title-timed-out',
|
|
31
|
+
't-message',
|
|
32
|
+
't-message-error-failed-refresh',
|
|
33
|
+
't-btn-stay-refresh',
|
|
34
|
+
't-btn-sign-out',
|
|
35
|
+
't-btn-close',
|
|
36
|
+
'keep-alive-url',
|
|
37
|
+
'login-url',
|
|
38
|
+
'logout-url',
|
|
39
|
+
'warning-in-milliseconds',
|
|
40
|
+
'timeout-in-milliseconds',
|
|
41
|
+
];
|
|
42
|
+
}
|
|
16
43
|
constructor() {
|
|
17
44
|
super();
|
|
18
|
-
|
|
19
45
|
/** good practice to "bind" event listener functions, so `this` always works inside them */
|
|
20
46
|
this.onClickSignInButton = this.onClickSignInButton.bind(this);
|
|
21
47
|
this.onSignedOutDialogClose = this.onSignedOutDialogClose.bind(this);
|
|
48
|
+
|
|
49
|
+
this.dialogIdWarning = `mds-timeout-dialog-warning-${window.crypto.randomUUID()}`;
|
|
50
|
+
this.dialogIdSignedOut = `mds-timeout-dialog-signed-out-${window.crypto.randomUUID()}`;
|
|
22
51
|
}
|
|
23
52
|
connectedCallback() {
|
|
24
|
-
this.
|
|
53
|
+
this.render();
|
|
54
|
+
this.update(STATE.NONE);
|
|
55
|
+
this.#setTimeouts();
|
|
25
56
|
}
|
|
26
57
|
disconnectedCallback() {
|
|
27
|
-
this
|
|
58
|
+
this.#clearTimeouts();
|
|
59
|
+
this.removeEventListeners();
|
|
60
|
+
this.update(STATE.NONE);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* if attributes change, re-render template, refresh state
|
|
64
|
+
* @param {string} name
|
|
65
|
+
* @param {string} oldValue
|
|
66
|
+
* @param {string} newValue
|
|
67
|
+
*/
|
|
68
|
+
attributeChangedCallback(name, oldValue = null, newValue = null) {
|
|
69
|
+
if (!this.isConnected) return; // attributes are null before connect, causing callback to fire
|
|
70
|
+
if (oldValue === newValue) return; // no need to re-render or update if attribute value stays the same
|
|
71
|
+
|
|
72
|
+
const dontNeedToReRenderOnThese = ['warning-in-milliseconds', 'timeout-in-milliseconds'];
|
|
73
|
+
if (!dontNeedToReRenderOnThese.includes(name)) {
|
|
74
|
+
this.render();
|
|
75
|
+
this.update();
|
|
76
|
+
} else {
|
|
77
|
+
console.warn(`${name} was changed which may affect timeout accuracy`);
|
|
78
|
+
}
|
|
28
79
|
}
|
|
29
80
|
|
|
30
81
|
get rootNode() {
|
|
31
82
|
return this;
|
|
32
83
|
}
|
|
33
84
|
|
|
34
|
-
get
|
|
85
|
+
get #document() {
|
|
35
86
|
return this.getRootNode({ composed: true });
|
|
36
87
|
}
|
|
37
88
|
|
|
38
89
|
/**
|
|
39
|
-
* template
|
|
90
|
+
* Main template, which is re-rendered on attribute changes.
|
|
40
91
|
*
|
|
41
92
|
* closedby="none" means it does not close with `esc` key, we want the user to make a decision via the dialog buttons
|
|
42
93
|
*/
|
|
43
94
|
get template() {
|
|
44
|
-
const template = this.
|
|
45
|
-
const titleId = `mds-timeout-dialog-title-${window.crypto.randomUUID()}`;
|
|
95
|
+
const template = this.#document.createElement('template');
|
|
46
96
|
template.innerHTML = /* HTML */ `
|
|
47
|
-
<dialog class="mds-timeout-dialog" role="alertdialog" closedby="none" aria-labelledby="${
|
|
48
|
-
<h2 class="mds-margin-bottom-b4" id="${
|
|
97
|
+
<dialog class="mds-timeout-dialog" role="alertdialog" closedby="none" aria-labelledby="${this.dialogIdWarning}">
|
|
98
|
+
<h2 class="mds-margin-bottom-b4" id="${this.dialogIdWarning}">${this.translations['title']}</h2>
|
|
49
99
|
<p>${this.translations['message']}</p>
|
|
50
100
|
<p class="mds-message mds-message--error mds-display-none">${this.translations['message-error-sign-in']}</p>
|
|
51
101
|
<div class="mds-grid-row mds-grid-center">
|
|
52
102
|
<button class="mds-button mds-margin-right-b4" stay-signed-in-trigger type="button">
|
|
53
103
|
${this.translations['btn-stay-signed-in']}
|
|
104
|
+
<svg class="mds-timeout-dialog__button-icon" viewBox="0 0 100 100">
|
|
105
|
+
<path
|
|
106
|
+
fill="currentColor"
|
|
107
|
+
d="M100 50c0-27.6-22.4-50-50-50S0 22.4 0 50m8.5 0C8.5 27.2 27 8.5 50 8.5S91.5 27.2 91.5 50"
|
|
108
|
+
></path>
|
|
109
|
+
</svg>
|
|
54
110
|
</button>
|
|
55
|
-
<a class="mds-button mds-button--neutral" href
|
|
111
|
+
<a class="mds-button mds-button--neutral" href="${this.logoutUrl}">${this.translations['btn-sign-out']}</a>
|
|
56
112
|
</div>
|
|
57
113
|
</dialog>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* template used when time has run out
|
|
63
|
-
*/
|
|
64
|
-
get templateSignedOut() {
|
|
65
|
-
const template = this._document.createElement('template');
|
|
66
|
-
const titleId = `mds-timeout-dialog-title-${window.crypto.randomUUID()}`;
|
|
67
|
-
template.innerHTML = /* HTML */ `
|
|
68
|
-
<dialog role="alertdialog" class="mds-timeout-dialog" aria-labelledby="${titleId}">
|
|
69
|
-
<h2 class="mds-margin-bottom-b4" id="${titleId}">${this.translations['title-signed-out']}</h2>
|
|
114
|
+
<dialog role="alertdialog" class="mds-timeout-dialog" aria-labelledby="${this.dialogIdSignedOut}">
|
|
115
|
+
<h2 class="mds-margin-bottom-b4" id="${this.dialogIdSignedOut}">${this.translations['title-signed-out']}</h2>
|
|
70
116
|
<div class="mds-grid-row mds-grid-center">
|
|
71
117
|
<!-- will "submit" the dialog, e.g. close it without JS -->
|
|
72
118
|
<form method="dialog">
|
|
@@ -77,8 +123,11 @@ export class MdsTimeoutDialog extends HTMLElement {
|
|
|
77
123
|
`;
|
|
78
124
|
return template;
|
|
79
125
|
}
|
|
80
|
-
get
|
|
81
|
-
return this.rootNode.querySelector(
|
|
126
|
+
get elDialogWarning() {
|
|
127
|
+
return this.rootNode.querySelector(`dialog[aria-labelledby=${this.dialogIdWarning}]`);
|
|
128
|
+
}
|
|
129
|
+
get elDialogSignedOut() {
|
|
130
|
+
return this.rootNode.querySelector(`dialog[aria-labelledby=${this.dialogIdSignedOut}]`);
|
|
82
131
|
}
|
|
83
132
|
get elSignInButton() {
|
|
84
133
|
return this.rootNode.querySelector('[stay-signed-in-trigger]');
|
|
@@ -99,69 +148,104 @@ export class MdsTimeoutDialog extends HTMLElement {
|
|
|
99
148
|
}
|
|
100
149
|
/** URL to hit to refresh auth cookie, when user clicks to stay signed in */
|
|
101
150
|
get keepAliveUrl() {
|
|
102
|
-
return this.getAttribute('keep-alive-url')
|
|
151
|
+
return this.getAttribute('keep-alive-url');
|
|
103
152
|
}
|
|
104
153
|
get loginUrl() {
|
|
105
|
-
|
|
154
|
+
const attr = this.getAttribute('login-url');
|
|
155
|
+
if (!attr) throw new Error('no attribute login-url supplied');
|
|
156
|
+
return attr;
|
|
106
157
|
}
|
|
107
158
|
get logoutUrl() {
|
|
108
|
-
|
|
159
|
+
const attr = this.getAttribute('logout-url');
|
|
160
|
+
if (!attr) throw new Error('no attribute logout-url supplied');
|
|
161
|
+
return attr;
|
|
109
162
|
}
|
|
110
163
|
/** How many minutes until signed out, dialog opens this many minutes before signed out */
|
|
111
164
|
get warningInMilliseconds() {
|
|
112
|
-
|
|
165
|
+
const attr = this.getAttribute('warning-in-milliseconds');
|
|
166
|
+
return attr ? parseInt(attr, 10) : ONE_MINUTE_IN_MS * 2;
|
|
113
167
|
}
|
|
114
|
-
/**
|
|
168
|
+
/** number of milliseconds until user is signed out (cookie expires) */
|
|
115
169
|
get timeoutInMilliseconds() {
|
|
116
|
-
const
|
|
117
|
-
if (!
|
|
118
|
-
|
|
170
|
+
const attr = this.getAttribute('timeout-in-milliseconds');
|
|
171
|
+
if (!attr) throw new Error('no attribute timeout-in-milliseconds supplied');
|
|
172
|
+
return parseInt(attr, 10);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Ensure the correct dialog is open/closed based on the current state.
|
|
177
|
+
*
|
|
178
|
+
* Optionally passing a new state.
|
|
179
|
+
* @param {string?} newState STATE
|
|
180
|
+
*/
|
|
181
|
+
update(newState) {
|
|
182
|
+
if (newState) {
|
|
183
|
+
this.#state = newState;
|
|
184
|
+
}
|
|
185
|
+
switch (this.#state) {
|
|
186
|
+
case STATE.NONE:
|
|
187
|
+
this.elMessageError?.classList.add('mds-display-none');
|
|
188
|
+
this.elDialogWarning?.close();
|
|
189
|
+
this.elDialogSignedOut?.close();
|
|
190
|
+
break;
|
|
191
|
+
case STATE.WARNING:
|
|
192
|
+
this.elDialogSignedOut?.close();
|
|
193
|
+
this.elDialogWarning?.showModal();
|
|
194
|
+
break;
|
|
195
|
+
case STATE.TIMED_OUT:
|
|
196
|
+
this.elDialogWarning?.close();
|
|
197
|
+
this.elDialogSignedOut?.showModal();
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
break;
|
|
119
201
|
}
|
|
120
|
-
return timeoutInMilliseconds;
|
|
121
202
|
}
|
|
122
|
-
/** clear timeouts, event listeners and remove dialog */
|
|
123
|
-
destroy() {
|
|
124
|
-
clearTimeout(this.showWarningDialogTimeout);
|
|
125
|
-
clearTimeout(this.showTimedOutDialogTimeout);
|
|
126
203
|
|
|
127
|
-
|
|
128
|
-
|
|
204
|
+
/**
|
|
205
|
+
* destroy DOM and events, and re-render them.
|
|
206
|
+
*/
|
|
207
|
+
render() {
|
|
208
|
+
this.removeEventListeners();
|
|
209
|
+
this.rootNode.replaceChildren(this.template.content.cloneNode(true));
|
|
129
210
|
|
|
130
|
-
|
|
131
|
-
this.
|
|
211
|
+
this.elSignInButton?.addEventListener('click', this.onClickSignInButton);
|
|
212
|
+
this.elDialogSignedOut?.addEventListener('close', this.onSignedOutDialogClose);
|
|
132
213
|
}
|
|
133
|
-
/** add warning dialog to this DOM, initialise timeouts for showing dialogs, and handlers for timeouts */
|
|
134
|
-
start() {
|
|
135
|
-
/** use light DOM so we can access the page CSS, and use template contents */
|
|
136
|
-
this.rootNode.replaceChildren(this.template.content.cloneNode(true));
|
|
137
|
-
this.elSignInButton.addEventListener('click', this.onClickSignInButton);
|
|
138
214
|
|
|
139
|
-
|
|
140
|
-
|
|
215
|
+
/**
|
|
216
|
+
* remove event listeners, not we are not destroying the rendered DOM
|
|
217
|
+
*/
|
|
218
|
+
removeEventListeners() {
|
|
219
|
+
this.elSignInButton?.removeEventListener('click', this.onClickSignInButton);
|
|
220
|
+
this.elDialogSignedOut?.removeEventListener('close', this.onSignedOutDialogClose);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
#clearTimeouts() {
|
|
224
|
+
clearTimeout(this.#warningDialogTimeout);
|
|
225
|
+
clearTimeout(this.#timedOutDialogTimeout);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
#setTimeouts() {
|
|
229
|
+
this.#clearTimeouts();
|
|
230
|
+
this.#warningDialogTimeout = setTimeout(() => {
|
|
231
|
+
this.update(STATE.WARNING);
|
|
141
232
|
}, this.timeoutInMilliseconds - this.warningInMilliseconds);
|
|
142
233
|
|
|
143
|
-
this
|
|
144
|
-
this.
|
|
234
|
+
this.#timedOutDialogTimeout = setTimeout(() => {
|
|
235
|
+
this.update(STATE.TIMED_OUT);
|
|
145
236
|
}, this.timeoutInMilliseconds);
|
|
146
237
|
}
|
|
147
|
-
/** destroy existing dialog/timeouts, and re-create as if starting from the beginning */
|
|
148
|
-
reset() {
|
|
149
|
-
this.destroy();
|
|
150
|
-
this.start();
|
|
151
|
-
}
|
|
152
|
-
/** end if the line, we are signed out, shut down timeouts and show signed out dialog, on dialog close redirect to log in page */
|
|
153
|
-
setSignedOut() {
|
|
154
|
-
this.destroy();
|
|
155
|
-
/** use light DOM so we can access the page CSS, and use template contents */
|
|
156
|
-
this.rootNode.replaceChildren(this.templateSignedOut.content.cloneNode(true));
|
|
157
|
-
this.elDialog.showModal();
|
|
158
|
-
this.elDialog.addEventListener('close', this.onSignedOutDialogClose);
|
|
159
|
-
}
|
|
160
238
|
/**
|
|
161
|
-
*
|
|
162
|
-
* We assume a 200 response means a cookie was set, as the cookie is usually not readable via javascript
|
|
239
|
+
* If `keepAliveUrl` is populated, GET it, which should hopefully return a new logged in cookie.
|
|
240
|
+
* We assume a 200 response means a cookie was set, as the cookie is usually not readable via javascript.
|
|
241
|
+
*
|
|
242
|
+
* If `keepAliveUrl` is not populated, we assume external fetch will happen on `refresh` event,
|
|
243
|
+
* and `onRefreshSuccess` / `onRefreshFailed` will be called externally.
|
|
163
244
|
*/
|
|
164
245
|
async onClickSignInButton() {
|
|
246
|
+
this.dispatchEvent(new CustomEvent('refresh'));
|
|
247
|
+
this.elDialogWarning?.classList.add('mds-timeout-dialog--refreshing');
|
|
248
|
+
if (!this.keepAliveUrl) return;
|
|
165
249
|
try {
|
|
166
250
|
const res = await fetch(this.keepAliveUrl);
|
|
167
251
|
if (!res.ok) {
|
|
@@ -169,21 +253,57 @@ export class MdsTimeoutDialog extends HTMLElement {
|
|
|
169
253
|
throw new Error(`Could not stay signed in - ${res.statusText} - ${text}`);
|
|
170
254
|
}
|
|
171
255
|
// assume successful response means successful cookie refresh
|
|
172
|
-
this.
|
|
173
|
-
if (this.elMessageError) this.elMessageError.classList.add('mds-display-none');
|
|
256
|
+
this.onRefreshSuccess();
|
|
174
257
|
} catch (error) {
|
|
175
|
-
|
|
176
|
-
// response is error, assume failed to fetch fresh cookie
|
|
177
|
-
if (this.elMessageError) this.elMessageError.classList.remove('mds-display-none');
|
|
258
|
+
this.onRefreshFailed(error);
|
|
178
259
|
}
|
|
179
260
|
}
|
|
180
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Useful for external call when auth has been refreshed. Currently the same as `onRefreshSuccess`
|
|
264
|
+
*/
|
|
265
|
+
restart() {
|
|
266
|
+
this.elDialogWarning?.classList.remove('mds-timeout-dialog--refreshing');
|
|
267
|
+
this.elMessageError?.classList.add('mds-display-none');
|
|
268
|
+
this.update(STATE.NONE);
|
|
269
|
+
this.#setTimeouts();
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Useful for external call when auth has expired outside of this component.
|
|
273
|
+
*/
|
|
274
|
+
timedOut() {
|
|
275
|
+
this.#clearTimeouts();
|
|
276
|
+
this.update(STATE.TIMED_OUT);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Called on successful sign in refresh. May be called externally.
|
|
281
|
+
*/
|
|
282
|
+
onRefreshSuccess() {
|
|
283
|
+
this.restart();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Called on failed sign in refresh. May be called externally.
|
|
288
|
+
*
|
|
289
|
+
* @param {Error} error optional
|
|
290
|
+
*/
|
|
291
|
+
onRefreshFailed(error) {
|
|
292
|
+
console.error(error);
|
|
293
|
+
// response is error, assume failed to fetch fresh cookie
|
|
294
|
+
this.elDialogWarning?.classList.remove('mds-timeout-dialog--refreshing');
|
|
295
|
+
this.elMessageError?.classList.remove('mds-display-none');
|
|
296
|
+
}
|
|
297
|
+
|
|
181
298
|
/**
|
|
182
299
|
* when the 'signed out dialog' gets closed, we want to send the user straight to the log in page.
|
|
183
300
|
* This is because we dont want the user to close the dialog and be left with a visually signed in page.
|
|
184
301
|
* PipelinedPage return URL back to this current page URL after log in
|
|
185
302
|
*/
|
|
186
303
|
onSignedOutDialogClose() {
|
|
187
|
-
|
|
304
|
+
// ensure if the signed out dialog is closed, it was only in state `TIMED_OUT`
|
|
305
|
+
if (this.#state === STATE.TIMED_OUT) {
|
|
306
|
+
window.location.href = `${this.loginUrl}?PipelinedPage=${encodeURIComponent(window.location.href)}`;
|
|
307
|
+
}
|
|
188
308
|
}
|
|
189
309
|
}
|
|
@@ -79,6 +79,9 @@
|
|
|
79
79
|
<script>
|
|
80
80
|
function testRegularTimeOutDialog() {
|
|
81
81
|
const regularElement = document.createElement('mds-timeout-dialog');
|
|
82
|
+
regularElement.setAttribute('login-url', '/login');
|
|
83
|
+
regularElement.setAttribute('logout-url', '/logout');
|
|
84
|
+
regularElement.setAttribute('keep-alive-url', '/?keepalive');
|
|
82
85
|
regularElement.setAttribute('timeout-in-milliseconds', '6000');
|
|
83
86
|
regularElement.setAttribute('warning-in-milliseconds', '5500');
|
|
84
87
|
regularElement.setAttribute('t-title', 'Regular Version - Light DOM');
|
|
@@ -91,6 +94,9 @@
|
|
|
91
94
|
|
|
92
95
|
function testStandaloneTimeOutDialog() {
|
|
93
96
|
const standaloneElement = document.createElement('mds-timeout-dialog-standalone');
|
|
97
|
+
standaloneElement.setAttribute('login-url', '/login');
|
|
98
|
+
standaloneElement.setAttribute('logout-url', '/logout');
|
|
99
|
+
standaloneElement.setAttribute('keep-alive-url', '/?keepalive');
|
|
94
100
|
standaloneElement.setAttribute('timeout-in-milliseconds', '6000');
|
|
95
101
|
standaloneElement.setAttribute('warning-in-milliseconds', '5500');
|
|
96
102
|
standaloneElement.setAttribute('t-title', 'Standalone Version - Shadow DOM');
|
|
@@ -11,3 +11,24 @@
|
|
|
11
11
|
.mds-timeout-dialog::backdrop {
|
|
12
12
|
background-color: rgba(0, 0, 0, 0.8);
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
.mds-timeout-dialog__button-icon {
|
|
16
|
+
display: none;
|
|
17
|
+
width: 1em;
|
|
18
|
+
height: 1em;
|
|
19
|
+
animation: spin-timeout-dialog 1s infinite linear;
|
|
20
|
+
color: inherit;
|
|
21
|
+
margin-left: 4px;
|
|
22
|
+
}
|
|
23
|
+
.mds-timeout-dialog--refreshing .mds-timeout-dialog__button-icon {
|
|
24
|
+
display: inline-block;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@keyframes spin-timeout-dialog {
|
|
28
|
+
0% {
|
|
29
|
+
transform: rotate(0);
|
|
30
|
+
}
|
|
31
|
+
100% {
|
|
32
|
+
transform: rotate(360deg);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/js/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import prose from '../helpers/prose/prose';
|
|
|
12
12
|
import { MdsDropdownNav } from '../components/dropdown-nav/dropdown-nav';
|
|
13
13
|
import { MdsTimeoutDialog } from '../components/timeout-dialog/timeout-dialog';
|
|
14
14
|
import { MdsCardLink } from '../components/card/card-link';
|
|
15
|
+
import { MdsConditionalSection } from '../components/conditional-section/conditional-section';
|
|
15
16
|
|
|
16
17
|
if (!window.customElements.get('mds-dropdown-nav')) {
|
|
17
18
|
window.customElements.define('mds-dropdown-nav', MdsDropdownNav);
|
|
@@ -22,6 +23,9 @@ if (!window.customElements.get('mds-timeout-dialog')) {
|
|
|
22
23
|
if (!window.customElements.get('mds-card-link')) {
|
|
23
24
|
window.customElements.define('mds-card-link', MdsCardLink);
|
|
24
25
|
}
|
|
26
|
+
if (!window.customElements.get('mds-conditional-section')) {
|
|
27
|
+
window.customElements.define('mds-conditional-section', MdsConditionalSection);
|
|
28
|
+
}
|
|
25
29
|
|
|
26
30
|
const initAll = () => {
|
|
27
31
|
tabs.init();
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
class s extends HTMLElement{constructor(){super(),this.onClickSignInButton=this.onClickSignInButton.bind(this),this.onSignedOutDialogClose=this.onSignedOutDialogClose.bind(this)}connectedCallback(){this.start()}disconnectedCallback(){this.destroy()}get rootNode(){return this}get _document(){return this.getRootNode({composed:!0})}get template(){const t=this._document.createElement("template"),e=`mds-timeout-dialog-title-${window.crypto.randomUUID()}`;return t.innerHTML=`
|
|
2
|
-
<dialog class="mds-timeout-dialog" role="alertdialog" closedby="none" aria-labelledby="${e}">
|
|
3
|
-
<h2 class="mds-margin-bottom-b4" id="${e}">${this.translations.title}</h2>
|
|
4
|
-
<p>${this.translations.message}</p>
|
|
5
|
-
<p class="mds-message mds-message--error mds-display-none">${this.translations["message-error-sign-in"]}</p>
|
|
6
|
-
<div class="mds-grid-row mds-grid-center">
|
|
7
|
-
<button class="mds-button mds-margin-right-b4" stay-signed-in-trigger type="button">
|
|
8
|
-
${this.translations["btn-stay-signed-in"]}
|
|
9
|
-
</button>
|
|
10
|
-
<a class="mds-button mds-button--neutral" href=${this.logoutUrl}>${this.translations["btn-sign-out"]}</a>
|
|
11
|
-
</div>
|
|
12
|
-
</dialog>
|
|
13
|
-
`,t}get templateSignedOut(){const t=this._document.createElement("template"),e=`mds-timeout-dialog-title-${window.crypto.randomUUID()}`;return t.innerHTML=`
|
|
14
|
-
<dialog role="alertdialog" class="mds-timeout-dialog" aria-labelledby="${e}">
|
|
15
|
-
<h2 class="mds-margin-bottom-b4" id="${e}">${this.translations["title-signed-out"]}</h2>
|
|
16
|
-
<div class="mds-grid-row mds-grid-center">
|
|
17
|
-
<!-- will "submit" the dialog, e.g. close it without JS -->
|
|
18
|
-
<form method="dialog">
|
|
19
|
-
<button class="mds-button">${this.translations["btn-close"]}</button>
|
|
20
|
-
</form>
|
|
21
|
-
</div>
|
|
22
|
-
</dialog>
|
|
23
|
-
`,t}get elDialog(){return this.rootNode.querySelector("dialog")}get elSignInButton(){return this.rootNode.querySelector("[stay-signed-in-trigger]")}get elMessageError(){return this.rootNode.querySelector(".mds-message--error")}get translations(){return{title:this.getAttribute("t-title")||"You are about to be signed out","title-signed-out":this.getAttribute("t-title-timed-out")||"You have been signed out",message:this.getAttribute("t-message")||"For your security, we will log you out in 2 minutes.","message-error-sign-in":this.getAttribute("t-message-error-failed-refresh")||"Failed to sign in - try again","btn-stay-signed-in":this.getAttribute("t-btn-stay-refresh")||"Stay signed in","btn-sign-out":this.getAttribute("t-btn-sign-out")||"Sign out","btn-close":this.getAttribute("t-btn-close")||"close"}}get keepAliveUrl(){return this.getAttribute("keep-alive-url")||"?continue=true"}get loginUrl(){return this.getAttribute("login-url")||"/login"}get logoutUrl(){return this.getAttribute("logout-url")||"/logoff"}get warningInMilliseconds(){return parseInt(this.getAttribute("warning-in-milliseconds"),10)||2*6e4}get timeoutInMilliseconds(){const t=parseInt(this.getAttribute("timeout-in-milliseconds"),10);return t||console.error("no attribute timeout-in-milliseconds supplied"),t}destroy(){clearTimeout(this.showWarningDialogTimeout),clearTimeout(this.showTimedOutDialogTimeout),this.elSignInButton&&this.elSignInButton.removeEventListener("click",this.onClickSignInButton),this.elDialog&&this.elDialog.removeEventListener("close",this.onSignedOutDialogClose),this.elDialog&&this.elDialog.close(),this.rootNode.replaceChildren("")}start(){this.rootNode.replaceChildren(this.template.content.cloneNode(!0)),this.elSignInButton.addEventListener("click",this.onClickSignInButton),this.showWarningDialogTimeout=setTimeout(()=>{this.elDialog.showModal()},this.timeoutInMilliseconds-this.warningInMilliseconds),this.showTimedOutDialogTimeout=setTimeout(()=>{this.setSignedOut()},this.timeoutInMilliseconds)}reset(){this.destroy(),this.start()}setSignedOut(){this.destroy(),this.rootNode.replaceChildren(this.templateSignedOut.content.cloneNode(!0)),this.elDialog.showModal(),this.elDialog.addEventListener("close",this.onSignedOutDialogClose)}async onClickSignInButton(){try{const t=await fetch(this.keepAliveUrl);if(!t.ok){const e=await t.text();throw new Error(`Could not stay signed in - ${t.statusText} - ${e}`)}this.reset(),this.elMessageError&&this.elMessageError.classList.add("mds-display-none")}catch(t){console.error(t),this.elMessageError&&this.elMessageError.classList.remove("mds-display-none")}}onSignedOutDialogClose(){window.location.href=`${this.loginUrl}?PipelinedPage=${encodeURIComponent(window.location.href)}`}}export{s as M};
|