@seafile/sdoc-editor 0.1.141 → 0.1.142-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 +15 -0
  2. package/dist/api/seafile-api.js +27 -5
  3. package/dist/basic-sdk/assets/css/dropdown-menu.css +5 -1
  4. package/dist/basic-sdk/constants/index.js +14 -1
  5. package/dist/basic-sdk/editor/common-editor.js +45 -0
  6. package/dist/basic-sdk/editor/index.js +135 -0
  7. package/dist/basic-sdk/editor/rebase-editor/index.css +29 -0
  8. package/dist/basic-sdk/editor/rebase-editor/index.js +276 -0
  9. package/dist/basic-sdk/{slate-editor.js → editor/slate-editor.js} +21 -16
  10. package/dist/basic-sdk/extension/core/transforms/replace-node-children.js +26 -0
  11. package/dist/basic-sdk/extension/toolbar/header-toolbar/index.js +5 -1
  12. package/dist/basic-sdk/extension/toolbar/header-toolbar/insert-toolbar/index.css +5 -0
  13. package/dist/basic-sdk/socket/helpers.js +1 -0
  14. package/dist/basic-sdk/socket/socket-client.js +5 -0
  15. package/dist/basic-sdk/socket/socket-manager.js +8 -2
  16. package/dist/basic-sdk/socket/with-socket-io.js +20 -12
  17. package/dist/basic-sdk/utils/diff.js +2 -2
  18. package/dist/basic-sdk/utils/rebase.js +193 -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 +45 -0
  26. package/dist/constants/index.js +8 -1
  27. package/dist/context.js +30 -4
  28. package/dist/pages/simple-editor.js +221 -71
  29. package/package.json +1 -1
  30. package/public/locales/en/sdoc-editor.json +7 -1
  31. package/public/locales/zh_CN/sdoc-editor.json +7 -1
  32. package/dist/basic-sdk/editor.js +0 -105
@@ -12,4 +12,30 @@ export var replaceNodeChildren = function replaceNodeChildren(editor, _ref) {
12
12
  at: at.concat([0])
13
13
  }));
14
14
  });
15
+ };
16
+ export var replaceNode = function replaceNode(editor) {
17
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
18
+ at = _ref2.at,
19
+ nodes = _ref2.nodes,
20
+ insertOptions = _ref2.insertOptions,
21
+ removeOptions = _ref2.removeOptions;
22
+ Editor.withoutNormalizing(editor, function () {
23
+ Transforms.removeNodes(editor, _objectSpread({
24
+ at: at
25
+ }, removeOptions));
26
+ Transforms.insertNodes(editor, nodes, _objectSpread(_objectSpread({}, insertOptions), {}, {
27
+ at: at
28
+ }));
29
+ });
30
+ };
31
+ export var deleteNodeMark = function deleteNodeMark(editor, path, element) {
32
+ var marks = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
33
+ var newElement = _objectSpread({}, element);
34
+ marks.forEach(function (markItem) {
35
+ newElement[markItem] && delete newElement[markItem];
36
+ });
37
+ replaceNode(editor, {
38
+ at: path,
39
+ nodes: newElement
40
+ });
15
41
  };
@@ -12,6 +12,7 @@ import ClearFormatMenu from '../../plugins/clear-format/menu';
12
12
  import HistoryMenu from './redo-undo';
13
13
  import Font from '../../plugins/font/menu';
14
14
  import InsertToolbar from './insert-toolbar';
15
+ import ActiveTableMenu from '../../plugins/table/menu/active-table-menu';
15
16
  var Toolbar = function Toolbar(_ref) {
16
17
  var editor = _ref.editor,
17
18
  readonly = _ref.readonly;
@@ -53,7 +54,10 @@ var Toolbar = function Toolbar(_ref) {
53
54
  }), /*#__PURE__*/React.createElement(TextAlignMenu, {
54
55
  editor: editor,
55
56
  readonly: readonly
56
- })));
57
+ })), /*#__PURE__*/React.createElement(ActiveTableMenu, {
58
+ editor: editor,
59
+ readonly: readonly
60
+ }));
57
61
  };
58
62
  Toolbar.defaultProps = {
59
63
  readonly: false
@@ -5,6 +5,11 @@
5
5
  justify-content: space-between;
6
6
  }
7
7
 
8
+ .menu-group .menu-group-item.sdoc-insert-toolbar-btn.disabled {
9
+ width: 64px !important; /* 64: 76 - 12 */
10
+ color: #BDBDBD;
11
+ }
12
+
8
13
  .menu-group .sdoc-insert-toolbar-btn .sdoc-menu-with-dropdown-icon {
9
14
  flex: 1;
10
15
  justify-content: flex-start;
@@ -252,6 +252,7 @@ export var reExecRevertOperationList = function reExecRevertOperationList(editor
252
252
  }
253
253
  };
254
254
  export var syncRemoteOperations = function syncRemoteOperations(editor, remoteOperations) {
255
+ if (editor.isReadonly) return;
255
256
  if (remoteOperations.length === 0) return;
256
257
  Editor.withoutNormalizing(editor, function () {
257
258
  for (var i = 0; i < remoteOperations.length; i++) {
@@ -123,6 +123,10 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
123
123
  this.disconnectWithServer = function () {
124
124
  _this.socket.disconnect();
125
125
  };
126
+ this.onRebaseDocument = function (document) {
127
+ var socketManager = SocketManager.getInstance();
128
+ socketManager.rebaseContent(document);
129
+ };
126
130
  this.config = config;
127
131
  this.isReconnect = false;
128
132
  this.socket = io(config.sdocServer, {
@@ -137,6 +141,7 @@ var SocketClient = /*#__PURE__*/_createClass(function SocketClient(config) {
137
141
  this.socket.on('join-room', this.onJoinRoom);
138
142
  this.socket.on('leave-room', this.onLeaveRoom);
139
143
  this.socket.on('update-document', this.onReceiveRemoteOperations);
144
+ this.socket.on('rebase-document', this.onRebaseDocument);
140
145
  this.socket.on('update-cursor', this.receiveCursorLocation);
141
146
  this.socket.io.on('reconnect', this.onReconnect);
142
147
  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 debug from '../utils/debug';
9
9
  import { deleteCursor } from '../cursor/helper';
10
+ import { EXTERNAL_EVENT } from '../../constants';
10
11
 
11
12
  // idle --> sending --> conflict --> idle
12
13
  // --> conflict --> idle
@@ -19,13 +20,17 @@ 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.rebaseContent = function (document) {
31
+ _this.document = document;
32
+ _this.eventBus.dispatch(EXTERNAL_EVENT.REBASE_DOCUMENT, document);
33
+ };
29
34
  this.onReceiveLocalOperations = function (operations) {
30
35
  _this.pendingOperationList.push(operations);
31
36
  if (_this.pendingOperationList.length > 5) {
@@ -34,6 +39,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
34
39
  _this.sendOperations();
35
40
  };
36
41
  this.sendOperations = function () {
42
+ if (_this.editor.isReadonly) return;
37
43
  if (_this.state !== STATE.IDLE) return;
38
44
  _this.state = STATE.SENDING;
39
45
  _this.sendNextOperations();
@@ -270,7 +276,7 @@ var SocketManager = /*#__PURE__*/_createClass(function SocketManager(editor, doc
270
276
  _this.socketClient.disconnectWithServer();
271
277
  };
272
278
  this.editor = editor;
273
- this.document = document;
279
+ this.document = _document;
274
280
  this.socketClient = new SocketClient(config);
275
281
  this.pendingOperationList = []; // Two-dimensional arrays: [operations, operations, ...]
276
282
  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,26 +20,33 @@ 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
  };
44
52
  return newEditor;
@@ -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,193 @@
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
+ var getRevisionChanges = function getRevisionChanges(masterContent, currentContent) {
8
+ var _generateIdMapAndIds = generateIdMapAndIds(currentContent.children),
9
+ currentContentMap = _generateIdMapAndIds.map,
10
+ currentIds = _generateIdMapAndIds.ids;
11
+ var _generateIdMapAndIds2 = generateIdMapAndIds(masterContent.children),
12
+ masterContentMap = _generateIdMapAndIds2.map,
13
+ masterIds = _generateIdMapAndIds2.ids;
14
+ var idDiffs = getIdDiffs(masterIds, currentIds);
15
+ var content = [];
16
+ idDiffs.forEach(function (idDiff) {
17
+ var value = idDiff.value,
18
+ added = idDiff.added,
19
+ removed = idDiff.removed;
20
+ if (added) {
21
+ var addedList = value.map(function (item) {
22
+ return _objectSpread(_objectSpread({}, currentContentMap[item]), {}, {
23
+ modifyType: MODIFY_TYPE.ADD
24
+ });
25
+ });
26
+ content.push.apply(content, _toConsumableArray(addedList));
27
+ } else if (removed) {
28
+ var deletedList = value.map(function (item) {
29
+ return _objectSpread(_objectSpread({}, masterContentMap[item]), {}, {
30
+ modifyType: MODIFY_TYPE.DELETE
31
+ });
32
+ });
33
+ content.push.apply(content, _toConsumableArray(deletedList));
34
+ } else {
35
+ value.forEach(function (elementId) {
36
+ if (ObjectUtils.isSameObject(masterContentMap[elementId], currentContentMap[elementId])) {
37
+ content.push(currentContentMap[elementId]);
38
+ } else {
39
+ var oldElement = masterContentMap[elementId];
40
+ var currentElement = currentContentMap[elementId];
41
+ var newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
42
+ modifyType: MODIFY_TYPE.MODIFY,
43
+ oldElement: oldElement
44
+ });
45
+ if (currentElement.type === oldElement.type) {
46
+ var elementType = currentElement.type;
47
+ if ([ELEMENT_TYPE.UNORDERED_LIST, ELEMENT_TYPE.ORDERED_LIST].includes(elementType)) {
48
+ var listContent = getRevisionChanges(oldElement, currentElement);
49
+ newElement['modifyType'] = MODIFY_TYPE.CHILDREN_MODIFY;
50
+ newElement['children'] = listContent;
51
+ }
52
+ }
53
+ content.push(newElement);
54
+ }
55
+ });
56
+ }
57
+ });
58
+ return content;
59
+ };
60
+ var getMasterChanges = function getMasterChanges(masterContent, revisionChanges) {
61
+ var canMerge = true;
62
+ var _generateIdMapAndIds3 = generateIdMapAndIds(revisionChanges),
63
+ currentContentMap = _generateIdMapAndIds3.map,
64
+ currentIds = _generateIdMapAndIds3.ids;
65
+ var _generateIdMapAndIds4 = generateIdMapAndIds(masterContent.children),
66
+ masterContentMap = _generateIdMapAndIds4.map,
67
+ masterIds = _generateIdMapAndIds4.ids;
68
+ var idDiffs = getIdDiffs(masterIds, currentIds);
69
+ var content = [];
70
+ idDiffs.forEach(function (idDiff) {
71
+ var value = idDiff.value,
72
+ added = idDiff.added,
73
+ removed = idDiff.removed;
74
+ if (added) {
75
+ value.forEach(function (elementId) {
76
+ var element = currentContentMap[elementId];
77
+ var newElement = {
78
+ id: element.id,
79
+ children: element.children,
80
+ type: element.type
81
+ };
82
+ // 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
83
+ // ==> delete | use modification
84
+ if (element.modifyType === MODIFY_TYPE.MODIFY) {
85
+ newElement['rebaseType'] = REBASE_TYPE.DELETE_MODIFY;
86
+ content.push(newElement);
87
+ canMerge = false;
88
+ } else {
89
+ // new direct append
90
+ content.push(newElement);
91
+ }
92
+ });
93
+ } else if (removed) {
94
+ var deletedList = value.map(function (item) {
95
+ return _objectSpread({}, masterContentMap[item]);
96
+ });
97
+ content.push.apply(content, _toConsumableArray(deletedList));
98
+ } else {
99
+ value.forEach(function (elementId) {
100
+ var currentElement = currentContentMap[elementId];
101
+ var masterElement = masterContentMap[elementId];
102
+
103
+ // Unchanged
104
+ if (ObjectUtils.isSameObject(masterElement, currentElement)) {
105
+ content.push(currentElement);
106
+
107
+ // 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
108
+ } else if (ObjectUtils.isSameObject(masterElement, currentElement.oldElement)) {
109
+ var newElement = _objectSpread({}, currentElement);
110
+ newElement['oldElement'] && delete newElement['oldElement'];
111
+ newElement['modifyType'] && delete newElement['modifyType'];
112
+ content.push(newElement);
113
+
114
+ // Modify at the same time
115
+ } else if (currentElement.modifyType === MODIFY_TYPE.MODIFY) {
116
+ content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
117
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
118
+ origin: 'master'
119
+ }));
120
+ var _newElement = _objectSpread(_objectSpread({}, currentElement), {}, {
121
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
122
+ origin: 'current'
123
+ });
124
+ _newElement['modifyType'] && delete _newElement['modifyType'];
125
+ _newElement['oldElement'] && delete _newElement['oldElement'];
126
+ content.push(_newElement);
127
+ canMerge = false;
128
+
129
+ // children modify
130
+ } else if (currentElement.modifyType === MODIFY_TYPE.CHILDREN_MODIFY) {
131
+ canMerge = false;
132
+ if (currentElement.type === masterElement.type) {
133
+ var _getMasterChanges = getMasterChanges(masterElement, currentElement.children),
134
+ childrenContent = _getMasterChanges.content;
135
+ content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
136
+ children: childrenContent,
137
+ rebaseType: REBASE_TYPE.CHILDREN_MODIFY
138
+ }));
139
+ } else {
140
+ content.push(_objectSpread(_objectSpread({}, masterElement), {}, {
141
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
142
+ origin: 'master'
143
+ }));
144
+ var _newElement2 = _objectSpread(_objectSpread({}, currentElement.oldElement), {}, {
145
+ rebaseType: REBASE_TYPE.MODIFY_MODIFY,
146
+ origin: 'current'
147
+ });
148
+ content.push(_newElement2);
149
+ }
150
+ } else {
151
+ var _newElement3 = _objectSpread({}, currentElement);
152
+ _newElement3['oldElement'] && delete _newElement3['oldElement'];
153
+ _newElement3['modifyType'] && delete _newElement3['modifyType'];
154
+ content.push(_newElement3);
155
+ }
156
+ });
157
+ }
158
+ });
159
+ return {
160
+ content: content,
161
+ canMerge: canMerge
162
+ };
163
+ };
164
+ export var getRebase = function getRebase(masterContent, revisionMasterContent, revisionCurrentContent) {
165
+ // master no changes, merged directly
166
+ if (masterContent.version === revisionMasterContent.version) {
167
+ return {
168
+ canMerge: true,
169
+ isNeedReplaceMaster: true,
170
+ value: revisionCurrentContent
171
+ };
172
+ }
173
+
174
+ // The revision content has not changed
175
+ if (revisionMasterContent.version === revisionCurrentContent.version) {
176
+ return {
177
+ canMerge: true,
178
+ isNeedReplaceMaster: false,
179
+ value: masterContent
180
+ };
181
+ }
182
+ var revisionChanges = getRevisionChanges(revisionMasterContent, revisionCurrentContent);
183
+ var _getMasterChanges2 = getMasterChanges(masterContent, revisionChanges),
184
+ canMerge = _getMasterChanges2.canMerge,
185
+ content = _getMasterChanges2.content;
186
+ return {
187
+ canMerge: canMerge,
188
+ isNeedReplaceMaster: true,
189
+ value: _objectSpread(_objectSpread({}, revisionCurrentContent), {}, {
190
+ children: content
191
+ })
192
+ };
193
+ };
@@ -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,20 @@ 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,
16
+ mode = _ref.mode,
17
+ abortRebase = _ref.abortRebase;
15
18
  var isSdocRevision = context.getSetting('isSdocRevision');
16
19
  return /*#__PURE__*/React.createElement("div", {
17
20
  className: "doc-ops"
18
21
  }, /*#__PURE__*/React.createElement(RevisionOperations, {
19
22
  isShowChanges: isShowChanges,
20
23
  changes: changes,
21
- toggleViewChanges: toggleViewChanges
24
+ mode: mode,
25
+ toggleViewChanges: toggleViewChanges,
26
+ publishRevision: publishRevision,
27
+ abortRebase: abortRebase
22
28
  }), /*#__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
29
  };
24
30
  export default withTranslation('sdoc-editor')(DocOperations);
@@ -5,17 +5,25 @@ import ViewChanges from './view-changes';
5
5
  import MoreRevisionOperations from './more-revision-operations';
6
6
  import Revisions from './revisions';
7
7
  import ChangesCount from './changes-count';
8
+ import { MODE } from '../../../constants';
8
9
  var RevisionOperations = function RevisionOperations(_ref) {
9
10
  var isShowChanges = _ref.isShowChanges,
10
11
  changes = _ref.changes,
11
- toggleViewChanges = _ref.toggleViewChanges;
12
+ toggleViewChanges = _ref.toggleViewChanges,
13
+ publishRevision = _ref.publishRevision,
14
+ mode = _ref.mode,
15
+ abortRebase = _ref.abortRebase;
12
16
  var isSdocRevision = context.getSetting('isSdocRevision');
13
17
  var isPublished = context.getSetting('isPublished');
14
18
  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, {
15
19
  changes: changes
16
- }), isSdocRevision && /*#__PURE__*/React.createElement(ViewChanges, {
20
+ }), isSdocRevision && mode !== MODE.REBASE && /*#__PURE__*/React.createElement(ViewChanges, {
17
21
  isShowChanges: isShowChanges,
18
22
  toggleViewChanges: toggleViewChanges
19
- }), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, null));
23
+ }), isSdocRevision && !isPublished && /*#__PURE__*/React.createElement(PublishRevision, {
24
+ publishRevision: publishRevision,
25
+ mode: mode,
26
+ abortRebase: abortRebase
27
+ }));
20
28
  };
21
29
  export default RevisionOperations;
@@ -1,28 +1,31 @@
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';
4
+ import { MODE } from '../../../constants';
6
5
  var PublishRevision = function PublishRevision(_ref) {
7
- var t = _ref.t;
8
- var repoID = context.getSetting('repoID');
9
- var siteRoot = context.getSetting('siteRoot');
6
+ var mode = _ref.mode,
7
+ publishRevision = _ref.publishRevision,
8
+ abortRebase = _ref.abortRebase;
9
+ var _useTranslation = useTranslation(),
10
+ t = _useTranslation.t;
10
11
  var publish = useCallback(function (event) {
11
12
  event.stopPropagation();
12
13
  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
- });
14
+ publishRevision();
19
15
 
20
16
  // eslint-disable-next-line react-hooks/exhaustive-deps
21
17
  }, []);
18
+ if (mode === MODE.REBASE) {
19
+ return /*#__PURE__*/React.createElement(Button, {
20
+ color: "success",
21
+ onClick: abortRebase,
22
+ className: "ml-4"
23
+ }, t('Abort'));
24
+ }
22
25
  return /*#__PURE__*/React.createElement(Button, {
23
26
  color: "success",
24
27
  onClick: publish,
25
28
  className: "ml-4"
26
29
  }, t('Publish'));
27
30
  };
28
- export default withTranslation('sdoc-editor')(PublishRevision);
31
+ export default PublishRevision;
File without changes
@@ -0,0 +1,45 @@
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 './index.css';
6
+ var TipDialog = function TipDialog(_ref) {
7
+ var title = _ref.title,
8
+ children = _ref.children,
9
+ className = _ref.className,
10
+ toggle = _ref.toggle,
11
+ submit = _ref.submit;
12
+ var _useTranslation = useTranslation(),
13
+ t = _useTranslation.t;
14
+ var closeDialog = useCallback(function () {
15
+ toggle && toggle(false);
16
+
17
+ // eslint-disable-next-line react-hooks/exhaustive-deps
18
+ }, []);
19
+ var confirmTip = useCallback(function () {
20
+ submit && submit();
21
+
22
+ // eslint-disable-next-line react-hooks/exhaustive-deps
23
+ }, []);
24
+ return /*#__PURE__*/React.createElement(Modal, {
25
+ isOpen: true,
26
+ autoFocus: false,
27
+ zIndex: 1071,
28
+ returnFocusAfterClose: false,
29
+ className: classnames('sdoc-tip-dialog', className),
30
+ contentClassName: "sdoc-tip-modal"
31
+ }, /*#__PURE__*/React.createElement(ModalHeader, {
32
+ toggle: closeDialog
33
+ }, title), /*#__PURE__*/React.createElement(ModalBody, {
34
+ className: "sdoc-tip-body"
35
+ }, children), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
36
+ color: "secondary",
37
+ className: "mr-2",
38
+ onClick: closeDialog
39
+ }, t('Cancel')), /*#__PURE__*/React.createElement(Button, {
40
+ color: "primary",
41
+ className: "highlight-bg-color",
42
+ onClick: confirmTip
43
+ }, t('Confirm'))));
44
+ };
45
+ export default TipDialog;
@@ -2,5 +2,12 @@ export var EXTERNAL_EVENT = {
2
2
  INTERNAL_LINK_CLICK: 'internal_link_click',
3
3
  TOGGLE_STAR: 'toggle_star',
4
4
  UNMARK_AS_DRAFT: 'unmark_as_draft',
5
- SHARE_SDOC: 'share_sdoc'
5
+ SHARE_SDOC: 'share_sdoc',
6
+ REBASE_DOCUMENT: 'rebase_document'
7
+ };
8
+ export var MODE = {
9
+ DIFF_VIEWER: 'diff-viewer',
10
+ VIEWER: 'viewer',
11
+ EDITOR: 'editor',
12
+ REBASE: 'rebase'
6
13
  };