@seafile/sdoc-editor 0.1.158 → 0.1.159-beta11
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/api/seafile-api.js +28 -9
- package/dist/basic-sdk/constants/index.js +25 -1
- package/dist/basic-sdk/editor/common-editor.js +50 -0
- package/dist/basic-sdk/editor/index.css +29 -0
- package/dist/basic-sdk/editor/index.js +129 -0
- package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
- package/dist/basic-sdk/extension/constants/element-type.js +6 -1
- package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
- package/dist/basic-sdk/extension/plugins/font/helpers.js +1 -3
- package/dist/basic-sdk/extension/plugins/text-style/render-elem.js +4 -3
- package/dist/basic-sdk/extension/render/render-element.js +221 -1
- package/dist/basic-sdk/socket/helpers.js +2 -0
- package/dist/basic-sdk/socket/socket-client.js +51 -0
- package/dist/basic-sdk/socket/socket-manager.js +31 -2
- package/dist/basic-sdk/socket/with-socket-io.js +35 -12
- package/dist/basic-sdk/utils/diff.js +4 -3
- package/dist/basic-sdk/utils/rebase.js +193 -0
- package/dist/basic-sdk/views/diff-viewer.js +3 -1
- package/dist/basic-sdk/views/viewer.js +9 -12
- package/dist/components/doc-operations/index.js +4 -2
- package/dist/components/doc-operations/revision-operations/index.js +5 -2
- package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
- package/dist/components/tip-dialog/index.js +50 -0
- package/dist/components/tip-dialog/tip-content.js +47 -0
- package/dist/constants/index.js +26 -2
- package/dist/context.js +43 -9
- package/dist/pages/simple-editor.js +245 -88
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +12 -1
- package/public/locales/zh_CN/sdoc-editor.json +10 -1
- package/dist/basic-sdk/editor.js +0 -105
package/dist/api/seafile-api.js
CHANGED
|
@@ -3,7 +3,12 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
var SeafileAPI = /*#__PURE__*/function () {
|
|
5
5
|
function SeafileAPI(server, token) {
|
|
6
|
+
var _this = this;
|
|
6
7
|
_classCallCheck(this, SeafileAPI);
|
|
8
|
+
this.deleteSdocRevision = function (docUuid) {
|
|
9
|
+
var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
|
|
10
|
+
return _this.req.delete(url);
|
|
11
|
+
};
|
|
7
12
|
this.req = axios.create({
|
|
8
13
|
baseURL: server,
|
|
9
14
|
headers: {
|
|
@@ -46,12 +51,6 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
46
51
|
var url = '/api/v2.1/seadoc/download-image/' + docUuid + '/' + encodeURIComponent(imageName);
|
|
47
52
|
return this.req.get(url);
|
|
48
53
|
}
|
|
49
|
-
}, {
|
|
50
|
-
key: "sdocPublishRevision",
|
|
51
|
-
value: function sdocPublishRevision(docUuid) {
|
|
52
|
-
var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
|
|
53
|
-
return this.req.post(url);
|
|
54
|
-
}
|
|
55
54
|
}, {
|
|
56
55
|
key: "startRevise",
|
|
57
56
|
value: function startRevise(repoID, fileUuid, path) {
|
|
@@ -63,9 +62,9 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
63
62
|
return this._sendPostRequest(url, form);
|
|
64
63
|
}
|
|
65
64
|
}, {
|
|
66
|
-
key: "
|
|
67
|
-
value: function
|
|
68
|
-
var url = '/api/v2.1/seadoc/revision/
|
|
65
|
+
key: "getSeadocOriginFileContent",
|
|
66
|
+
value: function getSeadocOriginFileContent(docUuid) {
|
|
67
|
+
var url = '/api/v2.1/seadoc/revision/origin-file-content/' + docUuid + '/';
|
|
69
68
|
return this.req.get(url);
|
|
70
69
|
}
|
|
71
70
|
}, {
|
|
@@ -81,6 +80,26 @@ var SeafileAPI = /*#__PURE__*/function () {
|
|
|
81
80
|
var url = 'api/v2.1/seadoc/revisions/' + docUuid + '/?page=' + page + '&per_page=' + perPage;
|
|
82
81
|
return this.req.get(url);
|
|
83
82
|
}
|
|
83
|
+
}, {
|
|
84
|
+
key: "publishRevision",
|
|
85
|
+
value: function publishRevision(docUuid) {
|
|
86
|
+
var url = '/api/v2.1/seadoc/publish-revision/' + docUuid + '/';
|
|
87
|
+
return this.req.post(url);
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "updateSdocRevision",
|
|
91
|
+
value: function updateSdocRevision(docUuid) {
|
|
92
|
+
var url = 'api/v2.1/seadoc/revision/' + docUuid + '/';
|
|
93
|
+
return this.req.put(url);
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "getRevisionBasicVersionContent",
|
|
97
|
+
value: function getRevisionBasicVersionContent(docUuid) {
|
|
98
|
+
var url = 'api/v2.1/seadoc/revision/basic-version-content/' + docUuid + '/';
|
|
99
|
+
return this.req.get(url);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// local files
|
|
84
103
|
}, {
|
|
85
104
|
key: "getSdocFiles",
|
|
86
105
|
value: function getSdocFiles(docUuid, p, type) {
|
|
@@ -6,4 +6,28 @@ export var INTERNAL_EVENT = {
|
|
|
6
6
|
INSERT_ELEMENT: 'insert_element',
|
|
7
7
|
OUTLINE_STATE_CHANGED: 'outline_state_changed'
|
|
8
8
|
};
|
|
9
|
-
export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
|
9
|
+
export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
|
10
|
+
|
|
11
|
+
export var MODIFY_TYPE = {
|
|
12
|
+
ADD: 'add',
|
|
13
|
+
DELETE: 'delete',
|
|
14
|
+
MODIFY: 'modify',
|
|
15
|
+
CHILDREN_MODIFY: 'children_modify'
|
|
16
|
+
};
|
|
17
|
+
export var REBASE_TYPE = {
|
|
18
|
+
MODIFY_MODIFY: 'modify_modify',
|
|
19
|
+
DELETE_MODIFY: 'delete_modify',
|
|
20
|
+
MODIFY_DELETE: 'modify_delete',
|
|
21
|
+
CHILDREN_MODIFY: 'children_modify'
|
|
22
|
+
};
|
|
23
|
+
export var REBASE_MARK_KEY = {
|
|
24
|
+
ORIGIN: 'origin',
|
|
25
|
+
REBASE_TYPE: 'rebase_type',
|
|
26
|
+
MODIFY_TYPE: 'modify_type',
|
|
27
|
+
OLD_ELEMENT: 'old_element'
|
|
28
|
+
};
|
|
29
|
+
export var REBASE_ORIGIN = {
|
|
30
|
+
OTHER: 'other',
|
|
31
|
+
MY: 'my'
|
|
32
|
+
};
|
|
33
|
+
export var REBASE_MARKS = [REBASE_MARK_KEY.ORIGIN, REBASE_MARK_KEY.REBASE_TYPE, REBASE_MARK_KEY.MODIFY_TYPE, REBASE_MARK_KEY.OLD_ELEMENT];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import { Editor } from '@seafile/slate';
|
|
4
|
+
import { focusEditor } from '../extension/core';
|
|
5
|
+
import { EditorContainer, EditorContent } from '../layout';
|
|
6
|
+
import SlateEditor from './slate-editor';
|
|
7
|
+
import InsertElementDialog from '../extension/commons/insert-element-dialog';
|
|
8
|
+
var CommonEditor = function CommonEditor(_ref) {
|
|
9
|
+
var slateValue = _ref.slateValue,
|
|
10
|
+
updateSlateValue = _ref.updateSlateValue,
|
|
11
|
+
editor = _ref.editor,
|
|
12
|
+
renderElement = _ref.renderElement;
|
|
13
|
+
// useMount: focus editor
|
|
14
|
+
useEffect(function () {
|
|
15
|
+
var timer = setTimeout(function () {
|
|
16
|
+
var _editor$children = _slicedToArray(editor.children, 1),
|
|
17
|
+
firstNode = _editor$children[0];
|
|
18
|
+
if (firstNode) {
|
|
19
|
+
var _firstNode$children = _slicedToArray(firstNode.children, 1),
|
|
20
|
+
firstNodeFirstChild = _firstNode$children[0];
|
|
21
|
+
if (firstNodeFirstChild) {
|
|
22
|
+
var endOfFirstNode = Editor.end(editor, [0, 0]);
|
|
23
|
+
var range = {
|
|
24
|
+
anchor: endOfFirstNode,
|
|
25
|
+
focus: endOfFirstNode
|
|
26
|
+
};
|
|
27
|
+
focusEditor(editor, range);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, 300);
|
|
31
|
+
return function () {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
};
|
|
34
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
+
}, []);
|
|
36
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
|
|
37
|
+
editor: editor
|
|
38
|
+
}, /*#__PURE__*/React.createElement(EditorContent, {
|
|
39
|
+
docValue: slateValue,
|
|
40
|
+
showOutline: true
|
|
41
|
+
}, /*#__PURE__*/React.createElement(SlateEditor, {
|
|
42
|
+
editor: editor,
|
|
43
|
+
slateValue: slateValue,
|
|
44
|
+
setSlateValue: updateSlateValue,
|
|
45
|
+
renderElement: renderElement
|
|
46
|
+
}))), /*#__PURE__*/React.createElement(InsertElementDialog, {
|
|
47
|
+
editor: editor
|
|
48
|
+
}));
|
|
49
|
+
};
|
|
50
|
+
export default CommonEditor;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
.sdoc-rebase-btn-group {
|
|
2
|
+
color: #aaa;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.sdoc-rebase-btn-group .sdoc-rebase-btn {
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sdoc-rebase-current-changes-start {
|
|
10
|
+
background-color: rgb(202, 232, 254);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.sdoc-rebase-current-changes {
|
|
14
|
+
background-color: rgba(202, 232, 254, .8);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.sdoc-rebase-incoming-changes {
|
|
18
|
+
background-color: rgb(222, 232, 254);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.sdoc-rebase-incoming-changes > *:first-child,
|
|
22
|
+
.sdoc-rebase-current-changes > *:first-child {
|
|
23
|
+
margin: 0;
|
|
24
|
+
padding: 0.8em 0 0.8em 0.2em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.sdoc-rebase-incoming-changes-end {
|
|
28
|
+
background-color: rgb(212, 212, 254);
|
|
29
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import React, { useMemo, useEffect, useState, useCallback, useImperativeHandle, forwardRef } from 'react';
|
|
4
|
+
import deepCopy from 'deep-copy';
|
|
5
|
+
import { createDefaultEditor, renderElement } from '../extension';
|
|
6
|
+
import { withSocketIO } from '../socket';
|
|
7
|
+
import withNodeId from '../node-id';
|
|
8
|
+
import { PAGE_EDIT_AREA_WIDTH } from '../constants';
|
|
9
|
+
import { MODE } from '../../constants';
|
|
10
|
+
import DiffViewer from '../views/diff-viewer';
|
|
11
|
+
import SDocEditor from './common-editor';
|
|
12
|
+
import CommonLoading from '../../components/common-loading';
|
|
13
|
+
import context from '../../context';
|
|
14
|
+
import './index.css';
|
|
15
|
+
var Editor = forwardRef(function (_ref, ref) {
|
|
16
|
+
var mode = _ref.mode,
|
|
17
|
+
document = _ref.document,
|
|
18
|
+
setDiffChanges = _ref.setDiffChanges;
|
|
19
|
+
var editor = useMemo(function () {
|
|
20
|
+
var defaultEditor = createDefaultEditor();
|
|
21
|
+
var editorConfig = context.getEditorConfig();
|
|
22
|
+
defaultEditor.mode = MODE.EDITOR;
|
|
23
|
+
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
24
|
+
document: document,
|
|
25
|
+
config: editorConfig
|
|
26
|
+
}));
|
|
27
|
+
var cursors = document.cursors;
|
|
28
|
+
newEditor.cursors = cursors || {};
|
|
29
|
+
newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
|
|
30
|
+
return newEditor;
|
|
31
|
+
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, []);
|
|
34
|
+
var _useState = useState(document.children),
|
|
35
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
36
|
+
slateValue = _useState2[0],
|
|
37
|
+
_setSlateValue = _useState2[1];
|
|
38
|
+
var _useState3 = useState(false),
|
|
39
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
40
|
+
isLoading = _useState4[0],
|
|
41
|
+
_setLoading = _useState4[1];
|
|
42
|
+
var _useState5 = useState(null),
|
|
43
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
44
|
+
diffContent = _useState6[0],
|
|
45
|
+
_setDiffContent = _useState6[1];
|
|
46
|
+
var _useState7 = useState(null),
|
|
47
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
48
|
+
currentContent = _useState8[0],
|
|
49
|
+
setCurrentContent = _useState8[1];
|
|
50
|
+
|
|
51
|
+
// useMount: init socket connection
|
|
52
|
+
useEffect(function () {
|
|
53
|
+
editor.openConnection();
|
|
54
|
+
return function () {
|
|
55
|
+
editor.closeConnection();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
+
}, []);
|
|
60
|
+
var updateSlateValue = useCallback(function (value) {
|
|
61
|
+
_setSlateValue(value);
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
// The parent component can call the method of this component through ref
|
|
67
|
+
useImperativeHandle(ref, function () {
|
|
68
|
+
return {
|
|
69
|
+
// set value
|
|
70
|
+
setLoading: function setLoading(isLoading) {
|
|
71
|
+
_setLoading(isLoading);
|
|
72
|
+
},
|
|
73
|
+
setDiffContent: function setDiffContent(content) {
|
|
74
|
+
setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
75
|
+
children: slateValue
|
|
76
|
+
})));
|
|
77
|
+
_setDiffContent(content);
|
|
78
|
+
},
|
|
79
|
+
setEditorMode: function setEditorMode(mode) {
|
|
80
|
+
editor.cursors = {};
|
|
81
|
+
editor.selection = null;
|
|
82
|
+
if (mode === MODE.EDITOR) {
|
|
83
|
+
editor.operations = [];
|
|
84
|
+
}
|
|
85
|
+
editor.mode = mode;
|
|
86
|
+
},
|
|
87
|
+
setSlateValue: function setSlateValue(document) {
|
|
88
|
+
_setSlateValue(document.children);
|
|
89
|
+
},
|
|
90
|
+
// get value
|
|
91
|
+
getSlateValue: function getSlateValue() {
|
|
92
|
+
return deepCopy(_objectSpread(_objectSpread({}, document), {}, {
|
|
93
|
+
children: slateValue
|
|
94
|
+
}));
|
|
95
|
+
},
|
|
96
|
+
// send message
|
|
97
|
+
publishDocument: function publishDocument(originDocUuid, originDocName, callback) {
|
|
98
|
+
editor.publishDocument(originDocUuid, originDocName, callback);
|
|
99
|
+
},
|
|
100
|
+
replaceDocument: function replaceDocument(value, originFileVersion) {
|
|
101
|
+
editor.replaceDocument(value, originFileVersion);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
+
};
|
|
106
|
+
}, [document, editor, slateValue]);
|
|
107
|
+
if (isLoading) {
|
|
108
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
109
|
+
className: "h-100 w-100 d-flex align-items-center justify-content-center"
|
|
110
|
+
}, /*#__PURE__*/React.createElement(CommonLoading, null));
|
|
111
|
+
}
|
|
112
|
+
if (mode === MODE.DIFF_VIEWER) {
|
|
113
|
+
return /*#__PURE__*/React.createElement(DiffViewer, {
|
|
114
|
+
showToolbar: true,
|
|
115
|
+
showOutline: true,
|
|
116
|
+
editor: editor,
|
|
117
|
+
currentContent: currentContent,
|
|
118
|
+
lastContent: diffContent,
|
|
119
|
+
didMountCallback: setDiffChanges
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return /*#__PURE__*/React.createElement(SDocEditor, {
|
|
123
|
+
slateValue: slateValue,
|
|
124
|
+
editor: editor,
|
|
125
|
+
updateSlateValue: updateSlateValue,
|
|
126
|
+
renderElement: renderElement
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
export default Editor;
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, Fragment } from 'react';
|
|
2
2
|
import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
|
|
3
|
-
import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '
|
|
4
|
-
import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '
|
|
5
|
-
import EventProxy from '
|
|
6
|
-
import { useCursors } from '
|
|
7
|
-
import { INTERNAL_EVENT } from '
|
|
8
|
-
import { SetNodeToDecorations } from '
|
|
9
|
-
import CommentContextProvider from '
|
|
10
|
-
import CommentWrapper from '
|
|
11
|
-
import { usePipDecorate } from '
|
|
12
|
-
import { getCursorPosition, getDomHeight, getDomMarginTop } from '
|
|
13
|
-
import EventBus from '
|
|
14
|
-
import { ArticleContainer } from '
|
|
15
|
-
import { useScrollContext } from '
|
|
3
|
+
import { renderLeaf, renderElement, ContextToolbar, SideToolbar } from '../extension';
|
|
4
|
+
import { getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from '../extension/core';
|
|
5
|
+
import EventProxy from '../utils/event-handler';
|
|
6
|
+
import { useCursors } from '../cursor/use-cursors';
|
|
7
|
+
import { INTERNAL_EVENT } from '../constants';
|
|
8
|
+
import { SetNodeToDecorations } from '../highlight-decorate/setNodeToDecorations';
|
|
9
|
+
import CommentContextProvider from '../comment/comment-context-provider';
|
|
10
|
+
import CommentWrapper from '../comment';
|
|
11
|
+
import { usePipDecorate } from '../decorates';
|
|
12
|
+
import { getCursorPosition, getDomHeight, getDomMarginTop } from '../utils/dom-utils';
|
|
13
|
+
import EventBus from '../utils/event-bus';
|
|
14
|
+
import { ArticleContainer } from '../layout';
|
|
15
|
+
import { useScrollContext } from '../hooks/use-scroll-context';
|
|
16
16
|
var SlateEditor = function SlateEditor(_ref) {
|
|
17
17
|
var editor = _ref.editor,
|
|
18
18
|
setSlateValue = _ref.setSlateValue,
|
|
19
|
-
slateValue = _ref.slateValue
|
|
19
|
+
slateValue = _ref.slateValue,
|
|
20
|
+
customRenderElement = _ref.renderElement,
|
|
21
|
+
isShowComment = _ref.isShowComment;
|
|
20
22
|
var _useCursors = useCursors(editor),
|
|
21
23
|
cursors = _useCursors.cursors;
|
|
22
24
|
var decorate = usePipDecorate(editor);
|
|
@@ -138,12 +140,15 @@ var SlateEditor = function SlateEditor(_ref) {
|
|
|
138
140
|
editor: editor
|
|
139
141
|
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
140
142
|
cursors: cursors,
|
|
141
|
-
renderElement: renderElement,
|
|
143
|
+
renderElement: customRenderElement || renderElement,
|
|
142
144
|
renderLeaf: renderLeaf,
|
|
143
145
|
onKeyDown: onKeyDown,
|
|
144
146
|
onMouseDown: onMouseDown,
|
|
145
147
|
decorate: decorate,
|
|
146
148
|
onCut: eventProxy.onCut
|
|
147
|
-
})), /*#__PURE__*/React.createElement(SideToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
|
|
149
|
+
})), /*#__PURE__*/React.createElement(SideToolbar, null), isShowComment && /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null))));
|
|
150
|
+
};
|
|
151
|
+
SlateEditor.defaultProps = {
|
|
152
|
+
isShowComment: true
|
|
148
153
|
};
|
|
149
154
|
export default SlateEditor;
|
|
@@ -22,4 +22,9 @@ export var TABLE_CELL = 'table_cell';
|
|
|
22
22
|
export var LINK = 'link';
|
|
23
23
|
export var SDOC_LINK = 'sdoc_link';
|
|
24
24
|
export var FILE_LINK = 'file_link';
|
|
25
|
-
export var IMAGE = 'image';
|
|
25
|
+
export var IMAGE = 'image';
|
|
26
|
+
|
|
27
|
+
// font
|
|
28
|
+
export var FONT_SIZE = 'font-size';
|
|
29
|
+
export var FONT_SIZE_INCREASE = 'font-size-increase';
|
|
30
|
+
export var FONT_SIZE_REDUCE = 'font-size-reduce';
|
|
@@ -12,4 +12,30 @@ export var replaceNodeChildren = function replaceNodeChildren(editor, _ref) {
|
|
|
12
12
|
at: at.concat([0])
|
|
13
13
|
}));
|
|
14
14
|
});
|
|
15
|
+
};
|
|
16
|
+
export var replaceNode = function replaceNode(editor) {
|
|
17
|
+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
18
|
+
at = _ref2.at,
|
|
19
|
+
nodes = _ref2.nodes,
|
|
20
|
+
insertOptions = _ref2.insertOptions,
|
|
21
|
+
removeOptions = _ref2.removeOptions;
|
|
22
|
+
Editor.withoutNormalizing(editor, function () {
|
|
23
|
+
Transforms.removeNodes(editor, _objectSpread({
|
|
24
|
+
at: at
|
|
25
|
+
}, removeOptions));
|
|
26
|
+
Transforms.insertNodes(editor, nodes, _objectSpread(_objectSpread({}, insertOptions), {}, {
|
|
27
|
+
at: at
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export var deleteNodeMark = function deleteNodeMark(editor, path, element) {
|
|
32
|
+
var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
33
|
+
var newElement = _objectSpread({}, element);
|
|
34
|
+
marks.forEach(function (markItem) {
|
|
35
|
+
newElement[markItem] && delete newElement[markItem];
|
|
36
|
+
});
|
|
37
|
+
replaceNode(editor, {
|
|
38
|
+
at: path,
|
|
39
|
+
nodes: newElement
|
|
40
|
+
});
|
|
15
41
|
};
|
|
@@ -132,9 +132,7 @@ export var loadFont = function loadFont() {
|
|
|
132
132
|
fontLink.className = GOOGLE_FONT_CLASS;
|
|
133
133
|
document.body.appendChild(fontLink);
|
|
134
134
|
};
|
|
135
|
-
export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight
|
|
136
|
-
var isCodeBlock = leaf && Object.keys(leaf).includes('token');
|
|
137
|
-
if (isCodeBlock) return '';
|
|
135
|
+
export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight) {
|
|
138
136
|
var lang = context.getSetting('lang') || 'zh-cn';
|
|
139
137
|
if (fontName === DEFAULT_FONT) {
|
|
140
138
|
return "'Arial', ".concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");
|
|
@@ -32,9 +32,10 @@ var renderText = function renderText(props, editor) {
|
|
|
32
32
|
style['fontSize'] = "".concat(fontSize, "pt");
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
if (leaf[TEXT_STYLE_MAP.FONT]) {
|
|
36
|
+
var fontWeight = leaf[TEXT_STYLE_MAP.BOLD] ? 600 : 400;
|
|
37
|
+
style['fontFamily'] = generatorFontFamily(leaf[TEXT_STYLE_MAP.FONT], fontWeight);
|
|
38
|
+
}
|
|
38
39
|
if (leaf[TEXT_STYLE_MAP.BOLD]) {
|
|
39
40
|
markedChildren = /*#__PURE__*/React.createElement("strong", null, markedChildren);
|
|
40
41
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
4
|
import React, { useCallback } from 'react';
|
|
3
5
|
import { useSlateStatic } from '@seafile/slate-react';
|
|
6
|
+
import { Transforms } from '@seafile/slate';
|
|
7
|
+
import deepCopy from 'deep-copy';
|
|
8
|
+
import { useTranslation } from 'react-i18next';
|
|
4
9
|
import { BLOCKQUOTE, LINK, CHECK_LIST_ITEM, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, LIST_ITEM, LIST_LIC, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, CODE_LINE, IMAGE, ELEMENT_TYPE, SDOC_LINK, FILE_LINK, TITLE, SUBTITLE } from '../constants';
|
|
5
10
|
import { BlockquotePlugin, LinkPlugin, CheckListPlugin, HeaderPlugin, ListPlugin, CodeBlockPlugin, ImagePlugin, TablePlugin, SdocLinkPlugin, ParagraphPlugin, FileLinkPlugin } from '../plugins';
|
|
6
11
|
import EventBus from '../../utils/event-bus';
|
|
7
|
-
import { INTERNAL_EVENT } from '../../constants';
|
|
12
|
+
import { INTERNAL_EVENT, REBASE_TYPE, REBASE_MARKS, REBASE_MARK_KEY, REBASE_ORIGIN } from '../../constants';
|
|
13
|
+
import { findPath, getNode, replaceNode, deleteNodeMark } from '../../extension/core';
|
|
8
14
|
var CustomElement = function CustomElement(props) {
|
|
9
15
|
var editor = useSlateStatic();
|
|
10
16
|
var element = props.element,
|
|
@@ -146,6 +152,220 @@ var CustomElement = function CustomElement(props) {
|
|
|
146
152
|
}
|
|
147
153
|
};
|
|
148
154
|
var RenderElement = function RenderElement(props) {
|
|
155
|
+
var editor = useSlateStatic();
|
|
156
|
+
var _useTranslation = useTranslation(),
|
|
157
|
+
t = _useTranslation.t;
|
|
158
|
+
var updateParentNodeByPath = useCallback(function (path) {
|
|
159
|
+
var parentPath = path.slice(0, -1);
|
|
160
|
+
var parentNode = getNode(editor, parentPath);
|
|
161
|
+
if (parentNode.children.filter(function (item) {
|
|
162
|
+
return item[REBASE_MARK_KEY.REBASE_TYPE];
|
|
163
|
+
}).length === 0) {
|
|
164
|
+
var newParentElement = _objectSpread({}, parentNode);
|
|
165
|
+
newParentElement[REBASE_MARK_KEY.REBASE_TYPE] && delete newParentElement[REBASE_MARK_KEY.REBASE_TYPE];
|
|
166
|
+
newParentElement[REBASE_MARK_KEY.OLD_ELEMENT] && delete newParentElement[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
167
|
+
newParentElement[REBASE_MARK_KEY.ORIGIN] && delete newParentElement[REBASE_MARK_KEY.ORIGIN];
|
|
168
|
+
newParentElement['children'] = newParentElement['children'].map(function (item) {
|
|
169
|
+
item[REBASE_MARK_KEY.REBASE_TYPE] && delete item[REBASE_MARK_KEY.REBASE_TYPE];
|
|
170
|
+
item[REBASE_MARK_KEY.OLD_ELEMENT] && delete item[REBASE_MARK_KEY.OLD_ELEMENT];
|
|
171
|
+
item[REBASE_MARK_KEY.ORIGIN] && delete item[REBASE_MARK_KEY.ORIGIN];
|
|
172
|
+
return item;
|
|
173
|
+
});
|
|
174
|
+
replaceNode(editor, {
|
|
175
|
+
at: parentPath,
|
|
176
|
+
nodes: newParentElement
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
181
|
+
}, [editor]);
|
|
182
|
+
var deleteElement = useCallback(function (element) {
|
|
183
|
+
var path = findPath(editor, element);
|
|
184
|
+
Transforms.removeNodes(editor, {
|
|
185
|
+
at: path
|
|
186
|
+
});
|
|
187
|
+
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
188
|
+
updateParentNodeByPath(path);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
192
|
+
}, [editor]);
|
|
193
|
+
var deleteMark = useCallback(function (element) {
|
|
194
|
+
var path = findPath(editor, element);
|
|
195
|
+
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
196
|
+
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
197
|
+
updateParentNodeByPath(path);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
201
|
+
}, [editor]);
|
|
202
|
+
var useMasterChanges = useCallback(function (element) {
|
|
203
|
+
var path = findPath(editor, element);
|
|
204
|
+
deleteNodeMark(editor, path, element[REBASE_MARK_KEY.OLD_ELEMENT], REBASE_MARKS);
|
|
205
|
+
var nextElementPath = _toConsumableArray(path);
|
|
206
|
+
nextElementPath[path.length - 1] = path[path.length - 1] + 1;
|
|
207
|
+
Transforms.removeNodes(editor, {
|
|
208
|
+
at: nextElementPath
|
|
209
|
+
});
|
|
210
|
+
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
211
|
+
updateParentNodeByPath(path);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
215
|
+
}, [editor]);
|
|
216
|
+
var useCurrentChanges = useCallback(function (element) {
|
|
217
|
+
var path = findPath(editor, element);
|
|
218
|
+
var currentElementPath = _toConsumableArray(path);
|
|
219
|
+
currentElementPath[path.length - 1] = path[path.length - 1] + 1;
|
|
220
|
+
var currentElement = getNode(editor, currentElementPath);
|
|
221
|
+
var newCurrentElement = deepCopy(currentElement);
|
|
222
|
+
deleteNodeMark(editor, currentElementPath, newCurrentElement, REBASE_MARKS);
|
|
223
|
+
Transforms.removeNodes(editor, {
|
|
224
|
+
at: path
|
|
225
|
+
});
|
|
226
|
+
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
227
|
+
updateParentNodeByPath(path);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
231
|
+
}, [editor]);
|
|
232
|
+
var useBothChanges = useCallback(function (element) {
|
|
233
|
+
// delete element marks
|
|
234
|
+
var path = findPath(editor, element);
|
|
235
|
+
deleteNodeMark(editor, path, element, REBASE_MARKS);
|
|
236
|
+
|
|
237
|
+
// delete next element marks
|
|
238
|
+
var nextElementPath = [].concat(_toConsumableArray(path.slice(0, -1)), [path[path.length - 1] + 1]);
|
|
239
|
+
var nextElement = getNode(editor, nextElementPath);
|
|
240
|
+
deleteNodeMark(editor, nextElementPath, nextElement, REBASE_MARKS);
|
|
241
|
+
if (element.type === ELEMENT_TYPE.LIST_ITEM) {
|
|
242
|
+
updateParentNodeByPath(path);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
246
|
+
}, [editor]);
|
|
247
|
+
var element = props.element;
|
|
248
|
+
var rebaseType = element[REBASE_MARK_KEY.REBASE_TYPE];
|
|
249
|
+
if (!rebaseType) {
|
|
250
|
+
return /*#__PURE__*/React.createElement(CustomElement, props);
|
|
251
|
+
}
|
|
252
|
+
if (rebaseType === REBASE_TYPE.MODIFY_DELETE) {
|
|
253
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
254
|
+
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
255
|
+
contentEditable: false
|
|
256
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
257
|
+
className: "sdoc-rebase-btn",
|
|
258
|
+
onClick: function onClick() {
|
|
259
|
+
return deleteMark(element);
|
|
260
|
+
}
|
|
261
|
+
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
262
|
+
className: "mr-2 ml-2"
|
|
263
|
+
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
264
|
+
className: "sdoc-rebase-btn",
|
|
265
|
+
onClick: function onClick() {
|
|
266
|
+
return deleteElement(element);
|
|
267
|
+
}
|
|
268
|
+
}, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
|
|
269
|
+
className: "mr-2 ml-2"
|
|
270
|
+
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
271
|
+
className: "sdoc-rebase-btn",
|
|
272
|
+
onClick: function onClick() {
|
|
273
|
+
return deleteMark(element);
|
|
274
|
+
}
|
|
275
|
+
}, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
276
|
+
className: "w-100 sdoc-rebase-current-changes-start",
|
|
277
|
+
contentEditable: false
|
|
278
|
+
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
279
|
+
className: "w-100 sdoc-rebase-incoming-changes",
|
|
280
|
+
contentEditable: false
|
|
281
|
+
}, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
|
|
282
|
+
className: "w-100",
|
|
283
|
+
contentEditable: false
|
|
284
|
+
}, '======='), /*#__PURE__*/React.createElement("div", {
|
|
285
|
+
className: "w-100 sdoc-rebase-incoming-changes-end",
|
|
286
|
+
contentEditable: false
|
|
287
|
+
}, '>>>>>>>'));
|
|
288
|
+
}
|
|
289
|
+
if (rebaseType === REBASE_TYPE.DELETE_MODIFY) {
|
|
290
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
291
|
+
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
292
|
+
contentEditable: false
|
|
293
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
294
|
+
className: "sdoc-rebase-btn",
|
|
295
|
+
onClick: function onClick() {
|
|
296
|
+
return deleteElement(element);
|
|
297
|
+
}
|
|
298
|
+
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
299
|
+
className: "mr-2 ml-2"
|
|
300
|
+
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
301
|
+
className: "sdoc-rebase-btn",
|
|
302
|
+
onClick: function onClick() {
|
|
303
|
+
return deleteMark(element);
|
|
304
|
+
}
|
|
305
|
+
}, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
|
|
306
|
+
className: "mr-2 ml-2"
|
|
307
|
+
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
308
|
+
className: "sdoc-rebase-btn",
|
|
309
|
+
onClick: function onClick() {
|
|
310
|
+
return deleteMark(element);
|
|
311
|
+
}
|
|
312
|
+
}, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
313
|
+
className: "w-100 sdoc-rebase-current-changes-start",
|
|
314
|
+
contentEditable: false
|
|
315
|
+
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
316
|
+
className: "w-100",
|
|
317
|
+
contentEditable: false
|
|
318
|
+
}, '======='), /*#__PURE__*/React.createElement("div", {
|
|
319
|
+
className: "w-100 sdoc-rebase-incoming-changes",
|
|
320
|
+
contentEditable: false
|
|
321
|
+
}, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
|
|
322
|
+
className: "w-100 sdoc-rebase-incoming-changes-end",
|
|
323
|
+
contentEditable: false
|
|
324
|
+
}, '>>>>>>>'));
|
|
325
|
+
}
|
|
326
|
+
if (rebaseType === REBASE_TYPE.MODIFY_MODIFY) {
|
|
327
|
+
if (element[REBASE_MARK_KEY.ORIGIN] === REBASE_ORIGIN.OTHER) {
|
|
328
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
329
|
+
className: "w-100 d-flex sdoc-rebase-btn-group",
|
|
330
|
+
contentEditable: false
|
|
331
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
332
|
+
className: "sdoc-rebase-btn",
|
|
333
|
+
onClick: function onClick() {
|
|
334
|
+
return useMasterChanges(element);
|
|
335
|
+
}
|
|
336
|
+
}, t('Keep_other_modification')), /*#__PURE__*/React.createElement("div", {
|
|
337
|
+
className: "mr-2 ml-2"
|
|
338
|
+
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
339
|
+
className: "sdoc-rebase-btn",
|
|
340
|
+
onClick: function onClick() {
|
|
341
|
+
return useCurrentChanges(element);
|
|
342
|
+
}
|
|
343
|
+
}, t('Keep_my_modification')), /*#__PURE__*/React.createElement("div", {
|
|
344
|
+
className: "mr-2 ml-2"
|
|
345
|
+
}, '|'), /*#__PURE__*/React.createElement("div", {
|
|
346
|
+
className: "sdoc-rebase-btn",
|
|
347
|
+
onClick: function onClick() {
|
|
348
|
+
return useBothChanges(element);
|
|
349
|
+
}
|
|
350
|
+
}, t('Keep_both_modification'))), /*#__PURE__*/React.createElement("div", {
|
|
351
|
+
className: "w-100 sdoc-rebase-current-changes-start",
|
|
352
|
+
contentEditable: false
|
|
353
|
+
}, '<<<<<<<'), /*#__PURE__*/React.createElement("div", {
|
|
354
|
+
className: "w-100 sdoc-rebase-current-changes",
|
|
355
|
+
contentEditable: false
|
|
356
|
+
}, /*#__PURE__*/React.createElement(CustomElement, props)));
|
|
357
|
+
}
|
|
358
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
359
|
+
className: "w-100",
|
|
360
|
+
contentEditable: false
|
|
361
|
+
}, '======='), /*#__PURE__*/React.createElement("div", {
|
|
362
|
+
className: "w-100 sdoc-rebase-incoming-changes",
|
|
363
|
+
contentEditable: false
|
|
364
|
+
}, /*#__PURE__*/React.createElement(CustomElement, props)), /*#__PURE__*/React.createElement("div", {
|
|
365
|
+
className: "w-100 sdoc-rebase-incoming-changes-end",
|
|
366
|
+
contentEditable: false
|
|
367
|
+
}, '>>>>>>>'));
|
|
368
|
+
}
|
|
149
369
|
return /*#__PURE__*/React.createElement(CustomElement, props);
|
|
150
370
|
|
|
151
371
|
// const { element } = props;
|