@v-c/upload 1.0.0 → 1.1.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/AjaxUploader.js +37 -16
- package/dist/Upload.js +14 -6
- package/dist/attrAccept.js +2 -0
- package/dist/index.js +4 -2
- package/dist/interface.d.ts +2 -1
- package/dist/request.js +2 -0
- package/dist/traverseFileTree.js +3 -2
- package/dist/uid.js +2 -0
- package/package.json +11 -5
- package/dist/AjaxUploader.cjs +0 -415
- package/dist/Upload.cjs +0 -196
- package/dist/_virtual/rolldown_runtime.cjs +0 -21
- package/dist/attrAccept.cjs +0 -34
- package/dist/index.cjs +0 -7
- package/dist/interface.cjs +0 -1
- package/dist/request.cjs +0 -60
- package/dist/traverseFileTree.cjs +0 -55
- package/dist/uid.cjs +0 -10
package/dist/AjaxUploader.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import attrAccept_default from "./attrAccept.js";
|
|
2
2
|
import upload from "./request.js";
|
|
3
|
-
import
|
|
3
|
+
import traverseFileTree from "./traverseFileTree.js";
|
|
4
4
|
import uid from "./uid.js";
|
|
5
5
|
import { computed, createVNode, defineComponent, mergeProps, onMounted, onUnmounted, onUpdated, ref } from "vue";
|
|
6
6
|
import { clsx } from "@v-c/util";
|
|
7
7
|
import pickAttrs from "@v-c/util/dist/pickAttrs";
|
|
8
|
+
//#region src/AjaxUploader.tsx
|
|
8
9
|
function noop() {}
|
|
9
|
-
var
|
|
10
|
+
var AjaxUploader = /* @__PURE__ */ defineComponent((props, { attrs, expose, slots }) => {
|
|
10
11
|
const uid$1 = ref(uid());
|
|
11
12
|
let _isMounted = false;
|
|
12
13
|
const reqs = {};
|
|
@@ -48,7 +49,7 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
48
49
|
const post = ({ data, origin, action, parsedFile }) => {
|
|
49
50
|
if (!_isMounted) return;
|
|
50
51
|
const { onStart, customRequest, name, headers, withCredentials, method } = props;
|
|
51
|
-
const { uid
|
|
52
|
+
const { uid } = origin;
|
|
52
53
|
const request = customRequest || upload;
|
|
53
54
|
const requestOption = {
|
|
54
55
|
action,
|
|
@@ -65,17 +66,20 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
65
66
|
onSuccess: (ret, xhr) => {
|
|
66
67
|
const { onSuccess } = props;
|
|
67
68
|
onSuccess?.(ret, parsedFile, xhr);
|
|
68
|
-
delete reqs[uid
|
|
69
|
+
delete reqs[uid];
|
|
69
70
|
},
|
|
70
71
|
onError: (err, ret) => {
|
|
71
72
|
const { onError } = props;
|
|
72
73
|
onError?.(err, ret, parsedFile);
|
|
73
|
-
delete reqs[uid
|
|
74
|
+
delete reqs[uid];
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
onStart?.(origin);
|
|
77
|
-
reqs[uid
|
|
78
|
+
reqs[uid] = request(requestOption, { defaultRequest: upload });
|
|
78
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Process file before upload. When all the file is ready, we start upload.
|
|
82
|
+
*/
|
|
79
83
|
const processFile = async (file, fileList) => {
|
|
80
84
|
const { beforeUpload } = props;
|
|
81
85
|
let transformedFile = file;
|
|
@@ -137,7 +141,7 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
137
141
|
let files = [...dataTransfer.files || []];
|
|
138
142
|
if (files.length > 0 || items.some((item) => item.kind === "file")) existFileCallback?.();
|
|
139
143
|
if (directory) {
|
|
140
|
-
files = await
|
|
144
|
+
files = await traverseFileTree(Array.prototype.slice.call(items), (currentFile) => filterFile(currentFile));
|
|
141
145
|
uploadFiles(files);
|
|
142
146
|
} else {
|
|
143
147
|
let acceptFiles = [...files].filter((file) => filterFile(file, true));
|
|
@@ -145,6 +149,18 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
145
149
|
uploadFiles(acceptFiles);
|
|
146
150
|
}
|
|
147
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Retry upload for a file. The origin file passed to `onStart` / `onError`
|
|
154
|
+
* should be provided so it can be processed and posted again.
|
|
155
|
+
* A retry is ignored while a request for the same uid is still in flight.
|
|
156
|
+
*/
|
|
157
|
+
const retry = (originFile) => {
|
|
158
|
+
const { uid } = originFile;
|
|
159
|
+
processFile(originFile, [originFile]).then((fileInfo) => {
|
|
160
|
+
if (reqs[uid]) return;
|
|
161
|
+
if (fileInfo.parsedFile) post(fileInfo);
|
|
162
|
+
}).catch(() => {});
|
|
163
|
+
};
|
|
148
164
|
const onFileDrop = (e) => {
|
|
149
165
|
e.preventDefault();
|
|
150
166
|
if (e.type === "drop") {
|
|
@@ -160,7 +176,8 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
160
176
|
};
|
|
161
177
|
const onChange = (e) => {
|
|
162
178
|
const { files } = e.target;
|
|
163
|
-
|
|
179
|
+
const acceptedFiles = [...files || []].filter((file) => filterFile(file));
|
|
180
|
+
uploadFiles(acceptedFiles);
|
|
164
181
|
reset();
|
|
165
182
|
};
|
|
166
183
|
const dirProps = computed(() => {
|
|
@@ -171,12 +188,12 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
171
188
|
});
|
|
172
189
|
const abort = (file) => {
|
|
173
190
|
if (file) {
|
|
174
|
-
const uid
|
|
175
|
-
if (reqs[uid
|
|
176
|
-
delete reqs[uid
|
|
177
|
-
} else Object.keys(reqs).forEach((uid
|
|
178
|
-
if (reqs[uid
|
|
179
|
-
delete reqs[uid
|
|
191
|
+
const uid = file.uid ? file.uid : file;
|
|
192
|
+
if (reqs[uid] && reqs[uid].abort) reqs[uid].abort();
|
|
193
|
+
delete reqs[uid];
|
|
194
|
+
} else Object.keys(reqs).forEach((uid) => {
|
|
195
|
+
if (reqs[uid] && reqs[uid].abort) reqs[uid].abort();
|
|
196
|
+
delete reqs[uid];
|
|
180
197
|
});
|
|
181
198
|
};
|
|
182
199
|
const events = computed(() => {
|
|
@@ -217,7 +234,10 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
217
234
|
abort();
|
|
218
235
|
document.removeEventListener("paste", onFilePaste);
|
|
219
236
|
});
|
|
220
|
-
expose({
|
|
237
|
+
expose({
|
|
238
|
+
abort,
|
|
239
|
+
retry
|
|
240
|
+
});
|
|
221
241
|
return () => {
|
|
222
242
|
const { component, prefixCls, className, classNames = {}, disabled, id, name, style, styles = {}, multiple, accept, capture, directory, openFileDialogOnClick, onMouseEnter, onMouseLeave, hasControlInside, ...otherProps } = {
|
|
223
243
|
...props,
|
|
@@ -405,4 +425,5 @@ var AjaxUploader_default = /* @__PURE__ */ defineComponent((props, { attrs, expo
|
|
|
405
425
|
default: void 0
|
|
406
426
|
}
|
|
407
427
|
} });
|
|
408
|
-
|
|
428
|
+
//#endregion
|
|
429
|
+
export { AjaxUploader as default };
|
package/dist/Upload.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import AjaxUploader from "./AjaxUploader.js";
|
|
2
2
|
import { computed, createVNode, defineComponent, mergeDefaults, mergeProps, ref } from "vue";
|
|
3
|
+
//#region src/Upload.tsx
|
|
3
4
|
function empty() {}
|
|
4
5
|
var defaults = {
|
|
5
6
|
component: "span",
|
|
@@ -17,19 +18,25 @@ var defaults = {
|
|
|
17
18
|
openFileDialogOnClick: true,
|
|
18
19
|
hasControlInside: false
|
|
19
20
|
};
|
|
20
|
-
var
|
|
21
|
+
var Upload = /* @__PURE__ */ defineComponent((props, { attrs, expose, slots }) => {
|
|
21
22
|
const uploaderRef = ref();
|
|
22
23
|
const abort = (file) => {
|
|
23
24
|
uploaderRef.value?.abort(file);
|
|
24
25
|
};
|
|
25
|
-
|
|
26
|
+
const retry = (file) => {
|
|
27
|
+
uploaderRef.value?.retry(file);
|
|
28
|
+
};
|
|
29
|
+
expose({
|
|
30
|
+
abort,
|
|
31
|
+
retry
|
|
32
|
+
});
|
|
26
33
|
const mergedProps = computed(() => ({
|
|
27
34
|
...defaults,
|
|
28
35
|
...props
|
|
29
36
|
}));
|
|
30
|
-
return () => createVNode(
|
|
37
|
+
return () => createVNode(AjaxUploader, mergeProps({ "ref": uploaderRef }, mergedProps.value, attrs), { default: () => [slots.default?.()] });
|
|
31
38
|
}, {
|
|
32
|
-
props:
|
|
39
|
+
props: /*@__PURE__*/ mergeDefaults({
|
|
33
40
|
name: {
|
|
34
41
|
type: String,
|
|
35
42
|
required: false,
|
|
@@ -187,4 +194,5 @@ var Upload_default = /* @__PURE__ */ defineComponent((props, { attrs, expose, sl
|
|
|
187
194
|
}, defaults),
|
|
188
195
|
name: "Upload"
|
|
189
196
|
});
|
|
190
|
-
|
|
197
|
+
//#endregion
|
|
198
|
+
export { Upload as default };
|
package/dist/attrAccept.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { warning } from "@v-c/util";
|
|
2
|
+
//#region src/attrAccept.ts
|
|
2
3
|
var attrAccept_default = (file, acceptedFiles) => {
|
|
3
4
|
if (file && acceptedFiles) {
|
|
4
5
|
const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(",");
|
|
@@ -26,4 +27,5 @@ var attrAccept_default = (file, acceptedFiles) => {
|
|
|
26
27
|
}
|
|
27
28
|
return true;
|
|
28
29
|
};
|
|
30
|
+
//#endregion
|
|
29
31
|
export { attrAccept_default as default };
|
package/dist/index.js
CHANGED
package/dist/interface.d.ts
CHANGED
|
@@ -20,7 +20,8 @@ export interface UploadProgressEvent extends Partial<ProgressEvent> {
|
|
|
20
20
|
percent?: number;
|
|
21
21
|
}
|
|
22
22
|
export interface AjaxUploaderExpose {
|
|
23
|
-
abort: (file
|
|
23
|
+
abort: (file?: any) => void;
|
|
24
|
+
retry: (file: VcFile) => void;
|
|
24
25
|
}
|
|
25
26
|
export interface UploadRequestOption<T = any> {
|
|
26
27
|
onProgress?: (event: UploadProgressEvent, file?: UploadRequestFile) => void;
|
package/dist/request.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/request.ts
|
|
1
2
|
function getError(option, xhr) {
|
|
2
3
|
const msg = `cannot ${option.method} ${option.action} ${xhr.status}'`;
|
|
3
4
|
const err = new Error(msg);
|
|
@@ -53,4 +54,5 @@ function upload(option) {
|
|
|
53
54
|
xhr.abort();
|
|
54
55
|
} };
|
|
55
56
|
}
|
|
57
|
+
//#endregion
|
|
56
58
|
export { upload as default };
|
package/dist/traverseFileTree.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/traverseFileTree.ts
|
|
1
2
|
async function traverseFileTree(files, isAccepted) {
|
|
2
3
|
const flattenFileList = [];
|
|
3
4
|
const progressFileList = [];
|
|
@@ -47,5 +48,5 @@ async function traverseFileTree(files, isAccepted) {
|
|
|
47
48
|
}
|
|
48
49
|
return flattenFileList;
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
export {
|
|
51
|
+
//#endregion
|
|
52
|
+
export { traverseFileTree as default };
|
package/dist/uid.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@v-c/upload",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/antdv-next/vue-components/tree/next/packages/upload",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/antdv-next/vue-components.git"
|
|
10
|
+
},
|
|
5
11
|
"exports": {
|
|
6
12
|
".": {
|
|
7
13
|
"types": "./dist/index.d.ts",
|
|
8
14
|
"import": "./dist/index.js",
|
|
9
|
-
"
|
|
15
|
+
"default": "./dist/index.js"
|
|
10
16
|
},
|
|
11
17
|
"./dist/*": "./dist/*",
|
|
12
18
|
"./package.json": "./package.json"
|
|
@@ -23,12 +29,12 @@
|
|
|
23
29
|
"vue": "^3.0.0"
|
|
24
30
|
},
|
|
25
31
|
"dependencies": {
|
|
26
|
-
"@v-c/util": "^1.0
|
|
32
|
+
"@v-c/util": "^1.2.0"
|
|
27
33
|
},
|
|
28
34
|
"devDependencies": {
|
|
29
35
|
"@types/nise": "^1.4.5",
|
|
30
|
-
"nise": "^6.1.
|
|
31
|
-
"vue": "^3.5.
|
|
36
|
+
"nise": "^6.1.5",
|
|
37
|
+
"vue": "^3.5.39"
|
|
32
38
|
},
|
|
33
39
|
"scripts": {
|
|
34
40
|
"build": "vite build",
|
package/dist/AjaxUploader.cjs
DELETED
|
@@ -1,415 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_attrAccept = require("./attrAccept.cjs");
|
|
7
|
-
const require_request = require("./request.cjs");
|
|
8
|
-
const require_traverseFileTree = require("./traverseFileTree.cjs");
|
|
9
|
-
const require_uid = require("./uid.cjs");
|
|
10
|
-
let vue = require("vue");
|
|
11
|
-
let _v_c_util = require("@v-c/util");
|
|
12
|
-
let _v_c_util_dist_pickAttrs = require("@v-c/util/dist/pickAttrs");
|
|
13
|
-
_v_c_util_dist_pickAttrs = require_rolldown_runtime.__toESM(_v_c_util_dist_pickAttrs);
|
|
14
|
-
function noop() {}
|
|
15
|
-
var AjaxUploader = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, expose, slots }) => {
|
|
16
|
-
const uid$1 = (0, vue.ref)(require_uid.default());
|
|
17
|
-
let _isMounted = false;
|
|
18
|
-
const reqs = {};
|
|
19
|
-
const fileInputRef = (0, vue.ref)();
|
|
20
|
-
const cls = (0, vue.computed)(() => {
|
|
21
|
-
const { prefixCls, disabled, className } = props;
|
|
22
|
-
return (0, _v_c_util.clsx)({
|
|
23
|
-
[prefixCls]: true,
|
|
24
|
-
[`${prefixCls}-disabled`]: disabled,
|
|
25
|
-
[className]: className
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
const filterFile = (file, force = false) => {
|
|
29
|
-
const { accept, directory } = props;
|
|
30
|
-
let filterFn;
|
|
31
|
-
let acceptFormat;
|
|
32
|
-
if (typeof accept === "string") acceptFormat = accept;
|
|
33
|
-
else {
|
|
34
|
-
const { filter, format } = accept || {};
|
|
35
|
-
acceptFormat = format;
|
|
36
|
-
if (filter === "native") filterFn = () => true;
|
|
37
|
-
else filterFn = filter;
|
|
38
|
-
}
|
|
39
|
-
return (filterFn || (directory || force ? (currentFile) => require_attrAccept.default(currentFile, acceptFormat) : () => true))(file);
|
|
40
|
-
};
|
|
41
|
-
const onClick = (event) => {
|
|
42
|
-
if (!fileInputRef.value) return;
|
|
43
|
-
const target = event.target;
|
|
44
|
-
if (target && target.tagName === "BUTTON") {
|
|
45
|
-
fileInputRef.value.parentNode.focus();
|
|
46
|
-
target.blur();
|
|
47
|
-
}
|
|
48
|
-
fileInputRef.value.click();
|
|
49
|
-
if (props.onClick) props.onClick(event);
|
|
50
|
-
};
|
|
51
|
-
const onKeyDown = (e) => {
|
|
52
|
-
if (e.key === "Enter") onClick(e);
|
|
53
|
-
};
|
|
54
|
-
const post = ({ data, origin, action, parsedFile }) => {
|
|
55
|
-
if (!_isMounted) return;
|
|
56
|
-
const { onStart, customRequest, name, headers, withCredentials, method } = props;
|
|
57
|
-
const { uid: uid$2 } = origin;
|
|
58
|
-
const request = customRequest || require_request.default;
|
|
59
|
-
const requestOption = {
|
|
60
|
-
action,
|
|
61
|
-
filename: name,
|
|
62
|
-
data,
|
|
63
|
-
file: parsedFile,
|
|
64
|
-
headers,
|
|
65
|
-
withCredentials,
|
|
66
|
-
method: method || "post",
|
|
67
|
-
onProgress: (e) => {
|
|
68
|
-
const { onProgress } = props;
|
|
69
|
-
onProgress?.(e, parsedFile);
|
|
70
|
-
},
|
|
71
|
-
onSuccess: (ret, xhr) => {
|
|
72
|
-
const { onSuccess } = props;
|
|
73
|
-
onSuccess?.(ret, parsedFile, xhr);
|
|
74
|
-
delete reqs[uid$2];
|
|
75
|
-
},
|
|
76
|
-
onError: (err, ret) => {
|
|
77
|
-
const { onError } = props;
|
|
78
|
-
onError?.(err, ret, parsedFile);
|
|
79
|
-
delete reqs[uid$2];
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
onStart?.(origin);
|
|
83
|
-
reqs[uid$2] = request(requestOption, { defaultRequest: require_request.default });
|
|
84
|
-
};
|
|
85
|
-
const processFile = async (file, fileList) => {
|
|
86
|
-
const { beforeUpload } = props;
|
|
87
|
-
let transformedFile = file;
|
|
88
|
-
if (beforeUpload) {
|
|
89
|
-
try {
|
|
90
|
-
transformedFile = await beforeUpload(file, fileList);
|
|
91
|
-
} catch (e) {
|
|
92
|
-
transformedFile = false;
|
|
93
|
-
}
|
|
94
|
-
if (transformedFile === false) return {
|
|
95
|
-
origin: file,
|
|
96
|
-
parsedFile: null,
|
|
97
|
-
action: null,
|
|
98
|
-
data: null
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
const { action } = props;
|
|
102
|
-
let mergedAction;
|
|
103
|
-
if (typeof action === "function") mergedAction = await action(file);
|
|
104
|
-
else mergedAction = action;
|
|
105
|
-
const { data } = props;
|
|
106
|
-
let mergedData;
|
|
107
|
-
if (typeof data === "function") mergedData = await data(file);
|
|
108
|
-
else mergedData = data;
|
|
109
|
-
const parsedData = (typeof transformedFile === "object" || typeof transformedFile === "string") && transformedFile ? transformedFile : file;
|
|
110
|
-
let parsedFile;
|
|
111
|
-
if (parsedData instanceof File) parsedFile = parsedData;
|
|
112
|
-
else parsedFile = new File([parsedData], file.name, { type: file.type });
|
|
113
|
-
const mergedParsedFile = parsedFile;
|
|
114
|
-
mergedParsedFile.uid = file.uid;
|
|
115
|
-
return {
|
|
116
|
-
origin: file,
|
|
117
|
-
data: mergedData,
|
|
118
|
-
parsedFile: mergedParsedFile,
|
|
119
|
-
action: mergedAction
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
const uploadFiles = (files) => {
|
|
123
|
-
const originFiles = [...files];
|
|
124
|
-
const postFiles = originFiles.map((file) => {
|
|
125
|
-
file.uid = require_uid.default();
|
|
126
|
-
return processFile(file, originFiles);
|
|
127
|
-
});
|
|
128
|
-
Promise.all(postFiles).then((fileList) => {
|
|
129
|
-
const { onBatchStart } = props;
|
|
130
|
-
onBatchStart?.(fileList.map(({ origin, parsedFile }) => ({
|
|
131
|
-
file: origin,
|
|
132
|
-
parsedFile
|
|
133
|
-
})));
|
|
134
|
-
fileList.filter((file) => file.parsedFile !== null).forEach((file) => {
|
|
135
|
-
post(file);
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
const onDataTransferFiles = async (dataTransfer, existFileCallback) => {
|
|
140
|
-
if (!dataTransfer) return;
|
|
141
|
-
const { multiple, directory } = props;
|
|
142
|
-
const items = [...dataTransfer.items || []];
|
|
143
|
-
let files = [...dataTransfer.files || []];
|
|
144
|
-
if (files.length > 0 || items.some((item) => item.kind === "file")) existFileCallback?.();
|
|
145
|
-
if (directory) {
|
|
146
|
-
files = await require_traverseFileTree.default(Array.prototype.slice.call(items), (currentFile) => filterFile(currentFile));
|
|
147
|
-
uploadFiles(files);
|
|
148
|
-
} else {
|
|
149
|
-
let acceptFiles = [...files].filter((file) => filterFile(file, true));
|
|
150
|
-
if (multiple === false) acceptFiles = files.slice(0, 1);
|
|
151
|
-
uploadFiles(acceptFiles);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
const onFileDrop = (e) => {
|
|
155
|
-
e.preventDefault();
|
|
156
|
-
if (e.type === "drop") {
|
|
157
|
-
const dataTransfer = e.dataTransfer;
|
|
158
|
-
return onDataTransferFiles(dataTransfer);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
const onFileDragOver = (e) => {
|
|
162
|
-
e.preventDefault();
|
|
163
|
-
};
|
|
164
|
-
const reset = () => {
|
|
165
|
-
uid$1.value = require_uid.default();
|
|
166
|
-
};
|
|
167
|
-
const onChange = (e) => {
|
|
168
|
-
const { files } = e.target;
|
|
169
|
-
uploadFiles([...files || []].filter((file) => filterFile(file)));
|
|
170
|
-
reset();
|
|
171
|
-
};
|
|
172
|
-
const dirProps = (0, vue.computed)(() => {
|
|
173
|
-
return props.directory ? {
|
|
174
|
-
directory: "directory",
|
|
175
|
-
webkitdirectory: "webkitdirectory"
|
|
176
|
-
} : {};
|
|
177
|
-
});
|
|
178
|
-
const abort = (file) => {
|
|
179
|
-
if (file) {
|
|
180
|
-
const uid$2 = file.uid ? file.uid : file;
|
|
181
|
-
if (reqs[uid$2] && reqs[uid$2].abort) reqs[uid$2].abort();
|
|
182
|
-
delete reqs[uid$2];
|
|
183
|
-
} else Object.keys(reqs).forEach((uid$2) => {
|
|
184
|
-
if (reqs[uid$2] && reqs[uid$2].abort) reqs[uid$2].abort();
|
|
185
|
-
delete reqs[uid$2];
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
const events = (0, vue.computed)(() => {
|
|
189
|
-
return props.disabled ? {} : {
|
|
190
|
-
onClick: props.openFileDialogOnClick ? onClick : noop,
|
|
191
|
-
onKeyDown: props.openFileDialogOnClick ? onKeyDown : noop,
|
|
192
|
-
onMouseEnter: props.onMouseEnter,
|
|
193
|
-
onMouseLeave: props.onMouseLeave,
|
|
194
|
-
onDrop: onFileDrop,
|
|
195
|
-
onDragover: onFileDragOver,
|
|
196
|
-
tabIndex: props.hasControlInside ? void 0 : "0"
|
|
197
|
-
};
|
|
198
|
-
});
|
|
199
|
-
const onFilePaste = async (e) => {
|
|
200
|
-
const { pastable } = props;
|
|
201
|
-
if (!pastable) return;
|
|
202
|
-
if (e.type === "paste") {
|
|
203
|
-
const clipboardData = e.clipboardData;
|
|
204
|
-
return onDataTransferFiles(clipboardData, () => {
|
|
205
|
-
e.preventDefault();
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
let prevPastable;
|
|
210
|
-
(0, vue.onMounted)(() => {
|
|
211
|
-
_isMounted = true;
|
|
212
|
-
if (props.pastable) document.addEventListener("paste", onFilePaste);
|
|
213
|
-
prevPastable = props.pastable;
|
|
214
|
-
});
|
|
215
|
-
(0, vue.onUpdated)(() => {
|
|
216
|
-
const pastable = props.pastable;
|
|
217
|
-
if (pastable && !prevPastable) document.addEventListener("paste", onFilePaste);
|
|
218
|
-
else if (!pastable && prevPastable) document.removeEventListener("paste", onFilePaste);
|
|
219
|
-
prevPastable = pastable;
|
|
220
|
-
});
|
|
221
|
-
(0, vue.onUnmounted)(() => {
|
|
222
|
-
_isMounted = false;
|
|
223
|
-
abort();
|
|
224
|
-
document.removeEventListener("paste", onFilePaste);
|
|
225
|
-
});
|
|
226
|
-
expose({ abort });
|
|
227
|
-
return () => {
|
|
228
|
-
const { component, prefixCls, className, classNames = {}, disabled, id, name, style, styles = {}, multiple, accept, capture, directory, openFileDialogOnClick, onMouseEnter, onMouseLeave, hasControlInside, ...otherProps } = {
|
|
229
|
-
...props,
|
|
230
|
-
...attrs
|
|
231
|
-
};
|
|
232
|
-
const acceptFormat = typeof accept === "string" ? accept : accept?.format;
|
|
233
|
-
return (0, vue.createVNode)(component, (0, vue.mergeProps)({ "class": cls.value }, events.value, {
|
|
234
|
-
"role": hasControlInside ? void 0 : "button",
|
|
235
|
-
"style": style
|
|
236
|
-
}), { default: () => [(0, vue.createVNode)("input", (0, vue.mergeProps)((0, _v_c_util_dist_pickAttrs.default)(otherProps, {
|
|
237
|
-
aria: true,
|
|
238
|
-
data: true
|
|
239
|
-
}), {
|
|
240
|
-
"id": id,
|
|
241
|
-
"name": name,
|
|
242
|
-
"disabled": disabled,
|
|
243
|
-
"type": "file",
|
|
244
|
-
"ref": fileInputRef,
|
|
245
|
-
"onClick": (e) => e.stopPropagation(),
|
|
246
|
-
"key": uid$1.value,
|
|
247
|
-
"style": {
|
|
248
|
-
display: "none",
|
|
249
|
-
...styles.input
|
|
250
|
-
},
|
|
251
|
-
"class": classNames.input
|
|
252
|
-
}, dirProps.value, {
|
|
253
|
-
"multiple": multiple,
|
|
254
|
-
"accept": acceptFormat,
|
|
255
|
-
"onChange": onChange
|
|
256
|
-
}, capture != null ? { capture } : {}), null), slots.default?.()] });
|
|
257
|
-
};
|
|
258
|
-
}, { props: {
|
|
259
|
-
name: {
|
|
260
|
-
type: String,
|
|
261
|
-
required: false,
|
|
262
|
-
default: void 0
|
|
263
|
-
},
|
|
264
|
-
style: {
|
|
265
|
-
type: Object,
|
|
266
|
-
required: false,
|
|
267
|
-
default: void 0
|
|
268
|
-
},
|
|
269
|
-
className: {
|
|
270
|
-
type: String,
|
|
271
|
-
required: false,
|
|
272
|
-
default: void 0
|
|
273
|
-
},
|
|
274
|
-
disabled: {
|
|
275
|
-
type: Boolean,
|
|
276
|
-
required: false,
|
|
277
|
-
default: void 0
|
|
278
|
-
},
|
|
279
|
-
component: {
|
|
280
|
-
type: [
|
|
281
|
-
Object,
|
|
282
|
-
Function,
|
|
283
|
-
String
|
|
284
|
-
],
|
|
285
|
-
required: false,
|
|
286
|
-
default: void 0
|
|
287
|
-
},
|
|
288
|
-
action: {
|
|
289
|
-
type: [String, Function],
|
|
290
|
-
required: false,
|
|
291
|
-
default: void 0
|
|
292
|
-
},
|
|
293
|
-
method: {
|
|
294
|
-
type: String,
|
|
295
|
-
required: false,
|
|
296
|
-
default: void 0
|
|
297
|
-
},
|
|
298
|
-
directory: {
|
|
299
|
-
type: Boolean,
|
|
300
|
-
required: false,
|
|
301
|
-
default: void 0
|
|
302
|
-
},
|
|
303
|
-
data: {
|
|
304
|
-
type: [Object, Function],
|
|
305
|
-
required: false,
|
|
306
|
-
default: void 0
|
|
307
|
-
},
|
|
308
|
-
headers: {
|
|
309
|
-
type: Object,
|
|
310
|
-
required: false,
|
|
311
|
-
default: void 0
|
|
312
|
-
},
|
|
313
|
-
accept: {
|
|
314
|
-
type: [String, Object],
|
|
315
|
-
required: false,
|
|
316
|
-
default: void 0
|
|
317
|
-
},
|
|
318
|
-
multiple: {
|
|
319
|
-
type: Boolean,
|
|
320
|
-
required: false,
|
|
321
|
-
default: void 0
|
|
322
|
-
},
|
|
323
|
-
onBatchStart: {
|
|
324
|
-
type: Function,
|
|
325
|
-
required: false,
|
|
326
|
-
default: void 0
|
|
327
|
-
},
|
|
328
|
-
onStart: {
|
|
329
|
-
type: Function,
|
|
330
|
-
required: false,
|
|
331
|
-
default: void 0
|
|
332
|
-
},
|
|
333
|
-
onError: {
|
|
334
|
-
type: Function,
|
|
335
|
-
required: false,
|
|
336
|
-
default: void 0
|
|
337
|
-
},
|
|
338
|
-
onSuccess: {
|
|
339
|
-
type: Function,
|
|
340
|
-
required: false,
|
|
341
|
-
default: void 0
|
|
342
|
-
},
|
|
343
|
-
onProgress: {
|
|
344
|
-
type: Function,
|
|
345
|
-
required: false,
|
|
346
|
-
default: void 0
|
|
347
|
-
},
|
|
348
|
-
beforeUpload: {
|
|
349
|
-
type: Function,
|
|
350
|
-
required: false,
|
|
351
|
-
default: void 0
|
|
352
|
-
},
|
|
353
|
-
customRequest: {
|
|
354
|
-
type: Function,
|
|
355
|
-
required: false,
|
|
356
|
-
default: void 0
|
|
357
|
-
},
|
|
358
|
-
withCredentials: {
|
|
359
|
-
type: Boolean,
|
|
360
|
-
required: false,
|
|
361
|
-
default: void 0
|
|
362
|
-
},
|
|
363
|
-
openFileDialogOnClick: {
|
|
364
|
-
type: Boolean,
|
|
365
|
-
required: false,
|
|
366
|
-
default: void 0
|
|
367
|
-
},
|
|
368
|
-
prefixCls: {
|
|
369
|
-
type: String,
|
|
370
|
-
required: false,
|
|
371
|
-
default: void 0
|
|
372
|
-
},
|
|
373
|
-
id: {
|
|
374
|
-
type: String,
|
|
375
|
-
required: false,
|
|
376
|
-
default: void 0
|
|
377
|
-
},
|
|
378
|
-
onMouseEnter: {
|
|
379
|
-
type: Function,
|
|
380
|
-
required: false,
|
|
381
|
-
default: void 0
|
|
382
|
-
},
|
|
383
|
-
onMouseLeave: {
|
|
384
|
-
type: Function,
|
|
385
|
-
required: false,
|
|
386
|
-
default: void 0
|
|
387
|
-
},
|
|
388
|
-
onClick: {
|
|
389
|
-
type: Function,
|
|
390
|
-
required: false,
|
|
391
|
-
default: void 0
|
|
392
|
-
},
|
|
393
|
-
classNames: {
|
|
394
|
-
type: Object,
|
|
395
|
-
required: false,
|
|
396
|
-
default: void 0
|
|
397
|
-
},
|
|
398
|
-
styles: {
|
|
399
|
-
type: Object,
|
|
400
|
-
required: false,
|
|
401
|
-
default: void 0
|
|
402
|
-
},
|
|
403
|
-
hasControlInside: {
|
|
404
|
-
type: Boolean,
|
|
405
|
-
required: false,
|
|
406
|
-
default: void 0
|
|
407
|
-
},
|
|
408
|
-
pastable: {
|
|
409
|
-
type: Boolean,
|
|
410
|
-
required: false,
|
|
411
|
-
default: void 0
|
|
412
|
-
}
|
|
413
|
-
} });
|
|
414
|
-
var AjaxUploader_default = AjaxUploader;
|
|
415
|
-
exports.default = AjaxUploader_default;
|
package/dist/Upload.cjs
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
const require_AjaxUploader = require("./AjaxUploader.cjs");
|
|
7
|
-
let vue = require("vue");
|
|
8
|
-
function empty() {}
|
|
9
|
-
var defaults = {
|
|
10
|
-
component: "span",
|
|
11
|
-
prefixCls: "vc-upload",
|
|
12
|
-
data: {},
|
|
13
|
-
headers: {},
|
|
14
|
-
name: "file",
|
|
15
|
-
onStart: empty,
|
|
16
|
-
onError: empty,
|
|
17
|
-
onSuccess: empty,
|
|
18
|
-
multiple: false,
|
|
19
|
-
beforeUpload: void 0,
|
|
20
|
-
customRequest: void 0,
|
|
21
|
-
withCredentials: false,
|
|
22
|
-
openFileDialogOnClick: true,
|
|
23
|
-
hasControlInside: false
|
|
24
|
-
};
|
|
25
|
-
var Upload = /* @__PURE__ */ (0, vue.defineComponent)((props, { attrs, expose, slots }) => {
|
|
26
|
-
const uploaderRef = (0, vue.ref)();
|
|
27
|
-
const abort = (file) => {
|
|
28
|
-
uploaderRef.value?.abort(file);
|
|
29
|
-
};
|
|
30
|
-
expose({ abort });
|
|
31
|
-
const mergedProps = (0, vue.computed)(() => ({
|
|
32
|
-
...defaults,
|
|
33
|
-
...props
|
|
34
|
-
}));
|
|
35
|
-
return () => (0, vue.createVNode)(require_AjaxUploader.default, (0, vue.mergeProps)({ "ref": uploaderRef }, mergedProps.value, attrs), { default: () => [slots.default?.()] });
|
|
36
|
-
}, {
|
|
37
|
-
props: /* @__PURE__ */ (0, vue.mergeDefaults)({
|
|
38
|
-
name: {
|
|
39
|
-
type: String,
|
|
40
|
-
required: false,
|
|
41
|
-
default: void 0
|
|
42
|
-
},
|
|
43
|
-
style: {
|
|
44
|
-
type: Object,
|
|
45
|
-
required: false,
|
|
46
|
-
default: void 0
|
|
47
|
-
},
|
|
48
|
-
className: {
|
|
49
|
-
type: String,
|
|
50
|
-
required: false,
|
|
51
|
-
default: void 0
|
|
52
|
-
},
|
|
53
|
-
disabled: {
|
|
54
|
-
type: Boolean,
|
|
55
|
-
required: false,
|
|
56
|
-
default: void 0
|
|
57
|
-
},
|
|
58
|
-
component: {
|
|
59
|
-
type: [
|
|
60
|
-
Object,
|
|
61
|
-
Function,
|
|
62
|
-
String
|
|
63
|
-
],
|
|
64
|
-
required: false,
|
|
65
|
-
default: void 0
|
|
66
|
-
},
|
|
67
|
-
action: {
|
|
68
|
-
type: [String, Function],
|
|
69
|
-
required: false,
|
|
70
|
-
default: void 0
|
|
71
|
-
},
|
|
72
|
-
method: {
|
|
73
|
-
type: String,
|
|
74
|
-
required: false,
|
|
75
|
-
default: void 0
|
|
76
|
-
},
|
|
77
|
-
directory: {
|
|
78
|
-
type: Boolean,
|
|
79
|
-
required: false,
|
|
80
|
-
default: void 0
|
|
81
|
-
},
|
|
82
|
-
data: {
|
|
83
|
-
type: [Object, Function],
|
|
84
|
-
required: false,
|
|
85
|
-
default: void 0
|
|
86
|
-
},
|
|
87
|
-
headers: {
|
|
88
|
-
type: Object,
|
|
89
|
-
required: false,
|
|
90
|
-
default: void 0
|
|
91
|
-
},
|
|
92
|
-
accept: {
|
|
93
|
-
type: [String, Object],
|
|
94
|
-
required: false,
|
|
95
|
-
default: void 0
|
|
96
|
-
},
|
|
97
|
-
multiple: {
|
|
98
|
-
type: Boolean,
|
|
99
|
-
required: false,
|
|
100
|
-
default: void 0
|
|
101
|
-
},
|
|
102
|
-
onBatchStart: {
|
|
103
|
-
type: Function,
|
|
104
|
-
required: false,
|
|
105
|
-
default: void 0
|
|
106
|
-
},
|
|
107
|
-
onStart: {
|
|
108
|
-
type: Function,
|
|
109
|
-
required: false,
|
|
110
|
-
default: void 0
|
|
111
|
-
},
|
|
112
|
-
onError: {
|
|
113
|
-
type: Function,
|
|
114
|
-
required: false,
|
|
115
|
-
default: void 0
|
|
116
|
-
},
|
|
117
|
-
onSuccess: {
|
|
118
|
-
type: Function,
|
|
119
|
-
required: false,
|
|
120
|
-
default: void 0
|
|
121
|
-
},
|
|
122
|
-
onProgress: {
|
|
123
|
-
type: Function,
|
|
124
|
-
required: false,
|
|
125
|
-
default: void 0
|
|
126
|
-
},
|
|
127
|
-
beforeUpload: {
|
|
128
|
-
type: Function,
|
|
129
|
-
required: false,
|
|
130
|
-
default: void 0
|
|
131
|
-
},
|
|
132
|
-
customRequest: {
|
|
133
|
-
type: Function,
|
|
134
|
-
required: false,
|
|
135
|
-
default: void 0
|
|
136
|
-
},
|
|
137
|
-
withCredentials: {
|
|
138
|
-
type: Boolean,
|
|
139
|
-
required: false,
|
|
140
|
-
default: void 0
|
|
141
|
-
},
|
|
142
|
-
openFileDialogOnClick: {
|
|
143
|
-
type: Boolean,
|
|
144
|
-
required: false,
|
|
145
|
-
default: void 0
|
|
146
|
-
},
|
|
147
|
-
prefixCls: {
|
|
148
|
-
type: String,
|
|
149
|
-
required: false,
|
|
150
|
-
default: void 0
|
|
151
|
-
},
|
|
152
|
-
id: {
|
|
153
|
-
type: String,
|
|
154
|
-
required: false,
|
|
155
|
-
default: void 0
|
|
156
|
-
},
|
|
157
|
-
onMouseEnter: {
|
|
158
|
-
type: Function,
|
|
159
|
-
required: false,
|
|
160
|
-
default: void 0
|
|
161
|
-
},
|
|
162
|
-
onMouseLeave: {
|
|
163
|
-
type: Function,
|
|
164
|
-
required: false,
|
|
165
|
-
default: void 0
|
|
166
|
-
},
|
|
167
|
-
onClick: {
|
|
168
|
-
type: Function,
|
|
169
|
-
required: false,
|
|
170
|
-
default: void 0
|
|
171
|
-
},
|
|
172
|
-
classNames: {
|
|
173
|
-
type: Object,
|
|
174
|
-
required: false,
|
|
175
|
-
default: void 0
|
|
176
|
-
},
|
|
177
|
-
styles: {
|
|
178
|
-
type: Object,
|
|
179
|
-
required: false,
|
|
180
|
-
default: void 0
|
|
181
|
-
},
|
|
182
|
-
hasControlInside: {
|
|
183
|
-
type: Boolean,
|
|
184
|
-
required: false,
|
|
185
|
-
default: void 0
|
|
186
|
-
},
|
|
187
|
-
pastable: {
|
|
188
|
-
type: Boolean,
|
|
189
|
-
required: false,
|
|
190
|
-
default: void 0
|
|
191
|
-
}
|
|
192
|
-
}, defaults),
|
|
193
|
-
name: "Upload"
|
|
194
|
-
});
|
|
195
|
-
var Upload_default = Upload;
|
|
196
|
-
exports.default = Upload_default;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __copyProps = (to, from, except, desc) => {
|
|
8
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
9
|
-
key = keys[i];
|
|
10
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
11
|
-
get: ((k) => from[k]).bind(null, key),
|
|
12
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
18
|
-
value: mod,
|
|
19
|
-
enumerable: true
|
|
20
|
-
}) : target, mod));
|
|
21
|
-
exports.__toESM = __toESM;
|
package/dist/attrAccept.cjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
const require_rolldown_runtime = require("./_virtual/rolldown_runtime.cjs");
|
|
6
|
-
let _v_c_util = require("@v-c/util");
|
|
7
|
-
var attrAccept_default = (file, acceptedFiles) => {
|
|
8
|
-
if (file && acceptedFiles) {
|
|
9
|
-
const acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(",");
|
|
10
|
-
const fileName = file.name || "";
|
|
11
|
-
const mimeType = file.type || "";
|
|
12
|
-
const baseMimeType = mimeType.replace(/\/.*$/, "");
|
|
13
|
-
return acceptedFilesArray.some((type) => {
|
|
14
|
-
const validType = type.trim();
|
|
15
|
-
if (/^\*(\/\*)?$/.test(type)) return true;
|
|
16
|
-
if (validType.charAt(0) === ".") {
|
|
17
|
-
const lowerFileName = fileName.toLowerCase();
|
|
18
|
-
const lowerType = validType.toLowerCase();
|
|
19
|
-
let affixList = [lowerType];
|
|
20
|
-
if (lowerType === ".jpg" || lowerType === ".jpeg") affixList = [".jpg", ".jpeg"];
|
|
21
|
-
return affixList.some((affix) => lowerFileName.endsWith(affix));
|
|
22
|
-
}
|
|
23
|
-
if (/\/\*$/.test(validType)) return baseMimeType === validType.replace(/\/.*$/, "");
|
|
24
|
-
if (mimeType === validType) return true;
|
|
25
|
-
if (/^\w+$/.test(validType)) {
|
|
26
|
-
(0, _v_c_util.warning)(false, `Upload takes an invalidate 'accept' type '${validType}'.Skip for check.`);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
};
|
|
34
|
-
exports.default = attrAccept_default;
|
package/dist/index.cjs
DELETED
package/dist/interface.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
package/dist/request.cjs
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
function getError(option, xhr) {
|
|
6
|
-
const msg = `cannot ${option.method} ${option.action} ${xhr.status}'`;
|
|
7
|
-
const err = new Error(msg);
|
|
8
|
-
err.status = xhr.status;
|
|
9
|
-
err.method = option.method;
|
|
10
|
-
err.url = option.action;
|
|
11
|
-
return err;
|
|
12
|
-
}
|
|
13
|
-
function getBody(xhr) {
|
|
14
|
-
const text = xhr.responseText || xhr.response;
|
|
15
|
-
if (!text) return text;
|
|
16
|
-
try {
|
|
17
|
-
return JSON.parse(text);
|
|
18
|
-
} catch (e) {
|
|
19
|
-
return text;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function upload(option) {
|
|
23
|
-
const xhr = new XMLHttpRequest();
|
|
24
|
-
if (option.onProgress && xhr.upload) xhr.upload.onprogress = function progress(e) {
|
|
25
|
-
if (e.total > 0) e.percent = e.loaded / e.total * 100;
|
|
26
|
-
option.onProgress?.(e);
|
|
27
|
-
};
|
|
28
|
-
const formData = new FormData();
|
|
29
|
-
if (option.data) Object.keys(option.data).forEach((key) => {
|
|
30
|
-
const value = option.data[key];
|
|
31
|
-
if (Array.isArray(value)) {
|
|
32
|
-
value.forEach((item) => {
|
|
33
|
-
formData.append(`${key}[]`, item);
|
|
34
|
-
});
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
formData.append(key, value);
|
|
38
|
-
});
|
|
39
|
-
if (option.file instanceof Blob) formData.append(option.filename, option.file, option.file.name);
|
|
40
|
-
else formData.append(option.filename, option.file);
|
|
41
|
-
xhr.onerror = function error(e) {
|
|
42
|
-
option.onError?.(e);
|
|
43
|
-
};
|
|
44
|
-
xhr.onload = function onload() {
|
|
45
|
-
if (xhr.status < 200 || xhr.status >= 300) return option.onError?.(getError(option, xhr), getBody(xhr));
|
|
46
|
-
return option.onSuccess?.(getBody(xhr), xhr);
|
|
47
|
-
};
|
|
48
|
-
xhr.open(option.method, option.action, true);
|
|
49
|
-
if (option.withCredentials && "withCredentials" in xhr) xhr.withCredentials = true;
|
|
50
|
-
const headers = option.headers || {};
|
|
51
|
-
if (headers["X-Requested-With"] !== null) xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
52
|
-
Object.keys(headers).forEach((h) => {
|
|
53
|
-
if (headers[h] !== null) xhr.setRequestHeader(h, headers[h]);
|
|
54
|
-
});
|
|
55
|
-
xhr.send(formData);
|
|
56
|
-
return { abort() {
|
|
57
|
-
xhr.abort();
|
|
58
|
-
} };
|
|
59
|
-
}
|
|
60
|
-
exports.default = upload;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
async function traverseFileTree(files, isAccepted) {
|
|
6
|
-
const flattenFileList = [];
|
|
7
|
-
const progressFileList = [];
|
|
8
|
-
files.forEach((file) => progressFileList.push(file.webkitGetAsEntry()));
|
|
9
|
-
async function readDirectory(directory) {
|
|
10
|
-
const dirReader = directory.createReader();
|
|
11
|
-
const entries = [];
|
|
12
|
-
while (true) {
|
|
13
|
-
const results = await new Promise((resolve) => {
|
|
14
|
-
dirReader.readEntries(resolve, () => resolve([]));
|
|
15
|
-
});
|
|
16
|
-
const n = results.length;
|
|
17
|
-
if (!n) break;
|
|
18
|
-
for (let i = 0; i < n; i++) entries.push(results[i]);
|
|
19
|
-
}
|
|
20
|
-
return entries;
|
|
21
|
-
}
|
|
22
|
-
async function readFile(item) {
|
|
23
|
-
return new Promise((resolve) => {
|
|
24
|
-
item.file((file) => {
|
|
25
|
-
if (isAccepted(file)) {
|
|
26
|
-
if (item.fullPath && !file.webkitRelativePath) {
|
|
27
|
-
Object.defineProperties(file, { webkitRelativePath: { writable: true } });
|
|
28
|
-
file.webkitRelativePath = item.fullPath.replace(/^\//, "");
|
|
29
|
-
Object.defineProperties(file, { webkitRelativePath: { writable: false } });
|
|
30
|
-
}
|
|
31
|
-
resolve(file);
|
|
32
|
-
} else resolve(null);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const _traverseFileTree = async (item, path) => {
|
|
37
|
-
if (!item) return;
|
|
38
|
-
item.path = path || "";
|
|
39
|
-
if (item.isFile) {
|
|
40
|
-
const file = await readFile(item);
|
|
41
|
-
if (file) flattenFileList.push(file);
|
|
42
|
-
} else if (item.isDirectory) {
|
|
43
|
-
const entries = await readDirectory(item);
|
|
44
|
-
progressFileList.push(...entries);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
let wipIndex = 0;
|
|
48
|
-
while (wipIndex < progressFileList.length) {
|
|
49
|
-
await _traverseFileTree(progressFileList[wipIndex]);
|
|
50
|
-
wipIndex++;
|
|
51
|
-
}
|
|
52
|
-
return flattenFileList;
|
|
53
|
-
}
|
|
54
|
-
var traverseFileTree_default = traverseFileTree;
|
|
55
|
-
exports.default = traverseFileTree_default;
|
package/dist/uid.cjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
Object.defineProperties(exports, {
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
5
|
-
var now = +/* @__PURE__ */ new Date();
|
|
6
|
-
var index = 0;
|
|
7
|
-
function uid() {
|
|
8
|
-
return `vc-upload-${now}-${++index}`;
|
|
9
|
-
}
|
|
10
|
-
exports.default = uid;
|