ywana-core8 0.0.842 → 0.0.844
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/index.cjs +54 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +25 -1
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +54 -36
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +57 -40
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -1
- package/src/html/textfield-outlined.css +1 -1
- package/src/html/textfield.test.js +1 -3
- package/src/http/client.js +14 -8
- package/src/incubator/task.js +4 -5
- package/src/site/site.css +24 -0
- package/src/site/site.js +34 -19
- package/src/site/site.test.js +7 -5
- package/src/test.js +0 -67
- package/src_old/upload/UploadArea.js +0 -80
- package/src_old/upload/UploadDialog.js +0 -41
- package/src_old/upload/UploadFile.js +0 -29
- package/src_old/upload/index.js +0 -4
- package/src_old/upload/uploader.css +0 -58
- package/src_old/upload/uploader.js +0 -87
@@ -1,87 +0,0 @@
|
|
1
|
-
import React, { useState, useMemo } from 'react'
|
2
|
-
import ResumableJS from 'resumablejs'
|
3
|
-
import { UploadArea } from "./UploadArea";
|
4
|
-
import { UploadFile } from "./UploadFile";
|
5
|
-
import './uploader.css'
|
6
|
-
|
7
|
-
const STATES = {
|
8
|
-
IDLE: 0, RUNNING: 1, SUCCESS: 2, ERROR: 3, COMPLETED: 4
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
* Uploader
|
13
|
-
*/
|
14
|
-
export const Uploader = ({ label, target, accept, simultaneousUploads = 1, className, onProgress, onSuccess, onError, onComplete, errors = [] }) => {
|
15
|
-
|
16
|
-
|
17
|
-
const resumable = useMemo(() => {
|
18
|
-
const config = {
|
19
|
-
target: target,
|
20
|
-
chunkSize: 1 * 1024 * 1024,
|
21
|
-
simultaneousUploads,
|
22
|
-
testChunks: false,
|
23
|
-
throttleProgressCallbacks: 1,
|
24
|
-
fileType: accept
|
25
|
-
}
|
26
|
-
const resumable = new ResumableJS(config)
|
27
|
-
resumable.on('fileAdded', onFileAdded)
|
28
|
-
resumable.on('fileProgress', onFileProgress)
|
29
|
-
resumable.on('fileSuccess', onFileSuccess)
|
30
|
-
resumable.on('fileError', onFileError)
|
31
|
-
resumable.on('complete', onAllComplete)
|
32
|
-
return resumable
|
33
|
-
}, [])
|
34
|
-
|
35
|
-
const [progress, setProgress] = useState(0)
|
36
|
-
const [state, setState] = useState(STATES.IDLE)
|
37
|
-
const [error, setError] = useState()
|
38
|
-
const [files, setFiles] = useState([])
|
39
|
-
|
40
|
-
function onFileAdded(file) {
|
41
|
-
files.push(file)
|
42
|
-
setFiles(files)
|
43
|
-
setState(STATES.RUNNING)
|
44
|
-
resumable.upload()
|
45
|
-
}
|
46
|
-
|
47
|
-
function onFileProgress(file) {
|
48
|
-
const progress = file.progress()
|
49
|
-
setProgress(progress)
|
50
|
-
if (onProgress) onProgress(files);
|
51
|
-
}
|
52
|
-
|
53
|
-
function onFileSuccess(file, message) {
|
54
|
-
setState(STATES.SUCCESS)
|
55
|
-
if (onSuccess) onSuccess(file, message)
|
56
|
-
}
|
57
|
-
|
58
|
-
function onFileError(file, message) {
|
59
|
-
setError(message)
|
60
|
-
setState(STATES.ERROR)
|
61
|
-
if (onError) onError(file, message)
|
62
|
-
}
|
63
|
-
|
64
|
-
function onAllComplete() {
|
65
|
-
setState(STATES.IDLE)
|
66
|
-
if (onComplete) onComplete(files)
|
67
|
-
}
|
68
|
-
|
69
|
-
return (
|
70
|
-
<div className={`uploader ${className}`}>
|
71
|
-
{state === STATES.IDLE ? <UploadArea resumable={resumable} state={state} label={label} error={error} progress={progress} /> : null}
|
72
|
-
{state === STATES.RUNNING || STATES.SUCCESS || STATES.ERROR ? <UploadProgress files={files} errors={errors} /> : null}
|
73
|
-
</div>
|
74
|
-
)
|
75
|
-
}
|
76
|
-
|
77
|
-
const UploadProgress = ({ files = [], errors }) => {
|
78
|
-
return (
|
79
|
-
<div>
|
80
|
-
{files.map((file) => {
|
81
|
-
const error2 = errors.some((e) => e === file.fileName) ? "Fichero Mal Nombrado" : "";
|
82
|
-
const progress = 1
|
83
|
-
return <UploadFile file={file} state={STATES.RUNNING} progress={file.progress()} />;
|
84
|
-
})}
|
85
|
-
</div>
|
86
|
-
);
|
87
|
-
};
|