armo-breadboard
Version:
Edit a live React component's source in real time.
150 lines (123 loc) • 5.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = undefined;
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 _class, _temp;
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactControllers = require('react-controllers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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 ResponsiveModeController = (_temp = _class = function (_PureController) {
_inherits(ResponsiveModeController, _PureController);
function ResponsiveModeController(props) {
_classCallCheck(this, ResponsiveModeController);
var _this = _possibleConstructorReturn(this, (ResponsiveModeController.__proto__ || Object.getPrototypeOf(ResponsiveModeController)).call(this, props));
_this.state = {
primary: props.defaultMode,
filesPrimary: props.defaultFilesMode
};
return _this;
}
_createClass(ResponsiveModeController, [{
key: 'output',
value: function output() {
var props = this.props;
var _state = this.state,
primary = _state.primary,
filesPrimary = _state.filesPrimary;
var modes = {};
if (props.width !== undefined && props.width <= props.maxSinglePaneWidth) {
modes[primary] = true;
} else {
modes['files'] = true;
modes[primary === 'files' ? props.defaultSecondary : primary] = true;
}
var filesModes = {};
if (props.maxHeight !== undefined && props.maxHeight <= props.maxSinglePaneMaxHeight || filesPrimary === 'source') {
filesModes[filesPrimary] = true;
} else {
filesModes['source'] = true;
filesModes[filesPrimary] = true;
}
return {
modeActions: this.actions,
modes: modes,
filesModes: filesModes
};
}
}]);
return ResponsiveModeController;
}(_reactControllers.PureController), _class.propTypes = {
/**
* The default mode to display upon load when the screen only contains
* space for a single pane.
*/
defaultMode: _propTypes2.default.oneOf(['files', 'browser', 'console', 'info']),
/**
* Selects the secondary pane to display in the case that the user is
* viewing the source pane on a small screen, and then the screen
* expands to allow a second pane.
*/
defaultSecondary: _propTypes2.default.oneOf(['browser', 'console', 'info']),
/**
* The default mode to display in an files tab when it only contains
* space for a single pane.
*/
defaultFilesMode: _propTypes2.default.oneOf(['source', 'transformedSource', 'solution']),
/**
* The maximum width for which only a single pane will be used.
*/
maxSinglePaneWidth: _propTypes2.default.number,
/**
* The maximum screen height for which only a single pane will be used.
*/
maxSinglePaneMaxHeight: _propTypes2.default.number,
/**
* Current breadboard width.
*/
width: _propTypes2.default.number,
/**
* The maximum possible height to which the breadboard can expand.
*/
maxHeight: _propTypes2.default.number
}, _class.defaultProps = {
defaultSecondary: 'browser',
defaultMode: 'files',
defaultFilesMode: 'source',
maxSinglePaneWidth: 999,
maxSinglePaneMaxHeight: 650
}, _class.actions = {
selectFilesMode: function selectFilesMode(mode) {
this.setState({ filesPrimary: mode });
},
selectSource: function selectSource() {
this.setState({ filesPrimary: 'source' });
},
selectTransformedSource: function selectTransformedSource() {
this.setState({ filesPrimary: 'transformedSource' });
},
selectSolution: function selectSolution() {
this.setState({ filesPrimary: 'solution' });
},
selectMode: function selectMode(mode) {
this.setState({ primary: mode });
},
selectFiles: function selectFiles() {
this.setState({ primary: 'files' });
},
selectBrowser: function selectBrowser() {
this.setState({ primary: 'browser' });
},
selectConsole: function selectConsole() {
this.setState({ primary: 'console' });
},
selectInfo: function selectInfo() {
this.setState({ primary: 'info' });
}
}, _temp);
exports.default = ResponsiveModeController;