@simonbackx/vue-app-navigation 2.18.1 → 2.19.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
@@ -773,6 +773,7 @@ const _ComponentWithProperties = class _ComponentWithProperties {
773
773
  }
774
774
  const state = HistoryManager.getCurrentState();
775
775
  this.historyIndex = state.index;
776
+ if (_ComponentWithProperties.debug) console.warn("Assigned index to component", this.component.name ?? this, state.index);
776
777
  _ComponentWithProperties.historyIndexOwners.set(state.index, this);
777
778
  }
778
779
  inheritHistoryIndex(index) {
@@ -832,6 +833,7 @@ const _ComponentWithProperties = class _ComponentWithProperties {
832
833
  if (_ComponentWithProperties.debug) console.warn("Returning to a component that has no history index assigned. Has this component been pushed to a navigation controller properly before returning to it?", this.component.name);
833
834
  return false;
834
835
  }
836
+ if (_ComponentWithProperties.debug) console.warn("Returned to component", this.component.name ?? this);
835
837
  HistoryManager.returnToHistoryIndex(this.historyIndex);
836
838
  return true;
837
839
  }
@@ -1163,7 +1165,7 @@ const ComponentWithPropertiesInstance = defineComponent({
1163
1165
  };
1164
1166
  }
1165
1167
  });
1166
- const _sfc_main$5 = {
1168
+ const _sfc_main$4 = {
1167
1169
  name: "FramedComponent",
1168
1170
  components: {
1169
1171
  ComponentWithPropertiesInstance
@@ -1200,8 +1202,8 @@ function _sfc_render$2(_ctx, _cache, $props, $setup, $data, $options) {
1200
1202
  ])
1201
1203
  ]);
1202
1204
  }
1203
- const FramedComponent = /* @__PURE__ */ _export_sfc(_sfc_main$5, [["render", _sfc_render$2]]);
1204
- const _sfc_main$4 = defineComponent({
1205
+ const FramedComponent = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$2]]);
1206
+ const NavigationController$1 = defineComponent({
1205
1207
  name: "NavigationController",
1206
1208
  components: {
1207
1209
  FramedComponent
@@ -1215,6 +1217,9 @@ const _sfc_main$4 = defineComponent({
1215
1217
  },
1216
1218
  reactive_navigation_can_dismiss: {
1217
1219
  default: false
1220
+ },
1221
+ reactive_navigationController: {
1222
+ default: null
1218
1223
  }
1219
1224
  },
1220
1225
  provide() {
@@ -1273,6 +1278,11 @@ const _sfc_main$4 = defineComponent({
1273
1278
  cachedProvides: /* @__PURE__ */ new Map()
1274
1279
  };
1275
1280
  },
1281
+ computed: {
1282
+ navigationController() {
1283
+ return unref(this.reactive_navigationController);
1284
+ }
1285
+ },
1276
1286
  watch: {
1277
1287
  // whenever question changes, this function will run
1278
1288
  mainComponent(newComponent) {
@@ -1768,7 +1778,14 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
1768
1778
  }, 8, ["onBeforeEnter", "onBeforeLeave", "onEnter", "onLeave", "onAfterLeave", "onAfterEnter", "onEnterCancelled"])
1769
1779
  ])) : createCommentVNode("", true);
1770
1780
  }
1771
- const NavigationController = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["render", _sfc_render$1]]);
1781
+ const NavigationController = /* @__PURE__ */ _export_sfc(NavigationController$1, [["render", _sfc_render$1]]);
1782
+ function typeRoute(route) {
1783
+ return route;
1784
+ }
1785
+ const defineRoute = (route) => {
1786
+ defineRoutes([route]);
1787
+ return route;
1788
+ };
1772
1789
  function usePop() {
1773
1790
  const rawPop = inject("reactive_navigation_pop", null);
1774
1791
  return (options) => {
@@ -1786,12 +1803,18 @@ function useNavigate() {
1786
1803
  const show = useShow();
1787
1804
  const showDetail = useShowDetail();
1788
1805
  const toRoute = async function(route, options) {
1789
- let componentProperties = (options == null ? void 0 : options.properties) ?? (options == null ? void 0 : options.params) ?? {};
1806
+ let componentProperties = (options == null ? void 0 : options.properties) ?? {};
1790
1807
  let params = (options == null ? void 0 : options.params) ?? {};
1791
- if (!(options == null ? void 0 : options.properties) && route.paramsToProps) {
1792
- componentProperties = route.paramsToProps(params, options == null ? void 0 : options.query);
1808
+ if (!(options == null ? void 0 : options.properties)) {
1809
+ if ("paramsToProps" in route) {
1810
+ componentProperties = route.paramsToProps((options == null ? void 0 : options.params) ?? {}, options == null ? void 0 : options.query);
1811
+ } else {
1812
+ if (options == null ? void 0 : options.params) {
1813
+ throw new Error("Using route to a route that only has properties, no parameters. Use properties instead of params in navigate() for this route: " + route.url);
1814
+ }
1815
+ }
1793
1816
  }
1794
- if (!(options == null ? void 0 : options.params) && route.propsToParams && componentProperties) {
1817
+ if (!(options == null ? void 0 : options.params) && "propsToParams" in route) {
1795
1818
  const { params: p } = route.propsToParams(await componentProperties);
1796
1819
  params = p;
1797
1820
  }
@@ -1801,7 +1824,8 @@ function useNavigate() {
1801
1824
  url,
1802
1825
  adjustHistory: (options == null ? void 0 : options.adjustHistory) ?? true,
1803
1826
  animated: (options == null ? void 0 : options.animated) ?? true,
1804
- modalDisplayStyle: route.present && typeof route.present === "string" ? route.present : void 0,
1827
+ modalDisplayStyle: void 0,
1828
+ // modalDisplayStyle: route.present && typeof route.present === 'string' ? route.present : undefined,
1805
1829
  checkRoutes: (options == null ? void 0 : options.checkRoutes) ?? false,
1806
1830
  componentProperties: await componentProperties
1807
1831
  });
@@ -1810,7 +1834,7 @@ function useNavigate() {
1810
1834
  let component;
1811
1835
  const isComponentFunction = typeof route.component === "function" && !(!!route.component.prototype && route.component.prototype.constructor === route.component);
1812
1836
  if (isComponentFunction || componentProperties.then) {
1813
- const method = isComponentFunction ? route.component : () => route.component;
1837
+ const method = isComponentFunction ? route.component : (_) => route.component;
1814
1838
  const originalProperties = componentProperties;
1815
1839
  if (!("PromiseComponent" in window)) {
1816
1840
  throw new Error("Required PromiseComponent window variable to make async components work in routes");
@@ -1818,8 +1842,12 @@ function useNavigate() {
1818
1842
  component = window.PromiseComponent;
1819
1843
  componentProperties = {
1820
1844
  promise: async () => {
1821
- const realComponent = await method();
1822
- return new ComponentWithProperties(realComponent === "self" ? instance == null ? void 0 : instance.type : realComponent, await originalProperties);
1845
+ const properties = await originalProperties;
1846
+ const realComponent = await method(properties);
1847
+ if (realComponent instanceof ComponentWithProperties) {
1848
+ return realComponent;
1849
+ }
1850
+ return new ComponentWithProperties(realComponent === "self" ? instance == null ? void 0 : instance.type : realComponent, properties);
1823
1851
  }
1824
1852
  };
1825
1853
  } else {
@@ -1862,7 +1890,7 @@ function useNavigate() {
1862
1890
  new ComponentWithProperties(component, componentProperties)
1863
1891
  ],
1864
1892
  checkRoutes: (options == null ? void 0 : options.checkRoutes) ?? false
1865
- });
1893
+ }, typeof route.show === "object" && route.show !== null && "getCustomShow" in route.show ? route.show.getCustomShow() : void 0);
1866
1894
  }
1867
1895
  };
1868
1896
  const currentRoutes = getCurrentRoutes();
@@ -1950,13 +1978,18 @@ function defineRoutes(routes) {
1950
1978
  const navigate = useNavigate();
1951
1979
  const currentRoutes = getCurrentRoutes();
1952
1980
  const provideDefaultHandler = inject("reactive_provide_default_handler", null);
1981
+ let hadRoutes = false;
1953
1982
  if (currentRoutes.value.length) {
1954
- console.error("Multiple calls to defineRoutes: routes will get overwritten");
1983
+ hadRoutes = true;
1984
+ routes = [...currentRoutes.value, ...Array.isArray(routes) ? routes : []];
1955
1985
  }
1956
1986
  currentRoutes.value = Array.isArray(routes) ? routes : [];
1987
+ if (hadRoutes) {
1988
+ return;
1989
+ }
1957
1990
  async function handleRoutes(routes2) {
1958
1991
  for (const route of routes2) {
1959
- const result = urlhelpers.match(route.url, route.params);
1992
+ const result = urlhelpers.match(route.url, "params" in route ? route.params : {});
1960
1993
  if (result) {
1961
1994
  try {
1962
1995
  await navigate(route, {
@@ -2013,24 +2046,12 @@ function defineRoutes(routes) {
2013
2046
  }
2014
2047
  };
2015
2048
  onCheckRoutes(async () => {
2016
- if (Array.isArray(routes)) {
2017
- if (await handleRoutes(routes)) {
2049
+ const routes2 = currentRoutes.value;
2050
+ if (Array.isArray(routes2)) {
2051
+ if (await handleRoutes(routes2)) {
2018
2052
  setDefaultHandler();
2019
2053
  return;
2020
2054
  }
2021
- } else {
2022
- const extraRoutes = await routes();
2023
- if (Array.isArray(extraRoutes)) {
2024
- if (await handleRoutes(extraRoutes)) {
2025
- setDefaultHandler();
2026
- return;
2027
- }
2028
- } else {
2029
- if (extraRoutes) {
2030
- setDefaultHandler();
2031
- return;
2032
- }
2033
- }
2034
2055
  }
2035
2056
  setDefaultHandler();
2036
2057
  });
@@ -2039,10 +2060,6 @@ function defineRoutes(routes) {
2039
2060
  setDefaultHandler();
2040
2061
  });
2041
2062
  }
2042
- const checkRouteCache = {
2043
- lastUrl: null,
2044
- results: /* @__PURE__ */ new Map()
2045
- };
2046
2063
  function useCurrentHref() {
2047
2064
  const state = ref(window.location.href);
2048
2065
  const owner = {};
@@ -2059,6 +2076,10 @@ function useCheckRoute() {
2059
2076
  const currentRoutes = getCurrentRoutes();
2060
2077
  const instance = getCurrentInstance();
2061
2078
  const currentPath = useCurrentHref();
2079
+ const checkRouteCache = {
2080
+ lastUrl: null,
2081
+ results: /* @__PURE__ */ new Map()
2082
+ };
2062
2083
  const checkMatchResult = function(route, result, options) {
2063
2084
  if (!result) {
2064
2085
  return false;
@@ -2074,7 +2095,7 @@ function useCheckRoute() {
2074
2095
  return false;
2075
2096
  }
2076
2097
  }
2077
- if (!(options == null ? void 0 : options.params) && route.propsToParams && options.properties) {
2098
+ if (!(options == null ? void 0 : options.params) && "propsToParams" in route && options.properties) {
2078
2099
  const { params } = route.propsToParams(options.properties);
2079
2100
  for (const key in params) {
2080
2101
  if (result.params[key] !== params[key]) {
@@ -2097,7 +2118,7 @@ function useCheckRoute() {
2097
2118
  }
2098
2119
  };
2099
2120
  const checkRoute = function(route, options) {
2100
- const result = urlhelpers.matchCurrent(route.url, route.params);
2121
+ const result = urlhelpers.matchCurrent(route.url, "params" in route ? route.params : {});
2101
2122
  checkRouteCache.results.set(route.url, { result, route });
2102
2123
  if (route.name) {
2103
2124
  checkRouteCache.results.set(route.name, { result, route });
@@ -2162,8 +2183,8 @@ function useShow() {
2162
2183
  const currentComponent = useCurrentComponent();
2163
2184
  const rawShow = inject("reactive_navigation_show", null);
2164
2185
  const urlHelpers = useUrl();
2165
- return (options) => {
2166
- const show = unref(rawShow);
2186
+ return (options, customShow) => {
2187
+ const show = customShow ?? unref(rawShow);
2167
2188
  if (!show) {
2168
2189
  console.warn("Failed to perform show");
2169
2190
  return Promise.resolve();
@@ -2773,6 +2794,13 @@ const _sfc_main = defineComponent({
2773
2794
  }
2774
2795
  };
2775
2796
  },
2797
+ detailProvide() {
2798
+ return {
2799
+ // Detail can not alter the navigation of the parent of split view controller.
2800
+ reactive_navigation_can_pop: false,
2801
+ reactive_navigation_can_dismiss: false
2802
+ };
2803
+ },
2776
2804
  lastIsDetail() {
2777
2805
  var _a, _b;
2778
2806
  return this.detailKey != null && ((_b = (_a = this.navigationController) == null ? void 0 : _a.mainComponent) == null ? void 0 : _b.key) == this.detailKey;
@@ -2811,6 +2839,7 @@ const _sfc_main = defineComponent({
2811
2839
  return this.navigationController.returnToHistoryIndex();
2812
2840
  },
2813
2841
  onResize() {
2842
+ if (this.$el.isConnected === false) return false;
2814
2843
  if (this.shouldCollapse()) {
2815
2844
  if (this.detail) {
2816
2845
  this.collapse().catch(console.error);
@@ -3017,8 +3046,9 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
3017
3046
  _ctx.detail ? (openBlock(), createElementBlock("div", _hoisted_3, [
3018
3047
  (openBlock(), createBlock(_component_FramedComponent, {
3019
3048
  key: _ctx.detail.key,
3020
- root: _ctx.detail
3021
- }, null, 8, ["root"]))
3049
+ root: _ctx.detail,
3050
+ "custom-provide": _ctx.detailProvide
3051
+ }, null, 8, ["root", "custom-provide"]))
3022
3052
  ])) : createCommentVNode("", true)
3023
3053
  ], 8, _hoisted_1);
3024
3054
  }
@@ -3036,6 +3066,7 @@ export {
3036
3066
  SplitViewController,
3037
3067
  _sfc_main$3 as StackComponent,
3038
3068
  UrlHelper,
3069
+ defineRoute,
3039
3070
  defineRoutes,
3040
3071
  extendUrl,
3041
3072
  forAllRoots,
@@ -3050,6 +3081,7 @@ export {
3050
3081
  setTitleSuffix,
3051
3082
  setUrl,
3052
3083
  templateToUrl,
3084
+ typeRoute,
3053
3085
  useCanDismiss,
3054
3086
  useCanPop,
3055
3087
  useCheckRoute,
@@ -3,7 +3,7 @@ import { ComponentWithProperties, ComponentWithPropertiesType } from './Componen
3
3
  import { PopOptions } from './PopOptions';
4
4
  import { PushOptions } from './PushOptions';
5
5
 
6
- declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
6
+ declare const NavigationController: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
7
7
  root: {
8
8
  default: null;
9
9
  type: PropType<ComponentWithProperties | null>;
@@ -29,7 +29,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
29
29
  asyncQueue: (() => Promise<void>)[];
30
30
  asyncQueueRunning: boolean;
31
31
  cachedProvides: Map<number, any>;
32
- }, {}, {
32
+ }, {
33
+ navigationController(): InstanceType<typeof NavigationController> | null;
34
+ }, {
33
35
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
34
36
  provideForComponent(key: number): any;
35
37
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -135,7 +137,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
135
137
  asyncQueue: (() => Promise<void>)[];
136
138
  asyncQueueRunning: boolean;
137
139
  cachedProvides: Map<number, any>;
138
- }, {}, {
140
+ }, {
141
+ navigationController(): InstanceType<typeof NavigationController> | null;
142
+ }, {
139
143
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
140
144
  provideForComponent(key: number): any;
141
145
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -172,6 +176,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
172
176
  reactive_navigation_can_dismiss: {
173
177
  default: boolean;
174
178
  };
179
+ reactive_navigationController: {
180
+ default: null;
181
+ };
175
182
  }, {}, {
176
183
  FramedComponent: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
177
184
  root: {
@@ -235,7 +242,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
235
242
  asyncQueue: (() => Promise<void>)[];
236
243
  asyncQueueRunning: boolean;
237
244
  cachedProvides: Map<number, any>;
238
- }, {}, {
245
+ }, {
246
+ navigationController(): InstanceType<typeof NavigationController> | null;
247
+ }, {
239
248
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
240
249
  provideForComponent(key: number): any;
241
250
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -266,4 +275,4 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
266
275
  reactive_navigation_show: (options: PushOptions) => Promise<void>;
267
276
  reactive_navigation_pop: import('vue').ComputedRef<unknown>;
268
277
  }, true, {}, any>;
269
- export default _default;
278
+ export default NavigationController;
@@ -23,12 +23,16 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
23
23
  reactive_navigation_disable_url: import('vue').ComputedRef<boolean>;
24
24
  reactive_provide_default_handler: (defaultHandler: DefaultRouteHandler) => void;
25
25
  };
26
+ detailProvide(): {
27
+ reactive_navigation_can_pop: boolean;
28
+ reactive_navigation_can_dismiss: boolean;
29
+ };
26
30
  lastIsDetail(): boolean;
27
31
  navigationController(): InstanceType<typeof NavigationController>;
28
32
  masterElement(): HTMLElement;
29
33
  }, {
30
34
  returnToHistoryIndex(): boolean;
31
- onResize(): void;
35
+ onResize(): false | undefined;
32
36
  getScrollElement(element?: HTMLElement | null): HTMLElement;
33
37
  shouldNavigateAway(): Promise<boolean>;
34
38
  showDetail(options: PushOptions): Promise<boolean>;
@@ -74,7 +78,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
74
78
  asyncQueue: (() => Promise<void>)[];
75
79
  asyncQueueRunning: boolean;
76
80
  cachedProvides: Map<number, any>;
77
- }, {}, {
81
+ }, {
82
+ navigationController(): InstanceType<typeof NavigationController> | null;
83
+ }, {
78
84
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
79
85
  provideForComponent(key: number): any;
80
86
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -180,7 +186,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
180
186
  asyncQueue: (() => Promise<void>)[];
181
187
  asyncQueueRunning: boolean;
182
188
  cachedProvides: Map<number, any>;
183
- }, {}, {
189
+ }, {
190
+ navigationController(): InstanceType<typeof NavigationController> | null;
191
+ }, {
184
192
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
185
193
  provideForComponent(key: number): any;
186
194
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -217,6 +225,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
217
225
  reactive_navigation_can_dismiss: {
218
226
  default: boolean;
219
227
  };
228
+ reactive_navigationController: {
229
+ default: null;
230
+ };
220
231
  }, {}, {
221
232
  FramedComponent: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
222
233
  root: {
@@ -280,7 +291,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
280
291
  asyncQueue: (() => Promise<void>)[];
281
292
  asyncQueueRunning: boolean;
282
293
  cachedProvides: Map<number, any>;
283
- }, {}, {
294
+ }, {
295
+ navigationController(): InstanceType<typeof NavigationController> | null;
296
+ }, {
284
297
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
285
298
  provideForComponent(key: number): any;
286
299
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -360,12 +373,16 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
360
373
  reactive_navigation_disable_url: import('vue').ComputedRef<boolean>;
361
374
  reactive_provide_default_handler: (defaultHandler: DefaultRouteHandler) => void;
362
375
  };
376
+ detailProvide(): {
377
+ reactive_navigation_can_pop: boolean;
378
+ reactive_navigation_can_dismiss: boolean;
379
+ };
363
380
  lastIsDetail(): boolean;
364
381
  navigationController(): InstanceType<typeof NavigationController>;
365
382
  masterElement(): HTMLElement;
366
383
  }, {
367
384
  returnToHistoryIndex(): boolean;
368
- onResize(): void;
385
+ onResize(): false | undefined;
369
386
  getScrollElement(element?: HTMLElement | null): HTMLElement;
370
387
  shouldNavigateAway(): Promise<boolean>;
371
388
  showDetail(options: PushOptions): Promise<boolean>;
@@ -400,7 +417,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
400
417
  asyncQueue: (() => Promise<void>)[];
401
418
  asyncQueueRunning: boolean;
402
419
  cachedProvides: Map<number, any>;
403
- }, {}, {
420
+ }, {
421
+ navigationController(): InstanceType<typeof NavigationController> | null;
422
+ }, {
404
423
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
405
424
  provideForComponent(key: number): any;
406
425
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -506,7 +525,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
506
525
  asyncQueue: (() => Promise<void>)[];
507
526
  asyncQueueRunning: boolean;
508
527
  cachedProvides: Map<number, any>;
509
- }, {}, {
528
+ }, {
529
+ navigationController(): InstanceType<typeof NavigationController> | null;
530
+ }, {
510
531
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
511
532
  provideForComponent(key: number): any;
512
533
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -543,6 +564,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
543
564
  reactive_navigation_can_dismiss: {
544
565
  default: boolean;
545
566
  };
567
+ reactive_navigationController: {
568
+ default: null;
569
+ };
546
570
  }, {}, {
547
571
  FramedComponent: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
548
572
  root: {
@@ -606,7 +630,9 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
606
630
  asyncQueue: (() => Promise<void>)[];
607
631
  asyncQueueRunning: boolean;
608
632
  cachedProvides: Map<number, any>;
609
- }, {}, {
633
+ }, {
634
+ navigationController(): InstanceType<typeof NavigationController> | null;
635
+ }, {
610
636
  cacheComponentProvides(newComponent: ComponentWithPropertiesType): void;
611
637
  provideForComponent(key: number): any;
612
638
  runQueue<T>(run: () => Promise<T>): Promise<T>;
@@ -692,12 +718,16 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
692
718
  reactive_navigation_disable_url: import('vue').ComputedRef<boolean>;
693
719
  reactive_provide_default_handler: (defaultHandler: DefaultRouteHandler) => void;
694
720
  };
721
+ detailProvide(): {
722
+ reactive_navigation_can_pop: boolean;
723
+ reactive_navigation_can_dismiss: boolean;
724
+ };
695
725
  lastIsDetail(): boolean;
696
726
  navigationController(): InstanceType<typeof NavigationController>;
697
727
  masterElement(): HTMLElement;
698
728
  }, {
699
729
  returnToHistoryIndex(): boolean;
700
- onResize(): void;
730
+ onResize(): false | undefined;
701
731
  getScrollElement(element?: HTMLElement | null): HTMLElement;
702
732
  shouldNavigateAway(): Promise<boolean>;
703
733
  showDetail(options: PushOptions): Promise<boolean>;
@@ -66,6 +66,10 @@ export declare class UrlHelper {
66
66
  static trim(url: string): string;
67
67
  match<Params>(template: string, params?: UrlParamsConstructors<Params>): UrlMatchResult<Params> | undefined;
68
68
  }
69
+ type ConstructorToType<C> = C extends NumberConstructor ? number : C extends StringConstructor ? string : C extends BooleanConstructor ? boolean : never;
70
+ export type ParamsFromConstructors<C> = {
71
+ [K in keyof C]: ConstructorToType<C[K]>;
72
+ };
69
73
  export type UrlParamsConstructors<Params> = {
70
74
  [Key in keyof Params]: Params[Key] extends number ? NumberConstructor : StringConstructor;
71
75
  };
@@ -80,3 +84,4 @@ export type UrlMatchResult<Params> = {
80
84
  export declare function matchPath<Params>(path: string | string[], query: URLSearchParams, template: string, params?: UrlParamsConstructors<Params>): UrlMatchResult<Params> | undefined;
81
85
  export declare function matchQuery(): void;
82
86
  export declare function templateToUrl<Params>(template: string, params: Params): string;
87
+ export {};
@@ -3,70 +3,67 @@ import { ComponentWithProperties, ModalDisplayStyle } from '../ComponentWithProp
3
3
  import { HistoryUrl } from '../HistoryManager';
4
4
  import { PopOptions } from '../PopOptions';
5
5
  import { PushOptions } from '../PushOptions';
6
- import { UrlMatchResult, UrlParamsConstructors } from './UrlHelper';
6
+ import { ParamsFromConstructors, UrlMatchResult, UrlParamsConstructors } from './UrlHelper';
7
7
 
8
- export type Route<Params> = {
9
- name?: string;
10
- url: string;
11
- params?: UrlParamsConstructors<Params>;
12
- query?: UrlParamsConstructors<unknown>;
13
- component: Component | (() => Promise<Component>) | 'self';
8
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
9
+ export declare function typeRoute<const C extends Record<string, StringConstructor | NumberConstructor>, Props = unknown>(route: DistributiveOmit<RouteWithParams<Props, ParamsFromConstructors<C>>, 'params'> & {
10
+ params: C;
11
+ }): RouteWithParams<Props, ParamsFromConstructors<C>>;
12
+ export declare function typeRoute<Props = unknown>(route: RouteWithoutParams<Props>): RouteWithoutParams<Props>;
13
+ export declare const defineRoute: typeof typeRoute;
14
+ type NotFunction<T> = T extends Function ? never : T;
15
+ type RouteComponent<Props> = {
14
16
  present?: ModalDisplayStyle | true;
15
- show?: true | 'detail';
16
- isDefault?: RouteNavigationOptions<Params>;
17
- paramsToProps?: (params: Params, query?: URLSearchParams) => Promise<Record<string, unknown>> | Record<string, unknown>;
18
- /**
19
- * Used for building back the URL if only properties are provided
20
- */
21
- propsToParams?: (props: Record<string, unknown>) => {
22
- params: Params;
23
- query?: URLSearchParams;
17
+ show?: true | 'detail' | {
18
+ getCustomShow: () => (options: PushOptions) => Promise<void>;
24
19
  };
20
+ component: NotFunction<Component> | 'self' | ((props: Record<string, unknown>) => Promise<Component | ComponentWithProperties> | Component | ComponentWithProperties);
25
21
  } | {
26
- name?: string;
27
- url: string;
28
- params?: UrlParamsConstructors<Params>;
29
- query?: UrlParamsConstructors<unknown>;
30
- present?: ModalDisplayStyle | true;
31
22
  handler: (options: {
32
23
  url: string;
33
24
  adjustHistory: boolean;
34
25
  animated: boolean;
35
26
  modalDisplayStyle: ModalDisplayStyle | undefined;
36
27
  checkRoutes: boolean;
37
- componentProperties: Record<string, unknown>;
28
+ componentProperties: Props;
38
29
  }) => Promise<void>;
39
- isDefault?: RouteNavigationOptions<Params>;
40
- paramsToProps?: (params: Params, query?: URLSearchParams) => Promise<Record<string, unknown>> | Record<string, unknown>;
41
- /**
42
- * Used for building back the URL if only properties are provided
43
- */
44
- propsToParams?: (props: Record<string, unknown>) => {
30
+ };
31
+ export type RouteWithParams<Props, Params> = {
32
+ name?: string;
33
+ url: string;
34
+ params: UrlParamsConstructors<Params>;
35
+ isDefault?: RouteNavigationOptions<Props, Params> & ({
36
+ params: Params;
37
+ } | {
38
+ properties: Props;
39
+ });
40
+ paramsToProps: (params: Params, query?: URLSearchParams) => Promise<Props> | Props;
41
+ propsToParams: (props: Props) => {
45
42
  params: Params;
46
43
  query?: URLSearchParams;
47
44
  };
48
- };
49
- export type RouteNavigationOptions<Params> = {
45
+ } & RouteComponent<Props>;
46
+ export type RouteWithoutParams<Props> = {
47
+ name?: string;
48
+ url: string;
49
+ isDefault?: RouteNavigationOptions<Props>;
50
+ defaultProperties?: (query?: URLSearchParams) => Promise<Props> | Props;
51
+ } & RouteComponent<Props>;
52
+ export type Route<Props = Record<string, unknown>, Params = Record<string, unknown>> = RouteWithParams<Props, Params> | RouteWithoutParams<Props>;
53
+ export type RouteNavigationOptions<Props = Record<string, unknown>, Params = Record<string, never>> = {
50
54
  params?: Params;
51
- properties?: Record<string, unknown>;
55
+ properties?: Props;
52
56
  query?: URLSearchParams;
53
57
  animated?: boolean;
54
58
  adjustHistory?: boolean;
55
59
  checkRoutes?: boolean;
56
60
  };
57
- export type RouteIdentification<Params> = {
58
- name: string;
59
- } | {
60
- url: string;
61
- } | {
62
- route: Route<Params>;
63
- };
64
61
  export type NavigationOptions<T> = {
65
62
  title: string | ((this: T) => string);
66
63
  routes?: Route<any>[];
67
64
  };
68
65
  export declare function usePop(): (options?: PopOptions) => Promise<void> | undefined;
69
- export declare function useNavigate(): <Params extends Record<string, unknown>>(prop1: string | Route<Params>, prop2?: RouteNavigationOptions<Params>) => Promise<void>;
66
+ export declare function useNavigate(): <Props extends Record<string, unknown>, Params extends Record<string, unknown>>(prop1: string | Route<Props, Params>, prop2?: RouteNavigationOptions<Props, Params>) => Promise<void>;
70
67
  export type DefaultRouteHandler = () => Promise<boolean>;
71
68
  /**
72
69
  * Return true when the route has been handled and other route checks should not be executed.
@@ -74,12 +71,12 @@ export type DefaultRouteHandler = () => Promise<boolean>;
74
71
  export type OnCheckRoutesHandler = () => Promise<void | boolean> | void | boolean;
75
72
  export declare function onCheckRoutes(handler: OnCheckRoutesHandler): void;
76
73
  export declare function onNotCheckRoutes(handler: OnCheckRoutesHandler): void;
77
- export declare function defineRoutes(routes: (Route<any>[]) | (() => Promise<boolean | (Route<any>[])>)): void;
74
+ export declare function defineRoutes(routes: Route<any, any>[]): void;
78
75
  export declare function useCurrentHref(): Ref<string, string>;
79
76
  export declare function useCheckRoute(): <Params extends Record<string, unknown>>(prop1: string | Route<Params>, prop2?: RouteNavigationOptions<Params>) => boolean;
80
77
  export declare function normalizePushOptions(o: PushOptions | ComponentWithProperties, currentComponent: ComponentWithProperties | null, urlHelpers: ReturnType<typeof useUrl>): PushOptions;
81
78
  export declare function useManualPresent(): (present: (options: PushOptions) => Promise<void> | void, options: PushOptions | ComponentWithProperties) => void | Promise<void>;
82
- export declare function useShow(): (options: PushOptions | ComponentWithProperties) => Promise<void>;
79
+ export declare function useShow(): (options: PushOptions | ComponentWithProperties, customShow?: (options: PushOptions) => Promise<void>) => Promise<void>;
83
80
  export declare function useShowDetail(): (options: PushOptions | ComponentWithProperties) => Promise<void>;
84
81
  export declare function usePresent(): (options: PushOptions | ComponentWithProperties) => Promise<void>;
85
82
  export declare function useDismiss(): (options?: PopOptions) => Promise<void>;
@@ -106,3 +103,4 @@ export declare function useUrl(): {
106
103
  matchCurrent<Params>(template: string, params?: UrlParamsConstructors<Params>): UrlMatchResult<Params> | undefined;
107
104
  overrideUrl(url: HistoryUrl, title?: string): void;
108
105
  };
106
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@simonbackx/vue-app-navigation",
3
3
  "main": "./dist/index.js",
4
4
  "types": "./dist/index.d.ts",
5
- "version": "2.18.1",
5
+ "version": "2.19.0",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./dist/index.js",