@seafile/seafile-editor 0.3.76
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.
- package/README.md +119 -0
- package/TODO.md +55 -0
- package/dist/components/add-formula-dialog.js +135 -0
- package/dist/components/add-image-dialog.js +78 -0
- package/dist/components/add-link-dialog.js +148 -0
- package/dist/components/comment-dialog.js +107 -0
- package/dist/components/comment-panel.js +452 -0
- package/dist/components/context-menu.js +112 -0
- package/dist/components/detail-list-view.js +119 -0
- package/dist/components/generate-share-link.js +412 -0
- package/dist/components/internal-link-dialog.js +96 -0
- package/dist/components/loading.js +32 -0
- package/dist/components/markdown-lint.js +87 -0
- package/dist/components/modal-portal.js +46 -0
- package/dist/components/outline.js +130 -0
- package/dist/components/participants-list.js +126 -0
- package/dist/components/related-files-list.js +75 -0
- package/dist/components/shortcut-dialog.js +167 -0
- package/dist/components/side-panel.js +175 -0
- package/dist/components/toast/alert.js +150 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/toast.js +179 -0
- package/dist/components/toast/toastManager.js +158 -0
- package/dist/components/toast/toaster.js +76 -0
- package/dist/components/toolbar.js +235 -0
- package/dist/components/topbar-component/button-group.js +31 -0
- package/dist/components/topbar-component/editor-toolbar.js +545 -0
- package/dist/components/topbar-component/file-info.js +65 -0
- package/dist/components/topbar-component/header-list.js +128 -0
- package/dist/components/topbar-component/icon-button.js +99 -0
- package/dist/components/topbar-component/insert-file.js +67 -0
- package/dist/components/topbar-component/table-toolbar.js +175 -0
- package/dist/components/topbar-component/upload-img.js +122 -0
- package/dist/components/user-help.js +205 -0
- package/dist/css/diff-viewer.css +105 -0
- package/dist/css/history-viewer.css +104 -0
- package/dist/css/keyboard-shortcuts.css +59 -0
- package/dist/css/layout.css +110 -0
- package/dist/css/markdown-viewer-slate/file-tags-list.css +76 -0
- package/dist/css/markdown-viewer.css +69 -0
- package/dist/css/plaineditor/markdown-editor.css +12 -0
- package/dist/css/react-mentions-default-style.js +72 -0
- package/dist/css/related-files-list.css +56 -0
- package/dist/css/richeditor/comments-list.css +184 -0
- package/dist/css/richeditor/detail-list-view.css +114 -0
- package/dist/css/richeditor/document-info.css +57 -0
- package/dist/css/richeditor/formula.css +19 -0
- package/dist/css/richeditor/image.css +141 -0
- package/dist/css/richeditor/link.css +7 -0
- package/dist/css/richeditor/navbar-imgbutton.css +79 -0
- package/dist/css/richeditor/participants-list.css +22 -0
- package/dist/css/richeditor/rich-editor-main.css +42 -0
- package/dist/css/richeditor/right-panel.css +84 -0
- package/dist/css/richeditor/side-panel.css +190 -0
- package/dist/css/richeditor/table.css +57 -0
- package/dist/css/richeditor/textlink-hovermenu.css +47 -0
- package/dist/css/richeditor/tree-view.css +67 -0
- package/dist/css/topbar.css +400 -0
- package/dist/editor/code-highlight-package.js +27 -0
- package/dist/editor/controller/block-element-controller.js +376 -0
- package/dist/editor/controller/inline-element-controller.js +129 -0
- package/dist/editor/controller/normalize-controller.js +107 -0
- package/dist/editor/controller/shortcut-controller.js +394 -0
- package/dist/editor/controller/void-element-controller.js +12 -0
- package/dist/editor/custom/custom.js +17 -0
- package/dist/editor/custom/get-event-transfer.js +34 -0
- package/dist/editor/custom/getNodesByTypeAtRange.js +69 -0
- package/dist/editor/custom/insertNodes.js +140 -0
- package/dist/editor/custom/is-empty-paragraph.js +13 -0
- package/dist/editor/custom/set-event-transfer.js +31 -0
- package/dist/editor/custom/split-nodes-at-point.js +162 -0
- package/dist/editor/custom/unwrap-node-by-type-at-range.js +81 -0
- package/dist/editor/editor-component/check-list-item.js +64 -0
- package/dist/editor/editor-component/code-block.js +150 -0
- package/dist/editor/editor-component/formula.js +79 -0
- package/dist/editor/editor-component/image.js +215 -0
- package/dist/editor/editor-component/link.js +11 -0
- package/dist/editor/editor-component/table.js +172 -0
- package/dist/editor/editor-component/textlink-hovermenu.js +136 -0
- package/dist/editor/editor-plugin.js +249 -0
- package/dist/editor/editor-utils/block-element-utils/blockquote-utils.js +96 -0
- package/dist/editor/editor-utils/block-element-utils/code-utils.js +162 -0
- package/dist/editor/editor-utils/block-element-utils/formula-utils.js +58 -0
- package/dist/editor/editor-utils/block-element-utils/index.js +38 -0
- package/dist/editor/editor-utils/block-element-utils/list-utils.js +398 -0
- package/dist/editor/editor-utils/block-element-utils/table-utils.js +418 -0
- package/dist/editor/editor-utils/common-editor-utils.js +587 -0
- package/dist/editor/editor-utils/inline-element-utils/index.js +95 -0
- package/dist/editor/editor-utils/mark-utils.js +25 -0
- package/dist/editor/editor-utils/range-utils.js +9 -0
- package/dist/editor/editor-utils/selection-utils.js +33 -0
- package/dist/editor/editor-utils/text-utils.js +130 -0
- package/dist/editor/editor.js +66 -0
- package/dist/editor/element-model/blockquote.js +16 -0
- package/dist/editor/element-model/image.js +19 -0
- package/dist/editor/element-model/link.js +19 -0
- package/dist/editor/element-model/table.js +50 -0
- package/dist/editor/element-model/text.js +13 -0
- package/dist/editor/load-script.js +83 -0
- package/dist/editor/plain-markdown-editor.js +324 -0
- package/dist/editor/rich-markdown-editor.js +580 -0
- package/dist/editor/seafile-editor.js +326 -0
- package/dist/editor/simple-editor.js +245 -0
- package/dist/editor-api.js +261 -0
- package/dist/index.css +97 -0
- package/dist/lib/slate-hyperscript/creators.js +263 -0
- package/dist/lib/slate-hyperscript/hyperscript.js +92 -0
- package/dist/lib/slate-hyperscript/index.js +3 -0
- package/dist/lib/slate-hyperscript/tokens.js +102 -0
- package/dist/lib/unified/index.js +470 -0
- package/dist/lib/vfile/core.js +172 -0
- package/dist/lib/vfile/index.js +48 -0
- package/dist/seafile-editor-chooser.js +45 -0
- package/dist/seafile-markdown-editor.js +301 -0
- package/dist/seafile-markdown-viewer.js +79 -0
- package/dist/seafile-simple-editor.js +56 -0
- package/dist/utils/copy-to-clipboard.js +47 -0
- package/dist/utils/deserialize-html.js +282 -0
- package/dist/utils/diff/compare-strings.js +46 -0
- package/dist/utils/diff/diff.js +855 -0
- package/dist/utils/diff/index.js +2 -0
- package/dist/utils/render-slate.js +219 -0
- package/dist/utils/seafile-markdown2html.js +62 -0
- package/dist/utils/slate2markdown/deserialize.js +689 -0
- package/dist/utils/slate2markdown/index.js +3 -0
- package/dist/utils/slate2markdown/serialize.js +407 -0
- package/dist/utils/utils.js +28 -0
- package/dist/viewer/diff-viewer.js +98 -0
- package/dist/viewer/markdown-viewer.js +139 -0
- package/dist/viewer/slate-viewer.js +73 -0
- package/dist/viewer/viewer-formula.js +67 -0
- package/dist/viewer/viewer-image.js +93 -0
- package/dist/viewer/viewer-outline.js +118 -0
- package/package.json +215 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +45 -0
- package/public/locales/cs/seafile-editor.json +169 -0
- package/public/locales/de/seafile-editor.json +169 -0
- package/public/locales/en/seafile-editor.json +222 -0
- package/public/locales/es/seafile-editor.json +169 -0
- package/public/locales/es-AR/seafile-editor.json +169 -0
- package/public/locales/es-MX/seafile-editor.json +169 -0
- package/public/locales/fr/seafile-editor.json +169 -0
- package/public/locales/it/seafile-editor.json +169 -0
- package/public/locales/ru/seafile-editor.json +169 -0
- package/public/locales/zh-CN/seafile-editor.json +219 -0
- package/public/manifest.json +15 -0
- package/public/media/scripts/mathjax/tex-svg.js +1 -0
- package/public/media/seafile-editor-font/iconfont.eot +0 -0
- package/public/media/seafile-editor-font/iconfont.svg +164 -0
- package/public/media/seafile-editor-font/iconfont.ttf +0 -0
- package/public/media/seafile-editor-font/iconfont.woff +0 -0
- package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
- package/public/media/seafile-editor-font.css +201 -0
- package/public/media/seafile-logo.png +0 -0
- package/public/media/seafile-ui.css +11169 -0
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import ToolBar from '../components/toolbar';
|
|
8
|
+
import { withTranslation } from 'react-i18next';
|
|
9
|
+
import { renderNode, renderLeaf, EditorUtils, decorationNode } from './editor-utils/common-editor-utils';
|
|
10
|
+
import { createEditor, Node, Editor, Range } from 'slate';
|
|
11
|
+
import { withHistory } from 'slate-history';
|
|
12
|
+
import { serialize } from '../utils/slate2markdown/index';
|
|
13
|
+
import { Editable, withReact, Slate, ReactEditor } from '@seafile/slate-react';
|
|
14
|
+
import { isRangeCollapsed } from './editor-utils/range-utils';
|
|
15
|
+
import ModalPortal from '../components/modal-portal';
|
|
16
|
+
import TextLinkHoverMenu from './editor-component/textlink-hovermenu';
|
|
17
|
+
import ContextMenu from '../components/context-menu';
|
|
18
|
+
import withBlock from './controller/block-element-controller';
|
|
19
|
+
import withInline from './controller/inline-element-controller';
|
|
20
|
+
import withVoid from './controller/void-element-controller';
|
|
21
|
+
import withMarkdownShortcut from './controller/shortcut-controller';
|
|
22
|
+
import normalizeNode from './controller/normalize-controller';
|
|
23
|
+
import Plugin from './editor-plugin';
|
|
24
|
+
import TableUtils from '../editor/editor-utils/block-element-utils/table-utils';
|
|
25
|
+
import UserHelpDialog from '../components/user-help';
|
|
26
|
+
import CommentDialog from '../components/comment-dialog';
|
|
27
|
+
import SidePanel from '../components/side-panel';
|
|
28
|
+
import toaster from '../components/toast';
|
|
29
|
+
import '../css/richeditor/right-panel.css';
|
|
30
|
+
import '../css/richeditor/side-panel.css';
|
|
31
|
+
import '../css/richeditor/navbar-imgbutton.css';
|
|
32
|
+
import '../css/richeditor/textlink-hovermenu.css';
|
|
33
|
+
import '../css/richeditor/comments-list.css';
|
|
34
|
+
import '../css/richeditor/image.css';
|
|
35
|
+
import '../css/richeditor/link.css';
|
|
36
|
+
import '../css/richeditor/tree-view.css';
|
|
37
|
+
|
|
38
|
+
var SimpleEditor = /*#__PURE__*/function (_React$Component) {
|
|
39
|
+
_inherits(SimpleEditor, _React$Component);
|
|
40
|
+
|
|
41
|
+
var _super = _createSuper(SimpleEditor);
|
|
42
|
+
|
|
43
|
+
function SimpleEditor(props) {
|
|
44
|
+
var _this;
|
|
45
|
+
|
|
46
|
+
_classCallCheck(this, SimpleEditor);
|
|
47
|
+
|
|
48
|
+
_this = _super.call(this, props);
|
|
49
|
+
|
|
50
|
+
_this.getDomNodeByPath = function (path) {
|
|
51
|
+
var node,
|
|
52
|
+
parent = document.querySelector('.editor-component');
|
|
53
|
+
|
|
54
|
+
while (typeof path[0] === 'number' && parent) {
|
|
55
|
+
node = parent.children[path[0]];
|
|
56
|
+
path.shift();
|
|
57
|
+
parent = node;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return node;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
_this.setBtnPosition = function () {
|
|
64
|
+
if (!_this.state.showCommentBtn) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (_this.timmer) return;
|
|
69
|
+
_this.timmer = setTimeout(function () {
|
|
70
|
+
var selection = _this.editor.selection;
|
|
71
|
+
|
|
72
|
+
if (!selection || Range.isCollapsed(selection)) {
|
|
73
|
+
var _style = _this.refs.commentbtn.style;
|
|
74
|
+
_style.top = '-1000px';
|
|
75
|
+
clearTimeout(_this.timmer);
|
|
76
|
+
_this.timmer = null;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var focusNodePath = selection.anchor.path.slice();
|
|
81
|
+
focusNodePath.pop();
|
|
82
|
+
|
|
83
|
+
var focusNode = _this.getDomNodeByPath(focusNodePath);
|
|
84
|
+
|
|
85
|
+
var style = _this.refs.commentbtn.style;
|
|
86
|
+
style.right = '40px';
|
|
87
|
+
|
|
88
|
+
if (focusNode) {
|
|
89
|
+
style.top = "".concat(focusNode.offsetTop, "px");
|
|
90
|
+
} else {
|
|
91
|
+
style.top = '-1000px';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
clearTimeout(_this.timmer);
|
|
95
|
+
_this.timmer = null;
|
|
96
|
+
}, 40);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
_this.initialSidePanel = function () {
|
|
100
|
+
var mainPanelWidth = _this.getCookie('md-editor-main-panel-width');
|
|
101
|
+
|
|
102
|
+
if (mainPanelWidth) _this.setState({
|
|
103
|
+
mainPanelWidth: mainPanelWidth * 1
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
var isShowSidePanel = _this.getCookie('md-editor-show-side-panel');
|
|
107
|
+
|
|
108
|
+
if (isShowSidePanel === 'true') {
|
|
109
|
+
_this.setState({
|
|
110
|
+
isShowSidePanel: true
|
|
111
|
+
});
|
|
112
|
+
} else if (isShowSidePanel === 'false') {
|
|
113
|
+
_this.setState({
|
|
114
|
+
isShowSidePanel: false
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
_this.scrollToNode = function (node) {
|
|
120
|
+
var editor = document.querySelector('.editor-component');
|
|
121
|
+
var element = editor.childNodes[node.path[0]];
|
|
122
|
+
|
|
123
|
+
_this.refs.editorContainer.scrollTo(0, element.offsetTop);
|
|
124
|
+
|
|
125
|
+
window.location.hash = encodeURI(node.children[0].text);
|
|
126
|
+
Editor.select(_this.editor, node.path);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
_this.showHelpDialog = function () {
|
|
130
|
+
_this.setState({
|
|
131
|
+
isShowSidePanel: false,
|
|
132
|
+
isShowHelpDialog: true
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
_this.hideHelpDialog = function () {
|
|
137
|
+
_this.setState({
|
|
138
|
+
isShowHelpDialog: false
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
_this.insertRepoImage = function (event) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
if (_this.props.readOnly) return;
|
|
145
|
+
_this.props.openDialogs && _this.props.openDialogs('insert_repo_image');
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
_this.onResizeMouseUp = function (event) {
|
|
149
|
+
if (_this.state.resizeFlag) {
|
|
150
|
+
_this.setState({
|
|
151
|
+
resizeFlag: false
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
_this.setCookie('md-editor-main-panel-width', _this.state.mainPanelWidth);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
_this.onResizeMouseDown = function (event) {
|
|
159
|
+
_this.setState({
|
|
160
|
+
resizeFlag: true
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
_this.onResizeMouseMove = function (event) {
|
|
165
|
+
var mainPanelWidth = _this.state.mainPanelWidth + event.nativeEvent.movementX / event.view.innerWidth * 100;
|
|
166
|
+
|
|
167
|
+
if (mainPanelWidth >= 82 || mainPanelWidth <= 30) {
|
|
168
|
+
_this.setState({
|
|
169
|
+
resizeFlag: false
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
_this.setState({
|
|
176
|
+
mainPanelWidth: mainPanelWidth
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
_this.toggleSidePanel = function () {
|
|
181
|
+
if (_this.state.isShowSidePanel) {
|
|
182
|
+
_this.setState({
|
|
183
|
+
isShowSidePanel: false
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
_this.setCookie('md-editor-show-side-panel', 'false');
|
|
187
|
+
} else {
|
|
188
|
+
_this.setState({
|
|
189
|
+
isShowSidePanel: true
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
_this.setCookie('md-editor-show-side-panel', 'true');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
_this.setState({
|
|
196
|
+
isShowHelpDialog: false
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
_this.handleCommentOpen = function () {
|
|
201
|
+
_this.setState({
|
|
202
|
+
mainPanelWidth: 70,
|
|
203
|
+
isShowHelpDialog: false
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
_this.setCookie = function (key, value) {
|
|
208
|
+
document.cookie = key + '=' + value + '; ';
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
_this.onSave = function (event) {
|
|
212
|
+
_this.props.onSave();
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
_this.insertRepoFile = function () {
|
|
216
|
+
if (_this.props.readOnly) return;
|
|
217
|
+
_this.editorSelection = window.editor.selection;
|
|
218
|
+
_this.props.openDialogs && _this.props.openDialogs('insert_file');
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
_this.onCommentAdded = function () {
|
|
222
|
+
_this.toggleCommentDialog();
|
|
223
|
+
|
|
224
|
+
_this.setState({
|
|
225
|
+
relistComment: _this.state.relistComment + 1
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
_this.toggleCommentBtn = function (value) {
|
|
230
|
+
_this.setState({
|
|
231
|
+
showCommentBtn: value
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
_this.addComment = function (e) {
|
|
236
|
+
e.stopPropagation();
|
|
237
|
+
|
|
238
|
+
_this.getQuote();
|
|
239
|
+
|
|
240
|
+
_this.toggleCommentDialog();
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
_this.toggleCommentDialog = function () {
|
|
244
|
+
_this.setState({
|
|
245
|
+
showCommentDialog: !_this.state.showCommentDialog
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
_this.getQuote = function () {
|
|
250
|
+
_this.quote = serialize(Editor.fragment(_this.editor, _this.editor.selection));
|
|
251
|
+
|
|
252
|
+
_this.setState({
|
|
253
|
+
commentPosition: _this.editor.selection.anchor.path
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
_this.onChange = function (value) {
|
|
258
|
+
_this.setState({
|
|
259
|
+
value: value
|
|
260
|
+
}); // hide context menu when content change
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
if (_this.state.isShowContextMenu === true) {
|
|
264
|
+
_this.setState({
|
|
265
|
+
isShowContextMenu: false
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
_this.contextMenuPosition = {};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
_this.props.onChange(value, _this.editor.operations);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
_this.foucsEditor = function () {
|
|
275
|
+
_this.editorRef.firstChild.focus();
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
_this.onToggleLinkDialog = function () {
|
|
279
|
+
_this.setState({
|
|
280
|
+
isShowLinkDialog: !_this.state.isShowLinkDialog
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
_this.onToggleFormulaDialog = function () {
|
|
285
|
+
_this.setState({
|
|
286
|
+
isShowFormulaDialog: !_this.state.isShowFormulaDialog
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
_this.onToggleImageDialog = function () {
|
|
291
|
+
_this.setState({
|
|
292
|
+
isShowImageDialog: !_this.state.isShowImageDialog
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
_this.getCookie = function (key) {
|
|
297
|
+
var name = key + '=';
|
|
298
|
+
var ca = document.cookie.split(';');
|
|
299
|
+
|
|
300
|
+
for (var i = 0; i < ca.length; i++) {
|
|
301
|
+
var c = ca[i].trim();
|
|
302
|
+
|
|
303
|
+
if (c.indexOf(name) === 0) {
|
|
304
|
+
return c.substring(name.length, c.length);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return '';
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
_this.addComment = function (e) {
|
|
312
|
+
e.stopPropagation();
|
|
313
|
+
|
|
314
|
+
_this.getQuote();
|
|
315
|
+
|
|
316
|
+
_this.toggleCommentDialog();
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
_this.scrollToQuote = function (path) {
|
|
320
|
+
if (!path) return;
|
|
321
|
+
var editor = _this.editor;
|
|
322
|
+
var node = editor.children[path[0]];
|
|
323
|
+
var element = ReactEditor.toDOMNode(editor, node);
|
|
324
|
+
|
|
325
|
+
_this.refs.editorContainer.scrollTo(0, element.offsetTop);
|
|
326
|
+
|
|
327
|
+
Editor.select(_this.editor, path);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
_this.onContextMenu = function (event) {
|
|
331
|
+
if (_this.tableUtils.isInTable()) {
|
|
332
|
+
event.preventDefault();
|
|
333
|
+
_this.contextMenuPosition = {
|
|
334
|
+
left: event.clientX,
|
|
335
|
+
top: event.clientY
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
_this.setState({
|
|
339
|
+
isShowContextMenu: !_this.state.isShowContextMenu
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
_this.addLink = function (fileName, url, isImage) {
|
|
345
|
+
if (isImage) {
|
|
346
|
+
_this.editorUtils.insertImage({
|
|
347
|
+
url: url,
|
|
348
|
+
selection: _this.editorSelection
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
_this.editorUtils.insertLink({
|
|
355
|
+
text: fileName,
|
|
356
|
+
url: url,
|
|
357
|
+
selection: _this.editorSelection
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
_this.editor = normalizeNode(withMarkdownShortcut(withVoid(withBlock(withInline(withHistory(withReact(createEditor())))))));
|
|
362
|
+
_this.editor.editorApi = props.editorApi;
|
|
363
|
+
_this.editor.onSave = props.onSave;
|
|
364
|
+
window.editor = _this.editor;
|
|
365
|
+
_this.editorUtils = new EditorUtils(_this.editor);
|
|
366
|
+
_this.tableUtils = new TableUtils(_this.editor);
|
|
367
|
+
_this.plugin = new Plugin(_this.editor);
|
|
368
|
+
_this.editorRef = null;
|
|
369
|
+
_this.timmer = null;
|
|
370
|
+
_this.contextMenuPosition = {};
|
|
371
|
+
_this.state = {
|
|
372
|
+
value: props.value,
|
|
373
|
+
leftNavMode: 'files',
|
|
374
|
+
mainPanelWidth: 80,
|
|
375
|
+
resizeFlag: false,
|
|
376
|
+
isShowHelpDialog: false,
|
|
377
|
+
isShowSidePanel: false,
|
|
378
|
+
isShowLinkDialog: false,
|
|
379
|
+
isShowImageDialog: false,
|
|
380
|
+
isShowFormulaDialog: false,
|
|
381
|
+
isShowContextMenu: false,
|
|
382
|
+
showCommentBtn: false,
|
|
383
|
+
showCommentDialog: false,
|
|
384
|
+
commentPosition: null,
|
|
385
|
+
relistComment: 0
|
|
386
|
+
};
|
|
387
|
+
return _this;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
_createClass(SimpleEditor, [{
|
|
391
|
+
key: "componentDidCatch",
|
|
392
|
+
value: function componentDidCatch(error) {
|
|
393
|
+
this.props.resetRichValue();
|
|
394
|
+
console.log(error);
|
|
395
|
+
}
|
|
396
|
+
}, {
|
|
397
|
+
key: "componentDidMount",
|
|
398
|
+
value: function componentDidMount() {
|
|
399
|
+
window.richMarkdownEditor = this; // notify current user if others are also editing this file
|
|
400
|
+
|
|
401
|
+
var editingUsers = this.props.collabUsers.filter(function (ele) {
|
|
402
|
+
return ele.is_editing === true && ele.myself === undefined;
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
if (editingUsers.length > 0) {
|
|
406
|
+
toaster.danger('Another user is editing this file!', {
|
|
407
|
+
duration: 3
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
var userAgent = navigator.userAgent.toLowerCase();
|
|
412
|
+
|
|
413
|
+
if (userAgent.indexOf('chrome') === -1) {
|
|
414
|
+
toaster.warning(this.props.t('Editing_files_in_this_browser_can_lead_to_slight_display_problems'), {
|
|
415
|
+
duration: 4
|
|
416
|
+
});
|
|
417
|
+
} // get first text node of the document and focus at the start of the text node
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
var _Array$from$ = _slicedToArray(Array.from(Node.texts(this.editor.children[0]))[0], 2),
|
|
421
|
+
textPath = _Array$from$[1];
|
|
422
|
+
|
|
423
|
+
textPath.unshift(0);
|
|
424
|
+
Editor.select(this.editor, {
|
|
425
|
+
path: textPath,
|
|
426
|
+
offset: 0
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
}, {
|
|
430
|
+
key: "componentWillReceiveProps",
|
|
431
|
+
value: function componentWillReceiveProps(nextProps) {
|
|
432
|
+
if (this.props.issues !== nextProps.issues && nextProps.issues.issue_list.length > 0 && !this.state.isShowSidePanel) {
|
|
433
|
+
this.setState({
|
|
434
|
+
isShowSidePanel: true
|
|
435
|
+
}, function () {
|
|
436
|
+
window.openMarkdownHint && window.openMarkdownHint();
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}, {
|
|
441
|
+
key: "render",
|
|
442
|
+
value: function render() {
|
|
443
|
+
var _this2 = this;
|
|
444
|
+
|
|
445
|
+
var _this$state = this.state,
|
|
446
|
+
value = _this$state.value,
|
|
447
|
+
isShowLinkDialog = _this$state.isShowLinkDialog,
|
|
448
|
+
isShowImageDialog = _this$state.isShowImageDialog,
|
|
449
|
+
isShowFormulaDialog = _this$state.isShowFormulaDialog;
|
|
450
|
+
var _this$props = this.props,
|
|
451
|
+
t = _this$props.t,
|
|
452
|
+
mode = _this$props.mode,
|
|
453
|
+
editorApi = _this$props.editorApi;
|
|
454
|
+
var _this$state2 = this.state,
|
|
455
|
+
mainPanelWidth = _this$state2.mainPanelWidth,
|
|
456
|
+
isShowHelpDialog = _this$state2.isShowHelpDialog,
|
|
457
|
+
isShowSidePanel = _this$state2.isShowSidePanel;
|
|
458
|
+
var onResizeMove = this.state.resizeFlag ? this.onResizeMouseMove : null;
|
|
459
|
+
var mainPanelClass = "seafile-editor-main-panel d-flex align-self-end ".concat(!isShowSidePanel && !isShowHelpDialog ? 'seafile-editor-all-panel' : '');
|
|
460
|
+
var mainPanelStyle = {
|
|
461
|
+
width: isShowSidePanel ? mainPanelWidth + '%' : '100%'
|
|
462
|
+
};
|
|
463
|
+
var editor = this.editor,
|
|
464
|
+
foucsEditor = this.foucsEditor;
|
|
465
|
+
var toolbarStatus = this.editorUtils.getToolbarStatus();
|
|
466
|
+
var readOnly = this.props.readOnly;
|
|
467
|
+
var selectionCollapsed = isRangeCollapsed(editor.selection);
|
|
468
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
469
|
+
className: "seafile-editor-module seafile-editor"
|
|
470
|
+
}, /*#__PURE__*/React.createElement(Slate, {
|
|
471
|
+
editor: this.editor,
|
|
472
|
+
value: value,
|
|
473
|
+
onChange: this.onChange
|
|
474
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
475
|
+
className: "seafile-rich-editor-topbar"
|
|
476
|
+
}, /*#__PURE__*/React.createElement(ToolBar, {
|
|
477
|
+
onToggleLinkDialog: this.onToggleLinkDialog,
|
|
478
|
+
onToggleImageDialog: this.onToggleImageDialog,
|
|
479
|
+
onToggleFormulaDialog: this.onToggleFormulaDialog,
|
|
480
|
+
toolbarStatus: toolbarStatus,
|
|
481
|
+
toggleSidePanel: this.toggleSidePanel,
|
|
482
|
+
insertRepoFile: this.insertRepoFile,
|
|
483
|
+
isShowLinkDialog: isShowLinkDialog,
|
|
484
|
+
isShowImageDialog: isShowImageDialog,
|
|
485
|
+
isShowSidePanel: isShowSidePanel,
|
|
486
|
+
hasSidePanel: true,
|
|
487
|
+
mode: mode,
|
|
488
|
+
readOnly: readOnly,
|
|
489
|
+
isShowFormulaDialog: isShowFormulaDialog
|
|
490
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
491
|
+
className: "seafile-editor-main d-flex",
|
|
492
|
+
onMouseMove: onResizeMove,
|
|
493
|
+
onMouseUp: this.onResizeMouseUp
|
|
494
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
495
|
+
className: mainPanelClass,
|
|
496
|
+
style: mainPanelStyle
|
|
497
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
498
|
+
className: "editor-container align-self-start",
|
|
499
|
+
ref: "editorContainer"
|
|
500
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
501
|
+
ref: function ref(_ref) {
|
|
502
|
+
return _this2.editorRef = _ref;
|
|
503
|
+
},
|
|
504
|
+
onClick: value.length === 2 && value[0].type === 'paragraph' && Node.text(value[0].children[0]).length === 0 ? foucsEditor : null,
|
|
505
|
+
className: "editor article"
|
|
506
|
+
}, /*#__PURE__*/React.createElement(Editable, {
|
|
507
|
+
renderElement: function renderElement(props) {
|
|
508
|
+
return renderNode(props, editor, readOnly);
|
|
509
|
+
},
|
|
510
|
+
className: 'editor-component',
|
|
511
|
+
renderLeaf: renderLeaf,
|
|
512
|
+
onContextMenu: this.onContextMenu,
|
|
513
|
+
onCopy: function onCopy(event) {
|
|
514
|
+
_this2.plugin.onCopy(event, editor);
|
|
515
|
+
},
|
|
516
|
+
onCut: function onCut(event) {
|
|
517
|
+
return _this2.plugin.onCut(event);
|
|
518
|
+
},
|
|
519
|
+
autoFocus: true,
|
|
520
|
+
onKeyDown: this.plugin.onKeyDown,
|
|
521
|
+
decorate: decorationNode,
|
|
522
|
+
onSelect: this.setBtnPosition
|
|
523
|
+
}), this.state.showCommentBtn && /*#__PURE__*/React.createElement("i", {
|
|
524
|
+
className: "iconfont icon-plus-square seafile-viewer-comment-btn",
|
|
525
|
+
ref: "commentbtn",
|
|
526
|
+
onMouseDown: this.addComment
|
|
527
|
+
})), toolbarStatus.isLinkActive && selectionCollapsed ? /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(TextLinkHoverMenu, {
|
|
528
|
+
onToggleLinkDialog: this.onToggleLinkDialog,
|
|
529
|
+
editorUtils: this.editorUtils
|
|
530
|
+
})) : null, this.state.isShowContextMenu && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(ContextMenu, {
|
|
531
|
+
tableUtils: this.tableUtils,
|
|
532
|
+
contextMenuPosition: this.contextMenuPosition
|
|
533
|
+
})))), !isShowHelpDialog && isShowSidePanel && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
534
|
+
className: "seafile-editor-resize",
|
|
535
|
+
style: {
|
|
536
|
+
right: 100 - mainPanelWidth + '%'
|
|
537
|
+
},
|
|
538
|
+
onMouseDown: this.onResizeMouseDown
|
|
539
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
540
|
+
className: "seafile-editor-side-panel align-self-start",
|
|
541
|
+
style: {
|
|
542
|
+
width: 100 - mainPanelWidth + '%'
|
|
543
|
+
}
|
|
544
|
+
}, /*#__PURE__*/React.createElement(SidePanel, {
|
|
545
|
+
editor: this,
|
|
546
|
+
document: value,
|
|
547
|
+
issues: this.props.issues,
|
|
548
|
+
scrollToNode: this.scrollToNode,
|
|
549
|
+
scrollToQuote: this.scrollToQuote,
|
|
550
|
+
t: this.props.t,
|
|
551
|
+
editorApi: editorApi,
|
|
552
|
+
toggleCommentBtn: this.toggleCommentBtn,
|
|
553
|
+
relistComment: this.state.relistComment,
|
|
554
|
+
relatedFiles: this.props.relatedFiles,
|
|
555
|
+
fileTagList: this.props.fileTagList,
|
|
556
|
+
openDialogs: this.props.openDialogs,
|
|
557
|
+
fileInfo: this.props.fileInfo,
|
|
558
|
+
participants: this.props.participants,
|
|
559
|
+
onParticipantsChange: this.props.onParticipantsChange
|
|
560
|
+
}))), isShowHelpDialog && /*#__PURE__*/React.createElement(UserHelpDialog, {
|
|
561
|
+
userHelp: t('userHelp', {
|
|
562
|
+
returnObjects: true
|
|
563
|
+
}),
|
|
564
|
+
hideHelpDialog: this.hideHelpDialog
|
|
565
|
+
}), this.state.showCommentDialog && /*#__PURE__*/React.createElement(CommentDialog, {
|
|
566
|
+
editorApi: editorApi,
|
|
567
|
+
t: t,
|
|
568
|
+
quote: this.quote,
|
|
569
|
+
scrollToQuote: this.scrollToQuote,
|
|
570
|
+
commentPosition: this.state.commentPosition,
|
|
571
|
+
onCommentAdded: this.onCommentAdded,
|
|
572
|
+
toggleCommentDialog: this.toggleCommentDialog
|
|
573
|
+
}))));
|
|
574
|
+
}
|
|
575
|
+
}]);
|
|
576
|
+
|
|
577
|
+
return SimpleEditor;
|
|
578
|
+
}(React.Component);
|
|
579
|
+
|
|
580
|
+
export default withTranslation('seafile-editor')(SimpleEditor);
|