@seafile/seafile-editor 0.3.97 → 0.3.100

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 (92) hide show
  1. package/dist/_i18n/index.js +20 -0
  2. package/dist/assets/css/comment-dialog.css +50 -0
  3. package/dist/{css → assets/css}/diff-viewer.css +0 -0
  4. package/dist/{css/richeditor → assets/css}/formula.css +0 -0
  5. package/dist/{css → assets/css}/history-viewer.css +0 -0
  6. package/dist/{css/richeditor → assets/css}/image.css +0 -0
  7. package/dist/{index.css → assets/css/index.css} +0 -0
  8. package/dist/assets/css/issue-card.css +43 -0
  9. package/dist/{css → assets/css}/keyboard-shortcuts.css +0 -0
  10. package/dist/{css/richeditor → assets/css}/link.css +0 -0
  11. package/dist/{css/plaineditor → assets/css}/markdown-editor.css +0 -0
  12. package/dist/{css → assets/css}/markdown-viewer.css +0 -0
  13. package/dist/{css/richeditor → assets/css}/navbar-imgbutton.css +0 -0
  14. package/dist/assets/css/outline.css +29 -0
  15. package/dist/{css/richeditor → assets/css}/table.css +0 -0
  16. package/dist/{css/richeditor → assets/css}/textlink-hovermenu.css +0 -0
  17. package/dist/{css → assets/css}/topbar.css +19 -33
  18. package/dist/{css/richeditor → assets/css}/tree-view.css +0 -0
  19. package/dist/{css/richeditor/right-panel.css → assets/css/user-help.css} +9 -9
  20. package/dist/assets/editor/plain-editor.css +30 -0
  21. package/dist/assets/editor/rich-editor.css +104 -0
  22. package/dist/assets/editor/simple-editor.css +77 -0
  23. package/dist/{css/richeditor → assets/rich-editor}/document-info.css +0 -0
  24. package/dist/components/add-formula-dialog.js +6 -4
  25. package/dist/components/add-image-dialog.js +3 -1
  26. package/dist/components/add-link-dialog.js +4 -3
  27. package/dist/components/comment-dialog.js +12 -6
  28. package/dist/components/markdown-lint.js +1 -0
  29. package/dist/components/outline/index.js +97 -0
  30. package/dist/components/outline/outline-item.js +70 -0
  31. package/dist/components/shortcut-dialog.js +26 -51
  32. package/dist/components/{topbar-component → toolbar}/header-list.js +0 -0
  33. package/dist/components/toolbar/help-group.js +40 -0
  34. package/dist/components/toolbar/index.js +4 -0
  35. package/dist/components/{topbar-component/upload-img.js → toolbar/insert-image.js} +18 -15
  36. package/dist/components/toolbar/insert-table.js +155 -0
  37. package/dist/components/toolbar/table-group.js +82 -0
  38. package/dist/components/{toolbar.js → toolbar/toolbar.js} +102 -64
  39. package/dist/components/{topbar-component → toolbar/widgets}/button-group.js +0 -0
  40. package/dist/components/toolbar/widgets/button-item.js +144 -0
  41. package/dist/components/toolbar/widgets/drop-list.js +101 -0
  42. package/dist/components/user-help.js +16 -10
  43. package/dist/editor/controller/block-element-controller.js +6 -2
  44. package/dist/editor/controller/inline-element-controller.js +6 -2
  45. package/dist/editor/editor-builder.js +107 -0
  46. package/dist/editor/editor-component/formula.js +4 -2
  47. package/dist/editor/editor-component/image.js +10 -6
  48. package/dist/editor/editor-component/table.js +1 -1
  49. package/dist/editor/editor-plugin.js +3 -1
  50. package/dist/editor/editor.js +1 -32
  51. package/dist/editor/index.js +97 -0
  52. package/dist/editor/markdown-editor.js +323 -0
  53. package/dist/editor/plain-markdown-editor.js +5 -4
  54. package/dist/editor/rich-markdown-editor.js +70 -149
  55. package/dist/editor/simple-editor.js +44 -78
  56. package/dist/{css/richeditor → example/assets/css}/comments-list.css +0 -45
  57. package/dist/{css/richeditor → example/assets/css}/detail-list-view.css +0 -0
  58. package/dist/{css/richeditor → example/assets/css}/participants-list.css +0 -0
  59. package/dist/{css → example/assets/css}/react-mentions-default-style.js +0 -0
  60. package/dist/example/assets/css/seafile-editor-main.css +125 -0
  61. package/dist/example/assets/css/seafile-editor-side.css +89 -0
  62. package/dist/example/assets/css/side-panel.css +81 -0
  63. package/dist/{components → example/components}/comment-panel.js +12 -6
  64. package/dist/{components → example/components}/detail-list-view.js +1 -1
  65. package/dist/{components → example/components}/participants-list.js +1 -1
  66. package/dist/{components → example/components}/side-panel.js +5 -7
  67. package/dist/example/seafile-editor.js +137 -0
  68. package/dist/index.js +9 -0
  69. package/dist/index.local.js +58 -0
  70. package/dist/pages/seafile-editor/index.js +38 -0
  71. package/dist/{editor → pages/seafile-editor}/seafile-editor.js +19 -35
  72. package/dist/{seafile-editor-chooser.js → pages/seafile-editor-chooser.js} +0 -0
  73. package/dist/{seafile-markdown-editor.js → pages/seafile-markdown-editor.js} +5 -5
  74. package/dist/{seafile-markdown-viewer.js → pages/seafile-markdown-viewer.js} +3 -3
  75. package/dist/{seafile-simple-editor.js → pages/seafile-simple-editor.js} +5 -2
  76. package/dist/viewer/diff-viewer.js +1 -1
  77. package/dist/viewer/markdown-viewer.js +14 -15
  78. package/dist/viewer/slate-viewer.js +9 -24
  79. package/dist/viewer/viewer-formula.js +1 -1
  80. package/package.json +6 -14
  81. package/public/locales/zh-CN/seafile-editor.json +15 -13
  82. package/dist/components/generate-share-link.js +0 -412
  83. package/dist/components/internal-link-dialog.js +0 -96
  84. package/dist/components/outline.js +0 -130
  85. package/dist/components/topbar-component/icon-button.js +0 -99
  86. package/dist/components/topbar-component/insert-file.js +0 -67
  87. package/dist/components/topbar-component/table-toolbar.js +0 -175
  88. package/dist/config-0.js +0 -15
  89. package/dist/css/layout.css +0 -111
  90. package/dist/css/markdown-viewer-slate/file-tags-list.css +0 -76
  91. package/dist/css/richeditor/rich-editor-main.css +0 -32
  92. package/dist/css/richeditor/side-panel.css +0 -183
@@ -0,0 +1,323 @@
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 { renderNode, renderLeaf, decorationNode } from './editor-utils/common-editor-utils';
9
+ import { Node, Editor, Range } from 'slate';
10
+ import { Editable, Slate, ReactEditor } from '@seafile/slate-react';
11
+ import toaster from '../components/toast';
12
+ import ModalPortal from '../components/modal-portal';
13
+ import ContextMenu from '../components/context-menu';
14
+ import CommentDialog from '../components/comment-dialog';
15
+ import { serialize } from '../utils/slate2markdown/index';
16
+ import TextLinkHoverMenu from './editor-component/textlink-hovermenu';
17
+ import { isRangeCollapsed } from './editor-utils/range-utils';
18
+ import EditorBuilder from './editor-builder';
19
+ import '../assets/css/navbar-imgbutton.css';
20
+ import '../assets/css/textlink-hovermenu.css';
21
+ import '../assets/css/image.css';
22
+ import '../assets/css/link.css';
23
+ import '../assets/css/tree-view.css';
24
+
25
+ var MarkdownEditor = /*#__PURE__*/function (_React$Component) {
26
+ _inherits(MarkdownEditor, _React$Component);
27
+
28
+ var _super = _createSuper(MarkdownEditor);
29
+
30
+ function MarkdownEditor(props) {
31
+ var _this;
32
+
33
+ _classCallCheck(this, MarkdownEditor);
34
+
35
+ _this = _super.call(this, props);
36
+
37
+ _this.getDomNodeByPath = function (path) {
38
+ var node,
39
+ parent = document.querySelector('.editor-component');
40
+
41
+ while (typeof path[0] === 'number' && parent) {
42
+ node = parent.children[path[0]];
43
+ path.shift();
44
+ parent = node;
45
+ }
46
+
47
+ return node;
48
+ };
49
+
50
+ _this.updateCommentBtnPosition = function () {
51
+ if (!_this.props.isSupportComment) return;
52
+ if (_this.timer) return;
53
+ _this.timer = setTimeout(function () {
54
+ var selection = _this.editor.selection;
55
+
56
+ if (!selection || Range.isCollapsed(selection)) {
57
+ var _style = _this.commentRef.style;
58
+ _style.top = '-1000px';
59
+ clearTimeout(_this.timer);
60
+ _this.timer = null;
61
+ return;
62
+ }
63
+
64
+ var focusNodePath = selection.anchor.path.slice();
65
+ focusNodePath.pop();
66
+
67
+ var focusNode = _this.getDomNodeByPath(focusNodePath);
68
+
69
+ var style = _this.commentRef.style;
70
+ style.right = '40px';
71
+
72
+ if (focusNode) {
73
+ style.top = "".concat(focusNode.offsetTop, "px");
74
+ } else {
75
+ style.top = '-1000px';
76
+ }
77
+
78
+ clearTimeout(_this.timer);
79
+ _this.timer = null;
80
+ }, 40);
81
+ };
82
+
83
+ _this.onCommentAdded = function () {
84
+ _this.toggleCommentDialog();
85
+
86
+ _this.props.onAddComment && _this.props.onAddComment();
87
+ };
88
+
89
+ _this.addComment = function (e) {
90
+ e.stopPropagation();
91
+
92
+ _this.getQuote();
93
+
94
+ _this.toggleCommentDialog();
95
+ };
96
+
97
+ _this.toggleCommentDialog = function () {
98
+ _this.setState({
99
+ showCommentDialog: !_this.state.showCommentDialog
100
+ });
101
+ };
102
+
103
+ _this.getQuote = function () {
104
+ _this.quote = serialize(Editor.fragment(_this.editor, _this.editor.selection));
105
+
106
+ _this.setState({
107
+ commentPosition: _this.editor.selection.anchor.path
108
+ });
109
+ };
110
+
111
+ _this.onChange = function (value) {
112
+ _this.setState({
113
+ value: value
114
+ }); // hide context menu when content change
115
+
116
+
117
+ if (_this.state.isShowContextMenu === true) {
118
+ _this.setState({
119
+ isShowContextMenu: false
120
+ });
121
+
122
+ _this.contextMenuPosition = {};
123
+ }
124
+
125
+ _this.props.onChange(value, _this.editor.operations);
126
+ };
127
+
128
+ _this.onFocusEditor = function () {
129
+ var value = _this.state.value;
130
+
131
+ if (value.length === 2 && value[0].type === 'paragraph' && Node.text(value[0].children[0]).length === 0) {
132
+ _this.editorRef.firstChild.focus();
133
+ }
134
+ };
135
+
136
+ _this.addLink = function (fileName, url, isImage) {
137
+ var selection = _this.editor.selection;
138
+
139
+ if (isImage) {
140
+ _this.editorUtils.insertImage({
141
+ url: url,
142
+ selection: selection
143
+ });
144
+
145
+ return;
146
+ }
147
+
148
+ _this.editorUtils.insertLink({
149
+ text: fileName,
150
+ url: url,
151
+ selection: selection
152
+ });
153
+ };
154
+
155
+ _this.scrollToQuote = function (path) {
156
+ if (!path) return;
157
+ var editor = _this.editor;
158
+ var node = editor.children[path[0]];
159
+ var element = ReactEditor.toDOMNode(editor, node);
160
+
161
+ _this.editorContainerRef.scrollTo(0, element.offsetTop);
162
+
163
+ Editor.select(_this.editor, path);
164
+ };
165
+
166
+ _this.scrollToNode = function (node) {
167
+ var editor = document.querySelector('.editor-component');
168
+ var element = editor.childNodes[node.path[0]];
169
+
170
+ _this.editorContainerRef.scrollTo(0, element.offsetTop);
171
+
172
+ window.location.hash = encodeURI(node.children[0].text);
173
+ Editor.select(_this.editor, node.path);
174
+ };
175
+
176
+ _this.onCopy = function (event) {
177
+ _this.plugin.onCopy(event, _this.editor);
178
+ };
179
+
180
+ _this.onCut = function (event) {
181
+ _this.plugin.onCut(event);
182
+ };
183
+
184
+ _this.onKeyDown = function (event) {
185
+ _this.plugin.onKeyDown(event);
186
+ };
187
+
188
+ _this.onContextMenu = function (event) {
189
+ if (_this.tableUtils.isInTable()) {
190
+ event.preventDefault();
191
+ _this.contextMenuPosition = {
192
+ left: event.clientX,
193
+ top: event.clientY
194
+ };
195
+
196
+ _this.setState({
197
+ isShowContextMenu: !_this.state.isShowContextMenu
198
+ });
199
+ }
200
+ };
201
+
202
+ _this.setCommentRef = function (ref) {
203
+ _this.commentRef = ref;
204
+ };
205
+
206
+ _this.setEditorRef = function (ref) {
207
+ _this.editorRef = ref;
208
+ };
209
+
210
+ _this.setEditorContainerRef = function (ref) {
211
+ _this.editorContainerRef = ref;
212
+ };
213
+
214
+ _this.state = {
215
+ value: props.value,
216
+ isShowContextMenu: false,
217
+ showCommentDialog: false,
218
+ commentPosition: null
219
+ };
220
+ _this.editor = EditorBuilder.getEditor(props);
221
+ _this.plugin = EditorBuilder.getPlugin();
222
+ _this.tableUtils = EditorBuilder.getTableUtils();
223
+ _this.editorUtils = EditorBuilder.getEditorUtils();
224
+ _this.contextMenuPosition = {};
225
+ return _this;
226
+ }
227
+
228
+ _createClass(MarkdownEditor, [{
229
+ key: "componentDidCatch",
230
+ value: function componentDidCatch(error) {
231
+ this.props.resetRichValue();
232
+ console.log(error);
233
+ }
234
+ }, {
235
+ key: "componentDidMount",
236
+ value: function componentDidMount() {
237
+ window.abcdef_editor = this;
238
+ var t = this.props.t;
239
+ var userAgent = navigator.userAgent.toLowerCase();
240
+
241
+ if (userAgent.indexOf('chrome') === -1) {
242
+ var message = t('Editing_files_in_this_browser_can_lead_to_slight_display_problems');
243
+ toaster.warning(message, {
244
+ duration: 4
245
+ });
246
+ } // get first text node of the document and focus at the start of the text node
247
+
248
+
249
+ var _Array$from$ = _slicedToArray(Array.from(Node.texts(this.editor.children[0]))[0], 2),
250
+ textPath = _Array$from$[1];
251
+
252
+ textPath.unshift(0);
253
+ Editor.select(this.editor, {
254
+ path: textPath,
255
+ offset: 0
256
+ });
257
+ }
258
+ }, {
259
+ key: "componentWillUnmount",
260
+ value: function componentWillUnmount() {
261
+ EditorBuilder.resetEditor();
262
+ }
263
+ }, {
264
+ key: "render",
265
+ value: function render() {
266
+ var editor = this.editor;
267
+ var _this$state = this.state,
268
+ value = _this$state.value,
269
+ commentPosition = _this$state.commentPosition;
270
+ var addCommentClass = 'iconfont icon-plus-square seafile-viewer-comment-btn'; // link detail message
271
+
272
+ var toolbarStatus = this.editorUtils.getToolbarStatus();
273
+ var selectionCollapsed = isRangeCollapsed(editor.selection);
274
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Slate, {
275
+ editor: this.editor,
276
+ value: value,
277
+ onChange: this.onChange
278
+ }, /*#__PURE__*/React.createElement("div", {
279
+ className: "editor-container align-self-start",
280
+ ref: this.setEditorContainerRef
281
+ }, /*#__PURE__*/React.createElement("div", {
282
+ ref: this.setEditorRef,
283
+ onClick: this.onFocusEditor,
284
+ className: "editor article"
285
+ }, /*#__PURE__*/React.createElement(Editable, {
286
+ autoFocus: true,
287
+ className: "editor-component",
288
+ renderElement: function renderElement(props) {
289
+ return renderNode(props, editor);
290
+ },
291
+ renderLeaf: renderLeaf,
292
+ decorate: decorationNode,
293
+ onCut: this.onCut,
294
+ onCopy: this.onCopy,
295
+ onKeyDown: this.onKeyDown,
296
+ onSelect: this.updateCommentBtnPosition,
297
+ onContextMenu: this.onContextMenu
298
+ }), /*#__PURE__*/React.createElement("i", {
299
+ className: addCommentClass,
300
+ ref: this.setCommentRef,
301
+ onMouseDown: this.addComment
302
+ })))), /*#__PURE__*/React.createElement(Fragment, null, toolbarStatus.isLinkActive && selectionCollapsed && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(TextLinkHoverMenu, {
303
+ onToggleLinkDialog: this.onToggleLinkDialog,
304
+ editorUtils: this.editorUtils
305
+ })), this.state.isShowContextMenu && /*#__PURE__*/React.createElement(ModalPortal, null, /*#__PURE__*/React.createElement(ContextMenu, {
306
+ tableUtils: this.tableUtils,
307
+ contextMenuPosition: this.contextMenuPosition
308
+ })), this.state.showCommentDialog && /*#__PURE__*/React.createElement(CommentDialog, {
309
+ quote: this.quote,
310
+ editorApi: this.editor.editorApi,
311
+ commentPosition: commentPosition,
312
+ onCommentAdded: this.onCommentAdded,
313
+ toggleCommentDialog: this.toggleCommentDialog
314
+ })));
315
+ }
316
+ }]);
317
+
318
+ return MarkdownEditor;
319
+ }(React.Component);
320
+
321
+ export default withTranslation('seafile-editor', {
322
+ withRef: true
323
+ })(MarkdownEditor);
@@ -8,6 +8,7 @@ import toaster from '../components/toast';
8
8
  import isHotkey from 'is-hotkey';
9
9
  import { withTranslation } from 'react-i18next';
10
10
  import Prism from 'prismjs';
11
+ import '../assets/editor/plain-editor.css';
11
12
 
12
13
  var className = require('classnames');
13
14
 
@@ -17,10 +18,10 @@ require('codemirror/lib/codemirror.css');
17
18
 
18
19
  require('codemirror/mode/markdown/markdown');
19
20
 
20
- require('../css/plaineditor/markdown-editor.css');
21
-
22
21
  require('prismjs/themes/prism.css');
23
22
 
23
+ require('../assets/css/markdown-editor.css');
24
+
24
25
  var CodeMirror = /*#__PURE__*/function (_React$Component) {
25
26
  _inherits(CodeMirror, _React$Component);
26
27
 
@@ -286,9 +287,9 @@ var PlainMarkdownEditor = /*#__PURE__*/function (_React$Component2) {
286
287
  key: "render",
287
288
  value: function render() {
288
289
  return /*#__PURE__*/React.createElement("div", {
289
- className: "seafile-editor-module seafile-editor"
290
+ className: "plain-editor seafile-editor-module"
290
291
  }, /*#__PURE__*/React.createElement("div", {
291
- className: "seafile-editor-main plain-editor-main d-flex"
292
+ className: "plain-editor-main d-flex"
292
293
  }, /*#__PURE__*/React.createElement("div", {
293
294
  className: "plain-editor-left-panel",
294
295
  onKeyDown: this.onHotKey,