@devwareng/vanilla-ts 1.3.6 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +49 -49
package/dist/index.cjs
CHANGED
|
@@ -83,7 +83,7 @@ export function createRouter(DOM: HTMLElement) {
|
|
|
83
83
|
|
|
84
84
|
return { navigate, routes: routeTree }
|
|
85
85
|
}
|
|
86
|
-
`;M.default.writeFileSync(ge,a,"utf-8"),console.log("\u2705 Generated:",ge)}A()
|
|
86
|
+
`;M.default.writeFileSync(ge,a,"utf-8"),console.log("\u2705 Generated:",ge)}typeof process<"u"&&process.versions?.node&&(A(),console.log("\u{1F440} Watching for changes in /src/pages..."),pe.watch(O).on("add",s=>{if(s.endsWith(".ts")){let t=P.default.basename(s,".ts"),e=t.replace(/\[|\]/g,"Param").replace(/(^\w|-\w)/g,r=>r.replace("-","").toUpperCase());M.default.readFileSync(s,"utf-8").trim()||(M.default.writeFileSync(s,ps(e),"utf-8"),console.log(`\u{1F4DD} Scaffolded page: ${t}.ts`))}A()}).on("unlink",()=>A()).on("change",()=>A()));var zt=y(require("dompurify"),1);var we=require("zustand/vanilla"),Te=y(require("dompurify"),1),L=(0,we.createStore)(s=>({params:{},query:{},setParams:t=>s(()=>({params:ye(t)})),setQuery:t=>s(()=>({query:ye(t)}))}));function ye(s){let t={};for(let e in s)t[e]=Te.default.sanitize(s[e]);return t}var et=class{constructor(t,e){this.routes=[];this.routes=t,this.expectedParams=new Set(e),window.addEventListener("popstate",this.handlePopState.bind(this)),this.handlePopState()}handlePopState(){let t=window.location.pathname,e=window.location.search,n=this.parseQueryParams(e),r=this.findMatchingRoute(t,this.routes);if(r){if(r.routeto){this.navigate(r.routeto);return}let i=this.filterAndSanitizeParams(r.params);L.getState().setParams(i),L.getState().setQuery(n);let a=document.createElement("div");if(r.element?.(a,i,n),r.children){let o=t.slice(r.path.length),c=a.querySelector("#child");c&&this.renderChildren(r.children,o,c,i,n)}}else{let i=this.findMatchingRoute("*",this.routes);if(i){let a=this.filterAndSanitizeParams(i.params);L.getState().setParams(a),L.getState().setQuery(n);let o=document.createElement("div");i.element?.(o,a,n)}}}renderChildren(t,e,n,r,i){if(!t||t.length===0){let o=n.querySelector("#child");o&&o.remove();return}let a=this.findMatchingRoute(e,t);if(a){let o=document.createElement("div");o.id="child";let c={...r,...a.params},l=this.filterAndSanitizeParams(c);if(L.getState().setParams(l),L.getState().setQuery(i),a.element?.(o,l,i),n.appendChild(o),a.children){let d=e.slice(a.path.length);this.renderChildren(a.children,d,o,l,i)}}}parseQueryParams(t){let e={},n=new URLSearchParams(t);for(let[r,i]of n.entries())this.expectedParams.has(r)&&(e[r]=zt.default.sanitize(i));return e}findMatchingRoute(t,e,n={}){for(let r of e){let i=r.path;if(i==="*")return r;{let o=[],c=i.replace(/:[^\s/]+/g,h=>(o.push(h.substring(1)),"([^\\s/]+)")),l=new RegExp(`^${c}(?:/|$)`),d=t.match(l);if(d){let h={...n};if(o.forEach((u,m)=>{h[u]=d[m+1]??""}),r.children){let u=t.slice(d[0].length),m=this.findMatchingRoute(u,r.children,h);if(m)return m}return{...r,params:h}}}}}filterAndSanitizeParams(t){if(!t)return{};let e={};for(let n in t)this.expectedParams.has(n)&&(e[n]=zt.default.sanitize(t[n]??""));return e}navigate(t){history.pushState(null,"",t),this.handlePopState()}addRoute(t){this.routes.push(t)}};typeof window<"u"&&(window.addEventListener("popstate",()=>{U()}),document.addEventListener("DOMContentLoaded",U));0&&(module.exports={TSRouter,createEffect,createSignal,html,loadPyFiles,mapper,renderChildRoutes,useAnchor,useAnchorSingle,useInitialDOM,useTSAnchorMount,useTSAuth,useTSCollection,useTSComponent,useTSElementEach,useTSElements,useTSEvent,useTSEventAll,useTSExtractParams,useTSFilebasedRouter,useTSHashAnchor,useTSLazy,useTSMetaData,useTSNavigate,useTSNoReload,useTSOutlet,useTSParams,useTSPurifier,useTSSSRHydration,useTSSelect,useTSloadBrython});
|
|
87
87
|
/*! Bundled license information:
|
|
88
88
|
|
|
89
89
|
chokidar/esm/index.js:
|