@seafile/sdoc-editor 0.5.43 → 0.5.44

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.
@@ -1,6 +1,7 @@
1
- import React, { Fragment, useCallback, useState } from 'react';
1
+ import React, { Fragment, useCallback, useState, useMemo } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Alert, Label } from 'reactstrap';
4
+ import { getEditorString } from '../../../../core';
4
5
  import { insertLink, updateLink, checkLink } from '../../helpers';
5
6
  const AddLinkDialog = _ref => {
6
7
  let {
@@ -23,7 +24,8 @@ const AddLinkDialog = _ref => {
23
24
  title: '',
24
25
  href: ''
25
26
  };
26
- const [title, setTitle] = useState(oldTitle);
27
+ const initTitle = useMemo(() => oldTitle ? oldTitle : getEditorString(editor, editor.selection), [editor, oldTitle]);
28
+ const [title, setTitle] = useState(initTitle);
27
29
  const [url, setURL] = useState(oldURL);
28
30
  const submit = useCallback(() => {
29
31
  setLinkErrorMessage('');
@@ -43,21 +43,15 @@ const getBeforeText = editor => {
43
43
  range: null
44
44
  };
45
45
  const {
46
- anchor
46
+ anchor,
47
+ focus
47
48
  } = selection;
48
- // Find the block element above the current text
49
- const block = Editor.above(editor, {
50
- match: n => Editor.isBlock(editor, n)
51
- });
52
- if (block == null) return {
53
- beforeText: '',
54
- range: null
55
- };
56
- const blockPath = block[1];
57
- const blockStart = Editor.start(editor, blockPath); // The starting position of the block element
58
49
  const range = {
59
50
  anchor,
60
- focus: blockStart
51
+ focus: {
52
+ path: focus.path,
53
+ offset: 0
54
+ }
61
55
  };
62
56
  const beforeText = Editor.string(editor, range) || '';
63
57
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.43",
3
+ "version": "0.5.44",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",