preact-router
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -260,10 +260,10 @@ import { Component, cloneElement, createElement, toChildArray } from 'preact'; | ||
Router.prototype.routeTo = function routeTo (url) { | ||
this._didRoute = false; | ||
this.setState({ url: url }); | ||
// if we're in the middle of an update, don't synchronously re-route. | ||
if (this.updating) { return this.canRoute(url); } | ||
var didRoute = this.canRoute(url); | ||
this.forceUpdate(); | ||
return this._didRoute; | ||
// trigger a manual re-route if we're not in the middle of an update: | ||
if (!this.updating) { this.forceUpdate(); } | ||
return didRoute; | ||
}; | ||
@@ -327,3 +327,2 @@ | ||
var current = active[0] || null; | ||
this._didRoute = !!current; | ||
@@ -363,3 +362,3 @@ var previous = this.previousUrl; | ||
export { subscribers, getCurrentUrl, route, Router, Route, Link };export default Router; | ||
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 s=Math.max(t.length,e.length),l=0;l<s;l++)if(e[l]&&":"===e[l].charAt(0)){var h=e[l].replace(/(^:|[+*?]+$)/g,""),d=(e[l].match(/[+*?]+$/)||C)[0]||"",g=~d.indexOf("+"),m=~d.indexOf("*"),y=t[l]||"";if(!y&&!m&&(d.indexOf("?")<0||g)){r=!1;break}if(a[h]=decodeURIComponent(y),g||m){a[h]=t.slice(l).map(decodeURIComponent).join("/");break}}else if(e[l]!==t[l]){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:k,""+(t.pathname||"")+(t.search||"")}function s(t,e){return void 0===e&&(e=!1),"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),l(t)&&c(t,e?"replace":"push"),h(t)}function l(t){for(var e=R.length;e--;)if(R[e].canRoute(t))return!0;return!1}function h(t){for(var e=!1,n=0;n<R.length;n++)!0===R[n].routeTo(t)&&(e=!0);for(var r=U.length;r--;)U[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 s(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(){x||("function"==typeof addEventListener&&(b||addEventListener("popstate",function(){h(f())}),addEventListener("click",y)),x=!0)}var C={},b=null,R=[],U=[],k={},x=!1,A=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){return this._didRoute=!1,this.setState({url:t}),this.updating?this.canRoute(t):(this.forceUpdate(),this._didRoute)},u.prototype.componentWillMount=function(){R.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(),R.splice(R.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;this._didRoute=!!a;var 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),_=function(n){return t.createElement("a",e({onClick:g},n))},E=function(e){return t.createElement(e.component,e)};return A.subscribers=U,A.getCurrentUrl=f,A.route=s,A.Router=A,A.Route=E,A.Link=_,A}); | ||
!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}); | ||
//# sourceMappingURL=preact-router.js.map |
@@ -55,3 +55,3 @@ 'use strict'; | ||
path: path, | ||
matches: path === props.path | ||
matches: (0, _preactRouter.exec)(path, props.path, {}) !== false | ||
}); | ||
@@ -58,0 +58,0 @@ }; |
{ | ||
"name": "preact-router", | ||
"amdName": "preactRouter", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -48,3 +48,3 @@ "main": "dist/preact-router.js", | ||
"peerDependencies": { | ||
"preact": ">=10 || ^10.0.0-beta.0" | ||
"preact": ">=10 || ^10.0.0-rc.0" | ||
}, | ||
@@ -79,3 +79,3 @@ "devDependencies": { | ||
"npm-run-all": "^3.0.0", | ||
"preact": "^10.0.0-beta.0", | ||
"preact": "^10.0.0-rc.0", | ||
"pretty-bytes-cli": "^1.0.0", | ||
@@ -82,0 +82,0 @@ "puppeteer": "^1.9.0", |
@@ -123,3 +123,4 @@ # preact-router | ||
```js | ||
import { Router, Link } from 'preact-router'; | ||
import { Router } from 'preact-router'; | ||
import { Link } from 'preact-router/match'; | ||
@@ -126,0 +127,0 @@ render( |
@@ -171,10 +171,10 @@ import { cloneElement, createElement, Component, toChildArray } from 'preact'; | ||
routeTo(url) { | ||
this._didRoute = false; | ||
this.setState({ url }); | ||
// if we're in the middle of an update, don't synchronously re-route. | ||
if (this.updating) return this.canRoute(url); | ||
const didRoute = this.canRoute(url); | ||
this.forceUpdate(); | ||
return this._didRoute; | ||
// trigger a manual re-route if we're not in the middle of an update: | ||
if (!this.updating) this.forceUpdate(); | ||
return didRoute; | ||
} | ||
@@ -232,3 +232,2 @@ | ||
let current = active[0] || null; | ||
this._didRoute = !!current; | ||
@@ -266,3 +265,3 @@ let previous = this.previousUrl; | ||
export { subscribers, getCurrentUrl, route, Router, Route, Link }; | ||
export { subscribers, getCurrentUrl, route, Router, Route, Link, exec }; | ||
export default Router; |
import { h, Component } from 'preact'; | ||
import { subscribers, getCurrentUrl, Link as StaticLink } from 'preact-router'; | ||
import { subscribers, getCurrentUrl, Link as StaticLink, exec } from 'preact-router'; | ||
@@ -22,3 +22,3 @@ export class Match extends Component { | ||
path, | ||
matches: path===props.path | ||
matches: exec(path, props.path, {}) !== false | ||
}); | ||
@@ -25,0 +25,0 @@ } |
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
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
17430
255
0
74033
817