@studysync/draft-js-modifiers 0.3.1 → 0.3.5
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/README.md +30 -0
- package/addBlock.js +3 -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/getEntitiesForSelection.js +31 -0
- package/es/getSelectedText.js +19 -0
- package/es/index.js +259 -17
- package/es/insertAtomicBlock.js +11 -3
- package/es/insertBlockAfter.js +70 -0
- 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 +31 -0
- package/es/moveCaretToEnd.js +25 -0
- package/es/removeBlock.js +41 -0
- 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 +25 -0
- package/es/toggleBlockStyle.js +35 -0
- 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/es/utils/numbers.js +18 -0
- package/getAllEntities.js +29 -0
- package/getEntitiesForBlock.js +44 -0
- package/getEntitiesForSelection.js +31 -0
- package/getSelectedText.js +19 -0
- package/index.js +134 -18
- package/insertAtomicBlock.js +2 -2
- package/insertBlockAfter.js +70 -0
- 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 +31 -0
- package/moveCaretToEnd.js +25 -0
- package/package.json +8 -10
- package/removeBlock.js +41 -0
- 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 +25 -0
- package/toggleBlockStyle.js +35 -0
- package/toggleBlockType.js +2 -2
- package/toggleEntity.js +2 -2
- package/toggleInlineStyle.js +2 -2
- package/utils/getCurrentBlock.js +2 -2
- package/utils/numbers.js +18 -0
|
@@ -0,0 +1,70 @@
|
|
|
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 = _interopRequireDefault(require("immutable"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
|
+
|
|
16
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
+
|
|
18
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
+
|
|
20
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
|
|
22
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
23
|
+
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
+
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
27
|
+
|
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
+
|
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
var insertBlockAfter = function insertBlockAfter(editorState, keyBefore, blockParams) {
|
|
35
|
+
var newBlock = new _draftJs.ContentBlock(_objectSpread({
|
|
36
|
+
key: (0, _draftJs.genKey)(),
|
|
37
|
+
type: 'unstyled',
|
|
38
|
+
text: ''
|
|
39
|
+
}, blockParams));
|
|
40
|
+
var contentState = editorState.getCurrentContent();
|
|
41
|
+
var oldBlockMap = contentState.getBlockMap();
|
|
42
|
+
|
|
43
|
+
var newBlockMap = _immutable["default"].OrderedMap().withMutations(function (map) {
|
|
44
|
+
var _iterator = _createForOfIteratorHelper(oldBlockMap.entries()),
|
|
45
|
+
_step;
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
49
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
50
|
+
k = _step$value[0],
|
|
51
|
+
v = _step$value[1];
|
|
52
|
+
|
|
53
|
+
map.set(k, v);
|
|
54
|
+
|
|
55
|
+
if (keyBefore === k) {
|
|
56
|
+
map.set(newBlock.key, newBlock);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
_iterator.e(err);
|
|
61
|
+
} finally {
|
|
62
|
+
_iterator.f();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return _draftJs.EditorState.push(editorState, _draftJs.ContentState.createFromBlockArray(Array.from(newBlockMap.values())).set('selectionBefore', contentState.getSelectionBefore()).set('selectionAfter', contentState.getSelectionAfter()));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
var _default = insertBlockAfter;
|
|
70
|
+
exports["default"] = _default;
|
package/es/insertEmptyBlock.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _insertNewBlock = _interopRequireDefault(require("./insertNewBlock"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
2
11
|
|
|
3
12
|
var insertEmptyBlock = function insertEmptyBlock(editorState) {
|
|
4
13
|
var blockType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unstyled';
|
|
5
|
-
return
|
|
14
|
+
return (0, _insertNewBlock["default"])(editorState, blockType);
|
|
6
15
|
};
|
|
7
16
|
|
|
8
|
-
|
|
17
|
+
var _default = insertEmptyBlock;
|
|
18
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 _ = require(".");
|
|
11
|
+
|
|
12
|
+
var insertEntity = function insertEntity(editorState, text, type, data) {
|
|
13
|
+
var mutability = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'MUTABLE';
|
|
14
|
+
var selectedText = (0, _.getSelectedText)(editorState);
|
|
15
|
+
var contentState = editorState.getCurrentContent();
|
|
16
|
+
var selection = editorState.getSelection();
|
|
17
|
+
var textWithSpace = text.concat(' ');
|
|
18
|
+
var newContent = selectedText ? _draftJs.Modifier.replaceText(contentState, selection, text) : _draftJs.Modifier.insertText(contentState, selection, textWithSpace);
|
|
19
|
+
var newContentWithEntity = newContent.createEntity(type, mutability, data, false);
|
|
20
|
+
var entityKey = newContentWithEntity.getLastCreatedEntityKey();
|
|
21
|
+
var anchorOffset = selection.getAnchorOffset();
|
|
22
|
+
var newSelection = new _draftJs.SelectionState({
|
|
23
|
+
anchorKey: selection.getAnchorKey(),
|
|
24
|
+
anchorOffset: anchorOffset,
|
|
25
|
+
focusKey: selection.getAnchorKey(),
|
|
26
|
+
focusOffset: anchorOffset + text.length
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
var newContentWithLink = _draftJs.Modifier.applyEntity(newContentWithEntity, newSelection, entityKey);
|
|
30
|
+
|
|
31
|
+
var withLinkText = _draftJs.EditorState.push(editorState, newContentWithLink, 'insert-characters');
|
|
32
|
+
|
|
33
|
+
return _draftJs.EditorState.forceSelection(withLinkText, newContent.getSelectionAfter());
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
var _default = insertEntity;
|
|
37
|
+
exports["default"] = _default;
|
package/es/insertNewBlock.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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");
|
|
11
|
+
|
|
12
|
+
var _getCurrentBlock = _interopRequireDefault(require("./utils/getCurrentBlock"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
4
15
|
|
|
5
16
|
var insertNewBlock = function insertNewBlock(editorState) {
|
|
6
17
|
var blockType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'unstyled';
|
|
@@ -8,14 +19,14 @@ var insertNewBlock = function insertNewBlock(editorState) {
|
|
|
8
19
|
var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
9
20
|
var content = editorState.getCurrentContent();
|
|
10
21
|
var selection = editorState.getSelection();
|
|
11
|
-
var currentBlock =
|
|
12
|
-
var emptyBlockKey = genKey();
|
|
13
|
-
var emptyBlock = new ContentBlock({
|
|
22
|
+
var currentBlock = (0, _getCurrentBlock["default"])(editorState);
|
|
23
|
+
var emptyBlockKey = (0, _draftJs.genKey)();
|
|
24
|
+
var emptyBlock = new _draftJs.ContentBlock({
|
|
14
25
|
key: emptyBlockKey,
|
|
15
26
|
type: blockType,
|
|
16
27
|
text: text,
|
|
17
|
-
characterList: List(Repeat(CharacterMetadata.create(), text.length)),
|
|
18
|
-
data: Map().merge(data)
|
|
28
|
+
characterList: (0, _immutable.List)((0, _immutable.Repeat)(_draftJs.CharacterMetadata.create(), text.length)),
|
|
29
|
+
data: (0, _immutable.Map)().merge(data)
|
|
19
30
|
});
|
|
20
31
|
var blockMap = content.getBlockMap();
|
|
21
32
|
var blocksBefore = blockMap.toSeq().takeUntil(function (value) {
|
|
@@ -38,8 +49,11 @@ var insertNewBlock = function insertNewBlock(editorState) {
|
|
|
38
49
|
isBackward: false
|
|
39
50
|
})
|
|
40
51
|
});
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
|
|
53
|
+
var newState = _draftJs.EditorState.push(editorState, newContent, 'split-block');
|
|
54
|
+
|
|
55
|
+
return _draftJs.EditorState.forceSelection(newState, newContent.getSelectionAfter());
|
|
43
56
|
};
|
|
44
57
|
|
|
45
|
-
|
|
58
|
+
var _default = insertNewBlock;
|
|
59
|
+
exports["default"] = _default;
|
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 moveCaretAfterBlock = function moveCaretAfterBlock(editorState, block) {
|
|
11
|
+
var content = editorState.getCurrentContent();
|
|
12
|
+
var nextBlock = content.getBlockAfter(block.getKey());
|
|
13
|
+
var key = nextBlock ? nextBlock.getKey() : undefined;
|
|
14
|
+
|
|
15
|
+
if (key) {
|
|
16
|
+
var selectionState = _draftJs.SelectionState.createEmpty();
|
|
17
|
+
|
|
18
|
+
var newSelectionState = selectionState.merge({
|
|
19
|
+
anchorKey: key,
|
|
20
|
+
anchorOffset: 0,
|
|
21
|
+
focusKey: key,
|
|
22
|
+
focusOffset: 0
|
|
23
|
+
});
|
|
24
|
+
return _draftJs.EditorState.forceSelection(editorState, newSelectionState);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return editorState;
|
|
28
|
+
};
|
|
29
|
+
|
|
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;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
// from draft-js-plugins/draft-js-plugins/packages/drag-n-drop/src/modifiers/addBlock.ts
|
|
11
|
+
var removeBlock = function removeBlock(contentState, blockKey) {
|
|
12
|
+
var afterKey = contentState.getKeyAfter(blockKey);
|
|
13
|
+
var afterBlock = contentState.getBlockForKey(afterKey);
|
|
14
|
+
var targetRange; // Only if the following block the last with no text then the whole block
|
|
15
|
+
// should be removed. Otherwise the block should be reduced to an unstyled block
|
|
16
|
+
// without any characters.
|
|
17
|
+
|
|
18
|
+
if (afterBlock && afterBlock.getType() === 'unstyled' && afterBlock.getLength() === 0 && afterBlock === contentState.getBlockMap().last()) {
|
|
19
|
+
targetRange = new _draftJs.SelectionState({
|
|
20
|
+
anchorKey: blockKey,
|
|
21
|
+
anchorOffset: 0,
|
|
22
|
+
focusKey: afterKey,
|
|
23
|
+
focusOffset: 0
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
targetRange = new _draftJs.SelectionState({
|
|
27
|
+
anchorKey: blockKey,
|
|
28
|
+
anchorOffset: 0,
|
|
29
|
+
focusKey: blockKey,
|
|
30
|
+
focusOffset: 1
|
|
31
|
+
});
|
|
32
|
+
} // change the blocktype and remove the characterList entry with the block
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var newContentState = _draftJs.Modifier.setBlockType(contentState, targetRange, 'unstyled');
|
|
36
|
+
|
|
37
|
+
return _draftJs.Modifier.removeRange(newContentState, targetRange, 'backward');
|
|
38
|
+
};
|
|
39
|
+
|
|
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;
|
|
@@ -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 selectBlockByKey = function selectBlockByKey(editorState, key) {
|
|
11
|
+
var currentBlock = editorState.getCurrentContent().getBlockForKey(key);
|
|
12
|
+
|
|
13
|
+
var selectionState = _draftJs.SelectionState.createEmpty();
|
|
14
|
+
|
|
15
|
+
var entireBlockSelectionState = selectionState.merge({
|
|
16
|
+
anchorKey: key,
|
|
17
|
+
anchorOffset: 0,
|
|
18
|
+
focusKey: key,
|
|
19
|
+
focusOffset: currentBlock.getText().length
|
|
20
|
+
});
|
|
21
|
+
return _draftJs.EditorState.forceSelection(editorState, entireBlockSelectionState);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var _default = selectBlockByKey;
|
|
25
|
+
exports["default"] = _default;
|