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