@studysync/draft-js-modifiers 0.3.3 → 0.3.4
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/getEntitiesForSelection.js +31 -0
- package/es/index.js +8 -0
- package/es/utils/numbers.js +18 -0
- package/getEntitiesForSelection.js +31 -0
- package/index.js +8 -0
- package/package.json +1 -1
- package/utils/numbers.js +18 -0
|
@@ -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 _ = require(".");
|
|
9
|
+
|
|
10
|
+
var _numbers = require("./utils/numbers");
|
|
11
|
+
|
|
12
|
+
var getEntitiesForCurrentBlock = function getEntitiesForCurrentBlock(editorState) {
|
|
13
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
14
|
+
return (0, _.getEntitiesForBlock)(editorState, (0, _.getCurrentBlock)(editorState), type);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var getEntitiesForSelection = function getEntitiesForSelection(editorState) {
|
|
18
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
19
|
+
var entities = getEntitiesForCurrentBlock(editorState, type);
|
|
20
|
+
var selection = editorState.getSelection();
|
|
21
|
+
var selectionStart = selection.isCollapsed() ? selection.getStartOffset() - 1 : selection.getStartOffset();
|
|
22
|
+
var selectionEnd = selection.getEndOffset();
|
|
23
|
+
return entities.filter(function (_ref) {
|
|
24
|
+
var start = _ref.start,
|
|
25
|
+
end = _ref.end;
|
|
26
|
+
return (0, _numbers.rangesOverlap)(selectionStart, selectionEnd, start, end);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var _default = getEntitiesForSelection;
|
|
31
|
+
exports["default"] = _default;
|
package/es/index.js
CHANGED
|
@@ -34,6 +34,12 @@ Object.defineProperty(exports, "getEntitiesForBlock", {
|
|
|
34
34
|
return _getEntitiesForBlock["default"];
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
+
Object.defineProperty(exports, "getEntitiesForSelection", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _getEntitiesForSelection["default"];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
37
43
|
Object.defineProperty(exports, "getSelectedText", {
|
|
38
44
|
enumerable: true,
|
|
39
45
|
get: function get() {
|
|
@@ -189,6 +195,8 @@ var _getCurrentBlock = _interopRequireDefault(require("./utils/getCurrentBlock")
|
|
|
189
195
|
|
|
190
196
|
var _getEntitiesForBlock = _interopRequireDefault(require("./getEntitiesForBlock"));
|
|
191
197
|
|
|
198
|
+
var _getEntitiesForSelection = _interopRequireDefault(require("./getEntitiesForSelection"));
|
|
199
|
+
|
|
192
200
|
var _getSelectedText = _interopRequireDefault(require("./getSelectedText"));
|
|
193
201
|
|
|
194
202
|
var _insertAtomicBlock = _interopRequireDefault(require("./insertAtomicBlock"));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rangesOverlap = exports.fallsWithin = void 0;
|
|
7
|
+
|
|
8
|
+
var fallsWithin = function fallsWithin(value, start, end) {
|
|
9
|
+
return start <= value && value <= end;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.fallsWithin = fallsWithin;
|
|
13
|
+
|
|
14
|
+
var rangesOverlap = function rangesOverlap(s1, e1, s2, e2) {
|
|
15
|
+
return fallsWithin(s2, s1, e1) || fallsWithin(s1, s2, e2);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.rangesOverlap = rangesOverlap;
|
|
@@ -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 _ = require(".");
|
|
9
|
+
|
|
10
|
+
var _numbers = require("./utils/numbers");
|
|
11
|
+
|
|
12
|
+
var getEntitiesForCurrentBlock = function getEntitiesForCurrentBlock(editorState) {
|
|
13
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
14
|
+
return (0, _.getEntitiesForBlock)(editorState, (0, _.getCurrentBlock)(editorState), type);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var getEntitiesForSelection = function getEntitiesForSelection(editorState) {
|
|
18
|
+
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
19
|
+
var entities = getEntitiesForCurrentBlock(editorState, type);
|
|
20
|
+
var selection = editorState.getSelection();
|
|
21
|
+
var selectionStart = selection.isCollapsed() ? selection.getStartOffset() - 1 : selection.getStartOffset();
|
|
22
|
+
var selectionEnd = selection.getEndOffset();
|
|
23
|
+
return entities.filter(function (_ref) {
|
|
24
|
+
var start = _ref.start,
|
|
25
|
+
end = _ref.end;
|
|
26
|
+
return (0, _numbers.rangesOverlap)(selectionStart, selectionEnd, start, end);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var _default = getEntitiesForSelection;
|
|
31
|
+
exports["default"] = _default;
|
package/index.js
CHANGED
|
@@ -34,6 +34,12 @@ Object.defineProperty(exports, "getEntitiesForBlock", {
|
|
|
34
34
|
return _getEntitiesForBlock["default"];
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
+
Object.defineProperty(exports, "getEntitiesForSelection", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function get() {
|
|
40
|
+
return _getEntitiesForSelection["default"];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
37
43
|
Object.defineProperty(exports, "getSelectedText", {
|
|
38
44
|
enumerable: true,
|
|
39
45
|
get: function get() {
|
|
@@ -189,6 +195,8 @@ var _getCurrentBlock = _interopRequireDefault(require("./utils/getCurrentBlock")
|
|
|
189
195
|
|
|
190
196
|
var _getEntitiesForBlock = _interopRequireDefault(require("./getEntitiesForBlock"));
|
|
191
197
|
|
|
198
|
+
var _getEntitiesForSelection = _interopRequireDefault(require("./getEntitiesForSelection"));
|
|
199
|
+
|
|
192
200
|
var _getSelectedText = _interopRequireDefault(require("./getSelectedText"));
|
|
193
201
|
|
|
194
202
|
var _insertAtomicBlock = _interopRequireDefault(require("./insertAtomicBlock"));
|
package/package.json
CHANGED
package/utils/numbers.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rangesOverlap = exports.fallsWithin = void 0;
|
|
7
|
+
|
|
8
|
+
var fallsWithin = function fallsWithin(value, start, end) {
|
|
9
|
+
return start <= value && value <= end;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.fallsWithin = fallsWithin;
|
|
13
|
+
|
|
14
|
+
var rangesOverlap = function rangesOverlap(s1, e1, s2, e2) {
|
|
15
|
+
return fallsWithin(s2, s1, e1) || fallsWithin(s1, s2, e2);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.rangesOverlap = rangesOverlap;
|