@griddo/ax 1.66.2 → 1.66.3
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "1.66.
|
|
4
|
+
"version": "1.66.3",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Carlos Torres <carlos.torres@secuoyas.com>",
|
|
@@ -221,5 +221,5 @@
|
|
|
221
221
|
"publishConfig": {
|
|
222
222
|
"access": "public"
|
|
223
223
|
},
|
|
224
|
-
"gitHead": "
|
|
224
|
+
"gitHead": "c5cf3e9fcc40893cc5a92140dd3a4c50f42a2cfe"
|
|
225
225
|
}
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { GriddoImage } from "@griddo/core";
|
|
3
|
+
import { createCloudinaryUrl, isCloudinary } from "./utils";
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const DAM_DEFAULTS = {
|
|
6
|
+
quality: 75,
|
|
7
|
+
crop: "cover",
|
|
8
|
+
loading: "lazy",
|
|
9
|
+
formats: ["webp"],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const Image = (props: IProps): React.ReactElement => {
|
|
13
|
+
const { url } = props;
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
if (isCloudinary(url)) {
|
|
16
|
+
const cloudinaryUrl = createCloudinaryUrl({ props });
|
|
17
|
+
return <img src={cloudinaryUrl} alt="Griddo site thumbnail" />;
|
|
18
|
+
} else {
|
|
19
|
+
return <GriddoImage {...DAM_DEFAULTS} {...props} />;
|
|
20
|
+
}
|
|
13
21
|
};
|
|
14
22
|
|
|
15
|
-
interface IProps {
|
|
23
|
+
export interface IProps {
|
|
16
24
|
width: number;
|
|
17
25
|
height?: number;
|
|
18
26
|
url: string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IProps } from "./index";
|
|
2
|
+
|
|
3
|
+
// The string to split up the cloudinary url
|
|
4
|
+
const CLOUDINARY_SEPARATOR = "image/upload";
|
|
5
|
+
// The string to know if the url is a cloudinary url
|
|
6
|
+
const CLOUDINARY_HEAD_URL = "https://res.cloudinary.com";
|
|
7
|
+
|
|
8
|
+
function isCloudinary(url: string): boolean {
|
|
9
|
+
// TODO: Write a better check, probabily parsing the API props from a UrlField
|
|
10
|
+
return url.startsWith(CLOUDINARY_HEAD_URL);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createCloudinaryUrl({ props, retina = true }: ICreateCloudinaryUrl): string {
|
|
14
|
+
// Split the cloudinary url to be able to insert the concat params between them
|
|
15
|
+
const [head, tail] = props.url.split(CLOUDINARY_SEPARATOR);
|
|
16
|
+
|
|
17
|
+
// Concat props in a cloudinary url format
|
|
18
|
+
// w_100 for width: 100, etc..
|
|
19
|
+
// * 2 = full retina
|
|
20
|
+
const cloudinaryParms = concatCloudinaryParams({
|
|
21
|
+
w: props.width * (retina ? 2 : 1),
|
|
22
|
+
h: props.height && props.height * (retina ? 2 : 1),
|
|
23
|
+
q: props.quality,
|
|
24
|
+
c: "fill",
|
|
25
|
+
f: "jpg",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return `${head}${cloudinaryParms}${tail}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function concatCloudinaryParams(params: ICloudinaryParams) {
|
|
32
|
+
const cloudinaryParms = Object.keys(params)
|
|
33
|
+
.map((key) => (params[key] ? `${key}_${params[key]}` : ""))
|
|
34
|
+
.join(",");
|
|
35
|
+
|
|
36
|
+
// This split cleans up the string url with extra commas (,)
|
|
37
|
+
// w_100,,q_10 --> w_100,q_10 ->
|
|
38
|
+
return cloudinaryParms.split(",").filter(Boolean).join(",");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface ICloudinaryParams {
|
|
42
|
+
w: number;
|
|
43
|
+
h?: number;
|
|
44
|
+
q?: number;
|
|
45
|
+
c: "fill" | "fit";
|
|
46
|
+
f: "webp" | "jpg";
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface ICreateCloudinaryUrl {
|
|
51
|
+
props: IProps;
|
|
52
|
+
retina?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { createCloudinaryUrl, isCloudinary };
|