├── coverage
└── lcov-report
│ ├── sort-arrow-sprite.png
│ ├── prettify.css
│ ├── src
│ ├── utils
│ │ ├── keycode.js.html
│ │ └── index.html
│ ├── index.html
│ ├── components
│ │ ├── index.html
│ │ ├── mentionMixin.js.html
│ │ └── Panel.jsx.html
│ ├── editor-components
│ │ ├── index.html
│ │ └── baseEditor.js.html
│ └── index.js.html
│ ├── sorter.js
│ ├── base.css
│ ├── index.html
│ └── prettify.js
├── tests
└── index.js
├── src
├── utils
│ ├── keycode.js
│ ├── util.js
│ └── rangy-position.js
├── index.js
├── components
│ ├── Panel.jsx
│ ├── mentionMixin.js
│ ├── Mention.jsx
│ └── TinymceMention.jsx
├── Mention.less
└── editor-components
│ ├── baseEditor.js
│ ├── textareaEditor.jsx
│ ├── inputEditor.jsx
│ └── contentEditableEditor.jsx
├── demo
├── index.jsx
├── MentionDemo.less
├── MentionDemo.jsx
└── mockData.json
├── .gitignore
├── .npmignore
├── .eslintrc.json
├── .travis.yml
├── index.html
├── HISTORY.md
├── package.json
├── doc
├── zh-CN.md
└── en-US.md
└── README.md
/coverage/lcov-report/sort-arrow-sprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/WisestCoder/uxcore-mention/master/coverage/lcov-report/sort-arrow-sprite.png
--------------------------------------------------------------------------------
/tests/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * only require other specs here
3 | */
4 |
5 | const req = require.context('.', false, /\.spec\.js$/);
6 | req.keys().forEach(req);
--------------------------------------------------------------------------------
/src/utils/keycode.js:
--------------------------------------------------------------------------------
1 | export const KEYCODE = {
2 | DOWN: 40,
3 | UP: 38,
4 | ESC: 27,
5 | TAB: 9,
6 | ENTER: 13,
7 | CTRL: 17,
8 | BACKSPACE: 8,
9 | DELETE: 46,
10 | };
11 |
--------------------------------------------------------------------------------
/demo/index.jsx:
--------------------------------------------------------------------------------
1 | /**
2 | * Mention Component Demo for uxcore
3 | * @author
4 | *
5 | * Copyright 2014-2015, Uxcore Team, Alinw.
6 | * All rights reserved.
7 | */
8 |
9 | import React from 'react';
10 | import { render } from 'react-dom';
11 | import Demo from './MentionDemo';
12 |
13 | render(
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 | 62 | 63 | 1× 64 | 65 | 66 | 1× 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | | "use strict";
77 |
78 | Object.defineProperty(exports, "__esModule", {
79 | value: true
80 | });
81 | var KEYCODE = exports.KEYCODE = {
82 | DOWN: 40,
83 | UP: 38,
84 | ESC: 27,
85 | TAB: 9,
86 | ENTER: 13,
87 | CTRL: 17,
88 | BACKSPACE: 8,
89 | DELETE: 46
90 | };
91 | |
| File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| index.js | 63 |100% | 65 |19/19 | 66 |75% | 67 |3/4 | 68 |100% | 69 |1/1 | 70 |100% | 71 |18/18 | 72 |
| File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| keycode.js | 63 |100% | 65 |2/2 | 66 |100% | 67 |0/0 | 68 |100% | 69 |0/0 | 70 |100% | 71 |2/2 | 72 ||
| rangy-position.js | 76 |21.84% | 78 |64/293 | 79 |9.93% | 80 |15/151 | 81 |17.5% | 82 |7/40 | 83 |22.07% | 84 |64/290 | 85 ||
| util.js | 89 |80.83% | 91 |97/120 | 92 |72% | 93 |36/50 | 94 |100% | 95 |7/7 | 96 |80.83% | 97 |97/120 | 98 |
| File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| src/ | 63 |100% | 65 |19/19 | 66 |75% | 67 |3/4 | 68 |100% | 69 |1/1 | 70 |100% | 71 |18/18 | 72 ||
| src/components/ | 76 |87.2% | 78 |286/328 | 79 |57.62% | 80 |87/151 | 81 |88.89% | 82 |56/63 | 83 |95.93% | 84 |259/270 | 85 ||
| src/editor-components/ | 89 |82.25% | 91 |366/445 | 92 |56.89% | 93 |128/225 | 94 |91.03% | 95 |71/78 | 96 |92.52% | 97 |334/361 | 98 ||
| src/utils/ | 102 |39.28% | 104 |163/415 | 105 |25.37% | 106 |51/201 | 107 |29.79% | 108 |14/47 | 109 |39.56% | 110 |163/412 | 111 |
| File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| Mention.jsx | 63 |83.33% | 65 |55/66 | 66 |46.43% | 67 |13/28 | 68 |87.5% | 69 |14/16 | 70 |97.92% | 71 |47/48 | 72 ||
| Panel.jsx | 76 |78.85% | 78 |41/52 | 79 |46.67% | 80 |14/30 | 81 |90% | 82 |9/10 | 83 |100% | 84 |30/30 | 85 ||
| TinymceMention.jsx | 89 |89.02% | 91 |154/173 | 92 |58.21% | 93 |39/67 | 94 |86.67% | 95 |26/30 | 96 |94.19% | 97 |146/155 | 98 ||
| mentionMixin.js | 102 |97.3% | 104 |36/37 | 105 |80.77% | 106 |21/26 | 107 |100% | 108 |7/7 | 109 |97.3% | 110 |36/37 | 111 |
| File | 50 |51 | | Statements | 52 |53 | | Branches | 54 |55 | | Functions | 56 |57 | | Lines | 58 |59 | |
|---|---|---|---|---|---|---|---|---|---|
| baseEditor.js | 63 |85.51% | 65 |59/69 | 66 |58.7% | 67 |27/46 | 68 |90.91% | 69 |10/11 | 70 |100% | 71 |51/51 | 72 ||
| contentEditableEditor.jsx | 76 |88.82% | 78 |151/170 | 79 |63.22% | 80 |55/87 | 81 |93.1% | 82 |27/29 | 83 |94.08% | 84 |143/152 | 85 ||
| inputEditor.jsx | 89 |75.73% | 91 |78/103 | 92 |50% | 93 |23/46 | 94 |89.47% | 95 |17/19 | 96 |88.61% | 97 |70/79 | 98 ||
| textareaEditor.jsx | 102 |75.73% | 104 |78/103 | 105 |50% | 106 |23/46 | 107 |89.47% | 108 |17/19 | 109 |88.61% | 110 |70/79 | 111 |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 | 88 | 89 | 1× 90 | 91 | 92 | 1× 93 | 94 | 1× 95 | 96 | 1× 97 | 98 | 1× 99 | 100 | 1× 101 | 102 | 1× 103 | 104 | 1× 105 | 106 | 1× 107 | 108 | 1× 109 | 110 | 1× 111 | 112 | 1× 113 | 114 | 5× 115 | 116 | 1× 117 | 1× 118 | 1× 119 | 1× 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 1× 128 | | 'use strict';
129 |
130 | Object.defineProperty(exports, "__esModule", {
131 | value: true
132 | });
133 | exports.TinymceMention = exports.InputEditor = exports.TextareaEditor = exports.ContenteditableEditor = undefined;
134 |
135 | var _Mention = require('./components/Mention');
136 |
137 | var _Mention2 = _interopRequireDefault(_Mention);
138 |
139 | var _contentEditableEditor = require('./editor-components/contentEditableEditor');
140 |
141 | var _contentEditableEditor2 = _interopRequireDefault(_contentEditableEditor);
142 |
143 | var _textareaEditor = require('./editor-components/textareaEditor');
144 |
145 | var _textareaEditor2 = _interopRequireDefault(_textareaEditor);
146 |
147 | var _inputEditor = require('./editor-components/inputEditor');
148 |
149 | var _inputEditor2 = _interopRequireDefault(_inputEditor);
150 |
151 | var _TinymceMention = require('./components/TinymceMention');
152 |
153 | var _TinymceMention2 = _interopRequireDefault(_TinymceMention);
154 |
155 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
156 |
157 | exports.ContenteditableEditor = _contentEditableEditor2['default'];
158 | exports.TextareaEditor = _textareaEditor2['default'];
159 | exports.InputEditor = _inputEditor2['default'];
160 | exports.TinymceMention = _TinymceMention2['default']; /**
161 | * Mention Component for uxcore
162 | * @author
163 | *
164 | * Copyright 2014-2015, Uxcore Team, Alinw.
165 | * All rights reserved.
166 | */
167 |
168 | exports['default'] = _Mention2['default'];
169 | |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 121 | 76 122 | 77 123 | 78 124 | 79 125 | 80 126 | 81 127 | 82 128 | 83 129 | 84 130 | 85 131 | 86 132 | 87 133 | 88 134 | 89 135 | 90 136 | 91 137 | 92 138 | 93 139 | 94 | 140 | 141 | 1× 142 | 143 | 144 | 145 | 1× 146 | 147 | 1× 148 | 149 | 1× 150 | 151 | 97× 152 | 23× 153 | 154 | 155 | 156 | 97× 157 | 13× 158 | 159 | 160 | 161 | 162 | 163 | 31× 164 | 165 | 166 | 167 | 168 | 31× 169 | 18× 170 | 18× 171 | 172 | 1× 173 | 174 | 175 | 1× 176 | 177 | 10× 178 | 179 | 180 | 10× 181 | 182 | 6× 183 | 6× 184 | 185 | 1× 186 | 187 | 188 | 1× 189 | 190 | 191 | 192 | 193 | 13× 194 | 195 | 13× 196 | 12× 197 | 198 | 13× 199 | 13× 200 | 201 | 202 | 203 | 13× 204 | 205 | 206 | 207 | 13× 208 | 209 | 210 | 211 | 13× 212 | 13× 213 | 13× 214 | 104× 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 13× 223 | 13× 224 | 13× 225 | 226 | 13× 227 | 228 | 229 | 230 | 231 | 1× 232 | | 'use strict';
233 |
234 | Object.defineProperty(exports, "__esModule", {
235 | value: true
236 | });
237 |
238 | var _keycode = require('../utils/keycode');
239 |
240 | var __matchTimer = void 0;
241 |
242 | exports['default'] = {
243 | componentDidUpdate: function componentDidUpdate(prevProps, prevState) {
244 | if (prevState.mentionList.length !== this.state.mentionList.length) {
245 | this.setState({
246 | panelVisible: this.state.mentionList.length > 0
247 | });
248 | }
249 | if (!prevState.panelVisible && this.state.panelVisible) {
250 | this.setState({
251 | panelIdx: 0
252 | });
253 | }
254 | },
255 | onPanelKeyup: function onPanelKeyup(e) {
256 | var _state = this.state,
257 | panelVisible = _state.panelVisible,
258 | panelIdx = _state.panelIdx,
259 | mentionList = _state.mentionList;
260 |
261 | if (panelVisible) {
262 | var count = mentionList.length;
263 | switch (e.keyCode) {
264 | case _keycode.KEYCODE.UP:
265 | this.setState({
266 | panelIdx: panelIdx === 0 ? count - 1 : panelIdx - 1
267 | });
268 | break;
269 | case _keycode.KEYCODE.DOWN:
270 | this.setState({
271 | panelIdx: panelIdx === count - 1 ? 0 : panelIdx + 1
272 | });
273 | break;
274 | case _keycode.KEYCODE.ENTER:
275 | this.selectItem(mentionList[panelIdx]);
276 | break;
277 | default:
278 | this.setState({
279 | mentionList: []
280 | });
281 | break;
282 | }
283 | }
284 | },
285 | runMatcher: function runMatcher(str) {
286 | var _this = this;
287 |
288 | if (__matchTimer) {
289 | clearTimeout(__matchTimer);
290 | }
291 | __matchTimer = setTimeout(function () {
292 | _this._matcher(str);
293 | }, this.props.delay);
294 | },
295 | _matcher: function _matcher(str) {
296 | var _props = this.props,
297 | source = _props.source,
298 | matchRange = _props.matchRange;
299 |
300 | this.setState({
301 | panelVisible: false,
302 | mentionList: []
303 | });
304 | Eif (str.length >= matchRange[0] && str.length <= matchRange[1]) {
305 | Eif (Array.isArray(source)) {
306 | this.next(source.filter(function (item) {
307 | return item.indexOf(str) !== -1;
308 | }));
309 | } else {
310 | source(str, this.next.bind(this));
311 | }
312 | }
313 | },
314 | next: function next(matchResult) {
315 | var result = matchResult;
316 | Eif (this.props.formatter) {
317 | result = this.props.formatter(result);
318 | }
319 | this.setState({
320 | mentionList: result
321 | });
322 | }
323 | };
324 | module.exports = exports['default'];
325 | |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 121 | 76 122 | 77 123 | 78 124 | 79 125 | 80 126 | 81 127 | 82 128 | 83 129 | 84 130 | 85 131 | 86 132 | 87 133 | 88 134 | 89 135 | 90 136 | 91 | 137 | 138 | 1× 139 | 140 | 141 | 142 | 1× 143 | 144 | 1× 145 | 146 | 1× 147 | 148 | 1× 149 | 150 | 1× 151 | 152 | 1× 153 | 154 | 3× 155 | 156 | 1× 157 | 158 | 327× 159 | 160 | 30× 161 | 162 | 30× 163 | 164 | 1× 165 | 166 | 1× 167 | 1× 168 | 169 | 1× 170 | 30× 171 | 172 | 30× 173 | 174 | 175 | 1× 176 | 127× 177 | 178 | 127× 179 | 127× 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 127× 188 | 189 | 190 | 191 | 192 | 193 | 200× 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 1× 205 | 206 | 207 | 1× 208 | 1× 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 1× 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 1× 225 | 1× 226 | | 'use strict';
227 |
228 | Object.defineProperty(exports, "__esModule", {
229 | value: true
230 | });
231 |
232 | var _react = require('react');
233 |
234 | var _react2 = _interopRequireDefault(_react);
235 |
236 | var _propTypes = require('prop-types');
237 |
238 | var _propTypes2 = _interopRequireDefault(_propTypes);
239 |
240 | var _classnames = require('classnames');
241 |
242 | var _classnames2 = _interopRequireDefault(_classnames);
243 |
244 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
245 |
246 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
247 |
248 | function _defineProperty(obj, key, value) { Iif (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
249 |
250 | function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
251 |
252 | function _possibleConstructorReturn(self, call) { Iif (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
253 |
254 | function _inherits(subClass, superClass) { Iif (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 } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
255 |
256 | var Panel = function (_Component) {
257 | _inherits(Panel, _Component);
258 |
259 | function Panel() {
260 | _classCallCheck(this, Panel);
261 |
262 | return _possibleConstructorReturn(this, _Component.apply(this, arguments));
263 | }
264 |
265 | Panel.prototype.render = function render() {
266 | var _this2 = this;
267 |
268 | var props = this.props;
269 | var onSelect = props.onSelect,
270 | list = props.list,
271 | style = props.style,
272 | visible = props.visible,
273 | idx = props.idx,
274 | formatter = props.formatter,
275 | prefixCls = props.prefixCls;
276 |
277 | return _react2['default'].createElement(
278 | 'ul',
279 | {
280 | className: (0, _classnames2['default'])(prefixCls + '-panel', _defineProperty({}, prefixCls + '-panel-visible', visible)), style: style
281 | },
282 | list.map(function (item, index) {
283 | return _react2['default'].createElement(
284 | 'li',
285 | {
286 | className: (0, _classnames2['default'])(prefixCls + '-panel-item', _defineProperty({}, prefixCls + '-panel-item-current', idx === index)), key: index, onClick: onSelect.bind(_this2, item)
287 | },
288 | _react2['default'].createElement('div', { dangerouslySetInnerHTML: { __html: formatter(item) } })
289 | );
290 | })
291 | );
292 | };
293 |
294 | return Panel;
295 | }(_react.Component);
296 |
297 | Panel.displayName = 'uxcore-mention-panel';
298 | Panel.propTypes = {
299 | prefixCls: _propTypes2['default'].string,
300 | list: _propTypes2['default'].array,
301 | style: _propTypes2['default'].object,
302 | idx: _propTypes2['default'].number,
303 | onSelect: _propTypes2['default'].func,
304 | formatter: _propTypes2['default'].func
305 | };
306 | Panel.defaultProps = {
307 | prefixCls: '',
308 | list: [],
309 | style: {},
310 | idx: 0,
311 | onSelect: null,
312 | formatter: ''
313 | };
314 | exports['default'] = Panel;
315 | module.exports = exports['default'];
316 | |
| 1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 121 | 76 122 | 77 123 | 78 124 | 79 125 | 80 126 | 81 127 | 82 128 | 83 129 | 84 130 | 85 131 | 86 132 | 87 133 | 88 134 | 89 135 | 90 136 | 91 137 | 92 138 | 93 139 | 94 140 | 95 141 | 96 142 | 97 143 | 98 144 | 99 145 | 100 146 | 101 147 | 102 148 | 103 149 | 104 150 | 105 | 151 | 152 | 1× 153 | 154 | 155 | 156 | 1× 157 | 158 | 1× 159 | 160 | 1× 161 | 162 | 1× 163 | 164 | 1× 165 | 166 | 1× 167 | 168 | 1× 169 | 170 | 32× 171 | 172 | 32× 173 | 174 | 1× 175 | 176 | 1× 177 | 1× 178 | 179 | 1× 180 | 32× 181 | 182 | 32× 183 | 184 | 185 | 1× 186 | 15× 187 | 188 | 189 | 1× 190 | 29× 191 | 192 | 29× 193 | 194 | 195 | 10× 196 | 10× 197 | 198 | 10× 199 | 200 | 5× 201 | 4× 202 | 1× 203 | 1× 204 | 205 | 5× 206 | 207 | 14× 208 | 209 | 210 | 211 | 1× 212 | 26× 213 | 214 | 26× 215 | 216 | 217 | 10× 218 | 10× 219 | 220 | 10× 221 | 222 | 5× 223 | 224 | 11× 225 | 11× 226 | 227 | 11× 228 | 229 | 230 | 231 | 1× 232 | 9× 233 | 234 | 235 | 236 | 9× 237 | 9× 238 | 9× 239 | 240 | 241 | 1× 242 | 243 | 244 | 1× 245 | 1× 246 | 247 | 248 | 249 | 250 | 251 | 1× 252 | 1× 253 | 1× 254 | | 'use strict';
255 |
256 | Object.defineProperty(exports, "__esModule", {
257 | value: true
258 | });
259 |
260 | var _react = require('react');
261 |
262 | var _propTypes = require('prop-types');
263 |
264 | var _propTypes2 = _interopRequireDefault(_propTypes);
265 |
266 | var _keycode = require('../utils/keycode');
267 |
268 | require('../utils/rangy-position');
269 |
270 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
271 |
272 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
273 |
274 | function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
275 |
276 | function _possibleConstructorReturn(self, call) { Iif (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
277 |
278 | function _inherits(subClass, superClass) { Iif (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 } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
279 |
280 | var BaseEditor = function (_Component) {
281 | _inherits(BaseEditor, _Component);
282 |
283 | function BaseEditor() {
284 | _classCallCheck(this, BaseEditor);
285 |
286 | return _possibleConstructorReturn(this, _Component.apply(this, arguments));
287 | }
288 |
289 | BaseEditor.prototype.onFocus = function onFocus() {
290 | this.props.onFocus(this);
291 | };
292 |
293 | BaseEditor.prototype.onKeydown = function onKeydown(e) {
294 | var panelVisible = this.props.panelVisible;
295 |
296 | switch (e.keyCode) {
297 | case _keycode.KEYCODE.UP:
298 | case _keycode.KEYCODE.DOWN:
299 | Eif (panelVisible) {
300 | e.preventDefault();
301 | }
302 | break;
303 | case _keycode.KEYCODE.ENTER:
304 | if (panelVisible) {
305 | e.preventDefault();
306 | } else Eif (this.handleEnterPress) {
307 | this.handleEnterPress(e);
308 | }
309 | break;
310 | default:
311 | break;
312 | }
313 | };
314 |
315 | BaseEditor.prototype.onKeyup = function onKeyup(e) {
316 | var panelVisible = this.props.panelVisible;
317 |
318 | switch (e.keyCode) {
319 | case _keycode.KEYCODE.UP:
320 | case _keycode.KEYCODE.DOWN:
321 | Eif (panelVisible) {
322 | e.preventDefault();
323 | }
324 | break;
325 | case _keycode.KEYCODE.ENTER:
326 | break;
327 | default:
328 | Eif (this.handleDefaultKeyup) {
329 | this.handleDefaultKeyup();
330 | }
331 | break;
332 | }
333 | };
334 |
335 | BaseEditor.prototype.insertMentionData = function insertMentionData(mentionData) {
336 | var _props = this.props,
337 | mentionFormatter = _props.mentionFormatter,
338 | onAdd = _props.onAdd;
339 |
340 | var insertContent = mentionFormatter(mentionData);
341 | this.insert(insertContent);
342 | onAdd(insertContent, mentionData);
343 | };
344 |
345 | return BaseEditor;
346 | }(_react.Component);
347 |
348 | BaseEditor.displayName = 'BaseEditor';
349 | BaseEditor.propTypes = {
350 | panelVisible: _propTypes2['default'].boolean,
351 | onFocus: _propTypes2['default'].func,
352 | mentionFormatter: _propTypes2['default'].func,
353 | onAdd: _propTypes2['default'].func
354 | };
355 | BaseEditor.defaultProps = {};
356 | exports['default'] = BaseEditor;
357 | module.exports = exports['default'];
358 | |