@seafile/sdoc-editor 0.5.29 → 0.5.30

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.
@@ -41,6 +41,12 @@ const SdocEditor = forwardRef((_ref, ref) => {
41
41
  // eslint-disable-next-line react-hooks/exhaustive-deps
42
42
  }, []);
43
43
  const [slateValue, setSlateValue] = useState(document.children);
44
+
45
+ // Fix: The editor's children are not updated when the document is updated in revision
46
+ // In revision mode, the document is updated, but the editor's children are not updated,as onValueChange override the new document.children. This unexpected action cause the editor to display the old content
47
+ useEffect(() => {
48
+ setSlateValue(document.children);
49
+ }, [document.children]);
44
50
  useEffect(() => {
45
51
  validEditor.readonly = false;
46
52
  return () => {
@@ -49,7 +55,6 @@ const SdocEditor = forwardRef((_ref, ref) => {
49
55
 
50
56
  // eslint-disable-next-line react-hooks/exhaustive-deps
51
57
  }, []);
52
-
53
58
  // useMount: init socket connection
54
59
  useEffect(() => {
55
60
  if (propsEditor) return;
@@ -57,7 +62,6 @@ const SdocEditor = forwardRef((_ref, ref) => {
57
62
  return () => {
58
63
  validEditor.closeConnection();
59
64
  };
60
-
61
65
  // eslint-disable-next-line react-hooks/exhaustive-deps
62
66
  }, []);
63
67
 
@@ -46,7 +46,6 @@ export const MOUSE_ENTER_EVENT_DISABLED_MAP = {
46
46
  [CHECK_LIST_ITEM]: [CALL_OUT],
47
47
  [ORDERED_LIST]: [CALL_OUT],
48
48
  [UNORDERED_LIST]: [CALL_OUT],
49
- [UNORDERED_LIST]: [CALL_OUT],
50
49
  [LIST_ITEM]: [CALL_OUT],
51
50
  [BLOCKQUOTE]: [CALL_OUT],
52
51
  [HEADER1]: [CALL_OUT],
@@ -57,4 +56,5 @@ export const MOUSE_ENTER_EVENT_DISABLED_MAP = {
57
56
  [HEADER6]: [CALL_OUT],
58
57
  [CALL_OUT]: [CALL_OUT]
59
58
  };
59
+ export const ROOT_ELEMENT_TYPES = [PARAGRAPH, TITLE, SUBTITLE, CHECK_LIST_ITEM, ORDERED_LIST, UNORDERED_LIST, BLOCKQUOTE, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, CALL_OUT, TABLE];
60
60
  export { ELEMENT_TYPE, BLOCKQUOTE, TITLE, SUBTITLE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, CHECK_LIST_ITEM, CODE_BLOCK, CODE_LINE, TABLE, TABLE_CELL, TABLE_ROW, LINK, SDOC_LINK, FILE_LINK, IMAGE, IMAGE_BLOCK, TOP_LEVEL_TYPES, INLINE_LEVEL_TYPES, CALL_OUT, MENTION, MENTION_TEMP };
@@ -4,7 +4,7 @@ import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4,
4
4
  import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin, CalloutPlugin, MentionPlugin } from '../plugins';
5
5
  import { onDragOver, onDragLeave, onDrop } from '../toolbar/side-toolbar/event';
6
6
  import { getParentNode } from '../core';
7
- import { setMouseEnter } from './helper';
7
+ import { setDataRoot, setMouseEnter } from './helper';
8
8
  const CustomRenderElement = props => {
9
9
  const editor = useSlateStatic();
10
10
  const readonly = useReadOnly();
@@ -19,6 +19,9 @@ const CustomRenderElement = props => {
19
19
  attributes['onDrop'] = onDrop;
20
20
  attributes['className'] = 'sdoc-drag-cover';
21
21
  }
22
+
23
+ // Sets the data-root attribute to true for certain elements
24
+ setDataRoot(element, attributes);
22
25
  switch (element.type) {
23
26
  case PARAGRAPH:
24
27
  {
@@ -1,6 +1,6 @@
1
1
  import { Editor } from '@seafile/slate';
2
2
  import { findPath } from '../core';
3
- import { MOUSE_ENTER_EVENT_DISABLED_MAP } from '../constants';
3
+ import { MOUSE_ENTER_EVENT_DISABLED_MAP, ROOT_ELEMENT_TYPES } from '../constants';
4
4
  import { onMouseEnter } from '../toolbar/side-toolbar/event';
5
5
  const isNeedAddMouseEnterEvent = (editor, element) => {
6
6
  const elementPath = findPath(editor, element);
@@ -18,5 +18,8 @@ const isNeedAddMouseEnterEvent = (editor, element) => {
18
18
  export const setMouseEnter = (editor, element, attributes) => {
19
19
  if (!isNeedAddMouseEnterEvent(editor, element)) return;
20
20
  attributes['onMouseEnter'] = e => onMouseEnter(e, element);
21
+ };
22
+ export const setDataRoot = (element, attributes) => {
23
+ if (!ROOT_ELEMENT_TYPES.includes(element.type)) return;
21
24
  attributes['data-root'] = 'true';
22
25
  };
@@ -20,11 +20,17 @@ const generatorDiffTextElement = function (textElement, diffType) {
20
20
  export const getTopLevelChanges = changes => {
21
21
  const topLevelChanges = [];
22
22
  changes.forEach(item => {
23
- let dom = document.querySelectorAll("[data-id=".concat(item, "]"))[0];
23
+ let dom = document.querySelectorAll("[data-id=\"".concat(item, "\"]"))[0];
24
+ if (!dom) return [];
24
25
  while (((_dom = dom) === null || _dom === void 0 ? void 0 : (_dom$dataset = _dom.dataset) === null || _dom$dataset === void 0 ? void 0 : _dom$dataset.root) !== 'true') {
25
26
  var _dom, _dom$dataset, _dom2;
26
- if (!((_dom2 = dom) === null || _dom2 === void 0 ? void 0 : _dom2.parentNode)) break;
27
- dom = dom.parentNode;
27
+ if (!((_dom2 = dom) === null || _dom2 === void 0 ? void 0 : _dom2.parentNode) || dom instanceof Document) break;
28
+ const parentNode = dom.parentNode;
29
+ if (parentNode instanceof Document) {
30
+ break;
31
+ } else {
32
+ dom = parentNode;
33
+ }
28
34
  }
29
35
  topLevelChanges.push(dom.dataset.id);
30
36
  });
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useState } from 'react';
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import Tooltip from '../../../tooltip';
4
4
  import { getTopLevelChanges } from '../../../../basic-sdk/utils/diff';
@@ -12,18 +12,32 @@ const ChangesCount = _ref => {
12
12
  } = useTranslation();
13
13
  const [currentDiffIndex, setDiffIndex] = useState(0);
14
14
  const [topLevelChanges, setTopLevelChanges] = useState([]);
15
+ const intervalRef = useRef();
15
16
  useEffect(() => {
16
- if (changes.length !== 0) {
17
- queueMicrotask(() => {
17
+ // Article rendering is delayed, so we need to wait for the Article to render before we can get the changes
18
+ new Promise(resolve => {
19
+ intervalRef.current = setInterval(() => {
20
+ const article = document.querySelector('.article');
21
+ if (article) {
22
+ clearInterval(intervalRef.current);
23
+ intervalRef.current = null;
24
+ resolve();
25
+ }
26
+ }, 100);
27
+ }).then(() => {
28
+ if (changes.length !== 0) {
18
29
  const topLevelChanges = getTopLevelChanges(changes);
19
30
  setTopLevelChanges([...topLevelChanges]);
20
- });
21
- }
31
+ }
32
+ });
33
+ return () => {
34
+ intervalRef.current && clearInterval(intervalRef.current);
35
+ };
22
36
  }, [changes]);
23
37
  const jumpToElement = useCallback(currentDiffIndex => {
24
38
  setDiffIndex(currentDiffIndex);
25
39
  const change = topLevelChanges[currentDiffIndex];
26
- const changeElement = document.querySelectorAll("[data-id=".concat(change, "]"))[0];
40
+ const changeElement = document.querySelectorAll("[data-id=\"".concat(change, "\"]"))[0];
27
41
  if (changeElement) {
28
42
  const scrollContainer = document.getElementById('sdoc-scroll-container');
29
43
  if (scrollContainer) {
@@ -55,8 +55,8 @@ const SimpleEditor = _ref => {
55
55
  }
56
56
 
57
57
  // Get the contents of the current revision
58
- const revisionContent = editorRef.current.getSlateValue();
59
- setRevisionContent(revisionContent);
58
+ const revisionContentValue = editorRef.current.getSlateValue();
59
+ setRevisionContent(revisionContentValue);
60
60
  setShowChanges(isShowChanges);
61
61
  // eslint-disable-next-line react-hooks/exhaustive-deps
62
62
  }, [document, editorRef.current, isPublished]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.5.29",
3
+ "version": "0.5.30",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",