@salla.sa/twilight-components 2.12.35 → 2.12.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/{Helper-47ef09c2.js → Helper-eb233453.js} +15 -1
- package/dist/cjs/Helper-eb233453.js.map +1 -0
- package/dist/cjs/salla-add-product-button_41.cjs.entry.js +1 -1
- package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
- package/dist/cjs/salla-products-list.cjs.entry.js +50 -67
- package/dist/cjs/salla-products-list.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-slider.cjs.entry.js +19 -30
- package/dist/cjs/salla-products-slider.cjs.entry.js.map +1 -1
- package/dist/collection/Helpers/Helper.js +14 -0
- package/dist/collection/Helpers/Helper.js.map +1 -1
- package/dist/collection/components/salla-products-list/salla-products-list.js +49 -66
- package/dist/collection/components/salla-products-list/salla-products-list.js.map +1 -1
- package/dist/collection/components/salla-products-slider/salla-products-slider.js +18 -29
- package/dist/collection/components/salla-products-slider/salla-products-slider.js.map +1 -1
- package/dist/components/Helper.js +14 -0
- package/dist/components/Helper.js.map +1 -1
- package/dist/components/salla-products-list.js +49 -66
- package/dist/components/salla-products-list.js.map +1 -1
- package/dist/components/salla-products-slider.js +18 -29
- package/dist/components/salla-products-slider.js.map +1 -1
- package/dist/esm/{Helper-c2739d13.js → Helper-66d083b5.js} +15 -1
- package/dist/esm/Helper-66d083b5.js.map +1 -0
- package/dist/esm/salla-add-product-button_41.entry.js +1 -1
- package/dist/esm/salla-filters-widget.entry.js +1 -1
- package/dist/esm/salla-products-list.entry.js +50 -67
- package/dist/esm/salla-products-list.entry.js.map +1 -1
- package/dist/esm/salla-products-slider.entry.js +19 -30
- package/dist/esm/salla-products-slider.entry.js.map +1 -1
- package/dist/esm-es5/{Helper-c2739d13.js → Helper-66d083b5.js} +3 -3
- package/dist/esm-es5/{Helper-c2739d13.js.map → Helper-66d083b5.js.map} +1 -1
- package/dist/esm-es5/salla-add-product-button_41.entry.js +1 -1
- package/dist/esm-es5/salla-filters-widget.entry.js +1 -1
- package/dist/esm-es5/salla-products-list.entry.js +1 -1
- package/dist/esm-es5/salla-products-list.entry.js.map +1 -1
- package/dist/esm-es5/salla-products-slider.entry.js +1 -1
- package/dist/esm-es5/salla-products-slider.entry.js.map +1 -1
- package/dist/twilight/{p-e552c228.system.entry.js → p-09f2c48c.system.entry.js} +2 -2
- package/dist/twilight/p-17869512.system.entry.js +5 -0
- package/dist/twilight/p-17869512.system.entry.js.map +1 -0
- package/dist/twilight/{p-765672d0.entry.js → p-24103953.entry.js} +2 -2
- package/dist/twilight/p-34bf40ac.system.js +1 -1
- package/dist/twilight/p-5f51f7e6.entry.js +5 -0
- package/dist/twilight/p-5f51f7e6.entry.js.map +1 -0
- package/dist/twilight/{p-68d3a0d2.system.js → p-641358eb.system.js} +3 -3
- package/dist/twilight/{p-68d3a0d2.system.js.map → p-641358eb.system.js.map} +1 -1
- package/dist/twilight/{p-1f0a4705.entry.js → p-695467d5.entry.js} +2 -2
- package/dist/twilight/p-9f249e3c.system.entry.js +5 -0
- package/dist/twilight/p-9f249e3c.system.entry.js.map +1 -0
- package/dist/twilight/{p-20659764.system.entry.js → p-d2dc658a.system.entry.js} +2 -2
- package/dist/twilight/p-d7b6c544.entry.js +5 -0
- package/dist/twilight/p-d7b6c544.entry.js.map +1 -0
- package/dist/twilight/{p-69321383.js → p-ed793fc8.js} +2 -2
- package/dist/twilight/{p-69321383.js.map → p-ed793fc8.js.map} +1 -1
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/types/Helpers/Helper.d.ts +11 -0
- package/dist/types/components/salla-products-list/salla-products-list.d.ts +1 -1
- package/dist/types/components/salla-products-slider/salla-products-slider.d.ts +1 -3
- package/package.json +2 -2
- package/dist/cjs/Helper-47ef09c2.js.map +0 -1
- package/dist/esm/Helper-c2739d13.js.map +0 -1
- package/dist/twilight/p-5022a0dc.entry.js +0 -5
- package/dist/twilight/p-5022a0dc.entry.js.map +0 -1
- package/dist/twilight/p-672fb5e4.system.entry.js +0 -5
- package/dist/twilight/p-672fb5e4.system.entry.js.map +0 -1
- package/dist/twilight/p-98c3cddb.entry.js +0 -5
- package/dist/twilight/p-98c3cddb.entry.js.map +0 -1
- package/dist/twilight/p-e19acc25.system.entry.js +0 -5
- package/dist/twilight/p-e19acc25.system.entry.js.map +0 -1
- /package/dist/twilight/{p-e552c228.system.entry.js.map → p-09f2c48c.system.entry.js.map} +0 -0
- /package/dist/twilight/{p-765672d0.entry.js.map → p-24103953.entry.js.map} +0 -0
- /package/dist/twilight/{p-1f0a4705.entry.js.map → p-695467d5.entry.js.map} +0 -0
- /package/dist/twilight/{p-20659764.system.entry.js.map → p-d2dc658a.system.entry.js.map} +0 -0
|
@@ -96,9 +96,23 @@ class Helper {
|
|
|
96
96
|
// Return page id as default value
|
|
97
97
|
return salla.config.get('page.id');
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* We needed this function to help us avoid requesting the products list before salla is ready,
|
|
101
|
+
* was causing a strange issues in live for the bad connections ex: not loading the dom, requesting api without storeIdentefire
|
|
102
|
+
*/
|
|
103
|
+
onSallaReadyPromise(callback) {
|
|
104
|
+
return new Promise((resolve) => salla.onReady(() => resolve(callback())));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* let's make sure to send the request only when salla is ready
|
|
109
|
+
*/
|
|
110
|
+
fetchProducts(source, source_value, limit) {
|
|
111
|
+
return this.onSallaReadyPromise(() => salla.product.api.fetch({ source: source, source_value: source_value, limit: limit }));
|
|
112
|
+
}
|
|
99
113
|
}
|
|
100
114
|
const Helper$1 = new Helper;
|
|
101
115
|
|
|
102
116
|
exports.Helper = Helper$1;
|
|
103
117
|
|
|
104
|
-
//# sourceMappingURL=Helper-
|
|
118
|
+
//# sourceMappingURL=Helper-eb233453.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"Helper-eb233453.js","mappings":";;;;;AA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KAAK,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;GACzE;;;;;EAMD,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK;IAEvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAC,MAAM,EAAC,MAAM,EAAE,YAAY,EAAC,YAAY,EAAE,KAAK,EAAC,KAAK,EAAC,CAAC,CAAC,CAAC;GACvH;CACF;AAED,iBAAe,IAAI,MAAM;;;;","names":[],"sources":["./src/Helpers/Helper.ts"],"sourcesContent":["import { ProductResponse } from \"@salla.sa/twilight/types/api/product\";\n\n//TODO::reduce it to 10\nsalla.event.setMaxListeners(100);\n\nclass Helper {\n private debounce_: any;\n\n toggleElementClassIf(element, classes1, classes2, callback) {\n classes1 = Array.isArray(classes1) ? classes1 : classes1.split(' ');\n classes2 = Array.isArray(classes2) ? classes2 : classes2.split(' ');\n let isClasses1 = callback(element);\n element?.classList.remove(...(isClasses1 ? classes2 : classes1));\n element?.classList.add(...(isClasses1 ? classes1 : classes2));\n return this;\n }\n\n toggleClassIf(selector, classes1, classes2, callback) {\n document.querySelectorAll(selector).forEach(element => this.toggleElementClassIf(element, classes1, classes2, callback));\n return this;\n }\n\n isValidEmail(email) {\n const re = /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n return re.test(String(email).toLowerCase());\n }\n\n filterEmojies(text) {\n var characterFilter = /(?:[\\u2700-\\u27bf]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\u0023-\\u0039]\\ufe0f?\\u20e3|\\u3299|\\u3297|\\u303d|\\u3030|\\u24c2|\\ud83c[\\udd70-\\udd71]|\\ud83c[\\udd7e-\\udd7f]|\\ud83c\\udd8e|\\ud83c[\\udd91-\\udd9a]|\\ud83c[\\udde6-\\uddff]|\\ud83c[\\ude01-\\ude02]|\\ud83c\\ude1a|\\ud83c\\ude2f|\\ud83c[\\ude32-\\ude3a]|\\ud83c[\\ude50-\\ude51]|\\u203c|\\u2049|[\\u25aa-\\u25ab]|\\u25b6|\\u25c0|[\\u25fb-\\u25fe]|\\u00a9|\\u00ae|\\u2122|\\u2139|\\ud83c\\udc04|[\\u2600-\\u26FF]|\\u2b05|\\u2b06|\\u2b07|\\u2b1b|\\u2b1c|\\u2b50|\\u2b55|\\u231a|\\u231b|\\u2328|\\u23cf|[\\u23e9-\\u23f3]|[\\u23f8-\\u23fa]|\\ud83c\\udccf|\\u2934|\\u2935|[\\u2190-\\u21ff])/g;\n return text.replace(characterFilter, \"\");\n }\n\n debounce(fn, ...data) {\n if (!this.debounce_) {\n this.debounce_ = salla.helpers.debounce((callback, ...innerData) => callback(...innerData), 500);\n }\n //@ts-ignore\n return this.debounce_(fn, ...data);\n }\n\n getProductsSource(source) {\n return {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'product.index.search': 'search',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n 'product.index.sales': 'sales',\n 'components.most_sales_products': 'sales',//temporary, delete it after two days from now\n }[source || salla.config.get('page.slug')] || source || 'latest';\n }\n\n getPageTitleForSource(source){\n \n source= {\n 'brands':'common.titles.brands',\n // 'categories':'',\n 'latest':'blocks.home.latest_products',\n 'offers':'common.titles.discounts',\n // 'search':'',\n // 'landing-page':'',\n // 'tags':'',\n 'sales':'common.titles.most_sales',\n }[source];\n\n return source ? salla.lang.get(source):'';\n }\n\n getProductsSourceValue(source, sourceValue) {\n const parsedSource = this.getProductsSource(source);\n\n // Validate if the source value is a valid JSON string\n let parsedSourceValue: any = null;\n if (sourceValue) {\n try {\n parsedSourceValue = JSON.parse(sourceValue);\n } catch (error) {\n console.error('Invalid JSON string in sourceValue:', error);\n }\n }\n\n // Handle different source types\n if (!['search', 'json', 'offers', 'latest', 'sales', 'related'].includes(parsedSource)) {\n\n if (Array.isArray(parsedSourceValue) && parsedSourceValue.length) {\n return parsedSourceValue;\n }\n \n if (Array.isArray(parsedSourceValue) && !parsedSourceValue.length){\n return '';\n }\n\n if (typeof parsedSourceValue === 'number') {\n return [parsedSourceValue];\n }\n\n if (!sourceValue && ['categories', 'tags', 'brands'].includes(source)) {\n return [salla.config.get('page.id')];\n }\n }\n\n // Return sourceValue if it exists and is a valid JSON object/array\n if (parsedSourceValue || sourceValue) {\n return parsedSourceValue || sourceValue;\n }\n\n if (parsedSource === 'search') {\n return new URLSearchParams(window.location.search).get('q') || '';\n }\n\n // Return page id as default value\n return salla.config.get('page.id');\n }\n\n /**\n * We needed this function to help us avoid requesting the products list before salla is ready,\n * was causing a strange issues in live for the bad connections ex: not loading the dom, requesting api without storeIdentefire\n */\n onSallaReadyPromise(callback): Promise<any>{\n return new Promise((resolve)=>salla.onReady(() => resolve(callback())));\n }\n\n /**\n * \n * let's make sure to send the request only when salla is ready\n */\n fetchProducts(source, source_value, limit): Promise<ProductResponse.lists>\n {\n return this.onSallaReadyPromise(()=>salla.product.api.fetch({source:source, source_value:source_value, limit:limit}));\n }\n}\n\nexport default new Helper;\n"],"version":3}
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
8
8
|
const index = require('./index-54f31d8b.js');
|
|
9
9
|
const anime_es = require('./anime.es-78730411.js');
|
|
10
10
|
const _commonjsHelpers = require('./_commonjsHelpers-691dd63b.js');
|
|
11
|
-
const Helper = require('./Helper-
|
|
11
|
+
const Helper = require('./Helper-eb233453.js');
|
|
12
12
|
const camera = require('./camera-058ddeeb.js');
|
|
13
13
|
|
|
14
14
|
const PendingOrdersIcon = `<!-- Generated by IcoMoon.io -->
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
7
7
|
|
|
8
8
|
const index = require('./index-54f31d8b.js');
|
|
9
|
-
const Helper = require('./Helper-
|
|
9
|
+
const Helper = require('./Helper-eb233453.js');
|
|
10
10
|
const interfaces = require('./interfaces-56bf4b49.js');
|
|
11
11
|
|
|
12
12
|
const sallaFiltersWidgetCss = ":host{display:block}";
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
7
7
|
|
|
8
8
|
const index = require('./index-54f31d8b.js');
|
|
9
9
|
const anime_es = require('./anime.es-78730411.js');
|
|
10
|
-
const Helper = require('./Helper-
|
|
10
|
+
const Helper = require('./Helper-eb233453.js');
|
|
11
11
|
|
|
12
12
|
const ShoppingBag = `<!-- Generated by IcoMoon.io -->
|
|
13
13
|
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
|
@@ -39,27 +39,6 @@ const SallaProductsList = class {
|
|
|
39
39
|
this.parsedFilters = undefined;
|
|
40
40
|
}
|
|
41
41
|
connectedCallback() {
|
|
42
|
-
salla.onReady(() => {
|
|
43
|
-
this.hasCustomComponent = !!customElements.get('custom-salla-product-card');
|
|
44
|
-
this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());
|
|
45
|
-
this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());
|
|
46
|
-
try {
|
|
47
|
-
let searchParams = new URLSearchParams(window.location.search);
|
|
48
|
-
this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');
|
|
49
|
-
let filters = searchParams.get('filters');
|
|
50
|
-
this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
salla.logger.warn('failed to get filters from url', e.message);
|
|
54
|
-
}
|
|
55
|
-
this.buildNextPageUrl();
|
|
56
|
-
this.createStatusDom();
|
|
57
|
-
this.isReady = true;
|
|
58
|
-
});
|
|
59
|
-
if (!this.sourceValueIsValid) {
|
|
60
|
-
salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
42
|
salla.event.on('salla-filters::changed', filters => this.setFilters(filters));
|
|
64
43
|
}
|
|
65
44
|
/**
|
|
@@ -198,25 +177,6 @@ const SallaProductsList = class {
|
|
|
198
177
|
getSourceValue() {
|
|
199
178
|
return Helper.Helper.getProductsSourceValue(this.source, this.sourceValue);
|
|
200
179
|
}
|
|
201
|
-
fetchProducts() {
|
|
202
|
-
salla.product.api.fetch({
|
|
203
|
-
source: this.getSource(),
|
|
204
|
-
source_value: this.getSourceValue(),
|
|
205
|
-
limit: this.limit
|
|
206
|
-
})
|
|
207
|
-
.then(res => {
|
|
208
|
-
if (!res.data.length) {
|
|
209
|
-
this.showPlaceholder = true;
|
|
210
|
-
this.loading(false);
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
this.handleResponse(res).forEach(card => this.wrapper.append(card));
|
|
214
|
-
}).catch(() => {
|
|
215
|
-
// TODO: Find the real issue and fix it
|
|
216
|
-
salla.log('Request headers', salla.api.getHeaders());
|
|
217
|
-
setTimeout(() => this.fetchProducts(), 1000);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
180
|
initiateInfiniteScroll() {
|
|
221
181
|
var _a, _b, _c;
|
|
222
182
|
if (!this.hasInfiniteScroll) {
|
|
@@ -252,15 +212,61 @@ const SallaProductsList = class {
|
|
|
252
212
|
});
|
|
253
213
|
salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll));
|
|
254
214
|
}
|
|
215
|
+
componentWillLoad() {
|
|
216
|
+
return Helper.Helper.onSallaReadyPromise(() => {
|
|
217
|
+
this.hasCustomComponent = !!customElements.get('custom-salla-product-card');
|
|
218
|
+
this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());
|
|
219
|
+
this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource()) && !this.limit;
|
|
220
|
+
try {
|
|
221
|
+
let searchParams = new URLSearchParams(window.location.search);
|
|
222
|
+
this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');
|
|
223
|
+
let filters = searchParams.get('filters');
|
|
224
|
+
this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
salla.logger.warn('failed to get filters from url', e.message);
|
|
228
|
+
}
|
|
229
|
+
this.buildNextPageUrl();
|
|
230
|
+
this.createStatusDom();
|
|
231
|
+
this.isReady = true;
|
|
232
|
+
if (!this.sourceValueIsValid) {
|
|
233
|
+
salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (this.hasInfiniteScroll) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
// Handle json source
|
|
240
|
+
if (this.getSource() === 'json') {
|
|
241
|
+
if (!this.getSourceValue().length) {
|
|
242
|
+
this.showPlaceholder = true;
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
// Handle selected source
|
|
249
|
+
if (this.getSource() === 'selected' && !this.getSourceValue().length) {
|
|
250
|
+
this.showPlaceholder = true;
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
return Helper.Helper.fetchProducts(this.getSource(), this.getSourceValue(), this.limit).then(res => {
|
|
254
|
+
if (!res.data.length) {
|
|
255
|
+
this.showPlaceholder = true;
|
|
256
|
+
this.loading(false);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
this.handleResponse(res).forEach(card => this.wrapper.append(card));
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
}
|
|
255
263
|
canRender() {
|
|
256
264
|
return this.sourceValueIsValid && this.isReady;
|
|
257
265
|
}
|
|
258
266
|
render() {
|
|
259
|
-
salla.log('render: before can render');
|
|
260
267
|
if (!this.canRender()) {
|
|
261
268
|
return '';
|
|
262
269
|
}
|
|
263
|
-
salla.log('render: after can render');
|
|
264
270
|
if (this.showPlaceholder) {
|
|
265
271
|
return index.h("div", { class: "s-products-list-placeholder" }, index.h("span", { innerHTML: ShoppingBag }), index.h("p", null, this.placeholderText));
|
|
266
272
|
}
|
|
@@ -272,30 +278,7 @@ const SallaProductsList = class {
|
|
|
272
278
|
}, ref: wrapper => this.wrapper = wrapper })));
|
|
273
279
|
}
|
|
274
280
|
componentDidLoad() {
|
|
275
|
-
|
|
276
|
-
if (!this.canRender()) {
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
salla.log('component did load after can render');
|
|
280
|
-
// Handle json source
|
|
281
|
-
if (this.getSource() === 'json') {
|
|
282
|
-
if (!this.getSourceValue().length) {
|
|
283
|
-
this.showPlaceholder = true;
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
// Handle selected source
|
|
290
|
-
if (this.getSource() === 'selected' || this.getSource() === 'landing-page') {
|
|
291
|
-
if (this.getSource() === 'selected' && !this.getSourceValue().length) {
|
|
292
|
-
this.showPlaceholder = true;
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
this.fetchProducts();
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
this.init();
|
|
281
|
+
this.hasInfiniteScroll && this.init();
|
|
299
282
|
}
|
|
300
283
|
init() {
|
|
301
284
|
this.initiateInfiniteScroll();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-list.entry.cjs.js","mappings":";;;;;;;;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,EAAE;;MCQlB,iBAAi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AE;MAC9B,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;KACrC;IACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;MAC5C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;MAC5E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACnF;IACD,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,KAAI,EAAE,CAAC;GACvE;;;;;;;","names":["anime","Helper","h","Host"],"sources":["./src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","./src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import { Component, Host, h, Prop, State, Element, Method, Event, EventEmitter } from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.onReady(() => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n\n\n }\n\n /**\n * Set parsed filters data from URI\n * @param filters\n */\n @Method()\n async setFilters(filters) {\n if (!!filters && JSON.stringify(this.parsedFilters) === JSON.stringify(filters)) {\n return;\n }\n window.scrollTo({ top: 0, behavior: 'smooth' });\n this.parsedFilters = filters;\n return this.reload();\n }\n\n /**\n * Reload the list of products (entire content of the component).\n */\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n // TODO: this is problematic in testing, for the time being it's been resolved like this\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({ mutable: true }) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({ mutable: true }) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({ reflect: true, mutable: true }) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({ reflect: true }) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n /**\n * Custom event fired when the the products fetched.\n */\n @Event() productsFetched: EventEmitter;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n // @ts-ignore\n this.nextPage += `&filters[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`;\n } else if (Array.isArray(value)) {\n value.forEach(item => this.nextPage += `&filters[${encodeURIComponent(key)}][]=${encodeURIComponent(item)}`);\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${encodeURIComponent(key)}][${encodeURIComponent(k)}]=${encodeURIComponent(v)}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n const productCard = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n productCard.product = product;\n\n this.applyLandingPageStyles(productCard);\n this.applyHorizontalCardStyles(productCard);\n\n return productCard;\n }\n\n private applyLandingPageStyles(productCard) {\n if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {\n productCard.toggleAttribute('hide-add-btn', true);\n productCard.classList.add('s-product-card-fit-height');\n }\n }\n\n private applyHorizontalCardStyles(productCard) {\n if (!this.horizontalCards) {\n return;\n }\n productCard.setAttribute('horizontal', true);\n if (!this.hasCustomComponent) {\n productCard.setAttribute('shadow-on-hover', true);\n }\n\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n private fetchProducts() {\n\n salla.product.api.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit\n })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll?.on('request', () => this.loading())\n this.infiniteScroll?.on('load', response => {\n if (!response.data?.length && this.infiniteScroll.pageIndex == 2) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n } else {\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll?.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n salla.log('render: before can render')\n if (!this.canRender()) {\n return '';\n }\n salla.log('render: after can render')\n if (this.showPlaceholder) {\n return <div class=\"s-products-list-placeholder\">\n <span innerHTML={ShoppingBag} />\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class={{\n \"s-products-list-wrapper\": true,\n 's-products-list-horizontal-cards': this.horizontalCards && !this.filtersResults,\n 's-products-list-vertical-cards': !this.horizontalCards && !this.filtersResults,\n 's-products-list-filters-results': this.filtersResults,\n }}\n ref={wrapper => this.wrapper = wrapper} />\n </Host>\n );\n }\n\n componentDidLoad() {\n salla.log('component did load before can render')\n if (!this.canRender()) {\n return;\n }\n salla.log('component did load after can render')\n\n // Handle json source\n if (this.getSource() === 'json') {\n if (!this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n // Handle selected source\n if (this.getSource() === 'selected' || this.getSource() === 'landing-page') {\n if (this.getSource() === 'selected' && !this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.fetchProducts()\n return;\n }\n this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n }\n\n private handleResponse(response): Array<HTMLElement> {\n let source=this.getSource();\n let title = '';\n //help the developer to know the current page title\n if (response.cursor?.current === 1) {\n title = Helper.getPageTitleForSource(source);\n try {\n if (this.getSource() === 'search') {\n title = salla.lang.get('common.elements.search_about', {'word': this.getSourceValue()});\n } else if (!title) {\n let catId = this.parsedFilters.category_id || this.getSourceValue()[0];\n // get the first filter that its key is category_id, then get the value when filter.value.*.key==catId\n title = response.filters.find(filter => filter.key == 'category_id') ?. values ?. find(cat => cat.key == catId) ?. value || '';\n }\n title += (title ? ' - ' : '') + salla.lang.choice('blocks.header.products_count', response.data ?. length);\n if (response.data.length === 20) {\n title = title.replace(response.data.length, salla.lang.get('common.elements.more_than') + ' ' + response.data.length)\n }\n response.title = title;\n } catch (e) {}\n }\n\n salla.event.emit('salla-products-list::products.fetched', response);\n this.productsFetched.emit(response);\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', { filters: response.filters });\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"salla-products-list.entry.cjs.js","mappings":";;;;;;;;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,EAAE;;MCQlB,iBAAiB;;;;;;;;;;gBA8EJ,CAAC;;;;;;;;;;EA7EzB,iBAAiB;IACf,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,wBAAwB,EAAE,OAAO,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;GAC9E;;;;;EAOD,MAAM,UAAU,CAAC,OAAO;IACtB,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;MAC/E,OAAO;KACR;IACD,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC;IAC7B,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;GACtB;;;;EAMD,MAAM,MAAM;IACV,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAClD,IAAI,CAAC,gBAAgB,EAAE,CAAC;;IAExB,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;GACb;EAgEO,YAAY;IAClB,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,IAAI,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Q,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;MAC5C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;MAC5E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACnF;IACD,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,KAAI,EAAE,CAAC;GACvE;;;;;;;","names":["anime","Helper","h","Host"],"sources":["./src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","./src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import { Component, Host, h, Prop, State, Element, Method, Event, EventEmitter } from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n }\n\n /**\n * Set parsed filters data from URI\n * @param filters\n */\n @Method()\n async setFilters(filters) {\n if (!!filters && JSON.stringify(this.parsedFilters) === JSON.stringify(filters)) {\n return;\n }\n window.scrollTo({ top: 0, behavior: 'smooth' });\n this.parsedFilters = filters;\n return this.reload();\n }\n\n /**\n * Reload the list of products (entire content of the component).\n */\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n // TODO: this is problematic in testing, for the time being it's been resolved like this\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({ mutable: true }) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({ mutable: true }) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({ reflect: true, mutable: true }) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({ reflect: true }) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n /**\n * Custom event fired when the the products fetched.\n */\n @Event() productsFetched: EventEmitter;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n // @ts-ignore\n this.nextPage += `&filters[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`;\n } else if (Array.isArray(value)) {\n value.forEach(item => this.nextPage += `&filters[${encodeURIComponent(key)}][]=${encodeURIComponent(item)}`);\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${encodeURIComponent(key)}][${encodeURIComponent(k)}]=${encodeURIComponent(v)}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n const productCard = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n productCard.product = product;\n\n this.applyLandingPageStyles(productCard);\n this.applyHorizontalCardStyles(productCard);\n\n return productCard;\n }\n\n private applyLandingPageStyles(productCard) {\n if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {\n productCard.toggleAttribute('hide-add-btn', true);\n productCard.classList.add('s-product-card-fit-height');\n }\n }\n\n private applyHorizontalCardStyles(productCard) {\n if (!this.horizontalCards) {\n return;\n }\n productCard.setAttribute('horizontal', true);\n if (!this.hasCustomComponent) {\n productCard.setAttribute('shadow-on-hover', true);\n }\n\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll?.on('request', () => this.loading())\n this.infiniteScroll?.on('load', response => {\n if (!response.data?.length && this.infiniteScroll.pageIndex == 2) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n } else {\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll?.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n componentWillLoad() {\n return Helper.onSallaReadyPromise( () => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource()) && !this.limit;\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n \n this.isReady = true;\n \n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n if (this.hasInfiniteScroll) {\n return;\n }\n\n // Handle json source\n if (this.getSource() === 'json') {\n if (!this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n\n // Handle selected source\n if (this.getSource() === 'selected' && !this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n\n return Helper.fetchProducts(this.getSource(), this.getSourceValue(), this.limit).then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n });\n });\n }\n\n\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n if (!this.canRender()) {\n return '';\n }\n\n if (this.showPlaceholder) {\n return <div class=\"s-products-list-placeholder\">\n <span innerHTML={ShoppingBag} />\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class={{\n \"s-products-list-wrapper\": true,\n 's-products-list-horizontal-cards': this.horizontalCards && !this.filtersResults,\n 's-products-list-vertical-cards': !this.horizontalCards && !this.filtersResults,\n 's-products-list-filters-results': this.filtersResults,\n }}\n ref={wrapper => this.wrapper = wrapper} />\n </Host>\n );\n }\n\n componentDidLoad() {\n this.hasInfiniteScroll && this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n }\n\n private handleResponse(response): Array<HTMLElement> {\n let source=this.getSource();\n let title = '';\n //help the developer to know the current page title\n if (response.cursor?.current === 1) {\n title = Helper.getPageTitleForSource(source);\n try {\n if (this.getSource() === 'search') {\n title = salla.lang.get('common.elements.search_about', {'word': this.getSourceValue()});\n } else if (!title) {\n let catId = this.parsedFilters.category_id || this.getSourceValue()[0];\n // get the first filter that its key is category_id, then get the value when filter.value.*.key==catId\n title = response.filters.find(filter => filter.key == 'category_id') ?. values ?. find(cat => cat.key == catId) ?. value || '';\n }\n title += (title ? ' - ' : '') + salla.lang.choice('blocks.header.products_count', response.data ?. length);\n if (response.data.length === 20) {\n title = title.replace(response.data.length, salla.lang.get('common.elements.more_than') + ' ' + response.data.length)\n }\n response.title = title;\n } catch (e) {}\n }\n\n salla.event.emit('salla-products-list::products.fetched', response);\n this.productsFetched.emit(response);\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', { filters: response.filters });\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"version":3}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
7
7
|
|
|
8
8
|
const index = require('./index-54f31d8b.js');
|
|
9
|
-
const Helper = require('./Helper-
|
|
9
|
+
const Helper = require('./Helper-eb233453.js');
|
|
10
10
|
|
|
11
11
|
const sallaProductsSliderCss = "";
|
|
12
12
|
|
|
@@ -27,14 +27,6 @@ const SallaProductsSlider = class {
|
|
|
27
27
|
this.hasCustomComponent = undefined;
|
|
28
28
|
this.apiUrl = '';
|
|
29
29
|
this.parsedSourceValue = undefined;
|
|
30
|
-
salla.onReady(() => {
|
|
31
|
-
this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());
|
|
32
|
-
if (!this.sourceValueIsValid) {
|
|
33
|
-
salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.hasCustomComponent = !!customElements.get('custom-salla-product-card');
|
|
37
|
-
});
|
|
38
30
|
}
|
|
39
31
|
isSourceWithoutValue() {
|
|
40
32
|
return ['offers', 'latest', 'sales'].includes(this.getSource());
|
|
@@ -49,27 +41,24 @@ const SallaProductsSlider = class {
|
|
|
49
41
|
return this.sourceValueIsValid && this.isReady;
|
|
50
42
|
}
|
|
51
43
|
componentWillLoad() {
|
|
52
|
-
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
salla.log('Request headers', salla.api.getHeaders());
|
|
71
|
-
setTimeout(() => this.fetchProducts(), 1000);
|
|
72
|
-
}));
|
|
44
|
+
return Helper.Helper.onSallaReadyPromise(() => {
|
|
45
|
+
this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());
|
|
46
|
+
if (!this.sourceValueIsValid) {
|
|
47
|
+
salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.hasCustomComponent = !!customElements.get('custom-salla-product-card');
|
|
51
|
+
if (this.source === 'json') {
|
|
52
|
+
this.productsData = this.getSourceValue();
|
|
53
|
+
this.isReady = true;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
return Helper.Helper.fetchProducts(this.getSource(), this.getSourceValue(), this.limit).then(res => {
|
|
57
|
+
this.productsData = res.data;
|
|
58
|
+
this.isReady = true;
|
|
59
|
+
salla.event.emit('salla-products-slider::products.fetched', res.data);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
73
62
|
}
|
|
74
63
|
getSource() {
|
|
75
64
|
return Helper.Helper.getProductsSource(this.source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-slider.entry.cjs.js","mappings":";;;;;;;;;;AAAA,MAAM,sBAAsB,GAAG,EAAE;;MCQpB,mBAAmB
|
|
1
|
+
{"file":"salla-products-slider.entry.cjs.js","mappings":";;;;;;;;;;AAAA,MAAM,sBAAsB,GAAG,EAAE;;MCQpB,mBAAmB;;;;;;;;;;;;;;;kBAuEJ,EAAE;;;EAtEpB,oBAAoB;IAC1B,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;GACjE;EAuEO,WAAW,CAAC,OAAO;IACzB,IAAI,IAAI,CAAC,kBAAkB,EAAE;MAC3B,OAAOA,iBAAK,KAAK,EAAC,wBAAwB,IACxCA,uCAA2B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,kBAAgB,IAAI,CAAC,cAAc,EAAE,GAAI,CAC1G,CAAC;KACR;IAED,OAAOA,iBAAK,KAAK,EAAC,wBAAwB,IACxCA,iDACiB,IAAI,CAAC,SAAS,EAAE,IAAI,cAAc,kBACnC,IAAI,CAAC,SAAS,EAAE,IAAI,cAAc,qBAC/B,IAAI,EACrB,OAAO,EAAE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W,CAAC,CAAC;GACrE;EAED,MAAM;;IACJ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,SAAS,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,iDAAiD,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;MAChI,OAAO;KACR;IACD,QACED,QAACE,UAAI,IAAC,KAAK,EAAC,2BAA2B,IACrCF,0BACE,KAAK,EAAC,0BAA0B,EAChC,EAAE,EAAE,IAAI,CAAC,QAAQ,IAAI,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,eACxE,IAAI,CAAC,QAAQ,EACxB,IAAI,EAAC,UAAU,iBACF,IAAI,CAAC,UAAU,oBACZ,IAAI,CAAC,QAAQ,qBACZ,IAAI,CAAC,aAAa,IAEnCA,iBAAK,IAAI,EAAC,OAAO,IACd,MAAA,IAAI,CAAC,YAAY,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CACzD,CACO,CACV,EACP;GACH;;;;;;;","names":["h","Helper","Host"],"sources":["./src/components/salla-products-slider/salla-products-slider.scss?tag=salla-products-slider","./src/components/salla-products-slider/salla-products-slider.tsx"],"sourcesContent":[".s-products-slider{\n &-wrapper{\n\n }\n &-slider{\n\n }\n &-card{\n\n }\n}","import { Component, Host, h, Prop, Element, State } from '@stencil/core';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-slider',\n styleUrl: 'salla-products-slider.scss'\n})\n\n//todo:: extends this component from salla-products-list or the opposite\nexport class SallaProductsSlider {\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n @Element() host: HTMLElement;\n //todo:: support limit, default =10, make sure that maximum is 32,\n\n /**\n * Title of the block - works only if slider is true\n * @type {string}\n * @default ''\n * */\n @Prop() blockTitle: string;\n\n /**\n * Sub title of the block - works only if slider is true\n * @type {string}\n * @default ''\n * */\n @Prop() subTitle: string;\n\n /**\n * Slider Id, if not provided will be generated automatically\n * @type {string}\n * @default ''\n * */\n @Prop() sliderId: string;\n\n /**\n * Display 'ALL' URL\n * @type {string}\n * @default ''\n * */\n @Prop() displayAllUrl: string;\n\n /**\n * autoplay option for products slider\n */\n @Prop({ mutable: true }) autoplay: boolean\n\n /**\n * Source of the products, if api will get the products from the API, if json will get the products from the products prop\n * @type {string}\n * @default ''\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'tags' | 'selected' | 'offers' | 'landing-page';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop() sourceValue: string;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n\n @State() productsData: any;\n @State() isReady: boolean;\n @State() sourceValueIsValid: boolean;\n @State() hasCustomComponent: boolean;\n @State() apiUrl: string = '';\n @State() parsedSourceValue: any;\n\n private getItemHTML(product) {\n if (this.hasCustomComponent) {\n return <div class=\"s-products-slider-card\">\n <custom-salla-product-card product={product} source={this.getSource()} source-value={this.getSourceValue()} />\n </div>;\n }\n\n return <div class=\"s-products-slider-card\">\n <salla-product-card\n show-quantity={this.getSource() == 'landing-page'}\n hide-add-btn={this.getSource() == 'landing-page'}\n shadow-on-hover={true}\n product={product} />\n </div>;\n }\n\n\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n componentWillLoad() {\n return Helper.onSallaReadyPromise(() => {\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${\n this.getSource()\n }]`);\n return;\n }\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n\n if (this.source === 'json') {\n this.productsData = this.getSourceValue();\n this.isReady = true\n return;\n }\n return Helper.fetchProducts(this.getSource(), this.getSourceValue(), this.limit).then(res => {\n this.productsData = res.data\n this.isReady = true\n salla.event.emit('salla-products-slider::products.fetched', res.data);\n });\n });\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n render() {\n if ((this.getSource() == 'related' && !salla.config.get('store.settings.product.related_products_enabled')) || !this.canRender()) {\n return;\n }\n return (\n <Host class=\"s-products-slider-wrapper\">\n <salla-slider\n class=\"s-products-slider-slider\"\n id={this.sliderId || `s-products-slider-${Math.random().toString(36).substr(2, 9)}`}\n auto-play={this.autoplay}\n type=\"carousel\"\n block-title={this.blockTitle}\n block-subTitle={this.subTitle}\n display-all-url={this.displayAllUrl}\n >\n <div slot=\"items\">\n {this.productsData?.map(product => this.getItemHTML(product))}\n </div>\n </salla-slider>\n </Host>\n );\n }\n\n}\n"],"version":3}
|
|
@@ -94,6 +94,20 @@ class Helper {
|
|
|
94
94
|
// Return page id as default value
|
|
95
95
|
return salla.config.get('page.id');
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* We needed this function to help us avoid requesting the products list before salla is ready,
|
|
99
|
+
* was causing a strange issues in live for the bad connections ex: not loading the dom, requesting api without storeIdentefire
|
|
100
|
+
*/
|
|
101
|
+
onSallaReadyPromise(callback) {
|
|
102
|
+
return new Promise((resolve) => salla.onReady(() => resolve(callback())));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* let's make sure to send the request only when salla is ready
|
|
107
|
+
*/
|
|
108
|
+
fetchProducts(source, source_value, limit) {
|
|
109
|
+
return this.onSallaReadyPromise(() => salla.product.api.fetch({ source: source, source_value: source_value, limit: limit }));
|
|
110
|
+
}
|
|
97
111
|
}
|
|
98
112
|
export default new Helper;
|
|
99
113
|
//# sourceMappingURL=Helper.js.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AE;QACrE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;OACtC;KACF;IAED,mEAAmE;IACnE,IAAI,iBAAiB,IAAI,WAAW,EAAE;MACpC,OAAO,iBAAiB,IAAI,WAAW,CAAC;KACzC;IAED,IAAI,YAAY,KAAK,QAAQ,EAAE;MAC7B,OAAO,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;KACnE;IAED,kCAAkC;IAClC,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;EACrC,CAAC;EAED;;;KAGG;EACH,mBAAmB,CAAC,QAAQ;IAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAC,EAAE,CAAA,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;EAC1E,CAAC;EAED;;;KAGG;EACH,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK;IAEvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAE,EAAE,CAAA,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAC,MAAM,EAAC,MAAM,EAAE,YAAY,EAAC,YAAY,EAAE,KAAK,EAAC,KAAK,EAAC,CAAC,CAAC,CAAC;EACxH,CAAC;CACF;AAED,eAAe,IAAI,MAAM,CAAC","sourcesContent":["import { ProductResponse } from \"@salla.sa/twilight/types/api/product\";\n\n//TODO::reduce it to 10\nsalla.event.setMaxListeners(100);\n\nclass Helper {\n private debounce_: any;\n\n toggleElementClassIf(element, classes1, classes2, callback) {\n classes1 = Array.isArray(classes1) ? classes1 : classes1.split(' ');\n classes2 = Array.isArray(classes2) ? classes2 : classes2.split(' ');\n let isClasses1 = callback(element);\n element?.classList.remove(...(isClasses1 ? classes2 : classes1));\n element?.classList.add(...(isClasses1 ? classes1 : classes2));\n return this;\n }\n\n toggleClassIf(selector, classes1, classes2, callback) {\n document.querySelectorAll(selector).forEach(element => this.toggleElementClassIf(element, classes1, classes2, callback));\n return this;\n }\n\n isValidEmail(email) {\n const re = /^(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$/;\n return re.test(String(email).toLowerCase());\n }\n\n filterEmojies(text) {\n var characterFilter = /(?:[\\u2700-\\u27bf]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\u0023-\\u0039]\\ufe0f?\\u20e3|\\u3299|\\u3297|\\u303d|\\u3030|\\u24c2|\\ud83c[\\udd70-\\udd71]|\\ud83c[\\udd7e-\\udd7f]|\\ud83c\\udd8e|\\ud83c[\\udd91-\\udd9a]|\\ud83c[\\udde6-\\uddff]|\\ud83c[\\ude01-\\ude02]|\\ud83c\\ude1a|\\ud83c\\ude2f|\\ud83c[\\ude32-\\ude3a]|\\ud83c[\\ude50-\\ude51]|\\u203c|\\u2049|[\\u25aa-\\u25ab]|\\u25b6|\\u25c0|[\\u25fb-\\u25fe]|\\u00a9|\\u00ae|\\u2122|\\u2139|\\ud83c\\udc04|[\\u2600-\\u26FF]|\\u2b05|\\u2b06|\\u2b07|\\u2b1b|\\u2b1c|\\u2b50|\\u2b55|\\u231a|\\u231b|\\u2328|\\u23cf|[\\u23e9-\\u23f3]|[\\u23f8-\\u23fa]|\\ud83c\\udccf|\\u2934|\\u2935|[\\u2190-\\u21ff])/g;\n return text.replace(characterFilter, \"\");\n }\n\n debounce(fn, ...data) {\n if (!this.debounce_) {\n this.debounce_ = salla.helpers.debounce((callback, ...innerData) => callback(...innerData), 500);\n }\n //@ts-ignore\n return this.debounce_(fn, ...data);\n }\n\n getProductsSource(source) {\n return {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'product.index.search': 'search',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n 'product.index.sales': 'sales',\n 'components.most_sales_products': 'sales',//temporary, delete it after two days from now\n }[source || salla.config.get('page.slug')] || source || 'latest';\n }\n\n getPageTitleForSource(source){\n \n source= {\n 'brands':'common.titles.brands',\n // 'categories':'',\n 'latest':'blocks.home.latest_products',\n 'offers':'common.titles.discounts',\n // 'search':'',\n // 'landing-page':'',\n // 'tags':'',\n 'sales':'common.titles.most_sales',\n }[source];\n\n return source ? salla.lang.get(source):'';\n }\n\n getProductsSourceValue(source, sourceValue) {\n const parsedSource = this.getProductsSource(source);\n\n // Validate if the source value is a valid JSON string\n let parsedSourceValue: any = null;\n if (sourceValue) {\n try {\n parsedSourceValue = JSON.parse(sourceValue);\n } catch (error) {\n console.error('Invalid JSON string in sourceValue:', error);\n }\n }\n\n // Handle different source types\n if (!['search', 'json', 'offers', 'latest', 'sales', 'related'].includes(parsedSource)) {\n\n if (Array.isArray(parsedSourceValue) && parsedSourceValue.length) {\n return parsedSourceValue;\n }\n \n if (Array.isArray(parsedSourceValue) && !parsedSourceValue.length){\n return '';\n }\n\n if (typeof parsedSourceValue === 'number') {\n return [parsedSourceValue];\n }\n\n if (!sourceValue && ['categories', 'tags', 'brands'].includes(source)) {\n return [salla.config.get('page.id')];\n }\n }\n\n // Return sourceValue if it exists and is a valid JSON object/array\n if (parsedSourceValue || sourceValue) {\n return parsedSourceValue || sourceValue;\n }\n\n if (parsedSource === 'search') {\n return new URLSearchParams(window.location.search).get('q') || '';\n }\n\n // Return page id as default value\n return salla.config.get('page.id');\n }\n\n /**\n * We needed this function to help us avoid requesting the products list before salla is ready,\n * was causing a strange issues in live for the bad connections ex: not loading the dom, requesting api without storeIdentefire\n */\n onSallaReadyPromise(callback): Promise<any>{\n return new Promise((resolve)=>salla.onReady(() => resolve(callback())));\n }\n\n /**\n * \n * let's make sure to send the request only when salla is ready\n */\n fetchProducts(source, source_value, limit): Promise<ProductResponse.lists>\n {\n return this.onSallaReadyPromise(()=>salla.product.api.fetch({source:source, source_value:source_value, limit:limit}));\n }\n}\n\nexport default new Helper;\n"]}
|