@salla.sa/twilight-components 2.11.115 → 2.11.117
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/app-globals-4ffc202e.js.map +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js +2 -1
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-filters.cjs.entry.js +10 -3
- package/dist/cjs/salla-filters.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-price-range.cjs.entry.js +1 -0
- package/dist/cjs/salla-price-range.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-list.cjs.entry.js +4 -0
- package/dist/cjs/salla-products-list.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-slider.cjs.entry.js +2 -1
- package/dist/cjs/salla-products-slider.cjs.entry.js.map +1 -1
- package/dist/cjs/twilight.cjs.js +1 -1
- package/dist/collection/components/salla-filters/salla-filters.js +10 -3
- package/dist/collection/components/salla-filters/salla-filters.js.map +1 -1
- package/dist/collection/components/salla-price-range/salla-price-range.js +1 -0
- package/dist/collection/components/salla-price-range/salla-price-range.js.map +1 -1
- package/dist/collection/components/salla-products-list/salla-products-list.js +4 -0
- 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 +19 -1
- package/dist/collection/components/salla-products-slider/salla-products-slider.js.map +1 -1
- package/dist/collection/components/salla-quick-buy/salla-quick-buy.js +2 -1
- package/dist/collection/components/salla-quick-buy/salla-quick-buy.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/salla-filters.js +10 -3
- package/dist/components/salla-filters.js.map +1 -1
- package/dist/components/salla-price-range2.js +1 -0
- package/dist/components/salla-price-range2.js.map +1 -1
- package/dist/components/salla-products-list.js +4 -0
- package/dist/components/salla-products-list.js.map +1 -1
- package/dist/components/salla-products-slider.js +3 -1
- package/dist/components/salla-products-slider.js.map +1 -1
- package/dist/components/salla-quick-buy2.js +2 -1
- package/dist/components/salla-quick-buy2.js.map +1 -1
- package/dist/esm/app-globals-fa8f5faf.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/salla-add-product-button_40.entry.js +2 -1
- package/dist/esm/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm/salla-filters.entry.js +10 -3
- package/dist/esm/salla-filters.entry.js.map +1 -1
- package/dist/esm/salla-price-range.entry.js +1 -0
- package/dist/esm/salla-price-range.entry.js.map +1 -1
- package/dist/esm/salla-products-list.entry.js +4 -0
- package/dist/esm/salla-products-list.entry.js.map +1 -1
- package/dist/esm/salla-products-slider.entry.js +2 -1
- package/dist/esm/salla-products-slider.entry.js.map +1 -1
- package/dist/esm/twilight.js +1 -1
- package/dist/esm-es5/app-globals-fa8f5faf.js.map +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/loader.js.map +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.entry.js +1 -1
- package/dist/esm-es5/salla-filters.entry.js.map +1 -1
- package/dist/esm-es5/salla-price-range.entry.js +1 -1
- package/dist/esm-es5/salla-price-range.entry.js.map +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/esm-es5/twilight.js +1 -1
- package/dist/esm-es5/twilight.js.map +1 -1
- package/dist/twilight/p-1c36dab3.system.js +1 -1
- package/dist/twilight/p-1c36dab3.system.js.map +1 -1
- package/dist/twilight/p-35a7b883.entry.js +5 -0
- package/dist/twilight/p-35a7b883.entry.js.map +1 -0
- package/dist/twilight/{p-aa4bff7e.entry.js → p-40e572fc.entry.js} +2 -2
- package/dist/twilight/{p-aa4bff7e.entry.js.map → p-40e572fc.entry.js.map} +1 -1
- package/dist/twilight/p-82053aa3.system.entry.js +5 -0
- package/dist/twilight/p-82053aa3.system.entry.js.map +1 -0
- package/dist/twilight/{p-11c9d4f1.system.entry.js → p-82469635.system.entry.js} +2 -2
- package/dist/twilight/{p-11c9d4f1.system.entry.js.map → p-82469635.system.entry.js.map} +1 -1
- package/dist/twilight/p-9756b2af.js.map +1 -1
- package/dist/twilight/{p-cda133d3.system.entry.js → p-b075bc8e.system.entry.js} +2 -2
- package/dist/twilight/p-b075bc8e.system.entry.js.map +1 -0
- package/dist/twilight/p-be3279c0.entry.js +5 -0
- package/dist/twilight/p-be3279c0.entry.js.map +1 -0
- package/dist/twilight/p-c3539119.entry.js +5 -0
- package/dist/twilight/p-c3539119.entry.js.map +1 -0
- package/dist/twilight/p-ce7f7f7d.system.js.map +1 -1
- package/dist/twilight/p-cf703bcf.system.entry.js +5 -0
- package/dist/twilight/p-cf703bcf.system.entry.js.map +1 -0
- package/dist/twilight/p-d4d0a75e.entry.js +5 -0
- package/dist/twilight/p-d4d0a75e.entry.js.map +1 -0
- package/dist/twilight/{p-2739ddc5.system.entry.js → p-f6c7b904.system.entry.js} +2 -2
- package/dist/twilight/p-f6c7b904.system.entry.js.map +1 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.esm.js.map +1 -1
- package/dist/types/components/salla-products-slider/salla-products-slider.d.ts +4 -0
- package/dist/types/components.d.ts +8 -0
- package/package.json +5 -5
- package/dist/twilight/p-1726b13b.entry.js +0 -5
- package/dist/twilight/p-1726b13b.entry.js.map +0 -1
- package/dist/twilight/p-2739ddc5.system.entry.js.map +0 -1
- package/dist/twilight/p-7180e106.entry.js +0 -5
- package/dist/twilight/p-7180e106.entry.js.map +0 -1
- package/dist/twilight/p-8dbe3def.system.entry.js +0 -5
- package/dist/twilight/p-8dbe3def.system.entry.js.map +0 -1
- package/dist/twilight/p-bada2f30.system.entry.js +0 -5
- package/dist/twilight/p-bada2f30.system.entry.js.map +0 -1
- package/dist/twilight/p-cd5cb2f7.entry.js +0 -5
- package/dist/twilight/p-cd5cb2f7.entry.js.map +0 -1
- package/dist/twilight/p-cda133d3.system.entry.js.map +0 -1
- package/dist/twilight/p-f1d68104.entry.js +0 -5
- package/dist/twilight/p-f1d68104.entry.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["sallaProductsListCss","SallaProductsList","exports","class_1","prototype","connectedCallback","_this","this","salla","onReady","hasCustomComponent","customElements","get","sourceValueIsValid","getSourceValue","isSourceWithoutValue","hasInfiniteScroll","includes","getSource","searchParams","URLSearchParams","window","location","search","sortBy","filters","parsedFilters","JSON","parse","decodeURIComponent","e","logger","warn","message","buildNextPageUrl","createStatusDom","isReady","concat","event","on","setFilters","reload","infiniteScroll","destroy","wrapper","innerHTML","init","isFilterable","config","filtersResults","animateItems","anime","targets","opacity","duration","translateY","delay","_el","i","status","document","createElement","className","lang","btnLoader","querySelector","onLoaded","placeholderText","initBaseNextPageUrl","source","nextPage","url","api","limit","key","value","this_1","Array","isArray","forEach","item","_d","_e","Object","entries","length","_f","k","v","_i","_b","_c","join","sourceValue","loading","isLoading","style","display","getItemHTML","product","customComponentTag","customComponent","toggleAttribute","classList","add","horizontalCards","fetchProducts","fetch","source_value","then","res","data","showPlaceholder","handleResponse","card","append","initiateInfiniteScroll","host","insertAdjacentElement","initiate","path","history","scrollThreshold","response","_a","appendItems","pageIndex","remove","loadNextPage","canRender","render","h","class","ShoppingBag","Host","ref","componentDidLoad","map","emit","cursor","next","option","loadOnScroll"],"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} 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 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.getItem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SAAeU,GAAf,IAAArH,EAAAC,K,MAEN,GAAIoH,EAASlG,SAAWlB,KAAKwC,eAAgB,CAC3CxC,KAAK0C,eAAiB,KACtBzC,MAAM8B,MAAMoG,KAAK,mBAAoB,CAACjH,QAASkG,EAASlG,S,MACnD,GAAIlB,KAAKwC,eAAgB,CAC9BvC,MAAM8B,MAAMoG,KAAK,kB,CAEnBnI,KAAK+D,SAAWqD,EAASgB,OAAShB,EAASgB,OAAOC,KAAOrI,KAAK+D,SAC9D/D,KAAKuF,QAAQ,OACb,GAAIvF,KAAKS,oBAAsBT,KAAK+D,SAAU,CAC5C/D,KAAKmC,eAAemG,OAAO,CAACnB,gBAAiB,MAAOoB,aAAc,QAClEvI,KAAKoD,OAAOM,cAAc,2BAA2BsC,UAAUwB,OAAO,W,CAExE,QAAOH,EAAAD,EAASZ,QAAI,MAAAa,SAAA,SAAAA,EAAEa,KAAI,SAAAtC,GAAW,OAAA7F,EAAK4F,YAAYC,EAAjB,MAA8B,E,yHAxXzC,I"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Crafted with ❤ by Salla
|
|
3
|
-
*/
|
|
4
|
-
System.register(["./p-5ee0461b.system.js"],(function(e){"use strict";var t,s,r,i;return{setters:[function(e){t=e.r;s=e.h;r=e.H;i=e.g}],execute:function(){var u="";var a=e("salla_products_slider",function(){function e(e){var s=this;t(this,e);this.blockTitle=undefined;this.subTitle=undefined;this.sliderId=undefined;this.displayAllUrl=undefined;this.source=undefined;this.sourceValue=undefined;this.limit=undefined;this.productsData=undefined;this.isReady=undefined;this.sourceValueIsValid=undefined;this.hasCustomComponent=undefined;this.apiUrl="";this.parsedSourceValue=undefined;salla.onReady((function(){s.sourceValueIsValid=!!(s.getSource()||s.isSourceWithoutValue());if(!s.sourceValueIsValid){salla.logger.warn("source-value prop is required for source [".concat(s.getSource(),"]"));return}s.hasCustomComponent=!!customElements.get("custom-salla-product-card")}))}e.prototype.isSourceWithoutValue=function(){return["offers","latest","sales"].includes(this.getSource())};e.prototype.getItemHTML=function(e){if(this.hasCustomComponent){return s("div",{class:"s-products-slider-card"},s("custom-salla-product-card",{product:e,source:this.getSource(),"source-value":this.getSourceValue()}))}return s("div",{class:"s-products-slider-card"},s("salla-product-card",{"show-quantity":this.getSource()=="landing-page","hide-add-btn":this.getSource()=="landing-page","shadow-on-hover":true,product:e}))};e.prototype.getSource=function(){return{"brands.single":"brands","product.index":"categories","product.index.latest":"latest","product.index.offers":"offers","product.index.search":"search","landing-page":"landing-page","product.index.tag":"tags"}[this.source||salla.config.get("page.slug")]||this.source||"latest"};e.prototype.getSourceValue=function(){var e=this.getSource();if(!["search","json","offers","latest","sales","related"].includes(e)){if(this.sourceValue&&Array.isArray(JSON.parse(this.sourceValue))&&JSON.parse(this.sourceValue).length){return JSON.parse(this.sourceValue)}if(this.sourceValue&&typeof JSON.parse(this.sourceValue)=="number"){return[JSON.parse(this.sourceValue)]}if(!this.sourceValue&&["categories","tags","brands"].includes(this.getSource())){return[salla.config.get("page.id")]}}if(this.sourceValue){return this.sourceValue}if(e==="search"){return new URLSearchParams(window.location.search).get("q")}return salla.config.get("page.id")};e.prototype.canRender=function(){return this.sourceValueIsValid&&this.isReady};e.prototype.componentWillLoad=function(){var e=this;if(this.source==="json"){this.productsData=this.getSourceValue();this.isReady=true;return}return salla.product.fetch({source:this.getSource(),source_value:this.getSourceValue(),limit:this.limit}).then((function(t){e.productsData=t.data;e.isReady=true}))};e.prototype.render=function(){var e=this;var t;if(this.getSource()=="related"&&!salla.config.get("store.settings.product.related_products_enabled")||!this.canRender()){return}return s(r,{class:"s-products-slider-wrapper"},s("salla-slider",{class:"s-products-slider-slider",id:this.sliderId||"s-products-slider-".concat(Math.random().toString(36).substr(2,9)),type:"carousel","block-title":this.blockTitle,"block-subTitle":this.subTitle,"display-all-url":this.displayAllUrl},s("div",{slot:"items"},(t=this.productsData)===null||t===void 0?void 0:t.map((function(t){return e.getItemHTML(t)})))))};Object.defineProperty(e.prototype,"host",{get:function(){return i(this)},enumerable:false,configurable:true});return e}());a.style=u}}}));
|
|
5
|
-
//# sourceMappingURL=p-bada2f30.system.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["sallaProductsSliderCss","SallaProductsSlider","exports","class_1","hostRef","_this","this","salla","onReady","sourceValueIsValid","getSource","isSourceWithoutValue","logger","warn","concat","hasCustomComponent","customElements","get","prototype","includes","getItemHTML","product","h","class","source","getSourceValue","config","sourceValue","Array","isArray","JSON","parse","length","URLSearchParams","window","location","search","canRender","isReady","componentWillLoad","productsData","fetch","source_value","limit","then","res","data","render","Host","id","sliderId","Math","random","toString","substr","type","blockTitle","subTitle","displayAllUrl","slot","_a","map"],"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';\n\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 * 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 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 }[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' , 'related'].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 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\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 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"],"mappings":";;;0JAAA,IAAMA,EAAyB,G,ICQlBC,EAAmBC,EAAA,mCAC9B,SAAAC,EAAAC,GAAA,IAAAC,EAAAC,K,0TA2E0B,G,iCA1ExBC,MAAMC,SAAQ,WACZH,EAAKI,sBAAwBJ,EAAKK,aAAeL,EAAKM,wBACtD,IAAKN,EAAKI,mBAAoB,CAC5BF,MAAMK,OAAOC,KAAK,6CAAAC,OAA6CT,EAAKK,YAAW,MAC/E,M,CAEFL,EAAKU,qBAAuBC,eAAeC,IAAI,4B,IAG3Cd,EAAAe,UAAAP,qBAAA,WACN,MAAO,CAAC,SAAU,SAAU,SAASQ,SAASb,KAAKI,Y,EAmE7CP,EAAAe,UAAAE,YAAA,SAAYC,GAClB,GAAIf,KAAKS,mB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AAAe,UAAAqB,kBAAA,eAAAlC,EAAAC,KACE,GAAIA,KAAKkB,SAAW,OAAQ,CAC1BlB,KAAKkC,aAAelC,KAAKmB,iBACzBnB,KAAKgC,QAAU,KACf,M,CAEF,OAAQ/B,MAAMc,QAAQoB,MAAM,CAC1BjB,OAAQlB,KAAKI,YACbgC,aAAcpC,KAAKmB,iBACnBkB,MAAOrC,KAAKqC,QACXC,MAAK,SAAAC,GACNxC,EAAKmC,aAAeK,EAAIC,KACxBzC,EAAKiC,QAAU,I,KAInBnC,EAAAe,UAAA6B,OAAA,eAAA1C,EAAAC,K,MACE,GAAKA,KAAKI,aAAe,YAAcH,MAAMmB,OAAOT,IAAI,qDAAwDX,KAAK+B,YAAa,CAChI,M,CAEF,OACEf,EAAC0B,EAAI,CAACzB,MAAM,6BACVD,EAAA,gBACEC,MAAM,2BACN0B,GAAI3C,KAAK4C,UAAY,qBAAApC,OAAqBqC,KAAKC,SAASC,SAAS,IAAIC,OAAO,EAAG,IAC/EC,KAAK,WAAU,cACFjD,KAAKkD,WAAU,iBACZlD,KAAKmD,SAAQ,kBACZnD,KAAKoD,eAEtBpC,EAAA,OAAKqC,KAAK,UACPC,EAAAtD,KAAKkC,gBAAY,MAAAoB,SAAA,SAAAA,EAAEC,KAAI,SAAAxC,GAAW,OAAAhB,EAAKe,YAAYC,EAAjB,M,yHA3Kf,I"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Crafted with ❤ by Salla
|
|
3
|
-
*/
|
|
4
|
-
import{r as t,c as s,h as i,H as e,g as a}from"./p-3c7d3f26.js";import{F as l,a as r}from"./p-d3cc3770.js";const n=":host{display:block}.s-rating-stars-small{line-height:12px}.s-filters-radio{background-image:none !important}";const o=class{constructor(i){t(this,i);this.changed=s(this,"changed",7);this.isReady=false;this.filters=undefined;this.isSidebarOpen=undefined;this.filtersData={};this.apply=undefined;this.reset=undefined;salla.event.on("filters::hidden",(()=>this.host.style.display="none"));salla.lang.onLoaded((()=>{this.apply=salla.lang.get("pages.checkout.apply");this.reset=salla.lang.get("pages.categories.filters_reset")}));salla.event.on("filters::fetched",(({filters:t})=>{this.host.style.display="";let s={};this.filters=t.map((t=>{t.label={category_id:salla.lang.get("common.titles.categories"),brand_id:salla.lang.get("common.titles.brands"),rating:salla.lang.get("pages.categories.filter_rating"),price_range:salla.lang.get("pages.categories.filter_price")}[t.key]||t.label;t.inputType=l.CHECKBOX;if(t.key=="rating"){t.inputType=l.RADIO;let{max:s,min:i}=t.values;t.values=[5,4,3,2,1].filter((t=>t>=i||t<=s))}if(this.filtersData[t.key]){s[t.key]=this.filtersData[t.key]}return t}));this.filtersData=s}))}connectedCallback(){try{let t=new URLSearchParams(window.location.search).get("filters");this.filtersData=t?JSON.parse(decodeURIComponent(t)):{}}catch(t){salla.logger.warn("failed to get filters from url",t.message)}}async getFilters(){return this.filtersData}async applyFilters(){if(!this.isReady){return}window.scrollTo({top:0,behavior:"smooth"});setTimeout((()=>{window.history.pushState({},"",salla.url.addParamToUrl("filters",encodeURIComponent(JSON.stringify(this.filtersData))));salla.event.emit("salla-filters::changed",this.filtersData);this.changed.emit(this.filtersData)}),300)}async resetFilters(){this.filtersData={};this.host.childNodes.forEach((t=>t.reset&&t.reset()));salla.event.emit("salla-filters::reset");return this.applyFilters()}handleOptionChange(t,s,i){if(s.type===r.RANGE){this.filtersData[s.key]=i;return}let e=t.target.checked;if(t.target.type==l.RADIO){e&&(this.filtersData[s.key]=i);e||delete this.filtersData[s.key];return}this.filtersData[s.key]=this.filtersData[s.key]||[];if(e){this.filtersData[s.key].push(i);return}this.filtersData[s.key]=this.filtersData[s.key].filter((t=>t!=i))}render(){var t,s;return i(e,null,(t=this.filters)===null||t===void 0?void 0:t.map((t=>i("salla-filters-widget",{option:t,filtersData:this.filtersData,onChanged:({detail:{event:t,option:s,value:i}})=>this.handleOptionChange(t,s,i)}))),((s=this.filters)===null||s===void 0?void 0:s.length)&&i("div",{class:"s-filters-footer"},i("salla-button",{color:"primary",onClick:()=>this.applyFilters()},this.apply),i("salla-button",{color:"gray",fill:"outline",onClick:()=>this.resetFilters()},this.reset)))}componentDidLoad(){this.isReady=true}get host(){return a(this)}};o.style=n;export{o as salla_filters};
|
|
5
|
-
//# sourceMappingURL=p-cd5cb2f7.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["sallaFiltersCss","SallaFilters","constructor","hostRef","this","isReady","salla","event","on","host","style","display","lang","onLoaded","apply","get","reset","filters","freshFilterData","map","filter","label","category_id","brand_id","rating","price_range","key","inputType","FilterOptionInputType","CHECKBOX","RADIO","max","min","values","stars","filtersData","connectedCallback","URLSearchParams","window","location","search","JSON","parse","decodeURIComponent","e","logger","warn","message","async","scrollTo","top","behavior","setTimeout","history","pushState","url","addParamToUrl","encodeURIComponent","stringify","emit","changed","childNodes","forEach","widget","applyFilters","handleOptionChange","option","value","type","FilterOptionTypes","RANGE","isChecked","target","checked","push","val","render","h","Host","_a","onChanged","detail","_b","length","class","color","onClick","fill","resetFilters","componentDidLoad"],"sources":["./src/components/salla-filters/salla-filters.scss?tag=salla-filters","./src/components/salla-filters/salla-filters.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n.s-rating-stars-small {\n line-height: 12px;\n}\n.s-filters-radio{\n background-image: none !important;\n}","import { Component, Element, h, Event, EventEmitter, Host, Method, Prop, State } from '@stencil/core';\nimport { Filter, FilterOptionInputType, FilterOptionTypes } from \"./interfaces\";\n\n//todo::\n\n\n@Component({\n tag: 'salla-filters',\n styleUrl: 'salla-filters.scss',\n})\nexport class SallaFilters {\n\n constructor() {\n salla.event.on('filters::hidden', () => this.host.style.display = 'none');\n\n salla.lang.onLoaded(() => {\n this.apply = salla.lang.get('pages.checkout.apply');\n this.reset = salla.lang.get('pages.categories.filters_reset');\n });\n\n salla.event.on('filters::fetched', ({ filters }) => {\n this.host.style.display = '';\n let freshFilterData = {};\n this.filters = filters\n .map((filter: Filter) => {\n filter.label = {\n category_id: salla.lang.get('common.titles.categories'),\n brand_id: salla.lang.get('common.titles.brands'),\n rating: salla.lang.get('pages.categories.filter_rating'),\n price_range: salla.lang.get('pages.categories.filter_price'),\n }[filter.key] || filter.label;\n filter.inputType = FilterOptionInputType.CHECKBOX;\n if (filter.key == 'rating') {\n filter.inputType = FilterOptionInputType.RADIO;\n //@ts-ignore\n let { max, min } = filter.values;\n //@ts-ignore\n filter.values = [5, 4, 3, 2, 1].filter(stars => stars >= min || stars <= max)\n }\n\n //when getting new filters, maybe less than we had, so let's get from the old one, only what is existed now.\n if (this.filtersData[filter.key]) {\n freshFilterData[filter.key] = this.filtersData[filter.key];\n }\n\n return filter;\n });\n this.filtersData = freshFilterData;\n });\n }\n\n connectedCallback() {\n try {\n let filters = (new URLSearchParams(window.location.search)).get('filters')\n this.filtersData = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n }\n\n @Element() host: HTMLElement;\n @Prop({ reflect: true, mutable: true }) filters?: Filter[];\n private isReady = false;//to avoid triggering the changed event\n @State() isSidebarOpen: boolean;\n @State() filtersData: object = {}\n @State() apply: string;\n @State() reset: string;\n @Event() changed: EventEmitter;\n\n //TODO:: move all @methods into one section\n @Method()\n async getFilters() {\n return this.filtersData;\n }\n\n @Method()\n async applyFilters() {\n if (!this.isReady) {\n return;\n }\n //todo:: why we need this🤔\n window.scrollTo({top: 0,behavior: 'smooth'});\n setTimeout(() => {\n window.history.pushState({}, '', salla.url.addParamToUrl('filters', encodeURIComponent(JSON.stringify(this.filtersData))));\n salla.event.emit('salla-filters::changed', this.filtersData);\n this.changed.emit(this.filtersData);\n }, 300);\n }\n\n @Method()\n async resetFilters() {\n this.filtersData = {};\n this.host.childNodes.forEach((widget: HTMLSallaFiltersWidgetElement) => widget.reset && widget.reset())\n salla.event.emit('salla-filters::reset');\n return this.applyFilters();\n }\n\n /**\n * @param {{target:HTMLInputElement}} event\n * @param option\n * @param value\n * @private\n */\n private handleOptionChange(event, option: Filter, value) {\n if (option.type === FilterOptionTypes.RANGE) {\n this.filtersData[option.key] = value;\n return;\n }\n let isChecked = event.target.checked;\n if (event.target.type == FilterOptionInputType.RADIO) {\n isChecked && (this.filtersData[option.key] = value);\n isChecked || (delete this.filtersData[option.key]);\n return;\n }\n\n //it's checkbox\n this.filtersData[option.key] = this.filtersData[option.key] || [];\n if (isChecked) {\n this.filtersData[option.key].push(value);\n return;\n }\n this.filtersData[option.key] = this.filtersData[option.key].filter(val => val != value);\n }\n\n render() {\n return <Host>\n {this.filters?.map(option => <salla-filters-widget\n option={option}\n filtersData={this.filtersData}\n onChanged={({ detail: { event, option, value } }) => this.handleOptionChange(event, option, value)} />)}\n\n {this.filters?.length && <div class=\"s-filters-footer\">\n <salla-button color='primary' onClick={() => this.applyFilters()}>{this.apply}</salla-button>\n <salla-button color='gray' fill='outline' onClick={() => this.resetFilters()}>{this.reset}</salla-button>\n </div>}\n </Host>;\n }\n\n componentDidLoad() {\n this.isReady = true;\n }\n}\n\n"],"mappings":";;;2GAAA,MAAMA,EAAkB,gH,MCUXC,EAAY,MAEvBC,YAAAC,G,2CAkDQC,KAAAC,QAAU,M,qEAEa,G,0CAnD7BC,MAAMC,MAAMC,GAAG,mBAAmB,IAAMJ,KAAKK,KAAKC,MAAMC,QAAU,SAElEL,MAAMM,KAAKC,UAAS,KAClBT,KAAKU,MAAQR,MAAMM,KAAKG,IAAI,wBAC5BX,KAAKY,MAAQV,MAAMM,KAAKG,IAAI,iCAAiC,IAG/DT,MAAMC,MAAMC,GAAG,oBAAoB,EAAGS,cACpCb,KAAKK,KAAKC,MAAMC,QAAU,GAC1B,IAAIO,EAAkB,GACtBd,KAAKa,QAAUA,EACZE,KAAKC,IACJA,EAAOC,MAAQ,CACbC,YAAahB,MAAMM,KAAKG,IAAI,4BAC5BQ,SAAUjB,MAAMM,KAAKG,IAAI,wBACzBS,OAAQlB,MAAMM,KAAKG,IAAI,kCACvBU,YAAanB,MAAMM,K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,KAAK+B,YAAY+B,EAAOxC,KAAOyC,EAC/B,M,CAEF,IAAII,EAAYhE,EAAMiE,OAAOC,QAC7B,GAAIlE,EAAMiE,OAAOJ,MAAQxC,EAAsBE,MAAO,CACpDyC,IAAcnE,KAAK+B,YAAY+B,EAAOxC,KAAOyC,GAC7CI,UAAqBnE,KAAK+B,YAAY+B,EAAOxC,KAC7C,M,CAIFtB,KAAK+B,YAAY+B,EAAOxC,KAAOtB,KAAK+B,YAAY+B,EAAOxC,MAAQ,GAC/D,GAAI6C,EAAW,CACbnE,KAAK+B,YAAY+B,EAAOxC,KAAKgD,KAAKP,GAClC,M,CAEF/D,KAAK+B,YAAY+B,EAAOxC,KAAOtB,KAAK+B,YAAY+B,EAAOxC,KAAKN,QAAOuD,GAAOA,GAAOR,G,CAGnFS,S,QACE,OAAOC,EAACC,EAAI,MACTC,EAAA3E,KAAKa,WAAO,MAAA8D,SAAA,S,EAAE5D,KAAI+C,GAAUW,EAAA,wBAC3BX,OAAQA,EACR/B,YAAa/B,KAAK+B,YAClB6C,UAAW,EAAGC,QAAU1E,QAAO2D,SAAQC,YAAc/D,KAAK6D,mBAAmB1D,EAAO2D,EAAQC,SAE7Fe,EAAA9E,KAAKa,WAAO,MAAAiE,SAAA,SAAAA,EAAEC,SAAUN,EAAA,OAAKO,MAAM,oBAClCP,EAAA,gBAAcQ,MAAM,UAAUC,QAAS,IAAMlF,KAAK4D,gBAAiB5D,KAAKU,OACxE+D,EAAA,gBAAcQ,MAAM,OAAOE,KAAK,UAAUD,QAAS,IAAMlF,KAAKoF,gBAAiBpF,KAAKY,Q,CAK1FyE,mBACErF,KAAKC,QAAU,I"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["sallaPriceRangeCss","SallaPriceRange","exports","this","filterValues","class_1","prototype","connectedCallback","filtersData","_a","price","minPrice","min","maxPrice","max","option","values","length","chunkSize","Math","ceil","i","push","slice","reduce","final","currentValue","to","count","reset","minInput","value","maxInput","getPriceLabel","filterValue","isNaN","from","concat","salla","money","handleMinMaxPrice","event","changedEventHandler","isMin","target","minInputValidation","maxInputValidation","isReady","changed","emit","isChecked","isMinEqual","isMaxEqual","render","_this","h","Host","map","index","class","htmlFor","key","id","name","type","checked","onChange","e","config","currency","symbol","maxlength","ref","el","onInput","placeholder","componentDidLoad"],"sources":["src/components/salla-price-range/salla-price-range.scss?tag=salla-price-range","src/components/salla-price-range/salla-price-range.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n\n.rtl, [dir=\"rtl\"] {\n .rtl-range-slider {\n transform: rotateY(180deg);\n }\n\n .rtl-range-numbers{\n flex-direction: row-reverse;\n }\n\n .form-select, select{\n background-position: left 0.5rem center;\n padding-right: 12px;\n } \n\n // divide\n.menu-divide {\n li {\n &:not(:last-child) {\n &:after {\n left: 0;\n right: auto;\n }\n }\n }\n}\n}\n\ninput[type=range]::-webkit-slider-thumb {\n pointer-events: all;\n width: 24px;\n height: 24px;\n -webkit-appearance: none;\n}\n\n[type='checkbox']:checked{\n background-size: 80%;\n}","import {Component, Host, h, State, Prop, Event, Method} from '@stencil/core';\nimport {Filter, FilterValue} from \"../salla-filters/interfaces\";\n\n@Component({\n tag: 'salla-price-range',\n styleUrl: 'salla-price-range.scss',\n})\nexport class SallaPriceRange {\n @Prop({mutable: true}) minPrice;\n @Prop({mutable: true}) maxPrice;\n @Prop({reflect: true}) option: Filter;\n @Prop({reflect: true}) filtersData: any;\n @State() min = 0;\n @State() max = 10000;\n\n @State() priceOptions: any;\n\n @Event() changed: any;\n\n isReady: Boolean;\n minInput: HTMLInputElement;\n maxInput: HTMLInputElement;\n filterValues: Array<FilterValue> = [];\n\n\n connectedCallback() {\n if (this.filtersData && this.filtersData?.price) {\n this.minPrice = this.filtersData.price.min;\n this.maxPrice = this.filtersData.price.max;\n }\n\n //no need to show one option only\n if (this.option.values.length == 1) {\n return;\n }\n //here we may recive too many prices, we will group all inputs to\n if (this.option.values.length <= 5) {\n this.filterValues = this.option.values;\n return;\n }\n const chunkSize = Math.ceil(this.option.values.length / 5);\n for (let i = 0; i < this.option.values.length; i += chunkSize) {\n this.filterValues.push(\n this.option.values\n .slice(i, i + chunkSize)\n .reduce((final: FilterValue, currentValue: FilterValue) => {\n final.to = currentValue.to;\n final.count += currentValue.count;\n return final;\n })\n );\n // do whatever\n }\n }\n\n @Method()\n async reset() {\n //@ts-ignore\n this.minInput.value = null;\n this.maxInput.value = null;\n }\n\n private getPriceLabel(filterValue: FilterValue) {\n // @ts-ignore\n if (isNaN(filterValue.from) || filterValue.from < 1) {\n return `اقل من ${salla.money(filterValue.to)}`;\n }\n // @ts-ignore\n if (isNaN(filterValue.to) || filterValue.to < 1) {\n return `أكثر من ${salla.money(filterValue.from)}`;\n }\n\n return `${salla.money(filterValue.from)} الى ${salla.money(filterValue.to)}`;\n }\n\n\n private handleMinMaxPrice(event: Event, value: FilterValue): void {\n\n this.minPrice = value.from;\n this.maxPrice = value.to != '*' ? value.to : null;\n\n this.changedEventHandler(event);\n }\n\n private async changedEventHandler(event, isMin = false) {\n\n let value = event ? event.target.value * 1 : null\n if (isMin) {\n this.minInputValidation(value);\n } else {\n this.maxInputValidation(value)\n }\n\n\n this.isReady && this.changed.emit({\n event: event,\n option: this.option,\n value: {max: this.maxPrice, min: this.minPrice}\n })\n }\n\n\n minInputValidation(value) {\n if (value && (value > this.max || value > this.maxPrice)) {\n // this.minPrice = this.maxPrice;\n return;\n }\n\n if (value < this.min) {\n this.minPrice = this.min;\n return;\n }\n\n if (value) {\n this.minPrice = value;\n }\n }\n\n maxInputValidation(value) {\n if (value && (value < this.min || value < this.minPrice)) {\n // this.maxPrice = this.minPrice;\n return;\n }\n if (value > this.max) {\n this.maxPrice = this.max;\n return;\n }\n\n if (value) {\n this.maxPrice = value;\n }\n }\n\n private isChecked(filterValue: FilterValue) {\n if (!this.minPrice && !this.maxPrice) {\n return false;\n }\n\n //1 filterValue.from zero or * and this.minPrice not set or zero\n //2 filterValue.from == this.minPrice\n let isMinEqual = ((filterValue.from < 1 || filterValue.from == '*') && this.minPrice == 0) || filterValue.from == this.minPrice;\n\n //1 filterValue.to == \"*\" or null\n //2 filterValue.to == this.max\n let isMaxEqual = filterValue.to == '*' || !filterValue.to || filterValue.to == this.maxPrice;\n return isMinEqual && isMaxEqual;\n }\n\n\n render() {\n return (\n <Host>\n {\n this.filterValues.map((filterValue, index) => {\n return <label class=\"s-filters-label\" htmlFor={`${this.option.key}-${index}`}>\n <input\n id={`${this.option.key}-${index}`}\n name=\"price\"\n type=\"radio\"\n checked={this.isChecked(filterValue)}\n class=\"s-filters-radio\"\n onChange={e => this.handleMinMaxPrice(e, filterValue)}\n />\n {this.getPriceLabel(filterValue)}\n </label>\n })\n }\n\n\n <div class=\"flex justify-center items-center\">\n <div class=\"relative max-w-xl w-full\">\n <div class=\"s-price-range-inputs\">\n <div class=\"s-price-range-relative\">\n <div class=\"s-price-range-currency\"> {salla.config.currency().symbol}</div>\n <input\n type=\"number\"\n maxlength=\"5\"\n ref={el => this.minInput = el}\n onInput={(event) => this.changedEventHandler(event, true)}\n value={this.minPrice}\n placeholder=\"من\"\n class=\"s-price-range-number-input\"\n />\n </div>\n\n <div class=\"s-price-range-gray-text\"> -</div>\n <div class=\"s-price-range-relative\">\n <div class=\"s-price-range-currency\"> {salla.config.currency().symbol}</div>\n <input type=\"number\" maxlength=\"5\"\n placeholder=\"الى\"\n ref={el => this.maxInput = el}\n onInput={(event) => this.changedEventHandler(event)}\n value={this.maxPrice}\n class=\"s-price-range-number-input\" aria-describedby=\"price-currency\"/>\n </div>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n this.isReady = true;\n }\n}\n"],"mappings":";;;6JAAA,IAAMA,EAAqB,0nB,ICOdC,EAAeC,EAAA,+B,yDAe1BC,KAAAC,aAAmC,G,0GAVpB,E,SACA,I,4BAYfC,EAAAC,UAAAC,kBAAA,W,MACE,GAAIJ,KAAKK,eAAeC,EAAAN,KAAKK,eAAW,MAAAC,SAA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by Salla
|
|
3
|
-
*/
|
|
4
|
-
import{r as s,h as t,H as i,g as e}from"./p-3c7d3f26.js";import{a as r}from"./p-201c8085.js";const l=`\x3c!-- Generated by IcoMoon.io --\x3e\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">\n<title>shopping-bag</title>\n<path d="M28 10.667h-4v-2.667c0-4.412-3.588-8-8-8s-8 3.588-8 8v2.667h-4c-0.736 0-1.333 0.596-1.333 1.333v13.333c0 3.676 2.991 6.667 6.667 6.667h13.333c3.676 0 6.667-2.991 6.667-6.667v-13.333c0-0.737-0.597-1.333-1.333-1.333zM10.667 8c0-2.941 2.392-5.333 5.333-5.333s5.333 2.392 5.333 5.333v2.667h-10.667zM26.667 25.333c0 2.205-1.795 4-4 4h-13.333c-2.205 0-4-1.795-4-4v-12h2.667v2.667c0 0.737 0.597 1.333 1.333 1.333s1.333-0.596 1.333-1.333v-2.667h10.667v2.667c0 0.737 0.597 1.333 1.333 1.333s1.333-0.596 1.333-1.333v-2.667h2.667z"></path>\n</svg>\n`;const a="";const n=class{constructor(t){s(this,t);this.source=undefined;this.sourceValue=undefined;this.limit=undefined;this.sortBy=undefined;this.filtersResults=undefined;this.horizontalCards=undefined;this.page=1;this.nextPage=undefined;this.hasInfiniteScroll=undefined;this.hasCustomComponent=undefined;this.sourceValueIsValid=undefined;this.placeholderText=undefined;this.isReady=undefined;this.showPlaceholder=undefined;this.parsedFilters=undefined}connectedCallback(){salla.onReady((()=>{this.hasCustomComponent=!!customElements.get("custom-salla-product-card");this.sourceValueIsValid=!!(this.getSourceValue()||this.isSourceWithoutValue());this.hasInfiniteScroll=!["json","selected","related","landing-page"].includes(this.getSource());try{let s=new URLSearchParams(window.location.search);this.sortBy=this.sortBy||s.get("sort")||s.get("by");let t=s.get("filters");this.parsedFilters=t?JSON.parse(decodeURIComponent(t)):{}}catch(s){salla.logger.warn("failed to get filters from url",s.message)}this.buildNextPageUrl();this.createStatusDom();this.isReady=true}));if(!this.sourceValueIsValid){salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);return}salla.event.on("salla-filters::changed",(s=>this.setFilters(s)))}async setFilters(s){this.parsedFilters=s;return this.reload()}async reload(){salla.infiniteScroll.destroy(this.infiniteScroll);this.buildNextPageUrl();this.wrapper.innerHTML="";this.init()}isFilterable(){return salla.config.get("store.settings.product.filters")&&this.filtersResults}isSourceWithoutValue(){return["offers","latest","sales"].includes(this.getSource())}animateItems(){r({targets:"salla-products-list salla-product-card",opacity:[0,1],duration:1200,translateY:[20,0],delay:function(s,t){return t*100}})}createStatusDom(){this.status=document.createElement("div");this.status.className="s-infinite-scroll-wrapper";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>`;this.btnLoader=this.status.querySelector(".s-button-loader");salla.lang.onLoaded((()=>{this.status.querySelector(".s-infinite-scroll-last").innerHTML=salla.lang.get("common.elements.end_of_content");this.status.querySelector(".s-infinite-scroll-error").innerHTML=salla.lang.get("common.elements.failed_to_load_more");this.placeholderText=salla.lang.get("pages.categories.no_products")}))}initBaseNextPageUrl(s){this.nextPage=salla.url.api(`products?source=${s}`);if(this.limit){this.nextPage+=`&per_page=${this.limit>32?32:this.limit}`}if(this.sortBy){this.nextPage+=`&sort=${this.sortBy}`}this.nextPage+="&filterable=1";for(const[s,t]of Object.entries(this.parsedFilters||{})){if(["string","number"].includes(typeof t)){this.nextPage+=`&filters[${s}]=${t}`}else if(Array.isArray(t)){t.forEach((t=>this.nextPage+=`&filters[${s}][]=${t}`))}else if(typeof t==="object"){for(const[i,e]of Object.entries(t)){this.nextPage+=`&filters[${s}][${i}]=${e}`}}}}buildNextPageUrl(){let s=this.getSource();if(s==="json"){return}this.initBaseNextPageUrl(s);if(this.isSourceWithoutValue()){return}if(["search","related","landing-page"].includes(s)){this.nextPage+=`&source_value=${this.getSourceValue()}`;return}try{this.nextPage+=`&source_value[]=${this.getSourceValue().join("&source_value[]=")}`}catch(t){salla.logger.warn(`source-value prop should be array of ids ex source-value="[1,2,3]" for the source [${s}]`);this.sourceValueIsValid=false}}getSource(){return{"brands.single":"brands","product.index":"categories","product.index.latest":"latest","product.index.offers":"offers","product.index.search":"search","landing-page":"landing-page","product.index.tag":"tags","product.index.sales":"sales","components.most_sales_products":"sales"}[this.source||salla.config.get("page.slug")]||this.source||"latest"}getSourceValue(){let s=this.getSource();if(!["search","json","offers","latest","sales"].includes(s)){if(this.sourceValue&&Array.isArray(JSON.parse(this.sourceValue))&&JSON.parse(this.sourceValue).length){return JSON.parse(this.sourceValue)}if(this.sourceValue&&typeof JSON.parse(this.sourceValue)=="number"){return[JSON.parse(this.sourceValue)]}if(!this.sourceValue&&["categories","tags","brands"].includes(this.getSource())){return[salla.config.get("page.id")]}}if(this.sourceValue){return this.sourceValue}if(s==="search"){return new URLSearchParams(window.location.search).get("q")}return salla.config.get("page.id")}loading(s=true){this.btnLoader.style.display=s?"inherit":"none"}getItemHTML(s){let t=this.hasCustomComponent?"custom-salla-product-card":"salla-product-card";let i=document.createElement(t);i.product=s;if(this.getSource()=="landing-page"&&!this.hasCustomComponent){i.toggleAttribute("hide-add-btn",true);i.classList.add("s-product-card-fit-height")}if(this.horizontalCards&&!this.hasCustomComponent){i.toggleAttribute("horizontal",true);i.toggleAttribute("shadow-on-hover",true)}return i}fetchProducts(){salla.product.fetch({source:this.getSource(),source_value:this.getSourceValue(),limit:this.limit}).then((s=>{if(!s.data.length){this.showPlaceholder=true;this.loading(false);return}this.handleResponse(s).forEach((s=>this.wrapper.append(s)))}))}initiateInfiniteScroll(){if(!this.hasInfiniteScroll){return}this.host.insertAdjacentElement("beforeend",this.status);this.infiniteScroll=salla.infiniteScroll.initiate(this.wrapper,this.wrapper,{path:()=>this.nextPage,history:false,nextPage:this.nextPage,scrollThreshold:100},true);this.infiniteScroll.on("request",(()=>this.loading()));this.infiniteScroll.on("load",(s=>{var t;if(!((t=s.data)===null||t===void 0?void 0:t.length)){this.showPlaceholder=true;salla.infiniteScroll.destroy(this.infiniteScroll);this.loading(false);return}else{this.showPlaceholder=false}this.infiniteScroll.appendItems(this.handleResponse(s));if(this.infiniteScroll.pageIndex==2){this.animateItems()}}));this.infiniteScroll.on("error",(()=>{this.status.querySelector(".s-infinite-scroll-error").classList.remove("s-hidden");this.loading(false)}));salla.onReady((()=>salla.infiniteScroll.loadNextPage(this.infiniteScroll)))}canRender(){return this.sourceValueIsValid&&this.isReady}render(){if(!this.canRender()){return""}if(this.showPlaceholder){return t("div",{class:"s-products-list-placeholder"},t("span",{innerHTML:l}),t("p",null,this.placeholderText))}return t(i,{class:"s-products-list"},t("div",{class:{"s-products-list-wrapper":true,"s-products-list-horizontal-cards":this.horizontalCards&&!this.filtersResults,"s-products-list-vertical-cards":!this.horizontalCards&&!this.filtersResults,"s-products-list-filters-results":this.filtersResults},ref:s=>this.wrapper=s}))}componentDidLoad(){if(!this.canRender()){return}if(this.getSource()==="json"){if(!this.getSourceValue().length){this.showPlaceholder=true;return}this.getSourceValue().map((s=>this.wrapper.append(this.getItemHTML(s))));return}if(this.getSource()==="selected"||this.getSource()==="landing-page"){if(this.getSource()==="selected"&&!this.getSourceValue().length){this.showPlaceholder=true;return}this.fetchProducts();return}this.init()}init(){this.initiateInfiniteScroll();this.loading()}handleResponse(s){var t;if(s.filters&&this.isFilterable()){this.filtersResults=true;salla.event.emit("filters::fetched",{filters:s.filters})}else if(this.isFilterable()){salla.event.emit("filters::hidden")}this.nextPage=s.cursor?s.cursor.next:this.nextPage;this.loading(false);if(this.hasInfiniteScroll&&!this.nextPage){this.infiniteScroll.option({scrollThreshold:false,loadOnScroll:false});this.status.querySelector(".s-infinite-scroll-last").classList.remove("s-hidden")}return((t=s.data)===null||t===void 0?void 0:t.map((s=>this.getItemHTML(s))))||[]}get host(){return e(this)}};n.style=a;export{n as salla_products_list};
|
|
5
|
-
//# sourceMappingURL=p-f1d68104.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["sallaProductsListCss","SallaProductsList","connectedCallback","salla","onReady","this","hasCustomComponent","customElements","get","sourceValueIsValid","getSourceValue","isSourceWithoutValue","hasInfiniteScroll","includes","getSource","searchParams","URLSearchParams","window","location","search","sortBy","filters","parsedFilters","JSON","parse","decodeURIComponent","e","logger","warn","message","buildNextPageUrl","createStatusDom","isReady","event","on","setFilters","async","reload","infiniteScroll","destroy","wrapper","innerHTML","init","isFilterable","config","filtersResults","animateItems","anime","targets","opacity","duration","translateY","delay","_el","i","status","document","createElement","className","lang","btnLoader","querySelector","onLoaded","placeholderText","initBaseNextPageUrl","source","nextPage","url","api","limit","key","value","Object","entries","Array","isArray","forEach","item","k","v","join","sourceValue","length","loading","isLoading","style","display","getItemHTML","product","customComponentTag","customComponent","toggleAttribute","classList","add","horizontalCards","fetchProducts","fetch","source_value","then","res","data","showPlaceholder","handleResponse","card","append","initiateInfiniteScroll","host","insertAdjacentElement","initiate","path","history","scrollThreshold","response","_a","appendItems","pageIndex","remove","loadNextPage","canRender","render","h","class","ShoppingBag","Host","ref","componentDidLoad","map","emit","cursor","next","option","loadOnScroll"],"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} 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 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"],"mappings":";;;mzBAAA,MAAMA,EAAuB,G,MCQhBC,EAAiB,M,4LA2FJ,E,+OA1FxBC,oBACEC,MA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