@seafile/seafile-editor 0.3.99 → 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 (90) 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 +1 -1
  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 +5 -13
  81. package/dist/components/generate-share-link.js +0 -412
  82. package/dist/components/internal-link-dialog.js +0 -96
  83. package/dist/components/outline.js +0 -130
  84. package/dist/components/topbar-component/icon-button.js +0 -99
  85. package/dist/components/topbar-component/insert-file.js +0 -67
  86. package/dist/components/topbar-component/table-toolbar.js +0 -175
  87. package/dist/css/layout.css +0 -111
  88. package/dist/css/markdown-viewer-slate/file-tags-list.css +0 -76
  89. package/dist/css/richeditor/rich-editor-main.css +0 -32
  90. package/dist/css/richeditor/side-panel.css +0 -183
@@ -2,6 +2,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import { Editor, Range } from 'slate';
3
3
  import generateLinkElement from '../element-model/link';
4
4
  import generateImageElement from '../element-model/image';
5
+ import EditorBuilder from '../editor-builder';
5
6
 
6
7
  var withInline = function withInline(editor) {
7
8
  var exec = editor.exec,
@@ -102,8 +103,11 @@ var withInline = function withInline(editor) {
102
103
  break;
103
104
 
104
105
  case 'insert_data':
105
- if (data.types.includes('Files') && data.files[0].type.includes('image') && window.editor.editorApi.uploadLocalImage) {
106
- window.editor.editorApi.uploadLocalImage(command.data.files[0]).then(function (res) {
106
+ var _EditorBuilder$getEdi = EditorBuilder.getEditor(),
107
+ editorApi = _EditorBuilder$getEdi.editorApi;
108
+
109
+ if (data.types.includes('Files') && data.files[0].type.includes('image') && editorApi.uploadLocalImage) {
110
+ editorApi.uploadLocalImage(command.data.files[0]).then(function (res) {
107
111
  var img = generateImageElement({
108
112
  data: {
109
113
  src: res
@@ -0,0 +1,107 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import { createEditor } from 'slate';
4
+ import { withHistory } from 'slate-history';
5
+ import { withReact } from '@seafile/slate-react';
6
+ import withInline from './controller/inline-element-controller';
7
+ import withBlock from './controller/block-element-controller';
8
+ import withVoid from './controller/void-element-controller';
9
+ import withMarkdownShortcut from './controller/shortcut-controller';
10
+ import normalizeNode from './controller/normalize-controller';
11
+ import { EditorUtils } from './editor-utils/common-editor-utils';
12
+ import TableUtils from './editor-utils/block-element-utils/table-utils';
13
+ import Plugin from './editor-plugin';
14
+
15
+ var EditorBuilder = /*#__PURE__*/function () {
16
+ function EditorBuilder() {
17
+ _classCallCheck(this, EditorBuilder);
18
+
19
+ this.editor = null;
20
+ this.plugin = null;
21
+ this.tableUtils = null;
22
+ this.editorUtils = null;
23
+ }
24
+
25
+ _createClass(EditorBuilder, null, [{
26
+ key: "getEditor",
27
+ value: function getEditor(options) {
28
+ if (this.editor && options) {
29
+ if (options && options.onSave) {
30
+ this.editor.onSave = options.onSave;
31
+ }
32
+
33
+ if (options && options.editorApi) {
34
+ this.editor.editorApi = options.editorApi;
35
+ }
36
+ }
37
+
38
+ if (this.editor) return this.editor;
39
+ this.editor = normalizeNode(withMarkdownShortcut(withVoid(withBlock(withInline(withHistory(withReact(createEditor())))))));
40
+
41
+ if (options && options.onSave) {
42
+ this.editor.onSave = options.onSave;
43
+ }
44
+
45
+ if (options && options.editorApi) {
46
+ this.editor.editorApi = options.editorApi;
47
+ }
48
+
49
+ return this.editor;
50
+ }
51
+ }, {
52
+ key: "getSlateEditor",
53
+ value: function getSlateEditor() {
54
+ if (this.editor) this.editor = null;
55
+ this.editor = withInline(withVoid(withReact(createEditor())));
56
+ return this.editor;
57
+ }
58
+ }, {
59
+ key: "resetEditor",
60
+ value: function resetEditor() {
61
+ this.editor = null;
62
+ this.plugin = null;
63
+ this.editorUtils = null;
64
+ this.tableUtils = null;
65
+ }
66
+ }, {
67
+ key: "getEditorRef",
68
+ value: function getEditorRef() {
69
+ var editorRef = window.abcdef_editor;
70
+ return editorRef;
71
+ }
72
+ }, {
73
+ key: "getToolbarRef",
74
+ value: function getToolbarRef() {
75
+ var toolbarRef = window.abcdef_editorToolbar;
76
+ return toolbarRef;
77
+ }
78
+ }, {
79
+ key: "getEditorUtils",
80
+ value: function getEditorUtils() {
81
+ if (this.editorUtils) return this.editorUtils;
82
+ if (!this.editor) this.getEditor();
83
+ this.editorUtils = new EditorUtils(this.editor);
84
+ return this.editorUtils;
85
+ }
86
+ }, {
87
+ key: "getTableUtils",
88
+ value: function getTableUtils() {
89
+ if (this.tableUtils) return this.tableUtils;
90
+ if (!this.editor) this.getEditor();
91
+ this.tableUtils = new TableUtils(this.editor);
92
+ return this.tableUtils;
93
+ }
94
+ }, {
95
+ key: "getPlugin",
96
+ value: function getPlugin() {
97
+ if (this.plugin) return this.plugin;
98
+ if (!this.editor) this.getEditor();
99
+ this.plugin = new Plugin(this.editor);
100
+ return this.plugin;
101
+ }
102
+ }]);
103
+
104
+ return EditorBuilder;
105
+ }();
106
+
107
+ export default EditorBuilder;
@@ -3,7 +3,8 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
3
  import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
- import '../../css/richeditor/formula.css';
6
+ import '../../assets/css/formula.css';
7
+ import EditorBuilder from '../editor-builder';
7
8
 
8
9
  var Formula = /*#__PURE__*/function (_React$Component) {
9
10
  _inherits(Formula, _React$Component);
@@ -22,7 +23,8 @@ var Formula = /*#__PURE__*/function (_React$Component) {
22
23
  _this = _super.call.apply(_super, [this].concat(args));
23
24
 
24
25
  _this.toggleFormulaEditor = function () {
25
- window.richMarkdownEditor.onToggleFormulaDialog();
26
+ var toolbarRef = EditorBuilder.getToolbarRef();
27
+ toolbarRef.onToggleFormulaDialog();
26
28
  };
27
29
 
28
30
  _this.renderFormula = function () {
@@ -8,6 +8,7 @@ import { withTranslation } from 'react-i18next';
8
8
  import Lightbox from '@seafile/react-image-lightbox';
9
9
  import { Utils } from '../../utils/utils';
10
10
  import InlineElementUtils from '../editor-utils/inline-element-utils';
11
+ import EditorBuilder from '../editor-builder';
11
12
  import '@seafile/react-image-lightbox/style.css';
12
13
 
13
14
  var Image = /*#__PURE__*/function (_React$Component) {
@@ -100,7 +101,8 @@ var Image = /*#__PURE__*/function (_React$Component) {
100
101
  isResizing: false,
101
102
  isShowBigImage: false
102
103
  };
103
- _this.inlineElementUtils = new InlineElementUtils(window.editor);
104
+ var editor = EditorBuilder.getEditor();
105
+ _this.inlineElementUtils = new InlineElementUtils(editor);
104
106
  return _this;
105
107
  }
106
108
 
@@ -128,10 +130,11 @@ var Image = /*#__PURE__*/function (_React$Component) {
128
130
  var src = data.src;
129
131
 
130
132
  if (/^\.\.\/*/.test(src) || /^\.\/*/.test(src)) {
131
- var _window$editor$editor = window.editor.editorApi,
132
- filePath = _window$editor$editor.filePath,
133
- serviceUrl = _window$editor$editor.serviceUrl,
134
- repoID = _window$editor$editor.repoID;
133
+ var editor = EditorBuilder.getEditor();
134
+ var _editor$editorApi = editor.editorApi,
135
+ filePath = _editor$editorApi.filePath,
136
+ serviceUrl = _editor$editorApi.serviceUrl,
137
+ repoID = _editor$editorApi.repoID;
135
138
  var originalPath = filePath.slice(0, filePath.lastIndexOf('/')) + '/' + src;
136
139
  src = serviceUrl + '/lib/' + repoID + '/file/' + Utils.pathNormalize(originalPath) + '?raw=1';
137
140
  }
@@ -221,7 +224,8 @@ var ImagePreviewer = /*#__PURE__*/function (_React$Component2) {
221
224
  });
222
225
  };
223
226
 
224
- _this2.images = _this2.getImageNodes(window.editor.children);
227
+ var editor = EditorBuilder.getEditor();
228
+ _this2.images = _this2.getImageNodes(editor.children);
225
229
  _this2.state = {
226
230
  imageIndex: _this2.images.findIndex(function (item) {
227
231
  return item === props.imageUrl;
@@ -4,7 +4,7 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import ReactDOM from 'react-dom';
7
- import '../../css/richeditor/table.css';
7
+ import '../../assets/css/table.css';
8
8
 
9
9
  var TableContainer = /*#__PURE__*/function (_React$PureComponent) {
10
10
  _inherits(TableContainer, _React$PureComponent);
@@ -7,6 +7,7 @@ import CodeUtils from './editor-utils/block-element-utils/code-utils';
7
7
  import TableUtils from './editor-utils/block-element-utils/table-utils';
8
8
  import setEventTransfer from './custom/set-event-transfer';
9
9
  import { SfEditor } from '../editor/custom/custom';
10
+ import EditorBuilder from './editor-builder';
10
11
 
11
12
  var Plugin = function Plugin(_editor) {
12
13
  var _this = this;
@@ -143,7 +144,8 @@ var Plugin = function Plugin(_editor) {
143
144
  byKey: true
144
145
  })(event)) {
145
146
  event.preventDefault();
146
- window.richMarkdownEditor.onToggleFormulaDialog();
147
+ var toolbarRef = EditorBuilder.getToolbarRef();
148
+ toolbarRef.onToggleFormulaDialog();
147
149
  return;
148
150
  } // compate chrome: in chrome press backspace would not exec delete_backward command
149
151
 
@@ -4,8 +4,6 @@ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
4
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
5
5
  import React from 'react';
6
6
  import SimpleEditor from './simple-editor';
7
- import SeafileEditor from './seafile-editor';
8
- import LoadScript from './load-script';
9
7
 
10
8
  var SimpleEditorWithErrorBoundary = /*#__PURE__*/function (_React$Component) {
11
9
  _inherits(SimpleEditorWithErrorBoundary, _React$Component);
@@ -34,33 +32,4 @@ var SimpleEditorWithErrorBoundary = /*#__PURE__*/function (_React$Component) {
34
32
  return SimpleEditorWithErrorBoundary;
35
33
  }(React.Component);
36
34
 
37
- var SeafileEditorWithErrorBundary = /*#__PURE__*/function (_React$Component2) {
38
- _inherits(SeafileEditorWithErrorBundary, _React$Component2);
39
-
40
- var _super2 = _createSuper(SeafileEditorWithErrorBundary);
41
-
42
- function SeafileEditorWithErrorBundary() {
43
- _classCallCheck(this, SeafileEditorWithErrorBundary);
44
-
45
- return _super2.apply(this, arguments);
46
- }
47
-
48
- _createClass(SeafileEditorWithErrorBundary, [{
49
- key: "componentDidCatch",
50
- value: function componentDidCatch(error) {
51
- console.error(error);
52
- this.forceUpdate();
53
- }
54
- }, {
55
- key: "render",
56
- value: function render() {
57
- return /*#__PURE__*/React.createElement(LoadScript, {
58
- scriptSource: this.props.scriptSource
59
- }, /*#__PURE__*/React.createElement(SeafileEditor, this.props));
60
- }
61
- }]);
62
-
63
- return SeafileEditorWithErrorBundary;
64
- }(React.Component);
65
-
66
- export { SimpleEditorWithErrorBoundary as SimpleEditor, SeafileEditorWithErrorBundary as SeafileEditor };
35
+ export { SimpleEditorWithErrorBoundary as SimpleEditor };
@@ -0,0 +1,97 @@
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 MarkdownEditor from "./markdown-editor";
7
+ import SimpleEditor from "./simple-editor";
8
+ import PlainMarkdownEditor from "./plain-markdown-editor";
9
+ import LoadScript from './load-script';
10
+ import EditorBuilder from "./editor-builder";
11
+
12
+ var SimpleEditorWithErrorBoundary = /*#__PURE__*/function (_React$Component) {
13
+ _inherits(SimpleEditorWithErrorBoundary, _React$Component);
14
+
15
+ var _super = _createSuper(SimpleEditorWithErrorBoundary);
16
+
17
+ function SimpleEditorWithErrorBoundary() {
18
+ _classCallCheck(this, SimpleEditorWithErrorBoundary);
19
+
20
+ return _super.apply(this, arguments);
21
+ }
22
+
23
+ _createClass(SimpleEditorWithErrorBoundary, [{
24
+ key: "componentDidCatch",
25
+ value: function componentDidCatch(error) {
26
+ console.error(error);
27
+ this.forceUpdate();
28
+ }
29
+ }, {
30
+ key: "render",
31
+ value: function render() {
32
+ return /*#__PURE__*/React.createElement(SimpleEditor, this.props);
33
+ }
34
+ }]);
35
+
36
+ return SimpleEditorWithErrorBoundary;
37
+ }(React.Component);
38
+
39
+ var MarkdownEditorWithErrorBoundary = /*#__PURE__*/function (_React$Component2) {
40
+ _inherits(MarkdownEditorWithErrorBoundary, _React$Component2);
41
+
42
+ var _super2 = _createSuper(MarkdownEditorWithErrorBoundary);
43
+
44
+ function MarkdownEditorWithErrorBoundary() {
45
+ _classCallCheck(this, MarkdownEditorWithErrorBoundary);
46
+
47
+ return _super2.apply(this, arguments);
48
+ }
49
+
50
+ _createClass(MarkdownEditorWithErrorBoundary, [{
51
+ key: "componentDidCatch",
52
+ value: function componentDidCatch(error) {
53
+ console.error(error);
54
+ this.forceUpdate();
55
+ }
56
+ }, {
57
+ key: "render",
58
+ value: function render() {
59
+ return /*#__PURE__*/React.createElement(LoadScript, {
60
+ scriptSource: this.props.scriptSource
61
+ }, /*#__PURE__*/React.createElement(MarkdownEditor, this.props));
62
+ }
63
+ }]);
64
+
65
+ return MarkdownEditorWithErrorBoundary;
66
+ }(React.Component);
67
+
68
+ var PlainMarkdownEditorWithErrorBoundary = /*#__PURE__*/function (_React$Component3) {
69
+ _inherits(PlainMarkdownEditorWithErrorBoundary, _React$Component3);
70
+
71
+ var _super3 = _createSuper(PlainMarkdownEditorWithErrorBoundary);
72
+
73
+ function PlainMarkdownEditorWithErrorBoundary() {
74
+ _classCallCheck(this, PlainMarkdownEditorWithErrorBoundary);
75
+
76
+ return _super3.apply(this, arguments);
77
+ }
78
+
79
+ _createClass(PlainMarkdownEditorWithErrorBoundary, [{
80
+ key: "componentDidCatch",
81
+ value: function componentDidCatch(error) {
82
+ console.error(error);
83
+ this.forceUpdate();
84
+ }
85
+ }, {
86
+ key: "render",
87
+ value: function render() {
88
+ return /*#__PURE__*/React.createElement(LoadScript, {
89
+ scriptSource: this.props.scriptSource
90
+ }, /*#__PURE__*/React.createElement(PlainMarkdownEditor, this.props));
91
+ }
92
+ }]);
93
+
94
+ return PlainMarkdownEditorWithErrorBoundary;
95
+ }(React.Component);
96
+
97
+ export { EditorBuilder, MarkdownEditorWithErrorBoundary as MarkdownEditor, SimpleEditorWithErrorBoundary as SimpleEditor, PlainMarkdownEditorWithErrorBoundary as PlainMarkdownEditor };
@@ -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);