@everymatrix/general-registration 1.32.4 → 1.33.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.
Files changed (79) hide show
  1. package/dist/cjs/checkbox-group-input_13.cjs.entry.js +36991 -0
  2. package/dist/cjs/general-registration.cjs.js +19 -0
  3. package/dist/cjs/index-0b9241d1.js +1360 -0
  4. package/dist/cjs/index.cjs.js +18 -0
  5. package/dist/cjs/loader.cjs.js +21 -0
  6. package/dist/collection/collection-manifest.json +30 -0
  7. package/dist/collection/components/general-registration/general-registration.css +122 -0
  8. package/dist/collection/components/general-registration/general-registration.js +774 -0
  9. package/dist/collection/index.js +17 -0
  10. package/dist/collection/utils/locale.utils.js +108 -0
  11. package/dist/collection/utils/utils.js +3 -0
  12. package/dist/components/active-mixin.js +975 -0
  13. package/dist/components/checkbox-group-input.js +6 -0
  14. package/dist/components/checkbox-group-input2.js +1078 -0
  15. package/dist/components/checkbox-input.js +6 -0
  16. package/dist/components/checkbox-input2.js +129 -0
  17. package/dist/components/date-input.js +6 -0
  18. package/dist/components/date-input2.js +11556 -0
  19. package/dist/components/email-input.js +6 -0
  20. package/dist/components/email-input2.js +171 -0
  21. package/dist/components/field-mixin.js +12426 -0
  22. package/dist/components/general-input.js +6 -0
  23. package/dist/components/general-input2.js +341 -0
  24. package/dist/components/general-registration.d.ts +11 -0
  25. package/dist/components/general-registration.js +754 -0
  26. package/dist/components/index.d.ts +26 -0
  27. package/dist/components/index.js +18 -0
  28. package/dist/components/input-field-shared-styles.js +1211 -0
  29. package/dist/components/number-input.js +6 -0
  30. package/dist/components/number-input2.js +158 -0
  31. package/dist/components/password-input.js +6 -0
  32. package/dist/components/password-input2.js +1041 -0
  33. package/dist/components/radio-input.js +6 -0
  34. package/dist/components/radio-input2.js +114 -0
  35. package/dist/components/select-input.js +6 -0
  36. package/dist/components/select-input2.js +183 -0
  37. package/dist/components/tel-input.js +6 -0
  38. package/dist/components/tel-input2.js +197 -0
  39. package/dist/components/text-input.js +6 -0
  40. package/dist/components/text-input2.js +199 -0
  41. package/dist/components/toggle-checkbox-input.js +6 -0
  42. package/dist/components/tooltipIcon.js +127 -0
  43. package/dist/components/vaadin-button.js +490 -0
  44. package/dist/components/vaadin-combo-box.js +4512 -0
  45. package/dist/components/virtual-keyboard-controller.js +2001 -0
  46. package/dist/esm/checkbox-group-input_13.entry.js +36975 -0
  47. package/dist/esm/general-registration.js +17 -0
  48. package/dist/esm/index-a42c182c.js +1332 -0
  49. package/dist/esm/index.js +16 -0
  50. package/dist/esm/loader.js +17 -0
  51. package/dist/esm/polyfills/core-js.js +11 -0
  52. package/dist/esm/polyfills/css-shim.js +1 -0
  53. package/dist/esm/polyfills/dom.js +79 -0
  54. package/dist/esm/polyfills/es5-html-element.js +1 -0
  55. package/dist/esm/polyfills/index.js +34 -0
  56. package/dist/esm/polyfills/system.js +6 -0
  57. package/dist/general-registration/general-registration.esm.js +1 -0
  58. package/dist/general-registration/index.esm.js +1 -0
  59. package/dist/general-registration/p-4ff02444.js +1 -0
  60. package/dist/general-registration/p-8eaa2cfb.entry.js +3647 -0
  61. package/dist/index.cjs.js +1 -0
  62. package/dist/index.js +1 -0
  63. package/dist/stencil.config.js +22 -0
  64. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-stencil/packages/general-registration/.stencil/packages/general-input/src/utils/types.d.ts +87 -0
  65. package/dist/types/Users/adrian.pripon/Documents/Work/widgets-stencil/packages/general-registration/.stencil/packages/general-registration/stencil.config.d.ts +2 -0
  66. package/dist/types/components/general-registration/general-registration.d.ts +93 -0
  67. package/dist/types/components.d.ts +111 -0
  68. package/dist/types/index.d.ts +1 -0
  69. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  70. package/dist/types/utils/locale.utils.d.ts +17 -0
  71. package/dist/types/utils/utils.d.ts +1 -0
  72. package/loader/cdn.js +3 -0
  73. package/loader/index.cjs.js +3 -0
  74. package/loader/index.d.ts +12 -0
  75. package/loader/index.es2017.js +3 -0
  76. package/loader/index.js +4 -0
  77. package/loader/package.json +10 -0
  78. package/package.json +2 -3
  79. package/LICENSE +0 -21
@@ -0,0 +1,774 @@
1
+ import { Component, h, Listen, Prop, State, Watch, Event, Element } from '@stencil/core';
2
+ import { getTranslations, translate, TRANSLATIONS } from '../../utils/locale.utils';
3
+ import '@everymatrix/general-input';
4
+ export class GeneralRegistration {
5
+ constructor() {
6
+ /**
7
+ * Currently selected language
8
+ */
9
+ this.language = 'en';
10
+ /**
11
+ * Client custom styling via inline styles
12
+ */
13
+ this.clientStyling = '';
14
+ /**
15
+ * Client custom styling via url
16
+ */
17
+ this.clientStylingUrl = '';
18
+ /**
19
+ * Translations via URL
20
+ */
21
+ this.translationUrl = '';
22
+ /**
23
+ * Affiliate code to be passed in and sent in the registration.
24
+ */
25
+ this.btag = null;
26
+ /**
27
+ * Boolean flag that tells inputs to emit an event on click.
28
+ */
29
+ this.emitOnClick = false;
30
+ this.isLoading = true;
31
+ this.forms = [];
32
+ this.limitStylingAppends = false;
33
+ this.autofilled = false;
34
+ this.listOfInputValues = [];
35
+ this.listOfInputValidity = [];
36
+ this.listOfActions = [];
37
+ this.listOfInputs = [];
38
+ this.emitValue = false;
39
+ this.backButtonPressed = false;
40
+ this.registerErrors = false;
41
+ this.extraActions = [];
42
+ this.registrationStepsState = {
43
+ regId: null
44
+ };
45
+ this.setClientStyling = () => {
46
+ let sheet = document.createElement('style');
47
+ sheet.innerHTML = this.clientStyling;
48
+ this.host.shadowRoot.prepend(sheet);
49
+ };
50
+ this.setClientStylingURL = () => {
51
+ let url = new URL(this.clientStylingUrl);
52
+ let cssFile = document.createElement('style');
53
+ fetch(url.href)
54
+ .then((res) => res.text())
55
+ .then((data) => {
56
+ cssFile.innerHTML = data;
57
+ this.clientStyling = data;
58
+ setTimeout(() => { this.host.shadowRoot.prepend(cssFile); }, 1);
59
+ });
60
+ };
61
+ }
62
+ sendStep() {
63
+ this.registrationStepUpdated.emit(this.registrationStep);
64
+ window.postMessage({ type: 'registrationStepUpdated', step: this.registrationStep }, window.location.href);
65
+ }
66
+ handleStylingChange(newValue, oldValue) {
67
+ if (newValue !== oldValue)
68
+ this.setClientStyling();
69
+ }
70
+ handleStylingUrlChange(newValue, oldValue) {
71
+ if (newValue !== oldValue)
72
+ this.setClientStylingURL();
73
+ }
74
+ setFormValidity() {
75
+ this.errorMessage = '';
76
+ if (this.listOfInputValidity) {
77
+ this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
78
+ }
79
+ //Check for autofilled.
80
+ if (this.listOfInputs.some(inputs => inputs.autofill)) {
81
+ this.autofilled = true;
82
+ }
83
+ }
84
+ addBtag() {
85
+ this.addBtagValue();
86
+ }
87
+ checkInputsValidityHandler(event) {
88
+ // Set isValid state of the input in the list.
89
+ this.listOfInputValidity.find(input => input.name == event.detail.name).isValid = event.detail.valid;
90
+ // Check if any one is invalid.
91
+ this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
92
+ }
93
+ getInputsValueHandler(event) {
94
+ this.listOfInputValues.find(input => {
95
+ if (input.name == event.detail.name) {
96
+ input.value = event.detail.value;
97
+ input.type = event.detail.type || null;
98
+ }
99
+ });
100
+ this.stepsStateMachine({ event: 'set', type: 'values' });
101
+ }
102
+ componentWillLoad() {
103
+ return this.getRegisterConfig()
104
+ .then((config) => {
105
+ this.formatConfig(config);
106
+ this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
107
+ this.stepsStateMachine({ event: 'set', type: 'inputs' });
108
+ });
109
+ }
110
+ componentDidLoad() {
111
+ this.registrationWidgetLoaded.emit();
112
+ window.postMessage({ type: 'registrationWidgetLoaded' }, window.location.href);
113
+ if (!this.limitStylingAppends && this.host) {
114
+ if (this.clientStyling)
115
+ this.setClientStyling();
116
+ if (this.clientStylingUrl)
117
+ this.setClientStylingURL();
118
+ this.limitStylingAppends = true;
119
+ }
120
+ }
121
+ nextHandler(e) {
122
+ e.preventDefault();
123
+ // Trigger events in subwidgets.
124
+ this.emitValue = true;
125
+ this.setRegisterStep();
126
+ }
127
+ backHandler(e) {
128
+ e.preventDefault();
129
+ this.registrationStep = this.stepChange('decrement');
130
+ this.stepsStateMachine({ event: 'get', type: 'inputs' });
131
+ this.stepsStateMachine({ event: 'get', type: 'values' });
132
+ }
133
+ stepsStateMachine(state) {
134
+ switch (state.event) {
135
+ case 'set':
136
+ if (state.type == 'inputs') {
137
+ this.registrationStepsState[this.registrationStep].fields = this.listOfInputs;
138
+ this.registrationStepsState[this.registrationStep].actions = this.listOfActions;
139
+ this.registrationStepsState[this.registrationStep].fieldsValidity = this.listOfInputValidity;
140
+ }
141
+ if (state.type == 'values') {
142
+ this.registrationStepsState[this.registrationStep].registerUserData = this.listOfInputValues.reduce((acc, curr) => {
143
+ acc[curr.name] = { value: curr.value, isDuplicate: curr.isDuplicate };
144
+ return acc;
145
+ }, {});
146
+ }
147
+ localStorage.setItem('registrationStepsState', JSON.stringify(this.registrationStepsState));
148
+ break;
149
+ case 'get':
150
+ const savedUserData = JSON.parse(localStorage.getItem('registrationStepsState'));
151
+ if (!savedUserData)
152
+ return;
153
+ if (state.type == 'inputs') {
154
+ this.listOfInputs = this.registrationStepsState[this.registrationStep].fields;
155
+ this.listOfActions = this.registrationStepsState[this.registrationStep].actions;
156
+ this.listOfInputValidity = this.registrationStepsState[this.registrationStep].fieldsValidity;
157
+ }
158
+ if (state.type == 'values') {
159
+ const savedValues = savedUserData[this.registrationStep].registerUserData;
160
+ this.listOfInputValues = Object.keys(savedValues).map(name => {
161
+ return { name, value: savedValues[name].value, isDuplicate: savedValues[name].isDuplicate };
162
+ });
163
+ // Give to each field the user input as the default value.
164
+ this.listOfInputValues.forEach(inputValue => {
165
+ const input = this.listOfInputs.find(input => input.name === inputValue.name);
166
+ if (input) {
167
+ input.defaultValue = inputValue.value;
168
+ }
169
+ });
170
+ }
171
+ this.isFormValid = !this.getInvalidStatus(this.listOfInputValidity);
172
+ break;
173
+ }
174
+ }
175
+ getRegisterConfig(registrationID) {
176
+ const url = new URL(`${this.endpoint}/v1/player/legislation/registration/config`);
177
+ const headers = new Headers();
178
+ headers.append('Content-Type', 'application/json');
179
+ headers.append('Accept', 'application/json');
180
+ if (registrationID) {
181
+ url.searchParams.append('registrationId', registrationID);
182
+ }
183
+ const options = {
184
+ method: 'GET',
185
+ headers
186
+ };
187
+ return new Promise((resolve, reject) => {
188
+ this.isLoading = true;
189
+ fetch(url.href, options)
190
+ .then((res) => res.json())
191
+ .then((config) => {
192
+ this.isLoading = false;
193
+ resolve(config);
194
+ }).catch((err) => {
195
+ this.isLoading = false;
196
+ console.error(err);
197
+ reject(err);
198
+ }).finally(() => {
199
+ this.isLoading = false;
200
+ });
201
+ });
202
+ }
203
+ setRegisterStep() {
204
+ this.isLoadingPOST = true;
205
+ const url = new URL(`${this.endpoint}/v1/player/legislation/registration/step`);
206
+ const registerStep = {
207
+ registrationId: this.registrationID,
208
+ registerUserDto: this.listOfInputValues
209
+ .filter(input => !input.isDuplicate)
210
+ .reduce((acc, curr) => {
211
+ // Because the API is very robust, some values need to be split as separate entities.
212
+ if (curr.name === 'TypeOfPublicArea') {
213
+ acc[curr.name] = curr.value.toLowerCase();
214
+ }
215
+ else if (curr.type === 'tel') {
216
+ //@ts-ignore
217
+ acc['MobilePrefix'] = curr.value.prefix;
218
+ //@ts-ignore
219
+ acc[curr.name] = curr.value.phone;
220
+ }
221
+ else if (curr.type === 'checkboxgroup') {
222
+ // Skip adding the parent of the checkboxgroup as a key.
223
+ if (curr.value !== null) {
224
+ Object.entries(curr.value).forEach(([key, value]) => {
225
+ acc[key] = value ? 'true' : 'false';
226
+ });
227
+ }
228
+ }
229
+ else {
230
+ acc[curr.name] = curr.value;
231
+ }
232
+ return acc;
233
+ }, {}),
234
+ step: this.registrationStep,
235
+ };
236
+ const headers = new Headers();
237
+ headers.append('Content-Type', 'application/json');
238
+ headers.append('Accept', 'application/json');
239
+ const options = {
240
+ method: 'POST',
241
+ body: JSON.stringify(registerStep),
242
+ headers
243
+ };
244
+ fetch(url.href, options)
245
+ .then((res) => {
246
+ if (!res.ok) {
247
+ return res.json().then(error => {
248
+ this.errorCode = error.thirdPartyResponse.errorCode;
249
+ // Show the idomsoft error if it is the case
250
+ if (this.errorCode == 'GmErr_BadRequest_IdomsoftVerification_ShouldRetry') {
251
+ this.errorMessage = error.thirdPartyResponse.message;
252
+ }
253
+ else if (this.errorCode === 'GmErr_Forbidden_UserAccount_NavExcluded') {
254
+ this.errorMessage = translate(`${this.errorCode}`, this.language);
255
+ }
256
+ else if (this.errorCode == 'GmErr_BadRequest') {
257
+ this.errorMessage = error.thirdPartyResponse.message;
258
+ }
259
+ else {
260
+ this.errorMessage = translate(`${this.errorCode}`, this.language) || translate(`generalError`, this.language);
261
+ }
262
+ });
263
+ }
264
+ return res.json();
265
+ })
266
+ .then((data) => {
267
+ this.isLoadingPOST = false;
268
+ this.registrationID = data.registrationId;
269
+ if (this.listOfActions.some(action => action == '/register')) {
270
+ if (this.listOfActions.some(action => action == '/generate-2FA-code/Generate2FACode')) {
271
+ this.extraActions.push('2fa');
272
+ }
273
+ this.setRegister();
274
+ }
275
+ else {
276
+ // After sending the current step, increment and check if the next one is in state.
277
+ this.registrationStep = this.stepChange('increment');
278
+ // If step is present in state do NOT fetch the next config.
279
+ if (Object.keys(this.registrationStepsState).find(key => key == this.registrationStep)) {
280
+ // Use the one from state
281
+ this.stepsStateMachine({ event: 'get', type: 'inputs' });
282
+ this.stepsStateMachine({ event: 'get', type: 'values' });
283
+ }
284
+ else {
285
+ this.getRegisterConfig(this.registrationID).then((config) => {
286
+ // Format the new step config.
287
+ this.formatConfig(config);
288
+ // Set it in local storage.
289
+ this.stepsStateMachine({ event: 'set', type: 'inputs' });
290
+ });
291
+ }
292
+ }
293
+ })
294
+ .catch((err) => {
295
+ this.isLoadingPOST = false;
296
+ console.error(err);
297
+ }).finally(() => {
298
+ this.isLoadingPOST = false;
299
+ });
300
+ }
301
+ setRegister() {
302
+ this.isLoading = true;
303
+ this.registerErrors = false;
304
+ const url = new URL(`${this.endpoint}/v1/player/legislation/register`);
305
+ const headers = new Headers();
306
+ headers.append('Content-Type', 'application/json');
307
+ headers.append('Accept', 'application/json');
308
+ const options = {
309
+ method: 'PUT',
310
+ body: JSON.stringify({ registrationId: this.registrationID }),
311
+ headers
312
+ };
313
+ fetch(url.href, options)
314
+ .then((res) => {
315
+ if (!res.ok) {
316
+ this.registerErrors = true;
317
+ return res.json().then(error => {
318
+ this.errorCode = error.thirdPartyResponse.errorCode;
319
+ // Show the idomsoft error if it is the case
320
+ if (this.errorCode == 'GmErr_BadRequest_IdomsoftVerification_ShouldRetry') {
321
+ this.errorMessage = error.thirdPartyResponse.message;
322
+ }
323
+ else if (this.errorCode == 'GmErr_BadRequest') {
324
+ this.errorMessage = error.thirdPartyResponse.message;
325
+ }
326
+ else {
327
+ this.errorMessage = translate(`${this.errorCode}`, this.language) || translate(`generalError`, this.language);
328
+ }
329
+ window.postMessage({ type: 'registrationFailed', errorMessage: error === null || error === void 0 ? void 0 : error.thirdPartyResponse.message }, window.location.href);
330
+ window.postMessage({ type: 'WidgetNotification', data: {
331
+ type: 'error',
332
+ message: this.errorMessage
333
+ } }, window.location.href);
334
+ });
335
+ }
336
+ return res.json();
337
+ })
338
+ .then((data) => {
339
+ this.isLoading = false;
340
+ if (!this.registerErrors) {
341
+ window.postMessage({ type: 'registrationSuccessful', userId: data === null || data === void 0 ? void 0 : data.userId, extraActions: this.extraActions }, window.location.href);
342
+ window.postMessage({ type: 'WidgetNotification', data: {
343
+ type: 'success',
344
+ message: translate('successMessage', this.language)
345
+ } }, window.location.href);
346
+ }
347
+ })
348
+ .catch((err) => {
349
+ this.isLoading = false;
350
+ console.error(err);
351
+ })
352
+ .finally(() => {
353
+ this.isLoading = false;
354
+ });
355
+ }
356
+ formatConfig(config) {
357
+ // Populate the list of inputs
358
+ this.listOfInputs = config.content.fields.flatMap((field) => {
359
+ // Special case for inputs that need to be duplicated.
360
+ const duplicateInputRule = field.validate.custom.find(customRule => customRule.rule === 'duplicate-input');
361
+ const inputElement = Object.assign({}, field);
362
+ if (duplicateInputRule) {
363
+ const duplicateInput = Object.assign(Object.assign({}, field), { name: `${field.name}Duplicate`, displayName: duplicateInputRule.displayName, isDuplicateInput: true });
364
+ return [inputElement, duplicateInput];
365
+ }
366
+ else {
367
+ return [inputElement];
368
+ }
369
+ });
370
+ this.listOfInputValidity = this.listOfInputs.reduce((acc, field) => {
371
+ var _a;
372
+ // If the field is a togglecheckbox, add its subfields
373
+ if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "togglecheckbox") {
374
+ field.data.subFields.forEach(subfield => {
375
+ acc.push({
376
+ name: subfield.name,
377
+ isValid: this.setInitialValidStatus(subfield)
378
+ });
379
+ });
380
+ }
381
+ else {
382
+ acc.push({
383
+ name: field.name,
384
+ isValid: this.setInitialValidStatus(field)
385
+ });
386
+ }
387
+ return acc;
388
+ }, []);
389
+ this.listOfInputValues = this.listOfInputs.reduce((acc, field) => {
390
+ var _a, _b, _c;
391
+ // If the field type is a 'togglecheckbox', add its subfields
392
+ if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === "togglecheckbox") {
393
+ field.data.subFields.forEach(subfield => {
394
+ var _a, _b;
395
+ acc.push({
396
+ name: subfield.name,
397
+ value: ((_a = subfield.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'checkbox' ? 'false' : null,
398
+ isDuplicate: subfield.isDuplicateInput || false,
399
+ type: ((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) == 'togglecheckbox'
400
+ ? 'togglecheckbox'
401
+ : null
402
+ });
403
+ });
404
+ }
405
+ else {
406
+ acc.push({
407
+ name: field.name,
408
+ value: ((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) == 'checkbox' ? 'false' : null,
409
+ isDuplicate: field.isDuplicateInput || false,
410
+ type: ((_c = field.inputType) === null || _c === void 0 ? void 0 : _c.toLowerCase()) == 'checkboxgroup' ? 'checkboxgroup' : null
411
+ });
412
+ }
413
+ return acc;
414
+ }, []);
415
+ if (this.btag)
416
+ this.addBtagValue();
417
+ // Set the list of actions
418
+ this.listOfActions = config.content.actions.map(action => action);
419
+ this.registrationID = config.content.registrationID;
420
+ this.registrationStep = config.content.step;
421
+ if (this.listOfActions.some(action => action == '/register')) {
422
+ this.lastStep = this.registrationStep;
423
+ }
424
+ ;
425
+ // The translations for fields happens here.
426
+ if (this.translationUrl) {
427
+ getTranslations(this.translationUrl).then(() => {
428
+ this.listOfInputs.forEach(field => {
429
+ var _a, _b;
430
+ this.addTranslation(field);
431
+ // Logic for field types that have subfields
432
+ if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'togglecheckbox') {
433
+ field.data.subFields.forEach(subField => this.addTranslation(subField));
434
+ }
435
+ if (((_b = field.inputType) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'checkboxgroup') {
436
+ this.addTranslation(field);
437
+ field.data.subFields.forEach(subField => this.addTranslation(subField));
438
+ }
439
+ return field;
440
+ });
441
+ })
442
+ .catch((error) => {
443
+ console.error('Failed to fetch translations:', error);
444
+ }).finally(() => {
445
+ this.forms = [...this.forms, { [this.registrationStep]: this.listOfInputs }];
446
+ });
447
+ }
448
+ else {
449
+ this.forms = [...this.forms, { [this.registrationStep]: this.listOfInputs }];
450
+ }
451
+ // Add the step to the registrationStepsData
452
+ this.registrationStepsState.regId = this.registrationID;
453
+ if (!this.registrationStepsState[this.registrationStep]) {
454
+ this.registrationStepsState[this.registrationStep] = {
455
+ fields: [],
456
+ fieldsValidity: [],
457
+ registerUserData: {},
458
+ actions: []
459
+ };
460
+ }
461
+ }
462
+ addBtagValue() {
463
+ const btagField = this.listOfInputs.find(input => input.name.toLowerCase() === 'btag');
464
+ if (btagField) {
465
+ btagField.defaultValue = this.btag;
466
+ }
467
+ const btagValue = this.listOfInputValues.find(input => input.name.toLowerCase() === 'btag');
468
+ if (btagValue) {
469
+ btagValue.value = this.btag;
470
+ }
471
+ }
472
+ addTranslation(field) {
473
+ if (TRANSLATIONS[this.language][field.name]) {
474
+ Object.keys(TRANSLATIONS[this.language][field.name]).forEach((key) => {
475
+ field[key] = TRANSLATIONS[this.language][field.name][key];
476
+ });
477
+ }
478
+ }
479
+ setInitialValidStatus(field) {
480
+ var _a, _b;
481
+ // Input type checkbox, with no validation are valid
482
+ if (((_a = field.inputType) === null || _a === void 0 ? void 0 : _a.toLowerCase()) == 'checkbox' && ((_b = field.validate) === null || _b === void 0 ? void 0 : _b.mandatory) == false) {
483
+ return true;
484
+ }
485
+ //Inputs that have default value are valid.
486
+ if (field.defaultValue !== null) {
487
+ return true;
488
+ }
489
+ return false;
490
+ }
491
+ stepChange(action) {
492
+ const stepNum = parseInt(this.registrationStep.replace('Step', ''));
493
+ if (action === 'increment') {
494
+ return 'Step' + (stepNum + 1);
495
+ }
496
+ if (action === 'decrement') {
497
+ return 'Step' + (stepNum - 1);
498
+ }
499
+ }
500
+ getInvalidStatus(listOfInputs) {
501
+ return listOfInputs.filter(input => input.isValid == false).length > 0;
502
+ }
503
+ renderForm() {
504
+ return this.forms.map((form, index) => {
505
+ return h("form", { action: '.', id: `RegistrationForm${this.registrationStep}`, class: `registration__form ${this.registrationStep !== `Step${index + 1}` ? 'hidden' : ''}`, ref: el => this.form = el },
506
+ form[this.registrationStep] && form[this.registrationStep].map(input => h("general-input", { type: input.inputType, name: input.name, displayName: input.displayName, validation: input.validate, action: input.action || null, options: input.data
507
+ ? (input.inputType.toLowerCase() == 'checkboxgroup' || input.inputType.toLowerCase() == 'togglecheckbox')
508
+ ? input.data.subFields
509
+ : input.data.values
510
+ : [], defaultValue: input.defaultValue, autofilled: input.autofill, emitValue: this.emitValue, language: this.language, isDuplicateInput: input.isDuplicateInput, "client-styling": this.clientStyling, tooltip: input.tooltip, placeholder: input.placeholder == null ? '' : input.placeholder, dateFormat: this.dateFormat, "translation-url": this.translationUrl, emitOnClick: this.emitOnClick })),
511
+ this.buttonInsideForm && this.renderButtons(),
512
+ h("div", { class: 'registration__wrapper--flex' },
513
+ h("p", { class: 'registration__error-message', innerHTML: this.errorMessage })));
514
+ });
515
+ }
516
+ ;
517
+ renderButtons() {
518
+ return (h("div", { class: `registration__buttons-wrapper ${this.autofilled ? 'registration__buttons-wrapper--autofilled' : ''}` },
519
+ this.isLoadingPOST
520
+ && h("slot", { name: 'spinner' })
521
+ && h("svg", { class: "spinner", viewBox: "0 0 50 50" },
522
+ h("circle", { class: "path", cx: "25", cy: "25", r: "20", fill: "none", "stroke-width": "5" })),
523
+ !this.isLoadingPOST && h("button", { class: `registration__button registration__button--next ${this.isFormValid ? '' : 'registration__button--disabled'}`, type: 'submit', form: `RegistrationForm${this.registrationStep}`, onClick: (e) => this.nextHandler(e), disabled: !this.isFormValid }, this.lastStep === this.registrationStep ? translate('doneButton', this.language) : translate('nextButton', this.language)),
524
+ h("button", { class: `registration__button registration__button--back ${this.registrationStep == 'Step1' ? 'registration__button--first-step' : ''}`, onClick: (e) => this.backHandler(e) }, translate('backButton', this.language))));
525
+ }
526
+ render() {
527
+ if (this.isLoading) {
528
+ return h("p", null, "Please wait, loading ...");
529
+ }
530
+ return (h("div", { class: `registration registration__${this.registrationStep}` },
531
+ this.renderForm(),
532
+ !this.buttonInsideForm && this.renderButtons()));
533
+ }
534
+ static get is() { return "general-registration"; }
535
+ static get encapsulation() { return "shadow"; }
536
+ static get originalStyleUrls() { return {
537
+ "$": ["general-registration.scss"]
538
+ }; }
539
+ static get styleUrls() { return {
540
+ "$": ["general-registration.css"]
541
+ }; }
542
+ static get properties() { return {
543
+ "endpoint": {
544
+ "type": "string",
545
+ "mutable": false,
546
+ "complexType": {
547
+ "original": "string",
548
+ "resolved": "string",
549
+ "references": {}
550
+ },
551
+ "required": true,
552
+ "optional": false,
553
+ "docs": {
554
+ "tags": [],
555
+ "text": "NorWAy Endpoint for all the calls."
556
+ },
557
+ "attribute": "endpoint",
558
+ "reflect": true
559
+ },
560
+ "language": {
561
+ "type": "string",
562
+ "mutable": false,
563
+ "complexType": {
564
+ "original": "string",
565
+ "resolved": "string",
566
+ "references": {}
567
+ },
568
+ "required": false,
569
+ "optional": false,
570
+ "docs": {
571
+ "tags": [],
572
+ "text": "Currently selected language"
573
+ },
574
+ "attribute": "language",
575
+ "reflect": true,
576
+ "defaultValue": "'en'"
577
+ },
578
+ "clientStyling": {
579
+ "type": "string",
580
+ "mutable": true,
581
+ "complexType": {
582
+ "original": "string",
583
+ "resolved": "string",
584
+ "references": {}
585
+ },
586
+ "required": false,
587
+ "optional": false,
588
+ "docs": {
589
+ "tags": [],
590
+ "text": "Client custom styling via inline styles"
591
+ },
592
+ "attribute": "client-styling",
593
+ "reflect": true,
594
+ "defaultValue": "''"
595
+ },
596
+ "clientStylingUrl": {
597
+ "type": "string",
598
+ "mutable": false,
599
+ "complexType": {
600
+ "original": "string",
601
+ "resolved": "string",
602
+ "references": {}
603
+ },
604
+ "required": false,
605
+ "optional": false,
606
+ "docs": {
607
+ "tags": [],
608
+ "text": "Client custom styling via url"
609
+ },
610
+ "attribute": "client-styling-url",
611
+ "reflect": true,
612
+ "defaultValue": "''"
613
+ },
614
+ "translationUrl": {
615
+ "type": "string",
616
+ "mutable": false,
617
+ "complexType": {
618
+ "original": "string",
619
+ "resolved": "string",
620
+ "references": {}
621
+ },
622
+ "required": false,
623
+ "optional": false,
624
+ "docs": {
625
+ "tags": [],
626
+ "text": "Translations via URL"
627
+ },
628
+ "attribute": "translation-url",
629
+ "reflect": true,
630
+ "defaultValue": "''"
631
+ },
632
+ "dateFormat": {
633
+ "type": "string",
634
+ "mutable": false,
635
+ "complexType": {
636
+ "original": "string",
637
+ "resolved": "string",
638
+ "references": {}
639
+ },
640
+ "required": false,
641
+ "optional": false,
642
+ "docs": {
643
+ "tags": [],
644
+ "text": "Date format for date picker"
645
+ },
646
+ "attribute": "date-format",
647
+ "reflect": true
648
+ },
649
+ "buttonInsideForm": {
650
+ "type": "boolean",
651
+ "mutable": false,
652
+ "complexType": {
653
+ "original": "boolean",
654
+ "resolved": "boolean",
655
+ "references": {}
656
+ },
657
+ "required": true,
658
+ "optional": false,
659
+ "docs": {
660
+ "tags": [],
661
+ "text": "Boolean that decides the position of the button. e.g. button inside -- true / outside -- false the form."
662
+ },
663
+ "attribute": "button-inside-form",
664
+ "reflect": true
665
+ },
666
+ "btag": {
667
+ "type": "string",
668
+ "mutable": false,
669
+ "complexType": {
670
+ "original": "string",
671
+ "resolved": "string",
672
+ "references": {}
673
+ },
674
+ "required": false,
675
+ "optional": false,
676
+ "docs": {
677
+ "tags": [],
678
+ "text": "Affiliate code to be passed in and sent in the registration."
679
+ },
680
+ "attribute": "btag",
681
+ "reflect": true,
682
+ "defaultValue": "null"
683
+ },
684
+ "emitOnClick": {
685
+ "type": "boolean",
686
+ "mutable": false,
687
+ "complexType": {
688
+ "original": "boolean",
689
+ "resolved": "boolean",
690
+ "references": {}
691
+ },
692
+ "required": false,
693
+ "optional": false,
694
+ "docs": {
695
+ "tags": [],
696
+ "text": "Boolean flag that tells inputs to emit an event on click."
697
+ },
698
+ "attribute": "emit-on-click",
699
+ "reflect": true,
700
+ "defaultValue": "false"
701
+ }
702
+ }; }
703
+ static get states() { return {
704
+ "errorMessage": {},
705
+ "isFormValid": {},
706
+ "isLoading": {},
707
+ "isLoadingPOST": {},
708
+ "registrationStep": {},
709
+ "forms": {},
710
+ "limitStylingAppends": {},
711
+ "autofilled": {}
712
+ }; }
713
+ static get events() { return [{
714
+ "method": "registrationWidgetLoaded",
715
+ "name": "registrationWidgetLoaded",
716
+ "bubbles": true,
717
+ "cancelable": true,
718
+ "composed": true,
719
+ "docs": {
720
+ "tags": [],
721
+ "text": ""
722
+ },
723
+ "complexType": {
724
+ "original": "any",
725
+ "resolved": "any",
726
+ "references": {}
727
+ }
728
+ }, {
729
+ "method": "registrationStepUpdated",
730
+ "name": "registrationStepUpdated",
731
+ "bubbles": true,
732
+ "cancelable": true,
733
+ "composed": true,
734
+ "docs": {
735
+ "tags": [],
736
+ "text": ""
737
+ },
738
+ "complexType": {
739
+ "original": "string",
740
+ "resolved": "string",
741
+ "references": {}
742
+ }
743
+ }]; }
744
+ static get elementRef() { return "host"; }
745
+ static get watchers() { return [{
746
+ "propName": "registrationStep",
747
+ "methodName": "sendStep"
748
+ }, {
749
+ "propName": "clientStyling",
750
+ "methodName": "handleStylingChange"
751
+ }, {
752
+ "propName": "clientStylingUrl",
753
+ "methodName": "handleStylingUrlChange"
754
+ }, {
755
+ "propName": "forms",
756
+ "methodName": "setFormValidity"
757
+ }, {
758
+ "propName": "btag",
759
+ "methodName": "addBtag"
760
+ }]; }
761
+ static get listeners() { return [{
762
+ "name": "sendValidityState",
763
+ "method": "checkInputsValidityHandler",
764
+ "target": undefined,
765
+ "capture": false,
766
+ "passive": false
767
+ }, {
768
+ "name": "sendInputValue",
769
+ "method": "getInputsValueHandler",
770
+ "target": undefined,
771
+ "capture": false,
772
+ "passive": false
773
+ }]; }
774
+ }