@raketa-builder/image-input 0.6.0 → 0.8.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/package.json CHANGED
@@ -1,27 +1,28 @@
1
1
  {
2
2
  "name": "@raketa-builder/image-input",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "lint": "TIMING=1 eslint \"**/*.js\"",
9
8
  "build": "tsup src/index.js --format cjs --loader \".js=jsx\"",
10
- "dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch"
9
+ "dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch",
10
+ "format": "prettier --write .",
11
+ "lint": "biome lint --max-diagnostics=5000 ."
11
12
  },
12
13
  "peerDependencies": {
13
14
  "react": "18.2.0",
14
15
  "react-dom": "18.2.0"
15
16
  },
16
17
  "dependencies": {
17
- "react-dropzone": "^11.0.1",
18
+ "react-dropzone": "14.2.3",
18
19
  "ui": "*"
19
20
  },
20
21
  "devDependencies": {
22
+ "@biomejs/biome": "1.5.2",
21
23
  "@types/react": "17.0.37",
22
24
  "@types/react-dom": "17.0.11",
23
- "eslint": "7.32.0",
24
- "eslint-config-custom": "*",
25
+ "prettier": "3.2.4",
25
26
  "react": "18.2.0",
26
27
  "tsconfig": "*",
27
28
  "tsup": "6.5.0",
@@ -15,8 +15,8 @@ const patch = (url, params = {}, opts = {}) =>
15
15
  credentials: "same-origin",
16
16
  body: JSON.stringify(params),
17
17
  },
18
- opts
19
- )
18
+ opts,
19
+ ),
20
20
  );
21
21
 
22
22
  const post = (url, params = {}, opts = {}) =>
@@ -28,8 +28,8 @@ const post = (url, params = {}, opts = {}) =>
28
28
  credentials: "same-origin",
29
29
  body: JSON.stringify(params),
30
30
  },
31
- opts
32
- )
31
+ opts,
32
+ ),
33
33
  );
34
34
 
35
35
  const del = (url, params = {}, opts = {}) =>
@@ -41,8 +41,8 @@ const del = (url, params = {}, opts = {}) =>
41
41
  credentials: "same-origin",
42
42
  body: JSON.stringify(params),
43
43
  },
44
- opts
45
- )
44
+ opts,
45
+ ),
46
46
  );
47
47
 
48
48
  export default class MediaManager {
@@ -69,7 +69,7 @@ export default class MediaManager {
69
69
  patch(
70
70
  `${this.baseUrl}images/${image.id}`,
71
71
  { image: params },
72
- { headers: { "content-type": "application/json" } }
72
+ { headers: { "content-type": "application/json" } },
73
73
  )
74
74
  .then((r) => r.json())
75
75
  .then((image) => callback(image));
@@ -79,7 +79,7 @@ export default class MediaManager {
79
79
  del(
80
80
  `${this.baseUrl}images/${image.id}`,
81
81
  {},
82
- { headers: { "content-type": "application/json" } }
82
+ { headers: { "content-type": "application/json" } },
83
83
  )
84
84
  .then((r) => r.json())
85
85
  .then((image) => callback(image));
package/src/index.js CHANGED
@@ -1,18 +1,6 @@
1
1
  import ImagePicker from "./pickers/ImagePicker/ImagePicker";
2
2
  import ImageInput from "./pickers/ImagePicker/ImageInput";
3
- import Img from "./lib/Image";
4
- import imageSrc from "./helpers/imageSrc";
5
- import imagePlaceholder from "./helpers/imagePlaceholder";
6
3
  import MediaManager from "./MediaManager";
7
4
  import MediaManagerContext from "./MediaManagerContext";
8
5
 
9
- export {
10
- ImagePicker,
11
- ImageInput,
12
- Img,
13
- Img as Image,
14
- imageSrc,
15
- imagePlaceholder,
16
- MediaManager,
17
- MediaManagerContext,
18
- };
6
+ export { ImagePicker, ImageInput, MediaManager, MediaManagerContext };
@@ -7,7 +7,7 @@ const removeByIndex = (items, idx) => [
7
7
  const removeById = (items, id, idField = "id") =>
8
8
  removeByIndex(
9
9
  items,
10
- items.findIndex((current) => current[idField] === id)
10
+ items.findIndex((current) => current[idField] === id),
11
11
  );
12
12
  const updateFieldByIndex = (items, field, value, idx) => [
13
13
  ...items.slice(0, idx),
@@ -19,7 +19,7 @@ const updateFieldById = (items, field, value, id, idField = "id") =>
19
19
  items,
20
20
  field,
21
21
  value,
22
- items.findIndex((current) => current[idField] === id)
22
+ items.findIndex((current) => current[idField] === id),
23
23
  );
24
24
  const reorder = (items, order) => order.map((idx) => items[idx]);
25
25
 
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { Button, Stack, H, cn } from "@raketa-builder/ui";
3
- import Img from "../../lib/Image";
3
+ import Image from "@raketa-builder/support";
4
4
  import TextInput from "../../forms/TextInput";
5
5
 
6
6
  const ImageList = ({ className, ...rest }) => (
@@ -45,10 +45,11 @@ const ImageItem = ({ image, selected, onSelect, onFastSelect }) => (
45
45
  onDoubleClick={() => onFastSelect(image)}
46
46
  >
47
47
  <ImageWrapper title={image.name}>
48
- <Img
48
+ <Image
49
49
  src={getPreviewImage(image)}
50
50
  variant="thumb"
51
51
  title={image && image.name}
52
+ alt=""
52
53
  />
53
54
  </ImageWrapper>
54
55
  </Thumb>
@@ -82,7 +83,7 @@ const ImagePreview = ({ image, onDelete }) => {
82
83
  return (
83
84
  <ImageInspector>
84
85
  <ImagePreviewWrapper>
85
- <Img src={image} variant="original" />
86
+ <Image src={image} variant="original" alt="" />
86
87
 
87
88
  {isImageEditable(image) && (
88
89
  <React.Fragment>
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { cn } from "@raketa-builder/ui";
3
- import Img from "../../lib/Image";
3
+ import Image from "@raketa-builder/support";
4
4
  import TextInput from "../../forms/TextInput";
5
5
  import Dialog from "../../dialogs/Dialog";
6
6
  import BrowseTab from "./BrowseTab";
@@ -181,7 +181,9 @@ const ImagePicker = ({
181
181
  <div>
182
182
  <ImageControl>
183
183
  <ImageWrapper>
184
- {image && <Img src={image} variant="thumb" title={image.name} />}
184
+ {image && (
185
+ <Image src={image} variant="thumb" title={image.name} alt="" />
186
+ )}
185
187
 
186
188
  {!image && <ImagePlaceholder />}
187
189
  </ImageWrapper>
package/src/styles.css CHANGED
@@ -98,7 +98,11 @@
98
98
  linear-gradient(225deg, #eee 25%, transparent 25%),
99
99
  linear-gradient(45deg, #eee 25%, transparent 25%),
100
100
  linear-gradient(315deg, #eee 25%, #ffffff 25%);
101
- background-position: 10px 0, 10px 0, 0 0, 0 0;
101
+ background-position:
102
+ 10px 0,
103
+ 10px 0,
104
+ 0 0,
105
+ 0 0;
102
106
  background-size: 20px 20px;
103
107
  background-repeat: repeat;
104
108
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "tsconfig/react-library.json",
3
3
  "include": ["src"],
4
- "exclude": ["dist", "build", "node_modules"]
4
+ "exclude": ["dist", "build", "node_modules"],
5
5
  }
@@ -1,5 +0,0 @@
1
- const imgPlaceholder = (size) => {
2
- return `https://placeholder.raketa.cloud/images/${size}`;
3
- };
4
-
5
- export default imgPlaceholder;
@@ -1,17 +0,0 @@
1
- const imgageSrc = (src, variant) => {
2
- if (typeof src === "object" && !("name" in src))
3
- console.warn(`WARNING: Image with empty {}: ${variant}`);
4
-
5
- if (
6
- typeof src === "object" &&
7
- "name" in src &&
8
- (src.name.includes(".svg") || src.name.includes(".gif"))
9
- )
10
- return src.urls.original;
11
- if (typeof src === "object" && "name" in src) return src.urls[variant];
12
- if (typeof src === "string") return src;
13
-
14
- return null;
15
- };
16
-
17
- export default imgageSrc;
package/src/lib/Image.js DELETED
@@ -1,123 +0,0 @@
1
- import React from "react";
2
-
3
- const getWebp = (url) => {
4
- if (!url) return null;
5
-
6
- const segments = url.split(".");
7
- segments[segments.length - 1] = "webp";
8
-
9
- return segments.join(".");
10
- };
11
-
12
- const getDimensions = (src, variant) => {
13
- if (typeof src === "object" && src?.name?.includes(".svg")) {
14
- const width = src.width;
15
- const height = src.height;
16
-
17
- return [width, height];
18
- }
19
-
20
- if (typeof src === "object") {
21
- const width = src.sizes[variant]?.width || null;
22
- const height = src.sizes[variant]?.height || null;
23
-
24
- return [width, height];
25
- }
26
-
27
- return [null, null];
28
- };
29
-
30
- const getAlt = (src) => {
31
- const type = typeof src;
32
-
33
- if (type === "object" && src.alt) {
34
- return src.alt;
35
- }
36
-
37
- if (type === "object") {
38
- const imageObj = src.image || src;
39
-
40
- const altSetting = (imageObj?.settings || []).find(
41
- (setting) => setting.key === "alt"
42
- );
43
-
44
- if (altSetting) {
45
- return altSetting.value;
46
- }
47
- }
48
-
49
- return "";
50
- };
51
-
52
- const getSrc = (src, variant) => {
53
- if (typeof src === "object") {
54
- if (src?.name?.includes(".svg") || src?.name?.includes(".gif")) {
55
- return [null, src.urls?.original];
56
- }
57
-
58
- const fallback = src.urls[variant];
59
- const webp = getWebp(fallback);
60
-
61
- return [webp, fallback];
62
- }
63
-
64
- return [null, src];
65
- };
66
-
67
- const getImageObjOrSrc = (value) => {
68
- const type = typeof value;
69
-
70
- if (type === "object" && value.hasOwnProperty("image")) {
71
- return value.image;
72
- }
73
-
74
- return value;
75
- };
76
-
77
- const Image = ({ variant, src, alt, loading, ...props }) => {
78
- if (!variant) {
79
- console.error("Image with no variant", { variant, src, alt, props });
80
- return null;
81
- }
82
-
83
- if (!src) {
84
- console.error("Image with no src", { variant, src, alt, props });
85
- return null;
86
- }
87
-
88
- const imageObjOrSrc = getImageObjOrSrc(src);
89
-
90
- if (
91
- imageObjOrSrc &&
92
- typeof imageObjOrSrc === "object" &&
93
- !imageObjOrSrc.sizes
94
- ) {
95
- console.error("Image with no sizes", { variant, src, alt, props });
96
- return null;
97
- }
98
-
99
- const [width, height] = getDimensions(imageObjOrSrc, variant);
100
- const altAttr = alt || getAlt(src);
101
- const [webp, fallback] = getSrc(imageObjOrSrc, variant);
102
-
103
- return (
104
- <picture>
105
- {webp && <source srcSet={encodeURI(webp)} type="image/webp" />}
106
- <source srcSet={encodeURI(fallback)} type={src.mime_type} />
107
- <img
108
- src={fallback}
109
- alt={altAttr}
110
- width={width}
111
- height={height}
112
- loading={loading}
113
- {...props}
114
- />
115
- </picture>
116
- );
117
- };
118
-
119
- Image.defaultProps = {
120
- loading: "lazy",
121
- };
122
-
123
- export default Image;