1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = exports.FontBgColorPlugin = undefined;
|
7 |
|
8 | 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; }; }();
|
9 |
|
10 | var _class, _temp;
|
11 |
|
12 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
13 |
|
14 | var _react = require('react');
|
15 |
|
16 | var React = _interopRequireWildcard(_react);
|
17 |
|
18 | var _slateIconShared = require('@canner/slate-icon-shared');
|
19 |
|
20 | var _slateIconShared2 = _interopRequireDefault(_slateIconShared);
|
21 |
|
22 | var _slateHelperMarkAddoverwrite = require('@canner/slate-helper-mark-addoverwrite');
|
23 |
|
24 | var _slateHelperMarkAddoverwrite2 = _interopRequireDefault(_slateHelperMarkAddoverwrite);
|
25 |
|
26 | var _slateUtilHave = require('@canner/slate-util-have');
|
27 |
|
28 | var _slateUtilGet = require('@canner/slate-util-get');
|
29 |
|
30 | var _rcColorPicker = require('rc-color-picker');
|
31 |
|
32 | var _rcColorPicker2 = _interopRequireDefault(_rcColorPicker);
|
33 |
|
34 | var _hexRgb = require('hex-rgb');
|
35 |
|
36 | var _hexRgb2 = _interopRequireDefault(_hexRgb);
|
37 |
|
38 | var _marks = require('@canner/slate-constant/lib/marks');
|
39 |
|
40 | var _lodash = require('lodash.omit');
|
41 |
|
42 | var _lodash2 = _interopRequireDefault(_lodash);
|
43 |
|
44 | var _commonMark = require('@canner/slate-editor-renderer/lib/commonMark');
|
45 |
|
46 | var _commonMark2 = _interopRequireDefault(_commonMark);
|
47 |
|
48 | require('rc-color-picker/assets/index.css');
|
49 |
|
50 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
51 |
|
52 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
53 |
|
54 | 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; }
|
55 |
|
56 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
57 |
|
58 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
59 |
|
60 | 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; }
|
61 |
|
62 | 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; }
|
63 |
|
64 | var FontBgColorPlugin = exports.FontBgColorPlugin = function FontBgColorPlugin(opt) {
|
65 | var options = _extends({
|
66 | type: _marks.FONTBGCOLOR,
|
67 | tagName: 'span',
|
68 | backgroundColor: _slateIconShared.markAttrs.backgroundColor
|
69 | }, opt);
|
70 |
|
71 | return {
|
72 | renderMark: function renderMark(props) {
|
73 | if (props.mark.type === options.type) return (0, _commonMark2.default)(options.tagName, (0, _lodash2.default)(options, ['type', 'tagName']))(props);
|
74 | }
|
75 | };
|
76 | };
|
77 |
|
78 | var fontBgColor = (_temp = _class = function (_React$Component) {
|
79 | _inherits(fontBgColor, _React$Component);
|
80 |
|
81 | function fontBgColor(props) {
|
82 | _classCallCheck(this, fontBgColor);
|
83 |
|
84 | var _this = _possibleConstructorReturn(this, (fontBgColor.__proto__ || Object.getPrototypeOf(fontBgColor)).call(this, props));
|
85 |
|
86 | _this.onChange = function (color) {
|
87 | var _this$props = _this.props,
|
88 | change = _this$props.change,
|
89 | onChange = _this$props.onChange,
|
90 | colorKey = _this$props.colorKey;
|
91 |
|
92 |
|
93 |
|
94 | color.rgba = 'rgba(' + (0, _hexRgb2.default)(color.color, { format: 'array' }).join(',') + ', ' + color.alpha / 100 + ')';
|
95 | _this.setState({ color: color });
|
96 | onChange((0, _slateHelperMarkAddoverwrite2.default)(change, { type: _this.typeName, data: _defineProperty({}, colorKey, color) }));
|
97 | };
|
98 |
|
99 | _this.typeName = _this.props.type || _marks.FONTBGCOLOR;
|
100 | _this.state = {
|
101 | color: {}
|
102 | };
|
103 | return _this;
|
104 | }
|
105 |
|
106 | _createClass(fontBgColor, [{
|
107 | key: 'render',
|
108 | value: function render() {
|
109 | var _props = this.props,
|
110 | icon = _props.icon,
|
111 | change = _props.change,
|
112 | rest = _objectWithoutProperties(_props, ['icon', 'change']);
|
113 |
|
114 | var isActive = (0, _slateUtilHave.haveMarks)(change, this.typeName);
|
115 | var colorStyle = {};
|
116 |
|
117 | if (isActive) {
|
118 | var first = (0, _slateUtilGet.getMarkType)(change, this.typeName).first().get('data');
|
119 | var _color = first.get('color');
|
120 | var _alpha = first.get('alpha');
|
121 |
|
122 | colorStyle = {
|
123 | fill: _color,
|
124 | opacity: _alpha
|
125 | };
|
126 | }
|
127 |
|
128 | return React.createElement(
|
129 | _rcColorPicker2.default,
|
130 | {
|
131 | onChange: this.onChange },
|
132 | React.createElement(_slateIconShared2.default, _extends({
|
133 | colorStyle: colorStyle,
|
134 | type: this.typeName,
|
135 | icon: icon || 'Background',
|
136 | isActive: isActive
|
137 | }, rest))
|
138 | );
|
139 | }
|
140 | }]);
|
141 |
|
142 | return fontBgColor;
|
143 | }(React.Component), _class.defaultProps = {
|
144 | colorKey: 'color'
|
145 | }, _temp);
|
146 | exports.default = fontBgColor; |
\ | No newline at end of file |