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