@inertiajs/react
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,2 +0,2 @@ | ||
import{router as et}from"@inertiajs/core";import{router as be,setupProgress as ke}from"@inertiajs/core";import{createElement as Ce}from"react";import{createHeadManager as Se,router as G}from"@inertiajs/core";import{createElement as E,useEffect as Te,useMemo as ve,useState as Fe}from"react";import{createContext as ye}from"react";var Y=ye(void 0);Y.displayName="InertiaHeadContext";var w=Y;import{createContext as he}from"react";var z=he(void 0);z.displayName="InertiaPageContext";var O=z;function H({children:p,initialPage:r,initialComponent:s,resolveComponent:a,titleCallback:i,onHeadUpdate:P}){let[l,m]=Fe({component:s||null,page:r,key:null}),g=ve(()=>Se(typeof window>"u",i||(f=>f),P||(()=>{})),[]);if(Te(()=>{G.init({initialPage:r,resolveComponent:a,swapComponent:async({component:f,page:e,preserveState:c})=>{m(n=>({component:f,page:e,key:c?n.key:Date.now()}))}}),G.on("navigate",()=>g.forceUpdate())},[]),!l.component)return E(w.Provider,{value:g},E(O.Provider,{value:l.page},null));let y=p||(({Component:f,props:e,key:c})=>{let n=E(f,{key:c,...e});return typeof f.layout=="function"?f.layout(n):Array.isArray(f.layout)?f.layout.concat(n).reverse().reduce((h,S)=>E(S,{children:h,...e})):n});return E(w.Provider,{value:g},E(O.Provider,{value:l.page},y({Component:l.component,key:l.key,props:l.page.props})))}H.displayName="Inertia";async function X({id:p="app",resolve:r,setup:s,title:a,progress:i={},page:P,render:l}){let m=typeof window>"u",g=m?null:document.getElementById(p),y=P||JSON.parse(g.dataset.page),f=n=>Promise.resolve(r(n)).then(h=>h.default||h),e=[],c=await Promise.all([f(y.component),be.decryptHistory().catch(()=>{})]).then(([n])=>s({el:g,App:H,props:{initialPage:y,initialComponent:n,resolveComponent:f,titleCallback:a,onHeadUpdate:m?h=>e=h:null}}));if(!m&&i&&ke(i),m){let n=await l(Ce("div",{id:p,"data-page":JSON.stringify(y)},c));return{head:e,body:n}}}import{useEffect as xe,useState as Ie}from"react";import{useContext as Re}from"react";function V(){let p=Re(O);if(!p)throw new Error("usePage must be used within the Inertia component");return p}var Z=({children:p,data:r,fallback:s})=>{if(!r)throw new Error("`<Deferred>` requires a `data` prop");let[a,i]=Ie(!1),P=V().props,l=Array.isArray(r)?r:[r];return xe(()=>{i(l.every(m=>P[m]!==void 0))},[P,l]),a?p:s};Z.displayName="InertiaDeferred";var Ee=Z;import ee,{useContext as Ae,useEffect as we,useMemo as Oe}from"react";var De=function({children:p,title:r}){let s=Ae(w),a=Oe(()=>s.createProvider(),[s]);we(()=>()=>{a.disconnect()},[a]);function i(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function P(e){let c=Object.keys(e.props).reduce((n,h)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(h))return n;let S=e.props[h];return S===""?n+` ${h}`:n+` ${h}="${S}"`},"");return`<${e.type}${c}>`}function l(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((c,n)=>c+m(n),"")}function m(e){let c=P(e);return e.props.children&&(c+=l(e)),e.props.dangerouslySetInnerHTML&&(c+=e.props.dangerouslySetInnerHTML.__html),i(e)||(c+=`</${e.type}>`),c}function g(e){return ee.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function y(e){return m(g(e))}function f(e){let c=ee.Children.toArray(e).filter(n=>n).map(n=>y(n));return r&&!c.find(n=>n.startsWith("<title"))&&c.push(`<title inertia>${r}</title>`),c}return a.update(f(p)),null},Me=De;import{mergeDataIntoQueryString as Le,router as j,shouldIntercept as W}from"@inertiajs/core";import{createElement as He,forwardRef as Ve,useEffect as te,useMemo as re,useRef as Be,useState as Ne}from"react";var k=()=>{},ne=Ve(({children:p,as:r="a",data:s={},href:a,method:i="get",preserveScroll:P=!1,preserveState:l=null,replace:m=!1,only:g=[],except:y=[],headers:f={},queryStringArrayFormat:e="brackets",async:c=!1,onClick:n=k,onCancelToken:h=k,onBefore:S=k,onStart:R=k,onProgress:x=k,onFinish:B=k,onCancel:L=k,onSuccess:N=k,onError:A=k,prefetch:v=!1,cacheFor:F=0,...t},u)=>{let[o,b]=Ne(0),d=Be(null);r=r.toLowerCase(),i=i.toLowerCase();let[fe,de]=Le(i,a||"",s,e);a=fe,s=de;let q={data:s,method:i,preserveScroll:P,preserveState:l??i!=="get",replace:m,only:g,except:y,headers:f,async:c},J={...q,onCancelToken:h,onBefore:S,onStart(T){b($=>$+1),R(T)},onProgress:x,onFinish(T){b($=>$-1),B(T)},onCancel:L,onSuccess:N,onError:A},U=()=>{j.prefetch(a,q,{cacheFor:me})},I=re(()=>v===!0?["hover"]:v===!1?[]:Array.isArray(v)?v:[v],Array.isArray(v)?v:[v]),me=re(()=>F!==0?F:I.length===1&&I[0]==="click"?0:3e4,[F,I]);te(()=>()=>{clearTimeout(d.current)},[]),te(()=>{I.includes("mount")&&setTimeout(()=>U())},I);let Q={onClick:T=>{n(T),W(T)&&(T.preventDefault(),j.visit(a,J))}},ge={onMouseEnter:()=>{d.current=window.setTimeout(()=>{U()},75)},onMouseLeave:()=>{clearTimeout(d.current)},onClick:Q.onClick},Pe={onMouseDown:T=>{W(T)&&(T.preventDefault(),U())},onMouseUp:T=>{T.preventDefault(),j.visit(a,J)},onClick:T=>{n(T),W(T)&&T.preventDefault()}};return i!=="get"&&(r="button"),He(r,{...t,...{a:{href:a},button:{type:"button"}}[r]||{},ref:u,...(()=>I.includes("hover")?ge:I.includes("click")?Pe:Q)(),"data-loading":o>0?"":void 0},p)});ne.displayName="InertiaLink";var Ue=ne;import{router as se}from"@inertiajs/core";import We from"lodash.isequal";import{useCallback as Ke,useEffect as _e,useRef as K,useState as C}from"react";import{router as oe}from"@inertiajs/core";import{useEffect as $e,useState as je}from"react";function D(p,r){let[s,a]=je(()=>{let i=oe.restore(r);return i!==void 0?i:p});return $e(()=>{oe.remember(s,r)},[s,r]),[s,a]}function ae(p,r){let s=K(null),a=typeof p=="string"?p:null,[i,P]=C((typeof p=="string"?r:p)||{}),l=K(null),m=K(null),[g,y]=a?D(i,`${a}:data`):C(i),[f,e]=a?D({},`${a}:errors`):C({}),[c,n]=C(!1),[h,S]=C(!1),[R,x]=C(null),[B,L]=C(!1),[N,A]=C(!1),v=t=>t;_e(()=>(s.current=!0,()=>{s.current=!1}),[]);let F=Ke((t,u,o={})=>{let b={...o,onCancelToken:d=>{if(l.current=d,o.onCancelToken)return o.onCancelToken(d)},onBefore:d=>{if(L(!1),A(!1),clearTimeout(m.current),o.onBefore)return o.onBefore(d)},onStart:d=>{if(S(!0),o.onStart)return o.onStart(d)},onProgress:d=>{if(x(d),o.onProgress)return o.onProgress(d)},onSuccess:d=>{if(s.current&&(S(!1),x(null),e({}),n(!1),L(!0),A(!0),m.current=setTimeout(()=>{s.current&&A(!1)},2e3)),o.onSuccess)return o.onSuccess(d)},onError:d=>{if(s.current&&(S(!1),x(null),e(d),n(!0)),o.onError)return o.onError(d)},onCancel:()=>{if(s.current&&(S(!1),x(null)),o.onCancel)return o.onCancel()},onFinish:d=>{if(s.current&&(S(!1),x(null)),l.current=null,o.onFinish)return o.onFinish(d)}};t==="delete"?se.delete(u,{...b,data:v(g)}):se[t](u,v(g),b)},[g,e,v]);return{data:g,setData(t,u){y(typeof t=="string"?o=>({...o,[t]:u}):typeof t=="function"?o=>t(o):t)},isDirty:!We(g,i),errors:f,hasErrors:c,processing:h,progress:R,wasSuccessful:B,recentlySuccessful:N,transform(t){v=t},setDefaults(t,u){P(typeof t>"u"?()=>g:o=>({...o,...typeof t=="string"?{[t]:u}:t}))},reset(...t){t.length===0?y(i):y(Object.keys(i).filter(u=>t.includes(u)).reduce((u,o)=>(u[o]=i[o],u),{...g}))},setError(t,u){e(o=>{let b={...o,...typeof t=="string"?{[t]:u}:t};return n(Object.keys(b).length>0),b})},clearErrors(...t){e(u=>{let o=Object.keys(u).reduce((b,d)=>({...b,...t.length>0&&!t.includes(d)?{[d]:u[d]}:{}}),{});return n(Object.keys(o).length>0),o})},submit:F,get(t,u){F("get",t,u)},post(t,u){F("post",t,u)},put(t,u){F("put",t,u)},patch(t,u){F("patch",t,u)},delete(t,u){F("delete",t,u)},cancel(){l.current&&l.current.cancel()}}}import{router as qe}from"@inertiajs/core";import{useEffect as Je,useRef as Qe}from"react";function ie(p,r={},s={keepAlive:!1,autoStart:!0}){let a=Qe(qe.poll(p,r,{...s,autoStart:!1}));return Je(()=>((s.autoStart??!0)&&a.current.start(),()=>a.current.stop()),[]),{stop:a.current.stop,start:a.current.start}}import{router as M}from"@inertiajs/core";import{useEffect as Ye,useState as _}from"react";function pe(p={}){let r=typeof window>"u"?null:M.getCached(window.location.pathname,p),s=typeof window>"u"?null:M.getPrefetching(window.location.pathname,p),[a,i]=_(r?.staleTimestamp||null),[P,l]=_(s!==null),[m,g]=_(r!==null);return Ye(()=>{let y=M.on("prefetching",e=>{e.detail.visit.url.pathname===window.location.pathname&&l(!0)}),f=M.on("prefetched",e=>{e.detail.visit.url.pathname===window.location.pathname&&(l(!1),g(!0),i(e.detail.fetchedAt))});return()=>{f(),y()}},[]),{lastUpdatedAt:a,isPrefetching:P,isPrefetched:m,flush:()=>M.flush(window.location.pathname,p)}}import{router as ze}from"@inertiajs/core";import{createElement as Ge,useEffect as Xe,useRef as ue,useState as le}from"react";var ce=({children:p,data:r,params:s,buffer:a,as:i,always:P,fallback:l})=>{P=P??!1,i=i??"div",l=l??null;let[m,g]=le(!1),[y,f]=le(!1),e=ue(null),c=ue(null),n=()=>{if(r)return{only:Array.isArray(r)?r:[r]};if(!s)throw new Error("You must provide either a `data` or `params` prop.");return s};return Xe(()=>{if(c.current)return e.current=new IntersectionObserver(h=>{if(!h[0].isIntersecting||(P||e.current?.disconnect(),y))return;f(!0);let S=n();ze.reload({...S,onStart:R=>{f(!0),S.onStart?.(R)},onFinish:R=>{g(!0),f(!1),S.onFinish?.(R)}})},{rootMargin:`${a||0}px`}),e.current.observe(c.current),()=>{e.current?.disconnect()}},[c]),P||!m?Ge(i,{props:null,ref:c},m?p:l):m?p:null};ce.displayName="InertiaWhenVisible";var Ze=ce;var hr=et;export{Ee as Deferred,Me as Head,Ue as Link,Ze as WhenVisible,X as createInertiaApp,hr as router,ae as useForm,V as usePage,ie as usePoll,pe as usePrefetch,D as useRemember}; | ||
import{router as rt}from"@inertiajs/core";import{router as Ce,setupProgress as ke}from"@inertiajs/core";import{createElement as Re}from"react";import{createHeadManager as Te,router as se}from"@inertiajs/core";import{createElement as A,useEffect as Fe,useMemo as ve,useState as be}from"react";import{createContext as he}from"react";var oe=he(void 0);oe.displayName="InertiaHeadContext";var M=oe;import{createContext as Se}from"react";var ne=Se(void 0);ne.displayName="InertiaPageContext";var L=ne;function W({children:u,initialPage:o,initialComponent:n,resolveComponent:s,titleCallback:a,onHeadUpdate:m}){let[p,g]=be({component:n||null,page:o,key:null}),P=ve(()=>Te(typeof window>"u",a||(l=>l),m||(()=>{})),[]);if(Fe(()=>{se.init({initialPage:o,resolveComponent:s,swapComponent:async({component:l,page:e,preserveState:f})=>{g(t=>({component:l,page:e,key:f?t.key:Date.now()}))}}),se.on("navigate",()=>P.forceUpdate())},[]),!p.component)return A(M.Provider,{value:P},A(L.Provider,{value:p.page},null));let y=u||(({Component:l,props:e,key:f})=>{let t=A(l,{key:f,...e});return typeof l.layout=="function"?l.layout(t):Array.isArray(l.layout)?l.layout.concat(t).reverse().reduce((h,T)=>A(T,{children:h,...e})):t});return A(M.Provider,{value:P},A(L.Provider,{value:p.page},y({Component:p.component,key:p.key,props:p.page.props})))}W.displayName="Inertia";async function ae({id:u="app",resolve:o,setup:n,title:s,progress:a={},page:m,render:p}){let g=typeof window>"u",P=g?null:document.getElementById(u),y=m||JSON.parse(P.dataset.page),l=t=>Promise.resolve(o(t)).then(h=>h.default||h),e=[],f=await Promise.all([l(y.component),Ce.decryptHistory().catch(()=>{})]).then(([t])=>n({el:P,App:W,props:{initialPage:y,initialComponent:t,resolveComponent:l,titleCallback:s,onHeadUpdate:g?h=>e=h:null}}));if(!g&&a&&ke(a),g){let t=await p(Re("div",{id:u,"data-page":JSON.stringify(y)},f));return{head:e,body:t}}}import{useEffect as Ie,useState as Ee}from"react";import{useContext as xe}from"react";function K(){let u=xe(L);if(!u)throw new Error("usePage must be used within the Inertia component");return u}var ie=({children:u,data:o,fallback:n})=>{if(!o)throw new Error("`<Deferred>` requires a `data` prop");let[s,a]=Ee(!1),m=K().props,p=Array.isArray(o)?o:[o];return Ie(()=>{a(p.every(g=>m[g]!==void 0))},[m,p]),s?u:n};ie.displayName="InertiaDeferred";var Ae=ie;import ue,{useContext as Oe,useEffect as De,useMemo as we}from"react";var Me=function({children:u,title:o}){let n=Oe(M),s=we(()=>n.createProvider(),[n]);De(()=>()=>{s.disconnect()},[s]);function a(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function m(e){let f=Object.keys(e.props).reduce((t,h)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(h))return t;let T=e.props[h];return T===""?t+` ${h}`:t+` ${h}="${T}"`},"");return`<${e.type}${f}>`}function p(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((f,t)=>f+g(t),"")}function g(e){let f=m(e);return e.props.children&&(f+=p(e)),e.props.dangerouslySetInnerHTML&&(f+=e.props.dangerouslySetInnerHTML.__html),a(e)||(f+=`</${e.type}>`),f}function P(e){return ue.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function y(e){return g(P(e))}function l(e){let f=ue.Children.toArray(e).filter(t=>t).map(t=>y(t));return o&&!f.find(t=>t.startsWith("<title"))&&f.push(`<title inertia>${o}</title>`),f}return s.update(l(u)),null},Le=Me;import{mergeDataIntoQueryString as He,router as Z,shouldIntercept as ee}from"@inertiajs/core";import{createElement as Be,forwardRef as Ne,useEffect as pe,useMemo as ce,useRef as Ve,useState as Ue}from"react";var k=()=>{},le=Ne(({children:u,as:o="a",data:n={},href:s,method:a="get",preserveScroll:m=!1,preserveState:p=null,replace:g=!1,only:P=[],except:y=[],headers:l={},queryStringArrayFormat:e="brackets",async:f=!1,onClick:t=k,onCancelToken:h=k,onBefore:T=k,onStart:x=k,onProgress:I=k,onFinish:q=k,onCancel:N=k,onSuccess:J=k,onError:O=k,prefetch:F=!1,cacheFor:b=0,...Q},Y)=>{let[z,V]=Ue(0),D=Ve(null);o=o.toLowerCase(),a=a.toLowerCase();let[E,G]=He(a,s||"",n,e);s=E,n=G;let U={data:n,method:a,preserveScroll:m,preserveState:p??a!=="get",replace:g,only:P,except:y,headers:l,async:f},$={...U,onCancelToken:h,onBefore:T,onStart(c){V(d=>d+1),x(c)},onProgress:I,onFinish(c){V(d=>d-1),q(c)},onCancel:N,onSuccess:J,onError:O},w=()=>{Z.prefetch(s,U,{cacheFor:X})},C=ce(()=>F===!0?["hover"]:F===!1?[]:Array.isArray(F)?F:[F],Array.isArray(F)?F:[F]),X=ce(()=>b!==0?b:C.length===1&&C[0]==="click"?0:3e4,[b,C]);pe(()=>()=>{clearTimeout(D.current)},[]),pe(()=>{C.includes("mount")&&setTimeout(()=>w())},C);let j={onClick:c=>{t(c),ee(c)&&(c.preventDefault(),Z.visit(s,$))}},i={onMouseEnter:()=>{D.current=window.setTimeout(()=>{w()},75)},onMouseLeave:()=>{clearTimeout(D.current)},onClick:j.onClick},S={onMouseDown:c=>{ee(c)&&(c.preventDefault(),w())},onMouseUp:c=>{c.preventDefault(),Z.visit(s,$)},onClick:c=>{t(c),ee(c)&&c.preventDefault()}};return a!=="get"&&(o="button"),Be(o,{...Q,...{a:{href:s},button:{type:"button"}}[o]||{},ref:Y,...(()=>C.includes("hover")?i:C.includes("click")?S:j)(),"data-loading":z>0?"":void 0},u)});le.displayName="InertiaLink";var $e=le;import{router as de}from"@inertiajs/core";import Ke from"lodash.isequal";import{useCallback as v,useEffect as _e,useRef as _,useState as R}from"react";import{router as fe}from"@inertiajs/core";import{useEffect as je,useState as We}from"react";function H(u,o){let[n,s]=We(()=>{let a=fe.restore(o);return a!==void 0?a:u});return je(()=>{fe.remember(n,o)},[n,o]),[n,s]}function me(u,o){let n=_(null),s=typeof u=="string"?u:null,[a,m]=R((typeof u=="string"?o:u)||{}),p=_(null),g=_(null),[P,y]=s?H(a,`${s}:data`):R(a),[l,e]=s?H({},`${s}:errors`):R({}),[f,t]=R(!1),[h,T]=R(!1),[x,I]=R(null),[q,N]=R(!1),[J,O]=R(!1),F=_(i=>i);_e(()=>(n.current=!0,()=>{n.current=!1}),[]);let b=v((i,S,r={})=>{let c={...r,onCancelToken:d=>{if(p.current=d,r.onCancelToken)return r.onCancelToken(d)},onBefore:d=>{if(N(!1),O(!1),clearTimeout(g.current),r.onBefore)return r.onBefore(d)},onStart:d=>{if(T(!0),r.onStart)return r.onStart(d)},onProgress:d=>{if(I(d),r.onProgress)return r.onProgress(d)},onSuccess:d=>{if(n.current&&(T(!1),I(null),e({}),t(!1),N(!0),O(!0),g.current=setTimeout(()=>{n.current&&O(!1)},2e3)),r.onSuccess)return r.onSuccess(d)},onError:d=>{if(n.current&&(T(!1),I(null),e(d),t(!0)),r.onError)return r.onError(d)},onCancel:()=>{if(n.current&&(T(!1),I(null)),r.onCancel)return r.onCancel()},onFinish:d=>{if(n.current&&(T(!1),I(null)),p.current=null,r.onFinish)return r.onFinish(d)}};i==="delete"?de.delete(S,{...c,data:F.current(P)}):de[i](S,F.current(P),c)},[P,e,F]),Q=v((i,S)=>{y(typeof i=="string"?r=>({...r,[i]:S}):typeof i=="function"?r=>i(r):i)},[y]),Y=v((i,S)=>{m(typeof i>"u"?()=>P:r=>({...r,...typeof i=="string"?{[i]:S}:i}))},[P,m]),z=v((...i)=>{i.length===0?y(a):y(S=>Object.keys(a).filter(r=>i.includes(r)).reduce((r,c)=>(r[c]=a[c],r),{...S}))},[y,a]),V=v((i,S)=>{e(r=>{let c={...r,...typeof i=="string"?{[i]:S}:i};return t(Object.keys(c).length>0),c})},[e,t]),D=v((...i)=>{e(S=>{let r=Object.keys(S).reduce((c,d)=>({...c,...i.length>0&&!i.includes(d)?{[d]:S[d]}:{}}),{});return t(Object.keys(r).length>0),r})},[e,t]),E=i=>(S,r)=>{b(i,S,r)},G=v(E("get"),[b]),U=v(E("post"),[b]),$=v(E("put"),[b]),w=v(E("patch"),[b]),C=v(E("delete"),[b]),X=v(()=>{p.current&&p.current.cancel()},[]),j=v(i=>{F.current=i},[]);return{data:P,setData:Q,isDirty:!Ke(P,a),errors:l,hasErrors:f,processing:h,progress:x,wasSuccessful:q,recentlySuccessful:J,transform:j,setDefaults:Y,reset:z,setError:V,clearErrors:D,submit:b,get:G,post:U,put:$,patch:w,delete:C,cancel:X}}import{router as qe}from"@inertiajs/core";import{useEffect as Je,useRef as Qe}from"react";function ge(u,o={},n={keepAlive:!1,autoStart:!0}){let s=Qe(qe.poll(u,o,{...n,autoStart:!1}));return Je(()=>((n.autoStart??!0)&&s.current.start(),()=>s.current.stop()),[]),{stop:s.current.stop,start:s.current.start}}import{router as B}from"@inertiajs/core";import{useEffect as Ye,useState as te}from"react";function Pe(u={}){let o=typeof window>"u"?null:B.getCached(window.location.pathname,u),n=typeof window>"u"?null:B.getPrefetching(window.location.pathname,u),[s,a]=te(o?.staleTimestamp||null),[m,p]=te(n!==null),[g,P]=te(o!==null);return Ye(()=>{let y=B.on("prefetching",e=>{e.detail.visit.url.pathname===window.location.pathname&&p(!0)}),l=B.on("prefetched",e=>{e.detail.visit.url.pathname===window.location.pathname&&(p(!1),P(!0),a(e.detail.fetchedAt))});return()=>{l(),y()}},[]),{lastUpdatedAt:s,isPrefetching:m,isPrefetched:g,flush:()=>B.flush(window.location.pathname,u)}}import{router as ze}from"@inertiajs/core";import{createElement as Ge,useCallback as Xe,useEffect as Ze,useRef as re,useState as et}from"react";var ye=({children:u,data:o,params:n,buffer:s,as:a,always:m,fallback:p})=>{m=m??!1,a=a??"div",p=p??null;let[g,P]=et(!1),y=re(!1),l=re(!1),e=re(null),f=Xe(()=>{if(o)return{only:Array.isArray(o)?o:[o]};if(!n)throw new Error("You must provide either a `data` or `params` prop.");return n},[n,o]);return Ze(()=>{if(!e.current)return;let t=new IntersectionObserver(h=>{if(!h[0].isIntersecting||(!m&&y.current&&t.disconnect(),l.current))return;y.current=!0,l.current=!0;let T=f();ze.reload({...T,onStart:x=>{l.current=!0,T.onStart?.(x)},onFinish:x=>{P(!0),l.current=!1,T.onFinish?.(x),m||t.disconnect()}})},{rootMargin:`${s||0}px`});return t.observe(e.current),()=>{t.disconnect()}},[e,f,s]),m||!g?Ge(a,{props:null,ref:e},g?u:p):g?u:null};ye.displayName="InertiaWhenVisible";var tt=ye;var Sr=rt;export{Ae as Deferred,Le as Head,$e as Link,tt as WhenVisible,ae as createInertiaApp,Sr as router,me as useForm,K as usePage,ge as usePoll,Pe as usePrefetch,H as useRemember}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var Oe=Object.create;var W=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var Me=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var Ve=(r,t)=>{for(var n in t)W(r,n,{get:t[n],enumerable:!0})},pe=(r,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Me(t))!He.call(r,s)&&s!==n&&W(r,s,{get:()=>t[s],enumerable:!(a=De(t,s))||a.enumerable});return r};var ue=(r,t,n)=>(n=r!=null?Oe(Le(r)):{},pe(t||!r||!r.__esModule?W(n,"default",{value:r,enumerable:!0}):n,r)),Be=r=>pe(W({},"__esModule",{value:!0}),r);var $e={};Ve($e,{Deferred:()=>ye,Head:()=>he,Link:()=>Te,WhenVisible:()=>Ce,createInertiaApp:()=>Z,router:()=>Ue,useForm:()=>re,usePage:()=>$,usePoll:()=>ne,usePrefetch:()=>oe,useRemember:()=>M});module.exports=Be($e);var Re=require("@inertiajs/core");var _=require("@inertiajs/core"),me=require("react");var U=require("@inertiajs/core"),k=require("react");var le=require("react"),ce=(0,le.createContext)(void 0);ce.displayName="InertiaHeadContext";var B=ce;var fe=require("react"),de=(0,fe.createContext)(void 0);de.displayName="InertiaPageContext";var N=de;function K({children:r,initialPage:t,initialComponent:n,resolveComponent:a,titleCallback:s,onHeadUpdate:P}){let[l,m]=(0,k.useState)({component:n||null,page:t,key:null}),g=(0,k.useMemo)(()=>(0,U.createHeadManager)(typeof window>"u",s||(f=>f),P||(()=>{})),[]);if((0,k.useEffect)(()=>{U.router.init({initialPage:t,resolveComponent:a,swapComponent:async({component:f,page:e,preserveState:c})=>{m(i=>({component:f,page:e,key:c?i.key:Date.now()}))}}),U.router.on("navigate",()=>g.forceUpdate())},[]),!l.component)return(0,k.createElement)(B.Provider,{value:g},(0,k.createElement)(N.Provider,{value:l.page},null));let y=r||(({Component:f,props:e,key:c})=>{let i=(0,k.createElement)(f,{key:c,...e});return typeof f.layout=="function"?f.layout(i):Array.isArray(f.layout)?f.layout.concat(i).reverse().reduce((h,T)=>(0,k.createElement)(T,{children:h,...e})):i});return(0,k.createElement)(B.Provider,{value:g},(0,k.createElement)(N.Provider,{value:l.page},y({Component:l.component,key:l.key,props:l.page.props})))}K.displayName="Inertia";async function Z({id:r="app",resolve:t,setup:n,title:a,progress:s={},page:P,render:l}){let m=typeof window>"u",g=m?null:document.getElementById(r),y=P||JSON.parse(g.dataset.page),f=i=>Promise.resolve(t(i)).then(h=>h.default||h),e=[],c=await Promise.all([f(y.component),_.router.decryptHistory().catch(()=>{})]).then(([i])=>n({el:g,App:K,props:{initialPage:y,initialComponent:i,resolveComponent:f,titleCallback:a,onHeadUpdate:m?h=>e=h:null}}));if(!m&&s&&(0,_.setupProgress)(s),m){let i=await l((0,me.createElement)("div",{id:r,"data-page":JSON.stringify(y)},c));return{head:e,body:i}}}var q=require("react");var ge=require("react");function $(){let r=(0,ge.useContext)(N);if(!r)throw new Error("usePage must be used within the Inertia component");return r}var Pe=({children:r,data:t,fallback:n})=>{if(!t)throw new Error("`<Deferred>` requires a `data` prop");let[a,s]=(0,q.useState)(!1),P=$().props,l=Array.isArray(t)?t:[t];return(0,q.useEffect)(()=>{s(l.every(m=>P[m]!==void 0))},[P,l]),a?r:n};Pe.displayName="InertiaDeferred";var ye=Pe;var E=ue(require("react"),1);var Ne=function({children:r,title:t}){let n=(0,E.useContext)(B),a=(0,E.useMemo)(()=>n.createProvider(),[n]);(0,E.useEffect)(()=>()=>{a.disconnect()},[a]);function s(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function P(e){let c=Object.keys(e.props).reduce((i,h)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(h))return i;let T=e.props[h];return T===""?i+` ${h}`:i+` ${h}="${T}"`},"");return`<${e.type}${c}>`}function l(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((c,i)=>c+m(i),"")}function m(e){let c=P(e);return e.props.children&&(c+=l(e)),e.props.dangerouslySetInnerHTML&&(c+=e.props.dangerouslySetInnerHTML.__html),s(e)||(c+=`</${e.type}>`),c}function g(e){return E.default.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function y(e){return m(g(e))}function f(e){let c=E.default.Children.toArray(e).filter(i=>i).map(i=>y(i));return t&&!c.find(i=>i.startsWith("<title"))&&c.push(`<title inertia>${t}</title>`),c}return a.update(f(r)),null},he=Ne;var x=require("@inertiajs/core"),F=require("react"),A=()=>{},Se=(0,F.forwardRef)(({children:r,as:t="a",data:n={},href:a,method:s="get",preserveScroll:P=!1,preserveState:l=null,replace:m=!1,only:g=[],except:y=[],headers:f={},queryStringArrayFormat:e="brackets",async:c=!1,onClick:i=A,onCancelToken:h=A,onBefore:T=A,onStart:w=A,onProgress:O=A,onFinish:Y=A,onCancel:j=A,onSuccess:z=A,onError:V=A,prefetch:b=!1,cacheFor:C=0,...o},u)=>{let[p,R]=(0,F.useState)(0),d=(0,F.useRef)(null);t=t.toLowerCase(),s=s.toLowerCase();let[xe,Ie]=(0,x.mergeDataIntoQueryString)(s,a||"",n,e);a=xe,n=Ie;let se={data:n,method:s,preserveScroll:P,preserveState:l??s!=="get",replace:m,only:g,except:y,headers:f,async:c},ae={...se,onCancelToken:h,onBefore:T,onStart(v){R(X=>X+1),w(v)},onProgress:O,onFinish(v){R(X=>X-1),Y(v)},onCancel:j,onSuccess:z,onError:V},G=()=>{x.router.prefetch(a,se,{cacheFor:Ee})},D=(0,F.useMemo)(()=>b===!0?["hover"]:b===!1?[]:Array.isArray(b)?b:[b],Array.isArray(b)?b:[b]),Ee=(0,F.useMemo)(()=>C!==0?C:D.length===1&&D[0]==="click"?0:3e4,[C,D]);(0,F.useEffect)(()=>()=>{clearTimeout(d.current)},[]),(0,F.useEffect)(()=>{D.includes("mount")&&setTimeout(()=>G())},D);let ie={onClick:v=>{i(v),(0,x.shouldIntercept)(v)&&(v.preventDefault(),x.router.visit(a,ae))}},Ae={onMouseEnter:()=>{d.current=window.setTimeout(()=>{G()},75)},onMouseLeave:()=>{clearTimeout(d.current)},onClick:ie.onClick},we={onMouseDown:v=>{(0,x.shouldIntercept)(v)&&(v.preventDefault(),G())},onMouseUp:v=>{v.preventDefault(),x.router.visit(a,ae)},onClick:v=>{i(v),(0,x.shouldIntercept)(v)&&v.preventDefault()}};return s!=="get"&&(t="button"),(0,F.createElement)(t,{...o,...{a:{href:a},button:{type:"button"}}[t]||{},ref:u,...(()=>D.includes("hover")?Ae:D.includes("click")?we:ie)(),"data-loading":p>0?"":void 0},r)});Se.displayName="InertiaLink";var Te=Se;var te=require("@inertiajs/core"),ve=ue(require("lodash.isequal"),1),S=require("react");var ee=require("@inertiajs/core"),J=require("react");function M(r,t){let[n,a]=(0,J.useState)(()=>{let s=ee.router.restore(t);return s!==void 0?s:r});return(0,J.useEffect)(()=>{ee.router.remember(n,t)},[n,t]),[n,a]}function re(r,t){let n=(0,S.useRef)(null),a=typeof r=="string"?r:null,[s,P]=(0,S.useState)((typeof r=="string"?t:r)||{}),l=(0,S.useRef)(null),m=(0,S.useRef)(null),[g,y]=a?M(s,`${a}:data`):(0,S.useState)(s),[f,e]=a?M({},`${a}:errors`):(0,S.useState)({}),[c,i]=(0,S.useState)(!1),[h,T]=(0,S.useState)(!1),[w,O]=(0,S.useState)(null),[Y,j]=(0,S.useState)(!1),[z,V]=(0,S.useState)(!1),b=o=>o;(0,S.useEffect)(()=>(n.current=!0,()=>{n.current=!1}),[]);let C=(0,S.useCallback)((o,u,p={})=>{let R={...p,onCancelToken:d=>{if(l.current=d,p.onCancelToken)return p.onCancelToken(d)},onBefore:d=>{if(j(!1),V(!1),clearTimeout(m.current),p.onBefore)return p.onBefore(d)},onStart:d=>{if(T(!0),p.onStart)return p.onStart(d)},onProgress:d=>{if(O(d),p.onProgress)return p.onProgress(d)},onSuccess:d=>{if(n.current&&(T(!1),O(null),e({}),i(!1),j(!0),V(!0),m.current=setTimeout(()=>{n.current&&V(!1)},2e3)),p.onSuccess)return p.onSuccess(d)},onError:d=>{if(n.current&&(T(!1),O(null),e(d),i(!0)),p.onError)return p.onError(d)},onCancel:()=>{if(n.current&&(T(!1),O(null)),p.onCancel)return p.onCancel()},onFinish:d=>{if(n.current&&(T(!1),O(null)),l.current=null,p.onFinish)return p.onFinish(d)}};o==="delete"?te.router.delete(u,{...R,data:b(g)}):te.router[o](u,b(g),R)},[g,e,b]);return{data:g,setData(o,u){y(typeof o=="string"?p=>({...p,[o]:u}):typeof o=="function"?p=>o(p):o)},isDirty:!(0,ve.default)(g,s),errors:f,hasErrors:c,processing:h,progress:w,wasSuccessful:Y,recentlySuccessful:z,transform(o){b=o},setDefaults(o,u){P(typeof o>"u"?()=>g:p=>({...p,...typeof o=="string"?{[o]:u}:o}))},reset(...o){o.length===0?y(s):y(Object.keys(s).filter(u=>o.includes(u)).reduce((u,p)=>(u[p]=s[p],u),{...g}))},setError(o,u){e(p=>{let R={...p,...typeof o=="string"?{[o]:u}:o};return i(Object.keys(R).length>0),R})},clearErrors(...o){e(u=>{let p=Object.keys(u).reduce((R,d)=>({...R,...o.length>0&&!o.includes(d)?{[d]:u[d]}:{}}),{});return i(Object.keys(p).length>0),p})},submit:C,get(o,u){C("get",o,u)},post(o,u){C("post",o,u)},put(o,u){C("put",o,u)},patch(o,u){C("patch",o,u)},delete(o,u){C("delete",o,u)},cancel(){l.current&&l.current.cancel()}}}var Fe=require("@inertiajs/core"),Q=require("react");function ne(r,t={},n={keepAlive:!1,autoStart:!0}){let a=(0,Q.useRef)(Fe.router.poll(r,t,{...n,autoStart:!1}));return(0,Q.useEffect)(()=>((n.autoStart??!0)&&a.current.start(),()=>a.current.stop()),[]),{stop:a.current.stop,start:a.current.start}}var L=require("@inertiajs/core"),H=require("react");function oe(r={}){let t=typeof window>"u"?null:L.router.getCached(window.location.pathname,r),n=typeof window>"u"?null:L.router.getPrefetching(window.location.pathname,r),[a,s]=(0,H.useState)(t?.staleTimestamp||null),[P,l]=(0,H.useState)(n!==null),[m,g]=(0,H.useState)(t!==null);return(0,H.useEffect)(()=>{let y=L.router.on("prefetching",e=>{e.detail.visit.url.pathname===window.location.pathname&&l(!0)}),f=L.router.on("prefetched",e=>{e.detail.visit.url.pathname===window.location.pathname&&(l(!1),g(!0),s(e.detail.fetchedAt))});return()=>{f(),y()}},[]),{lastUpdatedAt:a,isPrefetching:P,isPrefetched:m,flush:()=>L.router.flush(window.location.pathname,r)}}var be=require("@inertiajs/core"),I=require("react"),ke=({children:r,data:t,params:n,buffer:a,as:s,always:P,fallback:l})=>{P=P??!1,s=s??"div",l=l??null;let[m,g]=(0,I.useState)(!1),[y,f]=(0,I.useState)(!1),e=(0,I.useRef)(null),c=(0,I.useRef)(null),i=()=>{if(t)return{only:Array.isArray(t)?t:[t]};if(!n)throw new Error("You must provide either a `data` or `params` prop.");return n};return(0,I.useEffect)(()=>{if(c.current)return e.current=new IntersectionObserver(h=>{if(!h[0].isIntersecting||(P||e.current?.disconnect(),y))return;f(!0);let T=i();be.router.reload({...T,onStart:w=>{f(!0),T.onStart?.(w)},onFinish:w=>{g(!0),f(!1),T.onFinish?.(w)}})},{rootMargin:`${a||0}px`}),e.current.observe(c.current),()=>{e.current?.disconnect()}},[c]),P||!m?(0,I.createElement)(s,{props:null,ref:c},m?r:l):m?r:null};ke.displayName="InertiaWhenVisible";var Ce=ke;var Ue=Re.router; | ||
var we=Object.create;var Y=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var He=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var Ne=(r,t)=>{for(var o in t)Y(r,o,{get:t[o],enumerable:!0})},me=(r,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Le(t))!Be.call(r,n)&&n!==o&&Y(r,n,{get:()=>t[n],enumerable:!(a=Me(t,n))||a.enumerable});return r};var ge=(r,t,o)=>(o=r!=null?we(He(r)):{},me(t||!r||!r.__esModule?Y(o,"default",{value:r,enumerable:!0}):o,r)),Ve=r=>me(Y({},"__esModule",{value:!0}),r);var je={};Ne(je,{Deferred:()=>be,Head:()=>Ce,Link:()=>Re,WhenVisible:()=>Oe,createInertiaApp:()=>ue,router:()=>$e,useForm:()=>le,usePage:()=>W,usePoll:()=>fe,usePrefetch:()=>de,useRemember:()=>M});module.exports=Ve(je);var De=require("@inertiajs/core");var G=require("@inertiajs/core"),Te=require("react");var j=require("@inertiajs/core"),C=require("react");var Pe=require("react"),ye=(0,Pe.createContext)(void 0);ye.displayName="InertiaHeadContext";var U=ye;var he=require("react"),Se=(0,he.createContext)(void 0);Se.displayName="InertiaPageContext";var $=Se;function z({children:r,initialPage:t,initialComponent:o,resolveComponent:a,titleCallback:n,onHeadUpdate:g}){let[c,P]=(0,C.useState)({component:o||null,page:t,key:null}),y=(0,C.useMemo)(()=>(0,j.createHeadManager)(typeof window>"u",n||(f=>f),g||(()=>{})),[]);if((0,C.useEffect)(()=>{j.router.init({initialPage:t,resolveComponent:a,swapComponent:async({component:f,page:e,preserveState:d})=>{P(s=>({component:f,page:e,key:d?s.key:Date.now()}))}}),j.router.on("navigate",()=>y.forceUpdate())},[]),!c.component)return(0,C.createElement)(U.Provider,{value:y},(0,C.createElement)($.Provider,{value:c.page},null));let h=r||(({Component:f,props:e,key:d})=>{let s=(0,C.createElement)(f,{key:d,...e});return typeof f.layout=="function"?f.layout(s):Array.isArray(f.layout)?f.layout.concat(s).reverse().reduce((S,F)=>(0,C.createElement)(F,{children:S,...e})):s});return(0,C.createElement)(U.Provider,{value:y},(0,C.createElement)($.Provider,{value:c.page},h({Component:c.component,key:c.key,props:c.page.props})))}z.displayName="Inertia";async function ue({id:r="app",resolve:t,setup:o,title:a,progress:n={},page:g,render:c}){let P=typeof window>"u",y=P?null:document.getElementById(r),h=g||JSON.parse(y.dataset.page),f=s=>Promise.resolve(t(s)).then(S=>S.default||S),e=[],d=await Promise.all([f(h.component),G.router.decryptHistory().catch(()=>{})]).then(([s])=>o({el:y,App:z,props:{initialPage:h,initialComponent:s,resolveComponent:f,titleCallback:a,onHeadUpdate:P?S=>e=S:null}}));if(!P&&n&&(0,G.setupProgress)(n),P){let s=await c((0,Te.createElement)("div",{id:r,"data-page":JSON.stringify(h)},d));return{head:e,body:s}}}var X=require("react");var Fe=require("react");function W(){let r=(0,Fe.useContext)($);if(!r)throw new Error("usePage must be used within the Inertia component");return r}var ve=({children:r,data:t,fallback:o})=>{if(!t)throw new Error("`<Deferred>` requires a `data` prop");let[a,n]=(0,X.useState)(!1),g=W().props,c=Array.isArray(t)?t:[t];return(0,X.useEffect)(()=>{n(c.every(P=>g[P]!==void 0))},[g,c]),a?r:o};ve.displayName="InertiaDeferred";var be=ve;var E=ge(require("react"),1);var Ue=function({children:r,title:t}){let o=(0,E.useContext)(U),a=(0,E.useMemo)(()=>o.createProvider(),[o]);(0,E.useEffect)(()=>()=>{a.disconnect()},[a]);function n(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function g(e){let d=Object.keys(e.props).reduce((s,S)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(S))return s;let F=e.props[S];return F===""?s+` ${S}`:s+` ${S}="${F}"`},"");return`<${e.type}${d}>`}function c(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((d,s)=>d+P(s),"")}function P(e){let d=g(e);return e.props.children&&(d+=c(e)),e.props.dangerouslySetInnerHTML&&(d+=e.props.dangerouslySetInnerHTML.__html),n(e)||(d+=`</${e.type}>`),d}function y(e){return E.default.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function h(e){return P(y(e))}function f(e){let d=E.default.Children.toArray(e).filter(s=>s).map(s=>h(s));return t&&!d.find(s=>s.startsWith("<title"))&&d.push(`<title inertia>${t}</title>`),d}return a.update(f(r)),null},Ce=Ue;var x=require("@inertiajs/core"),v=require("react"),A=()=>{},ke=(0,v.forwardRef)(({children:r,as:t="a",data:o={},href:a,method:n="get",preserveScroll:g=!1,preserveState:c=null,replace:P=!1,only:y=[],except:h=[],headers:f={},queryStringArrayFormat:e="brackets",async:d=!1,onClick:s=A,onCancelToken:S=A,onBefore:F=A,onStart:O=A,onProgress:D=A,onFinish:te=A,onCancel:K=A,onSuccess:re=A,onError:B=A,prefetch:b=!1,cacheFor:R=0,...oe},ne)=>{let[se,_]=(0,v.useState)(0),N=(0,v.useRef)(null);t=t.toLowerCase(),n=n.toLowerCase();let[w,ae]=(0,x.mergeDataIntoQueryString)(n,a||"",o,e);a=w,o=ae;let q={data:o,method:n,preserveScroll:g,preserveState:c??n!=="get",replace:P,only:y,except:h,headers:f,async:d},J={...q,onCancelToken:S,onBefore:F,onStart(l){_(m=>m+1),O(l)},onProgress:D,onFinish(l){_(m=>m-1),te(l)},onCancel:K,onSuccess:re,onError:B},V=()=>{x.router.prefetch(a,q,{cacheFor:ie})},I=(0,v.useMemo)(()=>b===!0?["hover"]:b===!1?[]:Array.isArray(b)?b:[b],Array.isArray(b)?b:[b]),ie=(0,v.useMemo)(()=>R!==0?R:I.length===1&&I[0]==="click"?0:3e4,[R,I]);(0,v.useEffect)(()=>()=>{clearTimeout(N.current)},[]),(0,v.useEffect)(()=>{I.includes("mount")&&setTimeout(()=>V())},I);let Q={onClick:l=>{s(l),(0,x.shouldIntercept)(l)&&(l.preventDefault(),x.router.visit(a,J))}},u={onMouseEnter:()=>{N.current=window.setTimeout(()=>{V()},75)},onMouseLeave:()=>{clearTimeout(N.current)},onClick:Q.onClick},T={onMouseDown:l=>{(0,x.shouldIntercept)(l)&&(l.preventDefault(),V())},onMouseUp:l=>{l.preventDefault(),x.router.visit(a,J)},onClick:l=>{s(l),(0,x.shouldIntercept)(l)&&l.preventDefault()}};return n!=="get"&&(t="button"),(0,v.createElement)(t,{...oe,...{a:{href:a},button:{type:"button"}}[t]||{},ref:ne,...(()=>I.includes("hover")?u:I.includes("click")?T:Q)(),"data-loading":se>0?"":void 0},r)});ke.displayName="InertiaLink";var Re=ke;var ce=require("@inertiajs/core"),xe=ge(require("lodash.isequal"),1),p=require("react");var pe=require("@inertiajs/core"),Z=require("react");function M(r,t){let[o,a]=(0,Z.useState)(()=>{let n=pe.router.restore(t);return n!==void 0?n:r});return(0,Z.useEffect)(()=>{pe.router.remember(o,t)},[o,t]),[o,a]}function le(r,t){let o=(0,p.useRef)(null),a=typeof r=="string"?r:null,[n,g]=(0,p.useState)((typeof r=="string"?t:r)||{}),c=(0,p.useRef)(null),P=(0,p.useRef)(null),[y,h]=a?M(n,`${a}:data`):(0,p.useState)(n),[f,e]=a?M({},`${a}:errors`):(0,p.useState)({}),[d,s]=(0,p.useState)(!1),[S,F]=(0,p.useState)(!1),[O,D]=(0,p.useState)(null),[te,K]=(0,p.useState)(!1),[re,B]=(0,p.useState)(!1),b=(0,p.useRef)(u=>u);(0,p.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let R=(0,p.useCallback)((u,T,i={})=>{let l={...i,onCancelToken:m=>{if(c.current=m,i.onCancelToken)return i.onCancelToken(m)},onBefore:m=>{if(K(!1),B(!1),clearTimeout(P.current),i.onBefore)return i.onBefore(m)},onStart:m=>{if(F(!0),i.onStart)return i.onStart(m)},onProgress:m=>{if(D(m),i.onProgress)return i.onProgress(m)},onSuccess:m=>{if(o.current&&(F(!1),D(null),e({}),s(!1),K(!0),B(!0),P.current=setTimeout(()=>{o.current&&B(!1)},2e3)),i.onSuccess)return i.onSuccess(m)},onError:m=>{if(o.current&&(F(!1),D(null),e(m),s(!0)),i.onError)return i.onError(m)},onCancel:()=>{if(o.current&&(F(!1),D(null)),i.onCancel)return i.onCancel()},onFinish:m=>{if(o.current&&(F(!1),D(null)),c.current=null,i.onFinish)return i.onFinish(m)}};u==="delete"?ce.router.delete(T,{...l,data:b.current(y)}):ce.router[u](T,b.current(y),l)},[y,e,b]),oe=(0,p.useCallback)((u,T)=>{h(typeof u=="string"?i=>({...i,[u]:T}):typeof u=="function"?i=>u(i):u)},[h]),ne=(0,p.useCallback)((u,T)=>{g(typeof u>"u"?()=>y:i=>({...i,...typeof u=="string"?{[u]:T}:u}))},[y,g]),se=(0,p.useCallback)((...u)=>{u.length===0?h(n):h(T=>Object.keys(n).filter(i=>u.includes(i)).reduce((i,l)=>(i[l]=n[l],i),{...T}))},[h,n]),_=(0,p.useCallback)((u,T)=>{e(i=>{let l={...i,...typeof u=="string"?{[u]:T}:u};return s(Object.keys(l).length>0),l})},[e,s]),N=(0,p.useCallback)((...u)=>{e(T=>{let i=Object.keys(T).reduce((l,m)=>({...l,...u.length>0&&!u.includes(m)?{[m]:T[m]}:{}}),{});return s(Object.keys(i).length>0),i})},[e,s]),w=u=>(T,i)=>{R(u,T,i)},ae=(0,p.useCallback)(w("get"),[R]),q=(0,p.useCallback)(w("post"),[R]),J=(0,p.useCallback)(w("put"),[R]),V=(0,p.useCallback)(w("patch"),[R]),I=(0,p.useCallback)(w("delete"),[R]),ie=(0,p.useCallback)(()=>{c.current&&c.current.cancel()},[]),Q=(0,p.useCallback)(u=>{b.current=u},[]);return{data:y,setData:oe,isDirty:!(0,xe.default)(y,n),errors:f,hasErrors:d,processing:S,progress:O,wasSuccessful:te,recentlySuccessful:re,transform:Q,setDefaults:ne,reset:se,setError:_,clearErrors:N,submit:R,get:ae,post:q,put:J,patch:V,delete:I,cancel:ie}}var Ie=require("@inertiajs/core"),ee=require("react");function fe(r,t={},o={keepAlive:!1,autoStart:!0}){let a=(0,ee.useRef)(Ie.router.poll(r,t,{...o,autoStart:!1}));return(0,ee.useEffect)(()=>((o.autoStart??!0)&&a.current.start(),()=>a.current.stop()),[]),{stop:a.current.stop,start:a.current.start}}var L=require("@inertiajs/core"),H=require("react");function de(r={}){let t=typeof window>"u"?null:L.router.getCached(window.location.pathname,r),o=typeof window>"u"?null:L.router.getPrefetching(window.location.pathname,r),[a,n]=(0,H.useState)(t?.staleTimestamp||null),[g,c]=(0,H.useState)(o!==null),[P,y]=(0,H.useState)(t!==null);return(0,H.useEffect)(()=>{let h=L.router.on("prefetching",e=>{e.detail.visit.url.pathname===window.location.pathname&&c(!0)}),f=L.router.on("prefetched",e=>{e.detail.visit.url.pathname===window.location.pathname&&(c(!1),y(!0),n(e.detail.fetchedAt))});return()=>{f(),h()}},[]),{lastUpdatedAt:a,isPrefetching:g,isPrefetched:P,flush:()=>L.router.flush(window.location.pathname,r)}}var Ee=require("@inertiajs/core"),k=require("react"),Ae=({children:r,data:t,params:o,buffer:a,as:n,always:g,fallback:c})=>{g=g??!1,n=n??"div",c=c??null;let[P,y]=(0,k.useState)(!1),h=(0,k.useRef)(!1),f=(0,k.useRef)(!1),e=(0,k.useRef)(null),d=(0,k.useCallback)(()=>{if(t)return{only:Array.isArray(t)?t:[t]};if(!o)throw new Error("You must provide either a `data` or `params` prop.");return o},[o,t]);return(0,k.useEffect)(()=>{if(!e.current)return;let s=new IntersectionObserver(S=>{if(!S[0].isIntersecting||(!g&&h.current&&s.disconnect(),f.current))return;h.current=!0,f.current=!0;let F=d();Ee.router.reload({...F,onStart:O=>{f.current=!0,F.onStart?.(O)},onFinish:O=>{y(!0),f.current=!1,F.onFinish?.(O),g||s.disconnect()}})},{rootMargin:`${a||0}px`});return s.observe(e.current),()=>{s.disconnect()}},[e,d,a]),g||!P?(0,k.createElement)(n,{props:null,ref:e},P?r:c):P?r:null};Ae.displayName="InertiaWhenVisible";var Oe=Ae;var $e=De.router; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@inertiajs/react", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
@@ -62,5 +62,5 @@ "description": "The React adapter for Inertia.js", | ||
"dependencies": { | ||
"@inertiajs/core": "2.0.0", | ||
"@inertiajs/core": "2.0.1", | ||
"lodash.isequal": "^4.5.0" | ||
} | ||
} |
@@ -6,3 +6,3 @@ export declare const router: import("@inertiajs/core").Router; | ||
export { InertiaLinkProps, default as Link } from './Link'; | ||
export { default as useForm } from './useForm'; | ||
export { InertiaFormProps, default as useForm } from './useForm'; | ||
export { default as usePage } from './usePage'; | ||
@@ -9,0 +9,0 @@ export { default as usePoll } from './usePoll'; |
@@ -5,3 +5,4 @@ import { FormDataConvertible, Method, Progress, VisitOptions } from '@inertiajs/core'; | ||
type setDataByKeyValuePair<TForm> = <K extends keyof TForm>(key: K, value: TForm[K]) => void; | ||
type FormDataType = object; | ||
type FormDataType = Record<string, FormDataConvertible>; | ||
type FormOptions = Omit<VisitOptions, 'data'>; | ||
export interface InertiaFormProps<TForm extends FormDataType> { | ||
@@ -25,8 +26,8 @@ data: TForm; | ||
setError(errors: Record<keyof TForm, string>): void; | ||
submit: (method: Method, url: string, options?: VisitOptions) => void; | ||
get: (url: string, options?: VisitOptions) => void; | ||
patch: (url: string, options?: VisitOptions) => void; | ||
post: (url: string, options?: VisitOptions) => void; | ||
put: (url: string, options?: VisitOptions) => void; | ||
delete: (url: string, options?: VisitOptions) => void; | ||
submit: (method: Method, url: string, options?: FormOptions) => void; | ||
get: (url: string, options?: FormOptions) => void; | ||
patch: (url: string, options?: FormOptions) => void; | ||
post: (url: string, options?: FormOptions) => void; | ||
put: (url: string, options?: FormOptions) => void; | ||
delete: (url: string, options?: FormOptions) => void; | ||
cancel: () => void; | ||
@@ -33,0 +34,0 @@ } |
@@ -6,3 +6,3 @@ import { ReloadOptions } from '@inertiajs/core'; | ||
fallback: ReactElement | number | string; | ||
data: string | string[]; | ||
data?: string | string[]; | ||
params?: ReloadOptions; | ||
@@ -9,0 +9,0 @@ buffer?: number; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
132460
289
+ Added@inertiajs/core@2.0.1(transitive)
- Removed@inertiajs/core@2.0.0(transitive)
Updated@inertiajs/core@2.0.1