@seafile/sdoc-editor 0.1.0 → 0.1.2
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/{new-editors/editor.js → editor.js} +38 -17
- package/dist/index.js +2 -36
- package/dist/slate-extension/core/transforms/move-children.js +1 -1
- package/dist/slate-extension/plugins/blockquote/helpers.js +3 -3
- package/dist/slate-extension/plugins/index.js +3 -2
- package/dist/slate-extension/plugins/list/transforms/normalize-list-item.js +2 -2
- package/dist/slate-extension/plugins/list/transforms/toggle-list.js +6 -8
- package/dist/slate-extension/plugins/socket/index.js +6 -0
- package/dist/slate-extension/plugins/socket/plugin.js +23 -0
- package/dist/slate-extension/socket/socket-client.js +94 -0
- package/dist/slate-extension/socket/socket-manager.js +63 -0
- package/dist/slate-extension/toolbar/index.js +1 -1
- package/dist/utils/event-bus.js +39 -0
- package/package.json +5 -25
- package/dist/assets/css/comment-dialog.css +0 -50
- package/dist/assets/css/diff-viewer.css +0 -105
- package/dist/assets/css/formula.css +0 -19
- package/dist/assets/css/history-viewer.css +0 -104
- package/dist/assets/css/image.css +0 -134
- package/dist/assets/css/issue-card.css +0 -43
- package/dist/assets/css/keyboard-shortcuts.css +0 -58
- package/dist/assets/css/link.css +0 -7
- package/dist/assets/css/markdown-editor.css +0 -12
- package/dist/assets/css/markdown-viewer.css +0 -69
- package/dist/assets/css/navbar-imgbutton.css +0 -83
- package/dist/assets/css/outline.css +0 -29
- package/dist/assets/css/table.css +0 -57
- package/dist/assets/css/textlink-hovermenu.css +0 -47
- package/dist/assets/css/topbar.css +0 -350
- package/dist/assets/css/tree-view.css +0 -67
- package/dist/assets/css/user-help.css +0 -84
- package/dist/assets/editor/plain-editor.css +0 -30
- package/dist/assets/editor/seatable-editor.css +0 -77
- package/dist/assets/editor/simple-editor.css +0 -77
- package/dist/components/click-outside.js +0 -46
- package/dist/components/context-menu.js +0 -97
- package/dist/components/dialogs/add-formula-dialog.js +0 -116
- package/dist/components/dialogs/add-image-dialog.js +0 -69
- package/dist/components/dialogs/add-link-dialog.js +0 -133
- package/dist/components/dialogs/comment-dialog.js +0 -97
- package/dist/components/dialogs/shortcut-dialog.js +0 -131
- package/dist/components/error-boundary.js +0 -28
- package/dist/components/load-script/index.js +0 -69
- package/dist/components/loading.js +0 -25
- package/dist/components/markdown-lint.js +0 -72
- package/dist/components/menu/index.js +0 -4
- package/dist/components/menu/item.js +0 -49
- package/dist/components/menu/menu.js +0 -38
- package/dist/components/menu/style.css +0 -42
- package/dist/components/modal-portal.js +0 -38
- package/dist/components/outline/index.js +0 -92
- package/dist/components/outline/outline-item.js +0 -58
- package/dist/components/select/_option.js +0 -44
- package/dist/components/select/field-setting.js +0 -106
- package/dist/components/select/index.js +0 -149
- package/dist/components/select/style.css +0 -144
- package/dist/components/svg-icons/check-mark-icon.js +0 -14
- package/dist/components/svg-icons/column-icon.js +0 -17
- package/dist/components/svg-icons/text-icon.js +0 -34
- package/dist/components/text-link-hover-menu/index.js +0 -123
- package/dist/components/toast/alert.js +0 -138
- package/dist/components/toast/index.js +0 -3
- package/dist/components/toast/toast.js +0 -159
- package/dist/components/toast/toastManager.js +0 -139
- package/dist/components/toast/toaster.js +0 -65
- package/dist/components/toolbar/header-list.js +0 -114
- package/dist/components/toolbar/help-group.js +0 -33
- package/dist/components/toolbar/index.js +0 -4
- package/dist/components/toolbar/insert-image.js +0 -106
- package/dist/components/toolbar/insert-table.js +0 -136
- package/dist/components/toolbar/table-group.js +0 -74
- package/dist/components/toolbar/toolbar.js +0 -317
- package/dist/components/toolbar/widgets/button-group.js +0 -24
- package/dist/components/toolbar/widgets/button-item.js +0 -129
- package/dist/components/toolbar/widgets/drop-list.js +0 -88
- package/dist/components/user-help/index.js +0 -179
- package/dist/config-0.js +0 -15
- package/dist/config.js +0 -16
- package/dist/constants/cell-types.js +0 -29
- package/dist/constants/column.js +0 -4
- package/dist/containers/code-highlight-package.js +0 -14
- package/dist/containers/controller/block-element-controller.js +0 -375
- package/dist/containers/controller/index.js +0 -5
- package/dist/containers/controller/inline-element-controller.js +0 -134
- package/dist/containers/controller/normalize-controller.js +0 -95
- package/dist/containers/controller/shortcut-controller.js +0 -385
- package/dist/containers/controller/void-element-controller.js +0 -9
- package/dist/containers/custom/custom.js +0 -18
- package/dist/containers/custom/get-event-transfer.js +0 -33
- package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
- package/dist/containers/custom/insertNodes.js +0 -120
- package/dist/containers/custom/is-empty-paragraph.js +0 -9
- package/dist/containers/custom/set-event-transfer.js +0 -30
- package/dist/containers/custom/split-nodes-at-point.js +0 -136
- package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
- package/dist/containers/editor-context.js +0 -85
- package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
- package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
- package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
- package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
- package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
- package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
- package/dist/containers/editor-utils/clear-format-utils.js +0 -84
- package/dist/containers/editor-utils/common-editor-utils.js +0 -492
- package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
- package/dist/containers/editor-utils/mark-utils.js +0 -20
- package/dist/containers/editor-utils/range-utils.js +0 -7
- package/dist/containers/editor-utils/selection-utils.js +0 -30
- package/dist/containers/editor-utils/text-utils.js +0 -117
- package/dist/containers/editor-widgets/check-list-item.js +0 -53
- package/dist/containers/editor-widgets/code-block.js +0 -128
- package/dist/containers/editor-widgets/column.js +0 -100
- package/dist/containers/editor-widgets/formula.js +0 -67
- package/dist/containers/editor-widgets/image.js +0 -237
- package/dist/containers/editor-widgets/link.js +0 -9
- package/dist/containers/editor-widgets/table.js +0 -144
- package/dist/containers/element-model/blockquote.js +0 -13
- package/dist/containers/element-model/column.js +0 -19
- package/dist/containers/element-model/image.js +0 -16
- package/dist/containers/element-model/link.js +0 -16
- package/dist/containers/element-model/table.js +0 -57
- package/dist/containers/element-model/text.js +0 -10
- package/dist/containers/render-utils/common-utils.js +0 -80
- package/dist/containers/render-utils/editor-utils.js +0 -133
- package/dist/containers/render-utils/viewer-utils.js +0 -198
- package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
- package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
- package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
- package/dist/editors/index.js +0 -78
- package/dist/editors/markdown-editor.js +0 -280
- package/dist/editors/plain-markdown-editor.js +0 -285
- package/dist/editors/seatable-editor.js +0 -210
- package/dist/editors/simple-editor.js +0 -200
- package/dist/utils/deserialize-html.js +0 -260
- package/dist/utils/diff/compare-strings.js +0 -35
- package/dist/utils/diff/diff.js +0 -769
- package/dist/utils/diff/index.js +0 -2
- package/dist/utils/seafile-markdown2html.js +0 -52
- package/dist/utils/slate2markdown/deserialize.js +0 -588
- package/dist/utils/slate2markdown/index.js +0 -3
- package/dist/utils/slate2markdown/serialize.js +0 -366
- package/dist/utils/utils.js +0 -69
- package/dist/viewer/diff-viewer.js +0 -85
- package/dist/viewer/index.js +0 -4
- package/dist/viewer/markdown-viewer.js +0 -121
- package/dist/viewer/seatable-viewer.js +0 -63
- package/dist/viewer/slate-viewer.js +0 -71
- /package/dist/assets/css/{new-editor-toolbar.css → sdoc-editor-toolbar.css} +0 -0
- /package/dist/assets/css/{new-editor.css → sdoc-editor.css} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
4
|
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
@@ -5,15 +6,22 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
5
6
|
import React from 'react';
|
|
6
7
|
import { Editable, Slate } from 'slate-react';
|
|
7
8
|
import isHotkey from 'is-hotkey';
|
|
8
|
-
import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from '
|
|
9
|
-
import '
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from './slate-extension';
|
|
10
|
+
import SocketManager from './slate-extension/socket/socket-manager';
|
|
11
|
+
import './assets/css/sdoc-editor.css';
|
|
12
|
+
var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
13
|
+
_inherits(SDocEditor, _React$Component);
|
|
14
|
+
var _super = _createSuper(SDocEditor);
|
|
15
|
+
function SDocEditor(props) {
|
|
14
16
|
var _this;
|
|
15
|
-
_classCallCheck(this,
|
|
17
|
+
_classCallCheck(this, SDocEditor);
|
|
16
18
|
_this = _super.call(this, props);
|
|
19
|
+
_this.updateWithRemoteOperation = function (params) {
|
|
20
|
+
var operation = params.operation;
|
|
21
|
+
_this.editor.apply(_objectSpread(_objectSpread({}, operation), {}, {
|
|
22
|
+
is_remote: true
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
17
25
|
_this.onChange = function (slateValue) {
|
|
18
26
|
var onValueChanged = _this.props.onValueChanged;
|
|
19
27
|
_this.setState({
|
|
@@ -21,22 +29,32 @@ var NewEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
21
29
|
});
|
|
22
30
|
onValueChanged && onValueChanged(slateValue);
|
|
23
31
|
};
|
|
32
|
+
var children = props.document.children;
|
|
24
33
|
_this.state = {
|
|
25
|
-
slateValue:
|
|
34
|
+
slateValue: children,
|
|
26
35
|
isLoading: true
|
|
27
36
|
};
|
|
28
37
|
_this.editor = editor;
|
|
38
|
+
_this.socketManager = null;
|
|
29
39
|
return _this;
|
|
30
40
|
}
|
|
31
|
-
_createClass(
|
|
41
|
+
_createClass(SDocEditor, [{
|
|
32
42
|
key: "componentDidMount",
|
|
33
43
|
value: function componentDidMount() {
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
var _this$props = this.props,
|
|
45
|
+
isOpenSocket = _this$props.isOpenSocket,
|
|
46
|
+
document = _this$props.document,
|
|
47
|
+
config = _this$props.config;
|
|
48
|
+
if (isOpenSocket) {
|
|
49
|
+
this.socketManager = SocketManager.getInstance(document, config);
|
|
50
|
+
var eventBus = this.socketManager.eventBus;
|
|
51
|
+
this.unsubscribeReceiveOption = eventBus.subscribe('receive-operation', this.updateWithRemoteOperation);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "componentWillUnmount",
|
|
56
|
+
value: function componentWillUnmount() {
|
|
57
|
+
this.unsubscribeReceiveOption();
|
|
40
58
|
}
|
|
41
59
|
}, {
|
|
42
60
|
key: "render",
|
|
@@ -72,6 +90,9 @@ var NewEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
72
90
|
})))));
|
|
73
91
|
}
|
|
74
92
|
}]);
|
|
75
|
-
return
|
|
93
|
+
return SDocEditor;
|
|
76
94
|
}(React.Component);
|
|
77
|
-
|
|
95
|
+
SDocEditor.defaultProps = {
|
|
96
|
+
isOpenSocket: false
|
|
97
|
+
};
|
|
98
|
+
export default SDocEditor;
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// import UserHelp from './components/user-help';
|
|
4
|
-
// import EditorContext from './containers/editor-context';
|
|
5
|
-
// import { deserialize, serialize } from './utils/slate2markdown';
|
|
6
|
-
// import { processor } from './utils/seafile-markdown2html';
|
|
7
|
-
// import { replaceColumnData } from './utils/utils';
|
|
8
|
-
// import {
|
|
9
|
-
// MarkdownEditor,
|
|
10
|
-
// SimpleEditor,
|
|
11
|
-
// PlainMarkdownEditor,
|
|
12
|
-
// SeatableEditor
|
|
13
|
-
// } from './editors';
|
|
14
|
-
// import {
|
|
15
|
-
// DiffViewer,
|
|
16
|
-
// MarkdownViewer,
|
|
17
|
-
// SeatableViewer
|
|
18
|
-
// } from './viewer';
|
|
19
|
-
import NewEditor from './new-editors/editor';
|
|
20
|
-
export {
|
|
21
|
-
// EditorContext,
|
|
22
|
-
// MarkdownEditor,
|
|
23
|
-
// SimpleEditor,
|
|
24
|
-
// PlainMarkdownEditor,
|
|
25
|
-
// DiffViewer,
|
|
26
|
-
// MarkdownViewer,
|
|
27
|
-
// SeatableViewer,
|
|
28
|
-
// Toolbar,
|
|
29
|
-
// Outline,
|
|
30
|
-
// UserHelp,
|
|
31
|
-
// deserialize,
|
|
32
|
-
// serialize,
|
|
33
|
-
// processor,
|
|
34
|
-
// SeatableEditor,
|
|
35
|
-
// replaceColumnData,
|
|
36
|
-
NewEditor };
|
|
1
|
+
import SDocEditor from './editor';
|
|
2
|
+
export { SDocEditor };
|
|
@@ -10,7 +10,7 @@ export var moveChildren = function moveChildren(editor, _ref) {
|
|
|
10
10
|
var moved = 0;
|
|
11
11
|
var parentPath = Path.isPath(at) ? at : at[1];
|
|
12
12
|
var parentNode = Path.isPath(at) ? getNode(editor, parentPath) : at[0];
|
|
13
|
-
|
|
13
|
+
if (!parentNode) return moved;
|
|
14
14
|
// There have none children in a not block element
|
|
15
15
|
if (!Editor.isBlock(editor, parentNode)) return moved;
|
|
16
16
|
for (var i = parentNode.children.length - 1; i >= fromStartIndex; i--) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import { Editor, Transforms } from
|
|
3
|
-
import { BLOCKQUOTE } from
|
|
4
|
-
import { getNodeType } from
|
|
2
|
+
import { Editor, Transforms } from 'slate';
|
|
3
|
+
import { BLOCKQUOTE } from '../../constants';
|
|
4
|
+
import { getNodeType } from '../../core';
|
|
5
5
|
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
6
6
|
if (editor.selection == null) return true;
|
|
7
7
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
@@ -3,6 +3,7 @@ import BlockquotePlugin from './blockquote';
|
|
|
3
3
|
import ListPlugin from './list';
|
|
4
4
|
import CheckListPlugin from './check-list';
|
|
5
5
|
import TextPlugin from './text-style';
|
|
6
|
-
|
|
6
|
+
import SocketPlugin from './socket';
|
|
7
|
+
var Plugins = [HeaderPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, SocketPlugin];
|
|
7
8
|
export default Plugins;
|
|
8
|
-
export { HeaderPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin };
|
|
9
|
+
export { HeaderPlugin, BlockquotePlugin, ListPlugin, CheckListPlugin, TextPlugin, SocketPlugin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
-
import { Transforms, Editor, Path } from 'slate';
|
|
4
|
+
import { Transforms, Editor, Path, Element } from 'slate';
|
|
5
5
|
import { LIST_LIC } from '../../../constants';
|
|
6
6
|
import { getChildren, getDeepInlineChildren, match } from '../../../core';
|
|
7
7
|
import { getListTypes } from '../queries';
|
|
@@ -79,7 +79,7 @@ export var normalizeListItem = function normalizeListItem(editor, _ref) {
|
|
|
79
79
|
try {
|
|
80
80
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
81
81
|
var licChild = _step.value;
|
|
82
|
-
if (!Editor.isBlock(editor, licChild[0])) {
|
|
82
|
+
if (!(Element.isElement(licChild[0]) && Editor.isBlock(editor, licChild[0]))) {
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
85
|
blockPathRefs.push(Editor.pathRef(editor, licChild[1]));
|
|
@@ -6,15 +6,19 @@ import { findNode, getNodeEntries, getNodeType, getSelectedNodeEntryByType, isRa
|
|
|
6
6
|
import { getListItemEntry, getListTypes } from '../queries';
|
|
7
7
|
import { unwrapList } from './unwrap-list';
|
|
8
8
|
var wrapLineList = function wrapLineList(editor, type) {
|
|
9
|
+
Transforms.wrapNodes(editor, {
|
|
10
|
+
type: type,
|
|
11
|
+
children: []
|
|
12
|
+
});
|
|
9
13
|
var nodeEntry = getSelectedNodeEntryByType(editor, PARAGRAPH);
|
|
14
|
+
if (!nodeEntry) return;
|
|
10
15
|
var _nodeEntry = _slicedToArray(nodeEntry, 2),
|
|
11
16
|
node = _nodeEntry[0],
|
|
12
17
|
path = _nodeEntry[1];
|
|
13
18
|
if (node.type !== LIST_LIC) {
|
|
19
|
+
// paragraph to list-lic
|
|
14
20
|
Transforms.setNodes(editor, {
|
|
15
21
|
type: LIST_LIC
|
|
16
|
-
}, {
|
|
17
|
-
at: path
|
|
18
22
|
});
|
|
19
23
|
}
|
|
20
24
|
Transforms.wrapNodes(editor, {
|
|
@@ -23,12 +27,6 @@ var wrapLineList = function wrapLineList(editor, type) {
|
|
|
23
27
|
}, {
|
|
24
28
|
at: path
|
|
25
29
|
});
|
|
26
|
-
Transforms.wrapNodes(editor, {
|
|
27
|
-
type: type,
|
|
28
|
-
children: []
|
|
29
|
-
}, {
|
|
30
|
-
at: path
|
|
31
|
-
});
|
|
32
30
|
return;
|
|
33
31
|
};
|
|
34
32
|
var wrapRangeList = function wrapRangeList(editor, type) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import SocketManager from "../../socket/socket-manager";
|
|
2
|
+
var withSocket = function withSocket(editor) {
|
|
3
|
+
var apply = editor.apply;
|
|
4
|
+
var newEditor = editor;
|
|
5
|
+
newEditor.apply = function (operation) {
|
|
6
|
+
var isRemote = operation.is_remote;
|
|
7
|
+
if (isRemote) {
|
|
8
|
+
apply(operation);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 合并 op
|
|
13
|
+
try {
|
|
14
|
+
var socketManager = SocketManager.getInstance();
|
|
15
|
+
socketManager.addOperation && socketManager.addOperation(operation);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
// first load, socketManager has not been init
|
|
18
|
+
}
|
|
19
|
+
apply(operation);
|
|
20
|
+
};
|
|
21
|
+
return newEditor;
|
|
22
|
+
};
|
|
23
|
+
export default withSocket;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import io from 'socket.io-client';
|
|
5
|
+
import Debug from 'debug';
|
|
6
|
+
import SocketManager from './socket-manager';
|
|
7
|
+
var debug = Debug('sdoc:socket-client');
|
|
8
|
+
var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
|
|
9
|
+
var _this = this;
|
|
10
|
+
_classCallCheck(this, SocketClient);
|
|
11
|
+
this.getParams = function () {
|
|
12
|
+
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
13
|
+
return _objectSpread({}, params);
|
|
14
|
+
};
|
|
15
|
+
this.onConnected = function () {
|
|
16
|
+
var socketManager = SocketManager.getInstance();
|
|
17
|
+
var _this$config = _this.config,
|
|
18
|
+
fileUuid = _this$config.fileUuid,
|
|
19
|
+
filePath = _this$config.filePath,
|
|
20
|
+
fileName = _this$config.fileName,
|
|
21
|
+
accessToken = _this$config.accessToken;
|
|
22
|
+
var params = {
|
|
23
|
+
file_uuid: fileUuid,
|
|
24
|
+
file_path: filePath,
|
|
25
|
+
file_name: fileName,
|
|
26
|
+
access_token: accessToken
|
|
27
|
+
};
|
|
28
|
+
_this.socket.emit('join-room', params, function (result) {
|
|
29
|
+
if (result.status) {
|
|
30
|
+
socketManager.dispatchConnectState('connect', result);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Disconnect the server in the client side. There will be no reconnection.
|
|
35
|
+
_this.socket.disconnect();
|
|
36
|
+
socketManager.dispatchConnectState('connect-error', result);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
this.onReconnect = function (data) {
|
|
40
|
+
debug('reconnect.');
|
|
41
|
+
var socketManager = SocketManager.getInstance();
|
|
42
|
+
socketManager.dispatchConnectState('reconnect');
|
|
43
|
+
};
|
|
44
|
+
this.onReconnecting = function (attemptNumber) {
|
|
45
|
+
debug('reconnecting.', attemptNumber);
|
|
46
|
+
var socketManager = SocketManager.getInstance();
|
|
47
|
+
socketManager.dispatchConnectState('reconnecting', attemptNumber);
|
|
48
|
+
};
|
|
49
|
+
this.onDisconnected = function (data) {
|
|
50
|
+
debug('disconnect message: %s', data);
|
|
51
|
+
var socketManager = SocketManager.getInstance();
|
|
52
|
+
socketManager.dispatchConnectState('disconnect');
|
|
53
|
+
};
|
|
54
|
+
this.onJoinRoom = function (username) {
|
|
55
|
+
debug('%s joined room success.', username);
|
|
56
|
+
var socketManager = SocketManager.getInstance();
|
|
57
|
+
socketManager.dispatchConnectState('join-room', username);
|
|
58
|
+
};
|
|
59
|
+
this.onLeaveRoom = function (username) {
|
|
60
|
+
debug('%s leaved room success.', username);
|
|
61
|
+
var socketManager = SocketManager.getInstance();
|
|
62
|
+
socketManager.dispatchConnectState('leave-room', username);
|
|
63
|
+
};
|
|
64
|
+
this.sendOperation = function (operation, callback) {
|
|
65
|
+
debug('==================================');
|
|
66
|
+
debug('send operation: %s' + operation.toString());
|
|
67
|
+
debug('==================================');
|
|
68
|
+
_this.socket.emit('update-document', _this.getParams({
|
|
69
|
+
operation: operation
|
|
70
|
+
}), function (result) {
|
|
71
|
+
callback && callback(result);
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
this.receiveOperation = function (operation, version) {
|
|
75
|
+
debug('==================================');
|
|
76
|
+
debug('received operation: %s' + operation.toString());
|
|
77
|
+
debug('==================================');
|
|
78
|
+
var socketManager = SocketManager.getInstance();
|
|
79
|
+
socketManager.receiveOperation(operation, version);
|
|
80
|
+
};
|
|
81
|
+
this.disconnectWithServer = function () {
|
|
82
|
+
_this.socket.disconnect();
|
|
83
|
+
};
|
|
84
|
+
this.config = config;
|
|
85
|
+
this.socket = io(config.sdocServer);
|
|
86
|
+
this.socket.on('connect', this.onConnected);
|
|
87
|
+
this.socket.on('reconnect', this.onReconnect);
|
|
88
|
+
this.socket.on('reconnecting', this.onReconnecting);
|
|
89
|
+
this.socket.on('disconnect', this.onDisconnected);
|
|
90
|
+
this.socket.on('join-room', this.onJoinRoom);
|
|
91
|
+
this.socket.on('leave-room', this.onLeaveRoom);
|
|
92
|
+
this.socket.on('update-document', this.receiveOperation);
|
|
93
|
+
});
|
|
94
|
+
export default SocketClient;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import EventBus from '../../utils/event-bus';
|
|
4
|
+
import SocketClient from './socket-client';
|
|
5
|
+
var SocketManager = /*#__PURE__*/_createClass(function SocketManager(document, config) {
|
|
6
|
+
var _this = this;
|
|
7
|
+
_classCallCheck(this, SocketManager);
|
|
8
|
+
this.addOperation = function (operation) {
|
|
9
|
+
_this.pendingOperations.push(operation);
|
|
10
|
+
_this.sendOperation();
|
|
11
|
+
};
|
|
12
|
+
this.sendOperation = function () {
|
|
13
|
+
if (_this.isSendingOperation || _this.pendingOperations.length === 0) return;
|
|
14
|
+
_this.isSendingOperation = true;
|
|
15
|
+
_this.sendNextOperation();
|
|
16
|
+
};
|
|
17
|
+
this.sendNextOperation = function () {
|
|
18
|
+
if (_this.pendingOperations.length === 0) {
|
|
19
|
+
_this.isSendingOperation = false;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
var operation = _this.pendingOperations.shift();
|
|
23
|
+
_this.sendingOperation = operation;
|
|
24
|
+
_this.socketClient.sendOperation(operation, _this.sendOperationCallback);
|
|
25
|
+
};
|
|
26
|
+
this.sendOperationCallback = function (result) {
|
|
27
|
+
if (result && result.success) {
|
|
28
|
+
_this.sendingOperation = null;
|
|
29
|
+
var remoteVersion = result.version;
|
|
30
|
+
var localeVersion = _this.doc.version;
|
|
31
|
+
_this.doc['version'] = remoteVersion > localeVersion ? remoteVersion : localeVersion;
|
|
32
|
+
_this.sendNextOperation();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// operation is execute failure
|
|
37
|
+
_this.sendingOperation = null;
|
|
38
|
+
_this.sendNextOperation();
|
|
39
|
+
};
|
|
40
|
+
this.receiveOperation = function (params, last_version) {
|
|
41
|
+
_this.eventBus.dispatch('receive-operation', params);
|
|
42
|
+
};
|
|
43
|
+
this.dispatchConnectState = function (type, message) {
|
|
44
|
+
console.log(type);
|
|
45
|
+
};
|
|
46
|
+
this.doc = document;
|
|
47
|
+
this.socketClient = new SocketClient(config);
|
|
48
|
+
this.sendingOperation = null;
|
|
49
|
+
this.pendingOperations = [];
|
|
50
|
+
this.isSendingOperation = false;
|
|
51
|
+
this.eventBus = new EventBus();
|
|
52
|
+
});
|
|
53
|
+
SocketManager.getInstance = function (document, socketConfig) {
|
|
54
|
+
if (SocketManager.instance) {
|
|
55
|
+
return SocketManager.instance;
|
|
56
|
+
}
|
|
57
|
+
if (!document || !socketConfig) {
|
|
58
|
+
throw new Error('SocketManager init params is invalid. Place check your code to fix it.');
|
|
59
|
+
}
|
|
60
|
+
SocketManager.instance = new SocketManager(document, socketConfig);
|
|
61
|
+
return SocketManager.instance;
|
|
62
|
+
};
|
|
63
|
+
export default SocketManager;
|
|
@@ -9,7 +9,7 @@ import { ORDERED_LIST, UNORDERED_LIST } from '../constants';
|
|
|
9
9
|
import HeaderMenu from '../plugins/header/menu';
|
|
10
10
|
import CheckListMenu from '../plugins/check-list/menu';
|
|
11
11
|
import { MenuGroup } from '../menu';
|
|
12
|
-
import '../../assets/css/
|
|
12
|
+
import '../../assets/css/sdoc-editor-toolbar.css';
|
|
13
13
|
var Toolbar = /*#__PURE__*/function (_React$Component) {
|
|
14
14
|
_inherits(Toolbar, _React$Component);
|
|
15
15
|
var _super = _createSuper(Toolbar);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
var EventBus = /*#__PURE__*/function () {
|
|
4
|
+
function EventBus() {
|
|
5
|
+
_classCallCheck(this, EventBus);
|
|
6
|
+
this.subscribers = {};
|
|
7
|
+
}
|
|
8
|
+
_createClass(EventBus, [{
|
|
9
|
+
key: "subscribe",
|
|
10
|
+
value: function subscribe(type, handler) {
|
|
11
|
+
if (!this.subscribers[type]) {
|
|
12
|
+
this.subscribers[type] = [];
|
|
13
|
+
}
|
|
14
|
+
var handlers = this.subscribers[type];
|
|
15
|
+
handlers.push(handler);
|
|
16
|
+
return function () {
|
|
17
|
+
var index = handlers.indexOf(handler);
|
|
18
|
+
if (index > -1) {
|
|
19
|
+
handlers.splice(index, 1);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}, {
|
|
24
|
+
key: "dispatch",
|
|
25
|
+
value: function dispatch(type) {
|
|
26
|
+
for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
27
|
+
data[_key - 1] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
var handlers = this.subscribers[type];
|
|
30
|
+
if (Array.isArray(handlers)) {
|
|
31
|
+
handlers.forEach(function (handler) {
|
|
32
|
+
return handler.apply(void 0, data);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}]);
|
|
37
|
+
return EventBus;
|
|
38
|
+
}();
|
|
39
|
+
export default EventBus;
|
package/package.json
CHANGED
|
@@ -1,39 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "This is a sdoc editor",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@seafile/react-image-lightbox": "2.0.2",
|
|
9
|
-
"@seafile/slate-react": "^0.54.13",
|
|
10
|
-
"codemirror": "^5.37.0",
|
|
11
|
-
"deepmerge": "^2.1.0",
|
|
12
|
-
"detect-indent": "^4.0.0",
|
|
13
|
-
"hast-util-sanitize": "^1.1.2",
|
|
14
9
|
"is-hotkey": "0.2.0",
|
|
15
|
-
"
|
|
16
|
-
"lodash": "4.17.21",
|
|
17
|
-
"mdast-util-definitions": "^1.2.2",
|
|
18
|
-
"prismjs": "1.23.0",
|
|
10
|
+
"react-cookies": "0.1.1",
|
|
19
11
|
"reactstrap": "8.9.0",
|
|
20
|
-
"
|
|
21
|
-
"rehype-mathjax": "^2.0.0",
|
|
22
|
-
"rehype-raw": "^2.0.0",
|
|
23
|
-
"rehype-stringify": "^3.0.0",
|
|
24
|
-
"remark": "^9.0.0",
|
|
25
|
-
"remark-breaks": "^1.0.0",
|
|
26
|
-
"remark-math": "^3.0.0",
|
|
27
|
-
"remark-parse": "^5.0.0",
|
|
28
|
-
"remark-rehype": "^3.0.0",
|
|
29
|
-
"remark-slug": "^5.0.0",
|
|
30
|
-
"slate": "0.88.1",
|
|
12
|
+
"slate": "0.91.4",
|
|
31
13
|
"slate-history": "0.86.0",
|
|
32
14
|
"slate-hyperscript": "0.77.0",
|
|
33
|
-
"slate-react": "0.
|
|
34
|
-
"
|
|
35
|
-
"url-parse": "^1.4.3",
|
|
36
|
-
"xtend": "^4.0.1"
|
|
15
|
+
"slate-react": "0.92.0",
|
|
16
|
+
"socket.io-client": "4.6.1"
|
|
37
17
|
},
|
|
38
18
|
"scripts": {
|
|
39
19
|
"clean": "rm -rf dist && mkdir dist",
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
.seafile-editor-comment.comment-dialog {
|
|
2
|
-
width: 500px;
|
|
3
|
-
position: absolute;
|
|
4
|
-
top: 30%;
|
|
5
|
-
right: 0;
|
|
6
|
-
padding: 15px;
|
|
7
|
-
background-color: #fafafa;
|
|
8
|
-
border: 1px solid rgba(0,0,0,.2);
|
|
9
|
-
border-radius: .3rem;
|
|
10
|
-
box-shadow: 0 0 3px #ccc;
|
|
11
|
-
z-index: 1000;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.seafile-editor-comment.comment-dialog .comment-dialog-triangle {
|
|
15
|
-
position: absolute;
|
|
16
|
-
left: -5px;
|
|
17
|
-
top: 50%;
|
|
18
|
-
transform: rotate(45deg);
|
|
19
|
-
border: 1px solid rgba(0,0,0,.2);
|
|
20
|
-
border-top: none;
|
|
21
|
-
border-right: none;
|
|
22
|
-
width: 10px;
|
|
23
|
-
height: 10px;
|
|
24
|
-
background-color: #fafafa;
|
|
25
|
-
box-shadow: -1px 1px #ccc;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.seafile-editor-comment.comment-dialog textarea {
|
|
29
|
-
width: 100%;
|
|
30
|
-
min-height: 100px;
|
|
31
|
-
max-height: 300px;
|
|
32
|
-
padding: 5px;
|
|
33
|
-
background-color: #fff;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.seafile-editor-comment.comment-dialog .button-group .btn {
|
|
37
|
-
margin-right: 10px;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.seafile-editor-comment.comment-dialog .comment-dialog-quote {
|
|
41
|
-
margin-top: 10px;
|
|
42
|
-
max-height: 6rem;
|
|
43
|
-
overflow: auto;
|
|
44
|
-
padding-left: 1rem;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.seafile-editor-comment.comment-dialog .comment-dialog-quote ul,
|
|
48
|
-
.seafile-editor-comment.comment-dialog .comment-dialog-quote ol {
|
|
49
|
-
padding-left: 1rem;
|
|
50
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
.diff-added {
|
|
2
|
-
padding: 0 5px;
|
|
3
|
-
margin: 0 -5px;
|
|
4
|
-
background-color: #e6ffed;
|
|
5
|
-
overflow: hidden;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.diff-removed {
|
|
9
|
-
padding: 0 5px;
|
|
10
|
-
margin: 0 -5px;
|
|
11
|
-
overflow: hidden;
|
|
12
|
-
background-color: #ffeef0;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.diff-removed * {
|
|
16
|
-
border-left: none;
|
|
17
|
-
padding-left: 0
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.diff-added * {
|
|
21
|
-
padding-left: 0;
|
|
22
|
-
border-left: none;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.diff-replaced {
|
|
27
|
-
padding-left: 2px;
|
|
28
|
-
margin-left: -5px;
|
|
29
|
-
border-left: 3px solid #f9c513;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.diff-replaced .diff-added {
|
|
33
|
-
background-color: #e6ffed;
|
|
34
|
-
margin-left: 0;
|
|
35
|
-
padding-left: 0;
|
|
36
|
-
overflow: visible;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.diff-replaced .diff-removed {
|
|
40
|
-
overflow: visible;
|
|
41
|
-
padding-left: 0;
|
|
42
|
-
color: #cb2431;
|
|
43
|
-
margin-left: 0;
|
|
44
|
-
background-color: #ffeef0;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.diff-replaced .diff-replaced {
|
|
48
|
-
border-left: none;
|
|
49
|
-
margin-left: 0;
|
|
50
|
-
overflow: visible;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.diff-replaced .diff-removed-container {
|
|
54
|
-
padding: 0 5px;
|
|
55
|
-
margin: 0 -5px;
|
|
56
|
-
background-color: #ffeef0;
|
|
57
|
-
box-sizing: border-box;
|
|
58
|
-
overflow: hidden;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.diff-replaced .diff-added-container {
|
|
62
|
-
padding: 0 5px;
|
|
63
|
-
margin: 0 -5px;
|
|
64
|
-
background-color: #e6ffed;
|
|
65
|
-
box-sizing: border-box;
|
|
66
|
-
overflow: hidden;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
.diff-replaced table .diff-added {
|
|
71
|
-
background-color: #e6ffed;
|
|
72
|
-
padding: 0 0;
|
|
73
|
-
margin: 0;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
.diff-replaced table .diff-removed {
|
|
77
|
-
background-color: #ffeef0;
|
|
78
|
-
margin: 0;
|
|
79
|
-
padding: 0 0;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.diff-replaced table tr.diff-replaced {
|
|
83
|
-
padding-left: 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.diff-replaced del {
|
|
87
|
-
background-color: #fdb8c0;
|
|
88
|
-
text-decoration: none;
|
|
89
|
-
color: #cb2431;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
.diff-replaced ins {
|
|
93
|
-
background-color: #acf2bd;
|
|
94
|
-
text-decoration: none;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
.article .diff-replaced .old-paragraph {
|
|
98
|
-
background-color: #ffeef0;
|
|
99
|
-
margin-bottom: 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.article .diff-replaced .new-paragraph {
|
|
103
|
-
background-color: #e6ffed;
|
|
104
|
-
margin-top: 0;
|
|
105
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
.seafile-editor-module .selected-formula {
|
|
2
|
-
outline: 2px solid #007bff;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
.seafile-editor-module .block-formula {
|
|
6
|
-
display: block;
|
|
7
|
-
user-select: none;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.seafile-editor-module .MathJax {
|
|
11
|
-
margin: 0;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.formula-preview {
|
|
15
|
-
padding: 10px;
|
|
16
|
-
border: 2px dashed #ebebeb;
|
|
17
|
-
min-height: 40px;
|
|
18
|
-
overflow-x: auto;
|
|
19
|
-
}
|