@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.
Files changed (156) hide show
  1. package/README.md +119 -0
  2. package/TODO.md +55 -0
  3. package/dist/components/add-formula-dialog.js +135 -0
  4. package/dist/components/add-image-dialog.js +78 -0
  5. package/dist/components/add-link-dialog.js +148 -0
  6. package/dist/components/comment-dialog.js +107 -0
  7. package/dist/components/comment-panel.js +452 -0
  8. package/dist/components/context-menu.js +112 -0
  9. package/dist/components/detail-list-view.js +119 -0
  10. package/dist/components/generate-share-link.js +412 -0
  11. package/dist/components/internal-link-dialog.js +96 -0
  12. package/dist/components/loading.js +32 -0
  13. package/dist/components/markdown-lint.js +87 -0
  14. package/dist/components/modal-portal.js +46 -0
  15. package/dist/components/outline.js +130 -0
  16. package/dist/components/participants-list.js +126 -0
  17. package/dist/components/related-files-list.js +75 -0
  18. package/dist/components/shortcut-dialog.js +167 -0
  19. package/dist/components/side-panel.js +175 -0
  20. package/dist/components/toast/alert.js +150 -0
  21. package/dist/components/toast/index.js +3 -0
  22. package/dist/components/toast/toast.js +179 -0
  23. package/dist/components/toast/toastManager.js +158 -0
  24. package/dist/components/toast/toaster.js +76 -0
  25. package/dist/components/toolbar.js +235 -0
  26. package/dist/components/topbar-component/button-group.js +31 -0
  27. package/dist/components/topbar-component/editor-toolbar.js +545 -0
  28. package/dist/components/topbar-component/file-info.js +65 -0
  29. package/dist/components/topbar-component/header-list.js +128 -0
  30. package/dist/components/topbar-component/icon-button.js +99 -0
  31. package/dist/components/topbar-component/insert-file.js +67 -0
  32. package/dist/components/topbar-component/table-toolbar.js +175 -0
  33. package/dist/components/topbar-component/upload-img.js +122 -0
  34. package/dist/components/user-help.js +205 -0
  35. package/dist/css/diff-viewer.css +105 -0
  36. package/dist/css/history-viewer.css +104 -0
  37. package/dist/css/keyboard-shortcuts.css +59 -0
  38. package/dist/css/layout.css +110 -0
  39. package/dist/css/markdown-viewer-slate/file-tags-list.css +76 -0
  40. package/dist/css/markdown-viewer.css +69 -0
  41. package/dist/css/plaineditor/markdown-editor.css +12 -0
  42. package/dist/css/react-mentions-default-style.js +72 -0
  43. package/dist/css/related-files-list.css +56 -0
  44. package/dist/css/richeditor/comments-list.css +184 -0
  45. package/dist/css/richeditor/detail-list-view.css +114 -0
  46. package/dist/css/richeditor/document-info.css +57 -0
  47. package/dist/css/richeditor/formula.css +19 -0
  48. package/dist/css/richeditor/image.css +141 -0
  49. package/dist/css/richeditor/link.css +7 -0
  50. package/dist/css/richeditor/navbar-imgbutton.css +79 -0
  51. package/dist/css/richeditor/participants-list.css +22 -0
  52. package/dist/css/richeditor/rich-editor-main.css +42 -0
  53. package/dist/css/richeditor/right-panel.css +84 -0
  54. package/dist/css/richeditor/side-panel.css +190 -0
  55. package/dist/css/richeditor/table.css +57 -0
  56. package/dist/css/richeditor/textlink-hovermenu.css +47 -0
  57. package/dist/css/richeditor/tree-view.css +67 -0
  58. package/dist/css/topbar.css +400 -0
  59. package/dist/editor/code-highlight-package.js +27 -0
  60. package/dist/editor/controller/block-element-controller.js +376 -0
  61. package/dist/editor/controller/inline-element-controller.js +129 -0
  62. package/dist/editor/controller/normalize-controller.js +107 -0
  63. package/dist/editor/controller/shortcut-controller.js +394 -0
  64. package/dist/editor/controller/void-element-controller.js +12 -0
  65. package/dist/editor/custom/custom.js +17 -0
  66. package/dist/editor/custom/get-event-transfer.js +34 -0
  67. package/dist/editor/custom/getNodesByTypeAtRange.js +69 -0
  68. package/dist/editor/custom/insertNodes.js +140 -0
  69. package/dist/editor/custom/is-empty-paragraph.js +13 -0
  70. package/dist/editor/custom/set-event-transfer.js +31 -0
  71. package/dist/editor/custom/split-nodes-at-point.js +162 -0
  72. package/dist/editor/custom/unwrap-node-by-type-at-range.js +81 -0
  73. package/dist/editor/editor-component/check-list-item.js +64 -0
  74. package/dist/editor/editor-component/code-block.js +150 -0
  75. package/dist/editor/editor-component/formula.js +79 -0
  76. package/dist/editor/editor-component/image.js +215 -0
  77. package/dist/editor/editor-component/link.js +11 -0
  78. package/dist/editor/editor-component/table.js +172 -0
  79. package/dist/editor/editor-component/textlink-hovermenu.js +136 -0
  80. package/dist/editor/editor-plugin.js +249 -0
  81. package/dist/editor/editor-utils/block-element-utils/blockquote-utils.js +96 -0
  82. package/dist/editor/editor-utils/block-element-utils/code-utils.js +162 -0
  83. package/dist/editor/editor-utils/block-element-utils/formula-utils.js +58 -0
  84. package/dist/editor/editor-utils/block-element-utils/index.js +38 -0
  85. package/dist/editor/editor-utils/block-element-utils/list-utils.js +398 -0
  86. package/dist/editor/editor-utils/block-element-utils/table-utils.js +418 -0
  87. package/dist/editor/editor-utils/common-editor-utils.js +587 -0
  88. package/dist/editor/editor-utils/inline-element-utils/index.js +95 -0
  89. package/dist/editor/editor-utils/mark-utils.js +25 -0
  90. package/dist/editor/editor-utils/range-utils.js +9 -0
  91. package/dist/editor/editor-utils/selection-utils.js +33 -0
  92. package/dist/editor/editor-utils/text-utils.js +130 -0
  93. package/dist/editor/editor.js +66 -0
  94. package/dist/editor/element-model/blockquote.js +16 -0
  95. package/dist/editor/element-model/image.js +19 -0
  96. package/dist/editor/element-model/link.js +19 -0
  97. package/dist/editor/element-model/table.js +50 -0
  98. package/dist/editor/element-model/text.js +13 -0
  99. package/dist/editor/load-script.js +83 -0
  100. package/dist/editor/plain-markdown-editor.js +324 -0
  101. package/dist/editor/rich-markdown-editor.js +580 -0
  102. package/dist/editor/seafile-editor.js +326 -0
  103. package/dist/editor/simple-editor.js +245 -0
  104. package/dist/editor-api.js +261 -0
  105. package/dist/index.css +97 -0
  106. package/dist/lib/slate-hyperscript/creators.js +263 -0
  107. package/dist/lib/slate-hyperscript/hyperscript.js +92 -0
  108. package/dist/lib/slate-hyperscript/index.js +3 -0
  109. package/dist/lib/slate-hyperscript/tokens.js +102 -0
  110. package/dist/lib/unified/index.js +470 -0
  111. package/dist/lib/vfile/core.js +172 -0
  112. package/dist/lib/vfile/index.js +48 -0
  113. package/dist/seafile-editor-chooser.js +45 -0
  114. package/dist/seafile-markdown-editor.js +301 -0
  115. package/dist/seafile-markdown-viewer.js +79 -0
  116. package/dist/seafile-simple-editor.js +56 -0
  117. package/dist/utils/copy-to-clipboard.js +47 -0
  118. package/dist/utils/deserialize-html.js +282 -0
  119. package/dist/utils/diff/compare-strings.js +46 -0
  120. package/dist/utils/diff/diff.js +855 -0
  121. package/dist/utils/diff/index.js +2 -0
  122. package/dist/utils/render-slate.js +219 -0
  123. package/dist/utils/seafile-markdown2html.js +62 -0
  124. package/dist/utils/slate2markdown/deserialize.js +689 -0
  125. package/dist/utils/slate2markdown/index.js +3 -0
  126. package/dist/utils/slate2markdown/serialize.js +407 -0
  127. package/dist/utils/utils.js +28 -0
  128. package/dist/viewer/diff-viewer.js +98 -0
  129. package/dist/viewer/markdown-viewer.js +139 -0
  130. package/dist/viewer/slate-viewer.js +73 -0
  131. package/dist/viewer/viewer-formula.js +67 -0
  132. package/dist/viewer/viewer-image.js +93 -0
  133. package/dist/viewer/viewer-outline.js +118 -0
  134. package/package.json +215 -0
  135. package/public/favicon.ico +0 -0
  136. package/public/index.html +45 -0
  137. package/public/locales/cs/seafile-editor.json +169 -0
  138. package/public/locales/de/seafile-editor.json +169 -0
  139. package/public/locales/en/seafile-editor.json +222 -0
  140. package/public/locales/es/seafile-editor.json +169 -0
  141. package/public/locales/es-AR/seafile-editor.json +169 -0
  142. package/public/locales/es-MX/seafile-editor.json +169 -0
  143. package/public/locales/fr/seafile-editor.json +169 -0
  144. package/public/locales/it/seafile-editor.json +169 -0
  145. package/public/locales/ru/seafile-editor.json +169 -0
  146. package/public/locales/zh-CN/seafile-editor.json +219 -0
  147. package/public/manifest.json +15 -0
  148. package/public/media/scripts/mathjax/tex-svg.js +1 -0
  149. package/public/media/seafile-editor-font/iconfont.eot +0 -0
  150. package/public/media/seafile-editor-font/iconfont.svg +164 -0
  151. package/public/media/seafile-editor-font/iconfont.ttf +0 -0
  152. package/public/media/seafile-editor-font/iconfont.woff +0 -0
  153. package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
  154. package/public/media/seafile-editor-font.css +201 -0
  155. package/public/media/seafile-logo.png +0 -0
  156. package/public/media/seafile-ui.css +11169 -0
@@ -0,0 +1,326 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
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 toaster from '../components/toast';
8
+ import { withTranslation } from 'react-i18next';
9
+ import { Text } from 'slate';
10
+ import '../css/layout.css';
11
+ import '../css/topbar.css';
12
+ import RichMarkdownEditor from './rich-markdown-editor';
13
+ import PlainMarkdownEditor from './plain-markdown-editor';
14
+ import { serialize, deserialize } from '../utils/slate2markdown';
15
+
16
+ var SeafileEditor = /*#__PURE__*/function (_React$Component) {
17
+ _inherits(SeafileEditor, _React$Component);
18
+
19
+ var _super = _createSuper(SeafileEditor);
20
+
21
+ function SeafileEditor(props) {
22
+ var _this;
23
+
24
+ _classCallCheck(this, SeafileEditor);
25
+
26
+ _this = _super.call(this, props);
27
+
28
+ _this.switchToPlainTextEditor = function () {
29
+ // TODO: performance, change to do serialize in async way
30
+ if (_this.props.editorMode === 'rich') {
31
+ var value = _this.state.richValue;
32
+ var str = serialize(value);
33
+
34
+ _this.props.setEditorMode('plain');
35
+
36
+ _this.setState({
37
+ initialPlainValue: str,
38
+ currentContent: str
39
+ });
40
+ }
41
+
42
+ if (_this.props.collabServer) {
43
+ _this.props.emitSwitchEditor(false);
44
+ }
45
+ };
46
+
47
+ _this.switchToRichTextEditor = function () {
48
+ // TODO: performance, change to do deserialize in async way
49
+ _this.setState({
50
+ richValue: deserialize(_this.state.currentContent)
51
+ });
52
+
53
+ _this.props.setEditorMode('rich');
54
+
55
+ if (_this.props.collabServer) {
56
+ _this.props.emitSwitchEditor(false);
57
+ }
58
+ };
59
+
60
+ _this.onUnload = function (event) {
61
+ if (!_this.props.contentChanged) return;
62
+ var confirmationMessage = 'Leave this page? The system may not save your changes.';
63
+
64
+ _this.props.clearTimer();
65
+
66
+ _this.props.deleteDraft && _this.props.deleteDraft();
67
+ event.returnValue = confirmationMessage;
68
+ return confirmationMessage;
69
+ };
70
+
71
+ _this.onChange = function (value, operations) {
72
+ if (_this.props.editorMode === 'rich') {
73
+ _this.setState({
74
+ richValue: value
75
+ });
76
+
77
+ _this.props.setDraftValue('rich', _this.state.richValue);
78
+
79
+ var ops = operations.filter(function (o) {
80
+ return o.type !== 'set_selection' && o.type !== 'set_value';
81
+ });
82
+
83
+ if (ops.length !== 0) {
84
+ _this.props.onContentChanged(true);
85
+
86
+ if (_this.autoSave) _this.props.autoSaveDraft();
87
+ }
88
+ } else {
89
+ _this.setState({
90
+ currentContent: value
91
+ });
92
+
93
+ _this.props.onContentChanged(true);
94
+
95
+ _this.props.setDraftValue('rich', _this.state.richValue);
96
+
97
+ _this.props.autoSaveDraft();
98
+ }
99
+ };
100
+
101
+ _this.saveContent = function (str) {
102
+ _this.props.editorApi.saveContent(str).then(function () {
103
+ _this.props.onSaving(false);
104
+
105
+ _this.props.onContentChanged(false); // remove markdown lint temporarily
106
+ // if (this.props.markdownLint) {
107
+ // const slateValue = this.state.richValue;
108
+ // this.props.editorApi.markdownLint(JSON.stringify(slateValue)).then((res) => {
109
+ // this.setState({
110
+ // issues: res.data
111
+ // });
112
+ // });
113
+ // }
114
+
115
+
116
+ _this.lastModifyTime = new Date();
117
+ toaster.success(_this.props.t('file_saved'), {
118
+ duration: 2
119
+ });
120
+
121
+ _this.props.editorApi.getFileInfo().then(function (res) {
122
+ _this.props.setFileInfoMtime(res.data);
123
+ });
124
+
125
+ _this.addParticipants();
126
+ }, function () {
127
+ _this.props.onSaving(false);
128
+
129
+ toaster.danger(_this.props.t('file_failed_to_save'), {
130
+ duration: 2
131
+ });
132
+ });
133
+
134
+ _this.props.onSaving(true);
135
+ };
136
+
137
+ _this.addParticipants = function () {
138
+ if (_this.isParticipant || !window.showParticipants) return;
139
+ var _this$props$editorApi = _this.props.editorApi,
140
+ userName = _this$props$editorApi.userName,
141
+ addFileParticipants = _this$props$editorApi.addFileParticipants;
142
+ var participants = _this.props.participants;
143
+
144
+ if (participants && participants.length !== 0) {
145
+ _this.isParticipant = participants.every(function (participant) {
146
+ return participant.email === userName;
147
+ });
148
+ if (_this.isParticipant) return;
149
+ }
150
+
151
+ var emails = [userName];
152
+ addFileParticipants(emails).then(function (res) {
153
+ _this.isParticipant = true;
154
+
155
+ _this.props.onParticipantsChange();
156
+ });
157
+ };
158
+
159
+ _this.onRichEditorSave = function () {
160
+ if (_this.props.isSaving) return;
161
+ var value = _this.state.richValue;
162
+ var str = serialize(value);
163
+
164
+ _this.saveContent(str);
165
+
166
+ _this.props.clearTimer();
167
+
168
+ _this.props.deleteDraft && _this.props.deleteDraft();
169
+ };
170
+
171
+ _this.resetRichValue = function () {
172
+ var value = _this.state.richValue;
173
+
174
+ _this.setState({
175
+ richValue: value
176
+ });
177
+ };
178
+
179
+ _this.onPlainEditorSave = function () {
180
+ if (_this.props.isSaving) return;
181
+ var str = _this.state.currentContent;
182
+
183
+ _this.saveContent(str);
184
+
185
+ _this.props.clearTimer();
186
+
187
+ _this.props.deleteDraft && _this.props.deleteDraft();
188
+ };
189
+
190
+ _this.resetContentChanged = function () {
191
+ if (_this.props.contentChanged) {
192
+ _this.props.onContentChanged(false);
193
+ }
194
+
195
+ _this.autoSave = true;
196
+ };
197
+
198
+ var markdownContent = _this.props.markdownContent;
199
+ var isEditMode = _this.props.mode === 'editor';
200
+ var isDraft = _this.props.isDraft;
201
+ _this.lastModifyTime = null;
202
+ _this.autoSave = false;
203
+ _this.isParticipant = false;
204
+ window.seafileEditor = _assertThisInitialized(_this);
205
+ _this.state = {
206
+ isTreeDataLoaded: false,
207
+ initialPlainValue: '',
208
+ // for plain editor
209
+ currentContent: markdownContent,
210
+ // for plain editor and viewer
211
+ richValue: isEditMode || isDraft ? deserialize(markdownContent) : deserialize(''),
212
+ // for rich editor
213
+ issues: {
214
+ issue_list: []
215
+ }
216
+ };
217
+ return _this;
218
+ } // componentWillReceiveProps(nextProps) {
219
+ // if (this.props.markdownContent !== nextProps.markdownContent) {
220
+ // this.setState({ richValue: deserialize(nextProps.markdownContent) });
221
+ // }
222
+ // }
223
+ // from rich editor to plain editor
224
+
225
+
226
+ _createClass(SeafileEditor, [{
227
+ key: "componentDidMount",
228
+ value: function componentDidMount() {
229
+ // window.seafileEditor = this;
230
+ window.addEventListener('beforeunload', this.onUnload);
231
+ }
232
+ }, {
233
+ key: "componentWillMount",
234
+ value:
235
+ /*
236
+ * when seafileEditor first mounted check the content
237
+ * if the content is empty add h1 to document
238
+ * */
239
+ function componentWillMount() {
240
+ if (this.props.editorMode === 'rich') {
241
+ var document = this.state.richValue;
242
+ var firstNode = document[0];
243
+ /**
244
+ * if the markdown content is empty, the rich value contains
245
+ * only a paragraph which contains a empty text node
246
+ *
247
+ */
248
+
249
+ if (document.length === 1 && firstNode.type === 'paragraph' && firstNode.children.length === 1 && Text.isText(firstNode.children[0]) && firstNode.children[0].text.length === 0) {
250
+ var headerContent = this.props.fileInfo.name.slice(0, this.props.fileInfo.name.lastIndexOf('.'));
251
+ var header = {
252
+ type: 'header_one',
253
+ children: [{
254
+ text: headerContent,
255
+ marks: []
256
+ }]
257
+ };
258
+ document.push(header);
259
+ document.shift();
260
+ this.setState({
261
+ richValue: document
262
+ });
263
+ }
264
+ }
265
+ }
266
+ }, {
267
+ key: "render",
268
+ value: function render() {
269
+ var dom = '';
270
+
271
+ if (this.props.editorMode === 'rich') {
272
+ dom = /*#__PURE__*/React.createElement(RichMarkdownEditor, {
273
+ editorApi: this.props.editorApi,
274
+ onChange: this.onChange,
275
+ onSave: this.onRichEditorSave,
276
+ value: this.state.richValue,
277
+ resetRichValue: this.resetRichValue,
278
+ contentChanged: this.props.contentChanged,
279
+ saving: this.props.saving,
280
+ switchToMarkDownViewer: this.switchToMarkDownViewer,
281
+ switchToPlainTextEditor: this.switchToPlainTextEditor,
282
+ fileInfo: this.props.fileInfo,
283
+ toggleStar: this.props.toggleStar,
284
+ issues: this.state.issues,
285
+ resetContentChanged: this.resetContentChanged,
286
+ collabUsers: this.props.collabUsers,
287
+ mode: this.props.editorMode,
288
+ draftID: this.props.draftID,
289
+ isDraft: this.props.isDraft,
290
+ openDialogs: this.props.openDialogs,
291
+ readOnly: this.props.readOnly,
292
+ relatedFiles: this.props.relatedFiles,
293
+ fileTagList: this.props.fileTagList,
294
+ participants: this.props.participants,
295
+ onParticipantsChange: this.props.onParticipantsChange
296
+ });
297
+ } else if (this.props.editorMode === 'plain') {
298
+ dom = /*#__PURE__*/React.createElement(PlainMarkdownEditor, {
299
+ editorApi: this.props.editorApi,
300
+ initialValue: this.state.initialPlainValue,
301
+ currentContent: this.state.currentContent,
302
+ contentChanged: this.props.contentChanged,
303
+ switchToRichTextEditor: this.switchToRichTextEditor,
304
+ switchToMarkDownViewer: this.switchToMarkDownViewer,
305
+ onSave: this.onPlainEditorSave,
306
+ onChange: this.onChange,
307
+ fileInfo: this.props.fileInfo,
308
+ toggleStar: this.props.toggleStar,
309
+ collabUsers: this.props.collabUsers,
310
+ mode: this.props.editorMode,
311
+ draftID: this.props.draftID,
312
+ isDraft: this.props.isDraft
313
+ });
314
+ }
315
+
316
+ return dom;
317
+ }
318
+ }]);
319
+
320
+ return SeafileEditor;
321
+ }(React.Component);
322
+
323
+ SeafileEditor.defaultProps = {
324
+ userInfo: null
325
+ };
326
+ export default withTranslation('seafile-editor')(SeafileEditor);
@@ -0,0 +1,245 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
+ import React from 'react';
6
+ import ToolBar from '../components/toolbar';
7
+ import { withTranslation } from 'react-i18next';
8
+ import { renderNode, renderLeaf, EditorUtils, decorationNode } from './editor-utils/common-editor-utils';
9
+ import { createEditor, Node, Editor } from 'slate';
10
+ import { withHistory } from 'slate-history';
11
+ import { deserialize, serialize } from '../utils/slate2markdown/index';
12
+ import { Editable, withReact, Slate } from '@seafile/slate-react';
13
+ import { isRangeCollapsed } from './editor-utils/range-utils';
14
+ import ModalPortal from '../components/modal-portal';
15
+ import TextLinkHoverMenu from './editor-component/textlink-hovermenu';
16
+ import ContextMenu from '../components/context-menu';
17
+ import withBlock from './controller/block-element-controller';
18
+ import withInline from './controller/inline-element-controller';
19
+ import withVoid from './controller/void-element-controller';
20
+ import withMarkdownShortcut from './controller/shortcut-controller';
21
+ import normalizeNode from './controller/normalize-controller';
22
+ import Plugin from './editor-plugin';
23
+ import TableUtils from '../editor/editor-utils/block-element-utils/table-utils';
24
+ import IconButton from '../components/topbar-component/icon-button';
25
+ import KeyboardShortcuts from '../components/shortcut-dialog';
26
+ import './code-highlight-package';
27
+ import '../css/layout.css';
28
+ import '../css/richeditor/rich-editor-main.css';
29
+ import '../css/richeditor/navbar-imgbutton.css';
30
+ import '../css/richeditor/textlink-hovermenu.css';
31
+ import '../css/richeditor/image.css';
32
+ import '../css/richeditor/link.css';
33
+ import '../css/topbar.css';
34
+
35
+ var SimpleEditor = /*#__PURE__*/function (_React$Component) {
36
+ _inherits(SimpleEditor, _React$Component);
37
+
38
+ var _super = _createSuper(SimpleEditor);
39
+
40
+ function SimpleEditor(props) {
41
+ var _this;
42
+
43
+ _classCallCheck(this, SimpleEditor);
44
+
45
+ _this = _super.call(this, props);
46
+
47
+ _this.onChange = function (value) {
48
+ _this.setState({
49
+ value: value
50
+ }); // hide context menu when content change
51
+
52
+
53
+ if (_this.state.isShowContextMenu === true) {
54
+ _this.setState({
55
+ isShowContextMenu: false
56
+ });
57
+
58
+ _this.contextMenuPosition = {};
59
+ }
60
+
61
+ var operations = _this.editor.operations;
62
+ var hasChange = operations.some(function (o) {
63
+ return o.type !== 'set_selection' && o.type !== 'set_value';
64
+ });
65
+ if (hasChange) _this.contentChanged = true;
66
+ };
67
+
68
+ _this.foucsEditor = function () {
69
+ _this.editorRef.firstChild.focus();
70
+ };
71
+
72
+ _this.focusText = function () {
73
+ // In dtable long text editor, press the key to open the editor.
74
+ // Then the cursor should move to the end of this character.
75
+ var _this$props = _this.props,
76
+ focusEnd = _this$props.focusEnd,
77
+ value = _this$props.value;
78
+
79
+ if (focusEnd === true && value.length === 1) {
80
+ setTimeout(function () {
81
+ Editor.select(_this.editor, {
82
+ path: [0, 0],
83
+ offset: 1
84
+ });
85
+ }, 1);
86
+ }
87
+ };
88
+
89
+ _this.hasContentChange = function () {
90
+ return _this.contentChanged;
91
+ };
92
+
93
+ _this.onToggleLinkDialog = function () {
94
+ _this.setState({
95
+ isShowLinkDialog: !_this.state.isShowLinkDialog
96
+ });
97
+ };
98
+
99
+ _this.onToggleImageDialog = function () {
100
+ _this.setState({
101
+ isShowImageDialog: !_this.state.isShowImageDialog
102
+ });
103
+ };
104
+
105
+ _this.onContextMenu = function (event) {
106
+ if (_this.tableUtils.isInTable()) {
107
+ event.preventDefault();
108
+ _this.contextMenuPosition = {
109
+ left: event.clientX,
110
+ top: event.clientY
111
+ };
112
+
113
+ _this.setState({
114
+ isShowContextMenu: !_this.state.isShowContextMenu
115
+ });
116
+ }
117
+ };
118
+
119
+ _this.toggleShortcutDialog = function () {
120
+ _this.setState({
121
+ isShowShortcutDialog: !_this.state.isShowShortcutDialog
122
+ });
123
+ };
124
+
125
+ _this.editor = normalizeNode(withMarkdownShortcut(withVoid(withBlock(withInline(withHistory(withReact(createEditor())))))));
126
+ _this.editor.editorApi = props.editorApi;
127
+ window.editor = _this.editor;
128
+ _this.editorUtils = new EditorUtils(_this.editor);
129
+ _this.tableUtils = new TableUtils(_this.editor);
130
+ _this.plugin = new Plugin(_this.editor);
131
+ _this.editorRef = null;
132
+ _this.contextMenuPosition = {};
133
+ _this.state = {
134
+ value: deserialize(props.value),
135
+ isShowLinkDialog: false,
136
+ isShowImageDialog: false,
137
+ isShowBigImage: false,
138
+ isShowContextMenu: false,
139
+ isShowShortcutDialog: false
140
+ };
141
+ return _this;
142
+ }
143
+
144
+ _createClass(SimpleEditor, [{
145
+ key: "componentDidMount",
146
+ value: function componentDidMount() {
147
+ this.props.onRef(this);
148
+ this.focusText();
149
+ }
150
+ }, {
151
+ key: "getMarkdown",
152
+ value: function getMarkdown() {
153
+ this.contentChanged = false;
154
+ return serialize(this.state.value);
155
+ }
156
+ }, {
157
+ key: "getValue",
158
+ value: function getValue() {
159
+ return this.state.value;
160
+ }
161
+ }, {
162
+ key: "render",
163
+ value: function render() {
164
+ var _this2 = this;
165
+
166
+ var _this$state = this.state,
167
+ value = _this$state.value,
168
+ isShowLinkDialog = _this$state.isShowLinkDialog,
169
+ isShowImageDialog = _this$state.isShowImageDialog;
170
+ var editor = this.editor,
171
+ foucsEditor = this.foucsEditor;
172
+ var toolbarStatus = this.editorUtils.getToolbarStatus();
173
+ var _this$props2 = this.props,
174
+ readOnly = _this$props2.readOnly,
175
+ t = _this$props2.t;
176
+ var selectionCollapsed = isRangeCollapsed(editor.selection);
177
+ return /*#__PURE__*/React.createElement("div", {
178
+ className: "seafile-editor-module seafile-simple-editor"
179
+ }, /*#__PURE__*/React.createElement(Slate, {
180
+ editor: this.editor,
181
+ value: value,
182
+ onChange: this.onChange
183
+ }, /*#__PURE__*/React.createElement("div", {
184
+ className: "seafile-rich-editor-topbar"
185
+ }, /*#__PURE__*/React.createElement(ToolBar, {
186
+ onToggleLinkDialog: this.onToggleLinkDialog,
187
+ onToggleImageDialog: this.onToggleImageDialog,
188
+ toolbarStatus: toolbarStatus,
189
+ isSimpleEditor: true,
190
+ isShowLinkDialog: isShowLinkDialog,
191
+ isShowImageDialog: isShowImageDialog
192
+ }), /*#__PURE__*/React.createElement("div", {
193
+ className: 'btn-group editor-btn-group'
194
+ }, /*#__PURE__*/React.createElement(IconButton, {
195
+ isRichEditor: true,
196
+ text: t('Shortcut_help'),
197
+ id: 'helpIcon',
198
+ className: 'use-help-icon',
199
+ icon: 'iconfont icon-use-help',
200
+ onMouseDown: function onMouseDown(event) {
201
+ return _this2.toggleShortcutDialog();
202
+ }
203
+ }))), /*#__PURE__*/React.createElement("div", {
204
+ className: "editor-container"
205
+ }, /*#__PURE__*/React.createElement("div", {
206
+ ref: function ref(_ref) {
207
+ return _this2.editorRef = _ref;
208
+ },
209
+ onClick: value.length === 1 && value[0].type === 'paragraph' && Node.text(value[0].children[0]).length === 0 ? foucsEditor : null,
210
+ className: "editor article"
211
+ }, /*#__PURE__*/React.createElement(Editable, {
212
+ renderElement: function renderElement(props) {
213
+ return renderNode(props, editor, readOnly);
214
+ },
215
+ className: 'editor-component',
216
+ renderLeaf: renderLeaf,
217
+ onContextMenu: this.onContextMenu,
218
+ onCopy: function onCopy(event) {
219
+ _this2.plugin.onCopy(event, editor);
220
+ },
221
+ onCut: function onCut(event) {
222
+ return _this2.plugin.onCut(event);
223
+ },
224
+ autoFocus: true,
225
+ onKeyDown: this.plugin.onKeyDown,
226
+ decorate: decorationNode
227
+ })), toolbarStatus.isLinkActive && selectionCollapsed ? /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(TextLinkHoverMenu, {
228
+ onToggleLinkDialog: this.onToggleLinkDialog,
229
+ editorUtils: this.editorUtils
230
+ })) : null, this.state.isShowContextMenu && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(ContextMenu, {
231
+ tableUtils: this.tableUtils,
232
+ contextMenuPosition: this.contextMenuPosition
233
+ })), this.state.isShowShortcutDialog && /*#__PURE__*/React.createElement(KeyboardShortcuts, {
234
+ userHelp: t('userHelp', {
235
+ returnObjects: true
236
+ }),
237
+ toggleShortcutDialog: this.toggleShortcutDialog
238
+ }))));
239
+ }
240
+ }]);
241
+
242
+ return SimpleEditor;
243
+ }(React.Component);
244
+
245
+ export default withTranslation('seafile-editor')(SimpleEditor);