@ppg_pl/tinting 0.0.0
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/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/cjs/index-0a139db0.js +1667 -0
- package/dist/cjs/index-0a139db0.js.map +1 -0
- package/dist/cjs/index.cjs.js +4 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/loader.cjs.js +24 -0
- package/dist/cjs/loader.cjs.js.map +1 -0
- package/dist/cjs/modal-header_10.cjs.entry.js +12313 -0
- package/dist/cjs/modal-header_10.cjs.entry.js.map +1 -0
- package/dist/cjs/tinting.cjs.js +28 -0
- package/dist/cjs/tinting.cjs.js.map +1 -0
- package/dist/collection/collection-manifest.json +21 -0
- package/dist/collection/components/api/index.js +23 -0
- package/dist/collection/components/api/index.js.map +1 -0
- package/dist/collection/components/api/services.js +96 -0
- package/dist/collection/components/api/services.js.map +1 -0
- package/dist/collection/components/backdrop/index.css +14 -0
- package/dist/collection/components/backdrop/index.js +17 -0
- package/dist/collection/components/backdrop/index.js.map +1 -0
- package/dist/collection/components/colorbox/index.css +53 -0
- package/dist/collection/components/colorbox/index.js +182 -0
- package/dist/collection/components/colorbox/index.js.map +1 -0
- package/dist/collection/components/colorinfo/index.js +239 -0
- package/dist/collection/components/colorinfo/index.js.map +1 -0
- package/dist/collection/components/component/index.css +6 -0
- package/dist/collection/components/component/index.js +220 -0
- package/dist/collection/components/component/index.js.map +1 -0
- package/dist/collection/components/header/assets/close.png +0 -0
- package/dist/collection/components/header/index.css +180 -0
- package/dist/collection/components/header/index.js +334 -0
- package/dist/collection/components/header/index.js.map +1 -0
- package/dist/collection/components/loader/index.css +85 -0
- package/dist/collection/components/loader/index.js +19 -0
- package/dist/collection/components/loader/index.js.map +1 -0
- package/dist/collection/components/modal/__mocks__/index.js +759 -0
- package/dist/collection/components/modal/__mocks__/index.js.map +1 -0
- package/dist/collection/components/modal/assets/arrow_down.png +0 -0
- package/dist/collection/components/modal/index.css +386 -0
- package/dist/collection/components/modal/index.js +646 -0
- package/dist/collection/components/modal/index.js.map +1 -0
- package/dist/collection/components/search/assets/search.svg +15 -0
- package/dist/collection/components/search/index.css +38 -0
- package/dist/collection/components/search/index.js +178 -0
- package/dist/collection/components/search/index.js.map +1 -0
- package/dist/collection/components/select/assets/chevron-down.webp +0 -0
- package/dist/collection/components/select/assets/chevron.png +0 -0
- package/dist/collection/components/select/index.css +77 -0
- package/dist/collection/components/select/index.js +231 -0
- package/dist/collection/components/select/index.js.map +1 -0
- package/dist/collection/components/slider/index.css +89 -0
- package/dist/collection/components/slider/index.js +145 -0
- package/dist/collection/components/slider/index.js.map +1 -0
- package/dist/collection/gtmUtils.js +4 -0
- package/dist/collection/gtmUtils.js.map +1 -0
- package/dist/collection/index.js +2 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/types.js +2 -0
- package/dist/collection/types.js.map +1 -0
- package/dist/collection/utils/index.js +12 -0
- package/dist/collection/utils/index.js.map +1 -0
- package/dist/components/gtmUtils.js +7 -0
- package/dist/components/gtmUtils.js.map +1 -0
- package/dist/components/index.d.ts +27 -0
- package/dist/components/index.js +3 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index10.js +31 -0
- package/dist/components/index10.js.map +1 -0
- package/dist/components/index11.js +3949 -0
- package/dist/components/index11.js.map +1 -0
- package/dist/components/index2.js +2726 -0
- package/dist/components/index2.js.map +1 -0
- package/dist/components/index3.js +87 -0
- package/dist/components/index3.js.map +1 -0
- package/dist/components/index4.js +121 -0
- package/dist/components/index4.js.map +1 -0
- package/dist/components/index5.js +26 -0
- package/dist/components/index5.js.map +1 -0
- package/dist/components/index6.js +31 -0
- package/dist/components/index6.js.map +1 -0
- package/dist/components/index7.js +75 -0
- package/dist/components/index7.js.map +1 -0
- package/dist/components/index8.js +87 -0
- package/dist/components/index8.js.map +1 -0
- package/dist/components/index9.js +5306 -0
- package/dist/components/index9.js.map +1 -0
- package/dist/components/modal-header.d.ts +11 -0
- package/dist/components/modal-header.js +8 -0
- package/dist/components/modal-header.js.map +1 -0
- package/dist/components/my-backdrop.d.ts +11 -0
- package/dist/components/my-backdrop.js +8 -0
- package/dist/components/my-backdrop.js.map +1 -0
- package/dist/components/my-colorbox.d.ts +11 -0
- package/dist/components/my-colorbox.js +8 -0
- package/dist/components/my-colorbox.js.map +1 -0
- package/dist/components/my-colorinfo.d.ts +11 -0
- package/dist/components/my-colorinfo.js +8 -0
- package/dist/components/my-colorinfo.js.map +1 -0
- package/dist/components/my-component.d.ts +11 -0
- package/dist/components/my-component.js +254 -0
- package/dist/components/my-component.js.map +1 -0
- package/dist/components/my-loader.d.ts +11 -0
- package/dist/components/my-loader.js +8 -0
- package/dist/components/my-loader.js.map +1 -0
- package/dist/components/my-modal.d.ts +11 -0
- package/dist/components/my-modal.js +8 -0
- package/dist/components/my-modal.js.map +1 -0
- package/dist/components/my-search.d.ts +11 -0
- package/dist/components/my-search.js +8 -0
- package/dist/components/my-search.js.map +1 -0
- package/dist/components/my-select.d.ts +11 -0
- package/dist/components/my-select.js +8 -0
- package/dist/components/my-select.js.map +1 -0
- package/dist/components/my-slider.d.ts +11 -0
- package/dist/components/my-slider.js +8 -0
- package/dist/components/my-slider.js.map +1 -0
- package/dist/esm/index-f3be6531.js +1638 -0
- package/dist/esm/index-f3be6531.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loader.js +20 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/modal-header_10.entry.js +12300 -0
- package/dist/esm/modal-header_10.entry.js.map +1 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/esm/tinting.js +23 -0
- package/dist/esm/tinting.js.map +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/tinting/assets/arrow_down.png +0 -0
- package/dist/tinting/assets/chevron-down.webp +0 -0
- package/dist/tinting/assets/chevron.png +0 -0
- package/dist/tinting/assets/close.png +0 -0
- package/dist/tinting/assets/search.svg +15 -0
- package/dist/tinting/index.esm.js +2 -0
- package/dist/tinting/index.esm.js.map +1 -0
- package/dist/tinting/p-06cd865b.entry.js +15 -0
- package/dist/tinting/p-06cd865b.entry.js.map +1 -0
- package/dist/tinting/p-b135c76f.js +3 -0
- package/dist/tinting/p-b135c76f.js.map +1 -0
- package/dist/tinting/tinting.css +1 -0
- package/dist/tinting/tinting.esm.js +2 -0
- package/dist/tinting/tinting.esm.js.map +1 -0
- package/dist/types/components/api/index.d.ts +7 -0
- package/dist/types/components/api/services.d.ts +9 -0
- package/dist/types/components/backdrop/index.d.ts +3 -0
- package/dist/types/components/colorbox/index.d.ts +15 -0
- package/dist/types/components/colorinfo/index.d.ts +19 -0
- package/dist/types/components/component/index.d.ts +18 -0
- package/dist/types/components/header/index.d.ts +35 -0
- package/dist/types/components/loader/index.d.ts +3 -0
- package/dist/types/components/modal/__mocks__/index.d.ts +415 -0
- package/dist/types/components/modal/index.d.ts +77 -0
- package/dist/types/components/search/index.d.ts +15 -0
- package/dist/types/components/select/index.d.ts +31 -0
- package/dist/types/components/slider/index.d.ts +15 -0
- package/dist/types/components.d.ts +289 -0
- package/dist/types/gtmUtils.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1637 -0
- package/dist/types/types.d.ts +68 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +21 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +11 -0
- package/package.json +69 -0
- package/www/build/assets/arrow_down.png +0 -0
- package/www/build/assets/chevron-down.webp +0 -0
- package/www/build/assets/chevron.png +0 -0
- package/www/build/assets/close.png +0 -0
- package/www/build/assets/fonts/Galatea-Regular.eot +0 -0
- package/www/build/assets/fonts/Galatea-Regular.ttf +0 -0
- package/www/build/assets/fonts/Galatea-Regular.woff +0 -0
- package/www/build/assets/fonts/Galatea-Regular.woff2 +0 -0
- package/www/build/assets/search.svg +15 -0
- package/www/build/index.esm.js +2 -0
- package/www/build/index.esm.js.map +1 -0
- package/www/build/p-06cd865b.entry.js +15 -0
- package/www/build/p-06cd865b.entry.js.map +1 -0
- package/www/build/p-a4907f5e.css +4 -0
- package/www/build/p-b135c76f.js +3 -0
- package/www/build/p-b135c76f.js.map +1 -0
- package/www/build/p-e2322b6c.js +163 -0
- package/www/build/tinting.css +1 -0
- package/www/build/tinting.esm.js +2 -0
- package/www/build/tinting.esm.js.map +1 -0
- package/www/build/tinting.js +33 -0
- package/www/host.config.json +15 -0
- package/www/index.html +31 -0
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
import { h } from '@stencil/core';
|
|
2
|
+
import { APIURL, accessToken } from '../api';
|
|
3
|
+
import { setDataLayer } from '../../gtmUtils';
|
|
4
|
+
import { fetchColors, fetchProductData, limit, updateFilters } from '../api/services';
|
|
5
|
+
import { debounce } from '../../utils';
|
|
6
|
+
import chroma from 'chroma-js';
|
|
7
|
+
export class Modal {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.boxDesktopWidth = 130;
|
|
10
|
+
this.boxMobileWidth = 70;
|
|
11
|
+
this.desktopPadding = 75;
|
|
12
|
+
this.mobilePadding = 35;
|
|
13
|
+
this.mediumBreakpoint = 1024;
|
|
14
|
+
this.clearInterval = () => {
|
|
15
|
+
this.colorTimerInterval && clearInterval(this.colorTimerInterval);
|
|
16
|
+
this.colorTimerInterval = undefined;
|
|
17
|
+
};
|
|
18
|
+
this.colorTimer = () => {
|
|
19
|
+
if (this.currentColor && this.currentColor.id) {
|
|
20
|
+
this.colorTimerInterval = setInterval(() => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.name) &&
|
|
23
|
+
setDataLayer({
|
|
24
|
+
event: 'ColorTimer',
|
|
25
|
+
shop: this.shop,
|
|
26
|
+
product: this.product,
|
|
27
|
+
color: (_b = this.currentColor) === null || _b === void 0 ? void 0 : _b.name,
|
|
28
|
+
timer: '10',
|
|
29
|
+
});
|
|
30
|
+
}, 10000);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.clearInterval();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
this.chunks = (xs, y = []) => {
|
|
37
|
+
return xs.length === 0 ? y : this.chunks(xs.slice(this.chunksNum), y.concat([xs.slice(0, this.chunksNum)]));
|
|
38
|
+
};
|
|
39
|
+
this.calculateBoxCount = () => {
|
|
40
|
+
var _a;
|
|
41
|
+
const modalWidth = this.modalEl.children && this.modalEl.children[0] && ((_a = this.modalEl.children[0]) === null || _a === void 0 ? void 0 : _a.clientWidth) - this.padding;
|
|
42
|
+
const boxWidth = this.boxWidth;
|
|
43
|
+
const calc = Math.floor(modalWidth / boxWidth);
|
|
44
|
+
const boxesCount = calc;
|
|
45
|
+
if (!this.preloader)
|
|
46
|
+
this.chunksNum = boxesCount;
|
|
47
|
+
};
|
|
48
|
+
this.displayForMobile = () => {
|
|
49
|
+
if (window.innerWidth < this.mediumBreakpoint) {
|
|
50
|
+
this.boxWidth = this.boxMobileWidth;
|
|
51
|
+
this.padding = this.mobilePadding;
|
|
52
|
+
this.isMobile = true;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.isMobile = false;
|
|
56
|
+
this.boxWidth = this.boxDesktopWidth;
|
|
57
|
+
this.padding = this.desktopPadding;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
this.handleSampleSelect = (selectedSample) => {
|
|
61
|
+
this.currentColor = null;
|
|
62
|
+
this.selectedCategory = selectedSample.value;
|
|
63
|
+
this.updateFilterAndFetch({ sampleId: selectedSample.value, colorFamily: '' });
|
|
64
|
+
};
|
|
65
|
+
this.shop = undefined;
|
|
66
|
+
this.product = undefined;
|
|
67
|
+
this.baselink = undefined;
|
|
68
|
+
this.selectedcolor = undefined;
|
|
69
|
+
this.arrowDown = 'arrow_down.png';
|
|
70
|
+
this.chunksNum = 12;
|
|
71
|
+
this.data = null;
|
|
72
|
+
this.preloader = false;
|
|
73
|
+
this.loading = false;
|
|
74
|
+
this.currentColor = null;
|
|
75
|
+
this.currentIndex = null;
|
|
76
|
+
this.infoBoxWidth = null;
|
|
77
|
+
this.boxWidth = this.boxDesktopWidth;
|
|
78
|
+
this.padding = this.desktopPadding;
|
|
79
|
+
this.isMobile = false;
|
|
80
|
+
this.showRange = false;
|
|
81
|
+
this.colorCategories = null;
|
|
82
|
+
this.selectedCategory = null;
|
|
83
|
+
this.page = 1;
|
|
84
|
+
this.colorIsSelected = false;
|
|
85
|
+
this.colorsList = [];
|
|
86
|
+
this.hasMore = true;
|
|
87
|
+
this.filters = {
|
|
88
|
+
type: 'product',
|
|
89
|
+
id: '',
|
|
90
|
+
productId: '',
|
|
91
|
+
page: 1,
|
|
92
|
+
colorNumber: '',
|
|
93
|
+
colorName: '',
|
|
94
|
+
};
|
|
95
|
+
this.debouncedSearchColorsHandler = debounce(this.searchColor.bind(this), 300);
|
|
96
|
+
}
|
|
97
|
+
setInfoBoxWidth(newValue) {
|
|
98
|
+
this.infoBoxWidth = newValue * this.boxWidth;
|
|
99
|
+
}
|
|
100
|
+
watchPropHandler(newValue) {
|
|
101
|
+
if (newValue) {
|
|
102
|
+
this.filters = updateFilters(this.filters, { id: newValue.id, type: 'product' });
|
|
103
|
+
this.fetchColorsData();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async open() {
|
|
107
|
+
this.modalEl.style.display = 'block';
|
|
108
|
+
}
|
|
109
|
+
closeModalHandler() {
|
|
110
|
+
this.close.emit();
|
|
111
|
+
}
|
|
112
|
+
handleReadyToClose(value) {
|
|
113
|
+
this.readyToCLose.emit({ observable: value });
|
|
114
|
+
}
|
|
115
|
+
closeInfoBoxHandler() {
|
|
116
|
+
this.currentColor = null;
|
|
117
|
+
this.currentIndex = null;
|
|
118
|
+
}
|
|
119
|
+
handleEmitColor(event) {
|
|
120
|
+
this.onSelectedColorEmit.emit(event.detail);
|
|
121
|
+
}
|
|
122
|
+
handleResize() {
|
|
123
|
+
this.calculateBoxCount();
|
|
124
|
+
this.displayForMobile();
|
|
125
|
+
}
|
|
126
|
+
sortColorsBySimilarity(colors) {
|
|
127
|
+
if (colors.length <= 1)
|
|
128
|
+
return colors;
|
|
129
|
+
const sortedColors = [];
|
|
130
|
+
const remainingColors = [...colors];
|
|
131
|
+
// Start with the first color
|
|
132
|
+
sortedColors.push(remainingColors.shift());
|
|
133
|
+
while (remainingColors.length > 0) {
|
|
134
|
+
// Find the most similar color to the last color in sortedColors
|
|
135
|
+
const lastColor = sortedColors[sortedColors.length - 1];
|
|
136
|
+
let mostSimilarIndex = 0;
|
|
137
|
+
let minDistance = Infinity;
|
|
138
|
+
remainingColors.forEach((color, index) => {
|
|
139
|
+
const distance = chroma.distance(lastColor.hex, color.hex, 'lab');
|
|
140
|
+
if (distance < minDistance) {
|
|
141
|
+
minDistance = distance;
|
|
142
|
+
mostSimilarIndex = index;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
// Move the most similar color to sortedColors
|
|
146
|
+
sortedColors.push(remainingColors.splice(mostSimilarIndex, 1)[0]);
|
|
147
|
+
}
|
|
148
|
+
return sortedColors;
|
|
149
|
+
}
|
|
150
|
+
getColorHueGroup(hex) {
|
|
151
|
+
const color = chroma(hex);
|
|
152
|
+
const hue = color.get('hsl.h');
|
|
153
|
+
const saturation = color.get('hsl.s');
|
|
154
|
+
const lightness = color.get('hsl.l');
|
|
155
|
+
// Handle grayscale colors
|
|
156
|
+
if (saturation < 0.1) {
|
|
157
|
+
if (lightness < 0.2)
|
|
158
|
+
return 'black';
|
|
159
|
+
if (lightness > 0.8)
|
|
160
|
+
return 'white';
|
|
161
|
+
return 'gray';
|
|
162
|
+
}
|
|
163
|
+
// Group colors by hue ranges
|
|
164
|
+
if (hue >= 330 || hue < 30)
|
|
165
|
+
return 'red';
|
|
166
|
+
if (hue >= 30 && hue < 90)
|
|
167
|
+
return 'yellow';
|
|
168
|
+
if (hue >= 90 && hue < 150)
|
|
169
|
+
return 'green';
|
|
170
|
+
if (hue >= 150 && hue < 210)
|
|
171
|
+
return 'cyan';
|
|
172
|
+
if (hue >= 210 && hue < 270)
|
|
173
|
+
return 'blue';
|
|
174
|
+
if (hue >= 270 && hue < 330)
|
|
175
|
+
return 'magenta';
|
|
176
|
+
return 'other';
|
|
177
|
+
}
|
|
178
|
+
sortColorsByHueAndSimilarity(colors) {
|
|
179
|
+
if (colors.length <= 1)
|
|
180
|
+
return colors;
|
|
181
|
+
// Group colors by their hue family
|
|
182
|
+
const colorGroups = {
|
|
183
|
+
red: [],
|
|
184
|
+
yellow: [],
|
|
185
|
+
green: [],
|
|
186
|
+
cyan: [],
|
|
187
|
+
blue: [],
|
|
188
|
+
magenta: [],
|
|
189
|
+
gray: [],
|
|
190
|
+
black: [],
|
|
191
|
+
white: [],
|
|
192
|
+
other: [],
|
|
193
|
+
};
|
|
194
|
+
// Sort colors into groups
|
|
195
|
+
colors.forEach(color => {
|
|
196
|
+
const group = this.getColorHueGroup(color.hex);
|
|
197
|
+
colorGroups[group].push(color);
|
|
198
|
+
});
|
|
199
|
+
// Sort each group by similarity
|
|
200
|
+
const sortedGroups = [];
|
|
201
|
+
const groupOrder = ['red', 'magenta', 'blue', 'cyan', 'green', 'yellow', 'gray', 'black', 'white', 'other'];
|
|
202
|
+
groupOrder.forEach(groupName => {
|
|
203
|
+
if (colorGroups[groupName].length > 0) {
|
|
204
|
+
sortedGroups.push(this.sortColorsBySimilarity(colorGroups[groupName]));
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// Combine all sorted groups
|
|
208
|
+
return sortedGroups.flat();
|
|
209
|
+
}
|
|
210
|
+
async fetchColorsData({ reset = false } = {}) {
|
|
211
|
+
if (this.loading && !reset)
|
|
212
|
+
return;
|
|
213
|
+
this.loading = true;
|
|
214
|
+
try {
|
|
215
|
+
const colors = await fetchColors(this.filters);
|
|
216
|
+
if (reset) {
|
|
217
|
+
// For new searches, sort all colors by hue and similarity
|
|
218
|
+
this.colorsList = this.sortColorsByHueAndSimilarity(colors);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// For pagination, combine and sort all colors
|
|
222
|
+
this.colorsList = this.sortColorsByHueAndSimilarity([...this.colorsList, ...colors]);
|
|
223
|
+
}
|
|
224
|
+
this.hasMore = colors.length >= limit;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
console.error('Error fetching colors:', error);
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
this.loading = false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async loadProductData() {
|
|
234
|
+
this.preloader = true;
|
|
235
|
+
const product = await fetchProductData({ shopName: this.shop, productName: this.product });
|
|
236
|
+
if (product) {
|
|
237
|
+
this.data = product;
|
|
238
|
+
this.filters = updateFilters(this.filters, { type: 'product', id: product.id });
|
|
239
|
+
// Fetch initial colors
|
|
240
|
+
await this.fetchColorsData();
|
|
241
|
+
}
|
|
242
|
+
this.preloader = false;
|
|
243
|
+
}
|
|
244
|
+
async loadMoreColors() {
|
|
245
|
+
if (this.loading || !this.hasMore)
|
|
246
|
+
return; // Prevent spam loading
|
|
247
|
+
this.filters = Object.assign(Object.assign({}, this.filters), { page: this.filters.page + 1 }); // Increase page for lazy loading
|
|
248
|
+
await this.fetchColorsData({ reset: false }); // Append results
|
|
249
|
+
}
|
|
250
|
+
updateFilterAndFetch(newFilters) {
|
|
251
|
+
var _a;
|
|
252
|
+
if (!((_a = this.data) === null || _a === void 0 ? void 0 : _a.id))
|
|
253
|
+
return;
|
|
254
|
+
this.loading = true;
|
|
255
|
+
this.filters = updateFilters(this.filters, Object.assign(Object.assign({ id: this.data.id, sampleId: this.filters.sampleId, colorName: this.filters.colorName }, newFilters), { page: 1 }));
|
|
256
|
+
this.fetchColorsData({ reset: true }).finally(() => {
|
|
257
|
+
this.loading = false;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
async searchColor(event) {
|
|
261
|
+
var _a;
|
|
262
|
+
const query = (_a = event.detail) === null || _a === void 0 ? void 0 : _a.trim();
|
|
263
|
+
this.updateFilterAndFetch({ colorName: query });
|
|
264
|
+
}
|
|
265
|
+
handleColorFamilySelected(event) {
|
|
266
|
+
this.currentColor = null;
|
|
267
|
+
if (event.detail === this.filters.colorFamily) {
|
|
268
|
+
this.filters = updateFilters(this.filters, { colorFamily: '' });
|
|
269
|
+
this.updateFilterAndFetch({ colorFamily: '' });
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this.filters = updateFilters(this.filters, { colorFamily: event.detail });
|
|
273
|
+
this.updateFilterAndFetch({ colorFamily: event.detail });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
searchColorsHandler(event) {
|
|
277
|
+
this.loading = true;
|
|
278
|
+
this.currentColor = null;
|
|
279
|
+
this.debouncedSearchColorsHandler(event);
|
|
280
|
+
}
|
|
281
|
+
handleScroll(_event, modalContent) {
|
|
282
|
+
if (this.loading || !this.hasMore)
|
|
283
|
+
return;
|
|
284
|
+
const scrollTop = modalContent.scrollTop;
|
|
285
|
+
const scrollHeight = modalContent.scrollHeight;
|
|
286
|
+
const clientHeight = modalContent.clientHeight;
|
|
287
|
+
// Check if user scrolled to the bottom of the modal
|
|
288
|
+
if (scrollTop + clientHeight >= scrollHeight - 50) {
|
|
289
|
+
this.loadMoreColors();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
openSeletedColor() {
|
|
293
|
+
var _a, _b;
|
|
294
|
+
if (!this.colorsList || !this.selectedcolor)
|
|
295
|
+
return;
|
|
296
|
+
if (!this.colorIsSelected) {
|
|
297
|
+
const result = this.chunks(this.colorsList)
|
|
298
|
+
.map((innerArray, arrayIndex) => {
|
|
299
|
+
const foundColor = innerArray.find(color => { var _a, _b, _c; return ((_a = color.name.trim()) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === ((_c = (_b = this.selectedcolor) === null || _b === void 0 ? void 0 : _b.trim()) === null || _c === void 0 ? void 0 : _c.toUpperCase()); });
|
|
300
|
+
return foundColor ? { color: foundColor, index: arrayIndex } : null;
|
|
301
|
+
})
|
|
302
|
+
.filter(item => item !== null);
|
|
303
|
+
this.currentColor = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.color;
|
|
304
|
+
this.currentIndex = (_b = result[0]) === null || _b === void 0 ? void 0 : _b.index;
|
|
305
|
+
this.colorIsSelected = true;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
componentWillLoad() {
|
|
309
|
+
this.preloader = true;
|
|
310
|
+
setDataLayer({
|
|
311
|
+
shop: this.shop,
|
|
312
|
+
product: this.product,
|
|
313
|
+
});
|
|
314
|
+
this.loadProductData();
|
|
315
|
+
}
|
|
316
|
+
componentWillRender() {
|
|
317
|
+
this.displayForMobile();
|
|
318
|
+
this.calculateBoxCount();
|
|
319
|
+
this.colorTimer();
|
|
320
|
+
this.openSeletedColor();
|
|
321
|
+
const modalContent = this.modalEl.querySelector('.my-modal');
|
|
322
|
+
if (modalContent) {
|
|
323
|
+
modalContent.addEventListener('scroll', event => this.handleScroll(event, modalContent));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
resetColors() {
|
|
327
|
+
this.currentColor = null;
|
|
328
|
+
this.currentIndex = null;
|
|
329
|
+
this.colorIsSelected = false;
|
|
330
|
+
}
|
|
331
|
+
resetAllFilters() {
|
|
332
|
+
var _a;
|
|
333
|
+
// Reset current color selection
|
|
334
|
+
this.resetColors();
|
|
335
|
+
// Reset filters to initial state
|
|
336
|
+
this.filters = {
|
|
337
|
+
type: 'product',
|
|
338
|
+
id: ((_a = this.data) === null || _a === void 0 ? void 0 : _a.id) || '',
|
|
339
|
+
productId: '',
|
|
340
|
+
page: 1,
|
|
341
|
+
colorNumber: '',
|
|
342
|
+
colorName: '',
|
|
343
|
+
colorFamily: '',
|
|
344
|
+
sampleId: '',
|
|
345
|
+
};
|
|
346
|
+
// Reset selected category
|
|
347
|
+
this.selectedCategory = null;
|
|
348
|
+
// Clear search text
|
|
349
|
+
this.clearSearchText.emit();
|
|
350
|
+
// Fetch colors with reset filters
|
|
351
|
+
this.fetchColorsData({ reset: true });
|
|
352
|
+
}
|
|
353
|
+
resetSelectedCategory() {
|
|
354
|
+
this.resetColors();
|
|
355
|
+
this.colorIsSelected = false;
|
|
356
|
+
this.selectedCategory = null;
|
|
357
|
+
this.filters = updateFilters(this.filters, { sampleId: '' });
|
|
358
|
+
this.fetchColorsData({ reset: true });
|
|
359
|
+
}
|
|
360
|
+
render() {
|
|
361
|
+
var _a;
|
|
362
|
+
return (h("div", { class: `my-modal`, onMouseEnter: () => this.handleReadyToClose(false), onMouseLeave: () => this.handleReadyToClose(true) }, this.preloader && (h("div", { class: 'loader' }, h("my-loader", null))), !this.preloader && this.data && (h("modal-header", { modalName: this.data.modalName, modalLogo: this.data.modalLogo ? `${APIURL}/assets/${this.data.modalLogo}?access_token=${accessToken}` : null, modalDescription: this.data.modalDescription, shop: this.shop, productName: this.data.name, productSamples: this.data.productSamples, selectedColorFamily: this.filters.colorFamily, isMobile: this.isMobile, onCloseModal: () => this.closeModalHandler(), onSampleSelected: event => this.handleSampleSelect(event.detail), onOnLogoClick: () => this.resetAllFilters(), onOnResetCategory: () => this.resetSelectedCategory() })), h("div", { class: 'my-modal__wrapper' }, !this.preloader && (h("div", { class: 'container_boxes' }, !this.loading && this.colorsList.length === 0 && (h("div", { class: "not-found" }, h("p", null, "Nie zaleziono wynik\u00F3w wyszukiwania pod danym has\u0142em."), h("p", null, " Wpisz inn\u0105 nazw\u0119 b\u0105d\u017A numer koloru lub skorzystaj z kolekcji kolorystycznych."))), ((_a = this.colorsList) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
|
|
363
|
+
this.chunks(this.colorsList).map((color, index) => {
|
|
364
|
+
var _a;
|
|
365
|
+
return (h("div", { key: index, class: "boxes" }, h("div", { class: "boxes__list" }, color.map((c) => {
|
|
366
|
+
var _a;
|
|
367
|
+
return (h("my-colorbox", { key: c.id, onClick: () => {
|
|
368
|
+
var _a;
|
|
369
|
+
if (((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.id) === c.id) {
|
|
370
|
+
this.currentColor = null;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
this.currentColor = c;
|
|
374
|
+
}
|
|
375
|
+
this.currentIndex = index;
|
|
376
|
+
setDataLayer({
|
|
377
|
+
event: 'ColorClick',
|
|
378
|
+
shop: this.shop,
|
|
379
|
+
product: this.product,
|
|
380
|
+
color: c.name,
|
|
381
|
+
});
|
|
382
|
+
this.clearInterval();
|
|
383
|
+
}, color: c.hex, name: c.name, isActive: ((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.id) === c.id, shop: this.shop, product: this.product, isImageInsteadHex: {
|
|
384
|
+
isImageInsteadHex: c.imageInsteadHex,
|
|
385
|
+
bigImage: c.bigImage,
|
|
386
|
+
} }));
|
|
387
|
+
})), ((_a = this.currentColor) === null || _a === void 0 ? void 0 : _a.id) && index === this.currentIndex && (h("my-colorinfo", { currentColor: this.currentColor, shop: this.shop, product: this.product, data: this.data, isMobile: this.isMobile, infoBoxWidth: this.infoBoxWidth, baselink: this.baselink }))));
|
|
388
|
+
}))), this.loading && h("my-loader", null)), !this.preloader && this.isMobile && (h("button", { class: "button", onClick: () => this.closeModalHandler() }, "Zamknij"))));
|
|
389
|
+
}
|
|
390
|
+
static get is() { return "my-modal"; }
|
|
391
|
+
static get originalStyleUrls() {
|
|
392
|
+
return {
|
|
393
|
+
"$": ["index.scss"]
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
static get styleUrls() {
|
|
397
|
+
return {
|
|
398
|
+
"$": ["index.css"]
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
static get assetsDirs() { return ["assets"]; }
|
|
402
|
+
static get properties() {
|
|
403
|
+
return {
|
|
404
|
+
"shop": {
|
|
405
|
+
"type": "string",
|
|
406
|
+
"mutable": false,
|
|
407
|
+
"complexType": {
|
|
408
|
+
"original": "string",
|
|
409
|
+
"resolved": "string",
|
|
410
|
+
"references": {}
|
|
411
|
+
},
|
|
412
|
+
"required": false,
|
|
413
|
+
"optional": false,
|
|
414
|
+
"docs": {
|
|
415
|
+
"tags": [],
|
|
416
|
+
"text": ""
|
|
417
|
+
},
|
|
418
|
+
"attribute": "shop",
|
|
419
|
+
"reflect": false
|
|
420
|
+
},
|
|
421
|
+
"product": {
|
|
422
|
+
"type": "string",
|
|
423
|
+
"mutable": false,
|
|
424
|
+
"complexType": {
|
|
425
|
+
"original": "string",
|
|
426
|
+
"resolved": "string",
|
|
427
|
+
"references": {}
|
|
428
|
+
},
|
|
429
|
+
"required": false,
|
|
430
|
+
"optional": false,
|
|
431
|
+
"docs": {
|
|
432
|
+
"tags": [],
|
|
433
|
+
"text": ""
|
|
434
|
+
},
|
|
435
|
+
"attribute": "product",
|
|
436
|
+
"reflect": false
|
|
437
|
+
},
|
|
438
|
+
"baselink": {
|
|
439
|
+
"type": "string",
|
|
440
|
+
"mutable": false,
|
|
441
|
+
"complexType": {
|
|
442
|
+
"original": "string",
|
|
443
|
+
"resolved": "string",
|
|
444
|
+
"references": {}
|
|
445
|
+
},
|
|
446
|
+
"required": false,
|
|
447
|
+
"optional": false,
|
|
448
|
+
"docs": {
|
|
449
|
+
"tags": [],
|
|
450
|
+
"text": ""
|
|
451
|
+
},
|
|
452
|
+
"attribute": "baselink",
|
|
453
|
+
"reflect": false
|
|
454
|
+
},
|
|
455
|
+
"selectedcolor": {
|
|
456
|
+
"type": "string",
|
|
457
|
+
"mutable": false,
|
|
458
|
+
"complexType": {
|
|
459
|
+
"original": "string | null",
|
|
460
|
+
"resolved": "null | string",
|
|
461
|
+
"references": {}
|
|
462
|
+
},
|
|
463
|
+
"required": false,
|
|
464
|
+
"optional": false,
|
|
465
|
+
"docs": {
|
|
466
|
+
"tags": [],
|
|
467
|
+
"text": ""
|
|
468
|
+
},
|
|
469
|
+
"attribute": "selectedcolor",
|
|
470
|
+
"reflect": false
|
|
471
|
+
},
|
|
472
|
+
"arrowDown": {
|
|
473
|
+
"type": "string",
|
|
474
|
+
"mutable": false,
|
|
475
|
+
"complexType": {
|
|
476
|
+
"original": "string",
|
|
477
|
+
"resolved": "string",
|
|
478
|
+
"references": {}
|
|
479
|
+
},
|
|
480
|
+
"required": false,
|
|
481
|
+
"optional": false,
|
|
482
|
+
"docs": {
|
|
483
|
+
"tags": [],
|
|
484
|
+
"text": ""
|
|
485
|
+
},
|
|
486
|
+
"attribute": "arrow-down",
|
|
487
|
+
"reflect": false,
|
|
488
|
+
"defaultValue": "'arrow_down.png'"
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
static get states() {
|
|
493
|
+
return {
|
|
494
|
+
"chunksNum": {},
|
|
495
|
+
"data": {},
|
|
496
|
+
"preloader": {},
|
|
497
|
+
"loading": {},
|
|
498
|
+
"currentColor": {},
|
|
499
|
+
"currentIndex": {},
|
|
500
|
+
"infoBoxWidth": {},
|
|
501
|
+
"boxWidth": {},
|
|
502
|
+
"padding": {},
|
|
503
|
+
"isMobile": {},
|
|
504
|
+
"showRange": {},
|
|
505
|
+
"colorCategories": {},
|
|
506
|
+
"selectedCategory": {},
|
|
507
|
+
"page": {},
|
|
508
|
+
"colorIsSelected": {},
|
|
509
|
+
"colorsList": {},
|
|
510
|
+
"hasMore": {},
|
|
511
|
+
"filters": {}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
static get events() {
|
|
515
|
+
return [{
|
|
516
|
+
"method": "onSelectedColorEmit",
|
|
517
|
+
"name": "onSelectedColorEmit",
|
|
518
|
+
"bubbles": true,
|
|
519
|
+
"cancelable": true,
|
|
520
|
+
"composed": true,
|
|
521
|
+
"docs": {
|
|
522
|
+
"tags": [],
|
|
523
|
+
"text": ""
|
|
524
|
+
},
|
|
525
|
+
"complexType": {
|
|
526
|
+
"original": "Color",
|
|
527
|
+
"resolved": "{ hex: string; image: Record<string, Image>; links: Link[]; name: string; position: number; buttonInverse: boolean; textWhite: boolean; id?: number | undefined; category?: Partial<Color> | undefined; number?: string | undefined; Category_id: Color; imageInsteadHex: boolean; bigImage: string; }",
|
|
528
|
+
"references": {
|
|
529
|
+
"Color": {
|
|
530
|
+
"location": "import",
|
|
531
|
+
"path": "../../types"
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}, {
|
|
536
|
+
"method": "clearSearchText",
|
|
537
|
+
"name": "clearSearchText",
|
|
538
|
+
"bubbles": true,
|
|
539
|
+
"cancelable": true,
|
|
540
|
+
"composed": true,
|
|
541
|
+
"docs": {
|
|
542
|
+
"tags": [],
|
|
543
|
+
"text": ""
|
|
544
|
+
},
|
|
545
|
+
"complexType": {
|
|
546
|
+
"original": "any",
|
|
547
|
+
"resolved": "any",
|
|
548
|
+
"references": {}
|
|
549
|
+
}
|
|
550
|
+
}, {
|
|
551
|
+
"method": "close",
|
|
552
|
+
"name": "close",
|
|
553
|
+
"bubbles": true,
|
|
554
|
+
"cancelable": true,
|
|
555
|
+
"composed": true,
|
|
556
|
+
"docs": {
|
|
557
|
+
"tags": [],
|
|
558
|
+
"text": ""
|
|
559
|
+
},
|
|
560
|
+
"complexType": {
|
|
561
|
+
"original": "any",
|
|
562
|
+
"resolved": "any",
|
|
563
|
+
"references": {}
|
|
564
|
+
}
|
|
565
|
+
}, {
|
|
566
|
+
"method": "readyToCLose",
|
|
567
|
+
"name": "readyToCLose",
|
|
568
|
+
"bubbles": true,
|
|
569
|
+
"cancelable": true,
|
|
570
|
+
"composed": true,
|
|
571
|
+
"docs": {
|
|
572
|
+
"tags": [],
|
|
573
|
+
"text": ""
|
|
574
|
+
},
|
|
575
|
+
"complexType": {
|
|
576
|
+
"original": "any",
|
|
577
|
+
"resolved": "any",
|
|
578
|
+
"references": {}
|
|
579
|
+
}
|
|
580
|
+
}];
|
|
581
|
+
}
|
|
582
|
+
static get methods() {
|
|
583
|
+
return {
|
|
584
|
+
"open": {
|
|
585
|
+
"complexType": {
|
|
586
|
+
"signature": "() => Promise<void>",
|
|
587
|
+
"parameters": [],
|
|
588
|
+
"references": {
|
|
589
|
+
"Promise": {
|
|
590
|
+
"location": "global"
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
"return": "Promise<void>"
|
|
594
|
+
},
|
|
595
|
+
"docs": {
|
|
596
|
+
"text": "",
|
|
597
|
+
"tags": []
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
static get elementRef() { return "modalEl"; }
|
|
603
|
+
static get watchers() {
|
|
604
|
+
return [{
|
|
605
|
+
"propName": "chunksNum",
|
|
606
|
+
"methodName": "setInfoBoxWidth"
|
|
607
|
+
}, {
|
|
608
|
+
"propName": "data",
|
|
609
|
+
"methodName": "watchPropHandler"
|
|
610
|
+
}];
|
|
611
|
+
}
|
|
612
|
+
static get listeners() {
|
|
613
|
+
return [{
|
|
614
|
+
"name": "closeInfoBox",
|
|
615
|
+
"method": "closeInfoBoxHandler",
|
|
616
|
+
"target": undefined,
|
|
617
|
+
"capture": false,
|
|
618
|
+
"passive": false
|
|
619
|
+
}, {
|
|
620
|
+
"name": "onCurrentColor",
|
|
621
|
+
"method": "handleEmitColor",
|
|
622
|
+
"target": undefined,
|
|
623
|
+
"capture": false,
|
|
624
|
+
"passive": false
|
|
625
|
+
}, {
|
|
626
|
+
"name": "resize",
|
|
627
|
+
"method": "handleResize",
|
|
628
|
+
"target": "window",
|
|
629
|
+
"capture": false,
|
|
630
|
+
"passive": true
|
|
631
|
+
}, {
|
|
632
|
+
"name": "colorFamilySelected",
|
|
633
|
+
"method": "handleColorFamilySelected",
|
|
634
|
+
"target": undefined,
|
|
635
|
+
"capture": false,
|
|
636
|
+
"passive": false
|
|
637
|
+
}, {
|
|
638
|
+
"name": "searchColors",
|
|
639
|
+
"method": "searchColorsHandler",
|
|
640
|
+
"target": undefined,
|
|
641
|
+
"capture": false,
|
|
642
|
+
"passive": false
|
|
643
|
+
}];
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
//# sourceMappingURL=index.js.map
|