@seafile/sdoc-editor 0.1.125-beta → 0.1.126
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/constants/index.js +2 -1
- package/dist/basic-sdk/editor.js +173 -25
- package/dist/basic-sdk/extension/constants/index.js +71 -0
- package/dist/basic-sdk/extension/index.js +2 -2
- package/dist/basic-sdk/extension/plugins/blockquote/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +5 -7
- package/dist/basic-sdk/extension/plugins/blockquote/render-elem.js +2 -1
- package/dist/basic-sdk/extension/plugins/check-list/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/check-list/menu/index.js +5 -7
- package/dist/basic-sdk/extension/plugins/check-list/render-elem.js +2 -1
- package/dist/basic-sdk/extension/plugins/clear-format/helpers.js +0 -2
- package/dist/basic-sdk/extension/plugins/clear-format/menu/index.js +2 -3
- package/dist/basic-sdk/extension/plugins/code-block/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/code-block/menu/index.js +4 -7
- package/dist/basic-sdk/extension/plugins/code-block/render-elem.js +1 -0
- package/dist/basic-sdk/extension/plugins/font/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/font/menu/font-family/index.js +2 -3
- package/dist/basic-sdk/extension/plugins/font/menu/font-size/index.js +2 -3
- package/dist/basic-sdk/extension/plugins/font/menu/index.js +3 -6
- package/dist/basic-sdk/extension/plugins/header/helpers.js +0 -2
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +2 -4
- package/dist/basic-sdk/extension/plugins/header/render-elem.js +2 -2
- package/dist/basic-sdk/extension/plugins/image/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/image/menu/index.js +6 -8
- package/dist/basic-sdk/extension/plugins/link/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/link/menu/add-link-dialog.js +7 -2
- package/dist/basic-sdk/extension/plugins/link/menu/index.js +6 -8
- package/dist/basic-sdk/extension/plugins/list/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/list/menu/index.js +9 -11
- package/dist/basic-sdk/extension/plugins/list/render-elem.js +3 -1
- package/dist/basic-sdk/extension/plugins/paragraph/render-elem.js +2 -1
- package/dist/basic-sdk/extension/plugins/sdoc-link/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/sdoc-link/menu/index.js +3 -4
- package/dist/basic-sdk/extension/plugins/sdoc-link/render-elem.js +0 -1
- package/dist/basic-sdk/extension/plugins/table/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/cell-text-align-menu.js +3 -6
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +2 -3
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +6 -12
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/remove-table-menu.js +3 -5
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/table-column-menu.js +4 -8
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/table-row-menu.js +4 -8
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +5 -7
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.js +11 -4
- package/dist/basic-sdk/extension/plugins/table/render/table-root.js +1 -0
- package/dist/basic-sdk/extension/plugins/text-align/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/text-align/menu/index.js +2 -3
- package/dist/basic-sdk/extension/plugins/text-style/helpers.js +1 -2
- package/dist/basic-sdk/extension/plugins/text-style/menu/index.js +4 -5
- package/dist/basic-sdk/extension/render/render-element.js +17 -2
- package/dist/basic-sdk/extension/toolbar/header-toolbar/index.js +17 -37
- package/dist/basic-sdk/extension/toolbar/header-toolbar/redo-undo.js +4 -7
- package/dist/basic-sdk/extension/toolbar/index.js +2 -1
- package/dist/basic-sdk/extension/toolbar/side-toolbar/helpers.js +121 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.css +24 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/index.js +123 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-below-menu.js +23 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/insert-block-menu.js +95 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu-item.js +35 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.css +64 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/side-menu.js +76 -0
- package/dist/basic-sdk/extension/toolbar/side-toolbar/transform-menus.js +41 -0
- package/dist/basic-sdk/layout/article-container.js +3 -2
- package/dist/basic-sdk/outline/index.js +1 -0
- package/dist/basic-sdk/outline/style.css +1 -5
- package/dist/basic-sdk/socket/socket-client.js +1 -1
- package/dist/basic-sdk/socket/socket-manager.js +0 -4
- package/dist/basic-sdk/socket/with-socket-io.js +0 -1
- package/dist/basic-sdk/utils/diff.js +0 -12
- package/dist/basic-sdk/views/diff-viewer.js +5 -10
- package/dist/basic-sdk/views/viewer.js +20 -20
- package/dist/components/doc-operations/index.js +0 -2
- package/dist/components/doc-operations/revision-operations/index.js +1 -5
- package/dist/pages/diff-viewer/history-version-viewer.js +15 -0
- package/dist/pages/diff-viewer/index.js +35 -0
- package/dist/pages/simple-editor.js +3 -16
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +7 -1
- package/public/locales/zh-CN/sdoc-editor.json +8 -1
- package/public/media/sdoc-editor-font/iconfont.eot +0 -0
- package/public/media/sdoc-editor-font/iconfont.svg +0 -4
- 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 +6 -14
- package/dist/basic-sdk/layout/editor-container.js +0 -26
- package/dist/basic-sdk/layout/editor-content.js +0 -56
- package/dist/basic-sdk/layout/index.js +0 -4
- package/dist/basic-sdk/slate-editor.js +0 -149
- package/dist/components/doc-operations/revision-operations/changes-count/index.css +0 -34
- package/dist/components/doc-operations/revision-operations/changes-count/index.js +0 -85
- package/dist/pages/diff-viewer.js +0 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export var INTERNAL_EVENT = {
|
|
2
2
|
CANCEL_TABLE_SELECT_RANGE: 'cancel_table_select_range',
|
|
3
3
|
SET_TABLE_SELECT_RANGE: 'set_table_select_range',
|
|
4
|
-
HIDDEN_CODE_BLOCK_HOVER_MENU: 'hidden_code_block_hover_menu'
|
|
4
|
+
HIDDEN_CODE_BLOCK_HOVER_MENU: 'hidden_code_block_hover_menu',
|
|
5
|
+
ON_MOUSE_ENTER_BLOCK: 'on_mouse_enter_block'
|
|
5
6
|
};
|
|
6
7
|
export var PAGE_EDIT_AREA_WIDTH = 672; // 672 = 794 - 2[borderLeft + borderRight] - 120[paddingLeft + paddingRight]
|
package/dist/basic-sdk/editor.js
CHANGED
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
-
import React, { useEffect, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState, forwardRef, useImperativeHandle, Fragment } from 'react';
|
|
3
3
|
import { Editor } from '@seafile/slate';
|
|
4
|
-
import {
|
|
5
|
-
import defaultEditor from './extension';
|
|
6
|
-
import { focusEditor } from './extension/core';
|
|
4
|
+
import { Editable, ReactEditor, Slate } from '@seafile/slate-react';
|
|
5
|
+
import defaultEditor, { renderLeaf, renderElement, Toolbar, ContextToolbar } from './extension';
|
|
6
|
+
import { focusEditor, getAboveBlockNode, getNextNode, getPrevNode, isSelectionAtBlockEnd, isSelectionAtBlockStart } from './extension/core';
|
|
7
7
|
import { withSocketIO } from './socket';
|
|
8
8
|
import withNodeId from './node-id';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
9
|
+
import SDocOutline from './outline';
|
|
10
|
+
import EventProxy from './utils/event-handler';
|
|
11
|
+
import { useCursors } from './cursor/use-cursors';
|
|
12
|
+
import { INTERNAL_EVENT, PAGE_EDIT_AREA_WIDTH } from './constants';
|
|
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';
|
|
13
26
|
var SDocEditor = forwardRef(function (_ref, ref) {
|
|
14
27
|
var document = _ref.document,
|
|
15
28
|
config = _ref.config;
|
|
16
|
-
var _useTranslation = useTranslation(),
|
|
17
|
-
t = _useTranslation.t;
|
|
18
|
-
|
|
19
29
|
// init editor
|
|
20
30
|
var editor = useMemo(function () {
|
|
21
31
|
var newEditor = withNodeId(withSocketIO(defaultEditor, {
|
|
@@ -32,6 +42,16 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
32
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
33
43
|
slateValue = _useState2[0],
|
|
34
44
|
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
|
+
}, []);
|
|
35
55
|
|
|
36
56
|
// The parent component can call the method of this component through ref
|
|
37
57
|
useImperativeHandle(ref, function () {
|
|
@@ -75,26 +95,154 @@ var SDocEditor = forwardRef(function (_ref, ref) {
|
|
|
75
95
|
};
|
|
76
96
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
97
|
}, []);
|
|
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;
|
|
78
149
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
150
|
+
// above viewport
|
|
151
|
+
if (_y2 < 0) {
|
|
152
|
+
var newY = Math.abs(_y2);
|
|
153
|
+
if (isSelectionAtBlockStart(editor)) {
|
|
154
|
+
var _prevNode = getPrevNode(editor);
|
|
155
|
+
if (!_prevNode) return;
|
|
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
|
+
}
|
|
85
197
|
}
|
|
86
198
|
|
|
87
199
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
200
|
}, []);
|
|
89
|
-
|
|
201
|
+
var _useState3 = useState(0),
|
|
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
|
+
console.log(editor.children);
|
|
210
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
211
|
+
className: "sdoc-editor-container"
|
|
212
|
+
}, /*#__PURE__*/React.createElement(ColorProvider, null, /*#__PURE__*/React.createElement(Toolbar, {
|
|
90
213
|
editor: editor
|
|
91
|
-
}, /*#__PURE__*/React.createElement(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
214
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
215
|
+
className: "sdoc-editor-content"
|
|
216
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
217
|
+
className: "sdoc-absolute-wrapper"
|
|
218
|
+
}, /*#__PURE__*/React.createElement(SDocOutline, {
|
|
219
|
+
scrollLeft: scrollLeft,
|
|
220
|
+
doc: slateValue,
|
|
221
|
+
docUuid: config.docUuid
|
|
222
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
223
|
+
className: "sdoc-absolute-wrapper"
|
|
224
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
225
|
+
ref: scrollRef,
|
|
226
|
+
className: "sdoc-scroll-container",
|
|
227
|
+
onScroll: onWrapperScroll
|
|
228
|
+
}, /*#__PURE__*/React.createElement(ScrollContext.Provider, {
|
|
229
|
+
value: {
|
|
230
|
+
scrollRef: scrollRef
|
|
231
|
+
}
|
|
232
|
+
}, /*#__PURE__*/React.createElement(Slate, {
|
|
95
233
|
editor: editor,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
234
|
+
value: slateValue,
|
|
235
|
+
onChange: onChange
|
|
236
|
+
}, /*#__PURE__*/React.createElement(ArticleContainer, {
|
|
237
|
+
editor: editor
|
|
238
|
+
}, /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(ContextToolbar, null), /*#__PURE__*/React.createElement(SetNodeToDecorations, null), /*#__PURE__*/React.createElement(Editable, {
|
|
239
|
+
cursors: cursors,
|
|
240
|
+
renderElement: renderElement,
|
|
241
|
+
renderLeaf: renderLeaf,
|
|
242
|
+
onKeyDown: onKeyDown,
|
|
243
|
+
onMouseDown: onMouseDown,
|
|
244
|
+
decorate: decorate,
|
|
245
|
+
onCut: eventProxy.onCut
|
|
246
|
+
})), /*#__PURE__*/React.createElement(SideToolbar, null), /*#__PURE__*/React.createElement(CommentContextProvider, null, /*#__PURE__*/React.createElement(CommentWrapper, null)))))))))));
|
|
99
247
|
});
|
|
100
248
|
export default SDocEditor;
|
|
@@ -161,4 +161,75 @@ export var LIST_TYPE_ARRAY = ['unordered_list', 'ordered_list'];
|
|
|
161
161
|
export var TRANSPARENT = 'transparent';
|
|
162
162
|
export var CLIPBOARD_FORMAT_KEY = 'x-slate-fragment';
|
|
163
163
|
export var INSERT_FILE_DISPLAY_TYPE = ['text_link', 'icon_link', 'card_link'];
|
|
164
|
+
export var SIDE_MENUS_CONFIG = [{
|
|
165
|
+
id: PARAGRAPH,
|
|
166
|
+
iconClass: 'sdocfont sdoc-text',
|
|
167
|
+
type: PARAGRAPH,
|
|
168
|
+
title: 'Paragraph'
|
|
169
|
+
}, {
|
|
170
|
+
id: HEADER1,
|
|
171
|
+
iconClass: 'sdocfont sdoc-header1',
|
|
172
|
+
type: HEADER1,
|
|
173
|
+
title: 'Header_one'
|
|
174
|
+
}, {
|
|
175
|
+
id: HEADER2,
|
|
176
|
+
iconClass: 'sdocfont sdoc-header2',
|
|
177
|
+
type: HEADER2,
|
|
178
|
+
title: 'Header_two'
|
|
179
|
+
}, {
|
|
180
|
+
id: HEADER3,
|
|
181
|
+
iconClass: 'sdocfont sdoc-header3',
|
|
182
|
+
type: HEADER3,
|
|
183
|
+
title: 'Header_three'
|
|
184
|
+
}, {
|
|
185
|
+
id: HEADER4,
|
|
186
|
+
iconClass: 'sdocfont sdoc-header4',
|
|
187
|
+
type: HEADER4,
|
|
188
|
+
title: 'Header_four'
|
|
189
|
+
}, {
|
|
190
|
+
id: HEADER5,
|
|
191
|
+
iconClass: 'sdocfont sdoc-header5',
|
|
192
|
+
type: HEADER5,
|
|
193
|
+
title: 'Header_five'
|
|
194
|
+
}, {
|
|
195
|
+
id: HEADER6,
|
|
196
|
+
iconClass: 'sdocfont sdoc-header6',
|
|
197
|
+
type: HEADER6,
|
|
198
|
+
title: 'Header_six'
|
|
199
|
+
}, {
|
|
200
|
+
id: UNORDERED_LIST,
|
|
201
|
+
iconClass: 'sdocfont sdoc-list-ul',
|
|
202
|
+
type: UNORDERED_LIST,
|
|
203
|
+
title: 'Unordered_list'
|
|
204
|
+
}, {
|
|
205
|
+
id: ORDERED_LIST,
|
|
206
|
+
iconClass: 'sdocfont sdoc-list-ol',
|
|
207
|
+
type: ORDERED_LIST,
|
|
208
|
+
title: 'Ordered_list'
|
|
209
|
+
}, {
|
|
210
|
+
id: CHECK_LIST_ITEM,
|
|
211
|
+
iconClass: 'sdocfont sdoc-check-square',
|
|
212
|
+
type: CHECK_LIST_ITEM,
|
|
213
|
+
title: 'Check_list_item'
|
|
214
|
+
}, {
|
|
215
|
+
id: ALIGN_LEFT,
|
|
216
|
+
iconClass: 'sdocfont sdoc-align-left',
|
|
217
|
+
type: 'left',
|
|
218
|
+
title: 'Left'
|
|
219
|
+
}, {
|
|
220
|
+
id: ALIGN_CENTER,
|
|
221
|
+
iconClass: 'sdocfont sdoc-align-center',
|
|
222
|
+
type: 'center',
|
|
223
|
+
title: 'Center'
|
|
224
|
+
}, {
|
|
225
|
+
id: ALIGN_RIGHT,
|
|
226
|
+
iconClass: 'sdocfont sdoc-align-right',
|
|
227
|
+
type: 'right',
|
|
228
|
+
title: 'Right'
|
|
229
|
+
}, {
|
|
230
|
+
id: BLOCKQUOTE,
|
|
231
|
+
iconClass: 'sdocfont sdoc-quote1',
|
|
232
|
+
type: BLOCKQUOTE,
|
|
233
|
+
title: 'Quote'
|
|
234
|
+
}];
|
|
164
235
|
export { BLOCKQUOTE, HEADER, HEADER1, HEADER2, HEADER3, HEADER4, HEADER5, HEADER6, PARAGRAPH, BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SUPERSCRIPT, SUBSCRIPT, ORDERED_LIST, UNORDERED_LIST, LIST_ITEM, LIST_LIC, CHECK_LIST, CHECK_LIST_ITEM, LINK, HTML, CODE_BLOCK, CODE_LINE, IMAGE, TABLE, TABLE_CELL, TABLE_ROW, FORMULA, COLUMN, TEXT_STYLE, TEXT_STYLE_MORE, BOLD_ITALIC, TEXT_ALIGN, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, ELEMENT_TYPE, KEYBOARD, DEFAULT_COLORS, STANDARD_COLORS, DEFAULT_RECENT_USED_LIST, CLEAR_FORMAT, DEFAULT_FONT_COLOR, RECENT_USED_HIGHLIGHT_COLORS_KEY, RECENT_USED_FONT_COLORS_KEY, RECENT_USED_TABLE_CELL_BG_COLORS_KEY, DEFAULT_LAST_USED_FONT_COLOR, DEFAULT_LAST_USED_HIGHLIGHT_COLOR, DEFAULT_LAST_USED_TABLE_CELL_BG_COLOR, SPECIAL_FONT_SIZE_NAME, DEFAULT_COMMON_FONT_SIZE, FONT_SIZE, DEFAULT_FONT, FONT, GOOGLE_FONT_CLASS, RECENT_USED_FONTS_KEY, HEADER_FONT_SIZE, SDOC_LINK };
|
|
@@ -4,7 +4,7 @@ import { withHistory } from '@seafile/slate-history';
|
|
|
4
4
|
import Plugins from './plugins';
|
|
5
5
|
import renderElement from './render/render-element';
|
|
6
6
|
import renderLeaf from './render/render-leaf';
|
|
7
|
-
import { Toolbar, ContextToolbar } from './toolbar';
|
|
7
|
+
import { Toolbar, ContextToolbar, SideToolbar } from './toolbar';
|
|
8
8
|
var baseEditor = withHistory(withReact(createEditor()));
|
|
9
9
|
var defaultEditor = Plugins === null || Plugins === void 0 ? void 0 : Plugins.reduce(function (editor, pluginItem) {
|
|
10
10
|
var withPlugin = pluginItem.editorPlugin;
|
|
@@ -14,4 +14,4 @@ var defaultEditor = Plugins === null || Plugins === void 0 ? void 0 : Plugins.re
|
|
|
14
14
|
return editor;
|
|
15
15
|
}, baseEditor);
|
|
16
16
|
export default defaultEditor;
|
|
17
|
-
export { renderLeaf, renderElement, Toolbar, ContextToolbar };
|
|
17
|
+
export { renderLeaf, renderElement, Toolbar, ContextToolbar, SideToolbar };
|
|
@@ -3,8 +3,7 @@ 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
|
|
7
|
-
if (readonly) return true;
|
|
6
|
+
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
8
7
|
if (editor.selection == null) return true;
|
|
9
8
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
10
9
|
match: function match(n) {
|
|
@@ -22,10 +22,8 @@ var QuoteMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
22
22
|
return getBlockQuoteType(editor) === BLOCKQUOTE;
|
|
23
23
|
};
|
|
24
24
|
_this.isDisabled = function () {
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
readonly = _this$props.readonly;
|
|
28
|
-
return isMenuDisabled(editor, readonly);
|
|
25
|
+
var editor = _this.props.editor;
|
|
26
|
+
return isMenuDisabled(editor);
|
|
29
27
|
};
|
|
30
28
|
_this.onMouseDown = function (e) {
|
|
31
29
|
var editor = _this.props.editor;
|
|
@@ -37,9 +35,9 @@ var QuoteMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
37
35
|
_createClass(QuoteMenu, [{
|
|
38
36
|
key: "render",
|
|
39
37
|
value: function render() {
|
|
40
|
-
var _this$
|
|
41
|
-
isRichEditor = _this$
|
|
42
|
-
className = _this$
|
|
38
|
+
var _this$props = this.props,
|
|
39
|
+
isRichEditor = _this$props.isRichEditor,
|
|
40
|
+
className = _this$props.className;
|
|
43
41
|
var menuConfig = MENUS_CONFIG_MAP[BLOCKQUOTE];
|
|
44
42
|
var props = _objectSpread(_objectSpread({
|
|
45
43
|
isRichEditor: isRichEditor,
|
|
@@ -7,7 +7,8 @@ var renderBlockquote = function renderBlockquote(props, editor) {
|
|
|
7
7
|
textAlign: element.align
|
|
8
8
|
};
|
|
9
9
|
return /*#__PURE__*/React.createElement("blockquote", Object.assign({
|
|
10
|
-
"data-id": element.id
|
|
10
|
+
"data-id": element.id,
|
|
11
|
+
"data-root": "true"
|
|
11
12
|
}, attributes, {
|
|
12
13
|
style: style
|
|
13
14
|
}), children);
|
|
@@ -3,8 +3,7 @@ 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
|
|
7
|
-
if (readonly) return true;
|
|
6
|
+
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
8
7
|
if (editor.selection == null) return true;
|
|
9
8
|
var selectedElements = [];
|
|
10
9
|
var nodeEntries = Editor.nodes(editor, {
|
|
@@ -22,10 +22,8 @@ var CheckListMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
22
22
|
return getCheckListItemType(editor) === CHECK_LIST_ITEM;
|
|
23
23
|
};
|
|
24
24
|
_this.isDisabled = function () {
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
readonly = _this$props.readonly;
|
|
28
|
-
return isMenuDisabled(editor, readonly);
|
|
25
|
+
var editor = _this.props.editor;
|
|
26
|
+
return isMenuDisabled(editor);
|
|
29
27
|
};
|
|
30
28
|
_this.onMouseDown = function () {
|
|
31
29
|
var editor = _this.props.editor;
|
|
@@ -38,9 +36,9 @@ var CheckListMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
38
36
|
_createClass(CheckListMenu, [{
|
|
39
37
|
key: "render",
|
|
40
38
|
value: function render() {
|
|
41
|
-
var _this$
|
|
42
|
-
isRichEditor = _this$
|
|
43
|
-
className = _this$
|
|
39
|
+
var _this$props = this.props,
|
|
40
|
+
isRichEditor = _this$props.isRichEditor,
|
|
41
|
+
className = _this$props.className;
|
|
44
42
|
var menuConfig = MENUS_CONFIG_MAP[CHECK_LIST];
|
|
45
43
|
var props = _objectSpread(_objectSpread({
|
|
46
44
|
isRichEditor: isRichEditor,
|
|
@@ -45,7 +45,8 @@ var CheckListItem = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
45
45
|
textAlign: align
|
|
46
46
|
};
|
|
47
47
|
return /*#__PURE__*/React.createElement("div", Object.assign({
|
|
48
|
-
"data-id": id
|
|
48
|
+
"data-id": id,
|
|
49
|
+
"data-root": "true"
|
|
49
50
|
}, attributes, {
|
|
50
51
|
style: style
|
|
51
52
|
}), /*#__PURE__*/React.createElement("span", {
|
|
@@ -4,8 +4,6 @@ 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;
|
|
9
7
|
if (editor.selection == null) return true;
|
|
10
8
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
11
9
|
match: function match(n) {
|
|
@@ -7,8 +7,7 @@ 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
|
|
11
|
-
readonly = _ref.readonly;
|
|
10
|
+
editor = _ref.editor;
|
|
12
11
|
var onMouseDown = useCallback(function () {
|
|
13
12
|
clearStyles(editor);
|
|
14
13
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -17,7 +16,7 @@ var ClearFormatMenu = function ClearFormatMenu(_ref) {
|
|
|
17
16
|
isRichEditor: isRichEditor,
|
|
18
17
|
className: className
|
|
19
18
|
}, menuConfig), {}, {
|
|
20
|
-
disabled: isMenuDisabled(editor
|
|
19
|
+
disabled: isMenuDisabled(editor),
|
|
21
20
|
isActive: false,
|
|
22
21
|
'onMouseDown': onMouseDown
|
|
23
22
|
});
|
|
@@ -5,8 +5,7 @@ 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
|
|
9
|
-
if (readonly) return true;
|
|
8
|
+
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
10
9
|
var selection = editor.selection;
|
|
11
10
|
if (selection == null) return true;
|
|
12
11
|
var selectedElems = getSelectedElems(editor);
|
|
@@ -24,10 +24,7 @@ var CodeBlockMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
24
24
|
return !!elem;
|
|
25
25
|
};
|
|
26
26
|
_this.isDisabled = function () {
|
|
27
|
-
|
|
28
|
-
editor = _this$props.editor,
|
|
29
|
-
readonly = _this$props.readonly;
|
|
30
|
-
return isMenuDisabled(editor, readonly);
|
|
27
|
+
return isMenuDisabled(_this.props.editor);
|
|
31
28
|
};
|
|
32
29
|
_this.onMouseDown = function (e) {
|
|
33
30
|
e.preventDefault();
|
|
@@ -48,9 +45,9 @@ var CodeBlockMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
48
45
|
_createClass(CodeBlockMenu, [{
|
|
49
46
|
key: "render",
|
|
50
47
|
value: function render() {
|
|
51
|
-
var _this$
|
|
52
|
-
isRichEditor = _this$
|
|
53
|
-
className = _this$
|
|
48
|
+
var _this$props = this.props,
|
|
49
|
+
isRichEditor = _this$props.isRichEditor,
|
|
50
|
+
className = _this$props.className;
|
|
54
51
|
var menuConfig = MENUS_CONFIG_MAP[CODE_BLOCK];
|
|
55
52
|
var props = _objectSpread(_objectSpread({
|
|
56
53
|
isRichEditor: isRichEditor,
|
|
@@ -126,6 +126,7 @@ var CodeBlock = function CodeBlock(_ref) {
|
|
|
126
126
|
}, []);
|
|
127
127
|
return /*#__PURE__*/React.createElement("div", {
|
|
128
128
|
"data-id": element.id,
|
|
129
|
+
"data-root": "true",
|
|
129
130
|
ref: codeBlockRef,
|
|
130
131
|
className: 'sdoc-code-block-container',
|
|
131
132
|
onClick: onFocusCodeBlock,
|
|
@@ -4,8 +4,7 @@ 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
|
|
8
|
-
if (readonly) return true;
|
|
7
|
+
export var isMenuDisabled = function isMenuDisabled(editor) {
|
|
9
8
|
if (!editor.selection) return true;
|
|
10
9
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
11
10
|
match: function match(node) {
|
|
@@ -15,8 +15,7 @@ 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
|
|
19
|
-
readonly = _ref.readonly;
|
|
18
|
+
className = _ref.className;
|
|
20
19
|
var _useState = useState(LocalStorage.getItem(RECENT_USED_FONTS_KEY, [])),
|
|
21
20
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
21
|
recentUsedFonts = _useState2[0],
|
|
@@ -32,7 +31,7 @@ var FontFamily = function FontFamily(_ref) {
|
|
|
32
31
|
var _useTranslation = useTranslation(),
|
|
33
32
|
t = _useTranslation.t;
|
|
34
33
|
var popoverRef = useRef(null);
|
|
35
|
-
var disabled = isMenuDisabled(editor
|
|
34
|
+
var disabled = isMenuDisabled(editor);
|
|
36
35
|
var fontSizeButtonId = 'sdoc-button-font';
|
|
37
36
|
var selectedFont = getFont(editor);
|
|
38
37
|
var lang = context.getSetting('lang');
|
|
@@ -13,8 +13,7 @@ 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
|
|
17
|
-
readonly = _ref.readonly;
|
|
16
|
+
editor = _ref.editor;
|
|
18
17
|
var _useState = useState(false),
|
|
19
18
|
_useState2 = _slicedToArray(_useState, 2),
|
|
20
19
|
isShowMenu = _useState2[0],
|
|
@@ -22,7 +21,7 @@ var FontSize = function FontSize(_ref) {
|
|
|
22
21
|
var _useTranslation = useTranslation(),
|
|
23
22
|
t = _useTranslation.t;
|
|
24
23
|
var popoverRef = useRef(null);
|
|
25
|
-
var disabled = isMenuDisabled(editor
|
|
24
|
+
var disabled = isMenuDisabled(editor);
|
|
26
25
|
var fontSizeButtonId = 'sdoc-button-font-size';
|
|
27
26
|
var selectedFontSize = getFontSize(editor);
|
|
28
27
|
var selectedFontSizeValue = selectedFontSize;
|
|
@@ -2,14 +2,11 @@ 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
|
|
6
|
-
readonly = _ref.readonly;
|
|
5
|
+
var editor = _ref.editor;
|
|
7
6
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(FontFamily, {
|
|
8
|
-
editor: editor
|
|
9
|
-
readonly: readonly
|
|
7
|
+
editor: editor
|
|
10
8
|
}), /*#__PURE__*/React.createElement(FontSize, {
|
|
11
|
-
editor: editor
|
|
12
|
-
readonly: readonly
|
|
9
|
+
editor: editor
|
|
13
10
|
}));
|
|
14
11
|
};
|
|
15
12
|
export default Font;
|
|
@@ -3,8 +3,6 @@ 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;
|
|
8
6
|
if (!editor.selection) return true;
|
|
9
7
|
var _Editor$nodes = Editor.nodes(editor, {
|
|
10
8
|
match: function match(n) {
|
|
@@ -41,10 +41,8 @@ var HeaderMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
41
41
|
return _this.getValue() === type;
|
|
42
42
|
};
|
|
43
43
|
_this.isDisabled = function () {
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
readonly = _this$props.readonly;
|
|
47
|
-
return isMenuDisabled(editor, readonly);
|
|
44
|
+
var editor = _this.props.editor;
|
|
45
|
+
return isMenuDisabled(editor);
|
|
48
46
|
};
|
|
49
47
|
_this.onToggleClick = function (event) {
|
|
50
48
|
event.stopPropagation();
|
|
@@ -19,8 +19,8 @@ var renderHeader = function renderHeader(props, editor) {
|
|
|
19
19
|
isShowPlaceHolder = true;
|
|
20
20
|
}
|
|
21
21
|
return /*#__PURE__*/React.createElement(Tag, Object.assign({
|
|
22
|
-
id: element.id,
|
|
23
|
-
"data-
|
|
22
|
+
"data-id": element.id,
|
|
23
|
+
"data-root": "true"
|
|
24
24
|
}, attributes, {
|
|
25
25
|
style: _objectSpread({
|
|
26
26
|
position: isShowPlaceHolder ? 'relative' : ''
|
|
@@ -5,8 +5,7 @@ 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
|
|
9
|
-
if (readonly) return true;
|
|
8
|
+
export var isInsertImageMenuDisabled = function isInsertImageMenuDisabled(editor) {
|
|
10
9
|
var selection = editor.selection;
|
|
11
10
|
if (selection === null) return true;
|
|
12
11
|
if (!Range.isCollapsed(selection)) return true;
|
|
@@ -35,10 +35,8 @@ var ImageMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
35
35
|
return false;
|
|
36
36
|
};
|
|
37
37
|
_this.isDisabled = function () {
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
readonly = _this$props.readonly;
|
|
41
|
-
return isInsertImageMenuDisabled(editor, readonly);
|
|
38
|
+
var editor = _this.props.editor;
|
|
39
|
+
return isInsertImageMenuDisabled(editor);
|
|
42
40
|
};
|
|
43
41
|
_this.onToggleClick = function (event) {
|
|
44
42
|
event.stopPropagation();
|
|
@@ -107,10 +105,10 @@ var ImageMenu = /*#__PURE__*/function (_React$Component) {
|
|
|
107
105
|
_createClass(ImageMenu, [{
|
|
108
106
|
key: "render",
|
|
109
107
|
value: function render() {
|
|
110
|
-
var _this$
|
|
111
|
-
isRichEditor = _this$
|
|
112
|
-
className = _this$
|
|
113
|
-
t = _this$
|
|
108
|
+
var _this$props = this.props,
|
|
109
|
+
isRichEditor = _this$props.isRichEditor,
|
|
110
|
+
className = _this$props.className,
|
|
111
|
+
t = _this$props.t;
|
|
114
112
|
var _this$state = this.state,
|
|
115
113
|
isShowImagePopover = _this$state.isShowImagePopover,
|
|
116
114
|
isShowInsertImageDialog = _this$state.isShowInsertImageDialog;
|