@salla.sa/twilight-components 1.0.21 → 1.0.22

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 (95) hide show
  1. package/dist/cjs/Helper-fcea994c.js +23 -0
  2. package/dist/cjs/index-714023c8.js +1653 -0
  3. package/dist/cjs/index.cjs.js +13 -0
  4. package/dist/cjs/loader.cjs.js +21 -0
  5. package/dist/cjs/salla-branches.cjs.entry.js +92 -0
  6. package/dist/cjs/salla-button_5.cjs.entry.js +1727 -0
  7. package/dist/cjs/salla-localization.cjs.entry.js +82 -0
  8. package/dist/cjs/salla-login-c438bb35.js +128 -0
  9. package/dist/cjs/salla-offer.cjs.entry.js +79 -0
  10. package/dist/cjs/salla-product-availability.cjs.entry.js +75 -0
  11. package/dist/cjs/salla-rating.cjs.entry.js +195 -0
  12. package/dist/cjs/salla-search-45173394.js +85 -0
  13. package/dist/cjs/salla-search.cjs.entry.js +11 -0
  14. package/dist/cjs/twilight-components.cjs.js +19 -0
  15. package/dist/collection/Helpers/Helper.js +19 -0
  16. package/dist/collection/collection-manifest.json +22 -0
  17. package/dist/collection/components/generate-summary.js +35 -0
  18. package/dist/collection/components/salla-branches/salla-branches.css +12 -0
  19. package/dist/collection/components/salla-branches/salla-branches.js +233 -0
  20. package/dist/collection/components/salla-button/salla-button.css +3 -0
  21. package/dist/collection/components/salla-button/salla-button.js +246 -0
  22. package/dist/collection/components/salla-localization/salla-localization.js +208 -0
  23. package/dist/collection/components/salla-login/salla-login.css +3 -0
  24. package/dist/collection/components/salla-login/salla-login.js +380 -0
  25. package/dist/collection/components/salla-modal/salla-modal.js +477 -0
  26. package/dist/collection/components/salla-offer/offer-schema.js +1 -0
  27. package/dist/collection/components/salla-offer/salla-offer.js +110 -0
  28. package/dist/collection/components/salla-product-availability/salla-product-availability.js +331 -0
  29. package/dist/collection/components/salla-rating/order-feedback-response.js +1 -0
  30. package/dist/collection/components/salla-rating/salla-rating.css +7 -0
  31. package/dist/collection/components/salla-rating/salla-rating.js +277 -0
  32. package/dist/collection/components/salla-search/salla-search.css +24 -0
  33. package/dist/collection/components/salla-search/salla-search.js +143 -0
  34. package/dist/collection/components/salla-tel-input/salla-tel-input.js +121 -0
  35. package/dist/collection/components/salla-verify/salla-verify.js +280 -0
  36. package/dist/collection/index.js +2 -0
  37. package/dist/collection/interfaces/colors.js +1 -0
  38. package/dist/collection/interfaces/index.js +2 -0
  39. package/dist/collection/interfaces/ratio.js +1 -0
  40. package/dist/collection/plugins/tailwind-theme/generator.js +62 -0
  41. package/dist/collection/plugins/tailwind-theme/index.js +26 -0
  42. package/dist/{twilight-components → esm}/Helper-d07ebbc7.js +0 -0
  43. package/dist/esm/index-a1bf769d.js +1625 -0
  44. package/dist/esm/index.js +4 -0
  45. package/dist/esm/loader.js +17 -0
  46. package/dist/esm/polyfills/core-js.js +11 -0
  47. package/dist/esm/polyfills/css-shim.js +1 -0
  48. package/dist/esm/polyfills/dom.js +79 -0
  49. package/dist/esm/polyfills/es5-html-element.js +1 -0
  50. package/dist/esm/polyfills/index.js +34 -0
  51. package/dist/esm/polyfills/system.js +6 -0
  52. package/dist/{twilight-components → esm}/salla-branches.entry.js +2 -2
  53. package/dist/{twilight-components/salla-tel-input.entry.js → esm/salla-button_5.entry.js} +337 -35
  54. package/dist/{twilight-components → esm}/salla-localization.entry.js +1 -1
  55. package/dist/{twilight-components/salla-login-57b18c2c.js → esm/salla-login-dd957742.js} +26 -23
  56. package/dist/{twilight-components → esm}/salla-offer.entry.js +1 -1
  57. package/dist/{twilight-components → esm}/salla-product-availability.entry.js +1 -1
  58. package/dist/{twilight-components → esm}/salla-rating.entry.js +71 -108
  59. package/dist/{twilight-components/salla-search-30fec1e8.js → esm/salla-search-5e691ebb.js} +15 -11
  60. package/dist/esm/salla-search.entry.js +3 -0
  61. package/dist/esm/twilight-components.js +17 -0
  62. package/dist/index.cjs.js +1 -0
  63. package/dist/index.js +1 -0
  64. package/dist/twilight-components/index.esm.js +1 -4
  65. package/dist/twilight-components/p-1a6d8171.entry.js +1 -0
  66. package/dist/twilight-components/p-1deb8111.entry.js +1 -0
  67. package/dist/twilight-components/p-3a4d963e.js +1 -0
  68. package/dist/twilight-components/p-47f17d3b.js +1 -0
  69. package/dist/twilight-components/p-5b2eb87d.entry.js +1 -0
  70. package/dist/twilight-components/p-6a5be894.js +1 -0
  71. package/dist/twilight-components/p-7fbdf746.entry.js +1 -0
  72. package/dist/twilight-components/p-7fe5d346.entry.js +1 -0
  73. package/dist/twilight-components/p-81a61f4e.js +1 -0
  74. package/dist/twilight-components/p-ce991664.entry.js +1 -0
  75. package/dist/twilight-components/p-da73fc9b.entry.js +1 -0
  76. package/dist/twilight-components/twilight-components.css +1 -3
  77. package/dist/twilight-components/twilight-components.esm.js +1 -125
  78. package/dist/types/components/salla-login/salla-login.d.ts +3 -3
  79. package/dist/types/components/salla-modal/salla-modal.d.ts +1 -0
  80. package/dist/types/components/salla-rating/salla-rating.d.ts +6 -23
  81. package/dist/types/components/salla-search/salla-search.d.ts +1 -1
  82. package/dist/types/components/salla-tel-input/salla-tel-input.d.ts +14 -0
  83. package/dist/types/components/salla-verify/salla-verify.d.ts +3 -1
  84. package/dist/types/components.d.ts +12 -35
  85. package/package.json +1 -1
  86. package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
  87. package/dist/twilight-components/css-shim-a64b8820.js +0 -4
  88. package/dist/twilight-components/dom-d08ba8aa.js +0 -73
  89. package/dist/twilight-components/index-9c087700.js +0 -3010
  90. package/dist/twilight-components/salla-button.entry.js +0 -75
  91. package/dist/twilight-components/salla-login.entry.js +0 -3
  92. package/dist/twilight-components/salla-modal.entry.js +0 -113
  93. package/dist/twilight-components/salla-search.entry.js +0 -3
  94. package/dist/twilight-components/salla-verify.entry.js +0 -114
  95. package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
@@ -1,44 +1,198 @@
1
- import { r as registerInstance, h, e as Host } from './index-9c087700.js';
1
+ import { r as registerInstance, h, H as Host, g as getElement, c as createEvent } from './index-a1bf769d.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+ export { S as salla_login } from './salla-login-dd957742.js';
2
4
 
3
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
5
+ const sallaButtonCss = ":host{display:block}";
4
6
 
5
- function getDefaultExportFromCjs (x) {
6
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
7
- }
7
+ const SallaButton = class {
8
+ constructor(hostRef) {
9
+ registerInstance(this, hostRef);
10
+ this.btnStyle = 'primary';
11
+ this.loading = false;
12
+ this.disabled = false;
13
+ this.loaderPosition = 'before';
14
+ this.wide = false;
15
+ this.hostAttributes = {};
16
+ //============= Initiate Button Attributes =============//
17
+ for (let i = 0; i < this.host.attributes.length; i++) {
18
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
19
+ }
20
+ this.hostAttributes.type = this.hostAttributes.type || 'button';
21
+ this.hostAttributes.class += ' s-button-btn btn--has-loading'
22
+ + ' s-button-' + this.btnStyle
23
+ + (this.wide ? ' s-button-wide ' : '')
24
+ + ' loader-' + this.loaderPosition
25
+ + (this.loaderPosition == 'before' ? ' s-button-loader-after' : '');
26
+ delete this.hostAttributes['btn-style'];
27
+ delete this.hostAttributes['id'];
28
+ if (this.wide) {
29
+ this.host.classList.add('s-button-wide');
30
+ }
31
+ }
32
+ async load() {
33
+ if (this.loaderPosition == 'center')
34
+ this.text.classList.add('s-button-hide');
35
+ this.host.setAttribute('loading', '');
36
+ return this.host;
37
+ }
38
+ async stop() {
39
+ this.host.removeAttribute('loading');
40
+ return this.host;
41
+ }
42
+ async disable() {
43
+ this.host.setAttribute('disabled', '');
44
+ }
45
+ async enable() {
46
+ this.host.removeAttribute('disabled');
47
+ }
48
+ handleVisible(newKind, oldKind) {
49
+ //todo::use united styles
50
+ this.btn.classList.remove('btn-' + oldKind);
51
+ this.btn.classList.add('btn-' + newKind);
52
+ }
53
+ handleLoading(newVal) {
54
+ //todo::use united styles
55
+ Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
56
+ }
57
+ render() {
58
+ return (
59
+ //TODO:: use HOST then fake button behaviours
60
+ h(Host, { class: "s-button-host-tag" }, h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes), h("span", { class: "s-button-text", ref: el => this.text = el }, h("slot", null)), this.loading ? h("span", { class: {
61
+ //todo::use united styles
62
+ 's-button-loader': true,
63
+ 's-button-loader-start': this.loaderPosition === 'start',
64
+ 's-button-loader-end': this.loaderPosition === 'end',
65
+ 's-button-loader-center': this.loaderPosition === 'center',
66
+ } }) : '')));
67
+ }
68
+ get host() { return getElement(this); }
69
+ static get watchers() { return {
70
+ "btnStyle": ["handleVisible"],
71
+ "loading": ["handleLoading"]
72
+ }; }
73
+ };
74
+ SallaButton.style = sallaButtonCss;
75
+
76
+ const SallaModal = class {
77
+ constructor(hostRef) {
78
+ registerInstance(this, hostRef);
79
+ this.modalOpened = createEvent(this, "modalOpened", 7);
80
+ this.modalClosed = createEvent(this, "modalClosed", 7);
81
+ var _a;
82
+ //todo:: unite three colors (error, success, primary) in one prop
83
+ this.error = false;
84
+ this.success = false;
85
+ this.primary = false;
86
+ this.isClosable = true;
87
+ this.width = 'md';
88
+ this.position = 'middel';
89
+ this.visible = false;
90
+ this.isLoading = false;
91
+ this.subTitleFirst = false;
92
+ this.subTitle = '';
93
+ this.icon = '';
94
+ this.imageIcon = '';
95
+ Helper.setHost(this.host);
96
+ salla.event.on('modal::open', btn => btn.dataset.target == this.host.id && this.show());
97
+ salla.event.on('modal::close', btn => btn.dataset.target == this.host.id && this.hide());
98
+ this.title = this.host.title;
99
+ this.host.removeAttribute('title');
100
+ (_a = Helper.getElement('[slot=body]')) === null || _a === void 0 ? void 0 : _a.classList.add('s-modal-body', 's-modal-' + this.width);
101
+ }
102
+ handleVisible(newValue) {
103
+ if (!newValue) {
104
+ this.toggleModal(false);
105
+ this.modalClosed.emit();
106
+ return;
107
+ }
108
+ this.host.classList.remove('hidden');
109
+ setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
110
+ this.modalOpened.emit();
111
+ }
112
+ async show() {
113
+ this.host.setAttribute('visible', '');
114
+ return this.host;
115
+ }
116
+ async hide() {
117
+ this.host.removeAttribute('visible');
118
+ return this.host;
119
+ }
120
+ async setTitle(title) {
121
+ this.title = title;
122
+ return this.host;
123
+ }
124
+ async loading() {
125
+ this.isLoading = true;
126
+ return this.host;
127
+ }
128
+ async stopLoading() {
129
+ this.isLoading = false;
130
+ return this.host;
131
+ }
132
+ toggleModal(isOpen) {
133
+ Helper
134
+ // .toggleElement(this.host.querySelector('.s-modal-body'), 's-modal-entering', 's-modal-leaving', () => isOpen)
135
+ .toggleElement(this.host.querySelector('[slot=body]') || this.host, 's-modal-entering', 's-modal-leaving', () => isOpen)
136
+ .toggleElement(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
137
+ //todo:: use united class names
138
+ .toggleElement(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
139
+ if (!isOpen) {
140
+ setTimeout(() => this.host.classList.add('hidden'), 350);
141
+ }
142
+ }
143
+ closeModal() {
144
+ if (!this.isClosable) {
145
+ return;
146
+ }
147
+ this.host.removeAttribute('visible');
148
+ }
149
+ //todo:: pref for each modal
150
+ render() {
151
+ this.host.id = this.host.id || 'salla-modal';
152
+ return (
153
+ //todo:: use suitable class name instead of hidden
154
+ h(Host, { class: 's-modal-container hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-wrapper" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), 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, slot: "body" }, this.isLoading
155
+ ? h("span", null, "Loading...")
156
+ :
157
+ [h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.icon != '' || this.imageIcon != '' } }, this.isClosable ?
158
+ h("button", { class: "s-modal-close", onClick: () => this.closeModal(), type: "button" }, h("span", { class: "sicon-cancel" }))
159
+ : '', this.error || this.success || this.icon
160
+ ? h("div", { class: {
161
+ 's-modal-icon': true,
162
+ 's-modal-bg-error': this.error,
163
+ 's-modal-bg-success': this.success,
164
+ 's-modal-bg-normal': !this.error && !this.success,
165
+ 's-modal-bg-primary': this.primary
166
+ } }, h("i", { class: {
167
+ [this.icon]: true,
168
+ 's-modal-text-error': this.error,
169
+ 's-modal-text-success': this.success,
170
+ } }))
171
+ : this.imageIcon ?
172
+ h("img", { class: "s-modal-header-img", src: this.imageIcon })
173
+ : '', this.title || this.subTitle ?
174
+ 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 }))
175
+ : ''),
176
+ h("slot", null),
177
+ h("slot", { name: "footer" })
178
+ ]))));
179
+ }
180
+ get host() { return getElement(this); }
181
+ static get watchers() { return {
182
+ "visible": ["handleVisible"]
183
+ }; }
184
+ };
8
185
 
9
186
  function createCommonjsModule(fn, basedir, module) {
10
187
  return module = {
11
188
  path: basedir,
12
189
  exports: {},
13
190
  require: function (path, base) {
14
- return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
191
+ return commonjsRequire();
15
192
  }
16
193
  }, fn(module, module.exports), module.exports;
17
194
  }
18
195
 
19
- function getDefaultExportFromNamespaceIfPresent (n) {
20
- return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
21
- }
22
-
23
- function getDefaultExportFromNamespaceIfNotNamed (n) {
24
- return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
25
- }
26
-
27
- function getAugmentedNamespace(n) {
28
- if (n.__esModule) return n;
29
- var a = Object.defineProperty({}, '__esModule', {value: true});
30
- Object.keys(n).forEach(function (k) {
31
- var d = Object.getOwnPropertyDescriptor(n, k);
32
- Object.defineProperty(a, k, d.get ? d : {
33
- enumerable: true,
34
- get: function () {
35
- return n[k];
36
- }
37
- });
38
- });
39
- return a;
40
- }
41
-
42
196
  function commonjsRequire () {
43
197
  throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
44
198
  }
@@ -52,9 +206,8 @@ var intlTelInput$1 = createCommonjsModule(function (module) {
52
206
 
53
207
  // wrap in UMD
54
208
  (function(factory) {
55
- if ('object' === "object" && module.exports) module.exports = factory(); else window.intlTelInput = factory();
209
+ if (module.exports) module.exports = factory(); else window.intlTelInput = factory();
56
210
  })(function(undefined$1) {
57
- "use strict";
58
211
  return function() {
59
212
  // Array of country objects for the flag dropdown.
60
213
  // Here is the criteria for the plugin to support a given country/territory
@@ -82,7 +235,6 @@ var intlTelInput$1 = createCommonjsModule(function (module) {
82
235
  areaCodes: c[4] || null
83
236
  };
84
237
  }
85
- "use strict";
86
238
  function _classCallCheck(instance, Constructor) {
87
239
  if (!(instance instanceof Constructor)) {
88
240
  throw new TypeError("Cannot call a class as a function");
@@ -1407,11 +1559,161 @@ var intlTelInput = intlTelInput$1;
1407
1559
  const SallaTelInput = class {
1408
1560
  constructor(hostRef) {
1409
1561
  registerInstance(this, hostRef);
1410
- console.log(intlTelInput);
1562
+ this.countryCode = "SA";
1563
+ this.countryKey = "+966";
1564
+ Helper.setHost(this.host);
1565
+ }
1566
+ async getValues() {
1567
+ this.phone = this.phoneInput.value;
1568
+ this.countryCode = this.countryCodeInput.value;
1569
+ this.countryKey = this.countryKeyInput.value;
1570
+ return { phone: this.phoneInput.value, countryCode: this.countryCodeInput.value, countryKey: this.countryKeyInput.value };
1571
+ }
1572
+ initTelInput() {
1573
+ salla.document.event.onKeyup('.tel-input', event => salla.helpers.digitsOnly(event.target));
1574
+ document.querySelectorAll('.tel-input').forEach((intlInput) => {
1575
+ salla.helpers.digitsOnly(intlInput);
1576
+ let iti = intlTelInput(intlInput, {
1577
+ initialCountry: intlInput.dataset.code || 'sa',
1578
+ preferredCountries: ['sa', 'ae', 'kw', 'bh', 'qa', 'iq', 'om', 'ye', 'eg', 'jo', 'sy', 'ps', 'sd', 'lb', 'dz', 'tn', 'ma', 'ly'],
1579
+ formatOnDisplay: false,
1580
+ separateDialCode: true,
1581
+ autoPlaceholder: 'aggressive',
1582
+ utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.12/js/utils.min.js',
1583
+ });
1584
+ intlInput.addEventListener("countrychange", () => {
1585
+ let data = iti.getSelectedCountryData();
1586
+ this.host.querySelectorAll('.country_code').forEach((input) => input.value = data.iso2.toUpperCase());
1587
+ this.host.querySelectorAll('.country_key').forEach((input) => {
1588
+ input.value = ('+' + data.dialCode).replace('++', '+');
1589
+ });
1590
+ });
1591
+ });
1592
+ }
1593
+ render() {
1594
+ return (h(Host, null, h("input", { type: "tel", name: "mobile", "data-code": this.countryCode, value: this.phone, ref: el => this.phoneInput = el, class: "s-tel-input-control tel-input s-ltr" }), h("input", { type: "hidden", name: "country_code", value: this.countryCode, ref: el => this.countryCodeInput = el, class: "country_code" }), h("input", { type: "hidden", name: "country_key", value: this.countryKey, ref: el => this.countryKeyInput = el, class: "country_key" })));
1595
+ }
1596
+ componentDidRender() {
1597
+ this.initTelInput();
1598
+ }
1599
+ get host() { return getElement(this); }
1600
+ };
1601
+
1602
+ const SallaVerify = class {
1603
+ constructor(hostRef) {
1604
+ registerInstance(this, hostRef);
1605
+ this.verified = createEvent(this, "verified", 7);
1606
+ this.backClicked = createEvent(this, "backClicked", 7);
1607
+ this.url = 'profile/verify-mobile';
1608
+ this.by = 'sms';
1609
+ this.autoReload = true;
1610
+ Helper.setHost(this.host);
1611
+ if (this.withoutModal) {
1612
+ this.modal = { show: () => '', hide: () => '' };
1613
+ }
1614
+ else {
1615
+ salla.event.on('profile::verify.mobile', data => this.show(data));
1616
+ }
1617
+ }
1618
+ async getCode() {
1619
+ return this.code.value;
1620
+ }
1621
+ componentDidLoad() {
1622
+ Helper.on('input', '.s-verify-input', e => salla.helpers.digitsOnly(e.target));
1623
+ Helper.onKeyUp('.s-verify-input', event => {
1624
+ var _a, _b, _c, _d;
1625
+ let key = event.keyCode || event.charCode;
1626
+ if (event.target.value) {
1627
+ (_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
1628
+ (_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
1629
+ }
1630
+ else if ([8, 46].includes(key)) {
1631
+ (_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
1632
+ (_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
1633
+ }
1634
+ this.toggleOTPSubmit();
1635
+ });
1636
+ Helper.on('paste', '.s-verify-input', event => {
1637
+ let text = event.clipboardData.getData('text').toArabicDigits().replace(/[^0-9.]/g, '').replace('..', '.');
1638
+ this.otpInputs.forEach((input, i) => input.value = text[i] || '');
1639
+ this.toggleOTPSubmit();
1640
+ setTimeout(() => this.otpInputs[3].focus(), 100);
1641
+ });
1642
+ return this.modal.show();
1643
+ }
1644
+ async show(data) {
1645
+ this.data = data;
1646
+ this.resendTimer();
1647
+ this.otpInputs = document.querySelectorAll('.s-verify-input');
1648
+ this.reset();
1649
+ }
1650
+ toggleOTPSubmit() {
1651
+ let otp = [];
1652
+ this.otpInputs.forEach(input => input.value && otp.push(input.value));
1653
+ this.code.value = otp.join('');
1654
+ if (otp.length === 4) {
1655
+ this.btn.removeAttribute('disabled');
1656
+ this.btn.click();
1657
+ return;
1658
+ }
1659
+ this.btn.setAttribute('disabled', '');
1660
+ }
1661
+ reset() {
1662
+ this.otpInputs.forEach((input) => input.value = '');
1663
+ this.code.value = '';
1664
+ this.otpInputs[0].focus();
1665
+ }
1666
+ resendTimer() {
1667
+ Helper.showElement(this.resendMessage).hideElement(this.resend);
1668
+ let resendAfter = 30;
1669
+ let timerId = setInterval(() => {
1670
+ if (resendAfter === -1) {
1671
+ clearTimeout(timerId);
1672
+ Helper.hideElement(this.resendMessage).showElement(this.resend);
1673
+ }
1674
+ else {
1675
+ this.timer.innerHTML = `${resendAfter >= 10 ? resendAfter : '0' + resendAfter} : 00`;
1676
+ resendAfter--;
1677
+ }
1678
+ }, 1000);
1679
+ }
1680
+ resendCode() {
1681
+ return this.btn.stop()
1682
+ .then(() => this.btn.disable())
1683
+ .then(() => {
1684
+ this.otpInputs.forEach(input => input.value = '');
1685
+ this.otpInputs[0].focus();
1686
+ })
1687
+ .then(() => salla.api.auth.resend(Object.assign({ resend_by: this.by }, this.data)))
1688
+ .then(() => this.resendTimer())
1689
+ .catch(() => this.resendTimer());
1690
+ }
1691
+ submit() {
1692
+ return this.btn.load()
1693
+ .then(() => this.btn.disable())
1694
+ .then(() => salla.document.api.request(this.url, Object.assign({ code: this.code.value }, this.data)))
1695
+ .then(response => this.verified.emit(response))
1696
+ .then(() => this.btn.stop() && this.btn.disable())
1697
+ .then(() => this.modal.hide())
1698
+ .then(() => this.autoReload && window.location.reload())
1699
+ .catch(() => this.btn.stop() && this.btn.enable() && this.reset());
1411
1700
  }
1412
1701
  render() {
1413
- return (h(Host, null, h("slot", null, h("h1", null, "Test Tel Input"))));
1702
+ return this.withoutModal ? this.myBody() :
1703
+ h("salla-modal", { id: "s-verify", ref: modal => this.modal = modal, title: salla.lang.get('pages.profile.verify_title') }, this.myBody());
1704
+ }
1705
+ myBody() {
1706
+ return [
1707
+ h("div", { class: "s-verify-message", innerHTML: salla.lang.get('pages.profile.verify_message') }),
1708
+ // <label class="s-verify-label">{salla.lang.get('pages.profile.verify_placeholder')}</label>,
1709
+ h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }),
1710
+ h("div", { class: "s-verify-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => h("input", { type: "text", maxlength: "1", class: "s-verify-input", required: true }))),
1711
+ h("div", { slot: "footer", class: "s-verify-footer" }, h("salla-button", { class: "s-verify-submit", disabled: true, onClick: () => this.submit(), ref: b => this.btn = b }, salla.lang.get('pages.profile.verify')), h("p", { class: "s-verify-resend-message", ref: el => this.resendMessage = el }, salla.lang.get('blocks.header.resend_after'), h("b", { class: "s-verify-timer", ref: el => this.timer = el })), h("a", { href: "#", class: "s-verify-resend", onClick: () => this.resendCode(), ref: el => this.resend = el }, salla.lang.get('blocks.comments.submit')), this.backText ?
1712
+ h("a", { href: "#", class: "s-verify-resend", onClick: () => this.backClicked.emit() }, this.backText)
1713
+ : '')
1714
+ ];
1414
1715
  }
1716
+ get host() { return getElement(this); }
1415
1717
  };
1416
1718
 
1417
- export { SallaTelInput as salla_tel_input };
1719
+ export { SallaButton as salla_button, SallaModal as salla_modal, SallaTelInput as salla_tel_input, SallaVerify as salla_verify };
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
1
+ import { r as registerInstance, h, g as getElement } from './index-a1bf769d.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaLocalization = class {
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
1
+ import { r as registerInstance, h, g as getElement } from './index-a1bf769d.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const sallaLoginCss = "salla-verify{display:block}";
@@ -6,8 +6,8 @@ const sallaLoginCss = "salla-verify{display:block}";
6
6
  const SallaLogin = class {
7
7
  constructor(hostRef) {
8
8
  registerInstance(this, hostRef);
9
- this.regType = 'sms';
10
- this.isLoginByMail = true;
9
+ this.regType = 'phone';
10
+ this.isEmailAllowed = true;
11
11
  this.loginTypeTitle = salla.lang.get('blocks.header.select_login_way');
12
12
  this.loginText = salla.lang.get('blocks.header.login');
13
13
  this.smsLabel = salla.lang.get('blocks.header.sms');
@@ -44,10 +44,10 @@ const SallaLogin = class {
44
44
  window.location.reload();
45
45
  }
46
46
  onbackClicked() {
47
- this.regType == 'sms' ? this.showTab(this.tab2) : this.showTab(this.tab3);
47
+ this.regType == 'phone' ? this.showTab(this.tab2) : this.showTab(this.tab3);
48
48
  }
49
49
  async show() {
50
- this.showTab(this.isLoginByMail ? this.tab1 : this.tab2);
50
+ this.showTab(this.isEmailAllowed ? this.tab1 : this.tab2);
51
51
  return this.modal.show();
52
52
  }
53
53
  showTab(tab) {
@@ -55,12 +55,13 @@ const SallaLogin = class {
55
55
  setTimeout(() => { [this.tab1, this.tab2, this.tab3, this.tab4, this.tab5].map(el => Helper.toggleElement(el, 's-login-active', 's-login-unactive', () => el == tab)); }, 200);
56
56
  setTimeout(() => { this.host.querySelector('.s-login-wrapper').setAttribute('style', 'height:' + (tab === null || tab === void 0 ? void 0 : tab.scrollHeight) + 'px'); });
57
57
  if ([this.tab2, this.tab3].includes(tab)) {
58
- this.regType = tab === this.tab2 ? 'sms' : 'email';
58
+ this.regType = tab === this.tab2 ? 'phone' : 'email';
59
59
  }
60
60
  let isRegistrationTab = tab == this.tab5;
61
+ isRegistrationTab && this.firstName.focus();
61
62
  this.modal.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
62
63
  if (!isRegistrationTab) {
63
- Helper.toggleElement(this.regMobileBlock, 's-hidden', 's-block', () => this.regType === 'sms')
64
+ Helper.toggleElement(this.regMobileBlock, 's-hidden', 's-block', () => this.regType === 'phone')
64
65
  .toggleElement(this.regEmailBlock, 's-hidden', 's-block', () => this.regType === 'email');
65
66
  }
66
67
  return this;
@@ -78,18 +79,19 @@ const SallaLogin = class {
78
79
  .then(() => (this.tab4.by = 'email') && (this.tab4.url = 'auth/email/verify'))
79
80
  .then(() => this.tab4.show({ email: this.email.value }));
80
81
  }
81
- loginBySMS() {
82
- if (this.mobile.value.length < 6) {
83
- this.mobile.classList.add('s-has-error');
84
- this.mobile.nextElementSibling['innerText'] = '* ' + salla.lang.get('mobile_app.strings.incorrect_mobile');
82
+ async loginBySMS() {
83
+ const { phone, countryCode } = await this.loginTelInput.getValues();
84
+ if (phone.length < 6) {
85
+ this.loginTelInput.classList.add('s-has-error');
86
+ this.loginTelInput.nextElementSibling['innerText'] = '* ' + salla.lang.get('mobile_app.strings.incorrect_mobile');
85
87
  return;
86
88
  }
87
- this.mobile.nextElementSibling['innerText'] = '';
88
- this.mobile.classList.remove('s-has-error');
89
- salla.auth.api.login({ type: 'sms', mobile: this.mobile.value })
89
+ this.loginTelInput.nextElementSibling['innerText'] = '';
90
+ this.loginTelInput.classList.remove('s-has-error');
91
+ salla.auth.api.login({ type: 'mobile', phone: phone, country_code: countryCode })
90
92
  .then(() => this.showTab(this.tab4))
91
93
  .then(() => (this.tab4.by = 'sms') && (this.tab4.url = 'auth/mobile/verify'))
92
- .then(() => this.tab4.show({ mobile: this.mobile.value, country_code: 'SA' }));
94
+ .then(() => this.tab4.show({ phone: phone, country_code: countryCode }));
93
95
  }
94
96
  //TODO:: if it's enter, go submit
95
97
  typing({ target }) {
@@ -97,24 +99,25 @@ const SallaLogin = class {
97
99
  target.classList.remove('s-has-error');
98
100
  target.nextElementSibling.innerText = '';
99
101
  }
100
- newUser() {
102
+ async newUser() {
103
+ const { phone: regPhone, countryCode, countryKey } = await this.regTelInput.getValues();
101
104
  this.tab4.getCode()
102
105
  .then(code => salla.auth.api.register({
103
106
  first_name: this.firstName.value,
104
107
  last_name: this.lastName.value,
105
- phone: this.regMobile.value || this.mobile.value,
108
+ phone: regPhone || this.loginTelInput.phone,
106
109
  email: this.regEmail.value || this.email.value,
107
- country_code: '',
108
- country_key: '',
110
+ country_code: countryCode,
111
+ country_key: countryKey,
109
112
  code: code,
110
113
  verified_by: this.regType,
111
- }));
114
+ })).then(() => window.location.reload());
112
115
  }
113
116
  render() {
114
- return (h("salla-modal", { id: "salla-login", title: this.title, ref: modal => this.modal = modal, width: "xs" }, h("div", { class: "s-login-wrapper" }, this.isLoginByMail ?
117
+ return (h("salla-modal", { id: "salla-login", title: this.title, ref: modal => this.modal = modal, width: "xs" }, h("div", { class: "s-login-wrapper" }, this.isEmailAllowed ?
115
118
  h("div", { class: "s-login-tab", ref: tab => this.tab1 = tab }, h("p", { class: "s-login-sub-title" }, this.loginTypeTitle), h("a", { href: "#", class: "s-login-main-btn", onClick: () => this.showTab(this.tab2) }, h("i", { class: "s-login-main-btn-icon sicon-phone" }), h("span", { class: "s-login-main-btn-text" }, this.smsLabel), h("i", { class: "main-btn-arrow sicon-keyboard_arrow_left" })), h("a", { href: "#", class: "s-login-main-btn", onClick: () => this.showTab(this.tab3) }, h("i", { class: "s-login-main-btn-icon sicon-mail" }), h("span", { class: "s-login-main-btn-text" }, this.emailLabel), h("i", { class: "main-btn-arrow sicon-keyboard_arrow_left" })))
116
- : '', h("div", { class: "s-login-tab", ref: tab => this.tab2 = tab }, h("label", { class: "s-login-label" }, this.mobileLabel), h("salla-tel-input", null), h("input", { onChange: () => this.loginBySMS(), type: "tel", ref: el => this.mobile = el, onInput: this.typing, placeholder: "5xx xxx xxx", class: "s-login-input tel-input s-ltr" }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginBySMS() }, this.enterText), this.isLoginByMail ? h("a", { href: "#", onClick: () => this.showTab(this.tab3), class: "s-login-link" }, this.byEmailText) : ''), this.isLoginByMail ?
117
- h("div", { class: "s-login-tab", ref: tab => this.tab3 = tab }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { onChange: () => this.loginByEmail(), type: "email", ref: el => this.email = el, onInput: this.typing, placeholder: "your@email.com", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginByEmail() }, this.enterText), h("a", { href: "#", onClick: () => this.showTab(this.tab2), class: "s-login-link" }, this.bySMSText)) : '', h("salla-verify", { "without-modal": true, ref: tab => this.tab4 = tab, autoReload: false, "back-text": this.backText }), h("div", { ref: tab => this.tab5 = tab }, h("label", { class: "s-login-label" }, salla.lang.get('blocks.header.your_name')), h("input", { type: "text", class: "s-login-input", ref: el => this.firstName = el, placeholder: salla.lang.get('pages.profile.first_name') }), h("label", { class: "s-login-label" }, salla.lang.get('pages.profile.last_name')), h("input", { type: "text", class: "s-login-input", ref: el => this.lastName = el, placeholder: salla.lang.get('pages.profile.last_name') }), h("div", { ref: el => this.regMobileBlock = el }, h("label", { class: "s-login-label" }, this.mobileLabel), h("input", { type: "tel", ref: el => this.regMobile = el, onInput: this.typing, placeholder: "5xx xxx xxx", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" })), h("div", { ref: el => this.regEmailBlock = el }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { type: "email", ref: el => this.regEmail = el, onInput: this.typing, placeholder: "your@email.com", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" })), h("salla-button", { wide: true, onClick: () => this.newUser() }, salla.lang.get('blocks.header.register'))))));
119
+ : '', h("div", { class: "s-login-tab", ref: tab => this.tab2 = tab }, h("label", { class: "s-login-label" }, this.mobileLabel), h("salla-tel-input", { phone: '', ref: el => this.loginTelInput = el }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginBySMS() }, this.enterText), this.isEmailAllowed ? h("a", { href: "#", onClick: () => this.showTab(this.tab3), class: "s-login-link" }, this.byEmailText) : ''), this.isEmailAllowed ?
120
+ h("div", { class: "s-login-tab", ref: tab => this.tab3 = tab }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { onChange: () => this.loginByEmail(), type: "email", ref: el => this.email = el, onInput: this.typing, placeholder: "your@email.com", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginByEmail() }, this.enterText), h("a", { href: "#", onClick: () => this.showTab(this.tab2), class: "s-login-link" }, this.bySMSText)) : '', h("salla-verify", { "without-modal": true, ref: tab => this.tab4 = tab, autoReload: false, "back-text": this.backText }), h("div", { ref: tab => this.tab5 = tab }, h("label", { class: "s-login-label" }, salla.lang.get('blocks.header.your_name')), h("input", { type: "text", class: "s-login-input", ref: el => this.firstName = el, placeholder: salla.lang.get('pages.profile.first_name') }), h("label", { class: "s-login-label" }, salla.lang.get('pages.profile.last_name')), h("input", { type: "text", class: "s-login-input", ref: el => this.lastName = el, placeholder: salla.lang.get('pages.profile.last_name') }), h("div", { ref: el => this.regMobileBlock = el }, h("label", { class: "s-login-label" }, this.mobileLabel), h("salla-tel-input", { phone: '', ref: el => this.regTelInput = el }), h("span", { class: "s-login-error-message" })), h("div", { ref: el => this.regEmailBlock = el }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { type: "email", ref: el => this.regEmail = el, onInput: this.typing, placeholder: "your@email.com", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" })), h("salla-button", { wide: true, onClick: () => this.newUser() }, salla.lang.get('blocks.header.register'))))));
118
121
  }
119
122
  get host() { return getElement(this); }
120
123
  };
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, g as getElement } from './index-9c087700.js';
1
+ import { r as registerInstance, h, g as getElement } from './index-a1bf769d.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaOffer = class {
@@ -1,4 +1,4 @@
1
- import { r as registerInstance, h, e as Host, g as getElement } from './index-9c087700.js';
1
+ import { r as registerInstance, h, H as Host, g as getElement } from './index-a1bf769d.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaProductAvailability = class {