@aerogel/plugin-routing 0.0.0-next.0a86dbbb7bd76119cdde6fba32bca23589073d53

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.
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("virtual:aerogel"),t=require("@aerogel/core"),r=require("vue-router"),n=require("@babel/runtime/helpers/defineProperty"),o=require("vue"),s=require("@noeldemartin/utils");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("core-js/modules/esnext.async-iterator.map.js"),require("core-js/modules/esnext.iterator.map.js");var u=a(e),i=a(n),c=t.defineServiceState({name:"router",initialState:{flashRoute:null},persist:["flashRoute"]});class l extends c{constructor(){super(),i.default(this,"currentRoute",void 0),i.default(this,"routesParams",void 0),i.default(this,"router",void 0),i.default(this,"bindings",void 0),this.router=o.shallowRef(null),this.bindings={},this.routesParams=o.shallowRef({}),this.currentRoute=o.computed((()=>{if(!this.router.value)return null;const e=o.unref(this.router.value.currentRoute);return{...e,params:this.routesParams.value?.[e.path],rawParams:e.params}}))}use(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.router.value=e,this.bindings=t.bindings??{},e.beforeEach(s.once((()=>this.handleStatic404Redirect()))),e.beforeEach((e=>this.beforeNavigation(e)))}async boot(){t.Events.on("before-login",(()=>this.flashRoute=s.objectOnly(this.currentRoute.value,["path","query","hash"]))),t.Events.on("login",(async()=>{this.flashRoute&&(await this.replace(this.flashRoute),this.flashRoute=null)}))}__get(e){return this.router.value?super.__get(e)??Reflect.get(this.router.value,e):super.__get(e)}async beforeNavigation(e){const t={...e.params};for(const[r,n]of Object.entries(e.params))t[r]=await this.resolveBinding(r,n,t);this.routesParams.value={...this.routesParams.value,[e.path]:t}}handleStatic404Redirect(){const e=s.Storage.pull("static-404-redirect");e&&this.replace(e)}async resolveBinding(e,r,n){const o=this.bindings[e];return Array.isArray(r)||!o?r:(await t.App.ready,o(r,n))}}var f=s.facade(new l);function h(e){return o.defineComponent({setup:()=>function(e){const t=r.useRoute(),n=o.computed((()=>f.routesParams?.value[t.path]));return()=>o.h(e,n.value)}(e)})}function p(e){return async function(){await t.App.ready;for(var r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];return e.call(this,...n)}}function d(e){return function(e){if(e.component)if("function"!=typeof e.component)e.component=h(e.component);else{const t=e.component;e.component=async()=>{const{default:e}=await t();return h(e)}}}(e),function(e){e.beforeEnter&&(Array.isArray(e.beforeEnter)?e.beforeEnter=e.beforeEnter.map(p):e.beforeEnter=p(e.beforeEnter))}(e),e}const v={$router:f};exports.Router=f,exports.RouterService=l,exports.default=function(e){return{async install(n){const o=r.createRouter({routes:e.routes,history:r.createWebHistory(e.basePath??u.default.basePath)});f.use(o,e),n.use(o),await t.bootServices(n,v)}}},exports.defineRoute=d,exports.defineRouteBindings=function(e){return e},exports.defineRoutes=function(e){return e.map(d)};
2
+ //# sourceMappingURL=aerogel-plugin-routing.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aerogel-plugin-routing.cjs.js","sources":["../src/services/Router.state.ts","../src/services/Router.ts","../src/utils/routes.ts","../src/main.ts"],"sourcesContent":["import { defineServiceState } from '@aerogel/core';\nimport type { RouteLocationRaw } from 'vue-router';\n\nexport default defineServiceState({\n name: 'router',\n initialState: {\n flashRoute: null as RouteLocationRaw | null,\n },\n persist: ['flashRoute'],\n});\n","import { computed, shallowRef, unref } from 'vue';\nimport { App, Events } from '@aerogel/core';\nimport { Storage, facade, objectOnly, once } from '@noeldemartin/utils';\nimport type { ComputedRef, Ref } from 'vue';\nimport type {\n RouteLocationNormalized,\n RouteLocationNormalizedLoaded,\n RouteLocationRaw,\n RouteParamValue,\n RouteParams,\n Router,\n} from 'vue-router';\n\nimport Service from './Router.state';\n\nexport type LoadedRoute = Omit<RouteLocationNormalizedLoaded, 'params'> & {\n rawParams: RouteParams;\n params?: Record<string, unknown>;\n};\nexport type RouteBinding = (slug: string, params: Record<string, unknown>) => unknown | Promise<unknown>;\nexport type RouteBindings = Record<string, RouteBinding>;\n\nexport class RouterService extends Service {\n\n public readonly currentRoute: ComputedRef<LoadedRoute | null>;\n public readonly routesParams: Ref<Record<string, Record<string, unknown>>>;\n protected router: Ref<Router | null>;\n protected bindings: RouteBindings;\n\n constructor() {\n super();\n\n this.router = shallowRef(null);\n this.bindings = {};\n this.routesParams = shallowRef({});\n this.currentRoute = computed(() => {\n if (!this.router.value) {\n return null;\n }\n\n const route = unref(this.router.value.currentRoute);\n\n return {\n ...route,\n params: this.routesParams.value?.[route.path],\n rawParams: route.params,\n };\n });\n }\n\n public use(router: Router, options: { bindings?: RouteBindings } = {}): void {\n this.router.value = router;\n this.bindings = options.bindings ?? {};\n\n router.beforeEach(once(() => this.handleStatic404Redirect()));\n router.beforeEach((to) => this.beforeNavigation(to));\n }\n\n protected async boot(): Promise<void> {\n Events.on(\n 'before-login',\n () =>\n (this.flashRoute = objectOnly(this.currentRoute.value as unknown as Record<string, unknown>, [\n 'path',\n 'query',\n 'hash',\n ])),\n );\n Events.on('login', async () => {\n if (!this.flashRoute) {\n return;\n }\n\n await this.replace(this.flashRoute);\n\n this.flashRoute = null;\n });\n }\n\n protected __get(property: string): unknown {\n return this.router.value\n ? super.__get(property) ?? Reflect.get(this.router.value, property)\n : super.__get(property);\n }\n\n protected async beforeNavigation(route: RouteLocationNormalized): Promise<void> {\n const resolvedParams: Record<string, unknown> = { ...route.params };\n\n for (const [paramName, paramValue] of Object.entries(route.params)) {\n resolvedParams[paramName] = await this.resolveBinding(paramName, paramValue, resolvedParams);\n }\n\n this.routesParams.value = {\n ...this.routesParams.value,\n [route.path]: resolvedParams,\n };\n }\n\n protected handleStatic404Redirect(): void {\n const route = Storage.pull<RouteLocationRaw>('static-404-redirect');\n\n route && this.replace(route);\n }\n\n protected async resolveBinding(\n name: string,\n value: RouteParamValue | RouteParamValue[],\n params: Record<string, unknown>,\n ): Promise<unknown> {\n const binding = this.bindings[name];\n\n if (Array.isArray(value) || !binding) {\n return value;\n }\n\n await App.ready;\n\n return binding(value, params);\n }\n\n}\n\nexport interface RouterService extends Omit<Router, 'currentRoute'> {}\n\nexport default facade(new RouterService());\n","import { App } from '@aerogel/core';\nimport { computed, defineComponent, h } from 'vue';\nimport { useRoute } from 'vue-router';\nimport type { Component, ConcreteComponent } from 'vue';\nimport type { NavigationGuardWithThis, RouteRecordRaw } from 'vue-router';\n\nimport Router from '../services/Router';\nimport type { RouteBindings } from '../services/Router';\n\nexport type AerogelRoute = RouteRecordRaw;\n\nfunction setupPageComponent(pageComponent: ConcreteComponent) {\n const route = useRoute();\n const pageParams = computed(() => Router.routesParams?.value[route.path]);\n\n return () => h(pageComponent, pageParams.value);\n}\n\nfunction defineRouteComponent(pageComponent: ConcreteComponent): Component {\n return defineComponent({\n setup: () => setupPageComponent(pageComponent),\n });\n}\n\nfunction enhanceRouteComponent(route: AerogelRoute): void {\n if (!route.component) {\n return;\n }\n\n if (typeof route.component === 'function') {\n const lazyComponent = route.component as () => Promise<{ default: ConcreteComponent }>;\n\n route.component = async () => {\n const { default: component } = await lazyComponent();\n\n return defineRouteComponent(component);\n };\n\n return;\n }\n\n route.component = defineRouteComponent(route.component);\n}\n\nfunction enhanceRouteNavigationGuard(guard: NavigationGuardWithThis<undefined>): NavigationGuardWithThis<undefined> {\n return async function(this, ...args) {\n await App.ready;\n\n return guard.call(this, ...args);\n };\n}\n\nfunction enhanceRouteNavigationGuards(route: AerogelRoute): void {\n if (!route.beforeEnter) {\n return;\n }\n\n if (Array.isArray(route.beforeEnter)) {\n route.beforeEnter = route.beforeEnter.map(enhanceRouteNavigationGuard);\n\n return;\n }\n\n route.beforeEnter = enhanceRouteNavigationGuard(route.beforeEnter);\n}\n\nexport function defineRoute(route: AerogelRoute): RouteRecordRaw {\n enhanceRouteComponent(route);\n enhanceRouteNavigationGuards(route);\n\n return route;\n}\n\nexport function defineRouteBindings(bindings: RouteBindings): RouteBindings {\n return bindings;\n}\n\nexport function defineRoutes(routes: AerogelRoute[]): RouteRecordRaw[] {\n return routes.map(defineRoute);\n}\n","import Aerogel from 'virtual:aerogel';\n\nimport { bootServices } from '@aerogel/core';\nimport { createRouter, createWebHistory } from 'vue-router';\nimport type { Plugin } from '@aerogel/core';\nimport type { RouteRecordRaw } from 'vue-router';\n\nimport Router from './services/Router';\nimport type { RouteBindings } from './services/Router';\n\nconst services = { $router: Router };\n\nexport * from './services/Router';\nexport * from './utils';\nexport { default as Router } from './services/Router';\n\nexport interface Options {\n routes: RouteRecordRaw[];\n bindings?: RouteBindings;\n basePath?: string;\n}\n\nexport type RoutingServices = typeof services;\n\nexport default function routing(options: Options): Plugin {\n return {\n async install(app) {\n const router = createRouter({\n routes: options.routes,\n history: createWebHistory(options.basePath ?? Aerogel.basePath),\n });\n\n Router.use(router, options);\n app.use(router);\n\n await bootServices(app, services);\n },\n };\n}\n\ndeclare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends RoutingServices {}\n}\n"],"names":["Service","defineServiceState","name","initialState","flashRoute","persist","RouterService","constructor","super","_defineProperty","this","router","shallowRef","bindings","routesParams","currentRoute","computed","value","route","unref","params","path","rawParams","use","options","arguments","length","undefined","beforeEach","once","handleStatic404Redirect","to","beforeNavigation","boot","Events","on","objectOnly","async","replace","__get","property","Reflect","get","resolvedParams","paramName","paramValue","Object","entries","resolveBinding","Storage","pull","binding","Array","isArray","App","ready","Router","facade","defineRouteComponent","pageComponent","defineComponent","setup","useRoute","pageParams","h","setupPageComponent","enhanceRouteNavigationGuard","guard","_len","args","_key","call","defineRoute","component","lazyComponent","default","enhanceRouteComponent","beforeEnter","map","enhanceRouteNavigationGuards","services","$router","install","app","createRouter","routes","history","createWebHistory","basePath","Aerogel","bootServices"],"mappings":"icAGAA,EAAeC,qBAAmB,CAC9BC,KAAM,SACNC,aAAc,CACVC,WAAY,MAEhBC,QAAS,CAAC,gBCcR,MAAOC,UAAsBN,EAO/BO,WAAAA,GACIC,QAA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G,CAAsB1D,GAf1B,SAAsCA,GAC7BA,EAAM2D,cAIPzB,MAAMC,QAAQnC,EAAM2D,aACpB3D,EAAM2D,YAAc3D,EAAM2D,YAAYC,IAAIZ,GAK9ChD,EAAM2D,YAAcX,EAA4BhD,EAAM2D,aAC1D,CAIIE,CAA6B7D,GAEtBA,CACX,CC7DA,MAAM8D,EAAW,CAAEC,QAASzB,4DAcJ,SAAQhC,GAC5B,MAAO,CACH,aAAM0D,CAAQC,GACV,MAAMxE,EAASyE,EAAAA,aAAa,CACxBC,OAAQ7D,EAAQ6D,OAChBC,QAASC,EAAAA,iBAAiB/D,EAAQgE,UAAYC,EAAAA,QAAQD,YAG1DhC,EAAOjC,IAAIZ,EAAQa,GACnB2D,EAAI5D,IAAIZ,SAEF+E,EAAYA,aAACP,EAAKH,EAC5B,EAER,oDDmCM,SAA8BnE,GAChC,OAAOA,CACX,uBAEM,SAAuBwE,GACzB,OAAOA,EAAOP,IAAIN,EACtB"}
@@ -0,0 +1,81 @@
1
+ import type { ComputedRef } from 'vue';
2
+ import { Constructor } from '@noeldemartin/utils';
3
+ import { Facade } from '@noeldemartin/utils';
4
+ import type { Plugin as Plugin_2 } from '@aerogel/core';
5
+ import type { Ref } from 'vue';
6
+ import type { RouteLocationNormalized } from 'vue-router';
7
+ import type { RouteLocationNormalizedLoaded } from 'vue-router';
8
+ import type { RouteLocationRaw } from 'vue-router';
9
+ import type { RouteParams } from 'vue-router';
10
+ import type { RouteParamValue } from 'vue-router';
11
+ import type { Router as Router_2 } from 'vue-router';
12
+ import type { RouteRecordRaw } from 'vue-router';
13
+ import { Service } from '@aerogel/core';
14
+ import { UnrefServiceState } from '@aerogel/core';
15
+
16
+ export declare type AerogelRoute = RouteRecordRaw;
17
+
18
+ declare const _default: Constructor<UnrefServiceState< {
19
+ flashRoute: RouteLocationRaw | null;
20
+ }>> & Constructor< {}> & Constructor<Service<UnrefServiceState< {
21
+ flashRoute: RouteLocationRaw | null;
22
+ }>, {}, Partial<UnrefServiceState< {
23
+ flashRoute: RouteLocationRaw | null;
24
+ }>>>>;
25
+
26
+ export declare function defineRoute(route: AerogelRoute): RouteRecordRaw;
27
+
28
+ export declare function defineRouteBindings(bindings: RouteBindings): RouteBindings;
29
+
30
+ export declare function defineRoutes(routes: AerogelRoute[]): RouteRecordRaw[];
31
+
32
+ export declare type LoadedRoute = Omit<RouteLocationNormalizedLoaded, 'params'> & {
33
+ rawParams: RouteParams;
34
+ params?: Record<string, unknown>;
35
+ };
36
+
37
+ export declare interface Options {
38
+ routes: RouteRecordRaw[];
39
+ bindings?: RouteBindings;
40
+ basePath?: string;
41
+ }
42
+
43
+ export declare type RouteBinding = (slug: string, params: Record<string, unknown>) => unknown | Promise<unknown>;
44
+
45
+ export declare type RouteBindings = Record<string, RouteBinding>;
46
+
47
+ export declare const Router: Facade<RouterService, Constructor<RouterService>>;
48
+
49
+ export declare class RouterService extends _default {
50
+ readonly currentRoute: ComputedRef<LoadedRoute | null>;
51
+ readonly routesParams: Ref<Record<string, Record<string, unknown>>>;
52
+ protected router: Ref<Router_2 | null>;
53
+ protected bindings: RouteBindings;
54
+ constructor();
55
+ use(router: Router_2, options?: {
56
+ bindings?: RouteBindings;
57
+ }): void;
58
+ protected boot(): Promise<void>;
59
+ protected __get(property: string): unknown;
60
+ protected beforeNavigation(route: RouteLocationNormalized): Promise<void>;
61
+ protected handleStatic404Redirect(): void;
62
+ protected resolveBinding(name: string, value: RouteParamValue | RouteParamValue[], params: Record<string, unknown>): Promise<unknown>;
63
+ }
64
+
65
+ export declare interface RouterService extends Omit<Router_2, 'currentRoute'> {
66
+ }
67
+
68
+ declare function routing(options: Options): Plugin_2;
69
+ export default routing;
70
+
71
+ export declare type RoutingServices = typeof services;
72
+
73
+ declare const services: {
74
+ $router: Facade<RouterService, Constructor<RouterService>>;
75
+ };
76
+
77
+ export { }
78
+
79
+ declare module '@vue/runtime-core' {
80
+ interface ComponentCustomProperties extends RoutingServices {}
81
+ }
@@ -0,0 +1,2 @@
1
+ import t from"virtual:aerogel";import{defineServiceState as e,Events as r,App as o,bootServices as n}from"@aerogel/core";import{useRoute as s,createRouter as a,createWebHistory as i}from"vue-router";import u from"@babel/runtime/helpers/esm/defineProperty";import{shallowRef as c,computed as l,unref as h,defineComponent as f,h as m}from"vue";import{facade as p,once as d,objectOnly as v,Storage as b}from"@noeldemartin/utils";import"core-js/modules/esnext.async-iterator.map.js";import"core-js/modules/esnext.iterator.map.js";var g=e({name:"router",initialState:{flashRoute:null},persist:["flashRoute"]});class y extends g{constructor(){super(),u(this,"currentRoute",void 0),u(this,"routesParams",void 0),u(this,"router",void 0),u(this,"bindings",void 0),this.router=c(null),this.bindings={},this.routesParams=c({}),this.currentRoute=l((()=>{if(!this.router.value)return null;const t=h(this.router.value.currentRoute);return{...t,params:this.routesParams.value?.[t.path],rawParams:t.params}}))}use(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.router.value=t,this.bindings=e.bindings??{},t.beforeEach(d((()=>this.handleStatic404Redirect()))),t.beforeEach((t=>this.beforeNavigation(t)))}async boot(){r.on("before-login",(()=>this.flashRoute=v(this.currentRoute.value,["path","query","hash"]))),r.on("login",(async()=>{this.flashRoute&&(await this.replace(this.flashRoute),this.flashRoute=null)}))}__get(t){return this.router.value?super.__get(t)??Reflect.get(this.router.value,t):super.__get(t)}async beforeNavigation(t){const e={...t.params};for(const[r,o]of Object.entries(t.params))e[r]=await this.resolveBinding(r,o,e);this.routesParams.value={...this.routesParams.value,[t.path]:e}}handleStatic404Redirect(){const t=b.pull("static-404-redirect");t&&this.replace(t)}async resolveBinding(t,e,r){const n=this.bindings[t];return Array.isArray(e)||!n?e:(await o.ready,n(e,r))}}var R=p(new y);function P(t){return f({setup:()=>function(t){const e=s(),r=l((()=>R.routesParams?.value[e.path]));return()=>m(t,r.value)}(t)})}function w(t){return async function(){await o.ready;for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return t.call(this,...r)}}function E(t){return function(t){if(t.component)if("function"!=typeof t.component)t.component=P(t.component);else{const e=t.component;t.component=async()=>{const{default:t}=await e();return P(t)}}}(t),function(t){t.beforeEnter&&(Array.isArray(t.beforeEnter)?t.beforeEnter=t.beforeEnter.map(w):t.beforeEnter=w(t.beforeEnter))}(t),t}function _(t){return t}function j(t){return t.map(E)}const A={$router:R};function x(e){return{async install(r){const o=a({routes:e.routes,history:i(e.basePath??t.basePath)});R.use(o,e),r.use(o),await n(r,A)}}}export{R as Router,y as RouterService,x as default,E as defineRoute,_ as defineRouteBindings,j as defineRoutes};
2
+ //# sourceMappingURL=aerogel-plugin-routing.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aerogel-plugin-routing.esm.js","sources":["../src/services/Router.state.ts","../src/services/Router.ts","../src/utils/routes.ts","../src/main.ts"],"sourcesContent":["import { defineServiceState } from '@aerogel/core';\nimport type { RouteLocationRaw } from 'vue-router';\n\nexport default defineServiceState({\n name: 'router',\n initialState: {\n flashRoute: null as RouteLocationRaw | null,\n },\n persist: ['flashRoute'],\n});\n","import { computed, shallowRef, unref } from 'vue';\nimport { App, Events } from '@aerogel/core';\nimport { Storage, facade, objectOnly, once } from '@noeldemartin/utils';\nimport type { ComputedRef, Ref } from 'vue';\nimport type {\n RouteLocationNormalized,\n RouteLocationNormalizedLoaded,\n RouteLocationRaw,\n RouteParamValue,\n RouteParams,\n Router,\n} from 'vue-router';\n\nimport Service from './Router.state';\n\nexport type LoadedRoute = Omit<RouteLocationNormalizedLoaded, 'params'> & {\n rawParams: RouteParams;\n params?: Record<string, unknown>;\n};\nexport type RouteBinding = (slug: string, params: Record<string, unknown>) => unknown | Promise<unknown>;\nexport type RouteBindings = Record<string, RouteBinding>;\n\nexport class RouterService extends Service {\n\n public readonly currentRoute: ComputedRef<LoadedRoute | null>;\n public readonly routesParams: Ref<Record<string, Record<string, unknown>>>;\n protected router: Ref<Router | null>;\n protected bindings: RouteBindings;\n\n constructor() {\n super();\n\n this.router = shallowRef(null);\n this.bindings = {};\n this.routesParams = shallowRef({});\n this.currentRoute = computed(() => {\n if (!this.router.value) {\n return null;\n }\n\n const route = unref(this.router.value.currentRoute);\n\n return {\n ...route,\n params: this.routesParams.value?.[route.path],\n rawParams: route.params,\n };\n });\n }\n\n public use(router: Router, options: { bindings?: RouteBindings } = {}): void {\n this.router.value = router;\n this.bindings = options.bindings ?? {};\n\n router.beforeEach(once(() => this.handleStatic404Redirect()));\n router.beforeEach((to) => this.beforeNavigation(to));\n }\n\n protected async boot(): Promise<void> {\n Events.on(\n 'before-login',\n () =>\n (this.flashRoute = objectOnly(this.currentRoute.value as unknown as Record<string, unknown>, [\n 'path',\n 'query',\n 'hash',\n ])),\n );\n Events.on('login', async () => {\n if (!this.flashRoute) {\n return;\n }\n\n await this.replace(this.flashRoute);\n\n this.flashRoute = null;\n });\n }\n\n protected __get(property: string): unknown {\n return this.router.value\n ? super.__get(property) ?? Reflect.get(this.router.value, property)\n : super.__get(property);\n }\n\n protected async beforeNavigation(route: RouteLocationNormalized): Promise<void> {\n const resolvedParams: Record<string, unknown> = { ...route.params };\n\n for (const [paramName, paramValue] of Object.entries(route.params)) {\n resolvedParams[paramName] = await this.resolveBinding(paramName, paramValue, resolvedParams);\n }\n\n this.routesParams.value = {\n ...this.routesParams.value,\n [route.path]: resolvedParams,\n };\n }\n\n protected handleStatic404Redirect(): void {\n const route = Storage.pull<RouteLocationRaw>('static-404-redirect');\n\n route && this.replace(route);\n }\n\n protected async resolveBinding(\n name: string,\n value: RouteParamValue | RouteParamValue[],\n params: Record<string, unknown>,\n ): Promise<unknown> {\n const binding = this.bindings[name];\n\n if (Array.isArray(value) || !binding) {\n return value;\n }\n\n await App.ready;\n\n return binding(value, params);\n }\n\n}\n\nexport interface RouterService extends Omit<Router, 'currentRoute'> {}\n\nexport default facade(new RouterService());\n","import { App } from '@aerogel/core';\nimport { computed, defineComponent, h } from 'vue';\nimport { useRoute } from 'vue-router';\nimport type { Component, ConcreteComponent } from 'vue';\nimport type { NavigationGuardWithThis, RouteRecordRaw } from 'vue-router';\n\nimport Router from '../services/Router';\nimport type { RouteBindings } from '../services/Router';\n\nexport type AerogelRoute = RouteRecordRaw;\n\nfunction setupPageComponent(pageComponent: ConcreteComponent) {\n const route = useRoute();\n const pageParams = computed(() => Router.routesParams?.value[route.path]);\n\n return () => h(pageComponent, pageParams.value);\n}\n\nfunction defineRouteComponent(pageComponent: ConcreteComponent): Component {\n return defineComponent({\n setup: () => setupPageComponent(pageComponent),\n });\n}\n\nfunction enhanceRouteComponent(route: AerogelRoute): void {\n if (!route.component) {\n return;\n }\n\n if (typeof route.component === 'function') {\n const lazyComponent = route.component as () => Promise<{ default: ConcreteComponent }>;\n\n route.component = async () => {\n const { default: component } = await lazyComponent();\n\n return defineRouteComponent(component);\n };\n\n return;\n }\n\n route.component = defineRouteComponent(route.component);\n}\n\nfunction enhanceRouteNavigationGuard(guard: NavigationGuardWithThis<undefined>): NavigationGuardWithThis<undefined> {\n return async function(this, ...args) {\n await App.ready;\n\n return guard.call(this, ...args);\n };\n}\n\nfunction enhanceRouteNavigationGuards(route: AerogelRoute): void {\n if (!route.beforeEnter) {\n return;\n }\n\n if (Array.isArray(route.beforeEnter)) {\n route.beforeEnter = route.beforeEnter.map(enhanceRouteNavigationGuard);\n\n return;\n }\n\n route.beforeEnter = enhanceRouteNavigationGuard(route.beforeEnter);\n}\n\nexport function defineRoute(route: AerogelRoute): RouteRecordRaw {\n enhanceRouteComponent(route);\n enhanceRouteNavigationGuards(route);\n\n return route;\n}\n\nexport function defineRouteBindings(bindings: RouteBindings): RouteBindings {\n return bindings;\n}\n\nexport function defineRoutes(routes: AerogelRoute[]): RouteRecordRaw[] {\n return routes.map(defineRoute);\n}\n","import Aerogel from 'virtual:aerogel';\n\nimport { bootServices } from '@aerogel/core';\nimport { createRouter, createWebHistory } from 'vue-router';\nimport type { Plugin } from '@aerogel/core';\nimport type { RouteRecordRaw } from 'vue-router';\n\nimport Router from './services/Router';\nimport type { RouteBindings } from './services/Router';\n\nconst services = { $router: Router };\n\nexport * from './services/Router';\nexport * from './utils';\nexport { default as Router } from './services/Router';\n\nexport interface Options {\n routes: RouteRecordRaw[];\n bindings?: RouteBindings;\n basePath?: string;\n}\n\nexport type RoutingServices = typeof services;\n\nexport default function routing(options: Options): Plugin {\n return {\n async install(app) {\n const router = createRouter({\n routes: options.routes,\n history: createWebHistory(options.basePath ?? Aerogel.basePath),\n });\n\n Router.use(router, options);\n app.use(router);\n\n await bootServices(app, services);\n },\n };\n}\n\ndeclare module '@vue/runtime-core' {\n interface ComponentCustomProperties extends RoutingServices {}\n}\n"],"names":["Service","defineServiceState","name","initialState","flashRoute","persist","RouterService","constructor","super","_defineProperty","this","router","shallowRef","bindings","routesParams","currentRoute","computed","value","route","unref","params","path","rawParams","use","options","arguments","length","undefined","beforeEach","once","handleStatic404Redirect","to","beforeNavigation","boot","Events","on","objectOnly","async","replace","__get","property","Reflect","get","resolvedParams","paramName","paramValue","Object","entries","resolveBinding","Storage","pull","binding","Array","isArray","App","ready","Router","facade","defineRouteComponent","pageComponent","defineComponent","setup","useRoute","pageParams","h","setupPageComponent","enhanceRouteNavigationGuard","guard","_len","args","_key","call","defineRoute","component","lazyComponent","default","enhanceRouteComponent","beforeEnter","map","enhanceRouteNavigationGuards","defineRouteBindings","defineRoutes","routes","services","$router","routing","install","app","createRouter","history","createWebHistory","basePath","Aerogel","bootServices"],"mappings":"8gBAGA,IAAAA,EAAeC,EAAmB,CAC9BC,KAAM,SACNC,aAAc,CACVC,WAAY,MAEhBC,QAAS,CAAC,gBCcR,MAAOC,UAAsBN,EAO/BO,WAAAA,GACIC,QAAQC,EAAAC,KAAA,oBAAA,GAAAD,EAAAC,KAAA,oBAAA,GAAAD,EAAAC,KAAA,cAAA,GAAAD,EAAAC,KAAA,gBAAA,GAERA,KAAKC,OAASC,EAAW,MACzBF,KAAKG,SAAW,GAChBH,KAAKI,aAAeF,EAAW,CAAA,GAC/BF,KAAKK,aAAeC,GAAS,KACzB,I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S5B,GAcJ,SAAA6B,EAAQ7D,GAC5B,MAAO,CACH,aAAM8D,CAAQC,GACV,MAAM5E,EAAS6E,EAAa,CACxBN,OAAQ1D,EAAQ0D,OAChBO,QAASC,EAAiBlE,EAAQmE,UAAYC,EAAQD,YAG1DnC,EAAOjC,IAAIZ,EAAQa,GACnB+D,EAAIhE,IAAIZ,SAEFkF,EAAaN,EAAKJ,EAC5B,EAER"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@aerogel/plugin-routing",
3
+ "description": "Aerogel routing plugin",
4
+ "version": "0.0.0-next.0a86dbbb7bd76119cdde6fba32bca23589073d53",
5
+ "main": "dist/aerogel-plugin-routing.cjs.js",
6
+ "module": "dist/aerogel-plugin-routing.esm.js",
7
+ "types": "dist/aerogel-plugin-routing.d.ts",
8
+ "sideEffects": false,
9
+ "scripts": {
10
+ "build": "rm dist -rf && npm run build:js && npm run build:types",
11
+ "build:js": "noeldemartin-build-javascript",
12
+ "build:types": "noeldemartin-build-types",
13
+ "publish-next": "noeldemartin-publish-next",
14
+ "lint": "noeldemartin-lint src"
15
+ },
16
+ "engines": {
17
+ "node": ">=18.x"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/NoelDeMartin/aerogeljs.git"
22
+ },
23
+ "keywords": [
24
+ "javascript",
25
+ "aerogel"
26
+ ],
27
+ "author": "Noel De Martin",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/NoelDeMartin/aerogeljs/issues"
31
+ },
32
+ "peerDependencies": {
33
+ "@aerogel/core": "*",
34
+ "@aerogel/vite": "*"
35
+ },
36
+ "dependencies": {
37
+ "@noeldemartin/utils": "0.5.0-next.dce7f1ca99862fde01601bb39d71d0eaaed3abe5",
38
+ "vue": "^3.4.15",
39
+ "vue-router": "^4.2.1"
40
+ },
41
+ "devDependencies": {
42
+ "@aerogel/core": "*"
43
+ },
44
+ "eslintConfig": {
45
+ "extends": [
46
+ "@noeldemartin/eslint-config-typescript"
47
+ ]
48
+ }
49
+ }
package/src/main.ts ADDED
@@ -0,0 +1,43 @@
1
+ import Aerogel from 'virtual:aerogel';
2
+
3
+ import { bootServices } from '@aerogel/core';
4
+ import { createRouter, createWebHistory } from 'vue-router';
5
+ import type { Plugin } from '@aerogel/core';
6
+ import type { RouteRecordRaw } from 'vue-router';
7
+
8
+ import Router from './services/Router';
9
+ import type { RouteBindings } from './services/Router';
10
+
11
+ const services = { $router: Router };
12
+
13
+ export * from './services/Router';
14
+ export * from './utils';
15
+ export { default as Router } from './services/Router';
16
+
17
+ export interface Options {
18
+ routes: RouteRecordRaw[];
19
+ bindings?: RouteBindings;
20
+ basePath?: string;
21
+ }
22
+
23
+ export type RoutingServices = typeof services;
24
+
25
+ export default function routing(options: Options): Plugin {
26
+ return {
27
+ async install(app) {
28
+ const router = createRouter({
29
+ routes: options.routes,
30
+ history: createWebHistory(options.basePath ?? Aerogel.basePath),
31
+ });
32
+
33
+ Router.use(router, options);
34
+ app.use(router);
35
+
36
+ await bootServices(app, services);
37
+ },
38
+ };
39
+ }
40
+
41
+ declare module '@vue/runtime-core' {
42
+ interface ComponentCustomProperties extends RoutingServices {}
43
+ }
@@ -0,0 +1,10 @@
1
+ import { defineServiceState } from '@aerogel/core';
2
+ import type { RouteLocationRaw } from 'vue-router';
3
+
4
+ export default defineServiceState({
5
+ name: 'router',
6
+ initialState: {
7
+ flashRoute: null as RouteLocationRaw | null,
8
+ },
9
+ persist: ['flashRoute'],
10
+ });
@@ -0,0 +1,125 @@
1
+ import { computed, shallowRef, unref } from 'vue';
2
+ import { App, Events } from '@aerogel/core';
3
+ import { Storage, facade, objectOnly, once } from '@noeldemartin/utils';
4
+ import type { ComputedRef, Ref } from 'vue';
5
+ import type {
6
+ RouteLocationNormalized,
7
+ RouteLocationNormalizedLoaded,
8
+ RouteLocationRaw,
9
+ RouteParamValue,
10
+ RouteParams,
11
+ Router,
12
+ } from 'vue-router';
13
+
14
+ import Service from './Router.state';
15
+
16
+ export type LoadedRoute = Omit<RouteLocationNormalizedLoaded, 'params'> & {
17
+ rawParams: RouteParams;
18
+ params?: Record<string, unknown>;
19
+ };
20
+ export type RouteBinding = (slug: string, params: Record<string, unknown>) => unknown | Promise<unknown>;
21
+ export type RouteBindings = Record<string, RouteBinding>;
22
+
23
+ export class RouterService extends Service {
24
+
25
+ public readonly currentRoute: ComputedRef<LoadedRoute | null>;
26
+ public readonly routesParams: Ref<Record<string, Record<string, unknown>>>;
27
+ protected router: Ref<Router | null>;
28
+ protected bindings: RouteBindings;
29
+
30
+ constructor() {
31
+ super();
32
+
33
+ this.router = shallowRef(null);
34
+ this.bindings = {};
35
+ this.routesParams = shallowRef({});
36
+ this.currentRoute = computed(() => {
37
+ if (!this.router.value) {
38
+ return null;
39
+ }
40
+
41
+ const route = unref(this.router.value.currentRoute);
42
+
43
+ return {
44
+ ...route,
45
+ params: this.routesParams.value?.[route.path],
46
+ rawParams: route.params,
47
+ };
48
+ });
49
+ }
50
+
51
+ public use(router: Router, options: { bindings?: RouteBindings } = {}): void {
52
+ this.router.value = router;
53
+ this.bindings = options.bindings ?? {};
54
+
55
+ router.beforeEach(once(() => this.handleStatic404Redirect()));
56
+ router.beforeEach((to) => this.beforeNavigation(to));
57
+ }
58
+
59
+ protected async boot(): Promise<void> {
60
+ Events.on(
61
+ 'before-login',
62
+ () =>
63
+ (this.flashRoute = objectOnly(this.currentRoute.value as unknown as Record<string, unknown>, [
64
+ 'path',
65
+ 'query',
66
+ 'hash',
67
+ ])),
68
+ );
69
+ Events.on('login', async () => {
70
+ if (!this.flashRoute) {
71
+ return;
72
+ }
73
+
74
+ await this.replace(this.flashRoute);
75
+
76
+ this.flashRoute = null;
77
+ });
78
+ }
79
+
80
+ protected __get(property: string): unknown {
81
+ return this.router.value
82
+ ? super.__get(property) ?? Reflect.get(this.router.value, property)
83
+ : super.__get(property);
84
+ }
85
+
86
+ protected async beforeNavigation(route: RouteLocationNormalized): Promise<void> {
87
+ const resolvedParams: Record<string, unknown> = { ...route.params };
88
+
89
+ for (const [paramName, paramValue] of Object.entries(route.params)) {
90
+ resolvedParams[paramName] = await this.resolveBinding(paramName, paramValue, resolvedParams);
91
+ }
92
+
93
+ this.routesParams.value = {
94
+ ...this.routesParams.value,
95
+ [route.path]: resolvedParams,
96
+ };
97
+ }
98
+
99
+ protected handleStatic404Redirect(): void {
100
+ const route = Storage.pull<RouteLocationRaw>('static-404-redirect');
101
+
102
+ route && this.replace(route);
103
+ }
104
+
105
+ protected async resolveBinding(
106
+ name: string,
107
+ value: RouteParamValue | RouteParamValue[],
108
+ params: Record<string, unknown>,
109
+ ): Promise<unknown> {
110
+ const binding = this.bindings[name];
111
+
112
+ if (Array.isArray(value) || !binding) {
113
+ return value;
114
+ }
115
+
116
+ await App.ready;
117
+
118
+ return binding(value, params);
119
+ }
120
+
121
+ }
122
+
123
+ export interface RouterService extends Omit<Router, 'currentRoute'> {}
124
+
125
+ export default facade(new RouterService());
@@ -0,0 +1 @@
1
+ export * from './routes';
@@ -0,0 +1,80 @@
1
+ import { App } from '@aerogel/core';
2
+ import { computed, defineComponent, h } from 'vue';
3
+ import { useRoute } from 'vue-router';
4
+ import type { Component, ConcreteComponent } from 'vue';
5
+ import type { NavigationGuardWithThis, RouteRecordRaw } from 'vue-router';
6
+
7
+ import Router from '../services/Router';
8
+ import type { RouteBindings } from '../services/Router';
9
+
10
+ export type AerogelRoute = RouteRecordRaw;
11
+
12
+ function setupPageComponent(pageComponent: ConcreteComponent) {
13
+ const route = useRoute();
14
+ const pageParams = computed(() => Router.routesParams?.value[route.path]);
15
+
16
+ return () => h(pageComponent, pageParams.value);
17
+ }
18
+
19
+ function defineRouteComponent(pageComponent: ConcreteComponent): Component {
20
+ return defineComponent({
21
+ setup: () => setupPageComponent(pageComponent),
22
+ });
23
+ }
24
+
25
+ function enhanceRouteComponent(route: AerogelRoute): void {
26
+ if (!route.component) {
27
+ return;
28
+ }
29
+
30
+ if (typeof route.component === 'function') {
31
+ const lazyComponent = route.component as () => Promise<{ default: ConcreteComponent }>;
32
+
33
+ route.component = async () => {
34
+ const { default: component } = await lazyComponent();
35
+
36
+ return defineRouteComponent(component);
37
+ };
38
+
39
+ return;
40
+ }
41
+
42
+ route.component = defineRouteComponent(route.component);
43
+ }
44
+
45
+ function enhanceRouteNavigationGuard(guard: NavigationGuardWithThis<undefined>): NavigationGuardWithThis<undefined> {
46
+ return async function(this, ...args) {
47
+ await App.ready;
48
+
49
+ return guard.call(this, ...args);
50
+ };
51
+ }
52
+
53
+ function enhanceRouteNavigationGuards(route: AerogelRoute): void {
54
+ if (!route.beforeEnter) {
55
+ return;
56
+ }
57
+
58
+ if (Array.isArray(route.beforeEnter)) {
59
+ route.beforeEnter = route.beforeEnter.map(enhanceRouteNavigationGuard);
60
+
61
+ return;
62
+ }
63
+
64
+ route.beforeEnter = enhanceRouteNavigationGuard(route.beforeEnter);
65
+ }
66
+
67
+ export function defineRoute(route: AerogelRoute): RouteRecordRaw {
68
+ enhanceRouteComponent(route);
69
+ enhanceRouteNavigationGuards(route);
70
+
71
+ return route;
72
+ }
73
+
74
+ export function defineRouteBindings(bindings: RouteBindings): RouteBindings {
75
+ return bindings;
76
+ }
77
+
78
+ export function defineRoutes(routes: AerogelRoute[]): RouteRecordRaw[] {
79
+ return routes.map(defineRoute);
80
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["@aerogel/vite/dist/virtual"]
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }