@simonbackx/vue-app-navigation 2.4.1 → 2.5.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
@@ -705,6 +705,10 @@ const _ComponentWithProperties = class _ComponentWithProperties {
705
705
  ownsHistoryIndex() {
706
706
  return this.historyIndex !== null && _ComponentWithProperties.historyIndexOwners.get(this.historyIndex) === this;
707
707
  }
708
+ overrideUrl(url, title) {
709
+ this.provide.reactive_navigation_url = url;
710
+ this.setUrl(url, title);
711
+ }
708
712
  setUrl(url, title) {
709
713
  if (this.historyIndex === null) {
710
714
  if (_ComponentWithProperties.debug)
@@ -1817,6 +1821,44 @@ function getCurrentRoutes() {
1817
1821
  function onCheckRoutes(handler) {
1818
1822
  const instance = getCurrentInstance();
1819
1823
  instance._navigationCheckRoutesHandlers = [...instance._navigationCheckRoutes ?? [], handler];
1824
+ addCheckRoutesMountedHandler();
1825
+ }
1826
+ function onNotCheckRoutes(handler) {
1827
+ const instance = getCurrentInstance();
1828
+ instance._navigationNotCheckRoutesHandlers = [...instance._navigationNotCheckRoutesHandlers ?? [], handler];
1829
+ addCheckRoutesMountedHandler();
1830
+ }
1831
+ function addCheckRoutesMountedHandler() {
1832
+ const instance = getCurrentInstance();
1833
+ const component = useCurrentComponent();
1834
+ if (instance._didAddCheckRoutesMountedHandler) {
1835
+ return;
1836
+ }
1837
+ instance._didAddCheckRoutesMountedHandler = true;
1838
+ onMounted(async () => {
1839
+ if (component && component.checkRoutes) {
1840
+ component.checkRoutes = false;
1841
+ if ("_navigationCheckRoutesHandlers" in instance && Array.isArray(instance._navigationCheckRoutesHandlers)) {
1842
+ for (const handler of instance._navigationCheckRoutesHandlers) {
1843
+ if (typeof handler === "function") {
1844
+ await handler();
1845
+ } else {
1846
+ console.error("Invalid checkRoutes handler", handler);
1847
+ }
1848
+ }
1849
+ }
1850
+ } else {
1851
+ if ("_navigationNotCheckRoutesHandlers" in instance && Array.isArray(instance._navigationNotCheckRoutesHandlers)) {
1852
+ for (const handler of instance._navigationNotCheckRoutesHandlers) {
1853
+ if (typeof handler === "function") {
1854
+ await handler();
1855
+ } else {
1856
+ console.error("Invalid not checkRoutes handler", handler);
1857
+ }
1858
+ }
1859
+ }
1860
+ }
1861
+ });
1820
1862
  }
1821
1863
  function defineRoutes(routes) {
1822
1864
  const component = useCurrentComponent();
@@ -1887,42 +1929,32 @@ function defineRoutes(routes) {
1887
1929
  }
1888
1930
  }
1889
1931
  };
1890
- onMounted(async () => {
1891
- if (component && component.checkRoutes) {
1892
- component.checkRoutes = false;
1893
- if ("_navigationCheckRoutesHandlers" in component && Array.isArray(component._navigationCheckRoutesHandlers)) {
1894
- for (const handler of component._navigationCheckRoutesHandlers) {
1895
- if (typeof handler === "function") {
1896
- await handler();
1897
- } else {
1898
- console.error("Invalid checkRoutes handler", handler);
1899
- }
1900
- }
1932
+ onCheckRoutes(async () => {
1933
+ if (Array.isArray(routes)) {
1934
+ if (await handleRoutes(routes)) {
1935
+ setDefaultHandler();
1936
+ return;
1901
1937
  }
1902
- if (Array.isArray(routes)) {
1903
- if (await handleRoutes(routes)) {
1938
+ } else {
1939
+ const extraRoutes = await routes();
1940
+ if (Array.isArray(extraRoutes)) {
1941
+ if (await handleRoutes(extraRoutes)) {
1904
1942
  setDefaultHandler();
1905
1943
  return;
1906
1944
  }
1907
1945
  } else {
1908
- const extraRoutes = await routes();
1909
- if (Array.isArray(extraRoutes)) {
1910
- if (await handleRoutes(extraRoutes)) {
1911
- setDefaultHandler();
1912
- return;
1913
- }
1914
- } else {
1915
- if (extraRoutes) {
1916
- setDefaultHandler();
1917
- return;
1918
- }
1946
+ if (extraRoutes) {
1947
+ setDefaultHandler();
1948
+ return;
1919
1949
  }
1920
1950
  }
1921
- } else {
1922
- await defaultHandler({ allowDetail: false });
1923
1951
  }
1924
1952
  setDefaultHandler();
1925
1953
  });
1954
+ onNotCheckRoutes(async () => {
1955
+ await defaultHandler({ allowDetail: false });
1956
+ setDefaultHandler();
1957
+ });
1926
1958
  }
1927
1959
  const checkRouteCache = {
1928
1960
  lastUrl: null,
@@ -2118,6 +2150,12 @@ function setTitle(title) {
2118
2150
  urlHelpers.setTitle(title);
2119
2151
  });
2120
2152
  }
2153
+ function setUrl(url, title) {
2154
+ const urlHelpers = useUrl();
2155
+ onMounted(() => {
2156
+ urlHelpers.overrideUrl(url, title);
2157
+ });
2158
+ }
2121
2159
  function useUrl() {
2122
2160
  const currentComponent = useCurrentComponent();
2123
2161
  const navigationUrl = inject("reactive_navigation_url", null);
@@ -2156,6 +2194,16 @@ function useUrl() {
2156
2194
  matchCurrent(template, params) {
2157
2195
  const helper = new UrlHelper(void 0, this.getUrl());
2158
2196
  return helper.match(template, params);
2197
+ },
2198
+ overrideUrl(url, title) {
2199
+ if (!currentComponent) {
2200
+ console.error("No current component while setting title", title);
2201
+ return;
2202
+ }
2203
+ if (unref(disableUrl)) {
2204
+ return;
2205
+ }
2206
+ currentComponent == null ? void 0 : currentComponent.overrideUrl(url, title);
2159
2207
  }
2160
2208
  };
2161
2209
  }
@@ -2915,8 +2963,10 @@ export {
2915
2963
  matchQuery,
2916
2964
  normalizePushOptions,
2917
2965
  onCheckRoutes,
2966
+ onNotCheckRoutes,
2918
2967
  setTitle,
2919
2968
  setTitleSuffix,
2969
+ setUrl,
2920
2970
  templateToUrl,
2921
2971
  useCanDismiss,
2922
2972
  useCanPop,
@@ -46,6 +46,7 @@ export declare class ComponentWithProperties {
46
46
  assignHistoryIndex(): void;
47
47
  inheritHistoryIndex(index: number): void;
48
48
  ownsHistoryIndex(): boolean;
49
+ overrideUrl(url: string, title?: string): void;
49
50
  setUrl(url: string, title?: string): void;
50
51
  setTitle(title: string): void;
51
52
  /**
@@ -66,6 +66,7 @@ export declare const ModalMixin: import('vue').DefineComponent<{}, {}, {}, {}, {
66
66
  assignHistoryIndex: () => void;
67
67
  inheritHistoryIndex: (index: number) => void;
68
68
  ownsHistoryIndex: () => boolean;
69
+ overrideUrl: (url: string, title?: string | undefined) => void;
69
70
  setUrl: (url: string, title?: string | undefined) => void;
70
71
  setTitle: (title: string) => void;
71
72
  returnToHistoryIndex: () => boolean;
@@ -136,6 +137,7 @@ export declare const ModalMixin: import('vue').DefineComponent<{}, {}, {}, {}, {
136
137
  assignHistoryIndex: () => void;
137
138
  inheritHistoryIndex: (index: number) => void;
138
139
  ownsHistoryIndex: () => boolean;
140
+ overrideUrl: (url: string, title?: string | undefined) => void;
139
141
  setUrl: (url: string, title?: string | undefined) => void;
140
142
  setTitle: (title: string) => void;
141
143
  returnToHistoryIndex: () => boolean;
@@ -440,6 +442,7 @@ export declare const ModalMixin: import('vue').DefineComponent<{}, {}, {}, {}, {
440
442
  assignHistoryIndex: () => void;
441
443
  inheritHistoryIndex: (index: number) => void;
442
444
  ownsHistoryIndex: () => boolean;
445
+ overrideUrl: (url: string, title?: string | undefined) => void;
443
446
  setUrl: (url: string, title?: string | undefined) => void;
444
447
  setTitle: (title: string) => void;
445
448
  returnToHistoryIndex: () => boolean;
@@ -510,6 +513,7 @@ export declare const ModalMixin: import('vue').DefineComponent<{}, {}, {}, {}, {
510
513
  assignHistoryIndex: () => void;
511
514
  inheritHistoryIndex: (index: number) => void;
512
515
  ownsHistoryIndex: () => boolean;
516
+ overrideUrl: (url: string, title?: string | undefined) => void;
513
517
  setUrl: (url: string, title?: string | undefined) => void;
514
518
  setTitle: (title: string) => void;
515
519
  returnToHistoryIndex: () => boolean;
@@ -65,6 +65,7 @@ declare const ModalStackComponent: import('vue').DefineComponent<{
65
65
  assignHistoryIndex: () => void;
66
66
  inheritHistoryIndex: (index: number) => void;
67
67
  ownsHistoryIndex: () => boolean;
68
+ overrideUrl: (url: string, title?: string | undefined) => void;
68
69
  setUrl: (url: string, title?: string | undefined) => void;
69
70
  setTitle: (title: string) => void;
70
71
  returnToHistoryIndex: () => boolean;
@@ -135,6 +136,7 @@ declare const ModalStackComponent: import('vue').DefineComponent<{
135
136
  assignHistoryIndex: () => void;
136
137
  inheritHistoryIndex: (index: number) => void;
137
138
  ownsHistoryIndex: () => boolean;
139
+ overrideUrl: (url: string, title?: string | undefined) => void;
138
140
  setUrl: (url: string, title?: string | undefined) => void;
139
141
  setTitle: (title: string) => void;
140
142
  returnToHistoryIndex: () => boolean;
@@ -45,6 +45,7 @@ declare const StackComponent: import('vue').DefineComponent<{}, {}, {
45
45
  assignHistoryIndex: () => void;
46
46
  inheritHistoryIndex: (index: number) => void;
47
47
  ownsHistoryIndex: () => boolean;
48
+ overrideUrl: (url: string, title?: string | undefined) => void;
48
49
  setUrl: (url: string, title?: string | undefined) => void;
49
50
  setTitle: (title: string) => void;
50
51
  returnToHistoryIndex: () => boolean;
@@ -68,6 +68,7 @@ export declare function useNavigate(): <Params extends Record<string, unknown>>(
68
68
  export type DefaultRouteHandler = () => Promise<boolean>;
69
69
  export type OnCheckRoutesHandler = () => Promise<void> | void;
70
70
  export declare function onCheckRoutes(handler: OnCheckRoutesHandler): void;
71
+ export declare function onNotCheckRoutes(handler: OnCheckRoutesHandler): void;
71
72
  export declare function defineRoutes(routes: (Route<any, undefined>[]) | (() => Promise<boolean | (Route<any, undefined>[])>)): void;
72
73
  export declare function useCurrentHref(): Ref<string>;
73
74
  export declare function useCheckRoute(): <Params extends Record<string, unknown>>(prop1: string | Route<Params, unknown>, prop2?: RouteNavigationOptions<Params>) => boolean;
@@ -85,6 +86,7 @@ export declare function useFocused(): boolean | Ref<boolean>;
85
86
  export declare function extendUrl(url: string | Ref<string>): void;
86
87
  export declare function setTitleSuffix(title: string): void;
87
88
  export declare function setTitle(title: string): void;
89
+ export declare function setUrl(url: string, title?: string): void;
88
90
  export declare function useUrl(): {
89
91
  getUrl(): string;
90
92
  /**
@@ -94,4 +96,5 @@ export declare function useUrl(): {
94
96
  extendUrl(url: string): string;
95
97
  match<Params>(template: string, params?: UrlParamsConstructors<Params>): UrlMatchResult<Params> | undefined;
96
98
  matchCurrent<Params_1>(template: string, params?: UrlParamsConstructors<Params_1> | undefined): UrlMatchResult<Params_1> | undefined;
99
+ overrideUrl(url: string, title?: string): void;
97
100
  };
@@ -129,6 +129,7 @@ declare const EditWebshopMixin_base: new (...args: any) => import('../src/class-
129
129
  assignHistoryIndex: () => void;
130
130
  inheritHistoryIndex: (index: number) => void;
131
131
  ownsHistoryIndex: () => boolean;
132
+ overrideUrl: (url: string, title?: string | undefined) => void;
132
133
  setUrl: (url: string, title?: string | undefined) => void;
133
134
  setTitle: (title: string) => void;
134
135
  returnToHistoryIndex: () => boolean;
@@ -199,6 +200,7 @@ declare const EditWebshopMixin_base: new (...args: any) => import('../src/class-
199
200
  assignHistoryIndex: () => void;
200
201
  inheritHistoryIndex: (index: number) => void;
201
202
  ownsHistoryIndex: () => boolean;
203
+ overrideUrl: (url: string, title?: string | undefined) => void;
202
204
  setUrl: (url: string, title?: string | undefined) => void;
203
205
  setTitle: (title: string) => void;
204
206
  returnToHistoryIndex: () => boolean;
@@ -503,6 +505,7 @@ declare const EditWebshopMixin_base: new (...args: any) => import('../src/class-
503
505
  assignHistoryIndex: () => void;
504
506
  inheritHistoryIndex: (index: number) => void;
505
507
  ownsHistoryIndex: () => boolean;
508
+ overrideUrl: (url: string, title?: string | undefined) => void;
506
509
  setUrl: (url: string, title?: string | undefined) => void;
507
510
  setTitle: (title: string) => void;
508
511
  returnToHistoryIndex: () => boolean;
@@ -573,6 +576,7 @@ declare const EditWebshopMixin_base: new (...args: any) => import('../src/class-
573
576
  assignHistoryIndex: () => void;
574
577
  inheritHistoryIndex: (index: number) => void;
575
578
  ownsHistoryIndex: () => boolean;
579
+ overrideUrl: (url: string, title?: string | undefined) => void;
576
580
  setUrl: (url: string, title?: string | undefined) => void;
577
581
  setTitle: (title: string) => void;
578
582
  returnToHistoryIndex: () => boolean;
@@ -1533,6 +1537,7 @@ declare const EditWebshopMixin_base: new (...args: any) => import('../src/class-
1533
1537
  extendUrl(url: string): string;
1534
1538
  match<Params>(template: string, params?: import('..').UrlParamsConstructors<Params> | undefined): import('..').UrlMatchResult<Params> | undefined;
1535
1539
  matchCurrent<Params_1>(template: string, params?: import('..').UrlParamsConstructors<Params_1> | undefined): import('..').UrlMatchResult<Params_1> | undefined;
1540
+ overrideUrl(url: string, title?: string | undefined): void;
1536
1541
  };
1537
1542
  $navigate: <Params_2 extends Record<string, unknown>>(prop1: string | import('..').Route<Params_2, unknown>, prop2?: import('..').RouteNavigationOptions<Params_2> | undefined) => Promise<void>;
1538
1543
  }, {}, {
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.4.1",
5
+ "version": "2.5.0",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./dist/index.js",