@shipstatic/drop 2.10.4-beta.7 → 2.10.4-beta.8

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/index.cjs CHANGED
@@ -1121,13 +1121,12 @@ function useDrop({ ship }) {
1121
1121
  [state.files]
1122
1122
  );
1123
1123
  const getFilesForUpload = react.useCallback(() => validFiles.map((f) => f.file), [validFiles]);
1124
- const processFiles2 = react.useCallback(
1125
- async (newFiles) => {
1124
+ const prepare = react.useCallback(
1125
+ async (collect) => {
1126
1126
  if (runRef.current) {
1127
1127
  console.warn("File processing already in progress. Ignoring duplicate call.");
1128
1128
  return;
1129
1129
  }
1130
- if (!newFiles || newFiles.length === 0) return;
1131
1130
  const run = new AbortController();
1132
1131
  runRef.current = run;
1133
1132
  setState({
@@ -1136,8 +1135,17 @@ function useDrop({ ship }) {
1136
1135
  status: { title: "Processing...", details: "Validating and preparing files." }
1137
1136
  });
1138
1137
  try {
1139
- const outcome = await processFiles(newFiles, {
1140
- limits: await ship.getLimits({ signal: run.signal }),
1138
+ const [files, limits] = await Promise.all([
1139
+ collect(),
1140
+ ship.getLimits({ signal: run.signal })
1141
+ ]);
1142
+ if (run.signal.aborted) return;
1143
+ if (files.length === 0) {
1144
+ setState(initialState);
1145
+ return;
1146
+ }
1147
+ const outcome = await processFiles(files, {
1148
+ limits,
1141
1149
  onStatus: (status) => {
1142
1150
  if (!run.signal.aborted) setState((prev) => ({ ...prev, status }));
1143
1151
  }
@@ -1167,6 +1175,13 @@ function useDrop({ ship }) {
1167
1175
  },
1168
1176
  [ship]
1169
1177
  );
1178
+ const processFiles2 = react.useCallback(
1179
+ async (newFiles) => {
1180
+ if (!newFiles || newFiles.length === 0) return;
1181
+ await prepare(async () => newFiles);
1182
+ },
1183
+ [prepare]
1184
+ );
1170
1185
  const reset = react.useCallback(() => {
1171
1186
  runRef.current?.abort();
1172
1187
  runRef.current = null;
@@ -1205,13 +1220,14 @@ function useDrop({ ship }) {
1205
1220
  if (file) files.push(file);
1206
1221
  }
1207
1222
  }
1208
- await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1209
- if (files.length === 0 && e.dataTransfer.files.length > 0) {
1210
- files.push(...Array.from(e.dataTransfer.files));
1211
- }
1212
- if (files.length > 0) await processFiles2(files);
1223
+ const plain = Array.from(e.dataTransfer.files);
1224
+ if (directories.length === 0 && files.length === 0 && plain.length === 0) return;
1225
+ await prepare(async () => {
1226
+ await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1227
+ return files.length > 0 ? files : plain;
1228
+ });
1213
1229
  },
1214
- [processFiles2]
1230
+ [prepare]
1215
1231
  );
1216
1232
  const handleInputChange = react.useCallback(
1217
1233
  (e) => {