@seafile/sdoc-editor 0.1.67-beta → 0.1.68-beta
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.
- package/dist/basic-sdk/assets/css/code-block.css +8 -5
- package/dist/basic-sdk/comment/style.css +1 -0
- package/dist/basic-sdk/editor.js +4 -2
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +72 -4
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +4 -4
- package/dist/basic-sdk/extension/render/render-element.js +1 -0
- package/dist/basic-sdk/hooks/use-scroll-context.js +1 -1
- package/dist/basic-sdk/index.js +2 -2
- package/dist/{pages/diff-viewer → basic-sdk/views}/diff-viewer.js +4 -4
- package/dist/basic-sdk/views/index.js +3 -0
- package/dist/basic-sdk/{viewer.js → views/viewer.js} +6 -6
- package/dist/components/code-block-hover-menu/index.css +2 -2
- package/dist/components/doc-operations/history-operation.js +2 -0
- package/dist/components/doc-operations/{revision-operations/index.js → revision-operations.js} +3 -3
- package/dist/pages/diff-viewer/index.js +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
.sdoc-code-block-pre {
|
|
6
|
-
|
|
6
|
+
background: #FAFAFA;
|
|
7
|
+
border: 1px solid #f0f0f0;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
.sdoc-code-block-pre .sdoc-code-no-wrap {
|
|
@@ -16,19 +17,21 @@
|
|
|
16
17
|
|
|
17
18
|
.sdoc-code-block-code .sdoc-code-line {
|
|
18
19
|
position: relative;
|
|
19
|
-
padding-left:
|
|
20
|
+
padding-left: 24px;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
.sdoc-code-block-code .sdoc-code-line .sdoc-code-line-index {
|
|
23
24
|
position: absolute;
|
|
24
|
-
left: -
|
|
25
|
+
left: -8px;
|
|
25
26
|
color: #ccc;
|
|
26
|
-
width: 10px;
|
|
27
|
-
height: 10px;
|
|
28
27
|
caret-color: transparent;
|
|
29
28
|
pointer-events: none;
|
|
30
29
|
}
|
|
31
30
|
|
|
31
|
+
.sdoc-code-block-code .sdoc-code-line .sdoc-code-line-index::selection {
|
|
32
|
+
background: transparent;
|
|
33
|
+
}
|
|
34
|
+
|
|
32
35
|
.sdoc-code-line
|
|
33
36
|
.token.comment,
|
|
34
37
|
.token.prolog,
|
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -47,6 +47,7 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
47
47
|
var _useCursors = useCursors(editor),
|
|
48
48
|
cursors = _useCursors.cursors;
|
|
49
49
|
var scrollRef = useRef(null);
|
|
50
|
+
var articleRef = useRef(null);
|
|
50
51
|
var decorate = usePipDecorate(editor);
|
|
51
52
|
|
|
52
53
|
// init eventHandler
|
|
@@ -59,7 +60,7 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
59
60
|
// useMount: init socket connection
|
|
60
61
|
useEffect(function () {
|
|
61
62
|
editor.openConnection();
|
|
62
|
-
editor.width =
|
|
63
|
+
editor.width = articleRef.current.children[0].clientWidth;
|
|
63
64
|
return function () {
|
|
64
65
|
editor.closeConnection();
|
|
65
66
|
};
|
|
@@ -121,7 +122,8 @@ var SDocEditor = function SDocEditor(_ref) {
|
|
|
121
122
|
value: slateValue,
|
|
122
123
|
onChange: onChange
|
|
123
124
|
}, /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement("div", {
|
|
124
|
-
className: "article"
|
|
125
|
+
className: "article",
|
|
126
|
+
ref: articleRef
|
|
125
127
|
}, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
126
128
|
renderElement: renderElement,
|
|
127
129
|
renderLeaf: renderLeaf,
|
|
@@ -1,10 +1,78 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import slugid from 'slugid';
|
|
5
|
+
import { Transforms, Node, Range, Editor } from '@seafile/slate';
|
|
6
|
+
import { getNodeType, isLastNode, genEmptyParagraph, getSelectedNodeByType, generateEmptyElement } from '../../core';
|
|
7
|
+
import { CODE_BLOCK, PARAGRAPH, CODE_LINE } from '../../constants';
|
|
5
8
|
var withCodeBlock = function withCodeBlock(editor) {
|
|
6
|
-
var normalizeNode = editor.normalizeNode
|
|
9
|
+
var normalizeNode = editor.normalizeNode,
|
|
10
|
+
insertFragment = editor.insertFragment,
|
|
11
|
+
insertText = editor.insertText,
|
|
12
|
+
insertBreak = editor.insertBreak;
|
|
7
13
|
var newEditor = editor;
|
|
14
|
+
newEditor.insertFragment = function (data) {
|
|
15
|
+
// only selected code block content
|
|
16
|
+
if (data.length === 1 && data[0].type === CODE_BLOCK && !getSelectedNodeByType(editor, CODE_BLOCK)) {
|
|
17
|
+
data.forEach(function (node, index) {
|
|
18
|
+
if (node.type === CODE_BLOCK) {
|
|
19
|
+
var newBlock = node.children.map(function (line) {
|
|
20
|
+
var text = Node.string(line);
|
|
21
|
+
var p = generateEmptyElement(PARAGRAPH);
|
|
22
|
+
p.children[0].text = text;
|
|
23
|
+
return p;
|
|
24
|
+
});
|
|
25
|
+
data.splice.apply(data, [index, 1].concat(_toConsumableArray(newBlock)));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return insertFragment(data);
|
|
29
|
+
} else {
|
|
30
|
+
if (getSelectedNodeByType(editor, CODE_BLOCK)) {
|
|
31
|
+
// Paste into code block
|
|
32
|
+
|
|
33
|
+
// Pasted data is code block split with code-line
|
|
34
|
+
data.forEach(function (node, index) {
|
|
35
|
+
if (node.type === CODE_BLOCK) {
|
|
36
|
+
var codeLineArr = node.children.map(function (line) {
|
|
37
|
+
return line;
|
|
38
|
+
});
|
|
39
|
+
data.splice.apply(data, [index, 1].concat(_toConsumableArray(codeLineArr)));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var newData = data.map(function (node) {
|
|
43
|
+
var text = Node.string(node);
|
|
44
|
+
var codeLine = {
|
|
45
|
+
id: slugid.nice(),
|
|
46
|
+
type: CODE_LINE,
|
|
47
|
+
children: [{
|
|
48
|
+
text: text,
|
|
49
|
+
id: slugid.nice()
|
|
50
|
+
}]
|
|
51
|
+
};
|
|
52
|
+
return codeLine;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// current focus code-line string not empty
|
|
56
|
+
var string = Editor.string(newEditor, newEditor.selection.focus.path);
|
|
57
|
+
if (string.length !== 0 && Range.isCollapsed(newEditor.selection)) {
|
|
58
|
+
var _newData = _toArray(newData),
|
|
59
|
+
node = _newData[0],
|
|
60
|
+
restNode = _newData.slice(1);
|
|
61
|
+
var text = Node.string(node);
|
|
62
|
+
insertText(text);
|
|
63
|
+
if (restNode.length !== 0) {
|
|
64
|
+
insertBreak();
|
|
65
|
+
insertFragment(restNode);
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
return insertFragment(newData);
|
|
70
|
+
} else {
|
|
71
|
+
// Paste into not a code block
|
|
72
|
+
return insertFragment(data);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
8
76
|
|
|
9
77
|
// Rewrite normalizeNode
|
|
10
78
|
newEditor.normalizeNode = function (_ref) {
|
|
@@ -10,6 +10,7 @@ import { TABLE_ROW_MIN_HEIGHT } from '../constants';
|
|
|
10
10
|
import { updateTableRowHeight } from '../helpers';
|
|
11
11
|
import { eventStopPropagation, getMouseDownInfo, getMouseMoveInfo, registerResizeEvents, unregisterResizeEvents } from '../../../../utils/mouse-event';
|
|
12
12
|
import { useSettingSelectRangeContext, useResizeHandlersContext } from './hooks';
|
|
13
|
+
import { useScrollContext } from '../../../../hooks/use-scroll-context';
|
|
13
14
|
var TableRow = function TableRow(_ref) {
|
|
14
15
|
var _element$style;
|
|
15
16
|
var element = _ref.element,
|
|
@@ -36,11 +37,11 @@ var TableRow = function TableRow(_ref) {
|
|
|
36
37
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
37
38
|
height = _useState6[0],
|
|
38
39
|
setHeight = _useState6[1];
|
|
40
|
+
var scrollContent = useScrollContext();
|
|
39
41
|
var onMouseDown = useCallback(function (event) {
|
|
40
42
|
eventStopPropagation(event);
|
|
41
43
|
Transforms.deselect(editor);
|
|
42
|
-
var
|
|
43
|
-
var mouseDownInfo = getMouseDownInfo(event, pageElement);
|
|
44
|
+
var mouseDownInfo = getMouseDownInfo(event, scrollContent.current);
|
|
44
45
|
setMouseDownInfo(mouseDownInfo);
|
|
45
46
|
setIsResizing(true);
|
|
46
47
|
|
|
@@ -50,8 +51,7 @@ var TableRow = function TableRow(_ref) {
|
|
|
50
51
|
if (!isResizing) return;
|
|
51
52
|
var onMouseMove = function onMouseMove(event) {
|
|
52
53
|
eventStopPropagation(event);
|
|
53
|
-
var
|
|
54
|
-
var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, pageElement);
|
|
54
|
+
var mouseMoveInfo = getMouseMoveInfo(event, mouseDownInfo, scrollContent.current);
|
|
55
55
|
var newHeight = tableRow.current + mouseMoveInfo.displacementY;
|
|
56
56
|
var validHeight = Math.max(TABLE_ROW_MIN_HEIGHT, newHeight);
|
|
57
57
|
setHeight(validHeight);
|
|
@@ -99,6 +99,7 @@ var CustomElement = function CustomElement(props) {
|
|
|
99
99
|
return /*#__PURE__*/React.createElement("div", Object.assign({}, attributes, {
|
|
100
100
|
className: 'sdoc-code-line'
|
|
101
101
|
}), lineNumber && /*#__PURE__*/React.createElement("span", {
|
|
102
|
+
spellCheck: false,
|
|
102
103
|
className: "sdoc-code-line-index"
|
|
103
104
|
}, lineNumber), children);
|
|
104
105
|
}
|
package/dist/basic-sdk/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import SDocEditor from './editor';
|
|
2
|
-
import SDocViewer from './
|
|
2
|
+
import { DiffViewer, SDocViewer } from './views';
|
|
3
3
|
import SDocOutline from './outline';
|
|
4
4
|
import EventBus from './utils/event-bus';
|
|
5
|
-
export { SDocEditor, SDocViewer, SDocOutline, EventBus };
|
|
5
|
+
export { SDocEditor, SDocViewer, SDocOutline, EventBus, DiffViewer };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useCallback, useEffect } from 'react';
|
|
2
|
-
import { renderLeaf, renderElement } from '
|
|
3
|
-
import { getDiff } from '
|
|
2
|
+
import { renderLeaf, renderElement } from '../extension';
|
|
3
|
+
import { getDiff } from '../utils/diff';
|
|
4
4
|
import context from '../../context';
|
|
5
|
-
import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '
|
|
6
|
-
import
|
|
5
|
+
import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../extension/constants';
|
|
6
|
+
import SDocViewer from './viewer';
|
|
7
7
|
import '../../assets/css/diff-viewer.css';
|
|
8
8
|
var DiffViewer = function DiffViewer(_ref) {
|
|
9
9
|
var currentContent = _ref.currentContent,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React, { useRef, useEffect, useState } from 'react';
|
|
3
3
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
4
|
-
import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from '
|
|
5
|
-
import { withSocketIO } from '
|
|
6
|
-
import withNodeId from '
|
|
7
|
-
import '
|
|
8
|
-
import '
|
|
9
|
-
import { generateDefaultDocContent } from '
|
|
4
|
+
import defaultEditor, { renderLeaf as _renderLeaf, renderElement as _renderElement } from '../extension';
|
|
5
|
+
import { withSocketIO } from '../socket';
|
|
6
|
+
import withNodeId from '../node-id';
|
|
7
|
+
import '../assets/css/layout.css';
|
|
8
|
+
import '../assets/css/sdoc-editor-plugins.css';
|
|
9
|
+
import { generateDefaultDocContent } from '../../utils';
|
|
10
10
|
var SDocViewer = function SDocViewer(_ref) {
|
|
11
11
|
var isOpenSocket = _ref.isOpenSocket,
|
|
12
12
|
document = _ref.document,
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
.sdoc-code-block-hover-menu-container .hover-menu-container .op-item {
|
|
27
27
|
font-size: 12px;
|
|
28
28
|
color: #212529;
|
|
29
|
-
padding: 0
|
|
29
|
+
padding: 0 3px;
|
|
30
30
|
border-radius: 2px;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
.sdoc-code-block-hover-menu-container .hover-menu-container .icon-font {
|
|
40
|
-
font-size:
|
|
40
|
+
font-size: 14px;
|
|
41
41
|
color: #999999;
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -3,6 +3,7 @@ import context from '../../context';
|
|
|
3
3
|
var HistoryOperation = function HistoryOperation() {
|
|
4
4
|
var docPerm = context.getSetting('docPerm');
|
|
5
5
|
var historyURL = context.getSetting('historyURL');
|
|
6
|
+
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
6
7
|
var toggleHistory = useCallback(function (event) {
|
|
7
8
|
event.stopPropagation();
|
|
8
9
|
event.nativeEvent.stopImmediatePropagation();
|
|
@@ -11,6 +12,7 @@ var HistoryOperation = function HistoryOperation() {
|
|
|
11
12
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
12
13
|
}, []);
|
|
13
14
|
if (docPerm !== 'rw' || !historyURL) return null;
|
|
15
|
+
if (isSdocRevision) return null;
|
|
14
16
|
return /*#__PURE__*/React.createElement("span", {
|
|
15
17
|
className: "op-item",
|
|
16
18
|
onClick: toggleHistory
|
package/dist/components/doc-operations/{revision-operations/index.js → revision-operations.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import { Button } from 'reactstrap';
|
|
3
3
|
import { withTranslation } from 'react-i18next';
|
|
4
|
-
import context from '
|
|
5
|
-
import toaster from '
|
|
4
|
+
import context from '../../context';
|
|
5
|
+
import toaster from '../../components/toast';
|
|
6
6
|
var RevisionOperations = function RevisionOperations(_ref) {
|
|
7
7
|
var t = _ref.t;
|
|
8
8
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
@@ -30,7 +30,7 @@ var RevisionOperations = function RevisionOperations(_ref) {
|
|
|
30
30
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
31
|
}, []);
|
|
32
32
|
if (!isSdocRevision) return null;
|
|
33
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, revisionURL && /*#__PURE__*/React.createElement(Button, {
|
|
33
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, !isPublished && revisionURL && /*#__PURE__*/React.createElement(Button, {
|
|
34
34
|
color: "success",
|
|
35
35
|
className: "mr-4",
|
|
36
36
|
onClick: viewChanges
|
|
@@ -4,7 +4,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
|
4
4
|
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
5
|
import React, { Component } from 'react';
|
|
6
6
|
import HistoryVersionViewer from './history-version-viewer';
|
|
7
|
-
import DiffViewer from '
|
|
7
|
+
import { DiffViewer } from '../../basic-sdk';
|
|
8
8
|
import context from '../../context';
|
|
9
9
|
var Index = /*#__PURE__*/function (_Component) {
|
|
10
10
|
_inherits(Index, _Component);
|