@majapisoftwares/ui 4.1.7 → 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;
@@ -47,4 +48,5 @@ declare function FileInput<PFP extends object>({ error, className, helpText, onC
47
48
  previewFileProps?: PFP;
48
49
  }): import("react").JSX.Element;
49
50
  export type FileInputProps = ComponentPropsWithRef<typeof FileInput>;
50
- export default FileInput;
51
+ declare const _default: typeof FileInput;
52
+ export default _default;
@@ -1,12 +1,12 @@
1
1
  import clsx from "../../utils/clsx";
2
- import { useCallback, useEffect, useRef, useState, } from "react";
3
- import { useDeepCompareEffect, useUpdateEffect } from "react-use";
2
+ import { memo, useCallback, useEffect, useMemo, useRef, useState, } from "react";
3
+ import { useDeepCompareEffect } from "react-use";
4
4
  import { defaultHelpTextClassName, defaultLabelClassName, } from "../Input";
5
5
  import FileSelect from "../FileSelect";
6
6
  import isomorphicObjectId from "@majapisoftwares/next/utils/isomorphicObjectId";
7
7
  import { isEqual } from "lodash-es";
8
8
  import Text from "../Text";
9
- import { PreviewFile } from "./PreviewFile";
9
+ import PreviewFile from "./PreviewFile";
10
10
  import concurrentForOf from "@majapisoftwares/next/utils/concurrentForOf";
11
11
  import paginated from "@majapisoftwares/next/utils/paginated";
12
12
  import Pagination from "../Pagination";
@@ -14,7 +14,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
14
14
  const [uploading, setUploading] = useState(false);
15
15
  const [innerValue, setInnerValue] = useState(value || []);
16
16
  const [currentPage, setCurrentPage] = useState(1);
17
- const PreviewFileComponent = previewFileComponent || PreviewFile;
17
+ const PreviewFileComponent = useMemo(() => memo(previewFileComponent || PreviewFile, isEqual), [previewFileComponent]);
18
18
  const paginatedValue = paginated(innerValue, currentPage - 1, filesPerPage);
19
19
  useEffect(() => {
20
20
  const totalPages = Math.ceil(innerValue.length / filesPerPage);
@@ -26,7 +26,7 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
26
26
  if (value && !isEqual(value, innerValue)) {
27
27
  setInnerValue(value);
28
28
  }
29
- }, [{ value: value }]);
29
+ }, [{ value }]);
30
30
  const innerRef = useRef({
31
31
  get value() {
32
32
  return innerValue;
@@ -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
@@ -98,17 +100,12 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
98
100
  setUploading(false);
99
101
  }
100
102
  };
101
- useUpdateEffect(() => {
103
+ useDeepCompareEffect(() => {
102
104
  if (onChange) {
103
105
  onChange({
104
106
  target: {
105
107
  name,
106
- value: innerValue.map((file) => ({
107
- ...file,
108
- url: file.file
109
- ? URL.createObjectURL(file.file)
110
- : file.url,
111
- })),
108
+ value: innerValue,
112
109
  },
113
110
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
114
111
  });
@@ -141,4 +138,4 @@ function FileInput({ error, className, helpText, onChange, name, limit, label, i
141
138
  </div>)}
142
139
  </div>);
143
140
  }
144
- export default FileInput;
141
+ export default memo(FileInput, isEqual);
@@ -13,4 +13,6 @@ export type PreviewFileProps = {
13
13
  filesPerPage: number;
14
14
  currentPage: number;
15
15
  };
16
- export declare function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display, additionalInfo, index, className, filesPerPage, currentPage, }: PreviewFileProps): import("react").JSX.Element;
16
+ declare function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display, additionalInfo, index, className, filesPerPage, currentPage, }: PreviewFileProps): import("react").JSX.Element;
17
+ declare const _default: import("react").MemoExoticComponent<typeof PreviewFile>;
18
+ export default _default;
@@ -5,23 +5,22 @@ import Text from "../Text";
5
5
  import numeral from "numeral";
6
6
  import Button from "../Button";
7
7
  import { ArrowTopRightOnSquareIcon, TrashIcon, } from "@heroicons/react/20/solid";
8
+ import { memo } from "react";
8
9
  import clsx from "../../utils/clsx";
9
10
  import checkIsVideo from "./isVideo";
10
11
  import checkIsImage from "./isImage";
11
- export function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display = "info", additionalInfo, index, className, filesPerPage, currentPage, }) {
12
- const url = file.file
13
- ? URL.createObjectURL(file.file)
14
- : file.url;
15
- const isVideo = file.type?.startsWith("video") || checkIsVideo(url);
16
- const isImage = file.type?.startsWith("image") || checkIsImage(url);
12
+ import { isEqual } from "lodash-es";
13
+ function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, openText, display = "info", additionalInfo, index, className, filesPerPage, currentPage, }) {
14
+ const isVideo = file.type?.startsWith("video") || checkIsVideo(file.url);
15
+ const isImage = file.type?.startsWith("image") || checkIsImage(file.url);
17
16
  if (display === "preview" && !isVideo && !isImage) {
18
17
  display = "info";
19
18
  }
20
19
  return (<div className={clsx("group relative flex flex-wrap items-center justify-center rounded-md bg-zinc-200 dark:bg-zinc-800", className)}>
21
20
  {["preview", "both"].includes(display) &&
22
- (isVideo ? (<video className="max-h-96 rounded-md" src={url} controls/>) : (
21
+ (isVideo ? (<video className="max-h-96 rounded-md" src={file.url} controls/>) : (
23
22
  // eslint-disable-next-line @next/next/no-img-element
24
- <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"/>))}
25
24
  {["info", "both"].includes(display) && (<Group className="w-full items-center gap-0">
26
25
  {display === "info" && (<div className="m-2 mr-0 rounded-lg bg-zinc-300 p-2 dark:bg-zinc-800">
27
26
  <DocumentIcon className="h-5 w-5"/>
@@ -34,11 +33,11 @@ export function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, o
34
33
  {file.description && <div>{file.description}</div>}
35
34
  <Text size="sm">{file.type}</Text>
36
35
  {!!file.size && (<Text size="sm">{numeral(file.size).format("0b")}</Text>)}
37
- {!url.startsWith("blob") && (<Group className="mr-auto">
38
- <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">
39
38
  {openText}
40
39
  </Button>
41
- <Button leading={<ArrowDownTrayIcon />} href={url} download={file.name}>
40
+ <Button leading={<ArrowDownTrayIcon />} href={file.url} download={file.name}>
42
41
  {downloadText}
43
42
  </Button>
44
43
  </Group>)}
@@ -52,3 +51,4 @@ export function PreviewFile({ file, readOnly, handleDeleteClick, downloadText, o
52
51
  </Button>)}
53
52
  </div>);
54
53
  }
54
+ export default memo(PreviewFile, isEqual);
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.7",
7
+ "version": "4.1.9",
8
8
  "type": "module"
9
9
  }