@salla.sa/twilight-components 2.11.110 → 2.11.112
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/README.md +48 -42
- package/dist/cjs/{app-globals-c392da62.js → app-globals-38ac4fe8.js} +2 -2
- package/dist/cjs/{app-globals-c392da62.js.map → app-globals-38ac4fe8.js.map} +1 -1
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js +74 -24
- package/dist/cjs/salla-add-product-button_40.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-filters-widget.cjs.entry.js +5 -27
- package/dist/cjs/salla-filters-widget.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-filters.cjs.entry.js +8 -4
- package/dist/cjs/salla-filters.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-price-range.cjs.entry.js +109 -37
- package/dist/cjs/salla-price-range.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-list.cjs.entry.js +85 -59
- package/dist/cjs/salla-products-list.cjs.entry.js.map +1 -1
- package/dist/cjs/salla-products-slider.cjs.entry.js +12 -4
- package/dist/cjs/salla-products-slider.cjs.entry.js.map +1 -1
- package/dist/cjs/twilight.cjs.js +2 -2
- package/dist/collection/components/salla-filters/salla-filters.js +8 -4
- package/dist/collection/components/salla-filters/salla-filters.js.map +1 -1
- package/dist/collection/components/salla-filters-widget/salla-filters-widget.js +5 -27
- package/dist/collection/components/salla-filters-widget/salla-filters-widget.js.map +1 -1
- package/dist/collection/components/salla-login-modal/intefaces.js.map +1 -1
- package/dist/collection/components/salla-login-modal/salla-login-modal.js +1 -1
- package/dist/collection/components/salla-login-modal/salla-login-modal.js.map +1 -1
- package/dist/collection/components/salla-maintenance-alert/salla-maintenance-alert.js +14 -1
- package/dist/collection/components/salla-maintenance-alert/salla-maintenance-alert.js.map +1 -1
- package/dist/collection/components/salla-price-range/salla-price-range.js +152 -148
- package/dist/collection/components/salla-price-range/salla-price-range.js.map +1 -1
- package/dist/collection/components/salla-products-list/salla-products-list.js +85 -59
- 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 +29 -5
- package/dist/collection/components/salla-products-slider/salla-products-slider.js.map +1 -1
- package/dist/collection/components/salla-verify/salla-verify.css +12 -0
- package/dist/collection/components/salla-verify/salla-verify.js +59 -21
- package/dist/collection/components/salla-verify/salla-verify.js.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/salla-filters-widget2.js +5 -27
- package/dist/components/salla-filters-widget2.js.map +1 -1
- package/dist/components/salla-filters.js +8 -4
- package/dist/components/salla-filters.js.map +1 -1
- package/dist/components/salla-login-modal.js +1 -1
- package/dist/components/salla-login-modal.js.map +1 -1
- package/dist/components/salla-maintenance-alert.js +14 -1
- package/dist/components/salla-maintenance-alert.js.map +1 -1
- package/dist/components/salla-price-range2.js +113 -43
- package/dist/components/salla-price-range2.js.map +1 -1
- package/dist/components/salla-products-list.js +85 -59
- package/dist/components/salla-products-list.js.map +1 -1
- package/dist/components/salla-products-slider.js +13 -5
- package/dist/components/salla-products-slider.js.map +1 -1
- package/dist/components/salla-verify2.js +60 -22
- package/dist/components/salla-verify2.js.map +1 -1
- package/dist/esm/{app-globals-663240cc.js → app-globals-3a81b4f2.js} +2 -2
- package/dist/esm/{app-globals-663240cc.js.map → app-globals-3a81b4f2.js.map} +1 -1
- package/dist/esm/loader.js +2 -2
- package/dist/esm/salla-add-product-button_40.entry.js +74 -24
- package/dist/esm/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm/salla-filters-widget.entry.js +5 -27
- package/dist/esm/salla-filters-widget.entry.js.map +1 -1
- package/dist/esm/salla-filters.entry.js +8 -4
- package/dist/esm/salla-filters.entry.js.map +1 -1
- package/dist/esm/salla-price-range.entry.js +109 -37
- package/dist/esm/salla-price-range.entry.js.map +1 -1
- package/dist/esm/salla-products-list.entry.js +85 -59
- package/dist/esm/salla-products-list.entry.js.map +1 -1
- package/dist/esm/salla-products-slider.entry.js +12 -4
- package/dist/esm/salla-products-slider.entry.js.map +1 -1
- package/dist/esm/twilight.js +2 -2
- package/dist/esm-es5/{app-globals-663240cc.js → app-globals-3a81b4f2.js} +2 -2
- package/dist/{twilight/p-dcfa0f39.system.js.map → esm-es5/app-globals-3a81b4f2.js.map} +1 -1
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/loader.js.map +1 -1
- package/dist/esm-es5/salla-add-product-button_40.entry.js +4 -4
- package/dist/esm-es5/salla-add-product-button_40.entry.js.map +1 -1
- package/dist/esm-es5/salla-filters-widget.entry.js +1 -1
- package/dist/esm-es5/salla-filters-widget.entry.js.map +1 -1
- package/dist/esm-es5/salla-filters.entry.js +1 -1
- package/dist/esm-es5/salla-filters.entry.js.map +1 -1
- package/dist/esm-es5/salla-price-range.entry.js +2 -2
- package/dist/esm-es5/salla-price-range.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/esm-es5/twilight.js +1 -1
- package/dist/esm-es5/twilight.js.map +1 -1
- package/dist/twilight/{p-6948b825.js → p-1edec127.js} +2 -2
- package/dist/twilight/{p-6948b825.js.map → p-1edec127.js.map} +1 -1
- package/dist/twilight/{p-7c6638f5.system.entry.js → p-2739ddc5.system.entry.js} +2 -2
- package/dist/twilight/p-2739ddc5.system.entry.js.map +1 -0
- package/dist/twilight/p-3212e42c.entry.js +5 -0
- package/dist/twilight/p-3212e42c.entry.js.map +1 -0
- package/dist/twilight/{p-6404a9a5.system.js → p-37389934.system.js} +2 -2
- package/dist/twilight/{p-6404a9a5.system.js.map → p-37389934.system.js.map} +1 -1
- package/dist/twilight/{p-dcfa0f39.system.js → p-38496eab.system.js} +2 -2
- package/dist/{esm-es5/app-globals-663240cc.js.map → twilight/p-38496eab.system.js.map} +1 -1
- package/dist/twilight/p-3f03d17c.system.entry.js +5 -0
- package/dist/twilight/p-3f03d17c.system.entry.js.map +1 -0
- package/dist/twilight/p-46b7f931.system.entry.js +5 -0
- package/dist/twilight/p-46b7f931.system.entry.js.map +1 -0
- package/dist/twilight/p-54783694.system.entry.js +5 -0
- package/dist/twilight/p-54783694.system.entry.js.map +1 -0
- package/dist/twilight/{p-1e4abb42.system.entry.js → p-9a1231a6.system.entry.js} +2 -2
- package/dist/twilight/p-9a1231a6.system.entry.js.map +1 -0
- package/dist/twilight/{p-9713044b.entry.js → p-b766115a.entry.js} +2 -2
- package/dist/twilight/p-b766115a.entry.js.map +1 -0
- package/dist/twilight/p-cd5cb2f7.entry.js +5 -0
- package/dist/twilight/p-cd5cb2f7.entry.js.map +1 -0
- package/dist/twilight/p-d7a62fb3.system.entry.js +5 -0
- package/dist/twilight/p-d7a62fb3.system.entry.js.map +1 -0
- package/dist/twilight/p-def222e1.entry.js +5 -0
- package/dist/twilight/p-def222e1.entry.js.map +1 -0
- package/dist/twilight/p-e393f123.entry.js +5 -0
- package/dist/twilight/p-e393f123.entry.js.map +1 -0
- package/dist/twilight/p-e3dc0687.entry.js +5 -0
- package/dist/twilight/p-e3dc0687.entry.js.map +1 -0
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.esm.js.map +1 -1
- package/dist/twilight/twilight.js +1 -1
- package/dist/types/components/salla-filters-widget/salla-filters-widget.d.ts +0 -7
- package/dist/types/components/salla-login-modal/intefaces.d.ts +1 -0
- package/dist/types/components/salla-maintenance-alert/salla-maintenance-alert.d.ts +3 -0
- package/dist/types/components/salla-price-range/salla-price-range.d.ts +16 -10
- package/dist/types/components/salla-products-list/salla-products-list.d.ts +2 -2
- package/dist/types/components/salla-products-slider/salla-products-slider.d.ts +5 -1
- package/dist/types/components/salla-verify/salla-verify.d.ts +6 -1
- package/dist/types/components.d.ts +14 -8
- package/package.json +4 -4
- package/dist/twilight/p-1e4abb42.system.entry.js.map +0 -1
- package/dist/twilight/p-3b1a0059.entry.js +0 -5
- package/dist/twilight/p-3b1a0059.entry.js.map +0 -1
- package/dist/twilight/p-41b3e09d.entry.js +0 -5
- package/dist/twilight/p-41b3e09d.entry.js.map +0 -1
- package/dist/twilight/p-4a743b5e.system.entry.js +0 -5
- package/dist/twilight/p-4a743b5e.system.entry.js.map +0 -1
- package/dist/twilight/p-62c1b309.entry.js +0 -5
- package/dist/twilight/p-62c1b309.entry.js.map +0 -1
- package/dist/twilight/p-6349125a.entry.js +0 -5
- package/dist/twilight/p-6349125a.entry.js.map +0 -1
- package/dist/twilight/p-7c6638f5.system.entry.js.map +0 -1
- package/dist/twilight/p-8ee37cc6.entry.js +0 -5
- package/dist/twilight/p-8ee37cc6.entry.js.map +0 -1
- package/dist/twilight/p-9713044b.entry.js.map +0 -1
- package/dist/twilight/p-9e27da8e.system.entry.js +0 -5
- package/dist/twilight/p-9e27da8e.system.entry.js.map +0 -1
- package/dist/twilight/p-b1f8b436.system.entry.js +0 -5
- package/dist/twilight/p-b1f8b436.system.entry.js.map +0 -1
- package/dist/twilight/p-c9cdaea6.system.entry.js +0 -5
- package/dist/twilight/p-c9cdaea6.system.entry.js.map +0 -1
|
@@ -9,84 +9,154 @@ const SallaPriceRange = /*@__PURE__*/ proxyCustomElement(class extends HTMLEleme
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
11
11
|
this.__registerHost();
|
|
12
|
-
this.
|
|
13
|
-
this.maxPriceSelected = createEvent(this, "maxPriceSelected", 7);
|
|
12
|
+
this.changed = createEvent(this, "changed", 7);
|
|
14
13
|
this.minPrice = 1000;
|
|
15
14
|
this.maxPrice = 5000;
|
|
15
|
+
this.option = undefined;
|
|
16
|
+
this.filtersData = undefined;
|
|
16
17
|
this.min = 0;
|
|
17
18
|
this.max = 10000;
|
|
18
19
|
this.minthumb = 0;
|
|
19
20
|
this.maxthumb = 0;
|
|
21
|
+
this.priceOptions = undefined;
|
|
22
|
+
this.generatePriceOptions();
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
async reset() {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
//@ts-ignore
|
|
27
|
+
this.minInput.value = `${((_b = (_a = this.option) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b.min) || 0}`;
|
|
28
|
+
this.maxInput.value = `${this.max}`;
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
generatePriceOptions() {
|
|
31
|
+
const MAX_PRICE = this.max;
|
|
32
|
+
let option1 = Math.floor(MAX_PRICE / 100);
|
|
33
|
+
if (option1 < 1) {
|
|
34
|
+
option1 = Math.floor(MAX_PRICE / 10);
|
|
35
|
+
}
|
|
36
|
+
let option2 = Math.floor(MAX_PRICE / 2);
|
|
37
|
+
let option3 = Math.floor((MAX_PRICE / 3) * 2);
|
|
38
|
+
this.priceOptions = [option1, option2, option3];
|
|
39
|
+
// to be removed
|
|
40
|
+
console.log(`Price options for max price ${MAX_PRICE}: ${this.priceOptions.join(', ')}`);
|
|
41
|
+
}
|
|
42
|
+
getPriceLabel(price) {
|
|
43
|
+
if (price == Math.floor(this.max / 100)) {
|
|
44
|
+
return `اقل من ${salla.money(price)}`;
|
|
45
|
+
}
|
|
46
|
+
else if (price == Math.floor(this.max / 2)) {
|
|
47
|
+
return `${salla.money(this.priceOptions[0])} الى ${salla.money(this.priceOptions[2])}`;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
return `أكثر من ${salla.money(price)}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
handleMinMaxPrice(event, option) {
|
|
54
|
+
const [firstOption, secondOption, thirdOption] = this.priceOptions;
|
|
55
|
+
switch (option) {
|
|
56
|
+
case firstOption:
|
|
57
|
+
this.minPrice = 0;
|
|
58
|
+
this.maxPrice = firstOption;
|
|
59
|
+
break;
|
|
60
|
+
case secondOption:
|
|
61
|
+
this.minPrice = firstOption;
|
|
62
|
+
this.maxPrice = thirdOption;
|
|
63
|
+
break;
|
|
64
|
+
case thirdOption:
|
|
65
|
+
this.minPrice = thirdOption;
|
|
66
|
+
this.maxPrice = this.max;
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(`Invalid price option: ${option}`);
|
|
70
|
+
}
|
|
71
|
+
// Update the input values
|
|
72
|
+
this.minInput.value = `${this.minPrice}`;
|
|
73
|
+
this.maxInput.value = `${this.maxPrice}`;
|
|
74
|
+
this.changedEventHandler(event);
|
|
31
75
|
}
|
|
32
|
-
async
|
|
76
|
+
async changedEventHandler(event, isMin = false) {
|
|
33
77
|
let value = event ? event.target.value * 1 : null;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
78
|
+
if (isMin) {
|
|
79
|
+
this.minInputValidation(value);
|
|
80
|
+
this.minthumb = ((this.minPrice - this.min) / (this.max - this.min)) * 100;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
this.maxInputValidation(value);
|
|
84
|
+
this.maxthumb = 100 - (((this.maxPrice - this.min) / (this.max - this.min)) * 100);
|
|
85
|
+
}
|
|
86
|
+
this.isReady && this.changed.emit({
|
|
87
|
+
event: event,
|
|
88
|
+
option: this.option,
|
|
89
|
+
value: { max: this.maxPrice, min: this.minPrice }
|
|
90
|
+
});
|
|
38
91
|
}
|
|
39
|
-
|
|
40
|
-
if (value && (value > this.max || value > this.maxPrice))
|
|
92
|
+
minInputValidation(value) {
|
|
93
|
+
if (value && (value > this.max || value > this.maxPrice)) {
|
|
94
|
+
// this.minPrice = this.maxPrice;
|
|
41
95
|
return;
|
|
42
|
-
|
|
96
|
+
}
|
|
97
|
+
if (value < this.min) {
|
|
43
98
|
this.minPrice = this.min;
|
|
99
|
+
return;
|
|
44
100
|
}
|
|
45
|
-
|
|
46
|
-
|
|
101
|
+
if (value) {
|
|
102
|
+
this.minPrice = value;
|
|
47
103
|
}
|
|
48
104
|
}
|
|
49
|
-
|
|
50
|
-
if (value && (value < this.min || value < this.minPrice))
|
|
105
|
+
maxInputValidation(value) {
|
|
106
|
+
if (value && (value < this.min || value < this.minPrice)) {
|
|
107
|
+
// this.maxPrice = this.minPrice;
|
|
51
108
|
return;
|
|
52
|
-
|
|
109
|
+
}
|
|
110
|
+
if (value > this.max) {
|
|
53
111
|
this.maxPrice = this.max;
|
|
112
|
+
return;
|
|
54
113
|
}
|
|
55
|
-
|
|
56
|
-
|
|
114
|
+
if (value) {
|
|
115
|
+
this.maxPrice = value;
|
|
57
116
|
}
|
|
58
117
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
118
|
+
isChecked(option) {
|
|
119
|
+
if (option == Math.floor(this.max / 100)) {
|
|
120
|
+
return this.minPrice == 0 && this.maxPrice == option;
|
|
121
|
+
}
|
|
122
|
+
if (option == Math.floor(this.max / 2)) {
|
|
123
|
+
return this.minPrice == this.priceOptions[0] && this.maxPrice == this.priceOptions[2];
|
|
124
|
+
}
|
|
125
|
+
if (option == Math.floor((this.max / 3) * 2)) {
|
|
126
|
+
return this.minPrice == option && this.maxPrice == this.max;
|
|
127
|
+
}
|
|
66
128
|
}
|
|
67
129
|
render() {
|
|
68
|
-
return (h(Host, null,
|
|
130
|
+
return (h(Host, null, this.priceOptions && this.priceOptions.map((option, index) => {
|
|
131
|
+
return h("label", { class: "s-filters-label", htmlFor: `${option}-${index}` }, h("input", { id: `${option}-${index}`, name: "price", type: "radio", checked: this.isChecked(option), class: "s-filters-radio", onChange: e => this.handleMinMaxPrice(e, option) }), this.getPriceLabel(option));
|
|
132
|
+
}), h("div", { class: "flex justify-center items-center" }, h("div", { class: "relative max-w-xl w-full" }, h("div", { class: "s-price-range-inputs" }, h("div", { class: "s-price-range-relative" }, h("div", { class: "s-price-range-currency" }, " ", salla.config.currency().symbol), h("input", { type: "number", maxlength: "5", ref: el => this.minInput = el, onInput: (event) => this.changedEventHandler(event, true),
|
|
133
|
+
// value={this.minPrice}
|
|
134
|
+
placeholder: "\u0645\u0646", class: "s-price-range-number-input" })), h("div", { class: "s-price-range-gray-text" }, " -"), h("div", { class: "s-price-range-relative" }, h("div", { class: "s-price-range-currency" }, " ", salla.config.currency().symbol), h("input", { type: "number", maxlength: "5", placeholder: "\u0627\u0644\u0649", ref: el => this.maxInput = el, onInput: (event) => this.changedEventHandler(event),
|
|
135
|
+
// value={this.maxPrice}
|
|
136
|
+
class: "s-price-range-number-input", "aria-describedby": "price-currency" })))))));
|
|
69
137
|
}
|
|
70
138
|
componentDidLoad() {
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
|
|
139
|
+
var _a;
|
|
140
|
+
if (this.filtersData && ((_a = this.filtersData) === null || _a === void 0 ? void 0 : _a.price)) {
|
|
141
|
+
this.minPrice = this.filtersData.price.min;
|
|
142
|
+
this.maxPrice = this.filtersData.price.max;
|
|
143
|
+
this.maxInput.value = `${this.maxPrice}`;
|
|
144
|
+
this.minInput.value = `${this.minPrice}`;
|
|
145
|
+
}
|
|
74
146
|
this.isReady = true;
|
|
75
147
|
}
|
|
76
148
|
static get style() { return sallaPriceRangeCss; }
|
|
77
149
|
}, [0, "salla-price-range", {
|
|
78
150
|
"minPrice": [1026, "min-price"],
|
|
79
151
|
"maxPrice": [1026, "max-price"],
|
|
152
|
+
"option": [16],
|
|
153
|
+
"filtersData": [520, "filters-data"],
|
|
80
154
|
"min": [32],
|
|
81
155
|
"max": [32],
|
|
82
156
|
"minthumb": [32],
|
|
83
157
|
"maxthumb": [32],
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"minInputValidation": [64],
|
|
87
|
-
"maxInputValidation": [64],
|
|
88
|
-
"changeRightHandle": [64],
|
|
89
|
-
"changeLeftHandle": [64]
|
|
158
|
+
"priceOptions": [32],
|
|
159
|
+
"re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AAsB,IAC/B,WAAK,KAAK,EAAC,wBAAwB,IACjC,WAAK,KAAK,EAAC,wBAAwB,SAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAO,EAC3E,aACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,GAAG,EACb,OAAO,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAC1C,KAAK,EAAE,IAAI,CAAC,QAAQ,EACpB,KAAK,EAAC,4BAA4B,GAClC,CACE,EAEN,WAAK,KAAK,EAAC,yBAAyB,UAAU,EAC9C,WAAK,KAAK,EAAC,wBAAwB,IACjC,WAAK,KAAK,EAAC,wBAAwB,SAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAO,EAC3E,aAAO,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,GAAG,EAC3B,OAAO,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAC1C,KAAK,EAAE,IAAI,CAAC,QAAQ,EACpB,KAAK,EAAC,4BAA4B,EAAC,WAAW,EAAC,MAAM,sBAAkB,gBAAgB,GAAE,CAC5F,CAEF,CAEF,CACF,CACD,EACP;GACH;EAED,gBAAgB;;IAEd,IAAI,CAAC,gBAAgB,EAAE,CAAA;IACvB,IAAI,CAAC,iBAAiB,EAAE,CAAA;IACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;GACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["./src/components/salla-price-range/salla-price-range.scss?tag=salla-price-range","./src/components/salla-price-range/salla-price-range.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n\n.rtl, [dir=\"rtl\"] {\n .rtl-range-slider {\n transform: rotateY(180deg);\n }\n\n .rtl-range-numbers{\n flex-direction: row-reverse;\n }\n\n .form-select, select{\n background-position: left 0.5rem center;\n padding-right: 12px;\n } \n\n // divide\n.menu-divide {\n li {\n &:not(:last-child) {\n &:after {\n left: 0;\n right: auto;\n }\n }\n }\n}\n}\n\ninput[type=range]::-webkit-slider-thumb {\n pointer-events: all;\n width: 24px;\n height: 24px;\n -webkit-appearance: none;\n}\n\n[type='checkbox']:checked{\n background-size: 80%;\n}","import {Component, Host, h, Method, State, Prop, Event, EventEmitter} from '@stencil/core';\n\n@Component({\n tag: 'salla-price-range',\n styleUrl: 'salla-price-range.scss',\n})\nexport class SallaPriceRange {\n @Prop({mutable: true}) minPrice = 1000;\n @Prop({mutable: true}) maxPrice = 5000;\n @State() min = 0;\n @State() max = 10000;\n\n @State() minthumb = 0;\n @State() maxthumb = 0;\n\n @Event() minPriceSelected: EventEmitter<number>;\n @Event() maxPriceSelected: EventEmitter<number>;\n\n isReady: Boolean;\n rightHandle: HTMLDivElement;\n leftHandle: HTMLDivElement;\n activeBar: HTMLDivElement;\n\n componentWillLoad() {\n this.minTrigger();\n this.maxTrigger();\n }\n\n @Method()\n async minTrigger(event = null) {\n let value = event ? event.target.value * 1 : null\n this.minInputValidation(value);\n this.minthumb = ((this.minPrice - this.min) / (this.max - this.min)) * 100;\n this.changeLeftHandle()\n \n this.isReady && this.minPriceSelected.emit(value);\n }\n\n @Method()\n async maxTrigger(event = null) {\n let value = event ? event.target.value * 1 : null\n this.maxInputValidation(value)\n this.maxthumb = 100 - (((this.maxPrice - this.min) / (this.max - this.min)) * 100);\n this.changeRightHandle()\n \n this.isReady && this.maxPriceSelected.emit(value);\n }\n\n @Method()\n async minInputValidation(value) {\n if (value && (value > this.max || value > this.maxPrice)) return;\n else if (value < this.min) {\n this.minPrice = this.min;\n } else {\n value && (this.minPrice = value)\n }\n }\n\n @Method()\n async maxInputValidation(value) {\n if (value && (value < this.min || value < this.minPrice)) return;\n else if (value > this.max) {\n this.maxPrice = this.max;\n } else {\n value && (this.maxPrice = value)\n }\n }\n\n @Method()\n async changeRightHandle() {\n this.rightHandle && (this.rightHandle.style.right = `${this.maxthumb}%`);\n this.activeBar && (this.activeBar.style.right = `${this.maxthumb}%`);\n }\n\n @Method()\n async changeLeftHandle() {\n this.leftHandle && (this.leftHandle.style.left = `${this.minthumb}%`);\n this.activeBar && (this.activeBar.style.left = `${this.minthumb}%`);\n }\n\n\n render() {\n return (\n <Host>\n <div style={{direction: 'ltr'}} class=\"flex justify-center items-center\">\n <div class=\"relative max-w-xl w-full\">\n <div class=\"rtl-range-slider\">\n <input\n type=\"range\"\n step=\"100\"\n min={this.min} max={this.max}\n onInput={(event) => this.minTrigger(event)}\n value={this.minPrice}\n class=\"s-price-range-input\"\n />\n\n <input\n type=\"range\"\n step=\"100\"\n min={this.min}\n max={this.max}\n onInput={(event) => this.maxTrigger(event)}\n value={this.maxPrice}\n class=\"s-price-range-input\"\n />\n\n <div class=\"s-price-range-bar-container\">\n <div class=\"s-price-range-bar\"/>\n <div class=\"s-price-range-active-bar\" ref={(el) => this.activeBar = el}/>\n <div class=\"s-price-range-left-handle\" ref={(el) => this.leftHandle = el}/>\n <div class=\"s-price-range-right-handle\" ref={(el) => this.rightHandle = el}/>\n </div>\n\n </div>\n\n\n <div class=\"s-price-range-inputs\">\n <div class=\"s-price-range-relative\">\n <div class=\"s-price-range-currency\"> {salla.config.currency().symbol}</div>\n <input\n type=\"number\"\n maxlength=\"5\"\n onInput={(event) => this.minTrigger(event)}\n value={this.minPrice}\n class=\"s-price-range-number-input\"\n />\n </div>\n\n <div class=\"s-price-range-gray-text\"> - </div>\n <div class=\"s-price-range-relative\">\n <div class=\"s-price-range-currency\"> {salla.config.currency().symbol}</div>\n <input type=\"number\" maxlength=\"5\"\n onInput={(event) => this.maxTrigger(event)}\n value={this.maxPrice}\n class=\"s-price-range-number-input\" placeholder=\"0.00\" aria-describedby=\"price-currency\"/>\n </div>\n\n </div>\n\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n // this.max=this.maxPrice;\n this.changeLeftHandle()\n this.changeRightHandle()\n this.isReady = true;\n }\n}\n"],"version":3}
|
|
1
|
+
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ACP;GACH;EAED,gBAAgB;;IACd,IAAI,IAAI,CAAC,WAAW,KAAI,MAAA,IAAI,CAAC,WAAW,0CAAE,KAAK,CAAA,EAAE;MAC/C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC;MAC3C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC;MAC3C,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;MACzC,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;KAC1C;IACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;GACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["./src/components/salla-price-range/salla-price-range.scss?tag=salla-price-range","./src/components/salla-price-range/salla-price-range.tsx"],"sourcesContent":[":host {\n display: block;\n}\n\n\n.rtl, [dir=\"rtl\"] {\n .rtl-range-slider {\n transform: rotateY(180deg);\n }\n\n .rtl-range-numbers{\n flex-direction: row-reverse;\n }\n\n .form-select, select{\n background-position: left 0.5rem center;\n padding-right: 12px;\n } \n\n // divide\n.menu-divide {\n li {\n &:not(:last-child) {\n &:after {\n left: 0;\n right: auto;\n }\n }\n }\n}\n}\n\ninput[type=range]::-webkit-slider-thumb {\n pointer-events: all;\n width: 24px;\n height: 24px;\n -webkit-appearance: none;\n}\n\n[type='checkbox']:checked{\n background-size: 80%;\n}","import { Component, Host, h, State, Prop, Event, Method } from '@stencil/core';\nimport { Filter } from \"../salla-filters/interfaces\";\n\n@Component({\n tag: 'salla-price-range',\n styleUrl: 'salla-price-range.scss',\n})\nexport class SallaPriceRange {\n constructor() {\n this.generatePriceOptions();\n }\n @Prop({ mutable: true }) minPrice = 1000;\n @Prop({ mutable: true }) maxPrice = 5000;\n @Prop({ reflect: true }) option: Filter;\n @Prop({ reflect: true }) filtersData: any;\n @State() min = 0;\n @State() max = 10000;\n\n @State() minthumb = 0;\n @State() maxthumb = 0;\n @State() priceOptions: any;\n\n @Event() changed: any;\n\n isReady: Boolean;\n rightHandle: HTMLDivElement;\n leftHandle: HTMLDivElement;\n activeBar: HTMLDivElement;\n minInput: HTMLInputElement;\n maxInput: HTMLInputElement;\n\n @Method()\n async reset() {\n //@ts-ignore\n this.minInput.value = `${this.option?.values?.min || 0}`;\n this.maxInput.value = `${this.max}`;\n }\n\n private generatePriceOptions() {\n const MAX_PRICE = this.max;\n let option1 = Math.floor(MAX_PRICE / 100);\n if (option1 < 1) {\n option1 = Math.floor(MAX_PRICE / 10);\n }\n let option2 = Math.floor(MAX_PRICE / 2);\n let option3 = Math.floor((MAX_PRICE / 3) * 2);\n this.priceOptions = [option1, option2, option3];\n\n // to be removed\n console.log(`Price options for max price ${MAX_PRICE}: ${this.priceOptions.join(', ')}`);\n }\n private getPriceLabel(price) {\n if (price == Math.floor(this.max / 100)) {\n return `اقل من ${salla.money(price)}`;\n } else if (price == Math.floor(this.max / 2)) {\n return `${salla.money(this.priceOptions[0])} الى ${salla.money(this.priceOptions[2])}`;\n } else {\n return `أكثر من ${salla.money(price)}`;\n }\n }\n\n private handleMinMaxPrice(event: Event, option: string): void {\n const [firstOption, secondOption, thirdOption] = this.priceOptions;\n switch (option) {\n case firstOption:\n this.minPrice = 0;\n this.maxPrice = firstOption;\n break;\n case secondOption:\n this.minPrice = firstOption;\n this.maxPrice = thirdOption;\n break;\n case thirdOption:\n this.minPrice = thirdOption;\n this.maxPrice = this.max;\n break;\n default:\n throw new Error(`Invalid price option: ${option}`);\n }\n\n // Update the input values\n this.minInput.value = `${this.minPrice}`;\n this.maxInput.value = `${this.maxPrice}`;\n this.changedEventHandler(event);\n }\n\n private async changedEventHandler(event, isMin = false) {\n\n let value = event ? event.target.value * 1 : null\n if (isMin) {\n this.minInputValidation(value);\n this.minthumb = ((this.minPrice - this.min) / (this.max - this.min)) * 100;\n } else {\n this.maxInputValidation(value)\n this.maxthumb = 100 - (((this.maxPrice - this.min) / (this.max - this.min)) * 100);\n }\n\n\n this.isReady && this.changed.emit({\n event: event,\n option: this.option,\n value: { max: this.maxPrice, min: this.minPrice }\n })\n }\n\n\n minInputValidation(value) {\n if (value && (value > this.max || value > this.maxPrice)) {\n // this.minPrice = this.maxPrice;\n return;\n }\n\n if (value < this.min) {\n this.minPrice = this.min;\n return;\n }\n\n if (value) {\n this.minPrice = value;\n }\n }\n\n maxInputValidation(value) {\n if (value && (value < this.min || value < this.minPrice)) {\n // this.maxPrice = this.minPrice;\n return;\n }\n if (value > this.max) {\n this.maxPrice = this.max;\n return;\n }\n\n if (value) {\n this.maxPrice = value;\n }\n }\n private isChecked(option) {\n if (option == Math.floor(this.max / 100)) {\n return this.minPrice == 0 && this.maxPrice == option;\n }\n if (option == Math.floor(this.max / 2)) {\n return this.minPrice == this.priceOptions[0] && this.maxPrice == this.priceOptions[2];\n }\n if (option == Math.floor((this.max / 3) * 2)) {\n\n return this.minPrice == option && this.maxPrice == this.max;\n }\n }\n\n\n render() {\n return (\n <Host>\n {\n this.priceOptions && this.priceOptions.map((option, index) => {\n return <label class=\"s-filters-label\" htmlFor={`${option}-${index}`}>\n <input\n id={`${option}-${index}`}\n name=\"price\"\n type=\"radio\"\n checked={this.isChecked(option)}\n class=\"s-filters-radio\"\n onChange={e => this.handleMinMaxPrice(e, option)}\n />\n {this.getPriceLabel(option)}\n </label>\n })\n }\n\n\n <div class=\"flex justify-center items-center\">\n <div class=\"relative max-w-xl w-full\">\n <div class=\"s-price-range-inputs\">\n <div class=\"s-price-range-relative\">\n <div class=\"s-price-range-currency\"> {salla.config.currency().symbol}</div>\n <input\n type=\"number\"\n maxlength=\"5\"\n ref={el => this.minInput = el}\n onInput={(event) => this.changedEventHandler(event, true)}\n // value={this.minPrice}\n placeholder=\"من\"\n class=\"s-price-range-number-input\"\n />\n </div>\n\n <div class=\"s-price-range-gray-text\"> -</div>\n <div class=\"s-price-range-relative\">\n <div class=\"s-price-range-currency\"> {salla.config.currency().symbol}</div>\n <input type=\"number\" maxlength=\"5\"\n placeholder=\"الى\"\n ref={el => this.maxInput = el}\n onInput={(event) => this.changedEventHandler(event)}\n // value={this.maxPrice}\n class=\"s-price-range-number-input\" aria-describedby=\"price-currency\" />\n </div>\n </div>\n </div>\n </div>\n </Host>\n );\n }\n\n componentDidLoad() {\n if (this.filtersData && this.filtersData?.price) {\n this.minPrice = this.filtersData.price.min;\n this.maxPrice = this.filtersData.price.max;\n this.maxInput.value = `${this.maxPrice}`;\n this.minInput.value = `${this.minPrice}`;\n }\n this.isReady = true;\n }\n}\n"],"version":3}
|
|
@@ -32,10 +32,21 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
32
32
|
this.isReady = undefined;
|
|
33
33
|
this.showPlaceholder = undefined;
|
|
34
34
|
this.parsedFilters = undefined;
|
|
35
|
+
}
|
|
36
|
+
connectedCallback() {
|
|
35
37
|
salla.onReady(() => {
|
|
36
38
|
this.hasCustomComponent = !!customElements.get('custom-salla-product-card');
|
|
37
39
|
this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());
|
|
38
40
|
this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());
|
|
41
|
+
try {
|
|
42
|
+
let searchParams = new URLSearchParams(window.location.search);
|
|
43
|
+
this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');
|
|
44
|
+
let filters = searchParams.get('filters');
|
|
45
|
+
this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
salla.logger.warn('failed to get filters from url', e.message);
|
|
49
|
+
}
|
|
39
50
|
this.buildNextPageUrl();
|
|
40
51
|
this.createStatusDom();
|
|
41
52
|
this.isReady = true;
|
|
@@ -46,22 +57,12 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
46
57
|
}
|
|
47
58
|
salla.event.on('salla-filters::changed', filters => this.setFilters(filters));
|
|
48
59
|
}
|
|
49
|
-
connectedCallback() {
|
|
50
|
-
try {
|
|
51
|
-
let searchParams = new URLSearchParams(window.location.search);
|
|
52
|
-
this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');
|
|
53
|
-
let filters = searchParams.get('filters');
|
|
54
|
-
this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
salla.logger.warn('failed to get filters from url', e.message);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
60
|
async setFilters(filters) {
|
|
61
61
|
this.parsedFilters = filters;
|
|
62
62
|
return this.reload();
|
|
63
63
|
}
|
|
64
64
|
async reload() {
|
|
65
|
+
salla.infiniteScroll.destroy(this.infiniteScroll);
|
|
65
66
|
this.buildNextPageUrl();
|
|
66
67
|
this.wrapper.innerHTML = '';
|
|
67
68
|
this.init();
|
|
@@ -100,52 +101,53 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
100
101
|
this.placeholderText = salla.lang.get('pages.categories.no_products');
|
|
101
102
|
});
|
|
102
103
|
}
|
|
104
|
+
initBaseNextPageUrl(source) {
|
|
105
|
+
this.nextPage = salla.url.api(`products?source=${source}`);
|
|
106
|
+
if (this.limit) {
|
|
107
|
+
this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;
|
|
108
|
+
}
|
|
109
|
+
if (this.sortBy) {
|
|
110
|
+
this.nextPage += `&sort=${this.sortBy}`;
|
|
111
|
+
}
|
|
112
|
+
// if (!this.isFilterable()) {
|
|
113
|
+
// return this.nextPage;
|
|
114
|
+
// }
|
|
115
|
+
this.nextPage += '&filterable=1';
|
|
116
|
+
for (const [key, value] of Object.entries(this.parsedFilters || {})) {
|
|
117
|
+
if (["string", "number"].includes(typeof value)) {
|
|
118
|
+
this.nextPage += `&filters[${key}]=${value}`;
|
|
119
|
+
}
|
|
120
|
+
else if (Array.isArray(value)) {
|
|
121
|
+
value.forEach(item => this.nextPage += `&filters[${key}][]=${item}`);
|
|
122
|
+
}
|
|
123
|
+
else if (typeof value === 'object') {
|
|
124
|
+
for (const [k, v] of Object.entries(value)) {
|
|
125
|
+
this.nextPage += `&filters[${key}][${k}]=${v}`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
103
130
|
buildNextPageUrl() {
|
|
104
131
|
let source = this.getSource();
|
|
105
132
|
if (source === 'json') {
|
|
106
133
|
return;
|
|
107
134
|
}
|
|
108
|
-
|
|
135
|
+
this.initBaseNextPageUrl(source);
|
|
109
136
|
if (this.isSourceWithoutValue()) {
|
|
110
|
-
this.nextPage = salla.url.api(`products?source=${source}${urlPrefix}`);
|
|
111
137
|
return;
|
|
112
138
|
}
|
|
113
139
|
if (['search', 'related', 'landing-page'].includes(source)) {
|
|
114
|
-
this.nextPage
|
|
140
|
+
this.nextPage += `&source_value=${this.getSourceValue()}`;
|
|
115
141
|
return;
|
|
116
142
|
}
|
|
117
143
|
try {
|
|
118
|
-
this.nextPage
|
|
144
|
+
this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;
|
|
119
145
|
}
|
|
120
146
|
catch (e) {
|
|
121
147
|
salla.logger.warn(`source-value prop should be array of ids ex source-value="[1,2,3]" for the source [${source}]`);
|
|
122
148
|
this.sourceValueIsValid = false;
|
|
123
149
|
}
|
|
124
150
|
}
|
|
125
|
-
getUrlPrefix() {
|
|
126
|
-
let urlPrefix = '';
|
|
127
|
-
if (this.limit) {
|
|
128
|
-
urlPrefix = `&per_page=${this.limit > 32 ? 32 : this.limit}`;
|
|
129
|
-
}
|
|
130
|
-
if (this.sortBy) {
|
|
131
|
-
urlPrefix = `&sort=${this.sortBy}`;
|
|
132
|
-
}
|
|
133
|
-
if (!this.isFilterable()) {
|
|
134
|
-
return urlPrefix;
|
|
135
|
-
}
|
|
136
|
-
urlPrefix += '&filterable=1';
|
|
137
|
-
for (const [key, value] of Object.entries(this.parsedFilters || {})) {
|
|
138
|
-
if (typeof value == "string") {
|
|
139
|
-
urlPrefix += `&filters[${key}]=${value}`;
|
|
140
|
-
}
|
|
141
|
-
else if (Array.isArray(value)) {
|
|
142
|
-
value.forEach(item => {
|
|
143
|
-
urlPrefix += `&filters[${key}][]=${item}}`;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return urlPrefix;
|
|
148
|
-
}
|
|
149
151
|
getSource() {
|
|
150
152
|
return {
|
|
151
153
|
'brands.single': 'brands',
|
|
@@ -195,10 +197,25 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
195
197
|
}
|
|
196
198
|
if (this.horizontalCards && !this.hasCustomComponent) {
|
|
197
199
|
customComponent.toggleAttribute('horizontal', true);
|
|
200
|
+
customComponent.toggleAttribute('shadow-on-hover', true);
|
|
198
201
|
}
|
|
199
|
-
customComponent.toggleAttribute('shadow-on-hover', true);
|
|
200
202
|
return customComponent;
|
|
201
203
|
}
|
|
204
|
+
fetchProducts() {
|
|
205
|
+
salla.product.fetch({
|
|
206
|
+
source: this.getSource(),
|
|
207
|
+
source_value: this.getSourceValue(),
|
|
208
|
+
limit: this.limit
|
|
209
|
+
})
|
|
210
|
+
.then(res => {
|
|
211
|
+
if (!res.data.length) {
|
|
212
|
+
this.showPlaceholder = true;
|
|
213
|
+
this.loading(false);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
this.handleResponse(res).forEach(card => this.wrapper.append(card));
|
|
217
|
+
});
|
|
218
|
+
}
|
|
202
219
|
initiateInfiniteScroll() {
|
|
203
220
|
if (!this.hasInfiniteScroll) {
|
|
204
221
|
return;
|
|
@@ -211,11 +228,27 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
211
228
|
scrollThreshold: 100,
|
|
212
229
|
}, /* infinite via api*/ true);
|
|
213
230
|
this.infiniteScroll.on('request', () => this.loading());
|
|
214
|
-
this.infiniteScroll.on('load', response =>
|
|
231
|
+
this.infiniteScroll.on('load', response => {
|
|
232
|
+
var _a;
|
|
233
|
+
if (!((_a = response.data) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
234
|
+
this.showPlaceholder = true;
|
|
235
|
+
salla.infiniteScroll.destroy(this.infiniteScroll);
|
|
236
|
+
this.loading(false);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
this.showPlaceholder = false;
|
|
241
|
+
}
|
|
242
|
+
this.infiniteScroll.appendItems(this.handleResponse(response));
|
|
243
|
+
if (this.infiniteScroll.pageIndex == 2) {
|
|
244
|
+
this.animateItems();
|
|
245
|
+
}
|
|
246
|
+
});
|
|
215
247
|
this.infiniteScroll.on('error', () => {
|
|
216
248
|
this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden');
|
|
217
249
|
this.loading(false);
|
|
218
250
|
});
|
|
251
|
+
salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll));
|
|
219
252
|
}
|
|
220
253
|
canRender() {
|
|
221
254
|
return this.sourceValueIsValid && this.isReady;
|
|
@@ -238,6 +271,7 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
238
271
|
if (!this.canRender()) {
|
|
239
272
|
return;
|
|
240
273
|
}
|
|
274
|
+
// Handle json source
|
|
241
275
|
if (this.getSource() === 'json') {
|
|
242
276
|
if (!this.getSourceValue().length) {
|
|
243
277
|
this.showPlaceholder = true;
|
|
@@ -246,34 +280,26 @@ const SallaProductsList$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLE
|
|
|
246
280
|
this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));
|
|
247
281
|
return;
|
|
248
282
|
}
|
|
283
|
+
// Handle selected source
|
|
284
|
+
if (this.getSource() === 'selected') {
|
|
285
|
+
if (!this.getSourceValue().length) {
|
|
286
|
+
this.showPlaceholder = true;
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
this.fetchProducts();
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
249
292
|
this.init();
|
|
250
293
|
}
|
|
251
294
|
init() {
|
|
252
295
|
this.initiateInfiniteScroll();
|
|
253
296
|
this.loading();
|
|
254
|
-
salla.product.fetch({
|
|
255
|
-
source: this.getSource(),
|
|
256
|
-
source_value: this.getSourceValue(),
|
|
257
|
-
filters: this.parsedFilters,
|
|
258
|
-
limit: this.limit,
|
|
259
|
-
filterable: this.isFilterable() ? 1 : 0,
|
|
260
|
-
sort: this.sortBy,
|
|
261
|
-
})
|
|
262
|
-
.then(res => {
|
|
263
|
-
var _a;
|
|
264
|
-
if (!((_a = res.data) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
265
|
-
this.showPlaceholder = true;
|
|
266
|
-
this.loading(false);
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
this.handleResponse(res).forEach(card => this.wrapper.append(card));
|
|
270
|
-
this.animateItems();
|
|
271
|
-
});
|
|
272
297
|
}
|
|
273
298
|
handleResponse(response) {
|
|
274
299
|
var _a;
|
|
275
300
|
//💡 when source is related, cursor will not be existed
|
|
276
301
|
if (response.filters && this.isFilterable()) {
|
|
302
|
+
this.filtersResults = true;
|
|
277
303
|
salla.event.emit('filters::fetched', { filters: response.filters });
|
|
278
304
|
}
|
|
279
305
|
else if (this.isFilterable()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"salla-products-list.js","mappings":";;;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,EAAE;;MCQlBA,mBAAiB;EAC5B;;;;;;;;;gBA0FwB,CAAC;;;;;;;;;IAzFvB,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;MAC5E,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,EAAE,CAAC;KACrB,CAAC,CAAA;GACL;EAEO,cAAc,CAAC,QAAQ;;;IAE7B,IAAI,QAAQ,CAAC,OAAO,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE;MAC3C,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAC,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAC,CAAC,CAAC;KACnE;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,EAAC,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAC,CAAC,CAAC;MAC1E,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":["SallaProductsList"],"sources":["./src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","./src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import {Component, Host, h, Prop, State, Element, Method} from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\n\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n constructor() {\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\n this.buildNextPageUrl();\n this.createStatusDom();\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 connectedCallback() {\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 }\n\n @Method()\n async setFilters(filters) {\n this.parsedFilters = filters;\n return this.reload();\n }\n\n\n @Method()\n async reload() {\n this.buildNextPageUrl();\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({mutable: true}) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({mutable: true}) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({mutable: true}) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({reflect: true, mutable: true}) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({reflect: true}) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n let urlPrefix = this.getUrlPrefix();\n if (this.isSourceWithoutValue()) {\n this.nextPage = salla.url.api(`products?source=${source}${urlPrefix}`);\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage = salla.url.api(`products?source=${source}&source_value=${this.getSourceValue()}${urlPrefix}`);\n return;\n }\n\n try {\n this.nextPage = salla.url.api(`products?source=${source}&source_value[]=${this.getSourceValue().join('&source_value[]=')}${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 [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n private getUrlPrefix() {\n let urlPrefix = '';\n if (this.limit) {\n urlPrefix = `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n urlPrefix = `&sort=${this.sortBy}`;\n }\n if (!this.isFilterable()) {\n return urlPrefix;\n }\n urlPrefix += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if (typeof value == \"string\") {\n urlPrefix += `&filters[${key}]=${value}`;\n } else if (Array.isArray(value)) {\n (value as any).forEach(item => {\n urlPrefix += `&filters[${key}][]=${item}}`\n })\n }\n }\n return urlPrefix;\n }\n\n private getSource() {\n return {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'product.index.search': 'search',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n 'product.index.sales': 'sales',\n 'components.most_sales_products': 'sales',//temporary, delete it after two days from now\n }[this.source || salla.config.get('page.slug')] || this.source || 'latest';\n }\n\n private getSourceValue() {\n let source = this.getSource();\n\n //todo:: enhance this code, it call JSON.parse too many times.\n if (!['search', 'json', 'offers', 'latest', 'sales'].includes(source)) {\n if (this.sourceValue && Array.isArray(JSON.parse(this.sourceValue)) && JSON.parse(this.sourceValue).length) {\n return JSON.parse(this.sourceValue);\n }\n\n if (this.sourceValue && typeof JSON.parse(this.sourceValue) == 'number') {\n return [JSON.parse(this.sourceValue)];\n }\n if (!this.sourceValue && ['categories', 'tags', 'brands', 'landing-page'].includes(this.getSource())) {\n return [salla.config.get('page.id')];\n }\n }\n\n if (this.sourceValue) {\n return this.sourceValue;\n }\n\n\n if (source === 'search') {\n return (new URLSearchParams(window.location.search)).get('q');\n }\n\n return salla.config.get('page.id');\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n let customComponentTag: string = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n let customComponent: HTMLSallaProductCardElement = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n customComponent.product = product;\n // customComponent.setAttribute('product', JSON.stringify(product));\n if (this.getSource() == 'landing-page' && !this.hasCustomComponent) {\n customComponent.toggleAttribute('hide-add-btn', true);\n customComponent.classList.add('s-product-card-fit-height');\n }\n if (this.horizontalCards && !this.hasCustomComponent) {\n customComponent.toggleAttribute('horizontal', true);\n }\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('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 => 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}/>\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 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 this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n salla.product.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n filters: this.parsedFilters,\n limit: this.limit,\n filterable: this.isFilterable() ? 1 : 0,\n sort: this.sortBy,\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 this.animateItems();\n })\n }\n\n private handleResponse(response): Array<HTMLElement> {\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n salla.event.emit('filters::fetched', {filters: response.filters});\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({scrollThreshold: false, loadOnScroll: false});\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"salla-products-list.js","mappings":";;;;;;;;;;;;;AAAA,MAAM,oBAAoB,GAAG,EAAE;;MCQlBA,mBAAiB;;;;;;;;;;gBA2FJ,CAAC;;;;;;;;;;EA1FzB,iBAAiB;IACf,KAAK,CAAC,OAAO,CAAC;MACZ,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;MAC5E,IAA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AC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,IAAI,IAAI,CAAC,iBAAiB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;MAC5C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAC,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAC,CAAC,CAAC;MAC1E,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":["SallaProductsList"],"sources":["./src/components/salla-products-list/salla-products-list.scss?tag=salla-products-list","./src/components/salla-products-list/salla-products-list.tsx"],"sourcesContent":["\n","import {Component, Host, h, Prop, State, Element, Method} from '@stencil/core';\nimport anime from 'animejs';\nimport ShoppingBag from '../../assets/svg/shopping-bag.svg';\n\n@Component({\n tag: 'salla-products-list',\n styleUrl: 'salla-products-list.scss'\n})\nexport class SallaProductsList {\n connectedCallback() {\n salla.onReady(() => {\n this.hasCustomComponent = !!customElements.get('custom-salla-product-card');\n this.sourceValueIsValid = !!(this.getSourceValue() || this.isSourceWithoutValue());\n this.hasInfiniteScroll = !['json', 'selected', 'related', 'landing-page'].includes(this.getSource());\n try {\n let searchParams = new URLSearchParams(window.location.search);\n this.sortBy = this.sortBy || searchParams.get('sort') || searchParams.get('by');\n let filters = searchParams.get('filters')\n this.parsedFilters = filters ? JSON.parse(decodeURIComponent(filters)) : {};\n } catch (e) {\n salla.logger.warn('failed to get filters from url', e.message);\n }\n this.buildNextPageUrl();\n this.createStatusDom();\n\n this.isReady = true;\n });\n\n if (!this.sourceValueIsValid) {\n salla.logger.warn(`source-value prop is required for source [${this.getSource()}]`);\n return;\n }\n salla.event.on('salla-filters::changed', filters => this.setFilters(filters))\n\n\n }\n\n @Method()\n async setFilters(filters) {\n this.parsedFilters = filters;\n return this.reload();\n }\n\n\n @Method()\n async reload() {\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.buildNextPageUrl();\n this.wrapper.innerHTML = '';\n this.init();\n }\n\n\n private status: HTMLDivElement;\n private btnLoader: HTMLAnchorElement;\n @Element() host: HTMLElement;\n private wrapper: any;\n private infiniteScroll: any;\n /**\n * The source of the products list\n * @type {string}\n * */\n @Prop({\n reflect: true,\n mutable: true\n }) source: 'categories' | 'latest' | 'related' | 'brands' | 'json' | 'search' | 'tags' | 'selected' | 'offers' | 'landing-page' | 'sales';\n\n /**\n * The source value, cloud be different values as following:\n * - array of ids when `source` in ['categories', 'brands', 'tags', 'selected']\n * - keyword when `source` = 'search'\n * - products payload when `source` = 'json'\n * - product_id when `source` = 'related'\n *\n * @type {string}\n * */\n @Prop({mutable: true}) sourceValue: any;\n\n /**\n * Limit for number of products in the list.\n */\n @Prop({mutable: true}) limit: number;\n\n /**\n * Sorting the list of products\n */\n @Prop({mutable: true}) sortBy?: string | 'ourSuggest' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop';\n\n /**\n * should listen to filters events `salla-filters::changed` and re-render\n */\n @Prop({reflect: true, mutable: true}) filtersResults: boolean;\n\n /**\n * Horizontal cards\n */\n @Prop({reflect: true}) horizontalCards: boolean\n\n // State\n @State() page: number = 1;\n @State() nextPage: string;\n @State() hasInfiniteScroll: boolean;\n @State() hasCustomComponent: boolean;\n @State() sourceValueIsValid: boolean;\n @State() placeholderText: string;\n @State() isReady: boolean;\n @State() showPlaceholder: boolean;\n @State() parsedFilters: any;\n\n private isFilterable() {\n return salla.config.get('store.settings.product.filters') && this.filtersResults;\n }\n\n private isSourceWithoutValue() {\n return ['offers', 'latest', 'sales'].includes(this.getSource());\n }\n\n private animateItems() {\n anime({\n targets: 'salla-products-list salla-product-card',\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n })\n }\n\n private createStatusDom() {\n this.status = document.createElement('div');\n this.status.className = 's-infinite-scroll-wrapper';\n this.status.innerHTML = `<div class=\"s-infinite-scroll-status\">\n <p class=\"s-infinite-scroll-last infinite-scroll-last s-hidden\" >${salla.lang.get('common.elements.end_of_content')}</p>\n <p class=\"s-infinite-scroll-error infinite-scroll-error s-hidden\">${salla.lang.get('common.elements.failed_to_load_more')}</p>\n </div>\n <a href=\"#\" class=\"s-infinite-scroll-btn s-button-btn\">\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" style=\"display: none\"></span>\n </a>`;\n this.btnLoader = this.status.querySelector('.s-button-loader');\n salla.lang.onLoaded(() => {\n this.status.querySelector('.s-infinite-scroll-last').innerHTML = salla.lang.get('common.elements.end_of_content');\n this.status.querySelector('.s-infinite-scroll-error').innerHTML = salla.lang.get('common.elements.failed_to_load_more');\n this.placeholderText = salla.lang.get('pages.categories.no_products');\n });\n }\n\n private initBaseNextPageUrl(source: string) {\n\n this.nextPage = salla.url.api(`products?source=${source}`);\n\n if (this.limit) {\n this.nextPage += `&per_page=${this.limit > 32 ? 32 : this.limit}`;\n }\n if (this.sortBy) {\n this.nextPage += `&sort=${this.sortBy}`;\n }\n // if (!this.isFilterable()) {\n // return this.nextPage;\n // }\n this.nextPage += '&filterable=1';\n for (const [key, value] of Object.entries(this.parsedFilters || {})) {\n if ([\"string\", \"number\"].includes(typeof value)) {\n this.nextPage += `&filters[${key}]=${value}`;\n } else if (Array.isArray(value)) {\n (value as any).forEach(item => this.nextPage += `&filters[${key}][]=${item}`)\n } else if (typeof value === 'object') {\n for (const [k, v] of Object.entries(value)) {\n this.nextPage += `&filters[${key}][${k}]=${v}`;\n }\n }\n }\n }\n\n private buildNextPageUrl() {\n let source = this.getSource();\n if (source === 'json') {\n return;\n }\n this.initBaseNextPageUrl(source);\n if (this.isSourceWithoutValue()) {\n return;\n }\n\n if (['search', 'related', 'landing-page'].includes(source)) {\n this.nextPage += `&source_value=${this.getSourceValue()}`;\n return;\n }\n\n try {\n this.nextPage += `&source_value[]=${this.getSourceValue().join('&source_value[]=')}`;\n } catch (e) {\n salla.logger.warn(`source-value prop should be array of ids ex source-value=\"[1,2,3]\" for the source [${source}]`);\n this.sourceValueIsValid = false;\n }\n }\n\n private getSource() {\n return {\n 'brands.single': 'brands',\n 'product.index': 'categories',\n 'product.index.latest': 'latest',\n 'product.index.offers': 'offers',\n 'product.index.search': 'search',\n 'landing-page': 'landing-page',\n 'product.index.tag': 'tags',\n 'product.index.sales': 'sales',\n 'components.most_sales_products': 'sales',//temporary, delete it after two days from now\n }[this.source || salla.config.get('page.slug')] || this.source || 'latest';\n }\n\n private getSourceValue() {\n let source = this.getSource();\n\n //todo:: enhance this code, it call JSON.parse too many times.\n if (!['search', 'json', 'offers', 'latest', 'sales'].includes(source)) {\n if (this.sourceValue && Array.isArray(JSON.parse(this.sourceValue)) && JSON.parse(this.sourceValue).length) {\n return JSON.parse(this.sourceValue);\n }\n\n if (this.sourceValue && typeof JSON.parse(this.sourceValue) == 'number') {\n return [JSON.parse(this.sourceValue)];\n }\n if (!this.sourceValue && ['categories', 'tags', 'brands', 'landing-page'].includes(this.getSource())) {\n return [salla.config.get('page.id')];\n }\n }\n\n if (this.sourceValue) {\n return this.sourceValue;\n }\n\n\n if (source === 'search') {\n return (new URLSearchParams(window.location.search)).get('q');\n }\n\n return salla.config.get('page.id');\n }\n\n\n private loading(isLoading = true) {\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n\n private getItemHTML(product) {\n let customComponentTag: string = this.hasCustomComponent ? 'custom-salla-product-card' : 'salla-product-card';\n let customComponent: HTMLSallaProductCardElement = document.createElement(customComponentTag) as HTMLSallaProductCardElement;\n customComponent.product = product;\n // customComponent.setAttribute('product', JSON.stringify(product));\n if (this.getSource() == 'landing-page' && !this.hasCustomComponent) {\n customComponent.toggleAttribute('hide-add-btn', true);\n customComponent.classList.add('s-product-card-fit-height');\n }\n if (this.horizontalCards && !this.hasCustomComponent) {\n customComponent.toggleAttribute('horizontal', true);\n customComponent.toggleAttribute('shadow-on-hover', true);\n }\n return customComponent;\n }\n\n private fetchProducts() {\n salla.product.fetch({\n source: this.getSource(),\n source_value: this.getSourceValue(),\n limit: this.limit\n })\n .then(res => {\n if (!res.data.length) {\n this.showPlaceholder = true;\n this.loading(false);\n return;\n }\n this.handleResponse(res).forEach(card => this.wrapper.append(card));\n })\n }\n \n private initiateInfiniteScroll() {\n if (!this.hasInfiniteScroll) {\n return;\n }\n\n this.host.insertAdjacentElement('beforeend', this.status);\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: false,\n nextPage: this.nextPage,\n scrollThreshold: 100,\n }, /* infinite via api*/true);\n this.infiniteScroll.on('request', () => this.loading())\n this.infiniteScroll.on('load', response => {\n if (!response.data?.length) {\n this.showPlaceholder = true;\n salla.infiniteScroll.destroy(this.infiniteScroll);\n this.loading(false);\n return;\n }else{\n this.showPlaceholder = false;\n\n }\n this.infiniteScroll.appendItems(this.handleResponse(response))\n if (this.infiniteScroll.pageIndex == 2) {\n this.animateItems();\n }\n })\n this.infiniteScroll.on('error', () => {\n this.status.querySelector('.s-infinite-scroll-error').classList.remove('s-hidden')\n this.loading(false);\n });\n salla.onReady(() => salla.infiniteScroll.loadNextPage(this.infiniteScroll))\n }\n\n private canRender() {\n return this.sourceValueIsValid && this.isReady;\n }\n\n render() {\n if (!this.canRender()) {\n return '';\n }\n if (this.showPlaceholder) {\n return <div class=\"s-products-list-placeholder\">\n <span innerHTML={ShoppingBag}/>\n <p>{this.placeholderText}</p>\n </div>;\n }\n return (\n <Host class=\"s-products-list\">\n <div class={{\n \"s-products-list-wrapper\": true,\n 's-products-list-horizontal-cards': this.horizontalCards && !this.filtersResults,\n 's-products-list-vertical-cards': !this.horizontalCards && !this.filtersResults,\n 's-products-list-filters-results': this.filtersResults,\n }}\n ref={wrapper => this.wrapper = wrapper}/>\n </Host>\n );\n }\n\n componentDidLoad() {\n if (!this.canRender()) {\n return;\n }\n\n // Handle json source\n if (this.getSource() === 'json') {\n if (!this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.getSourceValue().map(product => this.wrapper.append(this.getItemHTML(product)));\n return;\n }\n // Handle selected source\n if (this.getSource() === 'selected') {\n if (!this.getSourceValue().length) {\n this.showPlaceholder = true;\n return;\n }\n this.fetchProducts()\n return;\n }\n this.init();\n }\n\n private init() {\n this.initiateInfiniteScroll();\n this.loading();\n }\n\n private handleResponse(response): Array<HTMLElement> {\n //💡 when source is related, cursor will not be existed\n if (response.filters && this.isFilterable()) {\n this.filtersResults = true;\n salla.event.emit('filters::fetched', {filters: response.filters});\n } else if (this.isFilterable()) {\n salla.event.emit('filters::hidden');\n }\n this.nextPage = response.cursor ? response.cursor.next : this.nextPage;\n this.loading(false);\n if (this.hasInfiniteScroll && !this.nextPage) {\n this.infiniteScroll.option({scrollThreshold: false, loadOnScroll: false});\n this.status.querySelector('.s-infinite-scroll-last').classList.remove('s-hidden');\n }\n return response.data?.map(product => this.getItemHTML(product)) || [];\n }\n}\n"],"version":3}
|