homeflowjs 0.13.8 → 0.13.12
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.
@@ -0,0 +1,72 @@
|
|
1
|
+
import replaceImageDimensions from '../images/replaceImageDimensions';
|
2
|
+
|
3
|
+
describe('replaceImageDimensions()', () => {
|
4
|
+
it('takes a path string, if string is null it will return an empty string', () => {
|
5
|
+
expect(replaceImageDimensions(null)).toEqual('');
|
6
|
+
});
|
7
|
+
|
8
|
+
it('takes a path string, if string is empty it will return an empty string', () => {
|
9
|
+
expect(replaceImageDimensions('')).toEqual('');
|
10
|
+
});
|
11
|
+
|
12
|
+
it('takes a path string, if string is undefined it will return an empty string', () => {
|
13
|
+
expect(replaceImageDimensions(undefined)).toEqual('');
|
14
|
+
});
|
15
|
+
|
16
|
+
it('takes a path with no dimensions or _x_ value and returns the updated path with width and height if set in options object', () => {
|
17
|
+
expect(
|
18
|
+
replaceImageDimensions('https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/HON230052_02.jpg', 1000, 1000),
|
19
|
+
).toEqual(
|
20
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/1000x1000/HON230052_02.jpg',
|
21
|
+
);
|
22
|
+
});
|
23
|
+
|
24
|
+
it('takes an absolute path with _x_ returns the updated path with width and height if set in options object', () => {
|
25
|
+
expect(
|
26
|
+
replaceImageDimensions(
|
27
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/_x_/HON230052_02.jpg',
|
28
|
+
1000,
|
29
|
+
1000,
|
30
|
+
),
|
31
|
+
).toEqual(
|
32
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/1000x1000/HON230052_02.jpg',
|
33
|
+
);
|
34
|
+
});
|
35
|
+
|
36
|
+
it('removes image path sizes 120x90 and replaces them with _x_ if options width and height are not set', () => {
|
37
|
+
expect(replaceImageDimensions('https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/120x90/HON230052_02.jpg')).toEqual(
|
38
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/_x_/HON230052_02.jpg',
|
39
|
+
);
|
40
|
+
});
|
41
|
+
|
42
|
+
it('removes image path sizes 120x90 and replaces them with width and height', () => {
|
43
|
+
expect(
|
44
|
+
replaceImageDimensions('https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/120x90/HON230052_02.jpg',
|
45
|
+
1000,
|
46
|
+
1000,
|
47
|
+
),
|
48
|
+
).toEqual(
|
49
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/1000x1000/HON230052_02.jpg',
|
50
|
+
);
|
51
|
+
});
|
52
|
+
|
53
|
+
it('removes image path _x_ and replaces them with width and height', () => {
|
54
|
+
expect(
|
55
|
+
replaceImageDimensions('https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/_x_/HON230052_02.jpg', 1000, 1000),
|
56
|
+
).toEqual(
|
57
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/1000x1000/HON230052_02.jpg',
|
58
|
+
);
|
59
|
+
});
|
60
|
+
|
61
|
+
it('removes image path width and replaces dimensions with default if width option is not set', () => {
|
62
|
+
expect(replaceImageDimensions('https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/220x_/HON230052_02.jpg')).toEqual(
|
63
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/_x_/HON230052_02.jpg',
|
64
|
+
);
|
65
|
+
});
|
66
|
+
|
67
|
+
it('removes image path height and replaces dimensions with default if height option is not set', () => {
|
68
|
+
expect(replaceImageDimensions('https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/_x220/HON230052_02.jpg')).toEqual(
|
69
|
+
'https://mr0.homeflow-assets.co.uk/files/photo/image/27190/2904/_x_/HON230052_02.jpg',
|
70
|
+
);
|
71
|
+
});
|
72
|
+
});
|
@@ -1,33 +1,32 @@
|
|
1
|
-
const replaceImageDimensions = (src, width
|
2
|
-
if (!src) return
|
1
|
+
const replaceImageDimensions = (src, width, height) => {
|
2
|
+
if (!src) return '';
|
3
3
|
|
4
|
-
const
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
let formatedSrc = null; // default to null
|
16
|
-
if ((srcPathWithoutSize || srcPathWithSize) && src.includes('_x_')) {
|
17
|
-
formatedSrc = src.replace('_x_', widthXheight);
|
18
|
-
}
|
19
|
-
if ((srcPathWithoutSize || srcPathWithSize) && !src.includes('_x_') && !pathBeforeFileName.includes('x')) {
|
20
|
-
formatedSrc = `${src.substring(0, lastSlashIndex + 1)}${widthXheight}${src.substr(lastSlashIndex)}`;
|
21
|
-
}
|
22
|
-
// src contains width or height set on the cms but not the component
|
23
|
-
if ((srcPathWithoutSize || srcPathWithSize) && !src.includes('_x_') && pathBeforeFileName.includes('x')) {
|
24
|
-
formatedSrc = src;
|
25
|
-
}
|
26
|
-
if (srcPathWithoutSize === srcPathWithSize) {
|
27
|
-
console.log('Source not supported', src);
|
28
|
-
formatedSrc = null;
|
4
|
+
const dimensions = `${width || '_'}x${height || '_'}`;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* This will be used to add dimensions to a src that has no dimensions or _x_ values.
|
8
|
+
* For example /files/photos/12345/6789/my-photo.jpg => /files/photos/12345/6789/_x_/my-photo.jpg
|
9
|
+
*/
|
10
|
+
function addDimensionsToPathWithoutSize(string) {
|
11
|
+
const lastSlashIndex = string.lastIndexOf('/');
|
12
|
+
return `${string.substring(0, lastSlashIndex + 1)}${dimensions}${string.substring(
|
13
|
+
lastSlashIndex,
|
14
|
+
)}`;
|
29
15
|
}
|
30
|
-
|
16
|
+
|
17
|
+
/**
|
18
|
+
* This covers:
|
19
|
+
* - Dimensions in format of 1000x1000
|
20
|
+
* - Dimensions in format of _x1000
|
21
|
+
* - Dimensions in format of 1000x_
|
22
|
+
* - Dimensions in format of _x_
|
23
|
+
* or
|
24
|
+
* - A path with no dimensions or _x_ values /files/photos/12345/6789/my-photo.jpg
|
25
|
+
*/
|
26
|
+
const resizedPath = /\/(\d+|_)x(\d+|_)\//.test(src)
|
27
|
+
? src.replace(/\/(\d+|_)x(\d+|_)\//, `/${dimensions}/`).trim() : addDimensionsToPathWithoutSize(src);
|
28
|
+
|
29
|
+
return resizedPath;
|
31
30
|
};
|
32
31
|
|
33
32
|
export default replaceImageDimensions;
|
package/package.json
CHANGED
@@ -190,13 +190,13 @@ export default class GeonamesMap extends DraggableMap {
|
|
190
190
|
}
|
191
191
|
|
192
192
|
getMarkerBounds() {
|
193
|
-
const
|
193
|
+
const polygon = store.getState().search.currentSearch?.place?.polygon;
|
194
194
|
if (this.viewport) {
|
195
195
|
const viewportBounds = this.getViewportBounds();
|
196
196
|
if (viewportBounds.flat().find(coordinate => coordinate === Infinity)) return null;
|
197
197
|
|
198
198
|
return L.latLngBounds(...viewportBounds.map(bound => L.latLng(...bound)));
|
199
|
-
} else if (polygon && polygon
|
199
|
+
} else if (polygon && polygon?.length) {
|
200
200
|
const polyBounds = [this.getTopRightPolygonCoordinates(polygon[0]), this.getBottomLeftPolygonCoordinates(polygon[0])];
|
201
201
|
const options = Homeflow.get('custom_map_bounds_padding')
|
202
202
|
const latLongBounds = L.latLngBounds(...polyBounds.map(bound => L.latLng(...bound)));
|