preact-router
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -1,2 +0,2 @@ | ||
var t=require("preact"),e=require("preact/hooks");function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}var r={};function o(t,e){for(var n in e)t[n]=e[n];return t}function i(t,e,n){var o,i=/(?:\?([^#]*))?(#.*)?$/,a=t.match(i),u={};if(a&&a[1])for(var p=a[1].split("&"),l=0;l<p.length;l++){var s=p[l].split("=");u[decodeURIComponent(s[0])]=decodeURIComponent(s.slice(1).join("="))}t=c(t.replace(i,"")),e=c(e||"");for(var h=Math.max(t.length,e.length),f=0;f<h;f++)if(e[f]&&":"===e[f].charAt(0)){var d=e[f].replace(/(^:|[+*?]+$)/g,""),v=(e[f].match(/[+*?]+$/)||r)[0]||"",g=~v.indexOf("+"),m=~v.indexOf("*"),y=t[f]||"";if(!y&&!m&&(v.indexOf("?")<0||g)){o=!1;break}if(u[d]=decodeURIComponent(y),g||m){u[d]=t.slice(f).map(decodeURIComponent).join("/");break}}else if(e[f]!==t[f]){o=!1;break}return(!0===n.default||!1!==o)&&u}function a(t,e){return t.rank<e.rank?1:t.rank>e.rank?-1:t.index-e.index}function u(t,e){return t.index=e,t.rank=function(t){return t.props.default?0:c(t.props.path).map(p).join("")}(t),t.props}function c(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")}function p(t){return":"==t.charAt(0)?1+"*+?".indexOf(t.charAt(t.length-1))||4:5}var l=t.createContext({}),s=null,h=[],f={};function d(){var t;return""+((t=s&&s.location?s.location:s&&s.getCurrentLocation?s.getCurrentLocation():"undefined"!=typeof location?location:f).pathname||"")+(t.search||"")}function v(t,e){return void 0===e&&(e=!1),"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),function(t){for(var e=h.length;e--;)if(h[e].canRoute(t))return!0;return!1}(t)&&function(t,e){void 0===e&&(e="push"),s&&s[e]?s[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}(t,e?"replace":"push"),g(t)}function g(t){for(var e=!1,n=0;n<h.length;n++)!0===h[n].routeTo(t)&&(e=!0);return e}function m(t){if(t&&t.getAttribute){var e=t.getAttribute("href"),n=t.getAttribute("target");if(e&&e.match(/^\//g)&&(!n||n.match(/^_?self$/i)))return v(e)}}function y(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button))return m(t.currentTarget||t.target||this),C(t)}function C(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function x(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button)){var e=t.target;do{if("A"===String(e.nodeName).toUpperCase()&&e.getAttribute("href")){if(e.hasAttribute("data-native")||e.hasAttribute("native"))return;if(m(e))return C(t)}}while(e=e.parentNode)}}var b=!1,k=/*#__PURE__*/function(e){var r,c;function p(t){var n;return n=e.call(this,t)||this,t.history&&(s=t.history),n.state={url:t.url||d()},n.contextValue={},b||("function"==typeof addEventListener&&(s||addEventListener("popstate",function(){g(d())}),addEventListener("click",x)),b=!0),n}c=e,(r=p).prototype=Object.create(c.prototype),r.prototype.constructor=r,n(r,c);var f=p.prototype;return f.shouldComponentUpdate=function(t){return!0!==t.static||t.url!==this.props.url||t.onChange!==this.props.onChange},f.canRoute=function(e){var n=t.toChildArray(this.props.children);return this.getMatchingChildren(n,e,!1).length>0},f.routeTo=function(t){this.setState({url:t});var e=this.canRoute(t);return this.updating||this.forceUpdate(),e},f.componentWillMount=function(){this.updating=!0},f.componentDidMount=function(){var t=this;h.push(this),s&&(this.unlisten=s.listen(function(e){var n=e.location||e;t.routeTo(""+(n.pathname||"")+(n.search||""))})),this.updating=!1},f.componentWillUnmount=function(){"function"==typeof this.unlisten&&this.unlisten(),h.splice(h.indexOf(this),1)},f.componentWillUpdate=function(){this.updating=!0},f.componentDidUpdate=function(){this.updating=!1},f.getMatchingChildren=function(e,n,r){return e.filter(u).sort(a).map(function(e){var a=i(n,e.props.path,e.props);if(a){if(!1!==r){var u={url:n,matches:a};return o(u,a),delete u.ref,delete u.key,{vnode:t.cloneElement(e,u),matches:a}}return{vnode:e,matches:a}}}).filter(Boolean)},f.render=function(e,n){var r=e.onChange,o=n.url,i=this.getMatchingChildren(t.toChildArray(e.children),o,!0),a=i[0]||{vnode:null,matches:null},u=a.vnode,c=a.matches,p=this.previousUrl;return o!==p&&(this.previousUrl=o,this.contextValue={router:this,url:o,previous:p,active:i.map(function(t){return t.vnode}),current:u,path:u?u.props.path:null,matches:c},"function"==typeof r&&r(this.contextValue)),t.h(l.Provider,{value:this.contextValue},u)},p}(t.Component);k.getCurrentUrl=d,k.route=v,k.Router=k,k.Route=function(e){return t.createElement(e.component,e)},k.Link=function(e){return t.createElement("a",o({onClick:y},e))},k.exec=i,k.useRouter=function(){return[e.useContext(l),v]},module.exports=k; | ||
var n=require("preact"),t=require("preact/hooks"),r={};function i(n,t){for(var r in t)n[r]=t[r];return n}function e(n,t,i){var e,o=/(?:\?([^#]*))?(#.*)?$/,u=n.match(o),c={};if(u&&u[1])for(var a=u[1].split("&"),h=0;h<a.length;h++){var s=a[h].split("=");c[decodeURIComponent(s[0])]=decodeURIComponent(s.slice(1).join("="))}n=f(n.replace(o,"")),t=f(t||"");for(var v=Math.max(n.length,t.length),d=0;d<v;d++)if(t[d]&&":"===t[d].charAt(0)){var l=t[d].replace(/(^:|[+*?]+$)/g,""),p=(t[d].match(/[+*?]+$/)||r)[0]||"",m=~p.indexOf("+"),y=~p.indexOf("*"),U=n[d]||"";if(!U&&!y&&(p.indexOf("?")<0||m)){e=!1;break}if(c[l]=decodeURIComponent(U),m||y){c[l]=n.slice(d).map(decodeURIComponent).join("/");break}}else if(t[d]!==n[d]){e=!1;break}return(!0===i.default||!1!==e)&&c}function o(n,t){return n.rank<t.rank?1:n.rank>t.rank?-1:n.index-t.index}function u(n,t){return n.index=t,n.rank=function(n){return n.props.default?0:f(n.props.path).map(c).join("")}(n),n.props}function f(n){return n.replace(/(^\/+|\/+$)/g,"").split("/")}function c(n){return":"==n.charAt(0)?1+"*+?".indexOf(n.charAt(n.length-1))||4:5}var a={},h=[],s=[],v=null,d={url:p()},l=n.createContext(d);function p(){var n;return""+((n=v&&v.location?v.location:v&&v.getCurrentLocation?v.getCurrentLocation():"undefined"!=typeof location?location:a).pathname||"")+(n.search||"")}function m(n,t){return void 0===t&&(t=!1),"string"!=typeof n&&n.url&&(t=n.replace,n=n.url),function(n){for(var t=h.length;t--;)if(h[t].canRoute(n))return!0;return!1}(n)&&function(n,t){void 0===t&&(t="push"),v&&v[t]?v[t](n):"undefined"!=typeof history&&history[t+"State"]&&history[t+"State"](null,null,n)}(n,t?"replace":"push"),y(n)}function y(n){for(var t=!1,r=0;r<h.length;r++)h[r].routeTo(n)&&(t=!0);return t}function U(n){if(n&&n.getAttribute){var t=n.getAttribute("href"),r=n.getAttribute("target");if(t&&t.match(/^\//g)&&(!r||r.match(/^_?self$/i)))return m(t)}}function g(n){return n.stopImmediatePropagation&&n.stopImmediatePropagation(),n.stopPropagation&&n.stopPropagation(),n.preventDefault(),!1}function k(n){if(!(n.ctrlKey||n.metaKey||n.altKey||n.shiftKey||n.button)){var t=n.target;do{if("a"===t.localName&&t.getAttribute("href")){if(t.hasAttribute("data-native")||t.hasAttribute("native"))return;if(U(t))return g(n)}}while(t=t.parentNode)}}var C=!1;function R(n){n.history&&(v=n.history),this.state={url:n.url||p()}}i(R.prototype=new n.Component,{shouldComponentUpdate:function(n){return!0!==n.static||n.url!==this.props.url||n.onChange!==this.props.onChange},canRoute:function(t){var r=n.toChildArray(this.props.children);return void 0!==this.g(r,t)},routeTo:function(n){this.setState({url:n});var t=this.canRoute(n);return this.p||this.forceUpdate(),t},componentWillMount:function(){this.p=!0},componentDidMount:function(){var n=this;C||(C=!0,v||addEventListener("popstate",function(){y(p())}),addEventListener("click",k)),h.push(this),v&&(this.u=v.listen(function(t){var r=t.location||t;n.routeTo(""+(r.pathname||"")+(r.search||""))})),this.p=!1},componentWillUnmount:function(){"function"==typeof this.u&&this.u(),h.splice(h.indexOf(this),1)},componentWillUpdate:function(){this.p=!0},componentDidUpdate:function(){this.p=!1},g:function(n,t){n=n.filter(u).sort(o);for(var r=0;r<n.length;r++){var i=n[r],f=e(t,i.props.path,i.props);if(f)return[i,f]}},render:function(t,r){var e,o,u=t.onChange,f=r.url,c=this.c,a=this.g(n.toChildArray(t.children),f);if(a&&(o=n.cloneElement(a[0],i(i({url:f,matches:e=a[1]},e),{key:void 0,ref:void 0}))),f!==(c&&c.url)){i(d,c=this.c={url:f,previous:c&&c.url,current:o,path:o?o.props.path:null,matches:e}),c.router=this,c.active=o?[o]:[];for(var h=s.length;h--;)s[h]({});"function"==typeof u&&u(c)}return n.h(l.Provider,{value:c},o)}}),R.getCurrentUrl=p,R.route=m,R.Router=R,R.Route=function(t){return n.h(t.component,t)},R.Link=function(t){return n.h("a",i({onClick:k},t))},R.exec=e,R.useRouter=function(){var n=t.useContext(l);if(n===d){var r=t.useState()[1];t.useEffect(function(){return s.push(r),function(){return s.splice(s.indexOf(r),1)}},[])}return[n,m]},module.exports=R; | ||
//# sourceMappingURL=preact-router.js.map |
@@ -1,2 +0,2 @@ | ||
import{createContext as t,toChildArray as n,cloneElement as e,h as r,createElement as o,Component as i}from"preact";import{useContext as a}from"preact/hooks";function u(t,n){return u=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t},u(t,n)}var c={};function p(t,n){for(var e in n)t[e]=n[e];return t}function s(t,n,e){var r,o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),a={};if(i&&i[1])for(var u=i[1].split("&"),p=0;p<u.length;p++){var s=u[p].split("=");a[decodeURIComponent(s[0])]=decodeURIComponent(s.slice(1).join("="))}t=h(t.replace(o,"")),n=h(n||"");for(var f=Math.max(t.length,n.length),l=0;l<f;l++)if(n[l]&&":"===n[l].charAt(0)){var d=n[l].replace(/(^:|[+*?]+$)/g,""),v=(n[l].match(/[+*?]+$/)||c)[0]||"",g=~v.indexOf("+"),m=~v.indexOf("*"),y=t[l]||"";if(!y&&!m&&(v.indexOf("?")<0||g)){r=!1;break}if(a[d]=decodeURIComponent(y),g||m){a[d]=t.slice(l).map(decodeURIComponent).join("/");break}}else if(n[l]!==t[l]){r=!1;break}return(!0===e.default||!1!==r)&&a}function f(t,n){return t.rank<n.rank?1:t.rank>n.rank?-1:t.index-n.index}function l(t,n){return t.index=n,t.rank=function(t){return t.props.default?0:h(t.props.path).map(d).join("")}(t),t.props}function h(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")}function d(t){return":"==t.charAt(0)?1+"*+?".indexOf(t.charAt(t.length-1))||4:5}var v=t({}),g=null,m=[],y={};function C(){return[a(v),b]}function x(){var t;return""+((t=g&&g.location?g.location:g&&g.getCurrentLocation?g.getCurrentLocation():"undefined"!=typeof location?location:y).pathname||"")+(t.search||"")}function b(t,n){return void 0===n&&(n=!1),"string"!=typeof t&&t.url&&(n=t.replace,t=t.url),function(t){for(var n=m.length;n--;)if(m[n].canRoute(t))return!0;return!1}(t)&&function(t,n){void 0===n&&(n="push"),g&&g[n]?g[n](t):"undefined"!=typeof history&&history[n+"State"]&&history[n+"State"](null,null,t)}(t,n?"replace":"push"),k(t)}function k(t){for(var n=!1,e=0;e<m.length;e++)!0===m[e].routeTo(t)&&(n=!0);return n}function U(t){if(t&&t.getAttribute){var n=t.getAttribute("href"),e=t.getAttribute("target");if(n&&n.match(/^\//g)&&(!e||e.match(/^_?self$/i)))return b(n)}}function A(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button))return U(t.currentTarget||t.target||this),K(t)}function K(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function O(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button)){var n=t.target;do{if("A"===String(n.nodeName).toUpperCase()&&n.getAttribute("href")){if(n.hasAttribute("data-native")||n.hasAttribute("native"))return;if(U(n))return K(t)}}while(n=n.parentNode)}}var R=!1,I=/*#__PURE__*/function(t){var o,i;function a(n){var e;return e=t.call(this,n)||this,n.history&&(g=n.history),e.state={url:n.url||x()},e.contextValue={},R||("function"==typeof addEventListener&&(g||addEventListener("popstate",function(){k(x())}),addEventListener("click",O)),R=!0),e}i=t,(o=a).prototype=Object.create(i.prototype),o.prototype.constructor=o,u(o,i);var c=a.prototype;return c.shouldComponentUpdate=function(t){return!0!==t.static||t.url!==this.props.url||t.onChange!==this.props.onChange},c.canRoute=function(t){var e=n(this.props.children);return this.getMatchingChildren(e,t,!1).length>0},c.routeTo=function(t){this.setState({url:t});var n=this.canRoute(t);return this.updating||this.forceUpdate(),n},c.componentWillMount=function(){this.updating=!0},c.componentDidMount=function(){var t=this;m.push(this),g&&(this.unlisten=g.listen(function(n){var e=n.location||n;t.routeTo(""+(e.pathname||"")+(e.search||""))})),this.updating=!1},c.componentWillUnmount=function(){"function"==typeof this.unlisten&&this.unlisten(),m.splice(m.indexOf(this),1)},c.componentWillUpdate=function(){this.updating=!0},c.componentDidUpdate=function(){this.updating=!1},c.getMatchingChildren=function(t,n,r){return t.filter(l).sort(f).map(function(t){var o=s(n,t.props.path,t.props);if(o){if(!1!==r){var i={url:n,matches:o};return p(i,o),delete i.ref,delete i.key,{vnode:e(t,i),matches:o}}return{vnode:t,matches:o}}}).filter(Boolean)},c.render=function(t,e){var o=t.onChange,i=e.url,a=this.getMatchingChildren(n(t.children),i,!0),u=a[0]||{vnode:null,matches:null},c=u.vnode,p=u.matches,s=this.previousUrl;return i!==s&&(this.previousUrl=i,this.contextValue={router:this,url:i,previous:s,active:a.map(function(t){return t.vnode}),current:c,path:c?c.props.path:null,matches:p},"function"==typeof o&&o(this.contextValue)),r(v.Provider,{value:this.contextValue},c)},a}(i),M=function(t){return o("a",p({onClick:A},t))},P=function(t){return o(t.component,t)};export{M as Link,P as Route,I as Router,I as default,s as exec,x as getCurrentUrl,b as route,C as useRouter}; | ||
import{createContext as n,Component as t,toChildArray as r,cloneElement as i,h as o}from"preact";import{useContext as e,useState as u,useEffect as f}from"preact/hooks";var a={};function c(n,t){for(var r in t)n[r]=t[r];return n}function s(n,t,r){var i,o=/(?:\?([^#]*))?(#.*)?$/,e=n.match(o),u={};if(e&&e[1])for(var f=e[1].split("&"),c=0;c<f.length;c++){var s=f[c].split("=");u[decodeURIComponent(s[0])]=decodeURIComponent(s.slice(1).join("="))}n=d(n.replace(o,"")),t=d(t||"");for(var h=Math.max(n.length,t.length),v=0;v<h;v++)if(t[v]&&":"===t[v].charAt(0)){var l=t[v].replace(/(^:|[+*?]+$)/g,""),p=(t[v].match(/[+*?]+$/)||a)[0]||"",m=~p.indexOf("+"),y=~p.indexOf("*"),U=n[v]||"";if(!U&&!y&&(p.indexOf("?")<0||m)){i=!1;break}if(u[l]=decodeURIComponent(U),m||y){u[l]=n.slice(v).map(decodeURIComponent).join("/");break}}else if(t[v]!==n[v]){i=!1;break}return(!0===r.default||!1!==i)&&u}function h(n,t){return n.rank<t.rank?1:n.rank>t.rank?-1:n.index-t.index}function v(n,t){return n.index=t,n.rank=function(n){return n.props.default?0:d(n.props.path).map(l).join("")}(n),n.props}function d(n){return n.replace(/(^\/+|\/+$)/g,"").split("/")}function l(n){return":"==n.charAt(0)?1+"*+?".indexOf(n.charAt(n.length-1))||4:5}var p={},m=[],y=[],U=null,g={url:R()},k=n(g);function C(){var n=e(k);if(n===g){var t=u()[1];f(function(){return y.push(t),function(){return y.splice(y.indexOf(t),1)}},[])}return[n,$]}function R(){var n;return""+((n=U&&U.location?U.location:U&&U.getCurrentLocation?U.getCurrentLocation():"undefined"!=typeof location?location:p).pathname||"")+(n.search||"")}function $(n,t){return void 0===t&&(t=!1),"string"!=typeof n&&n.url&&(t=n.replace,n=n.url),function(n){for(var t=m.length;t--;)if(m[t].canRoute(n))return!0;return!1}(n)&&function(n,t){void 0===t&&(t="push"),U&&U[t]?U[t](n):"undefined"!=typeof history&&history[t+"State"]&&history[t+"State"](null,null,n)}(n,t?"replace":"push"),I(n)}function I(n){for(var t=!1,r=0;r<m.length;r++)m[r].routeTo(n)&&(t=!0);return t}function M(n){if(n&&n.getAttribute){var t=n.getAttribute("href"),r=n.getAttribute("target");if(t&&t.match(/^\//g)&&(!r||r.match(/^_?self$/i)))return $(t)}}function b(n){return n.stopImmediatePropagation&&n.stopImmediatePropagation(),n.stopPropagation&&n.stopPropagation(),n.preventDefault(),!1}function W(n){if(!(n.ctrlKey||n.metaKey||n.altKey||n.shiftKey||n.button)){var t=n.target;do{if("a"===t.localName&&t.getAttribute("href")){if(t.hasAttribute("data-native")||t.hasAttribute("native"))return;if(M(t))return b(n)}}while(t=t.parentNode)}}var w=!1;function D(n){n.history&&(U=n.history),this.state={url:n.url||R()}}c(D.prototype=new t,{shouldComponentUpdate:function(n){return!0!==n.static||n.url!==this.props.url||n.onChange!==this.props.onChange},canRoute:function(n){var t=r(this.props.children);return void 0!==this.g(t,n)},routeTo:function(n){this.setState({url:n});var t=this.canRoute(n);return this.p||this.forceUpdate(),t},componentWillMount:function(){this.p=!0},componentDidMount:function(){var n=this;w||(w=!0,U||addEventListener("popstate",function(){I(R())}),addEventListener("click",W)),m.push(this),U&&(this.u=U.listen(function(t){var r=t.location||t;n.routeTo(""+(r.pathname||"")+(r.search||""))})),this.p=!1},componentWillUnmount:function(){"function"==typeof this.u&&this.u(),m.splice(m.indexOf(this),1)},componentWillUpdate:function(){this.p=!0},componentDidUpdate:function(){this.p=!1},g:function(n,t){n=n.filter(v).sort(h);for(var r=0;r<n.length;r++){var i=n[r],o=s(t,i.props.path,i.props);if(o)return[i,o]}},render:function(n,t){var e,u,f=n.onChange,a=t.url,s=this.c,h=this.g(r(n.children),a);if(h&&(u=i(h[0],c(c({url:a,matches:e=h[1]},e),{key:void 0,ref:void 0}))),a!==(s&&s.url)){c(g,s=this.c={url:a,previous:s&&s.url,current:u,path:u?u.props.path:null,matches:e}),s.router=this,s.active=u?[u]:[];for(var v=y.length;v--;)y[v]({});"function"==typeof f&&f(s)}return o(k.Provider,{value:s},u)}});var E=function(n){return o("a",c({onClick:W},n))},L=function(n){return o(n.component,n)};export{E as Link,L as Route,D as Router,D as default,s as exec,R as getCurrentUrl,$ as route,C as useRouter}; | ||
//# sourceMappingURL=preact-router.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact"),require("preact/hooks")):"function"==typeof define&&define.amd?define(["preact","preact/hooks"],e):(t||self).preactRouter=e(t.preact,t.hooks)}(this,function(t,e){function n(t,e){return n=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},n(t,e)}var r={};function o(t,e){for(var n in e)t[n]=e[n];return t}function i(t,e,n){var o,i=/(?:\?([^#]*))?(#.*)?$/,a=t.match(i),u={};if(a&&a[1])for(var p=a[1].split("&"),l=0;l<p.length;l++){var s=p[l].split("=");u[decodeURIComponent(s[0])]=decodeURIComponent(s.slice(1).join("="))}t=c(t.replace(i,"")),e=c(e||"");for(var f=Math.max(t.length,e.length),h=0;h<f;h++)if(e[h]&&":"===e[h].charAt(0)){var d=e[h].replace(/(^:|[+*?]+$)/g,""),g=(e[h].match(/[+*?]+$/)||r)[0]||"",m=~g.indexOf("+"),v=~g.indexOf("*"),y=t[h]||"";if(!y&&!v&&(g.indexOf("?")<0||m)){o=!1;break}if(u[d]=decodeURIComponent(y),m||v){u[d]=t.slice(h).map(decodeURIComponent).join("/");break}}else if(e[h]!==t[h]){o=!1;break}return(!0===n.default||!1!==o)&&u}function a(t,e){return t.rank<e.rank?1:t.rank>e.rank?-1:t.index-e.index}function u(t,e){return t.index=e,t.rank=function(t){return t.props.default?0:c(t.props.path).map(p).join("")}(t),t.props}function c(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")}function p(t){return":"==t.charAt(0)?1+"*+?".indexOf(t.charAt(t.length-1))||4:5}var l=t.createContext({}),s=null,f=[],h={};function d(){var t;return""+((t=s&&s.location?s.location:s&&s.getCurrentLocation?s.getCurrentLocation():"undefined"!=typeof location?location:h).pathname||"")+(t.search||"")}function g(t,e){return void 0===e&&(e=!1),"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),function(t){for(var e=f.length;e--;)if(f[e].canRoute(t))return!0;return!1}(t)&&function(t,e){void 0===e&&(e="push"),s&&s[e]?s[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}(t,e?"replace":"push"),m(t)}function m(t){for(var e=!1,n=0;n<f.length;n++)!0===f[n].routeTo(t)&&(e=!0);return e}function v(t){if(t&&t.getAttribute){var e=t.getAttribute("href"),n=t.getAttribute("target");if(e&&e.match(/^\//g)&&(!n||n.match(/^_?self$/i)))return g(e)}}function y(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button))return v(t.currentTarget||t.target||this),C(t)}function C(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function x(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button)){var e=t.target;do{if("A"===String(e.nodeName).toUpperCase()&&e.getAttribute("href")){if(e.hasAttribute("data-native")||e.hasAttribute("native"))return;if(v(e))return C(t)}}while(e=e.parentNode)}}var b=!1,k=/*#__PURE__*/function(e){var r,c;function p(t){var n;return n=e.call(this,t)||this,t.history&&(s=t.history),n.state={url:t.url||d()},n.contextValue={},b||("function"==typeof addEventListener&&(s||addEventListener("popstate",function(){m(d())}),addEventListener("click",x)),b=!0),n}c=e,(r=p).prototype=Object.create(c.prototype),r.prototype.constructor=r,n(r,c);var h=p.prototype;return h.shouldComponentUpdate=function(t){return!0!==t.static||t.url!==this.props.url||t.onChange!==this.props.onChange},h.canRoute=function(e){var n=t.toChildArray(this.props.children);return this.getMatchingChildren(n,e,!1).length>0},h.routeTo=function(t){this.setState({url:t});var e=this.canRoute(t);return this.updating||this.forceUpdate(),e},h.componentWillMount=function(){this.updating=!0},h.componentDidMount=function(){var t=this;f.push(this),s&&(this.unlisten=s.listen(function(e){var n=e.location||e;t.routeTo(""+(n.pathname||"")+(n.search||""))})),this.updating=!1},h.componentWillUnmount=function(){"function"==typeof this.unlisten&&this.unlisten(),f.splice(f.indexOf(this),1)},h.componentWillUpdate=function(){this.updating=!0},h.componentDidUpdate=function(){this.updating=!1},h.getMatchingChildren=function(e,n,r){return e.filter(u).sort(a).map(function(e){var a=i(n,e.props.path,e.props);if(a){if(!1!==r){var u={url:n,matches:a};return o(u,a),delete u.ref,delete u.key,{vnode:t.cloneElement(e,u),matches:a}}return{vnode:e,matches:a}}}).filter(Boolean)},h.render=function(e,n){var r=e.onChange,o=n.url,i=this.getMatchingChildren(t.toChildArray(e.children),o,!0),a=i[0]||{vnode:null,matches:null},u=a.vnode,c=a.matches,p=this.previousUrl;return o!==p&&(this.previousUrl=o,this.contextValue={router:this,url:o,previous:p,active:i.map(function(t){return t.vnode}),current:u,path:u?u.props.path:null,matches:c},"function"==typeof r&&r(this.contextValue)),t.h(l.Provider,{value:this.contextValue},u)},p}(t.Component);return k.getCurrentUrl=d,k.route=g,k.Router=k,k.Route=function(e){return t.createElement(e.component,e)},k.Link=function(e){return t.createElement("a",o({onClick:y},e))},k.exec=i,k.useRouter=function(){return[e.useContext(l),g]},k}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("preact"),require("preact/hooks")):"function"==typeof define&&define.amd?define(["preact","preact/hooks"],t):(n||self).preactRouter=t(n.preact,n.hooks)}(this,function(n,t){var e={};function r(n,t){for(var e in t)n[e]=t[e];return n}function i(n,t,r){var i,o=/(?:\?([^#]*))?(#.*)?$/,u=n.match(o),c={};if(u&&u[1])for(var a=u[1].split("&"),s=0;s<a.length;s++){var h=a[s].split("=");c[decodeURIComponent(h[0])]=decodeURIComponent(h.slice(1).join("="))}n=f(n.replace(o,"")),t=f(t||"");for(var d=Math.max(n.length,t.length),l=0;l<d;l++)if(t[l]&&":"===t[l].charAt(0)){var v=t[l].replace(/(^:|[+*?]+$)/g,""),p=(t[l].match(/[+*?]+$/)||e)[0]||"",m=~p.indexOf("+"),y=~p.indexOf("*"),g=n[l]||"";if(!g&&!y&&(p.indexOf("?")<0||m)){i=!1;break}if(c[v]=decodeURIComponent(g),m||y){c[v]=n.slice(l).map(decodeURIComponent).join("/");break}}else if(t[l]!==n[l]){i=!1;break}return(!0===r.default||!1!==i)&&c}function o(n,t){return n.rank<t.rank?1:n.rank>t.rank?-1:n.index-t.index}function u(n,t){return n.index=t,n.rank=function(n){return n.props.default?0:f(n.props.path).map(c).join("")}(n),n.props}function f(n){return n.replace(/(^\/+|\/+$)/g,"").split("/")}function c(n){return":"==n.charAt(0)?1+"*+?".indexOf(n.charAt(n.length-1))||4:5}var a={},s=[],h=[],d=null,l={url:p()},v=n.createContext(l);function p(){var n;return""+((n=d&&d.location?d.location:d&&d.getCurrentLocation?d.getCurrentLocation():"undefined"!=typeof location?location:a).pathname||"")+(n.search||"")}function m(n,t){return void 0===t&&(t=!1),"string"!=typeof n&&n.url&&(t=n.replace,n=n.url),function(n){for(var t=s.length;t--;)if(s[t].canRoute(n))return!0;return!1}(n)&&function(n,t){void 0===t&&(t="push"),d&&d[t]?d[t](n):"undefined"!=typeof history&&history[t+"State"]&&history[t+"State"](null,null,n)}(n,t?"replace":"push"),y(n)}function y(n){for(var t=!1,e=0;e<s.length;e++)s[e].routeTo(n)&&(t=!0);return t}function g(n){if(n&&n.getAttribute){var t=n.getAttribute("href"),e=n.getAttribute("target");if(t&&t.match(/^\//g)&&(!e||e.match(/^_?self$/i)))return m(t)}}function k(n){return n.stopImmediatePropagation&&n.stopImmediatePropagation(),n.stopPropagation&&n.stopPropagation(),n.preventDefault(),!1}function U(n){if(!(n.ctrlKey||n.metaKey||n.altKey||n.shiftKey||n.button)){var t=n.target;do{if("a"===t.localName&&t.getAttribute("href")){if(t.hasAttribute("data-native")||t.hasAttribute("native"))return;if(g(t))return k(n)}}while(t=t.parentNode)}}var C=!1;function b(n){n.history&&(d=n.history),this.state={url:n.url||p()}}return r(b.prototype=new n.Component,{shouldComponentUpdate:function(n){return!0!==n.static||n.url!==this.props.url||n.onChange!==this.props.onChange},canRoute:function(t){var e=n.toChildArray(this.props.children);return void 0!==this.g(e,t)},routeTo:function(n){this.setState({url:n});var t=this.canRoute(n);return this.p||this.forceUpdate(),t},componentWillMount:function(){this.p=!0},componentDidMount:function(){var n=this;C||(C=!0,d||addEventListener("popstate",function(){y(p())}),addEventListener("click",U)),s.push(this),d&&(this.u=d.listen(function(t){var e=t.location||t;n.routeTo(""+(e.pathname||"")+(e.search||""))})),this.p=!1},componentWillUnmount:function(){"function"==typeof this.u&&this.u(),s.splice(s.indexOf(this),1)},componentWillUpdate:function(){this.p=!0},componentDidUpdate:function(){this.p=!1},g:function(n,t){n=n.filter(u).sort(o);for(var e=0;e<n.length;e++){var r=n[e],f=i(t,r.props.path,r.props);if(f)return[r,f]}},render:function(t,e){var i,o,u=t.onChange,f=e.url,c=this.c,a=this.g(n.toChildArray(t.children),f);if(a&&(o=n.cloneElement(a[0],r(r({url:f,matches:i=a[1]},i),{key:void 0,ref:void 0}))),f!==(c&&c.url)){r(l,c=this.c={url:f,previous:c&&c.url,current:o,path:o?o.props.path:null,matches:i}),c.router=this,c.active=o?[o]:[];for(var s=h.length;s--;)h[s]({});"function"==typeof u&&u(c)}return n.h(v.Provider,{value:c},o)}}),b.getCurrentUrl=p,b.route=m,b.Router=b,b.Route=function(t){return n.h(t.component,t)},b.Link=function(t){return n.h("a",r({onClick:U},t))},b.exec=i,b.useRouter=function(){var n=t.useContext(v);if(n===l){var e=t.useState()[1];t.useEffect(function(){return h.push(e),function(){return h.splice(h.indexOf(e),1)}},[])}return[n,m]},b}); | ||
//# sourceMappingURL=preact-router.umd.js.map |
@@ -1,1 +0,1 @@ | ||
var e=require("preact"),r=require("preact-router");function a(){return a=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var a=arguments[r];for(var t in a)Object.prototype.hasOwnProperty.call(a,t)&&(e[t]=a[t])}return e},a.apply(this,arguments)}var t=["class","className","activeClass","activeClassName","path"];function n(e){var a=r.useRouter()[0],t=a.url,n=a.path;return e.children({url:t,path:n,matches:!!t&&!!n&&!1!==r.exec(n,e.path,{})})}n.Link=function(n){var s=n.class,c=n.className,l=n.activeClass,i=n.activeClassName,o=n.path,u=function(e,r){if(null==e)return{};var a,t,n={},s=Object.keys(e);for(t=0;t<s.length;t++)r.indexOf(a=s[t])>=0||(n[a]=e[a]);return n}(n,t),h=[s,c].filter(Boolean).join(" "),p=[s,c,l,i].filter(Boolean).join(" "),f=r.useRouter()[0].path||u.href,v=!!f&&!1!==r.exec(f,o,{});return e.h(r.Link,a({},u,{class:v?p:h}))},module.exports=n; | ||
var e=require("preact"),a=require("preact-router"),r=["className","activeClass","activeClassName","path"];function t(e){var r=a.useRouter()[0];return e.children({url:r.url,path:r.path,matches:!1!==a.exec(r.path||r.url,e.path,{})})}t.Link=function(t){var s=t.className,u=t.activeClass,c=t.activeClassName,l=t.path,n=function(e,a){if(null==e)return{};var r,t,s={},u=Object.keys(e);for(t=0;t<u.length;t++)a.indexOf(r=u[t])>=0||(s[r]=e[r]);return s}(t,r),i=a.useRouter()[0],h=l&&i.path&&a.exec(i.path,l,{})||a.exec(i.url,n.href,{}),p=n.class||s||"",o=h&&(u||c)||"";return n.class=p+(p&&o&&" ")+o,e.h(a.Link,n)},module.exports=t; |
@@ -1,1 +0,1 @@ | ||
import{h as a}from"preact";import{useRouter as r,exec as t,Link as e}from"preact-router";function n(){return n=Object.assign||function(a){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(a[e]=t[e])}return a},n.apply(this,arguments)}var s=["class","className","activeClass","activeClassName","path"];function l(a){var e=r()[0],n=e.url,s=e.path;return a.children({url:n,path:s,matches:!!n&&!!s&&!1!==t(s,a.path,{})})}function o(l){var o=l.class,c=l.className,i=l.activeClass,f=l.activeClassName,p=l.path,u=function(a,r){if(null==a)return{};var t,e,n={},s=Object.keys(a);for(e=0;e<s.length;e++)r.indexOf(t=s[e])>=0||(n[t]=a[t]);return n}(l,s),h=[o,c].filter(Boolean).join(" "),v=[o,c,i,f].filter(Boolean).join(" "),m=r()[0].path||u.href,j=!!m&&!1!==t(m,p,{});return a(e,n({},u,{class:j?v:h}))}export{o as Link,l as Match,l as default}; | ||
import{h as a}from"preact";import{useRouter as t,exec as r,Link as e}from"preact-router";var s=["className","activeClass","activeClassName","path"];function l(a){var e=t()[0];return a.children({url:e.url,path:e.path,matches:!1!==r(e.path||e.url,a.path,{})})}function c(l){var c=l.className,n=l.activeClass,u=l.activeClassName,i=l.path,p=function(a,t){if(null==a)return{};var r,e,s={},l=Object.keys(a);for(e=0;e<l.length;e++)t.indexOf(r=l[e])>=0||(s[r]=a[r]);return s}(l,s),h=t()[0],f=i&&h.path&&r(h.path,i,{})||r(h.url,p.href,{}),o=p.class||c||"",m=f&&(n||u)||"";return p.class=o+(o&&m&&" ")+m,a(e,p)}export{c as Link,l as Match,l as default}; |
@@ -5,7 +5,7 @@ import { h } from 'preact'; | ||
export function Match(props) { | ||
const [{ url, path }] = useRouter(); | ||
const router = useRouter()[0]; | ||
return props.children({ | ||
url, | ||
path, | ||
matches: !!url && !!path && exec(path, props.path, {}) !== false | ||
url: router.url, | ||
path: router.path, | ||
matches: exec(router.path || router.url, props.path, {}) !== false | ||
}); | ||
@@ -15,19 +15,20 @@ } | ||
export function Link({ | ||
class: c, | ||
className, | ||
activeClass, | ||
activeClassName, | ||
path: linkPath, | ||
path, | ||
...props | ||
}) { | ||
const inactive = [c, className].filter(Boolean).join(' '); | ||
const active = [c, className, activeClass, activeClassName] | ||
.filter(Boolean) | ||
.join(' '); | ||
const path = useRouter()[0].path || props.href; | ||
const matches = !!path && exec(path, linkPath, {}) !== false; | ||
const router = useRouter()[0]; | ||
const matches = | ||
(path && router.path && exec(router.path, path, {})) || | ||
exec(router.url, props.href, {}); | ||
return <StaticLink {...props} class={matches ? active : inactive} />; | ||
let inactive = props.class || className || ''; | ||
let active = (matches && (activeClass || activeClassName)) || ''; | ||
props.class = inactive + (inactive && active && ' ') + active; | ||
return <StaticLink {...props} />; | ||
} | ||
export default Match; |
{ | ||
"name": "preact-router", | ||
"amdName": "preactRouter", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -6,0 +6,0 @@ "main": "dist/preact-router.js", |
@@ -139,3 +139,3 @@ # preact-router | ||
This can be accomplished by adding a `dataset-native` boolean attribute to any link: | ||
This can be accomplished by adding a `data-native` boolean attribute to any link: | ||
@@ -142,0 +142,0 @@ ```html |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
77805
180