@shipstatic/drop 2.10.4-beta.1 → 2.10.4-beta.10

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.js CHANGED
@@ -1108,7 +1108,7 @@ var initialState = {
1108
1108
  };
1109
1109
  function useDrop({ ship }) {
1110
1110
  const [state, setState] = useState(initialState);
1111
- const isProcessingRef = useRef(false);
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,40 @@ function useDrop({ ship }) {
1119
1119
  [state.files]
1120
1120
  );
1121
1121
  const getFilesForUpload = useCallback(() => validFiles.map((f) => f.file), [validFiles]);
1122
- const processFiles2 = useCallback(
1123
- async (newFiles) => {
1124
- if (isProcessingRef.current) {
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
- if (!newFiles || newFiles.length === 0) return;
1129
- isProcessingRef.current = true;
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 outcome = await processFiles(newFiles, {
1137
- limits: await ship.getLimits(),
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({
1143
+ ...initialState,
1144
+ phase: "error",
1145
+ status: { title: "Empty Folder", details: "It has no files to deploy." }
1146
+ });
1147
+ return;
1148
+ }
1149
+ const outcome = await processFiles(files, {
1150
+ limits,
1151
+ // The pipeline says its status before its first wait, so a
1152
+ // cancelled run has none left to say.
1138
1153
  onStatus: (status) => setState((prev) => ({ ...prev, status }))
1139
1154
  });
1155
+ if (run.signal.aborted) return;
1140
1156
  setState({
1141
1157
  phase: outcome.phase,
1142
1158
  isDragging: false,
@@ -1145,15 +1161,33 @@ function useDrop({ ship }) {
1145
1161
  status: outcome.status,
1146
1162
  needsBuild: outcome.needsBuild
1147
1163
  });
1164
+ } catch (error) {
1165
+ if (run.signal.aborted) return;
1166
+ setState({
1167
+ ...initialState,
1168
+ phase: "error",
1169
+ status: {
1170
+ title: "Processing Failed",
1171
+ details: error instanceof Error ? error.message : String(error)
1172
+ }
1173
+ });
1148
1174
  } finally {
1149
- isProcessingRef.current = false;
1175
+ if (runRef.current === run) runRef.current = null;
1150
1176
  }
1151
1177
  },
1152
1178
  [ship]
1153
1179
  );
1180
+ const processFiles2 = useCallback(
1181
+ async (newFiles) => {
1182
+ if (!newFiles || newFiles.length === 0) return;
1183
+ await prepare(async () => newFiles);
1184
+ },
1185
+ [prepare]
1186
+ );
1154
1187
  const reset = useCallback(() => {
1188
+ runRef.current?.abort();
1189
+ runRef.current = null;
1155
1190
  setState(initialState);
1156
- isProcessingRef.current = false;
1157
1191
  }, []);
1158
1192
  const handleDragOver = useCallback((e) => {
1159
1193
  e.preventDefault();
@@ -1188,13 +1222,13 @@ function useDrop({ ship }) {
1188
1222
  if (file) files.push(file);
1189
1223
  }
1190
1224
  }
1191
- await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1192
- if (files.length === 0 && e.dataTransfer.files.length > 0) {
1193
- files.push(...Array.from(e.dataTransfer.files));
1194
- }
1195
- if (files.length > 0) await processFiles2(files);
1225
+ if (directories.length === 0 && files.length === 0) return;
1226
+ await prepare(async () => {
1227
+ await Promise.all(directories.map((d) => traverseFileTree(d.entry, files, d.path)));
1228
+ return files;
1229
+ });
1196
1230
  },
1197
- [processFiles2]
1231
+ [prepare]
1198
1232
  );
1199
1233
  const handleInputChange = useCallback(
1200
1234
  (e) => {