@seafile/seafile-editor 0.3.76
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/README.md +119 -0
- package/TODO.md +55 -0
- package/dist/components/add-formula-dialog.js +135 -0
- package/dist/components/add-image-dialog.js +78 -0
- package/dist/components/add-link-dialog.js +148 -0
- package/dist/components/comment-dialog.js +107 -0
- package/dist/components/comment-panel.js +452 -0
- package/dist/components/context-menu.js +112 -0
- package/dist/components/detail-list-view.js +119 -0
- package/dist/components/generate-share-link.js +412 -0
- package/dist/components/internal-link-dialog.js +96 -0
- package/dist/components/loading.js +32 -0
- package/dist/components/markdown-lint.js +87 -0
- package/dist/components/modal-portal.js +46 -0
- package/dist/components/outline.js +130 -0
- package/dist/components/participants-list.js +126 -0
- package/dist/components/related-files-list.js +75 -0
- package/dist/components/shortcut-dialog.js +167 -0
- package/dist/components/side-panel.js +175 -0
- package/dist/components/toast/alert.js +150 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/toast.js +179 -0
- package/dist/components/toast/toastManager.js +158 -0
- package/dist/components/toast/toaster.js +76 -0
- package/dist/components/toolbar.js +235 -0
- package/dist/components/topbar-component/button-group.js +31 -0
- package/dist/components/topbar-component/editor-toolbar.js +545 -0
- package/dist/components/topbar-component/file-info.js +65 -0
- package/dist/components/topbar-component/header-list.js +128 -0
- package/dist/components/topbar-component/icon-button.js +99 -0
- package/dist/components/topbar-component/insert-file.js +67 -0
- package/dist/components/topbar-component/table-toolbar.js +175 -0
- package/dist/components/topbar-component/upload-img.js +122 -0
- package/dist/components/user-help.js +205 -0
- package/dist/css/diff-viewer.css +105 -0
- package/dist/css/history-viewer.css +104 -0
- package/dist/css/keyboard-shortcuts.css +59 -0
- package/dist/css/layout.css +110 -0
- package/dist/css/markdown-viewer-slate/file-tags-list.css +76 -0
- package/dist/css/markdown-viewer.css +69 -0
- package/dist/css/plaineditor/markdown-editor.css +12 -0
- package/dist/css/react-mentions-default-style.js +72 -0
- package/dist/css/related-files-list.css +56 -0
- package/dist/css/richeditor/comments-list.css +184 -0
- package/dist/css/richeditor/detail-list-view.css +114 -0
- package/dist/css/richeditor/document-info.css +57 -0
- package/dist/css/richeditor/formula.css +19 -0
- package/dist/css/richeditor/image.css +141 -0
- package/dist/css/richeditor/link.css +7 -0
- package/dist/css/richeditor/navbar-imgbutton.css +79 -0
- package/dist/css/richeditor/participants-list.css +22 -0
- package/dist/css/richeditor/rich-editor-main.css +42 -0
- package/dist/css/richeditor/right-panel.css +84 -0
- package/dist/css/richeditor/side-panel.css +190 -0
- package/dist/css/richeditor/table.css +57 -0
- package/dist/css/richeditor/textlink-hovermenu.css +47 -0
- package/dist/css/richeditor/tree-view.css +67 -0
- package/dist/css/topbar.css +400 -0
- package/dist/editor/code-highlight-package.js +27 -0
- package/dist/editor/controller/block-element-controller.js +376 -0
- package/dist/editor/controller/inline-element-controller.js +129 -0
- package/dist/editor/controller/normalize-controller.js +107 -0
- package/dist/editor/controller/shortcut-controller.js +394 -0
- package/dist/editor/controller/void-element-controller.js +12 -0
- package/dist/editor/custom/custom.js +17 -0
- package/dist/editor/custom/get-event-transfer.js +34 -0
- package/dist/editor/custom/getNodesByTypeAtRange.js +69 -0
- package/dist/editor/custom/insertNodes.js +140 -0
- package/dist/editor/custom/is-empty-paragraph.js +13 -0
- package/dist/editor/custom/set-event-transfer.js +31 -0
- package/dist/editor/custom/split-nodes-at-point.js +162 -0
- package/dist/editor/custom/unwrap-node-by-type-at-range.js +81 -0
- package/dist/editor/editor-component/check-list-item.js +64 -0
- package/dist/editor/editor-component/code-block.js +150 -0
- package/dist/editor/editor-component/formula.js +79 -0
- package/dist/editor/editor-component/image.js +215 -0
- package/dist/editor/editor-component/link.js +11 -0
- package/dist/editor/editor-component/table.js +172 -0
- package/dist/editor/editor-component/textlink-hovermenu.js +136 -0
- package/dist/editor/editor-plugin.js +249 -0
- package/dist/editor/editor-utils/block-element-utils/blockquote-utils.js +96 -0
- package/dist/editor/editor-utils/block-element-utils/code-utils.js +162 -0
- package/dist/editor/editor-utils/block-element-utils/formula-utils.js +58 -0
- package/dist/editor/editor-utils/block-element-utils/index.js +38 -0
- package/dist/editor/editor-utils/block-element-utils/list-utils.js +398 -0
- package/dist/editor/editor-utils/block-element-utils/table-utils.js +418 -0
- package/dist/editor/editor-utils/common-editor-utils.js +587 -0
- package/dist/editor/editor-utils/inline-element-utils/index.js +95 -0
- package/dist/editor/editor-utils/mark-utils.js +25 -0
- package/dist/editor/editor-utils/range-utils.js +9 -0
- package/dist/editor/editor-utils/selection-utils.js +33 -0
- package/dist/editor/editor-utils/text-utils.js +130 -0
- package/dist/editor/editor.js +66 -0
- package/dist/editor/element-model/blockquote.js +16 -0
- package/dist/editor/element-model/image.js +19 -0
- package/dist/editor/element-model/link.js +19 -0
- package/dist/editor/element-model/table.js +50 -0
- package/dist/editor/element-model/text.js +13 -0
- package/dist/editor/load-script.js +83 -0
- package/dist/editor/plain-markdown-editor.js +324 -0
- package/dist/editor/rich-markdown-editor.js +580 -0
- package/dist/editor/seafile-editor.js +326 -0
- package/dist/editor/simple-editor.js +245 -0
- package/dist/editor-api.js +261 -0
- package/dist/index.css +97 -0
- package/dist/lib/slate-hyperscript/creators.js +263 -0
- package/dist/lib/slate-hyperscript/hyperscript.js +92 -0
- package/dist/lib/slate-hyperscript/index.js +3 -0
- package/dist/lib/slate-hyperscript/tokens.js +102 -0
- package/dist/lib/unified/index.js +470 -0
- package/dist/lib/vfile/core.js +172 -0
- package/dist/lib/vfile/index.js +48 -0
- package/dist/seafile-editor-chooser.js +45 -0
- package/dist/seafile-markdown-editor.js +301 -0
- package/dist/seafile-markdown-viewer.js +79 -0
- package/dist/seafile-simple-editor.js +56 -0
- package/dist/utils/copy-to-clipboard.js +47 -0
- package/dist/utils/deserialize-html.js +282 -0
- package/dist/utils/diff/compare-strings.js +46 -0
- package/dist/utils/diff/diff.js +855 -0
- package/dist/utils/diff/index.js +2 -0
- package/dist/utils/render-slate.js +219 -0
- package/dist/utils/seafile-markdown2html.js +62 -0
- package/dist/utils/slate2markdown/deserialize.js +689 -0
- package/dist/utils/slate2markdown/index.js +3 -0
- package/dist/utils/slate2markdown/serialize.js +407 -0
- package/dist/utils/utils.js +28 -0
- package/dist/viewer/diff-viewer.js +98 -0
- package/dist/viewer/markdown-viewer.js +139 -0
- package/dist/viewer/slate-viewer.js +73 -0
- package/dist/viewer/viewer-formula.js +67 -0
- package/dist/viewer/viewer-image.js +93 -0
- package/dist/viewer/viewer-outline.js +118 -0
- package/package.json +215 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +45 -0
- package/public/locales/cs/seafile-editor.json +169 -0
- package/public/locales/de/seafile-editor.json +169 -0
- package/public/locales/en/seafile-editor.json +222 -0
- package/public/locales/es/seafile-editor.json +169 -0
- package/public/locales/es-AR/seafile-editor.json +169 -0
- package/public/locales/es-MX/seafile-editor.json +169 -0
- package/public/locales/fr/seafile-editor.json +169 -0
- package/public/locales/it/seafile-editor.json +169 -0
- package/public/locales/ru/seafile-editor.json +169 -0
- package/public/locales/zh-CN/seafile-editor.json +219 -0
- package/public/manifest.json +15 -0
- package/public/media/scripts/mathjax/tex-svg.js +1 -0
- package/public/media/seafile-editor-font/iconfont.eot +0 -0
- package/public/media/seafile-editor-font/iconfont.svg +164 -0
- package/public/media/seafile-editor-font/iconfont.ttf +0 -0
- package/public/media/seafile-editor-font/iconfont.woff +0 -0
- package/public/media/seafile-editor-font/iconfont.woff2 +0 -0
- package/public/media/seafile-editor-font.css +201 -0
- package/public/media/seafile-logo.png +0 -0
- package/public/media/seafile-ui.css +11169 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { Editor, Node, Range, Path } from 'slate';
|
|
4
|
+
import ListUtils from '../editor-utils/block-element-utils/list-utils';
|
|
5
|
+
import { isRangeCollapsed } from '../editor-utils/range-utils';
|
|
6
|
+
import { SfEditor } from '../custom/custom';
|
|
7
|
+
import CodeUtils from '../editor-utils/block-element-utils/code-utils';
|
|
8
|
+
import TextUtils from '../editor-utils/text-utils';
|
|
9
|
+
import TableUtils from '../editor-utils/block-element-utils/table-utils';
|
|
10
|
+
import BlockquoteUtils from '../editor-utils/block-element-utils/blockquote-utils';
|
|
11
|
+
var SHORTCUTS = {
|
|
12
|
+
'1.': 'ordered_list',
|
|
13
|
+
'*': 'unordered_list',
|
|
14
|
+
'-': 'unordered_list',
|
|
15
|
+
'>': 'blockquote',
|
|
16
|
+
'#': 'header_one',
|
|
17
|
+
'##': 'header_two',
|
|
18
|
+
'###': 'header_three',
|
|
19
|
+
'####': 'header_four',
|
|
20
|
+
'#####': 'header_five',
|
|
21
|
+
'######': 'header_six',
|
|
22
|
+
' ': 'code_block'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var withMarkdownShortcut = function withMarkdownShortcut(editor) {
|
|
26
|
+
var exec = editor.exec;
|
|
27
|
+
var listUtils = new ListUtils(editor);
|
|
28
|
+
var codeUtils = new CodeUtils(editor);
|
|
29
|
+
var tableUtils = new TableUtils(editor);
|
|
30
|
+
var textUtils = new TextUtils(editor);
|
|
31
|
+
var blockquoteUtils = new BlockquoteUtils(editor);
|
|
32
|
+
|
|
33
|
+
editor.exec = function (command) {
|
|
34
|
+
var selection = editor.selection;
|
|
35
|
+
|
|
36
|
+
switch (command.type) {
|
|
37
|
+
case 'split_list_item':
|
|
38
|
+
Editor.splitNodes(editor, {
|
|
39
|
+
match: 'block',
|
|
40
|
+
always: true
|
|
41
|
+
});
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case 'insert_break':
|
|
45
|
+
if (!Range.isCollapsed(editor.selection)) {
|
|
46
|
+
var _node = Editor.node(editor, [editor.selection.anchor.path[0]]);
|
|
47
|
+
|
|
48
|
+
if (_node && _node[0].type.includes('header')) {
|
|
49
|
+
exec(command);
|
|
50
|
+
Editor.setNodes(editor, {
|
|
51
|
+
type: 'paragraph'
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
} // if the expand selection is in table delete the selected and insert a new row when press enter
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if (tableUtils.isInTable()) {
|
|
58
|
+
Editor.collapse(editor, {
|
|
59
|
+
edge: 'end'
|
|
60
|
+
});
|
|
61
|
+
tableUtils.insertRow();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exec(command);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
70
|
+
match: {
|
|
71
|
+
type: 'link'
|
|
72
|
+
}
|
|
73
|
+
}),
|
|
74
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
75
|
+
link = _Editor$nodes2[0]; // when selection is at the end of link, select the text node after the link
|
|
76
|
+
// to prevent split a empty link node
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if (link) {
|
|
80
|
+
var linkPath = link[1];
|
|
81
|
+
|
|
82
|
+
if (Editor.isEnd(editor, editor.selection.anchor, linkPath)) {
|
|
83
|
+
var nextPath = Path.next(linkPath);
|
|
84
|
+
var point = {
|
|
85
|
+
path: nextPath,
|
|
86
|
+
offset: 0
|
|
87
|
+
};
|
|
88
|
+
Editor.select(editor, point);
|
|
89
|
+
}
|
|
90
|
+
} // When a picture is selected, a blank line is inserted when press Enter
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
var _Editor$nodes3 = Editor.nodes(editor, {
|
|
94
|
+
match: {
|
|
95
|
+
type: 'image'
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
_Editor$nodes4 = _slicedToArray(_Editor$nodes3, 1),
|
|
99
|
+
image = _Editor$nodes4[0];
|
|
100
|
+
|
|
101
|
+
if (image) {
|
|
102
|
+
var imagePath = image[1].slice();
|
|
103
|
+
var imageIndex = imagePath.pop(); // insert new table row when selection is in table
|
|
104
|
+
|
|
105
|
+
Editor.insertNodes(editor, {
|
|
106
|
+
text: ''
|
|
107
|
+
}, {
|
|
108
|
+
at: [].concat(_toConsumableArray(imagePath), [imageIndex + 1])
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (tableUtils.isInTable()) {
|
|
112
|
+
tableUtils.insertRow();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exec(command);
|
|
117
|
+
return;
|
|
118
|
+
} // unwrap blockquote when press enter at an empty blockquote line;
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if (blockquoteUtils.isInBlockquote()) {
|
|
122
|
+
var _Editor$nodes5 = Editor.nodes(editor, {
|
|
123
|
+
match: 'block'
|
|
124
|
+
}),
|
|
125
|
+
_Editor$nodes6 = _slicedToArray(_Editor$nodes5, 1),
|
|
126
|
+
block = _Editor$nodes6[0];
|
|
127
|
+
|
|
128
|
+
if (Node.text(block[0]).length === 0) {
|
|
129
|
+
Editor.unwrapNodes(editor, {
|
|
130
|
+
match: {
|
|
131
|
+
type: 'blockquote'
|
|
132
|
+
},
|
|
133
|
+
split: true
|
|
134
|
+
});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
} // if press enter in a list unwrap the list or insert a new list item
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if (listUtils.isInlist()) {
|
|
141
|
+
var _node2 = SfEditor.getNodesByTypeAtRange(editor, 'list_item'); // unwrap list if the list item text is none
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
if (Node.text(_node2[0]).length === 0) {
|
|
145
|
+
listUtils.unwrapList();
|
|
146
|
+
return;
|
|
147
|
+
} // insert a new list item
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
if (isRangeCollapsed(editor.selection)) {
|
|
151
|
+
SfEditor.splitNodesAtPoint(editor, {
|
|
152
|
+
at: editor.selection.anchor,
|
|
153
|
+
match: {
|
|
154
|
+
type: 'list_item'
|
|
155
|
+
},
|
|
156
|
+
always: true
|
|
157
|
+
});
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (codeUtils.isInCodeBlock()) {
|
|
163
|
+
codeUtils.splitCodeLine();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (tableUtils.isInTable()) {
|
|
168
|
+
tableUtils.insertRow();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var node = Editor.node(editor, [editor.selection.anchor.path[0]]);
|
|
173
|
+
|
|
174
|
+
if (node && node[0].type.includes('header')) {
|
|
175
|
+
var header = node[0]; // get the offset of the selection
|
|
176
|
+
|
|
177
|
+
var offset = editor.selection.anchor.offset; // split the header
|
|
178
|
+
|
|
179
|
+
exec(command); // if the selection is at the end of the header
|
|
180
|
+
// set the splited header sibling to paragraph
|
|
181
|
+
|
|
182
|
+
if (offset === Node.text(header).length) {
|
|
183
|
+
Editor.setNodes(editor, {
|
|
184
|
+
type: 'paragraph'
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
exec(command);
|
|
192
|
+
break;
|
|
193
|
+
|
|
194
|
+
case 'insert_text':
|
|
195
|
+
// set element by markdown shortcut;
|
|
196
|
+
if (command.text === ' ' && isRangeCollapsed(selection)) {
|
|
197
|
+
// if current selection is in table or code block exec default command
|
|
198
|
+
if (tableUtils.isInTable() || codeUtils.isInCodeBlock()) {
|
|
199
|
+
exec(command);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
var _textUtils$getTextInf = textUtils.getTextInfoBeforeSelection(),
|
|
204
|
+
beforeText = _textUtils$getTextInf.beforeText,
|
|
205
|
+
range = _textUtils$getTextInf.range,
|
|
206
|
+
_block = _textUtils$getTextInf.block;
|
|
207
|
+
|
|
208
|
+
var path = _block[1];
|
|
209
|
+
var type = SHORTCUTS[beforeText]; // set block element by shortcut
|
|
210
|
+
|
|
211
|
+
if (type) {
|
|
212
|
+
Editor.select(editor, range);
|
|
213
|
+
Editor.delete(editor);
|
|
214
|
+
|
|
215
|
+
if (type === 'blockquote') {
|
|
216
|
+
if (!blockquoteUtils.isInBlockquote()) {
|
|
217
|
+
editor.exec({
|
|
218
|
+
type: 'set_blockquote'
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (type.includes('header')) {
|
|
224
|
+
// set the outest paragraph into header
|
|
225
|
+
if (_block[0].type === 'paragraph' && path.length === 1) {
|
|
226
|
+
editor.exec({
|
|
227
|
+
type: 'set_header',
|
|
228
|
+
headerType: type
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (type === 'ordered_list') {
|
|
234
|
+
editor.exec({
|
|
235
|
+
type: 'set_ordered_list'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (type === 'unordered_list') {
|
|
240
|
+
editor.exec({
|
|
241
|
+
type: 'set_unordered_list'
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (type === 'code_block') {
|
|
246
|
+
if (!codeUtils.isInCodeBlock()) {
|
|
247
|
+
editor.exec({
|
|
248
|
+
type: 'set_code_block'
|
|
249
|
+
});
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return;
|
|
255
|
+
} else {
|
|
256
|
+
// set text mark by shortcut
|
|
257
|
+
textUtils.setTextMarkByShortCut(exec, command);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (command.text === '`' && isRangeCollapsed(editor.selection)) {
|
|
263
|
+
var _textUtils$getTextInf2 = textUtils.getTextInfoBeforeSelection(),
|
|
264
|
+
_beforeText = _textUtils$getTextInf2.beforeText,
|
|
265
|
+
_range = _textUtils$getTextInf2.range;
|
|
266
|
+
|
|
267
|
+
if (_beforeText === '``' && !codeUtils.isInCodeBlock()) {
|
|
268
|
+
Editor.select(editor, _range);
|
|
269
|
+
Editor.delete(editor);
|
|
270
|
+
editor.exec({
|
|
271
|
+
type: 'set_code_block'
|
|
272
|
+
});
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
exec(command);
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
case 'increase_list_item_depth':
|
|
281
|
+
listUtils.increaseListDepth();
|
|
282
|
+
break;
|
|
283
|
+
|
|
284
|
+
case 'delete_backward':
|
|
285
|
+
var anchor = selection.anchor;
|
|
286
|
+
|
|
287
|
+
if (anchor.offset === 0 && isRangeCollapsed(selection)) {
|
|
288
|
+
var _Editor$nodes7 = Editor.nodes(editor, {
|
|
289
|
+
match: 'block'
|
|
290
|
+
}),
|
|
291
|
+
_Editor$nodes8 = _slicedToArray(_Editor$nodes7, 1),
|
|
292
|
+
match = _Editor$nodes8[0];
|
|
293
|
+
|
|
294
|
+
var _block2 = match[0]; // set header to paragraph when delete at the start of header
|
|
295
|
+
|
|
296
|
+
if (_block2.type.includes('header')) {
|
|
297
|
+
editor.exec({
|
|
298
|
+
type: 'set_header',
|
|
299
|
+
headerType: 'paragraph'
|
|
300
|
+
});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* If the anchor offset is 0 but not focus the head of the block node such as
|
|
305
|
+
* an image is selected, the editor shoud delete the image first instead of
|
|
306
|
+
* execute the delete operation of list or code_block or table
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
if (_block2.children.length > 1) {
|
|
311
|
+
var blockDepth = match[1].length - 1;
|
|
312
|
+
var inlineIndex = anchor.path[blockDepth + 1]; // If the inline node is the first child of the block, execute default command
|
|
313
|
+
|
|
314
|
+
if (inlineIndex !== 0) {
|
|
315
|
+
exec(command);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (blockquoteUtils.isInBlockquote()) {
|
|
321
|
+
editor.exec({
|
|
322
|
+
type: 'unwrap_blockquote'
|
|
323
|
+
});
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (listUtils.isInlist()) {
|
|
328
|
+
var _Editor$nodes9 = Editor.nodes(editor, {
|
|
329
|
+
match: [{
|
|
330
|
+
type: 'ordered_list'
|
|
331
|
+
}, {
|
|
332
|
+
type: 'unordered_list'
|
|
333
|
+
}]
|
|
334
|
+
}),
|
|
335
|
+
_Editor$nodes10 = _slicedToArray(_Editor$nodes9, 1),
|
|
336
|
+
_node3 = _Editor$nodes10[0];
|
|
337
|
+
|
|
338
|
+
var listNode = _node3[0];
|
|
339
|
+
|
|
340
|
+
if (listNode.children.length === 1 && Node.text(listNode).length === 0) {
|
|
341
|
+
listUtils.unwrapList();
|
|
342
|
+
return;
|
|
343
|
+
} // Unwrap the list item when the selection is at the first list item of the first node of document
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
if (anchor.path[0] === 0 && anchor.path[1] === 0) {
|
|
347
|
+
listUtils.unwrapList();
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (codeUtils.isInCodeBlock()) {
|
|
353
|
+
var _node4 = Editor.match(editor, editor.selection, {
|
|
354
|
+
type: 'code_block'
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
var codeBlock = _node4[0];
|
|
358
|
+
var children = codeBlock.children;
|
|
359
|
+
var text = Node.text(codeBlock);
|
|
360
|
+
|
|
361
|
+
if (text.length === 0 && children.length === 1) {
|
|
362
|
+
editor.exec({
|
|
363
|
+
type: 'unwrap_code_block'
|
|
364
|
+
});
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (tableUtils.isInTable()) {
|
|
370
|
+
var _block3 = Editor.match(editor, editor.selection, 'block');
|
|
371
|
+
|
|
372
|
+
var blockPath = _block3[1];
|
|
373
|
+
var blockNode = _block3[0];
|
|
374
|
+
var start = Editor.start(editor, blockPath);
|
|
375
|
+
var _offset = start.offset;
|
|
376
|
+
|
|
377
|
+
if (_offset === 0 && blockNode.children.length === 1) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
exec(command);
|
|
384
|
+
break;
|
|
385
|
+
|
|
386
|
+
default:
|
|
387
|
+
exec(command);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
return editor;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
export default withMarkdownShortcut;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var withVoid = function withVoid(editor) {
|
|
2
|
+
var isVoid = editor.isVoid;
|
|
3
|
+
var VOID_ELEMENTS = ['image', 'formula'];
|
|
4
|
+
|
|
5
|
+
editor.isVoid = function (element) {
|
|
6
|
+
return VOID_ELEMENTS.includes(element.type) ? true : isVoid(element);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
return editor;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default withVoid;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { Editor } from 'slate';
|
|
3
|
+
import splitNodesAtPoint from './split-nodes-at-point';
|
|
4
|
+
import unwrapNodesByTypeAtRange from './unwrap-node-by-type-at-range';
|
|
5
|
+
import getNodesByTypeAtRange from './getNodesByTypeAtRange';
|
|
6
|
+
import { insertNodes } from './insertNodes';
|
|
7
|
+
import isEmptyParagraph from './is-empty-paragraph'; //due to some of the function of slate is not perfect now, add some custom fucntion to Editor and exported as SfEditor
|
|
8
|
+
|
|
9
|
+
var SfEditor = _objectSpread(_objectSpread({}, Editor), {}, {
|
|
10
|
+
splitNodesAtPoint: splitNodesAtPoint,
|
|
11
|
+
getNodesByTypeAtRange: getNodesByTypeAtRange,
|
|
12
|
+
unwrapNodesByTypeAtRange: unwrapNodesByTypeAtRange,
|
|
13
|
+
insertNodes: insertNodes,
|
|
14
|
+
isEmptyParagraph: isEmptyParagraph
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { SfEditor };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var getEventTransfer = function getEventTransfer(data) {
|
|
2
|
+
var fragmentString = data.getData('application/x-slate-fragment');
|
|
3
|
+
var textContent = data.getData('text') || data.getData('text/plain') || '';
|
|
4
|
+
var fragmentContent = fragmentString ? JSON.parse(decodeURIComponent(window.atob(fragmentString))) : null;
|
|
5
|
+
var htmlContent = data.getData('text/html') || '';
|
|
6
|
+
var hasRtfContent = data.types.includes('text/rtf');
|
|
7
|
+
/**
|
|
8
|
+
* compat old version slate: if clipboard content is old version slate fragment
|
|
9
|
+
* return html content
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var files = data.files;
|
|
13
|
+
var type = 'text'; // Paste rtf format content which copied from PPT or Word or Excel as text to document
|
|
14
|
+
|
|
15
|
+
if (hasRtfContent) {
|
|
16
|
+
type = 'text';
|
|
17
|
+
} else if (files.length > 0) {
|
|
18
|
+
type = 'file';
|
|
19
|
+
} else if (fragmentContent && Array.isArray(fragmentContent)) {
|
|
20
|
+
type = 'fragment';
|
|
21
|
+
} else if (htmlContent) {
|
|
22
|
+
type = 'html';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
text: textContent,
|
|
27
|
+
html: htmlContent,
|
|
28
|
+
fragment: fragmentContent,
|
|
29
|
+
type: type,
|
|
30
|
+
files: files
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default getEventTransfer;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { Editor, Range } from 'slate'; // modified on the basic of the slate function Editor.nodes
|
|
4
|
+
// todo: get the node which nearest to the selection
|
|
5
|
+
|
|
6
|
+
var getNodesByTypeAtRange = function getNodesByTypeAtRange(editor, type) {
|
|
7
|
+
var match = {};
|
|
8
|
+
|
|
9
|
+
if (Array.isArray(type)) {
|
|
10
|
+
match.match = type;
|
|
11
|
+
} else {
|
|
12
|
+
match.match = {
|
|
13
|
+
type: type
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var nodes = Editor.nodes(editor, match);
|
|
18
|
+
|
|
19
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
20
|
+
match: 'block'
|
|
21
|
+
}),
|
|
22
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
23
|
+
blockNode = _Editor$nodes2[0];
|
|
24
|
+
|
|
25
|
+
var listItemDepth = blockNode[1].length - 1;
|
|
26
|
+
|
|
27
|
+
if (Range.isCollapsed(editor.selection)) {
|
|
28
|
+
var node;
|
|
29
|
+
|
|
30
|
+
var _iterator = _createForOfIteratorHelper(nodes),
|
|
31
|
+
_step;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
35
|
+
var item = _step.value;
|
|
36
|
+
node = item;
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
_iterator.e(err);
|
|
40
|
+
} finally {
|
|
41
|
+
_iterator.f();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return node;
|
|
45
|
+
} else {
|
|
46
|
+
var itemsWithSameAncesstor = [];
|
|
47
|
+
|
|
48
|
+
var _iterator2 = _createForOfIteratorHelper(nodes),
|
|
49
|
+
_step2;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
53
|
+
var _node = _step2.value;
|
|
54
|
+
|
|
55
|
+
if (listItemDepth === _node[1].length) {
|
|
56
|
+
itemsWithSameAncesstor.push(_node);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
} catch (err) {
|
|
60
|
+
_iterator2.e(err);
|
|
61
|
+
} finally {
|
|
62
|
+
_iterator2.f();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return itemsWithSameAncesstor;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default getNodesByTypeAtRange;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { Editor, Range, Path, Node, Point, Text } from 'slate'; // modifyed function from slate
|
|
4
|
+
// The goal of the modification: focus the selection to the end of the last inserted node
|
|
5
|
+
|
|
6
|
+
export var insertNodes = function insertNodes(editor, nodes) {
|
|
7
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
8
|
+
Editor.withoutNormalizing(editor, function () {
|
|
9
|
+
// eslint-disable-next-line no-unused-vars
|
|
10
|
+
var selection = editor.selection;
|
|
11
|
+
var _options$hanging = options.hanging,
|
|
12
|
+
hanging = _options$hanging === void 0 ? false : _options$hanging,
|
|
13
|
+
_options$voids = options.voids,
|
|
14
|
+
voids = _options$voids === void 0 ? false : _options$voids;
|
|
15
|
+
var at = options.at,
|
|
16
|
+
match = options.match,
|
|
17
|
+
select = options.select;
|
|
18
|
+
|
|
19
|
+
if (Node.isNode(nodes)) {
|
|
20
|
+
nodes = [nodes];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (nodes.length === 0) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var _nodes = nodes,
|
|
28
|
+
_nodes2 = _slicedToArray(_nodes, 1),
|
|
29
|
+
node = _nodes2[0]; // By default, use the selection as the target location. But if there is
|
|
30
|
+
// no selection, insert at the end of the document since that is such a
|
|
31
|
+
// common use case when inserting from a non-selected state.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if (!at) {
|
|
35
|
+
if (editor.selection) {
|
|
36
|
+
at = editor.selection;
|
|
37
|
+
} else if (editor.children.length > 0) {
|
|
38
|
+
at = Editor.end(editor, []);
|
|
39
|
+
} else {
|
|
40
|
+
at = [0];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
select = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (select == null) {
|
|
47
|
+
select = false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (Range.isRange(at)) {
|
|
51
|
+
if (!hanging) {
|
|
52
|
+
at = Editor.unhangRange(editor, at);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (Range.isCollapsed(at)) {
|
|
56
|
+
at = at.anchor;
|
|
57
|
+
} else {
|
|
58
|
+
var _Range$edges = Range.edges(at),
|
|
59
|
+
_Range$edges2 = _slicedToArray(_Range$edges, 2),
|
|
60
|
+
end = _Range$edges2[1];
|
|
61
|
+
|
|
62
|
+
var pointRef = Editor.pointRef(editor, end);
|
|
63
|
+
Editor.delete(editor, {
|
|
64
|
+
at: at
|
|
65
|
+
});
|
|
66
|
+
at = pointRef.unref();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (Point.isPoint(at)) {
|
|
71
|
+
if (match == null) {
|
|
72
|
+
if (Text.isText(node)) {
|
|
73
|
+
match = 'text';
|
|
74
|
+
} else if (editor.isInline(node)) {
|
|
75
|
+
match = ['inline', 'text'];
|
|
76
|
+
} else {
|
|
77
|
+
match = 'block';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var atMatch = Editor.match(editor, at.path, match);
|
|
82
|
+
|
|
83
|
+
if (atMatch) {
|
|
84
|
+
var _atMatch = _slicedToArray(atMatch, 2),
|
|
85
|
+
matchPath = _atMatch[1];
|
|
86
|
+
|
|
87
|
+
var pathRef = Editor.pathRef(editor, matchPath);
|
|
88
|
+
var isAtEnd = Editor.isEnd(editor, at, matchPath);
|
|
89
|
+
Editor.splitNodes(editor, {
|
|
90
|
+
at: at,
|
|
91
|
+
match: match
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
var _path = pathRef.unref();
|
|
95
|
+
|
|
96
|
+
at = isAtEnd ? Path.next(_path) : _path;
|
|
97
|
+
} else {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var parentPath = Path.parent(at);
|
|
103
|
+
var index = at[at.length - 1];
|
|
104
|
+
|
|
105
|
+
if (!voids && Editor.match(editor, parentPath, 'void')) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var path = [];
|
|
110
|
+
|
|
111
|
+
var _iterator = _createForOfIteratorHelper(nodes),
|
|
112
|
+
_step;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
116
|
+
var _node = _step.value;
|
|
117
|
+
path = parentPath.concat(index);
|
|
118
|
+
index++;
|
|
119
|
+
at = path;
|
|
120
|
+
editor.apply({
|
|
121
|
+
type: 'insert_node',
|
|
122
|
+
path: path,
|
|
123
|
+
node: _node
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
_iterator.e(err);
|
|
128
|
+
} finally {
|
|
129
|
+
_iterator.f();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (select) {
|
|
133
|
+
var point = Editor.end(editor, at);
|
|
134
|
+
|
|
135
|
+
if (point) {
|
|
136
|
+
Editor.select(editor, point);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Node, Text } from 'slate';
|
|
2
|
+
|
|
3
|
+
var isEmptyParagraph = function isEmptyParagraph(node) {
|
|
4
|
+
if (node.type !== 'paragraph') return false;
|
|
5
|
+
|
|
6
|
+
if (node.children.length === 1 && Text.isText(node.children[0]) && Node.text(node).length === 0) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default isEmptyParagraph;
|