@@ -11,9 +11,6 @@ const FILES_TO_IGNORE = [
11
11
* NOTE: If some of the items are folders,
12
12
* everything will be flattened and placed in the same list but the paths will be kept as a {path} property.
13
13
*
14
- * EXPERIMENTAL: A list of https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle objects can also be passed as an arg
15
- * and a list of File objects will be returned.
16
- *
17
14
* @param evt
18
15
*/
19
16
export async function fromEvent (
@@ -23,11 +20,6 @@ export async function fromEvent(
23
20
return getDataTransferFiles ( evt . dataTransfer , evt . type ) ;
24
21
} else if ( isChangeEvt ( evt ) ) {
25
22
return getInputFiles ( evt ) ;
26
- } else if (
27
- Array . isArray ( evt ) &&
28
- evt . every ( ( item ) => "getFile" in item && typeof item . getFile === "function" )
29
- ) {
30
- return getFsHandleFiles ( evt ) ;
31
23
}
32
24
return [ ] ;
33
25
}
@@ -52,10 +44,32 @@ function getInputFiles(event: Event): FileWithPath[] {
52
44
return Array . from ( event . target . files ) . map ( ( file ) => toFileWithPath ( file ) ) ;
53
45
}
54
46
55
- // Ee expect each handle to be https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle
56
- async function getFsHandleFiles ( handles : any [ ] ) {
57
- const files = await Promise . all ( handles . map ( ( h ) => h . getFile ( ) ) ) ;
58
- return files . map ( ( file ) => toFileWithPath ( file ) ) ;
47
+ /**
48
+ * Retrieves files from an array of `FileSystemHandle` objects from the File System API.
49
+ *
50
+ * @param handles The array of handles to convert.
51
+ * @returns A promise that resolves to an array of files retrieved from the handles.
52
+ *
53
+ * @example
54
+ * ```js
55
+ * const handles = await window.showOpenFilePicker({ multiple: true });
56
+ * const files = await fromFileHandles(handles);
57
+ * ```
58
+ *
59
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/File_System_API|MDN - File System API }
60
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle|MDN - `FileSystemHandle` }
61
+ */
62
+ export function fromFileHandles (
63
+ handles : FileSystemFileHandle [ ] ,
64
+ ) : Promise < FileWithPath [ ] > {
65
+ return Promise . all ( handles . map ( ( handle ) => fromFileHandle ( handle ) ) ) ;
66
+ }
67
+
68
+ async function fromFileHandle (
69
+ handle : FileSystemFileHandle ,
70
+ ) : Promise < FileWithPath > {
71
+ const file = await handle . getFile ( ) ;
72
+ return toFileWithPath ( file ) ;
59
73
}
60
74
61
75
async function getDataTransferFiles ( dataTransfer : DataTransfer , type : string ) {
0 commit comments