@dashadmin/dash-admin 1.3.55 → 1.3.57

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.
@@ -1,44 +1,107 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1
20
  import { jsx, jsxs } from "react/jsx-runtime";
2
21
  import { IconButton } from "@mui/material";
3
22
  import { useState } from "react";
4
23
  import Edit from "@mui/icons-material/Edit";
5
24
  import Image from "@mui/icons-material/Image";
6
25
  const SingleImageUploader = (props) => {
7
- const { classNamePrefix = "default", currentUrl = "single-image-uploader", onChange } = props;
26
+ const {
27
+ classNamePrefix = "default",
28
+ currentUrl,
29
+ onChange,
30
+ disableDragAndDrop = false
31
+ } = props;
8
32
  const [localFile, setLocalFile] = useState(null);
9
- return /* @__PURE__ */ jsxs("div", { className: `single-image-uploader ${classNamePrefix}-img`, children: [
10
- localFile || currentUrl ? /* @__PURE__ */ jsx("img", { src: localFile || currentUrl, alt: "" }) : /* @__PURE__ */ jsx("div", { className: `${classNamePrefix}-icon`, children: /* @__PURE__ */ jsx(Image, {}) }),
11
- /* @__PURE__ */ jsxs(
12
- IconButton,
13
- {
14
- "aria-label": "upload image",
15
- component: "label",
16
- className: `${classNamePrefix}-edit`,
17
- children: [
18
- /* @__PURE__ */ jsx(
19
- "input",
20
- {
21
- hidden: true,
22
- accept: "image/*",
23
- type: "file",
24
- onChange: (e) => {
25
- setLocalFile(URL.createObjectURL(e.target.files[0]));
26
- if (onChange) {
27
- onChange(e.target.files[0]);
33
+ const [isDragging, setIsDragging] = useState(false);
34
+ const acceptFile = (file) => {
35
+ var _a;
36
+ if (!file) return;
37
+ if (!((_a = file.type) == null ? void 0 : _a.startsWith("image/"))) return;
38
+ setLocalFile(URL.createObjectURL(file));
39
+ onChange == null ? void 0 : onChange(file);
40
+ };
41
+ const dragHandlers = disableDragAndDrop ? {} : {
42
+ onDragEnter: (e) => {
43
+ e.preventDefault();
44
+ e.stopPropagation();
45
+ setIsDragging(true);
46
+ },
47
+ // Both dragOver AND dragEnter must preventDefault, or the browser
48
+ // navigates away to the dropped file instead of firing onDrop.
49
+ onDragOver: (e) => {
50
+ e.preventDefault();
51
+ e.stopPropagation();
52
+ setIsDragging(true);
53
+ },
54
+ onDragLeave: (e) => {
55
+ e.preventDefault();
56
+ e.stopPropagation();
57
+ if (e.currentTarget.contains(e.relatedTarget)) return;
58
+ setIsDragging(false);
59
+ },
60
+ onDrop: (e) => {
61
+ var _a, _b;
62
+ e.preventDefault();
63
+ e.stopPropagation();
64
+ setIsDragging(false);
65
+ acceptFile((_b = (_a = e.dataTransfer) == null ? void 0 : _a.files) == null ? void 0 : _b[0]);
66
+ }
67
+ };
68
+ return /* @__PURE__ */ jsxs(
69
+ "div",
70
+ __spreadProps(__spreadValues({
71
+ className: [
72
+ "single-image-uploader",
73
+ `${classNamePrefix}-img`,
74
+ isDragging ? "is-dragging" : ""
75
+ ].filter(Boolean).join(" ")
76
+ }, dragHandlers), {
77
+ children: [
78
+ localFile || currentUrl ? /* @__PURE__ */ jsx("img", { src: localFile || currentUrl, alt: "" }) : /* @__PURE__ */ jsx("div", { className: `${classNamePrefix}-icon`, children: /* @__PURE__ */ jsx(Image, {}) }),
79
+ /* @__PURE__ */ jsxs(
80
+ IconButton,
81
+ {
82
+ "aria-label": "upload image",
83
+ component: "label",
84
+ className: `${classNamePrefix}-edit`,
85
+ children: [
86
+ /* @__PURE__ */ jsx(
87
+ "input",
88
+ {
89
+ hidden: true,
90
+ accept: "image/*",
91
+ type: "file",
92
+ onChange: (e) => {
93
+ var _a;
94
+ return acceptFile((_a = e.target.files) == null ? void 0 : _a[0]);
95
+ }
28
96
  }
29
- }
30
- }
31
- ),
32
- /* @__PURE__ */ jsx(
33
- Edit,
34
- {
35
- style: { opacity: "0.6" }
36
- }
37
- )
38
- ]
39
- }
40
- )
41
- ] });
97
+ ),
98
+ /* @__PURE__ */ jsx(Edit, { style: { opacity: "0.6" } })
99
+ ]
100
+ }
101
+ )
102
+ ]
103
+ })
104
+ );
42
105
  };
43
106
  var SingleImageUploader_default = SingleImageUploader;
44
107
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashadmin/dash-admin",
3
- "version": "1.3.55",
3
+ "version": "1.3.57",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -46,7 +46,7 @@
46
46
  "framer-motion": "latest",
47
47
  "prop-types": "latest",
48
48
  "query-string": "latest",
49
- "ra-input-rich-text": "5.14.6",
49
+ "ra-input-rich-text": "5.15.1",
50
50
  "react": "19.2.8",
51
51
  "react-admin": "5.15.1",
52
52
  "react-custom-scrollbars-2": "latest",
@@ -1,53 +1,107 @@
1
- import { IconButton} from "@mui/material";
1
+ import { IconButton } from "@mui/material";
2
2
  import { FC, useState } from "react";
3
- import Edit from "@mui/icons-material/Edit";
4
- import Image from "@mui/icons-material/Image";
3
+ import Edit from "@mui/icons-material/Edit";
4
+ import Image from "@mui/icons-material/Image";
5
5
  import React from "react";
6
+
6
7
  export interface ISingleImageUploader {
7
8
  classNamePrefix?: string;
8
9
  currentUrl?: string;
9
- onChange?: (file:File) => void
10
+ onChange?: (file: File) => void;
11
+ /** Disable drag & drop, leaving only the click-to-browse button. */
12
+ disableDragAndDrop?: boolean;
10
13
  }
11
14
 
12
- const SingleImageUploader:FC<ISingleImageUploader> = (props) => {
13
-
14
- const {classNamePrefix = 'default',currentUrl = 'single-image-uploader',onChange} = props;
15
+ const SingleImageUploader: FC<ISingleImageUploader> = (props) => {
16
+ // NOTE: currentUrl deliberately defaults to undefined, NOT to the string
17
+ // 'single-image-uploader' as it once did — that default was always truthy, so
18
+ // the `<Image />` placeholder branch below could never run and an uploader
19
+ // with no image rendered a broken <img> instead of the icon.
20
+ const {
21
+ classNamePrefix = 'default',
22
+ currentUrl,
23
+ onChange,
24
+ disableDragAndDrop = false,
25
+ } = props;
15
26
 
16
27
  const [localFile, setLocalFile] = useState(null);
28
+ const [isDragging, setIsDragging] = useState(false);
17
29
 
18
- return <div className={`single-image-uploader ${classNamePrefix}-img`}>
19
- {localFile || currentUrl ? (
20
- <img src={localFile || currentUrl} alt='' />
21
- ) : (
22
- <div className={`${classNamePrefix}-icon`}>
23
- <Image />
24
- </div>
25
- )}
26
- <IconButton
27
- aria-label='upload image'
28
- component='label'
29
- className={`${classNamePrefix}-edit`}
30
- >
31
- <input
32
- hidden
33
- accept='image/*'
34
- type='file'
35
- onChange={e => {
36
-
37
- setLocalFile(URL.createObjectURL(e.target.files[0]))
38
-
39
- if(onChange) {
40
- onChange(e.target.files[0])
41
- }
42
-
43
- }}
44
- />
45
-
46
- <Edit
47
- style={{ opacity: '0.6' }}
48
- />
49
- </IconButton>
50
- </div>
51
- }
30
+ /** Shared by the file input and the drop handler. */
31
+ const acceptFile = (file?: File) => {
32
+ // Guard: cancelling the file dialog fires change with an empty list.
33
+ if (!file) return;
34
+
35
+ // Dropping a non-image (a PDF, a folder) must not blank the current
36
+ // preview — ignore it and keep whatever is already there.
37
+ if (!file.type?.startsWith('image/')) return;
38
+
39
+ setLocalFile(URL.createObjectURL(file));
40
+ onChange?.(file);
41
+ };
42
+
43
+ const dragHandlers = disableDragAndDrop
44
+ ? {}
45
+ : {
46
+ onDragEnter: (e: React.DragEvent) => {
47
+ e.preventDefault();
48
+ e.stopPropagation();
49
+ setIsDragging(true);
50
+ },
51
+ // Both dragOver AND dragEnter must preventDefault, or the browser
52
+ // navigates away to the dropped file instead of firing onDrop.
53
+ onDragOver: (e: React.DragEvent) => {
54
+ e.preventDefault();
55
+ e.stopPropagation();
56
+ setIsDragging(true);
57
+ },
58
+ onDragLeave: (e: React.DragEvent) => {
59
+ e.preventDefault();
60
+ e.stopPropagation();
61
+ // Ignore leaves fired by moving over a CHILD element — without
62
+ // this the highlight flickers as the pointer crosses the img.
63
+ if (e.currentTarget.contains(e.relatedTarget as Node)) return;
64
+ setIsDragging(false);
65
+ },
66
+ onDrop: (e: React.DragEvent) => {
67
+ e.preventDefault();
68
+ e.stopPropagation();
69
+ setIsDragging(false);
70
+ acceptFile(e.dataTransfer?.files?.[0]);
71
+ },
72
+ };
73
+
74
+ return (
75
+ <div
76
+ className={[
77
+ 'single-image-uploader',
78
+ `${classNamePrefix}-img`,
79
+ isDragging ? 'is-dragging' : '',
80
+ ].filter(Boolean).join(' ')}
81
+ {...dragHandlers}
82
+ >
83
+ {localFile || currentUrl ? (
84
+ <img src={localFile || currentUrl} alt='' />
85
+ ) : (
86
+ <div className={`${classNamePrefix}-icon`}>
87
+ <Image />
88
+ </div>
89
+ )}
90
+ <IconButton
91
+ aria-label='upload image'
92
+ component='label'
93
+ className={`${classNamePrefix}-edit`}
94
+ >
95
+ <input
96
+ hidden
97
+ accept='image/*'
98
+ type='file'
99
+ onChange={e => acceptFile(e.target.files?.[0])}
100
+ />
101
+ <Edit style={{ opacity: '0.6' }} />
102
+ </IconButton>
103
+ </div>
104
+ );
105
+ };
52
106
 
53
- export default SingleImageUploader;
107
+ export default SingleImageUploader;