@seafile/sdoc-editor 0.5.5 → 0.5.6
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.
|
@@ -67,13 +67,13 @@ const withBlockquote = editor => {
|
|
|
67
67
|
if (currentLineIndex === 0 && isBlockAboveEmpty(newEditor)) {
|
|
68
68
|
const emptyParagraph = generateEmptyElement(PARAGRAPH);
|
|
69
69
|
Transforms.removeNodes(editor, {
|
|
70
|
-
at:
|
|
70
|
+
at: blockQuoteEntry[1]
|
|
71
71
|
});
|
|
72
72
|
Transforms.insertNodes(newEditor, emptyParagraph, {
|
|
73
73
|
at: blockQuoteEntry[1]
|
|
74
74
|
});
|
|
75
|
-
const
|
|
76
|
-
focusEditor(newEditor,
|
|
75
|
+
const focusPoint = Editor.end(newEditor, blockQuoteEntry[1]);
|
|
76
|
+
focusEditor(newEditor, focusPoint);
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
// Merge with previous line when Select at the beginning of the line
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Editor, Node, Path, Transforms } from '@seafile/slate';
|
|
2
|
-
import { CALL_OUT } from '../../constants/element-type';
|
|
2
|
+
import { CALL_OUT, PARAGRAPH } from '../../constants/element-type';
|
|
3
3
|
import { focusEditor, generateEmptyElement, getSelectedElems, isRangeAcrossBlocks } from '../../core';
|
|
4
4
|
import { CALLOUT_ALLOWED_INSIDE_TYPES, CALLOUT_COLOR_MAP } from './constant';
|
|
5
5
|
export const isMenuActive = editor => {
|
|
@@ -110,7 +110,10 @@ export const getCalloutEntry = function (editor) {
|
|
|
110
110
|
export const isCalloutContentEmpty = calloutEntry => {
|
|
111
111
|
const [calloutNode] = calloutEntry;
|
|
112
112
|
const contentString = Node.string(calloutNode);
|
|
113
|
-
|
|
113
|
+
const calloutChildren = calloutNode.children;
|
|
114
|
+
const isSingleParagraph = calloutChildren.length === 1 && calloutChildren[0].type === PARAGRAPH;
|
|
115
|
+
const isEmptyContent = contentString.length === 0;
|
|
116
|
+
return isSingleParagraph && isEmptyContent;
|
|
114
117
|
};
|
|
115
118
|
|
|
116
119
|
// Insert a new element at new line in callout after current path
|
|
@@ -17,6 +17,19 @@ const generatorDiffTextElement = function (textElement, diffType) {
|
|
|
17
17
|
[diffType]: true
|
|
18
18
|
}, style);
|
|
19
19
|
};
|
|
20
|
+
export const getTopLevelChanges = changes => {
|
|
21
|
+
const topLevelChanges = [];
|
|
22
|
+
changes.forEach(item => {
|
|
23
|
+
let dom = document.querySelectorAll("[data-id=".concat(item, "]"))[0];
|
|
24
|
+
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
|
+
var _dom, _dom$dataset, _dom2;
|
|
26
|
+
if (!((_dom2 = dom) === null || _dom2 === void 0 ? void 0 : _dom2.parentNode)) break;
|
|
27
|
+
dom = dom.parentNode;
|
|
28
|
+
}
|
|
29
|
+
topLevelChanges.push(dom.dataset.id);
|
|
30
|
+
});
|
|
31
|
+
return Array.from(new Set(topLevelChanges));
|
|
32
|
+
};
|
|
20
33
|
|
|
21
34
|
// Depth facilitates each child node, adding diffType to each end node
|
|
22
35
|
const generatorDiffElement = function (element, diffType) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React, { useCallback, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import Tooltip from '../../../tooltip';
|
|
4
|
+
import { getTopLevelChanges } from '../../../../basic-sdk/utils/diff';
|
|
4
5
|
import './index.css';
|
|
5
6
|
const ChangesCount = _ref => {
|
|
6
7
|
let {
|
|
@@ -10,9 +11,18 @@ const ChangesCount = _ref => {
|
|
|
10
11
|
t
|
|
11
12
|
} = useTranslation();
|
|
12
13
|
const [currentDiffIndex, setDiffIndex] = useState(0);
|
|
14
|
+
const [topLevelChanges, setTopLevelChanges] = useState([]);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (changes.length !== 0) {
|
|
17
|
+
queueMicrotask(() => {
|
|
18
|
+
const topLevelChanges = getTopLevelChanges(changes);
|
|
19
|
+
setTopLevelChanges([...topLevelChanges]);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}, [changes]);
|
|
13
23
|
const jumpToElement = useCallback(currentDiffIndex => {
|
|
14
24
|
setDiffIndex(currentDiffIndex);
|
|
15
|
-
const change =
|
|
25
|
+
const change = topLevelChanges[currentDiffIndex];
|
|
16
26
|
const changeElement = document.querySelectorAll("[data-id=".concat(change, "]"))[0];
|
|
17
27
|
if (changeElement) {
|
|
18
28
|
const scrollContainer = document.getElementById('sdoc-scroll-container');
|
|
@@ -22,31 +32,31 @@ const ChangesCount = _ref => {
|
|
|
22
32
|
}
|
|
23
33
|
|
|
24
34
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
-
}, [
|
|
35
|
+
}, [topLevelChanges, currentDiffIndex]);
|
|
26
36
|
const lastChange = useCallback(() => {
|
|
27
37
|
if (currentDiffIndex === 0) {
|
|
28
|
-
jumpToElement(
|
|
38
|
+
jumpToElement(topLevelChanges.length - 1);
|
|
29
39
|
return;
|
|
30
40
|
}
|
|
31
41
|
jumpToElement(currentDiffIndex - 1);
|
|
32
42
|
|
|
33
43
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
34
|
-
}, [
|
|
44
|
+
}, [topLevelChanges, currentDiffIndex]);
|
|
35
45
|
const nextChange = useCallback(() => {
|
|
36
|
-
if (currentDiffIndex ===
|
|
46
|
+
if (currentDiffIndex === topLevelChanges.length - 1) {
|
|
37
47
|
jumpToElement(0);
|
|
38
48
|
return;
|
|
39
49
|
}
|
|
40
50
|
jumpToElement(currentDiffIndex + 1);
|
|
41
51
|
|
|
42
52
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
-
}, [
|
|
44
|
-
if (!Array.isArray(
|
|
53
|
+
}, [topLevelChanges, currentDiffIndex]);
|
|
54
|
+
if (!Array.isArray(topLevelChanges) || topLevelChanges.length === 0) {
|
|
45
55
|
return /*#__PURE__*/React.createElement("div", {
|
|
46
56
|
className: "sdoc-revision-changes-container d-flex align-items-center pl-2 pr-2 ml-4"
|
|
47
57
|
}, t('No_changes'));
|
|
48
58
|
}
|
|
49
|
-
const changesCount =
|
|
59
|
+
const changesCount = topLevelChanges.length;
|
|
50
60
|
return /*#__PURE__*/React.createElement("div", {
|
|
51
61
|
className: "sdoc-revision-changes-container d-flex align-items-center ml-4"
|
|
52
62
|
}, /*#__PURE__*/React.createElement("div", {
|