@uploadista/react 0.0.20 → 0.1.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/dist/components/index.d.mts +3 -3
- package/dist/components/index.mjs +1 -1
- package/dist/index.d.mts +4 -548
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/upload-zone-CH8B2-hl.mjs +2 -0
- package/dist/upload-zone-CH8B2-hl.mjs.map +1 -0
- package/dist/{uploadista-provider-Cb13AK7Z.d.mts → uploadista-provider-DwKXudoT.d.mts} +558 -15
- package/dist/uploadista-provider-DwKXudoT.d.mts.map +1 -0
- package/dist/use-upload-BgaJmdwF.mjs.map +1 -1
- package/dist/use-uploadista-events-CtDXJYrR.d.mts.map +1 -1
- package/dist/use-uploadista-events-KhJ4knam.mjs.map +1 -1
- package/package.json +12 -9
- package/src/__tests__/event-utils.test.ts +179 -0
- package/src/__tests__/setup.ts +40 -0
- package/src/__tests__/uploadista-provider.test.tsx +316 -0
- package/src/__tests__/use-drag-drop.test.tsx +476 -0
- package/src/__tests__/use-upload.test.tsx +317 -0
- package/src/__tests__/use-uploadista-client.test.tsx +208 -0
- package/src/components/flow-primitives.tsx +3 -8
- package/src/components/index.tsx +37 -6
- package/src/components/upload-primitives.tsx +22 -19
- package/src/components/upload-zone.tsx +1 -2
- package/src/hooks/event-utils.ts +1 -1
- package/src/hooks/use-upload-events.ts +2 -5
- package/src/index.ts +89 -96
- package/vitest.config.ts +16 -0
- package/dist/flow-upload-list-BJSCZ4Ty.mjs +0 -2
- package/dist/flow-upload-list-BJSCZ4Ty.mjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/uploadista-provider-Cb13AK7Z.d.mts.map +0 -1
|
@@ -2,12 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { BrowserUploadInput } from "@uploadista/client-browser";
|
|
4
4
|
import type { UploadFile } from "@uploadista/core/types";
|
|
5
|
-
import {
|
|
6
|
-
type ReactNode,
|
|
7
|
-
createContext,
|
|
8
|
-
useCallback,
|
|
9
|
-
useContext,
|
|
10
|
-
} from "react";
|
|
5
|
+
import { createContext, type ReactNode, useCallback, useContext } from "react";
|
|
11
6
|
import {
|
|
12
7
|
type DragDropState,
|
|
13
8
|
type UseDragDropReturn,
|
|
@@ -15,13 +10,21 @@ import {
|
|
|
15
10
|
} from "../hooks/use-drag-drop";
|
|
16
11
|
import {
|
|
17
12
|
type MultiUploadState,
|
|
18
|
-
type UploadItem,
|
|
13
|
+
type UploadItem as UploadItemData,
|
|
19
14
|
useMultiUpload,
|
|
20
15
|
} from "../hooks/use-multi-upload";
|
|
21
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
UploadState,
|
|
18
|
+
UploadStatus as UploadStatusType,
|
|
19
|
+
} from "../hooks/use-upload";
|
|
22
20
|
|
|
23
21
|
// Re-export types for convenience
|
|
24
|
-
export type {
|
|
22
|
+
export type {
|
|
23
|
+
UploadState,
|
|
24
|
+
UploadStatusType as UploadStatus,
|
|
25
|
+
UploadItemData as UploadItem,
|
|
26
|
+
MultiUploadState,
|
|
27
|
+
};
|
|
25
28
|
|
|
26
29
|
// ============ UPLOAD CONTEXT ============
|
|
27
30
|
|
|
@@ -35,7 +38,7 @@ export interface UploadContextValue {
|
|
|
35
38
|
/** Current multi-upload state (aggregate) */
|
|
36
39
|
state: MultiUploadState;
|
|
37
40
|
/** All upload items */
|
|
38
|
-
items:
|
|
41
|
+
items: UploadItemData[];
|
|
39
42
|
/** Whether auto-start is enabled */
|
|
40
43
|
autoStart: boolean;
|
|
41
44
|
|
|
@@ -73,7 +76,7 @@ export function useUploadContext(): UploadContextValue {
|
|
|
73
76
|
if (!context) {
|
|
74
77
|
throw new Error(
|
|
75
78
|
"useUploadContext must be used within an <Upload> component. " +
|
|
76
|
-
|
|
79
|
+
"Wrap your component tree with <Upload onSuccess={...}>",
|
|
77
80
|
);
|
|
78
81
|
}
|
|
79
82
|
return context;
|
|
@@ -133,18 +136,18 @@ export interface UploadProps {
|
|
|
133
136
|
/** Called when a single file upload succeeds (single mode) */
|
|
134
137
|
onSuccess?: (result: UploadFile) => void;
|
|
135
138
|
/** Called when an upload fails */
|
|
136
|
-
onError?: (error: Error, item?:
|
|
139
|
+
onError?: (error: Error, item?: UploadItemData) => void;
|
|
137
140
|
/** Called when all uploads complete (multi mode) */
|
|
138
141
|
onComplete?: (results: {
|
|
139
|
-
successful:
|
|
140
|
-
failed:
|
|
142
|
+
successful: UploadItemData[];
|
|
143
|
+
failed: UploadItemData[];
|
|
141
144
|
total: number;
|
|
142
145
|
}) => void;
|
|
143
146
|
/** Called when an individual upload starts */
|
|
144
|
-
onUploadStart?: (item:
|
|
147
|
+
onUploadStart?: (item: UploadItemData) => void;
|
|
145
148
|
/** Called on upload progress */
|
|
146
149
|
onProgress?: (
|
|
147
|
-
item:
|
|
150
|
+
item: UploadItemData,
|
|
148
151
|
progress: number,
|
|
149
152
|
bytesUploaded: number,
|
|
150
153
|
totalBytes: number | null,
|
|
@@ -211,7 +214,7 @@ function UploadRoot({
|
|
|
211
214
|
metadata,
|
|
212
215
|
onUploadStart,
|
|
213
216
|
onUploadProgress: onProgress,
|
|
214
|
-
onUploadSuccess: (
|
|
217
|
+
onUploadSuccess: (_item, result) => {
|
|
215
218
|
// In single mode, call onSuccess directly
|
|
216
219
|
if (!multiple) {
|
|
217
220
|
onSuccess?.(result);
|
|
@@ -350,7 +353,7 @@ function UploadDropZone({
|
|
|
350
353
|
*/
|
|
351
354
|
export interface UploadItemsRenderProps {
|
|
352
355
|
/** All upload items */
|
|
353
|
-
items:
|
|
356
|
+
items: UploadItemData[];
|
|
354
357
|
/** Whether there are any items */
|
|
355
358
|
hasItems: boolean;
|
|
356
359
|
/** Whether items array is empty */
|
|
@@ -590,7 +593,7 @@ export interface UploadErrorRenderProps {
|
|
|
590
593
|
/** Number of failed uploads */
|
|
591
594
|
failedCount: number;
|
|
592
595
|
/** Failed items */
|
|
593
|
-
failedItems:
|
|
596
|
+
failedItems: UploadItemData[];
|
|
594
597
|
/** Reset/clear all errors */
|
|
595
598
|
reset: () => void;
|
|
596
599
|
}
|
|
@@ -522,8 +522,7 @@ export function SimpleUploadZone({
|
|
|
522
522
|
</p>
|
|
523
523
|
{dragDrop.state.errors.map((error, index) => (
|
|
524
524
|
<p
|
|
525
|
-
|
|
526
|
-
key={index}
|
|
525
|
+
key={`${error}-${index}`}
|
|
527
526
|
style={{
|
|
528
527
|
color: "#721c24",
|
|
529
528
|
fontSize: "11px",
|
package/src/hooks/event-utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { UploadistaEvent } from "@uploadista/client-browser";
|
|
2
2
|
import { EventType, type FlowEvent } from "@uploadista/core/flow";
|
|
3
|
-
import {
|
|
3
|
+
import { type UploadEvent, UploadEventType } from "@uploadista/core/types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Type guard to check if an event is a flow event
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UploadEventType
|
|
1
|
+
import { UploadEventType } from "@uploadista/core/types";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import { useUploadistaContext } from "../components/uploadista-provider";
|
|
4
4
|
import { isUploadEvent } from "./event-utils";
|
|
@@ -163,10 +163,7 @@ export function useUploadEvents(options: UseUploadEventsOptions): void {
|
|
|
163
163
|
break;
|
|
164
164
|
case UploadEventType.UPLOAD_PROGRESS:
|
|
165
165
|
options.onUploadProgress?.({
|
|
166
|
-
...(event.data as unknown as Omit<
|
|
167
|
-
UploadProgressEventData,
|
|
168
|
-
"flow"
|
|
169
|
-
>),
|
|
166
|
+
...(event.data as unknown as Omit<UploadProgressEventData, "flow">),
|
|
170
167
|
flow: flowContext,
|
|
171
168
|
});
|
|
172
169
|
break;
|
package/src/index.ts
CHANGED
|
@@ -1,50 +1,120 @@
|
|
|
1
1
|
// ============ FLOW PRIMITIVES (NEW) ============
|
|
2
2
|
// Compound component for flow-based uploads
|
|
3
|
-
|
|
4
|
-
Flow,
|
|
5
|
-
useFlowContext,
|
|
6
|
-
useFlowInputContext,
|
|
7
|
-
} from "./components/flow-primitives";
|
|
3
|
+
|
|
8
4
|
export type {
|
|
9
|
-
|
|
5
|
+
FlowCancelProps,
|
|
10
6
|
FlowContextValue,
|
|
11
|
-
FlowInputContextValue,
|
|
12
7
|
FlowDropZoneProps,
|
|
13
8
|
FlowDropZoneRenderProps,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
FlowErrorProps,
|
|
10
|
+
FlowErrorRenderProps,
|
|
11
|
+
FlowInputContextValue,
|
|
17
12
|
FlowInputDropZoneProps,
|
|
18
13
|
FlowInputDropZoneRenderProps,
|
|
19
|
-
FlowInputUrlFieldProps,
|
|
20
14
|
FlowInputPreviewProps,
|
|
21
15
|
FlowInputPreviewRenderProps,
|
|
16
|
+
FlowInputProps,
|
|
17
|
+
FlowInputsProps,
|
|
18
|
+
FlowInputsRenderProps,
|
|
19
|
+
FlowInputUrlFieldProps,
|
|
22
20
|
FlowProgressProps,
|
|
23
21
|
FlowProgressRenderProps,
|
|
22
|
+
FlowProps,
|
|
23
|
+
FlowResetProps,
|
|
24
24
|
FlowStatusProps,
|
|
25
25
|
FlowStatusRenderProps,
|
|
26
|
-
FlowErrorProps,
|
|
27
|
-
FlowErrorRenderProps,
|
|
28
26
|
FlowSubmitProps,
|
|
29
|
-
FlowCancelProps,
|
|
30
|
-
FlowResetProps,
|
|
31
27
|
} from "./components/flow-primitives";
|
|
32
|
-
|
|
28
|
+
export {
|
|
29
|
+
Flow,
|
|
30
|
+
useFlowContext,
|
|
31
|
+
useFlowInputContext,
|
|
32
|
+
} from "./components/flow-primitives";
|
|
33
|
+
// ============ FLOW UPLOAD LIST (for batch uploads) ============
|
|
34
|
+
export type {
|
|
35
|
+
FlowUploadListProps,
|
|
36
|
+
FlowUploadListRenderProps,
|
|
37
|
+
SimpleFlowUploadListItemProps,
|
|
38
|
+
SimpleFlowUploadListProps,
|
|
39
|
+
} from "./components/flow-upload-list";
|
|
40
|
+
export {
|
|
41
|
+
FlowUploadList,
|
|
42
|
+
SimpleFlowUploadList,
|
|
43
|
+
SimpleFlowUploadListItem,
|
|
44
|
+
} from "./components/flow-upload-list";
|
|
45
|
+
// ============ UPLOAD COMPONENTS (LEGACY) ============
|
|
46
|
+
export type {
|
|
47
|
+
SimpleUploadListItemProps,
|
|
48
|
+
UploadListProps,
|
|
49
|
+
UploadListRenderProps,
|
|
50
|
+
} from "./components/upload-list";
|
|
51
|
+
export { SimpleUploadListItem, UploadList } from "./components/upload-list";
|
|
52
|
+
export type {
|
|
53
|
+
UploadCancelProps,
|
|
54
|
+
UploadClearCompletedProps,
|
|
55
|
+
UploadContextValue,
|
|
56
|
+
UploadDropZoneProps,
|
|
57
|
+
UploadDropZoneRenderProps,
|
|
58
|
+
UploadErrorProps,
|
|
59
|
+
UploadErrorRenderProps,
|
|
60
|
+
UploadItemContextValue,
|
|
61
|
+
UploadItemProps,
|
|
62
|
+
UploadItemsProps,
|
|
63
|
+
UploadItemsRenderProps,
|
|
64
|
+
UploadProgressProps,
|
|
65
|
+
UploadProgressRenderProps,
|
|
66
|
+
UploadProps,
|
|
67
|
+
UploadResetProps,
|
|
68
|
+
UploadRetryProps,
|
|
69
|
+
UploadStartAllProps,
|
|
70
|
+
UploadStatusProps,
|
|
71
|
+
UploadStatusRenderProps,
|
|
72
|
+
} from "./components/upload-primitives";
|
|
73
|
+
// ============ UPLOAD PRIMITIVES (NEW) ============
|
|
74
|
+
// Compound component for file uploads
|
|
75
|
+
export {
|
|
76
|
+
Upload,
|
|
77
|
+
useUploadContext,
|
|
78
|
+
useUploadItemContext,
|
|
79
|
+
} from "./components/upload-primitives";
|
|
80
|
+
export type {
|
|
81
|
+
SimpleUploadZoneProps,
|
|
82
|
+
UploadZoneProps,
|
|
83
|
+
UploadZoneRenderProps,
|
|
84
|
+
} from "./components/upload-zone";
|
|
85
|
+
export { SimpleUploadZone, UploadZone } from "./components/upload-zone";
|
|
86
|
+
// ============ PROVIDERS & CONTEXTS ============
|
|
87
|
+
export {
|
|
88
|
+
UploadistaProvider,
|
|
89
|
+
useUploadistaContext,
|
|
90
|
+
} from "./components/uploadista-provider";
|
|
91
|
+
export {
|
|
92
|
+
FlowManagerProvider,
|
|
93
|
+
useFlowManagerContext,
|
|
94
|
+
} from "./contexts/flow-manager-context";
|
|
95
|
+
// ============ EVENT UTILITIES ============
|
|
96
|
+
export { isFlowEvent, isUploadEvent } from "./hooks/event-utils";
|
|
97
|
+
// ============ DRAG & DROP ============
|
|
98
|
+
export type {
|
|
99
|
+
DragDropOptions,
|
|
100
|
+
DragDropState,
|
|
101
|
+
UseDragDropReturn,
|
|
102
|
+
} from "./hooks/use-drag-drop";
|
|
103
|
+
export { useDragDrop } from "./hooks/use-drag-drop";
|
|
33
104
|
// ============ FLOW HOOKS ============
|
|
34
105
|
// useFlow is the primary hook for flow operations
|
|
35
106
|
export type {
|
|
36
107
|
FlowInputMetadata,
|
|
37
|
-
InputExecutionState,
|
|
38
|
-
UseFlowReturn,
|
|
39
108
|
FlowUploadState,
|
|
40
109
|
FlowUploadStatus,
|
|
110
|
+
InputExecutionState,
|
|
111
|
+
UseFlowReturn,
|
|
41
112
|
} from "./hooks/use-flow";
|
|
42
113
|
export { useFlow } from "./hooks/use-flow";
|
|
43
114
|
export type { UseFlowEventsOptions } from "./hooks/use-flow-events";
|
|
44
115
|
export { useFlowEvents } from "./hooks/use-flow-events";
|
|
45
116
|
export type { UseMultiFlowUploadReturn } from "./hooks/use-multi-flow-upload";
|
|
46
117
|
export { useMultiFlowUpload } from "./hooks/use-multi-flow-upload";
|
|
47
|
-
|
|
48
118
|
// ============ UPLOAD HOOKS ============
|
|
49
119
|
export type {
|
|
50
120
|
MultiUploadOptions,
|
|
@@ -77,83 +147,6 @@ export type {
|
|
|
77
147
|
UseUploadMetricsReturn,
|
|
78
148
|
} from "./hooks/use-upload-metrics";
|
|
79
149
|
export { useUploadMetrics } from "./hooks/use-upload-metrics";
|
|
80
|
-
|
|
81
|
-
// ============ DRAG & DROP ============
|
|
82
|
-
export type {
|
|
83
|
-
DragDropOptions,
|
|
84
|
-
DragDropState,
|
|
85
|
-
UseDragDropReturn,
|
|
86
|
-
} from "./hooks/use-drag-drop";
|
|
87
|
-
export { useDragDrop } from "./hooks/use-drag-drop";
|
|
88
|
-
|
|
89
|
-
// ============ UPLOAD PRIMITIVES (NEW) ============
|
|
90
|
-
// Compound component for file uploads
|
|
91
|
-
export {
|
|
92
|
-
Upload,
|
|
93
|
-
useUploadContext,
|
|
94
|
-
useUploadItemContext,
|
|
95
|
-
} from "./components/upload-primitives";
|
|
96
|
-
export type {
|
|
97
|
-
UploadProps,
|
|
98
|
-
UploadContextValue,
|
|
99
|
-
UploadItemContextValue,
|
|
100
|
-
UploadDropZoneProps,
|
|
101
|
-
UploadDropZoneRenderProps,
|
|
102
|
-
UploadItemsProps,
|
|
103
|
-
UploadItemsRenderProps,
|
|
104
|
-
UploadItemProps,
|
|
105
|
-
UploadProgressProps,
|
|
106
|
-
UploadProgressRenderProps,
|
|
107
|
-
UploadStatusProps,
|
|
108
|
-
UploadStatusRenderProps,
|
|
109
|
-
UploadErrorProps,
|
|
110
|
-
UploadErrorRenderProps,
|
|
111
|
-
UploadCancelProps,
|
|
112
|
-
UploadRetryProps,
|
|
113
|
-
UploadResetProps,
|
|
114
|
-
UploadStartAllProps,
|
|
115
|
-
UploadClearCompletedProps,
|
|
116
|
-
} from "./components/upload-primitives";
|
|
117
|
-
|
|
118
|
-
// ============ UPLOAD COMPONENTS (LEGACY) ============
|
|
119
|
-
export type {
|
|
120
|
-
SimpleUploadListItemProps,
|
|
121
|
-
UploadListProps,
|
|
122
|
-
UploadListRenderProps,
|
|
123
|
-
} from "./components/upload-list";
|
|
124
|
-
export { SimpleUploadListItem, UploadList } from "./components/upload-list";
|
|
125
|
-
export type {
|
|
126
|
-
SimpleUploadZoneProps,
|
|
127
|
-
UploadZoneProps,
|
|
128
|
-
UploadZoneRenderProps,
|
|
129
|
-
} from "./components/upload-zone";
|
|
130
|
-
export { SimpleUploadZone, UploadZone } from "./components/upload-zone";
|
|
131
|
-
|
|
132
|
-
// ============ FLOW UPLOAD LIST (for batch uploads) ============
|
|
133
|
-
export type {
|
|
134
|
-
FlowUploadListProps,
|
|
135
|
-
FlowUploadListRenderProps,
|
|
136
|
-
SimpleFlowUploadListItemProps,
|
|
137
|
-
SimpleFlowUploadListProps,
|
|
138
|
-
} from "./components/flow-upload-list";
|
|
139
|
-
export {
|
|
140
|
-
FlowUploadList,
|
|
141
|
-
SimpleFlowUploadList,
|
|
142
|
-
SimpleFlowUploadListItem,
|
|
143
|
-
} from "./components/flow-upload-list";
|
|
144
|
-
|
|
145
|
-
// ============ PROVIDERS & CONTEXTS ============
|
|
146
|
-
export {
|
|
147
|
-
UploadistaProvider,
|
|
148
|
-
useUploadistaContext,
|
|
149
|
-
} from "./components/uploadista-provider";
|
|
150
|
-
export {
|
|
151
|
-
FlowManagerProvider,
|
|
152
|
-
useFlowManagerContext,
|
|
153
|
-
} from "./contexts/flow-manager-context";
|
|
154
|
-
|
|
155
|
-
// ============ EVENT UTILITIES ============
|
|
156
|
-
export { isFlowEvent, isUploadEvent } from "./hooks/event-utils";
|
|
157
150
|
export type {
|
|
158
151
|
UseUploadistaClientOptions,
|
|
159
152
|
UseUploadistaClientReturn,
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
environment: "jsdom",
|
|
6
|
+
globals: true,
|
|
7
|
+
setupFiles: ["./src/__tests__/setup.ts"],
|
|
8
|
+
include: ["src/**/*.test.{ts,tsx}"],
|
|
9
|
+
coverage: {
|
|
10
|
+
provider: "v8",
|
|
11
|
+
reporter: ["text", "json", "html"],
|
|
12
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
13
|
+
exclude: ["src/__tests__/**", "src/**/*.test.{ts,tsx}"],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r,u as i}from"./use-upload-BgaJmdwF.mjs";import{createContext as a,useCallback as o,useContext as s}from"react";import{Fragment as c,jsx as l,jsxs as u}from"react/jsx-runtime";const d=a(null);function f(){let e=s(d);if(!e)throw Error(`useFlowContext must be used within a <Flow> component. Wrap your component tree with <Flow flowId="..." storageId="...">`);return e}const p=a(null);function m(){let e=s(p);if(!e)throw Error(`useFlowInputContext must be used within a <Flow.Input> component. Wrap your component with <Flow.Input nodeId="...">`);return e}function h({flowId:t,storageId:n,outputNodeId:r,metadata:i,onSuccess:a,onError:o,onProgress:s,onFlowComplete:c,onAbort:u,children:f}){let p=e({flowConfig:{flowId:t,storageId:n,outputNodeId:r,metadata:i},onSuccess:a,onError:o,onProgress:s,onFlowComplete:c,onAbort:u}),m={state:p.state,inputMetadata:p.inputMetadata,inputs:p.inputs,inputStates:p.inputStates,setInput:p.setInput,execute:p.execute,upload:p.upload,abort:p.abort,pause:p.pause,reset:p.reset,isUploading:p.isUploading,isUploadingFile:p.isUploadingFile,isProcessing:p.isProcessing,isDiscoveringInputs:p.isDiscoveringInputs};return l(d.Provider,{value:m,children:f})}function g({accept:e,maxFileSize:t,children:n}){let r=f(),a=i({onFilesReceived:e=>{let t=e[0];t&&r.upload(t)},accept:e?e.split(`,`).map(e=>e.trim()):void 0,maxFileSize:t,multiple:!1});return l(c,{children:n({isDragging:a.state.isDragging,isOver:a.state.isOver,progress:r.state.progress,status:r.state.status,getRootProps:()=>a.dragHandlers,getInputProps:()=>a.inputProps,openFilePicker:a.openFilePicker,dragDropState:a.state})})}function _({children:e}){let t=f();return l(c,{children:e({inputs:t.inputMetadata??[],isLoading:t.isDiscoveringInputs})})}function v({nodeId:e,children:t}){let n=f(),r=n.inputMetadata?.find(t=>t.nodeId===e);if(!r)return null;let i={nodeId:e,metadata:r,value:n.inputs[e],setValue:t=>n.setInput(e,t),state:n.inputStates.get(e)};return l(p.Provider,{value:i,children:typeof t==`function`?t(i):t})}function y({accept:e,maxFileSize:t,children:n}){let r=m(),a=i({onFilesReceived:e=>{let t=e[0];t&&r.setValue(t)},accept:e?e.split(`,`).map(e=>e.trim()):void 0,maxFileSize:t,multiple:!1});return l(c,{children:n({isDragging:a.state.isDragging,isOver:a.state.isOver,value:r.value,progress:r.state?.progress??0,status:r.state?.status??`idle`,getRootProps:()=>a.dragHandlers,getInputProps:()=>a.inputProps,openFilePicker:a.openFilePicker,dragDropState:a.state})})}function b({placeholder:e=`https://example.com/file`,...t}){let n=m();return l(`input`,{type:`url`,value:typeof n.value==`string`?n.value:``,onChange:e=>n.setValue(e.target.value),placeholder:e,...t})}function x({children:e}){let t=m(),n=t.value instanceof File,r=typeof t.value==`string`&&t.value.length>0;return l(c,{children:e({value:t.value,isFile:n,isUrl:r,fileName:n?t.value.name:null,fileSize:n?t.value.size:null,clear:()=>t.setValue(void 0)})})}function S({children:e}){let t=f();return l(c,{children:e({progress:t.state.progress,bytesUploaded:t.state.bytesUploaded,totalBytes:t.state.totalBytes,status:t.state.status})})}function C({children:e}){let t=f();return l(c,{children:e({status:t.state.status,currentNodeName:t.state.currentNodeName,currentNodeType:t.state.currentNodeType,error:t.state.error,jobId:t.state.jobId,flowStarted:t.state.flowStarted,flowOutputs:t.state.flowOutputs})})}function w({children:e}){let t=f();return l(c,{children:e({error:t.state.error,hasError:t.state.status===`error`,message:t.state.error?.message??null,reset:t.reset})})}function T({children:e,disabled:t,...n}){let r=f();return l(`button`,{type:`button`,onClick:o(()=>{r.execute()},[r]),disabled:t||r.isUploading,...n,children:e})}function E({children:e,...t}){let n=f();return l(`button`,{type:`button`,onClick:o(()=>{n.abort()},[n]),...t,children:e})}function D({children:e,...t}){let n=f();return l(`button`,{type:`button`,onClick:o(()=>{n.reset()},[n]),...t,children:e})}const O=Object.assign(h,{DropZone:g,Inputs:_,Input:Object.assign(v,{DropZone:y,UrlField:b,Preview:x}),Progress:S,Status:C,Error:w,Submit:T,Cancel:E,Reset:D});function k({multiUpload:e,filter:t,sortBy:n,children:r}){let i=e.items;t&&(i=i.filter(t)),n&&(i=[...i].sort(n));let a={idle:i.filter(e=>e.state.status===`idle`),uploading:i.filter(e=>e.state.status===`uploading`),success:i.filter(e=>e.state.status===`success`),error:i.filter(e=>e.state.status===`error`),aborted:i.filter(e=>e.state.status===`aborted`)};return l(c,{children:r({items:i,itemsByStatus:a,multiUpload:e,actions:{removeItem:t=>{e.removeItem(t)},retryItem:t=>{e.retryFailed()},abortItem:t=>{e.removeItem(t.id)},startItem:t=>{e.startAll()}}})})}function A({item:e,actions:t,className:n=``,style:r={},showDetails:i=!0}){let a=e=>{switch(e){case`idle`:return`#6c757d`;case`uploading`:return`#007bff`;case`success`:return`#28a745`;case`error`:return`#dc3545`;case`aborted`:return`#6c757d`;default:return`#6c757d`}},o=e=>{switch(e){case`idle`:return`⏳`;case`uploading`:return`📤`;case`success`:return`✅`;case`error`:return`❌`;case`aborted`:return`⏹️`;default:return`❓`}},s=e=>{if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`};return u(`div`,{className:`upload-list-item upload-list-item--${e.state.status} ${n}`,style:{padding:`12px`,border:`1px solid #e0e0e0`,borderRadius:`6px`,marginBottom:`8px`,backgroundColor:`#fff`,transition:`all 0.2s ease`,...r},children:[u(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:`8px`},children:[u(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`,flex:1},children:[l(`span`,{style:{fontSize:`16px`},children:o(e.state.status)}),l(`span`,{style:{fontWeight:`500`,flex:1},children:e.file instanceof File?e.file.name:`File`})]}),l(`span`,{style:{fontSize:`12px`,color:a(e.state.status),fontWeight:`500`,textTransform:`uppercase`},children:e.state.status})]}),e.state.status===`uploading`&&u(`div`,{style:{marginBottom:`8px`},children:[u(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginBottom:`4px`},children:[u(`span`,{style:{fontSize:`12px`,color:`#666`},children:[e.state.progress,`%`]}),i&&e.state.totalBytes&&u(`span`,{style:{fontSize:`12px`,color:`#666`},children:[s(e.state.bytesUploaded),` /`,` `,s(e.state.totalBytes)]})]}),l(`div`,{style:{width:`100%`,height:`6px`,backgroundColor:`#e0e0e0`,borderRadius:`3px`,overflow:`hidden`},children:l(`div`,{style:{width:`${e.state.progress}%`,height:`100%`,backgroundColor:`#007bff`,transition:`width 0.2s ease`}})})]}),i&&u(`div`,{style:{fontSize:`12px`,color:`#666`,marginBottom:`8px`},children:[e.state.totalBytes&&l(`span`,{children:s(e.state.totalBytes)}),e.state.status===`uploading`&&e.state.progress>0&&u(`span`,{children:[` • Progress: `,e.state.progress,`%`]}),e.state.status===`error`&&e.state.error&&l(`div`,{style:{color:`#dc3545`,marginTop:`4px`},children:e.state.error.message})]}),u(`div`,{style:{display:`flex`,gap:`8px`,flexWrap:`wrap`},children:[e.state.status===`idle`&&u(c,{children:[l(`button`,{type:`button`,onClick:()=>t.startItem(e),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #007bff`,backgroundColor:`#007bff`,color:`white`,borderRadius:`4px`,cursor:`pointer`},children:`Start`}),l(`button`,{type:`button`,onClick:()=>t.removeItem(e.id),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #6c757d`,backgroundColor:`transparent`,color:`#6c757d`,borderRadius:`4px`,cursor:`pointer`},children:`Remove`})]}),e.state.status===`uploading`&&l(`button`,{type:`button`,onClick:()=>t.abortItem(e),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #dc3545`,backgroundColor:`transparent`,color:`#dc3545`,borderRadius:`4px`,cursor:`pointer`},children:`Cancel`}),e.state.status===`error`&&u(c,{children:[l(`button`,{type:`button`,onClick:()=>t.retryItem(e),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #28a745`,backgroundColor:`#28a745`,color:`white`,borderRadius:`4px`,cursor:`pointer`},children:`Retry`}),l(`button`,{type:`button`,onClick:()=>t.removeItem(e.id),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #6c757d`,backgroundColor:`transparent`,color:`#6c757d`,borderRadius:`4px`,cursor:`pointer`},children:`Remove`})]}),e.state.status===`success`&&l(`button`,{type:`button`,onClick:()=>t.removeItem(e.id),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #6c757d`,backgroundColor:`transparent`,color:`#6c757d`,borderRadius:`4px`,cursor:`pointer`},children:`Remove`}),e.state.status===`aborted`&&u(c,{children:[l(`button`,{type:`button`,onClick:()=>t.retryItem(e),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #007bff`,backgroundColor:`#007bff`,color:`white`,borderRadius:`4px`,cursor:`pointer`},children:`Retry`}),l(`button`,{type:`button`,onClick:()=>t.removeItem(e.id),style:{padding:`4px 8px`,fontSize:`12px`,border:`1px solid #6c757d`,backgroundColor:`transparent`,color:`#6c757d`,borderRadius:`4px`,cursor:`pointer`},children:`Remove`})]})]})]})}function j({children:e,multiple:n=!0,multiUploadOptions:a={},uploadOptions:s={},onUploadStart:u,onValidationError:d,...f}){let p=r(s),m=t(a),h=o(e=>{let t=[];if(!n&&e.length>1&&t.push(`Single file mode is enabled. Please select only one file. You selected ${e.length} files.`),f.accept&&f.accept.length>0){let n=e.filter(e=>!f.accept?.some(t=>{if(t.startsWith(`.`))return e.name.toLowerCase().endsWith(t.toLowerCase());if(t.endsWith(`/*`)){let n=t.slice(0,-2);return e.type.startsWith(n)}else return e.type===t}));if(n.length>0){let e=n.map(e=>`"${e.name}" (${e.type})`).join(`, `),r=f.accept.join(`, `);t.push(`Invalid file type(s): ${e}. Accepted types: ${r}.`)}}return t.length>0?t:null},[n,f.accept]),g=e=>{u?.(e),n&&m?(m.addFiles(e),setTimeout(()=>m.startAll(),0)):!n&&p&&e.length>0&&e[0]&&p.upload(e[0])},_=o(e=>{console.error(`Upload zone validation errors:`,e),d?.(e)},[d]),v=i({...f,multiple:n,validator:h,onFilesReceived:g,onValidationError:_}),y=v.state.isDragging||v.state.isOver,b=n?m?.state.isUploading??!1:p?.isUploading??!1;return l(c,{children:e({dragDrop:v,upload:p,multiUpload:m,openFilePicker:v.openFilePicker,isActive:y,isProcessing:b})})}function M({className:e=``,style:t={},text:n={},errorStyle:r={},children:i,...a}){let o={idle:a.multiple?`Drag files here or click to select`:`Drag a file here or click to select`,dragging:a.multiple?`Drop files here...`:`Drop file here...`,uploading:`Uploading...`,...n};return i?l(j,{...a,children:i}):l(j,{...a,children:({dragDrop:n,upload:i,multiUpload:a,openFilePicker:s,isActive:c,isProcessing:d})=>u(`button`,{type:`button`,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&s()},onKeyUp:e=>{(e.key===`Enter`||e.key===` `)&&s()},...n.dragHandlers,onClick:s,className:`upload-zone ${c?`upload-zone--active`:``} ${d?`upload-zone--processing`:``} ${e}`,style:{border:c?`2px dashed #007bff`:`2px dashed #ccc`,borderRadius:`8px`,padding:`2rem`,textAlign:`center`,cursor:`pointer`,backgroundColor:c?`#f8f9fa`:`transparent`,transition:`all 0.2s ease`,minHeight:`120px`,display:`flex`,flexDirection:`column`,alignItems:`center`,justifyContent:`center`,...t},children:[n.state.isDragging?l(`p`,{style:{margin:0,fontSize:`16px`,color:`#007bff`},children:o.dragging}):d?u(`div`,{style:{textAlign:`center`},children:[l(`p`,{style:{margin:`0 0 10px 0`,fontSize:`14px`},children:o.uploading}),i&&u(`div`,{children:[l(`progress`,{value:i.state.progress,max:100,style:{width:`200px`,height:`8px`}}),u(`p`,{style:{margin:`5px 0 0 0`,fontSize:`12px`,color:`#666`},children:[i.state.progress,`%`]})]}),a&&u(`div`,{children:[l(`progress`,{value:a.state.progress,max:100,style:{width:`200px`,height:`8px`}}),u(`p`,{style:{margin:`5px 0 0 0`,fontSize:`12px`,color:`#666`},children:[a.state.progress,`% (`,a.state.uploading,` `,`uploading, `,a.state.successful,` completed)`]})]})]}):l(`p`,{style:{margin:0,fontSize:`16px`,color:`#666`},children:o.idle}),n.state.errors.length>0&&u(`div`,{style:{marginTop:`10px`,padding:`8px 12px`,backgroundColor:`#f8d7da`,border:`1px solid #f5c6cb`,borderRadius:`4px`,maxWidth:`100%`,...r},children:[l(`p`,{style:{margin:`0 0 5px 0`,fontSize:`12px`,fontWeight:`bold`,color:`#721c24`},children:`Validation Errors:`}),n.state.errors.map((e,t)=>u(`p`,{style:{color:`#721c24`,fontSize:`11px`,margin:`2px 0`,lineHeight:`1.3`},children:[`• `,e]},t))]}),l(`input`,{...n.inputProps})]})})}function N({flowConfig:e,options:t,children:r}){let i=n({...t,flowConfig:e});return l(c,{children:r({items:i.state.items,totalProgress:i.state.totalProgress,activeUploads:i.state.activeUploads,completedUploads:i.state.completedUploads,failedUploads:i.state.failedUploads,isUploading:i.isUploading,addFiles:i.addFiles,removeFile:i.removeFile,startUpload:i.startUpload,abortUpload:i.abortUpload,abortAll:i.abortAll,clear:i.clear,retryUpload:i.retryUpload})})}function P({item:e,onAbort:t,onRetry:n,onRemove:r}){return u(`div`,{style:{display:`flex`,alignItems:`center`,gap:`12px`,padding:`8px`,borderBottom:`1px solid #eee`},children:[l(`span`,{style:{color:(()=>{switch(e.status){case`success`:return`green`;case`error`:return`red`;case`uploading`:return`blue`;case`aborted`:return`gray`;default:return`black`}})(),fontSize:`18px`},children:(()=>{switch(e.status){case`success`:return`✓`;case`error`:return`✗`;case`uploading`:return`⟳`;case`aborted`:return`⊘`;default:return`○`}})()}),u(`div`,{style:{flex:1,minWidth:0},children:[l(`div`,{style:{fontSize:`14px`,fontWeight:500,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.file instanceof File?e.file.name:`Upload`}),e.status===`uploading`&&u(`div`,{style:{marginTop:`4px`},children:[l(`progress`,{value:e.progress,max:100,style:{width:`100%`,height:`4px`}}),u(`div`,{style:{fontSize:`12px`,color:`#666`,marginTop:`2px`},children:[e.progress,`% • `,Math.round(e.bytesUploaded/1024),` KB /`,` `,Math.round(e.totalBytes/1024),` KB`]})]}),e.status===`error`&&l(`div`,{style:{fontSize:`12px`,color:`red`,marginTop:`2px`},children:e.error?.message||`Upload failed`}),e.status===`success`&&l(`div`,{style:{fontSize:`12px`,color:`green`,marginTop:`2px`},children:`Upload complete`})]}),u(`div`,{style:{display:`flex`,gap:`8px`},children:[e.status===`uploading`&&l(`button`,{type:`button`,onClick:t,style:{padding:`4px 8px`,fontSize:`12px`,borderRadius:`4px`,border:`1px solid #ccc`,backgroundColor:`#fff`,cursor:`pointer`},children:`Cancel`}),e.status===`error`&&l(`button`,{type:`button`,onClick:n,style:{padding:`4px 8px`,fontSize:`12px`,borderRadius:`4px`,border:`1px solid #ccc`,backgroundColor:`#fff`,cursor:`pointer`},children:`Retry`}),(e.status===`pending`||e.status===`error`||e.status===`aborted`)&&l(`button`,{type:`button`,onClick:r,style:{padding:`4px 8px`,fontSize:`12px`,borderRadius:`4px`,border:`1px solid #ccc`,backgroundColor:`#fff`,cursor:`pointer`},children:`Remove`})]})]})}function F({flowConfig:e,options:t,className:n=``,showFileInput:r=!0,accept:i}){return l(N,{flowConfig:e,options:t,children:({items:e,addFiles:t,startUpload:a,abortUpload:o,retryUpload:s,removeFile:c,totalProgress:d})=>u(`div`,{className:n,children:[r&&l(`div`,{style:{marginBottom:`16px`},children:l(`input`,{type:`file`,multiple:!0,accept:i,onChange:e=>{e.target.files&&(t(e.target.files),a())},style:{padding:`8px`,border:`1px solid #ccc`,borderRadius:`4px`}})}),e.length>0&&u(`div`,{children:[u(`div`,{style:{marginBottom:`8px`,fontSize:`14px`,color:`#666`},children:[`Total Progress: `,d,`%`]}),l(`div`,{style:{border:`1px solid #eee`,borderRadius:`8px`,overflow:`hidden`},children:e.map(e=>l(P,{item:e,onAbort:()=>o(e.id),onRetry:()=>s(e.id),onRemove:()=>c(e.id)},e.id))})]})]})})}export{j as a,O as c,M as i,f as l,F as n,A as o,P as r,k as s,N as t,m as u};
|
|
2
|
-
//# sourceMappingURL=flow-upload-list-BJSCZ4Ty.mjs.map
|