@seafile/sdoc-editor 0.1.127 → 0.1.128
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.js +25 -172
- package/dist/basic-sdk/extension/plugins/blockquote/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +7 -5
- package/dist/basic-sdk/extension/plugins/check-list/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/check-list/menu/index.js +7 -5
- package/dist/basic-sdk/extension/plugins/clear-format/helpers.js +2 -0
- package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/code-block/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/code-block/menu/index.js +7 -4
- package/dist/basic-sdk/extension/plugins/font/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/font/menu/font-family/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/font/menu/font-size/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/font/menu/index.js +6 -3
- package/dist/basic-sdk/extension/plugins/header/helpers.js +2 -0
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +4 -2
- package/dist/basic-sdk/extension/plugins/image/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/image/menu/index.js +8 -6
- package/dist/basic-sdk/extension/plugins/link/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/link/menu/index.js +8 -6
- package/dist/basic-sdk/extension/plugins/list/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/list/menu/index.js +11 -9
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/sdoc-link/menu/index.js +4 -3
- package/dist/basic-sdk/extension/plugins/sdoc-link/render-elem.js +1 -0
- package/dist/basic-sdk/extension/plugins/table/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-text-align-menu.js +6 -3
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +3 -2
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +12 -6
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/remove-table-menu.js +5 -3
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/table-column-menu.js +8 -4
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/table-row-menu.js +8 -4
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +7 -5
- package/dist/basic-sdk/extension/plugins/text-align/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/text-style/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +5 -4
- package/dist/basic-sdk/extension/toolbar/header-toolbar/index.js +37 -17
- package/dist/basic-sdk/extension/toolbar/header-toolbar/redo-undo.js +7 -4
- package/dist/basic-sdk/layout/editor-container.js +26 -0
- package/dist/basic-sdk/layout/editor-content.js +56 -0
- package/dist/basic-sdk/layout/index.js +4 -0
- package/dist/basic-sdk/outline/index.js +0 -1
- package/dist/basic-sdk/outline/style.css +5 -1
- package/dist/basic-sdk/slate-editor.js +149 -0
- package/dist/basic-sdk/socket/with-socket-io.js +1 -0
- package/dist/basic-sdk/utils/diff.js +12 -0
- package/dist/basic-sdk/views/diff-viewer.js +10 -5
- package/dist/basic-sdk/views/viewer.js +20 -20
- package/dist/components/doc-operations/index.js +2 -0
- package/dist/components/doc-operations/revision-operations/changes-count/index.css +34 -0
- package/dist/components/doc-operations/revision-operations/changes-count/index.js +85 -0
- package/dist/components/doc-operations/revision-operations/index.js +5 -1
- package/dist/pages/diff-viewer.js +2 -0
- package/dist/pages/simple-editor.js +16 -3
- package/package.json +4 -1
- package/public/locales/en/sdoc-editor.json +5 -1
- package/public/locales/zh-CN/sdoc-editor.json +5 -1
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +4 -0
- package/public/media/sdoc-editor-font/iconfont.ttf +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff +0 -0
- package/public/media/sdoc-editor-font/iconfont.woff2 +0 -0
- package/public/media/sdoc-editor-font.css +14 -6
- package/dist/pages/diff-viewer/history-version-viewer.js +0 -15
- package/dist/pages/diff-viewer/index.js +0 -35
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
|
|
3
3
|
import { Editor } from '@seafile/slate';
|
|
4
|
-
import {
|
|
5
|
-
import defaultEditor
|
|
6
|
-
import { focusEditor
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import defaultEditor from './extension';
|
|
6
|
+
import { focusEditor } from './extension/core';
|
|
7
7
|
import { withSocketIO } from './socket';
|
|
8
8
|
import withNodeId from './node-id';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import { SetNodeToDecorations } from './highlight-decorate/setNodeToDecorations';
|
|
14
|
-
import { ScrollContext } from './hooks/use-scroll-context';
|
|
15
|
-
import CommentContextProvider from './comment/comment-context-provider';
|
|
16
|
-
import CommentWrapper from './comment';
|
|
17
|
-
import { usePipDecorate } from './decorates';
|
|
18
|
-
import { getCursorPosition, getDomHeight, getDomMarginTop } from './utils/dom-utils';
|
|
19
|
-
import EventBus from './utils/event-bus';
|
|
20
|
-
import { ColorProvider } from './hooks/use-color-context';
|
|
21
|
-
import ArticleContainer from './layout/article-container';
|
|
22
|
-
import './assets/css/layout.css';
|
|
23
|
-
import './assets/css/sdoc-editor-plugins.css';
|
|
24
|
-
import './assets/css/dropdown-menu.css';
|
|
25
|
-
import SideToolbar from './extension/toolbar/side-toolbar';
|
|
9
|
+
import { PAGE_EDIT_AREA_WIDTH } from './constants';
|
|
10
|
+
import context from '../context';
|
|
11
|
+
import { EditorContainer, EditorContent } from './layout';
|
|
12
|
+
import SlateEditor from './slate-editor';
|
|
26
13
|
var SDocEditor = forwardRef(function (_ref, ref) {
|
|
27
14
|
var document = _ref.document,
|
|
28
15
|
config = _ref.config;
|
|
16
|
+
var _useTranslation = useTranslation(),
|
|
17
|
+
t = _useTranslation.t;
|
|
18
|
+
|
|
29
19
|
// init editor
|
|
30
20
|
var editor = useMemo(function () {
|
|
31
21
|
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
@@ -42,16 +32,6 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
42
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
43
33
|
slateValue = _useState2[0],
|
|
44
34
|
setSlateValue = _useState2[1];
|
|
45
|
-
var _useCursors = useCursors(editor),
|
|
46
|
-
cursors = _useCursors.cursors;
|
|
47
|
-
var scrollRef = useRef(null);
|
|
48
|
-
var decorate = usePipDecorate(editor);
|
|
49
|
-
|
|
50
|
-
// init eventHandler
|
|
51
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
-
var eventProxy = useMemo(function () {
|
|
53
|
-
return new EventProxy(editor);
|
|
54
|
-
}, []);
|
|
55
35
|
|
|
56
36
|
// The parent component can call the method of this component through ref
|
|
57
37
|
useImperativeHandle(ref, function () {
|
|
@@ -95,153 +75,26 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
95
75
|
};
|
|
96
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
77
|
}, []);
|
|
98
|
-
var onChange = useCallback(function (slateValue) {
|
|
99
|
-
setSlateValue(slateValue);
|
|
100
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
|
-
}, []);
|
|
102
|
-
var onMouseDown = useCallback(function (event) {
|
|
103
|
-
if (event.button === 0) {
|
|
104
|
-
editor.reSetTableSelectedRange();
|
|
105
|
-
var eventBus = EventBus.getInstance();
|
|
106
|
-
eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
107
|
-
}
|
|
108
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
109
|
-
}, []);
|
|
110
|
-
var onKeyDown = useCallback(function (event) {
|
|
111
|
-
var _scrollRef$current = scrollRef.current,
|
|
112
|
-
scrollTop = _scrollRef$current.scrollTop,
|
|
113
|
-
clientHeight = _scrollRef$current.clientHeight;
|
|
114
|
-
eventProxy.onKeyDown(event);
|
|
115
|
-
if (event.key === 'ArrowLeft') {
|
|
116
|
-
if (!isSelectionAtBlockStart(editor)) return;
|
|
117
|
-
}
|
|
118
|
-
if (event.key === 'ArrowUp' || event.key === 'ArrowLeft') {
|
|
119
|
-
if (scrollTop === 0) return;
|
|
120
|
-
var prevNode = getPrevNode(editor);
|
|
121
|
-
if (!prevNode) return;
|
|
122
|
-
var domNode = ReactEditor.toDOMNode(editor, prevNode[0]);
|
|
123
|
-
var domHeight = getDomHeight(domNode);
|
|
124
|
-
var isScrollUp = true;
|
|
125
|
-
var _getCursorPosition = getCursorPosition(isScrollUp),
|
|
126
|
-
y = _getCursorPosition.y;
|
|
127
|
-
if (y >= domHeight) return;
|
|
128
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - domHeight));
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (event.key === 'ArrowRight') {
|
|
132
|
-
if (!isSelectionAtBlockEnd(editor)) return;
|
|
133
|
-
}
|
|
134
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowRight') {
|
|
135
|
-
var nextNode = getNextNode(editor);
|
|
136
|
-
if (!nextNode) return;
|
|
137
|
-
var _domNode = ReactEditor.toDOMNode(editor, nextNode[0]);
|
|
138
|
-
var _domHeight = getDomHeight(_domNode);
|
|
139
|
-
var _isScrollUp = false;
|
|
140
|
-
var _getCursorPosition2 = getCursorPosition(_isScrollUp),
|
|
141
|
-
_y = _getCursorPosition2.y;
|
|
142
|
-
if (clientHeight - _y >= _domHeight) return;
|
|
143
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop + _domHeight));
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
if (event.key === 'Backspace') {
|
|
147
|
-
var _getCursorPosition3 = getCursorPosition(),
|
|
148
|
-
_y2 = _getCursorPosition3.y;
|
|
149
78
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
var _domNode2 = ReactEditor.toDOMNode(editor, _prevNode[0]);
|
|
157
|
-
var _domHeight2 = getDomHeight(_domNode2);
|
|
158
|
-
var node = getAboveBlockNode(editor);
|
|
159
|
-
if (!node) return;
|
|
160
|
-
var currentDomNode = ReactEditor.toDOMNode(editor, node[0]);
|
|
161
|
-
var marginTop = getDomMarginTop(currentDomNode);
|
|
162
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2 + marginTop)));
|
|
163
|
-
} else {
|
|
164
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - newY));
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// insider viewport
|
|
170
|
-
if (_y2 >= 0 && _y2 <= clientHeight) {
|
|
171
|
-
if (isSelectionAtBlockStart(editor)) {
|
|
172
|
-
var _prevNode2 = getPrevNode(editor);
|
|
173
|
-
if (!_prevNode2) return;
|
|
174
|
-
var _domNode3 = ReactEditor.toDOMNode(editor, _prevNode2[0]);
|
|
175
|
-
var _domHeight3 = getDomHeight(_domNode3);
|
|
176
|
-
if (_y2 >= _domHeight3) return;
|
|
177
|
-
// Scroll up the height of the previous block
|
|
178
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - _domHeight3));
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// below viewport
|
|
184
|
-
if (_y2 > clientHeight) {
|
|
185
|
-
if (isSelectionAtBlockStart(editor)) {
|
|
186
|
-
// y: text top border
|
|
187
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop + (_y2 - clientHeight)));
|
|
188
|
-
} else {
|
|
189
|
-
var marginBottom = 11.2;
|
|
190
|
-
var _getCursorPosition4 = getCursorPosition(false),
|
|
191
|
-
_newY = _getCursorPosition4.y;
|
|
192
|
-
var rectBottom = _newY + marginBottom; // text bottom border
|
|
193
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop + (rectBottom - clientHeight)));
|
|
194
|
-
}
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
79
|
+
// useMount: reset title
|
|
80
|
+
useEffect(function () {
|
|
81
|
+
var isSdocRevision = context.getSetting('isSdocRevision');
|
|
82
|
+
var originFilename = context.getSetting('originFilename');
|
|
83
|
+
if (isSdocRevision) {
|
|
84
|
+
window.document.getElementsByTagName('title')[0].innerText = "".concat(t('Revision'), " - ").concat(originFilename);
|
|
197
85
|
}
|
|
198
86
|
|
|
199
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
200
88
|
}, []);
|
|
201
|
-
|
|
202
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
203
|
-
scrollLeft = _useState4[0],
|
|
204
|
-
setScrollLeft = _useState4[1];
|
|
205
|
-
var onWrapperScroll = useCallback(function (event) {
|
|
206
|
-
var scrollLeft = event.target.scrollLeft;
|
|
207
|
-
setScrollLeft(scrollLeft);
|
|
208
|
-
}, []);
|
|
209
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
210
|
-
className: "sdoc-editor-container"
|
|
211
|
-
}, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(Toolbar, {
|
|
89
|
+
return /*#__PURE__*/React.createElement(EditorContainer, {
|
|
212
90
|
editor: editor
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}, /*#__PURE__*/React.createElement(SDocOutline, {
|
|
218
|
-
scrollLeft: scrollLeft,
|
|
219
|
-
doc: slateValue,
|
|
220
|
-
docUuid: config.docUuid
|
|
221
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
222
|
-
className: "sdoc-absolute-wrapper"
|
|
223
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
224
|
-
ref: scrollRef,
|
|
225
|
-
className: "sdoc-scroll-container",
|
|
226
|
-
onScroll: onWrapperScroll
|
|
227
|
-
}, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
|
|
228
|
-
value: {
|
|
229
|
-
scrollRef: scrollRef
|
|
230
|
-
}
|
|
231
|
-
}, /*#__PURE__*/React.createElement(Slate, {
|
|
91
|
+
}, /*#__PURE__*/React.createElement(EditorContent, {
|
|
92
|
+
docValue: slateValue,
|
|
93
|
+
showOutline: true
|
|
94
|
+
}, /*#__PURE__*/React.createElement(SlateEditor, {
|
|
232
95
|
editor: editor,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
editor: editor
|
|
237
|
-
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
238
|
-
cursors: cursors,
|
|
239
|
-
renderElement: renderElement,
|
|
240
|
-
renderLeaf: renderLeaf,
|
|
241
|
-
onKeyDown: onKeyDown,
|
|
242
|
-
onMouseDown: onMouseDown,
|
|
243
|
-
decorate: decorate,
|
|
244
|
-
onCut: eventProxy.onCut
|
|
245
|
-
})), /*#__PURE__*/React.createElement(SideToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null)))))))))));
|
|
96
|
+
slateValue: slateValue,
|
|
97
|
+
setSlateValue: setSlateValue
|
|
98
|
+
})));
|
|
246
99
|
});
|
|
247
100
|
export default SDocEditor;
|
|
@@ -3,7 +3,8 @@ import { Editor, Transforms, Element } from '@seafile/slate';
|
|
|
3
3
|
import slugid from 'slugid';
|
|
4
4
|
import { BLOCKQUOTE, CHECK_LIST_ITEM, IMAGE, ORDERED_LIST, UNORDERED_LIST } from '../../constants';
|
|
5
5
|
import { focusEditor, getNodeType } from '../../core';
|
|
6
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
6
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
7
|
+
if (readonly) return true;
|
|
7
8
|
if (editor.selection == null) return true;
|
|
8
9
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
9
10
|
match: function match(n) {
|
|
@@ -22,8 +22,10 @@ var QuoteMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
22
22
|
return getBlockQuoteType(editor) === BLOCKQUOTE;
|
|
23
23
|
};
|
|
24
24
|
_this.isDisabled = function () {
|
|
25
|
-
var
|
|
26
|
-
|
|
25
|
+
var _this$props = _this.props,
|
|
26
|
+
editor = _this$props.editor,
|
|
27
|
+
readonly = _this$props.readonly;
|
|
28
|
+
return isMenuDisabled(editor, readonly);
|
|
27
29
|
};
|
|
28
30
|
_this.onMouseDown = function (e) {
|
|
29
31
|
var editor = _this.props.editor;
|
|
@@ -35,9 +37,9 @@ var QuoteMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
35
37
|
_createClass(QuoteMenu, [{
|
|
36
38
|
key: "render",
|
|
37
39
|
value: function render() {
|
|
38
|
-
var _this$
|
|
39
|
-
isRichEditor = _this$
|
|
40
|
-
className = _this$
|
|
40
|
+
var _this$props2 = this.props,
|
|
41
|
+
isRichEditor = _this$props2.isRichEditor,
|
|
42
|
+
className = _this$props2.className;
|
|
41
43
|
var menuConfig = MENUS_CONFIG_MAP[BLOCKQUOTE];
|
|
42
44
|
var props = _objectSpread(_objectSpread({
|
|
43
45
|
isRichEditor: isRichEditor,
|
|
@@ -3,7 +3,8 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
|
|
|
3
3
|
import { Transforms, Editor, Element } from '@seafile/slate';
|
|
4
4
|
import { CHECK_LIST_ITEM, PARAGRAPH, ELEMENT_TYPE } from '../../constants';
|
|
5
5
|
import { getSelectedNodeByType } from '../../core';
|
|
6
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
6
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
7
|
+
if (readonly) return true;
|
|
7
8
|
if (editor.selection == null) return true;
|
|
8
9
|
var selectedElements = [];
|
|
9
10
|
var nodeEntries = Editor.nodes(editor, {
|
|
@@ -22,8 +22,10 @@ var CheckListMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
22
22
|
return getCheckListItemType(editor) === CHECK_LIST_ITEM;
|
|
23
23
|
};
|
|
24
24
|
_this.isDisabled = function () {
|
|
25
|
-
var
|
|
26
|
-
|
|
25
|
+
var _this$props = _this.props,
|
|
26
|
+
editor = _this$props.editor,
|
|
27
|
+
readonly = _this$props.readonly;
|
|
28
|
+
return isMenuDisabled(editor, readonly);
|
|
27
29
|
};
|
|
28
30
|
_this.onMouseDown = function () {
|
|
29
31
|
var editor = _this.props.editor;
|
|
@@ -36,9 +38,9 @@ var CheckListMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
36
38
|
_createClass(CheckListMenu, [{
|
|
37
39
|
key: "render",
|
|
38
40
|
value: function render() {
|
|
39
|
-
var _this$
|
|
40
|
-
isRichEditor = _this$
|
|
41
|
-
className = _this$
|
|
41
|
+
var _this$props2 = this.props,
|
|
42
|
+
isRichEditor = _this$props2.isRichEditor,
|
|
43
|
+
className = _this$props2.className;
|
|
42
44
|
var menuConfig = MENUS_CONFIG_MAP[CHECK_LIST];
|
|
43
45
|
var props = _objectSpread(_objectSpread({
|
|
44
46
|
isRichEditor: isRichEditor,
|
|
@@ -4,6 +4,8 @@ import { Editor, Text } from '@seafile/slate';
|
|
|
4
4
|
import { CODE_BLOCK, CODE_LINE } from '../../constants';
|
|
5
5
|
import { getNodeType } from '../../core';
|
|
6
6
|
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
7
|
+
var readonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
8
|
+
if (readonly) return true;
|
|
7
9
|
if (editor.selection == null) return true;
|
|
8
10
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
9
11
|
match: function match(n) {
|
|
@@ -7,7 +7,8 @@ var menuConfig = MENUS_CONFIG_MAP[CLEAR_FORMAT];
|
|
|
7
7
|
var ClearFormatMenu = function ClearFormatMenu(_ref) {
|
|
8
8
|
var isRichEditor = _ref.isRichEditor,
|
|
9
9
|
className = _ref.className,
|
|
10
|
-
editor = _ref.editor
|
|
10
|
+
editor = _ref.editor,
|
|
11
|
+
readonly = _ref.readonly;
|
|
11
12
|
var onMouseDown = useCallback(function () {
|
|
12
13
|
clearStyles(editor);
|
|
13
14
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -16,7 +17,7 @@ var ClearFormatMenu = function ClearFormatMenu(_ref) {
|
|
|
16
17
|
isRichEditor: isRichEditor,
|
|
17
18
|
className: className
|
|
18
19
|
}, menuConfig), {}, {
|
|
19
|
-
disabled: isMenuDisabled(editor),
|
|
20
|
+
disabled: isMenuDisabled(editor, readonly),
|
|
20
21
|
isActive: false,
|
|
21
22
|
'onMouseDown': onMouseDown
|
|
22
23
|
});
|
|
@@ -5,7 +5,8 @@ import { Transforms, Editor, Node } from '@seafile/slate';
|
|
|
5
5
|
import slugid from 'slugid';
|
|
6
6
|
import { CODE_BLOCK, CODE_LINE, PARAGRAPH } from '../../constants';
|
|
7
7
|
import { getNodeType, getSelectedNodeByType, getSelectedElems } from '../../core';
|
|
8
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
8
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
9
|
+
if (readonly) return true;
|
|
9
10
|
var selection = editor.selection;
|
|
10
11
|
if (selection == null) return true;
|
|
11
12
|
var selectedElems = getSelectedElems(editor);
|
|
@@ -24,7 +24,10 @@ var CodeBlockMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
24
24
|
return !!elem;
|
|
25
25
|
};
|
|
26
26
|
_this.isDisabled = function () {
|
|
27
|
-
|
|
27
|
+
var _this$props = _this.props,
|
|
28
|
+
editor = _this$props.editor,
|
|
29
|
+
readonly = _this$props.readonly;
|
|
30
|
+
return isMenuDisabled(editor, readonly);
|
|
28
31
|
};
|
|
29
32
|
_this.onMouseDown = function (e) {
|
|
30
33
|
e.preventDefault();
|
|
@@ -45,9 +48,9 @@ var CodeBlockMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
45
48
|
_createClass(CodeBlockMenu, [{
|
|
46
49
|
key: "render",
|
|
47
50
|
value: function render() {
|
|
48
|
-
var _this$
|
|
49
|
-
isRichEditor = _this$
|
|
50
|
-
className = _this$
|
|
51
|
+
var _this$props2 = this.props,
|
|
52
|
+
isRichEditor = _this$props2.isRichEditor,
|
|
53
|
+
className = _this$props2.className;
|
|
51
54
|
var menuConfig = MENUS_CONFIG_MAP[CODE_BLOCK];
|
|
52
55
|
var props = _objectSpread(_objectSpread({
|
|
53
56
|
isRichEditor: isRichEditor,
|
|
@@ -4,7 +4,8 @@ import { CODE_BLOCK, DEFAULT_COMMON_FONT_SIZE, IMAGE, FONT_SIZE, SPECIAL_FONT_SI
|
|
|
4
4
|
import { focusEditor, getParentNode } from '../../core';
|
|
5
5
|
import context from '../../../../context';
|
|
6
6
|
import { isMac } from '../../../../utils';
|
|
7
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
7
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
8
|
+
if (readonly) return true;
|
|
8
9
|
if (!editor.selection) return true;
|
|
9
10
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
10
11
|
match: function match(node) {
|
|
@@ -15,7 +15,8 @@ import './index.css';
|
|
|
15
15
|
var FontFamily = function FontFamily(_ref) {
|
|
16
16
|
var editor = _ref.editor,
|
|
17
17
|
isRichEditor = _ref.isRichEditor,
|
|
18
|
-
className = _ref.className
|
|
18
|
+
className = _ref.className,
|
|
19
|
+
readonly = _ref.readonly;
|
|
19
20
|
var _useState = useState(LocalStorage.getItem(RECENT_USED_FONTS_KEY, [])),
|
|
20
21
|
_useState2 = _slicedToArray(_useState, 2),
|
|
21
22
|
recentUsedFonts = _useState2[0],
|
|
@@ -31,7 +32,7 @@ var FontFamily = function FontFamily(_ref) {
|
|
|
31
32
|
var _useTranslation = useTranslation(),
|
|
32
33
|
t = _useTranslation.t;
|
|
33
34
|
var popoverRef = useRef(null);
|
|
34
|
-
var disabled = isMenuDisabled(editor);
|
|
35
|
+
var disabled = isMenuDisabled(editor, readonly);
|
|
35
36
|
var fontSizeButtonId = 'sdoc-button-font';
|
|
36
37
|
var selectedFont = getFont(editor);
|
|
37
38
|
var lang = context.getSetting('lang');
|
|
@@ -13,7 +13,8 @@ import './index.css';
|
|
|
13
13
|
var FontSize = function FontSize(_ref) {
|
|
14
14
|
var isRichEditor = _ref.isRichEditor,
|
|
15
15
|
className = _ref.className,
|
|
16
|
-
editor = _ref.editor
|
|
16
|
+
editor = _ref.editor,
|
|
17
|
+
readonly = _ref.readonly;
|
|
17
18
|
var _useState = useState(false),
|
|
18
19
|
_useState2 = _slicedToArray(_useState, 2),
|
|
19
20
|
isShowMenu = _useState2[0],
|
|
@@ -21,7 +22,7 @@ var FontSize = function FontSize(_ref) {
|
|
|
21
22
|
var _useTranslation = useTranslation(),
|
|
22
23
|
t = _useTranslation.t;
|
|
23
24
|
var popoverRef = useRef(null);
|
|
24
|
-
var disabled = isMenuDisabled(editor);
|
|
25
|
+
var disabled = isMenuDisabled(editor, readonly);
|
|
25
26
|
var fontSizeButtonId = 'sdoc-button-font-size';
|
|
26
27
|
var selectedFontSize = getFontSize(editor);
|
|
27
28
|
var selectedFontSizeValue = selectedFontSize;
|
|
@@ -2,11 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import FontFamily from './font-family';
|
|
3
3
|
import FontSize from './font-size';
|
|
4
4
|
var Font = function Font(_ref) {
|
|
5
|
-
var editor = _ref.editor
|
|
5
|
+
var editor = _ref.editor,
|
|
6
|
+
readonly = _ref.readonly;
|
|
6
7
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FontFamily, {
|
|
7
|
-
editor: editor
|
|
8
|
+
editor: editor,
|
|
9
|
+
readonly: readonly
|
|
8
10
|
}), /*#__PURE__*/React.createElement(FontSize, {
|
|
9
|
-
editor: editor
|
|
11
|
+
editor: editor,
|
|
12
|
+
readonly: readonly
|
|
10
13
|
}));
|
|
11
14
|
};
|
|
12
15
|
export default Font;
|
|
@@ -3,6 +3,8 @@ import { Editor, Transforms } from '@seafile/slate';
|
|
|
3
3
|
import { getNodeType, isTextNode, getParentNode } from '../../core';
|
|
4
4
|
import { ELEMENT_TYPE } from '../../constants';
|
|
5
5
|
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
6
|
+
var readonly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
7
|
+
if (readonly) return true;
|
|
6
8
|
if (!editor.selection) return true;
|
|
7
9
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
8
10
|
match: function match(n) {
|
|
@@ -41,8 +41,10 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
41
41
|
return _this.getValue() === type;
|
|
42
42
|
};
|
|
43
43
|
_this.isDisabled = function () {
|
|
44
|
-
var
|
|
45
|
-
|
|
44
|
+
var _this$props = _this.props,
|
|
45
|
+
editor = _this$props.editor,
|
|
46
|
+
readonly = _this$props.readonly;
|
|
47
|
+
return isMenuDisabled(editor, readonly);
|
|
46
48
|
};
|
|
47
49
|
_this.onToggleClick = function (event) {
|
|
48
50
|
event.stopPropagation();
|
|
@@ -5,7 +5,8 @@ import { Editor, Range, Transforms } from '@seafile/slate';
|
|
|
5
5
|
import { CODE_BLOCK, IMAGE } from '../../constants';
|
|
6
6
|
import { generateEmptyElement, getNodeType, isTextNode, getParentNode } from '../../core';
|
|
7
7
|
import context from '../../../../context';
|
|
8
|
-
export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor) {
|
|
8
|
+
export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor, readonly) {
|
|
9
|
+
if (readonly) return true;
|
|
9
10
|
var selection = editor.selection;
|
|
10
11
|
if (selection === null) return true;
|
|
11
12
|
if (!Range.isCollapsed(selection)) return true;
|
|
@@ -35,8 +35,10 @@ var ImageMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
35
35
|
return false;
|
|
36
36
|
};
|
|
37
37
|
_this.isDisabled = function () {
|
|
38
|
-
var
|
|
39
|
-
|
|
38
|
+
var _this$props = _this.props,
|
|
39
|
+
editor = _this$props.editor,
|
|
40
|
+
readonly = _this$props.readonly;
|
|
41
|
+
return isInsertImageMenuDisabled(editor, readonly);
|
|
40
42
|
};
|
|
41
43
|
_this.onToggleClick = function (event) {
|
|
42
44
|
event.stopPropagation();
|
|
@@ -105,10 +107,10 @@ var ImageMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
105
107
|
_createClass(ImageMenu, [{
|
|
106
108
|
key: "render",
|
|
107
109
|
value: function render() {
|
|
108
|
-
var _this$
|
|
109
|
-
isRichEditor = _this$
|
|
110
|
-
className = _this$
|
|
111
|
-
t = _this$
|
|
110
|
+
var _this$props2 = this.props,
|
|
111
|
+
isRichEditor = _this$props2.isRichEditor,
|
|
112
|
+
className = _this$props2.className,
|
|
113
|
+
t = _this$props2.t;
|
|
112
114
|
var _this$state = this.state,
|
|
113
115
|
isShowImagePopover = _this$state.isShowImagePopover,
|
|
114
116
|
isShowInsertImageDialog = _this$state.isShowInsertImageDialog;
|
|
@@ -6,7 +6,8 @@ import { Editor, Transforms, Range } from '@seafile/slate';
|
|
|
6
6
|
import slugid from 'slugid';
|
|
7
7
|
import { LINK } from '../../constants';
|
|
8
8
|
import { getNodeType, getSelectedElems, getAboveNode, getEditorString, replaceNodeChildren } from '../../core';
|
|
9
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
9
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
10
|
+
if (readonly) return true;
|
|
10
11
|
if (editor.selection == null) return true;
|
|
11
12
|
var selectedElems = getSelectedElems(editor);
|
|
12
13
|
var notMatch = selectedElems.some(function (elem) {
|
|
@@ -21,8 +21,10 @@ var LinkMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
21
21
|
return getLinkType(editor) === LINK;
|
|
22
22
|
};
|
|
23
23
|
_this.isDisabled = function () {
|
|
24
|
-
var
|
|
25
|
-
|
|
24
|
+
var _this$props = _this.props,
|
|
25
|
+
editor = _this$props.editor,
|
|
26
|
+
readonly = _this$props.readonly;
|
|
27
|
+
return isMenuDisabled(editor, readonly);
|
|
26
28
|
};
|
|
27
29
|
_this.onLinkDialogToggle = function () {
|
|
28
30
|
_this.setState({
|
|
@@ -40,10 +42,10 @@ var LinkMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
40
42
|
_createClass(LinkMenu, [{
|
|
41
43
|
key: "render",
|
|
42
44
|
value: function render() {
|
|
43
|
-
var _this$
|
|
44
|
-
isRichEditor = _this$
|
|
45
|
-
className = _this$
|
|
46
|
-
editor = _this$
|
|
45
|
+
var _this$props2 = this.props,
|
|
46
|
+
isRichEditor = _this$props2.isRichEditor,
|
|
47
|
+
className = _this$props2.className,
|
|
48
|
+
editor = _this$props2.editor;
|
|
47
49
|
var isShowLinkDialog = this.state.isShowLinkDialog;
|
|
48
50
|
var menuConfig = MENUS_CONFIG_MAP[LINK];
|
|
49
51
|
var props = _objectSpread(_objectSpread({
|
|
@@ -4,7 +4,8 @@ import { Editor, Element } from '@seafile/slate';
|
|
|
4
4
|
import { PARAGRAPH } from '../../constants';
|
|
5
5
|
import { getSelectedNodeByType } from '../../core';
|
|
6
6
|
import { toggleList } from './transforms';
|
|
7
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
7
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
8
|
+
if (readonly) return true;
|
|
8
9
|
if (editor.selection == null) return true;
|
|
9
10
|
var selectedElements = [];
|
|
10
11
|
var nodeEntries = Editor.nodes(editor, {
|
|
@@ -25,16 +25,18 @@ var ListMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
25
25
|
return getListType(editor, type) === type;
|
|
26
26
|
};
|
|
27
27
|
_this.isDisabled = function () {
|
|
28
|
-
var
|
|
29
|
-
|
|
28
|
+
var _this$props2 = _this.props,
|
|
29
|
+
editor = _this$props2.editor,
|
|
30
|
+
readonly = _this$props2.readonly;
|
|
31
|
+
return isMenuDisabled(editor, readonly);
|
|
30
32
|
};
|
|
31
33
|
_this.onMouseDown = function (e) {
|
|
32
34
|
e.preventDefault();
|
|
33
35
|
e.stopPropagation();
|
|
34
36
|
if (_this.isDisabled()) return;
|
|
35
|
-
var _this$
|
|
36
|
-
editor = _this$
|
|
37
|
-
type = _this$
|
|
37
|
+
var _this$props3 = _this.props,
|
|
38
|
+
editor = _this$props3.editor,
|
|
39
|
+
type = _this$props3.type;
|
|
38
40
|
|
|
39
41
|
// 执行命令
|
|
40
42
|
setListType(editor, type);
|
|
@@ -45,10 +47,10 @@ var ListMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
45
47
|
_createClass(ListMenu, [{
|
|
46
48
|
key: "render",
|
|
47
49
|
value: function render() {
|
|
48
|
-
var _this$
|
|
49
|
-
isRichEditor = _this$
|
|
50
|
-
className = _this$
|
|
51
|
-
type = _this$
|
|
50
|
+
var _this$props4 = this.props,
|
|
51
|
+
isRichEditor = _this$props4.isRichEditor,
|
|
52
|
+
className = _this$props4.className,
|
|
53
|
+
type = _this$props4.type;
|
|
52
54
|
var menuConfig = MENUS_CONFIG_MAP[type];
|
|
53
55
|
var props = _objectSpread(_objectSpread({
|
|
54
56
|
isRichEditor: isRichEditor,
|
|
@@ -6,7 +6,8 @@ import copy from 'copy-to-clipboard';
|
|
|
6
6
|
import context from '../../../../context';
|
|
7
7
|
import { SDOC_LINK, LINK, INSERT_FILE_DISPLAY_TYPE } from '../../constants';
|
|
8
8
|
import { getNodeType, getSelectedElems } from '../../core';
|
|
9
|
-
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
9
|
+
export var isMenuDisabled = function isMenuDisabled(editor, readonly) {
|
|
10
|
+
if (readonly) return true;
|
|
10
11
|
if (editor.selection == null) return true;
|
|
11
12
|
var selectedElems = getSelectedElems(editor);
|
|
12
13
|
var notMatch = selectedElems.some(function (elem) {
|
|
@@ -11,7 +11,8 @@ var SdocLinkMenu = function SdocLinkMenu(_ref) {
|
|
|
11
11
|
var isRichEditor = _ref.isRichEditor,
|
|
12
12
|
className = _ref.className,
|
|
13
13
|
editor = _ref.editor,
|
|
14
|
-
t = _ref.t
|
|
14
|
+
t = _ref.t,
|
|
15
|
+
readonly = _ref.readonly;
|
|
15
16
|
var _useState = useState(false),
|
|
16
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
17
18
|
showInsertDialog = _useState2[0],
|
|
@@ -25,9 +26,9 @@ var SdocLinkMenu = function SdocLinkMenu(_ref) {
|
|
|
25
26
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
26
27
|
}, []);
|
|
27
28
|
var isDisabled = useCallback(function () {
|
|
28
|
-
return isMenuDisabled(editor);
|
|
29
|
+
return isMenuDisabled(editor, readonly);
|
|
29
30
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
|
-
}, []);
|
|
31
|
+
}, [editor, readonly]);
|
|
31
32
|
var onInsertFileDialogToggle = useCallback(function () {
|
|
32
33
|
setShowInsertPopover(true);
|
|
33
34
|
}, []);
|
|
@@ -87,6 +87,7 @@ var SdocFileLink = function SdocFileLink(_ref) {
|
|
|
87
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
88
|
}, []);
|
|
89
89
|
return /*#__PURE__*/React.createElement("span", Object.assign({}, attributes, {
|
|
90
|
+
"data-id": element.id,
|
|
90
91
|
contentEditable: false,
|
|
91
92
|
className: "sdoc-file-render ".concat(element.display_type === 'card_link' ? 'sdoc-file-card-link' : ''),
|
|
92
93
|
onClick: onClickFile
|
|
@@ -12,7 +12,8 @@ import EventBus from '../../../utils/event-bus';
|
|
|
12
12
|
import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from '../../../constants';
|
|
13
13
|
import ObjectUtils from '../../../utils/object-utils';
|
|
14
14
|
import { replacePastedDataId } from '../../../node-id/helpers';
|
|
15
|
-
export var isTableMenuDisabled = function isTableMenuDisabled(editor) {
|
|
15
|
+
export var isTableMenuDisabled = function isTableMenuDisabled(editor, readonly) {
|
|
16
|
+
if (readonly) return true;
|
|
16
17
|
var selection = editor.selection;
|
|
17
18
|
if (selection === null) return true;
|
|
18
19
|
if (!Range.isCollapsed(selection)) return true;
|