zcw-shared 1.32.3 → 1.32.6
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.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Document, HTMLElement } from '../../../references/dom.d';
|
|
2
|
+
import type { File } from '../../../references/browser.d';
|
|
3
|
+
import type { setTimeout } from '../../../references/timer.d';
|
|
4
|
+
export interface PickFileOptions {
|
|
5
|
+
accept?: string;
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface PickFileDeps {
|
|
9
|
+
createElement: Document['createElement'];
|
|
10
|
+
body: HTMLElement & {
|
|
11
|
+
removeChild: (child: HTMLElement) => HTMLElement;
|
|
12
|
+
};
|
|
13
|
+
setTimeout: typeof setTimeout;
|
|
14
|
+
}
|
|
15
|
+
export declare function pickFile(options: PickFileOptions | undefined, deps: PickFileDeps): Promise<File | File[] | null>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function pickFile(options = {}, deps) {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
let isResolved = false;
|
|
4
|
+
const input = deps.createElement('input');
|
|
5
|
+
input.type = 'file';
|
|
6
|
+
input.style.display = 'none';
|
|
7
|
+
if (options.accept) {
|
|
8
|
+
input.accept = options.accept;
|
|
9
|
+
}
|
|
10
|
+
if (options.multiple) {
|
|
11
|
+
input.setAttribute('multiple', '');
|
|
12
|
+
}
|
|
13
|
+
const handleChange = () => {
|
|
14
|
+
if (isResolved)
|
|
15
|
+
return;
|
|
16
|
+
isResolved = true;
|
|
17
|
+
const files = input.files;
|
|
18
|
+
if (input.parentNode) {
|
|
19
|
+
deps.body.removeChild(input);
|
|
20
|
+
}
|
|
21
|
+
input.removeEventListener('change', handleChange);
|
|
22
|
+
if (!files || files.length === 0) {
|
|
23
|
+
resolve(null);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (options.multiple) {
|
|
27
|
+
resolve(Array.from(files));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve(files[0]);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
input.addEventListener('change', handleChange);
|
|
34
|
+
deps.body.appendChild(input);
|
|
35
|
+
input.click();
|
|
36
|
+
deps.setTimeout(() => {
|
|
37
|
+
if (isResolved)
|
|
38
|
+
return;
|
|
39
|
+
isResolved = true;
|
|
40
|
+
if (input.parentNode) {
|
|
41
|
+
input.removeEventListener('change', handleChange);
|
|
42
|
+
deps.body.removeChild(input);
|
|
43
|
+
}
|
|
44
|
+
resolve(null);
|
|
45
|
+
}, 60000);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=pickFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pickFile.js","sourceRoot":"","sources":["../../../src/functions/dom/pickFile.ts"],"names":[],"mappings":"AA8EA,MAAM,UAAU,QAAQ,CACtB,UAA2B,EAAE,EAC7B,IAAkB;IAElB,OAAO,IAAI,OAAO,CAAuB,CAAC,OAAO,EAAE,EAAE;QACnD,IAAI,UAAU,GAAG,KAAK,CAAA;QAGtB,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAqB,CAAA;QAC7D,KAAK,CAAC,IAAI,GAAG,MAAM,CAAA;QACnB,KAAK,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAA;QAG5B,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;QAC/B,CAAC;QAGD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,KAAK,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;QACpC,CAAC;QAGD,MAAM,YAAY,GAAG,GAAG,EAAE;YACxB,IAAI,UAAU;gBAAE,OAAM;YACtB,UAAU,GAAG,IAAI,CAAA;YAEjB,MAAM,KAAK,GAAG,K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"1.32.6",
|
|
4
4
|
"files": [
|
|
5
5
|
"references",
|
|
6
6
|
"dist",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"vitepress": "^1.6.4",
|
|
21
21
|
"vue": "^3.5.22",
|
|
22
22
|
"zcw-shared": "^1.28.0",
|
|
23
|
-
"zcw-vue-ui": "1.
|
|
23
|
+
"zcw-vue-ui": "1.23.0"
|
|
24
24
|
},
|
|
25
25
|
"exports": {
|
|
26
26
|
"./constants/colorPatterns": "./dist/constants/colorPatterns.js",
|
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
"./functions/dom/getRelativePosition": "./dist/functions/dom/getRelativePosition.js",
|
|
119
119
|
"./functions/dom/getViewportRect": "./dist/functions/dom/getViewportRect.js",
|
|
120
120
|
"./functions/dom/isValidPlacement": "./dist/functions/dom/isValidPlacement.js",
|
|
121
|
+
"./functions/dom/pickFile": "./dist/functions/dom/pickFile.js",
|
|
121
122
|
"./functions/file/formatFileSize": "./dist/functions/file/formatFileSize.js",
|
|
122
123
|
"./functions/file/getFileExtension": "./dist/functions/file/getFileExtension.js",
|
|
123
124
|
"./functions/functional/compose": "./dist/functions/functional/compose.js",
|
package/references/dom.d.ts
CHANGED
|
@@ -82,6 +82,23 @@ export interface HTMLIFrameElement extends HTMLElement {
|
|
|
82
82
|
onerror: (() => void) | null
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
export interface HTMLInputElement extends HTMLElement {
|
|
86
|
+
type: string
|
|
87
|
+
accept: string
|
|
88
|
+
files: FileList | null
|
|
89
|
+
click(): void
|
|
90
|
+
value: string
|
|
91
|
+
style: CSSStyleDeclaration
|
|
92
|
+
setAttribute(name: string, value: string): void
|
|
93
|
+
hasAttribute(name: string): boolean
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface FileList {
|
|
97
|
+
readonly length: number
|
|
98
|
+
item(index: number): File | null
|
|
99
|
+
[index: number]: File
|
|
100
|
+
}
|
|
101
|
+
|
|
85
102
|
export interface CanvasRenderingContext2D {
|
|
86
103
|
drawImage(image: HTMLImageElement, dx: number, dy: number, dWidth: number, dHeight: number): void
|
|
87
104
|
}
|
|
@@ -99,6 +116,7 @@ export interface Document extends Node {
|
|
|
99
116
|
createElement(tagName: 'link'): HTMLLinkElement
|
|
100
117
|
createElement(tagName: 'img'): HTMLImageElement
|
|
101
118
|
createElement(tagName: 'iframe'): HTMLIFrameElement
|
|
119
|
+
createElement(tagName: 'input'): HTMLInputElement
|
|
102
120
|
createElement(tagName: string): HTMLElement
|
|
103
121
|
documentElement: {
|
|
104
122
|
clientWidth: number
|