@everymatrix/general-registration 1.10.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.
Files changed (68) hide show
  1. package/dist/cjs/checkbox-input_11.cjs.entry.js +1165 -0
  2. package/dist/cjs/general-registration.cjs.js +19 -0
  3. package/dist/cjs/index-c04f4a2a.js +1264 -0
  4. package/dist/cjs/index.cjs.js +2 -0
  5. package/dist/cjs/loader.cjs.js +21 -0
  6. package/dist/collection/collection-manifest.json +28 -0
  7. package/dist/collection/components/general-registration/general-registration.css +45 -0
  8. package/dist/collection/components/general-registration/general-registration.js +529 -0
  9. package/dist/collection/index.js +1 -0
  10. package/dist/collection/utils/utils.js +3 -0
  11. package/dist/components/checkbox-input.js +6 -0
  12. package/dist/components/checkbox-input2.js +78 -0
  13. package/dist/components/date-input.js +6 -0
  14. package/dist/components/date-input2.js +90 -0
  15. package/dist/components/email-input.js +6 -0
  16. package/dist/components/email-input2.js +108 -0
  17. package/dist/components/general-input.js +6 -0
  18. package/dist/components/general-input2.js +120 -0
  19. package/dist/components/general-registration.d.ts +11 -0
  20. package/dist/components/general-registration.js +530 -0
  21. package/dist/components/index.d.ts +26 -0
  22. package/dist/components/index.js +1 -0
  23. package/dist/components/locale.utils.js +29 -0
  24. package/dist/components/number-input.js +6 -0
  25. package/dist/components/number-input2.js +96 -0
  26. package/dist/components/password-input.js +6 -0
  27. package/dist/components/password-input2.js +93 -0
  28. package/dist/components/radio-input.js +6 -0
  29. package/dist/components/radio-input2.js +89 -0
  30. package/dist/components/select-input.js +6 -0
  31. package/dist/components/select-input2.js +127 -0
  32. package/dist/components/tel-input.js +6 -0
  33. package/dist/components/tel-input2.js +111 -0
  34. package/dist/components/text-input.js +6 -0
  35. package/dist/components/text-input2.js +112 -0
  36. package/dist/esm/checkbox-input_11.entry.js +1151 -0
  37. package/dist/esm/general-registration.js +17 -0
  38. package/dist/esm/index-79f297c1.js +1238 -0
  39. package/dist/esm/index.js +1 -0
  40. package/dist/esm/loader.js +17 -0
  41. package/dist/esm/polyfills/core-js.js +11 -0
  42. package/dist/esm/polyfills/css-shim.js +1 -0
  43. package/dist/esm/polyfills/dom.js +79 -0
  44. package/dist/esm/polyfills/es5-html-element.js +1 -0
  45. package/dist/esm/polyfills/index.js +34 -0
  46. package/dist/esm/polyfills/system.js +6 -0
  47. package/dist/general-registration/general-registration.esm.js +1 -0
  48. package/dist/general-registration/index.esm.js +0 -0
  49. package/dist/general-registration/p-0e7175cd.js +1 -0
  50. package/dist/general-registration/p-cadaffbe.entry.js +1 -0
  51. package/dist/index.cjs.js +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/stencil.config.js +22 -0
  54. package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/general-registration/.stencil/packages/general-input/src/utils/locale.utils.d.ts +5 -0
  55. package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/general-registration/.stencil/packages/general-input/src/utils/types.d.ts +55 -0
  56. package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/general-registration/.stencil/packages/general-registration/stencil.config.d.ts +2 -0
  57. package/dist/types/components/general-registration/general-registration.d.ts +67 -0
  58. package/dist/types/components.d.ts +77 -0
  59. package/dist/types/index.d.ts +1 -0
  60. package/dist/types/stencil-public-runtime.d.ts +1565 -0
  61. package/dist/types/utils/utils.d.ts +1 -0
  62. package/loader/cdn.js +3 -0
  63. package/loader/index.cjs.js +3 -0
  64. package/loader/index.d.ts +12 -0
  65. package/loader/index.es2017.js +3 -0
  66. package/loader/index.js +4 -0
  67. package/loader/package.json +10 -0
  68. package/package.json +22 -0
@@ -0,0 +1,1165 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-c04f4a2a.js');
6
+
7
+ const DEFAULT_LANGUAGE$1 = 'en';
8
+ const SUPPORTED_LANGUAGES$1 = ['ro', 'en'];
9
+ const TRANSLATIONS$1 = {
10
+ en: {
11
+ dateError: 'The selected date should be between {min} and {max}',
12
+ numberLengthError: 'The number should be between ${min} and ${max}',
13
+ lengthError: `The length should be between {minLength} and {maxLength}`,
14
+ requiredError: 'This input is required.',
15
+ nextButton: 'Next',
16
+ backButton: 'Back'
17
+ },
18
+ ro: {
19
+ lengthError: `Cuvântul introdus este prea scurt. {minLength} and {maxLength}`,
20
+ requiredError: 'Acest câmp este obligatoriu.'
21
+ }
22
+ };
23
+ const translate$1 = (key, customLang, values) => {
24
+ const lang = customLang;
25
+ let translation = TRANSLATIONS$1[lang !== undefined && SUPPORTED_LANGUAGES$1.includes(lang) ? lang : DEFAULT_LANGUAGE$1][key];
26
+ if (values !== undefined) {
27
+ for (const [key, value] of Object.entries(values.values)) {
28
+ const regex = new RegExp(`{${key}}`, 'g');
29
+ translation = translation.replace(regex, value);
30
+ }
31
+ }
32
+ return translation;
33
+ };
34
+
35
+ const checkboxInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.checkbox__wrapper{display:flex;gap:10px;position:relative;align-items:baseline}.checkbox__error-message{position:absolute;top:calc(100% + 5px);left:0;color:red}";
36
+
37
+ const CheckboxInput = class {
38
+ constructor(hostRef) {
39
+ index.registerInstance(this, hostRef);
40
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
41
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
42
+ }
43
+ validityChanged() {
44
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
45
+ if (this.emitValue == true) {
46
+ this.valueHandler({ name: this.name, value: this.value });
47
+ }
48
+ }
49
+ validityStateHandler(inputStateEvent) {
50
+ this.sendValidityState.emit(inputStateEvent);
51
+ }
52
+ emitValueHandler(newValue) {
53
+ if (newValue == true && this.isValid) {
54
+ this.valueHandler({ name: this.name, value: this.value });
55
+ }
56
+ }
57
+ valueHandler(inputValueEvent) {
58
+ this.sendInputValue.emit(inputValueEvent);
59
+ }
60
+ connectedCallback() {
61
+ }
62
+ handleClick() {
63
+ this.value = this.inputReference.checked;
64
+ this.errorMessage = this.setErrorMessage();
65
+ this.isValid = this.setValidity();
66
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
67
+ }
68
+ setValidity() {
69
+ return this.inputReference.validity.valid;
70
+ }
71
+ setErrorMessage() {
72
+ if (this.inputReference.validity.valueMissing) {
73
+ return translate$1('requiredError', this.language);
74
+ }
75
+ }
76
+ render() {
77
+ return index.h("div", { class: 'checkbox__wrapper' }, index.h("input", { type: "checkbox", id: `${this.name}__input`, ref: (el) => this.inputReference = el, name: this.name, required: this.validation.mandatory, value: 'jdjdj', onClick: () => this.handleClick() }), index.h("label", { htmlFor: `${this.name}__input` }, this.displayName, " ", this.validation.mandatory ? '*' : ''), index.h("small", { class: 'checkbox__error-message' }, this.errorMessage));
78
+ }
79
+ static get watchers() { return {
80
+ "isValid": ["validityChanged"],
81
+ "emitValue": ["emitValueHandler"]
82
+ }; }
83
+ };
84
+ CheckboxInput.style = checkboxInputCss;
85
+
86
+ const dateInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.date__wrapper{position:relative;display:flex;flex-direction:column-reverse;padding-top:10px}.date__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.date__label--required::after{content:\"*\";margin-left:5px;color:#666666}.date__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit}.date__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.date__input::placeholder{color:#666666}.date__input--invalid{border-bottom:3px solid #cc0000}.date__input:placeholder-shown+.date__label{opacity:0;visibility:hidden;transform:translateY(0)}.date__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
87
+
88
+ const DateInput = class {
89
+ constructor(hostRef) {
90
+ index.registerInstance(this, hostRef);
91
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
92
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
93
+ }
94
+ checkValidityHandler(newValue) {
95
+ if (newValue == true) {
96
+ this.isValid = this.setValidity();
97
+ this.errorMessage = this.setErrorMessage();
98
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
99
+ }
100
+ }
101
+ validityChanged() {
102
+ if (this.checkValidity == true) {
103
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
104
+ }
105
+ if (this.emitValue == true) {
106
+ this.valueHandler({ name: this.name, value: this.value });
107
+ }
108
+ }
109
+ validityStateHandler(inputStateEvent) {
110
+ this.sendValidityState.emit(inputStateEvent);
111
+ }
112
+ emitValueHandler(newValue) {
113
+ if (newValue == true && this.isValid) {
114
+ this.valueHandler({ name: this.name, value: this.value });
115
+ }
116
+ }
117
+ valueHandler(inputValueEvent) {
118
+ this.sendInputValue.emit(inputValueEvent);
119
+ }
120
+ handleInput(event) {
121
+ this.value = event.target.value;
122
+ this.errorMessage = this.setErrorMessage();
123
+ this.isValid = this.setValidity();
124
+ }
125
+ setValidity() {
126
+ return this.inputReference.validity.valid;
127
+ }
128
+ setErrorMessage() {
129
+ if (this.inputReference.validity.rangeUnderflow || this.inputReference.validity.rangeOverflow) {
130
+ return translate$1('dateError', this.language, { values: { min: this.validation.min, max: this.validation.max } });
131
+ }
132
+ if (this.inputReference.validity.valueMissing) {
133
+ return translate$1('requiredError', this.language);
134
+ }
135
+ }
136
+ render() {
137
+ return index.h("div", { class: 'date__wrapper' }, index.h("input", { id: `${this.name}__input`, type: 'date', class: `date__input`, value: this.defaultValue, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, ref: (el) => this.inputReference = el, required: this.validation.mandatory, max: this.validation.max, min: this.validation.min, onInput: (e) => this.handleInput(e) }), index.h("label", { class: `date__label ${this.validation.mandatory ? 'date__label--required' : ''}}`, htmlFor: `${this.name}__input` }, this.displayName, " ", this.validation.mandatory ? '*' : ''), index.h("small", { class: 'date__error-message' }, this.errorMessage));
138
+ }
139
+ static get watchers() { return {
140
+ "checkValidity": ["checkValidityHandler"],
141
+ "isValid": ["validityChanged"],
142
+ "emitValue": ["emitValueHandler"]
143
+ }; }
144
+ };
145
+ DateInput.style = dateInputCss;
146
+
147
+ const emailInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.email__wrapper{position:relative;display:flex;flex-direction:column-reverse;padding-top:10px}.email__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.email__label--required::after{content:\"*\";margin-left:5px;color:#666666}.email__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit}.email__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.email__input::placeholder{color:#666666}.email__input--invalid{border-bottom:3px solid #cc0000}.email__input:placeholder-shown+.email__label{opacity:0;visibility:hidden;transform:translateY(0)}.email__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
148
+
149
+ const EmailInput = class {
150
+ constructor(hostRef) {
151
+ index.registerInstance(this, hostRef);
152
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
153
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
154
+ this.validationPattern = '';
155
+ }
156
+ checkValidityHandler(newValue) {
157
+ if (newValue == true) {
158
+ this.isValid = this.setValidity();
159
+ this.errorMessage = this.setErrorMessage();
160
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
161
+ }
162
+ }
163
+ validityChanged() {
164
+ if (this.checkValidity == true) {
165
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
166
+ }
167
+ if (this.emitValue == true) {
168
+ this.valueHandler({ name: this.name, value: this.value });
169
+ }
170
+ }
171
+ validityStateHandler(inputStateEvent) {
172
+ this.sendValidityState.emit(inputStateEvent);
173
+ }
174
+ emitValueHandler(newValue) {
175
+ if (newValue == true && this.isValid) {
176
+ this.valueHandler({ name: this.name, value: this.value });
177
+ }
178
+ }
179
+ valueHandler(inputValueEvent) {
180
+ this.sendInputValue.emit(inputValueEvent);
181
+ }
182
+ connectedCallback() {
183
+ this.validationPattern = this.setPattern();
184
+ }
185
+ handleInput(event) {
186
+ this.value = event.target.value;
187
+ if (this.debounceTime) {
188
+ clearTimeout(this.debounceTime);
189
+ }
190
+ this.debounceTime = setTimeout(() => {
191
+ this.errorMessage = this.setErrorMessage();
192
+ this.isValid = this.setValidity();
193
+ }, 500);
194
+ }
195
+ setValidity() {
196
+ return this.inputReference.validity.valid;
197
+ }
198
+ setPattern() {
199
+ var _a;
200
+ if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
201
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').pattern;
202
+ }
203
+ }
204
+ setErrorMessage() {
205
+ if (this.inputReference.validity.patternMismatch) {
206
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').errorMessage;
207
+ }
208
+ if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
209
+ return translate$1('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
210
+ }
211
+ if (this.inputReference.validity.valueMissing) {
212
+ return translate$1('requiredError', this.language);
213
+ }
214
+ }
215
+ render() {
216
+ return index.h("div", { class: 'email__wrapper' }, index.h("input", { id: `${this.name}__input`, type: 'email', class: `email__input`, value: this.defaultValue, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, ref: (el) => this.inputReference = el, pattern: this.validationPattern, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onInput: (e) => this.handleInput(e) }), index.h("label", { class: `email__label ${this.validation.mandatory ? 'email__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), index.h("small", { class: 'email__error-message' }, this.errorMessage));
217
+ }
218
+ static get watchers() { return {
219
+ "checkValidity": ["checkValidityHandler"],
220
+ "isValid": ["validityChanged"],
221
+ "emitValue": ["emitValueHandler"]
222
+ }; }
223
+ };
224
+ EmailInput.style = emailInputCss;
225
+
226
+ const generalInputCss = ":host{display:block}";
227
+
228
+ const GeneralInput = class {
229
+ constructor(hostRef) {
230
+ index.registerInstance(this, hostRef);
231
+ /**
232
+ * Type the general-input should take. Can take the default HTML input values.
233
+ */
234
+ this.type = 'text';
235
+ }
236
+ render() {
237
+ switch (this.type.toLowerCase()) {
238
+ case 'text':
239
+ return index.h("text-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, emitValue: this.emitValue, language: this.language });
240
+ case 'email':
241
+ return index.h("email-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, emitValue: this.emitValue, language: this.language });
242
+ case 'number':
243
+ return index.h("number-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, emitValue: this.emitValue, language: this.language });
244
+ case 'checkbox':
245
+ return index.h("checkbox-input", { name: this.name, displayName: this.displayName, validation: this.validation, emitValue: this.emitValue, language: this.language });
246
+ case 'datetime':
247
+ return index.h("date-input", { name: this.name, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, emitValue: this.emitValue, language: this.language });
248
+ case 'password':
249
+ return index.h("password-input", { name: this.name, displayName: this.displayName, validation: this.validation, emitValue: this.emitValue, language: this.language });
250
+ case 'radio':
251
+ return index.h("radio-input", { name: this.name, displayName: this.displayName, optionsGroup: this.options, validation: this.validation, emitValue: this.emitValue, language: this.language });
252
+ case 'tel':
253
+ return index.h("tel-input", { name: this.name, action: this.action, displayName: this.displayName, validation: this.validation, defaultValue: this.defaultValue, emitValue: this.emitValue, language: this.language });
254
+ case 'dropdown':
255
+ return index.h("select-input", { name: this.name, action: this.action, displayName: this.displayName, options: this.options, validation: this.validation, emitValue: this.emitValue, language: this.language });
256
+ default:
257
+ // Nothing here
258
+ return index.h("p", null, "The ", this.type, " input type is not valid");
259
+ }
260
+ }
261
+ };
262
+ GeneralInput.style = generalInputCss;
263
+
264
+ const DEFAULT_LANGUAGE = 'en';
265
+ const SUPPORTED_LANGUAGES = ['ro', 'en'];
266
+ const TRANSLATIONS = {
267
+ en: {
268
+ dateError: 'The selected date should be between {min} and {max}',
269
+ numberLengthError: 'The number should be between ${min} and ${max}',
270
+ lengthError: `The length should be between {minLength} and {maxLength}`,
271
+ requiredError: 'This input is required.',
272
+ nextButton: 'Next',
273
+ backButton: 'Back'
274
+ },
275
+ ro: {
276
+ lengthError: `Cuvântul introdus este prea scurt. {minLength} and {maxLength}`,
277
+ requiredError: 'Acest câmp este obligatoriu.'
278
+ }
279
+ };
280
+ const translate = (key, customLang, values) => {
281
+ const lang = customLang;
282
+ let translation = TRANSLATIONS[lang !== undefined && SUPPORTED_LANGUAGES.includes(lang) ? lang : DEFAULT_LANGUAGE][key];
283
+ if (values !== undefined) {
284
+ for (const [key, value] of Object.entries(values.values)) {
285
+ const regex = new RegExp(`{${key}}`, 'g');
286
+ translation = translation.replace(regex, value);
287
+ }
288
+ }
289
+ return translation;
290
+ };
291
+
292
+ const generalRegistrationCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.registration{display:flex;flex-direction:column;gap:20px;width:100%;height:100%}.registration__form{display:grid;grid-template-columns:repeat(2, minmax(min-content, 1fr));column-gap:65px;row-gap:30px;justify-items:stretch;align-content:flex-start;overflow:scroll;width:100%;height:100%}.registration__buttons-wrapper{display:flex;flex-direction:row-reverse;justify-content:space-between}.registration__button{background-color:#e69200;border-radius:30px;text-transform:uppercase;padding:10px 50px;border:none;box-shadow:0px 2px 2px rgba(0, 0, 0, 0.5)}.registration__button--disabled{background-color:grey}.registration__button--done{background-color:#176317}";
293
+
294
+ const GeneralRegistration = class {
295
+ constructor(hostRef) {
296
+ index.registerInstance(this, hostRef);
297
+ this.data = {
298
+ "type": "default",
299
+ "content": {
300
+ "step": "step1",
301
+ "fields": [
302
+ {
303
+ "name": "firstName",
304
+ "displayName": "Username",
305
+ "defaultValue": null,
306
+ "validate": {
307
+ "mandatory": true,
308
+ "minLength": 3,
309
+ "maxLength": 20
310
+ },
311
+ "autofill": false
312
+ },
313
+ {
314
+ "name": "firstName",
315
+ "displayName": "Username",
316
+ "defaultValue": null,
317
+ "validate": {
318
+ "mandatory": true,
319
+ "minLength": 3,
320
+ "maxLength": 20
321
+ },
322
+ "autofill": false
323
+ },
324
+ // {
325
+ // "name": "tel",
326
+ // "displayName": "Telephone",
327
+ // "defaultValue": null,
328
+ // "validate": {
329
+ // "mandatory": true
330
+ // },
331
+ // "autofill": false,
332
+ // "inputType": "tel"
333
+ // },
334
+ // {
335
+ // "name": "dateOfBirth",
336
+ // "displayName": "Date of Birth",
337
+ // "defaultValue": null,
338
+ // "validate": {
339
+ // "min": "2023-04-01",
340
+ // "max": "2023-04-29",
341
+ // "mandatory": true,
342
+ // },
343
+ // "inputType": "datetime"
344
+ // },
345
+ // {
346
+ // "name": "email",
347
+ // "displayName": "Email",
348
+ // "defaultValue": 'a@a.com',
349
+ // "validate": {
350
+ // "mandatory": true,
351
+ // "custom": [
352
+ // {
353
+ // "rule": "regex",
354
+ // "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z-9.-]+\\.[a-zA-Z]{2,3}$",
355
+ // "errorMessage": "Please enter a valid email address"
356
+ // }
357
+ // ]
358
+ // },
359
+ // "inputType": "email"
360
+ // },
361
+ // {
362
+ // "name": "lastName",
363
+ // "displayName": "Last name",
364
+ // "defaultValue": null,
365
+ // "validate": {
366
+ // "mandatory": true,
367
+ // "minLength": 3,
368
+ // "maxLength": 20
369
+ // },
370
+ // },
371
+ // {
372
+ // "name": "password",
373
+ // "displayName": "Password",
374
+ // "defaultValue": null,
375
+ // "validate": {
376
+ // "mandatory": true,
377
+ // "minLength": 3,
378
+ // "maxLength": 20,
379
+ // "type": "password",
380
+ // "custom": [
381
+ // {
382
+ // "rule": "regex",
383
+ // "pattern": "(?=.*\\d+)(?=.*[A-Za-z]+).{8,20}",
384
+ // "errorMessage": "Password must contain at least 1 letter and 1 digit, and its minimal length is 8."
385
+ // }
386
+ // ]
387
+ // },
388
+ // "inputType": "password"
389
+ // },
390
+ // {
391
+ // "name": "email",
392
+ // "defaultValue": null,
393
+ // "validate": {
394
+ // "mandatory": true,
395
+ // "type": "email",
396
+ // "custom": [
397
+ // {
398
+ // "rule": "unique-email",
399
+ // "errorMessage": "Please check your email"
400
+ // },
401
+ // {
402
+ // "rule": "regex",
403
+ // "pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z-9.-]+\\.[a-zA-Z]{2,3}$",
404
+ // "errorMessage": "Please enter a valid email address"
405
+ // }
406
+ // ]
407
+ // }
408
+ // },
409
+ // {
410
+ // "name": "termsAndConditions",
411
+ // "displayName": "Terms and Conditions",
412
+ // "validate": {
413
+ // "mandatory": true,
414
+ // "type": "boolean"
415
+ // },
416
+ // "inputType": "checkbox"
417
+ // },
418
+ // {
419
+ // "name": "pepCheck",
420
+ // "validate": {
421
+ // "mandatory": true
422
+ // },
423
+ // "inputType": "checkbox"
424
+ // },
425
+ // {
426
+ // "name": "gender",
427
+ // "data": {
428
+ // "values": [
429
+ // {
430
+ // "label": "🍆",
431
+ // "value": "m"
432
+ // },
433
+ // {
434
+ // "label": "🍑",
435
+ // "value": "f"
436
+ // }
437
+ // ]
438
+ // },
439
+ // "validate": {
440
+ // "mandatory": true
441
+ // },
442
+ // "inputType": "radio"
443
+ // },
444
+ // {
445
+ // "name": "dateOfBirth",
446
+ // "validate": {
447
+ // "mandatory": true,
448
+ // "custom": [
449
+ // {
450
+ // "rule": "regex",
451
+ // "pattern": "(?:19\\d{2}|20[01][0-9]|2020)[-/.](?:0[1-9]|1[012])[-/.](?:0[1-9]|[12][0-9]|3[01])",
452
+ // "errorMessage": "Invalid date format"
453
+ // },
454
+ // {
455
+ // "rule": "min-18-years",
456
+ // "errorMessage": "Not old enough to ride the roller coaster"
457
+ // }
458
+ // ]
459
+ // }
460
+ // },
461
+ // {
462
+ // "name": "city",
463
+ // "displayName": "Cities",
464
+ // "action": null,
465
+ // "data": {
466
+ // "values": [
467
+ // {
468
+ // "label": "Budapest",
469
+ // "value": "Budapest"
470
+ // },
471
+ // {
472
+ // "label": "Debrecen",
473
+ // "value": "Debrecen"
474
+ // },
475
+ // {
476
+ // "label": "Miskolc",
477
+ // "value": "Miskolc"
478
+ // },
479
+ // {
480
+ // "label": "Szeged",
481
+ // "value": "Szeged"
482
+ // },
483
+ // {
484
+ // "label": "Zuglo",
485
+ // "value": "Zuglo"
486
+ // }
487
+ // ]
488
+ // },
489
+ // "validate": {
490
+ // "mandatory": true
491
+ // },
492
+ // "inputType" : "dropdown"
493
+ // },
494
+ // {
495
+ // "name": "city",
496
+ // "displayName": "Cities",
497
+ // "data": null,
498
+ // "action": "GET https://demo-api.stage.norway.everymatrix.com/v1/player/countries",
499
+ // "validate": {
500
+ // "mandatory": true
501
+ // },
502
+ // "inputType" : "dropdown"
503
+ // }
504
+ ],
505
+ "actions": [
506
+ "get-next-step",
507
+ "some-async-action-before-submitting",
508
+ "submit-step-data"
509
+ ]
510
+ }
511
+ };
512
+ /**
513
+ * Currently selected language
514
+ */
515
+ this.language = 'en';
516
+ this.emitValue = false;
517
+ this.listOfInputs = [];
518
+ this.isLoading = false;
519
+ this.listOfInputValues = [];
520
+ this.listOfActions = [];
521
+ this.actionsStepIndex = 0;
522
+ }
523
+ validityStateHandler() {
524
+ console.log('bababa', this.isFormValid);
525
+ this.buttonReference.disabled = this.isFormValid ? false : true;
526
+ }
527
+ checkInputsValidityHandler(event) {
528
+ console.log('se ajunge aici');
529
+ // Set isValid state of the input in the list.
530
+ this.listOfInputs.find(input => input.name == event.detail.name).isValid = event.detail.valid;
531
+ // Check if any one is invalid.
532
+ this.isFormValid = !this.getInvalidStatus(this.listOfInputs);
533
+ }
534
+ getInputsValueHandler(event) {
535
+ console.log('sendInputValue');
536
+ this.listOfInputValues.find(input => input.name == event.detail.name).inputValue = event.detail.value;
537
+ /*Note to self: -- what about the inputs that received a default value.
538
+ They will send an undefined because there was no input
539
+ Handle it somehow!!!!!, one idea can be that value equals defaultValue but dependes on how the api wants stuff*/
540
+ }
541
+ connectedCallback() {
542
+ }
543
+ componentWillLoad() {
544
+ // const mockCall = Promise.resolve(this.data);
545
+ // return mockCall.then((data) => {
546
+ // this.listOfInputs = data.content.fields.map((field) => {
547
+ // return { ...field, isValid: false };
548
+ // });
549
+ // });
550
+ // Initial Fetch
551
+ return this.getRegisterConfig().then((config) => {
552
+ this.formatConfig(config);
553
+ });
554
+ }
555
+ nextHandler(e) {
556
+ e.preventDefault();
557
+ // Trigger events in subwidgets.
558
+ this.emitValue = true;
559
+ if (this.isFormValid) {
560
+ this.setRegisterStep();
561
+ }
562
+ }
563
+ getRegisterConfig(registrationID) {
564
+ const url = new URL(`${this.endpoint}/api/v1.0/registerCfg/`);
565
+ const headers = new Headers();
566
+ headers.append('X-Tenant-ID', this.tenantId);
567
+ headers.append('X-Client-ID', this.clientId);
568
+ headers.append('X-Api-Key', this.apiKey);
569
+ headers.append('Content-Type', 'application/json');
570
+ headers.append('Accept', 'application/json');
571
+ if (registrationID) {
572
+ url.searchParams.append('registrationId', registrationID);
573
+ }
574
+ const options = {
575
+ method: 'GET',
576
+ headers
577
+ };
578
+ return new Promise((resolve, reject) => {
579
+ this.isLoading = true;
580
+ fetch(url.href, options)
581
+ .then((res) => res.json())
582
+ .then((config) => {
583
+ resolve(config);
584
+ }).catch((err) => {
585
+ console.error(err);
586
+ reject(err);
587
+ }).finally(() => {
588
+ this.isLoading = false;
589
+ });
590
+ });
591
+ }
592
+ setRegisterStep() {
593
+ this.emitValue = false;
594
+ const url = new URL(`${this.endpoint}/api/v1.0/registerStep/`);
595
+ const registerStep = {
596
+ registrationId: this.registrationID,
597
+ registerUserDto: this.listOfInputValues.reduce((acc, curr) => {
598
+ acc[curr.name] = curr.inputValue;
599
+ return acc;
600
+ }, {}),
601
+ step: this.registrationStep,
602
+ };
603
+ const headers = new Headers();
604
+ headers.append('X-Tenant-ID', this.tenantId);
605
+ headers.append('X-Client-ID', this.clientId);
606
+ headers.append('X-Api-Key', this.apiKey);
607
+ headers.append('Content-Type', 'application/json');
608
+ headers.append('Accept', 'application/json');
609
+ const options = {
610
+ method: 'POST',
611
+ body: JSON.stringify(registerStep),
612
+ headers
613
+ };
614
+ fetch(url.href, options)
615
+ .then((res) => {
616
+ if (res.status >= 300) {
617
+ throw new Error('err');
618
+ }
619
+ })
620
+ .then((data) => {
621
+ this.registrationID = data.registrationId;
622
+ if (this.listOfActions.some(action => action == '/register')) {
623
+ this.setRegister();
624
+ }
625
+ else {
626
+ this.getRegisterConfig(this.registrationID).then((config) => this.formatConfig(config));
627
+ }
628
+ })
629
+ .catch((err) => {
630
+ console.error(err);
631
+ });
632
+ }
633
+ setRegister() {
634
+ const url = new URL(`${this.endpoint}/api/v1.0/register/`);
635
+ const headers = new Headers();
636
+ headers.append('X-Tenant-ID', this.tenantId);
637
+ headers.append('X-Client-ID', this.clientId);
638
+ headers.append('X-Api-Key', this.apiKey);
639
+ headers.append('Content-Type', 'application/json');
640
+ headers.append('Accept', 'application/json');
641
+ const registerStep = {
642
+ registrationId: this.registrationID,
643
+ registerUserDto: this.listOfInputValues.reduce((acc, curr) => {
644
+ acc[curr.name] = curr.inputValue;
645
+ return acc;
646
+ }, {}),
647
+ step: this.registrationStep,
648
+ };
649
+ const options = {
650
+ method: 'POST',
651
+ body: JSON.stringify(registerStep),
652
+ headers
653
+ };
654
+ fetch(url.href, options)
655
+ .then((res) => {
656
+ if (res.status >= 300) {
657
+ throw new Error('err');
658
+ }
659
+ })
660
+ .then((data) => {
661
+ console.log(data);
662
+ })
663
+ .catch((err) => {
664
+ console.log(err);
665
+ });
666
+ }
667
+ formatConfig(config) {
668
+ // Populate the list of inputs and set as invalid in the beginning
669
+ this.listOfInputs = config.content.fields.map((field) => {
670
+ return Object.assign(Object.assign({}, field), { isValid: false });
671
+ });
672
+ // Populate the list of inputs values and set as null in the beginning
673
+ this.listOfInputValues = config.content.fields.map(field => {
674
+ return { name: field.name, inputValue: null };
675
+ });
676
+ // Set the list of actions
677
+ this.listOfActions = config.content.actions.map(action => action);
678
+ this.registrationID = config.content.registrationID;
679
+ this.registrationStep = config.content.step;
680
+ }
681
+ getInvalidStatus(listOfInputs) {
682
+ return listOfInputs.filter(input => input.isValid == false).length > 0;
683
+ }
684
+ renderInputs() {
685
+ /*let aux = this.listOfInputs;
686
+ this.listOfInputs = [];
687
+ this.listOfInputs = aux;*/
688
+ return (this.listOfInputs.map(input => index.h("general-input", { type: input.inputType, name: input.name, displayName: input.displayName, validation: input.validate, action: input.action || null, options: input.data ? input.data.values : [], defaultValue: input.defaultValue, emitValue: this.emitValue, language: this.language })));
689
+ }
690
+ ;
691
+ renderButtons() {
692
+ return (index.h("div", { class: 'registration__buttons-wrapper' }, index.h("button", { class: 'registration__button', type: 'submit', form: 'RegistrationForm', onClick: (e) => this.nextHandler(e), ref: (el) => this.buttonReference = el }, translate('nextButton', this.language)), index.h("button", { class: 'registration__button' }, translate('backButton', this.language))));
693
+ }
694
+ render() {
695
+ return (index.h("div", { class: 'registration' }, index.h("form", { action: '.', id: 'RegistrationForm', class: 'registration__form' }, this.renderInputs()), this.renderButtons()));
696
+ }
697
+ static get watchers() { return {
698
+ "isFormValid": ["validityStateHandler"]
699
+ }; }
700
+ };
701
+ GeneralRegistration.style = generalRegistrationCss;
702
+
703
+ const numberInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.number__wrapper{position:relative;display:flex;flex-direction:column-reverse;padding-top:10px}.number__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.number__label--required::after{content:\"*\";margin-left:5px;color:#666666}.number__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit;-moz-appearance:textfield;}.number__input::-webkit-outer-spin-button,.number__input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}.number__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.number__input::placeholder{color:#666666}.number__input--invalid{border-bottom:3px solid #cc0000}.number__input:placeholder-shown+.number__label{opacity:0;visibility:hidden;transform:translateY(0)}.number__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
704
+
705
+ const NumberInput = class {
706
+ constructor(hostRef) {
707
+ index.registerInstance(this, hostRef);
708
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
709
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
710
+ }
711
+ checkValidityHandler(newValue) {
712
+ if (newValue == true) {
713
+ this.isValid = this.setValidity();
714
+ this.errorMessage = this.setErrorMessage();
715
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
716
+ }
717
+ }
718
+ validityChanged() {
719
+ if (this.checkValidity == true) {
720
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
721
+ }
722
+ if (this.emitValue == true) {
723
+ this.valueHandler({ name: this.name, value: this.value });
724
+ }
725
+ }
726
+ validityStateHandler(inputStateEvent) {
727
+ this.sendValidityState.emit(inputStateEvent);
728
+ }
729
+ emitValueHandler(newValue) {
730
+ if (newValue == true && this.isValid) {
731
+ this.valueHandler({ name: this.name, value: this.value });
732
+ }
733
+ }
734
+ valueHandler(inputValueEvent) {
735
+ this.sendInputValue.emit(inputValueEvent);
736
+ }
737
+ handleInput(event) {
738
+ this.value = event.target.value;
739
+ if (this.debounceTime) {
740
+ clearTimeout(this.debounceTime);
741
+ }
742
+ this.debounceTime = setTimeout(() => {
743
+ this.errorMessage = this.setErrorMessage();
744
+ this.isValid = this.setValidity();
745
+ }, 500);
746
+ }
747
+ setValidity() {
748
+ return this.inputReference.validity.valid;
749
+ }
750
+ setErrorMessage() {
751
+ if (this.inputReference.validity.rangeUnderflow || this.inputReference.validity.rangeOverflow) {
752
+ return translate$1('numberLengthError', this.language, { values: { min: this.validation.min, max: this.validation.max } });
753
+ }
754
+ if (this.inputReference.validity.valueMissing) {
755
+ return translate$1('requiredError', this.language);
756
+ }
757
+ }
758
+ render() {
759
+ const invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'number__input--invalid';
760
+ return index.h("div", { class: 'number__wrapper' }, index.h("input", { ref: (el) => this.inputReference = el, type: "number", value: this.defaultValue, id: `${this.name}__input`, class: `number__input ${invalidClass}`, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, required: this.validation.mandatory, max: this.validation.max, min: this.validation.min, onInput: (e) => this.handleInput(e) }), index.h("label", { class: `number__label ${this.validation.mandatory ? 'number__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), index.h("small", { class: 'number__error-message' }, this.errorMessage));
761
+ }
762
+ static get watchers() { return {
763
+ "checkValidity": ["checkValidityHandler"],
764
+ "isValid": ["validityChanged"],
765
+ "emitValue": ["emitValueHandler"]
766
+ }; }
767
+ };
768
+ NumberInput.style = numberInputCss;
769
+
770
+ const passwordInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.password__wrapper{position:relative;display:flex;flex-direction:column-reverse;padding-top:10px}.password__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.password__label--required::after{content:\"*\";margin-left:5px;color:#666666}.password__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit}.password__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.password__input::placeholder{color:#666666}.password__input--invalid{border-bottom:3px solid #cc0000}.password__input:placeholder-shown+.password__label{opacity:0;visibility:hidden;transform:translateY(0)}.password__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
771
+
772
+ const PasswordInput = class {
773
+ constructor(hostRef) {
774
+ index.registerInstance(this, hostRef);
775
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
776
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
777
+ this.validationPattern = '';
778
+ }
779
+ validityChanged() {
780
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
781
+ if (this.emitValue == true) {
782
+ this.valueHandler({ name: this.name, value: this.value });
783
+ }
784
+ }
785
+ validityStateHandler(inputStateEvent) {
786
+ this.sendValidityState.emit(inputStateEvent);
787
+ }
788
+ emitValueHandler(newValue) {
789
+ if (newValue == true && this.isValid) {
790
+ this.valueHandler({ name: this.name, value: this.value });
791
+ }
792
+ }
793
+ valueHandler(inputValueEvent) {
794
+ this.sendInputValue.emit(inputValueEvent);
795
+ }
796
+ connectedCallback() {
797
+ this.validationPattern = this.setPattern();
798
+ }
799
+ handleInput(event) {
800
+ this.value = event.target.value;
801
+ this.errorMessage = this.setErrorMessage();
802
+ this.isValid = this.setValidity();
803
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
804
+ }
805
+ setValidity() {
806
+ return this.inputReference.validity.valid;
807
+ }
808
+ setPattern() {
809
+ var _a;
810
+ if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
811
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').pattern;
812
+ }
813
+ }
814
+ setErrorMessage() {
815
+ if (this.inputReference.validity.patternMismatch) {
816
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').errorMessage;
817
+ }
818
+ if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
819
+ return translate$1('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
820
+ }
821
+ if (this.inputReference.validity.valueMissing) {
822
+ return translate$1('requiredError', this.language);
823
+ }
824
+ }
825
+ render() {
826
+ const invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'password__input--invalid';
827
+ return index.h("div", { class: 'password__wrapper' }, index.h("input", { type: "password", id: `${this.name}__input`, class: `password__input ${invalidClass}`, name: this.name, ref: (el) => this.inputReference = el, required: this.validation.mandatory, maxlength: this.validation.maxLength, minlength: this.validation.minLength, pattern: this.validationPattern, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, onBlur: (e) => this.handleInput(e) }), index.h("label", { class: `password__label ${this.validation.mandatory ? 'password__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), index.h("small", { class: 'password__error-message' }, this.errorMessage));
828
+ }
829
+ static get watchers() { return {
830
+ "isValid": ["validityChanged"],
831
+ "emitValue": ["emitValueHandler"]
832
+ }; }
833
+ };
834
+ PasswordInput.style = passwordInputCss;
835
+
836
+ const radioInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.radio__fieldset{border:none;position:relative}.radio__wrapper{display:flex;gap:5px}.radio__error-message{position:absolute;top:calc(100% + 5px);left:0;color:red}";
837
+
838
+ const RadioInput = class {
839
+ constructor(hostRef) {
840
+ index.registerInstance(this, hostRef);
841
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
842
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
843
+ }
844
+ checkValidityHandler(newValue) {
845
+ if (newValue == true) {
846
+ this.isValid = this.setValidity();
847
+ this.errorMessage = this.setErrorMessage();
848
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
849
+ }
850
+ }
851
+ validityChanged() {
852
+ if (this.checkValidity == true) {
853
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
854
+ }
855
+ if (this.emitValue == true) {
856
+ this.valueHandler({ name: this.name, value: this.value });
857
+ }
858
+ }
859
+ emitValueHandler(newValue) {
860
+ if (newValue == true && this.isValid) {
861
+ this.valueHandler({ name: this.name, value: this.value });
862
+ }
863
+ }
864
+ valueHandler(inputValueEvent) {
865
+ this.sendInputValue.emit(inputValueEvent);
866
+ }
867
+ validityStateHandler(inputStateEvent) {
868
+ this.sendValidityState.emit(inputStateEvent);
869
+ }
870
+ connectedCallback() {
871
+ }
872
+ handleClick(event) {
873
+ this.value = event.target.value;
874
+ this.isValid = this.setValidity();
875
+ this.errorMessage = this.setErrorMessage();
876
+ }
877
+ setValidity() {
878
+ return this.inputReference.validity.valid;
879
+ }
880
+ setErrorMessage() {
881
+ if (this.inputReference.validity.valueMissing) {
882
+ return translate$1('requiredError', this.language);
883
+ }
884
+ }
885
+ render() {
886
+ return index.h("fieldset", { class: 'radio__fieldset' }, index.h("legend", { class: 'radio__legend' }, this.displayName, ":"), this.optionsGroup.map(option => index.h("div", { class: 'radio__wrapper' }, index.h("input", { type: "radio", class: 'radio__input', id: `${option.label}__input`, ref: (el) => this.inputReference = el, value: option.value, name: this.name, required: this.validation.mandatory, onClick: (e) => this.handleClick(e) }), index.h("label", { htmlFor: `${option.label}__input` }, option.label))), index.h("small", { class: 'radio__error-message' }, this.errorMessage));
887
+ }
888
+ static get watchers() { return {
889
+ "checkValidity": ["checkValidityHandler"],
890
+ "isValid": ["validityChanged"],
891
+ "emitValue": ["emitValueHandler"]
892
+ }; }
893
+ };
894
+ RadioInput.style = radioInputCss;
895
+
896
+ const selectInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.select__wrapper{position:relative;display:flex;padding-top:10px;width:100%}.select__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.select__label--hidden{opacity:0;visibility:hidden;transform:translateY(0)}.select__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit}.select__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.select__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
897
+
898
+ const SelectInput = class {
899
+ constructor(hostRef) {
900
+ index.registerInstance(this, hostRef);
901
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
902
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
903
+ /**
904
+ * Options of the input.
905
+ */
906
+ this.options = [];
907
+ }
908
+ checkValidityHandler(newValue) {
909
+ if (newValue == true) {
910
+ this.isValid = this.setValidity();
911
+ this.errorMessage = this.setErrorMessage();
912
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
913
+ }
914
+ }
915
+ validityChanged() {
916
+ if (this.checkValidity == true) {
917
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
918
+ }
919
+ if (this.emitValue == true) {
920
+ this.valueHandler({ name: this.name, value: this.value });
921
+ }
922
+ }
923
+ validityStateHandler(inputStateEvent) {
924
+ this.sendValidityState.emit(inputStateEvent);
925
+ }
926
+ emitValueHandler(newValue) {
927
+ if (newValue == true && this.isValid) {
928
+ this.valueHandler({ name: this.name, value: this.value });
929
+ }
930
+ }
931
+ valueHandler(inputValueEvent) {
932
+ this.sendInputValue.emit(inputValueEvent);
933
+ }
934
+ connectedCallback() {
935
+ this.displayedOptions = this.options;
936
+ console.log(this.displayedOptions);
937
+ }
938
+ componentWillLoad() {
939
+ console.log(this.action, this.options);
940
+ if (this.action && !this.options.length) {
941
+ if (this.action.split(" ")[0] == 'GET') {
942
+ return this.getOptions().then((options) => {
943
+ this.displayedOptions = options.countries.map(option => {
944
+ return { label: option.Name, value: option.Alpha2Code };
945
+ });
946
+ });
947
+ }
948
+ }
949
+ }
950
+ getOptions() {
951
+ // TEMPORARY FOR DEMO PURPOSES UNTIL NORWAY CONFIGURES AN ACTUAL ENDPOINT...
952
+ const url = new URL("https://demo-api.stage.norway.everymatrix.com/v1/player/countries");
953
+ return new Promise((resolve, reject) => {
954
+ fetch(url.href)
955
+ .then((res) => res.json())
956
+ .then((options) => {
957
+ resolve(options);
958
+ }).catch((err) => {
959
+ console.error(err);
960
+ reject(err);
961
+ });
962
+ });
963
+ }
964
+ handleChange(event) {
965
+ this.value = event.target.value;
966
+ this.errorMessage = this.setErrorMessage();
967
+ this.isValid = this.setValidity();
968
+ this.inputReference.previousElementSibling.classList.remove('select__label--hidden');
969
+ console.log(this.action, this.options);
970
+ }
971
+ setValidity() {
972
+ return this.inputReference.validity.valid;
973
+ }
974
+ setErrorMessage() {
975
+ if (this.inputReference.validity.valueMissing) {
976
+ return translate$1('requiredError', this.language);
977
+ }
978
+ }
979
+ render() {
980
+ console.log('RENDER');
981
+ return index.h("div", { class: 'select__wrapper' }, index.h("label", { class: 'select__label select__label--hidden', htmlFor: `${this.name}__input` }, this.displayName, ":"), index.h("select", { ref: (el) => this.inputReference = el, name: this.name, id: `${this.name}__input`, required: this.validation.mandatory, class: 'select__input', onChange: (e) => this.handleChange(e) }, index.h("option", { value: "", selected: true, disabled: true }, " ", this.displayName, " "), this.displayedOptions.map(option => {
982
+ return index.h("option", { value: option.value }, " ", option.label, " ");
983
+ })), index.h("small", { class: 'select__error-message' }, this.errorMessage));
984
+ }
985
+ static get watchers() { return {
986
+ "checkValidity": ["checkValidityHandler"],
987
+ "isValid": ["validityChanged"],
988
+ "emitValue": ["emitValueHandler"]
989
+ }; }
990
+ };
991
+ SelectInput.style = selectInputCss;
992
+
993
+ const telInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.tel__wrapper{position:relative;display:flex;flex-direction:column-reverse;padding-top:10px}.tel__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.tel__label--required::after{content:\"*\";margin-left:5px;color:#666666}.tel__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit;-moz-appearance:textfield;}.tel__input::-webkit-outer-spin-button,.tel__input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}.tel__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.tel__input::placeholder{color:#666666}.tel__input--invalid{border-bottom:3px solid #cc0000}.tel__input:placeholder-shown+.tel__label{opacity:0;visibility:hidden;transform:translateY(0)}.tel__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
994
+
995
+ const TelInput = class {
996
+ constructor(hostRef) {
997
+ index.registerInstance(this, hostRef);
998
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
999
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
1000
+ this.validationPattern = '';
1001
+ }
1002
+ checkValidityHandler(newValue) {
1003
+ if (newValue == true) {
1004
+ this.isValid = this.setValidity();
1005
+ this.errorMessage = this.setErrorMessage();
1006
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
1007
+ }
1008
+ }
1009
+ validityChanged() {
1010
+ if (this.checkValidity == true) {
1011
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
1012
+ }
1013
+ if (this.emitValue == true) {
1014
+ this.valueHandler({ name: this.name, value: this.value });
1015
+ }
1016
+ }
1017
+ validityStateHandler(inputStateEvent) {
1018
+ this.sendValidityState.emit(inputStateEvent);
1019
+ }
1020
+ emitValueHandler(newValue) {
1021
+ if (newValue == true && this.isValid) {
1022
+ this.valueHandler({ name: this.name, value: this.value });
1023
+ }
1024
+ }
1025
+ valueHandler(inputValueEvent) {
1026
+ this.sendInputValue.emit(inputValueEvent);
1027
+ }
1028
+ connectedCallback() {
1029
+ this.validationPattern = this.setPattern();
1030
+ }
1031
+ handleInput(event) {
1032
+ this.value = event.target.value;
1033
+ if (this.debounceTime) {
1034
+ clearTimeout(this.debounceTime);
1035
+ }
1036
+ this.debounceTime = setTimeout(() => {
1037
+ this.errorMessage = this.setErrorMessage();
1038
+ this.isValid = this.setValidity();
1039
+ }, 500);
1040
+ }
1041
+ setValidity() {
1042
+ return this.inputReference.validity.valid;
1043
+ }
1044
+ setPattern() {
1045
+ var _a;
1046
+ if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1047
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').pattern;
1048
+ }
1049
+ }
1050
+ setErrorMessage() {
1051
+ if (this.inputReference.validity.patternMismatch) {
1052
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').errorMessage;
1053
+ }
1054
+ if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
1055
+ return translate$1('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
1056
+ }
1057
+ if (this.inputReference.validity.valueMissing) {
1058
+ return translate$1('requiredError', this.language);
1059
+ }
1060
+ }
1061
+ render() {
1062
+ const invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'tel__input--invalid';
1063
+ return index.h("div", { class: 'tel__wrapper' }, index.h("input", { type: "tel", ref: (el) => this.inputReference = el, id: `${this.name}__input`, value: this.defaultValue, class: `tel__input ${invalidClass}`, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, pattern: this.validationPattern, onInput: (e) => this.handleInput(e) }), index.h("label", { class: `tel__label ${this.validation.mandatory ? 'tel__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), index.h("small", { class: 'tel__error-message' }, this.errorMessage));
1064
+ }
1065
+ static get watchers() { return {
1066
+ "checkValidity": ["checkValidityHandler"],
1067
+ "isValid": ["validityChanged"],
1068
+ "emitValue": ["emitValueHandler"]
1069
+ }; }
1070
+ };
1071
+ TelInput.style = telInputCss;
1072
+
1073
+ const textInputCss = "*,*::before,*::after{padding:0;margin:0;box-sizing:border-box}.text__wrapper{position:relative;display:flex;flex-direction:column-reverse;padding-top:10px}.text__label{color:#474747;font-size:16px;position:absolute;bottom:15px;left:5px;transform:translateY(-25px);transition:all 0.3s cubic-bezier(0.5, 0, 0.5, 1)}.text__label--required::after{content:\"*\";margin-left:5px;color:#666666}.text__input{width:inherit;padding:15px 6px;position:relative;border:none;border-bottom:3px solid #666666;background-color:transparent;color:#666666;font-size:16px;font-family:inherit}.text__input:focus{outline:none;box-shadow:0 5px 5px rgba(16, 15, 15, 0.1)}.text__input::placeholder{color:#666666}.text__input--invalid{border-bottom:3px solid #cc0000}.text__input:placeholder-shown+.text__label{opacity:0;visibility:hidden;transform:translateY(0)}.text__error-message{position:absolute;top:calc(100% + 5px);left:0;color:#cc0000}";
1074
+
1075
+ const TextInput = class {
1076
+ constructor(hostRef) {
1077
+ index.registerInstance(this, hostRef);
1078
+ this.sendValidityState = index.createEvent(this, "sendValidityState", 7);
1079
+ this.sendInputValue = index.createEvent(this, "sendInputValue", 7);
1080
+ /**
1081
+ * Default value for the input.
1082
+ */
1083
+ this.defaultValue = '';
1084
+ this.errorMessage = '';
1085
+ this.value = '';
1086
+ this.customRules = [];
1087
+ this.validationPattern = '';
1088
+ }
1089
+ validityChanged() {
1090
+ if (this.emitValue == true) {
1091
+ this.valueHandler({ name: this.name, value: this.value });
1092
+ }
1093
+ }
1094
+ validityStateHandler(inputStateEvent) {
1095
+ this.sendValidityState.emit(inputStateEvent);
1096
+ }
1097
+ emitValueHandler(newValue) {
1098
+ if (newValue == true && this.isValid) {
1099
+ this.valueHandler({ name: this.name, value: this.value });
1100
+ }
1101
+ }
1102
+ valueHandler(inputValueEvent) {
1103
+ this.sendInputValue.emit(inputValueEvent);
1104
+ }
1105
+ connectedCallback() {
1106
+ // @TODO do something with customRules !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1107
+ this.customRules = this.setCustomRules();
1108
+ this.validationPattern = this.setPattern();
1109
+ }
1110
+ handleInput(event) {
1111
+ this.value = event.target.value;
1112
+ this.isValid = this.setValidity();
1113
+ this.errorMessage = this.setErrorMessage();
1114
+ this.validityStateHandler({ valid: this.isValid, name: this.name });
1115
+ }
1116
+ setValidity() {
1117
+ return this.inputReference.validity.valid;
1118
+ }
1119
+ // @TODO type here
1120
+ setCustomRules() {
1121
+ var _a;
1122
+ if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1123
+ return this.validation.custom.filter(customValidation => customValidation.rule !== 'regex');
1124
+ }
1125
+ }
1126
+ setPattern() {
1127
+ var _a;
1128
+ if (((_a = this.validation.custom) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1129
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').pattern;
1130
+ }
1131
+ }
1132
+ setErrorMessage() {
1133
+ if (this.inputReference.validity.patternMismatch) {
1134
+ return this.validation.custom.find(customValidation => customValidation.rule === 'regex').errorMessage;
1135
+ }
1136
+ if (this.inputReference.validity.tooShort || this.inputReference.validity.tooLong) {
1137
+ return translate$1('lengthError', this.language, { values: { minLength: this.validation.minLength, maxLength: this.validation.maxLength } });
1138
+ }
1139
+ if (this.inputReference.validity.valueMissing) {
1140
+ return translate$1('requiredError', this.language);
1141
+ }
1142
+ }
1143
+ render() {
1144
+ const invalidClass = this.isValid == true || this.isValid == undefined ? '' : 'text__input--invalid';
1145
+ console.log('this', this.name, this.defaultValue, this.displayName);
1146
+ return index.h("div", { class: 'text__wrapper' }, index.h("input", { id: `${this.name}__input`, value: this.defaultValue, type: 'text', class: `text__input ${invalidClass}`, placeholder: `${this.displayName} ${this.validation.mandatory ? '*' : ''}`, ref: (el) => this.inputReference = el, pattern: this.validationPattern, required: this.validation.mandatory, minlength: this.validation.minLength, maxlength: this.validation.maxLength, onBlur: (e) => { this.handleInput(e); } }), index.h("label", { class: `text__label ${this.validation.mandatory ? 'text__label--required' : ''}`, htmlFor: `${this.name}__input` }, this.displayName), index.h("small", { class: 'text__error-message' }, this.errorMessage));
1147
+ }
1148
+ static get watchers() { return {
1149
+ "isValid": ["validityChanged"],
1150
+ "emitValue": ["emitValueHandler"]
1151
+ }; }
1152
+ };
1153
+ TextInput.style = textInputCss;
1154
+
1155
+ exports.checkbox_input = CheckboxInput;
1156
+ exports.date_input = DateInput;
1157
+ exports.email_input = EmailInput;
1158
+ exports.general_input = GeneralInput;
1159
+ exports.general_registration = GeneralRegistration;
1160
+ exports.number_input = NumberInput;
1161
+ exports.password_input = PasswordInput;
1162
+ exports.radio_input = RadioInput;
1163
+ exports.select_input = SelectInput;
1164
+ exports.tel_input = TelInput;
1165
+ exports.text_input = TextInput;