@salla.sa/twilight-components 2.12.34 → 2.12.35
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/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 -2
- package/dist/cjs/salla-products-slider.cjs.entry.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 +2 -2
- package/dist/collection/components/salla-products-slider/salla-products-slider.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 +2 -2
- package/dist/components/salla-products-slider.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 -2
- package/dist/esm/salla-products-slider.entry.js.map +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/twilight/p-34bf40ac.system.js +1 -1
- package/dist/twilight/{p-8af2b33f.entry.js → p-5022a0dc.entry.js} +2 -2
- package/dist/twilight/p-5022a0dc.entry.js.map +1 -0
- package/dist/twilight/{p-7508e0b1.system.entry.js → p-672fb5e4.system.entry.js} +3 -3
- package/dist/twilight/{p-7508e0b1.system.entry.js.map → p-672fb5e4.system.entry.js.map} +1 -1
- package/dist/twilight/{p-a528415a.entry.js → p-98c3cddb.entry.js} +2 -2
- package/dist/twilight/{p-a528415a.entry.js.map → p-98c3cddb.entry.js.map} +1 -1
- package/dist/twilight/{p-535b0024.system.entry.js → p-e19acc25.system.entry.js} +2 -2
- package/dist/twilight/p-e19acc25.system.entry.js.map +1 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/package.json +2 -2
- package/dist/twilight/p-535b0024.system.entry.js.map +0 -1
- package/dist/twilight/p-8af2b33f.entry.js.map +0 -1
|
@@ -65,7 +65,7 @@ const SallaProductsSlider$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
|
|
|
65
65
|
return this.fetchProducts();
|
|
66
66
|
}
|
|
67
67
|
fetchProducts() {
|
|
68
|
-
return salla.product.api.fetch({
|
|
68
|
+
return salla.api.withoutNotifier(() => salla.product.api.fetch({
|
|
69
69
|
source: this.getSource(),
|
|
70
70
|
source_value: this.getSourceValue(),
|
|
71
71
|
limit: this.limit,
|
|
@@ -77,7 +77,7 @@ const SallaProductsSlider$1 = /*@__PURE__*/ proxyCustomElement(class extends HTM
|
|
|
77
77
|
// TODO: Find the real issue and fix it
|
|
78
78
|
salla.log('Request headers', salla.api.getHeaders());
|
|
79
79
|
setTimeout(() => this.fetchProducts(), 1000);
|
|
80
|
-
});
|
|
80
|
+
}));
|
|
81
81
|
}
|
|
82
82
|
getSource() {
|
|
83
83
|
return Helper.getProductsSource(this.source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-slider.js","mappings":";;;;;;;;;;;;;;;;;AAAA,MAAM,sBAAsB,GAAG,EAAE;;MCQpBA,qBAAmB;EAC9B;;;;;;;;;;;;;;;kBAgF0B,EAAE;;IA/E1B,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,kBAAkB,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;MACnF,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;QAC5B,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,6CAA6C,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;QACpF,OAAO;OACR;MACD,IAAI,CAAC,kBAAkB,GAAG,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CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,eACxE,IAAI,CAAC,QAAQ,EACxB,IAAI,EAAC,UAAU,iBACF,IAAI,CAAC,UAAU,oBACZ,IAAI,CAAC,QAAQ,qBACZ,IAAI,CAAC,aAAa,IAEnC,WAAK,IAAI,EAAC,OAAO,IACd,MAAA,IAAI,CAAC,YAAY,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CACzD,CACO,CACV,EACP;GACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaProductsSlider"],"sources":["./src/components/salla-products-slider/salla-products-slider.scss?tag=salla-products-slider","./src/components/salla-products-slider/salla-products-slider.tsx"],"sourcesContent":[".s-products-slider{\n &-wrapper{\n\n }\n &-slider{\n\n }\n &-card{\n\n }\n}","import { Component, Host, h, Prop, Element, State } from '@stencil/core';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-slider',\n styleUrl: 'salla-products-slider.scss'\n})\n\n//todo:: extends this component from salla-products-list or the opposite\nexport class SallaProductsSlider {\n constructor() {\n salla.onReady(() => {\n this.sourceValueIsValid = !!(this.getSourceValue() || 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 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 this.fetchProducts();\n\n }\n\n private fetchProducts() {\n return salla.api.withoutNotifier(() => \n salla.product.api.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 salla.event.emit('salla-products-slider::products.fetched', res.data);\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n )\n }\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n render() {\n if ((this.getSource() == 'related' && !salla.config.get('store.settings.product.related_products_enabled')) || !this.canRender()) {\n return;\n }\n return (\n <Host class=\"s-products-slider-wrapper\">\n <salla-slider\n class=\"s-products-slider-slider\"\n id={this.sliderId || `s-products-slider-${Math.random().toString(36).substr(2, 9)}`}\n auto-play={this.autoplay}\n type=\"carousel\"\n block-title={this.blockTitle}\n block-subTitle={this.subTitle}\n display-all-url={this.displayAllUrl}\n >\n <div slot=\"items\">\n {this.productsData?.map(product => this.getItemHTML(product))}\n </div>\n </salla-slider>\n </Host>\n );\n }\n\n}\n"],"version":3}
|
|
@@ -252,9 +252,11 @@ const SallaProductsList = class {
|
|
|
252
252
|
return this.sourceValueIsValid && this.isReady;
|
|
253
253
|
}
|
|
254
254
|
render() {
|
|
255
|
+
salla.log('render: before can render');
|
|
255
256
|
if (!this.canRender()) {
|
|
256
257
|
return '';
|
|
257
258
|
}
|
|
259
|
+
salla.log('render: after can render');
|
|
258
260
|
if (this.showPlaceholder) {
|
|
259
261
|
return h("div", { class: "s-products-list-placeholder" }, h("span", { innerHTML: ShoppingBag }), h("p", null, this.placeholderText));
|
|
260
262
|
}
|
|
@@ -266,9 +268,11 @@ const SallaProductsList = class {
|
|
|
266
268
|
}, ref: wrapper => this.wrapper = wrapper })));
|
|
267
269
|
}
|
|
268
270
|
componentDidLoad() {
|
|
271
|
+
salla.log('component did load before can render');
|
|
269
272
|
if (!this.canRender()) {
|
|
270
273
|
return;
|
|
271
274
|
}
|
|
275
|
+
salla.log('component did load after can render');
|
|
272
276
|
// Handle json source
|
|
273
277
|
if (this.getSource() === 'json') {
|
|
274
278
|
if (!this.getSourceValue().length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-list.entry.js","mappings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,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;MAC5C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;MAC5E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACnF;IACD,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,KAAI,EAAE,CAAC;GACvE;;;;;;;","names":[],"sources":["./src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","./src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import { Component, Host, h, Prop, State, Element, Method, Event, EventEmitter } from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.onReady(() => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n\n\n }\n\n /**\n * Set parsed filters data from URI\n * @param filters\n */\n @Method()\n async setFilters(filters) {\n if (!!filters && JSON.stringify(this.parsedFilters) === JSON.stringify(filters)) {\n return;\n }\n window.scrollTo({ top: 0, behavior: 'smooth' });\n this.parsedFilters = filters;\n return this.reload();\n }\n\n /**\n * Reload the list of products (entire content of the component).\n */\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n // TODO: this is problematic in testing, for the time being it's been resolved like this\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({ mutable: true }) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({ mutable: true }) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({ reflect: true, mutable: true }) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({ reflect: true }) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n /**\n * Custom event fired when the the products fetched.\n */\n @Event() productsFetched: EventEmitter;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n // @ts-ignore\n this.nextPage += `&filters[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`;\n } else if (Array.isArray(value)) {\n value.forEach(item => this.nextPage += `&filters[${encodeURIComponent(key)}][]=${encodeURIComponent(item)}`);\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${encodeURIComponent(key)}][${encodeURIComponent(k)}]=${encodeURIComponent(v)}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n const productCard = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n productCard.product = product;\n\n this.applyLandingPageStyles(productCard);\n this.applyHorizontalCardStyles(productCard);\n\n return productCard;\n }\n\n private applyLandingPageStyles(productCard) {\n if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {\n productCard.toggleAttribute('hide-add-btn', true);\n productCard.classList.add('s-product-card-fit-height');\n }\n }\n\n private applyHorizontalCardStyles(productCard) {\n if (!this.horizontalCards) {\n return;\n }\n productCard.setAttribute('horizontal', true);\n if (!this.hasCustomComponent) {\n productCard.setAttribute('shadow-on-hover', true);\n }\n\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n private fetchProducts() {\n \n salla.product.api.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit\n })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll?.on('request', () => this.loading())\n this.infiniteScroll?.on('load', response => {\n if (!response.data?.length && this.infiniteScroll.pageIndex == 2) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n } else {\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll?.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n 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 let source=this.getSource();\n let title = '';\n //help the developer to know the current page title\n if (response.cursor?.current === 1) {\n title = Helper.getPageTitleForSource(source);\n try {\n if (this.getSource() === 'search') {\n title = salla.lang.get('common.elements.search_about', {'word': this.getSourceValue()});\n } else if (!title) {\n let catId = this.parsedFilters.category_id || this.getSourceValue()[0];\n // get the first filter that its key is category_id, then get the value when filter.value.*.key==catId\n title = response.filters.find(filter => filter.key == 'category_id') ?. values ?. find(cat => cat.key == catId) ?. value || '';\n }\n title += (title ? ' - ' : '') + salla.lang.choice('blocks.header.products_count', response.data ?. length);\n if (response.data.length === 20) {\n title = title.replace(response.data.length, salla.lang.get('common.elements.more_than') + ' ' + response.data.length)\n }\n response.title = title;\n } catch (e) {}\n }\n\n salla.event.emit('salla-products-list::products.fetched', response);\n this.productsFetched.emit(response);\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', { filters: response.filters });\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)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kB,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;KACrE;SAAM,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE;MAC9B,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;KACrC;IACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;MAC5C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;MAC5E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KACnF;IACD,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,KAAI,EAAE,CAAC;GACvE;;;;;;;","names":[],"sources":["./src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","./src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import { Component, Host, h, Prop, State, Element, Method, Event, EventEmitter } from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.onReady(() => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n\n\n }\n\n /**\n * Set parsed filters data from URI\n * @param filters\n */\n @Method()\n async setFilters(filters) {\n if (!!filters && JSON.stringify(this.parsedFilters) === JSON.stringify(filters)) {\n return;\n }\n window.scrollTo({ top: 0, behavior: 'smooth' });\n this.parsedFilters = filters;\n return this.reload();\n }\n\n /**\n * Reload the list of products (entire content of the component).\n */\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n // TODO: this is problematic in testing, for the time being it's been resolved like this\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({ mutable: true }) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({ mutable: true }) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({ reflect: true, mutable: true }) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({ reflect: true }) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n /**\n * Custom event fired when the the products fetched.\n */\n @Event() productsFetched: EventEmitter;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n // @ts-ignore\n this.nextPage += `&filters[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`;\n } else if (Array.isArray(value)) {\n value.forEach(item => this.nextPage += `&filters[${encodeURIComponent(key)}][]=${encodeURIComponent(item)}`);\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${encodeURIComponent(key)}][${encodeURIComponent(k)}]=${encodeURIComponent(v)}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n const productCard = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n productCard.product = product;\n\n this.applyLandingPageStyles(productCard);\n this.applyHorizontalCardStyles(productCard);\n\n return productCard;\n }\n\n private applyLandingPageStyles(productCard) {\n if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {\n productCard.toggleAttribute('hide-add-btn', true);\n productCard.classList.add('s-product-card-fit-height');\n }\n }\n\n private applyHorizontalCardStyles(productCard) {\n if (!this.horizontalCards) {\n return;\n }\n productCard.setAttribute('horizontal', true);\n if (!this.hasCustomComponent) {\n productCard.setAttribute('shadow-on-hover', true);\n }\n\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n private fetchProducts() {\n\n salla.product.api.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit\n })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll?.on('request', () => this.loading())\n this.infiniteScroll?.on('load', response => {\n if (!response.data?.length && this.infiniteScroll.pageIndex == 2) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n } else {\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll?.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n salla.log('render: before can render')\n if (!this.canRender()) {\n return '';\n }\n salla.log('render: after can render')\n if (this.showPlaceholder) {\n return <div class=\"s-products-list-placeholder\">\n <span innerHTML={ShoppingBag} />\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class={{\n \"s-products-list-wrapper\": true,\n 's-products-list-horizontal-cards': this.horizontalCards && !this.filtersResults,\n 's-products-list-vertical-cards': !this.horizontalCards && !this.filtersResults,\n 's-products-list-filters-results': this.filtersResults,\n }}\n ref={wrapper => this.wrapper = wrapper} />\n </Host>\n );\n }\n\n componentDidLoad() {\n salla.log('component did load before can render')\n if (!this.canRender()) {\n return;\n }\n salla.log('component did load after can render')\n\n // Handle json source\n if (this.getSource() === 'json') {\n if (!this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n // Handle selected source\n if (this.getSource() === 'selected' || this.getSource() === 'landing-page') {\n if (this.getSource() === 'selected' && !this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.fetchProducts()\n return;\n }\n this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n }\n\n private handleResponse(response): Array<HTMLElement> {\n let source=this.getSource();\n let title = '';\n //help the developer to know the current page title\n if (response.cursor?.current === 1) {\n title = Helper.getPageTitleForSource(source);\n try {\n if (this.getSource() === 'search') {\n title = salla.lang.get('common.elements.search_about', {'word': this.getSourceValue()});\n } else if (!title) {\n let catId = this.parsedFilters.category_id || this.getSourceValue()[0];\n // get the first filter that its key is category_id, then get the value when filter.value.*.key==catId\n title = response.filters.find(filter => filter.key == 'category_id') ?. values ?. find(cat => cat.key == catId) ?. value || '';\n }\n title += (title ? ' - ' : '') + salla.lang.choice('blocks.header.products_count', response.data ?. length);\n if (response.data.length === 20) {\n title = title.replace(response.data.length, salla.lang.get('common.elements.more_than') + ' ' + response.data.length)\n }\n response.title = title;\n } catch (e) {}\n }\n\n salla.event.emit('salla-products-list::products.fetched', response);\n this.productsFetched.emit(response);\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', { filters: response.filters });\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"version":3}
|
|
@@ -53,7 +53,7 @@ const SallaProductsSlider = class {
|
|
|
53
53
|
return this.fetchProducts();
|
|
54
54
|
}
|
|
55
55
|
fetchProducts() {
|
|
56
|
-
return salla.product.api.fetch({
|
|
56
|
+
return salla.api.withoutNotifier(() => salla.product.api.fetch({
|
|
57
57
|
source: this.getSource(),
|
|
58
58
|
source_value: this.getSourceValue(),
|
|
59
59
|
limit: this.limit,
|
|
@@ -65,7 +65,7 @@ const SallaProductsSlider = class {
|
|
|
65
65
|
// TODO: Find the real issue and fix it
|
|
66
66
|
salla.log('Request headers', salla.api.getHeaders());
|
|
67
67
|
setTimeout(() => this.fetchProducts(), 1000);
|
|
68
|
-
});
|
|
68
|
+
}));
|
|
69
69
|
}
|
|
70
70
|
getSource() {
|
|
71
71
|
return Helper.getProductsSource(this.source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-slider.entry.js","mappings":";;;;;;AAAA,MAAM,sBAAsB,GAAG,EAAE;;MCQpB,mBAAmB;EAC9B;;;;;;;;;;;;;;kBAgF0B,EAAE;;IA/E1B,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,kBAAkB,GAAG,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;MACnF,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;QAC5B,KAAK,CAAC,MAAM,CAA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EAChC,EAAE,EAAE,IAAI,CAAC,QAAQ,IAAI,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,eACxE,IAAI,CAAC,QAAQ,EACxB,IAAI,EAAC,UAAU,iBACF,IAAI,CAAC,UAAU,oBACZ,IAAI,CAAC,QAAQ,qBACZ,IAAI,CAAC,aAAa,IAEnC,WAAK,IAAI,EAAC,OAAO,IACd,MAAA,IAAI,CAAC,YAAY,0CAAE,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CACzD,CACO,CACV,EACP;GACH;;;;;;;","names":[],"sources":["./src/components/salla-products-slider/salla-products-slider.scss?tag=salla-products-slider","./src/components/salla-products-slider/salla-products-slider.tsx"],"sourcesContent":[".s-products-slider{\n &-wrapper{\n\n }\n &-slider{\n\n }\n &-card{\n\n }\n}","import { Component, Host, h, Prop, Element, State } from '@stencil/core';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-slider',\n styleUrl: 'salla-products-slider.scss'\n})\n\n//todo:: extends this component from salla-products-list or the opposite\nexport class SallaProductsSlider {\n constructor() {\n salla.onReady(() => {\n this.sourceValueIsValid = !!(this.getSourceValue() || 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 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 this.fetchProducts();\n\n }\n\n private fetchProducts() {\n return salla.api.withoutNotifier(() => \n salla.product.api.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 salla.event.emit('salla-products-slider::products.fetched', res.data);\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n )\n }\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n render() {\n if ((this.getSource() == 'related' && !salla.config.get('store.settings.product.related_products_enabled')) || !this.canRender()) {\n return;\n }\n return (\n <Host class=\"s-products-slider-wrapper\">\n <salla-slider\n class=\"s-products-slider-slider\"\n id={this.sliderId || `s-products-slider-${Math.random().toString(36).substr(2, 9)}`}\n auto-play={this.autoplay}\n type=\"carousel\"\n block-title={this.blockTitle}\n block-subTitle={this.subTitle}\n display-all-url={this.displayAllUrl}\n >\n <div slot=\"items\">\n {this.productsData?.map(product => this.getItemHTML(product))}\n </div>\n </salla-slider>\n </Host>\n );\n }\n\n}\n"],"version":3}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var __awaiter=this&&this.__awaiter||function(e,t,
|
|
1
|
+
var __awaiter=this&&this.__awaiter||function(e,t,n,r){function i(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function a(e){try{l(r["throw"](e))}catch(e){s(e)}}function l(e){e.done?n(e.value):i(e.value).then(o,a)}l((r=r.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,i,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(e){return function(t){return l([e,t])}}function l(a){if(r)throw new TypeError("Generator is already executing.");while(o&&(o=0,a[0]&&(n=0)),n)try{if(r=1,i&&(s=a[0]&2?i["return"]:a[0]?i["throw"]||((s=i["return"])&&s.call(i),0):i.next)&&!(s=s.call(i,a[1])).done)return s;if(i=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:n.label++;return{value:a[1],done:false};case 5:n.label++;i=a[1];a=[0];continue;case 7:a=n.ops.pop();n.trys.pop();continue;default:if(!(s=n.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){n=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){n.label=a[1];break}if(a[0]===6&&n.label<s[1]){n.label=s[1];s=a;break}if(s&&n.label<s[2]){n.label=s[2];n.ops.push(a);break}if(s[2])n.ops.pop();n.trys.pop();continue}a=t.call(e,n)}catch(e){a=[6,e];i=0}finally{r=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};
|
|
2
2
|
/*!
|
|
3
3
|
* Crafted with ❤ by Salla
|
|
4
|
-
*/import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-56f9513d.js";import{a as anime}from"./anime.es-6b92d9cd.js";import{H as Helper}from"./Helper-c2739d13.js";var ShoppingBag='\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';var sallaProductsListCss="";var SallaProductsList=function(){function e(e){registerInstance(this,e);this.productsFetched=createEvent(this,"productsFetched",7);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}e.prototype.connectedCallback=function(){var e=this;salla.onReady((function(){e.hasCustomComponent=!!customElements.get("custom-salla-product-card");e.sourceValueIsValid=!!(e.getSourceValue()||e.isSourceWithoutValue());e.hasInfiniteScroll=!["json","selected","related","landing-page"].includes(e.getSource());try{var t=new URLSearchParams(window.location.search);e.sortBy=e.sortBy||t.get("sort")||t.get("by");var i=t.get("filters");e.parsedFilters=i?JSON.parse(decodeURIComponent(i)):{}}catch(e){salla.logger.warn("failed to get filters from url",e.message)}e.buildNextPageUrl();e.createStatusDom();e.isReady=true}));if(!this.sourceValueIsValid){salla.logger.warn("source-value prop is required for source [".concat(this.getSource(),"]"));return}salla.event.on("salla-filters::changed",(function(t){return e.setFilters(t)}))};e.prototype.setFilters=function(e){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){if(!!e&&JSON.stringify(this.parsedFilters)===JSON.stringify(e)){return[2]}window.scrollTo({top:0,behavior:"smooth"});this.parsedFilters=e;return[2,this.reload()]}))}))};e.prototype.reload=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){salla.infiniteScroll.destroy(this.infiniteScroll);this.buildNextPageUrl();this.wrapper.innerHTML="";this.init();return[2]}))}))};e.prototype.isFilterable=function(){return salla.config.get("store.settings.product.filters")&&this.filtersResults};e.prototype.isSourceWithoutValue=function(){return["offers","latest","sales"].includes(this.getSource())};e.prototype.animateItems=function(){anime({targets:"salla-products-list salla-product-card",opacity:[0,1],duration:1200,translateY:[20,0],delay:function(e,t){return t*100}})};e.prototype.createStatusDom=function(){var e=this;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" >'.concat(salla.lang.get("common.elements.end_of_content"),'</p>\n <p class="s-infinite-scroll-error infinite-scroll-error s-hidden">').concat(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((function(){e.status.querySelector(".s-infinite-scroll-last").innerHTML=salla.lang.get("common.elements.end_of_content");e.status.querySelector(".s-infinite-scroll-error").innerHTML=salla.lang.get("common.elements.failed_to_load_more");e.placeholderText=salla.lang.get("pages.categories.no_products")}))};e.prototype.initBaseNextPageUrl=function(e){var t=this;this.nextPage=salla.url.api("products?source=".concat(e));if(this.limit){this.nextPage+="&per_page=".concat(this.limit>32?32:this.limit)}if(this.sortBy){this.nextPage+="&sort=".concat(this.sortBy)}this.nextPage+="&filterable=1";var i=function(e,i){if(["string","number"].includes(typeof i)){n.nextPage+="&filters[".concat(encodeURIComponent(e),"]=").concat(encodeURIComponent(i))}else if(Array.isArray(i)){i.forEach((function(i){return t.nextPage+="&filters[".concat(encodeURIComponent(e),"][]=").concat(encodeURIComponent(i))}))}else if(typeof i==="object"){for(var r=0,s=Object.entries(i);r<s.length;r++){var o=s[r],a=o[0],l=o[1];n.nextPage+="&filters[".concat(encodeURIComponent(e),"][").concat(encodeURIComponent(a),"]=").concat(encodeURIComponent(l))}}};var n=this;for(var r=0,s=Object.entries(this.parsedFilters||{});r<s.length;r++){var o=s[r],a=o[0],l=o[1];i(a,l)}};e.prototype.buildNextPageUrl=function(){var e=this.getSource();if(e==="json"){return}this.initBaseNextPageUrl(e);if(this.isSourceWithoutValue()){return}if(["search","related","landing-page"].includes(e)){this.nextPage+="&source_value=".concat(this.getSourceValue());return}try{this.nextPage+="&source_value[]=".concat(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 ['.concat(e,"]"));this.sourceValueIsValid=false}};e.prototype.loading=function(e){if(e===void 0){e=true}this.btnLoader.style.display=e?"inherit":"none"};e.prototype.getItemHTML=function(e){var t=this.hasCustomComponent?"custom-salla-product-card":"salla-product-card";var i=document.createElement(t);i.product=e;this.applyLandingPageStyles(i);this.applyHorizontalCardStyles(i);return i};e.prototype.applyLandingPageStyles=function(e){if(this.getSource()==="landing-page"&&!this.hasCustomComponent){e.toggleAttribute("hide-add-btn",true);e.classList.add("s-product-card-fit-height")}};e.prototype.applyHorizontalCardStyles=function(e){if(!this.horizontalCards){return}e.setAttribute("horizontal",true);if(!this.hasCustomComponent){e.setAttribute("shadow-on-hover",true)}};e.prototype.getSource=function(){return Helper.getProductsSource(this.source)};e.prototype.getSourceValue=function(){return Helper.getProductsSourceValue(this.source,this.sourceValue)};e.prototype.fetchProducts=function(){var e=this;salla.product.api.fetch({source:this.getSource(),source_value:this.getSourceValue(),limit:this.limit}).then((function(t){if(!t.data.length){e.showPlaceholder=true;e.loading(false);return}e.handleResponse(t).forEach((function(t){return e.wrapper.append(t)}))})).catch((function(){salla.log("Request headers",salla.api.getHeaders());setTimeout((function(){return e.fetchProducts()}),1e3)}))};e.prototype.initiateInfiniteScroll=function(){var e=this;var t,i,n;if(!this.hasInfiniteScroll){return}this.host.insertAdjacentElement("beforeend",this.status);this.infiniteScroll=salla.infiniteScroll.initiate(this.wrapper,this.wrapper,{path:function(){return e.nextPage},history:false,nextPage:this.nextPage,scrollThreshold:100},true);(t=this.infiniteScroll)===null||t===void 0?void 0:t.on("request",(function(){return e.loading()}));(i=this.infiniteScroll)===null||i===void 0?void 0:i.on("load",(function(t){var i;if(!((i=t.data)===null||i===void 0?void 0:i.length)&&e.infiniteScroll.pageIndex==2){e.showPlaceholder=true;salla.infiniteScroll.destroy(e.infiniteScroll);e.loading(false);return}else{e.showPlaceholder=false}e.infiniteScroll.appendItems(e.handleResponse(t));if(e.infiniteScroll.pageIndex==2){e.animateItems()}}));(n=this.infiniteScroll)===null||n===void 0?void 0:n.on("error",(function(){e.status.querySelector(".s-infinite-scroll-error").classList.remove("s-hidden");e.loading(false)}));salla.onReady((function(){return salla.infiniteScroll.loadNextPage(e.infiniteScroll)}))};e.prototype.canRender=function(){return this.sourceValueIsValid&&this.isReady};e.prototype.render=function(){var e=this;if(!this.canRender()){return""}if(this.showPlaceholder){return h("div",{class:"s-products-list-placeholder"},h("span",{innerHTML:ShoppingBag}),h("p",null,this.placeholderText))}return h(Host,{class:"s-products-list"},h("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:function(t){return e.wrapper=t}}))};e.prototype.componentDidLoad=function(){var e=this;if(!this.canRender()){return}if(this.getSource()==="json"){if(!this.getSourceValue().length){this.showPlaceholder=true;return}this.getSourceValue().map((function(t){return e.wrapper.append(e.getItemHTML(t))}));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()};e.prototype.init=function(){this.initiateInfiniteScroll();this.loading()};e.prototype.handleResponse=function(e){var t=this;var i,n,r,s,o,a;var l=this.getSource();var c="";if(((i=e.cursor)===null||i===void 0?void 0:i.current)===1){c=Helper.getPageTitleForSource(l);try{if(this.getSource()==="search"){c=salla.lang.get("common.elements.search_about",{word:this.getSourceValue()})}else if(!c){var u=this.parsedFilters.category_id||this.getSourceValue()[0];c=((s=(r=(n=e.filters.find((function(e){return e.key=="category_id"})))===null||n===void 0?void 0:n.values)===null||r===void 0?void 0:r.find((function(e){return e.key==u})))===null||s===void 0?void 0:s.value)||""}c+=(c?" - ":"")+salla.lang.choice("blocks.header.products_count",(o=e.data)===null||o===void 0?void 0:o.length);if(e.data.length===20){c=c.replace(e.data.length,salla.lang.get("common.elements.more_than")+" "+e.data.length)}e.title=c}catch(e){}}salla.event.emit("salla-products-list::products.fetched",e);this.productsFetched.emit(e);if(e.filters&&this.isFilterable()){this.filtersResults=true;salla.event.emit("filters::fetched",{filters:e.filters})}else if(this.isFilterable()){salla.event.emit("filters::hidden")}this.nextPage=e.cursor?e.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((a=e.data)===null||a===void 0?void 0:a.map((function(e){return t.getItemHTML(e)})))||[]};Object.defineProperty(e.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();SallaProductsList.style=sallaProductsListCss;export{SallaProductsList as salla_products_list};
|
|
4
|
+
*/import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-56f9513d.js";import{a as anime}from"./anime.es-6b92d9cd.js";import{H as Helper}from"./Helper-c2739d13.js";var ShoppingBag='\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';var sallaProductsListCss="";var SallaProductsList=function(){function e(e){registerInstance(this,e);this.productsFetched=createEvent(this,"productsFetched",7);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}e.prototype.connectedCallback=function(){var e=this;salla.onReady((function(){e.hasCustomComponent=!!customElements.get("custom-salla-product-card");e.sourceValueIsValid=!!(e.getSourceValue()||e.isSourceWithoutValue());e.hasInfiniteScroll=!["json","selected","related","landing-page"].includes(e.getSource());try{var t=new URLSearchParams(window.location.search);e.sortBy=e.sortBy||t.get("sort")||t.get("by");var n=t.get("filters");e.parsedFilters=n?JSON.parse(decodeURIComponent(n)):{}}catch(e){salla.logger.warn("failed to get filters from url",e.message)}e.buildNextPageUrl();e.createStatusDom();e.isReady=true}));if(!this.sourceValueIsValid){salla.logger.warn("source-value prop is required for source [".concat(this.getSource(),"]"));return}salla.event.on("salla-filters::changed",(function(t){return e.setFilters(t)}))};e.prototype.setFilters=function(e){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){if(!!e&&JSON.stringify(this.parsedFilters)===JSON.stringify(e)){return[2]}window.scrollTo({top:0,behavior:"smooth"});this.parsedFilters=e;return[2,this.reload()]}))}))};e.prototype.reload=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){salla.infiniteScroll.destroy(this.infiniteScroll);this.buildNextPageUrl();this.wrapper.innerHTML="";this.init();return[2]}))}))};e.prototype.isFilterable=function(){return salla.config.get("store.settings.product.filters")&&this.filtersResults};e.prototype.isSourceWithoutValue=function(){return["offers","latest","sales"].includes(this.getSource())};e.prototype.animateItems=function(){anime({targets:"salla-products-list salla-product-card",opacity:[0,1],duration:1200,translateY:[20,0],delay:function(e,t){return t*100}})};e.prototype.createStatusDom=function(){var e=this;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" >'.concat(salla.lang.get("common.elements.end_of_content"),'</p>\n <p class="s-infinite-scroll-error infinite-scroll-error s-hidden">').concat(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((function(){e.status.querySelector(".s-infinite-scroll-last").innerHTML=salla.lang.get("common.elements.end_of_content");e.status.querySelector(".s-infinite-scroll-error").innerHTML=salla.lang.get("common.elements.failed_to_load_more");e.placeholderText=salla.lang.get("pages.categories.no_products")}))};e.prototype.initBaseNextPageUrl=function(e){var t=this;this.nextPage=salla.url.api("products?source=".concat(e));if(this.limit){this.nextPage+="&per_page=".concat(this.limit>32?32:this.limit)}if(this.sortBy){this.nextPage+="&sort=".concat(this.sortBy)}this.nextPage+="&filterable=1";var n=function(e,n){if(["string","number"].includes(typeof n)){r.nextPage+="&filters[".concat(encodeURIComponent(e),"]=").concat(encodeURIComponent(n))}else if(Array.isArray(n)){n.forEach((function(n){return t.nextPage+="&filters[".concat(encodeURIComponent(e),"][]=").concat(encodeURIComponent(n))}))}else if(typeof n==="object"){for(var i=0,s=Object.entries(n);i<s.length;i++){var o=s[i],a=o[0],l=o[1];r.nextPage+="&filters[".concat(encodeURIComponent(e),"][").concat(encodeURIComponent(a),"]=").concat(encodeURIComponent(l))}}};var r=this;for(var i=0,s=Object.entries(this.parsedFilters||{});i<s.length;i++){var o=s[i],a=o[0],l=o[1];n(a,l)}};e.prototype.buildNextPageUrl=function(){var e=this.getSource();if(e==="json"){return}this.initBaseNextPageUrl(e);if(this.isSourceWithoutValue()){return}if(["search","related","landing-page"].includes(e)){this.nextPage+="&source_value=".concat(this.getSourceValue());return}try{this.nextPage+="&source_value[]=".concat(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 ['.concat(e,"]"));this.sourceValueIsValid=false}};e.prototype.loading=function(e){if(e===void 0){e=true}this.btnLoader.style.display=e?"inherit":"none"};e.prototype.getItemHTML=function(e){var t=this.hasCustomComponent?"custom-salla-product-card":"salla-product-card";var n=document.createElement(t);n.product=e;this.applyLandingPageStyles(n);this.applyHorizontalCardStyles(n);return n};e.prototype.applyLandingPageStyles=function(e){if(this.getSource()==="landing-page"&&!this.hasCustomComponent){e.toggleAttribute("hide-add-btn",true);e.classList.add("s-product-card-fit-height")}};e.prototype.applyHorizontalCardStyles=function(e){if(!this.horizontalCards){return}e.setAttribute("horizontal",true);if(!this.hasCustomComponent){e.setAttribute("shadow-on-hover",true)}};e.prototype.getSource=function(){return Helper.getProductsSource(this.source)};e.prototype.getSourceValue=function(){return Helper.getProductsSourceValue(this.source,this.sourceValue)};e.prototype.fetchProducts=function(){var e=this;salla.product.api.fetch({source:this.getSource(),source_value:this.getSourceValue(),limit:this.limit}).then((function(t){if(!t.data.length){e.showPlaceholder=true;e.loading(false);return}e.handleResponse(t).forEach((function(t){return e.wrapper.append(t)}))})).catch((function(){salla.log("Request headers",salla.api.getHeaders());setTimeout((function(){return e.fetchProducts()}),1e3)}))};e.prototype.initiateInfiniteScroll=function(){var e=this;var t,n,r;if(!this.hasInfiniteScroll){return}this.host.insertAdjacentElement("beforeend",this.status);this.infiniteScroll=salla.infiniteScroll.initiate(this.wrapper,this.wrapper,{path:function(){return e.nextPage},history:false,nextPage:this.nextPage,scrollThreshold:100},true);(t=this.infiniteScroll)===null||t===void 0?void 0:t.on("request",(function(){return e.loading()}));(n=this.infiniteScroll)===null||n===void 0?void 0:n.on("load",(function(t){var n;if(!((n=t.data)===null||n===void 0?void 0:n.length)&&e.infiniteScroll.pageIndex==2){e.showPlaceholder=true;salla.infiniteScroll.destroy(e.infiniteScroll);e.loading(false);return}else{e.showPlaceholder=false}e.infiniteScroll.appendItems(e.handleResponse(t));if(e.infiniteScroll.pageIndex==2){e.animateItems()}}));(r=this.infiniteScroll)===null||r===void 0?void 0:r.on("error",(function(){e.status.querySelector(".s-infinite-scroll-error").classList.remove("s-hidden");e.loading(false)}));salla.onReady((function(){return salla.infiniteScroll.loadNextPage(e.infiniteScroll)}))};e.prototype.canRender=function(){return this.sourceValueIsValid&&this.isReady};e.prototype.render=function(){var e=this;salla.log("render: before can render");if(!this.canRender()){return""}salla.log("render: after can render");if(this.showPlaceholder){return h("div",{class:"s-products-list-placeholder"},h("span",{innerHTML:ShoppingBag}),h("p",null,this.placeholderText))}return h(Host,{class:"s-products-list"},h("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:function(t){return e.wrapper=t}}))};e.prototype.componentDidLoad=function(){var e=this;salla.log("component did load before can render");if(!this.canRender()){return}salla.log("component did load after can render");if(this.getSource()==="json"){if(!this.getSourceValue().length){this.showPlaceholder=true;return}this.getSourceValue().map((function(t){return e.wrapper.append(e.getItemHTML(t))}));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()};e.prototype.init=function(){this.initiateInfiniteScroll();this.loading()};e.prototype.handleResponse=function(e){var t=this;var n,r,i,s,o,a;var l=this.getSource();var c="";if(((n=e.cursor)===null||n===void 0?void 0:n.current)===1){c=Helper.getPageTitleForSource(l);try{if(this.getSource()==="search"){c=salla.lang.get("common.elements.search_about",{word:this.getSourceValue()})}else if(!c){var u=this.parsedFilters.category_id||this.getSourceValue()[0];c=((s=(i=(r=e.filters.find((function(e){return e.key=="category_id"})))===null||r===void 0?void 0:r.values)===null||i===void 0?void 0:i.find((function(e){return e.key==u})))===null||s===void 0?void 0:s.value)||""}c+=(c?" - ":"")+salla.lang.choice("blocks.header.products_count",(o=e.data)===null||o===void 0?void 0:o.length);if(e.data.length===20){c=c.replace(e.data.length,salla.lang.get("common.elements.more_than")+" "+e.data.length)}e.title=c}catch(e){}}salla.event.emit("salla-products-list::products.fetched",e);this.productsFetched.emit(e);if(e.filters&&this.isFilterable()){this.filtersResults=true;salla.event.emit("filters::fetched",{filters:e.filters})}else if(this.isFilterable()){salla.event.emit("filters::hidden")}this.nextPage=e.cursor?e.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((a=e.data)===null||a===void 0?void 0:a.map((function(e){return t.getItemHTML(e)})))||[]};Object.defineProperty(e.prototype,"host",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();SallaProductsList.style=sallaProductsListCss;export{SallaProductsList as salla_products_list};
|
|
5
5
|
//# sourceMappingURL=salla-products-list.entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sallaProductsListCss","SallaProductsList","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","stringify","scrollTo","top","behavior","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","encodeURIComponent","Array","isArray","forEach","item","_j","_k","Object","entries","length","_l","k","v","_i","_g","_h","join","loading","isLoading","style","display","getItemHTML","product","customComponentTag","productCard","applyLandingPageStyles","applyHorizontalCardStyles","toggleAttribute","classList","add","horizontalCards","setAttribute","Helper","getProductsSource","getProductsSourceValue","sourceValue","fetchProducts","fetch","source_value","then","res","data","showPlaceholder","handleResponse","card","append","catch","log","getHeaders","setTimeout","initiateInfiniteScroll","host","insertAdjacentElement","initiate","path","history","scrollThreshold","_a","_b","response","pageIndex","appendItems","_c","remove","loadNextPage","canRender","render","h","class","ShoppingBag","Host","ref","componentDidLoad","map","title","cursor","current","getPageTitleForSource","word","catId_1","category_id","_d","find","filter","values","cat","choice","_e","replace","emit","productsFetched","next","option","loadOnScroll","_f"],"sources":["src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import { Component, Host, h, Prop, State, Element, Method, Event, EventEmitter } from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.onReady(() => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n\n\n }\n\n /**\n * Set parsed filters data from URI\n * @param filters\n */\n @Method()\n async setFilters(filters) {\n if (!!filters && JSON.stringify(this.parsedFilters) === JSON.stringify(filters)) {\n return;\n }\n window.scrollTo({ top: 0, behavior: 'smooth' });\n this.parsedFilters = filters;\n return this.reload();\n }\n\n /**\n * Reload the list of products (entire content of the component).\n */\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n // TODO: this is problematic in testing, for the time being it's been resolved like this\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({ mutable: true }) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({ mutable: true }) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({ reflect: true, mutable: true }) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({ reflect: true }) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n /**\n * Custom event fired when the the products fetched.\n */\n @Event() productsFetched: EventEmitter;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n // @ts-ignore\n this.nextPage += `&filters[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`;\n } else if (Array.isArray(value)) {\n value.forEach(item => this.nextPage += `&filters[${encodeURIComponent(key)}][]=${encodeURIComponent(item)}`);\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${encodeURIComponent(key)}][${encodeURIComponent(k)}]=${encodeURIComponent(v)}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n const productCard = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n productCard.product = product;\n\n this.applyLandingPageStyles(productCard);\n this.applyHorizontalCardStyles(productCard);\n\n return productCard;\n }\n\n private applyLandingPageStyles(productCard) {\n if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {\n productCard.toggleAttribute('hide-add-btn', true);\n productCard.classList.add('s-product-card-fit-height');\n }\n }\n\n private applyHorizontalCardStyles(productCard) {\n if (!this.horizontalCards) {\n return;\n }\n productCard.setAttribute('horizontal', true);\n if (!this.hasCustomComponent) {\n productCard.setAttribute('shadow-on-hover', true);\n }\n\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n private fetchProducts() {\n \n salla.product.api.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit\n })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll?.on('request', () => this.loading())\n this.infiniteScroll?.on('load', response => {\n if (!response.data?.length && this.infiniteScroll.pageIndex == 2) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n } else {\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll?.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n 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 let source=this.getSource();\n let title = '';\n //help the developer to know the current page title\n if (response.cursor?.current === 1) {\n title = Helper.getPageTitleForSource(source);\n try {\n if (this.getSource() === 'search') {\n title = salla.lang.get('common.elements.search_about', {'word': this.getSourceValue()});\n } else if (!title) {\n let catId = this.parsedFilters.category_id || this.getSourceValue()[0];\n // get the first filter that its key is category_id, then get the value when filter.value.*.key==catId\n title = response.filters.find(filter => filter.key == 'category_id') ?. values ?. find(cat => cat.key == catId) ?. value || '';\n }\n title += (title ? ' - ' : '') + salla.lang.choice('blocks.header.products_count', response.data ?. length);\n if (response.data.length === 20) {\n title = title.replace(response.data.length, salla.lang.get('common.elements.more_than') + ' ' + response.data.length)\n }\n response.title = title;\n } catch (e) {}\n }\n\n salla.event.emit('salla-products-list::products.fetched', response);\n this.productsFetched.emit(response);\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', { filters: response.filters });\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"mappings":";;;k6BAAA,IAAMA,qBAAuB,G,ICQhBC,kBAAiB,W,qQAsGJ,E,+OArGxBC,EAAAC,UAAAC,kBAAA,eAAAC,EAAAC,KACEC,MAAMC,SAAQ,WACZH,EAAKI,qBAAuBC,eAAeC,IAAI,6BAC/CN,EAAKO,sBAAwBP,EAAKQ,kBAA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AAW,OAAAjG,EAAKgG,YAAYC,EAAjB,MAA8B,E,kIA/YzC,G"}
|
|
1
|
+
{"version":3,"names":["sallaProductsListCss","SallaProductsList","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","stringify","scrollTo","top","behavior","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","encodeURIComponent","Array","isArray","forEach","item","_j","_k","Object","entries","length","_l","k","v","_i","_g","_h","join","loading","isLoading","style","display","getItemHTML","product","customComponentTag","productCard","applyLandingPageStyles","applyHorizontalCardStyles","toggleAttribute","classList","add","horizontalCards","setAttribute","Helper","getProductsSource","getProductsSourceValue","sourceValue","fetchProducts","fetch","source_value","then","res","data","showPlaceholder","handleResponse","card","append","catch","log","getHeaders","setTimeout","initiateInfiniteScroll","host","insertAdjacentElement","initiate","path","history","scrollThreshold","_a","_b","response","pageIndex","appendItems","_c","remove","loadNextPage","canRender","render","h","class","ShoppingBag","Host","ref","componentDidLoad","map","title","cursor","current","getPageTitleForSource","word","catId_1","category_id","_d","find","filter","values","cat","choice","_e","replace","emit","productsFetched","next","option","loadOnScroll","_f"],"sources":["src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import { Component, Host, h, Prop, State, Element, Method, Event, EventEmitter } from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.onReady(() => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n\n\n }\n\n /**\n * Set parsed filters data from URI\n * @param filters\n */\n @Method()\n async setFilters(filters) {\n if (!!filters && JSON.stringify(this.parsedFilters) === JSON.stringify(filters)) {\n return;\n }\n window.scrollTo({ top: 0, behavior: 'smooth' });\n this.parsedFilters = filters;\n return this.reload();\n }\n\n /**\n * Reload the list of products (entire content of the component).\n */\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n // TODO: this is problematic in testing, for the time being it's been resolved like this\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({ mutable: true }) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({ mutable: true }) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({ mutable: true }) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({ reflect: true, mutable: true }) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({ reflect: true }) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n /**\n * Custom event fired when the the products fetched.\n */\n @Event() productsFetched: EventEmitter;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n // @ts-ignore\n this.nextPage += `&filters[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`;\n } else if (Array.isArray(value)) {\n value.forEach(item => this.nextPage += `&filters[${encodeURIComponent(key)}][]=${encodeURIComponent(item)}`);\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${encodeURIComponent(key)}][${encodeURIComponent(k)}]=${encodeURIComponent(v)}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n const customComponentTag = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n const productCard = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n productCard.product = product;\n\n this.applyLandingPageStyles(productCard);\n this.applyHorizontalCardStyles(productCard);\n\n return productCard;\n }\n\n private applyLandingPageStyles(productCard) {\n if (this.getSource() === 'landing-page' && !this.hasCustomComponent) {\n productCard.toggleAttribute('hide-add-btn', true);\n productCard.classList.add('s-product-card-fit-height');\n }\n }\n\n private applyHorizontalCardStyles(productCard) {\n if (!this.horizontalCards) {\n return;\n }\n productCard.setAttribute('horizontal', true);\n if (!this.hasCustomComponent) {\n productCard.setAttribute('shadow-on-hover', true);\n }\n\n }\n\n private getSource() {\n return Helper.getProductsSource(this.source);\n }\n\n private getSourceValue() {\n return Helper.getProductsSourceValue(this.source, this.sourceValue);\n }\n\n private fetchProducts() {\n\n salla.product.api.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit\n })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll?.on('request', () => this.loading())\n this.infiniteScroll?.on('load', response => {\n if (!response.data?.length && this.infiniteScroll.pageIndex == 2) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n } else {\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll?.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n salla.log('render: before can render')\n if (!this.canRender()) {\n return '';\n }\n salla.log('render: after can render')\n if (this.showPlaceholder) {\n return <div class=\"s-products-list-placeholder\">\n <span innerHTML={ShoppingBag} />\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class={{\n \"s-products-list-wrapper\": true,\n 's-products-list-horizontal-cards': this.horizontalCards && !this.filtersResults,\n 's-products-list-vertical-cards': !this.horizontalCards && !this.filtersResults,\n 's-products-list-filters-results': this.filtersResults,\n }}\n ref={wrapper => this.wrapper = wrapper} />\n </Host>\n );\n }\n\n componentDidLoad() {\n salla.log('component did load before can render')\n if (!this.canRender()) {\n return;\n }\n salla.log('component did load after can render')\n\n // Handle json source\n if (this.getSource() === 'json') {\n if (!this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n // Handle selected source\n if (this.getSource() === 'selected' || this.getSource() === 'landing-page') {\n if (this.getSource() === 'selected' && !this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.fetchProducts()\n return;\n }\n this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n }\n\n private handleResponse(response): Array<HTMLElement> {\n let source=this.getSource();\n let title = '';\n //help the developer to know the current page title\n if (response.cursor?.current === 1) {\n title = Helper.getPageTitleForSource(source);\n try {\n if (this.getSource() === 'search') {\n title = salla.lang.get('common.elements.search_about', {'word': this.getSourceValue()});\n } else if (!title) {\n let catId = this.parsedFilters.category_id || this.getSourceValue()[0];\n // get the first filter that its key is category_id, then get the value when filter.value.*.key==catId\n title = response.filters.find(filter => filter.key == 'category_id') ?. values ?. find(cat => cat.key == catId) ?. value || '';\n }\n title += (title ? ' - ' : '') + salla.lang.choice('blocks.header.products_count', response.data ?. length);\n if (response.data.length === 20) {\n title = title.replace(response.data.length, salla.lang.get('common.elements.more_than') + ' ' + response.data.length)\n }\n response.title = title;\n } catch (e) {}\n }\n\n salla.event.emit('salla-products-list::products.fetched', response);\n this.productsFetched.emit(response);\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', { filters: response.filters });\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"mappings":";;;k6BAAA,IAAMA,qBAAuB,G,ICQhBC,kBAAiB,W,qQAsGJ,E,+OArGxBC,EAAAC,UAAAC,kBAAA,eAAAC,EAAAC,KACEC,MAAMC,SAAQ,WACZH,EAAKI,qBAAuBC,eAAeC,IAAI,6BAC/CN,EAAKO,sBAAwBP,EAAKQ,kBAAoBR,EAAKS,wBAC3DT,EAAKU,mBAAqB,CAAC,OAAQ,WAAY,UAAW,gBAAgBC,SAASX,EAAKY,aACxF,IACE,IAAIC,EAAe,IAAIC,gBAAgBC,OAAOC,SAASC,QACvDjB,EAAKkB,OAASlB,EAAKkB,QAAUL,EAAaP,IAAI,SAAWO,EAAaP,IAAI,MAC1E,IAAIa,EAAUN,EAAaP,IAAI,WAC/BN,EAAKoB,cAAgBD,EAAUE,KAAKC,MAAMC,mBAAmBJ,IAAY,E,CACzE,MAAOK,GACPtB,MAAMuB,OAAOC,KAAK,iCAAkCF,EAAEG,Q,CAExD3B,EAAK4B,mBACL5B,EAAK6B,kBAEL7B,EAAK8B,QAAU,I,IAGjB,IAAK7B,KAAKM,mBAAoB,CAC5BL,M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AA,EAAI9E,QACnG,GAAIkD,EAASlB,KAAKhC,SAAW,GAAI,CAC7BiE,EAAQA,EAAMc,QAAQ7B,EAASlB,KAAKhC,OAAQlF,MAAM2D,KAAKvD,IAAI,6BAA+B,IAAMgI,EAASlB,KAAKhC,O,CAElHkD,EAASe,MAAQA,CACT,CAAV,MAAO7H,GAAG,C,CAGhBtB,MAAM8B,MAAMoI,KAAK,wCAAyC9B,GAC1DrI,KAAKoK,gBAAgBD,KAAK9B,GAE1B,GAAIA,EAASnH,SAAWlB,KAAK4C,eAAgB,CAC3C5C,KAAK8C,eAAiB,KACtB7C,MAAM8B,MAAMoI,KAAK,mBAAoB,CAAEjJ,QAASmH,EAASnH,S,MACpD,GAAIlB,KAAK4C,eAAgB,CAC9B3C,MAAM8B,MAAMoI,KAAK,kB,CAEnBnK,KAAKmE,SAAWkE,EAASgB,OAAShB,EAASgB,OAAOgB,KAAOrK,KAAKmE,SAC9DnE,KAAK2F,QAAQ,OACb,GAAI3F,KAAKS,oBAAsBT,KAAKmE,SAAU,CAC5CnE,KAAKuC,eAAe+H,OAAO,CAAEpC,gBAAiB,MAAOqC,aAAc,QACnEvK,KAAKwD,OAAOM,cAAc,2BAA2BwC,UAAUmC,OAAO,W,CAExE,QAAO+B,EAAAnC,EAASlB,QAAI,MAAAqD,SAAA,SAAAA,EAAErB,KAAI,SAAAnD,GAAW,OAAAjG,EAAKgG,YAAYC,EAAjB,MAA8B,E,kIAnZzC,G"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* Crafted with ❤ by Salla
|
|
3
3
|
*/
|
|
4
|
-
import{r as registerInstance,h,H as Host,g as getElement}from"./index-56f9513d.js";import{H as Helper}from"./Helper-c2739d13.js";var sallaProductsSliderCss="";var SallaProductsSlider=function(){function e(e){var t=this;registerInstance(this,e);this.blockTitle=undefined;this.subTitle=undefined;this.sliderId=undefined;this.displayAllUrl=undefined;this.autoplay=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(){t.sourceValueIsValid=!!(t.getSourceValue()||t.isSourceWithoutValue());if(!t.sourceValueIsValid){salla.logger.warn("source-value prop is required for source [".concat(t.getSource(),"]"));return}t.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 h("div",{class:"s-products-slider-card"},h("custom-salla-product-card",{product:e,source:this.getSource(),"source-value":this.getSourceValue()}))}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:e}))};e.prototype.canRender=function(){return this.sourceValueIsValid&&this.isReady};e.prototype.componentWillLoad=function(){if(this.source==="json"){this.productsData=this.getSourceValue();this.isReady=true;return}return this.fetchProducts()};e.prototype.fetchProducts=function(){var e=this;return salla.product.api.fetch({source:
|
|
4
|
+
import{r as registerInstance,h,H as Host,g as getElement}from"./index-56f9513d.js";import{H as Helper}from"./Helper-c2739d13.js";var sallaProductsSliderCss="";var SallaProductsSlider=function(){function e(e){var t=this;registerInstance(this,e);this.blockTitle=undefined;this.subTitle=undefined;this.sliderId=undefined;this.displayAllUrl=undefined;this.autoplay=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(){t.sourceValueIsValid=!!(t.getSourceValue()||t.isSourceWithoutValue());if(!t.sourceValueIsValid){salla.logger.warn("source-value prop is required for source [".concat(t.getSource(),"]"));return}t.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 h("div",{class:"s-products-slider-card"},h("custom-salla-product-card",{product:e,source:this.getSource(),"source-value":this.getSourceValue()}))}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:e}))};e.prototype.canRender=function(){return this.sourceValueIsValid&&this.isReady};e.prototype.componentWillLoad=function(){if(this.source==="json"){this.productsData=this.getSourceValue();this.isReady=true;return}return this.fetchProducts()};e.prototype.fetchProducts=function(){var e=this;return salla.api.withoutNotifier((function(){return salla.product.api.fetch({source:e.getSource(),source_value:e.getSourceValue(),limit:e.limit}).then((function(t){e.productsData=t.data;e.isReady=true;salla.event.emit("salla-products-slider::products.fetched",t.data)})).catch((function(){salla.log("Request headers",salla.api.getHeaders());setTimeout((function(){return e.fetchProducts()}),1e3)}))}))};e.prototype.getSource=function(){return Helper.getProductsSource(this.source)};e.prototype.getSourceValue=function(){return Helper.getProductsSourceValue(this.source,this.sourceValue)};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 h(Host,{class:"s-products-slider-wrapper"},h("salla-slider",{class:"s-products-slider-slider",id:this.sliderId||"s-products-slider-".concat(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"},(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 getElement(this)},enumerable:false,configurable:true});return e}();SallaProductsSlider.style=sallaProductsSliderCss;export{SallaProductsSlider as salla_products_slider};
|
|
5
5
|
//# sourceMappingURL=salla-products-slider.entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sallaProductsSliderCss","SallaProductsSlider","hostRef","_this","this","salla","onReady","sourceValueIsValid","getSourceValue","isSourceWithoutValue","logger","warn","concat","getSource","hasCustomComponent","customElements","get","prototype","includes","getItemHTML","product","h","class","source","canRender","isReady","componentWillLoad","productsData","fetchProducts","api","fetch","source_value","limit","then","res","data","event","emit","catch","log","getHeaders","setTimeout","Helper","getProductsSource","getProductsSourceValue","sourceValue","render","config","Host","id","sliderId","Math","random","toString","substr","autoplay","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';\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.getSourceValue() || 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 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 this.fetchProducts();\n\n }\n\n private fetchProducts() {\n return salla.product.api.fetch({\n
|
|
1
|
+
{"version":3,"names":["sallaProductsSliderCss","SallaProductsSlider","hostRef","_this","this","salla","onReady","sourceValueIsValid","getSourceValue","isSourceWithoutValue","logger","warn","concat","getSource","hasCustomComponent","customElements","get","prototype","includes","getItemHTML","product","h","class","source","canRender","isReady","componentWillLoad","productsData","fetchProducts","api","withoutNotifier","fetch","source_value","limit","then","res","data","event","emit","catch","log","getHeaders","setTimeout","Helper","getProductsSource","getProductsSourceValue","sourceValue","render","config","Host","id","sliderId","Math","random","toString","substr","autoplay","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';\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.getSourceValue() || 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 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 this.fetchProducts();\n\n }\n\n private fetchProducts() {\n return salla.api.withoutNotifier(() => \n salla.product.api.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 salla.event.emit('salla-products-slider::products.fetched', res.data);\n }).catch(() => {\n // TODO: Find the real issue and fix it\n salla.log('Request headers', salla.api.getHeaders());\n setTimeout(() => this.fetchProducts(), 1000);\n })\n )\n }\n private 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-sl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