preact-router
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -80,4 +80,2 @@ (function (global, factory) { | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
var customHistory = null; | ||
@@ -205,12 +203,4 @@ | ||
var Link = function Link(_ref) { | ||
var children = _ref.children; | ||
var props = _objectWithoutProperties(_ref, ['children']); | ||
return preact.h( | ||
'a', | ||
_extends({}, props, { onClick: handleLinkClick }), | ||
children | ||
); | ||
var Link = function Link(props) { | ||
return preact.h('a', _extends({}, props, { onClick: handleLinkClick })); | ||
}; | ||
@@ -284,4 +274,4 @@ | ||
Router.prototype.getMatchingChildren = function getMatchingChildren(children, url, invoke) { | ||
return children.slice().sort(pathRankSort).filter(function (_ref2) { | ||
var attributes = _ref2.attributes; | ||
return children.slice().sort(pathRankSort).filter(function (_ref) { | ||
var attributes = _ref.attributes; | ||
@@ -306,6 +296,6 @@ var path = attributes.path, | ||
Router.prototype.render = function render(_ref3, _ref4) { | ||
var children = _ref3.children; | ||
var onChange = _ref3.onChange; | ||
var url = _ref4.url; | ||
Router.prototype.render = function render(_ref2, _ref3) { | ||
var children = _ref2.children, | ||
onChange = _ref2.onChange; | ||
var url = _ref3.url; | ||
@@ -337,7 +327,8 @@ var active = this.getMatchingChildren(children, url, true); | ||
var Route = function Route(_ref5) { | ||
var RoutedComponent = _ref5.component; | ||
var url = _ref5.url; | ||
var matches = _ref5.matches; | ||
return preact.h(RoutedComponent, { url: url, matches: matches }); | ||
var Route = function Route(_ref4) { | ||
var component = _ref4.component, | ||
url = _ref4.url, | ||
matches = _ref4.matches; | ||
return preact.h(component, { url: url, matches: matches }); | ||
}; | ||
@@ -344,0 +335,0 @@ |
@@ -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){"use strict";function e(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:C,o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),u={},a=void 0;if(i&&i[1])for(var c=i[1].split("&"),p=0;p<c.length;p++){var f=c[p].split("=");u[decodeURIComponent(f[0])]=decodeURIComponent(f.slice(1).join("="))}t=r(t.replace(o,"")),e=r(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("*"),v=t[s]||"";if(!v&&!y&&(d.indexOf("?")<0||g)){a=!1;break}if(u[h]=decodeURIComponent(v),g||y){u[h]=t.slice(s).map(decodeURIComponent).join("/");break}}else if(e[s]!==t[s]){a=!1;break}return(n.default===!0||a!==!1)&&u}function n(t,e){var n=t.attributes||C,r=e.attributes||C;if(n.default)return 1;if(r.default)return-1;var i=o(n.path)-o(r.path);return i||n.path.length-r.path.length}function r(t){return i(t).split("/")}function o(t){return(i(t).match(/\/+/g)||"").length}function i(t){return t.replace(/(^\/+|\/+$)/g,"")}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function p(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}function f(t){return _ in t}function l(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"push";R&&R[e]?R[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}function s(){var t=void 0;return t=R&&R.location?R.location:R&&R.getCurrentLocation?R.getCurrentLocation():"undefined"!=typeof location?location:w,""+(t.pathname||"")+(t.search||"")}function h(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),d(t)&&l(t,e?"replace":"push"),g(t)}function d(t){for(var e=U.length;e--;)if(U[e].canRoute(t))return!0;return!1}function g(t){for(var e=!1,n=0;n<U.length;n++)U[n].routeTo(t)===!0&&(e=!0);return e}function y(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 h(e)}}function v(t){if(0===t.button)return y(t.currentTarget||t.target||this),m(t)}function m(t){return t&&(t.stopImmediatePropagation&&t.stopImmediatePropagation(),t.stopPropagation&&t.stopPropagation(),t.preventDefault()),!1}function b(t){if(!(t.ctrlKey||t.metaKey||t.altKey||t.shiftKey)){var e=t.target;do if("A"===String(e.nodeName).toUpperCase()&&e.getAttribute("href")&&f(e)){if(0!==t.button)return;if(y(e))return m(t)}while(e=e.parentNode)}}var C={},O=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},R=null,U=[],w={},_="undefined"!=typeof Symbol?Symbol.for("preactattr"):"__preactattr_";"function"==typeof addEventListener&&(addEventListener("popstate",function(){return g(s())}),addEventListener("click",b));var j=function(e){var n=e.children,r=p(e,["children"]);return t.h("a",O({},r,{onClick:v}),n)},x=function(t){function r(e){u(this,r);var n=a(this,t.call(this,e));return e.history&&(R=e.history),n.state={url:n.props.url||s()},n}return c(r,t),r.prototype.shouldComponentUpdate=function(t){return t.static!==!0||(t.url!==this.props.url||t.onChange!==this.props.onChange)},r.prototype.canRoute=function(t){return this.getMatchingChildren(this.props.children,t,!1).length>0},r.prototype.routeTo=function(t){return this._didRoute=!1,this.setState({url:t}),this.updating?this.canRoute(t):(this.forceUpdate(),this._didRoute)},r.prototype.componentWillMount=function(){U.push(this),this.updating=!0},r.prototype.componentDidMount=function(){this.updating=!1},r.prototype.componentWillUnmount=function(){U.splice(U.indexOf(this),1)},r.prototype.componentWillUpdate=function(){this.updating=!0},r.prototype.componentDidUpdate=function(){this.updating=!1},r.prototype.getMatchingChildren=function(t,r,o){return t.slice().sort(n).filter(function(t){var n=t.attributes,i=n.path,u=e(r,i,n);if(u){if(o!==!1){n.url=r,n.matches=u;for(var a in u)u.hasOwnProperty(a)&&(n[a]=u[a])}return!0}})},r.prototype.render=function(t,e){var n=t.children,r=t.onChange,o=e.url,i=this.getMatchingChildren(n,o,!0),u=i[0]||null;this._didRoute=!!u;var a=this.previousUrl;return o!==a&&(this.previousUrl=o,"function"==typeof r&&r({router:this,url:o,previous:a,active:i,current:u})),u},r}(t.Component),P=function(e){var n=e.component,r=e.url,o=e.matches;return t.h(n,{url:r,matches:o})};return x.route=h,x.Router=x,x.Route=P,x.Link=j,x}); | ||
!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){"use strict";function e(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:b,o=/(?:\?([^#]*))?(#.*)?$/,i=t.match(o),u={},a=void 0;if(i&&i[1])for(var p=i[1].split("&"),c=0;c<p.length;c++){var f=p[c].split("=");u[decodeURIComponent(f[0])]=decodeURIComponent(f.slice(1).join("="))}t=r(t.replace(o,"")),e=r(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(/[+*?]+$/)||b)[0]||"",g=~d.indexOf("+"),y=~d.indexOf("*"),v=t[s]||"";if(!v&&!y&&(d.indexOf("?")<0||g)){a=!1;break}if(u[h]=decodeURIComponent(v),g||y){u[h]=t.slice(s).map(decodeURIComponent).join("/");break}}else if(e[s]!==t[s]){a=!1;break}return(n.default===!0||a!==!1)&&u}function n(t,e){var n=t.attributes||b,r=e.attributes||b;if(n.default)return 1;if(r.default)return-1;var i=o(n.path)-o(r.path);return i||n.path.length-r.path.length}function r(t){return i(t).split("/")}function o(t){return(i(t).match(/\/+/g)||"").length}function i(t){return t.replace(/(^\/+|\/+$)/g,"")}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function p(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function c(t){return _ in t}function f(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"push";R&&R[e]?R[e](t):"undefined"!=typeof history&&history[e+"State"]&&history[e+"State"](null,null,t)}function l(){var t=void 0;return t=R&&R.location?R.location:R&&R.getCurrentLocation?R.getCurrentLocation():"undefined"!=typeof location?location:U,""+(t.pathname||"")+(t.search||"")}function s(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof t&&t.url&&(e=t.replace,t=t.url),h(t)&&f(t,e?"replace":"push"),d(t)}function h(t){for(var e=O.length;e--;)if(O[e].canRoute(t))return!0;return!1}function d(t){for(var e=!1,n=0;n<O.length;n++)O[n].routeTo(t)===!0&&(e=!0);return e}function g(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 y(t){if(0===t.button)return g(t.currentTarget||t.target||this),v(t)}function v(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)){var e=t.target;do if("A"===String(e.nodeName).toUpperCase()&&e.getAttribute("href")&&c(e)){if(0!==t.button)return;if(g(e))return v(t)}while(e=e.parentNode)}}var b={},C=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},R=null,O=[],U={},_="undefined"!=typeof Symbol?Symbol.for("preactattr"):"__preactattr_";"function"==typeof addEventListener&&(addEventListener("popstate",function(){return d(l())}),addEventListener("click",m));var w=function(e){return t.h("a",C({},e,{onClick:y}))},j=function(t){function r(e){u(this,r);var n=a(this,t.call(this,e));return e.history&&(R=e.history),n.state={url:n.props.url||l()},n}return p(r,t),r.prototype.shouldComponentUpdate=function(t){return t.static!==!0||(t.url!==this.props.url||t.onChange!==this.props.onChange)},r.prototype.canRoute=function(t){return this.getMatchingChildren(this.props.children,t,!1).length>0},r.prototype.routeTo=function(t){return this._didRoute=!1,this.setState({url:t}),this.updating?this.canRoute(t):(this.forceUpdate(),this._didRoute)},r.prototype.componentWillMount=function(){O.push(this),this.updating=!0},r.prototype.componentDidMount=function(){this.updating=!1},r.prototype.componentWillUnmount=function(){O.splice(O.indexOf(this),1)},r.prototype.componentWillUpdate=function(){this.updating=!0},r.prototype.componentDidUpdate=function(){this.updating=!1},r.prototype.getMatchingChildren=function(t,r,o){return t.slice().sort(n).filter(function(t){var n=t.attributes,i=n.path,u=e(r,i,n);if(u){if(o!==!1){n.url=r,n.matches=u;for(var a in u)u.hasOwnProperty(a)&&(n[a]=u[a])}return!0}})},r.prototype.render=function(t,e){var n=t.children,r=t.onChange,o=e.url,i=this.getMatchingChildren(n,o,!0),u=i[0]||null;this._didRoute=!!u;var a=this.previousUrl;return o!==a&&(this.previousUrl=o,"function"==typeof r&&r({router:this,url:o,previous:a,active:i,current:u})),u},r}(t.Component),x=function(e){var n=e.component,r=e.url,o=e.matches;return t.h(n,{url:r,matches:o})};return j.route=s,j.Router=j,j.Route=x,j.Link=w,j}); | ||
//# sourceMappingURL=preact-router.min.js.map |
{ | ||
"name": "preact-router", | ||
"amdName": "preactRouter", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Connect your components up to that address bar.", | ||
@@ -46,2 +46,3 @@ "main": "dist/preact-router.js", | ||
"babel-plugin-transform-es2015-classes": "^6.9.0", | ||
"babel-plugin-transform-object-assign": "^6.0.0", | ||
"babel-plugin-transform-react-jsx": "^6.8.0", | ||
@@ -48,0 +49,0 @@ "babel-preset-es2015": "^6.9.0", |
@@ -134,5 +134,5 @@ import { h, Component } from 'preact'; | ||
const Link = ({ children, ...props }) => ( | ||
<a {...props} onClick={handleLinkClick}>{ children }</a> | ||
); | ||
const Link = (props) => { | ||
return h('a', Object.assign({}, props, { onClick: handleLinkClick })); | ||
}; | ||
@@ -240,5 +240,5 @@ | ||
const Route = ({ component:RoutedComponent, url, matches }) => ( | ||
<RoutedComponent {...{url, matches}} /> | ||
); | ||
const Route = ({ component, url, matches }) => { | ||
return h(component, { url, matches }); | ||
}; | ||
@@ -245,0 +245,0 @@ |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
87490
27
1167
37
2