@studysync/draft-js-modifiers 0.4.5 → 0.4.6
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/es/getSimilarAdjacentBlocks.js +66 -0
- package/es/index.js +8 -0
- package/getSimilarAdjacentBlocks.js +66 -0
- package/index.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
|
|
12
|
+
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); }
|
|
13
|
+
|
|
14
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
15
|
+
|
|
16
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
var getSimilarAdjacentBlocks = function getSimilarAdjacentBlocks(editorState, block) {
|
|
21
|
+
var blockType = block.getType();
|
|
22
|
+
var depth = block.getDepth();
|
|
23
|
+
var variant = block.getData().get('variant');
|
|
24
|
+
var contentState = editorState.getCurrentContent();
|
|
25
|
+
|
|
26
|
+
var matches = function matches(aBlock) {
|
|
27
|
+
return aBlock.getType() === blockType && aBlock.getDepth() === depth && aBlock.getData().get('variant') === variant;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var before = [];
|
|
31
|
+
var after = [];
|
|
32
|
+
var cursor = block;
|
|
33
|
+
|
|
34
|
+
while (cursor) {
|
|
35
|
+
var prev = contentState.getBlockBefore(cursor.getKey());
|
|
36
|
+
|
|
37
|
+
if (matches(prev)) {
|
|
38
|
+
before.push(prev);
|
|
39
|
+
cursor = prev;
|
|
40
|
+
} else {
|
|
41
|
+
cursor = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cursor = block;
|
|
46
|
+
|
|
47
|
+
while (cursor) {
|
|
48
|
+
var next = contentState.getBlockAfter(cursor.getKey());
|
|
49
|
+
|
|
50
|
+
if (matches(next)) {
|
|
51
|
+
after.push(next);
|
|
52
|
+
cursor = next;
|
|
53
|
+
} else {
|
|
54
|
+
cursor = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
before: before.reverse(),
|
|
60
|
+
after: after,
|
|
61
|
+
all: [].concat(_toConsumableArray(before.reverse()), [block], after)
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var _default = getSimilarAdjacentBlocks;
|
|
66
|
+
exports["default"] = _default;
|
package/es/index.js
CHANGED
|
@@ -64,6 +64,12 @@ Object.defineProperty(exports, "getSelectedText", {
|
|
|
64
64
|
return _getSelectedText["default"];
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
+
Object.defineProperty(exports, "getSimilarAdjacentBlocks", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function get() {
|
|
70
|
+
return _getSimilarAdjacentBlocks["default"];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
67
73
|
Object.defineProperty(exports, "insertAtomicBlock", {
|
|
68
74
|
enumerable: true,
|
|
69
75
|
get: function get() {
|
|
@@ -241,6 +247,8 @@ var _getEntitiesForSelection = _interopRequireDefault(require("./getEntitiesForS
|
|
|
241
247
|
|
|
242
248
|
var _getSelectedText = _interopRequireDefault(require("./getSelectedText"));
|
|
243
249
|
|
|
250
|
+
var _getSimilarAdjacentBlocks = _interopRequireDefault(require("./getSimilarAdjacentBlocks"));
|
|
251
|
+
|
|
244
252
|
var _insertAtomicBlock = _interopRequireDefault(require("./insertAtomicBlock"));
|
|
245
253
|
|
|
246
254
|
var _insertBlockAfter = _interopRequireDefault(require("./insertBlockAfter"));
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
|
|
10
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
|
|
12
|
+
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); }
|
|
13
|
+
|
|
14
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
15
|
+
|
|
16
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
var getSimilarAdjacentBlocks = function getSimilarAdjacentBlocks(editorState, block) {
|
|
21
|
+
var blockType = block.getType();
|
|
22
|
+
var depth = block.getDepth();
|
|
23
|
+
var variant = block.getData().get('variant');
|
|
24
|
+
var contentState = editorState.getCurrentContent();
|
|
25
|
+
|
|
26
|
+
var matches = function matches(aBlock) {
|
|
27
|
+
return aBlock.getType() === blockType && aBlock.getDepth() === depth && aBlock.getData().get('variant') === variant;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var before = [];
|
|
31
|
+
var after = [];
|
|
32
|
+
var cursor = block;
|
|
33
|
+
|
|
34
|
+
while (cursor) {
|
|
35
|
+
var prev = contentState.getBlockBefore(cursor.getKey());
|
|
36
|
+
|
|
37
|
+
if (matches(prev)) {
|
|
38
|
+
before.push(prev);
|
|
39
|
+
cursor = prev;
|
|
40
|
+
} else {
|
|
41
|
+
cursor = null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cursor = block;
|
|
46
|
+
|
|
47
|
+
while (cursor) {
|
|
48
|
+
var next = contentState.getBlockAfter(cursor.getKey());
|
|
49
|
+
|
|
50
|
+
if (matches(next)) {
|
|
51
|
+
after.push(next);
|
|
52
|
+
cursor = next;
|
|
53
|
+
} else {
|
|
54
|
+
cursor = null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
before: before.reverse(),
|
|
60
|
+
after: after,
|
|
61
|
+
all: [].concat(_toConsumableArray(before.reverse()), [block], after)
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var _default = getSimilarAdjacentBlocks;
|
|
66
|
+
exports["default"] = _default;
|
package/index.js
CHANGED
|
@@ -64,6 +64,12 @@ Object.defineProperty(exports, "getSelectedText", {
|
|
|
64
64
|
return _getSelectedText["default"];
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
|
+
Object.defineProperty(exports, "getSimilarAdjacentBlocks", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function get() {
|
|
70
|
+
return _getSimilarAdjacentBlocks["default"];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
67
73
|
Object.defineProperty(exports, "insertAtomicBlock", {
|
|
68
74
|
enumerable: true,
|
|
69
75
|
get: function get() {
|
|
@@ -241,6 +247,8 @@ var _getEntitiesForSelection = _interopRequireDefault(require("./getEntitiesForS
|
|
|
241
247
|
|
|
242
248
|
var _getSelectedText = _interopRequireDefault(require("./getSelectedText"));
|
|
243
249
|
|
|
250
|
+
var _getSimilarAdjacentBlocks = _interopRequireDefault(require("./getSimilarAdjacentBlocks"));
|
|
251
|
+
|
|
244
252
|
var _insertAtomicBlock = _interopRequireDefault(require("./insertAtomicBlock"));
|
|
245
253
|
|
|
246
254
|
var _insertBlockAfter = _interopRequireDefault(require("./insertBlockAfter"));
|