@rxova/journey-react 0.6.3 → 0.7.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/README.md +28 -2
- package/dist/bindings/Provider.d.ts +1 -1
- package/dist/bindings/useJourneyApi.d.ts +7 -8
- package/dist/bindings/useJourneyEvent.d.ts +5 -0
- package/dist/bindings/useJourneySelector.d.ts +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/types.d.ts +20 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -5,9 +5,14 @@ Typed React bindings for Rxova Journey.
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
+
pnpm add @rxova/journey-react
|
|
9
|
+
yarn add @rxova/journey-react
|
|
8
10
|
npm i @rxova/journey-react
|
|
11
|
+
bun add @rxova/journey-react
|
|
9
12
|
```
|
|
10
13
|
|
|
14
|
+
Works in Bun-based SPAs as long as your app runtime supports React 18+.
|
|
15
|
+
|
|
11
16
|
## API Style
|
|
12
17
|
|
|
13
18
|
`@rxova/journey-react` is bindings-first:
|
|
@@ -16,6 +21,8 @@ npm i @rxova/journey-react
|
|
|
16
21
|
- `Provider`
|
|
17
22
|
- `StepRenderer`
|
|
18
23
|
- `useJourneyApi`
|
|
24
|
+
- `useJourneyEvent`
|
|
25
|
+
- `useJourneySelector`
|
|
19
26
|
- `useJourneySnapshot`
|
|
20
27
|
- `useJourneyMachine`
|
|
21
28
|
|
|
@@ -102,6 +109,8 @@ bindings = createJourneyBindings(journey);
|
|
|
102
109
|
## Hooks
|
|
103
110
|
|
|
104
111
|
- `useJourneySnapshot()` subscribes to the machine and rerenders on changes.
|
|
112
|
+
- `useJourneyEvent(listener)` subscribes to typed lifecycle events.
|
|
113
|
+
- `useJourneySelector(selector, equalityFn?)` subscribes to a selected slice and rerenders only when that selected value changes.
|
|
105
114
|
- `useJourneyApi()` returns typed commands.
|
|
106
115
|
- `useJourneyMachine()` returns the underlying core machine instance.
|
|
107
116
|
|
|
@@ -125,17 +134,34 @@ Imperative jump is available through `send`:
|
|
|
125
134
|
await api.send({ type: "goToStepById", stepId: "review" });
|
|
126
135
|
```
|
|
127
136
|
|
|
137
|
+
`send()` and convenience helpers resolve with `result.error` on guard/effect failure instead of rejecting, so `void api.goToNextStep()` will not create an unhandled rejection if transition logic fails.
|
|
138
|
+
|
|
139
|
+
`updateContext()` is immediate, but it follows core async timing rules: it does not retroactively change a transition already in `evaluating-when` or `running-effect`, and a running effect can later commit over that update. If the change must affect the current transition, apply it before `send(...)` or await the transition first.
|
|
140
|
+
|
|
128
141
|
## Provider Behavior
|
|
129
142
|
|
|
130
143
|
- `<Provider />` creates an internal core machine from the bound journey.
|
|
131
144
|
- `<Provider journey={...} />` lets you pass a different journey definition at runtime.
|
|
132
|
-
- Internal machine is preserved across `journey` prop changes by default.
|
|
145
|
+
- Internal machine is preserved across `journey` and `persistence` prop changes by default.
|
|
133
146
|
- Set `resetOnJourneyChange` to rebuild internal machine when `journey` identity changes.
|
|
147
|
+
- Set `resetOnPersistenceChange` to rebuild internal machine when `persistence` identity changes.
|
|
134
148
|
- `<Provider machine={externalMachine} />` uses your machine directly.
|
|
135
149
|
- `persistence` applies only when Provider owns the internal machine.
|
|
150
|
+
- Internal Provider-owned machines default to completing on `goToNextStep()` when the current step declares no next transition.
|
|
151
|
+
- Set `completeOnNoNextStep={false}` to opt out.
|
|
152
|
+
- `onStart(event)` wraps `machine.subscribeStart(...)`.
|
|
153
|
+
- `onComplete(event)` wraps `machine.subscribeComplete(...)`.
|
|
154
|
+
- `onTerminate(event)` wraps `machine.subscribeTerminate(...)`.
|
|
155
|
+
- All three callback props work with internal and external machines.
|
|
156
|
+
- `onStart` replays startup on mount, matching core `journey.start` behavior.
|
|
157
|
+
- `onComplete` and `onTerminate` fire only for emitted terminal lifecycle events.
|
|
136
158
|
|
|
137
159
|
```tsx
|
|
138
|
-
<bindings.Provider
|
|
160
|
+
<bindings.Provider
|
|
161
|
+
journey={dynamicJourney}
|
|
162
|
+
resetOnJourneyChange
|
|
163
|
+
onStart={() => console.log("started!")}
|
|
164
|
+
>
|
|
139
165
|
<bindings.StepRenderer />
|
|
140
166
|
</bindings.Provider>
|
|
141
167
|
```
|
|
@@ -4,5 +4,5 @@ type ProviderFactoryProps<TContext, TStepId extends string, TCustomEvent extends
|
|
|
4
4
|
JourneyContext: React.Context<JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> | null>;
|
|
5
5
|
boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;
|
|
6
6
|
};
|
|
7
|
-
export declare const createProvider: <TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown>({ JourneyContext, boundJourney }: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => ({ journey, machine, persistence, resetOnJourneyChange, children }: JourneyBindingsProviderProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const createProvider: <TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown>({ JourneyContext, boundJourney }: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => ({ journey, machine, persistence, completeOnNoNextStep, resetOnJourneyChange, resetOnPersistenceChange, onStart, onComplete, onTerminate, children }: JourneyBindingsProviderProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export {};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import type { JourneyPayloadFor, JourneySendEvent } from "@rxova/journey-core";
|
|
1
|
+
import type { JourneyPayloadFor, JourneySendEvent, JourneySendResult } 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: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<
|
|
6
|
-
goToNextStep: () => Promise<
|
|
7
|
-
terminateJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "terminateJourney">) => Promise<
|
|
8
|
-
completeJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "completeJourney">) => Promise<
|
|
9
|
-
goToPreviousStep: (steps?: number) => Promise<
|
|
10
|
-
goToLastVisitedStep: () => Promise<
|
|
5
|
+
send: (event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
6
|
+
goToNextStep: () => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
7
|
+
terminateJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "terminateJourney">) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
8
|
+
completeJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "completeJourney">) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
9
|
+
goToPreviousStep: (steps?: number) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
10
|
+
goToLastVisitedStep: () => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
11
11
|
clearStepError: (stepId?: TStepId) => void;
|
|
12
12
|
updateContext: (updater: (context: TContext) => TContext) => void;
|
|
13
13
|
updateStepMetadata: (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => void;
|
|
14
|
-
updateComponentMetadata: (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => void;
|
|
15
14
|
resetJourney: () => void;
|
|
16
15
|
};
|
|
17
16
|
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JourneyObservationEvent } from "@rxova/journey-core";
|
|
2
|
+
import type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from "../types";
|
|
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
|
+
export declare const createUseJourneyEvent: <TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown>(useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => (listener: (event: JourneyObservationEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>) => void) => void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JourneyEqualityFn, JourneySelector } from "@rxova/journey-core";
|
|
2
|
+
import type { JourneyReactEventPayloadMap, JourneyStoreValue } from "../types";
|
|
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
|
+
export declare const createUseJourneySelector: <TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown>(useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => <TSelected>(selector: JourneySelector<TContext, TStepId, TStepMeta, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected;
|
|
5
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var ne=Object.create;var P=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty;var se=(o,e)=>{for(var t in e)P(o,t,{get:e[t],enumerable:!0})},_=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of re(e))!ue.call(o,n)&&n!==t&&P(o,n,{get:()=>e[n],enumerable:!(r=oe(e,n))||r.enumerable});return o};var E=(o,e,t)=>(t=o!=null?ne(ae(o)):{},_(e||!o||!o.__esModule?P(t,"default",{value:o,enumerable:!0}):t,o)),de=o=>_(P({},"__esModule",{value:!0}),o);var Te={};se(Te,{JOURNEY_ASYNC_PHASE:()=>p.JOURNEY_ASYNC_PHASE,JOURNEY_EVENT:()=>p.JOURNEY_EVENT,JOURNEY_STATUS:()=>p.JOURNEY_STATUS,JOURNEY_WILDCARD:()=>p.JOURNEY_WILDCARD,createJourneyBindings:()=>Z,createTransitions:()=>p.createTransitions,tx:()=>p.tx});module.exports=de(Te);var F=E(require("react"),1);var d=E(require("react"),1),w=require("@rxova/journey-core"),H=require("react/jsx-runtime"),pe=typeof window>"u"?d.default.useEffect:d.default.useLayoutEffect,O=({JourneyContext:o,boundJourney:e})=>({journey:r,machine:n,persistence:a,completeOnNoNextStep:u,resetOnJourneyChange:J=!1,resetOnPersistenceChange:T=!1,onStart:s,onComplete:y,onTerminate:i,children:N})=>{let v=r??e,S=d.default.useRef(null),x=d.default.useRef(v),I=d.default.useRef(a),g=d.default.useRef(u),j=d.default.useRef(s),A=d.default.useRef(y),q=d.default.useRef(i),[,ee]=d.default.useReducer(c=>c+1,0),h=s!==void 0,b=y!==void 0,k=i!==void 0;if(j.current=s,A.current=y,q.current=i,!n&&!S.current){let c=a!==void 0||u!==void 0?{...a!==void 0?{persistence:a}:{},...u!==void 0?{completeOnNoNextStep:u}:{}}:void 0;S.current=(0,w.createJourneyMachine)(v,c),x.current=v,I.current=a,g.current=u}let B=!n&&J&&x.current!==v,D=!n&&T&&I.current!==a,L=!n&&g.current!==u;pe(()=>{if(n||!B&&!D&&!L)return;let c=S.current,U=a!==void 0||u!==void 0?{...a!==void 0?{persistence:a}:{},...u!==void 0?{completeOnNoNextStep:u}:{}}:void 0,f=(0,w.createJourneyMachine)(v,U);S.current=f,x.current=v,I.current=a,g.current=u,c&&c!==f&&c.dispose(),ee()},[u,v,n,a,B,D,L]);let l=n??S.current,Y=n?v:x.current,te=d.default.useMemo(()=>({machine:l,journey:Y}),[l,Y]);return d.default.useEffect(()=>{if(!h&&!b&&!k)return;let c=h?l.subscribeStart(m=>{j.current?.(m)}):void 0,U=b?l.subscribeComplete(m=>{A.current?.(m)}):void 0,f=k?l.subscribeTerminate(m=>{q.current?.(m)}):void 0;return()=>{c?.(),U?.(),f?.()}},[h,b,k,l]),d.default.useEffect(()=>()=>{n||!S.current||(S.current.dispose(),S.current=null)},[n]),(0,H.jsx)(o.Provider,{value:te,children:N})};var M=require("react/jsx-runtime"),W=({useJourneySnapshot:o,useJourneyStore:e})=>({fallback:r=null})=>{let n=o(),{journey:a}=e("StepRenderer"),u=a.steps[n.currentStepId]?.component;return u?(0,M.jsx)(u,{},n.currentStepId):(0,M.jsx)(M.Fragment,{children:r})};var $=E(require("react"),1),z=o=>()=>{let{machine:e}=o("useJourneyApi");return $.default.useMemo(()=>({send:async t=>e.send(t),goToNextStep:async()=>e.goToNextStep(),terminateJourney:async t=>e.terminateJourney(t),completeJourney:async t=>e.completeJourney(t),goToPreviousStep:async t=>e.goToPreviousStep(t),goToLastVisitedStep:async()=>e.goToLastVisitedStep(),clearStepError:t=>{e.clearStepError(t)},updateContext:t=>{e.updateContext(t)},updateStepMetadata:(t,r)=>{e.updateStepMetadata(t,r)},resetJourney:()=>{e.resetMachine()}}),[e])};var V=E(require("react"),1),G=o=>e=>{let{machine:t}=o("useJourneyEvent"),r=V.default.useRef(e);r.current=e,V.default.useEffect(()=>t.subscribeEvent(n=>{r.current(n)}),[t])};var K=o=>()=>o("useJourneyMachine").machine;var C=E(require("react"),1),Q=o=>(e,t)=>{let{machine:r}=o("useJourneySelector"),n=t??Object.is,a=C.default.useRef(null),u=C.default.useCallback(()=>{let T=r.getSnapshot(),s=a.current;if(s&&s.selector===e&&s.isEqual===n&&Object.is(s.snapshot,T))return s.selected;let y=e(T);return s&&s.selector===e&&s.isEqual===n&&s.isEqual(s.selected,y)?(a.current={snapshot:T,selected:s.selected,selector:e,isEqual:n},s.selected):(a.current={snapshot:T,selected:y,selector:e,isEqual:n},y)},[r,e,n]),J=C.default.useCallback(T=>r.subscribeSelector(e,()=>{T()},n),[r,e,n]);return C.default.useSyncExternalStore(J,u,u)};var R=E(require("react"),1),X=o=>()=>{let{machine:e}=o("useJourneySnapshot"),t=R.default.useCallback(()=>e.getSnapshot(),[e]),r=R.default.useCallback(n=>e.subscribe(n),[e]);return R.default.useSyncExternalStore(r,t,t)};var Z=o=>{let e=F.default.createContext(null),t=(y="hook")=>{let i=F.default.useContext(e);if(!i)throw new Error(`${y} must be used within bindings.Provider.`);return i},r=X(t),n=Q(t),a=K(t),u=G(t),J=z(t),T=O({JourneyContext:e,boundJourney:o}),s=W({useJourneySnapshot:r,useJourneyStore:t});return{Provider:T,StepRenderer:s,useJourneyApi:J,useJourneyEvent:u,useJourneyMachine:a,useJourneySelector:n,useJourneySnapshot:r}};var p=require("@rxova/journey-core");0&&(module.exports={JOURNEY_ASYNC_PHASE,JOURNEY_EVENT,JOURNEY_STATUS,JOURNEY_WILDCARD,createJourneyBindings,createTransitions,tx});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 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": ["// 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\n/**\n * Creates a typed React integration bundle (Provider, StepRenderer, and hooks)\n * bound to a specific journey definition.\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": "
|
|
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", "
|
|
3
|
+
"sources": ["../src/index.ts", "../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyEvent.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySelector.ts", "../src/bindings/useJourneySnapshot.ts"],
|
|
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, JourneySendResult } 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 { createUseJourneyEvent } from \"./useJourneyEvent\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySelector } from \"./useJourneySelector\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\n/**\n * Creates a typed React integration bundle (Provider, StepRenderer, and hooks)\n * bound to a specific journey definition.\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 useJourneySelector = createUseJourneySelector(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyEvent = createUseJourneyEvent(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 useJourneyEvent,\n useJourneyMachine,\n useJourneySelector,\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\nconst useSafeLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\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 completeOnNoNextStep,\n resetOnJourneyChange = false,\n resetOnPersistenceChange = false,\n onStart,\n onComplete,\n onTerminate,\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 const completeOnNoNextStepRef = React.useRef(completeOnNoNextStep);\n const onStartRef = React.useRef(onStart);\n const onCompleteRef = React.useRef(onComplete);\n const onTerminateRef = React.useRef(onTerminate);\n const [, forceUpdate] = React.useReducer((count: number) => count + 1, 0);\n const hasOnStart = onStart !== undefined;\n const hasOnComplete = onComplete !== undefined;\n const hasOnTerminate = onTerminate !== undefined;\n\n onStartRef.current = onStart;\n onCompleteRef.current = onComplete;\n onTerminateRef.current = onTerminate;\n\n if (!machine && !internalMachineRef.current) {\n const options =\n persistence !== undefined || completeOnNoNextStep !== undefined\n ? {\n ...(persistence !== undefined ? { persistence } : {}),\n ...(completeOnNoNextStep !== undefined ? { completeOnNoNextStep } : {})\n }\n : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n completeOnNoNextStepRef.current = completeOnNoNextStep;\n }\n\n const shouldResetJourney =\n !machine && resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence =\n !machine && resetOnPersistenceChange && persistenceRef.current !== persistence;\n const shouldResetNextCompletion =\n !machine && completeOnNoNextStepRef.current !== completeOnNoNextStep;\n\n useSafeLayoutEffect(() => {\n if (\n machine ||\n (!shouldResetJourney && !shouldResetPersistence && !shouldResetNextCompletion)\n ) {\n return;\n }\n\n const previousInternalMachine = internalMachineRef.current;\n const options =\n persistence !== undefined || completeOnNoNextStep !== undefined\n ? {\n ...(persistence !== undefined ? { persistence } : {}),\n ...(completeOnNoNextStep !== undefined ? { completeOnNoNextStep } : {})\n }\n : undefined;\n const nextInternalMachine = createJourneyMachine(incomingJourney, options);\n internalMachineRef.current = nextInternalMachine;\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n completeOnNoNextStepRef.current = completeOnNoNextStep;\n\n if (previousInternalMachine && previousInternalMachine !== nextInternalMachine) {\n previousInternalMachine.dispose();\n }\n\n forceUpdate();\n }, [\n completeOnNoNextStep,\n incomingJourney,\n machine,\n persistence,\n shouldResetJourney,\n shouldResetPersistence,\n shouldResetNextCompletion\n ]);\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value = React.useMemo<\n JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n >(\n () => ({\n machine: resolvedMachine,\n journey: resolvedJourney\n }),\n [resolvedMachine, resolvedJourney]\n );\n\n React.useEffect(() => {\n if (!hasOnStart && !hasOnComplete && !hasOnTerminate) {\n return;\n }\n\n const unsubStart = hasOnStart\n ? resolvedMachine.subscribeStart((event) => {\n onStartRef.current?.(event);\n })\n : undefined;\n\n const unsubComplete = hasOnComplete\n ? resolvedMachine.subscribeComplete((event) => {\n onCompleteRef.current?.(event);\n })\n : undefined;\n\n const unsubTerminate = hasOnTerminate\n ? resolvedMachine.subscribeTerminate((event) => {\n onTerminateRef.current?.(event);\n })\n : undefined;\n\n return () => {\n unsubStart?.();\n unsubComplete?.();\n unsubTerminate?.();\n };\n }, [hasOnStart, hasOnComplete, hasOnTerminate, resolvedMachine]);\n\n React.useEffect(() => {\n return () => {\n if (machine || !internalMachineRef.current) {\n return;\n }\n internalMachineRef.current.dispose();\n internalMachineRef.current = null;\n };\n }, [machine]);\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 key={snapshot.currentStepId} />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyPayloadFor, JourneySendEvent, JourneySendResult } 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\");\n\n return React.useMemo(\n () => ({\n send: async (\n event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.send(event);\n },\n goToNextStep: async (): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.goToNextStep();\n },\n terminateJourney: async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.terminateJourney(payload);\n },\n completeJourney: async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.completeJourney(payload);\n },\n goToPreviousStep: async (\n steps?: number\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.goToPreviousStep(steps);\n },\n goToLastVisitedStep: async (): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.goToLastVisitedStep();\n },\n clearStepError: (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n updateContext: (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n updateStepMetadata: (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n resetJourney: () => {\n machine.resetMachine();\n }\n }),\n [machine]\n );\n };\n};\n", "import React from \"react\";\n\nimport type { JourneyObservationEvent } 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 createUseJourneyEvent = <\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 listener: (\n event: JourneyObservationEvent<\n TStepId,\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n TStepMeta\n >\n ) => void\n ) => {\n const { machine } = useJourneyStore(\"useJourneyEvent\");\n const listenerRef = React.useRef(listener);\n listenerRef.current = listener;\n\n React.useEffect(() => {\n return machine.subscribeEvent((event) => {\n listenerRef.current(event);\n });\n }, [machine]);\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 { JourneyEqualityFn, JourneySelector, 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 SelectorCache<TContext, TStepId extends string, TStepMeta, TSelected> = {\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>;\n selected: TSelected;\n selector: JourneySelector<TContext, TStepId, TStepMeta, TSelected>;\n isEqual: JourneyEqualityFn<TSelected>;\n};\n\nexport const createUseJourneySelector = <\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 <TSelected>(\n selector: JourneySelector<TContext, TStepId, TStepMeta, TSelected>,\n equalityFn?: JourneyEqualityFn<TSelected>\n ): TSelected => {\n const { machine } = useJourneyStore(\"useJourneySelector\");\n const isEqual = equalityFn ?? Object.is;\n const cacheRef = React.useRef<SelectorCache<TContext, TStepId, TStepMeta, TSelected> | null>(\n null\n );\n\n const getSelectedSnapshot = React.useCallback(() => {\n const nextSnapshot = machine.getSnapshot();\n const cached = cacheRef.current;\n\n if (\n cached &&\n cached.selector === selector &&\n cached.isEqual === isEqual &&\n Object.is(cached.snapshot, nextSnapshot)\n ) {\n return cached.selected;\n }\n\n const nextSelected = selector(nextSnapshot);\n\n if (cached && cached.selector === selector && cached.isEqual === isEqual) {\n if (cached.isEqual(cached.selected, nextSelected)) {\n cacheRef.current = {\n snapshot: nextSnapshot,\n selected: cached.selected,\n selector,\n isEqual\n };\n return cached.selected;\n }\n }\n\n cacheRef.current = {\n snapshot: nextSnapshot,\n selected: nextSelected,\n selector,\n isEqual\n };\n return nextSelected;\n }, [machine, selector, isEqual]);\n\n const subscribeToSelectedSnapshot = React.useCallback(\n (onStoreChange: () => void) =>\n machine.subscribeSelector(\n selector,\n () => {\n onStoreChange();\n },\n isEqual\n ),\n [machine, selector, isEqual]\n );\n\n return React.useSyncExternalStore(\n subscribeToSelectedSnapshot,\n getSelectedSnapshot,\n getSelectedSnapshot\n );\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 const getSnapshot = React.useCallback(() => machine.getSnapshot(), [machine]);\n const subscribe = React.useCallback(\n (onStoreChange: () => void) => machine.subscribe(onStoreChange),\n [machine]\n );\n\n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,CACF,CACF,EDlEA,IAAAc,EAOO",
|
|
6
|
+
"names": ["index_exports", "__export", "createJourneyBindings", "__toCommonJS", "import_react", "import_react", "import_journey_core", "import_jsx_runtime", "useSafeLayoutEffect", "React", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "completeOnNoNextStep", "resetOnJourneyChange", "resetOnPersistenceChange", "onStart", "onComplete", "onTerminate", "children", "incomingJourney", "internalMachineRef", "journeyRef", "persistenceRef", "completeOnNoNextStepRef", "onStartRef", "onCompleteRef", "onTerminateRef", "forceUpdate", "count", "hasOnStart", "hasOnComplete", "hasOnTerminate", "options", "shouldResetJourney", "shouldResetPersistence", "shouldResetNextCompletion", "previousInternalMachine", "nextInternalMachine", "resolvedMachine", "resolvedJourney", "value", "unsubStart", "event", "unsubComplete", "unsubTerminate", "import_jsx_runtime", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "import_react", "createUseJourneyApi", "useJourneyStore", "machine", "React", "event", "payload", "steps", "stepId", "updater", "import_react", "createUseJourneyEvent", "useJourneyStore", "listener", "machine", "listenerRef", "React", "event", "createUseJourneyMachine", "useJourneyStore", "import_react", "createUseJourneySelector", "useJourneyStore", "selector", "equalityFn", "machine", "isEqual", "cacheRef", "React", "getSelectedSnapshot", "nextSnapshot", "cached", "nextSelected", "subscribeToSelectedSnapshot", "onStoreChange", "import_react", "createUseJourneySnapshot", "useJourneyStore", "machine", "getSnapshot", "React", "subscribe", "onStoreChange", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneySelector", "createUseJourneySelector", "useJourneyMachine", "createUseJourneyMachine", "useJourneyEvent", "createUseJourneyEvent", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer", "import_journey_core"]
|
|
7
7
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createJourneyBindings } from "./bindings";
|
|
2
2
|
export { createTransitions, tx, JOURNEY_STATUS, JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_WILDCARD } from "@rxova/journey-core";
|
|
3
|
-
export type { JourneyDefinition } from "@rxova/journey-core";
|
|
3
|
+
export type { JourneyDefinition, JourneySendResult } from "@rxova/journey-core";
|
|
4
4
|
export type { JourneyApi, JourneyBindings, JourneyBindingsProviderProps, JourneyEventType, JourneyReactDefinition, JourneyReactEventPayloadMap, JourneyReactStep, JourneyStoreValue } from "./types";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createJourneyBindings } from "./bindings";
|
|
2
2
|
export { createTransitions, tx, JOURNEY_STATUS, JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_WILDCARD } from "@rxova/journey-core";
|
|
3
|
-
export type { JourneyDefinition } from "@rxova/journey-core";
|
|
3
|
+
export type { JourneyDefinition, JourneySendResult } from "@rxova/journey-core";
|
|
4
4
|
export type { JourneyApi, JourneyBindings, JourneyBindingsProviderProps, JourneyEventType, JourneyReactDefinition, JourneyReactEventPayloadMap, JourneyReactStep, JourneyStoreValue } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import
|
|
1
|
+
"use client";import W from"react";import d from"react";import{createJourneyMachine as j}from"@rxova/journey-core";import{jsx as Q}from"react/jsx-runtime";var K=typeof window>"u"?d.useEffect:d.useLayoutEffect,A=({JourneyContext:s,boundJourney:e})=>({journey:a,machine:n,persistence:o,completeOnNoNextStep:r,resetOnJourneyChange:l=!1,resetOnPersistenceChange:p=!1,onStart:u,onComplete:T,onTerminate:S,children:$})=>{let c=a??e,v=d.useRef(null),J=d.useRef(c),C=d.useRef(o),x=d.useRef(r),h=d.useRef(u),b=d.useRef(T),k=d.useRef(S),[,z]=d.useReducer(y=>y+1,0),f=u!==void 0,P=T!==void 0,R=S!==void 0;if(h.current=u,b.current=T,k.current=S,!n&&!v.current){let y=o!==void 0||r!==void 0?{...o!==void 0?{persistence:o}:{},...r!==void 0?{completeOnNoNextStep:r}:{}}:void 0;v.current=j(c,y),J.current=c,C.current=o,x.current=r}let U=!n&&l&&J.current!==c,w=!n&&p&&C.current!==o,V=!n&&x.current!==r;K(()=>{if(n||!U&&!w&&!V)return;let y=v.current,I=o!==void 0||r!==void 0?{...o!==void 0?{persistence:o}:{},...r!==void 0?{completeOnNoNextStep:r}:{}}:void 0,m=j(c,I);v.current=m,J.current=c,C.current=o,x.current=r,y&&y!==m&&y.dispose(),z()},[r,c,n,o,U,w,V]);let i=n??v.current,F=n?c:J.current,G=d.useMemo(()=>({machine:i,journey:F}),[i,F]);return d.useEffect(()=>{if(!f&&!P&&!R)return;let y=f?i.subscribeStart(E=>{h.current?.(E)}):void 0,I=P?i.subscribeComplete(E=>{b.current?.(E)}):void 0,m=R?i.subscribeTerminate(E=>{k.current?.(E)}):void 0;return()=>{y?.(),I?.(),m?.()}},[f,P,R,i]),d.useEffect(()=>()=>{n||!v.current||(v.current.dispose(),v.current=null)},[n]),Q(s.Provider,{value:G,children:$})};import{Fragment as X,jsx as q}from"react/jsx-runtime";var B=({useJourneySnapshot:s,useJourneyStore:e})=>({fallback:a=null})=>{let n=s(),{journey:o}=e("StepRenderer"),r=o.steps[n.currentStepId]?.component;return r?q(r,{},n.currentStepId):q(X,{children:a})};import Z from"react";var D=s=>()=>{let{machine:e}=s("useJourneyApi");return Z.useMemo(()=>({send:async t=>e.send(t),goToNextStep:async()=>e.goToNextStep(),terminateJourney:async t=>e.terminateJourney(t),completeJourney:async t=>e.completeJourney(t),goToPreviousStep:async t=>e.goToPreviousStep(t),goToLastVisitedStep:async()=>e.goToLastVisitedStep(),clearStepError:t=>{e.clearStepError(t)},updateContext:t=>{e.updateContext(t)},updateStepMetadata:(t,a)=>{e.updateStepMetadata(t,a)},resetJourney:()=>{e.resetMachine()}}),[e])};import L from"react";var Y=s=>e=>{let{machine:t}=s("useJourneyEvent"),a=L.useRef(e);a.current=e,L.useEffect(()=>t.subscribeEvent(n=>{a.current(n)}),[t])};var _=s=>()=>s("useJourneyMachine").machine;import M from"react";var O=s=>(e,t)=>{let{machine:a}=s("useJourneySelector"),n=t??Object.is,o=M.useRef(null),r=M.useCallback(()=>{let p=a.getSnapshot(),u=o.current;if(u&&u.selector===e&&u.isEqual===n&&Object.is(u.snapshot,p))return u.selected;let T=e(p);return u&&u.selector===e&&u.isEqual===n&&u.isEqual(u.selected,T)?(o.current={snapshot:p,selected:u.selected,selector:e,isEqual:n},u.selected):(o.current={snapshot:p,selected:T,selector:e,isEqual:n},T)},[a,e,n]),l=M.useCallback(p=>a.subscribeSelector(e,()=>{p()},n),[a,e,n]);return M.useSyncExternalStore(l,r,r)};import g from"react";var H=s=>()=>{let{machine:e}=s("useJourneySnapshot"),t=g.useCallback(()=>e.getSnapshot(),[e]),a=g.useCallback(n=>e.subscribe(n),[e]);return g.useSyncExternalStore(a,t,t)};var N=s=>{let e=W.createContext(null),t=(T="hook")=>{let S=W.useContext(e);if(!S)throw new Error(`${T} must be used within bindings.Provider.`);return S},a=H(t),n=O(t),o=_(t),r=Y(t),l=D(t),p=A({JourneyContext:e,boundJourney:s}),u=B({useJourneySnapshot:a,useJourneyStore:t});return{Provider:p,StepRenderer:u,useJourneyApi:l,useJourneyEvent:r,useJourneyMachine:o,useJourneySelector:n,useJourneySnapshot:a}};import{createTransitions as ge,tx as he,JOURNEY_STATUS as be,JOURNEY_EVENT as ke,JOURNEY_ASYNC_PHASE as Ue,JOURNEY_WILDCARD as we}from"@rxova/journey-core";export{Ue as JOURNEY_ASYNC_PHASE,ke as JOURNEY_EVENT,be as JOURNEY_STATUS,we as JOURNEY_WILDCARD,N as createJourneyBindings,ge as createTransitions,he as tx};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 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\n/**\n * Creates a typed React integration bundle (Provider, StepRenderer, and hooks)\n * bound to a specific journey definition.\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,
|
|
6
|
-
"names": ["React", "React", "createJourneyMachine", "jsx", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "journeyRef", "persistenceRef", "
|
|
3
|
+
"sources": ["../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyEvent.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySelector.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 { createUseJourneyEvent } from \"./useJourneyEvent\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySelector } from \"./useJourneySelector\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\n/**\n * Creates a typed React integration bundle (Provider, StepRenderer, and hooks)\n * bound to a specific journey definition.\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 useJourneySelector = createUseJourneySelector(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyEvent = createUseJourneyEvent(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 useJourneyEvent,\n useJourneyMachine,\n useJourneySelector,\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\nconst useSafeLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\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 completeOnNoNextStep,\n resetOnJourneyChange = false,\n resetOnPersistenceChange = false,\n onStart,\n onComplete,\n onTerminate,\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 const completeOnNoNextStepRef = React.useRef(completeOnNoNextStep);\n const onStartRef = React.useRef(onStart);\n const onCompleteRef = React.useRef(onComplete);\n const onTerminateRef = React.useRef(onTerminate);\n const [, forceUpdate] = React.useReducer((count: number) => count + 1, 0);\n const hasOnStart = onStart !== undefined;\n const hasOnComplete = onComplete !== undefined;\n const hasOnTerminate = onTerminate !== undefined;\n\n onStartRef.current = onStart;\n onCompleteRef.current = onComplete;\n onTerminateRef.current = onTerminate;\n\n if (!machine && !internalMachineRef.current) {\n const options =\n persistence !== undefined || completeOnNoNextStep !== undefined\n ? {\n ...(persistence !== undefined ? { persistence } : {}),\n ...(completeOnNoNextStep !== undefined ? { completeOnNoNextStep } : {})\n }\n : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n completeOnNoNextStepRef.current = completeOnNoNextStep;\n }\n\n const shouldResetJourney =\n !machine && resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence =\n !machine && resetOnPersistenceChange && persistenceRef.current !== persistence;\n const shouldResetNextCompletion =\n !machine && completeOnNoNextStepRef.current !== completeOnNoNextStep;\n\n useSafeLayoutEffect(() => {\n if (\n machine ||\n (!shouldResetJourney && !shouldResetPersistence && !shouldResetNextCompletion)\n ) {\n return;\n }\n\n const previousInternalMachine = internalMachineRef.current;\n const options =\n persistence !== undefined || completeOnNoNextStep !== undefined\n ? {\n ...(persistence !== undefined ? { persistence } : {}),\n ...(completeOnNoNextStep !== undefined ? { completeOnNoNextStep } : {})\n }\n : undefined;\n const nextInternalMachine = createJourneyMachine(incomingJourney, options);\n internalMachineRef.current = nextInternalMachine;\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n completeOnNoNextStepRef.current = completeOnNoNextStep;\n\n if (previousInternalMachine && previousInternalMachine !== nextInternalMachine) {\n previousInternalMachine.dispose();\n }\n\n forceUpdate();\n }, [\n completeOnNoNextStep,\n incomingJourney,\n machine,\n persistence,\n shouldResetJourney,\n shouldResetPersistence,\n shouldResetNextCompletion\n ]);\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value = React.useMemo<\n JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n >(\n () => ({\n machine: resolvedMachine,\n journey: resolvedJourney\n }),\n [resolvedMachine, resolvedJourney]\n );\n\n React.useEffect(() => {\n if (!hasOnStart && !hasOnComplete && !hasOnTerminate) {\n return;\n }\n\n const unsubStart = hasOnStart\n ? resolvedMachine.subscribeStart((event) => {\n onStartRef.current?.(event);\n })\n : undefined;\n\n const unsubComplete = hasOnComplete\n ? resolvedMachine.subscribeComplete((event) => {\n onCompleteRef.current?.(event);\n })\n : undefined;\n\n const unsubTerminate = hasOnTerminate\n ? resolvedMachine.subscribeTerminate((event) => {\n onTerminateRef.current?.(event);\n })\n : undefined;\n\n return () => {\n unsubStart?.();\n unsubComplete?.();\n unsubTerminate?.();\n };\n }, [hasOnStart, hasOnComplete, hasOnTerminate, resolvedMachine]);\n\n React.useEffect(() => {\n return () => {\n if (machine || !internalMachineRef.current) {\n return;\n }\n internalMachineRef.current.dispose();\n internalMachineRef.current = null;\n };\n }, [machine]);\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 key={snapshot.currentStepId} />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyPayloadFor, JourneySendEvent, JourneySendResult } 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\");\n\n return React.useMemo(\n () => ({\n send: async (\n event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.send(event);\n },\n goToNextStep: async (): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.goToNextStep();\n },\n terminateJourney: async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.terminateJourney(payload);\n },\n completeJourney: async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.completeJourney(payload);\n },\n goToPreviousStep: async (\n steps?: number\n ): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.goToPreviousStep(steps);\n },\n goToLastVisitedStep: async (): Promise<JourneySendResult<TContext, TStepId, TStepMeta>> => {\n return machine.goToLastVisitedStep();\n },\n clearStepError: (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n updateContext: (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n updateStepMetadata: (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n resetJourney: () => {\n machine.resetMachine();\n }\n }),\n [machine]\n );\n };\n};\n", "import React from \"react\";\n\nimport type { JourneyObservationEvent } 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 createUseJourneyEvent = <\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 listener: (\n event: JourneyObservationEvent<\n TStepId,\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n TStepMeta\n >\n ) => void\n ) => {\n const { machine } = useJourneyStore(\"useJourneyEvent\");\n const listenerRef = React.useRef(listener);\n listenerRef.current = listener;\n\n React.useEffect(() => {\n return machine.subscribeEvent((event) => {\n listenerRef.current(event);\n });\n }, [machine]);\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 { JourneyEqualityFn, JourneySelector, 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 SelectorCache<TContext, TStepId extends string, TStepMeta, TSelected> = {\n snapshot: JourneySnapshot<TContext, TStepId, TStepMeta>;\n selected: TSelected;\n selector: JourneySelector<TContext, TStepId, TStepMeta, TSelected>;\n isEqual: JourneyEqualityFn<TSelected>;\n};\n\nexport const createUseJourneySelector = <\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 <TSelected>(\n selector: JourneySelector<TContext, TStepId, TStepMeta, TSelected>,\n equalityFn?: JourneyEqualityFn<TSelected>\n ): TSelected => {\n const { machine } = useJourneyStore(\"useJourneySelector\");\n const isEqual = equalityFn ?? Object.is;\n const cacheRef = React.useRef<SelectorCache<TContext, TStepId, TStepMeta, TSelected> | null>(\n null\n );\n\n const getSelectedSnapshot = React.useCallback(() => {\n const nextSnapshot = machine.getSnapshot();\n const cached = cacheRef.current;\n\n if (\n cached &&\n cached.selector === selector &&\n cached.isEqual === isEqual &&\n Object.is(cached.snapshot, nextSnapshot)\n ) {\n return cached.selected;\n }\n\n const nextSelected = selector(nextSnapshot);\n\n if (cached && cached.selector === selector && cached.isEqual === isEqual) {\n if (cached.isEqual(cached.selected, nextSelected)) {\n cacheRef.current = {\n snapshot: nextSnapshot,\n selected: cached.selected,\n selector,\n isEqual\n };\n return cached.selected;\n }\n }\n\n cacheRef.current = {\n snapshot: nextSnapshot,\n selected: nextSelected,\n selector,\n isEqual\n };\n return nextSelected;\n }, [machine, selector, isEqual]);\n\n const subscribeToSelectedSnapshot = React.useCallback(\n (onStoreChange: () => void) =>\n machine.subscribeSelector(\n selector,\n () => {\n onStoreChange();\n },\n isEqual\n ),\n [machine, selector, isEqual]\n );\n\n return React.useSyncExternalStore(\n subscribeToSelectedSnapshot,\n getSelectedSnapshot,\n getSelectedSnapshot\n );\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 const getSnapshot = React.useCallback(() => machine.getSnapshot(), [machine]);\n const subscribe = React.useCallback(\n (onStoreChange: () => void) => machine.subscribe(onStoreChange),\n [machine]\n );\n\n return React.useSyncExternalStore(subscribe, getSnapshot, 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, JourneySendResult } 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,sBA+L1B,cAAAC,MAAA,oBAvLX,IAAMC,EAAsB,OAAO,OAAW,IAAcH,EAAM,UAAYA,EAAM,gBAyBvEI,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EACA,qBAAAC,EA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tEE,EAAYL,EAAM,YACrBM,GAA8BH,EAAQ,UAAUG,CAAa,EAC9D,CAACH,CAAO,CACV,EAEA,OAAOH,EAAM,qBAAqBK,EAAWD,EAAaA,CAAW,CACvE,EPbK,IAAMG,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,EAAqBC,EAAyBN,CAAe,EAC7DO,EAAoBC,EAAwBR,CAAe,EAC3DS,EAAkBC,EAAsBV,CAAe,EACvDW,EAAgBC,EAAoBZ,CAAe,EAEnDa,EAAWC,EAAe,CAC9B,eAAAhB,EACA,aAAAD,CACF,CAAC,EAEKkB,EAAeC,EAAmB,CACtC,mBAAAb,EACA,gBAAAH,CACF,CAAC,EAED,MAAO,CACL,SAAAa,EACA,aAAAE,EACA,cAAAJ,EACA,gBAAAF,EACA,kBAAAF,EACA,mBAAAF,EACA,mBAAAF,CACF,CACF,EQlEA,OACE,qBAAAc,GACA,MAAAC,GACA,kBAAAC,GACA,iBAAAC,GACA,uBAAAC,GACA,oBAAAC,OACK",
|
|
6
|
+
"names": ["React", "React", "createJourneyMachine", "jsx", "useSafeLayoutEffect", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "completeOnNoNextStep", "resetOnJourneyChange", "resetOnPersistenceChange", "onStart", "onComplete", "onTerminate", "children", "incomingJourney", "internalMachineRef", "journeyRef", "persistenceRef", "completeOnNoNextStepRef", "onStartRef", "onCompleteRef", "onTerminateRef", "forceUpdate", "count", "hasOnStart", "hasOnComplete", "hasOnTerminate", "options", "shouldResetJourney", "shouldResetPersistence", "shouldResetNextCompletion", "previousInternalMachine", "nextInternalMachine", "resolvedMachine", "resolvedJourney", "value", "unsubStart", "event", "unsubComplete", "unsubTerminate", "Fragment", "jsx", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "React", "createUseJourneyApi", "useJourneyStore", "machine", "event", "payload", "steps", "stepId", "updater", "React", "createUseJourneyEvent", "useJourneyStore", "listener", "machine", "listenerRef", "event", "createUseJourneyMachine", "useJourneyStore", "React", "createUseJourneySelector", "useJourneyStore", "selector", "equalityFn", "machine", "isEqual", "cacheRef", "getSelectedSnapshot", "nextSnapshot", "cached", "nextSelected", "subscribeToSelectedSnapshot", "onStoreChange", "React", "createUseJourneySnapshot", "useJourneyStore", "machine", "getSnapshot", "subscribe", "onStoreChange", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneySelector", "createUseJourneySelector", "useJourneyMachine", "createUseJourneyMachine", "useJourneyEvent", "createUseJourneyEvent", "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, JourneyEventPayloadMap as JourneyCoreEventPayloadMap, JourneyMachine, JourneyPayloadFor, JourneyPersistenceOptions, JourneySendEvent, JourneySnapshot, JourneyStepDefinition } from "@rxova/journey-core";
|
|
2
|
+
import type { JourneyDefinition, JourneyEqualityFn, JourneyEventPayloadMap as JourneyCoreEventPayloadMap, JourneyMachine, JourneyObservationEvent, JourneyPayloadFor, JourneyPersistenceOptions, JourneySelector, JourneySendEvent, JourneySendResult, 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,15 +10,14 @@ 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: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<
|
|
14
|
-
goToNextStep: () => Promise<
|
|
15
|
-
terminateJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "terminateJourney">) => Promise<
|
|
16
|
-
completeJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "completeJourney">) => Promise<
|
|
17
|
-
goToPreviousStep: (steps?: number) => Promise<
|
|
18
|
-
goToLastVisitedStep: () => Promise<
|
|
13
|
+
send: (event: JourneySendEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
14
|
+
goToNextStep: () => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
15
|
+
terminateJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "terminateJourney">) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
16
|
+
completeJourney: (payload?: JourneyPayloadFor<JourneyEventType<TCustomEvent>, TEventPayloadMap, "completeJourney">) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
17
|
+
goToPreviousStep: (steps?: number) => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
18
|
+
goToLastVisitedStep: () => Promise<JourneySendResult<TContext, TStepId, TStepMeta>>;
|
|
19
19
|
clearStepError: (stepId?: TStepId) => void;
|
|
20
20
|
updateContext: (updater: (context: TContext) => TContext) => void;
|
|
21
|
-
updateComponentMetadata: (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => void;
|
|
22
21
|
updateStepMetadata: (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => void;
|
|
23
22
|
resetJourney: () => void;
|
|
24
23
|
};
|
|
@@ -30,7 +29,18 @@ export type JourneyBindingsProviderProps<TContext, TStepId extends string, TCust
|
|
|
30
29
|
journey?: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;
|
|
31
30
|
machine?: JourneyMachine<TContext, TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>;
|
|
32
31
|
persistence?: JourneyPersistenceOptions<TContext, TStepId, TStepMeta>;
|
|
32
|
+
completeOnNoNextStep?: boolean;
|
|
33
33
|
resetOnJourneyChange?: boolean;
|
|
34
|
+
resetOnPersistenceChange?: boolean;
|
|
35
|
+
onStart?: (event: Extract<JourneyObservationEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>, {
|
|
36
|
+
type: "journey.start";
|
|
37
|
+
}>) => void;
|
|
38
|
+
onComplete?: (event: Extract<JourneyObservationEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>, {
|
|
39
|
+
type: "journey.complete";
|
|
40
|
+
}>) => void;
|
|
41
|
+
onTerminate?: (event: Extract<JourneyObservationEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>, {
|
|
42
|
+
type: "journey.close";
|
|
43
|
+
}>) => void;
|
|
34
44
|
children: React.ReactNode;
|
|
35
45
|
};
|
|
36
46
|
export type JourneyBindings<TContext, TStepId extends string, TCustomEvent extends string = never, TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>, TStepMeta = unknown> = {
|
|
@@ -40,5 +50,7 @@ export type JourneyBindings<TContext, TStepId extends string, TCustomEvent exten
|
|
|
40
50
|
}>;
|
|
41
51
|
useJourneyApi: () => JourneyApi<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;
|
|
42
52
|
useJourneyMachine: () => JourneyMachine<TContext, TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>;
|
|
53
|
+
useJourneyEvent: (listener: (event: JourneyObservationEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap, TStepMeta>) => void) => void;
|
|
54
|
+
useJourneySelector: <TSelected>(selector: JourneySelector<TContext, TStepId, TStepMeta, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected;
|
|
43
55
|
useJourneySnapshot: () => JourneySnapshot<TContext, TStepId, TStepMeta>;
|
|
44
56
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxova/journey-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.
|
|
50
|
+
"@rxova/journey-core": "^0.7.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=18.2.0"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"name": "react/createJourneyBindings",
|
|
63
63
|
"path": "dist/index.js",
|
|
64
64
|
"import": "{ createJourneyBindings }",
|
|
65
|
-
"limit": "
|
|
65
|
+
"limit": "6 kB"
|
|
66
66
|
}
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"react-dom": "^19.2.4"
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
|
-
"build": "pnpm run clean && node ./scripts/build.
|
|
77
|
-
"clean": "node ../../scripts/clean-paths.
|
|
76
|
+
"build": "pnpm run clean && node --import tsx ./scripts/build.ts && tsc -p tsconfig.build.json && node --import tsx ../../scripts/copy-types.ts dist",
|
|
77
|
+
"clean": "node --import tsx ../../scripts/clean-paths.ts 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",
|