@salla.sa/twilight-components 1.0.28 → 1.0.31

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 (38) hide show
  1. package/dist/cjs/index.cjs.js +2 -3
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/salla-branches.cjs.entry.js +2 -5
  4. package/dist/cjs/{salla-button_5.cjs.entry.js → salla-button_7.cjs.entry.js} +82 -4
  5. package/dist/cjs/{salla-login-15aff630.js → salla-search-257561ac.js} +74 -0
  6. package/dist/cjs/twilight-components.cjs.js +1 -1
  7. package/dist/collection/components/salla-branches/salla-branches.js +2 -5
  8. package/dist/collection/components/salla-tel-input/salla-tel-input.js +3 -3
  9. package/dist/collection/plugins/tailwind-theme/index.js +16 -1
  10. package/dist/esm/index.js +1 -2
  11. package/dist/esm/loader.js +1 -1
  12. package/dist/esm/salla-branches.entry.js +2 -5
  13. package/dist/esm/{salla-button_5.entry.js → salla-button_7.entry.js} +80 -4
  14. package/dist/esm/{salla-login-e6e86a3d.js → salla-search-c30c12ef.js} +74 -1
  15. package/dist/esm/twilight-components.js +1 -1
  16. package/dist/twilight-components/index.esm.js +1 -1
  17. package/dist/twilight-components/{p-f97ea1f7.js → p-1ec2f128.js} +1 -1
  18. package/dist/twilight-components/p-8d941a1f.entry.js +1 -0
  19. package/dist/twilight-components/p-9cabc8a4.entry.js +1 -0
  20. package/dist/twilight-components/twilight-components.esm.js +1 -1
  21. package/example/assets/tailwind.css +3 -0
  22. package/example/dist/tailwind.css +2891 -0
  23. package/example/index.html +77 -0
  24. package/example/package-lock.json +1073 -0
  25. package/example/package.json +17 -0
  26. package/example/tailwind.config.js +48 -0
  27. package/package.json +3 -2
  28. package/dist/cjs/salla-localization.cjs.entry.js +0 -84
  29. package/dist/cjs/salla-search-7d0fe40b.js +0 -79
  30. package/dist/cjs/salla-search.cjs.entry.js +0 -11
  31. package/dist/esm/salla-localization.entry.js +0 -80
  32. package/dist/esm/salla-search-66aae389.js +0 -77
  33. package/dist/esm/salla-search.entry.js +0 -3
  34. package/dist/twilight-components/p-079df88b.js +0 -1
  35. package/dist/twilight-components/p-54f90d2b.entry.js +0 -1
  36. package/dist/twilight-components/p-5bf5ce53.entry.js +0 -1
  37. package/dist/twilight-components/p-8305cef7.entry.js +0 -1
  38. package/dist/twilight-components/p-b195e28c.entry.js +0 -1
@@ -2,12 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const sallaLogin = require('./salla-login-15aff630.js');
6
- const sallaSearch = require('./salla-search-7d0fe40b.js');
5
+ const sallaSearch = require('./salla-search-257561ac.js');
7
6
  require('./index-714023c8.js');
8
7
  require('./Helper-fcea994c.js');
9
8
 
10
9
 
11
10
 
12
- exports.SallaLogin = sallaLogin.SallaLogin;
11
+ exports.SallaLogin = sallaSearch.SallaLogin;
13
12
  exports.SallaSearch = sallaSearch.SallaSearch;
@@ -14,7 +14,7 @@ const patchEsm = () => {
14
14
  const defineCustomElements = (win, options) => {
15
15
  if (typeof window === 'undefined') return Promise.resolve();
16
16
  return patchEsm().then(() => {
17
- return index.bootstrapLazy([["salla-button_5.cjs",[[0,"salla-login",{"isEmailAllowed":[4,"is-email-allowed"],"isMobileAllowed":[4,"is-mobile-allowed"],"isEmailRequired":[4,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"show":[64]},[[0,"verified","onVerified"],[0,"backClicked","onbackClicked"]]],[0,"salla-verify",{"withoutModal":[4,"without-modal"],"url":[513],"by":[1],"isShowBack":[4,"is-show-back"],"autoReload":[4,"auto-reload"],"title":[32],"getCode":[64],"show":[64]}],[0,"salla-tel-input",{"mobile":[1025],"countryCode":[1025,"country-code"],"countryKey":[1025,"country-key"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"btnStyle":[513,"btn-style"],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"wide":[4],"load":[64],"setText":[64],"stop":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"error":[4],"success":[4],"primary":[4],"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"imageIcon":[1,"image-icon"],"title":[32],"show":[64],"hide":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-product-availability.cjs",[[4,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32]}]]],["salla-branches.cjs",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"ok":[32],"show":[64],"hide":[64]}]]],["salla-localization.cjs",[[4,"salla-localization",{"languagesTitle":[32],"currenciesTitle":[32],"ok":[32],"show":[64],"hide":[64],"submit":[64]}]]],["salla-offer.cjs",[[0,"salla-offer",{"offer":[32],"show":[64]}]]],["salla-rating.cjs",[[0,"salla-rating",{"order":[32],"show":[64],"hide":[64]}]]],["salla-search.cjs",[[0,"salla-search",{"results":[32],"placeholder":[32],"noResultsText":[32]},[[0,"modalOpened","onModalOpen"],[0,"modalClosed","onModalClose"]]]]],["salla-infinite-scroll.cjs",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[4],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]]], options);
17
+ return index.bootstrapLazy([["salla-button_7.cjs",[[0,"salla-login",{"isEmailAllowed":[4,"is-email-allowed"],"isMobileAllowed":[4,"is-mobile-allowed"],"isEmailRequired":[4,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"show":[64]},[[0,"verified","onVerified"],[0,"backClicked","onbackClicked"]]],[4,"salla-localization",{"languagesTitle":[32],"currenciesTitle":[32],"ok":[32],"show":[64],"hide":[64],"submit":[64]}],[0,"salla-search",{"results":[32],"placeholder":[32],"noResultsText":[32]},[[0,"modalOpened","onModalOpen"],[0,"modalClosed","onModalClose"]]],[0,"salla-verify",{"withoutModal":[4,"without-modal"],"url":[513],"by":[1],"isShowBack":[4,"is-show-back"],"autoReload":[4,"auto-reload"],"title":[32],"getCode":[64],"show":[64]}],[0,"salla-tel-input",{"mobile":[1025],"countryCode":[1025,"country-code"],"countryKey":[1025,"country-key"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"btnStyle":[513,"btn-style"],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"wide":[4],"load":[64],"setText":[64],"stop":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"error":[4],"success":[4],"primary":[4],"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"imageIcon":[1,"image-icon"],"title":[32],"show":[64],"hide":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-product-availability.cjs",[[4,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32]}]]],["salla-branches.cjs",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"ok":[32],"show":[64],"hide":[64]}]]],["salla-offer.cjs",[[0,"salla-offer",{"offer":[32],"show":[64]}]]],["salla-rating.cjs",[[0,"salla-rating",{"order":[32],"show":[64],"hide":[64]}]]],["salla-infinite-scroll.cjs",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[4],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]]], options);
18
18
  });
19
19
  };
20
20
 
@@ -6,14 +6,11 @@ const index = require('./index-714023c8.js');
6
6
 
7
7
  const sallaBranchesCss = ":host{display:block}";
8
8
 
9
- let engine = require('store/src/store-engine');
10
- let storages = require('store/storages/sessionStorage');
11
- let sessionStore = engine.createStore(storages);
12
9
  const SallaBranches = class {
13
10
  constructor(hostRef) {
14
11
  index.registerInstance(this, hostRef);
15
12
  this.open = false;
16
- this.isOpenedBefore = sessionStore.get("branch-choosed-before");
13
+ this.isOpenedBefore = salla.localData.get("branch-choosed-before");
17
14
  this.displayAs = 'default';
18
15
  this.browseProductsFrom = 'all';
19
16
  this.branches = [
@@ -59,7 +56,7 @@ const SallaBranches = class {
59
56
  this.btn.load().then(() => {
60
57
  setTimeout(() => location.reload(), 2000);
61
58
  });
62
- sessionStore.set("branch-choosed-before", true);
59
+ salla.localData.set("branch-choosed-before", true);
63
60
  this.show();
64
61
  setTimeout(() => {
65
62
  this.current = this.selected;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-714023c8.js');
6
6
  const Helper = require('./Helper-fcea994c.js');
7
- const sallaLogin = require('./salla-login-15aff630.js');
7
+ const sallaSearch = require('./salla-search-257561ac.js');
8
8
 
9
9
  const sallaButtonCss = ":host{display:block}";
10
10
 
@@ -83,6 +83,82 @@ const SallaButton = class {
83
83
  };
84
84
  SallaButton.style = sallaButtonCss;
85
85
 
86
+ const SallaLocalization = class {
87
+ constructor(hostRef) {
88
+ index.registerInstance(this, hostRef);
89
+ var _a, _b;
90
+ this.language = salla.config.get('language', {});
91
+ this.currency = salla.config.get('currency', {});
92
+ Helper.Helper.setHost(this.host);
93
+ salla.event.on('localization::show', () => this.show());
94
+ salla.event.on('languages::translations.loaded', () => {
95
+ this.languagesTitle = salla.lang.get('common.titles.language');
96
+ this.currenciesTitle = salla.lang.get('common.titles.currency');
97
+ this.ok = salla.lang.get('common.elements.ok');
98
+ });
99
+ /**
100
+ * letting developer to insert his own slot like:
101
+ * <salla-localization>
102
+ * <div slot="language">...{name}....</div>
103
+ * <div slot="currency">...{name}....</div>
104
+ * </salla-localization>
105
+ * Because scoped templates not supported in stencil );
106
+ * we made a workaround to pass language & currency attributes, then replace names in rendering
107
+ */
108
+ 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>';
109
+ 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>';
110
+ this.languages = Object.values(salla.config.get('languages', {}));
111
+ this.currencies = Object.values(salla.config.get('currencies', {}));
112
+ }
113
+ async show() {
114
+ return this.modal.show();
115
+ }
116
+ async hide() {
117
+ return this.modal.hide();
118
+ }
119
+ onChangeCurrency(event) {
120
+ this.currency = salla.config.get('currencies.' + event.target.value);
121
+ }
122
+ onChangeLanguage(event) {
123
+ this.language = salla.config.get('languages.' + event.target.value);
124
+ }
125
+ async submit() {
126
+ let url;
127
+ console.log('this.currency.code::::', this.currency, this.currency.code);
128
+ this.btn.load()
129
+ .then(() => this.currency.code === salla.config.get('user.currency') || ((url = window.location.href) && salla.currency.api.change(this.currency.code)))
130
+ .then(() => this.language.code === salla.config.get('user.language') || (url = this.language.url))
131
+ .then(() => this.btn.stop())
132
+ .then(() => this.hide())
133
+ .then(() => url && (window.location.href = url));
134
+ }
135
+ render() {
136
+ return (index.h("salla-modal", { id: "salla-localization", class: "hidden", ref: modal => this.modal = modal, width: "xs" }, index.h("div", { slot: "header" }, index.h("slot", { name: "header" })), index.h("div", { class: "s-localization-inner" }, this.languages.length > 1 ?
137
+ 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 ?
138
+ this.languages.map(lang => index.h("div", { class: "s-localization-item" }, index.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 }), index.h("div", { id: "language-slot", innerHTML: this.languageSlot
139
+ .replace(/\{name\}/g, lang.name)
140
+ .replace(/\{code\}/g, lang.code)
141
+ .replace(/\{country_code\}/g, lang.country_code) }))) :
142
+ index.h("select", { class: "s-branches-select", name: "currency", onChange: e => this.onChangeLanguage(e) }, this.languages.map(lang => index.h("option", { value: lang.code, selected: this.language.code == lang.code }, lang.name)))))
143
+ : '', this.currencies.length > 1 ?
144
+ 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 ?
145
+ 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.code == currency.code, onChange: () => this.currency = currency, id: 'currency-' + currency.code, value: currency.code }), index.h("div", { id: "currency-slot", innerHTML: this.currencySlot
146
+ .replace(/\{name\}/g, currency.name)
147
+ .replace(/\{code\}/g, currency.code)
148
+ .replace(/\{country_code\}/g, currency.country_code) }))) :
149
+ index.h("select", { class: "s-branches-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, this.currencies.map(currency => index.h("option", { value: currency.code, selected: this.currency.code == currency.code }, currency.name)))))
150
+ : ''), index.h("slot", { name: "footer" }, index.h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, this.ok))));
151
+ }
152
+ /**
153
+ * to reduce dom levels we will move slot data into the parent dom
154
+ */
155
+ componentDidRender() {
156
+ this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
157
+ this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
158
+ }
159
+ get host() { return index.getElement(this); }
160
+ };
161
+
86
162
  const sallaModalCss = "";
87
163
 
88
164
  const SallaModal = class {
@@ -1574,8 +1650,8 @@ const SallaTelInput = class {
1574
1650
  constructor(hostRef) {
1575
1651
  index.registerInstance(this, hostRef);
1576
1652
  this.enterClicked = index.createEvent(this, "enterClicked", 7);
1577
- this.countryCode = "SA";
1578
- this.countryKey = "+966";
1653
+ this.countryCode = salla.config.get('user.country_code', 'SA');
1654
+ this.countryKey = "+966"; //TODO:: why we need it
1579
1655
  this.countryCodeLabel = salla.lang.get('common.country_code');
1580
1656
  this.mobileLabel = salla.lang.get('common.elements.mobile');
1581
1657
  this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
@@ -1786,8 +1862,10 @@ const SallaVerify = class {
1786
1862
  get host() { return index.getElement(this); }
1787
1863
  };
1788
1864
 
1789
- exports.salla_login = sallaLogin.SallaLogin;
1865
+ exports.salla_login = sallaSearch.SallaLogin;
1866
+ exports.salla_search = sallaSearch.SallaSearch;
1790
1867
  exports.salla_button = SallaButton;
1868
+ exports.salla_localization = SallaLocalization;
1791
1869
  exports.salla_modal = SallaModal;
1792
1870
  exports.salla_tel_input = SallaTelInput;
1793
1871
  exports.salla_verify = SallaVerify;
@@ -184,4 +184,78 @@ const SallaLogin = class {
184
184
  };
185
185
  SallaLogin.style = sallaLoginCss;
186
186
 
187
+ const sallaSearchCss = "#s-search-modal .s-modal-wrapper{align-items:flex-start;padding:0}#s-search-modal .s-modal-spacer{display:inline}#s-search-modal .s-modal-body{padding:0;max-width:90%;margin-top:3.2rem;border-radius:0.5rem}#s-search-modal .s-modal-close{top:1rem}";
188
+
189
+ const SallaSearch = class {
190
+ constructor(hostRef) {
191
+ index.registerInstance(this, hostRef);
192
+ var _a;
193
+ Helper.Helper.setHost(this.host);
194
+ this.productSlot = ((_a = Helper.Helper.getElement('[slot="product"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || this.getDefaultProductSlot();
195
+ salla.event.on('search::show', () => this.modal.show());
196
+ salla.event.on('languages::translations.loaded', () => {
197
+ this.placeholder = salla.lang.get('blocks.header.search_placeholder');
198
+ this.noResultsText = salla.lang.get('common.elements.no_options');
199
+ });
200
+ }
201
+ onModalOpen() {
202
+ this.modal.querySelector('.s-search-input').focus();
203
+ }
204
+ onModalClose() {
205
+ this.modal.querySelector('.s-search-input').value = '';
206
+ this.results = undefined;
207
+ this.afterSearching();
208
+ }
209
+ getDefaultProductSlot() {
210
+ return '<div class="s-search-product-image-container">' +
211
+ ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
212
+ '</div>' +
213
+ '<div class="s-search-product-details">' +
214
+ ' <div class="s-search-product-name">{name}</div> <div class="s-search-product-price">{price}</div>' +
215
+ '</div>';
216
+ }
217
+ //todo:: reset data when closing
218
+ search(e) {
219
+ Helper.Helper.hideElement(this.noResults);
220
+ if (e.target.value.length === 0) {
221
+ this.results = undefined;
222
+ this.afterSearching();
223
+ return;
224
+ }
225
+ if (e.target.value.length <= 2) {
226
+ return;
227
+ }
228
+ //run loading spinner or stop it
229
+ Helper.Helper.toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => true);
230
+ salla.search.api.search(e.target.value)
231
+ .then(response => this.results = response)
232
+ .catch(err => err !== 'Query Same As Previous!' ? this.results = undefined : null)
233
+ .finally(() => this.afterSearching(/*isEmpty*/ false));
234
+ }
235
+ afterSearching(isEmpty = true) {
236
+ var _a;
237
+ this.noResults.style.display = isEmpty || ((_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length) > 0 ? 'none' : 'block';
238
+ Helper.Helper.toggleElement(this.container, 's-search-container-open', 'no-results', () => { var _a; return (_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length; })
239
+ .toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => false); //stop searching anime
240
+ salla.search.api.previousQuery = ''; //avoid having error 'Query Same As Previous' after reopen modal;
241
+ }
242
+ render() {
243
+ var _a;
244
+ return (index.h("salla-modal", { position: "top", id: "s-search-modal", ref: modal => this.modal = modal }, index.h("div", { class: "s-search-container", ref: container => this.container = container }, index.h("input", { class: "s-search-input", type: "text", placeholder: this.placeholder, onInput: e => this.search(e) }), index.h("span", { class: "s-search-icon" }, index.h("i", { class: "sicon-search", ref: el => this.searchIcon = el })), index.h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
245
+ _a.data.map(item => index.h("a", { href: item.url, class: "s-search-product", innerHTML: this.productSlot
246
+ .replace(/\{name\}/g, item.name)
247
+ .replace(/\{price\}/g, item.price) //todo:: get discounted price too
248
+ .replace(/\{image\}/g, item.image_url) })), index.h("p", { ref: el => this.noResults = el, class: "s-search-no-results" }, this.noResultsText)))));
249
+ }
250
+ /**
251
+ * Run it one time after load
252
+ */
253
+ componentDidLoad() {
254
+ this.afterSearching();
255
+ }
256
+ get host() { return index.getElement(this); }
257
+ };
258
+ SallaSearch.style = sallaSearchCss;
259
+
187
260
  exports.SallaLogin = SallaLogin;
261
+ exports.SallaSearch = SallaSearch;
@@ -15,5 +15,5 @@ const patchBrowser = () => {
15
15
  };
16
16
 
17
17
  patchBrowser().then(options => {
18
- return index.bootstrapLazy([["salla-button_5.cjs",[[0,"salla-login",{"isEmailAllowed":[4,"is-email-allowed"],"isMobileAllowed":[4,"is-mobile-allowed"],"isEmailRequired":[4,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"show":[64]},[[0,"verified","onVerified"],[0,"backClicked","onbackClicked"]]],[0,"salla-verify",{"withoutModal":[4,"without-modal"],"url":[513],"by":[1],"isShowBack":[4,"is-show-back"],"autoReload":[4,"auto-reload"],"title":[32],"getCode":[64],"show":[64]}],[0,"salla-tel-input",{"mobile":[1025],"countryCode":[1025,"country-code"],"countryKey":[1025,"country-key"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"btnStyle":[513,"btn-style"],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"wide":[4],"load":[64],"setText":[64],"stop":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"error":[4],"success":[4],"primary":[4],"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"imageIcon":[1,"image-icon"],"title":[32],"show":[64],"hide":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-product-availability.cjs",[[4,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32]}]]],["salla-branches.cjs",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"ok":[32],"show":[64],"hide":[64]}]]],["salla-localization.cjs",[[4,"salla-localization",{"languagesTitle":[32],"currenciesTitle":[32],"ok":[32],"show":[64],"hide":[64],"submit":[64]}]]],["salla-offer.cjs",[[0,"salla-offer",{"offer":[32],"show":[64]}]]],["salla-rating.cjs",[[0,"salla-rating",{"order":[32],"show":[64],"hide":[64]}]]],["salla-search.cjs",[[0,"salla-search",{"results":[32],"placeholder":[32],"noResultsText":[32]},[[0,"modalOpened","onModalOpen"],[0,"modalClosed","onModalClose"]]]]],["salla-infinite-scroll.cjs",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[4],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]]], options);
18
+ return index.bootstrapLazy([["salla-button_7.cjs",[[0,"salla-login",{"isEmailAllowed":[4,"is-email-allowed"],"isMobileAllowed":[4,"is-mobile-allowed"],"isEmailRequired":[4,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"show":[64]},[[0,"verified","onVerified"],[0,"backClicked","onbackClicked"]]],[4,"salla-localization",{"languagesTitle":[32],"currenciesTitle":[32],"ok":[32],"show":[64],"hide":[64],"submit":[64]}],[0,"salla-search",{"results":[32],"placeholder":[32],"noResultsText":[32]},[[0,"modalOpened","onModalOpen"],[0,"modalClosed","onModalClose"]]],[0,"salla-verify",{"withoutModal":[4,"without-modal"],"url":[513],"by":[1],"isShowBack":[4,"is-show-back"],"autoReload":[4,"auto-reload"],"title":[32],"getCode":[64],"show":[64]}],[0,"salla-tel-input",{"mobile":[1025],"countryCode":[1025,"country-code"],"countryKey":[1025,"country-key"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"btnStyle":[513,"btn-style"],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"wide":[4],"load":[64],"setText":[64],"stop":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"error":[4],"success":[4],"primary":[4],"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"imageIcon":[1,"image-icon"],"title":[32],"show":[64],"hide":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-product-availability.cjs",[[4,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32]}]]],["salla-branches.cjs",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"ok":[32],"show":[64],"hide":[64]}]]],["salla-offer.cjs",[[0,"salla-offer",{"offer":[32],"show":[64]}]]],["salla-rating.cjs",[[0,"salla-rating",{"order":[32],"show":[64],"hide":[64]}]]],["salla-infinite-scroll.cjs",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[4],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]]], options);
19
19
  });
@@ -1,11 +1,8 @@
1
1
  import { Component, h, Prop, Method, State, Element } from "@stencil/core";
2
- let engine = require('store/src/store-engine');
3
- let storages = require('store/storages/sessionStorage');
4
- let sessionStore = engine.createStore(storages);
5
2
  export class SallaBranches {
6
3
  constructor() {
7
4
  this.open = false;
8
- this.isOpenedBefore = sessionStore.get("branch-choosed-before");
5
+ this.isOpenedBefore = salla.localData.get("branch-choosed-before");
9
6
  this.displayAs = 'default';
10
7
  this.browseProductsFrom = 'all';
11
8
  this.branches = [
@@ -51,7 +48,7 @@ export class SallaBranches {
51
48
  this.btn.load().then(() => {
52
49
  setTimeout(() => location.reload(), 2000);
53
50
  });
54
- sessionStore.set("branch-choosed-before", true);
51
+ salla.localData.set("branch-choosed-before", true);
55
52
  this.show();
56
53
  setTimeout(() => {
57
54
  this.current = this.selected;
@@ -3,8 +3,8 @@ import TelInput from "intl-tel-input";
3
3
  import Helper from "../../Helpers/Helper";
4
4
  export class SallaTelInput {
5
5
  constructor() {
6
- this.countryCode = "SA";
7
- this.countryKey = "+966";
6
+ this.countryCode = salla.config.get('user.country_code', 'SA');
7
+ this.countryKey = "+966"; //TODO:: why we need it
8
8
  this.countryCodeLabel = salla.lang.get('common.country_code');
9
9
  this.mobileLabel = salla.lang.get('common.elements.mobile');
10
10
  this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
@@ -121,7 +121,7 @@ export class SallaTelInput {
121
121
  },
122
122
  "attribute": "country-code",
123
123
  "reflect": false,
124
- "defaultValue": "\"SA\""
124
+ "defaultValue": "salla.config.get('user.country_code', 'SA')"
125
125
  },
126
126
  "countryKey": {
127
127
  "type": "string",
@@ -8,13 +8,28 @@ module.exports = require('tailwindcss/plugin').withOptions(() => {
8
8
  '.error' : {},
9
9
  '.search-box' : {},
10
10
  '.spinner-loader-wrap': {},
11
+ // '.me-3' : {},
12
+ // '.ms-3' : {},
13
+ // '.pe-4' : {},
14
+ // '.ps-5' : {},
15
+ // '.space-s-3' : {},
16
+ // '.end-4' : {},
17
+
18
+ '.has-error' : {'@apply border-red-400 focus:border-red-500': {}},
19
+ '.rounded-icon' : {'@apply w-16 h-16 flex justify-center items-center rounded-full text-3xl': {}},
20
+ '.form-input' : {'@apply w-full h-10 transition-colors duration-300 focus:ring-transparent focus:border-primary dark:focus:border-primary sm:text-sm border-border-color dark:bg-gray-600 dark:border-gray-600 rounded-md': {}},
21
+ '.btn' : {'@apply transition duration-300 flex-1 inline-flex justify-center items-center px-6 pb-2.5 pt-2 text-sm font-bold rounded-md hover:opacity-80 whitespace-nowrap': {}},
22
+ '.btn-primary' : {'@apply text-primary-reverse border border-primary bg-primary': {}},
23
+ '.btn-danger' : {'@apply bg-theme-red text-white hover:opacity-80': {}},
24
+ '.btn-outline' : {'@apply text-gray-400 bg-white shadow-sm hover:text-gray-600 border border-border-color': {}},
25
+ '.btn-outline-primary': {'@apply border border-primary text-primary hover:bg-primary hover:text-reverse': {}},
11
26
  });
12
27
 
13
28
  // todo :: move it to global
14
29
  addUtilities({
15
30
  '.spinner-loader': {
16
31
  'border-right-color': 'var(--color-main) !important',
17
- '&.reverse': {
32
+ '&.reverse' : {
18
33
  'border-right-color': '#9f7171 !important',
19
34
  'background-color' : '#f98181'
20
35
  }
package/dist/esm/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export { S as SallaLogin } from './salla-login-e6e86a3d.js';
2
- export { S as SallaSearch } from './salla-search-66aae389.js';
1
+ export { S as SallaLogin, a as SallaSearch } from './salla-search-c30c12ef.js';
3
2
  import './index-a1bf769d.js';
4
3
  import './Helper-d07ebbc7.js';
@@ -10,7 +10,7 @@ const patchEsm = () => {
10
10
  const defineCustomElements = (win, options) => {
11
11
  if (typeof window === 'undefined') return Promise.resolve();
12
12
  return patchEsm().then(() => {
13
- return bootstrapLazy([["salla-button_5",[[0,"salla-login",{"isEmailAllowed":[4,"is-email-allowed"],"isMobileAllowed":[4,"is-mobile-allowed"],"isEmailRequired":[4,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"show":[64]},[[0,"verified","onVerified"],[0,"backClicked","onbackClicked"]]],[0,"salla-verify",{"withoutModal":[4,"without-modal"],"url":[513],"by":[1],"isShowBack":[4,"is-show-back"],"autoReload":[4,"auto-reload"],"title":[32],"getCode":[64],"show":[64]}],[0,"salla-tel-input",{"mobile":[1025],"countryCode":[1025,"country-code"],"countryKey":[1025,"country-key"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"btnStyle":[513,"btn-style"],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"wide":[4],"load":[64],"setText":[64],"stop":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"error":[4],"success":[4],"primary":[4],"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"imageIcon":[1,"image-icon"],"title":[32],"show":[64],"hide":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-product-availability",[[4,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32]}]]],["salla-branches",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"ok":[32],"show":[64],"hide":[64]}]]],["salla-localization",[[4,"salla-localization",{"languagesTitle":[32],"currenciesTitle":[32],"ok":[32],"show":[64],"hide":[64],"submit":[64]}]]],["salla-offer",[[0,"salla-offer",{"offer":[32],"show":[64]}]]],["salla-rating",[[0,"salla-rating",{"order":[32],"show":[64],"hide":[64]}]]],["salla-search",[[0,"salla-search",{"results":[32],"placeholder":[32],"noResultsText":[32]},[[0,"modalOpened","onModalOpen"],[0,"modalClosed","onModalClose"]]]]],["salla-infinite-scroll",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[4],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]]], options);
13
+ return bootstrapLazy([["salla-button_7",[[0,"salla-login",{"isEmailAllowed":[4,"is-email-allowed"],"isMobileAllowed":[4,"is-mobile-allowed"],"isEmailRequired":[4,"is-email-required"],"title":[32],"loginTypeTitle":[32],"loginText":[32],"smsLabel":[32],"mobileLabel":[32],"emailLabel":[32],"enterText":[32],"bySMSText":[32],"byEmailText":[32],"emailErrorMsg":[32],"firstNameLabel":[32],"lastNameLabel":[32],"firstNameErrorMsg":[32],"lastNameErrorMsg":[32],"show":[64]},[[0,"verified","onVerified"],[0,"backClicked","onbackClicked"]]],[4,"salla-localization",{"languagesTitle":[32],"currenciesTitle":[32],"ok":[32],"show":[64],"hide":[64],"submit":[64]}],[0,"salla-search",{"results":[32],"placeholder":[32],"noResultsText":[32]},[[0,"modalOpened","onModalOpen"],[0,"modalClosed","onModalClose"]]],[0,"salla-verify",{"withoutModal":[4,"without-modal"],"url":[513],"by":[1],"isShowBack":[4,"is-show-back"],"autoReload":[4,"auto-reload"],"title":[32],"getCode":[64],"show":[64]}],[0,"salla-tel-input",{"mobile":[1025],"countryCode":[1025,"country-code"],"countryKey":[1025,"country-key"],"mobileRequired":[32],"countryCodeLabel":[32],"mobileLabel":[32],"tooShort":[32],"tooLong":[32],"invalidCountryCode":[32],"invalidNumber":[32],"errorMap":[32],"getValues":[64],"isValid":[64]}],[4,"salla-button",{"btnStyle":[513,"btn-style"],"loading":[516],"disabled":[516],"loaderPosition":[1,"loader-position"],"wide":[4],"load":[64],"setText":[64],"stop":[64],"disable":[64],"enable":[64]}],[4,"salla-modal",{"error":[4],"success":[4],"primary":[4],"isClosable":[1028,"is-closable"],"width":[513],"position":[513],"visible":[516],"isLoading":[1540,"is-loading"],"subTitleFirst":[4,"sub-title-first"],"noPadding":[4,"no-padding"],"subTitle":[1,"sub-title"],"icon":[1],"imageIcon":[1,"image-icon"],"title":[32],"show":[64],"hide":[64],"setTitle":[64],"loading":[64],"stopLoading":[64]}]]],["salla-product-availability",[[4,"salla-product-availability",{"channels":[1],"productId":[2,"product-id"],"isSubscribed":[1028,"is-subscribed"],"subTitle":[32],"mobileLabel":[32],"emailLabel":[32],"emailPlaceholder":[32],"subscribedMessage":[32],"title_":[32],"emailErrorMsg":[32]}]]],["salla-branches",[[4,"salla-branches",{"position":[1],"displayAs":[1,"display-as"],"browseProductsFrom":[1,"browse-products-from"],"branches":[16],"current":[1026],"open":[32],"selected":[32],"isOpenedBefore":[32],"ok":[32],"show":[64],"hide":[64]}]]],["salla-offer",[[0,"salla-offer",{"offer":[32],"show":[64]}]]],["salla-rating",[[0,"salla-rating",{"order":[32],"show":[64],"hide":[64]}]]],["salla-infinite-scroll",[[4,"salla-infinite-scroll",{"nextPage":[1,"next-page"],"autoload":[4],"container":[1],"item":[1],"loadMore":[32],"noMore":[32],"failedToLoad":[32]}]]]], options);
14
14
  });
15
15
  };
16
16
 
@@ -2,14 +2,11 @@ import { r as registerInstance, h, g as getElement } from './index-a1bf769d.js';
2
2
 
3
3
  const sallaBranchesCss = ":host{display:block}";
4
4
 
5
- let engine = require('store/src/store-engine');
6
- let storages = require('store/storages/sessionStorage');
7
- let sessionStore = engine.createStore(storages);
8
5
  const SallaBranches = class {
9
6
  constructor(hostRef) {
10
7
  registerInstance(this, hostRef);
11
8
  this.open = false;
12
- this.isOpenedBefore = sessionStore.get("branch-choosed-before");
9
+ this.isOpenedBefore = salla.localData.get("branch-choosed-before");
13
10
  this.displayAs = 'default';
14
11
  this.browseProductsFrom = 'all';
15
12
  this.branches = [
@@ -55,7 +52,7 @@ const SallaBranches = class {
55
52
  this.btn.load().then(() => {
56
53
  setTimeout(() => location.reload(), 2000);
57
54
  });
58
- sessionStore.set("branch-choosed-before", true);
55
+ salla.localData.set("branch-choosed-before", true);
59
56
  this.show();
60
57
  setTimeout(() => {
61
58
  this.current = this.selected;
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, h, H as Host, g as getElement, c as createEvent } from './index-a1bf769d.js';
2
2
  import { H as Helper } from './Helper-d07ebbc7.js';
3
- export { S as salla_login } from './salla-login-e6e86a3d.js';
3
+ export { S as salla_login, a as salla_search } from './salla-search-c30c12ef.js';
4
4
 
5
5
  const sallaButtonCss = ":host{display:block}";
6
6
 
@@ -79,6 +79,82 @@ const SallaButton = class {
79
79
  };
80
80
  SallaButton.style = sallaButtonCss;
81
81
 
82
+ const SallaLocalization = class {
83
+ constructor(hostRef) {
84
+ registerInstance(this, hostRef);
85
+ var _a, _b;
86
+ this.language = salla.config.get('language', {});
87
+ this.currency = salla.config.get('currency', {});
88
+ Helper.setHost(this.host);
89
+ salla.event.on('localization::show', () => this.show());
90
+ salla.event.on('languages::translations.loaded', () => {
91
+ this.languagesTitle = salla.lang.get('common.titles.language');
92
+ this.currenciesTitle = salla.lang.get('common.titles.currency');
93
+ this.ok = salla.lang.get('common.elements.ok');
94
+ });
95
+ /**
96
+ * letting developer to insert his own slot like:
97
+ * <salla-localization>
98
+ * <div slot="language">...{name}....</div>
99
+ * <div slot="currency">...{name}....</div>
100
+ * </salla-localization>
101
+ * Because scoped templates not supported in stencil );
102
+ * we made a workaround to pass language & currency attributes, then replace names in rendering
103
+ */
104
+ 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>';
105
+ 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>';
106
+ this.languages = Object.values(salla.config.get('languages', {}));
107
+ this.currencies = Object.values(salla.config.get('currencies', {}));
108
+ }
109
+ async show() {
110
+ return this.modal.show();
111
+ }
112
+ async hide() {
113
+ return this.modal.hide();
114
+ }
115
+ onChangeCurrency(event) {
116
+ this.currency = salla.config.get('currencies.' + event.target.value);
117
+ }
118
+ onChangeLanguage(event) {
119
+ this.language = salla.config.get('languages.' + event.target.value);
120
+ }
121
+ async submit() {
122
+ let url;
123
+ console.log('this.currency.code::::', this.currency, this.currency.code);
124
+ this.btn.load()
125
+ .then(() => this.currency.code === salla.config.get('user.currency') || ((url = window.location.href) && salla.currency.api.change(this.currency.code)))
126
+ .then(() => this.language.code === salla.config.get('user.language') || (url = this.language.url))
127
+ .then(() => this.btn.stop())
128
+ .then(() => this.hide())
129
+ .then(() => url && (window.location.href = url));
130
+ }
131
+ render() {
132
+ return (h("salla-modal", { id: "salla-localization", class: "hidden", ref: modal => this.modal = modal, width: "xs" }, h("div", { slot: "header" }, h("slot", { name: "header" })), h("div", { class: "s-localization-inner" }, this.languages.length > 1 ?
133
+ 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 ?
134
+ 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
135
+ .replace(/\{name\}/g, lang.name)
136
+ .replace(/\{code\}/g, lang.code)
137
+ .replace(/\{country_code\}/g, lang.country_code) }))) :
138
+ 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)))))
139
+ : '', this.currencies.length > 1 ?
140
+ 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 ?
141
+ 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
142
+ .replace(/\{name\}/g, currency.name)
143
+ .replace(/\{code\}/g, currency.code)
144
+ .replace(/\{country_code\}/g, currency.country_code) }))) :
145
+ 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)))))
146
+ : ''), h("slot", { name: "footer" }, h("salla-button", { wide: true, ref: btn => this.btn = btn, onClick: () => this.submit() }, this.ok))));
147
+ }
148
+ /**
149
+ * to reduce dom levels we will move slot data into the parent dom
150
+ */
151
+ componentDidRender() {
152
+ this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
153
+ this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
154
+ }
155
+ get host() { return getElement(this); }
156
+ };
157
+
82
158
  const sallaModalCss = "";
83
159
 
84
160
  const SallaModal = class {
@@ -1570,8 +1646,8 @@ const SallaTelInput = class {
1570
1646
  constructor(hostRef) {
1571
1647
  registerInstance(this, hostRef);
1572
1648
  this.enterClicked = createEvent(this, "enterClicked", 7);
1573
- this.countryCode = "SA";
1574
- this.countryKey = "+966";
1649
+ this.countryCode = salla.config.get('user.country_code', 'SA');
1650
+ this.countryKey = "+966"; //TODO:: why we need it
1575
1651
  this.countryCodeLabel = salla.lang.get('common.country_code');
1576
1652
  this.mobileLabel = salla.lang.get('common.elements.mobile');
1577
1653
  this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
@@ -1782,4 +1858,4 @@ const SallaVerify = class {
1782
1858
  get host() { return getElement(this); }
1783
1859
  };
1784
1860
 
1785
- export { SallaButton as salla_button, SallaModal as salla_modal, SallaTelInput as salla_tel_input, SallaVerify as salla_verify };
1861
+ export { SallaButton as salla_button, SallaLocalization as salla_localization, SallaModal as salla_modal, SallaTelInput as salla_tel_input, SallaVerify as salla_verify };
@@ -182,4 +182,77 @@ const SallaLogin = class {
182
182
  };
183
183
  SallaLogin.style = sallaLoginCss;
184
184
 
185
- export { SallaLogin as S };
185
+ const sallaSearchCss = "#s-search-modal .s-modal-wrapper{align-items:flex-start;padding:0}#s-search-modal .s-modal-spacer{display:inline}#s-search-modal .s-modal-body{padding:0;max-width:90%;margin-top:3.2rem;border-radius:0.5rem}#s-search-modal .s-modal-close{top:1rem}";
186
+
187
+ const SallaSearch = class {
188
+ constructor(hostRef) {
189
+ registerInstance(this, hostRef);
190
+ var _a;
191
+ Helper.setHost(this.host);
192
+ this.productSlot = ((_a = Helper.getElement('[slot="product"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || this.getDefaultProductSlot();
193
+ salla.event.on('search::show', () => this.modal.show());
194
+ salla.event.on('languages::translations.loaded', () => {
195
+ this.placeholder = salla.lang.get('blocks.header.search_placeholder');
196
+ this.noResultsText = salla.lang.get('common.elements.no_options');
197
+ });
198
+ }
199
+ onModalOpen() {
200
+ this.modal.querySelector('.s-search-input').focus();
201
+ }
202
+ onModalClose() {
203
+ this.modal.querySelector('.s-search-input').value = '';
204
+ this.results = undefined;
205
+ this.afterSearching();
206
+ }
207
+ getDefaultProductSlot() {
208
+ return '<div class="s-search-product-image-container">' +
209
+ ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
210
+ '</div>' +
211
+ '<div class="s-search-product-details">' +
212
+ ' <div class="s-search-product-name">{name}</div> <div class="s-search-product-price">{price}</div>' +
213
+ '</div>';
214
+ }
215
+ //todo:: reset data when closing
216
+ search(e) {
217
+ Helper.hideElement(this.noResults);
218
+ if (e.target.value.length === 0) {
219
+ this.results = undefined;
220
+ this.afterSearching();
221
+ return;
222
+ }
223
+ if (e.target.value.length <= 2) {
224
+ return;
225
+ }
226
+ //run loading spinner or stop it
227
+ Helper.toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => true);
228
+ salla.search.api.search(e.target.value)
229
+ .then(response => this.results = response)
230
+ .catch(err => err !== 'Query Same As Previous!' ? this.results = undefined : null)
231
+ .finally(() => this.afterSearching(/*isEmpty*/ false));
232
+ }
233
+ afterSearching(isEmpty = true) {
234
+ var _a;
235
+ this.noResults.style.display = isEmpty || ((_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length) > 0 ? 'none' : 'block';
236
+ Helper.toggleElement(this.container, 's-search-container-open', 'no-results', () => { var _a; return (_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length; })
237
+ .toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => false); //stop searching anime
238
+ salla.search.api.previousQuery = ''; //avoid having error 'Query Same As Previous' after reopen modal;
239
+ }
240
+ render() {
241
+ var _a;
242
+ return (h("salla-modal", { position: "top", id: "s-search-modal", ref: modal => this.modal = modal }, h("div", { class: "s-search-container", ref: container => this.container = container }, h("input", { class: "s-search-input", type: "text", placeholder: this.placeholder, onInput: e => this.search(e) }), h("span", { class: "s-search-icon" }, h("i", { class: "sicon-search", ref: el => this.searchIcon = el })), h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
243
+ _a.data.map(item => h("a", { href: item.url, class: "s-search-product", innerHTML: this.productSlot
244
+ .replace(/\{name\}/g, item.name)
245
+ .replace(/\{price\}/g, item.price) //todo:: get discounted price too
246
+ .replace(/\{image\}/g, item.image_url) })), h("p", { ref: el => this.noResults = el, class: "s-search-no-results" }, this.noResultsText)))));
247
+ }
248
+ /**
249
+ * Run it one time after load
250
+ */
251
+ componentDidLoad() {
252
+ this.afterSearching();
253
+ }
254
+ get host() { return getElement(this); }
255
+ };
256
+ SallaSearch.style = sallaSearchCss;
257
+
258
+ export { SallaLogin as S, SallaSearch as a };