1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 |
|
5 | var _react = require('react');
|
6 |
|
7 | var _react2 = _interopRequireDefault(_react);
|
8 |
|
9 | var _immutable = require('immutable');
|
10 |
|
11 | var _ToolbarLine = require('./ToolbarLine');
|
12 |
|
13 | var _ToolbarLine2 = _interopRequireDefault(_ToolbarLine);
|
14 |
|
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
16 |
|
17 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
18 |
|
19 | 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; }
|
20 |
|
21 | 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; }
|
22 |
|
23 |
|
24 | function noop() {}
|
25 |
|
26 | var Toolbar = function (_React$Component) {
|
27 | _inherits(Toolbar, _React$Component);
|
28 |
|
29 | function Toolbar(props) {
|
30 | _classCallCheck(this, Toolbar);
|
31 |
|
32 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
|
33 |
|
34 | var map = {};
|
35 | props.plugins.forEach(function (plugin) {
|
36 | map[plugin.name] = plugin;
|
37 | });
|
38 | _this.pluginsMap = (0, _immutable.Map)(map);
|
39 | _this.state = {
|
40 | editorState: props.editorState,
|
41 | toolbars: []
|
42 | };
|
43 | return _this;
|
44 | }
|
45 |
|
46 | Toolbar.prototype.renderToolbarItem = function renderToolbarItem(pluginName, idx) {
|
47 | var element = this.pluginsMap.get(pluginName);
|
48 | if (element && element.component) {
|
49 | var component = element.component;
|
50 |
|
51 | var props = {
|
52 | key: 'toolbar-item-' + idx,
|
53 | onClick: component.props ? component.props.onClick : noop
|
54 | };
|
55 | if (_react2['default'].isValidElement(component)) {
|
56 | return _react2['default'].cloneElement(component, props);
|
57 | }
|
58 | return _react2['default'].createElement(component, props);
|
59 | }
|
60 | return null;
|
61 | };
|
62 |
|
63 | Toolbar.prototype.conpomentWillReceiveProps = function conpomentWillReceiveProps(nextProps) {
|
64 | this.render();
|
65 | };
|
66 |
|
67 | Toolbar.prototype.render = function render() {
|
68 | var _this2 = this;
|
69 |
|
70 | var _props = this.props,
|
71 | toolbars = _props.toolbars,
|
72 | prefixCls = _props.prefixCls;
|
73 |
|
74 | return _react2['default'].createElement(
|
75 | 'div',
|
76 | { className: prefixCls + '-toolbar' },
|
77 | toolbars.map(function (toolbar, idx) {
|
78 | var children = _react2['default'].Children.map(toolbar, _this2.renderToolbarItem.bind(_this2));
|
79 | return _react2['default'].createElement(
|
80 | _ToolbarLine2['default'],
|
81 | { key: 'toolbar-' + idx },
|
82 | children
|
83 | );
|
84 | })
|
85 | );
|
86 | };
|
87 |
|
88 | return Toolbar;
|
89 | }(_react2['default'].Component);
|
90 |
|
91 | exports['default'] = Toolbar;
|
92 | module.exports = exports['default']; |
\ | No newline at end of file |