@fluixi/core 1.0.0-alpha.56 → 1.0.0-alpha.57

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.
@@ -1 +1 @@
1
- import{createSignal as P,createMemo as d,createResource as ge,createEffect as w,getOwner as xe,onCleanup as A,untrack as R}from"@fluixi/reactive/signal";import{insert as h,createComponent as F,createNativeElement as g,setAttribute as u}from"@fluixi/dom";import{createContext as v,useContext as p}from"@fluixi/reactive/signal";import{get as he}from"@fluixi/utils/object";import{deepEqual as ve}from"@fluixi/utils/compare";import{createRouter as Te,createBrowserHistory as Ce,matchRoutes as be,matchPath as Re}from"@fluixi/router";import{createMemoryHistory as Vt,createBrowserHistory as Ft,matchRoutes as jt,matchPath as Ut}from"@fluixi/router";import{createResource as oe,createSignal as N}from"@fluixi/reactive/signal";var B=!1,C=new Map;function O(){return B}function E(e,n){C.set(e,n)}function L(e){return C.get(e)}function J(){C.clear()}function X(){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=[],o;for(;o=n.nextNode();){let r=o,a=r.nodeValue||"";(a.startsWith("#")||a.startsWith("/"))&&t.push(r)}t.forEach(r=>r.remove()),J()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(X,100)});function D(){return typeof window>"u"}import{asProvider as ne}from"@fluixi/dom";import{createContext as re,useContext as Qe}from"@fluixi/reactive/signal";import{readChildren as nt}from"@fluixi/reactive/signal";import{registerCreateComponent as Y,asComponent as G}from"@fluixi/dom";import{untrack as Q,onCleanup as Ne,getOwner as _e,createEffect as He,createMemo as Ve,createSignal as Fe,isSignal as Z,batch as je,runWithOwner as Ie}from"@fluixi/reactive/signal";function k(e){Y(ee)}function ee(e,n){return te(e,n)}function te(e,n){let t=typeof e=="function"?Q(()=>e(n)):e;if(t!=null&&(typeof t=="function"||typeof t=="object")&&!Z(t)){try{t.$name=e.name}catch{}return G(t)}return t}k("index");function M(e){let n=re(e),t=o=>(o.debug,n.Provider({value:o.value,get children(){return o.children},debug:o.debug}));return typeof Symbol<"u"&&Symbol.for&&(t.$$typeof=Symbol.for("react.provider")),t.$$typeof=Symbol.for("react.provider"),{id:n.id,Provider:ne(t),defaultValue:e}}var m=new Map,y=new Map;function ae(e,n){return async(...t)=>{let o=n+":"+JSON.stringify(t);if(O()||typeof window<"u"){let a=L(o);if(a!==void 0)return a}if(m.has(o))return m.get(o);if(y.has(o))return y.get(o);let r=Promise.resolve(e(...t)).then(a=>(m.set(o,a),y.delete(o),D()&&E(o,a),a),a=>{throw y.delete(o),a});return y.set(o,r),r}}var[dt,ie]=N(0),se=new Set;function ce(e){let n=typeof e=="string"?t=>t.startsWith(e):e;for(let t of m.keys())n(t)&&(m.delete(t),se.add(t));ie(t=>t+1)}function ue(e,n){let[t]=oe(n||(()=>!0),e);return t}var b=new Map;function _(e){return b.has(e)||b.set(e,N(void 0)),b.get(e)}function H(e,n){let t=n||e.name||"action",o=async r=>{let[,a]=_(t),i=()=>a(void 0),s=()=>o(r);a({input:r,pending:!0,clear:i,retry:s});try{let c=await e(r);return a({input:r,result:c,pending:!1,clear:i,retry:s}),c}catch(c){throw a({input:r,error:c,pending:!1,clear:i,retry:s}),c}};return o.url=t,o.with=r=>H((...a)=>e(r,...a),n),o}function de(e){let[n]=_(e.url);return n}function fe(e){return e}var le=M(),ft=le.Provider;import{untrack as V,createMemo as pe,createResource as ye}from"@fluixi/reactive/signal";function me(e,n){let t,o,r;function a(){return o||(o=e().then(s=>t=s.default)),o}n?.preload&&a();let i=(s=>{if(t){let c=t;return V(()=>c(s))}if(!r){let[c]=ye(()=>a());if(r=c,c.error)throw c.error}return pe(()=>{let c=r();return c?V(()=>c(s)):void 0},void 0,{name:"lazy"})});return i.preload=()=>a().then(()=>{}),i.$lazy=!0,i.loader=e,i}import{runWithOwner as Wt}from"@fluixi/reactive/signal";var T=v(),j=v(),U=v(),I=v();function Pe(e,n,t){let o,r=e.route.data;if(typeof r=="function"){let x=!1;A(()=>{x=!0});let $=xe(),[q]=ge(()=>r({params:t.params,location:t.location},$,()=>x));o=q}let a=()=>I.Provider({value:o,get children(){return U.Provider({value:e.params,get children(){return j.Provider({value:{depth:n,...t},get children(){return F(e.component,{})}})}})}});if(!o)return a();let i=o,s=()=>i.loading,[c,f]=P(R(()=>!s()));return w(()=>f(!s())),d(()=>c()?a():null)}function z(e){let n=e.depth+1,[t,o]=P(R(()=>e.matched()[n]?.component));return w(()=>{let r=e.matched()[n]?.component;o(()=>r)}),d(()=>{if(!t())return e.notFound?e.notFound():null;let a=R(()=>e.matched())[n];return Pe(a,n,{matched:e.matched,params:e.params,location:e.location})})}function we(e){return e==null?Ae():typeof e=="function"?F(e,{}):e}function Ae(){let e=g("div");u(e,"class","fx-not-found"),u(e,"role","main"),u(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=g("h1");u(n,"style","margin:0;font-size:2.5rem;font-weight:700"),h(n,"404");let t=g("p");return u(t,"style","margin:0;opacity:.7"),h(t,"This page could not be found."),e.appendChild(n),e.appendChild(t),e}function bt(e){let n=e.history??Ce(),t=Te({routes:e.routes,base:e.base,history:n}),[o,r]=P(t.state()),a=t.subscribe(r);A(()=>{a(),t.destroy()});let i=d(()=>(o().match?.matched??[]).filter(x=>x.component)),s={router:t,location:d(()=>o().location),params:d(()=>o().match?.params??{})},c={depth:-1,matched:i,params:s.params,location:s.location,notFound:()=>we(e.notFound)},f;return T.Provider({value:s,get children(){return f??=z(c)}})}function Rt(){let e=p(j);return e?z(e):null}function Pt(e){let n=p(T);if(!n||typeof window>"u")return null;let t=!1;return A(()=>t=!0),queueMicrotask(()=>{t||n.router.navigate(e.to,{replace:e.replace!==!1})}),null}var Se={router:{navigate:()=>{}},location:()=>({pathname:"",search:"",hash:"",query:{}}),params:()=>({})};function S(){let e=p(T);if(e)return e;if(typeof window>"u")return Se;throw new Error("[router-next] useRouter must be used within <Router>")}function K(){let e=S().params;return d(()=>e(),{},{equals:(n,t)=>JSON.stringify(n)===JSON.stringify(t)})}function wt(){return p(U)??{}}function At(e){let n=K();return d(()=>n()[e])}function St(e,n){let t=K();return d(()=>e(t()),void 0,n?{equals:n}:void 0)}function Ot(e){let n=W();return d(()=>Re(typeof e=="function"?e():e,n.pathname))}function Et(){let e=W(),n=Oe();return[d(()=>e.query),(r,a)=>{let i=new URLSearchParams(e.search);for(let[c,f]of Object.entries(r))f===null?i.delete(c):i.set(c,f);let s=i.toString();n(e.pathname+(s?`?${s}`:""),a)}]}function Lt(e,n){let t=(o,r)=>ve(o,r);return n!==void 0?d(()=>he(e(),n),void 0,{equals:t}):d(e,void 0,{equals:t})}function W(){let{location:e}=S();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 Oe(){let{router:e}=S();return(n,t)=>e.navigate(n,t)}function Dt(){return p(I)??(()=>{})}var l=e=>typeof e=="function"?e():e;function Ee(e){let n=p(T),t=typeof document>"u",o=()=>n?.router.navigate(l(e.href)??"",{replace:l(e.replace)}),r=g("a");if(u(r,"href",l(e.href)??""),e.slot&&u(r,"slot",l(e.slot)),typeof r.addEventListener=="function")r.addEventListener("click",i=>{i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||(i.preventDefault(),o())});else{let i=l(e.className??e.class)??"";i&&u(r,"class",i)}typeof r.addEventListener=="function"&&w(()=>{let i=l(e.href)??"";r.setAttribute("href",i);let s=l(e.className??e.class)??"",c=l(e.activeClass)??"",f=l(e.active)??n?.location().pathname===i;r.className=[s,f?c:""].filter(Boolean).join(" ")});let a=e.children;return a!=null&&h(r,a),r}var kt=Ee;function Mt(e){let n=e.action,t=e.className??e.class,o=n.url??"",r=g("form");u(r,"method","post"),o&&u(r,"action",o),t&&u(r,"class",t);for(let[i,s]of Object.entries(e))i==="action"||i==="children"||i==="class"||i==="className"||s!=null&&typeof s!="function"&&u(r,i,String(s));typeof r.addEventListener=="function"&&r.addEventListener("submit",i=>{i.preventDefault();let s={};new FormData(r).forEach((c,f)=>{s[f]=c}),Promise.resolve(n(s)).catch(()=>{})});let a=e.children;return a!=null&&h(r,a),r}async function Nt(e,n){let t=be(e,n);if(!t)return;let o=[];for(let r of t.matched){let a=r.component;a&&typeof a.preload=="function"&&o.push(a.preload())}await Promise.all(o)}export{kt as A,Mt as Form,Ee as Link,Rt as Outlet,Pt as Redirect,bt as Router,H as action,ae as cache,ue as createAsync,Ft as createBrowserHistory,Vt as createMemoryHistory,me as lazy,Ut as matchPath,jt as matchRoutes,Nt as preloadRoutes,ce as revalidate,Wt as runWithOwner,Lt as select,fe as useAction,wt as useLevelParams,W as useLocation,Ot as useMatch,Oe as useNavigate,At as useParam,St as useParamSelector,K as useParams,Dt as useRouteData,S as useRouter,Et as useSearchParams,de as useSubmission};
1
+ import{createSignal as P,createMemo as d,createResource as ge,createEffect as w,getOwner as xe,onCleanup as A,untrack as R}from"@fluixi/reactive/signal";import{insert as h,createComponent as F,createNativeElement as g,setAttribute as u}from"@fluixi/dom";import{createContext as v,useContext as p}from"@fluixi/reactive/signal";import{get as he}from"@fluixi/utils/object";import{deepEqual as ve}from"@fluixi/utils/compare";import{createRouter as Te,createBrowserHistory as Ce,matchRoutes as be,matchPath as Re}from"@fluixi/router";import{createMemoryHistory as Ft,createBrowserHistory as jt,matchRoutes as Ut,matchPath as It}from"@fluixi/router";import{createResource as oe,createSignal as N}from"@fluixi/reactive/signal";var B=!1,C=new Map;function O(){return B}function E(e,n){C.set(e,n)}function L(e){return C.get(e)}function J(){C.clear()}function X(){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=[],o;for(;o=n.nextNode();){let r=o,a=r.nodeValue||"";(a.startsWith("#")||a.startsWith("/"))&&t.push(r)}t.forEach(r=>r.remove()),J()}typeof window<"u"&&window.addEventListener("load",()=>{setTimeout(X,100)});function D(){return typeof window>"u"}import{asProvider as ne}from"@fluixi/dom";import{createContext as re,useContext as Ze}from"@fluixi/reactive/signal";import{readChildren as rt}from"@fluixi/reactive/signal";import{registerCreateComponent as Y,asComponent as G}from"@fluixi/dom";import{untrack as Q,onCleanup as Ne,getOwner as _e,createEffect as He,createMemo as Ve,createSignal as Fe,isSignal as Z,batch as je,runWithOwner as Ie,isOwnerDisposed as ze}from"@fluixi/reactive/signal";function k(e){Y(ee)}function ee(e,n){return te(e,n)}function te(e,n){let t=typeof e=="function"?Q(()=>e(n)):e;if(t!=null&&(typeof t=="function"||typeof t=="object")&&!Z(t)){try{t.$name=e.name}catch{}return G(t)}return t}k("index");function M(e){let n=re(e),t=o=>(o.debug,n.Provider({value:o.value,get children(){return o.children},debug:o.debug}));return typeof Symbol<"u"&&Symbol.for&&(t.$$typeof=Symbol.for("react.provider")),t.$$typeof=Symbol.for("react.provider"),{id:n.id,Provider:ne(t),defaultValue:e}}var m=new Map,y=new Map;function ae(e,n){return async(...t)=>{let o=n+":"+JSON.stringify(t);if(O()||typeof window<"u"){let a=L(o);if(a!==void 0)return a}if(m.has(o))return m.get(o);if(y.has(o))return y.get(o);let r=Promise.resolve(e(...t)).then(a=>(m.set(o,a),y.delete(o),D()&&E(o,a),a),a=>{throw y.delete(o),a});return y.set(o,r),r}}var[ft,ie]=N(0),se=new Set;function ce(e){let n=typeof e=="string"?t=>t.startsWith(e):e;for(let t of m.keys())n(t)&&(m.delete(t),se.add(t));ie(t=>t+1)}function ue(e,n){let[t]=oe(n||(()=>!0),e);return t}var b=new Map;function _(e){return b.has(e)||b.set(e,N(void 0)),b.get(e)}function H(e,n){let t=n||e.name||"action",o=async r=>{let[,a]=_(t),i=()=>a(void 0),s=()=>o(r);a({input:r,pending:!0,clear:i,retry:s});try{let c=await e(r);return a({input:r,result:c,pending:!1,clear:i,retry:s}),c}catch(c){throw a({input:r,error:c,pending:!1,clear:i,retry:s}),c}};return o.url=t,o.with=r=>H((...a)=>e(r,...a),n),o}function de(e){let[n]=_(e.url);return n}function fe(e){return e}var le=M(),lt=le.Provider;import{untrack as V,createMemo as pe,createResource as ye}from"@fluixi/reactive/signal";function me(e,n){let t,o,r;function a(){return o||(o=e().then(s=>t=s.default)),o}n?.preload&&a();let i=(s=>{if(t){let c=t;return V(()=>c(s))}if(!r){let[c]=ye(()=>a());if(r=c,c.error)throw c.error}return pe(()=>{let c=r();return c?V(()=>c(s)):void 0},void 0,{name:"lazy"})});return i.preload=()=>a().then(()=>{}),i.$lazy=!0,i.loader=e,i}import{runWithOwner as $t}from"@fluixi/reactive/signal";var T=v(),j=v(),U=v(),I=v();function Pe(e,n,t){let o,r=e.route.data;if(typeof r=="function"){let x=!1;A(()=>{x=!0});let $=xe(),[q]=ge(()=>r({params:t.params,location:t.location},$,()=>x));o=q}let a=()=>I.Provider({value:o,get children(){return U.Provider({value:e.params,get children(){return j.Provider({value:{depth:n,...t},get children(){return F(e.component,{})}})}})}});if(!o)return a();let i=o,s=()=>i.loading,[c,f]=P(R(()=>!s()));return w(()=>f(!s())),d(()=>c()?a():null)}function z(e){let n=e.depth+1,[t,o]=P(R(()=>e.matched()[n]?.component));return w(()=>{let r=e.matched()[n]?.component;o(()=>r)}),d(()=>{if(!t())return e.notFound?e.notFound():null;let a=R(()=>e.matched())[n];return Pe(a,n,{matched:e.matched,params:e.params,location:e.location})})}function we(e){return e==null?Ae():typeof e=="function"?F(e,{}):e}function Ae(){let e=g("div");u(e,"class","fx-not-found"),u(e,"role","main"),u(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=g("h1");u(n,"style","margin:0;font-size:2.5rem;font-weight:700"),h(n,"404");let t=g("p");return u(t,"style","margin:0;opacity:.7"),h(t,"This page could not be found."),e.appendChild(n),e.appendChild(t),e}function Rt(e){let n=e.history??Ce(),t=Te({routes:e.routes,base:e.base,history:n}),[o,r]=P(t.state()),a=t.subscribe(r);A(()=>{a(),t.destroy()});let i=d(()=>(o().match?.matched??[]).filter(x=>x.component)),s={router:t,location:d(()=>o().location),params:d(()=>o().match?.params??{})},c={depth:-1,matched:i,params:s.params,location:s.location,notFound:()=>we(e.notFound)},f;return T.Provider({value:s,get children(){return f??=z(c)}})}function Pt(){let e=p(j);return e?z(e):null}function wt(e){let n=p(T);if(!n||typeof window>"u")return null;let t=!1;return A(()=>t=!0),queueMicrotask(()=>{t||n.router.navigate(e.to,{replace:e.replace!==!1})}),null}var Se={router:{navigate:()=>{}},location:()=>({pathname:"",search:"",hash:"",query:{}}),params:()=>({})};function S(){let e=p(T);if(e)return e;if(typeof window>"u")return Se;throw new Error("[router-next] useRouter must be used within <Router>")}function K(){let e=S().params;return d(()=>e(),{},{equals:(n,t)=>JSON.stringify(n)===JSON.stringify(t)})}function At(){return p(U)??{}}function St(e){let n=K();return d(()=>n()[e])}function Ot(e,n){let t=K();return d(()=>e(t()),void 0,n?{equals:n}:void 0)}function Et(e){let n=W();return d(()=>Re(typeof e=="function"?e():e,n.pathname))}function Lt(){let e=W(),n=Oe();return[d(()=>e.query),(r,a)=>{let i=new URLSearchParams(e.search);for(let[c,f]of Object.entries(r))f===null?i.delete(c):i.set(c,f);let s=i.toString();n(e.pathname+(s?`?${s}`:""),a)}]}function Dt(e,n){let t=(o,r)=>ve(o,r);return n!==void 0?d(()=>he(e(),n),void 0,{equals:t}):d(e,void 0,{equals:t})}function W(){let{location:e}=S();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 Oe(){let{router:e}=S();return(n,t)=>e.navigate(n,t)}function kt(){return p(I)??(()=>{})}var l=e=>typeof e=="function"?e():e;function Ee(e){let n=p(T),t=typeof document>"u",o=()=>n?.router.navigate(l(e.href)??"",{replace:l(e.replace)}),r=g("a");if(u(r,"href",l(e.href)??""),e.slot&&u(r,"slot",l(e.slot)),typeof r.addEventListener=="function")r.addEventListener("click",i=>{i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||(i.preventDefault(),o())});else{let i=l(e.className??e.class)??"";i&&u(r,"class",i)}typeof r.addEventListener=="function"&&w(()=>{let i=l(e.href)??"";r.setAttribute("href",i);let s=l(e.className??e.class)??"",c=l(e.activeClass)??"",f=l(e.active)??n?.location().pathname===i;r.className=[s,f?c:""].filter(Boolean).join(" ")});let a=e.children;return a!=null&&h(r,a),r}var Mt=Ee;function Nt(e){let n=e.action,t=e.className??e.class,o=n.url??"",r=g("form");u(r,"method","post"),o&&u(r,"action",o),t&&u(r,"class",t);for(let[i,s]of Object.entries(e))i==="action"||i==="children"||i==="class"||i==="className"||s!=null&&typeof s!="function"&&u(r,i,String(s));typeof r.addEventListener=="function"&&r.addEventListener("submit",i=>{i.preventDefault();let s={};new FormData(r).forEach((c,f)=>{s[f]=c}),Promise.resolve(n(s)).catch(()=>{})});let a=e.children;return a!=null&&h(r,a),r}async function _t(e,n){let t=be(e,n);if(!t)return;let o=[];for(let r of t.matched){let a=r.component;a&&typeof a.preload=="function"&&o.push(a.preload())}await Promise.all(o)}export{Mt as A,Nt as Form,Ee as Link,Pt as Outlet,wt as Redirect,Rt as Router,H as action,ae as cache,ue as createAsync,jt as createBrowserHistory,Ft as createMemoryHistory,me as lazy,It as matchPath,Ut as matchRoutes,_t as preloadRoutes,ce as revalidate,$t as runWithOwner,Dt as select,fe as useAction,At as useLevelParams,W as useLocation,Et as useMatch,Oe as useNavigate,St as useParam,Ot as useParamSelector,K as useParams,kt as useRouteData,S as useRouter,Lt as useSearchParams,de as useSubmission};