@seafile/sdoc-editor 1.0.169 → 1.0.171

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.
@@ -21,7 +21,7 @@ const isMenuDisabled = (editor, readonly) => {
21
21
  type
22
22
  } = elem;
23
23
  if (editor.isVoid(elem)) return true;
24
- if ([_constants.CODE_BLOCK, _constants.CODE_LINE, _constants.LINK].includes(type)) return true;
24
+ if ([_constants.CODE_BLOCK, _constants.CODE_LINE, _constants.LINK, ..._constants.HEADERS].includes(type)) return true;
25
25
  return false;
26
26
  });
27
27
  if (notMatch) return true; // disabled
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setHeaderType = exports.isMenuDisabled = exports.getHeaderType = void 0;
6
+ exports.setHeaderType = exports.isSelectionInHeader = exports.isMenuDisabled = exports.getHeaderType = void 0;
7
7
  var _slate = require("@seafile/slate");
8
8
  var _core = require("../../core");
9
9
  var _constants = require("../../constants");
@@ -44,6 +44,22 @@ const getHeaderType = editor => {
44
44
  return (0, _core.getNodeType)(n);
45
45
  };
46
46
  exports.getHeaderType = getHeaderType;
47
+ const isSelectionInHeader = editor => {
48
+ const [match] = _slate.Editor.nodes(editor, {
49
+ match: n => {
50
+ if (!_slate.Element.isElement(n)) return false;
51
+ if (!n.type) return false;
52
+ if (n.type.startsWith(_constants.HEADER)) return true;
53
+ if (n.type === _constants.TITLE) return true;
54
+ if (n.type === _constants.SUBTITLE) return true;
55
+ return false;
56
+ },
57
+ // Matches nodes whose node.type starts with header
58
+ universal: true
59
+ });
60
+ return match;
61
+ };
62
+ exports.isSelectionInHeader = isSelectionInHeader;
47
63
  const setHeaderType = (editor, type) => {
48
64
  if (!type) return;
49
65
  _slate.Transforms.setNodes(editor, {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.transformToText = exports.getQuickInsertEntity = exports.genQuickInsert = void 0;
6
+ exports.transformToText = exports.isSelectionSameWithInsert = exports.getQuickInsertEntity = exports.genQuickInsert = void 0;
7
7
  var _slate = require("@seafile/slate");
8
8
  var _constants = require("../../constants");
9
9
  var _core = require("../../core");
@@ -37,4 +37,15 @@ const transformToText = (editor, quickInsertNode) => {
37
37
  });
38
38
  return insertPathRef.unref();
39
39
  };
40
- exports.transformToText = transformToText;
40
+ exports.transformToText = transformToText;
41
+ const isSelectionSameWithInsert = (editor, element) => {
42
+ if (!editor.selection) return;
43
+ if (!_slate.Range.isCollapsed(editor.selection)) return;
44
+ const {
45
+ anchor
46
+ } = editor.selection;
47
+ const path = _slateReact.ReactEditor.findPath(editor, element);
48
+ const lastPoint = _slate.Editor.end(editor, path);
49
+ return _slate.Point.equals(anchor, lastPoint);
50
+ };
51
+ exports.isSelectionSameWithInsert = isSelectionSameWithInsert;
@@ -32,6 +32,7 @@ const RenderQuickInsert = (_ref, editor, readonly) => {
32
32
  const insertElmRef = (0, _react.useRef)(null);
33
33
  const aboveBlockNode = (0, _core.getAboveBlockNode)(editor);
34
34
  const isEmptyNode = (0, _helpers.isVoidNode)(aboveBlockNode === null || aboveBlockNode === void 0 ? void 0 : aboveBlockNode[0]);
35
+ const [isShowPopover] = (0, _react.useState)((0, _helper.isSelectionSameWithInsert)(editor, element));
35
36
  const handleClick = (0, _react.useCallback)(e => {
36
37
  // Click the search input
37
38
  if (sideMenuRef.current.contains(e.target) && e.target.tagName === 'INPUT') return;
@@ -39,14 +40,17 @@ const RenderQuickInsert = (_ref, editor, readonly) => {
39
40
  (0, _helper.transformToText)(editor, element);
40
41
  }
41
42
  }, [editor, element]);
42
- const genStyle = (top, left) => {
43
- if (editor.isRemote) return null;
43
+ const genStyle = (0, _react.useCallback)((top, left) => {
44
44
  const overflowY = top + sideMenuRef.current.offsetHeight - document.body.clientHeight;
45
45
  if (overflowY > 0) {
46
46
  top = top - overflowY - 10;
47
47
  }
48
+ const overflowX = left - sideMenuRef.current.offsetWidth;
49
+ if (overflowX < 0) {
50
+ left = sideMenuRef.current.offsetWidth + 10;
51
+ }
48
52
  return `top: ${top}px; left: ${left}px`;
49
- };
53
+ }, []);
50
54
  const handleInsertMenuStyle = (0, _react.useCallback)(() => {
51
55
  const currentDom = _slateReact.ReactEditor.toDOMNode(editor, element);
52
56
  const {
@@ -55,12 +59,13 @@ const RenderQuickInsert = (_ref, editor, readonly) => {
55
59
  } = currentDom.getBoundingClientRect();
56
60
  const style = genStyle(top, left - 10);
57
61
  setMenuStyle(style);
58
- }, [editor, element]);
62
+ }, [editor, element, genStyle]);
59
63
  const handleScroll = (0, _react.useCallback)(e => {
60
64
  handleInsertMenuStyle();
61
65
  }, [handleInsertMenuStyle]);
62
66
  (0, _react.useEffect)(() => {
63
67
  if (readonly) return;
68
+ if (!sideMenuRef.current) return;
64
69
  const scrollDom = scrollRef.current;
65
70
  handleInsertMenuStyle();
66
71
  document.addEventListener('click', handleClick);
@@ -79,7 +84,7 @@ const RenderQuickInsert = (_ref, editor, readonly) => {
79
84
  ref: insertElmRef
80
85
  }, /*#__PURE__*/_react.default.createElement("span", Object.assign({}, attributes, {
81
86
  className: ""
82
- }), /*#__PURE__*/_react.default.createElement(_InlineBugFixWrapper.default, null), /*#__PURE__*/_react.default.createElement("span", null, "/", children), /*#__PURE__*/_react.default.createElement(_InlineBugFixWrapper.default, null), !readonly && /*#__PURE__*/_react.default.createElement(_commons.ElementPopover, {
87
+ }), /*#__PURE__*/_react.default.createElement(_InlineBugFixWrapper.default, null), /*#__PURE__*/_react.default.createElement("span", null, "/", children), /*#__PURE__*/_react.default.createElement(_InlineBugFixWrapper.default, null), !readonly && isShowPopover && /*#__PURE__*/_react.default.createElement(_commons.ElementPopover, {
83
88
  className: "sdoc-side-menu-popover",
84
89
  style: menuStyle
85
90
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -12,6 +12,7 @@ var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));
12
12
  var _context = _interopRequireDefault(require("../../../../context"));
13
13
  var _core = require("../../core");
14
14
  var _constants = require("../../constants");
15
+ var _helpers = require("../header/helpers");
15
16
  const isMenuDisabled = (editor, readonly) => {
16
17
  if (readonly) return true;
17
18
  if (editor.selection == null) return true;
@@ -21,7 +22,7 @@ const isMenuDisabled = (editor, readonly) => {
21
22
  type
22
23
  } = elem;
23
24
  if (editor.isVoid(elem)) return true;
24
- if ([_constants.CODE_BLOCK, _constants.CODE_LINE, _constants.LINK].includes(type)) return true;
25
+ if ([_constants.CODE_BLOCK, _constants.CODE_LINE, _constants.LINK, ..._constants.HEADERS].includes(type)) return true;
25
26
  return false;
26
27
  });
27
28
  if (notMatch) return true; // disabled
@@ -157,6 +158,9 @@ const getBeforeText = editor => {
157
158
  };
158
159
  exports.getBeforeText = getBeforeText;
159
160
  const isTriggeredByShortcut = editor => {
161
+ if ((0, _helpers.isSelectionInHeader)(editor)) {
162
+ return false;
163
+ }
160
164
  const {
161
165
  beforeText
162
166
  } = getBeforeText(editor);
@@ -69,13 +69,18 @@ const SideMenu = (_ref, ref) => {
69
69
  }, [onReset, slateNode.id, t]);
70
70
  const onUpdateMenuLocation = (0, _react.useCallback)(() => {
71
71
  let top = menuPosition.top;
72
+ let left = menuPosition.left;
72
73
  if (sideMenuRef.current) {
73
74
  const overflowY = menuPosition.top + sideMenuRef.current.offsetHeight - document.body.clientHeight;
74
75
  if (overflowY > 0) {
75
76
  top = menuPosition.top - overflowY - 10;
76
77
  }
78
+ const overflowX = menuPosition.left - sideMenuRef.current.offsetWidth;
79
+ if (overflowX < 0) {
80
+ left = sideMenuRef.current.offsetWidth + 10;
81
+ }
77
82
  }
78
- setMenuStyle(`top: ${top}px; left: ${menuPosition.left}px`);
83
+ setMenuStyle(`top: ${top}px; left: ${left}px`);
79
84
  }, [menuPosition.left, menuPosition.top]);
80
85
  (0, _react.useEffect)(() => {
81
86
  onUpdateMenuLocation();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.169",
3
+ "version": "1.0.171",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",