From b6c4317e7ea0df4cb53930ae8bcfec115ed9705a Mon Sep 17 00:00:00 2001 From: Rafik El Hadi Houari Date: Sat, 6 Jan 2024 23:38:32 +0100 Subject: [PATCH] Fix templates not rendering inside target after revist (#28) --- CHANGELOG.md | 8 ++++++++ README.md | 4 ++-- dist/router.esm.js | 2 +- dist/router.esm.js.map | 4 ++-- dist/router.min.js | 2 +- dist/router.min.js.map | 4 ++-- package.json | 2 +- src/index.ts | 16 +++++++--------- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34ce056..1c76b9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [4.1.1] - 2024-01-06 + +### Fixed + +- Fixed template not rendering inside the target element after revisiting the page +- Fixed loading event not being sent after preloading page finishes loading. + ## [4.1.0] - 2024-01-06 ### Fixed @@ -288,3 +295,4 @@ It's mostly backward compatible but need a few tweaks: [4.0.2]: https://github.com/pinecone-router/router/compare/4.0.1..4.0.2 [4.0.3]: https://github.com/pinecone-router/router/compare/4.0.2..4.0.3 [4.1.0]: https://github.com/pinecone-router/router/compare/4.0.3..4.1.0 +[4.1.1]: https://github.com/pinecone-router/router/compare/4.1.0..4.1.1 diff --git a/README.md b/README.md index 5e1eef4..5621ad0 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@

-[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/pinecone-router/router?color=%2337C8AB&label=version&sort=semver)](https://github.com/pinecone-router/router/tree/4.1.0) -[![npm bundle size](https://img.shields.io/bundlephobia/minzip/pinecone-router?color=37C8AB)](https://bundlephobia.com/result?p=pinecone-router@4.1.0) +[![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/pinecone-router/router?color=%2337C8AB&label=version&sort=semver)](https://github.com/pinecone-router/router/tree/4.1.1) +[![npm bundle size](https://img.shields.io/bundlephobia/minzip/pinecone-router?color=37C8AB)](https://bundlephobia.com/result?p=pinecone-router@4.1.1) [![Downloads from JSDelivr](https://data.jsdelivr.com/v1/package/npm/pinecone-router/badge?style=rounded)](https://www.jsdelivr.com/package/npm/pinecone-router) [![npm](https://img.shields.io/npm/dm/pinecone-router?color=37C8AB&label=npm&logo=npm&logoColor=37C8AB)](https://npmjs.com/package/pinecone-router) [![Changelog](https://img.shields.io/badge/change-log-%2337C8AB)](/CHANGELOG.md) diff --git a/dist/router.esm.js b/dist/router.esm.js index 2408ff6..cba6ba6 100644 --- a/dist/router.esm.js +++ b/dist/router.esm.js @@ -1,2 +1,2 @@ -var M=class{constructor(o,c={}){this.params={};this.handlers=[];this.handlersDone=!1;this.path=o,Object.keys(c).forEach(d=>{this[d]=c[d]})}},L=M;function k(a){return a.replace(/(^\/+|\/+$)/g,"").split("/")}function C(a,o){let c=/(?:\?([^#]*))?(#.*)?$/,d=a.match(c),p={},x;if(d&&d[1]){let l=d[1].split("&");for(let E=0;En.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new L(t,e))-1},remove(t){this.routes=this.routes.filter(e=>e.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=o;var c={},d={};let p=new Set;var x={};let b=(t,e)=>(c[e]?c[e].then(n=>t.innerHTML=n):c[e]=fetch(e).then(n=>n.ok?n.text():(S(n.statusText),null)).then(n=>n==null?(d[e]=null,c[e]=null,null):(d[e]=n,t.innerHTML=n,n)),c[e]),h=(t,e,n)=>{if(p.has(e))return;p.add(e);let r=t.content.cloneNode(!0).firstElementChild;!r||(a.addScopeToNode(r,{},t),a.mutateDom(()=>{n!=null?n.appendChild(r):t.after(r),a.initTree(r)}),t._x_currentIfEl=r,t._x_undoIf=()=>{r.remove(),delete t._x_currentIfEl},a.nextTick(()=>p.delete(e)))};function T(t){t._x_undoIf&&(t._x_undoIf(),delete t._x_undoIf)}function l(t,e,n,r){if(t._x_currentIfEl)return t._x_currentIfEl;t.content.firstElementChild?(h(t,e),f()):n&&(d[n]?(t.innerHTML=d[n],h(t,e,r),f()):x[n]?x[n].then(()=>h(t,e,r)):b(t,n).then(()=>h(t,e,r)).finally(()=>f()))}let E=()=>{document.dispatchEvent(o.loadStart)},f=()=>{document.dispatchEvent(o.loadEnd)},y=t=>!o.settings.hash&&o.settings.basePath!="/"?o.settings.basePath+t:t,v=t=>o.routes.findIndex(e=>e.path==t);a.directive("route",(t,{expression:e},{effect:n,cleanup:r})=>{let i=e;if(P("onBeforeRouteProcessed",t,i),i.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;i!="notfound"&&(i=y(i),s=o.add(i));let u=o.routes[s]??o.notfound;!t.hasAttribute("x-template")&&t.content.firstElementChild!=null&&a.nextTick(()=>{n(()=>{u.handlersDone&&o.context.route==i?l(t,e):T(t)})}),r(()=>{t._x_undoIf&&t._x_undoIf(),o.remove(i)}),P("onAfterRouteProcessed",t,i)}),a.directive("handler",(t,{expression:e},{evaluate:n,cleanup:r})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let i;!(e.startsWith("[")&&e.endsWith("]"))&&!(e.startsWith("Array(")&&e.endsWith(")"))&&(e=`[${e}]`);let s=n(e),u=t.getAttribute("x-route");if(typeof s=="object")i=s;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof s}.`);for(let w=0;w{g.handlers=[],g.handlersDone=!0})}),a.directive("template",(t,{modifiers:e,expression:n},{Alpine:r,effect:i,cleanup:s})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");let u=n,g=W(e,"target",null)??window.PineconeRouter.settings.templateTargetId,w=document.getElementById(g);if(g&&!w)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+g+")");e.includes("preload")&&(x[u]=b(t,u).finally(()=>x[u]=null));let _=t.getAttribute("x-route"),I,H;_=="notfound"?(o.notfound.template=u,I=o.notfound):(_=y(_),H=v(_),o.routes[H].template=u,I=o.routes[H]),r.nextTick(()=>{i(()=>{I.handlersDone&&o.context.route==I.path?l(t,n,u,w):T(t)})}),s(()=>{t._x_undoIf&&t._x_undoIf()})}),a.$router=o.context,a.magic("router",()=>o.context),document.addEventListener("alpine:initialized",()=>{P("init"),o.settings.hash==!1?m(location.pathname,!1,!0):m(location.hash.substring(1),!1,!0)}),window.addEventListener("popstate",()=>{o.settings.hash?window.location.hash!=""&&m(window.location.hash.substring(1),!0):m(window.location.pathname,!0)}),R();function R(){function t(e){if(!e||!e.getAttribute)return;let n=e.getAttribute("href"),r=e.getAttribute("target");if(!(!n||!n.match(/^\//g)||r&&!r.match(/^_?self$/i)))return typeof n!="string"&&n.url&&(n=n.url),n}window.document.body.addEventListener("click",function(e){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.button||e.defaultPrevented)return;let n=o.routes[v(o.context.route)]??o.notfound;n.handlersDone||(n.cancelHandlers=!0,f());let r=e.target;do if(r.localName==="a"&&r.getAttribute("href")){if(r.hasAttribute("data-native")||r.hasAttribute("native"))return;let i=t(r);i&&(m(i),e.stopImmediatePropagation&&e.stopImmediatePropagation(),e.stopPropagation&&e.stopPropagation(),e.preventDefault());break}while(r=r.parentNode)})}async function m(t,e=!1,n=!1){t||(t="/"),o.context.path=t,o.settings.hash||(o.settings.basePath!="/"&&!t.startsWith(o.settings.basePath)&&(t=o.settings.basePath+t),t==o.settings.basePath&&!t.endsWith("/")&&(t+="/"));let r=o.routes.find(s=>{let u=C(t,s.path);return s.params=u!=!1?u:{},u!=!1})??o.notfound;r.handlersDone=!r.handlers.length,(r.handlers.length||r.template)&&E();let i=$(r.path,t,r.params);if(o.context=i,P("onBeforeHandlersExecuted",r,t,n)=="stop"){f();return}if(!e){let s="";if(o.settings.hash?(s="#",s+=window.location.search+t):s=t+window.location.search+window.location.hash,!n)history.pushState({path:s},"",s);else if(o.settings.hash&&t=="/")return o.context=i,m("/",!1,!1)}if(r&&r.handlers.length){if(r.cancelHandlers=!1,!await O(r.handlers,i)){f();return}r.handlersDone=!0,r.template||f()}P("onHandlersExecuted",r,t,n)}function $(t,e,n){return{route:t,path:e,params:n,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(r){return m(r),"stop"},navigate(r){m(r)}}}function W(t,e,n){if(t.indexOf(e)===-1)return n;let r=t[t.indexOf(e)+1];if(!r)return n;if(e==="target"){let i=r.match(/([a-z0-9_-]+)/);if(i)return i[1]}return r}async function O(t,e){for(let n=0;n{this[f]=c[f]})}},L=M;function k(a){return a.replace(/(^\/+|\/+$)/g,"").split("/")}function C(a,o){let c=/(?:\?([^#]*))?(#.*)?$/,f=a.match(c),p={},x;if(f&&f[1]){let l=f[1].split("&");for(let E=0;En.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new L(t,e))-1},remove(t){this.routes=this.routes.filter(e=>e.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=o;var c={},f={};let p=new Set;var x={};let b=(t,e)=>(c[e]?c[e].then(n=>t.innerHTML=n):c[e]=fetch(e).then(n=>n.ok?n.text():(S(n.statusText),null)).then(n=>n==null?(f[e]=null,c[e]=null,null):(f[e]=n,t.innerHTML=n,n)),c[e]),h=(t,e,n)=>{if(p.has(e))return;p.add(e);let r=t.content.cloneNode(!0).firstElementChild;!r||(a.addScopeToNode(r,{},t),a.mutateDom(()=>{n!=null?n.appendChild(r):t.after(r),a.initTree(r)}),t._x_currentIfEl=r,t._x_undoIf=()=>{r.remove(),delete t._x_currentIfEl},a.nextTick(()=>p.delete(e)))};function T(t){t._x_undoIf&&(t._x_undoIf(),delete t._x_undoIf)}function l(t,e,n,r){if(t._x_currentIfEl)return t._x_currentIfEl;t.content.firstElementChild?(h(t,e,r),d()):n&&(f[n]?(t.innerHTML=f[n],h(t,e,r),d()):x[n]?x[n].then(()=>h(t,e,r)):b(t,n).then(()=>h(t,e,r)).finally(()=>d()))}let E=()=>{document.dispatchEvent(o.loadStart)},d=()=>{document.dispatchEvent(o.loadEnd)},y=t=>!o.settings.hash&&o.settings.basePath!="/"?o.settings.basePath+t:t,v=t=>o.routes.findIndex(e=>e.path==t);a.directive("route",(t,{expression:e},{effect:n,cleanup:r})=>{let i=e;if(P("onBeforeRouteProcessed",t,i),i.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;i!="notfound"&&(i=y(i),s=o.add(i));let u=o.routes[s]??o.notfound;t.content.firstElementChild!=null&&a.nextTick(()=>{n(()=>{u.handlersDone&&o.context.route==i?l(t,e):T(t)})}),r(()=>{t._x_undoIf&&t._x_undoIf(),o.remove(i)}),P("onAfterRouteProcessed",t,i)}),a.directive("handler",(t,{expression:e},{evaluate:n,cleanup:r})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let i;!(e.startsWith("[")&&e.endsWith("]"))&&!(e.startsWith("Array(")&&e.endsWith(")"))&&(e=`[${e}]`);let s=n(e),u=t.getAttribute("x-route");if(typeof s=="object")i=s;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof s}.`);for(let w=0;w{g.handlers=[],g.handlersDone=!0})}),a.directive("template",(t,{modifiers:e,expression:n},{Alpine:r,effect:i,cleanup:s})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");let u=n,g=W(e,"target",null)??window.PineconeRouter.settings.templateTargetId,w=document.getElementById(g);if(g&&!w)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+g+")");e.includes("preload")&&(x[u]=b(t,u).finally(()=>{x[u]=null,d()}));let _=t.getAttribute("x-route"),I,H;_=="notfound"?(o.notfound.template=u,I=o.notfound):(_=y(_),H=v(_),o.routes[H].template=u,I=o.routes[H]),r.nextTick(()=>{i(()=>{I.handlersDone&&o.context.route==I.path?l(t,n,u,w):T(t)})}),s(()=>{t._x_undoIf&&t._x_undoIf()})}),a.$router=o.context,a.magic("router",()=>o.context),document.addEventListener("alpine:initialized",()=>{P("init"),o.settings.hash==!1?m(location.pathname,!1,!0):m(location.hash.substring(1),!1,!0)}),window.addEventListener("popstate",()=>{o.settings.hash?window.location.hash!=""&&m(window.location.hash.substring(1),!0):m(window.location.pathname,!0)}),R();function R(){function t(e){if(!e||!e.getAttribute)return;let n=e.getAttribute("href"),r=e.getAttribute("target");if(!(!n||!n.match(/^\//g)||r&&!r.match(/^_?self$/i)))return typeof n!="string"&&n.url&&(n=n.url),n}window.document.body.addEventListener("click",function(e){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.button||e.defaultPrevented)return;let n=o.routes[v(o.context.route)]??o.notfound;n.handlersDone||(n.cancelHandlers=!0,d());let r=e.target;do if(r.localName==="a"&&r.getAttribute("href")){if(r.hasAttribute("data-native")||r.hasAttribute("native"))return;let i=t(r);i&&(m(i),e.stopImmediatePropagation&&e.stopImmediatePropagation(),e.stopPropagation&&e.stopPropagation(),e.preventDefault());break}while(r=r.parentNode)})}async function m(t,e=!1,n=!1){t||(t="/"),o.context.path=t,o.settings.hash||(o.settings.basePath!="/"&&!t.startsWith(o.settings.basePath)&&(t=o.settings.basePath+t),t==o.settings.basePath&&!t.endsWith("/")&&(t+="/"));let r=o.routes.find(s=>{let u=C(t,s.path);return s.params=u!=!1?u:{},u!=!1})??o.notfound;r.handlersDone=!r.handlers.length,(r.handlers.length||r.template)&&E();let i=$(r.path,t,r.params);if(o.context=i,P("onBeforeHandlersExecuted",r,t,n)=="stop"){d();return}if(!e){let s="";if(o.settings.hash?(s="#",s+=window.location.search+t):s=t+window.location.search+window.location.hash,!n)history.pushState({path:s},"",s);else if(o.settings.hash&&t=="/")return o.context=i,m("/",!1,!1)}if(r&&r.handlers.length){if(r.cancelHandlers=!1,!await O(r.handlers,i)){d();return}r.handlersDone=!0,r.template||d()}P("onHandlersExecuted",r,t,n)}function $(t,e,n){return{route:t,path:e,params:n,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(r){return m(r),"stop"},navigate(r){m(r)}}}function W(t,e,n){if(t.indexOf(e)===-1)return n;let r=t[t.indexOf(e)+1];if(!r)return n;if(e==="target"){let i=r.match(/([a-z0-9_-]+)/);if(i)return i[1]}return r}async function O(t,e){for(let n=0;n {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n\tinterface HTMLTemplateElement {\r\n\t\t_x_undoIf: Function\r\n\t\t_x_currentIfEl: Element\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.1.0',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\tconst inMakeProgress = new Set()\r\n\tvar preloadingTemplates: { [key: string]: Promise } = {}\r\n\r\n\tconst load = (el: HTMLTemplateElement, url: string) => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => el.innerHTML = html)\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (!r.ok) {\r\n\t\t\t\t\tfetchError(r.statusText);\r\n\t\t\t\t\treturn null\r\n\t\t\t\t}\r\n\t\t\t\treturn r.text()\r\n\t\t\t}).then(html => {\r\n\t\t\t\tif (html == null) {\r\n\t\t\t\t\tcachedTemplates[url] = null;\r\n\t\t\t\t\tloadingTemplates[url] = null\r\n\t\t\t\t\treturn null;\r\n\t\t\t\t}\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tel.innerHTML = html\r\n\t\t\t\treturn html\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst make = (el: HTMLTemplateElement, expression: string, targetEl?: HTMLElement) => {\r\n\t\tif (inMakeProgress.has(expression)) return\r\n\t\tinMakeProgress.add(expression)\r\n\r\n\t\tconst clone = (el.content.cloneNode(true) as HTMLElement).firstElementChild\r\n\r\n\t\tif (!clone) return\r\n\r\n\t\tAlpine.addScopeToNode(clone, {}, el)\r\n\r\n\t\tAlpine.mutateDom(() => {\r\n\t\t\tif (targetEl != null) {\r\n\t\t\t\ttargetEl.appendChild(clone)\r\n\t\t\t} else\r\n\t\t\t\tel.after(clone)\r\n\t\t\tAlpine.initTree(clone)\r\n\t\t})\r\n\r\n\t\tel._x_currentIfEl = clone\r\n\r\n\t\tel._x_undoIf = () => {\r\n\t\t\tclone.remove()\r\n\r\n\t\t\tdelete el._x_currentIfEl\r\n\t\t}\r\n\r\n\t\tAlpine.nextTick(() => inMakeProgress.delete(expression))\r\n\t}\r\n\r\n\tfunction hide(el: HTMLTemplateElement) {\r\n\t\tif (el._x_undoIf) {\r\n\t\t\tel._x_undoIf()\r\n\t\t\tdelete el._x_undoIf\r\n\t\t}\r\n\t}\r\n\r\n\tfunction show(el: HTMLTemplateElement, expression: string, url?: string, targetEl?: HTMLElement) {\r\n\t\tif (el._x_currentIfEl) return el._x_currentIfEl\r\n\t\tif (el.content.firstElementChild) {\r\n\t\t\tmake(el, expression)\r\n\t\t\tendLoading()\r\n\t\t} else if (url) {\r\n\t\t\t// Since during loading, the content is automatically put inside the template\r\n\t\t\t// This first case will only happen if the content of the template was cleared somehow\r\n\t\t\t// Likely manually\r\n\t\t\tif (cachedTemplates[url]) {\r\n\r\n\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\tmake(el, expression, targetEl)\r\n\t\t\t\tendLoading()\r\n\t\t\t} else {\r\n\t\t\t\t// This second case is that it didn't finish loading\r\n\t\t\t\tif (preloadingTemplates[url]) {\r\n\t\t\t\t\tpreloadingTemplates[url].then(() => make(el, expression, targetEl))\r\n\t\t\t\t} else {\r\n\t\t\t\t\tload(el, url).then(() => make(el, expression, targetEl)).finally(() => endLoading())\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { effect, cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\r\n\t\t\t// this will show inline templates, you can't mix inline and x-template\r\n\t\t\t// so we check if we already have x-template\r\n\t\t\t// this is due to x-template also putting the template inside el.content.firstElementChild\r\n\t\t\t// so we omit the x-template this code will run both here and in x-template directive\r\n\t\t\t// and also x-template.target will not work!\r\n\t\t\tif (!el.hasAttribute('x-template') && el.content.firstElementChild != null) {\r\n\t\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\t\teffect(() => {\r\n\t\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == path\r\n\t\t\t\t\t\tfound ? show(el, expression) : hide(el)\r\n\t\t\t\t\t})\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t\tPineconeRouter.remove(path);\r\n\t\t\t})\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\t// add `this` context for handlers inside an Alpine.component\r\n\t\t\tfor (let index = 0; index < handlers.length; index++) {\r\n\t\t\t\thandlers[index] = handlers[index].bind(Alpine.$data(el))\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tpreloadingTemplates[url] = load(el, url).finally(() => preloadingTemplates[url] = null)\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == route.path\r\n\t\t\t\t\tfound ? show(el, expression, url, targetEl) : hide(el)\r\n\t\t\t\t})\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (PineconeRouter.settings.hash == false) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\tfunction validateLink(node) {\r\n\t\t\t// only valid elements\r\n\t\t\tif (!node || !node.getAttribute) return;\r\n\r\n\t\t\tlet href = node.getAttribute('href'),\r\n\t\t\t\ttarget = node.getAttribute('target');\r\n\r\n\t\t\t// ignore links with targets and non-path URLs\r\n\t\t\tif (!href || !href.match(/^\\//g) || (target && !target.match(/^_?self$/i)))\r\n\t\t\t\treturn;\r\n\r\n\t\t\tif (typeof href !== 'string' && href.url) {\r\n\t\t\t\thref = href.url;\r\n\t\t\t}\r\n\t\t\treturn href\r\n\r\n\t\t}\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\t'click',\r\n\t\t\tfunction (e: any) {\r\n\t\t\t\tif (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button || e.defaultPrevented) return;\r\n\r\n\r\n\t\t\t\tlet currentRoute = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!currentRoute.handlersDone) {\r\n\t\t\t\t\tcurrentRoute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet node = e.target;\r\n\r\n\t\t\t\tdo {\r\n\t\t\t\t\tif (node.localName === 'a' && node.getAttribute('href')) {\r\n\t\t\t\t\t\tif (node.hasAttribute('data-native') || node.hasAttribute('native')) return;\r\n\t\t\t\t\t\tlet href = validateLink(node)\r\n\t\t\t\t\t\tif (href) {\r\n\t\t\t\t\t\t\tnavigate(href)\r\n\t\t\t\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation();\r\n\t\t\t\t\t\t\tif (e.stopPropagation) e.stopPropagation();\r\n\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t} while ((node = node.parentNode));\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\nexport default magic\r\n"], - "mappings": "AAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECXf,SAASK,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAAK,CAClC,IAAIC,EAAIF,EAAEC,GAAG,MAAM,GAAG,EACtBH,EAAQ,mBAAmBI,EAAE,EAAE,GAAK,mBACnCA,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,CACpB,CACD,CACD,CACA,IAAIC,EAASX,EAAWC,EAAI,QAAQG,EAAK,EAAE,CAAC,EAC3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AQ7B,EAAe,OAAOwB,EAAeuB,EAAQ,KAAK,IAAM/C,EAAe,SACnF,GAAI6B,EAAM,eACT,OAAAA,EAAM,eAAiB,GAChB,GAER,IAAI0B,EAMJ,GALIxB,EAASG,GAAG,YAAY,OAAS,gBACpCqB,EAAS,MAAMxB,EAASG,GAAGa,CAAO,EAElCQ,EAASxB,EAASG,GAAGa,CAAO,EAEzBQ,GAAU,OAAQ,MAAO,EAC9B,CAED,MAAO,EACR,CACD,CC1lBA,IAAOC,EAAQC", + "sourcesContent": ["import type { Handler } from './types'\r\n\r\nclass Route {\r\n\tparams: { [key: string]: any } = {}\r\n\tpath: string\r\n\thandlers: Handler[] = []\r\n\tconstructor(path: string, options = {}) {\r\n\t\tthis.path = path\r\n\t\tObject.keys(options).forEach((opt) => {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n\tinterface HTMLTemplateElement {\r\n\t\t_x_undoIf: Function\r\n\t\t_x_currentIfEl: Element\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.1.1',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\tconst inMakeProgress = new Set()\r\n\tvar preloadingTemplates: { [key: string]: Promise } = {}\r\n\r\n\tconst load = (el: HTMLTemplateElement, url: string) => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => el.innerHTML = html)\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (!r.ok) {\r\n\t\t\t\t\tfetchError(r.statusText);\r\n\t\t\t\t\treturn null\r\n\t\t\t\t}\r\n\t\t\t\treturn r.text()\r\n\t\t\t}).then(html => {\r\n\t\t\t\tif (html == null) {\r\n\t\t\t\t\tcachedTemplates[url] = null;\r\n\t\t\t\t\tloadingTemplates[url] = null\r\n\t\t\t\t\treturn null;\r\n\t\t\t\t}\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tel.innerHTML = html\r\n\t\t\t\treturn html\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst make = (el: HTMLTemplateElement, expression: string, targetEl?: HTMLElement) => {\r\n\t\tif (inMakeProgress.has(expression)) return\r\n\t\tinMakeProgress.add(expression)\r\n\r\n\t\tconst clone = (el.content.cloneNode(true) as HTMLElement).firstElementChild\r\n\r\n\t\tif (!clone) return\r\n\r\n\t\tAlpine.addScopeToNode(clone, {}, el)\r\n\r\n\t\tAlpine.mutateDom(() => {\r\n\t\t\tif (targetEl != null) {\r\n\t\t\t\ttargetEl.appendChild(clone)\r\n\t\t\t} else\r\n\t\t\t\tel.after(clone)\r\n\t\t\tAlpine.initTree(clone)\r\n\t\t})\r\n\r\n\t\tel._x_currentIfEl = clone\r\n\r\n\t\tel._x_undoIf = () => {\r\n\t\t\tclone.remove()\r\n\r\n\t\t\tdelete el._x_currentIfEl\r\n\t\t}\r\n\r\n\t\tAlpine.nextTick(() => inMakeProgress.delete(expression))\r\n\t}\r\n\r\n\tfunction hide(el: HTMLTemplateElement) {\r\n\t\tif (el._x_undoIf) {\r\n\t\t\tel._x_undoIf()\r\n\t\t\tdelete el._x_undoIf\r\n\t\t}\r\n\t}\r\n\r\n\tfunction show(el: HTMLTemplateElement, expression: string, url?: string, targetEl?: HTMLElement) {\r\n\t\tif (el._x_currentIfEl) return el._x_currentIfEl\r\n\t\tif (el.content.firstElementChild) {\r\n\t\t\tmake(el, expression, targetEl)\r\n\t\t\tendLoading()\r\n\t\t} else if (url) {\r\n\t\t\t// Since during loading, the content is automatically put inside the template\r\n\t\t\t// This first case will only happen if the content of the template was cleared somehow\r\n\t\t\t// Likely manually\r\n\t\t\tif (cachedTemplates[url]) {\r\n\r\n\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\tmake(el, expression, targetEl)\r\n\t\t\t\tendLoading()\r\n\t\t\t} else {\r\n\t\t\t\t// This second case is that it didn't finish loading\r\n\t\t\t\tif (preloadingTemplates[url]) {\r\n\t\t\t\t\tpreloadingTemplates[url].then(() => make(el, expression, targetEl))\r\n\t\t\t\t} else {\r\n\t\t\t\t\tload(el, url).then(() => make(el, expression, targetEl)).finally(() => endLoading())\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { effect, cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\r\n\t\t\tif (el.content.firstElementChild != null) {\r\n\t\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\t\teffect(() => {\r\n\t\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == path\r\n\t\t\t\t\t\tfound ? show(el, expression) : hide(el)\r\n\t\t\t\t\t})\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t\tPineconeRouter.remove(path);\r\n\t\t\t})\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\t// add `this` context for handlers inside an Alpine.component\r\n\t\t\tfor (let index = 0; index < handlers.length; index++) {\r\n\t\t\t\thandlers[index] = handlers[index].bind(Alpine.$data(el))\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tpreloadingTemplates[url] = load(el, url).finally(() => {\r\n\t\t\t\t\tpreloadingTemplates[url] = null;\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == route.path\r\n\t\t\t\t\tfound ? show(el, expression, url, targetEl) : hide(el)\r\n\t\t\t\t})\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (PineconeRouter.settings.hash == false) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\tfunction validateLink(node) {\r\n\t\t\t// only valid elements\r\n\t\t\tif (!node || !node.getAttribute) return;\r\n\r\n\t\t\tlet href = node.getAttribute('href'),\r\n\t\t\t\ttarget = node.getAttribute('target');\r\n\r\n\t\t\t// ignore links with targets and non-path URLs\r\n\t\t\tif (!href || !href.match(/^\\//g) || (target && !target.match(/^_?self$/i)))\r\n\t\t\t\treturn;\r\n\r\n\t\t\tif (typeof href !== 'string' && href.url) {\r\n\t\t\t\thref = href.url;\r\n\t\t\t}\r\n\t\t\treturn href\r\n\r\n\t\t}\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\t'click',\r\n\t\t\tfunction (e: any) {\r\n\t\t\t\tif (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button || e.defaultPrevented) return;\r\n\r\n\r\n\t\t\t\tlet currentRoute = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!currentRoute.handlersDone) {\r\n\t\t\t\t\tcurrentRoute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet node = e.target;\r\n\r\n\t\t\t\tdo {\r\n\t\t\t\t\tif (node.localName === 'a' && node.getAttribute('href')) {\r\n\t\t\t\t\t\tif (node.hasAttribute('data-native') || node.hasAttribute('native')) return;\r\n\t\t\t\t\t\tlet href = validateLink(node)\r\n\t\t\t\t\t\tif (href) {\r\n\t\t\t\t\t\t\tnavigate(href)\r\n\t\t\t\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation();\r\n\t\t\t\t\t\t\tif (e.stopPropagation) e.stopPropagation();\r\n\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t} while ((node = node.parentNode));\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\nexport default magic\r\n"], + "mappings": "AAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECXf,SAASK,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,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IAAIN,EAAQQ,EAAS,MAAM,eAAe,EAC1C,GAAIR,EAAO,OAAOA,EAAM,EACzB,CACA,OAAOQ,CACR,CAIA,eAAeJ,EAAOnB,EAAUgB,EAAS,CACxC,QAASb,EAAI,EAAGA,EAAIH,EAAS,OAAQG,IACpC,GAAI,OAAOH,EAASG,IAAM,WAAY,CAErC,IAAIL,EAAQ7B,EAAe,OAAOwB,EAAeuB,EAAQ,KAAK,IAAM/C,EAAe,SACnF,GAAI6B,EAAM,eACT,OAAAA,EAAM,eAAiB,GAChB,GAER,IAAI0B,EAMJ,GALIxB,EAASG,GAAG,YAAY,OAAS,gBACpCqB,EAAS,MAAMxB,EAASG,GAAGa,CAAO,EAElCQ,EAASxB,EAASG,GAAGa,CAAO,EAEzBQ,GAAU,OAAQ,MAAO,EAC9B,CAED,MAAO,EACR,CACD,CCxlBA,IAAOC,EAAQC", "names": ["Route", "path", "options", "opt", "route_default", "segmentize", "url", "match", "routePath", "reg", "c", "matches", "ret", "p", "i", "r", "urlSeg", "route", "max", "param", "flags", "plus", "star", "val", "middleware", "func", "args", "plugin", "fetchError", "error", "src_default", "Alpine", "PineconeRouter", "route_default", "path", "navigate", "options", "r", "loadingTemplates", "cachedTemplates", "inMakeProgress", "preloadingTemplates", "load", "el", "url", "html", "fetchError", "make", "expression", "targetEl", "clone", "hide", "show", "endLoading", "startLoading", "addBasePath", "findRouteIndex", "effect", "cleanup", "middleware", "routeIndex", "route", "evaluate", "handlers", "evaluatedExpression", "index", "i", "modifiers", "target", "modifierValue", "interceptLinks", "validateLink", "node", "href", "currentRoute", "fromPopState", "firstLoad", "m", "match", "context", "buildContext", "fullPath", "handle", "params", "key", "fallback", "rawValue", "result", "module_default", "src_default"] } diff --git a/dist/router.min.js b/dist/router.min.js index f8f54ff..d5fd9f3 100644 --- a/dist/router.min.js +++ b/dist/router.min.js @@ -1,2 +1,2 @@ -(()=>{var M=class{constructor(o,c={}){this.params={};this.handlers=[];this.handlersDone=!1;this.path=o,Object.keys(c).forEach(d=>{this[d]=c[d]})}},L=M;function k(a){return a.replace(/(^\/+|\/+$)/g,"").split("/")}function C(a,o){let c=/(?:\?([^#]*))?(#.*)?$/,d=a.match(c),p={},x;if(d&&d[1]){let l=d[1].split("&");for(let E=0;En.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new L(t,e))-1},remove(t){this.routes=this.routes.filter(e=>e.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=o;var c={},d={};let p=new Set;var x={};let b=(t,e)=>(c[e]?c[e].then(n=>t.innerHTML=n):c[e]=fetch(e).then(n=>n.ok?n.text():(S(n.statusText),null)).then(n=>n==null?(d[e]=null,c[e]=null,null):(d[e]=n,t.innerHTML=n,n)),c[e]),h=(t,e,n)=>{if(p.has(e))return;p.add(e);let r=t.content.cloneNode(!0).firstElementChild;!r||(a.addScopeToNode(r,{},t),a.mutateDom(()=>{n!=null?n.appendChild(r):t.after(r),a.initTree(r)}),t._x_currentIfEl=r,t._x_undoIf=()=>{r.remove(),delete t._x_currentIfEl},a.nextTick(()=>p.delete(e)))};function T(t){t._x_undoIf&&(t._x_undoIf(),delete t._x_undoIf)}function l(t,e,n,r){if(t._x_currentIfEl)return t._x_currentIfEl;t.content.firstElementChild?(h(t,e),f()):n&&(d[n]?(t.innerHTML=d[n],h(t,e,r),f()):x[n]?x[n].then(()=>h(t,e,r)):b(t,n).then(()=>h(t,e,r)).finally(()=>f()))}let E=()=>{document.dispatchEvent(o.loadStart)},f=()=>{document.dispatchEvent(o.loadEnd)},y=t=>!o.settings.hash&&o.settings.basePath!="/"?o.settings.basePath+t:t,v=t=>o.routes.findIndex(e=>e.path==t);a.directive("route",(t,{expression:e},{effect:n,cleanup:r})=>{let i=e;if(P("onBeforeRouteProcessed",t,i),i.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;i!="notfound"&&(i=y(i),s=o.add(i));let u=o.routes[s]??o.notfound;!t.hasAttribute("x-template")&&t.content.firstElementChild!=null&&a.nextTick(()=>{n(()=>{u.handlersDone&&o.context.route==i?l(t,e):T(t)})}),r(()=>{t._x_undoIf&&t._x_undoIf(),o.remove(i)}),P("onAfterRouteProcessed",t,i)}),a.directive("handler",(t,{expression:e},{evaluate:n,cleanup:r})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let i;!(e.startsWith("[")&&e.endsWith("]"))&&!(e.startsWith("Array(")&&e.endsWith(")"))&&(e=`[${e}]`);let s=n(e),u=t.getAttribute("x-route");if(typeof s=="object")i=s;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof s}.`);for(let w=0;w{g.handlers=[],g.handlersDone=!0})}),a.directive("template",(t,{modifiers:e,expression:n},{Alpine:r,effect:i,cleanup:s})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");let u=n,g=W(e,"target",null)??window.PineconeRouter.settings.templateTargetId,w=document.getElementById(g);if(g&&!w)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+g+")");e.includes("preload")&&(x[u]=b(t,u).finally(()=>x[u]=null));let _=t.getAttribute("x-route"),I,H;_=="notfound"?(o.notfound.template=u,I=o.notfound):(_=y(_),H=v(_),o.routes[H].template=u,I=o.routes[H]),r.nextTick(()=>{i(()=>{I.handlersDone&&o.context.route==I.path?l(t,n,u,w):T(t)})}),s(()=>{t._x_undoIf&&t._x_undoIf()})}),a.$router=o.context,a.magic("router",()=>o.context),document.addEventListener("alpine:initialized",()=>{P("init"),o.settings.hash==!1?m(location.pathname,!1,!0):m(location.hash.substring(1),!1,!0)}),window.addEventListener("popstate",()=>{o.settings.hash?window.location.hash!=""&&m(window.location.hash.substring(1),!0):m(window.location.pathname,!0)}),R();function R(){function t(e){if(!e||!e.getAttribute)return;let n=e.getAttribute("href"),r=e.getAttribute("target");if(!(!n||!n.match(/^\//g)||r&&!r.match(/^_?self$/i)))return typeof n!="string"&&n.url&&(n=n.url),n}window.document.body.addEventListener("click",function(e){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.button||e.defaultPrevented)return;let n=o.routes[v(o.context.route)]??o.notfound;n.handlersDone||(n.cancelHandlers=!0,f());let r=e.target;do if(r.localName==="a"&&r.getAttribute("href")){if(r.hasAttribute("data-native")||r.hasAttribute("native"))return;let i=t(r);i&&(m(i),e.stopImmediatePropagation&&e.stopImmediatePropagation(),e.stopPropagation&&e.stopPropagation(),e.preventDefault());break}while(r=r.parentNode)})}async function m(t,e=!1,n=!1){t||(t="/"),o.context.path=t,o.settings.hash||(o.settings.basePath!="/"&&!t.startsWith(o.settings.basePath)&&(t=o.settings.basePath+t),t==o.settings.basePath&&!t.endsWith("/")&&(t+="/"));let r=o.routes.find(s=>{let u=C(t,s.path);return s.params=u!=!1?u:{},u!=!1})??o.notfound;r.handlersDone=!r.handlers.length,(r.handlers.length||r.template)&&E();let i=$(r.path,t,r.params);if(o.context=i,P("onBeforeHandlersExecuted",r,t,n)=="stop"){f();return}if(!e){let s="";if(o.settings.hash?(s="#",s+=window.location.search+t):s=t+window.location.search+window.location.hash,!n)history.pushState({path:s},"",s);else if(o.settings.hash&&t=="/")return o.context=i,m("/",!1,!1)}if(r&&r.handlers.length){if(r.cancelHandlers=!1,!await A(r.handlers,i)){f();return}r.handlersDone=!0,r.template||f()}P("onHandlersExecuted",r,t,n)}function $(t,e,n){return{route:t,path:e,params:n,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(r){return m(r),"stop"},navigate(r){m(r)}}}function W(t,e,n){if(t.indexOf(e)===-1)return n;let r=t[t.indexOf(e)+1];if(!r)return n;if(e==="target"){let i=r.match(/([a-z0-9_-]+)/);if(i)return i[1]}return r}async function A(t,e){for(let n=0;n{window.Alpine.plugin(D)});})(); +(()=>{var M=class{constructor(o,c={}){this.params={};this.handlers=[];this.handlersDone=!1;this.path=o,Object.keys(c).forEach(f=>{this[f]=c[f]})}},L=M;function k(a){return a.replace(/(^\/+|\/+$)/g,"").split("/")}function C(a,o){let c=/(?:\?([^#]*))?(#.*)?$/,f=a.match(c),p={},x;if(f&&f[1]){let l=f[1].split("&");for(let E=0;En.path==t)!=null)throw new Error("Pinecone Router: route already exist");return this.routes.push(new L(t,e))-1},remove(t){this.routes=this.routes.filter(e=>e.path!=t)},loadStart:new Event("pinecone-start"),loadEnd:new Event("pinecone-end")});window.PineconeRouter=o;var c={},f={};let p=new Set;var x={};let b=(t,e)=>(c[e]?c[e].then(n=>t.innerHTML=n):c[e]=fetch(e).then(n=>n.ok?n.text():(S(n.statusText),null)).then(n=>n==null?(f[e]=null,c[e]=null,null):(f[e]=n,t.innerHTML=n,n)),c[e]),h=(t,e,n)=>{if(p.has(e))return;p.add(e);let r=t.content.cloneNode(!0).firstElementChild;!r||(a.addScopeToNode(r,{},t),a.mutateDom(()=>{n!=null?n.appendChild(r):t.after(r),a.initTree(r)}),t._x_currentIfEl=r,t._x_undoIf=()=>{r.remove(),delete t._x_currentIfEl},a.nextTick(()=>p.delete(e)))};function T(t){t._x_undoIf&&(t._x_undoIf(),delete t._x_undoIf)}function l(t,e,n,r){if(t._x_currentIfEl)return t._x_currentIfEl;t.content.firstElementChild?(h(t,e,r),d()):n&&(f[n]?(t.innerHTML=f[n],h(t,e,r),d()):x[n]?x[n].then(()=>h(t,e,r)):b(t,n).then(()=>h(t,e,r)).finally(()=>d()))}let E=()=>{document.dispatchEvent(o.loadStart)},d=()=>{document.dispatchEvent(o.loadEnd)},y=t=>!o.settings.hash&&o.settings.basePath!="/"?o.settings.basePath+t:t,v=t=>o.routes.findIndex(e=>e.path==t);a.directive("route",(t,{expression:e},{effect:n,cleanup:r})=>{let i=e;if(P("onBeforeRouteProcessed",t,i),i.indexOf("#")>-1)throw new Error("Pinecone Router: A route's path may not have a hash character.");let s=null;i!="notfound"&&(i=y(i),s=o.add(i));let u=o.routes[s]??o.notfound;t.content.firstElementChild!=null&&a.nextTick(()=>{n(()=>{u.handlersDone&&o.context.route==i?l(t,e):T(t)})}),r(()=>{t._x_undoIf&&t._x_undoIf(),o.remove(i)}),P("onAfterRouteProcessed",t,i)}),a.directive("handler",(t,{expression:e},{evaluate:n,cleanup:r})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-handler must be set on the same element as x-route.");let i;!(e.startsWith("[")&&e.endsWith("]"))&&!(e.startsWith("Array(")&&e.endsWith(")"))&&(e=`[${e}]`);let s=n(e),u=t.getAttribute("x-route");if(typeof s=="object")i=s;else throw new Error(`Pinecone Router: Invalid handler type: ${typeof s}.`);for(let w=0;w{g.handlers=[],g.handlersDone=!0})}),a.directive("template",(t,{modifiers:e,expression:n},{Alpine:r,effect:i,cleanup:s})=>{if(!t.hasAttribute("x-route"))throw new Error("Pinecone Router: x-template must be used on the same element as x-route.");let u=n,g=W(e,"target",null)??window.PineconeRouter.settings.templateTargetId,w=document.getElementById(g);if(g&&!w)throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID ("+g+")");e.includes("preload")&&(x[u]=b(t,u).finally(()=>{x[u]=null,d()}));let _=t.getAttribute("x-route"),I,H;_=="notfound"?(o.notfound.template=u,I=o.notfound):(_=y(_),H=v(_),o.routes[H].template=u,I=o.routes[H]),r.nextTick(()=>{i(()=>{I.handlersDone&&o.context.route==I.path?l(t,n,u,w):T(t)})}),s(()=>{t._x_undoIf&&t._x_undoIf()})}),a.$router=o.context,a.magic("router",()=>o.context),document.addEventListener("alpine:initialized",()=>{P("init"),o.settings.hash==!1?m(location.pathname,!1,!0):m(location.hash.substring(1),!1,!0)}),window.addEventListener("popstate",()=>{o.settings.hash?window.location.hash!=""&&m(window.location.hash.substring(1),!0):m(window.location.pathname,!0)}),R();function R(){function t(e){if(!e||!e.getAttribute)return;let n=e.getAttribute("href"),r=e.getAttribute("target");if(!(!n||!n.match(/^\//g)||r&&!r.match(/^_?self$/i)))return typeof n!="string"&&n.url&&(n=n.url),n}window.document.body.addEventListener("click",function(e){if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.button||e.defaultPrevented)return;let n=o.routes[v(o.context.route)]??o.notfound;n.handlersDone||(n.cancelHandlers=!0,d());let r=e.target;do if(r.localName==="a"&&r.getAttribute("href")){if(r.hasAttribute("data-native")||r.hasAttribute("native"))return;let i=t(r);i&&(m(i),e.stopImmediatePropagation&&e.stopImmediatePropagation(),e.stopPropagation&&e.stopPropagation(),e.preventDefault());break}while(r=r.parentNode)})}async function m(t,e=!1,n=!1){t||(t="/"),o.context.path=t,o.settings.hash||(o.settings.basePath!="/"&&!t.startsWith(o.settings.basePath)&&(t=o.settings.basePath+t),t==o.settings.basePath&&!t.endsWith("/")&&(t+="/"));let r=o.routes.find(s=>{let u=C(t,s.path);return s.params=u!=!1?u:{},u!=!1})??o.notfound;r.handlersDone=!r.handlers.length,(r.handlers.length||r.template)&&E();let i=$(r.path,t,r.params);if(o.context=i,P("onBeforeHandlersExecuted",r,t,n)=="stop"){d();return}if(!e){let s="";if(o.settings.hash?(s="#",s+=window.location.search+t):s=t+window.location.search+window.location.hash,!n)history.pushState({path:s},"",s);else if(o.settings.hash&&t=="/")return o.context=i,m("/",!1,!1)}if(r&&r.handlers.length){if(r.cancelHandlers=!1,!await O(r.handlers,i)){d();return}r.handlersDone=!0,r.template||d()}P("onHandlersExecuted",r,t,n)}function $(t,e,n){return{route:t,path:e,params:n,query:window.location.search.substring(1),hash:window.location.hash.substring(1),redirect(r){return m(r),"stop"},navigate(r){m(r)}}}function W(t,e,n){if(t.indexOf(e)===-1)return n;let r=t[t.indexOf(e)+1];if(!r)return n;if(e==="target"){let i=r.match(/([a-z0-9_-]+)/);if(i)return i[1]}return r}async function O(t,e){for(let n=0;n{window.Alpine.plugin(D)});})(); //# sourceMappingURL=router.min.js.map diff --git a/dist/router.min.js.map b/dist/router.min.js.map index 554e9cd..97ae7fe 100644 --- a/dist/router.min.js.map +++ b/dist/router.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["../src/route.ts", "../src/utils.ts", "../src/index.ts", "../builds/cdn.js"], - "sourcesContent": ["import type { Handler } from './types'\r\n\r\nclass Route {\r\n\tparams: { [key: string]: any } = {}\r\n\tpath: string\r\n\thandlers: Handler[] = []\r\n\tconstructor(path: string, options = {}) {\r\n\t\tthis.path = path\r\n\t\tObject.keys(options).forEach((opt) => {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n\tinterface HTMLTemplateElement {\r\n\t\t_x_undoIf: Function\r\n\t\t_x_currentIfEl: Element\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.1.0',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\tconst inMakeProgress = new Set()\r\n\tvar preloadingTemplates: { [key: string]: Promise } = {}\r\n\r\n\tconst load = (el: HTMLTemplateElement, url: string) => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => el.innerHTML = html)\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (!r.ok) {\r\n\t\t\t\t\tfetchError(r.statusText);\r\n\t\t\t\t\treturn null\r\n\t\t\t\t}\r\n\t\t\t\treturn r.text()\r\n\t\t\t}).then(html => {\r\n\t\t\t\tif (html == null) {\r\n\t\t\t\t\tcachedTemplates[url] = null;\r\n\t\t\t\t\tloadingTemplates[url] = null\r\n\t\t\t\t\treturn null;\r\n\t\t\t\t}\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tel.innerHTML = html\r\n\t\t\t\treturn html\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst make = (el: HTMLTemplateElement, expression: string, targetEl?: HTMLElement) => {\r\n\t\tif (inMakeProgress.has(expression)) return\r\n\t\tinMakeProgress.add(expression)\r\n\r\n\t\tconst clone = (el.content.cloneNode(true) as HTMLElement).firstElementChild\r\n\r\n\t\tif (!clone) return\r\n\r\n\t\tAlpine.addScopeToNode(clone, {}, el)\r\n\r\n\t\tAlpine.mutateDom(() => {\r\n\t\t\tif (targetEl != null) {\r\n\t\t\t\ttargetEl.appendChild(clone)\r\n\t\t\t} else\r\n\t\t\t\tel.after(clone)\r\n\t\t\tAlpine.initTree(clone)\r\n\t\t})\r\n\r\n\t\tel._x_currentIfEl = clone\r\n\r\n\t\tel._x_undoIf = () => {\r\n\t\t\tclone.remove()\r\n\r\n\t\t\tdelete el._x_currentIfEl\r\n\t\t}\r\n\r\n\t\tAlpine.nextTick(() => inMakeProgress.delete(expression))\r\n\t}\r\n\r\n\tfunction hide(el: HTMLTemplateElement) {\r\n\t\tif (el._x_undoIf) {\r\n\t\t\tel._x_undoIf()\r\n\t\t\tdelete el._x_undoIf\r\n\t\t}\r\n\t}\r\n\r\n\tfunction show(el: HTMLTemplateElement, expression: string, url?: string, targetEl?: HTMLElement) {\r\n\t\tif (el._x_currentIfEl) return el._x_currentIfEl\r\n\t\tif (el.content.firstElementChild) {\r\n\t\t\tmake(el, expression)\r\n\t\t\tendLoading()\r\n\t\t} else if (url) {\r\n\t\t\t// Since during loading, the content is automatically put inside the template\r\n\t\t\t// This first case will only happen if the content of the template was cleared somehow\r\n\t\t\t// Likely manually\r\n\t\t\tif (cachedTemplates[url]) {\r\n\r\n\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\tmake(el, expression, targetEl)\r\n\t\t\t\tendLoading()\r\n\t\t\t} else {\r\n\t\t\t\t// This second case is that it didn't finish loading\r\n\t\t\t\tif (preloadingTemplates[url]) {\r\n\t\t\t\t\tpreloadingTemplates[url].then(() => make(el, expression, targetEl))\r\n\t\t\t\t} else {\r\n\t\t\t\t\tload(el, url).then(() => make(el, expression, targetEl)).finally(() => endLoading())\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { effect, cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\r\n\t\t\t// this will show inline templates, you can't mix inline and x-template\r\n\t\t\t// so we check if we already have x-template\r\n\t\t\t// this is due to x-template also putting the template inside el.content.firstElementChild\r\n\t\t\t// so we omit the x-template this code will run both here and in x-template directive\r\n\t\t\t// and also x-template.target will not work!\r\n\t\t\tif (!el.hasAttribute('x-template') && el.content.firstElementChild != null) {\r\n\t\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\t\teffect(() => {\r\n\t\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == path\r\n\t\t\t\t\t\tfound ? show(el, expression) : hide(el)\r\n\t\t\t\t\t})\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t\tPineconeRouter.remove(path);\r\n\t\t\t})\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\t// add `this` context for handlers inside an Alpine.component\r\n\t\t\tfor (let index = 0; index < handlers.length; index++) {\r\n\t\t\t\thandlers[index] = handlers[index].bind(Alpine.$data(el))\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tpreloadingTemplates[url] = load(el, url).finally(() => preloadingTemplates[url] = null)\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == route.path\r\n\t\t\t\t\tfound ? show(el, expression, url, targetEl) : hide(el)\r\n\t\t\t\t})\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (PineconeRouter.settings.hash == false) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\tfunction validateLink(node) {\r\n\t\t\t// only valid elements\r\n\t\t\tif (!node || !node.getAttribute) return;\r\n\r\n\t\t\tlet href = node.getAttribute('href'),\r\n\t\t\t\ttarget = node.getAttribute('target');\r\n\r\n\t\t\t// ignore links with targets and non-path URLs\r\n\t\t\tif (!href || !href.match(/^\\//g) || (target && !target.match(/^_?self$/i)))\r\n\t\t\t\treturn;\r\n\r\n\t\t\tif (typeof href !== 'string' && href.url) {\r\n\t\t\t\thref = href.url;\r\n\t\t\t}\r\n\t\t\treturn href\r\n\r\n\t\t}\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\t'click',\r\n\t\t\tfunction (e: any) {\r\n\t\t\t\tif (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button || e.defaultPrevented) return;\r\n\r\n\r\n\t\t\t\tlet currentRoute = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!currentRoute.handlersDone) {\r\n\t\t\t\t\tcurrentRoute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet node = e.target;\r\n\r\n\t\t\t\tdo {\r\n\t\t\t\t\tif (node.localName === 'a' && node.getAttribute('href')) {\r\n\t\t\t\t\t\tif (node.hasAttribute('data-native') || node.hasAttribute('native')) return;\r\n\t\t\t\t\t\tlet href = validateLink(node)\r\n\t\t\t\t\t\tif (href) {\r\n\t\t\t\t\t\t\tnavigate(href)\r\n\t\t\t\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation();\r\n\t\t\t\t\t\t\tif (e.stopPropagation) e.stopPropagation();\r\n\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t} while ((node = node.parentNode));\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\ndocument.addEventListener('alpine:init', () => {\r\n window.Alpine.plugin(magic)\r\n})\r\n"], - "mappings": "MAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECXf,SAASK,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IAAIC,EAAM,wBACTC,EAAIJ,EAAI,MAAMG,CAAG,EACjBE,EAAe,CAAC,EAChBC,EACD,GAAIF,GAAKA,EAAE,GAAI,CACd,IAAIG,EAAIH,EAAE,GAAG,MAAM,GAAG,EACtB,QAASI,EAAI,EAAGA,EAAID,EAAE,OAAQC,IAAK,CAClC,IAAIC,EAAIF,EAAEC,GAAG,MAAM,GAAG,EACtBH,EAAQ,mBAAmBI,EAAE,EAAE,GAAK,mBACnCA,EAAE,MAAM,CAAC,EAAE,KAAK,G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,EAAGA,EAAIH,EAAS,OAAQG,IACpC,GAAI,OAAOH,EAASG,IAAM,WAAY,CAErC,IAAIL,EAAQ7B,EAAe,OAAOwB,EAAeuB,EAAQ,KAAK,IAAM/C,EAAe,SACnF,GAAI6B,EAAM,eACT,OAAAA,EAAM,eAAiB,GAChB,GAER,IAAI0B,EAMJ,GALIxB,EAASG,GAAG,YAAY,OAAS,gBACpCqB,EAAS,MAAMxB,EAASG,GAAGa,CAAO,EAElCQ,EAASxB,EAASG,GAAGa,CAAO,EAEzBQ,GAAU,OAAQ,MAAO,EAC9B,CAED,MAAO,EACR,CACD,CC1lBA,SAAS,iBAAiB,cAAe,IAAM,CAC7C,OAAO,OAAO,OAAOC,CAAK,CAC5B,CAAC", + "sourcesContent": ["import type { Handler } from './types'\r\n\r\nclass Route {\r\n\tparams: { [key: string]: any } = {}\r\n\tpath: string\r\n\thandlers: Handler[] = []\r\n\tconstructor(path: string, options = {}) {\r\n\t\tthis.path = path\r\n\t\tObject.keys(options).forEach((opt) => {\r\n\t\t\tthis[opt] = options[opt]\r\n\t\t})\r\n\t}\r\n\ttemplate: ''\r\n\thandlersDone: boolean = false\r\n\tcancelHandlers: boolean\r\n}\r\n\r\nexport default Route\r\n", "/**\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param url url to segmentize\r\n * @returns\r\n */\r\nfunction segmentize(url: string): string[] {\r\n\treturn url.replace(/(^\\/+|\\/+$)/g, '').split('/')\r\n}\r\n\r\n/**\r\n * check if a path match with this route\r\n * taken from preact-router\r\n * https://github.com/preactjs/preact-router\r\n * @param path {string}\r\n * @param routePath {string}\r\n * @returns {false|object}\r\n */\r\nexport function match(url: string, routePath: string): false | object {\r\n\tlet reg = /(?:\\?([^#]*))?(#.*)?$/,\r\n\t\tc = url.match(reg),\r\n\t\tmatches: any = {},\r\n\t\tret\r\n\tif (c && c[1]) {\r\n\t\tlet p = c[1].split('&')\r\n\t\tfor (let i = 0; i < p.length; i++) {\r\n\t\t\tlet r = p[i].split('=')\r\n\t\t\tmatches[decodeURIComponent(r[0])] = decodeURIComponent(\r\n\t\t\t\tr.slice(1).join('=')\r\n\t\t\t)\r\n\t\t}\r\n\t}\r\n\tlet urlSeg = segmentize(url.replace(reg, '')),\r\n\t\troute: string[] = segmentize(routePath || ''),\r\n\t\tmax = Math.max(urlSeg.length, route.length)\r\n\tfor (let i = 0; i < max; i++) {\r\n\t\tif (route[i] && route[i].charAt(0) === ':') {\r\n\t\t\tlet param: string = route[i].replace(/(^:|[+*?]+$)/g, ''),\r\n\t\t\t\tflags: string = (route[i].match(/[+*?]+$/) || {}).toString()[0],\r\n\t\t\t\tplus = ~flags.indexOf('+'),\r\n\t\t\t\tstar = ~flags.indexOf('*'),\r\n\t\t\t\tval = urlSeg[i] || ''\r\n\t\t\tif (!val && !star && (flags.indexOf('?') < 0 || plus)) {\r\n\t\t\t\tret = false\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t\tmatches[param] = decodeURIComponent(val)\r\n\t\t\tif (plus || star) {\r\n\t\t\t\tmatches[param] = urlSeg\r\n\t\t\t\t\t.slice(i)\r\n\t\t\t\t\t.map(decodeURIComponent)\r\n\t\t\t\t\t.join('/')\r\n\t\t\t\tbreak\r\n\t\t\t}\r\n\t\t} else if (route[i] !== urlSeg[i]) {\r\n\t\t\tret = false\r\n\t\t\tbreak\r\n\t\t}\r\n\t}\r\n\tif (ret === false) return false\r\n\treturn matches\r\n}\r\n\r\n/**\r\n * Call a function on all middlewares loaded, if any.\r\n * @param {string} func middleware function to call.\r\n * @param {any} args arguments to pass to the function.\r\n * @returns {boolean} false if the middleware function return false, i.e. it want to stop execution of the function and return.\r\n */\r\nexport function middleware(func: string, ...args: any): string | undefined {\r\n\tif (!window.PineconeRouterMiddlewares) return\r\n\tfor (const i in window.PineconeRouterMiddlewares) {\r\n\t\tlet plugin: any = window.PineconeRouterMiddlewares[i]\r\n\t\tif (plugin[func] == null) return\r\n\t\tlet ret = plugin[func](...args)\r\n\t\t// the return of the function will only be 'stop'\r\n\t\t// if the middleware request stopping the navigate function.\r\n\t\tif (ret == 'stop') return 'stop'\r\n\t}\r\n}\r\n\r\nexport function fetchError(error: string) {\r\n\tdocument.dispatchEvent(\r\n\t\tnew CustomEvent('fetch-error', { detail: error })\r\n\t)\r\n}", "import Route from './route'\r\nimport type { Settings, Context, Middleware, Handler } from './types'\r\nimport { fetchError, match, middleware } from './utils'\r\n\r\n\r\ndeclare global {\r\n\tinterface Window {\r\n\t\tPineconeRouter: {\r\n\t\t\tversion: string\r\n\t\t\tname: string\r\n\t\t\tsettings: Settings\r\n\t\t\tnotfound: Route\r\n\t\t\troutes: Route[]\r\n\t\t\tcontext: Context\r\n\t\t\tloadStart: Event\r\n\t\t\tloadEnd: Event\r\n\t\t\tadd: (path: string, options?: {}) => number\r\n\t\t\tremove: (path: string) => void\r\n\t\t}\r\n\t\tPineconeRouterMiddlewares: Array\r\n\t}\r\n\tinterface HTMLTemplateElement {\r\n\t\t_x_undoIf: Function\r\n\t\t_x_currentIfEl: Element\r\n\t}\r\n}\r\n\r\nexport default function (Alpine) {\r\n\r\n\tconst PineconeRouter = Alpine.reactive({\r\n\t\tversion: '4.1.1',\r\n\t\tname: 'pinecone-router',\r\n\r\n\t\tsettings: {\r\n\t\t\thash: false,\r\n\t\t\tbasePath: '/',\r\n\t\t\ttemplateTargetId: null\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * @description The handler for 404 pages, can be overwritten by a notfound route\r\n\t\t */\r\n\t\tnotfound: new Route('notfound'),\r\n\r\n\t\t/**\r\n\t\t * @type Route[]\r\n\t\t * @summary array of routes instantiated from the Route class.\r\n\t\t */\r\n\t\troutes: [],\r\n\r\n\t\t/**\r\n\t\t * @type {Context}\r\n\t\t * @summary The context object for current path.\r\n\t\t */\r\n\t\tcontext: {\r\n\t\t\troute: '',\r\n\t\t\tpath: '',\r\n\t\t\tparams: {},\r\n\t\t\tquery: window.location.search.substring(1),\r\n\t\t\thash: window.location.hash.substring(1),\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t},\r\n\r\n\t\t/**\r\n\t\t * Add a new route\r\n\t\t */\r\n\t\tadd(path: string, options?: {}) {\r\n\t\t\t// check if the route was registered on the same router.\r\n\t\t\tif (this.routes.find((r: Route) => r.path == path) != null) {\r\n\t\t\t\tthrow new Error('Pinecone Router: route already exist')\r\n\t\t\t}\r\n\r\n\t\t\treturn this.routes.push(new Route(path, options)) - 1\r\n\t\t},\r\n\t\t/**\r\n\t\t * Remove a route\r\n\t\t */\r\n\t\tremove(path: string) {\r\n\t\t\tthis.routes = this.routes.filter((r: Route) => r.path != path)\r\n\t\t},\r\n\t\t/**\r\n\t\t * @event pinecone-start\r\n\t\t * @summary be dispatched to the window after before page start loading.\r\n\t\t */\r\n\t\tloadStart: new Event('pinecone-start'),\r\n\r\n\t\t/**\r\n\t\t * @event pinecone-end\r\n\t\t * @summary will be dispatched to the window after the views are fetched\r\n\t\t */\r\n\t\tloadEnd: new Event('pinecone-end'),\r\n\t})\r\n\r\n\twindow.PineconeRouter = PineconeRouter\r\n\r\n\tvar loadingTemplates: { [key: string]: Promise } = {}\r\n\tvar cachedTemplates: { [key: string]: string } = {}\r\n\tconst inMakeProgress = new Set()\r\n\tvar preloadingTemplates: { [key: string]: Promise } = {}\r\n\r\n\tconst load = (el: HTMLTemplateElement, url: string) => {\r\n\t\tif (loadingTemplates[url]) {\r\n\t\t\tloadingTemplates[url].then(html => el.innerHTML = html)\r\n\t\t} else {\r\n\t\t\tloadingTemplates[url] = fetch(url).then(r => {\r\n\t\t\t\tif (!r.ok) {\r\n\t\t\t\t\tfetchError(r.statusText);\r\n\t\t\t\t\treturn null\r\n\t\t\t\t}\r\n\t\t\t\treturn r.text()\r\n\t\t\t}).then(html => {\r\n\t\t\t\tif (html == null) {\r\n\t\t\t\t\tcachedTemplates[url] = null;\r\n\t\t\t\t\tloadingTemplates[url] = null\r\n\t\t\t\t\treturn null;\r\n\t\t\t\t}\r\n\t\t\t\tcachedTemplates[url] = html\r\n\t\t\t\tel.innerHTML = html\r\n\t\t\t\treturn html\r\n\t\t\t})\r\n\t\t}\r\n\t\treturn loadingTemplates[url]\r\n\t}\r\n\r\n\tconst make = (el: HTMLTemplateElement, expression: string, targetEl?: HTMLElement) => {\r\n\t\tif (inMakeProgress.has(expression)) return\r\n\t\tinMakeProgress.add(expression)\r\n\r\n\t\tconst clone = (el.content.cloneNode(true) as HTMLElement).firstElementChild\r\n\r\n\t\tif (!clone) return\r\n\r\n\t\tAlpine.addScopeToNode(clone, {}, el)\r\n\r\n\t\tAlpine.mutateDom(() => {\r\n\t\t\tif (targetEl != null) {\r\n\t\t\t\ttargetEl.appendChild(clone)\r\n\t\t\t} else\r\n\t\t\t\tel.after(clone)\r\n\t\t\tAlpine.initTree(clone)\r\n\t\t})\r\n\r\n\t\tel._x_currentIfEl = clone\r\n\r\n\t\tel._x_undoIf = () => {\r\n\t\t\tclone.remove()\r\n\r\n\t\t\tdelete el._x_currentIfEl\r\n\t\t}\r\n\r\n\t\tAlpine.nextTick(() => inMakeProgress.delete(expression))\r\n\t}\r\n\r\n\tfunction hide(el: HTMLTemplateElement) {\r\n\t\tif (el._x_undoIf) {\r\n\t\t\tel._x_undoIf()\r\n\t\t\tdelete el._x_undoIf\r\n\t\t}\r\n\t}\r\n\r\n\tfunction show(el: HTMLTemplateElement, expression: string, url?: string, targetEl?: HTMLElement) {\r\n\t\tif (el._x_currentIfEl) return el._x_currentIfEl\r\n\t\tif (el.content.firstElementChild) {\r\n\t\t\tmake(el, expression, targetEl)\r\n\t\t\tendLoading()\r\n\t\t} else if (url) {\r\n\t\t\t// Since during loading, the content is automatically put inside the template\r\n\t\t\t// This first case will only happen if the content of the template was cleared somehow\r\n\t\t\t// Likely manually\r\n\t\t\tif (cachedTemplates[url]) {\r\n\r\n\t\t\t\tel.innerHTML = cachedTemplates[url]\r\n\t\t\t\tmake(el, expression, targetEl)\r\n\t\t\t\tendLoading()\r\n\t\t\t} else {\r\n\t\t\t\t// This second case is that it didn't finish loading\r\n\t\t\t\tif (preloadingTemplates[url]) {\r\n\t\t\t\t\tpreloadingTemplates[url].then(() => make(el, expression, targetEl))\r\n\t\t\t\t} else {\r\n\t\t\t\t\tload(el, url).then(() => make(el, expression, targetEl)).finally(() => endLoading())\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tconst startLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadStart)\r\n\t}\r\n\r\n\tconst endLoading = () => {\r\n\t\tdocument.dispatchEvent(PineconeRouter.loadEnd)\r\n\t}\r\n\r\n\tconst addBasePath = (path) => {\r\n\t\tif (!PineconeRouter.settings.hash && PineconeRouter.settings.basePath != '/') {\r\n\t\t\treturn PineconeRouter.settings.basePath + path\r\n\t\t} return path\r\n\t}\r\n\r\n\tconst findRouteIndex = (path) => {\r\n\t\treturn PineconeRouter.routes.findIndex(\r\n\t\t\t(r) => r.path == path\r\n\t\t)\r\n\t}\r\n\r\n\tAlpine.directive(\r\n\t\t'route',\r\n\t\t(el: HTMLTemplateElement, { expression }, { effect, cleanup }) => {\r\n\t\t\tlet path = expression\r\n\r\n\t\t\tmiddleware('onBeforeRouteProcessed', el, path)\r\n\r\n\t\t\tif (path.indexOf('#') > -1) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: A route's path may not have a hash character.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\r\n\t\t\tlet routeIndex = null\r\n\r\n\t\t\tif (path != 'notfound') {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// register the new route if possible\r\n\t\t\t\trouteIndex = PineconeRouter.add(path)\r\n\t\t\t}\r\n\r\n\t\t\tlet route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound\r\n\r\n\t\t\tif (el.content.firstElementChild != null) {\r\n\t\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\t\teffect(() => {\r\n\t\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == path\r\n\t\t\t\t\t\tfound ? show(el, expression) : hide(el)\r\n\t\t\t\t\t})\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t\tPineconeRouter.remove(path);\r\n\t\t\t})\r\n\r\n\t\t\tmiddleware('onAfterRouteProcessed', el, path)\r\n\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'handler',\r\n\t\t(\r\n\t\t\tel,\r\n\t\t\t{ expression },\r\n\t\t\t{ evaluate, cleanup }\r\n\t\t) => {\r\n\t\t\tif (!el.hasAttribute('x-route')) {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: x-handler must be set on the same element as x-route.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\tlet handlers\r\n\r\n\t\t\t// check if the handlers expression is an array\r\n\t\t\t// if not make it one\r\n\t\t\tif (\r\n\t\t\t\t!(expression.startsWith('[') && expression.endsWith(']')) &&\r\n\t\t\t\t!(expression.startsWith('Array(') && expression.endsWith(')'))\r\n\t\t\t) {\r\n\t\t\t\texpression = `[${expression}]`\r\n\t\t\t}\r\n\r\n\t\t\tlet evaluatedExpression = evaluate(expression)\r\n\t\t\tlet path = el.getAttribute('x-route')\r\n\r\n\t\t\tif (typeof evaluatedExpression == 'object')\r\n\t\t\t\thandlers = evaluatedExpression\r\n\t\t\telse {\r\n\t\t\t\tthrow new Error(\r\n\t\t\t\t\t`Pinecone Router: Invalid handler type: ${typeof evaluatedExpression}.`\r\n\t\t\t\t)\r\n\t\t\t}\r\n\r\n\t\t\t// add `this` context for handlers inside an Alpine.component\r\n\t\t\tfor (let index = 0; index < handlers.length; index++) {\r\n\t\t\t\thandlers[index] = handlers[index].bind(Alpine.$data(el))\r\n\t\t\t}\r\n\r\n\t\t\tlet route\r\n\r\n\t\t\tif (path == 'notfound')\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\telse {\r\n\t\t\t\t// if specified add the basePath\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\t// add handlers to the route\r\n\t\t\t\tlet i = findRouteIndex(path)\r\n\t\t\t\troute = PineconeRouter.routes[i]\r\n\t\t\t}\r\n\t\t\troute.handlers = handlers\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\troute.handlers = []\r\n\t\t\t\troute.handlersDone = true\r\n\t\t\t})\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.directive(\r\n\t\t'template',\r\n\t\t(el: HTMLTemplateElement, { modifiers, expression }, { Alpine, effect, cleanup }) => {\r\n\r\n\t\t\tif (!el.hasAttribute(\"x-route\")) throw new Error(\"Pinecone Router: x-template must be used on the same element as x-route.\")\r\n\r\n\t\t\tlet url: string = expression\r\n\r\n\t\t\tlet target = modifierValue(modifiers, 'target', null) ?? window.PineconeRouter.settings.templateTargetId\r\n\t\t\tlet targetEl = document.getElementById(target)\r\n\r\n\t\t\tif (target && !targetEl)\r\n\t\t\t\tthrow new Error(\"Pinecone Router: Can't find an element with the suplied x-template target ID (\" + target + \")\")\r\n\r\n\t\t\tif (modifiers.includes(\"preload\")) {\r\n\t\t\t\tpreloadingTemplates[url] = load(el, url).finally(() => {\r\n\t\t\t\t\tpreloadingTemplates[url] = null;\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t})\r\n\t\t\t}\r\n\r\n\t\t\tlet path = el.getAttribute(\"x-route\")\r\n\t\t\tlet route;\r\n\t\t\tlet routeIndex\r\n\r\n\t\t\tif (path == 'notfound') {\r\n\t\t\t\tPineconeRouter.notfound.template = url\r\n\t\t\t\troute = PineconeRouter.notfound\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tpath = addBasePath(path)\r\n\t\t\t\trouteIndex = findRouteIndex(path)\r\n\t\t\t\tPineconeRouter.routes[routeIndex].template = url\r\n\t\t\t\troute = PineconeRouter.routes[routeIndex]\r\n\t\t\t}\r\n\r\n\r\n\t\t\tAlpine.nextTick(() => {\r\n\t\t\t\teffect(() => {\r\n\t\t\t\t\tlet found = route.handlersDone && PineconeRouter.context.route == route.path\r\n\t\t\t\t\tfound ? show(el, expression, url, targetEl) : hide(el)\r\n\t\t\t\t})\r\n\t\t\t})\r\n\r\n\t\t\tcleanup(() => {\r\n\t\t\t\tel._x_undoIf && el._x_undoIf();\r\n\t\t\t})\r\n\r\n\t\t}\r\n\t)\r\n\r\n\tAlpine.$router = PineconeRouter.context\r\n\tAlpine.magic('router', () => PineconeRouter.context)\r\n\r\n\tdocument.addEventListener('alpine:initialized', () => {\r\n\t\tmiddleware('init')\r\n\t\t// virtually navigate the path on the first page load\r\n\t\t// this will register the path in history and sets the pathvariable\r\n\t\t// navigate(window.location.pathname, false, true)\r\n\t\tif (PineconeRouter.settings.hash == false) {\r\n\t\t\t// navigate to the current page to handle it\r\n\t\t\t// ONLY if we not using hash routing for the default router\r\n\t\t\tnavigate(location.pathname, false, true)\r\n\t\t} else {\r\n\t\t\tnavigate(location.hash.substring(1), false, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// handle navigation events not emitted by links, for example, back button.\r\n\twindow.addEventListener('popstate', () => {\r\n\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\tif (window.location.hash != '') {\r\n\t\t\t\tnavigate(window.location.hash.substring(1), true)\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\tnavigate(window.location.pathname, true)\r\n\t\t}\r\n\t})\r\n\r\n\t// intercept click event in links\r\n\tinterceptLinks()\r\n\r\n\t/**\r\n\t * @description Add a handler to click events on all valid links\r\n\t */\r\n\tfunction interceptLinks() {\r\n\t\tfunction validateLink(node) {\r\n\t\t\t// only valid elements\r\n\t\t\tif (!node || !node.getAttribute) return;\r\n\r\n\t\t\tlet href = node.getAttribute('href'),\r\n\t\t\t\ttarget = node.getAttribute('target');\r\n\r\n\t\t\t// ignore links with targets and non-path URLs\r\n\t\t\tif (!href || !href.match(/^\\//g) || (target && !target.match(/^_?self$/i)))\r\n\t\t\t\treturn;\r\n\r\n\t\t\tif (typeof href !== 'string' && href.url) {\r\n\t\t\t\thref = href.url;\r\n\t\t\t}\r\n\t\t\treturn href\r\n\r\n\t\t}\r\n\t\twindow.document.body.addEventListener(\r\n\t\t\t'click',\r\n\t\t\tfunction (e: any) {\r\n\t\t\t\tif (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button || e.defaultPrevented) return;\r\n\r\n\r\n\t\t\t\tlet currentRoute = PineconeRouter.routes[findRouteIndex(PineconeRouter.context.route)] ?? PineconeRouter.notfound\r\n\r\n\t\t\t\t// stop handlers in progress before navigating to the next page\r\n\t\t\t\tif (!currentRoute.handlersDone) {\r\n\t\t\t\t\tcurrentRoute.cancelHandlers = true\r\n\t\t\t\t\tendLoading()\r\n\t\t\t\t}\r\n\r\n\t\t\t\tlet node = e.target;\r\n\r\n\t\t\t\tdo {\r\n\t\t\t\t\tif (node.localName === 'a' && node.getAttribute('href')) {\r\n\t\t\t\t\t\tif (node.hasAttribute('data-native') || node.hasAttribute('native')) return;\r\n\t\t\t\t\t\tlet href = validateLink(node)\r\n\t\t\t\t\t\tif (href) {\r\n\t\t\t\t\t\t\tnavigate(href)\r\n\t\t\t\t\t\t\tif (e.stopImmediatePropagation) e.stopImmediatePropagation();\r\n\t\t\t\t\t\t\tif (e.stopPropagation) e.stopPropagation();\r\n\t\t\t\t\t\t\te.preventDefault();\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbreak;\r\n\t\t\t\t\t}\r\n\t\t\t\t} while ((node = node.parentNode));\r\n\t\t\t}\r\n\t\t)\r\n\t}\r\n\r\n\t/**\r\n\t * Go to the specified path without reloading\r\n\t * @param {string} path the path with no hash even if using hash routing\r\n\t * @param {boolean} fromPopState this will be set to true if called from window.onpopstate event\r\n\t * @param {boolean} firstLoad this will be set to true if this is the first page loaded, also from page reload\r\n\t */\r\n\tasync function navigate(path, fromPopState = false, firstLoad = false) {\r\n\t\tif (!path) path = '/'\r\n\t\tPineconeRouter.context.path = path\r\n\r\n\t\t// only add basePath if it was set\r\n\t\t// if not using hash routing\r\n\t\t// and if it wasn't added already\r\n\t\tif (!PineconeRouter.settings.hash) {\r\n\t\t\tif (\r\n\t\t\t\tPineconeRouter.settings.basePath != '/' &&\r\n\t\t\t\t!path.startsWith(PineconeRouter.settings.basePath)\r\n\t\t\t) {\r\n\t\t\t\tpath = PineconeRouter.settings.basePath + path\r\n\t\t\t}\r\n\t\t\tif (\r\n\t\t\t\tpath == PineconeRouter.settings.basePath &&\r\n\t\t\t\t!path.endsWith('/')\r\n\t\t\t) {\r\n\t\t\t\tpath += '/'\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst route: Route = PineconeRouter.routes.find(\r\n\t\t\t(route: Route) => {\r\n\t\t\t\tlet m = match(path, route.path)\r\n\t\t\t\troute.params = m != false ? m : {}\r\n\t\t\t\treturn m != false\r\n\t\t\t}\r\n\t\t) ?? PineconeRouter.notfound\r\n\r\n\t\t// if the route has handlres, it will mark them unhandled\r\n\t\t// this is so templates wont render till then.\r\n\t\troute.handlersDone = !route.handlers.length\r\n\r\n\t\tif (route.handlers.length || route.template) {\r\n\t\t\tstartLoading()\r\n\t\t}\r\n\r\n\t\tlet context = buildContext(route.path, path, route.params)\r\n\r\n\t\tPineconeRouter.context = context\r\n\r\n\t\t// the middleware may return 'stop' to stop execution of this function\r\n\t\tif (\r\n\t\t\tmiddleware('onBeforeHandlersExecuted', route, path, firstLoad) == 'stop'\r\n\t\t) {\r\n\t\t\tendLoading()\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\r\n\t\t// do not call pushstate from popstate event https://stackoverflow.com/a/50830905\r\n\t\tif (!fromPopState) {\r\n\t\t\tlet fullPath = ''\r\n\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\tfullPath = '#'\r\n\t\t\t\tfullPath += window.location.search + path\r\n\t\t\t} else {\r\n\t\t\t\tfullPath = path + window.location.search + window.location.hash\r\n\t\t\t}\r\n\t\t\t// don't create duplicate history entry on first page load\r\n\t\t\tif (!firstLoad) history.pushState({ path: fullPath }, '', fullPath)\r\n\t\t\telse {\r\n\t\t\t\tif (PineconeRouter.settings.hash) {\r\n\t\t\t\t\tif (path == '/') {\r\n\t\t\t\t\t\tPineconeRouter.context = context\r\n\t\t\t\t\t\treturn navigate('/', false, false)\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif (\r\n\t\t\t(route && route.handlers.length)\r\n\t\t) {\r\n\t\t\troute.cancelHandlers = false\r\n\t\t\tlet ok = await handle(route.handlers, context)\r\n\t\t\tif (!ok) {\r\n\t\t\t\tendLoading()\r\n\t\t\t\treturn\r\n\t\t\t}\r\n\t\t\troute.handlersDone = true\r\n\t\t\tif (!route.template) endLoading()\r\n\t\t}\r\n\r\n\r\n\t\tmiddleware('onHandlersExecuted', route, path, firstLoad)\r\n\t}\r\n\r\n\tfunction buildContext(route: string, path: string, params: {}): Context {\r\n\t\treturn {\r\n\t\t\troute: route,\r\n\t\t\tpath: path,\r\n\t\t\tparams: params,\r\n\t\t\tquery: window.location.search.substring(1), // query w/out leading '?'\r\n\t\t\thash: window.location.hash.substring(1), // hash without leading '#'\r\n\t\t\tredirect(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t\treturn 'stop'\r\n\t\t\t},\r\n\t\t\tnavigate(path) {\r\n\t\t\t\tnavigate(path)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction modifierValue(modifiers, key, fallback) {\r\n\t\t// If the modifier isn't present, use the default.\r\n\t\tif (modifiers.indexOf(key) === -1) return fallback\r\n\r\n\t\t// If it IS present, grab the value after it\r\n\t\tconst rawValue = modifiers[modifiers.indexOf(key) + 1]\r\n\r\n\t\tif (!rawValue) return fallback\r\n\r\n\t\tif (key === 'target') {\r\n\t\t\tlet match = rawValue.match(/([a-z0-9_-]+)/)\r\n\t\t\tif (match) return match[1]\r\n\t\t}\r\n\t\treturn rawValue\r\n\t}\r\n\t/**\r\n\t * execute the handlers of routes that are given passing them the context.\r\n\t */\r\n\tasync function handle(handlers, context) {\r\n\t\tfor (let i = 0; i < handlers.length; i++) {\r\n\t\t\tif (typeof handlers[i] == 'function') {\r\n\t\t\t\t// stop if the handlers were canceled for example the user clicked a link\r\n\t\t\t\tlet route = PineconeRouter.routes[findRouteIndex(context.route)] ?? PineconeRouter.notfound\r\n\t\t\t\tif (route.cancelHandlers) {\r\n\t\t\t\t\troute.cancelHandlers = false\r\n\t\t\t\t\treturn false\r\n\t\t\t\t}\r\n\t\t\t\tlet result\r\n\t\t\t\tif (handlers[i].constructor.name === 'AsyncFunction')\r\n\t\t\t\t\tresult = await handlers[i](context)\r\n\t\t\t\telse\r\n\t\t\t\t\tresult = handlers[i](context)\r\n\t\t\t\t// if the handler redirected, return\r\n\t\t\t\tif (result == 'stop') return false\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\n", "import magic from '../src/index.js'\r\n\r\ndocument.addEventListener('alpine:init', () => {\r\n window.Alpine.plugin(magic)\r\n})\r\n"], + "mappings": "MAEA,IAAMA,EAAN,KAAY,CAIX,YAAYC,EAAcC,EAAU,CAAC,EAAG,CAHxC,YAAiC,CAAC,EAElC,cAAsB,CAAC,EAQvB,kBAAwB,GANvB,KAAK,KAAOD,EACZ,OAAO,KAAKC,CAAO,EAAE,QAASC,GAAQ,CACrC,KAAKA,GAAOD,EAAQC,EACrB,CAAC,CACF,CAID,EAEOC,EAAQJ,ECXf,SAASK,EAAWC,EAAuB,CAC1C,OAAOA,EAAI,QAAQ,eAAgB,EAAE,EAAE,MAAM,GAAG,CACjD,CAUO,SAASC,EAAMD,EAAaE,EAAmC,CACrE,IA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,EAAU,CAEhD,GAAIlB,EAAU,QAAQiB,CAAG,IAAM,GAAI,OAAOC,EAG1C,IAAMC,EAAWnB,EAAUA,EAAU,QAAQiB,CAAG,EAAI,GAEpD,GAAI,CAACE,EAAU,OAAOD,EAEtB,GAAID,IAAQ,SAAU,CACrB,IAAIN,EAAQQ,EAAS,MAAM,eAAe,EAC1C,GAAIR,EAAO,OAAOA,EAAM,EACzB,CACA,OAAOQ,CACR,CAIA,eAAeJ,EAAOnB,EAAUgB,EAAS,CACxC,QAASb,EAAI,EAAGA,EAAIH,EAAS,OAAQG,IACpC,GAAI,OAAOH,EAASG,IAAM,WAAY,CAErC,IAAIL,EAAQ7B,EAAe,OAAOwB,EAAeuB,EAAQ,KAAK,IAAM/C,EAAe,SACnF,GAAI6B,EAAM,eACT,OAAAA,EAAM,eAAiB,GAChB,GAER,IAAI0B,EAMJ,GALIxB,EAASG,GAAG,YAAY,OAAS,gBACpCqB,EAAS,MAAMxB,EAASG,GAAGa,CAAO,EAElCQ,EAASxB,EAASG,GAAGa,CAAO,EAEzBQ,GAAU,OAAQ,MAAO,EAC9B,CAED,MAAO,EACR,CACD,CCxlBA,SAAS,iBAAiB,cAAe,IAAM,CAC7C,OAAO,OAAO,OAAOC,CAAK,CAC5B,CAAC", "names": ["Route", "path", "options", "opt", "route_default", "segmentize", "url", "match", "routePath", "reg", "c", "matches", "ret", "p", "i", "r", "urlSeg", "route", "max", "param", "flags", "plus", "star", "val", "middleware", "func", "args", "plugin", "fetchError", "error", "src_default", "Alpine", "PineconeRouter", "route_default", "path", "navigate", "options", "r", "loadingTemplates", "cachedTemplates", "inMakeProgress", "preloadingTemplates", "load", "el", "url", "html", "fetchError", "make", "expression", "targetEl", "clone", "hide", "show", "endLoading", "startLoading", "addBasePath", "findRouteIndex", "effect", "cleanup", "middleware", "routeIndex", "route", "evaluate", "handlers", "evaluatedExpression", "index", "i", "modifiers", "target", "modifierValue", "interceptLinks", "validateLink", "node", "href", "currentRoute", "fromPopState", "firstLoad", "m", "match", "context", "buildContext", "fullPath", "handle", "params", "key", "fallback", "rawValue", "result", "src_default"] } diff --git a/package.json b/package.json index ee3ec0d..181dc47 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "The extendable client-side router for Alpine.js.", "license": "MIT", "author": "Rafik El Hadi Houari ", - "version": "4.1.0", + "version": "4.1.1", "repository": { "type": "git", "url": "https://github.com/pinecone-router/router" diff --git a/src/index.ts b/src/index.ts index d0c1917..55d1813 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,7 +28,7 @@ declare global { export default function (Alpine) { const PineconeRouter = Alpine.reactive({ - version: '4.1.0', + version: '4.1.1', name: 'pinecone-router', settings: { @@ -167,7 +167,7 @@ export default function (Alpine) { function show(el: HTMLTemplateElement, expression: string, url?: string, targetEl?: HTMLElement) { if (el._x_currentIfEl) return el._x_currentIfEl if (el.content.firstElementChild) { - make(el, expression) + make(el, expression, targetEl) endLoading() } else if (url) { // Since during loading, the content is automatically put inside the template @@ -234,12 +234,7 @@ export default function (Alpine) { let route = PineconeRouter.routes[routeIndex] ?? PineconeRouter.notfound - // this will show inline templates, you can't mix inline and x-template - // so we check if we already have x-template - // this is due to x-template also putting the template inside el.content.firstElementChild - // so we omit the x-template this code will run both here and in x-template directive - // and also x-template.target will not work! - if (!el.hasAttribute('x-template') && el.content.firstElementChild != null) { + if (el.content.firstElementChild != null) { Alpine.nextTick(() => { effect(() => { let found = route.handlersDone && PineconeRouter.context.route == path @@ -334,7 +329,10 @@ export default function (Alpine) { throw new Error("Pinecone Router: Can't find an element with the suplied x-template target ID (" + target + ")") if (modifiers.includes("preload")) { - preloadingTemplates[url] = load(el, url).finally(() => preloadingTemplates[url] = null) + preloadingTemplates[url] = load(el, url).finally(() => { + preloadingTemplates[url] = null; + endLoading() + }) } let path = el.getAttribute("x-route")