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