@inertiajs/inertia-vue3
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -1,2 +0,2 @@ | ||
var e=require("vue"),r=require("@inertiajs/inertia");function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function n(e){void 0===e&&(e={});var n=JSON.parse(JSON.stringify(e)),o=null,i=function(e){return e};return t({},n,{errors:{},hasErrors:!1,processing:!1,progress:null,wasSuccessful:!1,recentlySuccessful:!1,data:function(){var r=this;return Object.keys(e).reduce(function(e,t){return e[t]=r[t],e},{})},transform:function(e){return i=e,this},reset:function(){var e=[].slice.call(arguments);return Object.assign(this,0===e.length?n:Object.keys(n).filter(function(r){return e.includes(r)}).reduce(function(e,r){return e[r]=n[r],e},{})),this},clearErrors:function(){var e=this,r=[].slice.call(arguments);return this.errors=Object.keys(this.errors).reduce(function(n,o){var i;return t({},n,r.length>0&&!r.includes(o)?((i={})[o]=e.errors[o],i):{})},{}),this.hasErrors=Object.keys(this.errors).length>0,this},serialize:function(){return t({errors:t({},this.errors)},this.data())},unserialize:function(e){return Object.assign(this,e),this.hasErrors=Object.keys(this.errors).length>0,this},submit:function(e,n,s){var u=this;void 0===s&&(s={});var a=i(this.data()),c=t({},s,{onBefore:function(e){if(u.wasSuccessful=!1,u.recentlySuccessful=!1,clearTimeout(o),s.onBefore)return s.onBefore(e)},onStart:function(e){if(u.processing=!0,s.onStart)return s.onStart(e)},onProgress:function(e){if(u.progress=e,s.onProgress)return s.onProgress(e)},onSuccess:function(e){if(u.clearErrors(),u.wasSuccessful=!0,u.recentlySuccessful=!0,o=setTimeout(function(){return u.recentlySuccessful=!1},2e3),s.onSuccess)return s.onSuccess(e)},onError:function(e){if(u.errors=e,u.hasErrors=!0,s.onError)return s.onError(e)},onFinish:function(){if(u.processing=!1,u.progress=null,s.onFinish)return s.onFinish()}});"delete"===e?r.Inertia.delete(n,t({},c,{data:a})):r.Inertia[e](n,a,c)},get:function(e,r){this.submit("get",e,r)},post:function(e,r){this.submit("post",e,r)},put:function(e,r){this.submit("put",e,r)},patch:function(e,r){this.submit("patch",e,r)},delete:function(e,r){this.submit("delete",e,r)}})}var o={props:{as:{type:String,default:"a"},data:{type:Object,default:function(){return{}}},href:{type:String,required:!0},method:{type:String,default:"get"},replace:{type:Boolean,default:!1},preserveScroll:{type:Boolean,default:!1},preserveState:{type:Boolean,default:null},only:{type:Array,default:function(){return[]}},headers:{type:Object,default:function(){return{}}}},setup:function(n,o){var i=o.slots,s=o.attrs;return function(n){var o=n.as.toLowerCase(),u=n.method.toLowerCase(),a=r.mergeDataIntoQueryString(u,r.hrefToUrl(n.href),n.data),c=a[0],l=a[1];return"a"===o&&"get"!==u&&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<inertia-link href="'+c.href+'" method="'+u+'" as="button">...</inertia-link>'),e.h(n.as,t({},s,"a"===o?{href:c.href}:{},{onClick:function(e){var t;r.shouldIntercept(e)&&(e.preventDefault(),r.Inertia.visit(c.href,{data:l,method:u,replace:n.replace,preserveScroll:n.preserveScroll,preserveState:null!=(t=n.preserveState)?t:"get"!==u,only:n.only,headers:n.headers,onCancelToken:s.onCancelToken||function(){return{}},onBefore:s.onBefore||function(){return{}},onStart:s.onStart||function(){return{}},onProgress:s.onProgress||function(){return{}},onFinish:s.onFinish||function(){return{}},onCancel:s.onCancel||function(){return{}},onSuccess:s.onSuccess||function(){return{}},onError:s.onError||function(){return{}}}))}}),i.default())}}},i={created:function(){var n=this;if(this.$options.remember){Array.isArray(this.$options.remember)&&(this.$options.remember={data:this.$options.remember}),"string"==typeof this.$options.remember&&(this.$options.remember={data:[this.$options.remember]}),"string"==typeof this.$options.remember.data&&(this.$options.remember={data:[this.$options.remember.data]});var o=this.$options.remember.key instanceof Function?this.$options.remember.key.call(this):this.$options.remember.key,i=r.Inertia.restore(o);this.$options.remember.data.forEach(function(s){void 0!==n[s]&&void 0!==i&&void 0!==i[s]&&("function"==typeof n[s].serialize&&"function"==typeof n[s].unserialize?n[s].unserialize(i[s]):n[s]=i[s]),n.$watch(s,function(){r.Inertia.remember(n.$options.remember.data.reduce(function(r,o){var i;return t({},r,((i={})[o]="function"==typeof n[o].serialize&&"function"==typeof n[o].unserialize?n[o].serialize():e.toRaw(n[o]),i))},{}),o)},{immediate:!0,deep:!0})})}}},s=e.ref(null),u=e.ref({}),a=e.ref(null),c={name:"Inertia",props:{initialPage:{type:Object,required:!0},resolveComponent:{type:Function,required:!0},resolveErrors:{type:Function,required:!1},transformProps:{type:Function,required:!1}},setup:function(n){return r.Inertia.init({initialPage:n.initialPage,resolveComponent:n.resolveComponent,resolveErrors:n.resolveErrors,transformProps:n.transformProps,swapComponent:function(r){try{return s.value=e.markRaw(r.component),u.value=r.page,a.value=r.preserveState?a.value:Date.now(),Promise.resolve()}catch(e){return Promise.reject(e)}}}),function(){if(s.value){var r=e.h(s.value,t({},u.value.props,{key:a.value}));return s.value.layout?"function"==typeof s.value.layout?s.value.layout(e.h,r):Array.isArray(s.value.layout)?s.value.layout.concat(r).reverse().reduce(function(r,t){return e.h(t,[r])}):e.h(s.value.layout,function(){return r}):r}}}},l={install:function(e){r.Inertia.form=n,Object.defineProperty(e.config.globalProperties,"$inertia",{get:function(){return r.Inertia}}),Object.defineProperty(e.config.globalProperties,"$page",{get:function(){return u.value}}),e.mixin(i),e.component("InertiaLink",o)}};exports.App=c,exports.Link=o,exports.app=c,exports.link=o,exports.plugin=l,exports.useForm=function(r){return e.ref(n(r))},exports.usePage=function(){return{props:e.computed(function(){return u.value.props}),url:e.computed(function(){return u.value.url}),component:e.computed(function(){return u.value.component}),version:e.computed(function(){return u.value.version})}},exports.useRemember=function(t,n){t=e.toRaw(e.unref(t));var o=r.Inertia.restore(n),i=e.ref(void 0===o?t:"function"==typeof t.serialize&&"function"==typeof t.unserialize?t.unserialize(o):o);return e.watch(i,function(o){r.Inertia.remember("function"==typeof t.serialize&&"function"==typeof t.unserialize?t.serialize():e.toRaw(o),n)},{immediate:!0,deep:!0}),i}; | ||
var e,r=require("vue"),t=(e=require("lodash.clonedeep"))&&"object"==typeof e&&"default"in e?e.default:e,n=require("@inertiajs/inertia");function o(){return(o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function i(e,i){void 0===e&&(e={});var s=void 0===i?{}:i,u=s.key,a=void 0===u?"form":u,c=s.remember,l=void 0===c||c,f=t(e),p=n.Inertia.restore(a),m=null,d=function(e){return e},h=r.reactive(o({__rememberable:!1},p?p.data:e,{errors:p?p.errors:{},hasErrors:!1,processing:!1,progress:null,wasSuccessful:!1,recentlySuccessful:!1,data:function(){var r=this;return Object.keys(e).reduce(function(e,t){return e[t]=r[t],e},{})},transform:function(e){return d=e,this},reset:function(){var e=[].slice.call(arguments),r=t(f);return Object.assign(this,0===e.length?r:Object.keys(r).filter(function(r){return e.includes(r)}).reduce(function(e,t){return e[t]=r[t],e},{})),this},clearErrors:function(){var e=this,r=[].slice.call(arguments);return this.errors=Object.keys(this.errors).reduce(function(t,n){var i;return o({},t,r.length>0&&!r.includes(n)?((i={})[n]=e.errors[n],i):{})},{}),this.hasErrors=Object.keys(this.errors).length>0,this},submit:function(e,r,t){var i=this;void 0===t&&(t={});var s=d(this.data()),u=o({},t,{onBefore:function(e){if(i.wasSuccessful=!1,i.recentlySuccessful=!1,clearTimeout(m),t.onBefore)return t.onBefore(e)},onStart:function(e){if(i.processing=!0,t.onStart)return t.onStart(e)},onProgress:function(e){if(i.progress=e,t.onProgress)return t.onProgress(e)},onBeforeRender:function(e){if(i.errors=e.resolvedErrors,i.hasErrors=Object.keys(i.errors).length>0,i.wasSuccessful=!i.hasErrors,i.recentlySuccessful=!i.hasErrors,t.onBeforeRender)return t.onBeforeRender(e)},onSuccess:function(e){if(m=setTimeout(function(){return i.recentlySuccessful=!1},2e3),t.onSuccess)return t.onSuccess(e)},onFinish:function(){if(i.processing=!1,i.progress=null,t.onFinish)return t.onFinish()}});"delete"===e?n.Inertia.delete(r,o({},u,{data:s})):n.Inertia[e](r,s,u)},get:function(e,r){this.submit("get",e,r)},post:function(e,r){this.submit("post",e,r)},put:function(e,r){this.submit("put",e,r)},patch:function(e,r){this.submit("patch",e,r)},delete:function(e,r){this.submit("delete",e,r)}}));return l&&r.watch(h,function(e){var t=r.toRaw(r.unref(e));n.Inertia.remember({data:t.data(),errors:t.errors},a)},{immediate:!0,deep:!0}),h}var s={props:{as:{type:String,default:"a"},data:{type:Object,default:function(){return{}}},href:{type:String,required:!0},method:{type:String,default:"get"},replace:{type:Boolean,default:!1},preserveScroll:{type:Boolean,default:!1},preserveState:{type:Boolean,default:null},only:{type:Array,default:function(){return[]}},headers:{type:Object,default:function(){return{}}}},setup:function(e,t){var i=t.slots,s=t.attrs;return function(e){var t=e.as.toLowerCase(),u=e.method.toLowerCase(),a=n.mergeDataIntoQueryString(u,n.hrefToUrl(e.href),e.data),c=a[0],l=a[1];return"a"===t&&"get"!==u&&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<inertia-link href="'+c.href+'" method="'+u+'" as="button">...</inertia-link>'),r.h(e.as,o({},s,"a"===t?{href:c.href}:{},{onClick:function(r){var t;n.shouldIntercept(r)&&(r.preventDefault(),n.Inertia.visit(c.href,{data:l,method:u,replace:e.replace,preserveScroll:e.preserveScroll,preserveState:null!=(t=e.preserveState)?t:"get"!==u,only:e.only,headers:e.headers,onCancelToken:s.onCancelToken||function(){return{}},onBefore:s.onBefore||function(){return{}},onStart:s.onStart||function(){return{}},onProgress:s.onProgress||function(){return{}},onFinish:s.onFinish||function(){return{}},onCancel:s.onCancel||function(){return{}},onSuccess:s.onSuccess||function(){return{}},onError:s.onError||function(){return{}}}))}}),i)}}},u={created:function(){var e=this;if(this.$options.remember){Array.isArray(this.$options.remember)&&(this.$options.remember={data:this.$options.remember}),"string"==typeof this.$options.remember&&(this.$options.remember={data:[this.$options.remember]}),"string"==typeof this.$options.remember.data&&(this.$options.remember={data:[this.$options.remember.data]});var t=this.$options.remember.key instanceof Function?this.$options.remember.key.call(this):this.$options.remember.key,i=n.Inertia.restore(t),s=this.$options.remember.data.filter(function(r){return!("object"==typeof e[r]&&null!==e[r]&&!1===e[r].__rememberable)});s.forEach(function(u){void 0!==e[u]&&void 0!==i&&void 0!==i[u]&&(e[u]=i[u]),e.$watch(u,function(){n.Inertia.remember(s.reduce(function(t,n){var i;return o({},t,((i={})[n]=r.toRaw(r.unref(e[n])),i))},{}),t)},{immediate:!0,deep:!0})})}}},a=r.ref(null),c=r.ref({}),l=r.ref(null),f={name:"Inertia",props:{initialPage:{type:Object,required:!0},resolveComponent:{type:Function,required:!0},resolveErrors:{type:Function,required:!1},transformProps:{type:Function,required:!1}},setup:function(e){return n.Inertia.init({initialPage:e.initialPage,resolveComponent:e.resolveComponent,resolveErrors:e.resolveErrors,transformProps:e.transformProps,swapComponent:function(e){try{return a.value=r.markRaw(e.component),c.value=e.page,l.value=e.preserveState?l.value:Date.now(),Promise.resolve()}catch(e){return Promise.reject(e)}}}),function(){if(a.value){var e=r.h(a.value,o({},c.value.props,{key:l.value}));return a.value.layout?"function"==typeof a.value.layout?a.value.layout(r.h,e):Array.isArray(a.value.layout)?a.value.layout.concat(e).reverse().reduce(function(e,t){return r.h(t,[e])}):r.h(a.value.layout,function(){return e}):e}}}},p={install:function(e){n.Inertia.form=i,Object.defineProperty(e.config.globalProperties,"$inertia",{get:function(){return n.Inertia}}),Object.defineProperty(e.config.globalProperties,"$page",{get:function(){return c.value}}),e.mixin(u),e.component("InertiaLink",s)}};exports.App=f,exports.Link=s,exports.app=f,exports.link=s,exports.plugin=p,exports.useForm=i,exports.usePage=function(){return{props:r.computed(function(){return c.value.props}),url:r.computed(function(){return c.value.url}),component:r.computed(function(){return c.value.component}),version:r.computed(function(){return c.value.version})}},exports.useRemember=function(e,t){if("object"==typeof e&&null!==e&&!1===e.__rememberable)return e;var o=n.Inertia.restore(t),i=void 0===o?e:r.isReactive(e)?r.reactive(e):r.ref(o);return r.watch(i,function(e){return n.Inertia.remember(r.toRaw(r.unref(e)),t)},{immediate:!0,deep:!0}),i}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("vue"),require("@inertiajs/inertia")):"function"==typeof define&&define.amd?define(["exports","vue","@inertiajs/inertia"],r):r((e=e||self).InertiaVue={},e.Vue,e.Inertia)}(this,function(e,r,t){function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function o(e){void 0===e&&(e={});var r=JSON.parse(JSON.stringify(e)),o=null,i=function(e){return e};return n({},r,{errors:{},hasErrors:!1,processing:!1,progress:null,wasSuccessful:!1,recentlySuccessful:!1,data:function(){var r=this;return Object.keys(e).reduce(function(e,t){return e[t]=r[t],e},{})},transform:function(e){return i=e,this},reset:function(){var e=[].slice.call(arguments);return Object.assign(this,0===e.length?r:Object.keys(r).filter(function(r){return e.includes(r)}).reduce(function(e,t){return e[t]=r[t],e},{})),this},clearErrors:function(){var e=this,r=[].slice.call(arguments);return this.errors=Object.keys(this.errors).reduce(function(t,o){var i;return n({},t,r.length>0&&!r.includes(o)?((i={})[o]=e.errors[o],i):{})},{}),this.hasErrors=Object.keys(this.errors).length>0,this},serialize:function(){return n({errors:n({},this.errors)},this.data())},unserialize:function(e){return Object.assign(this,e),this.hasErrors=Object.keys(this.errors).length>0,this},submit:function(e,r,s){var u=this;void 0===s&&(s={});var a=i(this.data()),c=n({},s,{onBefore:function(e){if(u.wasSuccessful=!1,u.recentlySuccessful=!1,clearTimeout(o),s.onBefore)return s.onBefore(e)},onStart:function(e){if(u.processing=!0,s.onStart)return s.onStart(e)},onProgress:function(e){if(u.progress=e,s.onProgress)return s.onProgress(e)},onSuccess:function(e){if(u.clearErrors(),u.wasSuccessful=!0,u.recentlySuccessful=!0,o=setTimeout(function(){return u.recentlySuccessful=!1},2e3),s.onSuccess)return s.onSuccess(e)},onError:function(e){if(u.errors=e,u.hasErrors=!0,s.onError)return s.onError(e)},onFinish:function(){if(u.processing=!1,u.progress=null,s.onFinish)return s.onFinish()}});"delete"===e?t.Inertia.delete(r,n({},c,{data:a})):t.Inertia[e](r,a,c)},get:function(e,r){this.submit("get",e,r)},post:function(e,r){this.submit("post",e,r)},put:function(e,r){this.submit("put",e,r)},patch:function(e,r){this.submit("patch",e,r)},delete:function(e,r){this.submit("delete",e,r)}})}var i={props:{as:{type:String,default:"a"},data:{type:Object,default:function(){return{}}},href:{type:String,required:!0},method:{type:String,default:"get"},replace:{type:Boolean,default:!1},preserveScroll:{type:Boolean,default:!1},preserveState:{type:Boolean,default:null},only:{type:Array,default:function(){return[]}},headers:{type:Object,default:function(){return{}}}},setup:function(e,o){var i=o.slots,s=o.attrs;return function(e){var o=e.as.toLowerCase(),u=e.method.toLowerCase(),a=t.mergeDataIntoQueryString(u,t.hrefToUrl(e.href),e.data),c=a[0],l=a[1];return"a"===o&&"get"!==u&&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<inertia-link href="'+c.href+'" method="'+u+'" as="button">...</inertia-link>'),r.h(e.as,n({},s,"a"===o?{href:c.href}:{},{onClick:function(r){var n;t.shouldIntercept(r)&&(r.preventDefault(),t.Inertia.visit(c.href,{data:l,method:u,replace:e.replace,preserveScroll:e.preserveScroll,preserveState:null!=(n=e.preserveState)?n:"get"!==u,only:e.only,headers:e.headers,onCancelToken:s.onCancelToken||function(){return{}},onBefore:s.onBefore||function(){return{}},onStart:s.onStart||function(){return{}},onProgress:s.onProgress||function(){return{}},onFinish:s.onFinish||function(){return{}},onCancel:s.onCancel||function(){return{}},onSuccess:s.onSuccess||function(){return{}},onError:s.onError||function(){return{}}}))}}),i.default())}}},s={created:function(){var e=this;if(this.$options.remember){Array.isArray(this.$options.remember)&&(this.$options.remember={data:this.$options.remember}),"string"==typeof this.$options.remember&&(this.$options.remember={data:[this.$options.remember]}),"string"==typeof this.$options.remember.data&&(this.$options.remember={data:[this.$options.remember.data]});var o=this.$options.remember.key instanceof Function?this.$options.remember.key.call(this):this.$options.remember.key,i=t.Inertia.restore(o);this.$options.remember.data.forEach(function(s){void 0!==e[s]&&void 0!==i&&void 0!==i[s]&&("function"==typeof e[s].serialize&&"function"==typeof e[s].unserialize?e[s].unserialize(i[s]):e[s]=i[s]),e.$watch(s,function(){t.Inertia.remember(e.$options.remember.data.reduce(function(t,o){var i;return n({},t,((i={})[o]="function"==typeof e[o].serialize&&"function"==typeof e[o].unserialize?e[o].serialize():r.toRaw(e[o]),i))},{}),o)},{immediate:!0,deep:!0})})}}},u=r.ref(null),a=r.ref({}),c=r.ref(null),l={name:"Inertia",props:{initialPage:{type:Object,required:!0},resolveComponent:{type:Function,required:!0},resolveErrors:{type:Function,required:!1},transformProps:{type:Function,required:!1}},setup:function(e){return t.Inertia.init({initialPage:e.initialPage,resolveComponent:e.resolveComponent,resolveErrors:e.resolveErrors,transformProps:e.transformProps,swapComponent:function(e){try{return u.value=r.markRaw(e.component),a.value=e.page,c.value=e.preserveState?c.value:Date.now(),Promise.resolve()}catch(e){return Promise.reject(e)}}}),function(){if(u.value){var e=r.h(u.value,n({},a.value.props,{key:c.value}));return u.value.layout?"function"==typeof u.value.layout?u.value.layout(r.h,e):Array.isArray(u.value.layout)?u.value.layout.concat(e).reverse().reduce(function(e,t){return r.h(t,[e])}):r.h(u.value.layout,function(){return e}):e}}}},f={install:function(e){t.Inertia.form=o,Object.defineProperty(e.config.globalProperties,"$inertia",{get:function(){return t.Inertia}}),Object.defineProperty(e.config.globalProperties,"$page",{get:function(){return a.value}}),e.mixin(s),e.component("InertiaLink",i)}};e.App=l,e.Link=i,e.app=l,e.link=i,e.plugin=f,e.useForm=function(e){return r.ref(o(e))},e.usePage=function(){return{props:r.computed(function(){return a.value.props}),url:r.computed(function(){return a.value.url}),component:r.computed(function(){return a.value.component}),version:r.computed(function(){return a.value.version})}},e.useRemember=function(e,n){e=r.toRaw(r.unref(e));var o=t.Inertia.restore(n),i=r.ref(void 0===o?e:"function"==typeof e.serialize&&"function"==typeof e.unserialize?e.unserialize(o):o);return r.watch(i,function(o){t.Inertia.remember("function"==typeof e.serialize&&"function"==typeof e.unserialize?e.serialize():r.toRaw(o),n)},{immediate:!0,deep:!0}),i}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("vue"),require("lodash.clonedeep"),require("@inertiajs/inertia")):"function"==typeof define&&define.amd?define(["exports","vue","lodash.clonedeep","@inertiajs/inertia"],r):r((e=e||self).InertiaVue={},e.Vue,e.cloneDeep,e.Inertia)}(this,function(e,r,t,n){function o(){return(o=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function i(e,i){void 0===e&&(e={});var s=void 0===i?{}:i,u=s.key,a=void 0===u?"form":u,c=s.remember,l=void 0===c||c,f=t(e),p=n.Inertia.restore(a),m=null,d=function(e){return e},h=r.reactive(o({__rememberable:!1},p?p.data:e,{errors:p?p.errors:{},hasErrors:!1,processing:!1,progress:null,wasSuccessful:!1,recentlySuccessful:!1,data:function(){var r=this;return Object.keys(e).reduce(function(e,t){return e[t]=r[t],e},{})},transform:function(e){return d=e,this},reset:function(){var e=[].slice.call(arguments),r=t(f);return Object.assign(this,0===e.length?r:Object.keys(r).filter(function(r){return e.includes(r)}).reduce(function(e,t){return e[t]=r[t],e},{})),this},clearErrors:function(){var e=this,r=[].slice.call(arguments);return this.errors=Object.keys(this.errors).reduce(function(t,n){var i;return o({},t,r.length>0&&!r.includes(n)?((i={})[n]=e.errors[n],i):{})},{}),this.hasErrors=Object.keys(this.errors).length>0,this},submit:function(e,r,t){var i=this;void 0===t&&(t={});var s=d(this.data()),u=o({},t,{onBefore:function(e){if(i.wasSuccessful=!1,i.recentlySuccessful=!1,clearTimeout(m),t.onBefore)return t.onBefore(e)},onStart:function(e){if(i.processing=!0,t.onStart)return t.onStart(e)},onProgress:function(e){if(i.progress=e,t.onProgress)return t.onProgress(e)},onBeforeRender:function(e){if(i.errors=e.resolvedErrors,i.hasErrors=Object.keys(i.errors).length>0,i.wasSuccessful=!i.hasErrors,i.recentlySuccessful=!i.hasErrors,t.onBeforeRender)return t.onBeforeRender(e)},onSuccess:function(e){if(m=setTimeout(function(){return i.recentlySuccessful=!1},2e3),t.onSuccess)return t.onSuccess(e)},onFinish:function(){if(i.processing=!1,i.progress=null,t.onFinish)return t.onFinish()}});"delete"===e?n.Inertia.delete(r,o({},u,{data:s})):n.Inertia[e](r,s,u)},get:function(e,r){this.submit("get",e,r)},post:function(e,r){this.submit("post",e,r)},put:function(e,r){this.submit("put",e,r)},patch:function(e,r){this.submit("patch",e,r)},delete:function(e,r){this.submit("delete",e,r)}}));return l&&r.watch(h,function(e){var t=r.toRaw(r.unref(e));n.Inertia.remember({data:t.data(),errors:t.errors},a)},{immediate:!0,deep:!0}),h}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var s={props:{as:{type:String,default:"a"},data:{type:Object,default:function(){return{}}},href:{type:String,required:!0},method:{type:String,default:"get"},replace:{type:Boolean,default:!1},preserveScroll:{type:Boolean,default:!1},preserveState:{type:Boolean,default:null},only:{type:Array,default:function(){return[]}},headers:{type:Object,default:function(){return{}}}},setup:function(e,t){var i=t.slots,s=t.attrs;return function(e){var t=e.as.toLowerCase(),u=e.method.toLowerCase(),a=n.mergeDataIntoQueryString(u,n.hrefToUrl(e.href),e.data),c=a[0],l=a[1];return"a"===t&&"get"!==u&&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<inertia-link href="'+c.href+'" method="'+u+'" as="button">...</inertia-link>'),r.h(e.as,o({},s,"a"===t?{href:c.href}:{},{onClick:function(r){var t;n.shouldIntercept(r)&&(r.preventDefault(),n.Inertia.visit(c.href,{data:l,method:u,replace:e.replace,preserveScroll:e.preserveScroll,preserveState:null!=(t=e.preserveState)?t:"get"!==u,only:e.only,headers:e.headers,onCancelToken:s.onCancelToken||function(){return{}},onBefore:s.onBefore||function(){return{}},onStart:s.onStart||function(){return{}},onProgress:s.onProgress||function(){return{}},onFinish:s.onFinish||function(){return{}},onCancel:s.onCancel||function(){return{}},onSuccess:s.onSuccess||function(){return{}},onError:s.onError||function(){return{}}}))}}),i)}}},u={created:function(){var e=this;if(this.$options.remember){Array.isArray(this.$options.remember)&&(this.$options.remember={data:this.$options.remember}),"string"==typeof this.$options.remember&&(this.$options.remember={data:[this.$options.remember]}),"string"==typeof this.$options.remember.data&&(this.$options.remember={data:[this.$options.remember.data]});var t=this.$options.remember.key instanceof Function?this.$options.remember.key.call(this):this.$options.remember.key,i=n.Inertia.restore(t),s=this.$options.remember.data.filter(function(r){return!("object"==typeof e[r]&&null!==e[r]&&!1===e[r].__rememberable)});s.forEach(function(u){void 0!==e[u]&&void 0!==i&&void 0!==i[u]&&(e[u]=i[u]),e.$watch(u,function(){n.Inertia.remember(s.reduce(function(t,n){var i;return o({},t,((i={})[n]=r.toRaw(r.unref(e[n])),i))},{}),t)},{immediate:!0,deep:!0})})}}},a=r.ref(null),c=r.ref({}),l=r.ref(null),f={name:"Inertia",props:{initialPage:{type:Object,required:!0},resolveComponent:{type:Function,required:!0},resolveErrors:{type:Function,required:!1},transformProps:{type:Function,required:!1}},setup:function(e){return n.Inertia.init({initialPage:e.initialPage,resolveComponent:e.resolveComponent,resolveErrors:e.resolveErrors,transformProps:e.transformProps,swapComponent:function(e){try{return a.value=r.markRaw(e.component),c.value=e.page,l.value=e.preserveState?l.value:Date.now(),Promise.resolve()}catch(e){return Promise.reject(e)}}}),function(){if(a.value){var e=r.h(a.value,o({},c.value.props,{key:l.value}));return a.value.layout?"function"==typeof a.value.layout?a.value.layout(r.h,e):Array.isArray(a.value.layout)?a.value.layout.concat(e).reverse().reduce(function(e,t){return r.h(t,[e])}):r.h(a.value.layout,function(){return e}):e}}}},p={install:function(e){n.Inertia.form=i,Object.defineProperty(e.config.globalProperties,"$inertia",{get:function(){return n.Inertia}}),Object.defineProperty(e.config.globalProperties,"$page",{get:function(){return c.value}}),e.mixin(u),e.component("InertiaLink",s)}};e.App=f,e.Link=s,e.app=f,e.link=s,e.plugin=p,e.useForm=i,e.usePage=function(){return{props:r.computed(function(){return c.value.props}),url:r.computed(function(){return c.value.url}),component:r.computed(function(){return c.value.component}),version:r.computed(function(){return c.value.version})}},e.useRemember=function(e,t){if("object"==typeof e&&null!==e&&!1===e.__rememberable)return e;var o=n.Inertia.restore(t),i=void 0===o?e:r.isReactive(e)?r.reactive(e):r.ref(o);return r.watch(i,function(e){return n.Inertia.remember(r.toRaw(r.unref(e)),t)},{immediate:!0,deep:!0}),i}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "@inertiajs/inertia-vue3", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"license": "MIT", | ||
@@ -30,3 +30,3 @@ "description": "The Vue 3 adapter for Inertia.js", | ||
"devDependencies": { | ||
"@inertiajs/inertia": "^0.8.2", | ||
"@inertiajs/inertia": "^0.8.6", | ||
"eslint": "^7.0.0", | ||
@@ -37,5 +37,8 @@ "microbundle": "^0.12.0", | ||
"peerDependencies": { | ||
"@inertiajs/inertia": "^0.8.2", | ||
"@inertiajs/inertia": "^0.8.6", | ||
"vue": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"lodash.clonedeep": "^4.5.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import form from './form' | ||
import useForm from './useForm' | ||
import link from './link' | ||
@@ -72,3 +72,3 @@ import remember from './remember' | ||
install(app) { | ||
Inertia.form = form | ||
Inertia.form = useForm | ||
Object.defineProperty(app.config.globalProperties, '$inertia', { get: () => Inertia }) | ||
@@ -75,0 +75,0 @@ Object.defineProperty(app.config.globalProperties, '$page', { get: () => page.value }) |
export { default as App, default as app, plugin, usePage } from './app' | ||
export { default as Link, default as link } from './link' | ||
export { useRemember } from './remember' | ||
export { useForm } from './form' | ||
export { default as useRemember } from './useRemember' | ||
export { default as useForm } from './useForm' |
@@ -79,5 +79,5 @@ import { h } from 'vue' | ||
}, | ||
}, slots.default()) | ||
}, slots) | ||
} | ||
}, | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ref, toRaw, unref, watch } from 'vue' | ||
import { toRaw, unref } from 'vue' | ||
import { Inertia } from '@inertiajs/inertia' | ||
@@ -28,7 +28,9 @@ | ||
this.$options.remember.data.forEach(key => { | ||
const rememberable = this.$options.remember.data.filter(key => { | ||
return !(typeof this[key] === 'object' && this[key] !== null && this[key].__rememberable === false) | ||
}) | ||
rememberable.forEach(key => { | ||
if (this[key] !== undefined && restored !== undefined && restored[key] !== undefined) { | ||
typeof this[key].serialize === 'function' && typeof this[key].unserialize === 'function' | ||
? this[key].unserialize(restored[key]) | ||
: (this[key] = restored[key]) | ||
this[key] = restored[key] | ||
} | ||
@@ -38,7 +40,5 @@ | ||
Inertia.remember( | ||
this.$options.remember.data.reduce((data, key) => ({ | ||
rememberable.reduce((data, key) => ({ | ||
...data, | ||
[key]: typeof this[key].serialize === 'function' && typeof this[key].unserialize === 'function' | ||
? this[key].serialize() | ||
: toRaw(this[key]), | ||
[key]: toRaw(unref(this[key])), | ||
}), {}), | ||
@@ -51,23 +51,1 @@ stateKey, | ||
} | ||
export function useRemember(data, key) { | ||
data = toRaw(unref(data)) | ||
const restored = Inertia.restore(key) | ||
const remembered = restored === undefined ? ref(data) : ref( | ||
typeof data.serialize === 'function' && typeof data.unserialize === 'function' | ||
? data.unserialize(restored) | ||
: restored, | ||
) | ||
watch(remembered, (remembered) => { | ||
Inertia.remember( | ||
typeof data.serialize === 'function' && typeof data.unserialize === 'function' | ||
? data.serialize() | ||
: toRaw(remembered), | ||
key, | ||
) | ||
}, { immediate: true, deep: true }) | ||
return remembered | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
66210
15
505
3
1
+ Addedlodash.clonedeep@^4.5.0
+ Addedlodash.clonedeep@4.5.0(transitive)