cursedbelt 5.16.1 → 5.17.0
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/dist/react/components/FileDropZone.d.ts +19 -0
- package/dist/react/components/FileDropZone.d.ts.map +1 -1
- package/dist/react/components/FileDropZone.js +96 -5
- package/dist/react/components/FileDropZone.js.map +1 -1
- package/package.json +1 -1
- package/src/react/components/FileDropZone.spec.tsx +79 -0
- package/src/react/components/FileDropZone.tsx +107 -5
|
@@ -102,6 +102,25 @@ export interface FileDropZoneProps {
|
|
|
102
102
|
* The notice is inline and dismissible, never a modal or a toast: it belongs
|
|
103
103
|
* beside the zone the files were aimed at, and it must not auto-dismiss, because
|
|
104
104
|
* a message the user did not get to read is the same as no message.
|
|
105
|
+
*
|
|
106
|
+
* ── 🔴 A DROPPED FOLDER IS ITS FILES (2026-09-28) ─────────────────────────────
|
|
107
|
+
* `dataTransfer.files` lists a dropped folder as ONE `File` — the folder's own
|
|
108
|
+
* name, no extension, no bytes — so it failed every `accept` and reached the app
|
|
109
|
+
* as a single refusal. Found in roms: the owner double-clicked a `.7z` in Finder
|
|
110
|
+
* and dropped the folder it unpacked to (a PlayStation disc's `.cue` and thirty
|
|
111
|
+
* `.bin`s, one level down) and got "not a file this accepts" for the lot, when
|
|
112
|
+
* what he dropped was exactly the files the zone takes. Finder's "unpack, then
|
|
113
|
+
* drag the result" is the ordinary way a person hands over a set of files.
|
|
114
|
+
*
|
|
115
|
+
* So a folder is walked (`webkitGetAsEntry`, the only door every browser ships)
|
|
116
|
+
* and its files are judged one by one, as if they had been dropped loose. Two
|
|
117
|
+
* rules keep that honest rather than noisy:
|
|
118
|
+
*
|
|
119
|
+
* · inside a folder, a file `accept` turns away is SKIPPED, as an archive's
|
|
120
|
+
* readme is — the person dropped the folder, not its `.txt` — and hidden files
|
|
121
|
+
* (`.DS_Store`, AppleDouble `._x`) are never files anyone meant;
|
|
122
|
+
* · but a folder that yields NOTHING acceptable is itself reported as rejected,
|
|
123
|
+
* under its own name — the 2026-08-14 rule, one level up: a drop never vanishes.
|
|
105
124
|
*/
|
|
106
125
|
export declare function FileDropZone({ onFiles, onRejected, onDrop: onDropResult, accept, multiple, disabled, children, hint, className, }: FileDropZoneProps): import("react").JSX.Element;
|
|
107
126
|
//# sourceMappingURL=FileDropZone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDropZone.d.ts","sourceRoot":"","sources":["../../../src/react/components/FileDropZone.tsx"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAC;AAKhF,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACjC;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACrC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;
|
|
1
|
+
{"version":3,"file":"FileDropZone.d.ts","sourceRoot":"","sources":["../../../src/react/components/FileDropZone.tsx"],"names":[],"mappings":"AACA,OAAO,EAAkB,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAC;AAKhF,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACjC;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACrC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAAC,QAAQ,EAAE,IAAI,EAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AA0FD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AACH,wBAAgB,YAAY,CAAC,EAC3B,OAAO,EACP,UAAU,EACV,MAAM,EAAE,YAAY,EACpB,MAAM,EACN,QAAe,EACf,QAAgB,EAChB,QAAQ,EACR,IAAI,EACJ,SAAS,GACV,EAAE,iBAAiB,+BAkInB"}
|
|
@@ -4,6 +4,72 @@ import { useId, useRef, useState } from 'react';
|
|
|
4
4
|
import { cn } from '../lib/cn.js';
|
|
5
5
|
import { Button } from './Button.js';
|
|
6
6
|
import { Input } from './Input.js';
|
|
7
|
+
/** What a folder can hold before walking it stops — a drop, not a disk scan. */
|
|
8
|
+
const MAX_FOLDER_FILES = 5000;
|
|
9
|
+
const isHidden = (name) => name.startsWith('.');
|
|
10
|
+
/** Every file under `entry`, depth-first. A directory's reader answers in batches until empty. */
|
|
11
|
+
async function filesUnder(entry, out) {
|
|
12
|
+
if (out.length >= MAX_FOLDER_FILES || isHidden(entry.name))
|
|
13
|
+
return;
|
|
14
|
+
if (entry.isFile && entry.file) {
|
|
15
|
+
const read = entry.file.bind(entry);
|
|
16
|
+
out.push(await new Promise((ok, fail) => read(ok, fail)));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (!entry.isDirectory || !entry.createReader)
|
|
20
|
+
return;
|
|
21
|
+
const reader = entry.createReader();
|
|
22
|
+
while (out.length < MAX_FOLDER_FILES) {
|
|
23
|
+
const batch = await new Promise((ok, fail) => reader.readEntries(ok, fail));
|
|
24
|
+
if (batch.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
for (const child of batch)
|
|
27
|
+
await filesUnder(child, out);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A drop's files, with every dropped FOLDER replaced by the accepted files inside it — see the
|
|
32
|
+
* FOLDER section above. `null` when nothing in the drop is a folder, so the ordinary path stays
|
|
33
|
+
* exactly `dataTransfer.files`.
|
|
34
|
+
*
|
|
35
|
+
* 🔴 The entries are taken SYNCHRONOUSLY, before the first `await`: a browser empties the
|
|
36
|
+
* `DataTransfer` once the drop event returns.
|
|
37
|
+
*/
|
|
38
|
+
function folderAwareDrop(transfer, accept) {
|
|
39
|
+
const items = transfer.items ? [...transfer.items] : [];
|
|
40
|
+
const entries = items.map((item) => item.kind === 'file' && typeof item.webkitGetAsEntry === 'function'
|
|
41
|
+
? item.webkitGetAsEntry()
|
|
42
|
+
: null);
|
|
43
|
+
if (!entries.some((entry) => entry?.isDirectory))
|
|
44
|
+
return null;
|
|
45
|
+
const looseFiles = [...transfer.files];
|
|
46
|
+
return (async () => {
|
|
47
|
+
const loose = [];
|
|
48
|
+
const fromFolders = [];
|
|
49
|
+
const emptyFolders = [];
|
|
50
|
+
for (const [i, entry] of entries.entries()) {
|
|
51
|
+
if (!entry?.isDirectory) {
|
|
52
|
+
const file = looseFiles[i] ?? (entry ? await new Promise((ok) => entry.file?.(ok, () => ok(null))) : null);
|
|
53
|
+
if (file)
|
|
54
|
+
loose.push(file);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const inside = [];
|
|
58
|
+
try {
|
|
59
|
+
await filesUnder(entry, inside);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// An unreadable folder yields what was read before the error — and, if that is nothing, a refusal below.
|
|
63
|
+
}
|
|
64
|
+
const kept = inside.filter((f) => matchesAccept(f, accept));
|
|
65
|
+
if (kept.length > 0)
|
|
66
|
+
fromFolders.push(...kept);
|
|
67
|
+
else
|
|
68
|
+
emptyFolders.push(new File([], entry.name));
|
|
69
|
+
}
|
|
70
|
+
return { loose, fromFolders, emptyFolders };
|
|
71
|
+
})();
|
|
72
|
+
}
|
|
7
73
|
const matchesAccept = (file, accept) => {
|
|
8
74
|
if (!accept)
|
|
9
75
|
return true;
|
|
@@ -81,21 +147,40 @@ const matchesAccept = (file, accept) => {
|
|
|
81
147
|
* The notice is inline and dismissible, never a modal or a toast: it belongs
|
|
82
148
|
* beside the zone the files were aimed at, and it must not auto-dismiss, because
|
|
83
149
|
* a message the user did not get to read is the same as no message.
|
|
150
|
+
*
|
|
151
|
+
* ── 🔴 A DROPPED FOLDER IS ITS FILES (2026-09-28) ─────────────────────────────
|
|
152
|
+
* `dataTransfer.files` lists a dropped folder as ONE `File` — the folder's own
|
|
153
|
+
* name, no extension, no bytes — so it failed every `accept` and reached the app
|
|
154
|
+
* as a single refusal. Found in roms: the owner double-clicked a `.7z` in Finder
|
|
155
|
+
* and dropped the folder it unpacked to (a PlayStation disc's `.cue` and thirty
|
|
156
|
+
* `.bin`s, one level down) and got "not a file this accepts" for the lot, when
|
|
157
|
+
* what he dropped was exactly the files the zone takes. Finder's "unpack, then
|
|
158
|
+
* drag the result" is the ordinary way a person hands over a set of files.
|
|
159
|
+
*
|
|
160
|
+
* So a folder is walked (`webkitGetAsEntry`, the only door every browser ships)
|
|
161
|
+
* and its files are judged one by one, as if they had been dropped loose. Two
|
|
162
|
+
* rules keep that honest rather than noisy:
|
|
163
|
+
*
|
|
164
|
+
* · inside a folder, a file `accept` turns away is SKIPPED, as an archive's
|
|
165
|
+
* readme is — the person dropped the folder, not its `.txt` — and hidden files
|
|
166
|
+
* (`.DS_Store`, AppleDouble `._x`) are never files anyone meant;
|
|
167
|
+
* · but a folder that yields NOTHING acceptable is itself reported as rejected,
|
|
168
|
+
* under its own name — the 2026-08-14 rule, one level up: a drop never vanishes.
|
|
84
169
|
*/
|
|
85
170
|
export function FileDropZone({ onFiles, onRejected, onDrop: onDropResult, accept, multiple = true, disabled = false, children, hint, className, }) {
|
|
86
171
|
const inputRef = useRef(null);
|
|
87
172
|
const inputId = useId();
|
|
88
173
|
const [dragOver, setDragOver] = useState(false);
|
|
89
174
|
const [rejected, setRejected] = useState([]);
|
|
90
|
-
const emit = (list) => {
|
|
175
|
+
const emit = (list, fromFolders = [], emptyFolders = []) => {
|
|
91
176
|
if (!list)
|
|
92
177
|
return;
|
|
93
178
|
const all = [...list];
|
|
94
|
-
if (all.length === 0)
|
|
179
|
+
if (all.length === 0 && fromFolders.length === 0 && emptyFolders.length === 0)
|
|
95
180
|
return;
|
|
96
|
-
const matched = all.filter((f) => matchesAccept(f, accept));
|
|
181
|
+
const matched = [...all.filter((f) => matchesAccept(f, accept)), ...fromFolders];
|
|
97
182
|
const accepted = multiple ? matched : matched.slice(0, 1);
|
|
98
|
-
const turnedAway = all.filter((f) => !matchesAccept(f, accept));
|
|
183
|
+
const turnedAway = [...all.filter((f) => !matchesAccept(f, accept)), ...emptyFolders];
|
|
99
184
|
// One gesture, one call — the whole reason this overload exists.
|
|
100
185
|
if (onDropResult) {
|
|
101
186
|
setRejected([]);
|
|
@@ -117,8 +202,14 @@ export function FileDropZone({ onFiles, onRejected, onDrop: onDropResult, accept
|
|
|
117
202
|
const onDrop = (e) => {
|
|
118
203
|
e.preventDefault();
|
|
119
204
|
setDragOver(false);
|
|
120
|
-
if (
|
|
205
|
+
if (disabled)
|
|
206
|
+
return;
|
|
207
|
+
const walking = folderAwareDrop(e.dataTransfer, accept);
|
|
208
|
+
if (!walking) {
|
|
121
209
|
emit(e.dataTransfer.files);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
void walking.then(({ loose, fromFolders, emptyFolders }) => emit(loose, fromFolders, emptyFolders));
|
|
122
213
|
};
|
|
123
214
|
return (_jsxs("div", { onDragOver: (e) => {
|
|
124
215
|
e.preventDefault(); // required by the spec for `drop` to fire
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDropZone.js","sourceRoot":"","sources":["../../../src/react/components/FileDropZone.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAkC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"FileDropZone.js","sourceRoot":"","sources":["../../../src/react/components/FileDropZone.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAkC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAmDnC,gFAAgF;AAChF,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAE9B,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAExD,kGAAkG;AAClG,KAAK,U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CAAsC,EAC3D,MAAM,CAAC,CAAC,CAAC,gBAAM,SAAS,EAAC,YAAY,kCAAc,MAAM,IAAQ,CAAC,CAAC,CAAC,IAAI,EACxE,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CACtB,eAAM,SAAS,EAAC,qCAAqC,YAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAQ,CACnF,IACI,EAKP,KAAC,MAAM,IACL,OAAO,EAAC,OAAO,EACf,IAAI,EAAC,SAAS,EACd,SAAS,EAAC,kBAAkB,EAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,gBACnB,SAAS,EACpB,OAAO,EAAC,SAAS,EACjB,aAAa,EAAC,KAAK,YAEnB,KAAC,CAAC,yBAAa,SAAS,EAAC,QAAQ,GAAG,GAC7B,IACL,CACP,IACG,CACP,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cursedbelt",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The React design system of the cursedbelt split — components, styles, theme. cursedbelt-core below it; server tier in cursedbelt-server.",
|
|
@@ -162,6 +162,85 @@ describe('FileDropZone', () => {
|
|
|
162
162
|
expect(input.className).toContain('peer');
|
|
163
163
|
});
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* 🔴 The 2026-09-28 roms report: the owner unpacked a `.7z` in Finder and dropped
|
|
167
|
+
* the FOLDER — `Loaded (USA) (En,Fr)/` holding a readme and, one level down, a
|
|
168
|
+
* `.cue` and thirty `.bin`s. `dataTransfer.files` lists a folder as one nameless
|
|
169
|
+
* File, so every one of those files was refused as "not a file this accepts".
|
|
170
|
+
*/
|
|
171
|
+
describe('a dropped folder', () => {
|
|
172
|
+
type Entry = {
|
|
173
|
+
isFile: boolean;
|
|
174
|
+
isDirectory: boolean;
|
|
175
|
+
name: string;
|
|
176
|
+
file?: (ok: (f: File) => void) => void;
|
|
177
|
+
createReader?: () => { readEntries: (ok: (e: Entry[]) => void) => void };
|
|
178
|
+
};
|
|
179
|
+
const fileEntry = (f: File): Entry => ({ isFile: true, isDirectory: false, name: f.name, file: (ok) => ok(f) });
|
|
180
|
+
/** A directory whose reader answers in batches of two, then empty — as browsers batch. */
|
|
181
|
+
const dirEntry = (name: string, children: Entry[]): Entry => ({
|
|
182
|
+
isFile: false,
|
|
183
|
+
isDirectory: true,
|
|
184
|
+
name,
|
|
185
|
+
createReader: () => {
|
|
186
|
+
let at = 0;
|
|
187
|
+
return {
|
|
188
|
+
readEntries: (ok) => {
|
|
189
|
+
const batch = children.slice(at, at + 2);
|
|
190
|
+
at += 2;
|
|
191
|
+
ok(batch);
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
const dropEntries = (zone: HTMLElement, entries: Entry[], files: File[]) =>
|
|
197
|
+
fireEvent.drop(zone, {
|
|
198
|
+
dataTransfer: {
|
|
199
|
+
files,
|
|
200
|
+
items: entries.map((entry) => ({ kind: 'file', webkitGetAsEntry: () => entry })),
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
204
|
+
|
|
205
|
+
test("is its files — nested ones included, the ones `accept` turns away and hidden ones skipped", async () => {
|
|
206
|
+
let result: { accepted: File[]; rejected: File[] } | null = null;
|
|
207
|
+
const { container } = render(
|
|
208
|
+
<FileDropZone accept='.cue,.bin' onFiles={() => {}} onDrop={(r) => (result = r)} />,
|
|
209
|
+
);
|
|
210
|
+
const folder = dirEntry('Loaded (USA) (En,Fr)', [
|
|
211
|
+
fileEntry(file("Vimm's Lair.txt", 'text/plain')),
|
|
212
|
+
fileEntry(file('.DS_Store', '')),
|
|
213
|
+
dirEntry('Loaded (USA) (En,Fr)', [
|
|
214
|
+
fileEntry(file('Loaded.cue', '')),
|
|
215
|
+
fileEntry(file('Loaded (Track 01).bin', '')),
|
|
216
|
+
fileEntry(file('Loaded (Track 02).bin', '')),
|
|
217
|
+
]),
|
|
218
|
+
]);
|
|
219
|
+
dropEntries(container.firstElementChild as HTMLElement, [folder], [file('Loaded (USA) (En,Fr)', '')]);
|
|
220
|
+
for (let i = 0; i < 10 && !result; i++) await settle();
|
|
221
|
+
const got = result as { accepted: File[]; rejected: File[] } | null;
|
|
222
|
+
expect(got?.accepted.map((f) => f.name)).toEqual(['Loaded.cue', 'Loaded (Track 01).bin', 'Loaded (Track 02).bin']);
|
|
223
|
+
expect(got?.rejected).toEqual([]);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('a folder with nothing acceptable in it is still a refusal, under its own name — never silence', async () => {
|
|
227
|
+
let result: { accepted: File[]; rejected: File[] } | null = null;
|
|
228
|
+
const { container } = render(
|
|
229
|
+
<FileDropZone accept='.zip' onFiles={() => {}} onDrop={(r) => (result = r)} />,
|
|
230
|
+
);
|
|
231
|
+
const loose = file('game.zip', 'application/zip');
|
|
232
|
+
dropEntries(
|
|
233
|
+
container.firstElementChild as HTMLElement,
|
|
234
|
+
[fileEntry(loose), dirEntry('Screenshots', [fileEntry(file('a.png', 'image/png'))])],
|
|
235
|
+
[loose, file('Screenshots', '')],
|
|
236
|
+
);
|
|
237
|
+
for (let i = 0; i < 10 && !result; i++) await settle();
|
|
238
|
+
const got = result as { accepted: File[]; rejected: File[] } | null;
|
|
239
|
+
expect(got?.accepted.map((f) => f.name)).toEqual(['game.zip']);
|
|
240
|
+
expect(got?.rejected.map((f) => f.name)).toEqual(['Screenshots']);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
165
244
|
test('renders custom children and the default hint otherwise', () => {
|
|
166
245
|
const { getByText, rerender } = render(
|
|
167
246
|
<FileDropZone onFiles={() => {}}>
|
|
@@ -42,6 +42,83 @@ export interface FileDropZoneProps {
|
|
|
42
42
|
className?: string;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/** The slice of the File and Directory Entries API a drop needs — every browser ships it. */
|
|
46
|
+
interface DropEntry {
|
|
47
|
+
isFile: boolean;
|
|
48
|
+
isDirectory: boolean;
|
|
49
|
+
name: string;
|
|
50
|
+
file?: (ok: (file: File) => void, fail: (error: unknown) => void) => void;
|
|
51
|
+
createReader?: () => {
|
|
52
|
+
readEntries: (ok: (entries: DropEntry[]) => void, fail: (error: unknown) => void) => void;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What a folder can hold before walking it stops — a drop, not a disk scan. */
|
|
57
|
+
const MAX_FOLDER_FILES = 5000;
|
|
58
|
+
|
|
59
|
+
const isHidden = (name: string) => name.startsWith('.');
|
|
60
|
+
|
|
61
|
+
/** Every file under `entry`, depth-first. A directory's reader answers in batches until empty. */
|
|
62
|
+
async function filesUnder(entry: DropEntry, out: File[]): Promise<void> {
|
|
63
|
+
if (out.length >= MAX_FOLDER_FILES || isHidden(entry.name)) return;
|
|
64
|
+
if (entry.isFile && entry.file) {
|
|
65
|
+
const read = entry.file.bind(entry);
|
|
66
|
+
out.push(await new Promise<File>((ok, fail) => read(ok, fail)));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!entry.isDirectory || !entry.createReader) return;
|
|
70
|
+
const reader = entry.createReader();
|
|
71
|
+
while (out.length < MAX_FOLDER_FILES) {
|
|
72
|
+
const batch = await new Promise<DropEntry[]>((ok, fail) => reader.readEntries(ok, fail));
|
|
73
|
+
if (batch.length === 0) return;
|
|
74
|
+
for (const child of batch) await filesUnder(child, out);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* A drop's files, with every dropped FOLDER replaced by the accepted files inside it — see the
|
|
80
|
+
* FOLDER section above. `null` when nothing in the drop is a folder, so the ordinary path stays
|
|
81
|
+
* exactly `dataTransfer.files`.
|
|
82
|
+
*
|
|
83
|
+
* 🔴 The entries are taken SYNCHRONOUSLY, before the first `await`: a browser empties the
|
|
84
|
+
* `DataTransfer` once the drop event returns.
|
|
85
|
+
*/
|
|
86
|
+
function folderAwareDrop(
|
|
87
|
+
transfer: DataTransfer,
|
|
88
|
+
accept: string | undefined,
|
|
89
|
+
): Promise<{ loose: File[]; fromFolders: File[]; emptyFolders: File[] }> | null {
|
|
90
|
+
const items = transfer.items ? [...transfer.items] : [];
|
|
91
|
+
const entries = items.map((item) =>
|
|
92
|
+
item.kind === 'file' && typeof item.webkitGetAsEntry === 'function'
|
|
93
|
+
? (item.webkitGetAsEntry() as DropEntry | null)
|
|
94
|
+
: null,
|
|
95
|
+
);
|
|
96
|
+
if (!entries.some((entry) => entry?.isDirectory)) return null;
|
|
97
|
+
const looseFiles = [...transfer.files];
|
|
98
|
+
return (async () => {
|
|
99
|
+
const loose: File[] = [];
|
|
100
|
+
const fromFolders: File[] = [];
|
|
101
|
+
const emptyFolders: File[] = [];
|
|
102
|
+
for (const [i, entry] of entries.entries()) {
|
|
103
|
+
if (!entry?.isDirectory) {
|
|
104
|
+
const file = looseFiles[i] ?? (entry ? await new Promise<File | null>((ok) => entry.file?.(ok, () => ok(null))) : null);
|
|
105
|
+
if (file) loose.push(file);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const inside: File[] = [];
|
|
109
|
+
try {
|
|
110
|
+
await filesUnder(entry, inside);
|
|
111
|
+
} catch {
|
|
112
|
+
// An unreadable folder yields what was read before the error — and, if that is nothing, a refusal below.
|
|
113
|
+
}
|
|
114
|
+
const kept = inside.filter((f) => matchesAccept(f, accept));
|
|
115
|
+
if (kept.length > 0) fromFolders.push(...kept);
|
|
116
|
+
else emptyFolders.push(new File([], entry.name));
|
|
117
|
+
}
|
|
118
|
+
return { loose, fromFolders, emptyFolders };
|
|
119
|
+
})();
|
|
120
|
+
}
|
|
121
|
+
|
|
45
122
|
const matchesAccept = (file: File, accept?: string): boolean => {
|
|
46
123
|
if (!accept) return true;
|
|
47
124
|
return accept.split(',').some((raw) => {
|
|
@@ -116,6 +193,25 @@ const matchesAccept = (file: File, accept?: string): boolean => {
|
|
|
116
193
|
* The notice is inline and dismissible, never a modal or a toast: it belongs
|
|
117
194
|
* beside the zone the files were aimed at, and it must not auto-dismiss, because
|
|
118
195
|
* a message the user did not get to read is the same as no message.
|
|
196
|
+
*
|
|
197
|
+
* ── 🔴 A DROPPED FOLDER IS ITS FILES (2026-09-28) ─────────────────────────────
|
|
198
|
+
* `dataTransfer.files` lists a dropped folder as ONE `File` — the folder's own
|
|
199
|
+
* name, no extension, no bytes — so it failed every `accept` and reached the app
|
|
200
|
+
* as a single refusal. Found in roms: the owner double-clicked a `.7z` in Finder
|
|
201
|
+
* and dropped the folder it unpacked to (a PlayStation disc's `.cue` and thirty
|
|
202
|
+
* `.bin`s, one level down) and got "not a file this accepts" for the lot, when
|
|
203
|
+
* what he dropped was exactly the files the zone takes. Finder's "unpack, then
|
|
204
|
+
* drag the result" is the ordinary way a person hands over a set of files.
|
|
205
|
+
*
|
|
206
|
+
* So a folder is walked (`webkitGetAsEntry`, the only door every browser ships)
|
|
207
|
+
* and its files are judged one by one, as if they had been dropped loose. Two
|
|
208
|
+
* rules keep that honest rather than noisy:
|
|
209
|
+
*
|
|
210
|
+
* · inside a folder, a file `accept` turns away is SKIPPED, as an archive's
|
|
211
|
+
* readme is — the person dropped the folder, not its `.txt` — and hidden files
|
|
212
|
+
* (`.DS_Store`, AppleDouble `._x`) are never files anyone meant;
|
|
213
|
+
* · but a folder that yields NOTHING acceptable is itself reported as rejected,
|
|
214
|
+
* under its own name — the 2026-08-14 rule, one level up: a drop never vanishes.
|
|
119
215
|
*/
|
|
120
216
|
export function FileDropZone({
|
|
121
217
|
onFiles,
|
|
@@ -133,13 +229,13 @@ export function FileDropZone({
|
|
|
133
229
|
const [dragOver, setDragOver] = useState(false);
|
|
134
230
|
const [rejected, setRejected] = useState<string[]>([]);
|
|
135
231
|
|
|
136
|
-
const emit = (list: FileList | File[] | null) => {
|
|
232
|
+
const emit = (list: FileList | File[] | null, fromFolders: File[] = [], emptyFolders: File[] = []) => {
|
|
137
233
|
if (!list) return;
|
|
138
234
|
const all = [...list];
|
|
139
|
-
if (all.length === 0) return;
|
|
140
|
-
const matched = all.filter((f) => matchesAccept(f, accept));
|
|
235
|
+
if (all.length === 0 && fromFolders.length === 0 && emptyFolders.length === 0) return;
|
|
236
|
+
const matched = [...all.filter((f) => matchesAccept(f, accept)), ...fromFolders];
|
|
141
237
|
const accepted = multiple ? matched : matched.slice(0, 1);
|
|
142
|
-
const turnedAway = all.filter((f) => !matchesAccept(f, accept));
|
|
238
|
+
const turnedAway = [...all.filter((f) => !matchesAccept(f, accept)), ...emptyFolders];
|
|
143
239
|
|
|
144
240
|
// One gesture, one call — the whole reason this overload exists.
|
|
145
241
|
if (onDropResult) {
|
|
@@ -161,7 +257,13 @@ export function FileDropZone({
|
|
|
161
257
|
const onDrop = (e: DragEvent) => {
|
|
162
258
|
e.preventDefault();
|
|
163
259
|
setDragOver(false);
|
|
164
|
-
if (
|
|
260
|
+
if (disabled) return;
|
|
261
|
+
const walking = folderAwareDrop(e.dataTransfer, accept);
|
|
262
|
+
if (!walking) {
|
|
263
|
+
emit(e.dataTransfer.files);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
void walking.then(({ loose, fromFolders, emptyFolders }) => emit(loose, fromFolders, emptyFolders));
|
|
165
267
|
};
|
|
166
268
|
|
|
167
269
|
return (
|