@rxova/journey-react 0.7.0 → 1.0.0-rc.1

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.
@@ -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/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 return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n};\n"],
5
- "mappings": "mlBAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,uLAAAE,EAAA,uEAAAC,GAAAH,ICAA,IAAAI,EAAkB,sBCAlB,IAAAC,EAAkB,sBAElBC,EAAqC,+BA+L1BC,EAAA,6BAvLLC,GAAsB,OAAO,OAAW,IAAc,EAAAC,QAAM,UAAY,EAAAA,QAAM,gBAyBvEC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EACA,qBAAAC,EAAuB,GACvB,yBAAAC,EAA2B,GAC3B,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBV,GAAWD,EAC7BY,EAAqB,EAAAf,QAAM,OAG/B,IAAI,EACAgB,EAAa,EAAAhB,QAAM,OAAOc,CAAe,EACzCG,EAAiB,EAAAjB,QAAM,OAAOM,CAAW,EACzCY,EAA0B,EAAAlB,QAAM,OAAOO,CAAoB,EAC3DY,EAAa,EAAAnB,QAAM,OAAOU,CAAO,EACjCU,EAAgB,EAAApB,QAAM,OAAOW,CAAU,EACvCU,EAAiB,EAAArB,QAAM,OAAOY,CAAW,EACzC,CAAC,CAAEU,EAAW,EAAI,EAAAtB,QAAM,WAAYuB,GAAkBA,EAAQ,EAAG,CAAC,EAClEC,EAAad,IAAY,OACzBe,EAAgBd,IAAe,OAC/Be,EAAiBd,IAAgB,OAMvC,GAJAO,EAAW,QAAUT,EACrBU,EAAc,QAAUT,EACxBU,EAAe,QAAUT,EAErB,CAACP,GAAW,CAACU,EAAmB,QAAS,CAC3C,IAAMY,EACJrB,IAAgB,QAAaC,IAAyB,OAClD,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C,EAED,MAAO,CACL,SAAAa,EACA,aAAAE,EACA,cAAAJ,EACA,gBAAAF,EACA,kBAAAF,EACA,mBAAAF,EACA,mBAAAF,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"]
3
+ "sources": ["../src/index.ts", "../src/createJourney.tsx", "../src/provider.tsx", "../src/runtime-hooks.tsx"],
4
+ "sourcesContent": ["export { createJourney, createJourneyFactory } from \"./createJourney\";\nexport type {\n JourneyCompleteObservationEvent,\n JourneyComputed,\n JourneyDefinition,\n JourneyEqualityFn,\n JourneyMachine,\n JourneyMachineOptions,\n JourneyMachinePlugin,\n JourneyMachineWithPlugins,\n JourneyObservationEvent,\n JourneySelector,\n JourneySendResult,\n JourneyStartObservationEvent,\n JourneySnapshot,\n JourneyLifecycleArgs\n} from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyCompleteEvent,\n JourneyDefaultEvent,\n JourneyProviderErrorContext,\n JourneyProviderProps,\n JourneyRuntime,\n JourneyRuntimeFactory,\n JourneyStartEvent,\n JourneyTerminateEvent,\n JourneyViews\n} from \"./types\";\n", "import { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyDefinition,\n JourneyJsonObject,\n JourneyMachineOptions,\n JourneyMachinePlugin,\n JourneyMachineWithPlugins\n} from \"@rxova/journey-core\";\nimport { createJourneyProviderArtifacts } from \"./provider\";\nimport { createJourneyHooks } from \"./runtime-hooks\";\nimport type { JourneyRuntime, JourneyRuntimeFactory } from \"./types\";\n\ntype JourneyOptionsInput<TPlugins extends readonly JourneyMachinePlugin[]> = JourneyMachineOptions<\n TPlugins extends [] ? readonly JourneyMachinePlugin[] : TPlugins\n>;\n\n/**\n * Creates a journey machine and returns React hooks/components bound to that machine.\n * Hooks work without a provider; `JourneyProvider` is only required for `StepRenderer`.\n */\nexport const createJourney = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n definition: JourneyDefinition<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options?: JourneyOptionsInput<TPlugins>\n): JourneyRuntime<TContext, TStepId, TEventMap, TStepMeta, TPlugins, THandlers> => {\n const machineOptions = options as JourneyMachineOptions<TPlugins> | undefined;\n const machine = createJourneyMachine<\n TContext,\n TStepId,\n TEventMap,\n TStepMeta,\n THandlers,\n TPlugins\n >(definition, machineOptions) as JourneyMachineWithPlugins<\n TContext,\n TStepId,\n TEventMap,\n TStepMeta,\n THandlers,\n TPlugins\n >;\n const hooks = createJourneyHooks<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>(\n machine\n );\n const providerArtifacts = createJourneyProviderArtifacts<\n TContext,\n TStepId,\n TEventMap,\n TStepMeta,\n THandlers,\n TPlugins\n >(machine, hooks.useJourneySelector);\n\n return {\n machine,\n dispose: () => machine.dispose(),\n ...hooks,\n ...providerArtifacts\n };\n};\n\n/**\n * Creates a typed factory for producing fresh React-bound journey runtimes.\n * Use this when a component or route boundary needs independent instances\n * from the same definition/options pair.\n */\nexport const createJourneyFactory = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n definition: JourneyDefinition<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options?: JourneyOptionsInput<TPlugins>\n): JourneyRuntimeFactory<TContext, TStepId, TEventMap, TStepMeta, TPlugins, THandlers> => {\n return () =>\n createJourney<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>(\n definition,\n options\n );\n};\n", "import React from \"react\";\n\nimport type {\n JourneyEqualityFn,\n JourneyJsonObject,\n JourneySelector,\n JourneyMachineWithPlugins,\n JourneyMachinePlugin\n} from \"@rxova/journey-core\";\nimport type { JourneyProviderErrorContext, JourneyProviderProps, JourneyViews } from \"./types\";\n\nconst useSafeLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nconst reportProviderError = (\n error: unknown,\n context: JourneyProviderErrorContext,\n listener?: ((error: unknown, context: JourneyProviderErrorContext) => void) | undefined\n) => {\n if (listener) {\n listener(error, context);\n return;\n }\n\n console.error(`JourneyProvider ${context.phase} failed.`, error);\n};\n\nexport const createJourneyProviderArtifacts = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>,\n useJourneySelector: <TSelected>(\n selector: JourneySelector<TContext, TStepId, TSelected>,\n equalityFn?: JourneyEqualityFn<TSelected>\n ) => TSelected\n) => {\n const ViewsContext = React.createContext<JourneyViews<TStepId> | null>(null);\n\n const useJourneyViews = (hookName = \"hook\") => {\n const views = React.useContext(ViewsContext);\n if (!views) {\n throw new Error(`${hookName} must be used within JourneyProvider.`);\n }\n return views;\n };\n\n const ProviderController = ({\n runtimeMachine,\n onStart,\n onComplete,\n onTerminate,\n onError,\n disposeOnUnmount\n }: {\n runtimeMachine: typeof machine;\n onStart: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onStart\"] | undefined;\n onComplete: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onComplete\"] | undefined;\n onTerminate: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onTerminate\"] | undefined;\n onError: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onError\"] | undefined;\n disposeOnUnmount: boolean;\n }) => {\n const onStartRef = React.useRef(onStart);\n const onCompleteRef = React.useRef(onComplete);\n const onTerminateRef = React.useRef(onTerminate);\n const onErrorRef = React.useRef(onError);\n const scheduledDisposeRef = React.useRef<ReturnType<typeof globalThis.setTimeout> | null>(null);\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 onErrorRef.current = onError;\n\n useSafeLayoutEffect(() => {\n if (scheduledDisposeRef.current === null) {\n return;\n }\n\n globalThis.clearTimeout(scheduledDisposeRef.current);\n scheduledDisposeRef.current = null;\n });\n\n const selectStatus = React.useCallback(\n (snapshot: ReturnType<typeof runtimeMachine.getSnapshot>) => snapshot.status,\n [runtimeMachine]\n );\n const subscribeToStatus = React.useCallback(\n (onStoreChange: () => void) =>\n runtimeMachine.subscribeSelector(selectStatus, () => {\n onStoreChange();\n }),\n [runtimeMachine, selectStatus]\n );\n const getStatus = React.useCallback(\n () => runtimeMachine.getSnapshot().status,\n [runtimeMachine]\n );\n const status = React.useSyncExternalStore(subscribeToStatus, getStatus, getStatus);\n\n useSafeLayoutEffect(() => {\n if (!hasOnStart && !hasOnComplete && !hasOnTerminate) {\n return;\n }\n\n const unsubStart = hasOnStart\n ? runtimeMachine.subscribeStart((event) => {\n onStartRef.current?.(event);\n })\n : undefined;\n\n const unsubComplete = hasOnComplete\n ? runtimeMachine.subscribeComplete((event) => {\n onCompleteRef.current?.(event);\n })\n : undefined;\n\n const unsubTerminate = hasOnTerminate\n ? runtimeMachine.subscribeTerminate((event) => {\n onTerminateRef.current?.(event);\n })\n : undefined;\n\n return () => {\n unsubStart?.();\n unsubComplete?.();\n unsubTerminate?.();\n };\n }, [runtimeMachine, hasOnComplete, hasOnStart, hasOnTerminate]);\n\n useSafeLayoutEffect(() => {\n if (status === \"idled\") {\n void runtimeMachine.start().catch((error) => {\n reportProviderError(error, { phase: \"start\" }, onErrorRef.current);\n });\n }\n }, [runtimeMachine, status]);\n\n useSafeLayoutEffect(() => {\n if (!disposeOnUnmount) {\n return;\n }\n\n return () => {\n scheduledDisposeRef.current = globalThis.setTimeout(() => {\n scheduledDisposeRef.current = null;\n runtimeMachine.dispose();\n }, 0);\n };\n }, [runtimeMachine, disposeOnUnmount]);\n\n return null;\n };\n\n const JourneyProvider = ({\n views,\n onStart,\n onComplete,\n onTerminate,\n onError,\n disposeOnUnmount = false,\n children\n }: JourneyProviderProps<TStepId, TEventMap, TStepMeta>) => {\n const runtimeMachine = machine;\n\n return (\n <ViewsContext.Provider value={views}>\n {children}\n <ProviderController\n runtimeMachine={runtimeMachine}\n onStart={onStart}\n onComplete={onComplete}\n onTerminate={onTerminate}\n onError={onError}\n disposeOnUnmount={disposeOnUnmount}\n />\n </ViewsContext.Provider>\n );\n };\n\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const currentStepId = useJourneySelector((snapshot) => snapshot.currentStepId);\n const views = useJourneyViews(\"StepRenderer\");\n const StepComponent = views[currentStepId];\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n const StepView = StepComponent as React.ComponentType;\n\n return (\n <React.Fragment key={currentStepId}>\n <StepView />\n </React.Fragment>\n );\n };\n\n return {\n JourneyProvider,\n StepRenderer\n };\n};\n", "import React from \"react\";\n\nimport type {\n JourneyComputed,\n JourneyEqualityFn,\n JourneyJsonObject,\n JourneyMachinePlugin,\n JourneyMachineWithPlugins,\n JourneyObservationEvent,\n JourneySelector,\n JourneySnapshot\n} from \"@rxova/journey-core\";\nimport type { JourneyApi } from \"./types\";\n\ntype SelectorCache<TContext extends JourneyJsonObject, TStepId extends string, TSelected> = {\n machine: unknown;\n snapshot: JourneySnapshot<TContext, TStepId>;\n selected: TSelected;\n selector: unknown;\n isEqual: JourneyEqualityFn<TSelected>;\n};\n\nconst useSafeLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nexport const createJourneyHooks = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>\n) => {\n const useJourneySnapshot = (): JourneySnapshot<TContext, TStepId> => {\n const runtimeMachine = machine;\n const getSnapshot = React.useCallback(() => runtimeMachine.getSnapshot(), [runtimeMachine]);\n const subscribe = React.useCallback(\n (onStoreChange: () => void) => runtimeMachine.subscribe(onStoreChange),\n [runtimeMachine]\n );\n\n return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n\n const useJourneyComputed = (): JourneyComputed<TStepId> => {\n const snapshot = useJourneySnapshot();\n const runtimeMachine = machine;\n return React.useMemo(() => {\n void snapshot;\n return runtimeMachine.getComputed();\n }, [runtimeMachine, snapshot]);\n };\n\n const useJourneySelector = <TSelected,>(\n selector: JourneySelector<TContext, TStepId, TSelected>,\n equalityFn?: JourneyEqualityFn<TSelected>\n ): TSelected => {\n const runtimeMachine = machine;\n const isEqual = equalityFn ?? Object.is;\n const cacheRef = React.useRef<SelectorCache<TContext, TStepId, TSelected> | null>(null);\n\n const getSelectedSnapshot = React.useCallback(() => {\n const nextSnapshot = runtimeMachine.getSnapshot();\n const cached = cacheRef.current;\n\n if (\n cached &&\n Object.is(cached.machine, runtimeMachine) &&\n Object.is(cached.selector, selector) &&\n Object.is(cached.isEqual, isEqual) &&\n Object.is(cached.snapshot, nextSnapshot)\n ) {\n return cached.selected;\n }\n\n const nextSelected = selector(nextSnapshot);\n\n if (\n cached &&\n Object.is(cached.machine, runtimeMachine) &&\n Object.is(cached.selector, selector) &&\n Object.is(cached.isEqual, isEqual) &&\n isEqual(cached.selected, nextSelected)\n ) {\n cacheRef.current = {\n machine: runtimeMachine,\n snapshot: nextSnapshot,\n selected: cached.selected,\n selector,\n isEqual\n };\n return cached.selected;\n }\n\n cacheRef.current = {\n machine: runtimeMachine,\n snapshot: nextSnapshot,\n selected: nextSelected,\n selector,\n isEqual\n };\n return nextSelected;\n }, [runtimeMachine, isEqual, selector]);\n\n const subscribeToSelectedSnapshot = React.useCallback(\n (onStoreChange: () => void) =>\n runtimeMachine.subscribeSelector(\n selector,\n () => {\n onStoreChange();\n },\n isEqual\n ),\n [runtimeMachine, isEqual, selector]\n );\n\n return React.useSyncExternalStore(\n subscribeToSelectedSnapshot,\n getSelectedSnapshot,\n getSelectedSnapshot\n );\n };\n\n const useJourneyEvent = (\n listener: (event: JourneyObservationEvent<TStepId, TEventMap>) => void\n ): void => {\n const runtimeMachine = machine;\n const listenerRef = React.useRef(listener);\n listenerRef.current = listener;\n\n useSafeLayoutEffect(() => {\n return runtimeMachine.subscribeEvent((event) => {\n listenerRef.current(event);\n });\n }, [runtimeMachine]);\n };\n\n const useJourneyStepLifecycle = (\n stepId: TStepId,\n callbacks: {\n onEnter?: (args: { context: TContext }) => void;\n onLeave?: (args: { context: TContext }) => void;\n }\n ): void => {\n useJourneyEvent((event) => {\n if (event.type === \"step.enter\" && event.stepId === stepId) {\n callbacks.onEnter?.({ context: machine.getSnapshot().context });\n } else if (event.type === \"step.exit\" && event.stepId === stepId) {\n callbacks.onLeave?.({ context: machine.getSnapshot().context });\n }\n });\n };\n\n const useJourneyApi = (): JourneyApi<TContext, TStepId, TEventMap, TStepMeta> => {\n const runtimeMachine = machine;\n return React.useMemo(\n () => ({\n start: runtimeMachine.start,\n send: runtimeMachine.send,\n goToNextStep: runtimeMachine.goToNextStep,\n goToStepById: runtimeMachine.goToStepById,\n terminateJourney: runtimeMachine.terminateJourney,\n completeJourney: runtimeMachine.completeJourney,\n goToPreviousStep: runtimeMachine.goToPreviousStep,\n goToLastVisitedStep: runtimeMachine.goToLastVisitedStep,\n clearStepError: runtimeMachine.clearStepError,\n updateContext: runtimeMachine.updateContext,\n getStepMeta: runtimeMachine.getStepMeta,\n resetJourney: () => runtimeMachine.resetJourney()\n }),\n [runtimeMachine]\n );\n };\n\n return {\n useJourneySnapshot,\n useJourneyComputed,\n useJourneySelector,\n useJourneyApi,\n useJourneyEvent,\n useJourneyStepLifecycle\n };\n};\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GCAA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e,MACtB,KAAMA,EAAe,KACrB,aAAcA,EAAe,aAC7B,aAAcA,EAAe,aAC7B,iBAAkBA,EAAe,iBACjC,gBAAiBA,EAAe,gBAChC,iBAAkBA,EAAe,iBACjC,oBAAqBA,EAAe,oBACpC,eAAgBA,EAAe,eAC/B,cAAeA,EAAe,cAC9B,YAAaA,EAAe,YAC5B,aAAc,IAAMA,EAAe,aAAa,CAClD,GACA,CAACA,CAAc,CACjB,CACF,EAOE,gBAAAgB,EACA,wBA3C8B,CAC9BI,EACAC,IAIS,CACTL,EAAiBG,GAAU,CACrBA,EAAM,OAAS,cAAgBA,EAAM,SAAWC,EAClDC,EAAU,UAAU,CAAE,QAASvB,EAAQ,YAAY,EAAE,OAAQ,CAAC,EACrDqB,EAAM,OAAS,aAAeA,EAAM,SAAWC,GACxDC,EAAU,UAAU,CAAE,QAASvB,EAAQ,YAAY,EAAE,OAAQ,CAAC,CAElE,CAAC,CACH,CA8BA,CACF,EFnKO,IAAMwB,EAAgB,CAQ3BC,EACAC,IACiF,CAEjF,IAAMC,KAAU,wBAOdF,EARqBC,CAQK,EAQtBE,EAAQC,EACZF,CACF,EACMG,EAAoBC,EAOxBJ,EAASC,EAAM,kBAAkB,EAEnC,MAAO,CACL,QAAAD,EACA,QAAS,IAAMA,EAAQ,QAAQ,EAC/B,GAAGC,EACH,GAAGE,CACL,CACF,EAOaE,EAAuB,CAQlCP,EACAC,IAEO,IACLF,EACEC,EACAC,CACF",
6
+ "names": ["index_exports", "__export", "createJourney", "createJourneyFactory", "__toCommonJS", "import_journey_core", "import_react", "import_jsx_runtime", "useSafeLayoutEffect", "React", "reportProviderError", "error", "context", "listener", "createJourneyProviderArtifacts", "machine", "useJourneySelector", "ViewsContext", "useJourneyViews", "hookName", "views", "ProviderController", "runtimeMachine", "onStart", "onComplete", "onTerminate", "onError", "disposeOnUnmount", "onStartRef", "onCompleteRef", "onTerminateRef", "onErrorRef", "scheduledDisposeRef", "hasOnStart", "hasOnComplete", "hasOnTerminate", "selectStatus", "snapshot", "subscribeToStatus", "onStoreChange", "getStatus", "status", "unsubStart", "event", "unsubComplete", "unsubTerminate", "children", "fallback", "currentStepId", "StepComponent", "StepView", "import_react", "useSafeLayoutEffect", "React", "createJourneyHooks", "machine", "useJourneySnapshot", "runtimeMachine", "getSnapshot", "subscribe", "onStoreChange", "useJourneyComputed", "snapshot", "useJourneySelector", "selector", "equalityFn", "isEqual", "cacheRef", "getSelectedSnapshot", "nextSnapshot", "cached", "nextSelected", "subscribeToSelectedSnapshot", "useJourneyEvent", "listener", "listenerRef", "event", "stepId", "callbacks", "createJourney", "definition", "options", "machine", "hooks", "createJourneyHooks", "providerArtifacts", "createJourneyProviderArtifacts", "createJourneyFactory"]
7
7
  }
package/dist/index.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- export { createJourneyBindings } from "./bindings";
2
- export { createTransitions, tx, JOURNEY_STATUS, JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_WILDCARD } from "@rxova/journey-core";
3
- export type { JourneyDefinition, JourneySendResult } from "@rxova/journey-core";
4
- export type { JourneyApi, JourneyBindings, JourneyBindingsProviderProps, JourneyEventType, JourneyReactDefinition, JourneyReactEventPayloadMap, JourneyReactStep, JourneyStoreValue } from "./types";
1
+ export { createJourney, createJourneyFactory } from "./createJourney";
2
+ export type { JourneyCompleteObservationEvent, JourneyComputed, JourneyDefinition, JourneyEqualityFn, JourneyMachine, JourneyMachineOptions, JourneyMachinePlugin, JourneyMachineWithPlugins, JourneyObservationEvent, JourneySelector, JourneySendResult, JourneyStartObservationEvent, JourneySnapshot, JourneyLifecycleArgs } from "@rxova/journey-core";
3
+ export type { JourneyApi, JourneyCompleteEvent, JourneyDefaultEvent, JourneyProviderErrorContext, JourneyProviderProps, JourneyRuntime, JourneyRuntimeFactory, JourneyStartEvent, JourneyTerminateEvent, JourneyViews } from "./types";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { createJourneyBindings } from "./bindings";
2
- export { createTransitions, tx, JOURNEY_STATUS, JOURNEY_EVENT, JOURNEY_ASYNC_PHASE, JOURNEY_WILDCARD } from "@rxova/journey-core";
3
- export type { JourneyDefinition, JourneySendResult } from "@rxova/journey-core";
4
- export type { JourneyApi, JourneyBindings, JourneyBindingsProviderProps, JourneyEventType, JourneyReactDefinition, JourneyReactEventPayloadMap, JourneyReactStep, JourneyStoreValue } from "./types";
1
+ export { createJourney, createJourneyFactory } from "./createJourney";
2
+ export type { JourneyCompleteObservationEvent, JourneyComputed, JourneyDefinition, JourneyEqualityFn, JourneyMachine, JourneyMachineOptions, JourneyMachinePlugin, JourneyMachineWithPlugins, JourneyObservationEvent, JourneySelector, JourneySendResult, JourneyStartObservationEvent, JourneySnapshot, JourneyLifecycleArgs } from "@rxova/journey-core";
3
+ export type { JourneyApi, JourneyCompleteEvent, JourneyDefaultEvent, JourneyProviderErrorContext, JourneyProviderProps, JourneyRuntime, JourneyRuntimeFactory, JourneyStartEvent, JourneyTerminateEvent, JourneyViews } from "./types";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
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};
1
+ import{createJourneyMachine as W}from"@rxova/journey-core";import u from"react";import{Fragment as A,jsx as h,jsxs as L}from"react/jsx-runtime";var g=typeof window>"u"?u.useEffect:u.useLayoutEffect,q=(r,c,y)=>{if(y){y(r,c);return}console.error(`JourneyProvider ${c.phase} failed.`,r)},I=(r,c)=>{let y=u.createContext(null),l=(e="hook")=>{let t=u.useContext(y);if(!t)throw new Error(`${e} must be used within JourneyProvider.`);return t},T=({runtimeMachine:e,onStart:t,onComplete:n,onTerminate:o,onError:p,disposeOnUnmount:d})=>{let J=u.useRef(t),a=u.useRef(n),s=u.useRef(o),v=u.useRef(p),f=u.useRef(null),P=t!==void 0,E=n!==void 0,m=o!==void 0;J.current=t,a.current=n,s.current=o,v.current=p,g(()=>{f.current!==null&&(globalThis.clearTimeout(f.current),f.current=null)});let C=u.useCallback(S=>S.status,[e]),j=u.useCallback(S=>e.subscribeSelector(C,()=>{S()}),[e,C]),b=u.useCallback(()=>e.getSnapshot().status,[e]),R=u.useSyncExternalStore(j,b,b);return g(()=>{if(!P&&!E&&!m)return;let S=P?e.subscribeStart(x=>{J.current?.(x)}):void 0,H=E?e.subscribeComplete(x=>{a.current?.(x)}):void 0,F=m?e.subscribeTerminate(x=>{s.current?.(x)}):void 0;return()=>{S?.(),H?.(),F?.()}},[e,E,P,m]),g(()=>{R==="idled"&&e.start().catch(S=>{q(S,{phase:"start"},v.current)})},[e,R]),g(()=>{if(d)return()=>{f.current=globalThis.setTimeout(()=>{f.current=null,e.dispose()},0)}},[e,d]),null};return{JourneyProvider:({views:e,onStart:t,onComplete:n,onTerminate:o,onError:p,disposeOnUnmount:d=!1,children:J})=>{let a=r;return L(y.Provider,{value:e,children:[J,h(T,{runtimeMachine:a,onStart:t,onComplete:n,onTerminate:o,onError:p,disposeOnUnmount:d})]})},StepRenderer:({fallback:e=null})=>{let t=c(d=>d.currentStepId),o=l("StepRenderer")[t];if(!o)return h(A,{children:e});let p=o;return h(u.Fragment,{children:h(p,{})},t)}}};import i from"react";var V=typeof window>"u"?i.useEffect:i.useLayoutEffect,O=r=>{let c=()=>{let e=r,t=i.useCallback(()=>e.getSnapshot(),[e]),n=i.useCallback(o=>e.subscribe(o),[e]);return i.useSyncExternalStore(n,t,t)},y=()=>{let e=c(),t=r;return i.useMemo(()=>t.getComputed(),[t,e])},l=(e,t)=>{let n=r,o=t??Object.is,p=i.useRef(null),d=i.useCallback(()=>{let a=n.getSnapshot(),s=p.current;if(s&&Object.is(s.machine,n)&&Object.is(s.selector,e)&&Object.is(s.isEqual,o)&&Object.is(s.snapshot,a))return s.selected;let v=e(a);return s&&Object.is(s.machine,n)&&Object.is(s.selector,e)&&Object.is(s.isEqual,o)&&o(s.selected,v)?(p.current={machine:n,snapshot:a,selected:s.selected,selector:e,isEqual:o},s.selected):(p.current={machine:n,snapshot:a,selected:v,selector:e,isEqual:o},v)},[n,o,e]),J=i.useCallback(a=>n.subscribeSelector(e,()=>{a()},o),[n,o,e]);return i.useSyncExternalStore(J,d,d)},T=e=>{let t=r,n=i.useRef(e);n.current=e,V(()=>t.subscribeEvent(o=>{n.current(o)}),[t])};return{useJourneySnapshot:c,useJourneyComputed:y,useJourneySelector:l,useJourneyApi:()=>{let e=r;return i.useMemo(()=>({start:e.start,send:e.send,goToNextStep:e.goToNextStep,goToStepById:e.goToStepById,terminateJourney:e.terminateJourney,completeJourney:e.completeJourney,goToPreviousStep:e.goToPreviousStep,goToLastVisitedStep:e.goToLastVisitedStep,clearStepError:e.clearStepError,updateContext:e.updateContext,getStepMeta:e.getStepMeta,resetJourney:()=>e.resetJourney()}),[e])},useJourneyEvent:T,useJourneyStepLifecycle:(e,t)=>{T(n=>{n.type==="step.enter"&&n.stepId===e?t.onEnter?.({context:r.getSnapshot().context}):n.type==="step.exit"&&n.stepId===e&&t.onLeave?.({context:r.getSnapshot().context})})}}};var w=(r,c)=>{let l=W(r,c),T=O(l),M=I(l,T.useJourneySelector);return{machine:l,dispose:()=>l.dispose(),...T,...M}},D=(r,c)=>()=>w(r,c);export{w as createJourney,D as createJourneyFactory};
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/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,UA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GAEO,IAAqD,CAC1D,GAAM,CAAE,QAAAC,CAAQ,EAAID,EAAgB,oBAAoB,EAClDE,EAAcJ,EAAM,YAAY,IAAMG,EAAQ,YAAY,EAAG,CAACA,CAAO,CAAC,EACtEE,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"]
3
+ "sources": ["../src/createJourney.tsx", "../src/provider.tsx", "../src/runtime-hooks.tsx"],
4
+ "sourcesContent": ["import { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyDefinition,\n JourneyJsonObject,\n JourneyMachineOptions,\n JourneyMachinePlugin,\n JourneyMachineWithPlugins\n} from \"@rxova/journey-core\";\nimport { createJourneyProviderArtifacts } from \"./provider\";\nimport { createJourneyHooks } from \"./runtime-hooks\";\nimport type { JourneyRuntime, JourneyRuntimeFactory } from \"./types\";\n\ntype JourneyOptionsInput<TPlugins extends readonly JourneyMachinePlugin[]> = JourneyMachineOptions<\n TPlugins extends [] ? readonly JourneyMachinePlugin[] : TPlugins\n>;\n\n/**\n * Creates a journey machine and returns React hooks/components bound to that machine.\n * Hooks work without a provider; `JourneyProvider` is only required for `StepRenderer`.\n */\nexport const createJourney = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n definition: JourneyDefinition<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options?: JourneyOptionsInput<TPlugins>\n): JourneyRuntime<TContext, TStepId, TEventMap, TStepMeta, TPlugins, THandlers> => {\n const machineOptions = options as JourneyMachineOptions<TPlugins> | undefined;\n const machine = createJourneyMachine<\n TContext,\n TStepId,\n TEventMap,\n TStepMeta,\n THandlers,\n TPlugins\n >(definition, machineOptions) as JourneyMachineWithPlugins<\n TContext,\n TStepId,\n TEventMap,\n TStepMeta,\n THandlers,\n TPlugins\n >;\n const hooks = createJourneyHooks<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>(\n machine\n );\n const providerArtifacts = createJourneyProviderArtifacts<\n TContext,\n TStepId,\n TEventMap,\n TStepMeta,\n THandlers,\n TPlugins\n >(machine, hooks.useJourneySelector);\n\n return {\n machine,\n dispose: () => machine.dispose(),\n ...hooks,\n ...providerArtifacts\n };\n};\n\n/**\n * Creates a typed factory for producing fresh React-bound journey runtimes.\n * Use this when a component or route boundary needs independent instances\n * from the same definition/options pair.\n */\nexport const createJourneyFactory = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n definition: JourneyDefinition<TContext, TStepId, TEventMap, TStepMeta, THandlers>,\n options?: JourneyOptionsInput<TPlugins>\n): JourneyRuntimeFactory<TContext, TStepId, TEventMap, TStepMeta, TPlugins, THandlers> => {\n return () =>\n createJourney<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>(\n definition,\n options\n );\n};\n", "import React from \"react\";\n\nimport type {\n JourneyEqualityFn,\n JourneyJsonObject,\n JourneySelector,\n JourneyMachineWithPlugins,\n JourneyMachinePlugin\n} from \"@rxova/journey-core\";\nimport type { JourneyProviderErrorContext, JourneyProviderProps, JourneyViews } from \"./types\";\n\nconst useSafeLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nconst reportProviderError = (\n error: unknown,\n context: JourneyProviderErrorContext,\n listener?: ((error: unknown, context: JourneyProviderErrorContext) => void) | undefined\n) => {\n if (listener) {\n listener(error, context);\n return;\n }\n\n console.error(`JourneyProvider ${context.phase} failed.`, error);\n};\n\nexport const createJourneyProviderArtifacts = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>,\n useJourneySelector: <TSelected>(\n selector: JourneySelector<TContext, TStepId, TSelected>,\n equalityFn?: JourneyEqualityFn<TSelected>\n ) => TSelected\n) => {\n const ViewsContext = React.createContext<JourneyViews<TStepId> | null>(null);\n\n const useJourneyViews = (hookName = \"hook\") => {\n const views = React.useContext(ViewsContext);\n if (!views) {\n throw new Error(`${hookName} must be used within JourneyProvider.`);\n }\n return views;\n };\n\n const ProviderController = ({\n runtimeMachine,\n onStart,\n onComplete,\n onTerminate,\n onError,\n disposeOnUnmount\n }: {\n runtimeMachine: typeof machine;\n onStart: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onStart\"] | undefined;\n onComplete: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onComplete\"] | undefined;\n onTerminate: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onTerminate\"] | undefined;\n onError: JourneyProviderProps<TStepId, TEventMap, TStepMeta>[\"onError\"] | undefined;\n disposeOnUnmount: boolean;\n }) => {\n const onStartRef = React.useRef(onStart);\n const onCompleteRef = React.useRef(onComplete);\n const onTerminateRef = React.useRef(onTerminate);\n const onErrorRef = React.useRef(onError);\n const scheduledDisposeRef = React.useRef<ReturnType<typeof globalThis.setTimeout> | null>(null);\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 onErrorRef.current = onError;\n\n useSafeLayoutEffect(() => {\n if (scheduledDisposeRef.current === null) {\n return;\n }\n\n globalThis.clearTimeout(scheduledDisposeRef.current);\n scheduledDisposeRef.current = null;\n });\n\n const selectStatus = React.useCallback(\n (snapshot: ReturnType<typeof runtimeMachine.getSnapshot>) => snapshot.status,\n [runtimeMachine]\n );\n const subscribeToStatus = React.useCallback(\n (onStoreChange: () => void) =>\n runtimeMachine.subscribeSelector(selectStatus, () => {\n onStoreChange();\n }),\n [runtimeMachine, selectStatus]\n );\n const getStatus = React.useCallback(\n () => runtimeMachine.getSnapshot().status,\n [runtimeMachine]\n );\n const status = React.useSyncExternalStore(subscribeToStatus, getStatus, getStatus);\n\n useSafeLayoutEffect(() => {\n if (!hasOnStart && !hasOnComplete && !hasOnTerminate) {\n return;\n }\n\n const unsubStart = hasOnStart\n ? runtimeMachine.subscribeStart((event) => {\n onStartRef.current?.(event);\n })\n : undefined;\n\n const unsubComplete = hasOnComplete\n ? runtimeMachine.subscribeComplete((event) => {\n onCompleteRef.current?.(event);\n })\n : undefined;\n\n const unsubTerminate = hasOnTerminate\n ? runtimeMachine.subscribeTerminate((event) => {\n onTerminateRef.current?.(event);\n })\n : undefined;\n\n return () => {\n unsubStart?.();\n unsubComplete?.();\n unsubTerminate?.();\n };\n }, [runtimeMachine, hasOnComplete, hasOnStart, hasOnTerminate]);\n\n useSafeLayoutEffect(() => {\n if (status === \"idled\") {\n void runtimeMachine.start().catch((error) => {\n reportProviderError(error, { phase: \"start\" }, onErrorRef.current);\n });\n }\n }, [runtimeMachine, status]);\n\n useSafeLayoutEffect(() => {\n if (!disposeOnUnmount) {\n return;\n }\n\n return () => {\n scheduledDisposeRef.current = globalThis.setTimeout(() => {\n scheduledDisposeRef.current = null;\n runtimeMachine.dispose();\n }, 0);\n };\n }, [runtimeMachine, disposeOnUnmount]);\n\n return null;\n };\n\n const JourneyProvider = ({\n views,\n onStart,\n onComplete,\n onTerminate,\n onError,\n disposeOnUnmount = false,\n children\n }: JourneyProviderProps<TStepId, TEventMap, TStepMeta>) => {\n const runtimeMachine = machine;\n\n return (\n <ViewsContext.Provider value={views}>\n {children}\n <ProviderController\n runtimeMachine={runtimeMachine}\n onStart={onStart}\n onComplete={onComplete}\n onTerminate={onTerminate}\n onError={onError}\n disposeOnUnmount={disposeOnUnmount}\n />\n </ViewsContext.Provider>\n );\n };\n\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const currentStepId = useJourneySelector((snapshot) => snapshot.currentStepId);\n const views = useJourneyViews(\"StepRenderer\");\n const StepComponent = views[currentStepId];\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n const StepView = StepComponent as React.ComponentType;\n\n return (\n <React.Fragment key={currentStepId}>\n <StepView />\n </React.Fragment>\n );\n };\n\n return {\n JourneyProvider,\n StepRenderer\n };\n};\n", "import React from \"react\";\n\nimport type {\n JourneyComputed,\n JourneyEqualityFn,\n JourneyJsonObject,\n JourneyMachinePlugin,\n JourneyMachineWithPlugins,\n JourneyObservationEvent,\n JourneySelector,\n JourneySnapshot\n} from \"@rxova/journey-core\";\nimport type { JourneyApi } from \"./types\";\n\ntype SelectorCache<TContext extends JourneyJsonObject, TStepId extends string, TSelected> = {\n machine: unknown;\n snapshot: JourneySnapshot<TContext, TStepId>;\n selected: TSelected;\n selector: unknown;\n isEqual: JourneyEqualityFn<TSelected>;\n};\n\nconst useSafeLayoutEffect = typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nexport const createJourneyHooks = <\n TContext extends JourneyJsonObject,\n TStepId extends string,\n TEventMap extends Record<string, unknown> = Record<never, never>,\n TStepMeta = unknown,\n THandlers extends Record<string, unknown> = Record<never, never>,\n TPlugins extends readonly JourneyMachinePlugin[] = []\n>(\n machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>\n) => {\n const useJourneySnapshot = (): JourneySnapshot<TContext, TStepId> => {\n const runtimeMachine = machine;\n const getSnapshot = React.useCallback(() => runtimeMachine.getSnapshot(), [runtimeMachine]);\n const subscribe = React.useCallback(\n (onStoreChange: () => void) => runtimeMachine.subscribe(onStoreChange),\n [runtimeMachine]\n );\n\n return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n };\n\n const useJourneyComputed = (): JourneyComputed<TStepId> => {\n const snapshot = useJourneySnapshot();\n const runtimeMachine = machine;\n return React.useMemo(() => {\n void snapshot;\n return runtimeMachine.getComputed();\n }, [runtimeMachine, snapshot]);\n };\n\n const useJourneySelector = <TSelected,>(\n selector: JourneySelector<TContext, TStepId, TSelected>,\n equalityFn?: JourneyEqualityFn<TSelected>\n ): TSelected => {\n const runtimeMachine = machine;\n const isEqual = equalityFn ?? Object.is;\n const cacheRef = React.useRef<SelectorCache<TContext, TStepId, TSelected> | null>(null);\n\n const getSelectedSnapshot = React.useCallback(() => {\n const nextSnapshot = runtimeMachine.getSnapshot();\n const cached = cacheRef.current;\n\n if (\n cached &&\n Object.is(cached.machine, runtimeMachine) &&\n Object.is(cached.selector, selector) &&\n Object.is(cached.isEqual, isEqual) &&\n Object.is(cached.snapshot, nextSnapshot)\n ) {\n return cached.selected;\n }\n\n const nextSelected = selector(nextSnapshot);\n\n if (\n cached &&\n Object.is(cached.machine, runtimeMachine) &&\n Object.is(cached.selector, selector) &&\n Object.is(cached.isEqual, isEqual) &&\n isEqual(cached.selected, nextSelected)\n ) {\n cacheRef.current = {\n machine: runtimeMachine,\n snapshot: nextSnapshot,\n selected: cached.selected,\n selector,\n isEqual\n };\n return cached.selected;\n }\n\n cacheRef.current = {\n machine: runtimeMachine,\n snapshot: nextSnapshot,\n selected: nextSelected,\n selector,\n isEqual\n };\n return nextSelected;\n }, [runtimeMachine, isEqual, selector]);\n\n const subscribeToSelectedSnapshot = React.useCallback(\n (onStoreChange: () => void) =>\n runtimeMachine.subscribeSelector(\n selector,\n () => {\n onStoreChange();\n },\n isEqual\n ),\n [runtimeMachine, isEqual, selector]\n );\n\n return React.useSyncExternalStore(\n subscribeToSelectedSnapshot,\n getSelectedSnapshot,\n getSelectedSnapshot\n );\n };\n\n const useJourneyEvent = (\n listener: (event: JourneyObservationEvent<TStepId, TEventMap>) => void\n ): void => {\n const runtimeMachine = machine;\n const listenerRef = React.useRef(listener);\n listenerRef.current = listener;\n\n useSafeLayoutEffect(() => {\n return runtimeMachine.subscribeEvent((event) => {\n listenerRef.current(event);\n });\n }, [runtimeMachine]);\n };\n\n const useJourneyStepLifecycle = (\n stepId: TStepId,\n callbacks: {\n onEnter?: (args: { context: TContext }) => void;\n onLeave?: (args: { context: TContext }) => void;\n }\n ): void => {\n useJourneyEvent((event) => {\n if (event.type === \"step.enter\" && event.stepId === stepId) {\n callbacks.onEnter?.({ context: machine.getSnapshot().context });\n } else if (event.type === \"step.exit\" && event.stepId === stepId) {\n callbacks.onLeave?.({ context: machine.getSnapshot().context });\n }\n });\n };\n\n const useJourneyApi = (): JourneyApi<TContext, TStepId, TEventMap, TStepMeta> => {\n const runtimeMachine = machine;\n return React.useMemo(\n () => ({\n start: runtimeMachine.start,\n send: runtimeMachine.send,\n goToNextStep: runtimeMachine.goToNextStep,\n goToStepById: runtimeMachine.goToStepById,\n terminateJourney: runtimeMachine.terminateJourney,\n completeJourney: runtimeMachine.completeJourney,\n goToPreviousStep: runtimeMachine.goToPreviousStep,\n goToLastVisitedStep: runtimeMachine.goToLastVisitedStep,\n clearStepError: runtimeMachine.clearStepError,\n updateContext: runtimeMachine.updateContext,\n getStepMeta: runtimeMachine.getStepMeta,\n resetJourney: () => runtimeMachine.resetJourney()\n }),\n [runtimeMachine]\n );\n };\n\n return {\n useJourneySnapshot,\n useJourneyComputed,\n useJourneySelector,\n useJourneyApi,\n useJourneyEvent,\n useJourneyStepLifecycle\n };\n};\n"],
5
+ "mappings": "AAAA,OAAS,wBAAAA,MAA4B,sBCArC,OAAOC,MAAW,QA2KZ,OAoBO,YAAAC,EAlBL,OAAAC,EAFF,QAAAC,MAAA,oBAhKN,IAAMC,EAAsB,OAAO,OAAW,IAAcJ,EAAM,UAAYA,EAAM,gBAE9EK,EAAsB,CAC1BC,EACAC,EACAC,IACG,CACH,GAAIA,EAAU,CACZA,EAASF,EAAOC,CAAO,EACvB,MACF,CAEA,QAAQ,MAAM,mBAAmBA,EAAQ,KAAK,WAAYD,CAAK,CACjE,EAEaG,EAAiC,CAQ5CC,EACAC,IAIG,CACH,IAAMC,EAAeZ,EAAM,cAA4C,IAAI,EAErEa,EAAkB,CAACC,EAAW,SAAW,CAC7C,IAAMC,EAAQf,EAAM,WAAWY,CAAY,EAC3C,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,GAAGD,CAAQ,uCAAuC,EAEpE,OAAOC,CACT,EAEMC,EAAqB,CAAC,CAC1B,eAAAC,EACA,QAAAC,EACA,WAAAC,EACA,YAAAC,EACA,QAAAC,EACA,iBAAAC,CACF,IAOM,CACJ,IAAMC,EAAavB,EAAM,OAAOkB,CAAO,EACjCM,EAAgBxB,EAAM,OAAOmB,CAAU,EACvCM,EAAiBzB,EAAM,OAAOoB,CAAW,EACzCM,EAAa1B,EAAM,OAAOqB,CAAO,EACjCM,EAAsB3B,EAAM,OAAwD,IAAI,EACxF4B,EAAaV,IAAY,OACzBW,EAAgBV,IAAe,OAC/BW,EAAiBV,IAAgB,OAEvCG,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oB,IACXI,EAAe,eAAgBmB,GAAU,CAC9CD,EAAY,QAAQC,CAAK,CAC3B,CAAC,EACA,CAACnB,CAAc,CAAC,CACrB,EAuCA,MAAO,CACL,mBAAAD,EACA,mBAAAK,EACA,mBAAAE,EACA,cAzBoB,IAA2D,CAC/E,IAAMN,EAAiBF,EACvB,OAAOH,EAAM,QACX,KAAO,CACL,MAAOK,EAAe,MACtB,KAAMA,EAAe,KACrB,aAAcA,EAAe,aAC7B,aAAcA,EAAe,aAC7B,iBAAkBA,EAAe,iBACjC,gBAAiBA,EAAe,gBAChC,iBAAkBA,EAAe,iBACjC,oBAAqBA,EAAe,oBACpC,eAAgBA,EAAe,eAC/B,cAAeA,EAAe,cAC9B,YAAaA,EAAe,YAC5B,aAAc,IAAMA,EAAe,aAAa,CAClD,GACA,CAACA,CAAc,CACjB,CACF,EAOE,gBAAAgB,EACA,wBA3C8B,CAC9BI,EACAC,IAIS,CACTL,EAAiBG,GAAU,CACrBA,EAAM,OAAS,cAAgBA,EAAM,SAAWC,EAClDC,EAAU,UAAU,CAAE,QAASvB,EAAQ,YAAY,EAAE,OAAQ,CAAC,EACrDqB,EAAM,OAAS,aAAeA,EAAM,SAAWC,GACxDC,EAAU,UAAU,CAAE,QAASvB,EAAQ,YAAY,EAAE,OAAQ,CAAC,CAElE,CAAC,CACH,CA8BA,CACF,EFnKO,IAAMwB,EAAgB,CAQ3BC,EACAC,IACiF,CAEjF,IAAMC,EAAUC,EAOdH,EARqBC,CAQK,EAQtBG,EAAQC,EACZH,CACF,EACMI,EAAoBC,EAOxBL,EAASE,EAAM,kBAAkB,EAEnC,MAAO,CACL,QAAAF,EACA,QAAS,IAAMA,EAAQ,QAAQ,EAC/B,GAAGE,EACH,GAAGE,CACL,CACF,EAOaE,EAAuB,CAQlCR,EACAC,IAEO,IACLF,EACEC,EACAC,CACF",
6
+ "names": ["createJourneyMachine", "React", "Fragment", "jsx", "jsxs", "useSafeLayoutEffect", "reportProviderError", "error", "context", "listener", "createJourneyProviderArtifacts", "machine", "useJourneySelector", "ViewsContext", "useJourneyViews", "hookName", "views", "ProviderController", "runtimeMachine", "onStart", "onComplete", "onTerminate", "onError", "disposeOnUnmount", "onStartRef", "onCompleteRef", "onTerminateRef", "onErrorRef", "scheduledDisposeRef", "hasOnStart", "hasOnComplete", "hasOnTerminate", "selectStatus", "snapshot", "subscribeToStatus", "onStoreChange", "getStatus", "status", "unsubStart", "event", "unsubComplete", "unsubTerminate", "children", "fallback", "currentStepId", "StepComponent", "StepView", "React", "useSafeLayoutEffect", "createJourneyHooks", "machine", "useJourneySnapshot", "runtimeMachine", "getSnapshot", "subscribe", "onStoreChange", "useJourneyComputed", "snapshot", "useJourneySelector", "selector", "equalityFn", "isEqual", "cacheRef", "getSelectedSnapshot", "nextSnapshot", "cached", "nextSelected", "subscribeToSelectedSnapshot", "useJourneyEvent", "listener", "listenerRef", "event", "stepId", "callbacks", "createJourney", "definition", "options", "machine", "createJourneyMachine", "hooks", "createJourneyHooks", "providerArtifacts", "createJourneyProviderArtifacts", "createJourneyFactory"]
7
7
  }
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import type { JourneyEqualityFn, JourneyJsonObject, JourneySelector, JourneyMachineWithPlugins, JourneyMachinePlugin } from "@rxova/journey-core";
3
+ import type { JourneyProviderProps } from "./types";
4
+ export declare const createJourneyProviderArtifacts: <TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, THandlers extends Record<string, unknown> = Record<never, never>, TPlugins extends readonly JourneyMachinePlugin[] = []>(machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>, useJourneySelector: <TSelected>(selector: JourneySelector<TContext, TStepId, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected) => {
5
+ JourneyProvider: ({ views, onStart, onComplete, onTerminate, onError, disposeOnUnmount, children }: JourneyProviderProps<TStepId, TEventMap, TStepMeta>) => import("react/jsx-runtime").JSX.Element;
6
+ StepRenderer: ({ fallback }: {
7
+ fallback?: React.ReactNode;
8
+ }) => import("react/jsx-runtime").JSX.Element;
9
+ };
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import type { JourneyEqualityFn, JourneyJsonObject, JourneySelector, JourneyMachineWithPlugins, JourneyMachinePlugin } from "@rxova/journey-core";
3
+ import type { JourneyProviderProps } from "./types";
4
+ export declare const createJourneyProviderArtifacts: <TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, THandlers extends Record<string, unknown> = Record<never, never>, TPlugins extends readonly JourneyMachinePlugin[] = []>(machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>, useJourneySelector: <TSelected>(selector: JourneySelector<TContext, TStepId, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected) => {
5
+ JourneyProvider: ({ views, onStart, onComplete, onTerminate, onError, disposeOnUnmount, children }: JourneyProviderProps<TStepId, TEventMap, TStepMeta>) => import("react/jsx-runtime").JSX.Element;
6
+ StepRenderer: ({ fallback }: {
7
+ fallback?: React.ReactNode;
8
+ }) => import("react/jsx-runtime").JSX.Element;
9
+ };
@@ -0,0 +1,17 @@
1
+ import type { JourneyComputed, JourneyEqualityFn, JourneyJsonObject, JourneyMachinePlugin, JourneyMachineWithPlugins, JourneyObservationEvent, JourneySelector, JourneySnapshot } from "@rxova/journey-core";
2
+ import type { JourneyApi } from "./types";
3
+ export declare const createJourneyHooks: <TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, THandlers extends Record<string, unknown> = Record<never, never>, TPlugins extends readonly JourneyMachinePlugin[] = []>(machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>) => {
4
+ useJourneySnapshot: () => JourneySnapshot<TContext, TStepId>;
5
+ useJourneyComputed: () => JourneyComputed<TStepId>;
6
+ useJourneySelector: <TSelected>(selector: JourneySelector<TContext, TStepId, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected;
7
+ useJourneyApi: () => JourneyApi<TContext, TStepId, TEventMap, TStepMeta>;
8
+ useJourneyEvent: (listener: (event: JourneyObservationEvent<TStepId, TEventMap>) => void) => void;
9
+ useJourneyStepLifecycle: (stepId: TStepId, callbacks: {
10
+ onEnter?: (args: {
11
+ context: TContext;
12
+ }) => void;
13
+ onLeave?: (args: {
14
+ context: TContext;
15
+ }) => void;
16
+ }) => void;
17
+ };
@@ -0,0 +1,17 @@
1
+ import type { JourneyComputed, JourneyEqualityFn, JourneyJsonObject, JourneyMachinePlugin, JourneyMachineWithPlugins, JourneyObservationEvent, JourneySelector, JourneySnapshot } from "@rxova/journey-core";
2
+ import type { JourneyApi } from "./types";
3
+ export declare const createJourneyHooks: <TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, THandlers extends Record<string, unknown> = Record<never, never>, TPlugins extends readonly JourneyMachinePlugin[] = []>(machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>) => {
4
+ useJourneySnapshot: () => JourneySnapshot<TContext, TStepId>;
5
+ useJourneyComputed: () => JourneyComputed<TStepId>;
6
+ useJourneySelector: <TSelected>(selector: JourneySelector<TContext, TStepId, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected;
7
+ useJourneyApi: () => JourneyApi<TContext, TStepId, TEventMap, TStepMeta>;
8
+ useJourneyEvent: (listener: (event: JourneyObservationEvent<TStepId, TEventMap>) => void) => void;
9
+ useJourneyStepLifecycle: (stepId: TStepId, callbacks: {
10
+ onEnter?: (args: {
11
+ context: TContext;
12
+ }) => void;
13
+ onLeave?: (args: {
14
+ context: TContext;
15
+ }) => void;
16
+ }) => void;
17
+ };
@@ -0,0 +1,58 @@
1
+ import type React from "react";
2
+ import type { JourneyCompleteObservationEvent, JourneyComputed, JourneyDefaultEventType, JourneyEqualityFn, JourneyJsonObject, JourneyMachinePlugin, JourneyMachineWithPlugins, JourneyObservationEvent, JourneyPayloadFor, JourneySelector, JourneySendEvent, JourneySendResult, JourneyStartObservationEvent, JourneyTerminateObservationEvent, JourneySnapshot } from "@rxova/journey-core";
3
+ export type JourneyDefaultEvent = JourneyDefaultEventType;
4
+ export type JourneyViews<TStepId extends string> = Record<TStepId, React.ComponentType>;
5
+ type JourneyTypeParam<TValue> = TValue extends unknown ? unknown : never;
6
+ type JourneyCompatEventAliasContext<TEventMap extends Record<string, unknown>, TStepMeta = unknown> = (JourneyObservationEvent<string, TEventMap> extends never ? never : unknown) & JourneyTypeParam<TStepMeta>;
7
+ export type JourneyApi<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown> = {
8
+ start: () => Promise<JourneySnapshot<TContext, TStepId>>;
9
+ send: (event: JourneySendEvent<TStepId, TEventMap>) => Promise<JourneySendResult<TContext, TStepId>>;
10
+ goToNextStep: () => Promise<JourneySendResult<TContext, TStepId>>;
11
+ goToStepById: (stepId: TStepId) => Promise<JourneySendResult<TContext, TStepId>>;
12
+ terminateJourney: (payload?: JourneyPayloadFor<TEventMap, "terminateJourney">) => Promise<JourneySendResult<TContext, TStepId>>;
13
+ completeJourney: (payload?: JourneyPayloadFor<TEventMap, "completeJourney">) => Promise<JourneySendResult<TContext, TStepId>>;
14
+ goToPreviousStep: (steps?: number) => Promise<JourneySendResult<TContext, TStepId>>;
15
+ goToLastVisitedStep: () => Promise<JourneySendResult<TContext, TStepId>>;
16
+ clearStepError: (stepId?: TStepId) => Promise<JourneySnapshot<TContext, TStepId>>;
17
+ updateContext: (updater: (context: TContext) => TContext) => Promise<JourneySnapshot<TContext, TStepId>>;
18
+ getStepMeta: (stepId: TStepId) => TStepMeta | undefined;
19
+ resetJourney: () => Promise<JourneySnapshot<TContext, TStepId>>;
20
+ };
21
+ export type JourneyStartEvent<TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown> = JourneyStartObservationEvent<TStepId> & JourneyCompatEventAliasContext<TEventMap, TStepMeta>;
22
+ export type JourneyCompleteEvent<TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown> = JourneyCompleteObservationEvent<TStepId> & JourneyCompatEventAliasContext<TEventMap, TStepMeta>;
23
+ export type JourneyTerminateEvent<TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown> = JourneyTerminateObservationEvent<TStepId> & JourneyCompatEventAliasContext<TEventMap, TStepMeta>;
24
+ export type JourneyProviderErrorContext = {
25
+ phase: "start";
26
+ };
27
+ export type JourneyProviderProps<TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown> = {
28
+ views: JourneyViews<TStepId>;
29
+ onStart?: (event: JourneyStartEvent<TStepId, TEventMap, TStepMeta>) => void;
30
+ onComplete?: (event: JourneyCompleteEvent<TStepId, TEventMap, TStepMeta>) => void;
31
+ onTerminate?: (event: JourneyTerminateEvent<TStepId, TEventMap, TStepMeta>) => void;
32
+ onError?: (error: unknown, context: JourneyProviderErrorContext) => void;
33
+ disposeOnUnmount?: boolean;
34
+ children: React.ReactNode;
35
+ };
36
+ export type JourneyRuntime<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, TPlugins extends readonly JourneyMachinePlugin[] = [], THandlers extends Record<string, unknown> = Record<never, never>> = {
37
+ machine: JourneyMachineWithPlugins<TContext, TStepId, TEventMap, TStepMeta, THandlers, TPlugins>;
38
+ dispose: () => void;
39
+ useJourneySnapshot: () => JourneySnapshot<TContext, TStepId>;
40
+ useJourneyComputed: () => JourneyComputed<TStepId>;
41
+ useJourneySelector: <TSelected>(selector: JourneySelector<TContext, TStepId, TSelected>, equalityFn?: JourneyEqualityFn<TSelected>) => TSelected;
42
+ useJourneyApi: () => JourneyApi<TContext, TStepId, TEventMap, TStepMeta>;
43
+ useJourneyEvent: (listener: (event: JourneyObservationEvent<TStepId, TEventMap>) => void) => void;
44
+ useJourneyStepLifecycle: (stepId: TStepId, callbacks: {
45
+ onEnter?: (args: {
46
+ context: TContext;
47
+ }) => void;
48
+ onLeave?: (args: {
49
+ context: TContext;
50
+ }) => void;
51
+ }) => void;
52
+ JourneyProvider: React.ComponentType<JourneyProviderProps<TStepId, TEventMap, TStepMeta>>;
53
+ StepRenderer: React.ComponentType<{
54
+ fallback?: React.ReactNode;
55
+ }>;
56
+ };
57
+ export type JourneyRuntimeFactory<TContext extends JourneyJsonObject, TStepId extends string, TEventMap extends Record<string, unknown> = Record<never, never>, TStepMeta = unknown, TPlugins extends readonly JourneyMachinePlugin[] = [], THandlers extends Record<string, unknown> = Record<never, never>> = () => JourneyRuntime<TContext, TStepId, TEventMap, TStepMeta, TPlugins, THandlers>;
58
+ export {};