@rilaykit/workflow 8.1.1 → 9.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 +22 -61
- package/dist/index.d.ts +22 -61
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/package.json +14 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { ril, FormConfiguration, CustomStepRenderer, StepConditionalBehavior, StepDataHelper, WorkflowContext, WorkflowAnalytics, WorkflowPlugin, StepConfig, WorkflowConfig, ConditionalBehavior, ComponentRendererBaseProps, WorkflowNextButtonRendererProps, WorkflowPreviousButtonRendererProps, WorkflowSkipButtonRendererProps, WorkflowStepperRendererProps } from '@rilaykit/core';
|
|
2
|
-
export * from '@rilaykit/core';
|
|
3
2
|
import { form } from '@rilaykit/forms';
|
|
4
|
-
export { form } from '@rilaykit/forms';
|
|
5
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
-
import
|
|
7
|
-
import React__default from 'react';
|
|
4
|
+
import React$1 from 'react';
|
|
8
5
|
|
|
9
6
|
interface WorkflowState {
|
|
10
7
|
currentStepIndex: number;
|
|
@@ -198,7 +195,7 @@ interface StepDefinition {
|
|
|
198
195
|
* Form configuration for the step
|
|
199
196
|
* Can be either a built FormConfiguration or a form builder instance
|
|
200
197
|
*/
|
|
201
|
-
formConfig: FormConfiguration | form
|
|
198
|
+
formConfig: FormConfiguration<any> | form<any>;
|
|
202
199
|
/**
|
|
203
200
|
* Whether users can skip this step
|
|
204
201
|
* @default false
|
|
@@ -307,6 +304,11 @@ interface WorkflowOptions {
|
|
|
307
304
|
* - Comprehensive statistics and analytics
|
|
308
305
|
* - Type-safe configuration management
|
|
309
306
|
*
|
|
307
|
+
* DX Notes:
|
|
308
|
+
* - Recommended: use the explicit factory `flow.create(rilConfig, id, name)`; we do not augment ril with `.flow()`.
|
|
309
|
+
* - Steps accept either a built `FormConfiguration` or a `form` builder; builders are built internally.
|
|
310
|
+
* - Use `when('path')...build()` for step-level conditions in `StepConditionalBehavior`.
|
|
311
|
+
*
|
|
310
312
|
* @example
|
|
311
313
|
* ```typescript
|
|
312
314
|
* const workflow = flow.create(rilConfig, 'user-onboarding', 'User Onboarding')
|
|
@@ -346,13 +348,15 @@ declare class flow {
|
|
|
346
348
|
* @param workflowName - Display name for the workflow
|
|
347
349
|
* @param description - Optional description of the workflow purpose
|
|
348
350
|
*/
|
|
349
|
-
constructor(config: ril
|
|
351
|
+
constructor(config: ril<any>, workflowId: string, workflowName: string, description?: string);
|
|
350
352
|
/**
|
|
351
353
|
* Static factory method to create a new workflow builder
|
|
352
354
|
*
|
|
353
355
|
* This is the preferred way to create workflow builders as it provides
|
|
354
356
|
* better type inference and follows the factory pattern.
|
|
355
357
|
*
|
|
358
|
+
* DX Note: Prefer using this factory over `new flow(...)` for clarity and consistency.
|
|
359
|
+
*
|
|
356
360
|
* @param config - The ril configuration instance
|
|
357
361
|
* @param workflowId - Unique identifier for the workflow
|
|
358
362
|
* @param workflowName - Display name for the workflow
|
|
@@ -364,7 +368,7 @@ declare class flow {
|
|
|
364
368
|
* const workflow = flow.create(rilConfig, 'checkout', 'Checkout Process');
|
|
365
369
|
* ```
|
|
366
370
|
*/
|
|
367
|
-
static create(config: ril
|
|
371
|
+
static create(config: ril<any>, workflowId: string, workflowName: string, description?: string): flow;
|
|
368
372
|
/**
|
|
369
373
|
* Helper method to create a step configuration from StepDefinition
|
|
370
374
|
*
|
|
@@ -687,51 +691,6 @@ declare class flow {
|
|
|
687
691
|
*/
|
|
688
692
|
fromJSON(json: any): this;
|
|
689
693
|
}
|
|
690
|
-
/**
|
|
691
|
-
* Factory function to create a workflow builder directly
|
|
692
|
-
*
|
|
693
|
-
* This is a convenience function that provides an alternative to using
|
|
694
|
-
* the class constructor or static create method. It's particularly useful
|
|
695
|
-
* for functional programming styles or when you prefer function calls
|
|
696
|
-
* over class instantiation.
|
|
697
|
-
*
|
|
698
|
-
* @param config - The ril configuration instance
|
|
699
|
-
* @param workflowId - Unique identifier for the workflow
|
|
700
|
-
* @param workflowName - Display name for the workflow
|
|
701
|
-
* @param description - Optional description of the workflow purpose
|
|
702
|
-
* @returns A new flow builder instance
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* ```typescript
|
|
706
|
-
* const workflow = createFlow(rilConfig, 'onboarding', 'User Onboarding');
|
|
707
|
-
* ```
|
|
708
|
-
*/
|
|
709
|
-
declare function createFlow(config: ril, workflowId: string, workflowName: string, description?: string): flow;
|
|
710
|
-
/**
|
|
711
|
-
* Module augmentation to add createFlow method to ril instances
|
|
712
|
-
*
|
|
713
|
-
* This declaration extends the ril interface to include the createFlow
|
|
714
|
-
* method, allowing for a more integrated API experience where workflows
|
|
715
|
-
* can be created directly from ril configuration instances.
|
|
716
|
-
*/
|
|
717
|
-
declare module '@rilaykit/core' {
|
|
718
|
-
interface ril {
|
|
719
|
-
/**
|
|
720
|
-
* Creates a new workflow builder using this ril configuration
|
|
721
|
-
*
|
|
722
|
-
* @param workflowId - Unique identifier for the workflow
|
|
723
|
-
* @param workflowName - Display name for the workflow
|
|
724
|
-
* @param description - Optional description of the workflow purpose
|
|
725
|
-
* @returns A new flow builder instance
|
|
726
|
-
*
|
|
727
|
-
* @example
|
|
728
|
-
* ```typescript
|
|
729
|
-
* const workflow = rilConfig.createFlow('checkout', 'Checkout Process');
|
|
730
|
-
* ```
|
|
731
|
-
*/
|
|
732
|
-
flow(workflowId: string, workflowName: string, description?: string): flow;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
694
|
|
|
736
695
|
interface ConditionEvaluationResult {
|
|
737
696
|
visible: boolean;
|
|
@@ -898,6 +857,8 @@ interface UseWorkflowAnalyticsReturn {
|
|
|
898
857
|
analyticsStartTime: React.MutableRefObject<number>;
|
|
899
858
|
trackStepSkip: (stepId: string, reason: string) => void;
|
|
900
859
|
trackError: (error: Error) => void;
|
|
860
|
+
trackNavigation: (fromStep: number, toStep: number, duration: number) => void;
|
|
861
|
+
trackConditionEvaluation: (duration: number, conditionsCount: number) => void;
|
|
901
862
|
}
|
|
902
863
|
declare function useWorkflowAnalytics({ workflowConfig, workflowState, workflowContext, }: UseWorkflowAnalyticsProps): UseWorkflowAnalyticsReturn;
|
|
903
864
|
|
|
@@ -1001,7 +962,7 @@ interface WorkflowContextValue {
|
|
|
1001
962
|
persistenceError?: Error | null;
|
|
1002
963
|
}
|
|
1003
964
|
interface WorkflowProviderProps {
|
|
1004
|
-
children:
|
|
965
|
+
children: React$1.ReactNode;
|
|
1005
966
|
workflowConfig: WorkflowConfig;
|
|
1006
967
|
defaultValues?: Record<string, any>;
|
|
1007
968
|
onStepChange?: (fromStep: number, toStep: number, context: WorkflowContext) => void;
|
|
@@ -1012,7 +973,7 @@ declare function WorkflowProvider({ children, workflowConfig, defaultValues, onS
|
|
|
1012
973
|
declare function useWorkflowContext(): WorkflowContextValue;
|
|
1013
974
|
|
|
1014
975
|
type WorkflowProps = Omit<WorkflowProviderProps, 'children' | 'workflowConfig'> & {
|
|
1015
|
-
children:
|
|
976
|
+
children: React$1.ReactNode;
|
|
1016
977
|
workflowConfig: WorkflowConfig | flow;
|
|
1017
978
|
};
|
|
1018
979
|
/**
|
|
@@ -1025,13 +986,13 @@ declare function Workflow({ children, workflowConfig, ...props }: WorkflowProps)
|
|
|
1025
986
|
|
|
1026
987
|
interface WorkflowBodyProps {
|
|
1027
988
|
stepId?: string;
|
|
1028
|
-
children?: React.ReactNode;
|
|
989
|
+
children?: React$1.ReactNode;
|
|
1029
990
|
}
|
|
1030
991
|
/**
|
|
1031
992
|
* Renders the main content of the current workflow step.
|
|
1032
993
|
* Simple component that renders either the children or FormBody by default.
|
|
1033
994
|
*/
|
|
1034
|
-
declare
|
|
995
|
+
declare const WorkflowBody: React$1.NamedExoticComponent<WorkflowBodyProps>;
|
|
1035
996
|
|
|
1036
997
|
interface WorkflowNextButtonProps extends ComponentRendererBaseProps<WorkflowNextButtonRendererProps> {
|
|
1037
998
|
/**
|
|
@@ -1040,7 +1001,7 @@ interface WorkflowNextButtonProps extends ComponentRendererBaseProps<WorkflowNex
|
|
|
1040
1001
|
*/
|
|
1041
1002
|
isSubmitting?: boolean;
|
|
1042
1003
|
}
|
|
1043
|
-
declare
|
|
1004
|
+
declare const WorkflowNextButton: React$1.NamedExoticComponent<WorkflowNextButtonProps>;
|
|
1044
1005
|
|
|
1045
1006
|
interface WorkflowPreviousButtonProps extends ComponentRendererBaseProps<WorkflowPreviousButtonRendererProps> {
|
|
1046
1007
|
/**
|
|
@@ -1049,7 +1010,7 @@ interface WorkflowPreviousButtonProps extends ComponentRendererBaseProps<Workflo
|
|
|
1049
1010
|
*/
|
|
1050
1011
|
isSubmitting?: boolean;
|
|
1051
1012
|
}
|
|
1052
|
-
declare
|
|
1013
|
+
declare const WorkflowPreviousButton: React$1.NamedExoticComponent<WorkflowPreviousButtonProps>;
|
|
1053
1014
|
|
|
1054
1015
|
interface WorkflowSkipButtonProps extends ComponentRendererBaseProps<WorkflowSkipButtonRendererProps> {
|
|
1055
1016
|
/**
|
|
@@ -1058,12 +1019,12 @@ interface WorkflowSkipButtonProps extends ComponentRendererBaseProps<WorkflowSki
|
|
|
1058
1019
|
*/
|
|
1059
1020
|
isSubmitting?: boolean;
|
|
1060
1021
|
}
|
|
1061
|
-
declare
|
|
1022
|
+
declare const WorkflowSkipButton: React$1.NamedExoticComponent<WorkflowSkipButtonProps>;
|
|
1062
1023
|
|
|
1063
1024
|
interface WorkflowStepperProps extends ComponentRendererBaseProps<WorkflowStepperRendererProps> {
|
|
1064
1025
|
onStepClick?: (stepIndex: number) => void;
|
|
1065
1026
|
}
|
|
1066
|
-
declare
|
|
1027
|
+
declare const WorkflowStepper: React$1.NamedExoticComponent<WorkflowStepperProps>;
|
|
1067
1028
|
|
|
1068
1029
|
/**
|
|
1069
1030
|
* @fileoverview LocalStorage persistence adapter for Rilay workflows
|
|
@@ -1251,4 +1212,4 @@ declare class RilayLicenseManager {
|
|
|
1251
1212
|
}>;
|
|
1252
1213
|
}
|
|
1253
1214
|
|
|
1254
|
-
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,
|
|
1215
|
+
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, debounce, flow, generateStorageKey, mergePersistedState, persistedToWorkflowState, useConditionEvaluation, usePersistence, useStepMetadata, useWorkflowAnalytics, useWorkflowConditions, useWorkflowContext, useWorkflowNavigation, useWorkflowState, useWorkflowSubmission, validatePersistedData, workflowStateToPersisted };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { ril, FormConfiguration, CustomStepRenderer, StepConditionalBehavior, StepDataHelper, WorkflowContext, WorkflowAnalytics, WorkflowPlugin, StepConfig, WorkflowConfig, ConditionalBehavior, ComponentRendererBaseProps, WorkflowNextButtonRendererProps, WorkflowPreviousButtonRendererProps, WorkflowSkipButtonRendererProps, WorkflowStepperRendererProps } from '@rilaykit/core';
|
|
2
|
-
export * from '@rilaykit/core';
|
|
3
2
|
import { form } from '@rilaykit/forms';
|
|
4
|
-
export { form } from '@rilaykit/forms';
|
|
5
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
-
import
|
|
7
|
-
import React__default from 'react';
|
|
4
|
+
import React$1 from 'react';
|
|
8
5
|
|
|
9
6
|
interface WorkflowState {
|
|
10
7
|
currentStepIndex: number;
|
|
@@ -198,7 +195,7 @@ interface StepDefinition {
|
|
|
198
195
|
* Form configuration for the step
|
|
199
196
|
* Can be either a built FormConfiguration or a form builder instance
|
|
200
197
|
*/
|
|
201
|
-
formConfig: FormConfiguration | form
|
|
198
|
+
formConfig: FormConfiguration<any> | form<any>;
|
|
202
199
|
/**
|
|
203
200
|
* Whether users can skip this step
|
|
204
201
|
* @default false
|
|
@@ -307,6 +304,11 @@ interface WorkflowOptions {
|
|
|
307
304
|
* - Comprehensive statistics and analytics
|
|
308
305
|
* - Type-safe configuration management
|
|
309
306
|
*
|
|
307
|
+
* DX Notes:
|
|
308
|
+
* - Recommended: use the explicit factory `flow.create(rilConfig, id, name)`; we do not augment ril with `.flow()`.
|
|
309
|
+
* - Steps accept either a built `FormConfiguration` or a `form` builder; builders are built internally.
|
|
310
|
+
* - Use `when('path')...build()` for step-level conditions in `StepConditionalBehavior`.
|
|
311
|
+
*
|
|
310
312
|
* @example
|
|
311
313
|
* ```typescript
|
|
312
314
|
* const workflow = flow.create(rilConfig, 'user-onboarding', 'User Onboarding')
|
|
@@ -346,13 +348,15 @@ declare class flow {
|
|
|
346
348
|
* @param workflowName - Display name for the workflow
|
|
347
349
|
* @param description - Optional description of the workflow purpose
|
|
348
350
|
*/
|
|
349
|
-
constructor(config: ril
|
|
351
|
+
constructor(config: ril<any>, workflowId: string, workflowName: string, description?: string);
|
|
350
352
|
/**
|
|
351
353
|
* Static factory method to create a new workflow builder
|
|
352
354
|
*
|
|
353
355
|
* This is the preferred way to create workflow builders as it provides
|
|
354
356
|
* better type inference and follows the factory pattern.
|
|
355
357
|
*
|
|
358
|
+
* DX Note: Prefer using this factory over `new flow(...)` for clarity and consistency.
|
|
359
|
+
*
|
|
356
360
|
* @param config - The ril configuration instance
|
|
357
361
|
* @param workflowId - Unique identifier for the workflow
|
|
358
362
|
* @param workflowName - Display name for the workflow
|
|
@@ -364,7 +368,7 @@ declare class flow {
|
|
|
364
368
|
* const workflow = flow.create(rilConfig, 'checkout', 'Checkout Process');
|
|
365
369
|
* ```
|
|
366
370
|
*/
|
|
367
|
-
static create(config: ril
|
|
371
|
+
static create(config: ril<any>, workflowId: string, workflowName: string, description?: string): flow;
|
|
368
372
|
/**
|
|
369
373
|
* Helper method to create a step configuration from StepDefinition
|
|
370
374
|
*
|
|
@@ -687,51 +691,6 @@ declare class flow {
|
|
|
687
691
|
*/
|
|
688
692
|
fromJSON(json: any): this;
|
|
689
693
|
}
|
|
690
|
-
/**
|
|
691
|
-
* Factory function to create a workflow builder directly
|
|
692
|
-
*
|
|
693
|
-
* This is a convenience function that provides an alternative to using
|
|
694
|
-
* the class constructor or static create method. It's particularly useful
|
|
695
|
-
* for functional programming styles or when you prefer function calls
|
|
696
|
-
* over class instantiation.
|
|
697
|
-
*
|
|
698
|
-
* @param config - The ril configuration instance
|
|
699
|
-
* @param workflowId - Unique identifier for the workflow
|
|
700
|
-
* @param workflowName - Display name for the workflow
|
|
701
|
-
* @param description - Optional description of the workflow purpose
|
|
702
|
-
* @returns A new flow builder instance
|
|
703
|
-
*
|
|
704
|
-
* @example
|
|
705
|
-
* ```typescript
|
|
706
|
-
* const workflow = createFlow(rilConfig, 'onboarding', 'User Onboarding');
|
|
707
|
-
* ```
|
|
708
|
-
*/
|
|
709
|
-
declare function createFlow(config: ril, workflowId: string, workflowName: string, description?: string): flow;
|
|
710
|
-
/**
|
|
711
|
-
* Module augmentation to add createFlow method to ril instances
|
|
712
|
-
*
|
|
713
|
-
* This declaration extends the ril interface to include the createFlow
|
|
714
|
-
* method, allowing for a more integrated API experience where workflows
|
|
715
|
-
* can be created directly from ril configuration instances.
|
|
716
|
-
*/
|
|
717
|
-
declare module '@rilaykit/core' {
|
|
718
|
-
interface ril {
|
|
719
|
-
/**
|
|
720
|
-
* Creates a new workflow builder using this ril configuration
|
|
721
|
-
*
|
|
722
|
-
* @param workflowId - Unique identifier for the workflow
|
|
723
|
-
* @param workflowName - Display name for the workflow
|
|
724
|
-
* @param description - Optional description of the workflow purpose
|
|
725
|
-
* @returns A new flow builder instance
|
|
726
|
-
*
|
|
727
|
-
* @example
|
|
728
|
-
* ```typescript
|
|
729
|
-
* const workflow = rilConfig.createFlow('checkout', 'Checkout Process');
|
|
730
|
-
* ```
|
|
731
|
-
*/
|
|
732
|
-
flow(workflowId: string, workflowName: string, description?: string): flow;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
694
|
|
|
736
695
|
interface ConditionEvaluationResult {
|
|
737
696
|
visible: boolean;
|
|
@@ -898,6 +857,8 @@ interface UseWorkflowAnalyticsReturn {
|
|
|
898
857
|
analyticsStartTime: React.MutableRefObject<number>;
|
|
899
858
|
trackStepSkip: (stepId: string, reason: string) => void;
|
|
900
859
|
trackError: (error: Error) => void;
|
|
860
|
+
trackNavigation: (fromStep: number, toStep: number, duration: number) => void;
|
|
861
|
+
trackConditionEvaluation: (duration: number, conditionsCount: number) => void;
|
|
901
862
|
}
|
|
902
863
|
declare function useWorkflowAnalytics({ workflowConfig, workflowState, workflowContext, }: UseWorkflowAnalyticsProps): UseWorkflowAnalyticsReturn;
|
|
903
864
|
|
|
@@ -1001,7 +962,7 @@ interface WorkflowContextValue {
|
|
|
1001
962
|
persistenceError?: Error | null;
|
|
1002
963
|
}
|
|
1003
964
|
interface WorkflowProviderProps {
|
|
1004
|
-
children:
|
|
965
|
+
children: React$1.ReactNode;
|
|
1005
966
|
workflowConfig: WorkflowConfig;
|
|
1006
967
|
defaultValues?: Record<string, any>;
|
|
1007
968
|
onStepChange?: (fromStep: number, toStep: number, context: WorkflowContext) => void;
|
|
@@ -1012,7 +973,7 @@ declare function WorkflowProvider({ children, workflowConfig, defaultValues, onS
|
|
|
1012
973
|
declare function useWorkflowContext(): WorkflowContextValue;
|
|
1013
974
|
|
|
1014
975
|
type WorkflowProps = Omit<WorkflowProviderProps, 'children' | 'workflowConfig'> & {
|
|
1015
|
-
children:
|
|
976
|
+
children: React$1.ReactNode;
|
|
1016
977
|
workflowConfig: WorkflowConfig | flow;
|
|
1017
978
|
};
|
|
1018
979
|
/**
|
|
@@ -1025,13 +986,13 @@ declare function Workflow({ children, workflowConfig, ...props }: WorkflowProps)
|
|
|
1025
986
|
|
|
1026
987
|
interface WorkflowBodyProps {
|
|
1027
988
|
stepId?: string;
|
|
1028
|
-
children?: React.ReactNode;
|
|
989
|
+
children?: React$1.ReactNode;
|
|
1029
990
|
}
|
|
1030
991
|
/**
|
|
1031
992
|
* Renders the main content of the current workflow step.
|
|
1032
993
|
* Simple component that renders either the children or FormBody by default.
|
|
1033
994
|
*/
|
|
1034
|
-
declare
|
|
995
|
+
declare const WorkflowBody: React$1.NamedExoticComponent<WorkflowBodyProps>;
|
|
1035
996
|
|
|
1036
997
|
interface WorkflowNextButtonProps extends ComponentRendererBaseProps<WorkflowNextButtonRendererProps> {
|
|
1037
998
|
/**
|
|
@@ -1040,7 +1001,7 @@ interface WorkflowNextButtonProps extends ComponentRendererBaseProps<WorkflowNex
|
|
|
1040
1001
|
*/
|
|
1041
1002
|
isSubmitting?: boolean;
|
|
1042
1003
|
}
|
|
1043
|
-
declare
|
|
1004
|
+
declare const WorkflowNextButton: React$1.NamedExoticComponent<WorkflowNextButtonProps>;
|
|
1044
1005
|
|
|
1045
1006
|
interface WorkflowPreviousButtonProps extends ComponentRendererBaseProps<WorkflowPreviousButtonRendererProps> {
|
|
1046
1007
|
/**
|
|
@@ -1049,7 +1010,7 @@ interface WorkflowPreviousButtonProps extends ComponentRendererBaseProps<Workflo
|
|
|
1049
1010
|
*/
|
|
1050
1011
|
isSubmitting?: boolean;
|
|
1051
1012
|
}
|
|
1052
|
-
declare
|
|
1013
|
+
declare const WorkflowPreviousButton: React$1.NamedExoticComponent<WorkflowPreviousButtonProps>;
|
|
1053
1014
|
|
|
1054
1015
|
interface WorkflowSkipButtonProps extends ComponentRendererBaseProps<WorkflowSkipButtonRendererProps> {
|
|
1055
1016
|
/**
|
|
@@ -1058,12 +1019,12 @@ interface WorkflowSkipButtonProps extends ComponentRendererBaseProps<WorkflowSki
|
|
|
1058
1019
|
*/
|
|
1059
1020
|
isSubmitting?: boolean;
|
|
1060
1021
|
}
|
|
1061
|
-
declare
|
|
1022
|
+
declare const WorkflowSkipButton: React$1.NamedExoticComponent<WorkflowSkipButtonProps>;
|
|
1062
1023
|
|
|
1063
1024
|
interface WorkflowStepperProps extends ComponentRendererBaseProps<WorkflowStepperRendererProps> {
|
|
1064
1025
|
onStepClick?: (stepIndex: number) => void;
|
|
1065
1026
|
}
|
|
1066
|
-
declare
|
|
1027
|
+
declare const WorkflowStepper: React$1.NamedExoticComponent<WorkflowStepperProps>;
|
|
1067
1028
|
|
|
1068
1029
|
/**
|
|
1069
1030
|
* @fileoverview LocalStorage persistence adapter for Rilay workflows
|
|
@@ -1251,4 +1212,4 @@ declare class RilayLicenseManager {
|
|
|
1251
1212
|
}>;
|
|
1252
1213
|
}
|
|
1253
1214
|
|
|
1254
|
-
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,
|
|
1215
|
+
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, debounce, flow, generateStorageKey, mergePersistedState, persistedToWorkflowState, useConditionEvaluation, usePersistence, useStepMetadata, useWorkflowAnalytics, useWorkflowConditions, useWorkflowContext, useWorkflowNavigation, useWorkflowState, useWorkflowSubmission, validatePersistedData, workflowStateToPersisted };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var core=require('@rilaykit/core'),forms=require('@rilaykit/forms'),react=require('react'),ge=require('@noble/ed25519'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ge__namespace=/*#__PURE__*/_interopNamespace(ge);var L=class r{constructor(e,t,i,n){this.steps=[];this.plugins=[];this.idGenerator=new core.IdGenerator;this.config=e,this.workflowId=t,this.workflowName=i,this.workflowDescription=n;}static create(e,t,i,n){return new r(e,t,i,n)}createStepFromDefinition(e){return {id:e.id||this.idGenerator.next("step"),title:e.title,description:e.description,formConfig:e.formConfig instanceof forms.form?e.formConfig.build():e.formConfig,allowSkip:e.allowSkip||false,renderer:e.renderer,conditions:e.conditions,metadata:e.metadata,onAfterValidation:e.onAfterValidation}}addStep(e){let t=core.normalizeToArray(e);for(let i of t){let n=this.createStepFromDefinition(i);this.steps.push(n);}return this}configure(e){return e.analytics&&(this.analytics=e.analytics),e.persistence&&(this.persistenceConfig=e.persistence),this}use(e){this.validatePluginDependencies(e),this.plugins.push(e);try{e.install(this);}catch(t){throw new Error(`Failed to install plugin "${e.name}": ${t instanceof Error?t.message:String(t)}`)}return this}validatePluginDependencies(e){if(!e.dependencies)return;let t=e.dependencies.filter(i=>!this.plugins.some(n=>n.name===i));if(t.length>0)throw new Error(`Plugin "${e.name}" requires missing dependencies: ${t.join(", ")}`)}removePlugin(e){return this.plugins=this.plugins.filter(t=>t.name!==e),this}updateStep(e,t){let i=this.steps.findIndex(n=>n.id===e);if(i===-1)throw new Error(`Step with ID "${e}" not found`);return this.steps[i]={...this.steps[i],...t},this}addStepConditions(e,t){let i=this.steps.findIndex(o=>o.id===e);if(i===-1)throw new Error(`Step with ID "${e}" not found`);let n={...this.steps[i].conditions,...t};return this.steps[i]={...this.steps[i],conditions:n},this}removeStep(e){return this.steps=this.steps.filter(t=>t.id!==e),this}getStep(e){return this.steps.find(t=>t.id===e)}getSteps(){return [...this.steps]}clearSteps(){return this.steps=[],this.idGenerator.reset(),this}clone(e,t){let i=new r(this.config,e||`${this.workflowId}-clone`,t||this.workflowName);return i.steps=core.deepClone(this.steps),i.analytics=this.analytics?core.deepClone(this.analytics):void 0,i.persistenceConfig=this.persistenceConfig?core.deepClone(this.persistenceConfig):void 0,i.plugins=[...this.plugins],i}validate(){let e=[];this.steps.length===0&&e.push("Workflow must have at least one step");let t=this.steps.map(i=>i.id);try{core.ensureUnique(t,"step");}catch(i){e.push(i instanceof Error?i.message:String(i));}for(let i of this.plugins)if(i.dependencies){let n=i.dependencies.filter(o=>!this.plugins.some(s=>s.name===o));n.length>0&&e.push(`Plugin "${i.name}" requires missing dependencies: ${n.join(", ")}`);}return e}getStats(){let e=this.steps.reduce((i,n)=>i+n.formConfig.allFields.length,0),t=this.steps.map(i=>i.formConfig.allFields.length);return {totalSteps:this.steps.length,totalFields:e,averageFieldsPerStep:this.steps.length>0?e/this.steps.length:0,maxFieldsInStep:t.length>0?Math.max(...t):0,minFieldsInStep:t.length>0?Math.min(...t):0,hasAnalytics:!!this.analytics}}build(){let e=this.validate();if(e.length>0)throw new Error(`Workflow validation failed: ${e.join(", ")}`);return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins,renderConfig:this.config.getWorkflowRenderConfig()}}toJSON(){return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins.map(e=>({name:e.name,version:e.version}))}}fromJSON(e){return this.workflowId=e.workflowId,this.workflowName=e.workflowName,this.workflowDescription=e.workflowDescription,this.steps=e.steps,this.analytics=e.analytics,this.persistenceConfig=e.persistence,this.plugins=e.plugins||[],this}};function Be(r,e,t,i){return L.create(r,e,t,i)}core.ril.prototype.flow=function(r,e,t){return L.create(this,r,e,t)};var Me=1751361139160,Oe="8fdb6a454550326d331c3b3d1d1f8c707a371bdb6c7ea72a0a1e4ea6f1822620",k=class k{static async setLicenseKey(e){k.licenseKey=e||"",k.licenseKey?k.licenseResult=await k.validateLicense():k.licenseResult={valid:false,error:"MISSING"},k.isInitialized=true;}static async validateLicense(){if(!k.licenseKey)return {valid:false,error:"MISSING"};try{if(!k.licenseKey.startsWith("ril_"))return {valid:!1,error:"FORMAT_INVALID"};let e=k.licenseKey.slice(4),i=k.base64ToString(e).split(".");if(i.length!==3)return {valid:!1,error:"FORMAT_INVALID"};let[n,o,s]=i,p=`${n}.${o}`,g=new TextEncoder().encode(p),a=s.match(/.{2}/g);if(!a)return {valid:!1,error:"INVALID"};let l=new Uint8Array(a.map(W=>Number.parseInt(W,16))),f=k.hexToBytes(Oe);if(!await ge__namespace.verify(l,g,f))return {valid:!1,error:"SIGNATURE_INVALID"};let y=k.base64ToString(o.replace(/-/g,"+").replace(/_/g,"/")),c=JSON.parse(y),d=Math.floor(Date.now()/1e3);return c.e<d?{valid:!1,error:"EXPIRED",data:k.decompressPayload(c)}:Me>c.e*1e3?{valid:!1,error:"EXPIRED",data:k.decompressPayload(c)}:c.p===void 0||!c.c||!c.i||!c.e||!c.t?{valid:!1,error:"INVALID"}:{valid:!0,data:k.decompressPayload(c)}}catch{return {valid:false,error:"INVALID"}}}static decompressPayload(e){return {plan:{0:"ARCHITECT",1:"FOUNDRY"}[e.p]||"ARCHITECT",company:e.c,customerId:e.i.toString(),expiry:e.e*1e3,iat:e.t*1e3}}static hexToBytes(e){let t=new Uint8Array(e.length/2);for(let i=0;i<e.length;i+=2)t[i/2]=Number.parseInt(e.substring(i,i+2),16);return t}static base64ToString(e){if(typeof atob<"u")return atob(e);if(typeof Buffer<"u")return Buffer.from(e,"base64").toString();let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i="",n=0,o=e.replace(/[^A-Za-z0-9+/]/g,"");for(;n<o.length;){let s=t.indexOf(o.charAt(n++)),p=t.indexOf(o.charAt(n++)),g=t.indexOf(o.charAt(n++)),a=t.indexOf(o.charAt(n++)),l=s<<18|p<<12|g<<6|a;i+=String.fromCharCode(l>>16&255),g!==64&&(i+=String.fromCharCode(l>>8&255)),a!==64&&(i+=String.fromCharCode(l&255));}return i}static getLicenseResult(){return k.isInitialized?k.licenseResult?k.licenseResult:{valid:false,error:"MISSING"}:{valid:false,error:"MISSING"}}static shouldDisplayWatermark(){return typeof window>"u"?false:!k.getLicenseResult().valid}static getWatermarkMessage(){let e=k.getLicenseResult();return {MISSING:"Rilay Workflow - For Trial Use Only",EXPIRED:"Rilay Workflow - License Expired",INVALID:"Rilay Workflow - Invalid License",FORMAT_INVALID:"Rilay Workflow - Invalid License Format",SIGNATURE_INVALID:"Rilay Workflow - Invalid License Signature"}[e.error||"MISSING"]||""}static logLicenseStatus(){let e=k.getLicenseResult();if(e.valid)return;let i={MISSING:"\u{1F527} Rilay Workflow - Trial Mode. Purchase a license at https://rilay.io/pricing",EXPIRED:"\u26A0\uFE0F Rilay Workflow - License Expired. Please renew your license.",INVALID:"\u274C Rilay Workflow - Invalid License. Please check your license key.",FORMAT_INVALID:"\u274C Rilay Workflow - Invalid License Format. Please check your license key.",SIGNATURE_INVALID:"\u274C Rilay Workflow - Invalid License Signature. Please check your license key."}[e.error||"MISSING"];console.warn(`%c${i}`,"color: #f59e0b; font-weight: bold;");}static async getLicenseInfo(){let e=k.getLicenseResult();return !e.valid||!e.data?{}:{plan:e.data.plan,company:e.data.company,expiryDate:new Date(e.data.expiry).toLocaleDateString()}}};k.licenseKey="",k.licenseResult=null,k.isInitialized=false;var B=k;function Z(r,e={},t={}){return react.useMemo(()=>{if(!r)return {visible:t.visible??true,disabled:t.disabled??false,required:t.required??false,readonly:t.readonly??false};let i=n=>{try{let o;return n&&typeof n=="object"&&"build"in n?o=n.build():o=n,core.evaluateCondition(o,e)}catch(o){return console.warn("Error evaluating condition:",o),false}};return {visible:r.visible?i(r.visible):true,disabled:r.disabled?i(r.disabled):false,required:r.required?i(r.required):false,readonly:r.readonly?i(r.readonly):false}},[r,e,t])}function ye(r,e={}){return react.useMemo(()=>{let t={};for(let[i,n]of Object.entries(r))if(t[i]={visible:true,disabled:false,required:false,readonly:false},n){let o=s=>{try{return s&&typeof s=="object"&&"build"in s?core.evaluateCondition(s.build(),e):core.evaluateCondition(s,e)}catch(p){return console.warn(`Error evaluating condition for field ${i}:`,p),false}};t[i]={visible:n.visible?o(n.visible):true,disabled:n.disabled?o(n.disabled):false,required:n.required?o(n.required):false,readonly:n.readonly?o(n.readonly):false};}return t},[r,e])}function be(r,e={}){return react.useMemo(()=>{let t={};for(let[i,n]of Object.entries(r)){let o=Number.parseInt(i,10);if(t[o]={visible:true,disabled:false,required:false,readonly:false},n){let s=p=>{try{return p&&typeof p=="object"&&"build"in p?core.evaluateCondition(p.build(),e):core.evaluateCondition(p,e)}catch(g){return console.warn(`Error evaluating condition for step ${o}:`,g),false}};t[o]={visible:n.visible?s(n.visible):true,disabled:n.disabled?s(n.disabled):false,required:n.required?s(n.required):false,readonly:n.readonly?s(n.readonly):false};}}return t},[r,e])}var w=class extends Error{constructor(t,i,n){super(`[WorkflowPersistence] ${t} (Code: ${i})`);this.code=i;this.cause=n;this.name="WorkflowPersistenceError";}};function Y(r,e,t){return {workflowId:r,currentStepIndex:e.currentStepIndex,allData:{...e.allData},stepData:{...e.stepData},visitedSteps:Array.from(e.visitedSteps),lastSaved:Date.now(),metadata:t}}function he(r){return {currentStepIndex:r.currentStepIndex,allData:{...r.allData},stepData:{...r.stepData},visitedSteps:new Set(r.visitedSteps),isSubmitting:false,isTransitioning:false}}function Ve(r){if(!r||typeof r!="object")return false;let e=["workflowId","currentStepIndex","allData","stepData","visitedSteps","lastSaved"];for(let t of e)if(!(t in r))return false;return !(typeof r.workflowId!="string"||typeof r.currentStepIndex!="number"||typeof r.allData!="object"||typeof r.stepData!="object"||!Array.isArray(r.visitedSteps)||typeof r.lastSaved!="number")}function Q(r,e){return e?`${e}:${r}`:r}function j(r,e){let t=null;return (...i)=>{t&&clearTimeout(t),t=setTimeout(()=>{r(...i);},e);}}function _e(r,e,t="persist"){let i=he(e);switch(t){case "persist":return {...i,isSubmitting:r.isSubmitting,isTransitioning:r.isTransitioning};case "current":return {...r,visitedSteps:new Set([...r.visitedSteps,...i.visitedSteps])};case "merge":return {currentStepIndex:r.currentStepIndex,allData:{...i.allData,...r.allData},stepData:{...i.stepData,...r.stepData},visitedSteps:new Set([...i.visitedSteps,...r.visitedSteps]),isSubmitting:r.isSubmitting,isTransitioning:r.isTransitioning};default:return i}}function q({workflowId:r,workflowState:e,adapter:t,options:i={},userId:n}){let[o,s]=react.useState(false),[p,g]=react.useState(null),[a,l]=react.useState(false),f=react.useRef(t),v=react.useRef(i),y=react.useRef({hasPendingChanges:false});react.useEffect(()=>{f.current=t,v.current=i;},[t,i]);let c=Q(v.current.storageKey||r,n),d=react.useCallback(()=>{g(null);},[]),P=react.useCallback((S,x)=>{let C=S instanceof w?S:new w(`${x} failed: ${S.message}`,"OPERATION_FAILED",S);g(C),console.error("[WorkflowPersistence]",C);},[]),W=react.useCallback(async S=>{d(),s(true);try{let x=Y(r,S,v.current.metadata);await f.current.save(c,x),y.current.lastSavedState={...S},y.current.hasPendingChanges=!1;}catch(x){throw P(x,"Save"),x}finally{s(false);}},[r,c,d,P]),m=react.useRef(j(async S=>{try{await W(S);}catch(x){console.debug("[WorkflowPersistence] Auto-save failed:",x);}},i.debounceMs||500)),h=react.useCallback((S,x)=>x?S.currentStepIndex!==x.currentStepIndex||JSON.stringify(S.allData)!==JSON.stringify(x.allData)||JSON.stringify(S.stepData)!==JSON.stringify(x.stepData)||S.visitedSteps.size!==x.visitedSteps.size||!Array.from(S.visitedSteps).every(C=>x.visitedSteps.has(C)):true,[]),I=react.useCallback(async()=>{d(),l(true);try{let S=await f.current.load(c);return S&&(y.current.lastSavedState={currentStepIndex:S.currentStepIndex,allData:S.allData,stepData:S.stepData,visitedSteps:new Set(S.visitedSteps),isSubmitting:!1,isTransitioning:!1,isInitializing:!1},y.current.hasPendingChanges=!1),S}catch(S){return P(S,"Load"),null}finally{setTimeout(()=>l(false),100);}},[c,d,P]),R=react.useCallback(async()=>{d();try{await f.current.remove(c),y.current.lastSavedState=void 0,y.current.hasPendingChanges=!1;}catch(S){throw P(S,"Clear"),S}},[c,d,P]),u=react.useCallback(async()=>{try{return await f.current.exists(c)}catch(S){return P(S,"Exists check"),false}},[c,P]);react.useEffect(()=>{v.current.autoPersist&&(o||a||e.isInitializing||e.isSubmitting||e.isTransitioning||h(e,y.current.lastSavedState)&&(y.current.hasPendingChanges=true,m.current(e)));},[e,o,a,h]);let b=react.useCallback(async()=>{await W(e);},[W,e]);return {isPersisting:o,persistenceError:p,persistNow:b,loadPersistedData:I,clearPersistedData:R,hasPersistedData:u}}function Ue(){let{workflowConfig:r,currentStep:e}=D(),t=react.useMemo(()=>e?.metadata,[e?.metadata]),i=react.useMemo(()=>a=>r.steps.find(f=>f.id===a)?.metadata,[r.steps]),n=react.useMemo(()=>a=>r.steps[a]?.metadata,[r.steps]),o=react.useMemo(()=>a=>t?a in t:false,[t]),s=react.useMemo(()=>(a,l)=>t&&a in t?t[a]:l,[t]),p=react.useMemo(()=>()=>r.steps.map((a,l)=>({id:a.id,title:a.title,index:l,metadata:a.metadata})),[r.steps]),g=react.useMemo(()=>a=>r.steps.map((l,f)=>({step:l,index:f})).filter(({step:l,index:f})=>a(l.metadata,l.id,f)).map(({step:l})=>l.id),[r.steps]);return {current:t,getByStepId:i,getByStepIndex:n,hasCurrentKey:o,getCurrentValue:s,getAllStepsMetadata:p,findStepsByMetadata:g}}function te({workflowConfig:r,workflowState:e,workflowContext:t}){let i=react.useRef(Date.now()),n=react.useRef(new Map),o=react.useRef(false),s=react.useRef(null);react.useEffect(()=>{r.analytics?.onWorkflowStart&&!o.current&&(o.current=true,r.analytics.onWorkflowStart(r.id,t));},[r.id,r.analytics,t]),react.useEffect(()=>{let a=r.steps[e.currentStepIndex];if(a&&s.current!==a.id){if(s.current&&r.analytics?.onStepComplete){let l=n.current.get(s.current);l&&r.analytics.onStepComplete(s.current,Date.now()-l,e.stepData,t);}s.current=a.id,n.current.set(a.id,Date.now()),r.analytics?.onStepStart&&r.analytics.onStepStart(a.id,Date.now(),t);}},[e.currentStepIndex,r.steps,r.analytics,t,e.stepData]);let p=react.useCallback((a,l)=>{r.analytics?.onStepSkip&&r.analytics.onStepSkip(a,l,t);},[r.analytics,t]),g=react.useCallback(a=>{r.analytics?.onError&&r.analytics.onError(a,t);},[r.analytics,t]);return {analyticsStartTime:i,trackStepSkip:p,trackError:g}}function xe(r,e){return {visible:r.visible,skippable:e===true||r.required}}function re({workflowConfig:r,workflowState:e,currentStep:t}){let i=react.useMemo(()=>({...e.allData,...e.stepData}),[e.allData,e.stepData]),n=react.useMemo(()=>{if(t?.conditions)return {visible:t.conditions.visible,required:t.conditions.skippable}},[t?.conditions]),o=Z(n,i,{visible:true,disabled:false,required:false,readonly:false}),s=react.useMemo(()=>xe(o,t?.allowSkip),[o,t?.allowSkip]),p=react.useMemo(()=>{let m={};return r.steps.forEach((h,I)=>{h.conditions&&(m[I]={visible:h.conditions.visible,required:h.conditions.skippable});}),m},[r.steps]),g=be(p,i),a=react.useMemo(()=>{let m={};return r.steps.forEach((h,I)=>{let R=g[I];R?m[I]=xe(R,h.allowSkip):m[I]={visible:true,skippable:h.allowSkip===true};}),m},[r.steps,g]),l=react.useMemo(()=>{if(!t?.formConfig?.allFields)return {};let m={};for(let h of t.formConfig.allFields)h.conditions&&(m[h.id]=h.conditions);return m},[t?.formConfig?.allFields]),f=ye(l,i),v=react.useCallback(m=>m<0||m>=r.steps.length?false:a[m]?.visible??true,[a,r.steps.length]),y=react.useCallback(m=>m<0||m>=r.steps.length?false:a[m]?.skippable??false,[a,r.steps.length]),c=react.useCallback(m=>f[m]?.visible??true,[f]),d=react.useCallback(m=>f[m]?.disabled??false,[f]),P=react.useCallback(m=>f[m]?.required??false,[f]),W=react.useCallback(m=>f[m]?.readonly??false,[f]);return {stepConditions:s,fieldConditions:f,allStepConditions:a,isStepVisible:v,isStepSkippable:y,isFieldVisible:c,isFieldDisabled:d,isFieldRequired:P,isFieldReadonly:W}}function ie({workflowConfig:r,workflowState:e,workflowContext:t,conditionsHelpers:i,setCurrentStep:n,setTransitioning:o,markStepVisited:s,setStepData:p,onStepChange:g}){let a=react.useRef(g);a.current=g;let l=r.steps[e.currentStepIndex],f=react.useCallback(()=>({setStepData:(u,b)=>{p(b,u);},setStepFields:(u,b)=>{let x={...e.allData[u]||{},...b};p(x,u);},getStepData:u=>e.allData[u]||{},setNextStepField:(u,b)=>{let S=e.currentStepIndex+1;if(S<r.steps.length){let x=r.steps[S].id,_={...e.allData[x]||{},[u]:b};p(_,x);}},setNextStepFields:u=>{let b=e.currentStepIndex+1;if(b<r.steps.length){let S=r.steps[b].id,C={...e.allData[S]||{},...u};p(C,S);}},getAllData:()=>({...e.allData}),getSteps:()=>[...r.steps]}),[e.allData,e.currentStepIndex,r.steps,p]),v=react.useCallback(async u=>{if(u<0||u>=r.steps.length||!i.isStepVisible(u))return false;o(true);try{return a.current&&a.current(e.currentStepIndex,u,t),n(u),s(u,r.steps[u].id),!0}catch(b){return console.error("Step transition failed:",b),r.analytics?.onError&&r.analytics.onError(b,t),false}finally{o(false);}},[r.steps,r.analytics,i,e.currentStepIndex,t,o,n,s]),y=react.useCallback(u=>{for(let b=u+1;b<r.steps.length;b++)if(i.isStepVisible(b))return b;return null},[r.steps.length,i]),c=react.useCallback(u=>{for(let b=u-1;b>=0;b--)if(i.isStepVisible(b))return b;return null},[i]),d=react.useCallback(async()=>{if(l?.onAfterValidation)try{let b=f();await l.onAfterValidation(e.stepData,b,t);}catch(b){return console.error("onAfterValidation failed:",b),r.analytics?.onError&&r.analytics.onError(b,t),false}let u=y(e.currentStepIndex);return u===null?false:v(u)},[l,f,e.stepData,t,r.analytics,e.currentStepIndex,y,v]),P=react.useCallback(async()=>{let u=c(e.currentStepIndex);return u===null?false:v(u)},[e.currentStepIndex,c,v]),W=react.useCallback(async()=>!l?.allowSkip&&!i.isStepSkippable(e.currentStepIndex)?false:(r.analytics?.onStepSkip&&r.analytics.onStepSkip(l.id,"user_skip",t),d()),[l,i,e.currentStepIndex,r.analytics,t,d]),m=react.useCallback(u=>u<0||u>=r.steps.length?false:i.isStepVisible(u),[r.steps.length,i]),h=react.useCallback(()=>{let u=y(e.currentStepIndex);return u!==null&&m(u)},[e.currentStepIndex,y,m]),I=react.useCallback(()=>{let u=c(e.currentStepIndex);return u!==null&&m(u)},[e.currentStepIndex,c,m]),R=react.useCallback(()=>l?.allowSkip===true&&i.isStepSkippable(e.currentStepIndex),[l?.allowSkip,i,e.currentStepIndex]);return {goToStep:v,goNext:d,goPrevious:P,skipStep:W,canGoToStep:m,canGoNext:h,canGoPrevious:I,canSkipCurrentStep:R}}function qe(r,e){switch(e.type){case "SET_CURRENT_STEP":return {...r,currentStepIndex:e.stepIndex};case "SET_STEP_DATA":return {...r,stepData:e.data,allData:{...r.allData,[e.stepId]:e.data}};case "SET_ALL_DATA":return {...r,allData:e.data};case "SET_FIELD_VALUE":{let t={...r.stepData,[e.fieldId]:e.value};return {...r,stepData:t,allData:{...r.allData,[e.stepId]:t}}}case "SET_SUBMITTING":return {...r,isSubmitting:e.isSubmitting};case "SET_TRANSITIONING":return {...r,isTransitioning:e.isTransitioning};case "MARK_STEP_VISITED":return {...r,visitedSteps:new Set([...r.visitedSteps,e.stepId])};case "RESET_WORKFLOW":return {currentStepIndex:0,allData:{},stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:false};case "LOAD_PERSISTED_STATE":return {...r,...e.state};case "SET_INITIALIZATION_COMPLETE":return {...r,isInitializing:false};default:return r}}function ne({defaultValues:r={},persistence:e}){let t={currentStepIndex:0,allData:r,stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:true},[i,n]=react.useReducer(qe,t),o=e?.adapter?q({workflowId:e.workflowId,workflowState:i,adapter:e.adapter,options:e.options,userId:e.userId}):null,s=react.useCallback(d=>{n({type:"SET_CURRENT_STEP",stepIndex:d});},[]),p=react.useCallback((d,P)=>{n({type:"SET_STEP_DATA",data:d,stepId:P});},[]),g=react.useCallback((d,P,W)=>{n({type:"SET_FIELD_VALUE",fieldId:d,value:P,stepId:W});},[]),a=react.useCallback(d=>{n({type:"SET_SUBMITTING",isSubmitting:d});},[]),l=react.useCallback(d=>{n({type:"SET_TRANSITIONING",isTransitioning:d});},[]),f=react.useCallback((d,P)=>{n({type:"MARK_STEP_VISITED",stepIndex:d,stepId:P});},[]),v=react.useCallback(()=>{n({type:"RESET_WORKFLOW"});},[]),y=react.useCallback(()=>{n({type:"SET_INITIALIZATION_COMPLETE"});},[]),c=react.useCallback(async()=>{if(!o)return y(),false;try{let d=await o.loadPersistedData();if(d){let P={currentStepIndex:d.currentStepIndex,allData:d.allData,stepData:d.stepData,visitedSteps:new Set(d.visitedSteps)};return n({type:"LOAD_PERSISTED_STATE",state:P}),y(),!0}}catch(d){console.error("Failed to load persisted state:",d);}return y(),false},[o,y]);return {workflowState:i,setCurrentStep:s,setStepData:p,setFieldValue:g,setSubmitting:a,setTransitioning:l,markStepVisited:f,resetWorkflow:v,loadPersistedState:c,persistence:o?{isPersisting:o.isPersisting,persistenceError:o.persistenceError,persistNow:o.persistNow,clearPersistedData:o.clearPersistedData,hasPersistedData:o.hasPersistedData}:null}}function oe({workflowConfig:r,workflowState:e,workflowContext:t,setSubmitting:i,onWorkflowComplete:n,analyticsStartTime:o}){let s=react.useRef(n);s.current=n;let p=react.useCallback(async()=>{i(true);try{if(s.current&&await s.current(e.allData),r.analytics?.onWorkflowComplete){let a=Date.now()-o.current;r.analytics.onWorkflowComplete(r.id,a,e.allData);}}catch(a){throw console.error("Workflow submission failed:",a),r.analytics?.onError&&r.analytics.onError(a,t),a}finally{i(false);}},[e.allData,r.analytics,r.id,t,o,i]),g=react.useCallback(()=>e.isSubmitting?false:e.currentStepIndex===r.steps.length-1,[e.isSubmitting,e.currentStepIndex,r.steps.length]);return {submitWorkflow:p,isSubmitting:e.isSubmitting,canSubmit:g()}}var De=react.createContext(null);function ae({children:r,workflowConfig:e,defaultValues:t={},onStepChange:i,onWorkflowComplete:n,className:o}){let{workflowState:s,setCurrentStep:p,setStepData:g,setFieldValue:a,setSubmitting:l,setTransitioning:f,markStepVisited:v,resetWorkflow:y,loadPersistedState:c,persistence:d}=ne({defaultValues:t,persistence:e.persistence?{workflowId:e.id,adapter:e.persistence.adapter,options:e.persistence.options,userId:e.persistence.userId}:void 0});react.useEffect(()=>{e.persistence&&c&&c();},[]);let P=d?.isPersisting??false,W=d?.persistenceError??null,m=d?.persistNow,h=react.useMemo(()=>({workflowId:e.id,currentStepIndex:s.currentStepIndex,totalSteps:e.steps.length,allData:s.allData,stepData:s.stepData,isFirstStep:s.currentStepIndex===0,isLastStep:s.currentStepIndex===e.steps.length-1,visitedSteps:s.visitedSteps}),[e.id,e.steps.length,s.currentStepIndex,s.allData,s.stepData,s.visitedSteps]),I=react.useMemo(()=>e.steps[s.currentStepIndex],[e.steps,s.currentStepIndex]),R=react.useMemo(()=>I?.formConfig,[I]),{analyticsStartTime:u}=te({workflowConfig:e,workflowState:s,workflowContext:h}),b=re({workflowConfig:e,workflowState:s,currentStep:I}),{goToStep:S,goNext:x,goPrevious:C,skipStep:_,canGoToStep:pe,canGoNext:ce,canGoPrevious:de,canSkipCurrentStep:ue}=ie({workflowConfig:e,workflowState:s,workflowContext:h,conditionsHelpers:b,setCurrentStep:p,setTransitioning:f,markStepVisited:v,setStepData:g,onStepChange:i});react.useEffect(()=>{if(!b.isStepVisible(s.currentStepIndex)){for(let A=0;A<e.steps.length;A++)if(b.isStepVisible(A)){p(A),v(A,e.steps[A].id);break}}},[b,s.currentStepIndex,e.steps,p,v]);let{submitWorkflow:U,isSubmitting:fe,canSubmit:me}=oe({workflowConfig:e,workflowState:s,workflowContext:h,setSubmitting:l,onWorkflowComplete:n,analyticsStartTime:u}),J=react.useCallback((K,A)=>{a(K,A,I?.id||"");},[a,I?.id]),Se=react.useCallback(K=>{g(K,I?.id||"");},[g,I?.id]),Re=react.useCallback(async()=>{h.isLastStep?await U():await x();},[h.isLastStep,U,x]),Ce=react.useMemo(()=>({workflowState:s,workflowConfig:e,currentStep:I,context:h,formConfig:R,conditionsHelpers:b,currentStepMetadata:I?.metadata,goToStep:S,goNext:x,goPrevious:C,skipStep:_,canGoToStep:pe,canGoNext:ce,canGoPrevious:de,canSkipCurrentStep:ue,setValue:J,setStepData:Se,resetWorkflow:y,submitWorkflow:U,isSubmitting:fe,canSubmit:me,persistNow:m,isPersisting:P,persistenceError:W}),[s,e,I,h,R,b,S,x,C,_,pe,ce,de,ue,J,Se,y,U,fe,me,m,P,W]);return jsxRuntime.jsx(De.Provider,{value:Ce,children:jsxRuntime.jsx(forms.FormProvider,{formConfig:R,defaultValues:s?.allData[I?.id]||{},onFieldChange:J,"data-workflow-id":e.id,className:o,onSubmit:Re,children:r},s.isInitializing.toString())})}function D(){let r=react.useContext(De);if(!r)throw new Error("useWorkflowContext must be used within a WorkflowProvider");return r}function Qe({children:r,workflowConfig:e,...t}){let[i,n]=react.useState(),o=react.useMemo(()=>e instanceof L?e.build():e,[e]);return react.useEffect(()=>{if(typeof window<"u"&&B.shouldDisplayWatermark()){let p=B.getWatermarkMessage();n(p);}},[]),jsxRuntime.jsxs("div",{style:{position:"relative"},children:[jsxRuntime.jsx(ae,{...t,workflowConfig:o,children:r}),i&&jsxRuntime.jsx("div",{style:{position:"absolute",top:"10px",right:"10px",background:"rgba(0, 0, 0, 0.8)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",zIndex:1e3,pointerEvents:"none",opacity:.7},children:i})]})}function tt({stepId:r,children:e}){let{currentStep:t}=D();if(!t||r&&t.id!==r)return null;let{formConfig:i,renderer:n}=t;return i?n?n(t):e??jsxRuntime.jsx(forms.FormBody,{}):null}function ot({className:r,isSubmitting:e,...t}){let{context:i,workflowState:n,workflowConfig:o,currentStep:s}=D(),{submit:p,formState:g}=forms.useFormContext(),a=g.isSubmitting||n.isSubmitting,l=e??a,f=!n.isTransitioning&&!l,v=async c=>{c?.preventDefault(),f&&await p(c);},y={isLastStep:i.isLastStep,canGoNext:f,isSubmitting:l,onSubmit:v,className:r,currentStep:s,stepData:g.values||{},allData:i.allData,context:i};return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowNextButton",renderer:o.renderConfig?.nextButtonRenderer,props:y,...t})}function pt({className:r,isSubmitting:e,...t}){let{context:i,goPrevious:n,workflowState:o,workflowConfig:s,currentStep:p}=D(),{formState:g}=forms.useFormContext(),a=g.isSubmitting||o.isSubmitting,l=e??a,f=i.currentStepIndex>0&&!o.isTransitioning&&!l,y={canGoPrevious:f,isSubmitting:l,onPrevious:async c=>{c?.preventDefault(),f&&await n();},className:r,currentStep:p,stepData:g.values||{},allData:i.allData,context:i};return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowPreviousButton",renderer:s.renderConfig?.previousButtonRenderer,props:y,...t})}function ft({className:r,isSubmitting:e,...t}){let{currentStep:i,skipStep:n,workflowState:o,workflowConfig:s,context:p,conditionsHelpers:g}=D(),{formState:a}=forms.useFormContext(),l=a.isSubmitting||o.isSubmitting,f=e??l,v=(!!i?.allowSkip||g.isStepSkippable(o.currentStepIndex))&&!o.isTransitioning&&!f,c={canSkip:v,isSubmitting:f,onSkip:async d=>{d?.preventDefault(),v&&await n();},className:r,currentStep:i,stepData:a.values||{},allData:p.allData,context:p};return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowSkipButton",renderer:s.renderConfig?.skipButtonRenderer,props:c,...t})}function yt({onStepClick:r,className:e,...t}){let{workflowConfig:i,workflowState:n,goToStep:o,conditionsHelpers:s}=D(),{visibleSteps:p,visibleToOriginalIndexMap:g,originalToVisibleIndexMap:a}=react.useMemo(()=>{let y=[],c=new Map,d=new Map;return i.steps.forEach((P,W)=>{if(s.isStepVisible(W)){let m=y.length;y.push(P),c.set(m,W),d.set(W,m);}}),{visibleSteps:y,visibleToOriginalIndexMap:c,originalToVisibleIndexMap:d}},[i.steps,s]),l=y=>{let c=g.get(y);c!==void 0&&(r?r(c):o(c));},f=a.get(n.currentStepIndex)??-1,v={steps:p,currentStepIndex:f,visitedSteps:n.visitedSteps,onStepClick:l,className:e};return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowStepper",renderer:i.renderConfig?.stepperRenderer,props:v,...t})}var le=class{constructor(e={}){this.version="1.0.0";this.keyPrefix=e.keyPrefix??"rilay_workflow_",this.compress=e.compress??false,this.maxAge=e.maxAge,this._isAvailable=this.isLocalStorageAvailable();}async save(e,t){if(this._isAvailable)try{let i=this.getStorageKey(e),n={data:{...t,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},o=JSON.stringify(n),s=this.compress?this.compressData(o):o;localStorage.setItem(i,s);}catch(i){if(i instanceof Error)if(i.name==="QuotaExceededError"||i.message.includes("quota")){await this.clearExpiredData();try{let n=this.getStorageKey(e),o={data:{...t,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},s=JSON.stringify(o),p=this.compress?this.compressData(s):s;localStorage.setItem(n,p);}catch(n){throw new w("localStorage quota exceeded and cleanup failed","QUOTA_EXCEEDED",n)}}else throw new w(`Failed to save to localStorage: ${i.message}`,"SAVE_FAILED",i);else throw new w("Unknown error occurred while saving","SAVE_FAILED")}}async load(e){if(!this._isAvailable)return null;try{let t=this.getStorageKey(e),i=localStorage.getItem(t);if(!i)return null;let n=this.compress?this.decompressData(i):i,o=JSON.parse(n);return o.expiresAt&&Date.now()>o.expiresAt?(await this.remove(e),null):{...o.data,visitedSteps:Array.isArray(o.data.visitedSteps)?o.data.visitedSteps:[]}}catch(t){throw t instanceof Error?new w(`Failed to load from localStorage: ${t.message}`,"LOAD_FAILED",t):new w("Unknown error occurred while loading","LOAD_FAILED")}}async remove(e){if(this._isAvailable)try{let t=this.getStorageKey(e);localStorage.removeItem(t);}catch(t){throw t instanceof Error?new w(`Failed to remove from localStorage: ${t.message}`,"REMOVE_FAILED",t):new w("Unknown error occurred while removing","REMOVE_FAILED")}}async exists(e){if(!this._isAvailable)return false;try{let t=this.getStorageKey(e),i=localStorage.getItem(t);if(!i)return !1;let n=this.compress?this.decompressData(i):i,o=JSON.parse(n);return o.expiresAt&&Date.now()>o.expiresAt?(await this.remove(e),!1):!0}catch{return false}}async listKeys(){if(!this._isAvailable)return [];try{let e=[];for(let t=0;t<localStorage.length;t++){let i=localStorage.key(t);if(i?.startsWith(this.keyPrefix)){let n=i.substring(this.keyPrefix.length);await this.exists(n)&&e.push(n);}}return e}catch(e){throw e instanceof Error?new w(`Failed to list keys: ${e.message}`,"LIST_FAILED",e):new w("Unknown error occurred while listing keys","LIST_FAILED")}}async clear(){try{let e=[];for(let t=0;t<localStorage.length;t++){let i=localStorage.key(t);i?.startsWith(this.keyPrefix)&&e.push(i);}for(let t of e)localStorage.removeItem(t);}catch(e){throw e instanceof Error?new w(`Failed to clear localStorage: ${e.message}`,"CLEAR_FAILED",e):new w("Unknown error occurred while clearing","CLEAR_FAILED")}}getStorageKey(e){return `${this.keyPrefix}${e}`}isLocalStorageAvailable(){try{let e="__rilay_test__";return localStorage.setItem(e,"test"),localStorage.removeItem(e),!0}catch{return false}}compressData(e){return btoa(e)}decompressData(e){try{return atob(e)}catch{return e}}async clearExpiredData(){if(!this._isAvailable)return;let e=[];for(let t=0;t<localStorage.length;t++){let i=localStorage.key(t);if(i?.startsWith(this.keyPrefix))try{let n=localStorage.getItem(i);if(n){let o=this.compress?this.decompressData(n):n,s=JSON.parse(o);s.expiresAt&&Date.now()>s.expiresAt&&e.push(i);}}catch{e.push(i);}}for(let t of e)localStorage.removeItem(t);}};
|
|
2
|
-
|
|
1
|
+
'use strict';var core=require('@rilaykit/core'),forms=require('@rilaykit/forms'),ft=require('react'),Pe=require('@noble/ed25519'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var ft__default=/*#__PURE__*/_interopDefault(ft);var Pe__namespace=/*#__PURE__*/_interopNamespace(Pe);var V=class t{constructor(e,r,n,i){this.steps=[];this.plugins=[];this.idGenerator=new core.IdGenerator;this.config=e,this.workflowId=r,this.workflowName=n,this.workflowDescription=i;}static create(e,r,n,i){return new t(e,r,n,i)}createStepFromDefinition(e){return {id:e.id||this.idGenerator.next("step"),title:e.title,description:e.description,formConfig:e.formConfig instanceof forms.form?e.formConfig.build():e.formConfig,allowSkip:e.allowSkip||false,renderer:e.renderer,conditions:e.conditions,metadata:e.metadata,onAfterValidation:e.onAfterValidation}}addStep(e){let r=core.normalizeToArray(e);for(let n of r){let i=this.createStepFromDefinition(n);this.steps.push(i);}return this}configure(e){return e.analytics&&(this.analytics=e.analytics),e.persistence&&(this.persistenceConfig=e.persistence),this}use(e){this.validatePluginDependencies(e),this.plugins.push(e);try{e.install(this);}catch(r){throw new Error(`Failed to install plugin "${e.name}": ${r instanceof Error?r.message:String(r)}`)}return this}validatePluginDependencies(e){if(!e.dependencies)return;let r=e.dependencies.filter(n=>!this.plugins.some(i=>i.name===n));if(r.length>0)throw new Error(`Plugin "${e.name}" requires missing dependencies: ${r.join(", ")}`)}removePlugin(e){return this.plugins=this.plugins.filter(r=>r.name!==e),this}updateStep(e,r){let n=this.steps.findIndex(i=>i.id===e);if(n===-1)throw new Error(`Step with ID "${e}" not found`);return this.steps[n]={...this.steps[n],...r},this}addStepConditions(e,r){let n=this.steps.findIndex(s=>s.id===e);if(n===-1)throw new Error(`Step with ID "${e}" not found`);let i={...this.steps[n].conditions,...r};return this.steps[n]={...this.steps[n],conditions:i},this}removeStep(e){return this.steps=this.steps.filter(r=>r.id!==e),this}getStep(e){return this.steps.find(r=>r.id===e)}getSteps(){return [...this.steps]}clearSteps(){return this.steps=[],this.idGenerator.reset(),this}clone(e,r){let n=new t(this.config,e||`${this.workflowId}-clone`,r||this.workflowName);return n.steps=core.deepClone(this.steps),n.analytics=this.analytics?core.deepClone(this.analytics):void 0,n.persistenceConfig=this.persistenceConfig?core.deepClone(this.persistenceConfig):void 0,n.plugins=[...this.plugins],n}validate(){let e=[];this.steps.length===0&&e.push("Workflow must have at least one step");let r=this.steps.map(n=>n.id);try{core.ensureUnique(r,"step");}catch(n){e.push(n instanceof Error?n.message:String(n));}for(let n of this.plugins)if(n.dependencies){let i=n.dependencies.filter(s=>!this.plugins.some(o=>o.name===s));i.length>0&&e.push(`Plugin "${n.name}" requires missing dependencies: ${i.join(", ")}`);}return e}getStats(){let e=this.steps.reduce((n,i)=>n+i.formConfig.allFields.length,0),r=this.steps.map(n=>n.formConfig.allFields.length);return {totalSteps:this.steps.length,totalFields:e,averageFieldsPerStep:this.steps.length>0?e/this.steps.length:0,maxFieldsInStep:r.length>0?Math.max(...r):0,minFieldsInStep:r.length>0?Math.min(...r):0,hasAnalytics:!!this.analytics}}build(){let e=this.validate();if(e.length>0)throw new Error(`Workflow validation failed: ${e.join(", ")}`);return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins,renderConfig:this.config.getWorkflowRenderConfig()}}toJSON(){return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins.map(e=>({name:e.name,version:e.version}))}}fromJSON(e){return this.workflowId=e.workflowId,this.workflowName=e.workflowName,this.workflowDescription=e.workflowDescription,this.steps=e.steps,this.analytics=e.analytics,this.persistenceConfig=e.persistence,this.plugins=e.plugins||[],this}};var Xe=1751361139160,He="8fdb6a454550326d331c3b3d1d1f8c707a371bdb6c7ea72a0a1e4ea6f1822620",x=class x{static async setLicenseKey(e){x.licenseKey=e||"",x.licenseKey?x.licenseResult=await x.validateLicense():x.licenseResult={valid:false,error:"MISSING"},x.isInitialized=true;}static async validateLicense(){if(!x.licenseKey)return {valid:false,error:"MISSING"};try{if(!x.licenseKey.startsWith("ril_"))return {valid:!1,error:"FORMAT_INVALID"};let e=x.licenseKey.slice(4),n=x.base64ToString(e).split(".");if(n.length!==3)return {valid:!1,error:"FORMAT_INVALID"};let[i,s,o]=n,a=`${i}.${s}`,c=new TextEncoder().encode(a),l=o.match(/.{2}/g);if(!l)return {valid:!1,error:"INVALID"};let p=new Uint8Array(l.map(W=>Number.parseInt(W,16))),f=x.hexToBytes(He);if(!await Pe__namespace.verify(p,c,f))return {valid:!1,error:"SIGNATURE_INVALID"};let m=x.base64ToString(s.replace(/-/g,"+").replace(/_/g,"/")),d=JSON.parse(m),u=Math.floor(Date.now()/1e3);return d.e<u?{valid:!1,error:"EXPIRED",data:x.decompressPayload(d)}:Xe>d.e*1e3?{valid:!1,error:"EXPIRED",data:x.decompressPayload(d)}:d.p===void 0||!d.c||!d.i||!d.e||!d.t?{valid:!1,error:"INVALID"}:{valid:!0,data:x.decompressPayload(d)}}catch{return {valid:false,error:"INVALID"}}}static decompressPayload(e){return {plan:{0:"ARCHITECT",1:"FOUNDRY"}[e.p]||"ARCHITECT",company:e.c,customerId:e.i.toString(),expiry:e.e*1e3,iat:e.t*1e3}}static hexToBytes(e){let r=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)r[n/2]=Number.parseInt(e.substring(n,n+2),16);return r}static base64ToString(e){if(typeof atob<"u")return atob(e);if(typeof Buffer<"u")return Buffer.from(e,"base64").toString();let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",i=0,s=e.replace(/[^A-Za-z0-9+/]/g,"");for(;i<s.length;){let o=r.indexOf(s.charAt(i++)),a=r.indexOf(s.charAt(i++)),c=r.indexOf(s.charAt(i++)),l=r.indexOf(s.charAt(i++)),p=o<<18|a<<12|c<<6|l;n+=String.fromCharCode(p>>16&255),c!==64&&(n+=String.fromCharCode(p>>8&255)),l!==64&&(n+=String.fromCharCode(p&255));}return n}static getLicenseResult(){return x.isInitialized?x.licenseResult?x.licenseResult:{valid:false,error:"MISSING"}:{valid:false,error:"MISSING"}}static shouldDisplayWatermark(){return typeof window>"u"?false:!x.getLicenseResult().valid}static getWatermarkMessage(){let e=x.getLicenseResult();return {MISSING:"Rilay Workflow - For Trial Use Only",EXPIRED:"Rilay Workflow - License Expired",INVALID:"Rilay Workflow - Invalid License",FORMAT_INVALID:"Rilay Workflow - Invalid License Format",SIGNATURE_INVALID:"Rilay Workflow - Invalid License Signature"}[e.error||"MISSING"]||""}static logLicenseStatus(){let e=x.getLicenseResult();if(e.valid)return;let n={MISSING:"\u{1F527} Rilay Workflow - Trial Mode. Purchase a license at https://rilay.io/pricing",EXPIRED:"\u26A0\uFE0F Rilay Workflow - License Expired. Please renew your license.",INVALID:"\u274C Rilay Workflow - Invalid License. Please check your license key.",FORMAT_INVALID:"\u274C Rilay Workflow - Invalid License Format. Please check your license key.",SIGNATURE_INVALID:"\u274C Rilay Workflow - Invalid License Signature. Please check your license key."}[e.error||"MISSING"];console.warn(`%c${n}`,"color: #f59e0b; font-weight: bold;");}static async getLicenseInfo(){let e=x.getLicenseResult();return !e.valid||!e.data?{}:{plan:e.data.plan,company:e.data.company,expiryDate:new Date(e.data.expiry).toLocaleDateString()}}};x.licenseKey="",x.licenseResult=null,x.isInitialized=false;var F=x;function Q(t,e={},r={}){return ft.useMemo(()=>{if(!t)return {visible:r.visible??true,disabled:r.disabled??false,required:r.required??false,readonly:r.readonly??false};let n=i=>{try{let s;return i&&typeof i=="object"&&"build"in i?s=i.build():s=i,core.evaluateCondition(s,e)}catch(s){return console.warn("Error evaluating condition:",s),false}};return {visible:t.visible?n(t.visible):true,disabled:t.disabled?n(t.disabled):false,required:t.required?n(t.required):false,readonly:t.readonly?n(t.readonly):false}},[t,e,r])}function Ie(t,e={}){return ft.useMemo(()=>{let r={};for(let[n,i]of Object.entries(t))if(r[n]={visible:true,disabled:false,required:false,readonly:false},i){let s=o=>{try{return o&&typeof o=="object"&&"build"in o?core.evaluateCondition(o.build(),e):core.evaluateCondition(o,e)}catch(a){return console.warn(`Error evaluating condition for field ${n}:`,a),false}};r[n]={visible:i.visible?s(i.visible):true,disabled:i.disabled?s(i.disabled):false,required:i.required?s(i.required):false,readonly:i.readonly?s(i.readonly):false};}return r},[t,e])}function We(t,e={}){return ft.useMemo(()=>{let r={};for(let[n,i]of Object.entries(t)){let s=Number.parseInt(n,10);if(r[s]={visible:true,disabled:false,required:false,readonly:false},i){let o=a=>{try{return a&&typeof a=="object"&&"build"in a?core.evaluateCondition(a.build(),e):core.evaluateCondition(a,e)}catch(c){return console.warn(`Error evaluating condition for step ${s}:`,c),false}};r[s]={visible:i.visible?o(i.visible):true,disabled:i.disabled?o(i.disabled):false,required:i.required?o(i.required):false,readonly:i.readonly?o(i.readonly):false};}}return r},[t,e])}var D=class extends Error{constructor(r,n,i){super(`[WorkflowPersistence] ${r} (Code: ${n})`);this.code=n;this.cause=i;this.name="WorkflowPersistenceError";}};function j(t,e,r){return {workflowId:t,currentStepIndex:e.currentStepIndex,allData:{...e.allData},stepData:{...e.stepData},visitedSteps:Array.from(e.visitedSteps),lastSaved:Date.now(),metadata:r}}function De(t){return {currentStepIndex:t.currentStepIndex,allData:{...t.allData},stepData:{...t.stepData},visitedSteps:new Set(t.visitedSteps),isSubmitting:false,isTransitioning:false}}function Ze(t){if(!t||typeof t!="object")return false;let e=["workflowId","currentStepIndex","allData","stepData","visitedSteps","lastSaved"];for(let r of e)if(!(r in t))return false;return !(typeof t.workflowId!="string"||typeof t.currentStepIndex!="number"||typeof t.allData!="object"||typeof t.stepData!="object"||!Array.isArray(t.visitedSteps)||typeof t.lastSaved!="number")}function ee(t,e){return e?`${e}:${t}`:t}function te(t,e){let r=null;return (...n)=>{r&&clearTimeout(r),r=setTimeout(()=>{t(...n);},e);}}function Ye(t,e,r="persist"){let n=De(e);switch(r){case "persist":return {...n,isSubmitting:t.isSubmitting,isTransitioning:t.isTransitioning};case "current":return {...t,visitedSteps:new Set([...t.visitedSteps,...n.visitedSteps])};case "merge":return {currentStepIndex:t.currentStepIndex,allData:{...n.allData,...t.allData},stepData:{...n.stepData,...t.stepData},visitedSteps:new Set([...n.visitedSteps,...t.visitedSteps]),isSubmitting:t.isSubmitting,isTransitioning:t.isTransitioning};default:return n}}function z({workflowId:t,workflowState:e,adapter:r,options:n={},userId:i}){let[s,o]=ft.useState(false),[a,c]=ft.useState(null),[l,p]=ft.useState(false),f=ft.useRef(r),S=ft.useRef(n),m=ft.useRef({hasPendingChanges:false});ft.useEffect(()=>{f.current=r,S.current=n;},[r,n]);let d=ee(S.current.storageKey||t,i),u=ft.useCallback(()=>{c(null);},[]),k=ft.useCallback((b,I)=>{let T=b instanceof D?b:new D(`${I} failed: ${b.message}`,"OPERATION_FAILED",b);c(T),console.error("[WorkflowPersistence]",T);},[]),W=ft.useCallback(async b=>{u(),o(true);try{let I=j(t,b,S.current.metadata);await f.current.save(d,I),m.current.lastSavedState={...b},m.current.hasPendingChanges=!1;}catch(I){throw k(I,"Save"),I}finally{o(false);}},[t,d,u,k]),g=ft.useRef(te(async b=>{try{await W(b);}catch(I){console.debug("[WorkflowPersistence] Auto-save failed:",I);}},n.debounceMs||500)),h=ft.useCallback((b,I)=>I?b.currentStepIndex!==I.currentStepIndex||JSON.stringify(b.allData)!==JSON.stringify(I.allData)||JSON.stringify(b.stepData)!==JSON.stringify(I.stepData)||b.visitedSteps.size!==I.visitedSteps.size||!Array.from(b.visitedSteps).every(T=>I.visitedSteps.has(T)):true,[]),P=ft.useCallback(async()=>{u(),p(true);try{let b=await f.current.load(d);return b&&(m.current.lastSavedState={currentStepIndex:b.currentStepIndex,allData:b.allData,stepData:b.stepData,visitedSteps:new Set(b.visitedSteps),isSubmitting:!1,isTransitioning:!1,isInitializing:!1},m.current.hasPendingChanges=!1),b}catch(b){return k(b,"Load"),null}finally{setTimeout(()=>p(false),100);}},[d,u,k]),w=ft.useCallback(async()=>{u();try{await f.current.remove(d),m.current.lastSavedState=void 0,m.current.hasPendingChanges=!1;}catch(b){throw k(b,"Clear"),b}},[d,u,k]),y=ft.useCallback(async()=>{try{return await f.current.exists(d)}catch(b){return k(b,"Exists check"),false}},[d,k]);ft.useEffect(()=>{S.current.autoPersist&&(s||l||e.isInitializing||e.isSubmitting||e.isTransitioning||h(e,m.current.lastSavedState)&&(m.current.hasPendingChanges=true,g.current(e)));},[e,s,l,h]);let v=ft.useCallback(async()=>{await W(e);},[W,e]);return {isPersisting:s,persistenceError:a,persistNow:v,loadPersistedData:P,clearPersistedData:w,hasPersistedData:y}}function Qe(){let{workflowConfig:t,currentStep:e}=E(),r=ft.useMemo(()=>e?.metadata,[e?.metadata]),n=ft.useMemo(()=>l=>t.steps.find(f=>f.id===l)?.metadata,[t.steps]),i=ft.useMemo(()=>l=>t.steps[l]?.metadata,[t.steps]),s=ft.useMemo(()=>l=>r?l in r:false,[r]),o=ft.useMemo(()=>(l,p)=>r&&l in r?r[l]:p,[r]),a=ft.useMemo(()=>()=>t.steps.map((l,p)=>({id:l.id,title:l.title,index:p,metadata:l.metadata})),[t.steps]),c=ft.useMemo(()=>l=>t.steps.map((p,f)=>({step:p,index:f})).filter(({step:p,index:f})=>l(p.metadata,p.id,f)).map(({step:p})=>p.id),[t.steps]);return {current:r,getByStepId:n,getByStepIndex:i,hasCurrentKey:s,getCurrentValue:o,getAllStepsMetadata:a,findStepsByMetadata:c}}function ne({workflowConfig:t,workflowState:e,workflowContext:r}){let n=ft.useRef(Date.now()),i=ft.useRef(new Map),s=ft.useRef(false),o=ft.useRef(null),a=core.getGlobalMonitor();ft.useEffect(()=>{t.analytics?.onWorkflowStart&&!s.current&&(s.current=true,t.analytics.onWorkflowStart(t.id,r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"start",totalSteps:t.steps.length},{timestamp:Date.now(),duration:0,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:0,navigationDuration:0,conditionEvaluationDuration:0},"low"));},[t.id,t.analytics,r,a,t.steps.length]),ft.useEffect(()=>{let S=t.steps[e.currentStepIndex];if(S&&o.current!==S.id){if(o.current&&t.analytics?.onStepComplete){let m=i.current.get(o.current);if(m){let d=Date.now()-m;t.analytics.onStepComplete(o.current,d,e.stepData,r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"step_complete",stepId:o.current,duration:d},{timestamp:Date.now(),duration:d,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:e.currentStepIndex,navigationDuration:d,conditionEvaluationDuration:0},"low");}}o.current=S.id,i.current.set(S.id,Date.now()),t.analytics?.onStepStart&&t.analytics.onStepStart(S.id,Date.now(),r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"step_start",stepId:S.id,stepIndex:e.currentStepIndex},{timestamp:Date.now(),duration:0,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:e.currentStepIndex,navigationDuration:0,conditionEvaluationDuration:0},"low");}},[e.currentStepIndex,t.steps,t.analytics,r,e.stepData,a,t.id]);let c=ft.useCallback((S,m)=>{t.analytics?.onStepSkip&&t.analytics.onStepSkip(S,m,r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"step_skip",stepId:S,reason:m},void 0,"medium");},[t.analytics,r,a,t.id]),l=ft.useCallback(S=>{t.analytics?.onError&&t.analytics.onError(S,r),a&&a.trackError(S,`workflow_${t.id}`,{workflowId:t.id,currentStepIndex:e.currentStepIndex,currentStepId:t.steps[e.currentStepIndex]?.id,workflowContext:r});},[t.analytics,r,a,t.id,e.currentStepIndex,t.steps]),p=ft.useCallback((S,m,d)=>{if(!a)return;let u={timestamp:Date.now(),duration:d,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:m,navigationDuration:d,conditionEvaluationDuration:0};a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"navigation",fromStep:S,toStep:m,direction:m>S?"forward":"backward"},u,d>1e3?"medium":"low");},[a,t.id,t.steps.length]),f=ft.useCallback((S,m)=>{if(!a)return;let d={timestamp:Date.now(),duration:S,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:e.currentStepIndex,navigationDuration:0,conditionEvaluationDuration:S};a.track("condition_evaluation",`workflow_${t.id}`,{workflowId:t.id,conditionsCount:m,currentStepIndex:e.currentStepIndex},d,S>100?"medium":"low");},[a,t.id,t.steps.length,e.currentStepIndex]);return {analyticsStartTime:n,trackStepSkip:c,trackError:l,trackNavigation:p,trackConditionEvaluation:f}}function Re(t,e){return {visible:t.visible,skippable:e===true||t.required}}function ie({workflowConfig:t,workflowState:e,currentStep:r}){let n=ft.useMemo(()=>({...e.allData,...e.stepData}),[e.allData,e.stepData]),i=ft.useMemo(()=>{if(r?.conditions)return {visible:r.conditions.visible,required:r.conditions.skippable}},[r?.conditions]),s=Q(i,n,{visible:true,disabled:false,required:false,readonly:false}),o=ft.useMemo(()=>Re(s,r?.allowSkip),[s,r?.allowSkip]),a=ft.useMemo(()=>{let g={};return t.steps.forEach((h,P)=>{h.conditions&&(g[P]={visible:h.conditions.visible,required:h.conditions.skippable});}),g},[t.steps]),c=We(a,n),l=ft.useMemo(()=>{let g={};return t.steps.forEach((h,P)=>{let w=c[P];w?g[P]=Re(w,h.allowSkip):g[P]={visible:true,skippable:h.allowSkip===true};}),g},[t.steps,c]),p=ft.useMemo(()=>{if(!r?.formConfig?.allFields)return {};let g={};for(let h of r.formConfig.allFields)h.conditions&&(g[h.id]=h.conditions);return g},[r?.formConfig?.allFields]),f=Ie(p,n),S=ft.useCallback(g=>g<0||g>=t.steps.length?false:l[g]?.visible??true,[l,t.steps.length]),m=ft.useCallback(g=>g<0||g>=t.steps.length?false:l[g]?.skippable??false,[l,t.steps.length]),d=ft.useCallback(g=>f[g]?.visible??true,[f]),u=ft.useCallback(g=>f[g]?.disabled??false,[f]),k=ft.useCallback(g=>f[g]?.required??false,[f]),W=ft.useCallback(g=>f[g]?.readonly??false,[f]);return {stepConditions:o,fieldConditions:f,allStepConditions:l,isStepVisible:S,isStepSkippable:m,isFieldVisible:d,isFieldDisabled:u,isFieldRequired:k,isFieldReadonly:W}}function se({workflowConfig:t,workflowState:e,workflowContext:r,conditionsHelpers:n,setCurrentStep:i,setTransitioning:s,markStepVisited:o,setStepData:a,onStepChange:c}){let l=ft.useRef(c);l.current=c;let p=t.steps[e.currentStepIndex],f=ft.useCallback(()=>({setStepData:(y,v)=>{a(v,y);},setStepFields:(y,v)=>{let I={...e.allData[y]||{},...v};a(I,y);},getStepData:y=>e.allData[y]||{},setNextStepField:(y,v)=>{let b=e.currentStepIndex+1;if(b<t.steps.length){let I=t.steps[b].id,G={...e.allData[I]||{},[y]:v};a(G,I);}},setNextStepFields:y=>{let v=e.currentStepIndex+1;if(v<t.steps.length){let b=t.steps[v].id,T={...e.allData[b]||{},...y};a(T,b);}},getAllData:()=>({...e.allData}),getSteps:()=>[...t.steps]}),[e.allData,e.currentStepIndex,t.steps,a]),S=ft.useCallback(async y=>{if(y<0||y>=t.steps.length||!n.isStepVisible(y))return false;s(true);try{return l.current&&l.current(e.currentStepIndex,y,r),i(y),o(y,t.steps[y].id),!0}catch(v){return console.error("Step transition failed:",v),t.analytics?.onError&&t.analytics.onError(v,r),false}finally{s(false);}},[t.steps,t.analytics,n,e.currentStepIndex,r,s,i,o]),m=ft.useCallback(y=>{for(let v=y+1;v<t.steps.length;v++)if(n.isStepVisible(v))return v;return null},[t.steps.length,n]),d=ft.useCallback(y=>{for(let v=y-1;v>=0;v--)if(n.isStepVisible(v))return v;return null},[n]),u=ft.useCallback(async()=>{if(p?.onAfterValidation)try{let v=f();await p.onAfterValidation(e.stepData,v,r);}catch(v){return console.error("onAfterValidation failed:",v),t.analytics?.onError&&t.analytics.onError(v,r),false}let y=m(e.currentStepIndex);return y===null?false:S(y)},[p,f,e.stepData,r,t.analytics,e.currentStepIndex,m,S]),k=ft.useCallback(async()=>{let y=d(e.currentStepIndex);return y===null?false:S(y)},[e.currentStepIndex,d,S]),W=ft.useCallback(async()=>!p?.allowSkip&&!n.isStepSkippable(e.currentStepIndex)?false:(t.analytics?.onStepSkip&&t.analytics.onStepSkip(p.id,"user_skip",r),u()),[p,n,e.currentStepIndex,t.analytics,r,u]),g=ft.useCallback(y=>y<0||y>=t.steps.length?false:n.isStepVisible(y),[t.steps.length,n]),h=ft.useCallback(()=>{let y=m(e.currentStepIndex);return y!==null&&g(y)},[e.currentStepIndex,m,g]),P=ft.useCallback(()=>{let y=d(e.currentStepIndex);return y!==null&&g(y)},[e.currentStepIndex,d,g]),w=ft.useCallback(()=>p?.allowSkip===true&&n.isStepSkippable(e.currentStepIndex),[p?.allowSkip,n,e.currentStepIndex]);return {goToStep:S,goNext:u,goPrevious:k,skipStep:W,canGoToStep:g,canGoNext:h,canGoPrevious:P,canSkipCurrentStep:w}}function rt(t,e){switch(e.type){case "SET_CURRENT_STEP":return {...t,currentStepIndex:e.stepIndex};case "SET_STEP_DATA":return {...t,stepData:e.data,allData:{...t.allData,[e.stepId]:e.data}};case "SET_ALL_DATA":return {...t,allData:e.data};case "SET_FIELD_VALUE":{let r={...t.stepData,[e.fieldId]:e.value};return {...t,stepData:r,allData:{...t.allData,[e.stepId]:r}}}case "SET_SUBMITTING":return {...t,isSubmitting:e.isSubmitting};case "SET_TRANSITIONING":return {...t,isTransitioning:e.isTransitioning};case "MARK_STEP_VISITED":return {...t,visitedSteps:new Set([...t.visitedSteps,e.stepId])};case "RESET_WORKFLOW":return {currentStepIndex:0,allData:{},stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:false};case "LOAD_PERSISTED_STATE":return {...t,...e.state};case "SET_INITIALIZATION_COMPLETE":return {...t,isInitializing:false};default:return t}}function oe({defaultValues:t={},persistence:e}){let r={currentStepIndex:0,allData:t,stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:true},[n,i]=ft.useReducer(rt,r),s=e?.adapter?z({workflowId:e.workflowId,workflowState:n,adapter:e.adapter,options:e.options,userId:e.userId}):null,o=ft.useCallback(u=>{i({type:"SET_CURRENT_STEP",stepIndex:u});},[]),a=ft.useCallback((u,k)=>{i({type:"SET_STEP_DATA",data:u,stepId:k});},[]),c=ft.useCallback((u,k,W)=>{i({type:"SET_FIELD_VALUE",fieldId:u,value:k,stepId:W});},[]),l=ft.useCallback(u=>{i({type:"SET_SUBMITTING",isSubmitting:u});},[]),p=ft.useCallback(u=>{i({type:"SET_TRANSITIONING",isTransitioning:u});},[]),f=ft.useCallback((u,k)=>{i({type:"MARK_STEP_VISITED",stepIndex:u,stepId:k});},[]),S=ft.useCallback(()=>{i({type:"RESET_WORKFLOW"});},[]),m=ft.useCallback(()=>{i({type:"SET_INITIALIZATION_COMPLETE"});},[]),d=ft.useCallback(async()=>{if(!s)return m(),false;try{let u=await s.loadPersistedData();if(u){let k={currentStepIndex:u.currentStepIndex,allData:u.allData,stepData:u.stepData,visitedSteps:new Set(u.visitedSteps)};return i({type:"LOAD_PERSISTED_STATE",state:k}),m(),!0}}catch(u){console.error("Failed to load persisted state:",u);}return m(),false},[s,m]);return {workflowState:n,setCurrentStep:o,setStepData:a,setFieldValue:c,setSubmitting:l,setTransitioning:p,markStepVisited:f,resetWorkflow:S,loadPersistedState:d,persistence:s?{isPersisting:s.isPersisting,persistenceError:s.persistenceError,persistNow:s.persistNow,clearPersistedData:s.clearPersistedData,hasPersistedData:s.hasPersistedData}:null}}function ae({workflowConfig:t,workflowState:e,workflowContext:r,setSubmitting:n,onWorkflowComplete:i,analyticsStartTime:s}){let o=ft.useRef(i);o.current=i;let a=ft.useCallback(async()=>{n(true);try{if(o.current&&await o.current(e.allData),t.analytics?.onWorkflowComplete){let l=Date.now()-s.current;t.analytics.onWorkflowComplete(t.id,l,e.allData);}}catch(l){throw console.error("Workflow submission failed:",l),t.analytics?.onError&&t.analytics.onError(l,r),l}finally{n(false);}},[e.allData,t.analytics,t.id,r,s,n]),c=ft.useCallback(()=>e.isSubmitting?false:e.currentStepIndex===t.steps.length-1,[e.isSubmitting,e.currentStepIndex,t.steps.length]);return {submitWorkflow:a,isSubmitting:e.isSubmitting,canSubmit:c()}}var Le=ft.createContext(null);function pe({children:t,workflowConfig:e,defaultValues:r={},onStepChange:n,onWorkflowComplete:i,className:s}){let o=ft.useRef(n),a=ft.useRef(i);o.current=n,a.current=i;let{workflowState:c,setCurrentStep:l,setStepData:p,setFieldValue:f,setSubmitting:S,setTransitioning:m,markStepVisited:d,resetWorkflow:u,loadPersistedState:k,persistence:W}=oe({defaultValues:r,persistence:e.persistence?{workflowId:e.id,adapter:e.persistence.adapter,options:e.persistence.options,userId:e.persistence.userId}:void 0});ft.useEffect(()=>{e.persistence&&k&&k();},[]);let g=ft.useMemo(()=>({isPersisting:W?.isPersisting??false,persistenceError:W?.persistenceError??null,persistNow:W?.persistNow}),[W?.isPersisting,W?.persistenceError,W?.persistNow]),h=ft.useMemo(()=>({workflowId:e.id,currentStepIndex:c.currentStepIndex,totalSteps:e.steps.length,allData:c.allData,stepData:c.stepData,isFirstStep:c.currentStepIndex===0,isLastStep:c.currentStepIndex===e.steps.length-1,visitedSteps:c.visitedSteps}),[e.id,e.steps.length,c.currentStepIndex,c.allData,c.stepData,c.visitedSteps]),P=ft.useMemo(()=>e.steps[c.currentStepIndex],[e.steps,c.currentStepIndex]),w=ft.useMemo(()=>P?.formConfig,[P?.formConfig]),{analyticsStartTime:y}=ne({workflowConfig:e,workflowState:c,workflowContext:h}),v=ie({workflowConfig:e,workflowState:c,currentStep:P}),{goToStep:b,goNext:I,goPrevious:T,skipStep:G,canGoToStep:ue,canGoNext:fe,canGoPrevious:me,canSkipCurrentStep:Se}=se({workflowConfig:e,workflowState:c,workflowContext:h,conditionsHelpers:v,setCurrentStep:l,setTransitioning:m,markStepVisited:d,setStepData:p,onStepChange:o.current});ft.useEffect(()=>{if(!v.isStepVisible(c.currentStepIndex)){for(let A=0;A<e.steps.length;A++)if(v.isStepVisible(A)){l(A),d(A,e.steps[A].id);break}}},[v,c.currentStepIndex,e.steps,l,d]);let{submitWorkflow:K,isSubmitting:ge,canSubmit:ye}=ae({workflowConfig:e,workflowState:c,workflowContext:h,setSubmitting:S,onWorkflowComplete:a.current,analyticsStartTime:y}),H=ft.useCallback((C,A)=>{f(C,A,P?.id||"");},[f,P?.id]),be=ft.useCallback(C=>{p(C,P?.id||"");},[p,P?.id]),Oe=ft.useCallback(async C=>{P?.id&&C&&p(C,P.id),h.isLastStep?await K():await I();},[h.isLastStep,K,I,P?.id,p]),ve=ft.useMemo(()=>({goToStep:b,goNext:I,goPrevious:T,skipStep:G,canGoToStep:ue,canGoNext:fe,canGoPrevious:me,canSkipCurrentStep:Se}),[b,I,T,G,ue,fe,me,Se]),he=ft.useMemo(()=>({setValue:H,setStepData:be,resetWorkflow:u}),[H,be,u]),ke=ft.useMemo(()=>({submitWorkflow:K,isSubmitting:ge,canSubmit:ye}),[K,ge,ye]),Ve=ft.useMemo(()=>({workflowState:c,workflowConfig:e,currentStep:P,context:h,formConfig:w,conditionsHelpers:v,currentStepMetadata:P?.metadata,...ve,...he,...ke,persistNow:g.persistNow,isPersisting:g.isPersisting,persistenceError:g.persistenceError}),[c,e,P,h,w,v,ve,he,ke,g]),Ue=ft.useMemo(()=>{if(!P?.id)return {};let C=c?.allData[P.id]||{};if(!w?.allFields)return C;let A=new Set(w.allFields.map($=>$.id)),xe={};for(let[$,Ke]of Object.entries(C))A.has($)&&(xe[$]=Ke);return xe},[c?.allData,P?.id,w?.allFields]),Ge=ft.useMemo(()=>c.isInitializing.toString(),[c.isInitializing]);return jsxRuntime.jsx(Le.Provider,{value:Ve,children:jsxRuntime.jsx(forms.FormProvider,{formConfig:w,defaultValues:Ue,onFieldChange:H,"data-workflow-id":e.id,className:s,onSubmit:Oe,children:t},Ge)})}function E(){let t=ft.useContext(Le);if(!t)throw new Error("useWorkflowContext must be used within a WorkflowProvider");return t}function ct({children:t,workflowConfig:e,...r}){let[n,i]=ft.useState(),s=ft.useMemo(()=>e instanceof V?e.build():e,[e]);return ft.useEffect(()=>{if(typeof window<"u"&&F.shouldDisplayWatermark()){let a=F.getWatermarkMessage();i(a);}},[]),jsxRuntime.jsxs("div",{style:{position:"relative"},children:[jsxRuntime.jsx(pe,{...r,workflowConfig:s,children:t}),n&&jsxRuntime.jsx("div",{style:{position:"absolute",top:"10px",right:"10px",background:"rgba(0, 0, 0, 0.8)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",zIndex:1e3,pointerEvents:"none",opacity:.7},children:n})]})}var mt=ft__default.default.memo(function({stepId:e,children:r}){let{currentStep:n}=E();if(!n||e&&n.id!==e)return null;let{formConfig:i,renderer:s}=n;return i?s?s(n):r??jsxRuntime.jsx(forms.FormBody,{}):null});var ht=ft__default.default.memo(function({className:e,isSubmitting:r,...n}){let{context:i,workflowState:s,workflowConfig:o,currentStep:a}=E(),{submit:c,formState:l}=forms.useFormContext(),p=ft.useMemo(()=>{let m=l.isSubmitting||s.isSubmitting,d=r??m,u=!s.isTransitioning&&!d;return {finalIsSubmitting:d,canGoNext:u}},[l.isSubmitting,s.isSubmitting,s.isTransitioning,r]),f=ft.useCallback(async m=>{m?.preventDefault(),p.canGoNext&&await c(m);},[p.canGoNext,c]),S=ft.useMemo(()=>({isLastStep:i.isLastStep,canGoNext:p.canGoNext,isSubmitting:p.finalIsSubmitting,onSubmit:f,className:e,currentStep:a,stepData:l.values||{},allData:i.allData,context:i}),[i.isLastStep,p.canGoNext,p.finalIsSubmitting,f,e,a,l.values,i.allData,i]);return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowNextButton",renderer:o.renderConfig?.nextButtonRenderer,props:S,...n})});var Dt=ft__default.default.memo(function({className:e,isSubmitting:r,...n}){let{context:i,goPrevious:s,workflowState:o,workflowConfig:a,currentStep:c}=E(),{formState:l}=forms.useFormContext(),p=ft.useMemo(()=>{let m=l.isSubmitting||o.isSubmitting,d=r??m,u=i.currentStepIndex>0&&!o.isTransitioning&&!d;return {finalIsSubmitting:d,canGoPrevious:u}},[l.isSubmitting,o.isSubmitting,o.isTransitioning,i.currentStepIndex,r]),f=ft.useCallback(async m=>{m?.preventDefault(),p.canGoPrevious&&await s();},[p.canGoPrevious,s]),S=ft.useMemo(()=>({canGoPrevious:p.canGoPrevious,isSubmitting:p.finalIsSubmitting,onPrevious:f,className:e,currentStep:c,stepData:l.values||{},allData:i.allData,context:i}),[p.canGoPrevious,p.finalIsSubmitting,f,e,c,l.values,i.allData,i]);return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowPreviousButton",renderer:a.renderConfig?.previousButtonRenderer,props:S,...n})});var At=ft__default.default.memo(function({className:e,isSubmitting:r,...n}){let{currentStep:i,skipStep:s,workflowState:o,workflowConfig:a,context:c,conditionsHelpers:l}=E(),{formState:p}=forms.useFormContext(),f=ft.useMemo(()=>{let d=p.isSubmitting||o.isSubmitting,u=r??d,k=(!!i?.allowSkip||l.isStepSkippable(o.currentStepIndex))&&!o.isTransitioning&&!u;return {finalIsSubmitting:u,canSkip:k}},[p.isSubmitting,o.isSubmitting,o.isTransitioning,o.currentStepIndex,i?.allowSkip,l.isStepSkippable,r]),S=ft.useCallback(async d=>{d?.preventDefault(),f.canSkip&&await s();},[f.canSkip,s]),m=ft.useMemo(()=>({canSkip:f.canSkip,isSubmitting:f.finalIsSubmitting,onSkip:S,className:e,currentStep:i,stepData:p.values||{},allData:c.allData,context:c}),[f.canSkip,f.finalIsSubmitting,S,e,i,p.values,c.allData,c]);return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowSkipButton",renderer:a.renderConfig?.skipButtonRenderer,props:m,...n})});var Ft=ft__default.default.memo(function({onStepClick:e,className:r,...n}){let{workflowConfig:i,workflowState:s,goToStep:o,conditionsHelpers:a}=E(),{visibleSteps:c,visibleToOriginalIndexMap:l,originalToVisibleIndexMap:p}=ft.useMemo(()=>{let d=[],u=new Map,k=new Map;return i.steps.forEach((W,g)=>{if(a.isStepVisible(g)){let h=d.length;d.push(W),u.set(h,g),k.set(g,h);}}),{visibleSteps:d,visibleToOriginalIndexMap:u,originalToVisibleIndexMap:k}},[i.steps,a]),f=ft.useCallback(d=>{let u=l.get(d);u!==void 0&&(e?e(u):o(u));},[l,e,o]),S=ft.useMemo(()=>p.get(s.currentStepIndex)??-1,[p,s.currentStepIndex]),m=ft.useMemo(()=>({steps:c,currentStepIndex:S,visitedSteps:s.visitedSteps,onStepClick:f,className:r}),[c,S,s.visitedSteps,f,r]);return jsxRuntime.jsx(core.ComponentRendererWrapper,{name:"WorkflowStepper",renderer:i.renderConfig?.stepperRenderer,props:m,...n})});var de=class{constructor(e={}){this.version="1.0.0";this.keyPrefix=e.keyPrefix??"rilay_workflow_",this.compress=e.compress??false,this.maxAge=e.maxAge,this._isAvailable=this.isLocalStorageAvailable();}async save(e,r){if(this._isAvailable)try{let n=this.getStorageKey(e),i={data:{...r,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},s=JSON.stringify(i),o=this.compress?this.compressData(s):s;localStorage.setItem(n,o);}catch(n){if(n instanceof Error)if(n.name==="QuotaExceededError"||n.message.includes("quota")){await this.clearExpiredData();try{let i=this.getStorageKey(e),s={data:{...r,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},o=JSON.stringify(s),a=this.compress?this.compressData(o):o;localStorage.setItem(i,a);}catch(i){throw new D("localStorage quota exceeded and cleanup failed","QUOTA_EXCEEDED",i)}}else throw new D(`Failed to save to localStorage: ${n.message}`,"SAVE_FAILED",n);else throw new D("Unknown error occurred while saving","SAVE_FAILED")}}async load(e){if(!this._isAvailable)return null;try{let r=this.getStorageKey(e),n=localStorage.getItem(r);if(!n)return null;let i=this.compress?this.decompressData(n):n,s=JSON.parse(i);return s.expiresAt&&Date.now()>s.expiresAt?(await this.remove(e),null):{...s.data,visitedSteps:Array.isArray(s.data.visitedSteps)?s.data.visitedSteps:[]}}catch(r){throw r instanceof Error?new D(`Failed to load from localStorage: ${r.message}`,"LOAD_FAILED",r):new D("Unknown error occurred while loading","LOAD_FAILED")}}async remove(e){if(this._isAvailable)try{let r=this.getStorageKey(e);localStorage.removeItem(r);}catch(r){throw r instanceof Error?new D(`Failed to remove from localStorage: ${r.message}`,"REMOVE_FAILED",r):new D("Unknown error occurred while removing","REMOVE_FAILED")}}async exists(e){if(!this._isAvailable)return false;try{let r=this.getStorageKey(e),n=localStorage.getItem(r);if(!n)return !1;let i=this.compress?this.decompressData(n):n,s=JSON.parse(i);return s.expiresAt&&Date.now()>s.expiresAt?(await this.remove(e),!1):!0}catch{return false}}async listKeys(){if(!this._isAvailable)return [];try{let e=[];for(let r=0;r<localStorage.length;r++){let n=localStorage.key(r);if(n?.startsWith(this.keyPrefix)){let i=n.substring(this.keyPrefix.length);await this.exists(i)&&e.push(i);}}return e}catch(e){throw e instanceof Error?new D(`Failed to list keys: ${e.message}`,"LIST_FAILED",e):new D("Unknown error occurred while listing keys","LIST_FAILED")}}async clear(){try{let e=[];for(let r=0;r<localStorage.length;r++){let n=localStorage.key(r);n?.startsWith(this.keyPrefix)&&e.push(n);}for(let r of e)localStorage.removeItem(r);}catch(e){throw e instanceof Error?new D(`Failed to clear localStorage: ${e.message}`,"CLEAR_FAILED",e):new D("Unknown error occurred while clearing","CLEAR_FAILED")}}getStorageKey(e){return `${this.keyPrefix}${e}`}isLocalStorageAvailable(){try{let e="__rilay_test__";return localStorage.setItem(e,"test"),localStorage.removeItem(e),!0}catch{return false}}compressData(e){return btoa(e)}decompressData(e){try{return atob(e)}catch{return e}}async clearExpiredData(){if(!this._isAvailable)return;let e=[];for(let r=0;r<localStorage.length;r++){let n=localStorage.key(r);if(n?.startsWith(this.keyPrefix))try{let i=localStorage.getItem(n);if(i){let s=this.compress?this.decompressData(i):i,o=JSON.parse(s);o.expiresAt&&Date.now()>o.expiresAt&&e.push(n);}}catch{e.push(n);}}for(let r of e)localStorage.removeItem(r);}};
|
|
2
|
+
exports.LocalStorageAdapter=de;exports.RilayLicenseManager=F;exports.Workflow=ct;exports.WorkflowBody=mt;exports.WorkflowNextButton=ht;exports.WorkflowPersistenceError=D;exports.WorkflowPreviousButton=Dt;exports.WorkflowProvider=pe;exports.WorkflowSkipButton=At;exports.WorkflowStepper=Ft;exports.debounce=te;exports.flow=V;exports.generateStorageKey=ee;exports.mergePersistedState=Ye;exports.persistedToWorkflowState=De;exports.useConditionEvaluation=Q;exports.usePersistence=z;exports.useStepMetadata=Qe;exports.useWorkflowAnalytics=ne;exports.useWorkflowConditions=ie;exports.useWorkflowContext=E;exports.useWorkflowNavigation=se;exports.useWorkflowState=oe;exports.useWorkflowSubmission=ae;exports.validatePersistedData=Ze;exports.workflowStateToPersisted=j;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {ril,IdGenerator,normalizeToArray,deepClone,ensureUnique,ComponentRendererWrapper,evaluateCondition}from'@rilaykit/core';export*from'@rilaykit/core';import {form,FormProvider,FormBody,useFormContext}from'@rilaykit/forms';export{form}from'@rilaykit/forms';import {createContext,useMemo,useState,useRef,useEffect,useCallback,useReducer,useContext}from'react';import*as ge from'@noble/ed25519';import {jsx,jsxs}from'react/jsx-runtime';var L=class r{constructor(e,t,i,n){this.steps=[];this.plugins=[];this.idGenerator=new IdGenerator;this.config=e,this.workflowId=t,this.workflowName=i,this.workflowDescription=n;}static create(e,t,i,n){return new r(e,t,i,n)}createStepFromDefinition(e){return {id:e.id||this.idGenerator.next("step"),title:e.title,description:e.description,formConfig:e.formConfig instanceof form?e.formConfig.build():e.formConfig,allowSkip:e.allowSkip||false,renderer:e.renderer,conditions:e.conditions,metadata:e.metadata,onAfterValidation:e.onAfterValidation}}addStep(e){let t=normalizeToArray(e);for(let i of t){let n=this.createStepFromDefinition(i);this.steps.push(n);}return this}configure(e){return e.analytics&&(this.analytics=e.analytics),e.persistence&&(this.persistenceConfig=e.persistence),this}use(e){this.validatePluginDependencies(e),this.plugins.push(e);try{e.install(this);}catch(t){throw new Error(`Failed to install plugin "${e.name}": ${t instanceof Error?t.message:String(t)}`)}return this}validatePluginDependencies(e){if(!e.dependencies)return;let t=e.dependencies.filter(i=>!this.plugins.some(n=>n.name===i));if(t.length>0)throw new Error(`Plugin "${e.name}" requires missing dependencies: ${t.join(", ")}`)}removePlugin(e){return this.plugins=this.plugins.filter(t=>t.name!==e),this}updateStep(e,t){let i=this.steps.findIndex(n=>n.id===e);if(i===-1)throw new Error(`Step with ID "${e}" not found`);return this.steps[i]={...this.steps[i],...t},this}addStepConditions(e,t){let i=this.steps.findIndex(o=>o.id===e);if(i===-1)throw new Error(`Step with ID "${e}" not found`);let n={...this.steps[i].conditions,...t};return this.steps[i]={...this.steps[i],conditions:n},this}removeStep(e){return this.steps=this.steps.filter(t=>t.id!==e),this}getStep(e){return this.steps.find(t=>t.id===e)}getSteps(){return [...this.steps]}clearSteps(){return this.steps=[],this.idGenerator.reset(),this}clone(e,t){let i=new r(this.config,e||`${this.workflowId}-clone`,t||this.workflowName);return i.steps=deepClone(this.steps),i.analytics=this.analytics?deepClone(this.analytics):void 0,i.persistenceConfig=this.persistenceConfig?deepClone(this.persistenceConfig):void 0,i.plugins=[...this.plugins],i}validate(){let e=[];this.steps.length===0&&e.push("Workflow must have at least one step");let t=this.steps.map(i=>i.id);try{ensureUnique(t,"step");}catch(i){e.push(i instanceof Error?i.message:String(i));}for(let i of this.plugins)if(i.dependencies){let n=i.dependencies.filter(o=>!this.plugins.some(s=>s.name===o));n.length>0&&e.push(`Plugin "${i.name}" requires missing dependencies: ${n.join(", ")}`);}return e}getStats(){let e=this.steps.reduce((i,n)=>i+n.formConfig.allFields.length,0),t=this.steps.map(i=>i.formConfig.allFields.length);return {totalSteps:this.steps.length,totalFields:e,averageFieldsPerStep:this.steps.length>0?e/this.steps.length:0,maxFieldsInStep:t.length>0?Math.max(...t):0,minFieldsInStep:t.length>0?Math.min(...t):0,hasAnalytics:!!this.analytics}}build(){let e=this.validate();if(e.length>0)throw new Error(`Workflow validation failed: ${e.join(", ")}`);return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins,renderConfig:this.config.getWorkflowRenderConfig()}}toJSON(){return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins.map(e=>({name:e.name,version:e.version}))}}fromJSON(e){return this.workflowId=e.workflowId,this.workflowName=e.workflowName,this.workflowDescription=e.workflowDescription,this.steps=e.steps,this.analytics=e.analytics,this.persistenceConfig=e.persistence,this.plugins=e.plugins||[],this}};function Be(r,e,t,i){return L.create(r,e,t,i)}ril.prototype.flow=function(r,e,t){return L.create(this,r,e,t)};var Me=1751361139160,Oe="8fdb6a454550326d331c3b3d1d1f8c707a371bdb6c7ea72a0a1e4ea6f1822620",k=class k{static async setLicenseKey(e){k.licenseKey=e||"",k.licenseKey?k.licenseResult=await k.validateLicense():k.licenseResult={valid:false,error:"MISSING"},k.isInitialized=true;}static async validateLicense(){if(!k.licenseKey)return {valid:false,error:"MISSING"};try{if(!k.licenseKey.startsWith("ril_"))return {valid:!1,error:"FORMAT_INVALID"};let e=k.licenseKey.slice(4),i=k.base64ToString(e).split(".");if(i.length!==3)return {valid:!1,error:"FORMAT_INVALID"};let[n,o,s]=i,p=`${n}.${o}`,g=new TextEncoder().encode(p),a=s.match(/.{2}/g);if(!a)return {valid:!1,error:"INVALID"};let l=new Uint8Array(a.map(W=>Number.parseInt(W,16))),f=k.hexToBytes(Oe);if(!await ge.verify(l,g,f))return {valid:!1,error:"SIGNATURE_INVALID"};let y=k.base64ToString(o.replace(/-/g,"+").replace(/_/g,"/")),c=JSON.parse(y),d=Math.floor(Date.now()/1e3);return c.e<d?{valid:!1,error:"EXPIRED",data:k.decompressPayload(c)}:Me>c.e*1e3?{valid:!1,error:"EXPIRED",data:k.decompressPayload(c)}:c.p===void 0||!c.c||!c.i||!c.e||!c.t?{valid:!1,error:"INVALID"}:{valid:!0,data:k.decompressPayload(c)}}catch{return {valid:false,error:"INVALID"}}}static decompressPayload(e){return {plan:{0:"ARCHITECT",1:"FOUNDRY"}[e.p]||"ARCHITECT",company:e.c,customerId:e.i.toString(),expiry:e.e*1e3,iat:e.t*1e3}}static hexToBytes(e){let t=new Uint8Array(e.length/2);for(let i=0;i<e.length;i+=2)t[i/2]=Number.parseInt(e.substring(i,i+2),16);return t}static base64ToString(e){if(typeof atob<"u")return atob(e);if(typeof Buffer<"u")return Buffer.from(e,"base64").toString();let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i="",n=0,o=e.replace(/[^A-Za-z0-9+/]/g,"");for(;n<o.length;){let s=t.indexOf(o.charAt(n++)),p=t.indexOf(o.charAt(n++)),g=t.indexOf(o.charAt(n++)),a=t.indexOf(o.charAt(n++)),l=s<<18|p<<12|g<<6|a;i+=String.fromCharCode(l>>16&255),g!==64&&(i+=String.fromCharCode(l>>8&255)),a!==64&&(i+=String.fromCharCode(l&255));}return i}static getLicenseResult(){return k.isInitialized?k.licenseResult?k.licenseResult:{valid:false,error:"MISSING"}:{valid:false,error:"MISSING"}}static shouldDisplayWatermark(){return typeof window>"u"?false:!k.getLicenseResult().valid}static getWatermarkMessage(){let e=k.getLicenseResult();return {MISSING:"Rilay Workflow - For Trial Use Only",EXPIRED:"Rilay Workflow - License Expired",INVALID:"Rilay Workflow - Invalid License",FORMAT_INVALID:"Rilay Workflow - Invalid License Format",SIGNATURE_INVALID:"Rilay Workflow - Invalid License Signature"}[e.error||"MISSING"]||""}static logLicenseStatus(){let e=k.getLicenseResult();if(e.valid)return;let i={MISSING:"\u{1F527} Rilay Workflow - Trial Mode. Purchase a license at https://rilay.io/pricing",EXPIRED:"\u26A0\uFE0F Rilay Workflow - License Expired. Please renew your license.",INVALID:"\u274C Rilay Workflow - Invalid License. Please check your license key.",FORMAT_INVALID:"\u274C Rilay Workflow - Invalid License Format. Please check your license key.",SIGNATURE_INVALID:"\u274C Rilay Workflow - Invalid License Signature. Please check your license key."}[e.error||"MISSING"];console.warn(`%c${i}`,"color: #f59e0b; font-weight: bold;");}static async getLicenseInfo(){let e=k.getLicenseResult();return !e.valid||!e.data?{}:{plan:e.data.plan,company:e.data.company,expiryDate:new Date(e.data.expiry).toLocaleDateString()}}};k.licenseKey="",k.licenseResult=null,k.isInitialized=false;var B=k;function Z(r,e={},t={}){return useMemo(()=>{if(!r)return {visible:t.visible??true,disabled:t.disabled??false,required:t.required??false,readonly:t.readonly??false};let i=n=>{try{let o;return n&&typeof n=="object"&&"build"in n?o=n.build():o=n,evaluateCondition(o,e)}catch(o){return console.warn("Error evaluating condition:",o),false}};return {visible:r.visible?i(r.visible):true,disabled:r.disabled?i(r.disabled):false,required:r.required?i(r.required):false,readonly:r.readonly?i(r.readonly):false}},[r,e,t])}function ye(r,e={}){return useMemo(()=>{let t={};for(let[i,n]of Object.entries(r))if(t[i]={visible:true,disabled:false,required:false,readonly:false},n){let o=s=>{try{return s&&typeof s=="object"&&"build"in s?evaluateCondition(s.build(),e):evaluateCondition(s,e)}catch(p){return console.warn(`Error evaluating condition for field ${i}:`,p),false}};t[i]={visible:n.visible?o(n.visible):true,disabled:n.disabled?o(n.disabled):false,required:n.required?o(n.required):false,readonly:n.readonly?o(n.readonly):false};}return t},[r,e])}function be(r,e={}){return useMemo(()=>{let t={};for(let[i,n]of Object.entries(r)){let o=Number.parseInt(i,10);if(t[o]={visible:true,disabled:false,required:false,readonly:false},n){let s=p=>{try{return p&&typeof p=="object"&&"build"in p?evaluateCondition(p.build(),e):evaluateCondition(p,e)}catch(g){return console.warn(`Error evaluating condition for step ${o}:`,g),false}};t[o]={visible:n.visible?s(n.visible):true,disabled:n.disabled?s(n.disabled):false,required:n.required?s(n.required):false,readonly:n.readonly?s(n.readonly):false};}}return t},[r,e])}var w=class extends Error{constructor(t,i,n){super(`[WorkflowPersistence] ${t} (Code: ${i})`);this.code=i;this.cause=n;this.name="WorkflowPersistenceError";}};function Y(r,e,t){return {workflowId:r,currentStepIndex:e.currentStepIndex,allData:{...e.allData},stepData:{...e.stepData},visitedSteps:Array.from(e.visitedSteps),lastSaved:Date.now(),metadata:t}}function he(r){return {currentStepIndex:r.currentStepIndex,allData:{...r.allData},stepData:{...r.stepData},visitedSteps:new Set(r.visitedSteps),isSubmitting:false,isTransitioning:false}}function Ve(r){if(!r||typeof r!="object")return false;let e=["workflowId","currentStepIndex","allData","stepData","visitedSteps","lastSaved"];for(let t of e)if(!(t in r))return false;return !(typeof r.workflowId!="string"||typeof r.currentStepIndex!="number"||typeof r.allData!="object"||typeof r.stepData!="object"||!Array.isArray(r.visitedSteps)||typeof r.lastSaved!="number")}function Q(r,e){return e?`${e}:${r}`:r}function j(r,e){let t=null;return (...i)=>{t&&clearTimeout(t),t=setTimeout(()=>{r(...i);},e);}}function _e(r,e,t="persist"){let i=he(e);switch(t){case "persist":return {...i,isSubmitting:r.isSubmitting,isTransitioning:r.isTransitioning};case "current":return {...r,visitedSteps:new Set([...r.visitedSteps,...i.visitedSteps])};case "merge":return {currentStepIndex:r.currentStepIndex,allData:{...i.allData,...r.allData},stepData:{...i.stepData,...r.stepData},visitedSteps:new Set([...i.visitedSteps,...r.visitedSteps]),isSubmitting:r.isSubmitting,isTransitioning:r.isTransitioning};default:return i}}function q({workflowId:r,workflowState:e,adapter:t,options:i={},userId:n}){let[o,s]=useState(false),[p,g]=useState(null),[a,l]=useState(false),f=useRef(t),v=useRef(i),y=useRef({hasPendingChanges:false});useEffect(()=>{f.current=t,v.current=i;},[t,i]);let c=Q(v.current.storageKey||r,n),d=useCallback(()=>{g(null);},[]),P=useCallback((S,x)=>{let C=S instanceof w?S:new w(`${x} failed: ${S.message}`,"OPERATION_FAILED",S);g(C),console.error("[WorkflowPersistence]",C);},[]),W=useCallback(async S=>{d(),s(true);try{let x=Y(r,S,v.current.metadata);await f.current.save(c,x),y.current.lastSavedState={...S},y.current.hasPendingChanges=!1;}catch(x){throw P(x,"Save"),x}finally{s(false);}},[r,c,d,P]),m=useRef(j(async S=>{try{await W(S);}catch(x){console.debug("[WorkflowPersistence] Auto-save failed:",x);}},i.debounceMs||500)),h=useCallback((S,x)=>x?S.currentStepIndex!==x.currentStepIndex||JSON.stringify(S.allData)!==JSON.stringify(x.allData)||JSON.stringify(S.stepData)!==JSON.stringify(x.stepData)||S.visitedSteps.size!==x.visitedSteps.size||!Array.from(S.visitedSteps).every(C=>x.visitedSteps.has(C)):true,[]),I=useCallback(async()=>{d(),l(true);try{let S=await f.current.load(c);return S&&(y.current.lastSavedState={currentStepIndex:S.currentStepIndex,allData:S.allData,stepData:S.stepData,visitedSteps:new Set(S.visitedSteps),isSubmitting:!1,isTransitioning:!1,isInitializing:!1},y.current.hasPendingChanges=!1),S}catch(S){return P(S,"Load"),null}finally{setTimeout(()=>l(false),100);}},[c,d,P]),R=useCallback(async()=>{d();try{await f.current.remove(c),y.current.lastSavedState=void 0,y.current.hasPendingChanges=!1;}catch(S){throw P(S,"Clear"),S}},[c,d,P]),u=useCallback(async()=>{try{return await f.current.exists(c)}catch(S){return P(S,"Exists check"),false}},[c,P]);useEffect(()=>{v.current.autoPersist&&(o||a||e.isInitializing||e.isSubmitting||e.isTransitioning||h(e,y.current.lastSavedState)&&(y.current.hasPendingChanges=true,m.current(e)));},[e,o,a,h]);let b=useCallback(async()=>{await W(e);},[W,e]);return {isPersisting:o,persistenceError:p,persistNow:b,loadPersistedData:I,clearPersistedData:R,hasPersistedData:u}}function Ue(){let{workflowConfig:r,currentStep:e}=D(),t=useMemo(()=>e?.metadata,[e?.metadata]),i=useMemo(()=>a=>r.steps.find(f=>f.id===a)?.metadata,[r.steps]),n=useMemo(()=>a=>r.steps[a]?.metadata,[r.steps]),o=useMemo(()=>a=>t?a in t:false,[t]),s=useMemo(()=>(a,l)=>t&&a in t?t[a]:l,[t]),p=useMemo(()=>()=>r.steps.map((a,l)=>({id:a.id,title:a.title,index:l,metadata:a.metadata})),[r.steps]),g=useMemo(()=>a=>r.steps.map((l,f)=>({step:l,index:f})).filter(({step:l,index:f})=>a(l.metadata,l.id,f)).map(({step:l})=>l.id),[r.steps]);return {current:t,getByStepId:i,getByStepIndex:n,hasCurrentKey:o,getCurrentValue:s,getAllStepsMetadata:p,findStepsByMetadata:g}}function te({workflowConfig:r,workflowState:e,workflowContext:t}){let i=useRef(Date.now()),n=useRef(new Map),o=useRef(false),s=useRef(null);useEffect(()=>{r.analytics?.onWorkflowStart&&!o.current&&(o.current=true,r.analytics.onWorkflowStart(r.id,t));},[r.id,r.analytics,t]),useEffect(()=>{let a=r.steps[e.currentStepIndex];if(a&&s.current!==a.id){if(s.current&&r.analytics?.onStepComplete){let l=n.current.get(s.current);l&&r.analytics.onStepComplete(s.current,Date.now()-l,e.stepData,t);}s.current=a.id,n.current.set(a.id,Date.now()),r.analytics?.onStepStart&&r.analytics.onStepStart(a.id,Date.now(),t);}},[e.currentStepIndex,r.steps,r.analytics,t,e.stepData]);let p=useCallback((a,l)=>{r.analytics?.onStepSkip&&r.analytics.onStepSkip(a,l,t);},[r.analytics,t]),g=useCallback(a=>{r.analytics?.onError&&r.analytics.onError(a,t);},[r.analytics,t]);return {analyticsStartTime:i,trackStepSkip:p,trackError:g}}function xe(r,e){return {visible:r.visible,skippable:e===true||r.required}}function re({workflowConfig:r,workflowState:e,currentStep:t}){let i=useMemo(()=>({...e.allData,...e.stepData}),[e.allData,e.stepData]),n=useMemo(()=>{if(t?.conditions)return {visible:t.conditions.visible,required:t.conditions.skippable}},[t?.conditions]),o=Z(n,i,{visible:true,disabled:false,required:false,readonly:false}),s=useMemo(()=>xe(o,t?.allowSkip),[o,t?.allowSkip]),p=useMemo(()=>{let m={};return r.steps.forEach((h,I)=>{h.conditions&&(m[I]={visible:h.conditions.visible,required:h.conditions.skippable});}),m},[r.steps]),g=be(p,i),a=useMemo(()=>{let m={};return r.steps.forEach((h,I)=>{let R=g[I];R?m[I]=xe(R,h.allowSkip):m[I]={visible:true,skippable:h.allowSkip===true};}),m},[r.steps,g]),l=useMemo(()=>{if(!t?.formConfig?.allFields)return {};let m={};for(let h of t.formConfig.allFields)h.conditions&&(m[h.id]=h.conditions);return m},[t?.formConfig?.allFields]),f=ye(l,i),v=useCallback(m=>m<0||m>=r.steps.length?false:a[m]?.visible??true,[a,r.steps.length]),y=useCallback(m=>m<0||m>=r.steps.length?false:a[m]?.skippable??false,[a,r.steps.length]),c=useCallback(m=>f[m]?.visible??true,[f]),d=useCallback(m=>f[m]?.disabled??false,[f]),P=useCallback(m=>f[m]?.required??false,[f]),W=useCallback(m=>f[m]?.readonly??false,[f]);return {stepConditions:s,fieldConditions:f,allStepConditions:a,isStepVisible:v,isStepSkippable:y,isFieldVisible:c,isFieldDisabled:d,isFieldRequired:P,isFieldReadonly:W}}function ie({workflowConfig:r,workflowState:e,workflowContext:t,conditionsHelpers:i,setCurrentStep:n,setTransitioning:o,markStepVisited:s,setStepData:p,onStepChange:g}){let a=useRef(g);a.current=g;let l=r.steps[e.currentStepIndex],f=useCallback(()=>({setStepData:(u,b)=>{p(b,u);},setStepFields:(u,b)=>{let x={...e.allData[u]||{},...b};p(x,u);},getStepData:u=>e.allData[u]||{},setNextStepField:(u,b)=>{let S=e.currentStepIndex+1;if(S<r.steps.length){let x=r.steps[S].id,_={...e.allData[x]||{},[u]:b};p(_,x);}},setNextStepFields:u=>{let b=e.currentStepIndex+1;if(b<r.steps.length){let S=r.steps[b].id,C={...e.allData[S]||{},...u};p(C,S);}},getAllData:()=>({...e.allData}),getSteps:()=>[...r.steps]}),[e.allData,e.currentStepIndex,r.steps,p]),v=useCallback(async u=>{if(u<0||u>=r.steps.length||!i.isStepVisible(u))return false;o(true);try{return a.current&&a.current(e.currentStepIndex,u,t),n(u),s(u,r.steps[u].id),!0}catch(b){return console.error("Step transition failed:",b),r.analytics?.onError&&r.analytics.onError(b,t),false}finally{o(false);}},[r.steps,r.analytics,i,e.currentStepIndex,t,o,n,s]),y=useCallback(u=>{for(let b=u+1;b<r.steps.length;b++)if(i.isStepVisible(b))return b;return null},[r.steps.length,i]),c=useCallback(u=>{for(let b=u-1;b>=0;b--)if(i.isStepVisible(b))return b;return null},[i]),d=useCallback(async()=>{if(l?.onAfterValidation)try{let b=f();await l.onAfterValidation(e.stepData,b,t);}catch(b){return console.error("onAfterValidation failed:",b),r.analytics?.onError&&r.analytics.onError(b,t),false}let u=y(e.currentStepIndex);return u===null?false:v(u)},[l,f,e.stepData,t,r.analytics,e.currentStepIndex,y,v]),P=useCallback(async()=>{let u=c(e.currentStepIndex);return u===null?false:v(u)},[e.currentStepIndex,c,v]),W=useCallback(async()=>!l?.allowSkip&&!i.isStepSkippable(e.currentStepIndex)?false:(r.analytics?.onStepSkip&&r.analytics.onStepSkip(l.id,"user_skip",t),d()),[l,i,e.currentStepIndex,r.analytics,t,d]),m=useCallback(u=>u<0||u>=r.steps.length?false:i.isStepVisible(u),[r.steps.length,i]),h=useCallback(()=>{let u=y(e.currentStepIndex);return u!==null&&m(u)},[e.currentStepIndex,y,m]),I=useCallback(()=>{let u=c(e.currentStepIndex);return u!==null&&m(u)},[e.currentStepIndex,c,m]),R=useCallback(()=>l?.allowSkip===true&&i.isStepSkippable(e.currentStepIndex),[l?.allowSkip,i,e.currentStepIndex]);return {goToStep:v,goNext:d,goPrevious:P,skipStep:W,canGoToStep:m,canGoNext:h,canGoPrevious:I,canSkipCurrentStep:R}}function qe(r,e){switch(e.type){case "SET_CURRENT_STEP":return {...r,currentStepIndex:e.stepIndex};case "SET_STEP_DATA":return {...r,stepData:e.data,allData:{...r.allData,[e.stepId]:e.data}};case "SET_ALL_DATA":return {...r,allData:e.data};case "SET_FIELD_VALUE":{let t={...r.stepData,[e.fieldId]:e.value};return {...r,stepData:t,allData:{...r.allData,[e.stepId]:t}}}case "SET_SUBMITTING":return {...r,isSubmitting:e.isSubmitting};case "SET_TRANSITIONING":return {...r,isTransitioning:e.isTransitioning};case "MARK_STEP_VISITED":return {...r,visitedSteps:new Set([...r.visitedSteps,e.stepId])};case "RESET_WORKFLOW":return {currentStepIndex:0,allData:{},stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:false};case "LOAD_PERSISTED_STATE":return {...r,...e.state};case "SET_INITIALIZATION_COMPLETE":return {...r,isInitializing:false};default:return r}}function ne({defaultValues:r={},persistence:e}){let t={currentStepIndex:0,allData:r,stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:true},[i,n]=useReducer(qe,t),o=e?.adapter?q({workflowId:e.workflowId,workflowState:i,adapter:e.adapter,options:e.options,userId:e.userId}):null,s=useCallback(d=>{n({type:"SET_CURRENT_STEP",stepIndex:d});},[]),p=useCallback((d,P)=>{n({type:"SET_STEP_DATA",data:d,stepId:P});},[]),g=useCallback((d,P,W)=>{n({type:"SET_FIELD_VALUE",fieldId:d,value:P,stepId:W});},[]),a=useCallback(d=>{n({type:"SET_SUBMITTING",isSubmitting:d});},[]),l=useCallback(d=>{n({type:"SET_TRANSITIONING",isTransitioning:d});},[]),f=useCallback((d,P)=>{n({type:"MARK_STEP_VISITED",stepIndex:d,stepId:P});},[]),v=useCallback(()=>{n({type:"RESET_WORKFLOW"});},[]),y=useCallback(()=>{n({type:"SET_INITIALIZATION_COMPLETE"});},[]),c=useCallback(async()=>{if(!o)return y(),false;try{let d=await o.loadPersistedData();if(d){let P={currentStepIndex:d.currentStepIndex,allData:d.allData,stepData:d.stepData,visitedSteps:new Set(d.visitedSteps)};return n({type:"LOAD_PERSISTED_STATE",state:P}),y(),!0}}catch(d){console.error("Failed to load persisted state:",d);}return y(),false},[o,y]);return {workflowState:i,setCurrentStep:s,setStepData:p,setFieldValue:g,setSubmitting:a,setTransitioning:l,markStepVisited:f,resetWorkflow:v,loadPersistedState:c,persistence:o?{isPersisting:o.isPersisting,persistenceError:o.persistenceError,persistNow:o.persistNow,clearPersistedData:o.clearPersistedData,hasPersistedData:o.hasPersistedData}:null}}function oe({workflowConfig:r,workflowState:e,workflowContext:t,setSubmitting:i,onWorkflowComplete:n,analyticsStartTime:o}){let s=useRef(n);s.current=n;let p=useCallback(async()=>{i(true);try{if(s.current&&await s.current(e.allData),r.analytics?.onWorkflowComplete){let a=Date.now()-o.current;r.analytics.onWorkflowComplete(r.id,a,e.allData);}}catch(a){throw console.error("Workflow submission failed:",a),r.analytics?.onError&&r.analytics.onError(a,t),a}finally{i(false);}},[e.allData,r.analytics,r.id,t,o,i]),g=useCallback(()=>e.isSubmitting?false:e.currentStepIndex===r.steps.length-1,[e.isSubmitting,e.currentStepIndex,r.steps.length]);return {submitWorkflow:p,isSubmitting:e.isSubmitting,canSubmit:g()}}var De=createContext(null);function ae({children:r,workflowConfig:e,defaultValues:t={},onStepChange:i,onWorkflowComplete:n,className:o}){let{workflowState:s,setCurrentStep:p,setStepData:g,setFieldValue:a,setSubmitting:l,setTransitioning:f,markStepVisited:v,resetWorkflow:y,loadPersistedState:c,persistence:d}=ne({defaultValues:t,persistence:e.persistence?{workflowId:e.id,adapter:e.persistence.adapter,options:e.persistence.options,userId:e.persistence.userId}:void 0});useEffect(()=>{e.persistence&&c&&c();},[]);let P=d?.isPersisting??false,W=d?.persistenceError??null,m=d?.persistNow,h=useMemo(()=>({workflowId:e.id,currentStepIndex:s.currentStepIndex,totalSteps:e.steps.length,allData:s.allData,stepData:s.stepData,isFirstStep:s.currentStepIndex===0,isLastStep:s.currentStepIndex===e.steps.length-1,visitedSteps:s.visitedSteps}),[e.id,e.steps.length,s.currentStepIndex,s.allData,s.stepData,s.visitedSteps]),I=useMemo(()=>e.steps[s.currentStepIndex],[e.steps,s.currentStepIndex]),R=useMemo(()=>I?.formConfig,[I]),{analyticsStartTime:u}=te({workflowConfig:e,workflowState:s,workflowContext:h}),b=re({workflowConfig:e,workflowState:s,currentStep:I}),{goToStep:S,goNext:x,goPrevious:C,skipStep:_,canGoToStep:pe,canGoNext:ce,canGoPrevious:de,canSkipCurrentStep:ue}=ie({workflowConfig:e,workflowState:s,workflowContext:h,conditionsHelpers:b,setCurrentStep:p,setTransitioning:f,markStepVisited:v,setStepData:g,onStepChange:i});useEffect(()=>{if(!b.isStepVisible(s.currentStepIndex)){for(let A=0;A<e.steps.length;A++)if(b.isStepVisible(A)){p(A),v(A,e.steps[A].id);break}}},[b,s.currentStepIndex,e.steps,p,v]);let{submitWorkflow:U,isSubmitting:fe,canSubmit:me}=oe({workflowConfig:e,workflowState:s,workflowContext:h,setSubmitting:l,onWorkflowComplete:n,analyticsStartTime:u}),J=useCallback((K,A)=>{a(K,A,I?.id||"");},[a,I?.id]),Se=useCallback(K=>{g(K,I?.id||"");},[g,I?.id]),Re=useCallback(async()=>{h.isLastStep?await U():await x();},[h.isLastStep,U,x]),Ce=useMemo(()=>({workflowState:s,workflowConfig:e,currentStep:I,context:h,formConfig:R,conditionsHelpers:b,currentStepMetadata:I?.metadata,goToStep:S,goNext:x,goPrevious:C,skipStep:_,canGoToStep:pe,canGoNext:ce,canGoPrevious:de,canSkipCurrentStep:ue,setValue:J,setStepData:Se,resetWorkflow:y,submitWorkflow:U,isSubmitting:fe,canSubmit:me,persistNow:m,isPersisting:P,persistenceError:W}),[s,e,I,h,R,b,S,x,C,_,pe,ce,de,ue,J,Se,y,U,fe,me,m,P,W]);return jsx(De.Provider,{value:Ce,children:jsx(FormProvider,{formConfig:R,defaultValues:s?.allData[I?.id]||{},onFieldChange:J,"data-workflow-id":e.id,className:o,onSubmit:Re,children:r},s.isInitializing.toString())})}function D(){let r=useContext(De);if(!r)throw new Error("useWorkflowContext must be used within a WorkflowProvider");return r}function Qe({children:r,workflowConfig:e,...t}){let[i,n]=useState(),o=useMemo(()=>e instanceof L?e.build():e,[e]);return useEffect(()=>{if(typeof window<"u"&&B.shouldDisplayWatermark()){let p=B.getWatermarkMessage();n(p);}},[]),jsxs("div",{style:{position:"relative"},children:[jsx(ae,{...t,workflowConfig:o,children:r}),i&&jsx("div",{style:{position:"absolute",top:"10px",right:"10px",background:"rgba(0, 0, 0, 0.8)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",zIndex:1e3,pointerEvents:"none",opacity:.7},children:i})]})}function tt({stepId:r,children:e}){let{currentStep:t}=D();if(!t||r&&t.id!==r)return null;let{formConfig:i,renderer:n}=t;return i?n?n(t):e??jsx(FormBody,{}):null}function ot({className:r,isSubmitting:e,...t}){let{context:i,workflowState:n,workflowConfig:o,currentStep:s}=D(),{submit:p,formState:g}=useFormContext(),a=g.isSubmitting||n.isSubmitting,l=e??a,f=!n.isTransitioning&&!l,v=async c=>{c?.preventDefault(),f&&await p(c);},y={isLastStep:i.isLastStep,canGoNext:f,isSubmitting:l,onSubmit:v,className:r,currentStep:s,stepData:g.values||{},allData:i.allData,context:i};return jsx(ComponentRendererWrapper,{name:"WorkflowNextButton",renderer:o.renderConfig?.nextButtonRenderer,props:y,...t})}function pt({className:r,isSubmitting:e,...t}){let{context:i,goPrevious:n,workflowState:o,workflowConfig:s,currentStep:p}=D(),{formState:g}=useFormContext(),a=g.isSubmitting||o.isSubmitting,l=e??a,f=i.currentStepIndex>0&&!o.isTransitioning&&!l,y={canGoPrevious:f,isSubmitting:l,onPrevious:async c=>{c?.preventDefault(),f&&await n();},className:r,currentStep:p,stepData:g.values||{},allData:i.allData,context:i};return jsx(ComponentRendererWrapper,{name:"WorkflowPreviousButton",renderer:s.renderConfig?.previousButtonRenderer,props:y,...t})}function ft({className:r,isSubmitting:e,...t}){let{currentStep:i,skipStep:n,workflowState:o,workflowConfig:s,context:p,conditionsHelpers:g}=D(),{formState:a}=useFormContext(),l=a.isSubmitting||o.isSubmitting,f=e??l,v=(!!i?.allowSkip||g.isStepSkippable(o.currentStepIndex))&&!o.isTransitioning&&!f,c={canSkip:v,isSubmitting:f,onSkip:async d=>{d?.preventDefault(),v&&await n();},className:r,currentStep:i,stepData:a.values||{},allData:p.allData,context:p};return jsx(ComponentRendererWrapper,{name:"WorkflowSkipButton",renderer:s.renderConfig?.skipButtonRenderer,props:c,...t})}function yt({onStepClick:r,className:e,...t}){let{workflowConfig:i,workflowState:n,goToStep:o,conditionsHelpers:s}=D(),{visibleSteps:p,visibleToOriginalIndexMap:g,originalToVisibleIndexMap:a}=useMemo(()=>{let y=[],c=new Map,d=new Map;return i.steps.forEach((P,W)=>{if(s.isStepVisible(W)){let m=y.length;y.push(P),c.set(m,W),d.set(W,m);}}),{visibleSteps:y,visibleToOriginalIndexMap:c,originalToVisibleIndexMap:d}},[i.steps,s]),l=y=>{let c=g.get(y);c!==void 0&&(r?r(c):o(c));},f=a.get(n.currentStepIndex)??-1,v={steps:p,currentStepIndex:f,visitedSteps:n.visitedSteps,onStepClick:l,className:e};return jsx(ComponentRendererWrapper,{name:"WorkflowStepper",renderer:i.renderConfig?.stepperRenderer,props:v,...t})}var le=class{constructor(e={}){this.version="1.0.0";this.keyPrefix=e.keyPrefix??"rilay_workflow_",this.compress=e.compress??false,this.maxAge=e.maxAge,this._isAvailable=this.isLocalStorageAvailable();}async save(e,t){if(this._isAvailable)try{let i=this.getStorageKey(e),n={data:{...t,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},o=JSON.stringify(n),s=this.compress?this.compressData(o):o;localStorage.setItem(i,s);}catch(i){if(i instanceof Error)if(i.name==="QuotaExceededError"||i.message.includes("quota")){await this.clearExpiredData();try{let n=this.getStorageKey(e),o={data:{...t,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},s=JSON.stringify(o),p=this.compress?this.compressData(s):s;localStorage.setItem(n,p);}catch(n){throw new w("localStorage quota exceeded and cleanup failed","QUOTA_EXCEEDED",n)}}else throw new w(`Failed to save to localStorage: ${i.message}`,"SAVE_FAILED",i);else throw new w("Unknown error occurred while saving","SAVE_FAILED")}}async load(e){if(!this._isAvailable)return null;try{let t=this.getStorageKey(e),i=localStorage.getItem(t);if(!i)return null;let n=this.compress?this.decompressData(i):i,o=JSON.parse(n);return o.expiresAt&&Date.now()>o.expiresAt?(await this.remove(e),null):{...o.data,visitedSteps:Array.isArray(o.data.visitedSteps)?o.data.visitedSteps:[]}}catch(t){throw t instanceof Error?new w(`Failed to load from localStorage: ${t.message}`,"LOAD_FAILED",t):new w("Unknown error occurred while loading","LOAD_FAILED")}}async remove(e){if(this._isAvailable)try{let t=this.getStorageKey(e);localStorage.removeItem(t);}catch(t){throw t instanceof Error?new w(`Failed to remove from localStorage: ${t.message}`,"REMOVE_FAILED",t):new w("Unknown error occurred while removing","REMOVE_FAILED")}}async exists(e){if(!this._isAvailable)return false;try{let t=this.getStorageKey(e),i=localStorage.getItem(t);if(!i)return !1;let n=this.compress?this.decompressData(i):i,o=JSON.parse(n);return o.expiresAt&&Date.now()>o.expiresAt?(await this.remove(e),!1):!0}catch{return false}}async listKeys(){if(!this._isAvailable)return [];try{let e=[];for(let t=0;t<localStorage.length;t++){let i=localStorage.key(t);if(i?.startsWith(this.keyPrefix)){let n=i.substring(this.keyPrefix.length);await this.exists(n)&&e.push(n);}}return e}catch(e){throw e instanceof Error?new w(`Failed to list keys: ${e.message}`,"LIST_FAILED",e):new w("Unknown error occurred while listing keys","LIST_FAILED")}}async clear(){try{let e=[];for(let t=0;t<localStorage.length;t++){let i=localStorage.key(t);i?.startsWith(this.keyPrefix)&&e.push(i);}for(let t of e)localStorage.removeItem(t);}catch(e){throw e instanceof Error?new w(`Failed to clear localStorage: ${e.message}`,"CLEAR_FAILED",e):new w("Unknown error occurred while clearing","CLEAR_FAILED")}}getStorageKey(e){return `${this.keyPrefix}${e}`}isLocalStorageAvailable(){try{let e="__rilay_test__";return localStorage.setItem(e,"test"),localStorage.removeItem(e),!0}catch{return false}}compressData(e){return btoa(e)}decompressData(e){try{return atob(e)}catch{return e}}async clearExpiredData(){if(!this._isAvailable)return;let e=[];for(let t=0;t<localStorage.length;t++){let i=localStorage.key(t);if(i?.startsWith(this.keyPrefix))try{let n=localStorage.getItem(i);if(n){let o=this.compress?this.decompressData(n):n,s=JSON.parse(o);s.expiresAt&&Date.now()>s.expiresAt&&e.push(i);}}catch{e.push(i);}}for(let t of e)localStorage.removeItem(t);}};
|
|
2
|
-
export{
|
|
1
|
+
import {ComponentRendererWrapper,IdGenerator,normalizeToArray,deepClone,ensureUnique,getGlobalMonitor,evaluateCondition}from'@rilaykit/core';import {FormBody,useFormContext,form,FormProvider}from'@rilaykit/forms';import ft,{createContext,useMemo,useCallback,useContext,useState,useRef,useEffect,useReducer}from'react';import*as Pe from'@noble/ed25519';import {jsx,jsxs}from'react/jsx-runtime';var V=class t{constructor(e,r,n,i){this.steps=[];this.plugins=[];this.idGenerator=new IdGenerator;this.config=e,this.workflowId=r,this.workflowName=n,this.workflowDescription=i;}static create(e,r,n,i){return new t(e,r,n,i)}createStepFromDefinition(e){return {id:e.id||this.idGenerator.next("step"),title:e.title,description:e.description,formConfig:e.formConfig instanceof form?e.formConfig.build():e.formConfig,allowSkip:e.allowSkip||false,renderer:e.renderer,conditions:e.conditions,metadata:e.metadata,onAfterValidation:e.onAfterValidation}}addStep(e){let r=normalizeToArray(e);for(let n of r){let i=this.createStepFromDefinition(n);this.steps.push(i);}return this}configure(e){return e.analytics&&(this.analytics=e.analytics),e.persistence&&(this.persistenceConfig=e.persistence),this}use(e){this.validatePluginDependencies(e),this.plugins.push(e);try{e.install(this);}catch(r){throw new Error(`Failed to install plugin "${e.name}": ${r instanceof Error?r.message:String(r)}`)}return this}validatePluginDependencies(e){if(!e.dependencies)return;let r=e.dependencies.filter(n=>!this.plugins.some(i=>i.name===n));if(r.length>0)throw new Error(`Plugin "${e.name}" requires missing dependencies: ${r.join(", ")}`)}removePlugin(e){return this.plugins=this.plugins.filter(r=>r.name!==e),this}updateStep(e,r){let n=this.steps.findIndex(i=>i.id===e);if(n===-1)throw new Error(`Step with ID "${e}" not found`);return this.steps[n]={...this.steps[n],...r},this}addStepConditions(e,r){let n=this.steps.findIndex(s=>s.id===e);if(n===-1)throw new Error(`Step with ID "${e}" not found`);let i={...this.steps[n].conditions,...r};return this.steps[n]={...this.steps[n],conditions:i},this}removeStep(e){return this.steps=this.steps.filter(r=>r.id!==e),this}getStep(e){return this.steps.find(r=>r.id===e)}getSteps(){return [...this.steps]}clearSteps(){return this.steps=[],this.idGenerator.reset(),this}clone(e,r){let n=new t(this.config,e||`${this.workflowId}-clone`,r||this.workflowName);return n.steps=deepClone(this.steps),n.analytics=this.analytics?deepClone(this.analytics):void 0,n.persistenceConfig=this.persistenceConfig?deepClone(this.persistenceConfig):void 0,n.plugins=[...this.plugins],n}validate(){let e=[];this.steps.length===0&&e.push("Workflow must have at least one step");let r=this.steps.map(n=>n.id);try{ensureUnique(r,"step");}catch(n){e.push(n instanceof Error?n.message:String(n));}for(let n of this.plugins)if(n.dependencies){let i=n.dependencies.filter(s=>!this.plugins.some(o=>o.name===s));i.length>0&&e.push(`Plugin "${n.name}" requires missing dependencies: ${i.join(", ")}`);}return e}getStats(){let e=this.steps.reduce((n,i)=>n+i.formConfig.allFields.length,0),r=this.steps.map(n=>n.formConfig.allFields.length);return {totalSteps:this.steps.length,totalFields:e,averageFieldsPerStep:this.steps.length>0?e/this.steps.length:0,maxFieldsInStep:r.length>0?Math.max(...r):0,minFieldsInStep:r.length>0?Math.min(...r):0,hasAnalytics:!!this.analytics}}build(){let e=this.validate();if(e.length>0)throw new Error(`Workflow validation failed: ${e.join(", ")}`);return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins,renderConfig:this.config.getWorkflowRenderConfig()}}toJSON(){return {id:this.workflowId,name:this.workflowName,description:this.workflowDescription,steps:this.steps,analytics:this.analytics,persistence:this.persistenceConfig,plugins:this.plugins.map(e=>({name:e.name,version:e.version}))}}fromJSON(e){return this.workflowId=e.workflowId,this.workflowName=e.workflowName,this.workflowDescription=e.workflowDescription,this.steps=e.steps,this.analytics=e.analytics,this.persistenceConfig=e.persistence,this.plugins=e.plugins||[],this}};var Xe=1751361139160,He="8fdb6a454550326d331c3b3d1d1f8c707a371bdb6c7ea72a0a1e4ea6f1822620",x=class x{static async setLicenseKey(e){x.licenseKey=e||"",x.licenseKey?x.licenseResult=await x.validateLicense():x.licenseResult={valid:false,error:"MISSING"},x.isInitialized=true;}static async validateLicense(){if(!x.licenseKey)return {valid:false,error:"MISSING"};try{if(!x.licenseKey.startsWith("ril_"))return {valid:!1,error:"FORMAT_INVALID"};let e=x.licenseKey.slice(4),n=x.base64ToString(e).split(".");if(n.length!==3)return {valid:!1,error:"FORMAT_INVALID"};let[i,s,o]=n,a=`${i}.${s}`,c=new TextEncoder().encode(a),l=o.match(/.{2}/g);if(!l)return {valid:!1,error:"INVALID"};let p=new Uint8Array(l.map(W=>Number.parseInt(W,16))),f=x.hexToBytes(He);if(!await Pe.verify(p,c,f))return {valid:!1,error:"SIGNATURE_INVALID"};let m=x.base64ToString(s.replace(/-/g,"+").replace(/_/g,"/")),d=JSON.parse(m),u=Math.floor(Date.now()/1e3);return d.e<u?{valid:!1,error:"EXPIRED",data:x.decompressPayload(d)}:Xe>d.e*1e3?{valid:!1,error:"EXPIRED",data:x.decompressPayload(d)}:d.p===void 0||!d.c||!d.i||!d.e||!d.t?{valid:!1,error:"INVALID"}:{valid:!0,data:x.decompressPayload(d)}}catch{return {valid:false,error:"INVALID"}}}static decompressPayload(e){return {plan:{0:"ARCHITECT",1:"FOUNDRY"}[e.p]||"ARCHITECT",company:e.c,customerId:e.i.toString(),expiry:e.e*1e3,iat:e.t*1e3}}static hexToBytes(e){let r=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)r[n/2]=Number.parseInt(e.substring(n,n+2),16);return r}static base64ToString(e){if(typeof atob<"u")return atob(e);if(typeof Buffer<"u")return Buffer.from(e,"base64").toString();let r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",i=0,s=e.replace(/[^A-Za-z0-9+/]/g,"");for(;i<s.length;){let o=r.indexOf(s.charAt(i++)),a=r.indexOf(s.charAt(i++)),c=r.indexOf(s.charAt(i++)),l=r.indexOf(s.charAt(i++)),p=o<<18|a<<12|c<<6|l;n+=String.fromCharCode(p>>16&255),c!==64&&(n+=String.fromCharCode(p>>8&255)),l!==64&&(n+=String.fromCharCode(p&255));}return n}static getLicenseResult(){return x.isInitialized?x.licenseResult?x.licenseResult:{valid:false,error:"MISSING"}:{valid:false,error:"MISSING"}}static shouldDisplayWatermark(){return typeof window>"u"?false:!x.getLicenseResult().valid}static getWatermarkMessage(){let e=x.getLicenseResult();return {MISSING:"Rilay Workflow - For Trial Use Only",EXPIRED:"Rilay Workflow - License Expired",INVALID:"Rilay Workflow - Invalid License",FORMAT_INVALID:"Rilay Workflow - Invalid License Format",SIGNATURE_INVALID:"Rilay Workflow - Invalid License Signature"}[e.error||"MISSING"]||""}static logLicenseStatus(){let e=x.getLicenseResult();if(e.valid)return;let n={MISSING:"\u{1F527} Rilay Workflow - Trial Mode. Purchase a license at https://rilay.io/pricing",EXPIRED:"\u26A0\uFE0F Rilay Workflow - License Expired. Please renew your license.",INVALID:"\u274C Rilay Workflow - Invalid License. Please check your license key.",FORMAT_INVALID:"\u274C Rilay Workflow - Invalid License Format. Please check your license key.",SIGNATURE_INVALID:"\u274C Rilay Workflow - Invalid License Signature. Please check your license key."}[e.error||"MISSING"];console.warn(`%c${n}`,"color: #f59e0b; font-weight: bold;");}static async getLicenseInfo(){let e=x.getLicenseResult();return !e.valid||!e.data?{}:{plan:e.data.plan,company:e.data.company,expiryDate:new Date(e.data.expiry).toLocaleDateString()}}};x.licenseKey="",x.licenseResult=null,x.isInitialized=false;var F=x;function Q(t,e={},r={}){return useMemo(()=>{if(!t)return {visible:r.visible??true,disabled:r.disabled??false,required:r.required??false,readonly:r.readonly??false};let n=i=>{try{let s;return i&&typeof i=="object"&&"build"in i?s=i.build():s=i,evaluateCondition(s,e)}catch(s){return console.warn("Error evaluating condition:",s),false}};return {visible:t.visible?n(t.visible):true,disabled:t.disabled?n(t.disabled):false,required:t.required?n(t.required):false,readonly:t.readonly?n(t.readonly):false}},[t,e,r])}function Ie(t,e={}){return useMemo(()=>{let r={};for(let[n,i]of Object.entries(t))if(r[n]={visible:true,disabled:false,required:false,readonly:false},i){let s=o=>{try{return o&&typeof o=="object"&&"build"in o?evaluateCondition(o.build(),e):evaluateCondition(o,e)}catch(a){return console.warn(`Error evaluating condition for field ${n}:`,a),false}};r[n]={visible:i.visible?s(i.visible):true,disabled:i.disabled?s(i.disabled):false,required:i.required?s(i.required):false,readonly:i.readonly?s(i.readonly):false};}return r},[t,e])}function We(t,e={}){return useMemo(()=>{let r={};for(let[n,i]of Object.entries(t)){let s=Number.parseInt(n,10);if(r[s]={visible:true,disabled:false,required:false,readonly:false},i){let o=a=>{try{return a&&typeof a=="object"&&"build"in a?evaluateCondition(a.build(),e):evaluateCondition(a,e)}catch(c){return console.warn(`Error evaluating condition for step ${s}:`,c),false}};r[s]={visible:i.visible?o(i.visible):true,disabled:i.disabled?o(i.disabled):false,required:i.required?o(i.required):false,readonly:i.readonly?o(i.readonly):false};}}return r},[t,e])}var D=class extends Error{constructor(r,n,i){super(`[WorkflowPersistence] ${r} (Code: ${n})`);this.code=n;this.cause=i;this.name="WorkflowPersistenceError";}};function j(t,e,r){return {workflowId:t,currentStepIndex:e.currentStepIndex,allData:{...e.allData},stepData:{...e.stepData},visitedSteps:Array.from(e.visitedSteps),lastSaved:Date.now(),metadata:r}}function De(t){return {currentStepIndex:t.currentStepIndex,allData:{...t.allData},stepData:{...t.stepData},visitedSteps:new Set(t.visitedSteps),isSubmitting:false,isTransitioning:false}}function Ze(t){if(!t||typeof t!="object")return false;let e=["workflowId","currentStepIndex","allData","stepData","visitedSteps","lastSaved"];for(let r of e)if(!(r in t))return false;return !(typeof t.workflowId!="string"||typeof t.currentStepIndex!="number"||typeof t.allData!="object"||typeof t.stepData!="object"||!Array.isArray(t.visitedSteps)||typeof t.lastSaved!="number")}function ee(t,e){return e?`${e}:${t}`:t}function te(t,e){let r=null;return (...n)=>{r&&clearTimeout(r),r=setTimeout(()=>{t(...n);},e);}}function Ye(t,e,r="persist"){let n=De(e);switch(r){case "persist":return {...n,isSubmitting:t.isSubmitting,isTransitioning:t.isTransitioning};case "current":return {...t,visitedSteps:new Set([...t.visitedSteps,...n.visitedSteps])};case "merge":return {currentStepIndex:t.currentStepIndex,allData:{...n.allData,...t.allData},stepData:{...n.stepData,...t.stepData},visitedSteps:new Set([...n.visitedSteps,...t.visitedSteps]),isSubmitting:t.isSubmitting,isTransitioning:t.isTransitioning};default:return n}}function z({workflowId:t,workflowState:e,adapter:r,options:n={},userId:i}){let[s,o]=useState(false),[a,c]=useState(null),[l,p]=useState(false),f=useRef(r),S=useRef(n),m=useRef({hasPendingChanges:false});useEffect(()=>{f.current=r,S.current=n;},[r,n]);let d=ee(S.current.storageKey||t,i),u=useCallback(()=>{c(null);},[]),k=useCallback((b,I)=>{let T=b instanceof D?b:new D(`${I} failed: ${b.message}`,"OPERATION_FAILED",b);c(T),console.error("[WorkflowPersistence]",T);},[]),W=useCallback(async b=>{u(),o(true);try{let I=j(t,b,S.current.metadata);await f.current.save(d,I),m.current.lastSavedState={...b},m.current.hasPendingChanges=!1;}catch(I){throw k(I,"Save"),I}finally{o(false);}},[t,d,u,k]),g=useRef(te(async b=>{try{await W(b);}catch(I){console.debug("[WorkflowPersistence] Auto-save failed:",I);}},n.debounceMs||500)),h=useCallback((b,I)=>I?b.currentStepIndex!==I.currentStepIndex||JSON.stringify(b.allData)!==JSON.stringify(I.allData)||JSON.stringify(b.stepData)!==JSON.stringify(I.stepData)||b.visitedSteps.size!==I.visitedSteps.size||!Array.from(b.visitedSteps).every(T=>I.visitedSteps.has(T)):true,[]),P=useCallback(async()=>{u(),p(true);try{let b=await f.current.load(d);return b&&(m.current.lastSavedState={currentStepIndex:b.currentStepIndex,allData:b.allData,stepData:b.stepData,visitedSteps:new Set(b.visitedSteps),isSubmitting:!1,isTransitioning:!1,isInitializing:!1},m.current.hasPendingChanges=!1),b}catch(b){return k(b,"Load"),null}finally{setTimeout(()=>p(false),100);}},[d,u,k]),w=useCallback(async()=>{u();try{await f.current.remove(d),m.current.lastSavedState=void 0,m.current.hasPendingChanges=!1;}catch(b){throw k(b,"Clear"),b}},[d,u,k]),y=useCallback(async()=>{try{return await f.current.exists(d)}catch(b){return k(b,"Exists check"),false}},[d,k]);useEffect(()=>{S.current.autoPersist&&(s||l||e.isInitializing||e.isSubmitting||e.isTransitioning||h(e,m.current.lastSavedState)&&(m.current.hasPendingChanges=true,g.current(e)));},[e,s,l,h]);let v=useCallback(async()=>{await W(e);},[W,e]);return {isPersisting:s,persistenceError:a,persistNow:v,loadPersistedData:P,clearPersistedData:w,hasPersistedData:y}}function Qe(){let{workflowConfig:t,currentStep:e}=E(),r=useMemo(()=>e?.metadata,[e?.metadata]),n=useMemo(()=>l=>t.steps.find(f=>f.id===l)?.metadata,[t.steps]),i=useMemo(()=>l=>t.steps[l]?.metadata,[t.steps]),s=useMemo(()=>l=>r?l in r:false,[r]),o=useMemo(()=>(l,p)=>r&&l in r?r[l]:p,[r]),a=useMemo(()=>()=>t.steps.map((l,p)=>({id:l.id,title:l.title,index:p,metadata:l.metadata})),[t.steps]),c=useMemo(()=>l=>t.steps.map((p,f)=>({step:p,index:f})).filter(({step:p,index:f})=>l(p.metadata,p.id,f)).map(({step:p})=>p.id),[t.steps]);return {current:r,getByStepId:n,getByStepIndex:i,hasCurrentKey:s,getCurrentValue:o,getAllStepsMetadata:a,findStepsByMetadata:c}}function ne({workflowConfig:t,workflowState:e,workflowContext:r}){let n=useRef(Date.now()),i=useRef(new Map),s=useRef(false),o=useRef(null),a=getGlobalMonitor();useEffect(()=>{t.analytics?.onWorkflowStart&&!s.current&&(s.current=true,t.analytics.onWorkflowStart(t.id,r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"start",totalSteps:t.steps.length},{timestamp:Date.now(),duration:0,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:0,navigationDuration:0,conditionEvaluationDuration:0},"low"));},[t.id,t.analytics,r,a,t.steps.length]),useEffect(()=>{let S=t.steps[e.currentStepIndex];if(S&&o.current!==S.id){if(o.current&&t.analytics?.onStepComplete){let m=i.current.get(o.current);if(m){let d=Date.now()-m;t.analytics.onStepComplete(o.current,d,e.stepData,r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"step_complete",stepId:o.current,duration:d},{timestamp:Date.now(),duration:d,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:e.currentStepIndex,navigationDuration:d,conditionEvaluationDuration:0},"low");}}o.current=S.id,i.current.set(S.id,Date.now()),t.analytics?.onStepStart&&t.analytics.onStepStart(S.id,Date.now(),r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"step_start",stepId:S.id,stepIndex:e.currentStepIndex},{timestamp:Date.now(),duration:0,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:e.currentStepIndex,navigationDuration:0,conditionEvaluationDuration:0},"low");}},[e.currentStepIndex,t.steps,t.analytics,r,e.stepData,a,t.id]);let c=useCallback((S,m)=>{t.analytics?.onStepSkip&&t.analytics.onStepSkip(S,m,r),a&&a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"step_skip",stepId:S,reason:m},void 0,"medium");},[t.analytics,r,a,t.id]),l=useCallback(S=>{t.analytics?.onError&&t.analytics.onError(S,r),a&&a.trackError(S,`workflow_${t.id}`,{workflowId:t.id,currentStepIndex:e.currentStepIndex,currentStepId:t.steps[e.currentStepIndex]?.id,workflowContext:r});},[t.analytics,r,a,t.id,e.currentStepIndex,t.steps]),p=useCallback((S,m,d)=>{if(!a)return;let u={timestamp:Date.now(),duration:d,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:m,navigationDuration:d,conditionEvaluationDuration:0};a.track("workflow_navigation",`workflow_${t.id}`,{workflowId:t.id,action:"navigation",fromStep:S,toStep:m,direction:m>S?"forward":"backward"},u,d>1e3?"medium":"low");},[a,t.id,t.steps.length]),f=useCallback((S,m)=>{if(!a)return;let d={timestamp:Date.now(),duration:S,workflowId:t.id,stepCount:t.steps.length,currentStepIndex:e.currentStepIndex,navigationDuration:0,conditionEvaluationDuration:S};a.track("condition_evaluation",`workflow_${t.id}`,{workflowId:t.id,conditionsCount:m,currentStepIndex:e.currentStepIndex},d,S>100?"medium":"low");},[a,t.id,t.steps.length,e.currentStepIndex]);return {analyticsStartTime:n,trackStepSkip:c,trackError:l,trackNavigation:p,trackConditionEvaluation:f}}function Re(t,e){return {visible:t.visible,skippable:e===true||t.required}}function ie({workflowConfig:t,workflowState:e,currentStep:r}){let n=useMemo(()=>({...e.allData,...e.stepData}),[e.allData,e.stepData]),i=useMemo(()=>{if(r?.conditions)return {visible:r.conditions.visible,required:r.conditions.skippable}},[r?.conditions]),s=Q(i,n,{visible:true,disabled:false,required:false,readonly:false}),o=useMemo(()=>Re(s,r?.allowSkip),[s,r?.allowSkip]),a=useMemo(()=>{let g={};return t.steps.forEach((h,P)=>{h.conditions&&(g[P]={visible:h.conditions.visible,required:h.conditions.skippable});}),g},[t.steps]),c=We(a,n),l=useMemo(()=>{let g={};return t.steps.forEach((h,P)=>{let w=c[P];w?g[P]=Re(w,h.allowSkip):g[P]={visible:true,skippable:h.allowSkip===true};}),g},[t.steps,c]),p=useMemo(()=>{if(!r?.formConfig?.allFields)return {};let g={};for(let h of r.formConfig.allFields)h.conditions&&(g[h.id]=h.conditions);return g},[r?.formConfig?.allFields]),f=Ie(p,n),S=useCallback(g=>g<0||g>=t.steps.length?false:l[g]?.visible??true,[l,t.steps.length]),m=useCallback(g=>g<0||g>=t.steps.length?false:l[g]?.skippable??false,[l,t.steps.length]),d=useCallback(g=>f[g]?.visible??true,[f]),u=useCallback(g=>f[g]?.disabled??false,[f]),k=useCallback(g=>f[g]?.required??false,[f]),W=useCallback(g=>f[g]?.readonly??false,[f]);return {stepConditions:o,fieldConditions:f,allStepConditions:l,isStepVisible:S,isStepSkippable:m,isFieldVisible:d,isFieldDisabled:u,isFieldRequired:k,isFieldReadonly:W}}function se({workflowConfig:t,workflowState:e,workflowContext:r,conditionsHelpers:n,setCurrentStep:i,setTransitioning:s,markStepVisited:o,setStepData:a,onStepChange:c}){let l=useRef(c);l.current=c;let p=t.steps[e.currentStepIndex],f=useCallback(()=>({setStepData:(y,v)=>{a(v,y);},setStepFields:(y,v)=>{let I={...e.allData[y]||{},...v};a(I,y);},getStepData:y=>e.allData[y]||{},setNextStepField:(y,v)=>{let b=e.currentStepIndex+1;if(b<t.steps.length){let I=t.steps[b].id,G={...e.allData[I]||{},[y]:v};a(G,I);}},setNextStepFields:y=>{let v=e.currentStepIndex+1;if(v<t.steps.length){let b=t.steps[v].id,T={...e.allData[b]||{},...y};a(T,b);}},getAllData:()=>({...e.allData}),getSteps:()=>[...t.steps]}),[e.allData,e.currentStepIndex,t.steps,a]),S=useCallback(async y=>{if(y<0||y>=t.steps.length||!n.isStepVisible(y))return false;s(true);try{return l.current&&l.current(e.currentStepIndex,y,r),i(y),o(y,t.steps[y].id),!0}catch(v){return console.error("Step transition failed:",v),t.analytics?.onError&&t.analytics.onError(v,r),false}finally{s(false);}},[t.steps,t.analytics,n,e.currentStepIndex,r,s,i,o]),m=useCallback(y=>{for(let v=y+1;v<t.steps.length;v++)if(n.isStepVisible(v))return v;return null},[t.steps.length,n]),d=useCallback(y=>{for(let v=y-1;v>=0;v--)if(n.isStepVisible(v))return v;return null},[n]),u=useCallback(async()=>{if(p?.onAfterValidation)try{let v=f();await p.onAfterValidation(e.stepData,v,r);}catch(v){return console.error("onAfterValidation failed:",v),t.analytics?.onError&&t.analytics.onError(v,r),false}let y=m(e.currentStepIndex);return y===null?false:S(y)},[p,f,e.stepData,r,t.analytics,e.currentStepIndex,m,S]),k=useCallback(async()=>{let y=d(e.currentStepIndex);return y===null?false:S(y)},[e.currentStepIndex,d,S]),W=useCallback(async()=>!p?.allowSkip&&!n.isStepSkippable(e.currentStepIndex)?false:(t.analytics?.onStepSkip&&t.analytics.onStepSkip(p.id,"user_skip",r),u()),[p,n,e.currentStepIndex,t.analytics,r,u]),g=useCallback(y=>y<0||y>=t.steps.length?false:n.isStepVisible(y),[t.steps.length,n]),h=useCallback(()=>{let y=m(e.currentStepIndex);return y!==null&&g(y)},[e.currentStepIndex,m,g]),P=useCallback(()=>{let y=d(e.currentStepIndex);return y!==null&&g(y)},[e.currentStepIndex,d,g]),w=useCallback(()=>p?.allowSkip===true&&n.isStepSkippable(e.currentStepIndex),[p?.allowSkip,n,e.currentStepIndex]);return {goToStep:S,goNext:u,goPrevious:k,skipStep:W,canGoToStep:g,canGoNext:h,canGoPrevious:P,canSkipCurrentStep:w}}function rt(t,e){switch(e.type){case "SET_CURRENT_STEP":return {...t,currentStepIndex:e.stepIndex};case "SET_STEP_DATA":return {...t,stepData:e.data,allData:{...t.allData,[e.stepId]:e.data}};case "SET_ALL_DATA":return {...t,allData:e.data};case "SET_FIELD_VALUE":{let r={...t.stepData,[e.fieldId]:e.value};return {...t,stepData:r,allData:{...t.allData,[e.stepId]:r}}}case "SET_SUBMITTING":return {...t,isSubmitting:e.isSubmitting};case "SET_TRANSITIONING":return {...t,isTransitioning:e.isTransitioning};case "MARK_STEP_VISITED":return {...t,visitedSteps:new Set([...t.visitedSteps,e.stepId])};case "RESET_WORKFLOW":return {currentStepIndex:0,allData:{},stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:false};case "LOAD_PERSISTED_STATE":return {...t,...e.state};case "SET_INITIALIZATION_COMPLETE":return {...t,isInitializing:false};default:return t}}function oe({defaultValues:t={},persistence:e}){let r={currentStepIndex:0,allData:t,stepData:{},visitedSteps:new Set,isSubmitting:false,isTransitioning:false,isInitializing:true},[n,i]=useReducer(rt,r),s=e?.adapter?z({workflowId:e.workflowId,workflowState:n,adapter:e.adapter,options:e.options,userId:e.userId}):null,o=useCallback(u=>{i({type:"SET_CURRENT_STEP",stepIndex:u});},[]),a=useCallback((u,k)=>{i({type:"SET_STEP_DATA",data:u,stepId:k});},[]),c=useCallback((u,k,W)=>{i({type:"SET_FIELD_VALUE",fieldId:u,value:k,stepId:W});},[]),l=useCallback(u=>{i({type:"SET_SUBMITTING",isSubmitting:u});},[]),p=useCallback(u=>{i({type:"SET_TRANSITIONING",isTransitioning:u});},[]),f=useCallback((u,k)=>{i({type:"MARK_STEP_VISITED",stepIndex:u,stepId:k});},[]),S=useCallback(()=>{i({type:"RESET_WORKFLOW"});},[]),m=useCallback(()=>{i({type:"SET_INITIALIZATION_COMPLETE"});},[]),d=useCallback(async()=>{if(!s)return m(),false;try{let u=await s.loadPersistedData();if(u){let k={currentStepIndex:u.currentStepIndex,allData:u.allData,stepData:u.stepData,visitedSteps:new Set(u.visitedSteps)};return i({type:"LOAD_PERSISTED_STATE",state:k}),m(),!0}}catch(u){console.error("Failed to load persisted state:",u);}return m(),false},[s,m]);return {workflowState:n,setCurrentStep:o,setStepData:a,setFieldValue:c,setSubmitting:l,setTransitioning:p,markStepVisited:f,resetWorkflow:S,loadPersistedState:d,persistence:s?{isPersisting:s.isPersisting,persistenceError:s.persistenceError,persistNow:s.persistNow,clearPersistedData:s.clearPersistedData,hasPersistedData:s.hasPersistedData}:null}}function ae({workflowConfig:t,workflowState:e,workflowContext:r,setSubmitting:n,onWorkflowComplete:i,analyticsStartTime:s}){let o=useRef(i);o.current=i;let a=useCallback(async()=>{n(true);try{if(o.current&&await o.current(e.allData),t.analytics?.onWorkflowComplete){let l=Date.now()-s.current;t.analytics.onWorkflowComplete(t.id,l,e.allData);}}catch(l){throw console.error("Workflow submission failed:",l),t.analytics?.onError&&t.analytics.onError(l,r),l}finally{n(false);}},[e.allData,t.analytics,t.id,r,s,n]),c=useCallback(()=>e.isSubmitting?false:e.currentStepIndex===t.steps.length-1,[e.isSubmitting,e.currentStepIndex,t.steps.length]);return {submitWorkflow:a,isSubmitting:e.isSubmitting,canSubmit:c()}}var Le=createContext(null);function pe({children:t,workflowConfig:e,defaultValues:r={},onStepChange:n,onWorkflowComplete:i,className:s}){let o=useRef(n),a=useRef(i);o.current=n,a.current=i;let{workflowState:c,setCurrentStep:l,setStepData:p,setFieldValue:f,setSubmitting:S,setTransitioning:m,markStepVisited:d,resetWorkflow:u,loadPersistedState:k,persistence:W}=oe({defaultValues:r,persistence:e.persistence?{workflowId:e.id,adapter:e.persistence.adapter,options:e.persistence.options,userId:e.persistence.userId}:void 0});useEffect(()=>{e.persistence&&k&&k();},[]);let g=useMemo(()=>({isPersisting:W?.isPersisting??false,persistenceError:W?.persistenceError??null,persistNow:W?.persistNow}),[W?.isPersisting,W?.persistenceError,W?.persistNow]),h=useMemo(()=>({workflowId:e.id,currentStepIndex:c.currentStepIndex,totalSteps:e.steps.length,allData:c.allData,stepData:c.stepData,isFirstStep:c.currentStepIndex===0,isLastStep:c.currentStepIndex===e.steps.length-1,visitedSteps:c.visitedSteps}),[e.id,e.steps.length,c.currentStepIndex,c.allData,c.stepData,c.visitedSteps]),P=useMemo(()=>e.steps[c.currentStepIndex],[e.steps,c.currentStepIndex]),w=useMemo(()=>P?.formConfig,[P?.formConfig]),{analyticsStartTime:y}=ne({workflowConfig:e,workflowState:c,workflowContext:h}),v=ie({workflowConfig:e,workflowState:c,currentStep:P}),{goToStep:b,goNext:I,goPrevious:T,skipStep:G,canGoToStep:ue,canGoNext:fe,canGoPrevious:me,canSkipCurrentStep:Se}=se({workflowConfig:e,workflowState:c,workflowContext:h,conditionsHelpers:v,setCurrentStep:l,setTransitioning:m,markStepVisited:d,setStepData:p,onStepChange:o.current});useEffect(()=>{if(!v.isStepVisible(c.currentStepIndex)){for(let A=0;A<e.steps.length;A++)if(v.isStepVisible(A)){l(A),d(A,e.steps[A].id);break}}},[v,c.currentStepIndex,e.steps,l,d]);let{submitWorkflow:K,isSubmitting:ge,canSubmit:ye}=ae({workflowConfig:e,workflowState:c,workflowContext:h,setSubmitting:S,onWorkflowComplete:a.current,analyticsStartTime:y}),H=useCallback((C,A)=>{f(C,A,P?.id||"");},[f,P?.id]),be=useCallback(C=>{p(C,P?.id||"");},[p,P?.id]),Oe=useCallback(async C=>{P?.id&&C&&p(C,P.id),h.isLastStep?await K():await I();},[h.isLastStep,K,I,P?.id,p]),ve=useMemo(()=>({goToStep:b,goNext:I,goPrevious:T,skipStep:G,canGoToStep:ue,canGoNext:fe,canGoPrevious:me,canSkipCurrentStep:Se}),[b,I,T,G,ue,fe,me,Se]),he=useMemo(()=>({setValue:H,setStepData:be,resetWorkflow:u}),[H,be,u]),ke=useMemo(()=>({submitWorkflow:K,isSubmitting:ge,canSubmit:ye}),[K,ge,ye]),Ve=useMemo(()=>({workflowState:c,workflowConfig:e,currentStep:P,context:h,formConfig:w,conditionsHelpers:v,currentStepMetadata:P?.metadata,...ve,...he,...ke,persistNow:g.persistNow,isPersisting:g.isPersisting,persistenceError:g.persistenceError}),[c,e,P,h,w,v,ve,he,ke,g]),Ue=useMemo(()=>{if(!P?.id)return {};let C=c?.allData[P.id]||{};if(!w?.allFields)return C;let A=new Set(w.allFields.map($=>$.id)),xe={};for(let[$,Ke]of Object.entries(C))A.has($)&&(xe[$]=Ke);return xe},[c?.allData,P?.id,w?.allFields]),Ge=useMemo(()=>c.isInitializing.toString(),[c.isInitializing]);return jsx(Le.Provider,{value:Ve,children:jsx(FormProvider,{formConfig:w,defaultValues:Ue,onFieldChange:H,"data-workflow-id":e.id,className:s,onSubmit:Oe,children:t},Ge)})}function E(){let t=useContext(Le);if(!t)throw new Error("useWorkflowContext must be used within a WorkflowProvider");return t}function ct({children:t,workflowConfig:e,...r}){let[n,i]=useState(),s=useMemo(()=>e instanceof V?e.build():e,[e]);return useEffect(()=>{if(typeof window<"u"&&F.shouldDisplayWatermark()){let a=F.getWatermarkMessage();i(a);}},[]),jsxs("div",{style:{position:"relative"},children:[jsx(pe,{...r,workflowConfig:s,children:t}),n&&jsx("div",{style:{position:"absolute",top:"10px",right:"10px",background:"rgba(0, 0, 0, 0.8)",color:"white",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",fontFamily:"monospace",zIndex:1e3,pointerEvents:"none",opacity:.7},children:n})]})}var mt=ft.memo(function({stepId:e,children:r}){let{currentStep:n}=E();if(!n||e&&n.id!==e)return null;let{formConfig:i,renderer:s}=n;return i?s?s(n):r??jsx(FormBody,{}):null});var ht=ft.memo(function({className:e,isSubmitting:r,...n}){let{context:i,workflowState:s,workflowConfig:o,currentStep:a}=E(),{submit:c,formState:l}=useFormContext(),p=useMemo(()=>{let m=l.isSubmitting||s.isSubmitting,d=r??m,u=!s.isTransitioning&&!d;return {finalIsSubmitting:d,canGoNext:u}},[l.isSubmitting,s.isSubmitting,s.isTransitioning,r]),f=useCallback(async m=>{m?.preventDefault(),p.canGoNext&&await c(m);},[p.canGoNext,c]),S=useMemo(()=>({isLastStep:i.isLastStep,canGoNext:p.canGoNext,isSubmitting:p.finalIsSubmitting,onSubmit:f,className:e,currentStep:a,stepData:l.values||{},allData:i.allData,context:i}),[i.isLastStep,p.canGoNext,p.finalIsSubmitting,f,e,a,l.values,i.allData,i]);return jsx(ComponentRendererWrapper,{name:"WorkflowNextButton",renderer:o.renderConfig?.nextButtonRenderer,props:S,...n})});var Dt=ft.memo(function({className:e,isSubmitting:r,...n}){let{context:i,goPrevious:s,workflowState:o,workflowConfig:a,currentStep:c}=E(),{formState:l}=useFormContext(),p=useMemo(()=>{let m=l.isSubmitting||o.isSubmitting,d=r??m,u=i.currentStepIndex>0&&!o.isTransitioning&&!d;return {finalIsSubmitting:d,canGoPrevious:u}},[l.isSubmitting,o.isSubmitting,o.isTransitioning,i.currentStepIndex,r]),f=useCallback(async m=>{m?.preventDefault(),p.canGoPrevious&&await s();},[p.canGoPrevious,s]),S=useMemo(()=>({canGoPrevious:p.canGoPrevious,isSubmitting:p.finalIsSubmitting,onPrevious:f,className:e,currentStep:c,stepData:l.values||{},allData:i.allData,context:i}),[p.canGoPrevious,p.finalIsSubmitting,f,e,c,l.values,i.allData,i]);return jsx(ComponentRendererWrapper,{name:"WorkflowPreviousButton",renderer:a.renderConfig?.previousButtonRenderer,props:S,...n})});var At=ft.memo(function({className:e,isSubmitting:r,...n}){let{currentStep:i,skipStep:s,workflowState:o,workflowConfig:a,context:c,conditionsHelpers:l}=E(),{formState:p}=useFormContext(),f=useMemo(()=>{let d=p.isSubmitting||o.isSubmitting,u=r??d,k=(!!i?.allowSkip||l.isStepSkippable(o.currentStepIndex))&&!o.isTransitioning&&!u;return {finalIsSubmitting:u,canSkip:k}},[p.isSubmitting,o.isSubmitting,o.isTransitioning,o.currentStepIndex,i?.allowSkip,l.isStepSkippable,r]),S=useCallback(async d=>{d?.preventDefault(),f.canSkip&&await s();},[f.canSkip,s]),m=useMemo(()=>({canSkip:f.canSkip,isSubmitting:f.finalIsSubmitting,onSkip:S,className:e,currentStep:i,stepData:p.values||{},allData:c.allData,context:c}),[f.canSkip,f.finalIsSubmitting,S,e,i,p.values,c.allData,c]);return jsx(ComponentRendererWrapper,{name:"WorkflowSkipButton",renderer:a.renderConfig?.skipButtonRenderer,props:m,...n})});var Ft=ft.memo(function({onStepClick:e,className:r,...n}){let{workflowConfig:i,workflowState:s,goToStep:o,conditionsHelpers:a}=E(),{visibleSteps:c,visibleToOriginalIndexMap:l,originalToVisibleIndexMap:p}=useMemo(()=>{let d=[],u=new Map,k=new Map;return i.steps.forEach((W,g)=>{if(a.isStepVisible(g)){let h=d.length;d.push(W),u.set(h,g),k.set(g,h);}}),{visibleSteps:d,visibleToOriginalIndexMap:u,originalToVisibleIndexMap:k}},[i.steps,a]),f=useCallback(d=>{let u=l.get(d);u!==void 0&&(e?e(u):o(u));},[l,e,o]),S=useMemo(()=>p.get(s.currentStepIndex)??-1,[p,s.currentStepIndex]),m=useMemo(()=>({steps:c,currentStepIndex:S,visitedSteps:s.visitedSteps,onStepClick:f,className:r}),[c,S,s.visitedSteps,f,r]);return jsx(ComponentRendererWrapper,{name:"WorkflowStepper",renderer:i.renderConfig?.stepperRenderer,props:m,...n})});var de=class{constructor(e={}){this.version="1.0.0";this.keyPrefix=e.keyPrefix??"rilay_workflow_",this.compress=e.compress??false,this.maxAge=e.maxAge,this._isAvailable=this.isLocalStorageAvailable();}async save(e,r){if(this._isAvailable)try{let n=this.getStorageKey(e),i={data:{...r,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},s=JSON.stringify(i),o=this.compress?this.compressData(s):s;localStorage.setItem(n,o);}catch(n){if(n instanceof Error)if(n.name==="QuotaExceededError"||n.message.includes("quota")){await this.clearExpiredData();try{let i=this.getStorageKey(e),s={data:{...r,lastSaved:Date.now()},version:this.version,expiresAt:this.maxAge?Date.now()+this.maxAge:void 0},o=JSON.stringify(s),a=this.compress?this.compressData(o):o;localStorage.setItem(i,a);}catch(i){throw new D("localStorage quota exceeded and cleanup failed","QUOTA_EXCEEDED",i)}}else throw new D(`Failed to save to localStorage: ${n.message}`,"SAVE_FAILED",n);else throw new D("Unknown error occurred while saving","SAVE_FAILED")}}async load(e){if(!this._isAvailable)return null;try{let r=this.getStorageKey(e),n=localStorage.getItem(r);if(!n)return null;let i=this.compress?this.decompressData(n):n,s=JSON.parse(i);return s.expiresAt&&Date.now()>s.expiresAt?(await this.remove(e),null):{...s.data,visitedSteps:Array.isArray(s.data.visitedSteps)?s.data.visitedSteps:[]}}catch(r){throw r instanceof Error?new D(`Failed to load from localStorage: ${r.message}`,"LOAD_FAILED",r):new D("Unknown error occurred while loading","LOAD_FAILED")}}async remove(e){if(this._isAvailable)try{let r=this.getStorageKey(e);localStorage.removeItem(r);}catch(r){throw r instanceof Error?new D(`Failed to remove from localStorage: ${r.message}`,"REMOVE_FAILED",r):new D("Unknown error occurred while removing","REMOVE_FAILED")}}async exists(e){if(!this._isAvailable)return false;try{let r=this.getStorageKey(e),n=localStorage.getItem(r);if(!n)return !1;let i=this.compress?this.decompressData(n):n,s=JSON.parse(i);return s.expiresAt&&Date.now()>s.expiresAt?(await this.remove(e),!1):!0}catch{return false}}async listKeys(){if(!this._isAvailable)return [];try{let e=[];for(let r=0;r<localStorage.length;r++){let n=localStorage.key(r);if(n?.startsWith(this.keyPrefix)){let i=n.substring(this.keyPrefix.length);await this.exists(i)&&e.push(i);}}return e}catch(e){throw e instanceof Error?new D(`Failed to list keys: ${e.message}`,"LIST_FAILED",e):new D("Unknown error occurred while listing keys","LIST_FAILED")}}async clear(){try{let e=[];for(let r=0;r<localStorage.length;r++){let n=localStorage.key(r);n?.startsWith(this.keyPrefix)&&e.push(n);}for(let r of e)localStorage.removeItem(r);}catch(e){throw e instanceof Error?new D(`Failed to clear localStorage: ${e.message}`,"CLEAR_FAILED",e):new D("Unknown error occurred while clearing","CLEAR_FAILED")}}getStorageKey(e){return `${this.keyPrefix}${e}`}isLocalStorageAvailable(){try{let e="__rilay_test__";return localStorage.setItem(e,"test"),localStorage.removeItem(e),!0}catch{return false}}compressData(e){return btoa(e)}decompressData(e){try{return atob(e)}catch{return e}}async clearExpiredData(){if(!this._isAvailable)return;let e=[];for(let r=0;r<localStorage.length;r++){let n=localStorage.key(r);if(n?.startsWith(this.keyPrefix))try{let i=localStorage.getItem(n);if(i){let s=this.compress?this.decompressData(i):i,o=JSON.parse(s);o.expiresAt&&Date.now()>o.expiresAt&&e.push(n);}}catch{e.push(n);}}for(let r of e)localStorage.removeItem(r);}};
|
|
2
|
+
export{de as LocalStorageAdapter,F as RilayLicenseManager,ct as Workflow,mt as WorkflowBody,ht as WorkflowNextButton,D as WorkflowPersistenceError,Dt as WorkflowPreviousButton,pe as WorkflowProvider,At as WorkflowSkipButton,Ft as WorkflowStepper,te as debounce,V as flow,ee as generateStorageKey,Ye as mergePersistedState,De as persistedToWorkflowState,Q as useConditionEvaluation,z as usePersistence,Qe as useStepMetadata,ne as useWorkflowAnalytics,ie as useWorkflowConditions,E as useWorkflowContext,se as useWorkflowNavigation,oe as useWorkflowState,ae as useWorkflowSubmission,Ze as validatePersistedData,j as workflowStateToPersisted};
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rilaykit/workflow",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Commercial workflow and multi-step form utilities for RilayKit - License required for all use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist"
|
|
9
17
|
],
|
|
@@ -26,19 +34,19 @@
|
|
|
26
34
|
},
|
|
27
35
|
"dependencies": {
|
|
28
36
|
"@noble/ed25519": "^1.7.1",
|
|
29
|
-
"@rilaykit/core": "
|
|
30
|
-
"@rilaykit/forms": "
|
|
37
|
+
"@rilaykit/core": "9.0.0",
|
|
38
|
+
"@rilaykit/forms": "9.0.0"
|
|
31
39
|
},
|
|
32
40
|
"peerDependencies": {
|
|
33
41
|
"react": ">=18.0.0",
|
|
34
42
|
"react-dom": ">=18.0.0"
|
|
35
43
|
},
|
|
36
44
|
"devDependencies": {
|
|
37
|
-
"@types/react": "^18.
|
|
38
|
-
"@types/react-dom": "^18.
|
|
45
|
+
"@types/react": "^18.3.23",
|
|
46
|
+
"@types/react-dom": "^18.3.0",
|
|
39
47
|
"react": "^18.3.1",
|
|
40
48
|
"react-dom": "^18.3.1",
|
|
41
|
-
"typescript": "^5.3
|
|
49
|
+
"typescript": "^5.8.3"
|
|
42
50
|
},
|
|
43
51
|
"publishConfig": {
|
|
44
52
|
"access": "public"
|