@majapisoftwares/ui 4.1.8 → 4.1.9

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.
@@ -9,6 +9,7 @@ export type FileFile = {
9
9
  name: string;
10
10
  type: string;
11
11
  size: number;
12
+ url: string;
12
13
  };
13
14
  export type FileUrl = {
14
15
  _id: string;
@@ -63,6 +63,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
63
63
  file,
64
64
  type: file.type,
65
65
  size: file.size,
66
+ url: URL.createObjectURL(file),
66
67
  })),
67
68
  ]);
68
69
  }
@@ -84,6 +85,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
84
85
  file,
85
86
  type: file.type,
86
87
  size: file.size,
88
+ url: URL.createObjectURL(file),
87
89
  });
88
90
  setInnerValue((value) => [...value, uploadedFile]);
89
91
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -103,13 +105,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
103
105
  onChange({
104
106
  target: {
105
107
  name,
106
- value: innerValue.map((file) => ({
107
- ...file,
108
- url: file.url ||
109
- (file.file
110
- ? URL.createObjectURL(file.file)
111
- : undefined),
112
- })),
108
+ value: innerValue,
113
109
  },
114
110
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
111
  });
@@ -11,25 +11,16 @@ import checkIsVideo from "./isVideo";
11
11
  import checkIsImage from "./isImage";
12
12
  import { isEqual } from "lodash-es";
13
13
  function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display = "info", additionalInfo, index, className, filesPerPage, currentPage, }) {
14
- const url = file.url ||
15
- (file.file
16
- ? URL.createObjectURL(file.file)
17
- : undefined);
18
- if (!url) {
19
- return (<div className={clsx("p-4 text-red-500", className)}>
20
- Error: No URL or file provided for preview.
21
- </div>);
22
- }
23
- const isVideo = file.type?.startsWith("video") || checkIsVideo(url);
24
- const isImage = file.type?.startsWith("image") || checkIsImage(url);
14
+ const isVideo = file.type?.startsWith("video") || checkIsVideo(file.url);
15
+ const isImage = file.type?.startsWith("image") || checkIsImage(file.url);
25
16
  if (display === "preview" && !isVideo && !isImage) {
26
17
  display = "info";
27
18
  }
28
19
  return (<div className={clsx("group relative flex flex-wrap items-center justify-center rounded-md bg-zinc-200 dark:bg-zinc-800", className)}>
29
20
  {["preview", "both"].includes(display) &&
30
- (isVideo ? (<video className="max-h-96 rounded-md" src={url} controls/>) : (
21
+ (isVideo ? (<video className="max-h-96 rounded-md" src={file.url} controls/>) : (
31
22
  // eslint-disable-next-line @next/next/no-img-element
32
- <img src={url} alt={file.description} className="max-h-96 rounded-md"/>))}
23
+ <img src={file.url} alt={file.description} className="max-h-96 rounded-md"/>))}
33
24
  {["info", "both"].includes(display) && (<Group className="w-full items-center gap-0">
34
25
  {display === "info" && (<div className="m-2 mr-0 rounded-lg bg-zinc-300 p-2 dark:bg-zinc-800">
35
26
  <DocumentIcon className="h-5 w-5"/>
@@ -42,11 +33,11 @@ function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText
42
33
  {file.description && <div>{file.description}</div>}
43
34
  <Text size="sm">{file.type}</Text>
44
35
  {!!file.size && (<Text size="sm">{numeral(file.size).format("0b")}</Text>)}
45
- {!url.startsWith("blob") && (<Group className="mr-auto">
46
- <Button leading={<ArrowTopRightOnSquareIcon />} href={url} target="_blank">
36
+ {!file.url.startsWith("blob") && (<Group className="mr-auto">
37
+ <Button leading={<ArrowTopRightOnSquareIcon />} href={file.url} target="_blank">
47
38
  {openText}
48
39
  </Button>
49
- <Button leading={<ArrowDownTrayIcon />} href={url} download={file.name}>
40
+ <Button leading={<ArrowDownTrayIcon />} href={file.url} download={file.name}>
50
41
  {downloadText}
51
42
  </Button>
52
43
  </Group>)}
package/package.json CHANGED
@@ -4,6 +4,6 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/majapisoftwares/ui.git"
6
6
  },
7
- "version": "4.1.8",
7
+ "version": "4.1.9",
8
8
  "type": "module"
9
9
  }