@gudhub/ssg-web-components-library 1.0.123 → 1.0.125
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/package.json
CHANGED
|
@@ -20,11 +20,15 @@ export const checkInputsValidations = (inputs) => {
|
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const isEmptyAndOptional = (input) => {
|
|
24
|
+
const value = input.value.trim();
|
|
25
|
+
return value === '' && !input.hasAttribute('required');
|
|
26
|
+
};
|
|
23
27
|
|
|
24
28
|
const emailValidation = (input) => {
|
|
25
29
|
const regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
|
26
30
|
|
|
27
|
-
let isValid = regex.test(input.value);
|
|
31
|
+
let isValid = isEmptyAndOptional(input) || regex.test(input.value);
|
|
28
32
|
|
|
29
33
|
if (!isValid) {
|
|
30
34
|
input.classList.add('error');
|
|
@@ -38,11 +42,9 @@ const emailValidation = (input) => {
|
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
const phoneValidation = (input) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const regex = /^\+?\d+$/; // We can write only numbers without special symbols besides "+" sign
|
|
45
|
+
const regex = /^\+?\d+$/;
|
|
44
46
|
|
|
45
|
-
let isValid = regex.test(input.value);
|
|
47
|
+
let isValid = isEmptyAndOptional(input) || regex.test(input.value);
|
|
46
48
|
|
|
47
49
|
if (!isValid) {
|
|
48
50
|
input.classList.add('error');
|
|
@@ -76,12 +76,12 @@ class MasonryGallery extends GHComponent {
|
|
|
76
76
|
'masonry-images'
|
|
77
77
|
);
|
|
78
78
|
|
|
79
|
-
const
|
|
80
|
-
this.getAttribute('init-count') === 'null';
|
|
79
|
+
const initCountFromJson = Number(this.getAttribute('init-count'));
|
|
81
80
|
|
|
82
|
-
const initCountImages =
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const initCountImages =
|
|
82
|
+
initCountFromJson > 0
|
|
83
|
+
? initCountFromJson
|
|
84
|
+
: (this.showCount || 10);
|
|
85
85
|
|
|
86
86
|
const initImages = images.slice(0, initCountImages);
|
|
87
87
|
const initMoreImages = images.slice(initCountImages);
|
|
@@ -208,68 +208,73 @@ class MasonryGallery extends GHComponent {
|
|
|
208
208
|
const msnry = this.msnry;
|
|
209
209
|
|
|
210
210
|
const promise = new Promise(async (res, rej) => {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
211
|
+
try {
|
|
212
|
+
const img = document.createElement('img');
|
|
213
|
+
|
|
214
|
+
const fileName = imageSrc.split('/').pop();
|
|
215
|
+
|
|
216
|
+
let finalSrc = `/assets/images/masonry/${fileName}`;
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const uploadResponse = await fetch('/upload-image-path', {
|
|
220
|
+
method: 'POST',
|
|
221
|
+
headers: {
|
|
222
|
+
'Content-Type': 'application/json'
|
|
223
|
+
},
|
|
224
|
+
body: JSON.stringify({
|
|
225
|
+
imageSrc: finalSrc,
|
|
226
|
+
imageUrl: imageSrc,
|
|
227
|
+
isCrop: true
|
|
228
|
+
})
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const uploadData = await uploadResponse.json();
|
|
232
|
+
|
|
233
|
+
if (uploadData?.normalizedSrc) {
|
|
234
|
+
finalSrc = uploadData.normalizedSrc;
|
|
235
|
+
}
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.error('upload-image-path error:', error);
|
|
238
|
+
}
|
|
221
239
|
|
|
222
|
-
|
|
223
|
-
await fetch('/upload-image-path', {
|
|
224
|
-
method: 'POST',
|
|
225
|
-
headers: {
|
|
226
|
-
'Content-Type': 'application/json'
|
|
227
|
-
},
|
|
228
|
-
body: JSON.stringify({
|
|
229
|
-
imageSrc: pathToJpg,
|
|
230
|
-
imageUrl: imageSrc,
|
|
231
|
-
isCrop: true
|
|
232
|
-
})
|
|
233
|
-
});
|
|
234
|
-
}
|
|
240
|
+
img.src = finalSrc;
|
|
235
241
|
|
|
236
|
-
|
|
242
|
+
img.setAttribute('src', finalSrc);
|
|
243
|
+
img.setAttribute('alt', imageAlt);
|
|
244
|
+
img.setAttribute('title', imageTitle);
|
|
237
245
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
`/assets/images/masonry/${fileName}`
|
|
241
|
-
);
|
|
242
|
-
img.setAttribute('alt', imageAlt);
|
|
243
|
-
img.setAttribute('title', imageTitle);
|
|
246
|
+
if (fullImageSrc) {
|
|
247
|
+
const tempoFullImageSrc = await this.temporaryImage(fullImageSrc);
|
|
244
248
|
|
|
245
|
-
|
|
246
|
-
|
|
249
|
+
img.classList.add('open-modal');
|
|
250
|
+
img.setAttribute('data-modal-image', tempoFullImageSrc);
|
|
251
|
+
}
|
|
247
252
|
|
|
248
|
-
img.
|
|
249
|
-
|
|
253
|
+
img.setAttribute('data-image-loading', 'true');
|
|
254
|
+
|
|
255
|
+
// Set image wrapper size while the image is loading
|
|
256
|
+
const interval = setInterval(() => {
|
|
257
|
+
if (img.width !== 0) {
|
|
258
|
+
img.style.width = `${img.naturalWidth}px`;
|
|
259
|
+
img.style.height = `${img.naturalHeight}px`;
|
|
260
|
+
clearInterval(interval);
|
|
261
|
+
res(imageWrapper);
|
|
262
|
+
}
|
|
263
|
+
}, 10);
|
|
264
|
+
|
|
265
|
+
// Create image wrapper and append the image to it
|
|
266
|
+
const imageWrapper = document.createElement('div');
|
|
267
|
+
imageWrapper.classList.add('masonry-grid-item')
|
|
268
|
+
// img.onload = () => {
|
|
269
|
+
img.removeAttribute('data-image-loading');
|
|
270
|
+
// }
|
|
271
|
+
imageWrapper.appendChild(img);
|
|
272
|
+
this.imagesContainer.appendChild(imageWrapper);
|
|
273
|
+
} catch (error) {
|
|
274
|
+
console.error(error);
|
|
275
|
+
rej(error);
|
|
250
276
|
}
|
|
251
|
-
|
|
252
|
-
img.setAttribute('data-image-loading', 'true');
|
|
253
|
-
|
|
254
|
-
// Set image wrapper size while the image is loading
|
|
255
|
-
const interval = setInterval(() => {
|
|
256
|
-
if (img.width !== 0) {
|
|
257
|
-
img.style.width = `${img.naturalWidth}px`;
|
|
258
|
-
img.style.height = `${img.naturalHeight}px`;
|
|
259
|
-
clearInterval(interval);
|
|
260
|
-
res(imageWrapper);
|
|
261
|
-
}
|
|
262
|
-
}, 10);
|
|
263
|
-
|
|
264
|
-
// Create image wrapper and append the image to it
|
|
265
|
-
const imageWrapper = document.createElement('div');
|
|
266
|
-
imageWrapper.classList.add('masonry-grid-item')
|
|
267
|
-
// img.onload = () => {
|
|
268
|
-
img.removeAttribute('data-image-loading');
|
|
269
|
-
// }
|
|
270
|
-
imageWrapper.appendChild(img);
|
|
271
|
-
this.imagesContainer.appendChild(imageWrapper);
|
|
272
|
-
});
|
|
277
|
+
});
|
|
273
278
|
|
|
274
279
|
// After image is loaded, append it to Masonry layout and re-layout the grid
|
|
275
280
|
promise.then((img) => {
|