@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,376 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
+
import { Editor } from 'slate';
|
|
5
|
+
import ListUtils from '../editor-utils/block-element-utils/list-utils';
|
|
6
|
+
import CodeUtils from '../editor-utils/block-element-utils/code-utils';
|
|
7
|
+
import { isRangeCollapsed } from '../editor-utils/range-utils';
|
|
8
|
+
import TableUtils from '../editor-utils/block-element-utils/table-utils';
|
|
9
|
+
import getEventTransfer from '../custom/get-event-transfer';
|
|
10
|
+
import BlockquoteUtils from '../editor-utils/block-element-utils/blockquote-utils';
|
|
11
|
+
import FormulaUtils from '../editor-utils/block-element-utils/formula-utils';
|
|
12
|
+
import { htmlDeserializer } from '../../utils/deserialize-html';
|
|
13
|
+
import generateLinkElement from '../element-model/link';
|
|
14
|
+
import generateImageElement from '../element-model/image';
|
|
15
|
+
import isUrl from 'is-url';
|
|
16
|
+
import { SfEditor } from '../custom/custom';
|
|
17
|
+
|
|
18
|
+
var withBlock = function withBlock(editor) {
|
|
19
|
+
var exec = editor.exec;
|
|
20
|
+
var listUtils = new ListUtils(editor);
|
|
21
|
+
var codeUtils = new CodeUtils(editor);
|
|
22
|
+
var tableUtils = new TableUtils(editor);
|
|
23
|
+
var blockquoteUtils = new BlockquoteUtils(editor);
|
|
24
|
+
var formulaUtils = new FormulaUtils(editor);
|
|
25
|
+
|
|
26
|
+
editor.exec = function (command) {
|
|
27
|
+
var data = command.data;
|
|
28
|
+
var selection = editor.selection;
|
|
29
|
+
|
|
30
|
+
switch (command.type) {
|
|
31
|
+
case 'set_header':
|
|
32
|
+
Editor.setNodes(editor, {
|
|
33
|
+
type: command.headerType
|
|
34
|
+
});
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
case 'insert_data':
|
|
38
|
+
var _getEventTransfer = getEventTransfer(data),
|
|
39
|
+
fragment = _getEventTransfer.fragment,
|
|
40
|
+
type = _getEventTransfer.type,
|
|
41
|
+
html = _getEventTransfer.html,
|
|
42
|
+
text = _getEventTransfer.text;
|
|
43
|
+
|
|
44
|
+
if (type === 'file') {
|
|
45
|
+
exec(command);
|
|
46
|
+
return;
|
|
47
|
+
} // insert a link if text content is a url
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if (isUrl(text) && !codeUtils.isInCodeBlock()) {
|
|
51
|
+
if (text.endsWith('png') || text.endsWith('PNG') || text.endsWith('jpg') || text.endsWith('JPG') || text.endsWith('gif') || text.endsWith('GIF')) {
|
|
52
|
+
var img = generateImageElement({
|
|
53
|
+
data: {
|
|
54
|
+
src: text
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Editor.insertNodes(editor, img);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (window.editor.editorApi.isInternalFileLink(text)) {
|
|
62
|
+
var index = text.lastIndexOf('/');
|
|
63
|
+
|
|
64
|
+
if (index > 0) {
|
|
65
|
+
var name = text.substring(index + 1);
|
|
66
|
+
var fileName = decodeURIComponent(name);
|
|
67
|
+
SfEditor.insertNodes(editor, [generateLinkElement({
|
|
68
|
+
data: {
|
|
69
|
+
href: text
|
|
70
|
+
},
|
|
71
|
+
children: [{
|
|
72
|
+
text: fileName
|
|
73
|
+
}]
|
|
74
|
+
}), {
|
|
75
|
+
text: ' '
|
|
76
|
+
}]);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (window.editor.editorApi.isInternalDirLink(text)) {
|
|
82
|
+
var _index = text.lastIndexOf('/');
|
|
83
|
+
|
|
84
|
+
if (_index > 0) {
|
|
85
|
+
var name = text.substring(_index + 1);
|
|
86
|
+
var dirName = decodeURIComponent(name);
|
|
87
|
+
SfEditor.insertNodes(editor, [generateLinkElement({
|
|
88
|
+
data: {
|
|
89
|
+
href: text
|
|
90
|
+
},
|
|
91
|
+
children: [{
|
|
92
|
+
text: dirName
|
|
93
|
+
}]
|
|
94
|
+
}), {
|
|
95
|
+
text: ' '
|
|
96
|
+
}]);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
SfEditor.insertNodes(editor, [generateLinkElement({
|
|
102
|
+
data: {
|
|
103
|
+
href: text
|
|
104
|
+
},
|
|
105
|
+
children: [{
|
|
106
|
+
text: text
|
|
107
|
+
}]
|
|
108
|
+
}), {
|
|
109
|
+
text: ' '
|
|
110
|
+
}]);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
if (tableUtils.isInTable()) {
|
|
116
|
+
tableUtils.pasteContentInTable(command);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (listUtils.isInlist()) {
|
|
121
|
+
listUtils.pasteContentInList(command);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (codeUtils.isInCodeBlock()) {
|
|
126
|
+
codeUtils.pasteContentInCodeBlock(command);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (blockquoteUtils.isInBlockquote()) {
|
|
131
|
+
blockquoteUtils.pasteContentInBlockquote(command);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
Editor.insertText(editor, text);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (type === 'fragment') {
|
|
139
|
+
var _Editor$match = Editor.match(editor, editor.selection, 'block'),
|
|
140
|
+
_Editor$match2 = _slicedToArray(_Editor$match, 2),
|
|
141
|
+
currentBlock = _Editor$match2[0],
|
|
142
|
+
path = _Editor$match2[1];
|
|
143
|
+
|
|
144
|
+
var firstFragmentNode = fragment[0]; // if first fragment node is paragraph insert the content of it into previous sibling
|
|
145
|
+
// and insert other node
|
|
146
|
+
|
|
147
|
+
if (firstFragmentNode.type === 'paragraph') {
|
|
148
|
+
Editor.insertFragment(editor, fragment);
|
|
149
|
+
return;
|
|
150
|
+
} // if current node is an empty paragraph, insert the fragment and
|
|
151
|
+
// delete the empty paragraph
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
if (SfEditor.isEmptyParagraph(currentBlock)) {
|
|
155
|
+
Editor.insertNodes(editor, fragment);
|
|
156
|
+
Editor.delete(editor, {
|
|
157
|
+
at: path
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
} // insert the fragment below the current selection node
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
Editor.insertNodes(editor, fragment);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (type === 'html') {
|
|
168
|
+
try {
|
|
169
|
+
var _fragment = htmlDeserializer(html);
|
|
170
|
+
|
|
171
|
+
Editor.insertFragment(editor, _fragment);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
var newText = text.replace(/\n|\r\n/g, ' ');
|
|
174
|
+
Editor.insertText(editor, newText);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return;
|
|
178
|
+
} // remove text line break and insert text
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
if (type === 'text') {
|
|
182
|
+
var textArray = text.split(/\r\n|\n/g);
|
|
183
|
+
textArray.forEach(function (text, index) {
|
|
184
|
+
if (index === 0) {
|
|
185
|
+
Editor.insertText(editor, text);
|
|
186
|
+
} else {
|
|
187
|
+
Editor.insertNodes(editor, {
|
|
188
|
+
type: 'paragraph',
|
|
189
|
+
children: [{
|
|
190
|
+
text: text
|
|
191
|
+
}]
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
exec(command);
|
|
199
|
+
break;
|
|
200
|
+
|
|
201
|
+
case 'set_blockquote':
|
|
202
|
+
if (!selection) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
blockquoteUtils.wrapBlockquote();
|
|
207
|
+
break;
|
|
208
|
+
|
|
209
|
+
case 'unwrap_blockquote':
|
|
210
|
+
blockquoteUtils.unwrapBlockquote();
|
|
211
|
+
break;
|
|
212
|
+
|
|
213
|
+
case 'set_ordered_list':
|
|
214
|
+
if (!selection) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
listUtils.wrapList('ordered_list');
|
|
219
|
+
break;
|
|
220
|
+
|
|
221
|
+
case 'set_unordered_list':
|
|
222
|
+
if (!selection) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
listUtils.wrapList('unordered_list');
|
|
227
|
+
break;
|
|
228
|
+
|
|
229
|
+
case 'unwrap_unordered_list':
|
|
230
|
+
case 'unwrap_ordered_list':
|
|
231
|
+
listUtils.unwrapList();
|
|
232
|
+
break;
|
|
233
|
+
|
|
234
|
+
case 'wrap_check_list_item':
|
|
235
|
+
var listItem = listUtils.getCurrentListItem();
|
|
236
|
+
|
|
237
|
+
if (listItem.length === 0) {
|
|
238
|
+
// not in list, add list
|
|
239
|
+
listUtils.wrapList('unordered_list');
|
|
240
|
+
Editor.setNodes(editor, {
|
|
241
|
+
data: {
|
|
242
|
+
checked: false
|
|
243
|
+
}
|
|
244
|
+
}, {
|
|
245
|
+
match: {
|
|
246
|
+
type: 'list_item'
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
} else {
|
|
250
|
+
var listItems = Editor.nodes(editor, {
|
|
251
|
+
at: editor.selection,
|
|
252
|
+
match: {
|
|
253
|
+
type: 'list_item'
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
var nearestItem;
|
|
257
|
+
|
|
258
|
+
var _iterator = _createForOfIteratorHelper(listItems),
|
|
259
|
+
_step;
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
263
|
+
var _listItem = _step.value;
|
|
264
|
+
nearestItem = _listItem;
|
|
265
|
+
}
|
|
266
|
+
} catch (err) {
|
|
267
|
+
_iterator.e(err);
|
|
268
|
+
} finally {
|
|
269
|
+
_iterator.f();
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
Editor.setNodes(editor, {
|
|
273
|
+
data: {
|
|
274
|
+
checked: false
|
|
275
|
+
}
|
|
276
|
+
}, {
|
|
277
|
+
at: nearestItem[1]
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
break;
|
|
282
|
+
|
|
283
|
+
case 'unwrap_check_list_item':
|
|
284
|
+
var item = listUtils.getCurrentListItem();
|
|
285
|
+
Editor.setNodes(editor, {
|
|
286
|
+
data: {}
|
|
287
|
+
}, {
|
|
288
|
+
at: item[0][1]
|
|
289
|
+
});
|
|
290
|
+
break;
|
|
291
|
+
|
|
292
|
+
case 'set_code_block':
|
|
293
|
+
codeUtils.wrapCodeBlock();
|
|
294
|
+
break;
|
|
295
|
+
|
|
296
|
+
case 'unwrap_code_block':
|
|
297
|
+
codeUtils.unwrapCodeBlock();
|
|
298
|
+
break;
|
|
299
|
+
|
|
300
|
+
case 'exit_code_block':
|
|
301
|
+
Editor.splitNodes(editor, {
|
|
302
|
+
match: 'block',
|
|
303
|
+
always: true
|
|
304
|
+
});
|
|
305
|
+
codeUtils.unwrapCodeBlock(true);
|
|
306
|
+
break;
|
|
307
|
+
|
|
308
|
+
case 'increase_code_block_indent':
|
|
309
|
+
if (isRangeCollapsed(editor.selection)) {
|
|
310
|
+
var block = Editor.match(editor, editor.selection, 'block');
|
|
311
|
+
Editor.insertText(editor, '\t', {
|
|
312
|
+
at: {
|
|
313
|
+
anchor: {
|
|
314
|
+
path: [].concat(_toConsumableArray(block[1]), [0]),
|
|
315
|
+
offset: 0
|
|
316
|
+
},
|
|
317
|
+
focus: {
|
|
318
|
+
path: [].concat(_toConsumableArray(block[1]), [0]),
|
|
319
|
+
offset: 0
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
break;
|
|
326
|
+
|
|
327
|
+
case 'insert_table':
|
|
328
|
+
tableUtils.insertTable();
|
|
329
|
+
break;
|
|
330
|
+
|
|
331
|
+
case 'remove_table':
|
|
332
|
+
tableUtils.removeTable();
|
|
333
|
+
break;
|
|
334
|
+
|
|
335
|
+
case 'insert_row':
|
|
336
|
+
tableUtils.insertRow();
|
|
337
|
+
break;
|
|
338
|
+
|
|
339
|
+
case 'insert_column':
|
|
340
|
+
tableUtils.insertColumn();
|
|
341
|
+
break;
|
|
342
|
+
|
|
343
|
+
case 'remove_row':
|
|
344
|
+
tableUtils.removeRow();
|
|
345
|
+
break;
|
|
346
|
+
|
|
347
|
+
case 'remove_column':
|
|
348
|
+
tableUtils.removeColumn();
|
|
349
|
+
break;
|
|
350
|
+
|
|
351
|
+
case 'set_table_cell_align':
|
|
352
|
+
tableUtils.setAlign(command.align);
|
|
353
|
+
break;
|
|
354
|
+
|
|
355
|
+
case 'exit_table':
|
|
356
|
+
tableUtils.exitTable();
|
|
357
|
+
break;
|
|
358
|
+
|
|
359
|
+
case 'insert_formula':
|
|
360
|
+
formulaUtils.insertFormula(command.data);
|
|
361
|
+
break;
|
|
362
|
+
|
|
363
|
+
case 'set_formula':
|
|
364
|
+
formulaUtils.setFormula(command.data);
|
|
365
|
+
break;
|
|
366
|
+
|
|
367
|
+
default:
|
|
368
|
+
exec(command);
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
return editor;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export default withBlock;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import { Editor, Range } from 'slate';
|
|
3
|
+
import generateLinkElement from '../element-model/link';
|
|
4
|
+
import generateImageElement from '../element-model/image';
|
|
5
|
+
|
|
6
|
+
var withInline = function withInline(editor) {
|
|
7
|
+
var exec = editor.exec,
|
|
8
|
+
isInline = editor.isInline;
|
|
9
|
+
|
|
10
|
+
editor.isInline = function (element) {
|
|
11
|
+
return element.type === 'link' || element.type === 'image' ? true : isInline(element);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
editor.exec = function (command) {
|
|
15
|
+
var data = command.data;
|
|
16
|
+
var selection = editor.selection;
|
|
17
|
+
|
|
18
|
+
switch (command.type) {
|
|
19
|
+
case 'insert_link_at_selection':
|
|
20
|
+
selection = command.elementData.selection;
|
|
21
|
+
var isCollapsed = selection && Range.isCollapsed(selection);
|
|
22
|
+
var link = generateLinkElement({
|
|
23
|
+
type: 'link',
|
|
24
|
+
children: [{
|
|
25
|
+
text: command.elementData.text
|
|
26
|
+
}],
|
|
27
|
+
data: {
|
|
28
|
+
href: command.elementData.url
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (isCollapsed) {
|
|
33
|
+
Editor.insertNodes(editor, link, {
|
|
34
|
+
at: selection
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
Editor.wrapNodes(editor, link, {
|
|
38
|
+
split: true,
|
|
39
|
+
at: selection
|
|
40
|
+
});
|
|
41
|
+
Editor.select(editor, selection);
|
|
42
|
+
Editor.collapse(editor, {
|
|
43
|
+
edge: 'end'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
break;
|
|
48
|
+
|
|
49
|
+
case 'unwrap_link':
|
|
50
|
+
Editor.unwrapNodes(editor, {
|
|
51
|
+
match: {
|
|
52
|
+
type: 'link'
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
|
|
57
|
+
case 'set_link':
|
|
58
|
+
selection = command.elementData.selection;
|
|
59
|
+
Editor.removeNodes(editor, {
|
|
60
|
+
match: {
|
|
61
|
+
type: 'link'
|
|
62
|
+
},
|
|
63
|
+
at: selection
|
|
64
|
+
});
|
|
65
|
+
var newNodeLink = generateLinkElement({
|
|
66
|
+
type: 'link',
|
|
67
|
+
data: {
|
|
68
|
+
href: command.elementData.url
|
|
69
|
+
},
|
|
70
|
+
children: [{
|
|
71
|
+
text: command.elementData.text
|
|
72
|
+
}]
|
|
73
|
+
}); // Insert a new link at previous link path
|
|
74
|
+
|
|
75
|
+
var linkPath = _toConsumableArray(selection.anchor.path);
|
|
76
|
+
|
|
77
|
+
linkPath.pop();
|
|
78
|
+
Editor.insertNodes(editor, newNodeLink, {
|
|
79
|
+
at: linkPath
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
|
|
83
|
+
case 'insert_image_at_selection':
|
|
84
|
+
var img = generateImageElement({
|
|
85
|
+
data: command.data
|
|
86
|
+
});
|
|
87
|
+
Editor.insertNodes(editor, img, {
|
|
88
|
+
at: command.at
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case 'set_image':
|
|
93
|
+
Editor.setNodes(editor, {
|
|
94
|
+
data: data
|
|
95
|
+
}, {
|
|
96
|
+
match: {
|
|
97
|
+
type: 'image'
|
|
98
|
+
},
|
|
99
|
+
at: editor.selection,
|
|
100
|
+
voids: true
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case 'insert_data':
|
|
105
|
+
if (data.types.includes('Files') && data.files[0].type.includes('image') && window.editor.editorApi.uploadLocalImage) {
|
|
106
|
+
window.editor.editorApi.uploadLocalImage(command.data.files[0]).then(function (res) {
|
|
107
|
+
var img = generateImageElement({
|
|
108
|
+
data: {
|
|
109
|
+
src: res
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
Editor.insertNodes(editor, img);
|
|
113
|
+
});
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exec(command);
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
default:
|
|
121
|
+
exec(command);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return editor;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export default withInline;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import { SfEditor } from '../custom/custom';
|
|
4
|
+
import { Node, Text, Path } from 'slate';
|
|
5
|
+
|
|
6
|
+
var normalizeNode = function normalizeNode(editor) {
|
|
7
|
+
var normalizeNode = editor.normalizeNode;
|
|
8
|
+
|
|
9
|
+
editor.normalizeNode = function (_ref) {
|
|
10
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
11
|
+
node = _ref2[0],
|
|
12
|
+
path = _ref2[1];
|
|
13
|
+
|
|
14
|
+
// if current node is a list node
|
|
15
|
+
var type = node.type; // wrap the outest list item into unoreded list
|
|
16
|
+
|
|
17
|
+
if (path.length === 1 && type === 'list_item') {
|
|
18
|
+
SfEditor.wrapNodes(editor, {
|
|
19
|
+
type: 'unordered_list',
|
|
20
|
+
children: [node]
|
|
21
|
+
}, {
|
|
22
|
+
at: path
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (type === 'ordered_list' || type === 'unordered_list') {
|
|
27
|
+
var currentNodeIndex = path.slice(-1)[0];
|
|
28
|
+
var previousSibling;
|
|
29
|
+
|
|
30
|
+
if (currentNodeIndex !== 0) {
|
|
31
|
+
previousSibling = Node.get(editor, Path.previous(path));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (previousSibling && previousSibling.type === type) {
|
|
35
|
+
// merge previous same type list node
|
|
36
|
+
SfEditor.mergeNodes(editor, {
|
|
37
|
+
at: path
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var parentNode = Node.parent(editor, path);
|
|
42
|
+
var nextIndex = currentNodeIndex + 1;
|
|
43
|
+
var nextSiblings = parentNode.children[nextIndex];
|
|
44
|
+
|
|
45
|
+
if (nextSiblings && nextSiblings.type === type) {
|
|
46
|
+
// merge next same type list node
|
|
47
|
+
SfEditor.mergeNodes(editor, {
|
|
48
|
+
at: Path.next(path)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
} // trailing a paragrph at the end of the document
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if (path.length === 1 && path[0] === editor.children.length - 1) {
|
|
55
|
+
if (node.type !== 'paragraph' || !SfEditor.isEmptyParagraph(node)) {
|
|
56
|
+
SfEditor.insertNodes(editor, {
|
|
57
|
+
type: 'paragraph',
|
|
58
|
+
children: [{
|
|
59
|
+
text: ''
|
|
60
|
+
}]
|
|
61
|
+
}, {
|
|
62
|
+
at: [path[0] + 1]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (type === 'blockquote') {
|
|
68
|
+
node.children.forEach(function (child, index) {
|
|
69
|
+
var childPath = [].concat(_toConsumableArray(path), [index]);
|
|
70
|
+
|
|
71
|
+
if (child.type === 'blockquote') {
|
|
72
|
+
SfEditor.unwrapNodes(editor, {
|
|
73
|
+
at: childPath
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
} // remove empty link
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if (type === 'link') {
|
|
81
|
+
if (Node.text(node) === '' && node.children.length > 0) {
|
|
82
|
+
SfEditor.removeNodes(editor, {
|
|
83
|
+
at: path
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
} // remove mark when the text node is empty
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
if (Text.isText(node) && node.text.length === 0) {
|
|
90
|
+
if (Object.keys(node).length > 1) {
|
|
91
|
+
SfEditor.setNodes(editor, {
|
|
92
|
+
CODE: false,
|
|
93
|
+
BOLD: false,
|
|
94
|
+
ITALIC: false
|
|
95
|
+
}, {
|
|
96
|
+
at: path
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return normalizeNode([node, path]);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return editor;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default normalizeNode;
|