@salla.sa/twilight-components 2.11.95 → 2.11.96
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-add-product-button_40.cjs.entry.js +11 -5
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-list.cjs.entry.js +2 -3
- package/dist/cjs/salla-products-list.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-slider.cjs.entry.js +2 -3
- package/dist/cjs/salla-products-slider.cjs.entry.js.map +1 -1
- package/dist/collection/components/salla-add-product-button/salla-add-product-button.js +1 -1
- package/dist/collection/components/salla-add-product-button/salla-add-product-button.js.map +1 -1
- package/dist/collection/components/salla-product-card/salla-product-card.js +5 -2
- package/dist/collection/components/salla-product-card/salla-product-card.js.map +1 -1
- package/dist/collection/components/salla-products-list/salla-products-list.js +2 -3
- 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 -3
- package/dist/collection/components/salla-products-slider/salla-products-slider.js.map +1 -1
- package/dist/collection/components/salla-progress-bar/salla-progress-bar.js +5 -2
- package/dist/collection/components/salla-progress-bar/salla-progress-bar.js.map +1 -1
- package/dist/components/salla-add-product-button2.js +1 -1
- package/dist/components/salla-add-product-button2.js.map +1 -1
- package/dist/components/salla-product-card2.js +5 -2
- package/dist/components/salla-product-card2.js.map +1 -1
- package/dist/components/salla-products-list.js +2 -3
- package/dist/components/salla-products-list.js.map +1 -1
- package/dist/components/salla-products-slider.js +2 -3
- package/dist/components/salla-products-slider.js.map +1 -1
- package/dist/components/salla-progress-bar2.js +5 -2
- package/dist/components/salla-progress-bar2.js.map +1 -1
- package/dist/esm/salla-add-product-button_40.entry.js +11 -5
- package/dist/esm/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm/salla-products-list.entry.js +2 -3
- package/dist/esm/salla-products-list.entry.js.map +1 -1
- package/dist/esm/salla-products-slider.entry.js +2 -3
- package/dist/esm/salla-products-slider.entry.js.map +1 -1
- package/dist/esm-es5/salla-add-product-button_40.entry.js +2 -2
- package/dist/esm-es5/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm-es5/salla-products-list.entry.js +1 -1
- package/dist/esm-es5/salla-products-list.entry.js.map +1 -1
- package/dist/esm-es5/salla-products-slider.entry.js +1 -1
- package/dist/esm-es5/salla-products-slider.entry.js.map +1 -1
- package/dist/twilight/p-009ab1f2.system.entry.js +5 -0
- package/dist/twilight/p-009ab1f2.system.entry.js.map +1 -0
- package/dist/twilight/{p-b28388c6.entry.js → p-23f7c19e.entry.js} +3 -3
- package/dist/twilight/p-23f7c19e.entry.js.map +1 -0
- package/dist/twilight/p-437c62e8.system.js +1 -1
- package/dist/twilight/p-69a92ff4.system.entry.js +5 -0
- package/dist/twilight/p-69a92ff4.system.entry.js.map +1 -0
- package/dist/twilight/{p-152e1cd4.system.entry.js → p-6a906858.system.entry.js} +3 -3
- package/dist/twilight/p-6a906858.system.entry.js.map +1 -0
- package/dist/twilight/p-a7196205.entry.js +5 -0
- package/dist/twilight/p-a7196205.entry.js.map +1 -0
- package/dist/twilight/p-ffcd40eb.entry.js +5 -0
- package/dist/twilight/p-ffcd40eb.entry.js.map +1 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/types/components/salla-product-card/salla-product-card.d.ts +1 -0
- package/package.json +2 -2
- package/dist/twilight/p-07d3cdea.entry.js +0 -5
- package/dist/twilight/p-07d3cdea.entry.js.map +0 -1
- package/dist/twilight/p-152e1cd4.system.entry.js.map +0 -1
- package/dist/twilight/p-18d654a0.entry.js +0 -5
- package/dist/twilight/p-18d654a0.entry.js.map +0 -1
- package/dist/twilight/p-5316354e.system.entry.js +0 -5
- package/dist/twilight/p-5316354e.system.entry.js.map +0 -1
- package/dist/twilight/p-affbcb10.system.entry.js +0 -5
- package/dist/twilight/p-affbcb10.system.entry.js.map +0 -1
- package/dist/twilight/p-b28388c6.entry.js.map +0 -1
|
@@ -18,9 +18,8 @@ const SallaProductsList = class {
|
|
|
18
18
|
// State
|
|
19
19
|
this.page = 1;
|
|
20
20
|
this.urlPrefix = '';
|
|
21
|
-
// this.source = this.source || 'latest';
|
|
22
21
|
salla.onReady(() => {
|
|
23
|
-
this.source =
|
|
22
|
+
this.source = {
|
|
24
23
|
'brands.single': 'brands',
|
|
25
24
|
'product.index': 'categories',
|
|
26
25
|
'product.index.latest': 'latest',
|
|
@@ -28,7 +27,7 @@ const SallaProductsList = class {
|
|
|
28
27
|
'product.index.search': 'search',
|
|
29
28
|
'landing-page': 'landing-page',
|
|
30
29
|
'product.index.tag': 'tags',
|
|
31
|
-
}[salla.config.get('page.slug')] || 'latest';
|
|
30
|
+
}[this.source || salla.config.get('page.slug')] || this.source || 'latest';
|
|
32
31
|
let parsedSourceValue = this.sourceValue = this.sourceValue || this.getSourceValue();
|
|
33
32
|
if (this.sourceValue && ['categories', 'brands', 'tags', 'selected'].includes(this.source) && typeof this.sourceValue == 'string') {
|
|
34
33
|
parsedSourceValue = JSON.parse(this.sourceValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-list.entry.js","mappings":";;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,EAAE;;MCOlB,iBAAiB;EAC5B;;;IAoHS,SAAI,GAAW,CAAC,CAAC;IAQjB,cAAS,GAAW,EAAE,CAAC;;IA1H9B,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI;QAC3B,eAAe,EAAE,QAAQ;QACzB,eAAe,EAAE,YAAY;QAC7B,sBAAsB,EAAE,QAAQ;QAChC,sBAAsB,EAAE,QAAQ;QAChC,sBAAsB,EAAE,QAAQ;QAChC,cAAc,EAAE,cAAc;QAC9B,mBAAmB,EAAE,MAAM;OAC5B,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,QAAQ,CAAC;MAG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AC,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, Watch } from '@stencil/core';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\n\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n constructor() {\n // this.source = this.source || 'latest';\n salla.onReady(() => {\n this.source = this.source || {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'product.index.search': 'search',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n }[salla.config.get('page.slug')] || 'latest';\n\n\n let parsedSourceValue = this.sourceValue = this.sourceValue || this.getSourceValue();\n\n if (this.sourceValue && ['categories', 'brands', 'tags', 'selected'].includes(this.source) && typeof this.sourceValue == 'string') {\n parsedSourceValue = JSON.parse(this.sourceValue);\n }\n this.parsedSourceValue = parsedSourceValue;\n this.sourceValueIsValid = !!(this.sourceValue || ['latest', 'offers'].includes(this.source));\n this.buildNextPageUrl();\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.source}]`);\n return;\n }\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.source);\n // Language\n //enhance\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 readonly 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';\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 * Filter parameters. JSON STRING or object\n */\n @Prop({ mutable: true }) filters: string | object;\n\n @Watch('limit')\n validateLimitMaximumValue(_newValue: number, _) {\n if (this.limit) {\n this.urlPrefix += `&per_page=${this.limit > 32 ? 32 : this.limit}}`;\n }\n }\n\n @Watch('filters')\n parseFilters(newValue: string | object, _) {\n this.parsedFilters = typeof newValue == 'string' ? JSON.parse(newValue) : newValue\n this.urlPrefix = '';\n\n for (const [key, value] of Object.entries(this.parsedFilters)) {\n if (typeof value == \"string\") {\n this.urlPrefix += `&filters[${key}]=${value}`;\n }\n else if (Array.isArray(value)) {\n (value as any).forEach(item => {\n this.urlPrefix += `&filters[${key}][]=${item}}`\n })\n }\n }\n // reset page products\n if (this.source == 'categories') {\n this.wrapper.innerHTML = '';\n this.init()\n }\n }\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() urlPrefix: string = '';\n @State() parsedSourceValue: any;\n @State() parsedFilters: any;\n\n\n private buildNextPageUrl() {\n if (this.source === 'json') {\n return;\n }\n if (['offers', 'latest'].includes(this.source)) {\n this.nextPage = salla.url.api(`products?source=${this.source}${this.urlPrefix}`);\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(this.source)) {\n this.nextPage = salla.url.api(`products?source=${this.source}&source_value=${this.parsedSourceValue}${this.urlPrefix}`);\n return;\n }\n\n try {\n this.nextPage = salla.url.api(`products?source=${this.source}&source_value[]=${this.parsedSourceValue.join('&source_value[]=')}${this.urlPrefix}`);\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${this.source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n private getSourceValue() {\n if (['landing-page'].includes(this.source)) {\n return `${salla.config.get('page.id')}`\n } else if (['categories', 'brands', 'tags'].includes(this.source)) {\n return JSON.stringify([salla.config.get('page.id')])\n }\n return this.sourceValue;\n }\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n let customComponent: string | HTMLElement = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n customComponent = document.createElement(customComponent);\n customComponent.setAttribute('product', JSON.stringify(product));\n if (this.source == 'landing-page' && !this.hasCustomComponent) {\n customComponent.toggleAttribute('hide-add-btn', true);\n customComponent.toggleAttribute('show-quantity', true);\n customComponent.classList.add('s-product-card-fit-height');\n }\n customComponent.toggleAttribute('shadow-on-hover', true);\n return customComponent;\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('afterend', 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 => this.infiniteScroll.appendItems(this.handleResponse(response)))\n this.infiniteScroll.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\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}></span>\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class=\"s-products-list-wrapper\" ref={wrapper => this.wrapper = wrapper} />\n </Host>\n );\n }\n\n componentDidLoad() {\n if (!this.canRender()) {\n return;\n }\n if (this.source === 'json') {\n if (!this.parsedSourceValue.length) {\n this.showPlaceholder = true;\n return;\n }\n this.parsedSourceValue.map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n if (this.source == 'categories') {\n // check if there is a filters in the url\n const filters = window.location.search\n .replace('?', '')\n .split('&')\n .map(item => item.split('='))\n .reduce((acc, [key, value]) => {\n if (key == 'sort') {\n acc[key] = value;\n }\n return acc;\n }, {});\n if (filters) {\n this.filters = filters;\n return;\n }\n }\n this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n salla.product.fetch({ source: this.source, source_value: this.parsedSourceValue, filters: this.filters, limit: this.limit })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n })\n }\n private handleResponse(response): Array<HTMLElement> {\n //💡 when source is related, cursor will not be existed\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({ scrollThreshold: false, loadOnScroll: false });\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"salla-products-list.entry.js","mappings":";;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,EAAE;;MCOlB,iBAAiB;EAC5B;;;IAmHS,SAAI,GAAW,CAAC,CAAC;IAQjB,cAAS,GAAW,EAAE,CAAC;IA1H9B,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,MAAM,GAAG;QACZ,eAAe,EAAE,QAAQ;QACzB,eAAe,EAAE,YAAY;QAC7B,sBAAsB,EAAE,QAAQ;QAChC,sBAAsB,EAAE,QAAQ;QAChC,sBAAsB,EAAE,QAAQ;QAChC,cAAc,EAAE,cAAc;QAC9B,mBAAmB,EAAE,MAAM;OAC5B,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,IAAG,QAAQ,CAAC;MAG1E,IAAI,iBAAiB,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;MAErF,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,OAAO,IAAI,CAAC,WAAW,IAAI,QAAQ,EAAE;QACjI,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;OAClD;MACD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;MAC3C,IAAI,CAAC,kBAAkB,GAAG,CAAC,EAAE,IAAI,CAAC,WAAW,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,I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AC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;KACrE,CAAC,CAAA;GACL;EACO,cAAc,CAAC,QAAQ;;;IAE7B,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, Watch } from '@stencil/core';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\n\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n constructor() {\n salla.onReady(() => {\n this.source = {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'product.index.search': 'search',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n }[this.source || salla.config.get('page.slug')] || this.source ||'latest';\n\n\n let parsedSourceValue = this.sourceValue = this.sourceValue || this.getSourceValue();\n\n if (this.sourceValue && ['categories', 'brands', 'tags', 'selected'].includes(this.source) && typeof this.sourceValue == 'string') {\n parsedSourceValue = JSON.parse(this.sourceValue);\n }\n this.parsedSourceValue = parsedSourceValue;\n this.sourceValueIsValid = !!(this.sourceValue || ['latest', 'offers'].includes(this.source));\n this.buildNextPageUrl();\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.source}]`);\n return;\n }\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.source);\n // Language\n //enhance\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 readonly 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';\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 * Filter parameters. JSON STRING or object\n */\n @Prop({ mutable: true }) filters: string | object;\n\n @Watch('limit')\n validateLimitMaximumValue(_newValue: number, _) {\n if (this.limit) {\n this.urlPrefix += `&per_page=${this.limit > 32 ? 32 : this.limit}}`;\n }\n }\n\n @Watch('filters')\n parseFilters(newValue: string | object, _) {\n this.parsedFilters = typeof newValue == 'string' ? JSON.parse(newValue) : newValue\n this.urlPrefix = '';\n\n for (const [key, value] of Object.entries(this.parsedFilters)) {\n if (typeof value == \"string\") {\n this.urlPrefix += `&filters[${key}]=${value}`;\n }\n else if (Array.isArray(value)) {\n (value as any).forEach(item => {\n this.urlPrefix += `&filters[${key}][]=${item}}`\n })\n }\n }\n // reset page products\n if (this.source == 'categories') {\n this.wrapper.innerHTML = '';\n this.init()\n }\n }\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() urlPrefix: string = '';\n @State() parsedSourceValue: any;\n @State() parsedFilters: any;\n\n\n private buildNextPageUrl() {\n if (this.source === 'json') {\n return;\n }\n if (['offers', 'latest'].includes(this.source)) {\n this.nextPage = salla.url.api(`products?source=${this.source}${this.urlPrefix}`);\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(this.source)) {\n this.nextPage = salla.url.api(`products?source=${this.source}&source_value=${this.parsedSourceValue}${this.urlPrefix}`);\n return;\n }\n\n try {\n this.nextPage = salla.url.api(`products?source=${this.source}&source_value[]=${this.parsedSourceValue.join('&source_value[]=')}${this.urlPrefix}`);\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${this.source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n private getSourceValue() {\n if (['landing-page'].includes(this.source)) {\n return `${salla.config.get('page.id')}`\n } else if (['categories', 'brands', 'tags'].includes(this.source)) {\n return JSON.stringify([salla.config.get('page.id')])\n }\n return this.sourceValue;\n }\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n let customComponent: string | HTMLElement = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n customComponent = document.createElement(customComponent);\n customComponent.setAttribute('product', JSON.stringify(product));\n if (this.source == 'landing-page' && !this.hasCustomComponent) {\n customComponent.toggleAttribute('hide-add-btn', true);\n customComponent.toggleAttribute('show-quantity', true);\n customComponent.classList.add('s-product-card-fit-height');\n }\n customComponent.toggleAttribute('shadow-on-hover', true);\n return customComponent;\n }\n\n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('afterend', 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 => this.infiniteScroll.appendItems(this.handleResponse(response)))\n this.infiniteScroll.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\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}></span>\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class=\"s-products-list-wrapper\" ref={wrapper => this.wrapper = wrapper} />\n </Host>\n );\n }\n\n componentDidLoad() {\n if (!this.canRender()) {\n return;\n }\n if (this.source === 'json') {\n if (!this.parsedSourceValue.length) {\n this.showPlaceholder = true;\n return;\n }\n this.parsedSourceValue.map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n if (this.source == 'categories') {\n // check if there is a filters in the url\n const filters = window.location.search\n .replace('?', '')\n .split('&')\n .map(item => item.split('='))\n .reduce((acc, [key, value]) => {\n if (key == 'sort') {\n acc[key] = value;\n }\n return acc;\n }, {});\n if (filters) {\n this.filters = filters;\n return;\n }\n }\n this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n salla.product.fetch({ source: this.source, source_value: this.parsedSourceValue, filters: this.filters, limit: this.limit })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n })\n }\n private handleResponse(response): Array<HTMLElement> {\n //💡 when source is related, cursor will not be existed\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}
|
|
@@ -11,15 +11,14 @@ const SallaProductsSlider = class {
|
|
|
11
11
|
this.urlPrefix = '';
|
|
12
12
|
this.apiUrl = '';
|
|
13
13
|
salla.onReady(() => {
|
|
14
|
-
this.source =
|
|
14
|
+
this.source = {
|
|
15
15
|
'brands.single': 'brands',
|
|
16
16
|
'product.index': 'categories',
|
|
17
17
|
'product.index.latest': 'latest',
|
|
18
18
|
'product.index.offers': 'offers',
|
|
19
19
|
'landing-page': 'landing-page',
|
|
20
20
|
'product.index.tag': 'tags',
|
|
21
|
-
|
|
22
|
-
}[salla.config.get('page.slug')] || 'latest';
|
|
21
|
+
}[this.source || salla.config.get('page.slug')] || this.source || 'latest';
|
|
23
22
|
let parsedSourceValue = this.sourceValue = this.sourceValue || this.getSourceValue();
|
|
24
23
|
if (this.sourceValue && ['categories', 'brands', 'tags', 'selected'].includes(this.source) && typeof this.sourceValue == 'string') {
|
|
25
24
|
parsedSourceValue = JSON.parse(this.sourceValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-slider.entry.js","mappings":";;;;;AAAA,MAAM,sBAAsB,GAAG,EAAE;;MCMpB,mBAAmB;EAC9B;;
|
|
1
|
+
{"file":"salla-products-slider.entry.js","mappings":";;;;;AAAA,MAAM,sBAAsB,GAAG,EAAE;;MCMpB,mBAAmB;EAC9B;;IAmFS,cAAS,GAAW,EAAE,CAAC;IACvB,WAAM,GAAW,EAAE,CAAC;IAnF3B,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,MAAM,GAAG;QACZ,eAAe,EAAE,QAAQ;QACzB,eAAe,EAAE,YAAY;QAC7B,sBAAsB,EAAE,QAAQ;QAChC,sBAAsB,EAAE,QAAQ;QAChC,cAAc,EAAE,cAAc;QAC9B,mBAAmB,EAAE,MAAM;OAC5B,CAAC,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,IAAK,QAAQ,CAAC;MAE5E,IAAI,iBAAiB,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;MAErF,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,OAAO,IAAI,CAAC,WAAW,IAAI,QAAQ,EAAE;QACjI,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;OAClD;MACD,IAAI,CAAC,iBAAiB,GAAG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AAA;MAChD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;MACnB,OAAO;KACR;IACD,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG;MACvD,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,IAAI,CAAA;MAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;KACpB,CAAC,CAAA;GACH;EAED,MAAM;;IACJ,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE;MACnG,OAAO;KACR;IACD,QACE,EAAC,IAAI,IAAC,KAAK,EAAC,2BAA2B,IACrC,oBACE,KAAK,EAAC,0BAA0B,EAChC,EAAE,EAAE,IAAI,CAAC,QAAQ,IAAI,qBAAqB,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EACnF,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,CAAC,OAAO,KAC9B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAC1B,CACG,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';\n\n@Component({\n tag: 'salla-products-slider',\n styleUrl: 'salla-products-slider.scss'\n})\nexport class SallaProductsSlider {\n constructor() {\n salla.onReady(() => {\n this.source = {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n }[this.source || salla.config.get('page.slug')] || this.source || 'latest';\n \n let parsedSourceValue = this.sourceValue = this.sourceValue || this.getSourceValue();\n\n if (this.sourceValue && ['categories', 'brands', 'tags', 'selected'].includes(this.source) && typeof this.sourceValue == 'string') {\n parsedSourceValue = JSON.parse(this.sourceValue);\n }\n this.parsedSourceValue = parsedSourceValue;\n this.sourceValueIsValid = !!(this.sourceValue || ['latest', 'offers'].includes(this.source));\n\n });\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.source}]`);\n return;\n }\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n }\n\n @Element() host: HTMLElement;\n //todo:: support limit, default =10, make sure that maximum is 32,\n\n /**\n * Title of the block - works only if slider is true\n * @type {string}\n * @default ''\n * */\n @Prop() blockTitle: string;\n\n /**\n * Sub title of the block - works only if slider is true\n * @type {string}\n * @default ''\n * */\n @Prop() subTitle: string;\n\n /**\n * Slider Id, if not provided will be generated automatically\n * @type {string}\n * @default ''\n * */\n @Prop() sliderId: string;\n\n /**\n * Display 'ALL' URL\n * @type {string}\n * @default ''\n * */\n @Prop() displayAllUrl: string;\n\n /**\n * Source of the products, if api will get the products from the API, if json will get the products from the products prop\n * @type {string}\n * @default ''\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'tags' | 'selected' | 'offers' | 'landing-page';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop() sourceValue: string;\n\n //todo:: remove this\n @State() productsData: any;\n @State() isReady: boolean;\n @State() sourceValueIsValid: boolean;\n @State() hasCustomComponent: boolean;\n @State() urlPrefix: string = '';\n @State() apiUrl: string = '';\n @State() parsedSourceValue: any;\n private getSourceValue() {\n if (['landing-page', 'related'].includes(this.source)) {\n return `${salla.config.get('page.id')}`\n } else if (['categories', 'brands', 'tags'].includes(this.source)) {\n return JSON.stringify([salla.config.get('page.id')])\n }\n return this.sourceValue;\n }\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.source} source-value={this.sourceValue}/>\n </div>;\n }\n\n return <div class=\"s-products-slider-card\">\n <salla-product-card\n show-quantity={this.source == 'landing-page'}\n hide-add-btn={this.source == 'landing-page'}\n shadow-on-hover={true}\n product={product}/>\n </div>;\n }\n\n getApiUrl() {\n if (this.source === 'json') {\n return;\n }\n if (['offers', 'latest'].includes(this.source)) {\n return salla.url.api(`products?source=${this.source}${this.urlPrefix}`);\n }\n if (['related', 'landing-page'].includes(this.source)) {\n return salla.url.api(`products?source=${this.source}&source_value=${this.sourceValue}${this.urlPrefix}`);\n }\n\n try {\n let ids: Array<number> = JSON.parse(this.sourceValue);\n return salla.url.api(`products?source=${this.source}&source_value[]=${ids.join('&source_value[]=')}${this.urlPrefix}`);\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${this.source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n componentWillLoad() {\n if (this.source === 'json') {\n this.productsData = JSON.parse(this.sourceValue)\n this.isReady = true\n return;\n }\n salla.api.request(this.getApiUrl(), null, 'get').then(res => {\n this.productsData = res.data\n this.isReady = true\n })\n }\n\n render() {\n if ((this.source == 'related' && salla.config.get('product.related_products')) || !this.canRender()) {\n return;\n }\n return (\n <Host class=\"s-products-slider-wrapper\">\n <salla-slider\n class=\"s-products-slider-slider\"\n id={this.sliderId || `s-products-slider-${Math.random().toString(36).substr(2, 9)}`}\n type=\"carousel\"\n block-title={this.blockTitle}\n block-subTitle={this.subTitle}\n display-all-url={this.displayAllUrl}\n >\n <div slot=\"items\">\n {this.productsData?.map((product) =>\n this.getItemHTML(product)\n )}\n </div>\n </salla-slider>\n </Host>\n );\n }\n\n}\n"],"version":3}
|