@tstdl/base 0.90.69 → 0.90.70
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/dom/files-select.d.ts +7 -0
- package/dom/files-select.js +19 -0
- package/dom/index.d.ts +1 -0
- package/dom/index.js +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { OneOrMany } from '../types.js';
|
|
2
|
+
export type FileSelectDialogOptions = {
|
|
3
|
+
accept?: OneOrMany<string>;
|
|
4
|
+
multiple?: boolean;
|
|
5
|
+
capture?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function openFileSelectDialog({ accept, multiple, capture }?: FileSelectDialogOptions): Promise<File[] | null>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isDefined, isString } from '../utils/type-guards.js';
|
|
2
|
+
export async function openFileSelectDialog({ accept, multiple, capture } = {}) {
|
|
3
|
+
const fileInput = document.createElement('input');
|
|
4
|
+
fileInput.type = 'file';
|
|
5
|
+
if (isDefined(accept)) {
|
|
6
|
+
fileInput.accept = isString(accept) ? accept : accept.join(',');
|
|
7
|
+
}
|
|
8
|
+
if (isDefined(multiple)) {
|
|
9
|
+
fileInput.multiple = multiple;
|
|
10
|
+
}
|
|
11
|
+
if (isDefined(capture)) {
|
|
12
|
+
fileInput.capture = capture;
|
|
13
|
+
}
|
|
14
|
+
fileInput.click();
|
|
15
|
+
return new Promise((resolve) => {
|
|
16
|
+
fileInput.addEventListener('change', () => resolve(Array.from(fileInput.files ?? [])));
|
|
17
|
+
fileInput.addEventListener('cancel', () => resolve(null));
|
|
18
|
+
});
|
|
19
|
+
}
|
package/dom/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './files-select.js';
|
package/dom/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './files-select.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.90.
|
|
3
|
+
"version": "0.90.70",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"./decorators": "./decorators/index.js",
|
|
42
42
|
"./disposable": "./disposable/index.js",
|
|
43
43
|
"./distributed-loop": "./distributed-loop/index.js",
|
|
44
|
+
"./dom": "./dom/index.js",
|
|
44
45
|
"./enumerable": "./enumerable/index.js",
|
|
45
46
|
"./errors": "./errors/index.js",
|
|
46
47
|
"./file": "./file/index.js",
|