@seafile/sdoc-editor 0.1.147 → 0.1.148-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 (32) 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/constants/index.js +14 -1
  4. package/dist/basic-sdk/editor/common-editor.js +50 -0
  5. package/dist/basic-sdk/editor/index.css +29 -0
  6. package/dist/basic-sdk/editor/index.js +129 -0
  7. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  8. package/dist/basic-sdk/extension/constants/element-type.js +4 -1
  9. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  10. package/dist/basic-sdk/extension/plugins/font/helpers.js +1 -1
  11. package/dist/basic-sdk/extension/render/render-element.js +209 -1
  12. package/dist/basic-sdk/socket/helpers.js +2 -0
  13. package/dist/basic-sdk/socket/socket-client.js +38 -0
  14. package/dist/basic-sdk/socket/socket-manager.js +25 -2
  15. package/dist/basic-sdk/socket/with-socket-io.js +35 -12
  16. package/dist/basic-sdk/utils/diff.js +2 -2
  17. package/dist/basic-sdk/utils/rebase.js +197 -0
  18. package/dist/basic-sdk/views/diff-viewer.js +3 -1
  19. package/dist/basic-sdk/views/viewer.js +8 -11
  20. package/dist/components/doc-operations/index.js +4 -2
  21. package/dist/components/doc-operations/revision-operations/index.js +5 -2
  22. package/dist/components/doc-operations/revision-operations/publish-button.js +6 -13
  23. package/dist/components/tip-dialog/index.css +0 -0
  24. package/dist/components/tip-dialog/index.js +49 -0
  25. package/dist/components/tip-dialog/tip-content.js +56 -0
  26. package/dist/constants/index.js +23 -2
  27. package/dist/context.js +35 -4
  28. package/dist/pages/simple-editor.js +247 -83
  29. package/package.json +1 -1
  30. package/public/locales/en/sdoc-editor.json +11 -1
  31. package/public/locales/zh_CN/sdoc-editor.json +10 -1
  32. package/dist/basic-sdk/editor.js +0 -105
@@ -119,6 +119,38 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
119
119
  this.disconnectWithServer = function () {
120
120
  _this.socket.disconnect();
121
121
  };
122
+ this.sendPublishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc, callback) {
123
+ _this.socket.emit('publish-document', _this.getParams({
124
+ origin_doc_uuid: originDocUuid,
125
+ origin_doc_name: originDocName,
126
+ update_origin_doc: isNeedUpdateOriginDoc
127
+ }), function (result) {
128
+ callback && callback(result);
129
+ });
130
+ };
131
+ this.receivePublishDocument = function () {
132
+ var socketManager = SocketManager.getInstance();
133
+ socketManager.receivePublishDocument();
134
+ };
135
+ this.receivePublishDocumentError = function () {
136
+ var socketManager = SocketManager.getInstance();
137
+ socketManager.receivePublishDocumentError();
138
+ };
139
+ this.sendReplaceDocument = function (document, callback) {
140
+ _this.socket.emit('replace-doc', _this.getParams({
141
+ document: document
142
+ }), function (result) {
143
+ callback && callback(result);
144
+ });
145
+ };
146
+ this.receiveDocumentReplaced = function () {
147
+ var socketManager = SocketManager.getInstance();
148
+ socketManager.receiveDocumentReplaced();
149
+ };
150
+ this.receiveDocumentReplacedError = function () {
151
+ var socketManager = SocketManager.getInstance();
152
+ socketManager.receiveDocumentReplacedError();
153
+ };
122
154
  this.config = config;
123
155
  this.isReconnect = false;
124
156
  this.socket = io(config.sdocServer, {
@@ -133,6 +165,12 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
133
165
  this.socket.on('join-room', this.onJoinRoom);
134
166
  this.socket.on('leave-room', this.onLeaveRoom);
135
167
  this.socket.on('update-document', this.onReceiveRemoteOperations);
168
+
169
+ // doc-replaced
170
+ this.socket.on('doc-replaced', this.receiveDocumentReplaced);
171
+ this.socket.on('doc-replaced-error', this.receiveDocumentReplacedError);
172
+ this.socket.on('publish-document', this.receivePublishDocument);
173
+ this.socket.on('publish-document-error', this.receivePublishDocumentError);
136
174
  this.socket.on('update-cursor', this.receiveCursorLocation);
137
175
  this.socket.io.on('reconnect', this.onReconnect);
138
176
  this.socket.io.on('reconnect_attempt', this.onReconnectAttempt);
@@ -7,6 +7,7 @@ import { syncRemoteOperations, reExecRevertOperationList, revertOperationList, s
7
7
  import SocketClient from './socket-client';
8
8
  import { clientDebug, conflictDebug, serverDebug, stateDebug } from '../utils/debug';
9
9
  import { deleteCursor } from '../cursor/helper';
10
+ import { EXTERNAL_EVENT, MODE } from '../../constants';
10
11
 
11
12
  // idle --> sending --> conflict --> idle
12
13
  // --> conflict --> idle
@@ -19,13 +20,34 @@ var STATE = {
19
20
  DISCONNECT: 'disconnect',
20
21
  NEED_RELOAD: 'need_reload'
21
22
  };
22
- var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, document, config) {
23
+ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, _document, config) {
23
24
  var _this = this;
24
25
  _classCallCheck(this, SocketManager);
25
26
  this.getDocumentVersion = function () {
26
27
  var version = _this.document.version;
27
28
  return version;
28
29
  };
30
+ this.sendPublishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc) {
31
+ _this.socketClient.sendPublishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc);
32
+ };
33
+ this.receivePublishDocument = function () {
34
+ _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT);
35
+ };
36
+ this.receivePublishDocumentError = function () {
37
+ _this.eventBus.dispatch(EXTERNAL_EVENT.PUBLISH_DOCUMENT_ERROR);
38
+ };
39
+ this.sendReplaceDocument = function (document) {
40
+ _this.socketClient.sendReplaceDocument(document, function (result) {
41
+ var serverVersion = result.version;
42
+ _this.document['version'] = serverVersion;
43
+ });
44
+ };
45
+ this.receiveDocumentReplaced = function () {
46
+ _this.eventBus.dispatch(EXTERNAL_EVENT.DOCUMENT_REPLACED);
47
+ };
48
+ this.receiveDocumentReplacedError = function () {
49
+ _this.eventBus.dispatch(EXTERNAL_EVENT.DOCUMENT_REPLACED_ERROR);
50
+ };
29
51
  this.onReceiveLocalOperations = function (operations) {
30
52
  _this.pendingOperationList.push(operations);
31
53
  if (_this.pendingOperationList.length > 5) {
@@ -34,6 +56,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
34
56
  _this.sendOperations();
35
57
  };
36
58
  this.sendOperations = function () {
59
+ if (_this.editor.mode !== MODE.EDITOR) return;
37
60
  if (_this.state !== STATE.IDLE) return;
38
61
  stateDebug("State changed: ".concat(_this.state, " -> ").concat(STATE.SENDING));
39
62
  _this.state = STATE.SENDING;
@@ -292,7 +315,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
292
315
  _this.socketClient.disconnectWithServer();
293
316
  };
294
317
  this.editor = editor;
295
- this.document = document;
318
+ this.document = _document;
296
319
  this.socketClient = new SocketClient(config);
297
320
  this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
298
321
  this.remoteOperationsList = []; // Same with pending operations
@@ -1,3 +1,4 @@
1
+ import { MODE } from '../../constants';
1
2
  import { generateCursorData } from '../cursor/helper';
2
3
  import EventBus from '../utils/event-bus';
3
4
  import SocketManager from './socket-manager';
@@ -19,28 +20,50 @@ var withSocketIO = function withSocketIO(editor, options) {
19
20
  SocketManager.destroy();
20
21
  };
21
22
  newEditor.onChange = function () {
22
- if (newEditor.readonly) return;
23
+ var document = options.document,
24
+ config = options.config;
25
+ if (newEditor.mode === MODE.DIFF_VIEWER) return;
23
26
  var operations = newEditor.operations;
24
27
  if (!newEditor.isRemote && operations.length > 0) {
25
28
  var isAllSetSelection = operations.every(function (operation) {
26
29
  return operation.type === 'set_selection';
27
30
  });
28
- var _socketManager = SocketManager.getInstance();
31
+ var _socketManager = SocketManager.getInstance(newEditor, document, config);
29
32
  if (!isAllSetSelection) {
30
- // get update content value operations
31
- var updateOperations = operations.filter(function (operation) {
32
- return operation.type !== 'set_selection';
33
- });
34
- _socketManager.onReceiveLocalOperations(updateOperations);
33
+ if (newEditor.mode === MODE.EDITOR) {
34
+ // get update content value operations
35
+ var updateOperations = operations.filter(function (operation) {
36
+ return operation.type !== 'set_selection';
37
+ });
38
+ _socketManager.onReceiveLocalOperations(updateOperations);
39
+ }
35
40
  }
36
- _socketManager.sendCursorLocation(editor.selection);
41
+ if (newEditor.mode === MODE.EDITOR) {
42
+ _socketManager.sendCursorLocation(editor.selection);
43
+ }
44
+ }
45
+ if (newEditor.mode === MODE.EDITOR) {
46
+ // dispatch editor change event
47
+ var eventBus = EventBus.getInstance(newEditor, document, config);
48
+ eventBus.dispatch('change');
37
49
  }
38
-
39
- // dispatch editor change event
40
- var eventBus = EventBus.getInstance();
41
- eventBus.dispatch('change');
42
50
  onChange();
43
51
  };
52
+ newEditor.rebaseContent = function (document, originFileVersion) {
53
+ var config = options.config;
54
+ var socketManager = SocketManager.getInstance(newEditor, document, config);
55
+ socketManager.sendRebaseContent(document, originFileVersion);
56
+ };
57
+ newEditor.publishDocument = function (originDocUuid, originDocName, isNeedUpdateOriginDoc) {
58
+ var config = options.config;
59
+ var socketManager = SocketManager.getInstance(newEditor, document, config);
60
+ socketManager.sendPublishDocument(originDocUuid, originDocName, isNeedUpdateOriginDoc);
61
+ };
62
+ newEditor.replaceDocument = function (document) {
63
+ var config = options.config;
64
+ var socketManager = SocketManager.getInstance(newEditor, document, config);
65
+ socketManager.sendReplaceDocument(document);
66
+ };
44
67
  return newEditor;
45
68
  };
46
69
  export default withSocketIO;
@@ -31,7 +31,7 @@ var generatorDiffElement = function generatorDiffElement(element, diffType) {
31
31
  return generatorDiffElement(item, diffType, style);
32
32
  })), _objectSpread3));
33
33
  };
34
- var generateIdMapAndIds = function generateIdMapAndIds(elements) {
34
+ export var generateIdMapAndIds = function generateIdMapAndIds(elements) {
35
35
  var map = {};
36
36
  var ids = [];
37
37
  if (!Array.isArray(elements) || elements.length === 0) return {
@@ -54,7 +54,7 @@ var hasChildren = function hasChildren(element) {
54
54
  };
55
55
 
56
56
  // id diffs
57
- var getIdDiffs = function getIdDiffs(oldIds, newIds) {
57
+ export var getIdDiffs = function getIdDiffs(oldIds, newIds) {
58
58
  var diff = new DiffText(oldIds, newIds);
59
59
  return diff.getDiffs();
60
60
  };
@@ -0,0 +1,197 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { generateIdMapAndIds, getIdDiffs } from './diff';
4
+ import ObjectUtils from './object-utils';
5
+ import { MODIFY_TYPE, REBASE_TYPE } from '../constants';
6
+ import { ELEMENT_TYPE } from '../extension/constants';
7
+ import { replaceNodeId } from '../node-id/helpers';
8
+ var getRevisionChanges = function getRevisionChanges(masterContent, currentContent) {
9
+ var _generateIdMapAndIds = generateIdMapAndIds(currentContent.children),
10
+ currentContentMap = _generateIdMapAndIds.map,
11
+ currentIds = _generateIdMapAndIds.ids;
12
+ var _generateIdMapAndIds2 = generateIdMapAndIds(masterContent.children),
13
+ masterContentMap = _generateIdMapAndIds2.map,
14
+ masterIds = _generateIdMapAndIds2.ids;
15
+ var idDiffs = getIdDiffs(masterIds, currentIds);
16
+ var content = [];
17
+ idDiffs.forEach(function (idDiff) {
18
+ var value = idDiff.value,
19
+ added = idDiff.added,
20
+ removed = idDiff.removed;
21
+ if (added) {
22
+ var addedList = value.map(function (item) {
23
+ return _objectSpread(_objectSpread({}, currentContentMap[item]), {}, {
24
+ modifyType: MODIFY_TYPE.ADD
25
+ });
26
+ });
27
+ content.push.apply(content, _toConsumableArray(addedList));
28
+ } else if (removed) {
29
+ var deletedList = value.map(function (item) {
30
+ return _objectSpread(_objectSpread({}, masterContentMap[item]), {}, {
31
+ modifyType: MODIFY_TYPE.DELETE
32
+ });
33
+ });
34
+ content.push.apply(content, _toConsumableArray(deletedList));
35
+ } else {
36
+ value.forEach(function (elementId) {
37
+ if (ObjectUtils.isSameObject(masterContentMap[elementId], currentContentMap[elementId])) {
38
+ content.push(currentContentMap[elementId]);
39
+ } else {
40
+ var oldElement = masterContentMap[elementId];
41
+ var currentElement = currentContentMap[elementId];
42
+ var newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
43
+ modifyType: MODIFY_TYPE.MODIFY,
44
+ oldElement: oldElement
45
+ });
46
+ if (currentElement.type === oldElement.type) {
47
+ var elementType = currentElement.type;
48
+ if ([ELEMENT_TYPE.UNORDERED_LIST, ELEMENT_TYPE.ORDERED_LIST].includes(elementType)) {
49
+ var listContent = getRevisionChanges(oldElement, currentElement);
50
+ newElement['modifyType'] = MODIFY_TYPE.CHILDREN_MODIFY;
51
+ newElement['children'] = listContent;
52
+ }
53
+ }
54
+ content.push(newElement);
55
+ }
56
+ });
57
+ }
58
+ });
59
+ return content;
60
+ };
61
+ var getMasterChanges = function getMasterChanges(masterContent, revisionChanges) {
62
+ var canMerge = true;
63
+ var _generateIdMapAndIds3 = generateIdMapAndIds(revisionChanges),
64
+ currentContentMap = _generateIdMapAndIds3.map,
65
+ currentIds = _generateIdMapAndIds3.ids;
66
+ var _generateIdMapAndIds4 = generateIdMapAndIds(masterContent.children),
67
+ masterContentMap = _generateIdMapAndIds4.map,
68
+ masterIds = _generateIdMapAndIds4.ids;
69
+ var idDiffs = getIdDiffs(masterIds, currentIds);
70
+ var content = [];
71
+ idDiffs.forEach(function (idDiff) {
72
+ var value = idDiff.value,
73
+ added = idDiff.added,
74
+ removed = idDiff.removed;
75
+ if (added) {
76
+ value.forEach(function (elementId) {
77
+ var element = currentContentMap[elementId];
78
+ var newElement = {
79
+ id: element.id,
80
+ children: element.children,
81
+ type: element.type
82
+ };
83
+ // The content has been deleted from the master, but this branch has been modified. At this time, rebase is required, and the user needs to confirm the selected content
84
+ // ==> delete | use modification
85
+ if (element.modifyType === MODIFY_TYPE.MODIFY) {
86
+ newElement['rebaseType'] = REBASE_TYPE.DELETE_MODIFY;
87
+ content.push(newElement);
88
+ canMerge = false;
89
+ } else {
90
+ // new direct append
91
+ content.push(newElement);
92
+ }
93
+ });
94
+ } else if (removed) {
95
+ var deletedList = value.map(function (item) {
96
+ return _objectSpread({}, masterContentMap[item]);
97
+ });
98
+ content.push.apply(content, _toConsumableArray(deletedList));
99
+ } else {
100
+ value.forEach(function (elementId) {
101
+ var currentElement = currentContentMap[elementId];
102
+ var masterElement = masterContentMap[elementId];
103
+
104
+ // Unchanged
105
+ if (ObjectUtils.isSameObject(masterElement, currentElement)) {
106
+ content.push(currentElement);
107
+
108
+ // The content of the master branch is modified in the current branch, but the content of the master branch is the same as that of origin
109
+ } else if (ObjectUtils.isSameObject(masterElement, currentElement.oldElement)) {
110
+ var newElement = _objectSpread({}, currentElement);
111
+ newElement['oldElement'] && delete newElement['oldElement'];
112
+ newElement['modifyType'] && delete newElement['modifyType'];
113
+ content.push(newElement);
114
+
115
+ // Modify at the same time
116
+ } else if (currentElement.modifyType === MODIFY_TYPE.MODIFY) {
117
+ var oldMasterElement = replaceNodeId(_objectSpread(_objectSpread({}, masterElement), {}, {
118
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
119
+ origin: 'master'
120
+ }));
121
+ content.push(oldMasterElement);
122
+ var _newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
123
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
124
+ origin: 'current'
125
+ });
126
+ _newElement['modifyType'] && delete _newElement['modifyType'];
127
+ _newElement['oldElement'] && delete _newElement['oldElement'];
128
+ content.push(_newElement);
129
+ canMerge = false;
130
+
131
+ // children modify
132
+ } else if (currentElement.modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
133
+ canMerge = false;
134
+ if (currentElement.type === masterElement.type) {
135
+ var _getMasterChanges = getMasterChanges(masterElement, currentElement.children),
136
+ childrenContent = _getMasterChanges.content;
137
+ content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
138
+ children: childrenContent,
139
+ rebaseType: REBASE_TYPE.CHILDREN_MODIFY
140
+ }));
141
+ } else {
142
+ var _oldMasterElement = replaceNodeId(_objectSpread(_objectSpread({}, masterElement), {}, {
143
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
144
+ origin: 'master'
145
+ }));
146
+ content.push(_oldMasterElement);
147
+ var _newElement2 = _objectSpread(_objectSpread({}, currentElement.oldElement), {}, {
148
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
149
+ origin: 'current'
150
+ });
151
+ content.push(_newElement2);
152
+ }
153
+ } else {
154
+ var _newElement3 = _objectSpread({}, currentElement);
155
+ _newElement3['oldElement'] && delete _newElement3['oldElement'];
156
+ _newElement3['modifyType'] && delete _newElement3['modifyType'];
157
+ content.push(_newElement3);
158
+ }
159
+ });
160
+ }
161
+ });
162
+ return {
163
+ content: content,
164
+ canMerge: canMerge
165
+ };
166
+ };
167
+ export var getRebase = function getRebase(masterContent, revisionMasterContent, revisionCurrentContent) {
168
+ // master no changes, merged directly
169
+ if (masterContent.version === revisionMasterContent.version) {
170
+ return {
171
+ canMerge: true,
172
+ isNeedReplaceMaster: true,
173
+ value: revisionCurrentContent
174
+ };
175
+ }
176
+
177
+ // The revision content has not changed
178
+ if (revisionMasterContent.version === revisionCurrentContent.version) {
179
+ return {
180
+ canMerge: true,
181
+ isNeedReplaceMaster: false,
182
+ value: masterContent
183
+ };
184
+ }
185
+ var revisionChanges = getRevisionChanges(revisionMasterContent, revisionCurrentContent);
186
+ var _getMasterChanges2 = getMasterChanges(masterContent, revisionChanges),
187
+ canMerge = _getMasterChanges2.canMerge,
188
+ content = _getMasterChanges2.content;
189
+ return {
190
+ canMerge: canMerge,
191
+ isNeedReplaceMaster: true,
192
+ value: _objectSpread(_objectSpread({}, revisionCurrentContent), {}, {
193
+ children: content,
194
+ version: Math.max(masterContent.version, revisionCurrentContent.version) + 1
195
+ })
196
+ };
197
+ };
@@ -6,7 +6,8 @@ import { ELEMENT_TYPE, ADDED_STYLE, DELETED_STYLE } from '../extension/constants
6
6
  import SDocViewer from './viewer';
7
7
  import '../../assets/css/diff-viewer.css';
8
8
  var DiffViewer = function DiffViewer(_ref) {
9
- var currentContent = _ref.currentContent,
9
+ var editor = _ref.editor,
10
+ currentContent = _ref.currentContent,
10
11
  lastContent = _ref.lastContent,
11
12
  didMountCallback = _ref.didMountCallback,
12
13
  showToolbar = _ref.showToolbar,
@@ -38,6 +39,7 @@ var DiffViewer = function DiffViewer(_ref) {
38
39
  return renderElement(props, editor);
39
40
  }, []);
40
41
  return /*#__PURE__*/React.createElement(SDocViewer, {
42
+ editor: editor,
41
43
  showToolbar: showToolbar,
42
44
  showOutline: showOutline,
43
45
  document: {
@@ -1,4 +1,4 @@
1
- import React, { Fragment, useMemo } from 'react';
1
+ import React, { Fragment } from 'react';
2
2
  import { Editable, Slate } from '@seafile/slate-react';
3
3
  import { renderLeaf as _renderLeaf, renderElement as _renderElement, createDefaultEditor } from '../extension';
4
4
  import withNodeId from '../node-id';
@@ -8,16 +8,13 @@ import { usePipDecorate } from '../decorates';
8
8
  import { ArticleContainer, EditorContainer, EditorContent } from '../layout';
9
9
  import '../assets/css/simple-viewer.css';
10
10
  var SDocViewer = function SDocViewer(_ref) {
11
- var document = _ref.document,
11
+ var editor = _ref.editor,
12
+ document = _ref.document,
12
13
  customRenderLeaf = _ref.renderLeaf,
13
14
  customRenderElement = _ref.renderElement,
14
15
  showToolbar = _ref.showToolbar,
15
16
  showOutline = _ref.showOutline;
16
- var editor = useMemo(function () {
17
- var defaultEditor = createDefaultEditor();
18
- return withNodeId(defaultEditor);
19
- }, []);
20
- editor.readonly = true;
17
+ var validEditor = editor || withNodeId(createDefaultEditor());
21
18
  var slateValue = (document || generateDefaultDocContent()).children;
22
19
  var decorate = usePipDecorate(editor);
23
20
  return /*#__PURE__*/React.createElement(EditorContainer, {
@@ -29,19 +26,19 @@ var SDocViewer = function SDocViewer(_ref) {
29
26
  readonly: true,
30
27
  showOutline: showOutline
31
28
  }, /*#__PURE__*/React.createElement(Slate, {
32
- editor: editor,
29
+ editor: validEditor,
33
30
  value: slateValue
34
31
  }, /*#__PURE__*/React.createElement(ArticleContainer, {
35
- editor: editor,
32
+ editor: validEditor,
36
33
  readOnly: true
37
34
  }, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
38
35
  readOnly: true,
39
36
  placeholder: "",
40
37
  renderElement: function renderElement(props) {
41
- return (customRenderElement || _renderElement)(props, editor);
38
+ return (customRenderElement || _renderElement)(props, validEditor);
42
39
  },
43
40
  renderLeaf: function renderLeaf(props) {
44
- return (customRenderLeaf || _renderLeaf)(props, editor);
41
+ return (customRenderLeaf || _renderLeaf)(props, validEditor);
45
42
  },
46
43
  onDOMBeforeInput: function onDOMBeforeInput(event) {},
47
44
  decorate: decorate
@@ -11,14 +11,16 @@ import './style.css';
11
11
  var DocOperations = function DocOperations(_ref) {
12
12
  var isShowChanges = _ref.isShowChanges,
13
13
  changes = _ref.changes,
14
- toggleViewChanges = _ref.toggleViewChanges;
14
+ toggleViewChanges = _ref.toggleViewChanges,
15
+ publishRevision = _ref.publishRevision;
15
16
  var isSdocRevision = context.getSetting('isSdocRevision');
16
17
  return /*#__PURE__*/React.createElement("div", {
17
18
  className: "doc-ops"
18
19
  }, /*#__PURE__*/React.createElement(RevisionOperations, {
19
20
  isShowChanges: isShowChanges,
20
21
  changes: changes,
21
- toggleViewChanges: toggleViewChanges
22
+ toggleViewChanges: toggleViewChanges,
23
+ publishRevision: publishRevision
22
24
  }), /*#__PURE__*/React.createElement(CommentsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(ShareOperation, null), /*#__PURE__*/React.createElement(HistoryOperation, null), /*#__PURE__*/React.createElement(CollaboratorsOperation, null), !isSdocRevision && /*#__PURE__*/React.createElement(MoreOperations, null));
23
25
  };
24
26
  export default withTranslation('sdoc-editor')(DocOperations);
@@ -8,7 +8,8 @@ import ChangesCount from './changes-count';
8
8
  var RevisionOperations = function RevisionOperations(_ref) {
9
9
  var isShowChanges = _ref.isShowChanges,
10
10
  changes = _ref.changes,
11
- toggleViewChanges = _ref.toggleViewChanges;
11
+ toggleViewChanges = _ref.toggleViewChanges,
12
+ publishRevision = _ref.publishRevision;
12
13
  var isSdocRevision = context.getSetting('isSdocRevision');
13
14
  var isPublished = context.getSetting('isPublished');
14
15
  return /*#__PURE__*/React.createElement(React.Fragment, null, !isSdocRevision && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MoreRevisionOperations, null), /*#__PURE__*/React.createElement(Revisions, null)), isSdocRevision && isShowChanges && /*#__PURE__*/React.createElement(ChangesCount, {
@@ -16,6 +17,8 @@ var RevisionOperations = function RevisionOperations(_ref) {
16
17
  }), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
17
18
  isShowChanges: isShowChanges,
18
19
  toggleViewChanges: toggleViewChanges
19
- }), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, null));
20
+ }), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, {
21
+ publishRevision: publishRevision
22
+ }));
20
23
  };
21
24
  export default RevisionOperations;
@@ -1,21 +1,14 @@
1
1
  import React, { useCallback } from 'react';
2
+ import { useTranslation } from 'react-i18next';
2
3
  import { Button } from 'reactstrap';
3
- import { withTranslation } from 'react-i18next';
4
- import context from '../../../context';
5
- import toaster from '../../../components/toast';
6
4
  var PublishRevision = function PublishRevision(_ref) {
7
- var t = _ref.t;
8
- var repoID = context.getSetting('repoID');
9
- var siteRoot = context.getSetting('siteRoot');
5
+ var publishRevision = _ref.publishRevision;
6
+ var _useTranslation = useTranslation(),
7
+ t = _useTranslation.t;
10
8
  var publish = useCallback(function (event) {
11
9
  event.stopPropagation();
12
10
  event.nativeEvent.stopImmediatePropagation();
13
- context.publishSdocRevision().then(function (res) {
14
- var origin_file_path = res.data.origin_file_path;
15
- window.location.href = "".concat(siteRoot, "lib/").concat(repoID, "/file/").concat(origin_file_path);
16
- }).catch(function (error) {
17
- toaster.danger(t('Error'));
18
- });
11
+ publishRevision();
19
12
 
20
13
  // eslint-disable-next-line react-hooks/exhaustive-deps
21
14
  }, []);
@@ -25,4 +18,4 @@ var PublishRevision = function PublishRevision(_ref) {
25
18
  className: "ml-4"
26
19
  }, t('Publish'));
27
20
  };
28
- export default withTranslation('sdoc-editor')(PublishRevision);
21
+ export default PublishRevision;
File without changes
@@ -0,0 +1,49 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap';
4
+ import classnames from 'classnames';
5
+ import { TIP_TYPE, TIP_TITLE } from '../../constants';
6
+ import TipContent from './tip-content';
7
+ import './index.css';
8
+ var TipDialog = function TipDialog(_ref) {
9
+ var className = _ref.className,
10
+ tipType = _ref.tipType,
11
+ toggle = _ref.toggle,
12
+ submit = _ref.submit;
13
+ var _useTranslation = useTranslation(),
14
+ t = _useTranslation.t;
15
+ var closeDialog = useCallback(function () {
16
+ toggle && toggle(false);
17
+
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
19
+ }, [tipType]);
20
+ var confirmTip = useCallback(function () {
21
+ submit && submit();
22
+
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ }, []);
25
+ return /*#__PURE__*/React.createElement(Modal, {
26
+ isOpen: true,
27
+ autoFocus: false,
28
+ zIndex: 1071,
29
+ returnFocusAfterClose: false,
30
+ toggle: closeDialog,
31
+ className: classnames('sdoc-tip-dialog', className),
32
+ contentClassName: "sdoc-tip-modal"
33
+ }, /*#__PURE__*/React.createElement(ModalHeader, {
34
+ toggle: [TIP_TYPE.HAS_BEEN_REPLACED, TIP_TYPE.HAS_BEEN_PUBLISHED].includes(tipType) ? undefined : closeDialog
35
+ }, t(TIP_TITLE[tipType])), /*#__PURE__*/React.createElement(ModalBody, {
36
+ className: "sdoc-tip-body"
37
+ }, /*#__PURE__*/React.createElement(TipContent, {
38
+ tipType: tipType
39
+ })), ![TIP_TYPE.HAS_BEEN_REPLACED, TIP_TYPE.HAS_BEEN_PUBLISHED].includes(tipType) && /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
40
+ color: "secondary",
41
+ className: "mr-2",
42
+ onClick: closeDialog
43
+ }, t('Cancel')), /*#__PURE__*/React.createElement(Button, {
44
+ color: "primary",
45
+ className: "highlight-bg-color",
46
+ onClick: confirmTip
47
+ }, t('Confirm'))));
48
+ };
49
+ export default TipDialog;
@@ -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;