@luftborn/custom-elements 1.1.44 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/assets/style.css +277 -277
- package/azure-pipeline.yml +54 -0
- package/demo/index.html +585 -585
- package/demo/index.js +6109 -0
- package/demo/index.min.js +6110 -0
- package/demo/index.min.js.map +1 -0
- package/demo/index.ts +11 -11
- package/demo/old/index.html +586 -586
- package/demo/old/index.js +10849 -10849
- package/demo/old/index.min.js +10850 -10850
- package/demo/old/index.ts +10 -10
- package/dist/custom-form.d.ts +20 -20
- package/dist/custom-form.js +147 -146
- package/dist/custom-form.js.map +1 -1
- package/dist/elements/Address/AddressElement.d.ts +28 -28
- package/dist/elements/Address/AddressElement.js +206 -206
- package/dist/elements/BankField/BankFieldElement.d.ts +22 -22
- package/dist/elements/BankField/BankFieldElement.js +127 -127
- package/dist/elements/CPRElement/CPRElement.d.ts +14 -14
- package/dist/elements/CPRElement/CPRElement.js +82 -82
- package/dist/elements/CVRElement/CVRElement.d.ts +14 -14
- package/dist/elements/CVRElement/CVRElement.js +82 -82
- package/dist/elements/CheckBoxElement/CheckBoxElement.d.ts +14 -14
- package/dist/elements/CheckBoxElement/CheckBoxElement.js +96 -96
- package/dist/elements/CheckBoxElement/CheckBoxElement.js.map +1 -1
- package/dist/elements/CustomRegularExpression/CustomRegularExpressionElement.d.ts +12 -12
- package/dist/elements/CustomRegularExpression/CustomRegularExpressionElement.js +82 -82
- package/dist/elements/DateField/DateFieldElement.d.ts +12 -12
- package/dist/elements/DateField/DateFieldElement.js +85 -85
- package/dist/elements/DropDownList/DropDownListElement.d.ts +14 -14
- package/dist/elements/DropDownList/DropDownListElement.js +93 -93
- package/dist/elements/DropDownList/DropDownListElement.js.map +1 -1
- package/dist/elements/Elements.d.ts +18 -18
- package/dist/elements/Elements.js +37 -37
- package/dist/elements/EmailField/EmailFieldElement.d.ts +13 -13
- package/dist/elements/EmailField/EmailFieldElement.js +83 -83
- package/dist/elements/FileField/FileFieldElement.d.ts +15 -12
- package/dist/elements/FileField/FileFieldElement.js +103 -83
- package/dist/elements/FileField/FileFieldElement.js.map +1 -1
- package/dist/elements/IdentificationElement/IdentificationElement.d.ts +18 -18
- package/dist/elements/IdentificationElement/IdentificationElement.js +94 -94
- package/dist/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.d.ts +16 -16
- package/dist/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.js +114 -108
- package/dist/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.js.map +1 -1
- package/dist/elements/NumericField/NumericFieldElement.d.ts +12 -12
- package/dist/elements/NumericField/NumericFieldElement.js +91 -91
- package/dist/elements/RadioButtonGroup/RadioButtonGroupElement.d.ts +14 -14
- package/dist/elements/RadioButtonGroup/RadioButtonGroupElement.js +99 -99
- package/dist/elements/RadioButtonGroup/RadioButtonGroupElement.js.map +1 -1
- package/dist/elements/TextAreaElement/TextAreaElement.d.ts +12 -12
- package/dist/elements/TextAreaElement/TextAreaElement.js +79 -79
- package/dist/elements/TextField/TextFieldElement.d.ts +12 -12
- package/dist/elements/TextField/TextFieldElement.js +79 -79
- package/dist/elements/TypeAhead/TypeAheadElement.d.ts +24 -24
- package/dist/elements/TypeAhead/TypeAheadElement.js +209 -209
- package/dist/framework/CustomEvents.d.ts +21 -21
- package/dist/framework/CustomEvents.js +47 -47
- package/dist/framework/CustomInputElement.d.ts +50 -50
- package/dist/framework/CustomInputElement.js +258 -257
- package/dist/framework/CustomInputElement.js.map +1 -1
- package/dist/framework/Language/Languages/Base/BaseDictionary.d.ts +4 -4
- package/dist/framework/Language/Languages/Base/BaseDictionary.js +20 -20
- package/dist/framework/Language/Languages/CzechDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/CzechDictionary.js +40 -0
- package/dist/framework/Language/Languages/CzechDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/DanishDictionary.d.ts +4 -4
- package/dist/framework/Language/Languages/DanishDictionary.js +39 -39
- package/dist/framework/Language/Languages/DutchDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/DutchDictionary.js +40 -0
- package/dist/framework/Language/Languages/DutchDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/EnglishDictionary.d.ts +4 -4
- package/dist/framework/Language/Languages/EnglishDictionary.js +39 -39
- package/dist/framework/Language/Languages/EstonianDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/EstonianDictionary.js +40 -0
- package/dist/framework/Language/Languages/EstonianDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/FinnishDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/FinnishDictionary.js +40 -0
- package/dist/framework/Language/Languages/FinnishDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/FrenchDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/FrenchDictionary.js +40 -0
- package/dist/framework/Language/Languages/FrenchDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/GermanDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/GermanDictionary.js +40 -0
- package/dist/framework/Language/Languages/GermanDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/GreekDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/GreekDictionary.js +40 -0
- package/dist/framework/Language/Languages/GreekDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/HungarianDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/HungarianDictionary.js +40 -0
- package/dist/framework/Language/Languages/HungarianDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/IcelandicDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/IcelandicDictionary.js +40 -0
- package/dist/framework/Language/Languages/IcelandicDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/ItalianDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/ItalianDictionary.js +40 -0
- package/dist/framework/Language/Languages/ItalianDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/LatvianDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/LatvianDictionary.js +40 -0
- package/dist/framework/Language/Languages/LatvianDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/LituanianDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/LituanianDictionary.js +40 -0
- package/dist/framework/Language/Languages/LituanianDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/NorwegianDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/NorwegianDictionary.js +40 -0
- package/dist/framework/Language/Languages/NorwegianDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/PolishDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/PolishDictionary.js +40 -0
- package/dist/framework/Language/Languages/PolishDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/PortugueseDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/PortugueseDictionary.js +40 -0
- package/dist/framework/Language/Languages/PortugueseDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/SpanishDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/SpanishDictionary.js +40 -0
- package/dist/framework/Language/Languages/SpanishDictionary.js.map +1 -0
- package/dist/framework/Language/Languages/SwedishDictionary.d.ts +4 -0
- package/dist/framework/Language/Languages/SwedishDictionary.js +40 -0
- package/dist/framework/Language/Languages/SwedishDictionary.js.map +1 -0
- package/dist/framework/Language/Translator.d.ts +23 -6
- package/dist/framework/Language/Translator.js +115 -32
- package/dist/framework/Language/Translator.js.map +1 -1
- package/dist/framework/Models/OptionWithDescription.d.ts +6 -6
- package/dist/framework/Models/OptionWithDescription.js +9 -9
- package/dist/framework/Polyfills/getAttributeNamesPolyfill.d.ts +1 -1
- package/dist/framework/Polyfills/getAttributeNamesPolyfill.js +17 -17
- package/dist/framework/Translations/CaseConverter.d.ts +5 -5
- package/dist/framework/Translations/CaseConverter.js +50 -50
- package/dist/framework/Utilities/ArrayUtil.d.ts +6 -0
- package/dist/framework/Utilities/ArrayUtil.js +37 -0
- package/dist/framework/Utilities/ArrayUtil.js.map +1 -0
- package/dist/framework/Utilities/DomUtil.d.ts +21 -0
- package/dist/framework/Utilities/DomUtil.js +102 -0
- package/dist/framework/Utilities/DomUtil.js.map +1 -0
- package/dist/framework/Utilities/DomUtility.d.ts +3 -3
- package/dist/framework/Utilities/DomUtility.js +12 -12
- package/dist/framework/Utilities/MakeRequest.d.ts +8 -0
- package/dist/framework/Utilities/MakeRequest.js +49 -0
- package/dist/framework/Utilities/MakeRequest.js.map +1 -0
- package/dist/framework/Utilities/StringUtil.d.ts +4 -0
- package/dist/framework/Utilities/StringUtil.js +17 -0
- package/dist/framework/Utilities/StringUtil.js.map +1 -0
- package/dist/framework/Utilities/ViewportUtil.d.ts +8 -0
- package/dist/framework/Utilities/ViewportUtil.js +43 -0
- package/dist/framework/Utilities/ViewportUtil.js.map +1 -0
- package/dist/framework/Utilities/debouncer.d.ts +8 -8
- package/dist/framework/Utilities/debouncer.js +51 -51
- package/dist/framework/Validation/IValidator.interface.d.ts +3 -3
- package/dist/framework/Validation/IValidator.interface.js +2 -2
- package/dist/framework/Validation/Validators/BankAccount.d.ts +4 -4
- package/dist/framework/Validation/Validators/BankAccount.js +12 -12
- package/dist/framework/Validation/Validators/BankAccountRegistrationNumber.d.ts +4 -4
- package/dist/framework/Validation/Validators/BankAccountRegistrationNumber.js +12 -12
- package/dist/framework/Validation/Validators/BankIdNorway.d.ts +5 -5
- package/dist/framework/Validation/Validators/BankIdNorway.js +21 -21
- package/dist/framework/Validation/Validators/BankIdSweden.d.ts +5 -5
- package/dist/framework/Validation/Validators/BankIdSweden.js +21 -21
- package/dist/framework/Validation/Validators/CPR.d.ts +9 -9
- package/dist/framework/Validation/Validators/CPR.js +75 -75
- package/dist/framework/Validation/Validators/CVR.d.ts +5 -5
- package/dist/framework/Validation/Validators/CVR.js +30 -30
- package/dist/framework/custom-element.decorator.d.ts +9 -9
- package/dist/framework/custom-element.decorator.js +51 -51
- package/dist/index.d.ts +7 -7
- package/dist/index.js +14 -14
- package/node_modules/@webcomponents/webcomponentsjs/CHANGELOG.md +15 -0
- package/node_modules/@webcomponents/webcomponentsjs/README.md +13 -0
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-ce.js +31 -31
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-ce.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-pf_dom.js +15 -13
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-pf_dom.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-pf_js.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce-pf.js +237 -223
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce-pf.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce.js +188 -176
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd-ce.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd.js +155 -144
- package/node_modules/@webcomponents/webcomponentsjs/bundles/webcomponents-sd.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/package.json +31 -64
- package/node_modules/@webcomponents/webcomponentsjs/src/entrypoints/webcomponents-pf_dom-index.js +2 -0
- package/node_modules/@webcomponents/webcomponentsjs/src/platform/event-listener-options.js +122 -0
- package/node_modules/@webcomponents/webcomponentsjs/src/platform/toggle-attribute.js +39 -0
- package/node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.d.ts +1 -0
- package/node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js +239 -225
- package/node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js.map +1 -1
- package/node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js +35 -3
- package/package.json +38 -39
- package/src/custom-form.ts +140 -139
- package/src/elements/Address/AddressElement.ts +216 -216
- package/src/elements/BankField/BankFieldElement.ts +127 -127
- package/src/elements/CPRElement/CPRElement.ts +74 -74
- package/src/elements/CVRElement/CVRElement.ts +75 -75
- package/src/elements/CheckBoxElement/CheckBoxElement.ts +99 -99
- package/src/elements/CustomRegularExpression/CustomRegularExpressionElement.ts +75 -75
- package/src/elements/DateField/DateFieldElement.ts +78 -78
- package/src/elements/DropDownList/DropDownListElement.ts +100 -100
- package/src/elements/Elements.ts +37 -37
- package/src/elements/EmailField/EmailFieldElement.ts +78 -78
- package/src/elements/FileField/FileFieldElement.ts +96 -76
- package/src/elements/IdentificationElement/IdentificationElement.ts +104 -104
- package/src/elements/InternationaPhoneNumber/InternationaPhoneNumberElement.ts +116 -111
- package/src/elements/NumericField/NumericFieldElement.ts +84 -84
- package/src/elements/RadioButtonGroup/RadioButtonGroupElement.ts +103 -103
- package/src/elements/TextAreaElement/TextAreaElement.ts +72 -72
- package/src/elements/TextField/TextFieldElement.ts +72 -72
- package/src/elements/TypeAhead/TypeAheadElement.ts +248 -248
- package/src/framework/CustomEvents.ts +47 -47
- package/src/framework/CustomInputElement.ts +277 -276
- package/src/framework/Language/Languages/Base/BaseDictionary.ts +15 -15
- package/src/framework/Language/Languages/CzechDictionary.ts +18 -0
- package/src/framework/Language/Languages/DanishDictionary.ts +17 -17
- package/src/framework/Language/Languages/DutchDictionary.ts +18 -0
- package/src/framework/Language/Languages/EnglishDictionary.ts +18 -18
- package/src/framework/Language/Languages/EstonianDictionary.ts +18 -0
- package/src/framework/Language/Languages/FinnishDictionary.ts +18 -0
- package/src/framework/Language/Languages/FrenchDictionary.ts +18 -0
- package/src/framework/Language/Languages/GermanDictionary.ts +18 -0
- package/src/framework/Language/Languages/GreekDictionary.ts +18 -0
- package/src/framework/Language/Languages/HungarianDictionary.ts +18 -0
- package/src/framework/Language/Languages/IcelandicDictionary.ts +18 -0
- package/src/framework/Language/Languages/ItalianDictionary.ts +18 -0
- package/src/framework/Language/Languages/LatvianDictionary.ts +18 -0
- package/src/framework/Language/Languages/LituanianDictionary.ts +18 -0
- package/src/framework/Language/Languages/NorwegianDictionary.ts +18 -0
- package/src/framework/Language/Languages/PolishDictionary.ts +18 -0
- package/src/framework/Language/Languages/PortugueseDictionary.ts +18 -0
- package/src/framework/Language/Languages/SpanishDictionary.ts +18 -0
- package/src/framework/Language/Languages/SwedishDictionary.ts +18 -0
- package/src/framework/Language/Translator.ts +110 -26
- package/src/framework/Models/OptionWithDescription.ts +8 -8
- package/src/framework/Polyfills/getAttributeNamesPolyfill.ts +13 -13
- package/src/framework/Translations/CaseConverter.ts +43 -43
- package/src/framework/Utilities/ArrayUtil.ts +31 -0
- package/src/framework/Utilities/DomUtil.ts +117 -0
- package/src/framework/Utilities/DomUtility.ts +6 -6
- package/src/framework/Utilities/MakeRequest.ts +47 -0
- package/src/framework/Utilities/StringUtil.ts +9 -0
- package/src/framework/Utilities/ViewportUtil.ts +46 -0
- package/src/framework/Utilities/debouncer.ts +66 -66
- package/src/framework/Validation/IValidator.interface.ts +3 -3
- package/src/framework/Validation/Validators/BankAccount.ts +7 -7
- package/src/framework/Validation/Validators/BankAccountRegistrationNumber.ts +8 -8
- package/src/framework/Validation/Validators/BankIdNorway.ts +21 -21
- package/src/framework/Validation/Validators/BankIdSweden.ts +21 -21
- package/src/framework/Validation/Validators/CPR.ts +82 -82
- package/src/framework/Validation/Validators/CVR.ts +27 -27
- package/src/framework/custom-element.decorator.ts +57 -57
- package/src/index.ts +12 -12
|
@@ -1,216 +1,216 @@
|
|
|
1
|
-
import CustomElement from '../../framework/custom-element.decorator';
|
|
2
|
-
import { CustomInputElement } from '../../framework/CustomInputElement';
|
|
3
|
-
import { CustomElementEventArgs } from '../../framework/CustomEvents';
|
|
4
|
-
import Translator from '../../framework/Language/Translator';
|
|
5
|
-
import getAttributeNamesPolyfill from '../../framework/Polyfills/getAttributeNamesPolyfill';
|
|
6
|
-
import debouncer from "../../framework/Utilities/debouncer";
|
|
7
|
-
|
|
8
|
-
@CustomElement({
|
|
9
|
-
selector: 'address-element',
|
|
10
|
-
template: `
|
|
11
|
-
<div class="address-wrapper">
|
|
12
|
-
<input class='address-part' id='address' type="text" placeholder='Address'/>
|
|
13
|
-
<input class='address-part' id='zip' type="text" placeholder='Zip'/>
|
|
14
|
-
<input class='address-part' id='city' type="text" placeholder='City'/>
|
|
15
|
-
<input class='address-part' id='country' type="text" placeholder='Country'/>
|
|
16
|
-
</div>`,
|
|
17
|
-
style: `.address-wrapper{
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-wrap: nowrap;
|
|
20
|
-
}
|
|
21
|
-
input.address-part{
|
|
22
|
-
box-sizing: border-box;
|
|
23
|
-
border: none;
|
|
24
|
-
background-color: #f1f4ff;
|
|
25
|
-
margin: 2px;
|
|
26
|
-
resize: none;
|
|
27
|
-
width:33% !important;
|
|
28
|
-
}
|
|
29
|
-
`,
|
|
30
|
-
templatePath: './html.html',
|
|
31
|
-
useShadow: true,
|
|
32
|
-
})
|
|
33
|
-
export class AddressElement extends CustomInputElement {
|
|
34
|
-
private autoCompleteEnabled = false;
|
|
35
|
-
private addressAutoComplete: google.maps.places.Autocomplete;
|
|
36
|
-
private googlePlacesLibraryElement: HTMLScriptElement;
|
|
37
|
-
private googlePlacesApiKey: string;
|
|
38
|
-
|
|
39
|
-
address: HTMLInputElement;
|
|
40
|
-
city: HTMLInputElement;
|
|
41
|
-
country: HTMLInputElement;
|
|
42
|
-
zip: HTMLInputElement;
|
|
43
|
-
|
|
44
|
-
constructor() {
|
|
45
|
-
super();
|
|
46
|
-
getAttributeNamesPolyfill();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get value(): string {
|
|
50
|
-
let address = this.address.value || '';
|
|
51
|
-
let city = this.city.value ? `,${this.city.value}` : '';
|
|
52
|
-
let zip = this.zip.value ? `,${this.zip.value}` : '';
|
|
53
|
-
let country = this.country.value ? `,${this.country.value}` : '';
|
|
54
|
-
return `${address}${city}${zip}${country}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
set value(value: string) {
|
|
58
|
-
const values = value.split(',');
|
|
59
|
-
this.address.value = values[0];
|
|
60
|
-
this.city.value = values[1];
|
|
61
|
-
this.country.value = values[2];
|
|
62
|
-
this.zip.value = values[3];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get valid(): boolean {
|
|
66
|
-
return (
|
|
67
|
-
this.address.validity.valid &&
|
|
68
|
-
this.city.validity.valid &&
|
|
69
|
-
this.country.validity.valid &&
|
|
70
|
-
this.zip.validity.valid
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
connectedCallback(): void {
|
|
75
|
-
super.connectedCallback();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
componentDidMount() {
|
|
79
|
-
this.initChildInputs();
|
|
80
|
-
this.getAttributeNames().forEach(attributeName => {
|
|
81
|
-
let attributeValue = this.getAttribute(attributeName);
|
|
82
|
-
this.attributeChanged(attributeName, null, attributeValue);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
initChildInputs() {
|
|
87
|
-
this.address = super.getChildInput('#address');
|
|
88
|
-
this.city = super.getChildInput('#city');
|
|
89
|
-
this.country = super.getChildInput('#country');
|
|
90
|
-
this.zip = super.getChildInput('#zip');
|
|
91
|
-
const addressChaneDebounce = debouncer(this.change.bind(this), 400, false);
|
|
92
|
-
this.address.addEventListener('change', () => {
|
|
93
|
-
addressChaneDebounce();
|
|
94
|
-
});
|
|
95
|
-
this.city.addEventListener('change', this.change.bind(this));
|
|
96
|
-
this.country.addEventListener('change', this.change.bind(this));
|
|
97
|
-
this.zip.addEventListener('change', this.change.bind(this));
|
|
98
|
-
|
|
99
|
-
if (this.required) {
|
|
100
|
-
this.address.setAttribute('required', '');
|
|
101
|
-
this.city.setAttribute('required', '');
|
|
102
|
-
this.country.setAttribute('required', '');
|
|
103
|
-
this.zip.setAttribute('required', '');
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// events
|
|
108
|
-
public change($event): void {
|
|
109
|
-
this.touched = true;
|
|
110
|
-
this.onChange.emit(new CustomElementEventArgs(this.value, 'change'));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
public validate(): void {
|
|
114
|
-
this.valid;
|
|
115
|
-
this.onValidate.emit(
|
|
116
|
-
new CustomElementEventArgs(this.value, 'validate'),
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
changeLanguage(language: string) {
|
|
121
|
-
if (!this.address || !this.city || !this.country || !this.zip) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.address.placeholder = Translator.Translate('AddressElement.Address', language);
|
|
125
|
-
this.city.placeholder = Translator.Translate('AddressElement.City', language);
|
|
126
|
-
this.country.placeholder = Translator.Translate('AddressElement.Country', language);
|
|
127
|
-
this.zip.placeholder = Translator.Translate('AddressElement.Zip', language);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
enableAutoComplete() {
|
|
131
|
-
if (!this.googlePlacesApiKey || this.googlePlacesApiKey.trim() === '' || !this.autoCompleteEnabled) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
this.googlePlacesLibraryElement = document.querySelector<HTMLScriptElement>(`[src="https://maps.googleapis.com/maps/api/js?key=${this.googlePlacesApiKey}&libraries=places"]`);
|
|
136
|
-
if (this.googlePlacesLibraryElement) {
|
|
137
|
-
this.googlePlacesLibraryElementBindLoad();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
this.googlePlacesLibraryElement = document.createElement('script');
|
|
141
|
-
this.googlePlacesLibraryElement.type = 'text/javascript';
|
|
142
|
-
this.googlePlacesLibraryElement.src = `https://maps.googleapis.com/maps/api/js?key=${this.googlePlacesApiKey}&libraries=places`;
|
|
143
|
-
window.document.head.appendChild(this.googlePlacesLibraryElement);
|
|
144
|
-
this.googlePlacesLibraryElementBindLoad();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private googlePlacesLibraryElementBindLoad() {
|
|
148
|
-
this.googlePlacesLibraryElement.addEventListener('load', () => {
|
|
149
|
-
this.bindAutoComplete();
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
bindAutoComplete(): void {
|
|
154
|
-
this.addressAutoComplete = new google.maps.places.Autocomplete(this.address);
|
|
155
|
-
this.addressAutoComplete.addListener("place_changed", this.onAddressChangedHandler.bind(this));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
onAddressChangedHandler() {
|
|
159
|
-
this.city.value = '';
|
|
160
|
-
this.country.value = '';
|
|
161
|
-
this.zip.value = '';
|
|
162
|
-
|
|
163
|
-
const place = this.addressAutoComplete.getPlace();
|
|
164
|
-
console.log(place);
|
|
165
|
-
if (!place.address_components) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
this.address.value = place.name;
|
|
170
|
-
|
|
171
|
-
const cityComponents = place.address_components.filter(component => {
|
|
172
|
-
const citySynonyms = ['administrative_area_level_1', 'locality'];
|
|
173
|
-
const isCityComponent = citySynonyms.some(citySynonym => component.types.indexOf(citySynonym) != -1);
|
|
174
|
-
return isCityComponent;
|
|
175
|
-
});
|
|
176
|
-
if (cityComponents && cityComponents[0]) {
|
|
177
|
-
this.city.value = cityComponents[cityComponents.length - 1].long_name;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const countryComponents = place.address_components.filter(component => component.types.indexOf('country') != -1);
|
|
181
|
-
if (countryComponents && countryComponents[0]) {
|
|
182
|
-
this.country.value = countryComponents[countryComponents.length - 1].long_name;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const zipComponents = place.address_components.filter(component => component.types.indexOf('postal_code') != -1);
|
|
186
|
-
if (zipComponents && zipComponents[0]) {
|
|
187
|
-
this.zip.value = zipComponents[0].long_name;
|
|
188
|
-
}
|
|
189
|
-
this.change(null);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
static get observedAttributes() {
|
|
193
|
-
return ['language', 'google-places-key', 'enable-auto-complete'];
|
|
194
|
-
}
|
|
195
|
-
attributeChangedCallback(name: string, oldVal: string, newVal: string) {
|
|
196
|
-
this.attributeChanged(name, oldVal, newVal);
|
|
197
|
-
}
|
|
198
|
-
private attributeChanged(name: string, oldVal: string, newVal: string) {
|
|
199
|
-
switch (name) {
|
|
200
|
-
case 'language':
|
|
201
|
-
this.changeLanguage(newVal)
|
|
202
|
-
break;
|
|
203
|
-
case 'google-places-key':
|
|
204
|
-
this.googlePlacesApiKey = newVal;
|
|
205
|
-
this.enableAutoComplete()
|
|
206
|
-
break;
|
|
207
|
-
case 'enable-auto-complete':
|
|
208
|
-
if (newVal && newVal != 'false') {
|
|
209
|
-
this.autoCompleteEnabled = true;
|
|
210
|
-
this.enableAutoComplete()
|
|
211
|
-
}
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
1
|
+
import CustomElement from '../../framework/custom-element.decorator';
|
|
2
|
+
import { CustomInputElement } from '../../framework/CustomInputElement';
|
|
3
|
+
import { CustomElementEventArgs } from '../../framework/CustomEvents';
|
|
4
|
+
import Translator from '../../framework/Language/Translator';
|
|
5
|
+
import getAttributeNamesPolyfill from '../../framework/Polyfills/getAttributeNamesPolyfill';
|
|
6
|
+
import debouncer from "../../framework/Utilities/debouncer";
|
|
7
|
+
|
|
8
|
+
@CustomElement({
|
|
9
|
+
selector: 'address-element',
|
|
10
|
+
template: `
|
|
11
|
+
<div class="address-wrapper">
|
|
12
|
+
<input class='address-part' id='address' type="text" placeholder='Address'/>
|
|
13
|
+
<input class='address-part' id='zip' type="text" placeholder='Zip'/>
|
|
14
|
+
<input class='address-part' id='city' type="text" placeholder='City'/>
|
|
15
|
+
<input class='address-part' id='country' type="text" placeholder='Country'/>
|
|
16
|
+
</div>`,
|
|
17
|
+
style: `.address-wrapper{
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-wrap: nowrap;
|
|
20
|
+
}
|
|
21
|
+
input.address-part{
|
|
22
|
+
box-sizing: border-box;
|
|
23
|
+
border: none;
|
|
24
|
+
background-color: #f1f4ff;
|
|
25
|
+
margin: 2px;
|
|
26
|
+
resize: none;
|
|
27
|
+
width:33% !important;
|
|
28
|
+
}
|
|
29
|
+
`,
|
|
30
|
+
templatePath: './html.html',
|
|
31
|
+
useShadow: true,
|
|
32
|
+
})
|
|
33
|
+
export class AddressElement extends CustomInputElement {
|
|
34
|
+
private autoCompleteEnabled = false;
|
|
35
|
+
private addressAutoComplete: google.maps.places.Autocomplete;
|
|
36
|
+
private googlePlacesLibraryElement: HTMLScriptElement;
|
|
37
|
+
private googlePlacesApiKey: string;
|
|
38
|
+
|
|
39
|
+
address: HTMLInputElement;
|
|
40
|
+
city: HTMLInputElement;
|
|
41
|
+
country: HTMLInputElement;
|
|
42
|
+
zip: HTMLInputElement;
|
|
43
|
+
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
getAttributeNamesPolyfill();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get value(): string {
|
|
50
|
+
let address = this.address.value || '';
|
|
51
|
+
let city = this.city.value ? `,${this.city.value}` : '';
|
|
52
|
+
let zip = this.zip.value ? `,${this.zip.value}` : '';
|
|
53
|
+
let country = this.country.value ? `,${this.country.value}` : '';
|
|
54
|
+
return `${address}${city}${zip}${country}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
set value(value: string) {
|
|
58
|
+
const values = value.split(',');
|
|
59
|
+
this.address.value = values[0];
|
|
60
|
+
this.city.value = values[1];
|
|
61
|
+
this.country.value = values[2];
|
|
62
|
+
this.zip.value = values[3];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get valid(): boolean {
|
|
66
|
+
return (
|
|
67
|
+
this.address.validity.valid &&
|
|
68
|
+
this.city.validity.valid &&
|
|
69
|
+
this.country.validity.valid &&
|
|
70
|
+
this.zip.validity.valid
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
connectedCallback(): void {
|
|
75
|
+
super.connectedCallback();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
componentDidMount() {
|
|
79
|
+
this.initChildInputs();
|
|
80
|
+
this.getAttributeNames().forEach(attributeName => {
|
|
81
|
+
let attributeValue = this.getAttribute(attributeName);
|
|
82
|
+
this.attributeChanged(attributeName, null, attributeValue);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
initChildInputs() {
|
|
87
|
+
this.address = super.getChildInput('#address');
|
|
88
|
+
this.city = super.getChildInput('#city');
|
|
89
|
+
this.country = super.getChildInput('#country');
|
|
90
|
+
this.zip = super.getChildInput('#zip');
|
|
91
|
+
const addressChaneDebounce = debouncer(this.change.bind(this), 400, false);
|
|
92
|
+
this.address.addEventListener('change', () => {
|
|
93
|
+
addressChaneDebounce();
|
|
94
|
+
});
|
|
95
|
+
this.city.addEventListener('change', this.change.bind(this));
|
|
96
|
+
this.country.addEventListener('change', this.change.bind(this));
|
|
97
|
+
this.zip.addEventListener('change', this.change.bind(this));
|
|
98
|
+
|
|
99
|
+
if (this.required) {
|
|
100
|
+
this.address.setAttribute('required', '');
|
|
101
|
+
this.city.setAttribute('required', '');
|
|
102
|
+
this.country.setAttribute('required', '');
|
|
103
|
+
this.zip.setAttribute('required', '');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// events
|
|
108
|
+
public change($event): void {
|
|
109
|
+
this.touched = true;
|
|
110
|
+
this.onChange.emit(new CustomElementEventArgs(this.value, 'change'));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public validate(): void {
|
|
114
|
+
this.valid;
|
|
115
|
+
this.onValidate.emit(
|
|
116
|
+
new CustomElementEventArgs(this.value, 'validate'),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
changeLanguage(language: string) {
|
|
121
|
+
if (!this.address || !this.city || !this.country || !this.zip) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.address.placeholder = Translator.Translate('AddressElement.Address', language);
|
|
125
|
+
this.city.placeholder = Translator.Translate('AddressElement.City', language);
|
|
126
|
+
this.country.placeholder = Translator.Translate('AddressElement.Country', language);
|
|
127
|
+
this.zip.placeholder = Translator.Translate('AddressElement.Zip', language);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
enableAutoComplete() {
|
|
131
|
+
if (!this.googlePlacesApiKey || this.googlePlacesApiKey.trim() === '' || !this.autoCompleteEnabled) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.googlePlacesLibraryElement = document.querySelector<HTMLScriptElement>(`[src="https://maps.googleapis.com/maps/api/js?key=${this.googlePlacesApiKey}&libraries=places"]`);
|
|
136
|
+
if (this.googlePlacesLibraryElement) {
|
|
137
|
+
this.googlePlacesLibraryElementBindLoad();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this.googlePlacesLibraryElement = document.createElement('script');
|
|
141
|
+
this.googlePlacesLibraryElement.type = 'text/javascript';
|
|
142
|
+
this.googlePlacesLibraryElement.src = `https://maps.googleapis.com/maps/api/js?key=${this.googlePlacesApiKey}&libraries=places`;
|
|
143
|
+
window.document.head.appendChild(this.googlePlacesLibraryElement);
|
|
144
|
+
this.googlePlacesLibraryElementBindLoad();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private googlePlacesLibraryElementBindLoad() {
|
|
148
|
+
this.googlePlacesLibraryElement.addEventListener('load', () => {
|
|
149
|
+
this.bindAutoComplete();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
bindAutoComplete(): void {
|
|
154
|
+
this.addressAutoComplete = new google.maps.places.Autocomplete(this.address);
|
|
155
|
+
this.addressAutoComplete.addListener("place_changed", this.onAddressChangedHandler.bind(this));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
onAddressChangedHandler() {
|
|
159
|
+
this.city.value = '';
|
|
160
|
+
this.country.value = '';
|
|
161
|
+
this.zip.value = '';
|
|
162
|
+
|
|
163
|
+
const place = this.addressAutoComplete.getPlace();
|
|
164
|
+
console.log(place);
|
|
165
|
+
if (!place.address_components) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
this.address.value = place.name;
|
|
170
|
+
|
|
171
|
+
const cityComponents = place.address_components.filter(component => {
|
|
172
|
+
const citySynonyms = ['administrative_area_level_1', 'locality'];
|
|
173
|
+
const isCityComponent = citySynonyms.some(citySynonym => component.types.indexOf(citySynonym) != -1);
|
|
174
|
+
return isCityComponent;
|
|
175
|
+
});
|
|
176
|
+
if (cityComponents && cityComponents[0]) {
|
|
177
|
+
this.city.value = cityComponents[cityComponents.length - 1].long_name;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const countryComponents = place.address_components.filter(component => component.types.indexOf('country') != -1);
|
|
181
|
+
if (countryComponents && countryComponents[0]) {
|
|
182
|
+
this.country.value = countryComponents[countryComponents.length - 1].long_name;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const zipComponents = place.address_components.filter(component => component.types.indexOf('postal_code') != -1);
|
|
186
|
+
if (zipComponents && zipComponents[0]) {
|
|
187
|
+
this.zip.value = zipComponents[0].long_name;
|
|
188
|
+
}
|
|
189
|
+
this.change(null);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static get observedAttributes() {
|
|
193
|
+
return ['language', 'google-places-key', 'enable-auto-complete'];
|
|
194
|
+
}
|
|
195
|
+
attributeChangedCallback(name: string, oldVal: string, newVal: string) {
|
|
196
|
+
this.attributeChanged(name, oldVal, newVal);
|
|
197
|
+
}
|
|
198
|
+
private attributeChanged(name: string, oldVal: string, newVal: string) {
|
|
199
|
+
switch (name) {
|
|
200
|
+
case 'language':
|
|
201
|
+
this.changeLanguage(newVal)
|
|
202
|
+
break;
|
|
203
|
+
case 'google-places-key':
|
|
204
|
+
this.googlePlacesApiKey = newVal;
|
|
205
|
+
this.enableAutoComplete()
|
|
206
|
+
break;
|
|
207
|
+
case 'enable-auto-complete':
|
|
208
|
+
if (newVal && newVal != 'false') {
|
|
209
|
+
this.autoCompleteEnabled = true;
|
|
210
|
+
this.enableAutoComplete()
|
|
211
|
+
}
|
|
212
|
+
break;
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|