@seafile/sdoc-editor 0.1.145 → 0.1.146-beta-4

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 (33) 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/assets/css/default.css +5 -2
  4. package/dist/basic-sdk/comment/comment/comment-editor.js +4 -4
  5. package/dist/basic-sdk/constants/index.js +14 -1
  6. package/dist/basic-sdk/editor/common-editor.js +47 -0
  7. package/dist/basic-sdk/editor/index.css +29 -0
  8. package/dist/basic-sdk/editor/index.js +340 -0
  9. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  10. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  11. package/dist/basic-sdk/extension/constants/font.js +1 -1
  12. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  13. package/dist/basic-sdk/socket/helpers.js +2 -0
  14. package/dist/basic-sdk/socket/socket-client.js +47 -0
  15. package/dist/basic-sdk/socket/socket-manager.js +30 -2
  16. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  17. package/dist/basic-sdk/utils/diff.js +2 -2
  18. package/dist/basic-sdk/utils/rebase.js +196 -0
  19. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  20. package/dist/basic-sdk/views/viewer.js +8 -11
  21. package/dist/components/doc-operations/index.js +8 -2
  22. package/dist/components/doc-operations/revision-operations/index.js +11 -3
  23. package/dist/components/doc-operations/revision-operations/publish-button.js +16 -13
  24. package/dist/components/tip-dialog/index.css +0 -0
  25. package/dist/components/tip-dialog/index.js +49 -0
  26. package/dist/components/tip-dialog/tip-content.js +56 -0
  27. package/dist/constants/index.js +24 -2
  28. package/dist/context.js +35 -4
  29. package/dist/pages/simple-editor.js +272 -72
  30. package/package.json +1 -1
  31. package/public/locales/en/sdoc-editor.json +13 -1
  32. package/public/locales/zh_CN/sdoc-editor.json +12 -1
  33. package/dist/basic-sdk/editor.js +0 -105
@@ -0,0 +1,56 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useEffect, useState } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { TIP_TYPE, TIP_CONTENT } from '../../constants';
6
+ import context from '../../context';
7
+ var TipContent = function TipContent(_ref) {
8
+ var tipType = _ref.tipType;
9
+ var _useState = useState(3),
10
+ _useState2 = _slicedToArray(_useState, 2),
11
+ time = _useState2[0],
12
+ setTime = _useState2[1];
13
+ useEffect(function () {
14
+ if (tipType === TIP_TYPE.HAS_BEEN_PUBLISHED) {
15
+ var _time = 3;
16
+ var timer = setInterval(function () {
17
+ _time--;
18
+ setTime(_time);
19
+ if (_time === 0) {
20
+ clearInterval(timer);
21
+ timer = null;
22
+ }
23
+ }, 1000);
24
+ return function () {
25
+ timer && clearInterval(timer);
26
+ };
27
+ }
28
+ }, [tipType]);
29
+ useEffect(function () {
30
+ if (time === 0) {
31
+ var repoID = context.getSetting('repoID');
32
+ var siteRoot = context.getSetting('siteRoot');
33
+ var originFilePath = context.getSetting('originFilePath');
34
+ var originFileURL = "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath);
35
+ window.location.href = originFileURL;
36
+ }
37
+ }, [time]);
38
+ var _useTranslation = useTranslation(),
39
+ t = _useTranslation.t;
40
+ switch (tipType) {
41
+ case TIP_TYPE.HAS_BEEN_PUBLISHED:
42
+ {
43
+ return /*#__PURE__*/React.createElement(React.Fragment, null, t(TIP_CONTENT[tipType], {
44
+ time: time
45
+ }));
46
+ }
47
+ default:
48
+ {
49
+ return /*#__PURE__*/React.createElement(React.Fragment, null, t(TIP_CONTENT[tipType]));
50
+ }
51
+ }
52
+ };
53
+ TipContent.propTypes = {
54
+ tipType: PropTypes.string
55
+ };
56
+ export default TipContent;
@@ -1,6 +1,28 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ var _TIP_TITLE, _TIP_CONTENT;
1
3
  export var EXTERNAL_EVENT = {
2
4
  INTERNAL_LINK_CLICK: 'internal_link_click',
3
5
  TOGGLE_STAR: 'toggle_star',
4
6
  UNMARK_AS_DRAFT: 'unmark_as_draft',
5
- SHARE_SDOC: 'share_sdoc'
6
- };
7
+ SHARE_SDOC: 'share_sdoc',
8
+ PUBLISH_DOCUMENT: 'publish_document',
9
+ PUBLISH_DOCUMENT_ERROR: 'publish_document_error',
10
+ MERGE_DOCUMENT: 'merge_document',
11
+ MERGE_DOCUMENT_ERROR: 'merge_document_error',
12
+ UPDATE_DOCUMENT_FROM_HARD_DISK: 'update-document-from-hard-disk'
13
+ };
14
+ export var MODE = {
15
+ DIFF_VIEWER: 'diff-viewer',
16
+ VIEWER: 'viewer',
17
+ EDITOR: 'editor'
18
+ };
19
+ export var TIP_TYPE = {
20
+ DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
21
+ MERGE: 'merge',
22
+ HAS_CONFLICT_BEFORE_PUBLISH: 'has_conflict_before_publish',
23
+ HAS_BEEN_PUBLISHED: 'has_been_published',
24
+ HAS_BEEN_MERGE: 'has_been_merge',
25
+ HAS_CONFLICT_BEFORE_VIEW_CHANGES: 'has_conflict_before_view_changes'
26
+ };
27
+ export var TIP_TITLE = (_TIP_TITLE = {}, _defineProperty(_TIP_TITLE, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_BEEN_MERGE, 'Tip'), _defineProperty(_TIP_TITLE, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Tip'), _TIP_TITLE);
28
+ export var TIP_CONTENT = (_TIP_CONTENT = {}, _defineProperty(_TIP_CONTENT, TIP_TYPE.DELETE_NO_CHANGES_REVISION, 'Rebase_delete_no_change_revision_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.MERGE, 'Merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH, 'Has_conflict_before_publish_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_PUBLISHED, 'Has_been_published_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_BEEN_MERGE, 'Has_been_merge_tip'), _defineProperty(_TIP_CONTENT, TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES, 'Has_conflict_before_view_changes_tip'), _TIP_CONTENT);
package/dist/context.js CHANGED
@@ -10,6 +10,9 @@ var Context = /*#__PURE__*/function () {
10
10
  this.initSettings = function () {
11
11
  _this.settings = window.seafile ? window.seafile : window.seafileConfig;
12
12
  };
13
+ // saveDocContentByRebase(content) {
14
+ // return this.sdocServerApi.saveDocContentByRebase(content);
15
+ // }
13
16
  this.uploadLocalImage = function (imageFile) {
14
17
  var docUuid = _this.getSetting('docUuid');
15
18
  return _this.api.uploadSdocImage(docUuid, imageFile).then(function (res) {
@@ -45,6 +48,13 @@ var Context = /*#__PURE__*/function () {
45
48
  if (this.settings[key] === false) return this.settings[key];
46
49
  return this.settings[key] || '';
47
50
  }
51
+ }, {
52
+ key: "updateSettings",
53
+ value: function updateSettings(update) {
54
+ for (var key in update) {
55
+ this.settings[key] = update[key];
56
+ }
57
+ }
48
58
  }, {
49
59
  key: "getViewConfig",
50
60
  value: function getViewConfig() {
@@ -156,14 +166,15 @@ var Context = /*#__PURE__*/function () {
156
166
  }, {
157
167
  key: "publishSdocRevision",
158
168
  value: function publishSdocRevision() {
169
+ var replace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
159
170
  var docUuid = this.getSetting('docUuid');
160
- return this.api.sdocPublishRevision(docUuid);
171
+ return this.api.sdocPublishRevision(docUuid, replace);
161
172
  }
162
173
  }, {
163
- key: "getSeadocRevisionDownloadLinks",
164
- value: function getSeadocRevisionDownloadLinks() {
174
+ key: "getSeadocOriginFileDownloadLink",
175
+ value: function getSeadocOriginFileDownloadLink() {
165
176
  var docUuid = this.getSetting('docUuid');
166
- return this.api.getSeadocRevisionDownloadLinks(docUuid);
177
+ return this.api.getSeadocOriginFileDownloadLink(docUuid);
167
178
  }
168
179
  }, {
169
180
  key: "getSdocRevisionsCount",
@@ -177,6 +188,26 @@ var Context = /*#__PURE__*/function () {
177
188
  var docUuid = this.getSetting('docUuid');
178
189
  return this.api.getSdocRevisions(docUuid, page, perPage);
179
190
  }
191
+ }, {
192
+ key: "deleteSdocRevision",
193
+ value: function deleteSdocRevision() {
194
+ var docUuid = this.getSetting('docUuid');
195
+ return this.api.deleteSdocRevision(docUuid);
196
+ }
197
+ }, {
198
+ key: "mergeSdocRevision",
199
+ value: function mergeSdocRevision() {
200
+ var docUuid = this.getSetting('docUuid');
201
+ return this.api.mergeSdocRevision(docUuid);
202
+ }
203
+ }, {
204
+ key: "getFileHistoryVersion",
205
+ value: function getFileHistoryVersion(fileVersion, filePath) {
206
+ var docUuid = this.getSetting('docUuid');
207
+ return this.api.getFileHistoryVersion(docUuid, fileVersion, filePath);
208
+ }
209
+
210
+ // local files
180
211
  }, {
181
212
  key: "getSdocLocalFiles",
182
213
  value: function getSdocLocalFiles(p) {
@@ -1,9 +1,6 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
2
  import React, { useCallback, useEffect, useRef, useState } from 'react';
4
3
  import { withTranslation } from 'react-i18next';
5
- import deepCopy from 'deep-copy';
6
- import { SDocEditor, DiffViewer } from '../basic-sdk';
7
4
  import Loading from '../components/loading';
8
5
  import DocInfo from '../components/doc-info';
9
6
  import DocOperations from '../components/doc-operations';
@@ -11,47 +8,115 @@ import Layout, { Header, Content } from '../layout';
11
8
  import { generateDefaultDocContent } from '../utils';
12
9
  import context from '../context';
13
10
  import ErrorBoundary from './error-boundary';
11
+ import TipDialog from '../components/tip-dialog';
12
+ import { EXTERNAL_EVENT, MODE, TIP_TYPE } from '../constants';
13
+ import { getRebase } from '../basic-sdk/utils/rebase';
14
+ import toaster from '../components/toast';
15
+ import { EventBus, SDocEditor } from '../basic-sdk';
14
16
  import '../assets/css/simple-editor.css';
15
17
  var SimpleEditor = function SimpleEditor(_ref) {
16
18
  var isStarred = _ref.isStarred,
17
19
  isDraft = _ref.isDraft,
18
20
  t = _ref.t;
21
+ context.initApi();
22
+ var repoID = context.getSetting('repoID');
23
+ var siteRoot = context.getSetting('siteRoot');
24
+ var originFilePath = context.getSetting('originFilePath');
25
+ var isRevision = context.getSetting('isSdocRevision');
26
+ var originFileURL = isRevision ? "".concat(siteRoot, "lib/").concat(repoID, "/file").concat(originFilePath) : '';
27
+ var originDocName = isRevision ? context.getSetting('originFilename') : '';
28
+ var originDocUuid = isRevision ? context.getSetting('originDocUuid') : '';
19
29
  var editorRef = useRef(null);
20
30
  var _useState = useState(true),
21
31
  _useState2 = _slicedToArray(_useState, 2),
22
- isFirstLoad = _useState2[0],
23
- setFirstLoad = _useState2[1];
24
- var _useState3 = useState(true),
32
+ isLoadingSdoc = _useState2[0],
33
+ setLoadingSdoc = _useState2[1];
34
+ var _useState3 = useState(''),
25
35
  _useState4 = _slicedToArray(_useState3, 2),
26
- isLoadingSdoc = _useState4[0],
27
- setLoadingSdoc = _useState4[1];
28
- var _useState5 = useState(''),
36
+ errorMessage = _useState4[0],
37
+ setErrorMessage = _useState4[1];
38
+ var _useState5 = useState(false),
29
39
  _useState6 = _slicedToArray(_useState5, 2),
30
- errorMessage = _useState6[0],
31
- setErrorMessage = _useState6[1];
32
- var _useState7 = useState(false),
40
+ isShowChanges = _useState6[0],
41
+ setShowChanges = _useState6[1];
42
+ var _useState7 = useState(null),
33
43
  _useState8 = _slicedToArray(_useState7, 2),
34
- isShowChanges = _useState8[0],
35
- setShowChanges = _useState8[1];
36
- var _useState9 = useState(null),
44
+ document = _useState8[0],
45
+ setDocument = _useState8[1];
46
+ var _useState9 = useState(MODE.EDITOR),
37
47
  _useState10 = _slicedToArray(_useState9, 2),
38
- document = _useState10[0],
39
- setDocument = _useState10[1];
40
- var _useState11 = useState(null),
48
+ mode = _useState10[0],
49
+ setMode = _useState10[1];
50
+ var _useState11 = useState([]),
41
51
  _useState12 = _slicedToArray(_useState11, 2),
42
- currentContent = _useState12[0],
43
- setCurrentContent = _useState12[1];
44
- var _useState13 = useState(null),
52
+ changes = _useState12[0],
53
+ setChanges = _useState12[1];
54
+ var _useState13 = useState(false),
45
55
  _useState14 = _slicedToArray(_useState13, 2),
46
- lastContent = _useState14[0],
47
- setLastContent = _useState14[1];
56
+ showTip = _useState14[0],
57
+ setShowTip = _useState14[1];
58
+ var _useState15 = useState(''),
59
+ _useState16 = _slicedToArray(_useState15, 2),
60
+ tipType = _useState16[0],
61
+ setTipType = _useState16[1];
62
+ var _useState17 = useState([]),
63
+ _useState18 = _slicedToArray(_useState17, 2),
64
+ mergeValue = _useState18[0],
65
+ setMergeValue = _useState18[1];
66
+ useEffect(function () {
67
+ initDocumentData();
68
+
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ }, []);
71
+ var mergeDocument = useCallback(function () {
72
+ setTipType(TIP_TYPE.HAS_BEEN_MERGE);
73
+ setShowTip(true);
74
+
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ }, [editorRef]);
77
+ var hasPublishRevision = useCallback(function () {
78
+ setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
79
+ setShowTip(true);
80
+
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, [editorRef]);
83
+ var mergeDocumentError = useCallback(function () {}, []);
84
+ var publishDocumentError = useCallback(function () {}, []);
85
+ var updateDocumentFromHardDisk = useCallback(function (document) {
86
+ setDocument(document);
87
+ editorRef.current.setSlateValue(document);
88
+
89
+ // eslint-disable-next-line react-hooks/exhaustive-deps
90
+ }, [editorRef.current]);
48
91
  useEffect(function () {
49
- context.initApi();
50
- initDocumentData(true);
92
+ var eventBus = EventBus.getInstance();
93
+ var mergeDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.MERGE_DOCUMENT, mergeDocument);
94
+ var publishDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
95
+ var mergeDocumentErrorSubscribe = eventBus.subscribe(EXTERNAL_EVENT.MERGE_DOCUMENT_ERROR, mergeDocumentError);
96
+ var publishDocumentErrorSubscribe = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR, publishDocumentError);
97
+ var updateDocumentFromHardDiskSubscribe = eventBus.subscribe(EXTERNAL_EVENT.UPDATE_DOCUMENT_FROM_HARD_DISK, updateDocumentFromHardDisk);
98
+ return function () {
99
+ mergeDocumentSubscribe();
100
+ publishDocumentSubscribe();
101
+ mergeDocumentErrorSubscribe();
102
+ publishDocumentErrorSubscribe();
103
+ updateDocumentFromHardDiskSubscribe();
104
+ };
51
105
 
52
106
  // eslint-disable-next-line react-hooks/exhaustive-deps
53
107
  }, []);
54
- var initDocumentData = useCallback(function (isFirstLoad) {
108
+
109
+ // useMount: reset title
110
+ useEffect(function () {
111
+ var isSdocRevision = context.getSetting('isSdocRevision');
112
+ var originFilename = context.getSetting('originFilename');
113
+ if (isSdocRevision) {
114
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
115
+ }
116
+
117
+ // eslint-disable-next-line react-hooks/exhaustive-deps
118
+ }, []);
119
+ var initDocumentData = useCallback(function () {
55
120
  setShowChanges(false);
56
121
  setLoadingSdoc(true);
57
122
  context.getFileContent().then(function (res) {
@@ -65,7 +130,6 @@ var SimpleEditor = function SimpleEditor(_ref) {
65
130
  }
66
131
  setDocument(result);
67
132
  setLoadingSdoc(false);
68
- isFirstLoad && setFirstLoad(false);
69
133
  }).catch(function (error) {
70
134
  // eslint-disable-next-line
71
135
  console.log(error);
@@ -83,54 +147,194 @@ var SimpleEditor = function SimpleEditor(_ref) {
83
147
 
84
148
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
149
  }, []);
86
- var initChangesData = useCallback(function () {
87
- setShowChanges(true);
88
- setLoadingSdoc(true);
89
- context.getSeadocRevisionDownloadLinks().then(function (res) {
150
+ var setFileContent = useCallback(function () {
151
+ context.getFileContent().then(function (res) {
152
+ var result = res.data || generateDefaultDocContent();
153
+ if (result && !result.children) {
154
+ result = {
155
+ version: 0,
156
+ children: result.content,
157
+ cursors: result.cursors || {}
158
+ };
159
+ }
160
+ setDocument(result);
161
+ editorRef.current.setSlateValue(result);
162
+ editorRef.current.setLoading(false);
163
+ }).catch(function (error) {
164
+ // eslint-disable-next-line
165
+ console.log(error);
166
+ setErrorMessage('Load_doc_content_error');
167
+ editorRef.current.setLoading(false);
168
+ });
169
+
170
+ // eslint-disable-next-line no-trailing-spaces
171
+ }, []);
172
+ var setDiffContent = useCallback(function () {
173
+ context.getSeadocOriginFileDownloadLink().then(function (res) {
90
174
  var originFileDownloadLink = res.data.origin_file_download_link;
91
175
  return fetch(originFileDownloadLink);
92
176
  }).then(function (res) {
93
177
  return res.json();
94
178
  }).then(function (originContent) {
95
- setLastContent(originContent);
96
- setErrorMessage(null);
97
- setLoadingSdoc(false);
179
+ editorRef.current.setDiffContent(originContent);
180
+ editorRef.current.setLoading(false);
98
181
  }).catch(function (error) {
182
+ console.log('error');
183
+ });
184
+ }, []);
185
+ var toggleViewChanges = useCallback(function (isShowChanges) {
186
+ var needFetchNewContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
187
+ var revisionCurrentContent = editorRef.current.getSlateValue();
188
+ if (revisionCurrentContent.children.filter(function (item) {
189
+ return item.rebaseType;
190
+ }).length !== 0) {
191
+ setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
192
+ setShowTip(true);
193
+ return;
194
+ }
195
+ editorRef.current.setLoading(true);
196
+ setShowChanges(isShowChanges);
197
+ var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
198
+ setMode(mode);
199
+ editorRef.current.setEditorMode(mode);
200
+ if (!isShowChanges) {
201
+ setFileContent();
202
+ return;
203
+ }
204
+ if (!needFetchNewContent) {
205
+ setDiffContent();
206
+ return;
207
+ }
208
+ context.getFileContent().then(function (res) {
209
+ var result = res.data || generateDefaultDocContent();
210
+ if (result && !result.children) {
211
+ result = {
212
+ version: 0,
213
+ children: result.content,
214
+ cursors: result.cursors || {}
215
+ };
216
+ }
217
+ setDocument(result);
218
+ editorRef.current.setSlateValue(result);
219
+ }).then(function () {
220
+ setDiffContent();
221
+ }).catch(function (error) {
222
+ // eslint-disable-next-line
223
+ console.log(error);
99
224
  setErrorMessage('Load_doc_content_error');
100
- setLoadingSdoc(false);
225
+ editorRef.current.setLoading(false);
101
226
  });
102
227
 
103
228
  // eslint-disable-next-line react-hooks/exhaustive-deps
104
- }, [document]);
105
- var toggleViewChanges = useCallback(function (isShowChanges) {
106
- if (isShowChanges) {
107
- var newestValue = editorRef.current.getValue();
108
- setCurrentContent(deepCopy(_objectSpread(_objectSpread({}, document), {}, {
109
- children: newestValue
110
- })));
111
- }
112
- if (isShowChanges) {
113
- initChangesData();
229
+ }, [document, editorRef.current]);
230
+ var publishRevision = useCallback(function () {
231
+ var revisionCurrentContent = editorRef.current.getSlateValue();
232
+ if (revisionCurrentContent.children.filter(function (item) {
233
+ return item.rebaseType;
234
+ }).length !== 0) {
235
+ setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
236
+ setShowTip(true);
114
237
  return;
115
238
  }
116
- setChanges([]);
117
- initDocumentData(false);
239
+ var originFileVersion = context.getSetting('originFileVersion'); // changing
240
+ var revisionMasterContent;
241
+ var masterContent;
242
+ context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
243
+ var fileHistoryRevisionContent = res.data.content; // commit content
244
+ revisionMasterContent = JSON.parse(fileHistoryRevisionContent);
245
+ return context.getSeadocOriginFileDownloadLink();
246
+ }).then(function (res) {
247
+ var originFileDownloadLink = res.data.origin_file_download_link;
248
+ return fetch(originFileDownloadLink);
249
+ }).then(function (res) {
250
+ return res.json();
251
+ }).then(function (content) {
252
+ masterContent = content;
253
+ var _getRebase = getRebase(masterContent, revisionMasterContent, revisionCurrentContent),
254
+ canMerge = _getRebase.canMerge,
255
+ isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
256
+ value = _getRebase.value;
257
+ if (canMerge && isNeedReplaceMaster) {
258
+ context.publishSdocRevision().then(function (res) {
259
+ editorRef.current.publishDocument(originDocUuid, originDocName, true);
260
+ setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
261
+ setShowTip(true);
262
+ }).catch(function (error) {
263
+ toaster.danger(t('Error'));
264
+ });
265
+ return;
266
+ }
267
+ if (canMerge && !isNeedReplaceMaster) {
268
+ setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
269
+ setShowTip(true);
270
+ return;
271
+ }
272
+ setMergeValue(value);
273
+ setTipType(TIP_TYPE.MERGE);
274
+ setShowTip(true);
275
+ }).catch(function (error) {
276
+ toaster.danger(t('Error'));
277
+ });
118
278
 
119
279
  // 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];
280
+ }, [document, isShowChanges, mode, originDocUuid, originDocName, originFilePath]);
281
+ var abortRebase = useCallback(function () {
282
+ toggleViewChanges(isShowChanges, true);
283
+
284
+ // eslint-disable-next-line react-hooks/exhaustive-deps
285
+ }, [isShowChanges, document]);
125
286
  var setDiffChanges = useCallback(function (diff) {
126
287
  setChanges(diff.changes);
127
288
 
128
289
  // eslint-disable-next-line react-hooks/exhaustive-deps
129
290
  }, [isShowChanges]);
130
- if (isFirstLoad && !errorMessage) {
291
+ var jumpToURL = useCallback(function (url) {
292
+ window.location.href = url;
293
+ }, []);
294
+ var closeTip = useCallback(function () {
295
+ setShowTip(false);
296
+
297
+ // eslint-disable-next-line react-hooks/exhaustive-deps
298
+ }, [tipType]);
299
+ var tipSubmit = useCallback(function () {
300
+ if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
301
+ context.deleteSdocRevision().then(function (res) {
302
+ if (res.data.success) {
303
+ editorRef.current.publishDocument(originDocUuid, originDocName, false);
304
+ setShowTip(false);
305
+ jumpToURL(originFileURL);
306
+ }
307
+ }).catch(function (error) {
308
+ toaster.danger(t('Error'));
309
+ });
310
+ return;
311
+ }
312
+ if (tipType === TIP_TYPE.MERGE) {
313
+ context.mergeSdocRevision().then(function (res) {
314
+ var origin_file_version = res.data.origin_file_version;
315
+ context.updateSettings({
316
+ 'originFileVersion': origin_file_version
317
+ });
318
+ editorRef.current.mergeDocument(mergeValue, origin_file_version);
319
+ editorRef.current.setLoading(true);
320
+ editorRef.current.setSlateValue(mergeValue);
321
+ setMode(MODE.EDITOR);
322
+ editorRef.current.setEditorMode(MODE.EDITOR);
323
+ editorRef.current.setLoading(false);
324
+ setShowTip(false);
325
+ }).catch(function (error) {
326
+ toaster.danger(t('Error'));
327
+ });
328
+ return;
329
+ }
330
+ setShowTip(false);
331
+
332
+ // eslint-disable-next-line react-hooks/exhaustive-deps
333
+ }, [tipType, originFileURL, mergeValue, editorRef.current, originDocUuid, originDocName]);
334
+ if (isLoadingSdoc) {
131
335
  return /*#__PURE__*/React.createElement(Loading, null);
132
336
  }
133
- if (isFirstLoad && errorMessage) {
337
+ if (errorMessage) {
134
338
  return /*#__PURE__*/React.createElement("div", {
135
339
  className: "error-page"
136
340
  }, /*#__PURE__*/React.createElement("div", {
@@ -143,25 +347,21 @@ var SimpleEditor = function SimpleEditor(_ref) {
143
347
  isEditMode: !isShowChanges
144
348
  }), /*#__PURE__*/React.createElement(DocOperations, {
145
349
  isShowChanges: isShowChanges,
350
+ mode: mode,
146
351
  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,
352
+ toggleViewChanges: toggleViewChanges,
353
+ publishRevision: publishRevision,
354
+ abortRebase: abortRebase
355
+ })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
163
356
  ref: editorRef,
164
- isOpenSocket: context.getSetting('isOpenSocket')
165
- })))));
357
+ document: document,
358
+ mode: mode,
359
+ setDiffChanges: setDiffChanges,
360
+ toggleViewChanges: toggleViewChanges
361
+ }))), showTip && /*#__PURE__*/React.createElement(TipDialog, {
362
+ toggle: closeTip,
363
+ submit: tipSubmit,
364
+ tipType: tipType
365
+ }));
166
366
  };
167
367
  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.145",
3
+ "version": "0.1.146beta-4",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -362,5 +362,17 @@
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
+ "Need_rebase": "Need rebase",
370
+ "Abort": "Abort",
371
+ "Tip": "Tip",
372
+ "Rebase_delete_no_change_revision_tip": "Revision has not made any change compared to original document. Do you want to delete this revision?",
373
+ "Has_been_merge_tip": "Revision has been merged, please refresh the page to see the latest content.",
374
+ "Has_been_published_tip": "Revision has been published, Automatically jump to source content after {{ time }} seconds.",
375
+ "Has_conflict_before_publish_tip": "There are conflicts in the document, please resolve it before publishing!",
376
+ "Merge_tip": "There are conflicts in the documents. Do you want to merge them?",
377
+ "Has_conflict_before_view_changes_tip": "There are conflicts in the document. Please resolve the conflict before viewing the changes!"
366
378
  }
@@ -362,5 +362,16 @@
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
+ "Need_rebase": "需要变基",
370
+ "Abort": "中止",
371
+ "Rebase_delete_no_change_revision_tip": "修订改没有更改,是否删除修订稿?",
372
+ "Has_been_merge_tip": "修订稿被合并了,请刷新页面查看最新内容。",
373
+ "Has_been_published_tip": "修订稿已经发布了,{{ time }} 秒后自动跳转到源文件.",
374
+ "Has_conflict_before_publish_tip": "文档有冲突,请解决冲突后再发布!",
375
+ "Merge_tip": "文档有冲突,是否合并?",
376
+ "Has_conflict_before_view_changes_tip": "文档有冲突,请解决冲突后再查看更改!"
366
377
  }