@rxova/journey-react 0.6.0 → 0.6.2

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/README.md CHANGED
@@ -12,10 +12,12 @@ npm i @rxova/journey-react
12
12
 
13
13
  `@rxova/journey-react` is bindings-first:
14
14
 
15
- - `createJourneyBindings(journey)` returns a typed bundle:
16
- - `Provider`
17
- - `StepRenderer`
18
- - `useJourneyApi`, `useJourneySnapshot`, `useJourneyMachine`
15
+ - `createJourneyBindings(journey)` returns a typed bundle that contains:
16
+ - `Provider`
17
+ - `StepRenderer`
18
+ - `useJourneyApi`
19
+ - `useJourneySnapshot`
20
+ - `useJourneyMachine`
19
21
 
20
22
  No per-hook generic arguments are needed at callsites.
21
23
 
@@ -67,6 +69,42 @@ export const App = () => {
67
69
  };
68
70
  ```
69
71
 
72
+ ## Split Files Pattern (Hooks In Steps)
73
+
74
+ If step components live in separate files and call Journey hooks, export bindings as `let`:
75
+
76
+ ```tsx
77
+ // journey-bindings.ts
78
+ import { createJourneyBindings, type JourneyReactDefinition } from "@rxova/journey-react";
79
+ import { Start, Review } from "./steps";
80
+
81
+ type StepId = "start" | "review";
82
+ type Ctx = { name: string };
83
+
84
+ export let bindings: ReturnType<typeof createJourneyBindings<Ctx, StepId>>;
85
+
86
+ const journey: JourneyReactDefinition<Ctx, StepId> = {
87
+ initial: "start",
88
+ context: { name: "" },
89
+ steps: {
90
+ start: { component: Start },
91
+ review: { component: Review }
92
+ },
93
+ transitions: [
94
+ { from: "start", event: "goToNextStep", to: "review" },
95
+ { from: "review", event: "completeJourney" }
96
+ ]
97
+ };
98
+
99
+ bindings = createJourneyBindings(journey);
100
+ ```
101
+
102
+ ## Hooks
103
+
104
+ - `useJourneySnapshot()` subscribes to the machine and rerenders on changes.
105
+ - `useJourneyApi()` returns typed commands.
106
+ - `useJourneyMachine()` returns the underlying core machine instance.
107
+
70
108
  ## Journey API Helpers
71
109
 
72
110
  From `bindings.useJourneyApi()`:
@@ -86,3 +124,77 @@ Imperative jump is available through `send`:
86
124
  ```ts
87
125
  await api.send({ type: "goToStepById", stepId: "review" });
88
126
  ```
127
+
128
+ ## Provider Behavior
129
+
130
+ - `<Provider />` creates an internal core machine from the bound journey.
131
+ - `<Provider journey={...} />` lets you pass a different journey definition at runtime.
132
+ - Internal machine is preserved across `journey` prop changes by default.
133
+ - Set `resetOnJourneyChange` to rebuild internal machine when `journey` identity changes.
134
+ - `<Provider machine={externalMachine} />` uses your machine directly.
135
+ - `persistence` applies only when Provider owns the internal machine.
136
+
137
+ ```tsx
138
+ <bindings.Provider journey={dynamicJourney} resetOnJourneyChange>
139
+ <bindings.StepRenderer />
140
+ </bindings.Provider>
141
+ ```
142
+
143
+ ## Async and Error UI
144
+
145
+ Core async state is exposed via snapshot:
146
+
147
+ ```tsx
148
+ const api = bindings.useJourneyApi();
149
+ const snapshot = bindings.useJourneySnapshot();
150
+
151
+ if (snapshot.async.isLoading) return <p>Working...</p>;
152
+
153
+ const currentAsync = snapshot.async.byStep[snapshot.currentStepId];
154
+ if (currentAsync.phase === "error") {
155
+ return (
156
+ <div>
157
+ <p>Something failed.</p>
158
+ <button onClick={() => api.clearStepError()}>Dismiss</button>
159
+ </div>
160
+ );
161
+ }
162
+ ```
163
+
164
+ ## Devtools Bridge
165
+
166
+ Use `useJourneyMachine()` and attach the devtools bridge from an effect:
167
+
168
+ ```tsx
169
+ import React from "react";
170
+ import { attachJourneyDevtools } from "@rxova/journey-devtools-bridge";
171
+
172
+ const JourneyDevtoolsBridge = () => {
173
+ const machine = bindings.useJourneyMachine();
174
+
175
+ React.useEffect(() => {
176
+ return attachJourneyDevtools(machine, { label: "Signup" });
177
+ }, [machine]);
178
+
179
+ return null;
180
+ };
181
+ ```
182
+
183
+ ## Transition Ergonomics
184
+
185
+ `@rxova/journey-react` re-exports core transition builders:
186
+
187
+ ```ts
188
+ import { createTransitions, tx } from "@rxova/journey-react";
189
+
190
+ const transitions = createTransitions(
191
+ tx.from("start").on("goToNextStep").to("review"),
192
+ tx.from("review").toComplete()
193
+ );
194
+ ```
195
+
196
+ ## SSR and RSC Notes
197
+
198
+ - This package is a client entry (`"use client"`).
199
+ - In React Server Components environments, call bindings/hooks from client components.
200
+ - Server-side rendering is supported (Provider + StepRenderer render safely on the server).
@@ -1,8 +1,8 @@
1
- import type { JourneyEvent, JourneyPayloadFor } from "@rxova/journey-core";
1
+ import type { JourneyPayloadFor, JourneySendEvent } from "@rxova/journey-core";
2
2
  import type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from "../types";
3
3
  type UseJourneyStore<TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown> = (hookName?: string) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;
4
4
  export declare const createUseJourneyApi: <TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown>(useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => () => {
5
- send: (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<void>;
5
+ send: (event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<void>;
6
6
  goToNextStep: () => Promise<void>;
7
7
  terminateJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "terminateJourney">) => Promise<void>;
8
8
  completeJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "completeJourney">) => Promise<void>;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySnapshot.ts"],
4
- "sourcesContent": ["\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport {\n createTransitions,\n tx,\n JOURNEY_STATUS,\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_WILDCARD\n} from \"@rxova/journey-core\";\nexport type { JourneyDefinition } from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n", "import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyEvent, JourneyPayloadFor } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n"],
5
- "mappings": "ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uLAAAE,EAAA,uEAAAC,EAAAH,GCAA,IAAAI,EAAkB,sBCAlB,IAAAC,EAAkB,sBAElBC,EAAqC,+BAkF1BC,EAAA,6BAnDEC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EAAuB,GACvB,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBL,GAAWD,EAC7BO,EAAqB,EAAAC,QAAM,OAG/B,IAAI,EACAC,EAAa,EAAAD,QAAM,OAAOF,CAAe,EACzCI,EAAiB,EAAAF,QAAM,OAAOL,CAAW,EAEzCQ,EAAsBP,GAAwBK,EAAW,UAAYH,EACrEM,EAAyBF,EAAe,UAAYP,EAE1D,GACE,CAACD,IACA,CAACK,EAAmB,SAAWI,GAAuBC,GACvD,CACA,IAAMC,EAAUV,EAAc,CAAE,YAAAA,CAAY,EAAI,OAChDI,EAAmB,WAAU,wBAAqBD,EAAiBO,CAAO,EAC1EJ,EAAW,QAAUH,EACrBI,EAAe,QAAUP,CAC3B,CAEA,IAAMW,EAAkBZ,GAAWK,EAAmB,QAChDQ,EAAkBb,EAAUI,EAAkB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,SAAAS,EACA,aAAAE,EACA,cAAAJ,EACA,kBAAAF,EACA,mBAAAF,CACF,CACF,EDzDA,IAAAU,EAOO",
4
+ "sourcesContent": ["// Mark this entry point as a Next.js App Router client module so it can be used in client components.\n\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport {\n createTransitions,\n tx,\n JOURNEY_STATUS,\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_WILDCARD\n} from \"@rxova/journey-core\";\nexport type { JourneyDefinition } from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n", "import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyPayloadFor, JourneySendEvent } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (\n event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>\n ) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n"],
5
+ "mappings": "ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uLAAAE,EAAA,uEAAAC,EAAAH,GCAA,IAAAI,EAAkB,sBCAlB,IAAAC,EAAkB,sBAElBC,EAAqC,+BAkF1BC,EAAA,6BAnDEC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EAAuB,GACvB,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBL,GAAWD,EAC7BO,EAAqB,EAAAC,QAAM,OAG/B,IAAI,EACAC,EAAa,EAAAD,QAAM,OAAOF,CAAe,EACzCI,EAAiB,EAAAF,QAAM,OAAOL,CAAW,EAEzCQ,EAAsBP,GAAwBK,EAAW,UAAYH,EACrEM,EAAyBF,EAAe,UAAYP,EAE1D,GACE,CAACD,IACA,CAACK,EAAmB,SAAWI,GAAuBC,GACvD,CACA,IAAMC,EAAUV,EAAc,CAAE,YAAAA,CAAY,EAAI,OAChDI,EAAmB,WAAU,wBAAqBD,EAAiBO,CAAO,EAC1EJ,EAAW,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EACA,aAAAD,CACF,CAAC,EAEKc,EAAeC,EAAmB,CACtC,mBAAAT,EACA,gBAAAH,CACF,CAAC,EAED,MAAO,CACL,SAAAS,EACA,aAAAE,EACA,cAAAJ,EACA,kBAAAF,EACA,mBAAAF,CACF,CACF,EDxDA,IAAAU,EAOO",
6
6
  "names": ["index_exports", "__export", "createJourneyBindings", "__toCommonJS", "import_react", "import_react", "import_journey_core", "import_jsx_runtime", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "React", "journeyRef", "persistenceRef", "shouldResetInternal", "shouldResetPersistence", "options", "resolvedMachine", "resolvedJourney", "value", "import_jsx_runtime", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "import_react", "createUseJourneyApi", "useJourneyStore", "machine", "send", "React", "event", "goToNextStep", "terminateJourney", "payload", "completeJourney", "goToPreviousStep", "steps", "goToLastVisitedStep", "updateContext", "updater", "updateStepMetadata", "stepId", "clearStepError", "resetJourney", "createUseJourneyMachine", "useJourneyStore", "import_react", "createUseJourneySnapshot", "useJourneyStore", "machine", "React", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneyMachine", "createUseJourneyMachine", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer", "import_journey_core"]
7
7
  }
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySnapshot.ts", "../src/index.ts"],
4
- "sourcesContent": ["import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyEvent, JourneyPayloadFor } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n", "\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport {\n createTransitions,\n tx,\n JOURNEY_STATUS,\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_WILDCARD\n} from \"@rxova/journey-core\";\nexport type { JourneyDefinition } from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n"],
5
- "mappings": "aAAA,OAAOA,MAAW,QCAlB,OAAOC,MAAW,QAElB,OAAS,wBAAAC,MAA4B,sBAkF1B,cAAAC,MAAA,oBAnDJ,IAAMC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EAAuB,GACvB,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBL,GAAWD,EAC7BO,EAAqBZ,EAAM,OAG/B,IAAI,EACAa,EAAab,EAAM,OAAOW,CAAe,EACzCG,EAAiBd,EAAM,OAAOQ,CAAW,EAEzCO,EAAsBN,GAAwBI,EAAW,UAAYF,EACrEK,EAAyBF,EAAe,UAAYN,EAE1D,GACE,CAACD,IACA,CAACK,EAAmB,SAAWG,GAAuBC,GACvD,CACA,IAAMC,EAAUT,EAAc,CAAE,YAAAA,CAAY,EAAI,OAChDI,EAAmB,QAAUX,EAAqBU,EAAiBM,CAAO,EAC1EJ,EAAW,QAAUF,EACrBG,EAAe,QAAUN,CAC3B,CAEA,IAAMU,EAAkBX,GAAWK,EAAmB,QAChDO,EAAkBZ,EAAUI,EAAkBE,EAAW,QACzDO,EAAyF,CAC7F,QAASF,EACT,QAASC,CACX,EAEA,OAAOjB,EAACE,EAAe,SAAf,CAAwB,MAAOgB,EAAQ,SAAAV,EAAS,CAC1D,ECpCW,mBAAAW,EAAA,OAAAC,MAAA,oBAjBN,IAAMC,EAAqB,CAMhC,CACA,mBAAAC,EACA,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AAea,CAAM,CAC/B,EACA,CAACb,CAAO,CACV,EAEMe,EAAelB,EAAM,YAAY,IAAM,CAC3CG,EAAQ,aAAa,CACvB,EAAG,CAACA,CAAO,CAAC,EAEZ,MAAO,CACL,KAAAC,EACA,aAAAE,EACA,iBAAAC,EACA,gBAAAE,EACA,iBAAAC,EACA,oBAAAE,EACA,eAAAK,EACA,cAAAJ,EACA,mBAAAE,EACA,wBAAyBA,EACzB,aAAAG,CACF,CACF,ECrGK,IAAMC,EAOXC,GAEO,IACEA,EAAgB,mBAAmB,EAAE,QCtBhD,OAAOC,MAAW,QAeX,IAAMC,EAOXC,GAEO,IAAqD,CAC1D,GAAM,CAAE,QAAAC,CAAQ,EAAID,EAAgB,oBAAoB,EACxD,OAAOF,EAAM,qBAAqBG,EAAQ,UAAWA,EAAQ,YAAaA,EAAQ,WAAW,CAC/F,ELbK,IAAMC,EAOXC,GACkF,CAClF,IAAMC,EAAiBC,EAAM,cAMnB,IAAI,EAERC,EAAkB,CAACC,EAAW,SAAW,CAC7C,IAAMC,EAAQH,EAAM,WAAWD,CAAc,EAC7C,GAAI,CAACI,EACH,MAAM,IAAI,MAAM,GAAGD,CAAQ,yCAAyC,EAEtE,OAAOC,CACT,EAEMC,EAAqBC,EAAyBJ,CAAe,EAC7DK,EAAoBC,EAAwBN,CAAe,EAC3DO,EAAgBC,EAAoBR,CAAe,EAEnDS,EAAWC,EAAe,CAC9B,eAAAZ,EACA,aAAAD,CACF,CAAC,EAEKc,EAAeC,EAAmB,CACtC,mBAAAT,EACA,gBAAAH,CACF,CAAC,EAED,MAAO,CACL,SAAAS,EACA,aAAAE,EACA,cAAAJ,EACA,kBAAAF,EACA,mBAAAF,CACF,CACF,EMzDA,OACE,qBAAAU,EACA,MAAAC,GACA,kBAAAC,GACA,iBAAAC,GACA,uBAAAC,GACA,oBAAAC,OACK",
4
+ "sourcesContent": ["import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyPayloadFor, JourneySendEvent } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (\n event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>\n ) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n", "// Mark this entry point as a Next.js App Router client module so it can be used in client components.\n\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport {\n createTransitions,\n tx,\n JOURNEY_STATUS,\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_WILDCARD\n} from \"@rxova/journey-core\";\nexport type { JourneyDefinition } from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n"],
5
+ "mappings": "aAAA,OAAOA,MAAW,QCAlB,OAAOC,MAAW,QAElB,OAAS,wBAAAC,MAA4B,sBAkF1B,cAAAC,MAAA,oBAnDJ,IAAMC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EAAuB,GACvB,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBL,GAAWD,EAC7BO,EAAqBZ,EAAM,OAG/B,IAAI,EACAa,EAAab,EAAM,OAAOW,CAAe,EACzCG,EAAiBd,EAAM,OAAOQ,CAAW,EAEzCO,EAAsBN,GAAwBI,EAAW,UAAYF,EACrEK,EAAyBF,EAAe,UAAYN,EAE1D,GACE,CAACD,IACA,CAACK,EAAmB,SAAWG,GAAuBC,GACvD,CACA,IAAMC,EAAUT,EAAc,CAAE,YAAAA,CAAY,EAAI,OAChDI,EAAmB,QAAUX,EAAqBU,EAAiBM,CAAO,EAC1EJ,EAAW,QAAUF,EACrBG,EAAe,QAAUN,CAC3B,CAEA,IAAMU,EAAkBX,GAAWK,EAAmB,QAChDO,EAAkBZ,EAAUI,EAAkBE,EAAW,QACzDO,EAAyF,CAC7F,QAASF,EACT,QAASC,CACX,EAEA,OAAOjB,EAACE,EAAe,SAAf,CAAwB,MAAOgB,EAAQ,SAAAV,EAAS,CAC1D,ECpCW,mBAAAW,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ourneyMachine", "jsx", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "journeyRef", "persistenceRef", "shouldResetInternal", "shouldResetPersistence", "options", "resolvedMachine", "resolvedJourney", "value", "Fragment", "jsx", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "React", "createUseJourneyApi", "useJourneyStore", "machine", "send", "event", "goToNextStep", "terminateJourney", "payload", "completeJourney", "goToPreviousStep", "steps", "goToLastVisitedStep", "updateContext", "updater", "updateStepMetadata", "stepId", "clearStepError", "resetJourney", "createUseJourneyMachine", "useJourneyStore", "React", "createUseJourneySnapshot", "useJourneyStore", "machine", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneyMachine", "createUseJourneyMachine", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer", "createTransitions", "tx", "JOURNEY_STATUS", "JOURNEY_EVENT", "JOURNEY_ASYNC_PHASE", "JOURNEY_WILDCARD"]
7
7
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type React from "react";
2
- import type { JourneyDefinition, JourneyEvent, JourneyEventPayloadMap as JourneyCoreEventPayloadMap, JourneyMachine, JourneyPayloadFor, JourneyPersistenceOptions, JourneySnapshot, JourneyStepDefinition } from "@rxova/journey-core";
2
+ import type { JourneyDefinition, JourneyEventPayloadMap as JourneyCoreEventPayloadMap, JourneyMachine, JourneyPayloadFor, JourneyPersistenceOptions, JourneySendEvent, JourneySnapshot, JourneyStepDefinition } from "@rxova/journey-core";
3
3
  export type JourneyDefaultEvent = "goToNextStep" | "goToPreviousStep" | "terminateJourney" | "completeJourney";
4
4
  export type JourneyEventType<TCustomEvent extends string = never> = JourneyDefaultEvent | TCustomEvent;
5
5
  export type JourneyReactEventPayloadMap<TCustomEvent extends string = never> = JourneyCoreEventPayloadMap<JourneyEventType<TCustomEvent>>;
@@ -10,7 +10,7 @@ export type JourneyReactDefinition<TContext, TStepId extends string, TCustomEven
10
10
  steps: Record<TStepId, JourneyReactStep<TStepMeta>>;
11
11
  };
12
12
  export type JourneyApi<TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown> = {
13
- send: (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<void>;
13
+ send: (event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<void>;
14
14
  goToNextStep: () => Promise<void>;
15
15
  terminateJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "terminateJourney">) => Promise<void>;
16
16
  completeJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "completeJourney">) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxova/journey-react",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "React bindings for journey.",
5
5
  "keywords": [
6
6
  "react",
@@ -47,7 +47,7 @@
47
47
  ],
48
48
  "sideEffects": false,
49
49
  "dependencies": {
50
- "@rxova/journey-core": "^0.6.0"
50
+ "@rxova/journey-core": "^0.6.2"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "react": ">=18.2.0"
@@ -66,15 +66,15 @@
66
66
  }
67
67
  ],
68
68
  "devDependencies": {
69
- "@testing-library/react": "^16.1.0",
70
- "@types/react": "^19.0.8",
71
- "@types/react-dom": "^19.0.3",
72
- "react": "^19.0.0",
73
- "react-dom": "^19.0.0"
69
+ "@testing-library/react": "^16.3.2",
70
+ "@types/react": "^19.2.14",
71
+ "@types/react-dom": "^19.2.3",
72
+ "react": "^19.2.4",
73
+ "react-dom": "^19.2.4"
74
74
  },
75
75
  "scripts": {
76
76
  "build": "pnpm run clean && node ./scripts/build.mjs && tsc -p tsconfig.build.json && node ../../scripts/copy-types.mjs dist",
77
- "clean": "rm -rf dist tsconfig.build.tsbuildinfo",
77
+ "clean": "node ../../scripts/clean-paths.mjs dist tsconfig.build.tsbuildinfo",
78
78
  "coverage": "pnpm --workspace-root vitest run --coverage --coverage.include=packages/react/src/** --coverage.reporter=text-summary",
79
79
  "typecheck": "tsc --noEmit -p tsconfig.json",
80
80
  "publint": "publint",