From 939576ad0f3d3e633a9401c8c377bc7bc873ff35 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Tue, 20 Feb 2024 14:56:04 -0500 Subject: [PATCH] v1.8.2 --- CHANGELOG.md | 20 +++++++++++++++++++- dist/index.es.js | 2 +- dist/index.js | 2 +- dist/index.m.js | 2 +- dist/react.es.js | 2 +- dist/react.js | 2 +- dist/react.m.js | 2 +- dist/vue.es.js | 2 +- dist/vue.js | 2 +- dist/vue.m.js | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 12 files changed, 31 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35145752..22109674 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,23 @@ Breaking changes are marked with ⚠️. ## [Unreleased] +## [v1.8.2] - 2024-02-20 + +**Added** + +- Test on Laravel 11 by @shuvroroy in https://github.com/tighten/ziggy/pull/709 + +**Fixed** + +- Fix `route().current()` with encoded characters by @bakerkretzmar in https://github.com/tighten/ziggy/pull/668 +- Fix retrieving ziggys config from an api endpoint link in readme by @RomainMazB in https://github.com/tighten/ziggy/pull/694 +- Fix `route().current()` with nested/object query params by @bakerkretzmar in https://github.com/tighten/ziggy/pull/712 + +**Changed** + +- Enable provenance for npm package by @saibotk in https://github.com/tighten/ziggy/pull/684 +- Handle generated file extensions more robustly by @bakerkretzmar in https://github.com/tighten/ziggy/pull/687 + ## [v1.8.1] - 2023-10-12 **Fixed** @@ -316,7 +333,8 @@ Breaking changes are marked with ⚠️. For previous changes see the [Releases](https://github.com/tighten/ziggy/releases) page. -[Unreleased]: https://github.com/tighten/ziggy/compare/v1.8.1...HEAD +[Unreleased]: https://github.com/tighten/ziggy/compare/v1.8.2...HEAD +[v1.8.2]: https://github.com/tighten/ziggy/compare/v1.8.1...v1.8.2 [v1.8.1]: https://github.com/tighten/ziggy/compare/v1.8.0...v1.8.1 [v1.8.0]: https://github.com/tighten/ziggy/compare/v1.7.0...v1.8.0 [v1.7.0]: https://github.com/tighten/ziggy/compare/v1.6.2...v1.7.0 diff --git a/dist/index.es.js b/dist/index.es.js index b7f287b0..e66bf798 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -1 +1 @@ -function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e1;){var e=t.pop(),r=e.obj[e.prop];if(u(r)){for(var n=[],o=0;o=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===o.RFC1738&&(40===c||41===c)?s+=u.charAt(f):c<128?s+=a[c]:c<2048?s+=a[192|c>>6]+a[128|63&c]:c<55296||c>=57344?s+=a[224|c>>12]+a[128|c>>6&63]+a[128|63&c]:(c=65536+((1023&c)<<10|1023&u.charCodeAt(f+=1)),s+=a[240|c>>18]+a[128|c>>12&63]+a[128|c>>6&63]+a[128|63&c])}return s},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(u(t)){for(var r=[],n=0;n0?w.join(",")||null:void 0}];else if(p(a))R=a;else{var N=Object.keys(w);R=s?N.sort(s):N}for(var k=0;k-1?t.split(","):t},S=function(t,e,r,n){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(o),a=u?o.slice(0,u.index):o,s=[];if(a){if(!r.plainObjects&&j.call(Object.prototype,a)&&!r.allowPrototypes)return;s.push(a)}for(var f=0;r.depth>0&&null!==(u=i.exec(o))&&f=0;--i){var u,a=t[i];if("[]"===a&&r.parseArrays)u=[].concat(o);else{u=r.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,f=parseInt(s,10);r.parseArrays||""!==s?!isNaN(f)&&a!==s&&String(f)===s&&f>=0&&r.parseArrays&&f<=r.arrayLimit?(u=[])[f]=o:"__proto__"!==s&&(u[s]=o):u={0:o}}o=u}return o}(s,e,r,n)}},R=function(t,e){var r=function(t){if(!t)return $;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?$.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:$.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:$.arrayLimit,charset:void 0===t.charset?$.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:$.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:$.comma,decoder:"function"==typeof t.decoder?t.decoder:$.decoder,delimiter:"string"==typeof t.delimiter||f.isRegExp(t.delimiter)?t.delimiter:$.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:$.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:$.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:$.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:$.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:$.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),i=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(s=w(s)?[s]:s),n[a]=j.call(n,a)?f.combine(n[a],s):s}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var o;const i=`(?<${r}>${(null==(o=this.wheres[r])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${i})?`:`${e}${i}`}).replace(/^\w+:\/\//,""),[r,n]=t.replace(/^\w+:\/\//,"").split("?"),o=new RegExp(`^${e}/?$`).exec(decodeURI(r));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:R(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var o,i;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(i=t[r])?i:""))throw new Error(`Ziggy error: '${r}' parameter does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(o=t[r])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class N extends String{constructor(e,r,n=!0,o){if(super(),this.t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),e){if(!this.t.routes[e])throw new Error(`Ziggy error: route '${e}' is not in the route list.`);this.i=new x(e,this.t.routes[e],this.t),this.u=this.l(r)}}toString(){const e=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((e,r)=>t({},e,{[r]:this.u[r]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return m;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||m.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==t.format){if(!c.call(o.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=o.formatters[r],i=m.filter;return("function"==typeof t.filter||p(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:m.addQueryPrefix,allowDots:void 0===t.allowDots?m.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:m.charsetSentinel,delimiter:void 0===t.delimiter?m.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:m.encode,encoder:"function"==typeof t.encoder?t.encoder:m.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:m.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:m.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:m.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:m.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):p(i.filter)&&(r=i.filter);var u=[];if("object"!=typeof n||null===n)return"";var a=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var s=0;s0?y+h:""}(t({},e,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}p(e){e?this.t.absolute&&e.startsWith("/")&&(e=this.h().host+e):e=this.v();let r={};const[n,o]=Object.entries(this.t.routes).find(([t,n])=>r=new x(t,n,this.t).matchesUrl(e))||[void 0,void 0];return t({name:n},r,{route:o})}v(){const{host:t,pathname:e,search:r}=this.h();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(e,r){const{name:n,params:o,query:i,route:u}=this.p();if(!e)return n;const a=new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!a)return a;const s=new x(n,u,this.t);r=this.l(r,s);const f=t({},o,i);return!(!Object.values(r).every(t=>!t)||Object.values(f).some(t=>void 0!==t))||Object.entries(r).every(([t,e])=>f[t]==e)}h(){var t,e,r,n,o,i;const{host:u="",pathname:a="",search:s=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:u,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:s}}get params(){const{params:e,query:r}=this.p();return t({},e,r)}has(t){return Object.keys(this.t.routes).includes(t)}l(e={},r=this.i){null!=e||(e={}),e=["string","number"].includes(typeof e)?[e]:e;const n=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(e)?e=e.reduce((e,r,o)=>t({},e,n[o]?{[n[o].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==n.length||e[n[0].name]||!e.hasOwnProperty(Object.values(r.bindings)[0])&&!e.hasOwnProperty("id")||(e={[n[0].name]:e}),t({},this.m(r),this.g(e,r))}m(e){return e.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((e,{name:r},n)=>t({},e,{[r]:this.t.defaults[r]}),{})}g(e,{bindings:r,parameterSegments:n}){return Object.entries(e).reduce((e,[o,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||!n.some(({name:t})=>t===o))return t({},e,{[o]:i});if(!i.hasOwnProperty(r[o])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${o}' parameter is missing route model binding key '${r[o]}'.`);r[o]="id"}return t({},e,{[o]:i[r[o]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}function k(t,e,r,n){const o=new N(t,e,r,n);return t?o.toString():o}export{k as default}; +function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e1;){var e=t.pop(),r=e.obj[e.prop];if(u(r)){for(var n=[],o=0;o=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===o.RFC1738&&(40===c||41===c)?f+=u.charAt(s):c<128?f+=a[c]:c<2048?f+=a[192|c>>6]+a[128|63&c]:c<55296||c>=57344?f+=a[224|c>>12]+a[128|c>>6&63]+a[128|63&c]:(c=65536+((1023&c)<<10|1023&u.charCodeAt(s+=1)),f+=a[240|c>>18]+a[128|c>>12&63]+a[128|c>>6&63]+a[128|63&c])}return f},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(u(t)){for(var r=[],n=0;n0?w.join(",")||null:void 0}];else if(p(a))R=a;else{var N=Object.keys(w);R=f?N.sort(f):N}for(var k=0;k-1?t.split(","):t},S=function(t,e,r,n){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(o),a=u?o.slice(0,u.index):o,f=[];if(a){if(!r.plainObjects&&j.call(Object.prototype,a)&&!r.allowPrototypes)return;f.push(a)}for(var s=0;r.depth>0&&null!==(u=i.exec(o))&&s=0;--i){var u,a=t[i];if("[]"===a&&r.parseArrays)u=[].concat(o);else{u=r.plainObjects?Object.create(null):{};var f="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,s=parseInt(f,10);r.parseArrays||""!==f?!isNaN(s)&&a!==f&&String(s)===f&&s>=0&&r.parseArrays&&s<=r.arrayLimit?(u=[])[s]=o:"__proto__"!==f&&(u[f]=o):u={0:o}}o=u}return o}(f,e,r,n)}},R=function(t,e){var r=function(t){if(!t)return $;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?$.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:$.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:$.arrayLimit,charset:void 0===t.charset?$.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:$.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:$.comma,decoder:"function"==typeof t.decoder?t.decoder:$.decoder,delimiter:"string"==typeof t.delimiter||s.isRegExp(t.delimiter)?t.delimiter:$.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:$.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:$.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:$.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:$.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:$.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),i=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(f=w(f)?[f]:f),n[a]=j.call(n,a)?s.combine(n[a],f):f}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var o;const i=`(?<${r}>${(null==(o=this.wheres[r])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${i})?`:`${e}${i}`}).replace(/^\w+:\/\//,""),[r,n]=t.replace(/^\w+:\/\//,"").split("?"),o=new RegExp(`^${e}/?$`).exec(decodeURI(r));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:R(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var o,i;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(i=t[r])?i:""))throw new Error(`Ziggy error: '${r}' parameter does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(o=t[r])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class N extends String{constructor(e,r,n=!0,o){if(super(),this.t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),e){if(!this.t.routes[e])throw new Error(`Ziggy error: route '${e}' is not in the route list.`);this.i=new x(e,this.t.routes[e],this.t),this.u=this.l(r)}}toString(){const e=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((e,r)=>t({},e,{[r]:this.u[r]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return m;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||m.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==t.format){if(!c.call(o.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=o.formatters[r],i=m.filter;return("function"==typeof t.filter||p(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:m.addQueryPrefix,allowDots:void 0===t.allowDots?m.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:m.charsetSentinel,delimiter:void 0===t.delimiter?m.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:m.encode,encoder:"function"==typeof t.encoder?t.encoder:m.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:m.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:m.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:m.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:m.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):p(i.filter)&&(r=i.filter);var u=[];if("object"!=typeof n||null===n)return"";var a=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var f=0;f0?y+h:""}(t({},e,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}p(e){e?this.t.absolute&&e.startsWith("/")&&(e=this.h().host+e):e=this.v();let r={};const[n,o]=Object.entries(this.t.routes).find(([t,n])=>r=new x(t,n,this.t).matchesUrl(e))||[void 0,void 0];return t({name:n},r,{route:o})}v(){const{host:t,pathname:e,search:r}=this.h();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(e,r){const{name:n,params:o,query:i,route:u}=this.p();if(!e)return n;const a=new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!a)return a;const f=new x(n,u,this.t);r=this.l(r,f);const s=t({},o,i);if(Object.values(r).every(t=>!t)&&!Object.values(s).some(t=>void 0!==t))return!0;const c=(t,e)=>Object.entries(t).every(([t,r])=>Array.isArray(r)&&Array.isArray(e[t])?r.every(r=>e[t].includes(r)):"object"==typeof r&&"object"==typeof e[t]&&null!==r&&null!==e[t]?c(r,e[t]):e[t]==r);return c(r,s)}h(){var t,e,r,n,o,i;const{host:u="",pathname:a="",search:f=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:u,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:f}}get params(){const{params:e,query:r}=this.p();return t({},e,r)}has(t){return Object.keys(this.t.routes).includes(t)}l(e={},r=this.i){null!=e||(e={}),e=["string","number"].includes(typeof e)?[e]:e;const n=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(e)?e=e.reduce((e,r,o)=>t({},e,n[o]?{[n[o].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==n.length||e[n[0].name]||!e.hasOwnProperty(Object.values(r.bindings)[0])&&!e.hasOwnProperty("id")||(e={[n[0].name]:e}),t({},this.m(r),this.g(e,r))}m(e){return e.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((e,{name:r},n)=>t({},e,{[r]:this.t.defaults[r]}),{})}g(e,{bindings:r,parameterSegments:n}){return Object.entries(e).reduce((e,[o,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||!n.some(({name:t})=>t===o))return t({},e,{[o]:i});if(!i.hasOwnProperty(r[o])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${o}' parameter is missing route model binding key '${r[o]}'.`);r[o]="id"}return t({},e,{[o]:i[r[o]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}function k(t,e,r,n){const o=new N(t,e,r,n);return t?o.toString():o}export{k as default}; diff --git a/dist/index.js b/dist/index.js index 74c1220e..7992de87 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t||self).route=r()}(this,function(){function t(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(v(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(v(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(g(f))T=f;else{var x=Object.keys(h);T=a?x.sort(a):x}for(var N=0;N-1?t.split(","):t},D=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&T.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},$=function(t,r){var e=function(t){if(!t)return x;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?x.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:x.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:x.arrayLimit,charset:void 0===t.charset?x.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:x.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:x.comma,decoder:"function"==typeof t.decoder?t.decoder:x.decoder,delimiter:"string"==typeof t.delimiter||d.isRegExp(t.delimiter)?t.delimiter:x.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:x.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:x.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:x.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:x.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:x.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=k(a)?[a]:a),n[f]=T.call(n,f)?d.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:$(i)}}return!1},e.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),P=/*#__PURE__*/function(t){var n,i;function u(r,n,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=e({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new F(r,u.t.routes[r],u.t),u.u=u.l(n)}return u}i=t,(n=u).prototype=Object.create(i.prototype),n.prototype.constructor=n,o(n,i);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var o;return e({},r,((o={})[n]=t.u[n],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return R;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||R.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=l.default;if(void 0!==t.format){if(!b.call(l.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=l.formatters[e],o=R.filter;return("function"==typeof t.filter||g(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===t.allowDots?R.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:R.charsetSentinel,delimiter:void 0===t.delimiter?R.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:R.encode,encoder:"function"==typeof t.encoder?t.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:R.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:R.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):g(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=h[r&&r.arrayFormat in h?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?s+c:""}(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var n={},o=Object.entries(this.t.routes).find(function(e){return n=new F(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return e({name:o[0]},n,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var n=this.v(),o=n.name,i=n.params,u=n.query,f=n.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new F(o,f,this.t);r=this.l(r,c);var l=e({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var i,u;return e({},t,o[n]?((i={})[o[n].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return e({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,o){var i,u=n.name;return e({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var n=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return e({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(n[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return e({},t,((i={})[f]=a[n[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},r(u,[{key:"params",get:function(){var t=this.v();return e({},t.params,t.query)}}]),u}(/*#__PURE__*/u(String));return function(t,r,e,n){var o=new P(t,r,e,n);return t?o.toString():o}}); +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t||self).route=r()}(this,function(){function t(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(v(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(v(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(g(f))T=f;else{var x=Object.keys(h);T=a?x.sort(a):x}for(var N=0;N-1?t.split(","):t},A=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&T.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},D=function(t,r){var e=function(t){if(!t)return x;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?x.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:x.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:x.arrayLimit,charset:void 0===t.charset?x.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:x.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:x.comma,decoder:"function"==typeof t.decoder?t.decoder:x.decoder,delimiter:"string"==typeof t.delimiter||d.isRegExp(t.delimiter)?t.delimiter:x.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:x.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:x.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:x.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:x.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:x.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=k(a)?[a]:a),n[f]=T.call(n,f)?d.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:D(i)}}return!1},e.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),F=/*#__PURE__*/function(t){var n,i;function u(r,n,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=e({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new $(r,u.t.routes[r],u.t),u.u=u.l(n)}return u}i=t,(n=u).prototype=Object.create(i.prototype),n.prototype.constructor=n,o(n,i);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var o;return e({},r,((o={})[n]=t.u[n],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return R;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||R.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=l.default;if(void 0!==t.format){if(!b.call(l.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=l.formatters[e],o=R.filter;return("function"==typeof t.filter||g(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===t.allowDots?R.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:R.charsetSentinel,delimiter:void 0===t.delimiter?R.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:R.encode,encoder:"function"==typeof t.encoder?t.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:R.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:R.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):g(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=h[r&&r.arrayFormat in h?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?s+c:""}(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var n={},o=Object.entries(this.t.routes).find(function(e){return n=new $(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return e({name:o[0]},n,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var n=this.v(),o=n.name,i=n.params,u=n.query,f=n.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new $(o,f,this.t);r=this.l(r,c);var l=e({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||function t(r,e){return Object.entries(r).every(function(r){var n=r[0],o=r[1];return Array.isArray(o)&&Array.isArray(e[n])?o.every(function(t){return e[n].includes(t)}):"object"==typeof o&&"object"==typeof e[n]&&null!==o&&null!==e[n]?t(o,e[n]):e[n]==o})}(r,l)},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var i,u;return e({},t,o[n]?((i={})[o[n].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return e({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,o){var i,u=n.name;return e({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var n=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return e({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(n[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return e({},t,((i={})[f]=a[n[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},r(u,[{key:"params",get:function(){var t=this.v();return e({},t.params,t.query)}}]),u}(/*#__PURE__*/u(String));return function(t,r,e,n){var o=new F(t,r,e,n);return t?o.toString():o}}); diff --git a/dist/index.m.js b/dist/index.m.js index 30906a0e..3b2612de 100644 --- a/dist/index.m.js +++ b/dist/index.m.js @@ -1 +1 @@ -function t(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(v(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(v(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(g(f))k=f;else{var T=Object.keys(h);k=a?T.sort(a):T}for(var N=0;N-1?t.split(","):t},D=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&k.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},$=function(t,r){var e=function(t){if(!t)return T;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?T.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:T.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:T.arrayLimit,charset:void 0===t.charset?T.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:T.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:T.comma,decoder:"function"==typeof t.decoder?t.decoder:T.decoder,delimiter:"string"==typeof t.delimiter||d.isRegExp(t.delimiter)?t.delimiter:T.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:T.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:T.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:T.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:T.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:T.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=x(a)?[a]:a),n[f]=k.call(n,f)?d.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:$(i)}}return!1},e.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),P=/*#__PURE__*/function(t){var n,i;function u(r,n,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=e({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new F(r,u.t.routes[r],u.t),u.u=u.l(n)}return u}i=t,(n=u).prototype=Object.create(i.prototype),n.prototype.constructor=n,o(n,i);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var o;return e({},r,((o={})[n]=t.u[n],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return R;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||R.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=l.default;if(void 0!==t.format){if(!b.call(l.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=l.formatters[e],o=R.filter;return("function"==typeof t.filter||g(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===t.allowDots?R.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:R.charsetSentinel,delimiter:void 0===t.delimiter?R.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:R.encode,encoder:"function"==typeof t.encoder?t.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:R.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:R.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):g(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=h[r&&r.arrayFormat in h?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?s+c:""}(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var n={},o=Object.entries(this.t.routes).find(function(e){return n=new F(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return e({name:o[0]},n,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var n=this.v(),o=n.name,i=n.params,u=n.query,f=n.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new F(o,f,this.t);r=this.l(r,c);var l=e({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var i,u;return e({},t,o[n]?((i={})[o[n].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return e({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,o){var i,u=n.name;return e({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var n=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return e({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(n[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return e({},t,((i={})[f]=a[n[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},r(u,[{key:"params",get:function(){var t=this.v();return e({},t.params,t.query)}}]),u}(/*#__PURE__*/u(String));function A(t,r,e,n){var o=new P(t,r,e,n);return t?o.toString():o}export{A as default}; +function t(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(v(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(v(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(g(f))k=f;else{var T=Object.keys(h);k=a?T.sort(a):T}for(var N=0;N-1?t.split(","):t},A=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&k.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},D=function(t,r){var e=function(t){if(!t)return T;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?T.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:T.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:T.arrayLimit,charset:void 0===t.charset?T.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:T.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:T.comma,decoder:"function"==typeof t.decoder?t.decoder:T.decoder,delimiter:"string"==typeof t.delimiter||d.isRegExp(t.delimiter)?t.delimiter:T.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:T.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:T.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:T.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:T.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:T.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=x(a)?[a]:a),n[f]=k.call(n,f)?d.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:D(i)}}return!1},e.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),F=/*#__PURE__*/function(t){var n,i;function u(r,n,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=e({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new $(r,u.t.routes[r],u.t),u.u=u.l(n)}return u}i=t,(n=u).prototype=Object.create(i.prototype),n.prototype.constructor=n,o(n,i);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,n){var o;return e({},r,((o={})[n]=t.u[n],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return R;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||R.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=l.default;if(void 0!==t.format){if(!b.call(l.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=l.formatters[e],o=R.filter;return("function"==typeof t.filter||g(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===t.allowDots?R.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:R.charsetSentinel,delimiter:void 0===t.delimiter?R.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:R.encode,encoder:"function"==typeof t.encoder?t.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:R.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:R.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):g(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=h[r&&r.arrayFormat in h?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?s+c:""}(e({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var n={},o=Object.entries(this.t.routes).find(function(e){return n=new $(e[0],e[1],r.t).matchesUrl(t)})||[void 0,void 0];return e({name:o[0]},n,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var n=this.v(),o=n.name,i=n.params,u=n.query,f=n.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new $(o,f,this.t);r=this.l(r,c);var l=e({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||function t(r,e){return Object.entries(r).every(function(r){var n=r[0],o=r[1];return Array.isArray(o)&&Array.isArray(e[n])?o.every(function(t){return e[n].includes(t)}):"object"==typeof o&&"object"==typeof e[n]&&null!==o&&null!==e[n]?t(o,e[n]):e[n]==o})}(r,l)},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var n=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!n.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,n){var i,u;return e({},t,o[n]?((i={})[o[n].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return e({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,n,o){var i,u=n.name;return e({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var n=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return e({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(n[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+n[f]+"'.");n[f]="id"}return e({},t,((i={})[f]=a[n[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},r(u,[{key:"params",get:function(){var t=this.v();return e({},t.params,t.query)}}]),u}(/*#__PURE__*/u(String));function P(t,r,e,n){var o=new F(t,r,e,n);return t?o.toString():o}export{P as default}; diff --git a/dist/react.es.js b/dist/react.es.js index 634a7ee8..3ab0c8eb 100644 --- a/dist/react.es.js +++ b/dist/react.es.js @@ -1 +1 @@ -function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e1;){var e=t.pop(),r=e.obj[e.prop];if(u(r)){for(var n=[],o=0;o=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===o.RFC1738&&(40===c||41===c)?s+=u.charAt(f):c<128?s+=a[c]:c<2048?s+=a[192|c>>6]+a[128|63&c]:c<55296||c>=57344?s+=a[224|c>>12]+a[128|c>>6&63]+a[128|63&c]:(c=65536+((1023&c)<<10|1023&u.charCodeAt(f+=1)),s+=a[240|c>>18]+a[128|c>>12&63]+a[128|c>>6&63]+a[128|63&c])}return s},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(u(t)){for(var r=[],n=0;n0?w.join(",")||null:void 0}];else if(h(a))R=a;else{var N=Object.keys(w);R=s?N.sort(s):N}for(var T=0;T-1?t.split(","):t},S=function(t,e,r,n){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(o),a=u?o.slice(0,u.index):o,s=[];if(a){if(!r.plainObjects&&j.call(Object.prototype,a)&&!r.allowPrototypes)return;s.push(a)}for(var f=0;r.depth>0&&null!==(u=i.exec(o))&&f=0;--i){var u,a=t[i];if("[]"===a&&r.parseArrays)u=[].concat(o);else{u=r.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,f=parseInt(s,10);r.parseArrays||""!==s?!isNaN(f)&&a!==s&&String(f)===s&&f>=0&&r.parseArrays&&f<=r.arrayLimit?(u=[])[f]=o:"__proto__"!==s&&(u[s]=o):u={0:o}}o=u}return o}(s,e,r,n)}},R=function(t,e){var r=function(t){if(!t)return $;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?$.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:$.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:$.arrayLimit,charset:void 0===t.charset?$.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:$.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:$.comma,decoder:"function"==typeof t.decoder?t.decoder:$.decoder,delimiter:"string"==typeof t.delimiter||f.isRegExp(t.delimiter)?t.delimiter:$.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:$.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:$.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:$.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:$.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:$.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),i=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(s=w(s)?[s]:s),n[a]=j.call(n,a)?f.combine(n[a],s):s}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var o;const i=`(?<${r}>${(null==(o=this.wheres[r])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${i})?`:`${e}${i}`}).replace(/^\w+:\/\//,""),[r,n]=t.replace(/^\w+:\/\//,"").split("?"),o=new RegExp(`^${e}/?$`).exec(decodeURI(r));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:R(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var o,i;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(i=t[r])?i:""))throw new Error(`Ziggy error: '${r}' parameter does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(o=t[r])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class N extends String{constructor(e,r,n=!0,o){if(super(),this.t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),e){if(!this.t.routes[e])throw new Error(`Ziggy error: route '${e}' is not in the route list.`);this.i=new x(e,this.t.routes[e],this.t),this.u=this.l(r)}}toString(){const e=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((e,r)=>t({},e,{[r]:this.u[r]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return v;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||v.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==t.format){if(!c.call(o.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=o.formatters[r],i=v.filter;return("function"==typeof t.filter||h(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:v.addQueryPrefix,allowDots:void 0===t.allowDots?v.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:v.charsetSentinel,delimiter:void 0===t.delimiter?v.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:v.encode,encoder:"function"==typeof t.encoder?t.encoder:v.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:v.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:v.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:v.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:v.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):h(i.filter)&&(r=i.filter);var u=[];if("object"!=typeof n||null===n)return"";var a=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var s=0;s0?y+p:""}(t({},e,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}h(e){e?this.t.absolute&&e.startsWith("/")&&(e=this.p().host+e):e=this.g();let r={};const[n,o]=Object.entries(this.t.routes).find(([t,n])=>r=new x(t,n,this.t).matchesUrl(e))||[void 0,void 0];return t({name:n},r,{route:o})}g(){const{host:t,pathname:e,search:r}=this.p();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(e,r){const{name:n,params:o,query:i,route:u}=this.h();if(!e)return n;const a=new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!a)return a;const s=new x(n,u,this.t);r=this.l(r,s);const f=t({},o,i);return!(!Object.values(r).every(t=>!t)||Object.values(f).some(t=>void 0!==t))||Object.entries(r).every(([t,e])=>f[t]==e)}p(){var t,e,r,n,o,i;const{host:u="",pathname:a="",search:s=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:u,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:s}}get params(){const{params:e,query:r}=this.h();return t({},e,r)}has(t){return Object.keys(this.t.routes).includes(t)}l(e={},r=this.i){null!=e||(e={}),e=["string","number"].includes(typeof e)?[e]:e;const n=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(e)?e=e.reduce((e,r,o)=>t({},e,n[o]?{[n[o].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==n.length||e[n[0].name]||!e.hasOwnProperty(Object.values(r.bindings)[0])&&!e.hasOwnProperty("id")||(e={[n[0].name]:e}),t({},this.v(r),this.m(e,r))}v(e){return e.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((e,{name:r},n)=>t({},e,{[r]:this.t.defaults[r]}),{})}m(e,{bindings:r,parameterSegments:n}){return Object.entries(e).reduce((e,[o,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||!n.some(({name:t})=>t===o))return t({},e,{[o]:i});if(!i.hasOwnProperty(r[o])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${o}' parameter is missing route model binding key '${r[o]}'.`);r[o]="id"}return t({},e,{[o]:i[r[o]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}function T(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return(e,r,n,o=t)=>function(t,e,r,n){const o=new N(t,e,r,n);return t?o.toString():o}(e,r,n,o)}export{T as useRoute}; +function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e1;){var e=t.pop(),r=e.obj[e.prop];if(u(r)){for(var n=[],o=0;o=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===o.RFC1738&&(40===c||41===c)?f+=u.charAt(s):c<128?f+=a[c]:c<2048?f+=a[192|c>>6]+a[128|63&c]:c<55296||c>=57344?f+=a[224|c>>12]+a[128|c>>6&63]+a[128|63&c]:(c=65536+((1023&c)<<10|1023&u.charCodeAt(s+=1)),f+=a[240|c>>18]+a[128|c>>12&63]+a[128|c>>6&63]+a[128|63&c])}return f},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(u(t)){for(var r=[],n=0;n0?w.join(",")||null:void 0}];else if(p(a))R=a;else{var N=Object.keys(w);R=f?N.sort(f):N}for(var T=0;T-1?t.split(","):t},S=function(t,e,r,n){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(o),a=u?o.slice(0,u.index):o,f=[];if(a){if(!r.plainObjects&&j.call(Object.prototype,a)&&!r.allowPrototypes)return;f.push(a)}for(var s=0;r.depth>0&&null!==(u=i.exec(o))&&s=0;--i){var u,a=t[i];if("[]"===a&&r.parseArrays)u=[].concat(o);else{u=r.plainObjects?Object.create(null):{};var f="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,s=parseInt(f,10);r.parseArrays||""!==f?!isNaN(s)&&a!==f&&String(s)===f&&s>=0&&r.parseArrays&&s<=r.arrayLimit?(u=[])[s]=o:"__proto__"!==f&&(u[f]=o):u={0:o}}o=u}return o}(f,e,r,n)}},R=function(t,e){var r=function(t){if(!t)return $;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?$.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:$.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:$.arrayLimit,charset:void 0===t.charset?$.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:$.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:$.comma,decoder:"function"==typeof t.decoder?t.decoder:$.decoder,delimiter:"string"==typeof t.delimiter||s.isRegExp(t.delimiter)?t.delimiter:$.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:$.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:$.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:$.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:$.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:$.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),i=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(f=w(f)?[f]:f),n[a]=j.call(n,a)?s.combine(n[a],f):f}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var o;const i=`(?<${r}>${(null==(o=this.wheres[r])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${i})?`:`${e}${i}`}).replace(/^\w+:\/\//,""),[r,n]=t.replace(/^\w+:\/\//,"").split("?"),o=new RegExp(`^${e}/?$`).exec(decodeURI(r));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:R(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var o,i;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(i=t[r])?i:""))throw new Error(`Ziggy error: '${r}' parameter does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(o=t[r])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class N extends String{constructor(e,r,n=!0,o){if(super(),this.t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),e){if(!this.t.routes[e])throw new Error(`Ziggy error: route '${e}' is not in the route list.`);this.i=new x(e,this.t.routes[e],this.t),this.u=this.l(r)}}toString(){const e=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((e,r)=>t({},e,{[r]:this.u[r]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return v;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||v.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==t.format){if(!c.call(o.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=o.formatters[r],i=v.filter;return("function"==typeof t.filter||p(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:v.addQueryPrefix,allowDots:void 0===t.allowDots?v.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:v.charsetSentinel,delimiter:void 0===t.delimiter?v.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:v.encode,encoder:"function"==typeof t.encoder?t.encoder:v.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:v.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:v.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:v.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:v.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):p(i.filter)&&(r=i.filter);var u=[];if("object"!=typeof n||null===n)return"";var a=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var f=0;f0?y+h:""}(t({},e,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}p(e){e?this.t.absolute&&e.startsWith("/")&&(e=this.h().host+e):e=this.g();let r={};const[n,o]=Object.entries(this.t.routes).find(([t,n])=>r=new x(t,n,this.t).matchesUrl(e))||[void 0,void 0];return t({name:n},r,{route:o})}g(){const{host:t,pathname:e,search:r}=this.h();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(e,r){const{name:n,params:o,query:i,route:u}=this.p();if(!e)return n;const a=new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!a)return a;const f=new x(n,u,this.t);r=this.l(r,f);const s=t({},o,i);if(Object.values(r).every(t=>!t)&&!Object.values(s).some(t=>void 0!==t))return!0;const c=(t,e)=>Object.entries(t).every(([t,r])=>Array.isArray(r)&&Array.isArray(e[t])?r.every(r=>e[t].includes(r)):"object"==typeof r&&"object"==typeof e[t]&&null!==r&&null!==e[t]?c(r,e[t]):e[t]==r);return c(r,s)}h(){var t,e,r,n,o,i;const{host:u="",pathname:a="",search:f=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:u,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:f}}get params(){const{params:e,query:r}=this.p();return t({},e,r)}has(t){return Object.keys(this.t.routes).includes(t)}l(e={},r=this.i){null!=e||(e={}),e=["string","number"].includes(typeof e)?[e]:e;const n=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(e)?e=e.reduce((e,r,o)=>t({},e,n[o]?{[n[o].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==n.length||e[n[0].name]||!e.hasOwnProperty(Object.values(r.bindings)[0])&&!e.hasOwnProperty("id")||(e={[n[0].name]:e}),t({},this.v(r),this.m(e,r))}v(e){return e.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((e,{name:r},n)=>t({},e,{[r]:this.t.defaults[r]}),{})}m(e,{bindings:r,parameterSegments:n}){return Object.entries(e).reduce((e,[o,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||!n.some(({name:t})=>t===o))return t({},e,{[o]:i});if(!i.hasOwnProperty(r[o])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${o}' parameter is missing route model binding key '${r[o]}'.`);r[o]="id"}return t({},e,{[o]:i[r[o]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}function T(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return(e,r,n,o=t)=>function(t,e,r,n){const o=new N(t,e,r,n);return t?o.toString():o}(e,r,n,o)}export{T as useRoute}; diff --git a/dist/react.js b/dist/react.js index d69e57fd..2b872c79 100644 --- a/dist/react.js +++ b/dist/react.js @@ -1 +1 @@ -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t||self).ZiggyReact={})}(this,function(t){function r(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(p(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===s.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=y[a]:a<2048?u+=y[192|a>>6]+y[128|63&a]:a<55296||a>=57344?u+=y[224|a>>12]+y[128|a>>6&63]+y[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=y[240|a>>18]+y[128|a>>12&63]+y[128|a>>6&63]+y[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(p(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(m(f))T=f;else{var k=Object.keys(h);T=a?k.sort(a):k}for(var N=0;N-1?t.split(","):t},$=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&x.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},F=function(t,r){var e=function(t){if(!t)return N;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?N.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:N.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:N.arrayLimit,charset:void 0===t.charset?N.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:N.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:N.comma,decoder:"function"==typeof t.decoder?t.decoder:N.decoder,delimiter:"string"==typeof t.delimiter||b.isRegExp(t.delimiter)?t.delimiter:N.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:N.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:N.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:N.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:N.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:N.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=k(a)?[a]:a),n[f]=x.call(n,f)?b.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:F(i)}}return!1},r.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),Z=/*#__PURE__*/function(t){var r,o;function u(r,e,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new P(r,u.t.routes[r],u.t),u.u=u.l(e)}return u}o=t,(r=u).prototype=Object.create(o.prototype),r.prototype.constructor=r,i(r,o);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var o;return n({},r,((o={})[e]=t.u[e],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return S;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||S.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=s.default;if(void 0!==t.format){if(!h.call(s.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=s.formatters[e],o=S.filter;return("function"==typeof t.filter||m(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:S.addQueryPrefix,allowDots:void 0===t.allowDots?S.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:S.charsetSentinel,delimiter:void 0===t.delimiter?S.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:S.encode,encoder:"function"==typeof t.encoder?t.encoder:S.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:S.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:S.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:S.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:S.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):m(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=g[r&&r.arrayFormat in g?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?l+c:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new P(n[0],n[1],r.t).matchesUrl(t)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new P(o,f,this.t);r=this.l(r,c);var l=n({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var i,u;return n({},t,o[e]?((i={})[o[e].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return n({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,o){var i,u=e.name;return n({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var e=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return n({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},t,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},e(u,[{key:"params",get:function(){var t=this.v();return n({},t.params,t.query)}}]),u}(/*#__PURE__*/f(String));t.useRoute=function(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return function(r,e,n,o){return void 0===o&&(o=t),function(t,r,e,n){var o=new Z(t,r,e,n);return t?o.toString():o}(r,e,n,o)}}}); +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t||self).ZiggyReact={})}(this,function(t){function r(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(p(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===s.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=y[a]:a<2048?u+=y[192|a>>6]+y[128|63&a]:a<55296||a>=57344?u+=y[224|a>>12]+y[128|a>>6&63]+y[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=y[240|a>>18]+y[128|a>>12&63]+y[128|a>>6&63]+y[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(p(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(m(f))T=f;else{var k=Object.keys(h);T=a?k.sort(a):k}for(var N=0;N-1?t.split(","):t},D=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&x.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},$=function(t,r){var e=function(t){if(!t)return N;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?N.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:N.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:N.arrayLimit,charset:void 0===t.charset?N.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:N.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:N.comma,decoder:"function"==typeof t.decoder?t.decoder:N.decoder,delimiter:"string"==typeof t.delimiter||b.isRegExp(t.delimiter)?t.delimiter:N.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:N.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:N.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:N.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:N.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:N.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=k(a)?[a]:a),n[f]=x.call(n,f)?b.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:$(i)}}return!1},r.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),P=/*#__PURE__*/function(t){var r,o;function u(r,e,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new F(r,u.t.routes[r],u.t),u.u=u.l(e)}return u}o=t,(r=u).prototype=Object.create(o.prototype),r.prototype.constructor=r,i(r,o);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var o;return n({},r,((o={})[e]=t.u[e],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return S;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||S.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=s.default;if(void 0!==t.format){if(!h.call(s.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=s.formatters[e],o=S.filter;return("function"==typeof t.filter||m(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:S.addQueryPrefix,allowDots:void 0===t.allowDots?S.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:S.charsetSentinel,delimiter:void 0===t.delimiter?S.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:S.encode,encoder:"function"==typeof t.encoder?t.encoder:S.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:S.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:S.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:S.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:S.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):m(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=g[r&&r.arrayFormat in g?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?l+c:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new F(n[0],n[1],r.t).matchesUrl(t)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new F(o,f,this.t);r=this.l(r,c);var l=n({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||function t(r,e){return Object.entries(r).every(function(r){var n=r[0],o=r[1];return Array.isArray(o)&&Array.isArray(e[n])?o.every(function(t){return e[n].includes(t)}):"object"==typeof o&&"object"==typeof e[n]&&null!==o&&null!==e[n]?t(o,e[n]):e[n]==o})}(r,l)},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var i,u;return n({},t,o[e]?((i={})[o[e].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return n({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,o){var i,u=e.name;return n({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var e=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return n({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},t,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},e(u,[{key:"params",get:function(){var t=this.v();return n({},t.params,t.query)}}]),u}(/*#__PURE__*/f(String));t.useRoute=function(t){if(!t&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return function(r,e,n,o){return void 0===o&&(o=t),function(t,r,e,n){var o=new P(t,r,e,n);return t?o.toString():o}(r,e,n,o)}}}); diff --git a/dist/react.m.js b/dist/react.m.js index 7eb910d4..700b7274 100644 --- a/dist/react.m.js +++ b/dist/react.m.js @@ -1 +1 @@ -function r(r,t){for(var n=0;n1;){var t=r.pop(),n=t.obj[t.prop];if(v(n)){for(var e=[],i=0;i=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||i===l.RFC1738&&(40===a||41===a)?u+=o.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&o.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(r){return!(!r||"object"!=typeof r||!(r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer(r)))},isRegExp:function(r){return"[object RegExp]"===Object.prototype.toString.call(r)},maybeMap:function(r,t){if(v(r)){for(var n=[],e=0;e0?h.join(",")||null:void 0}];else if(g(f))k=f;else{var x=Object.keys(h);k=a?x.sort(a):x}for(var N=0;N-1?r.split(","):r},D=function(r,t,n,e){if(r){var i=n.allowDots?r.replace(/\.([^.[]+)/g,"[$1]"):r,o=/(\[[^[\]]*])/g,u=n.depth>0&&/(\[[^[\]]*])/.exec(i),f=u?i.slice(0,u.index):i,a=[];if(f){if(!n.plainObjects&&k.call(Object.prototype,f)&&!n.allowPrototypes)return;a.push(f)}for(var c=0;n.depth>0&&null!==(u=o.exec(i))&&c=0;--o){var u,f=r[o];if("[]"===f&&n.parseArrays)u=[].concat(i);else{u=n.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);n.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(u=[])[c]=i:"__proto__"!==a&&(u[a]=i):u={0:i}}i=u}return i}(a,t,n,e)}},$=function(r,t){var n=function(r){if(!r)return x;if(null!=r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===r.allowDots?x.allowDots:!!r.allowDots,allowPrototypes:"boolean"==typeof r.allowPrototypes?r.allowPrototypes:x.allowPrototypes,arrayLimit:"number"==typeof r.arrayLimit?r.arrayLimit:x.arrayLimit,charset:void 0===r.charset?x.charset:r.charset,charsetSentinel:"boolean"==typeof r.charsetSentinel?r.charsetSentinel:x.charsetSentinel,comma:"boolean"==typeof r.comma?r.comma:x.comma,decoder:"function"==typeof r.decoder?r.decoder:x.decoder,delimiter:"string"==typeof r.delimiter||d.isRegExp(r.delimiter)?r.delimiter:x.delimiter,depth:"number"==typeof r.depth||!1===r.depth?+r.depth:x.depth,ignoreQueryPrefix:!0===r.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof r.interpretNumericEntities?r.interpretNumericEntities:x.interpretNumericEntities,parameterLimit:"number"==typeof r.parameterLimit?r.parameterLimit:x.parameterLimit,parseArrays:!1!==r.parseArrays,plainObjects:"boolean"==typeof r.plainObjects?r.plainObjects:x.plainObjects,strictNullHandling:"boolean"==typeof r.strictNullHandling?r.strictNullHandling:x.strictNullHandling}}(t);if(""===r||null==r)return n.plainObjects?Object.create(null):{};for(var e="string"==typeof r?function(r,t){var n,e={},i=(t.ignoreQueryPrefix?r.replace(/^\?/,""):r).split(t.delimiter,Infinity===t.parameterLimit?void 0:t.parameterLimit),o=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(a=T(a)?[a]:a),e[f]=k.call(e,f)?d.combine(e[f],a):a}return e}(r,n):r,i=n.plainObjects?Object.create(null):{},o=Object.keys(e),u=0;u"+((null==(o=t.wheres[e])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return i?"("+n+u+")?":""+n+u}).replace(/^\w+:\/\//,""),e=r.replace(/^\w+:\/\//,"").split("?"),i=e[0],o=e[1],u=new RegExp("^"+n+"/?$").exec(decodeURI(i));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:$(o)}}return!1},n.compile=function(r){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,i){var o,u;if(!i&&[null,void 0].includes(r[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");if(t.wheres[e]&&!new RegExp("^"+(i?"("+t.wheres[e]+")?":t.wheres[e])+"$").test(null!=(u=r[e])?u:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+t.wheres[e]+"' for route '"+t.name+"'.");return encodeURI(null!=(o=r[e])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},t(r,[{key:"template",get:function(){var r=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===r?"/":r}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var r,t;return null!=(r=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(r){return{name:r.replace(/{|\??}/g,""),required:!/\?}$/.test(r)}}))?r:[]}}]),r}(),P=/*#__PURE__*/function(r){var e,o;function u(t,e,i,o){var u;if(void 0===i&&(i=!0),(u=r.call(this)||this).t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:i}),t){if(!u.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");u.i=new F(t,u.t.routes[t],u.t),u.u=u.l(e)}return u}o=r,(e=u).prototype=Object.create(o.prototype),e.prototype.constructor=e,i(e,o);var f=u.prototype;return f.toString=function(){var r=this,t=Object.keys(this.u).filter(function(t){return!r.i.parameterSegments.some(function(r){return r.name===t})}).filter(function(r){return"_query"!==r}).reduce(function(t,e){var i;return n({},t,((i={})[e]=r.u[e],i))},{});return this.i.compile(this.u)+function(r,t){var n,e=r,i=function(r){if(!r)return R;if(null!=r.encoder&&"function"!=typeof r.encoder)throw new TypeError("Encoder has to be a function.");var t=r.charset||R.charset;if(void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=l.default;if(void 0!==r.format){if(!b.call(l.formatters,r.format))throw new TypeError("Unknown format option provided.");n=r.format}var e=l.formatters[n],i=R.filter;return("function"==typeof r.filter||g(r.filter))&&(i=r.filter),{addQueryPrefix:"boolean"==typeof r.addQueryPrefix?r.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===r.allowDots?R.allowDots:!!r.allowDots,charset:t,charsetSentinel:"boolean"==typeof r.charsetSentinel?r.charsetSentinel:R.charsetSentinel,delimiter:void 0===r.delimiter?R.delimiter:r.delimiter,encode:"boolean"==typeof r.encode?r.encode:R.encode,encoder:"function"==typeof r.encoder?r.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof r.encodeValuesOnly?r.encodeValuesOnly:R.encodeValuesOnly,filter:i,format:n,formatter:e,serializeDate:"function"==typeof r.serializeDate?r.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof r.skipNulls?r.skipNulls:R.skipNulls,sort:"function"==typeof r.sort?r.sort:null,strictNullHandling:"boolean"==typeof r.strictNullHandling?r.strictNullHandling:R.strictNullHandling}}(t);"function"==typeof i.filter?e=(0,i.filter)("",e):g(i.filter)&&(n=i.filter);var o=[];if("object"!=typeof e||null===e)return"";var u=h[t&&t.arrayFormat in h?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices"];n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var f=0;f0?s+c:""}(n({},t,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(r,t){return"boolean"==typeof r?Number(r):t(r)}})},f.v=function(r){var t=this;r?this.t.absolute&&r.startsWith("/")&&(r=this.p().host+r):r=this.h();var e={},i=Object.entries(this.t.routes).find(function(n){return e=new F(n[0],n[1],t.t).matchesUrl(r)})||[void 0,void 0];return n({name:i[0]},e,{route:i[1]})},f.h=function(){var r=this.p(),t=r.pathname,n=r.search;return(this.t.absolute?r.host+t:t.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},f.current=function(r,t){var e=this.v(),i=e.name,o=e.params,u=e.query,f=e.route;if(!r)return i;var a=new RegExp("^"+r.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(i);if([null,void 0].includes(t)||!a)return a;var c=new F(i,f,this.t);t=this.l(t,c);var l=n({},o,u);return!(!Object.values(t).every(function(r){return!r})||Object.values(l).some(function(r){return void 0!==r}))||Object.entries(t).every(function(r){return l[r[0]]==r[1]})},f.p=function(){var r,t,n,e,i,o,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(r=null==(t=this.t.location)?void 0:t.host)?r:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===a?"":a,search:null!=(i=null==(o=this.t.location)?void 0:o.search)?i:void 0===c?"":c}},f.has=function(r){return Object.keys(this.t.routes).includes(r)},f.l=function(r,t){var e=this;void 0===r&&(r={}),void 0===t&&(t=this.i),null!=r||(r={}),r=["string","number"].includes(typeof r)?[r]:r;var i=t.parameterSegments.filter(function(r){return!e.t.defaults[r.name]});if(Array.isArray(r))r=r.reduce(function(r,t,e){var o,u;return n({},r,i[e]?((o={})[i[e].name]=t,o):"object"==typeof t?t:((u={})[t]="",u))},{});else if(1===i.length&&!r[i[0].name]&&(r.hasOwnProperty(Object.values(t.bindings)[0])||r.hasOwnProperty("id"))){var o;(o={})[i[0].name]=r,r=o}return n({},this.g(t),this.m(r,t))},f.g=function(r){var t=this;return r.parameterSegments.filter(function(r){return t.t.defaults[r.name]}).reduce(function(r,e,i){var o,u=e.name;return n({},r,((o={})[u]=t.t.defaults[u],o))},{})},f.m=function(r,t){var e=t.bindings,i=t.parameterSegments;return Object.entries(r).reduce(function(r,t){var o,u,f=t[0],a=t[1];if(!a||"object"!=typeof a||Array.isArray(a)||!i.some(function(r){return r.name===f}))return n({},r,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},r,((o={})[f]=a[e[f]],o))},{})},f.valueOf=function(){return this.toString()},f.check=function(r){return this.has(r)},t(u,[{key:"params",get:function(){var r=this.v();return n({},r.params,r.query)}}]),u}(/*#__PURE__*/u(String));function Z(r){if(!r&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return function(t,n,e,i){return void 0===i&&(i=r),function(r,t,n,e){var i=new P(r,t,n,e);return r?i.toString():i}(t,n,e,i)}}export{Z as useRoute}; +function r(r,t){for(var n=0;n1;){var t=r.pop(),n=t.obj[t.prop];if(v(n)){for(var e=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(r){return!(!r||"object"!=typeof r||!(r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer(r)))},isRegExp:function(r){return"[object RegExp]"===Object.prototype.toString.call(r)},maybeMap:function(r,t){if(v(r)){for(var n=[],e=0;e0?h.join(",")||null:void 0}];else if(g(f))k=f;else{var x=Object.keys(h);k=a?x.sort(a):x}for(var N=0;N-1?r.split(","):r},A=function(r,t,n,e){if(r){var o=n.allowDots?r.replace(/\.([^.[]+)/g,"[$1]"):r,i=/(\[[^[\]]*])/g,u=n.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!n.plainObjects&&k.call(Object.prototype,f)&&!n.allowPrototypes)return;a.push(f)}for(var c=0;n.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=r[i];if("[]"===f&&n.parseArrays)u=[].concat(o);else{u=n.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);n.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,t,n,e)}},D=function(r,t){var n=function(r){if(!r)return x;if(null!=r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===r.allowDots?x.allowDots:!!r.allowDots,allowPrototypes:"boolean"==typeof r.allowPrototypes?r.allowPrototypes:x.allowPrototypes,arrayLimit:"number"==typeof r.arrayLimit?r.arrayLimit:x.arrayLimit,charset:void 0===r.charset?x.charset:r.charset,charsetSentinel:"boolean"==typeof r.charsetSentinel?r.charsetSentinel:x.charsetSentinel,comma:"boolean"==typeof r.comma?r.comma:x.comma,decoder:"function"==typeof r.decoder?r.decoder:x.decoder,delimiter:"string"==typeof r.delimiter||d.isRegExp(r.delimiter)?r.delimiter:x.delimiter,depth:"number"==typeof r.depth||!1===r.depth?+r.depth:x.depth,ignoreQueryPrefix:!0===r.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof r.interpretNumericEntities?r.interpretNumericEntities:x.interpretNumericEntities,parameterLimit:"number"==typeof r.parameterLimit?r.parameterLimit:x.parameterLimit,parseArrays:!1!==r.parseArrays,plainObjects:"boolean"==typeof r.plainObjects?r.plainObjects:x.plainObjects,strictNullHandling:"boolean"==typeof r.strictNullHandling?r.strictNullHandling:x.strictNullHandling}}(t);if(""===r||null==r)return n.plainObjects?Object.create(null):{};for(var e="string"==typeof r?function(r,t){var n,e={},o=(t.ignoreQueryPrefix?r.replace(/^\?/,""):r).split(t.delimiter,Infinity===t.parameterLimit?void 0:t.parameterLimit),i=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(a=T(a)?[a]:a),e[f]=k.call(e,f)?d.combine(e[f],a):a}return e}(r,n):r,o=n.plainObjects?Object.create(null):{},i=Object.keys(e),u=0;u"+((null==(i=t.wheres[e])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+n+u+")?":""+n+u}).replace(/^\w+:\/\//,""),e=r.replace(/^\w+:\/\//,"").split("?"),o=e[0],i=e[1],u=new RegExp("^"+n+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:D(i)}}return!1},n.compile=function(r){var t=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,o){var i,u;if(!o&&[null,void 0].includes(r[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+t.name+"'.");if(t.wheres[e]&&!new RegExp("^"+(o?"("+t.wheres[e]+")?":t.wheres[e])+"$").test(null!=(u=r[e])?u:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+t.wheres[e]+"' for route '"+t.name+"'.");return encodeURI(null!=(i=r[e])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},t(r,[{key:"template",get:function(){var r=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===r?"/":r}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var r,t;return null!=(r=null==(t=this.template.match(/{[^}?]+\??}/g))?void 0:t.map(function(r){return{name:r.replace(/{|\??}/g,""),required:!/\?}$/.test(r)}}))?r:[]}}]),r}(),F=/*#__PURE__*/function(r){var e,i;function u(t,e,o,i){var u;if(void 0===o&&(o=!0),(u=r.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),t){if(!u.t.routes[t])throw new Error("Ziggy error: route '"+t+"' is not in the route list.");u.i=new $(t,u.t.routes[t],u.t),u.u=u.l(e)}return u}i=r,(e=u).prototype=Object.create(i.prototype),e.prototype.constructor=e,o(e,i);var f=u.prototype;return f.toString=function(){var r=this,t=Object.keys(this.u).filter(function(t){return!r.i.parameterSegments.some(function(r){return r.name===t})}).filter(function(r){return"_query"!==r}).reduce(function(t,e){var o;return n({},t,((o={})[e]=r.u[e],o))},{});return this.i.compile(this.u)+function(r,t){var n,e=r,o=function(r){if(!r)return R;if(null!=r.encoder&&"function"!=typeof r.encoder)throw new TypeError("Encoder has to be a function.");var t=r.charset||R.charset;if(void 0!==r.charset&&"utf-8"!==r.charset&&"iso-8859-1"!==r.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=l.default;if(void 0!==r.format){if(!b.call(l.formatters,r.format))throw new TypeError("Unknown format option provided.");n=r.format}var e=l.formatters[n],o=R.filter;return("function"==typeof r.filter||g(r.filter))&&(o=r.filter),{addQueryPrefix:"boolean"==typeof r.addQueryPrefix?r.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===r.allowDots?R.allowDots:!!r.allowDots,charset:t,charsetSentinel:"boolean"==typeof r.charsetSentinel?r.charsetSentinel:R.charsetSentinel,delimiter:void 0===r.delimiter?R.delimiter:r.delimiter,encode:"boolean"==typeof r.encode?r.encode:R.encode,encoder:"function"==typeof r.encoder?r.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof r.encodeValuesOnly?r.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:n,formatter:e,serializeDate:"function"==typeof r.serializeDate?r.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof r.skipNulls?r.skipNulls:R.skipNulls,sort:"function"==typeof r.sort?r.sort:null,strictNullHandling:"boolean"==typeof r.strictNullHandling?r.strictNullHandling:R.strictNullHandling}}(t);"function"==typeof o.filter?e=(0,o.filter)("",e):g(o.filter)&&(n=o.filter);var i=[];if("object"!=typeof e||null===e)return"";var u=h[t&&t.arrayFormat in h?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices"];n||(n=Object.keys(e)),o.sort&&n.sort(o.sort);for(var f=0;f0?s+c:""}(n({},t,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(r,t){return"boolean"==typeof r?Number(r):t(r)}})},f.v=function(r){var t=this;r?this.t.absolute&&r.startsWith("/")&&(r=this.p().host+r):r=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new $(n[0],n[1],t.t).matchesUrl(r)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var r=this.p(),t=r.pathname,n=r.search;return(this.t.absolute?r.host+t:t.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},f.current=function(r,t){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!r)return o;var a=new RegExp("^"+r.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(t)||!a)return a;var c=new $(o,f,this.t);t=this.l(t,c);var l=n({},i,u);return!(!Object.values(t).every(function(r){return!r})||Object.values(l).some(function(r){return void 0!==r}))||function r(t,n){return Object.entries(t).every(function(t){var e=t[0],o=t[1];return Array.isArray(o)&&Array.isArray(n[e])?o.every(function(r){return n[e].includes(r)}):"object"==typeof o&&"object"==typeof n[e]&&null!==o&&null!==n[e]?r(o,n[e]):n[e]==o})}(t,l)},f.p=function(){var r,t,n,e,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(r=null==(t=this.t.location)?void 0:t.host)?r:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(r){return Object.keys(this.t.routes).includes(r)},f.l=function(r,t){var e=this;void 0===r&&(r={}),void 0===t&&(t=this.i),null!=r||(r={}),r=["string","number"].includes(typeof r)?[r]:r;var o=t.parameterSegments.filter(function(r){return!e.t.defaults[r.name]});if(Array.isArray(r))r=r.reduce(function(r,t,e){var i,u;return n({},r,o[e]?((i={})[o[e].name]=t,i):"object"==typeof t?t:((u={})[t]="",u))},{});else if(1===o.length&&!r[o[0].name]&&(r.hasOwnProperty(Object.values(t.bindings)[0])||r.hasOwnProperty("id"))){var i;(i={})[o[0].name]=r,r=i}return n({},this.g(t),this.m(r,t))},f.g=function(r){var t=this;return r.parameterSegments.filter(function(r){return t.t.defaults[r.name]}).reduce(function(r,e,o){var i,u=e.name;return n({},r,((i={})[u]=t.t.defaults[u],i))},{})},f.m=function(r,t){var e=t.bindings,o=t.parameterSegments;return Object.entries(r).reduce(function(r,t){var i,u,f=t[0],a=t[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(r){return r.name===f}))return n({},r,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},r,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(r){return this.has(r)},t(u,[{key:"params",get:function(){var r=this.v();return n({},r.params,r.query)}}]),u}(/*#__PURE__*/u(String));function P(r){if(!r&&!globalThis.Ziggy&&"undefined"==typeof Ziggy)throw new Error("Ziggy error: missing configuration. Ensure that a `Ziggy` variable is defined globally or pass a config object into `useRoute()`.");return function(t,n,e,o){return void 0===o&&(o=r),function(r,t,n,e){var o=new F(r,t,n,e);return r?o.toString():o}(t,n,e,o)}}export{P as useRoute}; diff --git a/dist/vue.es.js b/dist/vue.es.js index 96acd92d..bff44f4d 100644 --- a/dist/vue.es.js +++ b/dist/vue.es.js @@ -1 +1 @@ -function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e1;){var e=t.pop(),r=e.obj[e.prop];if(u(r)){for(var n=[],o=0;o=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===o.RFC1738&&(40===c||41===c)?a+=u.charAt(f):c<128?a+=s[c]:c<2048?a+=s[192|c>>6]+s[128|63&c]:c<55296||c>=57344?a+=s[224|c>>12]+s[128|c>>6&63]+s[128|63&c]:(c=65536+((1023&c)<<10|1023&u.charCodeAt(f+=1)),a+=s[240|c>>18]+s[128|c>>12&63]+s[128|c>>6&63]+s[128|63&c])}return a},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(u(t)){for(var r=[],n=0;n0?w.join(",")||null:void 0}];else if(p(s))R=s;else{var N=Object.keys(w);R=a?N.sort(a):N}for(var k=0;k-1?t.split(","):t},S=function(t,e,r,n){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(o),s=u?o.slice(0,u.index):o,a=[];if(s){if(!r.plainObjects&&j.call(Object.prototype,s)&&!r.allowPrototypes)return;a.push(s)}for(var f=0;r.depth>0&&null!==(u=i.exec(o))&&f=0;--i){var u,s=t[i];if("[]"===s&&r.parseArrays)u=[].concat(o);else{u=r.plainObjects?Object.create(null):{};var a="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,f=parseInt(a,10);r.parseArrays||""!==a?!isNaN(f)&&s!==a&&String(f)===a&&f>=0&&r.parseArrays&&f<=r.arrayLimit?(u=[])[f]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,e,r,n)}},R=function(t,e){var r=function(t){if(!t)return $;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?$.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:$.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:$.arrayLimit,charset:void 0===t.charset?$.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:$.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:$.comma,decoder:"function"==typeof t.decoder?t.decoder:$.decoder,delimiter:"string"==typeof t.delimiter||f.isRegExp(t.delimiter)?t.delimiter:$.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:$.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:$.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:$.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:$.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:$.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),i=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(a=w(a)?[a]:a),n[s]=j.call(n,s)?f.combine(n[s],a):a}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var o;const i=`(?<${r}>${(null==(o=this.wheres[r])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${i})?`:`${e}${i}`}).replace(/^\w+:\/\//,""),[r,n]=t.replace(/^\w+:\/\//,"").split("?"),o=new RegExp(`^${e}/?$`).exec(decodeURI(r));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:R(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var o,i;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(i=t[r])?i:""))throw new Error(`Ziggy error: '${r}' parameter does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(o=t[r])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class N extends String{constructor(e,r,n=!0,o){if(super(),this.t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),e){if(!this.t.routes[e])throw new Error(`Ziggy error: route '${e}' is not in the route list.`);this.i=new x(e,this.t.routes[e],this.t),this.u=this.l(r)}}toString(){const e=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((e,r)=>t({},e,{[r]:this.u[r]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return m;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||m.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==t.format){if(!c.call(o.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=o.formatters[r],i=m.filter;return("function"==typeof t.filter||p(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:m.addQueryPrefix,allowDots:void 0===t.allowDots?m.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:m.charsetSentinel,delimiter:void 0===t.delimiter?m.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:m.encode,encoder:"function"==typeof t.encoder?t.encoder:m.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:m.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:m.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:m.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:m.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):p(i.filter)&&(r=i.filter);var u=[];if("object"!=typeof n||null===n)return"";var s=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var a=0;a0?y+h:""}(t({},e,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}p(e){e?this.t.absolute&&e.startsWith("/")&&(e=this.h().host+e):e=this.v();let r={};const[n,o]=Object.entries(this.t.routes).find(([t,n])=>r=new x(t,n,this.t).matchesUrl(e))||[void 0,void 0];return t({name:n},r,{route:o})}v(){const{host:t,pathname:e,search:r}=this.h();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(e,r){const{name:n,params:o,query:i,route:u}=this.p();if(!e)return n;const s=new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!s)return s;const a=new x(n,u,this.t);r=this.l(r,a);const f=t({},o,i);return!(!Object.values(r).every(t=>!t)||Object.values(f).some(t=>void 0!==t))||Object.entries(r).every(([t,e])=>f[t]==e)}h(){var t,e,r,n,o,i;const{host:u="",pathname:s="",search:a=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:u,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:s,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:a}}get params(){const{params:e,query:r}=this.p();return t({},e,r)}has(t){return Object.keys(this.t.routes).includes(t)}l(e={},r=this.i){null!=e||(e={}),e=["string","number"].includes(typeof e)?[e]:e;const n=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(e)?e=e.reduce((e,r,o)=>t({},e,n[o]?{[n[o].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==n.length||e[n[0].name]||!e.hasOwnProperty(Object.values(r.bindings)[0])&&!e.hasOwnProperty("id")||(e={[n[0].name]:e}),t({},this.m(r),this.g(e,r))}m(e){return e.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((e,{name:r},n)=>t({},e,{[r]:this.t.defaults[r]}),{})}g(e,{bindings:r,parameterSegments:n}){return Object.entries(e).reduce((e,[o,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||!n.some(({name:t})=>t===o))return t({},e,{[o]:i});if(!i.hasOwnProperty(r[o])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${o}' parameter is missing route model binding key '${r[o]}'.`);r[o]="id"}return t({},e,{[o]:i[r[o]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}const k={install(t,e){const r=(t,r,n,o=e)=>function(t,e,r,n){const o=new N(t,e,r,n);return t?o.toString():o}(t,r,n,o);t.mixin({methods:{route:r}}),parseInt(t.version)>2&&t.provide("route",r)}};export{k as ZiggyVue}; +function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e1;){var e=t.pop(),r=e.obj[e.prop];if(u(r)){for(var n=[],o=0;o=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||i===o.RFC1738&&(40===c||41===c)?a+=u.charAt(f):c<128?a+=s[c]:c<2048?a+=s[192|c>>6]+s[128|63&c]:c<55296||c>=57344?a+=s[224|c>>12]+s[128|c>>6&63]+s[128|63&c]:(c=65536+((1023&c)<<10|1023&u.charCodeAt(f+=1)),a+=s[240|c>>18]+s[128|c>>12&63]+s[128|c>>6&63]+s[128|63&c])}return a},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(u(t)){for(var r=[],n=0;n0?w.join(",")||null:void 0}];else if(p(s))R=s;else{var N=Object.keys(w);R=a?N.sort(a):N}for(var k=0;k-1?t.split(","):t},S=function(t,e,r,n){if(t){var o=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=r.depth>0&&/(\[[^[\]]*])/.exec(o),s=u?o.slice(0,u.index):o,a=[];if(s){if(!r.plainObjects&&j.call(Object.prototype,s)&&!r.allowPrototypes)return;a.push(s)}for(var f=0;r.depth>0&&null!==(u=i.exec(o))&&f=0;--i){var u,s=t[i];if("[]"===s&&r.parseArrays)u=[].concat(o);else{u=r.plainObjects?Object.create(null):{};var a="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,f=parseInt(a,10);r.parseArrays||""!==a?!isNaN(f)&&s!==a&&String(f)===a&&f>=0&&r.parseArrays&&f<=r.arrayLimit?(u=[])[f]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,e,r,n)}},R=function(t,e){var r=function(t){if(!t)return $;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?$.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:$.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:$.arrayLimit,charset:void 0===t.charset?$.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:$.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:$.comma,decoder:"function"==typeof t.decoder?t.decoder:$.decoder,delimiter:"string"==typeof t.delimiter||f.isRegExp(t.delimiter)?t.delimiter:$.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:$.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:$.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:$.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:$.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:$.strictNullHandling}}(e);if(""===t||null==t)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,e){var r,n={},o=(e.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(e.delimiter,Infinity===e.parameterLimit?void 0:e.parameterLimit),i=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r-1&&(a=w(a)?[a]:a),n[s]=j.call(n,s)?f.combine(n[s],a):a}return n}(t,r):t,o=r.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u({name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)})))?t:[]}matchesUrl(t){if(!this.definition.methods.includes("GET"))return!1;const e=this.template.replace(/(\/?){([^}?]*)(\??)}/g,(t,e,r,n)=>{var o;const i=`(?<${r}>${(null==(o=this.wheres[r])?void 0:o.replace(/(^\^)|(\$$)/g,""))||"[^/?]+"})`;return n?`(${e}${i})?`:`${e}${i}`}).replace(/^\w+:\/\//,""),[r,n]=t.replace(/^\w+:\/\//,"").split("?"),o=new RegExp(`^${e}/?$`).exec(decodeURI(r));if(o){for(const t in o.groups)o.groups[t]="string"==typeof o.groups[t]?decodeURIComponent(o.groups[t]):o.groups[t];return{params:o.groups,query:R(n)}}return!1}compile(t){return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,(e,r,n)=>{var o,i;if(!n&&[null,void 0].includes(t[r]))throw new Error(`Ziggy error: '${r}' parameter is required for route '${this.name}'.`);if(this.wheres[r]&&!new RegExp(`^${n?`(${this.wheres[r]})?`:this.wheres[r]}$`).test(null!=(i=t[r])?i:""))throw new Error(`Ziggy error: '${r}' parameter does not match required format '${this.wheres[r]}' for route '${this.name}'.`);return encodeURI(null!=(o=t[r])?o:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(`${this.origin}//`,`${this.origin}/`).replace(/\/+$/,""):this.template}}class N extends String{constructor(e,r,n=!0,o){if(super(),this.t=null!=o?o:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,this.t=t({},this.t,{absolute:n}),e){if(!this.t.routes[e])throw new Error(`Ziggy error: route '${e}' is not in the route list.`);this.i=new x(e,this.t.routes[e],this.t),this.u=this.l(r)}}toString(){const e=Object.keys(this.u).filter(t=>!this.i.parameterSegments.some(({name:e})=>e===t)).filter(t=>"_query"!==t).reduce((e,r)=>t({},e,{[r]:this.u[r]}),{});return this.i.compile(this.u)+function(t,e){var r,n=t,i=function(t){if(!t)return m;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||m.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=o.default;if(void 0!==t.format){if(!c.call(o.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var n=o.formatters[r],i=m.filter;return("function"==typeof t.filter||p(t.filter))&&(i=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:m.addQueryPrefix,allowDots:void 0===t.allowDots?m.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:m.charsetSentinel,delimiter:void 0===t.delimiter?m.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:m.encode,encoder:"function"==typeof t.encoder?t.encoder:m.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:m.encodeValuesOnly,filter:i,format:r,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:m.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:m.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:m.strictNullHandling}}(e);"function"==typeof i.filter?n=(0,i.filter)("",n):p(i.filter)&&(r=i.filter);var u=[];if("object"!=typeof n||null===n)return"";var s=l[e&&e.arrayFormat in l?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices"];r||(r=Object.keys(n)),i.sort&&r.sort(i.sort);for(var a=0;a0?y+h:""}(t({},e,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:(t,e)=>"boolean"==typeof t?Number(t):e(t)})}p(e){e?this.t.absolute&&e.startsWith("/")&&(e=this.h().host+e):e=this.v();let r={};const[n,o]=Object.entries(this.t.routes).find(([t,n])=>r=new x(t,n,this.t).matchesUrl(e))||[void 0,void 0];return t({name:n},r,{route:o})}v(){const{host:t,pathname:e,search:r}=this.h();return(this.t.absolute?t+e:e.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+r}current(e,r){const{name:n,params:o,query:i,route:u}=this.p();if(!e)return n;const s=new RegExp(`^${e.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(n);if([null,void 0].includes(r)||!s)return s;const a=new x(n,u,this.t);r=this.l(r,a);const f=t({},o,i);if(Object.values(r).every(t=>!t)&&!Object.values(f).some(t=>void 0!==t))return!0;const c=(t,e)=>Object.entries(t).every(([t,r])=>Array.isArray(r)&&Array.isArray(e[t])?r.every(r=>e[t].includes(r)):"object"==typeof r&&"object"==typeof e[t]&&null!==r&&null!==e[t]?c(r,e[t]):e[t]==r);return c(r,f)}h(){var t,e,r,n,o,i;const{host:u="",pathname:s="",search:a=""}="undefined"!=typeof window?window.location:{};return{host:null!=(t=null==(e=this.t.location)?void 0:e.host)?t:u,pathname:null!=(r=null==(n=this.t.location)?void 0:n.pathname)?r:s,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:a}}get params(){const{params:e,query:r}=this.p();return t({},e,r)}has(t){return Object.keys(this.t.routes).includes(t)}l(e={},r=this.i){null!=e||(e={}),e=["string","number"].includes(typeof e)?[e]:e;const n=r.parameterSegments.filter(({name:t})=>!this.t.defaults[t]);return Array.isArray(e)?e=e.reduce((e,r,o)=>t({},e,n[o]?{[n[o].name]:r}:"object"==typeof r?r:{[r]:""}),{}):1!==n.length||e[n[0].name]||!e.hasOwnProperty(Object.values(r.bindings)[0])&&!e.hasOwnProperty("id")||(e={[n[0].name]:e}),t({},this.m(r),this.g(e,r))}m(e){return e.parameterSegments.filter(({name:t})=>this.t.defaults[t]).reduce((e,{name:r},n)=>t({},e,{[r]:this.t.defaults[r]}),{})}g(e,{bindings:r,parameterSegments:n}){return Object.entries(e).reduce((e,[o,i])=>{if(!i||"object"!=typeof i||Array.isArray(i)||!n.some(({name:t})=>t===o))return t({},e,{[o]:i});if(!i.hasOwnProperty(r[o])){if(!i.hasOwnProperty("id"))throw new Error(`Ziggy error: object passed as '${o}' parameter is missing route model binding key '${r[o]}'.`);r[o]="id"}return t({},e,{[o]:i[r[o]]})},{})}valueOf(){return this.toString()}check(t){return this.has(t)}}const k={install(t,e){const r=(t,r,n,o=e)=>function(t,e,r,n){const o=new N(t,e,r,n);return t?o.toString():o}(t,r,n,o);t.mixin({methods:{route:r}}),parseInt(t.version)>2&&t.provide("route",r)}};export{k as ZiggyVue}; diff --git a/dist/vue.js b/dist/vue.js index 5b5722b9..582ab19a 100644 --- a/dist/vue.js +++ b/dist/vue.js @@ -1 +1 @@ -!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t||self).ZiggyVue={})}(this,function(t){function r(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(p(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===s.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=y[a]:a<2048?u+=y[192|a>>6]+y[128|63&a]:a<55296||a>=57344?u+=y[224|a>>12]+y[128|a>>6&63]+y[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=y[240|a>>18]+y[128|a>>12&63]+y[128|a>>6&63]+y[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(p(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(m(f))x=f;else{var k=Object.keys(h);x=a?k.sort(a):k}for(var N=0;N-1?t.split(","):t},$=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&T.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},F=function(t,r){var e=function(t){if(!t)return N;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?N.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:N.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:N.arrayLimit,charset:void 0===t.charset?N.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:N.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:N.comma,decoder:"function"==typeof t.decoder?t.decoder:N.decoder,delimiter:"string"==typeof t.delimiter||b.isRegExp(t.delimiter)?t.delimiter:N.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:N.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:N.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:N.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:N.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:N.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=k(a)?[a]:a),n[f]=T.call(n,f)?b.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:F(i)}}return!1},r.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),P=/*#__PURE__*/function(t){var r,o;function u(r,e,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new I(r,u.t.routes[r],u.t),u.u=u.l(e)}return u}o=t,(r=u).prototype=Object.create(o.prototype),r.prototype.constructor=r,i(r,o);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var o;return n({},r,((o={})[e]=t.u[e],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return S;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||S.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=s.default;if(void 0!==t.format){if(!h.call(s.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=s.formatters[e],o=S.filter;return("function"==typeof t.filter||m(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:S.addQueryPrefix,allowDots:void 0===t.allowDots?S.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:S.charsetSentinel,delimiter:void 0===t.delimiter?S.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:S.encode,encoder:"function"==typeof t.encoder?t.encoder:S.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:S.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:S.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:S.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:S.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):m(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=g[r&&r.arrayFormat in g?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?l+c:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new I(n[0],n[1],r.t).matchesUrl(t)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new I(o,f,this.t);r=this.l(r,c);var l=n({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var i,u;return n({},t,o[e]?((i={})[o[e].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return n({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,o){var i,u=e.name;return n({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var e=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return n({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},t,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},e(u,[{key:"params",get:function(){var t=this.v();return n({},t.params,t.query)}}]),u}(/*#__PURE__*/f(String));t.ZiggyVue={install:function(t,r){var e=function(t,e,n,o){return void 0===o&&(o=r),function(t,r,e,n){var o=new P(t,r,e,n);return t?o.toString():o}(t,e,n,o)};t.mixin({methods:{route:e}}),parseInt(t.version)>2&&t.provide("route",e)}}}); +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t||self).ZiggyVue={})}(this,function(t){function r(t,r){for(var e=0;e1;){var r=t.pop(),e=r.obj[r.prop];if(p(e)){for(var n=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===s.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=y[a]:a<2048?u+=y[192|a>>6]+y[128|63&a]:a<55296||a>=57344?u+=y[224|a>>12]+y[128|a>>6&63]+y[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=y[240|a>>18]+y[128|a>>12&63]+y[128|a>>6&63]+y[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(p(t)){for(var e=[],n=0;n0?h.join(",")||null:void 0}];else if(m(f))x=f;else{var k=Object.keys(h);x=a?k.sort(a):k}for(var N=0;N-1?t.split(","):t},D=function(t,r,e,n){if(t){var o=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=e.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!e.plainObjects&&T.call(Object.prototype,f)&&!e.allowPrototypes)return;a.push(f)}for(var c=0;e.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&e.parseArrays)u=[].concat(o);else{u=e.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);e.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,e,n)}},$=function(t,r){var e=function(t){if(!t)return N;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?N.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:N.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:N.arrayLimit,charset:void 0===t.charset?N.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:N.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:N.comma,decoder:"function"==typeof t.decoder?t.decoder:N.decoder,delimiter:"string"==typeof t.delimiter||b.isRegExp(t.delimiter)?t.delimiter:N.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:N.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:N.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:N.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:N.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:N.strictNullHandling}}(r);if(""===t||null==t)return e.plainObjects?Object.create(null):{};for(var n="string"==typeof t?function(t,r){var e,n={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(e=0;e-1&&(a=k(a)?[a]:a),n[f]=T.call(n,f)?b.combine(n[f],a):a}return n}(t,e):t,o=e.plainObjects?Object.create(null):{},i=Object.keys(n),u=0;u"+((null==(i=r.wheres[n])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+e+u+")?":""+e+u}).replace(/^\w+:\/\//,""),n=t.replace(/^\w+:\/\//,"").split("?"),o=n[0],i=n[1],u=new RegExp("^"+e+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:$(i)}}return!1},r.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(e,n,o){var i,u;if(!o&&[null,void 0].includes(t[n]))throw new Error("Ziggy error: '"+n+"' parameter is required for route '"+r.name+"'.");if(r.wheres[n]&&!new RegExp("^"+(o?"("+r.wheres[n]+")?":r.wheres[n])+"$").test(null!=(u=t[n])?u:""))throw new Error("Ziggy error: '"+n+"' parameter does not match required format '"+r.wheres[n]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[n])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},e(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),I=/*#__PURE__*/function(t){var r,o;function u(r,e,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new F(r,u.t.routes[r],u.t),u.u=u.l(e)}return u}o=t,(r=u).prototype=Object.create(o.prototype),r.prototype.constructor=r,i(r,o);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var o;return n({},r,((o={})[e]=t.u[e],o))},{});return this.i.compile(this.u)+function(t,r){var e,n=t,o=function(t){if(!t)return S;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||S.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=s.default;if(void 0!==t.format){if(!h.call(s.formatters,t.format))throw new TypeError("Unknown format option provided.");e=t.format}var n=s.formatters[e],o=S.filter;return("function"==typeof t.filter||m(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:S.addQueryPrefix,allowDots:void 0===t.allowDots?S.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:S.charsetSentinel,delimiter:void 0===t.delimiter?S.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:S.encode,encoder:"function"==typeof t.encoder?t.encoder:S.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:S.encodeValuesOnly,filter:o,format:e,formatter:n,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:S.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:S.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:S.strictNullHandling}}(r);"function"==typeof o.filter?n=(0,o.filter)("",n):m(o.filter)&&(e=o.filter);var i=[];if("object"!=typeof n||null===n)return"";var u=g[r&&r.arrayFormat in g?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];e||(e=Object.keys(n)),o.sort&&e.sort(o.sort);for(var f=0;f0?l+c:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new F(n[0],n[1],r.t).matchesUrl(t)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,e=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+e},f.current=function(t,r){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new F(o,f,this.t);r=this.l(r,c);var l=n({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||function t(r,e){return Object.entries(r).every(function(r){var n=r[0],o=r[1];return Array.isArray(o)&&Array.isArray(e[n])?o.every(function(t){return e[n].includes(t)}):"object"==typeof o&&"object"==typeof e[n]&&null!==o&&null!==e[n]?t(o,e[n]):e[n]==o})}(r,l)},f.p=function(){var t,r,e,n,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(e=null==(n=this.t.location)?void 0:n.pathname)?e:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var i,u;return n({},t,o[e]?((i={})[o[e].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return n({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,o){var i,u=e.name;return n({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var e=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return n({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},t,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},e(u,[{key:"params",get:function(){var t=this.v();return n({},t.params,t.query)}}]),u}(/*#__PURE__*/f(String));t.ZiggyVue={install:function(t,r){var e=function(t,e,n,o){return void 0===o&&(o=r),function(t,r,e,n){var o=new I(t,r,e,n);return t?o.toString():o}(t,e,n,o)};t.mixin({methods:{route:e}}),parseInt(t.version)>2&&t.provide("route",e)}}}); diff --git a/dist/vue.m.js b/dist/vue.m.js index 6ff42447..91497286 100644 --- a/dist/vue.m.js +++ b/dist/vue.m.js @@ -1 +1 @@ -function t(t,r){for(var n=0;n1;){var r=t.pop(),n=r.obj[r.prop];if(v(n)){for(var e=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(v(t)){for(var n=[],e=0;e0?h.join(",")||null:void 0}];else if(g(f))k=f;else{var T=Object.keys(h);k=a?T.sort(a):T}for(var N=0;N-1?t.split(","):t},D=function(t,r,n,e){if(t){var o=n.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=n.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!n.plainObjects&&k.call(Object.prototype,f)&&!n.allowPrototypes)return;a.push(f)}for(var c=0;n.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&n.parseArrays)u=[].concat(o);else{u=n.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);n.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,n,e)}},$=function(t,r){var n=function(t){if(!t)return T;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?T.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:T.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:T.arrayLimit,charset:void 0===t.charset?T.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:T.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:T.comma,decoder:"function"==typeof t.decoder?t.decoder:T.decoder,delimiter:"string"==typeof t.delimiter||d.isRegExp(t.delimiter)?t.delimiter:T.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:T.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:T.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:T.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:T.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:T.strictNullHandling}}(r);if(""===t||null==t)return n.plainObjects?Object.create(null):{};for(var e="string"==typeof t?function(t,r){var n,e={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(n=0;n-1&&(a=x(a)?[a]:a),e[f]=k.call(e,f)?d.combine(e[f],a):a}return e}(t,n):t,o=n.plainObjects?Object.create(null):{},i=Object.keys(e),u=0;u"+((null==(i=r.wheres[e])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+n+u+")?":""+n+u}).replace(/^\w+:\/\//,""),e=t.replace(/^\w+:\/\//,"").split("?"),o=e[0],i=e[1],u=new RegExp("^"+n+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:$(i)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,o){var i,u;if(!o&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(o?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(u=t[e])?u:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[e])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),I=/*#__PURE__*/function(t){var e,i;function u(r,e,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new F(r,u.t.routes[r],u.t),u.u=u.l(e)}return u}i=t,(e=u).prototype=Object.create(i.prototype),e.prototype.constructor=e,o(e,i);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var o;return n({},r,((o={})[e]=t.u[e],o))},{});return this.i.compile(this.u)+function(t,r){var n,e=t,o=function(t){if(!t)return R;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||R.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=l.default;if(void 0!==t.format){if(!b.call(l.formatters,t.format))throw new TypeError("Unknown format option provided.");n=t.format}var e=l.formatters[n],o=R.filter;return("function"==typeof t.filter||g(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===t.allowDots?R.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:R.charsetSentinel,delimiter:void 0===t.delimiter?R.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:R.encode,encoder:"function"==typeof t.encoder?t.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:n,formatter:e,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:R.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:R.strictNullHandling}}(r);"function"==typeof o.filter?e=(0,o.filter)("",e):g(o.filter)&&(n=o.filter);var i=[];if("object"!=typeof e||null===e)return"";var u=h[r&&r.arrayFormat in h?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];n||(n=Object.keys(e)),o.sort&&n.sort(o.sort);for(var f=0;f0?s+c:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new F(n[0],n[1],r.t).matchesUrl(t)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},f.current=function(t,r){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new F(o,f,this.t);r=this.l(r,c);var l=n({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||Object.entries(r).every(function(t){return l[t[0]]==t[1]})},f.p=function(){var t,r,n,e,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var i,u;return n({},t,o[e]?((i={})[o[e].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return n({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,o){var i,u=e.name;return n({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var e=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return n({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},t,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},r(u,[{key:"params",get:function(){var t=this.v();return n({},t.params,t.query)}}]),u}(/*#__PURE__*/u(String)),P={install:function(t,r){var n=function(t,n,e,o){return void 0===o&&(o=r),function(t,r,n,e){var o=new I(t,r,n,e);return t?o.toString():o}(t,n,e,o)};t.mixin({methods:{route:n}}),parseInt(t.version)>2&&t.provide("route",n)}};export{P as ZiggyVue}; +function t(t,r){for(var n=0;n1;){var r=t.pop(),n=r.obj[r.prop];if(v(n)){for(var e=[],o=0;o=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||o===l.RFC1738&&(40===a||41===a)?u+=i.charAt(f):a<128?u+=p[a]:a<2048?u+=p[192|a>>6]+p[128|63&a]:a<55296||a>=57344?u+=p[224|a>>12]+p[128|a>>6&63]+p[128|63&a]:(a=65536+((1023&a)<<10|1023&i.charCodeAt(f+=1)),u+=p[240|a>>18]+p[128|a>>12&63]+p[128|a>>6&63]+p[128|63&a])}return u},isBuffer:function(t){return!(!t||"object"!=typeof t||!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t)))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,r){if(v(t)){for(var n=[],e=0;e0?h.join(",")||null:void 0}];else if(g(f))k=f;else{var T=Object.keys(h);k=a?T.sort(a):T}for(var N=0;N-1?t.split(","):t},A=function(t,r,n,e){if(t){var o=n.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/g,u=n.depth>0&&/(\[[^[\]]*])/.exec(o),f=u?o.slice(0,u.index):o,a=[];if(f){if(!n.plainObjects&&k.call(Object.prototype,f)&&!n.allowPrototypes)return;a.push(f)}for(var c=0;n.depth>0&&null!==(u=i.exec(o))&&c=0;--i){var u,f=t[i];if("[]"===f&&n.parseArrays)u=[].concat(o);else{u=n.plainObjects?Object.create(null):{};var a="["===f.charAt(0)&&"]"===f.charAt(f.length-1)?f.slice(1,-1):f,c=parseInt(a,10);n.parseArrays||""!==a?!isNaN(c)&&f!==a&&String(c)===a&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(u=[])[c]=o:"__proto__"!==a&&(u[a]=o):u={0:o}}o=u}return o}(a,r,n,e)}},D=function(t,r){var n=function(t){if(!t)return T;if(null!=t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");return{allowDots:void 0===t.allowDots?T.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:T.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:T.arrayLimit,charset:void 0===t.charset?T.charset:t.charset,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:T.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:T.comma,decoder:"function"==typeof t.decoder?t.decoder:T.decoder,delimiter:"string"==typeof t.delimiter||d.isRegExp(t.delimiter)?t.delimiter:T.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:T.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:T.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:T.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:T.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:T.strictNullHandling}}(r);if(""===t||null==t)return n.plainObjects?Object.create(null):{};for(var e="string"==typeof t?function(t,r){var n,e={},o=(r.ignoreQueryPrefix?t.replace(/^\?/,""):t).split(r.delimiter,Infinity===r.parameterLimit?void 0:r.parameterLimit),i=-1,u=r.charset;if(r.charsetSentinel)for(n=0;n-1&&(a=x(a)?[a]:a),e[f]=k.call(e,f)?d.combine(e[f],a):a}return e}(t,n):t,o=n.plainObjects?Object.create(null):{},i=Object.keys(e),u=0;u"+((null==(i=r.wheres[e])?void 0:i.replace(/(^\^)|(\$$)/g,""))||"[^/?]+")+")";return o?"("+n+u+")?":""+n+u}).replace(/^\w+:\/\//,""),e=t.replace(/^\w+:\/\//,"").split("?"),o=e[0],i=e[1],u=new RegExp("^"+n+"/?$").exec(decodeURI(o));if(u){for(var f in u.groups)u.groups[f]="string"==typeof u.groups[f]?decodeURIComponent(u.groups[f]):u.groups[f];return{params:u.groups,query:D(i)}}return!1},n.compile=function(t){var r=this;return this.parameterSegments.length?this.template.replace(/{([^}?]+)(\??)}/g,function(n,e,o){var i,u;if(!o&&[null,void 0].includes(t[e]))throw new Error("Ziggy error: '"+e+"' parameter is required for route '"+r.name+"'.");if(r.wheres[e]&&!new RegExp("^"+(o?"("+r.wheres[e]+")?":r.wheres[e])+"$").test(null!=(u=t[e])?u:""))throw new Error("Ziggy error: '"+e+"' parameter does not match required format '"+r.wheres[e]+"' for route '"+r.name+"'.");return encodeURI(null!=(i=t[e])?i:"").replace(/%7C/g,"|").replace(/%25/g,"%").replace(/\$/g,"%24")}).replace(this.origin+"//",this.origin+"/").replace(/\/+$/,""):this.template},r(t,[{key:"template",get:function(){var t=(this.origin+"/"+this.definition.uri).replace(/\/+$/,"");return""===t?"/":t}},{key:"origin",get:function(){return this.config.absolute?this.definition.domain?""+this.config.url.match(/^\w+:\/\//)[0]+this.definition.domain+(this.config.port?":"+this.config.port:""):this.config.url:""}},{key:"parameterSegments",get:function(){var t,r;return null!=(t=null==(r=this.template.match(/{[^}?]+\??}/g))?void 0:r.map(function(t){return{name:t.replace(/{|\??}/g,""),required:!/\?}$/.test(t)}}))?t:[]}}]),t}(),F=/*#__PURE__*/function(t){var e,i;function u(r,e,o,i){var u;if(void 0===o&&(o=!0),(u=t.call(this)||this).t=null!=i?i:"undefined"!=typeof Ziggy?Ziggy:null==globalThis?void 0:globalThis.Ziggy,u.t=n({},u.t,{absolute:o}),r){if(!u.t.routes[r])throw new Error("Ziggy error: route '"+r+"' is not in the route list.");u.i=new $(r,u.t.routes[r],u.t),u.u=u.l(e)}return u}i=t,(e=u).prototype=Object.create(i.prototype),e.prototype.constructor=e,o(e,i);var f=u.prototype;return f.toString=function(){var t=this,r=Object.keys(this.u).filter(function(r){return!t.i.parameterSegments.some(function(t){return t.name===r})}).filter(function(t){return"_query"!==t}).reduce(function(r,e){var o;return n({},r,((o={})[e]=t.u[e],o))},{});return this.i.compile(this.u)+function(t,r){var n,e=t,o=function(t){if(!t)return R;if(null!=t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var r=t.charset||R.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=l.default;if(void 0!==t.format){if(!b.call(l.formatters,t.format))throw new TypeError("Unknown format option provided.");n=t.format}var e=l.formatters[n],o=R.filter;return("function"==typeof t.filter||g(t.filter))&&(o=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:R.addQueryPrefix,allowDots:void 0===t.allowDots?R.allowDots:!!t.allowDots,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:R.charsetSentinel,delimiter:void 0===t.delimiter?R.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:R.encode,encoder:"function"==typeof t.encoder?t.encoder:R.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:R.encodeValuesOnly,filter:o,format:n,formatter:e,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:R.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:R.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:R.strictNullHandling}}(r);"function"==typeof o.filter?e=(0,o.filter)("",e):g(o.filter)&&(n=o.filter);var i=[];if("object"!=typeof e||null===e)return"";var u=h[r&&r.arrayFormat in h?r.arrayFormat:r&&"indices"in r?r.indices?"indices":"repeat":"indices"];n||(n=Object.keys(e)),o.sort&&n.sort(o.sort);for(var f=0;f0?s+c:""}(n({},r,this.u._query),{addQueryPrefix:!0,arrayFormat:"indices",encodeValuesOnly:!0,skipNulls:!0,encoder:function(t,r){return"boolean"==typeof t?Number(t):r(t)}})},f.v=function(t){var r=this;t?this.t.absolute&&t.startsWith("/")&&(t=this.p().host+t):t=this.h();var e={},o=Object.entries(this.t.routes).find(function(n){return e=new $(n[0],n[1],r.t).matchesUrl(t)})||[void 0,void 0];return n({name:o[0]},e,{route:o[1]})},f.h=function(){var t=this.p(),r=t.pathname,n=t.search;return(this.t.absolute?t.host+r:r.replace(this.t.url.replace(/^\w*:\/\/[^/]+/,""),"").replace(/^\/+/,"/"))+n},f.current=function(t,r){var e=this.v(),o=e.name,i=e.params,u=e.query,f=e.route;if(!t)return o;var a=new RegExp("^"+t.replace(/\./g,"\\.").replace(/\*/g,".*")+"$").test(o);if([null,void 0].includes(r)||!a)return a;var c=new $(o,f,this.t);r=this.l(r,c);var l=n({},i,u);return!(!Object.values(r).every(function(t){return!t})||Object.values(l).some(function(t){return void 0!==t}))||function t(r,n){return Object.entries(r).every(function(r){var e=r[0],o=r[1];return Array.isArray(o)&&Array.isArray(n[e])?o.every(function(t){return n[e].includes(t)}):"object"==typeof o&&"object"==typeof n[e]&&null!==o&&null!==n[e]?t(o,n[e]):n[e]==o})}(r,l)},f.p=function(){var t,r,n,e,o,i,u="undefined"!=typeof window?window.location:{},f=u.host,a=u.pathname,c=u.search;return{host:null!=(t=null==(r=this.t.location)?void 0:r.host)?t:void 0===f?"":f,pathname:null!=(n=null==(e=this.t.location)?void 0:e.pathname)?n:void 0===a?"":a,search:null!=(o=null==(i=this.t.location)?void 0:i.search)?o:void 0===c?"":c}},f.has=function(t){return Object.keys(this.t.routes).includes(t)},f.l=function(t,r){var e=this;void 0===t&&(t={}),void 0===r&&(r=this.i),null!=t||(t={}),t=["string","number"].includes(typeof t)?[t]:t;var o=r.parameterSegments.filter(function(t){return!e.t.defaults[t.name]});if(Array.isArray(t))t=t.reduce(function(t,r,e){var i,u;return n({},t,o[e]?((i={})[o[e].name]=r,i):"object"==typeof r?r:((u={})[r]="",u))},{});else if(1===o.length&&!t[o[0].name]&&(t.hasOwnProperty(Object.values(r.bindings)[0])||t.hasOwnProperty("id"))){var i;(i={})[o[0].name]=t,t=i}return n({},this.g(r),this.m(t,r))},f.g=function(t){var r=this;return t.parameterSegments.filter(function(t){return r.t.defaults[t.name]}).reduce(function(t,e,o){var i,u=e.name;return n({},t,((i={})[u]=r.t.defaults[u],i))},{})},f.m=function(t,r){var e=r.bindings,o=r.parameterSegments;return Object.entries(t).reduce(function(t,r){var i,u,f=r[0],a=r[1];if(!a||"object"!=typeof a||Array.isArray(a)||!o.some(function(t){return t.name===f}))return n({},t,((u={})[f]=a,u));if(!a.hasOwnProperty(e[f])){if(!a.hasOwnProperty("id"))throw new Error("Ziggy error: object passed as '"+f+"' parameter is missing route model binding key '"+e[f]+"'.");e[f]="id"}return n({},t,((i={})[f]=a[e[f]],i))},{})},f.valueOf=function(){return this.toString()},f.check=function(t){return this.has(t)},r(u,[{key:"params",get:function(){var t=this.v();return n({},t.params,t.query)}}]),u}(/*#__PURE__*/u(String)),I={install:function(t,r){var n=function(t,n,e,o){return void 0===o&&(o=r),function(t,r,n,e){var o=new F(t,r,n,e);return t?o.toString():o}(t,n,e,o)};t.mixin({methods:{route:n}}),parseInt(t.version)>2&&t.provide("route",n)}};export{I as ZiggyVue}; diff --git a/package-lock.json b/package-lock.json index 50385e04..47a416d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ziggy-js", - "version": "1.8.1", + "version": "1.8.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ziggy-js", - "version": "1.8.1", + "version": "1.8.2", "license": "MIT", "dependencies": { "qs": "~6.9.7" diff --git a/package.json b/package.json index 9b3db7ed..d10f4611 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ziggy-js", - "version": "1.8.1", + "version": "1.8.2", "description": "Use your Laravel named routes in JavaScript.", "keywords": [ "laravel",