@seafile/sdoc-editor 1.0.7 → 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
  });
@@ -112,10 +112,13 @@ const withBlockquote = editor => {
112
112
  const parentNodeEntry = Editor.parent(editor, paragraphEntry[1]);
113
113
  if (parentNodeEntry && parentNodeEntry[0].type === BLOCKQUOTE) {
114
114
  if (!Node.string(paragraphEntry[0]).length) {
115
- insertFragment(data);
116
- return Transforms.removeNodes(newEditor, {
117
- at: paragraphEntry[1]
115
+ data.forEach(node => {
116
+ if (node.type === BLOCKQUOTE) {
117
+ node.type = PARAGRAPH;
118
+ }
118
119
  });
120
+ insertFragment(data);
121
+ return;
119
122
  }
120
123
  }
121
124
  }
@@ -1,8 +1,10 @@
1
1
  import React, { useCallback, useState } from 'react';
2
2
  import classNames from 'classnames';
3
+ import { useTranslation } from 'react-i18next';
3
4
  import { ElementPopover } from '../../../../commons';
4
5
  import ColorSelector from '../callout-color-selector';
5
6
  import IconSelector from '../callout-icon';
7
+ import { setCalloutIcon } from '../../helper';
6
8
  import './style.css';
7
9
  export default function CalloutHoverMenu(_ref) {
8
10
  let {
@@ -12,6 +14,9 @@ export default function CalloutHoverMenu(_ref) {
12
14
  } = _ref;
13
15
  const [isShowColorSelector, setIsShowColorSelector] = useState(false);
14
16
  const [isShowIcon, setIsShowIcon] = useState(false);
17
+ const {
18
+ t
19
+ } = useTranslation();
15
20
  const onColorSelectorToggle = useCallback(event => {
16
21
  event.stopPropagation();
17
22
  if (!isShowColorSelector) {
@@ -38,6 +43,9 @@ export default function CalloutHoverMenu(_ref) {
38
43
  'callout-menu-item': true,
39
44
  'icon-active': isShowIcon
40
45
  });
46
+ const handleRemoveIcon = () => {
47
+ setCalloutIcon(editor, '');
48
+ };
41
49
  return /*#__PURE__*/React.createElement(ElementPopover, null, /*#__PURE__*/React.createElement("div", {
42
50
  className: "sdoc-callout-hover-menu",
43
51
  style: popoverPosition
@@ -65,5 +73,10 @@ export default function CalloutHoverMenu(_ref) {
65
73
  editor: editor,
66
74
  element: element,
67
75
  onCloseSelector: onCloseSelector
68
- })));
76
+ }), /*#__PURE__*/React.createElement("div", {
77
+ className: "callout-menu-divider"
78
+ }), /*#__PURE__*/React.createElement("div", {
79
+ className: "callout-menu-item",
80
+ onClick: handleRemoveIcon
81
+ }, t('Remove_icon'))));
69
82
  }
@@ -14,12 +14,14 @@
14
14
  display: flex;
15
15
  justify-content: center;
16
16
  align-items: center;
17
- color: #aaa;
17
+ font-size: 12px;
18
+ color: #212529;
18
19
  cursor: pointer;
20
+ border-radius: 3px;
19
21
  }
20
22
 
21
23
  .sdoc-callout-hover-menu .callout-menu-item:hover {
22
- color: #444;
24
+ background-color: #f2f2f2;
23
25
  }
24
26
 
25
27
  .sdoc-callout-hover-menu .callout-menu-item .sdocfont {
@@ -29,33 +29,29 @@ const withLink = editor => {
29
29
  }
30
30
  return isInline(elem);
31
31
  };
32
- newEditor.insertData = data => {
32
+ newEditor.insertData = async data => {
33
33
  // Paste link content
34
34
  const text = data.getData('text/plain');
35
+ // Internal link, insert sdoc file link
35
36
  if (isUrl(text) && !isImage(text)) {
36
- const link = genLinkNode(text, text);
37
- Transforms.insertNodes(newEditor, link);
38
- // Void merging text fron link
37
+ if (isSameDomain(text, context.getSetting('serviceUrl'))) {
38
+ const res = await context.getLinkFilesInfo([text]);
39
+ if (isSdocFile(res, text)) {
40
+ const fileName = res.data.files_info[text].name;
41
+ const fileUuid = res.data.files_info[text].file_uuid;
42
+ insertSdocFileLink(editor, fileName, fileUuid);
43
+ } else {
44
+ const link = genLinkNode(text, text);
45
+ Transforms.insertNodes(newEditor, link);
46
+ }
47
+ } else {
48
+ const link = genLinkNode(text, text);
49
+ Transforms.insertNodes(newEditor, link);
50
+ }
51
+ // Void merging text from link
39
52
  const [, focusPath] = Editor.next(newEditor);
40
53
  const focusPoint = Editor.start(newEditor, focusPath);
41
54
  Transforms.select(newEditor, focusPoint);
42
- if (isSameDomain(text, context.getSetting('serviceUrl'))) {
43
- context.getLinkFilesInfo([text]).then(res => {
44
- if (isSdocFile(res, text)) {
45
- const [nodeEntry] = Editor.nodes(editor, {
46
- match: n => n.type === LINK,
47
- universal: true
48
- });
49
- const fileName = res.data.files_info[text].name;
50
- const fileUuid = res.data.files_info[text].file_uuid;
51
- Transforms.removeNodes(editor, {
52
- at: nodeEntry[1]
53
- });
54
- insertSdocFileLink(editor, fileName, fileUuid);
55
- return;
56
- }
57
- });
58
- }
59
55
  return;
60
56
  }
61
57
  insertData(data);
@@ -87,7 +87,7 @@ const ColorSelectorPopover = _ref => {
87
87
  // eslint-disable-next-line react-hooks/exhaustive-deps
88
88
  }, [readonly]);
89
89
  return /*#__PURE__*/React.createElement(UncontrolledPopover, {
90
- target: target,
90
+ target: target.current,
91
91
  trigger: "hover",
92
92
  placement: "right-start",
93
93
  hideArrow: true,
@@ -190,7 +190,7 @@ class TableContextMenu extends React.Component {
190
190
  onClick: e => console.log('123')
191
191
  }, /*#__PURE__*/React.createElement("span", null, t('Horizontal_align')), /*#__PURE__*/React.createElement("i", {
192
192
  className: "sdocfont sdoc-right-slide"
193
- })), /*#__PURE__*/React.createElement(HorizontalAlignPopover, {
193
+ })), this.horizontalAlignRef.current && /*#__PURE__*/React.createElement(HorizontalAlignPopover, {
194
194
  target: this.horizontalAlignRef,
195
195
  editor: editor,
196
196
  readonly: readonly,
@@ -200,7 +200,7 @@ class TableContextMenu extends React.Component {
200
200
  className: "dropdown-item side-extendable"
201
201
  }, /*#__PURE__*/React.createElement("span", null, t('Vertical_align')), /*#__PURE__*/React.createElement("i", {
202
202
  className: "sdocfont sdoc-right-slide"
203
- })), /*#__PURE__*/React.createElement(VerticalAlignPopover, {
203
+ })), this.verticalAlignRef.current && /*#__PURE__*/React.createElement(VerticalAlignPopover, {
204
204
  target: this.verticalAlignRef,
205
205
  editor: editor,
206
206
  readonly: readonly,
@@ -210,7 +210,7 @@ class TableContextMenu extends React.Component {
210
210
  className: "dropdown-item side-extendable"
211
211
  }, /*#__PURE__*/React.createElement("span", null, t('Background_color')), /*#__PURE__*/React.createElement("i", {
212
212
  className: "sdocfont sdoc-right-slide"
213
- })), /*#__PURE__*/React.createElement(ColorSelectorPopover, {
213
+ })), this.colorSelectorRef.current && /*#__PURE__*/React.createElement(ColorSelectorPopover, {
214
214
  target: this.colorSelectorRef,
215
215
  editor: editor,
216
216
  readonly: readonly
@@ -32,7 +32,7 @@ const VerticalAlignPopover = _ref => {
32
32
  }, 0);
33
33
  }, [editor, readonly]);
34
34
  return /*#__PURE__*/React.createElement(UncontrolledPopover, {
35
- target: target,
35
+ target: target.current,
36
36
  trigger: "hover",
37
37
  placement: "right-start",
38
38
  hideArrow: true,
@@ -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.7",
3
+ "version": "1.0.9",
4
4
  "private": false,
5
5
  "description": "This is a sdoc editor",
6
6
  "main": "dist/index.js",
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Header"
471
+ "Header": "Header",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Überschrift"
471
+ "Header": "Überschrift",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Header"
471
+ "Header": "Header",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Encabezado"
471
+ "Header": "Encabezado",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Encabezado"
471
+ "Header": "Encabezado",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Encabezado"
471
+ "Header": "Encabezado",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "En-tête "
471
+ "Header": "En-tête ",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Show record numbers",
469
469
  "Alternate_color": "Alternate color",
470
470
  "Select_column_display_option_color_tip": "Single-select and multi-select columns display option colors",
471
- "Header": "Intestazione"
471
+ "Header": "Intestazione",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "Показывать номера записей",
469
469
  "Alternate_color": "Альтернативный цвет",
470
470
  "Select_column_display_option_color_tip": "Цвета параметров отображения столбцов с одиночным и множественным выбором",
471
- "Header": "Заголовок"
471
+ "Header": "Заголовок",
472
+ "Remove_icon": "Remove icon"
472
473
  }
@@ -468,5 +468,6 @@
468
468
  "Show_record_numbers": "显示记录编号",
469
469
  "Alternate_color": "单双行不同背景色",
470
470
  "Select_column_display_option_color_tip": "单选列和多选列显示选项颜色",
471
- "Header": "标题"
471
+ "Header": "标题",
472
+ "Remove_icon": "移除图标"
472
473
  }