@seafile/sdoc-editor 0.1.9 → 0.1.11

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.
Files changed (40) hide show
  1. package/dist/api/sdoc-server-api.js +16 -5
  2. package/dist/assets/css/collaborator-popover.css +75 -0
  3. package/dist/assets/css/simple-editor.css +5 -0
  4. package/dist/basic-sdk/assets/css/layout.css +2 -2
  5. package/dist/basic-sdk/assets/css/sdoc-editor-toolbar.css +1 -0
  6. package/dist/basic-sdk/editor.js +6 -10
  7. package/dist/basic-sdk/extension/core/transforms/index.js +2 -1
  8. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +15 -0
  9. package/dist/basic-sdk/extension/menu/menu.css +1 -1
  10. package/dist/basic-sdk/extension/plugins/link/helpers.js +44 -19
  11. package/dist/basic-sdk/index.js +2 -1
  12. package/dist/basic-sdk/socket/socket-client.js +3 -14
  13. package/dist/basic-sdk/socket/socket-manager.js +1 -4
  14. package/dist/basic-sdk/utils/event-bus.js +8 -0
  15. package/dist/basic-sdk/utils/event-handler.js +22 -0
  16. package/dist/components/doc-operations/collaborators-operation/collaborators-popover.js +54 -0
  17. package/dist/components/doc-operations/collaborators-operation/index.js +106 -0
  18. package/dist/components/doc-operations/index.js +37 -0
  19. package/dist/components/doc-operations/style.css +25 -0
  20. package/dist/components/tip-message/index.js +48 -11
  21. package/dist/context.js +7 -12
  22. package/dist/layout/layout.css +1 -1
  23. package/dist/pages/simple-editor.js +5 -44
  24. package/dist/pages/simple-viewer.js +2 -2
  25. package/package.json +1 -1
  26. package/public/index.html +1 -1
  27. package/public/locales/en/sdoc-editor.json +4 -1
  28. package/public/locales/zh-CN/sdoc-editor.json +3 -1
  29. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  30. package/public/media/sdoc-editor-font/iconfont.svg +129 -0
  31. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  32. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  33. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  34. package/public/media/{seafile-editor-font.css → sdoc-editor-font.css} +124 -107
  35. package/public/locales/zh-CN/seafile-editor.json +0 -225
  36. package/public/media/seafile-editor-font/iconfont.eot +0 -0
  37. package/public/media/seafile-editor-font/iconfont.svg +0 -121
  38. package/public/media/seafile-editor-font/iconfont.ttf +0 -0
  39. package/public/media/seafile-editor-font/iconfont.woff +0 -0
  40. package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
@@ -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: {
@@ -47,6 +45,19 @@ var SDocServerApi = /*#__PURE__*/function () {
47
45
  }
48
46
  });
49
47
  }
48
+ }, {
49
+ key: "getCollaborators",
50
+ value: function getCollaborators() {
51
+ var server = this.server,
52
+ docUuid = this.docUuid,
53
+ accessToken = this.accessToken;
54
+ var url = "".concat(server, "/api/v1/docs/").concat(docUuid, "/collaborators/");
55
+ return axios.get(url, {
56
+ headers: {
57
+ Authorization: "Token ".concat(accessToken)
58
+ }
59
+ });
60
+ }
50
61
  }]);
51
62
  return SDocServerApi;
52
63
  }();
@@ -0,0 +1,75 @@
1
+ .collaborators-popover.popover {
2
+ width: 300px;
3
+ max-width: 300px;
4
+ }
5
+
6
+ .collaborators-popover .popover-container {
7
+ padding: 0;
8
+ margin: 0;
9
+ max-height: 360px;
10
+ display: flex;
11
+ flex-direction: column;
12
+ justify-content: center;
13
+ }
14
+
15
+ .collaborators-popover .popover-header {
16
+ height: 50px;
17
+ min-height: 50px;
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ font-weight: 600;
22
+ font-size: 16px;
23
+ border-bottom: 1px solid #ededed;
24
+ color: #212529;
25
+ }
26
+
27
+ .collaborators-popover .popover-container .content-list {
28
+ flex: 1;
29
+ display: flex;
30
+ flex-direction: column;
31
+ min-height: 0;
32
+ overflow: auto;
33
+ padding: 5px 0;
34
+ }
35
+
36
+ .content-list .collaborator-details {
37
+ height: 32px;
38
+ line-height: 32px;
39
+ width: 100%;
40
+ display: flex;
41
+ align-items: center;
42
+ padding: 3px 12px;
43
+
44
+ }
45
+
46
+ .content-list .collaborator-details:hover {
47
+ background-color: #f8f8f8;
48
+ }
49
+
50
+ .content-list .collaborator-details .collaborator-tag {
51
+ margin-right: 8px;
52
+ height: 5px;
53
+ width: 5px;
54
+ background-color: #08DB6B;
55
+ border-radius: 50%;
56
+ overflow: hidden;
57
+ }
58
+
59
+ .content-list .collaborator-details .collaborator-avatar {
60
+ margin-right: 8px;
61
+ height: 20px;
62
+ width: 20px;
63
+ border-radius: 50%;
64
+ overflow: hidden;
65
+ }
66
+
67
+ .content-list .collaborator-details .collaborator-name {
68
+ max-width: calc(100% - 20px);
69
+ overflow: hidden;
70
+ white-space: nowrap;
71
+ text-overflow: ellipsis;
72
+ color: #212529;
73
+ }
74
+
75
+
@@ -2,3 +2,8 @@
2
2
  display: flex;
3
3
  align-items: center;
4
4
  }
5
+
6
+ .sdoc-editor-page-header .doc-info .doc-name {
7
+ font-size: 18px;
8
+ color: #212529;
9
+ }
@@ -14,10 +14,10 @@
14
14
  .sdoc-editor-container .sdoc-editor-toolbar {
15
15
  display: flex;
16
16
  justify-content: center;
17
- height: 39px;
17
+ height: 44px;
18
18
  align-items: center;
19
19
  padding: 0 10px;
20
- background-color: #fcfcfc;
20
+ background-color: #fff;
21
21
  user-select: none;
22
22
  border-bottom: 1px solid #e5e5e5;
23
23
  box-shadow: 0 3px 2px -2px rgb(200 200 200 / 15%)
@@ -14,6 +14,7 @@
14
14
  display: flex;
15
15
  justify-content: space-between;
16
16
  align-items: center;
17
+ margin: 0 5px;
17
18
  }
18
19
 
19
20
  .header-menu .header-toggle .iconfont {
@@ -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
+ };
@@ -13,7 +13,7 @@
13
13
  border: 1px solid transparent;
14
14
  line-height: 30px;
15
15
  color: #555555;
16
- background-color: #fcfcfc;
16
+ background-color: #fff;
17
17
  }
18
18
 
19
19
  .menu-group .menu-group-item:disabled {
@@ -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
  }();
@@ -1,3 +1,4 @@
1
1
  import SDocEditor from './editor';
2
2
  import SDocViewer from './viewer';
3
- export { SDocEditor, SDocViewer };
3
+ import EventBus from './utils/event-bus';
4
+ export { SDocEditor, SDocViewer, EventBus };
@@ -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
@@ -126,8 +115,8 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
126
115
  this.isReconnect = false;
127
116
  this.socket = io(config.sdocServer, {
128
117
  reconnection: true,
129
- query: {
130
- doc_uuid: config.docUuid
118
+ auth: {
119
+ token: config.accessToken
131
120
  }
132
121
  });
133
122
  this.socket.on('connect', this.onConnected);
@@ -156,9 +156,6 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
156
156
  _this.editor.isRemote = false;
157
157
  });
158
158
  };
159
- this.subscribe = function (type, handler) {
160
- return _this.eventBus.subscribe(type, handler);
161
- };
162
159
  this.dispatchConnectState = function (type, message) {
163
160
  _this.eventBus.dispatch(type, message);
164
161
  };
@@ -172,7 +169,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
172
169
  this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
173
170
  this.remoteOperationsList = []; // Same with pending operations
174
171
  this.revertOperationList = [];
175
- this.eventBus = new EventBus();
172
+ this.eventBus = EventBus.getInstance();
176
173
  });
177
174
  SocketManager.getInstance = function (editor, document, socketConfig) {
178
175
  if (SocketManager.instance) {
@@ -3,6 +3,7 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  var EventBus = /*#__PURE__*/function () {
4
4
  function EventBus() {
5
5
  _classCallCheck(this, EventBus);
6
+ this.instance = null;
6
7
  this.subscribers = {};
7
8
  }
8
9
  _createClass(EventBus, [{
@@ -33,6 +34,13 @@ var EventBus = /*#__PURE__*/function () {
33
34
  });
34
35
  }
35
36
  }
37
+ }], [{
38
+ key: "getInstance",
39
+ value: function getInstance() {
40
+ if (this.instance) return this.instance;
41
+ this.instance = new EventBus();
42
+ return this.instance;
43
+ }
36
44
  }]);
37
45
  return EventBus;
38
46
  }();
@@ -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;
@@ -0,0 +1,54 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+ import { withTranslation } from 'react-i18next';
7
+ import { UncontrolledPopover, PopoverBody, PopoverHeader } from 'reactstrap';
8
+ import '../../../assets/css/collaborator-popover.css';
9
+ var CollaboratorsPopover = /*#__PURE__*/function (_React$PureComponent) {
10
+ _inherits(CollaboratorsPopover, _React$PureComponent);
11
+ var _super = _createSuper(CollaboratorsPopover);
12
+ function CollaboratorsPopover() {
13
+ _classCallCheck(this, CollaboratorsPopover);
14
+ return _super.apply(this, arguments);
15
+ }
16
+ _createClass(CollaboratorsPopover, [{
17
+ key: "render",
18
+ value: function render() {
19
+ var _this$props = this.props,
20
+ t = _this$props.t,
21
+ collaborators = _this$props.collaborators;
22
+ return /*#__PURE__*/React.createElement(UncontrolledPopover, {
23
+ target: "collaborators",
24
+ placement: "bottom-end",
25
+ popperClassName: "collaborators-popover",
26
+ trigger: "legacy",
27
+ hideArrow: true,
28
+ security: "fixed"
29
+ }, /*#__PURE__*/React.createElement(PopoverHeader, {
30
+ className: "popover-header"
31
+ }, t('Online_members'), ' ', "(", collaborators.length, ")"), /*#__PURE__*/React.createElement(PopoverBody, {
32
+ className: "popover-container"
33
+ }, /*#__PURE__*/React.createElement("div", {
34
+ className: "content-list"
35
+ }, collaborators.map(function (item, index) {
36
+ var name = index === 0 ? "".concat(item.name, " (").concat(t('me'), ")") : item.name;
37
+ return /*#__PURE__*/React.createElement("div", {
38
+ key: index,
39
+ className: "collaborator-details"
40
+ }, /*#__PURE__*/React.createElement("span", {
41
+ className: "collaborator-tag"
42
+ }), /*#__PURE__*/React.createElement("img", {
43
+ className: "collaborator-avatar",
44
+ alt: name,
45
+ src: item.avatar_url
46
+ }), /*#__PURE__*/React.createElement("span", {
47
+ className: "collaborator-name"
48
+ }, name));
49
+ }))));
50
+ }
51
+ }]);
52
+ return CollaboratorsPopover;
53
+ }(React.PureComponent);
54
+ export default withTranslation('sdoc-editor')(CollaboratorsPopover);
@@ -0,0 +1,106 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React, { Fragment } from 'react';
6
+ import { EventBus } from '../../../basic-sdk';
7
+ import context from '../../../context';
8
+ import CollaboratorsPopover from './collaborators-popover';
9
+ var URL = 'https://tupian.qqw21.com/article/UploadPic/2020-8/20208522181570993.jpg';
10
+ var CollaboratorsOperation = /*#__PURE__*/function (_React$PureComponent) {
11
+ _inherits(CollaboratorsOperation, _React$PureComponent);
12
+ var _super = _createSuper(CollaboratorsOperation);
13
+ function CollaboratorsOperation(props) {
14
+ var _this;
15
+ _classCallCheck(this, CollaboratorsOperation);
16
+ _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) {
25
+ var collaborators = _this.state.collaborators;
26
+ var newCollaborators = collaborators.slice();
27
+ if (!newCollaborators.find(function (user) {
28
+ return user.username === username;
29
+ })) {
30
+ var newUser = _this.getUserInfo(username);
31
+ newCollaborators.push(newUser);
32
+ _this.setState({
33
+ collaborators: newCollaborators
34
+ });
35
+ }
36
+ };
37
+ _this.onUserLeaveRoom = function (username) {
38
+ if (_this.currentUser.username === username) return;
39
+ var collaborators = _this.state.collaborators;
40
+ var newCollaborators = collaborators.slice();
41
+ if (newCollaborators.find(function (user) {
42
+ return user.username === username;
43
+ })) {
44
+ newCollaborators = newCollaborators.filter(function (user) {
45
+ return user.username !== username;
46
+ });
47
+ _this.setState({
48
+ collaborators: newCollaborators
49
+ });
50
+ }
51
+ };
52
+ var _username = context.getSetting('username');
53
+ _this.currentUser = _this.getUserInfo(_username);
54
+ _this.state = {
55
+ collaborators: [_this.currentUser]
56
+ };
57
+ return _this;
58
+ }
59
+ _createClass(CollaboratorsOperation, [{
60
+ key: "componentDidMount",
61
+ value: function componentDidMount() {
62
+ var _this2 = this;
63
+ context.getCollaborators().then(function (res) {
64
+ var collaborators = res.data.collaborators;
65
+ var newCollaborators = collaborators.map(function (item) {
66
+ return _this2.getUserInfo(item);
67
+ });
68
+ // delete current user and push it at first one
69
+ var currentUserIndex = newCollaborators.findIndex(function (user) {
70
+ return user.username === _this2.currentUser.username;
71
+ });
72
+ if (currentUserIndex > -1) {
73
+ newCollaborators.splice(currentUserIndex, 1);
74
+ }
75
+ newCollaborators.unshift(_this2.currentUser);
76
+ _this2.setState({
77
+ collaborators: newCollaborators
78
+ });
79
+ });
80
+ var eventBus = EventBus.getInstance();
81
+ this.unsubscribeJoinEvent = eventBus.subscribe('join-room', this.onUserJoinRoom);
82
+ this.unsubscribeLeaveEvent = eventBus.subscribe('leave-room', this.onUserLeaveRoom);
83
+ }
84
+ }, {
85
+ key: "componentWillUnmount",
86
+ value: function componentWillUnmount() {
87
+ this.unsubscribeJoinEvent();
88
+ this.unsubscribeLeaveEvent();
89
+ }
90
+ }, {
91
+ key: "render",
92
+ value: function render() {
93
+ var collaborators = this.state.collaborators;
94
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("span", {
95
+ className: "op-item",
96
+ id: "collaborators"
97
+ }, /*#__PURE__*/React.createElement("i", {
98
+ className: "iconfont icon-user mr-1"
99
+ }), collaborators.length), /*#__PURE__*/React.createElement(CollaboratorsPopover, {
100
+ collaborators: collaborators
101
+ }));
102
+ }
103
+ }]);
104
+ return CollaboratorsOperation;
105
+ }(React.PureComponent);
106
+ export default CollaboratorsOperation;
@@ -0,0 +1,37 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React, { Fragment } from 'react';
6
+ import CollaboratorsOperation from './collaborators-operation';
7
+ import './style.css';
8
+ var DocOperations = /*#__PURE__*/function (_React$Component) {
9
+ _inherits(DocOperations, _React$Component);
10
+ var _super = _createSuper(DocOperations);
11
+ function DocOperations() {
12
+ _classCallCheck(this, DocOperations);
13
+ return _super.apply(this, arguments);
14
+ }
15
+ _createClass(DocOperations, [{
16
+ key: "render",
17
+ value: function render() {
18
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
19
+ className: "doc-ops"
20
+ }, /*#__PURE__*/React.createElement("span", {
21
+ className: "op-item"
22
+ }, /*#__PURE__*/React.createElement("i", {
23
+ className: "iconfont icon-share"
24
+ })), /*#__PURE__*/React.createElement("span", {
25
+ className: "op-item"
26
+ }, /*#__PURE__*/React.createElement("i", {
27
+ className: "iconfont icon-history"
28
+ })), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), /*#__PURE__*/React.createElement("span", {
29
+ className: "op-item"
30
+ }, /*#__PURE__*/React.createElement("i", {
31
+ className: "iconfont icon-menu"
32
+ }))));
33
+ }
34
+ }]);
35
+ return DocOperations;
36
+ }(React.Component);
37
+ export default DocOperations;