@zjlab-fe/data-hub-ui 0.21.6 → 0.22.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/types/components/tip-tap/extensions/index.d.ts +1 -1
- package/es/assets/cardImg.png.js +3 -0
- package/es/assets/closeBtn.png.js +3 -0
- package/es/assets/icon-tag-header.png.js +3 -0
- package/es/assets/source.png.js +3 -0
- package/es/components/FileUploader/FileUploadModal.js +24 -0
- package/es/components/FileUploader/FileUploader.js +20 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploader.js +34 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderContextProvider.js +46 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderFileReceiver.css.js +36 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderFileReceiver.js +57 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderFileReceiverContainer.js +24 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderFileReceiverDesc.js +9 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderList.js +46 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderListItem.js +46 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderListItemFail.js +21 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderListItemPaused.js +20 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderListItemUploading.js +43 -0
- package/es/components/FileUploader/FileUploaderImpl/FileUploaderlListItemFinished.js +32 -0
- package/es/components/FileUploader/Locale/translations.js +52 -0
- package/es/components/FileUploader/Locale/useTranslate.js +16 -0
- package/es/components/FileUploader/UploadStoreProvider/UploadStoreProvider.js +31 -0
- package/es/components/FileUploader/UploadStoreProvider/uploadStoreReducer.js +62 -0
- package/es/components/FileUploader/UploadStoreProvider/useOnFileAllUploaded.js +31 -0
- package/es/components/FileUploader/UploadStoreProvider/useSaveUnfinishedUploads.js +42 -0
- package/es/components/FileUploader/UploadStoreProvider/useSetupMergingEvent.js +45 -0
- package/es/components/FileUploader/hooks/useCancelUpload.js +40 -0
- package/es/components/FileUploader/hooks/useCurrentFile.js +61 -0
- package/es/components/FileUploader/hooks/useCurrentFileOnUploading.js +52 -0
- package/es/components/FileUploader/hooks/useCurrentFileSetupAndBackUp.js +39 -0
- package/es/components/FileUploader/hooks/useFormatFiles.js +64 -0
- package/es/components/FileUploader/hooks/useFormatFilesFindDuplicates.js +75 -0
- package/es/components/FileUploader/hooks/useFormatFilesRemoveDuplicates.js +21 -0
- package/es/components/FileUploader/hooks/useHandleChunkCompletion.js +31 -0
- package/es/components/FileUploader/hooks/useOnMounted.js +24 -0
- package/es/components/FileUploader/hooks/useOnMountedResumeUnfinished.js +58 -0
- package/es/components/FileUploader/hooks/useRetryUpload.js +33 -0
- package/es/components/FileUploader/hooks/useUploadChunk.js +46 -0
- package/es/components/FileUploader/icons/CloseFilled.js +7 -0
- package/es/components/FileUploader/icons/UnkownFileIcon.js +7 -0
- package/es/components/FileUploader/icons/UploadIcon.js +7 -0
- package/es/components/FileUploader/index.css.js +532 -0
- package/es/components/FileUploader/index.js +23 -0
- package/es/components/FileUploader/types.js +13 -0
- package/es/components/FileUploader/utils/calcDisplaySize.js +20 -0
- package/es/components/FileUploader/utils/checkExpiryTime.js +15 -0
- package/es/components/FileUploader/utils/createFileToUpload.js +60 -0
- package/es/components/FileUploader/utils/fileDB/addFilesToIndexdb.js +14 -0
- package/es/components/FileUploader/utils/fileDB/deleteFileInStore.js +18 -0
- package/es/components/FileUploader/utils/fileDB/deleteObjectStore.js +25 -0
- package/es/components/FileUploader/utils/fileDB/index.js +77 -0
- package/es/components/FileUploader/utils/fileDB/openDBAndRetrieveData.js +90 -0
- package/es/components/FileUploader/utils/fileDB/retrieveExistingData.js +49 -0
- package/es/components/FileUploader/utils/modalConfig.css.js +20 -0
- package/es/components/FileUploader/utils/modalConfig.js +32 -0
- package/es/components/FileUploader/utils/retrieveAllFiles.js +70 -0
- package/es/components/FileUploader/utils/splitFileIntoChunk.js +15 -0
- package/es/components/SDK-modal/document-link.js +8 -0
- package/es/components/SDK-modal/index.js +25 -0
- package/es/components/SDK-modal/index.module.scss.js +49 -0
- package/es/components/SDK-modal/inner-modal.js +59 -0
- package/es/components/SDK-modal/locale/translations.js +17 -0
- package/es/components/apply-perm-modal/index.js +53 -0
- package/es/components/apply-perm-modal/index.module.scss.js +96 -0
- package/es/components/auth-tag/index.js +23 -0
- package/es/components/bench-card/index.js +20 -0
- package/es/components/bench-card/index.module.scss.js +48 -0
- package/es/components/confirm-again/index.js +15 -0
- package/es/components/confirm-again/index.scss.js +37 -0
- package/es/components/copy/index.js +41 -0
- package/es/components/copy/index.module.scss.js +15 -0
- package/es/components/corpus-card/index.js +88 -0
- package/es/components/corpus-card/index.module.scss.js +171 -0
- package/es/components/feature-card/classNames.js +72 -0
- package/es/components/feature-card/components.js +48 -0
- package/es/components/feature-card/context.js +13 -0
- package/es/components/feature-card/index.css.js +655 -0
- package/es/components/feature-card/index.js +48 -0
- package/es/components/file-preview/data-table/index.js +94 -0
- package/es/components/file-preview/data-table/index.module.scss.js +54 -0
- package/es/components/file-preview/excel-preview/index.js +132 -0
- package/es/components/file-preview/excel-preview/index.module.scss.js +11 -0
- package/es/components/file-preview/excel-preview/utils.js +46 -0
- package/es/components/file-preview/img-preview/index.js +18 -0
- package/es/components/file-preview/img-preview/index.module.scss.js +17 -0
- package/es/components/file-preview/index.js +124 -0
- package/es/components/file-preview/index.module.scss.js +32 -0
- package/es/components/file-preview/json-preview/index.js +166 -0
- package/es/components/file-preview/markdown-preview/index.js +53 -0
- package/es/components/file-preview/markdown-preview/index.module.scss.js +1055 -0
- package/es/components/file-preview/parquet-preview/index.js +54 -0
- package/es/components/file-preview/pdf-preview/index.js +215 -0
- package/es/components/file-preview/pdf-preview/index.module.scss.js +16 -0
- package/es/components/file-preview/table-preview/index.js +43 -0
- package/es/components/file-preview/table-preview/index.module.scss.js +11 -0
- package/es/components/file-preview/txt-preview/index.js +24 -0
- package/es/components/file-preview/util.js +94 -0
- package/es/components/file-uploader/components/circle-progress.css.js +39 -0
- package/es/components/file-uploader/components/circle-progress.js +12 -0
- package/es/components/file-uploader/components/hooks/use-drop-zone.js +74 -0
- package/es/components/file-uploader/components/hooks/use-file-validation.js +52 -0
- package/es/components/file-uploader/components/icons.js +19 -0
- package/es/components/file-uploader/components/theme.css.js +64 -0
- package/es/components/file-uploader/components/uploader-drop-zone.css.js +66 -0
- package/es/components/file-uploader/components/uploader-drop-zone.js +74 -0
- package/es/components/file-uploader/components/uploader-file-item.css.js +186 -0
- package/es/components/file-uploader/components/uploader-file-item.js +63 -0
- package/es/components/file-uploader/components/uploader-file-list.css.js +43 -0
- package/es/components/file-uploader/components/uploader-file-list.js +27 -0
- package/es/components/file-uploader/components/uploader.css.js +20 -0
- package/es/components/file-uploader/components/uploader.js +51 -0
- package/es/components/file-uploader/components/uploading-status.css.js +52 -0
- package/es/components/file-uploader/components/uploading-status.js +54 -0
- package/es/components/file-uploader/components/utils/directory-reader.js +65 -0
- package/es/components/file-uploader/constants.js +31 -0
- package/es/components/file-uploader/context/action-registry.js +69 -0
- package/es/components/file-uploader/context/file-state-store.js +83 -0
- package/es/components/file-uploader/context/handler-registry.js +119 -0
- package/es/components/file-uploader/context/upload-context.js +36 -0
- package/es/components/file-uploader/context/upload-provider.js +77 -0
- package/es/components/file-uploader/context/upload-reducer.js +21 -0
- package/es/components/file-uploader/context/use-upload-engine.js +440 -0
- package/es/components/file-uploader/engine/queue-callbacks.js +257 -0
- package/es/components/file-uploader/engine/queue-manager.js +195 -0
- package/es/components/file-uploader/engine/queue-uploader.js +25 -0
- package/es/components/file-uploader/hooks/use-upload.js +327 -0
- package/es/components/file-uploader/utils/chunk-handlers.js +66 -0
- package/es/components/file-uploader/utils/ensure-handlers.js +53 -0
- package/es/components/file-uploader/utils/error-handler.js +84 -0
- package/es/components/file-uploader/utils/upload-controllers.js +43 -0
- package/es/components/file-uploader/utils/upload-handler.js +68 -0
- package/es/components/file-uploader/utils/validate-handlers.js +16 -0
- package/es/components/floating-label-input/index.js +46 -0
- package/es/components/floating-label-input/index.module.scss.js +30 -0
- package/es/components/floating-layer/index.js +15 -0
- package/es/components/floating-layer/index.scss.js +31 -0
- package/es/components/header/index.js +10 -0
- package/es/components/header/index.module.scss.js +16 -0
- package/es/components/input-tag/index.js +65 -0
- package/es/components/menu/index.js +96 -0
- package/es/components/menu/index.module.scss.js +188 -0
- package/es/components/model-card/index.js +20 -0
- package/es/components/model-card/index.module.scss.js +116 -0
- package/es/components/notion-editor/code-block/index.js +18 -0
- package/es/components/notion-editor/code-block/languageDetector.js +134 -0
- package/es/components/notion-editor/code-block/languages.js +42 -0
- package/es/components/notion-editor/index.js +258 -0
- package/es/components/notion-editor/index.scss.js +421 -0
- package/es/components/notion-editor/parseMarkdown.js +184 -0
- package/es/components/operator-chain/components/AddButton.js +20 -0
- package/es/components/operator-chain/components/IOCard.js +8 -0
- package/es/components/operator-chain/components/SingleCard.js +12 -0
- package/es/components/operator-chain/components/VirtualDropdown.js +56 -0
- package/es/components/operator-chain/index.js +83 -0
- package/es/components/operator-chain/index.module.scss.js +232 -0
- package/es/components/permission-editor/index.js +9 -0
- package/es/components/permission-editor/permissionEditModal/index.js +37 -0
- package/es/components/permission-editor/permissionEditor/index.js +253 -0
- package/es/components/permission-editor/permissionEditor/index.module.scss.js +22 -0
- package/es/components/permission-editor/permissionViewPopover/index.js +9 -0
- package/es/components/popover-select/index.js +42 -0
- package/es/components/popover-select/index.module.scss.js +22 -0
- package/es/components/radio-card/index.js +24 -0
- package/es/components/radio-card/index.scss.js +58 -0
- package/es/components/section-heading/classNames.js +22 -0
- package/es/components/section-heading/components.js +27 -0
- package/es/components/section-heading/context.js +13 -0
- package/es/components/section-heading/index.css.js +648 -0
- package/es/components/section-heading/index.js +37 -0
- package/es/components/status-tag/index.js +31 -0
- package/es/components/tag-group-filter/dataSizeFilter.js +100 -0
- package/es/components/tag-group-filter/index.js +53 -0
- package/es/components/tag-group-filter/index.module.scss.js +134 -0
- package/es/components/tag-group-filter/tagFilter.js +19 -0
- package/es/components/tag-view/index.js +138 -0
- package/es/components/tag-view/index.module.scss.js +56 -0
- package/es/components/tag-view/useSize.js +41 -0
- package/es/components/tip-tap/bubble-menu.js +47 -0
- package/es/components/tip-tap/editor.js +34 -0
- package/es/components/tip-tap/extensions/index.js +133 -0
- package/es/components/tip-tap/extensions/markdown-paste.js +148 -0
- package/es/components/tip-tap/icons/index.js +29 -0
- package/es/components/tip-tap/reader.js +15 -0
- package/es/components/tip-tap/styles/editor.css.js +863 -0
- package/es/components/tip-tap/toolbar/components/color-picker.js +76 -0
- package/es/components/tip-tap/toolbar/components/heading-dropdown.js +44 -0
- package/es/components/tip-tap/toolbar/components/image-button.js +26 -0
- package/es/components/tip-tap/toolbar/components/link-button.js +107 -0
- package/es/components/tip-tap/toolbar/components/table-button.js +37 -0
- package/es/components/tip-tap/toolbar/components/toolbar-button.js +7 -0
- package/es/components/tip-tap/toolbar/index.js +39 -0
- package/es/components/uploadDrawer/UploadStoreProvider.js +61 -0
- package/es/components/uploadDrawer/fileUploadDrawer.js +66 -0
- package/es/components/uploadDrawer/fileUploadDrawerFileDragger.js +71 -0
- package/es/components/uploadDrawer/fileUploadDrawerList.js +54 -0
- package/es/components/uploadDrawer/fileUploadDrawerListProgressButton.js +54 -0
- package/es/components/uploadDrawer/hooks/useCancelUpload.js +37 -0
- package/es/components/uploadDrawer/hooks/useFilterFiles.js +107 -0
- package/es/components/uploadDrawer/hooks/useFinishUpload.js +33 -0
- package/es/components/uploadDrawer/hooks/useFormatFiles.js +54 -0
- package/es/components/uploadDrawer/hooks/useProgressButtonRef.js +22 -0
- package/es/components/uploadDrawer/hooks/useRemoveFilesInUploadQueue.js +21 -0
- package/es/components/uploadDrawer/hooks/useResumeUnfinishedUploads.js +52 -0
- package/es/components/uploadDrawer/hooks/useRetryUpload.js +35 -0
- package/es/components/uploadDrawer/hooks/useSaveUnfinishedUploads.js +42 -0
- package/es/components/uploadDrawer/hooks/useSetupUpload.js +80 -0
- package/es/components/uploadDrawer/hooks/useUploadFileToOSS.js +23 -0
- package/es/components/uploadDrawer/index.css.js +511 -0
- package/es/components/uploadDrawer/index.js +43 -0
- package/es/components/uploadDrawer/utils/calcDisplaySize.js +19 -0
- package/es/components/uploadDrawer/utils/constant.js +16 -0
- package/es/components/uploadDrawer/utils/createFileToUpload.js +51 -0
- package/es/components/uploadDrawer/utils/fileDB/deleteFileInStore.js +28 -0
- package/es/components/uploadDrawer/utils/fileDB/deleteObjectStore.js +28 -0
- package/es/components/uploadDrawer/utils/fileDB/handleAddFilesToDB.js +37 -0
- package/es/components/uploadDrawer/utils/fileDB/index.js +9 -0
- package/es/components/uploadDrawer/utils/fileDB/openDB.js +111 -0
- package/es/components/uploadDrawer/utils/retrieveAllFiles.js +110 -0
- package/es/components/uploadDrawer/utils/shouldCreateNewFile.js +13 -0
- package/es/components/uploadDrawer/utils/splitFileIntoChunk.js +15 -0
- package/es/index.js +42 -1
- package/es/lib/utils.js +8 -0
- package/lib/index.js +1 -1
- package/package.json +164 -154
- package/rollup.es.config.mjs +177 -0
- package/tsconfig.rollup.json +7 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import DataTable from '../data-table/index.js';
|
|
5
|
+
import { parseTable } from 'arrow-js-ffi';
|
|
6
|
+
import initWasm, { wasmMemory, readParquet } from 'parquet-wasm';
|
|
7
|
+
|
|
8
|
+
initWasm();
|
|
9
|
+
let WASM_MEMORY;
|
|
10
|
+
function ParquetPreview(props) {
|
|
11
|
+
var _a;
|
|
12
|
+
const ref = useRef(null);
|
|
13
|
+
const [parquetData, setParquetData] = useState();
|
|
14
|
+
const [containerHeight, setContainerHeight] = useState();
|
|
15
|
+
const [containerWidth, setContainerWidth] = useState();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!WASM_MEMORY) {
|
|
18
|
+
WASM_MEMORY = wasmMemory();
|
|
19
|
+
}
|
|
20
|
+
let ffiTable;
|
|
21
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var _a, _b, _c, _d;
|
|
23
|
+
try {
|
|
24
|
+
const resp = yield fetch(props.filePath);
|
|
25
|
+
const parquetUint8Array = new Uint8Array(yield resp.arrayBuffer());
|
|
26
|
+
// const start = new Date().getTime();
|
|
27
|
+
ffiTable = readParquet(parquetUint8Array).intoFFI();
|
|
28
|
+
const arrowTable = parseTable(WASM_MEMORY.buffer, ffiTable.arrayAddrs(), ffiTable.schemaAddr());
|
|
29
|
+
// 获取列名作为表头
|
|
30
|
+
const head = arrowTable.schema.fields.map((field) => field.name);
|
|
31
|
+
// console.log('+++ head', head);
|
|
32
|
+
// 获取数据
|
|
33
|
+
const data = [];
|
|
34
|
+
console.log('+++ arrowTable.numRows', arrowTable.numRows);
|
|
35
|
+
for (let i = 0; i < arrowTable.numRows; i++) {
|
|
36
|
+
data.push(Object.assign(Object.assign({}, arrowTable.get(i).toJSON()), { key: i.toString() }));
|
|
37
|
+
}
|
|
38
|
+
// const end = new Date().getTime();
|
|
39
|
+
// console.log('+++ 耗时', end - start);
|
|
40
|
+
setParquetData({ head, data });
|
|
41
|
+
setContainerHeight((_a = ref.current) === null || _a === void 0 ? void 0 : _a.clientHeight);
|
|
42
|
+
setContainerWidth((_b = ref.current) === null || _b === void 0 ? void 0 : _b.clientWidth);
|
|
43
|
+
(_c = props === null || props === void 0 ? void 0 : props.onSuccess) === null || _c === void 0 ? void 0 : _c.call(props);
|
|
44
|
+
ffiTable.drop();
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
(_d = props === null || props === void 0 ? void 0 : props.onError) === null || _d === void 0 ? void 0 : _d.call(props, e);
|
|
48
|
+
}
|
|
49
|
+
}))();
|
|
50
|
+
}, []);
|
|
51
|
+
return (jsx("div", { style: { height: '100%', overflow: 'auto', wordBreak: 'break-all' }, ref: ref, children: parquetData && (jsx(DataTable, { head: parquetData.head, data: parquetData.data, containerHeight: containerHeight, containerWidth: containerWidth, maxLines: (_a = props.tableConfig) === null || _a === void 0 ? void 0 : _a.maxLines })) }));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { ParquetPreview as default };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { appendAsset } from '../util.js';
|
|
3
|
+
import { useRef, useEffect } from 'react';
|
|
4
|
+
import { wrap } from './index.module.scss.js';
|
|
5
|
+
|
|
6
|
+
class OutputScale {
|
|
7
|
+
constructor() {
|
|
8
|
+
const pixelRatio = window.devicePixelRatio || 1;
|
|
9
|
+
this.sx = pixelRatio;
|
|
10
|
+
this.sy = pixelRatio;
|
|
11
|
+
}
|
|
12
|
+
get scaled() {
|
|
13
|
+
return this.sx !== 1 || this.sy !== 1;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function approximateFraction(x) {
|
|
17
|
+
// Fast paths for int numbers or their inversions.
|
|
18
|
+
if (Math.floor(x) === x) {
|
|
19
|
+
return [x, 1];
|
|
20
|
+
}
|
|
21
|
+
const xinv = 1 / x;
|
|
22
|
+
const limit = 8;
|
|
23
|
+
if (xinv > limit) {
|
|
24
|
+
return [1, limit];
|
|
25
|
+
}
|
|
26
|
+
else if (Math.floor(xinv) === xinv) {
|
|
27
|
+
return [1, xinv];
|
|
28
|
+
}
|
|
29
|
+
const x_ = x > 1 ? xinv : x;
|
|
30
|
+
// a/b and c/d are neighbours in Farey sequence.
|
|
31
|
+
let a = 0, b = 1, c = 1, d = 1;
|
|
32
|
+
// Limiting search to order 8.
|
|
33
|
+
// eslint-disable-next-line no-constant-condition
|
|
34
|
+
while (true) {
|
|
35
|
+
// Generating next term in sequence (order of q).
|
|
36
|
+
const p = a + c, q = b + d;
|
|
37
|
+
if (q > limit) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
if (x_ <= p / q) {
|
|
41
|
+
c = p;
|
|
42
|
+
d = q;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
a = p;
|
|
46
|
+
b = q;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
let result;
|
|
50
|
+
// Select closest of the neighbours to x.
|
|
51
|
+
if (x_ - a / b < c / d - x_) {
|
|
52
|
+
result = x_ === x ? [a, b] : [b, a];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
result = x_ === x ? [c, d] : [d, c];
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
function roundToDivide(x, div) {
|
|
60
|
+
const r = x % div;
|
|
61
|
+
return r === 0 ? x : Math.round(x - r + div);
|
|
62
|
+
}
|
|
63
|
+
function PdfPreview(props) {
|
|
64
|
+
const { filePath } = props;
|
|
65
|
+
const pdfContainer = useRef(null);
|
|
66
|
+
const pageSize = 3;
|
|
67
|
+
const lastScrollTop = useRef(0);
|
|
68
|
+
// eslint-disable-next-line
|
|
69
|
+
const pdfDoc = useRef(null);
|
|
70
|
+
const totalPages = useRef(0);
|
|
71
|
+
const loadedHeight = useRef(0);
|
|
72
|
+
const currentPage = useRef(0);
|
|
73
|
+
const loading = useRef(false);
|
|
74
|
+
const onScroll = (e) => {
|
|
75
|
+
const currentScrollTop = e.target.scrollTop;
|
|
76
|
+
// console.log('totalPages.current', totalPages.current);
|
|
77
|
+
// console.log('currentScrollTop', currentScrollTop);
|
|
78
|
+
// console.log('lastScrollTop.current', lastScrollTop.current);
|
|
79
|
+
// console.log('currentPage.current', currentPage.current);
|
|
80
|
+
// console.log(
|
|
81
|
+
// 'loadedHeight.current - 200 - pdfContainer.current!.clientHeight',
|
|
82
|
+
// loadedHeight.current - 200 - pdfContainer.current!.clientHeight,
|
|
83
|
+
// );
|
|
84
|
+
if (currentScrollTop > lastScrollTop.current &&
|
|
85
|
+
currentPage.current < totalPages.current &&
|
|
86
|
+
currentScrollTop > loadedHeight.current - 200 - pdfContainer.current.clientHeight) {
|
|
87
|
+
// debugger;
|
|
88
|
+
// 加载更多
|
|
89
|
+
loadMore();
|
|
90
|
+
}
|
|
91
|
+
lastScrollTop.current = currentScrollTop;
|
|
92
|
+
};
|
|
93
|
+
const loadMore = () => {
|
|
94
|
+
if (loading.current) {
|
|
95
|
+
return Promise.resolve();
|
|
96
|
+
}
|
|
97
|
+
// console.log('+++ load more');
|
|
98
|
+
loading.current = true;
|
|
99
|
+
// console.log('loading.current', loading.current);
|
|
100
|
+
const lastPage = currentPage.current + pageSize > totalPages.current
|
|
101
|
+
? totalPages.current
|
|
102
|
+
: currentPage.current + pageSize;
|
|
103
|
+
return new Promise((resolve) => {
|
|
104
|
+
if (pdfDoc.current) {
|
|
105
|
+
const canvasContainer = pdfContainer.current;
|
|
106
|
+
let length = lastPage - currentPage.current;
|
|
107
|
+
for (let i = currentPage.current + 1; i <= lastPage; i++) {
|
|
108
|
+
// 使用 pdfDoc.getPage(i) 获取第 i 页的数据
|
|
109
|
+
pdfDoc.current
|
|
110
|
+
.getPage(i)
|
|
111
|
+
// eslint-disable-next-line
|
|
112
|
+
.then((page) => {
|
|
113
|
+
// 可通过scale来调节初始的缩放比
|
|
114
|
+
const viewport = page.getViewport({
|
|
115
|
+
scale: window.devicePixelRatio || 1,
|
|
116
|
+
});
|
|
117
|
+
// 创建一个 canvas 元素,并设置元素的画布属性
|
|
118
|
+
const canvas = document.createElement('canvas');
|
|
119
|
+
canvas.setAttribute('id', 'the-canvas' + i);
|
|
120
|
+
const context = canvas.getContext('2d');
|
|
121
|
+
const MAX_CANVAS_PIXELS = 16777216;
|
|
122
|
+
const outputScale = new OutputScale();
|
|
123
|
+
const maxCanvasPixels = MAX_CANVAS_PIXELS;
|
|
124
|
+
const { width, height } = viewport;
|
|
125
|
+
{
|
|
126
|
+
const pixelsInViewport = width * height;
|
|
127
|
+
const maxScale = Math.sqrt(maxCanvasPixels / pixelsInViewport);
|
|
128
|
+
if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
|
|
129
|
+
outputScale.sx = maxScale;
|
|
130
|
+
outputScale.sy = maxScale;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const sfx = approximateFraction(outputScale.sx);
|
|
134
|
+
const sfy = approximateFraction(outputScale.sy);
|
|
135
|
+
canvas.width = roundToDivide(width * outputScale.sx, sfx[0]);
|
|
136
|
+
canvas.height = roundToDivide(height * outputScale.sy, sfy[0]);
|
|
137
|
+
const { style } = canvas;
|
|
138
|
+
style.width = roundToDivide(width, sfx[1]) + 'px';
|
|
139
|
+
style.height = roundToDivide(height, sfy[1]) + 'px';
|
|
140
|
+
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null;
|
|
141
|
+
const renderContext = {
|
|
142
|
+
canvasContext: context,
|
|
143
|
+
transform,
|
|
144
|
+
viewport,
|
|
145
|
+
};
|
|
146
|
+
// 将canvas元素加入到容器中
|
|
147
|
+
canvasContainer.appendChild(canvas);
|
|
148
|
+
// console.log('canvas.clientHeight', canvas.clientHeight);
|
|
149
|
+
// 使用 page.render 将数据渲染到画布上
|
|
150
|
+
return page.render(renderContext).promise.then(() => {
|
|
151
|
+
return new Promise((_resolve) => {
|
|
152
|
+
setTimeout(() => {
|
|
153
|
+
// console.log('timeout canvas.clientHeight', canvas.clientHeight);
|
|
154
|
+
loadedHeight.current = loadedHeight.current + canvas.clientHeight;
|
|
155
|
+
_resolve(1);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
})
|
|
160
|
+
// eslint-disable-next-line
|
|
161
|
+
.catch((e) => { })
|
|
162
|
+
.finally(() => {
|
|
163
|
+
length--;
|
|
164
|
+
if (length === 0) {
|
|
165
|
+
if (loadedHeight.current < pdfContainer.current.clientHeight &&
|
|
166
|
+
lastPage < totalPages.current) {
|
|
167
|
+
setTimeout(loadMore);
|
|
168
|
+
}
|
|
169
|
+
resolve(1);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
resolve(0);
|
|
176
|
+
}
|
|
177
|
+
}).then(() => {
|
|
178
|
+
loading.current = false;
|
|
179
|
+
currentPage.current = lastPage;
|
|
180
|
+
// console.log('loading.current', loading.current);
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
appendAsset([
|
|
185
|
+
'https://haina-datahub.zero2x.org/ossRoute/frontend/resources/npm/pdfjs-dist/4.7.76/build/pdf.min.mjs',
|
|
186
|
+
'https://haina-datahub.zero2x.org/ossRoute/frontend/resources/npm/pdfjs-dist/4.7.76/build/pdf.worker.min.mjs',
|
|
187
|
+
]).then(() => {
|
|
188
|
+
// eslint-disable-next-line
|
|
189
|
+
const pdfjsLib = window.pdfjsLib;
|
|
190
|
+
pdfjsLib
|
|
191
|
+
.getDocument({
|
|
192
|
+
url: filePath,
|
|
193
|
+
cMapUrl: 'https://haina-datahub.zero2x.org/ossRoute/frontend/resources/npm/pdfjs-dist/4.7.76/cmaps/',
|
|
194
|
+
cMapPacked: true,
|
|
195
|
+
})
|
|
196
|
+
// eslint-disable-next-line
|
|
197
|
+
.promise.then((doc) => {
|
|
198
|
+
var _a;
|
|
199
|
+
pdfDoc.current = doc;
|
|
200
|
+
// pdf 的总页数
|
|
201
|
+
totalPages.current = doc.numPages;
|
|
202
|
+
loadMore();
|
|
203
|
+
(_a = props === null || props === void 0 ? void 0 : props.onSuccess) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
204
|
+
})
|
|
205
|
+
// eslint-disable-next-line
|
|
206
|
+
.catch((e) => {
|
|
207
|
+
var _a;
|
|
208
|
+
(_a = props === null || props === void 0 ? void 0 : props.onError) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}, [filePath]);
|
|
212
|
+
return jsx("div", { ref: pdfContainer, className: wrap, onScroll: onScroll });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export { PdfPreview as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var style = document.createElement('style');
|
|
2
|
+
style.textContent = `.index-module__wrap___eXiLF {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
align-items: center;
|
|
6
|
+
height: 100%;
|
|
7
|
+
overflow: auto;
|
|
8
|
+
}
|
|
9
|
+
.index-module__wrap___eXiLF canvas {
|
|
10
|
+
max-width: 100%;
|
|
11
|
+
}`;
|
|
12
|
+
document.head.appendChild(style);
|
|
13
|
+
|
|
14
|
+
var wrap = "index-module__wrap___eXiLF";
|
|
15
|
+
|
|
16
|
+
export { wrap };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useState, useEffect } from 'react';
|
|
3
|
+
import DataTable from '../data-table/index.js';
|
|
4
|
+
import { wrap } from './index.module.scss.js';
|
|
5
|
+
|
|
6
|
+
function TablePreview(props) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const ref = useRef(null);
|
|
9
|
+
const [csvData, setCsvData] = useState();
|
|
10
|
+
const [csvContainerHeight, setCsvContainerHeight] = useState();
|
|
11
|
+
const [csvContainerWidth, setCsvContainerWidth] = useState();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const { tableConfig } = props;
|
|
15
|
+
const { header, rows = [] } = tableConfig || {};
|
|
16
|
+
if (header) {
|
|
17
|
+
const head = header;
|
|
18
|
+
const data = [];
|
|
19
|
+
rows.forEach((row, rowIndex) => {
|
|
20
|
+
const rowData = {
|
|
21
|
+
key: rowIndex.toString(),
|
|
22
|
+
};
|
|
23
|
+
head.forEach((cell, index) => {
|
|
24
|
+
rowData[cell] = row[index];
|
|
25
|
+
});
|
|
26
|
+
data.push(rowData);
|
|
27
|
+
});
|
|
28
|
+
setCsvData({
|
|
29
|
+
head,
|
|
30
|
+
data,
|
|
31
|
+
});
|
|
32
|
+
setCsvContainerHeight(ref.current.clientHeight);
|
|
33
|
+
setCsvContainerWidth(ref.current.clientWidth);
|
|
34
|
+
(_a = props === null || props === void 0 ? void 0 : props.onSuccess) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
(_b = props === null || props === void 0 ? void 0 : props.onError) === null || _b === void 0 ? void 0 : _b.call(props, new Error('tableConfig.header is required'));
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
return (jsx("div", { ref: ref, className: wrap, children: csvData ? (jsx(DataTable, { head: csvData.head, data: csvData.data, maxLines: (_a = props.tableConfig) === null || _a === void 0 ? void 0 : _a.maxLines, total: (_b = props.tableConfig) === null || _b === void 0 ? void 0 : _b.rowCount, containerHeight: csvContainerHeight, containerWidth: csvContainerWidth })) : null }));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { TablePreview as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var style = document.createElement('style');
|
|
2
|
+
style.textContent = `.index-module__wrap___YSAno {
|
|
3
|
+
height: 100%;
|
|
4
|
+
overflow-x: hidden;
|
|
5
|
+
overflow-y: auto;
|
|
6
|
+
}`;
|
|
7
|
+
document.head.appendChild(style);
|
|
8
|
+
|
|
9
|
+
var wrap = "index-module__wrap___YSAno";
|
|
10
|
+
|
|
11
|
+
export { wrap };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useState, useEffect } from 'react';
|
|
4
|
+
import { fetchFileWithAutoCode } from '../util.js';
|
|
5
|
+
|
|
6
|
+
function TxtPreview(props) {
|
|
7
|
+
const [content, setContent] = useState('');
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
try {
|
|
12
|
+
const result = yield fetchFileWithAutoCode(props.filePath);
|
|
13
|
+
setContent(result);
|
|
14
|
+
(_a = props === null || props === void 0 ? void 0 : props.onSuccess) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
(_b = props === null || props === void 0 ? void 0 : props.onError) === null || _b === void 0 ? void 0 : _b.call(props, e);
|
|
18
|
+
}
|
|
19
|
+
}))();
|
|
20
|
+
}, []);
|
|
21
|
+
return jsx("div", { style: { whiteSpace: 'pre-wrap', height: '100%', overflow: 'auto' }, children: content });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { TxtPreview as default };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { getFileExt } from '@zjlab-fe/util';
|
|
3
|
+
|
|
4
|
+
function appendAsset(assetUrlArr) {
|
|
5
|
+
return new Promise((resolve) => {
|
|
6
|
+
if (assetUrlArr && assetUrlArr.length > 0) {
|
|
7
|
+
const assetArr = [...assetUrlArr];
|
|
8
|
+
// eslint-disable-next-line
|
|
9
|
+
function appendNext() {
|
|
10
|
+
if (assetArr.length > 0) {
|
|
11
|
+
setTimeout(innerAppend);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
resolve(null);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// eslint-disable-next-line
|
|
20
|
+
function innerAppend() {
|
|
21
|
+
const currentAssetUrl = assetArr.shift();
|
|
22
|
+
const ext = getFileExt(currentAssetUrl);
|
|
23
|
+
if (ext === 'js' || ext === 'mjs') {
|
|
24
|
+
if (!document.querySelector(`script[src="${currentAssetUrl}"]`)) {
|
|
25
|
+
const script = document.createElement('script');
|
|
26
|
+
script.src = currentAssetUrl;
|
|
27
|
+
if (ext === 'mjs') {
|
|
28
|
+
script.type = 'module';
|
|
29
|
+
}
|
|
30
|
+
document.head.appendChild(script);
|
|
31
|
+
script.onload = appendNext;
|
|
32
|
+
script.onerror = appendNext;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (ext === 'css') {
|
|
37
|
+
if (!document.querySelector(`link[href="${currentAssetUrl}"]`)) {
|
|
38
|
+
const link = document.createElement('link');
|
|
39
|
+
link.rel = 'stylesheet';
|
|
40
|
+
link.href = currentAssetUrl;
|
|
41
|
+
document.head.appendChild(link);
|
|
42
|
+
link.onload = appendNext;
|
|
43
|
+
link.onerror = appendNext;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
appendNext();
|
|
48
|
+
}
|
|
49
|
+
innerAppend();
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
resolve(null);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetch 文件并自动判断编码解析(未知编码场景)
|
|
58
|
+
* 优先尝试:GBK → GB2312 → Big5 → UTF-8,按实际业务调整优先级
|
|
59
|
+
* @param {string} fileUrl - 文件地址
|
|
60
|
+
* @returns {Promise<string>} 解码后的正常字符串
|
|
61
|
+
*/
|
|
62
|
+
function fetchFileWithAutoCode(fileUrl) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const response = yield fetch(fileUrl);
|
|
65
|
+
if (!response.ok)
|
|
66
|
+
throw new Error(`请求失败:${response.status}`);
|
|
67
|
+
const arrayBuffer = yield response.arrayBuffer();
|
|
68
|
+
let resultStr = '';
|
|
69
|
+
// 定义待尝试的编码列表(按业务场景调整优先级)
|
|
70
|
+
const codeList = ['utf-8', 'gbk', 'gb2312', 'big5', 'gb18030'];
|
|
71
|
+
// 遍历编码尝试解码,成功则立即返回
|
|
72
|
+
for (const code of codeList) {
|
|
73
|
+
try {
|
|
74
|
+
// `fatal: true` 表示编码不匹配时抛出错误,进入下一次尝试
|
|
75
|
+
const decoder = new TextDecoder(code, { fatal: true });
|
|
76
|
+
resultStr = decoder.decode(arrayBuffer);
|
|
77
|
+
// console.log(`文件编码匹配成功:${code}`);
|
|
78
|
+
break; // 解码成功,退出循环
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
// 该编码不匹配,继续尝试下一个
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// 若所有编码都失败,返回原始UTF-8解码结果(兜底)
|
|
86
|
+
if (!resultStr) {
|
|
87
|
+
resultStr = new TextDecoder('utf-8').decode(arrayBuffer);
|
|
88
|
+
console.warn('未匹配到已知编码,返回UTF-8兜底结果(可能乱码)');
|
|
89
|
+
}
|
|
90
|
+
return resultStr;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { appendAsset, fetchFileWithAutoCode };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var style = document.createElement('style');
|
|
2
|
+
style.textContent = `.styled-progress-circle {
|
|
3
|
+
display: flex;
|
|
4
|
+
align-items: center;
|
|
5
|
+
justify-content: center;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.styled-progress-circle svg {
|
|
9
|
+
transform: rotate(-90deg);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.styled-progress-circle circle {
|
|
13
|
+
fill: none;
|
|
14
|
+
stroke-width: 10;
|
|
15
|
+
stroke-linecap: round;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.styled-progress-circle .circle-bg {
|
|
19
|
+
stroke: var(--uploader-progress-track);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.styled-progress-circle .circle-progress {
|
|
23
|
+
stroke: var(--uploader-progress-fill);
|
|
24
|
+
transition: stroke-dashoffset 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.styled-progress-circle.progress-failed .circle-progress {
|
|
28
|
+
stroke: var(--uploader-progress-failed);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.styled-progress-circle.progress-success .circle-progress {
|
|
32
|
+
stroke: var(--uploader-progress-success);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
`;
|
|
39
|
+
document.head.appendChild(style);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import './circle-progress.css.js';
|
|
3
|
+
|
|
4
|
+
// Circle Progress Component
|
|
5
|
+
function CircleProgress({ percent, isFailed, isSuccess, }) {
|
|
6
|
+
const radius = 50;
|
|
7
|
+
const circumference = 2 * Math.PI * radius;
|
|
8
|
+
const offset = circumference - (percent / 100) * circumference;
|
|
9
|
+
return (jsx("div", { className: `styled-progress-circle ${isFailed ? 'progress-failed' : isSuccess ? 'progress-success' : ''}`, children: jsxs("svg", { width: "20", height: "20", viewBox: "0 0 120 120", children: [jsx("circle", { className: "circle-bg", cx: "60", cy: "60", r: radius }), jsx("circle", { className: "circle-progress", cx: "60", cy: "60", r: radius, strokeDasharray: circumference, strokeDashoffset: offset })] }) }));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { CircleProgress };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { useState, useRef, useCallback } from 'react';
|
|
3
|
+
import { readEntry } from '../utils/directory-reader.js';
|
|
4
|
+
|
|
5
|
+
function useDropZone({ disabled, directory, accept, onFilesReady, onError }) {
|
|
6
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
7
|
+
const dragCounterRef = useRef(0);
|
|
8
|
+
const handleDragEnter = useCallback((e) => {
|
|
9
|
+
e.preventDefault();
|
|
10
|
+
e.stopPropagation();
|
|
11
|
+
if (disabled)
|
|
12
|
+
return;
|
|
13
|
+
dragCounterRef.current += 1;
|
|
14
|
+
if (e.dataTransfer.items && e.dataTransfer.items.length > 0) {
|
|
15
|
+
setIsDragging(true);
|
|
16
|
+
}
|
|
17
|
+
}, [disabled]);
|
|
18
|
+
const handleDragOver = useCallback((e) => {
|
|
19
|
+
e.preventDefault();
|
|
20
|
+
e.stopPropagation();
|
|
21
|
+
if (disabled)
|
|
22
|
+
return;
|
|
23
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
24
|
+
}, [disabled]);
|
|
25
|
+
const handleDragLeave = useCallback((e) => {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
e.stopPropagation();
|
|
28
|
+
if (disabled)
|
|
29
|
+
return;
|
|
30
|
+
dragCounterRef.current -= 1;
|
|
31
|
+
if (dragCounterRef.current === 0) {
|
|
32
|
+
setIsDragging(false);
|
|
33
|
+
}
|
|
34
|
+
}, [disabled]);
|
|
35
|
+
const handleDrop = useCallback((e) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
e.preventDefault();
|
|
37
|
+
e.stopPropagation();
|
|
38
|
+
if (disabled)
|
|
39
|
+
return;
|
|
40
|
+
setIsDragging(false);
|
|
41
|
+
dragCounterRef.current = 0;
|
|
42
|
+
try {
|
|
43
|
+
const items = Array.from(e.dataTransfer.items);
|
|
44
|
+
const filesWithPaths = [];
|
|
45
|
+
// Always use webkitGetAsEntry for better handling
|
|
46
|
+
// When directory=false, directories will be skipped automatically
|
|
47
|
+
const entries = items.map((item) => item.webkitGetAsEntry()).filter(Boolean);
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (entry) {
|
|
50
|
+
const entryFiles = yield readEntry(entry, accept, directory);
|
|
51
|
+
filesWithPaths.push(...entryFiles);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (filesWithPaths.length > 0) {
|
|
55
|
+
onFilesReady(filesWithPaths);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
onError === null || onError === void 0 ? void 0 : onError({
|
|
60
|
+
type: 'DROP_FAILED',
|
|
61
|
+
message: error instanceof Error ? error.message : 'Failed to process dropped files',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}), [disabled, directory, accept, onFilesReady, onError]);
|
|
65
|
+
return {
|
|
66
|
+
isDragging,
|
|
67
|
+
handleDragEnter,
|
|
68
|
+
handleDragOver,
|
|
69
|
+
handleDragLeave,
|
|
70
|
+
handleDrop,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { useDropZone };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
function useFileValidation({ maxSize, maxFiles, fileValidation, onDrop, onError, }) {
|
|
5
|
+
const validateFiles = useCallback((files) => __awaiter(this, void 0, void 0, function* () {
|
|
6
|
+
const valid = [];
|
|
7
|
+
const invalid = [];
|
|
8
|
+
// Step 1: Filter by file size
|
|
9
|
+
for (const fileWithPath of files) {
|
|
10
|
+
if (maxSize && fileWithPath.file.size > maxSize) {
|
|
11
|
+
invalid.push(fileWithPath);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
valid.push(fileWithPath);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// Step 2: Filter by max files count
|
|
18
|
+
if (maxFiles && valid.length > maxFiles) {
|
|
19
|
+
const excess = valid.splice(maxFiles);
|
|
20
|
+
invalid.push(...excess);
|
|
21
|
+
}
|
|
22
|
+
// Step 3: Apply custom validation callback
|
|
23
|
+
if (fileValidation && valid.length > 0) {
|
|
24
|
+
const validationResults = yield Promise.all(valid.map((fwp) => fileValidation(fwp.file)));
|
|
25
|
+
const passedFiles = valid.filter((_, index) => validationResults[index]);
|
|
26
|
+
const failedFiles = valid.filter((_, index) => !validationResults[index]);
|
|
27
|
+
valid.length = 0;
|
|
28
|
+
valid.push(...passedFiles);
|
|
29
|
+
invalid.push(...failedFiles);
|
|
30
|
+
}
|
|
31
|
+
return { valid, invalid };
|
|
32
|
+
}), [maxSize, maxFiles, fileValidation]);
|
|
33
|
+
const processFiles = useCallback((files) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const { valid, invalid } = yield validateFiles(files);
|
|
35
|
+
if (invalid.length > 0) {
|
|
36
|
+
const error = {
|
|
37
|
+
type: maxSize && invalid.some((fwp) => fwp.file.size > maxSize) ? 'FILE_TOO_LARGE' : 'TOO_MANY_FILES',
|
|
38
|
+
message: maxSize && invalid.some((fwp) => fwp.file.size > maxSize)
|
|
39
|
+
? `${invalid.length} file(s) exceed maximum size`
|
|
40
|
+
: `Too many files. Maximum ${maxFiles} allowed`,
|
|
41
|
+
rejectedFiles: invalid.map((fwp) => fwp.file),
|
|
42
|
+
};
|
|
43
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
44
|
+
}
|
|
45
|
+
if (valid.length > 0) {
|
|
46
|
+
onDrop(valid);
|
|
47
|
+
}
|
|
48
|
+
}), [validateFiles, maxSize, maxFiles, onDrop, onError]);
|
|
49
|
+
return { processFiles };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { useFileValidation };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
function UploadIcon(props) {
|
|
4
|
+
return (jsx("svg", Object.assign({ width: "34", height: "31", viewBox: "0 0 34 31", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, props, { children: jsxs("g", { id: "\u00E4\u00B8\u008A\u00E4\u00BC\u00A0\u00E6\u008F\u0092\u00E5\u009B\u00BE", children: [jsx("path", { id: "Vector", d: "M26 8.66665V29.7043C26.0013 29.867 25.9705 30.0284 25.9094 30.1792C25.8483 30.33 25.7581 30.4672 25.6439 30.5831C25.5297 30.699 25.3938 30.7913 25.244 30.8547C25.0941 30.918 24.9332 30.9512 24.7705 30.9523H1.22943C0.903577 30.9523 0.591055 30.823 0.360528 30.5927C0.130002 30.3624 0.000328142 30.05 0 29.7241V1.22819C0 0.563332 0.553428 0 1.23562 0H17.3333V7.42856C17.3333 7.75692 17.4638 8.07184 17.6959 8.30402C17.9281 8.53621 18.243 8.66665 18.5714 8.66665H26ZM26 6.19047H19.8095V0.00371423L26 6.19047Z", fill: "#B9D6FF" }), jsxs("g", { id: "Group 1000006993", children: [jsx("circle", { id: "Ellipse 87", cx: "26", cy: "23", r: "8", fill: "#1775FE" }), jsx("path", { id: "Vector_2", d: "M26.4545 24.315V27.5714H25.5455V24.315L24.3034 25.2023L23.775 24.4625L26 22.8732L28.225 24.4625L27.6966 25.2023L26.4545 24.315ZM31 24.4545C31 25.7098 29.9825 26.7273 28.7273 26.7273H27.3636V25.8182H28.7273C29.0749 25.8184 29.4094 25.6858 29.6625 25.4476C29.9156 25.2094 30.0682 24.8835 30.0891 24.5365C30.11 24.1896 29.9976 23.8477 29.7749 23.5808C29.5522 23.314 29.236 23.1422 28.8909 23.1007L28.4568 23.0489L28.4918 22.6127C28.4973 22.5455 28.5 22.4775 28.5 22.4091C28.5 21.0284 27.3807 19.9091 26 19.9091C25.4245 19.9091 24.8666 20.1077 24.4205 20.4712C23.9744 20.8347 23.6672 21.3409 23.5509 21.9045L23.4955 22.175L23.2295 22.2507C22.8492 22.3591 22.5146 22.5885 22.2763 22.9042C22.038 23.2198 21.9091 23.6045 21.9091 24C21.9091 24.4822 22.1006 24.9447 22.4416 25.2856C22.7826 25.6266 23.2451 25.8182 23.7273 25.8182H24.6364V26.7273H23.7273C22.2211 26.7273 21 25.5061 21 24C21 22.8655 21.6989 21.8682 22.7239 21.4632C22.9292 20.753 23.3598 20.1288 23.9506 19.6846C24.5415 19.2403 25.2607 19.0001 26 19C27.8414 19 29.3416 20.4598 29.4068 22.2852C29.8687 22.4302 30.2723 22.7187 30.5588 23.1089C30.8453 23.499 30.9999 23.9705 31 24.4545Z", fill: "white" })] })] }) })));
|
|
5
|
+
}
|
|
6
|
+
function FileIcon() {
|
|
7
|
+
return (jsx("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" }) }));
|
|
8
|
+
}
|
|
9
|
+
function CloseIcon() {
|
|
10
|
+
return (jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: jsx("path", { d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" }) }));
|
|
11
|
+
}
|
|
12
|
+
function PauseIcon() {
|
|
13
|
+
return (jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: jsx("path", { d: "M6 19h4V5H6v14zm8-14v14h4V5h-4z" }) }));
|
|
14
|
+
}
|
|
15
|
+
function ResumeIcon() {
|
|
16
|
+
return (jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", children: jsx("path", { d: "M8 5v14l11-7z" }) }));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { CloseIcon, FileIcon, PauseIcon, ResumeIcon, UploadIcon as default };
|