zcw-shared 1.32.2 → 1.32.4
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,13 @@
|
|
|
1
|
+
import type { Document, HTMLElement, FileList } from '../../../references/dom.d';
|
|
2
|
+
import type { setTimeout } from '../../../references/timer.d';
|
|
3
|
+
export interface PickFileOptions {
|
|
4
|
+
accept?: string;
|
|
5
|
+
multiple?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PickFileDeps {
|
|
8
|
+
createElement: Document['createElement'];
|
|
9
|
+
removeChild: (parent: HTMLElement, child: HTMLElement) => void;
|
|
10
|
+
body: HTMLElement;
|
|
11
|
+
setTimeout: typeof setTimeout;
|
|
12
|
+
}
|
|
13
|
+
export declare function pickFile(options: PickFileOptions | undefined, deps: PickFileDeps): Promise<FileList | null>;
|
|
@@ -0,0 +1,39 @@
|
|
|
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.removeChild(deps.body, input);
|
|
20
|
+
}
|
|
21
|
+
input.removeEventListener('change', handleChange);
|
|
22
|
+
resolve(files);
|
|
23
|
+
};
|
|
24
|
+
input.addEventListener('change', handleChange);
|
|
25
|
+
deps.body.appendChild(input);
|
|
26
|
+
input.click();
|
|
27
|
+
deps.setTimeout(() => {
|
|
28
|
+
if (isResolved)
|
|
29
|
+
return;
|
|
30
|
+
isResolved = true;
|
|
31
|
+
if (input.parentNode) {
|
|
32
|
+
input.removeEventListener('change', handleChange);
|
|
33
|
+
deps.removeChild(deps.body, input);
|
|
34
|
+
}
|
|
35
|
+
resolve(null);
|
|
36
|
+
}, 60000);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=pickFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pickFile.js","sourceRoot":"","sources":["../../../src/functions/dom/pickFile.ts"],"names":[],"mappings":"AA2EA,MAAM,UAAU,QAAQ,CACtB,UAA2B,EAAE,EAC7B,IAAkB;IAElB,OAAO,IAAI,OAAO,CAAkB,CAAC,OAAO,EAAE,EAAE;QAC9C,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,KAAK,CAAC,KAAK,CAAA;YAEzB,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACpC,CAAC;YACD,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;YAEjD,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB,CAAC,CAAA;QAED,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;QAG9C,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;QAG5B,KAAK,CAAC,KAAK,EAAE,CAAA;QAIb,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;YACnB,IAAI,UAAU;gBAAE,OAAM;YACtB,UAAU,GAAG,IAAI,CAAA;YAGjB,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;gBACrB,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAA;gBACjD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACpC,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC,EAAE,KAAK,CAAC,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcw-shared",
|
|
3
|
-
"version": "1.32.
|
|
3
|
+
"version": "1.32.4",
|
|
4
4
|
"files": [
|
|
5
5
|
"references",
|
|
6
6
|
"dist",
|
|
@@ -12,18 +12,6 @@
|
|
|
12
12
|
"license": "ISC",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"description": "",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsc -p tsconfig.build.json && tsx scripts/generate-exports.ts",
|
|
17
|
-
"publish:patch": "npx tsx scripts/publish.ts patch",
|
|
18
|
-
"publish:minor": "npx tsx scripts/publish.ts minor",
|
|
19
|
-
"publish:major": "npx tsx scripts/publish.ts major",
|
|
20
|
-
"publish:prerelease": "npx tsx scripts/publish.ts prerelease",
|
|
21
|
-
"docs:dev": "vitepress dev docs",
|
|
22
|
-
"docs:build": "NODE_OPTIONS=--max-old-space-size=4096 vitepress build docs",
|
|
23
|
-
"docs:preview": "vitepress preview docs",
|
|
24
|
-
"deploy:tcb": "npx tsx scripts/deploy-tcb.ts",
|
|
25
|
-
"deploy:cos": "npx tsx scripts/deploy-cos.ts"
|
|
26
|
-
},
|
|
27
15
|
"devDependencies": {
|
|
28
16
|
"@cloudbase/manager-node": "^4.3.2",
|
|
29
17
|
"cos-nodejs-sdk-v5": "^2.14.4",
|
|
@@ -32,7 +20,7 @@
|
|
|
32
20
|
"vitepress": "^1.6.4",
|
|
33
21
|
"vue": "^3.5.22",
|
|
34
22
|
"zcw-shared": "^1.28.0",
|
|
35
|
-
"zcw-vue-ui": "
|
|
23
|
+
"zcw-vue-ui": "1.14.0"
|
|
36
24
|
},
|
|
37
25
|
"exports": {
|
|
38
26
|
"./constants/colorPatterns": "./dist/constants/colorPatterns.js",
|
|
@@ -130,6 +118,7 @@
|
|
|
130
118
|
"./functions/dom/getRelativePosition": "./dist/functions/dom/getRelativePosition.js",
|
|
131
119
|
"./functions/dom/getViewportRect": "./dist/functions/dom/getViewportRect.js",
|
|
132
120
|
"./functions/dom/isValidPlacement": "./dist/functions/dom/isValidPlacement.js",
|
|
121
|
+
"./functions/dom/pickFile": "./dist/functions/dom/pickFile.js",
|
|
133
122
|
"./functions/file/formatFileSize": "./dist/functions/file/formatFileSize.js",
|
|
134
123
|
"./functions/file/getFileExtension": "./dist/functions/file/getFileExtension.js",
|
|
135
124
|
"./functions/functional/compose": "./dist/functions/functional/compose.js",
|
|
@@ -311,5 +300,17 @@
|
|
|
311
300
|
"./types/uniapp-android-build": "./types/uniapp-android-build.d.ts",
|
|
312
301
|
"./types/vue": "./types/vue.d.ts",
|
|
313
302
|
"./types/worker": "./types/worker.d.ts"
|
|
303
|
+
},
|
|
304
|
+
"scripts": {
|
|
305
|
+
"build": "tsc -p tsconfig.build.json && tsx scripts/generate-exports.ts",
|
|
306
|
+
"publish:patch": "npx tsx scripts/publish.ts patch",
|
|
307
|
+
"publish:minor": "npx tsx scripts/publish.ts minor",
|
|
308
|
+
"publish:major": "npx tsx scripts/publish.ts major",
|
|
309
|
+
"publish:prerelease": "npx tsx scripts/publish.ts prerelease",
|
|
310
|
+
"docs:dev": "vitepress dev docs",
|
|
311
|
+
"docs:build": "NODE_OPTIONS=--max-old-space-size=4096 vitepress build docs",
|
|
312
|
+
"docs:preview": "vitepress preview docs",
|
|
313
|
+
"deploy:tcb": "npx tsx scripts/deploy-tcb.ts",
|
|
314
|
+
"deploy:cos": "npx tsx scripts/deploy-cos.ts"
|
|
314
315
|
}
|
|
315
316
|
}
|
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
|