@uploadista/react-native-core 0.1.3-beta.7 → 0.1.3-beta.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadista/react-native-core",
3
- "version": "0.1.3-beta.7",
3
+ "version": "0.1.3-beta.9",
4
4
  "type": "module",
5
5
  "description": "Core React Native client for Uploadista",
6
6
  "license": "MIT",
@@ -15,8 +15,8 @@
15
15
  "dependencies": {
16
16
  "uuid": "^13.0.0",
17
17
  "js-base64": "^3.7.7",
18
- "@uploadista/client-core": "0.1.3-beta.7",
19
- "@uploadista/core": "0.1.3-beta.7"
18
+ "@uploadista/client-core": "0.1.3-beta.9",
19
+ "@uploadista/core": "0.1.3-beta.9"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react": ">=16.8.0",
@@ -31,7 +31,7 @@
31
31
  "devDependencies": {
32
32
  "@types/react": ">=18.0.0",
33
33
  "tsdown": "0.20.1",
34
- "@uploadista/typescript-config": "0.1.3-beta.7"
34
+ "@uploadista/typescript-config": "0.1.3-beta.9"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "tsc --noEmit && tsdown",
@@ -45,6 +45,8 @@ export interface FlowContextValue {
45
45
  upload: (file: FilePickResult) => Promise<void>;
46
46
  /** Abort the current upload */
47
47
  abort: () => void;
48
+ /** Pause the current upload */
49
+ pause: () => void;
48
50
  /** Reset the upload state and clear all inputs */
49
51
  reset: () => void;
50
52
 
@@ -56,6 +58,8 @@ export interface FlowContextValue {
56
58
  isProcessing: boolean;
57
59
  /** Whether the hook is discovering flow inputs */
58
60
  isDiscoveringInputs: boolean;
61
+ /** Whether the flow is currently paused */
62
+ isPaused: boolean;
59
63
 
60
64
  /** Pick a file and set it for a specific input node */
61
65
  pickFileForInput: (nodeId: string) => Promise<void>;
@@ -241,11 +245,13 @@ function FlowRoot({
241
245
  execute: flow.execute,
242
246
  upload: flow.upload,
243
247
  abort: flow.abort,
248
+ pause: flow.pause,
244
249
  reset: flow.reset,
245
250
  isActive: flow.isActive,
246
251
  isUploadingFile: flow.isUploadingFile,
247
252
  isProcessing: flow.isProcessing,
248
253
  isDiscoveringInputs: flow.isDiscoveringInputs,
254
+ isPaused: flow.isPaused,
249
255
  pickFileForInput,
250
256
  pickAndUpload,
251
257
  };
@@ -726,6 +732,43 @@ function FlowReset({ children }: FlowResetProps) {
726
732
  );
727
733
  }
728
734
 
735
+ /**
736
+ * Render props for Flow.Pause component.
737
+ */
738
+ export interface FlowPauseRenderProps {
739
+ /** Pause the flow */
740
+ pause: () => void;
741
+ /** Whether the button should be disabled */
742
+ isDisabled: boolean;
743
+ /** Whether currently paused */
744
+ isPaused: boolean;
745
+ }
746
+
747
+ /**
748
+ * Props for Flow.Pause component.
749
+ */
750
+ export interface FlowPauseProps {
751
+ /** Render function receiving pause state */
752
+ children: ReactNode | ((props: FlowPauseRenderProps) => ReactNode);
753
+ }
754
+
755
+ /**
756
+ * Pause primitive that pauses the current upload.
757
+ */
758
+ function FlowPause({ children }: FlowPauseProps) {
759
+ const flow = useFlowContext();
760
+
761
+ const renderProps: FlowPauseRenderProps = {
762
+ pause: flow.pause,
763
+ isDisabled: !flow.isActive || flow.isPaused,
764
+ isPaused: flow.isPaused,
765
+ };
766
+
767
+ return (
768
+ <>{typeof children === "function" ? children(renderProps) : children}</>
769
+ );
770
+ }
771
+
729
772
  // ============ QUICK UPLOAD PRIMITIVE ============
730
773
 
731
774
  /**
@@ -842,6 +885,7 @@ export const Flow = Object.assign(FlowRoot, {
842
885
  Error: FlowError,
843
886
  Submit: FlowSubmit,
844
887
  Cancel: FlowCancel,
888
+ Pause: FlowPause,
845
889
  Reset: FlowReset,
846
890
  QuickUpload: FlowQuickUpload,
847
891
  });
@@ -27,6 +27,8 @@ export {
27
27
  type FlowInputProps,
28
28
  type FlowInputsProps,
29
29
  type FlowInputsRenderProps,
30
+ type FlowPauseProps,
31
+ type FlowPauseRenderProps,
30
32
  type FlowProgressProps,
31
33
  type FlowProgressRenderProps,
32
34
  type FlowProps,
@@ -166,6 +166,16 @@ export interface UseFlowReturn {
166
166
  * Whether a retry is possible (after error or abort with stored inputs)
167
167
  */
168
168
  canRetry: boolean;
169
+
170
+ /**
171
+ * Pause the current upload
172
+ */
173
+ pause: () => void;
174
+
175
+ /**
176
+ * Whether the flow is currently paused
177
+ */
178
+ isPaused: boolean;
169
179
  }
170
180
 
171
181
  const initialState: FlowUploadState = {
@@ -179,6 +189,7 @@ const initialState: FlowUploadState = {
179
189
  currentNodeName: null,
180
190
  currentNodeType: null,
181
191
  flowOutputs: null,
192
+ pausedAtNodeId: null,
182
193
  };
183
194
 
184
195
  /**
@@ -529,6 +540,10 @@ export function useFlow(options: UseFlowOptions): UseFlowReturn {
529
540
  managerRef.current?.abort();
530
541
  }, []);
531
542
 
543
+ const pause = useCallback(() => {
544
+ managerRef.current?.pause();
545
+ }, []);
546
+
532
547
  const reset = useCallback(() => {
533
548
  managerRef.current?.reset();
534
549
  setInputs({});
@@ -552,6 +567,7 @@ export function useFlow(options: UseFlowOptions): UseFlowReturn {
552
567
  state.status === "uploading" || state.status === "processing";
553
568
  const isUploadingFile = state.status === "uploading";
554
569
  const isProcessing = state.status === "processing";
570
+ const isPaused = state.status === "paused";
555
571
  const canRetry =
556
572
  (state.status === "error" || state.status === "aborted") &&
557
573
  lastInputsRef.current !== null;
@@ -565,6 +581,7 @@ export function useFlow(options: UseFlowOptions): UseFlowReturn {
565
581
  execute,
566
582
  upload,
567
583
  abort,
584
+ pause,
568
585
  reset,
569
586
  retry,
570
587
  isActive,
@@ -572,5 +589,6 @@ export function useFlow(options: UseFlowOptions): UseFlowReturn {
572
589
  isProcessing,
573
590
  isDiscoveringInputs,
574
591
  canRetry,
592
+ isPaused,
575
593
  };
576
594
  }
package/src/index.ts CHANGED
@@ -48,6 +48,8 @@ export {
48
48
  type FlowInputProps,
49
49
  type FlowInputsProps,
50
50
  type FlowInputsRenderProps,
51
+ type FlowPauseProps,
52
+ type FlowPauseRenderProps,
51
53
  type FlowProgressProps,
52
54
  type FlowProgressRenderProps,
53
55
  type FlowProps,