@shipstatic/drop 0.1.8 → 0.1.9
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/README.md +38 -39
- package/dist/index.cjs +13 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -10
- package/dist/index.d.ts +19 -10
- package/dist/index.js +14 -9
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.d.cts
CHANGED
|
@@ -62,6 +62,7 @@ type DropStateValue = 'idle' | 'dragging' | 'processing' | 'ready' | 'error';
|
|
|
62
62
|
interface DropStatus {
|
|
63
63
|
title: string;
|
|
64
64
|
details: string;
|
|
65
|
+
errors?: string[];
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* State machine state for the drop hook
|
|
@@ -84,12 +85,21 @@ interface DropOptions {
|
|
|
84
85
|
stripPrefix?: boolean;
|
|
85
86
|
}
|
|
86
87
|
interface DropReturn {
|
|
87
|
-
/** Current
|
|
88
|
-
|
|
88
|
+
/** Current phase of the state machine */
|
|
89
|
+
phase: DropStateValue;
|
|
89
90
|
/** Whether currently processing files (ZIP extraction, etc.) */
|
|
90
91
|
isProcessing: boolean;
|
|
91
92
|
/** Whether user is currently dragging over the dropzone */
|
|
92
93
|
isDragging: boolean;
|
|
94
|
+
/** Flattened access to files */
|
|
95
|
+
files: ProcessedFile[];
|
|
96
|
+
/** Flattened access to source name */
|
|
97
|
+
sourceName: string;
|
|
98
|
+
/** Flattened access to status */
|
|
99
|
+
status: {
|
|
100
|
+
title: string;
|
|
101
|
+
details: string;
|
|
102
|
+
} | null;
|
|
93
103
|
/** Get props to spread on dropzone element (handles drag & drop) */
|
|
94
104
|
getDropzoneProps: () => {
|
|
95
105
|
onDragOver: (e: React.DragEvent) => void;
|
|
@@ -115,7 +125,7 @@ interface DropReturn {
|
|
|
115
125
|
/** Clear all files and reset state */
|
|
116
126
|
clearAll: () => void;
|
|
117
127
|
/** Get only valid files ready for upload */
|
|
118
|
-
|
|
128
|
+
validFiles: ProcessedFile[];
|
|
119
129
|
/** Update upload state for a specific file (status, progress, message) */
|
|
120
130
|
updateFileStatus: (fileId: string, state: {
|
|
121
131
|
status: FileStatus;
|
|
@@ -144,7 +154,6 @@ declare function useDrop(options: DropOptions): DropReturn;
|
|
|
144
154
|
* Unified file processing utilities
|
|
145
155
|
* Converts Files directly to ProcessedFiles
|
|
146
156
|
*/
|
|
147
|
-
|
|
148
157
|
/**
|
|
149
158
|
* Format file size to human-readable string
|
|
150
159
|
* Re-exported from Ship SDK for convenience
|
|
@@ -166,16 +175,16 @@ declare function createProcessedFile(file: File, options?: {
|
|
|
166
175
|
/** Custom path (defaults to webkitRelativePath or file.name) */
|
|
167
176
|
path?: string;
|
|
168
177
|
}): Promise<ProcessedFile>;
|
|
169
|
-
/**
|
|
170
|
-
* Get only the valid files (status: READY) from a list
|
|
171
|
-
* Re-exported from Ship SDK for convenience
|
|
172
|
-
*/
|
|
173
|
-
declare const getValidFiles: (files: ProcessedFile[]) => ProcessedFile[];
|
|
174
178
|
/**
|
|
175
179
|
* Strip common directory prefix from file paths
|
|
176
180
|
* Only strips if ALL files share the same prefix
|
|
177
181
|
*/
|
|
178
182
|
declare function stripCommonPrefix(files: ProcessedFile[]): ProcessedFile[];
|
|
183
|
+
/**
|
|
184
|
+
* Recursively traverse FileSystemEntry from drag & drop to collect all files
|
|
185
|
+
* Properly sets webkitRelativePath to preserve folder structure
|
|
186
|
+
*/
|
|
187
|
+
declare function traverseFileTree(entry: FileSystemEntry, files: File[], currentPath?: string): Promise<void>;
|
|
179
188
|
|
|
180
189
|
interface ZipExtractionResult {
|
|
181
190
|
/** Extracted files as regular File objects */
|
|
@@ -203,4 +212,4 @@ declare function normalizePath(path: string): string;
|
|
|
203
212
|
*/
|
|
204
213
|
declare function isZipFile(file: File): boolean;
|
|
205
214
|
|
|
206
|
-
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize,
|
|
215
|
+
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,7 @@ type DropStateValue = 'idle' | 'dragging' | 'processing' | 'ready' | 'error';
|
|
|
62
62
|
interface DropStatus {
|
|
63
63
|
title: string;
|
|
64
64
|
details: string;
|
|
65
|
+
errors?: string[];
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* State machine state for the drop hook
|
|
@@ -84,12 +85,21 @@ interface DropOptions {
|
|
|
84
85
|
stripPrefix?: boolean;
|
|
85
86
|
}
|
|
86
87
|
interface DropReturn {
|
|
87
|
-
/** Current
|
|
88
|
-
|
|
88
|
+
/** Current phase of the state machine */
|
|
89
|
+
phase: DropStateValue;
|
|
89
90
|
/** Whether currently processing files (ZIP extraction, etc.) */
|
|
90
91
|
isProcessing: boolean;
|
|
91
92
|
/** Whether user is currently dragging over the dropzone */
|
|
92
93
|
isDragging: boolean;
|
|
94
|
+
/** Flattened access to files */
|
|
95
|
+
files: ProcessedFile[];
|
|
96
|
+
/** Flattened access to source name */
|
|
97
|
+
sourceName: string;
|
|
98
|
+
/** Flattened access to status */
|
|
99
|
+
status: {
|
|
100
|
+
title: string;
|
|
101
|
+
details: string;
|
|
102
|
+
} | null;
|
|
93
103
|
/** Get props to spread on dropzone element (handles drag & drop) */
|
|
94
104
|
getDropzoneProps: () => {
|
|
95
105
|
onDragOver: (e: React.DragEvent) => void;
|
|
@@ -115,7 +125,7 @@ interface DropReturn {
|
|
|
115
125
|
/** Clear all files and reset state */
|
|
116
126
|
clearAll: () => void;
|
|
117
127
|
/** Get only valid files ready for upload */
|
|
118
|
-
|
|
128
|
+
validFiles: ProcessedFile[];
|
|
119
129
|
/** Update upload state for a specific file (status, progress, message) */
|
|
120
130
|
updateFileStatus: (fileId: string, state: {
|
|
121
131
|
status: FileStatus;
|
|
@@ -144,7 +154,6 @@ declare function useDrop(options: DropOptions): DropReturn;
|
|
|
144
154
|
* Unified file processing utilities
|
|
145
155
|
* Converts Files directly to ProcessedFiles
|
|
146
156
|
*/
|
|
147
|
-
|
|
148
157
|
/**
|
|
149
158
|
* Format file size to human-readable string
|
|
150
159
|
* Re-exported from Ship SDK for convenience
|
|
@@ -166,16 +175,16 @@ declare function createProcessedFile(file: File, options?: {
|
|
|
166
175
|
/** Custom path (defaults to webkitRelativePath or file.name) */
|
|
167
176
|
path?: string;
|
|
168
177
|
}): Promise<ProcessedFile>;
|
|
169
|
-
/**
|
|
170
|
-
* Get only the valid files (status: READY) from a list
|
|
171
|
-
* Re-exported from Ship SDK for convenience
|
|
172
|
-
*/
|
|
173
|
-
declare const getValidFiles: (files: ProcessedFile[]) => ProcessedFile[];
|
|
174
178
|
/**
|
|
175
179
|
* Strip common directory prefix from file paths
|
|
176
180
|
* Only strips if ALL files share the same prefix
|
|
177
181
|
*/
|
|
178
182
|
declare function stripCommonPrefix(files: ProcessedFile[]): ProcessedFile[];
|
|
183
|
+
/**
|
|
184
|
+
* Recursively traverse FileSystemEntry from drag & drop to collect all files
|
|
185
|
+
* Properly sets webkitRelativePath to preserve folder structure
|
|
186
|
+
*/
|
|
187
|
+
declare function traverseFileTree(entry: FileSystemEntry, files: File[], currentPath?: string): Promise<void>;
|
|
179
188
|
|
|
180
189
|
interface ZipExtractionResult {
|
|
181
190
|
/** Extracted files as regular File objects */
|
|
@@ -203,4 +212,4 @@ declare function normalizePath(path: string): string;
|
|
|
203
212
|
*/
|
|
204
213
|
declare function isZipFile(file: File): boolean;
|
|
205
214
|
|
|
206
|
-
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize,
|
|
215
|
+
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useRef, useMemo, useCallback } from 'react';
|
|
2
|
-
import { formatFileSize as formatFileSize$1, getValidFiles
|
|
2
|
+
import { formatFileSize as formatFileSize$1, getValidFiles, filterJunk, validateFiles } from '@shipstatic/ship';
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -11811,7 +11811,6 @@ async function createProcessedFile(file, options) {
|
|
|
11811
11811
|
status: FILE_STATUSES.PENDING
|
|
11812
11812
|
};
|
|
11813
11813
|
}
|
|
11814
|
-
var getValidFiles = getValidFiles$1;
|
|
11815
11814
|
function stripCommonPrefix(files) {
|
|
11816
11815
|
if (files.length === 0) return files;
|
|
11817
11816
|
const paths = files.map((f) => f.path);
|
|
@@ -11886,6 +11885,7 @@ function useDrop(options) {
|
|
|
11886
11885
|
const inputRef = useRef(null);
|
|
11887
11886
|
const isProcessing = useMemo(() => state.value === "processing", [state.value]);
|
|
11888
11887
|
const isDragging = useMemo(() => state.value === "dragging", [state.value]);
|
|
11888
|
+
const validFiles = useMemo(() => getValidFiles(state.files), [state.files]);
|
|
11889
11889
|
const processFiles = useCallback(async (newFiles) => {
|
|
11890
11890
|
if (isProcessingRef.current) {
|
|
11891
11891
|
console.warn("File processing already in progress. Ignoring duplicate call.");
|
|
@@ -11951,7 +11951,11 @@ function useDrop(options) {
|
|
|
11951
11951
|
value: "error",
|
|
11952
11952
|
files: validation.files,
|
|
11953
11953
|
sourceName: detectedSourceName,
|
|
11954
|
-
status: {
|
|
11954
|
+
status: {
|
|
11955
|
+
title: validation.error.error,
|
|
11956
|
+
details: validation.error.details,
|
|
11957
|
+
errors: validation.error.errors
|
|
11958
|
+
}
|
|
11955
11959
|
});
|
|
11956
11960
|
onValidationError?.(validation.error);
|
|
11957
11961
|
} else if (validation.validFiles.length > 0) {
|
|
@@ -11996,9 +12000,6 @@ function useDrop(options) {
|
|
|
11996
12000
|
setState(initialState);
|
|
11997
12001
|
isProcessingRef.current = false;
|
|
11998
12002
|
}, []);
|
|
11999
|
-
const getValidFilesCallback = useCallback(() => {
|
|
12000
|
-
return getValidFiles(state.files);
|
|
12001
|
-
}, [state.files]);
|
|
12002
12003
|
const updateFileStatus = useCallback((fileId, fileState) => {
|
|
12003
12004
|
setState((prev) => ({
|
|
12004
12005
|
...prev,
|
|
@@ -12089,10 +12090,14 @@ function useDrop(options) {
|
|
|
12089
12090
|
}), [handleInputChange]);
|
|
12090
12091
|
return {
|
|
12091
12092
|
// State machine
|
|
12092
|
-
state,
|
|
12093
|
+
// state, // REMOVED
|
|
12093
12094
|
// Convenience getters (computed from state)
|
|
12095
|
+
phase: state.value,
|
|
12094
12096
|
isProcessing,
|
|
12095
12097
|
isDragging,
|
|
12098
|
+
files: state.files,
|
|
12099
|
+
sourceName: state.sourceName,
|
|
12100
|
+
status: state.status,
|
|
12096
12101
|
// Primary API: Prop getters
|
|
12097
12102
|
getDropzoneProps,
|
|
12098
12103
|
getInputProps,
|
|
@@ -12101,7 +12106,7 @@ function useDrop(options) {
|
|
|
12101
12106
|
processFiles,
|
|
12102
12107
|
clearAll,
|
|
12103
12108
|
// Helpers
|
|
12104
|
-
|
|
12109
|
+
validFiles,
|
|
12105
12110
|
updateFileStatus
|
|
12106
12111
|
};
|
|
12107
12112
|
}
|
|
@@ -12129,6 +12134,6 @@ mime-db/index.js:
|
|
|
12129
12134
|
*)
|
|
12130
12135
|
*/
|
|
12131
12136
|
|
|
12132
|
-
export { FILE_STATUSES, createProcessedFile, extractZipToFiles, formatFileSize,
|
|
12137
|
+
export { FILE_STATUSES, createProcessedFile, extractZipToFiles, formatFileSize, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
|
12133
12138
|
//# sourceMappingURL=index.js.map
|
|
12134
12139
|
//# sourceMappingURL=index.js.map
|