@seafile/sdoc-editor 1.0.8 → 1.0.9

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.
@@ -2,6 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import React, { useEffect, useState, useImperativeHandle, forwardRef, useMemo, useCallback } from 'react';
3
3
  import { Editor } from '@seafile/slate';
4
4
  import deepCopy from 'deep-copy';
5
+ import classNames from 'classnames';
5
6
  import context from '../../context';
6
7
  import CommonLoading from '../../components/common-loading';
7
8
  import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../constants';
@@ -10,20 +11,21 @@ import withNodeId from '../node-id';
10
11
  import { withSocketIO } from '../socket';
11
12
  import { focusEditor } from '../extension/core';
12
13
  import InsertElementDialog from '../extension/commons/insert-element-dialog';
13
- import { EditorContainer, EditorContent } from '../layout';
14
+ import { EditorContainer } from '../layout';
14
15
  import EditableArticle from './editable-article';
15
16
  import { ColorProvider } from '../hooks/use-color-context';
16
17
  import ReadOnlyArticle from '../views/readonly-article';
17
18
  import { isMobile } from '../../utils';
18
19
  import { EventBus } from '../../basic-sdk';
19
20
  import { EXTERNAL_EVENT } from '../../constants';
21
+ import { ScrollContext } from '../hooks/use-scroll-context';
20
22
  const WikiEditor = forwardRef((_ref, ref) => {
21
23
  let {
22
24
  editor: propsEditor,
23
25
  document,
24
26
  isReloading,
25
27
  isWikiReadOnly,
26
- topSlot
28
+ scrollRef
27
29
  } = _ref;
28
30
  const validEditor = propsEditor || useMemo(() => {
29
31
  const defaultEditor = createDefaultEditor();
@@ -87,6 +89,11 @@ const WikiEditor = forwardRef((_ref, ref) => {
87
89
  };
88
90
  // eslint-disable-next-line react-hooks/exhaustive-deps
89
91
  }, []);
92
+ useEffect(() => {
93
+ if (scrollRef) {
94
+ scrollRef.current.id = 'sdoc-scroll-container';
95
+ }
96
+ }, [scrollRef]);
90
97
  const onRefreshDocument = useCallback(() => {
91
98
  window.location.reload();
92
99
  }, []);
@@ -130,31 +137,38 @@ const WikiEditor = forwardRef((_ref, ref) => {
130
137
  return /*#__PURE__*/React.createElement(EditorContainer, {
131
138
  editor: validEditor,
132
139
  readonly: true
133
- }, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(EditorContent, {
134
- docValue: slateValue,
135
- readonly: true,
136
- showOutline: false,
137
- editor: validEditor,
138
- showComment: false
139
- }, topSlot, /*#__PURE__*/React.createElement(ReadOnlyArticle, {
140
+ }, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement("div", {
141
+ className: "sdoc-content-wrapper"
142
+ }, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
143
+ value: {
144
+ scrollRef
145
+ }
146
+ }, /*#__PURE__*/React.createElement("div", {
147
+ className: "sdoc-editor-content readonly"
148
+ }, /*#__PURE__*/React.createElement(ReadOnlyArticle, {
140
149
  editor: validEditor,
141
150
  slateValue: slateValue,
142
151
  showComment: false
143
- }))));
152
+ }))))));
144
153
  }
145
154
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorContainer, {
146
155
  editor: validEditor
147
- }, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(EditorContent, {
148
- docValue: slateValue,
149
- showOutline: false,
150
- editor: validEditor,
151
- showComment: false
152
- }, topSlot, /*#__PURE__*/React.createElement(EditableArticle, {
156
+ }, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement("div", {
157
+ className: "sdoc-content-wrapper"
158
+ }, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
159
+ value: {
160
+ scrollRef
161
+ }
162
+ }, /*#__PURE__*/React.createElement("div", {
163
+ className: classNames('sdoc-editor-content', {
164
+ 'readonly': isWikiReadOnly
165
+ })
166
+ }, /*#__PURE__*/React.createElement(EditableArticle, {
153
167
  editor: validEditor,
154
168
  slateValue: slateValue,
155
169
  updateSlateValue: onValueChange,
156
170
  showComment: false
157
- })))), /*#__PURE__*/React.createElement(InsertElementDialog, {
171
+ })))))), /*#__PURE__*/React.createElement(InsertElementDialog, {
158
172
  editor: validEditor
159
173
  }));
160
174
  });
@@ -40,6 +40,9 @@ const withLink = editor => {
40
40
  const fileName = res.data.files_info[text].name;
41
41
  const fileUuid = res.data.files_info[text].file_uuid;
42
42
  insertSdocFileLink(editor, fileName, fileUuid);
43
+ } else {
44
+ const link = genLinkNode(text, text);
45
+ Transforms.insertNodes(newEditor, link);
43
46
  }
44
47
  } else {
45
48
  const link = genLinkNode(text, text);
@@ -1,4 +1,4 @@
1
- import { WIKI_EDITOR, DOCUMENT_PLUGIN_EDITOR } from '../constants';
1
+ import { DOCUMENT_PLUGIN_EDITOR, WIKI_EDITOR } from '../constants';
2
2
  export const getDomHeight = dom => {
3
3
  const styles = window.getComputedStyle(dom);
4
4
  const rect = dom.getBoundingClientRect();
@@ -58,7 +58,9 @@ export const getHeaderHeight = editor => {
58
58
  } = editor;
59
59
  switch (editorType) {
60
60
  case WIKI_EDITOR:
61
- return 113.2;
61
+ const headerHeight = document.querySelector('.sdoc-editor-container').offsetTop; // async height in wiki
62
+ const headerBarHeight = 44;
63
+ return headerHeight + headerBarHeight;
62
64
  case DOCUMENT_PLUGIN_EDITOR:
63
65
  return 67 + 48 + 49 + 37;
64
66
  default:
@@ -14,7 +14,7 @@ const SdocWikiViewer = _ref => {
14
14
  document,
15
15
  docUuid,
16
16
  isWikiReadOnly,
17
- topSlot
17
+ scrollRef
18
18
  } = _ref;
19
19
  context.initApi();
20
20
 
@@ -51,7 +51,7 @@ const SdocWikiViewer = _ref => {
51
51
  docUuid: docUuid,
52
52
  editor: validEditor,
53
53
  isWikiReadOnly: isWikiReadOnly,
54
- topSlot: topSlot
54
+ scrollRef: scrollRef
55
55
  }));
56
56
  };
57
57
  export default withTranslation('sdoc-editor')(SdocWikiViewer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/sdoc-editor",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",