@seafile/sdoc-editor 0.1.0 → 0.1.2

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 (149) hide show
  1. package/dist/{new-editors/editor.js → editor.js} +38 -17
  2. package/dist/index.js +2 -36
  3. package/dist/slate-extension/core/transforms/move-children.js +1 -1
  4. package/dist/slate-extension/plugins/blockquote/helpers.js +3 -3
  5. package/dist/slate-extension/plugins/index.js +3 -2
  6. package/dist/slate-extension/plugins/list/transforms/normalize-list-item.js +2 -2
  7. package/dist/slate-extension/plugins/list/transforms/toggle-list.js +6 -8
  8. package/dist/slate-extension/plugins/socket/index.js +6 -0
  9. package/dist/slate-extension/plugins/socket/plugin.js +23 -0
  10. package/dist/slate-extension/socket/socket-client.js +94 -0
  11. package/dist/slate-extension/socket/socket-manager.js +63 -0
  12. package/dist/slate-extension/toolbar/index.js +1 -1
  13. package/dist/utils/event-bus.js +39 -0
  14. package/package.json +5 -25
  15. package/dist/assets/css/comment-dialog.css +0 -50
  16. package/dist/assets/css/diff-viewer.css +0 -105
  17. package/dist/assets/css/formula.css +0 -19
  18. package/dist/assets/css/history-viewer.css +0 -104
  19. package/dist/assets/css/image.css +0 -134
  20. package/dist/assets/css/issue-card.css +0 -43
  21. package/dist/assets/css/keyboard-shortcuts.css +0 -58
  22. package/dist/assets/css/link.css +0 -7
  23. package/dist/assets/css/markdown-editor.css +0 -12
  24. package/dist/assets/css/markdown-viewer.css +0 -69
  25. package/dist/assets/css/navbar-imgbutton.css +0 -83
  26. package/dist/assets/css/outline.css +0 -29
  27. package/dist/assets/css/table.css +0 -57
  28. package/dist/assets/css/textlink-hovermenu.css +0 -47
  29. package/dist/assets/css/topbar.css +0 -350
  30. package/dist/assets/css/tree-view.css +0 -67
  31. package/dist/assets/css/user-help.css +0 -84
  32. package/dist/assets/editor/plain-editor.css +0 -30
  33. package/dist/assets/editor/seatable-editor.css +0 -77
  34. package/dist/assets/editor/simple-editor.css +0 -77
  35. package/dist/components/click-outside.js +0 -46
  36. package/dist/components/context-menu.js +0 -97
  37. package/dist/components/dialogs/add-formula-dialog.js +0 -116
  38. package/dist/components/dialogs/add-image-dialog.js +0 -69
  39. package/dist/components/dialogs/add-link-dialog.js +0 -133
  40. package/dist/components/dialogs/comment-dialog.js +0 -97
  41. package/dist/components/dialogs/shortcut-dialog.js +0 -131
  42. package/dist/components/error-boundary.js +0 -28
  43. package/dist/components/load-script/index.js +0 -69
  44. package/dist/components/loading.js +0 -25
  45. package/dist/components/markdown-lint.js +0 -72
  46. package/dist/components/menu/index.js +0 -4
  47. package/dist/components/menu/item.js +0 -49
  48. package/dist/components/menu/menu.js +0 -38
  49. package/dist/components/menu/style.css +0 -42
  50. package/dist/components/modal-portal.js +0 -38
  51. package/dist/components/outline/index.js +0 -92
  52. package/dist/components/outline/outline-item.js +0 -58
  53. package/dist/components/select/_option.js +0 -44
  54. package/dist/components/select/field-setting.js +0 -106
  55. package/dist/components/select/index.js +0 -149
  56. package/dist/components/select/style.css +0 -144
  57. package/dist/components/svg-icons/check-mark-icon.js +0 -14
  58. package/dist/components/svg-icons/column-icon.js +0 -17
  59. package/dist/components/svg-icons/text-icon.js +0 -34
  60. package/dist/components/text-link-hover-menu/index.js +0 -123
  61. package/dist/components/toast/alert.js +0 -138
  62. package/dist/components/toast/index.js +0 -3
  63. package/dist/components/toast/toast.js +0 -159
  64. package/dist/components/toast/toastManager.js +0 -139
  65. package/dist/components/toast/toaster.js +0 -65
  66. package/dist/components/toolbar/header-list.js +0 -114
  67. package/dist/components/toolbar/help-group.js +0 -33
  68. package/dist/components/toolbar/index.js +0 -4
  69. package/dist/components/toolbar/insert-image.js +0 -106
  70. package/dist/components/toolbar/insert-table.js +0 -136
  71. package/dist/components/toolbar/table-group.js +0 -74
  72. package/dist/components/toolbar/toolbar.js +0 -317
  73. package/dist/components/toolbar/widgets/button-group.js +0 -24
  74. package/dist/components/toolbar/widgets/button-item.js +0 -129
  75. package/dist/components/toolbar/widgets/drop-list.js +0 -88
  76. package/dist/components/user-help/index.js +0 -179
  77. package/dist/config-0.js +0 -15
  78. package/dist/config.js +0 -16
  79. package/dist/constants/cell-types.js +0 -29
  80. package/dist/constants/column.js +0 -4
  81. package/dist/containers/code-highlight-package.js +0 -14
  82. package/dist/containers/controller/block-element-controller.js +0 -375
  83. package/dist/containers/controller/index.js +0 -5
  84. package/dist/containers/controller/inline-element-controller.js +0 -134
  85. package/dist/containers/controller/normalize-controller.js +0 -95
  86. package/dist/containers/controller/shortcut-controller.js +0 -385
  87. package/dist/containers/controller/void-element-controller.js +0 -9
  88. package/dist/containers/custom/custom.js +0 -18
  89. package/dist/containers/custom/get-event-transfer.js +0 -33
  90. package/dist/containers/custom/getNodesByTypeAtRange.js +0 -57
  91. package/dist/containers/custom/insertNodes.js +0 -120
  92. package/dist/containers/custom/is-empty-paragraph.js +0 -9
  93. package/dist/containers/custom/set-event-transfer.js +0 -30
  94. package/dist/containers/custom/split-nodes-at-point.js +0 -136
  95. package/dist/containers/custom/unwrap-node-by-type-at-range.js +0 -70
  96. package/dist/containers/editor-context.js +0 -85
  97. package/dist/containers/editor-utils/block-element-utils/blockquote-utils.js +0 -80
  98. package/dist/containers/editor-utils/block-element-utils/code-utils.js +0 -145
  99. package/dist/containers/editor-utils/block-element-utils/formula-utils.js +0 -51
  100. package/dist/containers/editor-utils/block-element-utils/index.js +0 -31
  101. package/dist/containers/editor-utils/block-element-utils/list-utils.js +0 -395
  102. package/dist/containers/editor-utils/block-element-utils/table-utils.js +0 -412
  103. package/dist/containers/editor-utils/clear-format-utils.js +0 -84
  104. package/dist/containers/editor-utils/common-editor-utils.js +0 -492
  105. package/dist/containers/editor-utils/inline-element-utils/index.js +0 -95
  106. package/dist/containers/editor-utils/mark-utils.js +0 -20
  107. package/dist/containers/editor-utils/range-utils.js +0 -7
  108. package/dist/containers/editor-utils/selection-utils.js +0 -30
  109. package/dist/containers/editor-utils/text-utils.js +0 -117
  110. package/dist/containers/editor-widgets/check-list-item.js +0 -53
  111. package/dist/containers/editor-widgets/code-block.js +0 -128
  112. package/dist/containers/editor-widgets/column.js +0 -100
  113. package/dist/containers/editor-widgets/formula.js +0 -67
  114. package/dist/containers/editor-widgets/image.js +0 -237
  115. package/dist/containers/editor-widgets/link.js +0 -9
  116. package/dist/containers/editor-widgets/table.js +0 -144
  117. package/dist/containers/element-model/blockquote.js +0 -13
  118. package/dist/containers/element-model/column.js +0 -19
  119. package/dist/containers/element-model/image.js +0 -16
  120. package/dist/containers/element-model/link.js +0 -16
  121. package/dist/containers/element-model/table.js +0 -57
  122. package/dist/containers/element-model/text.js +0 -10
  123. package/dist/containers/render-utils/common-utils.js +0 -80
  124. package/dist/containers/render-utils/editor-utils.js +0 -133
  125. package/dist/containers/render-utils/viewer-utils.js +0 -198
  126. package/dist/containers/viewer-widgets/viewer-formula/index.js +0 -54
  127. package/dist/containers/viewer-widgets/viewer-image/index.js +0 -70
  128. package/dist/containers/viewer-widgets/viewer-image/viewer-image.css +0 -3
  129. package/dist/editors/index.js +0 -78
  130. package/dist/editors/markdown-editor.js +0 -280
  131. package/dist/editors/plain-markdown-editor.js +0 -285
  132. package/dist/editors/seatable-editor.js +0 -210
  133. package/dist/editors/simple-editor.js +0 -200
  134. package/dist/utils/deserialize-html.js +0 -260
  135. package/dist/utils/diff/compare-strings.js +0 -35
  136. package/dist/utils/diff/diff.js +0 -769
  137. package/dist/utils/diff/index.js +0 -2
  138. package/dist/utils/seafile-markdown2html.js +0 -52
  139. package/dist/utils/slate2markdown/deserialize.js +0 -588
  140. package/dist/utils/slate2markdown/index.js +0 -3
  141. package/dist/utils/slate2markdown/serialize.js +0 -366
  142. package/dist/utils/utils.js +0 -69
  143. package/dist/viewer/diff-viewer.js +0 -85
  144. package/dist/viewer/index.js +0 -4
  145. package/dist/viewer/markdown-viewer.js +0 -121
  146. package/dist/viewer/seatable-viewer.js +0 -63
  147. package/dist/viewer/slate-viewer.js +0 -71
  148. /package/dist/assets/css/{new-editor-toolbar.css → sdoc-editor-toolbar.css} +0 -0
  149. /package/dist/assets/css/{new-editor.css → sdoc-editor.css} +0 -0
@@ -1,280 +0,0 @@
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, { Fragment } from 'react';
7
- import { withTranslation } from 'react-i18next';
8
- import { Node, Editor, Range } from 'slate';
9
- import { Editable, Slate, ReactEditor } from '@seafile/slate-react';
10
- import toaster from '../components/toast';
11
- import ModalPortal from '../components/modal-portal';
12
- import ContextMenu from '../components/context-menu';
13
- import TextLinkHoverMenu from '../components/text-link-hover-menu';
14
- import CommentDialog from '../components/dialogs/comment-dialog';
15
- import AddLinkDialog from '../components/dialogs/add-link-dialog';
16
- import { serialize } from '../utils/slate2markdown/index';
17
- import { isRangeCollapsed } from '../containers/editor-utils/range-utils';
18
- import { renderNode, renderLeaf, decorationNode } from '../containers/render-utils/editor-utils';
19
- import EditorContext from '../containers/editor-context';
20
- import '../assets/css/navbar-imgbutton.css';
21
- import '../assets/css/image.css';
22
- import '../assets/css/link.css';
23
- import '../assets/css/tree-view.css';
24
- var MarkdownEditor = /*#__PURE__*/function (_React$Component) {
25
- _inherits(MarkdownEditor, _React$Component);
26
- var _super = _createSuper(MarkdownEditor);
27
- function MarkdownEditor(props) {
28
- var _this;
29
- _classCallCheck(this, MarkdownEditor);
30
- _this = _super.call(this, props);
31
- _this.getDomNodeByPath = function (path) {
32
- var node,
33
- parent = document.querySelector('.editor-component');
34
- while (typeof path[0] === 'number' && parent) {
35
- node = parent.children[path[0]];
36
- path.shift();
37
- parent = node;
38
- }
39
- return node;
40
- };
41
- _this.updateCommentBtnPosition = function () {
42
- if (!_this.props.isSupportComment) return;
43
- if (_this.timer) return;
44
- _this.timer = setTimeout(function () {
45
- var selection = _this.editor.selection;
46
- if (!selection || Range.isCollapsed(selection)) {
47
- var _style = _this.commentRef.style;
48
- _style.top = '-1000px';
49
- clearTimeout(_this.timer);
50
- _this.timer = null;
51
- return;
52
- }
53
- var focusNodePath = selection.anchor.path.slice();
54
- focusNodePath.pop();
55
- var focusNode = _this.getDomNodeByPath(focusNodePath);
56
- var style = _this.commentRef.style;
57
- style.right = '40px';
58
- if (focusNode) {
59
- style.top = "".concat(focusNode.offsetTop, "px");
60
- } else {
61
- style.top = '-1000px';
62
- }
63
- clearTimeout(_this.timer);
64
- _this.timer = null;
65
- }, 40);
66
- };
67
- _this.onCommentAdded = function () {
68
- _this.toggleCommentDialog();
69
- _this.props.onAddComment && _this.props.onAddComment();
70
- };
71
- _this.addComment = function (e) {
72
- e.stopPropagation();
73
- _this.getQuote();
74
- _this.toggleCommentDialog();
75
- };
76
- _this.toggleCommentDialog = function () {
77
- _this.setState({
78
- showCommentDialog: !_this.state.showCommentDialog
79
- });
80
- };
81
- _this.onToggleLinkDialog = function () {
82
- _this.setState({
83
- isShowLinkDialog: !_this.state.isShowLinkDialog
84
- });
85
- };
86
- _this.getQuote = function () {
87
- _this.quote = serialize(Editor.fragment(_this.editor, _this.editor.selection));
88
- _this.setState({
89
- commentPosition: _this.editor.selection.anchor.path
90
- });
91
- };
92
- _this.onChange = function (value) {
93
- _this.setState({
94
- value: value
95
- });
96
-
97
- // hide context menu when content change
98
- if (_this.state.isShowContextMenu === true) {
99
- _this.setState({
100
- isShowContextMenu: false
101
- });
102
- _this.contextMenuPosition = {};
103
- }
104
- _this.props.onChange(value, _this.editor.operations);
105
- };
106
- _this.onFocusEditor = function () {
107
- var value = _this.state.value;
108
- if (value.length === 2 && value[0].type === 'paragraph' && Node.text(value[0].children[0]).length === 0) {
109
- _this.editorRef.firstChild.focus();
110
- }
111
- };
112
- // provide the api to seahub to insert files of library
113
- _this.addLink = function (fileName, url, isImage) {
114
- var selection = _this.editor.selection;
115
- if (isImage) {
116
- _this.editorUtils.insertImage({
117
- url: url,
118
- selection: selection
119
- });
120
- return;
121
- }
122
- _this.editorUtils.insertLink({
123
- text: fileName,
124
- url: url,
125
- selection: selection
126
- });
127
- };
128
- _this.scrollToQuote = function (path) {
129
- if (!path) return;
130
- var editor = _this.editor;
131
- var node = editor.children[path[0]];
132
- var element = ReactEditor.toDOMNode(editor, node);
133
- _this.editorContainerRef.scrollTo(0, element.offsetTop);
134
- Editor.select(_this.editor, path);
135
- };
136
- _this.scrollToNode = function (node) {
137
- var editor = document.querySelector('.editor-component');
138
- var element = editor.childNodes[node.path[0]];
139
- _this.editorContainerRef.scrollTo(0, element.offsetTop);
140
- window.location.hash = encodeURI(node.children[0].text);
141
- Editor.select(_this.editor, node.path);
142
- };
143
- _this.onCopy = function (event) {
144
- _this.editorUtils.onCopy(event, _this.editor);
145
- };
146
- _this.onCut = function (event) {
147
- _this.editorUtils.onCut(event);
148
- };
149
- _this.onKeyDown = function (event) {
150
- _this.editorUtils.onKeyDown(event);
151
- };
152
- _this.onContextMenu = function (event) {
153
- if (_this.tableUtils.isInTable()) {
154
- event.preventDefault();
155
- _this.contextMenuPosition = {
156
- left: event.clientX,
157
- top: event.clientY
158
- };
159
- _this.setState({
160
- isShowContextMenu: !_this.state.isShowContextMenu
161
- });
162
- }
163
- };
164
- _this.setCommentRef = function (ref) {
165
- _this.commentRef = ref;
166
- };
167
- _this.setEditorRef = function (ref) {
168
- _this.editorRef = ref;
169
- };
170
- _this.setEditorContainerRef = function (ref) {
171
- _this.editorContainerRef = ref;
172
- };
173
- _this.state = {
174
- value: props.value,
175
- isShowContextMenu: false,
176
- showCommentDialog: false,
177
- commentPosition: null,
178
- isShowLinkDialog: false
179
- };
180
- _this.editor = EditorContext.getEditor(props);
181
- _this.editorUtils = EditorContext.getEditorUtils();
182
- _this.tableUtils = EditorContext.getTableUtils();
183
- _this.contextMenuPosition = {};
184
- return _this;
185
- }
186
- _createClass(MarkdownEditor, [{
187
- key: "componentDidCatch",
188
- value: function componentDidCatch(error) {
189
- this.props.resetRichValue();
190
- console.log(error);
191
- }
192
- }, {
193
- key: "componentDidMount",
194
- value: function componentDidMount() {
195
- window.abcdef_editor = this;
196
- var t = this.props.t;
197
- var userAgent = navigator.userAgent.toLowerCase();
198
- if (userAgent.indexOf('chrome') === -1) {
199
- var message = t('Editing_files_in_this_browser_can_lead_to_slight_display_problems');
200
- toaster.warning(message, {
201
- duration: 4
202
- });
203
- }
204
-
205
- // get first text node of the document and focus at the start of the text node
206
- var _Array$from$ = _slicedToArray(Array.from(Node.texts(this.editor.children[0]))[0], 2),
207
- textPath = _Array$from$[1];
208
- textPath.unshift(0);
209
- Editor.select(this.editor, {
210
- path: textPath,
211
- offset: 0
212
- });
213
- }
214
- }, {
215
- key: "componentWillUnmount",
216
- value: function componentWillUnmount() {
217
- EditorContext.resetEditor();
218
- }
219
- }, {
220
- key: "render",
221
- value: function render() {
222
- var editor = this.editor;
223
- var _this$state = this.state,
224
- value = _this$state.value,
225
- commentPosition = _this$state.commentPosition;
226
- var addCommentClass = 'iconfont icon-plus-square seafile-viewer-comment-btn';
227
-
228
- // link detail message
229
- var toolbarStatus = this.editorUtils.getToolbarStatus();
230
- var selectionCollapsed = isRangeCollapsed(editor.selection);
231
- return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Slate, {
232
- editor: this.editor,
233
- value: value,
234
- onChange: this.onChange
235
- }, /*#__PURE__*/React.createElement("div", {
236
- className: "editor-container align-self-start",
237
- ref: this.setEditorContainerRef
238
- }, /*#__PURE__*/React.createElement("div", {
239
- ref: this.setEditorRef,
240
- onClick: this.onFocusEditor,
241
- className: "editor article"
242
- }, /*#__PURE__*/React.createElement(Editable, {
243
- autoFocus: true,
244
- className: "editor-component",
245
- renderElement: function renderElement(props) {
246
- return renderNode(props, editor);
247
- },
248
- renderLeaf: renderLeaf,
249
- decorate: decorationNode,
250
- onCut: this.onCut,
251
- onCopy: this.onCopy,
252
- onKeyDown: this.onKeyDown,
253
- onSelect: this.updateCommentBtnPosition,
254
- onContextMenu: this.onContextMenu
255
- }), /*#__PURE__*/React.createElement("i", {
256
- className: addCommentClass,
257
- ref: this.setCommentRef,
258
- onMouseDown: this.addComment
259
- })))), /*#__PURE__*/React.createElement(Fragment, null, toolbarStatus.isLinkActive && selectionCollapsed && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(TextLinkHoverMenu, {
260
- onToggleLinkDialog: this.onToggleLinkDialog,
261
- editorUtils: this.editorUtils
262
- })), this.state.isShowContextMenu && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(ContextMenu, {
263
- tableUtils: this.tableUtils,
264
- contextMenuPosition: this.contextMenuPosition
265
- })), this.state.showCommentDialog && /*#__PURE__*/React.createElement(CommentDialog, {
266
- quote: this.quote,
267
- editorApi: this.editor.editorApi,
268
- commentPosition: commentPosition,
269
- onCommentAdded: this.onCommentAdded,
270
- toggleCommentDialog: this.toggleCommentDialog
271
- }), this.state.isShowLinkDialog && /*#__PURE__*/React.createElement(AddLinkDialog, {
272
- toggleLinkDialog: this.onToggleLinkDialog
273
- })));
274
- }
275
- }]);
276
- return MarkdownEditor;
277
- }(React.Component);
278
- export default withTranslation('seafile-editor', {
279
- withRef: true
280
- })(MarkdownEditor);
@@ -1,285 +0,0 @@
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 isHotkey from 'is-hotkey';
7
- import { withTranslation } from 'react-i18next';
8
- import Prism from 'prismjs';
9
- import toaster from '../components/toast';
10
- import { processor } from '../utils/seafile-markdown2html';
11
- import '../assets/editor/plain-editor.css';
12
- var className = require('classnames');
13
- var lodash = require('lodash');
14
- require('codemirror/lib/codemirror.css');
15
- require('codemirror/mode/markdown/markdown');
16
- require('prismjs/themes/prism.css');
17
- require('../assets/css/markdown-editor.css');
18
- var CodeMirror = /*#__PURE__*/function (_React$Component) {
19
- _inherits(CodeMirror, _React$Component);
20
- var _super = _createSuper(CodeMirror);
21
- function CodeMirror() {
22
- var _this;
23
- _classCallCheck(this, CodeMirror);
24
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
25
- args[_key] = arguments[_key];
26
- }
27
- _this = _super.call.apply(_super, [this].concat(args));
28
- _this.state = {
29
- isFocused: false
30
- };
31
- _this.focus = function () {
32
- if (_this.codeMirror) {
33
- _this.codeMirror.focus();
34
- }
35
- };
36
- _this.focusChanged = function (focused) {
37
- _this.setState({
38
- isFocused: focused
39
- });
40
- _this.props.onFocusChange && _this.props.onFocusChange(focused);
41
- };
42
- _this.cursorActivity = function (cm) {
43
- _this.props.onCursorActivity && _this.props.onCursorActivity(cm);
44
- };
45
- _this.scrollChanged = function (cm) {
46
- _this.props.onScroll && _this.props.onScroll(cm.getScrollInfo());
47
- };
48
- _this.codemirrorValueChanged = function (doc, change) {
49
- if (_this.props.onChange && change.origin !== 'setValue') {
50
- _this.props.onChange(doc.getValue(), change);
51
- }
52
- };
53
- return _this;
54
- }
55
- _createClass(CodeMirror, [{
56
- key: "getCodeMirrorInstance",
57
- value: function getCodeMirrorInstance() {
58
- return this.props.codeMirrorInstance || require('codemirror');
59
- }
60
- }, {
61
- key: "componentWillMount",
62
- value: function componentWillMount() {
63
- if (this.props.path) {
64
- console.error('Warning: react-codemirror: the `path` prop has been changed to `name`');
65
- }
66
- }
67
- }, {
68
- key: "componentDidMount",
69
- value: function componentDidMount() {
70
- var codeMirrorInstance = this.getCodeMirrorInstance();
71
- this.codeMirror = codeMirrorInstance.fromTextArea(this.textareaNode, this.props.options);
72
- this.codeMirror.on('change', this.codemirrorValueChanged);
73
- this.codeMirror.on('cursorActivity', this.cursorActivity);
74
- this.codeMirror.on('focus', this.focusChanged.bind(this, true));
75
- this.codeMirror.on('blur', this.focusChanged.bind(this, false));
76
- this.codeMirror.on('scroll', this.scrollChanged);
77
- }
78
- }, {
79
- key: "componentWillUnmount",
80
- value: function componentWillUnmount() {
81
- // is there a lighter-weight way to remove the cm instance?
82
- if (this.codeMirror) {
83
- this.codeMirror.toTextArea();
84
- }
85
- }
86
- }, {
87
- key: "componentWillReceiveProps",
88
- value: function componentWillReceiveProps(nextProps) {
89
- if (this.codeMirror && nextProps.initialValue !== undefined && nextProps.initialValue !== this.props.initialValue) {
90
- if (this.props.preserveScrollPosition) {
91
- var prevScrollPosition = this.codeMirror.getScrollInfo();
92
- this.codeMirror.setValue(nextProps.initialValue);
93
- this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);
94
- } else {
95
- this.codeMirror.setValue(nextProps.initialValue);
96
- }
97
- }
98
- }
99
- }, {
100
- key: "render",
101
- value: function render() {
102
- var _this2 = this;
103
- var editorClassName = className('ReactCodeMirror', this.state.isFocused ? 'ReactCodeMirror--focused' : null, this.props.className);
104
- return /*#__PURE__*/React.createElement("div", {
105
- className: editorClassName
106
- }, /*#__PURE__*/React.createElement("textarea", {
107
- ref: function ref(_ref) {
108
- return _this2.textareaNode = _ref;
109
- },
110
- name: this.props.name || this.props.path,
111
- defaultValue: this.props.initialValue,
112
- autoComplete: "off",
113
- autoFocus: this.props.autoFocus
114
- }));
115
- }
116
- }]);
117
- return CodeMirror;
118
- }(React.Component);
119
- /*
120
-
121
- When loading a new file:
122
-
123
- markdownContent initialValue
124
- index.js -----------------> PlainMarkdownEditor --------> CodeMirror --> Real CodeMirror
125
-
126
- When user type in CodeMirror
127
-
128
- value value
129
- Real CodeMirror ------> CodeMirror ------> PlainMarkdownEditor
130
-
131
- On Save:
132
-
133
- value
134
- MarkdownEditor -----> index.js
135
-
136
- */
137
- var PlainMarkdownEditor = /*#__PURE__*/function (_React$Component2) {
138
- _inherits(PlainMarkdownEditor, _React$Component2);
139
- var _super2 = _createSuper(PlainMarkdownEditor);
140
- function PlainMarkdownEditor(props) {
141
- var _this3;
142
- _classCallCheck(this, PlainMarkdownEditor);
143
- _this3 = _super2.call(this, props);
144
- _this3.state = {
145
- html: '',
146
- leftIsBindScroll: false,
147
- rightIsBindScroll: false
148
- };
149
- /*
150
- * the data about scroll, these variable has nothing to width react
151
- * they are not state
152
- * */
153
- _this3.scrollData = {
154
- scrollPercentage: 0,
155
- leftPanel: null,
156
- rightPanel: null
157
- };
158
- _this3.updateCode = function (newCode) {
159
- _this3.props.onChange(newCode);
160
- };
161
- _this3.onLeftScroll = function (e) {
162
- var srcElement = _this3.scrollData.leftPanel;
163
- _this3.scrollData.scrollPercentage = srcElement.scrollTop / srcElement.scrollHeight;
164
- _this3.scrollData.rightPanel.scrollTop = _this3.scrollData.scrollPercentage * _this3.scrollData.rightPanel.scrollHeight;
165
- };
166
- _this3.onRightScroll = function (e) {
167
- var srcElement = _this3.scrollData.rightPanel;
168
- _this3.scrollData.scrollPercentage = srcElement.scrollTop / srcElement.scrollHeight;
169
- _this3.scrollData.leftPanel.scrollTop = _this3.scrollData.scrollPercentage * _this3.scrollData.leftPanel.scrollHeight;
170
- };
171
- _this3.onEnterLeftPanel = function () {
172
- _this3.setState({
173
- leftIsBindScroll: true
174
- });
175
- };
176
- _this3.onLeaveLeftPanel = function () {
177
- _this3.setState({
178
- leftIsBindScroll: false
179
- });
180
- };
181
- _this3.onEnterRightPanel = function () {
182
- _this3.setState({
183
- rightIsBindScroll: true
184
- });
185
- };
186
- _this3.onLeaveRightPanel = function () {
187
- _this3.setState({
188
- rightIsBindScroll: false
189
- });
190
- };
191
- _this3.onHotKey = function (event) {
192
- if (isHotkey('mod+s', event)) {
193
- event.preventDefault();
194
- _this3.props.onSave(event);
195
- return true;
196
- }
197
- };
198
- _this3.options = {
199
- lineNumbers: true,
200
- mode: 'markdown',
201
- lineWrapping: true,
202
- scrollbarStyle: null
203
- };
204
- _this3.setContent = lodash.throttle(_this3.setContent, 1000);
205
- return _this3;
206
- }
207
- _createClass(PlainMarkdownEditor, [{
208
- key: "setContent",
209
- value: function setContent(markdownContent) {
210
- var _this4 = this;
211
- processor.process(markdownContent, function (error, vfile) {
212
- var html = String(vfile);
213
- _this4.setState({
214
- html: html
215
- });
216
- });
217
- }
218
- }, {
219
- key: "componentDidMount",
220
- value: function componentDidMount() {
221
- // get relevant dom when component mounted instead of get them when scrolling to improve performance
222
- this.scrollData.leftPanel = document.querySelector('.plain-editor-left-panel');
223
- this.scrollData.rightPanel = document.querySelector('.plain-editor-right-panel');
224
- this.setContent(this.props.currentContent);
225
-
226
- // notify current user if others are also editing this file
227
- var editingUsers = this.props.collabUsers.filter(function (ele) {
228
- return ele.is_editing === true && ele.myself === undefined;
229
- });
230
- if (editingUsers.length > 0) {
231
- toaster.danger('Another user is editing this file!', {
232
- duration: 3
233
- });
234
- }
235
- }
236
- }, {
237
- key: "componentWillReceiveProps",
238
- value: function componentWillReceiveProps(nextProps) {
239
- this.setContent(nextProps.currentContent);
240
- }
241
- }, {
242
- key: "componentDidUpdate",
243
- value: function componentDidUpdate() {
244
- Prism.highlightAll();
245
- // render math formula
246
- window.MathJax.typesetPromise(document.querySelectorAll('.math-display'));
247
- }
248
- }, {
249
- key: "render",
250
- value: function render() {
251
- return /*#__PURE__*/React.createElement("div", {
252
- className: "plain-editor seafile-editor-module"
253
- }, /*#__PURE__*/React.createElement("div", {
254
- className: "plain-editor-main d-flex"
255
- }, /*#__PURE__*/React.createElement("div", {
256
- className: "plain-editor-left-panel",
257
- onKeyDown: this.onHotKey,
258
- onMouseLeave: this.onLeaveLeftPanel,
259
- onMouseEnter: this.onEnterLeftPanel,
260
- onScroll: this.state.leftIsBindScroll ? this.onLeftScroll : null
261
- }, /*#__PURE__*/React.createElement(CodeMirror, {
262
- initialValue: this.props.initialValue,
263
- onChange: this.updateCode,
264
- options: this.options
265
- })), /*#__PURE__*/React.createElement("div", {
266
- className: "plain-editor-right-panel",
267
- onMouseEnter: this.onEnterRightPanel,
268
- onMouseLeave: this.onLeaveRightPanel,
269
- onScroll: this.state.rightIsBindScroll ? this.onRightScroll : null
270
- }, /*#__PURE__*/React.createElement("div", {
271
- className: "preview"
272
- }, /*#__PURE__*/React.createElement("div", {
273
- className: "rendered-markdown article",
274
- dangerouslySetInnerHTML: {
275
- __html: this.state.html
276
- }
277
- })))));
278
- }
279
- }]);
280
- return PlainMarkdownEditor;
281
- }(React.Component);
282
- PlainMarkdownEditor.defaultProps = {
283
- collabUsers: []
284
- };
285
- export default withTranslation('seafile-editor')(PlainMarkdownEditor);