@seafile/sdoc-editor 0.4.14 → 0.4.16

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.
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useMemo, Fragment } from 'react';
2
2
  import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
3
- import { Editor } from '@seafile/slate';
3
+ import { Editor, Node, Range } from '@seafile/slate';
4
4
  import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '../extension';
5
5
  import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
6
6
  import EventProxy from '../utils/event-handler';
@@ -139,11 +139,16 @@ const EditableArticle = _ref => {
139
139
  const {
140
140
  selection
141
141
  } = editor;
142
- const [imageNodeEntry] = Editor.nodes(editor, {
143
- match: n => n.type === IMAGE
144
- });
145
- if (imageNodeEntry) return;
146
- const domNode = ReactEditor.toDOMNode(editor, selection.focus.path);
142
+ if (Range.isCollapsed(selection)) {
143
+ // Do not scroll into view, when focus on image
144
+ const [imageNodeEntry] = Editor.nodes(editor, {
145
+ match: n => n.type === IMAGE,
146
+ at: selection
147
+ });
148
+ if (imageNodeEntry) return;
149
+ }
150
+ const focusedNode = Node.get(editor, selection.focus.path);
151
+ const domNode = ReactEditor.toDOMNode(editor, focusedNode);
147
152
  if (!domNode) return;
148
153
  domNode.scrollIntoView({
149
154
  block: 'nearest'
@@ -75,7 +75,10 @@ const ImageHoverMenu = _ref => {
75
75
  centerNode = null,
76
76
  afterNode = null;
77
77
  let p = path[0];
78
- if (!beforeLeaf.every(item => item.text.length === 0)) {
78
+ if (!beforeLeaf.every(item => {
79
+ var _item$text;
80
+ return (item === null || item === void 0 ? void 0 : (_item$text = item.text) === null || _item$text === void 0 ? void 0 : _item$text.length) === 0;
81
+ })) {
79
82
  beforeNode = generateEmptyElement(PARAGRAPH);
80
83
  beforeNode.children = beforeLeaf;
81
84
  Transforms.insertNodes(editor, beforeNode, {
@@ -90,8 +93,8 @@ const ImageHoverMenu = _ref => {
90
93
  });
91
94
  p = p + 1;
92
95
  if (!afterLeaf.every(item => {
93
- var _item$text;
94
- return (item === null || item === void 0 ? void 0 : (_item$text = item.text) === null || _item$text === void 0 ? void 0 : _item$text.length) === 0;
96
+ var _item$text2;
97
+ return (item === null || item === void 0 ? void 0 : (_item$text2 = item.text) === null || _item$text2 === void 0 ? void 0 : _item$text2.length) === 0;
95
98
  })) {
96
99
  afterNode = generateEmptyElement(PARAGRAPH);
97
100
  afterNode.children = afterLeaf;
@@ -114,6 +114,7 @@ const withImage = editor => {
114
114
  const point = Editor.before(editor, selection, {
115
115
  distance: 2
116
116
  });
117
+ if (!point) return;
117
118
  const [node, path] = Editor.node(editor, [point.path[0], point.path[1]]);
118
119
  const isPerviousNodeImage = node.type === IMAGE;
119
120
  if (isPerviousNodeImage && Range.isCollapsed(selection) && isBlockAboveEmpty(editor) && !Path.isCommon(path, selection.anchor.path)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.14",
3
+ "version": "0.4.16",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",