@shipstatic/drop 0.1.2 → 0.1.4
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 +39 -589
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -45
- package/dist/index.d.ts +22 -45
- package/dist/index.js +40 -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,43 +52,30 @@ 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
|
}
|
|
74
66
|
interface DropReturn {
|
|
75
67
|
/** All processed files with their status */
|
|
76
68
|
files: ProcessedFile[];
|
|
69
|
+
/** Name of the source (file/folder/ZIP) that was dropped/selected */
|
|
70
|
+
sourceName: string;
|
|
77
71
|
/** Current status text */
|
|
78
72
|
statusText: string;
|
|
79
73
|
/** Whether currently processing files (ZIP extraction, etc.) */
|
|
80
74
|
isProcessing: boolean;
|
|
81
75
|
/** Last validation error if any */
|
|
82
76
|
validationError: ClientError | null;
|
|
83
|
-
/** Whether all valid files have MD5 checksums calculated */
|
|
84
|
-
hasChecksums: boolean;
|
|
85
77
|
/** Process files from drop (resets and replaces existing files) */
|
|
86
78
|
processFiles: (files: File[]) => Promise<void>;
|
|
87
|
-
/** Remove a specific file */
|
|
88
|
-
removeFile: (fileId: string) => void;
|
|
89
79
|
/** Clear all files and reset state */
|
|
90
80
|
clearAll: () => void;
|
|
91
81
|
/** Get only valid files ready for upload */
|
|
@@ -102,20 +92,25 @@ interface DropReturn {
|
|
|
102
92
|
* Handles file processing, ZIP extraction, and validation
|
|
103
93
|
* Does NOT handle uploading - that's the consumer's responsibility
|
|
104
94
|
*/
|
|
105
|
-
declare function useDrop(options
|
|
95
|
+
declare function useDrop(options: DropOptions): DropReturn;
|
|
106
96
|
|
|
107
97
|
/**
|
|
108
|
-
*
|
|
98
|
+
* Unified file processing utilities
|
|
99
|
+
* Converts Files directly to ProcessedFiles
|
|
109
100
|
*/
|
|
110
|
-
|
|
101
|
+
|
|
111
102
|
/**
|
|
112
103
|
* Format file size to human-readable string
|
|
104
|
+
* Re-exported from Ship SDK for convenience
|
|
113
105
|
*/
|
|
114
|
-
declare
|
|
106
|
+
declare const formatFileSize: typeof formatFileSize$1;
|
|
115
107
|
/**
|
|
116
108
|
* Create a ProcessedFile from a File object
|
|
117
109
|
* This is the single conversion point from File to ProcessedFile
|
|
118
110
|
*
|
|
111
|
+
* Note: MD5 calculation is handled by Ship SDK during deployment.
|
|
112
|
+
* Drop focuses on file processing, path normalization, and UI state management.
|
|
113
|
+
*
|
|
119
114
|
* Path resolution priority:
|
|
120
115
|
* 1. options.path (if provided)
|
|
121
116
|
* 2. file.webkitRelativePath (if non-empty, preserves folder structure)
|
|
@@ -124,30 +119,12 @@ declare function formatFileSize(bytes: number, decimals?: number): string;
|
|
|
124
119
|
declare function createProcessedFile(file: File, options?: {
|
|
125
120
|
/** Custom path (defaults to webkitRelativePath or file.name) */
|
|
126
121
|
path?: string;
|
|
127
|
-
/** Whether to calculate MD5 hash (defaults to true) */
|
|
128
|
-
calculateMD5?: boolean;
|
|
129
122
|
}): 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
123
|
/**
|
|
144
124
|
* Get only the valid files (status: READY) from a list
|
|
125
|
+
* Re-exported from Ship SDK for convenience
|
|
145
126
|
*/
|
|
146
|
-
declare
|
|
147
|
-
/**
|
|
148
|
-
* Check if all valid files have MD5 checksums calculated
|
|
149
|
-
*/
|
|
150
|
-
declare function allValidFilesHaveChecksums(files: ProcessedFile[]): boolean;
|
|
127
|
+
declare const getValidFiles: (files: ProcessedFile[]) => ProcessedFile[];
|
|
151
128
|
/**
|
|
152
129
|
* Strip common directory prefix from file paths
|
|
153
130
|
* Only strips if ALL files share the same prefix
|
|
@@ -197,4 +174,4 @@ declare function isJunkFile(path: string): boolean;
|
|
|
197
174
|
*/
|
|
198
175
|
declare function isZipFile(file: File): boolean;
|
|
199
176
|
|
|
200
|
-
export { type ClientError,
|
|
177
|
+
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,43 +52,30 @@ 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
|
}
|
|
74
66
|
interface DropReturn {
|
|
75
67
|
/** All processed files with their status */
|
|
76
68
|
files: ProcessedFile[];
|
|
69
|
+
/** Name of the source (file/folder/ZIP) that was dropped/selected */
|
|
70
|
+
sourceName: string;
|
|
77
71
|
/** Current status text */
|
|
78
72
|
statusText: string;
|
|
79
73
|
/** Whether currently processing files (ZIP extraction, etc.) */
|
|
80
74
|
isProcessing: boolean;
|
|
81
75
|
/** Last validation error if any */
|
|
82
76
|
validationError: ClientError | null;
|
|
83
|
-
/** Whether all valid files have MD5 checksums calculated */
|
|
84
|
-
hasChecksums: boolean;
|
|
85
77
|
/** Process files from drop (resets and replaces existing files) */
|
|
86
78
|
processFiles: (files: File[]) => Promise<void>;
|
|
87
|
-
/** Remove a specific file */
|
|
88
|
-
removeFile: (fileId: string) => void;
|
|
89
79
|
/** Clear all files and reset state */
|
|
90
80
|
clearAll: () => void;
|
|
91
81
|
/** Get only valid files ready for upload */
|
|
@@ -102,20 +92,25 @@ interface DropReturn {
|
|
|
102
92
|
* Handles file processing, ZIP extraction, and validation
|
|
103
93
|
* Does NOT handle uploading - that's the consumer's responsibility
|
|
104
94
|
*/
|
|
105
|
-
declare function useDrop(options
|
|
95
|
+
declare function useDrop(options: DropOptions): DropReturn;
|
|
106
96
|
|
|
107
97
|
/**
|
|
108
|
-
*
|
|
98
|
+
* Unified file processing utilities
|
|
99
|
+
* Converts Files directly to ProcessedFiles
|
|
109
100
|
*/
|
|
110
|
-
|
|
101
|
+
|
|
111
102
|
/**
|
|
112
103
|
* Format file size to human-readable string
|
|
104
|
+
* Re-exported from Ship SDK for convenience
|
|
113
105
|
*/
|
|
114
|
-
declare
|
|
106
|
+
declare const formatFileSize: typeof formatFileSize$1;
|
|
115
107
|
/**
|
|
116
108
|
* Create a ProcessedFile from a File object
|
|
117
109
|
* This is the single conversion point from File to ProcessedFile
|
|
118
110
|
*
|
|
111
|
+
* Note: MD5 calculation is handled by Ship SDK during deployment.
|
|
112
|
+
* Drop focuses on file processing, path normalization, and UI state management.
|
|
113
|
+
*
|
|
119
114
|
* Path resolution priority:
|
|
120
115
|
* 1. options.path (if provided)
|
|
121
116
|
* 2. file.webkitRelativePath (if non-empty, preserves folder structure)
|
|
@@ -124,30 +119,12 @@ declare function formatFileSize(bytes: number, decimals?: number): string;
|
|
|
124
119
|
declare function createProcessedFile(file: File, options?: {
|
|
125
120
|
/** Custom path (defaults to webkitRelativePath or file.name) */
|
|
126
121
|
path?: string;
|
|
127
|
-
/** Whether to calculate MD5 hash (defaults to true) */
|
|
128
|
-
calculateMD5?: boolean;
|
|
129
122
|
}): 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
123
|
/**
|
|
144
124
|
* Get only the valid files (status: READY) from a list
|
|
125
|
+
* Re-exported from Ship SDK for convenience
|
|
145
126
|
*/
|
|
146
|
-
declare
|
|
147
|
-
/**
|
|
148
|
-
* Check if all valid files have MD5 checksums calculated
|
|
149
|
-
*/
|
|
150
|
-
declare function allValidFilesHaveChecksums(files: ProcessedFile[]): boolean;
|
|
127
|
+
declare const getValidFiles: (files: ProcessedFile[]) => ProcessedFile[];
|
|
151
128
|
/**
|
|
152
129
|
* Strip common directory prefix from file paths
|
|
153
130
|
* Only strips if ALL files share the same prefix
|
|
@@ -197,4 +174,4 @@ declare function isJunkFile(path: string): boolean;
|
|
|
197
174
|
*/
|
|
198
175
|
declare function isZipFile(file: File): boolean;
|
|
199
176
|
|
|
200
|
-
export { type ClientError,
|
|
177
|
+
export { type ClientError, type DropOptions, type DropReturn, FILE_STATUSES, type FileStatus, type ProcessedFile, type ZipExtractionResult, createProcessedFile, extractZipToFiles, formatFileSize, getValidFiles, isJunkFile, isZipFile, normalizePath, stripCommonPrefix, useDrop };
|