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