@salla.sa/twilight-components 1.0.16 → 1.0.18

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 (26) hide show
  1. package/dist/twilight-components/{Helper-81ac9a8c.js → Helper-d07ebbc7.js} +1 -1
  2. package/dist/twilight-components/index.esm.js +3 -3
  3. package/dist/twilight-components/salla-branches.entry.js +5 -5
  4. package/dist/twilight-components/salla-button.entry.js +16 -14
  5. package/dist/twilight-components/salla-localization.entry.js +30 -25
  6. package/dist/twilight-components/salla-login-7c25f64b.js +116 -0
  7. package/dist/twilight-components/salla-login-b92c73dc.js +127 -0
  8. package/dist/twilight-components/salla-login.entry.js +2 -1
  9. package/dist/twilight-components/salla-modal.entry.js +49 -27
  10. package/dist/twilight-components/salla-offer.entry.js +46 -0
  11. package/dist/twilight-components/salla-product-availability.entry.js +2 -2
  12. package/dist/twilight-components/salla-rating.entry.js +73 -70
  13. package/dist/twilight-components/{salla-search-5338c0a1.js → salla-search-69f2d9c1.js} +1 -1
  14. package/dist/twilight-components/salla-search.entry.js +2 -2
  15. package/dist/twilight-components/salla-verify.entry.js +43 -21
  16. package/dist/twilight-components/twilight-components.esm.js +1 -1
  17. package/dist/types/components/salla-button/salla-button.d.ts +3 -2
  18. package/dist/types/components/salla-localization/salla-localization.d.ts +10 -0
  19. package/dist/types/components/salla-login/salla-login.d.ts +40 -0
  20. package/dist/types/components/salla-modal/salla-modal.d.ts +12 -4
  21. package/dist/types/components/salla-offer/salla-offer.d.ts +56 -0
  22. package/dist/types/components/salla-rating/salla-rating.d.ts +17 -2
  23. package/dist/types/components/salla-verify/salla-verify.d.ts +18 -6
  24. package/dist/types/components.d.ts +99 -8
  25. package/package.json +2 -1
  26. package/dist/twilight-components/salla-login-4d620368.js +0 -12
@@ -13,7 +13,7 @@ class Helper extends salla.AppHelpers {
13
13
  return this.getAttribute(selector, 'value');
14
14
  }
15
15
  isUser() {
16
- return !!salla.config.is_user;
16
+ return salla.config.get('user.type') === 'user';
17
17
  }
18
18
  }
19
19
  const Helper$1 = new Helper;
@@ -1,4 +1,4 @@
1
- export { S as SallaLogin } from './salla-login-4d620368.js';
2
- export { S as SallaSearch } from './salla-search-5338c0a1.js';
1
+ export { S as SallaLogin } from './salla-login-b92c73dc.js';
2
+ export { S as SallaSearch } from './salla-search-69f2d9c1.js';
3
3
  import './index-8966d27f.js';
4
- import './Helper-81ac9a8c.js';
4
+ import './Helper-d07ebbc7.js';
@@ -25,9 +25,9 @@ const SallaBranches = class {
25
25
  };
26
26
  this.statusColor = (branch = null) => {
27
27
  return branch ?
28
- branch.limited ? 'text-red-400' : branch.available ? 'text-green-500' : 'text-gray-400'
28
+ branch.limited ? 's-branches-color-red' : branch.available ? 's-branches-color-green' : 's-branches-color-gray'
29
29
  :
30
- this.currentBranch('limited') ? 'text-red-400' : this.currentBranch('available') ? 'text-green-500' : 'text-gray-400';
30
+ this.currentBranch('limited') ? 's-branches-color-red' : this.currentBranch('available') ? 's-branches-color-green' : 's-branches-color-gray';
31
31
  };
32
32
  this.isChoiceable = () => {
33
33
  return (this.browseProductsFrom !== 'all' && this.position == 'single') || this.position == 'header';
@@ -59,7 +59,7 @@ const SallaBranches = class {
59
59
  }, 300);
60
60
  }
61
61
  render() {
62
- return (h("salla-modal", { icon: "sicon-store-alt", title: "\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636", "sub-title": "\u0623\u0646\u062A \u0627\u0644\u0622\u0646 \u062A\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u062A\u062C\u0631 \u0645\u0646", "sub-title-first": true, "is-closable": !this.isOpenedBefore && this.displayAs == 'popup' ? 'false' : 'true', ref: modal => this.modal = modal, "modal-width": "w-116", id: "s-branches-modal", class: "hidden" }, h("fieldset", null, h("h4", { class: "s-branches-title" }, this.formTitle()), h("legend", { class: "s-branches-sr-only" }, this.formTitle()), this.branches.length <= 5 ?
62
+ return (h("salla-modal", { icon: "sicon-store-alt", title: "\u0641\u0631\u0639 \u0627\u0644\u0631\u064A\u0627\u0636", "sub-title": "\u0623\u0646\u062A \u0627\u0644\u0622\u0646 \u062A\u062A\u0635\u0641\u062D \u0627\u0644\u0645\u062A\u062C\u0631 \u0645\u0646", "sub-title-first": true, "is-closable": !this.isOpenedBefore && this.displayAs == 'popup' ? 'false' : 'true', ref: modal => this.modal = modal, "modal-width": "sm", id: "s-branches-modal", class: "hidden" }, h("h4", { class: "s-branches-title" }, this.formTitle()), this.branches.length <= 5 ?
63
63
  h("div", { class: "s-branches-space-v" }, this.branches.map((branch) => h("div", { class: "s-branches-input-wrap" }, h("input", { id: this.position + '_branch_' + branch.id, disabled: !branch.open && this.isChoiceable(), name: "lang", type: "radio", value: branch.id, onChange: (event) => this.handelChange(event), class: {
64
64
  's-branches-input': true,
65
65
  'opacity-50': !branch.open,
@@ -72,8 +72,8 @@ const SallaBranches = class {
72
72
  :
73
73
  h("span", { class: this.statusColor(branch) }, branch.tag)))))
74
74
  :
75
- h("select", { class: "s-branches-select", onInput: (event) => this.handelChange(event) }, this.branches.map(branch => (h("option", { value: branch.id, disabled: !branch.open, selected: this.selected == branch.id }, branch.name, " ", branch.open ? '' : '- مُغلق'))))), this.isChoiceable() ?
76
- h("slot", { name: "footer" }, h("salla-button", { "loader-position": "before", ref: btn => this.btn = btn, onClick: () => this.handleSubmit(), class: "s-branches-submit" }, salla.lang.get('common.elements.ok')))
75
+ h("select", { class: "s-branches-select", onInput: (event) => this.handelChange(event) }, this.branches.map(branch => (h("option", { value: branch.id, disabled: !branch.open, selected: this.selected == branch.id }, branch.name, " ", branch.open ? '' : '- مُغلق')))), this.isChoiceable() ?
76
+ h("slot", { name: "footer" }, h("salla-button", { ref: btn => this.btn = btn, onClick: () => this.handleSubmit(), class: "s-branches-submit", wide: true }, salla.lang.get('common.elements.ok')))
77
77
  : ''));
78
78
  }
79
79
  componentDidRender() {
@@ -1,12 +1,12 @@
1
- import { r as registerInstance, h, g as getElement } from './index-8966d27f.js';
2
- import { H as Helper } from './Helper-81ac9a8c.js';
1
+ import { r as registerInstance, h, e as Host, g as getElement } from './index-8966d27f.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const sallaButtonCss = ":host{display:block}";
5
5
 
6
6
  const SallaButton = class {
7
7
  constructor(hostRef) {
8
8
  registerInstance(this, hostRef);
9
- this.btnStyle = 'primary'; // outline, outline-primary ,danger
9
+ this.btnStyle = 'primary';
10
10
  this.loading = false;
11
11
  this.disabled = false;
12
12
  this.loaderPosition = 'before';
@@ -17,14 +17,11 @@ const SallaButton = class {
17
17
  this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
18
18
  }
19
19
  this.hostAttributes.type = this.hostAttributes.type || 'button';
20
- this.hostAttributes.class += ' s-button-btn btn--has-loading '
21
- + 'btn-' + this.btnStyle
20
+ this.hostAttributes.class += ' s-button-btn btn--has-loading'
21
+ + ' s-button-' + this.btnStyle
22
22
  + (this.wide ? ' s-button-wide ' : '')
23
- + 'loader-' + this.loaderPosition
23
+ + ' loader-' + this.loaderPosition
24
24
  + (this.loaderPosition == 'before' ? ' s-button-loader-after' : '');
25
- // if(this.hostAttributes.onclick){
26
- // this.hostAttributes.onclick=eval(this.hostAttributes.onclick);
27
- // }
28
25
  delete this.hostAttributes['btn-style'];
29
26
  delete this.hostAttributes['id'];
30
27
  if (this.wide) {
@@ -33,7 +30,7 @@ const SallaButton = class {
33
30
  }
34
31
  async load() {
35
32
  if (this.loaderPosition == 'center')
36
- this.host.querySelector('.s-button-text').classList.add('s-button-hide');
33
+ this.text.classList.add('s-button-hide');
37
34
  this.host.setAttribute('loading', '');
38
35
  return this.host;
39
36
  }
@@ -48,19 +45,24 @@ const SallaButton = class {
48
45
  this.host.removeAttribute('disabled');
49
46
  }
50
47
  handleVisible(newKind, oldKind) {
48
+ //todo::use united styles
51
49
  this.btn.classList.remove('btn-' + oldKind);
52
50
  this.btn.classList.add('btn-' + newKind);
53
51
  }
54
52
  handleLoading(newVal) {
53
+ //todo::use united styles
55
54
  Helper.toggleElement(this.btn, 'btn--is-loading', 'btn--no-loading', () => newVal);
56
55
  }
57
56
  render() {
58
- return (h("button", Object.assign({ ref: btn => this.btn = btn, disabled: this.disabled }, this.hostAttributes), h("span", { class: "s-button-text" }, h("slot", null)), this.loading ? h("span", { class: {
59
- 'loader loader--small s-button-loader': true,
57
+ return (
58
+ //TODO:: use HOST then fake button behaviours
59
+ 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: {
60
+ //todo::use united styles
61
+ 's-button-loader': true,
60
62
  's-button-loader-start': this.loaderPosition === 'start',
61
63
  's-button-loader-end': this.loaderPosition === 'end',
62
- 's-buton-loader-center': this.loaderPosition === 'center',
63
- } }) : ''));
64
+ 's-button-loader-center': this.loaderPosition === 'center',
65
+ } }) : '')));
64
66
  }
65
67
  get host() { return getElement(this); }
66
68
  static get watchers() { return {
@@ -1,13 +1,12 @@
1
1
  import { r as registerInstance, h, g as getElement } from './index-8966d27f.js';
2
- import { H as Helper } from './Helper-81ac9a8c.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaLocalization = class {
5
5
  constructor(hostRef) {
6
6
  registerInstance(this, hostRef);
7
7
  var _a, _b;
8
- this.language = salla.config.language;
9
- this.currency = salla.config.currency;
10
- //todo::
8
+ this.language = salla.config.get('language', {});
9
+ this.currency = salla.config.get('currency', {});
11
10
  this.languagesTitle = salla.lang.get('common.titles.language');
12
11
  this.currenciesTitle = salla.lang.get('common.titles.currency');
13
12
  this.ok = salla.lang.get('common.elements.ok');
@@ -24,6 +23,8 @@ const SallaLocalization = class {
24
23
  */
25
24
  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>';
26
25
  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>';
26
+ this.languages = Object.values(salla.config.get('languages', {}));
27
+ this.currencies = Object.values(salla.config.get('currencies', {}));
27
28
  }
28
29
  async show() {
29
30
  return this.modal.show();
@@ -31,34 +32,38 @@ const SallaLocalization = class {
31
32
  async hide() {
32
33
  return this.modal.hide();
33
34
  }
35
+ onChangeCurrency(event) {
36
+ this.currency = salla.config.get('currencies.' + event.target.value);
37
+ }
38
+ onChangeLanguage(event) {
39
+ this.language = salla.config.get('languages.' + event.target.value);
40
+ }
34
41
  async submit() {
35
42
  let url;
43
+ console.log('this.currency.code::::', this.currency, this.currency.code);
36
44
  this.btn.load()
37
- .then(() => {
38
- if (this.currency && this.currency.code !== salla.config.currency.code) {
39
- url = window.location.href;
40
- return salla.currency.api.change(this.currency.code);
41
- }
42
- }).then(() => {
43
- if (this.language && this.language.code !== salla.config.language.code) {
44
- url = this.language.url;
45
- }
46
- }).then(() => this.btn.stop())
45
+ .then(() => this.currency.code === salla.config.get('user.currency') || ((url = window.location.href) && salla.currency.api.change(this.currency.code)))
46
+ .then(() => this.language.code === salla.config.get('user.language') || (url = this.language.url))
47
+ .then(() => this.btn.stop())
47
48
  .then(() => this.hide())
48
49
  .then(() => url && (window.location.href = url));
49
50
  }
50
51
  render() {
51
- return (h("salla-modal", { id: "salla-localization", class: "hidden", ref: modal => this.modal = modal }, h("slot", { name: "header" }, h("div", { slot: "header" })), h("div", { class: "s-localization-inner" }, salla.config.languages
52
- ? h("div", { class: "s-localization-section" }, h("label", { class: "s-localization-title" }, this.languagesTitle), h("fieldset", { class: "s-localization-fieldset" }, h("div", { class: "s-localization-section-inner" }, salla.config.languages.map(lang => h("div", { class: "s-localization-item" }, h("input", { class: "s-localization-input", type: "radio", checked: this.language.code == lang.code, onChange: () => this.language = lang, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }), h("div", { id: "language-slot", innerHTML: this.languageSlot
53
- .replace(/\{name\}/g, lang.name)
54
- .replace(/\{code\}/g, lang.code)
55
- .replace(/\{country_code\}/g, lang.country_code) }))))))
56
- : '', salla.config.currencies
57
- ? h("div", { class: "s-localization-section" }, h("label", { class: "s-localization-title" }, this.currenciesTitle), h("fieldset", { class: "s-localization-fieldset" }, h("div", { class: "s-localization-section-inner" }, salla.config.currencies.map(currency => h("div", { class: "s-localization-item" }, h("input", { class: "s-localization-input", type: "radio", name: "currency", checked: this.currency.code == currency.code, onChange: () => this.currency = currency, id: 'currency-' + currency.code, value: currency.code }), h("div", { id: "currency-slot", innerHTML: this.currencySlot
58
- .replace(/\{name\}/g, currency.name)
59
- .replace(/\{code\}/g, currency.code)
60
- .replace(/\{country_code\}/g, currency.country_code) }))))))
61
- : ''), h("p", { slot: "footer" }, h("slot", { name: "footer" }, h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, this.ok)))));
52
+ return (h("salla-modal", { id: "salla-localization", class: "hidden", ref: modal => this.modal = modal, "modal-width": "xs" }, h("div", { slot: "header" }, h("slot", { name: "header" })), h("div", { class: "s-localization-inner" }, this.languages.length > 1 ?
53
+ 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 ?
54
+ this.languages.map(lang => h("div", { class: "s-localization-item" }, h("input", { class: "s-localization-input", type: "radio", checked: this.language.code == lang.code, onChange: () => this.language = lang, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }), h("div", { id: "language-slot", innerHTML: this.languageSlot
55
+ .replace(/\{name\}/g, lang.name)
56
+ .replace(/\{code\}/g, lang.code)
57
+ .replace(/\{country_code\}/g, lang.country_code) }))) :
58
+ h("select", { class: "s-branches-select", name: "currency", onChange: e => this.onChangeLanguage(e) }, this.languages.map(lang => h("option", { value: lang.code, selected: this.language.code == lang.code }, lang.name)))))
59
+ : '', this.currencies.length > 1 ?
60
+ 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 ?
61
+ this.currencies.map(currency => h("div", { class: "s-localization-item" }, h("input", { class: "s-localization-input", type: "radio", name: "currency", checked: this.currency.code == currency.code, onChange: () => this.currency = currency, id: 'currency-' + currency.code, value: currency.code }), h("div", { id: "currency-slot", innerHTML: this.currencySlot
62
+ .replace(/\{name\}/g, currency.name)
63
+ .replace(/\{code\}/g, currency.code)
64
+ .replace(/\{country_code\}/g, currency.country_code) }))) :
65
+ h("select", { class: "s-branches-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, this.currencies.map(currency => h("option", { value: currency.code, selected: this.currency.code == currency.code }, currency.name)))))
66
+ : ''), h("slot", { name: "footer" }, h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, this.ok))));
62
67
  }
63
68
  /**
64
69
  * to reduce dom levels we will move slot data into the parent dom
@@ -0,0 +1,116 @@
1
+ import { r as registerInstance, h, g as getElement } from './index-8966d27f.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+
4
+ const SallaLogin = class {
5
+ constructor(hostRef) {
6
+ registerInstance(this, hostRef);
7
+ this.regType = 'sms';
8
+ this.loginTypeTitle = salla.lang.get('blocks.header.select_login_way');
9
+ this.loginText = salla.lang.get('blocks.header.login');
10
+ this.smsLabel = salla.lang.get('blocks.header.sms');
11
+ this.mobileLabel = salla.lang.get('common.elements.mobile');
12
+ this.emailLabel = salla.lang.get('common.elements.email');
13
+ this.enterText = salla.lang.get('blocks.header.enter');
14
+ this.bySMSText = salla.lang.get('blocks.header.login_by_sms');
15
+ this.byEmailText = salla.lang.get('blocks.header.login_by_email');
16
+ this.backText = salla.lang.get('common.elements.back');
17
+ this.title = this.host.title || salla.lang.get('blocks.header.login');
18
+ this.host.removeAttribute('title');
19
+ salla.auth.event.onVerificationFailed(() => {
20
+ //
21
+ });
22
+ }
23
+ /**
24
+ * @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
25
+ */
26
+ onVerified(event) {
27
+ if (!event.detail.case) {
28
+ console.log('verified but without case!');
29
+ return;
30
+ }
31
+ if (event.detail.case === "new_customer") {
32
+ return this.showTab(this.tab5);
33
+ }
34
+ //TODO::It looks that is this workaround🤔
35
+ if (salla.auth.event.getTypeActionOnVerified() !== 'redirect') {
36
+ return;
37
+ }
38
+ if (event.redirect_url) {
39
+ return window.location.href = event.redirect_url;
40
+ }
41
+ window.location.reload();
42
+ }
43
+ onModalClose() {
44
+ this.showTab(this.tab1);
45
+ }
46
+ async show() {
47
+ return this.modal.show();
48
+ }
49
+ showTab(tab) {
50
+ [this.tab1, this.tab2, this.tab3, this.tab4, this.tab5].map(el => Helper.toggleElement(el, 'visible', 'hidden', () => el == tab));
51
+ if ([this.tab2, this.tab3].includes(tab)) {
52
+ this.regType = tab === this.tab2 ? 'sms' : 'email';
53
+ }
54
+ let isRegistrationTab = tab == this.tab5;
55
+ this.modal.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
56
+ if (!isRegistrationTab) {
57
+ Helper.toggleElement(this.regMobileBlock, 's-hidden', 's-block', () => this.regType === 'sms')
58
+ .toggleElement(this.regEmailBlock, 's-hidden', 's-block', () => this.regType === 'email');
59
+ }
60
+ return this;
61
+ }
62
+ loginByEmail() {
63
+ if (!Helper.isValidEmail(this.email.value)) {
64
+ this.email.classList.add('s-has-error');
65
+ this.email.nextElementSibling['innerText'] = '* ' + salla.lang.get('common.elements.email_is_valid');
66
+ return;
67
+ }
68
+ this.email.nextElementSibling['innerText'] = '';
69
+ this.email.classList.remove('s-has-error');
70
+ salla.auth.api.login({ type: 'email', email: this.email.value })
71
+ .then(() => this.showTab(this.tab4))
72
+ .then(() => (this.tab4.by = 'email') && (this.tab4.url = 'auth/email/verify'))
73
+ .then(() => this.tab4.show({ email: this.email.value }));
74
+ }
75
+ loginBySMS() {
76
+ if (this.mobile.value.length < 6) {
77
+ this.mobile.classList.add('s-has-error');
78
+ this.mobile.nextElementSibling['innerText'] = '* ' + salla.lang.get('mobile_app.strings.incorrect_mobile');
79
+ return;
80
+ }
81
+ this.mobile.nextElementSibling['innerText'] = '';
82
+ this.mobile.classList.remove('s-has-error');
83
+ salla.auth.api.login({ type: 'sms', mobile: this.mobile.value })
84
+ .then(() => this.showTab(this.tab4))
85
+ .then(() => (this.tab4.by = 'sms') && (this.tab4.url = 'auth/mobile/verify'))
86
+ .then(() => this.tab4.show({ mobile: this.mobile.value, country_code: 'SA' }));
87
+ }
88
+ //TODO:: if it's enter, go submit
89
+ typing({ target }) {
90
+ target.type === 'tel' && salla.helpers.digitsOnly(target);
91
+ target.classList.remove('s-has-error');
92
+ target.nextElementSibling.innerText = '';
93
+ }
94
+ newUser() {
95
+ this.tab4.getCode()
96
+ .then(code => salla.auth.api.register({
97
+ first_name: this.firstName.value,
98
+ last_name: this.lastName.value,
99
+ phone: this.regMobile.value || this.mobile.value,
100
+ email: this.regEmail.value || this.email.value,
101
+ country_code: '',
102
+ country_key: '',
103
+ code: code,
104
+ verified_by: this.regType,
105
+ }));
106
+ }
107
+ render() {
108
+ return (h("salla-modal", { id: "salla-login", title: this.title, ref: modal => this.modal = modal, width: "xs" }, 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" }))), h("div", { class: "s-login-tab", ref: tab => this.tab2 = tab }, h("label", { class: "s-login-label" }, this.mobileLabel), h("input", { type: "tel", ref: el => this.mobile = el, onInput: this.typing, placeholder: "5xx xxx xxx", class: "s-login-input s-ltr" }), h("span", { class: "s-login-error-message" }), h("salla-button", { wide: true, onClick: () => this.loginBySMS() }, this.enterText), h("a", { href: "#", onClick: () => this.showTab(this.tab3), class: "s-login-link" }, this.byEmailText)), h("div", { class: "s-login-tab", ref: tab => this.tab3 = tab }, h("label", { class: "s-login-label" }, this.emailLabel), h("input", { 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 }), h("div", { ref: tab => this.tab5 = tab }, h("label", { class: "s-login-label" }, salla.lang.get('blocks.header.your_name')), h("div", { class: "s-login-input-group" }, h("input", { type: "text", class: "s-login-input", ref: el => this.firstName = el, placeholder: salla.lang.get('pages.profile.first_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')))));
109
+ }
110
+ componentDidRender() {
111
+ this.showTab(this.tab1);
112
+ }
113
+ get host() { return getElement(this); }
114
+ };
115
+
116
+ export { SallaLogin as S };
@@ -0,0 +1,127 @@
1
+ import { r as registerInstance, h, g as getElement } from './index-8966d27f.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
+
4
+ const sallaLoginCss = "salla-verify{display:block}";
5
+
6
+ const SallaLogin = class {
7
+ constructor(hostRef) {
8
+ registerInstance(this, hostRef);
9
+ this.inputChanged = (event) => {
10
+ console.log('input changed: ', event.target.value);
11
+ };
12
+ this.regType = 'sms';
13
+ this.isLoginByMail = true;
14
+ this.loginTypeTitle = salla.lang.get('blocks.header.select_login_way');
15
+ this.loginText = salla.lang.get('blocks.header.login');
16
+ this.smsLabel = salla.lang.get('blocks.header.sms');
17
+ this.mobileLabel = salla.lang.get('common.elements.mobile');
18
+ this.emailLabel = salla.lang.get('common.elements.email');
19
+ this.enterText = salla.lang.get('blocks.header.enter');
20
+ this.bySMSText = salla.lang.get('blocks.header.login_by_sms');
21
+ this.byEmailText = salla.lang.get('blocks.header.login_by_email');
22
+ this.backText = salla.lang.get('common.elements.back');
23
+ this.title = this.host.title || salla.lang.get('blocks.header.login');
24
+ this.host.removeAttribute('title');
25
+ salla.auth.event.onVerificationFailed(() => {
26
+ //
27
+ });
28
+ }
29
+ /**
30
+ * @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
31
+ */
32
+ onVerified(event) {
33
+ if (!event.detail.case) {
34
+ console.log('verified but without case!');
35
+ return;
36
+ }
37
+ if (event.detail.case === "new_customer") {
38
+ return this.showTab(this.tab5);
39
+ }
40
+ //TODO::It looks that is this workaround🤔
41
+ if (salla.auth.event.getTypeActionOnVerified() !== 'redirect') {
42
+ return;
43
+ }
44
+ if (event.redirect_url) {
45
+ return window.location.href = event.redirect_url;
46
+ }
47
+ window.location.reload();
48
+ }
49
+ onbackClicked() {
50
+ this.regType == 'sms' ? this.showTab(this.tab2) : this.showTab(this.tab3);
51
+ }
52
+ async show() {
53
+ this.showTab(this.isLoginByMail ? this.tab1 : this.tab2);
54
+ return this.modal.show();
55
+ }
56
+ showTab(tab) {
57
+ [this.tab1, this.tab2, this.tab3, this.tab4, this.tab5].map(el => Helper.toggleElement(el, 'visible', 'hidden', () => el == tab));
58
+ 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);
59
+ setTimeout(() => { this.host.querySelector('.s-login-wrapper').setAttribute('style', 'height:' + (tab === null || tab === void 0 ? void 0 : tab.scrollHeight) + 'px'); });
60
+ if ([this.tab2, this.tab3].includes(tab)) {
61
+ this.regType = tab === this.tab2 ? 'sms' : 'email';
62
+ this.backText = this.regType == 'sms' ? 'تغيير رقم الهاتف' : 'تغيير البريد';
63
+ }
64
+ let isRegistrationTab = tab == this.tab5;
65
+ this.modal.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
66
+ if (!isRegistrationTab) {
67
+ Helper.toggleElement(this.regMobileBlock, 's-hidden', 's-block', () => this.regType === 'sms')
68
+ .toggleElement(this.regEmailBlock, 's-hidden', 's-block', () => this.regType === 'email');
69
+ }
70
+ return this;
71
+ }
72
+ loginByEmail() {
73
+ if (!Helper.isValidEmail(this.email.value)) {
74
+ this.email.classList.add('s-has-error');
75
+ this.email.nextElementSibling['innerText'] = '* ' + salla.lang.get('common.elements.email_is_valid');
76
+ return;
77
+ }
78
+ this.email.nextElementSibling['innerText'] = '';
79
+ this.email.classList.remove('s-has-error');
80
+ salla.auth.api.login({ type: 'email', email: this.email.value })
81
+ .then(() => this.showTab(this.tab4))
82
+ .then(() => (this.tab4.by = 'email') && (this.tab4.url = 'auth/email/verify'))
83
+ .then(() => this.tab4.show({ email: this.email.value }));
84
+ }
85
+ loginBySMS() {
86
+ if (this.mobile.value.length < 6) {
87
+ this.mobile.classList.add('s-has-error');
88
+ this.mobile.nextElementSibling['innerText'] = '* ' + salla.lang.get('mobile_app.strings.incorrect_mobile');
89
+ return;
90
+ }
91
+ this.mobile.nextElementSibling['innerText'] = '';
92
+ this.mobile.classList.remove('s-has-error');
93
+ salla.auth.api.login({ type: 'sms', mobile: this.mobile.value })
94
+ .then(() => this.showTab(this.tab4))
95
+ .then(() => (this.tab4.by = 'sms') && (this.tab4.url = 'auth/mobile/verify'))
96
+ .then(() => this.tab4.show({ mobile: this.mobile.value, country_code: 'SA' }));
97
+ }
98
+ //TODO:: if it's enter, go submit
99
+ typing({ target }) {
100
+ target.type === 'tel' && salla.helpers.digitsOnly(target);
101
+ target.classList.remove('s-has-error');
102
+ target.nextElementSibling.innerText = '';
103
+ }
104
+ newUser() {
105
+ this.tab4.getCode()
106
+ .then(code => salla.auth.api.register({
107
+ first_name: this.firstName.value,
108
+ last_name: this.lastName.value,
109
+ phone: this.regMobile.value || this.mobile.value,
110
+ email: this.regEmail.value || this.email.value,
111
+ country_code: '',
112
+ country_key: '',
113
+ code: code,
114
+ verified_by: this.regType,
115
+ }));
116
+ }
117
+ render() {
118
+ 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 ?
119
+ 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" })))
120
+ : '', h("div", { class: "s-login-tab", ref: tab => this.tab2 = tab }, h("label", { class: "s-login-label" }, this.mobileLabel), 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 ?
121
+ 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'))))));
122
+ }
123
+ get host() { return getElement(this); }
124
+ };
125
+ SallaLogin.style = sallaLoginCss;
126
+
127
+ export { SallaLogin as S };
@@ -1,2 +1,3 @@
1
- export { S as salla_login } from './salla-login-4d620368.js';
1
+ export { S as salla_login } from './salla-login-b92c73dc.js';
2
2
  import './index-8966d27f.js';
3
+ import './Helper-d07ebbc7.js';
@@ -1,17 +1,20 @@
1
1
  import { r as registerInstance, f as createEvent, h, e as Host, g as getElement } from './index-8966d27f.js';
2
- import { H as Helper } from './Helper-81ac9a8c.js';
2
+ import { H as Helper } from './Helper-d07ebbc7.js';
3
3
 
4
4
  const SallaModal = class {
5
5
  constructor(hostRef) {
6
6
  registerInstance(this, hostRef);
7
- this.ready = createEvent(this, "ready", 7);
8
- this.close = createEvent(this, "close", 7);
7
+ this.modalOpened = createEvent(this, "modalOpened", 7);
8
+ this.modalClosed = createEvent(this, "modalClosed", 7);
9
9
  var _a;
10
+ //todo:: unite three colors (error, success, primary) in one prop
10
11
  this.error = false;
11
12
  this.success = false;
13
+ this.primary = false;
12
14
  this.isClosable = true;
13
- this.modalWidth = 'w-96'; //todo use friendly names
15
+ this.width = 'md';
14
16
  this.visible = false;
17
+ this.isLoading = false;
15
18
  this.subTitleFirst = false;
16
19
  this.subTitle = '';
17
20
  this.icon = '';
@@ -21,17 +24,17 @@ const SallaModal = class {
21
24
  salla.event.on('modal::close', btn => btn.dataset.target == this.host.id && this.hide());
22
25
  this.title = this.host.title;
23
26
  this.host.removeAttribute('title');
24
- (_a = Helper.getElement('[slot=body]')) === null || _a === void 0 ? void 0 : _a.classList.add('s-modal-body');
27
+ (_a = Helper.getElement('[slot=body]')) === null || _a === void 0 ? void 0 : _a.classList.add('s-modal-body', 's-modal-' + this.width);
25
28
  }
26
29
  handleVisible(newValue) {
27
30
  if (!newValue) {
28
31
  this.toggleModal(false);
29
- this.close.emit();
32
+ this.modalClosed.emit();
30
33
  return;
31
34
  }
32
35
  this.host.classList.remove('hidden');
33
36
  setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
34
- this.ready.emit();
37
+ this.modalOpened.emit();
35
38
  }
36
39
  async show() {
37
40
  this.host.setAttribute('visible', '');
@@ -45,10 +48,20 @@ const SallaModal = class {
45
48
  this.title = title;
46
49
  return this.host;
47
50
  }
51
+ async loading() {
52
+ this.isLoading = true;
53
+ return this.host;
54
+ }
55
+ async stopLoading() {
56
+ this.isLoading = false;
57
+ return this.host;
58
+ }
48
59
  toggleModal(isOpen) {
49
- Helper.toggleElement(this.host.querySelector('.s-modal-body'), 's-modal-entering', 's-modal-leaving', () => isOpen)
50
- .toggleElement(this.host.querySelector('[slot=body]'), 's-modal-entering', 's-modal-leaving', () => isOpen)
60
+ Helper
61
+ // .toggleElement(this.host.querySelector('.s-modal-body'), 's-modal-entering', 's-modal-leaving', () => isOpen)
62
+ .toggleElement(this.host.querySelector('[slot=body]') || this.host, 's-modal-entering', 's-modal-leaving', () => isOpen)
51
63
  .toggleElement(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
64
+ //todo:: use united class names
52
65
  .toggleElement(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
53
66
  if (!isOpen) {
54
67
  setTimeout(() => this.host.classList.add('hidden'), 350);
@@ -63,24 +76,33 @@ const SallaModal = class {
63
76
  //todo:: pref for each modal
64
77
  render() {
65
78
  this.host.id = this.host.id || 'salla-modal';
66
- return (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" }, "\u200B"), h("slot", { name: "body" }, h("div", { class: 's-modal-body ' + this.modalWidth }, h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.icon != '' || this.imageIcon != '' } }, this.isClosable ?
67
- h("button", { class: "s-modal-close cursor-pointer", onClick: () => this.closeModal(), type: "button" }, h("span", { class: "sicon-cancel" }))
68
- : '', this.error || this.success || this.icon
69
- ? h("div", { class: {
70
- 's-modal-icon': true,
71
- 's-modal-bg-error': this.error,
72
- 's-modal-bg-success': this.success,
73
- 's-modal-bg-normal': !this.error && !this.success
74
- } }, h("i", { class: {
75
- [this.icon]: true,
76
- 's-modal-text-error': this.error,
77
- 's-modal-text-success': this.success,
78
- } }))
79
- : this.imageIcon ?
80
- h("img", { class: "s-modal-header-img", src: this.imageIcon })
81
- : '', this.title || this.subTitle ?
82
- 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 }))
83
- : ''), h("slot", null), h("slot", { name: "footer" }))))));
79
+ return (
80
+ //todo:: use suitable class name instead of hidden
81
+ 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" }, "\u200B"), h("slot", { name: "body" }, h("div", { class: 's-modal-body ' + 's-modal-' + this.width, slot: "body" }, this.isLoading
82
+ ? h("span", null, "Loading...")
83
+ : [h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.icon != '' || this.imageIcon != '' } }, this.isClosable ?
84
+ //todo:: remove cursor-pointer
85
+ h("button", { class: "s-modal-close cursor-pointer", onClick: () => this.closeModal(), type: "button" }, h("span", { class: "sicon-cancel" }))
86
+ : '', this.error || this.success || this.icon
87
+ ? h("div", { class: {
88
+ 's-modal-icon': true,
89
+ 's-modal-bg-error': this.error,
90
+ 's-modal-bg-success': this.success,
91
+ 's-modal-bg-normal': !this.error && !this.success,
92
+ 's-modal-bg-primary': this.primary
93
+ } }, h("i", { class: {
94
+ [this.icon]: true,
95
+ 's-modal-text-error': this.error,
96
+ 's-modal-text-success': this.success,
97
+ } }))
98
+ : this.imageIcon ?
99
+ h("img", { class: "s-modal-header-img", src: this.imageIcon })
100
+ : '', this.title || this.subTitle ?
101
+ 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 }))
102
+ : ''),
103
+ h("slot", null),
104
+ h("slot", { name: "footer" })
105
+ ])))));
84
106
  }
85
107
  get host() { return getElement(this); }
86
108
  static get watchers() { return {