@shipstatic/drop 0.1.3 → 0.1.5

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.d.cts CHANGED
@@ -66,6 +66,8 @@ interface DropOptions {
66
66
  interface DropReturn {
67
67
  /** All processed files with their status */
68
68
  files: ProcessedFile[];
69
+ /** Name of the source (file/folder/ZIP) that was dropped/selected */
70
+ sourceName: string;
69
71
  /** Current status text */
70
72
  statusText: string;
71
73
  /** Whether currently processing files (ZIP extraction, etc.) */
@@ -150,26 +152,9 @@ declare function extractZipToFiles(zipFile: File): Promise<ZipExtractionResult>;
150
152
  * normalizePath('/absolute/path.txt') → 'absolute/path.txt'
151
153
  */
152
154
  declare function normalizePath(path: string): string;
153
- /**
154
- * Check if a file path is a junk file that should be filtered out
155
- * Filters common system files like .DS_Store, Thumbs.db, desktop.ini,
156
- * and macOS resource fork metadata in __MACOSX directories
157
- *
158
- * Case-insensitive matching to handle files from different operating systems
159
- * (Windows file systems are case-insensitive, so Thumbs.db === THUMBS.DB)
160
- *
161
- * @example
162
- * isJunkFile('.DS_Store') → true
163
- * isJunkFile('.ds_store') → true (case-insensitive)
164
- * isJunkFile('THUMBS.DB') → true (case-insensitive)
165
- * isJunkFile('folder/.DS_Store') → true
166
- * isJunkFile('__MACOSX/file.txt') → true
167
- * isJunkFile('mydsstore.txt') → false
168
- */
169
- declare function isJunkFile(path: string): boolean;
170
155
  /**
171
156
  * Check if a file is a ZIP file based on MIME type or extension
172
157
  */
173
158
  declare function isZipFile(file: File): boolean;
174
159
 
175
- export { type ClientError, type DropOptions, type DropReturn, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isJunkFile, isZipFile, normalizePath, stripCommonPrefix, useDrop };
160
+ export { type ClientError, type DropOptions, type DropReturn, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isZipFile, normalizePath, stripCommonPrefix, useDrop };
package/dist/index.d.ts CHANGED
@@ -66,6 +66,8 @@ interface DropOptions {
66
66
  interface DropReturn {
67
67
  /** All processed files with their status */
68
68
  files: ProcessedFile[];
69
+ /** Name of the source (file/folder/ZIP) that was dropped/selected */
70
+ sourceName: string;
69
71
  /** Current status text */
70
72
  statusText: string;
71
73
  /** Whether currently processing files (ZIP extraction, etc.) */
@@ -150,26 +152,9 @@ declare function extractZipToFiles(zipFile: File): Promise<ZipExtractionResult>;
150
152
  * normalizePath('/absolute/path.txt') → 'absolute/path.txt'
151
153
  */
152
154
  declare function normalizePath(path: string): string;
153
- /**
154
- * Check if a file path is a junk file that should be filtered out
155
- * Filters common system files like .DS_Store, Thumbs.db, desktop.ini,
156
- * and macOS resource fork metadata in __MACOSX directories
157
- *
158
- * Case-insensitive matching to handle files from different operating systems
159
- * (Windows file systems are case-insensitive, so Thumbs.db === THUMBS.DB)
160
- *
161
- * @example
162
- * isJunkFile('.DS_Store') → true
163
- * isJunkFile('.ds_store') → true (case-insensitive)
164
- * isJunkFile('THUMBS.DB') → true (case-insensitive)
165
- * isJunkFile('folder/.DS_Store') → true
166
- * isJunkFile('__MACOSX/file.txt') → true
167
- * isJunkFile('mydsstore.txt') → false
168
- */
169
- declare function isJunkFile(path: string): boolean;
170
155
  /**
171
156
  * Check if a file is a ZIP file based on MIME type or extension
172
157
  */
173
158
  declare function isZipFile(file: File): boolean;
174
159
 
175
- export { type ClientError, type DropOptions, type DropReturn, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isJunkFile, isZipFile, normalizePath, stripCommonPrefix, useDrop };
160
+ export { type ClientError, type DropOptions, type DropReturn, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isZipFile, normalizePath, stripCommonPrefix, useDrop };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useState, useRef, useCallback } from 'react';
2
- import { formatFileSize as formatFileSize$1, getValidFiles as getValidFiles$1, validateFiles } from '@shipstatic/ship';
2
+ import { formatFileSize as formatFileSize$1, getValidFiles as getValidFiles$1, filterJunk, validateFiles } from '@shipstatic/ship';
3
3
 
4
4
  var __create = Object.create;
5
5
  var __defProp = Object.defineProperty;
@@ -11735,7 +11735,6 @@ async function extractZipToFiles(zipFile) {
11735
11735
  errors.push(`Skipped invalid path: ${path}`);
11736
11736
  continue;
11737
11737
  }
11738
- if (isJunkFile(sanitizedPath)) continue;
11739
11738
  try {
11740
11739
  const content = await entry.async("blob");
11741
11740
  const mimeType = getMimeType(sanitizedPath);
@@ -11773,11 +11772,6 @@ function normalizePath(path) {
11773
11772
  }
11774
11773
  return normalized.join("/");
11775
11774
  }
11776
- function isJunkFile(path) {
11777
- const basename = (path.split("/").pop() || "").toLowerCase();
11778
- const junkFiles = [".ds_store", "thumbs.db", "desktop.ini", "._.ds_store"];
11779
- return path.toLowerCase().startsWith("__macosx/") || junkFiles.includes(basename);
11780
- }
11781
11775
  function isZipFile(file) {
11782
11776
  return file.type === "application/zip" || file.type === "application/x-zip-compressed" || file.name.toLowerCase().endsWith(".zip");
11783
11777
  }
@@ -11846,6 +11840,7 @@ function useDrop(options) {
11846
11840
  stripPrefix = true
11847
11841
  } = options;
11848
11842
  const [files, setFiles] = useState([]);
11843
+ const [sourceName, setSourceName] = useState("");
11849
11844
  const [statusText, setStatusText] = useState("");
11850
11845
  const [isProcessing, setIsProcessing] = useState(false);
11851
11846
  const [validationError, setValidationError] = useState(null);
@@ -11865,6 +11860,18 @@ function useDrop(options) {
11865
11860
  setValidationError(null);
11866
11861
  setStatusText("Processing files...");
11867
11862
  try {
11863
+ let detectedSourceName = "";
11864
+ if (newFiles.length === 1 && isZipFile(newFiles[0])) {
11865
+ detectedSourceName = newFiles[0].name.replace(/\.zip$/i, "");
11866
+ } else if (newFiles.length > 0) {
11867
+ const firstPath = newFiles[0].webkitRelativePath || "";
11868
+ if (firstPath && firstPath.includes("/")) {
11869
+ detectedSourceName = firstPath.split("/")[0];
11870
+ } else {
11871
+ detectedSourceName = newFiles[0].name;
11872
+ }
11873
+ }
11874
+ setSourceName(detectedSourceName);
11868
11875
  const allFiles = [];
11869
11876
  const shouldExtractZip = newFiles.length === 1 && isZipFile(newFiles[0]);
11870
11877
  if (shouldExtractZip) {
@@ -11878,9 +11885,16 @@ function useDrop(options) {
11878
11885
  } else {
11879
11886
  allFiles.push(...newFiles);
11880
11887
  }
11888
+ const getFilePath = (f) => {
11889
+ const webkitPath = f.webkitRelativePath;
11890
+ return webkitPath && webkitPath.trim() ? webkitPath : f.name;
11891
+ };
11892
+ const filePaths = allFiles.map(getFilePath);
11893
+ const validPaths = new Set(filterJunk(filePaths));
11894
+ const cleanFiles = allFiles.filter((f) => validPaths.has(getFilePath(f)));
11881
11895
  setStatusText("Processing files...");
11882
11896
  const processedFiles = await Promise.all(
11883
- allFiles.map((file) => createProcessedFile(file))
11897
+ cleanFiles.map((file) => createProcessedFile(file))
11884
11898
  );
11885
11899
  const finalFiles = stripPrefix ? stripCommonPrefix(processedFiles) : processedFiles;
11886
11900
  const config = await ship.getConfig();
@@ -11919,6 +11933,7 @@ function useDrop(options) {
11919
11933
  }, [ship, onValidationError, onFilesReady, stripPrefix]);
11920
11934
  const clearAll = useCallback(() => {
11921
11935
  setFiles([]);
11936
+ setSourceName("");
11922
11937
  setStatusText("");
11923
11938
  setValidationError(null);
11924
11939
  isProcessingRef.current = false;
@@ -11934,6 +11949,7 @@ function useDrop(options) {
11934
11949
  }, []);
11935
11950
  return {
11936
11951
  files,
11952
+ sourceName,
11937
11953
  statusText,
11938
11954
  isProcessing,
11939
11955
  validationError,
@@ -11967,6 +11983,6 @@ mime-db/index.js:
11967
11983
  *)
11968
11984
  */
11969
11985
 
11970
- export { FILE_STATUSES, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isJunkFile, isZipFile, normalizePath, stripCommonPrefix, useDrop };
11986
+ export { FILE_STATUSES, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isZipFile, normalizePath, stripCommonPrefix, useDrop };
11971
11987
  //# sourceMappingURL=index.js.map
11972
11988
  //# sourceMappingURL=index.js.map