1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = clearPastedStyle;
|
7 |
|
8 | var _draftJs = require('draft-js');
|
9 |
|
10 | var _replaceTextRegex = require('./replaceTextRegex');
|
11 |
|
12 | var BLOCK_TYPES = ['header-three', 'unordered-list-item', 'ordered-list-item'];
|
13 |
|
14 | function clearPastedStyle(editorState) {
|
15 | var CS = editorState.getCurrentContent();
|
16 | var SS = editorState.getSelection();
|
17 |
|
18 | var blockMap = CS.getBlockMap().map(function (block) {
|
19 | if (BLOCK_TYPES.indexOf(block.type) === -1) {
|
20 | if (block.type.slice(0, 6) === 'header') {
|
21 | return (0, _replaceTextRegex.createContentBlock)(block, { type: 'header-three' });
|
22 | }
|
23 | return (0, _replaceTextRegex.createContentBlock)(block, { type: 'unstyled' });
|
24 | }
|
25 | return block;
|
26 | });
|
27 | var newCS = new _draftJs.ContentState({ blockMap: blockMap });
|
28 | var newEditorState = _draftJs.EditorState.createWithContent(newCS);
|
29 | var ES = _draftJs.EditorState.forceSelection(newEditorState, SS);
|
30 |
|
31 | return ES;
|
32 | } |
\ | No newline at end of file |