@seafile/comment-editor 0.0.1-alpha.8 → 0.0.1-alpha.81

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.
Files changed (29) hide show
  1. package/dist/basic-sdk/context.js +7 -21
  2. package/dist/basic-sdk/editor/comment-editor.js +10 -22
  3. package/dist/basic-sdk/extension/commons/color-menu/color-item.js +4 -2
  4. package/dist/basic-sdk/extension/commons/color-menu/index.js +4 -2
  5. package/dist/basic-sdk/extension/commons/select-file-dialog/local-files/index.js +4 -2
  6. package/dist/basic-sdk/extension/plugins/code-block/hover-menu/index.js +5 -3
  7. package/dist/basic-sdk/extension/plugins/file-link/hover-menu/index.js +5 -3
  8. package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -2
  9. package/dist/basic-sdk/extension/plugins/image/hover-menu/index.js +4 -2
  10. package/dist/basic-sdk/extension/plugins/image/render-elem.js +5 -3
  11. package/dist/basic-sdk/extension/plugins/image/use-copy-image.js +1 -2
  12. package/dist/basic-sdk/extension/plugins/image/use-upload-image.js +2 -2
  13. package/dist/basic-sdk/extension/plugins/sdoc-link/hover-menu/index.js +4 -2
  14. package/dist/basic-sdk/extension/plugins/table/menu/color-selector-popover/color-item.js +4 -2
  15. package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +1 -2
  16. package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +1 -1
  17. package/dist/basic-sdk/extension/plugins/text-style/menu/comemnt-editor-menu.js +1 -2
  18. package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +4 -2
  19. package/dist/basic-sdk/extension/plugins/video/render-elem.js +1 -2
  20. package/dist/basic-sdk/extension/toolbar/comment-editor-toolbar/index.js +13 -9
  21. package/dist/basic-sdk/hooks/use-comment.js +23 -11
  22. package/dist/basic-sdk/model/index.js +1 -8
  23. package/dist/basic-sdk/socket/helpers.js +312 -0
  24. package/dist/components/error-boundary/error-page.js +4 -4
  25. package/dist/pages/seafile-comment-editor.js +32 -19
  26. package/package.json +6 -6
  27. package/dist/basic-sdk/model/notification.js +0 -18
  28. package/dist/components/tip-message/index.js +0 -194
  29. package/dist/components/tip-message/style.css +0 -15
@@ -11,12 +11,12 @@ var _sdocServerApi = _interopRequireDefault(require("./api/sdoc-server-api"));
11
11
  var _seafileApi = _interopRequireDefault(require("./api/seafile-api"));
12
12
  class Context {
13
13
  constructor() {
14
- (0, _defineProperty2.default)(this, "initSettings", () => {
15
- this.settings = window.seafile ? window.seafile : window.seafileConfig;
14
+ (0, _defineProperty2.default)(this, "initSettings", settings => {
15
+ this.settings = settings ? settings : window.seafile ? window.seafile : window.seafileConfig;
16
16
  const {
17
- name,
18
- username,
19
- avatarURL
17
+ name = '',
18
+ username = '',
19
+ avatarURL = ''
20
20
  } = this.settings;
21
21
  const userInfo = {
22
22
  name,
@@ -24,13 +24,6 @@ class Context {
24
24
  avatar_url: avatarURL
25
25
  };
26
26
  this.user = userInfo;
27
- if (this.settings['isSdocRevision']) {
28
- const repoID = this.getSetting('repoID');
29
- const siteRoot = this.getSetting('siteRoot');
30
- const originFilePath = this.getSetting('originFilePath');
31
- const originFileURL = `${siteRoot}lib/${repoID}/file${originFilePath}`;
32
- this.settings['originFileURL'] = originFileURL;
33
- }
34
27
  });
35
28
  (0, _defineProperty2.default)(this, "uploadLocalImage", imageFiles => {
36
29
  const docUuid = this.getSetting('docUuid');
@@ -55,16 +48,9 @@ class Context {
55
48
  this.api = null;
56
49
  this.config = null;
57
50
  }
58
- init(api) {
59
- this.initSettings(); // lazy init context class
51
+ init(settings, api) {
52
+ this.initSettings(settings);
60
53
  this.api = api;
61
- // const server = this.getSetting('serviceUrl');
62
- // const token = this.getSetting('accessToken');
63
- // this.api = new SeafileAPI(server, token);
64
- // const isOpenSocket = this.getSetting('isOpenSocket');
65
- // if (isOpenSocket) {
66
- // this.sdocServerApi = new SDocServerApi(this.settings);
67
- // }
68
54
  }
69
55
  getSettings() {
70
56
  return this.settings;
@@ -14,7 +14,6 @@ var _classnames = _interopRequireDefault(require("classnames"));
14
14
  var _isHotkey = _interopRequireDefault(require("is-hotkey"));
15
15
  var _scrollIntoViewIfNeeded = _interopRequireDefault(require("scroll-into-view-if-needed"));
16
16
  var _constants = require("../constants");
17
- var _context = _interopRequireDefault(require("../context"));
18
17
  var _useCursors = require("../cursor/use-cursors");
19
18
  var _decorates = require("../decorates");
20
19
  var _extension = require("../extension");
@@ -39,16 +38,13 @@ const DEFAULT_PLACEHOLDER = 'Enter_comment_shift_enter_for_new_line_Enter_to_sen
39
38
  const CommentEditor = _ref => {
40
39
  let {
41
40
  content,
42
- commentContent,
43
41
  placeholder = DEFAULT_PLACEHOLDER,
42
+ toolMenus = ['text_style', _constants2.BLOCKQUOTE, _constants2.UNORDERED_LIST, _constants2.ORDERED_LIST, _constants2.LINK, _constants2.IMAGE],
44
43
  insertContent,
45
- updateContent,
46
44
  onContentChange,
47
- setIsEditing,
48
45
  hiddenComment,
49
46
  hiddenUserInfo,
50
- closeComment,
51
- addParticipants
47
+ closePanel
52
48
  } = _ref;
53
49
  const commentWrapperRef = (0, _react.useRef)();
54
50
  const {
@@ -91,23 +87,18 @@ const CommentEditor = _ref => {
91
87
  // init eventHandler
92
88
  // eslint-disable-next-line react-hooks/exhaustive-deps
93
89
  const eventProxy = (0, _react.useMemo)(() => new _eventHandler.default(editor), []);
94
- const updateValue = (0, _react.useCallback)(value => {
95
- if (!value || value.trim() === '') return;
96
- if (!content) return insertContent(value);
97
- updateContent && updateContent(value);
98
- }, [content, insertContent, updateContent]);
99
90
  const onSubmit = (0, _react.useCallback)(event => {
100
91
  event && event.stopPropagation();
101
92
  const mdString = (0, _slateToMd.default)(editor.children);
102
- updateValue(mdString);
103
- addParticipants(userInfo.username);
93
+ if (mdString && mdString.trim()) insertContent(mdString);
104
94
  editor.children = [(0, _core.generateEmptyElement)(_constants2.PARAGRAPH, {
105
95
  placeholder
106
96
  })];
107
97
  _slate.Transforms.select(editor, _slate.Editor.start(editor, []));
108
98
  onContentChange && onContentChange(null);
109
- closeComment && closeComment();
110
- }, [editor, updateValue, addParticipants, userInfo.username, placeholder, onContentChange, closeComment]);
99
+ closePanel && closePanel();
100
+ // eslint-disable-next-line react-hooks/exhaustive-deps
101
+ }, [editor, insertContent, placeholder, onContentChange, closePanel]);
111
102
  const onSubmitByEnterKey = (0, _react.useCallback)(event => {
112
103
  if (!_slateReact.ReactEditor.isFocused(editor)) return;
113
104
  onSubmit(event);
@@ -139,7 +130,6 @@ const CommentEditor = _ref => {
139
130
  const isPreventCancel = isClickOnListContainer || isClickOnCommentEditorContainer || isClickResizeContainer || isSdocContentWrapper;
140
131
  if (isPreventCancel) return;
141
132
  }
142
- setIsEditing && setIsEditing(false);
143
133
  hiddenComment && hiddenComment(false);
144
134
  if (onContentChange) {
145
135
  if (editor.children.find(n => _slate.Node.string(n).trim())) {
@@ -149,17 +139,14 @@ const CommentEditor = _ref => {
149
139
  }
150
140
  }
151
141
  // eslint-disable-next-line react-hooks/exhaustive-deps
152
- }, [setIsEditing]);
142
+ }, []);
153
143
 
154
144
  // set editor children
155
145
  (0, _react.useEffect)(() => {
156
146
  let children = (0, _mdToSlate.default)(content);
157
- if (commentContent) {
158
- children = (0, _mdToSlate.default)(commentContent);
159
- }
160
147
  editor.children = children;
161
148
  _slate.Transforms.select(editor, _slate.Editor.end(editor, []));
162
- }, [editor, content, commentContent]);
149
+ }, [editor, content]);
163
150
 
164
151
  // useMount: focus editor
165
152
  (0, _react.useEffect)(() => {
@@ -279,10 +266,11 @@ const CommentEditor = _ref => {
279
266
  onBeforeInput: eventProxy.onBeforeInput
280
267
  })))), /*#__PURE__*/_react.default.createElement(_commentEditorToolbar.default, {
281
268
  editor: editor,
269
+ toolMenus: toolMenus,
282
270
  onSubmit: onSubmit,
283
271
  submitBtnText: t(submitTip),
284
272
  onCancel: onCancel
285
- }))), /*#__PURE__*/_react.default.createElement(_insertElementDialog.default, {
273
+ }))), toolMenus.includes(_constants2.IMAGE) && /*#__PURE__*/_react.default.createElement(_insertElementDialog.default, {
286
274
  editor: editor
287
275
  }));
288
276
  };
@@ -10,10 +10,12 @@ var _reactI18next = require("react-i18next");
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
  const ColorItem = _ref => {
12
12
  let {
13
- t,
14
13
  color,
15
14
  lastUsedColor
16
15
  } = _ref;
16
+ const {
17
+ t
18
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
17
19
  return /*#__PURE__*/_react.default.createElement("div", {
18
20
  className: (0, _classnames.default)('sdoc-color-item', {
19
21
  'selected': lastUsedColor === color.value
@@ -28,4 +30,4 @@ const ColorItem = _ref => {
28
30
  }) : t(color.name)
29
31
  });
30
32
  };
31
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(ColorItem);
33
+ var _default = exports.default = ColorItem;
@@ -26,7 +26,6 @@ const ColorMenu = _ref => {
26
26
  id,
27
27
  popoverClassName,
28
28
  disabled,
29
- t,
30
29
  setColor,
31
30
  recentUsedColorsKey,
32
31
  text,
@@ -35,6 +34,9 @@ const ColorMenu = _ref => {
35
34
  lastUsedColor,
36
35
  updateLastUsedColor
37
36
  } = _ref;
37
+ const {
38
+ t
39
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
38
40
  const popoverRef = (0, _react.useRef)(null);
39
41
  const moreColorsPopoverRef = (0, _react.useRef)(null);
40
42
  const [recentUsedColors, setRecentUsedColors] = (0, _react.useState)(_localStorageUtils.default.getItem(recentUsedColorsKey, _constants.DEFAULT_RECENT_USED_LIST));
@@ -205,4 +207,4 @@ const ColorMenu = _ref => {
205
207
  onChange: onChange
206
208
  }))))));
207
209
  };
208
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(ColorMenu);
210
+ var _default = exports.default = ColorMenu;
@@ -20,10 +20,12 @@ const LocalFiles = _ref => {
20
20
  onSelectedFile,
21
21
  toggle,
22
22
  fileType,
23
- t,
24
23
  searchContent,
25
24
  isOpenSearch
26
25
  } = _ref;
26
+ const {
27
+ t
28
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
27
29
  const folderRef = (0, _react.useRef)(null);
28
30
  const [expandedFolder, setExpandedFolder] = (0, _react.useState)(new Set([]));
29
31
  const [currentActiveItem, setCurrentActiveItem] = (0, _react.useState)(null);
@@ -188,4 +190,4 @@ const LocalFiles = _ref => {
188
190
  className: "sdoc-file-search-no-result"
189
191
  }, t('No_results')));
190
192
  };
191
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(LocalFiles);
193
+ var _default = exports.default = LocalFiles;
@@ -55,9 +55,11 @@ const CodeBlockHoverMenu = _ref2 => {
55
55
  onChangeLanguage,
56
56
  onChangeAutoLineWrap,
57
57
  onCopyCodeBlock,
58
- onDeleteCodeBlock,
59
- t
58
+ onDeleteCodeBlock
60
59
  } = _ref2;
60
+ const {
61
+ t
62
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
61
63
  const {
62
64
  white_space = 'nowrap'
63
65
  } = style;
@@ -254,4 +256,4 @@ const CodeBlockHoverMenu = _ref2 => {
254
256
  ref: langRefs
255
257
  })))));
256
258
  };
257
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(CodeBlockHoverMenu);
259
+ var _default = exports.default = CodeBlockHoverMenu;
@@ -24,9 +24,11 @@ const FileLinkHoverMenu = _ref => {
24
24
  menuPosition,
25
25
  element,
26
26
  onUnwrapFileLinkNode,
27
- onHideInsertHoverMenu,
28
- t
27
+ onHideInsertHoverMenu
29
28
  } = _ref;
29
+ const {
30
+ t
31
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
30
32
  const readOnly = (0, _slateReact.useReadOnly)();
31
33
  const [isShowDisplayStylePopover, setIsShowDisplayStylePopover] = (0, _react.useState)(false);
32
34
  const onCopy = (0, _react.useCallback)(e => {
@@ -117,4 +119,4 @@ const FileLinkHoverMenu = _ref => {
117
119
  }));
118
120
  }))));
119
121
  };
120
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(FileLinkHoverMenu);
122
+ var _default = exports.default = FileLinkHoverMenu;
@@ -291,8 +291,7 @@ const handleBase64Image = (editor, path, imgData) => {
291
291
  const file = new File([blob], `${_slugid.default.nice()}.jpg`, {
292
292
  type: unit8Array.mime
293
293
  });
294
- console.log(111);
295
- _context.default.uploadLocalImage([file]).then(res => {
294
+ _context.default.api.uploadLocalImage([file]).then(res => {
296
295
  const _data = {
297
296
  ...imgData,
298
297
  src: res[0]
@@ -27,9 +27,11 @@ const ImageHoverMenu = _ref => {
27
27
  parentNodeEntry,
28
28
  imageCaptionInputRef,
29
29
  onHideImageHoverMenu,
30
- t,
31
30
  readonly
32
31
  } = _ref;
32
+ const {
33
+ t
34
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
33
35
  const {
34
36
  data,
35
37
  border_type = _constants2.IMAGE_BORDER_TYPE[0].type
@@ -299,4 +301,4 @@ const ImageHoverMenu = _ref => {
299
301
  }
300
302
  })));
301
303
  };
302
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(ImageHoverMenu);
304
+ var _default = exports.default = ImageHoverMenu;
@@ -33,9 +33,11 @@ const Image = _ref => {
33
33
  className,
34
34
  attributes,
35
35
  children,
36
- isSelected,
37
- t
36
+ isSelected
38
37
  } = _ref;
38
+ const {
39
+ t
40
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
39
41
  const {
40
42
  data,
41
43
  border_type = _constants3.IMAGE_BORDER_TYPE[0].type
@@ -348,7 +350,7 @@ const Image = _ref => {
348
350
  }
349
351
  })));
350
352
  };
351
- const SdocImage = (0, _reactI18next.withTranslation)('sdoc-editor')(Image);
353
+ const SdocImage = Image;
352
354
  function renderImage(props, editor) {
353
355
  // eslint-disable-next-line react-hooks/rules-of-hooks
354
356
  const isSelected = (0, _slateReact.useSelected)();
@@ -51,8 +51,7 @@ const useCopyImage = _ref => {
51
51
  const file = new File([blob], 'downloaded_image.png', {
52
52
  type: blob.type
53
53
  });
54
- console.log(222);
55
- const imageUrl = await _context.default.uploadLocalImage([file]);
54
+ const imageUrl = await _context.default.api.uploadLocalImage([file]);
56
55
  if (imageUrl && imageUrl[0]) {
57
56
  updateImageNode(editor, element, imageUrl[0]);
58
57
  }
@@ -42,8 +42,8 @@ const useUploadImage = _ref => {
42
42
  const uploadCurrentImage = async () => {
43
43
  try {
44
44
  const fileItem = _imageCache.default.getImage(file_uuid);
45
- console.log(333, _context.default);
46
- const imageUrl = await _context.default.uploadLocalImage([fileItem]);
45
+ const imageUrl = await _context.default.api.uploadLocalImage([fileItem]);
46
+ console.log('imageUrl', imageUrl);
47
47
  if (imageUrl && imageUrl[0]) {
48
48
  updateImageNode(editor, element, imageUrl[0]);
49
49
  }
@@ -25,9 +25,11 @@ const SdocLinkHoverMenu = _ref => {
25
25
  element,
26
26
  onUnwrapFileLinkNode,
27
27
  onHideInsertHoverMenu,
28
- t,
29
28
  url
30
29
  } = _ref;
30
+ const {
31
+ t
32
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
31
33
  const readOnly = (0, _slateReact.useReadOnly)();
32
34
  const [isShowDisplayStylePopover, setIsShowDisplayStylePopover] = (0, _react.useState)(false);
33
35
  const onCopy = (0, _react.useCallback)(e => {
@@ -116,4 +118,4 @@ const SdocLinkHoverMenu = _ref => {
116
118
  }));
117
119
  }))));
118
120
  };
119
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(SdocLinkHoverMenu);
121
+ var _default = exports.default = SdocLinkHoverMenu;
@@ -10,10 +10,12 @@ var _reactI18next = require("react-i18next");
10
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
11
  const ColorItem = _ref => {
12
12
  let {
13
- t,
14
13
  color,
15
14
  lastUsedColor
16
15
  } = _ref;
16
+ const {
17
+ t
18
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
17
19
  return /*#__PURE__*/_react.default.createElement("div", {
18
20
  className: (0, _classnames.default)('sdoc-color-item', {
19
21
  'selected': lastUsedColor === color.value
@@ -28,4 +30,4 @@ const ColorItem = _ref => {
28
30
  }) : t(color.name)
29
31
  });
30
32
  };
31
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(ColorItem);
33
+ var _default = exports.default = ColorItem;
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
- var _reactI18next = require("react-i18next");
11
10
  var _dropdownMenuItem = _interopRequireDefault(require("../../../../commons/dropdown-menu-item"));
12
11
  var _constants = require("../../../../constants");
13
12
  var _helpers = require("../../helpers");
@@ -38,4 +37,4 @@ const TableMenu = _ref => {
38
37
  createTable: createTable
39
38
  }));
40
39
  };
41
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(TableMenu);
40
+ var _default = exports.default = TableMenu;
@@ -95,4 +95,4 @@ const TextAlignMenu = _ref => {
95
95
  }));
96
96
  }))));
97
97
  };
98
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(TextAlignMenu);
98
+ var _default = exports.default = TextAlignMenu;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactI18next = require("react-i18next");
10
9
  var _commons = require("../../../commons");
11
10
  var _constants = require("../../../constants");
12
11
  var _menusConfig = require("../../../constants/menus-config");
@@ -69,4 +68,4 @@ const CommentEditorTextStyleMenuList = _ref => {
69
68
  key: index
70
69
  }, itemProps))));
71
70
  };
72
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(CommentEditorTextStyleMenuList);
71
+ var _default = exports.default = CommentEditorTextStyleMenuList;
@@ -25,12 +25,14 @@ var _helpers3 = require("../helpers");
25
25
  const TextStyleMenuList = _ref => {
26
26
  let {
27
27
  editor,
28
- t,
29
28
  isRichEditor,
30
29
  className,
31
30
  idPrefix,
32
31
  readonly
33
32
  } = _ref;
33
+ const {
34
+ t
35
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
34
36
  let selectedFontSize = (0, _helpers.getFontSize)(editor);
35
37
  let selectedFontSizeValue = selectedFontSize;
36
38
  const enableSeafileAI = _context.default.getSetting('enableSeafileAI');
@@ -159,4 +161,4 @@ const TextStyleMenuList = _ref => {
159
161
  isRichEditor: isRichEditor
160
162
  }));
161
163
  };
162
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(TextStyleMenuList);
164
+ var _default = exports.default = TextStyleMenuList;
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.renderVideo = renderVideo;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactI18next = require("react-i18next");
10
9
  var _slate = require("@seafile/slate");
11
10
  var _slateReact = require("@seafile/slate-react");
12
11
  var _helpers = require("./helpers");
@@ -128,7 +127,7 @@ const Video = _ref => {
128
127
  }
129
128
  }))));
130
129
  };
131
- const SdocVideo = (0, _reactI18next.withTranslation)('sdoc-editor')(Video);
130
+ const SdocVideo = Video;
132
131
  function renderVideo(props, editor) {
133
132
  const {
134
133
  element,
@@ -22,33 +22,37 @@ const CommentEditorToolbar = _ref => {
22
22
  readonly = false,
23
23
  onSubmit,
24
24
  submitBtnText,
25
- onCancel
25
+ onCancel,
26
+ toolMenus
26
27
  } = _ref;
27
28
  (0, _useSelectionUpdate.default)();
28
29
  const eventBus = _eventBus.default.getInstance();
29
30
  return /*#__PURE__*/_react.default.createElement("div", {
30
- className: "comment-editor-toolbar"
31
- }, /*#__PURE__*/_react.default.createElement(_commons.MenuGroup, {
31
+ className: "comment-editor-toolbar",
32
+ style: {
33
+ justifyContent: toolMenus.length === 0 ? 'end' : ''
34
+ }
35
+ }, toolMenus.length !== 0 && /*#__PURE__*/_react.default.createElement(_commons.MenuGroup, {
32
36
  className: "menu-group comment-editor-menu-group"
33
- }, /*#__PURE__*/_react.default.createElement(_comemntEditorMenu.default, {
37
+ }, toolMenus.includes('text_style') && /*#__PURE__*/_react.default.createElement(_comemntEditorMenu.default, {
34
38
  editor: editor,
35
39
  readonly: readonly
36
- }), /*#__PURE__*/_react.default.createElement(_menu.default, {
40
+ }), toolMenus.includes(_constants.BLOCKQUOTE) && /*#__PURE__*/_react.default.createElement(_menu.default, {
37
41
  editor: editor,
38
42
  readonly: readonly
39
- }), /*#__PURE__*/_react.default.createElement(_menu4.default, {
43
+ }), toolMenus.includes(_constants.UNORDERED_LIST) && /*#__PURE__*/_react.default.createElement(_menu4.default, {
40
44
  editor: editor,
41
45
  type: _constants.UNORDERED_LIST,
42
46
  readonly: readonly
43
- }), /*#__PURE__*/_react.default.createElement(_menu4.default, {
47
+ }), toolMenus.includes(_constants.ORDERED_LIST) && /*#__PURE__*/_react.default.createElement(_menu4.default, {
44
48
  editor: editor,
45
49
  type: _constants.ORDERED_LIST,
46
50
  readonly: readonly
47
- }), /*#__PURE__*/_react.default.createElement(_menu3.default, {
51
+ }), toolMenus.includes(_constants.LINK) && /*#__PURE__*/_react.default.createElement(_menu3.default, {
48
52
  editor: editor,
49
53
  readonly: readonly,
50
54
  eventBus: eventBus
51
- }), /*#__PURE__*/_react.default.createElement(_menu2.default, {
55
+ }), toolMenus.includes(_constants.IMAGE) && /*#__PURE__*/_react.default.createElement(_menu2.default, {
52
56
  editor: editor,
53
57
  readonly: readonly,
54
58
  eventBus: eventBus
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.useComment = exports.CommentProvider = void 0;
8
9
  var _react = _interopRequireWildcard(require("react"));
9
- var _reactI18next = require("react-i18next");
10
+ var _context = _interopRequireDefault(require("../context"));
11
+ var _model = require("../model");
10
12
  require("../assets/css/layout.css");
11
13
  require("../assets/css/default.css");
12
14
  require("../assets/css/sdoc-editor-article.css");
@@ -18,25 +20,35 @@ const CommentProvider = _ref => {
18
20
  let {
19
21
  children,
20
22
  type,
21
- userInfo,
22
- pluginName = '',
23
+ // comment or replay
23
24
  className = '',
25
+ pluginName = '',
26
+ // sdoc or wiki or txt ...
24
27
  pluginEventBus,
25
- pluginEvent
28
+ pluginEvent,
29
+ collaborators = [],
30
+ participants = [],
31
+ addParticipants
26
32
  } = _ref;
27
- const {
28
- t
29
- } = (0, _reactI18next.useTranslation)('sdoc-editor');
30
- const [collaborators, setCollaborators] = (0, _react.useState)([]);
33
+ const getCollaborators = (0, _react.useCallback)(() => {
34
+ const newCollaborators = collaborators.map(user => new _model.User(user));
35
+ return newCollaborators;
36
+ }, [collaborators]);
37
+ const getParticipants = (0, _react.useCallback)(() => {
38
+ const newParticipants = participants.map(user => new _model.User(user));
39
+ return newParticipants;
40
+ }, [participants]);
31
41
  return /*#__PURE__*/_react.default.createElement(CommentContext.Provider, {
32
42
  value: {
33
43
  type,
34
- userInfo,
35
- pluginName,
44
+ userInfo: _context.default.getUserInfo(),
36
45
  className,
46
+ pluginName,
37
47
  pluginEventBus,
38
48
  pluginEvent,
39
- collaborators
49
+ collaborators: getCollaborators(),
50
+ participants: getParticipants(),
51
+ addParticipants
40
52
  }
41
53
  }, children);
42
54
  };
@@ -4,17 +4,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- Object.defineProperty(exports, "Notification", {
8
- enumerable: true,
9
- get: function () {
10
- return _notification.default;
11
- }
12
- });
13
7
  Object.defineProperty(exports, "User", {
14
8
  enumerable: true,
15
9
  get: function () {
16
10
  return _user.default;
17
11
  }
18
12
  });
19
- var _user = _interopRequireDefault(require("./user"));
20
- var _notification = _interopRequireDefault(require("./notification"));
13
+ var _user = _interopRequireDefault(require("./user"));
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.validateOperation = exports.syncRemoteOperations = exports.syncRemoteCursorLocation = exports.revertOperationList = exports.reExecRevertOperationList = exports.getRevertOperationList = exports.getNodePathById = void 0;
9
+ var _slate = require("@seafile/slate");
10
+ var _deepCopy = _interopRequireDefault(require("deep-copy"));
11
+ var _helper = require("../cursor/helper");
12
+ var _core = require("../extension/core");
13
+ var OPERATION = _interopRequireWildcard(require("../node-id/constants"));
14
+ const getNodePathById = function (rootNode, nodeId) {
15
+ let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
16
+ if (rootNode.id === nodeId) return path;
17
+ const {
18
+ children = []
19
+ } = rootNode;
20
+ for (let i = 0; i < children.length; i++) {
21
+ const child = children[i];
22
+ path.push(i);
23
+ const nodePath = getNodePathById(child, nodeId, path);
24
+ if (nodePath) return nodePath;
25
+ path.pop();
26
+ }
27
+ return null;
28
+ };
29
+ exports.getNodePathById = getNodePathById;
30
+ const validateOperation = (editor, operation) => {
31
+ let isValid = false;
32
+ let newOperation = (0, _deepCopy.default)(operation);
33
+ const {
34
+ type
35
+ } = newOperation;
36
+ switch (type) {
37
+ case OPERATION.INSERT_TEXT:
38
+ case OPERATION.REMOVE_TEXT:
39
+ {
40
+ const {
41
+ node_id,
42
+ path
43
+ } = newOperation;
44
+ const node = (0, _core.getNode)(editor, path);
45
+ // node is exist and node path is not changed
46
+ if (node && node.id === node_id) {
47
+ isValid = true;
48
+ break;
49
+ }
50
+
51
+ // node is exist but node path is changed
52
+ const nodePath = getNodePathById(editor, node_id);
53
+ if (nodePath) {
54
+ isValid = true;
55
+ newOperation.path = nodePath;
56
+ break;
57
+ }
58
+ // node is not exist
59
+ isValid = false;
60
+ break;
61
+ }
62
+ case OPERATION.INSERT_NODE:
63
+ {
64
+ let {
65
+ parent_node_id,
66
+ path
67
+ } = newOperation;
68
+ const parentNodePath = getNodePathById(editor, parent_node_id);
69
+ if (!parentNodePath) {
70
+ isValid = false;
71
+ break;
72
+ }
73
+ const parentPath = path.slice(0, path.length - 1);
74
+ if (parentPath.join() === parentNodePath.join()) {
75
+ isValid = true;
76
+ break;
77
+ }
78
+
79
+ // reset insert node path
80
+ const parentNode = (0, _core.getNode)(editor, path);
81
+ if (parentNode) {
82
+ const childLength = parentNode.children.length;
83
+ const index = Math.min(path[path.length - 1], childLength);
84
+ newOperation.path = parentNodePath.concat([index]);
85
+ isValid = true;
86
+ }
87
+ break;
88
+ }
89
+ case OPERATION.REMOVE_NODE:
90
+ {
91
+ const {
92
+ node_id,
93
+ path
94
+ } = newOperation;
95
+ const node = (0, _core.getNode)(editor, path);
96
+ // node is exist and node path is not changed
97
+ if (node && node.id === node_id) {
98
+ isValid = true;
99
+ break;
100
+ }
101
+
102
+ // node is exist but node path is changed
103
+ const nodePath = getNodePathById(editor, node_id);
104
+ if (nodePath) {
105
+ isValid = true;
106
+ newOperation.path = nodePath;
107
+ break;
108
+ }
109
+
110
+ // node is not exist
111
+ isValid = false;
112
+ break;
113
+ }
114
+ case OPERATION.MERGE_NODE:
115
+ {
116
+ // merge next node into prev node
117
+ const {
118
+ node_id,
119
+ path
120
+ } = newOperation;
121
+ const node = (0, _core.getNode)(editor, path);
122
+ // node is exist and node path is not changed
123
+ if (node && node.id === node_id) {
124
+ isValid = true;
125
+ break;
126
+ }
127
+
128
+ // node is exist but node path is changed
129
+ const nodePath = getNodePathById(editor, node_id);
130
+ if (nodePath) {
131
+ isValid = true;
132
+ newOperation.path = nodePath;
133
+ break;
134
+ }
135
+
136
+ // node is not exist
137
+ isValid = false;
138
+ break;
139
+ }
140
+ case OPERATION.SPLIT_NODE:
141
+ {
142
+ const {
143
+ node_id,
144
+ path
145
+ } = newOperation;
146
+ const node = (0, _core.getNode)(editor, path);
147
+ // node is exist and node path is not changed
148
+ if (node && node.id === node_id) {
149
+ isValid = true;
150
+ break;
151
+ }
152
+
153
+ // node is exist but node path is changed
154
+ const nodePath = getNodePathById(editor, node_id);
155
+ if (nodePath) {
156
+ isValid = true;
157
+ newOperation.path = nodePath;
158
+ break;
159
+ }
160
+
161
+ // node is not exist
162
+ isValid = false;
163
+ break;
164
+ }
165
+ case OPERATION.SET_NODE:
166
+ {
167
+ const {
168
+ node_id,
169
+ path,
170
+ properties
171
+ } = newOperation;
172
+ const node = (0, _core.getNode)(editor, path);
173
+ // node is exist and node path is not changed
174
+ if (node && node.id === node_id) {
175
+ isValid = true;
176
+ newOperation.properties = {
177
+ ...properties,
178
+ type: node.type
179
+ };
180
+ break;
181
+ }
182
+
183
+ // node is exist but node path is changed
184
+ const nodePath = getNodePathById(editor, node_id);
185
+ if (nodePath) {
186
+ isValid = true;
187
+ const node = (0, _core.getNode)(editor, nodePath);
188
+ newOperation.properties = {
189
+ ...properties,
190
+ type: node.type
191
+ };
192
+ newOperation.path = nodePath;
193
+ break;
194
+ }
195
+
196
+ // node is not exist
197
+ isValid = false;
198
+ break;
199
+ }
200
+ case OPERATION.MOVE_NODE:
201
+ {
202
+ const {
203
+ node_id,
204
+ path
205
+ } = newOperation;
206
+ const node = (0, _core.getNode)(editor, path);
207
+ // node is exist and node path is not changed
208
+ if (node && node.id === node_id) {
209
+ isValid = true;
210
+ break;
211
+ }
212
+
213
+ // TODO: newPath can not calculate by nodePath
214
+ // node is exist but node path is changed
215
+ // const nodePath = getNodePathById(editor, node_id);
216
+ // if (nodePath) {}
217
+
218
+ // node is not exist
219
+ isValid = false;
220
+ break;
221
+ }
222
+ default:
223
+ {
224
+ // set_selection
225
+ break;
226
+ }
227
+ }
228
+ if (isValid) return newOperation;
229
+ return isValid;
230
+ };
231
+ exports.validateOperation = validateOperation;
232
+ const getRevertOperationList = operationList => {
233
+ if (operationList.length === 0) return [];
234
+
235
+ // Generate a duplicate operationList, The original value cannot be modified here
236
+ let revertOperationList = (0, _deepCopy.default)(operationList);
237
+ revertOperationList = revertOperationList.reverse();
238
+ return revertOperationList.map(operations => {
239
+ const ops = operations.reverse();
240
+ return ops.map(item => _slate.Operation.inverse(item));
241
+ });
242
+ };
243
+ exports.getRevertOperationList = getRevertOperationList;
244
+ const revertOperationList = (editor, operationList) => {
245
+ if (operationList.length === 0) return [];
246
+ const revertOperationList = getRevertOperationList(operationList);
247
+
248
+ // Cancel locale execute operations
249
+ for (let i = 0; i < revertOperationList.length; i++) {
250
+ const operations = revertOperationList[i];
251
+ _slate.Editor.withoutNormalizing(editor, () => {
252
+ for (let j = 0; j < operations.length; j++) {
253
+ const op = operations[j];
254
+ editor.apply(op);
255
+ }
256
+ });
257
+ }
258
+ };
259
+ exports.revertOperationList = revertOperationList;
260
+ const reExecRevertOperationList = (editor, revertOperationList) => {
261
+ if (revertOperationList.length === 0) return;
262
+
263
+ // Re-execute revert operations
264
+ for (let i = 0; i < revertOperationList.length; i++) {
265
+ const operations = revertOperationList[i];
266
+ _slate.Editor.withoutNormalizing(editor, () => {
267
+ for (let j = 0; j < operations.length; j++) {
268
+ const op = validateOperation(editor, operations[j]);
269
+ if (op) {
270
+ editor.apply(op);
271
+ }
272
+ }
273
+ });
274
+ }
275
+ };
276
+ exports.reExecRevertOperationList = reExecRevertOperationList;
277
+ const syncRemoteOperations = (editor, remoteOperations) => {
278
+ if (remoteOperations.length === 0) return;
279
+ _slate.Editor.withoutNormalizing(editor, () => {
280
+ for (let i = 0; i < remoteOperations.length; i++) {
281
+ const op = remoteOperations[i];
282
+ if (op.type === 'set_selection') {
283
+ continue;
284
+ }
285
+ editor.apply(op);
286
+ }
287
+ });
288
+ };
289
+ exports.syncRemoteOperations = syncRemoteOperations;
290
+ const syncRemoteCursorLocation = (editor, user, location, cursorData) => {
291
+ const currentUser = editor.user;
292
+ if (user && user.username !== currentUser.username) {
293
+ // Get front Point as cursor
294
+ const {
295
+ anchor,
296
+ focus
297
+ } = location;
298
+ let newLocation = location;
299
+ if (!_slate.Point.equals(anchor, focus)) {
300
+ const frontPoint = _slate.Editor.start(editor, location);
301
+ newLocation = {
302
+ anchor: frontPoint,
303
+ focus: frontPoint
304
+ };
305
+ }
306
+ (0, _helper.setCursor)(editor, user, newLocation, cursorData);
307
+
308
+ // sync cursor position
309
+ editor.onCursor && editor.onCursor(editor.cursors);
310
+ }
311
+ };
312
+ exports.syncRemoteCursorLocation = syncRemoteCursorLocation;
@@ -10,10 +10,10 @@ var _reactI18next = require("react-i18next");
10
10
  var _reactstrap = require("reactstrap");
11
11
  var _basicSdk = require("../../basic-sdk");
12
12
  require("./error-page.css");
13
- function ErrorPage(_ref) {
14
- let {
13
+ function ErrorPage() {
14
+ const {
15
15
  t
16
- } = _ref;
16
+ } = (0, _reactI18next.useTranslation)('sdoc-editor');
17
17
  const normalizeSdoc = (0, _react.useCallback)(async () => {
18
18
  const res = await _basicSdk.context.normalizeSdocContent();
19
19
  const {
@@ -33,4 +33,4 @@ function ErrorPage(_ref) {
33
33
  onClick: () => normalizeSdoc()
34
34
  }, t('Repair')));
35
35
  }
36
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(ErrorPage);
36
+ var _default = exports.default = ErrorPage;
@@ -1,45 +1,58 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.default = void 0;
8
- var _react = _interopRequireDefault(require("react"));
9
- var _reactI18next = require("react-i18next");
9
+ var _react = _interopRequireWildcard(require("react"));
10
10
  var _basicSdk = require("../basic-sdk");
11
11
  var _errorBoundary = _interopRequireDefault(require("../components/error-boundary"));
12
12
  const SeafileCommentEditor = _ref => {
13
13
  let {
14
+ // Provider
14
15
  type,
15
- userInfo,
16
- pluginName = '',
16
+ // comment or replay
17
17
  className = '',
18
- commentContent,
19
- hiddenUserInfo,
18
+ pluginName = '',
19
+ // sdoc or wiki or txt ...
20
+ pluginEventBus,
21
+ pluginEvent,
22
+ // Comment editor
23
+ content,
20
24
  insertContent,
21
- hiddenComment,
22
25
  onContentChange,
26
+ hiddenUserInfo,
27
+ hiddenComment,
28
+ toolMenus,
29
+ closePanel,
30
+ collaborators,
31
+ participants,
23
32
  addParticipants,
24
- pluginEventBus,
25
- pluginEvent,
33
+ // settings
34
+ settings,
26
35
  api
27
36
  } = _ref;
28
- _basicSdk.context.init(api);
29
- return /*#__PURE__*/_react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
37
+ _basicSdk.context.init(settings, api);
38
+ return /*#__PURE__*/_react.default.createElement(_react.Suspense, null, /*#__PURE__*/_react.default.createElement(_errorBoundary.default, null, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentProvider, {
30
39
  type: type,
31
- userInfo: userInfo,
32
- pluginName: pluginName,
33
40
  className: className,
41
+ pluginName: pluginName,
34
42
  pluginEventBus: pluginEventBus,
35
- pluginEvent: pluginEvent
43
+ pluginEvent: pluginEvent,
44
+ collaborators: collaborators,
45
+ participants: participants,
46
+ addParticipants: addParticipants
36
47
  }, /*#__PURE__*/_react.default.createElement(_basicSdk.CommentEditor, {
37
- commentContent: commentContent,
38
- hiddenUserInfo: hiddenUserInfo,
48
+ content: content,
39
49
  insertContent: insertContent,
40
- hiddenComment: hiddenComment,
41
50
  onContentChange: onContentChange,
51
+ hiddenUserInfo: hiddenUserInfo,
52
+ hiddenComment: hiddenComment,
53
+ toolMenus: toolMenus,
54
+ closePanel: closePanel,
42
55
  addParticipants: addParticipants
43
- })));
56
+ }))));
44
57
  };
45
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(SeafileCommentEditor);
58
+ var _default = exports.default = SeafileCommentEditor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/comment-editor",
3
- "version": "0.0.1-alpha.8",
3
+ "version": "0.0.1-alpha.81",
4
4
  "private": false,
5
5
  "description": "This is a comment editor",
6
6
  "main": "dist/index.js",
@@ -115,10 +115,10 @@
115
115
  "fs-extra": "^10.0.0",
116
116
  "html-webpack-plugin": "^5.5.0",
117
117
  "husky": "8.0.3",
118
- "i18next": "22.4.9",
119
- "i18next-browser-languagedetector": "7.0.1",
120
- "i18next-xhr-backend": "3.2.2",
121
- "identity-obj-proxy": "3.0.0",
118
+ "i18next": "^25.2.1",
119
+ "i18next-browser-languagedetector": "^8.1.0",
120
+ "i18next-http-backend": "^3.0.2",
121
+ "identity-obj-proxy": "^3.0.0",
122
122
  "is-wsl": "^1.1.0",
123
123
  "jest": "29.7.0",
124
124
  "jest-environment-jsdom": "29.7.0",
@@ -141,7 +141,7 @@
141
141
  "react-app-polyfill": "^3.0.0",
142
142
  "react-dev-utils": "^12.0.1",
143
143
  "react-dom": "18.3.1",
144
- "react-i18next": "12.1.4",
144
+ "react-i18next": "15.5.2",
145
145
  "react-refresh": "^0.11.0",
146
146
  "react-router": "7.5.2",
147
147
  "react-router-dom": "7.1.3",
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _utils = require("../comment/utils");
8
- class Notification {
9
- constructor(options) {
10
- var _options$detail, _options$detail2, _options$detail3;
11
- this.id = options.id || '';
12
- this.comment_id = (options === null || options === void 0 ? void 0 : (_options$detail = options.detail) === null || _options$detail === void 0 ? void 0 : _options$detail.comment_id) || '';
13
- this.reply_id = (options === null || options === void 0 ? void 0 : (_options$detail2 = options.detail) === null || _options$detail2 === void 0 ? void 0 : _options$detail2.reply_id) || '';
14
- this.type = (options === null || options === void 0 ? void 0 : (_options$detail3 = options.detail) === null || _options$detail3 === void 0 ? void 0 : _options$detail3.msg_type) || '';
15
- this.key = this.type !== 'reply' ? (0, _utils.generatorNotificationKey)(this.comment_id) : (0, _utils.generatorNotificationKey)(this.comment_id, this.reply_id);
16
- }
17
- }
18
- var _default = exports.default = Notification;
@@ -1,194 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/defineProperty"));
9
- var _react = _interopRequireDefault(require("react"));
10
- var _reactI18next = require("react-i18next");
11
- var _dayjs = _interopRequireDefault(require("dayjs"));
12
- var _basicSdk = require("../../basic-sdk");
13
- require("./style.css");
14
- class TipMessage extends _react.default.Component {
15
- constructor(props) {
16
- super(props);
17
- (0, _defineProperty2.default)(this, "onOperationExecuteError", () => {
18
- const {
19
- t
20
- } = this.props;
21
- const message = t('Failed_to_execute_operation_on_server');
22
- _basicSdk.toaster.warning(message, {
23
- hasCloseButton: true
24
- });
25
- });
26
- (0, _defineProperty2.default)(this, "onSyncServerOperationError", () => {
27
- const {
28
- t
29
- } = this.props;
30
- const message = t('Failed_to_sync_with_server_operations');
31
- _basicSdk.toaster.danger(message, {
32
- hasCloseButton: false,
33
- duration: null
34
- });
35
- });
36
- (0, _defineProperty2.default)(this, "onInternalServerExecError", () => {
37
- const {
38
- t
39
- } = this.props;
40
- const message = t('Internal_server_exec_operations_error');
41
- _basicSdk.toaster.danger(message, {
42
- hasCloseButton: false,
43
- duration: null
44
- });
45
- });
46
- (0, _defineProperty2.default)(this, "onTokenExpiredError", msg => {
47
- const {
48
- t
49
- } = this.props;
50
- const message = t('Token_expired_Please_refresh_the_page');
51
- _basicSdk.toaster.closeAll();
52
- _basicSdk.toaster.danger(message, {
53
- duration: null
54
- });
55
- });
56
- (0, _defineProperty2.default)(this, "onPendingOpExceedLimit", () => {
57
- const {
58
- t
59
- } = this.props;
60
- _basicSdk.toaster.closeAll();
61
- const message = t('Pending_operations_exceed_limit');
62
- _basicSdk.toaster.warning(message, {
63
- duration: 5
64
- });
65
- });
66
- (0, _defineProperty2.default)(this, "onDisconnect", () => {
67
- const {
68
- t,
69
- isEditMode
70
- } = this.props;
71
- if (!isEditMode) return;
72
- const message = t('Server_is_not_connected_Operation_will_be_sent_to_server_later');
73
- _basicSdk.toaster.warning(message, {
74
- hasCloseButton: true,
75
- duration: null
76
- });
77
- });
78
- (0, _defineProperty2.default)(this, "onReconnectError", () => {
79
- if (!this.isConnectError) {
80
- this.isConnectError = true;
81
- const {
82
- t
83
- } = this.props;
84
- const message = t('Server_is_disconnected_Reconnecting');
85
- _basicSdk.toaster.closeAll();
86
- _basicSdk.toaster.warning(message, {
87
- hasCloseButton: true,
88
- duration: null
89
- });
90
- }
91
- });
92
- (0, _defineProperty2.default)(this, "onReconnect", () => {
93
- this.isConnectError = false;
94
- const {
95
- t
96
- } = this.props;
97
- const message = t('Server_is_reconnected');
98
- _basicSdk.toaster.closeAll();
99
- _basicSdk.toaster.success(message); // close after serval seconds
100
- });
101
- (0, _defineProperty2.default)(this, "onDocumentSaving", () => {
102
- this.setState({
103
- isSaving: true,
104
- isSaved: false
105
- });
106
- });
107
- (0, _defineProperty2.default)(this, "onDocumentSaved", lastSavedAt => {
108
- if (this.saveTimer) clearTimeout(this.saveTimer);
109
- if (this.resetTimer) clearTimeout(this.resetTimer);
110
- this.saveTimer = setTimeout(() => {
111
- this.setState({
112
- lastSavedAt,
113
- isSaving: false,
114
- isSaved: true
115
- });
116
- }, 1000);
117
- this.resetTimer = setTimeout(() => {
118
- this.setState({
119
- isSaving: false,
120
- isSaved: false
121
- });
122
- }, 2000);
123
- });
124
- (0, _defineProperty2.default)(this, "render", () => {
125
- const {
126
- t
127
- } = this.props;
128
- const {
129
- isSaved,
130
- isSaving,
131
- lastSavedAt
132
- } = this.state;
133
- if (isSaving && !isSaved) {
134
- return /*#__PURE__*/_react.default.createElement("span", {
135
- className: "tip-message"
136
- }, t('Saving'));
137
- }
138
- if (!isSaving && isSaved) {
139
- return /*#__PURE__*/_react.default.createElement("span", {
140
- className: "tip-message"
141
- }, t('All_changes_saved'));
142
- }
143
- if (lastSavedAt) {
144
- return /*#__PURE__*/_react.default.createElement("span", {
145
- className: "tip-message"
146
- }, /*#__PURE__*/_react.default.createElement("span", {
147
- className: "sdocfont sdoc-save-tip mr-2"
148
- }), /*#__PURE__*/_react.default.createElement("span", {
149
- className: "save-time"
150
- }, (0, _dayjs.default)(lastSavedAt).format('HH:mm')));
151
- }
152
- return null;
153
- });
154
- this.state = {
155
- isSaved: false,
156
- isSaving: false,
157
- lastSavedAt: ''
158
- };
159
- this.saveTimer = null;
160
- }
161
- componentDidMount() {
162
- const eventBus = _basicSdk.EventBus.getInstance();
163
- this.unsubscribeSavingEvent = eventBus.subscribe('is-saving', this.onDocumentSaving);
164
- this.unsubscribeSavedEvent = eventBus.subscribe('saved', this.onDocumentSaved);
165
- // offline reconnect
166
- this.unsubscribeDisconnectEvent = eventBus.subscribe('disconnect', this.onDisconnect);
167
- this.unsubscribeReconnectErrorEvent = eventBus.subscribe('reconnect_error', this.onReconnectError);
168
- this.unsubscribeReconnectEvent = eventBus.subscribe('reconnect', this.onReconnect);
169
-
170
- // server return error
171
- this.unsubscribeOpExecError = eventBus.subscribe('execute_client_operations_error', this.onOperationExecuteError);
172
- this.unsubscribeSyncServerOpError = eventBus.subscribe('sync_server_operations_error', this.onSyncServerOperationError);
173
- this.unsubscribeDocumentLoadError = eventBus.subscribe('load_document_content_error', this.onInternalServerExecError);
174
- this.unsubscribeOperationsSaveError = eventBus.subscribe('save_operations_to_database_error', this.onInternalServerExecError);
175
- this.unsubscribeOperationsSaveError = eventBus.subscribe('token_expired', this.onTokenExpiredError);
176
-
177
- // local error
178
- this.unsubscribePendingOpExceedLimit = eventBus.subscribe('pending_operations_exceed_limit', this.onPendingOpExceedLimit);
179
- }
180
- componentWillUnmount() {
181
- this.unsubscribeSavingEvent();
182
- this.unsubscribeSavedEvent();
183
- this.unsubscribeDisconnectEvent();
184
- this.unsubscribeReconnectErrorEvent();
185
- this.unsubscribeReconnectEvent();
186
- this.unsubscribeOpExecError();
187
- this.unsubscribeSyncServerOpError();
188
- this.unsubscribePendingOpExceedLimit();
189
- this.unsubscribeDocumentLoadError();
190
- this.unsubscribeOperationsSaveError();
191
- clearTimeout(this.saveTimer);
192
- }
193
- }
194
- var _default = exports.default = (0, _reactI18next.withTranslation)('sdoc-editor')(TipMessage);
@@ -1,15 +0,0 @@
1
- .sdoc-editor-page-wrapper .tip-message {
2
- margin-left: 12px;
3
- font-size: 12px;
4
- opacity: 0.75;
5
- color: #999;
6
- width: max-content;
7
- height: 27px;
8
- line-height: 27px;
9
- display: inline-flex;
10
- }
11
-
12
- .sdoc-editor-page-wrapper .tip-message .sdocfont {
13
- padding-top: 1px;
14
- font-size: 14px;
15
- }