@seafile/sdoc-editor 0.1.10 → 0.1.12

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.
@@ -19,11 +19,11 @@ var SDocServerApi = /*#__PURE__*/function () {
19
19
  }
20
20
  _createClass(SDocServerApi, [{
21
21
  key: "getDocContent",
22
- value: function getDocContent(docPath, docName) {
22
+ value: function getDocContent() {
23
23
  var server = this.server,
24
24
  docUuid = this.docUuid,
25
25
  accessToken = this.accessToken;
26
- var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/?doc_path=").concat(encodeURIComponent(docPath), "&doc_name=").concat(encodeURIComponent(docName));
26
+ var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/");
27
27
  return axios.get(url, {
28
28
  headers: {
29
29
  Authorization: "Token ".concat(accessToken)
@@ -32,14 +32,12 @@ var SDocServerApi = /*#__PURE__*/function () {
32
32
  }
33
33
  }, {
34
34
  key: "saveDocContent",
35
- value: function saveDocContent(docPath, docName, content) {
35
+ value: function saveDocContent(content) {
36
36
  var server = this.server,
37
37
  docUuid = this.docUuid,
38
38
  accessToken = this.accessToken;
39
39
  var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/");
40
40
  var formData = new FormData();
41
- formData.append('doc_path', docPath);
42
- formData.append('doc_name', docName);
43
41
  formData.append('doc_content', content);
44
42
  return axios.post(url, formData, {
45
43
  headers: {
@@ -4,10 +4,10 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import { Editable, Slate } from '@seafile/slate-react';
7
- import isHotkey from 'is-hotkey';
8
7
  import editor, { renderLeaf as _renderLeaf, renderElement as _renderElement, Toolbar } from './extension';
9
8
  import { SocketManager, withSocketIO } from './socket';
10
9
  import withNodeId from './node-id';
10
+ import EventProxy from './utils/event-handler';
11
11
  import './assets/css/layout.css';
12
12
  import './assets/css/sdoc-editor-plugins.css';
13
13
  var SDocEditor = /*#__PURE__*/function (_React$Component) {
@@ -33,11 +33,11 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
33
33
  isLoading: true
34
34
  };
35
35
  _this.socketManager = null;
36
- if (!props.isOpenSocket) {
37
- _this.editor = withNodeId(editor);
38
- } else {
39
- _this.editor = withSocketIO(withNodeId(editor));
36
+ _this.editor = withNodeId(editor);
37
+ if (props.isOpenSocket) {
38
+ _this.editor = withSocketIO(_this.editor);
40
39
  }
40
+ _this.eventProxy = new EventProxy(_this.editor);
41
41
  return _this;
42
42
  }
43
43
  _createClass(SDocEditor, [{
@@ -83,11 +83,7 @@ var SDocEditor = /*#__PURE__*/function (_React$Component) {
83
83
  return _renderLeaf(props, _this2.editor);
84
84
  },
85
85
  onDOMBeforeInput: function onDOMBeforeInput(event) {},
86
- onKeyDown: function onKeyDown(event) {
87
- if (isHotkey('tab', event) || isHotkey('shift+tab', event)) {
88
- editor.handleTab && editor.handleTab(event);
89
- }
90
- }
86
+ onKeyDown: this.eventProxy.onKeyDown
91
87
  })))));
92
88
  }
93
89
  }]);
@@ -1,3 +1,4 @@
1
1
  export * from './move-children';
2
2
  export * from './remove-node-children';
3
- export * from './focus-editor';
3
+ export * from './focus-editor';
4
+ export * from './replace-node-children';
@@ -0,0 +1,15 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import { Editor, Transforms } from '@seafile/slate';
3
+ import { removeNodeChildren } from './remove-node-children';
4
+ export var replaceNodeChildren = function replaceNodeChildren(editor, _ref) {
5
+ var at = _ref.at,
6
+ nodes = _ref.nodes,
7
+ insertOptions = _ref.insertOptions,
8
+ removeOptions = _ref.removeOptions;
9
+ Editor.withoutNormalizing(editor, function () {
10
+ removeNodeChildren(editor, at, removeOptions);
11
+ Transforms.insertNodes(editor, nodes, _objectSpread(_objectSpread({}, insertOptions), {}, {
12
+ at: at.concat([0])
13
+ }));
14
+ });
15
+ };
@@ -1,9 +1,10 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
4
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
5
  import { Editor, Transforms, Range } from '@seafile/slate';
5
6
  import { LINK } from '../../constants';
6
- import { getNodeType, getSelectedElems, removeNodeChildren, getAboveNode, getEditorString } from '../../core';
7
+ import { getNodeType, getSelectedElems, getAboveNode, getEditorString, replaceNodeChildren } from '../../core';
7
8
  export var isMenuDisabled = function isMenuDisabled(editor) {
8
9
  if (editor.selection == null) return true;
9
10
  var selectedElems = getSelectedElems(editor);
@@ -86,32 +87,56 @@ export var insertLink = function insertLink(editor, text, url) {
86
87
  };
87
88
  export var updateLink = function updateLink(editor, newText, newUrl) {
88
89
  // Update children
89
- var oldLink = getAboveNode(editor, {
90
+ var linkAbove = getAboveNode(editor, {
90
91
  match: {
91
- type: 'link'
92
+ type: LINK
92
93
  }
93
94
  });
94
- if (oldLink) {
95
- var _oldLink = _slicedToArray(oldLink, 2),
96
- oldLinkNode = _oldLink[0],
97
- oldLinkPath = _oldLink[1];
98
- var oldUrl = oldLinkNode.href;
99
- if (newText !== getEditorString(editor, oldLinkPath) || newUrl !== oldUrl) {
100
- // Remove link children
101
- removeNodeChildren(editor, oldLinkPath, {
102
- select: true
95
+ if (linkAbove) {
96
+ var _ref = linkAbove[0] || {},
97
+ oldUrl = _ref.href,
98
+ oldText = _ref.title;
99
+ if (oldUrl !== newUrl || oldText !== newText) {
100
+ Transforms.setNodes(editor, {
101
+ href: newUrl,
102
+ title: newText
103
+ }, {
104
+ at: linkAbove[1]
103
105
  });
104
-
105
- // insert link node
106
- var linkNode = genLinkNode(newUrl, newText);
107
- Transforms.insertNodes(editor, linkNode, {
108
- select: true
106
+ }
107
+ upsertLinkText(editor, {
108
+ text: newText
109
+ });
110
+ return true;
111
+ }
112
+ };
113
+ export var upsertLinkText = function upsertLinkText(editor, _ref2) {
114
+ var text = _ref2.text;
115
+ var newLink = getAboveNode(editor, {
116
+ match: {
117
+ type: LINK
118
+ }
119
+ });
120
+ if (newLink) {
121
+ var _newLink = _slicedToArray(newLink, 2),
122
+ newLInkNode = _newLink[0],
123
+ newLinkPath = _newLink[1];
124
+ if (text && text.length && text !== getEditorString(editor, newLinkPath)) {
125
+ var firstText = newLInkNode.children[0];
126
+ replaceNodeChildren(editor, {
127
+ at: newLinkPath,
128
+ nodes: _objectSpread(_objectSpread({}, firstText), {}, {
129
+ text: text
130
+ }),
131
+ insertOptions: {
132
+ select: true
133
+ }
109
134
  });
110
135
  }
111
136
  }
112
137
  };
113
138
  export var unWrapLinkNode = /*#__PURE__*/function () {
114
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(editor) {
139
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(editor) {
115
140
  var _Editor$nodes3, _Editor$nodes4, nodeEntry;
116
141
  return _regeneratorRuntime().wrap(function _callee$(_context) {
117
142
  while (1) switch (_context.prev = _context.next) {
@@ -147,6 +172,6 @@ export var unWrapLinkNode = /*#__PURE__*/function () {
147
172
  }, _callee);
148
173
  }));
149
174
  return function unWrapLinkNode(_x) {
150
- return _ref.apply(this, arguments);
175
+ return _ref3.apply(this, arguments);
151
176
  };
152
177
  }();
@@ -15,19 +15,8 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
15
15
  }, params);
16
16
  };
17
17
  this.onConnected = function () {
18
- var _this$config = _this.config,
19
- doc_uuid = _this$config.docUuid,
20
- doc_path = _this$config.docPath,
21
- doc_name = _this$config.docName,
22
- access_token = _this$config.accessToken;
23
- var params = {
24
- doc_uuid: doc_uuid,
25
- doc_path: doc_path,
26
- doc_name: doc_name,
27
- access_token: access_token
28
- };
29
18
  // join room
30
- _this.socket.emit('join-room', params, function (result) {
19
+ _this.socket.emit('join-room', function (result) {
31
20
  var socketManager = SocketManager.getInstance();
32
21
  if (result.success) {
33
22
  // sync operations or document
@@ -74,10 +63,10 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
74
63
  var socketManager = SocketManager.getInstance();
75
64
  socketManager.dispatchConnectState('connect_error');
76
65
  };
77
- this.onJoinRoom = function (username) {
78
- debug('%s joined room success.', username);
66
+ this.onJoinRoom = function (userInfo) {
67
+ debug('%s joined room success.', userInfo.username);
79
68
  var socketManager = SocketManager.getInstance();
80
- socketManager.dispatchConnectState('join-room', username);
69
+ socketManager.dispatchConnectState('join-room', userInfo);
81
70
  };
82
71
  this.onLeaveRoom = function (username) {
83
72
  debug('%s leaved room success.', username);
@@ -0,0 +1,22 @@
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import isHotkey from 'is-hotkey';
4
+ var EventProxy = /*#__PURE__*/_createClass(function EventProxy(_editor) {
5
+ var _this = this;
6
+ _classCallCheck(this, EventProxy);
7
+ this.onKeyDown = function (event) {
8
+ var editor = _this.editor;
9
+ if (isHotkey('tab', event) || isHotkey('shift+tab', event)) {
10
+ editor.handleTab && editor.handleTab(event);
11
+ }
12
+ };
13
+ this.onCopy = function (event) {
14
+ event.stopPropagation();
15
+ event.nativeEvent.stopImmediatePropagation();
16
+ // 处理数据
17
+ };
18
+ this.onCut = function (event) {};
19
+ this.onPaste = function (event) {};
20
+ this.editor = _editor;
21
+ });
22
+ export default EventProxy;
@@ -6,7 +6,6 @@ import React, { Fragment } from 'react';
6
6
  import { EventBus } from '../../../basic-sdk';
7
7
  import context from '../../../context';
8
8
  import CollaboratorsPopover from './collaborators-popover';
9
- var URL = 'https://tupian.qqw21.com/article/UploadPic/2020-8/20208522181570993.jpg';
10
9
  var CollaboratorsOperation = /*#__PURE__*/function (_React$PureComponent) {
11
10
  _inherits(CollaboratorsOperation, _React$PureComponent);
12
11
  var _super = _createSuper(CollaboratorsOperation);
@@ -14,21 +13,13 @@ var CollaboratorsOperation = /*#__PURE__*/function (_React$PureComponent) {
14
13
  var _this;
15
14
  _classCallCheck(this, CollaboratorsOperation);
16
15
  _this = _super.call(this, props);
17
- _this.getUserInfo = function (username) {
18
- return {
19
- name: username,
20
- username: username,
21
- avatar_url: URL
22
- };
23
- };
24
- _this.onUserJoinRoom = function (username) {
16
+ _this.onUserJoinRoom = function (userInfo) {
25
17
  var collaborators = _this.state.collaborators;
26
18
  var newCollaborators = collaborators.slice();
27
19
  if (!newCollaborators.find(function (user) {
28
- return user.username === username;
20
+ return user.username === userInfo.username;
29
21
  })) {
30
- var newUser = _this.getUserInfo(username);
31
- newCollaborators.push(newUser);
22
+ newCollaborators.push(userInfo);
32
23
  _this.setState({
33
24
  collaborators: newCollaborators
34
25
  });
@@ -49,11 +40,11 @@ var CollaboratorsOperation = /*#__PURE__*/function (_React$PureComponent) {
49
40
  });
50
41
  }
51
42
  };
52
- var _username = context.getSetting('username');
53
- _this.currentUser = _this.getUserInfo(_username);
43
+ var _userInfo = context.getUserInfo();
54
44
  _this.state = {
55
- collaborators: [_this.currentUser]
45
+ collaborators: [_userInfo]
56
46
  };
47
+ _this.currentUser = _userInfo;
57
48
  return _this;
58
49
  }
59
50
  _createClass(CollaboratorsOperation, [{
@@ -62,20 +53,17 @@ var CollaboratorsOperation = /*#__PURE__*/function (_React$PureComponent) {
62
53
  var _this2 = this;
63
54
  context.getCollaborators().then(function (res) {
64
55
  var collaborators = res.data.collaborators;
65
- var newCollaborators = collaborators.map(function (item) {
66
- return _this2.getUserInfo(item);
67
- });
56
+
68
57
  // delete current user and push it at first one
69
- var currentUserIndex = newCollaborators.findIndex(function (user) {
58
+ var currentUserIndex = collaborators.findIndex(function (user) {
70
59
  return user.username === _this2.currentUser.username;
71
60
  });
72
- console.log(currentUserIndex);
73
61
  if (currentUserIndex > -1) {
74
- newCollaborators.splice(currentUserIndex, 1);
62
+ collaborators.splice(currentUserIndex, 1);
75
63
  }
76
- newCollaborators.unshift(_this2.currentUser);
64
+ collaborators.unshift(_this2.currentUser);
77
65
  _this2.setState({
78
- collaborators: newCollaborators
66
+ collaborators: collaborators
79
67
  });
80
68
  });
81
69
  var eventBus = EventBus.getInstance();
package/dist/context.js CHANGED
@@ -76,14 +76,10 @@ var Context = /*#__PURE__*/function () {
76
76
  value: function getEditorConfig() {
77
77
  if (this.config) return this.config;
78
78
  var _this$getSettings2 = this.getSettings(),
79
- docName = _this$getSettings2.docName,
80
- docPath = _this$getSettings2.docPath,
81
79
  docUuid = _this$getSettings2.docUuid,
82
80
  accessToken = _this$getSettings2.accessToken,
83
81
  sdocServer = _this$getSettings2.sdocServer;
84
82
  this.config = {
85
- docName: docName,
86
- docPath: docPath,
87
83
  docUuid: docUuid,
88
84
  accessToken: accessToken,
89
85
  sdocServer: new Url(sdocServer).origin
@@ -117,18 +113,12 @@ var Context = /*#__PURE__*/function () {
117
113
  }, {
118
114
  key: "getFileContent1",
119
115
  value: function getFileContent1() {
120
- var settings = this.getSettings();
121
- var docPath = settings.docPath,
122
- docName = settings.docName;
123
- return this.sdocServerApi.getDocContent(docPath, docName);
116
+ return this.sdocServerApi.getDocContent();
124
117
  }
125
118
  }, {
126
119
  key: "saveContent1",
127
120
  value: function saveContent1(content) {
128
- var settings = this.getSettings();
129
- var docPath = settings.docPath,
130
- docName = settings.docName;
131
- return this.sdocServerApi.saveDocContent(docPath, docName, content);
121
+ return this.sdocServerApi.saveDocContent(content);
132
122
  }
133
123
  }, {
134
124
  key: "getFileContent2",
@@ -160,6 +150,18 @@ var Context = /*#__PURE__*/function () {
160
150
  value: function getCollaborators() {
161
151
  return this.sdocServerApi.getCollaborators();
162
152
  }
153
+ }, {
154
+ key: "getUserInfo",
155
+ value: function getUserInfo() {
156
+ var name = this.getSetting('name');
157
+ var username = this.getSetting('username');
158
+ var avatarURL = this.getSetting('avatarURL');
159
+ return {
160
+ name: name,
161
+ username: username,
162
+ avatar_url: avatarURL
163
+ };
164
+ }
163
165
  }]);
164
166
  return Context;
165
167
  }();
@@ -115,15 +115,15 @@ var SimpleEditor = /*#__PURE__*/function (_React$Component) {
115
115
  className: "d-flex justify-content-center"
116
116
  }, errorMessage);
117
117
  }
118
- var config = context.getEditorConfig();
118
+ var docName = context.getSetting('docName');
119
119
  var isOpenSocket = context.getSetting('isOpenSocket');
120
120
  return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", {
121
121
  className: "doc-info"
122
122
  }, /*#__PURE__*/React.createElement("div", {
123
123
  className: "doc-name"
124
- }, config.docName), /*#__PURE__*/React.createElement(TipMessage, null)), /*#__PURE__*/React.createElement(DocOperations, null)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
124
+ }, docName), /*#__PURE__*/React.createElement(TipMessage, null)), /*#__PURE__*/React.createElement(DocOperations, null)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
125
125
  ref: this.setEditorRef,
126
- config: config,
126
+ config: context.getEditorConfig(),
127
127
  document: document,
128
128
  isOpenSocket: isOpenSocket,
129
129
  onValueChanged: this.onValueChanged
@@ -94,8 +94,8 @@ var SimpleViewer = /*#__PURE__*/function (_React$Component) {
94
94
  className: "d-flex justify-content-center"
95
95
  }, errorMessage);
96
96
  }
97
- var config = context.getViewConfig();
98
- return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", null, config.docName)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocViewer, {
97
+ var docName = context.getSetting('docName');
98
+ return /*#__PURE__*/React.createElement(Layout, null, /*#__PURE__*/React.createElement(Header, null, /*#__PURE__*/React.createElement("div", null, docName)), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocViewer, {
99
99
  document: document,
100
100
  onValueChanged: this.onValueChanged
101
101
  })));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",