@seafile/seafile-editor 1.0.8 → 1.0.10-1

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.
@@ -4,6 +4,7 @@
4
4
  flex-direction: column;
5
5
  background-color: #f5f5f5;
6
6
  user-select: none;
7
+ min-height: 0;
7
8
  }
8
9
 
9
10
  .sf-article-info-container .nav {
@@ -44,7 +45,8 @@
44
45
  .sf-article-info-container .sf-article-info-content {
45
46
  flex: 1;
46
47
  font-size: 0.937rem;
47
- overflow: hidden;
48
+ min-height: 0;
49
+ overflow: auto;
48
50
  }
49
51
 
50
52
  .sf-article-info-container .sf-article-info-content:hover {
@@ -0,0 +1,27 @@
1
+ import React, { useEffect } from 'react';
2
+ import { SetNodeToDecorations, baseEditor, renderElement, renderLeaf, useHighlight } from '../../extension';
3
+ import { Editable, Slate } from 'slate-react';
4
+ export default function SimpleSlateViewer(_ref) {
5
+ let {
6
+ value
7
+ } = _ref;
8
+ const decorate = useHighlight(baseEditor);
9
+
10
+ // willUnmount
11
+ useEffect(() => {
12
+ return () => {
13
+ baseEditor.selection = null;
14
+ };
15
+ });
16
+ return /*#__PURE__*/React.createElement(Slate, {
17
+ editor: baseEditor,
18
+ initialValue: value
19
+ }, /*#__PURE__*/React.createElement("div", {
20
+ className: "article"
21
+ }, /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
22
+ readOnly: true,
23
+ decorate: decorate,
24
+ renderElement: renderElement,
25
+ renderLeaf: renderLeaf
26
+ })));
27
+ }
@@ -2,11 +2,11 @@
2
2
  display: none;
3
3
  background-color: #fff;
4
4
  border-left: 1px solid #eee;
5
- flex: 0 0 350px;
5
+ flex: 0 0 300px;
6
6
  height: 100%;
7
7
  overflow-x: hidden;
8
8
  overflow-y: auto;
9
- width: 250px;
9
+ width: 300px;
10
10
  }
11
11
 
12
12
  .sf-markdown-help-wrapper.active {
@@ -31,6 +31,7 @@
31
31
  .sf-slate-editor-container .sf-slate-scroll-container {
32
32
  height: 100%;
33
33
  width: 100%;
34
+ background-color: #fafaf9;
34
35
  overflow: auto;
35
36
  }
36
37
 
@@ -3,6 +3,7 @@ import 'prismjs/themes/prism.css';
3
3
  import 'prismjs/components/prism-javascript';
4
4
  import 'prismjs/components/prism-typescript';
5
5
  import 'prismjs/components/prism-markup';
6
+ import 'prismjs/components/prism-markup-templating';
6
7
  import 'prismjs/components/prism-go';
7
8
  import 'prismjs/components/prism-php';
8
9
  import 'prismjs/components/prism-c';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import RichMarkdownEditor from './pages/rich-markdown-editor';
4
4
  import MarkdownEditor from './pages/markdown-editor';
5
5
  import MarkdownViewer from './pages/markdown-view';
6
6
  import SimpleEditor from './pages/simple-editor';
7
+ import SimpleViewer from './pages/simple-viewer';
7
8
  import EventBus from './utils/event-bus';
8
9
  import { mdStringToSlate, slateToMdString, deserializeHtml, processor } from './slate-convert';
9
- export { MarkdownEditor, PlainMarkdownEditor, RichMarkdownEditor, MarkdownViewer, SimpleEditor, EXTERNAL_EVENTS, EventBus, mdStringToSlate, slateToMdString, deserializeHtml, processor };
10
+ export { MarkdownEditor, PlainMarkdownEditor, RichMarkdownEditor, MarkdownViewer, SimpleEditor, SimpleViewer, EXTERNAL_EVENTS, EventBus, mdStringToSlate, slateToMdString, deserializeHtml, processor };
@@ -0,0 +1,42 @@
1
+ import React, { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
2
+ import Loading from '../containers/loading';
3
+ import { mdStringToSlate, slateToMdString } from '../slate-convert';
4
+ import useMathJax from '../hooks/use-mathjax';
5
+ import SimpleSlateViewer from '../editors/simple-slate-viewer';
6
+ const SimpleEditor = forwardRef((_ref, ref) => {
7
+ let {
8
+ isFetching,
9
+ value,
10
+ mathJaxSource
11
+ } = _ref;
12
+ const [richValue, setRichValue] = useState([]);
13
+ const [isLoading, setIsLoading] = useState(true);
14
+ const {
15
+ isLoadingMathJax
16
+ } = useMathJax(mathJaxSource);
17
+ useImperativeHandle(ref, () => {
18
+ return {
19
+ getValue: () => {
20
+ const mdStringValue = slateToMdString(richValue);
21
+ return mdStringValue;
22
+ }
23
+ };
24
+ }, [richValue]);
25
+ useEffect(() => {
26
+ if (!isFetching) {
27
+ const richValue = mdStringToSlate(value);
28
+ setRichValue(richValue);
29
+ setIsLoading(false);
30
+ }
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, [isFetching]);
33
+ const props = {
34
+ isSupportFormula: !!mathJaxSource,
35
+ value: richValue
36
+ };
37
+ if (isFetching || isLoading || isLoadingMathJax) {
38
+ return /*#__PURE__*/React.createElement(Loading, null);
39
+ }
40
+ return /*#__PURE__*/React.createElement(SimpleSlateViewer, props);
41
+ });
42
+ export default SimpleEditor;
@@ -21,7 +21,8 @@ const codeBlockRule = (element, parseChild) => {
21
21
  } else {
22
22
  const lang = 'plaintext';
23
23
  const content = childNodes[0].textContent;
24
- const children = content.split('\n').map(text => {
24
+ const textArr = content.split('\n').filter(Boolean);
25
+ const children = textArr.map(text => {
25
26
  return {
26
27
  id: slugid.nice(),
27
28
  type: CODE_LINE,
@@ -65,7 +66,7 @@ const codeBlockRule = (element, parseChild) => {
65
66
  }]
66
67
  };
67
68
  }
68
- const codes = content.split('\n');
69
+ const codes = content.slugid('\n').filter(Boolean);
69
70
  return codes.map(item => {
70
71
  return {
71
72
  id: slugid.nice(),
@@ -15,7 +15,11 @@ const tableRule = (element, parseChild) => {
15
15
  if (nodeName === 'THEAD' || nodeName === 'TBODY') {
16
16
  return parseChild(childNodes);
17
17
  }
18
- if (nodeName === 'TR') {
18
+ if (nodeName === 'TR' && childNodes.length > 0) {
19
+ // patch
20
+ const children = Array.from(childNodes);
21
+ const hasTdOrTh = children.some(item => item.nodeName === 'TH' || item.nodeName === 'TD');
22
+ if (!hasTdOrTh) return;
19
23
  return {
20
24
  id: slugid.nice(),
21
25
  type: TABLE_ROW,
@@ -1,6 +1,7 @@
1
1
  import slugid from 'slugid';
2
2
  import { generateDefaultText } from '../../extension/core';
3
3
  import { BLOCKQUOTE, HEADER, IMAGE, LINK, PARAGRAPH, TABLE, CODE_BLOCK, LIST_ITEM, ORDERED_LIST, UNORDERED_LIST, CHECK_LIST_ITEM, CODE_LINE, TABLE_ROW, TABLE_CELL } from '../../extension/constants/element-types';
4
+ import deserializeHtml from '../html-to-slate';
4
5
  const INLINE_KEY_MAP = {
5
6
  strong: 'bold',
6
7
  emphasis: 'italic'
@@ -156,8 +157,11 @@ export const transformListItem = node => {
156
157
  return transformCodeBlock(child);
157
158
  } else if (child.type === 'list') {
158
159
  return transformList(child);
160
+ } else if (child.type === 'html') {
161
+ // patch
162
+ return transformBlockHtml(child);
159
163
  }
160
- })
164
+ }).flat()
161
165
  };
162
166
  };
163
167
  export const transformOrderedList = node => {
@@ -279,7 +283,7 @@ export const transformHtml = node => {
279
283
  } = new DOMParser().parseFromString(node.value, 'text/html');
280
284
  const img = body.firstChild;
281
285
  const src = img.getAttribute('src');
282
- if (!src) return defaultTextNode;
286
+ if (!src) return [defaultTextNode];
283
287
  const alt = img.getAttribute('alt');
284
288
  const title = img.getAttribute('title');
285
289
  const width = img.getAttribute('width');
@@ -307,14 +311,17 @@ export const transformHtml = node => {
307
311
  };
308
312
  return [generateDefaultText(), image, generateDefaultText()];
309
313
  }
310
- return defaultTextNode;
314
+ return [defaultTextNode];
311
315
  };
312
316
  export const transformBlockHtml = node => {
313
- return {
314
- id: slugid.nice(),
315
- type: PARAGRAPH,
316
- children: transformHtml(node)
317
- };
317
+ if (node.value.slice(0, 4).toLowerCase() === '<img') {
318
+ return {
319
+ id: slugid.nice(),
320
+ type: PARAGRAPH,
321
+ children: transformHtml(node)
322
+ };
323
+ }
324
+ return deserializeHtml(node.value);
318
325
  };
319
326
  export const transformMath = node => {
320
327
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-editor",
3
- "version": "1.0.8",
3
+ "version": "1.0.10-1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {