@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.
@@ -14,6 +14,8 @@
14
14
  background-color: #fff;
15
15
  user-select: none;
16
16
  border-bottom: 1px solid #e5e6e8;
17
+ position: relative;
18
+ z-index: 102;
17
19
  }
18
20
 
19
21
  .sdoc-editor-container .sdoc-editor-content {
@@ -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,10 @@
1
+ .sdoc-context-toolbar {
2
+ position: absolute;
3
+ width: auto;
4
+ height: 42px;
5
+ z-index: 101;
6
+ background-color: #fff;
7
+ border: 1px solid #e8e8e8;
8
+ border-radius: 3px;
9
+ box-shadow: 0 2px 5px #0000001f;
10
+ }
@@ -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;
@@ -20,6 +20,9 @@ html, body {
20
20
  border-bottom: 1px solid #e5e6e8;
21
21
  flex-shrink: 0;
22
22
  height: 56px;
23
+ position: relative;
24
+ z-index: 102;
25
+ background-color: #fff;
23
26
  }
24
27
 
25
28
  .sdoc-editor-page-wrapper .sdoc-editor-page-content {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.88beta",
3
+ "version": "0.1.89",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",