preact-router
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -178,6 +178,5 @@ import { Component, cloneElement, createElement, toChildArray } from 'preact'; | ||
function handleLinkClick(e) { | ||
if (e.button==0) { | ||
routeFromLink(e.currentTarget || e.target || this); | ||
return prevent(e); | ||
} | ||
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button!==0) { return; } | ||
routeFromLink(e.currentTarget || e.target || this); | ||
return prevent(e); | ||
} | ||
@@ -360,4 +359,5 @@ | ||
Router.Link = Link; | ||
Router.exec = exec; | ||
export { subscribers, getCurrentUrl, route, Router, Route, Link, exec };export default Router; | ||
//# sourceMappingURL=preact-router.es.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactRouter=e(t.preact)}(this,function(t){function e(t,e){for(var n in e)t[n]=e[n];return t}function n(t,e,n){var r,o=/(?:\?([^#]*))?(#.*)?$/,u=t.match(o),a={};if(u&&u[1])for(var p=u[1].split("&"),c=0;c<p.length;c++){var f=p[c].split("=");a[decodeURIComponent(f[0])]=decodeURIComponent(f.slice(1).join("="))}t=i(t.replace(o,"")),e=i(e||"");for(var l=Math.max(t.length,e.length),s=0;s<l;s++)if(e[s]&&":"===e[s].charAt(0)){var h=e[s].replace(/(^:|[+*?]+$)/g,""),d=(e[s].match(/[+*?]+$/)||C)[0]||"",g=~d.indexOf("+"),m=~d.indexOf("*"),y=t[s]||"";if(!y&&!m&&(d.indexOf("?")<0||g)){r=!1;break}if(a[h]=decodeURIComponent(y),g||m){a[h]=t.slice(s).map(decodeURIComponent).join("/");break}}else if(e[s]!==t[s]){r=!1;break}return(!0===n.default||!1!==r)&&a}function r(t,e){return t.rank<e.rank?1:t.rank>e.rank?-1:t.index-e.index}function o(t,e){return t.index=e,t.rank=p(t),t.props}function i(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")}function u(t){return":"==t.charAt(0)?1+"*+?".indexOf(t.charAt(t.length-1))||4:5}function a(t){return i(t).map(u).join("")}function p(t){return t.props.default?0:a(t.props.path)}function c(t,e){void 0===e&&(e="push"),b&&b[e]?b[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}function f(){var t;return t=b&&b.location?b.location:b&&b.getCurrentLocation?b.getCurrentLocation():"undefined"!=typeof location?location:x,""+(t.pathname||"")+(t.search||"")}function l(t,e){return void 0===e&&(e=!1),"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),s(t)&&c(t,e?"replace":"push"),h(t)}function s(t){for(var e=U.length;e--;)if(U[e].canRoute(t))return!0;return!1}function h(t){for(var e=!1,n=0;n<U.length;n++)!0===U[n].routeTo(t)&&(e=!0);for(var r=k.length;r--;)k[r](t);return e}function d(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 l(e)}}function g(t){if(0==t.button)return d(t.currentTarget||t.target||this),m(t)}function m(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function y(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button)){var e=t.target;do{if("A"===(e.nodeName+"").toUpperCase()&&e.getAttribute("href")){if(e.hasAttribute("native"))return;if(d(e))return m(t)}}while(e=e.parentNode)}}function v(){A||("function"==typeof addEventListener&&(b||addEventListener("popstate",function(){h(f())}),addEventListener("click",y)),A=!0)}var C={},b=null,U=[],k=[],x={},A=!1,R=function(i){function u(t){i.call(this,t),t.history&&(b=t.history),this.state={url:t.url||f()},v()}return i&&(u.__proto__=i),u.prototype=Object.create(i&&i.prototype),u.prototype.constructor=u,u.prototype.shouldComponentUpdate=function(t){return!0!==t.static||(t.url!==this.props.url||t.onChange!==this.props.onChange)},u.prototype.canRoute=function(e){return this.getMatchingChildren(t.toChildArray(this.props.children),e,!1).length>0},u.prototype.routeTo=function(t){this.setState({url:t});var e=this.canRoute(t);return this.updating||this.forceUpdate(),e},u.prototype.componentWillMount=function(){U.push(this),this.updating=!0},u.prototype.componentDidMount=function(){var t=this;b&&(this.unlisten=b.listen(function(e){t.routeTo(""+(e.pathname||"")+(e.search||""))})),this.updating=!1},u.prototype.componentWillUnmount=function(){"function"==typeof this.unlisten&&this.unlisten(),U.splice(U.indexOf(this),1)},u.prototype.componentWillUpdate=function(){this.updating=!0},u.prototype.componentDidUpdate=function(){this.updating=!1},u.prototype.getMatchingChildren=function(i,u,a){return i.filter(o).sort(r).map(function(r){var o=n(u,r.props.path,r.props);if(o){if(!1!==a){var i={url:u,matches:o};return e(i,o),delete i.ref,delete i.key,t.cloneElement(r,i)}return r}}).filter(Boolean)},u.prototype.render=function(e,n){var r=e.children,o=e.onChange,i=n.url,u=this.getMatchingChildren(t.toChildArray(r),i,!0),a=u[0]||null,p=this.previousUrl;return i!==p&&(this.previousUrl=i,"function"==typeof o&&o({router:this,url:i,previous:p,active:u,current:a})),a},u}(t.Component),E=function(n){return t.createElement("a",e({onClick:g},n))},I=function(e){return t.createElement(e.component,e)};return R.subscribers=k,R.getCurrentUrl=f,R.route=l,R.Router=R,R.Route=I,R.Link=E,R}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact")):"function"==typeof define&&define.amd?define(["preact"],e):t.preactRouter=e(t.preact)}(this,function(t){function e(t,e){for(var n in e)t[n]=e[n];return t}function n(t,e,n){var r,o=/(?:\?([^#]*))?(#.*)?$/,u=t.match(o),a={};if(u&&u[1])for(var p=u[1].split("&"),c=0;c<p.length;c++){var f=p[c].split("=");a[decodeURIComponent(f[0])]=decodeURIComponent(f.slice(1).join("="))}t=i(t.replace(o,"")),e=i(e||"");for(var l=Math.max(t.length,e.length),s=0;s<l;s++)if(e[s]&&":"===e[s].charAt(0)){var h=e[s].replace(/(^:|[+*?]+$)/g,""),d=(e[s].match(/[+*?]+$/)||C)[0]||"",g=~d.indexOf("+"),y=~d.indexOf("*"),m=t[s]||"";if(!m&&!y&&(d.indexOf("?")<0||g)){r=!1;break}if(a[h]=decodeURIComponent(m),g||y){a[h]=t.slice(s).map(decodeURIComponent).join("/");break}}else if(e[s]!==t[s]){r=!1;break}return(!0===n.default||!1!==r)&&a}function r(t,e){return t.rank<e.rank?1:t.rank>e.rank?-1:t.index-e.index}function o(t,e){return t.index=e,t.rank=p(t),t.props}function i(t){return t.replace(/(^\/+|\/+$)/g,"").split("/")}function u(t){return":"==t.charAt(0)?1+"*+?".indexOf(t.charAt(t.length-1))||4:5}function a(t){return i(t).map(u).join("")}function p(t){return t.props.default?0:a(t.props.path)}function c(t,e){void 0===e&&(e="push"),b&&b[e]?b[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}function f(){var t;return t=b&&b.location?b.location:b&&b.getCurrentLocation?b.getCurrentLocation():"undefined"!=typeof location?location:x,""+(t.pathname||"")+(t.search||"")}function l(t,e){return void 0===e&&(e=!1),"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),s(t)&&c(t,e?"replace":"push"),h(t)}function s(t){for(var e=U.length;e--;)if(U[e].canRoute(t))return!0;return!1}function h(t){for(var e=!1,n=0;n<U.length;n++)!0===U[n].routeTo(t)&&(e=!0);for(var r=k.length;r--;)k[r](t);return e}function d(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 l(e)}}function g(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button))return d(t.currentTarget||t.target||this),y(t)}function y(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function m(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey||0!==t.button)){var e=t.target;do{if("A"===(e.nodeName+"").toUpperCase()&&e.getAttribute("href")){if(e.hasAttribute("native"))return;if(d(e))return y(t)}}while(e=e.parentNode)}}function v(){A||("function"==typeof addEventListener&&(b||addEventListener("popstate",function(){h(f())}),addEventListener("click",m)),A=!0)}var C={},b=null,U=[],k=[],x={},A=!1,R=function(i){function u(t){i.call(this,t),t.history&&(b=t.history),this.state={url:t.url||f()},v()}return i&&(u.__proto__=i),u.prototype=Object.create(i&&i.prototype),u.prototype.constructor=u,u.prototype.shouldComponentUpdate=function(t){return!0!==t.static||(t.url!==this.props.url||t.onChange!==this.props.onChange)},u.prototype.canRoute=function(e){return this.getMatchingChildren(t.toChildArray(this.props.children),e,!1).length>0},u.prototype.routeTo=function(t){this.setState({url:t});var e=this.canRoute(t);return this.updating||this.forceUpdate(),e},u.prototype.componentWillMount=function(){U.push(this),this.updating=!0},u.prototype.componentDidMount=function(){var t=this;b&&(this.unlisten=b.listen(function(e){t.routeTo(""+(e.pathname||"")+(e.search||""))})),this.updating=!1},u.prototype.componentWillUnmount=function(){"function"==typeof this.unlisten&&this.unlisten(),U.splice(U.indexOf(this),1)},u.prototype.componentWillUpdate=function(){this.updating=!0},u.prototype.componentDidUpdate=function(){this.updating=!1},u.prototype.getMatchingChildren=function(i,u,a){return i.filter(o).sort(r).map(function(r){var o=n(u,r.props.path,r.props);if(o){if(!1!==a){var i={url:u,matches:o};return e(i,o),delete i.ref,delete i.key,t.cloneElement(r,i)}return r}}).filter(Boolean)},u.prototype.render=function(e,n){var r=e.children,o=e.onChange,i=n.url,u=this.getMatchingChildren(t.toChildArray(r),i,!0),a=u[0]||null,p=this.previousUrl;return i!==p&&(this.previousUrl=i,"function"==typeof o&&o({router:this,url:i,previous:p,active:u,current:a})),a},u}(t.Component),K=function(n){return t.createElement("a",e({onClick:g},n))},E=function(e){return t.createElement(e.component,e)};return R.subscribers=k,R.getCurrentUrl=f,R.route=l,R.Router=R,R.Route=E,R.Link=K,R.exec=n,R}); | ||
//# sourceMappingURL=preact-router.js.map |
{ | ||
"name": "preact-router", | ||
"amdName": "preactRouter", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -22,3 +22,3 @@ "main": "dist/preact-router.js", | ||
"test:ts": "tsc -p ./test", | ||
"prepublish": "npm-run-all build test", | ||
"prepublishOnly": "npm-run-all build test", | ||
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish" | ||
@@ -78,2 +78,3 @@ }, | ||
"mocha": "^5.2.0", | ||
"npm-merge-driver-install": "^1.1.1", | ||
"npm-run-all": "^3.0.0", | ||
@@ -80,0 +81,0 @@ "preact": "^10.0.0-rc.0", |
@@ -93,6 +93,5 @@ import { cloneElement, createElement, Component, toChildArray } from 'preact'; | ||
function handleLinkClick(e) { | ||
if (e.button==0) { | ||
routeFromLink(e.currentTarget || e.target || this); | ||
return prevent(e); | ||
} | ||
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || e.button!==0) return; | ||
routeFromLink(e.currentTarget || e.target || this); | ||
return prevent(e); | ||
} | ||
@@ -263,4 +262,5 @@ | ||
Router.Link = Link; | ||
Router.exec = exec; | ||
export { subscribers, getCurrentUrl, route, Router, Route, Link, exec }; | ||
export default Router; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
74629
42
1