@claspo/components 1.6.3 → 1.7.0-a11y.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 (45) hide show
  1. package/SysButtonComponent/SysButtonComponent.js +1 -1
  2. package/SysCalendarComponent/SysCalendarComponent.js +1 -1
  3. package/SysCheckboxListComponent/SysCheckboxListComponent.js +1 -1
  4. package/SysChoiceButtonsComponent/SysChoiceButtonsComponent.js +1 -1
  5. package/SysConsentComponent/SysConsentComponent.js +1 -1
  6. package/SysContainerComponent/SysContainerComponent.js +1 -1
  7. package/SysCountdownTimerComponent/SysCountdownTimerComponent.js +1 -1
  8. package/SysDateComponent/SysDateComponent.js +1 -1
  9. package/SysDropdownInputComponent/SysDropdownInputComponent.js +1 -1
  10. package/SysImageComponent/SysImageComponent.js +1 -1
  11. package/SysInAppColumnsComponent/SysInAppColumnsComponent.js +1 -1
  12. package/SysInputComponent/SysInputComponent.js +1 -1
  13. package/SysPhoneInputComponent/SysPhoneInputComponent.js +1 -1
  14. package/SysPromoCodeComponent/SysPromoCodeComponent.js +1 -1
  15. package/SysRadioGroupComponent/SysRadioGroupComponent.js +1 -1
  16. package/SysSliderComponent/SysSliderComponent.js +1 -1
  17. package/SysSocialComponent/SysSocialComponent.js +1 -1
  18. package/SysTextAreaComponent/SysTextAreaComponent.js +1 -1
  19. package/SysTextComponent/SysTextComponent.js +1 -1
  20. package/package.json +5 -3
  21. package/script/SysButtonComponent/SysButton.manifest.js +126 -0
  22. package/script/SysButtonComponent/SysButton.styles.js +64 -0
  23. package/script/SysButtonComponent/SysButtonComponent.js +231 -0
  24. package/script/SysColumnComponent/SysColumn.manifest.js +17 -0
  25. package/script/SysColumnComponent/SysColumnComponent.js +107 -0
  26. package/script/SysColumnsComponent/SysColumns.manifest.js +17 -0
  27. package/script/SysColumnsComponent/SysColumnsComponent.js +53 -0
  28. package/script/SysColumnsComponent/getStyleElement.js +23 -0
  29. package/script/SysContainerComponent/SysBaseContainerComponent.js +41 -0
  30. package/script/SysContainerComponent/SysContainer.manifest.js +18 -0
  31. package/script/SysContainerComponent/SysContainerComponent.js +86 -0
  32. package/script/SysImageComponent/SysImage.manifest.js +18 -0
  33. package/script/SysImageComponent/SysImageComponent.js +378 -0
  34. package/script/SysImageComponent/getStyleElement.js +18 -0
  35. package/script/SysInputComponent/EmailSuggesting.js +252 -0
  36. package/script/SysInputComponent/InputFormControl.js +136 -0
  37. package/script/SysInputComponent/SysInput.manifest.js +728 -0
  38. package/script/SysInputComponent/SysInputComponent.js +87 -0
  39. package/script/SysInputComponent/emailProvidersList.js +158 -0
  40. package/script/SysInputComponent/getOverlayStyles.js +220 -0
  41. package/script/SysInputComponent/getStyleElement.js +69 -0
  42. package/script/SysInputComponent/inputValidators.js +293 -0
  43. package/script/SysTextComponent/SysText.manifest.js +29 -0
  44. package/script/SysTextComponent/SysTextComponent.js +147 -0
  45. package/script/SysTextComponent/TextRoller.js +298 -0
@@ -0,0 +1,136 @@
1
+ import InputValidators from './inputValidators.js';
2
+ import { EmailSuggesting } from './EmailSuggesting.js';
3
+ import { getTranslationsMap, getWidgetLanguages } from '@claspo/renderer/sdk/TranslationUtils';
4
+
5
+ class InputFormControl {
6
+
7
+ getModel = null;
8
+ getProps = null;
9
+ getRootElement = null;
10
+ formService = null;
11
+ configService = null;
12
+ utils = null;
13
+ emailSuggesting = new EmailSuggesting();
14
+ i18n = null;
15
+ forbiddenChar = '';
16
+
17
+ constructor(
18
+ controlFactory,
19
+ getModel,
20
+ getProps,
21
+ getRootElement,
22
+ formService,
23
+ configService,
24
+ i18n,
25
+ htmlDocumentObject,
26
+ ) {
27
+ this.controlFactory = controlFactory;
28
+ this.componentId = getModel().id;
29
+ this.getProps = getProps;
30
+ this.getModel = getModel;
31
+ this.getRootElement = getRootElement;
32
+ this.formService = formService;
33
+ this.configService = configService;
34
+ this.i18n = i18n;
35
+ this.htmlDocumentObject = htmlDocumentObject;
36
+ }
37
+
38
+ init() {
39
+ const props = this.getProps();
40
+
41
+ const rootElement = this.getRootElement();
42
+ rootElement.querySelector('.input-tooltip');
43
+ const inputElement = rootElement.querySelector('input');
44
+
45
+ if (props.control.name === 'first_name') {
46
+ inputElement.setAttribute('name', 'name');
47
+ inputElement.setAttribute('autocomplete', 'off');
48
+ }
49
+
50
+ if (props.control.name === 'email') {
51
+ inputElement.setAttribute('name', 'email');
52
+ inputElement.setAttribute('autocomplete', 'on');
53
+ }
54
+
55
+ const validationMap = {
56
+ ...Object
57
+ .keys(InputValidators.validationMap)
58
+ .reduce((acc, key) => {
59
+ acc[key] = (...args) => {
60
+ const result = InputValidators.validationMap[key](...args);
61
+
62
+ if (result.forbiddenChar !== undefined) {
63
+ this.forbiddenChar = result.forbiddenChar;
64
+ }
65
+
66
+ return result;
67
+ };
68
+ return acc;
69
+ }, {}),
70
+ EMAIL: (value) => InputValidators.validationMap.EMAIL(value, this.getProps()),
71
+ };
72
+
73
+ const control = this.controlFactory([], {
74
+ validationMap,
75
+ validCallback: () => {
76
+ if (props.control.name === 'email' && rootElement.activeElement !== inputElement) {
77
+ this.suggestEmailFix(inputElement, control, true);
78
+ }
79
+ },
80
+ errorMessageMapper: (firstErrorKey, translatedValue) => {
81
+ if (firstErrorKey === InputValidators.validationErrorKeys.CONTAINS_FORBIDDEN_CHARACTERS) {
82
+ return translatedValue.replace('{{characters}}', this.forbiddenChar);
83
+ } else {
84
+ return translatedValue;
85
+ }
86
+ },
87
+ });
88
+
89
+ if (props.control.name === 'email') {
90
+ this.listenForEmailValueChanges(control);
91
+ this.suggestEmailFixOnFocusOut(inputElement, control);
92
+ }
93
+ }
94
+
95
+ destroy() {
96
+ this.emailSuggesting.hideEmailSuggestion();
97
+ }
98
+
99
+ listenForEmailValueChanges(control) {
100
+ control.on('valueChanged', value => {
101
+ this.emailSuggesting.emailValueChanged();
102
+ this.emailSuggesting.hideEmailSuggestion();
103
+ this.formatEmailValue(value, control);
104
+ });
105
+ }
106
+
107
+ formatEmailValue(value, control) {
108
+ const formattedValue = value.trim().toLowerCase();
109
+
110
+ if (formattedValue !== value) {
111
+ control.setValue(value.trim().toLowerCase());
112
+ }
113
+ }
114
+
115
+ suggestEmailFixOnFocusOut(inputElement, control) {
116
+ inputElement.addEventListener('focusout', () => this.suggestEmailFix(inputElement, control));
117
+ }
118
+
119
+ suggestEmailFix(inputElement, control, shouldSkipLastEmailSuggestionCheck) {
120
+ this.emailSuggesting.suggestEmail(
121
+ this.getProps(),
122
+ inputElement,
123
+ shouldSkipLastEmailSuggestionCheck,
124
+ this.formService,
125
+ control,
126
+ this.getCurrentLanguageMap.bind(this),
127
+ this.htmlDocumentObject,
128
+ );
129
+ }
130
+
131
+ getCurrentLanguageMap() {
132
+ return getTranslationsMap(this.i18n, getWidgetLanguages(this.configService)).translations;
133
+ }
134
+ }
135
+
136
+ export { InputFormControl as default };