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