@seafile/sdoc-editor 0.1.123 → 0.1.125-beta
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/comment/comment/editor-comment.js +11 -2
- package/dist/basic-sdk/comment/comment/style.css +1 -0
- package/dist/basic-sdk/editor.js +25 -171
- 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/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/check-list/menu/index.js +7 -5
- package/dist/basic-sdk/extension/plugins/check-list/render-elem.js +5 -9
- 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/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/code-block/menu/index.js +7 -4
- package/dist/basic-sdk/extension/plugins/code-block/plugin.js +9 -1
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +18 -9
- package/dist/basic-sdk/extension/plugins/font/helpers.js +5 -3
- 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/index.js +2 -1
- 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/paragraph/index.js +7 -0
- package/dist/basic-sdk/extension/plugins/paragraph/render-elem.js +35 -0
- package/dist/basic-sdk/extension/plugins/sdoc-link/dialogs/select-sdoc-file-dialog/index.css +55 -0
- package/dist/basic-sdk/extension/plugins/sdoc-link/{menu/sdoc-link-file-dialog.js → dialogs/select-sdoc-file-dialog/index.js} +36 -29
- package/dist/basic-sdk/extension/plugins/sdoc-link/dialogs/select-sdoc-file-dialog/local-files/index.css +75 -0
- package/dist/basic-sdk/extension/plugins/sdoc-link/{menu/local-files.js → dialogs/select-sdoc-file-dialog/local-files/index.js} +42 -32
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +2 -1
- package/dist/basic-sdk/extension/plugins/sdoc-link/{menu/sdoc-link-hover-menu.js → hover-menu/index.js} +1 -1
- package/dist/basic-sdk/extension/plugins/sdoc-link/menu/index.js +7 -6
- package/dist/basic-sdk/extension/plugins/sdoc-link/render-elem.js +3 -2
- 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/render/render-element.js +14 -48
- 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 +6 -7
- 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 +1 -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/basic-sdk/extension/plugins/sdoc-link/menu/local-files.css +0 -98
- package/dist/basic-sdk/extension/plugins/sdoc-link/menu/sdoc-link-file-dialog.css +0 -35
- package/dist/pages/diff-viewer/history-version-viewer.js +0 -15
- package/dist/pages/diff-viewer/index.js +0 -35
- /package/dist/basic-sdk/extension/plugins/sdoc-link/{menu/sdoc-link-hover-menu.css → hover-menu/index.css} +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
2
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useSlateStatic } from '@seafile/slate-react';
|
|
4
|
+
import { Node } from '@seafile/slate';
|
|
3
5
|
import useSelectionUpdate from '../../hooks/use-selection-update';
|
|
4
6
|
import { useCursorPosition } from '../helper';
|
|
5
7
|
import CommentList from './comment-list';
|
|
@@ -7,6 +9,7 @@ import { useSelectionElement } from '../../hooks/use-selection-element';
|
|
|
7
9
|
import { useCommentContext } from '../hooks/use-comment-context';
|
|
8
10
|
var EditorComment = function EditorComment() {
|
|
9
11
|
useSelectionUpdate();
|
|
12
|
+
var editor = useSlateStatic();
|
|
10
13
|
var selectionElement = useSelectionElement();
|
|
11
14
|
var _useState = useState(false),
|
|
12
15
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -17,10 +20,16 @@ var EditorComment = function EditorComment() {
|
|
|
17
20
|
}, []);
|
|
18
21
|
var cursor = useCursorPosition();
|
|
19
22
|
var style = useMemo(function () {
|
|
23
|
+
var _Node$string;
|
|
24
|
+
if (selectionElement && ((_Node$string = Node.string(selectionElement)) === null || _Node$string === void 0 ? void 0 : _Node$string.length) === 0) {
|
|
25
|
+
return {
|
|
26
|
+
top: '-99999px'
|
|
27
|
+
};
|
|
28
|
+
}
|
|
20
29
|
return {
|
|
21
30
|
top: cursor.y === 0 || isShowComments ? '-99999px' : cursor.y
|
|
22
31
|
};
|
|
23
|
-
}, [cursor, isShowComments]);
|
|
32
|
+
}, [cursor, isShowComments, selectionElement]);
|
|
24
33
|
|
|
25
34
|
// When selectionElement update, recalculate comment's panel state
|
|
26
35
|
var _useState3 = useState([]),
|
|
@@ -41,7 +50,7 @@ var EditorComment = function EditorComment() {
|
|
|
41
50
|
}
|
|
42
51
|
setComments([]);
|
|
43
52
|
setIsShowComments(false);
|
|
44
|
-
}, [element_comments_map, selectionElement]);
|
|
53
|
+
}, [element_comments_map, selectionElement, editor.selection]);
|
|
45
54
|
return /*#__PURE__*/React.createElement("div", {
|
|
46
55
|
className: "sdoc-comment-container"
|
|
47
56
|
}, /*#__PURE__*/React.createElement("div", {
|
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -1,30 +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';
|
|
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';
|
|
25
13
|
var SDocEditor = forwardRef(function (_ref, ref) {
|
|
26
14
|
var document = _ref.document,
|
|
27
15
|
config = _ref.config;
|
|
16
|
+
var _useTranslation = useTranslation(),
|
|
17
|
+
t = _useTranslation.t;
|
|
18
|
+
|
|
28
19
|
// init editor
|
|
29
20
|
var editor = useMemo(function () {
|
|
30
21
|
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
@@ -41,16 +32,6 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
41
32
|
_useState2 = _slicedToArray(_useState, 2),
|
|
42
33
|
slateValue = _useState2[0],
|
|
43
34
|
setSlateValue = _useState2[1];
|
|
44
|
-
var _useCursors = useCursors(editor),
|
|
45
|
-
cursors = _useCursors.cursors;
|
|
46
|
-
var scrollRef = useRef(null);
|
|
47
|
-
var decorate = usePipDecorate(editor);
|
|
48
|
-
|
|
49
|
-
// init eventHandler
|
|
50
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
|
-
var eventProxy = useMemo(function () {
|
|
52
|
-
return new EventProxy(editor);
|
|
53
|
-
}, []);
|
|
54
35
|
|
|
55
36
|
// The parent component can call the method of this component through ref
|
|
56
37
|
useImperativeHandle(ref, function () {
|
|
@@ -94,153 +75,26 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
94
75
|
};
|
|
95
76
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
77
|
}, []);
|
|
97
|
-
var onChange = useCallback(function (slateValue) {
|
|
98
|
-
setSlateValue(slateValue);
|
|
99
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
|
-
}, []);
|
|
101
|
-
var onMouseDown = useCallback(function (event) {
|
|
102
|
-
if (event.button === 0) {
|
|
103
|
-
editor.reSetTableSelectedRange();
|
|
104
|
-
var eventBus = EventBus.getInstance();
|
|
105
|
-
eventBus.dispatch(INTERNAL_EVENT.CANCEL_TABLE_SELECT_RANGE);
|
|
106
|
-
}
|
|
107
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
108
|
-
}, []);
|
|
109
|
-
var onKeyDown = useCallback(function (event) {
|
|
110
|
-
var _scrollRef$current = scrollRef.current,
|
|
111
|
-
scrollTop = _scrollRef$current.scrollTop,
|
|
112
|
-
clientHeight = _scrollRef$current.clientHeight;
|
|
113
|
-
eventProxy.onKeyDown(event);
|
|
114
|
-
if (event.key === 'ArrowLeft') {
|
|
115
|
-
if (!isSelectionAtBlockStart(editor)) return;
|
|
116
|
-
}
|
|
117
|
-
if (event.key === 'ArrowUp' || event.key === 'ArrowLeft') {
|
|
118
|
-
if (scrollTop === 0) return;
|
|
119
|
-
var prevNode = getPrevNode(editor);
|
|
120
|
-
if (!prevNode) return;
|
|
121
|
-
var domNode = ReactEditor.toDOMNode(editor, prevNode[0]);
|
|
122
|
-
var domHeight = getDomHeight(domNode);
|
|
123
|
-
var isScrollUp = true;
|
|
124
|
-
var _getCursorPosition = getCursorPosition(isScrollUp),
|
|
125
|
-
y = _getCursorPosition.y;
|
|
126
|
-
if (y >= domHeight) return;
|
|
127
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - domHeight));
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (event.key === 'ArrowRight') {
|
|
131
|
-
if (!isSelectionAtBlockEnd(editor)) return;
|
|
132
|
-
}
|
|
133
|
-
if (event.key === 'ArrowDown' || event.key === 'ArrowRight') {
|
|
134
|
-
var nextNode = getNextNode(editor);
|
|
135
|
-
if (!nextNode) return;
|
|
136
|
-
var _domNode = ReactEditor.toDOMNode(editor, nextNode[0]);
|
|
137
|
-
var _domHeight = getDomHeight(_domNode);
|
|
138
|
-
var _isScrollUp = false;
|
|
139
|
-
var _getCursorPosition2 = getCursorPosition(_isScrollUp),
|
|
140
|
-
_y = _getCursorPosition2.y;
|
|
141
|
-
if (clientHeight - _y >= _domHeight) return;
|
|
142
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop + _domHeight));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
if (event.key === 'Backspace') {
|
|
146
|
-
var _getCursorPosition3 = getCursorPosition(),
|
|
147
|
-
_y2 = _getCursorPosition3.y;
|
|
148
78
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
var _domNode2 = ReactEditor.toDOMNode(editor, _prevNode[0]);
|
|
156
|
-
var _domHeight2 = getDomHeight(_domNode2);
|
|
157
|
-
var node = getAboveBlockNode(editor);
|
|
158
|
-
if (!node) return;
|
|
159
|
-
var currentDomNode = ReactEditor.toDOMNode(editor, node[0]);
|
|
160
|
-
var marginTop = getDomMarginTop(currentDomNode);
|
|
161
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - (newY + _domHeight2 + marginTop)));
|
|
162
|
-
} else {
|
|
163
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - newY));
|
|
164
|
-
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// insider viewport
|
|
169
|
-
if (_y2 >= 0 && _y2 <= clientHeight) {
|
|
170
|
-
if (isSelectionAtBlockStart(editor)) {
|
|
171
|
-
var _prevNode2 = getPrevNode(editor);
|
|
172
|
-
if (!_prevNode2) return;
|
|
173
|
-
var _domNode3 = ReactEditor.toDOMNode(editor, _prevNode2[0]);
|
|
174
|
-
var _domHeight3 = getDomHeight(_domNode3);
|
|
175
|
-
if (_y2 >= _domHeight3) return;
|
|
176
|
-
// Scroll up the height of the previous block
|
|
177
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop - _domHeight3));
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// below viewport
|
|
183
|
-
if (_y2 > clientHeight) {
|
|
184
|
-
if (isSelectionAtBlockStart(editor)) {
|
|
185
|
-
// y: text top border
|
|
186
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop + (_y2 - clientHeight)));
|
|
187
|
-
} else {
|
|
188
|
-
var marginBottom = 11.2;
|
|
189
|
-
var _getCursorPosition4 = getCursorPosition(false),
|
|
190
|
-
_newY = _getCursorPosition4.y;
|
|
191
|
-
var rectBottom = _newY + marginBottom; // text bottom border
|
|
192
|
-
scrollRef.current.scroll(0, Math.max(0, scrollTop + (rectBottom - clientHeight)));
|
|
193
|
-
}
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
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);
|
|
196
85
|
}
|
|
197
86
|
|
|
198
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
199
88
|
}, []);
|
|
200
|
-
|
|
201
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
202
|
-
scrollLeft = _useState4[0],
|
|
203
|
-
setScrollLeft = _useState4[1];
|
|
204
|
-
var onWrapperScroll = useCallback(function (event) {
|
|
205
|
-
var scrollLeft = event.target.scrollLeft;
|
|
206
|
-
setScrollLeft(scrollLeft);
|
|
207
|
-
}, []);
|
|
208
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
209
|
-
className: "sdoc-editor-container"
|
|
210
|
-
}, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(Toolbar, {
|
|
89
|
+
return /*#__PURE__*/React.createElement(EditorContainer, {
|
|
211
90
|
editor: editor
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}, /*#__PURE__*/React.createElement(SDocOutline, {
|
|
217
|
-
scrollLeft: scrollLeft,
|
|
218
|
-
doc: slateValue,
|
|
219
|
-
docUuid: config.docUuid
|
|
220
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
221
|
-
className: "sdoc-absolute-wrapper"
|
|
222
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
223
|
-
ref: scrollRef,
|
|
224
|
-
className: "sdoc-scroll-container",
|
|
225
|
-
onScroll: onWrapperScroll
|
|
226
|
-
}, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
|
|
227
|
-
value: {
|
|
228
|
-
scrollRef: scrollRef
|
|
229
|
-
}
|
|
230
|
-
}, /*#__PURE__*/React.createElement(Slate, {
|
|
91
|
+
}, /*#__PURE__*/React.createElement(EditorContent, {
|
|
92
|
+
docValue: slateValue,
|
|
93
|
+
showOutline: true
|
|
94
|
+
}, /*#__PURE__*/React.createElement(SlateEditor, {
|
|
231
95
|
editor: editor,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
editor: editor
|
|
236
|
-
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
237
|
-
cursors: cursors,
|
|
238
|
-
renderElement: renderElement,
|
|
239
|
-
renderLeaf: renderLeaf,
|
|
240
|
-
onKeyDown: onKeyDown,
|
|
241
|
-
onMouseDown: onMouseDown,
|
|
242
|
-
decorate: decorate,
|
|
243
|
-
onCut: eventProxy.onCut
|
|
244
|
-
})), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null)))))))))));
|
|
96
|
+
slateValue: slateValue,
|
|
97
|
+
setSlateValue: setSlateValue
|
|
98
|
+
})));
|
|
245
99
|
});
|
|
246
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, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import withCheckList from './plugin';
|
|
2
|
-
import {
|
|
2
|
+
import { renderCheckListItem } from './render-elem';
|
|
3
3
|
var CheckListPlugin = {
|
|
4
4
|
editorPlugin: withCheckList,
|
|
5
|
-
renderElements: [
|
|
5
|
+
renderElements: [renderCheckListItem]
|
|
6
6
|
};
|
|
7
7
|
export default CheckListPlugin;
|
|
@@ -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,
|
|
@@ -5,14 +5,6 @@ import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { Transforms } from '@seafile/slate';
|
|
7
7
|
import { ReactEditor } from '@seafile/slate-react';
|
|
8
|
-
var renderCheckList = function renderCheckList(props, editor) {
|
|
9
|
-
var attributes = props.attributes,
|
|
10
|
-
children = props.children,
|
|
11
|
-
style = props.style;
|
|
12
|
-
return /*#__PURE__*/React.createElement("p", Object.assign({}, attributes, {
|
|
13
|
-
style: style
|
|
14
|
-
}), children);
|
|
15
|
-
};
|
|
16
8
|
var CheckListItem = /*#__PURE__*/function (_React$PureComponent) {
|
|
17
9
|
_inherits(CheckListItem, _React$PureComponent);
|
|
18
10
|
var _super = _createSuper(CheckListItem);
|
|
@@ -70,4 +62,8 @@ var CheckListItem = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
70
62
|
}]);
|
|
71
63
|
return CheckListItem;
|
|
72
64
|
}(React.PureComponent);
|
|
73
|
-
export
|
|
65
|
+
export var renderCheckListItem = function renderCheckListItem(props, editor) {
|
|
66
|
+
return /*#__PURE__*/React.createElement(CheckListItem, Object.assign({}, props, {
|
|
67
|
+
editor: editor
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
@@ -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);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CODE_BLOCK } from '../../constants';
|
|
2
2
|
import CodeBlockMenu from './menu';
|
|
3
3
|
import withCodeBlock from './plugin';
|
|
4
|
-
import { renderCodeBlock } from './render-elem';
|
|
4
|
+
import { renderCodeBlock, renderCodeLine } from './render-elem';
|
|
5
5
|
var CodeBlockPlugin = {
|
|
6
6
|
type: CODE_BLOCK,
|
|
7
7
|
nodeType: 'element',
|
|
8
8
|
editorMenus: [CodeBlockMenu],
|
|
9
9
|
editorPlugin: withCodeBlock,
|
|
10
|
-
renderElements: [renderCodeBlock]
|
|
10
|
+
renderElements: [renderCodeBlock, renderCodeLine]
|
|
11
11
|
};
|
|
12
12
|
export default CodeBlockPlugin;
|
|
@@ -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,
|
|
@@ -97,14 +97,22 @@ var withCodeBlock = function withCodeBlock(editor) {
|
|
|
97
97
|
node = _ref2[0],
|
|
98
98
|
path = _ref2[1];
|
|
99
99
|
var type = getNodeType(node);
|
|
100
|
-
if (type ===
|
|
100
|
+
if (type === CODE_LINE && path.length <= 1) {
|
|
101
101
|
Transforms.setNodes(newEditor, {
|
|
102
102
|
type: 'paragraph'
|
|
103
103
|
}, {
|
|
104
104
|
at: path
|
|
105
105
|
});
|
|
106
|
+
return;
|
|
106
107
|
}
|
|
107
108
|
if (type === CODE_BLOCK) {
|
|
109
|
+
if (node.children.length === 0) {
|
|
110
|
+
Transforms.delete(newEditor, {
|
|
111
|
+
at: path
|
|
112
|
+
});
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
// code-block is the last node in the editor and needs to be followed by a p node
|
|
109
117
|
var isLast = isLastNode(newEditor, node);
|
|
110
118
|
if (isLast) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
|
4
|
-
import { ReactEditor,
|
|
4
|
+
import { ReactEditor, useReadOnly } from '@seafile/slate-react';
|
|
5
5
|
import { Transforms } from '@seafile/slate';
|
|
6
6
|
import EventBus from '../../../utils/event-bus';
|
|
7
7
|
import { useScrollContext } from '../../../hooks/use-scroll-context';
|
|
@@ -10,14 +10,13 @@ import { setClipboardData } from './helpers';
|
|
|
10
10
|
import { INTERNAL_EVENT } from '../../../constants';
|
|
11
11
|
import '../../../assets/css/code-block.css';
|
|
12
12
|
var CodeBlock = function CodeBlock(_ref) {
|
|
13
|
-
var
|
|
13
|
+
var attributes = _ref.attributes,
|
|
14
|
+
children = _ref.children,
|
|
15
|
+
element = _ref.element,
|
|
16
|
+
editor = _ref.editor;
|
|
14
17
|
var readOnly = useReadOnly();
|
|
15
|
-
var editor = useSlateStatic();
|
|
16
18
|
var codeBlockRef = useRef();
|
|
17
19
|
var scrollRef = useScrollContext();
|
|
18
|
-
var attributes = codeBlockProps.attributes,
|
|
19
|
-
children = codeBlockProps.children,
|
|
20
|
-
element = codeBlockProps.element;
|
|
21
20
|
var _element$style = element.style,
|
|
22
21
|
style = _element$style === void 0 ? {
|
|
23
22
|
white_space: 'nowrap'
|
|
@@ -126,6 +125,7 @@ var CodeBlock = function CodeBlock(_ref) {
|
|
|
126
125
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
127
126
|
}, []);
|
|
128
127
|
return /*#__PURE__*/React.createElement("div", {
|
|
128
|
+
"data-id": element.id,
|
|
129
129
|
ref: codeBlockRef,
|
|
130
130
|
className: 'sdoc-code-block-container',
|
|
131
131
|
onClick: onFocusCodeBlock,
|
|
@@ -147,8 +147,17 @@ var CodeBlock = function CodeBlock(_ref) {
|
|
|
147
147
|
}));
|
|
148
148
|
};
|
|
149
149
|
export var renderCodeBlock = function renderCodeBlock(props, editor) {
|
|
150
|
-
return /*#__PURE__*/React.createElement(CodeBlock, {
|
|
151
|
-
codeBlockProps: _objectSpread({}, props),
|
|
150
|
+
return /*#__PURE__*/React.createElement(CodeBlock, Object.assign({}, props, {
|
|
152
151
|
editor: editor
|
|
153
|
-
});
|
|
152
|
+
}));
|
|
153
|
+
};
|
|
154
|
+
export var renderCodeLine = function renderCodeLine(props, editor) {
|
|
155
|
+
var element = props.element,
|
|
156
|
+
attributes = props.attributes,
|
|
157
|
+
children = props.children;
|
|
158
|
+
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
159
|
+
"data-id": element.id
|
|
160
|
+
}, attributes, {
|
|
161
|
+
className: 'sdoc-code-line'
|
|
162
|
+
}), children);
|
|
154
163
|
};
|
|
@@ -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) {
|
|
@@ -132,9 +133,10 @@ export var loadFont = function loadFont() {
|
|
|
132
133
|
};
|
|
133
134
|
export var generatorFontFamily = function generatorFontFamily(fontName, fontWeight, leaf) {
|
|
134
135
|
var isCodeBlock = leaf && Object.keys(leaf).includes('token');
|
|
136
|
+
if (isCodeBlock) return {};
|
|
135
137
|
var lang = context.getSetting('lang') || 'zh-cn';
|
|
136
138
|
if (fontName === DEFAULT_FONT) {
|
|
137
|
-
return "
|
|
139
|
+
return "'Arial', ".concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", 'sans-serif'");
|
|
138
140
|
}
|
|
139
141
|
var fontObject = FONT.find(function (item) {
|
|
140
142
|
return item.name === fontName;
|
|
@@ -143,5 +145,5 @@ export var generatorFontFamily = function generatorFontFamily(fontName, fontWeig
|
|
|
143
145
|
fontFamilyName = fontObject.fontFamilyName;
|
|
144
146
|
loadFont(fontObject, fontWeight);
|
|
145
147
|
var validFontName = fontFamilyName && isMac() ? fontFamilyName['mac'] : fontName;
|
|
146
|
-
return "".concat(
|
|
148
|
+
return "".concat(validFontName, ", ").concat(lang === 'zh-cn' ? "\u5B8B\u4F53" : 'Arial', ", ").concat(usuallyFontFamilyName || 'sans-serif');
|
|
147
149
|
};
|
|
@@ -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) {
|