@seafile/sdoc-editor 0.4.18 → 0.4.19

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.
@@ -68,14 +68,16 @@ const FileLink = _ref => {
68
68
  // eslint-disable-next-line react-hooks/exhaustive-deps
69
69
  }, [isShowInsertHoverMenu]);
70
70
  const onClickFile = useCallback(e => {
71
- e.stopPropagation();
71
+ if (isShowInsertHoverMenu) {
72
+ e.stopPropagation();
73
+ }
72
74
  setPosition(e.currentTarget);
73
75
  setIsShowInsertHoverMenu(true);
74
76
  setTimeout(() => {
75
77
  registerEventHandle();
76
78
  }, 0);
77
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
78
- }, []);
80
+ }, [isShowInsertHoverMenu]);
79
81
  const onHideInsertHoverMenu = useCallback(e => {
80
82
  setIsShowInsertHoverMenu(false);
81
83
  unregisterEventHandle();
@@ -1,7 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useCallback, useEffect, useState, useRef } from 'react';
3
- import { Range } from '@seafile/slate';
4
- import { useReadOnly } from '@seafile/slate-react';
3
+ import { Range, Transforms } from '@seafile/slate';
4
+ import { ReactEditor, useReadOnly } from '@seafile/slate-react';
5
5
  import { useScrollContext } from '../../../hooks/use-scroll-context';
6
6
  import { unwrapLinkNode, getUrl } from './helpers';
7
7
  import HoverMenu from './hover-menu';
@@ -70,14 +70,27 @@ const SdocFileLink = _ref => {
70
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
71
  }, [isShowInsertHoverMenu]);
72
72
  const onClickFile = useCallback(e => {
73
- e.stopPropagation();
73
+ if (isShowInsertHoverMenu) {
74
+ e.stopPropagation();
75
+ }
76
+ const path = ReactEditor.findPath(editor, element);
77
+ Transforms.setSelection(editor, {
78
+ anchor: {
79
+ offset: 1,
80
+ path: [path[0], path[1], 0]
81
+ },
82
+ focus: {
83
+ offset: 1,
84
+ path: [path[0], path[1], 0]
85
+ }
86
+ });
74
87
  setPosition(e.currentTarget);
75
88
  setIsShowInsertHoverMenu(true);
76
89
  setTimeout(() => {
77
90
  registerEventHandle();
78
91
  }, 0);
79
92
  // eslint-disable-next-line react-hooks/exhaustive-deps
80
- }, []);
93
+ }, [isShowInsertHoverMenu]);
81
94
  const onHideInsertHoverMenu = useCallback(e => {
82
95
  setIsShowInsertHoverMenu(false);
83
96
  unregisterEventHandle();
@@ -118,7 +131,7 @@ const SdocFileLink = _ref => {
118
131
  e.preventDefault();
119
132
  },
120
133
  title: element.title
121
- }, children))), isShowInsertHoverMenu && (!readOnly && Range.isCollapsed(editor.selection) || readOnly) && /*#__PURE__*/React.createElement(HoverMenu, {
134
+ }, children))), isShowInsertHoverMenu && !readOnly && editor.selection && Range.isCollapsed(editor.selection) && /*#__PURE__*/React.createElement(HoverMenu, {
122
135
  editor: editor,
123
136
  menuPosition: menuPosition,
124
137
  element: element,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.18",
3
+ "version": "0.4.19",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",