Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@inertiajs/react

Package Overview
Dependencies
Maintainers
6
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@inertiajs/react - npm Package Compare versions

Comparing version 1.0.13 to 1.0.14

4

dist/index.esm.js

@@ -1,6 +0,6 @@

import{router as Fe}from"@inertiajs/core";import{setupProgress as ee}from"@inertiajs/core";import{createElement as te}from"react";import{createHeadManager as G,router as j}from"@inertiajs/core";import{createElement as b,useEffect as X,useMemo as Y,useState as Z}from"react";import{createContext as Q}from"react";var N=Q(void 0);N.displayName="InertiaHeadContext";var A=N;import{createContext as z}from"react";var $=z(void 0);$.displayName="InertiaPageContext";var E=$;function O({children:l,initialPage:c,initialComponent:s,resolveComponent:p,titleCallback:a,onHeadUpdate:S}){let[d,P]=Z({component:s||null,page:c,key:null}),u=Y(()=>G(typeof window>"u",a||(f=>f),S||(()=>{})),[]);if(X(()=>{j.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()}))}}),j.on("navigate",()=>u.forceUpdate())},[]),!d.component)return b(A.Provider,{value:u},b(E.Provider,{value:d.page},null));let g=l||(({Component:f,props:e,key:i})=>{let r=b(f,{key:i,...e});return typeof f.layout=="function"?f.layout(r):Array.isArray(f.layout)?f.layout.concat(r).reverse().reduce((y,T)=>b(T,{children:y,...e})):r});return b(A.Provider,{value:u},b(E.Provider,{value:d.page},g({Component:d.component,key:d.key,props:d.page.props})))}O.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:O,props:{initialPage:g,initialComponent:r,resolveComponent:f,titleCallback:p,onHeadUpdate:P?y=>e=y:null}}));if(!P&&a&&ee(a),P){let r=await d(te("div",{id:l,"data-page":JSON.stringify(g)},i));return{head:e,body:r}}}import V,{useContext as re,useEffect as oe,useMemo as ne}from"react";var ae=function({children:l,title:c}){let s=re(A),p=ne(()=>s.createProvider(),[s]);oe(()=>()=>{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},se=ae;import{mergeDataIntoQueryString as ie,router as pe,shouldIntercept as ue}from"@inertiajs/core";import{createElement as ce,forwardRef as le,useCallback as de}from"react";var F=()=>{},K=le(({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=F,onCancelToken:i=F,onBefore:r=F,onStart:y=F,onProgress:T=F,onFinish:H=F,onCancel:h=F,onSuccess:M=F,onError:x=F,...L},R)=>{let I=de(t=>{e(t),ue(t)&&(t.preventDefault(),pe.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:h,onSuccess:M,onError:x}))},[s,p,a,S,d,P,u,g,e,i,r,y,T,H,h,M,x]);c=c.toLowerCase(),a=a.toLowerCase();let[v,w]=ie(a,p||"",s,f);return p=v,s=w,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.
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 b,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 w({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 b(A.Provider,{value:u},b(E.Provider,{value:d.page},null));let g=l||(({Component:f,props:e,key:i})=>{let r=b(f,{key:i,...e});return typeof f.layout=="function"?f.layout(r):Array.isArray(f.layout)?f.layout.concat(r).reverse().reduce((y,T)=>b(T,{children:y,...e})):r});return b(A.Provider,{value:u},b(E.Provider,{value:d.page},g({Component:d.component,key:d.key,props:d.page.props})))}w.displayName="Inertia";async function j({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:w,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 U,{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 U.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=U.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 F=()=>{},V=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=F,onCancelToken:i=F,onBefore:r=F,onStart:y=F,onProgress:T=F,onFinish:H=F,onCancel:h=F,onSuccess:M=F,onError:x=F,...O},R)=>{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:h,onSuccess:M,onError:x}))},[s,p,a,S,d,P,u,g,e,i,r,y,T,H,h,M,x]);c=c.toLowerCase(),a=a.toLowerCase();let[v,t]=se(a,p||"",s,f);return p=v,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="${a}" as="button">...</Link>`),ce(c,{...L,...c==="a"?{href:p}:{},ref:R,onClick:I},l)});K.displayName="InertiaLink";var fe=K;import{router as W}from"@inertiajs/core";import ye from"lodash.isequal";import{useCallback as Pe,useEffect as Te,useRef as B,useState as C}from"react";import{router as _}from"@inertiajs/core";import{useEffect as me,useState as ge}from"react";function D(l,c){let[s,p]=ge(()=>{let a=_.restore(c);return a!==void 0?a:l});return me(()=>{_.remember(s,c)},[s,c]),[s,p]}function q(l,c){let s=B(null),p=typeof l=="string"?l:null,[a,S]=C((typeof l=="string"?c:l)||{}),d=B(null),P=B(null),[u,g]=p?D(a,`${p}:data`):C(a),[f,e]=p?D({},`${p}:errors`):C({}),[i,r]=C(!1),[y,T]=C(!1),[H,h]=C(null),[M,x]=C(!1),[L,R]=C(!1),I=t=>t;Te(()=>(s.current=!0,()=>{s.current=!1}),[]);let v=Pe((t,n,o={})=>{let k={...o,onCancelToken:m=>{if(d.current=m,o.onCancelToken)return o.onCancelToken(m)},onBefore:m=>{if(x(!1),R(!1),clearTimeout(P.current),o.onBefore)return o.onBefore(m)},onStart:m=>{if(T(!0),o.onStart)return o.onStart(m)},onProgress:m=>{if(h(m),o.onProgress)return o.onProgress(m)},onSuccess:m=>{if(s.current&&(T(!1),h(null),e({}),r(!1),x(!0),R(!0),P.current=setTimeout(()=>{s.current&&R(!1)},2e3)),o.onSuccess)return o.onSuccess(m)},onError:m=>{if(s.current&&(T(!1),h(null),e(m),r(!0)),o.onError)return o.onError(m)},onCancel:()=>{if(s.current&&(T(!1),h(null)),o.onCancel)return o.onCancel()},onFinish:()=>{if(s.current&&(T(!1),h(null)),d.current=null,o.onFinish)return o.onFinish()}};t==="delete"?W.delete(n,{...k,data:I(u)}):W[t](n,I(u),k)},[u,e]);function w(...t){e(n=>{let o=Object.keys(n).reduce((k,m)=>({...k,...t.length>0&&!t.includes(m)?{[m]:n[m]}:{}}),{});return r(Object.keys(o).length>0),o})}return{data:u,setData(t,n){g(typeof t=="string"?{...u,[t]:n}:typeof t=="function"?o=>t(o):t)},isDirty:!ye(u,a),errors:f,hasErrors:i,processing:y,progress:H,wasSuccessful:M,recentlySuccessful:L,transform(t){I=t},setDefaults(t,n){S(typeof t>"u"?()=>u:o=>({...o,...typeof t=="string"?{[t]:n}:t}))},reset(...t){t.length===0?(g(a),e({}),r(!1)):(g(Object.keys(a).filter(n=>t.includes(n)).reduce((n,o)=>(n[o]=a[o],n),{...u})),w(...t))},setError(t,n){e(o=>{let k={...o,...typeof t=="string"?{[t]:n}:t};return r(Object.keys(k).length>0),k})},clearErrors:w,submit:v,get(t,n){v("get",t,n)},post(t,n){v("post",t,n)},put(t,n){v("put",t,n)},patch(t,n){v("patch",t,n)},delete(t,n){v("delete",t,n)},cancel(){d.current&&d.current.cancel()}}}import{useContext as Se}from"react";function J(){let l=Se(E);if(!l)throw new Error("usePage must be used within the Inertia component");return l}var Pt=Fe;export{se as Head,fe as Link,U as createInertiaApp,Pt as router,q as useForm,J as usePage,D as useRemember};
<Link href="${p}" method="${a}" as="button">...</Link>`),ue(c,{...O,...c==="a"?{href:p}:{},ref:R,onClick:I},l)});V.displayName="InertiaLink";var de=V;import{router as _}from"@inertiajs/core";import ge from"lodash.isequal";import{useCallback as ye,useEffect as Pe,useRef as L,useState as C}from"react";import{router as K}from"@inertiajs/core";import{useEffect as fe,useState as me}from"react";function D(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=L(null),p=typeof l=="string"?l:null,[a,S]=C((typeof l=="string"?c:l)||{}),d=L(null),P=L(null),[u,g]=p?D(a,`${p}:data`):C(a),[f,e]=p?D({},`${p}:errors`):C({}),[i,r]=C(!1),[y,T]=C(!1),[H,h]=C(null),[M,x]=C(!1),[O,R]=C(!1),I=t=>t;Pe(()=>(s.current=!0,()=>{s.current=!1}),[]);let v=ye((t,o,n={})=>{let k={...n,onCancelToken:m=>{if(d.current=m,n.onCancelToken)return n.onCancelToken(m)},onBefore:m=>{if(x(!1),R(!1),clearTimeout(P.current),n.onBefore)return n.onBefore(m)},onStart:m=>{if(T(!0),n.onStart)return n.onStart(m)},onProgress:m=>{if(h(m),n.onProgress)return n.onProgress(m)},onSuccess:m=>{if(s.current&&(T(!1),h(null),e({}),r(!1),x(!0),R(!0),P.current=setTimeout(()=>{s.current&&R(!1)},2e3)),n.onSuccess)return n.onSuccess(m)},onError:m=>{if(s.current&&(T(!1),h(null),e(m),r(!0)),n.onError)return n.onError(m)},onCancel:()=>{if(s.current&&(T(!1),h(null)),n.onCancel)return n.onCancel()},onFinish:()=>{if(s.current&&(T(!1),h(null)),d.current=null,n.onFinish)return n.onFinish()}};t==="delete"?_.delete(o,{...k,data:I(u)}):_[t](o,I(u),k)},[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: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(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 k={...n,...typeof t=="string"?{[t]:o}:t};return r(Object.keys(k).length>0),k})},clearErrors(...t){e(o=>{let n=Object.keys(o).reduce((k,m)=>({...k,...t.length>0&&!t.includes(m)?{[m]:o[m]}:{}}),{});return r(Object.keys(n).length>0),n})},submit:v,get(t,o){v("get",t,o)},post(t,o){v("post",t,o)},put(t,o){v("put",t,o)},patch(t,o){v("patch",t,o)},delete(t,o){v("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 yt=Se;export{ae as Head,de as Link,j as createInertiaApp,yt as router,W as useForm,q as usePage,D as useRemember};
//# sourceMappingURL=index.esm.js.map

@@ -1,6 +0,6 @@

var pe=Object.create;var $=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var fe=(r,a)=>{for(var o in a)$(r,o,{get:a[o],enumerable:!0})},Q=(r,a,o,u)=>{if(a&&typeof a=="object"||typeof a=="function")for(let s of ce(a))!de.call(r,s)&&s!==o&&$(r,s,{get:()=>a[s],enumerable:!(u=ue(a,s))||u.enumerable});return r};var z=(r,a,o)=>(o=r!=null?pe(le(r)):{},Q(a||!r||!r.__esModule?$(o,"default",{value:r,enumerable:!0}):o,r)),me=r=>Q($({},"__esModule",{value:!0}),r);var Pe={};fe(Pe,{Head:()=>re,Link:()=>ne,createInertiaApp:()=>K,router:()=>ye,useForm:()=>q,usePage:()=>J,useRemember:()=>A});module.exports=me(Pe);var ie=require("@inertiajs/core");var ee=require("@inertiajs/core"),te=require("react");var O=require("@inertiajs/core"),F=require("react");var G=require("react"),X=(0,G.createContext)(void 0);X.displayName="InertiaHeadContext";var M=X;var Y=require("react"),Z=(0,Y.createContext)(void 0);Z.displayName="InertiaPageContext";var w=Z;function j({children:r,initialPage:a,initialComponent:o,resolveComponent:u,titleCallback:s,onHeadUpdate:h}){let[d,T]=(0,F.useState)({component:o||null,page:a,key:null}),l=(0,F.useMemo)(()=>(0,O.createHeadManager)(typeof window>"u",s||(f=>f),h||(()=>{})),[]);if((0,F.useEffect)(()=>{O.router.init({initialPage:a,resolveComponent:u,swapComponent:async({component:f,page:e,preserveState:c})=>{T(n=>({component:f,page:e,key:c?n.key:Date.now()}))}}),O.router.on("navigate",()=>l.forceUpdate())},[]),!d.component)return(0,F.createElement)(M.Provider,{value:l},(0,F.createElement)(w.Provider,{value:d.page},null));let y=r||(({Component:f,props:e,key:c})=>{let n=(0,F.createElement)(f,{key:c,...e});return typeof f.layout=="function"?f.layout(n):Array.isArray(f.layout)?f.layout.concat(n).reverse().reduce((P,S)=>(0,F.createElement)(S,{children:P,...e})):n});return(0,F.createElement)(M.Provider,{value:l},(0,F.createElement)(w.Provider,{value:d.page},y({Component:d.component,key:d.key,props:d.page.props})))}j.displayName="Inertia";async function K({id:r="app",resolve:a,setup:o,title:u,progress:s={},page:h,render:d}){let T=typeof window>"u",l=T?null:document.getElementById(r),y=h||JSON.parse(l.dataset.page),f=n=>Promise.resolve(a(n)).then(P=>P.default||P),e=[],c=await f(y.component).then(n=>o({el:l,App:j,props:{initialPage:y,initialComponent:n,resolveComponent:f,titleCallback:u,onHeadUpdate:T?P=>e=P:null}}));if(!T&&s&&(0,ee.setupProgress)(s),T){let n=await d((0,te.createElement)("div",{id:r,"data-page":JSON.stringify(y)},c));return{head:e,body:n}}}var v=z(require("react"),1);var ge=function({children:r,title:a}){let o=(0,v.useContext)(M),u=(0,v.useMemo)(()=>o.createProvider(),[o]);(0,v.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 h(e){let c=Object.keys(e.props).reduce((n,P)=>{if(["head-key","children","dangerouslySetInnerHTML"].includes(P))return n;let S=e.props[P];return S===""?n+` ${P}`:n+` ${P}="${S}"`},"");return`<${e.type}${c}>`}function d(e){return typeof e.props.children=="string"?e.props.children:e.props.children.reduce((c,n)=>c+T(n),"")}function T(e){let c=h(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 v.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=v.default.Children.toArray(e).filter(n=>n).map(n=>y(n));return a&&!c.find(n=>n.startsWith("<title"))&&c.push(`<title inertia>${a}</title>`),c}return u.update(f(r)),null},re=ge;var R=require("@inertiajs/core"),I=require("react"),C=()=>{},oe=(0,I.forwardRef)(({children:r,as:a="a",data:o={},href:u,method:s="get",preserveScroll:h=!1,preserveState:d=null,replace:T=!1,only:l=[],headers:y={},queryStringArrayFormat:f="brackets",onClick:e=C,onCancelToken:c=C,onBefore:n=C,onStart:P=C,onProgress:S=C,onFinish:L=C,onCancel:k=C,onSuccess:B=C,onError:E=C,...V},D)=>{let H=(0,I.useCallback)(t=>{e(t),(0,R.shouldIntercept)(t)&&(t.preventDefault(),R.router.visit(u,{data:o,method:s,preserveScroll:h,preserveState:d??s!=="get",replace:T,only:l,headers:y,onCancelToken:c,onBefore:n,onStart:P,onProgress:S,onFinish:L,onCancel:k,onSuccess:B,onError:E}))},[o,u,s,h,d,T,l,y,e,c,n,P,S,L,k,B,E]);a=a.toLowerCase(),s=s.toLowerCase();let[b,N]=(0,R.mergeDataIntoQueryString)(s,u||"",o,f);return u=b,o=N,a==="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:()=>V,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"),F=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 w=Y;function $({children:r,initialPage:n,initialComponent:o,resolveComponent:u,titleCallback:a,onHeadUpdate:h}){let[d,T]=(0,F.useState)({component:o||null,page:n,key:null}),l=(0,F.useMemo)(()=>(0,O.createHeadManager)(typeof window>"u",a||(f=>f),h||(()=>{})),[]);if((0,F.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,F.createElement)(M.Provider,{value:l},(0,F.createElement)(w.Provider,{value:d.page},null));let y=r||(({Component:f,props:e,key:c})=>{let s=(0,F.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,F.createElement)(S,{children:P,...e})):s});return(0,F.createElement)(M.Provider,{value:l},(0,F.createElement)(w.Provider,{value:d.page},y({Component:d.component,key:d.key,props:d.page.props})))}$.displayName="Inertia";async function V({id:r="app",resolve:n,setup:o,title:u,progress:a={},page:h,render:d}){let T=typeof window>"u",l=T?null:document.getElementById(r),y=h||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 v=Q(require("react"),1);var me=function({children:r,title:n}){let o=(0,v.useContext)(M),u=(0,v.useMemo)(()=>o.createProvider(),[o]);(0,v.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 h(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=h(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 v.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=v.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 R=require("@inertiajs/core"),I=require("react"),C=()=>{},re=(0,I.forwardRef)(({children:r,as:n="a",data:o={},href:u,method:a="get",preserveScroll:h=!1,preserveState:d=null,replace:T=!1,only:l=[],headers:y={},queryStringArrayFormat:f="brackets",onClick:e=C,onCancelToken:c=C,onBefore:s=C,onStart:P=C,onProgress:S=C,onFinish:L=C,onCancel:k=C,onSuccess:B=C,onError:E=C,...U},D)=>{let H=(0,I.useCallback)(i=>{e(i),(0,R.shouldIntercept)(i)&&(i.preventDefault(),R.router.visit(u,{data:o,method:a,preserveScroll:h,preserveState:d??a!=="get",replace:T,only:l,headers:y,onCancelToken:c,onBefore:s,onStart:P,onProgress:S,onFinish:L,onCancel:k,onSuccess:B,onError:E}))},[o,u,a,h,d,T,l,y,e,c,s,P,S,L,k,B,E]);n=n.toLowerCase(),a=a.toLowerCase();let[b,t]=(0,R.mergeDataIntoQueryString)(a,u||"",o,f);return u=b,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)(a,{...V,...a==="a"?{href:u}:{},ref:D,onClick:H},r)});oe.displayName="InertiaLink";var ne=oe;var W=require("@inertiajs/core"),ae=z(require("lodash.isequal"),1),g=require("react");var _=require("@inertiajs/core"),U=require("react");function A(r,a){let[o,u]=(0,U.useState)(()=>{let s=_.router.restore(a);return s!==void 0?s:r});return(0,U.useEffect)(()=>{_.router.remember(o,a)},[o,a]),[o,u]}function q(r,a){let o=(0,g.useRef)(null),u=typeof r=="string"?r:null,[s,h]=(0,g.useState)((typeof r=="string"?a: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,n]=(0,g.useState)(!1),[P,S]=(0,g.useState)(!1),[L,k]=(0,g.useState)(null),[B,E]=(0,g.useState)(!1),[V,D]=(0,g.useState)(!1),H=t=>t;(0,g.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let b=(0,g.useCallback)((t,p,i={})=>{let x={...i,onCancelToken:m=>{if(d.current=m,i.onCancelToken)return i.onCancelToken(m)},onBefore:m=>{if(E(!1),D(!1),clearTimeout(T.current),i.onBefore)return i.onBefore(m)},onStart:m=>{if(S(!0),i.onStart)return i.onStart(m)},onProgress:m=>{if(k(m),i.onProgress)return i.onProgress(m)},onSuccess:m=>{if(o.current&&(S(!1),k(null),e({}),n(!1),E(!0),D(!0),T.current=setTimeout(()=>{o.current&&D(!1)},2e3)),i.onSuccess)return i.onSuccess(m)},onError:m=>{if(o.current&&(S(!1),k(null),e(m),n(!0)),i.onError)return i.onError(m)},onCancel:()=>{if(o.current&&(S(!1),k(null)),i.onCancel)return i.onCancel()},onFinish:()=>{if(o.current&&(S(!1),k(null)),d.current=null,i.onFinish)return i.onFinish()}};t==="delete"?W.router.delete(p,{...x,data:H(l)}):W.router[t](p,H(l),x)},[l,e]);function N(...t){e(p=>{let i=Object.keys(p).reduce((x,m)=>({...x,...t.length>0&&!t.includes(m)?{[m]:p[m]}:{}}),{});return n(Object.keys(i).length>0),i})}return{data:l,setData(t,p){y(typeof t=="string"?{...l,[t]:p}:typeof t=="function"?i=>t(i):t)},isDirty:!(0,ae.default)(l,s),errors:f,hasErrors:c,processing:P,progress:L,wasSuccessful:B,recentlySuccessful:V,transform(t){H=t},setDefaults(t,p){h(typeof t>"u"?()=>l:i=>({...i,...typeof t=="string"?{[t]:p}:t}))},reset(...t){t.length===0?(y(s),e({}),n(!1)):(y(Object.keys(s).filter(p=>t.includes(p)).reduce((p,i)=>(p[i]=s[i],p),{...l})),N(...t))},setError(t,p){e(i=>{let x={...i,...typeof t=="string"?{[t]:p}:t};return n(Object.keys(x).length>0),x})},clearErrors:N,submit:b,get(t,p){b("get",t,p)},post(t,p){b("post",t,p)},put(t,p){b("put",t,p)},patch(t,p){b("patch",t,p)},delete(t,p){b("delete",t,p)},cancel(){d.current&&d.current.cancel()}}}var se=require("react");function J(){let r=(0,se.useContext)(w);if(!r)throw new Error("usePage must be used within the Inertia component");return r}var ye=ie.router;
<Link href="${u}" method="${a}" as="button">...</Link>`),(0,I.createElement)(n,{...U,...n==="a"?{href:u}:{},ref:D,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"),j=require("react");function A(r,n){let[o,u]=(0,j.useState)(()=>{let a=K.router.restore(n);return a!==void 0?a:r});return(0,j.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,h]=(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),[L,k]=(0,g.useState)(null),[B,E]=(0,g.useState)(!1),[U,D]=(0,g.useState)(!1),H=t=>t;(0,g.useEffect)(()=>(o.current=!0,()=>{o.current=!1}),[]);let b=(0,g.useCallback)((t,i,p={})=>{let x={...p,onCancelToken:m=>{if(d.current=m,p.onCancelToken)return p.onCancelToken(m)},onBefore:m=>{if(E(!1),D(!1),clearTimeout(T.current),p.onBefore)return p.onBefore(m)},onStart:m=>{if(S(!0),p.onStart)return p.onStart(m)},onProgress:m=>{if(k(m),p.onProgress)return p.onProgress(m)},onSuccess:m=>{if(o.current&&(S(!1),k(null),e({}),s(!1),E(!0),D(!0),T.current=setTimeout(()=>{o.current&&D(!1)},2e3)),p.onSuccess)return p.onSuccess(m)},onError:m=>{if(o.current&&(S(!1),k(null),e(m),s(!0)),p.onError)return p.onError(m)},onCancel:()=>{if(o.current&&(S(!1),k(null)),p.onCancel)return p.onCancel()},onFinish:()=>{if(o.current&&(S(!1),k(null)),d.current=null,p.onFinish)return p.onFinish()}};t==="delete"?_.router.delete(i,{...x,data:H(l)}):_.router[t](i,H(l),x)},[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:L,wasSuccessful:B,recentlySuccessful:U,transform(t){H=t},setDefaults(t,i){h(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 x={...p,...typeof t=="string"?{[t]:i}:t};return s(Object.keys(x).length>0),x})},clearErrors(...t){e(i=>{let p=Object.keys(i).reduce((x,m)=>({...x,...t.length>0&&!t.includes(m)?{[m]:i[m]}:{}}),{});return s(Object.keys(p).length>0),p})},submit:b,get(t,i){b("get",t,i)},post(t,i){b("post",t,i)},put(t,i){b("put",t,i)},patch(t,i){b("patch",t,i)},delete(t,i){b("delete",t,i)},cancel(){d.current&&d.current.cancel()}}}var ae=require("react");function q(){let r=(0,ae.useContext)(w);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.13",
"version": "1.0.14",
"license": "MIT",

@@ -62,5 +62,5 @@ "description": "The React adapter for Inertia.js",

"dependencies": {
"@inertiajs/core": "1.0.13",
"@inertiajs/core": "1.0.14",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc