@rxova/journey-react 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
1
|
+
"use strict";"use client";var A=Object.create;var l=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var Y=(t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})},M=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!j.call(t,o)&&o!==n&&l(t,o,{get:()=>e[o],enumerable:!(s=B(e,o))||s.enumerable});return t};var E=(t,e,n)=>(n=t!=null?A(F(t)):{},M(e||!t||!t.__esModule?l(n,"default",{value:t,enumerable:!0}):n,t)),_=t=>M(l({},"__esModule",{value:!0}),t);var O={};Y(O,{JOURNEY_ASYNC_PHASE:()=>a.JOURNEY_ASYNC_PHASE,JOURNEY_EVENT:()=>a.JOURNEY_EVENT,JOURNEY_STATUS:()=>a.JOURNEY_STATUS,JOURNEY_WILDCARD:()=>a.JOURNEY_WILDCARD,createJourneyBindings:()=>w,createTransitions:()=>a.createTransitions,tx:()=>a.tx});module.exports=_(O);var C=E(require("react"),1);var m=E(require("react"),1),x=require("@rxova/journey-core"),R=require("react/jsx-runtime"),P=({JourneyContext:t,boundJourney:e})=>({journey:s,machine:o,persistence:u,resetOnJourneyChange:d=!1,children:v})=>{let y=s??e,T=m.default.useRef(null),c=m.default.useRef(y),S=m.default.useRef(u),r=d&&c.current!==y,J=S.current!==u;if(!o&&(!T.current||r||J)){let N=u?{persistence:u}:void 0;T.current=(0,x.createJourneyMachine)(y,N),c.current=y,S.current=u}let U=o??T.current,V=o?y:c.current,b={machine:U,journey:V};return(0,R.jsx)(t.Provider,{value:b,children:v})};var i=require("react/jsx-runtime"),g=({useJourneySnapshot:t,useJourneyStore:e})=>({fallback:s=null})=>{let o=t(),{journey:u}=e("StepRenderer"),d=u.steps[o.currentStepId]?.component;return d?(0,i.jsx)(d,{}):(0,i.jsx)(i.Fragment,{children:s})};var p=E(require("react"),1),f=t=>()=>{let e=t("useJourneyApi").machine,n=p.default.useCallback(async r=>{await e.send(r)},[e]),s=p.default.useCallback(async()=>{await e.goToNextStep()},[e]),o=p.default.useCallback(async r=>{await e.terminateJourney(r)},[e]),u=p.default.useCallback(async r=>{await e.completeJourney(r)},[e]),d=p.default.useCallback(async r=>{await e.goToPreviousStep(r)},[e]),v=p.default.useCallback(async()=>{await e.goToLastVisitedStep()},[e]),y=p.default.useCallback(r=>{e.updateContext(r)},[e]),T=p.default.useCallback((r,J)=>{e.updateStepMetadata(r,J)},[e]),c=p.default.useCallback(r=>{e.clearStepError(r)},[e]),S=p.default.useCallback(()=>{e.resetMachine()},[e]);return{send:n,goToNextStep:s,terminateJourney:o,completeJourney:u,goToPreviousStep:d,goToLastVisitedStep:v,clearStepError:c,updateContext:y,updateStepMetadata:T,updateComponentMetadata:T,resetJourney:S}};var I=t=>()=>t("useJourneyMachine").machine;var h=E(require("react"),1),k=t=>()=>{let{machine:e}=t("useJourneySnapshot");return h.default.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)};var w=t=>{let e=C.default.createContext(null),n=(y="hook")=>{let T=C.default.useContext(e);if(!T)throw new Error(`${y} must be used within bindings.Provider.`);return T},s=k(n),o=I(n),u=f(n),d=P({JourneyContext:e,boundJourney:t}),v=g({useJourneySnapshot:s,useJourneyStore:n});return{Provider:d,StepRenderer:v,useJourneyApi:u,useJourneyMachine:o,useJourneySnapshot:s}};var a=require("@rxova/journey-core");0&&(module.exports={JOURNEY_ASYNC_PHASE,JOURNEY_EVENT,JOURNEY_STATUS,JOURNEY_WILDCARD,createJourneyBindings,createTransitions,tx});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySnapshot.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n", "import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyEvent, JourneyPayloadFor } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n"],
|
|
5
|
-
"mappings": "ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,
|
|
6
|
-
"names": ["index_exports", "__export", "createJourneyBindings", "__toCommonJS", "import_react", "import_react", "import_journey_core", "import_jsx_runtime", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "React", "journeyRef", "persistenceRef", "shouldResetInternal", "shouldResetPersistence", "options", "resolvedMachine", "resolvedJourney", "value", "import_jsx_runtime", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "import_react", "createUseJourneyApi", "useJourneyStore", "machine", "send", "React", "event", "goToNextStep", "terminateJourney", "payload", "completeJourney", "goToPreviousStep", "steps", "goToLastVisitedStep", "updateContext", "updater", "updateStepMetadata", "stepId", "clearStepError", "resetJourney", "createUseJourneyMachine", "useJourneyStore", "import_react", "createUseJourneySnapshot", "useJourneyStore", "machine", "React", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneyMachine", "createUseJourneyMachine", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer"]
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport {\n createTransitions,\n tx,\n JOURNEY_STATUS,\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_WILDCARD\n} from \"@rxova/journey-core\";\nexport type { JourneyDefinition } from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n", "import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyEvent, JourneyPayloadFor } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n"],
|
|
5
|
+
"mappings": "ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uLAAAE,EAAA,uEAAAC,EAAAH,GCAA,IAAAI,EAAkB,sBCAlB,IAAAC,EAAkB,sBAElBC,EAAqC,+BAkF1BC,EAAA,6BAnDEC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EAAuB,GACvB,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBL,GAAWD,EAC7BO,EAAqB,EAAAC,QAAM,OAG/B,IAAI,EACAC,EAAa,EAAAD,QAAM,OAAOF,CAAe,EACzCI,EAAiB,EAAAF,QAAM,OAAOL,CAAW,EAEzCQ,EAAsBP,GAAwBK,EAAW,UAAYH,EACrEM,EAAyBF,EAAe,UAAYP,EAE1D,GACE,CAACD,IACA,CAACK,EAAmB,SAAWI,GAAuBC,GACvD,CACA,IAAMC,EAAUV,EAAc,CAAE,YAAAA,CAAY,EAAI,OAChDI,EAAmB,WAAU,wBAAqBD,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EnDS,EAAWC,EAAe,CAC9B,eAAAZ,EACA,aAAAD,CACF,CAAC,EAEKc,EAAeC,EAAmB,CACtC,mBAAAT,EACA,gBAAAH,CACF,CAAC,EAED,MAAO,CACL,SAAAS,EACA,aAAAE,EACA,cAAAJ,EACA,kBAAAF,EACA,mBAAAF,CACF,CACF,EDzDA,IAAAU,EAOO",
|
|
6
|
+
"names": ["index_exports", "__export", "createJourneyBindings", "__toCommonJS", "import_react", "import_react", "import_journey_core", "import_jsx_runtime", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "React", "journeyRef", "persistenceRef", "shouldResetInternal", "shouldResetPersistence", "options", "resolvedMachine", "resolvedJourney", "value", "import_jsx_runtime", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "import_react", "createUseJourneyApi", "useJourneyStore", "machine", "send", "React", "event", "goToNextStep", "terminateJourney", "payload", "completeJourney", "goToPreviousStep", "steps", "goToLastVisitedStep", "updateContext", "updater", "updateStepMetadata", "stepId", "clearStepError", "resetJourney", "createUseJourneyMachine", "useJourneyStore", "import_react", "createUseJourneySnapshot", "useJourneyStore", "machine", "React", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneyMachine", "createUseJourneyMachine", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer", "import_journey_core"]
|
|
7
7
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
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 } from "@rxova/journey-core";
|
|
2
4
|
export type { JourneyApi, JourneyBindings, JourneyBindingsProviderProps, JourneyEventType, JourneyReactDefinition, JourneyReactEventPayloadMap, JourneyReactStep, JourneyStoreValue } from "./types";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
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 } from "@rxova/journey-core";
|
|
2
4
|
export type { JourneyApi, JourneyBindings, JourneyBindingsProviderProps, JourneyEventType, JourneyReactDefinition, JourneyReactEventPayloadMap, JourneyReactStep, JourneyStoreValue } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import x from"react";import S from"react";import{createJourneyMachine as I}from"@rxova/journey-core";import{jsx as h}from"react/jsx-runtime";var l=({JourneyContext:n,boundJourney:e})=>({journey:y,machine:a,persistence:o,resetOnJourneyChange:T=!1,children:d})=>{let s=y??e,u=S.useRef(null),v=S.useRef(s),c=S.useRef(o),t=T&&v.current!==s,i=c.current!==o;if(!a&&(!u.current||t||i)){let f=o?{persistence:o}:void 0;u.current=I(s,f),v.current=s,c.current=o}let P=a??u.current,R=a?s:v.current,g={machine:P,journey:R};return h(n.Provider,{value:g,children:d})};import{Fragment as k,jsx as E}from"react/jsx-runtime";var m=({useJourneySnapshot:n,useJourneyStore:e})=>({fallback:y=null})=>{let a=n(),{journey:o}=e("StepRenderer"),T=o.steps[a.currentStepId]?.component;return T?E(T,{}):E(k,{children:y})};import r from"react";var J=n=>()=>{let e=n("useJourneyApi").machine,p=r.useCallback(async t=>{await e.send(t)},[e]),y=r.useCallback(async()=>{await e.goToNextStep()},[e]),a=r.useCallback(async t=>{await e.terminateJourney(t)},[e]),o=r.useCallback(async t=>{await e.completeJourney(t)},[e]),T=r.useCallback(async t=>{await e.goToPreviousStep(t)},[e]),d=r.useCallback(async()=>{await e.goToLastVisitedStep()},[e]),s=r.useCallback(t=>{e.updateContext(t)},[e]),u=r.useCallback((t,i)=>{e.updateStepMetadata(t,i)},[e]),v=r.useCallback(t=>{e.clearStepError(t)},[e]),c=r.useCallback(()=>{e.resetMachine()},[e]);return{send:p,goToNextStep:y,terminateJourney:a,completeJourney:o,goToPreviousStep:T,goToLastVisitedStep:d,clearStepError:v,updateContext:s,updateStepMetadata:u,updateComponentMetadata:u,resetJourney:c}};var C=n=>()=>n("useJourneyMachine").machine;import w from"react";var M=n=>()=>{let{machine:e}=n("useJourneySnapshot");return w.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)};var
|
|
1
|
+
"use client";import x from"react";import S from"react";import{createJourneyMachine as I}from"@rxova/journey-core";import{jsx as h}from"react/jsx-runtime";var l=({JourneyContext:n,boundJourney:e})=>({journey:y,machine:a,persistence:o,resetOnJourneyChange:T=!1,children:d})=>{let s=y??e,u=S.useRef(null),v=S.useRef(s),c=S.useRef(o),t=T&&v.current!==s,i=c.current!==o;if(!a&&(!u.current||t||i)){let f=o?{persistence:o}:void 0;u.current=I(s,f),v.current=s,c.current=o}let P=a??u.current,R=a?s:v.current,g={machine:P,journey:R};return h(n.Provider,{value:g,children:d})};import{Fragment as k,jsx as E}from"react/jsx-runtime";var m=({useJourneySnapshot:n,useJourneyStore:e})=>({fallback:y=null})=>{let a=n(),{journey:o}=e("StepRenderer"),T=o.steps[a.currentStepId]?.component;return T?E(T,{}):E(k,{children:y})};import r from"react";var J=n=>()=>{let e=n("useJourneyApi").machine,p=r.useCallback(async t=>{await e.send(t)},[e]),y=r.useCallback(async()=>{await e.goToNextStep()},[e]),a=r.useCallback(async t=>{await e.terminateJourney(t)},[e]),o=r.useCallback(async t=>{await e.completeJourney(t)},[e]),T=r.useCallback(async t=>{await e.goToPreviousStep(t)},[e]),d=r.useCallback(async()=>{await e.goToLastVisitedStep()},[e]),s=r.useCallback(t=>{e.updateContext(t)},[e]),u=r.useCallback((t,i)=>{e.updateStepMetadata(t,i)},[e]),v=r.useCallback(t=>{e.clearStepError(t)},[e]),c=r.useCallback(()=>{e.resetMachine()},[e]);return{send:p,goToNextStep:y,terminateJourney:a,completeJourney:o,goToPreviousStep:T,goToLastVisitedStep:d,clearStepError:v,updateContext:s,updateStepMetadata:u,updateComponentMetadata:u,resetJourney:c}};var C=n=>()=>n("useJourneyMachine").machine;import w from"react";var M=n=>()=>{let{machine:e}=n("useJourneySnapshot");return w.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot)};var U=n=>{let e=x.createContext(null),p=(s="hook")=>{let u=x.useContext(e);if(!u)throw new Error(`${s} must be used within bindings.Provider.`);return u},y=M(p),a=C(p),o=J(p),T=l({JourneyContext:e,boundJourney:n}),d=m({useJourneySnapshot:y,useJourneyStore:p});return{Provider:T,StepRenderer:d,useJourneyApi:o,useJourneyMachine:a,useJourneySnapshot:y}};import{createTransitions as Z,tx as ee,JOURNEY_STATUS as te,JOURNEY_EVENT as ne,JOURNEY_ASYNC_PHASE as oe,JOURNEY_WILDCARD as re}from"@rxova/journey-core";export{oe as JOURNEY_ASYNC_PHASE,ne as JOURNEY_EVENT,te as JOURNEY_STATUS,re as JOURNEY_WILDCARD,U as createJourneyBindings,Z as createTransitions,ee as tx};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySnapshot.ts"],
|
|
4
|
-
"sourcesContent": ["import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyEvent, JourneyPayloadFor } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n"],
|
|
5
|
-
"mappings": "aAAA,OAAOA,MAAW,QCAlB,OAAOC,MAAW,QAElB,OAAS,wBAAAC,MAA4B,sBAkF1B,cAAAC,MAA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AAqD,CAC1D,GAAM,CAAE,QAAAC,CAAQ,EAAID,EAAgB,oBAAoB,EACxD,OAAOF,EAAM,qBAAqBG,EAAQ,UAAWA,EAAQ,YAAaA,EAAQ,WAAW,CAC/F,ELbK,IAAMC,EAOXC,GACkF,CAClF,IAAMC,EAAiBC,EAAM,cAMnB,IAAI,EAERC,EAAkB,CAACC,EAAW,SAAW,CAC7C,IAAMC,EAAQH,EAAM,WAAWD,CAAc,EAC7C,GAAI,CAACI,EACH,MAAM,IAAI,MAAM,GAAGD,CAAQ,yCAAyC,EAEtE,OAAOC,CACT,EAEMC,EAAqBC,EAAyBJ,CAAe,EAC7DK,EAAoBC,EAAwBN,CAAe,EAC3DO,EAAgBC,EAAoBR,CAAe,EAEnDS,EAAWC,EAAe,CAC9B,eAAAZ,EACA,aAAAD,CACF,CAAC,EAEKc,EAAeC,EAAmB,CACtC,mBAAAT,EACA,gBAAAH,CACF,CAAC,EAED,MAAO,CACL,SAAAS,EACA,aAAAE,EACA,cAAAJ,EACA,kBAAAF,EACA,mBAAAF,CACF,CACF",
|
|
6
|
-
"names": ["React", "React", "createJourneyMachine", "jsx", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "journeyRef", "persistenceRef", "shouldResetInternal", "shouldResetPersistence", "options", "resolvedMachine", "resolvedJourney", "value", "Fragment", "jsx", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "React", "createUseJourneyApi", "useJourneyStore", "machine", "send", "event", "goToNextStep", "terminateJourney", "payload", "completeJourney", "goToPreviousStep", "steps", "goToLastVisitedStep", "updateContext", "updater", "updateStepMetadata", "stepId", "clearStepError", "resetJourney", "createUseJourneyMachine", "useJourneyStore", "React", "createUseJourneySnapshot", "useJourneyStore", "machine", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneyMachine", "createUseJourneyMachine", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer"]
|
|
3
|
+
"sources": ["../src/bindings/index.tsx", "../src/bindings/Provider.tsx", "../src/bindings/StepRenderer.tsx", "../src/bindings/useJourneyApi.ts", "../src/bindings/useJourneyMachine.ts", "../src/bindings/useJourneySnapshot.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import React from \"react\";\n\nimport type {\n JourneyBindings,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\nimport { createProvider } from \"./Provider\";\nimport { createStepRenderer } from \"./StepRenderer\";\nimport { createUseJourneyApi } from \"./useJourneyApi\";\nimport { createUseJourneyMachine } from \"./useJourneyMachine\";\nimport { createUseJourneySnapshot } from \"./useJourneySnapshot\";\n\nexport const createJourneyBindings = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n boundJourney: JourneyReactDefinition<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n): JourneyBindings<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> => {\n const JourneyContext = React.createContext<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>(null);\n\n const useJourneyStore = (hookName = \"hook\") => {\n const value = React.useContext(JourneyContext);\n if (!value) {\n throw new Error(`${hookName} must be used within bindings.Provider.`);\n }\n return value;\n };\n\n const useJourneySnapshot = createUseJourneySnapshot(useJourneyStore);\n const useJourneyMachine = createUseJourneyMachine(useJourneyStore);\n const useJourneyApi = createUseJourneyApi(useJourneyStore);\n\n const Provider = createProvider({\n JourneyContext,\n boundJourney\n });\n\n const StepRenderer = createStepRenderer({\n useJourneySnapshot,\n useJourneyStore\n });\n\n return {\n Provider,\n StepRenderer,\n useJourneyApi,\n useJourneyMachine,\n useJourneySnapshot\n };\n};\n", "import React from \"react\";\n\nimport { createJourneyMachine } from \"@rxova/journey-core\";\nimport type {\n JourneyBindingsProviderProps,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyStoreValue\n} from \"../types\";\n\ntype ProviderFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n JourneyContext: React.Context<JourneyStoreValue<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n > | null>;\n boundJourney: JourneyReactDefinition<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >;\n};\n\nexport const createProvider = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n JourneyContext,\n boundJourney\n}: ProviderFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const Provider = ({\n journey,\n machine,\n persistence,\n resetOnJourneyChange = false,\n children\n }: JourneyBindingsProviderProps<\n TContext,\n TStepId,\n TCustomEvent,\n TEventPayloadMap,\n TStepMeta\n >) => {\n const incomingJourney = journey ?? boundJourney;\n const internalMachineRef = React.useRef<\n | JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>[\"machine\"]\n | null\n >(null);\n const journeyRef = React.useRef(incomingJourney);\n const persistenceRef = React.useRef(persistence);\n\n const shouldResetInternal = resetOnJourneyChange && journeyRef.current !== incomingJourney;\n const shouldResetPersistence = persistenceRef.current !== persistence;\n\n if (\n !machine &&\n (!internalMachineRef.current || shouldResetInternal || shouldResetPersistence)\n ) {\n const options = persistence ? { persistence } : undefined;\n internalMachineRef.current = createJourneyMachine(incomingJourney, options);\n journeyRef.current = incomingJourney;\n persistenceRef.current = persistence;\n }\n\n const resolvedMachine = machine ?? internalMachineRef.current!;\n const resolvedJourney = machine ? incomingJourney : journeyRef.current;\n const value: JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta> = {\n machine: resolvedMachine,\n journey: resolvedJourney\n };\n\n return <JourneyContext.Provider value={value}>{children}</JourneyContext.Provider>;\n };\n\n return Provider;\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\ntype UseJourneySnapshot<\n TContext,\n TStepId extends string,\n TStepMeta = unknown\n> = () => JourneySnapshot<TContext, TStepId, TStepMeta>;\n\ntype StepRendererFactoryProps<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = {\n useJourneySnapshot: UseJourneySnapshot<TContext, TStepId, TStepMeta>;\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n};\n\nexport const createStepRenderer = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>({\n useJourneySnapshot,\n useJourneyStore\n}: StepRendererFactoryProps<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>) => {\n const StepRenderer = ({ fallback = null }: { fallback?: React.ReactNode }) => {\n const snapshot = useJourneySnapshot();\n const { journey } = useJourneyStore(\"StepRenderer\");\n\n const StepComponent = journey.steps[snapshot.currentStepId]?.component;\n\n if (!StepComponent) {\n return <>{fallback}</>;\n }\n\n return <StepComponent />;\n };\n\n return StepRenderer;\n};\n", "import React from \"react\";\n\nimport type { JourneyEvent, JourneyPayloadFor } from \"@rxova/journey-core\";\nimport type { JourneyEventType, JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyApi = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n const machine = useJourneyStore(\"useJourneyApi\").machine;\n\n const send = React.useCallback(\n async (event: JourneyEvent<TStepId, JourneyEventType<TCustomEvent>, TEventPayloadMap>) => {\n await machine.send(event);\n },\n [machine]\n );\n\n const goToNextStep = React.useCallback(async () => {\n await machine.goToNextStep();\n }, [machine]);\n\n const terminateJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"terminateJourney\"\n >\n ) => {\n await machine.terminateJourney(payload);\n },\n [machine]\n );\n\n const completeJourney = React.useCallback(\n async (\n payload?: JourneyPayloadFor<\n JourneyEventType<TCustomEvent>,\n TEventPayloadMap,\n \"completeJourney\"\n >\n ) => {\n await machine.completeJourney(payload);\n },\n [machine]\n );\n\n const goToPreviousStep = React.useCallback(\n async (steps?: number) => {\n await machine.goToPreviousStep(steps);\n },\n [machine]\n );\n\n const goToLastVisitedStep = React.useCallback(async () => {\n await machine.goToLastVisitedStep();\n }, [machine]);\n\n const updateContext = React.useCallback(\n (updater: (context: TContext) => TContext) => {\n machine.updateContext(updater);\n },\n [machine]\n );\n\n const updateStepMetadata = React.useCallback(\n (stepId: TStepId, updater: (metadata: TStepMeta) => TStepMeta) => {\n machine.updateStepMetadata(stepId, updater);\n },\n [machine]\n );\n\n const clearStepError = React.useCallback(\n (stepId?: TStepId) => {\n machine.clearStepError(stepId);\n },\n [machine]\n );\n\n const resetJourney = React.useCallback(() => {\n machine.resetMachine();\n }, [machine]);\n\n return {\n send,\n goToNextStep,\n terminateJourney,\n completeJourney,\n goToPreviousStep,\n goToLastVisitedStep,\n clearStepError,\n updateContext,\n updateStepMetadata,\n updateComponentMetadata: updateStepMetadata,\n resetJourney\n };\n };\n};\n", "import type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneyMachine = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return () => {\n return useJourneyStore(\"useJourneyMachine\").machine;\n };\n};\n", "import React from \"react\";\n\nimport type { JourneySnapshot } from \"@rxova/journey-core\";\nimport type { JourneyReactEventPayloadMap, JourneyStoreValue } from \"../types\";\n\ntype UseJourneyStore<\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n> = (\n hookName?: string\n) => JourneyStoreValue<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>;\n\nexport const createUseJourneySnapshot = <\n TContext,\n TStepId extends string,\n TCustomEvent extends string = never,\n TEventPayloadMap extends JourneyReactEventPayloadMap<TCustomEvent> = Record<never, never>,\n TStepMeta = unknown\n>(\n useJourneyStore: UseJourneyStore<TContext, TStepId, TCustomEvent, TEventPayloadMap, TStepMeta>\n) => {\n return (): JourneySnapshot<TContext, TStepId, TStepMeta> => {\n const { machine } = useJourneyStore(\"useJourneySnapshot\");\n return React.useSyncExternalStore(machine.subscribe, machine.getSnapshot, machine.getSnapshot);\n };\n};\n", "\"use client\";\n\nexport { createJourneyBindings } from \"./bindings\";\nexport {\n createTransitions,\n tx,\n JOURNEY_STATUS,\n JOURNEY_EVENT,\n JOURNEY_ASYNC_PHASE,\n JOURNEY_WILDCARD\n} from \"@rxova/journey-core\";\nexport type { JourneyDefinition } from \"@rxova/journey-core\";\nexport type {\n JourneyApi,\n JourneyBindings,\n JourneyBindingsProviderProps,\n JourneyEventType,\n JourneyReactDefinition,\n JourneyReactEventPayloadMap,\n JourneyReactStep,\n JourneyStoreValue\n} from \"./types\";\n"],
|
|
5
|
+
"mappings": "aAAA,OAAOA,MAAW,QCAlB,OAAOC,MAAW,QAElB,OAAS,wBAAAC,MAA4B,sBAkF1B,cAAAC,MAAA,oBAnDJ,IAAMC,EAAiB,CAM5B,CACA,eAAAC,EACA,aAAAC,CACF,IACmB,CAAC,CAChB,QAAAC,EACA,QAAAC,EACA,YAAAC,EACA,qBAAAC,EAAuB,GACvB,SAAAC,CACF,IAMM,CACJ,IAAMC,EAAkBL,GAAWD,EAC7BO,EAAqBZ,EAAM,OAG/B,IAAI,EACAa,EAAab,EAAM,OAAOW,CAAe,EACzCG,EAAiBd,EAAM,OAAOQ,CAAW,EAEzCO,EAAsBN,GAAwBI,EAAW,UAAYF,EACrEK,EAAyBF,EAAe,UAAYN,EAE1D,GACE,CAACD,IACA,CAACK,EAAmB,SAAWG,GAAuBC,GACvD,CACA,IAAMC,EAAUT,EAAc,CAAE,YAAAA,CAAY,EAAI,OAChDI,E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AAe,CAC9B,eAAAZ,EACA,aAAAD,CACF,CAAC,EAEKc,EAAeC,EAAmB,CACtC,mBAAAT,EACA,gBAAAH,CACF,CAAC,EAED,MAAO,CACL,SAAAS,EACA,aAAAE,EACA,cAAAJ,EACA,kBAAAF,EACA,mBAAAF,CACF,CACF,EMzDA,OACE,qBAAAU,EACA,MAAAC,GACA,kBAAAC,GACA,iBAAAC,GACA,uBAAAC,GACA,oBAAAC,OACK",
|
|
6
|
+
"names": ["React", "React", "createJourneyMachine", "jsx", "createProvider", "JourneyContext", "boundJourney", "journey", "machine", "persistence", "resetOnJourneyChange", "children", "incomingJourney", "internalMachineRef", "journeyRef", "persistenceRef", "shouldResetInternal", "shouldResetPersistence", "options", "resolvedMachine", "resolvedJourney", "value", "Fragment", "jsx", "createStepRenderer", "useJourneySnapshot", "useJourneyStore", "fallback", "snapshot", "journey", "StepComponent", "React", "createUseJourneyApi", "useJourneyStore", "machine", "send", "event", "goToNextStep", "terminateJourney", "payload", "completeJourney", "goToPreviousStep", "steps", "goToLastVisitedStep", "updateContext", "updater", "updateStepMetadata", "stepId", "clearStepError", "resetJourney", "createUseJourneyMachine", "useJourneyStore", "React", "createUseJourneySnapshot", "useJourneyStore", "machine", "createJourneyBindings", "boundJourney", "JourneyContext", "React", "useJourneyStore", "hookName", "value", "useJourneySnapshot", "createUseJourneySnapshot", "useJourneyMachine", "createUseJourneyMachine", "useJourneyApi", "createUseJourneyApi", "Provider", "createProvider", "StepRenderer", "createStepRenderer", "createTransitions", "tx", "JOURNEY_STATUS", "JOURNEY_EVENT", "JOURNEY_ASYNC_PHASE", "JOURNEY_WILDCARD"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxova/journey-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "React bindings for journey.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
],
|
|
48
48
|
"sideEffects": false,
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@rxova/journey-core": "^0.
|
|
50
|
+
"@rxova/journey-core": "^0.6.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=18.2.0"
|