@salla.sa/twilight-components 1.0.49 → 1.0.51
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/dist/cjs/index.cjs.js +3 -2
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/salla-button.cjs.entry.js +116 -0
- package/dist/cjs/salla-localization-modal.cjs.entry.js +117 -0
- package/dist/cjs/{salla-search-a7147639.js → salla-login-modal-a2c7fa5d.js} +13 -87
- package/dist/cjs/salla-login-modal.cjs.entry.js +11 -0
- package/dist/cjs/salla-modal_2.cjs.entry.js +155 -0
- package/dist/cjs/{salla-offer.cjs.entry.js → salla-offer-modal.cjs.entry.js} +26 -26
- package/dist/cjs/{salla-rating.cjs.entry.js → salla-rating-modal.cjs.entry.js} +33 -33
- package/dist/cjs/salla-search-99d08b1f.js +79 -0
- package/dist/cjs/{salla-button_7.cjs.entry.js → salla-tel-input.cjs.entry.js} +0 -509
- package/dist/cjs/salla-verify-modal.cjs.entry.js +148 -0
- package/dist/cjs/twilight-components.cjs.js +1 -1
- package/dist/collection/collection-manifest.json +4 -4
- package/dist/collection/components/{salla-localization/salla-localization.css → salla-localization-modal/salla-localization-modal.css} +0 -0
- package/dist/collection/components/{salla-localization/salla-localization.js → salla-localization-modal/salla-localization-modal.js} +19 -19
- package/dist/collection/components/{salla-login/salla-login.css → salla-login-modal/salla-login-modal.css} +0 -0
- package/dist/collection/components/{salla-login/salla-login.js → salla-login-modal/salla-login-modal.js} +34 -34
- package/dist/collection/components/{salla-offer → salla-offer-modal}/offer-schema.js +0 -0
- package/dist/collection/components/{salla-offer/salla-offer.css → salla-offer-modal/salla-offer-modal.css} +4 -4
- package/dist/collection/components/{salla-offer/salla-offer.js → salla-offer-modal/salla-offer-modal.js} +34 -34
- package/dist/collection/components/{salla-rating → salla-rating-modal}/order-feedback-response.js +0 -0
- package/dist/collection/components/{salla-rating/salla-rating.css → salla-rating-modal/salla-rating-modal.css} +1 -1
- package/dist/collection/components/{salla-rating/salla-rating.js → salla-rating-modal/salla-rating-modal.js} +57 -57
- package/dist/collection/index.js +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/salla-button.entry.js +112 -0
- package/dist/esm/salla-localization-modal.entry.js +113 -0
- package/dist/esm/{salla-search-813732a1.js → salla-login-modal-187c1f98.js} +13 -86
- package/dist/esm/salla-login-modal.entry.js +3 -0
- package/dist/esm/salla-modal_2.entry.js +150 -0
- package/dist/esm/{salla-offer.entry.js → salla-offer-modal.entry.js} +26 -26
- package/dist/esm/{salla-rating.entry.js → salla-rating-modal.entry.js} +33 -33
- package/dist/esm/salla-search-2e3e60cb.js +77 -0
- package/dist/esm/{salla-button_7.entry.js → salla-tel-input.entry.js} +2 -505
- package/dist/esm/salla-verify-modal.entry.js +144 -0
- package/dist/esm/twilight-components.js +1 -1
- package/dist/twilight-components/index.esm.js +1 -1
- package/dist/twilight-components/p-05dff05e.entry.js +1 -0
- package/dist/twilight-components/p-0b599094.js +1 -0
- package/dist/twilight-components/p-1f873057.entry.js +1 -0
- package/dist/twilight-components/p-2e03db57.entry.js +1 -0
- package/dist/twilight-components/p-5ffd56fb.js +1 -0
- package/dist/twilight-components/p-85427280.entry.js +1 -0
- package/dist/twilight-components/p-88d1bb89.entry.js +1 -0
- package/dist/twilight-components/p-8bfa19fb.entry.js +1 -0
- package/dist/twilight-components/p-ea455ae9.entry.js +1 -0
- package/dist/twilight-components/p-f0f51a3c.entry.js +1 -0
- package/dist/twilight-components/twilight-components.esm.js +1 -1
- package/dist/types/components/{salla-localization/salla-localization.d.ts → salla-localization-modal/salla-localization-modal.d.ts} +1 -1
- package/dist/types/components/{salla-login/salla-login.d.ts → salla-login-modal/salla-login-modal.d.ts} +1 -1
- package/dist/types/components/{salla-offer → salla-offer-modal}/offer-schema.d.ts +0 -0
- package/dist/types/components/{salla-offer/salla-offer.d.ts → salla-offer-modal/salla-offer-modal.d.ts} +1 -1
- package/dist/types/components/{salla-rating → salla-rating-modal}/order-feedback-response.d.ts +0 -0
- package/dist/types/components/{salla-rating/salla-rating.d.ts → salla-rating-modal/salla-rating-modal.d.ts} +1 -1
- package/dist/types/components.d.ts +36 -36
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/twilight-components/p-152b7287.entry.js +0 -1
- package/dist/twilight-components/p-4b774cf9.entry.js +0 -1
- package/dist/twilight-components/p-b584e892.entry.js +0 -1
- package/dist/twilight-components/p-b8ed7363.js +0 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { r as registerInstance, h, g as getElement } from './index-8b97d225.js';
|
|
2
|
+
import { H as Helper } from './Helper-7162a06c.js';
|
|
3
|
+
|
|
4
|
+
const sallaSearchCss = "#s-search-modal .s-modal-wrapper{align-items:flex-start;padding:0}#s-search-modal .s-modal-spacer{display:inline}#s-search-modal .s-modal-body{padding:0;max-width:90%;margin-top:3.2rem;border-radius:0.5rem}#s-search-modal .s-modal-close{top:50%;transform:translateY(-50%)}";
|
|
5
|
+
|
|
6
|
+
const SallaSearch = class {
|
|
7
|
+
constructor(hostRef) {
|
|
8
|
+
registerInstance(this, hostRef);
|
|
9
|
+
var _a;
|
|
10
|
+
Helper.setHost(this.host);
|
|
11
|
+
this.productSlot = ((_a = Helper.getElement('[slot="product"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || this.getDefaultProductSlot();
|
|
12
|
+
salla.event.on('search::show', () => this.modal.show());
|
|
13
|
+
salla.event.on('languages::translations.loaded', () => {
|
|
14
|
+
this.placeholder = salla.lang.get('blocks.header.search_placeholder');
|
|
15
|
+
this.noResultsText = salla.lang.get('common.elements.no_options');
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
onModalOpen() {
|
|
19
|
+
this.modal.querySelector('.s-search-input').focus();
|
|
20
|
+
}
|
|
21
|
+
onModalClose() {
|
|
22
|
+
this.modal.querySelector('.s-search-input').value = '';
|
|
23
|
+
this.results = undefined;
|
|
24
|
+
this.afterSearching();
|
|
25
|
+
}
|
|
26
|
+
getDefaultProductSlot() {
|
|
27
|
+
return '<div class="s-search-product-image-container">' +
|
|
28
|
+
' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
|
|
29
|
+
'</div>' +
|
|
30
|
+
'<div class="s-search-product-details">' +
|
|
31
|
+
' <div class="s-search-product-title">{name}</div> <div class="s-search-product-price">{price}</div>' +
|
|
32
|
+
'</div>';
|
|
33
|
+
}
|
|
34
|
+
//todo:: reset data when closing
|
|
35
|
+
search(e) {
|
|
36
|
+
Helper.hideElement(this.noResults);
|
|
37
|
+
if (e.target.value.length === 0) {
|
|
38
|
+
this.results = undefined;
|
|
39
|
+
this.afterSearching();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (e.target.value.length <= 2) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
//run loading spinner or stop it
|
|
46
|
+
Helper.toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => true);
|
|
47
|
+
salla.search.api.search(e.target.value)
|
|
48
|
+
.then(response => this.results = response)
|
|
49
|
+
.catch(err => err !== 'Query Same As Previous!' ? this.results = undefined : null)
|
|
50
|
+
.finally(() => this.afterSearching(/*isEmpty*/ false));
|
|
51
|
+
}
|
|
52
|
+
afterSearching(isEmpty = true) {
|
|
53
|
+
var _a;
|
|
54
|
+
this.noResults.style.display = isEmpty || ((_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length) > 0 ? 'none' : 'block';
|
|
55
|
+
Helper.toggleElement(this.container, 's-search-container-open', 'no-results', () => { var _a; return (_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length; })
|
|
56
|
+
.toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => false); //stop searching anime
|
|
57
|
+
salla.search.api.previousQuery = ''; //avoid having error 'Query Same As Previous' after reopen modal;
|
|
58
|
+
}
|
|
59
|
+
render() {
|
|
60
|
+
var _a;
|
|
61
|
+
return (h("salla-modal", { position: "top", id: "s-search-modal", ref: modal => this.modal = modal }, h("div", { class: "s-search-container", ref: container => this.container = container }, h("input", { class: "s-search-input", type: "text", placeholder: this.placeholder, onInput: e => this.search(e) }), h("span", { class: "s-search-icon" }, h("i", { class: "sicon-search", ref: el => this.searchIcon = el })), h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
|
|
62
|
+
_a.data.map(item => h("a", { href: item.url, class: "s-search-product", innerHTML: this.productSlot
|
|
63
|
+
.replace(/\{name\}/g, item.name)
|
|
64
|
+
.replace(/\{price\}/g, item.price) //todo:: get discounted price too
|
|
65
|
+
.replace(/\{image\}/g, item.image_url) })), h("p", { ref: el => this.noResults = el, class: "s-search-no-results" }, this.noResultsText)))));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run it one time after load
|
|
69
|
+
*/
|
|
70
|
+
componentDidLoad() {
|
|
71
|
+
this.afterSearching();
|
|
72
|
+
}
|
|
73
|
+
get host() { return getElement(this); }
|
|
74
|
+
};
|
|
75
|
+
SallaSearch.style = sallaSearchCss;
|
|
76
|
+
|
|
77
|
+
export { SallaSearch as S };
|
|
@@ -1,368 +1,5 @@
|
|
|
1
|
-
import { r as registerInstance, h, H as Host, g as getElement
|
|
1
|
+
import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-8b97d225.js';
|
|
2
2
|
import { H as Helper } from './Helper-7162a06c.js';
|
|
3
|
-
export { S as salla_login, a as salla_search } from './salla-search-813732a1.js';
|
|
4
|
-
|
|
5
|
-
const sallaButtonCss = "";
|
|
6
|
-
|
|
7
|
-
const SallaButton = class {
|
|
8
|
-
constructor(hostRef) {
|
|
9
|
-
registerInstance(this, hostRef);
|
|
10
|
-
/**
|
|
11
|
-
* Button Style
|
|
12
|
-
*/
|
|
13
|
-
this.btnStyle = 'primary';
|
|
14
|
-
/**
|
|
15
|
-
* Is the button currently loading
|
|
16
|
-
*/
|
|
17
|
-
this.loading = false;
|
|
18
|
-
/**
|
|
19
|
-
* Is the button currently disabled
|
|
20
|
-
*/
|
|
21
|
-
this.disabled = false;
|
|
22
|
-
/**
|
|
23
|
-
* If there is need to change loader position, pass the position
|
|
24
|
-
*/
|
|
25
|
-
this.loaderPosition = 'after';
|
|
26
|
-
/**
|
|
27
|
-
* Is the button wide
|
|
28
|
-
*/
|
|
29
|
-
this.wide = false;
|
|
30
|
-
this.hostAttributes = {};
|
|
31
|
-
for (let i = 0; i < this.host.attributes.length; i++) {
|
|
32
|
-
this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
|
|
33
|
-
}
|
|
34
|
-
this.hostAttributes.type = this.hostAttributes.type || 'button';
|
|
35
|
-
this.hostAttributes.class += ' s-button-btn btn--has-loading'
|
|
36
|
-
+ ' s-button-' + this.btnStyle
|
|
37
|
-
+ (this.wide ? ' s-button-wide ' : '')
|
|
38
|
-
+ ' s-button-btn-loader-' + this.loaderPosition //todo:: it looks there is no need for this class🤔
|
|
39
|
-
+ (this.loaderPosition == 'after' ? ' s-button-loader-after' : '');
|
|
40
|
-
delete this.hostAttributes['btn-style'];
|
|
41
|
-
delete this.hostAttributes['id'];
|
|
42
|
-
delete this.hostAttributes['data-on-click'];
|
|
43
|
-
if (this.wide) {
|
|
44
|
-
this.host.classList.add('s-button-wide');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Run loading animation
|
|
49
|
-
*/
|
|
50
|
-
async load() {
|
|
51
|
-
if (this.loaderPosition == 'center')
|
|
52
|
-
this.text.classList.add('s-button-hide');
|
|
53
|
-
this.host.setAttribute('loading', '');
|
|
54
|
-
return this.host;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Stop loading animation
|
|
58
|
-
*/
|
|
59
|
-
async stop() {
|
|
60
|
-
this.host.removeAttribute('loading');
|
|
61
|
-
if (this.loaderPosition == 'center')
|
|
62
|
-
this.text.classList.remove('s-button-hide');
|
|
63
|
-
return this.host;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Changing the body of the button
|
|
67
|
-
* @param html
|
|
68
|
-
*/
|
|
69
|
-
async setText(html) {
|
|
70
|
-
this.text.innerHTML = html;
|
|
71
|
-
return this.host;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Add `disabled` attribute
|
|
75
|
-
*/
|
|
76
|
-
async disable() {
|
|
77
|
-
this.host.setAttribute('disabled', '');
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Remove `disabled` attribute
|
|
81
|
-
*/
|
|
82
|
-
async enable() {
|
|
83
|
-
this.host.removeAttribute('disabled');
|
|
84
|
-
}
|
|
85
|
-
handleVisible(newKind, oldKind) {
|
|
86
|
-
//todo::use united styles
|
|
87
|
-
this.btn.classList.remove('btn-' + oldKind);
|
|
88
|
-
this.btn.classList.add('btn-' + newKind);
|
|
89
|
-
}
|
|
90
|
-
handleLoading(newVal) {
|
|
91
|
-
//todo::use united styles
|
|
92
|
-
Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
|
|
93
|
-
}
|
|
94
|
-
render() {
|
|
95
|
-
return (
|
|
96
|
-
//TODO:: use HOST then fake button behaviours
|
|
97
|
-
h(Host, { class: "s-button-wrap" }, h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes), h("span", { class: { 's-button-text': true, 's-button-hide': this.loaderPosition == 'center' && this.loading }, ref: el => this.text = el }, h("slot", null)), this.loading ? h("span", { class: {
|
|
98
|
-
//todo::use united styles
|
|
99
|
-
's-button-loader': true,
|
|
100
|
-
's-button-loader-start': this.loaderPosition === 'start',
|
|
101
|
-
's-button-loader-end': this.loaderPosition === 'end',
|
|
102
|
-
's-button-loader-center': this.loaderPosition === 'center',
|
|
103
|
-
} }) : '')));
|
|
104
|
-
}
|
|
105
|
-
get host() { return getElement(this); }
|
|
106
|
-
static get watchers() { return {
|
|
107
|
-
"btnStyle": ["handleVisible"],
|
|
108
|
-
"loading": ["handleLoading"]
|
|
109
|
-
}; }
|
|
110
|
-
};
|
|
111
|
-
SallaButton.style = sallaButtonCss;
|
|
112
|
-
|
|
113
|
-
const sallaLocalizationCss = "";
|
|
114
|
-
|
|
115
|
-
const SallaLocalization = class {
|
|
116
|
-
constructor(hostRef) {
|
|
117
|
-
registerInstance(this, hostRef);
|
|
118
|
-
var _a, _b;
|
|
119
|
-
this.languages = [];
|
|
120
|
-
this.currencies = [];
|
|
121
|
-
this.isLoading = true;
|
|
122
|
-
this.language = salla.config.get('user.language_code');
|
|
123
|
-
this.currency = salla.config.get('user.currency_code');
|
|
124
|
-
Helper.setHost(this.host);
|
|
125
|
-
salla.event.on('localization::show', () => this.show());
|
|
126
|
-
salla.event.on('languages::translations.loaded', () => {
|
|
127
|
-
var _a;
|
|
128
|
-
this.languagesTitle = salla.lang.get('common.titles.language');
|
|
129
|
-
this.currenciesTitle = salla.lang.get('common.titles.currency');
|
|
130
|
-
(_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(salla.lang.get('common.elements.ok'));
|
|
131
|
-
});
|
|
132
|
-
/**
|
|
133
|
-
* letting developer to insert his own slot like:
|
|
134
|
-
* <salla-localization>
|
|
135
|
-
* <div slot="language">...{name}....</div>
|
|
136
|
-
* <div slot="currency">...{name}....</div>
|
|
137
|
-
* </salla-localization>
|
|
138
|
-
* Because scoped templates not supported in stencil );
|
|
139
|
-
* we made a workaround to pass language & currency attributes, then replace names in rendering
|
|
140
|
-
*/
|
|
141
|
-
this.languageSlot = ((_a = Helper.getElement('[slot="language"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<label class="s-localization-label" for="lang-{code}"><span>{name}</span><div class="s-localization-flag flag iti__flag iti__{country_code}"></div></label>';
|
|
142
|
-
this.currencySlot = ((_b = Helper.getElement('[slot="currency"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || '<label class="s-localization-label" for="currency-{code}"><span>{name}</span><small class="s-localization-currency">{code}</small></label>';
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Show the component
|
|
146
|
-
*/
|
|
147
|
-
async show() {
|
|
148
|
-
return this.modal.show()
|
|
149
|
-
.then(() => this.getLanguages())
|
|
150
|
-
.then(() => this.getCurrencies())
|
|
151
|
-
.then(() => this.isLoading = false);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Hide the component
|
|
155
|
-
*/
|
|
156
|
-
async hide() {
|
|
157
|
-
return this.modal.hide();
|
|
158
|
-
}
|
|
159
|
-
async getLanguages() {
|
|
160
|
-
this.language = this.language || salla.config.get('user.language_code');
|
|
161
|
-
return this.languages.length > 1 ? null : await salla.config.languages().then(data => this.languages = data);
|
|
162
|
-
}
|
|
163
|
-
async getCurrencies() {
|
|
164
|
-
this.currency = this.currency || salla.config.get('user.currency_code');
|
|
165
|
-
return this.currencies.length > 1 ? null : await salla.config.currencies().then(data => this.currencies = data);
|
|
166
|
-
}
|
|
167
|
-
onChangeCurrency(event) {
|
|
168
|
-
this.currency = event.target.value;
|
|
169
|
-
}
|
|
170
|
-
onChangeLanguage(event) {
|
|
171
|
-
this.language = event.target.value;
|
|
172
|
-
}
|
|
173
|
-
async submit() {
|
|
174
|
-
let url;
|
|
175
|
-
this.btn.load()
|
|
176
|
-
.then(() => {
|
|
177
|
-
if (!this.currency) {
|
|
178
|
-
salla.log('There is no currency!');
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (this.currency === salla.config.get('user.currency_code', 'SAR')) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
url = window.location.href;
|
|
185
|
-
return salla.currency.api.change(this.currency);
|
|
186
|
-
})
|
|
187
|
-
.then(() => this.language === salla.config.get('user.language_code', 'ar') || (url = salla.helpers.addParamToUrl('lang', this.language)))
|
|
188
|
-
.then(() => this.btn.stop())
|
|
189
|
-
.then(() => this.hide())
|
|
190
|
-
.then(() => url && (window.location.href = url));
|
|
191
|
-
}
|
|
192
|
-
render() {
|
|
193
|
-
return (h("salla-modal", { isLoading: this.isLoading, id: "salla-localization", class: "s-hidden", ref: modal => this.modal = modal, width: "xs" }, !this.isLoading ?
|
|
194
|
-
h("div", { class: "s-localization-inner" }, this.languages.length > 1 ?
|
|
195
|
-
h("div", { class: "s-localization-section" }, h("label", { class: "s-localization-title" }, this.languagesTitle), h("div", { class: "s-localization-section-inner" }, this.languages.length < 6 ?
|
|
196
|
-
this.languages.map(lang => h("div", { class: "s-localization-item" }, h("input", { class: "s-localization-input", type: "radio", checked: this.language == lang.iso_code, onChange: () => this.language = lang.iso_code, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }), h("div", { id: "language-slot", innerHTML: this.languageSlot
|
|
197
|
-
.replace(/\{name\}/g, lang.name)
|
|
198
|
-
.replace(/\{code\}/g, lang.code)
|
|
199
|
-
.replace(/\{country_code\}/g, lang.country_code) }))) :
|
|
200
|
-
h("select", { class: "s-localization-select", name: "currency", onChange: e => this.onChangeLanguage(e) }, this.languages.map(lang => h("option", { value: lang.code, selected: this.language == lang.code }, lang.name)))))
|
|
201
|
-
: '', this.currencies.length > 1 ?
|
|
202
|
-
h("div", { class: "s-localization-section" }, h("label", { class: "s-localization-title" }, this.currenciesTitle), h("div", { class: "s-localization-section-inner" }, this.currencies.length < 6 ?
|
|
203
|
-
this.currencies.map(currency => h("div", { class: "s-localization-item" }, h("input", { class: "s-localization-input", type: "radio", name: "currency", checked: this.currency == currency.code, onChange: () => this.currency = currency.code, id: 'currency-' + currency.code, value: currency.code }), h("div", { id: "currency-slot", innerHTML: this.currencySlot
|
|
204
|
-
.replace(/\{name\}/g, currency.name)
|
|
205
|
-
.replace(/\{code\}/g, currency.code)
|
|
206
|
-
.replace(/\{country_code\}/g, currency.country_code) }))) :
|
|
207
|
-
h("select", { class: "s-localization-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, this.currencies.map(currency => h("option", { value: currency.code, selected: this.currency == currency.code }, currency.name)))))
|
|
208
|
-
: '', h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.ok')))
|
|
209
|
-
: ''));
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* to reduce dom levels we will move slot data into the parent dom
|
|
213
|
-
*/
|
|
214
|
-
componentDidRender() {
|
|
215
|
-
this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
|
|
216
|
-
this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
|
|
217
|
-
}
|
|
218
|
-
get host() { return getElement(this); }
|
|
219
|
-
};
|
|
220
|
-
SallaLocalization.style = sallaLocalizationCss;
|
|
221
|
-
|
|
222
|
-
const sallaModalCss = "";
|
|
223
|
-
|
|
224
|
-
const SallaModal = class {
|
|
225
|
-
constructor(hostRef) {
|
|
226
|
-
registerInstance(this, hostRef);
|
|
227
|
-
this.modalOpened = createEvent(this, "modalOpened", 7);
|
|
228
|
-
this.modalClosed = createEvent(this, "modalClosed", 7);
|
|
229
|
-
this.isClosable = true; //todo::rename unclude
|
|
230
|
-
/**
|
|
231
|
-
* The size of the modal
|
|
232
|
-
*/
|
|
233
|
-
this.width = 'md';
|
|
234
|
-
/**
|
|
235
|
-
* The position of the modal
|
|
236
|
-
*/
|
|
237
|
-
this.position = 'middle';
|
|
238
|
-
/**
|
|
239
|
-
* Show the modal on rendering
|
|
240
|
-
*/
|
|
241
|
-
this.visible = false;
|
|
242
|
-
/**
|
|
243
|
-
* Show loading in the middle
|
|
244
|
-
*/
|
|
245
|
-
this.isLoading = false;
|
|
246
|
-
this.subTitleFirst = false; //todo:: choose better name
|
|
247
|
-
this.noPadding = false; //todo:: choose better name
|
|
248
|
-
this.subTitle = '';
|
|
249
|
-
/**
|
|
250
|
-
* Icon css class, default for types `error` is `sicon-alert-engine`, `success` is `sicon-check-circle2`
|
|
251
|
-
*/
|
|
252
|
-
this.icon = '';
|
|
253
|
-
this.iconStyle = '';
|
|
254
|
-
/**
|
|
255
|
-
* url of an image
|
|
256
|
-
*/
|
|
257
|
-
this.imageIcon = '';
|
|
258
|
-
Helper.setHost(this.host);
|
|
259
|
-
salla.event.on('modal::open', btn => btn.dataset.target == this.host.id && this.show());
|
|
260
|
-
salla.event.on('modal::close', btn => btn.dataset.target == this.host.id && this.hide());
|
|
261
|
-
this.title = this.host.title;
|
|
262
|
-
this.host.removeAttribute('title');
|
|
263
|
-
}
|
|
264
|
-
handleVisible(newValue) {
|
|
265
|
-
if (!newValue) {
|
|
266
|
-
this.toggleModal(false);
|
|
267
|
-
this.modalClosed.emit();
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
this.host.classList.remove('s-hidden');
|
|
271
|
-
setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
|
|
272
|
-
this.modalOpened.emit();
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Show the modal
|
|
276
|
-
*/
|
|
277
|
-
async show() {
|
|
278
|
-
this.host.setAttribute('visible', '');
|
|
279
|
-
return this.host;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* hide the modal
|
|
283
|
-
*/
|
|
284
|
-
async hide() {
|
|
285
|
-
this.host.removeAttribute('visible');
|
|
286
|
-
return this.host;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Change the title
|
|
290
|
-
* @param {string} title
|
|
291
|
-
*/
|
|
292
|
-
async setTitle(title) {
|
|
293
|
-
this.title = title;
|
|
294
|
-
return this.host;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Start loading
|
|
298
|
-
*/
|
|
299
|
-
async loading() {
|
|
300
|
-
this.isLoading = true;
|
|
301
|
-
return this.host;
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Stop the loading
|
|
305
|
-
*/
|
|
306
|
-
async stopLoading() {
|
|
307
|
-
this.isLoading = false;
|
|
308
|
-
return this.host;
|
|
309
|
-
}
|
|
310
|
-
toggleModal(isOpen) {
|
|
311
|
-
const body = this.host.querySelector('.s-modal-body');
|
|
312
|
-
Helper.toggleElement(body, 's-modal-entering', 's-modal-leaving', () => isOpen)
|
|
313
|
-
.toggleElement(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
|
|
314
|
-
//todo:: use united class names
|
|
315
|
-
.toggleElement(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
|
|
316
|
-
if (!isOpen) {
|
|
317
|
-
setTimeout(() => this.host.classList.add('s-hidden'), 350);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
closeModal() {
|
|
321
|
-
if (!this.isClosable) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
this.host.removeAttribute('visible');
|
|
325
|
-
}
|
|
326
|
-
iconBlockClasses() {
|
|
327
|
-
return {
|
|
328
|
-
's-modal-icon': true,
|
|
329
|
-
's-modal-bg-error': this.iconStyle == 'error',
|
|
330
|
-
's-modal-bg-success': this.iconStyle == 'success',
|
|
331
|
-
's-modal-bg-normal': this.iconStyle != 'error' && this.iconStyle != 'success',
|
|
332
|
-
's-modal-bg-primary': this.iconStyle == 'primary'
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
iconClasses() {
|
|
336
|
-
return {
|
|
337
|
-
[this.icon]: true,
|
|
338
|
-
'sicon-alert-engine': !this.icon && this.iconStyle == 'error' && !this.imageIcon,
|
|
339
|
-
'sicon-check-circle2': !this.icon && this.iconStyle == 'success' && !this.imageIcon,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
//todo:: pref for each modal
|
|
343
|
-
render() {
|
|
344
|
-
this.host.id = this.host.id || 'salla-modal';
|
|
345
|
-
return (h(Host, { class: 'salla-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), h("div", { class: "s-modal-wrapper" }, h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.width + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, this.isLoading ?
|
|
346
|
-
h("div", { class: "s-modal-loader-wrap" }, h("span", { class: "s-modal-loader" }))
|
|
347
|
-
:
|
|
348
|
-
[
|
|
349
|
-
h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.icon != '' || this.imageIcon != '' } }, this.isClosable ?
|
|
350
|
-
h("button", { class: "s-modal-close", onClick: () => this.closeModal(), type: "button" }, h("span", { class: "sicon-cancel" }))
|
|
351
|
-
: '', this.title || this.subTitle ?
|
|
352
|
-
h("div", { class: "s-modal-header-inner" }, this.iconStyle || this.icon
|
|
353
|
-
? h("div", { class: this.iconBlockClasses() }, h("i", { class: this.iconClasses() }))
|
|
354
|
-
: this.imageIcon ? h("img", { class: "s-modal-header-img", src: this.imageIcon }) : '', h("div", { class: "s-modal-header-content" }, h("div", { class: { 's-modal-title': true, 's-modal-title-below': this.subTitleFirst }, innerHTML: this.title }), h("p", { class: { 's-modal-sub-title': true }, innerHTML: this.subTitle })))
|
|
355
|
-
: ''),
|
|
356
|
-
h("slot", null),
|
|
357
|
-
h("slot", { name: "footer" })
|
|
358
|
-
]))));
|
|
359
|
-
}
|
|
360
|
-
get host() { return getElement(this); }
|
|
361
|
-
static get watchers() { return {
|
|
362
|
-
"visible": ["handleVisible"]
|
|
363
|
-
}; }
|
|
364
|
-
};
|
|
365
|
-
SallaModal.style = sallaModalCss;
|
|
366
3
|
|
|
367
4
|
function createCommonjsModule(fn, basedir, module) {
|
|
368
5
|
return module = {
|
|
@@ -1836,144 +1473,4 @@ const SallaTelInput = class {
|
|
|
1836
1473
|
};
|
|
1837
1474
|
SallaTelInput.style = sallaTelInputCss;
|
|
1838
1475
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
const SallaVerifyModal = class {
|
|
1842
|
-
constructor(hostRef) {
|
|
1843
|
-
registerInstance(this, hostRef);
|
|
1844
|
-
this.verified = createEvent(this, "verified", 7);
|
|
1845
|
-
this.initiated = false;
|
|
1846
|
-
/**
|
|
1847
|
-
* Verifying method
|
|
1848
|
-
*/
|
|
1849
|
-
this.by = 'sms';
|
|
1850
|
-
/**
|
|
1851
|
-
* should auto reloading the page after success verification
|
|
1852
|
-
*/
|
|
1853
|
-
this.autoReload = true;
|
|
1854
|
-
Helper.setHost(this.host);
|
|
1855
|
-
if (this.withoutModal) {
|
|
1856
|
-
this.modal = { show: () => '', hide: () => '' };
|
|
1857
|
-
}
|
|
1858
|
-
else {
|
|
1859
|
-
salla.event.on('profile::verify.mobile', data => {
|
|
1860
|
-
this.url = 'profile/verify-mobile';
|
|
1861
|
-
this.show(data);
|
|
1862
|
-
});
|
|
1863
|
-
}
|
|
1864
|
-
salla.event.on('languages::translations.loaded', () => {
|
|
1865
|
-
var _a;
|
|
1866
|
-
this.title = salla.lang.get('pages.profile.verify_title');
|
|
1867
|
-
(_a = this.btn) === null || _a === void 0 ? void 0 : _a.setText(salla.lang.get('pages.profile.verify'));
|
|
1868
|
-
});
|
|
1869
|
-
}
|
|
1870
|
-
/**
|
|
1871
|
-
* Get current code
|
|
1872
|
-
* @return {string}
|
|
1873
|
-
*/
|
|
1874
|
-
async getCode() {
|
|
1875
|
-
return this.code.value;
|
|
1876
|
-
}
|
|
1877
|
-
/**
|
|
1878
|
-
* Show verifying modal
|
|
1879
|
-
* @param data
|
|
1880
|
-
*/
|
|
1881
|
-
async show(data) {
|
|
1882
|
-
var _a;
|
|
1883
|
-
this.data = data;
|
|
1884
|
-
this.resendTimer();
|
|
1885
|
-
this.otpInputs = this.host.querySelectorAll('.s-verify-modal-input');
|
|
1886
|
-
if (!this.initiated) {
|
|
1887
|
-
Helper.on('input', '.s-verify-modal-input', e => salla.helpers.digitsOnly(e.target));
|
|
1888
|
-
Helper.onKeyUp('.s-verify-modal-input', event => {
|
|
1889
|
-
var _a, _b, _c, _d;
|
|
1890
|
-
let key = event.keyCode || event.charCode;
|
|
1891
|
-
if (event.target.value) {
|
|
1892
|
-
(_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
|
|
1893
|
-
(_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
|
|
1894
|
-
}
|
|
1895
|
-
else if ([8, 46].includes(key)) {
|
|
1896
|
-
(_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
|
|
1897
|
-
(_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
|
|
1898
|
-
}
|
|
1899
|
-
this.toggleOTPSubmit();
|
|
1900
|
-
});
|
|
1901
|
-
Helper.on('paste', '.s-verify-modal-input', event => {
|
|
1902
|
-
let text = event.clipboardData.getData('text').toArabicDigits().replace(/[^0-9.]/g, '').replace('..', '.');
|
|
1903
|
-
this.otpInputs.forEach((input, i) => input.value = text[i] || '');
|
|
1904
|
-
this.toggleOTPSubmit();
|
|
1905
|
-
setTimeout(() => this.otpInputs[3].focus(), 100);
|
|
1906
|
-
});
|
|
1907
|
-
// return this.modal.show();
|
|
1908
|
-
this.initiated = true;
|
|
1909
|
-
}
|
|
1910
|
-
this.reset();
|
|
1911
|
-
!this.withoutModal && ((_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title));
|
|
1912
|
-
this.modal.show();
|
|
1913
|
-
}
|
|
1914
|
-
toggleOTPSubmit() {
|
|
1915
|
-
let otp = [];
|
|
1916
|
-
this.otpInputs.forEach(input => input.value && otp.push(input.value));
|
|
1917
|
-
this.code.value = otp.join('');
|
|
1918
|
-
if (otp.length === 4) {
|
|
1919
|
-
this.btn.removeAttribute('disabled');
|
|
1920
|
-
this.btn.click();
|
|
1921
|
-
return;
|
|
1922
|
-
}
|
|
1923
|
-
this.btn.setAttribute('disabled', '');
|
|
1924
|
-
}
|
|
1925
|
-
reset() {
|
|
1926
|
-
this.otpInputs.forEach((input) => input.value = '');
|
|
1927
|
-
this.code.value = '';
|
|
1928
|
-
this.otpInputs[0].focus();
|
|
1929
|
-
}
|
|
1930
|
-
resendTimer() {
|
|
1931
|
-
Helper.showElement(this.resendMessage).hideElement(this.resend);
|
|
1932
|
-
let resendAfter = 30;
|
|
1933
|
-
let timerId = setInterval(() => {
|
|
1934
|
-
if (resendAfter === -1) {
|
|
1935
|
-
clearTimeout(timerId);
|
|
1936
|
-
Helper.hideElement(this.resendMessage).showElement(this.resend);
|
|
1937
|
-
}
|
|
1938
|
-
else {
|
|
1939
|
-
this.timer.innerHTML = `${resendAfter >= 10 ? resendAfter : '0' + resendAfter} : 00`;
|
|
1940
|
-
resendAfter--;
|
|
1941
|
-
}
|
|
1942
|
-
}, 1000);
|
|
1943
|
-
}
|
|
1944
|
-
resendCode() {
|
|
1945
|
-
return this.btn.stop()
|
|
1946
|
-
.then(() => this.btn.disable())
|
|
1947
|
-
.then(() => {
|
|
1948
|
-
this.otpInputs.forEach(input => input.value = '');
|
|
1949
|
-
this.otpInputs[0].focus();
|
|
1950
|
-
})
|
|
1951
|
-
.then(() => salla.api.auth.resend(Object.assign({ resend_by: this.by }, this.data)))
|
|
1952
|
-
.then(() => this.resendTimer())
|
|
1953
|
-
.catch(() => this.resendTimer());
|
|
1954
|
-
}
|
|
1955
|
-
submit() {
|
|
1956
|
-
let data = Object.assign({ code: this.code.value }, this.data);
|
|
1957
|
-
return this.btn.load()
|
|
1958
|
-
.then(() => this.btn.disable())
|
|
1959
|
-
.then(() => this.url
|
|
1960
|
-
? salla.api.auth.request(this.url, data)
|
|
1961
|
-
: salla.api.auth.verify(this.by == 'sms' ? 'mobile' : this.by, data))
|
|
1962
|
-
.then(response => this.verified.emit(response))
|
|
1963
|
-
.then(() => this.btn.stop() && this.btn.disable())
|
|
1964
|
-
.then(() => this.modal.hide())
|
|
1965
|
-
.then(() => this.autoReload && window.location.reload())
|
|
1966
|
-
.catch(() => this.btn.stop() && this.btn.enable() && this.reset());
|
|
1967
|
-
}
|
|
1968
|
-
render() {
|
|
1969
|
-
return this.withoutModal ? this.myBody() :
|
|
1970
|
-
h("salla-modal", { icon: "sicon-android-phone", width: "xs", id: "s-verify-modal", ref: modal => this.modal = modal, title: this.title }, this.myBody());
|
|
1971
|
-
}
|
|
1972
|
-
myBody() {
|
|
1973
|
-
return (h(Host, { id: "s-verify-modal" }, h("div", { class: "s-verify-modal-message", innerHTML: salla.lang.get('pages.profile.verify_message') }), h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }), h("div", { class: "s-verify-modal-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => h("input", { type: "text", maxlength: "1", class: "s-verify-modal-input", required: true }))), h("div", { slot: "footer", class: "s-verify-modal-footer" }, h("salla-button", { class: "s-verify-modal-submit", "loader-position": 'center', disabled: true, onClick: () => this.submit(), ref: b => this.btn = b }, salla.lang.get('pages.profile.verify')), h("p", { class: "s-verify-modal-resend-message", ref: el => this.resendMessage = el }, salla.lang.get('blocks.header.resend_after'), h("b", { class: "s-verify-modal-timer", ref: el => this.timer = el })), h("a", { href: "#", class: "s-verify-modal-resend", onClick: () => this.resendCode(), ref: el => this.resend = el }, salla.lang.get('blocks.comments.submit'))), h("slot", { name: "after-footer" })));
|
|
1974
|
-
}
|
|
1975
|
-
get host() { return getElement(this); }
|
|
1976
|
-
};
|
|
1977
|
-
SallaVerifyModal.style = sallaVerifyModalCss;
|
|
1978
|
-
|
|
1979
|
-
export { SallaButton as salla_button, SallaLocalization as salla_localization, SallaModal as salla_modal, SallaTelInput as salla_tel_input, SallaVerifyModal as salla_verify_modal };
|
|
1476
|
+
export { SallaTelInput as salla_tel_input };
|