@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.85
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/cdn/core.global.js +2 -1
- package/dist/cli/generate.cjs +4117 -292
- package/dist/cli/generate.mjs +4122 -292
- package/dist/cli/index.cjs +4117 -292
- package/dist/cli/index.mjs +4122 -292
- package/dist/cli/run.cjs +63 -1
- package/dist/cli/run.mjs +39 -1
- package/dist/src/cdn/chunk-MDJLC3PE.mjs +830 -0
- package/dist/src/cdn/core.cjs +1365 -1
- package/dist/src/cdn/core.d.ts +3 -3
- package/dist/src/cdn/core.js +3 -3
- package/dist/src/cdn/core.mjs +642 -1
- package/dist/src/cdn/router-JYFZP3EZ.mjs +70 -0
- package/dist/src/index.cjs +1280 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1393 -1
- package/dist/src/jsx-dev-runtime.cjs +26 -1
- package/dist/src/jsx-dev-runtime.mjs +24 -1
- package/dist/src/jsx-runtime.cjs +26 -1
- package/dist/src/jsx-runtime.js +0 -9
- package/dist/src/jsx-runtime.mjs +24 -1
- package/dist/src/lib/client/chunk-7IUN2FLI.mjs +133 -0
- package/dist/src/lib/client/index.cjs +956 -1
- package/dist/src/lib/client/index.d.ts +17 -6
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +26 -19
- package/dist/src/lib/client/index.mjs +222 -1
- package/dist/src/lib/client/router-NOFEMOEH.mjs +631 -0
- package/dist/src/lib/context/context.cjs +118 -1
- package/dist/src/lib/context/context.d.ts +19 -37
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +8 -45
- package/dist/src/lib/context/context.mjs +99 -1
- package/dist/src/lib/context/index.cjs +120 -1
- package/dist/src/lib/context/index.mjs +99 -1
- package/dist/src/lib/control-flow.cjs +35 -1
- package/dist/src/lib/control-flow.mjs +25 -1
- package/dist/src/lib/core.cjs +1279 -1
- package/dist/src/lib/core.d.ts +0 -2
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +14 -48
- package/dist/src/lib/core.mjs +1393 -1
- package/dist/src/lib/env/index.cjs +60 -1
- package/dist/src/lib/env/index.d.ts +5 -5
- package/dist/src/lib/env/index.js +5 -5
- package/dist/src/lib/env/index.mjs +39 -1
- package/dist/src/lib/i18n/index.cjs +108 -1
- package/dist/src/lib/i18n/index.d.ts +31 -10
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +31 -10
- package/dist/src/lib/i18n/index.mjs +88 -1
- package/dist/src/lib/index.cjs +633 -1
- package/dist/src/lib/index.d.ts +0 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +5 -11
- package/dist/src/lib/index.mjs +721 -1
- package/dist/src/lib/isomorphic.cjs +85 -1
- package/dist/src/lib/isomorphic.d.ts +41 -8
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +38 -5
- package/dist/src/lib/isomorphic.mjs +64 -1
- package/dist/src/lib/jsx-runtime/index.cjs +21 -1
- package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
- package/dist/src/lib/jsx-runtime/index.js +1 -11
- package/dist/src/lib/jsx-runtime/index.mjs +4 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
- package/dist/src/lib/plugins/index.cjs +311 -8
- package/dist/src/lib/plugins/index.mjs +279 -8
- package/dist/src/lib/plugins/route-codegen.cjs +73 -8
- package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-codegen.js +4 -5
- package/dist/src/lib/plugins/route-codegen.mjs +52 -8
- package/dist/src/lib/plugins/route-scanner.cjs +189 -1
- package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-scanner.js +7 -8
- package/dist/src/lib/plugins/route-scanner.mjs +158 -1
- package/dist/src/lib/plugins/vite.cjs +27 -1
- package/dist/src/lib/plugins/vite.mjs +6 -1
- package/dist/src/lib/render/await.cjs +38 -1
- package/dist/src/lib/render/await.d.ts +18 -0
- package/dist/src/lib/render/await.d.ts.map +1 -1
- package/dist/src/lib/render/await.js +20 -2
- package/dist/src/lib/render/await.mjs +17 -1
- package/dist/src/lib/render/component.cjs +221 -1
- package/dist/src/lib/render/component.d.ts +3 -44
- package/dist/src/lib/render/component.d.ts.map +1 -1
- package/dist/src/lib/render/component.js +23 -55
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.js +5 -5
- package/dist/src/lib/render/deferred.mjs +158 -1
- package/dist/src/lib/render/index.cjs +573 -1
- package/dist/src/lib/render/index.d.ts +3 -17
- package/dist/src/lib/render/index.d.ts.map +1 -1
- package/dist/src/lib/render/index.js +8 -22
- package/dist/src/lib/render/index.mjs +590 -1
- package/dist/src/lib/render/lazy.cjs +67 -1
- package/dist/src/lib/render/lazy.d.ts +22 -1
- package/dist/src/lib/render/lazy.d.ts.map +1 -1
- package/dist/src/lib/render/lazy.js +26 -5
- package/dist/src/lib/render/lazy.mjs +50 -1
- package/dist/src/lib/render/suspense.cjs +141 -1
- package/dist/src/lib/render/suspense.d.ts +40 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -1
- package/dist/src/lib/render/suspense.js +46 -6
- package/dist/src/lib/render/suspense.mjs +136 -1
- package/dist/src/lib/render/versions.cjs +35 -1
- package/dist/src/lib/render/versions.js +6 -6
- package/dist/src/lib/render/versions.mjs +14 -1
- package/dist/src/lib/router/data.cjs +230 -1
- package/dist/src/lib/router/data.d.ts +1 -13
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +0 -12
- package/dist/src/lib/router/data.mjs +214 -1
- package/dist/src/lib/router/index.cjs +709 -1
- package/dist/src/lib/router/index.d.ts +78 -23
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +161 -37
- package/dist/src/lib/router/index.mjs +722 -1
- package/dist/src/lib/router/transition.cjs +75 -0
- package/dist/src/lib/router/transition.d.ts +81 -0
- package/dist/src/lib/router/transition.d.ts.map +1 -0
- package/dist/src/lib/router/transition.js +136 -0
- package/dist/src/lib/router/transition.mjs +54 -0
- package/dist/src/lib/server/hydration.cjs +169 -1
- package/dist/src/lib/server/hydration.d.ts +15 -55
- package/dist/src/lib/server/hydration.d.ts.map +1 -1
- package/dist/src/lib/server/hydration.js +23 -62
- package/dist/src/lib/server/hydration.mjs +148 -1
- package/dist/src/lib/server/index.cjs +401 -11
- package/dist/src/lib/server/index.d.ts +30 -6
- package/dist/src/lib/server/index.d.ts.map +1 -1
- package/dist/src/lib/server/index.js +34 -11
- package/dist/src/lib/server/index.mjs +379 -11
- package/dist/src/lib/server/reactive.cjs +197 -1
- package/dist/src/lib/server/reactive.d.ts +18 -77
- package/dist/src/lib/server/reactive.d.ts.map +1 -1
- package/dist/src/lib/server/reactive.js +19 -78
- package/dist/src/lib/server/reactive.mjs +176 -1
- package/dist/src/lib/theme/index.cjs +110 -1
- package/dist/src/lib/theme/index.d.ts +19 -4
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +17 -2
- package/dist/src/lib/theme/index.mjs +89 -1
- package/dist/src/lib/utils/index.cjs +209 -1
- package/dist/src/lib/utils/index.d.ts +0 -93
- package/dist/src/lib/utils/index.d.ts.map +1 -1
- package/dist/src/lib/utils/index.js +0 -93
- package/dist/src/lib/utils/index.mjs +188 -1
- package/dist/src/routes.cjs +37 -1
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/routes.js +2 -2
- package/dist/src/routes.mjs +17 -1
- package/dist/src/server.cjs +400 -11
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/server.mjs +377 -11
- package/dist/src/utils.cjs +21 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.mjs +4 -1
- package/dist/src/version.generated.cjs +26 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +2 -2
- package/dist/src/version.generated.mjs +5 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +2 -14
- package/dist/src/cdn/chunk-55BT3H6E.mjs +0 -1
- package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
- package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
- package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
|
@@ -1 +1,709 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var ae=(e,n)=>{for(var t in n)P(e,t,{get:n[t],enumerable:!0})},ie=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of re(n))!oe.call(e,r)&&r!==t&&P(e,r,{get:()=>n[r],enumerable:!(a=ne(n,r))||a.enumerable});return e};var se=e=>ie(P({},"__esModule",{value:!0}),e);var Ee={};ae(Ee,{A:()=>De,Form:()=>Ne,Link:()=>Q,Outlet:()=>Te,Redirect:()=>ve,Router:()=>xe,action:()=>S,cache:()=>_,createAsync:()=>F,createBrowserHistory:()=>m.createBrowserHistory,createMemoryHistory:()=>m.createMemoryHistory,lazy:()=>$,matchPath:()=>m.matchPath,matchRoutes:()=>m.matchRoutes,preloadRoutes:()=>Me,revalidate:()=>V,runWithOwner:()=>Z.runWithOwner,select:()=>Se,useAction:()=>K,useLevelParams:()=>Re,useLinkNavigation:()=>ke,useLocation:()=>O,useMatch:()=>Ae,useNavigate:()=>G,useParam:()=>Pe,useParamSelector:()=>be,useParams:()=>k,useRouteData:()=>Oe,useRouter:()=>R,useSearchParams:()=>we,useSubmission:()=>I});module.exports=se(Ee);var i=require("@fluixi/reactive/signal"),c=require("@fluixi/dom"),l=require("@fluixi/reactive/signal"),W=require("@fluixi/utils/object"),q=require("@fluixi/utils/compare"),y=require("@fluixi/router"),m=require("@fluixi/router");var T=require("@fluixi/reactive/signal");var ce=!1,b=new Map;function L(){return ce}function D(e,n){b.set(e,n)}function N(e){return b.get(e)}function ue(){b.clear()}function de(){if(typeof window>"u")return;let e=document.getElementById("__FLUIXI_HYDRATION__");e&&e.remove();let n=document.createTreeWalker(document.body,NodeFilter.SHOW_COMMENT,null),t=[],a;for(;a=n.nextNode();){let r=a,o=r.nodeValue||"";(o.startsWith("#")||o.startsWith("/"))&&t.push(r)}t.forEach(r=>r.remove()),ue()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(de,100)});function M(){return typeof window>"u"}var E=require("@fluixi/dom"),A=require("@fluixi/reactive/signal"),le=require("@fluixi/reactive/signal");function H(e,n){let t=(0,A.createContext)(e,n),a=r=>(r.debug,t.Provider({value:r.value,get children(){return r.children},debug:r.debug}));return typeof Symbol<"u"&&Symbol.for&&(a.$$typeof=Symbol.for("react.provider")),a.$$typeof=Symbol.for("react.provider"),{id:t.id,Provider:(0,E.asProvider)(a),defaultValue:e}}var x=new Map,h=new Map;function _(e,n){return async(...t)=>{let a=n+":"+JSON.stringify(t);if(L()||typeof window<"u"){let o=N(a);if(o!==void 0)return o}if(x.has(a))return x.get(a);if(h.has(a))return h.get(a);let r=Promise.resolve(e(...t)).then(o=>(x.set(a,o),h.delete(a),M()&&D(a,o),o),o=>{throw h.delete(a),o});return h.set(a,r),r}}var[$e,fe]=(0,T.createSignal)(0),pe=new Set;function V(e){let n=typeof e=="string"?t=>t.startsWith(e):e;for(let t of x.keys())n(t)&&(x.delete(t),pe.add(t));fe(t=>t+1)}function F(e,n){let[t]=(0,T.createResource)(n||(()=>!0),e);return t}var w=new Map;function j(e){return w.has(e)||w.set(e,(0,T.createSignal)(void 0)),w.get(e)}function S(e,n){let t=n||e.name||"action",a=async r=>{let[,o]=j(t),s=()=>o(void 0),u=()=>a(r);o({input:r,pending:!0,clear:s,retry:u});try{let d=await e(r);return o({input:r,result:d,pending:!1,clear:s,retry:u}),d}catch(d){throw o({input:r,error:d,pending:!1,clear:s,retry:u}),d}};return a.url=t,a.with=r=>S((...o)=>e(r,...o),n),a}function I(e){let[n]=j(e.url);return n}function K(e){return e}var ye=H(void 0,"route-data"),We=ye.Provider;var U=require("@fluixi/dom"),g=require("@fluixi/reactive/signal");function z(e){if(e!=null&&(typeof e=="object"||typeof e=="function"))try{e.$lazy=!0}catch{}return e}function $(e,n){let t,a,r;function o(){return a||(a=e().then(u=>t=u.default)),a}n?.preload&&o();let s=(u=>{if(t){let d=t;return z((0,g.untrack)(()=>d(u)))}if(!r){let[d]=(0,g.createResource)(()=>o(),{transport:!1});if(r=d,d.error)throw d.error}return(0,g.createMemo)(()=>{let d=r();return d?z((0,U.createComponent)(d,u)):void 0})});return s.preload=()=>o().then(()=>{}),s.$lazy=!0,s.loader=e,s}var Z=require("@fluixi/reactive/signal"),v=(0,l.createContext)(void 0,"router"),B=(0,l.createContext)(void 0,"outlet"),J=(0,l.createContext)(void 0,"route-params"),X=(0,l.createContext)(void 0,"route-data");function me(e,n,t){let a,r=e.route.data;if(typeof r=="function"){let C=!1;(0,i.onCleanup)(()=>{C=!0});let ee=(0,i.getOwner)(),[te]=(0,i.createResource)(()=>r({params:t.params,location:t.location},ee,()=>C));a=te}let o=()=>X.Provider({value:a,get children(){return J.Provider({value:e.params,get children(){return B.Provider({value:{depth:n,...t},get children(){return(0,c.createComponent)(e.component,{})}})}})}});if(!a)return o();let s=a,u=()=>s.loading,[d,p]=(0,i.createSignal)((0,i.untrack)(()=>!u()));return(0,i.createEffect)(()=>p(!u())),(0,i.createMemo)(()=>d()?o():null)}function Y(e){let n=e.depth+1,[t,a]=(0,i.createSignal)((0,i.untrack)(()=>e.matched()[n]?.component));return(0,i.createEffect)(()=>{let r=e.matched()[n]?.component;a(()=>r)}),(0,i.createMemo)(()=>{if(!t())return e.notFound?e.notFound():null;let o=(0,i.untrack)(()=>e.matched())[n];return me(o,n,{matched:e.matched,params:e.params,location:e.location})})}function ge(e){return e==null?he():typeof e=="function"?(0,c.createComponent)(e,{}):e}function he(){let e=(0,c.createNativeElement)("div");(0,c.setAttribute)(e,"class","fx-not-found"),(0,c.setAttribute)(e,"role","main"),(0,c.setAttribute)(e,"style","min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif");let n=(0,c.createNativeElement)("h1");(0,c.setAttribute)(n,"style","margin:0;font-size:2.5rem;font-weight:700"),(0,c.insert)(n,"404");let t=(0,c.createNativeElement)("p");return(0,c.setAttribute)(t,"style","margin:0;opacity:.7"),(0,c.insert)(t,"This page could not be found."),e.appendChild(n),e.appendChild(t),e}function xe(e){let n=e.history??(0,y.createBrowserHistory)(),t=(0,y.createRouter)({routes:e.routes,base:e.base,history:n}),[a,r]=(0,i.createSignal)(t.state()),o=t.subscribe(r);(0,i.onCleanup)(()=>{o(),t.destroy()});let s=(0,i.createMemo)(()=>(a().match?.matched??[]).filter(C=>C.component)),u={router:t,location:(0,i.createMemo)(()=>a().location),params:(0,i.createMemo)(()=>a().match?.params??{})},d={depth:-1,matched:s,params:u.params,location:u.location,notFound:()=>ge(e.notFound)},p;return v.Provider({value:u,get children(){return p??=Y(d)}})}function Te(){let e=(0,l.useContext)(B);return e?Y(e):null}function ve(e){let n=(0,l.useContext)(v);if(n&&typeof window<"u"){let t=!1;(0,i.onCleanup)(()=>t=!0),queueMicrotask(()=>{t||n.router.navigate(e.to,{replace:e.replace!==!1})})}return null}var Ce={router:{navigate:()=>{}},location:()=>({pathname:"",search:"",hash:"",query:{}}),params:()=>({})};function R(){let e=(0,l.useContext)(v);if(e)return e;if(typeof window>"u")return Ce;throw new Error("[router] useRouter must be used within <Router>")}function k(){let e=R().params;return(0,i.createMemo)(()=>e(),{},{equals:(n,t)=>JSON.stringify(n)===JSON.stringify(t)})}function Re(){return(0,l.useContext)(J)??{}}function Pe(e){let n=k();return(0,i.createMemo)(()=>n()[e])}function be(e,n){let t=k();return(0,i.createMemo)(()=>e(t()),void 0,n?{equals:n}:void 0)}function Ae(e){let n=O();return(0,i.createMemo)(()=>(0,y.matchPath)(typeof e=="function"?e():e,n.pathname))}function we(){let e=O(),n=G();return[(0,i.createMemo)(()=>e.query),(r,o)=>{let s=new URLSearchParams(e.search);for(let[d,p]of Object.entries(r))p===null?s.delete(d):s.set(d,p);let u=s.toString();n(e.pathname+(u?`?${u}`:""),o)}]}function Se(e,n){let t=(a,r)=>(0,q.deepEqual)(a,r);return n!==void 0?(0,i.createMemo)(()=>(0,W.get)(e(),n),void 0,{equals:t}):(0,i.createMemo)(e,void 0,{equals:t})}function O(){let{location:e}=R();return new Proxy({},{get:(n,t)=>e()[t],has:(n,t)=>t in e(),ownKeys:()=>Reflect.ownKeys(e()),getOwnPropertyDescriptor:(n,t)=>Object.getOwnPropertyDescriptor(e(),t)})}function ke(e={}){let n=(0,l.useContext)(v);return t=>{if(!n||t.defaultPrevented||t.button!==0||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey)return;let r=t.target?.closest?.("a");if(!r||!r.getAttribute("href")||r.target&&r.target!=="_self"||r.hasAttribute("download")||/(^|\s)external(\s|$)/.test(r.getAttribute("rel")??""))return;let o=new URL(r.href);o.protocol!=="http:"&&o.protocol!=="https:"||o.origin===window.location.origin&&(o.hash&&o.pathname===window.location.pathname&&o.search===window.location.search||e.shouldNavigate&&!e.shouldNavigate(o,r)||(t.preventDefault(),n.router.navigate(o.pathname+o.search+o.hash,{replace:e.replace})))}}function G(){let{router:e}=R();return(n,t)=>e.navigate(n,t)}function Oe(){return(0,l.useContext)(X)??(()=>{})}var f=e=>typeof e=="function"?e():e,Le=new Set(["href","slot","class","className","active","activeClass","replace","children"]);function Q(e){let n=(0,l.useContext)(v),t=()=>n?.router.navigate(f(e.href)??"",{replace:f(e.replace)}),a=(0,c.createNativeElement)("a");(0,c.setAttribute)(a,"href",f(e.href)??""),e.slot&&(0,c.setAttribute)(a,"slot",f(e.slot));for(let o of Object.keys(e)){if(Le.has(o))continue;let s=e[o];s!=null&&typeof s!="function"&&(0,c.setAttribute)(a,o,String(s))}if(typeof a.addEventListener=="function")a.addEventListener("click",o=>{o.metaKey||o.ctrlKey||o.shiftKey||o.altKey||(o.preventDefault(),t())});else{let o=f(e.className??e.class)??"";o&&(0,c.setAttribute)(a,"class",o)}typeof a.addEventListener=="function"&&(0,i.createEffect)(()=>{let o=f(e.href)??"";a.setAttribute("href",o);let s=f(e.className??e.class)??"",u=f(e.activeClass)??"",d=f(e.active)??n?.location().pathname===o;a.className=[s,d?u:""].filter(Boolean).join(" ")});let r=e.children;return r!=null&&(0,c.insert)(a,r),a}var De=Q;function Ne(e){let n=e.action,t=e.className??e.class,a=n.url??"",r=(0,c.createNativeElement)("form");(0,c.setAttribute)(r,"method","post"),a&&(0,c.setAttribute)(r,"action",a),t&&(0,c.setAttribute)(r,"class",t);for(let s of Object.keys(e)){if(s==="action"||s==="children"||s==="class"||s==="className")continue;let u=e[s];u!=null&&typeof u!="function"&&(0,c.setAttribute)(r,s,String(u))}typeof r.addEventListener=="function"&&r.addEventListener("submit",s=>{s.preventDefault();let u={};new FormData(r).forEach((d,p)=>{u[p]=d}),Promise.resolve(n(u)).catch(()=>{})});let o=e.children;return o!=null&&(0,c.insert)(r,o),r}async function Me(e,n){let t=(0,y.matchRoutes)(e,n);if(!t)return;let a=[];for(let r of t.matched){let o=r.component;o&&typeof o.preload=="function"&&a.push(o.preload())}await Promise.all(a)}
|
|
1
|
+
/*! @fluixi/core v1.0.0-alpha.85 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/lib/router/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
A: () => A,
|
|
25
|
+
Form: () => Form,
|
|
26
|
+
Link: () => Link,
|
|
27
|
+
Outlet: () => Outlet,
|
|
28
|
+
Redirect: () => Redirect,
|
|
29
|
+
Router: () => Router,
|
|
30
|
+
action: () => action,
|
|
31
|
+
cache: () => cache,
|
|
32
|
+
createAsync: () => createAsync,
|
|
33
|
+
createBrowserHistory: () => import_router2.createBrowserHistory,
|
|
34
|
+
createMemoryHistory: () => import_router2.createMemoryHistory,
|
|
35
|
+
lazy: () => lazy,
|
|
36
|
+
matchPath: () => import_router2.matchPath,
|
|
37
|
+
matchRoutes: () => import_router2.matchRoutes,
|
|
38
|
+
prefersReducedMotion: () => prefersReducedMotion,
|
|
39
|
+
preloadRoutes: () => preloadRoutes,
|
|
40
|
+
revalidate: () => revalidate,
|
|
41
|
+
runWithOwner: () => import_signal7.runWithOwner,
|
|
42
|
+
select: () => select,
|
|
43
|
+
supportsViewTransitions: () => supportsViewTransitions,
|
|
44
|
+
useAction: () => useAction,
|
|
45
|
+
useLevelParams: () => useLevelParams,
|
|
46
|
+
useLinkNavigation: () => useLinkNavigation,
|
|
47
|
+
useLocation: () => useLocation,
|
|
48
|
+
useMatch: () => useMatch,
|
|
49
|
+
useNavigate: () => useNavigate,
|
|
50
|
+
useParam: () => useParam,
|
|
51
|
+
useParamSelector: () => useParamSelector,
|
|
52
|
+
useParams: () => useParams,
|
|
53
|
+
useRouteData: () => useRouteData,
|
|
54
|
+
useRouter: () => useRouter,
|
|
55
|
+
useSearchParams: () => useSearchParams,
|
|
56
|
+
useSubmission: () => useSubmission
|
|
57
|
+
});
|
|
58
|
+
module.exports = __toCommonJS(index_exports);
|
|
59
|
+
var import_signal5 = require("@fluixi/reactive/signal");
|
|
60
|
+
|
|
61
|
+
// src/lib/router/transition.ts
|
|
62
|
+
function supportsViewTransitions() {
|
|
63
|
+
return typeof document !== "undefined" && typeof document.startViewTransition === "function";
|
|
64
|
+
}
|
|
65
|
+
function prefersReducedMotion() {
|
|
66
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function shouldAnimate(mode) {
|
|
76
|
+
return mode !== "none" && supportsViewTransitions() && !prefersReducedMotion();
|
|
77
|
+
}
|
|
78
|
+
function prepareComponents(components) {
|
|
79
|
+
const pending = [];
|
|
80
|
+
for (const component of components) {
|
|
81
|
+
const preload = component?.preload;
|
|
82
|
+
if (typeof preload === "function") {
|
|
83
|
+
try {
|
|
84
|
+
const result = preload();
|
|
85
|
+
if (result && typeof result.then === "function") {
|
|
86
|
+
pending.push(result.catch(() => void 0));
|
|
87
|
+
}
|
|
88
|
+
} catch {
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return pending.length ? Promise.all(pending).then(() => void 0) : null;
|
|
93
|
+
}
|
|
94
|
+
function runTransition(mode, commit) {
|
|
95
|
+
if (!shouldAnimate(mode)) {
|
|
96
|
+
return Promise.resolve(commit()).then(() => void 0);
|
|
97
|
+
}
|
|
98
|
+
const start = document.startViewTransition;
|
|
99
|
+
try {
|
|
100
|
+
const transition = start.call(document, () => commit());
|
|
101
|
+
transition.finished?.catch(() => void 0);
|
|
102
|
+
transition.ready?.catch(() => void 0);
|
|
103
|
+
return transition.updateCallbackDone.catch(() => void 0);
|
|
104
|
+
} catch {
|
|
105
|
+
return Promise.resolve(commit()).then(() => void 0);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/lib/router/index.ts
|
|
110
|
+
var import_dom4 = require("@fluixi/dom");
|
|
111
|
+
var import_signal6 = require("@fluixi/reactive/signal");
|
|
112
|
+
var import_object = require("@fluixi/utils/object");
|
|
113
|
+
var import_compare = require("@fluixi/utils/compare");
|
|
114
|
+
var import_router = require("@fluixi/router");
|
|
115
|
+
var import_router2 = require("@fluixi/router");
|
|
116
|
+
|
|
117
|
+
// src/lib/router/data.ts
|
|
118
|
+
var import_signal3 = require("@fluixi/reactive/signal");
|
|
119
|
+
|
|
120
|
+
// src/lib/server/hydration.ts
|
|
121
|
+
var import_dom = require("@fluixi/dom");
|
|
122
|
+
var hydrating = false;
|
|
123
|
+
var hydrationDataMap = /* @__PURE__ */ new Map();
|
|
124
|
+
function isHydrating() {
|
|
125
|
+
return hydrating;
|
|
126
|
+
}
|
|
127
|
+
function setHydrationData(key, data) {
|
|
128
|
+
hydrationDataMap.set(key, data);
|
|
129
|
+
}
|
|
130
|
+
function getHydrationData(key) {
|
|
131
|
+
return hydrationDataMap.get(key);
|
|
132
|
+
}
|
|
133
|
+
function clearHydrationData() {
|
|
134
|
+
hydrationDataMap.clear();
|
|
135
|
+
}
|
|
136
|
+
function cleanupHydration() {
|
|
137
|
+
if (typeof window === "undefined") {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
141
|
+
if (script) {
|
|
142
|
+
script.remove();
|
|
143
|
+
}
|
|
144
|
+
const walker = document.createTreeWalker(
|
|
145
|
+
document.body,
|
|
146
|
+
NodeFilter.SHOW_COMMENT,
|
|
147
|
+
null
|
|
148
|
+
);
|
|
149
|
+
const comments = [];
|
|
150
|
+
let node;
|
|
151
|
+
while (node = walker.nextNode()) {
|
|
152
|
+
const comment = node;
|
|
153
|
+
const text = comment.nodeValue || "";
|
|
154
|
+
if (text.startsWith("#") || text.startsWith("/")) {
|
|
155
|
+
comments.push(comment);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
comments.forEach((comment) => comment.remove());
|
|
159
|
+
clearHydrationData();
|
|
160
|
+
}
|
|
161
|
+
if (typeof window !== "undefined") {
|
|
162
|
+
window.addEventListener("load", () => {
|
|
163
|
+
setTimeout(cleanupHydration, 100);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function isServerEnvironment() {
|
|
167
|
+
return (0, import_dom.isServer)();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/lib/context/context.ts
|
|
171
|
+
var import_dom2 = require("@fluixi/dom");
|
|
172
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
173
|
+
var import_signal2 = require("@fluixi/reactive/signal");
|
|
174
|
+
function createContext(defaultValue, name) {
|
|
175
|
+
const context = (0, import_signal.createContext)(defaultValue, name);
|
|
176
|
+
const Provider = (props) => {
|
|
177
|
+
if (props.debug === true) {
|
|
178
|
+
}
|
|
179
|
+
return context.Provider({
|
|
180
|
+
value: props.value,
|
|
181
|
+
get children() {
|
|
182
|
+
return props.children;
|
|
183
|
+
},
|
|
184
|
+
debug: props.debug
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
188
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
189
|
+
}
|
|
190
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
191
|
+
return {
|
|
192
|
+
id: context.id,
|
|
193
|
+
Provider: (0, import_dom2.asProvider)(Provider),
|
|
194
|
+
defaultValue
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/lib/router/data.ts
|
|
199
|
+
var globalCache = /* @__PURE__ */ new Map();
|
|
200
|
+
var inflightRequests = /* @__PURE__ */ new Map();
|
|
201
|
+
function cache(fn, name) {
|
|
202
|
+
return async (...args) => {
|
|
203
|
+
const key = name + ":" + JSON.stringify(args);
|
|
204
|
+
if (isHydrating() || typeof window !== "undefined") {
|
|
205
|
+
const hydrated = getHydrationData(key);
|
|
206
|
+
if (hydrated !== void 0) {
|
|
207
|
+
return hydrated;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (globalCache.has(key)) {
|
|
211
|
+
return globalCache.get(key);
|
|
212
|
+
}
|
|
213
|
+
if (inflightRequests.has(key)) {
|
|
214
|
+
return inflightRequests.get(key);
|
|
215
|
+
}
|
|
216
|
+
const promise = Promise.resolve(fn(...args)).then(
|
|
217
|
+
(val) => {
|
|
218
|
+
globalCache.set(key, val);
|
|
219
|
+
inflightRequests.delete(key);
|
|
220
|
+
if (isServerEnvironment()) {
|
|
221
|
+
setHydrationData(key, val);
|
|
222
|
+
}
|
|
223
|
+
return val;
|
|
224
|
+
},
|
|
225
|
+
(err) => {
|
|
226
|
+
inflightRequests.delete(key);
|
|
227
|
+
throw err;
|
|
228
|
+
}
|
|
229
|
+
);
|
|
230
|
+
inflightRequests.set(key, promise);
|
|
231
|
+
return promise;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
var [revalidationVersion, setRevalidationVersion] = (0, import_signal3.createSignal)(0);
|
|
235
|
+
var revalidationKeys = /* @__PURE__ */ new Set();
|
|
236
|
+
function revalidate(key) {
|
|
237
|
+
const predicate = typeof key === "string" ? (k) => k.startsWith(key) : key;
|
|
238
|
+
for (const k of globalCache.keys()) {
|
|
239
|
+
if (predicate(k)) {
|
|
240
|
+
globalCache.delete(k);
|
|
241
|
+
revalidationKeys.add(k);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
setRevalidationVersion((v) => v + 1);
|
|
245
|
+
}
|
|
246
|
+
function createAsync(fetcher, source) {
|
|
247
|
+
const [data] = (0, import_signal3.createResource)(source || (() => true), fetcher);
|
|
248
|
+
return data;
|
|
249
|
+
}
|
|
250
|
+
var submissionState = /* @__PURE__ */ new Map();
|
|
251
|
+
function getSubmissionSignal(url) {
|
|
252
|
+
if (!submissionState.has(url)) {
|
|
253
|
+
submissionState.set(
|
|
254
|
+
url,
|
|
255
|
+
(0, import_signal3.createSignal)(void 0)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
return submissionState.get(url);
|
|
259
|
+
}
|
|
260
|
+
function action(fn, name) {
|
|
261
|
+
const actionUrl = name || fn.name || "action";
|
|
262
|
+
const submit = async (input) => {
|
|
263
|
+
const [, setSubmission] = getSubmissionSignal(actionUrl);
|
|
264
|
+
const clear = () => setSubmission(void 0);
|
|
265
|
+
const retry = () => submit(input);
|
|
266
|
+
setSubmission({
|
|
267
|
+
input,
|
|
268
|
+
// Approximate type for tracking
|
|
269
|
+
pending: true,
|
|
270
|
+
clear,
|
|
271
|
+
retry
|
|
272
|
+
});
|
|
273
|
+
try {
|
|
274
|
+
const result = await fn(input);
|
|
275
|
+
setSubmission({
|
|
276
|
+
input,
|
|
277
|
+
result,
|
|
278
|
+
pending: false,
|
|
279
|
+
clear,
|
|
280
|
+
retry
|
|
281
|
+
});
|
|
282
|
+
return result;
|
|
283
|
+
} catch (error) {
|
|
284
|
+
setSubmission({
|
|
285
|
+
input,
|
|
286
|
+
error,
|
|
287
|
+
pending: false,
|
|
288
|
+
clear,
|
|
289
|
+
retry
|
|
290
|
+
});
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
submit.url = actionUrl;
|
|
295
|
+
submit.with = (args) => action((...a) => fn(args, ...a), name);
|
|
296
|
+
return submit;
|
|
297
|
+
}
|
|
298
|
+
function useSubmission(actionFn) {
|
|
299
|
+
const [submission] = getSubmissionSignal(actionFn.url);
|
|
300
|
+
return submission;
|
|
301
|
+
}
|
|
302
|
+
function useAction(actionFn) {
|
|
303
|
+
return actionFn;
|
|
304
|
+
}
|
|
305
|
+
var RouteDataContext = createContext(void 0, "route-data");
|
|
306
|
+
var RouteDataProvider = RouteDataContext.Provider;
|
|
307
|
+
|
|
308
|
+
// src/lib/render/lazy.ts
|
|
309
|
+
var import_dom3 = require("@fluixi/dom");
|
|
310
|
+
var import_signal4 = require("@fluixi/reactive/signal");
|
|
311
|
+
function fromChunk(value) {
|
|
312
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
313
|
+
try {
|
|
314
|
+
value["$lazy"] = true;
|
|
315
|
+
} catch {
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return value;
|
|
319
|
+
}
|
|
320
|
+
function lazy(loader, options) {
|
|
321
|
+
let resolved;
|
|
322
|
+
let promise;
|
|
323
|
+
let component;
|
|
324
|
+
function load() {
|
|
325
|
+
if (!promise) {
|
|
326
|
+
promise = loader().then((mod) => resolved = mod.default);
|
|
327
|
+
}
|
|
328
|
+
return promise;
|
|
329
|
+
}
|
|
330
|
+
if (options?.preload) load();
|
|
331
|
+
const LazyWrapper = ((props) => {
|
|
332
|
+
if (resolved) {
|
|
333
|
+
const C = resolved;
|
|
334
|
+
return fromChunk((0, import_signal4.untrack)(() => C(props)));
|
|
335
|
+
}
|
|
336
|
+
if (!component) {
|
|
337
|
+
const [resource] = (0, import_signal4.createResource)(() => load(), { transport: false });
|
|
338
|
+
component = resource;
|
|
339
|
+
if (resource.error) throw resource.error;
|
|
340
|
+
}
|
|
341
|
+
return (0, import_signal4.createMemo)(() => {
|
|
342
|
+
const C = component();
|
|
343
|
+
return C ? fromChunk((0, import_dom3.createComponent)(C, props)) : void 0;
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
LazyWrapper.preload = () => load().then(() => void 0);
|
|
347
|
+
LazyWrapper.$lazy = true;
|
|
348
|
+
LazyWrapper.loader = loader;
|
|
349
|
+
return LazyWrapper;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/lib/router/index.ts
|
|
353
|
+
var import_signal7 = require("@fluixi/reactive/signal");
|
|
354
|
+
var RouterContext = (0, import_signal6.createContext)(void 0, "router");
|
|
355
|
+
var OutletContext = (0, import_signal6.createContext)(void 0, "outlet");
|
|
356
|
+
var LevelParamsContext = (0, import_signal6.createContext)(void 0, "route-params");
|
|
357
|
+
var RouteDataContext2 = (0, import_signal6.createContext)(void 0, "route-data");
|
|
358
|
+
function renderLayer(m, depth, base) {
|
|
359
|
+
let data;
|
|
360
|
+
const loader = m.route.data;
|
|
361
|
+
if (typeof loader === "function") {
|
|
362
|
+
let cancelled = false;
|
|
363
|
+
(0, import_signal5.onCleanup)(() => {
|
|
364
|
+
cancelled = true;
|
|
365
|
+
});
|
|
366
|
+
const owner = (0, import_signal5.getOwner)();
|
|
367
|
+
const [resource] = (0, import_signal5.createResource)(
|
|
368
|
+
() => loader({ params: base.params, location: base.location }, owner, () => cancelled)
|
|
369
|
+
);
|
|
370
|
+
data = resource;
|
|
371
|
+
}
|
|
372
|
+
const buildPage = () => RouteDataContext2.Provider({
|
|
373
|
+
value: data,
|
|
374
|
+
get children() {
|
|
375
|
+
return LevelParamsContext.Provider({
|
|
376
|
+
value: m.params,
|
|
377
|
+
get children() {
|
|
378
|
+
return OutletContext.Provider({
|
|
379
|
+
value: { depth, ...base },
|
|
380
|
+
get children() {
|
|
381
|
+
return (0, import_dom4.createComponent)(m.component, {});
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
if (!data) return buildPage();
|
|
389
|
+
const res = data;
|
|
390
|
+
const isLoading = () => res.loading;
|
|
391
|
+
const [ready, setReady] = (0, import_signal5.createSignal)((0, import_signal5.untrack)(() => !isLoading()));
|
|
392
|
+
(0, import_signal5.createEffect)(() => setReady(!isLoading()));
|
|
393
|
+
return (0, import_signal5.createMemo)(() => ready() ? buildPage() : null);
|
|
394
|
+
}
|
|
395
|
+
function renderChild(ctx) {
|
|
396
|
+
const childIdx = ctx.depth + 1;
|
|
397
|
+
const [childComp, setChildComp] = (0, import_signal5.createSignal)(
|
|
398
|
+
(0, import_signal5.untrack)(() => ctx.matched()[childIdx]?.component)
|
|
399
|
+
);
|
|
400
|
+
(0, import_signal5.createEffect)(() => {
|
|
401
|
+
const c = ctx.matched()[childIdx]?.component;
|
|
402
|
+
if ((0, import_signal5.untrack)(childComp) !== c) setChildComp(() => c);
|
|
403
|
+
});
|
|
404
|
+
return (0, import_signal5.createMemo)(() => {
|
|
405
|
+
const component = childComp();
|
|
406
|
+
if (!component) {
|
|
407
|
+
return ctx.notFound ? ctx.notFound() : null;
|
|
408
|
+
}
|
|
409
|
+
const m = (0, import_signal5.untrack)(() => ctx.matched())[childIdx];
|
|
410
|
+
return renderLayer(m, childIdx, {
|
|
411
|
+
matched: ctx.matched,
|
|
412
|
+
params: ctx.params,
|
|
413
|
+
location: ctx.location
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
function renderNotFound(notFound) {
|
|
418
|
+
if (notFound == null) return buildDefaultNotFound();
|
|
419
|
+
return typeof notFound === "function" ? (0, import_dom4.createComponent)(notFound, {}) : notFound;
|
|
420
|
+
}
|
|
421
|
+
function buildDefaultNotFound() {
|
|
422
|
+
const el = (0, import_dom4.createNativeElement)("div");
|
|
423
|
+
(0, import_dom4.setAttribute)(el, "class", "fx-not-found");
|
|
424
|
+
(0, import_dom4.setAttribute)(el, "role", "main");
|
|
425
|
+
(0, import_dom4.setAttribute)(
|
|
426
|
+
el,
|
|
427
|
+
"style",
|
|
428
|
+
"min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif"
|
|
429
|
+
);
|
|
430
|
+
const h1 = (0, import_dom4.createNativeElement)("h1");
|
|
431
|
+
(0, import_dom4.setAttribute)(h1, "style", "margin:0;font-size:2.5rem;font-weight:700");
|
|
432
|
+
(0, import_dom4.insert)(h1, "404");
|
|
433
|
+
const p = (0, import_dom4.createNativeElement)("p");
|
|
434
|
+
(0, import_dom4.setAttribute)(p, "style", "margin:0;opacity:.7");
|
|
435
|
+
(0, import_dom4.insert)(p, "This page could not be found.");
|
|
436
|
+
el.appendChild(h1);
|
|
437
|
+
el.appendChild(p);
|
|
438
|
+
return el;
|
|
439
|
+
}
|
|
440
|
+
var pendingTransitionMode;
|
|
441
|
+
function Router(props) {
|
|
442
|
+
const history = props.history ?? (0, import_router.createBrowserHistory)();
|
|
443
|
+
const router = (0, import_router.createRouter)({
|
|
444
|
+
routes: props.routes,
|
|
445
|
+
base: props.base,
|
|
446
|
+
history
|
|
447
|
+
});
|
|
448
|
+
const [state, setState] = (0, import_signal5.createSignal)(router.state());
|
|
449
|
+
let navigationId = 0;
|
|
450
|
+
const takeMode = () => {
|
|
451
|
+
const mode = pendingTransitionMode ?? (props.transition ?? "auto");
|
|
452
|
+
pendingTransitionMode = void 0;
|
|
453
|
+
return mode;
|
|
454
|
+
};
|
|
455
|
+
const unsub = router.subscribe((next) => {
|
|
456
|
+
const id = ++navigationId;
|
|
457
|
+
const mode = takeMode();
|
|
458
|
+
const prepared = prepareComponents(
|
|
459
|
+
(next.match?.matched ?? []).map((m) => m.component).filter(Boolean)
|
|
460
|
+
);
|
|
461
|
+
const commit = () => {
|
|
462
|
+
setState(next);
|
|
463
|
+
return (0, import_signal5.flush)();
|
|
464
|
+
};
|
|
465
|
+
if (!prepared) {
|
|
466
|
+
void runTransition(mode, commit);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
void prepared.then(() => {
|
|
470
|
+
if (id !== navigationId) return;
|
|
471
|
+
return runTransition(mode, commit);
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
(0, import_signal5.onCleanup)(() => {
|
|
475
|
+
unsub();
|
|
476
|
+
router.destroy();
|
|
477
|
+
navigationId++;
|
|
478
|
+
});
|
|
479
|
+
const matched = (0, import_signal5.createMemo)(
|
|
480
|
+
() => (state().match?.matched ?? []).filter((m) => m.component)
|
|
481
|
+
);
|
|
482
|
+
const ctx = {
|
|
483
|
+
router,
|
|
484
|
+
location: (0, import_signal5.createMemo)(() => state().location),
|
|
485
|
+
params: (0, import_signal5.createMemo)(() => state().match?.params ?? {})
|
|
486
|
+
};
|
|
487
|
+
const root = {
|
|
488
|
+
depth: -1,
|
|
489
|
+
matched,
|
|
490
|
+
params: ctx.params,
|
|
491
|
+
location: ctx.location,
|
|
492
|
+
// Only the root carries this: renderChild shows it when the URL matched nothing.
|
|
493
|
+
notFound: () => renderNotFound(props.notFound)
|
|
494
|
+
};
|
|
495
|
+
let rootView;
|
|
496
|
+
return RouterContext.Provider({
|
|
497
|
+
value: ctx,
|
|
498
|
+
get children() {
|
|
499
|
+
return rootView ??= renderChild(root);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function Outlet() {
|
|
504
|
+
const ctx = (0, import_signal6.useContext)(OutletContext);
|
|
505
|
+
if (!ctx) return null;
|
|
506
|
+
return renderChild(ctx);
|
|
507
|
+
}
|
|
508
|
+
function Redirect(props) {
|
|
509
|
+
const ctx = (0, import_signal6.useContext)(RouterContext);
|
|
510
|
+
if (ctx && typeof window !== "undefined") {
|
|
511
|
+
let cancelled = false;
|
|
512
|
+
(0, import_signal5.onCleanup)(() => cancelled = true);
|
|
513
|
+
queueMicrotask(() => {
|
|
514
|
+
if (!cancelled) ctx.router.navigate(props.to, { replace: props.replace !== false });
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
var _ssrRouterStub = {
|
|
520
|
+
router: { navigate: () => {
|
|
521
|
+
} },
|
|
522
|
+
location: () => ({ pathname: "", search: "", hash: "", query: {} }),
|
|
523
|
+
params: () => ({})
|
|
524
|
+
};
|
|
525
|
+
function useRouter() {
|
|
526
|
+
const ctx = (0, import_signal6.useContext)(RouterContext);
|
|
527
|
+
if (ctx) return ctx;
|
|
528
|
+
if (typeof window === "undefined") return _ssrRouterStub;
|
|
529
|
+
throw new Error("[router] useRouter must be used within <Router>");
|
|
530
|
+
}
|
|
531
|
+
function useParams() {
|
|
532
|
+
const params = useRouter().params;
|
|
533
|
+
return (0, import_signal5.createMemo)(() => params(), {}, {
|
|
534
|
+
equals: (a, b) => JSON.stringify(a) === JSON.stringify(b)
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
function useLevelParams() {
|
|
538
|
+
return (0, import_signal6.useContext)(LevelParamsContext) ?? {};
|
|
539
|
+
}
|
|
540
|
+
function useParam(key) {
|
|
541
|
+
const params = useParams();
|
|
542
|
+
return (0, import_signal5.createMemo)(() => params()[key]);
|
|
543
|
+
}
|
|
544
|
+
function useParamSelector(selector, equals) {
|
|
545
|
+
const params = useParams();
|
|
546
|
+
return (0, import_signal5.createMemo)(
|
|
547
|
+
() => selector(params()),
|
|
548
|
+
void 0,
|
|
549
|
+
equals ? { equals } : void 0
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
function useMatch(path) {
|
|
553
|
+
const location = useLocation();
|
|
554
|
+
return (0, import_signal5.createMemo)(
|
|
555
|
+
() => (0, import_router.matchPath)(typeof path === "function" ? path() : path, location.pathname)
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
function useSearchParams() {
|
|
559
|
+
const location = useLocation();
|
|
560
|
+
const navigate = useNavigate();
|
|
561
|
+
const params = (0, import_signal5.createMemo)(() => location.query);
|
|
562
|
+
const setParams = (next, options) => {
|
|
563
|
+
const current = new URLSearchParams(location.search);
|
|
564
|
+
for (const [k, v] of Object.entries(next)) {
|
|
565
|
+
if (v === null) current.delete(k);
|
|
566
|
+
else current.set(k, v);
|
|
567
|
+
}
|
|
568
|
+
const search = current.toString();
|
|
569
|
+
navigate(location.pathname + (search ? `?${search}` : ""), options);
|
|
570
|
+
};
|
|
571
|
+
return [params, setParams];
|
|
572
|
+
}
|
|
573
|
+
function select(source, key) {
|
|
574
|
+
const equals = (a, b) => (0, import_compare.deepEqual)(a, b);
|
|
575
|
+
if (key !== void 0) {
|
|
576
|
+
return (0, import_signal5.createMemo)(
|
|
577
|
+
() => (0, import_object.get)(source(), key),
|
|
578
|
+
void 0,
|
|
579
|
+
{ equals }
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
return (0, import_signal5.createMemo)(source, void 0, { equals });
|
|
583
|
+
}
|
|
584
|
+
function useLocation() {
|
|
585
|
+
const { location } = useRouter();
|
|
586
|
+
return new Proxy({}, {
|
|
587
|
+
get: (_t, key) => location()[key],
|
|
588
|
+
has: (_t, key) => key in location(),
|
|
589
|
+
ownKeys: () => Reflect.ownKeys(location()),
|
|
590
|
+
getOwnPropertyDescriptor: (_t, key) => Object.getOwnPropertyDescriptor(location(), key)
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
function useLinkNavigation(options = {}) {
|
|
594
|
+
const ctx = (0, import_signal6.useContext)(RouterContext);
|
|
595
|
+
return (event) => {
|
|
596
|
+
if (!ctx || event.defaultPrevented || event.button !== 0) return;
|
|
597
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
598
|
+
const target = event.target;
|
|
599
|
+
const anchor = target?.closest?.("a");
|
|
600
|
+
if (!anchor || !anchor.getAttribute("href")) return;
|
|
601
|
+
if (anchor.target && anchor.target !== "_self") return;
|
|
602
|
+
if (anchor.hasAttribute("download")) return;
|
|
603
|
+
if (/(^|\s)external(\s|$)/.test(anchor.getAttribute("rel") ?? "")) return;
|
|
604
|
+
const url = new URL(anchor.href);
|
|
605
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
606
|
+
if (url.origin !== window.location.origin) return;
|
|
607
|
+
if (url.hash && url.pathname === window.location.pathname && url.search === window.location.search) return;
|
|
608
|
+
if (options.shouldNavigate && !options.shouldNavigate(url, anchor)) return;
|
|
609
|
+
event.preventDefault();
|
|
610
|
+
pendingTransitionMode = options.transition;
|
|
611
|
+
ctx.router.navigate(url.pathname + url.search + url.hash, { replace: options.replace });
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
function useNavigate() {
|
|
615
|
+
const { router } = useRouter();
|
|
616
|
+
return (to, options) => {
|
|
617
|
+
pendingTransitionMode = options?.transition;
|
|
618
|
+
router.navigate(to, options);
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function useRouteData() {
|
|
622
|
+
const acc = (0, import_signal6.useContext)(RouteDataContext2);
|
|
623
|
+
return acc ?? (() => void 0);
|
|
624
|
+
}
|
|
625
|
+
var read = (v) => typeof v === "function" ? v() : v;
|
|
626
|
+
var LINK_OWN_PROPS = /* @__PURE__ */ new Set([
|
|
627
|
+
"href",
|
|
628
|
+
"slot",
|
|
629
|
+
"class",
|
|
630
|
+
"className",
|
|
631
|
+
"active",
|
|
632
|
+
"activeClass",
|
|
633
|
+
"replace",
|
|
634
|
+
"children"
|
|
635
|
+
]);
|
|
636
|
+
function Link(props) {
|
|
637
|
+
const ctx = (0, import_signal6.useContext)(RouterContext);
|
|
638
|
+
const navigate = () => ctx?.router.navigate(read(props.href) ?? "", { replace: read(props.replace) });
|
|
639
|
+
const a = (0, import_dom4.createNativeElement)("a");
|
|
640
|
+
(0, import_dom4.setAttribute)(a, "href", read(props.href) ?? "");
|
|
641
|
+
if (props.slot) (0, import_dom4.setAttribute)(a, "slot", read(props.slot));
|
|
642
|
+
for (const k of Object.keys(props)) {
|
|
643
|
+
if (LINK_OWN_PROPS.has(k)) continue;
|
|
644
|
+
const v = props[k];
|
|
645
|
+
if (v != null && typeof v !== "function") (0, import_dom4.setAttribute)(a, k, String(v));
|
|
646
|
+
}
|
|
647
|
+
if (typeof a.addEventListener === "function") {
|
|
648
|
+
a.addEventListener("click", (e) => {
|
|
649
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
650
|
+
e.preventDefault();
|
|
651
|
+
navigate();
|
|
652
|
+
});
|
|
653
|
+
} else {
|
|
654
|
+
const base = read(props.className ?? props.class) ?? "";
|
|
655
|
+
if (base) (0, import_dom4.setAttribute)(a, "class", base);
|
|
656
|
+
}
|
|
657
|
+
if (typeof a.addEventListener === "function") {
|
|
658
|
+
(0, import_signal5.createEffect)(() => {
|
|
659
|
+
const href = read(props.href) ?? "";
|
|
660
|
+
a.setAttribute("href", href);
|
|
661
|
+
const base = read(props.className ?? props.class) ?? "";
|
|
662
|
+
const activeClass = read(props.activeClass) ?? "";
|
|
663
|
+
const active = read(props.active) ?? ctx?.location().pathname === href;
|
|
664
|
+
a.className = [base, active ? activeClass : ""].filter(Boolean).join(" ");
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
const linkChildren = props.children;
|
|
668
|
+
if (linkChildren != null) (0, import_dom4.insert)(a, linkChildren);
|
|
669
|
+
return a;
|
|
670
|
+
}
|
|
671
|
+
var A = Link;
|
|
672
|
+
function Form(props) {
|
|
673
|
+
const action2 = props.action;
|
|
674
|
+
const cls = props.className ?? props.class;
|
|
675
|
+
const url = action2.url ?? "";
|
|
676
|
+
const form = (0, import_dom4.createNativeElement)("form");
|
|
677
|
+
(0, import_dom4.setAttribute)(form, "method", "post");
|
|
678
|
+
if (url) (0, import_dom4.setAttribute)(form, "action", url);
|
|
679
|
+
if (cls) (0, import_dom4.setAttribute)(form, "class", cls);
|
|
680
|
+
for (const k of Object.keys(props)) {
|
|
681
|
+
if (k === "action" || k === "children" || k === "class" || k === "className") continue;
|
|
682
|
+
const v = props[k];
|
|
683
|
+
if (v != null && typeof v !== "function") (0, import_dom4.setAttribute)(form, k, String(v));
|
|
684
|
+
}
|
|
685
|
+
if (typeof form.addEventListener === "function") {
|
|
686
|
+
form.addEventListener("submit", (e) => {
|
|
687
|
+
e.preventDefault();
|
|
688
|
+
const data = {};
|
|
689
|
+
new FormData(form).forEach((v, k) => {
|
|
690
|
+
data[k] = v;
|
|
691
|
+
});
|
|
692
|
+
Promise.resolve(action2(data)).catch(() => {
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
const children = props.children;
|
|
697
|
+
if (children != null) (0, import_dom4.insert)(form, children);
|
|
698
|
+
return form;
|
|
699
|
+
}
|
|
700
|
+
async function preloadRoutes(routes, pathname) {
|
|
701
|
+
const match = (0, import_router.matchRoutes)(routes, pathname);
|
|
702
|
+
if (!match) return;
|
|
703
|
+
const loads = [];
|
|
704
|
+
for (const m of match.matched) {
|
|
705
|
+
const c = m.component;
|
|
706
|
+
if (c && typeof c.preload === "function") loads.push(c.preload());
|
|
707
|
+
}
|
|
708
|
+
await Promise.all(loads);
|
|
709
|
+
}
|