react-breadcrumbs
Advanced tools
Comparing version 1.6.2 to 1.6.4
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import Breadcrumbs from '../index.jsx'; | ||
var userlist = [ | ||
@@ -5,0 +5,0 @@ {id:"1", name:"John"}, |
@@ -11,3 +11,3 @@ import React from 'react' | ||
<Route name="UserLocator" path=":userId" component={User}> | ||
<Route name="UserDetails" path="details" component={UserDetails} /> | ||
<Route name="UserDetails" path="details(/:baz)" component={UserDetails} /> | ||
</Route> | ||
@@ -14,0 +14,0 @@ </Route> |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),_react=require("react"),_react2=_interopRequireDefault(_react),_reactRouter=require("react-router"),_exenv=require("exenv"),_exenv2=_interopRequireDefault(_exenv),Breadcrumbs=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.displayName="Breadcrumbs",r}return _inherits(t,e),_createClass(t,[{key:"_getDisplayName",value:function(e){var t=null;return"function"==typeof e.getDisplayName&&(t=e.getDisplayName()),t=e.indexRoute?t||e.indexRoute.displayName||null:t||e.displayName||null,!t&&Boolean(e.name)&&(t=e.name),!t&&this.props.displayMissing&&(t=this.props.displayMissingText),t}},{key:"_addKeyToElement",value:function(e){return e&&!e.key&&e.type?Object.assign({},e,{key:100*Math.random()}):e}},{key:"_addKeyToArrayElements",value:function(e){var t=this;return e.map(function(e){return t._addKeyToElement(e)})}},{key:"_processCustomElements",value:function(e){var t=this;return e.map(function(e){return e?Array.isArray(e)?t._addKeyToArrayElements(e):t._addKeyToElement(e):null})}},{key:"_appendAndPrependElements",value:function(e){var t=[],r=this._processCustomElements([e.shift(),e.pop()]);return r[0]&&t.unshift(r[0]),t.push(e[0]),r[1]&&t.push(r[1]),t.reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return e})}},{key:"_resolveRouteName",value:function(e){var t=this._getDisplayName(e);return!t&&e.breadcrumbName&&(t=e.breadcrumbName),!t&&e.name&&(t=e.name),t}},{key:"_processRoute",value:function(e,t,r,a){var s=this;if(!e.path&&this.props.hideNoPath)return null;var n="",p=this._resolveRouteName(e);if(p&&"excludes"in this.props&&this.props.excludes.some(function(e){return e===p}))return null;var o=!0;o&&(o=Boolean(e.childRoutes)),n=r?"":this.props.separator,o||(n=""),Object.prototype.hasOwnProperty.call(e,"breadcrumblink")&&(o=e.breadcrumblink);var i=e.path.split("/")[e.path.split("/").length-1],u=void 0;if(e.path.split("/").forEach(function(t){if(":"===t.substring(0,1)&&s.props.params){u=Object.keys(s.props.params).map(function(e){return s.props.params[e]});var r=e.path.split("/").map(function(e){return":"===e.substring(0,1)?u.shift():e});e.path=r.reduce(function(e,t){return e+"/"+t}),e.staticName||":"!==i.substring(0,1)||(p=r.reduce(function(e,t){return t})),"function"==typeof e.prettifyParam&&(p=e.prettifyParam(p,s.props.params))}}),!p)return null;this.props.prettify&&(p=p.replace(/-/g," "),p=p.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()}));var l=p,c=this.props.itemClass;return o?a&&(l=_react2["default"].createElement(this.props.Link||_reactRouter.Link,{to:e.path},p)):c+=" "+this.props.activeItemClass,a?_react2["default"].createElement(this.props.itemElement,{className:c,key:100*Math.random()},l,n):l}},{key:"_buildRoutes",value:function(e,t,r,a){var s=this,n=[],p="/";return e=e.map(function(e,t){var r=Object.assign({},e);if("function"==typeof e.prettifyParam&&(r.prettifyParam=e.prettifyParam),"props"in r&&"path"in r.props&&(r.path=r.props.path,r.children=r.props.children,r.name=r.props.name,r.prettifyParam=r.props.prettifyParam),!r.path)return null;"/"===r.path.charAt(0)?p=r.path:("/"!==p.charAt(p.length-1)&&(p+="/"),p+=r.path),t>0&&"/"!==r.path.charAt(0)&&(r.path=p);var a=s._resolveRouteName(r);return!s.props.displayMissing&&!a||"excludes"in s.props&&s.props.excludes.some(function(e){return e===a})?null:r}).filter(function(e){return Boolean(e)}),n=e.map(function(r,a){return s._processRoute(r,e.length,e.length===a+1,t)}).filter(function(e){return Boolean(e)}),_exenv2["default"].canUseDOM&&window&&window.document&&"setDocumentTitle"in this.props&&this.props.setDocumentTitle&&n[n.length-1].props.children[0]>0&&(window.document.title=n[n.length-1].props.children[0].props.children),(r||a)&&(n=this._appendAndPrependElements([r,n,a])),t?_react2["default"].createElement(this.props.wrapperElement,{className:this.props.customClass||this.props.wrapperClass},n):n}},{key:"render",value:function(){return this._buildRoutes(this.props.routes,this.props.createElement,this.props.prepend,this.props.append)}}]),t}(_react2["default"].Component);Breadcrumbs.propTypes={params:_react2["default"].PropTypes.object.isRequired,prepend:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.node,_react2["default"].PropTypes.bool]),append:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.node,_react2["default"].PropTypes.bool]),separator:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),createElement:_react2["default"].PropTypes.bool,Link:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),displayMissing:_react2["default"].PropTypes.bool,prettify:_react2["default"].PropTypes.bool,displayMissingText:_react2["default"].PropTypes.string,wrapperElement:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),wrapperClass:_react2["default"].PropTypes.string,itemElement:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),itemClass:_react2["default"].PropTypes.string,customClass:_react2["default"].PropTypes.string,activeItemClass:_react2["default"].PropTypes.string,excludes:_react2["default"].PropTypes.arrayOf(_react2["default"].PropTypes.string),hideNoPath:_react2["default"].PropTypes.bool,routes:_react2["default"].PropTypes.arrayOf(_react2["default"].PropTypes.object).isRequired,setDocumentTitle:_react2["default"].PropTypes.bool},Breadcrumbs.defaultProps={prepend:!1,append:!1,separator:" > ",createElement:!0,displayMissing:!0,displayMissingText:"Missing name prop from Route",wrapperElement:"div",wrapperClass:"breadcrumbs",itemElement:"span",itemClass:"",activeItemClass:"",excludes:[""],prettify:!1,hideNoPath:!0,setDocumentTitle:!1},module.exports=Breadcrumbs; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var p=t[r];p.enumerable=p.enumerable||!1,p.configurable=!0,"value"in p&&(p.writable=!0),Object.defineProperty(e,p.key,p)}}return function(t,r,p){return r&&e(t.prototype,r),p&&e(t,p),t}}(),_react=require("react"),_react2=_interopRequireDefault(_react),_reactRouter=require("react-router"),_exenv=require("exenv"),_exenv2=_interopRequireDefault(_exenv),_propTypes=require("prop-types"),_propTypes2=_interopRequireDefault(_propTypes),Breadcrumbs=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.displayName="Breadcrumbs",r}return _inherits(t,e),_createClass(t,[{key:"_getDisplayName",value:function(e){var t=null;return"function"==typeof e.getDisplayName&&(t=e.getDisplayName()),t=e.indexRoute?t||e.indexRoute.displayName||null:t||e.displayName||null,!t&&Boolean(e.name)&&(t=e.name),!t&&this.props.displayMissing&&(t=this.props.displayMissingText),t}},{key:"_addKeyToElement",value:function(e){return e&&!e.key&&e.type?Object.assign({},e,{key:100*Math.random()}):e}},{key:"_addKeyToArrayElements",value:function(e){var t=this;return e.map(function(e){return t._addKeyToElement(e)})}},{key:"_processCustomElements",value:function(e){var t=this;return e.map(function(e){return e?Array.isArray(e)?t._addKeyToArrayElements(e):t._addKeyToElement(e):null})}},{key:"_appendAndPrependElements",value:function(e){var t=[],r=this._processCustomElements([e.shift(),e.pop()]);return r[0]&&t.unshift(r[0]),t.push(e[0]),r[1]&&t.push(r[1]),t.reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return e})}},{key:"_resolveRouteName",value:function(e){var t=this._getDisplayName(e);return!t&&e.breadcrumbName&&(t=e.breadcrumbName),!t&&e.name&&(t=e.name),t}},{key:"_processRoute",value:function(e,t,r,p){var s=this;if(!e.path&&this.props.hideNoPath)return null;var n="",a=this._resolveRouteName(e);if(a&&"excludes"in this.props&&this.props.excludes.some(function(e){return e===a}))return null;var o=!0;o&&(o=Boolean(e.childRoutes)),n=r?"":this.props.separator,o||(n=""),Object.prototype.hasOwnProperty.call(e,"breadcrumblink")&&(o=e.breadcrumblink);var i=e.path.split("/")[e.path.split("/").length-1],u=void 0;if(e.path.split("/").forEach(function(t){if(":"===t.substring(0,1)&&s.props.params){u=Object.keys(s.props.params).map(function(e){return s.props.params[e]});var r=e.path.split("/").map(function(e){return":"===e.substring(0,1)?u.shift():e});e.path=r.reduce(function(e,t){return e+"/"+t}),e.staticName||":"!==i.substring(0,1)||(a=r.reduce(function(e,t){return t})),"function"==typeof e.prettifyParam&&(a=e.prettifyParam(a,s.props.params))}}),!a)return null;this.props.prettify&&(a=a.replace(/-/g," "),a=a.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()}));var l=a,c=this.props.itemClass;return o?p&&(l=_react2["default"].createElement(this.props.Link||_reactRouter.Link,{to:e.path},a)):c+=" "+this.props.activeItemClass,p?_react2["default"].createElement(this.props.itemElement,{className:c,key:100*Math.random()},l,n):l}},{key:"_buildRoutes",value:function(e,t,r,p){var s=this,n=[],a="/";return e=e.map(function(e,t){var r=Object.assign({},e);if("function"==typeof e.prettifyParam&&(r.prettifyParam=e.prettifyParam),"props"in r&&"path"in r.props&&(r.path=r.props.path,r.children=r.props.children,r.name=r.props.name,r.prettifyParam=r.props.prettifyParam),!r.path)return null;"/"===r.path.charAt(0)?a=r.path:("/"!==a.charAt(a.length-1)&&(a+="/"),a+=r.path),t>0&&"/"!==r.path.charAt(0)&&(r.path=a);var p=s._resolveRouteName(r);return!s.props.displayMissing&&!p||"excludes"in s.props&&s.props.excludes.some(function(e){return e===p})?null:r}).filter(function(e){return Boolean(e)}),n=e.map(function(r,p){return s._processRoute(r,e.length,e.length===p+1,t)}).filter(function(e){return Boolean(e)}),_exenv2["default"].canUseDOM&&window&&window.document&&"setDocumentTitle"in this.props&&this.props.setDocumentTitle&&n[n.length-1].props.children[0]>0&&(window.document.title=n[n.length-1].props.children[0].props.children),(r||p)&&(n=this._appendAndPrependElements([r,n,p])),t?_react2["default"].createElement(this.props.wrapperElement,{className:this.props.customClass||this.props.wrapperClass},n):n}},{key:"render",value:function(){return this._buildRoutes(this.props.routes,this.props.createElement,this.props.prepend,this.props.append)}}]),t}(_react2["default"].Component);Breadcrumbs.propTypes={params:_propTypes2["default"].object.isRequired,prepend:_propTypes2["default"].oneOfType([_propTypes2["default"].node,_propTypes2["default"].bool]),append:_propTypes2["default"].oneOfType([_propTypes2["default"].node,_propTypes2["default"].bool]),separator:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),createElement:_propTypes2["default"].bool,Link:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),displayMissing:_propTypes2["default"].bool,prettify:_propTypes2["default"].bool,displayMissingText:_propTypes2["default"].string,wrapperElement:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),wrapperClass:_propTypes2["default"].string,itemElement:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),itemClass:_propTypes2["default"].string,customClass:_propTypes2["default"].string,activeItemClass:_propTypes2["default"].string,excludes:_propTypes2["default"].arrayOf(_propTypes2["default"].string),hideNoPath:_propTypes2["default"].bool,routes:_propTypes2["default"].arrayOf(_propTypes2["default"].object).isRequired,setDocumentTitle:_propTypes2["default"].bool},Breadcrumbs.defaultProps={prepend:!1,append:!1,separator:" > ",createElement:!0,displayMissing:!0,displayMissingText:"Missing name prop from Route",wrapperElement:"div",wrapperClass:"breadcrumbs",itemElement:"span",itemClass:"",activeItemClass:"",excludes:[""],prettify:!1,hideNoPath:!0,setDocumentTitle:!1},module.exports=Breadcrumbs; | ||
//# sourceMappingURL=dist/react-breadcrumbs.min.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,r,a){return r&&e(t.prototype,r),a&&e(t,a),t}}(),_react=require("react"),_react2=_interopRequireDefault(_react),_reactRouter=require("react-router"),_exenv=require("exenv"),_exenv2=_interopRequireDefault(_exenv),Breadcrumbs=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.displayName="Breadcrumbs",r}return _inherits(t,e),_createClass(t,[{key:"_getDisplayName",value:function(e){var t=null;return"function"==typeof e.getDisplayName&&(t=e.getDisplayName()),t=e.indexRoute?t||e.indexRoute.displayName||null:t||e.displayName||null,!t&&Boolean(e.name)&&(t=e.name),!t&&this.props.displayMissing&&(t=this.props.displayMissingText),t}},{key:"_addKeyToElement",value:function(e){return e&&!e.key&&e.type?Object.assign({},e,{key:100*Math.random()}):e}},{key:"_addKeyToArrayElements",value:function(e){var t=this;return e.map(function(e){return t._addKeyToElement(e)})}},{key:"_processCustomElements",value:function(e){var t=this;return e.map(function(e){return e?Array.isArray(e)?t._addKeyToArrayElements(e):t._addKeyToElement(e):null})}},{key:"_appendAndPrependElements",value:function(e){var t=[],r=this._processCustomElements([e.shift(),e.pop()]);return r[0]&&t.unshift(r[0]),t.push(e[0]),r[1]&&t.push(r[1]),t.reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return e})}},{key:"_resolveRouteName",value:function(e){var t=this._getDisplayName(e);return!t&&e.breadcrumbName&&(t=e.breadcrumbName),!t&&e.name&&(t=e.name),t}},{key:"_processRoute",value:function(e,t,r,a){var s=this;if(!e.path&&this.props.hideNoPath)return null;var n="",p=this._resolveRouteName(e);if(p&&"excludes"in this.props&&this.props.excludes.some(function(e){return e===p}))return null;var o=!0;o&&(o=Boolean(e.childRoutes)),n=r?"":this.props.separator,o||(n=""),Object.prototype.hasOwnProperty.call(e,"breadcrumblink")&&(o=e.breadcrumblink);var i=e.path.split("/")[e.path.split("/").length-1],u=void 0;if(e.path.split("/").forEach(function(t){if(":"===t.substring(0,1)&&s.props.params){u=Object.keys(s.props.params).map(function(e){return s.props.params[e]});var r=e.path.split("/").map(function(e){return":"===e.substring(0,1)?u.shift():e});e.path=r.reduce(function(e,t){return e+"/"+t}),e.staticName||":"!==i.substring(0,1)||(p=r.reduce(function(e,t){return t})),"function"==typeof e.prettifyParam&&(p=e.prettifyParam(p,s.props.params))}}),!p)return null;this.props.prettify&&(p=p.replace(/-/g," "),p=p.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()}));var l=p,c=this.props.itemClass;return o?a&&(l=_react2["default"].createElement(this.props.Link||_reactRouter.Link,{to:e.path},p)):c+=" "+this.props.activeItemClass,a?_react2["default"].createElement(this.props.itemElement,{className:c,key:100*Math.random()},l,n):l}},{key:"_buildRoutes",value:function(e,t,r,a){var s=this,n=[],p="/";return e=e.map(function(e,t){var r=Object.assign({},e);if("function"==typeof e.prettifyParam&&(r.prettifyParam=e.prettifyParam),"props"in r&&"path"in r.props&&(r.path=r.props.path,r.children=r.props.children,r.name=r.props.name,r.prettifyParam=r.props.prettifyParam),!r.path)return null;"/"===r.path.charAt(0)?p=r.path:("/"!==p.charAt(p.length-1)&&(p+="/"),p+=r.path),t>0&&"/"!==r.path.charAt(0)&&(r.path=p);var a=s._resolveRouteName(r);return!s.props.displayMissing&&!a||"excludes"in s.props&&s.props.excludes.some(function(e){return e===a})?null:r}).filter(function(e){return Boolean(e)}),n=e.map(function(r,a){return s._processRoute(r,e.length,e.length===a+1,t)}).filter(function(e){return Boolean(e)}),_exenv2["default"].canUseDOM&&window&&window.document&&"setDocumentTitle"in this.props&&this.props.setDocumentTitle&&n[n.length-1].props.children[0]>0&&(window.document.title=n[n.length-1].props.children[0].props.children),(r||a)&&(n=this._appendAndPrependElements([r,n,a])),t?_react2["default"].createElement(this.props.wrapperElement,{className:this.props.customClass||this.props.wrapperClass},n):n}},{key:"render",value:function(){return this._buildRoutes(this.props.routes,this.props.createElement,this.props.prepend,this.props.append)}}]),t}(_react2["default"].Component);Breadcrumbs.propTypes={params:_react2["default"].PropTypes.object.isRequired,prepend:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.node,_react2["default"].PropTypes.bool]),append:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.node,_react2["default"].PropTypes.bool]),separator:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),createElement:_react2["default"].PropTypes.bool,Link:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),displayMissing:_react2["default"].PropTypes.bool,prettify:_react2["default"].PropTypes.bool,displayMissingText:_react2["default"].PropTypes.string,wrapperElement:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),wrapperClass:_react2["default"].PropTypes.string,itemElement:_react2["default"].PropTypes.oneOfType([_react2["default"].PropTypes.element,_react2["default"].PropTypes.string]),itemClass:_react2["default"].PropTypes.string,customClass:_react2["default"].PropTypes.string,activeItemClass:_react2["default"].PropTypes.string,excludes:_react2["default"].PropTypes.arrayOf(_react2["default"].PropTypes.string),hideNoPath:_react2["default"].PropTypes.bool,routes:_react2["default"].PropTypes.arrayOf(_react2["default"].PropTypes.object).isRequired,setDocumentTitle:_react2["default"].PropTypes.bool},Breadcrumbs.defaultProps={prepend:!1,append:!1,separator:" > ",createElement:!0,displayMissing:!0,displayMissingText:"Missing name prop from Route",wrapperElement:"div",wrapperClass:"breadcrumbs",itemElement:"span",itemClass:"",activeItemClass:"",excludes:[""],prettify:!1,hideNoPath:!0,setDocumentTitle:!1},module.exports=Breadcrumbs; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var p=t[r];p.enumerable=p.enumerable||!1,p.configurable=!0,"value"in p&&(p.writable=!0),Object.defineProperty(e,p.key,p)}}return function(t,r,p){return r&&e(t.prototype,r),p&&e(t,p),t}}(),_react=require("react"),_react2=_interopRequireDefault(_react),_reactRouter=require("react-router"),_exenv=require("exenv"),_exenv2=_interopRequireDefault(_exenv),_propTypes=require("prop-types"),_propTypes2=_interopRequireDefault(_propTypes),Breadcrumbs=function(e){function t(e){_classCallCheck(this,t);var r=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.displayName="Breadcrumbs",r}return _inherits(t,e),_createClass(t,[{key:"_getDisplayName",value:function(e){var t=null;return"function"==typeof e.getDisplayName&&(t=e.getDisplayName()),t=e.indexRoute?t||e.indexRoute.displayName||null:t||e.displayName||null,!t&&Boolean(e.name)&&(t=e.name),!t&&this.props.displayMissing&&(t=this.props.displayMissingText),t}},{key:"_addKeyToElement",value:function(e){return e&&!e.key&&e.type?Object.assign({},e,{key:100*Math.random()}):e}},{key:"_addKeyToArrayElements",value:function(e){var t=this;return e.map(function(e){return t._addKeyToElement(e)})}},{key:"_processCustomElements",value:function(e){var t=this;return e.map(function(e){return e?Array.isArray(e)?t._addKeyToArrayElements(e):t._addKeyToElement(e):null})}},{key:"_appendAndPrependElements",value:function(e){var t=[],r=this._processCustomElements([e.shift(),e.pop()]);return r[0]&&t.unshift(r[0]),t.push(e[0]),r[1]&&t.push(r[1]),t.reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return e})}},{key:"_resolveRouteName",value:function(e){var t=this._getDisplayName(e);return!t&&e.breadcrumbName&&(t=e.breadcrumbName),!t&&e.name&&(t=e.name),t}},{key:"_processRoute",value:function(e,t,r,p){var s=this;if(!e.path&&this.props.hideNoPath)return null;var n="",a=this._resolveRouteName(e);if(a&&"excludes"in this.props&&this.props.excludes.some(function(e){return e===a}))return null;var o=!0;o&&(o=Boolean(e.childRoutes)),n=r?"":this.props.separator,o||(n=""),Object.prototype.hasOwnProperty.call(e,"breadcrumblink")&&(o=e.breadcrumblink);var i=e.path.split("/")[e.path.split("/").length-1],u=void 0;if(e.path.split("/").forEach(function(t){if(":"===t.substring(0,1)&&s.props.params){u=Object.keys(s.props.params).map(function(e){return s.props.params[e]});var r=e.path.split("/").map(function(e){return":"===e.substring(0,1)?u.shift():e});e.path=r.reduce(function(e,t){return e+"/"+t}),e.staticName||":"!==i.substring(0,1)||(a=r.reduce(function(e,t){return t})),"function"==typeof e.prettifyParam&&(a=e.prettifyParam(a,s.props.params))}}),!a)return null;this.props.prettify&&(a=a.replace(/-/g," "),a=a.replace(/\w\S*/g,function(e){return e.charAt(0).toUpperCase()+e.substr(1).toLowerCase()}));var l=a,c=this.props.itemClass;return o?p&&(l=_react2["default"].createElement(this.props.Link||_reactRouter.Link,{to:e.path},a)):c+=" "+this.props.activeItemClass,p?_react2["default"].createElement(this.props.itemElement,{className:c,key:100*Math.random()},l,n):l}},{key:"_buildRoutes",value:function(e,t,r,p){var s=this,n=[],a="/";return e=e.map(function(e,t){var r=Object.assign({},e);if("function"==typeof e.prettifyParam&&(r.prettifyParam=e.prettifyParam),"props"in r&&"path"in r.props&&(r.path=r.props.path,r.children=r.props.children,r.name=r.props.name,r.prettifyParam=r.props.prettifyParam),!r.path)return null;"/"===r.path.charAt(0)?a=r.path:("/"!==a.charAt(a.length-1)&&(a+="/"),a+=r.path),t>0&&"/"!==r.path.charAt(0)&&(r.path=a);var p=s._resolveRouteName(r);return!s.props.displayMissing&&!p||"excludes"in s.props&&s.props.excludes.some(function(e){return e===p})?null:r}).filter(function(e){return Boolean(e)}),n=e.map(function(r,p){return s._processRoute(r,e.length,e.length===p+1,t)}).filter(function(e){return Boolean(e)}),_exenv2["default"].canUseDOM&&window&&window.document&&"setDocumentTitle"in this.props&&this.props.setDocumentTitle&&n[n.length-1].props.children[0]>0&&(window.document.title=n[n.length-1].props.children[0].props.children),(r||p)&&(n=this._appendAndPrependElements([r,n,p])),t?_react2["default"].createElement(this.props.wrapperElement,{className:this.props.customClass||this.props.wrapperClass},n):n}},{key:"render",value:function(){return this._buildRoutes(this.props.routes,this.props.createElement,this.props.prepend,this.props.append)}}]),t}(_react2["default"].Component);Breadcrumbs.propTypes={params:_propTypes2["default"].object.isRequired,prepend:_propTypes2["default"].oneOfType([_propTypes2["default"].node,_propTypes2["default"].bool]),append:_propTypes2["default"].oneOfType([_propTypes2["default"].node,_propTypes2["default"].bool]),separator:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),createElement:_propTypes2["default"].bool,Link:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),displayMissing:_propTypes2["default"].bool,prettify:_propTypes2["default"].bool,displayMissingText:_propTypes2["default"].string,wrapperElement:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),wrapperClass:_propTypes2["default"].string,itemElement:_propTypes2["default"].oneOfType([_propTypes2["default"].element,_propTypes2["default"].string]),itemClass:_propTypes2["default"].string,customClass:_propTypes2["default"].string,activeItemClass:_propTypes2["default"].string,excludes:_propTypes2["default"].arrayOf(_propTypes2["default"].string),hideNoPath:_propTypes2["default"].bool,routes:_propTypes2["default"].arrayOf(_propTypes2["default"].object).isRequired,setDocumentTitle:_propTypes2["default"].bool},Breadcrumbs.defaultProps={prepend:!1,append:!1,separator:" > ",createElement:!0,displayMissing:!0,displayMissingText:"Missing name prop from Route",wrapperElement:"div",wrapperClass:"breadcrumbs",itemElement:"span",itemClass:"",activeItemClass:"",excludes:[""],prettify:!1,hideNoPath:!0,setDocumentTitle:!1},module.exports=Breadcrumbs; | ||
//# sourceMappingURL=dist/react-breadcrumbs.min.js.map |
@@ -7,3 +7,3 @@ /* global window */ | ||
* @exports Breadcrumbs | ||
* @version 1.1.11 | ||
* @version 1.6 | ||
* @extends component | ||
@@ -14,5 +14,7 @@ * @requires react | ||
*/ | ||
import React from 'react' | ||
import { Link } from 'react-router' | ||
import ExecutionEnvironment from 'exenv' | ||
import PropTypes from "prop-types" | ||
@@ -39,3 +41,3 @@ class Breadcrumbs extends React.Component { | ||
// check to see if a custom name has been applied to the route | ||
// Check to see if a custom name has been applied to the route | ||
if (!name && Boolean(route.name)) { | ||
@@ -45,4 +47,4 @@ name = route.name | ||
// if the name exists and it's in the excludes list exclude this route | ||
// if (name && this.props.excludes.some(item => item === name)) return null | ||
// If the name exists and it's in the excludes list exclude this route | ||
// If (name && this.props.excludes.some(item => item === name)) return null | ||
@@ -104,3 +106,3 @@ if (!name && this.props.displayMissing) { | ||
_processRoute(route, routesLength, lastCrumb, createElement) { | ||
// if there is no route path defined and we are set to hide these then do so | ||
// If there is no route path defined and we are set to hide these then do so | ||
if (!route.path && this.props.hideNoPath) { | ||
@@ -120,3 +122,3 @@ return null | ||
// don't make link if route doesn't have a child route | ||
// Don't make link if route doesn't have a child route | ||
if (makeLink) { | ||
@@ -126,3 +128,3 @@ makeLink = Boolean(route.childRoutes) | ||
// set up separator | ||
// Set up separator | ||
separator = lastCrumb ? '' : this.props.separator | ||
@@ -133,3 +135,3 @@ if (!makeLink) { | ||
// don't make link if route has a disabled breadcrumblink prop | ||
// Don't make link if route has a disabled breadcrumblink prop | ||
if (Object.prototype.hasOwnProperty.call(route, 'breadcrumblink')) { | ||
@@ -143,4 +145,3 @@ makeLink = route.breadcrumblink | ||
route.path.split('/').forEach((link) => { | ||
// if this is not a param, or we've been given no params to replace with, | ||
// we need not do anything | ||
// If this is not a param, or we've been given no params to replace with, we need not do anything | ||
if (link.substring(0, 1) !== ':' || !this.props.params) { | ||
@@ -214,3 +215,3 @@ return | ||
// iterate over the initial list of routes and remove all that don't apply | ||
// Iterate over the initial list of routes and remove all that don't apply | ||
routes = routes | ||
@@ -250,6 +251,6 @@ .map((_route, index) => { | ||
// iterate over the pruned list of routes and build the crumbs for each | ||
// Iterate over the pruned list of routes and build the crumbs for each | ||
crumbs = routes | ||
.map((route, idx) => { | ||
return this._processRoute(route, routes.length, routes.length === idx + 1 , createElement) | ||
return this._processRoute(route, routes.length, routes.length === idx + 1, createElement) | ||
}) | ||
@@ -293,39 +294,39 @@ .filter((crumb) => (Boolean(crumb))) | ||
Breadcrumbs.propTypes = { | ||
'params': React.PropTypes.object.isRequired, | ||
'prepend': React.PropTypes.oneOfType([ | ||
React.PropTypes.node, | ||
React.PropTypes.bool | ||
'params': PropTypes.object.isRequired, | ||
'prepend': PropTypes.oneOfType([ | ||
PropTypes.node, | ||
PropTypes.bool | ||
]), | ||
'append': React.PropTypes.oneOfType([ | ||
React.PropTypes.node, | ||
React.PropTypes.bool | ||
'append': PropTypes.oneOfType([ | ||
PropTypes.node, | ||
PropTypes.bool | ||
]), | ||
'separator': React.PropTypes.oneOfType([ | ||
React.PropTypes.element, | ||
React.PropTypes.string | ||
'separator': PropTypes.oneOfType([ | ||
PropTypes.element, | ||
PropTypes.string | ||
]), | ||
'createElement': React.PropTypes.bool, | ||
'Link': React.PropTypes.oneOfType([ | ||
React.PropTypes.element, | ||
React.PropTypes.string | ||
'createElement': PropTypes.bool, | ||
'Link': PropTypes.oneOfType([ | ||
PropTypes.element, | ||
PropTypes.string | ||
]), | ||
'displayMissing': React.PropTypes.bool, | ||
'prettify': React.PropTypes.bool, | ||
'displayMissingText': React.PropTypes.string, | ||
'wrapperElement': React.PropTypes.oneOfType([ | ||
React.PropTypes.element, | ||
React.PropTypes.string | ||
'displayMissing': PropTypes.bool, | ||
'prettify': PropTypes.bool, | ||
'displayMissingText': PropTypes.string, | ||
'wrapperElement': PropTypes.oneOfType([ | ||
PropTypes.element, | ||
PropTypes.string | ||
]), | ||
'wrapperClass': React.PropTypes.string, | ||
'itemElement': React.PropTypes.oneOfType([ | ||
React.PropTypes.element, | ||
React.PropTypes.string | ||
'wrapperClass': PropTypes.string, | ||
'itemElement': PropTypes.oneOfType([ | ||
PropTypes.element, | ||
PropTypes.string | ||
]), | ||
'itemClass': React.PropTypes.string, | ||
'customClass': React.PropTypes.string, | ||
'activeItemClass': React.PropTypes.string, | ||
'excludes': React.PropTypes.arrayOf(React.PropTypes.string), | ||
'hideNoPath': React.PropTypes.bool, | ||
'routes': React.PropTypes.arrayOf(React.PropTypes.object).isRequired, | ||
'setDocumentTitle': React.PropTypes.bool | ||
'itemClass': PropTypes.string, | ||
'customClass': PropTypes.string, | ||
'activeItemClass': PropTypes.string, | ||
'excludes': PropTypes.arrayOf(PropTypes.string), | ||
'hideNoPath': PropTypes.bool, | ||
'routes': PropTypes.arrayOf(PropTypes.object).isRequired, | ||
'setDocumentTitle': PropTypes.bool | ||
} | ||
@@ -332,0 +333,0 @@ |
{ | ||
"name": "react-breadcrumbs", | ||
"version": "1.6.2", | ||
"version": "1.6.4", | ||
"description": "Automatic breadcrumbs for react-router", | ||
@@ -53,4 +53,4 @@ "main": "index.js", | ||
"peerDependencies": { | ||
"react": ">=0.13.2 || ^15.2.1", | ||
"react-router": ">2.5.0 || ^3.0.0-beta.1" | ||
"react": ">=0.13.2 || <16.x", | ||
"react-router": ">2.5.0 || <4.x" | ||
}, | ||
@@ -68,4 +68,4 @@ "devDependencies": { | ||
"eslint": "^3.17.0", | ||
"eslint-config-xo": "^0.17.0", | ||
"eslint-config-xo-react": "^0.10.0", | ||
"eslint-config-xo": "^0.18.1", | ||
"eslint-config-xo-react": "^0.11.1", | ||
"eslint-plugin-react": "^6.10.0", | ||
@@ -77,7 +77,8 @@ "eslint-plugin-unicorn": "^2.0.1", | ||
"postcss": "^5.2.5", | ||
"postcss-cli": "^2.6.0", | ||
"postcss-cli": "^3.1.1", | ||
"prop-types": "^15.5.7", | ||
"react": "^15.3.2", | ||
"react-addons-test-utils": "^15.3.2", | ||
"react-dom": "^15.3.2", | ||
"react-router": "^2.0.0", | ||
"react-router": "3.x", | ||
"tape": "^4.2.2", | ||
@@ -84,0 +85,0 @@ "uglifyjs": "^2.4.10", |
Sorry, the diff of this file is too big to display
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
1294755
30
7545
28