@seafile/seafile-editor 1.0.99 → 1.0.100

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.
@@ -119,9 +119,10 @@ const InlineEditor = _ref => {
119
119
  handelEnableEdit();
120
120
  return;
121
121
  }
122
- const value = editor.children;
123
- const isDocumentEmpty = value.length === 1 && _slate.Node.string(value[0]).length === 0 && _slate.Text.isText(value[0]);
124
- if (isDocumentEmpty) {
122
+
123
+ // Focus at start of document, when document is empty
124
+ const isDoEmpty = (0, _common.isDocumentEmpty)(editor);
125
+ if (isDoEmpty) {
125
126
  focusNode(editor);
126
127
  }
127
128
  }, [enableEdit, editor, focusNode, handelEnableEdit]);
@@ -109,9 +109,8 @@ const SimpleSlateEditor = _ref => {
109
109
 
110
110
  // Focus at start of document, when document is empty
111
111
  const onEditorClick = (0, _react.useCallback)(() => {
112
- const value = editor.children;
113
- const isDocumentEmpty = value.length === 1 && _slate.Node.string(value[0]).length === 0 && _slate.Text.isText(value[0]);
114
- if (isDocumentEmpty) {
112
+ const isDocEmpty = (0, _common.isDocumentEmpty)(editor);
113
+ if (isDocEmpty) {
115
114
  focusNode(editor);
116
115
  }
117
116
  }, [editor, focusNode]);
@@ -97,9 +97,8 @@ function SlateEditor(_ref) {
97
97
 
98
98
  // Focus at start of document, when document is empty
99
99
  const onEditorClick = (0, _react.useCallback)(() => {
100
- const value = editor.children;
101
- const isDocumentEmpty = value.length === 1 && _slate.Node.string(value[0]).length === 0 && _slate.Text.isText(value[0]);
102
- if (isDocumentEmpty) {
100
+ const isDocEmpty = (0, _common.isDocumentEmpty)(editor);
101
+ if (isDocEmpty) {
103
102
  focusFirstNode(editor);
104
103
  }
105
104
  }, [editor, focusFirstNode]);
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isUrl = exports.isMac = exports.isImage = exports.IMAGE_TYPES = void 0;
7
+ exports.isUrl = exports.isMac = exports.isImage = exports.isDocumentEmpty = exports.IMAGE_TYPES = void 0;
8
8
  var _isUrl = _interopRequireDefault(require("is-url"));
9
+ var _slate = require("slate");
9
10
  const isMac = () => {
10
11
  const platform = navigator.platform;
11
12
  return platform === 'Mac68K' || platform === 'MacPPC' || platform === 'Macintosh' || platform === 'MacIntel';
@@ -27,4 +28,18 @@ const isUrl = url => {
27
28
  if (!(0, _isUrl.default)(url)) return false;
28
29
  return true;
29
30
  };
30
- exports.isUrl = isUrl;
31
+
32
+ // Check document is empty or only contains void nodes
33
+ exports.isUrl = isUrl;
34
+ const isDocumentEmpty = editor => {
35
+ const document = editor.children;
36
+ const [firstChildNode] = document;
37
+ // Check if document has only one block node
38
+ const isWrapperEmpty = document.length === 1 && _slate.Node.string(firstChildNode).length === 0;
39
+ if (!isWrapperEmpty) return false;
40
+ // Check if the only one block node has only one text node with empty string
41
+ const hasVoidNode = firstChildNode.children.some(node => _slate.Editor.isVoid(editor, node));
42
+ if (hasVoidNode) return false;
43
+ return true;
44
+ };
45
+ exports.isDocumentEmpty = isDocumentEmpty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.99",
3
+ "version": "1.0.100",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {