@kids-reporter/draft-editor 1.0.32 → 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.
@@ -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
- onChange(_draftJs.RichUtils.toggleLink(newEditorState, newEditorState.getSelection(), entityKey));
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
  };
@@ -9,20 +9,29 @@ var _jsxRuntime = require("react/jsx-runtime");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  const Wrapper = _styledComponents.default.span`
11
11
  display: inline;
12
+ padding-right: 1.25em;
12
13
  color: #8e8e8e;
13
14
  `;
14
- const EditButton = _styledComponents.default.div`
15
- display: inline;
15
+ const EditButton = _styledComponents.default.span`
16
+ position: absolute;
17
+ right: -20px;
16
18
  cursor: pointer;
17
- padding-left: 2px;
18
- padding-right: 2px;
19
+ user-select: none;
20
+ `;
21
+ const IconAnchor = _styledComponents.default.span`
22
+ display: inline;
23
+ position: relative;
19
24
  `;
20
25
  const EditableWrapper = props => {
21
26
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Wrapper, {
22
- children: [props.component, /*#__PURE__*/(0, _jsxRuntime.jsx)(EditButton, {
23
- onClick: props.onClick,
24
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
25
- className: "fas fa-pen"
27
+ children: [props.component, /*#__PURE__*/(0, _jsxRuntime.jsx)(IconAnchor, {
28
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(EditButton, {
29
+ contentEditable: false,
30
+ onMouseDown: e => e.preventDefault(),
31
+ onClick: props.onClick,
32
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("i", {
33
+ className: "fas fa-pen"
34
+ })
26
35
  })
27
36
  })]
28
37
  });
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kids-reporter/draft-editor",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {