@seafile/sdoc-editor 1.0.28 → 1.0.30

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.
@@ -2,6 +2,7 @@ import { Editor, Node, Path, Transforms } from '@seafile/slate';
2
2
  import { CALL_OUT, PARAGRAPH } from '../../constants/element-type';
3
3
  import { focusEditor, generateEmptyElement, getSelectedElems, isRangeAcrossBlocks } from '../../core';
4
4
  import { CALLOUT_ALLOWED_INSIDE_TYPES, CALLOUT_COLOR_MAP } from './constant';
5
+ import { DOCUMENT_PLUGIN_EDITOR } from '../../../constants';
5
6
  export const isMenuActive = editor => {
6
7
  const {
7
8
  selection
@@ -124,4 +125,20 @@ export const insertElementAtNewLineInCallout = (editor, type, currentPath) => {
124
125
  at: insertPath
125
126
  });
126
127
  Transforms.select(editor, insertPath);
128
+ };
129
+ export const getCalloutMenuPosition = (element, editor) => {
130
+ const {
131
+ top,
132
+ left
133
+ } = element.getBoundingClientRect();
134
+ const menuTop = top - 42; // top = top distance - menu height
135
+ const newMenuPosition = {
136
+ top: menuTop,
137
+ left: left // left = callout left distance
138
+ };
139
+ // 201 is distance with browser top
140
+ if (editor.editorType === DOCUMENT_PLUGIN_EDITOR && menuTop < 201) {
141
+ newMenuPosition['display'] = 'none';
142
+ }
143
+ return newMenuPosition;
127
144
  };
@@ -7,6 +7,7 @@ import { CALLOUT_COLOR_MAP, CALLOUT_ICON_MAP } from '../constant';
7
7
  import { INTERNAL_EVENT } from '../../../../constants';
8
8
  import EventBus from '../../../../utils/event-bus';
9
9
  import { useScrollContext } from '../../../../hooks/use-scroll-context';
10
+ import { getCalloutMenuPosition } from '../helper';
10
11
  import CalloutHoverMenu from './callout-hover-menu';
11
12
  import './index.css';
12
13
  const renderCallout = (_ref, editor) => {
@@ -63,22 +64,10 @@ const renderCallout = (_ref, editor) => {
63
64
  if (readOnly) return;
64
65
  if (!isShowColorSelector) return;
65
66
  if (e.currentTarget.scrollTop) {
66
- const {
67
- top,
68
- left
69
- } = calloutRef.current.getBoundingClientRect();
70
- const menuTop = top - 36; // top = top distance - menu height
71
- const newMenuPosition = {
72
- top: menuTop,
73
- left: left // left = code-block left distance
74
- };
75
- // 165 is distance with browser top
76
- if (menuTop < 165) {
77
- newMenuPosition['display'] = 'none';
78
- }
79
- setPopoverPosition(newMenuPosition);
67
+ const menuPosition = getCalloutMenuPosition(calloutRef.current, editor);
68
+ setPopoverPosition(menuPosition);
80
69
  }
81
- }, [isShowColorSelector, readOnly]);
70
+ }, [editor, isShowColorSelector, readOnly]);
82
71
  useEffect(() => {
83
72
  const eventBus = EventBus.getInstance();
84
73
  const unsubscribe = eventBus.subscribe(INTERNAL_EVENT.CLOSE_CALLOUT_COLOR_PICKER, handleCloseColorSelector);
@@ -102,22 +91,10 @@ const renderCallout = (_ref, editor) => {
102
91
  }, [isSelected]);
103
92
  const handleDisplayColorSelector = useCallback(() => {
104
93
  if (readOnly) return;
105
- const {
106
- top,
107
- left
108
- } = calloutRef.current.getBoundingClientRect();
109
- const menuTop = top - 42; // top = top distance - menu height
110
- const newMenuPosition = {
111
- top: menuTop,
112
- left: left // left = callout left distance
113
- };
114
- // 165 is distance with browser top
115
- if (menuTop < 165) {
116
- newMenuPosition['display'] = 'none';
117
- }
118
- setPopoverPosition(newMenuPosition);
94
+ const menuPosition = getCalloutMenuPosition(calloutRef.current, editor);
95
+ setPopoverPosition(menuPosition);
119
96
  setIsShowColorSelector(true);
120
- }, [readOnly]);
97
+ }, [editor, readOnly]);
121
98
  const handleClick = useCallback(e => {
122
99
  handleDisplayColorSelector();
123
100
  }, [handleDisplayColorSelector]);
@@ -183,4 +183,20 @@ export const isWeChat = () => {
183
183
  let isWeChat = ua.match(/MicroMessenger/i) === 'micromessenger';
184
184
  let isEnterpriseWeChat = ua.match(/MicroMessenger/i) === 'micromessenger' && ua.match(/wxwork/i) === 'wxwork';
185
185
  return isEnterpriseWeChat || isWeChat;
186
+ };
187
+ export const getMenuPosition = element => {
188
+ if (!element) return {};
189
+ const {
190
+ top,
191
+ left,
192
+ width
193
+ } = element.getBoundingClientRect();
194
+ // top = top distance - menu height
195
+ const menuTop = top - 42;
196
+ // left = left distance - (menu width / 2) + (link with / 2)
197
+ const menuLeft = left - 140 / 2 + width / 2;
198
+ return {
199
+ top: menuTop,
200
+ left: menuLeft
201
+ };
186
202
  };
@@ -7,7 +7,7 @@
7
7
  border: 1px solid #e5e5e5;
8
8
  border-radius: 3px;
9
9
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
10
- z-index: 1000;
10
+ z-index: 101;
11
11
  }
12
12
 
13
13
  .link-op-menu .link-op-menu-triangle {
@@ -3,7 +3,7 @@ import { createPortal } from 'react-dom';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import { useReadOnly } from '@seafile/slate-react';
5
5
  import { isWeChat } from '../helpers';
6
- import '../../../../assets/css/textlink-hovermenu.css';
6
+ import './index.css';
7
7
  const LinkHover = _ref => {
8
8
  let {
9
9
  editor,
@@ -1,20 +1,33 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import React from 'react';
3
3
  import { Range } from '@seafile/slate';
4
- import { unWrapLinkNode } from './helpers';
4
+ import { getMenuPosition, unWrapLinkNode } from './helpers';
5
5
  import LinkHover from './hover';
6
6
  import EventBus from '../../../utils/event-bus';
7
- import { INTERNAL_EVENT } from '../../../constants';
7
+ import { DOCUMENT_PLUGIN_EDITOR, INTERNAL_EVENT } from '../../../constants';
8
8
  import { ELEMENT_TYPE } from '../../constants';
9
9
  import InlineBugFixer from '../../commons/Inline-bug-fix-wrapper';
10
- class LinkHoverMenuComponent extends React.Component {
10
+ import { ScrollContext } from '../../../hooks/use-scroll-context';
11
+ class Link extends React.Component {
11
12
  constructor(props) {
12
13
  super(props);
13
14
  _defineProperty(this, "registerEventHandle", () => {
14
15
  document.addEventListener('click', this.onHideLinkMenu);
16
+ const {
17
+ scrollRef
18
+ } = this.context;
19
+ if (scrollRef.current) {
20
+ scrollRef.current.addEventListener('scroll', this.onScroll);
21
+ }
15
22
  });
16
23
  _defineProperty(this, "unregisterEventHandle", () => {
17
24
  document.removeEventListener('click', this.onHideLinkMenu);
25
+ const {
26
+ scrollRef
27
+ } = this.context;
28
+ if (scrollRef.current) {
29
+ scrollRef.current.addEventListener('scroll', this.onScroll);
30
+ }
18
31
  });
19
32
  _defineProperty(this, "onHideLinkMenu", () => {
20
33
  this.setState({
@@ -23,22 +36,25 @@ class LinkHoverMenuComponent extends React.Component {
23
36
  this.unregisterEventHandle();
24
37
  });
25
38
  });
26
- _defineProperty(this, "onLinkClick", e => {
39
+ _defineProperty(this, "onScroll", e => {
40
+ this.setPosition(this.linkRef);
41
+ });
42
+ _defineProperty(this, "setPosition", element => {
27
43
  const {
28
- top,
29
- left,
30
- width
31
- } = e.target.getBoundingClientRect();
32
- // top = top distance - menu height
33
- const menuTop = top - 42;
34
- // left = left distance - (menu width / 2) + (link with / 2)
35
- const menuLeft = left - 140 / 2 + width / 2;
44
+ editor
45
+ } = this.props;
46
+ const menuPosition = getMenuPosition(element);
47
+ if (editor.editorType === DOCUMENT_PLUGIN_EDITOR && menuPosition.top < 201) {
48
+ menuPosition['display'] = 'none';
49
+ }
36
50
  this.setState({
37
- isShowLinkMenu: true,
38
- menuPosition: {
39
- top: menuTop,
40
- left: menuLeft
41
- }
51
+ menuPosition
52
+ });
53
+ });
54
+ _defineProperty(this, "onLinkClick", e => {
55
+ this.setPosition(e.target);
56
+ this.setState({
57
+ isShowLinkMenu: true
42
58
  });
43
59
  setTimeout(() => {
44
60
  this.registerEventHandle();
@@ -59,6 +75,9 @@ class LinkHoverMenuComponent extends React.Component {
59
75
  element
60
76
  });
61
77
  });
78
+ _defineProperty(this, "setRef", ref => {
79
+ this.linkRef = ref;
80
+ });
62
81
  this.state = {
63
82
  isShowLinkMenu: false,
64
83
  menuPosition: null
@@ -94,6 +113,7 @@ class LinkHoverMenuComponent extends React.Component {
94
113
  }, attributes, {
95
114
  onClick: this.onLinkClick
96
115
  }), /*#__PURE__*/React.createElement("span", {
116
+ ref: this.setRef,
97
117
  className: "virtual-link",
98
118
  title: element.title
99
119
  }, /*#__PURE__*/React.createElement(InlineBugFixer, null), children, /*#__PURE__*/React.createElement(InlineBugFixer, null))), isShowLinkMenu && (this.props.readonly || Range.isCollapsed(editor.selection)) && /*#__PURE__*/React.createElement(LinkHover, {
@@ -105,8 +125,9 @@ class LinkHoverMenuComponent extends React.Component {
105
125
  }));
106
126
  }
107
127
  }
128
+ _defineProperty(Link, "contextType", ScrollContext);
108
129
  const renderLink = (props, editor, readonly) => {
109
- return /*#__PURE__*/React.createElement(LinkHoverMenuComponent, Object.assign({}, props, {
130
+ return /*#__PURE__*/React.createElement(Link, Object.assign({}, props, {
110
131
  editor: editor,
111
132
  readonly: readonly
112
133
  }));
@@ -135,8 +135,8 @@ function SeaTableTable(_ref) {
135
135
  top: menuTop,
136
136
  left: left // left = code-block left distance
137
137
  };
138
- // 165 is distance with browser top
139
- if (menuTop < 165) {
138
+ // 201 is distance with browser top
139
+ if (menuTop < 201) {
140
140
  newMenuPosition['display'] = 'none';
141
141
  }
142
142
  setMenuPosition(newMenuPosition);
@@ -169,8 +169,8 @@ function SeaTableTable(_ref) {
169
169
  top: menuTop,
170
170
  left: left // left = callout left distance
171
171
  };
172
- // 165 is distance with browser top
173
- if (menuTop < 165) {
172
+ // 201 is distance with browser top
173
+ if (menuTop <= 201) {
174
174
  newMenuPosition['display'] = 'none';
175
175
  }
176
176
  setMenuPosition(newMenuPosition);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",