@sanity/default-layout
Advanced tools
Comparing version 0.1.15 to 0.1.16
@@ -39,6 +39,2 @@ 'use strict'; | ||
var _tool = require('all:part:@sanity/base/tool'); | ||
var _tool2 = _interopRequireDefault(_tool); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -66,4 +62,4 @@ | ||
if (!router.state.tool && _tool2.default.length > 0) { | ||
router.navigate({ tool: _tool2.default[0].name }, { replace: true }); | ||
if (!router.state.tool && this.props.tools.length > 0) { | ||
router.navigate({ tool: this.props.tools[0].name }, { replace: true }); | ||
} | ||
@@ -85,2 +81,3 @@ } | ||
var router = this.context.router; | ||
var tools = this.props.tools; | ||
@@ -93,3 +90,3 @@ return _react2.default.createElement( | ||
{ className: _DefaultLayout2.default.desktopNavigation }, | ||
_react2.default.createElement(_DesktopNavigation2.default, null) | ||
_react2.default.createElement(_DesktopNavigation2.default, { tools: tools }) | ||
), | ||
@@ -99,3 +96,3 @@ _react2.default.createElement( | ||
{ className: _DefaultLayout2.default.mobileNavigation }, | ||
_react2.default.createElement(_MobileNavigation2.default, null) | ||
_react2.default.createElement(_MobileNavigation2.default, { tools: tools }) | ||
), | ||
@@ -129,2 +126,10 @@ _react2.default.createElement( | ||
}; | ||
DefaultLayout.propTypes = { | ||
tools: _react.PropTypes.arrayOf(_react.PropTypes.shape({ | ||
name: _react.PropTypes.string | ||
})) | ||
}; | ||
exports.default = DefaultLayout; |
@@ -29,2 +29,8 @@ 'use strict'; | ||
var _router = require('part:@sanity/base/router'); | ||
var _configSanity = require('config:sanity'); | ||
var _configSanity2 = _interopRequireDefault(_configSanity); | ||
var _NoLogin = require('./NoLogin'); | ||
@@ -38,8 +44,6 @@ | ||
var _configSanity = require('config:sanity'); | ||
var _getOrderedTools = require('../util/getOrderedTools'); | ||
var _configSanity2 = _interopRequireDefault(_configSanity); | ||
var _getOrderedTools2 = _interopRequireDefault(_getOrderedTools); | ||
var _router = require('part:@sanity/base/router'); | ||
var _defaultLayoutRouter = require('../defaultLayoutRouter'); | ||
@@ -57,4 +61,4 @@ | ||
var DefaultLayoutContainer = function (_React$Component) { | ||
_inherits(DefaultLayoutContainer, _React$Component); | ||
var DefaultLayoutContainer = function (_React$PureComponent) { | ||
_inherits(DefaultLayoutContainer, _React$PureComponent); | ||
@@ -92,2 +96,3 @@ function DefaultLayoutContainer() { | ||
var locale = _configSanity2.default.locale || {}; | ||
var tools = (0, _getOrderedTools2.default)(); | ||
var supportedLanguages = locale.supportedLanguages || ['en-US']; | ||
@@ -109,3 +114,3 @@ var LoginWrapper = _loginWrapper2.default || _NoLogin2.default; | ||
{ router: _defaultLayoutRouter2.default, state: _defaultLayoutRouter2.default.decode(location.pathname), onNavigate: this.handleNavigate }, | ||
_defaultLayoutRouter2.default.isNotFound(location.pathname) ? _react2.default.createElement(_NotFound2.default, null) : _react2.default.createElement(_DefaultLayout2.default, null) | ||
_defaultLayoutRouter2.default.isNotFound(location.pathname) ? _react2.default.createElement(_NotFound2.default, null) : _react2.default.createElement(_DefaultLayout2.default, { tools: tools }) | ||
) | ||
@@ -118,4 +123,4 @@ ) | ||
return DefaultLayoutContainer; | ||
}(_react2.default.Component); | ||
}(_react2.default.PureComponent); | ||
exports.default = DefaultLayoutContainer; |
@@ -29,6 +29,2 @@ 'use strict'; | ||
var _tool = require('all:part:@sanity/base/tool'); | ||
var _tool2 = _interopRequireDefault(_tool); | ||
var _Search = require('./Search'); | ||
@@ -64,3 +60,7 @@ | ||
_react2.default.createElement(_CompanyBranding2.default, null), | ||
_react2.default.createElement(_toolSwitcher2.default, { tools: _tool2.default, activeToolName: router.state.tool, className: _DesktopNavigation2.default.toolSwitcher }), | ||
_react2.default.createElement(_toolSwitcher2.default, { | ||
tools: this.props.tools, | ||
activeToolName: router.state.tool, | ||
className: _DesktopNavigation2.default.toolSwitcher | ||
}), | ||
_react2.default.createElement(_LoginStatus2.default, { className: _DesktopNavigation2.default.loginStatus }), | ||
@@ -82,2 +82,10 @@ _react2.default.createElement( | ||
}; | ||
DesktopNavigation.propTypes = { | ||
tools: _react.PropTypes.arrayOf(_react.PropTypes.shape({ | ||
title: _react.PropTypes.string | ||
})) | ||
}; | ||
exports.default = DesktopNavigation; |
@@ -21,6 +21,2 @@ 'use strict'; | ||
var _tool = require('all:part:@sanity/base/tool'); | ||
var _tool2 = _interopRequireDefault(_tool); | ||
var _MobileNavigation = require('./styles/MobileNavigation.css'); | ||
@@ -90,2 +86,3 @@ | ||
var isOpen = this.state.isOpen; | ||
var tools = this.props.tools; | ||
@@ -113,3 +110,3 @@ return _react2.default.createElement( | ||
_react2.default.createElement(_toolSwitcher2.default, { | ||
tools: _tool2.default, | ||
tools: tools, | ||
activeToolName: router.state.tool, | ||
@@ -130,2 +127,10 @@ className: _MobileNavigation2.default.toolSwitcher, | ||
}; | ||
MobileNavigation.propTypes = { | ||
tools: _react.PropTypes.arrayOf(_react.PropTypes.shape({ | ||
title: _react.PropTypes.string | ||
})) | ||
}; | ||
exports.default = MobileNavigation; |
@@ -23,3 +23,3 @@ 'use strict'; | ||
null, | ||
'No tools fulfills the role ', | ||
'No tools fulfills the part ', | ||
_react2.default.createElement( | ||
@@ -26,0 +26,0 @@ 'code', |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = require('react'); | ||
@@ -14,6 +12,2 @@ | ||
var _defaultLayout = require('config:@sanity/default-layout'); | ||
var _defaultLayout2 = _interopRequireDefault(_defaultLayout); | ||
var _router = require('part:@sanity/base/router'); | ||
@@ -27,115 +21,40 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function ToolSwitcher(props) { | ||
var tools = props.tools, | ||
activeToolName = props.activeToolName; | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
return _react2.default.createElement( | ||
'div', | ||
{ className: _ToolSwitcher2.default.toolSwitcher + ' ' + props.className }, | ||
_react2.default.createElement( | ||
'ul', | ||
{ className: _ToolSwitcher2.default.toolList }, | ||
tools.map(function (tool) { | ||
var itemClass = activeToolName === tool.name ? _ToolSwitcher2.default.activeItem : _ToolSwitcher2.default.item; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var ToolIcon = tool.icon; | ||
var ToolSwitcher = function (_React$PureComponent) { | ||
_inherits(ToolSwitcher, _React$PureComponent); | ||
return _react2.default.createElement( | ||
'li', | ||
{ key: tool.name, className: itemClass }, | ||
_react2.default.createElement( | ||
_router.StateLink, | ||
{ className: _ToolSwitcher2.default.toolLink, state: { tool: tool.name }, onClick: props.onClick }, | ||
_react2.default.createElement( | ||
'span', | ||
{ className: _ToolSwitcher2.default.iconContainer }, | ||
_react2.default.createElement(ToolIcon, null) | ||
), | ||
_react2.default.createElement( | ||
'span', | ||
{ className: _ToolSwitcher2.default.toolName }, | ||
tool.title || tool.name | ||
) | ||
) | ||
); | ||
}) | ||
) | ||
); | ||
} | ||
function ToolSwitcher() { | ||
_classCallCheck(this, ToolSwitcher); | ||
return _possibleConstructorReturn(this, (ToolSwitcher.__proto__ || Object.getPrototypeOf(ToolSwitcher)).apply(this, arguments)); | ||
} | ||
_createClass(ToolSwitcher, [{ | ||
key: 'getOrderedTools', | ||
value: function getOrderedTools() { | ||
var tools = this.props.tools; | ||
var config = _defaultLayout2.default.toolSwitcher || {}; | ||
var order = config.order || []; | ||
var hidden = config.hidden || []; | ||
if (!order.length && !hidden.length) { | ||
return tools; | ||
} | ||
var keyed = tools.reduce(function (target, tool) { | ||
var title = tool.title || '<unknown>'; | ||
if (!tool.name) { | ||
console.warn('Tool "' + title + '" does not have the required "name"-property'); // eslint-disable-line no-console | ||
return target; | ||
} | ||
if (target[tool.name]) { | ||
var existing = target[tool.name].tool.title; | ||
console.warn('Tools with duplicate name "' + tool.name + '" found ("' + title + '" and "' + existing + '")'); // eslint-disable-line no-console | ||
return target; | ||
} | ||
var toolIndex = order.indexOf(tool.name); | ||
target[tool.name] = { | ||
tool: tool, | ||
index: toolIndex === -1 ? +Infinity : toolIndex | ||
}; | ||
return target; | ||
}, {}); | ||
var isVisible = function isVisible(tool) { | ||
return hidden.indexOf(tool.name) === -1; | ||
}; | ||
return tools.filter(isVisible).sort(function (tool1, tool2) { | ||
var toolA = keyed[tool1.name]; | ||
var toolB = keyed[tool2.name]; | ||
var indexA = toolA ? toolA.index : +Infinity; | ||
var indexB = toolB ? toolB.index : +Infinity; | ||
if (indexA === indexB) { | ||
return 0; | ||
} | ||
return indexA - indexB; | ||
}); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _this2 = this; | ||
var activeToolName = this.props.activeToolName; | ||
var tools = this.getOrderedTools(); | ||
return _react2.default.createElement( | ||
'div', | ||
{ className: _ToolSwitcher2.default.toolSwitcher + ' ' + this.props.className }, | ||
_react2.default.createElement( | ||
'ul', | ||
{ className: _ToolSwitcher2.default.toolList }, | ||
tools.map(function (tool) { | ||
var itemClass = activeToolName === tool.name ? _ToolSwitcher2.default.activeItem : _ToolSwitcher2.default.item; | ||
var ToolIcon = tool.icon; | ||
return _react2.default.createElement( | ||
'li', | ||
{ key: tool.name, className: itemClass }, | ||
_react2.default.createElement( | ||
_router.StateLink, | ||
{ className: _ToolSwitcher2.default.toolLink, state: { tool: tool.name }, onClick: _this2.props.onClick }, | ||
_react2.default.createElement( | ||
'span', | ||
{ className: _ToolSwitcher2.default.iconContainer }, | ||
_react2.default.createElement(ToolIcon, null) | ||
), | ||
_react2.default.createElement( | ||
'span', | ||
{ className: _ToolSwitcher2.default.toolName }, | ||
tool.title || tool.name | ||
) | ||
) | ||
); | ||
}) | ||
) | ||
); | ||
} | ||
}]); | ||
return ToolSwitcher; | ||
}(_react2.default.PureComponent); | ||
ToolSwitcher.propTypes = { | ||
@@ -150,2 +69,3 @@ activeToolName: _react.PropTypes.string, | ||
}; | ||
exports.default = ToolSwitcher; |
{ | ||
"name": "@sanity/default-layout", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"description": "The default layout components for Sanity", | ||
@@ -5,0 +5,0 @@ "main": "lib/default-layout.js", |
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
1723
329565