@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/removeEntity.js
ADDED
|
@@ -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/removeInlineStyles.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
10
10
|
var _getCurrentBlock = _interopRequireDefault(require("./utils/getCurrentBlock"));
|
|
11
11
|
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
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; }
|
|
15
15
|
|
|
@@ -20,7 +20,7 @@ var removeInlineStyles = function removeInlineStyles(editorState) {
|
|
|
20
20
|
var newContent;
|
|
21
21
|
|
|
22
22
|
if (selection.isCollapsed()) {
|
|
23
|
-
var block = (0, _getCurrentBlock
|
|
23
|
+
var block = (0, _getCurrentBlock["default"])(editorState);
|
|
24
24
|
var updatedCharacterList = block.getCharacterList().map(function (c) {
|
|
25
25
|
return inlineStyles.reduce(function (characterMetadata, style) {
|
|
26
26
|
return _draftJs.CharacterMetadata.removeStyle(characterMetadata, style);
|
|
@@ -40,4 +40,4 @@ var removeInlineStyles = function removeInlineStyles(editorState) {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
var _default = removeInlineStyles;
|
|
43
|
-
exports
|
|
43
|
+
exports["default"] = _default;
|
package/resetBlock.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
@@ -30,4 +30,4 @@ var resetBlock = function resetBlock(editorState, block) {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
var _default = resetBlock;
|
|
33
|
-
exports
|
|
33
|
+
exports["default"] = _default;
|
package/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/selectBlockByKey.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
@@ -22,4 +22,4 @@ var selectBlockByKey = function selectBlockByKey(editorState, key) {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
var _default = selectBlockByKey;
|
|
25
|
-
exports
|
|
25
|
+
exports["default"] = _default;
|
package/toggleBlockStyle.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
@@ -32,4 +32,4 @@ var toggleBlockStyle = function toggleBlockStyle(editorState, _ref) {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
var _default = toggleBlockStyle;
|
|
35
|
-
exports
|
|
35
|
+
exports["default"] = _default;
|
package/toggleBlockType.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
@@ -12,4 +12,4 @@ var toggleBlockType = function toggleBlockType(editorState, blockType) {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
var _default = toggleBlockType;
|
|
15
|
-
exports
|
|
15
|
+
exports["default"] = _default;
|
package/toggleEntity.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
@@ -12,4 +12,4 @@ var toggleEntity = function toggleEntity(editorState, entityKey) {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
var _default = toggleEntity;
|
|
15
|
-
exports
|
|
15
|
+
exports["default"] = _default;
|
package/toggleInlineStyle.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
|
|
@@ -12,4 +12,4 @@ var toggleInlineStyle = function toggleInlineStyle(editorState, inlineStyle) {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
var _default = toggleInlineStyle;
|
|
15
|
-
exports
|
|
15
|
+
exports["default"] = _default;
|
package/utils/getCurrentBlock.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = void 0;
|
|
7
7
|
|
|
8
8
|
var getCurrentBlock = function getCurrentBlock(editorState) {
|
|
9
9
|
var selection = editorState.getSelection();
|
|
@@ -11,4 +11,4 @@ var getCurrentBlock = function getCurrentBlock(editorState) {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
var _default = getCurrentBlock;
|
|
14
|
-
exports
|
|
14
|
+
exports["default"] = _default;
|
package/es/getCurrentBlock.js
DELETED
package/getCurrentBlock.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var getCurrentBlock = function getCurrentBlock(editorState) {
|
|
9
|
-
var currentKey = editorState.getSelection().getAnchorKey();
|
|
10
|
-
return editorState.getCurrentContent().getBlockForKey(currentKey);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
var _default = getCurrentBlock;
|
|
14
|
-
exports.default = _default;
|