@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,324 @@
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 { processor } from '../utils/seafile-markdown2html';
7
+ import toaster from '../components/toast';
8
+ import isHotkey from 'is-hotkey';
9
+ import { withTranslation } from 'react-i18next';
10
+ import Prism from 'prismjs';
11
+
12
+ var className = require('classnames');
13
+
14
+ var lodash = require('lodash');
15
+
16
+ require('codemirror/lib/codemirror.css');
17
+
18
+ require('codemirror/mode/markdown/markdown');
19
+
20
+ require('../css/plaineditor/markdown-editor.css');
21
+
22
+ require('prismjs/themes/prism.css');
23
+
24
+ var CodeMirror = /*#__PURE__*/function (_React$Component) {
25
+ _inherits(CodeMirror, _React$Component);
26
+
27
+ var _super = _createSuper(CodeMirror);
28
+
29
+ function CodeMirror() {
30
+ var _this;
31
+
32
+ _classCallCheck(this, CodeMirror);
33
+
34
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
35
+ args[_key] = arguments[_key];
36
+ }
37
+
38
+ _this = _super.call.apply(_super, [this].concat(args));
39
+ _this.state = {
40
+ isFocused: false
41
+ };
42
+
43
+ _this.focus = function () {
44
+ if (_this.codeMirror) {
45
+ _this.codeMirror.focus();
46
+ }
47
+ };
48
+
49
+ _this.focusChanged = function (focused) {
50
+ _this.setState({
51
+ isFocused: focused
52
+ });
53
+
54
+ _this.props.onFocusChange && _this.props.onFocusChange(focused);
55
+ };
56
+
57
+ _this.cursorActivity = function (cm) {
58
+ _this.props.onCursorActivity && _this.props.onCursorActivity(cm);
59
+ };
60
+
61
+ _this.scrollChanged = function (cm) {
62
+ _this.props.onScroll && _this.props.onScroll(cm.getScrollInfo());
63
+ };
64
+
65
+ _this.codemirrorValueChanged = function (doc, change) {
66
+ if (_this.props.onChange && change.origin !== 'setValue') {
67
+ _this.props.onChange(doc.getValue(), change);
68
+ }
69
+ };
70
+
71
+ return _this;
72
+ }
73
+
74
+ _createClass(CodeMirror, [{
75
+ key: "getCodeMirrorInstance",
76
+ value: function getCodeMirrorInstance() {
77
+ return this.props.codeMirrorInstance || require('codemirror');
78
+ }
79
+ }, {
80
+ key: "componentWillMount",
81
+ value: function componentWillMount() {
82
+ if (this.props.path) {
83
+ console.error('Warning: react-codemirror: the `path` prop has been changed to `name`');
84
+ }
85
+ }
86
+ }, {
87
+ key: "componentDidMount",
88
+ value: function componentDidMount() {
89
+ var codeMirrorInstance = this.getCodeMirrorInstance();
90
+ this.codeMirror = codeMirrorInstance.fromTextArea(this.textareaNode, this.props.options);
91
+ this.codeMirror.on('change', this.codemirrorValueChanged);
92
+ this.codeMirror.on('cursorActivity', this.cursorActivity);
93
+ this.codeMirror.on('focus', this.focusChanged.bind(this, true));
94
+ this.codeMirror.on('blur', this.focusChanged.bind(this, false));
95
+ this.codeMirror.on('scroll', this.scrollChanged);
96
+ }
97
+ }, {
98
+ key: "componentWillUnmount",
99
+ value: function componentWillUnmount() {
100
+ // is there a lighter-weight way to remove the cm instance?
101
+ if (this.codeMirror) {
102
+ this.codeMirror.toTextArea();
103
+ }
104
+ }
105
+ }, {
106
+ key: "componentWillReceiveProps",
107
+ value: function componentWillReceiveProps(nextProps) {
108
+ if (this.codeMirror && nextProps.initialValue !== undefined && nextProps.initialValue !== this.props.initialValue) {
109
+ if (this.props.preserveScrollPosition) {
110
+ var prevScrollPosition = this.codeMirror.getScrollInfo();
111
+ this.codeMirror.setValue(nextProps.initialValue);
112
+ this.codeMirror.scrollTo(prevScrollPosition.left, prevScrollPosition.top);
113
+ } else {
114
+ this.codeMirror.setValue(nextProps.initialValue);
115
+ }
116
+ }
117
+ }
118
+ }, {
119
+ key: "render",
120
+ value: function render() {
121
+ var _this2 = this;
122
+
123
+ var editorClassName = className('ReactCodeMirror', this.state.isFocused ? 'ReactCodeMirror--focused' : null, this.props.className);
124
+ return /*#__PURE__*/React.createElement("div", {
125
+ className: editorClassName
126
+ }, /*#__PURE__*/React.createElement("textarea", {
127
+ ref: function ref(_ref) {
128
+ return _this2.textareaNode = _ref;
129
+ },
130
+ name: this.props.name || this.props.path,
131
+ defaultValue: this.props.initialValue,
132
+ autoComplete: "off",
133
+ autoFocus: this.props.autoFocus
134
+ }));
135
+ }
136
+ }]);
137
+
138
+ return CodeMirror;
139
+ }(React.Component);
140
+ /*
141
+
142
+ When loading a new file:
143
+
144
+ markdownContent initialValue
145
+ index.js -----------------> PlainMarkdownEditor --------> CodeMirror --> Real CodeMirror
146
+
147
+ When user type in CodeMirror
148
+
149
+ value value
150
+ Real CodeMirror ------> CodeMirror ------> PlainMarkdownEditor
151
+
152
+ On Save:
153
+
154
+ value
155
+ MarkdownEditor -----> index.js
156
+
157
+ */
158
+
159
+
160
+ var PlainMarkdownEditor = /*#__PURE__*/function (_React$Component2) {
161
+ _inherits(PlainMarkdownEditor, _React$Component2);
162
+
163
+ var _super2 = _createSuper(PlainMarkdownEditor);
164
+
165
+ function PlainMarkdownEditor(props) {
166
+ var _this3;
167
+
168
+ _classCallCheck(this, PlainMarkdownEditor);
169
+
170
+ _this3 = _super2.call(this, props);
171
+ _this3.state = {
172
+ html: '',
173
+ leftIsBindScroll: false,
174
+ rightIsBindScroll: false
175
+ };
176
+ _this3.scrollData = {
177
+ scrollPercentage: 0,
178
+ leftPanel: null,
179
+ rightPanel: null
180
+ };
181
+
182
+ _this3.updateCode = function (newCode) {
183
+ _this3.props.onChange(newCode);
184
+ };
185
+
186
+ _this3.onLeftScroll = function (e) {
187
+ var srcElement = _this3.scrollData.leftPanel;
188
+ _this3.scrollData.scrollPercentage = srcElement.scrollTop / srcElement.scrollHeight;
189
+ _this3.scrollData.rightPanel.scrollTop = _this3.scrollData.scrollPercentage * _this3.scrollData.rightPanel.scrollHeight;
190
+ };
191
+
192
+ _this3.onRightScroll = function (e) {
193
+ var srcElement = _this3.scrollData.rightPanel;
194
+ _this3.scrollData.scrollPercentage = srcElement.scrollTop / srcElement.scrollHeight;
195
+ _this3.scrollData.leftPanel.scrollTop = _this3.scrollData.scrollPercentage * _this3.scrollData.leftPanel.scrollHeight;
196
+ };
197
+
198
+ _this3.onEnterLeftPanel = function () {
199
+ _this3.setState({
200
+ leftIsBindScroll: true
201
+ });
202
+ };
203
+
204
+ _this3.onLeaveLeftPanel = function () {
205
+ _this3.setState({
206
+ leftIsBindScroll: false
207
+ });
208
+ };
209
+
210
+ _this3.onEnterRightPanel = function () {
211
+ _this3.setState({
212
+ rightIsBindScroll: true
213
+ });
214
+ };
215
+
216
+ _this3.onLeaveRightPanel = function () {
217
+ _this3.setState({
218
+ rightIsBindScroll: false
219
+ });
220
+ };
221
+
222
+ _this3.onHotKey = function (event) {
223
+ if (isHotkey('mod+s', event)) {
224
+ event.preventDefault();
225
+
226
+ _this3.props.onSave(event);
227
+
228
+ return true;
229
+ }
230
+ };
231
+
232
+ _this3.options = {
233
+ lineNumbers: true,
234
+ mode: 'markdown',
235
+ lineWrapping: true,
236
+ scrollbarStyle: null
237
+ };
238
+ _this3.setContent = lodash.throttle(_this3.setContent, 1000);
239
+ return _this3;
240
+ }
241
+
242
+ _createClass(PlainMarkdownEditor, [{
243
+ key: "setContent",
244
+ value: function setContent(markdownContent) {
245
+ var _this4 = this;
246
+
247
+ processor.process(markdownContent, function (error, vfile) {
248
+ var html = String(vfile);
249
+
250
+ _this4.setState({
251
+ html: html
252
+ });
253
+ });
254
+ }
255
+ }, {
256
+ key: "componentDidMount",
257
+ value: function componentDidMount() {
258
+ // get relevant dom when component mounted instead of get them when scrolling to improve performance
259
+ this.scrollData.leftPanel = document.querySelector('.plain-editor-left-panel');
260
+ this.scrollData.rightPanel = document.querySelector('.plain-editor-right-panel');
261
+ this.setContent(this.props.currentContent); // notify current user if others are also editing this file
262
+
263
+ var editingUsers = this.props.collabUsers.filter(function (ele) {
264
+ return ele.is_editing === true && ele.myself === undefined;
265
+ });
266
+
267
+ if (editingUsers.length > 0) {
268
+ toaster.danger('Another user is editing this file!', {
269
+ duration: 3
270
+ });
271
+ }
272
+ }
273
+ }, {
274
+ key: "componentWillReceiveProps",
275
+ value: function componentWillReceiveProps(nextProps) {
276
+ this.setContent(nextProps.currentContent);
277
+ }
278
+ }, {
279
+ key: "componentDidUpdate",
280
+ value: function componentDidUpdate() {
281
+ Prism.highlightAll(); // render math formula
282
+
283
+ window.MathJax.typesetPromise(document.querySelectorAll('.math-display'));
284
+ }
285
+ }, {
286
+ key: "render",
287
+ value: function render() {
288
+ return /*#__PURE__*/React.createElement("div", {
289
+ className: "seafile-editor-module seafile-editor"
290
+ }, /*#__PURE__*/React.createElement("div", {
291
+ className: "seafile-editor-main plain-editor-main d-flex"
292
+ }, /*#__PURE__*/React.createElement("div", {
293
+ className: "plain-editor-left-panel",
294
+ onKeyDown: this.onHotKey,
295
+ onMouseLeave: this.onLeaveLeftPanel,
296
+ onMouseEnter: this.onEnterLeftPanel,
297
+ onScroll: this.state.leftIsBindScroll ? this.onLeftScroll : null
298
+ }, /*#__PURE__*/React.createElement(CodeMirror, {
299
+ initialValue: this.props.initialValue,
300
+ onChange: this.updateCode,
301
+ options: this.options
302
+ })), /*#__PURE__*/React.createElement("div", {
303
+ className: "plain-editor-right-panel",
304
+ onMouseEnter: this.onEnterRightPanel,
305
+ onMouseLeave: this.onLeaveRightPanel,
306
+ onScroll: this.state.rightIsBindScroll ? this.onRightScroll : null
307
+ }, /*#__PURE__*/React.createElement("div", {
308
+ className: "preview"
309
+ }, /*#__PURE__*/React.createElement("div", {
310
+ className: "rendered-markdown article",
311
+ dangerouslySetInnerHTML: {
312
+ __html: this.state.html
313
+ }
314
+ })))));
315
+ }
316
+ }]);
317
+
318
+ return PlainMarkdownEditor;
319
+ }(React.Component);
320
+
321
+ PlainMarkdownEditor.defaultProps = {
322
+ collabUsers: []
323
+ };
324
+ export default withTranslation('seafile-editor')(PlainMarkdownEditor);