@seafile/sdoc-editor 1.0.5 → 1.0.6-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.
- package/dist/basic-sdk/editor/wiki-editor.js +31 -17
- package/dist/basic-sdk/extension/constants/menus-config.js +5 -0
- package/dist/basic-sdk/extension/plugins/blockquote/helpers.js +6 -2
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +2 -4
- package/dist/basic-sdk/extension/toolbar/insert-element-toolbar/index.js +12 -2
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +12 -2
- package/dist/basic-sdk/utils/dom-utils.js +4 -2
- package/dist/pages/sdoc-wiki-viewer.js +2 -2
- package/package.json +1 -1
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
},
|
|
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(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
});
|
|
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import { Editor, Transforms, Element, Node } from '@seafile/slate';
|
|
3
3
|
import slugid from 'slugid';
|
|
4
4
|
import { BLOCKQUOTE, CHECK_LIST_ITEM, IMAGE, ORDERED_LIST, PARAGRAPH, UNORDERED_LIST, CODE_BLOCK, TABLE, CALL_OUT } from '../../constants';
|
|
5
|
-
import { getNodeType } from '../../core';
|
|
5
|
+
import { focusEditor, getNodeType } from '../../core';
|
|
6
6
|
export const isMenuDisabled = (editor, readonly) => {
|
|
7
7
|
if (readonly) return true;
|
|
8
8
|
if (editor.selection == null) return true;
|
|
@@ -41,7 +41,7 @@ export const getBlockQuoteType = editor => {
|
|
|
41
41
|
return getNodeType(n);
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
// If cursor is in
|
|
44
|
+
// If cursor is in callout, insert block quote in callout, otherwise wrap block quote directly
|
|
45
45
|
export const setBlockQuoteType = (editor, active) => {
|
|
46
46
|
if (!active) {
|
|
47
47
|
const blockquoteNode = {
|
|
@@ -108,4 +108,8 @@ export const getFormattedRestElements = data => {
|
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
return restElements;
|
|
111
|
+
};
|
|
112
|
+
export const insertBlockQuote = (editor, active) => {
|
|
113
|
+
setBlockQuoteType(editor, active);
|
|
114
|
+
focusEditor(editor);
|
|
111
115
|
};
|
|
@@ -3,8 +3,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { BLOCKQUOTE, MENUS_CONFIG_MAP } from '../../../constants';
|
|
5
5
|
import { MenuItem } from '../../../commons';
|
|
6
|
-
import { getBlockQuoteType,
|
|
7
|
-
import { focusEditor } from '../../../core';
|
|
6
|
+
import { getBlockQuoteType, insertBlockQuote, isMenuDisabled } from '../helpers';
|
|
8
7
|
class QuoteMenu extends React.Component {
|
|
9
8
|
constructor() {
|
|
10
9
|
super(...arguments);
|
|
@@ -26,8 +25,7 @@ class QuoteMenu extends React.Component {
|
|
|
26
25
|
editor
|
|
27
26
|
} = this.props;
|
|
28
27
|
const active = this.isActive(editor);
|
|
29
|
-
|
|
30
|
-
focusEditor(editor);
|
|
28
|
+
insertBlockQuote(editor, active);
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
render() {
|
|
@@ -8,7 +8,7 @@ import TableSizePopover from '../../plugins/table/popover/table-size-popover';
|
|
|
8
8
|
import { changeToCodeBlock } from '../../plugins/code-block/helpers';
|
|
9
9
|
import { toggleList } from '../../plugins/list/transforms';
|
|
10
10
|
import { setCheckListItemType } from '../../plugins/check-list/helpers';
|
|
11
|
-
import { ELEMENT_TYPE, IMAGE, INSERT_POSITION, LINK, LOCAL_IMAGE, PARAGRAPH, SIDE_INSERT_MENUS_CONFIG, TABLE, CODE_BLOCK, CALL_OUT, UNORDERED_LIST, ORDERED_LIST, CHECK_LIST_ITEM, QUICK_INSERT } from '../../constants';
|
|
11
|
+
import { ELEMENT_TYPE, IMAGE, INSERT_POSITION, LINK, LOCAL_IMAGE, PARAGRAPH, SIDE_INSERT_MENUS_CONFIG, TABLE, CODE_BLOCK, CALL_OUT, UNORDERED_LIST, ORDERED_LIST, CHECK_LIST_ITEM, QUICK_INSERT, BLOCKQUOTE } from '../../constants';
|
|
12
12
|
import EventBus from '../../../utils/event-bus';
|
|
13
13
|
import { INTERNAL_EVENT } from '../../../constants';
|
|
14
14
|
import DropdownMenuItem from '../../commons/dropdown-menu-item';
|
|
@@ -16,6 +16,7 @@ import { wrapCallout } from '../../plugins/callout/helper';
|
|
|
16
16
|
import keyCodes from '../../../../constants/key-codes';
|
|
17
17
|
import { SELECTED_ITEM_CLASS_NAME, SHORT_INSERT_ELEMENT_USER_INPUT_MAP } from './const';
|
|
18
18
|
import { getAboveBlockNode } from '../../core';
|
|
19
|
+
import { insertBlockQuote } from '../../plugins/blockquote/helpers';
|
|
19
20
|
import './style.css';
|
|
20
21
|
const QuickInsertBlockMenu = _ref => {
|
|
21
22
|
let {
|
|
@@ -97,6 +98,10 @@ const QuickInsertBlockMenu = _ref => {
|
|
|
97
98
|
});
|
|
98
99
|
return !!callout;
|
|
99
100
|
}, [editor]);
|
|
101
|
+
const onInsertBlockQuote = useCallback(() => {
|
|
102
|
+
callback && callback();
|
|
103
|
+
insertBlockQuote(editor, false);
|
|
104
|
+
}, [callback, editor]);
|
|
100
105
|
const dropDownItems = useMemo(() => {
|
|
101
106
|
let items = {
|
|
102
107
|
[IMAGE]: /*#__PURE__*/React.createElement(DropdownMenuItem, {
|
|
@@ -126,6 +131,11 @@ const QuickInsertBlockMenu = _ref => {
|
|
|
126
131
|
menuConfig: _objectSpread({}, SIDE_INSERT_MENUS_CONFIG[ELEMENT_TYPE.LINK]),
|
|
127
132
|
onClick: openLinkDialog
|
|
128
133
|
}),
|
|
134
|
+
[BLOCKQUOTE]: /*#__PURE__*/React.createElement(DropdownMenuItem, {
|
|
135
|
+
key: "sdoc-insert-menu-blockquote",
|
|
136
|
+
menuConfig: _objectSpread({}, SIDE_INSERT_MENUS_CONFIG[ELEMENT_TYPE.BLOCKQUOTE]),
|
|
137
|
+
onClick: onInsertBlockQuote
|
|
138
|
+
}),
|
|
129
139
|
[CODE_BLOCK]: /*#__PURE__*/React.createElement(DropdownMenuItem, {
|
|
130
140
|
key: "sdoc-insert-menu-code-block",
|
|
131
141
|
menuConfig: _objectSpread({}, SIDE_INSERT_MENUS_CONFIG[ELEMENT_TYPE.CODE_BLOCK]),
|
|
@@ -171,7 +181,7 @@ const QuickInsertBlockMenu = _ref => {
|
|
|
171
181
|
});
|
|
172
182
|
});
|
|
173
183
|
return items;
|
|
174
|
-
}, [createTable, editor, isDisableCallout, isEmptyNode, onInsert, onInsertCallout, onInsertCheckList, onInsertCodeBlock, onInsertImageToggle, onInsertList, openLinkDialog]);
|
|
184
|
+
}, [createTable, editor, isDisableCallout, isEmptyNode, onInsert, onInsertBlockQuote, onInsertCallout, onInsertCheckList, onInsertCodeBlock, onInsertImageToggle, onInsertList, openLinkDialog]);
|
|
175
185
|
const getSelectItemDom = selectIndex => {
|
|
176
186
|
const dropDownItemWrapper = downDownWrapperRef.current;
|
|
177
187
|
const currentSelectItem = dropDownItemWrapper.children[selectIndex];
|
|
@@ -8,7 +8,7 @@ import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
|
8
8
|
import { focusEditor } from '../../core';
|
|
9
9
|
import { getDomTopHeight, setSelection, isVoidNode, getNodeEntry, isBlockquote, isList, onWrapListItem } from './helpers';
|
|
10
10
|
import { insertImageFiles } from '../../plugins/image/helpers';
|
|
11
|
-
import { INTERNAL_EVENT } from '../../../constants';
|
|
11
|
+
import { INTERNAL_EVENT, WIKI_EDITOR } from '../../../constants';
|
|
12
12
|
import { CODE_BLOCK, TABLE, BLOCKQUOTE, CHECK_LIST_ITEM, CALL_OUT, TABLE_DRAG_KEY } from '../../constants';
|
|
13
13
|
import { getCalloutEntry } from '../../plugins/callout/helper';
|
|
14
14
|
import './index.css';
|
|
@@ -77,11 +77,21 @@ const SideToolbar = () => {
|
|
|
77
77
|
const offsetY = !editor.editorType ? -1 : 0; // editorType is undefined means sdoc editor
|
|
78
78
|
const topValue = top + scrollRef.current.scrollTop + offsetY;
|
|
79
79
|
if (topValue !== sidePosition.top) setIsMoving(true);
|
|
80
|
+
let left = 20;
|
|
81
|
+
if (editor.editorType === WIKI_EDITOR) {
|
|
82
|
+
const {
|
|
83
|
+
left: editorLeft
|
|
84
|
+
} = document.querySelector('#sdoc-editor').getBoundingClientRect();
|
|
85
|
+
const {
|
|
86
|
+
left: containerLeft
|
|
87
|
+
} = document.querySelector('.sdoc-editor-container').getBoundingClientRect();
|
|
88
|
+
left = editorLeft - containerLeft - 40;
|
|
89
|
+
}
|
|
80
90
|
setTimeout(() => {
|
|
81
91
|
// wait animation
|
|
82
92
|
setSidePosition({
|
|
83
93
|
top: topValue,
|
|
84
|
-
left:
|
|
94
|
+
left: left
|
|
85
95
|
});
|
|
86
96
|
}, 150);
|
|
87
97
|
setSlateNode(node);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
+
scrollRef: scrollRef
|
|
55
55
|
}));
|
|
56
56
|
};
|
|
57
57
|
export default withTranslation('sdoc-editor')(SdocWikiViewer);
|