@seafile/sdoc-editor 0.1.1 → 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/editor.js +18 -3
- 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/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/plugin.js +6 -0
- package/dist/slate-extension/socket/socket-client.js +12 -2
- package/dist/slate-extension/socket/socket-manager.js +4 -2
- package/dist/utils/event-bus.js +39 -0
- package/package.json +3 -3
package/dist/editor.js
CHANGED
|
@@ -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";
|
|
@@ -15,6 +16,12 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
15
16
|
var _this;
|
|
16
17
|
_classCallCheck(this, SDocEditor);
|
|
17
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
|
+
};
|
|
18
25
|
_this.onChange = function (slateValue) {
|
|
19
26
|
var onValueChanged = _this.props.onValueChanged;
|
|
20
27
|
_this.setState({
|
|
@@ -22,12 +29,13 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
22
29
|
});
|
|
23
30
|
onValueChanged && onValueChanged(slateValue);
|
|
24
31
|
};
|
|
25
|
-
var
|
|
32
|
+
var children = props.document.children;
|
|
26
33
|
_this.state = {
|
|
27
|
-
slateValue:
|
|
34
|
+
slateValue: children,
|
|
28
35
|
isLoading: true
|
|
29
36
|
};
|
|
30
37
|
_this.editor = editor;
|
|
38
|
+
_this.socketManager = null;
|
|
31
39
|
return _this;
|
|
32
40
|
}
|
|
33
41
|
_createClass(SDocEditor, [{
|
|
@@ -38,9 +46,16 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
|
|
|
38
46
|
document = _this$props.document,
|
|
39
47
|
config = _this$props.config;
|
|
40
48
|
if (isOpenSocket) {
|
|
41
|
-
SocketManager.getInstance(document, config);
|
|
49
|
+
this.socketManager = SocketManager.getInstance(document, config);
|
|
50
|
+
var eventBus = this.socketManager.eventBus;
|
|
51
|
+
this.unsubscribeReceiveOption = eventBus.subscribe('receive-operation', this.updateWithRemoteOperation);
|
|
42
52
|
}
|
|
43
53
|
}
|
|
54
|
+
}, {
|
|
55
|
+
key: "componentWillUnmount",
|
|
56
|
+
value: function componentWillUnmount() {
|
|
57
|
+
this.unsubscribeReceiveOption();
|
|
58
|
+
}
|
|
44
59
|
}, {
|
|
45
60
|
key: "render",
|
|
46
61
|
value: function render() {
|
|
@@ -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, {
|
|
@@ -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) {
|
|
@@ -3,6 +3,12 @@ var withSocket = function withSocket(editor) {
|
|
|
3
3
|
var apply = editor.apply;
|
|
4
4
|
var newEditor = editor;
|
|
5
5
|
newEditor.apply = function (operation) {
|
|
6
|
+
var isRemote = operation.is_remote;
|
|
7
|
+
if (isRemote) {
|
|
8
|
+
apply(operation);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
// 合并 op
|
|
7
13
|
try {
|
|
8
14
|
var socketManager = SocketManager.getInstance();
|
|
@@ -14,8 +14,18 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
|
|
|
14
14
|
};
|
|
15
15
|
this.onConnected = function () {
|
|
16
16
|
var socketManager = SocketManager.getInstance();
|
|
17
|
-
|
|
18
|
-
|
|
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) {
|
|
19
29
|
if (result.status) {
|
|
20
30
|
socketManager.dispatchConnectState('connect', result);
|
|
21
31
|
return;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import EventBus from '../../utils/event-bus';
|
|
3
4
|
import SocketClient from './socket-client';
|
|
4
5
|
var SocketManager = /*#__PURE__*/_createClass(function SocketManager(document, config) {
|
|
5
6
|
var _this = this;
|
|
@@ -36,8 +37,8 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(document, c
|
|
|
36
37
|
_this.sendingOperation = null;
|
|
37
38
|
_this.sendNextOperation();
|
|
38
39
|
};
|
|
39
|
-
this.receiveOperation = function (
|
|
40
|
-
|
|
40
|
+
this.receiveOperation = function (params, last_version) {
|
|
41
|
+
_this.eventBus.dispatch('receive-operation', params);
|
|
41
42
|
};
|
|
42
43
|
this.dispatchConnectState = function (type, message) {
|
|
43
44
|
console.log(type);
|
|
@@ -47,6 +48,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(document, c
|
|
|
47
48
|
this.sendingOperation = null;
|
|
48
49
|
this.pendingOperations = [];
|
|
49
50
|
this.isSendingOperation = false;
|
|
51
|
+
this.eventBus = new EventBus();
|
|
50
52
|
});
|
|
51
53
|
SocketManager.getInstance = function (document, socketConfig) {
|
|
52
54
|
if (SocketManager.instance) {
|
|
@@ -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,6 +1,6 @@
|
|
|
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",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"is-hotkey": "0.2.0",
|
|
10
10
|
"react-cookies": "0.1.1",
|
|
11
11
|
"reactstrap": "8.9.0",
|
|
12
|
-
"slate": "0.
|
|
12
|
+
"slate": "0.91.4",
|
|
13
13
|
"slate-history": "0.86.0",
|
|
14
14
|
"slate-hyperscript": "0.77.0",
|
|
15
|
-
"slate-react": "0.
|
|
15
|
+
"slate-react": "0.92.0",
|
|
16
16
|
"socket.io-client": "4.6.1"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|