@seafile/sdoc-editor 0.1.142 → 0.1.143-beta2
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/sdoc-server-api.js +10 -0
- package/dist/api/seafile-api.js +27 -5
- package/dist/basic-sdk/assets/css/dropdown-menu.css +5 -1
- package/dist/basic-sdk/constants/index.js +14 -1
- package/dist/basic-sdk/editor/common-editor.js +45 -0
- package/dist/basic-sdk/editor/index.js +135 -0
- package/dist/basic-sdk/editor/rebase-editor/index.css +29 -0
- package/dist/basic-sdk/editor/rebase-editor/index.js +272 -0
- package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
- package/dist/basic-sdk/extension/commons/insert-element-dialog/index.js +12 -3
- package/dist/basic-sdk/extension/constants/index.js +2 -0
- package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +2 -20
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +7 -6
- package/dist/basic-sdk/extension/plugins/html/plugin.js +23 -2
- package/dist/basic-sdk/extension/plugins/image/helpers.js +13 -3
- package/dist/basic-sdk/extension/plugins/link/dialog/add-link-dialog/index.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/helpers.js +14 -4
- package/dist/basic-sdk/extension/plugins/link/plugin.js +8 -13
- package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +30 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +2 -3
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-below-menu.js +5 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +13 -8
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +7 -4
- package/dist/basic-sdk/extension/toolbar/side-toolbar/transform-menus.js +13 -2
- package/dist/basic-sdk/socket/helpers.js +1 -0
- package/dist/basic-sdk/socket/socket-client.js +15 -0
- package/dist/basic-sdk/socket/socket-manager.js +11 -2
- package/dist/basic-sdk/socket/with-socket-io.js +25 -12
- package/dist/basic-sdk/utils/diff.js +2 -2
- 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 +8 -11
- package/dist/components/doc-operations/index.js +8 -2
- package/dist/components/doc-operations/revision-operations/index.js +11 -3
- package/dist/components/doc-operations/revision-operations/publish-button.js +16 -13
- package/dist/components/tip-dialog/index.css +0 -0
- package/dist/components/tip-dialog/index.js +45 -0
- package/dist/constants/index.js +8 -1
- package/dist/context.js +28 -4
- package/dist/pages/simple-editor.js +228 -71
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +8 -1
- package/public/locales/zh_CN/sdoc-editor.json +7 -1
- package/dist/basic-sdk/editor.js +0 -105
|
@@ -7,6 +7,7 @@ import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, s
|
|
|
7
7
|
import SocketClient from './socket-client';
|
|
8
8
|
import debug from '../utils/debug';
|
|
9
9
|
import { deleteCursor } from '../cursor/helper';
|
|
10
|
+
import { EXTERNAL_EVENT } from '../../constants';
|
|
10
11
|
|
|
11
12
|
// idle --> sending --> conflict --> idle
|
|
12
13
|
// --> conflict --> idle
|
|
@@ -19,13 +20,20 @@ var STATE = {
|
|
|
19
20
|
DISCONNECT: 'disconnect',
|
|
20
21
|
NEED_RELOAD: 'need_reload'
|
|
21
22
|
};
|
|
22
|
-
var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor,
|
|
23
|
+
var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _document, config) {
|
|
23
24
|
var _this = this;
|
|
24
25
|
_classCallCheck(this, SocketManager);
|
|
25
26
|
this.getDocumentVersion = function () {
|
|
26
27
|
var version = _this.document.version;
|
|
27
28
|
return version;
|
|
28
29
|
};
|
|
30
|
+
this.sendRebaseContent = function (document) {
|
|
31
|
+
_this.socketClient.sendRebaseDocument(document);
|
|
32
|
+
};
|
|
33
|
+
this.receiveRebaseContent = function (document) {
|
|
34
|
+
_this.document = document;
|
|
35
|
+
_this.eventBus.dispatch(EXTERNAL_EVENT.REBASE_DOCUMENT, document);
|
|
36
|
+
};
|
|
29
37
|
this.onReceiveLocalOperations = function (operations) {
|
|
30
38
|
_this.pendingOperationList.push(operations);
|
|
31
39
|
if (_this.pendingOperationList.length > 5) {
|
|
@@ -34,6 +42,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
|
|
|
34
42
|
_this.sendOperations();
|
|
35
43
|
};
|
|
36
44
|
this.sendOperations = function () {
|
|
45
|
+
if (_this.editor.isReadonly) return;
|
|
37
46
|
if (_this.state !== STATE.IDLE) return;
|
|
38
47
|
_this.state = STATE.SENDING;
|
|
39
48
|
_this.sendNextOperations();
|
|
@@ -270,7 +279,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
|
|
|
270
279
|
_this.socketClient.disconnectWithServer();
|
|
271
280
|
};
|
|
272
281
|
this.editor = editor;
|
|
273
|
-
this.document =
|
|
282
|
+
this.document = _document;
|
|
274
283
|
this.socketClient = new SocketClient(config);
|
|
275
284
|
this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
|
|
276
285
|
this.remoteOperationsList = []; // Same with pending operations
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MODE } from '../../constants';
|
|
1
2
|
import { generateCursorData } from '../cursor/helper';
|
|
2
3
|
import EventBus from '../utils/event-bus';
|
|
3
4
|
import SocketManager from './socket-manager';
|
|
@@ -19,28 +20,40 @@ var withSocketIO = function withSocketIO(editor, options) {
|
|
|
19
20
|
SocketManager.destroy();
|
|
20
21
|
};
|
|
21
22
|
newEditor.onChange = function () {
|
|
22
|
-
|
|
23
|
+
var document = options.document,
|
|
24
|
+
config = options.config;
|
|
25
|
+
if (newEditor.mode === MODE.DIFF_VIEWER) return;
|
|
23
26
|
var operations = newEditor.operations;
|
|
24
27
|
if (!newEditor.isRemote && operations.length > 0) {
|
|
25
28
|
var isAllSetSelection = operations.every(function (operation) {
|
|
26
29
|
return operation.type === 'set_selection';
|
|
27
30
|
});
|
|
28
|
-
var _socketManager = SocketManager.getInstance();
|
|
31
|
+
var _socketManager = SocketManager.getInstance(newEditor, document, config);
|
|
29
32
|
if (!isAllSetSelection) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (newEditor.mode === MODE.EDITOR) {
|
|
34
|
+
// get update content value operations
|
|
35
|
+
var updateOperations = operations.filter(function (operation) {
|
|
36
|
+
return operation.type !== 'set_selection';
|
|
37
|
+
});
|
|
38
|
+
_socketManager.onReceiveLocalOperations(updateOperations);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (newEditor.mode === MODE.EDITOR) {
|
|
42
|
+
_socketManager.sendCursorLocation(editor.selection);
|
|
35
43
|
}
|
|
36
|
-
_socketManager.sendCursorLocation(editor.selection);
|
|
37
44
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
if (newEditor.mode === MODE.EDITOR) {
|
|
46
|
+
// dispatch editor change event
|
|
47
|
+
var eventBus = EventBus.getInstance(newEditor, document, config);
|
|
48
|
+
eventBus.dispatch('change');
|
|
49
|
+
}
|
|
42
50
|
onChange();
|
|
43
51
|
};
|
|
52
|
+
newEditor.rebaseContent = function (document) {
|
|
53
|
+
var config = options.config;
|
|
54
|
+
var socketManager = SocketManager.getInstance(newEditor, document, config);
|
|
55
|
+
socketManager.sendRebaseContent(document);
|
|
56
|
+
};
|
|
44
57
|
return newEditor;
|
|
45
58
|
};
|
|
46
59
|
export default withSocketIO;
|
|
@@ -31,7 +31,7 @@ var generatorDiffElement = function generatorDiffElement(element, diffType) {
|
|
|
31
31
|
return generatorDiffElement(item, diffType, style);
|
|
32
32
|
})), _objectSpread3));
|
|
33
33
|
};
|
|
34
|
-
var generateIdMapAndIds = function generateIdMapAndIds(elements) {
|
|
34
|
+
export var generateIdMapAndIds = function generateIdMapAndIds(elements) {
|
|
35
35
|
var map = {};
|
|
36
36
|
var ids = [];
|
|
37
37
|
if (!Array.isArray(elements) || elements.length === 0) return {
|
|
@@ -54,7 +54,7 @@ var hasChildren = function hasChildren(element) {
|
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
// id diffs
|
|
57
|
-
var getIdDiffs = function getIdDiffs(oldIds, newIds) {
|
|
57
|
+
export var getIdDiffs = function getIdDiffs(oldIds, newIds) {
|
|
58
58
|
var diff = new DiffText(oldIds, newIds);
|
|
59
59
|
return diff.getDiffs();
|
|
60
60
|
};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import { generateIdMapAndIds, getIdDiffs } from './diff';
|
|
4
|
+
import ObjectUtils from './object-utils';
|
|
5
|
+
import { MODIFY_TYPE, REBASE_TYPE } from '../constants';
|
|
6
|
+
import { ELEMENT_TYPE } from '../extension/constants';
|
|
7
|
+
var getRevisionChanges = function getRevisionChanges(masterContent, currentContent) {
|
|
8
|
+
var _generateIdMapAndIds = generateIdMapAndIds(currentContent.children),
|
|
9
|
+
currentContentMap = _generateIdMapAndIds.map,
|
|
10
|
+
currentIds = _generateIdMapAndIds.ids;
|
|
11
|
+
var _generateIdMapAndIds2 = generateIdMapAndIds(masterContent.children),
|
|
12
|
+
masterContentMap = _generateIdMapAndIds2.map,
|
|
13
|
+
masterIds = _generateIdMapAndIds2.ids;
|
|
14
|
+
var idDiffs = getIdDiffs(masterIds, currentIds);
|
|
15
|
+
var content = [];
|
|
16
|
+
idDiffs.forEach(function (idDiff) {
|
|
17
|
+
var value = idDiff.value,
|
|
18
|
+
added = idDiff.added,
|
|
19
|
+
removed = idDiff.removed;
|
|
20
|
+
if (added) {
|
|
21
|
+
var addedList = value.map(function (item) {
|
|
22
|
+
return _objectSpread(_objectSpread({}, currentContentMap[item]), {}, {
|
|
23
|
+
modifyType: MODIFY_TYPE.ADD
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
content.push.apply(content, _toConsumableArray(addedList));
|
|
27
|
+
} else if (removed) {
|
|
28
|
+
var deletedList = value.map(function (item) {
|
|
29
|
+
return _objectSpread(_objectSpread({}, masterContentMap[item]), {}, {
|
|
30
|
+
modifyType: MODIFY_TYPE.DELETE
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
content.push.apply(content, _toConsumableArray(deletedList));
|
|
34
|
+
} else {
|
|
35
|
+
value.forEach(function (elementId) {
|
|
36
|
+
if (ObjectUtils.isSameObject(masterContentMap[elementId], currentContentMap[elementId])) {
|
|
37
|
+
content.push(currentContentMap[elementId]);
|
|
38
|
+
} else {
|
|
39
|
+
var oldElement = masterContentMap[elementId];
|
|
40
|
+
var currentElement = currentContentMap[elementId];
|
|
41
|
+
var newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
|
|
42
|
+
modifyType: MODIFY_TYPE.MODIFY,
|
|
43
|
+
oldElement: oldElement
|
|
44
|
+
});
|
|
45
|
+
if (currentElement.type === oldElement.type) {
|
|
46
|
+
var elementType = currentElement.type;
|
|
47
|
+
if ([ELEMENT_TYPE.UNORDERED_LIST, ELEMENT_TYPE.ORDERED_LIST].includes(elementType)) {
|
|
48
|
+
var listContent = getRevisionChanges(oldElement, currentElement);
|
|
49
|
+
newElement['modifyType'] = MODIFY_TYPE.CHILDREN_MODIFY;
|
|
50
|
+
newElement['children'] = listContent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
content.push(newElement);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return content;
|
|
59
|
+
};
|
|
60
|
+
var getMasterChanges = function getMasterChanges(masterContent, revisionChanges) {
|
|
61
|
+
var canMerge = true;
|
|
62
|
+
var _generateIdMapAndIds3 = generateIdMapAndIds(revisionChanges),
|
|
63
|
+
currentContentMap = _generateIdMapAndIds3.map,
|
|
64
|
+
currentIds = _generateIdMapAndIds3.ids;
|
|
65
|
+
var _generateIdMapAndIds4 = generateIdMapAndIds(masterContent.children),
|
|
66
|
+
masterContentMap = _generateIdMapAndIds4.map,
|
|
67
|
+
masterIds = _generateIdMapAndIds4.ids;
|
|
68
|
+
var idDiffs = getIdDiffs(masterIds, currentIds);
|
|
69
|
+
var content = [];
|
|
70
|
+
idDiffs.forEach(function (idDiff) {
|
|
71
|
+
var value = idDiff.value,
|
|
72
|
+
added = idDiff.added,
|
|
73
|
+
removed = idDiff.removed;
|
|
74
|
+
if (added) {
|
|
75
|
+
value.forEach(function (elementId) {
|
|
76
|
+
var element = currentContentMap[elementId];
|
|
77
|
+
var newElement = {
|
|
78
|
+
id: element.id,
|
|
79
|
+
children: element.children,
|
|
80
|
+
type: element.type
|
|
81
|
+
};
|
|
82
|
+
// The content has been deleted from the master, but this branch has been modified. At this time, rebase is required, and the user needs to confirm the selected content
|
|
83
|
+
// ==> delete | use modification
|
|
84
|
+
if (element.modifyType === MODIFY_TYPE.MODIFY) {
|
|
85
|
+
newElement['rebaseType'] = REBASE_TYPE.DELETE_MODIFY;
|
|
86
|
+
content.push(newElement);
|
|
87
|
+
canMerge = false;
|
|
88
|
+
} else {
|
|
89
|
+
// new direct append
|
|
90
|
+
content.push(newElement);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
} else if (removed) {
|
|
94
|
+
var deletedList = value.map(function (item) {
|
|
95
|
+
return _objectSpread({}, masterContentMap[item]);
|
|
96
|
+
});
|
|
97
|
+
content.push.apply(content, _toConsumableArray(deletedList));
|
|
98
|
+
} else {
|
|
99
|
+
value.forEach(function (elementId) {
|
|
100
|
+
var currentElement = currentContentMap[elementId];
|
|
101
|
+
var masterElement = masterContentMap[elementId];
|
|
102
|
+
|
|
103
|
+
// Unchanged
|
|
104
|
+
if (ObjectUtils.isSameObject(masterElement, currentElement)) {
|
|
105
|
+
content.push(currentElement);
|
|
106
|
+
|
|
107
|
+
// The content of the master branch is modified in the current branch, but the content of the master branch is the same as that of origin
|
|
108
|
+
} else if (ObjectUtils.isSameObject(masterElement, currentElement.oldElement)) {
|
|
109
|
+
var newElement = _objectSpread({}, currentElement);
|
|
110
|
+
newElement['oldElement'] && delete newElement['oldElement'];
|
|
111
|
+
newElement['modifyType'] && delete newElement['modifyType'];
|
|
112
|
+
content.push(newElement);
|
|
113
|
+
|
|
114
|
+
// Modify at the same time
|
|
115
|
+
} else if (currentElement.modifyType === MODIFY_TYPE.MODIFY) {
|
|
116
|
+
content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
|
|
117
|
+
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
118
|
+
origin: 'master'
|
|
119
|
+
}));
|
|
120
|
+
var _newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
|
|
121
|
+
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
122
|
+
origin: 'current'
|
|
123
|
+
});
|
|
124
|
+
_newElement['modifyType'] && delete _newElement['modifyType'];
|
|
125
|
+
_newElement['oldElement'] && delete _newElement['oldElement'];
|
|
126
|
+
content.push(_newElement);
|
|
127
|
+
canMerge = false;
|
|
128
|
+
|
|
129
|
+
// children modify
|
|
130
|
+
} else if (currentElement.modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
|
|
131
|
+
canMerge = false;
|
|
132
|
+
if (currentElement.type === masterElement.type) {
|
|
133
|
+
var _getMasterChanges = getMasterChanges(masterElement, currentElement.children),
|
|
134
|
+
childrenContent = _getMasterChanges.content;
|
|
135
|
+
content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
|
|
136
|
+
children: childrenContent,
|
|
137
|
+
rebaseType: REBASE_TYPE.CHILDREN_MODIFY
|
|
138
|
+
}));
|
|
139
|
+
} else {
|
|
140
|
+
content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
|
|
141
|
+
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
142
|
+
origin: 'master'
|
|
143
|
+
}));
|
|
144
|
+
var _newElement2 = _objectSpread(_objectSpread({}, currentElement.oldElement), {}, {
|
|
145
|
+
rebaseType: REBASE_TYPE.MODIFY_MODIFY,
|
|
146
|
+
origin: 'current'
|
|
147
|
+
});
|
|
148
|
+
content.push(_newElement2);
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
var _newElement3 = _objectSpread({}, currentElement);
|
|
152
|
+
_newElement3['oldElement'] && delete _newElement3['oldElement'];
|
|
153
|
+
_newElement3['modifyType'] && delete _newElement3['modifyType'];
|
|
154
|
+
content.push(_newElement3);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
content: content,
|
|
161
|
+
canMerge: canMerge
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
export var getRebase = function getRebase(masterContent, revisionMasterContent, revisionCurrentContent) {
|
|
165
|
+
// master no changes, merged directly
|
|
166
|
+
if (masterContent.version === revisionMasterContent.version) {
|
|
167
|
+
return {
|
|
168
|
+
canMerge: true,
|
|
169
|
+
isNeedReplaceMaster: true,
|
|
170
|
+
value: revisionCurrentContent
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// The revision content has not changed
|
|
175
|
+
if (revisionMasterContent.version === revisionCurrentContent.version) {
|
|
176
|
+
return {
|
|
177
|
+
canMerge: true,
|
|
178
|
+
isNeedReplaceMaster: false,
|
|
179
|
+
value: masterContent
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
var revisionChanges = getRevisionChanges(revisionMasterContent, revisionCurrentContent);
|
|
183
|
+
var _getMasterChanges2 = getMasterChanges(masterContent, revisionChanges),
|
|
184
|
+
canMerge = _getMasterChanges2.canMerge,
|
|
185
|
+
content = _getMasterChanges2.content;
|
|
186
|
+
return {
|
|
187
|
+
canMerge: canMerge,
|
|
188
|
+
isNeedReplaceMaster: true,
|
|
189
|
+
value: _objectSpread(_objectSpread({}, revisionCurrentContent), {}, {
|
|
190
|
+
children: content
|
|
191
|
+
})
|
|
192
|
+
};
|
|
193
|
+
};
|
|
@@ -6,7 +6,8 @@ import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../extension/constants
|
|
|
6
6
|
import SDocViewer from './viewer';
|
|
7
7
|
import '../../assets/css/diff-viewer.css';
|
|
8
8
|
var DiffViewer = function DiffViewer(_ref) {
|
|
9
|
-
var
|
|
9
|
+
var editor = _ref.editor,
|
|
10
|
+
currentContent = _ref.currentContent,
|
|
10
11
|
lastContent = _ref.lastContent,
|
|
11
12
|
didMountCallback = _ref.didMountCallback,
|
|
12
13
|
showToolbar = _ref.showToolbar,
|
|
@@ -38,6 +39,7 @@ var DiffViewer = function DiffViewer(_ref) {
|
|
|
38
39
|
return renderElement(props, editor);
|
|
39
40
|
}, []);
|
|
40
41
|
return /*#__PURE__*/React.createElement(SDocViewer, {
|
|
42
|
+
editor: editor,
|
|
41
43
|
showToolbar: showToolbar,
|
|
42
44
|
showOutline: showOutline,
|
|
43
45
|
document: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Fragment
|
|
1
|
+
import React, { Fragment } from 'react';
|
|
2
2
|
import { Editable, Slate } from '@seafile/slate-react';
|
|
3
3
|
import { renderLeaf as _renderLeaf, renderElement as _renderElement, createDefaultEditor } from '../extension';
|
|
4
4
|
import withNodeId from '../node-id';
|
|
@@ -8,16 +8,13 @@ import { usePipDecorate } from '../decorates';
|
|
|
8
8
|
import { ArticleContainer, EditorContainer, EditorContent } from '../layout';
|
|
9
9
|
import '../assets/css/simple-viewer.css';
|
|
10
10
|
var SDocViewer = function SDocViewer(_ref) {
|
|
11
|
-
var
|
|
11
|
+
var editor = _ref.editor,
|
|
12
|
+
document = _ref.document,
|
|
12
13
|
customRenderLeaf = _ref.renderLeaf,
|
|
13
14
|
customRenderElement = _ref.renderElement,
|
|
14
15
|
showToolbar = _ref.showToolbar,
|
|
15
16
|
showOutline = _ref.showOutline;
|
|
16
|
-
var
|
|
17
|
-
var defaultEditor = createDefaultEditor();
|
|
18
|
-
return withNodeId(defaultEditor);
|
|
19
|
-
}, []);
|
|
20
|
-
editor.readonly = true;
|
|
17
|
+
var validEditor = editor || withNodeId(createDefaultEditor());
|
|
21
18
|
var slateValue = (document || generateDefaultDocContent()).children;
|
|
22
19
|
var decorate = usePipDecorate(editor);
|
|
23
20
|
return /*#__PURE__*/React.createElement(EditorContainer, {
|
|
@@ -29,19 +26,19 @@ var SDocViewer = function SDocViewer(_ref) {
|
|
|
29
26
|
readonly: true,
|
|
30
27
|
showOutline: showOutline
|
|
31
28
|
}, /*#__PURE__*/React.createElement(Slate, {
|
|
32
|
-
editor:
|
|
29
|
+
editor: validEditor,
|
|
33
30
|
value: slateValue
|
|
34
31
|
}, /*#__PURE__*/React.createElement(ArticleContainer, {
|
|
35
|
-
editor:
|
|
32
|
+
editor: validEditor,
|
|
36
33
|
readOnly: true
|
|
37
34
|
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
38
35
|
readOnly: true,
|
|
39
36
|
placeholder: "",
|
|
40
37
|
renderElement: function renderElement(props) {
|
|
41
|
-
return (customRenderElement || _renderElement)(props,
|
|
38
|
+
return (customRenderElement || _renderElement)(props, validEditor);
|
|
42
39
|
},
|
|
43
40
|
renderLeaf: function renderLeaf(props) {
|
|
44
|
-
return (customRenderLeaf || _renderLeaf)(props,
|
|
41
|
+
return (customRenderLeaf || _renderLeaf)(props, validEditor);
|
|
45
42
|
},
|
|
46
43
|
onDOMBeforeInput: function onDOMBeforeInput(event) {},
|
|
47
44
|
decorate: decorate
|
|
@@ -11,14 +11,20 @@ import './style.css';
|
|
|
11
11
|
var DocOperations = function DocOperations(_ref) {
|
|
12
12
|
var isShowChanges = _ref.isShowChanges,
|
|
13
13
|
changes = _ref.changes,
|
|
14
|
-
toggleViewChanges = _ref.toggleViewChanges
|
|
14
|
+
toggleViewChanges = _ref.toggleViewChanges,
|
|
15
|
+
publishRevision = _ref.publishRevision,
|
|
16
|
+
mode = _ref.mode,
|
|
17
|
+
abortRebase = _ref.abortRebase;
|
|
15
18
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
16
19
|
return /*#__PURE__*/React.createElement("div", {
|
|
17
20
|
className: "doc-ops"
|
|
18
21
|
}, /*#__PURE__*/React.createElement(RevisionOperations, {
|
|
19
22
|
isShowChanges: isShowChanges,
|
|
20
23
|
changes: changes,
|
|
21
|
-
|
|
24
|
+
mode: mode,
|
|
25
|
+
toggleViewChanges: toggleViewChanges,
|
|
26
|
+
publishRevision: publishRevision,
|
|
27
|
+
abortRebase: abortRebase
|
|
22
28
|
}), /*#__PURE__*/React.createElement(CommentsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(ShareOperation, null), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(MoreOperations, null));
|
|
23
29
|
};
|
|
24
30
|
export default withTranslation('sdoc-editor')(DocOperations);
|
|
@@ -5,17 +5,25 @@ import ViewChanges from './view-changes';
|
|
|
5
5
|
import MoreRevisionOperations from './more-revision-operations';
|
|
6
6
|
import Revisions from './revisions';
|
|
7
7
|
import ChangesCount from './changes-count';
|
|
8
|
+
import { MODE } from '../../../constants';
|
|
8
9
|
var RevisionOperations = function RevisionOperations(_ref) {
|
|
9
10
|
var isShowChanges = _ref.isShowChanges,
|
|
10
11
|
changes = _ref.changes,
|
|
11
|
-
toggleViewChanges = _ref.toggleViewChanges
|
|
12
|
+
toggleViewChanges = _ref.toggleViewChanges,
|
|
13
|
+
publishRevision = _ref.publishRevision,
|
|
14
|
+
mode = _ref.mode,
|
|
15
|
+
abortRebase = _ref.abortRebase;
|
|
12
16
|
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
13
17
|
var isPublished = context.getSetting('isPublished');
|
|
14
18
|
return /*#__PURE__*/React.createElement(React.Fragment, null, !isSdocRevision && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MoreRevisionOperations, null), /*#__PURE__*/React.createElement(Revisions, null)), isSdocRevision && isShowChanges && /*#__PURE__*/React.createElement(ChangesCount, {
|
|
15
19
|
changes: changes
|
|
16
|
-
}), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
|
|
20
|
+
}), isSdocRevision && mode !== MODE.REBASE && /*#__PURE__*/React.createElement(ViewChanges, {
|
|
17
21
|
isShowChanges: isShowChanges,
|
|
18
22
|
toggleViewChanges: toggleViewChanges
|
|
19
|
-
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision,
|
|
23
|
+
}), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, {
|
|
24
|
+
publishRevision: publishRevision,
|
|
25
|
+
mode: mode,
|
|
26
|
+
abortRebase: abortRebase
|
|
27
|
+
}));
|
|
20
28
|
};
|
|
21
29
|
export default RevisionOperations;
|
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
2
3
|
import { Button } from 'reactstrap';
|
|
3
|
-
import {
|
|
4
|
-
import context from '../../../context';
|
|
5
|
-
import toaster from '../../../components/toast';
|
|
4
|
+
import { MODE } from '../../../constants';
|
|
6
5
|
var PublishRevision = function PublishRevision(_ref) {
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var mode = _ref.mode,
|
|
7
|
+
publishRevision = _ref.publishRevision,
|
|
8
|
+
abortRebase = _ref.abortRebase;
|
|
9
|
+
var _useTranslation = useTranslation(),
|
|
10
|
+
t = _useTranslation.t;
|
|
10
11
|
var publish = useCallback(function (event) {
|
|
11
12
|
event.stopPropagation();
|
|
12
13
|
event.nativeEvent.stopImmediatePropagation();
|
|
13
|
-
|
|
14
|
-
var origin_file_path = res.data.origin_file_path;
|
|
15
|
-
window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
|
|
16
|
-
}).catch(function (error) {
|
|
17
|
-
toaster.danger(t('Error'));
|
|
18
|
-
});
|
|
14
|
+
publishRevision();
|
|
19
15
|
|
|
20
16
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
17
|
}, []);
|
|
18
|
+
if (mode === MODE.REBASE) {
|
|
19
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
20
|
+
color: "success",
|
|
21
|
+
onClick: abortRebase,
|
|
22
|
+
className: "ml-4"
|
|
23
|
+
}, t('Abort'));
|
|
24
|
+
}
|
|
22
25
|
return /*#__PURE__*/React.createElement(Button, {
|
|
23
26
|
color: "success",
|
|
24
27
|
onClick: publish,
|
|
25
28
|
className: "ml-4"
|
|
26
29
|
}, t('Publish'));
|
|
27
30
|
};
|
|
28
|
-
export default
|
|
31
|
+
export default PublishRevision;
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import './index.css';
|
|
6
|
+
var TipDialog = function TipDialog(_ref) {
|
|
7
|
+
var title = _ref.title,
|
|
8
|
+
children = _ref.children,
|
|
9
|
+
className = _ref.className,
|
|
10
|
+
toggle = _ref.toggle,
|
|
11
|
+
submit = _ref.submit;
|
|
12
|
+
var _useTranslation = useTranslation(),
|
|
13
|
+
t = _useTranslation.t;
|
|
14
|
+
var closeDialog = useCallback(function () {
|
|
15
|
+
toggle && toggle(false);
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
18
|
+
}, []);
|
|
19
|
+
var confirmTip = useCallback(function () {
|
|
20
|
+
submit && submit();
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
|
+
}, []);
|
|
24
|
+
return /*#__PURE__*/React.createElement(Modal, {
|
|
25
|
+
isOpen: true,
|
|
26
|
+
autoFocus: false,
|
|
27
|
+
zIndex: 1071,
|
|
28
|
+
returnFocusAfterClose: false,
|
|
29
|
+
className: classnames('sdoc-tip-dialog', className),
|
|
30
|
+
contentClassName: "sdoc-tip-modal"
|
|
31
|
+
}, /*#__PURE__*/React.createElement(ModalHeader, {
|
|
32
|
+
toggle: closeDialog
|
|
33
|
+
}, title), /*#__PURE__*/React.createElement(ModalBody, {
|
|
34
|
+
className: "sdoc-tip-body"
|
|
35
|
+
}, children), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
|
|
36
|
+
color: "secondary",
|
|
37
|
+
className: "mr-2",
|
|
38
|
+
onClick: closeDialog
|
|
39
|
+
}, t('Cancel')), /*#__PURE__*/React.createElement(Button, {
|
|
40
|
+
color: "primary",
|
|
41
|
+
className: "highlight-bg-color",
|
|
42
|
+
onClick: confirmTip
|
|
43
|
+
}, t('Confirm'))));
|
|
44
|
+
};
|
|
45
|
+
export default TipDialog;
|
package/dist/constants/index.js
CHANGED
|
@@ -2,5 +2,12 @@ export var EXTERNAL_EVENT = {
|
|
|
2
2
|
INTERNAL_LINK_CLICK: 'internal_link_click',
|
|
3
3
|
TOGGLE_STAR: 'toggle_star',
|
|
4
4
|
UNMARK_AS_DRAFT: 'unmark_as_draft',
|
|
5
|
-
SHARE_SDOC: 'share_sdoc'
|
|
5
|
+
SHARE_SDOC: 'share_sdoc',
|
|
6
|
+
REBASE_DOCUMENT: 'rebase_document'
|
|
7
|
+
};
|
|
8
|
+
export var MODE = {
|
|
9
|
+
DIFF_VIEWER: 'diff-viewer',
|
|
10
|
+
VIEWER: 'viewer',
|
|
11
|
+
EDITOR: 'editor',
|
|
12
|
+
REBASE: 'rebase'
|
|
6
13
|
};
|
package/dist/context.js
CHANGED
|
@@ -10,6 +10,9 @@ var Context = /*#__PURE__*/function () {
|
|
|
10
10
|
this.initSettings = function () {
|
|
11
11
|
_this.settings = window.seafile ? window.seafile : window.seafileConfig;
|
|
12
12
|
};
|
|
13
|
+
// saveDocContentByRebase(content) {
|
|
14
|
+
// return this.sdocServerApi.saveDocContentByRebase(content);
|
|
15
|
+
// }
|
|
13
16
|
this.uploadLocalImage = function (imageFile) {
|
|
14
17
|
var docUuid = _this.getSetting('docUuid');
|
|
15
18
|
return _this.api.uploadSdocImage(docUuid, imageFile).then(function (res) {
|
|
@@ -156,14 +159,15 @@ var Context = /*#__PURE__*/function () {
|
|
|
156
159
|
}, {
|
|
157
160
|
key: "publishSdocRevision",
|
|
158
161
|
value: function publishSdocRevision() {
|
|
162
|
+
var replace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
|
|
159
163
|
var docUuid = this.getSetting('docUuid');
|
|
160
|
-
return this.api.sdocPublishRevision(docUuid);
|
|
164
|
+
return this.api.sdocPublishRevision(docUuid, replace);
|
|
161
165
|
}
|
|
162
166
|
}, {
|
|
163
|
-
key: "
|
|
164
|
-
value: function
|
|
167
|
+
key: "getSeadocOriginFileDownloadLink",
|
|
168
|
+
value: function getSeadocOriginFileDownloadLink() {
|
|
165
169
|
var docUuid = this.getSetting('docUuid');
|
|
166
|
-
return this.api.
|
|
170
|
+
return this.api.getSeadocOriginFileDownloadLink(docUuid);
|
|
167
171
|
}
|
|
168
172
|
}, {
|
|
169
173
|
key: "getSdocRevisionsCount",
|
|
@@ -177,6 +181,26 @@ var Context = /*#__PURE__*/function () {
|
|
|
177
181
|
var docUuid = this.getSetting('docUuid');
|
|
178
182
|
return this.api.getSdocRevisions(docUuid, page, perPage);
|
|
179
183
|
}
|
|
184
|
+
}, {
|
|
185
|
+
key: "deleteSdocRevision",
|
|
186
|
+
value: function deleteSdocRevision() {
|
|
187
|
+
var docUuid = this.getSetting('docUuid');
|
|
188
|
+
return this.api.deleteSdocRevision(docUuid);
|
|
189
|
+
}
|
|
190
|
+
}, {
|
|
191
|
+
key: "rebaseSdocRevision",
|
|
192
|
+
value: function rebaseSdocRevision() {
|
|
193
|
+
var docUuid = this.getSetting('docUuid');
|
|
194
|
+
return this.api.rebaseSdocRevision(docUuid);
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "getFileHistoryVersion",
|
|
198
|
+
value: function getFileHistoryVersion(fileVersion, filePath) {
|
|
199
|
+
var docUuid = this.getSetting('docUuid');
|
|
200
|
+
return this.api.getFileHistoryVersion(docUuid, fileVersion, filePath);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// local files
|
|
180
204
|
}, {
|
|
181
205
|
key: "getSdocLocalFiles",
|
|
182
206
|
value: function getSdocLocalFiles(p) {
|