@seafile/sdoc-editor 0.1.148 → 0.1.149-beta

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 (41) hide show
  1. package/dist/api/sdoc-server-api.js +10 -0
  2. package/dist/api/seafile-api.js +27 -5
  3. package/dist/basic-sdk/comment/comment/comment-item-content.js +5 -0
  4. package/dist/basic-sdk/comment/comment/comment-item-reply.js +3 -0
  5. package/dist/basic-sdk/comment/comment/global-comment-header.js +5 -2
  6. package/dist/basic-sdk/comment/comment/global-comment.js +1 -1
  7. package/dist/basic-sdk/comment/comment/style.css +6 -5
  8. package/dist/basic-sdk/constants/index.js +20 -1
  9. package/dist/basic-sdk/editor/common-editor.js +50 -0
  10. package/dist/basic-sdk/editor/index.css +29 -0
  11. package/dist/basic-sdk/editor/index.js +129 -0
  12. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  13. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  14. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  15. package/dist/basic-sdk/extension/render/render-element.js +213 -1
  16. package/dist/basic-sdk/socket/helpers.js +2 -0
  17. package/dist/basic-sdk/socket/socket-client.js +38 -0
  18. package/dist/basic-sdk/socket/socket-manager.js +25 -2
  19. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  20. package/dist/basic-sdk/utils/diff.js +2 -2
  21. package/dist/basic-sdk/utils/rebase.js +181 -0
  22. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  23. package/dist/basic-sdk/views/viewer.js +9 -12
  24. package/dist/components/doc-operations/index.js +4 -2
  25. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  26. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  27. package/dist/components/tip-dialog/index.js +48 -0
  28. package/dist/components/tip-dialog/tip-content.js +50 -0
  29. package/dist/constants/index.js +23 -2
  30. package/dist/context.js +35 -4
  31. package/dist/pages/simple-editor.js +255 -83
  32. package/package.json +1 -1
  33. package/public/locales/en/sdoc-editor.json +11 -1
  34. package/public/locales/zh_CN/sdoc-editor.json +10 -1
  35. package/public/media/sdoc-editor-font/iconfont.eot +0 -0
  36. package/public/media/sdoc-editor-font/iconfont.svg +4 -0
  37. package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
  38. package/public/media/sdoc-editor-font/iconfont.woff +0 -0
  39. package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
  40. package/public/media/sdoc-editor-font.css +14 -6
  41. package/dist/basic-sdk/editor.js +0 -105
@@ -1,9 +1,8 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ 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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(typeof e + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
4
  import React, { useCallback, useEffect, useRef, useState } from 'react';
4
5
  import { withTranslation } from 'react-i18next';
5
- import deepCopy from 'deep-copy';
6
- import { SDocEditor, DiffViewer } from '../basic-sdk';
7
6
  import Loading from '../components/loading';
8
7
  import DocInfo from '../components/doc-info';
9
8
  import DocOperations from '../components/doc-operations';
@@ -11,49 +10,125 @@ import Layout, { Header, Content } from '../layout';
11
10
  import { generateDefaultDocContent } from '../utils';
12
11
  import context from '../context';
13
12
  import ErrorBoundary from './error-boundary';
13
+ import TipDialog from '../components/tip-dialog';
14
+ import { EXTERNAL_EVENT, MODE, TIP_TYPE } from '../constants';
15
+ import { getRebase } from '../basic-sdk/utils/rebase';
16
+ import toaster from '../components/toast';
17
+ import { EventBus, SDocEditor } from '../basic-sdk';
14
18
  import '../assets/css/simple-editor.css';
15
19
  var SimpleEditor = function SimpleEditor(_ref) {
16
20
  var isStarred = _ref.isStarred,
17
21
  isDraft = _ref.isDraft,
18
22
  t = _ref.t;
23
+ context.initApi();
24
+ var repoID = context.getSetting('repoID');
25
+ var siteRoot = context.getSetting('siteRoot');
26
+ var originFilePath = context.getSetting('originFilePath');
27
+ var isRevision = context.getSetting('isSdocRevision');
28
+ var originFileURL = isRevision ? "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath) : '';
29
+ var originDocName = isRevision ? context.getSetting('originFilename') : '';
30
+ var originDocUuid = isRevision ? context.getSetting('originDocUuid') : '';
19
31
  var editorRef = useRef(null);
20
32
  var _useState = useState(true),
21
33
  _useState2 = _slicedToArray(_useState, 2),
22
- isFirstLoad = _useState2[0],
23
- setFirstLoad = _useState2[1];
24
- var _useState3 = useState(true),
34
+ isLoadingSdoc = _useState2[0],
35
+ setLoadingSdoc = _useState2[1];
36
+ var _useState3 = useState(''),
25
37
  _useState4 = _slicedToArray(_useState3, 2),
26
- isLoadingSdoc = _useState4[0],
27
- setLoadingSdoc = _useState4[1];
28
- var _useState5 = useState(''),
38
+ errorMessage = _useState4[0],
39
+ setErrorMessage = _useState4[1];
40
+ var _useState5 = useState(false),
29
41
  _useState6 = _slicedToArray(_useState5, 2),
30
- errorMessage = _useState6[0],
31
- setErrorMessage = _useState6[1];
32
- var _useState7 = useState(false),
42
+ isShowChanges = _useState6[0],
43
+ setShowChanges = _useState6[1];
44
+ var _useState7 = useState(null),
33
45
  _useState8 = _slicedToArray(_useState7, 2),
34
- isShowChanges = _useState8[0],
35
- setShowChanges = _useState8[1];
36
- var _useState9 = useState(null),
46
+ document = _useState8[0],
47
+ setDocument = _useState8[1];
48
+ var _useState9 = useState(MODE.EDITOR),
37
49
  _useState10 = _slicedToArray(_useState9, 2),
38
- document = _useState10[0],
39
- setDocument = _useState10[1];
40
- var _useState11 = useState(null),
50
+ mode = _useState10[0],
51
+ setMode = _useState10[1];
52
+ var _useState11 = useState([]),
41
53
  _useState12 = _slicedToArray(_useState11, 2),
42
- currentContent = _useState12[0],
43
- setCurrentContent = _useState12[1];
44
- var _useState13 = useState(null),
54
+ changes = _useState12[0],
55
+ setChanges = _useState12[1];
56
+ var _useState13 = useState(false),
45
57
  _useState14 = _slicedToArray(_useState13, 2),
46
- lastContent = _useState14[0],
47
- setLastContent = _useState14[1];
58
+ showTip = _useState14[0],
59
+ setShowTip = _useState14[1];
60
+ var _useState15 = useState(''),
61
+ _useState16 = _slicedToArray(_useState15, 2),
62
+ tipType = _useState16[0],
63
+ setTipType = _useState16[1];
64
+ var _useState17 = useState([]),
65
+ _useState18 = _slicedToArray(_useState17, 2),
66
+ mergeValue = _useState18[0],
67
+ setMergeValue = _useState18[1];
68
+ useEffect(function () {
69
+ loadDocument(function (document) {
70
+ setDocument(document);
71
+ setLoadingSdoc(false);
72
+ }, function (errorMessage) {
73
+ setErrorMessage(errorMessage);
74
+ setDocument(null);
75
+ setLoadingSdoc(false);
76
+ }, function () {
77
+ setLoadingSdoc(true);
78
+ });
79
+
80
+ // eslint-disable-next-line react-hooks/exhaustive-deps
81
+ }, []);
82
+
83
+ // useMount: reset title
84
+ useEffect(function () {
85
+ var isSdocRevision = context.getSetting('isSdocRevision');
86
+ var originFilename = context.getSetting('originFilename');
87
+ if (isSdocRevision) {
88
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
89
+ }
90
+
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ }, []);
93
+ var onDocumentReplaced = useCallback(function () {
94
+ setTipType(TIP_TYPE.HAS_BEEN_REPLACED);
95
+ setShowTip(true);
96
+
97
+ // eslint-disable-next-line react-hooks/exhaustive-deps
98
+ }, [editorRef]);
99
+ var hasPublishRevision = useCallback(function () {
100
+ setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
101
+ setShowTip(true);
102
+
103
+ // eslint-disable-next-line react-hooks/exhaustive-deps
104
+ }, [editorRef]);
105
+ var onDocumentReplacedError = useCallback(function () {
106
+ toaster.danger(t('Error'));
107
+
108
+ // eslint-disable-next-line react-hooks/exhaustive-deps
109
+ }, []);
110
+ var publishDocumentError = useCallback(function () {
111
+ toaster.danger(t('Error'));
112
+
113
+ // eslint-disable-next-line react-hooks/exhaustive-deps
114
+ }, []);
48
115
  useEffect(function () {
49
- context.initApi();
50
- initDocumentData(true);
116
+ var eventBus = EventBus.getInstance();
117
+ var unsubscribeMergeDocument = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED, onDocumentReplaced);
118
+ var unsubscribePublishDocument = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
119
+ var unsubscribeMergeDocumentError = eventBus.subscribe(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR, onDocumentReplacedError);
120
+ var unsubscribePublishDocumentError = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, publishDocumentError);
121
+ return function () {
122
+ unsubscribeMergeDocument();
123
+ unsubscribePublishDocument();
124
+ unsubscribeMergeDocumentError();
125
+ unsubscribePublishDocumentError();
126
+ };
51
127
 
52
128
  // eslint-disable-next-line react-hooks/exhaustive-deps
53
129
  }, []);
54
- var initDocumentData = useCallback(function (isFirstLoad) {
55
- setShowChanges(false);
56
- setLoadingSdoc(true);
130
+ var loadDocument = useCallback(function (successCallback, errorCallback, callback) {
131
+ callback && callback();
57
132
  context.getFileContent().then(function (res) {
58
133
  var result = res.data || generateDefaultDocContent();
59
134
  if (result && !result.children) {
@@ -63,74 +138,178 @@ var SimpleEditor = function SimpleEditor(_ref) {
63
138
  cursors: result.cursors || {}
64
139
  };
65
140
  }
66
- setDocument(result);
67
- setLoadingSdoc(false);
68
- isFirstLoad && setFirstLoad(false);
141
+ successCallback && successCallback(result);
69
142
  }).catch(function (error) {
70
143
  // eslint-disable-next-line
71
144
  console.log(error);
72
- setErrorMessage('Load_doc_content_error');
145
+ var errorMessage = 'Load_doc_content_error';
73
146
  if (error && error.response) {
74
147
  var _ref2 = error.response.data || {},
75
148
  error_type = _ref2.error_type;
76
149
  if (error_type === 'content_invalid') {
77
- setErrorMessage('Sdoc_format_invalid');
150
+ errorMessage = 'Sdoc_format_invalid';
78
151
  }
79
152
  }
80
- setDocument(null);
81
- setLoadingSdoc(false);
153
+ errorCallback && errorCallback(errorMessage);
82
154
  });
83
-
84
- // eslint-disable-next-line react-hooks/exhaustive-deps
85
155
  }, []);
86
- var initChangesData = useCallback(function () {
87
- setShowChanges(true);
88
- setLoadingSdoc(true);
89
- context.getSeadocRevisionDownloadLinks().then(function (res) {
156
+ var setDiffContent = useCallback(function () {
157
+ context.getSeadocOriginFileDownloadLink().then(function (res) {
90
158
  var originFileDownloadLink = res.data.origin_file_download_link;
91
159
  return fetch(originFileDownloadLink);
92
160
  }).then(function (res) {
93
161
  return res.json();
94
162
  }).then(function (originContent) {
95
- setLastContent(originContent);
96
- setErrorMessage(null);
97
- setLoadingSdoc(false);
163
+ editorRef.current.setDiffContent(originContent);
164
+ editorRef.current.setLoading(false);
98
165
  }).catch(function (error) {
99
- setErrorMessage('Load_doc_content_error');
100
- setLoadingSdoc(false);
166
+ console.log('error');
101
167
  });
102
-
103
- // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, [document]);
168
+ }, []);
105
169
  var toggleViewChanges = useCallback(function (isShowChanges) {
106
- if (isShowChanges) {
107
- var newestValue = editorRef.current.getValue();
108
- setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
109
- children: newestValue
110
- })));
170
+ var revisionCurrentContent = editorRef.current.getSlateValue();
171
+ if (isShowChanges && revisionCurrentContent.children.filter(function (item) {
172
+ return item.rebase_type;
173
+ }).length !== 0) {
174
+ setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
175
+ setShowTip(true);
176
+ return;
111
177
  }
112
- if (isShowChanges) {
113
- initChangesData();
178
+ editorRef.current.setLoading(true);
179
+ setShowChanges(isShowChanges);
180
+ var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
181
+ setMode(mode);
182
+ editorRef.current.setEditorMode(mode);
183
+ if (!isShowChanges) {
184
+ loadDocument(function (document) {
185
+ setDocument(document);
186
+ editorRef.current.setSlateValue(document);
187
+ editorRef.current.setLoading(false);
188
+ }, function (errorMessage) {
189
+ setErrorMessage(errorMessage);
190
+ editorRef.current.setLoading(false);
191
+ });
114
192
  return;
115
193
  }
116
- setChanges([]);
117
- initDocumentData(false);
194
+ setDiffContent();
118
195
 
119
196
  // eslint-disable-next-line react-hooks/exhaustive-deps
120
- }, [document]);
121
- var _useState15 = useState([]),
122
- _useState16 = _slicedToArray(_useState15, 2),
123
- changes = _useState16[0],
124
- setChanges = _useState16[1];
197
+ }, [document, editorRef.current]);
198
+ var publishRevision = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
199
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
200
+ while (1) switch (_context.prev = _context.next) {
201
+ case 0:
202
+ loadDocument(function (document) {
203
+ var revisionCurrentContent = document;
204
+ if (revisionCurrentContent.children.filter(function (item) {
205
+ return item.rebase_type;
206
+ }).length !== 0) {
207
+ setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
208
+ setShowTip(true);
209
+ return;
210
+ }
211
+ var originFileVersion = context.getSetting('originFileVersion'); // changing
212
+ var revisionMasterContent;
213
+ var masterContent;
214
+ context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
215
+ var fileHistoryRevisionContent = res.data.content; // commit content
216
+ revisionMasterContent = JSON.parse(fileHistoryRevisionContent);
217
+ return context.getSeadocOriginFileDownloadLink();
218
+ }).then(function (res) {
219
+ var originFileDownloadLink = res.data.origin_file_download_link;
220
+ return fetch(originFileDownloadLink);
221
+ }).then(function (res) {
222
+ return res.json();
223
+ }).then(function (content) {
224
+ masterContent = content;
225
+ var _getRebase = getRebase(masterContent, revisionMasterContent, revisionCurrentContent),
226
+ canMerge = _getRebase.canMerge,
227
+ isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
228
+ value = _getRebase.value;
229
+ if (canMerge && isNeedReplaceMaster) {
230
+ context.publishSdocRevision().then(function (res) {
231
+ editorRef.current.publishDocument(originDocUuid, originDocName, true);
232
+ setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
233
+ setShowTip(true);
234
+ }).catch(function (error) {
235
+ toaster.danger(t('Error'));
236
+ });
237
+ return;
238
+ }
239
+ if (canMerge && !isNeedReplaceMaster) {
240
+ setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
241
+ setShowTip(true);
242
+ return;
243
+ }
244
+ setMergeValue(value);
245
+ setTipType(TIP_TYPE.MERGE);
246
+ setShowTip(true);
247
+ }).catch(function (error) {
248
+ toaster.danger(t('Error'));
249
+ });
250
+ }, function (errorMessage) {
251
+ toaster.danger(t(errorMessage));
252
+ });
253
+
254
+ // eslint-disable-next-line react-hooks/exhaustive-deps
255
+ case 1:
256
+ case "end":
257
+ return _context.stop();
258
+ }
259
+ }, _callee);
260
+ })), [isShowChanges, mode, originDocUuid, originDocName, originFilePath]);
125
261
  var setDiffChanges = useCallback(function (diff) {
126
262
  setChanges(diff.changes);
127
263
 
128
264
  // eslint-disable-next-line react-hooks/exhaustive-deps
129
265
  }, [isShowChanges]);
130
- if (isFirstLoad && !errorMessage) {
266
+ var jumpToURL = useCallback(function (url) {
267
+ window.location.href = url;
268
+ }, []);
269
+ var closeTip = useCallback(function () {
270
+ setShowTip(false);
271
+
272
+ // eslint-disable-next-line react-hooks/exhaustive-deps
273
+ }, [tipType]);
274
+ var tipSubmit = useCallback(function () {
275
+ if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
276
+ context.deleteSdocRevision().then(function (res) {
277
+ if (res.data.success) {
278
+ editorRef.current.publishDocument(originDocUuid, originDocName, false);
279
+ setShowTip(false);
280
+ jumpToURL(originFileURL);
281
+ }
282
+ }).catch(function (error) {
283
+ toaster.danger(t('Error'));
284
+ });
285
+ return;
286
+ }
287
+ if (tipType === TIP_TYPE.MERGE) {
288
+ context.updateSdocRevision().then(function (res) {
289
+ var origin_file_version = res.data.origin_file_version;
290
+ context.updateSettings({
291
+ 'originFileVersion': origin_file_version
292
+ });
293
+ editorRef.current.replaceDocument(mergeValue);
294
+ editorRef.current.setLoading(true);
295
+ editorRef.current.setSlateValue(mergeValue);
296
+ setMode(MODE.EDITOR);
297
+ editorRef.current.setEditorMode(MODE.EDITOR);
298
+ editorRef.current.setLoading(false);
299
+ setShowTip(false);
300
+ }).catch(function (error) {
301
+ toaster.danger(t('Error'));
302
+ });
303
+ return;
304
+ }
305
+ setShowTip(false);
306
+
307
+ // eslint-disable-next-line react-hooks/exhaustive-deps
308
+ }, [tipType, originFileURL, mergeValue, editorRef.current, originDocUuid, originDocName]);
309
+ if (isLoadingSdoc) {
131
310
  return /*#__PURE__*/React.createElement(Loading, null);
132
311
  }
133
- if (isFirstLoad && errorMessage) {
312
+ if (errorMessage) {
134
313
  return /*#__PURE__*/React.createElement("div", {
135
314
  className: "error-page"
136
315
  }, /*#__PURE__*/React.createElement("div", {
@@ -144,24 +323,17 @@ var SimpleEditor = function SimpleEditor(_ref) {
144
323
  }), /*#__PURE__*/React.createElement(DocOperations, {
145
324
  isShowChanges: isShowChanges,
146
325
  changes: changes,
147
- toggleViewChanges: toggleViewChanges
148
- })), /*#__PURE__*/React.createElement(Content, null, isLoadingSdoc && /*#__PURE__*/React.createElement("div", {
149
- className: "w-100 h-100 d-flex align-items-center justify-content-center"
150
- }, /*#__PURE__*/React.createElement(Loading, null)), !isLoadingSdoc && errorMessage && /*#__PURE__*/React.createElement("div", {
151
- className: "error-page"
152
- }, /*#__PURE__*/React.createElement("div", {
153
- className: "error-tip"
154
- }, t(errorMessage))), !isLoadingSdoc && !errorMessage && /*#__PURE__*/React.createElement(React.Fragment, null, isShowChanges ? /*#__PURE__*/React.createElement(DiffViewer, {
155
- showToolbar: true,
156
- showOutline: true,
157
- currentContent: currentContent,
158
- lastContent: lastContent,
159
- didMountCallback: setDiffChanges
160
- }) : /*#__PURE__*/React.createElement(SDocEditor, {
161
- config: context.getEditorConfig(),
162
- document: document,
326
+ toggleViewChanges: toggleViewChanges,
327
+ publishRevision: publishRevision
328
+ })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
163
329
  ref: editorRef,
164
- isOpenSocket: context.getSetting('isOpenSocket')
165
- })))));
330
+ document: document,
331
+ mode: mode,
332
+ setDiffChanges: setDiffChanges
333
+ }))), showTip && /*#__PURE__*/React.createElement(TipDialog, {
334
+ toggle: closeTip,
335
+ submit: tipSubmit,
336
+ tipType: tipType
337
+ }));
166
338
  };
167
339
  export default withTranslation('sdoc-editor')(SimpleEditor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.1.148",
3
+ "version": "0.1.149beta",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -362,5 +362,15 @@
362
362
  "No_changes": "No changes",
363
363
  "Title": "Title",
364
364
  "Subtitle": "Subtitle",
365
- "Link_sdoc": "Link sdoc"
365
+ "Link_sdoc": "Link sdoc",
366
+ "Keep_my_modification": "Keep my modification",
367
+ "Keep_other_modification": "Keep other's modification",
368
+ "Keep_both_modification": "Keep my modification",
369
+ "Tip": "Tip",
370
+ "Rebase_delete_no_change_revision_tip": "Revision has not made any change compared to original document. Do you want to delete this revision?",
371
+ "Has_been_replaced_tip": "Document content has been replaced. Please refresh the page.",
372
+ "Has_been_published_tip": "Revision has been published, Automatically jump to source content after {{ time }} seconds.",
373
+ "Has_conflict_before_publish_tip": "There are conflicts in the document, please resolve it before publishing!",
374
+ "Merge_tip": "There are conflicts in the documents. Do you want to merge them?",
375
+ "Has_conflict_before_view_changes_tip": "There are conflicts in the document. Please resolve the conflict before viewing the changes!"
366
376
  }
@@ -362,5 +362,14 @@
362
362
  "No_changes": "没有变化",
363
363
  "Title": "标题",
364
364
  "Subtitle": "副标题",
365
- "Link_sdoc": "链接 sdoc"
365
+ "Link_sdoc": "链接 sdoc",
366
+ "Keep_my_modification": "保留我的更改",
367
+ "Keep_other_modification": "保留其他的更改",
368
+ "Keep_both_modification": "保留两个更改",
369
+ "Rebase_delete_no_change_revision_tip": "修订改没有更改,是否删除修订稿?",
370
+ "Has_been_replaced_tip": "文档内容已经被替换,请刷新页面。",
371
+ "Has_been_published_tip": "修订稿已经发布了,{{ time }} 秒后自动跳转到源文件。",
372
+ "Has_conflict_before_publish_tip": "文档有冲突,请解决冲突后再发布!",
373
+ "Merge_tip": "文档有冲突,是否合并?",
374
+ "Has_conflict_before_view_changes_tip": "文档有冲突,请解决冲突后再查看更改!"
366
375
  }
@@ -14,6 +14,10 @@
14
14
  />
15
15
  <missing-glyph />
16
16
 
17
+ <glyph glyph-name="sdoc-sm-close" unicode="&#58965;" d="M512 439.466667L230.4 721.066667l-25.6 25.6-55.466667-55.466667 25.6-25.6 281.6-281.6-281.6-281.6-25.6-25.6 55.466667-55.466667 25.6 25.6 281.6 281.6 281.6-281.6 25.6-25.6 55.466667 55.466667-25.6 25.6-281.6 281.6 281.6 281.6 25.6 25.6-55.466667 55.466667-25.6-25.6z" horiz-adv-x="1024" />
18
+
19
+ <glyph glyph-name="sdoc-merge-cell" unicode="&#58963;" d="M480 896v-288h-96V800H96v-832h288v192h96v-288H0V896h480zM313.6 528L480 384l-166.4-144v96H160v92.8h153.6v99.2zM1024 896v-1024H544v288h96v-192h288V800h-288v-192h-96V896h480z m-313.6-368v-99.2H864v-92.8h-153.6v-96L544 384l166.4 144z" horiz-adv-x="1024" />
20
+
17
21
  <glyph glyph-name="sdoc-download" unicode="&#58962;" d="M582.4 326.4V793.6c0 41.6-32 70.4-70.4 70.4s-70.4-28.8-70.4-70.4v-467.2l-172.8 172.8c-25.6 25.6-70.4 25.6-96-3.2-25.6-25.6-25.6-70.4 0-96l291.2-291.2c25.6-25.6 70.4-25.6 96 0l291.2 291.2c25.6 25.6 25.6 70.4 3.2 96-25.6 25.6-70.4 25.6-96 3.2l-3.2-3.2-172.8-169.6z m-480-284.8h822.4c38.4 0 70.4-28.8 70.4-70.4s-32-67.2-73.6-67.2H102.4C60.8-96 32-67.2 32-25.6c0 35.2 28.8 67.2 70.4 67.2z" horiz-adv-x="1024" />
18
22
 
19
23
  <glyph glyph-name="sdoc-next-page" unicode="&#58918;" d="M342.4 768c12.8 0 28.8-6.4 38.4-16l329.6-329.6c22.4-22.4 22.4-57.6 0-76.8L380.8 16c-22.4-22.4-57.6-22.4-76.8 0-22.4 22.4-22.4 57.6 0 76.8L595.2 384 304 675.2c-22.4 22.4-22.4 57.6 0 76.8 9.6 9.6 25.6 16 38.4 16z" horiz-adv-x="1024" />
@@ -1,11 +1,11 @@
1
1
  @font-face {
2
2
  font-family: "sdocfont"; /* Project id 4097705 */
3
- src: url('./sdoc-editor-font/iconfont.eot?t=1693362307040'); /* IE9 */
4
- src: url('./sdoc-editor-font/iconfont.eot?t=1693362307040#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
- url('./sdoc-editor-font/iconfont.woff2?t=1693362307040') format('woff2'),
6
- url('./sdoc-editor-font/iconfont.woff?t=1693362307040') format('woff'),
7
- url('./sdoc-editor-font/iconfont.ttf?t=1693362307040') format('truetype'),
8
- url('./sdoc-editor-font/iconfont.svg?t=1693362307040#sdocfont') format('svg');
3
+ src: url('./sdoc-editor-font/iconfont.eot?t=1694758459474'); /* IE9 */
4
+ src: url('./sdoc-editor-font/iconfont.eot?t=1694758459474#iefix') format('embedded-opentype'), /* IE6-IE8 */
5
+ url('./sdoc-editor-font/iconfont.woff2?t=1694758459474') format('woff2'),
6
+ url('./sdoc-editor-font/iconfont.woff?t=1694758459474') format('woff'),
7
+ url('./sdoc-editor-font/iconfont.ttf?t=1694758459474') format('truetype'),
8
+ url('./sdoc-editor-font/iconfont.svg?t=1694758459474#sdocfont') format('svg');
9
9
  }
10
10
 
11
11
  .sdocfont {
@@ -16,6 +16,14 @@
16
16
  -moz-osx-font-smoothing: grayscale;
17
17
  }
18
18
 
19
+ .sdoc-sm-close:before {
20
+ content: "\e655";
21
+ }
22
+
23
+ .sdoc-merge-cell:before {
24
+ content: "\e653";
25
+ }
26
+
19
27
  .sdoc-download:before {
20
28
  content: "\e652";
21
29
  }
@@ -1,105 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
- import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
3
- import { Editor } from '@seafile/slate';
4
- import { useTranslation } from 'react-i18next';
5
- import { createDefaultEditor } from './extension';
6
- import { focusEditor } from './extension/core';
7
- import { withSocketIO } from './socket';
8
- import withNodeId from './node-id';
9
- import { PAGE_EDIT_AREA_WIDTH } from './constants';
10
- import context from '../context';
11
- import { EditorContainer, EditorContent } from './layout';
12
- import SlateEditor from './slate-editor';
13
- import InsertElementDialog from './extension/commons/insert-element-dialog';
14
- var SDocEditor = forwardRef(function (_ref, ref) {
15
- var document = _ref.document,
16
- config = _ref.config;
17
- var _useTranslation = useTranslation(),
18
- t = _useTranslation.t;
19
-
20
- // init editor
21
- var editor = useMemo(function () {
22
- var defaultEditor = createDefaultEditor();
23
- var newEditor = withNodeId(withSocketIO(defaultEditor, {
24
- document: document,
25
- config: config
26
- }));
27
- var cursors = document.cursors;
28
- newEditor.cursors = cursors || {};
29
- newEditor.width = PAGE_EDIT_AREA_WIDTH; // default width
30
- newEditor.readonly = false;
31
- return newEditor;
32
- // eslint-disable-next-line react-hooks/exhaustive-deps
33
- }, []);
34
- var _useState = useState(document.children),
35
- _useState2 = _slicedToArray(_useState, 2),
36
- slateValue = _useState2[0],
37
- setSlateValue = _useState2[1];
38
-
39
- // The parent component can call the method of this component through ref
40
- useImperativeHandle(ref, function () {
41
- return {
42
- // get latest value
43
- getValue: function getValue() {
44
- return slateValue;
45
- }
46
- };
47
- }, [slateValue]);
48
-
49
- // useMount: init socket connection
50
- useEffect(function () {
51
- editor.openConnection();
52
- return function () {
53
- editor.closeConnection();
54
- };
55
- // eslint-disable-next-line react-hooks/exhaustive-deps
56
- }, []);
57
-
58
- // useMount: focus editor
59
- useEffect(function () {
60
- var timer = setTimeout(function () {
61
- var _editor$children = _slicedToArray(editor.children, 1),
62
- firstNode = _editor$children[0];
63
- if (firstNode) {
64
- var _firstNode$children = _slicedToArray(firstNode.children, 1),
65
- firstNodeFirstChild = _firstNode$children[0];
66
- if (firstNodeFirstChild) {
67
- var endOfFirstNode = Editor.end(editor, [0, 0]);
68
- var range = {
69
- anchor: endOfFirstNode,
70
- focus: endOfFirstNode
71
- };
72
- focusEditor(editor, range);
73
- }
74
- }
75
- }, 300);
76
- return function () {
77
- clearTimeout(timer);
78
- };
79
- // eslint-disable-next-line react-hooks/exhaustive-deps
80
- }, []);
81
-
82
- // useMount: reset title
83
- useEffect(function () {
84
- var isSdocRevision = context.getSetting('isSdocRevision');
85
- var originFilename = context.getSetting('originFilename');
86
- if (isSdocRevision) {
87
- window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
88
- }
89
-
90
- // eslint-disable-next-line react-hooks/exhaustive-deps
91
- }, []);
92
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
93
- editor: editor
94
- }, /*#__PURE__*/React.createElement(EditorContent, {
95
- docValue: slateValue,
96
- showOutline: true
97
- }, /*#__PURE__*/React.createElement(SlateEditor, {
98
- editor: editor,
99
- slateValue: slateValue,
100
- setSlateValue: setSlateValue
101
- }))), /*#__PURE__*/React.createElement(InsertElementDialog, {
102
- editor: editor
103
- }));
104
- });
105
- export default SDocEditor;