@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.
- package/dist/basic-sdk/extension/plugins/callout/helper.js +17 -0
- package/dist/basic-sdk/extension/plugins/callout/render-elem/index.js +7 -30
- package/dist/basic-sdk/extension/plugins/link/helpers.js +16 -0
- package/dist/basic-sdk/{assets/css/textlink-hovermenu.css → extension/plugins/link/hover/index.css} +1 -1
- package/dist/basic-sdk/extension/plugins/link/hover/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/link/render-elem.js +39 -18
- package/dist/basic-sdk/extension/plugins/seatable-tables/render-element/seatable-table.js +4 -4
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
};
|
|
@@ -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 '
|
|
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
|
-
|
|
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, "
|
|
39
|
+
_defineProperty(this, "onScroll", e => {
|
|
40
|
+
this.setPosition(this.linkRef);
|
|
41
|
+
});
|
|
42
|
+
_defineProperty(this, "setPosition", element => {
|
|
27
43
|
const {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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(
|
|
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
|
-
//
|
|
139
|
-
if (menuTop <
|
|
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
|
-
//
|
|
173
|
-
if (menuTop
|
|
172
|
+
// 201 is distance with browser top
|
|
173
|
+
if (menuTop <= 201) {
|
|
174
174
|
newMenuPosition['display'] = 'none';
|
|
175
175
|
}
|
|
176
176
|
setMenuPosition(newMenuPosition);
|