@modular-vue/journeys 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Igor Savin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # @modular-vue/journeys
2
+
3
+ Vue 3 journeys for `@modular-vue`. Journeys are typed, serializable workflows
4
+ that compose multiple modules: a journey declares entry/exit transitions between
5
+ modules and owns shared state, while the modules stay journey-unaware.
6
+
7
+ This package is the Vue binding over the framework-neutral
8
+ [`@modular-frontend/journeys-engine`](../journeys-engine). It re-exports the
9
+ engine's authoring surface (`defineJourney`, handles, persistence, transition
10
+ helpers) and adds the Vue-specific pieces: the provider, the composables, the
11
+ outlet, and the registry plugin.
12
+
13
+ The React binding is [`@modular-react/journeys`](../journeys); the two are kept
14
+ at parity, and its README carries the long-form guides (authoring patterns,
15
+ invoke/resume, persistence) that apply to both.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @modular-vue/journeys
21
+ ```
22
+
23
+ ## What's included
24
+
25
+ - **`<JourneyProvider :runtime="…">`** — provides the journey runtime to
26
+ descendant journey hosts and mounts `<ModuleExitProvider>` so module exits
27
+ fired outside a step reach the shell's `onModuleExit`.
28
+ - **`<JourneyOutlet :instance-id="…">`** — renders the current step of a running
29
+ instance: mount-kind checks, loading, error boundary + policy, terminal, idle
30
+ preload, and abandon-on-unmount. Walks the active call chain to the leaf by
31
+ default.
32
+ - **`<JourneyHost :handle="…" :input="…">`** — mounts a journey in one line:
33
+ starts it on mount, renders its step, ends + forgets the instance on unmount.
34
+ Outlet props pass through as attrs, in either spelling (`:on-finished` and
35
+ `:onFinished` both reach the outlet); the default scoped slot receives
36
+ `{ instanceId, instance, stepIndex, outlet }` for chrome.
37
+ - **`useJourneyHost(handle, input, options?)`** — the lifecycle without the
38
+ rendering. Returns `{ instanceId, instance, stepIndex }` as refs, plus the
39
+ plain `runtime` it resolved at setup — the one `instanceId` is valid on.
40
+ - **`useJourneySync(id, port, options?)`** — keeps a journey and the URL in step
41
+ both ways: the journey advances and the URL follows; Back/Forward drive
42
+ `rewindTo` / `goForward`. You supply a small `JourneySyncPort` for vue-router.
43
+ - **`useJourneyState(id)` / `useJourneyInstance(id)`** — subscribe to one
44
+ journey instance; return a reactive ref of its `state` (or full snapshot).
45
+ - **`useActiveLeafJourneyState(rootId)` / `useActiveLeafJourneyInstance(rootId)`**
46
+ — walk the `activeChildId` chain and track the deepest active leaf, so a
47
+ parent host reads the child sub-flow's state without knowing the depth.
48
+ - **`<ModuleTab>`** — renders a single module entry outside a route and forwards
49
+ its exits to the shell. The non-journey counterpart to the outlet.
50
+ - **`useWaitForExit(exit, channels)`** — for step components that wait on an
51
+ async backend event: races a push `subscribe` channel, a `poll` channel, and a
52
+ `timeout` arm with first-wins-latched dispatch.
53
+ - **`journeysPlugin(options?)`** — pass to `createRegistry({ plugins: [...] })`
54
+ to contribute `registerJourney(...)`, validate journey contracts against
55
+ registered modules, produce the `JourneyRuntime` on
56
+ `manifest.extensions.journeys`, and wrap the provider stack in
57
+ `<JourneyProvider>`.
58
+
59
+ ## Usage
60
+
61
+ ```ts
62
+ // app-shared: register the plugin and journeys
63
+ import { createRegistry } from "@modular-vue/runtime";
64
+ import { journeysPlugin, defineJourney } from "@modular-vue/journeys";
65
+
66
+ const registry = createRegistry<AppDeps, AppSlots>({ stores, services, slots });
67
+ const journeys = journeysPlugin();
68
+ registry.use(journeys);
69
+
70
+ registry.registerJourney(checkoutJourney, {
71
+ nav: { label: "Checkout", group: "flows" },
72
+ });
73
+ ```
74
+
75
+ ```vue
76
+ <!-- a host component reading the active leaf's state -->
77
+ <script setup lang="ts">
78
+ import { useActiveLeafJourneyInstance } from "@modular-vue/journeys";
79
+
80
+ const props = defineProps<{ rootId: string }>();
81
+ const leaf = useActiveLeafJourneyInstance(props.rootId);
82
+ </script>
83
+
84
+ <template>
85
+ <span>{{ leaf?.step?.moduleId }} — {{ leaf?.status }}</span>
86
+ </template>
87
+ ```
88
+
89
+ ```vue
90
+ <!-- a journey route: mounted, deep-linked, cleaned up -->
91
+ <script setup lang="ts">
92
+ import { useRoute, useRouter } from "vue-router";
93
+ import { JourneyOutlet, useJourneyHost, useJourneySync } from "@modular-vue/journeys";
94
+ import type { JourneySyncPort } from "@modular-vue/journeys";
95
+ import { checkoutHandle } from "@app/journeys-checkout";
96
+
97
+ const props = defineProps<{ cartId: string }>();
98
+ const router = useRouter();
99
+ const route = useRoute();
100
+
101
+ const { instanceId, stepIndex } = useJourneyHost(checkoutHandle, { cartId: props.cartId });
102
+
103
+ const port: JourneySyncPort = {
104
+ read: () => String(route.params.step ?? ""),
105
+ push: (path) => void router.push({ name: "checkout", params: { step: path } }),
106
+ replace: (path) => void router.replace({ name: "checkout", params: { step: path } }),
107
+ go: (delta) => router.go(delta),
108
+ subscribe: (listener) => router.afterEach(() => listener()),
109
+ };
110
+
111
+ useJourneySync(instanceId, port, { stepToPath: (step) => step.entry });
112
+ </script>
113
+
114
+ <template>
115
+ <p>Step {{ stepIndex + 1 }}</p>
116
+ <JourneyOutlet v-if="instanceId" :instance-id="instanceId" />
117
+ </template>
118
+ ```
119
+
120
+ `useJourneyHost` starts the journey on mount and ends + forgets it on unmount;
121
+ `useJourneySync` owns the URL. Neither knows about the other, and `instanceId`
122
+ is `null` for the first render (the journey is started from `onMounted`, so the
123
+ start is guaranteed to be paired with an unmount that ends it).
124
+
125
+ A URL cannot navigate a journey to an arbitrary step — a step is derived from
126
+ state, so the only positions a location can select are ones the journey has
127
+ already been to. See
128
+ [Deep-linking steps](../journeys/README.md#deep-linking-steps---usejourneysync)
129
+ in the React README for the full model; the reconciler is the same code.
130
+
131
+ ## Reactivity
132
+
133
+ The composables mirror the React hooks but return Vue refs. A single-instance
134
+ composable subscribes at setup and pushes fresh snapshots into a `shallowRef` on
135
+ every runtime change; the leaf-walking composables re-subscribe as the active
136
+ chain grows (a parent invokes a child) or shrinks (a child terminates and the
137
+ parent resumes). Read `.value` at the call site, or bind directly in templates.