@raketa-builder/image-input 0.2.0 → 0.4.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/.turbo/turbo-build.log +2 -2
- package/.turbo/turbo-lint.log +10 -10
- package/dist/index.js +553 -842
- package/package.json +1 -2
- package/src/dialogs/Dialog.js +13 -13
- package/src/lib/Dropbox.js +14 -19
- package/src/lib/Image.js +4 -4
- package/src/lib/ProgressBar.js +13 -13
- package/src/pickers/ImagePicker/BrowseTab.js +36 -53
- package/src/pickers/ImagePicker/ImageInput.js +13 -17
- package/src/pickers/ImagePicker/ImagePicker.js +21 -31
- package/src/pickers/ImagePicker/UploadTab.js +7 -5
- package/src/styles.css +126 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raketa-builder/image-input",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
"dev": "tsup src/index.js --format cjs --loader \".js=jsx\" --watch"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"styled-components": "^5.1.0",
|
|
14
13
|
"react": "18.2.0",
|
|
15
14
|
"react-dom": "18.2.0"
|
|
16
15
|
},
|
package/src/dialogs/Dialog.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
3
|
-
import { Modal, Button } from "@raketa-builder/ui";
|
|
2
|
+
import { Modal, Button, cn } from "@raketa-builder/ui";
|
|
4
3
|
|
|
5
|
-
const ModalContent =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const ModalContent = ({ className, ...rest }) => (
|
|
5
|
+
<div
|
|
6
|
+
className={cn("r-reset", "r-image-picker-modal-content", className)}
|
|
7
|
+
{...rest}
|
|
8
|
+
/>
|
|
9
|
+
);
|
|
9
10
|
|
|
10
|
-
const ModalFooter =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const ModalFooter = ({ className, ...rest }) => (
|
|
12
|
+
<div
|
|
13
|
+
className={cn("r-reset", "r-image-picker-modal-footer", className)}
|
|
14
|
+
{...rest}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
14
17
|
|
|
15
18
|
const Dialog = ({
|
|
16
|
-
open,
|
|
17
19
|
onClose,
|
|
18
20
|
title,
|
|
19
21
|
children,
|
|
20
22
|
primaryLabel,
|
|
21
23
|
secondaryLabel = "Cancel",
|
|
22
24
|
onPrimary,
|
|
23
|
-
width,
|
|
24
|
-
dialogSize,
|
|
25
25
|
}) => (
|
|
26
26
|
<Modal title={title} onClose={onClose}>
|
|
27
27
|
<ModalContent>{children}</ModalContent>
|
package/src/lib/Dropbox.js
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
3
|
-
import { H, Button } from "@raketa-builder/ui";
|
|
2
|
+
import { H, Button, cn } from "@raketa-builder/ui";
|
|
4
3
|
|
|
5
4
|
import Dropzone from "react-dropzone";
|
|
6
5
|
|
|
7
|
-
const StyledDropzone =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
bottom: 0;
|
|
21
|
-
left: 0;
|
|
22
|
-
padding: 16px;
|
|
23
|
-
`;
|
|
6
|
+
const StyledDropzone = ({ className, ...rest }) => (
|
|
7
|
+
<div
|
|
8
|
+
className={cn("r-reset", "r-image-picker-dropzone", className)}
|
|
9
|
+
{...rest}
|
|
10
|
+
/>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const DropzoneLabel = ({ className, ...rest }) => (
|
|
14
|
+
<div
|
|
15
|
+
className={cn("r-reset", "r-image-picker-dropzone-label", className)}
|
|
16
|
+
{...rest}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
24
19
|
|
|
25
20
|
const Dropbox = ({ buttonLabel, onDrop }) => {
|
|
26
21
|
const dropzoneRef = React.createRef();
|
package/src/lib/Image.js
CHANGED
|
@@ -18,8 +18,8 @@ const getDimensions = (src, variant) => {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
if (typeof src === "object") {
|
|
21
|
-
const width = src.sizes[variant]
|
|
22
|
-
const height = src.sizes[variant]
|
|
21
|
+
const width = src.sizes[variant]?.width || null;
|
|
22
|
+
const height = src.sizes[variant]?.height || null;
|
|
23
23
|
|
|
24
24
|
return [width, height];
|
|
25
25
|
}
|
|
@@ -37,7 +37,7 @@ const getAlt = (src) => {
|
|
|
37
37
|
if (type === "object") {
|
|
38
38
|
const imageObj = src.image || src;
|
|
39
39
|
|
|
40
|
-
const altSetting = imageObj
|
|
40
|
+
const altSetting = (imageObj?.settings || []).find(
|
|
41
41
|
(setting) => setting.key === "alt"
|
|
42
42
|
);
|
|
43
43
|
|
|
@@ -52,7 +52,7 @@ const getAlt = (src) => {
|
|
|
52
52
|
const getSrc = (src, variant) => {
|
|
53
53
|
if (typeof src === "object") {
|
|
54
54
|
if (src?.name?.includes(".svg") || src?.name?.includes(".gif")) {
|
|
55
|
-
return [null, src.urls
|
|
55
|
+
return [null, src.urls?.original];
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const fallback = src.urls[variant];
|
package/src/lib/ProgressBar.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { cn } from "@raketa-builder/ui";
|
|
3
3
|
|
|
4
|
-
const ProgressWrapper =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const ProgressWrapper = ({ className, ...rest }) => (
|
|
5
|
+
<div
|
|
6
|
+
className={cn("r-reset", "r-image-picker-progress-wrapper", className)}
|
|
7
|
+
{...resst}
|
|
8
|
+
/>
|
|
9
|
+
);
|
|
8
10
|
|
|
9
|
-
const Progress =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
background-color: #4cae4c;
|
|
16
|
-
`;
|
|
11
|
+
const Progress = ({ className, ...rest }) => (
|
|
12
|
+
<div
|
|
13
|
+
className={cn("r-reset", "r-image-picker-progress", className)}
|
|
14
|
+
{...resst}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
17
|
|
|
18
18
|
const ProgressBar = ({ total, done }) => {
|
|
19
19
|
const progress = (100 / total) * done;
|
|
@@ -1,43 +1,31 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { reset, Button, Stack, H } from "@raketa-builder/ui";
|
|
5
|
-
|
|
2
|
+
import { Button, Stack, H, cn } from "@raketa-builder/ui";
|
|
6
3
|
import Img from "../../lib/Image";
|
|
7
4
|
import TextInput from "../../forms/TextInput";
|
|
8
5
|
|
|
9
|
-
const ImageList =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
height: 100px;
|
|
33
|
-
background-color: ${(props) => props.theme.colors.lighterGray};
|
|
34
|
-
|
|
35
|
-
img {
|
|
36
|
-
display: block;
|
|
37
|
-
max-width: 100%;
|
|
38
|
-
height: 100%;
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
6
|
+
const ImageList = ({ className, ...rest }) => (
|
|
7
|
+
<div
|
|
8
|
+
className={cn("r-reset", "r-image-picker-image-list", className)}
|
|
9
|
+
{...rest}
|
|
10
|
+
/>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const Thumb = ({ className, ...rest }) => (
|
|
14
|
+
<div
|
|
15
|
+
className={cn("r-reset", "r-image-picker-thumb", className)}
|
|
16
|
+
{...rest}
|
|
17
|
+
style={{
|
|
18
|
+
borderColor: rest.selected ? "var(--r-success)" : "transparent",
|
|
19
|
+
}}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const ImageWrapper = ({ className, ...rest }) => (
|
|
24
|
+
<div
|
|
25
|
+
className={cn("r-reset", "r-image-picker-image-wrapper", className)}
|
|
26
|
+
{...rest}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
41
29
|
|
|
42
30
|
const getPreviewImage = (image) => {
|
|
43
31
|
const LARGE_FILE_TRESHOLD = 2 * 1024 * 1024;
|
|
@@ -66,24 +54,19 @@ const ImageItem = ({ image, selected, onSelect, onFastSelect }) => (
|
|
|
66
54
|
</Thumb>
|
|
67
55
|
);
|
|
68
56
|
|
|
69
|
-
const ImagePreviewWrapper =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
object-fit: contain;
|
|
76
|
-
width: 100%;
|
|
77
|
-
max-height: 200px;
|
|
78
|
-
margin-bottom: 0.5rem;
|
|
79
|
-
}
|
|
80
|
-
`;
|
|
57
|
+
const ImagePreviewWrapper = ({ className, ...rest }) => (
|
|
58
|
+
<div
|
|
59
|
+
className={cn("r-reset", "r-image-picker-image-preview-wrapper", className)}
|
|
60
|
+
{...rest}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
81
63
|
|
|
82
|
-
const ImageInspector =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
64
|
+
const ImageInspector = ({ className, ...rest }) => (
|
|
65
|
+
<div
|
|
66
|
+
className={cn("r-reset", "r-image-picker-image-inspector", className)}
|
|
67
|
+
{...rest}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
87
70
|
|
|
88
71
|
const isImageEditable = (image) => {
|
|
89
72
|
if (!image) return false;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ThemeProvider } from "styled-components";
|
|
3
|
-
import { theme } from "@raketa-builder/ui";
|
|
4
2
|
|
|
5
3
|
import ImagePicker from "./ImagePicker";
|
|
6
4
|
|
|
@@ -24,21 +22,19 @@ class ImageInput extends React.Component {
|
|
|
24
22
|
const { selectedImage } = this.state;
|
|
25
23
|
|
|
26
24
|
return (
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</div>
|
|
41
|
-
</ThemeProvider>
|
|
25
|
+
<div>
|
|
26
|
+
<ImagePicker
|
|
27
|
+
mediaManager={mediaManager}
|
|
28
|
+
value={selectedImage}
|
|
29
|
+
onChange={(selectedImage) => this.handleChange(selectedImage)}
|
|
30
|
+
/>
|
|
31
|
+
|
|
32
|
+
<input
|
|
33
|
+
type="hidden"
|
|
34
|
+
name={name}
|
|
35
|
+
value={selectedImage ? selectedImage.id : ""}
|
|
36
|
+
/>
|
|
37
|
+
</div>
|
|
42
38
|
);
|
|
43
39
|
}
|
|
44
40
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { cn } from "@raketa-builder/ui";
|
|
4
3
|
import Img from "../../lib/Image";
|
|
5
4
|
import TextInput from "../../forms/TextInput";
|
|
6
5
|
import Dialog from "../../dialogs/Dialog";
|
|
@@ -12,35 +11,26 @@ import { FormGroup, Label, Button, Tabs, Stack } from "@raketa-builder/ui";
|
|
|
12
11
|
import { removeById } from "../../lists";
|
|
13
12
|
import MediaManagerContext from "../../MediaManagerContext";
|
|
14
13
|
|
|
15
|
-
const ImagePlaceholder =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
height: 100px;
|
|
36
|
-
background-color: #ddd;
|
|
37
|
-
}
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
const ImageControl = styled.div`
|
|
41
|
-
display: flex;
|
|
42
|
-
margin-bottom: 16px;
|
|
43
|
-
`;
|
|
14
|
+
const ImagePlaceholder = ({ className, ...rest }) => (
|
|
15
|
+
<div
|
|
16
|
+
className={cn("r-reset", "r-image-picker-placeholder", className)}
|
|
17
|
+
{...rest}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const ImageWrapper = ({ className, ...rest }) => (
|
|
22
|
+
<div
|
|
23
|
+
className={cn("r-reset", "r-image-picker-image-wrapper-2", className)}
|
|
24
|
+
{...rest}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const ImageControl = ({ className, ...rest }) => (
|
|
29
|
+
<div
|
|
30
|
+
className={cn("r-reset", "r-image-picker-image-control", className)}
|
|
31
|
+
{...rest}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
44
34
|
|
|
45
35
|
const fetchImage = (value) => {
|
|
46
36
|
if (!value) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { cn } from "@raketa-builder/ui";
|
|
3
3
|
import Dropbox from "../../lib/Dropbox";
|
|
4
4
|
import ProgressBar from "../../lib/ProgressBar";
|
|
5
5
|
|
|
@@ -18,10 +18,12 @@ const FileList = ({ files }) => (
|
|
|
18
18
|
</div>
|
|
19
19
|
);
|
|
20
20
|
|
|
21
|
-
const ImageUploader =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const ImageUploader = ({ className, ...rest }) => (
|
|
22
|
+
<div
|
|
23
|
+
className={cn("r-reset", "r-image-picker-image-uploader", className)}
|
|
24
|
+
{...rest}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
25
27
|
|
|
26
28
|
class UploadTab extends React.Component {
|
|
27
29
|
isUploading() {
|
package/src/styles.css
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
@layer raketa-builder {
|
|
2
|
+
.r-image-picker-modal-content {
|
|
3
|
+
max-height: 75vh;
|
|
4
|
+
overflow-y: auto;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.r-image-picker-modal-footer {
|
|
8
|
+
padding-top: 1rem;
|
|
9
|
+
border-top: 1px solid var(--r-gray);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.r-image-picker-dropzone {
|
|
13
|
+
position: relative;
|
|
14
|
+
margin-bottom: 16px;
|
|
15
|
+
height: 350px;
|
|
16
|
+
color: #666;
|
|
17
|
+
background-color: #efefef;
|
|
18
|
+
border: 2px dashed #ddd;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.r-image-picker-dropzone-label {
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 0;
|
|
24
|
+
right: 0;
|
|
25
|
+
bottom: 0;
|
|
26
|
+
left: 0;
|
|
27
|
+
padding: 16px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.r-image-picker-progress-wrapper {
|
|
31
|
+
height: 2em;
|
|
32
|
+
background-color: #efefef;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.r-image-picker-progress {
|
|
36
|
+
padding-left: 0.5em;
|
|
37
|
+
height: 2.4em;
|
|
38
|
+
font-size: 0.85em;
|
|
39
|
+
line-height: 2.4em;
|
|
40
|
+
color: #fff;
|
|
41
|
+
background-color: #4cae4c;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.r-image-picker-image-list {
|
|
45
|
+
flex: 3;
|
|
46
|
+
display: flex;
|
|
47
|
+
flex-wrap: wrap;
|
|
48
|
+
align-content: flex-start;
|
|
49
|
+
margin-top: 1em;
|
|
50
|
+
min-height: 500px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.r-image-picker-thumb {
|
|
54
|
+
position: relative;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
width: 116px;
|
|
57
|
+
height: 116px;
|
|
58
|
+
border: 8px solid transparent;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.r-image-picker-image-wrapper {
|
|
62
|
+
width: 100px;
|
|
63
|
+
height: 100px;
|
|
64
|
+
background-color: var(--r-light-gray);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.r-image-picker-image-wrapper img {
|
|
68
|
+
display: block;
|
|
69
|
+
max-width: 100%;
|
|
70
|
+
height: 100%;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.r-image-picker-image-preview-wrapper {
|
|
74
|
+
width: 100%;
|
|
75
|
+
margin-bottom: 1rem;
|
|
76
|
+
text-align: center;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.r-image-picker-image-preview-wrapper img {
|
|
80
|
+
object-fit: contain;
|
|
81
|
+
width: 100%;
|
|
82
|
+
max-height: 200px;
|
|
83
|
+
margin-bottom: 0.5rem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.r-image-picker-image-inspector {
|
|
87
|
+
flex: 1;
|
|
88
|
+
padding-left: 1rem;
|
|
89
|
+
border-left: 1px solid var(--r-gray);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.r-image-picker-placeholder {
|
|
93
|
+
width: 100px;
|
|
94
|
+
height: 100px;
|
|
95
|
+
border: 1px solid #ddd;
|
|
96
|
+
background-color: #fff;
|
|
97
|
+
background: linear-gradient(135deg, #eee 25%, transparent 25%),
|
|
98
|
+
linear-gradient(225deg, #eee 25%, transparent 25%),
|
|
99
|
+
linear-gradient(45deg, #eee 25%, transparent 25%),
|
|
100
|
+
linear-gradient(315deg, #eee 25%, #ffffff 25%);
|
|
101
|
+
background-position: 10px 0, 10px 0, 0 0, 0 0;
|
|
102
|
+
background-size: 20px 20px;
|
|
103
|
+
background-repeat: repeat;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.r-image-picker-image-wrapper-2 {
|
|
107
|
+
margin-right: 16px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.r-image-picker-image-wrapper-2 img {
|
|
111
|
+
object-fit: contain;
|
|
112
|
+
width: 100px;
|
|
113
|
+
height: 100px;
|
|
114
|
+
background-color: #ddd;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.r-image-picker-image-control {
|
|
118
|
+
display: flex;
|
|
119
|
+
margin-bottom: 16px;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.r-image-picker-image-uploader {
|
|
123
|
+
margin-top: 16px;
|
|
124
|
+
min-height: 400px;
|
|
125
|
+
}
|
|
126
|
+
}
|