@seafile/sdoc-editor 0.4.1 → 0.4.2-2

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.
@@ -0,0 +1,29 @@
1
+ .sdoc-editor-container {
2
+ flex: 1;
3
+ display: flex;
4
+ min-height: 0;
5
+ }
6
+
7
+ .sdoc-md-scroll-container {
8
+ display: flex;
9
+ overflow: auto;
10
+ }
11
+
12
+ .sdoc-md-scroll-container .sdoc-article-container {
13
+ width: 100%;
14
+ margin: 0 340px 0 40px !important;
15
+ }
16
+
17
+ .sdoc-md-scroll-container .sdoc-article-container .article .sdoc-header-2 {
18
+ border-bottom: 1px solid #ccc;
19
+ }
20
+
21
+ .sdoc-md-outline-container {
22
+ height: 80%;
23
+ overflow-y: auto;
24
+ padding-right: 1rem;
25
+ position: fixed;
26
+ right: 0;
27
+ top: 97px;
28
+ width: 300px;
29
+ }
@@ -86,9 +86,9 @@ const FileLink = _ref => {
86
86
  // eslint-disable-next-line react-hooks/exhaustive-deps
87
87
  }, []);
88
88
  let style = {};
89
- if (element.ADD) {
89
+ if (element.add) {
90
90
  style = _objectSpread({}, ADDED_STYLE);
91
- } else if (element.DELETE) {
91
+ } else if (element.delete) {
92
92
  style = _objectSpread({}, DELETED_STYLE);
93
93
  }
94
94
  if (style.computed_background_color) {
@@ -13,6 +13,7 @@ import { IMAGE_BORDER_TYPE } from './constants';
13
13
  import { ADDED_STYLE, DELETED_STYLE, IMAGE_BLOCK } from '../../constants';
14
14
  import imagePlaceholder from '../../../assets/images/image-placeholder.png';
15
15
  const Image = _ref => {
16
+ var _imageRef$current, _imageRef$current2;
16
17
  let {
17
18
  element,
18
19
  editor,
@@ -228,11 +229,11 @@ const Image = _ref => {
228
229
  }), isResizing && /*#__PURE__*/React.createElement("span", {
229
230
  className: "image-size",
230
231
  contentEditable: false
231
- }, /*#__PURE__*/React.createElement("span", null, t('Width'), ':', parseInt(movingWidth || imageRef.current.clientWidth)), /*#__PURE__*/React.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/React.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), nodeEntry[0].type === IMAGE_BLOCK && show_caption && /*#__PURE__*/React.createElement("input", {
232
+ }, /*#__PURE__*/React.createElement("span", null, t('Width'), ':', parseInt(movingWidth || ((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.clientWidth))), /*#__PURE__*/React.createElement("span", null, "\xA0\xA0"), /*#__PURE__*/React.createElement("span", null, t('Height'), ':', imageRef.current.clientHeight))), nodeEntry[0].type === IMAGE_BLOCK && show_caption && /*#__PURE__*/React.createElement("input", {
232
233
  id: "sdoc-image-caption-input",
233
234
  className: "sdoc-image-caption-input-wrapper",
234
235
  style: {
235
- width: (data === null || data === void 0 ? void 0 : data.width) || imageRef.current.clientWidth
236
+ width: (data === null || data === void 0 ? void 0 : data.width) || ((_imageRef$current2 = imageRef.current) === null || _imageRef$current2 === void 0 ? void 0 : _imageRef$current2.clientWidth)
236
237
  },
237
238
  placeholder: t('Insert_caption'),
238
239
  value: caption,
@@ -267,8 +268,11 @@ export function renderImage(props, editor) {
267
268
  if (leaf && leaf.computed_background_color) {
268
269
  style['backgroundColor'] = leaf.computed_background_color;
269
270
  }
270
- if (element.ADD || element.DELETE) {
271
- style = Object.assign({}, style, element.ADD ? ADDED_STYLE : DELETED_STYLE);
271
+ if (element.add || element.delete) {
272
+ style = Object.assign({}, style, element.add ? ADDED_STYLE : DELETED_STYLE);
273
+ if (style.computed_background_color) {
274
+ style['backgroundColor'] = style.computed_background_color;
275
+ }
272
276
  }
273
277
  return /*#__PURE__*/React.createElement(SdocImage, Object.assign({}, props, {
274
278
  style: style,
@@ -88,9 +88,9 @@ const SdocFileLink = _ref => {
88
88
  // eslint-disable-next-line react-hooks/exhaustive-deps
89
89
  }, []);
90
90
  let style = {};
91
- if (element.ADD) {
91
+ if (element.add) {
92
92
  style = _objectSpread({}, ADDED_STYLE);
93
- } else if (element.DELETE) {
93
+ } else if (element.delete) {
94
94
  style = _objectSpread({}, DELETED_STYLE);
95
95
  }
96
96
  if (style.computed_background_color) {
@@ -1,6 +1,6 @@
1
1
  import SDocEditor from './editor/sdoc-editor';
2
2
  import RevisionEditor from './editor/revision-editor';
3
- import { DiffViewer, SDocViewer, PublishedRevisionDiffViewer } from './views';
3
+ import { DiffViewer, SDocViewer, PublishedRevisionDiffViewer, SDocMdViewer } from './views';
4
4
  import SDocOutline from './outline';
5
5
  import EventBus from './utils/event-bus';
6
- export { SDocEditor, RevisionEditor, SDocViewer, SDocOutline, EventBus, DiffViewer, PublishedRevisionDiffViewer };
6
+ export { SDocEditor, RevisionEditor, SDocViewer, SDocOutline, EventBus, DiffViewer, PublishedRevisionDiffViewer, SDocMdViewer };
@@ -0,0 +1,70 @@
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import OutlineItem from './outline-item';
4
+ import { useScrollContext } from '../hooks/use-scroll-context';
5
+ import './style.css';
6
+ const getHeaderList = children => {
7
+ const headerList = [];
8
+ children.forEach(node => {
9
+ if (node.type === 'header2' || node.type === 'header3') {
10
+ headerList.push(node);
11
+ }
12
+ });
13
+ return headerList;
14
+ };
15
+ const Outline = _ref => {
16
+ let {
17
+ editor
18
+ } = _ref;
19
+ const {
20
+ t
21
+ } = useTranslation();
22
+ const scrollRef = useScrollContext();
23
+ const [headerList, setHeaderList] = useState([]);
24
+ const [activeId, setActiveId] = useState('');
25
+ useEffect(() => {
26
+ const headerList = getHeaderList(editor.children);
27
+ setHeaderList(headerList);
28
+ }, [editor.children]);
29
+ const handleScroll = useCallback(e => {
30
+ const scrollTop = scrollRef.current.scrollTop;
31
+ const styles = getComputedStyle(scrollRef === null || scrollRef === void 0 ? void 0 : scrollRef.current);
32
+ const paddingTop = parseInt(styles.paddingTop);
33
+ for (let i = 0; i < headerList.length; i++) {
34
+ const headerItem = headerList[i];
35
+ const dom = document.getElementById(headerItem.id);
36
+ const {
37
+ offsetTop,
38
+ offsetHeight
39
+ } = dom;
40
+ const styles = getComputedStyle(dom);
41
+ const marginTop = parseInt(styles.marginTop);
42
+ if (offsetTop + offsetHeight + marginTop > scrollTop - paddingTop) {
43
+ setActiveId(headerItem.id);
44
+ break;
45
+ }
46
+ }
47
+ }, [headerList, scrollRef]);
48
+ useEffect(() => {
49
+ let observerRefValue = null;
50
+ if (scrollRef.current) {
51
+ scrollRef.current.addEventListener('scroll', handleScroll);
52
+ observerRefValue = scrollRef.current;
53
+ }
54
+ return () => {
55
+ observerRefValue.removeEventListener('scroll', handleScroll);
56
+ };
57
+ }, [handleScroll, scrollRef]);
58
+ return /*#__PURE__*/React.createElement("div", {
59
+ className: "sdoc-md-editor-outline"
60
+ }, headerList.length === 0 && /*#__PURE__*/React.createElement("div", {
61
+ className: "empty-container"
62
+ }, t('No_out_line')), headerList.length > 0 && headerList.map((node, index) => {
63
+ return /*#__PURE__*/React.createElement(OutlineItem, {
64
+ key: index,
65
+ node: node,
66
+ activeId: activeId
67
+ });
68
+ }));
69
+ };
70
+ export default Outline;
@@ -0,0 +1,24 @@
1
+ import React, { useCallback } from 'react';
2
+ import classNames from 'classnames';
3
+ const OutlineItem = _ref => {
4
+ let {
5
+ node,
6
+ activeId
7
+ } = _ref;
8
+ const onItemClick = useCallback(() => {
9
+ const {
10
+ id
11
+ } = node;
12
+ document.getElementById(id).scrollIntoView();
13
+ }, [node]);
14
+ const className = classNames({
15
+ 'outline-h2': node.type === 'header2',
16
+ 'outline-h3': node.type === 'header3',
17
+ 'active': node.id === activeId
18
+ });
19
+ return /*#__PURE__*/React.createElement("div", {
20
+ className: className,
21
+ onClick: onItemClick
22
+ }, node.children.map(child => child.text).join(''));
23
+ };
24
+ export default OutlineItem;
@@ -0,0 +1,45 @@
1
+ .sdoc-md-editor-outline {
2
+ border-left: 1px solid #ddd;
3
+ padding: .5rem 1rem .5rem 0;
4
+ }
5
+
6
+ .sdoc-md-editor-outline .outline-h2,
7
+ .sdoc-md-editor-outline .outline-h3 {
8
+ white-space: nowrap;
9
+ overflow: hidden;
10
+ text-overflow: ellipsis;
11
+ }
12
+
13
+ .sdoc-md-editor-outline .outline-h2 {
14
+ margin-left: 20px;
15
+ line-height: 2.5;
16
+ color:#364149;
17
+ white-space: nowrap;
18
+ cursor:pointer;
19
+ }
20
+
21
+ .sdoc-md-editor-outline .outline-h2:hover {
22
+ color: #eb8205;
23
+ }
24
+
25
+ .sdoc-md-editor-outline .outline-h3 {
26
+ margin-left: 40px;
27
+ line-height: 2.5;
28
+ color:#364149;
29
+ white-space: nowrap;
30
+ cursor:pointer;
31
+ }
32
+
33
+ .sdoc-md-editor-outline .outline-h3:hover {
34
+ color: #eb8205;
35
+ }
36
+
37
+ .sdoc-md-editor-outline .empty-container {
38
+ margin-top: 10px;
39
+ text-align: center;
40
+ }
41
+
42
+ .sdoc-md-editor-outline .outline-h2.active,
43
+ .sdoc-md-editor-outline .outline-h3.active {
44
+ color: #eb8205;
45
+ }
@@ -2,4 +2,5 @@ import SDocViewer from './sdoc-viewer';
2
2
  import DiffViewer from './sdoc-diff-viewer';
3
3
  import RevisionDiffViewer from './revision-diff-viewer';
4
4
  import PublishedRevisionDiffViewer from './published-revision-diff-viewer';
5
- export { SDocViewer, DiffViewer, RevisionDiffViewer, PublishedRevisionDiffViewer };
5
+ import SDocMdViewer from './sdoc-md-viewer';
6
+ export { SDocViewer, DiffViewer, RevisionDiffViewer, PublishedRevisionDiffViewer, SDocMdViewer };
@@ -0,0 +1,44 @@
1
+ import React, { useRef } from 'react';
2
+ import { createDefaultEditor } from '../extension';
3
+ import withNodeId from '../node-id';
4
+ import { generateDefaultDocContent } from '../../utils';
5
+ import { EditorContainer } from '../layout';
6
+ import ReadOnlyArticle from './readonly-article';
7
+ import { ColorProvider } from '../hooks/use-color-context';
8
+ import { ScrollContext } from '../hooks/use-scroll-context';
9
+ import Outline from '../md-outline';
10
+ import '../assets/css/sdoc-md-viewer.css';
11
+ const SDocMdViewer = _ref => {
12
+ let {
13
+ editor,
14
+ document,
15
+ showOutline
16
+ } = _ref;
17
+ const validEditor = editor || withNodeId(createDefaultEditor());
18
+ const slateValue = (document || generateDefaultDocContent()).children;
19
+ const scrollRef = useRef(null);
20
+ return /*#__PURE__*/React.createElement(EditorContainer, {
21
+ editor: validEditor,
22
+ readonly: true
23
+ }, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement("div", {
24
+ ref: scrollRef,
25
+ className: "sdoc-md-scroll-container"
26
+ }, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
27
+ value: {
28
+ scrollRef
29
+ }
30
+ }, /*#__PURE__*/React.createElement(ReadOnlyArticle, {
31
+ editor: validEditor,
32
+ slateValue: slateValue,
33
+ isShowComment: false
34
+ }), showOutline && /*#__PURE__*/React.createElement("div", {
35
+ className: "sdoc-md-outline-container"
36
+ }, /*#__PURE__*/React.createElement(Outline, {
37
+ editor: validEditor
38
+ }))))));
39
+ };
40
+ SDocMdViewer.defaultProps = {
41
+ showToolbar: false,
42
+ showOutline: false
43
+ };
44
+ export default SDocMdViewer;
package/dist/index.js CHANGED
@@ -4,4 +4,5 @@ import SimpleEditor from './pages/simple-editor';
4
4
  import SimpleViewer from './pages/simple-viewer';
5
5
  import DiffViewer from './pages/diff-viewer';
6
6
  import PublishedRevisionViewer from './pages/published-revision-viewer';
7
- export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT, DiffViewer, PublishedRevisionViewer };
7
+ import MarkdownViewer from './pages/markdown-viewer';
8
+ export { SDocViewer, SimpleEditor, SimpleViewer, EventBus, EXTERNAL_EVENT, DiffViewer, PublishedRevisionViewer, MarkdownViewer };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import context from '../context';
3
+ import ErrorBoundary from './error-boundary';
4
+ import { SDocMdViewer } from '../basic-sdk';
5
+ import '../assets/css/simple-viewer.css';
6
+ context.initApi();
7
+ const MarkdownViewer = _ref => {
8
+ let {
9
+ document,
10
+ showOutline
11
+ } = _ref;
12
+ return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(SDocMdViewer, {
13
+ document: document,
14
+ showOutline: showOutline
15
+ }));
16
+ };
17
+ export default MarkdownViewer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "0.4.1",
3
+ "version": "0.4.2-2",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",