@seafile/sdoc-editor 0.1.145 → 0.1.146-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 (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 +41 -0
  15. package/dist/basic-sdk/socket/socket-manager.js +26 -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 +23 -2
  28. package/dist/context.js +35 -4
  29. package/dist/pages/simple-editor.js +268 -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.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,27 @@
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
+ // REBASE_DOCUMENT: 'rebase_document',
9
+ PUBLISH_DOCUMENT: 'publish_document',
10
+ MERGE_DOCUMENT: 'merge_document'
11
+ };
12
+ export var MODE = {
13
+ DIFF_VIEWER: 'diff-viewer',
14
+ VIEWER: 'viewer',
15
+ EDITOR: 'editor',
16
+ REBASE: 'rebase'
17
+ };
18
+ export var TIP_TYPE = {
19
+ DELETE_NO_CHANGES_REVISION: 'delete_no_changes_revision',
20
+ MERGE: 'merge',
21
+ HAS_CONFLICT_BEFORE_PUBLISH: 'has_conflict_before_publish',
22
+ HAS_BEEN_PUBLISHED: 'has_been_published',
23
+ HAS_BEEN_MERGE: 'has_been_merge',
24
+ HAS_CONFLICT_BEFORE_VIEW_CHANGES: 'has_conflict_before_view_changes'
25
+ };
26
+ 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);
27
+ 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,103 @@ 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) : '';
19
27
  var editorRef = useRef(null);
20
28
  var _useState = useState(true),
21
29
  _useState2 = _slicedToArray(_useState, 2),
22
- isFirstLoad = _useState2[0],
23
- setFirstLoad = _useState2[1];
24
- var _useState3 = useState(true),
30
+ isLoadingSdoc = _useState2[0],
31
+ setLoadingSdoc = _useState2[1];
32
+ var _useState3 = useState(''),
25
33
  _useState4 = _slicedToArray(_useState3, 2),
26
- isLoadingSdoc = _useState4[0],
27
- setLoadingSdoc = _useState4[1];
28
- var _useState5 = useState(''),
34
+ errorMessage = _useState4[0],
35
+ setErrorMessage = _useState4[1];
36
+ var _useState5 = useState(false),
29
37
  _useState6 = _slicedToArray(_useState5, 2),
30
- errorMessage = _useState6[0],
31
- setErrorMessage = _useState6[1];
32
- var _useState7 = useState(false),
38
+ isShowChanges = _useState6[0],
39
+ setShowChanges = _useState6[1];
40
+ var _useState7 = useState(null),
33
41
  _useState8 = _slicedToArray(_useState7, 2),
34
- isShowChanges = _useState8[0],
35
- setShowChanges = _useState8[1];
36
- var _useState9 = useState(null),
42
+ document = _useState8[0],
43
+ setDocument = _useState8[1];
44
+ var _useState9 = useState(MODE.EDITOR),
37
45
  _useState10 = _slicedToArray(_useState9, 2),
38
- document = _useState10[0],
39
- setDocument = _useState10[1];
40
- var _useState11 = useState(null),
46
+ mode = _useState10[0],
47
+ setMode = _useState10[1];
48
+ var _useState11 = useState([]),
41
49
  _useState12 = _slicedToArray(_useState11, 2),
42
- currentContent = _useState12[0],
43
- setCurrentContent = _useState12[1];
44
- var _useState13 = useState(null),
50
+ changes = _useState12[0],
51
+ setChanges = _useState12[1];
52
+ var _useState13 = useState(false),
45
53
  _useState14 = _slicedToArray(_useState13, 2),
46
- lastContent = _useState14[0],
47
- setLastContent = _useState14[1];
54
+ showTip = _useState14[0],
55
+ setShowTip = _useState14[1];
56
+ var _useState15 = useState(''),
57
+ _useState16 = _slicedToArray(_useState15, 2),
58
+ tipType = _useState16[0],
59
+ setTipType = _useState16[1];
60
+ var _useState17 = useState([]),
61
+ _useState18 = _slicedToArray(_useState17, 2),
62
+ mergeValue = _useState18[0],
63
+ setMergeValue = _useState18[1];
64
+ useEffect(function () {
65
+ initDocumentData();
66
+
67
+ // eslint-disable-next-line react-hooks/exhaustive-deps
68
+ }, []);
69
+
70
+ // 提示刷新界面: 主动刷新
71
+ var mergeDocument = useCallback(function (document, originFileVersion) {
72
+ setTipType(TIP_TYPE.HAS_BEEN_MERGE);
73
+ setShowTip(true);
74
+
75
+ // eslint-disable-next-line react-hooks/exhaustive-deps
76
+ }, [editorRef]);
77
+
78
+ // 提示刷新界面: 被动跳转
79
+ var hasPublishRevision = useCallback(function () {
80
+ setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
81
+ setShowTip(true);
82
+
83
+ // eslint-disable-next-line react-hooks/exhaustive-deps
84
+ }, [editorRef]);
48
85
  useEffect(function () {
49
- context.initApi();
50
- initDocumentData(true);
86
+ var eventBus = EventBus.getInstance();
87
+ var mergeDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.MERGE_DOCUMENT, mergeDocument);
88
+ var publishDocumentSubscribe = eventBus.subscribe(EXTERNAL_EVENT.PUBLISH_DOCUMENT, hasPublishRevision);
89
+ return function () {
90
+ mergeDocumentSubscribe();
91
+ publishDocumentSubscribe();
92
+ };
51
93
 
52
94
  // eslint-disable-next-line react-hooks/exhaustive-deps
53
95
  }, []);
54
- var initDocumentData = useCallback(function (isFirstLoad) {
96
+
97
+ // useMount: reset title
98
+ useEffect(function () {
99
+ var isSdocRevision = context.getSetting('isSdocRevision');
100
+ var originFilename = context.getSetting('originFilename');
101
+ if (isSdocRevision) {
102
+ window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
103
+ }
104
+
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, []);
107
+ var initDocumentData = useCallback(function () {
55
108
  setShowChanges(false);
56
109
  setLoadingSdoc(true);
57
110
  context.getFileContent().then(function (res) {
@@ -65,7 +118,6 @@ var SimpleEditor = function SimpleEditor(_ref) {
65
118
  }
66
119
  setDocument(result);
67
120
  setLoadingSdoc(false);
68
- isFirstLoad && setFirstLoad(false);
69
121
  }).catch(function (error) {
70
122
  // eslint-disable-next-line
71
123
  console.log(error);
@@ -83,54 +135,202 @@ var SimpleEditor = function SimpleEditor(_ref) {
83
135
 
84
136
  // eslint-disable-next-line react-hooks/exhaustive-deps
85
137
  }, []);
86
- var initChangesData = useCallback(function () {
87
- setShowChanges(true);
88
- setLoadingSdoc(true);
89
- context.getSeadocRevisionDownloadLinks().then(function (res) {
138
+ var setFileContent = useCallback(function () {
139
+ context.getFileContent().then(function (res) {
140
+ var result = res.data || generateDefaultDocContent();
141
+ if (result && !result.children) {
142
+ result = {
143
+ version: 0,
144
+ children: result.content,
145
+ cursors: result.cursors || {}
146
+ };
147
+ }
148
+ setDocument(result);
149
+ editorRef.current.setSlateValue(result);
150
+ editorRef.current.setLoading(false);
151
+ }).catch(function (error) {
152
+ // eslint-disable-next-line
153
+ console.log(error);
154
+ setErrorMessage('Load_doc_content_error');
155
+ editorRef.current.setLoading(false);
156
+ });
157
+
158
+ // eslint-disable-next-line no-trailing-spaces
159
+ }, []);
160
+ var setDiffContent = useCallback(function () {
161
+ context.getSeadocOriginFileDownloadLink().then(function (res) {
90
162
  var originFileDownloadLink = res.data.origin_file_download_link;
91
163
  return fetch(originFileDownloadLink);
92
164
  }).then(function (res) {
93
165
  return res.json();
94
166
  }).then(function (originContent) {
95
- setLastContent(originContent);
96
- setErrorMessage(null);
97
- setLoadingSdoc(false);
167
+ editorRef.current.setDiffContent(originContent);
168
+ editorRef.current.setLoading(false);
98
169
  }).catch(function (error) {
170
+ console.log('error');
171
+ });
172
+ }, []);
173
+ var toggleViewChanges = useCallback(function (isShowChanges) {
174
+ var needFetchNewContent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
175
+ var revisionCurrentContent = editorRef.current.getSlateValue();
176
+ if (revisionCurrentContent.children.filter(function (item) {
177
+ return item.rebaseType;
178
+ }).length !== 0) {
179
+ setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_VIEW_CHANGES);
180
+ setShowTip(true);
181
+ return;
182
+ }
183
+ editorRef.current.setLoading(true);
184
+ setShowChanges(isShowChanges);
185
+ var mode = isShowChanges ? MODE.DIFF_VIEWER : MODE.EDITOR;
186
+ setMode(mode);
187
+ editorRef.current.setEditorMode(mode);
188
+ if (!isShowChanges) {
189
+ setFileContent();
190
+ return;
191
+ }
192
+ if (!needFetchNewContent) {
193
+ setDiffContent();
194
+ return;
195
+ }
196
+ context.getFileContent().then(function (res) {
197
+ var result = res.data || generateDefaultDocContent();
198
+ if (result && !result.children) {
199
+ result = {
200
+ version: 0,
201
+ children: result.content,
202
+ cursors: result.cursors || {}
203
+ };
204
+ }
205
+ setDocument(result);
206
+ editorRef.current.setSlateValue(result);
207
+ }).then(function () {
208
+ setDiffContent();
209
+ }).catch(function (error) {
210
+ // eslint-disable-next-line
211
+ console.log(error);
99
212
  setErrorMessage('Load_doc_content_error');
100
- setLoadingSdoc(false);
213
+ editorRef.current.setLoading(false);
101
214
  });
102
215
 
103
216
  // 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();
217
+ }, [document, editorRef.current]);
218
+ var publishRevision = useCallback(function () {
219
+ var revisionCurrentContent = editorRef.current.getSlateValue();
220
+ if (revisionCurrentContent.children.filter(function (item) {
221
+ return item.rebaseType;
222
+ }).length !== 0) {
223
+ setTipType(TIP_TYPE.HAS_CONFLICT_BEFORE_PUBLISH);
224
+ setShowTip(true);
114
225
  return;
115
226
  }
116
- setChanges([]);
117
- initDocumentData(false);
227
+ var originFileVersion = context.getSetting('originFileVersion');
228
+ var originFilePath = context.getSetting('originFilePath');
229
+ var revisionMasterContent;
230
+ var masterContent;
231
+ context.getFileHistoryVersion(originFileVersion, originFilePath).then(function (res) {
232
+ var fileHistoryRevisionContent = res.data.content; // commit content
233
+ revisionMasterContent = JSON.parse(fileHistoryRevisionContent);
234
+ return context.getSeadocOriginFileDownloadLink();
235
+ }).then(function (res) {
236
+ var originFileDownloadLink = res.data.origin_file_download_link;
237
+ return fetch(originFileDownloadLink);
238
+ }).then(function (res) {
239
+ return res.json();
240
+ }).then(function (content) {
241
+ masterContent = content;
242
+ var _getRebase = getRebase(masterContent, revisionMasterContent, revisionCurrentContent),
243
+ canMerge = _getRebase.canMerge,
244
+ isNeedReplaceMaster = _getRebase.isNeedReplaceMaster,
245
+ value = _getRebase.value;
246
+ if (canMerge && isNeedReplaceMaster) {
247
+ context.publishSdocRevision().then(function (res) {
248
+ editorRef.current.publishDocument(originFileURL);
249
+ setTipType(TIP_TYPE.HAS_BEEN_PUBLISHED);
250
+ setShowTip(true);
251
+ }).catch(function (error) {
252
+ toaster.danger(t('Error'));
253
+ });
254
+ return;
255
+ }
256
+ if (canMerge && !isNeedReplaceMaster) {
257
+ setTipType(TIP_TYPE.DELETE_NO_CHANGES_REVISION);
258
+ setShowTip(true);
259
+ return;
260
+ }
261
+ setMergeValue(value);
262
+ setTipType(TIP_TYPE.MERGE);
263
+ setShowTip(true);
264
+ }).catch(function (error) {
265
+ toaster.danger(t('Error'));
266
+ });
118
267
 
119
268
  // 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];
269
+ }, [document, isShowChanges, mode]);
270
+ var abortRebase = useCallback(function () {
271
+ toggleViewChanges(isShowChanges, true);
272
+
273
+ // eslint-disable-next-line react-hooks/exhaustive-deps
274
+ }, [isShowChanges, document]);
125
275
  var setDiffChanges = useCallback(function (diff) {
126
276
  setChanges(diff.changes);
127
277
 
128
278
  // eslint-disable-next-line react-hooks/exhaustive-deps
129
279
  }, [isShowChanges]);
130
- if (isFirstLoad && !errorMessage) {
280
+ var jumpToURL = useCallback(function (url) {
281
+ window.href = url;
282
+ }, []);
283
+ var closeTip = useCallback(function () {
284
+ setShowTip(false);
285
+
286
+ // eslint-disable-next-line react-hooks/exhaustive-deps
287
+ }, [tipType]);
288
+ var tipSubmit = useCallback(function () {
289
+ if (tipType === TIP_TYPE.DELETE_NO_CHANGES_REVISION) {
290
+ context.deleteSdocRevision().then(function (res) {
291
+ if (res.data.success) {
292
+ // 通知其他用户文档已经发布
293
+ var targetURL = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(originFilePath);
294
+ editorRef.current.publishDocument(targetURL);
295
+ setShowTip(false);
296
+ // 跳转页面
297
+ jumpToURL(targetURL);
298
+ }
299
+ }).catch(function (error) {
300
+ toaster.danger(t('Error'));
301
+ });
302
+ return;
303
+ }
304
+ if (tipType === TIP_TYPE.MERGE) {
305
+ context.mergeSdocRevision().then(function (res) {
306
+ var origin_file_version = res.data.origin_file_version;
307
+ context.updateSettings({
308
+ 'originFileVersion': origin_file_version
309
+ });
310
+
311
+ // 通知其他用户合并文档 并更新
312
+ editorRef.current.mergeDocument(mergeValue, origin_file_version);
313
+
314
+ // 当前用户更新内容
315
+ editorRef.current.setLoading(true);
316
+ editorRef.current.setSlateValue(mergeValue);
317
+ setMode(MODE.EDITOR);
318
+ editorRef.current.setEditorMode(MODE.EDITOR);
319
+ editorRef.current.setLoading(false);
320
+ setShowTip(false);
321
+ }).catch(function (error) {
322
+ toaster.danger(t('Error'));
323
+ });
324
+ return;
325
+ }
326
+ setShowTip(false);
327
+
328
+ // eslint-disable-next-line react-hooks/exhaustive-deps
329
+ }, [tipType, originFileURL, mergeValue, editorRef.current]);
330
+ if (isLoadingSdoc) {
131
331
  return /*#__PURE__*/React.createElement(Loading, null);
132
332
  }
133
- if (isFirstLoad && errorMessage) {
333
+ if (errorMessage) {
134
334
  return /*#__PURE__*/React.createElement("div", {
135
335
  className: "error-page"
136
336
  }, /*#__PURE__*/React.createElement("div", {
@@ -143,25 +343,21 @@ var SimpleEditor = function SimpleEditor(_ref) {
143
343
  isEditMode: !isShowChanges
144
344
  }), /*#__PURE__*/React.createElement(DocOperations, {
145
345
  isShowChanges: isShowChanges,
346
+ mode: mode,
146
347
  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,
348
+ toggleViewChanges: toggleViewChanges,
349
+ publishRevision: publishRevision,
350
+ abortRebase: abortRebase
351
+ })), /*#__PURE__*/React.createElement(Content, null, /*#__PURE__*/React.createElement(SDocEditor, {
163
352
  ref: editorRef,
164
- isOpenSocket: context.getSetting('isOpenSocket')
165
- })))));
353
+ document: document,
354
+ mode: mode,
355
+ setDiffChanges: setDiffChanges,
356
+ toggleViewChanges: toggleViewChanges
357
+ }))), showTip && /*#__PURE__*/React.createElement(TipDialog, {
358
+ toggle: closeTip,
359
+ submit: tipSubmit,
360
+ tipType: tipType
361
+ }));
166
362
  };
167
363
  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
  "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
  }