@shipstatic/drop 0.1.18 → 0.2.0
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 -10
- package/dist/index.cjs +23 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -12
- package/dist/index.d.ts +17 -12
- package/dist/index.js +23 -19
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -93,6 +93,11 @@ interface DropOptions {
|
|
|
93
93
|
/** Whether to strip common directory prefix from paths (default: true) */
|
|
94
94
|
stripPrefix?: boolean;
|
|
95
95
|
}
|
|
96
|
+
/** Options for getDropzoneProps() */
|
|
97
|
+
interface DropzonePropsOptions {
|
|
98
|
+
/** Whether clicking the dropzone opens the file picker (default: true) */
|
|
99
|
+
clickable?: boolean;
|
|
100
|
+
}
|
|
96
101
|
interface DropReturn {
|
|
97
102
|
/** Current phase of the state machine */
|
|
98
103
|
phase: DropStateValue;
|
|
@@ -100,6 +105,10 @@ interface DropReturn {
|
|
|
100
105
|
isProcessing: boolean;
|
|
101
106
|
/** Whether user is currently dragging over the dropzone */
|
|
102
107
|
isDragging: boolean;
|
|
108
|
+
/** Whether the dropzone is interactive (idle, dragging, or ready - not processing or error) */
|
|
109
|
+
isInteractive: boolean;
|
|
110
|
+
/** Whether an error occurred during processing */
|
|
111
|
+
hasError: boolean;
|
|
103
112
|
/** Flattened access to files */
|
|
104
113
|
files: ProcessedFile[];
|
|
105
114
|
/** Flattened access to source name */
|
|
@@ -110,12 +119,12 @@ interface DropReturn {
|
|
|
110
119
|
details: string;
|
|
111
120
|
errors?: string[];
|
|
112
121
|
} | null;
|
|
113
|
-
/** Get props to spread on dropzone element (handles drag & drop) */
|
|
114
|
-
getDropzoneProps: () => {
|
|
122
|
+
/** Get props to spread on dropzone element (handles drag & drop, optionally click) */
|
|
123
|
+
getDropzoneProps: (options?: DropzonePropsOptions) => {
|
|
115
124
|
onDragOver: (e: React.DragEvent) => void;
|
|
116
125
|
onDragLeave: (e: React.DragEvent) => void;
|
|
117
126
|
onDrop: (e: React.DragEvent) => void;
|
|
118
|
-
onClick
|
|
127
|
+
onClick?: () => void;
|
|
119
128
|
};
|
|
120
129
|
/** Get props to spread on hidden file input element */
|
|
121
130
|
getInputProps: () => {
|
|
@@ -132,16 +141,12 @@ interface DropReturn {
|
|
|
132
141
|
open: () => void;
|
|
133
142
|
/** Manually process files (for advanced usage) */
|
|
134
143
|
processFiles: (files: File[]) => Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
|
|
144
|
+
/** Reset state and clear all files */
|
|
145
|
+
reset: () => void;
|
|
137
146
|
/** Get only valid files ready for upload */
|
|
138
147
|
validFiles: ProcessedFile[];
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
status: FileStatus;
|
|
142
|
-
statusMessage?: string;
|
|
143
|
-
progress?: number;
|
|
144
|
-
}) => void;
|
|
148
|
+
/** Get raw File objects ready for Ship SDK upload */
|
|
149
|
+
getFilesForUpload: () => File[];
|
|
145
150
|
}
|
|
146
151
|
/**
|
|
147
152
|
* Headless drop hook for file upload workflows
|
|
@@ -227,4 +232,4 @@ declare function isZipFile(file: File): boolean;
|
|
|
227
232
|
*/
|
|
228
233
|
declare function getMimeType(path: string): string;
|
|
229
234
|
|
|
230
|
-
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, FILE_STATUSES, type FileStatus, type FileWithPath, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getMimeType, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
|
235
|
+
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, type DropzonePropsOptions, FILE_STATUSES, type FileStatus, type FileWithPath, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getMimeType, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,11 @@ interface DropOptions {
|
|
|
93
93
|
/** Whether to strip common directory prefix from paths (default: true) */
|
|
94
94
|
stripPrefix?: boolean;
|
|
95
95
|
}
|
|
96
|
+
/** Options for getDropzoneProps() */
|
|
97
|
+
interface DropzonePropsOptions {
|
|
98
|
+
/** Whether clicking the dropzone opens the file picker (default: true) */
|
|
99
|
+
clickable?: boolean;
|
|
100
|
+
}
|
|
96
101
|
interface DropReturn {
|
|
97
102
|
/** Current phase of the state machine */
|
|
98
103
|
phase: DropStateValue;
|
|
@@ -100,6 +105,10 @@ interface DropReturn {
|
|
|
100
105
|
isProcessing: boolean;
|
|
101
106
|
/** Whether user is currently dragging over the dropzone */
|
|
102
107
|
isDragging: boolean;
|
|
108
|
+
/** Whether the dropzone is interactive (idle, dragging, or ready - not processing or error) */
|
|
109
|
+
isInteractive: boolean;
|
|
110
|
+
/** Whether an error occurred during processing */
|
|
111
|
+
hasError: boolean;
|
|
103
112
|
/** Flattened access to files */
|
|
104
113
|
files: ProcessedFile[];
|
|
105
114
|
/** Flattened access to source name */
|
|
@@ -110,12 +119,12 @@ interface DropReturn {
|
|
|
110
119
|
details: string;
|
|
111
120
|
errors?: string[];
|
|
112
121
|
} | null;
|
|
113
|
-
/** Get props to spread on dropzone element (handles drag & drop) */
|
|
114
|
-
getDropzoneProps: () => {
|
|
122
|
+
/** Get props to spread on dropzone element (handles drag & drop, optionally click) */
|
|
123
|
+
getDropzoneProps: (options?: DropzonePropsOptions) => {
|
|
115
124
|
onDragOver: (e: React.DragEvent) => void;
|
|
116
125
|
onDragLeave: (e: React.DragEvent) => void;
|
|
117
126
|
onDrop: (e: React.DragEvent) => void;
|
|
118
|
-
onClick
|
|
127
|
+
onClick?: () => void;
|
|
119
128
|
};
|
|
120
129
|
/** Get props to spread on hidden file input element */
|
|
121
130
|
getInputProps: () => {
|
|
@@ -132,16 +141,12 @@ interface DropReturn {
|
|
|
132
141
|
open: () => void;
|
|
133
142
|
/** Manually process files (for advanced usage) */
|
|
134
143
|
processFiles: (files: File[]) => Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
|
|
144
|
+
/** Reset state and clear all files */
|
|
145
|
+
reset: () => void;
|
|
137
146
|
/** Get only valid files ready for upload */
|
|
138
147
|
validFiles: ProcessedFile[];
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
status: FileStatus;
|
|
142
|
-
statusMessage?: string;
|
|
143
|
-
progress?: number;
|
|
144
|
-
}) => void;
|
|
148
|
+
/** Get raw File objects ready for Ship SDK upload */
|
|
149
|
+
getFilesForUpload: () => File[];
|
|
145
150
|
}
|
|
146
151
|
/**
|
|
147
152
|
* Headless drop hook for file upload workflows
|
|
@@ -227,4 +232,4 @@ declare function isZipFile(file: File): boolean;
|
|
|
227
232
|
*/
|
|
228
233
|
declare function getMimeType(path: string): string;
|
|
229
234
|
|
|
230
|
-
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, FILE_STATUSES, type FileStatus, type FileWithPath, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getMimeType, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
|
235
|
+
export { type ClientError, type DropOptions, type DropReturn, type DropState, type DropStateValue, type DropStatus, type DropzonePropsOptions, FILE_STATUSES, type FileStatus, type FileWithPath, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getMimeType, isZipFile, normalizePath, stripCommonPrefix, traverseFileTree, useDrop };
|
package/dist/index.js
CHANGED
|
@@ -11700,7 +11700,7 @@ var require_mime_db = __commonJS({
|
|
|
11700
11700
|
}
|
|
11701
11701
|
});
|
|
11702
11702
|
|
|
11703
|
-
// node_modules/.pnpm/@shipstatic+types@0.4.
|
|
11703
|
+
// node_modules/.pnpm/@shipstatic+types@0.4.7/node_modules/@shipstatic/types/dist/index.js
|
|
11704
11704
|
var ErrorType;
|
|
11705
11705
|
(function(ErrorType2) {
|
|
11706
11706
|
ErrorType2["Validation"] = "validation_failed";
|
|
@@ -11914,7 +11914,15 @@ function useDrop(options) {
|
|
|
11914
11914
|
const inputRef = useRef(null);
|
|
11915
11915
|
const isProcessing = useMemo(() => state.value === "processing", [state.value]);
|
|
11916
11916
|
const isDragging = useMemo(() => state.value === "dragging", [state.value]);
|
|
11917
|
+
const isInteractive = useMemo(
|
|
11918
|
+
() => state.value === "idle" || state.value === "dragging" || state.value === "ready",
|
|
11919
|
+
[state.value]
|
|
11920
|
+
);
|
|
11921
|
+
const hasError = useMemo(() => state.value === "error", [state.value]);
|
|
11917
11922
|
const validFiles = useMemo(() => getValidFiles(state.files), [state.files]);
|
|
11923
|
+
const getFilesForUpload = useCallback(() => {
|
|
11924
|
+
return validFiles.map((f) => f.file);
|
|
11925
|
+
}, [validFiles]);
|
|
11918
11926
|
const processFiles = useCallback(async (newFiles) => {
|
|
11919
11927
|
if (isProcessingRef.current) {
|
|
11920
11928
|
console.warn("File processing already in progress. Ignoring duplicate call.");
|
|
@@ -12025,18 +12033,10 @@ function useDrop(options) {
|
|
|
12025
12033
|
isProcessingRef.current = false;
|
|
12026
12034
|
}
|
|
12027
12035
|
}, [ship, onValidationError, onFilesReady, stripPrefix]);
|
|
12028
|
-
const
|
|
12036
|
+
const reset = useCallback(() => {
|
|
12029
12037
|
setState(initialState);
|
|
12030
12038
|
isProcessingRef.current = false;
|
|
12031
12039
|
}, []);
|
|
12032
|
-
const updateFileStatus = useCallback((fileId, fileState) => {
|
|
12033
|
-
setState((prev) => ({
|
|
12034
|
-
...prev,
|
|
12035
|
-
files: prev.files.map(
|
|
12036
|
-
(file) => file.id === fileId ? { ...file, ...fileState } : file
|
|
12037
|
-
)
|
|
12038
|
-
}));
|
|
12039
|
-
}, []);
|
|
12040
12040
|
const handleDragOver = useCallback((e) => {
|
|
12041
12041
|
e.preventDefault();
|
|
12042
12042
|
setState((prev) => {
|
|
@@ -12119,12 +12119,15 @@ function useDrop(options) {
|
|
|
12119
12119
|
const open = useCallback(() => {
|
|
12120
12120
|
inputRef.current?.click();
|
|
12121
12121
|
}, []);
|
|
12122
|
-
const getDropzoneProps = useCallback(() =>
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
|
|
12126
|
-
|
|
12127
|
-
|
|
12122
|
+
const getDropzoneProps = useCallback((options2) => {
|
|
12123
|
+
const { clickable = true } = options2 ?? {};
|
|
12124
|
+
return {
|
|
12125
|
+
onDragOver: handleDragOver,
|
|
12126
|
+
onDragLeave: handleDragLeave,
|
|
12127
|
+
onDrop: handleDrop,
|
|
12128
|
+
...clickable && { onClick: open }
|
|
12129
|
+
};
|
|
12130
|
+
}, [handleDragOver, handleDragLeave, handleDrop, open]);
|
|
12128
12131
|
const getInputProps = useCallback(() => ({
|
|
12129
12132
|
ref: inputRef,
|
|
12130
12133
|
type: "file",
|
|
@@ -12134,11 +12137,12 @@ function useDrop(options) {
|
|
|
12134
12137
|
onChange: handleInputChange
|
|
12135
12138
|
}), [handleInputChange]);
|
|
12136
12139
|
return {
|
|
12137
|
-
// State machine
|
|
12138
12140
|
// Convenience getters (computed from state)
|
|
12139
12141
|
phase: state.value,
|
|
12140
12142
|
isProcessing,
|
|
12141
12143
|
isDragging,
|
|
12144
|
+
isInteractive,
|
|
12145
|
+
hasError,
|
|
12142
12146
|
files: state.files,
|
|
12143
12147
|
sourceName: state.sourceName,
|
|
12144
12148
|
status: state.status,
|
|
@@ -12148,10 +12152,10 @@ function useDrop(options) {
|
|
|
12148
12152
|
// Actions
|
|
12149
12153
|
open,
|
|
12150
12154
|
processFiles,
|
|
12151
|
-
|
|
12155
|
+
reset,
|
|
12152
12156
|
// Helpers
|
|
12153
12157
|
validFiles,
|
|
12154
|
-
|
|
12158
|
+
getFilesForUpload
|
|
12155
12159
|
};
|
|
12156
12160
|
}
|
|
12157
12161
|
/*! Bundled license information:
|