@shipstatic/drop 0.1.0 → 0.1.1
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 +29 -29
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @shipstatic/
|
|
1
|
+
# @shipstatic/drop
|
|
2
2
|
|
|
3
3
|
**Headless file processing toolkit for Ship SDK deployments**
|
|
4
4
|
|
|
@@ -29,15 +29,15 @@ The package focuses on what's hard (ZIP extraction, MD5 calculation, validation)
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
npm install @shipstatic/
|
|
32
|
+
npm install @shipstatic/drop
|
|
33
33
|
# or
|
|
34
|
-
pnpm add @shipstatic/
|
|
34
|
+
pnpm add @shipstatic/drop
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
## Quick Start
|
|
38
38
|
|
|
39
39
|
```tsx
|
|
40
|
-
import {
|
|
40
|
+
import { useDrop } from '@shipstatic/drop';
|
|
41
41
|
import Ship from '@shipstatic/ship';
|
|
42
42
|
|
|
43
43
|
function MyUploader() {
|
|
@@ -46,12 +46,12 @@ function MyUploader() {
|
|
|
46
46
|
// Get validation config from Ship SDK
|
|
47
47
|
const config = await ship.getConfig();
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const drop = useDrop({
|
|
50
50
|
config // Pass SDK config directly
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
const handleUpload = async () => {
|
|
54
|
-
const validFiles =
|
|
54
|
+
const validFiles = drop.getValidFiles();
|
|
55
55
|
|
|
56
56
|
// ProcessedFile extends StaticFile - no conversion needed!
|
|
57
57
|
await ship.deployments.create({ files: validFiles });
|
|
@@ -64,13 +64,13 @@ function MyUploader() {
|
|
|
64
64
|
multiple
|
|
65
65
|
onChange={(e) => {
|
|
66
66
|
const files = Array.from(e.target.files || []);
|
|
67
|
-
|
|
67
|
+
drop.processFiles(files);
|
|
68
68
|
}}
|
|
69
69
|
/>
|
|
70
70
|
|
|
71
|
-
<p>{
|
|
71
|
+
<p>{drop.statusText}</p>
|
|
72
72
|
|
|
73
|
-
{
|
|
73
|
+
{drop.files.map(file => (
|
|
74
74
|
<div key={file.id}>
|
|
75
75
|
{file.name} - {file.status}
|
|
76
76
|
</div>
|
|
@@ -78,25 +78,25 @@ function MyUploader() {
|
|
|
78
78
|
|
|
79
79
|
<button
|
|
80
80
|
onClick={handleUpload}
|
|
81
|
-
disabled={
|
|
81
|
+
disabled={drop.getValidFiles().length === 0}
|
|
82
82
|
>
|
|
83
|
-
Upload {
|
|
83
|
+
Upload {drop.getValidFiles().length} files
|
|
84
84
|
</button>
|
|
85
85
|
</div>
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
## Building Your
|
|
90
|
+
## Building Your Drop Zone with Folder Support
|
|
91
91
|
|
|
92
92
|
For production use, you'll want to support folder drag-and-drop using modern browser APIs. Here's a complete example:
|
|
93
93
|
|
|
94
94
|
```tsx
|
|
95
95
|
import { useState } from 'react';
|
|
96
|
-
import {
|
|
96
|
+
import { useDrop } from '@shipstatic/drop';
|
|
97
97
|
|
|
98
98
|
function MyDeployUI() {
|
|
99
|
-
const
|
|
99
|
+
const drop = useDrop();
|
|
100
100
|
const [isDragActive, setIsDragActive] = useState(false);
|
|
101
101
|
|
|
102
102
|
const handleDrop = async (e: React.DragEvent) => {
|
|
@@ -105,7 +105,7 @@ function MyDeployUI() {
|
|
|
105
105
|
|
|
106
106
|
// Extract files with folder structure preserved
|
|
107
107
|
const files = await extractFilesWithStructure(e.dataTransfer);
|
|
108
|
-
|
|
108
|
+
drop.processFiles(files);
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
const extractFilesWithStructure = async (
|
|
@@ -212,14 +212,14 @@ function MyDeployUI() {
|
|
|
212
212
|
onDrop={handleDrop}
|
|
213
213
|
className={isDragActive ? 'border-blue-500 bg-blue-50' : 'border-gray-300'}
|
|
214
214
|
>
|
|
215
|
-
{
|
|
216
|
-
<p>Processing {
|
|
215
|
+
{drop.isProcessing ? (
|
|
216
|
+
<p>Processing {drop.files.length} files...</p>
|
|
217
217
|
) : (
|
|
218
218
|
<p>Drag & drop files or folders here</p>
|
|
219
219
|
)}
|
|
220
220
|
|
|
221
|
-
{
|
|
222
|
-
<div className="text-red-600">{
|
|
221
|
+
{drop.validationError && (
|
|
222
|
+
<div className="text-red-600">{drop.validationError.details}</div>
|
|
223
223
|
)}
|
|
224
224
|
</div>
|
|
225
225
|
);
|
|
@@ -235,14 +235,14 @@ function MyDeployUI() {
|
|
|
235
235
|
|
|
236
236
|
## API
|
|
237
237
|
|
|
238
|
-
### `
|
|
238
|
+
### `useDrop(options?)`
|
|
239
239
|
|
|
240
|
-
Main hook for managing
|
|
240
|
+
Main hook for managing drop state.
|
|
241
241
|
|
|
242
242
|
**Options:**
|
|
243
243
|
|
|
244
244
|
```typescript
|
|
245
|
-
interface
|
|
245
|
+
interface DropOptions {
|
|
246
246
|
/** Validation configuration (from ship.getConfig()) */
|
|
247
247
|
config?: Partial<ValidationConfig>;
|
|
248
248
|
/** Callback when validation fails */
|
|
@@ -257,7 +257,7 @@ interface DropzoneManagerOptions {
|
|
|
257
257
|
**Returns:**
|
|
258
258
|
|
|
259
259
|
```typescript
|
|
260
|
-
interface
|
|
260
|
+
interface DropReturn {
|
|
261
261
|
/** All processed files with their status */
|
|
262
262
|
files: ProcessedFile[];
|
|
263
263
|
/** Current status text */
|
|
@@ -269,7 +269,7 @@ interface DropzoneManagerReturn {
|
|
|
269
269
|
/** Whether all valid files have MD5 checksums calculated */
|
|
270
270
|
hasChecksums: boolean;
|
|
271
271
|
|
|
272
|
-
/** Process files from
|
|
272
|
+
/** Process files from drop (resets and replaces existing files) */
|
|
273
273
|
processFiles: (files: File[]) => Promise<void>;
|
|
274
274
|
/** Remove a specific file */
|
|
275
275
|
removeFile: (fileId: string) => void;
|
|
@@ -343,7 +343,7 @@ type FileStatus =
|
|
|
343
343
|
**ProcessedFile extends StaticFile** - no conversion needed! Since `ProcessedFile` extends `StaticFile` from `@shipstatic/types`, you can pass the files directly to the Ship SDK:
|
|
344
344
|
|
|
345
345
|
```typescript
|
|
346
|
-
const validFiles =
|
|
346
|
+
const validFiles = drop.getValidFiles();
|
|
347
347
|
|
|
348
348
|
// ProcessedFile[] IS StaticFile[] - pass directly!
|
|
349
349
|
await ship.deployments.create({ files: validFiles });
|
|
@@ -369,7 +369,7 @@ interface ProcessedFile extends StaticFile {
|
|
|
369
369
|
}
|
|
370
370
|
```
|
|
371
371
|
|
|
372
|
-
**Important**: The
|
|
372
|
+
**Important**: The drop hook preserves folder structure via `webkitRelativePath` and processes paths with `stripCommonPrefix` automatically. The `path` property is always deployment-ready.
|
|
373
373
|
|
|
374
374
|
## Architecture Decisions
|
|
375
375
|
|
|
@@ -391,7 +391,7 @@ Following industry standards (Firebase hooks, Supabase utilities), we chose:
|
|
|
391
391
|
- ✅ **Flexible**: Host app controls WHEN to deploy
|
|
392
392
|
|
|
393
393
|
Instead of:
|
|
394
|
-
- ❌ Passing Ship SDK instance to
|
|
394
|
+
- ❌ Passing Ship SDK instance to useDrop
|
|
395
395
|
- ❌ React Context provider pattern
|
|
396
396
|
- ❌ Global configuration singleton
|
|
397
397
|
|
|
@@ -407,8 +407,8 @@ No conversion needed. ProcessedFile adds UI-specific properties (id, name, statu
|
|
|
407
407
|
|
|
408
408
|
**4. No UI Components**
|
|
409
409
|
|
|
410
|
-
We deliberately don't provide
|
|
411
|
-
- Generic
|
|
410
|
+
We deliberately don't provide drop zone UI components because:
|
|
411
|
+
- Generic drop zone libraries (like `react-dropzone`) don't support folder structure preservation
|
|
412
412
|
- Proper folder drag-and-drop requires modern browser APIs that need custom implementation
|
|
413
413
|
- Your deployment UI is unique to your application
|
|
414
414
|
- Providing a component that "works but loses paths" would be misleading
|
package/dist/index.cjs
CHANGED
|
@@ -12394,8 +12394,8 @@ function stripCommonPrefix(files) {
|
|
|
12394
12394
|
}));
|
|
12395
12395
|
}
|
|
12396
12396
|
|
|
12397
|
-
// src/hooks/
|
|
12398
|
-
function
|
|
12397
|
+
// src/hooks/useDrop.ts
|
|
12398
|
+
function useDrop(options = {}) {
|
|
12399
12399
|
const {
|
|
12400
12400
|
config: customConfig,
|
|
12401
12401
|
onValidationError,
|
|
@@ -12542,7 +12542,7 @@ exports.isJunkFile = isJunkFile;
|
|
|
12542
12542
|
exports.isZipFile = isZipFile;
|
|
12543
12543
|
exports.normalizePath = normalizePath;
|
|
12544
12544
|
exports.stripCommonPrefix = stripCommonPrefix;
|
|
12545
|
-
exports.
|
|
12545
|
+
exports.useDrop = useDrop;
|
|
12546
12546
|
exports.validateFiles = validateFiles;
|
|
12547
12547
|
//# sourceMappingURL=index.cjs.map
|
|
12548
12548
|
//# sourceMappingURL=index.cjs.map
|