@raketa-builder/image-input 0.6.0 → 0.7.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/dist/index.js CHANGED
@@ -219,11 +219,11 @@ var require_dist = __commonJS({
219
219
  var import_react32 = __toESM2(require("react"));
220
220
  var import_jsx_runtime32 = require("react/jsx-runtime");
221
221
  var Button5 = (_a) => {
222
- var _b = _a, { type, size, variant, className } = _b, props = __objRest2(_b, ["type", "size", "variant", "className"]);
222
+ var _b = _a, { as = "button", size, variant, className } = _b, rest = __objRest2(_b, ["as", "size", "variant", "className"]);
223
+ const Component = as;
223
224
  return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
224
- "button",
225
+ Component,
225
226
  __spreadValues2({
226
- type,
227
227
  className: cn7(
228
228
  "r-reset",
229
229
  "r-reset-button",
@@ -232,7 +232,7 @@ var require_dist = __commonJS({
232
232
  `r-button-${variant}`,
233
233
  className
234
234
  )
235
- }, props)
235
+ }, rest)
236
236
  );
237
237
  };
238
238
  Button5.defaultProps = {
@@ -285,8 +285,8 @@ var require_dist = __commonJS({
285
285
  var import_react52 = __toESM2(require("react"));
286
286
  var import_jsx_runtime52 = require("react/jsx-runtime");
287
287
  var Input2 = (_a) => {
288
- var _b = _a, { className } = _b, props = __objRest2(_b, ["className"]);
289
- return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("input", __spreadValues2({ className: cn7("r-reset", "r-input", className) }, props));
288
+ var _b = _a, { className } = _b, rest = __objRest2(_b, ["className"]);
289
+ return /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("input", __spreadValues2({ className: cn7("r-reset", "r-input", className) }, rest));
290
290
  };
291
291
  var Input_default = Input2;
292
292
  var import_react62 = __toESM2(require("react"));
@@ -457,11 +457,28 @@ var require_dist = __commonJS({
457
457
  }, props)
458
458
  );
459
459
  };
460
+ var FooterBar = (_a) => {
461
+ var _b = _a, { className } = _b, props = __objRest2(_b, ["className"]);
462
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn7("r-reset", "r-modal-footer-bar", className) }, props));
463
+ };
460
464
  var Content = (_a) => {
461
465
  var _b = _a, { className } = _b, props = __objRest2(_b, ["className"]);
462
466
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues2({ className: cn7("r-reset", "r-modal-content", className) }, props));
463
467
  };
464
- var Modal2 = ({ title, children, onClose }) => {
468
+ var Modal2 = (_a) => {
469
+ var _b = _a, {
470
+ title,
471
+ children,
472
+ customWrapper,
473
+ FooterContent,
474
+ onClose
475
+ } = _b, rest = __objRest2(_b, [
476
+ "title",
477
+ "children",
478
+ "customWrapper",
479
+ "FooterContent",
480
+ "onClose"
481
+ ]);
465
482
  const handleKeyUp = ({ key }) => {
466
483
  if (key === "Escape")
467
484
  onClose();
@@ -472,15 +489,17 @@ var require_dist = __commonJS({
472
489
  document.removeEventListener("keyup", handleKeyUp);
473
490
  };
474
491
  });
492
+ const ModalWrapper = customWrapper ? customWrapper : Wrapper;
475
493
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_react17.default.Fragment, { children: [
476
494
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Overlay, { onClick: onClose }),
477
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Wrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Inner, { children: [
495
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModalWrapper, __spreadProps2(__spreadValues2({}, rest), { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Inner, { children: [
478
496
  /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(TitleBar, { children: [
479
497
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Title, { children: title }),
480
498
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CloseButton, { type: "button", onClick: onClose, children: "\xD7" })
481
499
  ] }),
482
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Content, { children })
483
- ] }) })
500
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Content, { children }),
501
+ FooterContent && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterBar, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterContent, {}) })
502
+ ] }) }))
484
503
  ] });
485
504
  };
486
505
  var Modal_default = Modal2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/image-input",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@
14
14
  "react-dom": "18.2.0"
15
15
  },
16
16
  "dependencies": {
17
- "react-dropzone": "^11.0.1",
17
+ "react-dropzone": "14.2.3",
18
18
  "ui": "*"
19
19
  },
20
20
  "devDependencies": {
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 };
@@ -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;