@rilaykit/workflow 7.1.0 → 8.0.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/index.d.mts +346 -242
- package/dist/index.d.ts +346 -242
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,169 @@ export { form } from '@rilaykit/forms';
|
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import React$1 from 'react';
|
|
7
7
|
|
|
8
|
+
interface WorkflowState {
|
|
9
|
+
currentStepIndex: number;
|
|
10
|
+
allData: Record<string, any>;
|
|
11
|
+
stepData: Record<string, any>;
|
|
12
|
+
visitedSteps: Set<string>;
|
|
13
|
+
isSubmitting: boolean;
|
|
14
|
+
isTransitioning: boolean;
|
|
15
|
+
isInitializing: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface UseWorkflowStateProps {
|
|
18
|
+
defaultValues?: Record<string, any>;
|
|
19
|
+
persistence?: {
|
|
20
|
+
workflowId: string;
|
|
21
|
+
adapter?: WorkflowPersistenceAdapter;
|
|
22
|
+
options?: PersistenceOptions;
|
|
23
|
+
userId?: string;
|
|
24
|
+
autoLoad?: boolean;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
declare function useWorkflowState({ defaultValues, persistence }: UseWorkflowStateProps): {
|
|
28
|
+
workflowState: WorkflowState;
|
|
29
|
+
setCurrentStep: (stepIndex: number) => void;
|
|
30
|
+
setStepData: (data: Record<string, any>, stepId: string) => void;
|
|
31
|
+
setFieldValue: (fieldId: string, value: any, stepId: string) => void;
|
|
32
|
+
setSubmitting: (isSubmitting: boolean) => void;
|
|
33
|
+
setTransitioning: (isTransitioning: boolean) => void;
|
|
34
|
+
markStepVisited: (stepIndex: number, stepId: string) => void;
|
|
35
|
+
resetWorkflow: () => void;
|
|
36
|
+
loadPersistedState: () => Promise<boolean>;
|
|
37
|
+
persistence: {
|
|
38
|
+
isPersisting: boolean;
|
|
39
|
+
persistenceError: WorkflowPersistenceError | null;
|
|
40
|
+
persistNow: () => Promise<void>;
|
|
41
|
+
clearPersistedData: () => Promise<void>;
|
|
42
|
+
hasPersistedData: () => Promise<boolean>;
|
|
43
|
+
} | null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @fileoverview Persistence system types for Rilay workflows
|
|
48
|
+
*
|
|
49
|
+
* This module defines the core interfaces and types for the workflow persistence system.
|
|
50
|
+
* It provides a flexible adapter pattern allowing different persistence strategies:
|
|
51
|
+
* - localStorage persistence
|
|
52
|
+
* - API-based persistence
|
|
53
|
+
* - Custom persistence implementations
|
|
54
|
+
*
|
|
55
|
+
* The system is designed to be type-safe and extensible while maintaining
|
|
56
|
+
* a simple API for common use cases.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Persistent workflow data that gets saved/loaded
|
|
61
|
+
*/
|
|
62
|
+
interface PersistedWorkflowData {
|
|
63
|
+
/** Unique identifier for the workflow */
|
|
64
|
+
workflowId: string;
|
|
65
|
+
/** Current step index in the workflow */
|
|
66
|
+
currentStepIndex: number;
|
|
67
|
+
/** All collected data across steps */
|
|
68
|
+
allData: Record<string, any>;
|
|
69
|
+
/** Currently active step data */
|
|
70
|
+
stepData: Record<string, any>;
|
|
71
|
+
/** Set of visited step IDs */
|
|
72
|
+
visitedSteps: string[];
|
|
73
|
+
/** When this data was last saved */
|
|
74
|
+
lastSaved: number;
|
|
75
|
+
/** Optional metadata for custom persistence needs */
|
|
76
|
+
metadata?: Record<string, any>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for persistence operations
|
|
80
|
+
*/
|
|
81
|
+
interface PersistenceOptions {
|
|
82
|
+
/** Whether to automatically persist on state changes */
|
|
83
|
+
autoPersist?: boolean;
|
|
84
|
+
/** Debounce delay in ms for auto-persistence (default: 500ms) */
|
|
85
|
+
debounceMs?: number;
|
|
86
|
+
/** Custom key for storage (overrides default) */
|
|
87
|
+
storageKey?: string;
|
|
88
|
+
/** Additional metadata to include in persisted data */
|
|
89
|
+
metadata?: Record<string, any>;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Core persistence adapter interface
|
|
93
|
+
*
|
|
94
|
+
* All persistence implementations must implement this interface.
|
|
95
|
+
* It provides a consistent API regardless of the underlying storage mechanism.
|
|
96
|
+
*/
|
|
97
|
+
interface WorkflowPersistenceAdapter {
|
|
98
|
+
/**
|
|
99
|
+
* Save workflow data
|
|
100
|
+
* @param key - Unique identifier for the stored data
|
|
101
|
+
* @param data - Workflow data to persist
|
|
102
|
+
* @returns Promise that resolves when save is complete
|
|
103
|
+
*/
|
|
104
|
+
save(key: string, data: PersistedWorkflowData): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Load workflow data
|
|
107
|
+
* @param key - Unique identifier for the stored data
|
|
108
|
+
* @returns Promise that resolves to persisted data or null if not found
|
|
109
|
+
*/
|
|
110
|
+
load(key: string): Promise<PersistedWorkflowData | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Remove persisted workflow data
|
|
113
|
+
* @param key - Unique identifier for the stored data
|
|
114
|
+
* @returns Promise that resolves when deletion is complete
|
|
115
|
+
*/
|
|
116
|
+
remove(key: string): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Check if data exists for the given key
|
|
119
|
+
* @param key - Unique identifier to check
|
|
120
|
+
* @returns Promise that resolves to true if data exists
|
|
121
|
+
*/
|
|
122
|
+
exists(key: string): Promise<boolean>;
|
|
123
|
+
/**
|
|
124
|
+
* List all available keys (optional, for debugging/admin)
|
|
125
|
+
* @returns Promise that resolves to array of available keys
|
|
126
|
+
*/
|
|
127
|
+
listKeys?(): Promise<string[]>;
|
|
128
|
+
/**
|
|
129
|
+
* Clear all persisted data (optional, for cleanup)
|
|
130
|
+
* @returns Promise that resolves when all data is cleared
|
|
131
|
+
*/
|
|
132
|
+
clear?(): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Configuration for localStorage persistence adapter
|
|
136
|
+
*/
|
|
137
|
+
interface LocalStorageAdapterConfig {
|
|
138
|
+
/** Prefix for localStorage keys (default: 'rilay_workflow_') */
|
|
139
|
+
keyPrefix?: string;
|
|
140
|
+
/** Whether to compress data before storage */
|
|
141
|
+
compress?: boolean;
|
|
142
|
+
/** Maximum age in ms before data expires (optional) */
|
|
143
|
+
maxAge?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Error types for persistence operations
|
|
147
|
+
*/
|
|
148
|
+
declare class WorkflowPersistenceError extends Error {
|
|
149
|
+
readonly code: string;
|
|
150
|
+
readonly cause?: Error | undefined;
|
|
151
|
+
constructor(message: string, code: string, cause?: Error | undefined);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Persistence hook return type
|
|
155
|
+
*/
|
|
156
|
+
interface UsePersistenceReturn {
|
|
157
|
+
/** Whether persistence is currently saving */
|
|
158
|
+
isPersisting: boolean;
|
|
159
|
+
/** Last persistence error (if any) */
|
|
160
|
+
persistenceError: WorkflowPersistenceError | null;
|
|
161
|
+
/** Manually trigger a save operation */
|
|
162
|
+
persistNow: () => Promise<void>;
|
|
163
|
+
/** Load data from persistence */
|
|
164
|
+
loadPersistedData: () => Promise<PersistedWorkflowData | null>;
|
|
165
|
+
/** Clear persisted data */
|
|
166
|
+
clearPersistedData: () => Promise<void>;
|
|
167
|
+
/** Whether persisted data exists */
|
|
168
|
+
hasPersistedData: () => Promise<boolean>;
|
|
169
|
+
}
|
|
170
|
+
|
|
8
171
|
/**
|
|
9
172
|
* Enhanced step configuration interface for better type safety and simplicity
|
|
10
173
|
*
|
|
@@ -55,6 +218,30 @@ interface StepDefinition {
|
|
|
55
218
|
* Controls visibility and skippable state
|
|
56
219
|
*/
|
|
57
220
|
conditions?: StepConditionalBehavior;
|
|
221
|
+
/**
|
|
222
|
+
* Custom metadata for this step
|
|
223
|
+
* Allows storing arbitrary information that can be accessed via hooks and context
|
|
224
|
+
*
|
|
225
|
+
* This is useful for:
|
|
226
|
+
* - UI customization (icons, colors, themes)
|
|
227
|
+
* - Analytics tracking (categories, priorities, custom events)
|
|
228
|
+
* - Business logic flags (feature flags, permissions, workflow rules)
|
|
229
|
+
* - Integration data (external IDs, API endpoints, configuration)
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* {
|
|
234
|
+
* metadata: {
|
|
235
|
+
* icon: 'user-circle',
|
|
236
|
+
* category: 'personal-info',
|
|
237
|
+
* analytics: { trackCompletion: true, priority: 'high' },
|
|
238
|
+
* ui: { theme: 'primary', showProgress: true },
|
|
239
|
+
* business: { requiresApproval: false, estimatedTime: 120 }
|
|
240
|
+
* }
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
metadata?: Record<string, any>;
|
|
58
245
|
/**
|
|
59
246
|
* Callback function that executes after successful validation and before moving to next step
|
|
60
247
|
* Provides clean helper methods for modifying workflow data and pre-filling subsequent steps
|
|
@@ -97,6 +284,12 @@ interface StepDefinition {
|
|
|
97
284
|
interface WorkflowOptions {
|
|
98
285
|
/** Analytics and tracking configuration */
|
|
99
286
|
analytics?: WorkflowAnalytics;
|
|
287
|
+
/** Persistence configuration */
|
|
288
|
+
persistence?: {
|
|
289
|
+
adapter: WorkflowPersistenceAdapter;
|
|
290
|
+
options?: PersistenceOptions;
|
|
291
|
+
userId?: string;
|
|
292
|
+
};
|
|
100
293
|
}
|
|
101
294
|
/**
|
|
102
295
|
* Workflow builder class for creating complex multi-step workflows
|
|
@@ -141,6 +334,7 @@ declare class flow {
|
|
|
141
334
|
private workflowDescription?;
|
|
142
335
|
private steps;
|
|
143
336
|
private analytics?;
|
|
337
|
+
private persistenceConfig?;
|
|
144
338
|
private plugins;
|
|
145
339
|
private idGenerator;
|
|
146
340
|
/**
|
|
@@ -231,17 +425,14 @@ declare class flow {
|
|
|
231
425
|
* @example
|
|
232
426
|
* ```typescript
|
|
233
427
|
* workflow.configure({
|
|
234
|
-
* navigation: {
|
|
235
|
-
* allowBackNavigation: true,
|
|
236
|
-
* showProgressBar: true
|
|
237
|
-
* },
|
|
238
|
-
* persistence: {
|
|
239
|
-
* saveOnStepComplete: true,
|
|
240
|
-
* storageKey: 'my-workflow'
|
|
241
|
-
* },
|
|
242
428
|
* analytics: {
|
|
243
429
|
* trackStepCompletion: true,
|
|
244
430
|
* trackFieldInteractions: false
|
|
431
|
+
* },
|
|
432
|
+
* persistence: {
|
|
433
|
+
* adapter: new LocalStorageAdapter(),
|
|
434
|
+
* options: { autoPersist: true, debounceMs: 1000 },
|
|
435
|
+
* userId: 'user123'
|
|
245
436
|
* }
|
|
246
437
|
* });
|
|
247
438
|
* ```
|
|
@@ -556,215 +747,146 @@ interface ConditionEvaluationResult {
|
|
|
556
747
|
* @returns Evaluated condition results
|
|
557
748
|
*/
|
|
558
749
|
declare function useConditionEvaluation(conditions?: ConditionalBehavior, workflowData?: Record<string, any>, defaultState?: Partial<ConditionEvaluationResult>): ConditionEvaluationResult;
|
|
559
|
-
/**
|
|
560
|
-
* Hook to evaluate multiple field conditions at once
|
|
561
|
-
*
|
|
562
|
-
* @param fieldsWithConditions - Map of field IDs to their conditional behaviors
|
|
563
|
-
* @param workflowData - Current workflow data to evaluate against
|
|
564
|
-
* @returns Map of field IDs to their evaluated conditions
|
|
565
|
-
*/
|
|
566
|
-
declare function useMultipleConditionEvaluation(fieldsWithConditions: Record<string, ConditionalBehavior | undefined>, workflowData?: Record<string, any>): Record<string, ConditionEvaluationResult>;
|
|
567
|
-
/**
|
|
568
|
-
* Hook to evaluate multiple step conditions at once using numeric indices
|
|
569
|
-
*
|
|
570
|
-
* @param stepsWithConditions - Map of step indices to their conditional behaviors
|
|
571
|
-
* @param workflowData - Current workflow data to evaluate against
|
|
572
|
-
* @returns Map of step indices to their evaluated conditions
|
|
573
|
-
*/
|
|
574
|
-
declare function useMultipleStepConditionEvaluation(stepsWithConditions: Record<number, ConditionalBehavior | undefined>, workflowData?: Record<string, any>): Record<number, ConditionEvaluationResult>;
|
|
575
750
|
|
|
576
751
|
/**
|
|
577
|
-
* @fileoverview Persistence
|
|
578
|
-
*
|
|
579
|
-
* This module defines the core interfaces and types for the workflow persistence system.
|
|
580
|
-
* It provides a flexible adapter pattern allowing different persistence strategies:
|
|
581
|
-
* - localStorage persistence
|
|
582
|
-
* - API-based persistence
|
|
583
|
-
* - Custom persistence implementations
|
|
752
|
+
* @fileoverview Persistence hook for Rilay workflows
|
|
584
753
|
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
754
|
+
* This hook provides workflow persistence functionality with automatic
|
|
755
|
+
* debounced saving, error handling, and flexible adapter support.
|
|
756
|
+
* It integrates seamlessly with the existing workflow state management.
|
|
587
757
|
*/
|
|
588
758
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
*/
|
|
592
|
-
interface PersistedWorkflowData {
|
|
593
|
-
/** Unique identifier for the workflow */
|
|
759
|
+
interface UsePersistenceProps {
|
|
760
|
+
/** Unique workflow identifier */
|
|
594
761
|
workflowId: string;
|
|
595
|
-
/** Current
|
|
596
|
-
|
|
597
|
-
/**
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
|
|
603
|
-
/** When this data was last saved */
|
|
604
|
-
lastSaved: number;
|
|
605
|
-
/** Optional metadata for custom persistence needs */
|
|
606
|
-
metadata?: Record<string, any>;
|
|
762
|
+
/** Current workflow state */
|
|
763
|
+
workflowState: WorkflowState;
|
|
764
|
+
/** Persistence adapter to use */
|
|
765
|
+
adapter: WorkflowPersistenceAdapter;
|
|
766
|
+
/** Persistence options */
|
|
767
|
+
options?: PersistenceOptions;
|
|
768
|
+
/** Optional user ID for multi-user scenarios */
|
|
769
|
+
userId?: string;
|
|
607
770
|
}
|
|
608
771
|
/**
|
|
609
|
-
*
|
|
772
|
+
* Hook for managing workflow persistence
|
|
773
|
+
*
|
|
774
|
+
* Provides automatic persistence with debouncing, manual save/load operations,
|
|
775
|
+
* and comprehensive error handling. Integrates with any persistence adapter
|
|
776
|
+
* that implements the WorkflowPersistenceAdapter interface.
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
* ```typescript
|
|
780
|
+
* const persistence = usePersistence({
|
|
781
|
+
* workflowId: 'user-onboarding',
|
|
782
|
+
* workflowState,
|
|
783
|
+
* adapter: new LocalStorageAdapter(),
|
|
784
|
+
* options: {
|
|
785
|
+
* autoPersist: true,
|
|
786
|
+
* debounceMs: 1000
|
|
787
|
+
* }
|
|
788
|
+
* });
|
|
789
|
+
*
|
|
790
|
+
* if (persistence.persistenceError) {
|
|
791
|
+
* console.error('Persistence error:', persistence.persistenceError);
|
|
792
|
+
* }
|
|
793
|
+
* ```
|
|
610
794
|
*/
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
autoPersist?: boolean;
|
|
614
|
-
/** Debounce delay in ms for auto-persistence (default: 500ms) */
|
|
615
|
-
debounceMs?: number;
|
|
616
|
-
/** Custom key for storage (overrides default) */
|
|
617
|
-
storageKey?: string;
|
|
618
|
-
/** Additional metadata to include in persisted data */
|
|
619
|
-
metadata?: Record<string, any>;
|
|
620
|
-
}
|
|
795
|
+
declare function usePersistence({ workflowId, workflowState, adapter, options, userId, }: UsePersistenceProps): UsePersistenceReturn;
|
|
796
|
+
|
|
621
797
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* All persistence implementations must implement this interface.
|
|
625
|
-
* It provides a consistent API regardless of the underlying storage mechanism.
|
|
798
|
+
* Hook return type for step metadata access
|
|
626
799
|
*/
|
|
627
|
-
interface
|
|
800
|
+
interface UseStepMetadataReturn {
|
|
628
801
|
/**
|
|
629
|
-
*
|
|
630
|
-
* @param key - Unique identifier for the stored data
|
|
631
|
-
* @param data - Workflow data to persist
|
|
632
|
-
* @returns Promise that resolves when save is complete
|
|
802
|
+
* Metadata for the current step
|
|
633
803
|
*/
|
|
634
|
-
|
|
804
|
+
current: Record<string, any> | undefined;
|
|
635
805
|
/**
|
|
636
|
-
*
|
|
637
|
-
* @param
|
|
638
|
-
* @returns
|
|
806
|
+
* Get metadata for a specific step by ID
|
|
807
|
+
* @param stepId - The ID of the step to get metadata for
|
|
808
|
+
* @returns The metadata object or undefined if step not found
|
|
639
809
|
*/
|
|
640
|
-
|
|
810
|
+
getByStepId: (stepId: string) => Record<string, any> | undefined;
|
|
641
811
|
/**
|
|
642
|
-
*
|
|
643
|
-
* @param
|
|
644
|
-
* @returns
|
|
812
|
+
* Get metadata for a specific step by index
|
|
813
|
+
* @param stepIndex - The index of the step to get metadata for
|
|
814
|
+
* @returns The metadata object or undefined if step not found
|
|
645
815
|
*/
|
|
646
|
-
|
|
816
|
+
getByStepIndex: (stepIndex: number) => Record<string, any> | undefined;
|
|
647
817
|
/**
|
|
648
|
-
* Check if
|
|
649
|
-
* @param key -
|
|
650
|
-
* @returns
|
|
818
|
+
* Check if current step has specific metadata key
|
|
819
|
+
* @param key - The metadata key to check for
|
|
820
|
+
* @returns True if the key exists in current step metadata
|
|
651
821
|
*/
|
|
652
|
-
|
|
822
|
+
hasCurrentKey: (key: string) => boolean;
|
|
653
823
|
/**
|
|
654
|
-
*
|
|
655
|
-
* @
|
|
824
|
+
* Get specific metadata value from current step
|
|
825
|
+
* @param key - The metadata key to retrieve
|
|
826
|
+
* @param defaultValue - Default value if key doesn't exist
|
|
827
|
+
* @returns The metadata value or default value
|
|
656
828
|
*/
|
|
657
|
-
|
|
829
|
+
getCurrentValue: <T = any>(key: string, defaultValue?: T) => T;
|
|
658
830
|
/**
|
|
659
|
-
*
|
|
660
|
-
* @returns
|
|
831
|
+
* Get all steps with their metadata
|
|
832
|
+
* @returns Array of objects containing step info and metadata
|
|
661
833
|
*/
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
/**
|
|
676
|
-
* Error types for persistence operations
|
|
677
|
-
*/
|
|
678
|
-
declare class WorkflowPersistenceError extends Error {
|
|
679
|
-
readonly code: string;
|
|
680
|
-
readonly cause?: Error | undefined;
|
|
681
|
-
constructor(message: string, code: string, cause?: Error | undefined);
|
|
834
|
+
getAllStepsMetadata: () => Array<{
|
|
835
|
+
id: string;
|
|
836
|
+
title: string;
|
|
837
|
+
index: number;
|
|
838
|
+
metadata: Record<string, any> | undefined;
|
|
839
|
+
}>;
|
|
840
|
+
/**
|
|
841
|
+
* Find steps by metadata criteria
|
|
842
|
+
* @param predicate - Function to test each step's metadata
|
|
843
|
+
* @returns Array of step IDs that match the criteria
|
|
844
|
+
*/
|
|
845
|
+
findStepsByMetadata: (predicate: (metadata: Record<string, any> | undefined, stepId: string, stepIndex: number) => boolean) => string[];
|
|
682
846
|
}
|
|
683
847
|
/**
|
|
684
|
-
*
|
|
848
|
+
* Hook to access and work with step metadata in workflows
|
|
849
|
+
*
|
|
850
|
+
* This hook provides convenient methods to access metadata for the current step
|
|
851
|
+
* or any other step in the workflow. It's useful for UI customization, analytics,
|
|
852
|
+
* business logic, and integration scenarios.
|
|
853
|
+
*
|
|
854
|
+
* @returns Object containing metadata access methods and current step metadata
|
|
855
|
+
*
|
|
856
|
+
* @example
|
|
857
|
+
* ```typescript
|
|
858
|
+
* function MyComponent() {
|
|
859
|
+
* const {
|
|
860
|
+
* current,
|
|
861
|
+
* getCurrentValue,
|
|
862
|
+
* hasCurrentKey,
|
|
863
|
+
* getByStepId,
|
|
864
|
+
* findStepsByMetadata
|
|
865
|
+
* } = useStepMetadata();
|
|
866
|
+
*
|
|
867
|
+
* // Access current step metadata
|
|
868
|
+
* const stepIcon = getCurrentValue('icon', 'default-icon');
|
|
869
|
+
* const hasAnalytics = hasCurrentKey('analytics');
|
|
870
|
+
*
|
|
871
|
+
* // Find steps with specific metadata
|
|
872
|
+
* const importantSteps = findStepsByMetadata(
|
|
873
|
+
* (metadata) => metadata?.priority === 'high'
|
|
874
|
+
* );
|
|
875
|
+
*
|
|
876
|
+
* // Get metadata from specific step
|
|
877
|
+
* const paymentStepMeta = getByStepId('payment-step');
|
|
878
|
+
*
|
|
879
|
+
* return (
|
|
880
|
+
* <div>
|
|
881
|
+
* <Icon name={stepIcon} />
|
|
882
|
+
* {hasAnalytics && <AnalyticsTracker />}
|
|
883
|
+
* <p>Important steps: {importantSteps.length}</p>
|
|
884
|
+
* </div>
|
|
885
|
+
* );
|
|
886
|
+
* }
|
|
887
|
+
* ```
|
|
685
888
|
*/
|
|
686
|
-
|
|
687
|
-
/** Whether persistence is currently saving */
|
|
688
|
-
isPersisting: boolean;
|
|
689
|
-
/** Last persistence error (if any) */
|
|
690
|
-
persistenceError: WorkflowPersistenceError | null;
|
|
691
|
-
/** Manually trigger a save operation */
|
|
692
|
-
persistNow: () => Promise<void>;
|
|
693
|
-
/** Load data from persistence */
|
|
694
|
-
loadPersistedData: () => Promise<PersistedWorkflowData | null>;
|
|
695
|
-
/** Clear persisted data */
|
|
696
|
-
clearPersistedData: () => Promise<void>;
|
|
697
|
-
/** Whether persisted data exists */
|
|
698
|
-
hasPersistedData: () => Promise<boolean>;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
interface WorkflowState {
|
|
702
|
-
currentStepIndex: number;
|
|
703
|
-
allData: Record<string, any>;
|
|
704
|
-
stepData: Record<string, any>;
|
|
705
|
-
visitedSteps: Set<string>;
|
|
706
|
-
isSubmitting: boolean;
|
|
707
|
-
isTransitioning: boolean;
|
|
708
|
-
}
|
|
709
|
-
type WorkflowAction = {
|
|
710
|
-
type: 'SET_CURRENT_STEP';
|
|
711
|
-
stepIndex: number;
|
|
712
|
-
} | {
|
|
713
|
-
type: 'SET_STEP_DATA';
|
|
714
|
-
data: Record<string, any>;
|
|
715
|
-
stepId: string;
|
|
716
|
-
} | {
|
|
717
|
-
type: 'SET_ALL_DATA';
|
|
718
|
-
data: Record<string, any>;
|
|
719
|
-
} | {
|
|
720
|
-
type: 'SET_FIELD_VALUE';
|
|
721
|
-
fieldId: string;
|
|
722
|
-
value: any;
|
|
723
|
-
stepId: string;
|
|
724
|
-
} | {
|
|
725
|
-
type: 'SET_SUBMITTING';
|
|
726
|
-
isSubmitting: boolean;
|
|
727
|
-
} | {
|
|
728
|
-
type: 'SET_TRANSITIONING';
|
|
729
|
-
isTransitioning: boolean;
|
|
730
|
-
} | {
|
|
731
|
-
type: 'MARK_STEP_VISITED';
|
|
732
|
-
stepIndex: number;
|
|
733
|
-
stepId: string;
|
|
734
|
-
} | {
|
|
735
|
-
type: 'RESET_WORKFLOW';
|
|
736
|
-
} | {
|
|
737
|
-
type: 'LOAD_PERSISTED_STATE';
|
|
738
|
-
state: Partial<WorkflowState>;
|
|
739
|
-
};
|
|
740
|
-
interface UseWorkflowStateProps {
|
|
741
|
-
defaultValues?: Record<string, any>;
|
|
742
|
-
persistence?: {
|
|
743
|
-
workflowId: string;
|
|
744
|
-
adapter?: WorkflowPersistenceAdapter;
|
|
745
|
-
options?: PersistenceOptions;
|
|
746
|
-
userId?: string;
|
|
747
|
-
autoLoad?: boolean;
|
|
748
|
-
};
|
|
749
|
-
}
|
|
750
|
-
declare function useWorkflowState({ defaultValues, persistence }: UseWorkflowStateProps): {
|
|
751
|
-
workflowState: WorkflowState;
|
|
752
|
-
setCurrentStep: (stepIndex: number) => void;
|
|
753
|
-
setStepData: (data: Record<string, any>, stepId: string) => void;
|
|
754
|
-
setFieldValue: (fieldId: string, value: any, stepId: string) => void;
|
|
755
|
-
setSubmitting: (isSubmitting: boolean) => void;
|
|
756
|
-
setTransitioning: (isTransitioning: boolean) => void;
|
|
757
|
-
markStepVisited: (stepIndex: number, stepId: string) => void;
|
|
758
|
-
resetWorkflow: () => void;
|
|
759
|
-
loadPersistedState: () => Promise<boolean>;
|
|
760
|
-
persistence: {
|
|
761
|
-
isPersisting: boolean;
|
|
762
|
-
persistenceError: WorkflowPersistenceError | null;
|
|
763
|
-
persistNow: () => Promise<void>;
|
|
764
|
-
clearPersistedData: () => Promise<void>;
|
|
765
|
-
hasPersistedData: () => Promise<boolean>;
|
|
766
|
-
} | null;
|
|
767
|
-
};
|
|
889
|
+
declare function useStepMetadata(): UseStepMetadataReturn;
|
|
768
890
|
|
|
769
891
|
interface UseWorkflowAnalyticsProps {
|
|
770
892
|
workflowConfig: WorkflowConfig;
|
|
@@ -858,6 +980,7 @@ interface WorkflowContextValue {
|
|
|
858
980
|
context: WorkflowContext;
|
|
859
981
|
formConfig?: FormConfiguration;
|
|
860
982
|
conditionsHelpers: UseWorkflowConditionsReturn;
|
|
983
|
+
currentStepMetadata?: Record<string, any>;
|
|
861
984
|
goToStep: (stepIndex: number) => Promise<boolean>;
|
|
862
985
|
goNext: () => Promise<boolean>;
|
|
863
986
|
goPrevious: () => Promise<boolean>;
|
|
@@ -872,6 +995,9 @@ interface WorkflowContextValue {
|
|
|
872
995
|
submitWorkflow: () => Promise<void>;
|
|
873
996
|
isSubmitting: boolean;
|
|
874
997
|
canSubmit: boolean;
|
|
998
|
+
persistNow?: () => Promise<void>;
|
|
999
|
+
isPersisting?: boolean;
|
|
1000
|
+
persistenceError?: Error | null;
|
|
875
1001
|
}
|
|
876
1002
|
interface WorkflowProviderProps {
|
|
877
1003
|
children: React$1.ReactNode;
|
|
@@ -896,17 +1022,41 @@ type WorkflowProps = Omit<WorkflowProviderProps, 'children' | 'workflowConfig'>
|
|
|
896
1022
|
*/
|
|
897
1023
|
declare function Workflow({ children, workflowConfig, ...props }: WorkflowProps): react_jsx_runtime.JSX.Element;
|
|
898
1024
|
|
|
1025
|
+
interface WorkflowBodyProps {
|
|
1026
|
+
stepId?: string;
|
|
1027
|
+
}
|
|
899
1028
|
/**
|
|
900
1029
|
* Renders the main content of the current workflow step.
|
|
901
1030
|
* Simple component that renders either the children or FormBody by default.
|
|
902
1031
|
*/
|
|
903
|
-
declare function WorkflowBody(): react_jsx_runtime.JSX.Element | null;
|
|
1032
|
+
declare function WorkflowBody({ stepId }: WorkflowBodyProps): react_jsx_runtime.JSX.Element | null;
|
|
904
1033
|
|
|
905
|
-
|
|
1034
|
+
interface WorkflowNextButtonProps extends ComponentRendererBaseProps<WorkflowNextButtonRendererProps> {
|
|
1035
|
+
/**
|
|
1036
|
+
* Override the isSubmitting state from workflow/form context
|
|
1037
|
+
* If provided, this value will be used instead of the computed isSubmitting state
|
|
1038
|
+
*/
|
|
1039
|
+
isSubmitting?: boolean;
|
|
1040
|
+
}
|
|
1041
|
+
declare function WorkflowNextButton({ className, isSubmitting: overrideIsSubmitting, ...props }: WorkflowNextButtonProps): react_jsx_runtime.JSX.Element;
|
|
906
1042
|
|
|
907
|
-
|
|
1043
|
+
interface WorkflowPreviousButtonProps extends ComponentRendererBaseProps<WorkflowPreviousButtonRendererProps> {
|
|
1044
|
+
/**
|
|
1045
|
+
* Override the isSubmitting state from workflow/form context
|
|
1046
|
+
* If provided, this value will be used instead of the computed isSubmitting state
|
|
1047
|
+
*/
|
|
1048
|
+
isSubmitting?: boolean;
|
|
1049
|
+
}
|
|
1050
|
+
declare function WorkflowPreviousButton({ className, isSubmitting: overrideIsSubmitting, ...props }: WorkflowPreviousButtonProps): react_jsx_runtime.JSX.Element;
|
|
908
1051
|
|
|
909
|
-
|
|
1052
|
+
interface WorkflowSkipButtonProps extends ComponentRendererBaseProps<WorkflowSkipButtonRendererProps> {
|
|
1053
|
+
/**
|
|
1054
|
+
* Override the isSubmitting state from workflow/form context
|
|
1055
|
+
* If provided, this value will be used instead of the computed isSubmitting state
|
|
1056
|
+
*/
|
|
1057
|
+
isSubmitting?: boolean;
|
|
1058
|
+
}
|
|
1059
|
+
declare function WorkflowSkipButton({ className, isSubmitting: overrideIsSubmitting, ...props }: WorkflowSkipButtonProps): react_jsx_runtime.JSX.Element;
|
|
910
1060
|
|
|
911
1061
|
interface WorkflowStepperProps extends ComponentRendererBaseProps<WorkflowStepperRendererProps> {
|
|
912
1062
|
onStepClick?: (stepIndex: number) => void;
|
|
@@ -1031,52 +1181,6 @@ declare function debounce<T extends (...args: any[]) => any>(func: T, wait: numb
|
|
|
1031
1181
|
*/
|
|
1032
1182
|
declare function mergePersistedState(currentState: WorkflowState, persistedData: PersistedWorkflowData, strategy?: 'persist' | 'current' | 'merge'): Partial<WorkflowState>;
|
|
1033
1183
|
|
|
1034
|
-
/**
|
|
1035
|
-
* @fileoverview Persistence hook for Rilay workflows
|
|
1036
|
-
*
|
|
1037
|
-
* This hook provides workflow persistence functionality with automatic
|
|
1038
|
-
* debounced saving, error handling, and flexible adapter support.
|
|
1039
|
-
* It integrates seamlessly with the existing workflow state management.
|
|
1040
|
-
*/
|
|
1041
|
-
|
|
1042
|
-
interface UsePersistenceProps {
|
|
1043
|
-
/** Unique workflow identifier */
|
|
1044
|
-
workflowId: string;
|
|
1045
|
-
/** Current workflow state */
|
|
1046
|
-
workflowState: WorkflowState;
|
|
1047
|
-
/** Persistence adapter to use */
|
|
1048
|
-
adapter: WorkflowPersistenceAdapter;
|
|
1049
|
-
/** Persistence options */
|
|
1050
|
-
options?: PersistenceOptions;
|
|
1051
|
-
/** Optional user ID for multi-user scenarios */
|
|
1052
|
-
userId?: string;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* Hook for managing workflow persistence
|
|
1056
|
-
*
|
|
1057
|
-
* Provides automatic persistence with debouncing, manual save/load operations,
|
|
1058
|
-
* and comprehensive error handling. Integrates with any persistence adapter
|
|
1059
|
-
* that implements the WorkflowPersistenceAdapter interface.
|
|
1060
|
-
*
|
|
1061
|
-
* @example
|
|
1062
|
-
* ```typescript
|
|
1063
|
-
* const persistence = usePersistence({
|
|
1064
|
-
* workflowId: 'user-onboarding',
|
|
1065
|
-
* workflowState,
|
|
1066
|
-
* adapter: new LocalStorageAdapter(),
|
|
1067
|
-
* options: {
|
|
1068
|
-
* autoPersist: true,
|
|
1069
|
-
* debounceMs: 1000
|
|
1070
|
-
* }
|
|
1071
|
-
* });
|
|
1072
|
-
*
|
|
1073
|
-
* if (persistence.persistenceError) {
|
|
1074
|
-
* console.error('Persistence error:', persistence.persistenceError);
|
|
1075
|
-
* }
|
|
1076
|
-
* ```
|
|
1077
|
-
*/
|
|
1078
|
-
declare function usePersistence({ workflowId, workflowState, adapter, options, userId, }: UsePersistenceProps): UsePersistenceReturn;
|
|
1079
|
-
|
|
1080
1184
|
interface LicensePayload {
|
|
1081
1185
|
plan: 'ARCHITECT' | 'FOUNDRY';
|
|
1082
1186
|
company: string;
|
|
@@ -1145,4 +1249,4 @@ declare class RilayLicenseManager {
|
|
|
1145
1249
|
}>;
|
|
1146
1250
|
}
|
|
1147
1251
|
|
|
1148
|
-
export { type
|
|
1252
|
+
export { type LicensePayload, type LicensePlan, type LicenseResult, LocalStorageAdapter, type LocalStorageAdapterConfig, type PersistedWorkflowData, type PersistenceOptions, RilayLicenseManager, type StepDefinition, type UsePersistenceProps, type UsePersistenceReturn, Workflow, WorkflowBody, type WorkflowContextValue, WorkflowNextButton, type WorkflowPersistenceAdapter, WorkflowPersistenceError, WorkflowPreviousButton, WorkflowProvider, WorkflowSkipButton, WorkflowStepper, createFlow, debounce, flow, generateStorageKey, mergePersistedState, persistedToWorkflowState, useConditionEvaluation, usePersistence, useStepMetadata, useWorkflowAnalytics, useWorkflowConditions, useWorkflowContext, useWorkflowNavigation, useWorkflowState, useWorkflowSubmission, validatePersistedData, workflowStateToPersisted };
|