@uploadista/react 0.0.20-beta.2 → 0.0.20-beta.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/dist/components/index.d.mts +3 -3
- package/dist/components/index.mjs +1 -1
- package/dist/flow-upload-list-D6j8JSP8.mjs +2 -0
- package/dist/flow-upload-list-D6j8JSP8.mjs.map +1 -0
- package/dist/hooks/index.d.mts +3 -3
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +1 -1
- package/dist/{uploadista-provider-D-N-eL2l.d.mts → uploadista-provider-Cb13AK7Z.d.mts} +515 -318
- package/dist/uploadista-provider-Cb13AK7Z.d.mts.map +1 -0
- package/dist/use-upload-BvvGROMR.mjs +2 -0
- package/dist/use-upload-BvvGROMR.mjs.map +1 -0
- package/dist/{use-uploadista-client-m9nF-irM.d.mts → use-uploadista-client-CkzVVmFT.d.mts} +121 -286
- package/dist/use-uploadista-client-CkzVVmFT.d.mts.map +1 -0
- package/dist/use-uploadista-events-BwUD-2Ck.mjs +2 -0
- package/dist/use-uploadista-events-BwUD-2Ck.mjs.map +1 -0
- package/dist/{use-upload-metrics-DhzS4lhG.d.mts → use-uploadista-events-CtDXJYrR.d.mts} +169 -371
- package/dist/use-uploadista-events-CtDXJYrR.d.mts.map +1 -0
- package/package.json +6 -6
- package/src/components/flow-primitives.tsx +843 -0
- package/src/components/index.tsx +31 -13
- package/src/hooks/index.ts +25 -37
- package/src/hooks/use-drag-drop.ts +1 -0
- package/src/index.ts +90 -81
- package/dist/upload-zone-BjWHuP7p.mjs +0 -6
- package/dist/upload-zone-BjWHuP7p.mjs.map +0 -1
- package/dist/uploadista-provider-D-N-eL2l.d.mts.map +0 -1
- package/dist/use-upload-BDHVhQsI.mjs +0 -2
- package/dist/use-upload-BDHVhQsI.mjs.map +0 -1
- package/dist/use-upload-metrics-Df90wIos.mjs +0 -2
- package/dist/use-upload-metrics-Df90wIos.mjs.map +0 -1
- package/dist/use-upload-metrics-DhzS4lhG.d.mts.map +0 -1
- package/dist/use-uploadista-client-m9nF-irM.d.mts.map +0 -1
- package/src/components/flow-input.tsx +0 -299
- package/src/components/flow-upload-zone.tsx +0 -441
- package/src/hooks/use-flow-execution.ts +0 -502
- package/src/hooks/use-flow-upload.ts +0 -299
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FlowUploadConfig,
|
|
3
|
-
FlowUploadOptions,
|
|
4
|
-
} from "@uploadista/client-browser";
|
|
5
|
-
import type { ReactNode } from "react";
|
|
6
|
-
import { type UseDragDropReturn, useDragDrop } from "../hooks/use-drag-drop";
|
|
7
|
-
import {
|
|
8
|
-
type UseFlowUploadReturn,
|
|
9
|
-
useFlowUpload,
|
|
10
|
-
} from "../hooks/use-flow-upload";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Render props passed to the FlowUploadZone children function.
|
|
14
|
-
* Provides access to flow upload state, drag-drop handlers, and helper functions.
|
|
15
|
-
*
|
|
16
|
-
* @property dragDrop - Complete drag-and-drop state and handlers
|
|
17
|
-
* @property flowUpload - Flow upload hook with upload state and controls
|
|
18
|
-
* @property isActive - True when dragging over zone
|
|
19
|
-
* @property openFilePicker - Programmatically open file selection dialog
|
|
20
|
-
* @property getRootProps - Returns props to spread on the drop zone container
|
|
21
|
-
* @property getInputProps - Returns props to spread on the hidden file input
|
|
22
|
-
*/
|
|
23
|
-
export interface FlowUploadZoneRenderProps {
|
|
24
|
-
/**
|
|
25
|
-
* Drag and drop state and handlers
|
|
26
|
-
*/
|
|
27
|
-
dragDrop: UseDragDropReturn;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Flow upload functionality
|
|
31
|
-
*/
|
|
32
|
-
flowUpload: UseFlowUploadReturn;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Whether the zone is currently active (dragging or uploading)
|
|
36
|
-
*/
|
|
37
|
-
isActive: boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Open file picker
|
|
41
|
-
*/
|
|
42
|
-
openFilePicker: () => void;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Props to spread on the drop zone element
|
|
46
|
-
*/
|
|
47
|
-
getRootProps: () => {
|
|
48
|
-
onDragEnter: (e: React.DragEvent) => void;
|
|
49
|
-
onDragOver: (e: React.DragEvent) => void;
|
|
50
|
-
onDragLeave: (e: React.DragEvent) => void;
|
|
51
|
-
onDrop: (e: React.DragEvent) => void;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Props to spread on the file input element
|
|
56
|
-
*/
|
|
57
|
-
getInputProps: () => React.InputHTMLAttributes<HTMLInputElement>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Props for the FlowUploadZone component.
|
|
62
|
-
*
|
|
63
|
-
* @property flowConfig - Flow execution configuration (flowId, storageId, etc.)
|
|
64
|
-
* @property options - Flow upload options (callbacks, metadata, etc.)
|
|
65
|
-
* @property accept - Accepted file types (e.g., "image/*", ".pdf")
|
|
66
|
-
* @property multiple - Allow multiple file selection (default: false)
|
|
67
|
-
* @property children - Render function receiving flow upload zone state
|
|
68
|
-
*/
|
|
69
|
-
export interface FlowUploadZoneProps {
|
|
70
|
-
/**
|
|
71
|
-
* Flow configuration
|
|
72
|
-
*/
|
|
73
|
-
flowConfig: FlowUploadConfig;
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Upload options
|
|
77
|
-
*/
|
|
78
|
-
options?: Omit<FlowUploadOptions, "flowConfig">;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Accepted file types (e.g., "image/*", ".pdf", etc.)
|
|
82
|
-
*/
|
|
83
|
-
accept?: string;
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Whether to allow multiple files (uses multi-upload internally)
|
|
87
|
-
*/
|
|
88
|
-
multiple?: boolean;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Render function for the drop zone
|
|
92
|
-
*/
|
|
93
|
-
children: (props: FlowUploadZoneRenderProps) => ReactNode;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Headless flow upload zone component with drag-and-drop support.
|
|
98
|
-
* Combines drag-drop functionality with flow processing, using render props
|
|
99
|
-
* for complete UI control.
|
|
100
|
-
*
|
|
101
|
-
* Files uploaded through this zone are automatically processed through the
|
|
102
|
-
* specified flow, which can perform operations like image optimization,
|
|
103
|
-
* storage saving, webhooks, etc.
|
|
104
|
-
*
|
|
105
|
-
* Must be used within an UploadistaProvider.
|
|
106
|
-
*
|
|
107
|
-
* @param props - Flow upload zone configuration and render prop
|
|
108
|
-
* @returns Rendered flow upload zone using the provided render prop
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```tsx
|
|
112
|
-
* // Image upload with flow processing
|
|
113
|
-
* <FlowUploadZone
|
|
114
|
-
* flowConfig={{
|
|
115
|
-
* flowId: "image-processing-flow",
|
|
116
|
-
* storageId: "s3-images",
|
|
117
|
-
* outputNodeId: "optimized-image",
|
|
118
|
-
* }}
|
|
119
|
-
* options={{
|
|
120
|
-
* onSuccess: (result) => console.log('Processed:', result),
|
|
121
|
-
* onFlowComplete: (outputs) => {
|
|
122
|
-
* console.log('All outputs:', outputs);
|
|
123
|
-
* },
|
|
124
|
-
* }}
|
|
125
|
-
* accept="image/*"
|
|
126
|
-
* >
|
|
127
|
-
* {({ dragDrop, flowUpload, getRootProps, getInputProps, openFilePicker }) => (
|
|
128
|
-
* <div {...getRootProps()} style={{
|
|
129
|
-
* border: dragDrop.state.isDragging ? '2px solid blue' : '2px dashed gray',
|
|
130
|
-
* padding: '2rem',
|
|
131
|
-
* textAlign: 'center'
|
|
132
|
-
* }}>
|
|
133
|
-
* <input {...getInputProps()} />
|
|
134
|
-
*
|
|
135
|
-
* {dragDrop.state.isDragging && (
|
|
136
|
-
* <p>Drop image here...</p>
|
|
137
|
-
* )}
|
|
138
|
-
*
|
|
139
|
-
* {!dragDrop.state.isDragging && !flowUpload.isUploading && (
|
|
140
|
-
* <div>
|
|
141
|
-
* <p>Drag an image or click to browse</p>
|
|
142
|
-
* <button onClick={openFilePicker}>Choose File</button>
|
|
143
|
-
* </div>
|
|
144
|
-
* )}
|
|
145
|
-
*
|
|
146
|
-
* {flowUpload.isUploadingFile && (
|
|
147
|
-
* <div>
|
|
148
|
-
* <p>Uploading...</p>
|
|
149
|
-
* <progress value={flowUpload.state.progress} max={100} />
|
|
150
|
-
* <span>{flowUpload.state.progress}%</span>
|
|
151
|
-
* </div>
|
|
152
|
-
* )}
|
|
153
|
-
*
|
|
154
|
-
* {flowUpload.isProcessing && (
|
|
155
|
-
* <div>
|
|
156
|
-
* <p>Processing image...</p>
|
|
157
|
-
* {flowUpload.state.currentNodeName && (
|
|
158
|
-
* <span>Step: {flowUpload.state.currentNodeName}</span>
|
|
159
|
-
* )}
|
|
160
|
-
* </div>
|
|
161
|
-
* )}
|
|
162
|
-
*
|
|
163
|
-
* {flowUpload.state.status === "success" && (
|
|
164
|
-
* <div>
|
|
165
|
-
* <p>✓ Upload complete!</p>
|
|
166
|
-
* {flowUpload.state.result && (
|
|
167
|
-
* <img src={flowUpload.state.result.url} alt="Uploaded" />
|
|
168
|
-
* )}
|
|
169
|
-
* </div>
|
|
170
|
-
* )}
|
|
171
|
-
*
|
|
172
|
-
* {flowUpload.state.status === "error" && (
|
|
173
|
-
* <div>
|
|
174
|
-
* <p>Error: {flowUpload.state.error?.message}</p>
|
|
175
|
-
* <button onClick={flowUpload.reset}>Try Again</button>
|
|
176
|
-
* </div>
|
|
177
|
-
* )}
|
|
178
|
-
*
|
|
179
|
-
* {flowUpload.isUploading && (
|
|
180
|
-
* <button onClick={flowUpload.abort}>Cancel</button>
|
|
181
|
-
* )}
|
|
182
|
-
* </div>
|
|
183
|
-
* )}
|
|
184
|
-
* </FlowUploadZone>
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* @see {@link SimpleFlowUploadZone} for a pre-styled version
|
|
188
|
-
* @see {@link useFlowUpload} for the underlying hook
|
|
189
|
-
*/
|
|
190
|
-
export function FlowUploadZone({
|
|
191
|
-
flowConfig,
|
|
192
|
-
options,
|
|
193
|
-
accept,
|
|
194
|
-
multiple = false,
|
|
195
|
-
children,
|
|
196
|
-
}: FlowUploadZoneProps) {
|
|
197
|
-
// Hook automatically subscribes to events through context
|
|
198
|
-
const flowUpload = useFlowUpload({
|
|
199
|
-
...options,
|
|
200
|
-
flowConfig,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const dragDrop = useDragDrop({
|
|
204
|
-
onFilesReceived: (files: File[]) => {
|
|
205
|
-
const file = files[0];
|
|
206
|
-
if (file) {
|
|
207
|
-
flowUpload.upload(file);
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
accept: accept ? [accept] : undefined,
|
|
211
|
-
multiple,
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
215
|
-
const files = e.target.files;
|
|
216
|
-
const file = files?.[0];
|
|
217
|
-
if (file) {
|
|
218
|
-
flowUpload.upload(file);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// Determine active state
|
|
223
|
-
const isActive = dragDrop.state.isDragging || dragDrop.state.isOver;
|
|
224
|
-
|
|
225
|
-
return (
|
|
226
|
-
<>
|
|
227
|
-
{children({
|
|
228
|
-
flowUpload,
|
|
229
|
-
dragDrop,
|
|
230
|
-
isActive,
|
|
231
|
-
openFilePicker: dragDrop.openFilePicker,
|
|
232
|
-
getRootProps: () => dragDrop.dragHandlers,
|
|
233
|
-
getInputProps: () => ({
|
|
234
|
-
...dragDrop.inputProps,
|
|
235
|
-
onChange: handleFileChange,
|
|
236
|
-
}),
|
|
237
|
-
})}
|
|
238
|
-
</>
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Props for the SimpleFlowUploadZone component.
|
|
244
|
-
*
|
|
245
|
-
* @property flowConfig - Flow execution configuration
|
|
246
|
-
* @property options - Flow upload options (callbacks, metadata)
|
|
247
|
-
* @property accept - Accepted file types
|
|
248
|
-
* @property className - CSS class name for custom styling
|
|
249
|
-
* @property dragText - Text displayed when dragging files over zone
|
|
250
|
-
* @property idleText - Text displayed when zone is idle
|
|
251
|
-
*/
|
|
252
|
-
export interface SimpleFlowUploadZoneProps {
|
|
253
|
-
/**
|
|
254
|
-
* Flow configuration
|
|
255
|
-
*/
|
|
256
|
-
flowConfig: FlowUploadConfig;
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Upload options
|
|
260
|
-
*/
|
|
261
|
-
options?: Omit<FlowUploadOptions, "flowConfig">;
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Accepted file types
|
|
265
|
-
*/
|
|
266
|
-
accept?: string;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* CSS class for the container
|
|
270
|
-
*/
|
|
271
|
-
className?: string;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Custom drag overlay text
|
|
275
|
-
*/
|
|
276
|
-
dragText?: string;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Custom idle text
|
|
280
|
-
*/
|
|
281
|
-
idleText?: string;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Simple pre-styled flow upload zone component with built-in UI.
|
|
286
|
-
* Provides a ready-to-use drag-and-drop interface for flow uploads.
|
|
287
|
-
*
|
|
288
|
-
* Features:
|
|
289
|
-
* - Built-in drag-and-drop visual feedback
|
|
290
|
-
* - Automatic progress display for upload and processing phases
|
|
291
|
-
* - Success and error state display
|
|
292
|
-
* - Cancel button during upload
|
|
293
|
-
* - Customizable text labels
|
|
294
|
-
*
|
|
295
|
-
* @param props - Flow upload zone configuration with styling options
|
|
296
|
-
* @returns Styled flow upload zone component
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```tsx
|
|
300
|
-
* // Basic image upload with flow processing
|
|
301
|
-
* <SimpleFlowUploadZone
|
|
302
|
-
* flowConfig={{
|
|
303
|
-
* flowId: "image-optimization-flow",
|
|
304
|
-
* storageId: "s3-images",
|
|
305
|
-
* }}
|
|
306
|
-
* accept="image/*"
|
|
307
|
-
* options={{
|
|
308
|
-
* onSuccess: (result) => console.log("Image processed:", result),
|
|
309
|
-
* onError: (error) => console.error("Processing failed:", error),
|
|
310
|
-
* }}
|
|
311
|
-
* idleText="Drop an image to optimize and upload"
|
|
312
|
-
* dragText="Release to start processing"
|
|
313
|
-
* className="my-upload-zone"
|
|
314
|
-
* />
|
|
315
|
-
*
|
|
316
|
-
* // Document upload with custom flow
|
|
317
|
-
* <SimpleFlowUploadZone
|
|
318
|
-
* flowConfig={{
|
|
319
|
-
* flowId: "document-processing-flow",
|
|
320
|
-
* storageId: "docs",
|
|
321
|
-
* outputNodeId: "processed-doc",
|
|
322
|
-
* }}
|
|
323
|
-
* accept=".pdf,.doc,.docx"
|
|
324
|
-
* options={{
|
|
325
|
-
* onFlowComplete: (outputs) => {
|
|
326
|
-
* console.log('Processing outputs:', outputs);
|
|
327
|
-
* },
|
|
328
|
-
* }}
|
|
329
|
-
* />
|
|
330
|
-
* ```
|
|
331
|
-
*
|
|
332
|
-
* @see {@link FlowUploadZone} for the headless version with full control
|
|
333
|
-
*/
|
|
334
|
-
export function SimpleFlowUploadZone({
|
|
335
|
-
flowConfig,
|
|
336
|
-
options,
|
|
337
|
-
accept,
|
|
338
|
-
className = "",
|
|
339
|
-
dragText = "Drop files here",
|
|
340
|
-
idleText = "Drag & drop files or click to browse",
|
|
341
|
-
}: SimpleFlowUploadZoneProps) {
|
|
342
|
-
return (
|
|
343
|
-
<FlowUploadZone flowConfig={flowConfig} options={options} accept={accept}>
|
|
344
|
-
{({
|
|
345
|
-
dragDrop,
|
|
346
|
-
flowUpload,
|
|
347
|
-
getRootProps,
|
|
348
|
-
getInputProps,
|
|
349
|
-
openFilePicker,
|
|
350
|
-
}) => (
|
|
351
|
-
<div
|
|
352
|
-
{...getRootProps()}
|
|
353
|
-
className={className}
|
|
354
|
-
style={{
|
|
355
|
-
border: "2px dashed #ccc",
|
|
356
|
-
borderRadius: "8px",
|
|
357
|
-
padding: "32px",
|
|
358
|
-
textAlign: "center",
|
|
359
|
-
cursor: "pointer",
|
|
360
|
-
backgroundColor: dragDrop.state.isDragging
|
|
361
|
-
? "#f0f0f0"
|
|
362
|
-
: "transparent",
|
|
363
|
-
transition: "background-color 0.2s",
|
|
364
|
-
}}
|
|
365
|
-
>
|
|
366
|
-
<input {...getInputProps()} />
|
|
367
|
-
|
|
368
|
-
{dragDrop.state.isDragging && <p style={{ margin: 0 }}>{dragText}</p>}
|
|
369
|
-
|
|
370
|
-
{!dragDrop.state.isDragging &&
|
|
371
|
-
!flowUpload.isUploading &&
|
|
372
|
-
flowUpload.state.status === "idle" && (
|
|
373
|
-
<div>
|
|
374
|
-
<p style={{ margin: "0 0 16px 0" }}>{idleText}</p>
|
|
375
|
-
<button
|
|
376
|
-
type="button"
|
|
377
|
-
onClick={(e) => {
|
|
378
|
-
e.stopPropagation();
|
|
379
|
-
openFilePicker();
|
|
380
|
-
}}
|
|
381
|
-
style={{
|
|
382
|
-
padding: "8px 16px",
|
|
383
|
-
borderRadius: "4px",
|
|
384
|
-
border: "1px solid #ccc",
|
|
385
|
-
backgroundColor: "#fff",
|
|
386
|
-
cursor: "pointer",
|
|
387
|
-
}}
|
|
388
|
-
>
|
|
389
|
-
Choose Files
|
|
390
|
-
</button>
|
|
391
|
-
</div>
|
|
392
|
-
)}
|
|
393
|
-
|
|
394
|
-
{flowUpload.isUploading && (
|
|
395
|
-
<div>
|
|
396
|
-
<progress
|
|
397
|
-
value={flowUpload.state.progress}
|
|
398
|
-
max={100}
|
|
399
|
-
style={{ width: "100%", height: "8px" }}
|
|
400
|
-
/>
|
|
401
|
-
<p style={{ margin: "8px 0 0 0" }}>
|
|
402
|
-
{flowUpload.state.progress}%
|
|
403
|
-
</p>
|
|
404
|
-
<button
|
|
405
|
-
type="button"
|
|
406
|
-
onClick={(e) => {
|
|
407
|
-
e.stopPropagation();
|
|
408
|
-
// abort() will be passed from parent
|
|
409
|
-
}}
|
|
410
|
-
style={{
|
|
411
|
-
marginTop: "8px",
|
|
412
|
-
padding: "4px 12px",
|
|
413
|
-
borderRadius: "4px",
|
|
414
|
-
border: "1px solid #ccc",
|
|
415
|
-
backgroundColor: "#fff",
|
|
416
|
-
cursor: "pointer",
|
|
417
|
-
}}
|
|
418
|
-
>
|
|
419
|
-
Cancel
|
|
420
|
-
</button>
|
|
421
|
-
</div>
|
|
422
|
-
)}
|
|
423
|
-
|
|
424
|
-
{flowUpload.state.status === "success" && (
|
|
425
|
-
<div>
|
|
426
|
-
<p style={{ margin: 0, color: "green" }}>✓ Upload complete!</p>
|
|
427
|
-
</div>
|
|
428
|
-
)}
|
|
429
|
-
|
|
430
|
-
{flowUpload.state.status === "error" && (
|
|
431
|
-
<div>
|
|
432
|
-
<p style={{ margin: 0, color: "red" }}>
|
|
433
|
-
✗ Error: {flowUpload.state.error?.message}
|
|
434
|
-
</p>
|
|
435
|
-
</div>
|
|
436
|
-
)}
|
|
437
|
-
</div>
|
|
438
|
-
)}
|
|
439
|
-
</FlowUploadZone>
|
|
440
|
-
);
|
|
441
|
-
}
|