@seafile/sdoc-editor 0.2.10 → 0.2.11

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,7 +1,8 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import React, { useState } from 'react';
2
+ import React, { useCallback, useState } from 'react';
3
3
  import { withTranslation } from 'react-i18next';
4
4
  import { Dropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap';
5
+ import { eventStopPropagation } from '../../utils/mouse-event';
5
6
  export var COMMENT_TYPES = {
6
7
  all: 'All_comments',
7
8
  resolved: 'Resolved_comments',
@@ -24,6 +25,12 @@ function GlobalCommentHeader(_ref) {
24
25
  count: commentList.length
25
26
  });
26
27
  }
28
+ var handleCommentTypeChanged = useCallback(function (event, type) {
29
+ eventStopPropagation(event);
30
+ onCommentTypeChanged(type);
31
+
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ }, []);
27
34
  var id = 'comment-type-controller';
28
35
  return /*#__PURE__*/React.createElement("div", {
29
36
  className: "comments-panel-body__header"
@@ -47,20 +54,20 @@ function GlobalCommentHeader(_ref) {
47
54
  }, /*#__PURE__*/React.createElement(DropdownItem, {
48
55
  className: "sdoc-dropdown-menu-item",
49
56
  tag: 'div',
50
- onClick: function onClick() {
51
- return onCommentTypeChanged(COMMENT_TYPES.all);
57
+ onClick: function onClick(event) {
58
+ return handleCommentTypeChanged(event, COMMENT_TYPES.all);
52
59
  }
53
60
  }, t(COMMENT_TYPES.all)), /*#__PURE__*/React.createElement(DropdownItem, {
54
61
  className: "sdoc-dropdown-menu-item",
55
62
  tag: 'div',
56
- onClick: function onClick() {
57
- return onCommentTypeChanged(COMMENT_TYPES.resolved);
63
+ onClick: function onClick(event) {
64
+ return handleCommentTypeChanged(event, COMMENT_TYPES.resolved);
58
65
  }
59
66
  }, t(COMMENT_TYPES.resolved)), /*#__PURE__*/React.createElement(DropdownItem, {
60
67
  className: "sdoc-dropdown-menu-item",
61
68
  tag: 'div',
62
- onClick: function onClick() {
63
- return onCommentTypeChanged(COMMENT_TYPES.unresolved);
69
+ onClick: function onClick(event) {
70
+ return handleCommentTypeChanged(event, COMMENT_TYPES.unresolved);
64
71
  }
65
72
  }, t(COMMENT_TYPES.unresolved))))), /*#__PURE__*/React.createElement("div", {
66
73
  className: "comment-count-tip"
@@ -8,7 +8,7 @@ import { withTranslation } from 'react-i18next';
8
8
  import GlobalCommentHeader from './global-comment-header';
9
9
  var GlobalComment = function GlobalComment(_ref) {
10
10
  var t = _ref.t;
11
- var _useState = useState(false),
11
+ var _useState = useState(null),
12
12
  _useState2 = _slicedToArray(_useState, 2),
13
13
  activeComment = _useState2[0],
14
14
  setActiveComment = _useState2[1];
@@ -26,6 +26,7 @@ var GlobalComment = function GlobalComment(_ref) {
26
26
  isShowCommentList = _useState4[0],
27
27
  setShowCommentList = _useState4[1];
28
28
  useEffect(function () {
29
+ if (!isShowCommentList) return;
29
30
  var toggleOuterSide = function toggleOuterSide(e) {
30
31
  var commentWrapper = commentRef.current;
31
32
  var clickIsInComment = commentWrapper && commentWrapper.contains(e.target) && commentWrapper !== e.target;
@@ -33,14 +34,18 @@ var GlobalComment = function GlobalComment(_ref) {
33
34
  setActiveComment(null);
34
35
  setShowCommentList(false);
35
36
  };
37
+ document.addEventListener('click', toggleOuterSide);
38
+ return function () {
39
+ document.removeEventListener('click', toggleOuterSide);
40
+ };
41
+ }, [isShowCommentList]);
42
+ useEffect(function () {
36
43
  var eventBus = EventBus.getInstance();
37
44
  var unsubscribe = eventBus.subscribe('COMMENT_LIST_CLICK', function () {
38
45
  return setShowCommentList(!isShowCommentList);
39
46
  });
40
- document.addEventListener('click', toggleOuterSide, true);
41
47
  return function () {
42
48
  unsubscribe();
43
- document.removeEventListener('click', toggleOuterSide, true);
44
49
  };
45
50
  }, [isShowCommentList]);
46
51
  var contentRef = useRef(null);
@@ -51,6 +56,9 @@ var GlobalComment = function GlobalComment(_ref) {
51
56
  behavior: 'smooth'
52
57
  });
53
58
  }, []);
59
+ var hiddenComment = useCallback(function () {
60
+ setActiveComment(null);
61
+ }, []);
54
62
  if (!isShowCommentList) return null;
55
63
  return /*#__PURE__*/React.createElement(ElementPopover, {
56
64
  className: 'global-comments-popover'
@@ -88,6 +96,7 @@ var GlobalComment = function GlobalComment(_ref) {
88
96
  comment: comment,
89
97
  isActive: isActive,
90
98
  onCommentClick: onCommentClick,
99
+ hiddenComment: hiddenComment,
91
100
  updateScrollPosition: updateScrollPosition
92
101
  });
93
102
  }))))));
@@ -7,6 +7,7 @@ import React from 'react';
7
7
  import { CHECK_LIST_ITEM, MENUS_CONFIG_MAP, PARAGRAPH } from '../../../constants';
8
8
  import { MenuItem } from '../../../commons';
9
9
  import { isMenuDisabled, setCheckListItemType, getCheckListItemType } from '../helpers';
10
+ import { focusEditor } from '../../../core';
10
11
  var CheckListMenu = /*#__PURE__*/function (_React$Component) {
11
12
  _inherits(CheckListMenu, _React$Component);
12
13
  var _super = _createSuper(CheckListMenu);
@@ -32,6 +33,7 @@ var CheckListMenu = /*#__PURE__*/function (_React$Component) {
32
33
  var active = _this.isActive(editor);
33
34
  var newType = active ? PARAGRAPH : CHECK_LIST_ITEM;
34
35
  setCheckListItemType(editor, newType);
36
+ focusEditor(editor, editor.selection);
35
37
  };
36
38
  return _this;
37
39
  }
@@ -1,6 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import { Editor, Transforms } from '@seafile/slate';
3
- import { getNodeType, isTextNode, getParentNode } from '../../core';
3
+ import { getNodeType } from '../../core';
4
4
  import { ELEMENT_TYPE, HEADER, PARAGRAPH, SUBTITLE, TITLE } from '../../constants';
5
5
  export var isMenuDisabled = function isMenuDisabled(editor) {
6
6
  var readonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -9,10 +9,7 @@ export var isMenuDisabled = function isMenuDisabled(editor) {
9
9
  var _Editor$nodes = Editor.nodes(editor, {
10
10
  match: function match(n) {
11
11
  var type = getNodeType(n);
12
- if (!type && isTextNode(n) && n.id) {
13
- var parentNode = getParentNode(editor.children, n.id);
14
- type = getNodeType(parentNode);
15
- }
12
+ if (!type) return false;
16
13
  if (type === ELEMENT_TYPE.CODE_LINE) return true;
17
14
  if (type === ELEMENT_TYPE.CODE_BLOCK) return true;
18
15
  if (type === ELEMENT_TYPE.PARAGRAPH) return true;
@@ -32,6 +29,7 @@ export var getHeaderType = function getHeaderType(editor) {
32
29
  var _Editor$nodes3 = Editor.nodes(editor, {
33
30
  match: function match(n) {
34
31
  var nodeType = getNodeType(n);
32
+ if (!nodeType) return false;
35
33
  if (nodeType.includes(HEADER)) return true;
36
34
  if (nodeType === TITLE) return true;
37
35
  if (nodeType === SUBTITLE) return true;
@@ -9,6 +9,7 @@ import classnames from 'classnames';
9
9
  import { getHeaderType, isMenuDisabled, setHeaderType } from '../helpers';
10
10
  import { HEADERS, HEADER_TITLE_MAP, MAC_HOTKEYS, PARAGRAPH, SDOC_FONT_SIZE, SUBTITLE, TITLE, WIN_HOTKEYS } from '../../../constants';
11
11
  import Tooltip from '../../../commons/tooltip';
12
+ import { focusEditor } from '../../../core';
12
13
  import './style.css';
13
14
  var HeaderMenu = /*#__PURE__*/function (_React$Component) {
14
15
  _inherits(HeaderMenu, _React$Component);
@@ -70,6 +71,7 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
70
71
  var active = _this.isActive(type);
71
72
  var newType = active ? PARAGRAPH : type;
72
73
  setHeaderType(editor, newType);
74
+ focusEditor(editor, editor.selection);
73
75
  _this.setState({
74
76
  isShowHeaderPopover: false
75
77
  }, function () {
@@ -23,6 +23,7 @@ var withHeader = function withHeader(editor) {
23
23
  var _Editor$nodes = Editor.nodes(newEditor, {
24
24
  match: function match(n) {
25
25
  if (!Element.isElement(n)) return false;
26
+ if (!n.type) return false;
26
27
  if (n.type.startsWith(HEADER)) return true;
27
28
  if (n.type === TITLE) return true;
28
29
  if (n.type === SUBTITLE) return true;
@@ -72,9 +72,9 @@ var withMarkDown = function withMarkDown(editor) {
72
72
 
73
73
  // Based on the keyword, find the type of element you want to convert
74
74
  var type = KEY_TO_TYPE_FOR_SPACE[beforeText.trim()];
75
+ var italicAndBoldType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-3)];
75
76
  var boldType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-2)];
76
77
  var italicType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-1)];
77
- var italicAndBoldType = KEY_TO_INLINE_TYPE_FOR_SPACE[beforeText.slice(-3)];
78
78
  if (!type && !boldType && !italicType && !italicAndBoldType) return insertText(text);
79
79
  if (italicAndBoldType === TEXT_STYLE_MAP.BOLD_ITALIC) {
80
80
  var restStr = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 3);
@@ -119,10 +119,17 @@ var withMarkDown = function withMarkDown(editor) {
119
119
  Editor.addMark(editor, newType, true);
120
120
  return insertText(_newText);
121
121
  }
122
+
123
+ // demos
124
+ // 1 '*'
125
+ // 2 'acd * add *'
122
126
  if (italicType === TEXT_STYLE_MAP.ITALIC) {
123
127
  var _restStr2 = beforeText === null || beforeText === void 0 ? void 0 : beforeText.slice(0, beforeText.length - 1);
124
128
  var _startOffset2 = _restStr2 === null || _restStr2 === void 0 ? void 0 : _restStr2.lastIndexOf('*');
125
129
  var _endOffset2 = (beforeText === null || beforeText === void 0 ? void 0 : beforeText.lastIndexOf('*')) + 1;
130
+ if (_startOffset2 === -1 && _restStr2.length > 0) {
131
+ return insertText(text);
132
+ }
126
133
  if (_startOffset2 !== -1) {
127
134
  Transforms.delete(editor, {
128
135
  at: {
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { getDiff } from '../utils/diff';
3
3
  import SDocViewer from './sdoc-viewer';
4
+ import context from '../../context';
4
5
  import '../../assets/css/diff-viewer.css';
5
6
  var DiffViewer = function DiffViewer(_ref) {
6
7
  var currentContent = _ref.currentContent,
@@ -8,6 +9,7 @@ var DiffViewer = function DiffViewer(_ref) {
8
9
  didMountCallback = _ref.didMountCallback;
9
10
  var diff = getDiff(currentContent, lastContent);
10
11
  useEffect(function () {
12
+ context.initApi();
11
13
  didMountCallback && didMountCallback(diff);
12
14
 
13
15
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,7 +1,9 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { EventBus } from '../../../basic-sdk';
3
+ import { eventStopPropagation } from '../../../basic-sdk/utils/mouse-event';
3
4
  export default function CommentsOperation() {
4
- var onCommentsToggle = useCallback(function () {
5
+ var onCommentsToggle = useCallback(function (event) {
6
+ eventStopPropagation(event);
5
7
  var eventBus = EventBus.getInstance();
6
8
  eventBus.dispatch('COMMENT_LIST_CLICK');
7
9
  }, []);
@@ -30,7 +30,7 @@ var MoreOperations = function MoreOperations(_ref) {
30
30
  className: "op-item",
31
31
  tag: "span"
32
32
  }, /*#__PURE__*/React.createElement("i", {
33
- className: "sdocfont sdoc-menu"
33
+ className: "sdocfont sdoc-more"
34
34
  })), /*#__PURE__*/React.createElement(DropdownMenu, {
35
35
  className: "sdoc-dropdown-menu",
36
36
  right: true
@@ -1,3 +1,4 @@
1
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import React, { useCallback, useEffect, useRef, useState } from 'react';
3
4
  import { withTranslation } from 'react-i18next';
@@ -55,7 +56,23 @@ var SimpleEditor = function SimpleEditor(_ref) {
55
56
  toaster.success(t('Revision_created', {
56
57
  id: revisionId
57
58
  }));
59
+ searchParams.delete(REVISION_FIRST_LOAD_KEY);
58
60
  }
61
+ var newParamsString = '';
62
+ var _iterator = _createForOfIteratorHelper(searchParams.entries()),
63
+ _step;
64
+ try {
65
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
+ var item = _step.value;
67
+ newParamsString = newParamsString + "&".concat(item[0], "=").concat(item[1]);
68
+ }
69
+ } catch (err) {
70
+ _iterator.e(err);
71
+ } finally {
72
+ _iterator.f();
73
+ }
74
+ var newURL = "".concat(url.origin).concat(url.pathname).concat(newParamsString ? '/?' + newParamsString : '');
75
+ window.history.replaceState(null, null, newURL);
59
76
  }
60
77
 
61
78
  // eslint-disable-next-line react-hooks/exhaustive-deps
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",