@shipstatic/drop 2.10.4-beta.6 → 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 +48 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1108,7 +1108,7 @@ var initialState = {
|
|
|
1108
1108
|
};
|
|
1109
1109
|
function useDrop({ ship }) {
|
|
1110
1110
|
const [state, setState] = useState(initialState);
|
|
1111
|
-
const
|
|
1111
|
+
const runRef = useRef(null);
|
|
1112
1112
|
const folderInputRef = useRef(null);
|
|
1113
1113
|
const filesInputRef = useRef(null);
|
|
1114
1114
|
const isProcessing = state.phase === "processing";
|
|
@@ -1119,24 +1119,36 @@ function useDrop({ ship }) {
|
|
|
1119
1119
|
[state.files]
|
|
1120
1120
|
);
|
|
1121
1121
|
const getFilesForUpload = useCallback(() => validFiles.map((f) => f.file), [validFiles]);
|
|
1122
|
-
const
|
|
1123
|
-
async (
|
|
1124
|
-
if (
|
|
1122
|
+
const prepare = useCallback(
|
|
1123
|
+
async (collect) => {
|
|
1124
|
+
if (runRef.current) {
|
|
1125
1125
|
console.warn("File processing already in progress. Ignoring duplicate call.");
|
|
1126
1126
|
return;
|
|
1127
1127
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1128
|
+
const run = new AbortController();
|
|
1129
|
+
runRef.current = run;
|
|
1130
1130
|
setState({
|
|
1131
1131
|
...initialState,
|
|
1132
1132
|
phase: "processing",
|
|
1133
1133
|
status: { title: "Processing...", details: "Validating and preparing files." }
|
|
1134
1134
|
});
|
|
1135
1135
|
try {
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1138
|
-
|
|
1136
|
+
const [files, limits] = await Promise.all([
|
|
1137
|
+
collect(),
|
|
1138
|
+
ship.getLimits({ signal: run.signal })
|
|
1139
|
+
]);
|
|
1140
|
+
if (run.signal.aborted) return;
|
|
1141
|
+
if (files.length === 0) {
|
|
1142
|
+
setState(initialState);
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
const outcome = await processFiles(files, {
|
|
1146
|
+
limits,
|
|
1147
|
+
onStatus: (status) => {
|
|
1148
|
+
if (!run.signal.aborted) setState((prev) => ({ ...prev, status }));
|
|
1149
|
+
}
|
|
1139
1150
|
});
|
|
1151
|
+
if (run.signal.aborted) return;
|
|
1140
1152
|
setState({
|
|
1141
1153
|
phase: outcome.phase,
|
|
1142
1154
|
isDragging: false,
|
|
@@ -1145,15 +1157,33 @@ function useDrop({ ship }) {
|
|
|
1145
1157
|
status: outcome.status,
|
|
1146
1158
|
needsBuild: outcome.needsBuild
|
|
1147
1159
|
});
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
if (run.signal.aborted) return;
|
|
1162
|
+
setState({
|
|
1163
|
+
...initialState,
|
|
1164
|
+
phase: "error",
|
|
1165
|
+
status: {
|
|
1166
|
+
title: "Processing Failed",
|
|
1167
|
+
details: error instanceof Error ? error.message : String(error)
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1148
1170
|
} finally {
|
|
1149
|
-
|
|
1171
|
+
if (runRef.current === run) runRef.current = null;
|
|
1150
1172
|
}
|
|
1151
1173
|
},
|
|
1152
1174
|
[ship]
|
|
1153
1175
|
);
|
|
1176
|
+
const processFiles2 = useCallback(
|
|
1177
|
+
async (newFiles) => {
|
|
1178
|
+
if (!newFiles || newFiles.length === 0) return;
|
|
1179
|
+
await prepare(async () => newFiles);
|
|
1180
|
+
},
|
|
1181
|
+
[prepare]
|
|
1182
|
+
);
|
|
1154
1183
|
const reset = useCallback(() => {
|
|
1184
|
+
runRef.current?.abort();
|
|
1185
|
+
runRef.current = null;
|
|
1155
1186
|
setState(initialState);
|
|
1156
|
-
isProcessingRef.current = false;
|
|
1157
1187
|
}, []);
|
|
1158
1188
|
const handleDragOver = useCallback((e) => {
|
|
1159
1189
|
e.preventDefault();
|
|
@@ -1188,13 +1218,14 @@ function useDrop({ ship }) {
|
|
|
1188
1218
|
if (file) files.push(file);
|
|
1189
1219
|
}
|
|
1190
1220
|
}
|
|
1191
|
-
|
|
1192
|
-
if (
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1221
|
+
const plain = Array.from(e.dataTransfer.files);
|
|
1222
|
+
if (directories.length === 0 && files.length === 0 && plain.length === 0) return;
|
|
1223
|
+
await prepare(async () => {
|
|
1224
|
+
await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
|
|
1225
|
+
return files.length > 0 ? files : plain;
|
|
1226
|
+
});
|
|
1196
1227
|
},
|
|
1197
|
-
[
|
|
1228
|
+
[prepare]
|
|
1198
1229
|
);
|
|
1199
1230
|
const handleInputChange = useCallback(
|
|
1200
1231
|
(e) => {
|