@studysync/draft-js-modifiers 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/addBlock.js +2 -2
- package/adjustBlockDepth.js +4 -4
- package/es/addBlock.js +30 -19
- package/es/adjustBlockDepth.js +16 -5
- package/es/getAllEntities.js +29 -0
- package/es/getEntitiesForBlock.js +44 -0
- package/es/getSelectedText.js +19 -0
- package/es/index.js +243 -23
- package/es/insertAtomicBlock.js +11 -3
- package/es/insertEmptyBlock.js +13 -3
- package/es/insertEntity.js +37 -0
- package/es/insertNewBlock.js +25 -11
- package/es/insertText.js +14 -4
- package/es/mergeBlockData.js +16 -5
- package/es/mergeBlockDataByKey.js +12 -4
- package/es/mergeEntityData.js +11 -3
- package/es/modifyBlock.js +16 -5
- package/es/modifyBlockByKey.js +11 -3
- package/es/moveCaretAfterBlock.js +13 -5
- package/es/moveCaretToEnd.js +25 -0
- package/es/removeBlock.js +16 -7
- package/es/removeBlockStyle.js +12 -4
- package/es/removeEntity.js +34 -0
- package/es/removeInlineStyles.js +19 -8
- package/es/resetBlock.js +19 -7
- package/es/selectAll.js +22 -0
- package/es/selectBlockByKey.js +14 -5
- package/es/toggleBlockStyle.js +19 -9
- package/es/toggleBlockType.js +11 -3
- package/es/toggleEntity.js +11 -3
- package/es/toggleInlineStyle.js +11 -3
- package/es/utils/getCurrentBlock.js +9 -1
- package/getAllEntities.js +29 -0
- package/getEntitiesForBlock.js +44 -0
- package/getSelectedText.js +19 -0
- package/index.js +81 -25
- package/insertAtomicBlock.js +2 -2
- package/insertEmptyBlock.js +4 -4
- package/insertEntity.js +37 -0
- package/insertNewBlock.js +4 -4
- package/insertText.js +2 -2
- package/mergeBlockData.js +2 -2
- package/mergeBlockDataByKey.js +2 -2
- package/mergeEntityData.js +2 -2
- package/modifyBlock.js +4 -4
- package/modifyBlockByKey.js +2 -2
- package/moveCaretAfterBlock.js +2 -2
- package/moveCaretToEnd.js +25 -0
- package/package.json +8 -10
- package/removeBlock.js +2 -2
- package/removeBlockStyle.js +2 -2
- package/removeEntity.js +34 -0
- package/removeInlineStyles.js +4 -4
- package/resetBlock.js +2 -2
- package/selectAll.js +22 -0
- package/selectBlockByKey.js +2 -2
- package/toggleBlockStyle.js +2 -2
- package/toggleBlockType.js +2 -2
- package/toggleEntity.js +2 -2
- package/toggleInlineStyle.js +2 -2
- package/utils/getCurrentBlock.js +2 -2
- package/es/getCurrentBlock.js +0 -6
- package/getCurrentBlock.js +0 -14
package/es/insertText.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var insertText = function insertText(editorState, text) {
|
|
4
11
|
var entity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
5
12
|
var selection = editorState.getSelection();
|
|
6
13
|
var content = editorState.getCurrentContent();
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
|
|
15
|
+
var newContent = _draftJs.Modifier[selection.isCollapsed() ? 'insertText' : 'replaceText'](content, selection, text, editorState.getCurrentInlineStyle(), entity);
|
|
16
|
+
|
|
17
|
+
return _draftJs.EditorState.push(editorState, newContent, 'insert-fragment');
|
|
9
18
|
};
|
|
10
19
|
|
|
11
|
-
|
|
20
|
+
var _default = insertText;
|
|
21
|
+
exports["default"] = _default;
|
package/es/mergeBlockData.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
var _immutable = require("immutable");
|
|
3
11
|
|
|
4
12
|
var mergeBlockData = function mergeBlockData(editorState, data) {
|
|
5
13
|
var content = editorState.getCurrentContent();
|
|
6
14
|
var selection = editorState.getSelection();
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
|
|
16
|
+
var newContent = _draftJs.Modifier.mergeBlockData(content, selection, (0, _immutable.Map)(data));
|
|
17
|
+
|
|
18
|
+
return _draftJs.EditorState.push(editorState, newContent, 'change-block-data');
|
|
9
19
|
};
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
var _default = mergeBlockData;
|
|
22
|
+
exports["default"] = _default;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
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; }
|
|
4
11
|
|
|
5
12
|
var mergeBlockDataByKey = function mergeBlockDataByKey(editorState, blockKey, data) {
|
|
6
13
|
var content = editorState.getCurrentContent();
|
|
7
14
|
var updatedBlock = content.getBlockForKey(blockKey).mergeIn(['data'], data);
|
|
8
15
|
var blockMap = content.getBlockMap().merge(_defineProperty({}, blockKey, updatedBlock));
|
|
9
|
-
return EditorState.push(editorState, content.merge({
|
|
16
|
+
return _draftJs.EditorState.push(editorState, content.merge({
|
|
10
17
|
blockMap: blockMap
|
|
11
18
|
}), 'change-block-data');
|
|
12
19
|
};
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
var _default = mergeBlockDataByKey;
|
|
22
|
+
exports["default"] = _default;
|
package/es/mergeEntityData.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var mergeEntityData = function mergeEntityData(editorState, entityKey, data) {
|
|
4
11
|
var newContentState = editorState.getCurrentContent().mergeEntityData(entityKey, data);
|
|
5
|
-
return EditorState.forceSelection(EditorState.push(editorState, newContentState, 'apply-entity'), editorState.getSelection());
|
|
12
|
+
return _draftJs.EditorState.forceSelection(_draftJs.EditorState.push(editorState, newContentState, 'apply-entity'), editorState.getSelection());
|
|
6
13
|
};
|
|
7
14
|
|
|
8
|
-
|
|
15
|
+
var _default = mergeEntityData;
|
|
16
|
+
exports["default"] = _default;
|
package/es/modifyBlock.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
var _modifyBlockForContentState = _interopRequireDefault(require("draft-js/lib/modifyBlockForContentState"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
3
13
|
|
|
4
14
|
var modifyBlock = function modifyBlock(editorState, blockData) {
|
|
5
15
|
var content = editorState.getCurrentContent();
|
|
6
16
|
var selection = editorState.getSelection();
|
|
7
|
-
var newContent =
|
|
17
|
+
var newContent = (0, _modifyBlockForContentState["default"])(content, selection, function (block) {
|
|
8
18
|
return block.merge(blockData);
|
|
9
19
|
});
|
|
10
|
-
return EditorState.push(editorState, newContent, 'split-block' // TODO: will this do ?
|
|
20
|
+
return _draftJs.EditorState.push(editorState, newContent, 'split-block' // TODO: will this do ?
|
|
11
21
|
);
|
|
12
22
|
};
|
|
13
23
|
|
|
14
|
-
|
|
24
|
+
var _default = modifyBlock;
|
|
25
|
+
exports["default"] = _default;
|
package/es/modifyBlockByKey.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var modifyBlockByKey = function modifyBlockByKey(editorState, blockKey, blockData) {
|
|
4
11
|
var content = editorState.getCurrentContent();
|
|
@@ -8,8 +15,9 @@ var modifyBlockByKey = function modifyBlockByKey(editorState, blockKey, blockDat
|
|
|
8
15
|
var newContent = content.merge({
|
|
9
16
|
blockMap: blockMap
|
|
10
17
|
});
|
|
11
|
-
return EditorState.push(editorState, newContent, 'split-block' // TODO: will this do ?
|
|
18
|
+
return _draftJs.EditorState.push(editorState, newContent, 'split-block' // TODO: will this do ?
|
|
12
19
|
);
|
|
13
20
|
};
|
|
14
21
|
|
|
15
|
-
|
|
22
|
+
var _default = modifyBlockByKey;
|
|
23
|
+
exports["default"] = _default;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
3
9
|
|
|
4
10
|
var moveCaretAfterBlock = function moveCaretAfterBlock(editorState, block) {
|
|
5
11
|
var content = editorState.getCurrentContent();
|
|
@@ -7,17 +13,19 @@ var moveCaretAfterBlock = function moveCaretAfterBlock(editorState, block) {
|
|
|
7
13
|
var key = nextBlock ? nextBlock.getKey() : undefined;
|
|
8
14
|
|
|
9
15
|
if (key) {
|
|
10
|
-
var selectionState = SelectionState.createEmpty();
|
|
16
|
+
var selectionState = _draftJs.SelectionState.createEmpty();
|
|
17
|
+
|
|
11
18
|
var newSelectionState = selectionState.merge({
|
|
12
19
|
anchorKey: key,
|
|
13
20
|
anchorOffset: 0,
|
|
14
21
|
focusKey: key,
|
|
15
22
|
focusOffset: 0
|
|
16
23
|
});
|
|
17
|
-
return EditorState.forceSelection(editorState, newSelectionState);
|
|
24
|
+
return _draftJs.EditorState.forceSelection(editorState, newSelectionState);
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
return editorState;
|
|
21
28
|
};
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
var _default = moveCaretAfterBlock;
|
|
31
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
var moveCaretToEnd = function moveCaretToEnd(editorState) {
|
|
11
|
+
var content = editorState.getCurrentContent();
|
|
12
|
+
var lastBlock = content.getLastBlock();
|
|
13
|
+
var key = lastBlock.getKey();
|
|
14
|
+
var length = lastBlock.getLength();
|
|
15
|
+
var selection = new _draftJs.SelectionState({
|
|
16
|
+
anchorKey: key,
|
|
17
|
+
anchorOffset: length,
|
|
18
|
+
focusKey: key,
|
|
19
|
+
focusOffset: length
|
|
20
|
+
});
|
|
21
|
+
return _draftJs.EditorState.forceSelection(editorState, selection);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var _default = moveCaretToEnd;
|
|
25
|
+
exports["default"] = _default;
|
package/es/removeBlock.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
import { Modifier } from "draft-js"; // from draft-js-plugins/draft-js-plugins/packages/drag-n-drop/src/modifiers/addBlock.ts
|
|
1
|
+
"use strict";
|
|
3
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
// from draft-js-plugins/draft-js-plugins/packages/drag-n-drop/src/modifiers/addBlock.ts
|
|
4
11
|
var removeBlock = function removeBlock(contentState, blockKey) {
|
|
5
12
|
var afterKey = contentState.getKeyAfter(blockKey);
|
|
6
13
|
var afterBlock = contentState.getBlockForKey(afterKey);
|
|
@@ -9,14 +16,14 @@ var removeBlock = function removeBlock(contentState, blockKey) {
|
|
|
9
16
|
// without any characters.
|
|
10
17
|
|
|
11
18
|
if (afterBlock && afterBlock.getType() === 'unstyled' && afterBlock.getLength() === 0 && afterBlock === contentState.getBlockMap().last()) {
|
|
12
|
-
targetRange = new SelectionState({
|
|
19
|
+
targetRange = new _draftJs.SelectionState({
|
|
13
20
|
anchorKey: blockKey,
|
|
14
21
|
anchorOffset: 0,
|
|
15
22
|
focusKey: afterKey,
|
|
16
23
|
focusOffset: 0
|
|
17
24
|
});
|
|
18
25
|
} else {
|
|
19
|
-
targetRange = new SelectionState({
|
|
26
|
+
targetRange = new _draftJs.SelectionState({
|
|
20
27
|
anchorKey: blockKey,
|
|
21
28
|
anchorOffset: 0,
|
|
22
29
|
focusKey: blockKey,
|
|
@@ -25,8 +32,10 @@ var removeBlock = function removeBlock(contentState, blockKey) {
|
|
|
25
32
|
} // change the blocktype and remove the characterList entry with the block
|
|
26
33
|
|
|
27
34
|
|
|
28
|
-
var newContentState = Modifier.setBlockType(contentState, targetRange, 'unstyled');
|
|
29
|
-
|
|
35
|
+
var newContentState = _draftJs.Modifier.setBlockType(contentState, targetRange, 'unstyled');
|
|
36
|
+
|
|
37
|
+
return _draftJs.Modifier.removeRange(newContentState, targetRange, 'backward');
|
|
30
38
|
};
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
var _default = removeBlock;
|
|
41
|
+
exports["default"] = _default;
|
package/es/removeBlockStyle.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var removeBlockStyle = function removeBlockStyle(editorState) {
|
|
4
|
-
var withoutBlockStyle = RichUtils.tryToRemoveBlockStyle(editorState);
|
|
11
|
+
var withoutBlockStyle = _draftJs.RichUtils.tryToRemoveBlockStyle(editorState);
|
|
5
12
|
|
|
6
13
|
if (withoutBlockStyle) {
|
|
7
|
-
return EditorState.push(editorState, withoutBlockStyle, 'change-block-type');
|
|
14
|
+
return _draftJs.EditorState.push(editorState, withoutBlockStyle, 'change-block-type');
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
return editorState;
|
|
11
18
|
};
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
var _default = removeBlockStyle;
|
|
21
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
var removeEntity = function removeEntity(editorState, entity) {
|
|
11
|
+
var contentState = editorState.getCurrentContent();
|
|
12
|
+
var selectionState = editorState.getSelection();
|
|
13
|
+
var startKey = selectionState.getStartKey();
|
|
14
|
+
var contentBlock = contentState.getBlockForKey(startKey);
|
|
15
|
+
/* istanbul ignore if */
|
|
16
|
+
|
|
17
|
+
if (!entity) return editorState;
|
|
18
|
+
var entitySelection = null;
|
|
19
|
+
contentBlock.findEntityRanges(function (character) {
|
|
20
|
+
return character.getEntity() === entity.entityKey;
|
|
21
|
+
}, function (start, end) {
|
|
22
|
+
entitySelection = selectionState.merge({
|
|
23
|
+
anchorOffset: start,
|
|
24
|
+
focusOffset: end
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
var newContentState = _draftJs.Modifier.applyEntity(contentState, entitySelection, null);
|
|
29
|
+
|
|
30
|
+
return _draftJs.EditorState.push(editorState, newContentState, 'apply-entity');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var _default = removeEntity;
|
|
34
|
+
exports["default"] = _default;
|
package/es/removeInlineStyles.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
10
|
+
var _getCurrentBlock = _interopRequireDefault(require("./utils/getCurrentBlock"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
5
15
|
|
|
6
16
|
var removeInlineStyles = function removeInlineStyles(editorState) {
|
|
7
17
|
var inlineStyles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
@@ -10,10 +20,10 @@ var removeInlineStyles = function removeInlineStyles(editorState) {
|
|
|
10
20
|
var newContent;
|
|
11
21
|
|
|
12
22
|
if (selection.isCollapsed()) {
|
|
13
|
-
var block =
|
|
23
|
+
var block = (0, _getCurrentBlock["default"])(editorState);
|
|
14
24
|
var updatedCharacterList = block.getCharacterList().map(function (c) {
|
|
15
25
|
return inlineStyles.reduce(function (characterMetadata, style) {
|
|
16
|
-
return CharacterMetadata.removeStyle(characterMetadata, style);
|
|
26
|
+
return _draftJs.CharacterMetadata.removeStyle(characterMetadata, style);
|
|
17
27
|
}, c);
|
|
18
28
|
});
|
|
19
29
|
var updatedBlock = block.set('characterList', updatedCharacterList);
|
|
@@ -22,11 +32,12 @@ var removeInlineStyles = function removeInlineStyles(editorState) {
|
|
|
22
32
|
});
|
|
23
33
|
} else {
|
|
24
34
|
newContent = inlineStyles.reduce(function (contentState, style) {
|
|
25
|
-
return Modifier.removeInlineStyle(contentState, selection, style);
|
|
35
|
+
return _draftJs.Modifier.removeInlineStyle(contentState, selection, style);
|
|
26
36
|
}, content);
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
return EditorState.push(editorState, newContent, 'change-inline-style');
|
|
39
|
+
return _draftJs.EditorState.push(editorState, newContent, 'change-inline-style');
|
|
30
40
|
};
|
|
31
41
|
|
|
32
|
-
|
|
42
|
+
var _default = removeInlineStyles;
|
|
43
|
+
exports["default"] = _default;
|
package/es/resetBlock.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
/**
|
|
4
11
|
* Remove range also change block type to 'unstyled'
|
|
@@ -6,16 +13,21 @@ import { EditorState, SelectionState, Modifier } from 'draft-js';
|
|
|
6
13
|
var resetBlock = function resetBlock(editorState, block) {
|
|
7
14
|
var content = editorState.getCurrentContent();
|
|
8
15
|
var key = block.getKey();
|
|
9
|
-
var targetRange = new SelectionState({
|
|
16
|
+
var targetRange = new _draftJs.SelectionState({
|
|
10
17
|
anchorKey: key,
|
|
11
18
|
anchorOffset: 0,
|
|
12
19
|
focusKey: key,
|
|
13
20
|
focusOffset: block.getLength()
|
|
14
21
|
});
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
|
|
23
|
+
var withoutTargetContent = _draftJs.Modifier.removeRange(content, targetRange, 'backward');
|
|
24
|
+
|
|
25
|
+
var resetBlock = _draftJs.Modifier.setBlockType(withoutTargetContent, withoutTargetContent.getSelectionAfter(), 'unstyled');
|
|
26
|
+
|
|
27
|
+
var newState = _draftJs.EditorState.push(editorState, resetBlock, 'remove-range');
|
|
28
|
+
|
|
29
|
+
return _draftJs.EditorState.forceSelection(newState, resetBlock.getSelectionAfter());
|
|
19
30
|
};
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
var _default = resetBlock;
|
|
33
|
+
exports["default"] = _default;
|
package/es/selectAll.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
var selectAll = function selectAll(editorState) {
|
|
11
|
+
var currentContent = editorState.getCurrentContent();
|
|
12
|
+
var selectionState = editorState.getSelection().merge({
|
|
13
|
+
anchorKey: currentContent.getFirstBlock().getKey(),
|
|
14
|
+
anchorOffset: 0,
|
|
15
|
+
focusOffset: currentContent.getLastBlock().getText().length,
|
|
16
|
+
focusKey: currentContent.getLastBlock().getKey()
|
|
17
|
+
});
|
|
18
|
+
return _draftJs.EditorState.forceSelection(editorState, selectionState);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var _default = selectAll;
|
|
22
|
+
exports["default"] = _default;
|
package/es/selectBlockByKey.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
3
9
|
|
|
4
10
|
var selectBlockByKey = function selectBlockByKey(editorState, key) {
|
|
5
11
|
var currentBlock = editorState.getCurrentContent().getBlockForKey(key);
|
|
6
|
-
|
|
12
|
+
|
|
13
|
+
var selectionState = _draftJs.SelectionState.createEmpty();
|
|
14
|
+
|
|
7
15
|
var entireBlockSelectionState = selectionState.merge({
|
|
8
16
|
anchorKey: key,
|
|
9
17
|
anchorOffset: 0,
|
|
10
18
|
focusKey: key,
|
|
11
19
|
focusOffset: currentBlock.getText().length
|
|
12
20
|
});
|
|
13
|
-
return EditorState.forceSelection(editorState, entireBlockSelectionState);
|
|
21
|
+
return _draftJs.EditorState.forceSelection(editorState, entireBlockSelectionState);
|
|
14
22
|
};
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
var _default = selectBlockByKey;
|
|
25
|
+
exports["default"] = _default;
|
package/es/toggleBlockStyle.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
9
|
+
|
|
10
|
+
var _immutable = require("immutable");
|
|
5
11
|
|
|
6
12
|
var toggleBlockStyle = function toggleBlockStyle(editorState, _ref) {
|
|
7
13
|
var blockStyle = _ref.type,
|
|
@@ -10,16 +16,20 @@ var toggleBlockStyle = function toggleBlockStyle(editorState, _ref) {
|
|
|
10
16
|
/* istanbul ignore else */
|
|
11
17
|
if (data) {
|
|
12
18
|
var selection = editorState.getSelection();
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
19
|
+
|
|
20
|
+
var newContentState = _draftJs.Modifier.mergeBlockData(editorState.getCurrentContent(), selection, (0, _immutable.Map)(data));
|
|
21
|
+
|
|
22
|
+
var newEditorState = _draftJs.EditorState.push(editorState, newContentState, 'change-block-data');
|
|
23
|
+
|
|
24
|
+
return _draftJs.RichUtils.toggleBlockType(newEditorState, blockStyle);
|
|
16
25
|
} // We currently always have data, but just in case we add new types in the
|
|
17
26
|
// future, the default action is to just blindly toggle it.
|
|
18
27
|
|
|
19
28
|
/* istanbul ignore next */
|
|
20
29
|
|
|
21
30
|
|
|
22
|
-
return RichUtils.toggleBlockType(editorState, blockStyle);
|
|
31
|
+
return _draftJs.RichUtils.toggleBlockType(editorState, blockStyle);
|
|
23
32
|
};
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
var _default = toggleBlockStyle;
|
|
35
|
+
exports["default"] = _default;
|
package/es/toggleBlockType.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var toggleBlockType = function toggleBlockType(editorState, blockType) {
|
|
4
|
-
return RichUtils.toggleBlockType(editorState, blockType);
|
|
11
|
+
return _draftJs.RichUtils.toggleBlockType(editorState, blockType);
|
|
5
12
|
};
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
var _default = toggleBlockType;
|
|
15
|
+
exports["default"] = _default;
|
package/es/toggleEntity.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var toggleEntity = function toggleEntity(editorState, entityKey) {
|
|
4
|
-
return RichUtils.toggleLink(editorState, editorState.getSelection(), entityKey);
|
|
11
|
+
return _draftJs.RichUtils.toggleLink(editorState, editorState.getSelection(), entityKey);
|
|
5
12
|
};
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
var _default = toggleEntity;
|
|
15
|
+
exports["default"] = _default;
|
package/es/toggleInlineStyle.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _draftJs = require("draft-js");
|
|
2
9
|
|
|
3
10
|
var toggleInlineStyle = function toggleInlineStyle(editorState, inlineStyle) {
|
|
4
|
-
return RichUtils.toggleInlineStyle(editorState, inlineStyle);
|
|
11
|
+
return _draftJs.RichUtils.toggleInlineStyle(editorState, inlineStyle);
|
|
5
12
|
};
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
var _default = toggleInlineStyle;
|
|
15
|
+
exports["default"] = _default;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
1
8
|
var getCurrentBlock = function getCurrentBlock(editorState) {
|
|
2
9
|
var selection = editorState.getSelection();
|
|
3
10
|
return editorState.getCurrentContent().getBlockForKey(selection.getStartKey());
|
|
4
11
|
};
|
|
5
12
|
|
|
6
|
-
|
|
13
|
+
var _default = getCurrentBlock;
|
|
14
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.flatten = exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _ = require(".");
|
|
9
|
+
|
|
10
|
+
var flatten = function flatten(arr) {
|
|
11
|
+
return arr.reduce(function (a, b) {
|
|
12
|
+
return a.concat(b);
|
|
13
|
+
}, []);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.flatten = flatten;
|
|
17
|
+
|
|
18
|
+
var getAllEntities = function getAllEntities(editorState) {
|
|
19
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
20
|
+
var content = editorState.getCurrentContent();
|
|
21
|
+
var entities = [];
|
|
22
|
+
content.getBlocksAsArray().forEach(function (contentBlock) {
|
|
23
|
+
entities.push((0, _.getEntitiesForBlock)(editorState, contentBlock, type));
|
|
24
|
+
});
|
|
25
|
+
return flatten(entities);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var _default = getAllEntities;
|
|
29
|
+
exports["default"] = _default;
|