@modular-vue/journeys 1.0.0 → 1.1.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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Suspense as e, computed as t, defineComponent as n, h as r, inject as i, onErrorCaptured as a, onMounted as o, onUnmounted as s, provide as c, ref as l, shallowRef as u, toRaw as d, toValue as f, watch as p, watchEffect as m } from "vue";
2
- import { ModuleErrorBoundary as h, ModuleExitProvider as g, resolveEntryComponent as _, useModuleExit as v } from "@modular-vue/vue";
3
- import { JourneyHydrationError as y, JourneyValidationError as b, JourneyValidationError as x, UnknownJourneyError as S, createJourneyRuntime as ee, createJourneyRuntime as te, createJourneySync as ne, createJourneySync as re, createMemoryJourneySyncPort as ie, createMemoryPersistence as ae, createWebStoragePersistence as oe, defaultStepPath as se, defaultStepPath as ce, defineJourney as le, defineJourneyHandle as ue, defineJourneyPersistence as de, defineTransition as fe, getInternals as pe, invoke as me, isAnnotatedTransition as he, isAnnotatedTransition as C, isTerminalSentinel as ge, journeyStepPath as w, resolveJourneySyncAction as T, selectModule as E, selectModuleOrDefault as D, validateJourneyContracts as O, validateJourneyContracts as k, validateJourneyDefinition as A, validateJourneyDefinition as j, validateJourneyGraph as M } from "@modular-frontend/journeys-engine";
4
- import { SemverParseError as N, compareVersions as P, isDevEnv as F, isJourneySystemAbort as I, satisfies as L } from "@modular-frontend/core";
2
+ import { ModuleErrorBoundary as h, ModuleExitProvider as g, provideBinding as _, resolveEntryComponent as v, useModuleExit as y } from "@modular-vue/vue";
3
+ import { JourneyHydrationError as b, JourneyValidationError as x, JourneyValidationError as S, UnknownJourneyError as ee, createJourneyRuntime as te, createJourneyRuntime as ne, createJourneySync as re, createJourneySync as ie, createMemoryJourneySyncPort as ae, createMemoryPersistence as oe, createWebStoragePersistence as se, defaultStepPath as ce, defaultStepPath as le, defineJourney as ue, defineJourneyHandle as de, defineJourneyPersistence as fe, defineTransition as pe, getInternals as me, invoke as he, isAnnotatedTransition as ge, isAnnotatedTransition as C, isTerminalSentinel as w, journeyStepPath as T, resolveJourneySyncAction as E, selectModule as D, selectModuleOrDefault as O, validateJourneyContracts as k, validateJourneyContracts as A, validateJourneyDefinition as j, validateJourneyDefinition as M, validateJourneyGraph as N } from "@modular-frontend/journeys-engine";
4
+ import { SemverParseError as P, compareVersions as F, isDevEnv as I, isJourneySystemAbort as L, satisfies as _e } from "@modular-frontend/core";
5
5
  //#region src/provider.ts
6
6
  var R = Symbol("modular-vue.journey"), z = n({
7
7
  name: "JourneyProvider",
@@ -29,7 +29,7 @@ function B() {
29
29
  }
30
30
  //#endregion
31
31
  //#region src/instance-hooks.ts
32
- var _e = 64, V = Object.freeze([]);
32
+ var ve = 64, V = Object.freeze([]);
33
33
  function H(e, t) {
34
34
  let n = u(null), r = () => {
35
35
  let n = f(t);
@@ -60,7 +60,7 @@ function U(e, t, n) {
60
60
  let s = /* @__PURE__ */ new Map(), c = !1, l = () => {
61
61
  if (c) return;
62
62
  let t = /* @__PURE__ */ new Set(), n = [], r = i, u = 0;
63
- for (; r && u < _e && !t.has(r);) {
63
+ for (; r && u < ve && !t.has(r);) {
64
64
  t.add(r), n.push(r), s.has(r) || s.set(r, e.subscribe(r, l));
65
65
  let i = e.getInstance(r);
66
66
  r = o && i ? i.activeChildId : null, u += 1;
@@ -81,14 +81,14 @@ function W(e, n, r) {
81
81
  }
82
82
  //#endregion
83
83
  //#region src/use-journey-state.ts
84
- function ve(e) {
84
+ function ye(e) {
85
85
  let n = G(e);
86
86
  return t(() => n.value ? n.value.state : null);
87
87
  }
88
88
  function G(e) {
89
89
  return H(B()?.runtime ?? null, e);
90
90
  }
91
- function ye(e) {
91
+ function be(e) {
92
92
  let n = K(e);
93
93
  return t(() => n.value ? n.value.state : null);
94
94
  }
@@ -147,7 +147,7 @@ var q = n({
147
147
  setup(n) {
148
148
  let a = i(R, null), c = d(n.runtime ?? a?.runtime ?? void 0) ?? null;
149
149
  if (!c) throw Error("[@modular-vue/journeys] <JourneyOutlet> needs a runtime. Either pass `runtime` or mount a <JourneyProvider>.");
150
- let u = pe(c), f = () => d(n.modules ?? u.__moduleMap), m = H(c, () => n.instanceId), h = W(c, () => n.instanceId, () => n.leafOnly), g = H(c, h), v = t(() => h.value === n.instanceId ? m.value : g.value), y = l(0);
150
+ let u = me(c), f = () => d(n.modules ?? u.__moduleMap), m = H(c, () => n.instanceId), h = W(c, () => n.instanceId, () => n.leafOnly), g = H(c, h), _ = t(() => h.value === n.instanceId ? m.value : g.value), y = l(0);
151
151
  s(() => {
152
152
  let e = n.instanceId;
153
153
  queueMicrotask(() => {
@@ -165,7 +165,7 @@ var q = n({
165
165
  })));
166
166
  }, { immediate: !0 }), o(() => {
167
167
  p(() => {
168
- let e = v.value;
168
+ let e = _.value;
169
169
  return [
170
170
  n.preload,
171
171
  e?.status === "active",
@@ -177,19 +177,19 @@ var q = n({
177
177
  if (e === !1 || !t || !n || !r || !i) return;
178
178
  let s = u.__getRegistered(i);
179
179
  if (!s) return;
180
- let c = e === "aggressive" ? "aggressive" : "precise", l = be(s.definition, f(), n, r, c);
180
+ let c = e === "aggressive" ? "aggressive" : "precise", l = xe(s.definition, f(), n, r, c);
181
181
  if (l.length === 0) return;
182
182
  let d = !1, p = () => {
183
183
  if (!d) for (let e of l) try {
184
- _(e).preload().catch(() => {});
184
+ v(e).preload().catch(() => {});
185
185
  } catch {}
186
- }, m = globalThis.requestIdleCallback, h = globalThis.cancelIdleCallback, g, v;
187
- typeof m == "function" ? g = m(p, { timeout: 2e3 }) : v = setTimeout(p, 0), o(() => {
188
- d = !0, g !== void 0 && typeof h == "function" && h(g), v !== void 0 && clearTimeout(v);
186
+ }, m = globalThis.requestIdleCallback, h = globalThis.cancelIdleCallback, g, _;
187
+ typeof m == "function" ? g = m(p, { timeout: 2e3 }) : _ = setTimeout(p, 0), o(() => {
188
+ d = !0, g !== void 0 && typeof h == "function" && h(g), _ !== void 0 && clearTimeout(_);
189
189
  });
190
190
  }, { immediate: !0 });
191
191
  }), () => {
192
- let t = v.value;
192
+ let t = _.value;
193
193
  if (!t) return null;
194
194
  if (t.status === "loading") {
195
195
  let e = n.loadingFallback;
@@ -199,11 +199,11 @@ var q = n({
199
199
  let i = t.step;
200
200
  if (!i) return null;
201
201
  let a = f()[i.moduleId], o = a?.entryPoints?.[i.entry];
202
- if (!a || !o) return r(n.notFoundComponent ?? Se, {
202
+ if (!a || !o) return r(n.notFoundComponent ?? Ce, {
203
203
  moduleId: i.moduleId,
204
204
  entry: i.entry
205
205
  });
206
- if (!xe(o)) return r(n.errorComponent ?? J, {
206
+ if (!Se(o)) return r(n.errorComponent ?? J, {
207
207
  moduleId: i.moduleId,
208
208
  error: /* @__PURE__ */ Error(`[@modular-vue/journeys] Entry "${i.moduleId}.${i.entry}" declares mountKinds=${JSON.stringify(o.mountKinds)} which does not include "journey". Journey steps cannot mount composition-only entries — either widen the entry's mountKinds, or pick a different module-entry in the transition.`)
209
209
  });
@@ -220,8 +220,8 @@ var q = n({
220
220
  return;
221
221
  }
222
222
  r === "retry" && (y.value += 1);
223
- }, { Component: g } = _(o), b = `${s.stepToken}:${y.value}`, x = o.fallback, S = n.loadingFallback;
224
- return r(Ce, {
223
+ }, { Component: g } = v(o), b = `${s.stepToken}:${y.value}`, x = o.fallback, S = n.loadingFallback;
224
+ return r(we, {
225
225
  key: b,
226
226
  moduleId: i.moduleId,
227
227
  onError: h,
@@ -241,7 +241,7 @@ var q = n({
241
241
  };
242
242
  }
243
243
  });
244
- function be(e, t, n, r, i) {
244
+ function xe(e, t, n, r, i) {
245
245
  let a = /* @__PURE__ */ new Set(), o = [], s = e.transitions;
246
246
  if (!s) return o;
247
247
  let c = (e, i) => {
@@ -265,10 +265,10 @@ function be(e, t, n, r, i) {
265
265
  }
266
266
  return o;
267
267
  }
268
- function xe(e) {
268
+ function Se(e) {
269
269
  return Array.isArray(e.mountKinds) ? e.mountKinds.includes("journey") : !0;
270
270
  }
271
- var Se = n({
271
+ var Ce = n({
272
272
  name: "JourneyOutletNotFound",
273
273
  props: {
274
274
  moduleId: {
@@ -320,7 +320,7 @@ var Se = n({
320
320
  } }, n)]);
321
321
  };
322
322
  }
323
- }), Ce = n({
323
+ }), we = n({
324
324
  name: "JourneyStepErrorBoundary",
325
325
  props: {
326
326
  moduleId: {
@@ -344,12 +344,12 @@ var Se = n({
344
344
  });
345
345
  }
346
346
  });
347
- function we(e, t) {
347
+ function Te(e, t) {
348
348
  return U(e, t, !0);
349
349
  }
350
350
  //#endregion
351
351
  //#region src/mount-adapter.ts
352
- function Y(e) {
352
+ function Ee(e) {
353
353
  return {
354
354
  start(t, n) {
355
355
  return e.start(t, n);
@@ -381,25 +381,25 @@ function Y(e) {
381
381
  }
382
382
  //#endregion
383
383
  //#region src/journey-host.ts
384
- var X = /* @__PURE__ */ new WeakMap();
385
- function Z(e) {
386
- let t = X.get(e);
387
- return t || (t = /* @__PURE__ */ new Map(), X.set(e, t)), t;
384
+ var Y = /* @__PURE__ */ new WeakMap();
385
+ function X(e) {
386
+ let t = Y.get(e);
387
+ return t || (t = /* @__PURE__ */ new Map(), Y.set(e, t)), t;
388
388
  }
389
- function Q(e, n, r = {}) {
389
+ function Z(e, n, r = {}) {
390
390
  let i = B(), a = d(r.runtime ?? i?.runtime ?? void 0) ?? null;
391
391
  if (!a) throw Error("[@modular-vue/journeys] useJourneyHost needs a runtime. Either pass `runtime` or mount a <JourneyProvider>.");
392
392
  let c = u(null), l = Symbol("journey-host");
393
393
  o(() => {
394
394
  let t = a.start(e.id, n);
395
395
  c.value = t;
396
- let r = Z(a), i = r.get(t);
396
+ let r = X(a), i = r.get(t);
397
397
  i || (i = /* @__PURE__ */ new Set(), r.set(t, i)), i.add(l);
398
398
  }), s(() => {
399
399
  let e = c.value;
400
400
  if (!e) return;
401
401
  c.value = null;
402
- let t = Z(a);
402
+ let t = X(a);
403
403
  queueMicrotask(() => {
404
404
  let n = t.get(e);
405
405
  n && (n.delete(l), !(n.size > 0) && (t.delete(e), a.end(e, { reason: "unmounted" }, { force: !0 }), a.forget(e)));
@@ -413,10 +413,10 @@ function Q(e, n, r = {}) {
413
413
  stepIndex: t(() => f.value ? f.value.history.length : 0)
414
414
  };
415
415
  }
416
- function Te(e) {
416
+ function De(e) {
417
417
  return e.loadingFallback ?? e["loading-fallback"];
418
418
  }
419
- var Ee = n({
419
+ var Oe = n({
420
420
  name: "JourneyHost",
421
421
  inheritAttrs: !1,
422
422
  props: {
@@ -434,11 +434,11 @@ var Ee = n({
434
434
  }
435
435
  },
436
436
  setup(e, { slots: t, attrs: n }) {
437
- let { instanceId: i, instance: a, runtime: o, stepIndex: s } = Q(e.handle, e.input, { runtime: e.runtime });
437
+ let { instanceId: i, instance: a, runtime: o, stepIndex: s } = Z(e.handle, e.input, { runtime: e.runtime });
438
438
  return () => {
439
439
  let e = i.value, c = a.value;
440
440
  if (!e || !c) {
441
- let e = Te(n);
441
+ let e = De(n);
442
442
  return e ? typeof e == "function" ? e() : e : null;
443
443
  }
444
444
  let l = r(q, {
@@ -457,7 +457,7 @@ var Ee = n({
457
457
  });
458
458
  //#endregion
459
459
  //#region src/use-journey-sync.ts
460
- function De(e, t, n = {}) {
460
+ function ke(e, t, n = {}) {
461
461
  let r = B(), i = d(f(n).runtime ?? r?.runtime ?? void 0) ?? null, a = {
462
462
  port: f(t),
463
463
  options: f(n)
@@ -476,7 +476,7 @@ function De(e, t, n = {}) {
476
476
  };
477
477
  p(() => f(e), (e, t, n) => {
478
478
  if (!i || !e) return;
479
- let r = a.options.stepToPath ?? ce, s = re(i, e, o, {
479
+ let r = a.options.stepToPath ?? le, s = ie(i, e, o, {
480
480
  stepToPath: r,
481
481
  onUnresolved: (e) => a.options.onUnresolved?.(e),
482
482
  onBlocked: (e) => a.options.onBlocked?.(e)
@@ -486,20 +486,20 @@ function De(e, t, n = {}) {
486
486
  }
487
487
  //#endregion
488
488
  //#region src/module-tab.ts
489
- function Oe(e, t) {
489
+ function Ae(e, t) {
490
490
  let n = e.entryPoints, r = n ? Object.keys(n) : [], i = t, a = null;
491
491
  return t === void 0 ? r.length === 1 ? i = r[0] : r.length > 1 && (a = `Module "${e.id}" exposes multiple entries (${r.join(", ")}); pass the \`entry\` prop to disambiguate.`) : n && !Object.prototype.hasOwnProperty.call(n, t) ? a = `Module "${e.id}" has no entry "${t}". Registered: ${r.join(", ") || "(none)"}.` : n || (i = void 0, a = `Module "${e.id}" has no entry points; \`entry="${t}"\` cannot be resolved.`), {
492
492
  resolvedName: i,
493
493
  missingEntryNotice: a
494
494
  };
495
495
  }
496
- function $(e) {
496
+ function Q(e) {
497
497
  return r("div", { style: {
498
498
  padding: "1rem",
499
499
  color: "#c53030"
500
500
  } }, e);
501
501
  }
502
- var ke = n({
502
+ var $ = n({
503
503
  name: "ModuleTab",
504
504
  inheritAttrs: !1,
505
505
  props: {
@@ -521,18 +521,18 @@ var ke = n({
521
521
  }
522
522
  },
523
523
  setup(n, { attrs: i }) {
524
- let a = () => d(n.module), o = t(() => Oe(a(), n.entry)), s = v(() => n.module.id, () => o.value.resolvedName ?? "", {
524
+ let a = () => d(n.module), o = t(() => Ae(a(), n.entry)), s = y(() => n.module.id, () => o.value.resolvedName ?? "", {
525
525
  tabId: () => n.tabId,
526
526
  localOnExit: () => n.onExit
527
527
  });
528
528
  return () => {
529
529
  let t = a(), { resolvedName: c, missingEntryNotice: l } = o.value, u = c ? t.entryPoints?.[c] : void 0, d;
530
- if (l) d = $(l);
530
+ if (l) d = Q(l);
531
531
  else if (u) {
532
532
  let n = "input" in i, a = i.input;
533
- if (a === void 0 && !n) d = $(`Module "${t.id}" entry "${c ?? ""}" was rendered without an \`input\` prop. Pass \`input={undefined}\` explicitly if the entry accepts no input.`);
533
+ if (a === void 0 && !n) d = Q(`Module "${t.id}" entry "${c ?? ""}" was rendered without an \`input\` prop. Pass \`input={undefined}\` explicitly if the entry accepts no input.`);
534
534
  else {
535
- let { Component: t } = _(u), n = u.fallback;
535
+ let { Component: t } = v(u), n = u.fallback;
536
536
  d = r(e, null, {
537
537
  default: () => r(t, {
538
538
  input: a,
@@ -547,14 +547,14 @@ var ke = n({
547
547
  input: a,
548
548
  tabId: n.tabId
549
549
  });
550
- } else d = $(`Module "${t.id}" has no entry points and no component.`);
550
+ } else d = Q(`Module "${t.id}" has no entry points and no component.`);
551
551
  return r(h, { moduleId: t.id }, () => d);
552
552
  };
553
553
  }
554
554
  });
555
555
  //#endregion
556
556
  //#region src/use-wait-for-exit.ts
557
- function Ae(e, t) {
557
+ function je(e, t) {
558
558
  let n = {
559
559
  exit: void 0,
560
560
  subscribe: void 0,
@@ -570,7 +570,7 @@ function Ae(e, t) {
570
570
  try {
571
571
  e();
572
572
  } catch (e) {
573
- F() && console.warn("[useWaitForExit] channel teardown threw:", e);
573
+ I() && console.warn("[useWaitForExit] channel teardown threw:", e);
574
574
  }
575
575
  }, p = () => {
576
576
  let e = u.splice(0);
@@ -620,15 +620,57 @@ function Ae(e, t) {
620
620
  }, { immediate: !0 });
621
621
  }
622
622
  //#endregion
623
+ //#region src/provide-journey-runtime.ts
624
+ function Me(e, t, n) {
625
+ let r = {
626
+ runtime: t,
627
+ onModuleExit: n?.onModuleExit
628
+ };
629
+ e.provide(R, r);
630
+ }
631
+ //#endregion
632
+ //#region src/pinia-persistence.ts
633
+ function Ne(e) {
634
+ let { keyFor: t } = e, n = e.stateKey ?? "journeys", r = e.clone !== !1, i = (e) => r ? JSON.parse(JSON.stringify(e)) : e, a = () => (typeof e.store == "function" ? e.store() : e.store) ?? null, o = (e) => {
635
+ let t = e.$state[n];
636
+ return t && typeof t == "object" ? t : void 0;
637
+ };
638
+ return {
639
+ keyFor: t,
640
+ load: (e) => {
641
+ let t = a();
642
+ if (!t) return null;
643
+ let n = o(t)?.[e];
644
+ return n ? i(n) : null;
645
+ },
646
+ save: (e, t) => {
647
+ let r = a();
648
+ if (!r) return;
649
+ let o = i(t);
650
+ r.$patch((t) => {
651
+ let r = t[n], i = r && typeof r == "object" ? r : t[n] = {};
652
+ i[e] = o;
653
+ });
654
+ },
655
+ remove: (e) => {
656
+ let t = a();
657
+ t && t.$patch((t) => {
658
+ let r = t[n];
659
+ r && delete r[e];
660
+ });
661
+ }
662
+ };
663
+ }
664
+ //#endregion
623
665
  //#region src/plugin.ts
624
- function je(e = {}) {
666
+ function Pe(e = {}) {
625
667
  let t = [];
626
668
  return {
627
669
  name: "journeys",
628
670
  extend() {
629
671
  return { registerJourney(e, n) {
630
- let r = e, i = j(r);
631
- if (i.length > 0) throw new x(i);
672
+ let r = e, i = M(r);
673
+ if (i.length > 0) throw new S(i);
632
674
  t.push({
633
675
  definition: r,
634
676
  options: n
@@ -636,10 +678,10 @@ function je(e = {}) {
636
678
  } };
637
679
  },
638
680
  validate({ modules: e }) {
639
- t.length > 0 && k(t, e);
681
+ t.length > 0 && A(t, e);
640
682
  },
641
683
  onResolve({ moduleDescriptors: n, debug: r }) {
642
- return te(t, {
684
+ return ne(t, {
643
685
  modules: n,
644
686
  debug: e.debug ?? r
645
687
  });
@@ -681,10 +723,16 @@ function je(e = {}) {
681
723
  }, () => n.default?.());
682
724
  }
683
725
  })];
726
+ },
727
+ appProvides({ runtime: t }) {
728
+ return [_(R, {
729
+ runtime: t,
730
+ onModuleExit: e.onModuleExit
731
+ })];
684
732
  }
685
733
  };
686
734
  }
687
735
  //#endregion
688
- export { Ee as JourneyHost, y as JourneyHydrationError, q as JourneyOutlet, z as JourneyProvider, b as JourneyValidationError, ke as ModuleTab, N as SemverParseError, S as UnknownJourneyError, P as compareVersions, Y as createJourneyMountAdapter, ee as createJourneyRuntime, ne as createJourneySync, ie as createMemoryJourneySyncPort, ae as createMemoryPersistence, oe as createWebStoragePersistence, se as defaultStepPath, le as defineJourney, ue as defineJourneyHandle, de as defineJourneyPersistence, fe as defineTransition, me as invoke, he as isAnnotatedTransition, I as isJourneySystemAbort, ge as isTerminalSentinel, R as journeyKey, w as journeyStepPath, je as journeysPlugin, T as resolveJourneySyncAction, L as satisfies, E as selectModule, D as selectModuleOrDefault, K as useActiveLeafJourneyInstance, ye as useActiveLeafJourneyState, U as useCallChain, H as useInstanceSnapshot, we as useJourneyCallStack, B as useJourneyContext, Q as useJourneyHost, G as useJourneyInstance, ve as useJourneyState, De as useJourneySync, W as useLeafId, Ae as useWaitForExit, O as validateJourneyContracts, A as validateJourneyDefinition, M as validateJourneyGraph };
736
+ export { Oe as JourneyHost, b as JourneyHydrationError, q as JourneyOutlet, z as JourneyProvider, x as JourneyValidationError, $ as ModuleTab, P as SemverParseError, ee as UnknownJourneyError, F as compareVersions, Ee as createJourneyMountAdapter, te as createJourneyRuntime, re as createJourneySync, ae as createMemoryJourneySyncPort, oe as createMemoryPersistence, Ne as createPiniaJourneyPersistence, se as createWebStoragePersistence, ce as defaultStepPath, ue as defineJourney, de as defineJourneyHandle, fe as defineJourneyPersistence, pe as defineTransition, he as invoke, ge as isAnnotatedTransition, L as isJourneySystemAbort, w as isTerminalSentinel, R as journeyKey, T as journeyStepPath, Pe as journeysPlugin, Me as provideJourneyRuntime, E as resolveJourneySyncAction, _e as satisfies, D as selectModule, O as selectModuleOrDefault, K as useActiveLeafJourneyInstance, be as useActiveLeafJourneyState, U as useCallChain, H as useInstanceSnapshot, Te as useJourneyCallStack, B as useJourneyContext, Z as useJourneyHost, G as useJourneyInstance, ye as useJourneyState, ke as useJourneySync, W as useLeafId, je as useWaitForExit, k as validateJourneyContracts, j as validateJourneyDefinition, N as validateJourneyGraph };
689
737
 
690
738
  //# sourceMappingURL=index.js.map