@seafile/sdoc-editor 0.1.88-beta → 0.1.89
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/assets/css/layout.css +2 -0
- package/dist/basic-sdk/editor.js +2 -2
- package/dist/basic-sdk/extension/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/render-elem.js +2 -1
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +5 -2
- package/dist/basic-sdk/extension/toolbar/context-toolbar/index.css +10 -0
- package/dist/basic-sdk/extension/toolbar/context-toolbar/index.js +55 -0
- package/dist/layout/layout.css +3 -0
- package/package.json +1 -1
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
|
|
4
|
-
import defaultEditor, { renderLeaf, renderElement, Toolbar } from './extension';
|
|
4
|
+
import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextToolbar } from './extension';
|
|
5
5
|
import { focusEditor, getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
|
|
6
6
|
import { withSocketIO } from './socket';
|
|
7
7
|
import withNodeId from './node-id';
|
|
@@ -232,7 +232,7 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
232
232
|
editor: editor,
|
|
233
233
|
value: slateValue,
|
|
234
234
|
onChange: onChange
|
|
235
|
-
}, /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement("div", {
|
|
235
|
+
}, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement("div", {
|
|
236
236
|
className: "article",
|
|
237
237
|
ref: articleRef
|
|
238
238
|
}, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
@@ -5,6 +5,7 @@ import Plugins from './plugins';
|
|
|
5
5
|
import renderElement from './render/render-element';
|
|
6
6
|
import renderLeaf from './render/render-leaf';
|
|
7
7
|
import Toolbar from './toolbar';
|
|
8
|
+
import ContextToolbar from './toolbar/context-toolbar';
|
|
8
9
|
var baseEditor = withHistory(withReact(createEditor()));
|
|
9
10
|
var defaultEditor = Plugins.reduce(function (editor, pluginItem) {
|
|
10
11
|
var withPlugin = pluginItem.editorPlugin;
|
|
@@ -14,4 +15,4 @@ var defaultEditor = Plugins.reduce(function (editor, pluginItem) {
|
|
|
14
15
|
return editor;
|
|
15
16
|
}, baseEditor);
|
|
16
17
|
export default defaultEditor;
|
|
17
|
-
export { renderLeaf, renderElement, Toolbar };
|
|
18
|
+
export { renderLeaf, renderElement, Toolbar, ContextToolbar };
|
|
@@ -3,6 +3,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
3
3
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
4
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
5
|
import React from 'react';
|
|
6
|
+
import { Range } from '@seafile/slate';
|
|
6
7
|
import { unWrapLinkNode } from './helpers';
|
|
7
8
|
import AddLinkDialog from './menu/add-link-dialog';
|
|
8
9
|
import LinkHoverComponent from './menu/hover-link-dialog';
|
|
@@ -96,7 +97,7 @@ var LinkHoverMenuComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
96
97
|
url: element.href,
|
|
97
98
|
title: element.title,
|
|
98
99
|
onLinkDialogToggle: this.onLinkDialogToggle
|
|
99
|
-
}), isShowLinkMenu && /*#__PURE__*/React.createElement(LinkHoverComponent, {
|
|
100
|
+
}), isShowLinkMenu && Range.isCollapsed(editor.selection) && /*#__PURE__*/React.createElement(LinkHoverComponent, {
|
|
100
101
|
menuPosition: menuPosition,
|
|
101
102
|
editor: editor,
|
|
102
103
|
href: element.href,
|
|
@@ -12,7 +12,8 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
12
12
|
var editor = _ref.editor,
|
|
13
13
|
t = _ref.t,
|
|
14
14
|
isRichEditor = _ref.isRichEditor,
|
|
15
|
-
className = _ref.className
|
|
15
|
+
className = _ref.className,
|
|
16
|
+
idPrefix = _ref.idPrefix;
|
|
16
17
|
var isActive = useCallback(function (type) {
|
|
17
18
|
var isMark = getValue(editor, type);
|
|
18
19
|
return !!isMark;
|
|
@@ -59,7 +60,9 @@ var TextStyleMenuList = function TextStyleMenuList(_ref) {
|
|
|
59
60
|
};
|
|
60
61
|
itemProps['defaultColorTip'] = item.type === ELEMENT_TYPE.COLOR ? t('Default') : '';
|
|
61
62
|
}
|
|
62
|
-
return _objectSpread(_objectSpread({}, itemProps), item)
|
|
63
|
+
return _objectSpread(_objectSpread(_objectSpread({}, itemProps), item), {}, {
|
|
64
|
+
id: idPrefix ? "".concat(idPrefix, "_").concat(item.id) : item.id
|
|
65
|
+
});
|
|
63
66
|
});
|
|
64
67
|
|
|
65
68
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { useRef, useEffect, useCallback } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { useFocused, useSlateStatic, useReadOnly } from '@seafile/slate-react';
|
|
4
|
+
import { Editor, Range } from '@seafile/slate';
|
|
5
|
+
import { MenuGroup } from '../../menu';
|
|
6
|
+
import TextStyleMenuList from '../../plugins/text-style/menu';
|
|
7
|
+
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
8
|
+
import { getSelectedNodeByType } from '../../core';
|
|
9
|
+
import { CODE_BLOCK } from '../../constants';
|
|
10
|
+
import './index.css';
|
|
11
|
+
var ContextToolbar = function ContextToolbar() {
|
|
12
|
+
var ref = useRef(null);
|
|
13
|
+
var editor = useSlateStatic();
|
|
14
|
+
var scrollRef = useScrollContext();
|
|
15
|
+
var inFocus = useFocused();
|
|
16
|
+
var readOnly = useReadOnly();
|
|
17
|
+
var setContextToolbarPosition = useCallback(function () {
|
|
18
|
+
var el = ref.current;
|
|
19
|
+
var domSelection = window.getSelection();
|
|
20
|
+
var domRange = domSelection.getRangeAt(0);
|
|
21
|
+
var rect = domRange.getBoundingClientRect();
|
|
22
|
+
el.style.top = "".concat(rect.top - el.offsetHeight, "px");
|
|
23
|
+
el.style.left = "".concat(rect.left, "px");
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
}, []);
|
|
26
|
+
var onScroll = useCallback(function (e) {
|
|
27
|
+
setContextToolbarPosition();
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, []);
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
var el = ref.current;
|
|
32
|
+
var selection = editor.selection;
|
|
33
|
+
if (!el) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (readOnly || !selection || !inFocus || Range.isCollapsed(selection) || Editor.string(editor, selection) === '' || getSelectedNodeByType(editor, CODE_BLOCK)) {
|
|
37
|
+
scrollRef.current && scrollRef.current.removeEventListener('scroll', onScroll);
|
|
38
|
+
el.removeAttribute('style');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
scrollRef.current && scrollRef.current.addEventListener('scroll', onScroll);
|
|
42
|
+
setContextToolbarPosition();
|
|
43
|
+
});
|
|
44
|
+
return createPortal( /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
ref: ref,
|
|
46
|
+
className: "sdoc-context-toolbar",
|
|
47
|
+
onMouseDown: function onMouseDown(e) {
|
|
48
|
+
e.preventDefault(); // prevent toolbar from taking focus away from editor
|
|
49
|
+
}
|
|
50
|
+
}, /*#__PURE__*/React.createElement(MenuGroup, null, /*#__PURE__*/React.createElement(TextStyleMenuList, {
|
|
51
|
+
editor: editor,
|
|
52
|
+
idPrefix: 'sdoc_context_toolar'
|
|
53
|
+
}))), document.body);
|
|
54
|
+
};
|
|
55
|
+
export default ContextToolbar;
|
package/dist/layout/layout.css
CHANGED