@kids-reporter/draft-editor 1.0.33 → 1.0.34
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/lib/buttons/link.js
CHANGED
|
@@ -8,6 +8,7 @@ var _draftRenderer = require("@kids-reporter/draft-renderer");
|
|
|
8
8
|
var _draftJs = require("draft-js");
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _link = require("../entity-decorators/link");
|
|
11
|
+
var _linkTrailingBuffer = require("../utils/link-trailing-buffer");
|
|
11
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
13
|
const LinkButton = props => {
|
|
13
14
|
const {
|
|
@@ -33,7 +34,9 @@ const LinkButton = props => {
|
|
|
33
34
|
const newEditorState = _draftJs.EditorState.set(editorState, {
|
|
34
35
|
currentContent: contentStateWithEntity
|
|
35
36
|
});
|
|
36
|
-
|
|
37
|
+
let next = _draftJs.RichUtils.toggleLink(newEditorState, newEditorState.getSelection(), entityKey);
|
|
38
|
+
next = (0, _linkTrailingBuffer.appendLinkCreateTrailingBuffer)(next);
|
|
39
|
+
onChange(next);
|
|
37
40
|
setToShowUrlInput(false);
|
|
38
41
|
props.onEditFinish();
|
|
39
42
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.appendLinkCreateTrailingBuffer = appendLinkCreateTrailingBuffer;
|
|
7
|
+
var _draftJs = require("draft-js");
|
|
8
|
+
/** Draft has no zero-length entity; ZWSP gives a neutral tail after a new link. */
|
|
9
|
+
const LINK_TRAILING_BUFFER = '\u200b';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* After toggleLink, collapse to range end and insert a zero-width buffer
|
|
13
|
+
* without link entity so IME / typing can continue outside the link span.
|
|
14
|
+
*/
|
|
15
|
+
function appendLinkCreateTrailingBuffer(editorState) {
|
|
16
|
+
const sel = editorState.getSelection();
|
|
17
|
+
const collapsed = sel.merge({
|
|
18
|
+
anchorKey: sel.getEndKey(),
|
|
19
|
+
anchorOffset: sel.getEndOffset(),
|
|
20
|
+
focusKey: sel.getEndKey(),
|
|
21
|
+
focusOffset: sel.getEndOffset(),
|
|
22
|
+
isBackward: false
|
|
23
|
+
});
|
|
24
|
+
const withSelection = _draftJs.EditorState.acceptSelection(editorState, collapsed);
|
|
25
|
+
const content = _draftJs.Modifier.insertText(withSelection.getCurrentContent(), withSelection.getSelection(), LINK_TRAILING_BUFFER, withSelection.getCurrentInlineStyle(), undefined);
|
|
26
|
+
return _draftJs.EditorState.push(withSelection, content, 'insert-characters');
|
|
27
|
+
}
|