tycho-components 0.11.7 → 0.12.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/AppDropzone/AppDropzone.d.ts +0 -1
- package/dist/AppDropzone/AppDropzone.js +3 -19
- package/dist/AppDropzone/AppDropzoneBody.d.ts +9 -0
- package/dist/AppDropzone/AppDropzoneBody.js +32 -0
- package/dist/AppDropzone/index.d.ts +2 -0
- package/dist/AppDropzone/index.js +2 -0
- package/dist/configs/types/Corpus.d.ts +0 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useState } from 'react';
|
|
3
|
-
import Dropzone from 'react-dropzone';
|
|
4
3
|
import { useTranslation } from 'react-i18next';
|
|
5
4
|
import AppModal from '../AppModal';
|
|
6
5
|
import CommonContext from '../configs/CommonContext';
|
|
7
6
|
import { toastLoading } from '../configs/store/actions';
|
|
8
7
|
import { useMessageUtils } from '../configs/useMessageUtils';
|
|
9
|
-
import './
|
|
8
|
+
import AppDropzoneBody from './AppDropzoneBody';
|
|
10
9
|
import UploadService from './UploadService';
|
|
11
10
|
export default function AppDropzone({ folder, onClose, onSuccess, onError, accept, onDrop, keepName, title, alternativeButton, }) {
|
|
12
11
|
const { t } = useTranslation('upload');
|
|
13
12
|
const { state, dispatch } = useContext(CommonContext);
|
|
14
13
|
const { dispatchError } = useMessageUtils();
|
|
15
14
|
const [file, setFile] = useState();
|
|
16
|
-
const [preview, setPreview] = useState();
|
|
17
|
-
const isImageFile = (file) => {
|
|
18
|
-
return file.type?.startsWith('image/') ?? false;
|
|
19
|
-
};
|
|
20
|
-
const handleDrop = async (files) => {
|
|
21
|
-
if (files.length === 0)
|
|
22
|
-
return;
|
|
23
|
-
const file = files[0];
|
|
24
|
-
setFile(file);
|
|
25
|
-
if (isImageFile(file))
|
|
26
|
-
setPreview(URL.createObjectURL(file));
|
|
27
|
-
onDrop && onDrop();
|
|
28
|
-
};
|
|
29
15
|
const upload = async () => {
|
|
30
16
|
if (!file || state.toastLoading)
|
|
31
17
|
return;
|
|
@@ -46,7 +32,5 @@ export default function AppDropzone({ folder, onClose, onSuccess, onError, accep
|
|
|
46
32
|
dispatch(toastLoading(false));
|
|
47
33
|
});
|
|
48
34
|
};
|
|
49
|
-
return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: upload, alternativeButton: alternativeButton, children:
|
|
50
|
-
URL.revokeObjectURL(preview);
|
|
51
|
-
} })), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("span", { children: file.name }), _jsx("b", { children: t('label.confirm') })] }))] }) }));
|
|
35
|
+
return (_jsx(AppModal, { title: title || t('modal.title'), className: "modal-upload", close: onClose, confirm: upload, alternativeButton: alternativeButton, children: _jsx(AppDropzoneBody, { accept: accept, file: file, onFileChange: setFile, onDrop: onDrop }) }));
|
|
52
36
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import './style.scss';
|
|
2
|
+
type Props = {
|
|
3
|
+
accept: Record<string, string[]>;
|
|
4
|
+
file?: File;
|
|
5
|
+
onFileChange: (file: File | undefined) => void;
|
|
6
|
+
onDrop?: () => void;
|
|
7
|
+
};
|
|
8
|
+
export default function AppDropzoneBody({ accept, file, onFileChange, onDrop, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import Dropzone from 'react-dropzone';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import './style.scss';
|
|
6
|
+
export default function AppDropzoneBody({ accept, file, onFileChange, onDrop, }) {
|
|
7
|
+
const { t } = useTranslation('upload');
|
|
8
|
+
const [preview, setPreview] = useState();
|
|
9
|
+
const isImageFile = (f) => {
|
|
10
|
+
return f.type?.startsWith('image/') ?? false;
|
|
11
|
+
};
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!file) {
|
|
14
|
+
setPreview(undefined);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (isImageFile(file)) {
|
|
18
|
+
const url = URL.createObjectURL(file);
|
|
19
|
+
setPreview(url);
|
|
20
|
+
return () => URL.revokeObjectURL(url);
|
|
21
|
+
}
|
|
22
|
+
setPreview(undefined);
|
|
23
|
+
}, [file]);
|
|
24
|
+
const handleDrop = (files) => {
|
|
25
|
+
if (files.length === 0)
|
|
26
|
+
return;
|
|
27
|
+
const droppedFile = files[0];
|
|
28
|
+
onFileChange(droppedFile);
|
|
29
|
+
onDrop?.();
|
|
30
|
+
};
|
|
31
|
+
return (_jsxs("div", { className: "dropzone-container", children: [!file && (_jsx(Dropzone, { onDrop: (acceptedFiles) => handleDrop(acceptedFiles), accept: accept, maxFiles: 1, children: ({ getRootProps, getInputProps }) => (_jsxs("div", { ...getRootProps(), className: "dropzone", children: [_jsx("input", { ...getInputProps() }), _jsx("span", { children: t('label.dropzone') })] })) })), file && preview && _jsx("img", { className: "preview", src: preview, alt: "" }), file && !preview && (_jsxs("div", { className: "uploaded-message", children: [_jsx("b", { children: t('label.uploaded.file') }), _jsx("span", { children: file.name }), _jsx("b", { children: t('label.confirm') })] }))] }));
|
|
32
|
+
}
|
|
@@ -10,12 +10,8 @@ export type Corpus = {
|
|
|
10
10
|
parameters: Record<string, any>;
|
|
11
11
|
status: CorpusStatus;
|
|
12
12
|
opened: boolean;
|
|
13
|
-
papers?: RelatedPaper[];
|
|
14
13
|
owner?: User;
|
|
15
14
|
github?: Github;
|
|
16
|
-
descriptions?: Record<string, string>;
|
|
17
|
-
featuredDescriptions?: Record<string, string>;
|
|
18
|
-
details?: Record<string, string>;
|
|
19
15
|
images?: CorpusImage[];
|
|
20
16
|
keyboardLayout?: string;
|
|
21
17
|
catalog?: string[];
|
|
@@ -38,12 +34,5 @@ export type Github = {
|
|
|
38
34
|
branch: string;
|
|
39
35
|
commit: string;
|
|
40
36
|
};
|
|
41
|
-
export type RelatedPaper = {
|
|
42
|
-
uid?: string;
|
|
43
|
-
title: string;
|
|
44
|
-
author: string;
|
|
45
|
-
link: string;
|
|
46
|
-
resume: string;
|
|
47
|
-
};
|
|
48
37
|
export declare const EMPTY_CORPUS: Corpus;
|
|
49
38
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { default as AppAnalytics } from './AppAnalytics';
|
|
|
2
2
|
export { default as AppCard } from './AppCard/AppCard';
|
|
3
3
|
export { default as AppClipboard } from './AppClipboard';
|
|
4
4
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
5
|
-
export { default as AppDropzone } from './AppDropzone';
|
|
5
|
+
export { default as AppDropzone, AppDropzoneBody } from './AppDropzone';
|
|
6
6
|
export type { UploadedFile } from './AppDropzone/UploadedFile';
|
|
7
7
|
export { default as AppEditable } from './AppEditable';
|
|
8
8
|
export type { AppEditableField } from './AppEditable/AppEditableField';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { default as AppAnalytics } from './AppAnalytics';
|
|
|
2
2
|
export { default as AppCard } from './AppCard/AppCard';
|
|
3
3
|
export { default as AppClipboard } from './AppClipboard';
|
|
4
4
|
export { default as AppColorpicker } from './AppColorpicker';
|
|
5
|
-
export { default as AppDropzone } from './AppDropzone';
|
|
5
|
+
export { default as AppDropzone, AppDropzoneBody } from './AppDropzone';
|
|
6
6
|
export { default as AppEditable } from './AppEditable';
|
|
7
7
|
export { validateFormField } from './AppEditable/FormField';
|
|
8
8
|
export { default as AppForm } from './AppForm/AppForm';
|