@inertiajs/react
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,6 +0,6 @@ | ||
import{router as Se}from"@inertiajs/core";import{setupProgress as Y}from"@inertiajs/core";import{createElement as Z}from"react";import{createHeadManager as Q,router as $}from"@inertiajs/core";import{createElement as R,useEffect as z,useMemo as G,useState as X}from"react";import{createContext as q}from"react";var B=q(void 0);B.displayName="InertiaHeadContext";var A=B;import{createContext as J}from"react";var N=J(void 0);N.displayName="InertiaPageContext";var E=N;function L({children:l,initialPage:c,initialComponent:a,resolveComponent:p,titleCallback:s,onHeadUpdate:S}){let[d,P]=X({component:a||null,page:c,key:null}),u=G(()=>Q(typeof window>"u",s||(f=>f),S||(()=>{})),[]);if(z(()=>{$.init({initialPage:c,resolveComponent:p,swapComponent:async({component:f,page:e,preserveState:i})=>{P(r=>({component:f,page:e,key:i?r.key:Date.now()}))}}),$.on("navigate",()=>u.forceUpdate())},[]),!d.component)return R(A.Provider,{value:u},R(E.Provider,{value:d.page},null));let g=l||(({Component:f,props:e,key:i})=>{let r=R(f,{key:i,...e});return typeof f.layout=="function"?f.layout(r):Array.isArray(f.layout)?f.layout.concat(r).reverse().reduce((y,T)=>R(T,{children:y,...e})):r});return R(A.Provider,{value:u},R(E.Provider,{value:d.page},g({Component:d.component,key:d.key,props:d.page.props})))}L.displayName="Inertia";async function U({id:l="app",resolve:c,setup:a,title:p,progress:s={},page:S,render:d}){let P=typeof window>"u",u=P?null:document.getElementById(l),g=S||JSON.parse(u.dataset.page),f=r=>Promise.resolve(c(r)).then(y=>y.default||y),e=[],i=await f(g.component).then(r=>a({el:u,App:L,props:{initialPage:g,initialComponent:r,resolveComponent:f,titleCallback:p,onHeadUpdate:P?y=>e=y:null}}));if(!P&&s&&Y(s),P){let r=await d(Z("div",{id:l,"data-page":JSON.stringify(g)},i));return{head:e,body:r}}}import V,{useContext as ee,useEffect as te,useMemo as re}from"react";var oe=function({children:l,title:c}){let a=ee(A),p=re(()=>a.createProvider(),[a]);te(()=>()=>{p.disconnect()},[p]);function s(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function S(e){let i=Object.keys(e.props).reduce((r,y)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(y))return r;let T=e.props[y];return T===""?r+` ${y}`:r+` ${y}="${T}"`},"");return`<${e.type}${i}>`}function d(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((i,r)=>i+P(r),"")}function P(e){let i=S(e);return e.props.children&&(i+=d(e)),e.props.dangerouslySetInnerHTML&&(i+=e.props.dangerouslySetInnerHTML.__html),s(e)||(i+=`</${e.type}>`),i}function u(e){return V.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function g(e){return P(u(e))}function f(e){let i=V.Children.toArray(e).filter(r=>r).map(r=>g(r));return c&&!i.find(r=>r.startsWith("<title"))&&i.push(`<title inertia>${c}</title>`),i}return p.update(f(l)),null},ne=oe;import{mergeDataIntoQueryString as se,router as ae,shouldIntercept as ie}from"@inertiajs/core";import{createElement as pe,forwardRef as ue,useCallback as ce}from"react";var k=()=>{},le=ue(({children:l,as:c="a",data:a={},href:p,method:s="get",preserveScroll:S=!1,preserveState:d=null,replace:P=!1,only:u=[],headers:g={},queryStringArrayFormat:f="brackets",onClick:e=k,onCancelToken:i=k,onBefore:r=k,onStart:y=k,onProgress:T=k,onFinish:H=k,onCancel:F=k,onSuccess:M=k,onError:b=k,...O},x)=>{let I=ce(o=>{e(o),ie(o)&&(o.preventDefault(),ae.visit(p,{data:a,method:s,preserveScroll:S,preserveState:d??s!=="get",replace:P,only:u,headers:g,onCancelToken:i,onBefore:r,onStart:y,onProgress:T,onFinish:H,onCancel:F,onSuccess:M,onError:b}))},[a,p,s,S,d,P,u,g,e,i,r,y,T,H,F,M,b]);c=c.toLowerCase(),s=s.toLowerCase();let[h,t]=se(s,p||"",a,f);return p=h,a=t,c==="a"&&s!=="get"&&console.warn(`Creating POST/PUT/PATCH/DELETE <a> links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues. | ||
import{router as Se}from"@inertiajs/core";import{setupProgress as Z}from"@inertiajs/core";import{createElement as ee}from"react";import{createHeadManager as z,router as $}from"@inertiajs/core";import{createElement as R,useEffect as G,useMemo as X,useState as Y}from"react";import{createContext as J}from"react";var B=J(void 0);B.displayName="InertiaHeadContext";var A=B;import{createContext as Q}from"react";var N=Q(void 0);N.displayName="InertiaPageContext";var E=N;function M({children:l,initialPage:c,initialComponent:s,resolveComponent:p,titleCallback:a,onHeadUpdate:S}){let[d,P]=Y({component:s||null,page:c,key:null}),u=X(()=>z(typeof window>"u",a||(f=>f),S||(()=>{})),[]);if(G(()=>{$.init({initialPage:c,resolveComponent:p,swapComponent:async({component:f,page:e,preserveState:i})=>{P(r=>({component:f,page:e,key:i?r.key:Date.now()}))}}),$.on("navigate",()=>u.forceUpdate())},[]),!d.component)return R(A.Provider,{value:u},R(E.Provider,{value:d.page},null));let g=l||(({Component:f,props:e,key:i})=>{let r=R(f,{key:i,...e});return typeof f.layout=="function"?f.layout(r):Array.isArray(f.layout)?f.layout.concat(r).reverse().reduce((y,T)=>R(T,{children:y,...e})):r});return R(A.Provider,{value:u},R(E.Provider,{value:d.page},g({Component:d.component,key:d.key,props:d.page.props})))}M.displayName="Inertia";async function U({id:l="app",resolve:c,setup:s,title:p,progress:a={},page:S,render:d}){let P=typeof window>"u",u=P?null:document.getElementById(l),g=S||JSON.parse(u.dataset.page),f=r=>Promise.resolve(c(r)).then(y=>y.default||y),e=[],i=await f(g.component).then(r=>s({el:u,App:M,props:{initialPage:g,initialComponent:r,resolveComponent:f,titleCallback:p,onHeadUpdate:P?y=>e=y:null}}));if(!P&&a&&Z(a),P){let r=await d(ee("div",{id:l,"data-page":JSON.stringify(g)},i));return{head:e,body:r}}}import V,{useContext as te,useEffect as re,useMemo as oe}from"react";var ne=function({children:l,title:c}){let s=te(A),p=oe(()=>s.createProvider(),[s]);re(()=>()=>{p.disconnect()},[p]);function a(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function S(e){let i=Object.keys(e.props).reduce((r,y)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(y))return r;let T=e.props[y];return T===""?r+` ${y}`:r+` ${y}="${T}"`},"");return`<${e.type}${i}>`}function d(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((i,r)=>i+P(r),"")}function P(e){let i=S(e);return e.props.children&&(i+=d(e)),e.props.dangerouslySetInnerHTML&&(i+=e.props.dangerouslySetInnerHTML.__html),a(e)||(i+=`</${e.type}>`),i}function u(e){return V.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function g(e){return P(u(e))}function f(e){let i=V.Children.toArray(e).filter(r=>r).map(r=>g(r));return c&&!i.find(r=>r.startsWith("<title"))&&i.push(`<title inertia>${c}</title>`),i}return p.update(f(l)),null},ae=ne;import{mergeDataIntoQueryString as se,router as ie,shouldIntercept as pe}from"@inertiajs/core";import{createElement as ue,forwardRef as ce,useCallback as le}from"react";var k=()=>{},j=ce(({children:l,as:c="a",data:s={},href:p,method:a="get",preserveScroll:S=!1,preserveState:d=null,replace:P=!1,only:u=[],headers:g={},queryStringArrayFormat:f="brackets",onClick:e=k,onCancelToken:i=k,onBefore:r=k,onStart:y=k,onProgress:T=k,onFinish:H=k,onCancel:F=k,onSuccess:L=k,onError:b=k,...O},x)=>{let I=le(o=>{e(o),pe(o)&&(o.preventDefault(),ie.visit(p,{data:s,method:a,preserveScroll:S,preserveState:d??a!=="get",replace:P,only:u,headers:g,onCancelToken:i,onBefore:r,onStart:y,onProgress:T,onFinish:H,onCancel:F,onSuccess:L,onError:b}))},[s,p,a,S,d,P,u,g,e,i,r,y,T,H,F,L,b]);c=c.toLowerCase(),a=a.toLowerCase();let[h,t]=se(a,p||"",s,f);return p=h,s=t,c==="a"&&a!=="get"&&console.warn(`Creating POST/PUT/PATCH/DELETE <a> links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues. | ||
Please specify a more appropriate element using the "as" attribute. For example: | ||
<Link href="${p}" method="${s}" as="button">...</Link>`),pe(c,{...O,...c==="a"?{href:p}:{},ref:x,onClick:I},l)}),de=le;import{router as K}from"@inertiajs/core";import ge from"lodash.isequal";import{useCallback as ye,useEffect as Pe,useRef as D,useState as v}from"react";import{router as j}from"@inertiajs/core";import{useEffect as fe,useState as me}from"react";function w(l,c){let[a,p]=me(()=>{let s=j.restore(c);return s!==void 0?s:l});return fe(()=>{j.remember(a,c)},[a,c]),[a,p]}function _(l,c){let a=D(null),p=typeof l=="string"?l:null,[s,S]=v((typeof l=="string"?c:l)||{}),d=D(null),P=D(null),[u,g]=p?w(s,`${p}:data`):v(s),[f,e]=p?w({},`${p}:errors`):v({}),[i,r]=v(!1),[y,T]=v(!1),[H,F]=v(null),[M,b]=v(!1),[O,x]=v(!1),I=t=>t;Pe(()=>(a.current=!0,()=>{a.current=!1}),[]);let h=ye((t,o,n={})=>{let C={...n,onCancelToken:m=>{if(d.current=m,n.onCancelToken)return n.onCancelToken(m)},onBefore:m=>{if(b(!1),x(!1),clearTimeout(P.current),n.onBefore)return n.onBefore(m)},onStart:m=>{if(T(!0),n.onStart)return n.onStart(m)},onProgress:m=>{if(F(m),n.onProgress)return n.onProgress(m)},onSuccess:m=>{if(a.current&&(T(!1),F(null),e({}),r(!1),b(!0),x(!0),P.current=setTimeout(()=>{a.current&&x(!1)},2e3)),n.onSuccess)return n.onSuccess(m)},onError:m=>{if(a.current&&(T(!1),F(null),e(m),r(!0)),n.onError)return n.onError(m)},onCancel:()=>{if(a.current&&(T(!1),F(null)),n.onCancel)return n.onCancel()},onFinish:()=>{if(a.current&&(T(!1),F(null)),d.current=null,n.onFinish)return n.onFinish()}};t==="delete"?K.delete(o,{...C,data:I(u)}):K[t](o,I(u),C)},[u,e]);return{data:u,setData(t,o){g(typeof t=="string"?{...u,[t]:o}:typeof t=="function"?n=>t(n):t)},isDirty:!ge(u,s),errors:f,hasErrors:i,processing:y,progress:H,wasSuccessful:M,recentlySuccessful:O,transform(t){I=t},setDefaults(t,o){S(typeof t>"u"?()=>u:n=>({...n,...typeof t=="string"?{[t]:o}:t}))},reset(...t){t.length===0?g(s):g(Object.keys(s).filter(o=>t.includes(o)).reduce((o,n)=>(o[n]=s[n],o),{...u}))},setError(t,o){e(n=>{let C={...n,...typeof t=="string"?{[t]:o}:t};return r(Object.keys(C).length>0),C})},clearErrors(...t){e(o=>{let n=Object.keys(o).reduce((C,m)=>({...C,...t.length>0&&!t.includes(m)?{[m]:o[m]}:{}}),{});return r(Object.keys(n).length>0),n})},submit:h,get(t,o){h("get",t,o)},post(t,o){h("post",t,o)},put(t,o){h("put",t,o)},patch(t,o){h("patch",t,o)},delete(t,o){h("delete",t,o)},cancel(){d.current&&d.current.cancel()}}}import{useContext as Te}from"react";function W(){let l=Te(E);if(!l)throw new Error("usePage must be used within the Inertia component");return l}var gt=Se;export{ne as Head,de as Link,U as createInertiaApp,gt as router,_ as useForm,W as usePage,w as useRemember}; | ||
<Link href="${p}" method="${a}" as="button">...</Link>`),ue(c,{...O,...c==="a"?{href:p}:{},ref:x,onClick:I},l)});j.displayName="InertiaLink";var de=j;import{router as _}from"@inertiajs/core";import ge from"lodash.isequal";import{useCallback as ye,useEffect as Pe,useRef as D,useState as v}from"react";import{router as K}from"@inertiajs/core";import{useEffect as fe,useState as me}from"react";function w(l,c){let[s,p]=me(()=>{let a=K.restore(c);return a!==void 0?a:l});return fe(()=>{K.remember(s,c)},[s,c]),[s,p]}function W(l,c){let s=D(null),p=typeof l=="string"?l:null,[a,S]=v((typeof l=="string"?c:l)||{}),d=D(null),P=D(null),[u,g]=p?w(a,`${p}:data`):v(a),[f,e]=p?w({},`${p}:errors`):v({}),[i,r]=v(!1),[y,T]=v(!1),[H,F]=v(null),[L,b]=v(!1),[O,x]=v(!1),I=t=>t;Pe(()=>(s.current=!0,()=>{s.current=!1}),[]);let h=ye((t,o,n={})=>{let C={...n,onCancelToken:m=>{if(d.current=m,n.onCancelToken)return n.onCancelToken(m)},onBefore:m=>{if(b(!1),x(!1),clearTimeout(P.current),n.onBefore)return n.onBefore(m)},onStart:m=>{if(T(!0),n.onStart)return n.onStart(m)},onProgress:m=>{if(F(m),n.onProgress)return n.onProgress(m)},onSuccess:m=>{if(s.current&&(T(!1),F(null),e({}),r(!1),b(!0),x(!0),P.current=setTimeout(()=>{s.current&&x(!1)},2e3)),n.onSuccess)return n.onSuccess(m)},onError:m=>{if(s.current&&(T(!1),F(null),e(m),r(!0)),n.onError)return n.onError(m)},onCancel:()=>{if(s.current&&(T(!1),F(null)),n.onCancel)return n.onCancel()},onFinish:()=>{if(s.current&&(T(!1),F(null)),d.current=null,n.onFinish)return n.onFinish()}};t==="delete"?_.delete(o,{...C,data:I(u)}):_[t](o,I(u),C)},[u,e]);return{data:u,setData(t,o){g(typeof t=="string"?{...u,[t]:o}:typeof t=="function"?n=>t(n):t)},isDirty:!ge(u,a),errors:f,hasErrors:i,processing:y,progress:H,wasSuccessful:L,recentlySuccessful:O,transform(t){I=t},setDefaults(t,o){S(typeof t>"u"?()=>u:n=>({...n,...typeof t=="string"?{[t]:o}:t}))},reset(...t){t.length===0?g(a):g(Object.keys(a).filter(o=>t.includes(o)).reduce((o,n)=>(o[n]=a[n],o),{...u}))},setError(t,o){e(n=>{let C={...n,...typeof t=="string"?{[t]:o}:t};return r(Object.keys(C).length>0),C})},clearErrors(...t){e(o=>{let n=Object.keys(o).reduce((C,m)=>({...C,...t.length>0&&!t.includes(m)?{[m]:o[m]}:{}}),{});return r(Object.keys(n).length>0),n})},submit:h,get(t,o){h("get",t,o)},post(t,o){h("post",t,o)},put(t,o){h("put",t,o)},patch(t,o){h("patch",t,o)},delete(t,o){h("delete",t,o)},cancel(){d.current&&d.current.cancel()}}}import{useContext as Te}from"react";function q(){let l=Te(E);if(!l)throw new Error("usePage must be used within the Inertia component");return l}var gt=Se;export{ae as Head,de as Link,U as createInertiaApp,gt as router,W as useForm,q as usePage,w as useRemember}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,6 +0,6 @@ | ||
var ae=Object.create;var N=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var le=(r,n)=>{for(var o in n)N(r,o,{get:n[o],enumerable:!0})},J=(r,n,o,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of pe(n))!ce.call(r,s)&&s!==o&&N(r,s,{get:()=>n[s],enumerable:!(u=ie(n,s))||u.enumerable});return r};var Q=(r,n,o)=>(o=r!=null?ae(ue(r)):{},J(n||!r||!r.__esModule?N(o,"default",{value:r,enumerable:!0}):o,r)),de=r=>J(N({},"__esModule",{value:!0}),r);var ye={};le(ye,{Head:()=>te,Link:()=>re,createInertiaApp:()=>j,router:()=>ge,useForm:()=>W,usePage:()=>q,useRemember:()=>A});module.exports=de(ye);var se=require("@inertiajs/core");var Z=require("@inertiajs/core"),ee=require("react");var O=require("@inertiajs/core"),k=require("react");var z=require("react"),G=(0,z.createContext)(void 0);G.displayName="InertiaHeadContext";var M=G;var X=require("react"),Y=(0,X.createContext)(void 0);Y.displayName="InertiaPageContext";var L=Y;function $({children:r,initialPage:n,initialComponent:o,resolveComponent:u,titleCallback:s,onHeadUpdate:F}){let[d,T]=(0,k.useState)({component:o||null,page:n,key:null}),l=(0,k.useMemo)(()=>(0,O.createHeadManager)(typeof window>"u",s||(f=>f),F||(()=>{})),[]);if((0,k.useEffect)(()=>{O.router.init({initialPage:n,resolveComponent:u,swapComponent:async({component:f,page:e,preserveState:c})=>{T(a=>({component:f,page:e,key:c?a.key:Date.now()}))}}),O.router.on("navigate",()=>l.forceUpdate())},[]),!d.component)return(0,k.createElement)(M.Provider,{value:l},(0,k.createElement)(L.Provider,{value:d.page},null));let y=r||(({Component:f,props:e,key:c})=>{let a=(0,k.createElement)(f,{key:c,...e});return typeof f.layout=="function"?f.layout(a):Array.isArray(f.layout)?f.layout.concat(a).reverse().reduce((P,S)=>(0,k.createElement)(S,{children:P,...e})):a});return(0,k.createElement)(M.Provider,{value:l},(0,k.createElement)(L.Provider,{value:d.page},y({Component:d.component,key:d.key,props:d.page.props})))}$.displayName="Inertia";async function j({id:r="app",resolve:n,setup:o,title:u,progress:s={},page:F,render:d}){let T=typeof window>"u",l=T?null:document.getElementById(r),y=F||JSON.parse(l.dataset.page),f=a=>Promise.resolve(n(a)).then(P=>P.default||P),e=[],c=await f(y.component).then(a=>o({el:l,App:$,props:{initialPage:y,initialComponent:a,resolveComponent:f,titleCallback:u,onHeadUpdate:T?P=>e=P:null}}));if(!T&&s&&(0,Z.setupProgress)(s),T){let a=await d((0,ee.createElement)("div",{id:r,"data-page":JSON.stringify(y)},c));return{head:e,body:a}}}var h=Q(require("react"),1);var fe=function({children:r,title:n}){let o=(0,h.useContext)(M),u=(0,h.useMemo)(()=>o.createProvider(),[o]);(0,h.useEffect)(()=>()=>{u.disconnect()},[u]);function s(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function F(e){let c=Object.keys(e.props).reduce((a,P)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(P))return a;let S=e.props[P];return S===""?a+` ${P}`:a+` ${P}="${S}"`},"");return`<${e.type}${c}>`}function d(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((c,a)=>c+T(a),"")}function T(e){let c=F(e);return e.props.children&&(c+=d(e)),e.props.dangerouslySetInnerHTML&&(c+=e.props.dangerouslySetInnerHTML.__html),s(e)||(c+=`</${e.type}>`),c}function l(e){return h.default.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function y(e){return T(l(e))}function f(e){let c=h.default.Children.toArray(e).filter(a=>a).map(a=>y(a));return n&&!c.find(a=>a.startsWith("<title"))&&c.push(`<title inertia>${n}</title>`),c}return u.update(f(r)),null},te=fe;var x=require("@inertiajs/core"),I=require("react"),v=()=>{},me=(0,I.forwardRef)(({children:r,as:n="a",data:o={},href:u,method:s="get",preserveScroll:F=!1,preserveState:d=null,replace:T=!1,only:l=[],headers:y={},queryStringArrayFormat:f="brackets",onClick:e=v,onCancelToken:c=v,onBefore:a=v,onStart:P=v,onProgress:S=v,onFinish:D=v,onCancel:C=v,onSuccess:B=v,onError:E=v,...V},w)=>{let H=(0,I.useCallback)(i=>{e(i),(0,x.shouldIntercept)(i)&&(i.preventDefault(),x.router.visit(u,{data:o,method:s,preserveScroll:F,preserveState:d??s!=="get",replace:T,only:l,headers:y,onCancelToken:c,onBefore:a,onStart:P,onProgress:S,onFinish:D,onCancel:C,onSuccess:B,onError:E}))},[o,u,s,F,d,T,l,y,e,c,a,P,S,D,C,B,E]);n=n.toLowerCase(),s=s.toLowerCase();let[R,t]=(0,x.mergeDataIntoQueryString)(s,u||"",o,f);return u=R,o=t,n==="a"&&s!=="get"&&console.warn(`Creating POST/PUT/PATCH/DELETE <a> links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues. | ||
var ie=Object.create;var N=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var de=(r,n)=>{for(var o in n)N(r,o,{get:n[o],enumerable:!0})},J=(r,n,o,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of ue(n))!le.call(r,a)&&a!==o&&N(r,a,{get:()=>n[a],enumerable:!(u=pe(n,a))||u.enumerable});return r};var Q=(r,n,o)=>(o=r!=null?ie(ce(r)):{},J(n||!r||!r.__esModule?N(o,"default",{value:r,enumerable:!0}):o,r)),fe=r=>J(N({},"__esModule",{value:!0}),r);var ye={};de(ye,{Head:()=>te,Link:()=>oe,createInertiaApp:()=>j,router:()=>ge,useForm:()=>W,usePage:()=>q,useRemember:()=>A});module.exports=fe(ye);var se=require("@inertiajs/core");var Z=require("@inertiajs/core"),ee=require("react");var O=require("@inertiajs/core"),k=require("react");var z=require("react"),G=(0,z.createContext)(void 0);G.displayName="InertiaHeadContext";var L=G;var X=require("react"),Y=(0,X.createContext)(void 0);Y.displayName="InertiaPageContext";var M=Y;function $({children:r,initialPage:n,initialComponent:o,resolveComponent:u,titleCallback:a,onHeadUpdate:F}){let[d,T]=(0,k.useState)({component:o||null,page:n,key:null}),l=(0,k.useMemo)(()=>(0,O.createHeadManager)(typeof window>"u",a||(f=>f),F||(()=>{})),[]);if((0,k.useEffect)(()=>{O.router.init({initialPage:n,resolveComponent:u,swapComponent:async({component:f,page:e,preserveState:c})=>{T(s=>({component:f,page:e,key:c?s.key:Date.now()}))}}),O.router.on("navigate",()=>l.forceUpdate())},[]),!d.component)return(0,k.createElement)(L.Provider,{value:l},(0,k.createElement)(M.Provider,{value:d.page},null));let y=r||(({Component:f,props:e,key:c})=>{let s=(0,k.createElement)(f,{key:c,...e});return typeof f.layout=="function"?f.layout(s):Array.isArray(f.layout)?f.layout.concat(s).reverse().reduce((P,S)=>(0,k.createElement)(S,{children:P,...e})):s});return(0,k.createElement)(L.Provider,{value:l},(0,k.createElement)(M.Provider,{value:d.page},y({Component:d.component,key:d.key,props:d.page.props})))}$.displayName="Inertia";async function j({id:r="app",resolve:n,setup:o,title:u,progress:a={},page:F,render:d}){let T=typeof window>"u",l=T?null:document.getElementById(r),y=F||JSON.parse(l.dataset.page),f=s=>Promise.resolve(n(s)).then(P=>P.default||P),e=[],c=await f(y.component).then(s=>o({el:l,App:$,props:{initialPage:y,initialComponent:s,resolveComponent:f,titleCallback:u,onHeadUpdate:T?P=>e=P:null}}));if(!T&&a&&(0,Z.setupProgress)(a),T){let s=await d((0,ee.createElement)("div",{id:r,"data-page":JSON.stringify(y)},c));return{head:e,body:s}}}var h=Q(require("react"),1);var me=function({children:r,title:n}){let o=(0,h.useContext)(L),u=(0,h.useMemo)(()=>o.createProvider(),[o]);(0,h.useEffect)(()=>()=>{u.disconnect()},[u]);function a(e){return["area","base","br","col","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"].indexOf(e.type)>-1}function F(e){let c=Object.keys(e.props).reduce((s,P)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(P))return s;let S=e.props[P];return S===""?s+` ${P}`:s+` ${P}="${S}"`},"");return`<${e.type}${c}>`}function d(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((c,s)=>c+T(s),"")}function T(e){let c=F(e);return e.props.children&&(c+=d(e)),e.props.dangerouslySetInnerHTML&&(c+=e.props.dangerouslySetInnerHTML.__html),a(e)||(c+=`</${e.type}>`),c}function l(e){return h.default.cloneElement(e,{inertia:e.props["head-key"]!==void 0?e.props["head-key"]:""})}function y(e){return T(l(e))}function f(e){let c=h.default.Children.toArray(e).filter(s=>s).map(s=>y(s));return n&&!c.find(s=>s.startsWith("<title"))&&c.push(`<title inertia>${n}</title>`),c}return u.update(f(r)),null},te=me;var x=require("@inertiajs/core"),I=require("react"),v=()=>{},re=(0,I.forwardRef)(({children:r,as:n="a",data:o={},href:u,method:a="get",preserveScroll:F=!1,preserveState:d=null,replace:T=!1,only:l=[],headers:y={},queryStringArrayFormat:f="brackets",onClick:e=v,onCancelToken:c=v,onBefore:s=v,onStart:P=v,onProgress:S=v,onFinish:D=v,onCancel:C=v,onSuccess:B=v,onError:E=v,...V},w)=>{let H=(0,I.useCallback)(i=>{e(i),(0,x.shouldIntercept)(i)&&(i.preventDefault(),x.router.visit(u,{data:o,method:a,preserveScroll:F,preserveState:d??a!=="get",replace:T,only:l,headers:y,onCancelToken:c,onBefore:s,onStart:P,onProgress:S,onFinish:D,onCancel:C,onSuccess:B,onError:E}))},[o,u,a,F,d,T,l,y,e,c,s,P,S,D,C,B,E]);n=n.toLowerCase(),a=a.toLowerCase();let[R,t]=(0,x.mergeDataIntoQueryString)(a,u||"",o,f);return u=R,o=t,n==="a"&&a!=="get"&&console.warn(`Creating POST/PUT/PATCH/DELETE <a> links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues. | ||
Please specify a more appropriate element using the "as" attribute. For example: | ||
<Link href="${u}" method="${s}" as="button">...</Link>`),(0,I.createElement)(n,{...V,...n==="a"?{href:u}:{},ref:w,onClick:H},r)}),re=me;var _=require("@inertiajs/core"),oe=Q(require("lodash.isequal"),1),g=require("react");var K=require("@inertiajs/core"),U=require("react");function A(r,n){let[o,u]=(0,U.useState)(()=>{let s=K.router.restore(n);return s!==void 0?s:r});return(0,U.useEffect)(()=>{K.router.remember(o,n)},[o,n]),[o,u]}function W(r,n){let o=(0,g.useRef)(null),u=typeof r=="string"?r:null,[s,F]=(0,g.useState)((typeof r=="string"?n:r)||{}),d=(0,g.useRef)(null),T=(0,g.useRef)(null),[l,y]=u?A(s,`${u}:data`):(0,g.useState)(s),[f,e]=u?A({},`${u}:errors`):(0,g.useState)({}),[c,a]=(0,g.useState)(!1),[P,S]=(0,g.useState)(!1),[D,C]=(0,g.useState)(null),[B,E]=(0,g.useState)(!1),[V,w]=(0,g.useState)(!1),H=t=>t;(0,g.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let R=(0,g.useCallback)((t,i,p={})=>{let b={...p,onCancelToken:m=>{if(d.current=m,p.onCancelToken)return p.onCancelToken(m)},onBefore:m=>{if(E(!1),w(!1),clearTimeout(T.current),p.onBefore)return p.onBefore(m)},onStart:m=>{if(S(!0),p.onStart)return p.onStart(m)},onProgress:m=>{if(C(m),p.onProgress)return p.onProgress(m)},onSuccess:m=>{if(o.current&&(S(!1),C(null),e({}),a(!1),E(!0),w(!0),T.current=setTimeout(()=>{o.current&&w(!1)},2e3)),p.onSuccess)return p.onSuccess(m)},onError:m=>{if(o.current&&(S(!1),C(null),e(m),a(!0)),p.onError)return p.onError(m)},onCancel:()=>{if(o.current&&(S(!1),C(null)),p.onCancel)return p.onCancel()},onFinish:()=>{if(o.current&&(S(!1),C(null)),d.current=null,p.onFinish)return p.onFinish()}};t==="delete"?_.router.delete(i,{...b,data:H(l)}):_.router[t](i,H(l),b)},[l,e]);return{data:l,setData(t,i){y(typeof t=="string"?{...l,[t]:i}:typeof t=="function"?p=>t(p):t)},isDirty:!(0,oe.default)(l,s),errors:f,hasErrors:c,processing:P,progress:D,wasSuccessful:B,recentlySuccessful:V,transform(t){H=t},setDefaults(t,i){F(typeof t>"u"?()=>l:p=>({...p,...typeof t=="string"?{[t]:i}:t}))},reset(...t){t.length===0?y(s):y(Object.keys(s).filter(i=>t.includes(i)).reduce((i,p)=>(i[p]=s[p],i),{...l}))},setError(t,i){e(p=>{let b={...p,...typeof t=="string"?{[t]:i}:t};return a(Object.keys(b).length>0),b})},clearErrors(...t){e(i=>{let p=Object.keys(i).reduce((b,m)=>({...b,...t.length>0&&!t.includes(m)?{[m]:i[m]}:{}}),{});return a(Object.keys(p).length>0),p})},submit:R,get(t,i){R("get",t,i)},post(t,i){R("post",t,i)},put(t,i){R("put",t,i)},patch(t,i){R("patch",t,i)},delete(t,i){R("delete",t,i)},cancel(){d.current&&d.current.cancel()}}}var ne=require("react");function q(){let r=(0,ne.useContext)(L);if(!r)throw new Error("usePage must be used within the Inertia component");return r}var ge=se.router; | ||
<Link href="${u}" method="${a}" as="button">...</Link>`),(0,I.createElement)(n,{...V,...n==="a"?{href:u}:{},ref:w,onClick:H},r)});re.displayName="InertiaLink";var oe=re;var _=require("@inertiajs/core"),ne=Q(require("lodash.isequal"),1),g=require("react");var K=require("@inertiajs/core"),U=require("react");function A(r,n){let[o,u]=(0,U.useState)(()=>{let a=K.router.restore(n);return a!==void 0?a:r});return(0,U.useEffect)(()=>{K.router.remember(o,n)},[o,n]),[o,u]}function W(r,n){let o=(0,g.useRef)(null),u=typeof r=="string"?r:null,[a,F]=(0,g.useState)((typeof r=="string"?n:r)||{}),d=(0,g.useRef)(null),T=(0,g.useRef)(null),[l,y]=u?A(a,`${u}:data`):(0,g.useState)(a),[f,e]=u?A({},`${u}:errors`):(0,g.useState)({}),[c,s]=(0,g.useState)(!1),[P,S]=(0,g.useState)(!1),[D,C]=(0,g.useState)(null),[B,E]=(0,g.useState)(!1),[V,w]=(0,g.useState)(!1),H=t=>t;(0,g.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let R=(0,g.useCallback)((t,i,p={})=>{let b={...p,onCancelToken:m=>{if(d.current=m,p.onCancelToken)return p.onCancelToken(m)},onBefore:m=>{if(E(!1),w(!1),clearTimeout(T.current),p.onBefore)return p.onBefore(m)},onStart:m=>{if(S(!0),p.onStart)return p.onStart(m)},onProgress:m=>{if(C(m),p.onProgress)return p.onProgress(m)},onSuccess:m=>{if(o.current&&(S(!1),C(null),e({}),s(!1),E(!0),w(!0),T.current=setTimeout(()=>{o.current&&w(!1)},2e3)),p.onSuccess)return p.onSuccess(m)},onError:m=>{if(o.current&&(S(!1),C(null),e(m),s(!0)),p.onError)return p.onError(m)},onCancel:()=>{if(o.current&&(S(!1),C(null)),p.onCancel)return p.onCancel()},onFinish:()=>{if(o.current&&(S(!1),C(null)),d.current=null,p.onFinish)return p.onFinish()}};t==="delete"?_.router.delete(i,{...b,data:H(l)}):_.router[t](i,H(l),b)},[l,e]);return{data:l,setData(t,i){y(typeof t=="string"?{...l,[t]:i}:typeof t=="function"?p=>t(p):t)},isDirty:!(0,ne.default)(l,a),errors:f,hasErrors:c,processing:P,progress:D,wasSuccessful:B,recentlySuccessful:V,transform(t){H=t},setDefaults(t,i){F(typeof t>"u"?()=>l:p=>({...p,...typeof t=="string"?{[t]:i}:t}))},reset(...t){t.length===0?y(a):y(Object.keys(a).filter(i=>t.includes(i)).reduce((i,p)=>(i[p]=a[p],i),{...l}))},setError(t,i){e(p=>{let b={...p,...typeof t=="string"?{[t]:i}:t};return s(Object.keys(b).length>0),b})},clearErrors(...t){e(i=>{let p=Object.keys(i).reduce((b,m)=>({...b,...t.length>0&&!t.includes(m)?{[m]:i[m]}:{}}),{});return s(Object.keys(p).length>0),p})},submit:R,get(t,i){R("get",t,i)},post(t,i){R("post",t,i)},put(t,i){R("put",t,i)},patch(t,i){R("patch",t,i)},delete(t,i){R("delete",t,i)},cancel(){d.current&&d.current.cancel()}}}var ae=require("react");function q(){let r=(0,ae.useContext)(M);if(!r)throw new Error("usePage must be used within the Inertia component");return r}var ge=se.router; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@inertiajs/react", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"license": "MIT", | ||
@@ -62,5 +62,5 @@ "description": "The React adapter for Inertia.js", | ||
"dependencies": { | ||
"@inertiajs/core": "1.0.3", | ||
"@inertiajs/core": "1.0.4", | ||
"lodash.isequal": "^4.5.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
94812
+ Added@inertiajs/core@1.0.4(transitive)
- Removed@inertiajs/core@1.0.3(transitive)
Updated@inertiajs/core@1.0.4