@powerhousedao/document-engineering 1.30.0 → 1.31.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/src/scalars/components/phone-number-field/phone-number-field.d.ts.map +1 -1
- package/dist/src/scalars/components/phone-number-field/phone-number-field.js +18 -2
- package/dist/src/scalars/components/phone-number-field/phone-number-field.js.map +1 -1
- package/dist/src/ui/components/data-entry/amount-input/amount-input.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/amount-input/amount-input.js +2 -2
- package/dist/src/ui/components/data-entry/amount-input/amount-input.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/examples/file-upload-item-example.d.ts +7 -0
- package/dist/src/ui/components/data-entry/file-input/examples/file-upload-item-example.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/examples/file-upload-item-example.js +64 -0
- package/dist/src/ui/components/data-entry/file-input/examples/file-upload-item-example.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/examples/index.d.ts +2 -0
- package/dist/src/ui/components/data-entry/file-input/examples/index.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/examples/index.js +2 -0
- package/dist/src/ui/components/data-entry/file-input/examples/index.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/file-input.js +1 -1
- package/dist/src/ui/components/data-entry/file-input/file-input.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/file-upload-item.d.ts +3 -3
- package/dist/src/ui/components/data-entry/file-input/sub-components/file-upload-item.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/file-upload-item.js +16 -9
- package/dist/src/ui/components/data-entry/file-input/sub-components/file-upload-item.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-corrupted.d.ts +9 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-corrupted.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-corrupted.js +10 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-corrupted.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-loading.d.ts +8 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-loading.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-loading.js +11 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-loading.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-unsupported.d.ts +6 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-unsupported.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-unsupported.js +8 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/placeholder-unsupported.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-audio.d.ts +8 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-audio.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-audio.js +8 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-audio.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-file.d.ts +2 -4
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-file.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-file.js +3 -8
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-file.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-header.d.ts +2 -2
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-header.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-header.js +1 -2
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-header.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-image.d.ts +2 -4
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-image.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-image.js +3 -8
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-image.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-video.d.ts +8 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-video.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-video.js +8 -0
- package/dist/src/ui/components/data-entry/file-input/sub-components/preview-video.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/types.d.ts +3 -5
- package/dist/src/ui/components/data-entry/file-input/types.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/types.js +1 -1
- package/dist/src/ui/components/data-entry/file-input/types.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/useFetchQuery.d.ts +11 -0
- package/dist/src/ui/components/data-entry/file-input/useFetchQuery.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/useFetchQuery.js +30 -0
- package/dist/src/ui/components/data-entry/file-input/useFetchQuery.js.map +1 -0
- package/dist/src/ui/components/data-entry/file-input/useUploadFile.d.ts +3 -4
- package/dist/src/ui/components/data-entry/file-input/useUploadFile.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/useUploadFile.js +30 -36
- package/dist/src/ui/components/data-entry/file-input/useUploadFile.js.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/utils.d.ts +32 -4
- package/dist/src/ui/components/data-entry/file-input/utils.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/file-input/utils.js +142 -57
- package/dist/src/ui/components/data-entry/file-input/utils.js.map +1 -1
- package/dist/src/ui/components/data-entry/number-input/number-input.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/number-input/number-input.js +5 -5
- package/dist/src/ui/components/data-entry/number-input/number-input.js.map +1 -1
- package/dist/src/ui/components/data-entry/number-input/types.d.ts +1 -0
- package/dist/src/ui/components/data-entry/number-input/types.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/phone-number-input/phone-number-input.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/phone-number-input/phone-number-input.js +3 -6
- package/dist/src/ui/components/data-entry/phone-number-input/phone-number-input.js.map +1 -1
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-diff.d.ts +15 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-diff.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-diff.js +117 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-diff.js.map +1 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-input-diff.d.ts +14 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-input-diff.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-input-diff.js +8 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/phone-number-input-diff.js.map +1 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/splitted-phone-number.d.ts +12 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/splitted-phone-number.d.ts.map +1 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/splitted-phone-number.js +9 -0
- package/dist/src/ui/components/data-entry/phone-number-input/subcomponents/splitted-phone-number.js.map +1 -0
- package/dist/src/ui/components/data-entry/phone-number-input/use-phone-number-input.d.ts.map +1 -1
- package/dist/src/ui/components/data-entry/phone-number-input/use-phone-number-input.js +37 -13
- package/dist/src/ui/components/data-entry/phone-number-input/use-phone-number-input.js.map +1 -1
- package/dist/src/ui/components/icon-components/BrokenAudio.d.ts +7 -0
- package/dist/src/ui/components/icon-components/BrokenAudio.d.ts.map +1 -0
- package/dist/src/ui/components/icon-components/BrokenAudio.js +7 -0
- package/dist/src/ui/components/icon-components/BrokenAudio.js.map +1 -0
- package/dist/src/ui/components/icon-components/BrokenVideo.d.ts +7 -0
- package/dist/src/ui/components/icon-components/BrokenVideo.d.ts.map +1 -0
- package/dist/src/ui/components/icon-components/BrokenVideo.js +7 -0
- package/dist/src/ui/components/icon-components/BrokenVideo.js.map +1 -0
- package/dist/src/ui/components/icon-components/PlaceholderAudio.d.ts +7 -0
- package/dist/src/ui/components/icon-components/PlaceholderAudio.d.ts.map +1 -0
- package/dist/src/ui/components/icon-components/PlaceholderAudio.js +7 -0
- package/dist/src/ui/components/icon-components/PlaceholderAudio.js.map +1 -0
- package/dist/src/ui/components/icon-components/PlaceholderVideo.d.ts +7 -0
- package/dist/src/ui/components/icon-components/PlaceholderVideo.d.ts.map +1 -0
- package/dist/src/ui/components/icon-components/PlaceholderVideo.js +7 -0
- package/dist/src/ui/components/icon-components/PlaceholderVideo.js.map +1 -0
- package/dist/src/ui/components/icon-components/index.d.ts +1 -1
- package/dist/src/ui/components/icon-components/index.d.ts.map +1 -1
- package/dist/src/ui/components/icon-components/index.js +12 -0
- package/dist/src/ui/components/icon-components/index.js.map +1 -1
- package/dist/src/ui/components/sidebar/subcomponents/sidebar-item.d.ts.map +1 -1
- package/dist/src/ui/components/sidebar/subcomponents/sidebar-item.js +2 -1
- package/dist/src/ui/components/sidebar/subcomponents/sidebar-item.js.map +1 -1
- package/dist/style.css +145 -12
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-image.d.ts +0 -9
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-image.d.ts.map +0 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-image.js +0 -13
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-image.js.map +0 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-pdf.d.ts +0 -9
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-pdf.d.ts.map +0 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-pdf.js +0 -13
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-pdf.js.map +0 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-unsupported.d.ts +0 -8
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-unsupported.d.ts.map +0 -1
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-unsupported.js +0 -11
- package/dist/src/ui/components/data-entry/file-input/sub-components/place-holder-unsupported.js.map +0 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cn } from '../../../../../scalars/lib/utils.js';
|
|
3
3
|
import { Icon } from '../../../icon/index.js';
|
|
4
|
-
import { PREVIEW_STATUS } from '../types.js';
|
|
5
4
|
const PreviewHeader = ({ status, onClose, title = 'File Preview' }) => {
|
|
6
|
-
return (_jsxs("header", { className: "flex justify-between items-center", children: [_jsx("span", { className: cn('text-gray-900 text-sm font-normal leading-4.5', status ===
|
|
5
|
+
return (_jsxs("header", { className: "flex justify-between items-center", children: [_jsx("span", { className: cn('text-gray-900 text-sm font-normal leading-4.5', status === 'error' && 'text-red-900'), children: title }), _jsx("button", { type: "button", onClick: onClose, "aria-label": "Close preview", className: "text-gray-400 hover:text-gray-600", children: _jsx(Icon, { name: "XmarkLight", size: 16, className: "text-gray-900" }) })] }));
|
|
7
6
|
};
|
|
8
7
|
export default PreviewHeader;
|
|
9
8
|
//# sourceMappingURL=preview-header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-header.js","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-header.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"preview-header.js","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-header.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAU7C,MAAM,aAAa,GAAG,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,GAAG,cAAc,EAAsB,EAAE,EAAE;IACxF,OAAO,CACL,kBAAQ,SAAS,EAAC,mCAAmC,aACnD,eAAM,SAAS,EAAE,EAAE,CAAC,+CAA+C,EAAE,MAAM,KAAK,OAAO,IAAI,cAAc,CAAC,YACvG,KAAK,GACD,EACP,iBAAQ,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAE,OAAO,gBAAa,eAAe,EAAC,SAAS,EAAC,mCAAmC,YAC9G,KAAC,IAAI,IAAC,IAAI,EAAC,YAAY,EAAC,IAAI,EAAE,EAAE,EAAE,SAAS,EAAC,eAAe,GAAG,GACvD,IACF,CACV,CAAA;AACH,CAAC,CAAA;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { type PreviewStatus } from '../types.js';
|
|
2
1
|
interface FilePreviewStateProps {
|
|
3
|
-
status: PreviewStatus;
|
|
4
2
|
onClose: () => void;
|
|
5
3
|
className?: string;
|
|
6
4
|
preview?: string;
|
|
7
5
|
}
|
|
8
|
-
declare const
|
|
9
|
-
export default
|
|
6
|
+
declare const PreviewImage: ({ onClose, className, preview }: FilePreviewStateProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default PreviewImage;
|
|
10
8
|
//# sourceMappingURL=preview-image.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-image.d.ts","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-image.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preview-image.d.ts","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-image.tsx"],"names":[],"mappings":"AAGA,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,QAAA,MAAM,YAAY,GAAI,iCAAiC,qBAAqB,4CAc3E,CAAA;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { cn } from '../../../../../scalars/lib/utils.js';
|
|
3
|
-
import { PREVIEW_STATUS } from '../types.js';
|
|
4
|
-
import { PlaceHolderImage } from './place-holder-image.js';
|
|
5
3
|
import PreviewHeader from './preview-header.js';
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
return (_jsxs("div", { className: cn('flex flex-col bg-white rounded-md shadow-[1px_4px_15px_0px_rgba(74,88,115,0.25)] px-6 py-4 gap-4 w-full h-full', className), children: [_jsx(PreviewHeader, { status: status, onClose: onClose, title: "Image Preview" }), _jsx("div", { className: "flex justify-center items-center relative rounded-md overflow-hidden", children: preview && _jsx("img", { src: preview, alt: "Preview", className: "w-full h-full object-contain" }) })] }));
|
|
9
|
-
}
|
|
10
|
-
return _jsx(PlaceHolderImage, { status: status, onClose: onClose, className: className });
|
|
4
|
+
const PreviewImage = ({ onClose, className, preview }) => {
|
|
5
|
+
return (_jsxs("div", { className: cn('flex flex-col bg-white rounded-md shadow-[1px_4px_15px_0px_rgba(74,88,115,0.25)] px-6 py-4 gap-4 w-full h-full', className), children: [_jsx(PreviewHeader, { status: "idle", onClose: onClose, title: "Image Preview" }), _jsx("div", { className: "flex-1 flex justify-center items-center relative rounded-md overflow-hidden", children: preview && _jsx("img", { src: preview, alt: "Preview", className: "w-full h-full object-contain" }) })] }));
|
|
11
6
|
};
|
|
12
|
-
export default
|
|
7
|
+
export default PreviewImage;
|
|
13
8
|
//# sourceMappingURL=preview-image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-image.js","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-image.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAA;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"preview-image.js","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-image.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAA;AACxD,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAQ/C,MAAM,YAAY,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAyB,EAAE,EAAE;IAC9E,OAAO,CACL,eACE,SAAS,EAAE,EAAE,CACX,gHAAgH,EAChH,SAAS,CACV,aAED,KAAC,aAAa,IAAC,MAAM,EAAC,MAAM,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAC,eAAe,GAAG,EACvE,cAAK,SAAS,EAAC,6EAA6E,YACzF,OAAO,IAAI,cAAK,GAAG,EAAE,OAAO,EAAE,GAAG,EAAC,SAAS,EAAC,SAAS,EAAC,8BAA8B,GAAG,GACpF,IACF,CACP,CAAA;AACH,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface VideoPreviewProps {
|
|
2
|
+
onClose?: () => void;
|
|
3
|
+
preview?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const PreviewVideo: ({ onClose, preview, className }: VideoPreviewProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default PreviewVideo;
|
|
8
|
+
//# sourceMappingURL=preview-video.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-video.d.ts","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-video.tsx"],"names":[],"mappings":"AAGA,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,MAAM,YAAY,GAAI,iCAA8C,iBAAiB,4CAsBpF,CAAA;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '../../../../../scalars/lib/utils.js';
|
|
3
|
+
import PreviewHeader from './preview-header.js';
|
|
4
|
+
const PreviewVideo = ({ onClose = () => null, preview, className }) => {
|
|
5
|
+
return (_jsxs("div", { className: cn('flex flex-col bg-white rounded-md shadow-[1px_4px_15px_0px_rgba(74,88,15,0.25)] px-6 py-4 gap-4 w-full h-full', className), children: [_jsx(PreviewHeader, { status: "idle", onClose: onClose, title: "Video Preview" }), _jsx("div", { className: "flex-1 flex justify-center items-center rounded-md overflow-hidden", children: _jsx("video", { src: preview, controls: true, "aria-label": "Video player", className: "w-full h-full rounded-md overflow-hidden object-contain", children: _jsx("p", { children: "Your browser does not support the video preview." }) }) })] }));
|
|
6
|
+
};
|
|
7
|
+
export default PreviewVideo;
|
|
8
|
+
//# sourceMappingURL=preview-video.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-video.js","sourceRoot":"","sources":["../../../../../../../src/ui/components/data-entry/file-input/sub-components/preview-video.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,qCAAqC,CAAA;AACxD,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAQ/C,MAAM,YAAY,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAqB,EAAE,EAAE;IACvF,OAAO,CACL,eACE,SAAS,EAAE,EAAE,CACX,+GAA+G,EAC/G,SAAS,CACV,aAED,KAAC,aAAa,IAAC,MAAM,EAAC,MAAM,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAC,eAAe,GAAG,EAEvE,cAAK,SAAS,EAAC,oEAAoE,YACjF,gBACE,GAAG,EAAE,OAAO,EACZ,QAAQ,sBACG,cAAc,EACzB,SAAS,EAAC,yDAAyD,YAEnE,2EAAuD,GACjD,GACJ,IACF,CACP,CAAA;AACH,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -20,17 +20,15 @@ export interface FileInputProps extends Omit<InputHTMLAttributes<HTMLInputElemen
|
|
|
20
20
|
export type UploadFile = 'idle' | 'uploading' | 'success' | 'error';
|
|
21
21
|
export declare const PREVIEW_STATUS: {
|
|
22
22
|
readonly LOADING: "loading";
|
|
23
|
-
readonly
|
|
23
|
+
readonly UNSUPPORTED_FILE: "unsupported_file";
|
|
24
24
|
readonly CORRUPTED_FILE: "corrupted_file";
|
|
25
25
|
readonly SUCCESS: "success";
|
|
26
26
|
};
|
|
27
|
-
type
|
|
28
|
-
export type PreviewStatus = ValueOf<typeof PREVIEW_STATUS>;
|
|
27
|
+
export type PreviewStatus = 'idle' | 'loading' | 'success' | 'corrupted_file' | 'unsupported_file';
|
|
29
28
|
export interface StatusConfig {
|
|
30
29
|
icon: IconName | undefined;
|
|
31
30
|
title?: string;
|
|
32
31
|
message?: string;
|
|
33
32
|
}
|
|
34
|
-
export type PreviewType = 'pdf' | 'image' | 'audio' | '
|
|
35
|
-
export {};
|
|
33
|
+
export type PreviewType = 'pdf' | 'image' | 'audio' | 'video';
|
|
36
34
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAA;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAs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AA;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/types.ts"],"names":[],"mappings":"AA0BA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,SAAS;IAClB,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/types.ts"],"names":[],"mappings":"AA0BA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,OAAO,EAAE,SAAS;IAClB,gBAAgB,EAAE,kBAAkB;IACpC,cAAc,EAAE,gBAAgB;IAChC,OAAO,EAAE,SAAS;CACV,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface UseQueryOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
}
|
|
4
|
+
interface UseQueryResult<T> {
|
|
5
|
+
data: T | null;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error: unknown;
|
|
8
|
+
}
|
|
9
|
+
declare const useFetchQuery: <T>(queryFn: () => Promise<T>, { enabled }?: UseQueryOptions) => UseQueryResult<T>;
|
|
10
|
+
export default useFetchQuery;
|
|
11
|
+
//# sourceMappingURL=useFetchQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchQuery.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/useFetchQuery.ts"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,UAAU,cAAc,CAAC,CAAC;IACxB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAA;IACd,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,OAAO,CAAA;CACf;AAED,QAAA,MAAM,aAAa,GAAI,CAAC,EAAE,SAAS,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,cAAoB,eAAoB,KAAG,cAAc,CAAC,CAAC,CA6B/G,CAAA;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
const useFetchQuery = (queryFn, { enabled = true } = {}) => {
|
|
3
|
+
const [data, setData] = useState(null);
|
|
4
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
5
|
+
const [error, setError] = useState(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!enabled) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const fetchData = async () => {
|
|
11
|
+
setIsLoading(true);
|
|
12
|
+
setError(null);
|
|
13
|
+
setData(null);
|
|
14
|
+
try {
|
|
15
|
+
const result = await queryFn();
|
|
16
|
+
setData(result);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
setError(err);
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setIsLoading(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
void fetchData();
|
|
26
|
+
}, [queryFn, enabled]);
|
|
27
|
+
return { data, isLoading, error };
|
|
28
|
+
};
|
|
29
|
+
export default useFetchQuery;
|
|
30
|
+
//# sourceMappingURL=useFetchQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchQuery.js","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/useFetchQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAY3C,MAAM,aAAa,GAAG,CAAI,OAAyB,EAAE,EAAE,OAAO,GAAG,IAAI,KAAsB,EAAE,EAAqB,EAAE;IAClH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAW,IAAI,CAAC,CAAA;IAChD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IACjD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAA;IAEjD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAM;QACR,CAAC;QAED,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;YAC3B,YAAY,CAAC,IAAI,CAAC,CAAA;YAClB,QAAQ,CAAC,IAAI,CAAC,CAAA;YACd,OAAO,CAAC,IAAI,CAAC,CAAA;YAEb,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAA;gBAC9B,OAAO,CAAC,MAAM,CAAC,CAAA;YACjB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,QAAQ,CAAC,GAAG,CAAC,CAAA;YACf,CAAC;oBAAS,CAAC;gBACT,YAAY,CAAC,KAAK,CAAC,CAAA;YACrB,CAAC;QACH,CAAC,CAAA;QAED,KAAK,SAAS,EAAE,CAAA;IAClB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IAEtB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;AACnC,CAAC,CAAA;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PreviewStatus } from './types.js';
|
|
2
2
|
interface UseFileUploadProps {
|
|
3
3
|
value?: File | null;
|
|
4
4
|
defaultValue?: File | null;
|
|
@@ -10,11 +10,10 @@ export declare const useFileUpload: ({ value, defaultValue, onChange }: UseFileU
|
|
|
10
10
|
borderIndicator: string;
|
|
11
11
|
preview: string | undefined;
|
|
12
12
|
handleCancelPreview: () => void;
|
|
13
|
-
handleOnPreview: () =>
|
|
13
|
+
handleOnPreview: () => void;
|
|
14
14
|
isPreviewOpen: boolean;
|
|
15
15
|
previewStatus: PreviewStatus;
|
|
16
|
-
|
|
17
|
-
typePreview: "audio" | "image" | "unknown" | "pdf";
|
|
16
|
+
typePreview: "audio" | "video" | "image" | "pdf" | undefined;
|
|
18
17
|
};
|
|
19
18
|
export {};
|
|
20
19
|
//# sourceMappingURL=useUploadFile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUploadFile.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/useUploadFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUploadFile.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/useUploadFile.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,UAAU,kBAAkB;IAC1B,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IACnB,YAAY,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IAC1B,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAA;CACvC;AAED,eAAO,MAAM,aAAa,GAAI,mCAAmC,kBAAkB;iCA0B9D,IAAI,EAAE;;;;;;;;;CA4C1B,CAAA"}
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
const mapValidator = {
|
|
5
|
-
['pdf']: validatePdfHeader,
|
|
6
|
-
['image']: validateImageHeader,
|
|
7
|
-
['audio']: async () => Promise.resolve(true),
|
|
8
|
-
['unknown']: async () => Promise.resolve(false),
|
|
9
|
-
};
|
|
2
|
+
import { detectPreviewType, getPreviewComponentFromError, validateFileForPreview } from './utils.js';
|
|
3
|
+
import useFetchQuery from './useFetchQuery.js';
|
|
10
4
|
export const useFileUpload = ({ value, defaultValue, onChange }) => {
|
|
11
5
|
const [file, setFile] = useState(value ?? defaultValue ?? null);
|
|
12
6
|
const [preview, setPreview] = useState(undefined);
|
|
13
7
|
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
|
|
14
|
-
const
|
|
8
|
+
const queryFn = useCallback(async () => {
|
|
9
|
+
if (!file)
|
|
10
|
+
return Promise.reject(new Error('No hay archivo seleccionado'));
|
|
11
|
+
return validateFileForPreview(file);
|
|
12
|
+
}, [file]);
|
|
13
|
+
const { data, isLoading, error } = useFetchQuery(queryFn, {
|
|
14
|
+
enabled: isPreviewOpen && !!file,
|
|
15
|
+
});
|
|
16
|
+
const getPreviewStatus = () => {
|
|
17
|
+
if (!isPreviewOpen)
|
|
18
|
+
return 'idle';
|
|
19
|
+
if (isLoading)
|
|
20
|
+
return 'loading';
|
|
21
|
+
if (error) {
|
|
22
|
+
const errorType = getPreviewComponentFromError(error);
|
|
23
|
+
return errorType || 'unsupported_file';
|
|
24
|
+
}
|
|
25
|
+
if (data === 'success')
|
|
26
|
+
return 'success';
|
|
27
|
+
return 'idle';
|
|
28
|
+
};
|
|
29
|
+
const previewStatus = getPreviewStatus();
|
|
15
30
|
const handleDrop = useCallback((acceptedFiles) => {
|
|
16
31
|
if (!acceptedFiles || acceptedFiles.length === 0)
|
|
17
32
|
return;
|
|
@@ -24,32 +39,7 @@ export const useFileUpload = ({ value, defaultValue, onChange }) => {
|
|
|
24
39
|
const handleCancelPreview = () => {
|
|
25
40
|
setIsPreviewOpen(false);
|
|
26
41
|
};
|
|
27
|
-
const typePreview = detectPreviewType(file
|
|
28
|
-
const handleOnPreview = async () => {
|
|
29
|
-
setIsPreviewOpen(true);
|
|
30
|
-
setPreviewStatus(PREVIEW_STATUS.LOADING);
|
|
31
|
-
if (!file || typePreview === 'unknown') {
|
|
32
|
-
setPreviewStatus(PREVIEW_STATUS.UNSUPPORTED_FORMAT);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const validator = mapValidator[typePreview];
|
|
36
|
-
try {
|
|
37
|
-
const isValid = await validator(file);
|
|
38
|
-
if (!isValid) {
|
|
39
|
-
setPreviewStatus(PREVIEW_STATUS.CORRUPTED_FILE);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!preview) {
|
|
43
|
-
setPreviewStatus(PREVIEW_STATUS.CORRUPTED_FILE);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
await new Promise((res) => setTimeout(res, 2000));
|
|
47
|
-
setPreviewStatus(PREVIEW_STATUS.SUCCESS);
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
setPreviewStatus(PREVIEW_STATUS.CORRUPTED_FILE);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
42
|
+
const typePreview = detectPreviewType(file ?? undefined);
|
|
53
43
|
useEffect(() => {
|
|
54
44
|
return () => {
|
|
55
45
|
if (preview) {
|
|
@@ -58,6 +48,11 @@ export const useFileUpload = ({ value, defaultValue, onChange }) => {
|
|
|
58
48
|
};
|
|
59
49
|
}, [preview]);
|
|
60
50
|
const borderIndicator = file ? 'text-blue-900' : 'text-gray-300';
|
|
51
|
+
const handleOnPreview = () => {
|
|
52
|
+
if (!file)
|
|
53
|
+
return;
|
|
54
|
+
setIsPreviewOpen(true);
|
|
55
|
+
};
|
|
61
56
|
return {
|
|
62
57
|
handleDrop,
|
|
63
58
|
file,
|
|
@@ -68,7 +63,6 @@ export const useFileUpload = ({ value, defaultValue, onChange }) => {
|
|
|
68
63
|
handleOnPreview,
|
|
69
64
|
isPreviewOpen,
|
|
70
65
|
previewStatus,
|
|
71
|
-
setPreviewStatus,
|
|
72
66
|
typePreview,
|
|
73
67
|
};
|
|
74
68
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUploadFile.js","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/useUploadFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":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AO;QACL,UAAU;QACV,IAAI;QACJ,eAAe;QACf,UAAU;QACV,OAAO;QACP,mBAAmB;QACnB,eAAe;QACf,aAAa;QACb,aAAa;QACb,WAAW;KACZ,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IconName } from '../../icon-components/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { PreviewStatus, PreviewType } from './types.js';
|
|
3
3
|
export declare const MESSAGES: {
|
|
4
4
|
success: string;
|
|
5
5
|
error: string;
|
|
@@ -8,9 +8,37 @@ export declare const MESSAGES: {
|
|
|
8
8
|
export declare const formatBytes: (bytes?: number, decimals?: number, binaryUnits?: boolean) => string;
|
|
9
9
|
export declare function getExtensionsFromMimeTypes(mimeTypes?: string[]): string[];
|
|
10
10
|
export declare const getIconKey: (mimeType: string) => IconName;
|
|
11
|
-
export declare const STATUS_CONFIG_PDF: Record<PreviewStatus, StatusConfig>;
|
|
12
|
-
export declare const STATUS_CONFIG_IMAGE: Record<PreviewStatus, StatusConfig>;
|
|
13
|
-
export declare const detectPreviewType: (mimeType?: string) => "pdf" | "image" | "audio" | "unknown";
|
|
14
11
|
export declare const validatePdfHeader: (file: File) => Promise<boolean>;
|
|
15
12
|
export declare const validateImageHeader: (file: File) => Promise<unknown>;
|
|
13
|
+
export declare const validateAudio: (file: File) => Promise<boolean>;
|
|
14
|
+
export declare const validateVideo: (file: File) => Promise<boolean>;
|
|
15
|
+
export declare const detectPreviewType: (file?: File) => "pdf" | "image" | "audio" | "video" | undefined;
|
|
16
|
+
export declare const isCorruptedFile: (file: File) => Promise<boolean>;
|
|
17
|
+
export declare const getPreviewComponentFromError: (error: unknown) => "corrupted_file" | "unsupported_file" | null;
|
|
18
|
+
export declare const previewSizeStyles: {
|
|
19
|
+
pdf: {
|
|
20
|
+
width: string;
|
|
21
|
+
height: string;
|
|
22
|
+
};
|
|
23
|
+
video: {
|
|
24
|
+
width: string;
|
|
25
|
+
height: string;
|
|
26
|
+
};
|
|
27
|
+
image: {
|
|
28
|
+
width: string;
|
|
29
|
+
height: string;
|
|
30
|
+
};
|
|
31
|
+
audio: {
|
|
32
|
+
width: string;
|
|
33
|
+
height: string;
|
|
34
|
+
};
|
|
35
|
+
unsupported_file: {
|
|
36
|
+
width: string;
|
|
37
|
+
height: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare const validateFileForPreview: (file?: File) => Promise<"success" | undefined>;
|
|
41
|
+
export declare const getIconLoading: (type: PreviewType) => IconName;
|
|
42
|
+
export declare const getBrokenFileIcon: (type: PreviewType) => IconName;
|
|
43
|
+
export declare const getContainerDimensions: (status: PreviewStatus, typePreview?: PreviewType) => string;
|
|
16
44
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../../src/ui/components/data-entry/file-input/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC5D,eAAO,MAAM,QAAQ;;;;CAIpB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,EAAE,iBAAY,EAAE,qBAAmB,KAAG,MAgB/E,CAAA;AAED,wBAAgB,0BAA0B,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAGzE;AAeD,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,KAAG,QAa7C,CAAA;AA2BD,eAAO,MAAM,iBAAiB,GAAU,MAAM,IAAI,qBAUjD,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAU,MAAM,IAAI,qBAiBnD,CAAA;AAED,eAAO,MAAM,aAAa,GAAU,MAAM,IAAI,KAAG,OAAO,CAAC,OAAO,CAS/D,CAAA;AAED,eAAO,MAAM,aAAa,GAAU,MAAM,IAAI,KAAG,OAAO,CAAC,OAAO,CAkB/D,CAAA;AAQD,eAAO,MAAM,iBAAiB,GAAI,OAAO,IAAI,KAAG,KAAK,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,SAOrF,CAAA;AAED,eAAO,MAAM,eAAe,GAAU,MAAM,IAAI,KAAG,OAAO,CAAC,OAAO,CAMjE,CAAA;AAED,eAAO,MAAM,4BAA4B,GAAI,OAAO,OAAO,KAAG,gBAAgB,GAAG,kBAAkB,GAAG,IAYrG,CAAA;AAED,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;CAM7B,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,OAAO,IAAI,mCAgBvD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,MAAM,WAAW,KAAG,QAalD,CAAA;AAED,eAAO,MAAM,iBAAiB,GAAI,MAAM,WAAW,KAAG,QAarD,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,QAAQ,aAAa,EAAE,cAAc,WAAW,KAAG,MAmBzF,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import mime from 'mime/lite';
|
|
2
|
-
import { PREVIEW_STATUS } from './types.js';
|
|
3
2
|
export const MESSAGES = {
|
|
4
3
|
success: 'Upload successful',
|
|
5
4
|
error: 'Upload failed',
|
|
@@ -43,55 +42,12 @@ export const getIconKey = (mimeType) => {
|
|
|
43
42
|
}
|
|
44
43
|
let iconName = 'DownloadFile';
|
|
45
44
|
const extension = mime.getExtension(mimeType);
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const existsExtension = Object.keys(ICON_CODE_TO_NAME).includes(extension?.toUpperCase() ?? '');
|
|
46
|
+
if (existsExtension) {
|
|
47
|
+
iconName = ICON_CODE_TO_NAME[extension?.toUpperCase() ?? ''];
|
|
48
48
|
}
|
|
49
49
|
return iconName;
|
|
50
50
|
};
|
|
51
|
-
export const STATUS_CONFIG_PDF = {
|
|
52
|
-
[PREVIEW_STATUS.LOADING]: {
|
|
53
|
-
icon: 'BookOpenText',
|
|
54
|
-
title: 'Loading',
|
|
55
|
-
message: '',
|
|
56
|
-
},
|
|
57
|
-
[PREVIEW_STATUS.UNSUPPORTED_FORMAT]: {
|
|
58
|
-
icon: 'ContentUnavailableIcon',
|
|
59
|
-
title: 'Opss!',
|
|
60
|
-
message: "It looks like we still don't support this format. (We are working on it) Please try to upload it with a different Format.",
|
|
61
|
-
},
|
|
62
|
-
[PREVIEW_STATUS.CORRUPTED_FILE]: {
|
|
63
|
-
icon: 'ContentUnavailableIcon',
|
|
64
|
-
title: '',
|
|
65
|
-
message: 'Your file is corrupted and cannot be shown in the preview',
|
|
66
|
-
},
|
|
67
|
-
[PREVIEW_STATUS.SUCCESS]: {
|
|
68
|
-
icon: undefined,
|
|
69
|
-
title: '',
|
|
70
|
-
message: '',
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
export const STATUS_CONFIG_IMAGE = {
|
|
74
|
-
[PREVIEW_STATUS.LOADING]: {
|
|
75
|
-
icon: 'Image',
|
|
76
|
-
title: 'Loading',
|
|
77
|
-
message: '',
|
|
78
|
-
},
|
|
79
|
-
[PREVIEW_STATUS.UNSUPPORTED_FORMAT]: {
|
|
80
|
-
icon: 'BrokenImage',
|
|
81
|
-
title: 'Opss!',
|
|
82
|
-
message: "It looks like we still don't support this format. (We are working on it) Please try to upload it with a different Format.",
|
|
83
|
-
},
|
|
84
|
-
[PREVIEW_STATUS.CORRUPTED_FILE]: {
|
|
85
|
-
icon: 'BrokenImage',
|
|
86
|
-
title: '',
|
|
87
|
-
message: 'Your file is corrupted and cannot be shown in the preview',
|
|
88
|
-
},
|
|
89
|
-
[PREVIEW_STATUS.SUCCESS]: {
|
|
90
|
-
icon: undefined,
|
|
91
|
-
title: '',
|
|
92
|
-
message: '',
|
|
93
|
-
},
|
|
94
|
-
};
|
|
95
51
|
const MIME_TYPE_TO_EXTENSION_IMAGE = {
|
|
96
52
|
'image/jpeg': 'jpg',
|
|
97
53
|
'image/png': 'png',
|
|
@@ -108,16 +64,10 @@ const MIME_TYPE_TO_EXTENSION_AUDIO = {
|
|
|
108
64
|
const MIME_TYPE_TO_EXTENSION_PDF = {
|
|
109
65
|
'application/pdf': 'pdf',
|
|
110
66
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return 'image';
|
|
116
|
-
if (Object.keys(MIME_TYPE_TO_EXTENSION_AUDIO).includes(mimeType))
|
|
117
|
-
return 'audio';
|
|
118
|
-
if (Object.keys(MIME_TYPE_TO_EXTENSION_PDF).includes(mimeType))
|
|
119
|
-
return 'pdf';
|
|
120
|
-
return 'unknown';
|
|
67
|
+
const MIME_TYPE_TO_EXTENSION_VIDEO = {
|
|
68
|
+
'video/mp4': 'mp4',
|
|
69
|
+
'video/webm': 'webm',
|
|
70
|
+
'video/ogg': 'ogg',
|
|
121
71
|
};
|
|
122
72
|
export const validatePdfHeader = async (file) => {
|
|
123
73
|
const buffer = await file.arrayBuffer();
|
|
@@ -143,4 +93,139 @@ export const validateImageHeader = async (file) => {
|
|
|
143
93
|
img.src = url;
|
|
144
94
|
});
|
|
145
95
|
};
|
|
96
|
+
export const validateAudio = async (file) => {
|
|
97
|
+
try {
|
|
98
|
+
const audioContext = new AudioContext();
|
|
99
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
100
|
+
await audioContext.decodeAudioData(arrayBuffer);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
export const validateVideo = async (file) => {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const url = URL.createObjectURL(file);
|
|
110
|
+
const video = document.createElement('video');
|
|
111
|
+
video.src = url;
|
|
112
|
+
video.preload = 'metadata';
|
|
113
|
+
video.onloadedmetadata = () => {
|
|
114
|
+
URL.revokeObjectURL(url);
|
|
115
|
+
resolve(true);
|
|
116
|
+
};
|
|
117
|
+
video.onerror = () => {
|
|
118
|
+
URL.revokeObjectURL(url);
|
|
119
|
+
resolve(false);
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
const fileValidators = {
|
|
124
|
+
pdf: validatePdfHeader,
|
|
125
|
+
image: validateImageHeader,
|
|
126
|
+
audio: validateAudio,
|
|
127
|
+
video: validateVideo,
|
|
128
|
+
};
|
|
129
|
+
export const detectPreviewType = (file) => {
|
|
130
|
+
if (!file)
|
|
131
|
+
return undefined;
|
|
132
|
+
const mimeType = file.type;
|
|
133
|
+
if (Object.keys(MIME_TYPE_TO_EXTENSION_IMAGE).includes(mimeType))
|
|
134
|
+
return 'image';
|
|
135
|
+
if (Object.keys(MIME_TYPE_TO_EXTENSION_AUDIO).includes(mimeType))
|
|
136
|
+
return 'audio';
|
|
137
|
+
if (Object.keys(MIME_TYPE_TO_EXTENSION_PDF).includes(mimeType))
|
|
138
|
+
return 'pdf';
|
|
139
|
+
if (Object.keys(MIME_TYPE_TO_EXTENSION_VIDEO).includes(mimeType))
|
|
140
|
+
return 'video';
|
|
141
|
+
};
|
|
142
|
+
export const isCorruptedFile = async (file) => {
|
|
143
|
+
const fileType = detectPreviewType(file);
|
|
144
|
+
if (!fileType)
|
|
145
|
+
return false;
|
|
146
|
+
const validator = fileValidators[fileType];
|
|
147
|
+
const isValid = await validator(file);
|
|
148
|
+
return !isValid;
|
|
149
|
+
};
|
|
150
|
+
export const getPreviewComponentFromError = (error) => {
|
|
151
|
+
if (error instanceof Error) {
|
|
152
|
+
switch (error.message) {
|
|
153
|
+
case 'corrupted_file':
|
|
154
|
+
return 'corrupted_file';
|
|
155
|
+
case 'unsupported_file':
|
|
156
|
+
return 'unsupported_file';
|
|
157
|
+
default:
|
|
158
|
+
return 'unsupported_file';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
export const previewSizeStyles = {
|
|
164
|
+
pdf: { width: '500px', height: '652px' },
|
|
165
|
+
video: { width: '600px', height: '340px' },
|
|
166
|
+
image: { width: '368px', height: '384px' },
|
|
167
|
+
audio: { width: '368px', height: '384px' },
|
|
168
|
+
unsupported_file: { width: '500px', height: '652px' },
|
|
169
|
+
};
|
|
170
|
+
export const validateFileForPreview = async (file) => {
|
|
171
|
+
if (!file)
|
|
172
|
+
return;
|
|
173
|
+
const typePreview = detectPreviewType(file);
|
|
174
|
+
if (!typePreview) {
|
|
175
|
+
throw new Error('unsupported_file');
|
|
176
|
+
}
|
|
177
|
+
const isCorrupted = await isCorruptedFile(file);
|
|
178
|
+
if (isCorrupted) {
|
|
179
|
+
throw new Error('corrupted_file');
|
|
180
|
+
}
|
|
181
|
+
await new Promise((res) => setTimeout(res, 2000));
|
|
182
|
+
return 'success';
|
|
183
|
+
};
|
|
184
|
+
export const getIconLoading = (type) => {
|
|
185
|
+
switch (type) {
|
|
186
|
+
case 'pdf':
|
|
187
|
+
return 'BookOpenText';
|
|
188
|
+
case 'image':
|
|
189
|
+
return 'PlaceholderImage';
|
|
190
|
+
case 'audio':
|
|
191
|
+
return 'PlaceholderAudio';
|
|
192
|
+
case 'video':
|
|
193
|
+
return 'PlaceholderVideo';
|
|
194
|
+
default:
|
|
195
|
+
return 'BookOpenText';
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
export const getBrokenFileIcon = (type) => {
|
|
199
|
+
switch (type) {
|
|
200
|
+
case 'pdf':
|
|
201
|
+
return 'ContentUnavailableIcon';
|
|
202
|
+
case 'image':
|
|
203
|
+
return 'BrokenImage';
|
|
204
|
+
case 'audio':
|
|
205
|
+
return 'BrokenAudio';
|
|
206
|
+
case 'video':
|
|
207
|
+
return 'BrokenVideo';
|
|
208
|
+
default:
|
|
209
|
+
return 'ContentUnavailableIcon';
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
export const getContainerDimensions = (status, typePreview) => {
|
|
213
|
+
if (status !== 'success') {
|
|
214
|
+
return 'w-[600px] h-[652px]';
|
|
215
|
+
}
|
|
216
|
+
switch (typePreview) {
|
|
217
|
+
case 'pdf':
|
|
218
|
+
return 'w-[500px] h-[652px]';
|
|
219
|
+
case 'video':
|
|
220
|
+
return 'w-[600px] h-[340px]';
|
|
221
|
+
case 'image':
|
|
222
|
+
return 'w-[368px] h-[384px]';
|
|
223
|
+
case 'audio':
|
|
224
|
+
return 'w-[368px] h-[384px]';
|
|
225
|
+
case undefined:
|
|
226
|
+
return 'w-[500px] h-[652px]';
|
|
227
|
+
default:
|
|
228
|
+
return 'w-[500px] h-[652px]';
|
|
229
|
+
}
|
|
230
|
+
};
|
|
146
231
|
//# sourceMappingURL=utils.js.map
|