Type directory picker without DOM FileSystemDirectoryHandle.entries.
This commit is contained in:
@@ -94,23 +94,20 @@ function mergeSelection(current: File[], incoming: File[], multiple: boolean, di
|
||||
return [...current, ...incoming];
|
||||
}
|
||||
|
||||
async function filesFromDirectoryHandle(
|
||||
handle: FileSystemDirectoryHandle,
|
||||
prefix = "",
|
||||
): Promise<File[]> {
|
||||
type DirHandle = {
|
||||
name: string;
|
||||
entries: () => AsyncIterable<[string, { kind: string; getFile?: () => Promise<File> } & DirHandle]>;
|
||||
};
|
||||
|
||||
async function filesFromDirectoryHandle(handle: DirHandle, prefix = ""): Promise<File[]> {
|
||||
const out: File[] = [];
|
||||
for await (const [name, child] of handle.entries()) {
|
||||
if (SKIP_DIR.test(name)) continue;
|
||||
if (child.kind === "file") {
|
||||
if (child.kind === "file" && child.getFile) {
|
||||
const file = await child.getFile();
|
||||
out.push(stampRelativePath(file, prefix + name));
|
||||
} else if (child.kind === "directory") {
|
||||
out.push(
|
||||
...(await filesFromDirectoryHandle(
|
||||
child as FileSystemDirectoryHandle,
|
||||
prefix + name + "/",
|
||||
)),
|
||||
);
|
||||
out.push(...(await filesFromDirectoryHandle(child, prefix + name + "/")));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
@@ -137,9 +134,7 @@ function pickFolderViaHiddenInput(): Promise<File[]> {
|
||||
|
||||
async function pickProjectFolder(): Promise<File[]> {
|
||||
const picker = (
|
||||
window as Window & {
|
||||
showDirectoryPicker?: () => Promise<FileSystemDirectoryHandle>;
|
||||
}
|
||||
window as Window & { showDirectoryPicker?: () => Promise<DirHandle> }
|
||||
).showDirectoryPicker;
|
||||
if (typeof picker === "function") {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user