@seafile/seafile-editor 1.0.84-alpha5 → 1.0.85-beta

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.
@@ -28,6 +28,9 @@ const renderLink = (_ref, editor) => {
28
28
  left: 0
29
29
  });
30
30
  const isReadonly = (0, _slateReact.useReadOnly)();
31
+
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ const isLinkActive = (0, _react.useMemo)(() => (0, _helper.isLinkType)(editor), [editor.selection]);
31
34
  const onClosePopover = (0, _react.useCallback)(e => {
32
35
  unregisterClickEvent();
33
36
  setIsShowPopover(false);
@@ -77,7 +80,7 @@ const renderLink = (_ref, editor) => {
77
80
  }, attributes), /*#__PURE__*/_react.default.createElement("a", {
78
81
  href: element.url,
79
82
  onClick: onHrefClick
80
- }, children)), isShowPopover && /*#__PURE__*/_react.default.createElement(_linkPopover.default, {
83
+ }, children)), isLinkActive && isShowPopover && /*#__PURE__*/_react.default.createElement(_linkPopover.default, {
81
84
  popoverPosition: popoverPosition,
82
85
  linkUrl: element.url,
83
86
  editor: editor,
@@ -14,7 +14,6 @@ var _helper = require("../helper");
14
14
  var _common = require("../../../../utils/common");
15
15
  var _eventTypes = require("../../../../constants/event-types");
16
16
  var _constants = require("../../../../constants");
17
- require("./style.css");
18
17
  const LinkPopover = _ref => {
19
18
  let {
20
19
  linkUrl,
@@ -59,4 +59,4 @@
59
59
 
60
60
  .sf-link-op-icon:hover {
61
61
  background: #f2f2f2;
62
- }
62
+ }
@@ -26,7 +26,8 @@ class MarkdownPreview extends _react.default.PureComponent {
26
26
  });
27
27
  });
28
28
  this.state = {
29
- innerHtml: null
29
+ innerHtml: null,
30
+ richValue: null
30
31
  };
31
32
  }
32
33
  componentDidMount() {
@@ -36,20 +37,27 @@ class MarkdownPreview extends _react.default.PureComponent {
36
37
  } = this.props;
37
38
  if (isWindowsWechat) {
38
39
  this.convertMarkdown(value);
40
+ } else {
41
+ const richValue = (0, _slateConvert.mdStringToSlate)(value);
42
+ this.setState({
43
+ richValue
44
+ });
45
+ this.props.beforeRenderCallback && this.props.beforeRenderCallback(richValue);
39
46
  }
40
47
  }
41
48
  render() {
42
49
  const {
43
50
  isWindowsWechat,
44
- value,
45
51
  isShowOutline
46
52
  } = this.props;
47
53
  const {
48
- innerHtml
54
+ innerHtml,
55
+ richValue
49
56
  } = this.state;
50
57
  if (isWindowsWechat && innerHtml === null) {
51
58
  return /*#__PURE__*/_react.default.createElement(_loading.default, null);
52
59
  }
60
+ if (!isWindowsWechat && !richValue) return null;
53
61
  return /*#__PURE__*/_react.default.createElement("div", {
54
62
  className: "longtext-preview-container"
55
63
  }, isWindowsWechat && /*#__PURE__*/_react.default.createElement("div", {
@@ -58,7 +66,7 @@ class MarkdownPreview extends _react.default.PureComponent {
58
66
  __html: this.state.innerHtml
59
67
  }
60
68
  }), !isWindowsWechat && /*#__PURE__*/_react.default.createElement(_slateViewer.default, {
61
- value: (0, _slateConvert.mdStringToSlate)(value),
69
+ value: richValue,
62
70
  isShowOutline: isShowOutline
63
71
  }));
64
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.84alpha5",
3
+ "version": "1.0.85beta",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -223,5 +223,9 @@
223
223
  "Open_link": "Open link",
224
224
  "Image_is_uploading": "Image is uploading",
225
225
  "Image_loading_failed": "Image loading failed",
226
- "Expand_editor": "Expand editor"
226
+ "Expand_editor": "Expand editor",
227
+ "Insert_below": "Insert below",
228
+ "Insert_above": "Insert above",
229
+ "Insert_on_the_right": "Insert on the right",
230
+ "Insert_on_the_left": "Insert on the left"
227
231
  }
package/readme.md CHANGED
@@ -8,7 +8,16 @@ SeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in
8
8
  ## Integrated markdown editor UI
9
9
  > An integrated demo. You can customize it according to the style you design.
10
10
 
11
- ![markdown editor](./assets/imgs/markdown-editor.png)
11
+ ![markdown editor](./assets/imgs/demo-markdown-editor.png)
12
+
13
+ ## Simple editor UI
14
+ ![simple editor](./assets/imgs/simple-editor.png)
15
+
16
+ ## Integrated simple editor UI
17
+ > An integrated demo. You can customize it according to the style you design.
18
+
19
+ ![simple editor](./assets/imgs/demo-simple-editor.png)
20
+
12
21
 
13
22
  ## Installation
14
23
  To install via npm:
@@ -29,6 +38,7 @@ import { MarkdownEditor } from '@seafile/seafile-editor';
29
38
  |Name|Explain|
30
39
  |-|-|
31
40
  |MarkdownEditor|Markdown rich text editor component|
41
+ |SimpleEditor|Simple markdown editor component|
32
42
  |MarkdownViewer|Markdown content preview component|
33
43
 
34
44
  ### Functions
@@ -81,7 +91,7 @@ import { Button } from 'reactstrap';
81
91
  import { MarkdownEditor } from '@seafile/seafile-editor';
82
92
  import editorApi from './api';
83
93
 
84
- export default function SimpleMarkdownEditor() {
94
+ export default function MarkdownEditorDemo() {
85
95
 
86
96
  const editorRef = useRef(null);
87
97
  const [fileContent, setFileContent] = useState('');
@@ -140,6 +150,109 @@ Common props you may want to specify include:
140
150
  * onContentChanged: When the editor content changes, a change event is triggered to facilitate the user to record whether the document
141
151
  * mathJaxSource: Supports inserting formulas. If you want to support inserting formulas, please provide a path that can load formula resources. If support is not required, you can ignore this parameter. [math-jax document](https://docs.mathjax.org/en/stable/start.html)
142
152
 
153
+ ## SimpleEditor usage
154
+
155
+ ### Define api
156
+
157
+ ```javascript
158
+ import axios from 'axios';
159
+
160
+ class API {
161
+
162
+ getFileContent() {
163
+ const fileUrl = '';
164
+ return axios.get(fileUrl);
165
+ }
166
+
167
+ saveFileContent(content) {
168
+ const updateLink = '';
169
+ const formData = new FormData();
170
+ const blob = new Blob([data], { type: 'text/plain' });
171
+ formData.append('file', blob);
172
+ axios.post(updateLink, formData);
173
+ }
174
+
175
+ uploadLocalImage(file) {
176
+ const uploadLink = '';
177
+ const formData = new FormData();
178
+ formData.append('file', file);
179
+ return axios.post(uploadLink, formData);
180
+ }
181
+
182
+ }
183
+
184
+ const editorApi = new API();
185
+
186
+ export default editorApi;
187
+ ```
188
+
189
+ ### Integrate simple into your own page
190
+
191
+ ```javascript
192
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
193
+ import { Button } from 'reactstrap';
194
+ import { SimpleEditor } from '@seafile/seafile-editor';
195
+ import editorApi from './api';
196
+
197
+ export default function SimpleEditorDemo() {
198
+
199
+ const editorRef = useRef(null);
200
+ const [fileContent, setFileContent] = useState('');
201
+ const [isFetching, setIsFetching] = useState(true);
202
+ const [contentVersion, setContentVersion] = useState(0);
203
+
204
+ const mathJaxSource = '';
205
+
206
+ useEffect(() => {
207
+ editorApi.getFileContent().then(res => {
208
+ setFileContent(res.data);
209
+ setIsFetching(false);
210
+ });
211
+ }, []);
212
+
213
+ const onSave = useCallback(() => {
214
+ const content = editorRef.current.getValue();
215
+ editorApi.saveFileContent(content).then(res => {
216
+ window.alert('Saved successfully')
217
+ });
218
+ }, []);
219
+
220
+ const onContentChanged = useCallback(() => {
221
+ setContentVersion(contentVersion + 1);
222
+ }, [contentVersion]);
223
+
224
+ return (
225
+ <div className='seafile-editor'>
226
+ <SimpleEditor
227
+ ref={editorRef}
228
+ isFetching={isFetching}
229
+ value={fileContent}
230
+ initValue={''}
231
+ editorApi={editorApi}
232
+ onSave={onSave}
233
+ onContentChanged={onContentChanged}
234
+ mathJaxSource={mathJaxSource}
235
+ />
236
+ </div>
237
+ );
238
+ }
239
+
240
+ ```
241
+
242
+ ### Props
243
+
244
+ Common props you may want to specify include:
245
+
246
+ * ref: A reference to the editor, used to obtain the current content in the editor
247
+ * ref.current.getValue: Get the current markdown string value in the editor
248
+ * ref.current.getSlateValue: Get the value of the current slate data format in the editor
249
+ * isFetching: Whether the value of the editor is being obtained, if the loading effect is displayed while obtaining, and if the acquisition is completed, the corresponding content obtained is displayed in the editor.
250
+ * value: The text content obtained
251
+ * onSave: When the editor content changes, the onSave callback event is triggered externally. The user can save the document by implementing this callback function.
252
+ * onContentChanged: When the editor content changes, a change event is triggered to facilitate the user to record whether the document
253
+ * mathJaxSource: Supports inserting formulas. If you want to support inserting formulas, please provide a path that can load formula resources. If support is not required, you can ignore this parameter. [math-jax document](https://docs.mathjax.org/en/stable/start.html)
254
+
255
+
143
256
  ## Functions
144
257
 
145
258
  ### `mdStringToSlate(mdString)`
@@ -190,31 +303,9 @@ processor.process(string).then(result => {
190
303
  ## 🖥 Environment Support
191
304
 
192
305
  * Modern browsers
193
- * Software built-in browser
194
306
 
195
307
  ### Modern browsers
196
308
 
197
309
  | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)<br>Safari |
198
310
  | --- | --- | --- | --- |
199
311
  | Edge | false | last 2 versions | false |
200
-
201
-
202
- ### Software built-in browser
203
-
204
- **Mac OS**
205
-
206
- | software | browser | version | internal | isSupport |
207
- |-|-|-|-|-|
208
- |<img src="./assets/imgs/wechat.png" width='16'> WeChat| Chrome |107.0.0.0| AppleWebKit/537.36 |false|
209
- |<img src="./assets/imgs/wecom.png" width='16'> WeCom|Safari||AppleWebKit/605.1.15 |false|
210
-
211
- **Windows OS**
212
- > windows 11
213
-
214
- | software | browser | version | internal | isSupport |
215
- |-|-|-|-|-|
216
- |<img src="./assets/imgs/wechat.png" width='16'> WeChat| Chrome |106.0.0.0| AppleWebKit/537.36 |false|
217
- |<img src="./assets/imgs/wecom.png" width='16'> WeCom|Chrome|108.0.5993.119|AppleWebKit/537.36 |false|
218
-
219
-
220
-