zcw-shared 1.32.3 → 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,EAC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AAQ,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",
3
+ "version": "1.32.4",
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.11.4"
23
+ "zcw-vue-ui": "1.14.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",
@@ -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