@salla.sa/twilight-components 2.11.126 → 2.11.128
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-63d6ab45.js → Helper-f14223e6.js} +48 -1
- package/dist/cjs/Helper-f14223e6.js.map +1 -0
- package/dist/cjs/app-globals-8c76baa2.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js +2 -2
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-filters-widget.cjs.entry.js +1 -1
- package/dist/cjs/salla-products-list.cjs.entry.js +27 -47
- package/dist/cjs/salla-products-list.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-slider.cjs.entry.js +9 -35
- package/dist/cjs/salla-products-slider.cjs.entry.js.map +1 -1
- package/dist/cjs/twilight.cjs.js +1 -1
- package/dist/collection/Helpers/Helper.js +47 -0
- package/dist/collection/Helpers/Helper.js.map +1 -1
- package/dist/collection/components/salla-products-list/salla-products-list.js +27 -47
- 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 +26 -52
- package/dist/collection/components/salla-products-slider/salla-products-slider.js.map +1 -1
- package/dist/collection/components/salla-quantity-input/salla-quantity-input.js +1 -1
- package/dist/collection/components/salla-quantity-input/salla-quantity-input.js.map +1 -1
- package/dist/components/Helper.js +47 -0
- package/dist/components/Helper.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/salla-products-list.js +27 -47
- package/dist/components/salla-products-list.js.map +1 -1
- package/dist/components/salla-products-slider.js +10 -36
- package/dist/components/salla-products-slider.js.map +1 -1
- package/dist/components/salla-quantity-input.js +1 -1
- package/dist/components/salla-quantity-input.js.map +1 -1
- package/dist/esm/{Helper-30bbdc37.js → Helper-a7971963.js} +48 -1
- package/dist/esm/Helper-a7971963.js.map +1 -0
- package/dist/esm/app-globals-8e3be062.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/salla-add-product-button_40.entry.js +2 -2
- package/dist/esm/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm/salla-filters-widget.entry.js +1 -1
- package/dist/esm/salla-products-list.entry.js +27 -47
- package/dist/esm/salla-products-list.entry.js.map +1 -1
- package/dist/esm/salla-products-slider.entry.js +9 -35
- package/dist/esm/salla-products-slider.entry.js.map +1 -1
- package/dist/esm/twilight.js +1 -1
- package/dist/esm-es5/Helper-a7971963.js +5 -0
- package/dist/esm-es5/Helper-a7971963.js.map +1 -0
- package/dist/esm-es5/app-globals-8e3be062.js.map +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/salla-add-product-button_40.entry.js +1 -1
- package/dist/esm-es5/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm-es5/salla-filters-widget.entry.js +1 -1
- package/dist/esm-es5/salla-products-list.entry.js +2 -2
- 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/esm-es5/twilight.js +1 -1
- package/dist/twilight/p-0254e9be.system.js +1 -1
- package/dist/twilight/p-059b0be0.system.js.map +1 -1
- package/dist/twilight/{p-3544bca0.entry.js → p-05e73fab.entry.js} +2 -2
- package/dist/twilight/{p-3544bca0.entry.js.map → p-05e73fab.entry.js.map} +1 -1
- package/dist/twilight/p-2042f370.system.js +5 -0
- package/dist/twilight/p-2042f370.system.js.map +1 -0
- package/dist/twilight/p-24d6867a.entry.js +5 -0
- package/dist/twilight/p-24d6867a.entry.js.map +1 -0
- package/dist/twilight/p-3278e007.js.map +1 -1
- package/dist/twilight/p-5ffffea6.js +5 -0
- package/dist/twilight/p-5ffffea6.js.map +1 -0
- package/dist/twilight/p-7857f10e.system.entry.js +5 -0
- package/dist/twilight/p-7857f10e.system.entry.js.map +1 -0
- package/dist/twilight/{p-710f64c1.entry.js → p-84baa754.entry.js} +2 -2
- package/dist/twilight/p-908e0bc9.system.entry.js +5 -0
- package/dist/twilight/p-908e0bc9.system.entry.js.map +1 -0
- package/dist/twilight/{p-3ae8f976.system.entry.js → p-941f36a6.system.entry.js} +2 -2
- package/dist/twilight/{p-3ae8f976.system.entry.js.map → p-941f36a6.system.entry.js.map} +1 -1
- package/dist/twilight/{p-e4f8147f.system.entry.js → p-d38d47c0.system.entry.js} +2 -2
- package/dist/twilight/p-ef0c75da.entry.js +5 -0
- package/dist/twilight/p-ef0c75da.entry.js.map +1 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/types/Helpers/Helper.d.ts +2 -0
- package/dist/types/components/salla-products-list/salla-products-list.d.ts +4 -2
- package/dist/types/components/salla-products-slider/salla-products-slider.d.ts +6 -6
- package/package.json +5 -5
- package/dist/cjs/Helper-63d6ab45.js.map +0 -1
- package/dist/esm/Helper-30bbdc37.js.map +0 -1
- package/dist/esm-es5/Helper-30bbdc37.js +0 -5
- package/dist/esm-es5/Helper-30bbdc37.js.map +0 -1
- package/dist/twilight/p-77944169.system.js +0 -5
- package/dist/twilight/p-77944169.system.js.map +0 -1
- package/dist/twilight/p-82053aa3.system.entry.js +0 -5
- package/dist/twilight/p-82053aa3.system.entry.js.map +0 -1
- package/dist/twilight/p-be3279c0.entry.js +0 -5
- package/dist/twilight/p-be3279c0.entry.js.map +0 -1
- package/dist/twilight/p-c3539119.entry.js +0 -5
- package/dist/twilight/p-c3539119.entry.js.map +0 -1
- package/dist/twilight/p-cf703bcf.system.entry.js +0 -5
- package/dist/twilight/p-cf703bcf.system.entry.js.map +0 -1
- package/dist/twilight/p-dad8bacc.js +0 -5
- package/dist/twilight/p-dad8bacc.js.map +0 -1
- /package/dist/twilight/{p-710f64c1.entry.js.map → p-84baa754.entry.js.map} +0 -0
- /package/dist/twilight/{p-e4f8147f.system.entry.js.map → p-d38d47c0.system.entry.js.map} +0 -0
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Host, h } from '@stencil/core';
|
|
5
5
|
import anime from 'animejs';
|
|
6
6
|
import ShoppingBag from '../../assets/svg/shopping-bag.svg';
|
|
7
|
+
import Helper from '../../Helpers/Helper';
|
|
7
8
|
export class SallaProductsList {
|
|
8
9
|
constructor() {
|
|
9
10
|
this.source = undefined;
|
|
@@ -141,58 +142,37 @@ export class SallaProductsList {
|
|
|
141
142
|
this.sourceValueIsValid = false;
|
|
142
143
|
}
|
|
143
144
|
}
|
|
144
|
-
getSource() {
|
|
145
|
-
return {
|
|
146
|
-
'brands.single': 'brands',
|
|
147
|
-
'product.index': 'categories',
|
|
148
|
-
'product.index.latest': 'latest',
|
|
149
|
-
'product.index.offers': 'offers',
|
|
150
|
-
'product.index.search': 'search',
|
|
151
|
-
'landing-page': 'landing-page',
|
|
152
|
-
'product.index.tag': 'tags',
|
|
153
|
-
'product.index.sales': 'sales',
|
|
154
|
-
'components.most_sales_products': 'sales', //temporary, delete it after two days from now
|
|
155
|
-
}[this.source || salla.config.get('page.slug')] || this.source || 'latest';
|
|
156
|
-
}
|
|
157
|
-
getSourceValue() {
|
|
158
|
-
let source = this.getSource();
|
|
159
|
-
//todo:: enhance this code, it call JSON.parse too many times.
|
|
160
|
-
if (!['search', 'json', 'offers', 'latest', 'sales'].includes(source)) {
|
|
161
|
-
if (this.sourceValue && Array.isArray(JSON.parse(this.sourceValue)) && JSON.parse(this.sourceValue).length) {
|
|
162
|
-
return JSON.parse(this.sourceValue);
|
|
163
|
-
}
|
|
164
|
-
if (this.sourceValue && typeof JSON.parse(this.sourceValue) == 'number') {
|
|
165
|
-
return [JSON.parse(this.sourceValue)];
|
|
166
|
-
}
|
|
167
|
-
if (!this.sourceValue && ['categories', 'tags', 'brands'].includes(this.getSource())) {
|
|
168
|
-
return [salla.config.get('page.id')];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (this.sourceValue) {
|
|
172
|
-
return this.sourceValue;
|
|
173
|
-
}
|
|
174
|
-
if (source === 'search') {
|
|
175
|
-
return (new URLSearchParams(window.location.search)).get('q');
|
|
176
|
-
}
|
|
177
|
-
return salla.config.get('page.id');
|
|
178
|
-
}
|
|
179
145
|
loading(isLoading = true) {
|
|
180
146
|
this.btnLoader.style.display = isLoading ? 'inherit' : 'none';
|
|
181
147
|
}
|
|
182
148
|
getItemHTML(product) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
149
|
+
const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';
|
|
150
|
+
const productCard = document.createElement(customComponentTag);
|
|
151
|
+
productCard.product = product;
|
|
152
|
+
this.applyLandingPageStyles(productCard);
|
|
153
|
+
this.applyHorizontalCardStyles(productCard);
|
|
154
|
+
return productCard;
|
|
155
|
+
}
|
|
156
|
+
applyLandingPageStyles(productCard) {
|
|
157
|
+
if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {
|
|
158
|
+
productCard.toggleAttribute('hide-add-btn', true);
|
|
159
|
+
productCard.classList.add('s-product-card-fit-height');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
applyHorizontalCardStyles(productCard) {
|
|
163
|
+
if (!this.horizontalCards) {
|
|
164
|
+
return;
|
|
190
165
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
166
|
+
productCard.setAttribute('horizontal', true);
|
|
167
|
+
if (!this.hasCustomComponent) {
|
|
168
|
+
productCard.setAttribute('shadow-on-hover', true);
|
|
194
169
|
}
|
|
195
|
-
|
|
170
|
+
}
|
|
171
|
+
getSource() {
|
|
172
|
+
return Helper.getProductsSource(this.source);
|
|
173
|
+
}
|
|
174
|
+
getSourceValue() {
|
|
175
|
+
return Helper.getProductsSourceValue(this.source, this.sourceValue);
|
|
196
176
|
}
|
|
197
177
|
fetchProducts() {
|
|
198
178
|
salla.product.fetch({
|
|
@@ -223,7 +203,7 @@ export class SallaProductsList {
|
|
|
223
203
|
this.infiniteScroll.on('request', () => this.loading());
|
|
224
204
|
this.infiniteScroll.on('load', response => {
|
|
225
205
|
var _a;
|
|
226
|
-
if (!((_a = response.data) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
206
|
+
if (!((_a = response.data) === null || _a === void 0 ? void 0 : _a.length) && this.infiniteScroll.pageIndex == 2) {
|
|
227
207
|
this.showPlaceholder = true;
|
|
228
208
|
salla.infiniteScroll.destroy(this.infiniteScroll);
|
|
229
209
|
this.loading(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"salla-products-list.js","sourceRoot":"","sources":["../../../src/components/salla-products-list/salla-products-list.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AAC/E,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,WAAW,MAAM,mCAAmC,CAAC;AAM5D,MAAM,OAAO,iBAAiB;;;;;;;;gBA+FJ,CAAC;;;;;;;;;;EA9FzB,iBAAiB;IACf,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;MACjB,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;MAC5E,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;MACnF,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;MACrG,IAAI;QACF,IAAI,YAAY,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,G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, Host, h, Prop, State, Element, Method} from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\n\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 @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 @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\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 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 this.nextPage += `&filters[${key}]=${value}`;\n } else if (Array.isArray(value)) {\n (value as any).forEach(item => this.nextPage += `&filters[${key}][]=${item}`)\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${key}][${k}]=${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 private getSource() {\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 }[this.source || salla.config.get('page.slug')] || this.source || 'latest';\n }\n\n private getSourceValue() {\n let source = this.getSource();\n\n //todo:: enhance this code, it call JSON.parse too many times.\n if (!['search', 'json', 'offers', 'latest', 'sales'].includes(source)) {\n if (this.sourceValue && Array.isArray(JSON.parse(this.sourceValue)) && JSON.parse(this.sourceValue).length) {\n return JSON.parse(this.sourceValue);\n }\n\n if (this.sourceValue && typeof JSON.parse(this.sourceValue) == 'number') {\n return [JSON.parse(this.sourceValue)];\n }\n if (!this.sourceValue && ['categories', 'tags', 'brands'].includes(this.getSource())) {\n return [salla.config.get('page.id')];\n }\n }\n\n if (this.sourceValue) {\n return this.sourceValue;\n }\n\n\n if (source === 'search') {\n return (new URLSearchParams(window.location.search)).get('q');\n }\n\n return salla.config.get('page.id');\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n let customComponentTag: string = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n let customComponent: HTMLSallaProductCardElement = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n customComponent.product = product;\n // customComponent.setAttribute('product', JSON.stringify(product));\n if (this.getSource() == 'landing-page' && !this.hasCustomComponent) {\n customComponent.toggleAttribute('hide-add-btn', true);\n customComponent.classList.add('s-product-card-fit-height');\n }\n if (this.horizontalCards && !this.hasCustomComponent) {\n customComponent.toggleAttribute('horizontal', true);\n customComponent.toggleAttribute('shadow-on-hover', true);\n }\n return customComponent;\n }\n\n private fetchProducts() {\n salla.product.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 })\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) {\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 if (!this.canRender()) {\n return '';\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 if (!this.canRender()) {\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 // 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 //💡 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"]}
|
|
1
|
+
{"version":3,"file":"salla-products-list.js","sourceRoot":"","sources":["../../../src/components/salla-products-list/salla-products-list.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,KAAK,MAAM,SAAS,CAAC;AAC5B,OAAO,WAAW,MAAM,mCAAmC,CAAC;AAC5D,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAK1C,MAAM,OAAO,iBAAiB;;;;;;;;gBA+FJ,CAAC;;;;;;;;;;EA9FzB,iBAAiB;IACf,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;MACjB,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;MAC5E,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;MACnF,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;MACrG,IAAI;QACF,IAAI,YAAY,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,YAAY,CAAC,GAAG,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cesContent":["import { Component, Host, h, Prop, State, Element, Method } 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 @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 @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\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 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 this.nextPage += `&filters[${key}]=${value}`;\n } else if (Array.isArray(value)) {\n (value as any).forEach(item => this.nextPage += `&filters[${key}][]=${item}`)\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${key}][${k}]=${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 salla.product.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 })\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 if (!this.canRender()) {\n return '';\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 if (!this.canRender()) {\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 // 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 //💡 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"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Crafted with ❤ by Salla
|
|
3
3
|
*/
|
|
4
4
|
import { Host, h } from '@stencil/core';
|
|
5
|
+
import Helper from '../../Helpers/Helper';
|
|
5
6
|
//todo:: extends this component from salla-products-list or the opposite
|
|
6
7
|
export class SallaProductsSlider {
|
|
7
8
|
constructor() {
|
|
@@ -9,10 +10,10 @@ export class SallaProductsSlider {
|
|
|
9
10
|
this.subTitle = undefined;
|
|
10
11
|
this.sliderId = undefined;
|
|
11
12
|
this.displayAllUrl = undefined;
|
|
13
|
+
this.autoplay = undefined;
|
|
12
14
|
this.source = undefined;
|
|
13
15
|
this.sourceValue = undefined;
|
|
14
16
|
this.limit = undefined;
|
|
15
|
-
this.autoplay = undefined;
|
|
16
17
|
this.productsData = undefined;
|
|
17
18
|
this.isReady = undefined;
|
|
18
19
|
this.sourceValueIsValid = undefined;
|
|
@@ -37,39 +38,6 @@ export class SallaProductsSlider {
|
|
|
37
38
|
}
|
|
38
39
|
return h("div", { class: "s-products-slider-card" }, h("salla-product-card", { "show-quantity": this.getSource() == 'landing-page', "hide-add-btn": this.getSource() == 'landing-page', "shadow-on-hover": true, product: product }));
|
|
39
40
|
}
|
|
40
|
-
getSource() {
|
|
41
|
-
return {
|
|
42
|
-
'brands.single': 'brands',
|
|
43
|
-
'product.index': 'categories',
|
|
44
|
-
'product.index.latest': 'latest',
|
|
45
|
-
'product.index.offers': 'offers',
|
|
46
|
-
'product.index.search': 'search',
|
|
47
|
-
'landing-page': 'landing-page',
|
|
48
|
-
'product.index.tag': 'tags',
|
|
49
|
-
}[this.source || salla.config.get('page.slug')] || this.source || 'latest';
|
|
50
|
-
}
|
|
51
|
-
getSourceValue() {
|
|
52
|
-
let source = this.getSource();
|
|
53
|
-
//todo:: enhance this code, it call JSON.parse too many times.
|
|
54
|
-
if (!['search', 'json', 'offers', 'latest', 'sales', 'related'].includes(source)) {
|
|
55
|
-
if (this.sourceValue && Array.isArray(JSON.parse(this.sourceValue)) && JSON.parse(this.sourceValue).length) {
|
|
56
|
-
return JSON.parse(this.sourceValue);
|
|
57
|
-
}
|
|
58
|
-
if (this.sourceValue && typeof JSON.parse(this.sourceValue) == 'number') {
|
|
59
|
-
return [JSON.parse(this.sourceValue)];
|
|
60
|
-
}
|
|
61
|
-
if (!this.sourceValue && ['categories', 'tags', 'brands'].includes(this.getSource())) {
|
|
62
|
-
return [salla.config.get('page.id')];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (this.sourceValue) {
|
|
66
|
-
return this.sourceValue;
|
|
67
|
-
}
|
|
68
|
-
if (source === 'search') {
|
|
69
|
-
return (new URLSearchParams(window.location.search)).get('q');
|
|
70
|
-
}
|
|
71
|
-
return salla.config.get('page.id');
|
|
72
|
-
}
|
|
73
41
|
canRender() {
|
|
74
42
|
return this.sourceValueIsValid && this.isReady;
|
|
75
43
|
}
|
|
@@ -88,12 +56,18 @@ export class SallaProductsSlider {
|
|
|
88
56
|
this.isReady = true;
|
|
89
57
|
});
|
|
90
58
|
}
|
|
59
|
+
getSource() {
|
|
60
|
+
return Helper.getProductsSource(this.source);
|
|
61
|
+
}
|
|
62
|
+
getSourceValue() {
|
|
63
|
+
return Helper.getProductsSourceValue(this.source, this.sourceValue);
|
|
64
|
+
}
|
|
91
65
|
render() {
|
|
92
66
|
var _a;
|
|
93
67
|
if ((this.getSource() == 'related' && !salla.config.get('store.settings.product.related_products_enabled')) || !this.canRender()) {
|
|
94
68
|
return;
|
|
95
69
|
}
|
|
96
|
-
return (h(Host, { class: "s-products-slider-wrapper" }, h("salla-slider", {
|
|
70
|
+
return (h(Host, { class: "s-products-slider-wrapper" }, h("salla-slider", { class: "s-products-slider-slider", id: this.sliderId || `s-products-slider-${Math.random().toString(36).substr(2, 9)}`, "auto-play": this.autoplay, type: "carousel", "block-title": this.blockTitle, "block-subTitle": this.subTitle, "display-all-url": this.displayAllUrl }, h("div", { slot: "items" }, (_a = this.productsData) === null || _a === void 0 ? void 0 : _a.map(product => this.getItemHTML(product))))));
|
|
97
71
|
}
|
|
98
72
|
static get is() { return "salla-products-slider"; }
|
|
99
73
|
static get originalStyleUrls() {
|
|
@@ -200,6 +174,23 @@ export class SallaProductsSlider {
|
|
|
200
174
|
"attribute": "display-all-url",
|
|
201
175
|
"reflect": false
|
|
202
176
|
},
|
|
177
|
+
"autoplay": {
|
|
178
|
+
"type": "boolean",
|
|
179
|
+
"mutable": true,
|
|
180
|
+
"complexType": {
|
|
181
|
+
"original": "boolean",
|
|
182
|
+
"resolved": "boolean",
|
|
183
|
+
"references": {}
|
|
184
|
+
},
|
|
185
|
+
"required": false,
|
|
186
|
+
"optional": false,
|
|
187
|
+
"docs": {
|
|
188
|
+
"tags": [],
|
|
189
|
+
"text": "autoplay option for products slider"
|
|
190
|
+
},
|
|
191
|
+
"attribute": "autoplay",
|
|
192
|
+
"reflect": false
|
|
193
|
+
},
|
|
203
194
|
"source": {
|
|
204
195
|
"type": "string",
|
|
205
196
|
"mutable": true,
|
|
@@ -259,23 +250,6 @@ export class SallaProductsSlider {
|
|
|
259
250
|
},
|
|
260
251
|
"attribute": "limit",
|
|
261
252
|
"reflect": false
|
|
262
|
-
},
|
|
263
|
-
"autoplay": {
|
|
264
|
-
"type": "boolean",
|
|
265
|
-
"mutable": true,
|
|
266
|
-
"complexType": {
|
|
267
|
-
"original": "boolean",
|
|
268
|
-
"resolved": "boolean",
|
|
269
|
-
"references": {}
|
|
270
|
-
},
|
|
271
|
-
"required": false,
|
|
272
|
-
"optional": false,
|
|
273
|
-
"docs": {
|
|
274
|
-
"tags": [],
|
|
275
|
-
"text": "autoplay option for products slider"
|
|
276
|
-
},
|
|
277
|
-
"attribute": "autoplay",
|
|
278
|
-
"reflect": false
|
|
279
253
|
}
|
|
280
254
|
};
|
|
281
255
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"salla-products-slider.js","sourceRoot":"","sources":["../../../src/components/salla-products-slider/salla-products-slider.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"salla-products-slider.js","sourceRoot":"","sources":["../../../src/components/salla-products-slider/salla-products-slider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM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AAC,UAAU,oBACZ,IAAI,CAAC,QAAQ,qBACZ,IAAI,CAAC,aAAa;QAEnC,WAAK,IAAI,EAAC,OAAO,IACd,MAAA,IAAI,CAAC,YAAY,0CAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CACzD,CACO,CACV,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAEF","sourcesContent":["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 constructor() {\n salla.onReady(() => {\n this.sourceValueIsValid = !!(this.getSource() || this.isSourceWithoutValue());\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n });\n }\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\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n componentWillLoad() {\n if (this.source === 'json') {\n this.productsData = this.getSourceValue();\n this.isReady = true\n return;\n }\n return salla.product.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit,\n }).then(res => {\n this.productsData = res.data\n this.isReady = true\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"]}
|
|
@@ -36,7 +36,7 @@ export class SallaQuantityInput {
|
|
|
36
36
|
componentDidLoad() {
|
|
37
37
|
this.didLoaded = true;
|
|
38
38
|
this.textInput.addEventListener('input', (event) => salla.helpers.inputDigitsOnly(event.target));
|
|
39
|
-
// handle quantity update from cart if exceeded the max quantity
|
|
39
|
+
// handle quantity update from cart if exceeded the max quantity and cartItemId is provided
|
|
40
40
|
this.cartItemId && salla.cart.event.onItemUpdatedFailed((data, itemId) => {
|
|
41
41
|
var _a, _b, _c, _d;
|
|
42
42
|
if (!((_d = (_c = (_b = (_a = data.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.fields) === null || _d === void 0 ? void 0 : _d.quantity)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"salla-quantity-input.js","sourceRoot":"","sources":["../../../src/components/salla-quantity-input/salla-quantity-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAG,IAAI,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,GAAG,MAAM,0BAA0B,CAAC;AAC3C,OAAO,KAAK,MAAM,4BAA4B,CAAC;AAC/C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAM1C,MAAM,OAAO,kBAAkB;;IASrB,mBAAc,GAAQ,EAAE,CAAC;IACzB,qBAAgB,GAAY,KAAK,CAAC;IAClC,qBAAgB,GAAY,KAAK,CAAC;IAGlC,cAAS,GAAY,KAAK,CAAC;;oBAEP,CAAC;2BACO,IAAI;;EAExC;;KAEG;EAEH,gBAAgB;IACd,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;MACnB,OAAO;KACR;IAED,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;MACzB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;MAC5B,OAAO;KACR;IAED,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;EACvG,CAAC;EAED,iBAAiB;IACf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/D,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,2BAA2B,CAAC,CAAC;IAC/E,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,2BAA2B,CAAC,CAAC;EACjF,CAAC;EAED,gBAAgB;IACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IACjG,
|
|
1
|
+
{"version":3,"file":"salla-quantity-input.js","sourceRoot":"","sources":["../../../src/components/salla-quantity-input/salla-quantity-input.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAG,IAAI,EAAE,MAAM,eAAe,CAAC;AACzF,OAAO,GAAG,MAAM,0BAA0B,CAAC;AAC3C,OAAO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O,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAC,QAAQ;UACnH,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,YAAM,SAAS,EAAE,KAAK,GAAS,CAAC,CAAC,CAAC,EAAE;UAC9D,YAAM,IAAI,EAAC,kBAAkB,GAAG,CACzB,CACL,CACD,CACR,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Host, State, Watch, h, Method , Prop } from '@stencil/core';\nimport Add from \"../../assets/svg/add.svg\";\nimport Minus from \"../../assets/svg/minus.svg\";\nimport Helper from '../../Helpers/Helper';\n\n@Component({\n tag: 'salla-quantity-input',\n styleUrl: 'salla-quantity-input.scss'\n})\nexport class SallaQuantityInput {\n\n @Element() host: HTMLElement;\n\n /**\n * Cart Item Id\n */\n @Prop() cartItemId;\n\n private hostAttributes: any = {};\n private hasIncrementSlot: boolean = false;\n private hasDecrementSlot: boolean = false;\n private textInput: any;\n\n private didLoaded: boolean = false;\n\n @State() quantity: number = 1;\n @State() fireChangeEvent: boolean = true;\n\n /**\n * Workaround to fire change event for the input.\n */\n @Watch('quantity')\n watchPropHandler() {\n if (!this.didLoaded) {\n return;\n }\n\n if (!this.fireChangeEvent) {\n this.fireChangeEvent = true;\n return;\n }\n\n Helper.debounce(() => salla.document.event.fireEvent(this.textInput, 'change', { 'bubbles': true }));\n }\n\n componentWillLoad() {\n this.quantity = parseInt(this.host.getAttribute('value')) || 1;\n this.hasIncrementSlot = !!this.host.querySelector('[slot=\"increment-button\"]');\n this.hasDecrementSlot = !!this.host.querySelector('[slot=\"decrement-button\"]');\n }\n\n componentDidLoad() {\n this.didLoaded = true;\n this.textInput.addEventListener('input', (event) => salla.helpers.inputDigitsOnly(event.target));\n // handle quantity update from cart if exceeded the max quantity and cartItemId is provided\n this.cartItemId && salla.cart.event.onItemUpdatedFailed((data, itemId) => {\n if (!data.response?.data?.error?.fields?.quantity) { return }\n if (this.cartItemId != itemId) { return }\n return this.setValue(this.host.getAttribute('value'), false);\n })\n }\n\n private getInputAttributes() {\n for (let i = 0; i < this.host.attributes.length; i++) {\n if (!['id', 'value', 'min', 'class'].includes(this.host.attributes[i].name)) {\n this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;\n }\n }\n\n return this.hostAttributes;\n }\n\n /**\n * decrease quantity by one.\n * @return HTMLSallaQuantityInputElement\n */\n @Method()\n async decrease() {\n return this.setValue(this.quantity - 1);\n }\n\n /**\n * increase quantity by one.\n * @return HTMLSallaQuantityInputElement\n */\n @Method()\n async increase() {\n return this.setValue(Number(this.quantity) + 1);\n }\n\n /**\n * set quantity by one.\n * @return HTMLSallaQuantityInputElement\n */\n @Method()\n async setValue(value, fireChangeEvent = true) {\n this.fireChangeEvent = fireChangeEvent;\n let maxQuantity = parseInt(this.host.getAttribute('max'));\n if (maxQuantity && value > maxQuantity) {\n value = maxQuantity;\n }\n if (value <= 1) {\n value = 1;\n }\n this.quantity = value;\n return this.host;\n }\n\n render() {\n return (\n <Host class=\"s-quantity-input\">\n <div class=\"s-quantity-input-container\">\n <button onClick={() => this.increase()} class=\"s-quantity-input-increase-button s-quantity-input-button\" type=\"button\">\n {!this.hasIncrementSlot ? <span innerHTML={Add}></span> : ''}\n <slot name=\"increment-button\" />\n </button>\n <input class=\"s-quantity-input-input\" {...this.getInputAttributes()}\n ref={(el) => this.textInput = el as HTMLInputElement}\n onInput={(event: any) => this.setValue(event.target.value)}\n min=\"1\"\n value={this.quantity} />\n <button class=\"s-quantity-input-decrease-button s-quantity-input-button\" onClick={() => this.decrease()} type=\"button\">\n {!this.hasDecrementSlot ? <span innerHTML={Minus}></span> : ''}\n <slot name=\"decrement-button\" />\n </button>\n </div>\n </Host>\n );\n }\n}\n"]}
|
|
@@ -31,6 +31,53 @@ class Helper {
|
|
|
31
31
|
//@ts-ignore
|
|
32
32
|
return this.debounce_(fn, ...data);
|
|
33
33
|
}
|
|
34
|
+
getProductsSource(source) {
|
|
35
|
+
return {
|
|
36
|
+
'brands.single': 'brands',
|
|
37
|
+
'product.index': 'categories',
|
|
38
|
+
'product.index.latest': 'latest',
|
|
39
|
+
'product.index.offers': 'offers',
|
|
40
|
+
'product.index.search': 'search',
|
|
41
|
+
'landing-page': 'landing-page',
|
|
42
|
+
'product.index.tag': 'tags',
|
|
43
|
+
'product.index.sales': 'sales',
|
|
44
|
+
'components.most_sales_products': 'sales', //temporary, delete it after two days from now
|
|
45
|
+
}[source || salla.config.get('page.slug')] || source || 'latest';
|
|
46
|
+
}
|
|
47
|
+
getProductsSourceValue(source, sourceValue) {
|
|
48
|
+
const parsedSource = this.getProductsSource(source);
|
|
49
|
+
// Validate if the source value is a valid JSON string
|
|
50
|
+
let parsedSourceValue = null;
|
|
51
|
+
if (sourceValue) {
|
|
52
|
+
try {
|
|
53
|
+
parsedSourceValue = JSON.parse(sourceValue);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('Invalid JSON string in sourceValue:', error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Handle different source types
|
|
60
|
+
if (!['search', 'json', 'offers', 'latest', 'sales', 'related'].includes(parsedSource)) {
|
|
61
|
+
if (Array.isArray(parsedSourceValue) && parsedSourceValue.length) {
|
|
62
|
+
return parsedSourceValue;
|
|
63
|
+
}
|
|
64
|
+
if (typeof parsedSourceValue === 'number') {
|
|
65
|
+
return [parsedSourceValue];
|
|
66
|
+
}
|
|
67
|
+
if (!sourceValue && ['categories', 'tags', 'brands'].includes(source)) {
|
|
68
|
+
return [salla.config.get('page.id')];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// Return sourceValue if it exists and is a valid JSON object/array
|
|
72
|
+
if (parsedSourceValue || sourceValue) {
|
|
73
|
+
return parsedSourceValue || sourceValue;
|
|
74
|
+
}
|
|
75
|
+
if (parsedSource === 'search') {
|
|
76
|
+
return new URLSearchParams(window.location.search).get('q') || '';
|
|
77
|
+
}
|
|
78
|
+
// Return page id as default value
|
|
79
|
+
return salla.config.get('page.id');
|
|
80
|
+
}
|
|
34
81
|
}
|
|
35
82
|
const Helper$1 = new Helper;
|
|
36
83
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"Helper.js","mappings":";;;AAAA;AACA,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAEjC,MAAM,MAAM;EAGV,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IACxD,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpE,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpE,IAAI,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACnC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAC,MAAM,CAAC,IAAI,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC;IACjE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,CAAC,GAAG,CAAC,IAAI,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC;IAC9D,OAAO,IAAI,CAAC;GACb;EAED,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IAClD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;IACzH,OAAO,IAAI,CAAC;GACb;EAED,YAAY,CAAC,KAAK;IAChB,MAAM,EAAE,GAAG,uJAAuJ,CAAC;IACnK,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;GAC7C;EAED,aAAa,CAAC,IAAI;IAChB,IAAI,eAAe,GAAG,gmBAAgmB,CAAC;IACvnB,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;GAC1C;EAED,QAAQ,CAAC,EAAE,EAAE,GAAG,IAAI;IAClB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;MACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,GAAG,SAAS,KAAK,QAAQ,CAAC,GAAG,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;KAClG;;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;GACpC;CACF;AAED,iBAAe,IAAI,MAAM;;;;","names":[],"sources":["./src/Helpers/Helper.ts"],"sourcesContent":["//TODO::reduce it to 10\nsalla.event.setMaxListeners(100);\n\nclass Helper {\n private debounce_: Boolean;\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\nexport default new Helper;\n"],"version":3}
|
|
1
|
+
{"file":"Helper.js","mappings":";;;AAAA;AACA,KAAK,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;AAEjC,MAAM,MAAM;EAGV,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;IACxD,QAAQ,GAAG,K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AK,QAAQ,EAAE;QACzC,OAAO,CAAC,iBAAiB,CAAC,CAAC;OAC5B;MAED,IAAI,CAAC,WAAW,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QACrE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;OACtC;KACF;;IAGD,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;;IAGD,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;GACpC;CACF;AAED,iBAAe,IAAI,MAAM;;;;","names":[],"sources":["./src/Helpers/Helper.ts"],"sourcesContent":["//TODO::reduce it to 10\nsalla.event.setMaxListeners(100);\n\nclass Helper {\n private debounce_: Boolean;\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 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 (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\nexport default new Helper;\n"],"version":3}
|