@shipstatic/drop 0.1.2 → 0.1.3
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/LICENSE +21 -0
- package/README.md +181 -42
- package/dist/index.cjs +24 -589
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -45
- package/dist/index.d.ts +20 -45
- package/dist/index.js +25 -586
- package/dist/index.js.map +1 -1
- package/package.json +7 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StaticFile } from '@shipstatic/types';
|
|
2
|
+
import { Ship, formatFileSize as formatFileSize$1 } from '@shipstatic/ship';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Core types for @shipstatic/dropzone
|
|
@@ -20,10 +21,12 @@ declare const FILE_STATUSES: {
|
|
|
20
21
|
type FileStatus = (typeof FILE_STATUSES)[keyof typeof FILE_STATUSES];
|
|
21
22
|
/**
|
|
22
23
|
* Client-side error structure
|
|
24
|
+
* Matches ValidationError from @shipstatic/ship for consistency
|
|
23
25
|
*/
|
|
24
26
|
interface ClientError {
|
|
25
27
|
error: string;
|
|
26
28
|
details: string;
|
|
29
|
+
errors?: string[];
|
|
27
30
|
isClientError: true;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
@@ -49,25 +52,14 @@ interface ProcessedFile extends StaticFile {
|
|
|
49
52
|
/** Upload progress (0-100) - only set during upload */
|
|
50
53
|
progress?: number;
|
|
51
54
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Validation configuration - direct alias to SDK's ConfigResponse
|
|
54
|
-
* This allows passing the config directly from ship.getConfig() to the dropzone
|
|
55
|
-
*
|
|
56
|
-
* Single source of truth: @shipstatic/types
|
|
57
|
-
*/
|
|
58
|
-
type ValidationConfig = ConfigResponse;
|
|
59
|
-
/**
|
|
60
|
-
* Default validation limits
|
|
61
|
-
*/
|
|
62
|
-
declare const DEFAULT_VALIDATION: ConfigResponse;
|
|
63
55
|
|
|
64
56
|
interface DropOptions {
|
|
65
|
-
/**
|
|
66
|
-
|
|
57
|
+
/** Ship SDK instance (required for validation) */
|
|
58
|
+
ship: Ship;
|
|
59
|
+
/** Callback when files are processed and ready */
|
|
60
|
+
onFilesReady?: (files: ProcessedFile[]) => void;
|
|
67
61
|
/** Callback when validation fails */
|
|
68
62
|
onValidationError?: (error: ClientError) => void;
|
|
69
|
-
/** Callback when files are ready for upload */
|
|
70
|
-
onFilesReady?: (files: ProcessedFile[]) => void;
|
|
71
63
|
/** Whether to strip common directory prefix from paths (default: true) */
|
|
72
64
|
stripPrefix?: boolean;
|
|
73
65
|
}
|
|
@@ -80,12 +72,8 @@ interface DropReturn {
|
|
|
80
72
|
isProcessing: boolean;
|
|
81
73
|
/** Last validation error if any */
|
|
82
74
|
validationError: ClientError | null;
|
|
83
|
-
/** Whether all valid files have MD5 checksums calculated */
|
|
84
|
-
hasChecksums: boolean;
|
|
85
75
|
/** Process files from drop (resets and replaces existing files) */
|
|
86
76
|
processFiles: (files: File[]) => Promise<void>;
|
|
87
|
-
/** Remove a specific file */
|
|
88
|
-
removeFile: (fileId: string) => void;
|
|
89
77
|
/** Clear all files and reset state */
|
|
90
78
|
clearAll: () => void;
|
|
91
79
|
/** Get only valid files ready for upload */
|
|
@@ -102,20 +90,25 @@ interface DropReturn {
|
|
|
102
90
|
* Handles file processing, ZIP extraction, and validation
|
|
103
91
|
* Does NOT handle uploading - that's the consumer's responsibility
|
|
104
92
|
*/
|
|
105
|
-
declare function useDrop(options
|
|
93
|
+
declare function useDrop(options: DropOptions): DropReturn;
|
|
106
94
|
|
|
107
95
|
/**
|
|
108
|
-
*
|
|
96
|
+
* Unified file processing utilities
|
|
97
|
+
* Converts Files directly to ProcessedFiles
|
|
109
98
|
*/
|
|
110
|
-
|
|
99
|
+
|
|
111
100
|
/**
|
|
112
101
|
* Format file size to human-readable string
|
|
102
|
+
* Re-exported from Ship SDK for convenience
|
|
113
103
|
*/
|
|
114
|
-
declare
|
|
104
|
+
declare const formatFileSize: typeof formatFileSize$1;
|
|
115
105
|
/**
|
|
116
106
|
* Create a ProcessedFile from a File object
|
|
117
107
|
* This is the single conversion point from File to ProcessedFile
|
|
118
108
|
*
|
|
109
|
+
* Note: MD5 calculation is handled by Ship SDK during deployment.
|
|
110
|
+
* Drop focuses on file processing, path normalization, and UI state management.
|
|
111
|
+
*
|
|
119
112
|
* Path resolution priority:
|
|
120
113
|
* 1. options.path (if provided)
|
|
121
114
|
* 2. file.webkitRelativePath (if non-empty, preserves folder structure)
|
|
@@ -124,30 +117,12 @@ declare function formatFileSize(bytes: number, decimals?: number): string;
|
|
|
124
117
|
declare function createProcessedFile(file: File, options?: {
|
|
125
118
|
/** Custom path (defaults to webkitRelativePath or file.name) */
|
|
126
119
|
path?: string;
|
|
127
|
-
/** Whether to calculate MD5 hash (defaults to true) */
|
|
128
|
-
calculateMD5?: boolean;
|
|
129
120
|
}): Promise<ProcessedFile>;
|
|
130
|
-
/**
|
|
131
|
-
* Validate and update status of ProcessedFiles
|
|
132
|
-
* Returns files with updated status and validation error if any
|
|
133
|
-
*/
|
|
134
|
-
interface ValidationResult {
|
|
135
|
-
/** All files with updated status */
|
|
136
|
-
files: ProcessedFile[];
|
|
137
|
-
/** Files that passed validation (status: READY) */
|
|
138
|
-
validFiles: ProcessedFile[];
|
|
139
|
-
/** Validation error if any files failed */
|
|
140
|
-
error: ClientError | null;
|
|
141
|
-
}
|
|
142
|
-
declare function validateFiles(files: ProcessedFile[], config: ValidationConfig): ValidationResult;
|
|
143
121
|
/**
|
|
144
122
|
* Get only the valid files (status: READY) from a list
|
|
123
|
+
* Re-exported from Ship SDK for convenience
|
|
145
124
|
*/
|
|
146
|
-
declare
|
|
147
|
-
/**
|
|
148
|
-
* Check if all valid files have MD5 checksums calculated
|
|
149
|
-
*/
|
|
150
|
-
declare function allValidFilesHaveChecksums(files: ProcessedFile[]): boolean;
|
|
125
|
+
declare const getValidFiles: (files: ProcessedFile[]) => ProcessedFile[];
|
|
151
126
|
/**
|
|
152
127
|
* Strip common directory prefix from file paths
|
|
153
128
|
* Only strips if ALL files share the same prefix
|
|
@@ -197,4 +172,4 @@ declare function isJunkFile(path: string): boolean;
|
|
|
197
172
|
*/
|
|
198
173
|
declare function isZipFile(file: File): boolean;
|
|
199
174
|
|
|
200
|
-
export { type ClientError,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StaticFile } from '@shipstatic/types';
|
|
2
|
+
import { Ship, formatFileSize as formatFileSize$1 } from '@shipstatic/ship';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Core types for @shipstatic/dropzone
|
|
@@ -20,10 +21,12 @@ declare const FILE_STATUSES: {
|
|
|
20
21
|
type FileStatus = (typeof FILE_STATUSES)[keyof typeof FILE_STATUSES];
|
|
21
22
|
/**
|
|
22
23
|
* Client-side error structure
|
|
24
|
+
* Matches ValidationError from @shipstatic/ship for consistency
|
|
23
25
|
*/
|
|
24
26
|
interface ClientError {
|
|
25
27
|
error: string;
|
|
26
28
|
details: string;
|
|
29
|
+
errors?: string[];
|
|
27
30
|
isClientError: true;
|
|
28
31
|
}
|
|
29
32
|
/**
|
|
@@ -49,25 +52,14 @@ interface ProcessedFile extends StaticFile {
|
|
|
49
52
|
/** Upload progress (0-100) - only set during upload */
|
|
50
53
|
progress?: number;
|
|
51
54
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Validation configuration - direct alias to SDK's ConfigResponse
|
|
54
|
-
* This allows passing the config directly from ship.getConfig() to the dropzone
|
|
55
|
-
*
|
|
56
|
-
* Single source of truth: @shipstatic/types
|
|
57
|
-
*/
|
|
58
|
-
type ValidationConfig = ConfigResponse;
|
|
59
|
-
/**
|
|
60
|
-
* Default validation limits
|
|
61
|
-
*/
|
|
62
|
-
declare const DEFAULT_VALIDATION: ConfigResponse;
|
|
63
55
|
|
|
64
56
|
interface DropOptions {
|
|
65
|
-
/**
|
|
66
|
-
|
|
57
|
+
/** Ship SDK instance (required for validation) */
|
|
58
|
+
ship: Ship;
|
|
59
|
+
/** Callback when files are processed and ready */
|
|
60
|
+
onFilesReady?: (files: ProcessedFile[]) => void;
|
|
67
61
|
/** Callback when validation fails */
|
|
68
62
|
onValidationError?: (error: ClientError) => void;
|
|
69
|
-
/** Callback when files are ready for upload */
|
|
70
|
-
onFilesReady?: (files: ProcessedFile[]) => void;
|
|
71
63
|
/** Whether to strip common directory prefix from paths (default: true) */
|
|
72
64
|
stripPrefix?: boolean;
|
|
73
65
|
}
|
|
@@ -80,12 +72,8 @@ interface DropReturn {
|
|
|
80
72
|
isProcessing: boolean;
|
|
81
73
|
/** Last validation error if any */
|
|
82
74
|
validationError: ClientError | null;
|
|
83
|
-
/** Whether all valid files have MD5 checksums calculated */
|
|
84
|
-
hasChecksums: boolean;
|
|
85
75
|
/** Process files from drop (resets and replaces existing files) */
|
|
86
76
|
processFiles: (files: File[]) => Promise<void>;
|
|
87
|
-
/** Remove a specific file */
|
|
88
|
-
removeFile: (fileId: string) => void;
|
|
89
77
|
/** Clear all files and reset state */
|
|
90
78
|
clearAll: () => void;
|
|
91
79
|
/** Get only valid files ready for upload */
|
|
@@ -102,20 +90,25 @@ interface DropReturn {
|
|
|
102
90
|
* Handles file processing, ZIP extraction, and validation
|
|
103
91
|
* Does NOT handle uploading - that's the consumer's responsibility
|
|
104
92
|
*/
|
|
105
|
-
declare function useDrop(options
|
|
93
|
+
declare function useDrop(options: DropOptions): DropReturn;
|
|
106
94
|
|
|
107
95
|
/**
|
|
108
|
-
*
|
|
96
|
+
* Unified file processing utilities
|
|
97
|
+
* Converts Files directly to ProcessedFiles
|
|
109
98
|
*/
|
|
110
|
-
|
|
99
|
+
|
|
111
100
|
/**
|
|
112
101
|
* Format file size to human-readable string
|
|
102
|
+
* Re-exported from Ship SDK for convenience
|
|
113
103
|
*/
|
|
114
|
-
declare
|
|
104
|
+
declare const formatFileSize: typeof formatFileSize$1;
|
|
115
105
|
/**
|
|
116
106
|
* Create a ProcessedFile from a File object
|
|
117
107
|
* This is the single conversion point from File to ProcessedFile
|
|
118
108
|
*
|
|
109
|
+
* Note: MD5 calculation is handled by Ship SDK during deployment.
|
|
110
|
+
* Drop focuses on file processing, path normalization, and UI state management.
|
|
111
|
+
*
|
|
119
112
|
* Path resolution priority:
|
|
120
113
|
* 1. options.path (if provided)
|
|
121
114
|
* 2. file.webkitRelativePath (if non-empty, preserves folder structure)
|
|
@@ -124,30 +117,12 @@ declare function formatFileSize(bytes: number, decimals?: number): string;
|
|
|
124
117
|
declare function createProcessedFile(file: File, options?: {
|
|
125
118
|
/** Custom path (defaults to webkitRelativePath or file.name) */
|
|
126
119
|
path?: string;
|
|
127
|
-
/** Whether to calculate MD5 hash (defaults to true) */
|
|
128
|
-
calculateMD5?: boolean;
|
|
129
120
|
}): Promise<ProcessedFile>;
|
|
130
|
-
/**
|
|
131
|
-
* Validate and update status of ProcessedFiles
|
|
132
|
-
* Returns files with updated status and validation error if any
|
|
133
|
-
*/
|
|
134
|
-
interface ValidationResult {
|
|
135
|
-
/** All files with updated status */
|
|
136
|
-
files: ProcessedFile[];
|
|
137
|
-
/** Files that passed validation (status: READY) */
|
|
138
|
-
validFiles: ProcessedFile[];
|
|
139
|
-
/** Validation error if any files failed */
|
|
140
|
-
error: ClientError | null;
|
|
141
|
-
}
|
|
142
|
-
declare function validateFiles(files: ProcessedFile[], config: ValidationConfig): ValidationResult;
|
|
143
121
|
/**
|
|
144
122
|
* Get only the valid files (status: READY) from a list
|
|
123
|
+
* Re-exported from Ship SDK for convenience
|
|
145
124
|
*/
|
|
146
|
-
declare
|
|
147
|
-
/**
|
|
148
|
-
* Check if all valid files have MD5 checksums calculated
|
|
149
|
-
*/
|
|
150
|
-
declare function allValidFilesHaveChecksums(files: ProcessedFile[]): boolean;
|
|
125
|
+
declare const getValidFiles: (files: ProcessedFile[]) => ProcessedFile[];
|
|
151
126
|
/**
|
|
152
127
|
* Strip common directory prefix from file paths
|
|
153
128
|
* Only strips if ALL files share the same prefix
|
|
@@ -197,4 +172,4 @@ declare function isJunkFile(path: string): boolean;
|
|
|
197
172
|
*/
|
|
198
173
|
declare function isZipFile(file: File): boolean;
|
|
199
174
|
|
|
200
|
-
export { type ClientError,
|
|
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 };
|